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 GtkEntry *entry = GTK_ENTRY (widget);
3526 GtkEntryPrivate *private = entry->priv;
3527 gint x, y, width, height;
3529 get_progress_area (widget, &x, &y, &width, &height);
3531 if ((width <= 0) || (height <= 0))
3534 gtk_style_context_save (context);
3535 gtk_style_context_add_class (context, GTK_STYLE_CLASS_PROGRESSBAR);
3536 if (private->progress_pulse_mode)
3537 gtk_style_context_add_class (context, GTK_STYLE_CLASS_PULSE);
3539 gtk_render_activity (context, cr,
3540 x, y, width, height);
3542 gtk_style_context_restore (context);
3546 gtk_entry_draw (GtkWidget *widget,
3549 GtkEntry *entry = GTK_ENTRY (widget);
3550 GtkStyleContext *context;
3551 GtkStateFlags state;
3552 GtkEntryPrivate *priv = entry->priv;
3555 context = gtk_widget_get_style_context (widget);
3556 state = gtk_widget_get_state_flags (widget);
3558 gtk_style_context_save (context);
3559 gtk_style_context_set_state (context, state);
3561 /* Draw entry_bg, shadow, progress and focus */
3562 gtk_entry_draw_frame (widget, context, cr);
3564 /* Draw text and cursor */
3567 gtk_cairo_transform_to_window (cr, widget, priv->text_area);
3569 if (priv->dnd_position != -1)
3570 gtk_entry_draw_cursor (GTK_ENTRY (widget), cr, CURSOR_DND);
3572 gtk_entry_draw_text (GTK_ENTRY (widget), cr);
3574 /* When no text is being displayed at all, don't show the cursor */
3575 if (gtk_entry_get_display_mode (entry) != DISPLAY_BLANK &&
3576 gtk_widget_has_focus (widget) &&
3577 priv->selection_bound == priv->current_pos && priv->cursor_visible)
3578 gtk_entry_draw_cursor (GTK_ENTRY (widget), cr, CURSOR_STANDARD);
3583 for (i = 0; i < MAX_ICONS; i++)
3585 EntryIconInfo *icon_info = priv->icons[i];
3587 if (icon_info != NULL)
3591 gtk_cairo_transform_to_window (cr, widget, icon_info->window);
3593 draw_icon (widget, cr, i);
3599 gtk_style_context_restore (context);
3605 gtk_entry_enter_notify (GtkWidget *widget,
3606 GdkEventCrossing *event)
3608 GtkEntry *entry = GTK_ENTRY (widget);
3609 GtkEntryPrivate *priv = entry->priv;
3612 for (i = 0; i < MAX_ICONS; i++)
3614 EntryIconInfo *icon_info = priv->icons[i];
3616 if (icon_info != NULL && event->window == icon_info->window)
3618 if (should_prelight (entry, i))
3620 icon_info->prelight = TRUE;
3621 gtk_widget_queue_draw (widget);
3632 gtk_entry_leave_notify (GtkWidget *widget,
3633 GdkEventCrossing *event)
3635 GtkEntry *entry = GTK_ENTRY (widget);
3636 GtkEntryPrivate *priv = entry->priv;
3639 for (i = 0; i < MAX_ICONS; i++)
3641 EntryIconInfo *icon_info = priv->icons[i];
3643 if (icon_info != NULL && event->window == icon_info->window)
3645 /* a grab means that we may never see the button release */
3646 if (event->mode == GDK_CROSSING_GRAB || event->mode == GDK_CROSSING_GTK_GRAB)
3647 icon_info->pressed = FALSE;
3649 if (should_prelight (entry, i))
3651 icon_info->prelight = FALSE;
3652 gtk_widget_queue_draw (widget);
3663 gtk_entry_get_pixel_ranges (GtkEntry *entry,
3667 gint start_char, end_char;
3669 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start_char, &end_char))
3671 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
3672 PangoLayoutLine *line = pango_layout_get_lines_readonly (layout)->data;
3673 const char *text = pango_layout_get_text (layout);
3674 gint start_index = g_utf8_offset_to_pointer (text, start_char) - text;
3675 gint end_index = g_utf8_offset_to_pointer (text, end_char) - text;
3676 gint real_n_ranges, i;
3678 pango_layout_line_get_x_ranges (line, start_index, end_index, ranges, &real_n_ranges);
3684 for (i = 0; i < real_n_ranges; ++i)
3686 r[2 * i + 1] = (r[2 * i + 1] - r[2 * i]) / PANGO_SCALE;
3687 r[2 * i] = r[2 * i] / PANGO_SCALE;
3692 *n_ranges = real_n_ranges;
3704 in_selection (GtkEntry *entry,
3709 gint retval = FALSE;
3711 gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
3713 for (i = 0; i < n_ranges; ++i)
3715 if (x >= ranges[2 * i] && x < ranges[2 * i] + ranges[2 * i + 1])
3727 gtk_entry_button_press (GtkWidget *widget,
3728 GdkEventButton *event)
3730 GtkEntry *entry = GTK_ENTRY (widget);
3731 GtkEditable *editable = GTK_EDITABLE (widget);
3732 GtkEntryPrivate *priv = entry->priv;
3733 EntryIconInfo *icon_info = NULL;
3735 gint sel_start, sel_end;
3738 for (i = 0; i < MAX_ICONS; i++)
3740 icon_info = priv->icons[i];
3742 if (!icon_info || icon_info->insensitive)
3745 if (event->window == icon_info->window)
3747 if (should_prelight (entry, i))
3749 icon_info->prelight = FALSE;
3750 gtk_widget_queue_draw (widget);
3753 priv->start_x = event->x;
3754 priv->start_y = event->y;
3755 icon_info->pressed = TRUE;
3757 if (!icon_info->nonactivatable)
3758 g_signal_emit (entry, signals[ICON_PRESS], 0, i, event);
3764 if (event->window != priv->text_area ||
3765 (priv->button && event->button != priv->button))
3768 gtk_entry_reset_blink_time (entry);
3770 priv->button = event->button;
3772 if (!gtk_widget_has_focus (widget))
3774 priv->in_click = TRUE;
3775 gtk_widget_grab_focus (widget);
3776 priv->in_click = FALSE;
3779 tmp_pos = gtk_entry_find_position (entry, event->x + priv->scroll_offset);
3781 if (gdk_event_triggers_context_menu ((GdkEvent *) event))
3783 gtk_entry_do_popup (entry, event);
3784 priv->button = 0; /* Don't wait for release, since the menu will gtk_grab_add */
3788 else if (event->button == 1)
3790 gboolean have_selection = gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end);
3792 priv->select_words = FALSE;
3793 priv->select_lines = FALSE;
3796 gtk_widget_get_modifier_mask (widget,
3797 GDK_MODIFIER_INTENT_EXTEND_SELECTION))
3799 _gtk_entry_reset_im_context (entry);
3801 if (!have_selection) /* select from the current position to the clicked position */
3802 sel_start = sel_end = priv->current_pos;
3804 if (tmp_pos > sel_start && tmp_pos < sel_end)
3806 /* Truncate current selection, but keep it as big as possible */
3807 if (tmp_pos - sel_start > sel_end - tmp_pos)
3808 gtk_entry_set_positions (entry, sel_start, tmp_pos);
3810 gtk_entry_set_positions (entry, tmp_pos, sel_end);
3814 gboolean extend_to_left;
3817 /* Figure out what click selects and extend current selection */
3818 switch (event->type)
3820 case GDK_BUTTON_PRESS:
3821 gtk_entry_set_positions (entry, tmp_pos, tmp_pos);
3824 case GDK_2BUTTON_PRESS:
3825 priv->select_words = TRUE;
3826 gtk_entry_select_word (entry);
3829 case GDK_3BUTTON_PRESS:
3830 priv->select_lines = TRUE;
3831 gtk_entry_select_line (entry);
3838 start = MIN (priv->current_pos, priv->selection_bound);
3839 start = MIN (sel_start, start);
3841 end = MAX (priv->current_pos, priv->selection_bound);
3842 end = MAX (sel_end, end);
3844 if (tmp_pos == sel_start || tmp_pos == sel_end)
3845 extend_to_left = (tmp_pos == start);
3847 extend_to_left = (end == sel_end);
3850 gtk_entry_set_positions (entry, start, end);
3852 gtk_entry_set_positions (entry, end, start);
3855 else /* no shift key */
3856 switch (event->type)
3858 case GDK_BUTTON_PRESS:
3859 if (in_selection (entry, event->x + priv->scroll_offset))
3861 /* Click inside the selection - we'll either start a drag, or
3862 * clear the selection
3864 priv->in_drag = TRUE;
3865 priv->drag_start_x = event->x + priv->scroll_offset;
3866 priv->drag_start_y = event->y;
3869 gtk_editable_set_position (editable, tmp_pos);
3872 case GDK_2BUTTON_PRESS:
3873 /* We ALWAYS receive a GDK_BUTTON_PRESS immediately before
3874 * receiving a GDK_2BUTTON_PRESS so we need to reset
3875 * priv->in_drag which may have been set above
3877 priv->in_drag = FALSE;
3878 priv->select_words = TRUE;
3879 gtk_entry_select_word (entry);
3882 case GDK_3BUTTON_PRESS:
3883 /* We ALWAYS receive a GDK_BUTTON_PRESS immediately before
3884 * receiving a GDK_3BUTTON_PRESS so we need to reset
3885 * priv->in_drag which may have been set above
3887 priv->in_drag = FALSE;
3888 priv->select_lines = TRUE;
3889 gtk_entry_select_line (entry);
3898 else if (event->button == 2 && event->type == GDK_BUTTON_PRESS)
3902 priv->insert_pos = tmp_pos;
3903 gtk_entry_paste (entry, GDK_SELECTION_PRIMARY);
3908 gtk_widget_error_bell (widget);
3916 gtk_entry_button_release (GtkWidget *widget,
3917 GdkEventButton *event)
3919 GtkEntry *entry = GTK_ENTRY (widget);
3920 GtkEntryPrivate *priv = entry->priv;
3921 EntryIconInfo *icon_info = NULL;
3924 for (i = 0; i < MAX_ICONS; i++)
3926 icon_info = priv->icons[i];
3928 if (!icon_info || icon_info->insensitive)
3931 if (event->window == icon_info->window)
3933 icon_info->pressed = FALSE;
3935 if (should_prelight (entry, i) &&
3936 event->x >= 0 && event->y >= 0 &&
3937 event->x < gdk_window_get_width (icon_info->window) &&
3938 event->y < gdk_window_get_height (icon_info->window))
3940 icon_info->prelight = TRUE;
3941 gtk_widget_queue_draw (widget);
3944 if (!icon_info->nonactivatable)
3945 g_signal_emit (entry, signals[ICON_RELEASE], 0, i, event);
3951 if (event->window != priv->text_area || priv->button != event->button)
3956 gint tmp_pos = gtk_entry_find_position (entry, priv->drag_start_x);
3958 gtk_editable_set_position (GTK_EDITABLE (entry), tmp_pos);
3965 gtk_entry_update_primary_selection (entry);
3971 _gtk_entry_get_selected_text (GtkEntry *entry)
3973 GtkEditable *editable = GTK_EDITABLE (entry);
3974 gint start_text, end_text;
3977 if (gtk_editable_get_selection_bounds (editable, &start_text, &end_text))
3978 text = gtk_editable_get_chars (editable, start_text, end_text);
3984 gtk_entry_motion_notify (GtkWidget *widget,
3985 GdkEventMotion *event)
3987 GtkEntry *entry = GTK_ENTRY (widget);
3988 GtkEntryPrivate *priv = entry->priv;
3989 EntryIconInfo *icon_info = NULL;
3993 for (i = 0; i < MAX_ICONS; i++)
3995 icon_info = priv->icons[i];
3997 if (!icon_info || icon_info->insensitive)
4000 if (event->window == icon_info->window)
4002 if (icon_info->pressed &&
4003 icon_info->target_list != NULL &&
4004 gtk_drag_check_threshold (widget,
4010 icon_info->in_drag = TRUE;
4011 icon_info->pressed = FALSE;
4012 gtk_drag_begin (widget,
4013 icon_info->target_list,
4023 if (priv->mouse_cursor_obscured)
4027 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
4028 gdk_window_set_cursor (priv->text_area, cursor);
4029 g_object_unref (cursor);
4030 priv->mouse_cursor_obscured = FALSE;
4033 if (event->window != priv->text_area || priv->button != 1)
4036 if (priv->select_lines)
4039 gdk_event_request_motions (event);
4043 if (gtk_entry_get_display_mode (entry) == DISPLAY_NORMAL &&
4044 gtk_drag_check_threshold (widget,
4045 priv->drag_start_x, priv->drag_start_y,
4046 event->x + priv->scroll_offset, event->y))
4048 GdkDragContext *context;
4049 GtkTargetList *target_list = gtk_target_list_new (NULL, 0);
4050 guint actions = priv->editable ? GDK_ACTION_COPY | GDK_ACTION_MOVE : GDK_ACTION_COPY;
4052 cairo_surface_t *surface;
4054 gtk_target_list_add_text_targets (target_list, 0);
4056 text = _gtk_entry_get_selected_text (entry);
4057 surface = _gtk_text_util_create_drag_icon (widget, text, -1);
4059 context = gtk_drag_begin (widget, target_list, actions,
4060 priv->button, (GdkEvent *)event);
4063 gtk_drag_set_icon_surface (context, surface);
4065 gtk_drag_set_icon_default (context);
4068 cairo_surface_destroy (surface);
4071 priv->in_drag = FALSE;
4074 gtk_target_list_unref (target_list);
4081 else if (event->y >= gdk_window_get_height (priv->text_area))
4082 tmp_pos = gtk_entry_buffer_get_length (get_buffer (entry));
4084 tmp_pos = gtk_entry_find_position (entry, event->x + priv->scroll_offset);
4086 if (priv->select_words)
4089 gint old_min, old_max;
4092 min = gtk_entry_move_backward_word (entry, tmp_pos, TRUE);
4093 max = gtk_entry_move_forward_word (entry, tmp_pos, TRUE);
4095 pos = priv->current_pos;
4096 bound = priv->selection_bound;
4098 old_min = MIN(priv->current_pos, priv->selection_bound);
4099 old_max = MAX(priv->current_pos, priv->selection_bound);
4106 else if (old_max < max)
4111 else if (pos == old_min)
4113 if (priv->current_pos != min)
4118 if (priv->current_pos != max)
4122 gtk_entry_set_positions (entry, pos, bound);
4125 gtk_entry_set_positions (entry, tmp_pos, -1);
4132 set_invisible_cursor (GdkWindow *window)
4134 GdkDisplay *display;
4137 display = gdk_window_get_display (window);
4138 cursor = gdk_cursor_new_for_display (display, GDK_BLANK_CURSOR);
4140 gdk_window_set_cursor (window, cursor);
4142 g_object_unref (cursor);
4146 gtk_entry_obscure_mouse_cursor (GtkEntry *entry)
4148 GtkEntryPrivate *priv = entry->priv;
4150 if (priv->mouse_cursor_obscured)
4153 set_invisible_cursor (priv->text_area);
4155 priv->mouse_cursor_obscured = TRUE;
4159 gtk_entry_key_press (GtkWidget *widget,
4162 GtkEntry *entry = GTK_ENTRY (widget);
4163 GtkEntryPrivate *priv = entry->priv;
4165 gtk_entry_reset_blink_time (entry);
4166 gtk_entry_pend_cursor_blink (entry);
4170 if (gtk_im_context_filter_keypress (priv->im_context, event))
4172 gtk_entry_obscure_mouse_cursor (entry);
4173 priv->need_im_reset = TRUE;
4178 if (event->keyval == GDK_KEY_Return ||
4179 event->keyval == GDK_KEY_KP_Enter ||
4180 event->keyval == GDK_KEY_ISO_Enter ||
4181 event->keyval == GDK_KEY_Escape)
4183 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
4185 if (completion && completion->priv->completion_timeout)
4187 g_source_remove (completion->priv->completion_timeout);
4188 completion->priv->completion_timeout = 0;
4191 _gtk_entry_reset_im_context (entry);
4194 if (GTK_WIDGET_CLASS (gtk_entry_parent_class)->key_press_event (widget, event))
4195 /* Activate key bindings
4199 if (!priv->editable && event->length)
4200 gtk_widget_error_bell (widget);
4206 gtk_entry_key_release (GtkWidget *widget,
4209 GtkEntry *entry = GTK_ENTRY (widget);
4210 GtkEntryPrivate *priv = entry->priv;
4214 if (gtk_im_context_filter_keypress (priv->im_context, event))
4216 priv->need_im_reset = TRUE;
4221 return GTK_WIDGET_CLASS (gtk_entry_parent_class)->key_release_event (widget, event);
4225 gtk_entry_focus_in (GtkWidget *widget,
4226 GdkEventFocus *event)
4228 GtkEntry *entry = GTK_ENTRY (widget);
4229 GtkEntryPrivate *priv = entry->priv;
4232 gtk_widget_queue_draw (widget);
4234 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (widget));
4238 priv->need_im_reset = TRUE;
4239 gtk_im_context_focus_in (priv->im_context);
4240 keymap_state_changed (keymap, entry);
4241 g_signal_connect (keymap, "state-changed",
4242 G_CALLBACK (keymap_state_changed), entry);
4245 g_signal_connect (keymap, "direction-changed",
4246 G_CALLBACK (keymap_direction_changed), entry);
4248 if (gtk_entry_buffer_get_bytes (get_buffer (entry)) == 0 &&
4249 priv->placeholder_text != NULL)
4251 gtk_entry_recompute (entry);
4255 gtk_entry_reset_blink_time (entry);
4256 gtk_entry_check_cursor_blink (entry);
4263 gtk_entry_focus_out (GtkWidget *widget,
4264 GdkEventFocus *event)
4266 GtkEntry *entry = GTK_ENTRY (widget);
4267 GtkEntryPrivate *priv = entry->priv;
4268 GtkEntryCompletion *completion;
4271 gtk_widget_queue_draw (widget);
4273 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (widget));
4277 priv->need_im_reset = TRUE;
4278 gtk_im_context_focus_out (priv->im_context);
4279 remove_capslock_feedback (entry);
4282 if (gtk_entry_buffer_get_bytes (get_buffer (entry)) == 0 &&
4283 priv->placeholder_text != NULL)
4285 gtk_entry_recompute (entry);
4289 gtk_entry_check_cursor_blink (entry);
4292 g_signal_handlers_disconnect_by_func (keymap, keymap_state_changed, entry);
4293 g_signal_handlers_disconnect_by_func (keymap, keymap_direction_changed, entry);
4295 completion = gtk_entry_get_completion (entry);
4297 _gtk_entry_completion_popdown (completion);
4303 gtk_entry_grab_focus (GtkWidget *widget)
4305 GtkEntry *entry = GTK_ENTRY (widget);
4306 GtkEntryPrivate *priv = entry->priv;
4307 gboolean select_on_focus;
4309 GTK_WIDGET_CLASS (gtk_entry_parent_class)->grab_focus (widget);
4311 if (priv->editable && !priv->in_click)
4313 g_object_get (gtk_widget_get_settings (widget),
4314 "gtk-entry-select-on-focus",
4318 if (select_on_focus)
4319 gtk_editable_select_region (GTK_EDITABLE (widget), 0, -1);
4324 gtk_entry_direction_changed (GtkWidget *widget,
4325 GtkTextDirection previous_dir)
4327 GtkEntry *entry = GTK_ENTRY (widget);
4329 gtk_entry_recompute (entry);
4331 GTK_WIDGET_CLASS (gtk_entry_parent_class)->direction_changed (widget, previous_dir);
4335 gtk_entry_state_flags_changed (GtkWidget *widget,
4336 GtkStateFlags previous_state)
4338 GtkEntry *entry = GTK_ENTRY (widget);
4339 GtkEntryPrivate *priv = entry->priv;
4342 if (gtk_widget_get_realized (widget))
4344 if (gtk_widget_is_sensitive (widget))
4345 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
4349 gdk_window_set_cursor (priv->text_area, cursor);
4352 g_object_unref (cursor);
4354 priv->mouse_cursor_obscured = FALSE;
4356 update_cursors (widget);
4359 if (!gtk_widget_is_sensitive (widget))
4361 /* Clear any selection */
4362 gtk_editable_select_region (GTK_EDITABLE (entry), priv->current_pos, priv->current_pos);
4365 gtk_entry_update_cached_style_values (entry);
4369 gtk_entry_screen_changed (GtkWidget *widget,
4370 GdkScreen *old_screen)
4372 gtk_entry_recompute (GTK_ENTRY (widget));
4375 /* GtkEditable method implementations
4378 gtk_entry_insert_text (GtkEditable *editable,
4379 const gchar *new_text,
4380 gint new_text_length,
4383 g_object_ref (editable);
4386 * The incoming text may a password or other secret. We make sure
4387 * not to copy it into temporary buffers.
4390 g_signal_emit_by_name (editable, "insert-text", new_text, new_text_length, position);
4392 g_object_unref (editable);
4396 gtk_entry_delete_text (GtkEditable *editable,
4400 g_object_ref (editable);
4402 g_signal_emit_by_name (editable, "delete-text", start_pos, end_pos);
4404 g_object_unref (editable);
4408 gtk_entry_get_chars (GtkEditable *editable,
4412 GtkEntry *entry = GTK_ENTRY (editable);
4415 gint start_index, end_index;
4417 text = gtk_entry_buffer_get_text (get_buffer (entry));
4418 text_length = gtk_entry_buffer_get_length (get_buffer (entry));
4421 end_pos = text_length;
4423 start_pos = MIN (text_length, start_pos);
4424 end_pos = MIN (text_length, end_pos);
4426 start_index = g_utf8_offset_to_pointer (text, start_pos) - text;
4427 end_index = g_utf8_offset_to_pointer (text, end_pos) - text;
4429 return g_strndup (text + start_index, end_index - start_index);
4433 gtk_entry_real_set_position (GtkEditable *editable,
4436 GtkEntry *entry = GTK_ENTRY (editable);
4437 GtkEntryPrivate *priv = entry->priv;
4441 length = gtk_entry_buffer_get_length (get_buffer (entry));
4442 if (position < 0 || position > length)
4445 if (position != priv->current_pos ||
4446 position != priv->selection_bound)
4448 _gtk_entry_reset_im_context (entry);
4449 gtk_entry_set_positions (entry, position, position);
4454 gtk_entry_get_position (GtkEditable *editable)
4456 GtkEntry *entry = GTK_ENTRY (editable);
4457 GtkEntryPrivate *priv = entry->priv;
4459 return priv->current_pos;
4463 gtk_entry_set_selection_bounds (GtkEditable *editable,
4467 GtkEntry *entry = GTK_ENTRY (editable);
4470 length = gtk_entry_buffer_get_length (get_buffer (entry));
4476 _gtk_entry_reset_im_context (entry);
4478 gtk_entry_set_positions (entry,
4480 MIN (start, length));
4482 gtk_entry_update_primary_selection (entry);
4486 gtk_entry_get_selection_bounds (GtkEditable *editable,
4490 GtkEntry *entry = GTK_ENTRY (editable);
4491 GtkEntryPrivate *priv = entry->priv;
4493 *start = priv->selection_bound;
4494 *end = priv->current_pos;
4496 return (priv->selection_bound != priv->current_pos);
4500 icon_theme_changed (GtkEntry *entry)
4502 GtkEntryPrivate *priv = entry->priv;
4505 for (i = 0; i < MAX_ICONS; i++)
4507 EntryIconInfo *icon_info = priv->icons[i];
4508 if (icon_info != NULL)
4510 if (icon_info->storage_type == GTK_IMAGE_ICON_NAME)
4511 gtk_entry_set_icon_from_icon_name (entry, i, icon_info->icon_name);
4512 else if (icon_info->storage_type == GTK_IMAGE_STOCK)
4513 gtk_entry_set_icon_from_stock (entry, i, icon_info->stock_id);
4514 else if (icon_info->storage_type == GTK_IMAGE_GICON)
4515 gtk_entry_set_icon_from_gicon (entry, i, icon_info->gicon);
4519 gtk_widget_queue_draw (GTK_WIDGET (entry));
4523 icon_margin_changed (GtkEntry *entry)
4525 GtkEntryPrivate *priv = entry->priv;
4528 _gtk_entry_effective_inner_border (GTK_ENTRY (entry), &border);
4530 priv->icon_margin = border.left;
4534 gtk_entry_update_cached_style_values (GtkEntry *entry)
4536 GtkEntryPrivate *priv = entry->priv;
4538 gboolean interior_focus;
4540 gtk_widget_style_get (GTK_WIDGET (entry),
4541 "focus-line-width", &focus_width,
4542 "interior-focus", &interior_focus,
4544 priv->focus_width = focus_width;
4545 priv->interior_focus = interior_focus;
4547 if (!priv->invisible_char_set)
4549 gunichar ch = find_invisible_char (GTK_WIDGET (entry));
4551 if (priv->invisible_char != ch)
4553 priv->invisible_char = ch;
4554 g_object_notify (G_OBJECT (entry), "invisible-char");
4560 gtk_entry_style_updated (GtkWidget *widget)
4562 GtkEntry *entry = GTK_ENTRY (widget);
4564 GTK_WIDGET_CLASS (gtk_entry_parent_class)->style_updated (widget);
4566 gtk_entry_update_cached_style_values (entry);
4568 gtk_entry_recompute (entry);
4570 icon_theme_changed (entry);
4571 icon_margin_changed (entry);
4574 /* GtkCellEditable method implementations
4577 gtk_cell_editable_entry_activated (GtkEntry *entry, gpointer data)
4579 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4580 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4584 gtk_cell_editable_key_press_event (GtkEntry *entry,
4585 GdkEventKey *key_event,
4588 GtkEntryPrivate *priv = entry->priv;
4590 if (key_event->keyval == GDK_KEY_Escape)
4592 priv->editing_canceled = TRUE;
4593 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4594 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4599 /* override focus */
4600 if (key_event->keyval == GDK_KEY_Up || key_event->keyval == GDK_KEY_Down)
4602 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4603 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4612 gtk_entry_start_editing (GtkCellEditable *cell_editable,
4615 GtkEntry *entry = GTK_ENTRY (cell_editable);
4616 GtkEntryPrivate *priv = entry->priv;
4618 priv->is_cell_renderer = TRUE;
4620 g_signal_connect (cell_editable, "activate",
4621 G_CALLBACK (gtk_cell_editable_entry_activated), NULL);
4622 g_signal_connect (cell_editable, "key-press-event",
4623 G_CALLBACK (gtk_cell_editable_key_press_event), NULL);
4627 gtk_entry_password_hint_free (GtkEntryPasswordHint *password_hint)
4629 if (password_hint->source_id)
4630 g_source_remove (password_hint->source_id);
4632 g_slice_free (GtkEntryPasswordHint, password_hint);
4637 gtk_entry_remove_password_hint (gpointer data)
4639 GtkEntryPasswordHint *password_hint = g_object_get_qdata (data, quark_password_hint);
4640 password_hint->position = -1;
4642 /* Force the string to be redrawn, but now without a visible character */
4643 gtk_entry_recompute (GTK_ENTRY (data));
4647 /* Default signal handlers
4650 gtk_entry_real_insert_text (GtkEditable *editable,
4651 const gchar *new_text,
4652 gint new_text_length,
4658 n_chars = g_utf8_strlen (new_text, new_text_length);
4661 * The actual insertion into the buffer. This will end up firing the
4662 * following signal handlers: buffer_inserted_text(), buffer_notify_display_text(),
4663 * buffer_notify_text(), buffer_notify_length()
4665 begin_change (GTK_ENTRY (editable));
4666 g_object_freeze_notify (G_OBJECT (editable));
4668 n_inserted = gtk_entry_buffer_insert_text (get_buffer (GTK_ENTRY (editable)), *position, new_text, n_chars);
4670 g_object_thaw_notify (G_OBJECT (editable));
4671 end_change (GTK_ENTRY (editable));
4673 if (n_inserted != n_chars)
4674 gtk_widget_error_bell (GTK_WIDGET (editable));
4676 *position += n_inserted;
4680 gtk_entry_real_delete_text (GtkEditable *editable,
4685 * The actual deletion from the buffer. This will end up firing the
4686 * following signal handlers: buffer_deleted_text(), buffer_notify_display_text(),
4687 * buffer_notify_text(), buffer_notify_length()
4690 begin_change (GTK_ENTRY (editable));
4691 g_object_freeze_notify (G_OBJECT (editable));
4692 gtk_entry_buffer_delete_text (get_buffer (GTK_ENTRY (editable)), start_pos, end_pos - start_pos);
4693 g_object_thaw_notify (G_OBJECT (editable));
4694 end_change (GTK_ENTRY (editable));
4697 /* GtkEntryBuffer signal handlers
4700 buffer_inserted_text (GtkEntryBuffer *buffer,
4706 GtkEntryPrivate *priv = entry->priv;
4707 guint password_hint_timeout;
4709 gint selection_bound;
4711 current_pos = priv->current_pos;
4712 if (current_pos > position)
4713 current_pos += n_chars;
4715 selection_bound = priv->selection_bound;
4716 if (selection_bound > position)
4717 selection_bound += n_chars;
4719 gtk_entry_set_positions (entry, current_pos, selection_bound);
4721 /* Calculate the password hint if it needs to be displayed. */
4722 if (n_chars == 1 && !priv->visible)
4724 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
4725 "gtk-entry-password-hint-timeout", &password_hint_timeout,
4728 if (password_hint_timeout > 0)
4730 GtkEntryPasswordHint *password_hint = g_object_get_qdata (G_OBJECT (entry),
4731 quark_password_hint);
4734 password_hint = g_slice_new0 (GtkEntryPasswordHint);
4735 g_object_set_qdata_full (G_OBJECT (entry), quark_password_hint, password_hint,
4736 (GDestroyNotify)gtk_entry_password_hint_free);
4739 password_hint->position = position;
4740 if (password_hint->source_id)
4741 g_source_remove (password_hint->source_id);
4742 password_hint->source_id = gdk_threads_add_timeout (password_hint_timeout,
4743 (GSourceFunc)gtk_entry_remove_password_hint, entry);
4749 buffer_deleted_text (GtkEntryBuffer *buffer,
4754 GtkEntryPrivate *priv = entry->priv;
4755 guint end_pos = position + n_chars;
4756 gint selection_bound;
4759 current_pos = priv->current_pos;
4760 if (current_pos > position)
4761 current_pos -= MIN (current_pos, end_pos) - position;
4763 selection_bound = priv->selection_bound;
4764 if (selection_bound > position)
4765 selection_bound -= MIN (selection_bound, end_pos) - position;
4767 gtk_entry_set_positions (entry, current_pos, selection_bound);
4769 /* We might have deleted the selection */
4770 gtk_entry_update_primary_selection (entry);
4772 /* Disable the password hint if one exists. */
4775 GtkEntryPasswordHint *password_hint = g_object_get_qdata (G_OBJECT (entry),
4776 quark_password_hint);
4779 if (password_hint->source_id)
4780 g_source_remove (password_hint->source_id);
4781 password_hint->source_id = 0;
4782 password_hint->position = -1;
4788 buffer_notify_text (GtkEntryBuffer *buffer,
4792 gtk_entry_recompute (entry);
4793 emit_changed (entry);
4794 g_object_notify (G_OBJECT (entry), "text");
4798 buffer_notify_length (GtkEntryBuffer *buffer,
4802 g_object_notify (G_OBJECT (entry), "text-length");
4806 buffer_notify_max_length (GtkEntryBuffer *buffer,
4810 g_object_notify (G_OBJECT (entry), "max-length");
4814 buffer_connect_signals (GtkEntry *entry)
4816 g_signal_connect (get_buffer (entry), "inserted-text", G_CALLBACK (buffer_inserted_text), entry);
4817 g_signal_connect (get_buffer (entry), "deleted-text", G_CALLBACK (buffer_deleted_text), entry);
4818 g_signal_connect (get_buffer (entry), "notify::text", G_CALLBACK (buffer_notify_text), entry);
4819 g_signal_connect (get_buffer (entry), "notify::length", G_CALLBACK (buffer_notify_length), entry);
4820 g_signal_connect (get_buffer (entry), "notify::max-length", G_CALLBACK (buffer_notify_max_length), entry);
4824 buffer_disconnect_signals (GtkEntry *entry)
4826 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_inserted_text, entry);
4827 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_deleted_text, entry);
4828 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_text, entry);
4829 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_length, entry);
4830 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_max_length, entry);
4833 /* Compute the X position for an offset that corresponds to the "more important
4834 * cursor position for that offset. We use this when trying to guess to which
4835 * end of the selection we should go to when the user hits the left or
4839 get_better_cursor_x (GtkEntry *entry,
4842 GtkEntryPrivate *priv = entry->priv;
4843 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
4844 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
4845 gboolean split_cursor;
4847 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
4848 const gchar *text = pango_layout_get_text (layout);
4849 gint index = g_utf8_offset_to_pointer (text, offset) - text;
4851 PangoRectangle strong_pos, weak_pos;
4853 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
4854 "gtk-split-cursor", &split_cursor,
4857 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
4860 return strong_pos.x / PANGO_SCALE;
4862 return (keymap_direction == priv->resolved_dir) ? strong_pos.x / PANGO_SCALE : weak_pos.x / PANGO_SCALE;
4866 gtk_entry_move_cursor (GtkEntry *entry,
4867 GtkMovementStep step,
4869 gboolean extend_selection)
4871 GtkEntryPrivate *priv = entry->priv;
4872 gint new_pos = priv->current_pos;
4874 _gtk_entry_reset_im_context (entry);
4876 if (priv->current_pos != priv->selection_bound && !extend_selection)
4878 /* If we have a current selection and aren't extending it, move to the
4879 * start/or end of the selection as appropriate
4883 case GTK_MOVEMENT_VISUAL_POSITIONS:
4885 gint current_x = get_better_cursor_x (entry, priv->current_pos);
4886 gint bound_x = get_better_cursor_x (entry, priv->selection_bound);
4889 new_pos = current_x < bound_x ? priv->current_pos : priv->selection_bound;
4891 new_pos = current_x > bound_x ? priv->current_pos : priv->selection_bound;
4894 case GTK_MOVEMENT_LOGICAL_POSITIONS:
4895 case GTK_MOVEMENT_WORDS:
4897 new_pos = MIN (priv->current_pos, priv->selection_bound);
4899 new_pos = MAX (priv->current_pos, priv->selection_bound);
4901 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
4902 case GTK_MOVEMENT_PARAGRAPH_ENDS:
4903 case GTK_MOVEMENT_BUFFER_ENDS:
4904 new_pos = count < 0 ? 0 : gtk_entry_buffer_get_length (get_buffer (entry));
4906 case GTK_MOVEMENT_DISPLAY_LINES:
4907 case GTK_MOVEMENT_PARAGRAPHS:
4908 case GTK_MOVEMENT_PAGES:
4909 case GTK_MOVEMENT_HORIZONTAL_PAGES:
4917 case GTK_MOVEMENT_LOGICAL_POSITIONS:
4918 new_pos = gtk_entry_move_logically (entry, new_pos, count);
4920 case GTK_MOVEMENT_VISUAL_POSITIONS:
4921 new_pos = gtk_entry_move_visually (entry, new_pos, count);
4922 if (priv->current_pos == new_pos)
4924 if (!extend_selection)
4926 if (!gtk_widget_keynav_failed (GTK_WIDGET (entry),
4928 GTK_DIR_RIGHT : GTK_DIR_LEFT))
4930 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (entry));
4933 gtk_widget_child_focus (toplevel,
4935 GTK_DIR_RIGHT : GTK_DIR_LEFT);
4940 gtk_widget_error_bell (GTK_WIDGET (entry));
4944 case GTK_MOVEMENT_WORDS:
4947 new_pos = gtk_entry_move_forward_word (entry, new_pos, FALSE);
4952 new_pos = gtk_entry_move_backward_word (entry, new_pos, FALSE);
4955 if (priv->current_pos == new_pos)
4956 gtk_widget_error_bell (GTK_WIDGET (entry));
4958 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
4959 case GTK_MOVEMENT_PARAGRAPH_ENDS:
4960 case GTK_MOVEMENT_BUFFER_ENDS:
4961 new_pos = count < 0 ? 0 : gtk_entry_buffer_get_length (get_buffer (entry));
4962 if (priv->current_pos == new_pos)
4963 gtk_widget_error_bell (GTK_WIDGET (entry));
4965 case GTK_MOVEMENT_DISPLAY_LINES:
4966 case GTK_MOVEMENT_PARAGRAPHS:
4967 case GTK_MOVEMENT_PAGES:
4968 case GTK_MOVEMENT_HORIZONTAL_PAGES:
4973 if (extend_selection)
4974 gtk_editable_select_region (GTK_EDITABLE (entry), priv->selection_bound, new_pos);
4976 gtk_editable_set_position (GTK_EDITABLE (entry), new_pos);
4978 gtk_entry_pend_cursor_blink (entry);
4982 gtk_entry_insert_at_cursor (GtkEntry *entry,
4985 GtkEntryPrivate *priv = entry->priv;
4986 GtkEditable *editable = GTK_EDITABLE (entry);
4987 gint pos = priv->current_pos;
4991 _gtk_entry_reset_im_context (entry);
4993 gtk_editable_insert_text (editable, str, -1, &pos);
4994 gtk_editable_set_position (editable, pos);
4999 gtk_entry_delete_from_cursor (GtkEntry *entry,
5003 GtkEntryPrivate *priv = entry->priv;
5004 GtkEditable *editable = GTK_EDITABLE (entry);
5005 gint start_pos = priv->current_pos;
5006 gint end_pos = priv->current_pos;
5007 gint old_n_bytes = gtk_entry_buffer_get_bytes (get_buffer (entry));
5009 _gtk_entry_reset_im_context (entry);
5011 if (!priv->editable)
5013 gtk_widget_error_bell (GTK_WIDGET (entry));
5017 if (priv->selection_bound != priv->current_pos)
5019 gtk_editable_delete_selection (editable);
5025 case GTK_DELETE_CHARS:
5026 end_pos = gtk_entry_move_logically (entry, priv->current_pos, count);
5027 gtk_editable_delete_text (editable, MIN (start_pos, end_pos), MAX (start_pos, end_pos));
5029 case GTK_DELETE_WORDS:
5032 /* Move to end of current word, or if not on a word, end of previous word */
5033 end_pos = gtk_entry_move_backward_word (entry, end_pos, FALSE);
5034 end_pos = gtk_entry_move_forward_word (entry, end_pos, FALSE);
5038 /* Move to beginning of current word, or if not on a word, begining of next word */
5039 start_pos = gtk_entry_move_forward_word (entry, start_pos, FALSE);
5040 start_pos = gtk_entry_move_backward_word (entry, start_pos, FALSE);
5044 case GTK_DELETE_WORD_ENDS:
5047 start_pos = gtk_entry_move_backward_word (entry, start_pos, FALSE);
5052 end_pos = gtk_entry_move_forward_word (entry, end_pos, FALSE);
5055 gtk_editable_delete_text (editable, start_pos, end_pos);
5057 case GTK_DELETE_DISPLAY_LINE_ENDS:
5058 case GTK_DELETE_PARAGRAPH_ENDS:
5060 gtk_editable_delete_text (editable, 0, priv->current_pos);
5062 gtk_editable_delete_text (editable, priv->current_pos, -1);
5064 case GTK_DELETE_DISPLAY_LINES:
5065 case GTK_DELETE_PARAGRAPHS:
5066 gtk_editable_delete_text (editable, 0, -1);
5068 case GTK_DELETE_WHITESPACE:
5069 gtk_entry_delete_whitespace (entry);
5073 if (gtk_entry_buffer_get_bytes (get_buffer (entry)) == old_n_bytes)
5074 gtk_widget_error_bell (GTK_WIDGET (entry));
5076 gtk_entry_pend_cursor_blink (entry);
5080 gtk_entry_backspace (GtkEntry *entry)
5082 GtkEntryPrivate *priv = entry->priv;
5083 GtkEditable *editable = GTK_EDITABLE (entry);
5086 _gtk_entry_reset_im_context (entry);
5088 if (!priv->editable)
5090 gtk_widget_error_bell (GTK_WIDGET (entry));
5094 if (priv->selection_bound != priv->current_pos)
5096 gtk_editable_delete_selection (editable);
5100 prev_pos = gtk_entry_move_logically (entry, priv->current_pos, -1);
5102 if (prev_pos < priv->current_pos)
5104 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
5105 PangoLogAttr *log_attrs;
5108 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
5110 /* Deleting parts of characters */
5111 if (log_attrs[priv->current_pos].backspace_deletes_character)
5113 gchar *cluster_text;
5114 gchar *normalized_text;
5117 cluster_text = gtk_entry_get_display_text (entry, prev_pos,
5119 normalized_text = g_utf8_normalize (cluster_text,
5120 strlen (cluster_text),
5122 len = g_utf8_strlen (normalized_text, -1);
5124 gtk_editable_delete_text (editable, prev_pos, priv->current_pos);
5127 gint pos = priv->current_pos;
5129 gtk_editable_insert_text (editable, normalized_text,
5130 g_utf8_offset_to_pointer (normalized_text, len - 1) - normalized_text,
5132 gtk_editable_set_position (editable, pos);
5135 g_free (normalized_text);
5136 g_free (cluster_text);
5140 gtk_editable_delete_text (editable, prev_pos, priv->current_pos);
5147 gtk_widget_error_bell (GTK_WIDGET (entry));
5150 gtk_entry_pend_cursor_blink (entry);
5154 gtk_entry_copy_clipboard (GtkEntry *entry)
5156 GtkEntryPrivate *priv = entry->priv;
5157 GtkEditable *editable = GTK_EDITABLE (entry);
5161 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5165 gtk_widget_error_bell (GTK_WIDGET (entry));
5169 str = gtk_entry_get_display_text (entry, start, end);
5170 gtk_clipboard_set_text (gtk_widget_get_clipboard (GTK_WIDGET (entry),
5171 GDK_SELECTION_CLIPBOARD),
5178 gtk_entry_cut_clipboard (GtkEntry *entry)
5180 GtkEntryPrivate *priv = entry->priv;
5181 GtkEditable *editable = GTK_EDITABLE (entry);
5186 gtk_widget_error_bell (GTK_WIDGET (entry));
5190 gtk_entry_copy_clipboard (entry);
5194 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5195 gtk_editable_delete_text (editable, start, end);
5199 gtk_widget_error_bell (GTK_WIDGET (entry));
5204 gtk_entry_paste_clipboard (GtkEntry *entry)
5206 GtkEntryPrivate *priv = entry->priv;
5209 gtk_entry_paste (entry, GDK_SELECTION_CLIPBOARD);
5211 gtk_widget_error_bell (GTK_WIDGET (entry));
5215 gtk_entry_delete_cb (GtkEntry *entry)
5217 GtkEntryPrivate *priv = entry->priv;
5218 GtkEditable *editable = GTK_EDITABLE (entry);
5223 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5224 gtk_editable_delete_text (editable, start, end);
5229 gtk_entry_toggle_overwrite (GtkEntry *entry)
5231 GtkEntryPrivate *priv = entry->priv;
5233 priv->overwrite_mode = !priv->overwrite_mode;
5234 gtk_entry_pend_cursor_blink (entry);
5235 gtk_widget_queue_draw (GTK_WIDGET (entry));
5239 gtk_entry_select_all (GtkEntry *entry)
5241 gtk_entry_select_line (entry);
5245 gtk_entry_real_activate (GtkEntry *entry)
5247 GtkEntryPrivate *priv = entry->priv;
5249 GtkWidget *default_widget, *focus_widget;
5250 GtkWidget *toplevel;
5253 widget = GTK_WIDGET (entry);
5255 if (priv->activates_default)
5257 toplevel = gtk_widget_get_toplevel (widget);
5258 if (GTK_IS_WINDOW (toplevel))
5260 window = GTK_WINDOW (toplevel);
5264 default_widget = gtk_window_get_default_widget (window);
5265 focus_widget = gtk_window_get_focus (window);
5266 if (widget != default_widget &&
5267 !(widget == focus_widget && (!default_widget || !gtk_widget_get_sensitive (default_widget))))
5268 gtk_window_activate_default (window);
5275 keymap_direction_changed (GdkKeymap *keymap,
5278 gtk_entry_recompute (entry);
5281 /* IM Context Callbacks
5285 gtk_entry_commit_cb (GtkIMContext *context,
5289 GtkEntryPrivate *priv = entry->priv;
5292 gtk_entry_enter_text (entry, str);
5296 gtk_entry_preedit_changed_cb (GtkIMContext *context,
5299 GtkEntryPrivate *priv = entry->priv;
5303 gchar *preedit_string;
5306 gtk_im_context_get_preedit_string (priv->im_context,
5307 &preedit_string, NULL,
5309 g_signal_emit (entry, signals[PREEDIT_CHANGED], 0, preedit_string);
5310 priv->preedit_length = strlen (preedit_string);
5311 cursor_pos = CLAMP (cursor_pos, 0, g_utf8_strlen (preedit_string, -1));
5312 priv->preedit_cursor = cursor_pos;
5313 g_free (preedit_string);
5315 gtk_entry_recompute (entry);
5320 gtk_entry_retrieve_surrounding_cb (GtkIMContext *context,
5323 GtkEntryPrivate *priv = entry->priv;
5326 /* XXXX ??? does this even make sense when text is not visible? Should we return FALSE? */
5327 text = gtk_entry_get_display_text (entry, 0, -1);
5328 gtk_im_context_set_surrounding (context, text, strlen (text), /* Length in bytes */
5329 g_utf8_offset_to_pointer (text, priv->current_pos) - text);
5336 gtk_entry_delete_surrounding_cb (GtkIMContext *slave,
5341 GtkEntryPrivate *priv = entry->priv;
5344 gtk_editable_delete_text (GTK_EDITABLE (entry),
5345 priv->current_pos + offset,
5346 priv->current_pos + offset + n_chars);
5351 /* Internal functions
5354 /* Used for im_commit_cb and inserting Unicode chars */
5356 gtk_entry_enter_text (GtkEntry *entry,
5359 GtkEntryPrivate *priv = entry->priv;
5360 GtkEditable *editable = GTK_EDITABLE (entry);
5362 gboolean old_need_im_reset;
5364 old_need_im_reset = priv->need_im_reset;
5365 priv->need_im_reset = FALSE;
5367 if (gtk_editable_get_selection_bounds (editable, NULL, NULL))
5368 gtk_editable_delete_selection (editable);
5371 if (priv->overwrite_mode)
5372 gtk_entry_delete_from_cursor (entry, GTK_DELETE_CHARS, 1);
5375 tmp_pos = priv->current_pos;
5376 gtk_editable_insert_text (editable, str, strlen (str), &tmp_pos);
5377 gtk_editable_set_position (editable, tmp_pos);
5379 priv->need_im_reset = old_need_im_reset;
5382 /* All changes to priv->current_pos and priv->selection_bound
5383 * should go through this function.
5386 gtk_entry_set_positions (GtkEntry *entry,
5388 gint selection_bound)
5390 GtkEntryPrivate *priv = entry->priv;
5391 gboolean changed = FALSE;
5393 g_object_freeze_notify (G_OBJECT (entry));
5395 if (current_pos != -1 &&
5396 priv->current_pos != current_pos)
5398 priv->current_pos = current_pos;
5401 g_object_notify (G_OBJECT (entry), "cursor-position");
5404 if (selection_bound != -1 &&
5405 priv->selection_bound != selection_bound)
5407 priv->selection_bound = selection_bound;
5410 g_object_notify (G_OBJECT (entry), "selection-bound");
5413 g_object_thaw_notify (G_OBJECT (entry));
5417 gtk_entry_move_adjustments (entry);
5418 gtk_entry_recompute (entry);
5423 gtk_entry_reset_layout (GtkEntry *entry)
5425 GtkEntryPrivate *priv = entry->priv;
5427 if (priv->cached_layout)
5429 g_object_unref (priv->cached_layout);
5430 priv->cached_layout = NULL;
5435 update_im_cursor_location (GtkEntry *entry)
5437 GtkEntryPrivate *priv = entry->priv;
5440 gint strong_xoffset;
5441 gint area_width, area_height;
5443 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
5444 gtk_entry_get_text_area_size (entry, NULL, NULL, &area_width, &area_height);
5446 strong_xoffset = strong_x - priv->scroll_offset;
5447 if (strong_xoffset < 0)
5451 else if (strong_xoffset > area_width)
5453 strong_xoffset = area_width;
5455 area.x = strong_xoffset;
5458 area.height = area_height;
5460 gtk_im_context_set_cursor_location (priv->im_context, &area);
5464 recompute_idle_func (gpointer data)
5466 GtkEntry *entry = GTK_ENTRY (data);
5467 GtkEntryPrivate *priv = entry->priv;
5469 priv->recompute_idle = 0;
5471 if (gtk_widget_has_screen (GTK_WIDGET (entry)))
5473 gtk_entry_adjust_scroll (entry);
5474 gtk_widget_queue_draw (GTK_WIDGET (entry));
5476 update_im_cursor_location (entry);
5483 gtk_entry_recompute (GtkEntry *entry)
5485 GtkEntryPrivate *priv = entry->priv;
5487 gtk_entry_reset_layout (entry);
5488 gtk_entry_check_cursor_blink (entry);
5490 if (!priv->recompute_idle)
5492 priv->recompute_idle = gdk_threads_add_idle_full (G_PRIORITY_HIGH_IDLE + 15, /* between resize and redraw */
5493 recompute_idle_func, entry, NULL);
5498 gtk_entry_get_placeholder_text_color (GtkEntry *entry,
5501 GtkWidget *widget = GTK_WIDGET (entry);
5502 GtkStyleContext *context;
5503 GdkRGBA fg = { 0.5, 0.5, 0.5 };
5505 context = gtk_widget_get_style_context (widget);
5506 gtk_style_context_lookup_color (context, "placeholder_text_color", &fg);
5508 color->red = CLAMP (fg.red * 65535. + 0.5, 0, 65535);
5509 color->green = CLAMP (fg.green * 65535. + 0.5, 0, 65535);
5510 color->blue = CLAMP (fg.blue * 65535. + 0.5, 0, 65535);
5513 static inline gboolean
5514 show_placeholder_text (GtkEntry *entry)
5516 GtkEntryPrivate *priv = entry->priv;
5518 if (!gtk_widget_has_focus (GTK_WIDGET (entry)) &&
5519 gtk_entry_buffer_get_bytes (get_buffer (entry)) == 0 &&
5520 priv->placeholder_text != NULL)
5526 static PangoLayout *
5527 gtk_entry_create_layout (GtkEntry *entry,
5528 gboolean include_preedit)
5530 GtkEntryPrivate *priv = entry->priv;
5531 GtkWidget *widget = GTK_WIDGET (entry);
5532 PangoLayout *layout = gtk_widget_create_pango_layout (widget, NULL);
5533 PangoAttrList *tmp_attrs = pango_attr_list_new ();
5534 gboolean placeholder_layout = show_placeholder_text (entry);
5536 gchar *preedit_string = NULL;
5537 gint preedit_length = 0;
5538 PangoAttrList *preedit_attrs = NULL;
5543 pango_layout_set_single_paragraph_mode (layout, TRUE);
5545 display = placeholder_layout ? g_strdup (priv->placeholder_text) : gtk_entry_get_display_text (entry, 0, -1);
5546 n_bytes = strlen (display);
5548 if (!placeholder_layout && include_preedit)
5550 gtk_im_context_get_preedit_string (priv->im_context,
5551 &preedit_string, &preedit_attrs, NULL);
5552 preedit_length = priv->preedit_length;
5554 else if (placeholder_layout)
5557 PangoAttribute *attr;
5559 gtk_entry_get_placeholder_text_color (entry, &color);
5560 attr = pango_attr_foreground_new (color.red, color.green, color.blue);
5561 attr->start_index = 0;
5562 attr->end_index = G_MAXINT;
5563 pango_attr_list_insert (tmp_attrs, attr);
5568 GString *tmp_string = g_string_new (display);
5569 gint cursor_index = g_utf8_offset_to_pointer (display, priv->current_pos) - display;
5571 g_string_insert (tmp_string, cursor_index, preedit_string);
5573 pango_layout_set_text (layout, tmp_string->str, tmp_string->len);
5575 pango_attr_list_splice (tmp_attrs, preedit_attrs,
5576 cursor_index, preedit_length);
5578 g_string_free (tmp_string, TRUE);
5582 PangoDirection pango_dir;
5584 if (gtk_entry_get_display_mode (entry) == DISPLAY_NORMAL)
5585 pango_dir = pango_find_base_dir (display, n_bytes);
5587 pango_dir = PANGO_DIRECTION_NEUTRAL;
5589 if (pango_dir == PANGO_DIRECTION_NEUTRAL)
5591 if (gtk_widget_has_focus (widget))
5593 GdkDisplay *display = gtk_widget_get_display (widget);
5594 GdkKeymap *keymap = gdk_keymap_get_for_display (display);
5595 if (gdk_keymap_get_direction (keymap) == PANGO_DIRECTION_RTL)
5596 pango_dir = PANGO_DIRECTION_RTL;
5598 pango_dir = PANGO_DIRECTION_LTR;
5602 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
5603 pango_dir = PANGO_DIRECTION_RTL;
5605 pango_dir = PANGO_DIRECTION_LTR;
5609 pango_context_set_base_dir (gtk_widget_get_pango_context (widget),
5612 priv->resolved_dir = pango_dir;
5614 pango_layout_set_text (layout, display, n_bytes);
5617 pango_layout_set_attributes (layout, tmp_attrs);
5619 g_free (preedit_string);
5623 pango_attr_list_unref (preedit_attrs);
5625 pango_attr_list_unref (tmp_attrs);
5630 static PangoLayout *
5631 gtk_entry_ensure_layout (GtkEntry *entry,
5632 gboolean include_preedit)
5634 GtkEntryPrivate *priv = entry->priv;
5636 if (priv->preedit_length > 0 &&
5637 !include_preedit != !priv->cache_includes_preedit)
5638 gtk_entry_reset_layout (entry);
5640 if (!priv->cached_layout)
5642 priv->cached_layout = gtk_entry_create_layout (entry, include_preedit);
5643 priv->cache_includes_preedit = include_preedit;
5646 return priv->cached_layout;
5650 get_layout_position (GtkEntry *entry,
5654 GtkEntryPrivate *priv = entry->priv;
5655 PangoLayout *layout;
5656 PangoRectangle logical_rect;
5657 gint area_width, area_height;
5658 GtkBorder inner_border;
5660 PangoLayoutLine *line;
5662 layout = gtk_entry_ensure_layout (entry, TRUE);
5664 gtk_entry_get_text_area_size (entry, NULL, NULL, &area_width, &area_height);
5665 _gtk_entry_effective_inner_border (entry, &inner_border);
5667 area_height = PANGO_SCALE * (area_height - inner_border.top - inner_border.bottom);
5669 line = pango_layout_get_lines_readonly (layout)->data;
5670 pango_layout_line_get_extents (line, NULL, &logical_rect);
5672 /* Align primarily for locale's ascent/descent */
5673 y_pos = ((area_height - priv->ascent - priv->descent) / 2 +
5674 priv->ascent + logical_rect.y);
5676 /* Now see if we need to adjust to fit in actual drawn string */
5677 if (logical_rect.height > area_height)
5678 y_pos = (area_height - logical_rect.height) / 2;
5681 else if (y_pos + logical_rect.height > area_height)
5682 y_pos = area_height - logical_rect.height;
5684 y_pos = inner_border.top + y_pos / PANGO_SCALE;
5687 *x = inner_border.left - priv->scroll_offset;
5694 draw_text_with_color (GtkEntry *entry,
5696 GdkRGBA *default_color)
5698 GtkEntryPrivate *priv = entry->priv;
5699 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
5702 gint start_pos, end_pos;
5704 widget = GTK_WIDGET (entry);
5708 get_layout_position (entry, &x, &y);
5710 cairo_move_to (cr, x, y);
5711 gdk_cairo_set_source_rgba (cr, default_color);
5712 pango_cairo_show_layout (cr, layout);
5714 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start_pos, &end_pos))
5718 PangoRectangle logical_rect;
5719 GdkRGBA selection_color, text_color;
5720 GtkBorder inner_border;
5721 GtkStyleContext *context;
5722 GtkStateFlags state;
5724 context = gtk_widget_get_style_context (widget);
5725 pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
5726 gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
5728 state = GTK_STATE_FLAG_SELECTED;
5730 if (gtk_widget_has_focus (widget))
5731 state |= GTK_STATE_FLAG_FOCUSED;
5733 gtk_style_context_get_background_color (context, state, &selection_color);
5734 gtk_style_context_get_color (context, state, &text_color);
5736 _gtk_entry_effective_inner_border (entry, &inner_border);
5738 for (i = 0; i < n_ranges; ++i)
5739 cairo_rectangle (cr,
5740 inner_border.left - priv->scroll_offset + ranges[2 * i],
5743 logical_rect.height);
5747 gdk_cairo_set_source_rgba (cr, &selection_color);
5750 cairo_move_to (cr, x, y);
5751 gdk_cairo_set_source_rgba (cr, &text_color);
5752 pango_cairo_show_layout (cr, layout);
5760 gtk_entry_draw_text (GtkEntry *entry,
5763 GtkEntryPrivate *priv = entry->priv;
5764 GtkWidget *widget = GTK_WIDGET (entry);
5765 GtkStateFlags state = 0;
5766 GdkRGBA text_color, bar_text_color;
5767 GtkStyleContext *context;
5769 gint progress_x, progress_y, progress_width, progress_height;
5770 gint clip_width, clip_height;
5772 /* Nothing to display at all */
5773 if (gtk_entry_get_display_mode (entry) == DISPLAY_BLANK)
5776 state = gtk_widget_get_state_flags (widget);
5777 context = gtk_widget_get_style_context (widget);
5779 gtk_style_context_get_color (context, state, &text_color);
5781 /* Get foreground color for progressbars */
5782 gtk_style_context_save (context);
5783 gtk_style_context_add_class (context, GTK_STYLE_CLASS_PROGRESSBAR);
5784 gtk_style_context_get_color (context, state, &bar_text_color);
5785 gtk_style_context_restore (context);
5787 get_progress_area (widget,
5788 &progress_x, &progress_y,
5789 &progress_width, &progress_height);
5793 clip_width = gdk_window_get_width (priv->text_area);
5794 clip_height = gdk_window_get_height (priv->text_area);
5795 cairo_rectangle (cr, 0, 0, clip_width, clip_height);
5798 /* If the color is the same, or the progress area has a zero
5799 * size, then we only need to draw once. */
5800 if (gdk_rgba_equal (&text_color, &bar_text_color) ||
5801 ((progress_width == 0) || (progress_height == 0)))
5803 draw_text_with_color (entry, cr, &text_color);
5807 int frame_x, frame_y, area_x, area_y;
5809 width = gdk_window_get_width (priv->text_area);
5810 height = gdk_window_get_height (priv->text_area);
5814 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
5815 cairo_rectangle (cr, 0, 0, width, height);
5817 /* progres area is frame-relative, we need it text-area window
5819 get_frame_size (entry, TRUE, &frame_x, &frame_y, NULL, NULL);
5820 gdk_window_get_position (priv->text_area, &area_x, &area_y);
5821 progress_x += frame_x - area_x;
5822 progress_y += frame_y - area_y;
5824 cairo_rectangle (cr, progress_x, progress_y,
5825 progress_width, progress_height);
5827 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_WINDING);
5829 draw_text_with_color (entry, cr, &text_color);
5834 cairo_rectangle (cr, progress_x, progress_y,
5835 progress_width, progress_height);
5838 draw_text_with_color (entry, cr, &bar_text_color);
5847 draw_insertion_cursor (GtkEntry *entry,
5849 GdkRectangle *cursor_location,
5850 gboolean is_primary,
5851 PangoDirection direction,
5852 gboolean draw_arrow)
5854 GtkWidget *widget = GTK_WIDGET (entry);
5855 GtkTextDirection text_dir;
5857 if (direction == PANGO_DIRECTION_LTR)
5858 text_dir = GTK_TEXT_DIR_LTR;
5860 text_dir = GTK_TEXT_DIR_RTL;
5862 gtk_draw_insertion_cursor (widget, cr,
5864 is_primary, text_dir, draw_arrow);
5868 gtk_entry_draw_cursor (GtkEntry *entry,
5872 GtkEntryPrivate *priv = entry->priv;
5873 GtkWidget *widget = GTK_WIDGET (entry);
5874 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
5875 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
5876 GdkRectangle cursor_location;
5877 gboolean split_cursor;
5878 PangoRectangle cursor_rect;
5879 GtkBorder inner_border;
5881 gint text_area_height;
5884 gboolean block_at_line_end;
5885 PangoLayout *layout;
5888 _gtk_entry_effective_inner_border (entry, &inner_border);
5890 xoffset = inner_border.left - priv->scroll_offset;
5892 text_area_height = gdk_window_get_height (priv->text_area);
5894 layout = gtk_entry_ensure_layout (entry, TRUE);
5895 text = pango_layout_get_text (layout);
5896 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos + priv->preedit_cursor) - text;
5897 if (!priv->overwrite_mode)
5900 block = _gtk_text_util_get_block_cursor_location (layout,
5901 cursor_index, &cursor_rect, &block_at_line_end);
5905 gint strong_x, weak_x;
5906 PangoDirection dir1 = PANGO_DIRECTION_NEUTRAL;
5907 PangoDirection dir2 = PANGO_DIRECTION_NEUTRAL;
5911 gtk_entry_get_cursor_locations (entry, type, &strong_x, &weak_x);
5913 g_object_get (gtk_widget_get_settings (widget),
5914 "gtk-split-cursor", &split_cursor,
5917 dir1 = priv->resolved_dir;
5923 if (weak_x != strong_x)
5925 dir2 = (priv->resolved_dir == PANGO_DIRECTION_LTR) ? PANGO_DIRECTION_RTL : PANGO_DIRECTION_LTR;
5931 if (keymap_direction == priv->resolved_dir)
5937 cursor_location.x = xoffset + x1;
5938 cursor_location.y = inner_border.top;
5939 cursor_location.width = 0;
5940 cursor_location.height = text_area_height - inner_border.top - inner_border.bottom;
5942 draw_insertion_cursor (entry, cr,
5943 &cursor_location, TRUE, dir1,
5944 dir2 != PANGO_DIRECTION_NEUTRAL);
5946 if (dir2 != PANGO_DIRECTION_NEUTRAL)
5948 cursor_location.x = xoffset + x2;
5949 draw_insertion_cursor (entry, cr,
5950 &cursor_location, FALSE, dir2,
5954 else /* overwrite_mode */
5956 GtkStyleContext *context;
5957 GdkRGBA cursor_color;
5963 get_layout_position (entry, &x, &y);
5965 rect.x = PANGO_PIXELS (cursor_rect.x) + x;
5966 rect.y = PANGO_PIXELS (cursor_rect.y) + y;
5967 rect.width = PANGO_PIXELS (cursor_rect.width);
5968 rect.height = PANGO_PIXELS (cursor_rect.height);
5970 context = gtk_widget_get_style_context (widget);
5972 _gtk_style_context_get_cursor_color (context, &cursor_color, NULL);
5973 gdk_cairo_set_source_rgba (cr, &cursor_color);
5974 gdk_cairo_rectangle (cr, &rect);
5977 if (!block_at_line_end)
5979 GtkStateFlags state;
5982 state = gtk_widget_get_state_flags (widget);
5983 gtk_style_context_get_background_color (context, state, &color);
5985 gdk_cairo_rectangle (cr, &rect);
5987 cairo_move_to (cr, x, y);
5988 gdk_cairo_set_source_rgba (cr, &color);
5989 pango_cairo_show_layout (cr, layout);
5997 _gtk_entry_reset_im_context (GtkEntry *entry)
5999 GtkEntryPrivate *priv = entry->priv;
6001 if (priv->need_im_reset)
6003 priv->need_im_reset = FALSE;
6004 gtk_im_context_reset (priv->im_context);
6009 * gtk_entry_reset_im_context:
6010 * @entry: a #GtkEntry
6012 * Reset the input method context of the entry if needed.
6014 * This can be necessary in the case where modifying the buffer
6015 * would confuse on-going input method behavior.
6020 gtk_entry_reset_im_context (GtkEntry *entry)
6022 g_return_if_fail (GTK_IS_ENTRY (entry));
6024 _gtk_entry_reset_im_context (entry);
6028 * gtk_entry_im_context_filter_keypress:
6029 * @entry: a #GtkEntry
6030 * @event: (type Gdk.EventKey): the key event
6032 * Allow the #GtkEntry input method to internally handle key press
6033 * and release events. If this function returns %TRUE, then no further
6034 * processing should be done for this key event. See
6035 * gtk_im_context_filter_keypress().
6037 * Note that you are expected to call this function from your handler
6038 * when overriding key event handling. This is needed in the case when
6039 * you need to insert your own key handling between the input method
6040 * and the default key event handling of the #GtkEntry.
6041 * See gtk_text_view_reset_im_context() for an example of use.
6043 * Return value: %TRUE if the input method handled the key event.
6048 gtk_entry_im_context_filter_keypress (GtkEntry *entry,
6051 GtkEntryPrivate *priv;
6053 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
6057 return gtk_im_context_filter_keypress (priv->im_context, event);
6061 _gtk_entry_get_im_context (GtkEntry *entry)
6063 return entry->priv->im_context;
6067 gtk_entry_find_position (GtkEntry *entry,
6070 GtkEntryPrivate *priv = entry->priv;
6071 PangoLayout *layout;
6072 PangoLayoutLine *line;
6079 layout = gtk_entry_ensure_layout (entry, TRUE);
6080 text = pango_layout_get_text (layout);
6081 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos) - text;
6083 line = pango_layout_get_lines_readonly (layout)->data;
6084 pango_layout_line_x_to_index (line, x * PANGO_SCALE, &index, &trailing);
6086 if (index >= cursor_index && priv->preedit_length)
6088 if (index >= cursor_index + priv->preedit_length)
6089 index -= priv->preedit_length;
6092 index = cursor_index;
6097 pos = g_utf8_pointer_to_offset (text, text + index);
6104 gtk_entry_get_cursor_locations (GtkEntry *entry,
6109 GtkEntryPrivate *priv = entry->priv;
6110 DisplayMode mode = gtk_entry_get_display_mode (entry);
6112 /* Nothing to display at all, so no cursor is relevant */
6113 if (mode == DISPLAY_BLANK)
6123 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
6124 const gchar *text = pango_layout_get_text (layout);
6125 PangoRectangle strong_pos, weak_pos;
6128 if (type == CURSOR_STANDARD)
6130 index = g_utf8_offset_to_pointer (text, priv->current_pos + priv->preedit_cursor) - text;
6132 else /* type == CURSOR_DND */
6134 index = g_utf8_offset_to_pointer (text, priv->dnd_position) - text;
6136 if (priv->dnd_position > priv->current_pos)
6138 if (mode == DISPLAY_NORMAL)
6139 index += priv->preedit_length;
6142 gint preedit_len_chars = g_utf8_strlen (text, -1) - gtk_entry_buffer_get_length (get_buffer (entry));
6143 index += preedit_len_chars * g_unichar_to_utf8 (priv->invisible_char, NULL);
6148 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
6151 *strong_x = strong_pos.x / PANGO_SCALE;
6154 *weak_x = weak_pos.x / PANGO_SCALE;
6159 gtk_entry_adjust_scroll (GtkEntry *entry)
6161 GtkEntryPrivate *priv = entry->priv;
6162 gint min_offset, max_offset;
6163 gint text_area_width, text_width;
6164 GtkBorder inner_border;
6165 gint strong_x, weak_x;
6166 gint strong_xoffset, weak_xoffset;
6168 PangoLayout *layout;
6169 PangoLayoutLine *line;
6170 PangoRectangle logical_rect;
6172 if (!gtk_widget_get_realized (GTK_WIDGET (entry)))
6175 _gtk_entry_effective_inner_border (entry, &inner_border);
6177 text_area_width = gdk_window_get_width (priv->text_area);
6178 text_area_width -= inner_border.left + inner_border.right;
6179 if (text_area_width < 0)
6180 text_area_width = 0;
6182 layout = gtk_entry_ensure_layout (entry, TRUE);
6183 line = pango_layout_get_lines_readonly (layout)->data;
6185 pango_layout_line_get_extents (line, NULL, &logical_rect);
6187 /* Display as much text as we can */
6189 if (priv->resolved_dir == PANGO_DIRECTION_LTR)
6190 xalign = priv->xalign;
6192 xalign = 1.0 - priv->xalign;
6194 text_width = PANGO_PIXELS(logical_rect.width);
6196 if (text_width > text_area_width)
6199 max_offset = text_width - text_area_width;
6203 min_offset = (text_width - text_area_width) * xalign;
6204 max_offset = min_offset;
6207 priv->scroll_offset = CLAMP (priv->scroll_offset, min_offset, max_offset);
6209 /* And make sure cursors are on screen. Note that the cursor is
6210 * actually drawn one pixel into the INNER_BORDER space on
6211 * the right, when the scroll is at the utmost right. This
6212 * looks better to to me than confining the cursor inside the
6213 * border entirely, though it means that the cursor gets one
6214 * pixel closer to the edge of the widget on the right than
6215 * on the left. This might need changing if one changed
6216 * INNER_BORDER from 2 to 1, as one would do on a
6217 * small-screen-real-estate display.
6219 * We always make sure that the strong cursor is on screen, and
6220 * put the weak cursor on screen if possible.
6223 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, &weak_x);
6225 strong_xoffset = strong_x - priv->scroll_offset;
6227 if (strong_xoffset < 0)
6229 priv->scroll_offset += strong_xoffset;
6232 else if (strong_xoffset > text_area_width)
6234 priv->scroll_offset += strong_xoffset - text_area_width;
6235 strong_xoffset = text_area_width;
6238 weak_xoffset = weak_x - priv->scroll_offset;
6240 if (weak_xoffset < 0 && strong_xoffset - weak_xoffset <= text_area_width)
6242 priv->scroll_offset += weak_xoffset;
6244 else if (weak_xoffset > text_area_width &&
6245 strong_xoffset - (weak_xoffset - text_area_width) >= 0)
6247 priv->scroll_offset += weak_xoffset - text_area_width;
6250 g_object_notify (G_OBJECT (entry), "scroll-offset");
6254 gtk_entry_move_adjustments (GtkEntry *entry)
6256 GtkWidget *widget = GTK_WIDGET (entry);
6257 GtkAllocation allocation;
6258 GtkAdjustment *adjustment;
6259 PangoContext *context;
6260 PangoFontMetrics *metrics;
6261 GtkStyleContext *style_context;
6262 GtkStateFlags state;
6263 gint x, layout_x, border_x, border_y;
6266 adjustment = g_object_get_qdata (G_OBJECT (entry), quark_cursor_hadjustment);
6270 gtk_widget_get_allocation (widget, &allocation);
6272 /* Cursor position, layout offset, border width, and widget allocation */
6273 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &x, NULL);
6274 get_layout_position (entry, &layout_x, NULL);
6275 _gtk_entry_get_borders (entry, &border_x, &border_y);
6276 x += allocation.x + layout_x + border_x;
6278 /* Approximate width of a char, so user can see what is ahead/behind */
6279 context = gtk_widget_get_pango_context (widget);
6280 style_context = gtk_widget_get_style_context (widget);
6281 state = gtk_widget_get_state_flags (widget);
6283 metrics = pango_context_get_metrics (context,
6284 gtk_style_context_get_font (style_context, state),
6285 pango_context_get_language (context));
6286 char_width = pango_font_metrics_get_approximate_char_width (metrics) / PANGO_SCALE;
6289 gtk_adjustment_clamp_page (adjustment,
6290 x - (char_width + 1), /* one char + one pixel before */
6291 x + (char_width + 2)); /* one char + cursor + one pixel after */
6295 gtk_entry_move_visually (GtkEntry *entry,
6299 GtkEntryPrivate *priv = entry->priv;
6301 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6304 text = pango_layout_get_text (layout);
6306 index = g_utf8_offset_to_pointer (text, start) - text;
6310 int new_index, new_trailing;
6311 gboolean split_cursor;
6314 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
6315 "gtk-split-cursor", &split_cursor,
6322 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
6323 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
6325 strong = keymap_direction == priv->resolved_dir;
6330 pango_layout_move_cursor_visually (layout, strong, index, 0, 1, &new_index, &new_trailing);
6335 pango_layout_move_cursor_visually (layout, strong, index, 0, -1, &new_index, &new_trailing);
6341 else if (new_index != G_MAXINT)
6344 while (new_trailing--)
6345 index = g_utf8_next_char (text + index) - text;
6348 return g_utf8_pointer_to_offset (text, text + index);
6352 gtk_entry_move_logically (GtkEntry *entry,
6356 gint new_pos = start;
6359 length = gtk_entry_buffer_get_length (get_buffer (entry));
6361 /* Prevent any leak of information */
6362 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6364 new_pos = CLAMP (start + count, 0, length);
6368 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6369 PangoLogAttr *log_attrs;
6372 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6374 while (count > 0 && new_pos < length)
6378 while (new_pos < length && !log_attrs[new_pos].is_cursor_position);
6382 while (count < 0 && new_pos > 0)
6386 while (new_pos > 0 && !log_attrs[new_pos].is_cursor_position);
6398 gtk_entry_move_forward_word (GtkEntry *entry,
6400 gboolean allow_whitespace)
6402 gint new_pos = start;
6405 length = gtk_entry_buffer_get_length (get_buffer (entry));
6407 /* Prevent any leak of information */
6408 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6412 else if (new_pos < length)
6414 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6415 PangoLogAttr *log_attrs;
6418 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6420 /* Find the next word boundary */
6422 while (new_pos < n_attrs - 1 && !(log_attrs[new_pos].is_word_end ||
6423 (log_attrs[new_pos].is_word_start && allow_whitespace)))
6434 gtk_entry_move_backward_word (GtkEntry *entry,
6436 gboolean allow_whitespace)
6438 gint new_pos = start;
6440 /* Prevent any leak of information */
6441 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6447 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6448 PangoLogAttr *log_attrs;
6451 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6453 new_pos = start - 1;
6455 /* Find the previous word boundary */
6456 while (new_pos > 0 && !(log_attrs[new_pos].is_word_start ||
6457 (log_attrs[new_pos].is_word_end && allow_whitespace)))
6467 gtk_entry_delete_whitespace (GtkEntry *entry)
6469 GtkEntryPrivate *priv = entry->priv;
6470 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6471 PangoLogAttr *log_attrs;
6475 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6477 start = end = priv->current_pos;
6479 while (start > 0 && log_attrs[start-1].is_white)
6482 while (end < n_attrs && log_attrs[end].is_white)
6488 gtk_editable_delete_text (GTK_EDITABLE (entry), start, end);
6493 gtk_entry_select_word (GtkEntry *entry)
6495 GtkEntryPrivate *priv = entry->priv;
6496 gint start_pos = gtk_entry_move_backward_word (entry, priv->current_pos, TRUE);
6497 gint end_pos = gtk_entry_move_forward_word (entry, priv->current_pos, TRUE);
6499 gtk_editable_select_region (GTK_EDITABLE (entry), start_pos, end_pos);
6503 gtk_entry_select_line (GtkEntry *entry)
6505 gtk_editable_select_region (GTK_EDITABLE (entry), 0, -1);
6509 truncate_multiline (const gchar *text)
6514 text[length] && text[length] != '\n' && text[length] != '\r';
6521 paste_received (GtkClipboard *clipboard,
6525 GtkEntry *entry = GTK_ENTRY (data);
6526 GtkEditable *editable = GTK_EDITABLE (entry);
6527 GtkEntryPrivate *priv = entry->priv;
6529 if (priv->button == 2)
6531 gint pos, start, end;
6532 pos = priv->insert_pos;
6533 gtk_editable_get_selection_bounds (editable, &start, &end);
6534 if (!((start <= pos && pos <= end) || (end <= pos && pos <= start)))
6535 gtk_editable_select_region (editable, pos, pos);
6540 gint pos, start, end;
6542 gboolean popup_completion;
6543 GtkEntryCompletion *completion;
6545 completion = gtk_entry_get_completion (entry);
6547 if (priv->truncate_multiline)
6548 length = truncate_multiline (text);
6550 /* only complete if the selection is at the end */
6551 popup_completion = (gtk_entry_buffer_get_length (get_buffer (entry)) ==
6552 MAX (priv->current_pos, priv->selection_bound));
6556 if (gtk_widget_get_mapped (completion->priv->popup_window))
6557 _gtk_entry_completion_popdown (completion);
6559 if (!popup_completion && completion->priv->changed_id > 0)
6560 g_signal_handler_block (entry, completion->priv->changed_id);
6563 begin_change (entry);
6564 g_object_freeze_notify (G_OBJECT (entry));
6565 if (gtk_editable_get_selection_bounds (editable, &start, &end))
6566 gtk_editable_delete_text (editable, start, end);
6568 pos = priv->current_pos;
6569 gtk_editable_insert_text (editable, text, length, &pos);
6570 gtk_editable_set_position (editable, pos);
6571 g_object_thaw_notify (G_OBJECT (entry));
6575 !popup_completion && completion->priv->changed_id > 0)
6576 g_signal_handler_unblock (entry, completion->priv->changed_id);
6579 g_object_unref (entry);
6583 gtk_entry_paste (GtkEntry *entry,
6586 g_object_ref (entry);
6587 gtk_clipboard_request_text (gtk_widget_get_clipboard (GTK_WIDGET (entry), selection),
6588 paste_received, entry);
6592 primary_get_cb (GtkClipboard *clipboard,
6593 GtkSelectionData *selection_data,
6597 GtkEntry *entry = GTK_ENTRY (data);
6600 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end))
6602 gchar *str = gtk_entry_get_display_text (entry, start, end);
6603 gtk_selection_data_set_text (selection_data, str, -1);
6609 primary_clear_cb (GtkClipboard *clipboard,
6612 GtkEntry *entry = GTK_ENTRY (data);
6613 GtkEntryPrivate *priv = entry->priv;
6615 gtk_editable_select_region (GTK_EDITABLE (entry), priv->current_pos, priv->current_pos);
6619 gtk_entry_update_primary_selection (GtkEntry *entry)
6621 GtkTargetList *list;
6622 GtkTargetEntry *targets;
6623 GtkClipboard *clipboard;
6627 if (!gtk_widget_get_realized (GTK_WIDGET (entry)))
6630 list = gtk_target_list_new (NULL, 0);
6631 gtk_target_list_add_text_targets (list, 0);
6633 targets = gtk_target_table_new_from_list (list, &n_targets);
6635 clipboard = gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_PRIMARY);
6637 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end))
6639 if (!gtk_clipboard_set_with_owner (clipboard, targets, n_targets,
6640 primary_get_cb, primary_clear_cb, G_OBJECT (entry)))
6641 primary_clear_cb (clipboard, entry);
6645 if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (entry))
6646 gtk_clipboard_clear (clipboard);
6649 gtk_target_table_free (targets, n_targets);
6650 gtk_target_list_unref (list);
6654 gtk_entry_clear (GtkEntry *entry,
6655 GtkEntryIconPosition icon_pos)
6657 GtkEntryPrivate *priv = entry->priv;
6658 EntryIconInfo *icon_info = priv->icons[icon_pos];
6660 if (!icon_info || icon_info->storage_type == GTK_IMAGE_EMPTY)
6663 g_object_freeze_notify (G_OBJECT (entry));
6665 /* Explicitly check, as the pointer may become invalidated
6666 * during destruction.
6668 if (GDK_IS_WINDOW (icon_info->window))
6669 gdk_window_hide (icon_info->window);
6671 if (icon_info->pixbuf)
6673 g_object_unref (icon_info->pixbuf);
6674 icon_info->pixbuf = NULL;
6677 switch (icon_info->storage_type)
6679 case GTK_IMAGE_PIXBUF:
6680 g_object_notify (G_OBJECT (entry),
6681 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-pixbuf" : "secondary-icon-pixbuf");
6684 case GTK_IMAGE_STOCK:
6685 g_free (icon_info->stock_id);
6686 icon_info->stock_id = NULL;
6687 g_object_notify (G_OBJECT (entry),
6688 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-stock" : "secondary-icon-stock");
6691 case GTK_IMAGE_ICON_NAME:
6692 g_free (icon_info->icon_name);
6693 icon_info->icon_name = NULL;
6694 g_object_notify (G_OBJECT (entry),
6695 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-name" : "secondary-icon-name");
6698 case GTK_IMAGE_GICON:
6699 if (icon_info->gicon)
6701 g_object_unref (icon_info->gicon);
6702 icon_info->gicon = NULL;
6704 g_object_notify (G_OBJECT (entry),
6705 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-gicon" : "secondary-icon-gicon");
6709 g_assert_not_reached ();
6713 icon_info->storage_type = GTK_IMAGE_EMPTY;
6714 g_object_notify (G_OBJECT (entry),
6715 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-storage-type" : "secondary-icon-storage-type");
6717 g_object_thaw_notify (G_OBJECT (entry));
6721 create_normal_pixbuf (GtkStyleContext *context,
6722 const gchar *stock_id,
6723 GtkIconSize icon_size)
6725 GtkIconSet *icon_set;
6728 gtk_style_context_save (context);
6730 /* Unset any state */
6731 gtk_style_context_set_state (context, GTK_STATE_FLAG_NORMAL);
6733 icon_set = gtk_style_context_lookup_icon_set (context, stock_id);
6734 pixbuf = gtk_icon_set_render_icon_pixbuf (icon_set, context, icon_size);
6736 gtk_style_context_restore (context);
6742 ensure_stated_icon_from_info (GtkStyleContext *context,
6745 GdkPixbuf *retval = NULL;
6746 gboolean symbolic = FALSE;
6751 gtk_icon_info_load_symbolic_for_context (info,
6760 create_normal_pixbuf (context,
6761 GTK_STOCK_MISSING_IMAGE,
6762 GTK_ICON_SIZE_MENU);
6766 GdkPixbuf *temp_pixbuf;
6767 GtkIconSource *icon_source;
6769 icon_source = gtk_icon_source_new ();
6770 gtk_icon_source_set_pixbuf (icon_source, retval);
6771 gtk_icon_source_set_state_wildcarded (icon_source, TRUE);
6773 temp_pixbuf = gtk_render_icon_pixbuf (context, icon_source, (GtkIconSize)-1);
6775 gtk_icon_source_free (icon_source);
6777 g_object_unref (retval);
6778 retval = temp_pixbuf;
6785 gtk_entry_ensure_pixbuf (GtkEntry *entry,
6786 GtkEntryIconPosition icon_pos)
6788 GtkEntryPrivate *priv = entry->priv;
6789 EntryIconInfo *icon_info = priv->icons[icon_pos];
6790 GtkStyleContext *context;
6792 GtkIconTheme *icon_theme;
6793 GtkSettings *settings;
6797 GtkStateFlags state;
6799 widget = GTK_WIDGET (entry);
6800 context = gtk_widget_get_style_context (widget);
6802 state = GTK_STATE_FLAG_NORMAL;
6804 if (!gtk_widget_is_sensitive (widget) || icon_info->insensitive)
6805 state |= GTK_STATE_FLAG_INSENSITIVE;
6806 else if (icon_info->prelight)
6807 state |= GTK_STATE_FLAG_PRELIGHT;
6809 if ((icon_info == NULL) ||
6810 ((icon_info->pixbuf != NULL) && icon_info->last_state == state))
6813 icon_info->last_state = state;
6815 gtk_style_context_save (context);
6816 gtk_style_context_set_state (context, state);
6817 gtk_style_context_add_class (context, GTK_STYLE_CLASS_IMAGE);
6819 switch (icon_info->storage_type)
6821 case GTK_IMAGE_EMPTY:
6822 case GTK_IMAGE_PIXBUF:
6824 case GTK_IMAGE_STOCK:
6825 icon_info->pixbuf = create_normal_pixbuf (context, icon_info->stock_id,
6826 GTK_ICON_SIZE_MENU);
6828 if (!icon_info->pixbuf)
6829 icon_info->pixbuf = create_normal_pixbuf (context,
6830 GTK_STOCK_MISSING_IMAGE,
6831 GTK_ICON_SIZE_MENU);
6834 case GTK_IMAGE_ICON_NAME:
6835 screen = gtk_widget_get_screen (widget);
6838 icon_theme = gtk_icon_theme_get_for_screen (screen);
6839 settings = gtk_settings_get_for_screen (screen);
6841 gtk_icon_size_lookup_for_settings (settings,
6845 info = gtk_icon_theme_lookup_icon (icon_theme,
6846 icon_info->icon_name,
6847 MIN (width, height),
6851 ensure_stated_icon_from_info (context, info);
6854 gtk_icon_info_free (info);
6858 case GTK_IMAGE_GICON:
6859 screen = gtk_widget_get_screen (widget);
6862 icon_theme = gtk_icon_theme_get_for_screen (screen);
6863 settings = gtk_settings_get_for_screen (screen);
6865 gtk_icon_size_lookup_for_settings (settings,
6869 info = gtk_icon_theme_lookup_by_gicon (icon_theme,
6871 MIN (width, height),
6872 GTK_ICON_LOOKUP_USE_BUILTIN);
6875 ensure_stated_icon_from_info (context, info);
6878 gtk_icon_info_free (info);
6883 g_assert_not_reached ();
6887 gtk_style_context_restore (context);
6889 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
6890 gdk_window_show_unraised (icon_info->window);
6900 * Creates a new entry.
6902 * Return value: a new #GtkEntry.
6905 gtk_entry_new (void)
6907 return g_object_new (GTK_TYPE_ENTRY, NULL);
6911 * gtk_entry_new_with_buffer:
6912 * @buffer: The buffer to use for the new #GtkEntry.
6914 * Creates a new entry with the specified text buffer.
6916 * Return value: a new #GtkEntry
6921 gtk_entry_new_with_buffer (GtkEntryBuffer *buffer)
6923 g_return_val_if_fail (GTK_IS_ENTRY_BUFFER (buffer), NULL);
6924 return g_object_new (GTK_TYPE_ENTRY, "buffer", buffer, NULL);
6927 static GtkEntryBuffer*
6928 get_buffer (GtkEntry *entry)
6930 GtkEntryPrivate *priv = entry->priv;
6932 if (priv->buffer == NULL)
6934 GtkEntryBuffer *buffer;
6935 buffer = gtk_entry_buffer_new (NULL, 0);
6936 gtk_entry_set_buffer (entry, buffer);
6937 g_object_unref (buffer);
6940 return priv->buffer;
6944 * gtk_entry_get_buffer:
6945 * @entry: a #GtkEntry
6947 * Get the #GtkEntryBuffer object which holds the text for
6952 * Returns: (transfer none): A #GtkEntryBuffer object.
6955 gtk_entry_get_buffer (GtkEntry *entry)
6957 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
6959 return get_buffer (entry);
6963 * gtk_entry_set_buffer:
6964 * @entry: a #GtkEntry
6965 * @buffer: a #GtkEntryBuffer
6967 * Set the #GtkEntryBuffer object which holds the text for
6973 gtk_entry_set_buffer (GtkEntry *entry,
6974 GtkEntryBuffer *buffer)
6976 GtkEntryPrivate *priv;
6979 g_return_if_fail (GTK_IS_ENTRY (entry));
6985 g_return_if_fail (GTK_IS_ENTRY_BUFFER (buffer));
6986 g_object_ref (buffer);
6991 buffer_disconnect_signals (entry);
6992 g_object_unref (priv->buffer);
6995 priv->buffer = buffer;
6998 buffer_connect_signals (entry);
7000 obj = G_OBJECT (entry);
7001 g_object_freeze_notify (obj);
7002 g_object_notify (obj, "buffer");
7003 g_object_notify (obj, "text");
7004 g_object_notify (obj, "text-length");
7005 g_object_notify (obj, "max-length");
7006 g_object_notify (obj, "visibility");
7007 g_object_notify (obj, "invisible-char");
7008 g_object_notify (obj, "invisible-char-set");
7009 g_object_thaw_notify (obj);
7011 gtk_editable_set_position (GTK_EDITABLE (entry), 0);
7012 gtk_entry_recompute (entry);
7016 * gtk_entry_get_text_area:
7017 * @entry: a #GtkEntry
7018 * @text_area: (out): Return location for the text area.
7020 * Gets the area where the entry's text is drawn. This function is
7021 * useful when drawing something to the entry in a draw callback.
7023 * If the entry is not realized, @text_area is filled with zeros.
7025 * See also gtk_entry_get_icon_area().
7030 gtk_entry_get_text_area (GtkEntry *entry,
7031 GdkRectangle *text_area)
7033 GtkEntryPrivate *priv;
7035 g_return_if_fail (GTK_IS_ENTRY (entry));
7036 g_return_if_fail (text_area != NULL);
7040 if (priv->text_area)
7042 GtkAllocation allocation;
7045 gtk_widget_get_allocation (GTK_WIDGET (entry), &allocation);
7046 gdk_window_get_position (priv->text_area, &x, &y);
7048 text_area->x = x - allocation.x;
7049 text_area->y = y - allocation.y;
7050 text_area->width = gdk_window_get_width (priv->text_area);
7051 text_area->height = gdk_window_get_height (priv->text_area);
7057 text_area->width = 0;
7058 text_area->height = 0;
7063 * gtk_entry_set_text:
7064 * @entry: a #GtkEntry
7065 * @text: the new text
7067 * Sets the text in the widget to the given
7068 * value, replacing the current contents.
7070 * See gtk_entry_buffer_set_text().
7073 gtk_entry_set_text (GtkEntry *entry,
7077 GtkEntryCompletion *completion;
7079 g_return_if_fail (GTK_IS_ENTRY (entry));
7080 g_return_if_fail (text != NULL);
7082 /* Actually setting the text will affect the cursor and selection;
7083 * if the contents don't actually change, this will look odd to the user.
7085 if (strcmp (gtk_entry_buffer_get_text (get_buffer (entry)), text) == 0)
7088 completion = gtk_entry_get_completion (entry);
7089 if (completion && completion->priv->changed_id > 0)
7090 g_signal_handler_block (entry, completion->priv->changed_id);
7092 begin_change (entry);
7093 g_object_freeze_notify (G_OBJECT (entry));
7094 gtk_editable_delete_text (GTK_EDITABLE (entry), 0, -1);
7096 gtk_editable_insert_text (GTK_EDITABLE (entry), text, strlen (text), &tmp_pos);
7097 g_object_thaw_notify (G_OBJECT (entry));
7100 if (completion && completion->priv->changed_id > 0)
7101 g_signal_handler_unblock (entry, completion->priv->changed_id);
7105 * gtk_entry_set_visibility:
7106 * @entry: a #GtkEntry
7107 * @visible: %TRUE if the contents of the entry are displayed
7110 * Sets whether the contents of the entry are visible or not.
7111 * When visibility is set to %FALSE, characters are displayed
7112 * as the invisible char, and will also appear that way when
7113 * the text in the entry widget is copied elsewhere.
7115 * By default, GTK+ picks the best invisible character available
7116 * in the current font, but it can be changed with
7117 * gtk_entry_set_invisible_char().
7120 gtk_entry_set_visibility (GtkEntry *entry,
7123 GtkEntryPrivate *priv;
7125 g_return_if_fail (GTK_IS_ENTRY (entry));
7129 visible = visible != FALSE;
7131 if (priv->visible != visible)
7133 priv->visible = visible;
7135 g_object_notify (G_OBJECT (entry), "visibility");
7136 gtk_entry_recompute (entry);
7141 * gtk_entry_get_visibility:
7142 * @entry: a #GtkEntry
7144 * Retrieves whether the text in @entry is visible. See
7145 * gtk_entry_set_visibility().
7147 * Return value: %TRUE if the text is currently visible
7150 gtk_entry_get_visibility (GtkEntry *entry)
7152 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7154 return entry->priv->visible;
7158 * gtk_entry_set_invisible_char:
7159 * @entry: a #GtkEntry
7160 * @ch: a Unicode character
7162 * Sets the character to use in place of the actual text when
7163 * gtk_entry_set_visibility() has been called to set text visibility
7164 * to %FALSE. i.e. this is the character used in "password mode" to
7165 * show the user how many characters have been typed. By default, GTK+
7166 * picks the best invisible char available in the current font. If you
7167 * set the invisible char to 0, then the user will get no feedback
7168 * at all; there will be no text on the screen as they type.
7171 gtk_entry_set_invisible_char (GtkEntry *entry,
7174 GtkEntryPrivate *priv;
7176 g_return_if_fail (GTK_IS_ENTRY (entry));
7180 if (!priv->invisible_char_set)
7182 priv->invisible_char_set = TRUE;
7183 g_object_notify (G_OBJECT (entry), "invisible-char-set");
7186 if (ch == priv->invisible_char)
7189 priv->invisible_char = ch;
7190 g_object_notify (G_OBJECT (entry), "invisible-char");
7191 gtk_entry_recompute (entry);
7195 * gtk_entry_get_invisible_char:
7196 * @entry: a #GtkEntry
7198 * Retrieves the character displayed in place of the real characters
7199 * for entries with visibility set to false. See gtk_entry_set_invisible_char().
7201 * Return value: the current invisible char, or 0, if the entry does not
7202 * show invisible text at all.
7205 gtk_entry_get_invisible_char (GtkEntry *entry)
7207 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7209 return entry->priv->invisible_char;
7213 * gtk_entry_unset_invisible_char:
7214 * @entry: a #GtkEntry
7216 * Unsets the invisible char previously set with
7217 * gtk_entry_set_invisible_char(). So that the
7218 * default invisible char is used again.
7223 gtk_entry_unset_invisible_char (GtkEntry *entry)
7225 GtkEntryPrivate *priv;
7228 g_return_if_fail (GTK_IS_ENTRY (entry));
7232 if (!priv->invisible_char_set)
7235 priv->invisible_char_set = FALSE;
7236 ch = find_invisible_char (GTK_WIDGET (entry));
7238 if (priv->invisible_char != ch)
7240 priv->invisible_char = ch;
7241 g_object_notify (G_OBJECT (entry), "invisible-char");
7244 g_object_notify (G_OBJECT (entry), "invisible-char-set");
7245 gtk_entry_recompute (entry);
7249 * gtk_entry_set_overwrite_mode:
7250 * @entry: a #GtkEntry
7251 * @overwrite: new value
7253 * Sets whether the text is overwritten when typing in the #GtkEntry.
7258 gtk_entry_set_overwrite_mode (GtkEntry *entry,
7261 GtkEntryPrivate *priv = entry->priv;
7263 g_return_if_fail (GTK_IS_ENTRY (entry));
7265 if (priv->overwrite_mode == overwrite)
7268 gtk_entry_toggle_overwrite (entry);
7270 g_object_notify (G_OBJECT (entry), "overwrite-mode");
7274 * gtk_entry_get_overwrite_mode:
7275 * @entry: a #GtkEntry
7277 * Gets the value set by gtk_entry_set_overwrite_mode().
7279 * Return value: whether the text is overwritten when typing.
7284 gtk_entry_get_overwrite_mode (GtkEntry *entry)
7286 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7288 return entry->priv->overwrite_mode;
7292 * gtk_entry_get_text:
7293 * @entry: a #GtkEntry
7295 * Retrieves the contents of the entry widget.
7296 * See also gtk_editable_get_chars().
7298 * This is equivalent to:
7300 * <informalexample><programlisting>
7301 * gtk_entry_buffer_get_text (gtk_entry_get_buffer (entry));
7302 * </programlisting></informalexample>
7304 * Return value: a pointer to the contents of the widget as a
7305 * string. This string points to internally allocated
7306 * storage in the widget and must not be freed, modified or
7310 gtk_entry_get_text (GtkEntry *entry)
7312 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7314 return gtk_entry_buffer_get_text (get_buffer (entry));
7318 * gtk_entry_set_max_length:
7319 * @entry: a #GtkEntry
7320 * @max: the maximum length of the entry, or 0 for no maximum.
7321 * (other than the maximum length of entries.) The value passed in will
7322 * be clamped to the range 0-65536.
7324 * Sets the maximum allowed length of the contents of the widget. If
7325 * the current contents are longer than the given length, then they
7326 * will be truncated to fit.
7328 * This is equivalent to:
7330 * <informalexample><programlisting>
7331 * gtk_entry_buffer_set_max_length (gtk_entry_get_buffer (entry), max);
7332 * </programlisting></informalexample>
7335 gtk_entry_set_max_length (GtkEntry *entry,
7338 g_return_if_fail (GTK_IS_ENTRY (entry));
7339 gtk_entry_buffer_set_max_length (get_buffer (entry), max);
7343 * gtk_entry_get_max_length:
7344 * @entry: a #GtkEntry
7346 * Retrieves the maximum allowed length of the text in
7347 * @entry. See gtk_entry_set_max_length().
7349 * This is equivalent to:
7351 * <informalexample><programlisting>
7352 * gtk_entry_buffer_get_max_length (gtk_entry_get_buffer (entry));
7353 * </programlisting></informalexample>
7355 * Return value: the maximum allowed number of characters
7356 * in #GtkEntry, or 0 if there is no maximum.
7359 gtk_entry_get_max_length (GtkEntry *entry)
7361 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7363 return gtk_entry_buffer_get_max_length (get_buffer (entry));
7367 * gtk_entry_get_text_length:
7368 * @entry: a #GtkEntry
7370 * Retrieves the current length of the text in
7373 * This is equivalent to:
7375 * <informalexample><programlisting>
7376 * gtk_entry_buffer_get_length (gtk_entry_get_buffer (entry));
7377 * </programlisting></informalexample>
7379 * Return value: the current number of characters
7380 * in #GtkEntry, or 0 if there are none.
7385 gtk_entry_get_text_length (GtkEntry *entry)
7387 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7389 return gtk_entry_buffer_get_length (get_buffer (entry));
7393 * gtk_entry_set_activates_default:
7394 * @entry: a #GtkEntry
7395 * @setting: %TRUE to activate window's default widget on Enter keypress
7397 * If @setting is %TRUE, pressing Enter in the @entry will activate the default
7398 * widget for the window containing the entry. This usually means that
7399 * the dialog box containing the entry will be closed, since the default
7400 * widget is usually one of the dialog buttons.
7402 * (For experts: if @setting is %TRUE, the entry calls
7403 * gtk_window_activate_default() on the window containing the entry, in
7404 * the default handler for the #GtkWidget::activate signal.)
7407 gtk_entry_set_activates_default (GtkEntry *entry,
7410 GtkEntryPrivate *priv;
7412 g_return_if_fail (GTK_IS_ENTRY (entry));
7416 setting = setting != FALSE;
7418 if (setting != priv->activates_default)
7420 priv->activates_default = setting;
7421 g_object_notify (G_OBJECT (entry), "activates-default");
7426 * gtk_entry_get_activates_default:
7427 * @entry: a #GtkEntry
7429 * Retrieves the value set by gtk_entry_set_activates_default().
7431 * Return value: %TRUE if the entry will activate the default widget
7434 gtk_entry_get_activates_default (GtkEntry *entry)
7436 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7438 return entry->priv->activates_default;
7442 * gtk_entry_set_width_chars:
7443 * @entry: a #GtkEntry
7444 * @n_chars: width in chars
7446 * Changes the size request of the entry to be about the right size
7447 * for @n_chars characters. Note that it changes the size
7448 * <emphasis>request</emphasis>, the size can still be affected by
7449 * how you pack the widget into containers. If @n_chars is -1, the
7450 * size reverts to the default entry size.
7453 gtk_entry_set_width_chars (GtkEntry *entry,
7456 GtkEntryPrivate *priv;
7458 g_return_if_fail (GTK_IS_ENTRY (entry));
7462 if (priv->width_chars != n_chars)
7464 priv->width_chars = n_chars;
7465 g_object_notify (G_OBJECT (entry), "width-chars");
7466 gtk_widget_queue_resize (GTK_WIDGET (entry));
7471 * gtk_entry_get_width_chars:
7472 * @entry: a #GtkEntry
7474 * Gets the value set by gtk_entry_set_width_chars().
7476 * Return value: number of chars to request space for, or negative if unset
7479 gtk_entry_get_width_chars (GtkEntry *entry)
7481 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7483 return entry->priv->width_chars;
7487 * gtk_entry_set_has_frame:
7488 * @entry: a #GtkEntry
7489 * @setting: new value
7491 * Sets whether the entry has a beveled frame around it.
7494 gtk_entry_set_has_frame (GtkEntry *entry,
7497 GtkEntryPrivate *priv;
7499 g_return_if_fail (GTK_IS_ENTRY (entry));
7503 setting = (setting != FALSE);
7505 if (priv->has_frame == setting)
7508 gtk_widget_queue_resize (GTK_WIDGET (entry));
7509 priv->has_frame = setting;
7510 g_object_notify (G_OBJECT (entry), "has-frame");
7514 * gtk_entry_get_has_frame:
7515 * @entry: a #GtkEntry
7517 * Gets the value set by gtk_entry_set_has_frame().
7519 * Return value: whether the entry has a beveled frame
7522 gtk_entry_get_has_frame (GtkEntry *entry)
7524 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7526 return entry->priv->has_frame;
7530 * gtk_entry_set_inner_border:
7531 * @entry: a #GtkEntry
7532 * @border: (allow-none): a #GtkBorder, or %NULL
7534 * Sets %entry's inner-border property to %border, or clears it if %NULL
7535 * is passed. The inner-border is the area around the entry's text, but
7538 * If set, this property overrides the inner-border style property.
7539 * Overriding the style-provided border is useful when you want to do
7540 * in-place editing of some text in a canvas or list widget, where
7541 * pixel-exact positioning of the entry is important.
7546 gtk_entry_set_inner_border (GtkEntry *entry,
7547 const GtkBorder *border)
7549 g_return_if_fail (GTK_IS_ENTRY (entry));
7551 gtk_widget_queue_resize (GTK_WIDGET (entry));
7554 g_object_set_qdata_full (G_OBJECT (entry), quark_inner_border,
7555 gtk_border_copy (border),
7556 (GDestroyNotify) gtk_border_free);
7558 g_object_set_qdata (G_OBJECT (entry), quark_inner_border, NULL);
7560 g_object_notify (G_OBJECT (entry), "inner-border");
7564 * gtk_entry_get_inner_border:
7565 * @entry: a #GtkEntry
7567 * This function returns the entry's #GtkEntry:inner-border property. See
7568 * gtk_entry_set_inner_border() for more information.
7570 * Return value: (transfer none): the entry's #GtkBorder, or %NULL if none was set.
7575 gtk_entry_get_inner_border (GtkEntry *entry)
7577 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7579 return g_object_get_qdata (G_OBJECT (entry), quark_inner_border);
7583 * gtk_entry_get_layout:
7584 * @entry: a #GtkEntry
7586 * Gets the #PangoLayout used to display the entry.
7587 * The layout is useful to e.g. convert text positions to
7588 * pixel positions, in combination with gtk_entry_get_layout_offsets().
7589 * The returned layout is owned by the entry and must not be
7590 * modified or freed by the caller.
7592 * Keep in mind that the layout text may contain a preedit string, so
7593 * gtk_entry_layout_index_to_text_index() and
7594 * gtk_entry_text_index_to_layout_index() are needed to convert byte
7595 * indices in the layout to byte indices in the entry contents.
7597 * Return value: (transfer none): the #PangoLayout for this entry
7600 gtk_entry_get_layout (GtkEntry *entry)
7602 PangoLayout *layout;
7604 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7606 layout = gtk_entry_ensure_layout (entry, TRUE);
7613 * gtk_entry_layout_index_to_text_index:
7614 * @entry: a #GtkEntry
7615 * @layout_index: byte index into the entry layout text
7617 * Converts from a position in the entry contents (returned
7618 * by gtk_entry_get_text()) to a position in the
7619 * entry's #PangoLayout (returned by gtk_entry_get_layout(),
7620 * with text retrieved via pango_layout_get_text()).
7622 * Return value: byte index into the entry contents
7625 gtk_entry_layout_index_to_text_index (GtkEntry *entry,
7628 GtkEntryPrivate *priv;
7629 PangoLayout *layout;
7633 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7637 layout = gtk_entry_ensure_layout (entry, TRUE);
7638 text = pango_layout_get_text (layout);
7639 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos) - text;
7641 if (layout_index >= cursor_index && priv->preedit_length)
7643 if (layout_index >= cursor_index + priv->preedit_length)
7644 layout_index -= priv->preedit_length;
7646 layout_index = cursor_index;
7649 return layout_index;
7653 * gtk_entry_text_index_to_layout_index:
7654 * @entry: a #GtkEntry
7655 * @text_index: byte index into the entry contents
7657 * Converts from a position in the entry's #PangoLayout (returned by
7658 * gtk_entry_get_layout()) to a position in the entry contents
7659 * (returned by gtk_entry_get_text()).
7661 * Return value: byte index into the entry layout text
7664 gtk_entry_text_index_to_layout_index (GtkEntry *entry,
7667 GtkEntryPrivate *priv;
7668 PangoLayout *layout;
7672 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7676 layout = gtk_entry_ensure_layout (entry, TRUE);
7677 text = pango_layout_get_text (layout);
7678 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos) - text;
7680 if (text_index > cursor_index)
7681 text_index += priv->preedit_length;
7687 * gtk_entry_get_layout_offsets:
7688 * @entry: a #GtkEntry
7689 * @x: (out) (allow-none): location to store X offset of layout, or %NULL
7690 * @y: (out) (allow-none): location to store Y offset of layout, or %NULL
7693 * Obtains the position of the #PangoLayout used to render text
7694 * in the entry, in widget coordinates. Useful if you want to line
7695 * up the text in an entry with some other text, e.g. when using the
7696 * entry to implement editable cells in a sheet widget.
7698 * Also useful to convert mouse events into coordinates inside the
7699 * #PangoLayout, e.g. to take some action if some part of the entry text
7702 * Note that as the user scrolls around in the entry the offsets will
7703 * change; you'll need to connect to the "notify::scroll-offset"
7704 * signal to track this. Remember when using the #PangoLayout
7705 * functions you need to convert to and from pixels using
7706 * PANGO_PIXELS() or #PANGO_SCALE.
7708 * Keep in mind that the layout text may contain a preedit string, so
7709 * gtk_entry_layout_index_to_text_index() and
7710 * gtk_entry_text_index_to_layout_index() are needed to convert byte
7711 * indices in the layout to byte indices in the entry contents.
7714 gtk_entry_get_layout_offsets (GtkEntry *entry,
7718 gint text_area_x, text_area_y;
7720 g_return_if_fail (GTK_IS_ENTRY (entry));
7722 /* this gets coords relative to text area */
7723 get_layout_position (entry, x, y);
7725 /* convert to widget coords */
7726 gtk_entry_get_text_area_size (entry, &text_area_x, &text_area_y, NULL, NULL);
7737 * gtk_entry_set_alignment:
7738 * @entry: a #GtkEntry
7739 * @xalign: The horizontal alignment, from 0 (left) to 1 (right).
7740 * Reversed for RTL layouts
7742 * Sets the alignment for the contents of the entry. This controls
7743 * the horizontal positioning of the contents when the displayed
7744 * text is shorter than the width of the entry.
7749 gtk_entry_set_alignment (GtkEntry *entry, gfloat xalign)
7751 GtkEntryPrivate *priv;
7753 g_return_if_fail (GTK_IS_ENTRY (entry));
7759 else if (xalign > 1.0)
7762 if (xalign != priv->xalign)
7764 priv->xalign = xalign;
7766 gtk_entry_recompute (entry);
7768 g_object_notify (G_OBJECT (entry), "xalign");
7773 * gtk_entry_get_alignment:
7774 * @entry: a #GtkEntry
7776 * Gets the value set by gtk_entry_set_alignment().
7778 * Return value: the alignment
7783 gtk_entry_get_alignment (GtkEntry *entry)
7785 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
7787 return entry->priv->xalign;
7791 * gtk_entry_set_icon_from_pixbuf:
7792 * @entry: a #GtkEntry
7793 * @icon_pos: Icon position
7794 * @pixbuf: (allow-none): A #GdkPixbuf, or %NULL
7796 * Sets the icon shown in the specified position using a pixbuf.
7798 * If @pixbuf is %NULL, no icon will be shown in the specified position.
7803 gtk_entry_set_icon_from_pixbuf (GtkEntry *entry,
7804 GtkEntryIconPosition icon_pos,
7807 GtkEntryPrivate *priv;
7808 EntryIconInfo *icon_info;
7810 g_return_if_fail (GTK_IS_ENTRY (entry));
7811 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7815 if ((icon_info = priv->icons[icon_pos]) == NULL)
7816 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7818 g_object_freeze_notify (G_OBJECT (entry));
7821 g_object_ref (pixbuf);
7823 gtk_entry_clear (entry, icon_pos);
7827 icon_info->storage_type = GTK_IMAGE_PIXBUF;
7828 icon_info->pixbuf = pixbuf;
7830 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7832 g_object_notify (G_OBJECT (entry), "primary-icon-pixbuf");
7833 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7837 g_object_notify (G_OBJECT (entry), "secondary-icon-pixbuf");
7838 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7841 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7842 gdk_window_show_unraised (icon_info->window);
7845 gtk_entry_ensure_pixbuf (entry, icon_pos);
7847 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7848 gtk_widget_queue_resize (GTK_WIDGET (entry));
7850 g_object_thaw_notify (G_OBJECT (entry));
7854 * gtk_entry_set_icon_from_stock:
7855 * @entry: A #GtkEntry
7856 * @icon_pos: Icon position
7857 * @stock_id: (allow-none): The name of the stock item, or %NULL
7859 * Sets the icon shown in the entry at the specified position from
7862 * If @stock_id is %NULL, no icon will be shown in the specified position.
7867 gtk_entry_set_icon_from_stock (GtkEntry *entry,
7868 GtkEntryIconPosition icon_pos,
7869 const gchar *stock_id)
7871 GtkEntryPrivate *priv;
7872 EntryIconInfo *icon_info;
7875 g_return_if_fail (GTK_IS_ENTRY (entry));
7876 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7880 if ((icon_info = priv->icons[icon_pos]) == NULL)
7881 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7883 g_object_freeze_notify (G_OBJECT (entry));
7885 /* need to dup before clearing */
7886 new_id = g_strdup (stock_id);
7888 gtk_entry_clear (entry, icon_pos);
7892 icon_info->storage_type = GTK_IMAGE_STOCK;
7893 icon_info->stock_id = new_id;
7895 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7897 g_object_notify (G_OBJECT (entry), "primary-icon-stock");
7898 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7902 g_object_notify (G_OBJECT (entry), "secondary-icon-stock");
7903 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7906 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7907 gdk_window_show_unraised (icon_info->window);
7910 gtk_entry_ensure_pixbuf (entry, icon_pos);
7912 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7913 gtk_widget_queue_resize (GTK_WIDGET (entry));
7915 g_object_thaw_notify (G_OBJECT (entry));
7919 * gtk_entry_set_icon_from_icon_name:
7920 * @entry: A #GtkEntry
7921 * @icon_pos: The position at which to set the icon
7922 * @icon_name: (allow-none): An icon name, or %NULL
7924 * Sets the icon shown in the entry at the specified position
7925 * from the current icon theme.
7927 * If the icon name isn't known, a "broken image" icon will be displayed
7930 * If @icon_name is %NULL, no icon will be shown in the specified position.
7935 gtk_entry_set_icon_from_icon_name (GtkEntry *entry,
7936 GtkEntryIconPosition icon_pos,
7937 const gchar *icon_name)
7939 GtkEntryPrivate *priv;
7940 EntryIconInfo *icon_info;
7943 g_return_if_fail (GTK_IS_ENTRY (entry));
7944 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7948 if ((icon_info = priv->icons[icon_pos]) == NULL)
7949 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7951 g_object_freeze_notify (G_OBJECT (entry));
7953 /* need to dup before clearing */
7954 new_name = g_strdup (icon_name);
7956 gtk_entry_clear (entry, icon_pos);
7958 if (new_name != NULL)
7960 icon_info->storage_type = GTK_IMAGE_ICON_NAME;
7961 icon_info->icon_name = new_name;
7963 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7965 g_object_notify (G_OBJECT (entry), "primary-icon-name");
7966 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7970 g_object_notify (G_OBJECT (entry), "secondary-icon-name");
7971 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7974 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7975 gdk_window_show_unraised (icon_info->window);
7978 gtk_entry_ensure_pixbuf (entry, icon_pos);
7980 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7981 gtk_widget_queue_resize (GTK_WIDGET (entry));
7983 g_object_thaw_notify (G_OBJECT (entry));
7987 * gtk_entry_set_icon_from_gicon:
7988 * @entry: A #GtkEntry
7989 * @icon_pos: The position at which to set the icon
7990 * @icon: (allow-none): The icon to set, or %NULL
7992 * Sets the icon shown in the entry at the specified position
7993 * from the current icon theme.
7994 * If the icon isn't known, a "broken image" icon will be displayed
7997 * If @icon is %NULL, no icon will be shown in the specified position.
8002 gtk_entry_set_icon_from_gicon (GtkEntry *entry,
8003 GtkEntryIconPosition icon_pos,
8006 GtkEntryPrivate *priv;
8007 EntryIconInfo *icon_info;
8009 g_return_if_fail (GTK_IS_ENTRY (entry));
8010 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8014 if ((icon_info = priv->icons[icon_pos]) == NULL)
8015 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8017 g_object_freeze_notify (G_OBJECT (entry));
8019 /* need to ref before clearing */
8021 g_object_ref (icon);
8023 gtk_entry_clear (entry, icon_pos);
8027 icon_info->storage_type = GTK_IMAGE_GICON;
8028 icon_info->gicon = icon;
8030 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
8032 g_object_notify (G_OBJECT (entry), "primary-icon-gicon");
8033 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
8037 g_object_notify (G_OBJECT (entry), "secondary-icon-gicon");
8038 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
8041 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
8042 gdk_window_show_unraised (icon_info->window);
8045 gtk_entry_ensure_pixbuf (entry, icon_pos);
8047 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
8048 gtk_widget_queue_resize (GTK_WIDGET (entry));
8050 g_object_thaw_notify (G_OBJECT (entry));
8054 * gtk_entry_set_icon_activatable:
8055 * @entry: A #GtkEntry
8056 * @icon_pos: Icon position
8057 * @activatable: %TRUE if the icon should be activatable
8059 * Sets whether the icon is activatable.
8064 gtk_entry_set_icon_activatable (GtkEntry *entry,
8065 GtkEntryIconPosition icon_pos,
8066 gboolean activatable)
8068 GtkEntryPrivate *priv;
8069 EntryIconInfo *icon_info;
8071 g_return_if_fail (GTK_IS_ENTRY (entry));
8072 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8076 if ((icon_info = priv->icons[icon_pos]) == NULL)
8077 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8079 activatable = activatable != FALSE;
8081 if (icon_info->nonactivatable != !activatable)
8083 icon_info->nonactivatable = !activatable;
8085 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
8086 update_cursors (GTK_WIDGET (entry));
8088 g_object_notify (G_OBJECT (entry),
8089 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-activatable" : "secondary-icon-activatable");
8094 * gtk_entry_get_icon_activatable:
8095 * @entry: a #GtkEntry
8096 * @icon_pos: Icon position
8098 * Returns whether the icon is activatable.
8100 * Returns: %TRUE if the icon is activatable.
8105 gtk_entry_get_icon_activatable (GtkEntry *entry,
8106 GtkEntryIconPosition icon_pos)
8108 GtkEntryPrivate *priv;
8109 EntryIconInfo *icon_info;
8111 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
8112 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), FALSE);
8115 icon_info = priv->icons[icon_pos];
8117 return (!icon_info || !icon_info->nonactivatable);
8121 * gtk_entry_get_icon_pixbuf:
8122 * @entry: A #GtkEntry
8123 * @icon_pos: Icon position
8125 * Retrieves the image used for the icon.
8127 * Unlike the other methods of setting and getting icon data, this
8128 * method will work regardless of whether the icon was set using a
8129 * #GdkPixbuf, a #GIcon, a stock item, or an icon name.
8131 * Returns: (transfer none): A #GdkPixbuf, or %NULL if no icon is
8132 * set for this position.
8137 gtk_entry_get_icon_pixbuf (GtkEntry *entry,
8138 GtkEntryIconPosition icon_pos)
8140 GtkEntryPrivate *priv;
8141 EntryIconInfo *icon_info;
8143 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8144 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8148 icon_info = priv->icons[icon_pos];
8153 gtk_entry_ensure_pixbuf (entry, icon_pos);
8155 return icon_info->pixbuf;
8159 * gtk_entry_get_icon_gicon:
8160 * @entry: A #GtkEntry
8161 * @icon_pos: Icon position
8163 * Retrieves the #GIcon used for the icon, or %NULL if there is
8164 * no icon or if the icon was set by some other method (e.g., by
8165 * stock, pixbuf, or icon name).
8167 * Returns: (transfer none): A #GIcon, or %NULL if no icon is set
8168 * or if the icon is not a #GIcon
8173 gtk_entry_get_icon_gicon (GtkEntry *entry,
8174 GtkEntryIconPosition icon_pos)
8176 GtkEntryPrivate *priv;
8177 EntryIconInfo *icon_info;
8179 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8180 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8183 icon_info = priv->icons[icon_pos];
8188 return icon_info->storage_type == GTK_IMAGE_GICON ? icon_info->gicon : NULL;
8192 * gtk_entry_get_icon_stock:
8193 * @entry: A #GtkEntry
8194 * @icon_pos: Icon position
8196 * Retrieves the stock id used for the icon, or %NULL if there is
8197 * no icon or if the icon was set by some other method (e.g., by
8198 * pixbuf, icon name or gicon).
8200 * Returns: A stock id, or %NULL if no icon is set or if the icon
8201 * wasn't set from a stock id
8206 gtk_entry_get_icon_stock (GtkEntry *entry,
8207 GtkEntryIconPosition icon_pos)
8209 GtkEntryPrivate *priv;
8210 EntryIconInfo *icon_info;
8212 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8213 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8216 icon_info = priv->icons[icon_pos];
8221 return icon_info->storage_type == GTK_IMAGE_STOCK ? icon_info->stock_id : NULL;
8225 * gtk_entry_get_icon_name:
8226 * @entry: A #GtkEntry
8227 * @icon_pos: Icon position
8229 * Retrieves the icon name used for the icon, or %NULL if there is
8230 * no icon or if the icon was set by some other method (e.g., by
8231 * pixbuf, stock or gicon).
8233 * Returns: An icon name, or %NULL if no icon is set or if the icon
8234 * wasn't set from an icon name
8239 gtk_entry_get_icon_name (GtkEntry *entry,
8240 GtkEntryIconPosition icon_pos)
8242 GtkEntryPrivate *priv;
8243 EntryIconInfo *icon_info;
8245 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8246 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8249 icon_info = priv->icons[icon_pos];
8254 return icon_info->storage_type == GTK_IMAGE_ICON_NAME ? icon_info->icon_name : NULL;
8258 * gtk_entry_set_icon_sensitive:
8259 * @entry: A #GtkEntry
8260 * @icon_pos: Icon position
8261 * @sensitive: Specifies whether the icon should appear
8262 * sensitive or insensitive
8264 * Sets the sensitivity for the specified icon.
8269 gtk_entry_set_icon_sensitive (GtkEntry *entry,
8270 GtkEntryIconPosition icon_pos,
8273 GtkEntryPrivate *priv;
8274 EntryIconInfo *icon_info;
8276 g_return_if_fail (GTK_IS_ENTRY (entry));
8277 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8281 if ((icon_info = priv->icons[icon_pos]) == NULL)
8282 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8284 if (icon_info->insensitive != !sensitive)
8286 icon_info->insensitive = !sensitive;
8288 icon_info->pressed = FALSE;
8289 icon_info->prelight = FALSE;
8291 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
8292 update_cursors (GTK_WIDGET (entry));
8294 gtk_widget_queue_draw (GTK_WIDGET (entry));
8296 g_object_notify (G_OBJECT (entry),
8297 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-sensitive" : "secondary-icon-sensitive");
8302 * gtk_entry_get_icon_sensitive:
8303 * @entry: a #GtkEntry
8304 * @icon_pos: Icon position
8306 * Returns whether the icon appears sensitive or insensitive.
8308 * Returns: %TRUE if the icon is sensitive.
8313 gtk_entry_get_icon_sensitive (GtkEntry *entry,
8314 GtkEntryIconPosition icon_pos)
8316 GtkEntryPrivate *priv;
8317 EntryIconInfo *icon_info;
8319 g_return_val_if_fail (GTK_IS_ENTRY (entry), TRUE);
8320 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), TRUE);
8324 icon_info = priv->icons[icon_pos];
8326 return (!icon_info || !icon_info->insensitive);
8331 * gtk_entry_get_icon_storage_type:
8332 * @entry: a #GtkEntry
8333 * @icon_pos: Icon position
8335 * Gets the type of representation being used by the icon
8336 * to store image data. If the icon has no image data,
8337 * the return value will be %GTK_IMAGE_EMPTY.
8339 * Return value: image representation being used
8344 gtk_entry_get_icon_storage_type (GtkEntry *entry,
8345 GtkEntryIconPosition icon_pos)
8347 GtkEntryPrivate *priv;
8348 EntryIconInfo *icon_info;
8350 g_return_val_if_fail (GTK_IS_ENTRY (entry), GTK_IMAGE_EMPTY);
8351 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), GTK_IMAGE_EMPTY);
8355 icon_info = priv->icons[icon_pos];
8358 return GTK_IMAGE_EMPTY;
8360 return icon_info->storage_type;
8364 * gtk_entry_get_icon_at_pos:
8365 * @entry: a #GtkEntry
8366 * @x: the x coordinate of the position to find
8367 * @y: the y coordinate of the position to find
8369 * Finds the icon at the given position and return its index. The
8370 * position's coordinates are relative to the @entry's top left corner.
8371 * If @x, @y doesn't lie inside an icon, -1 is returned.
8372 * This function is intended for use in a #GtkWidget::query-tooltip
8375 * Returns: the index of the icon at the given position, or -1
8380 gtk_entry_get_icon_at_pos (GtkEntry *entry,
8384 GtkAllocation primary;
8385 GtkAllocation secondary;
8386 gint frame_x, frame_y;
8388 g_return_val_if_fail (GTK_IS_ENTRY (entry), -1);
8390 get_frame_size (entry, FALSE, &frame_x, &frame_y, NULL, NULL);
8394 get_icon_allocations (entry, &primary, &secondary);
8396 if (primary.x <= x && x < primary.x + primary.width &&
8397 primary.y <= y && y < primary.y + primary.height)
8398 return GTK_ENTRY_ICON_PRIMARY;
8400 if (secondary.x <= x && x < secondary.x + secondary.width &&
8401 secondary.y <= y && y < secondary.y + secondary.height)
8402 return GTK_ENTRY_ICON_SECONDARY;
8408 * gtk_entry_set_icon_drag_source:
8409 * @entry: a #GtkIconEntry
8410 * @icon_pos: icon position
8411 * @target_list: the targets (data formats) in which the data can be provided
8412 * @actions: a bitmask of the allowed drag actions
8414 * Sets up the icon at the given position so that GTK+ will start a drag
8415 * operation when the user clicks and drags the icon.
8417 * To handle the drag operation, you need to connect to the usual
8418 * #GtkWidget::drag-data-get (or possibly #GtkWidget::drag-data-delete)
8419 * signal, and use gtk_entry_get_current_icon_drag_source() in
8420 * your signal handler to find out if the drag was started from
8423 * By default, GTK+ uses the icon as the drag icon. You can use the
8424 * #GtkWidget::drag-begin signal to set a different icon. Note that you
8425 * have to use g_signal_connect_after() to ensure that your signal handler
8426 * gets executed after the default handler.
8431 gtk_entry_set_icon_drag_source (GtkEntry *entry,
8432 GtkEntryIconPosition icon_pos,
8433 GtkTargetList *target_list,
8434 GdkDragAction actions)
8436 GtkEntryPrivate *priv;
8437 EntryIconInfo *icon_info;
8439 g_return_if_fail (GTK_IS_ENTRY (entry));
8440 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8444 if ((icon_info = priv->icons[icon_pos]) == NULL)
8445 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8447 if (icon_info->target_list)
8448 gtk_target_list_unref (icon_info->target_list);
8449 icon_info->target_list = target_list;
8450 if (icon_info->target_list)
8451 gtk_target_list_ref (icon_info->target_list);
8453 icon_info->actions = actions;
8457 * gtk_entry_get_current_icon_drag_source:
8458 * @entry: a #GtkIconEntry
8460 * Returns the index of the icon which is the source of the current
8461 * DND operation, or -1.
8463 * This function is meant to be used in a #GtkWidget::drag-data-get
8466 * Returns: index of the icon which is the source of the current
8467 * DND operation, or -1.
8472 gtk_entry_get_current_icon_drag_source (GtkEntry *entry)
8474 GtkEntryPrivate *priv;
8475 EntryIconInfo *icon_info = NULL;
8478 g_return_val_if_fail (GTK_IS_ENTRY (entry), -1);
8482 for (i = 0; i < MAX_ICONS; i++)
8484 if ((icon_info = priv->icons[i]))
8486 if (icon_info->in_drag)
8495 * gtk_entry_get_icon_area:
8496 * @entry: A #GtkEntry
8497 * @icon_pos: Icon position
8498 * @icon_area: (out): Return location for the icon's area
8500 * Gets the area where entry's icon at @icon_pos is drawn.
8501 * This function is useful when drawing something to the
8502 * entry in a draw callback.
8504 * If the entry is not realized or has no icon at the given position,
8505 * @icon_area is filled with zeros.
8507 * See also gtk_entry_get_text_area()
8512 gtk_entry_get_icon_area (GtkEntry *entry,
8513 GtkEntryIconPosition icon_pos,
8514 GdkRectangle *icon_area)
8516 GtkEntryPrivate *priv;
8517 EntryIconInfo *icon_info;
8519 g_return_if_fail (GTK_IS_ENTRY (entry));
8520 g_return_if_fail (icon_area != NULL);
8524 icon_info = priv->icons[icon_pos];
8528 GtkAllocation primary;
8529 GtkAllocation secondary;
8531 get_icon_allocations (entry, &primary, &secondary);
8533 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
8534 *icon_area = primary;
8536 *icon_area = secondary;
8542 icon_area->width = 0;
8543 icon_area->height = 0;
8548 ensure_has_tooltip (GtkEntry *entry)
8550 GtkEntryPrivate *priv;
8551 EntryIconInfo *icon_info;
8553 gboolean has_tooltip = FALSE;
8557 for (i = 0; i < MAX_ICONS; i++)
8559 if ((icon_info = priv->icons[i]) != NULL)
8561 if (icon_info->tooltip != NULL)
8569 gtk_widget_set_has_tooltip (GTK_WIDGET (entry), has_tooltip);
8573 * gtk_entry_get_icon_tooltip_text:
8574 * @entry: a #GtkEntry
8575 * @icon_pos: the icon position
8577 * Gets the contents of the tooltip on the icon at the specified
8578 * position in @entry.
8580 * Returns: the tooltip text, or %NULL. Free the returned string
8581 * with g_free() when done.
8586 gtk_entry_get_icon_tooltip_text (GtkEntry *entry,
8587 GtkEntryIconPosition icon_pos)
8589 GtkEntryPrivate *priv;
8590 EntryIconInfo *icon_info;
8593 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8594 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8598 icon_info = priv->icons[icon_pos];
8603 if (icon_info->tooltip &&
8604 !pango_parse_markup (icon_info->tooltip, -1, 0, NULL, &text, NULL, NULL))
8605 g_assert (NULL == text); /* text should still be NULL in case of markup errors */
8611 * gtk_entry_set_icon_tooltip_text:
8612 * @entry: a #GtkEntry
8613 * @icon_pos: the icon position
8614 * @tooltip: (allow-none): the contents of the tooltip for the icon, or %NULL
8616 * Sets @tooltip as the contents of the tooltip for the icon
8617 * at the specified position.
8619 * Use %NULL for @tooltip to remove an existing tooltip.
8621 * See also gtk_widget_set_tooltip_text() and
8622 * gtk_entry_set_icon_tooltip_markup().
8627 gtk_entry_set_icon_tooltip_text (GtkEntry *entry,
8628 GtkEntryIconPosition icon_pos,
8629 const gchar *tooltip)
8631 GtkEntryPrivate *priv;
8632 EntryIconInfo *icon_info;
8634 g_return_if_fail (GTK_IS_ENTRY (entry));
8635 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8639 if ((icon_info = priv->icons[icon_pos]) == NULL)
8640 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8642 if (icon_info->tooltip)
8643 g_free (icon_info->tooltip);
8645 /* Treat an empty string as a NULL string,
8646 * because an empty string would be useless for a tooltip:
8648 if (tooltip && tooltip[0] == '\0')
8651 icon_info->tooltip = tooltip ? g_markup_escape_text (tooltip, -1) : NULL;
8653 ensure_has_tooltip (entry);
8657 * gtk_entry_get_icon_tooltip_markup:
8658 * @entry: a #GtkEntry
8659 * @icon_pos: the icon position
8661 * Gets the contents of the tooltip on the icon at the specified
8662 * position in @entry.
8664 * Returns: the tooltip text, or %NULL. Free the returned string
8665 * with g_free() when done.
8670 gtk_entry_get_icon_tooltip_markup (GtkEntry *entry,
8671 GtkEntryIconPosition icon_pos)
8673 GtkEntryPrivate *priv;
8674 EntryIconInfo *icon_info;
8676 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8677 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8681 icon_info = priv->icons[icon_pos];
8686 return g_strdup (icon_info->tooltip);
8690 * gtk_entry_set_icon_tooltip_markup:
8691 * @entry: a #GtkEntry
8692 * @icon_pos: the icon position
8693 * @tooltip: (allow-none): the contents of the tooltip for the icon, or %NULL
8695 * Sets @tooltip as the contents of the tooltip for the icon at
8696 * the specified position. @tooltip is assumed to be marked up with
8697 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
8699 * Use %NULL for @tooltip to remove an existing tooltip.
8701 * See also gtk_widget_set_tooltip_markup() and
8702 * gtk_enty_set_icon_tooltip_text().
8707 gtk_entry_set_icon_tooltip_markup (GtkEntry *entry,
8708 GtkEntryIconPosition icon_pos,
8709 const gchar *tooltip)
8711 GtkEntryPrivate *priv;
8712 EntryIconInfo *icon_info;
8714 g_return_if_fail (GTK_IS_ENTRY (entry));
8715 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8719 if ((icon_info = priv->icons[icon_pos]) == NULL)
8720 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8722 if (icon_info->tooltip)
8723 g_free (icon_info->tooltip);
8725 /* Treat an empty string as a NULL string,
8726 * because an empty string would be useless for a tooltip:
8728 if (tooltip && tooltip[0] == '\0')
8731 icon_info->tooltip = g_strdup (tooltip);
8733 ensure_has_tooltip (entry);
8737 gtk_entry_query_tooltip (GtkWidget *widget,
8740 gboolean keyboard_tip,
8741 GtkTooltip *tooltip)
8744 GtkEntryPrivate *priv;
8745 EntryIconInfo *icon_info;
8748 entry = GTK_ENTRY (widget);
8753 icon_pos = gtk_entry_get_icon_at_pos (entry, x, y);
8756 if ((icon_info = priv->icons[icon_pos]) != NULL)
8758 if (icon_info->tooltip)
8760 gtk_tooltip_set_markup (tooltip, icon_info->tooltip);
8769 return GTK_WIDGET_CLASS (gtk_entry_parent_class)->query_tooltip (widget,
8776 /* Quick hack of a popup menu
8779 activate_cb (GtkWidget *menuitem,
8782 const gchar *signal = g_object_get_data (G_OBJECT (menuitem), "gtk-signal");
8783 g_signal_emit_by_name (entry, signal);
8788 gtk_entry_mnemonic_activate (GtkWidget *widget,
8789 gboolean group_cycling)
8791 gtk_widget_grab_focus (widget);
8796 append_action_signal (GtkEntry *entry,
8798 const gchar *stock_id,
8799 const gchar *signal,
8802 GtkWidget *menuitem = gtk_image_menu_item_new_from_stock (stock_id, NULL);
8804 g_object_set_data (G_OBJECT (menuitem), I_("gtk-signal"), (char *)signal);
8805 g_signal_connect (menuitem, "activate",
8806 G_CALLBACK (activate_cb), entry);
8808 gtk_widget_set_sensitive (menuitem, sensitive);
8810 gtk_widget_show (menuitem);
8811 gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
8815 popup_menu_detach (GtkWidget *attach_widget,
8818 GtkEntry *entry_attach = GTK_ENTRY (attach_widget);
8819 GtkEntryPrivate *priv_attach = entry_attach->priv;
8821 priv_attach->popup_menu = NULL;
8825 popup_position_func (GtkMenu *menu,
8831 GtkEntry *entry = GTK_ENTRY (user_data);
8832 GtkEntryPrivate *priv = entry->priv;
8833 GtkWidget *widget = GTK_WIDGET (entry);
8835 GtkRequisition menu_req;
8836 GdkRectangle monitor;
8837 GtkBorder inner_border;
8838 gint monitor_num, strong_x, height;
8840 g_return_if_fail (gtk_widget_get_realized (widget));
8842 gdk_window_get_origin (priv->text_area, x, y);
8844 screen = gtk_widget_get_screen (widget);
8845 monitor_num = gdk_screen_get_monitor_at_window (screen, priv->text_area);
8846 if (monitor_num < 0)
8848 gtk_menu_set_monitor (menu, monitor_num);
8850 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
8851 gtk_widget_get_preferred_size (priv->popup_menu,
8853 height = gdk_window_get_height (priv->text_area);
8854 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
8855 _gtk_entry_effective_inner_border (entry, &inner_border);
8857 *x += inner_border.left + strong_x - priv->scroll_offset;
8858 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
8859 *x -= menu_req.width;
8861 if ((*y + height + menu_req.height) <= monitor.y + monitor.height)
8863 else if ((*y - menu_req.height) >= monitor.y)
8864 *y -= menu_req.height;
8865 else if (monitor.y + monitor.height - (*y + height) > *y)
8868 *y -= menu_req.height;
8874 unichar_chosen_func (const char *text,
8877 GtkEntry *entry = GTK_ENTRY (data);
8878 GtkEntryPrivate *priv = entry->priv;
8881 gtk_entry_enter_text (entry, text);
8893 popup_targets_received (GtkClipboard *clipboard,
8894 GtkSelectionData *data,
8897 PopupInfo *info = user_data;
8898 GtkEntry *entry = info->entry;
8899 GtkEntryPrivate *info_entry_priv = entry->priv;
8901 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
8904 gboolean clipboard_contains_text;
8905 GtkWidget *menuitem;
8907 gboolean show_input_method_menu;
8908 gboolean show_unicode_menu;
8910 clipboard_contains_text = gtk_selection_data_targets_include_text (data);
8911 if (info_entry_priv->popup_menu)
8912 gtk_widget_destroy (info_entry_priv->popup_menu);
8914 info_entry_priv->popup_menu = gtk_menu_new ();
8916 gtk_menu_attach_to_widget (GTK_MENU (info_entry_priv->popup_menu),
8920 mode = gtk_entry_get_display_mode (entry);
8921 append_action_signal (entry, info_entry_priv->popup_menu, GTK_STOCK_CUT, "cut-clipboard",
8922 info_entry_priv->editable && mode == DISPLAY_NORMAL &&
8923 info_entry_priv->current_pos != info_entry_priv->selection_bound);
8925 append_action_signal (entry, info_entry_priv->popup_menu, GTK_STOCK_COPY, "copy-clipboard",
8926 mode == DISPLAY_NORMAL &&
8927 info_entry_priv->current_pos != info_entry_priv->selection_bound);
8929 append_action_signal (entry, info_entry_priv->popup_menu, GTK_STOCK_PASTE, "paste-clipboard",
8930 info_entry_priv->editable && clipboard_contains_text);
8932 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_DELETE, NULL);
8933 gtk_widget_set_sensitive (menuitem, info_entry_priv->editable && info_entry_priv->current_pos != info_entry_priv->selection_bound);
8934 g_signal_connect_swapped (menuitem, "activate",
8935 G_CALLBACK (gtk_entry_delete_cb), entry);
8936 gtk_widget_show (menuitem);
8937 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8939 menuitem = gtk_separator_menu_item_new ();
8940 gtk_widget_show (menuitem);
8941 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8943 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_SELECT_ALL, NULL);
8944 gtk_widget_set_sensitive (menuitem, gtk_entry_buffer_get_length (info_entry_priv->buffer) > 0);
8945 g_signal_connect_swapped (menuitem, "activate",
8946 G_CALLBACK (gtk_entry_select_all), entry);
8947 gtk_widget_show (menuitem);
8948 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8950 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
8951 "gtk-show-input-method-menu", &show_input_method_menu,
8952 "gtk-show-unicode-menu", &show_unicode_menu,
8955 if (show_input_method_menu || show_unicode_menu)
8957 menuitem = gtk_separator_menu_item_new ();
8958 gtk_widget_show (menuitem);
8959 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8962 if (show_input_method_menu)
8964 menuitem = gtk_menu_item_new_with_mnemonic (_("Input _Methods"));
8965 gtk_widget_set_sensitive (menuitem, info_entry_priv->editable);
8966 gtk_widget_show (menuitem);
8967 submenu = gtk_menu_new ();
8968 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
8970 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8972 gtk_im_multicontext_append_menuitems (GTK_IM_MULTICONTEXT (info_entry_priv->im_context),
8973 GTK_MENU_SHELL (submenu));
8976 if (show_unicode_menu)
8978 menuitem = gtk_menu_item_new_with_mnemonic (_("_Insert Unicode Control Character"));
8979 gtk_widget_set_sensitive (menuitem, info_entry_priv->editable);
8980 gtk_widget_show (menuitem);
8982 submenu = gtk_menu_new ();
8983 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
8984 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8986 _gtk_text_util_append_special_char_menuitems (GTK_MENU_SHELL (submenu),
8987 unichar_chosen_func,
8991 g_signal_emit (entry,
8992 signals[POPULATE_POPUP],
8994 info_entry_priv->popup_menu);
8998 gtk_menu_popup_for_device (GTK_MENU (info_entry_priv->popup_menu),
8999 info->device, NULL, NULL, NULL, NULL, NULL,
9000 info->button, info->time);
9003 gtk_menu_popup (GTK_MENU (info_entry_priv->popup_menu), NULL, NULL,
9004 popup_position_func, entry,
9005 0, gtk_get_current_event_time ());
9006 gtk_menu_shell_select_first (GTK_MENU_SHELL (info_entry_priv->popup_menu), FALSE);
9010 g_object_unref (entry);
9011 g_slice_free (PopupInfo, info);
9015 gtk_entry_do_popup (GtkEntry *entry,
9016 GdkEventButton *event)
9018 PopupInfo *info = g_slice_new (PopupInfo);
9020 /* In order to know what entries we should make sensitive, we
9021 * ask for the current targets of the clipboard, and when
9022 * we get them, then we actually pop up the menu.
9024 info->entry = g_object_ref (entry);
9028 info->button = event->button;
9029 info->time = event->time;
9030 info->device = event->device;
9035 info->time = gtk_get_current_event_time ();
9036 info->device = NULL;
9039 gtk_clipboard_request_contents (gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_CLIPBOARD),
9040 gdk_atom_intern_static_string ("TARGETS"),
9041 popup_targets_received,
9046 gtk_entry_popup_menu (GtkWidget *widget)
9048 gtk_entry_do_popup (GTK_ENTRY (widget), NULL);
9053 gtk_entry_drag_begin (GtkWidget *widget,
9054 GdkDragContext *context)
9056 GtkEntry *entry = GTK_ENTRY (widget);
9057 GtkEntryPrivate *priv = entry->priv;
9060 for (i = 0; i < MAX_ICONS; i++)
9062 EntryIconInfo *icon_info = priv->icons[i];
9064 if (icon_info != NULL)
9066 if (icon_info->in_drag)
9068 switch (icon_info->storage_type)
9070 case GTK_IMAGE_STOCK:
9071 gtk_drag_set_icon_stock (context, icon_info->stock_id, -2, -2);
9074 case GTK_IMAGE_ICON_NAME:
9075 gtk_drag_set_icon_name (context, icon_info->icon_name, -2, -2);
9078 /* FIXME: No GIcon support for dnd icons */
9079 case GTK_IMAGE_GICON:
9080 case GTK_IMAGE_PIXBUF:
9081 gtk_drag_set_icon_pixbuf (context, icon_info->pixbuf, -2, -2);
9084 g_assert_not_reached ();
9092 gtk_entry_drag_end (GtkWidget *widget,
9093 GdkDragContext *context)
9095 GtkEntry *entry = GTK_ENTRY (widget);
9096 GtkEntryPrivate *priv = entry->priv;
9099 for (i = 0; i < MAX_ICONS; i++)
9101 EntryIconInfo *icon_info = priv->icons[i];
9103 if (icon_info != NULL)
9104 icon_info->in_drag = 0;
9109 gtk_entry_drag_leave (GtkWidget *widget,
9110 GdkDragContext *context,
9113 GtkEntry *entry = GTK_ENTRY (widget);
9114 GtkEntryPrivate *priv = entry->priv;
9116 priv->dnd_position = -1;
9117 gtk_widget_queue_draw (widget);
9121 gtk_entry_drag_drop (GtkWidget *widget,
9122 GdkDragContext *context,
9127 GtkEntry *entry = GTK_ENTRY (widget);
9128 GtkEntryPrivate *priv = entry->priv;
9129 GdkAtom target = GDK_NONE;
9132 target = gtk_drag_dest_find_target (widget, context, NULL);
9134 if (target != GDK_NONE)
9135 gtk_drag_get_data (widget, context, target, time);
9137 gtk_drag_finish (context, FALSE, FALSE, time);
9143 gtk_entry_drag_motion (GtkWidget *widget,
9144 GdkDragContext *context,
9149 GtkEntry *entry = GTK_ENTRY (widget);
9150 GtkEntryPrivate *priv = entry->priv;
9151 GtkStyleContext *style_context;
9152 GtkWidget *source_widget;
9153 GdkDragAction suggested_action;
9154 gint new_position, old_position;
9158 style_context = gtk_widget_get_style_context (widget);
9159 gtk_style_context_get_padding (style_context, 0, &padding);
9163 old_position = priv->dnd_position;
9164 new_position = gtk_entry_find_position (entry, x + priv->scroll_offset);
9166 if (priv->editable &&
9167 gtk_drag_dest_find_target (widget, context, NULL) != GDK_NONE)
9169 source_widget = gtk_drag_get_source_widget (context);
9170 suggested_action = gdk_drag_context_get_suggested_action (context);
9172 if (!gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &sel1, &sel2) ||
9173 new_position < sel1 || new_position > sel2)
9175 if (source_widget == widget)
9177 /* Default to MOVE, unless the user has
9178 * pressed ctrl or alt to affect available actions
9180 if ((gdk_drag_context_get_actions (context) & GDK_ACTION_MOVE) != 0)
9181 suggested_action = GDK_ACTION_MOVE;
9184 priv->dnd_position = new_position;
9188 if (source_widget == widget)
9189 suggested_action = 0; /* Can't drop in selection where drag started */
9191 priv->dnd_position = -1;
9196 /* Entry not editable, or no text */
9197 suggested_action = 0;
9198 priv->dnd_position = -1;
9201 gdk_drag_status (context, suggested_action, time);
9203 if (priv->dnd_position != old_position)
9204 gtk_widget_queue_draw (widget);
9210 gtk_entry_drag_data_received (GtkWidget *widget,
9211 GdkDragContext *context,
9214 GtkSelectionData *selection_data,
9218 GtkEntry *entry = GTK_ENTRY (widget);
9219 GtkEntryPrivate *priv = entry->priv;
9220 GtkEditable *editable = GTK_EDITABLE (widget);
9221 GtkStyleContext *style_context;
9225 str = (gchar *) gtk_selection_data_get_text (selection_data);
9227 style_context = gtk_widget_get_style_context (widget);
9228 gtk_style_context_get_padding (style_context, 0, &padding);
9232 if (str && priv->editable)
9238 if (priv->truncate_multiline)
9239 length = truncate_multiline (str);
9241 new_position = gtk_entry_find_position (entry, x + priv->scroll_offset);
9243 if (!gtk_editable_get_selection_bounds (editable, &sel1, &sel2) ||
9244 new_position < sel1 || new_position > sel2)
9246 gtk_editable_insert_text (editable, str, length, &new_position);
9250 /* Replacing selection */
9251 begin_change (entry);
9252 g_object_freeze_notify (G_OBJECT (entry));
9253 gtk_editable_delete_text (editable, sel1, sel2);
9254 gtk_editable_insert_text (editable, str, length, &sel1);
9255 g_object_thaw_notify (G_OBJECT (entry));
9259 gtk_drag_finish (context, TRUE, gdk_drag_context_get_selected_action (context) == GDK_ACTION_MOVE, time);
9263 /* Drag and drop didn't happen! */
9264 gtk_drag_finish (context, FALSE, FALSE, time);
9271 gtk_entry_drag_data_get (GtkWidget *widget,
9272 GdkDragContext *context,
9273 GtkSelectionData *selection_data,
9277 GtkEntry *entry = GTK_ENTRY (widget);
9278 GtkEntryPrivate *priv = entry->priv;
9279 GtkEditable *editable = GTK_EDITABLE (widget);
9280 gint sel_start, sel_end;
9283 /* If there is an icon drag going on, exit early. */
9284 for (i = 0; i < MAX_ICONS; i++)
9286 EntryIconInfo *icon_info = priv->icons[i];
9288 if (icon_info != NULL)
9290 if (icon_info->in_drag)
9295 if (gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end))
9297 gchar *str = gtk_entry_get_display_text (GTK_ENTRY (widget), sel_start, sel_end);
9299 gtk_selection_data_set_text (selection_data, str, -1);
9307 gtk_entry_drag_data_delete (GtkWidget *widget,
9308 GdkDragContext *context)
9310 GtkEntry *entry = GTK_ENTRY (widget);
9311 GtkEntryPrivate *priv = entry->priv;
9312 GtkEditable *editable = GTK_EDITABLE (widget);
9313 gint sel_start, sel_end;
9316 /* If there is an icon drag going on, exit early. */
9317 for (i = 0; i < MAX_ICONS; i++)
9319 EntryIconInfo *icon_info = priv->icons[i];
9321 if (icon_info != NULL)
9323 if (icon_info->in_drag)
9328 if (priv->editable &&
9329 gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end))
9330 gtk_editable_delete_text (editable, sel_start, sel_end);
9333 /* We display the cursor when
9335 * - the selection is empty, AND
9336 * - the widget has focus
9339 #define CURSOR_ON_MULTIPLIER 2
9340 #define CURSOR_OFF_MULTIPLIER 1
9341 #define CURSOR_PEND_MULTIPLIER 3
9342 #define CURSOR_DIVIDER 3
9345 cursor_blinks (GtkEntry *entry)
9347 GtkEntryPrivate *priv = entry->priv;
9349 if (gtk_widget_has_focus (GTK_WIDGET (entry)) &&
9351 priv->selection_bound == priv->current_pos)
9353 GtkSettings *settings;
9356 settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9357 g_object_get (settings, "gtk-cursor-blink", &blink, NULL);
9366 get_cursor_time (GtkEntry *entry)
9368 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9371 g_object_get (settings, "gtk-cursor-blink-time", &time, NULL);
9377 get_cursor_blink_timeout (GtkEntry *entry)
9379 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9382 g_object_get (settings, "gtk-cursor-blink-timeout", &timeout, NULL);
9388 show_cursor (GtkEntry *entry)
9390 GtkEntryPrivate *priv = entry->priv;
9393 if (!priv->cursor_visible)
9395 priv->cursor_visible = TRUE;
9397 widget = GTK_WIDGET (entry);
9398 if (gtk_widget_has_focus (widget) && priv->selection_bound == priv->current_pos)
9399 gtk_widget_queue_draw (widget);
9404 hide_cursor (GtkEntry *entry)
9406 GtkEntryPrivate *priv = entry->priv;
9409 if (priv->cursor_visible)
9411 priv->cursor_visible = FALSE;
9413 widget = GTK_WIDGET (entry);
9414 if (gtk_widget_has_focus (widget) && priv->selection_bound == priv->current_pos)
9415 gtk_widget_queue_draw (widget);
9423 blink_cb (gpointer data)
9426 GtkEntryPrivate *priv;
9429 entry = GTK_ENTRY (data);
9432 if (!gtk_widget_has_focus (GTK_WIDGET (entry)))
9434 g_warning ("GtkEntry - did not receive focus-out-event. If you\n"
9435 "connect a handler to this signal, it must return\n"
9436 "FALSE so the entry gets the event as well");
9438 gtk_entry_check_cursor_blink (entry);
9443 g_assert (priv->selection_bound == priv->current_pos);
9445 blink_timeout = get_cursor_blink_timeout (entry);
9446 if (priv->blink_time > 1000 * blink_timeout &&
9447 blink_timeout < G_MAXINT/1000)
9449 /* we've blinked enough without the user doing anything, stop blinking */
9450 show_cursor (entry);
9451 priv->blink_timeout = 0;
9453 else if (priv->cursor_visible)
9455 hide_cursor (entry);
9456 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_OFF_MULTIPLIER / CURSOR_DIVIDER,
9462 show_cursor (entry);
9463 priv->blink_time += get_cursor_time (entry);
9464 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
9469 /* Remove ourselves */
9474 gtk_entry_check_cursor_blink (GtkEntry *entry)
9476 GtkEntryPrivate *priv = entry->priv;
9478 if (cursor_blinks (entry))
9480 if (!priv->blink_timeout)
9482 show_cursor (entry);
9483 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
9490 if (priv->blink_timeout)
9492 g_source_remove (priv->blink_timeout);
9493 priv->blink_timeout = 0;
9496 priv->cursor_visible = TRUE;
9501 gtk_entry_pend_cursor_blink (GtkEntry *entry)
9503 GtkEntryPrivate *priv = entry->priv;
9505 if (cursor_blinks (entry))
9507 if (priv->blink_timeout != 0)
9508 g_source_remove (priv->blink_timeout);
9510 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_PEND_MULTIPLIER / CURSOR_DIVIDER,
9513 show_cursor (entry);
9518 gtk_entry_reset_blink_time (GtkEntry *entry)
9520 GtkEntryPrivate *priv = entry->priv;
9522 priv->blink_time = 0;
9528 gtk_entry_completion_timeout (gpointer data)
9530 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (data);
9531 GtkEntryPrivate *completion_entry_priv = GTK_ENTRY (completion->priv->entry)->priv;
9533 completion->priv->completion_timeout = 0;
9535 if (completion->priv->filter_model &&
9536 g_utf8_strlen (gtk_entry_get_text (GTK_ENTRY (completion->priv->entry)), -1)
9537 >= completion->priv->minimum_key_length)
9541 GtkTreeSelection *s;
9542 gboolean popup_single;
9544 gtk_entry_completion_complete (completion);
9545 matches = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->filter_model), NULL);
9547 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9549 s = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view));
9551 gtk_tree_selection_unselect_all (s);
9553 actions = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->actions), NULL);
9555 g_object_get (completion, "popup-single-match", &popup_single, NULL);
9556 if ((matches > (popup_single ? 0: 1)) || actions > 0)
9558 if (gtk_widget_get_visible (completion->priv->popup_window))
9559 _gtk_entry_completion_resize_popup (completion);
9561 _gtk_entry_completion_popup (completion, completion_entry_priv->completion_device);
9564 _gtk_entry_completion_popdown (completion);
9566 else if (gtk_widget_get_visible (completion->priv->popup_window))
9567 _gtk_entry_completion_popdown (completion);
9572 static inline gboolean
9573 keyval_is_cursor_move (guint keyval)
9575 if (keyval == GDK_KEY_Up || keyval == GDK_KEY_KP_Up)
9578 if (keyval == GDK_KEY_Down || keyval == GDK_KEY_KP_Down)
9581 if (keyval == GDK_KEY_Page_Up)
9584 if (keyval == GDK_KEY_Page_Down)
9591 gtk_entry_completion_key_press (GtkWidget *widget,
9595 gint matches, actions = 0;
9596 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
9598 if (!gtk_widget_get_mapped (completion->priv->popup_window))
9601 matches = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->filter_model), NULL);
9603 if (completion->priv->actions)
9604 actions = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->actions), NULL);
9606 if (keyval_is_cursor_move (event->keyval))
9608 GtkTreePath *path = NULL;
9610 if (event->keyval == GDK_KEY_Up || event->keyval == GDK_KEY_KP_Up)
9612 if (completion->priv->current_selected < 0)
9613 completion->priv->current_selected = matches + actions - 1;
9615 completion->priv->current_selected--;
9617 else if (event->keyval == GDK_KEY_Down || event->keyval == GDK_KEY_KP_Down)
9619 if (completion->priv->current_selected < matches + actions - 1)
9620 completion->priv->current_selected++;
9622 completion->priv->current_selected = -1;
9624 else if (event->keyval == GDK_KEY_Page_Up)
9626 if (completion->priv->current_selected < 0)
9627 completion->priv->current_selected = matches + actions - 1;
9628 else if (completion->priv->current_selected == 0)
9629 completion->priv->current_selected = -1;
9630 else if (completion->priv->current_selected < matches)
9632 completion->priv->current_selected -= PAGE_STEP;
9633 if (completion->priv->current_selected < 0)
9634 completion->priv->current_selected = 0;
9638 completion->priv->current_selected -= PAGE_STEP;
9639 if (completion->priv->current_selected < matches - 1)
9640 completion->priv->current_selected = matches - 1;
9643 else if (event->keyval == GDK_KEY_Page_Down)
9645 if (completion->priv->current_selected < 0)
9646 completion->priv->current_selected = 0;
9647 else if (completion->priv->current_selected < matches - 1)
9649 completion->priv->current_selected += PAGE_STEP;
9650 if (completion->priv->current_selected > matches - 1)
9651 completion->priv->current_selected = matches - 1;
9653 else if (completion->priv->current_selected == matches + actions - 1)
9655 completion->priv->current_selected = -1;
9659 completion->priv->current_selected += PAGE_STEP;
9660 if (completion->priv->current_selected > matches + actions - 1)
9661 completion->priv->current_selected = matches + actions - 1;
9665 if (completion->priv->current_selected < 0)
9667 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9668 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view)));
9670 if (completion->priv->inline_selection &&
9671 completion->priv->completion_prefix)
9673 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9674 completion->priv->completion_prefix);
9675 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9678 else if (completion->priv->current_selected < matches)
9680 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view)));
9682 path = gtk_tree_path_new_from_indices (completion->priv->current_selected, -1);
9683 gtk_tree_view_set_cursor (GTK_TREE_VIEW (completion->priv->tree_view),
9686 if (completion->priv->inline_selection)
9690 GtkTreeIter child_iter;
9691 GtkTreeModel *model = NULL;
9692 GtkTreeSelection *sel;
9695 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view));
9696 if (!gtk_tree_selection_get_selected (sel, &model, &iter))
9699 gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (model), &child_iter, &iter);
9700 model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model));
9702 if (completion->priv->completion_prefix == NULL)
9703 completion->priv->completion_prefix = g_strdup (gtk_entry_get_text (GTK_ENTRY (completion->priv->entry)));
9705 g_signal_emit_by_name (completion, "cursor-on-match", model,
9706 &child_iter, &entry_set);
9709 else if (completion->priv->current_selected - matches >= 0)
9711 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9713 path = gtk_tree_path_new_from_indices (completion->priv->current_selected - matches, -1);
9714 gtk_tree_view_set_cursor (GTK_TREE_VIEW (completion->priv->action_view),
9717 if (completion->priv->inline_selection &&
9718 completion->priv->completion_prefix)
9720 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9721 completion->priv->completion_prefix);
9722 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9726 gtk_tree_path_free (path);
9730 else if (event->keyval == GDK_KEY_Escape ||
9731 event->keyval == GDK_KEY_Left ||
9732 event->keyval == GDK_KEY_KP_Left ||
9733 event->keyval == GDK_KEY_Right ||
9734 event->keyval == GDK_KEY_KP_Right)
9736 gboolean retval = TRUE;
9738 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9739 _gtk_entry_completion_popdown (completion);
9741 if (completion->priv->current_selected < 0)
9744 goto keypress_completion_out;
9746 else if (completion->priv->inline_selection)
9748 /* Escape rejects the tentative completion */
9749 if (event->keyval == GDK_KEY_Escape)
9751 if (completion->priv->completion_prefix)
9752 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9753 completion->priv->completion_prefix);
9755 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry), "");
9758 /* Move the cursor to the end for Right/Esc, to the
9759 beginning for Left */
9760 if (event->keyval == GDK_KEY_Right ||
9761 event->keyval == GDK_KEY_KP_Right ||
9762 event->keyval == GDK_KEY_Escape)
9763 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9765 gtk_editable_set_position (GTK_EDITABLE (widget), 0);
9768 keypress_completion_out:
9769 if (completion->priv->inline_selection)
9771 g_free (completion->priv->completion_prefix);
9772 completion->priv->completion_prefix = NULL;
9777 else if (event->keyval == GDK_KEY_Tab ||
9778 event->keyval == GDK_KEY_KP_Tab ||
9779 event->keyval == GDK_KEY_ISO_Left_Tab)
9781 GtkDirectionType dir = event->keyval == GDK_KEY_ISO_Left_Tab ?
9782 GTK_DIR_TAB_BACKWARD : GTK_DIR_TAB_FORWARD;
9784 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9785 _gtk_entry_completion_popdown (completion);
9787 g_free (completion->priv->completion_prefix);
9788 completion->priv->completion_prefix = NULL;
9790 gtk_widget_child_focus (gtk_widget_get_toplevel (widget), dir);
9794 else if (event->keyval == GDK_KEY_ISO_Enter ||
9795 event->keyval == GDK_KEY_KP_Enter ||
9796 event->keyval == GDK_KEY_Return)
9799 GtkTreeModel *model = NULL;
9800 GtkTreeModel *child_model;
9801 GtkTreeIter child_iter;
9802 GtkTreeSelection *sel;
9803 gboolean retval = TRUE;
9805 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9806 _gtk_entry_completion_popdown (completion);
9808 if (completion->priv->current_selected < matches)
9812 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view));
9813 if (gtk_tree_selection_get_selected (sel, &model, &iter))
9815 gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (model), &child_iter, &iter);
9816 child_model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model));
9817 g_signal_handler_block (widget, completion->priv->changed_id);
9818 g_signal_emit_by_name (completion, "match-selected",
9819 child_model, &child_iter, &entry_set);
9820 g_signal_handler_unblock (widget, completion->priv->changed_id);
9826 gtk_tree_model_get (model, &iter,
9827 completion->priv->text_column, &str,
9830 gtk_entry_set_text (GTK_ENTRY (widget), str);
9832 /* move the cursor to the end */
9833 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9841 else if (completion->priv->current_selected - matches >= 0)
9843 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view));
9844 if (gtk_tree_selection_get_selected (sel, &model, &iter))
9848 path = gtk_tree_path_new_from_indices (completion->priv->current_selected - matches, -1);
9849 g_signal_emit_by_name (completion, "action-activated",
9850 gtk_tree_path_get_indices (path)[0]);
9851 gtk_tree_path_free (path);
9857 g_free (completion->priv->completion_prefix);
9858 completion->priv->completion_prefix = NULL;
9867 gtk_entry_completion_changed (GtkWidget *widget,
9870 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
9871 GtkEntry *entry = GTK_ENTRY (widget);
9872 GtkEntryPrivate *priv = entry->priv;
9875 /* (re)install completion timeout */
9876 if (completion->priv->completion_timeout)
9877 g_source_remove (completion->priv->completion_timeout);
9879 if (!gtk_entry_get_text (entry))
9882 /* no need to normalize for this test */
9883 if (completion->priv->minimum_key_length > 0 &&
9884 strcmp ("", gtk_entry_get_text (entry)) == 0)
9886 if (gtk_widget_get_visible (completion->priv->popup_window))
9887 _gtk_entry_completion_popdown (completion);
9891 device = gtk_get_current_event_device ();
9893 if (device && gdk_device_get_source (device) == GDK_SOURCE_KEYBOARD)
9894 device = gdk_device_get_associated_device (device);
9897 priv->completion_device = device;
9899 completion->priv->completion_timeout =
9900 gdk_threads_add_timeout (COMPLETION_TIMEOUT,
9901 gtk_entry_completion_timeout,
9906 check_completion_callback (GtkEntryCompletion *completion)
9908 completion->priv->check_completion_idle = NULL;
9910 gtk_entry_completion_complete (completion);
9911 gtk_entry_completion_insert_prefix (completion);
9917 clear_completion_callback (GtkEntry *entry,
9920 if (pspec->name == I_("cursor-position") ||
9921 pspec->name == I_("selection-bound"))
9923 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
9925 completion->priv->has_completion = FALSE;
9930 accept_completion_callback (GtkEntry *entry)
9932 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
9934 if (completion->priv->has_completion)
9935 gtk_editable_set_position (GTK_EDITABLE (entry),
9936 gtk_entry_buffer_get_length (get_buffer (entry)));
9942 completion_insert_text_callback (GtkEntry *entry,
9946 GtkEntryCompletion *completion)
9948 /* idle to update the selection based on the file list */
9949 if (completion->priv->check_completion_idle == NULL)
9951 completion->priv->check_completion_idle = g_idle_source_new ();
9952 g_source_set_priority (completion->priv->check_completion_idle, G_PRIORITY_HIGH);
9953 g_source_set_closure (completion->priv->check_completion_idle,
9954 g_cclosure_new_object (G_CALLBACK (check_completion_callback),
9955 G_OBJECT (completion)));
9956 g_source_attach (completion->priv->check_completion_idle, NULL);
9961 completion_changed (GtkEntryCompletion *completion,
9965 GtkEntry *entry = GTK_ENTRY (data);
9967 if (pspec->name == I_("popup-completion") ||
9968 pspec->name == I_("inline-completion"))
9970 disconnect_completion_signals (entry, completion);
9971 connect_completion_signals (entry, completion);
9976 disconnect_completion_signals (GtkEntry *entry,
9977 GtkEntryCompletion *completion)
9979 g_signal_handlers_disconnect_by_func (completion,
9980 G_CALLBACK (completion_changed), entry);
9981 if (completion->priv->changed_id > 0 &&
9982 g_signal_handler_is_connected (entry, completion->priv->changed_id))
9984 g_signal_handler_disconnect (entry, completion->priv->changed_id);
9985 completion->priv->changed_id = 0;
9987 g_signal_handlers_disconnect_by_func (entry,
9988 G_CALLBACK (gtk_entry_completion_key_press), completion);
9989 if (completion->priv->insert_text_id > 0 &&
9990 g_signal_handler_is_connected (entry, completion->priv->insert_text_id))
9992 g_signal_handler_disconnect (entry, completion->priv->insert_text_id);
9993 completion->priv->insert_text_id = 0;
9995 g_signal_handlers_disconnect_by_func (entry,
9996 G_CALLBACK (completion_insert_text_callback), completion);
9997 g_signal_handlers_disconnect_by_func (entry,
9998 G_CALLBACK (clear_completion_callback), completion);
9999 g_signal_handlers_disconnect_by_func (entry,
10000 G_CALLBACK (accept_completion_callback), completion);
10004 connect_completion_signals (GtkEntry *entry,
10005 GtkEntryCompletion *completion)
10007 if (completion->priv->popup_completion)
10009 completion->priv->changed_id =
10010 g_signal_connect (entry, "changed",
10011 G_CALLBACK (gtk_entry_completion_changed), completion);
10012 g_signal_connect (entry, "key-press-event",
10013 G_CALLBACK (gtk_entry_completion_key_press), completion);
10016 if (completion->priv->inline_completion)
10018 completion->priv->insert_text_id =
10019 g_signal_connect (entry, "insert-text",
10020 G_CALLBACK (completion_insert_text_callback), completion);
10021 g_signal_connect (entry, "notify",
10022 G_CALLBACK (clear_completion_callback), completion);
10023 g_signal_connect (entry, "activate",
10024 G_CALLBACK (accept_completion_callback), completion);
10025 g_signal_connect (entry, "focus-out-event",
10026 G_CALLBACK (accept_completion_callback), completion);
10029 g_signal_connect (completion, "notify",
10030 G_CALLBACK (completion_changed), entry);
10034 * gtk_entry_set_completion:
10035 * @entry: A #GtkEntry
10036 * @completion: (allow-none): The #GtkEntryCompletion or %NULL
10038 * Sets @completion to be the auxiliary completion object to use with @entry.
10039 * All further configuration of the completion mechanism is done on
10040 * @completion using the #GtkEntryCompletion API. Completion is disabled if
10041 * @completion is set to %NULL.
10046 gtk_entry_set_completion (GtkEntry *entry,
10047 GtkEntryCompletion *completion)
10049 GtkEntryCompletion *old;
10051 g_return_if_fail (GTK_IS_ENTRY (entry));
10052 g_return_if_fail (!completion || GTK_IS_ENTRY_COMPLETION (completion));
10054 old = gtk_entry_get_completion (entry);
10056 if (old == completion)
10061 if (old->priv->completion_timeout)
10063 g_source_remove (old->priv->completion_timeout);
10064 old->priv->completion_timeout = 0;
10067 if (old->priv->check_completion_idle)
10069 g_source_destroy (old->priv->check_completion_idle);
10070 old->priv->check_completion_idle = NULL;
10073 if (gtk_widget_get_mapped (old->priv->popup_window))
10074 _gtk_entry_completion_popdown (old);
10076 disconnect_completion_signals (entry, old);
10077 old->priv->entry = NULL;
10079 g_object_unref (old);
10084 g_object_set_data (G_OBJECT (entry), I_(GTK_ENTRY_COMPLETION_KEY), NULL);
10088 /* hook into the entry */
10089 g_object_ref (completion);
10091 connect_completion_signals (entry, completion);
10092 completion->priv->entry = GTK_WIDGET (entry);
10093 g_object_set_data (G_OBJECT (entry), I_(GTK_ENTRY_COMPLETION_KEY), completion);
10095 g_object_notify (G_OBJECT (entry), "completion");
10099 * gtk_entry_get_completion:
10100 * @entry: A #GtkEntry
10102 * Returns the auxiliary completion object currently in use by @entry.
10104 * Return value: (transfer none): The auxiliary completion object currently
10105 * in use by @entry.
10109 GtkEntryCompletion *
10110 gtk_entry_get_completion (GtkEntry *entry)
10112 GtkEntryCompletion *completion;
10114 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
10116 completion = GTK_ENTRY_COMPLETION (g_object_get_data (G_OBJECT (entry),
10117 GTK_ENTRY_COMPLETION_KEY));
10123 * gtk_entry_set_cursor_hadjustment:
10124 * @entry: a #GtkEntry
10125 * @adjustment: an adjustment which should be adjusted when the cursor
10126 * is moved, or %NULL
10128 * Hooks up an adjustment to the cursor position in an entry, so that when
10129 * the cursor is moved, the adjustment is scrolled to show that position.
10130 * See gtk_scrolled_window_get_hadjustment() for a typical way of obtaining
10133 * The adjustment has to be in pixel units and in the same coordinate system
10139 gtk_entry_set_cursor_hadjustment (GtkEntry *entry,
10140 GtkAdjustment *adjustment)
10142 g_return_if_fail (GTK_IS_ENTRY (entry));
10144 g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
10147 g_object_ref (adjustment);
10149 g_object_set_qdata_full (G_OBJECT (entry),
10150 quark_cursor_hadjustment,
10156 * gtk_entry_get_cursor_hadjustment:
10157 * @entry: a #GtkEntry
10159 * Retrieves the horizontal cursor adjustment for the entry.
10160 * See gtk_entry_set_cursor_hadjustment().
10162 * Return value: (transfer none): the horizontal cursor adjustment, or %NULL
10163 * if none has been set.
10168 gtk_entry_get_cursor_hadjustment (GtkEntry *entry)
10170 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
10172 return g_object_get_qdata (G_OBJECT (entry), quark_cursor_hadjustment);
10176 * gtk_entry_set_progress_fraction:
10177 * @entry: a #GtkEntry
10178 * @fraction: fraction of the task that's been completed
10180 * Causes the entry's progress indicator to "fill in" the given
10181 * fraction of the bar. The fraction should be between 0.0 and 1.0,
10187 gtk_entry_set_progress_fraction (GtkEntry *entry,
10191 GtkEntryPrivate *private;
10192 gdouble old_fraction;
10193 gint x, y, width, height;
10194 gint old_x, old_y, old_width, old_height;
10196 g_return_if_fail (GTK_IS_ENTRY (entry));
10198 widget = GTK_WIDGET (entry);
10199 private = entry->priv;
10201 if (private->progress_pulse_mode)
10204 old_fraction = private->progress_fraction;
10206 if (gtk_widget_is_drawable (widget))
10207 get_progress_area (widget, &old_x, &old_y, &old_width, &old_height);
10209 fraction = CLAMP (fraction, 0.0, 1.0);
10211 private->progress_fraction = fraction;
10212 private->progress_pulse_mode = FALSE;
10213 private->progress_pulse_current = 0.0;
10215 if (gtk_widget_is_drawable (widget))
10217 get_progress_area (widget, &x, &y, &width, &height);
10219 if ((x != old_x) || (y != old_y) || (width != old_width) || (height != old_height))
10220 gtk_widget_queue_draw (widget);
10223 if (fraction != old_fraction)
10224 g_object_notify (G_OBJECT (entry), "progress-fraction");
10228 * gtk_entry_get_progress_fraction:
10229 * @entry: a #GtkEntry
10231 * Returns the current fraction of the task that's been completed.
10232 * See gtk_entry_set_progress_fraction().
10234 * Return value: a fraction from 0.0 to 1.0
10239 gtk_entry_get_progress_fraction (GtkEntry *entry)
10241 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
10243 return entry->priv->progress_fraction;
10247 * gtk_entry_set_progress_pulse_step:
10248 * @entry: a #GtkEntry
10249 * @fraction: fraction between 0.0 and 1.0
10251 * Sets the fraction of total entry width to move the progress
10252 * bouncing block for each call to gtk_entry_progress_pulse().
10257 gtk_entry_set_progress_pulse_step (GtkEntry *entry,
10260 GtkEntryPrivate *private;
10262 g_return_if_fail (GTK_IS_ENTRY (entry));
10264 private = entry->priv;
10266 fraction = CLAMP (fraction, 0.0, 1.0);
10268 if (fraction != private->progress_pulse_fraction)
10270 private->progress_pulse_fraction = fraction;
10272 gtk_widget_queue_draw (GTK_WIDGET (entry));
10274 g_object_notify (G_OBJECT (entry), "progress-pulse-step");
10279 * gtk_entry_get_progress_pulse_step:
10280 * @entry: a #GtkEntry
10282 * Retrieves the pulse step set with gtk_entry_set_progress_pulse_step().
10284 * Return value: a fraction from 0.0 to 1.0
10289 gtk_entry_get_progress_pulse_step (GtkEntry *entry)
10291 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
10293 return entry->priv->progress_pulse_fraction;
10297 * gtk_entry_progress_pulse:
10298 * @entry: a #GtkEntry
10300 * Indicates that some progress is made, but you don't know how much.
10301 * Causes the entry's progress indicator to enter "activity mode,"
10302 * where a block bounces back and forth. Each call to
10303 * gtk_entry_progress_pulse() causes the block to move by a little bit
10304 * (the amount of movement per pulse is determined by
10305 * gtk_entry_set_progress_pulse_step()).
10310 gtk_entry_progress_pulse (GtkEntry *entry)
10312 GtkEntryPrivate *private;
10314 g_return_if_fail (GTK_IS_ENTRY (entry));
10316 private = entry->priv;
10318 if (private->progress_pulse_mode)
10320 if (private->progress_pulse_way_back)
10322 private->progress_pulse_current -= private->progress_pulse_fraction;
10324 if (private->progress_pulse_current < 0.0)
10326 private->progress_pulse_current = 0.0;
10327 private->progress_pulse_way_back = FALSE;
10332 private->progress_pulse_current += private->progress_pulse_fraction;
10334 if (private->progress_pulse_current > 1.0 - private->progress_pulse_fraction)
10336 private->progress_pulse_current = 1.0 - private->progress_pulse_fraction;
10337 private->progress_pulse_way_back = TRUE;
10343 private->progress_fraction = 0.0;
10344 private->progress_pulse_mode = TRUE;
10345 private->progress_pulse_way_back = FALSE;
10346 private->progress_pulse_current = 0.0;
10349 gtk_widget_queue_draw (GTK_WIDGET (entry));
10353 * gtk_entry_set_placeholder_text:
10354 * @entry: a #GtkEntry
10355 * @text: a string to be displayed when @entry is empty an unfocused, or %NULL
10357 * Sets text to be displayed in @entry when it is empty and unfocused.
10358 * This can be used to give a visual hint of the expected contents of
10361 * Note that since the placeholder text gets removed when the entry
10362 * received focus, using this feature is a bit problematic if the entry
10363 * is given the initial focus in a window. Sometimes this can be
10364 * worked around by delaying the initial focus setting until the
10365 * first key event arrives.
10370 gtk_entry_set_placeholder_text (GtkEntry *entry,
10373 GtkEntryPrivate *priv;
10375 g_return_if_fail (GTK_IS_ENTRY (entry));
10377 priv = entry->priv;
10379 if (g_strcmp0 (priv->placeholder_text, text) == 0)
10382 g_free (priv->placeholder_text);
10383 priv->placeholder_text = g_strdup (text);
10385 gtk_entry_recompute (entry);
10387 g_object_notify (G_OBJECT (entry), "placeholder-text");
10391 * gtk_entry_get_placeholder_text:
10392 * @entry: a #GtkEntry
10394 * Retrieves the text that will be displayed when @entry is empty and unfocused
10396 * Returns: a pointer to the placeholder text as a string. This string points to internally allocated
10397 * storage in the widget and must not be freed, modified or stored.
10402 gtk_entry_get_placeholder_text (GtkEntry *entry)
10404 GtkEntryPrivate *priv;
10406 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
10408 priv = entry->priv;
10410 return priv->placeholder_text;
10413 /* Caps Lock warning for password entries */
10416 show_capslock_feedback (GtkEntry *entry,
10419 GtkEntryPrivate *priv = entry->priv;
10421 if (gtk_entry_get_icon_storage_type (entry, GTK_ENTRY_ICON_SECONDARY) == GTK_IMAGE_EMPTY)
10423 gtk_entry_set_icon_from_stock (entry, GTK_ENTRY_ICON_SECONDARY, GTK_STOCK_CAPS_LOCK_WARNING);
10424 gtk_entry_set_icon_activatable (entry, GTK_ENTRY_ICON_SECONDARY, FALSE);
10425 priv->caps_lock_warning_shown = TRUE;
10428 if (priv->caps_lock_warning_shown)
10429 gtk_entry_set_icon_tooltip_text (entry, GTK_ENTRY_ICON_SECONDARY, text);
10431 g_warning ("Can't show Caps Lock warning, since secondary icon is set");
10435 remove_capslock_feedback (GtkEntry *entry)
10437 GtkEntryPrivate *priv = entry->priv;
10439 if (priv->caps_lock_warning_shown)
10441 gtk_entry_set_icon_from_stock (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
10442 priv->caps_lock_warning_shown = FALSE;
10447 keymap_state_changed (GdkKeymap *keymap,
10450 GtkEntryPrivate *priv = entry->priv;
10453 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL && priv->caps_lock_warning)
10455 if (gdk_keymap_get_num_lock_state (keymap)
10456 && gdk_keymap_get_caps_lock_state (keymap))
10457 text = _("Caps Lock and Num Lock are on");
10458 else if (gdk_keymap_get_num_lock_state (keymap))
10459 text = _("Num Lock is on");
10460 else if (gdk_keymap_get_caps_lock_state (keymap))
10461 text = _("Caps Lock is on");
10465 show_capslock_feedback (entry, text);
10467 remove_capslock_feedback (entry);
10471 * _gtk_entry_set_is_cell_renderer:
10472 * @entry: a #GtkEntry
10473 * @is_cell_renderer: new value
10475 * This is a helper function for GtkComboBox. A GtkEntry in a GtkComboBox
10476 * is supposed to behave like a GtkCellEditable when placed in a combo box.
10478 * I.e take up its allocation and get GtkEntry->is_cell_renderer = TRUE.
10482 _gtk_entry_set_is_cell_renderer (GtkEntry *entry,
10483 gboolean is_cell_renderer)
10485 entry->priv->is_cell_renderer = is_cell_renderer;