1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* GTK - The GIMP Toolkit
3 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * Copyright (C) 2004-2006 Christian Hammond
5 * Copyright (C) 2008 Cody Russell
6 * Copyright (C) 2008 Red Hat, Inc.
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
25 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
26 * file for a list of people on the GTK+ Team. See the ChangeLog
27 * files for a list of changes. These files are distributed with
28 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
36 #include "gtkbindings.h"
37 #include "gtkcelleditable.h"
38 #include "gtkclipboard.h"
41 #include "gtkentrybuffer.h"
42 #include "gtkimagemenuitem.h"
43 #include "gtkimcontextsimple.h"
44 #include "gtkimmulticontext.h"
48 #include "gtkmarshalers.h"
50 #include "gtkmenuitem.h"
51 #include "gtkseparatormenuitem.h"
52 #include "gtkselection.h"
53 #include "gtksettings.h"
54 #include "gtkspinbutton.h"
56 #include "gtktextutil.h"
57 #include "gtkwindow.h"
58 #include "gtktreeview.h"
59 #include "gtktreeselection.h"
60 #include "gtktypebuiltins.h"
61 #include "gtkprivate.h"
62 #include "gtkentryprivate.h"
63 #include "gtkcelllayout.h"
64 #include "gtktooltip.h"
65 #include "gtkiconfactory.h"
66 #include "gtkicontheme.h"
67 #include "gtkwidgetprivate.h"
68 #include "gtkstylecontextprivate.h"
70 #include "a11y/gtkentryaccessible.h"
74 * @Short_description: A single line text entry field
76 * @See_also: #GtkTextView, #GtkEntryCompletion
78 * The #GtkEntry widget is a single line text entry
79 * widget. A fairly large set of key bindings are supported
80 * by default. If the entered text is longer than the allocation
81 * of the widget, the widget will scroll so that the cursor
82 * position is visible.
84 * When using an entry for passwords and other sensitive information,
85 * it can be put into "password mode" using gtk_entry_set_visibility().
86 * In this mode, entered text is displayed using a 'invisible' character.
87 * By default, GTK+ picks the best invisible character that is available
88 * in the current font, but it can be changed with
89 * gtk_entry_set_invisible_char(). Since 2.16, GTK+ displays a warning
90 * when Caps Lock or input methods might interfere with entering text in
91 * a password entry. The warning can be turned off with the
92 * #GtkEntry:caps-lock-warning property.
94 * Since 2.16, GtkEntry has the ability to display progress or activity
95 * information behind the text. To make an entry display such information,
96 * use gtk_entry_set_progress_fraction() or gtk_entry_set_progress_pulse_step().
98 * Additionally, GtkEntry can show icons at either side of the entry. These
99 * icons can be activatable by clicking, can be set up as drag source and
100 * can have tooltips. To add an icon, use gtk_entry_set_icon_from_gicon() or
101 * one of the various other functions that set an icon from a stock id, an
102 * icon name or a pixbuf. To trigger an action when the user clicks an icon,
103 * connect to the #GtkEntry::icon-press signal. To allow DND operations
104 * from an icon, use gtk_entry_set_icon_drag_source(). To set a tooltip on
105 * an icon, use gtk_entry_set_icon_tooltip_text() or the corresponding function
108 * Note that functionality or information that is only available by clicking
109 * on an icon in an entry may not be accessible at all to users which are not
110 * able to use a mouse or other pointing device. It is therefore recommended
111 * that any such functionality should also be available by other means, e.g.
112 * via the context menu of the entry.
116 #define GTK_ENTRY_COMPLETION_KEY "gtk-entry-completion-key"
118 #define MIN_ENTRY_WIDTH 150
119 #define DRAW_TIMEOUT 20
120 #define COMPLETION_TIMEOUT 300
121 #define PASSWORD_HINT_MAX 8
126 #define IS_VALID_ICON_POSITION(pos) \
127 ((pos) == GTK_ENTRY_ICON_PRIMARY || \
128 (pos) == GTK_ENTRY_ICON_SECONDARY)
130 static const GtkBorder default_inner_border = { 2, 2, 2, 2 };
131 static GQuark quark_inner_border = 0;
132 static GQuark quark_password_hint = 0;
133 static GQuark quark_cursor_hadjustment = 0;
134 static GQuark quark_capslock_feedback = 0;
136 typedef struct _EntryIconInfo EntryIconInfo;
137 typedef struct _GtkEntryPasswordHint GtkEntryPasswordHint;
138 typedef struct _GtkEntryCapslockFeedback GtkEntryCapslockFeedback;
140 struct _GtkEntryPrivate
142 EntryIconInfo *icons[MAX_ICONS];
144 GtkEntryBuffer *buffer;
145 GtkIMContext *im_context;
146 GtkShadowType shadow_type;
147 GtkWidget *popup_menu;
149 GdkDevice *completion_device;
150 GdkWindow *text_area;
152 PangoLayout *cached_layout;
156 gdouble progress_fraction;
157 gdouble progress_pulse_fraction;
158 gdouble progress_pulse_current;
160 gchar *placeholder_text;
164 gint ascent; /* font ascent in pango units */
166 gint descent; /* font descent in pango units */
167 gint dnd_position; /* In chars, -1 == no DND cursor */
173 gint selection_bound;
179 gunichar invisible_char;
182 guint blink_time; /* time in msec the cursor has blinked since last user event */
184 guint recompute_idle;
186 guint16 x_text_size; /* allocated size, in bytes */
187 guint16 x_n_bytes; /* length in use, in bytes */
189 guint16 preedit_length; /* length of preedit string, in bytes */
190 guint16 preedit_cursor; /* offset of cursor within preedit string, in chars */
194 guint overwrite_mode : 1;
197 guint activates_default : 1;
198 guint cache_includes_preedit : 1;
199 guint caps_lock_warning : 1;
200 guint caps_lock_warning_shown : 1;
201 guint change_count : 8;
202 guint cursor_visible : 1;
203 guint editing_canceled : 1; /* Only used by GtkCellRendererText */
205 guint in_click : 1; /* Flag so we don't select all when clicking in entry to focus in */
206 guint is_cell_renderer : 1;
207 guint invisible_char_set : 1;
208 guint interior_focus : 1;
209 guint mouse_cursor_obscured : 1;
210 guint need_im_reset : 1;
211 guint progress_pulse_mode : 1;
212 guint progress_pulse_way_back : 1;
213 guint real_changed : 1;
214 guint resolved_dir : 4; /* PangoDirection */
215 guint select_words : 1;
216 guint select_lines : 1;
217 guint truncate_multiline : 1;
220 struct _EntryIconInfo
224 guint insensitive : 1;
225 guint nonactivatable : 1;
230 GtkImageType storage_type;
236 GtkStateFlags last_state;
238 GtkTargetList *target_list;
239 GdkDragAction actions;
242 struct _GtkEntryPasswordHint
244 gint position; /* Position (in text) of the last password hint */
245 guint source_id; /* Timeout source id */
248 struct _GtkEntryCapslockFeedback
275 PROP_CURSOR_POSITION,
276 PROP_SELECTION_BOUND,
283 PROP_ACTIVATES_DEFAULT,
288 PROP_TRUNCATE_MULTILINE,
292 PROP_INVISIBLE_CHAR_SET,
293 PROP_CAPS_LOCK_WARNING,
294 PROP_PROGRESS_FRACTION,
295 PROP_PROGRESS_PULSE_STEP,
297 PROP_PIXBUF_SECONDARY,
299 PROP_STOCK_SECONDARY,
300 PROP_ICON_NAME_PRIMARY,
301 PROP_ICON_NAME_SECONDARY,
303 PROP_GICON_SECONDARY,
304 PROP_STORAGE_TYPE_PRIMARY,
305 PROP_STORAGE_TYPE_SECONDARY,
306 PROP_ACTIVATABLE_PRIMARY,
307 PROP_ACTIVATABLE_SECONDARY,
308 PROP_SENSITIVE_PRIMARY,
309 PROP_SENSITIVE_SECONDARY,
310 PROP_TOOLTIP_TEXT_PRIMARY,
311 PROP_TOOLTIP_TEXT_SECONDARY,
312 PROP_TOOLTIP_MARKUP_PRIMARY,
313 PROP_TOOLTIP_MARKUP_SECONDARY,
315 PROP_EDITING_CANCELED,
316 PROP_PLACEHOLDER_TEXT,
320 static guint signals[LAST_SIGNAL] = { 0 };
329 DISPLAY_NORMAL, /* The entry text is being shown */
330 DISPLAY_INVISIBLE, /* In invisible mode, text replaced by (eg) bullets */
331 DISPLAY_BLANK /* In invisible mode, nothing shown at all */
336 static void gtk_entry_editable_init (GtkEditableInterface *iface);
337 static void gtk_entry_cell_editable_init (GtkCellEditableIface *iface);
338 static void gtk_entry_set_property (GObject *object,
342 static void gtk_entry_get_property (GObject *object,
346 static void gtk_entry_finalize (GObject *object);
347 static void gtk_entry_dispose (GObject *object);
351 static void gtk_entry_destroy (GtkWidget *widget);
352 static void gtk_entry_realize (GtkWidget *widget);
353 static void gtk_entry_unrealize (GtkWidget *widget);
354 static void gtk_entry_map (GtkWidget *widget);
355 static void gtk_entry_unmap (GtkWidget *widget);
356 static void gtk_entry_get_preferred_width (GtkWidget *widget,
359 static void gtk_entry_get_preferred_height (GtkWidget *widget,
362 static void gtk_entry_size_allocate (GtkWidget *widget,
363 GtkAllocation *allocation);
364 static void gtk_entry_draw_frame (GtkWidget *widget,
365 GtkStyleContext *context,
367 static void gtk_entry_draw_progress (GtkWidget *widget,
368 GtkStyleContext *context,
370 static gint gtk_entry_draw (GtkWidget *widget,
372 static gint gtk_entry_button_press (GtkWidget *widget,
373 GdkEventButton *event);
374 static gint gtk_entry_button_release (GtkWidget *widget,
375 GdkEventButton *event);
376 static gint gtk_entry_enter_notify (GtkWidget *widget,
377 GdkEventCrossing *event);
378 static gint gtk_entry_leave_notify (GtkWidget *widget,
379 GdkEventCrossing *event);
380 static gint gtk_entry_motion_notify (GtkWidget *widget,
381 GdkEventMotion *event);
382 static gint gtk_entry_key_press (GtkWidget *widget,
384 static gint gtk_entry_key_release (GtkWidget *widget,
386 static gint gtk_entry_focus_in (GtkWidget *widget,
387 GdkEventFocus *event);
388 static gint gtk_entry_focus_out (GtkWidget *widget,
389 GdkEventFocus *event);
390 static void gtk_entry_grab_focus (GtkWidget *widget);
391 static void gtk_entry_style_updated (GtkWidget *widget);
392 static gboolean gtk_entry_query_tooltip (GtkWidget *widget,
395 gboolean keyboard_tip,
396 GtkTooltip *tooltip);
397 static void gtk_entry_direction_changed (GtkWidget *widget,
398 GtkTextDirection previous_dir);
399 static void gtk_entry_state_flags_changed (GtkWidget *widget,
400 GtkStateFlags previous_state);
401 static void gtk_entry_screen_changed (GtkWidget *widget,
402 GdkScreen *old_screen);
404 static gboolean gtk_entry_drag_drop (GtkWidget *widget,
405 GdkDragContext *context,
409 static gboolean gtk_entry_drag_motion (GtkWidget *widget,
410 GdkDragContext *context,
414 static void gtk_entry_drag_leave (GtkWidget *widget,
415 GdkDragContext *context,
417 static void gtk_entry_drag_data_received (GtkWidget *widget,
418 GdkDragContext *context,
421 GtkSelectionData *selection_data,
424 static void gtk_entry_drag_data_get (GtkWidget *widget,
425 GdkDragContext *context,
426 GtkSelectionData *selection_data,
429 static void gtk_entry_drag_data_delete (GtkWidget *widget,
430 GdkDragContext *context);
431 static void gtk_entry_drag_begin (GtkWidget *widget,
432 GdkDragContext *context);
433 static void gtk_entry_drag_end (GtkWidget *widget,
434 GdkDragContext *context);
437 /* GtkEditable method implementations
439 static void gtk_entry_insert_text (GtkEditable *editable,
440 const gchar *new_text,
441 gint new_text_length,
443 static void gtk_entry_delete_text (GtkEditable *editable,
446 static gchar * gtk_entry_get_chars (GtkEditable *editable,
449 static void gtk_entry_real_set_position (GtkEditable *editable,
451 static gint gtk_entry_get_position (GtkEditable *editable);
452 static void gtk_entry_set_selection_bounds (GtkEditable *editable,
455 static gboolean gtk_entry_get_selection_bounds (GtkEditable *editable,
459 /* GtkCellEditable method implementations
461 static void gtk_entry_start_editing (GtkCellEditable *cell_editable,
464 /* Default signal handlers
466 static void gtk_entry_real_insert_text (GtkEditable *editable,
467 const gchar *new_text,
468 gint new_text_length,
470 static void gtk_entry_real_delete_text (GtkEditable *editable,
473 static void gtk_entry_move_cursor (GtkEntry *entry,
474 GtkMovementStep step,
476 gboolean extend_selection);
477 static void gtk_entry_insert_at_cursor (GtkEntry *entry,
479 static void gtk_entry_delete_from_cursor (GtkEntry *entry,
482 static void gtk_entry_backspace (GtkEntry *entry);
483 static void gtk_entry_cut_clipboard (GtkEntry *entry);
484 static void gtk_entry_copy_clipboard (GtkEntry *entry);
485 static void gtk_entry_paste_clipboard (GtkEntry *entry);
486 static void gtk_entry_toggle_overwrite (GtkEntry *entry);
487 static void gtk_entry_select_all (GtkEntry *entry);
488 static void gtk_entry_real_activate (GtkEntry *entry);
489 static gboolean gtk_entry_popup_menu (GtkWidget *widget);
491 static void keymap_direction_changed (GdkKeymap *keymap,
493 static void keymap_state_changed (GdkKeymap *keymap,
495 static void remove_capslock_feedback (GtkEntry *entry);
497 /* IM Context Callbacks
499 static void gtk_entry_commit_cb (GtkIMContext *context,
502 static void gtk_entry_preedit_changed_cb (GtkIMContext *context,
504 static gboolean gtk_entry_retrieve_surrounding_cb (GtkIMContext *context,
506 static gboolean gtk_entry_delete_surrounding_cb (GtkIMContext *context,
513 static void gtk_entry_enter_text (GtkEntry *entry,
515 static void gtk_entry_set_positions (GtkEntry *entry,
517 gint selection_bound);
518 static void gtk_entry_draw_text (GtkEntry *entry,
520 static void gtk_entry_draw_cursor (GtkEntry *entry,
523 static PangoLayout *gtk_entry_ensure_layout (GtkEntry *entry,
524 gboolean include_preedit);
525 static void gtk_entry_reset_layout (GtkEntry *entry);
526 static void gtk_entry_recompute (GtkEntry *entry);
527 static gint gtk_entry_find_position (GtkEntry *entry,
529 static void gtk_entry_get_cursor_locations (GtkEntry *entry,
533 static void gtk_entry_adjust_scroll (GtkEntry *entry);
534 static gint gtk_entry_move_visually (GtkEntry *editable,
537 static gint gtk_entry_move_logically (GtkEntry *entry,
540 static gint gtk_entry_move_forward_word (GtkEntry *entry,
542 gboolean allow_whitespace);
543 static gint gtk_entry_move_backward_word (GtkEntry *entry,
545 gboolean allow_whitespace);
546 static void gtk_entry_delete_whitespace (GtkEntry *entry);
547 static void gtk_entry_select_word (GtkEntry *entry);
548 static void gtk_entry_select_line (GtkEntry *entry);
549 static void gtk_entry_paste (GtkEntry *entry,
551 static void gtk_entry_update_primary_selection (GtkEntry *entry);
552 static void gtk_entry_do_popup (GtkEntry *entry,
553 GdkEventButton *event);
554 static gboolean gtk_entry_mnemonic_activate (GtkWidget *widget,
555 gboolean group_cycling);
556 static void gtk_entry_check_cursor_blink (GtkEntry *entry);
557 static void gtk_entry_pend_cursor_blink (GtkEntry *entry);
558 static void gtk_entry_reset_blink_time (GtkEntry *entry);
559 static void gtk_entry_get_text_area_size (GtkEntry *entry,
564 static void get_text_area_size (GtkEntry *entry,
569 static void get_frame_size (GtkEntry *entry,
570 gboolean relative_to_window,
575 static void gtk_entry_move_adjustments (GtkEntry *entry);
576 static void gtk_entry_ensure_pixbuf (GtkEntry *entry,
577 GtkEntryIconPosition icon_pos);
578 static void gtk_entry_update_cached_style_values(GtkEntry *entry);
581 static gint gtk_entry_completion_timeout (gpointer data);
582 static gboolean gtk_entry_completion_key_press (GtkWidget *widget,
585 static void gtk_entry_completion_changed (GtkWidget *entry,
587 static gboolean check_completion_callback (GtkEntryCompletion *completion);
588 static void clear_completion_callback (GtkEntry *entry,
590 static gboolean accept_completion_callback (GtkEntry *entry);
591 static void completion_insert_text_callback (GtkEntry *entry,
595 GtkEntryCompletion *completion);
596 static void completion_changed (GtkEntryCompletion *completion,
599 static void disconnect_completion_signals (GtkEntry *entry,
600 GtkEntryCompletion *completion);
601 static void connect_completion_signals (GtkEntry *entry,
602 GtkEntryCompletion *completion);
604 static void begin_change (GtkEntry *entry);
605 static void end_change (GtkEntry *entry);
606 static void emit_changed (GtkEntry *entry);
608 static void buffer_inserted_text (GtkEntryBuffer *buffer,
613 static void buffer_deleted_text (GtkEntryBuffer *buffer,
617 static void buffer_notify_text (GtkEntryBuffer *buffer,
620 static void buffer_notify_length (GtkEntryBuffer *buffer,
623 static void buffer_notify_max_length (GtkEntryBuffer *buffer,
626 static void buffer_connect_signals (GtkEntry *entry);
627 static void buffer_disconnect_signals (GtkEntry *entry);
628 static GtkEntryBuffer *get_buffer (GtkEntry *entry);
630 G_DEFINE_TYPE_WITH_CODE (GtkEntry, gtk_entry, GTK_TYPE_WIDGET,
631 G_IMPLEMENT_INTERFACE (GTK_TYPE_EDITABLE,
632 gtk_entry_editable_init)
633 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_EDITABLE,
634 gtk_entry_cell_editable_init))
637 add_move_binding (GtkBindingSet *binding_set,
640 GtkMovementStep step,
643 g_return_if_fail ((modmask & GDK_SHIFT_MASK) == 0);
645 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
649 G_TYPE_BOOLEAN, FALSE);
651 /* Selection-extending version */
652 gtk_binding_entry_add_signal (binding_set, keyval, modmask | GDK_SHIFT_MASK,
656 G_TYPE_BOOLEAN, TRUE);
660 gtk_entry_class_init (GtkEntryClass *class)
662 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
663 GtkWidgetClass *widget_class;
664 GtkBindingSet *binding_set;
666 widget_class = (GtkWidgetClass*) class;
668 gobject_class->dispose = gtk_entry_dispose;
669 gobject_class->finalize = gtk_entry_finalize;
670 gobject_class->set_property = gtk_entry_set_property;
671 gobject_class->get_property = gtk_entry_get_property;
673 widget_class->destroy = gtk_entry_destroy;
674 widget_class->map = gtk_entry_map;
675 widget_class->unmap = gtk_entry_unmap;
676 widget_class->realize = gtk_entry_realize;
677 widget_class->unrealize = gtk_entry_unrealize;
678 widget_class->get_preferred_width = gtk_entry_get_preferred_width;
679 widget_class->get_preferred_height = gtk_entry_get_preferred_height;
680 widget_class->size_allocate = gtk_entry_size_allocate;
681 widget_class->draw = gtk_entry_draw;
682 widget_class->enter_notify_event = gtk_entry_enter_notify;
683 widget_class->leave_notify_event = gtk_entry_leave_notify;
684 widget_class->button_press_event = gtk_entry_button_press;
685 widget_class->button_release_event = gtk_entry_button_release;
686 widget_class->motion_notify_event = gtk_entry_motion_notify;
687 widget_class->key_press_event = gtk_entry_key_press;
688 widget_class->key_release_event = gtk_entry_key_release;
689 widget_class->focus_in_event = gtk_entry_focus_in;
690 widget_class->focus_out_event = gtk_entry_focus_out;
691 widget_class->grab_focus = gtk_entry_grab_focus;
692 widget_class->style_updated = gtk_entry_style_updated;
693 widget_class->query_tooltip = gtk_entry_query_tooltip;
694 widget_class->drag_begin = gtk_entry_drag_begin;
695 widget_class->drag_end = gtk_entry_drag_end;
696 widget_class->direction_changed = gtk_entry_direction_changed;
697 widget_class->state_flags_changed = gtk_entry_state_flags_changed;
698 widget_class->screen_changed = gtk_entry_screen_changed;
699 widget_class->mnemonic_activate = gtk_entry_mnemonic_activate;
701 widget_class->drag_drop = gtk_entry_drag_drop;
702 widget_class->drag_motion = gtk_entry_drag_motion;
703 widget_class->drag_leave = gtk_entry_drag_leave;
704 widget_class->drag_data_received = gtk_entry_drag_data_received;
705 widget_class->drag_data_get = gtk_entry_drag_data_get;
706 widget_class->drag_data_delete = gtk_entry_drag_data_delete;
708 widget_class->popup_menu = gtk_entry_popup_menu;
710 class->move_cursor = gtk_entry_move_cursor;
711 class->insert_at_cursor = gtk_entry_insert_at_cursor;
712 class->delete_from_cursor = gtk_entry_delete_from_cursor;
713 class->backspace = gtk_entry_backspace;
714 class->cut_clipboard = gtk_entry_cut_clipboard;
715 class->copy_clipboard = gtk_entry_copy_clipboard;
716 class->paste_clipboard = gtk_entry_paste_clipboard;
717 class->toggle_overwrite = gtk_entry_toggle_overwrite;
718 class->activate = gtk_entry_real_activate;
719 class->get_text_area_size = gtk_entry_get_text_area_size;
721 quark_inner_border = g_quark_from_static_string ("gtk-entry-inner-border");
722 quark_password_hint = g_quark_from_static_string ("gtk-entry-password-hint");
723 quark_cursor_hadjustment = g_quark_from_static_string ("gtk-hadjustment");
724 quark_capslock_feedback = g_quark_from_static_string ("gtk-entry-capslock-feedback");
726 g_object_class_override_property (gobject_class,
727 PROP_EDITING_CANCELED,
730 g_object_class_install_property (gobject_class,
732 g_param_spec_object ("buffer",
734 P_("Text buffer object which actually stores entry text"),
735 GTK_TYPE_ENTRY_BUFFER,
736 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT));
738 g_object_class_install_property (gobject_class,
739 PROP_CURSOR_POSITION,
740 g_param_spec_int ("cursor-position",
741 P_("Cursor Position"),
742 P_("The current position of the insertion cursor in chars"),
744 GTK_ENTRY_BUFFER_MAX_SIZE,
746 GTK_PARAM_READABLE));
748 g_object_class_install_property (gobject_class,
749 PROP_SELECTION_BOUND,
750 g_param_spec_int ("selection-bound",
751 P_("Selection Bound"),
752 P_("The position of the opposite end of the selection from the cursor in chars"),
754 GTK_ENTRY_BUFFER_MAX_SIZE,
756 GTK_PARAM_READABLE));
758 g_object_class_install_property (gobject_class,
760 g_param_spec_boolean ("editable",
762 P_("Whether the entry contents can be edited"),
764 GTK_PARAM_READWRITE));
766 g_object_class_install_property (gobject_class,
768 g_param_spec_int ("max-length",
769 P_("Maximum length"),
770 P_("Maximum number of characters for this entry. Zero if no maximum"),
772 GTK_ENTRY_BUFFER_MAX_SIZE,
774 GTK_PARAM_READWRITE));
775 g_object_class_install_property (gobject_class,
777 g_param_spec_boolean ("visibility",
779 P_("FALSE displays the \"invisible char\" instead of the actual text (password mode)"),
781 GTK_PARAM_READWRITE));
783 g_object_class_install_property (gobject_class,
785 g_param_spec_boolean ("has-frame",
787 P_("FALSE removes outside bevel from entry"),
789 GTK_PARAM_READWRITE));
791 g_object_class_install_property (gobject_class,
793 g_param_spec_boxed ("inner-border",
795 P_("Border between text and frame. Overrides the inner-border style property"),
797 GTK_PARAM_READWRITE));
799 g_object_class_install_property (gobject_class,
801 g_param_spec_unichar ("invisible-char",
802 P_("Invisible character"),
803 P_("The character to use when masking entry contents (in \"password mode\")"),
805 GTK_PARAM_READWRITE));
807 g_object_class_install_property (gobject_class,
808 PROP_ACTIVATES_DEFAULT,
809 g_param_spec_boolean ("activates-default",
810 P_("Activates default"),
811 P_("Whether to activate the default widget (such as the default button in a dialog) when Enter is pressed"),
813 GTK_PARAM_READWRITE));
814 g_object_class_install_property (gobject_class,
816 g_param_spec_int ("width-chars",
817 P_("Width in chars"),
818 P_("Number of characters to leave space for in the entry"),
822 GTK_PARAM_READWRITE));
824 g_object_class_install_property (gobject_class,
826 g_param_spec_int ("scroll-offset",
828 P_("Number of pixels of the entry scrolled off the screen to the left"),
832 GTK_PARAM_READABLE));
834 g_object_class_install_property (gobject_class,
836 g_param_spec_string ("text",
838 P_("The contents of the entry"),
840 GTK_PARAM_READWRITE));
845 * The horizontal alignment, from 0 (left) to 1 (right).
846 * Reversed for RTL layouts.
850 g_object_class_install_property (gobject_class,
852 g_param_spec_float ("xalign",
854 P_("The horizontal alignment, from 0 (left) to 1 (right). Reversed for RTL layouts."),
858 GTK_PARAM_READWRITE));
861 * GtkEntry:truncate-multiline:
863 * When %TRUE, pasted multi-line text is truncated to the first line.
867 g_object_class_install_property (gobject_class,
868 PROP_TRUNCATE_MULTILINE,
869 g_param_spec_boolean ("truncate-multiline",
870 P_("Truncate multiline"),
871 P_("Whether to truncate multiline pastes to one line."),
873 GTK_PARAM_READWRITE));
876 * GtkEntry:shadow-type:
878 * Which kind of shadow to draw around the entry when
879 * #GtkEntry:has-frame is set to %TRUE.
883 g_object_class_install_property (gobject_class,
885 g_param_spec_enum ("shadow-type",
887 P_("Which kind of shadow to draw around the entry when has-frame is set"),
888 GTK_TYPE_SHADOW_TYPE,
890 GTK_PARAM_READWRITE));
893 * GtkEntry:overwrite-mode:
895 * If text is overwritten when typing in the #GtkEntry.
899 g_object_class_install_property (gobject_class,
901 g_param_spec_boolean ("overwrite-mode",
902 P_("Overwrite mode"),
903 P_("Whether new text overwrites existing text"),
905 GTK_PARAM_READWRITE));
908 * GtkEntry:text-length:
910 * The length of the text in the #GtkEntry.
914 g_object_class_install_property (gobject_class,
916 g_param_spec_uint ("text-length",
918 P_("Length of the text currently in the entry"),
922 GTK_PARAM_READABLE));
924 * GtkEntry:invisible-char-set:
926 * Whether the invisible char has been set for the #GtkEntry.
930 g_object_class_install_property (gobject_class,
931 PROP_INVISIBLE_CHAR_SET,
932 g_param_spec_boolean ("invisible-char-set",
933 P_("Invisible character set"),
934 P_("Whether the invisible character has been set"),
936 GTK_PARAM_READWRITE));
939 * GtkEntry:caps-lock-warning
941 * Whether password entries will show a warning when Caps Lock is on.
943 * Note that the warning is shown using a secondary icon, and thus
944 * does not work if you are using the secondary icon position for some
949 g_object_class_install_property (gobject_class,
950 PROP_CAPS_LOCK_WARNING,
951 g_param_spec_boolean ("caps-lock-warning",
952 P_("Caps Lock warning"),
953 P_("Whether password entries will show a warning when Caps Lock is on"),
955 GTK_PARAM_READWRITE));
958 * GtkEntry:progress-fraction:
960 * The current fraction of the task that's been completed.
964 g_object_class_install_property (gobject_class,
965 PROP_PROGRESS_FRACTION,
966 g_param_spec_double ("progress-fraction",
967 P_("Progress Fraction"),
968 P_("The current fraction of the task that's been completed"),
972 GTK_PARAM_READWRITE));
975 * GtkEntry:progress-pulse-step:
977 * The fraction of total entry width to move the progress
978 * bouncing block for each call to gtk_entry_progress_pulse().
982 g_object_class_install_property (gobject_class,
983 PROP_PROGRESS_PULSE_STEP,
984 g_param_spec_double ("progress-pulse-step",
985 P_("Progress Pulse Step"),
986 P_("The fraction of total entry width to move the progress bouncing block for each call to gtk_entry_progress_pulse()"),
990 GTK_PARAM_READWRITE));
993 * GtkEntry:placeholder-text:
995 * The text that will be displayed in the #GtkEntry when it is empty
1000 g_object_class_install_property (gobject_class,
1001 PROP_PLACEHOLDER_TEXT,
1002 g_param_spec_string ("placeholder-text",
1003 P_("Placeholder text"),
1004 P_("Show text in the entry when it's empty and unfocused"),
1006 GTK_PARAM_READWRITE));
1009 * GtkEntry:primary-icon-pixbuf:
1011 * A pixbuf to use as the primary icon for the entry.
1015 g_object_class_install_property (gobject_class,
1016 PROP_PIXBUF_PRIMARY,
1017 g_param_spec_object ("primary-icon-pixbuf",
1018 P_("Primary pixbuf"),
1019 P_("Primary pixbuf for the entry"),
1021 GTK_PARAM_READWRITE));
1024 * GtkEntry:secondary-icon-pixbuf:
1026 * An pixbuf to use as the secondary icon for the entry.
1030 g_object_class_install_property (gobject_class,
1031 PROP_PIXBUF_SECONDARY,
1032 g_param_spec_object ("secondary-icon-pixbuf",
1033 P_("Secondary pixbuf"),
1034 P_("Secondary pixbuf for the entry"),
1036 GTK_PARAM_READWRITE));
1039 * GtkEntry:primary-icon-stock:
1041 * The stock id to use for the primary icon for the entry.
1045 g_object_class_install_property (gobject_class,
1047 g_param_spec_string ("primary-icon-stock",
1048 P_("Primary stock ID"),
1049 P_("Stock ID for primary icon"),
1051 GTK_PARAM_READWRITE));
1054 * GtkEntry:secondary-icon-stock:
1056 * The stock id to use for the secondary icon for the entry.
1060 g_object_class_install_property (gobject_class,
1061 PROP_STOCK_SECONDARY,
1062 g_param_spec_string ("secondary-icon-stock",
1063 P_("Secondary stock ID"),
1064 P_("Stock ID for secondary icon"),
1066 GTK_PARAM_READWRITE));
1069 * GtkEntry:primary-icon-name:
1071 * The icon name to use for the primary icon for the entry.
1075 g_object_class_install_property (gobject_class,
1076 PROP_ICON_NAME_PRIMARY,
1077 g_param_spec_string ("primary-icon-name",
1078 P_("Primary icon name"),
1079 P_("Icon name for primary icon"),
1081 GTK_PARAM_READWRITE));
1084 * GtkEntry:secondary-icon-name:
1086 * The icon name to use for the secondary icon for the entry.
1090 g_object_class_install_property (gobject_class,
1091 PROP_ICON_NAME_SECONDARY,
1092 g_param_spec_string ("secondary-icon-name",
1093 P_("Secondary icon name"),
1094 P_("Icon name for secondary icon"),
1096 GTK_PARAM_READWRITE));
1099 * GtkEntry:primary-icon-gicon:
1101 * The #GIcon to use for the primary icon for the entry.
1105 g_object_class_install_property (gobject_class,
1107 g_param_spec_object ("primary-icon-gicon",
1108 P_("Primary GIcon"),
1109 P_("GIcon for primary icon"),
1111 GTK_PARAM_READWRITE));
1114 * GtkEntry:secondary-icon-gicon:
1116 * The #GIcon to use for the secondary icon for the entry.
1120 g_object_class_install_property (gobject_class,
1121 PROP_GICON_SECONDARY,
1122 g_param_spec_object ("secondary-icon-gicon",
1123 P_("Secondary GIcon"),
1124 P_("GIcon for secondary icon"),
1126 GTK_PARAM_READWRITE));
1129 * GtkEntry:primary-icon-storage-type:
1131 * The representation which is used for the primary icon of the entry.
1135 g_object_class_install_property (gobject_class,
1136 PROP_STORAGE_TYPE_PRIMARY,
1137 g_param_spec_enum ("primary-icon-storage-type",
1138 P_("Primary storage type"),
1139 P_("The representation being used for primary icon"),
1140 GTK_TYPE_IMAGE_TYPE,
1142 GTK_PARAM_READABLE));
1145 * GtkEntry:secondary-icon-storage-type:
1147 * The representation which is used for the secondary icon of the entry.
1151 g_object_class_install_property (gobject_class,
1152 PROP_STORAGE_TYPE_SECONDARY,
1153 g_param_spec_enum ("secondary-icon-storage-type",
1154 P_("Secondary storage type"),
1155 P_("The representation being used for secondary icon"),
1156 GTK_TYPE_IMAGE_TYPE,
1158 GTK_PARAM_READABLE));
1161 * GtkEntry:primary-icon-activatable:
1163 * Whether the primary icon is activatable.
1165 * GTK+ emits the #GtkEntry::icon-press and #GtkEntry::icon-release
1166 * signals only on sensitive, activatable icons.
1168 * Sensitive, but non-activatable icons can be used for purely
1169 * informational purposes.
1173 g_object_class_install_property (gobject_class,
1174 PROP_ACTIVATABLE_PRIMARY,
1175 g_param_spec_boolean ("primary-icon-activatable",
1176 P_("Primary icon activatable"),
1177 P_("Whether the primary icon is activatable"),
1179 GTK_PARAM_READWRITE));
1182 * GtkEntry:secondary-icon-activatable:
1184 * Whether the secondary icon is activatable.
1186 * GTK+ emits the #GtkEntry::icon-press and #GtkEntry::icon-release
1187 * signals only on sensitive, activatable icons.
1189 * Sensitive, but non-activatable icons can be used for purely
1190 * informational purposes.
1194 g_object_class_install_property (gobject_class,
1195 PROP_ACTIVATABLE_SECONDARY,
1196 g_param_spec_boolean ("secondary-icon-activatable",
1197 P_("Secondary icon activatable"),
1198 P_("Whether the secondary icon is activatable"),
1200 GTK_PARAM_READWRITE));
1204 * GtkEntry:primary-icon-sensitive:
1206 * Whether the primary icon is sensitive.
1208 * An insensitive icon appears grayed out. GTK+ does not emit the
1209 * #GtkEntry::icon-press and #GtkEntry::icon-release signals and
1210 * does not allow DND from insensitive icons.
1212 * An icon should be set insensitive if the action that would trigger
1213 * when clicked is currently not available.
1217 g_object_class_install_property (gobject_class,
1218 PROP_SENSITIVE_PRIMARY,
1219 g_param_spec_boolean ("primary-icon-sensitive",
1220 P_("Primary icon sensitive"),
1221 P_("Whether the primary icon is sensitive"),
1223 GTK_PARAM_READWRITE));
1226 * GtkEntry:secondary-icon-sensitive:
1228 * Whether the secondary icon is sensitive.
1230 * An insensitive icon appears grayed out. GTK+ does not emit the
1231 * #GtkEntry::icon-press and #GtkEntry::icon-release signals and
1232 * does not allow DND from insensitive icons.
1234 * An icon should be set insensitive if the action that would trigger
1235 * when clicked is currently not available.
1239 g_object_class_install_property (gobject_class,
1240 PROP_SENSITIVE_SECONDARY,
1241 g_param_spec_boolean ("secondary-icon-sensitive",
1242 P_("Secondary icon sensitive"),
1243 P_("Whether the secondary icon is sensitive"),
1245 GTK_PARAM_READWRITE));
1248 * GtkEntry:primary-icon-tooltip-text:
1250 * The contents of the tooltip on the primary icon.
1252 * Also see gtk_entry_set_icon_tooltip_text().
1256 g_object_class_install_property (gobject_class,
1257 PROP_TOOLTIP_TEXT_PRIMARY,
1258 g_param_spec_string ("primary-icon-tooltip-text",
1259 P_("Primary icon tooltip text"),
1260 P_("The contents of the tooltip on the primary icon"),
1262 GTK_PARAM_READWRITE));
1265 * GtkEntry:secondary-icon-tooltip-text:
1267 * The contents of the tooltip on the secondary icon.
1269 * Also see gtk_entry_set_icon_tooltip_text().
1273 g_object_class_install_property (gobject_class,
1274 PROP_TOOLTIP_TEXT_SECONDARY,
1275 g_param_spec_string ("secondary-icon-tooltip-text",
1276 P_("Secondary icon tooltip text"),
1277 P_("The contents of the tooltip on the secondary icon"),
1279 GTK_PARAM_READWRITE));
1282 * GtkEntry:primary-icon-tooltip-markup:
1284 * The contents of the tooltip on the primary icon, which is marked up
1285 * with the <link linkend="PangoMarkupFormat">Pango text markup
1288 * Also see gtk_entry_set_icon_tooltip_markup().
1292 g_object_class_install_property (gobject_class,
1293 PROP_TOOLTIP_MARKUP_PRIMARY,
1294 g_param_spec_string ("primary-icon-tooltip-markup",
1295 P_("Primary icon tooltip markup"),
1296 P_("The contents of the tooltip on the primary icon"),
1298 GTK_PARAM_READWRITE));
1301 * GtkEntry:secondary-icon-tooltip-markup:
1303 * The contents of the tooltip on the secondary icon, which is marked up
1304 * with the <link linkend="PangoMarkupFormat">Pango text markup
1307 * Also see gtk_entry_set_icon_tooltip_markup().
1311 g_object_class_install_property (gobject_class,
1312 PROP_TOOLTIP_MARKUP_SECONDARY,
1313 g_param_spec_string ("secondary-icon-tooltip-markup",
1314 P_("Secondary icon tooltip markup"),
1315 P_("The contents of the tooltip on the secondary icon"),
1317 GTK_PARAM_READWRITE));
1320 * GtkEntry:im-module:
1322 * Which IM (input method) module should be used for this entry.
1323 * See #GtkIMContext.
1325 * Setting this to a non-%NULL value overrides the
1326 * system-wide IM module setting. See the GtkSettings
1327 * #GtkSettings:gtk-im-module property.
1331 g_object_class_install_property (gobject_class,
1333 g_param_spec_string ("im-module",
1335 P_("Which IM module should be used"),
1337 GTK_PARAM_READWRITE));
1340 * GtkEntry:completion:
1342 * The auxiliary completion object to use with the entry.
1346 g_object_class_install_property (gobject_class,
1348 g_param_spec_object ("completion",
1350 P_("The auxiliary completion object"),
1351 GTK_TYPE_ENTRY_COMPLETION,
1352 GTK_PARAM_READWRITE));
1355 * GtkEntry:icon-prelight:
1357 * The prelight style property determines whether activatable
1358 * icons prelight on mouseover.
1362 gtk_widget_class_install_style_property (widget_class,
1363 g_param_spec_boolean ("icon-prelight",
1364 P_("Icon Prelight"),
1365 P_("Whether activatable icons should prelight when hovered"),
1367 GTK_PARAM_READABLE));
1370 * GtkEntry:progress-border:
1372 * The border around the progress bar in the entry.
1376 gtk_widget_class_install_style_property (widget_class,
1377 g_param_spec_boxed ("progress-border",
1378 P_("Progress Border"),
1379 P_("Border around the progress bar"),
1381 GTK_PARAM_READABLE));
1384 * GtkEntry:invisible-char:
1386 * The invisible character is used when masking entry contents (in
1387 * \"password mode\")"). When it is not explicitly set with the
1388 * #GtkEntry::invisible-char property, GTK+ determines the character
1389 * to use from a list of possible candidates, depending on availability
1390 * in the current font.
1392 * This style property allows the theme to prepend a character
1393 * to the list of candidates.
1397 gtk_widget_class_install_style_property (widget_class,
1398 g_param_spec_unichar ("invisible-char",
1399 P_("Invisible character"),
1400 P_("The character to use when masking entry contents (in \"password mode\")"),
1402 GTK_PARAM_READABLE));
1405 * GtkEntry::populate-popup:
1406 * @entry: The entry on which the signal is emitted
1407 * @menu: the menu that is being populated
1409 * The ::populate-popup signal gets emitted before showing the
1410 * context menu of the entry.
1412 * If you need to add items to the context menu, connect
1413 * to this signal and append your menuitems to the @menu.
1415 signals[POPULATE_POPUP] =
1416 g_signal_new (I_("populate-popup"),
1417 G_OBJECT_CLASS_TYPE (gobject_class),
1419 G_STRUCT_OFFSET (GtkEntryClass, populate_popup),
1421 _gtk_marshal_VOID__OBJECT,
1425 /* Action signals */
1428 * GtkEntry::activate:
1429 * @entry: The entry on which the signal is emitted
1431 * A <link linkend="keybinding-signals">keybinding signal</link>
1432 * which gets emitted when the user activates the entry.
1434 * Applications should not connect to it, but may emit it with
1435 * g_signal_emit_by_name() if they need to control activation
1438 * The default bindings for this signal are all forms of the Enter key.
1441 g_signal_new (I_("activate"),
1442 G_OBJECT_CLASS_TYPE (gobject_class),
1443 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1444 G_STRUCT_OFFSET (GtkEntryClass, activate),
1446 _gtk_marshal_VOID__VOID,
1448 widget_class->activate_signal = signals[ACTIVATE];
1451 * GtkEntry::move-cursor:
1452 * @entry: the object which received the signal
1453 * @step: the granularity of the move, as a #GtkMovementStep
1454 * @count: the number of @step units to move
1455 * @extend_selection: %TRUE if the move should extend the selection
1457 * The ::move-cursor signal is a
1458 * <link linkend="keybinding-signals">keybinding signal</link>
1459 * which gets emitted when the user initiates a cursor movement.
1460 * If the cursor is not visible in @entry, this signal causes
1461 * the viewport to be moved instead.
1463 * Applications should not connect to it, but may emit it with
1464 * g_signal_emit_by_name() if they need to control the cursor
1467 * The default bindings for this signal come in two variants,
1468 * the variant with the Shift modifier extends the selection,
1469 * the variant without the Shift modifer does not.
1470 * There are too many key combinations to list them all here.
1472 * <listitem>Arrow keys move by individual characters/lines</listitem>
1473 * <listitem>Ctrl-arrow key combinations move by words/paragraphs</listitem>
1474 * <listitem>Home/End keys move to the ends of the buffer</listitem>
1477 signals[MOVE_CURSOR] =
1478 g_signal_new (I_("move-cursor"),
1479 G_OBJECT_CLASS_TYPE (gobject_class),
1480 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1481 G_STRUCT_OFFSET (GtkEntryClass, move_cursor),
1483 _gtk_marshal_VOID__ENUM_INT_BOOLEAN,
1485 GTK_TYPE_MOVEMENT_STEP,
1490 * GtkEntry::insert-at-cursor:
1491 * @entry: the object which received the signal
1492 * @string: the string to insert
1494 * The ::insert-at-cursor signal is a
1495 * <link linkend="keybinding-signals">keybinding signal</link>
1496 * which gets emitted when the user initiates the insertion of a
1497 * fixed string at the cursor.
1499 * This signal has no default bindings.
1501 signals[INSERT_AT_CURSOR] =
1502 g_signal_new (I_("insert-at-cursor"),
1503 G_OBJECT_CLASS_TYPE (gobject_class),
1504 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1505 G_STRUCT_OFFSET (GtkEntryClass, insert_at_cursor),
1507 _gtk_marshal_VOID__STRING,
1512 * GtkEntry::delete-from-cursor:
1513 * @entry: the object which received the signal
1514 * @type: the granularity of the deletion, as a #GtkDeleteType
1515 * @count: the number of @type units to delete
1517 * The ::delete-from-cursor signal is a
1518 * <link linkend="keybinding-signals">keybinding signal</link>
1519 * which gets emitted when the user initiates a text deletion.
1521 * If the @type is %GTK_DELETE_CHARS, GTK+ deletes the selection
1522 * if there is one, otherwise it deletes the requested number
1525 * The default bindings for this signal are
1526 * Delete for deleting a character and Ctrl-Delete for
1529 signals[DELETE_FROM_CURSOR] =
1530 g_signal_new (I_("delete-from-cursor"),
1531 G_OBJECT_CLASS_TYPE (gobject_class),
1532 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1533 G_STRUCT_OFFSET (GtkEntryClass, delete_from_cursor),
1535 _gtk_marshal_VOID__ENUM_INT,
1537 GTK_TYPE_DELETE_TYPE,
1541 * GtkEntry::backspace:
1542 * @entry: the object which received the signal
1544 * The ::backspace signal is a
1545 * <link linkend="keybinding-signals">keybinding signal</link>
1546 * which gets emitted when the user asks for it.
1548 * The default bindings for this signal are
1549 * Backspace and Shift-Backspace.
1551 signals[BACKSPACE] =
1552 g_signal_new (I_("backspace"),
1553 G_OBJECT_CLASS_TYPE (gobject_class),
1554 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1555 G_STRUCT_OFFSET (GtkEntryClass, backspace),
1557 _gtk_marshal_VOID__VOID,
1561 * GtkEntry::cut-clipboard:
1562 * @entry: the object which received the signal
1564 * The ::cut-clipboard signal is a
1565 * <link linkend="keybinding-signals">keybinding signal</link>
1566 * which gets emitted to cut the selection to the clipboard.
1568 * The default bindings for this signal are
1569 * Ctrl-x and Shift-Delete.
1571 signals[CUT_CLIPBOARD] =
1572 g_signal_new (I_("cut-clipboard"),
1573 G_OBJECT_CLASS_TYPE (gobject_class),
1574 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1575 G_STRUCT_OFFSET (GtkEntryClass, cut_clipboard),
1577 _gtk_marshal_VOID__VOID,
1581 * GtkEntry::copy-clipboard:
1582 * @entry: the object which received the signal
1584 * The ::copy-clipboard signal is a
1585 * <link linkend="keybinding-signals">keybinding signal</link>
1586 * which gets emitted to copy the selection to the clipboard.
1588 * The default bindings for this signal are
1589 * Ctrl-c and Ctrl-Insert.
1591 signals[COPY_CLIPBOARD] =
1592 g_signal_new (I_("copy-clipboard"),
1593 G_OBJECT_CLASS_TYPE (gobject_class),
1594 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1595 G_STRUCT_OFFSET (GtkEntryClass, copy_clipboard),
1597 _gtk_marshal_VOID__VOID,
1601 * GtkEntry::paste-clipboard:
1602 * @entry: the object which received the signal
1604 * The ::paste-clipboard signal is a
1605 * <link linkend="keybinding-signals">keybinding signal</link>
1606 * which gets emitted to paste the contents of the clipboard
1607 * into the text view.
1609 * The default bindings for this signal are
1610 * Ctrl-v and Shift-Insert.
1612 signals[PASTE_CLIPBOARD] =
1613 g_signal_new (I_("paste-clipboard"),
1614 G_OBJECT_CLASS_TYPE (gobject_class),
1615 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1616 G_STRUCT_OFFSET (GtkEntryClass, paste_clipboard),
1618 _gtk_marshal_VOID__VOID,
1622 * GtkEntry::toggle-overwrite:
1623 * @entry: the object which received the signal
1625 * The ::toggle-overwrite signal is a
1626 * <link linkend="keybinding-signals">keybinding signal</link>
1627 * which gets emitted to toggle the overwrite mode of the entry.
1629 * The default bindings for this signal is Insert.
1631 signals[TOGGLE_OVERWRITE] =
1632 g_signal_new (I_("toggle-overwrite"),
1633 G_OBJECT_CLASS_TYPE (gobject_class),
1634 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1635 G_STRUCT_OFFSET (GtkEntryClass, toggle_overwrite),
1637 _gtk_marshal_VOID__VOID,
1641 * GtkEntry::icon-press:
1642 * @entry: The entry on which the signal is emitted
1643 * @icon_pos: The position of the clicked icon
1644 * @event: (type Gdk.EventButton): the button press event
1646 * The ::icon-press signal is emitted when an activatable icon
1651 signals[ICON_PRESS] =
1652 g_signal_new (I_("icon-press"),
1653 G_TYPE_FROM_CLASS (gobject_class),
1657 _gtk_marshal_VOID__ENUM_BOXED,
1659 GTK_TYPE_ENTRY_ICON_POSITION,
1660 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1663 * GtkEntry::icon-release:
1664 * @entry: The entry on which the signal is emitted
1665 * @icon_pos: The position of the clicked icon
1666 * @event: (type Gdk.EventButton): the button release event
1668 * The ::icon-release signal is emitted on the button release from a
1669 * mouse click over an activatable icon.
1673 signals[ICON_RELEASE] =
1674 g_signal_new (I_("icon-release"),
1675 G_TYPE_FROM_CLASS (gobject_class),
1679 _gtk_marshal_VOID__ENUM_BOXED,
1681 GTK_TYPE_ENTRY_ICON_POSITION,
1682 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1685 * GtkEntry::preedit-changed:
1686 * @entry: the object which received the signal
1687 * @preedit: the current preedit string
1689 * If an input method is used, the typed text will not immediately
1690 * be committed to the buffer. So if you are interested in the text,
1691 * connect to this signal.
1695 signals[PREEDIT_CHANGED] =
1696 g_signal_new_class_handler (I_("preedit-changed"),
1697 G_OBJECT_CLASS_TYPE (gobject_class),
1698 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1701 _gtk_marshal_VOID__STRING,
1710 binding_set = gtk_binding_set_by_class (class);
1712 /* Moving the insertion point */
1713 add_move_binding (binding_set, GDK_KEY_Right, 0,
1714 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1716 add_move_binding (binding_set, GDK_KEY_Left, 0,
1717 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1719 add_move_binding (binding_set, GDK_KEY_KP_Right, 0,
1720 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1722 add_move_binding (binding_set, GDK_KEY_KP_Left, 0,
1723 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1725 add_move_binding (binding_set, GDK_KEY_Right, GDK_CONTROL_MASK,
1726 GTK_MOVEMENT_WORDS, 1);
1728 add_move_binding (binding_set, GDK_KEY_Left, GDK_CONTROL_MASK,
1729 GTK_MOVEMENT_WORDS, -1);
1731 add_move_binding (binding_set, GDK_KEY_KP_Right, GDK_CONTROL_MASK,
1732 GTK_MOVEMENT_WORDS, 1);
1734 add_move_binding (binding_set, GDK_KEY_KP_Left, GDK_CONTROL_MASK,
1735 GTK_MOVEMENT_WORDS, -1);
1737 add_move_binding (binding_set, GDK_KEY_Home, 0,
1738 GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
1740 add_move_binding (binding_set, GDK_KEY_End, 0,
1741 GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
1743 add_move_binding (binding_set, GDK_KEY_KP_Home, 0,
1744 GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
1746 add_move_binding (binding_set, GDK_KEY_KP_End, 0,
1747 GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
1749 add_move_binding (binding_set, GDK_KEY_Home, GDK_CONTROL_MASK,
1750 GTK_MOVEMENT_BUFFER_ENDS, -1);
1752 add_move_binding (binding_set, GDK_KEY_End, GDK_CONTROL_MASK,
1753 GTK_MOVEMENT_BUFFER_ENDS, 1);
1755 add_move_binding (binding_set, GDK_KEY_KP_Home, GDK_CONTROL_MASK,
1756 GTK_MOVEMENT_BUFFER_ENDS, -1);
1758 add_move_binding (binding_set, GDK_KEY_KP_End, GDK_CONTROL_MASK,
1759 GTK_MOVEMENT_BUFFER_ENDS, 1);
1763 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK,
1765 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1767 G_TYPE_BOOLEAN, FALSE);
1768 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK,
1770 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1772 G_TYPE_BOOLEAN, TRUE);
1774 gtk_binding_entry_add_signal (binding_set, GDK_KEY_slash, GDK_CONTROL_MASK,
1776 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1778 G_TYPE_BOOLEAN, FALSE);
1779 gtk_binding_entry_add_signal (binding_set, GDK_KEY_slash, GDK_CONTROL_MASK,
1781 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1783 G_TYPE_BOOLEAN, TRUE);
1786 gtk_binding_entry_add_signal (binding_set, GDK_KEY_backslash, GDK_CONTROL_MASK,
1788 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_VISUAL_POSITIONS,
1790 G_TYPE_BOOLEAN, FALSE);
1791 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_SHIFT_MASK | GDK_CONTROL_MASK,
1793 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_VISUAL_POSITIONS,
1795 G_TYPE_BOOLEAN, FALSE);
1799 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Return, 0,
1801 gtk_binding_entry_add_signal (binding_set, GDK_KEY_ISO_Enter, 0,
1803 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Enter, 0,
1807 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, 0,
1808 "delete-from-cursor", 2,
1809 G_TYPE_ENUM, GTK_DELETE_CHARS,
1812 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Delete, 0,
1813 "delete-from-cursor", 2,
1814 G_TYPE_ENUM, GTK_DELETE_CHARS,
1817 gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, 0,
1820 /* Make this do the same as Backspace, to help with mis-typing */
1821 gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, GDK_SHIFT_MASK,
1824 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, GDK_CONTROL_MASK,
1825 "delete-from-cursor", 2,
1826 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1829 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Delete, GDK_CONTROL_MASK,
1830 "delete-from-cursor", 2,
1831 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1834 gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, GDK_CONTROL_MASK,
1835 "delete-from-cursor", 2,
1836 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1839 /* Cut/copy/paste */
1841 gtk_binding_entry_add_signal (binding_set, GDK_KEY_x, GDK_CONTROL_MASK,
1842 "cut-clipboard", 0);
1843 gtk_binding_entry_add_signal (binding_set, GDK_KEY_c, GDK_CONTROL_MASK,
1844 "copy-clipboard", 0);
1845 gtk_binding_entry_add_signal (binding_set, GDK_KEY_v, GDK_CONTROL_MASK,
1846 "paste-clipboard", 0);
1848 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, GDK_SHIFT_MASK,
1849 "cut-clipboard", 0);
1850 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, GDK_CONTROL_MASK,
1851 "copy-clipboard", 0);
1852 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, GDK_SHIFT_MASK,
1853 "paste-clipboard", 0);
1856 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, 0,
1857 "toggle-overwrite", 0);
1858 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Insert, 0,
1859 "toggle-overwrite", 0);
1862 * GtkEntry:inner-border:
1864 * Sets the text area's border between the text and the frame.
1868 gtk_widget_class_install_style_property (widget_class,
1869 g_param_spec_boxed ("inner-border",
1871 P_("Border between text and frame."),
1873 GTK_PARAM_READABLE));
1875 g_type_class_add_private (gobject_class, sizeof (GtkEntryPrivate));
1877 gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_ENTRY_ACCESSIBLE);
1881 gtk_entry_editable_init (GtkEditableInterface *iface)
1883 iface->do_insert_text = gtk_entry_insert_text;
1884 iface->do_delete_text = gtk_entry_delete_text;
1885 iface->insert_text = gtk_entry_real_insert_text;
1886 iface->delete_text = gtk_entry_real_delete_text;
1887 iface->get_chars = gtk_entry_get_chars;
1888 iface->set_selection_bounds = gtk_entry_set_selection_bounds;
1889 iface->get_selection_bounds = gtk_entry_get_selection_bounds;
1890 iface->set_position = gtk_entry_real_set_position;
1891 iface->get_position = gtk_entry_get_position;
1895 gtk_entry_cell_editable_init (GtkCellEditableIface *iface)
1897 iface->start_editing = gtk_entry_start_editing;
1901 gtk_entry_set_property (GObject *object,
1903 const GValue *value,
1906 GtkEntry *entry = GTK_ENTRY (object);
1907 GtkEntryPrivate *priv = entry->priv;
1912 gtk_entry_set_buffer (entry, g_value_get_object (value));
1917 gboolean new_value = g_value_get_boolean (value);
1919 if (new_value != priv->editable)
1921 GtkWidget *widget = GTK_WIDGET (entry);
1925 _gtk_entry_reset_im_context (entry);
1926 if (gtk_widget_has_focus (widget))
1927 gtk_im_context_focus_out (priv->im_context);
1929 priv->preedit_length = 0;
1930 priv->preedit_cursor = 0;
1933 priv->editable = new_value;
1935 if (new_value && gtk_widget_has_focus (widget))
1936 gtk_im_context_focus_in (priv->im_context);
1938 gtk_widget_queue_draw (widget);
1943 case PROP_MAX_LENGTH:
1944 gtk_entry_set_max_length (entry, g_value_get_int (value));
1947 case PROP_VISIBILITY:
1948 gtk_entry_set_visibility (entry, g_value_get_boolean (value));
1951 case PROP_HAS_FRAME:
1952 gtk_entry_set_has_frame (entry, g_value_get_boolean (value));
1955 case PROP_INNER_BORDER:
1956 gtk_entry_set_inner_border (entry, g_value_get_boxed (value));
1959 case PROP_INVISIBLE_CHAR:
1960 gtk_entry_set_invisible_char (entry, g_value_get_uint (value));
1963 case PROP_ACTIVATES_DEFAULT:
1964 gtk_entry_set_activates_default (entry, g_value_get_boolean (value));
1967 case PROP_WIDTH_CHARS:
1968 gtk_entry_set_width_chars (entry, g_value_get_int (value));
1972 gtk_entry_set_text (entry, g_value_get_string (value));
1976 gtk_entry_set_alignment (entry, g_value_get_float (value));
1979 case PROP_TRUNCATE_MULTILINE:
1980 priv->truncate_multiline = g_value_get_boolean (value);
1983 case PROP_SHADOW_TYPE:
1984 priv->shadow_type = g_value_get_enum (value);
1987 case PROP_OVERWRITE_MODE:
1988 gtk_entry_set_overwrite_mode (entry, g_value_get_boolean (value));
1991 case PROP_INVISIBLE_CHAR_SET:
1992 if (g_value_get_boolean (value))
1993 priv->invisible_char_set = TRUE;
1995 gtk_entry_unset_invisible_char (entry);
1998 case PROP_CAPS_LOCK_WARNING:
1999 priv->caps_lock_warning = g_value_get_boolean (value);
2002 case PROP_PROGRESS_FRACTION:
2003 gtk_entry_set_progress_fraction (entry, g_value_get_double (value));
2006 case PROP_PROGRESS_PULSE_STEP:
2007 gtk_entry_set_progress_pulse_step (entry, g_value_get_double (value));
2010 case PROP_PLACEHOLDER_TEXT:
2011 gtk_entry_set_placeholder_text (entry, g_value_get_string (value));
2014 case PROP_PIXBUF_PRIMARY:
2015 gtk_entry_set_icon_from_pixbuf (entry,
2016 GTK_ENTRY_ICON_PRIMARY,
2017 g_value_get_object (value));
2020 case PROP_PIXBUF_SECONDARY:
2021 gtk_entry_set_icon_from_pixbuf (entry,
2022 GTK_ENTRY_ICON_SECONDARY,
2023 g_value_get_object (value));
2026 case PROP_STOCK_PRIMARY:
2027 gtk_entry_set_icon_from_stock (entry,
2028 GTK_ENTRY_ICON_PRIMARY,
2029 g_value_get_string (value));
2032 case PROP_STOCK_SECONDARY:
2033 gtk_entry_set_icon_from_stock (entry,
2034 GTK_ENTRY_ICON_SECONDARY,
2035 g_value_get_string (value));
2038 case PROP_ICON_NAME_PRIMARY:
2039 gtk_entry_set_icon_from_icon_name (entry,
2040 GTK_ENTRY_ICON_PRIMARY,
2041 g_value_get_string (value));
2044 case PROP_ICON_NAME_SECONDARY:
2045 gtk_entry_set_icon_from_icon_name (entry,
2046 GTK_ENTRY_ICON_SECONDARY,
2047 g_value_get_string (value));
2050 case PROP_GICON_PRIMARY:
2051 gtk_entry_set_icon_from_gicon (entry,
2052 GTK_ENTRY_ICON_PRIMARY,
2053 g_value_get_object (value));
2056 case PROP_GICON_SECONDARY:
2057 gtk_entry_set_icon_from_gicon (entry,
2058 GTK_ENTRY_ICON_SECONDARY,
2059 g_value_get_object (value));
2062 case PROP_ACTIVATABLE_PRIMARY:
2063 gtk_entry_set_icon_activatable (entry,
2064 GTK_ENTRY_ICON_PRIMARY,
2065 g_value_get_boolean (value));
2068 case PROP_ACTIVATABLE_SECONDARY:
2069 gtk_entry_set_icon_activatable (entry,
2070 GTK_ENTRY_ICON_SECONDARY,
2071 g_value_get_boolean (value));
2074 case PROP_SENSITIVE_PRIMARY:
2075 gtk_entry_set_icon_sensitive (entry,
2076 GTK_ENTRY_ICON_PRIMARY,
2077 g_value_get_boolean (value));
2080 case PROP_SENSITIVE_SECONDARY:
2081 gtk_entry_set_icon_sensitive (entry,
2082 GTK_ENTRY_ICON_SECONDARY,
2083 g_value_get_boolean (value));
2086 case PROP_TOOLTIP_TEXT_PRIMARY:
2087 gtk_entry_set_icon_tooltip_text (entry,
2088 GTK_ENTRY_ICON_PRIMARY,
2089 g_value_get_string (value));
2092 case PROP_TOOLTIP_TEXT_SECONDARY:
2093 gtk_entry_set_icon_tooltip_text (entry,
2094 GTK_ENTRY_ICON_SECONDARY,
2095 g_value_get_string (value));
2098 case PROP_TOOLTIP_MARKUP_PRIMARY:
2099 gtk_entry_set_icon_tooltip_markup (entry,
2100 GTK_ENTRY_ICON_PRIMARY,
2101 g_value_get_string (value));
2104 case PROP_TOOLTIP_MARKUP_SECONDARY:
2105 gtk_entry_set_icon_tooltip_markup (entry,
2106 GTK_ENTRY_ICON_SECONDARY,
2107 g_value_get_string (value));
2110 case PROP_IM_MODULE:
2111 g_free (priv->im_module);
2112 priv->im_module = g_value_dup_string (value);
2113 if (GTK_IS_IM_MULTICONTEXT (priv->im_context))
2114 gtk_im_multicontext_set_context_id (GTK_IM_MULTICONTEXT (priv->im_context), priv->im_module);
2117 case PROP_EDITING_CANCELED:
2118 priv->editing_canceled = g_value_get_boolean (value);
2121 case PROP_COMPLETION:
2122 gtk_entry_set_completion (entry, GTK_ENTRY_COMPLETION (g_value_get_object (value)));
2125 case PROP_SCROLL_OFFSET:
2126 case PROP_CURSOR_POSITION:
2128 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2134 gtk_entry_get_property (GObject *object,
2139 GtkEntry *entry = GTK_ENTRY (object);
2140 GtkEntryPrivate *priv = entry->priv;
2145 g_value_set_object (value, gtk_entry_get_buffer (entry));
2148 case PROP_CURSOR_POSITION:
2149 g_value_set_int (value, priv->current_pos);
2152 case PROP_SELECTION_BOUND:
2153 g_value_set_int (value, priv->selection_bound);
2157 g_value_set_boolean (value, priv->editable);
2160 case PROP_MAX_LENGTH:
2161 g_value_set_int (value, gtk_entry_buffer_get_max_length (get_buffer (entry)));
2164 case PROP_VISIBILITY:
2165 g_value_set_boolean (value, priv->visible);
2168 case PROP_HAS_FRAME:
2169 g_value_set_boolean (value, priv->has_frame);
2172 case PROP_INNER_BORDER:
2173 g_value_set_boxed (value, gtk_entry_get_inner_border (entry));
2176 case PROP_INVISIBLE_CHAR:
2177 g_value_set_uint (value, priv->invisible_char);
2180 case PROP_ACTIVATES_DEFAULT:
2181 g_value_set_boolean (value, priv->activates_default);
2184 case PROP_WIDTH_CHARS:
2185 g_value_set_int (value, priv->width_chars);
2188 case PROP_SCROLL_OFFSET:
2189 g_value_set_int (value, priv->scroll_offset);
2193 g_value_set_string (value, gtk_entry_get_text (entry));
2197 g_value_set_float (value, gtk_entry_get_alignment (entry));
2200 case PROP_TRUNCATE_MULTILINE:
2201 g_value_set_boolean (value, priv->truncate_multiline);
2204 case PROP_SHADOW_TYPE:
2205 g_value_set_enum (value, priv->shadow_type);
2208 case PROP_OVERWRITE_MODE:
2209 g_value_set_boolean (value, priv->overwrite_mode);
2212 case PROP_TEXT_LENGTH:
2213 g_value_set_uint (value, gtk_entry_buffer_get_length (get_buffer (entry)));
2216 case PROP_INVISIBLE_CHAR_SET:
2217 g_value_set_boolean (value, priv->invisible_char_set);
2220 case PROP_IM_MODULE:
2221 g_value_set_string (value, priv->im_module);
2224 case PROP_CAPS_LOCK_WARNING:
2225 g_value_set_boolean (value, priv->caps_lock_warning);
2228 case PROP_PROGRESS_FRACTION:
2229 g_value_set_double (value, priv->progress_fraction);
2232 case PROP_PROGRESS_PULSE_STEP:
2233 g_value_set_double (value, priv->progress_pulse_fraction);
2236 case PROP_PLACEHOLDER_TEXT:
2237 g_value_set_string (value, gtk_entry_get_placeholder_text (entry));
2240 case PROP_PIXBUF_PRIMARY:
2241 g_value_set_object (value,
2242 gtk_entry_get_icon_pixbuf (entry,
2243 GTK_ENTRY_ICON_PRIMARY));
2246 case PROP_PIXBUF_SECONDARY:
2247 g_value_set_object (value,
2248 gtk_entry_get_icon_pixbuf (entry,
2249 GTK_ENTRY_ICON_SECONDARY));
2252 case PROP_STOCK_PRIMARY:
2253 g_value_set_string (value,
2254 gtk_entry_get_icon_stock (entry,
2255 GTK_ENTRY_ICON_PRIMARY));
2258 case PROP_STOCK_SECONDARY:
2259 g_value_set_string (value,
2260 gtk_entry_get_icon_stock (entry,
2261 GTK_ENTRY_ICON_SECONDARY));
2264 case PROP_ICON_NAME_PRIMARY:
2265 g_value_set_string (value,
2266 gtk_entry_get_icon_name (entry,
2267 GTK_ENTRY_ICON_PRIMARY));
2270 case PROP_ICON_NAME_SECONDARY:
2271 g_value_set_string (value,
2272 gtk_entry_get_icon_name (entry,
2273 GTK_ENTRY_ICON_SECONDARY));
2276 case PROP_GICON_PRIMARY:
2277 g_value_set_object (value,
2278 gtk_entry_get_icon_gicon (entry,
2279 GTK_ENTRY_ICON_PRIMARY));
2282 case PROP_GICON_SECONDARY:
2283 g_value_set_object (value,
2284 gtk_entry_get_icon_gicon (entry,
2285 GTK_ENTRY_ICON_SECONDARY));
2288 case PROP_STORAGE_TYPE_PRIMARY:
2289 g_value_set_enum (value,
2290 gtk_entry_get_icon_storage_type (entry,
2291 GTK_ENTRY_ICON_PRIMARY));
2294 case PROP_STORAGE_TYPE_SECONDARY:
2295 g_value_set_enum (value,
2296 gtk_entry_get_icon_storage_type (entry,
2297 GTK_ENTRY_ICON_SECONDARY));
2300 case PROP_ACTIVATABLE_PRIMARY:
2301 g_value_set_boolean (value,
2302 gtk_entry_get_icon_activatable (entry, GTK_ENTRY_ICON_PRIMARY));
2305 case PROP_ACTIVATABLE_SECONDARY:
2306 g_value_set_boolean (value,
2307 gtk_entry_get_icon_activatable (entry, GTK_ENTRY_ICON_SECONDARY));
2310 case PROP_SENSITIVE_PRIMARY:
2311 g_value_set_boolean (value,
2312 gtk_entry_get_icon_sensitive (entry, GTK_ENTRY_ICON_PRIMARY));
2315 case PROP_SENSITIVE_SECONDARY:
2316 g_value_set_boolean (value,
2317 gtk_entry_get_icon_sensitive (entry, GTK_ENTRY_ICON_SECONDARY));
2320 case PROP_TOOLTIP_TEXT_PRIMARY:
2321 g_value_take_string (value,
2322 gtk_entry_get_icon_tooltip_text (entry, GTK_ENTRY_ICON_PRIMARY));
2325 case PROP_TOOLTIP_TEXT_SECONDARY:
2326 g_value_take_string (value,
2327 gtk_entry_get_icon_tooltip_text (entry, GTK_ENTRY_ICON_SECONDARY));
2330 case PROP_TOOLTIP_MARKUP_PRIMARY:
2331 g_value_take_string (value,
2332 gtk_entry_get_icon_tooltip_markup (entry, GTK_ENTRY_ICON_PRIMARY));
2335 case PROP_TOOLTIP_MARKUP_SECONDARY:
2336 g_value_take_string (value,
2337 gtk_entry_get_icon_tooltip_markup (entry, GTK_ENTRY_ICON_SECONDARY));
2340 case PROP_EDITING_CANCELED:
2341 g_value_set_boolean (value,
2342 priv->editing_canceled);
2345 case PROP_COMPLETION:
2346 g_value_set_object (value, G_OBJECT (gtk_entry_get_completion (entry)));
2350 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2356 find_invisible_char (GtkWidget *widget)
2358 PangoLayout *layout;
2359 PangoAttrList *attr_list;
2361 gunichar invisible_chars [] = {
2363 0x25cf, /* BLACK CIRCLE */
2364 0x2022, /* BULLET */
2365 0x2731, /* HEAVY ASTERISK */
2366 0x273a /* SIXTEEN POINTED ASTERISK */
2369 gtk_widget_style_get (widget,
2370 "invisible-char", &invisible_chars[0],
2373 layout = gtk_widget_create_pango_layout (widget, NULL);
2375 attr_list = pango_attr_list_new ();
2376 pango_attr_list_insert (attr_list, pango_attr_fallback_new (FALSE));
2378 pango_layout_set_attributes (layout, attr_list);
2379 pango_attr_list_unref (attr_list);
2381 for (i = (invisible_chars[0] != 0 ? 0 : 1); i < G_N_ELEMENTS (invisible_chars); i++)
2383 gchar text[7] = { 0, };
2386 len = g_unichar_to_utf8 (invisible_chars[i], text);
2387 pango_layout_set_text (layout, text, len);
2389 count = pango_layout_get_unknown_glyphs_count (layout);
2393 g_object_unref (layout);
2394 return invisible_chars[i];
2398 g_object_unref (layout);
2404 gtk_entry_init (GtkEntry *entry)
2406 GtkStyleContext *context;
2407 GtkEntryPrivate *priv;
2409 entry->priv = G_TYPE_INSTANCE_GET_PRIVATE (entry,
2414 gtk_widget_set_can_focus (GTK_WIDGET (entry), TRUE);
2415 gtk_widget_set_has_window (GTK_WIDGET (entry), FALSE);
2417 priv->editable = TRUE;
2418 priv->visible = TRUE;
2419 priv->dnd_position = -1;
2420 priv->width_chars = -1;
2421 priv->is_cell_renderer = FALSE;
2422 priv->editing_canceled = FALSE;
2423 priv->has_frame = TRUE;
2424 priv->truncate_multiline = FALSE;
2425 priv->shadow_type = GTK_SHADOW_IN;
2427 priv->caps_lock_warning = TRUE;
2428 priv->caps_lock_warning_shown = FALSE;
2429 priv->progress_fraction = 0.0;
2430 priv->progress_pulse_fraction = 0.1;
2432 gtk_drag_dest_set (GTK_WIDGET (entry),
2433 GTK_DEST_DEFAULT_HIGHLIGHT,
2435 GDK_ACTION_COPY | GDK_ACTION_MOVE);
2436 gtk_drag_dest_add_text_targets (GTK_WIDGET (entry));
2438 /* This object is completely private. No external entity can gain a reference
2439 * to it; so we create it here and destroy it in finalize().
2441 priv->im_context = gtk_im_multicontext_new ();
2443 g_signal_connect (priv->im_context, "commit",
2444 G_CALLBACK (gtk_entry_commit_cb), entry);
2445 g_signal_connect (priv->im_context, "preedit-changed",
2446 G_CALLBACK (gtk_entry_preedit_changed_cb), entry);
2447 g_signal_connect (priv->im_context, "retrieve-surrounding",
2448 G_CALLBACK (gtk_entry_retrieve_surrounding_cb), entry);
2449 g_signal_connect (priv->im_context, "delete-surrounding",
2450 G_CALLBACK (gtk_entry_delete_surrounding_cb), entry);
2452 context = gtk_widget_get_style_context (GTK_WIDGET (entry));
2453 gtk_style_context_add_class (context, GTK_STYLE_CLASS_ENTRY);
2455 gtk_entry_update_cached_style_values (entry);
2459 get_icon_width (GtkEntry *entry,
2460 GtkEntryIconPosition icon_pos)
2462 GtkEntryPrivate *priv = entry->priv;
2463 EntryIconInfo *icon_info = priv->icons[icon_pos];
2465 GtkSettings *settings;
2466 gint menu_icon_width;
2468 if (!icon_info || icon_info->pixbuf == NULL)
2471 screen = gtk_widget_get_screen (GTK_WIDGET (entry));
2472 settings = gtk_settings_get_for_screen (screen);
2474 gtk_icon_size_lookup_for_settings (settings, GTK_ICON_SIZE_MENU,
2475 &menu_icon_width, NULL);
2477 return MAX (gdk_pixbuf_get_width (icon_info->pixbuf), menu_icon_width);
2481 get_icon_allocations (GtkEntry *entry,
2482 GtkAllocation *primary,
2483 GtkAllocation *secondary)
2486 GtkEntryPrivate *priv = entry->priv;
2487 gint x, y, width, height;
2489 get_text_area_size (entry, &x, &y, &width, &height);
2491 if (gtk_widget_has_focus (GTK_WIDGET (entry)) && !priv->interior_focus)
2492 y += priv->focus_width;
2495 primary->height = height;
2496 primary->width = get_icon_width (entry, GTK_ENTRY_ICON_PRIMARY);
2497 if (primary->width > 0)
2498 primary->width += 2 * priv->icon_margin;
2501 secondary->height = height;
2502 secondary->width = get_icon_width (entry, GTK_ENTRY_ICON_SECONDARY);
2503 if (secondary->width > 0)
2504 secondary->width += 2 * priv->icon_margin;
2506 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
2508 primary->x = x + width - primary->width;
2514 secondary->x = x + width - secondary->width;
2520 begin_change (GtkEntry *entry)
2522 GtkEntryPrivate *priv = entry->priv;
2524 priv->change_count++;
2528 end_change (GtkEntry *entry)
2530 GtkEditable *editable = GTK_EDITABLE (entry);
2531 GtkEntryPrivate *priv = entry->priv;
2533 g_return_if_fail (priv->change_count > 0);
2535 priv->change_count--;
2537 if (priv->change_count == 0)
2539 if (priv->real_changed)
2541 g_signal_emit_by_name (editable, "changed");
2542 priv->real_changed = FALSE;
2548 emit_changed (GtkEntry *entry)
2550 GtkEditable *editable = GTK_EDITABLE (entry);
2551 GtkEntryPrivate *priv = entry->priv;
2553 if (priv->change_count == 0)
2554 g_signal_emit_by_name (editable, "changed");
2556 priv->real_changed = TRUE;
2560 gtk_entry_destroy (GtkWidget *widget)
2562 GtkEntry *entry = GTK_ENTRY (widget);
2563 GtkEntryPrivate *priv = entry->priv;
2565 priv->current_pos = priv->selection_bound = 0;
2566 _gtk_entry_reset_im_context (entry);
2567 gtk_entry_reset_layout (entry);
2569 if (priv->blink_timeout)
2571 g_source_remove (priv->blink_timeout);
2572 priv->blink_timeout = 0;
2575 if (priv->recompute_idle)
2577 g_source_remove (priv->recompute_idle);
2578 priv->recompute_idle = 0;
2581 GTK_WIDGET_CLASS (gtk_entry_parent_class)->destroy (widget);
2585 gtk_entry_dispose (GObject *object)
2587 GtkEntry *entry = GTK_ENTRY (object);
2588 GtkEntryPrivate *priv = entry->priv;
2591 gtk_entry_set_icon_from_pixbuf (entry, GTK_ENTRY_ICON_PRIMARY, NULL);
2592 gtk_entry_set_icon_tooltip_markup (entry, GTK_ENTRY_ICON_PRIMARY, NULL);
2593 gtk_entry_set_icon_from_pixbuf (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
2594 gtk_entry_set_icon_tooltip_markup (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
2598 buffer_disconnect_signals (entry);
2599 g_object_unref (priv->buffer);
2600 priv->buffer = NULL;
2603 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (object)));
2604 g_signal_handlers_disconnect_by_func (keymap, keymap_state_changed, entry);
2605 g_signal_handlers_disconnect_by_func (keymap, keymap_direction_changed, entry);
2606 G_OBJECT_CLASS (gtk_entry_parent_class)->dispose (object);
2610 gtk_entry_finalize (GObject *object)
2612 GtkEntry *entry = GTK_ENTRY (object);
2613 GtkEntryPrivate *priv = entry->priv;
2614 EntryIconInfo *icon_info = NULL;
2617 for (i = 0; i < MAX_ICONS; i++)
2619 if ((icon_info = priv->icons[i]) != NULL)
2621 if (icon_info->target_list != NULL)
2623 gtk_target_list_unref (icon_info->target_list);
2624 icon_info->target_list = NULL;
2627 g_slice_free (EntryIconInfo, icon_info);
2628 priv->icons[i] = NULL;
2632 gtk_entry_set_completion (entry, NULL);
2634 if (priv->cached_layout)
2635 g_object_unref (priv->cached_layout);
2637 g_object_unref (priv->im_context);
2639 if (priv->blink_timeout)
2640 g_source_remove (priv->blink_timeout);
2642 if (priv->recompute_idle)
2643 g_source_remove (priv->recompute_idle);
2645 g_free (priv->placeholder_text);
2646 g_free (priv->im_module);
2648 G_OBJECT_CLASS (gtk_entry_parent_class)->finalize (object);
2652 gtk_entry_get_display_mode (GtkEntry *entry)
2654 GtkEntryPrivate *priv = entry->priv;
2657 return DISPLAY_NORMAL;
2659 if (priv->invisible_char == 0 && priv->invisible_char_set)
2660 return DISPLAY_BLANK;
2662 return DISPLAY_INVISIBLE;
2666 gtk_entry_get_display_text (GtkEntry *entry,
2670 GtkEntryPasswordHint *password_hint;
2671 GtkEntryPrivate *priv;
2672 gunichar invisible_char;
2683 text = gtk_entry_buffer_get_text (get_buffer (entry));
2684 length = gtk_entry_buffer_get_length (get_buffer (entry));
2688 if (start_pos > length)
2691 if (end_pos <= start_pos)
2692 return g_strdup ("");
2693 else if (priv->visible)
2695 start = g_utf8_offset_to_pointer (text, start_pos);
2696 end = g_utf8_offset_to_pointer (start, end_pos - start_pos);
2697 return g_strndup (start, end - start);
2701 str = g_string_sized_new (length * 2);
2703 /* Figure out what our invisible char is and encode it */
2704 if (!priv->invisible_char)
2705 invisible_char = priv->invisible_char_set ? ' ' : '*';
2707 invisible_char = priv->invisible_char;
2708 char_len = g_unichar_to_utf8 (invisible_char, char_str);
2711 * Add hidden characters for each character in the text
2712 * buffer. If there is a password hint, then keep that
2713 * character visible.
2716 password_hint = g_object_get_qdata (G_OBJECT (entry), quark_password_hint);
2717 for (i = start_pos; i < end_pos; ++i)
2719 if (password_hint && i == password_hint->position)
2721 start = g_utf8_offset_to_pointer (text, i);
2722 g_string_append_len (str, start, g_utf8_next_char (start) - start);
2726 g_string_append_len (str, char_str, char_len);
2730 return g_string_free (str, FALSE);
2735 update_cursors (GtkWidget *widget)
2737 GtkEntry *entry = GTK_ENTRY (widget);
2738 GtkEntryPrivate *priv = entry->priv;
2739 EntryIconInfo *icon_info = NULL;
2740 GdkDisplay *display;
2744 for (i = 0; i < MAX_ICONS; i++)
2746 if ((icon_info = priv->icons[i]) != NULL)
2748 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
2749 gdk_window_show_unraised (icon_info->window);
2751 /* The icon windows are not children of the visible entry window,
2752 * thus we can't just inherit the xterm cursor. Slight complication
2753 * here is that for the entry, insensitive => arrow cursor, but for
2754 * an icon in a sensitive entry, insensitive => xterm cursor.
2756 if (gtk_widget_is_sensitive (widget) &&
2757 (icon_info->insensitive ||
2758 (icon_info->nonactivatable && icon_info->target_list == NULL)))
2760 display = gtk_widget_get_display (widget);
2761 cursor = gdk_cursor_new_for_display (display, GDK_XTERM);
2762 gdk_window_set_cursor (icon_info->window, cursor);
2763 g_object_unref (cursor);
2767 gdk_window_set_cursor (icon_info->window, NULL);
2774 realize_icon_info (GtkWidget *widget,
2775 GtkEntryIconPosition icon_pos)
2777 GtkEntry *entry = GTK_ENTRY (widget);
2778 GtkEntryPrivate *priv = entry->priv;
2779 EntryIconInfo *icon_info = priv->icons[icon_pos];
2780 GdkWindowAttr attributes;
2781 gint attributes_mask;
2783 g_return_if_fail (icon_info != NULL);
2787 attributes.width = 1;
2788 attributes.height = 1;
2789 attributes.window_type = GDK_WINDOW_CHILD;
2790 attributes.wclass = GDK_INPUT_ONLY;
2791 attributes.event_mask = gtk_widget_get_events (widget);
2792 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
2793 GDK_BUTTON_RELEASE_MASK |
2794 GDK_BUTTON1_MOTION_MASK |
2795 GDK_BUTTON3_MOTION_MASK |
2796 GDK_POINTER_MOTION_HINT_MASK |
2797 GDK_POINTER_MOTION_MASK |
2798 GDK_ENTER_NOTIFY_MASK |
2799 GDK_LEAVE_NOTIFY_MASK);
2800 attributes_mask = GDK_WA_X | GDK_WA_Y;
2802 icon_info->window = gdk_window_new (gtk_widget_get_window (widget),
2805 gdk_window_set_user_data (icon_info->window, widget);
2807 gtk_widget_queue_resize (widget);
2810 static EntryIconInfo*
2811 construct_icon_info (GtkWidget *widget,
2812 GtkEntryIconPosition icon_pos)
2814 GtkEntry *entry = GTK_ENTRY (widget);
2815 GtkEntryPrivate *priv = entry->priv;
2816 EntryIconInfo *icon_info;
2818 g_return_val_if_fail (priv->icons[icon_pos] == NULL, NULL);
2820 icon_info = g_slice_new0 (EntryIconInfo);
2821 priv->icons[icon_pos] = icon_info;
2823 if (gtk_widget_get_realized (widget))
2824 realize_icon_info (widget, icon_pos);
2830 gtk_entry_map (GtkWidget *widget)
2832 GtkEntry *entry = GTK_ENTRY (widget);
2833 GtkEntryPrivate *priv = entry->priv;
2834 EntryIconInfo *icon_info = NULL;
2837 GTK_WIDGET_CLASS (gtk_entry_parent_class)->map (widget);
2839 gdk_window_show (priv->text_area);
2841 for (i = 0; i < MAX_ICONS; i++)
2843 if ((icon_info = priv->icons[i]) != NULL)
2845 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
2846 gdk_window_show (icon_info->window);
2850 update_cursors (widget);
2854 gtk_entry_unmap (GtkWidget *widget)
2856 GtkEntry *entry = GTK_ENTRY (widget);
2857 GtkEntryPrivate *priv = entry->priv;
2858 EntryIconInfo *icon_info = NULL;
2861 for (i = 0; i < MAX_ICONS; i++)
2863 if ((icon_info = priv->icons[i]) != NULL)
2865 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
2866 gdk_window_hide (icon_info->window);
2870 gdk_window_hide (priv->text_area);
2872 GTK_WIDGET_CLASS (gtk_entry_parent_class)->unmap (widget);
2876 gtk_entry_realize (GtkWidget *widget)
2879 GtkEntryPrivate *priv;
2880 EntryIconInfo *icon_info;
2882 GdkWindowAttr attributes;
2883 gint attributes_mask;
2884 gint frame_x, frame_y;
2887 gtk_widget_set_realized (widget, TRUE);
2888 window = gtk_widget_get_parent_window (widget);
2889 gtk_widget_set_window (widget, window);
2890 g_object_ref (window);
2892 entry = GTK_ENTRY (widget);
2895 attributes.window_type = GDK_WINDOW_CHILD;
2896 attributes.wclass = GDK_INPUT_ONLY;
2897 attributes.event_mask = gtk_widget_get_events (widget);
2898 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
2899 GDK_BUTTON_RELEASE_MASK |
2900 GDK_BUTTON1_MOTION_MASK |
2901 GDK_BUTTON3_MOTION_MASK |
2902 GDK_POINTER_MOTION_HINT_MASK |
2903 GDK_POINTER_MOTION_MASK |
2904 GDK_ENTER_NOTIFY_MASK |
2905 GDK_LEAVE_NOTIFY_MASK);
2906 attributes_mask = GDK_WA_X | GDK_WA_Y;
2908 get_text_area_size (entry, &attributes.x, &attributes.y, &attributes.width, &attributes.height);
2910 get_frame_size (entry, TRUE, &frame_x, &frame_y, NULL, NULL);
2911 attributes.x += frame_x;
2912 attributes.y += frame_y;
2914 if (gtk_widget_is_sensitive (widget))
2916 attributes.cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
2917 attributes_mask |= GDK_WA_CURSOR;
2920 priv->text_area = gdk_window_new (gtk_widget_get_window (widget),
2924 gdk_window_set_user_data (priv->text_area, entry);
2926 if (attributes_mask & GDK_WA_CURSOR)
2927 g_object_unref (attributes.cursor);
2929 gtk_im_context_set_client_window (priv->im_context, priv->text_area);
2931 gtk_entry_adjust_scroll (entry);
2932 gtk_entry_update_primary_selection (entry);
2935 /* If the icon positions are already setup, create their windows.
2936 * Otherwise if they don't exist yet, then construct_icon_info()
2937 * will create the windows once the widget is already realized.
2939 for (i = 0; i < MAX_ICONS; i++)
2941 if ((icon_info = priv->icons[i]) != NULL)
2943 if (icon_info->window == NULL)
2944 realize_icon_info (widget, i);
2950 gtk_entry_unrealize (GtkWidget *widget)
2952 GtkEntry *entry = GTK_ENTRY (widget);
2953 GtkEntryPrivate *priv = entry->priv;
2954 GtkClipboard *clipboard;
2955 EntryIconInfo *icon_info;
2958 gtk_entry_reset_layout (entry);
2960 gtk_im_context_set_client_window (priv->im_context, NULL);
2962 clipboard = gtk_widget_get_clipboard (widget, GDK_SELECTION_PRIMARY);
2963 if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (entry))
2964 gtk_clipboard_clear (clipboard);
2966 if (priv->text_area)
2968 gdk_window_set_user_data (priv->text_area, NULL);
2969 gdk_window_destroy (priv->text_area);
2970 priv->text_area = NULL;
2973 if (priv->popup_menu)
2975 gtk_widget_destroy (priv->popup_menu);
2976 priv->popup_menu = NULL;
2979 GTK_WIDGET_CLASS (gtk_entry_parent_class)->unrealize (widget);
2981 for (i = 0; i < MAX_ICONS; i++)
2983 if ((icon_info = priv->icons[i]) != NULL)
2985 if (icon_info->window != NULL)
2987 gdk_window_destroy (icon_info->window);
2988 icon_info->window = NULL;
2995 _gtk_entry_get_borders (GtkEntry *entry,
2999 GtkEntryPrivate *priv = entry->priv;
3000 GtkWidget *widget = GTK_WIDGET (entry);
3002 if (priv->has_frame)
3004 GtkStyleContext *context;
3007 context = gtk_widget_get_style_context (widget);
3008 gtk_style_context_get_padding (context, 0, &padding);
3010 *xborder = padding.left;
3011 *yborder = padding.top;
3019 if (!priv->interior_focus)
3021 *xborder += priv->focus_width;
3022 *yborder += priv->focus_width;
3027 gtk_entry_get_preferred_width (GtkWidget *widget,
3031 GtkEntry *entry = GTK_ENTRY (widget);
3032 GtkEntryPrivate *priv = entry->priv;
3033 PangoFontMetrics *metrics;
3034 gint xborder, yborder;
3035 GtkBorder inner_border;
3036 PangoContext *context;
3037 GtkStyleContext *style_context;
3038 GtkStateFlags state;
3039 gint icon_widths = 0;
3043 context = gtk_widget_get_pango_context (widget);
3045 style_context = gtk_widget_get_style_context (widget);
3046 state = gtk_widget_get_state_flags (widget);
3048 metrics = pango_context_get_metrics (context,
3049 gtk_style_context_get_font (style_context, state),
3050 pango_context_get_language (context));
3052 _gtk_entry_get_borders (entry, &xborder, &yborder);
3053 _gtk_entry_effective_inner_border (entry, &inner_border);
3055 if (priv->width_chars < 0)
3056 width = MIN_ENTRY_WIDTH + xborder * 2 + inner_border.left + inner_border.right;
3059 gint char_width = pango_font_metrics_get_approximate_char_width (metrics);
3060 gint digit_width = pango_font_metrics_get_approximate_digit_width (metrics);
3061 gint char_pixels = (MAX (char_width, digit_width) + PANGO_SCALE - 1) / PANGO_SCALE;
3063 width = char_pixels * priv->width_chars + xborder * 2 + inner_border.left + inner_border.right;
3066 for (i = 0; i < MAX_ICONS; i++)
3068 icon_width = get_icon_width (entry, i);
3070 icon_widths += icon_width + 2 * priv->icon_margin;
3073 if (icon_widths > width)
3074 width += icon_widths;
3076 pango_font_metrics_unref (metrics);
3083 gtk_entry_get_preferred_height (GtkWidget *widget,
3087 GtkEntry *entry = GTK_ENTRY (widget);
3088 GtkEntryPrivate *priv = entry->priv;
3089 PangoFontMetrics *metrics;
3090 gint xborder, yborder;
3091 GtkBorder inner_border;
3092 GtkStyleContext *style_context;
3093 GtkStateFlags state;
3094 PangoContext *context;
3097 context = gtk_widget_get_pango_context (widget);
3099 style_context = gtk_widget_get_style_context (widget);
3100 state = gtk_widget_get_state_flags (widget);
3102 metrics = pango_context_get_metrics (context,
3103 gtk_style_context_get_font (style_context, state),
3104 pango_context_get_language (context));
3106 priv->ascent = pango_font_metrics_get_ascent (metrics);
3107 priv->descent = pango_font_metrics_get_descent (metrics);
3109 _gtk_entry_get_borders (entry, &xborder, &yborder);
3110 _gtk_entry_effective_inner_border (entry, &inner_border);
3112 height = PANGO_PIXELS (priv->ascent + priv->descent) + yborder * 2 + inner_border.top + inner_border.bottom;
3114 pango_font_metrics_unref (metrics);
3121 place_windows (GtkEntry *entry)
3123 GtkWidget *widget = GTK_WIDGET (entry);
3124 GtkEntryPrivate *priv = entry->priv;
3125 gint x, y, width, height;
3126 gint frame_x, frame_y;
3127 GtkAllocation primary;
3128 GtkAllocation secondary;
3129 EntryIconInfo *icon_info = NULL;
3131 get_frame_size (entry, TRUE, &frame_x, &frame_y, NULL, NULL);
3132 get_text_area_size (entry, &x, &y, &width, &height);
3133 get_icon_allocations (entry, &primary, &secondary);
3135 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3136 y += priv->focus_width;
3138 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
3139 x += secondary.width;
3142 width -= primary.width + secondary.width;
3146 primary.x += frame_x;
3147 primary.y += frame_y;
3148 secondary.x += frame_x;
3149 secondary.y += frame_y;
3151 if ((icon_info = priv->icons[GTK_ENTRY_ICON_PRIMARY]) != NULL)
3152 gdk_window_move_resize (icon_info->window,
3153 primary.x, primary.y,
3154 primary.width, primary.height);
3156 if ((icon_info = priv->icons[GTK_ENTRY_ICON_SECONDARY]) != NULL)
3157 gdk_window_move_resize (icon_info->window,
3158 secondary.x, secondary.y,
3159 secondary.width, secondary.height);
3161 gdk_window_move_resize (priv->text_area, x, y, width, height);
3165 gtk_entry_get_text_area_size (GtkEntry *entry,
3171 GtkEntryPrivate *priv = entry->priv;
3172 GtkWidget *widget = GTK_WIDGET (entry);
3173 GtkAllocation allocation;
3174 GtkRequisition requisition;
3177 gint xborder, yborder;
3179 gtk_widget_get_preferred_size (widget, &requisition, NULL);
3180 req_height = requisition.height - gtk_widget_get_margin_top (widget) - gtk_widget_get_margin_bottom (widget);
3182 gtk_widget_get_allocation (widget, &allocation);
3183 _gtk_entry_get_borders (entry, &xborder, &yborder);
3185 if (gtk_widget_get_realized (widget))
3186 get_frame_size (entry, TRUE, NULL, NULL, NULL, &frame_height);
3188 frame_height = req_height;
3190 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3191 frame_height -= 2 * priv->focus_width;
3197 *y = frame_height / 2 - (req_height - yborder * 2) / 2;
3200 *width = allocation.width - xborder * 2;
3203 *height = req_height - yborder * 2;
3207 get_text_area_size (GtkEntry *entry,
3213 GtkEntryClass *class;
3215 g_return_if_fail (GTK_IS_ENTRY (entry));
3217 class = GTK_ENTRY_GET_CLASS (entry);
3219 if (class->get_text_area_size)
3220 class->get_text_area_size (entry, x, y, width, height);
3225 get_frame_size (GtkEntry *entry,
3226 gboolean relative_to_window,
3232 GtkEntryPrivate *priv = entry->priv;
3233 GtkAllocation allocation;
3234 GtkRequisition requisition;
3235 GtkWidget *widget = GTK_WIDGET (entry);
3238 gtk_widget_get_preferred_size (widget, &requisition, NULL);
3240 req_height = requisition.height - gtk_widget_get_margin_top (widget) - gtk_widget_get_margin_bottom (widget);
3242 gtk_widget_get_allocation (widget, &allocation);
3245 *x = relative_to_window ? allocation.x : 0;
3249 if (priv->is_cell_renderer)
3252 *y = (allocation.height - req_height) / 2;
3254 if (relative_to_window)
3259 *width = allocation.width;
3263 if (priv->is_cell_renderer)
3264 *height = allocation.height;
3266 *height = req_height;
3271 _gtk_entry_effective_inner_border (GtkEntry *entry,
3274 GtkBorder *tmp_border;
3276 tmp_border = g_object_get_qdata (G_OBJECT (entry), quark_inner_border);
3280 *border = *tmp_border;
3284 gtk_widget_style_get (GTK_WIDGET (entry), "inner-border", &tmp_border, NULL);
3288 *border = *tmp_border;
3289 gtk_border_free (tmp_border);
3293 *border = default_inner_border;
3297 gtk_entry_size_allocate (GtkWidget *widget,
3298 GtkAllocation *allocation)
3300 GtkEntry *entry = GTK_ENTRY (widget);
3302 gtk_widget_set_allocation (widget, allocation);
3304 if (gtk_widget_get_realized (widget))
3306 GtkEntryCompletion* completion;
3308 place_windows (entry);
3309 gtk_entry_recompute (entry);
3311 completion = gtk_entry_get_completion (entry);
3312 if (completion && gtk_widget_get_mapped (completion->priv->popup_window))
3313 _gtk_entry_completion_resize_popup (completion);
3318 should_prelight (GtkEntry *entry,
3319 GtkEntryIconPosition icon_pos)
3321 GtkEntryPrivate *priv = entry->priv;
3322 EntryIconInfo *icon_info = priv->icons[icon_pos];
3328 if (icon_info->nonactivatable && icon_info->target_list == NULL)
3331 if (icon_info->pressed)
3334 gtk_widget_style_get (GTK_WIDGET (entry),
3335 "icon-prelight", &prelight,
3342 draw_icon (GtkWidget *widget,
3344 GtkEntryIconPosition icon_pos)
3346 GtkEntry *entry = GTK_ENTRY (widget);
3347 GtkEntryPrivate *priv = entry->priv;
3348 EntryIconInfo *icon_info = priv->icons[icon_pos];
3350 gint x, y, width, height;
3351 GtkStyleContext *context;
3356 gtk_entry_ensure_pixbuf (entry, icon_pos);
3358 if (icon_info->pixbuf == NULL)
3361 width = gdk_window_get_width (icon_info->window);
3362 height = gdk_window_get_height (icon_info->window);
3364 context = gtk_widget_get_style_context (widget);
3366 /* size_allocate hasn't been called yet. These are the default values.
3368 if (width == 1 || height == 1)
3371 pixbuf = icon_info->pixbuf;
3372 g_object_ref (pixbuf);
3374 if (gdk_pixbuf_get_height (pixbuf) > height)
3376 GdkPixbuf *temp_pixbuf;
3379 scale = height - 2 * priv->icon_margin;
3380 temp_pixbuf = gdk_pixbuf_scale_simple (pixbuf, scale, scale,
3381 GDK_INTERP_BILINEAR);
3382 g_object_unref (pixbuf);
3383 pixbuf = temp_pixbuf;
3386 x = (width - gdk_pixbuf_get_width (pixbuf)) / 2;
3387 y = (height - gdk_pixbuf_get_height (pixbuf)) / 2;
3389 gtk_render_icon (context, cr, pixbuf, x, y);
3391 g_object_unref (pixbuf);
3396 gtk_entry_draw_frame (GtkWidget *widget,
3397 GtkStyleContext *context,
3400 GtkEntry *entry = GTK_ENTRY (widget);
3401 GtkEntryPrivate *priv = entry->priv;
3402 gint x = 0, y = 0, width, height;
3403 gint frame_x, frame_y;
3407 get_frame_size (GTK_ENTRY (widget), FALSE, &frame_x, &frame_y, &width, &height);
3409 cairo_translate (cr, frame_x, frame_y);
3411 /* Fix a problem with some themes which assume that entry->text_area's
3412 * width equals widget->window's width
3413 * http://bugzilla.gnome.org/show_bug.cgi?id=466000 */
3414 if (GTK_IS_SPIN_BUTTON (widget))
3416 gint xborder, yborder;
3418 gtk_entry_get_text_area_size (GTK_ENTRY (widget), &x, NULL, &width, NULL);
3419 _gtk_entry_get_borders (GTK_ENTRY (widget), &xborder, &yborder);
3422 width += xborder * 2;
3425 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3427 x += priv->focus_width;
3428 y += priv->focus_width;
3429 width -= 2 * priv->focus_width;
3430 height -= 2 * priv->focus_width;
3433 gtk_render_background (context, cr,
3434 x, y, width, height);
3436 if (priv->has_frame)
3437 gtk_render_frame (context, cr,
3438 x, y, width, height);
3440 gtk_entry_draw_progress (widget, context, cr);
3442 if (gtk_widget_has_visible_focus (widget) && !priv->interior_focus)
3444 x -= priv->focus_width;
3445 y -= priv->focus_width;
3446 width += 2 * priv->focus_width;
3447 height += 2 * priv->focus_width;
3449 gtk_render_focus (context, cr,
3450 0, 0, width, height);
3457 get_progress_area (GtkWidget *widget,
3463 GtkEntry *entry = GTK_ENTRY (widget);
3464 GtkEntryPrivate *private = entry->priv;
3465 GtkBorder *progress_border;
3467 get_text_area_size (entry, x, y, width, height);
3469 if (!private->interior_focus)
3471 *x -= private->focus_width;
3472 *y -= private->focus_width;
3473 *width += 2 * private->focus_width;
3474 *height += 2 * private->focus_width;
3477 gtk_widget_style_get (widget, "progress-border", &progress_border, NULL);
3479 if (progress_border)
3481 *x += progress_border->left;
3482 *y += progress_border->top;
3483 *width -= progress_border->left + progress_border->right;
3484 *height -= progress_border->top + progress_border->bottom;
3486 gtk_border_free (progress_border);
3489 if (private->progress_pulse_mode)
3491 gdouble value = private->progress_pulse_current;
3493 *x += (gint) floor(value * (*width));
3494 *width = (gint) ceil(private->progress_pulse_fraction * (*width));
3496 else if (private->progress_fraction > 0)
3498 gdouble value = private->progress_fraction;
3500 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
3504 bar_width = floor(value * (*width) + 0.5);
3505 *x += *width - bar_width;
3510 *width = (gint) floor(value * (*width) + 0.5);
3521 gtk_entry_draw_progress (GtkWidget *widget,
3522 GtkStyleContext *context,
3525 gint x, y, width, height;
3527 get_progress_area (widget, &x, &y, &width, &height);
3529 if ((width <= 0) || (height <= 0))
3532 gtk_style_context_save (context);
3533 gtk_style_context_add_class (context, GTK_STYLE_CLASS_PROGRESSBAR);
3535 gtk_render_activity (context, cr,
3536 x, y, width, height);
3538 gtk_style_context_restore (context);
3542 gtk_entry_draw (GtkWidget *widget,
3545 GtkEntry *entry = GTK_ENTRY (widget);
3546 GtkStyleContext *context;
3547 GtkStateFlags state;
3548 GtkEntryPrivate *priv = entry->priv;
3551 context = gtk_widget_get_style_context (widget);
3552 state = gtk_widget_get_state_flags (widget);
3554 gtk_style_context_save (context);
3555 gtk_style_context_set_state (context, state);
3557 /* Draw entry_bg, shadow, progress and focus */
3558 gtk_entry_draw_frame (widget, context, cr);
3560 /* Draw text and cursor */
3563 gtk_cairo_transform_to_window (cr, widget, priv->text_area);
3565 if (priv->dnd_position != -1)
3566 gtk_entry_draw_cursor (GTK_ENTRY (widget), cr, CURSOR_DND);
3568 gtk_entry_draw_text (GTK_ENTRY (widget), cr);
3570 /* When no text is being displayed at all, don't show the cursor */
3571 if (gtk_entry_get_display_mode (entry) != DISPLAY_BLANK &&
3572 gtk_widget_has_focus (widget) &&
3573 priv->selection_bound == priv->current_pos && priv->cursor_visible)
3574 gtk_entry_draw_cursor (GTK_ENTRY (widget), cr, CURSOR_STANDARD);
3579 for (i = 0; i < MAX_ICONS; i++)
3581 EntryIconInfo *icon_info = priv->icons[i];
3583 if (icon_info != NULL)
3587 gtk_cairo_transform_to_window (cr, widget, icon_info->window);
3589 draw_icon (widget, cr, i);
3595 gtk_style_context_restore (context);
3601 gtk_entry_enter_notify (GtkWidget *widget,
3602 GdkEventCrossing *event)
3604 GtkEntry *entry = GTK_ENTRY (widget);
3605 GtkEntryPrivate *priv = entry->priv;
3608 for (i = 0; i < MAX_ICONS; i++)
3610 EntryIconInfo *icon_info = priv->icons[i];
3612 if (icon_info != NULL && event->window == icon_info->window)
3614 if (should_prelight (entry, i))
3616 icon_info->prelight = TRUE;
3617 gtk_widget_queue_draw (widget);
3628 gtk_entry_leave_notify (GtkWidget *widget,
3629 GdkEventCrossing *event)
3631 GtkEntry *entry = GTK_ENTRY (widget);
3632 GtkEntryPrivate *priv = entry->priv;
3635 for (i = 0; i < MAX_ICONS; i++)
3637 EntryIconInfo *icon_info = priv->icons[i];
3639 if (icon_info != NULL && event->window == icon_info->window)
3641 /* a grab means that we may never see the button release */
3642 if (event->mode == GDK_CROSSING_GRAB || event->mode == GDK_CROSSING_GTK_GRAB)
3643 icon_info->pressed = FALSE;
3645 if (should_prelight (entry, i))
3647 icon_info->prelight = FALSE;
3648 gtk_widget_queue_draw (widget);
3659 gtk_entry_get_pixel_ranges (GtkEntry *entry,
3663 gint start_char, end_char;
3665 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start_char, &end_char))
3667 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
3668 PangoLayoutLine *line = pango_layout_get_lines_readonly (layout)->data;
3669 const char *text = pango_layout_get_text (layout);
3670 gint start_index = g_utf8_offset_to_pointer (text, start_char) - text;
3671 gint end_index = g_utf8_offset_to_pointer (text, end_char) - text;
3672 gint real_n_ranges, i;
3674 pango_layout_line_get_x_ranges (line, start_index, end_index, ranges, &real_n_ranges);
3680 for (i = 0; i < real_n_ranges; ++i)
3682 r[2 * i + 1] = (r[2 * i + 1] - r[2 * i]) / PANGO_SCALE;
3683 r[2 * i] = r[2 * i] / PANGO_SCALE;
3688 *n_ranges = real_n_ranges;
3700 in_selection (GtkEntry *entry,
3705 gint retval = FALSE;
3707 gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
3709 for (i = 0; i < n_ranges; ++i)
3711 if (x >= ranges[2 * i] && x < ranges[2 * i] + ranges[2 * i + 1])
3723 gtk_entry_button_press (GtkWidget *widget,
3724 GdkEventButton *event)
3726 GtkEntry *entry = GTK_ENTRY (widget);
3727 GtkEditable *editable = GTK_EDITABLE (widget);
3728 GtkEntryPrivate *priv = entry->priv;
3729 EntryIconInfo *icon_info = NULL;
3731 gint sel_start, sel_end;
3734 for (i = 0; i < MAX_ICONS; i++)
3736 icon_info = priv->icons[i];
3738 if (!icon_info || icon_info->insensitive)
3741 if (event->window == icon_info->window)
3743 if (should_prelight (entry, i))
3745 icon_info->prelight = FALSE;
3746 gtk_widget_queue_draw (widget);
3749 priv->start_x = event->x;
3750 priv->start_y = event->y;
3751 icon_info->pressed = TRUE;
3753 if (!icon_info->nonactivatable)
3754 g_signal_emit (entry, signals[ICON_PRESS], 0, i, event);
3760 if (event->window != priv->text_area ||
3761 (priv->button && event->button != priv->button))
3764 gtk_entry_reset_blink_time (entry);
3766 priv->button = event->button;
3768 if (!gtk_widget_has_focus (widget))
3770 priv->in_click = TRUE;
3771 gtk_widget_grab_focus (widget);
3772 priv->in_click = FALSE;
3775 tmp_pos = gtk_entry_find_position (entry, event->x + priv->scroll_offset);
3777 if (gdk_event_triggers_context_menu ((GdkEvent *) event))
3779 gtk_entry_do_popup (entry, event);
3780 priv->button = 0; /* Don't wait for release, since the menu will gtk_grab_add */
3784 else if (event->button == 1)
3786 gboolean have_selection = gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end);
3788 priv->select_words = FALSE;
3789 priv->select_lines = FALSE;
3792 gtk_widget_get_modifier_mask (widget,
3793 GDK_MODIFIER_INTENT_EXTEND_SELECTION))
3795 _gtk_entry_reset_im_context (entry);
3797 if (!have_selection) /* select from the current position to the clicked position */
3798 sel_start = sel_end = priv->current_pos;
3800 if (tmp_pos > sel_start && tmp_pos < sel_end)
3802 /* Truncate current selection, but keep it as big as possible */
3803 if (tmp_pos - sel_start > sel_end - tmp_pos)
3804 gtk_entry_set_positions (entry, sel_start, tmp_pos);
3806 gtk_entry_set_positions (entry, tmp_pos, sel_end);
3810 gboolean extend_to_left;
3813 /* Figure out what click selects and extend current selection */
3814 switch (event->type)
3816 case GDK_BUTTON_PRESS:
3817 gtk_entry_set_positions (entry, tmp_pos, tmp_pos);
3820 case GDK_2BUTTON_PRESS:
3821 priv->select_words = TRUE;
3822 gtk_entry_select_word (entry);
3825 case GDK_3BUTTON_PRESS:
3826 priv->select_lines = TRUE;
3827 gtk_entry_select_line (entry);
3834 start = MIN (priv->current_pos, priv->selection_bound);
3835 start = MIN (sel_start, start);
3837 end = MAX (priv->current_pos, priv->selection_bound);
3838 end = MAX (sel_end, end);
3840 if (tmp_pos == sel_start || tmp_pos == sel_end)
3841 extend_to_left = (tmp_pos == start);
3843 extend_to_left = (end == sel_end);
3846 gtk_entry_set_positions (entry, start, end);
3848 gtk_entry_set_positions (entry, end, start);
3851 else /* no shift key */
3852 switch (event->type)
3854 case GDK_BUTTON_PRESS:
3855 if (in_selection (entry, event->x + priv->scroll_offset))
3857 /* Click inside the selection - we'll either start a drag, or
3858 * clear the selection
3860 priv->in_drag = TRUE;
3861 priv->drag_start_x = event->x + priv->scroll_offset;
3862 priv->drag_start_y = event->y;
3865 gtk_editable_set_position (editable, tmp_pos);
3868 case GDK_2BUTTON_PRESS:
3869 /* We ALWAYS receive a GDK_BUTTON_PRESS immediately before
3870 * receiving a GDK_2BUTTON_PRESS so we need to reset
3871 * priv->in_drag which may have been set above
3873 priv->in_drag = FALSE;
3874 priv->select_words = TRUE;
3875 gtk_entry_select_word (entry);
3878 case GDK_3BUTTON_PRESS:
3879 /* We ALWAYS receive a GDK_BUTTON_PRESS immediately before
3880 * receiving a GDK_3BUTTON_PRESS so we need to reset
3881 * priv->in_drag which may have been set above
3883 priv->in_drag = FALSE;
3884 priv->select_lines = TRUE;
3885 gtk_entry_select_line (entry);
3894 else if (event->button == 2 && event->type == GDK_BUTTON_PRESS)
3898 priv->insert_pos = tmp_pos;
3899 gtk_entry_paste (entry, GDK_SELECTION_PRIMARY);
3904 gtk_widget_error_bell (widget);
3912 gtk_entry_button_release (GtkWidget *widget,
3913 GdkEventButton *event)
3915 GtkEntry *entry = GTK_ENTRY (widget);
3916 GtkEntryPrivate *priv = entry->priv;
3917 EntryIconInfo *icon_info = NULL;
3920 for (i = 0; i < MAX_ICONS; i++)
3922 icon_info = priv->icons[i];
3924 if (!icon_info || icon_info->insensitive)
3927 if (event->window == icon_info->window)
3929 icon_info->pressed = FALSE;
3931 if (should_prelight (entry, i) &&
3932 event->x >= 0 && event->y >= 0 &&
3933 event->x < gdk_window_get_width (icon_info->window) &&
3934 event->y < gdk_window_get_height (icon_info->window))
3936 icon_info->prelight = TRUE;
3937 gtk_widget_queue_draw (widget);
3940 if (!icon_info->nonactivatable)
3941 g_signal_emit (entry, signals[ICON_RELEASE], 0, i, event);
3947 if (event->window != priv->text_area || priv->button != event->button)
3952 gint tmp_pos = gtk_entry_find_position (entry, priv->drag_start_x);
3954 gtk_editable_set_position (GTK_EDITABLE (entry), tmp_pos);
3961 gtk_entry_update_primary_selection (entry);
3967 _gtk_entry_get_selected_text (GtkEntry *entry)
3969 GtkEditable *editable = GTK_EDITABLE (entry);
3970 gint start_text, end_text;
3973 if (gtk_editable_get_selection_bounds (editable, &start_text, &end_text))
3974 text = gtk_editable_get_chars (editable, start_text, end_text);
3980 gtk_entry_motion_notify (GtkWidget *widget,
3981 GdkEventMotion *event)
3983 GtkEntry *entry = GTK_ENTRY (widget);
3984 GtkEntryPrivate *priv = entry->priv;
3985 EntryIconInfo *icon_info = NULL;
3989 for (i = 0; i < MAX_ICONS; i++)
3991 icon_info = priv->icons[i];
3993 if (!icon_info || icon_info->insensitive)
3996 if (event->window == icon_info->window)
3998 if (icon_info->pressed &&
3999 icon_info->target_list != NULL &&
4000 gtk_drag_check_threshold (widget,
4006 icon_info->in_drag = TRUE;
4007 icon_info->pressed = FALSE;
4008 gtk_drag_begin (widget,
4009 icon_info->target_list,
4019 if (priv->mouse_cursor_obscured)
4023 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
4024 gdk_window_set_cursor (priv->text_area, cursor);
4025 g_object_unref (cursor);
4026 priv->mouse_cursor_obscured = FALSE;
4029 if (event->window != priv->text_area || priv->button != 1)
4032 if (priv->select_lines)
4035 gdk_event_request_motions (event);
4039 if (gtk_entry_get_display_mode (entry) == DISPLAY_NORMAL &&
4040 gtk_drag_check_threshold (widget,
4041 priv->drag_start_x, priv->drag_start_y,
4042 event->x + priv->scroll_offset, event->y))
4044 GdkDragContext *context;
4045 GtkTargetList *target_list = gtk_target_list_new (NULL, 0);
4046 guint actions = priv->editable ? GDK_ACTION_COPY | GDK_ACTION_MOVE : GDK_ACTION_COPY;
4048 cairo_surface_t *surface;
4050 gtk_target_list_add_text_targets (target_list, 0);
4052 text = _gtk_entry_get_selected_text (entry);
4053 surface = _gtk_text_util_create_drag_icon (widget, text, -1);
4055 context = gtk_drag_begin (widget, target_list, actions,
4056 priv->button, (GdkEvent *)event);
4059 gtk_drag_set_icon_surface (context, surface);
4061 gtk_drag_set_icon_default (context);
4064 cairo_surface_destroy (surface);
4067 priv->in_drag = FALSE;
4070 gtk_target_list_unref (target_list);
4077 else if (event->y >= gdk_window_get_height (priv->text_area))
4078 tmp_pos = gtk_entry_buffer_get_length (get_buffer (entry));
4080 tmp_pos = gtk_entry_find_position (entry, event->x + priv->scroll_offset);
4082 if (priv->select_words)
4085 gint old_min, old_max;
4088 min = gtk_entry_move_backward_word (entry, tmp_pos, TRUE);
4089 max = gtk_entry_move_forward_word (entry, tmp_pos, TRUE);
4091 pos = priv->current_pos;
4092 bound = priv->selection_bound;
4094 old_min = MIN(priv->current_pos, priv->selection_bound);
4095 old_max = MAX(priv->current_pos, priv->selection_bound);
4102 else if (old_max < max)
4107 else if (pos == old_min)
4109 if (priv->current_pos != min)
4114 if (priv->current_pos != max)
4118 gtk_entry_set_positions (entry, pos, bound);
4121 gtk_entry_set_positions (entry, tmp_pos, -1);
4128 set_invisible_cursor (GdkWindow *window)
4130 GdkDisplay *display;
4133 display = gdk_window_get_display (window);
4134 cursor = gdk_cursor_new_for_display (display, GDK_BLANK_CURSOR);
4136 gdk_window_set_cursor (window, cursor);
4138 g_object_unref (cursor);
4142 gtk_entry_obscure_mouse_cursor (GtkEntry *entry)
4144 GtkEntryPrivate *priv = entry->priv;
4146 if (priv->mouse_cursor_obscured)
4149 set_invisible_cursor (priv->text_area);
4151 priv->mouse_cursor_obscured = TRUE;
4155 gtk_entry_key_press (GtkWidget *widget,
4158 GtkEntry *entry = GTK_ENTRY (widget);
4159 GtkEntryPrivate *priv = entry->priv;
4161 gtk_entry_reset_blink_time (entry);
4162 gtk_entry_pend_cursor_blink (entry);
4166 if (gtk_im_context_filter_keypress (priv->im_context, event))
4168 gtk_entry_obscure_mouse_cursor (entry);
4169 priv->need_im_reset = TRUE;
4174 if (event->keyval == GDK_KEY_Return ||
4175 event->keyval == GDK_KEY_KP_Enter ||
4176 event->keyval == GDK_KEY_ISO_Enter ||
4177 event->keyval == GDK_KEY_Escape)
4179 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
4181 if (completion && completion->priv->completion_timeout)
4183 g_source_remove (completion->priv->completion_timeout);
4184 completion->priv->completion_timeout = 0;
4187 _gtk_entry_reset_im_context (entry);
4190 if (GTK_WIDGET_CLASS (gtk_entry_parent_class)->key_press_event (widget, event))
4191 /* Activate key bindings
4195 if (!priv->editable && event->length)
4196 gtk_widget_error_bell (widget);
4202 gtk_entry_key_release (GtkWidget *widget,
4205 GtkEntry *entry = GTK_ENTRY (widget);
4206 GtkEntryPrivate *priv = entry->priv;
4210 if (gtk_im_context_filter_keypress (priv->im_context, event))
4212 priv->need_im_reset = TRUE;
4217 return GTK_WIDGET_CLASS (gtk_entry_parent_class)->key_release_event (widget, event);
4221 gtk_entry_focus_in (GtkWidget *widget,
4222 GdkEventFocus *event)
4224 GtkEntry *entry = GTK_ENTRY (widget);
4225 GtkEntryPrivate *priv = entry->priv;
4228 gtk_widget_queue_draw (widget);
4230 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (widget));
4234 priv->need_im_reset = TRUE;
4235 gtk_im_context_focus_in (priv->im_context);
4236 keymap_state_changed (keymap, entry);
4237 g_signal_connect (keymap, "state-changed",
4238 G_CALLBACK (keymap_state_changed), entry);
4241 g_signal_connect (keymap, "direction-changed",
4242 G_CALLBACK (keymap_direction_changed), entry);
4244 if (gtk_entry_buffer_get_bytes (get_buffer (entry)) == 0 &&
4245 priv->placeholder_text != NULL)
4247 gtk_entry_recompute (entry);
4251 gtk_entry_reset_blink_time (entry);
4252 gtk_entry_check_cursor_blink (entry);
4259 gtk_entry_focus_out (GtkWidget *widget,
4260 GdkEventFocus *event)
4262 GtkEntry *entry = GTK_ENTRY (widget);
4263 GtkEntryPrivate *priv = entry->priv;
4264 GtkEntryCompletion *completion;
4267 gtk_widget_queue_draw (widget);
4269 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (widget));
4273 priv->need_im_reset = TRUE;
4274 gtk_im_context_focus_out (priv->im_context);
4275 remove_capslock_feedback (entry);
4278 if (gtk_entry_buffer_get_bytes (get_buffer (entry)) == 0 &&
4279 priv->placeholder_text != NULL)
4281 gtk_entry_recompute (entry);
4285 gtk_entry_check_cursor_blink (entry);
4288 g_signal_handlers_disconnect_by_func (keymap, keymap_state_changed, entry);
4289 g_signal_handlers_disconnect_by_func (keymap, keymap_direction_changed, entry);
4291 completion = gtk_entry_get_completion (entry);
4293 _gtk_entry_completion_popdown (completion);
4299 gtk_entry_grab_focus (GtkWidget *widget)
4301 GtkEntry *entry = GTK_ENTRY (widget);
4302 GtkEntryPrivate *priv = entry->priv;
4303 gboolean select_on_focus;
4305 GTK_WIDGET_CLASS (gtk_entry_parent_class)->grab_focus (widget);
4307 if (priv->editable && !priv->in_click)
4309 g_object_get (gtk_widget_get_settings (widget),
4310 "gtk-entry-select-on-focus",
4314 if (select_on_focus)
4315 gtk_editable_select_region (GTK_EDITABLE (widget), 0, -1);
4320 gtk_entry_direction_changed (GtkWidget *widget,
4321 GtkTextDirection previous_dir)
4323 GtkEntry *entry = GTK_ENTRY (widget);
4325 gtk_entry_recompute (entry);
4327 GTK_WIDGET_CLASS (gtk_entry_parent_class)->direction_changed (widget, previous_dir);
4331 gtk_entry_state_flags_changed (GtkWidget *widget,
4332 GtkStateFlags previous_state)
4334 GtkEntry *entry = GTK_ENTRY (widget);
4335 GtkEntryPrivate *priv = entry->priv;
4338 if (gtk_widget_get_realized (widget))
4340 if (gtk_widget_is_sensitive (widget))
4341 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
4345 gdk_window_set_cursor (priv->text_area, cursor);
4348 g_object_unref (cursor);
4350 priv->mouse_cursor_obscured = FALSE;
4352 update_cursors (widget);
4355 if (!gtk_widget_is_sensitive (widget))
4357 /* Clear any selection */
4358 gtk_editable_select_region (GTK_EDITABLE (entry), priv->current_pos, priv->current_pos);
4361 gtk_entry_update_cached_style_values (entry);
4365 gtk_entry_screen_changed (GtkWidget *widget,
4366 GdkScreen *old_screen)
4368 gtk_entry_recompute (GTK_ENTRY (widget));
4371 /* GtkEditable method implementations
4374 gtk_entry_insert_text (GtkEditable *editable,
4375 const gchar *new_text,
4376 gint new_text_length,
4379 g_object_ref (editable);
4382 * The incoming text may a password or other secret. We make sure
4383 * not to copy it into temporary buffers.
4386 g_signal_emit_by_name (editable, "insert-text", new_text, new_text_length, position);
4388 g_object_unref (editable);
4392 gtk_entry_delete_text (GtkEditable *editable,
4396 g_object_ref (editable);
4398 g_signal_emit_by_name (editable, "delete-text", start_pos, end_pos);
4400 g_object_unref (editable);
4404 gtk_entry_get_chars (GtkEditable *editable,
4408 GtkEntry *entry = GTK_ENTRY (editable);
4411 gint start_index, end_index;
4413 text = gtk_entry_buffer_get_text (get_buffer (entry));
4414 text_length = gtk_entry_buffer_get_length (get_buffer (entry));
4417 end_pos = text_length;
4419 start_pos = MIN (text_length, start_pos);
4420 end_pos = MIN (text_length, end_pos);
4422 start_index = g_utf8_offset_to_pointer (text, start_pos) - text;
4423 end_index = g_utf8_offset_to_pointer (text, end_pos) - text;
4425 return g_strndup (text + start_index, end_index - start_index);
4429 gtk_entry_real_set_position (GtkEditable *editable,
4432 GtkEntry *entry = GTK_ENTRY (editable);
4433 GtkEntryPrivate *priv = entry->priv;
4437 length = gtk_entry_buffer_get_length (get_buffer (entry));
4438 if (position < 0 || position > length)
4441 if (position != priv->current_pos ||
4442 position != priv->selection_bound)
4444 _gtk_entry_reset_im_context (entry);
4445 gtk_entry_set_positions (entry, position, position);
4450 gtk_entry_get_position (GtkEditable *editable)
4452 GtkEntry *entry = GTK_ENTRY (editable);
4453 GtkEntryPrivate *priv = entry->priv;
4455 return priv->current_pos;
4459 gtk_entry_set_selection_bounds (GtkEditable *editable,
4463 GtkEntry *entry = GTK_ENTRY (editable);
4466 length = gtk_entry_buffer_get_length (get_buffer (entry));
4472 _gtk_entry_reset_im_context (entry);
4474 gtk_entry_set_positions (entry,
4476 MIN (start, length));
4478 gtk_entry_update_primary_selection (entry);
4482 gtk_entry_get_selection_bounds (GtkEditable *editable,
4486 GtkEntry *entry = GTK_ENTRY (editable);
4487 GtkEntryPrivate *priv = entry->priv;
4489 *start = priv->selection_bound;
4490 *end = priv->current_pos;
4492 return (priv->selection_bound != priv->current_pos);
4496 icon_theme_changed (GtkEntry *entry)
4498 GtkEntryPrivate *priv = entry->priv;
4501 for (i = 0; i < MAX_ICONS; i++)
4503 EntryIconInfo *icon_info = priv->icons[i];
4504 if (icon_info != NULL)
4506 if (icon_info->storage_type == GTK_IMAGE_ICON_NAME)
4507 gtk_entry_set_icon_from_icon_name (entry, i, icon_info->icon_name);
4508 else if (icon_info->storage_type == GTK_IMAGE_STOCK)
4509 gtk_entry_set_icon_from_stock (entry, i, icon_info->stock_id);
4510 else if (icon_info->storage_type == GTK_IMAGE_GICON)
4511 gtk_entry_set_icon_from_gicon (entry, i, icon_info->gicon);
4515 gtk_widget_queue_draw (GTK_WIDGET (entry));
4519 icon_margin_changed (GtkEntry *entry)
4521 GtkEntryPrivate *priv = entry->priv;
4524 _gtk_entry_effective_inner_border (GTK_ENTRY (entry), &border);
4526 priv->icon_margin = border.left;
4530 gtk_entry_update_cached_style_values (GtkEntry *entry)
4532 GtkEntryPrivate *priv = entry->priv;
4534 gboolean interior_focus;
4536 gtk_widget_style_get (GTK_WIDGET (entry),
4537 "focus-line-width", &focus_width,
4538 "interior-focus", &interior_focus,
4540 priv->focus_width = focus_width;
4541 priv->interior_focus = interior_focus;
4543 if (!priv->invisible_char_set)
4545 gunichar ch = find_invisible_char (GTK_WIDGET (entry));
4547 if (priv->invisible_char != ch)
4549 priv->invisible_char = ch;
4550 g_object_notify (G_OBJECT (entry), "invisible-char");
4556 gtk_entry_style_updated (GtkWidget *widget)
4558 GtkEntry *entry = GTK_ENTRY (widget);
4560 GTK_WIDGET_CLASS (gtk_entry_parent_class)->style_updated (widget);
4562 gtk_entry_update_cached_style_values (entry);
4564 gtk_entry_recompute (entry);
4566 icon_theme_changed (entry);
4567 icon_margin_changed (entry);
4570 /* GtkCellEditable method implementations
4573 gtk_cell_editable_entry_activated (GtkEntry *entry, gpointer data)
4575 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4576 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4580 gtk_cell_editable_key_press_event (GtkEntry *entry,
4581 GdkEventKey *key_event,
4584 GtkEntryPrivate *priv = entry->priv;
4586 if (key_event->keyval == GDK_KEY_Escape)
4588 priv->editing_canceled = TRUE;
4589 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4590 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4595 /* override focus */
4596 if (key_event->keyval == GDK_KEY_Up || key_event->keyval == GDK_KEY_Down)
4598 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4599 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4608 gtk_entry_start_editing (GtkCellEditable *cell_editable,
4611 GtkEntry *entry = GTK_ENTRY (cell_editable);
4612 GtkEntryPrivate *priv = entry->priv;
4614 priv->is_cell_renderer = TRUE;
4616 g_signal_connect (cell_editable, "activate",
4617 G_CALLBACK (gtk_cell_editable_entry_activated), NULL);
4618 g_signal_connect (cell_editable, "key-press-event",
4619 G_CALLBACK (gtk_cell_editable_key_press_event), NULL);
4623 gtk_entry_password_hint_free (GtkEntryPasswordHint *password_hint)
4625 if (password_hint->source_id)
4626 g_source_remove (password_hint->source_id);
4628 g_slice_free (GtkEntryPasswordHint, password_hint);
4633 gtk_entry_remove_password_hint (gpointer data)
4635 GtkEntryPasswordHint *password_hint = g_object_get_qdata (data, quark_password_hint);
4636 password_hint->position = -1;
4638 /* Force the string to be redrawn, but now without a visible character */
4639 gtk_entry_recompute (GTK_ENTRY (data));
4643 /* Default signal handlers
4646 gtk_entry_real_insert_text (GtkEditable *editable,
4647 const gchar *new_text,
4648 gint new_text_length,
4654 n_chars = g_utf8_strlen (new_text, new_text_length);
4657 * The actual insertion into the buffer. This will end up firing the
4658 * following signal handlers: buffer_inserted_text(), buffer_notify_display_text(),
4659 * buffer_notify_text(), buffer_notify_length()
4661 begin_change (GTK_ENTRY (editable));
4662 g_object_freeze_notify (G_OBJECT (editable));
4664 n_inserted = gtk_entry_buffer_insert_text (get_buffer (GTK_ENTRY (editable)), *position, new_text, n_chars);
4666 g_object_thaw_notify (G_OBJECT (editable));
4667 end_change (GTK_ENTRY (editable));
4669 if (n_inserted != n_chars)
4670 gtk_widget_error_bell (GTK_WIDGET (editable));
4672 *position += n_inserted;
4676 gtk_entry_real_delete_text (GtkEditable *editable,
4681 * The actual deletion from the buffer. This will end up firing the
4682 * following signal handlers: buffer_deleted_text(), buffer_notify_display_text(),
4683 * buffer_notify_text(), buffer_notify_length()
4686 begin_change (GTK_ENTRY (editable));
4687 g_object_freeze_notify (G_OBJECT (editable));
4688 gtk_entry_buffer_delete_text (get_buffer (GTK_ENTRY (editable)), start_pos, end_pos - start_pos);
4689 g_object_thaw_notify (G_OBJECT (editable));
4690 end_change (GTK_ENTRY (editable));
4693 /* GtkEntryBuffer signal handlers
4696 buffer_inserted_text (GtkEntryBuffer *buffer,
4702 GtkEntryPrivate *priv = entry->priv;
4703 guint password_hint_timeout;
4705 gint selection_bound;
4707 current_pos = priv->current_pos;
4708 if (current_pos > position)
4709 current_pos += n_chars;
4711 selection_bound = priv->selection_bound;
4712 if (selection_bound > position)
4713 selection_bound += n_chars;
4715 gtk_entry_set_positions (entry, current_pos, selection_bound);
4717 /* Calculate the password hint if it needs to be displayed. */
4718 if (n_chars == 1 && !priv->visible)
4720 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
4721 "gtk-entry-password-hint-timeout", &password_hint_timeout,
4724 if (password_hint_timeout > 0)
4726 GtkEntryPasswordHint *password_hint = g_object_get_qdata (G_OBJECT (entry),
4727 quark_password_hint);
4730 password_hint = g_slice_new0 (GtkEntryPasswordHint);
4731 g_object_set_qdata_full (G_OBJECT (entry), quark_password_hint, password_hint,
4732 (GDestroyNotify)gtk_entry_password_hint_free);
4735 password_hint->position = position;
4736 if (password_hint->source_id)
4737 g_source_remove (password_hint->source_id);
4738 password_hint->source_id = gdk_threads_add_timeout (password_hint_timeout,
4739 (GSourceFunc)gtk_entry_remove_password_hint, entry);
4745 buffer_deleted_text (GtkEntryBuffer *buffer,
4750 GtkEntryPrivate *priv = entry->priv;
4751 guint end_pos = position + n_chars;
4752 gint selection_bound;
4755 current_pos = priv->current_pos;
4756 if (current_pos > position)
4757 current_pos -= MIN (current_pos, end_pos) - position;
4759 selection_bound = priv->selection_bound;
4760 if (selection_bound > position)
4761 selection_bound -= MIN (selection_bound, end_pos) - position;
4763 gtk_entry_set_positions (entry, current_pos, selection_bound);
4765 /* We might have deleted the selection */
4766 gtk_entry_update_primary_selection (entry);
4768 /* Disable the password hint if one exists. */
4771 GtkEntryPasswordHint *password_hint = g_object_get_qdata (G_OBJECT (entry),
4772 quark_password_hint);
4775 if (password_hint->source_id)
4776 g_source_remove (password_hint->source_id);
4777 password_hint->source_id = 0;
4778 password_hint->position = -1;
4784 buffer_notify_text (GtkEntryBuffer *buffer,
4788 gtk_entry_recompute (entry);
4789 emit_changed (entry);
4790 g_object_notify (G_OBJECT (entry), "text");
4794 buffer_notify_length (GtkEntryBuffer *buffer,
4798 g_object_notify (G_OBJECT (entry), "text-length");
4802 buffer_notify_max_length (GtkEntryBuffer *buffer,
4806 g_object_notify (G_OBJECT (entry), "max-length");
4810 buffer_connect_signals (GtkEntry *entry)
4812 g_signal_connect (get_buffer (entry), "inserted-text", G_CALLBACK (buffer_inserted_text), entry);
4813 g_signal_connect (get_buffer (entry), "deleted-text", G_CALLBACK (buffer_deleted_text), entry);
4814 g_signal_connect (get_buffer (entry), "notify::text", G_CALLBACK (buffer_notify_text), entry);
4815 g_signal_connect (get_buffer (entry), "notify::length", G_CALLBACK (buffer_notify_length), entry);
4816 g_signal_connect (get_buffer (entry), "notify::max-length", G_CALLBACK (buffer_notify_max_length), entry);
4820 buffer_disconnect_signals (GtkEntry *entry)
4822 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_inserted_text, entry);
4823 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_deleted_text, entry);
4824 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_text, entry);
4825 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_length, entry);
4826 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_max_length, entry);
4829 /* Compute the X position for an offset that corresponds to the "more important
4830 * cursor position for that offset. We use this when trying to guess to which
4831 * end of the selection we should go to when the user hits the left or
4835 get_better_cursor_x (GtkEntry *entry,
4838 GtkEntryPrivate *priv = entry->priv;
4839 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
4840 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
4841 gboolean split_cursor;
4843 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
4844 const gchar *text = pango_layout_get_text (layout);
4845 gint index = g_utf8_offset_to_pointer (text, offset) - text;
4847 PangoRectangle strong_pos, weak_pos;
4849 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
4850 "gtk-split-cursor", &split_cursor,
4853 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
4856 return strong_pos.x / PANGO_SCALE;
4858 return (keymap_direction == priv->resolved_dir) ? strong_pos.x / PANGO_SCALE : weak_pos.x / PANGO_SCALE;
4862 gtk_entry_move_cursor (GtkEntry *entry,
4863 GtkMovementStep step,
4865 gboolean extend_selection)
4867 GtkEntryPrivate *priv = entry->priv;
4868 gint new_pos = priv->current_pos;
4870 _gtk_entry_reset_im_context (entry);
4872 if (priv->current_pos != priv->selection_bound && !extend_selection)
4874 /* If we have a current selection and aren't extending it, move to the
4875 * start/or end of the selection as appropriate
4879 case GTK_MOVEMENT_VISUAL_POSITIONS:
4881 gint current_x = get_better_cursor_x (entry, priv->current_pos);
4882 gint bound_x = get_better_cursor_x (entry, priv->selection_bound);
4885 new_pos = current_x < bound_x ? priv->current_pos : priv->selection_bound;
4887 new_pos = current_x > bound_x ? priv->current_pos : priv->selection_bound;
4890 case GTK_MOVEMENT_LOGICAL_POSITIONS:
4891 case GTK_MOVEMENT_WORDS:
4893 new_pos = MIN (priv->current_pos, priv->selection_bound);
4895 new_pos = MAX (priv->current_pos, priv->selection_bound);
4897 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
4898 case GTK_MOVEMENT_PARAGRAPH_ENDS:
4899 case GTK_MOVEMENT_BUFFER_ENDS:
4900 new_pos = count < 0 ? 0 : gtk_entry_buffer_get_length (get_buffer (entry));
4902 case GTK_MOVEMENT_DISPLAY_LINES:
4903 case GTK_MOVEMENT_PARAGRAPHS:
4904 case GTK_MOVEMENT_PAGES:
4905 case GTK_MOVEMENT_HORIZONTAL_PAGES:
4913 case GTK_MOVEMENT_LOGICAL_POSITIONS:
4914 new_pos = gtk_entry_move_logically (entry, new_pos, count);
4916 case GTK_MOVEMENT_VISUAL_POSITIONS:
4917 new_pos = gtk_entry_move_visually (entry, new_pos, count);
4918 if (priv->current_pos == new_pos)
4920 if (!extend_selection)
4922 if (!gtk_widget_keynav_failed (GTK_WIDGET (entry),
4924 GTK_DIR_RIGHT : GTK_DIR_LEFT))
4926 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (entry));
4929 gtk_widget_child_focus (toplevel,
4931 GTK_DIR_RIGHT : GTK_DIR_LEFT);
4936 gtk_widget_error_bell (GTK_WIDGET (entry));
4940 case GTK_MOVEMENT_WORDS:
4943 new_pos = gtk_entry_move_forward_word (entry, new_pos, FALSE);
4948 new_pos = gtk_entry_move_backward_word (entry, new_pos, FALSE);
4951 if (priv->current_pos == new_pos)
4952 gtk_widget_error_bell (GTK_WIDGET (entry));
4954 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
4955 case GTK_MOVEMENT_PARAGRAPH_ENDS:
4956 case GTK_MOVEMENT_BUFFER_ENDS:
4957 new_pos = count < 0 ? 0 : gtk_entry_buffer_get_length (get_buffer (entry));
4958 if (priv->current_pos == new_pos)
4959 gtk_widget_error_bell (GTK_WIDGET (entry));
4961 case GTK_MOVEMENT_DISPLAY_LINES:
4962 case GTK_MOVEMENT_PARAGRAPHS:
4963 case GTK_MOVEMENT_PAGES:
4964 case GTK_MOVEMENT_HORIZONTAL_PAGES:
4969 if (extend_selection)
4970 gtk_editable_select_region (GTK_EDITABLE (entry), priv->selection_bound, new_pos);
4972 gtk_editable_set_position (GTK_EDITABLE (entry), new_pos);
4974 gtk_entry_pend_cursor_blink (entry);
4978 gtk_entry_insert_at_cursor (GtkEntry *entry,
4981 GtkEntryPrivate *priv = entry->priv;
4982 GtkEditable *editable = GTK_EDITABLE (entry);
4983 gint pos = priv->current_pos;
4987 _gtk_entry_reset_im_context (entry);
4989 gtk_editable_insert_text (editable, str, -1, &pos);
4990 gtk_editable_set_position (editable, pos);
4995 gtk_entry_delete_from_cursor (GtkEntry *entry,
4999 GtkEntryPrivate *priv = entry->priv;
5000 GtkEditable *editable = GTK_EDITABLE (entry);
5001 gint start_pos = priv->current_pos;
5002 gint end_pos = priv->current_pos;
5003 gint old_n_bytes = gtk_entry_buffer_get_bytes (get_buffer (entry));
5005 _gtk_entry_reset_im_context (entry);
5007 if (!priv->editable)
5009 gtk_widget_error_bell (GTK_WIDGET (entry));
5013 if (priv->selection_bound != priv->current_pos)
5015 gtk_editable_delete_selection (editable);
5021 case GTK_DELETE_CHARS:
5022 end_pos = gtk_entry_move_logically (entry, priv->current_pos, count);
5023 gtk_editable_delete_text (editable, MIN (start_pos, end_pos), MAX (start_pos, end_pos));
5025 case GTK_DELETE_WORDS:
5028 /* Move to end of current word, or if not on a word, end of previous word */
5029 end_pos = gtk_entry_move_backward_word (entry, end_pos, FALSE);
5030 end_pos = gtk_entry_move_forward_word (entry, end_pos, FALSE);
5034 /* Move to beginning of current word, or if not on a word, begining of next word */
5035 start_pos = gtk_entry_move_forward_word (entry, start_pos, FALSE);
5036 start_pos = gtk_entry_move_backward_word (entry, start_pos, FALSE);
5040 case GTK_DELETE_WORD_ENDS:
5043 start_pos = gtk_entry_move_backward_word (entry, start_pos, FALSE);
5048 end_pos = gtk_entry_move_forward_word (entry, end_pos, FALSE);
5051 gtk_editable_delete_text (editable, start_pos, end_pos);
5053 case GTK_DELETE_DISPLAY_LINE_ENDS:
5054 case GTK_DELETE_PARAGRAPH_ENDS:
5056 gtk_editable_delete_text (editable, 0, priv->current_pos);
5058 gtk_editable_delete_text (editable, priv->current_pos, -1);
5060 case GTK_DELETE_DISPLAY_LINES:
5061 case GTK_DELETE_PARAGRAPHS:
5062 gtk_editable_delete_text (editable, 0, -1);
5064 case GTK_DELETE_WHITESPACE:
5065 gtk_entry_delete_whitespace (entry);
5069 if (gtk_entry_buffer_get_bytes (get_buffer (entry)) == old_n_bytes)
5070 gtk_widget_error_bell (GTK_WIDGET (entry));
5072 gtk_entry_pend_cursor_blink (entry);
5076 gtk_entry_backspace (GtkEntry *entry)
5078 GtkEntryPrivate *priv = entry->priv;
5079 GtkEditable *editable = GTK_EDITABLE (entry);
5082 _gtk_entry_reset_im_context (entry);
5084 if (!priv->editable)
5086 gtk_widget_error_bell (GTK_WIDGET (entry));
5090 if (priv->selection_bound != priv->current_pos)
5092 gtk_editable_delete_selection (editable);
5096 prev_pos = gtk_entry_move_logically (entry, priv->current_pos, -1);
5098 if (prev_pos < priv->current_pos)
5100 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
5101 PangoLogAttr *log_attrs;
5104 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
5106 /* Deleting parts of characters */
5107 if (log_attrs[priv->current_pos].backspace_deletes_character)
5109 gchar *cluster_text;
5110 gchar *normalized_text;
5113 cluster_text = gtk_entry_get_display_text (entry, prev_pos,
5115 normalized_text = g_utf8_normalize (cluster_text,
5116 strlen (cluster_text),
5118 len = g_utf8_strlen (normalized_text, -1);
5120 gtk_editable_delete_text (editable, prev_pos, priv->current_pos);
5123 gint pos = priv->current_pos;
5125 gtk_editable_insert_text (editable, normalized_text,
5126 g_utf8_offset_to_pointer (normalized_text, len - 1) - normalized_text,
5128 gtk_editable_set_position (editable, pos);
5131 g_free (normalized_text);
5132 g_free (cluster_text);
5136 gtk_editable_delete_text (editable, prev_pos, priv->current_pos);
5143 gtk_widget_error_bell (GTK_WIDGET (entry));
5146 gtk_entry_pend_cursor_blink (entry);
5150 gtk_entry_copy_clipboard (GtkEntry *entry)
5152 GtkEntryPrivate *priv = entry->priv;
5153 GtkEditable *editable = GTK_EDITABLE (entry);
5157 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5161 gtk_widget_error_bell (GTK_WIDGET (entry));
5165 str = gtk_entry_get_display_text (entry, start, end);
5166 gtk_clipboard_set_text (gtk_widget_get_clipboard (GTK_WIDGET (entry),
5167 GDK_SELECTION_CLIPBOARD),
5174 gtk_entry_cut_clipboard (GtkEntry *entry)
5176 GtkEntryPrivate *priv = entry->priv;
5177 GtkEditable *editable = GTK_EDITABLE (entry);
5182 gtk_widget_error_bell (GTK_WIDGET (entry));
5186 gtk_entry_copy_clipboard (entry);
5190 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5191 gtk_editable_delete_text (editable, start, end);
5195 gtk_widget_error_bell (GTK_WIDGET (entry));
5200 gtk_entry_paste_clipboard (GtkEntry *entry)
5202 GtkEntryPrivate *priv = entry->priv;
5205 gtk_entry_paste (entry, GDK_SELECTION_CLIPBOARD);
5207 gtk_widget_error_bell (GTK_WIDGET (entry));
5211 gtk_entry_delete_cb (GtkEntry *entry)
5213 GtkEntryPrivate *priv = entry->priv;
5214 GtkEditable *editable = GTK_EDITABLE (entry);
5219 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5220 gtk_editable_delete_text (editable, start, end);
5225 gtk_entry_toggle_overwrite (GtkEntry *entry)
5227 GtkEntryPrivate *priv = entry->priv;
5229 priv->overwrite_mode = !priv->overwrite_mode;
5230 gtk_entry_pend_cursor_blink (entry);
5231 gtk_widget_queue_draw (GTK_WIDGET (entry));
5235 gtk_entry_select_all (GtkEntry *entry)
5237 gtk_entry_select_line (entry);
5241 gtk_entry_real_activate (GtkEntry *entry)
5243 GtkEntryPrivate *priv = entry->priv;
5245 GtkWidget *default_widget, *focus_widget;
5246 GtkWidget *toplevel;
5249 widget = GTK_WIDGET (entry);
5251 if (priv->activates_default)
5253 toplevel = gtk_widget_get_toplevel (widget);
5254 if (GTK_IS_WINDOW (toplevel))
5256 window = GTK_WINDOW (toplevel);
5260 default_widget = gtk_window_get_default_widget (window);
5261 focus_widget = gtk_window_get_focus (window);
5262 if (widget != default_widget &&
5263 !(widget == focus_widget && (!default_widget || !gtk_widget_get_sensitive (default_widget))))
5264 gtk_window_activate_default (window);
5271 keymap_direction_changed (GdkKeymap *keymap,
5274 gtk_entry_recompute (entry);
5277 /* IM Context Callbacks
5281 gtk_entry_commit_cb (GtkIMContext *context,
5285 GtkEntryPrivate *priv = entry->priv;
5288 gtk_entry_enter_text (entry, str);
5292 gtk_entry_preedit_changed_cb (GtkIMContext *context,
5295 GtkEntryPrivate *priv = entry->priv;
5299 gchar *preedit_string;
5302 gtk_im_context_get_preedit_string (priv->im_context,
5303 &preedit_string, NULL,
5305 g_signal_emit (entry, signals[PREEDIT_CHANGED], 0, preedit_string);
5306 priv->preedit_length = strlen (preedit_string);
5307 cursor_pos = CLAMP (cursor_pos, 0, g_utf8_strlen (preedit_string, -1));
5308 priv->preedit_cursor = cursor_pos;
5309 g_free (preedit_string);
5311 gtk_entry_recompute (entry);
5316 gtk_entry_retrieve_surrounding_cb (GtkIMContext *context,
5319 GtkEntryPrivate *priv = entry->priv;
5322 /* XXXX ??? does this even make sense when text is not visible? Should we return FALSE? */
5323 text = gtk_entry_get_display_text (entry, 0, -1);
5324 gtk_im_context_set_surrounding (context, text, strlen (text), /* Length in bytes */
5325 g_utf8_offset_to_pointer (text, priv->current_pos) - text);
5332 gtk_entry_delete_surrounding_cb (GtkIMContext *slave,
5337 GtkEntryPrivate *priv = entry->priv;
5340 gtk_editable_delete_text (GTK_EDITABLE (entry),
5341 priv->current_pos + offset,
5342 priv->current_pos + offset + n_chars);
5347 /* Internal functions
5350 /* Used for im_commit_cb and inserting Unicode chars */
5352 gtk_entry_enter_text (GtkEntry *entry,
5355 GtkEntryPrivate *priv = entry->priv;
5356 GtkEditable *editable = GTK_EDITABLE (entry);
5358 gboolean old_need_im_reset;
5360 old_need_im_reset = priv->need_im_reset;
5361 priv->need_im_reset = FALSE;
5363 if (gtk_editable_get_selection_bounds (editable, NULL, NULL))
5364 gtk_editable_delete_selection (editable);
5367 if (priv->overwrite_mode)
5368 gtk_entry_delete_from_cursor (entry, GTK_DELETE_CHARS, 1);
5371 tmp_pos = priv->current_pos;
5372 gtk_editable_insert_text (editable, str, strlen (str), &tmp_pos);
5373 gtk_editable_set_position (editable, tmp_pos);
5375 priv->need_im_reset = old_need_im_reset;
5378 /* All changes to priv->current_pos and priv->selection_bound
5379 * should go through this function.
5382 gtk_entry_set_positions (GtkEntry *entry,
5384 gint selection_bound)
5386 GtkEntryPrivate *priv = entry->priv;
5387 gboolean changed = FALSE;
5389 g_object_freeze_notify (G_OBJECT (entry));
5391 if (current_pos != -1 &&
5392 priv->current_pos != current_pos)
5394 priv->current_pos = current_pos;
5397 g_object_notify (G_OBJECT (entry), "cursor-position");
5400 if (selection_bound != -1 &&
5401 priv->selection_bound != selection_bound)
5403 priv->selection_bound = selection_bound;
5406 g_object_notify (G_OBJECT (entry), "selection-bound");
5409 g_object_thaw_notify (G_OBJECT (entry));
5413 gtk_entry_move_adjustments (entry);
5414 gtk_entry_recompute (entry);
5419 gtk_entry_reset_layout (GtkEntry *entry)
5421 GtkEntryPrivate *priv = entry->priv;
5423 if (priv->cached_layout)
5425 g_object_unref (priv->cached_layout);
5426 priv->cached_layout = NULL;
5431 update_im_cursor_location (GtkEntry *entry)
5433 GtkEntryPrivate *priv = entry->priv;
5436 gint strong_xoffset;
5437 gint area_width, area_height;
5439 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
5440 gtk_entry_get_text_area_size (entry, NULL, NULL, &area_width, &area_height);
5442 strong_xoffset = strong_x - priv->scroll_offset;
5443 if (strong_xoffset < 0)
5447 else if (strong_xoffset > area_width)
5449 strong_xoffset = area_width;
5451 area.x = strong_xoffset;
5454 area.height = area_height;
5456 gtk_im_context_set_cursor_location (priv->im_context, &area);
5460 recompute_idle_func (gpointer data)
5462 GtkEntry *entry = GTK_ENTRY (data);
5463 GtkEntryPrivate *priv = entry->priv;
5465 priv->recompute_idle = 0;
5467 if (gtk_widget_has_screen (GTK_WIDGET (entry)))
5469 gtk_entry_adjust_scroll (entry);
5470 gtk_widget_queue_draw (GTK_WIDGET (entry));
5472 update_im_cursor_location (entry);
5479 gtk_entry_recompute (GtkEntry *entry)
5481 GtkEntryPrivate *priv = entry->priv;
5483 gtk_entry_reset_layout (entry);
5484 gtk_entry_check_cursor_blink (entry);
5486 if (!priv->recompute_idle)
5488 priv->recompute_idle = gdk_threads_add_idle_full (G_PRIORITY_HIGH_IDLE + 15, /* between resize and redraw */
5489 recompute_idle_func, entry, NULL);
5494 gtk_entry_get_placeholder_text_color (GtkEntry *entry,
5497 GtkWidget *widget = GTK_WIDGET (entry);
5498 GtkStyleContext *context;
5499 GdkRGBA fg = { 0.5, 0.5, 0.5 };
5501 context = gtk_widget_get_style_context (widget);
5502 gtk_style_context_lookup_color (context, "placeholder_text_color", &fg);
5504 color->red = CLAMP (fg.red * 65535. + 0.5, 0, 65535);
5505 color->green = CLAMP (fg.green * 65535. + 0.5, 0, 65535);
5506 color->blue = CLAMP (fg.blue * 65535. + 0.5, 0, 65535);
5509 static inline gboolean
5510 show_placeholder_text (GtkEntry *entry)
5512 GtkEntryPrivate *priv = entry->priv;
5514 if (!gtk_widget_has_focus (GTK_WIDGET (entry)) &&
5515 gtk_entry_buffer_get_bytes (get_buffer (entry)) == 0 &&
5516 priv->placeholder_text != NULL)
5522 static PangoLayout *
5523 gtk_entry_create_layout (GtkEntry *entry,
5524 gboolean include_preedit)
5526 GtkEntryPrivate *priv = entry->priv;
5527 GtkWidget *widget = GTK_WIDGET (entry);
5528 PangoLayout *layout = gtk_widget_create_pango_layout (widget, NULL);
5529 PangoAttrList *tmp_attrs = pango_attr_list_new ();
5530 gboolean placeholder_layout = show_placeholder_text (entry);
5532 gchar *preedit_string = NULL;
5533 gint preedit_length = 0;
5534 PangoAttrList *preedit_attrs = NULL;
5539 pango_layout_set_single_paragraph_mode (layout, TRUE);
5541 display = placeholder_layout ? g_strdup (priv->placeholder_text) : gtk_entry_get_display_text (entry, 0, -1);
5542 n_bytes = strlen (display);
5544 if (!placeholder_layout && include_preedit)
5546 gtk_im_context_get_preedit_string (priv->im_context,
5547 &preedit_string, &preedit_attrs, NULL);
5548 preedit_length = priv->preedit_length;
5550 else if (placeholder_layout)
5553 PangoAttribute *attr;
5555 gtk_entry_get_placeholder_text_color (entry, &color);
5556 attr = pango_attr_foreground_new (color.red, color.green, color.blue);
5557 attr->start_index = 0;
5558 attr->end_index = G_MAXINT;
5559 pango_attr_list_insert (tmp_attrs, attr);
5564 GString *tmp_string = g_string_new (display);
5565 gint cursor_index = g_utf8_offset_to_pointer (display, priv->current_pos) - display;
5567 g_string_insert (tmp_string, cursor_index, preedit_string);
5569 pango_layout_set_text (layout, tmp_string->str, tmp_string->len);
5571 pango_attr_list_splice (tmp_attrs, preedit_attrs,
5572 cursor_index, preedit_length);
5574 g_string_free (tmp_string, TRUE);
5578 PangoDirection pango_dir;
5580 if (gtk_entry_get_display_mode (entry) == DISPLAY_NORMAL)
5581 pango_dir = pango_find_base_dir (display, n_bytes);
5583 pango_dir = PANGO_DIRECTION_NEUTRAL;
5585 if (pango_dir == PANGO_DIRECTION_NEUTRAL)
5587 if (gtk_widget_has_focus (widget))
5589 GdkDisplay *display = gtk_widget_get_display (widget);
5590 GdkKeymap *keymap = gdk_keymap_get_for_display (display);
5591 if (gdk_keymap_get_direction (keymap) == PANGO_DIRECTION_RTL)
5592 pango_dir = PANGO_DIRECTION_RTL;
5594 pango_dir = PANGO_DIRECTION_LTR;
5598 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
5599 pango_dir = PANGO_DIRECTION_RTL;
5601 pango_dir = PANGO_DIRECTION_LTR;
5605 pango_context_set_base_dir (gtk_widget_get_pango_context (widget),
5608 priv->resolved_dir = pango_dir;
5610 pango_layout_set_text (layout, display, n_bytes);
5613 pango_layout_set_attributes (layout, tmp_attrs);
5615 g_free (preedit_string);
5619 pango_attr_list_unref (preedit_attrs);
5621 pango_attr_list_unref (tmp_attrs);
5626 static PangoLayout *
5627 gtk_entry_ensure_layout (GtkEntry *entry,
5628 gboolean include_preedit)
5630 GtkEntryPrivate *priv = entry->priv;
5632 if (priv->preedit_length > 0 &&
5633 !include_preedit != !priv->cache_includes_preedit)
5634 gtk_entry_reset_layout (entry);
5636 if (!priv->cached_layout)
5638 priv->cached_layout = gtk_entry_create_layout (entry, include_preedit);
5639 priv->cache_includes_preedit = include_preedit;
5642 return priv->cached_layout;
5646 get_layout_position (GtkEntry *entry,
5650 GtkEntryPrivate *priv = entry->priv;
5651 PangoLayout *layout;
5652 PangoRectangle logical_rect;
5653 gint area_width, area_height;
5654 GtkBorder inner_border;
5656 PangoLayoutLine *line;
5658 layout = gtk_entry_ensure_layout (entry, TRUE);
5660 gtk_entry_get_text_area_size (entry, NULL, NULL, &area_width, &area_height);
5661 _gtk_entry_effective_inner_border (entry, &inner_border);
5663 area_height = PANGO_SCALE * (area_height - inner_border.top - inner_border.bottom);
5665 line = pango_layout_get_lines_readonly (layout)->data;
5666 pango_layout_line_get_extents (line, NULL, &logical_rect);
5668 /* Align primarily for locale's ascent/descent */
5669 y_pos = ((area_height - priv->ascent - priv->descent) / 2 +
5670 priv->ascent + logical_rect.y);
5672 /* Now see if we need to adjust to fit in actual drawn string */
5673 if (logical_rect.height > area_height)
5674 y_pos = (area_height - logical_rect.height) / 2;
5677 else if (y_pos + logical_rect.height > area_height)
5678 y_pos = area_height - logical_rect.height;
5680 y_pos = inner_border.top + y_pos / PANGO_SCALE;
5683 *x = inner_border.left - priv->scroll_offset;
5690 draw_text_with_color (GtkEntry *entry,
5692 GdkRGBA *default_color)
5694 GtkEntryPrivate *priv = entry->priv;
5695 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
5698 gint start_pos, end_pos;
5700 widget = GTK_WIDGET (entry);
5704 get_layout_position (entry, &x, &y);
5706 cairo_move_to (cr, x, y);
5707 gdk_cairo_set_source_rgba (cr, default_color);
5708 pango_cairo_show_layout (cr, layout);
5710 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start_pos, &end_pos))
5714 PangoRectangle logical_rect;
5715 GdkRGBA selection_color, text_color;
5716 GtkBorder inner_border;
5717 GtkStyleContext *context;
5718 GtkStateFlags state;
5720 context = gtk_widget_get_style_context (widget);
5721 pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
5722 gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
5724 state = GTK_STATE_FLAG_SELECTED;
5726 if (gtk_widget_has_focus (widget))
5727 state |= GTK_STATE_FLAG_FOCUSED;
5729 gtk_style_context_get_background_color (context, state, &selection_color);
5730 gtk_style_context_get_color (context, state, &text_color);
5732 _gtk_entry_effective_inner_border (entry, &inner_border);
5734 for (i = 0; i < n_ranges; ++i)
5735 cairo_rectangle (cr,
5736 inner_border.left - priv->scroll_offset + ranges[2 * i],
5739 logical_rect.height);
5743 gdk_cairo_set_source_rgba (cr, &selection_color);
5746 cairo_move_to (cr, x, y);
5747 gdk_cairo_set_source_rgba (cr, &text_color);
5748 pango_cairo_show_layout (cr, layout);
5756 gtk_entry_draw_text (GtkEntry *entry,
5759 GtkEntryPrivate *priv = entry->priv;
5760 GtkWidget *widget = GTK_WIDGET (entry);
5761 GtkStateFlags state = 0;
5762 GdkRGBA text_color, bar_text_color;
5763 GtkStyleContext *context;
5765 gint progress_x, progress_y, progress_width, progress_height;
5766 gint clip_width, clip_height;
5768 /* Nothing to display at all */
5769 if (gtk_entry_get_display_mode (entry) == DISPLAY_BLANK)
5772 state = gtk_widget_get_state_flags (widget);
5773 context = gtk_widget_get_style_context (widget);
5775 gtk_style_context_get_color (context, state, &text_color);
5777 /* Get foreground color for progressbars */
5778 gtk_style_context_save (context);
5779 gtk_style_context_add_class (context, GTK_STYLE_CLASS_PROGRESSBAR);
5780 gtk_style_context_get_color (context, state, &bar_text_color);
5781 gtk_style_context_restore (context);
5783 get_progress_area (widget,
5784 &progress_x, &progress_y,
5785 &progress_width, &progress_height);
5789 clip_width = gdk_window_get_width (priv->text_area);
5790 clip_height = gdk_window_get_height (priv->text_area);
5791 cairo_rectangle (cr, 0, 0, clip_width, clip_height);
5794 /* If the color is the same, or the progress area has a zero
5795 * size, then we only need to draw once. */
5796 if (gdk_rgba_equal (&text_color, &bar_text_color) ||
5797 ((progress_width == 0) || (progress_height == 0)))
5799 draw_text_with_color (entry, cr, &text_color);
5803 int frame_x, frame_y, area_x, area_y;
5805 width = gdk_window_get_width (priv->text_area);
5806 height = gdk_window_get_height (priv->text_area);
5810 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
5811 cairo_rectangle (cr, 0, 0, width, height);
5813 /* progres area is frame-relative, we need it text-area window
5815 get_frame_size (entry, TRUE, &frame_x, &frame_y, NULL, NULL);
5816 gdk_window_get_position (priv->text_area, &area_x, &area_y);
5817 progress_x += frame_x - area_x;
5818 progress_y += frame_y - area_y;
5820 cairo_rectangle (cr, progress_x, progress_y,
5821 progress_width, progress_height);
5823 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_WINDING);
5825 draw_text_with_color (entry, cr, &text_color);
5830 cairo_rectangle (cr, progress_x, progress_y,
5831 progress_width, progress_height);
5834 draw_text_with_color (entry, cr, &bar_text_color);
5843 draw_insertion_cursor (GtkEntry *entry,
5845 GdkRectangle *cursor_location,
5846 gboolean is_primary,
5847 PangoDirection direction,
5848 gboolean draw_arrow)
5850 GtkWidget *widget = GTK_WIDGET (entry);
5851 GtkTextDirection text_dir;
5853 if (direction == PANGO_DIRECTION_LTR)
5854 text_dir = GTK_TEXT_DIR_LTR;
5856 text_dir = GTK_TEXT_DIR_RTL;
5858 gtk_draw_insertion_cursor (widget, cr,
5860 is_primary, text_dir, draw_arrow);
5864 gtk_entry_draw_cursor (GtkEntry *entry,
5868 GtkEntryPrivate *priv = entry->priv;
5869 GtkWidget *widget = GTK_WIDGET (entry);
5870 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
5871 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
5872 GdkRectangle cursor_location;
5873 gboolean split_cursor;
5874 PangoRectangle cursor_rect;
5875 GtkBorder inner_border;
5877 gint text_area_height;
5880 gboolean block_at_line_end;
5881 PangoLayout *layout;
5884 _gtk_entry_effective_inner_border (entry, &inner_border);
5886 xoffset = inner_border.left - priv->scroll_offset;
5888 text_area_height = gdk_window_get_height (priv->text_area);
5890 layout = gtk_entry_ensure_layout (entry, TRUE);
5891 text = pango_layout_get_text (layout);
5892 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos + priv->preedit_cursor) - text;
5893 if (!priv->overwrite_mode)
5896 block = _gtk_text_util_get_block_cursor_location (layout,
5897 cursor_index, &cursor_rect, &block_at_line_end);
5901 gint strong_x, weak_x;
5902 PangoDirection dir1 = PANGO_DIRECTION_NEUTRAL;
5903 PangoDirection dir2 = PANGO_DIRECTION_NEUTRAL;
5907 gtk_entry_get_cursor_locations (entry, type, &strong_x, &weak_x);
5909 g_object_get (gtk_widget_get_settings (widget),
5910 "gtk-split-cursor", &split_cursor,
5913 dir1 = priv->resolved_dir;
5919 if (weak_x != strong_x)
5921 dir2 = (priv->resolved_dir == PANGO_DIRECTION_LTR) ? PANGO_DIRECTION_RTL : PANGO_DIRECTION_LTR;
5927 if (keymap_direction == priv->resolved_dir)
5933 cursor_location.x = xoffset + x1;
5934 cursor_location.y = inner_border.top;
5935 cursor_location.width = 0;
5936 cursor_location.height = text_area_height - inner_border.top - inner_border.bottom;
5938 draw_insertion_cursor (entry, cr,
5939 &cursor_location, TRUE, dir1,
5940 dir2 != PANGO_DIRECTION_NEUTRAL);
5942 if (dir2 != PANGO_DIRECTION_NEUTRAL)
5944 cursor_location.x = xoffset + x2;
5945 draw_insertion_cursor (entry, cr,
5946 &cursor_location, FALSE, dir2,
5950 else /* overwrite_mode */
5952 GtkStyleContext *context;
5953 GdkRGBA cursor_color;
5959 get_layout_position (entry, &x, &y);
5961 rect.x = PANGO_PIXELS (cursor_rect.x) + x;
5962 rect.y = PANGO_PIXELS (cursor_rect.y) + y;
5963 rect.width = PANGO_PIXELS (cursor_rect.width);
5964 rect.height = PANGO_PIXELS (cursor_rect.height);
5966 context = gtk_widget_get_style_context (widget);
5968 _gtk_style_context_get_cursor_color (context, &cursor_color, NULL);
5969 gdk_cairo_set_source_rgba (cr, &cursor_color);
5970 gdk_cairo_rectangle (cr, &rect);
5973 if (!block_at_line_end)
5975 GtkStateFlags state;
5978 state = gtk_widget_get_state_flags (widget);
5979 gtk_style_context_get_background_color (context, state, &color);
5981 gdk_cairo_rectangle (cr, &rect);
5983 cairo_move_to (cr, x, y);
5984 gdk_cairo_set_source_rgba (cr, &color);
5985 pango_cairo_show_layout (cr, layout);
5993 _gtk_entry_reset_im_context (GtkEntry *entry)
5995 GtkEntryPrivate *priv = entry->priv;
5997 if (priv->need_im_reset)
5999 priv->need_im_reset = FALSE;
6000 gtk_im_context_reset (priv->im_context);
6005 * gtk_entry_reset_im_context:
6006 * @entry: a #GtkEntry
6008 * Reset the input method context of the entry if needed.
6010 * This can be necessary in the case where modifying the buffer
6011 * would confuse on-going input method behavior.
6016 gtk_entry_reset_im_context (GtkEntry *entry)
6018 g_return_if_fail (GTK_IS_ENTRY (entry));
6020 _gtk_entry_reset_im_context (entry);
6024 * gtk_entry_im_context_filter_keypress:
6025 * @entry: a #GtkEntry
6026 * @event: (type Gdk.EventKey): the key event
6028 * Allow the #GtkEntry input method to internally handle key press
6029 * and release events. If this function returns %TRUE, then no further
6030 * processing should be done for this key event. See
6031 * gtk_im_context_filter_keypress().
6033 * Note that you are expected to call this function from your handler
6034 * when overriding key event handling. This is needed in the case when
6035 * you need to insert your own key handling between the input method
6036 * and the default key event handling of the #GtkEntry.
6037 * See gtk_text_view_reset_im_context() for an example of use.
6039 * Return value: %TRUE if the input method handled the key event.
6044 gtk_entry_im_context_filter_keypress (GtkEntry *entry,
6047 GtkEntryPrivate *priv;
6049 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
6053 return gtk_im_context_filter_keypress (priv->im_context, event);
6057 _gtk_entry_get_im_context (GtkEntry *entry)
6059 return entry->priv->im_context;
6063 gtk_entry_find_position (GtkEntry *entry,
6066 GtkEntryPrivate *priv = entry->priv;
6067 PangoLayout *layout;
6068 PangoLayoutLine *line;
6075 layout = gtk_entry_ensure_layout (entry, TRUE);
6076 text = pango_layout_get_text (layout);
6077 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos) - text;
6079 line = pango_layout_get_lines_readonly (layout)->data;
6080 pango_layout_line_x_to_index (line, x * PANGO_SCALE, &index, &trailing);
6082 if (index >= cursor_index && priv->preedit_length)
6084 if (index >= cursor_index + priv->preedit_length)
6085 index -= priv->preedit_length;
6088 index = cursor_index;
6093 pos = g_utf8_pointer_to_offset (text, text + index);
6100 gtk_entry_get_cursor_locations (GtkEntry *entry,
6105 GtkEntryPrivate *priv = entry->priv;
6106 DisplayMode mode = gtk_entry_get_display_mode (entry);
6108 /* Nothing to display at all, so no cursor is relevant */
6109 if (mode == DISPLAY_BLANK)
6119 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
6120 const gchar *text = pango_layout_get_text (layout);
6121 PangoRectangle strong_pos, weak_pos;
6124 if (type == CURSOR_STANDARD)
6126 index = g_utf8_offset_to_pointer (text, priv->current_pos + priv->preedit_cursor) - text;
6128 else /* type == CURSOR_DND */
6130 index = g_utf8_offset_to_pointer (text, priv->dnd_position) - text;
6132 if (priv->dnd_position > priv->current_pos)
6134 if (mode == DISPLAY_NORMAL)
6135 index += priv->preedit_length;
6138 gint preedit_len_chars = g_utf8_strlen (text, -1) - gtk_entry_buffer_get_length (get_buffer (entry));
6139 index += preedit_len_chars * g_unichar_to_utf8 (priv->invisible_char, NULL);
6144 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
6147 *strong_x = strong_pos.x / PANGO_SCALE;
6150 *weak_x = weak_pos.x / PANGO_SCALE;
6155 gtk_entry_adjust_scroll (GtkEntry *entry)
6157 GtkEntryPrivate *priv = entry->priv;
6158 gint min_offset, max_offset;
6159 gint text_area_width, text_width;
6160 GtkBorder inner_border;
6161 gint strong_x, weak_x;
6162 gint strong_xoffset, weak_xoffset;
6164 PangoLayout *layout;
6165 PangoLayoutLine *line;
6166 PangoRectangle logical_rect;
6168 if (!gtk_widget_get_realized (GTK_WIDGET (entry)))
6171 _gtk_entry_effective_inner_border (entry, &inner_border);
6173 text_area_width = gdk_window_get_width (priv->text_area);
6174 text_area_width -= inner_border.left + inner_border.right;
6175 if (text_area_width < 0)
6176 text_area_width = 0;
6178 layout = gtk_entry_ensure_layout (entry, TRUE);
6179 line = pango_layout_get_lines_readonly (layout)->data;
6181 pango_layout_line_get_extents (line, NULL, &logical_rect);
6183 /* Display as much text as we can */
6185 if (priv->resolved_dir == PANGO_DIRECTION_LTR)
6186 xalign = priv->xalign;
6188 xalign = 1.0 - priv->xalign;
6190 text_width = PANGO_PIXELS(logical_rect.width);
6192 if (text_width > text_area_width)
6195 max_offset = text_width - text_area_width;
6199 min_offset = (text_width - text_area_width) * xalign;
6200 max_offset = min_offset;
6203 priv->scroll_offset = CLAMP (priv->scroll_offset, min_offset, max_offset);
6205 /* And make sure cursors are on screen. Note that the cursor is
6206 * actually drawn one pixel into the INNER_BORDER space on
6207 * the right, when the scroll is at the utmost right. This
6208 * looks better to to me than confining the cursor inside the
6209 * border entirely, though it means that the cursor gets one
6210 * pixel closer to the edge of the widget on the right than
6211 * on the left. This might need changing if one changed
6212 * INNER_BORDER from 2 to 1, as one would do on a
6213 * small-screen-real-estate display.
6215 * We always make sure that the strong cursor is on screen, and
6216 * put the weak cursor on screen if possible.
6219 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, &weak_x);
6221 strong_xoffset = strong_x - priv->scroll_offset;
6223 if (strong_xoffset < 0)
6225 priv->scroll_offset += strong_xoffset;
6228 else if (strong_xoffset > text_area_width)
6230 priv->scroll_offset += strong_xoffset - text_area_width;
6231 strong_xoffset = text_area_width;
6234 weak_xoffset = weak_x - priv->scroll_offset;
6236 if (weak_xoffset < 0 && strong_xoffset - weak_xoffset <= text_area_width)
6238 priv->scroll_offset += weak_xoffset;
6240 else if (weak_xoffset > text_area_width &&
6241 strong_xoffset - (weak_xoffset - text_area_width) >= 0)
6243 priv->scroll_offset += weak_xoffset - text_area_width;
6246 g_object_notify (G_OBJECT (entry), "scroll-offset");
6250 gtk_entry_move_adjustments (GtkEntry *entry)
6252 GtkWidget *widget = GTK_WIDGET (entry);
6253 GtkAllocation allocation;
6254 GtkAdjustment *adjustment;
6255 PangoContext *context;
6256 PangoFontMetrics *metrics;
6257 GtkStyleContext *style_context;
6258 GtkStateFlags state;
6259 gint x, layout_x, border_x, border_y;
6262 adjustment = g_object_get_qdata (G_OBJECT (entry), quark_cursor_hadjustment);
6266 gtk_widget_get_allocation (widget, &allocation);
6268 /* Cursor position, layout offset, border width, and widget allocation */
6269 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &x, NULL);
6270 get_layout_position (entry, &layout_x, NULL);
6271 _gtk_entry_get_borders (entry, &border_x, &border_y);
6272 x += allocation.x + layout_x + border_x;
6274 /* Approximate width of a char, so user can see what is ahead/behind */
6275 context = gtk_widget_get_pango_context (widget);
6276 style_context = gtk_widget_get_style_context (widget);
6277 state = gtk_widget_get_state_flags (widget);
6279 metrics = pango_context_get_metrics (context,
6280 gtk_style_context_get_font (style_context, state),
6281 pango_context_get_language (context));
6282 char_width = pango_font_metrics_get_approximate_char_width (metrics) / PANGO_SCALE;
6285 gtk_adjustment_clamp_page (adjustment,
6286 x - (char_width + 1), /* one char + one pixel before */
6287 x + (char_width + 2)); /* one char + cursor + one pixel after */
6291 gtk_entry_move_visually (GtkEntry *entry,
6295 GtkEntryPrivate *priv = entry->priv;
6297 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6300 text = pango_layout_get_text (layout);
6302 index = g_utf8_offset_to_pointer (text, start) - text;
6306 int new_index, new_trailing;
6307 gboolean split_cursor;
6310 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
6311 "gtk-split-cursor", &split_cursor,
6318 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
6319 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
6321 strong = keymap_direction == priv->resolved_dir;
6326 pango_layout_move_cursor_visually (layout, strong, index, 0, 1, &new_index, &new_trailing);
6331 pango_layout_move_cursor_visually (layout, strong, index, 0, -1, &new_index, &new_trailing);
6337 else if (new_index != G_MAXINT)
6340 while (new_trailing--)
6341 index = g_utf8_next_char (text + index) - text;
6344 return g_utf8_pointer_to_offset (text, text + index);
6348 gtk_entry_move_logically (GtkEntry *entry,
6352 gint new_pos = start;
6355 length = gtk_entry_buffer_get_length (get_buffer (entry));
6357 /* Prevent any leak of information */
6358 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6360 new_pos = CLAMP (start + count, 0, length);
6364 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6365 PangoLogAttr *log_attrs;
6368 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6370 while (count > 0 && new_pos < length)
6374 while (new_pos < length && !log_attrs[new_pos].is_cursor_position);
6378 while (count < 0 && new_pos > 0)
6382 while (new_pos > 0 && !log_attrs[new_pos].is_cursor_position);
6394 gtk_entry_move_forward_word (GtkEntry *entry,
6396 gboolean allow_whitespace)
6398 gint new_pos = start;
6401 length = gtk_entry_buffer_get_length (get_buffer (entry));
6403 /* Prevent any leak of information */
6404 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6408 else if (new_pos < length)
6410 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6411 PangoLogAttr *log_attrs;
6414 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6416 /* Find the next word boundary */
6418 while (new_pos < n_attrs - 1 && !(log_attrs[new_pos].is_word_end ||
6419 (log_attrs[new_pos].is_word_start && allow_whitespace)))
6430 gtk_entry_move_backward_word (GtkEntry *entry,
6432 gboolean allow_whitespace)
6434 gint new_pos = start;
6436 /* Prevent any leak of information */
6437 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6443 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6444 PangoLogAttr *log_attrs;
6447 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6449 new_pos = start - 1;
6451 /* Find the previous word boundary */
6452 while (new_pos > 0 && !(log_attrs[new_pos].is_word_start ||
6453 (log_attrs[new_pos].is_word_end && allow_whitespace)))
6463 gtk_entry_delete_whitespace (GtkEntry *entry)
6465 GtkEntryPrivate *priv = entry->priv;
6466 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6467 PangoLogAttr *log_attrs;
6471 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6473 start = end = priv->current_pos;
6475 while (start > 0 && log_attrs[start-1].is_white)
6478 while (end < n_attrs && log_attrs[end].is_white)
6484 gtk_editable_delete_text (GTK_EDITABLE (entry), start, end);
6489 gtk_entry_select_word (GtkEntry *entry)
6491 GtkEntryPrivate *priv = entry->priv;
6492 gint start_pos = gtk_entry_move_backward_word (entry, priv->current_pos, TRUE);
6493 gint end_pos = gtk_entry_move_forward_word (entry, priv->current_pos, TRUE);
6495 gtk_editable_select_region (GTK_EDITABLE (entry), start_pos, end_pos);
6499 gtk_entry_select_line (GtkEntry *entry)
6501 gtk_editable_select_region (GTK_EDITABLE (entry), 0, -1);
6505 truncate_multiline (const gchar *text)
6510 text[length] && text[length] != '\n' && text[length] != '\r';
6517 paste_received (GtkClipboard *clipboard,
6521 GtkEntry *entry = GTK_ENTRY (data);
6522 GtkEditable *editable = GTK_EDITABLE (entry);
6523 GtkEntryPrivate *priv = entry->priv;
6525 if (priv->button == 2)
6527 gint pos, start, end;
6528 pos = priv->insert_pos;
6529 gtk_editable_get_selection_bounds (editable, &start, &end);
6530 if (!((start <= pos && pos <= end) || (end <= pos && pos <= start)))
6531 gtk_editable_select_region (editable, pos, pos);
6536 gint pos, start, end;
6538 gboolean popup_completion;
6539 GtkEntryCompletion *completion;
6541 completion = gtk_entry_get_completion (entry);
6543 if (priv->truncate_multiline)
6544 length = truncate_multiline (text);
6546 /* only complete if the selection is at the end */
6547 popup_completion = (gtk_entry_buffer_get_length (get_buffer (entry)) ==
6548 MAX (priv->current_pos, priv->selection_bound));
6552 if (gtk_widget_get_mapped (completion->priv->popup_window))
6553 _gtk_entry_completion_popdown (completion);
6555 if (!popup_completion && completion->priv->changed_id > 0)
6556 g_signal_handler_block (entry, completion->priv->changed_id);
6559 begin_change (entry);
6560 g_object_freeze_notify (G_OBJECT (entry));
6561 if (gtk_editable_get_selection_bounds (editable, &start, &end))
6562 gtk_editable_delete_text (editable, start, end);
6564 pos = priv->current_pos;
6565 gtk_editable_insert_text (editable, text, length, &pos);
6566 gtk_editable_set_position (editable, pos);
6567 g_object_thaw_notify (G_OBJECT (entry));
6571 !popup_completion && completion->priv->changed_id > 0)
6572 g_signal_handler_unblock (entry, completion->priv->changed_id);
6575 g_object_unref (entry);
6579 gtk_entry_paste (GtkEntry *entry,
6582 g_object_ref (entry);
6583 gtk_clipboard_request_text (gtk_widget_get_clipboard (GTK_WIDGET (entry), selection),
6584 paste_received, entry);
6588 primary_get_cb (GtkClipboard *clipboard,
6589 GtkSelectionData *selection_data,
6593 GtkEntry *entry = GTK_ENTRY (data);
6596 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end))
6598 gchar *str = gtk_entry_get_display_text (entry, start, end);
6599 gtk_selection_data_set_text (selection_data, str, -1);
6605 primary_clear_cb (GtkClipboard *clipboard,
6608 GtkEntry *entry = GTK_ENTRY (data);
6609 GtkEntryPrivate *priv = entry->priv;
6611 gtk_editable_select_region (GTK_EDITABLE (entry), priv->current_pos, priv->current_pos);
6615 gtk_entry_update_primary_selection (GtkEntry *entry)
6617 GtkTargetList *list;
6618 GtkTargetEntry *targets;
6619 GtkClipboard *clipboard;
6623 if (!gtk_widget_get_realized (GTK_WIDGET (entry)))
6626 list = gtk_target_list_new (NULL, 0);
6627 gtk_target_list_add_text_targets (list, 0);
6629 targets = gtk_target_table_new_from_list (list, &n_targets);
6631 clipboard = gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_PRIMARY);
6633 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end))
6635 if (!gtk_clipboard_set_with_owner (clipboard, targets, n_targets,
6636 primary_get_cb, primary_clear_cb, G_OBJECT (entry)))
6637 primary_clear_cb (clipboard, entry);
6641 if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (entry))
6642 gtk_clipboard_clear (clipboard);
6645 gtk_target_table_free (targets, n_targets);
6646 gtk_target_list_unref (list);
6650 gtk_entry_clear (GtkEntry *entry,
6651 GtkEntryIconPosition icon_pos)
6653 GtkEntryPrivate *priv = entry->priv;
6654 EntryIconInfo *icon_info = priv->icons[icon_pos];
6656 if (!icon_info || icon_info->storage_type == GTK_IMAGE_EMPTY)
6659 g_object_freeze_notify (G_OBJECT (entry));
6661 /* Explicitly check, as the pointer may become invalidated
6662 * during destruction.
6664 if (GDK_IS_WINDOW (icon_info->window))
6665 gdk_window_hide (icon_info->window);
6667 if (icon_info->pixbuf)
6669 g_object_unref (icon_info->pixbuf);
6670 icon_info->pixbuf = NULL;
6673 switch (icon_info->storage_type)
6675 case GTK_IMAGE_PIXBUF:
6676 g_object_notify (G_OBJECT (entry),
6677 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-pixbuf" : "secondary-icon-pixbuf");
6680 case GTK_IMAGE_STOCK:
6681 g_free (icon_info->stock_id);
6682 icon_info->stock_id = NULL;
6683 g_object_notify (G_OBJECT (entry),
6684 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-stock" : "secondary-icon-stock");
6687 case GTK_IMAGE_ICON_NAME:
6688 g_free (icon_info->icon_name);
6689 icon_info->icon_name = NULL;
6690 g_object_notify (G_OBJECT (entry),
6691 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-name" : "secondary-icon-name");
6694 case GTK_IMAGE_GICON:
6695 if (icon_info->gicon)
6697 g_object_unref (icon_info->gicon);
6698 icon_info->gicon = NULL;
6700 g_object_notify (G_OBJECT (entry),
6701 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-gicon" : "secondary-icon-gicon");
6705 g_assert_not_reached ();
6709 icon_info->storage_type = GTK_IMAGE_EMPTY;
6710 g_object_notify (G_OBJECT (entry),
6711 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-storage-type" : "secondary-icon-storage-type");
6713 g_object_thaw_notify (G_OBJECT (entry));
6717 create_normal_pixbuf (GtkStyleContext *context,
6718 const gchar *stock_id,
6719 GtkIconSize icon_size)
6721 GtkIconSet *icon_set;
6724 gtk_style_context_save (context);
6726 /* Unset any state */
6727 gtk_style_context_set_state (context, GTK_STATE_FLAG_NORMAL);
6729 icon_set = gtk_style_context_lookup_icon_set (context, stock_id);
6730 pixbuf = gtk_icon_set_render_icon_pixbuf (icon_set, context, icon_size);
6732 gtk_style_context_restore (context);
6738 ensure_stated_icon_from_info (GtkStyleContext *context,
6741 GdkPixbuf *retval = NULL;
6742 gboolean symbolic = FALSE;
6747 gtk_icon_info_load_symbolic_for_context (info,
6756 create_normal_pixbuf (context,
6757 GTK_STOCK_MISSING_IMAGE,
6758 GTK_ICON_SIZE_MENU);
6762 GdkPixbuf *temp_pixbuf;
6763 GtkIconSource *icon_source;
6765 icon_source = gtk_icon_source_new ();
6766 gtk_icon_source_set_pixbuf (icon_source, retval);
6767 gtk_icon_source_set_state_wildcarded (icon_source, TRUE);
6769 temp_pixbuf = gtk_render_icon_pixbuf (context, icon_source, (GtkIconSize)-1);
6771 gtk_icon_source_free (icon_source);
6773 g_object_unref (retval);
6774 retval = temp_pixbuf;
6781 gtk_entry_ensure_pixbuf (GtkEntry *entry,
6782 GtkEntryIconPosition icon_pos)
6784 GtkEntryPrivate *priv = entry->priv;
6785 EntryIconInfo *icon_info = priv->icons[icon_pos];
6786 GtkStyleContext *context;
6788 GtkIconTheme *icon_theme;
6789 GtkSettings *settings;
6793 GtkStateFlags state;
6795 widget = GTK_WIDGET (entry);
6796 context = gtk_widget_get_style_context (widget);
6798 state = GTK_STATE_FLAG_NORMAL;
6800 if (!gtk_widget_is_sensitive (widget) || icon_info->insensitive)
6801 state |= GTK_STATE_FLAG_INSENSITIVE;
6802 else if (icon_info->prelight)
6803 state |= GTK_STATE_FLAG_PRELIGHT;
6805 if ((icon_info == NULL) ||
6806 ((icon_info->pixbuf != NULL) && icon_info->last_state == state))
6809 icon_info->last_state = state;
6811 gtk_style_context_save (context);
6812 gtk_style_context_set_state (context, state);
6813 gtk_style_context_add_class (context, GTK_STYLE_CLASS_IMAGE);
6815 switch (icon_info->storage_type)
6817 case GTK_IMAGE_EMPTY:
6818 case GTK_IMAGE_PIXBUF:
6820 case GTK_IMAGE_STOCK:
6821 icon_info->pixbuf = create_normal_pixbuf (context, icon_info->stock_id,
6822 GTK_ICON_SIZE_MENU);
6824 if (!icon_info->pixbuf)
6825 icon_info->pixbuf = create_normal_pixbuf (context,
6826 GTK_STOCK_MISSING_IMAGE,
6827 GTK_ICON_SIZE_MENU);
6830 case GTK_IMAGE_ICON_NAME:
6831 screen = gtk_widget_get_screen (widget);
6834 icon_theme = gtk_icon_theme_get_for_screen (screen);
6835 settings = gtk_settings_get_for_screen (screen);
6837 gtk_icon_size_lookup_for_settings (settings,
6841 info = gtk_icon_theme_lookup_icon (icon_theme,
6842 icon_info->icon_name,
6843 MIN (width, height),
6847 ensure_stated_icon_from_info (context, info);
6850 gtk_icon_info_free (info);
6854 case GTK_IMAGE_GICON:
6855 screen = gtk_widget_get_screen (widget);
6858 icon_theme = gtk_icon_theme_get_for_screen (screen);
6859 settings = gtk_settings_get_for_screen (screen);
6861 gtk_icon_size_lookup_for_settings (settings,
6865 info = gtk_icon_theme_lookup_by_gicon (icon_theme,
6867 MIN (width, height),
6868 GTK_ICON_LOOKUP_USE_BUILTIN);
6871 ensure_stated_icon_from_info (context, info);
6874 gtk_icon_info_free (info);
6879 g_assert_not_reached ();
6883 gtk_style_context_restore (context);
6885 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
6886 gdk_window_show_unraised (icon_info->window);
6896 * Creates a new entry.
6898 * Return value: a new #GtkEntry.
6901 gtk_entry_new (void)
6903 return g_object_new (GTK_TYPE_ENTRY, NULL);
6907 * gtk_entry_new_with_buffer:
6908 * @buffer: The buffer to use for the new #GtkEntry.
6910 * Creates a new entry with the specified text buffer.
6912 * Return value: a new #GtkEntry
6917 gtk_entry_new_with_buffer (GtkEntryBuffer *buffer)
6919 g_return_val_if_fail (GTK_IS_ENTRY_BUFFER (buffer), NULL);
6920 return g_object_new (GTK_TYPE_ENTRY, "buffer", buffer, NULL);
6923 static GtkEntryBuffer*
6924 get_buffer (GtkEntry *entry)
6926 GtkEntryPrivate *priv = entry->priv;
6928 if (priv->buffer == NULL)
6930 GtkEntryBuffer *buffer;
6931 buffer = gtk_entry_buffer_new (NULL, 0);
6932 gtk_entry_set_buffer (entry, buffer);
6933 g_object_unref (buffer);
6936 return priv->buffer;
6940 * gtk_entry_get_buffer:
6941 * @entry: a #GtkEntry
6943 * Get the #GtkEntryBuffer object which holds the text for
6948 * Returns: (transfer none): A #GtkEntryBuffer object.
6951 gtk_entry_get_buffer (GtkEntry *entry)
6953 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
6955 return get_buffer (entry);
6959 * gtk_entry_set_buffer:
6960 * @entry: a #GtkEntry
6961 * @buffer: a #GtkEntryBuffer
6963 * Set the #GtkEntryBuffer object which holds the text for
6969 gtk_entry_set_buffer (GtkEntry *entry,
6970 GtkEntryBuffer *buffer)
6972 GtkEntryPrivate *priv;
6975 g_return_if_fail (GTK_IS_ENTRY (entry));
6981 g_return_if_fail (GTK_IS_ENTRY_BUFFER (buffer));
6982 g_object_ref (buffer);
6987 buffer_disconnect_signals (entry);
6988 g_object_unref (priv->buffer);
6991 priv->buffer = buffer;
6994 buffer_connect_signals (entry);
6996 obj = G_OBJECT (entry);
6997 g_object_freeze_notify (obj);
6998 g_object_notify (obj, "buffer");
6999 g_object_notify (obj, "text");
7000 g_object_notify (obj, "text-length");
7001 g_object_notify (obj, "max-length");
7002 g_object_notify (obj, "visibility");
7003 g_object_notify (obj, "invisible-char");
7004 g_object_notify (obj, "invisible-char-set");
7005 g_object_thaw_notify (obj);
7007 gtk_editable_set_position (GTK_EDITABLE (entry), 0);
7008 gtk_entry_recompute (entry);
7012 * gtk_entry_get_text_area:
7013 * @entry: a #GtkEntry
7014 * @text_area: (out): Return location for the text area.
7016 * Gets the area where the entry's text is drawn. This function is
7017 * useful when drawing something to the entry in a draw callback.
7019 * If the entry is not realized, @text_area is filled with zeros.
7021 * See also gtk_entry_get_icon_area().
7026 gtk_entry_get_text_area (GtkEntry *entry,
7027 GdkRectangle *text_area)
7029 GtkEntryPrivate *priv;
7031 g_return_if_fail (GTK_IS_ENTRY (entry));
7032 g_return_if_fail (text_area != NULL);
7036 if (priv->text_area)
7038 GtkAllocation allocation;
7041 gtk_widget_get_allocation (GTK_WIDGET (entry), &allocation);
7042 gdk_window_get_position (priv->text_area, &x, &y);
7044 text_area->x = x - allocation.x;
7045 text_area->y = y - allocation.y;
7046 text_area->width = gdk_window_get_width (priv->text_area);
7047 text_area->height = gdk_window_get_height (priv->text_area);
7053 text_area->width = 0;
7054 text_area->height = 0;
7059 * gtk_entry_set_text:
7060 * @entry: a #GtkEntry
7061 * @text: the new text
7063 * Sets the text in the widget to the given
7064 * value, replacing the current contents.
7066 * See gtk_entry_buffer_set_text().
7069 gtk_entry_set_text (GtkEntry *entry,
7073 GtkEntryCompletion *completion;
7075 g_return_if_fail (GTK_IS_ENTRY (entry));
7076 g_return_if_fail (text != NULL);
7078 /* Actually setting the text will affect the cursor and selection;
7079 * if the contents don't actually change, this will look odd to the user.
7081 if (strcmp (gtk_entry_buffer_get_text (get_buffer (entry)), text) == 0)
7084 completion = gtk_entry_get_completion (entry);
7085 if (completion && completion->priv->changed_id > 0)
7086 g_signal_handler_block (entry, completion->priv->changed_id);
7088 begin_change (entry);
7089 g_object_freeze_notify (G_OBJECT (entry));
7090 gtk_editable_delete_text (GTK_EDITABLE (entry), 0, -1);
7092 gtk_editable_insert_text (GTK_EDITABLE (entry), text, strlen (text), &tmp_pos);
7093 g_object_thaw_notify (G_OBJECT (entry));
7096 if (completion && completion->priv->changed_id > 0)
7097 g_signal_handler_unblock (entry, completion->priv->changed_id);
7101 * gtk_entry_set_visibility:
7102 * @entry: a #GtkEntry
7103 * @visible: %TRUE if the contents of the entry are displayed
7106 * Sets whether the contents of the entry are visible or not.
7107 * When visibility is set to %FALSE, characters are displayed
7108 * as the invisible char, and will also appear that way when
7109 * the text in the entry widget is copied elsewhere.
7111 * By default, GTK+ picks the best invisible character available
7112 * in the current font, but it can be changed with
7113 * gtk_entry_set_invisible_char().
7116 gtk_entry_set_visibility (GtkEntry *entry,
7119 GtkEntryPrivate *priv;
7121 g_return_if_fail (GTK_IS_ENTRY (entry));
7125 visible = visible != FALSE;
7127 if (priv->visible != visible)
7129 priv->visible = visible;
7131 g_object_notify (G_OBJECT (entry), "visibility");
7132 gtk_entry_recompute (entry);
7137 * gtk_entry_get_visibility:
7138 * @entry: a #GtkEntry
7140 * Retrieves whether the text in @entry is visible. See
7141 * gtk_entry_set_visibility().
7143 * Return value: %TRUE if the text is currently visible
7146 gtk_entry_get_visibility (GtkEntry *entry)
7148 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7150 return entry->priv->visible;
7154 * gtk_entry_set_invisible_char:
7155 * @entry: a #GtkEntry
7156 * @ch: a Unicode character
7158 * Sets the character to use in place of the actual text when
7159 * gtk_entry_set_visibility() has been called to set text visibility
7160 * to %FALSE. i.e. this is the character used in "password mode" to
7161 * show the user how many characters have been typed. By default, GTK+
7162 * picks the best invisible char available in the current font. If you
7163 * set the invisible char to 0, then the user will get no feedback
7164 * at all; there will be no text on the screen as they type.
7167 gtk_entry_set_invisible_char (GtkEntry *entry,
7170 GtkEntryPrivate *priv;
7172 g_return_if_fail (GTK_IS_ENTRY (entry));
7176 if (!priv->invisible_char_set)
7178 priv->invisible_char_set = TRUE;
7179 g_object_notify (G_OBJECT (entry), "invisible-char-set");
7182 if (ch == priv->invisible_char)
7185 priv->invisible_char = ch;
7186 g_object_notify (G_OBJECT (entry), "invisible-char");
7187 gtk_entry_recompute (entry);
7191 * gtk_entry_get_invisible_char:
7192 * @entry: a #GtkEntry
7194 * Retrieves the character displayed in place of the real characters
7195 * for entries with visibility set to false. See gtk_entry_set_invisible_char().
7197 * Return value: the current invisible char, or 0, if the entry does not
7198 * show invisible text at all.
7201 gtk_entry_get_invisible_char (GtkEntry *entry)
7203 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7205 return entry->priv->invisible_char;
7209 * gtk_entry_unset_invisible_char:
7210 * @entry: a #GtkEntry
7212 * Unsets the invisible char previously set with
7213 * gtk_entry_set_invisible_char(). So that the
7214 * default invisible char is used again.
7219 gtk_entry_unset_invisible_char (GtkEntry *entry)
7221 GtkEntryPrivate *priv;
7224 g_return_if_fail (GTK_IS_ENTRY (entry));
7228 if (!priv->invisible_char_set)
7231 priv->invisible_char_set = FALSE;
7232 ch = find_invisible_char (GTK_WIDGET (entry));
7234 if (priv->invisible_char != ch)
7236 priv->invisible_char = ch;
7237 g_object_notify (G_OBJECT (entry), "invisible-char");
7240 g_object_notify (G_OBJECT (entry), "invisible-char-set");
7241 gtk_entry_recompute (entry);
7245 * gtk_entry_set_overwrite_mode:
7246 * @entry: a #GtkEntry
7247 * @overwrite: new value
7249 * Sets whether the text is overwritten when typing in the #GtkEntry.
7254 gtk_entry_set_overwrite_mode (GtkEntry *entry,
7257 GtkEntryPrivate *priv = entry->priv;
7259 g_return_if_fail (GTK_IS_ENTRY (entry));
7261 if (priv->overwrite_mode == overwrite)
7264 gtk_entry_toggle_overwrite (entry);
7266 g_object_notify (G_OBJECT (entry), "overwrite-mode");
7270 * gtk_entry_get_overwrite_mode:
7271 * @entry: a #GtkEntry
7273 * Gets the value set by gtk_entry_set_overwrite_mode().
7275 * Return value: whether the text is overwritten when typing.
7280 gtk_entry_get_overwrite_mode (GtkEntry *entry)
7282 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7284 return entry->priv->overwrite_mode;
7288 * gtk_entry_get_text:
7289 * @entry: a #GtkEntry
7291 * Retrieves the contents of the entry widget.
7292 * See also gtk_editable_get_chars().
7294 * This is equivalent to:
7296 * <informalexample><programlisting>
7297 * gtk_entry_buffer_get_text (gtk_entry_get_buffer (entry));
7298 * </programlisting></informalexample>
7300 * Return value: a pointer to the contents of the widget as a
7301 * string. This string points to internally allocated
7302 * storage in the widget and must not be freed, modified or
7306 gtk_entry_get_text (GtkEntry *entry)
7308 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7310 return gtk_entry_buffer_get_text (get_buffer (entry));
7314 * gtk_entry_set_max_length:
7315 * @entry: a #GtkEntry
7316 * @max: the maximum length of the entry, or 0 for no maximum.
7317 * (other than the maximum length of entries.) The value passed in will
7318 * be clamped to the range 0-65536.
7320 * Sets the maximum allowed length of the contents of the widget. If
7321 * the current contents are longer than the given length, then they
7322 * will be truncated to fit.
7324 * This is equivalent to:
7326 * <informalexample><programlisting>
7327 * gtk_entry_buffer_set_max_length (gtk_entry_get_buffer (entry), max);
7328 * </programlisting></informalexample>
7331 gtk_entry_set_max_length (GtkEntry *entry,
7334 g_return_if_fail (GTK_IS_ENTRY (entry));
7335 gtk_entry_buffer_set_max_length (get_buffer (entry), max);
7339 * gtk_entry_get_max_length:
7340 * @entry: a #GtkEntry
7342 * Retrieves the maximum allowed length of the text in
7343 * @entry. See gtk_entry_set_max_length().
7345 * This is equivalent to:
7347 * <informalexample><programlisting>
7348 * gtk_entry_buffer_get_max_length (gtk_entry_get_buffer (entry));
7349 * </programlisting></informalexample>
7351 * Return value: the maximum allowed number of characters
7352 * in #GtkEntry, or 0 if there is no maximum.
7355 gtk_entry_get_max_length (GtkEntry *entry)
7357 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7359 return gtk_entry_buffer_get_max_length (get_buffer (entry));
7363 * gtk_entry_get_text_length:
7364 * @entry: a #GtkEntry
7366 * Retrieves the current length of the text in
7369 * This is equivalent to:
7371 * <informalexample><programlisting>
7372 * gtk_entry_buffer_get_length (gtk_entry_get_buffer (entry));
7373 * </programlisting></informalexample>
7375 * Return value: the current number of characters
7376 * in #GtkEntry, or 0 if there are none.
7381 gtk_entry_get_text_length (GtkEntry *entry)
7383 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7385 return gtk_entry_buffer_get_length (get_buffer (entry));
7389 * gtk_entry_set_activates_default:
7390 * @entry: a #GtkEntry
7391 * @setting: %TRUE to activate window's default widget on Enter keypress
7393 * If @setting is %TRUE, pressing Enter in the @entry will activate the default
7394 * widget for the window containing the entry. This usually means that
7395 * the dialog box containing the entry will be closed, since the default
7396 * widget is usually one of the dialog buttons.
7398 * (For experts: if @setting is %TRUE, the entry calls
7399 * gtk_window_activate_default() on the window containing the entry, in
7400 * the default handler for the #GtkWidget::activate signal.)
7403 gtk_entry_set_activates_default (GtkEntry *entry,
7406 GtkEntryPrivate *priv;
7408 g_return_if_fail (GTK_IS_ENTRY (entry));
7412 setting = setting != FALSE;
7414 if (setting != priv->activates_default)
7416 priv->activates_default = setting;
7417 g_object_notify (G_OBJECT (entry), "activates-default");
7422 * gtk_entry_get_activates_default:
7423 * @entry: a #GtkEntry
7425 * Retrieves the value set by gtk_entry_set_activates_default().
7427 * Return value: %TRUE if the entry will activate the default widget
7430 gtk_entry_get_activates_default (GtkEntry *entry)
7432 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7434 return entry->priv->activates_default;
7438 * gtk_entry_set_width_chars:
7439 * @entry: a #GtkEntry
7440 * @n_chars: width in chars
7442 * Changes the size request of the entry to be about the right size
7443 * for @n_chars characters. Note that it changes the size
7444 * <emphasis>request</emphasis>, the size can still be affected by
7445 * how you pack the widget into containers. If @n_chars is -1, the
7446 * size reverts to the default entry size.
7449 gtk_entry_set_width_chars (GtkEntry *entry,
7452 GtkEntryPrivate *priv;
7454 g_return_if_fail (GTK_IS_ENTRY (entry));
7458 if (priv->width_chars != n_chars)
7460 priv->width_chars = n_chars;
7461 g_object_notify (G_OBJECT (entry), "width-chars");
7462 gtk_widget_queue_resize (GTK_WIDGET (entry));
7467 * gtk_entry_get_width_chars:
7468 * @entry: a #GtkEntry
7470 * Gets the value set by gtk_entry_set_width_chars().
7472 * Return value: number of chars to request space for, or negative if unset
7475 gtk_entry_get_width_chars (GtkEntry *entry)
7477 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7479 return entry->priv->width_chars;
7483 * gtk_entry_set_has_frame:
7484 * @entry: a #GtkEntry
7485 * @setting: new value
7487 * Sets whether the entry has a beveled frame around it.
7490 gtk_entry_set_has_frame (GtkEntry *entry,
7493 GtkEntryPrivate *priv;
7495 g_return_if_fail (GTK_IS_ENTRY (entry));
7499 setting = (setting != FALSE);
7501 if (priv->has_frame == setting)
7504 gtk_widget_queue_resize (GTK_WIDGET (entry));
7505 priv->has_frame = setting;
7506 g_object_notify (G_OBJECT (entry), "has-frame");
7510 * gtk_entry_get_has_frame:
7511 * @entry: a #GtkEntry
7513 * Gets the value set by gtk_entry_set_has_frame().
7515 * Return value: whether the entry has a beveled frame
7518 gtk_entry_get_has_frame (GtkEntry *entry)
7520 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7522 return entry->priv->has_frame;
7526 * gtk_entry_set_inner_border:
7527 * @entry: a #GtkEntry
7528 * @border: (allow-none): a #GtkBorder, or %NULL
7530 * Sets %entry's inner-border property to %border, or clears it if %NULL
7531 * is passed. The inner-border is the area around the entry's text, but
7534 * If set, this property overrides the inner-border style property.
7535 * Overriding the style-provided border is useful when you want to do
7536 * in-place editing of some text in a canvas or list widget, where
7537 * pixel-exact positioning of the entry is important.
7542 gtk_entry_set_inner_border (GtkEntry *entry,
7543 const GtkBorder *border)
7545 g_return_if_fail (GTK_IS_ENTRY (entry));
7547 gtk_widget_queue_resize (GTK_WIDGET (entry));
7550 g_object_set_qdata_full (G_OBJECT (entry), quark_inner_border,
7551 gtk_border_copy (border),
7552 (GDestroyNotify) gtk_border_free);
7554 g_object_set_qdata (G_OBJECT (entry), quark_inner_border, NULL);
7556 g_object_notify (G_OBJECT (entry), "inner-border");
7560 * gtk_entry_get_inner_border:
7561 * @entry: a #GtkEntry
7563 * This function returns the entry's #GtkEntry:inner-border property. See
7564 * gtk_entry_set_inner_border() for more information.
7566 * Return value: (transfer none): the entry's #GtkBorder, or %NULL if none was set.
7571 gtk_entry_get_inner_border (GtkEntry *entry)
7573 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7575 return g_object_get_qdata (G_OBJECT (entry), quark_inner_border);
7579 * gtk_entry_get_layout:
7580 * @entry: a #GtkEntry
7582 * Gets the #PangoLayout used to display the entry.
7583 * The layout is useful to e.g. convert text positions to
7584 * pixel positions, in combination with gtk_entry_get_layout_offsets().
7585 * The returned layout is owned by the entry and must not be
7586 * modified or freed by the caller.
7588 * Keep in mind that the layout text may contain a preedit string, so
7589 * gtk_entry_layout_index_to_text_index() and
7590 * gtk_entry_text_index_to_layout_index() are needed to convert byte
7591 * indices in the layout to byte indices in the entry contents.
7593 * Return value: (transfer none): the #PangoLayout for this entry
7596 gtk_entry_get_layout (GtkEntry *entry)
7598 PangoLayout *layout;
7600 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7602 layout = gtk_entry_ensure_layout (entry, TRUE);
7609 * gtk_entry_layout_index_to_text_index:
7610 * @entry: a #GtkEntry
7611 * @layout_index: byte index into the entry layout text
7613 * Converts from a position in the entry contents (returned
7614 * by gtk_entry_get_text()) to a position in the
7615 * entry's #PangoLayout (returned by gtk_entry_get_layout(),
7616 * with text retrieved via pango_layout_get_text()).
7618 * Return value: byte index into the entry contents
7621 gtk_entry_layout_index_to_text_index (GtkEntry *entry,
7624 GtkEntryPrivate *priv;
7625 PangoLayout *layout;
7629 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7633 layout = gtk_entry_ensure_layout (entry, TRUE);
7634 text = pango_layout_get_text (layout);
7635 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos) - text;
7637 if (layout_index >= cursor_index && priv->preedit_length)
7639 if (layout_index >= cursor_index + priv->preedit_length)
7640 layout_index -= priv->preedit_length;
7642 layout_index = cursor_index;
7645 return layout_index;
7649 * gtk_entry_text_index_to_layout_index:
7650 * @entry: a #GtkEntry
7651 * @text_index: byte index into the entry contents
7653 * Converts from a position in the entry's #PangoLayout (returned by
7654 * gtk_entry_get_layout()) to a position in the entry contents
7655 * (returned by gtk_entry_get_text()).
7657 * Return value: byte index into the entry layout text
7660 gtk_entry_text_index_to_layout_index (GtkEntry *entry,
7663 GtkEntryPrivate *priv;
7664 PangoLayout *layout;
7668 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7672 layout = gtk_entry_ensure_layout (entry, TRUE);
7673 text = pango_layout_get_text (layout);
7674 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos) - text;
7676 if (text_index > cursor_index)
7677 text_index += priv->preedit_length;
7683 * gtk_entry_get_layout_offsets:
7684 * @entry: a #GtkEntry
7685 * @x: (out) (allow-none): location to store X offset of layout, or %NULL
7686 * @y: (out) (allow-none): location to store Y offset of layout, or %NULL
7689 * Obtains the position of the #PangoLayout used to render text
7690 * in the entry, in widget coordinates. Useful if you want to line
7691 * up the text in an entry with some other text, e.g. when using the
7692 * entry to implement editable cells in a sheet widget.
7694 * Also useful to convert mouse events into coordinates inside the
7695 * #PangoLayout, e.g. to take some action if some part of the entry text
7698 * Note that as the user scrolls around in the entry the offsets will
7699 * change; you'll need to connect to the "notify::scroll-offset"
7700 * signal to track this. Remember when using the #PangoLayout
7701 * functions you need to convert to and from pixels using
7702 * PANGO_PIXELS() or #PANGO_SCALE.
7704 * Keep in mind that the layout text may contain a preedit string, so
7705 * gtk_entry_layout_index_to_text_index() and
7706 * gtk_entry_text_index_to_layout_index() are needed to convert byte
7707 * indices in the layout to byte indices in the entry contents.
7710 gtk_entry_get_layout_offsets (GtkEntry *entry,
7714 gint text_area_x, text_area_y;
7716 g_return_if_fail (GTK_IS_ENTRY (entry));
7718 /* this gets coords relative to text area */
7719 get_layout_position (entry, x, y);
7721 /* convert to widget coords */
7722 gtk_entry_get_text_area_size (entry, &text_area_x, &text_area_y, NULL, NULL);
7733 * gtk_entry_set_alignment:
7734 * @entry: a #GtkEntry
7735 * @xalign: The horizontal alignment, from 0 (left) to 1 (right).
7736 * Reversed for RTL layouts
7738 * Sets the alignment for the contents of the entry. This controls
7739 * the horizontal positioning of the contents when the displayed
7740 * text is shorter than the width of the entry.
7745 gtk_entry_set_alignment (GtkEntry *entry, gfloat xalign)
7747 GtkEntryPrivate *priv;
7749 g_return_if_fail (GTK_IS_ENTRY (entry));
7755 else if (xalign > 1.0)
7758 if (xalign != priv->xalign)
7760 priv->xalign = xalign;
7762 gtk_entry_recompute (entry);
7764 g_object_notify (G_OBJECT (entry), "xalign");
7769 * gtk_entry_get_alignment:
7770 * @entry: a #GtkEntry
7772 * Gets the value set by gtk_entry_set_alignment().
7774 * Return value: the alignment
7779 gtk_entry_get_alignment (GtkEntry *entry)
7781 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
7783 return entry->priv->xalign;
7787 * gtk_entry_set_icon_from_pixbuf:
7788 * @entry: a #GtkEntry
7789 * @icon_pos: Icon position
7790 * @pixbuf: (allow-none): A #GdkPixbuf, or %NULL
7792 * Sets the icon shown in the specified position using a pixbuf.
7794 * If @pixbuf is %NULL, no icon will be shown in the specified position.
7799 gtk_entry_set_icon_from_pixbuf (GtkEntry *entry,
7800 GtkEntryIconPosition icon_pos,
7803 GtkEntryPrivate *priv;
7804 EntryIconInfo *icon_info;
7806 g_return_if_fail (GTK_IS_ENTRY (entry));
7807 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7811 if ((icon_info = priv->icons[icon_pos]) == NULL)
7812 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7814 g_object_freeze_notify (G_OBJECT (entry));
7817 g_object_ref (pixbuf);
7819 gtk_entry_clear (entry, icon_pos);
7823 icon_info->storage_type = GTK_IMAGE_PIXBUF;
7824 icon_info->pixbuf = pixbuf;
7826 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7828 g_object_notify (G_OBJECT (entry), "primary-icon-pixbuf");
7829 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7833 g_object_notify (G_OBJECT (entry), "secondary-icon-pixbuf");
7834 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7837 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7838 gdk_window_show_unraised (icon_info->window);
7841 gtk_entry_ensure_pixbuf (entry, icon_pos);
7843 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7844 gtk_widget_queue_resize (GTK_WIDGET (entry));
7846 g_object_thaw_notify (G_OBJECT (entry));
7850 * gtk_entry_set_icon_from_stock:
7851 * @entry: A #GtkEntry
7852 * @icon_pos: Icon position
7853 * @stock_id: (allow-none): The name of the stock item, or %NULL
7855 * Sets the icon shown in the entry at the specified position from
7858 * If @stock_id is %NULL, no icon will be shown in the specified position.
7863 gtk_entry_set_icon_from_stock (GtkEntry *entry,
7864 GtkEntryIconPosition icon_pos,
7865 const gchar *stock_id)
7867 GtkEntryPrivate *priv;
7868 EntryIconInfo *icon_info;
7871 g_return_if_fail (GTK_IS_ENTRY (entry));
7872 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7876 if ((icon_info = priv->icons[icon_pos]) == NULL)
7877 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7879 g_object_freeze_notify (G_OBJECT (entry));
7881 /* need to dup before clearing */
7882 new_id = g_strdup (stock_id);
7884 gtk_entry_clear (entry, icon_pos);
7888 icon_info->storage_type = GTK_IMAGE_STOCK;
7889 icon_info->stock_id = new_id;
7891 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7893 g_object_notify (G_OBJECT (entry), "primary-icon-stock");
7894 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7898 g_object_notify (G_OBJECT (entry), "secondary-icon-stock");
7899 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7902 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7903 gdk_window_show_unraised (icon_info->window);
7906 gtk_entry_ensure_pixbuf (entry, icon_pos);
7908 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7909 gtk_widget_queue_resize (GTK_WIDGET (entry));
7911 g_object_thaw_notify (G_OBJECT (entry));
7915 * gtk_entry_set_icon_from_icon_name:
7916 * @entry: A #GtkEntry
7917 * @icon_pos: The position at which to set the icon
7918 * @icon_name: (allow-none): An icon name, or %NULL
7920 * Sets the icon shown in the entry at the specified position
7921 * from the current icon theme.
7923 * If the icon name isn't known, a "broken image" icon will be displayed
7926 * If @icon_name is %NULL, no icon will be shown in the specified position.
7931 gtk_entry_set_icon_from_icon_name (GtkEntry *entry,
7932 GtkEntryIconPosition icon_pos,
7933 const gchar *icon_name)
7935 GtkEntryPrivate *priv;
7936 EntryIconInfo *icon_info;
7939 g_return_if_fail (GTK_IS_ENTRY (entry));
7940 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7944 if ((icon_info = priv->icons[icon_pos]) == NULL)
7945 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7947 g_object_freeze_notify (G_OBJECT (entry));
7949 /* need to dup before clearing */
7950 new_name = g_strdup (icon_name);
7952 gtk_entry_clear (entry, icon_pos);
7954 if (new_name != NULL)
7956 icon_info->storage_type = GTK_IMAGE_ICON_NAME;
7957 icon_info->icon_name = new_name;
7959 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7961 g_object_notify (G_OBJECT (entry), "primary-icon-name");
7962 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7966 g_object_notify (G_OBJECT (entry), "secondary-icon-name");
7967 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7970 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7971 gdk_window_show_unraised (icon_info->window);
7974 gtk_entry_ensure_pixbuf (entry, icon_pos);
7976 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7977 gtk_widget_queue_resize (GTK_WIDGET (entry));
7979 g_object_thaw_notify (G_OBJECT (entry));
7983 * gtk_entry_set_icon_from_gicon:
7984 * @entry: A #GtkEntry
7985 * @icon_pos: The position at which to set the icon
7986 * @icon: (allow-none): The icon to set, or %NULL
7988 * Sets the icon shown in the entry at the specified position
7989 * from the current icon theme.
7990 * If the icon isn't known, a "broken image" icon will be displayed
7993 * If @icon is %NULL, no icon will be shown in the specified position.
7998 gtk_entry_set_icon_from_gicon (GtkEntry *entry,
7999 GtkEntryIconPosition icon_pos,
8002 GtkEntryPrivate *priv;
8003 EntryIconInfo *icon_info;
8005 g_return_if_fail (GTK_IS_ENTRY (entry));
8006 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8010 if ((icon_info = priv->icons[icon_pos]) == NULL)
8011 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8013 g_object_freeze_notify (G_OBJECT (entry));
8015 /* need to ref before clearing */
8017 g_object_ref (icon);
8019 gtk_entry_clear (entry, icon_pos);
8023 icon_info->storage_type = GTK_IMAGE_GICON;
8024 icon_info->gicon = icon;
8026 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
8028 g_object_notify (G_OBJECT (entry), "primary-icon-gicon");
8029 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
8033 g_object_notify (G_OBJECT (entry), "secondary-icon-gicon");
8034 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
8037 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
8038 gdk_window_show_unraised (icon_info->window);
8041 gtk_entry_ensure_pixbuf (entry, icon_pos);
8043 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
8044 gtk_widget_queue_resize (GTK_WIDGET (entry));
8046 g_object_thaw_notify (G_OBJECT (entry));
8050 * gtk_entry_set_icon_activatable:
8051 * @entry: A #GtkEntry
8052 * @icon_pos: Icon position
8053 * @activatable: %TRUE if the icon should be activatable
8055 * Sets whether the icon is activatable.
8060 gtk_entry_set_icon_activatable (GtkEntry *entry,
8061 GtkEntryIconPosition icon_pos,
8062 gboolean activatable)
8064 GtkEntryPrivate *priv;
8065 EntryIconInfo *icon_info;
8067 g_return_if_fail (GTK_IS_ENTRY (entry));
8068 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8072 if ((icon_info = priv->icons[icon_pos]) == NULL)
8073 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8075 activatable = activatable != FALSE;
8077 if (icon_info->nonactivatable != !activatable)
8079 icon_info->nonactivatable = !activatable;
8081 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
8082 update_cursors (GTK_WIDGET (entry));
8084 g_object_notify (G_OBJECT (entry),
8085 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-activatable" : "secondary-icon-activatable");
8090 * gtk_entry_get_icon_activatable:
8091 * @entry: a #GtkEntry
8092 * @icon_pos: Icon position
8094 * Returns whether the icon is activatable.
8096 * Returns: %TRUE if the icon is activatable.
8101 gtk_entry_get_icon_activatable (GtkEntry *entry,
8102 GtkEntryIconPosition icon_pos)
8104 GtkEntryPrivate *priv;
8105 EntryIconInfo *icon_info;
8107 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
8108 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), FALSE);
8111 icon_info = priv->icons[icon_pos];
8113 return (!icon_info || !icon_info->nonactivatable);
8117 * gtk_entry_get_icon_pixbuf:
8118 * @entry: A #GtkEntry
8119 * @icon_pos: Icon position
8121 * Retrieves the image used for the icon.
8123 * Unlike the other methods of setting and getting icon data, this
8124 * method will work regardless of whether the icon was set using a
8125 * #GdkPixbuf, a #GIcon, a stock item, or an icon name.
8127 * Returns: (transfer none): A #GdkPixbuf, or %NULL if no icon is
8128 * set for this position.
8133 gtk_entry_get_icon_pixbuf (GtkEntry *entry,
8134 GtkEntryIconPosition icon_pos)
8136 GtkEntryPrivate *priv;
8137 EntryIconInfo *icon_info;
8139 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8140 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8144 icon_info = priv->icons[icon_pos];
8149 gtk_entry_ensure_pixbuf (entry, icon_pos);
8151 return icon_info->pixbuf;
8155 * gtk_entry_get_icon_gicon:
8156 * @entry: A #GtkEntry
8157 * @icon_pos: Icon position
8159 * Retrieves the #GIcon used for the icon, or %NULL if there is
8160 * no icon or if the icon was set by some other method (e.g., by
8161 * stock, pixbuf, or icon name).
8163 * Returns: (transfer none): A #GIcon, or %NULL if no icon is set
8164 * or if the icon is not a #GIcon
8169 gtk_entry_get_icon_gicon (GtkEntry *entry,
8170 GtkEntryIconPosition icon_pos)
8172 GtkEntryPrivate *priv;
8173 EntryIconInfo *icon_info;
8175 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8176 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8179 icon_info = priv->icons[icon_pos];
8184 return icon_info->storage_type == GTK_IMAGE_GICON ? icon_info->gicon : NULL;
8188 * gtk_entry_get_icon_stock:
8189 * @entry: A #GtkEntry
8190 * @icon_pos: Icon position
8192 * Retrieves the stock id used for the icon, or %NULL if there is
8193 * no icon or if the icon was set by some other method (e.g., by
8194 * pixbuf, icon name or gicon).
8196 * Returns: A stock id, or %NULL if no icon is set or if the icon
8197 * wasn't set from a stock id
8202 gtk_entry_get_icon_stock (GtkEntry *entry,
8203 GtkEntryIconPosition icon_pos)
8205 GtkEntryPrivate *priv;
8206 EntryIconInfo *icon_info;
8208 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8209 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8212 icon_info = priv->icons[icon_pos];
8217 return icon_info->storage_type == GTK_IMAGE_STOCK ? icon_info->stock_id : NULL;
8221 * gtk_entry_get_icon_name:
8222 * @entry: A #GtkEntry
8223 * @icon_pos: Icon position
8225 * Retrieves the icon name used for the icon, or %NULL if there is
8226 * no icon or if the icon was set by some other method (e.g., by
8227 * pixbuf, stock or gicon).
8229 * Returns: An icon name, or %NULL if no icon is set or if the icon
8230 * wasn't set from an icon name
8235 gtk_entry_get_icon_name (GtkEntry *entry,
8236 GtkEntryIconPosition icon_pos)
8238 GtkEntryPrivate *priv;
8239 EntryIconInfo *icon_info;
8241 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8242 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8245 icon_info = priv->icons[icon_pos];
8250 return icon_info->storage_type == GTK_IMAGE_ICON_NAME ? icon_info->icon_name : NULL;
8254 * gtk_entry_set_icon_sensitive:
8255 * @entry: A #GtkEntry
8256 * @icon_pos: Icon position
8257 * @sensitive: Specifies whether the icon should appear
8258 * sensitive or insensitive
8260 * Sets the sensitivity for the specified icon.
8265 gtk_entry_set_icon_sensitive (GtkEntry *entry,
8266 GtkEntryIconPosition icon_pos,
8269 GtkEntryPrivate *priv;
8270 EntryIconInfo *icon_info;
8272 g_return_if_fail (GTK_IS_ENTRY (entry));
8273 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8277 if ((icon_info = priv->icons[icon_pos]) == NULL)
8278 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8280 if (icon_info->insensitive != !sensitive)
8282 icon_info->insensitive = !sensitive;
8284 icon_info->pressed = FALSE;
8285 icon_info->prelight = FALSE;
8287 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
8288 update_cursors (GTK_WIDGET (entry));
8290 gtk_widget_queue_draw (GTK_WIDGET (entry));
8292 g_object_notify (G_OBJECT (entry),
8293 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-sensitive" : "secondary-icon-sensitive");
8298 * gtk_entry_get_icon_sensitive:
8299 * @entry: a #GtkEntry
8300 * @icon_pos: Icon position
8302 * Returns whether the icon appears sensitive or insensitive.
8304 * Returns: %TRUE if the icon is sensitive.
8309 gtk_entry_get_icon_sensitive (GtkEntry *entry,
8310 GtkEntryIconPosition icon_pos)
8312 GtkEntryPrivate *priv;
8313 EntryIconInfo *icon_info;
8315 g_return_val_if_fail (GTK_IS_ENTRY (entry), TRUE);
8316 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), TRUE);
8320 icon_info = priv->icons[icon_pos];
8322 return (!icon_info || !icon_info->insensitive);
8327 * gtk_entry_get_icon_storage_type:
8328 * @entry: a #GtkEntry
8329 * @icon_pos: Icon position
8331 * Gets the type of representation being used by the icon
8332 * to store image data. If the icon has no image data,
8333 * the return value will be %GTK_IMAGE_EMPTY.
8335 * Return value: image representation being used
8340 gtk_entry_get_icon_storage_type (GtkEntry *entry,
8341 GtkEntryIconPosition icon_pos)
8343 GtkEntryPrivate *priv;
8344 EntryIconInfo *icon_info;
8346 g_return_val_if_fail (GTK_IS_ENTRY (entry), GTK_IMAGE_EMPTY);
8347 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), GTK_IMAGE_EMPTY);
8351 icon_info = priv->icons[icon_pos];
8354 return GTK_IMAGE_EMPTY;
8356 return icon_info->storage_type;
8360 * gtk_entry_get_icon_at_pos:
8361 * @entry: a #GtkEntry
8362 * @x: the x coordinate of the position to find
8363 * @y: the y coordinate of the position to find
8365 * Finds the icon at the given position and return its index. The
8366 * position's coordinates are relative to the @entry's top left corner.
8367 * If @x, @y doesn't lie inside an icon, -1 is returned.
8368 * This function is intended for use in a #GtkWidget::query-tooltip
8371 * Returns: the index of the icon at the given position, or -1
8376 gtk_entry_get_icon_at_pos (GtkEntry *entry,
8380 GtkAllocation primary;
8381 GtkAllocation secondary;
8382 gint frame_x, frame_y;
8384 g_return_val_if_fail (GTK_IS_ENTRY (entry), -1);
8386 get_frame_size (entry, FALSE, &frame_x, &frame_y, NULL, NULL);
8390 get_icon_allocations (entry, &primary, &secondary);
8392 if (primary.x <= x && x < primary.x + primary.width &&
8393 primary.y <= y && y < primary.y + primary.height)
8394 return GTK_ENTRY_ICON_PRIMARY;
8396 if (secondary.x <= x && x < secondary.x + secondary.width &&
8397 secondary.y <= y && y < secondary.y + secondary.height)
8398 return GTK_ENTRY_ICON_SECONDARY;
8404 * gtk_entry_set_icon_drag_source:
8405 * @entry: a #GtkIconEntry
8406 * @icon_pos: icon position
8407 * @target_list: the targets (data formats) in which the data can be provided
8408 * @actions: a bitmask of the allowed drag actions
8410 * Sets up the icon at the given position so that GTK+ will start a drag
8411 * operation when the user clicks and drags the icon.
8413 * To handle the drag operation, you need to connect to the usual
8414 * #GtkWidget::drag-data-get (or possibly #GtkWidget::drag-data-delete)
8415 * signal, and use gtk_entry_get_current_icon_drag_source() in
8416 * your signal handler to find out if the drag was started from
8419 * By default, GTK+ uses the icon as the drag icon. You can use the
8420 * #GtkWidget::drag-begin signal to set a different icon. Note that you
8421 * have to use g_signal_connect_after() to ensure that your signal handler
8422 * gets executed after the default handler.
8427 gtk_entry_set_icon_drag_source (GtkEntry *entry,
8428 GtkEntryIconPosition icon_pos,
8429 GtkTargetList *target_list,
8430 GdkDragAction actions)
8432 GtkEntryPrivate *priv;
8433 EntryIconInfo *icon_info;
8435 g_return_if_fail (GTK_IS_ENTRY (entry));
8436 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8440 if ((icon_info = priv->icons[icon_pos]) == NULL)
8441 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8443 if (icon_info->target_list)
8444 gtk_target_list_unref (icon_info->target_list);
8445 icon_info->target_list = target_list;
8446 if (icon_info->target_list)
8447 gtk_target_list_ref (icon_info->target_list);
8449 icon_info->actions = actions;
8453 * gtk_entry_get_current_icon_drag_source:
8454 * @entry: a #GtkIconEntry
8456 * Returns the index of the icon which is the source of the current
8457 * DND operation, or -1.
8459 * This function is meant to be used in a #GtkWidget::drag-data-get
8462 * Returns: index of the icon which is the source of the current
8463 * DND operation, or -1.
8468 gtk_entry_get_current_icon_drag_source (GtkEntry *entry)
8470 GtkEntryPrivate *priv;
8471 EntryIconInfo *icon_info = NULL;
8474 g_return_val_if_fail (GTK_IS_ENTRY (entry), -1);
8478 for (i = 0; i < MAX_ICONS; i++)
8480 if ((icon_info = priv->icons[i]))
8482 if (icon_info->in_drag)
8491 * gtk_entry_get_icon_area:
8492 * @entry: A #GtkEntry
8493 * @icon_pos: Icon position
8494 * @icon_area: (out): Return location for the icon's area
8496 * Gets the area where entry's icon at @icon_pos is drawn.
8497 * This function is useful when drawing something to the
8498 * entry in a draw callback.
8500 * If the entry is not realized or has no icon at the given position,
8501 * @icon_area is filled with zeros.
8503 * See also gtk_entry_get_text_area()
8508 gtk_entry_get_icon_area (GtkEntry *entry,
8509 GtkEntryIconPosition icon_pos,
8510 GdkRectangle *icon_area)
8512 GtkEntryPrivate *priv;
8513 EntryIconInfo *icon_info;
8515 g_return_if_fail (GTK_IS_ENTRY (entry));
8516 g_return_if_fail (icon_area != NULL);
8520 icon_info = priv->icons[icon_pos];
8524 GtkAllocation primary;
8525 GtkAllocation secondary;
8527 get_icon_allocations (entry, &primary, &secondary);
8529 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
8530 *icon_area = primary;
8532 *icon_area = secondary;
8538 icon_area->width = 0;
8539 icon_area->height = 0;
8544 ensure_has_tooltip (GtkEntry *entry)
8546 GtkEntryPrivate *priv;
8547 EntryIconInfo *icon_info;
8549 gboolean has_tooltip = FALSE;
8553 for (i = 0; i < MAX_ICONS; i++)
8555 if ((icon_info = priv->icons[i]) != NULL)
8557 if (icon_info->tooltip != NULL)
8565 gtk_widget_set_has_tooltip (GTK_WIDGET (entry), has_tooltip);
8569 * gtk_entry_get_icon_tooltip_text:
8570 * @entry: a #GtkEntry
8571 * @icon_pos: the icon position
8573 * Gets the contents of the tooltip on the icon at the specified
8574 * position in @entry.
8576 * Returns: the tooltip text, or %NULL. Free the returned string
8577 * with g_free() when done.
8582 gtk_entry_get_icon_tooltip_text (GtkEntry *entry,
8583 GtkEntryIconPosition icon_pos)
8585 GtkEntryPrivate *priv;
8586 EntryIconInfo *icon_info;
8589 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8590 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8594 icon_info = priv->icons[icon_pos];
8599 if (icon_info->tooltip &&
8600 !pango_parse_markup (icon_info->tooltip, -1, 0, NULL, &text, NULL, NULL))
8601 g_assert (NULL == text); /* text should still be NULL in case of markup errors */
8607 * gtk_entry_set_icon_tooltip_text:
8608 * @entry: a #GtkEntry
8609 * @icon_pos: the icon position
8610 * @tooltip: (allow-none): the contents of the tooltip for the icon, or %NULL
8612 * Sets @tooltip as the contents of the tooltip for the icon
8613 * at the specified position.
8615 * Use %NULL for @tooltip to remove an existing tooltip.
8617 * See also gtk_widget_set_tooltip_text() and
8618 * gtk_entry_set_icon_tooltip_markup().
8623 gtk_entry_set_icon_tooltip_text (GtkEntry *entry,
8624 GtkEntryIconPosition icon_pos,
8625 const gchar *tooltip)
8627 GtkEntryPrivate *priv;
8628 EntryIconInfo *icon_info;
8630 g_return_if_fail (GTK_IS_ENTRY (entry));
8631 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8635 if ((icon_info = priv->icons[icon_pos]) == NULL)
8636 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8638 if (icon_info->tooltip)
8639 g_free (icon_info->tooltip);
8641 /* Treat an empty string as a NULL string,
8642 * because an empty string would be useless for a tooltip:
8644 if (tooltip && tooltip[0] == '\0')
8647 icon_info->tooltip = tooltip ? g_markup_escape_text (tooltip, -1) : NULL;
8649 ensure_has_tooltip (entry);
8653 * gtk_entry_get_icon_tooltip_markup:
8654 * @entry: a #GtkEntry
8655 * @icon_pos: the icon position
8657 * Gets the contents of the tooltip on the icon at the specified
8658 * position in @entry.
8660 * Returns: the tooltip text, or %NULL. Free the returned string
8661 * with g_free() when done.
8666 gtk_entry_get_icon_tooltip_markup (GtkEntry *entry,
8667 GtkEntryIconPosition icon_pos)
8669 GtkEntryPrivate *priv;
8670 EntryIconInfo *icon_info;
8672 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8673 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8677 icon_info = priv->icons[icon_pos];
8682 return g_strdup (icon_info->tooltip);
8686 * gtk_entry_set_icon_tooltip_markup:
8687 * @entry: a #GtkEntry
8688 * @icon_pos: the icon position
8689 * @tooltip: (allow-none): the contents of the tooltip for the icon, or %NULL
8691 * Sets @tooltip as the contents of the tooltip for the icon at
8692 * the specified position. @tooltip is assumed to be marked up with
8693 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
8695 * Use %NULL for @tooltip to remove an existing tooltip.
8697 * See also gtk_widget_set_tooltip_markup() and
8698 * gtk_enty_set_icon_tooltip_text().
8703 gtk_entry_set_icon_tooltip_markup (GtkEntry *entry,
8704 GtkEntryIconPosition icon_pos,
8705 const gchar *tooltip)
8707 GtkEntryPrivate *priv;
8708 EntryIconInfo *icon_info;
8710 g_return_if_fail (GTK_IS_ENTRY (entry));
8711 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8715 if ((icon_info = priv->icons[icon_pos]) == NULL)
8716 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8718 if (icon_info->tooltip)
8719 g_free (icon_info->tooltip);
8721 /* Treat an empty string as a NULL string,
8722 * because an empty string would be useless for a tooltip:
8724 if (tooltip && tooltip[0] == '\0')
8727 icon_info->tooltip = g_strdup (tooltip);
8729 ensure_has_tooltip (entry);
8733 gtk_entry_query_tooltip (GtkWidget *widget,
8736 gboolean keyboard_tip,
8737 GtkTooltip *tooltip)
8740 GtkEntryPrivate *priv;
8741 EntryIconInfo *icon_info;
8744 entry = GTK_ENTRY (widget);
8749 icon_pos = gtk_entry_get_icon_at_pos (entry, x, y);
8752 if ((icon_info = priv->icons[icon_pos]) != NULL)
8754 if (icon_info->tooltip)
8756 gtk_tooltip_set_markup (tooltip, icon_info->tooltip);
8765 return GTK_WIDGET_CLASS (gtk_entry_parent_class)->query_tooltip (widget,
8772 /* Quick hack of a popup menu
8775 activate_cb (GtkWidget *menuitem,
8778 const gchar *signal = g_object_get_data (G_OBJECT (menuitem), "gtk-signal");
8779 g_signal_emit_by_name (entry, signal);
8784 gtk_entry_mnemonic_activate (GtkWidget *widget,
8785 gboolean group_cycling)
8787 gtk_widget_grab_focus (widget);
8792 append_action_signal (GtkEntry *entry,
8794 const gchar *stock_id,
8795 const gchar *signal,
8798 GtkWidget *menuitem = gtk_image_menu_item_new_from_stock (stock_id, NULL);
8800 g_object_set_data (G_OBJECT (menuitem), I_("gtk-signal"), (char *)signal);
8801 g_signal_connect (menuitem, "activate",
8802 G_CALLBACK (activate_cb), entry);
8804 gtk_widget_set_sensitive (menuitem, sensitive);
8806 gtk_widget_show (menuitem);
8807 gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
8811 popup_menu_detach (GtkWidget *attach_widget,
8814 GtkEntry *entry_attach = GTK_ENTRY (attach_widget);
8815 GtkEntryPrivate *priv_attach = entry_attach->priv;
8817 priv_attach->popup_menu = NULL;
8821 popup_position_func (GtkMenu *menu,
8827 GtkEntry *entry = GTK_ENTRY (user_data);
8828 GtkEntryPrivate *priv = entry->priv;
8829 GtkWidget *widget = GTK_WIDGET (entry);
8831 GtkRequisition menu_req;
8832 GdkRectangle monitor;
8833 GtkBorder inner_border;
8834 gint monitor_num, strong_x, height;
8836 g_return_if_fail (gtk_widget_get_realized (widget));
8838 gdk_window_get_origin (priv->text_area, x, y);
8840 screen = gtk_widget_get_screen (widget);
8841 monitor_num = gdk_screen_get_monitor_at_window (screen, priv->text_area);
8842 if (monitor_num < 0)
8844 gtk_menu_set_monitor (menu, monitor_num);
8846 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
8847 gtk_widget_get_preferred_size (priv->popup_menu,
8849 height = gdk_window_get_height (priv->text_area);
8850 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
8851 _gtk_entry_effective_inner_border (entry, &inner_border);
8853 *x += inner_border.left + strong_x - priv->scroll_offset;
8854 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
8855 *x -= menu_req.width;
8857 if ((*y + height + menu_req.height) <= monitor.y + monitor.height)
8859 else if ((*y - menu_req.height) >= monitor.y)
8860 *y -= menu_req.height;
8861 else if (monitor.y + monitor.height - (*y + height) > *y)
8864 *y -= menu_req.height;
8870 unichar_chosen_func (const char *text,
8873 GtkEntry *entry = GTK_ENTRY (data);
8874 GtkEntryPrivate *priv = entry->priv;
8877 gtk_entry_enter_text (entry, text);
8888 popup_targets_received (GtkClipboard *clipboard,
8889 GtkSelectionData *data,
8892 PopupInfo *info = user_data;
8893 GtkEntry *entry = info->entry;
8894 GtkEntryPrivate *info_entry_priv = entry->priv;
8896 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
8899 gboolean clipboard_contains_text;
8900 GtkWidget *menuitem;
8902 gboolean show_input_method_menu;
8903 gboolean show_unicode_menu;
8905 clipboard_contains_text = gtk_selection_data_targets_include_text (data);
8906 if (info_entry_priv->popup_menu)
8907 gtk_widget_destroy (info_entry_priv->popup_menu);
8909 info_entry_priv->popup_menu = gtk_menu_new ();
8911 gtk_menu_attach_to_widget (GTK_MENU (info_entry_priv->popup_menu),
8915 mode = gtk_entry_get_display_mode (entry);
8916 append_action_signal (entry, info_entry_priv->popup_menu, GTK_STOCK_CUT, "cut-clipboard",
8917 info_entry_priv->editable && mode == DISPLAY_NORMAL &&
8918 info_entry_priv->current_pos != info_entry_priv->selection_bound);
8920 append_action_signal (entry, info_entry_priv->popup_menu, GTK_STOCK_COPY, "copy-clipboard",
8921 mode == DISPLAY_NORMAL &&
8922 info_entry_priv->current_pos != info_entry_priv->selection_bound);
8924 append_action_signal (entry, info_entry_priv->popup_menu, GTK_STOCK_PASTE, "paste-clipboard",
8925 info_entry_priv->editable && clipboard_contains_text);
8927 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_DELETE, NULL);
8928 gtk_widget_set_sensitive (menuitem, info_entry_priv->editable && info_entry_priv->current_pos != info_entry_priv->selection_bound);
8929 g_signal_connect_swapped (menuitem, "activate",
8930 G_CALLBACK (gtk_entry_delete_cb), entry);
8931 gtk_widget_show (menuitem);
8932 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8934 menuitem = gtk_separator_menu_item_new ();
8935 gtk_widget_show (menuitem);
8936 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8938 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_SELECT_ALL, NULL);
8939 gtk_widget_set_sensitive (menuitem, gtk_entry_buffer_get_length (info_entry_priv->buffer) > 0);
8940 g_signal_connect_swapped (menuitem, "activate",
8941 G_CALLBACK (gtk_entry_select_all), entry);
8942 gtk_widget_show (menuitem);
8943 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8945 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
8946 "gtk-show-input-method-menu", &show_input_method_menu,
8947 "gtk-show-unicode-menu", &show_unicode_menu,
8950 if (show_input_method_menu || show_unicode_menu)
8952 menuitem = gtk_separator_menu_item_new ();
8953 gtk_widget_show (menuitem);
8954 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8957 if (show_input_method_menu)
8959 menuitem = gtk_menu_item_new_with_mnemonic (_("Input _Methods"));
8960 gtk_widget_set_sensitive (menuitem, info_entry_priv->editable);
8961 gtk_widget_show (menuitem);
8962 submenu = gtk_menu_new ();
8963 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
8965 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8967 gtk_im_multicontext_append_menuitems (GTK_IM_MULTICONTEXT (info_entry_priv->im_context),
8968 GTK_MENU_SHELL (submenu));
8971 if (show_unicode_menu)
8973 menuitem = gtk_menu_item_new_with_mnemonic (_("_Insert Unicode Control Character"));
8974 gtk_widget_set_sensitive (menuitem, info_entry_priv->editable);
8975 gtk_widget_show (menuitem);
8977 submenu = gtk_menu_new ();
8978 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
8979 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8981 _gtk_text_util_append_special_char_menuitems (GTK_MENU_SHELL (submenu),
8982 unichar_chosen_func,
8986 g_signal_emit (entry,
8987 signals[POPULATE_POPUP],
8989 info_entry_priv->popup_menu);
8993 gtk_menu_popup (GTK_MENU (info_entry_priv->popup_menu), NULL, NULL,
8995 info->button, info->time);
8998 gtk_menu_popup (GTK_MENU (info_entry_priv->popup_menu), NULL, NULL,
8999 popup_position_func, entry,
9000 info->button, info->time);
9001 gtk_menu_shell_select_first (GTK_MENU_SHELL (info_entry_priv->popup_menu), FALSE);
9005 g_object_unref (entry);
9006 g_slice_free (PopupInfo, info);
9010 gtk_entry_do_popup (GtkEntry *entry,
9011 GdkEventButton *event)
9013 PopupInfo *info = g_slice_new (PopupInfo);
9015 /* In order to know what entries we should make sensitive, we
9016 * ask for the current targets of the clipboard, and when
9017 * we get them, then we actually pop up the menu.
9019 info->entry = g_object_ref (entry);
9023 info->button = event->button;
9024 info->time = event->time;
9029 info->time = gtk_get_current_event_time ();
9032 gtk_clipboard_request_contents (gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_CLIPBOARD),
9033 gdk_atom_intern_static_string ("TARGETS"),
9034 popup_targets_received,
9039 gtk_entry_popup_menu (GtkWidget *widget)
9041 gtk_entry_do_popup (GTK_ENTRY (widget), NULL);
9046 gtk_entry_drag_begin (GtkWidget *widget,
9047 GdkDragContext *context)
9049 GtkEntry *entry = GTK_ENTRY (widget);
9050 GtkEntryPrivate *priv = entry->priv;
9053 for (i = 0; i < MAX_ICONS; i++)
9055 EntryIconInfo *icon_info = priv->icons[i];
9057 if (icon_info != NULL)
9059 if (icon_info->in_drag)
9061 switch (icon_info->storage_type)
9063 case GTK_IMAGE_STOCK:
9064 gtk_drag_set_icon_stock (context, icon_info->stock_id, -2, -2);
9067 case GTK_IMAGE_ICON_NAME:
9068 gtk_drag_set_icon_name (context, icon_info->icon_name, -2, -2);
9071 /* FIXME: No GIcon support for dnd icons */
9072 case GTK_IMAGE_GICON:
9073 case GTK_IMAGE_PIXBUF:
9074 gtk_drag_set_icon_pixbuf (context, icon_info->pixbuf, -2, -2);
9077 g_assert_not_reached ();
9085 gtk_entry_drag_end (GtkWidget *widget,
9086 GdkDragContext *context)
9088 GtkEntry *entry = GTK_ENTRY (widget);
9089 GtkEntryPrivate *priv = entry->priv;
9092 for (i = 0; i < MAX_ICONS; i++)
9094 EntryIconInfo *icon_info = priv->icons[i];
9096 if (icon_info != NULL)
9097 icon_info->in_drag = 0;
9102 gtk_entry_drag_leave (GtkWidget *widget,
9103 GdkDragContext *context,
9106 GtkEntry *entry = GTK_ENTRY (widget);
9107 GtkEntryPrivate *priv = entry->priv;
9109 priv->dnd_position = -1;
9110 gtk_widget_queue_draw (widget);
9114 gtk_entry_drag_drop (GtkWidget *widget,
9115 GdkDragContext *context,
9120 GtkEntry *entry = GTK_ENTRY (widget);
9121 GtkEntryPrivate *priv = entry->priv;
9122 GdkAtom target = GDK_NONE;
9125 target = gtk_drag_dest_find_target (widget, context, NULL);
9127 if (target != GDK_NONE)
9128 gtk_drag_get_data (widget, context, target, time);
9130 gtk_drag_finish (context, FALSE, FALSE, time);
9136 gtk_entry_drag_motion (GtkWidget *widget,
9137 GdkDragContext *context,
9142 GtkEntry *entry = GTK_ENTRY (widget);
9143 GtkEntryPrivate *priv = entry->priv;
9144 GtkStyleContext *style_context;
9145 GtkWidget *source_widget;
9146 GdkDragAction suggested_action;
9147 gint new_position, old_position;
9151 style_context = gtk_widget_get_style_context (widget);
9152 gtk_style_context_get_padding (style_context, 0, &padding);
9156 old_position = priv->dnd_position;
9157 new_position = gtk_entry_find_position (entry, x + priv->scroll_offset);
9159 if (priv->editable &&
9160 gtk_drag_dest_find_target (widget, context, NULL) != GDK_NONE)
9162 source_widget = gtk_drag_get_source_widget (context);
9163 suggested_action = gdk_drag_context_get_suggested_action (context);
9165 if (!gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &sel1, &sel2) ||
9166 new_position < sel1 || new_position > sel2)
9168 if (source_widget == widget)
9170 /* Default to MOVE, unless the user has
9171 * pressed ctrl or alt to affect available actions
9173 if ((gdk_drag_context_get_actions (context) & GDK_ACTION_MOVE) != 0)
9174 suggested_action = GDK_ACTION_MOVE;
9177 priv->dnd_position = new_position;
9181 if (source_widget == widget)
9182 suggested_action = 0; /* Can't drop in selection where drag started */
9184 priv->dnd_position = -1;
9189 /* Entry not editable, or no text */
9190 suggested_action = 0;
9191 priv->dnd_position = -1;
9194 gdk_drag_status (context, suggested_action, time);
9196 if (priv->dnd_position != old_position)
9197 gtk_widget_queue_draw (widget);
9203 gtk_entry_drag_data_received (GtkWidget *widget,
9204 GdkDragContext *context,
9207 GtkSelectionData *selection_data,
9211 GtkEntry *entry = GTK_ENTRY (widget);
9212 GtkEntryPrivate *priv = entry->priv;
9213 GtkEditable *editable = GTK_EDITABLE (widget);
9214 GtkStyleContext *style_context;
9218 str = (gchar *) gtk_selection_data_get_text (selection_data);
9220 style_context = gtk_widget_get_style_context (widget);
9221 gtk_style_context_get_padding (style_context, 0, &padding);
9225 if (str && priv->editable)
9231 if (priv->truncate_multiline)
9232 length = truncate_multiline (str);
9234 new_position = gtk_entry_find_position (entry, x + priv->scroll_offset);
9236 if (!gtk_editable_get_selection_bounds (editable, &sel1, &sel2) ||
9237 new_position < sel1 || new_position > sel2)
9239 gtk_editable_insert_text (editable, str, length, &new_position);
9243 /* Replacing selection */
9244 begin_change (entry);
9245 g_object_freeze_notify (G_OBJECT (entry));
9246 gtk_editable_delete_text (editable, sel1, sel2);
9247 gtk_editable_insert_text (editable, str, length, &sel1);
9248 g_object_thaw_notify (G_OBJECT (entry));
9252 gtk_drag_finish (context, TRUE, gdk_drag_context_get_selected_action (context) == GDK_ACTION_MOVE, time);
9256 /* Drag and drop didn't happen! */
9257 gtk_drag_finish (context, FALSE, FALSE, time);
9264 gtk_entry_drag_data_get (GtkWidget *widget,
9265 GdkDragContext *context,
9266 GtkSelectionData *selection_data,
9270 GtkEntry *entry = GTK_ENTRY (widget);
9271 GtkEntryPrivate *priv = entry->priv;
9272 GtkEditable *editable = GTK_EDITABLE (widget);
9273 gint sel_start, sel_end;
9276 /* If there is an icon drag going on, exit early. */
9277 for (i = 0; i < MAX_ICONS; i++)
9279 EntryIconInfo *icon_info = priv->icons[i];
9281 if (icon_info != NULL)
9283 if (icon_info->in_drag)
9288 if (gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end))
9290 gchar *str = gtk_entry_get_display_text (GTK_ENTRY (widget), sel_start, sel_end);
9292 gtk_selection_data_set_text (selection_data, str, -1);
9300 gtk_entry_drag_data_delete (GtkWidget *widget,
9301 GdkDragContext *context)
9303 GtkEntry *entry = GTK_ENTRY (widget);
9304 GtkEntryPrivate *priv = entry->priv;
9305 GtkEditable *editable = GTK_EDITABLE (widget);
9306 gint sel_start, sel_end;
9309 /* If there is an icon drag going on, exit early. */
9310 for (i = 0; i < MAX_ICONS; i++)
9312 EntryIconInfo *icon_info = priv->icons[i];
9314 if (icon_info != NULL)
9316 if (icon_info->in_drag)
9321 if (priv->editable &&
9322 gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end))
9323 gtk_editable_delete_text (editable, sel_start, sel_end);
9326 /* We display the cursor when
9328 * - the selection is empty, AND
9329 * - the widget has focus
9332 #define CURSOR_ON_MULTIPLIER 2
9333 #define CURSOR_OFF_MULTIPLIER 1
9334 #define CURSOR_PEND_MULTIPLIER 3
9335 #define CURSOR_DIVIDER 3
9338 cursor_blinks (GtkEntry *entry)
9340 GtkEntryPrivate *priv = entry->priv;
9342 if (gtk_widget_has_focus (GTK_WIDGET (entry)) &&
9344 priv->selection_bound == priv->current_pos)
9346 GtkSettings *settings;
9349 settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9350 g_object_get (settings, "gtk-cursor-blink", &blink, NULL);
9359 get_cursor_time (GtkEntry *entry)
9361 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9364 g_object_get (settings, "gtk-cursor-blink-time", &time, NULL);
9370 get_cursor_blink_timeout (GtkEntry *entry)
9372 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9375 g_object_get (settings, "gtk-cursor-blink-timeout", &timeout, NULL);
9381 show_cursor (GtkEntry *entry)
9383 GtkEntryPrivate *priv = entry->priv;
9386 if (!priv->cursor_visible)
9388 priv->cursor_visible = TRUE;
9390 widget = GTK_WIDGET (entry);
9391 if (gtk_widget_has_focus (widget) && priv->selection_bound == priv->current_pos)
9392 gtk_widget_queue_draw (widget);
9397 hide_cursor (GtkEntry *entry)
9399 GtkEntryPrivate *priv = entry->priv;
9402 if (priv->cursor_visible)
9404 priv->cursor_visible = FALSE;
9406 widget = GTK_WIDGET (entry);
9407 if (gtk_widget_has_focus (widget) && priv->selection_bound == priv->current_pos)
9408 gtk_widget_queue_draw (widget);
9416 blink_cb (gpointer data)
9419 GtkEntryPrivate *priv;
9422 entry = GTK_ENTRY (data);
9425 if (!gtk_widget_has_focus (GTK_WIDGET (entry)))
9427 g_warning ("GtkEntry - did not receive focus-out-event. If you\n"
9428 "connect a handler to this signal, it must return\n"
9429 "FALSE so the entry gets the event as well");
9431 gtk_entry_check_cursor_blink (entry);
9436 g_assert (priv->selection_bound == priv->current_pos);
9438 blink_timeout = get_cursor_blink_timeout (entry);
9439 if (priv->blink_time > 1000 * blink_timeout &&
9440 blink_timeout < G_MAXINT/1000)
9442 /* we've blinked enough without the user doing anything, stop blinking */
9443 show_cursor (entry);
9444 priv->blink_timeout = 0;
9446 else if (priv->cursor_visible)
9448 hide_cursor (entry);
9449 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_OFF_MULTIPLIER / CURSOR_DIVIDER,
9455 show_cursor (entry);
9456 priv->blink_time += get_cursor_time (entry);
9457 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
9462 /* Remove ourselves */
9467 gtk_entry_check_cursor_blink (GtkEntry *entry)
9469 GtkEntryPrivate *priv = entry->priv;
9471 if (cursor_blinks (entry))
9473 if (!priv->blink_timeout)
9475 show_cursor (entry);
9476 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
9483 if (priv->blink_timeout)
9485 g_source_remove (priv->blink_timeout);
9486 priv->blink_timeout = 0;
9489 priv->cursor_visible = TRUE;
9494 gtk_entry_pend_cursor_blink (GtkEntry *entry)
9496 GtkEntryPrivate *priv = entry->priv;
9498 if (cursor_blinks (entry))
9500 if (priv->blink_timeout != 0)
9501 g_source_remove (priv->blink_timeout);
9503 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_PEND_MULTIPLIER / CURSOR_DIVIDER,
9506 show_cursor (entry);
9511 gtk_entry_reset_blink_time (GtkEntry *entry)
9513 GtkEntryPrivate *priv = entry->priv;
9515 priv->blink_time = 0;
9521 gtk_entry_completion_timeout (gpointer data)
9523 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (data);
9524 GtkEntryPrivate *completion_entry_priv = GTK_ENTRY (completion->priv->entry)->priv;
9526 completion->priv->completion_timeout = 0;
9528 if (completion->priv->filter_model &&
9529 g_utf8_strlen (gtk_entry_get_text (GTK_ENTRY (completion->priv->entry)), -1)
9530 >= completion->priv->minimum_key_length)
9534 GtkTreeSelection *s;
9535 gboolean popup_single;
9537 gtk_entry_completion_complete (completion);
9538 matches = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->filter_model), NULL);
9540 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9542 s = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view));
9544 gtk_tree_selection_unselect_all (s);
9546 actions = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->actions), NULL);
9548 g_object_get (completion, "popup-single-match", &popup_single, NULL);
9549 if ((matches > (popup_single ? 0: 1)) || actions > 0)
9551 if (gtk_widget_get_visible (completion->priv->popup_window))
9552 _gtk_entry_completion_resize_popup (completion);
9554 _gtk_entry_completion_popup (completion, completion_entry_priv->completion_device);
9557 _gtk_entry_completion_popdown (completion);
9559 else if (gtk_widget_get_visible (completion->priv->popup_window))
9560 _gtk_entry_completion_popdown (completion);
9565 static inline gboolean
9566 keyval_is_cursor_move (guint keyval)
9568 if (keyval == GDK_KEY_Up || keyval == GDK_KEY_KP_Up)
9571 if (keyval == GDK_KEY_Down || keyval == GDK_KEY_KP_Down)
9574 if (keyval == GDK_KEY_Page_Up)
9577 if (keyval == GDK_KEY_Page_Down)
9584 gtk_entry_completion_key_press (GtkWidget *widget,
9588 gint matches, actions = 0;
9589 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
9591 if (!gtk_widget_get_mapped (completion->priv->popup_window))
9594 matches = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->filter_model), NULL);
9596 if (completion->priv->actions)
9597 actions = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->actions), NULL);
9599 if (keyval_is_cursor_move (event->keyval))
9601 GtkTreePath *path = NULL;
9603 if (event->keyval == GDK_KEY_Up || event->keyval == GDK_KEY_KP_Up)
9605 if (completion->priv->current_selected < 0)
9606 completion->priv->current_selected = matches + actions - 1;
9608 completion->priv->current_selected--;
9610 else if (event->keyval == GDK_KEY_Down || event->keyval == GDK_KEY_KP_Down)
9612 if (completion->priv->current_selected < matches + actions - 1)
9613 completion->priv->current_selected++;
9615 completion->priv->current_selected = -1;
9617 else if (event->keyval == GDK_KEY_Page_Up)
9619 if (completion->priv->current_selected < 0)
9620 completion->priv->current_selected = matches + actions - 1;
9621 else if (completion->priv->current_selected == 0)
9622 completion->priv->current_selected = -1;
9623 else if (completion->priv->current_selected < matches)
9625 completion->priv->current_selected -= PAGE_STEP;
9626 if (completion->priv->current_selected < 0)
9627 completion->priv->current_selected = 0;
9631 completion->priv->current_selected -= PAGE_STEP;
9632 if (completion->priv->current_selected < matches - 1)
9633 completion->priv->current_selected = matches - 1;
9636 else if (event->keyval == GDK_KEY_Page_Down)
9638 if (completion->priv->current_selected < 0)
9639 completion->priv->current_selected = 0;
9640 else if (completion->priv->current_selected < matches - 1)
9642 completion->priv->current_selected += PAGE_STEP;
9643 if (completion->priv->current_selected > matches - 1)
9644 completion->priv->current_selected = matches - 1;
9646 else if (completion->priv->current_selected == matches + actions - 1)
9648 completion->priv->current_selected = -1;
9652 completion->priv->current_selected += PAGE_STEP;
9653 if (completion->priv->current_selected > matches + actions - 1)
9654 completion->priv->current_selected = matches + actions - 1;
9658 if (completion->priv->current_selected < 0)
9660 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9661 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view)));
9663 if (completion->priv->inline_selection &&
9664 completion->priv->completion_prefix)
9666 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9667 completion->priv->completion_prefix);
9668 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9671 else if (completion->priv->current_selected < matches)
9673 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view)));
9675 path = gtk_tree_path_new_from_indices (completion->priv->current_selected, -1);
9676 gtk_tree_view_set_cursor (GTK_TREE_VIEW (completion->priv->tree_view),
9679 if (completion->priv->inline_selection)
9683 GtkTreeIter child_iter;
9684 GtkTreeModel *model = NULL;
9685 GtkTreeSelection *sel;
9688 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view));
9689 if (!gtk_tree_selection_get_selected (sel, &model, &iter))
9692 gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (model), &child_iter, &iter);
9693 model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model));
9695 if (completion->priv->completion_prefix == NULL)
9696 completion->priv->completion_prefix = g_strdup (gtk_entry_get_text (GTK_ENTRY (completion->priv->entry)));
9698 g_signal_emit_by_name (completion, "cursor-on-match", model,
9699 &child_iter, &entry_set);
9702 else if (completion->priv->current_selected - matches >= 0)
9704 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9706 path = gtk_tree_path_new_from_indices (completion->priv->current_selected - matches, -1);
9707 gtk_tree_view_set_cursor (GTK_TREE_VIEW (completion->priv->action_view),
9710 if (completion->priv->inline_selection &&
9711 completion->priv->completion_prefix)
9713 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9714 completion->priv->completion_prefix);
9715 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9719 gtk_tree_path_free (path);
9723 else if (event->keyval == GDK_KEY_Escape ||
9724 event->keyval == GDK_KEY_Left ||
9725 event->keyval == GDK_KEY_KP_Left ||
9726 event->keyval == GDK_KEY_Right ||
9727 event->keyval == GDK_KEY_KP_Right)
9729 gboolean retval = TRUE;
9731 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9732 _gtk_entry_completion_popdown (completion);
9734 if (completion->priv->current_selected < 0)
9737 goto keypress_completion_out;
9739 else if (completion->priv->inline_selection)
9741 /* Escape rejects the tentative completion */
9742 if (event->keyval == GDK_KEY_Escape)
9744 if (completion->priv->completion_prefix)
9745 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9746 completion->priv->completion_prefix);
9748 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry), "");
9751 /* Move the cursor to the end for Right/Esc, to the
9752 beginning for Left */
9753 if (event->keyval == GDK_KEY_Right ||
9754 event->keyval == GDK_KEY_KP_Right ||
9755 event->keyval == GDK_KEY_Escape)
9756 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9758 gtk_editable_set_position (GTK_EDITABLE (widget), 0);
9761 keypress_completion_out:
9762 if (completion->priv->inline_selection)
9764 g_free (completion->priv->completion_prefix);
9765 completion->priv->completion_prefix = NULL;
9770 else if (event->keyval == GDK_KEY_Tab ||
9771 event->keyval == GDK_KEY_KP_Tab ||
9772 event->keyval == GDK_KEY_ISO_Left_Tab)
9774 GtkDirectionType dir = event->keyval == GDK_KEY_ISO_Left_Tab ?
9775 GTK_DIR_TAB_BACKWARD : GTK_DIR_TAB_FORWARD;
9777 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9778 _gtk_entry_completion_popdown (completion);
9780 g_free (completion->priv->completion_prefix);
9781 completion->priv->completion_prefix = NULL;
9783 gtk_widget_child_focus (gtk_widget_get_toplevel (widget), dir);
9787 else if (event->keyval == GDK_KEY_ISO_Enter ||
9788 event->keyval == GDK_KEY_KP_Enter ||
9789 event->keyval == GDK_KEY_Return)
9792 GtkTreeModel *model = NULL;
9793 GtkTreeModel *child_model;
9794 GtkTreeIter child_iter;
9795 GtkTreeSelection *sel;
9796 gboolean retval = TRUE;
9798 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9799 _gtk_entry_completion_popdown (completion);
9801 if (completion->priv->current_selected < matches)
9805 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view));
9806 if (gtk_tree_selection_get_selected (sel, &model, &iter))
9808 gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (model), &child_iter, &iter);
9809 child_model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model));
9810 g_signal_handler_block (widget, completion->priv->changed_id);
9811 g_signal_emit_by_name (completion, "match-selected",
9812 child_model, &child_iter, &entry_set);
9813 g_signal_handler_unblock (widget, completion->priv->changed_id);
9819 gtk_tree_model_get (model, &iter,
9820 completion->priv->text_column, &str,
9823 gtk_entry_set_text (GTK_ENTRY (widget), str);
9825 /* move the cursor to the end */
9826 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9834 else if (completion->priv->current_selected - matches >= 0)
9836 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view));
9837 if (gtk_tree_selection_get_selected (sel, &model, &iter))
9841 path = gtk_tree_path_new_from_indices (completion->priv->current_selected - matches, -1);
9842 g_signal_emit_by_name (completion, "action-activated",
9843 gtk_tree_path_get_indices (path)[0]);
9844 gtk_tree_path_free (path);
9850 g_free (completion->priv->completion_prefix);
9851 completion->priv->completion_prefix = NULL;
9860 gtk_entry_completion_changed (GtkWidget *widget,
9863 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
9864 GtkEntry *entry = GTK_ENTRY (widget);
9865 GtkEntryPrivate *priv = entry->priv;
9868 /* (re)install completion timeout */
9869 if (completion->priv->completion_timeout)
9870 g_source_remove (completion->priv->completion_timeout);
9872 if (!gtk_entry_get_text (entry))
9875 /* no need to normalize for this test */
9876 if (completion->priv->minimum_key_length > 0 &&
9877 strcmp ("", gtk_entry_get_text (entry)) == 0)
9879 if (gtk_widget_get_visible (completion->priv->popup_window))
9880 _gtk_entry_completion_popdown (completion);
9884 device = gtk_get_current_event_device ();
9886 if (device && gdk_device_get_source (device) == GDK_SOURCE_KEYBOARD)
9887 device = gdk_device_get_associated_device (device);
9890 priv->completion_device = device;
9892 completion->priv->completion_timeout =
9893 gdk_threads_add_timeout (COMPLETION_TIMEOUT,
9894 gtk_entry_completion_timeout,
9899 check_completion_callback (GtkEntryCompletion *completion)
9901 completion->priv->check_completion_idle = NULL;
9903 gtk_entry_completion_complete (completion);
9904 gtk_entry_completion_insert_prefix (completion);
9910 clear_completion_callback (GtkEntry *entry,
9913 if (pspec->name == I_("cursor-position") ||
9914 pspec->name == I_("selection-bound"))
9916 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
9918 completion->priv->has_completion = FALSE;
9923 accept_completion_callback (GtkEntry *entry)
9925 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
9927 if (completion->priv->has_completion)
9928 gtk_editable_set_position (GTK_EDITABLE (entry),
9929 gtk_entry_buffer_get_length (get_buffer (entry)));
9935 completion_insert_text_callback (GtkEntry *entry,
9939 GtkEntryCompletion *completion)
9941 /* idle to update the selection based on the file list */
9942 if (completion->priv->check_completion_idle == NULL)
9944 completion->priv->check_completion_idle = g_idle_source_new ();
9945 g_source_set_priority (completion->priv->check_completion_idle, G_PRIORITY_HIGH);
9946 g_source_set_closure (completion->priv->check_completion_idle,
9947 g_cclosure_new_object (G_CALLBACK (check_completion_callback),
9948 G_OBJECT (completion)));
9949 g_source_attach (completion->priv->check_completion_idle, NULL);
9954 completion_changed (GtkEntryCompletion *completion,
9958 GtkEntry *entry = GTK_ENTRY (data);
9960 if (pspec->name == I_("popup-completion") ||
9961 pspec->name == I_("inline-completion"))
9963 disconnect_completion_signals (entry, completion);
9964 connect_completion_signals (entry, completion);
9969 disconnect_completion_signals (GtkEntry *entry,
9970 GtkEntryCompletion *completion)
9972 g_signal_handlers_disconnect_by_func (completion,
9973 G_CALLBACK (completion_changed), entry);
9974 if (completion->priv->changed_id > 0 &&
9975 g_signal_handler_is_connected (entry, completion->priv->changed_id))
9977 g_signal_handler_disconnect (entry, completion->priv->changed_id);
9978 completion->priv->changed_id = 0;
9980 g_signal_handlers_disconnect_by_func (entry,
9981 G_CALLBACK (gtk_entry_completion_key_press), completion);
9982 if (completion->priv->insert_text_id > 0 &&
9983 g_signal_handler_is_connected (entry, completion->priv->insert_text_id))
9985 g_signal_handler_disconnect (entry, completion->priv->insert_text_id);
9986 completion->priv->insert_text_id = 0;
9988 g_signal_handlers_disconnect_by_func (entry,
9989 G_CALLBACK (completion_insert_text_callback), completion);
9990 g_signal_handlers_disconnect_by_func (entry,
9991 G_CALLBACK (clear_completion_callback), completion);
9992 g_signal_handlers_disconnect_by_func (entry,
9993 G_CALLBACK (accept_completion_callback), completion);
9997 connect_completion_signals (GtkEntry *entry,
9998 GtkEntryCompletion *completion)
10000 if (completion->priv->popup_completion)
10002 completion->priv->changed_id =
10003 g_signal_connect (entry, "changed",
10004 G_CALLBACK (gtk_entry_completion_changed), completion);
10005 g_signal_connect (entry, "key-press-event",
10006 G_CALLBACK (gtk_entry_completion_key_press), completion);
10009 if (completion->priv->inline_completion)
10011 completion->priv->insert_text_id =
10012 g_signal_connect (entry, "insert-text",
10013 G_CALLBACK (completion_insert_text_callback), completion);
10014 g_signal_connect (entry, "notify",
10015 G_CALLBACK (clear_completion_callback), completion);
10016 g_signal_connect (entry, "activate",
10017 G_CALLBACK (accept_completion_callback), completion);
10018 g_signal_connect (entry, "focus-out-event",
10019 G_CALLBACK (accept_completion_callback), completion);
10022 g_signal_connect (completion, "notify",
10023 G_CALLBACK (completion_changed), entry);
10027 * gtk_entry_set_completion:
10028 * @entry: A #GtkEntry
10029 * @completion: (allow-none): The #GtkEntryCompletion or %NULL
10031 * Sets @completion to be the auxiliary completion object to use with @entry.
10032 * All further configuration of the completion mechanism is done on
10033 * @completion using the #GtkEntryCompletion API. Completion is disabled if
10034 * @completion is set to %NULL.
10039 gtk_entry_set_completion (GtkEntry *entry,
10040 GtkEntryCompletion *completion)
10042 GtkEntryCompletion *old;
10044 g_return_if_fail (GTK_IS_ENTRY (entry));
10045 g_return_if_fail (!completion || GTK_IS_ENTRY_COMPLETION (completion));
10047 old = gtk_entry_get_completion (entry);
10049 if (old == completion)
10054 if (old->priv->completion_timeout)
10056 g_source_remove (old->priv->completion_timeout);
10057 old->priv->completion_timeout = 0;
10060 if (old->priv->check_completion_idle)
10062 g_source_destroy (old->priv->check_completion_idle);
10063 old->priv->check_completion_idle = NULL;
10066 if (gtk_widget_get_mapped (old->priv->popup_window))
10067 _gtk_entry_completion_popdown (old);
10069 disconnect_completion_signals (entry, old);
10070 old->priv->entry = NULL;
10072 g_object_unref (old);
10077 g_object_set_data (G_OBJECT (entry), I_(GTK_ENTRY_COMPLETION_KEY), NULL);
10081 /* hook into the entry */
10082 g_object_ref (completion);
10084 connect_completion_signals (entry, completion);
10085 completion->priv->entry = GTK_WIDGET (entry);
10086 g_object_set_data (G_OBJECT (entry), I_(GTK_ENTRY_COMPLETION_KEY), completion);
10088 g_object_notify (G_OBJECT (entry), "completion");
10092 * gtk_entry_get_completion:
10093 * @entry: A #GtkEntry
10095 * Returns the auxiliary completion object currently in use by @entry.
10097 * Return value: (transfer none): The auxiliary completion object currently
10098 * in use by @entry.
10102 GtkEntryCompletion *
10103 gtk_entry_get_completion (GtkEntry *entry)
10105 GtkEntryCompletion *completion;
10107 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
10109 completion = GTK_ENTRY_COMPLETION (g_object_get_data (G_OBJECT (entry),
10110 GTK_ENTRY_COMPLETION_KEY));
10116 * gtk_entry_set_cursor_hadjustment:
10117 * @entry: a #GtkEntry
10118 * @adjustment: an adjustment which should be adjusted when the cursor
10119 * is moved, or %NULL
10121 * Hooks up an adjustment to the cursor position in an entry, so that when
10122 * the cursor is moved, the adjustment is scrolled to show that position.
10123 * See gtk_scrolled_window_get_hadjustment() for a typical way of obtaining
10126 * The adjustment has to be in pixel units and in the same coordinate system
10132 gtk_entry_set_cursor_hadjustment (GtkEntry *entry,
10133 GtkAdjustment *adjustment)
10135 g_return_if_fail (GTK_IS_ENTRY (entry));
10137 g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
10140 g_object_ref (adjustment);
10142 g_object_set_qdata_full (G_OBJECT (entry),
10143 quark_cursor_hadjustment,
10149 * gtk_entry_get_cursor_hadjustment:
10150 * @entry: a #GtkEntry
10152 * Retrieves the horizontal cursor adjustment for the entry.
10153 * See gtk_entry_set_cursor_hadjustment().
10155 * Return value: (transfer none): the horizontal cursor adjustment, or %NULL
10156 * if none has been set.
10161 gtk_entry_get_cursor_hadjustment (GtkEntry *entry)
10163 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
10165 return g_object_get_qdata (G_OBJECT (entry), quark_cursor_hadjustment);
10169 * gtk_entry_set_progress_fraction:
10170 * @entry: a #GtkEntry
10171 * @fraction: fraction of the task that's been completed
10173 * Causes the entry's progress indicator to "fill in" the given
10174 * fraction of the bar. The fraction should be between 0.0 and 1.0,
10180 gtk_entry_set_progress_fraction (GtkEntry *entry,
10184 GtkEntryPrivate *private;
10185 gdouble old_fraction;
10186 gint x, y, width, height;
10187 gint old_x, old_y, old_width, old_height;
10189 g_return_if_fail (GTK_IS_ENTRY (entry));
10191 widget = GTK_WIDGET (entry);
10192 private = entry->priv;
10194 if (private->progress_pulse_mode)
10197 old_fraction = private->progress_fraction;
10199 if (gtk_widget_is_drawable (widget))
10200 get_progress_area (widget, &old_x, &old_y, &old_width, &old_height);
10202 fraction = CLAMP (fraction, 0.0, 1.0);
10204 private->progress_fraction = fraction;
10205 private->progress_pulse_mode = FALSE;
10206 private->progress_pulse_current = 0.0;
10208 if (gtk_widget_is_drawable (widget))
10210 get_progress_area (widget, &x, &y, &width, &height);
10212 if ((x != old_x) || (y != old_y) || (width != old_width) || (height != old_height))
10213 gtk_widget_queue_draw (widget);
10216 if (fraction != old_fraction)
10217 g_object_notify (G_OBJECT (entry), "progress-fraction");
10221 * gtk_entry_get_progress_fraction:
10222 * @entry: a #GtkEntry
10224 * Returns the current fraction of the task that's been completed.
10225 * See gtk_entry_set_progress_fraction().
10227 * Return value: a fraction from 0.0 to 1.0
10232 gtk_entry_get_progress_fraction (GtkEntry *entry)
10234 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
10236 return entry->priv->progress_fraction;
10240 * gtk_entry_set_progress_pulse_step:
10241 * @entry: a #GtkEntry
10242 * @fraction: fraction between 0.0 and 1.0
10244 * Sets the fraction of total entry width to move the progress
10245 * bouncing block for each call to gtk_entry_progress_pulse().
10250 gtk_entry_set_progress_pulse_step (GtkEntry *entry,
10253 GtkEntryPrivate *private;
10255 g_return_if_fail (GTK_IS_ENTRY (entry));
10257 private = entry->priv;
10259 fraction = CLAMP (fraction, 0.0, 1.0);
10261 if (fraction != private->progress_pulse_fraction)
10263 private->progress_pulse_fraction = fraction;
10265 gtk_widget_queue_draw (GTK_WIDGET (entry));
10267 g_object_notify (G_OBJECT (entry), "progress-pulse-step");
10272 * gtk_entry_get_progress_pulse_step:
10273 * @entry: a #GtkEntry
10275 * Retrieves the pulse step set with gtk_entry_set_progress_pulse_step().
10277 * Return value: a fraction from 0.0 to 1.0
10282 gtk_entry_get_progress_pulse_step (GtkEntry *entry)
10284 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
10286 return entry->priv->progress_pulse_fraction;
10290 * gtk_entry_progress_pulse:
10291 * @entry: a #GtkEntry
10293 * Indicates that some progress is made, but you don't know how much.
10294 * Causes the entry's progress indicator to enter "activity mode,"
10295 * where a block bounces back and forth. Each call to
10296 * gtk_entry_progress_pulse() causes the block to move by a little bit
10297 * (the amount of movement per pulse is determined by
10298 * gtk_entry_set_progress_pulse_step()).
10303 gtk_entry_progress_pulse (GtkEntry *entry)
10305 GtkEntryPrivate *private;
10307 g_return_if_fail (GTK_IS_ENTRY (entry));
10309 private = entry->priv;
10311 if (private->progress_pulse_mode)
10313 if (private->progress_pulse_way_back)
10315 private->progress_pulse_current -= private->progress_pulse_fraction;
10317 if (private->progress_pulse_current < 0.0)
10319 private->progress_pulse_current = 0.0;
10320 private->progress_pulse_way_back = FALSE;
10325 private->progress_pulse_current += private->progress_pulse_fraction;
10327 if (private->progress_pulse_current > 1.0 - private->progress_pulse_fraction)
10329 private->progress_pulse_current = 1.0 - private->progress_pulse_fraction;
10330 private->progress_pulse_way_back = TRUE;
10336 private->progress_fraction = 0.0;
10337 private->progress_pulse_mode = TRUE;
10338 private->progress_pulse_way_back = FALSE;
10339 private->progress_pulse_current = 0.0;
10342 gtk_widget_queue_draw (GTK_WIDGET (entry));
10346 * gtk_entry_set_placeholder_text:
10347 * @entry: a #GtkEntry
10348 * @text: a string to be displayed when @entry is empty an unfocused, or %NULL
10350 * Sets text to be displayed in @entry when it is empty and unfocused.
10351 * This can be used to give a visual hint of the expected contents of
10354 * Note that since the placeholder text gets removed when the entry
10355 * received focus, using this feature is a bit problematic if the entry
10356 * is given the initial focus in a window. Sometimes this can be
10357 * worked around by delaying the initial focus setting until the
10358 * first key event arrives.
10363 gtk_entry_set_placeholder_text (GtkEntry *entry,
10366 GtkEntryPrivate *priv;
10368 g_return_if_fail (GTK_IS_ENTRY (entry));
10370 priv = entry->priv;
10372 if (g_strcmp0 (priv->placeholder_text, text) == 0)
10375 g_free (priv->placeholder_text);
10376 priv->placeholder_text = g_strdup (text);
10378 gtk_entry_recompute (entry);
10380 g_object_notify (G_OBJECT (entry), "placeholder-text");
10384 * gtk_entry_get_placeholder_text:
10385 * @entry: a #GtkEntry
10387 * Retrieves the text that will be displayed when @entry is empty and unfocused
10389 * Returns: a pointer to the placeholder text as a string. This string points to internally allocated
10390 * storage in the widget and must not be freed, modified or stored.
10395 gtk_entry_get_placeholder_text (GtkEntry *entry)
10397 GtkEntryPrivate *priv;
10399 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
10401 priv = entry->priv;
10403 return priv->placeholder_text;
10406 /* Caps Lock warning for password entries */
10409 show_capslock_feedback (GtkEntry *entry,
10412 GtkEntryPrivate *priv = entry->priv;
10414 if (gtk_entry_get_icon_storage_type (entry, GTK_ENTRY_ICON_SECONDARY) == GTK_IMAGE_EMPTY)
10416 gtk_entry_set_icon_from_stock (entry, GTK_ENTRY_ICON_SECONDARY, GTK_STOCK_CAPS_LOCK_WARNING);
10417 gtk_entry_set_icon_activatable (entry, GTK_ENTRY_ICON_SECONDARY, FALSE);
10418 priv->caps_lock_warning_shown = TRUE;
10421 if (priv->caps_lock_warning_shown)
10422 gtk_entry_set_icon_tooltip_text (entry, GTK_ENTRY_ICON_SECONDARY, text);
10424 g_warning ("Can't show Caps Lock warning, since secondary icon is set");
10428 remove_capslock_feedback (GtkEntry *entry)
10430 GtkEntryPrivate *priv = entry->priv;
10432 if (priv->caps_lock_warning_shown)
10434 gtk_entry_set_icon_from_stock (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
10435 priv->caps_lock_warning_shown = FALSE;
10440 keymap_state_changed (GdkKeymap *keymap,
10443 GtkEntryPrivate *priv = entry->priv;
10446 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL && priv->caps_lock_warning)
10448 if (gdk_keymap_get_num_lock_state (keymap)
10449 && gdk_keymap_get_caps_lock_state (keymap))
10450 text = _("Caps Lock and Num Lock are on");
10451 else if (gdk_keymap_get_num_lock_state (keymap))
10452 text = _("Num Lock is on");
10453 else if (gdk_keymap_get_caps_lock_state (keymap))
10454 text = _("Caps Lock is on");
10458 show_capslock_feedback (entry, text);
10460 remove_capslock_feedback (entry);
10464 * _gtk_entry_set_is_cell_renderer:
10465 * @entry: a #GtkEntry
10466 * @is_cell_renderer: new value
10468 * This is a helper function for GtkComboBox. A GtkEntry in a GtkComboBox
10469 * is supposed to behave like a GtkCellEditable when placed in a combo box.
10471 * I.e take up its allocation and get GtkEntry->is_cell_renderer = TRUE.
10475 _gtk_entry_set_is_cell_renderer (GtkEntry *entry,
10476 gboolean is_cell_renderer)
10478 entry->priv->is_cell_renderer = is_cell_renderer;