1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* GTK - The GIMP Toolkit
3 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * Copyright (C) 2004-2006 Christian Hammond
5 * Copyright (C) 2008 Cody Russell
6 * Copyright (C) 2008 Red Hat, Inc.
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
25 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
26 * file for a list of people on the GTK+ Team. See the ChangeLog
27 * files for a list of changes. These files are distributed with
28 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
36 #include "gtkbindings.h"
37 #include "gtkcelleditable.h"
38 #include "gtkclipboard.h"
41 #include "gtkentrybuffer.h"
42 #include "gtkimagemenuitem.h"
43 #include "gtkimcontextsimple.h"
44 #include "gtkimmulticontext.h"
48 #include "gtkmarshalers.h"
50 #include "gtkmenuitem.h"
51 #include "gtkseparatormenuitem.h"
52 #include "gtkselection.h"
53 #include "gtksettings.h"
54 #include "gtkspinbutton.h"
56 #include "gtktextutil.h"
57 #include "gtkwindow.h"
58 #include "gtktreeview.h"
59 #include "gtktreeselection.h"
60 #include "gtktypebuiltins.h"
61 #include "gtkprivate.h"
62 #include "gtkentryprivate.h"
63 #include "gtkcelllayout.h"
64 #include "gtktooltip.h"
65 #include "gtkiconfactory.h"
66 #include "gtkicontheme.h"
67 #include "gtkwidgetprivate.h"
68 #include "gtkstylecontextprivate.h"
70 #include "a11y/gtkentryaccessible.h"
74 * @Short_description: A single line text entry field
76 * @See_also: #GtkTextView, #GtkEntryCompletion
78 * The #GtkEntry widget is a single line text entry
79 * widget. A fairly large set of key bindings are supported
80 * by default. If the entered text is longer than the allocation
81 * of the widget, the widget will scroll so that the cursor
82 * position is visible.
84 * When using an entry for passwords and other sensitive information,
85 * it can be put into "password mode" using gtk_entry_set_visibility().
86 * In this mode, entered text is displayed using a 'invisible' character.
87 * By default, GTK+ picks the best invisible character that is available
88 * in the current font, but it can be changed with
89 * gtk_entry_set_invisible_char(). Since 2.16, GTK+ displays a warning
90 * when Caps Lock or input methods might interfere with entering text in
91 * a password entry. The warning can be turned off with the
92 * #GtkEntry:caps-lock-warning property.
94 * Since 2.16, GtkEntry has the ability to display progress or activity
95 * information behind the text. To make an entry display such information,
96 * use gtk_entry_set_progress_fraction() or gtk_entry_set_progress_pulse_step().
98 * Additionally, GtkEntry can show icons at either side of the entry. These
99 * icons can be activatable by clicking, can be set up as drag source and
100 * can have tooltips. To add an icon, use gtk_entry_set_icon_from_gicon() or
101 * one of the various other functions that set an icon from a stock id, an
102 * icon name or a pixbuf. To trigger an action when the user clicks an icon,
103 * connect to the #GtkEntry::icon-press signal. To allow DND operations
104 * from an icon, use gtk_entry_set_icon_drag_source(). To set a tooltip on
105 * an icon, use gtk_entry_set_icon_tooltip_text() or the corresponding function
108 * Note that functionality or information that is only available by clicking
109 * on an icon in an entry may not be accessible at all to users which are not
110 * able to use a mouse or other pointing device. It is therefore recommended
111 * that any such functionality should also be available by other means, e.g.
112 * via the context menu of the entry.
116 #define GTK_ENTRY_COMPLETION_KEY "gtk-entry-completion-key"
118 #define MIN_ENTRY_WIDTH 150
119 #define DRAW_TIMEOUT 20
120 #define COMPLETION_TIMEOUT 300
121 #define PASSWORD_HINT_MAX 8
126 #define IS_VALID_ICON_POSITION(pos) \
127 ((pos) == GTK_ENTRY_ICON_PRIMARY || \
128 (pos) == GTK_ENTRY_ICON_SECONDARY)
130 static const GtkBorder default_inner_border = { 2, 2, 2, 2 };
131 static GQuark quark_inner_border = 0;
132 static GQuark quark_password_hint = 0;
133 static GQuark quark_cursor_hadjustment = 0;
134 static GQuark quark_capslock_feedback = 0;
136 typedef struct _EntryIconInfo EntryIconInfo;
137 typedef struct _GtkEntryPasswordHint GtkEntryPasswordHint;
138 typedef struct _GtkEntryCapslockFeedback GtkEntryCapslockFeedback;
140 struct _GtkEntryPrivate
142 EntryIconInfo *icons[MAX_ICONS];
144 GtkEntryBuffer *buffer;
145 GtkIMContext *im_context;
146 GtkShadowType shadow_type;
147 GtkWidget *popup_menu;
149 GdkDevice *completion_device;
150 GdkWindow *text_area;
152 PangoLayout *cached_layout;
156 gdouble progress_fraction;
157 gdouble progress_pulse_fraction;
158 gdouble progress_pulse_current;
160 gchar *placeholder_text;
164 gint ascent; /* font ascent in pango units */
166 gint descent; /* font descent in pango units */
167 gint dnd_position; /* In chars, -1 == no DND cursor */
173 gint selection_bound;
179 gunichar invisible_char;
182 guint blink_time; /* time in msec the cursor has blinked since last user event */
184 guint recompute_idle;
186 guint16 x_text_size; /* allocated size, in bytes */
187 guint16 x_n_bytes; /* length in use, in bytes */
189 guint16 preedit_length; /* length of preedit string, in bytes */
190 guint16 preedit_cursor; /* offset of cursor within preedit string, in chars */
194 guint overwrite_mode : 1;
197 guint activates_default : 1;
198 guint cache_includes_preedit : 1;
199 guint caps_lock_warning : 1;
200 guint caps_lock_warning_shown : 1;
201 guint change_count : 8;
202 guint cursor_visible : 1;
203 guint editing_canceled : 1; /* Only used by GtkCellRendererText */
205 guint in_click : 1; /* Flag so we don't select all when clicking in entry to focus in */
206 guint is_cell_renderer : 1;
207 guint invisible_char_set : 1;
208 guint interior_focus : 1;
209 guint mouse_cursor_obscured : 1;
210 guint need_im_reset : 1;
211 guint progress_pulse_mode : 1;
212 guint progress_pulse_way_back : 1;
213 guint real_changed : 1;
214 guint resolved_dir : 4; /* PangoDirection */
215 guint select_words : 1;
216 guint select_lines : 1;
217 guint truncate_multiline : 1;
220 struct _EntryIconInfo
224 guint insensitive : 1;
225 guint nonactivatable : 1;
230 GtkImageType storage_type;
236 GtkStateFlags last_state;
238 GtkTargetList *target_list;
239 GdkDragAction actions;
242 struct _GtkEntryPasswordHint
244 gint position; /* Position (in text) of the last password hint */
245 guint source_id; /* Timeout source id */
248 struct _GtkEntryCapslockFeedback
275 PROP_CURSOR_POSITION,
276 PROP_SELECTION_BOUND,
283 PROP_ACTIVATES_DEFAULT,
288 PROP_TRUNCATE_MULTILINE,
292 PROP_INVISIBLE_CHAR_SET,
293 PROP_CAPS_LOCK_WARNING,
294 PROP_PROGRESS_FRACTION,
295 PROP_PROGRESS_PULSE_STEP,
297 PROP_PIXBUF_SECONDARY,
299 PROP_STOCK_SECONDARY,
300 PROP_ICON_NAME_PRIMARY,
301 PROP_ICON_NAME_SECONDARY,
303 PROP_GICON_SECONDARY,
304 PROP_STORAGE_TYPE_PRIMARY,
305 PROP_STORAGE_TYPE_SECONDARY,
306 PROP_ACTIVATABLE_PRIMARY,
307 PROP_ACTIVATABLE_SECONDARY,
308 PROP_SENSITIVE_PRIMARY,
309 PROP_SENSITIVE_SECONDARY,
310 PROP_TOOLTIP_TEXT_PRIMARY,
311 PROP_TOOLTIP_TEXT_SECONDARY,
312 PROP_TOOLTIP_MARKUP_PRIMARY,
313 PROP_TOOLTIP_MARKUP_SECONDARY,
315 PROP_EDITING_CANCELED,
316 PROP_PLACEHOLDER_TEXT,
320 static guint signals[LAST_SIGNAL] = { 0 };
329 DISPLAY_NORMAL, /* The entry text is being shown */
330 DISPLAY_INVISIBLE, /* In invisible mode, text replaced by (eg) bullets */
331 DISPLAY_BLANK /* In invisible mode, nothing shown at all */
336 static void gtk_entry_editable_init (GtkEditableInterface *iface);
337 static void gtk_entry_cell_editable_init (GtkCellEditableIface *iface);
338 static void gtk_entry_set_property (GObject *object,
342 static void gtk_entry_get_property (GObject *object,
346 static void gtk_entry_finalize (GObject *object);
347 static void gtk_entry_dispose (GObject *object);
351 static void gtk_entry_destroy (GtkWidget *widget);
352 static void gtk_entry_realize (GtkWidget *widget);
353 static void gtk_entry_unrealize (GtkWidget *widget);
354 static void gtk_entry_map (GtkWidget *widget);
355 static void gtk_entry_unmap (GtkWidget *widget);
356 static void gtk_entry_get_preferred_width (GtkWidget *widget,
359 static void gtk_entry_get_preferred_height (GtkWidget *widget,
362 static void gtk_entry_size_allocate (GtkWidget *widget,
363 GtkAllocation *allocation);
364 static void gtk_entry_draw_frame (GtkWidget *widget,
365 GtkStyleContext *context,
367 static void gtk_entry_draw_progress (GtkWidget *widget,
368 GtkStyleContext *context,
370 static gint gtk_entry_draw (GtkWidget *widget,
372 static gint gtk_entry_button_press (GtkWidget *widget,
373 GdkEventButton *event);
374 static gint gtk_entry_button_release (GtkWidget *widget,
375 GdkEventButton *event);
376 static gint gtk_entry_enter_notify (GtkWidget *widget,
377 GdkEventCrossing *event);
378 static gint gtk_entry_leave_notify (GtkWidget *widget,
379 GdkEventCrossing *event);
380 static gint gtk_entry_motion_notify (GtkWidget *widget,
381 GdkEventMotion *event);
382 static gint gtk_entry_key_press (GtkWidget *widget,
384 static gint gtk_entry_key_release (GtkWidget *widget,
386 static gint gtk_entry_focus_in (GtkWidget *widget,
387 GdkEventFocus *event);
388 static gint gtk_entry_focus_out (GtkWidget *widget,
389 GdkEventFocus *event);
390 static void gtk_entry_grab_focus (GtkWidget *widget);
391 static void gtk_entry_style_updated (GtkWidget *widget);
392 static gboolean gtk_entry_query_tooltip (GtkWidget *widget,
395 gboolean keyboard_tip,
396 GtkTooltip *tooltip);
397 static void gtk_entry_direction_changed (GtkWidget *widget,
398 GtkTextDirection previous_dir);
399 static void gtk_entry_state_flags_changed (GtkWidget *widget,
400 GtkStateFlags previous_state);
401 static void gtk_entry_screen_changed (GtkWidget *widget,
402 GdkScreen *old_screen);
404 static gboolean gtk_entry_drag_drop (GtkWidget *widget,
405 GdkDragContext *context,
409 static gboolean gtk_entry_drag_motion (GtkWidget *widget,
410 GdkDragContext *context,
414 static void gtk_entry_drag_leave (GtkWidget *widget,
415 GdkDragContext *context,
417 static void gtk_entry_drag_data_received (GtkWidget *widget,
418 GdkDragContext *context,
421 GtkSelectionData *selection_data,
424 static void gtk_entry_drag_data_get (GtkWidget *widget,
425 GdkDragContext *context,
426 GtkSelectionData *selection_data,
429 static void gtk_entry_drag_data_delete (GtkWidget *widget,
430 GdkDragContext *context);
431 static void gtk_entry_drag_begin (GtkWidget *widget,
432 GdkDragContext *context);
433 static void gtk_entry_drag_end (GtkWidget *widget,
434 GdkDragContext *context);
437 /* GtkEditable method implementations
439 static void gtk_entry_insert_text (GtkEditable *editable,
440 const gchar *new_text,
441 gint new_text_length,
443 static void gtk_entry_delete_text (GtkEditable *editable,
446 static gchar * gtk_entry_get_chars (GtkEditable *editable,
449 static void gtk_entry_real_set_position (GtkEditable *editable,
451 static gint gtk_entry_get_position (GtkEditable *editable);
452 static void gtk_entry_set_selection_bounds (GtkEditable *editable,
455 static gboolean gtk_entry_get_selection_bounds (GtkEditable *editable,
459 /* GtkCellEditable method implementations
461 static void gtk_entry_start_editing (GtkCellEditable *cell_editable,
464 /* Default signal handlers
466 static void gtk_entry_real_insert_text (GtkEditable *editable,
467 const gchar *new_text,
468 gint new_text_length,
470 static void gtk_entry_real_delete_text (GtkEditable *editable,
473 static void gtk_entry_move_cursor (GtkEntry *entry,
474 GtkMovementStep step,
476 gboolean extend_selection);
477 static void gtk_entry_insert_at_cursor (GtkEntry *entry,
479 static void gtk_entry_delete_from_cursor (GtkEntry *entry,
482 static void gtk_entry_backspace (GtkEntry *entry);
483 static void gtk_entry_cut_clipboard (GtkEntry *entry);
484 static void gtk_entry_copy_clipboard (GtkEntry *entry);
485 static void gtk_entry_paste_clipboard (GtkEntry *entry);
486 static void gtk_entry_toggle_overwrite (GtkEntry *entry);
487 static void gtk_entry_select_all (GtkEntry *entry);
488 static void gtk_entry_real_activate (GtkEntry *entry);
489 static gboolean gtk_entry_popup_menu (GtkWidget *widget);
491 static void keymap_direction_changed (GdkKeymap *keymap,
493 static void keymap_state_changed (GdkKeymap *keymap,
495 static void remove_capslock_feedback (GtkEntry *entry);
497 /* IM Context Callbacks
499 static void gtk_entry_commit_cb (GtkIMContext *context,
502 static void gtk_entry_preedit_changed_cb (GtkIMContext *context,
504 static gboolean gtk_entry_retrieve_surrounding_cb (GtkIMContext *context,
506 static gboolean gtk_entry_delete_surrounding_cb (GtkIMContext *context,
513 static void gtk_entry_enter_text (GtkEntry *entry,
515 static void gtk_entry_set_positions (GtkEntry *entry,
517 gint selection_bound);
518 static void gtk_entry_draw_text (GtkEntry *entry,
520 static void gtk_entry_draw_cursor (GtkEntry *entry,
523 static PangoLayout *gtk_entry_ensure_layout (GtkEntry *entry,
524 gboolean include_preedit);
525 static void gtk_entry_reset_layout (GtkEntry *entry);
526 static void gtk_entry_recompute (GtkEntry *entry);
527 static gint gtk_entry_find_position (GtkEntry *entry,
529 static void gtk_entry_get_cursor_locations (GtkEntry *entry,
533 static void gtk_entry_adjust_scroll (GtkEntry *entry);
534 static gint gtk_entry_move_visually (GtkEntry *editable,
537 static gint gtk_entry_move_logically (GtkEntry *entry,
540 static gint gtk_entry_move_forward_word (GtkEntry *entry,
542 gboolean allow_whitespace);
543 static gint gtk_entry_move_backward_word (GtkEntry *entry,
545 gboolean allow_whitespace);
546 static void gtk_entry_delete_whitespace (GtkEntry *entry);
547 static void gtk_entry_select_word (GtkEntry *entry);
548 static void gtk_entry_select_line (GtkEntry *entry);
549 static void gtk_entry_paste (GtkEntry *entry,
551 static void gtk_entry_update_primary_selection (GtkEntry *entry);
552 static void gtk_entry_do_popup (GtkEntry *entry,
553 GdkEventButton *event);
554 static gboolean gtk_entry_mnemonic_activate (GtkWidget *widget,
555 gboolean group_cycling);
556 static void gtk_entry_check_cursor_blink (GtkEntry *entry);
557 static void gtk_entry_pend_cursor_blink (GtkEntry *entry);
558 static void gtk_entry_reset_blink_time (GtkEntry *entry);
559 static void gtk_entry_get_text_area_size (GtkEntry *entry,
564 static void get_text_area_size (GtkEntry *entry,
569 static void get_frame_size (GtkEntry *entry,
570 gboolean relative_to_window,
575 static void gtk_entry_move_adjustments (GtkEntry *entry);
576 static void gtk_entry_ensure_pixbuf (GtkEntry *entry,
577 GtkEntryIconPosition icon_pos);
578 static void gtk_entry_update_cached_style_values(GtkEntry *entry);
581 static gint gtk_entry_completion_timeout (gpointer data);
582 static gboolean gtk_entry_completion_key_press (GtkWidget *widget,
585 static void gtk_entry_completion_changed (GtkWidget *entry,
587 static gboolean check_completion_callback (GtkEntryCompletion *completion);
588 static void clear_completion_callback (GtkEntry *entry,
590 static gboolean accept_completion_callback (GtkEntry *entry);
591 static void completion_insert_text_callback (GtkEntry *entry,
595 GtkEntryCompletion *completion);
596 static void completion_changed (GtkEntryCompletion *completion,
599 static void disconnect_completion_signals (GtkEntry *entry,
600 GtkEntryCompletion *completion);
601 static void connect_completion_signals (GtkEntry *entry,
602 GtkEntryCompletion *completion);
604 static void begin_change (GtkEntry *entry);
605 static void end_change (GtkEntry *entry);
606 static void emit_changed (GtkEntry *entry);
608 static void buffer_inserted_text (GtkEntryBuffer *buffer,
613 static void buffer_deleted_text (GtkEntryBuffer *buffer,
617 static void buffer_notify_text (GtkEntryBuffer *buffer,
620 static void buffer_notify_length (GtkEntryBuffer *buffer,
623 static void buffer_notify_max_length (GtkEntryBuffer *buffer,
626 static void buffer_connect_signals (GtkEntry *entry);
627 static void buffer_disconnect_signals (GtkEntry *entry);
628 static GtkEntryBuffer *get_buffer (GtkEntry *entry);
630 G_DEFINE_TYPE_WITH_CODE (GtkEntry, gtk_entry, GTK_TYPE_WIDGET,
631 G_IMPLEMENT_INTERFACE (GTK_TYPE_EDITABLE,
632 gtk_entry_editable_init)
633 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_EDITABLE,
634 gtk_entry_cell_editable_init))
637 add_move_binding (GtkBindingSet *binding_set,
640 GtkMovementStep step,
643 g_return_if_fail ((modmask & GDK_SHIFT_MASK) == 0);
645 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
649 G_TYPE_BOOLEAN, FALSE);
651 /* Selection-extending version */
652 gtk_binding_entry_add_signal (binding_set, keyval, modmask | GDK_SHIFT_MASK,
656 G_TYPE_BOOLEAN, TRUE);
660 gtk_entry_class_init (GtkEntryClass *class)
662 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
663 GtkWidgetClass *widget_class;
664 GtkBindingSet *binding_set;
666 widget_class = (GtkWidgetClass*) class;
668 gobject_class->dispose = gtk_entry_dispose;
669 gobject_class->finalize = gtk_entry_finalize;
670 gobject_class->set_property = gtk_entry_set_property;
671 gobject_class->get_property = gtk_entry_get_property;
673 widget_class->destroy = gtk_entry_destroy;
674 widget_class->map = gtk_entry_map;
675 widget_class->unmap = gtk_entry_unmap;
676 widget_class->realize = gtk_entry_realize;
677 widget_class->unrealize = gtk_entry_unrealize;
678 widget_class->get_preferred_width = gtk_entry_get_preferred_width;
679 widget_class->get_preferred_height = gtk_entry_get_preferred_height;
680 widget_class->size_allocate = gtk_entry_size_allocate;
681 widget_class->draw = gtk_entry_draw;
682 widget_class->enter_notify_event = gtk_entry_enter_notify;
683 widget_class->leave_notify_event = gtk_entry_leave_notify;
684 widget_class->button_press_event = gtk_entry_button_press;
685 widget_class->button_release_event = gtk_entry_button_release;
686 widget_class->motion_notify_event = gtk_entry_motion_notify;
687 widget_class->key_press_event = gtk_entry_key_press;
688 widget_class->key_release_event = gtk_entry_key_release;
689 widget_class->focus_in_event = gtk_entry_focus_in;
690 widget_class->focus_out_event = gtk_entry_focus_out;
691 widget_class->grab_focus = gtk_entry_grab_focus;
692 widget_class->style_updated = gtk_entry_style_updated;
693 widget_class->query_tooltip = gtk_entry_query_tooltip;
694 widget_class->drag_begin = gtk_entry_drag_begin;
695 widget_class->drag_end = gtk_entry_drag_end;
696 widget_class->direction_changed = gtk_entry_direction_changed;
697 widget_class->state_flags_changed = gtk_entry_state_flags_changed;
698 widget_class->screen_changed = gtk_entry_screen_changed;
699 widget_class->mnemonic_activate = gtk_entry_mnemonic_activate;
701 widget_class->drag_drop = gtk_entry_drag_drop;
702 widget_class->drag_motion = gtk_entry_drag_motion;
703 widget_class->drag_leave = gtk_entry_drag_leave;
704 widget_class->drag_data_received = gtk_entry_drag_data_received;
705 widget_class->drag_data_get = gtk_entry_drag_data_get;
706 widget_class->drag_data_delete = gtk_entry_drag_data_delete;
708 widget_class->popup_menu = gtk_entry_popup_menu;
710 class->move_cursor = gtk_entry_move_cursor;
711 class->insert_at_cursor = gtk_entry_insert_at_cursor;
712 class->delete_from_cursor = gtk_entry_delete_from_cursor;
713 class->backspace = gtk_entry_backspace;
714 class->cut_clipboard = gtk_entry_cut_clipboard;
715 class->copy_clipboard = gtk_entry_copy_clipboard;
716 class->paste_clipboard = gtk_entry_paste_clipboard;
717 class->toggle_overwrite = gtk_entry_toggle_overwrite;
718 class->activate = gtk_entry_real_activate;
719 class->get_text_area_size = gtk_entry_get_text_area_size;
721 quark_inner_border = g_quark_from_static_string ("gtk-entry-inner-border");
722 quark_password_hint = g_quark_from_static_string ("gtk-entry-password-hint");
723 quark_cursor_hadjustment = g_quark_from_static_string ("gtk-hadjustment");
724 quark_capslock_feedback = g_quark_from_static_string ("gtk-entry-capslock-feedback");
726 g_object_class_override_property (gobject_class,
727 PROP_EDITING_CANCELED,
730 g_object_class_install_property (gobject_class,
732 g_param_spec_object ("buffer",
734 P_("Text buffer object which actually stores entry text"),
735 GTK_TYPE_ENTRY_BUFFER,
736 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT));
738 g_object_class_install_property (gobject_class,
739 PROP_CURSOR_POSITION,
740 g_param_spec_int ("cursor-position",
741 P_("Cursor Position"),
742 P_("The current position of the insertion cursor in chars"),
744 GTK_ENTRY_BUFFER_MAX_SIZE,
746 GTK_PARAM_READABLE));
748 g_object_class_install_property (gobject_class,
749 PROP_SELECTION_BOUND,
750 g_param_spec_int ("selection-bound",
751 P_("Selection Bound"),
752 P_("The position of the opposite end of the selection from the cursor in chars"),
754 GTK_ENTRY_BUFFER_MAX_SIZE,
756 GTK_PARAM_READABLE));
758 g_object_class_install_property (gobject_class,
760 g_param_spec_boolean ("editable",
762 P_("Whether the entry contents can be edited"),
764 GTK_PARAM_READWRITE));
766 g_object_class_install_property (gobject_class,
768 g_param_spec_int ("max-length",
769 P_("Maximum length"),
770 P_("Maximum number of characters for this entry. Zero if no maximum"),
772 GTK_ENTRY_BUFFER_MAX_SIZE,
774 GTK_PARAM_READWRITE));
775 g_object_class_install_property (gobject_class,
777 g_param_spec_boolean ("visibility",
779 P_("FALSE displays the \"invisible char\" instead of the actual text (password mode)"),
781 GTK_PARAM_READWRITE));
783 g_object_class_install_property (gobject_class,
785 g_param_spec_boolean ("has-frame",
787 P_("FALSE removes outside bevel from entry"),
789 GTK_PARAM_READWRITE));
791 g_object_class_install_property (gobject_class,
793 g_param_spec_boxed ("inner-border",
795 P_("Border between text and frame. Overrides the inner-border style property"),
797 GTK_PARAM_READWRITE));
799 g_object_class_install_property (gobject_class,
801 g_param_spec_unichar ("invisible-char",
802 P_("Invisible character"),
803 P_("The character to use when masking entry contents (in \"password mode\")"),
805 GTK_PARAM_READWRITE));
807 g_object_class_install_property (gobject_class,
808 PROP_ACTIVATES_DEFAULT,
809 g_param_spec_boolean ("activates-default",
810 P_("Activates default"),
811 P_("Whether to activate the default widget (such as the default button in a dialog) when Enter is pressed"),
813 GTK_PARAM_READWRITE));
814 g_object_class_install_property (gobject_class,
816 g_param_spec_int ("width-chars",
817 P_("Width in chars"),
818 P_("Number of characters to leave space for in the entry"),
822 GTK_PARAM_READWRITE));
824 g_object_class_install_property (gobject_class,
826 g_param_spec_int ("scroll-offset",
828 P_("Number of pixels of the entry scrolled off the screen to the left"),
832 GTK_PARAM_READABLE));
834 g_object_class_install_property (gobject_class,
836 g_param_spec_string ("text",
838 P_("The contents of the entry"),
840 GTK_PARAM_READWRITE));
845 * The horizontal alignment, from 0 (left) to 1 (right).
846 * Reversed for RTL layouts.
850 g_object_class_install_property (gobject_class,
852 g_param_spec_float ("xalign",
854 P_("The horizontal alignment, from 0 (left) to 1 (right). Reversed for RTL layouts."),
858 GTK_PARAM_READWRITE));
861 * GtkEntry:truncate-multiline:
863 * When %TRUE, pasted multi-line text is truncated to the first line.
867 g_object_class_install_property (gobject_class,
868 PROP_TRUNCATE_MULTILINE,
869 g_param_spec_boolean ("truncate-multiline",
870 P_("Truncate multiline"),
871 P_("Whether to truncate multiline pastes to one line."),
873 GTK_PARAM_READWRITE));
876 * GtkEntry:shadow-type:
878 * Which kind of shadow to draw around the entry when
879 * #GtkEntry:has-frame is set to %TRUE.
883 g_object_class_install_property (gobject_class,
885 g_param_spec_enum ("shadow-type",
887 P_("Which kind of shadow to draw around the entry when has-frame is set"),
888 GTK_TYPE_SHADOW_TYPE,
890 GTK_PARAM_READWRITE));
893 * GtkEntry:overwrite-mode:
895 * If text is overwritten when typing in the #GtkEntry.
899 g_object_class_install_property (gobject_class,
901 g_param_spec_boolean ("overwrite-mode",
902 P_("Overwrite mode"),
903 P_("Whether new text overwrites existing text"),
905 GTK_PARAM_READWRITE));
908 * GtkEntry:text-length:
910 * The length of the text in the #GtkEntry.
914 g_object_class_install_property (gobject_class,
916 g_param_spec_uint ("text-length",
918 P_("Length of the text currently in the entry"),
922 GTK_PARAM_READABLE));
924 * GtkEntry:invisible-char-set:
926 * Whether the invisible char has been set for the #GtkEntry.
930 g_object_class_install_property (gobject_class,
931 PROP_INVISIBLE_CHAR_SET,
932 g_param_spec_boolean ("invisible-char-set",
933 P_("Invisible character set"),
934 P_("Whether the invisible character has been set"),
936 GTK_PARAM_READWRITE));
939 * GtkEntry:caps-lock-warning
941 * Whether password entries will show a warning when Caps Lock is on.
943 * Note that the warning is shown using a secondary icon, and thus
944 * does not work if you are using the secondary icon position for some
949 g_object_class_install_property (gobject_class,
950 PROP_CAPS_LOCK_WARNING,
951 g_param_spec_boolean ("caps-lock-warning",
952 P_("Caps Lock warning"),
953 P_("Whether password entries will show a warning when Caps Lock is on"),
955 GTK_PARAM_READWRITE));
958 * GtkEntry:progress-fraction:
960 * The current fraction of the task that's been completed.
964 g_object_class_install_property (gobject_class,
965 PROP_PROGRESS_FRACTION,
966 g_param_spec_double ("progress-fraction",
967 P_("Progress Fraction"),
968 P_("The current fraction of the task that's been completed"),
972 GTK_PARAM_READWRITE));
975 * GtkEntry:progress-pulse-step:
977 * The fraction of total entry width to move the progress
978 * bouncing block for each call to gtk_entry_progress_pulse().
982 g_object_class_install_property (gobject_class,
983 PROP_PROGRESS_PULSE_STEP,
984 g_param_spec_double ("progress-pulse-step",
985 P_("Progress Pulse Step"),
986 P_("The fraction of total entry width to move the progress bouncing block for each call to gtk_entry_progress_pulse()"),
990 GTK_PARAM_READWRITE));
993 * GtkEntry:placeholder-text:
995 * The text that will be displayed in the #GtkEntry when it is empty and unfocused.
999 g_object_class_install_property (gobject_class,
1000 PROP_PLACEHOLDER_TEXT,
1001 g_param_spec_string ("placeholder-text",
1002 P_("Placeholder text"),
1003 P_("Show text in the entry when it's empty and unfocused"),
1005 GTK_PARAM_READWRITE));
1008 * GtkEntry:primary-icon-pixbuf:
1010 * A pixbuf to use as the primary icon for the entry.
1014 g_object_class_install_property (gobject_class,
1015 PROP_PIXBUF_PRIMARY,
1016 g_param_spec_object ("primary-icon-pixbuf",
1017 P_("Primary pixbuf"),
1018 P_("Primary pixbuf for the entry"),
1020 GTK_PARAM_READWRITE));
1023 * GtkEntry:secondary-icon-pixbuf:
1025 * An pixbuf to use as the secondary icon for the entry.
1029 g_object_class_install_property (gobject_class,
1030 PROP_PIXBUF_SECONDARY,
1031 g_param_spec_object ("secondary-icon-pixbuf",
1032 P_("Secondary pixbuf"),
1033 P_("Secondary pixbuf for the entry"),
1035 GTK_PARAM_READWRITE));
1038 * GtkEntry:primary-icon-stock:
1040 * The stock id to use for the primary icon for the entry.
1044 g_object_class_install_property (gobject_class,
1046 g_param_spec_string ("primary-icon-stock",
1047 P_("Primary stock ID"),
1048 P_("Stock ID for primary icon"),
1050 GTK_PARAM_READWRITE));
1053 * GtkEntry:secondary-icon-stock:
1055 * The stock id to use for the secondary icon for the entry.
1059 g_object_class_install_property (gobject_class,
1060 PROP_STOCK_SECONDARY,
1061 g_param_spec_string ("secondary-icon-stock",
1062 P_("Secondary stock ID"),
1063 P_("Stock ID for secondary icon"),
1065 GTK_PARAM_READWRITE));
1068 * GtkEntry:primary-icon-name:
1070 * The icon name to use for the primary icon for the entry.
1074 g_object_class_install_property (gobject_class,
1075 PROP_ICON_NAME_PRIMARY,
1076 g_param_spec_string ("primary-icon-name",
1077 P_("Primary icon name"),
1078 P_("Icon name for primary icon"),
1080 GTK_PARAM_READWRITE));
1083 * GtkEntry:secondary-icon-name:
1085 * The icon name to use for the secondary icon for the entry.
1089 g_object_class_install_property (gobject_class,
1090 PROP_ICON_NAME_SECONDARY,
1091 g_param_spec_string ("secondary-icon-name",
1092 P_("Secondary icon name"),
1093 P_("Icon name for secondary icon"),
1095 GTK_PARAM_READWRITE));
1098 * GtkEntry:primary-icon-gicon:
1100 * The #GIcon to use for the primary icon for the entry.
1104 g_object_class_install_property (gobject_class,
1106 g_param_spec_object ("primary-icon-gicon",
1107 P_("Primary GIcon"),
1108 P_("GIcon for primary icon"),
1110 GTK_PARAM_READWRITE));
1113 * GtkEntry:secondary-icon-gicon:
1115 * The #GIcon to use for the secondary icon for the entry.
1119 g_object_class_install_property (gobject_class,
1120 PROP_GICON_SECONDARY,
1121 g_param_spec_object ("secondary-icon-gicon",
1122 P_("Secondary GIcon"),
1123 P_("GIcon for secondary icon"),
1125 GTK_PARAM_READWRITE));
1128 * GtkEntry:primary-icon-storage-type:
1130 * The representation which is used for the primary icon of the entry.
1134 g_object_class_install_property (gobject_class,
1135 PROP_STORAGE_TYPE_PRIMARY,
1136 g_param_spec_enum ("primary-icon-storage-type",
1137 P_("Primary storage type"),
1138 P_("The representation being used for primary icon"),
1139 GTK_TYPE_IMAGE_TYPE,
1141 GTK_PARAM_READABLE));
1144 * GtkEntry:secondary-icon-storage-type:
1146 * The representation which is used for the secondary icon of the entry.
1150 g_object_class_install_property (gobject_class,
1151 PROP_STORAGE_TYPE_SECONDARY,
1152 g_param_spec_enum ("secondary-icon-storage-type",
1153 P_("Secondary storage type"),
1154 P_("The representation being used for secondary icon"),
1155 GTK_TYPE_IMAGE_TYPE,
1157 GTK_PARAM_READABLE));
1160 * GtkEntry:primary-icon-activatable:
1162 * Whether the primary icon is activatable.
1164 * GTK+ emits the #GtkEntry::icon-press and #GtkEntry::icon-release
1165 * signals only on sensitive, activatable icons.
1167 * Sensitive, but non-activatable icons can be used for purely
1168 * informational purposes.
1172 g_object_class_install_property (gobject_class,
1173 PROP_ACTIVATABLE_PRIMARY,
1174 g_param_spec_boolean ("primary-icon-activatable",
1175 P_("Primary icon activatable"),
1176 P_("Whether the primary icon is activatable"),
1178 GTK_PARAM_READWRITE));
1181 * GtkEntry:secondary-icon-activatable:
1183 * Whether the secondary icon is activatable.
1185 * GTK+ emits the #GtkEntry::icon-press and #GtkEntry::icon-release
1186 * signals only on sensitive, activatable icons.
1188 * Sensitive, but non-activatable icons can be used for purely
1189 * informational purposes.
1193 g_object_class_install_property (gobject_class,
1194 PROP_ACTIVATABLE_SECONDARY,
1195 g_param_spec_boolean ("secondary-icon-activatable",
1196 P_("Secondary icon activatable"),
1197 P_("Whether the secondary icon is activatable"),
1199 GTK_PARAM_READWRITE));
1203 * GtkEntry:primary-icon-sensitive:
1205 * Whether the primary icon is sensitive.
1207 * An insensitive icon appears grayed out. GTK+ does not emit the
1208 * #GtkEntry::icon-press and #GtkEntry::icon-release signals and
1209 * does not allow DND from insensitive icons.
1211 * An icon should be set insensitive if the action that would trigger
1212 * when clicked is currently not available.
1216 g_object_class_install_property (gobject_class,
1217 PROP_SENSITIVE_PRIMARY,
1218 g_param_spec_boolean ("primary-icon-sensitive",
1219 P_("Primary icon sensitive"),
1220 P_("Whether the primary icon is sensitive"),
1222 GTK_PARAM_READWRITE));
1225 * GtkEntry:secondary-icon-sensitive:
1227 * Whether the secondary icon is sensitive.
1229 * An insensitive icon appears grayed out. GTK+ does not emit the
1230 * #GtkEntry::icon-press and #GtkEntry::icon-release signals and
1231 * does not allow DND from insensitive icons.
1233 * An icon should be set insensitive if the action that would trigger
1234 * when clicked is currently not available.
1238 g_object_class_install_property (gobject_class,
1239 PROP_SENSITIVE_SECONDARY,
1240 g_param_spec_boolean ("secondary-icon-sensitive",
1241 P_("Secondary icon sensitive"),
1242 P_("Whether the secondary icon is sensitive"),
1244 GTK_PARAM_READWRITE));
1247 * GtkEntry:primary-icon-tooltip-text:
1249 * The contents of the tooltip on the primary icon.
1251 * Also see gtk_entry_set_icon_tooltip_text().
1255 g_object_class_install_property (gobject_class,
1256 PROP_TOOLTIP_TEXT_PRIMARY,
1257 g_param_spec_string ("primary-icon-tooltip-text",
1258 P_("Primary icon tooltip text"),
1259 P_("The contents of the tooltip on the primary icon"),
1261 GTK_PARAM_READWRITE));
1264 * GtkEntry:secondary-icon-tooltip-text:
1266 * The contents of the tooltip on the secondary icon.
1268 * Also see gtk_entry_set_icon_tooltip_text().
1272 g_object_class_install_property (gobject_class,
1273 PROP_TOOLTIP_TEXT_SECONDARY,
1274 g_param_spec_string ("secondary-icon-tooltip-text",
1275 P_("Secondary icon tooltip text"),
1276 P_("The contents of the tooltip on the secondary icon"),
1278 GTK_PARAM_READWRITE));
1281 * GtkEntry:primary-icon-tooltip-markup:
1283 * The contents of the tooltip on the primary icon, which is marked up
1284 * with the <link linkend="PangoMarkupFormat">Pango text markup
1287 * Also see gtk_entry_set_icon_tooltip_markup().
1291 g_object_class_install_property (gobject_class,
1292 PROP_TOOLTIP_MARKUP_PRIMARY,
1293 g_param_spec_string ("primary-icon-tooltip-markup",
1294 P_("Primary icon tooltip markup"),
1295 P_("The contents of the tooltip on the primary icon"),
1297 GTK_PARAM_READWRITE));
1300 * GtkEntry:secondary-icon-tooltip-markup:
1302 * The contents of the tooltip on the secondary icon, which is marked up
1303 * with the <link linkend="PangoMarkupFormat">Pango text markup
1306 * Also see gtk_entry_set_icon_tooltip_markup().
1310 g_object_class_install_property (gobject_class,
1311 PROP_TOOLTIP_MARKUP_SECONDARY,
1312 g_param_spec_string ("secondary-icon-tooltip-markup",
1313 P_("Secondary icon tooltip markup"),
1314 P_("The contents of the tooltip on the secondary icon"),
1316 GTK_PARAM_READWRITE));
1319 * GtkEntry:im-module:
1321 * Which IM (input method) module should be used for this entry.
1322 * See #GtkIMContext.
1324 * Setting this to a non-%NULL value overrides the
1325 * system-wide IM module setting. See the GtkSettings
1326 * #GtkSettings:gtk-im-module property.
1330 g_object_class_install_property (gobject_class,
1332 g_param_spec_string ("im-module",
1334 P_("Which IM module should be used"),
1336 GTK_PARAM_READWRITE));
1339 * GtkEntry:completion:
1341 * The auxiliary completion object to use with the entry.
1345 g_object_class_install_property (gobject_class,
1347 g_param_spec_object ("completion",
1349 P_("The auxiliary completion object"),
1350 GTK_TYPE_ENTRY_COMPLETION,
1351 GTK_PARAM_READWRITE));
1354 * GtkEntry:icon-prelight:
1356 * The prelight style property determines whether activatable
1357 * icons prelight on mouseover.
1361 gtk_widget_class_install_style_property (widget_class,
1362 g_param_spec_boolean ("icon-prelight",
1363 P_("Icon Prelight"),
1364 P_("Whether activatable icons should prelight when hovered"),
1366 GTK_PARAM_READABLE));
1369 * GtkEntry:progress-border:
1371 * The border around the progress bar in the entry.
1375 gtk_widget_class_install_style_property (widget_class,
1376 g_param_spec_boxed ("progress-border",
1377 P_("Progress Border"),
1378 P_("Border around the progress bar"),
1380 GTK_PARAM_READABLE));
1383 * GtkEntry:invisible-char:
1385 * The invisible character is used when masking entry contents (in
1386 * \"password mode\")"). When it is not explicitly set with the
1387 * #GtkEntry::invisible-char property, GTK+ determines the character
1388 * to use from a list of possible candidates, depending on availability
1389 * in the current font.
1391 * This style property allows the theme to prepend a character
1392 * to the list of candidates.
1396 gtk_widget_class_install_style_property (widget_class,
1397 g_param_spec_unichar ("invisible-char",
1398 P_("Invisible character"),
1399 P_("The character to use when masking entry contents (in \"password mode\")"),
1401 GTK_PARAM_READABLE));
1404 * GtkEntry::populate-popup:
1405 * @entry: The entry on which the signal is emitted
1406 * @menu: the menu that is being populated
1408 * The ::populate-popup signal gets emitted before showing the
1409 * context menu of the entry.
1411 * If you need to add items to the context menu, connect
1412 * to this signal and append your menuitems to the @menu.
1414 signals[POPULATE_POPUP] =
1415 g_signal_new (I_("populate-popup"),
1416 G_OBJECT_CLASS_TYPE (gobject_class),
1418 G_STRUCT_OFFSET (GtkEntryClass, populate_popup),
1420 _gtk_marshal_VOID__OBJECT,
1424 /* Action signals */
1427 * GtkEntry::activate:
1428 * @entry: The entry on which the signal is emitted
1430 * A <link linkend="keybinding-signals">keybinding signal</link>
1431 * which gets emitted when the user activates the entry.
1433 * Applications should not connect to it, but may emit it with
1434 * g_signal_emit_by_name() if they need to control activation
1437 * The default bindings for this signal are all forms of the Enter key.
1440 g_signal_new (I_("activate"),
1441 G_OBJECT_CLASS_TYPE (gobject_class),
1442 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1443 G_STRUCT_OFFSET (GtkEntryClass, activate),
1445 _gtk_marshal_VOID__VOID,
1447 widget_class->activate_signal = signals[ACTIVATE];
1450 * GtkEntry::move-cursor:
1451 * @entry: the object which received the signal
1452 * @step: the granularity of the move, as a #GtkMovementStep
1453 * @count: the number of @step units to move
1454 * @extend_selection: %TRUE if the move should extend the selection
1456 * The ::move-cursor signal is a
1457 * <link linkend="keybinding-signals">keybinding signal</link>
1458 * which gets emitted when the user initiates a cursor movement.
1459 * If the cursor is not visible in @entry, this signal causes
1460 * the viewport to be moved instead.
1462 * Applications should not connect to it, but may emit it with
1463 * g_signal_emit_by_name() if they need to control the cursor
1466 * The default bindings for this signal come in two variants,
1467 * the variant with the Shift modifier extends the selection,
1468 * the variant without the Shift modifer does not.
1469 * There are too many key combinations to list them all here.
1471 * <listitem>Arrow keys move by individual characters/lines</listitem>
1472 * <listitem>Ctrl-arrow key combinations move by words/paragraphs</listitem>
1473 * <listitem>Home/End keys move to the ends of the buffer</listitem>
1476 signals[MOVE_CURSOR] =
1477 g_signal_new (I_("move-cursor"),
1478 G_OBJECT_CLASS_TYPE (gobject_class),
1479 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1480 G_STRUCT_OFFSET (GtkEntryClass, move_cursor),
1482 _gtk_marshal_VOID__ENUM_INT_BOOLEAN,
1484 GTK_TYPE_MOVEMENT_STEP,
1489 * GtkEntry::insert-at-cursor:
1490 * @entry: the object which received the signal
1491 * @string: the string to insert
1493 * The ::insert-at-cursor signal is a
1494 * <link linkend="keybinding-signals">keybinding signal</link>
1495 * which gets emitted when the user initiates the insertion of a
1496 * fixed string at the cursor.
1498 * This signal has no default bindings.
1500 signals[INSERT_AT_CURSOR] =
1501 g_signal_new (I_("insert-at-cursor"),
1502 G_OBJECT_CLASS_TYPE (gobject_class),
1503 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1504 G_STRUCT_OFFSET (GtkEntryClass, insert_at_cursor),
1506 _gtk_marshal_VOID__STRING,
1511 * GtkEntry::delete-from-cursor:
1512 * @entry: the object which received the signal
1513 * @type: the granularity of the deletion, as a #GtkDeleteType
1514 * @count: the number of @type units to delete
1516 * The ::delete-from-cursor signal is a
1517 * <link linkend="keybinding-signals">keybinding signal</link>
1518 * which gets emitted when the user initiates a text deletion.
1520 * If the @type is %GTK_DELETE_CHARS, GTK+ deletes the selection
1521 * if there is one, otherwise it deletes the requested number
1524 * The default bindings for this signal are
1525 * Delete for deleting a character and Ctrl-Delete for
1528 signals[DELETE_FROM_CURSOR] =
1529 g_signal_new (I_("delete-from-cursor"),
1530 G_OBJECT_CLASS_TYPE (gobject_class),
1531 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1532 G_STRUCT_OFFSET (GtkEntryClass, delete_from_cursor),
1534 _gtk_marshal_VOID__ENUM_INT,
1536 GTK_TYPE_DELETE_TYPE,
1540 * GtkEntry::backspace:
1541 * @entry: the object which received the signal
1543 * The ::backspace signal is a
1544 * <link linkend="keybinding-signals">keybinding signal</link>
1545 * which gets emitted when the user asks for it.
1547 * The default bindings for this signal are
1548 * Backspace and Shift-Backspace.
1550 signals[BACKSPACE] =
1551 g_signal_new (I_("backspace"),
1552 G_OBJECT_CLASS_TYPE (gobject_class),
1553 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1554 G_STRUCT_OFFSET (GtkEntryClass, backspace),
1556 _gtk_marshal_VOID__VOID,
1560 * GtkEntry::cut-clipboard:
1561 * @entry: the object which received the signal
1563 * The ::cut-clipboard signal is a
1564 * <link linkend="keybinding-signals">keybinding signal</link>
1565 * which gets emitted to cut the selection to the clipboard.
1567 * The default bindings for this signal are
1568 * Ctrl-x and Shift-Delete.
1570 signals[CUT_CLIPBOARD] =
1571 g_signal_new (I_("cut-clipboard"),
1572 G_OBJECT_CLASS_TYPE (gobject_class),
1573 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1574 G_STRUCT_OFFSET (GtkEntryClass, cut_clipboard),
1576 _gtk_marshal_VOID__VOID,
1580 * GtkEntry::copy-clipboard:
1581 * @entry: the object which received the signal
1583 * The ::copy-clipboard signal is a
1584 * <link linkend="keybinding-signals">keybinding signal</link>
1585 * which gets emitted to copy the selection to the clipboard.
1587 * The default bindings for this signal are
1588 * Ctrl-c and Ctrl-Insert.
1590 signals[COPY_CLIPBOARD] =
1591 g_signal_new (I_("copy-clipboard"),
1592 G_OBJECT_CLASS_TYPE (gobject_class),
1593 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1594 G_STRUCT_OFFSET (GtkEntryClass, copy_clipboard),
1596 _gtk_marshal_VOID__VOID,
1600 * GtkEntry::paste-clipboard:
1601 * @entry: the object which received the signal
1603 * The ::paste-clipboard signal is a
1604 * <link linkend="keybinding-signals">keybinding signal</link>
1605 * which gets emitted to paste the contents of the clipboard
1606 * into the text view.
1608 * The default bindings for this signal are
1609 * Ctrl-v and Shift-Insert.
1611 signals[PASTE_CLIPBOARD] =
1612 g_signal_new (I_("paste-clipboard"),
1613 G_OBJECT_CLASS_TYPE (gobject_class),
1614 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1615 G_STRUCT_OFFSET (GtkEntryClass, paste_clipboard),
1617 _gtk_marshal_VOID__VOID,
1621 * GtkEntry::toggle-overwrite:
1622 * @entry: the object which received the signal
1624 * The ::toggle-overwrite signal is a
1625 * <link linkend="keybinding-signals">keybinding signal</link>
1626 * which gets emitted to toggle the overwrite mode of the entry.
1628 * The default bindings for this signal is Insert.
1630 signals[TOGGLE_OVERWRITE] =
1631 g_signal_new (I_("toggle-overwrite"),
1632 G_OBJECT_CLASS_TYPE (gobject_class),
1633 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1634 G_STRUCT_OFFSET (GtkEntryClass, toggle_overwrite),
1636 _gtk_marshal_VOID__VOID,
1640 * GtkEntry::icon-press:
1641 * @entry: The entry on which the signal is emitted
1642 * @icon_pos: The position of the clicked icon
1643 * @event: (type Gdk.EventButton): the button press event
1645 * The ::icon-press signal is emitted when an activatable icon
1650 signals[ICON_PRESS] =
1651 g_signal_new (I_("icon-press"),
1652 G_TYPE_FROM_CLASS (gobject_class),
1656 _gtk_marshal_VOID__ENUM_BOXED,
1658 GTK_TYPE_ENTRY_ICON_POSITION,
1659 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1662 * GtkEntry::icon-release:
1663 * @entry: The entry on which the signal is emitted
1664 * @icon_pos: The position of the clicked icon
1665 * @event: (type Gdk.EventButton): the button release event
1667 * The ::icon-release signal is emitted on the button release from a
1668 * mouse click over an activatable icon.
1672 signals[ICON_RELEASE] =
1673 g_signal_new (I_("icon-release"),
1674 G_TYPE_FROM_CLASS (gobject_class),
1678 _gtk_marshal_VOID__ENUM_BOXED,
1680 GTK_TYPE_ENTRY_ICON_POSITION,
1681 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1684 * GtkEntry::preedit-changed:
1685 * @entry: the object which received the signal
1686 * @preedit: the current preedit string
1688 * If an input method is used, the typed text will not immediately
1689 * be committed to the buffer. So if you are interested in the text,
1690 * connect to this signal.
1694 signals[PREEDIT_CHANGED] =
1695 g_signal_new_class_handler (I_("preedit-changed"),
1696 G_OBJECT_CLASS_TYPE (gobject_class),
1697 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1700 _gtk_marshal_VOID__STRING,
1709 binding_set = gtk_binding_set_by_class (class);
1711 /* Moving the insertion point */
1712 add_move_binding (binding_set, GDK_KEY_Right, 0,
1713 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1715 add_move_binding (binding_set, GDK_KEY_Left, 0,
1716 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1718 add_move_binding (binding_set, GDK_KEY_KP_Right, 0,
1719 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1721 add_move_binding (binding_set, GDK_KEY_KP_Left, 0,
1722 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1724 add_move_binding (binding_set, GDK_KEY_Right, GDK_CONTROL_MASK,
1725 GTK_MOVEMENT_WORDS, 1);
1727 add_move_binding (binding_set, GDK_KEY_Left, GDK_CONTROL_MASK,
1728 GTK_MOVEMENT_WORDS, -1);
1730 add_move_binding (binding_set, GDK_KEY_KP_Right, GDK_CONTROL_MASK,
1731 GTK_MOVEMENT_WORDS, 1);
1733 add_move_binding (binding_set, GDK_KEY_KP_Left, GDK_CONTROL_MASK,
1734 GTK_MOVEMENT_WORDS, -1);
1736 add_move_binding (binding_set, GDK_KEY_Home, 0,
1737 GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
1739 add_move_binding (binding_set, GDK_KEY_End, 0,
1740 GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
1742 add_move_binding (binding_set, GDK_KEY_KP_Home, 0,
1743 GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
1745 add_move_binding (binding_set, GDK_KEY_KP_End, 0,
1746 GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
1748 add_move_binding (binding_set, GDK_KEY_Home, GDK_CONTROL_MASK,
1749 GTK_MOVEMENT_BUFFER_ENDS, -1);
1751 add_move_binding (binding_set, GDK_KEY_End, GDK_CONTROL_MASK,
1752 GTK_MOVEMENT_BUFFER_ENDS, 1);
1754 add_move_binding (binding_set, GDK_KEY_KP_Home, GDK_CONTROL_MASK,
1755 GTK_MOVEMENT_BUFFER_ENDS, -1);
1757 add_move_binding (binding_set, GDK_KEY_KP_End, GDK_CONTROL_MASK,
1758 GTK_MOVEMENT_BUFFER_ENDS, 1);
1762 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK,
1764 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1766 G_TYPE_BOOLEAN, FALSE);
1767 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK,
1769 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1771 G_TYPE_BOOLEAN, TRUE);
1773 gtk_binding_entry_add_signal (binding_set, GDK_KEY_slash, GDK_CONTROL_MASK,
1775 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1777 G_TYPE_BOOLEAN, FALSE);
1778 gtk_binding_entry_add_signal (binding_set, GDK_KEY_slash, GDK_CONTROL_MASK,
1780 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1782 G_TYPE_BOOLEAN, TRUE);
1785 gtk_binding_entry_add_signal (binding_set, GDK_KEY_backslash, GDK_CONTROL_MASK,
1787 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_VISUAL_POSITIONS,
1789 G_TYPE_BOOLEAN, FALSE);
1790 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_SHIFT_MASK | GDK_CONTROL_MASK,
1792 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_VISUAL_POSITIONS,
1794 G_TYPE_BOOLEAN, FALSE);
1798 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Return, 0,
1800 gtk_binding_entry_add_signal (binding_set, GDK_KEY_ISO_Enter, 0,
1802 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Enter, 0,
1806 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, 0,
1807 "delete-from-cursor", 2,
1808 G_TYPE_ENUM, GTK_DELETE_CHARS,
1811 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Delete, 0,
1812 "delete-from-cursor", 2,
1813 G_TYPE_ENUM, GTK_DELETE_CHARS,
1816 gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, 0,
1819 /* Make this do the same as Backspace, to help with mis-typing */
1820 gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, GDK_SHIFT_MASK,
1823 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, GDK_CONTROL_MASK,
1824 "delete-from-cursor", 2,
1825 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1828 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Delete, GDK_CONTROL_MASK,
1829 "delete-from-cursor", 2,
1830 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1833 gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, GDK_CONTROL_MASK,
1834 "delete-from-cursor", 2,
1835 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1838 /* Cut/copy/paste */
1840 gtk_binding_entry_add_signal (binding_set, GDK_KEY_x, GDK_CONTROL_MASK,
1841 "cut-clipboard", 0);
1842 gtk_binding_entry_add_signal (binding_set, GDK_KEY_c, GDK_CONTROL_MASK,
1843 "copy-clipboard", 0);
1844 gtk_binding_entry_add_signal (binding_set, GDK_KEY_v, GDK_CONTROL_MASK,
1845 "paste-clipboard", 0);
1847 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, GDK_SHIFT_MASK,
1848 "cut-clipboard", 0);
1849 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, GDK_CONTROL_MASK,
1850 "copy-clipboard", 0);
1851 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, GDK_SHIFT_MASK,
1852 "paste-clipboard", 0);
1855 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, 0,
1856 "toggle-overwrite", 0);
1857 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Insert, 0,
1858 "toggle-overwrite", 0);
1861 * GtkEntry:inner-border:
1863 * Sets the text area's border between the text and the frame.
1867 gtk_widget_class_install_style_property (widget_class,
1868 g_param_spec_boxed ("inner-border",
1870 P_("Border between text and frame."),
1872 GTK_PARAM_READABLE));
1874 g_type_class_add_private (gobject_class, sizeof (GtkEntryPrivate));
1876 gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_ENTRY_ACCESSIBLE);
1880 gtk_entry_editable_init (GtkEditableInterface *iface)
1882 iface->do_insert_text = gtk_entry_insert_text;
1883 iface->do_delete_text = gtk_entry_delete_text;
1884 iface->insert_text = gtk_entry_real_insert_text;
1885 iface->delete_text = gtk_entry_real_delete_text;
1886 iface->get_chars = gtk_entry_get_chars;
1887 iface->set_selection_bounds = gtk_entry_set_selection_bounds;
1888 iface->get_selection_bounds = gtk_entry_get_selection_bounds;
1889 iface->set_position = gtk_entry_real_set_position;
1890 iface->get_position = gtk_entry_get_position;
1894 gtk_entry_cell_editable_init (GtkCellEditableIface *iface)
1896 iface->start_editing = gtk_entry_start_editing;
1900 gtk_entry_set_property (GObject *object,
1902 const GValue *value,
1905 GtkEntry *entry = GTK_ENTRY (object);
1906 GtkEntryPrivate *priv = entry->priv;
1911 gtk_entry_set_buffer (entry, g_value_get_object (value));
1916 gboolean new_value = g_value_get_boolean (value);
1918 if (new_value != priv->editable)
1920 GtkWidget *widget = GTK_WIDGET (entry);
1924 _gtk_entry_reset_im_context (entry);
1925 if (gtk_widget_has_focus (widget))
1926 gtk_im_context_focus_out (priv->im_context);
1928 priv->preedit_length = 0;
1929 priv->preedit_cursor = 0;
1932 priv->editable = new_value;
1934 if (new_value && gtk_widget_has_focus (widget))
1935 gtk_im_context_focus_in (priv->im_context);
1937 gtk_widget_queue_draw (widget);
1942 case PROP_MAX_LENGTH:
1943 gtk_entry_set_max_length (entry, g_value_get_int (value));
1946 case PROP_VISIBILITY:
1947 gtk_entry_set_visibility (entry, g_value_get_boolean (value));
1950 case PROP_HAS_FRAME:
1951 gtk_entry_set_has_frame (entry, g_value_get_boolean (value));
1954 case PROP_INNER_BORDER:
1955 gtk_entry_set_inner_border (entry, g_value_get_boxed (value));
1958 case PROP_INVISIBLE_CHAR:
1959 gtk_entry_set_invisible_char (entry, g_value_get_uint (value));
1962 case PROP_ACTIVATES_DEFAULT:
1963 gtk_entry_set_activates_default (entry, g_value_get_boolean (value));
1966 case PROP_WIDTH_CHARS:
1967 gtk_entry_set_width_chars (entry, g_value_get_int (value));
1971 gtk_entry_set_text (entry, g_value_get_string (value));
1975 gtk_entry_set_alignment (entry, g_value_get_float (value));
1978 case PROP_TRUNCATE_MULTILINE:
1979 priv->truncate_multiline = g_value_get_boolean (value);
1982 case PROP_SHADOW_TYPE:
1983 priv->shadow_type = g_value_get_enum (value);
1986 case PROP_OVERWRITE_MODE:
1987 gtk_entry_set_overwrite_mode (entry, g_value_get_boolean (value));
1990 case PROP_INVISIBLE_CHAR_SET:
1991 if (g_value_get_boolean (value))
1992 priv->invisible_char_set = TRUE;
1994 gtk_entry_unset_invisible_char (entry);
1997 case PROP_CAPS_LOCK_WARNING:
1998 priv->caps_lock_warning = g_value_get_boolean (value);
2001 case PROP_PROGRESS_FRACTION:
2002 gtk_entry_set_progress_fraction (entry, g_value_get_double (value));
2005 case PROP_PROGRESS_PULSE_STEP:
2006 gtk_entry_set_progress_pulse_step (entry, g_value_get_double (value));
2009 case PROP_PLACEHOLDER_TEXT:
2010 gtk_entry_set_placeholder_text (entry, g_value_get_string (value));
2013 case PROP_PIXBUF_PRIMARY:
2014 gtk_entry_set_icon_from_pixbuf (entry,
2015 GTK_ENTRY_ICON_PRIMARY,
2016 g_value_get_object (value));
2019 case PROP_PIXBUF_SECONDARY:
2020 gtk_entry_set_icon_from_pixbuf (entry,
2021 GTK_ENTRY_ICON_SECONDARY,
2022 g_value_get_object (value));
2025 case PROP_STOCK_PRIMARY:
2026 gtk_entry_set_icon_from_stock (entry,
2027 GTK_ENTRY_ICON_PRIMARY,
2028 g_value_get_string (value));
2031 case PROP_STOCK_SECONDARY:
2032 gtk_entry_set_icon_from_stock (entry,
2033 GTK_ENTRY_ICON_SECONDARY,
2034 g_value_get_string (value));
2037 case PROP_ICON_NAME_PRIMARY:
2038 gtk_entry_set_icon_from_icon_name (entry,
2039 GTK_ENTRY_ICON_PRIMARY,
2040 g_value_get_string (value));
2043 case PROP_ICON_NAME_SECONDARY:
2044 gtk_entry_set_icon_from_icon_name (entry,
2045 GTK_ENTRY_ICON_SECONDARY,
2046 g_value_get_string (value));
2049 case PROP_GICON_PRIMARY:
2050 gtk_entry_set_icon_from_gicon (entry,
2051 GTK_ENTRY_ICON_PRIMARY,
2052 g_value_get_object (value));
2055 case PROP_GICON_SECONDARY:
2056 gtk_entry_set_icon_from_gicon (entry,
2057 GTK_ENTRY_ICON_SECONDARY,
2058 g_value_get_object (value));
2061 case PROP_ACTIVATABLE_PRIMARY:
2062 gtk_entry_set_icon_activatable (entry,
2063 GTK_ENTRY_ICON_PRIMARY,
2064 g_value_get_boolean (value));
2067 case PROP_ACTIVATABLE_SECONDARY:
2068 gtk_entry_set_icon_activatable (entry,
2069 GTK_ENTRY_ICON_SECONDARY,
2070 g_value_get_boolean (value));
2073 case PROP_SENSITIVE_PRIMARY:
2074 gtk_entry_set_icon_sensitive (entry,
2075 GTK_ENTRY_ICON_PRIMARY,
2076 g_value_get_boolean (value));
2079 case PROP_SENSITIVE_SECONDARY:
2080 gtk_entry_set_icon_sensitive (entry,
2081 GTK_ENTRY_ICON_SECONDARY,
2082 g_value_get_boolean (value));
2085 case PROP_TOOLTIP_TEXT_PRIMARY:
2086 gtk_entry_set_icon_tooltip_text (entry,
2087 GTK_ENTRY_ICON_PRIMARY,
2088 g_value_get_string (value));
2091 case PROP_TOOLTIP_TEXT_SECONDARY:
2092 gtk_entry_set_icon_tooltip_text (entry,
2093 GTK_ENTRY_ICON_SECONDARY,
2094 g_value_get_string (value));
2097 case PROP_TOOLTIP_MARKUP_PRIMARY:
2098 gtk_entry_set_icon_tooltip_markup (entry,
2099 GTK_ENTRY_ICON_PRIMARY,
2100 g_value_get_string (value));
2103 case PROP_TOOLTIP_MARKUP_SECONDARY:
2104 gtk_entry_set_icon_tooltip_markup (entry,
2105 GTK_ENTRY_ICON_SECONDARY,
2106 g_value_get_string (value));
2109 case PROP_IM_MODULE:
2110 g_free (priv->im_module);
2111 priv->im_module = g_value_dup_string (value);
2112 if (GTK_IS_IM_MULTICONTEXT (priv->im_context))
2113 gtk_im_multicontext_set_context_id (GTK_IM_MULTICONTEXT (priv->im_context), priv->im_module);
2116 case PROP_EDITING_CANCELED:
2117 priv->editing_canceled = g_value_get_boolean (value);
2120 case PROP_COMPLETION:
2121 gtk_entry_set_completion (entry, GTK_ENTRY_COMPLETION (g_value_get_object (value)));
2124 case PROP_SCROLL_OFFSET:
2125 case PROP_CURSOR_POSITION:
2127 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2133 gtk_entry_get_property (GObject *object,
2138 GtkEntry *entry = GTK_ENTRY (object);
2139 GtkEntryPrivate *priv = entry->priv;
2144 g_value_set_object (value, gtk_entry_get_buffer (entry));
2147 case PROP_CURSOR_POSITION:
2148 g_value_set_int (value, priv->current_pos);
2151 case PROP_SELECTION_BOUND:
2152 g_value_set_int (value, priv->selection_bound);
2156 g_value_set_boolean (value, priv->editable);
2159 case PROP_MAX_LENGTH:
2160 g_value_set_int (value, gtk_entry_buffer_get_max_length (get_buffer (entry)));
2163 case PROP_VISIBILITY:
2164 g_value_set_boolean (value, priv->visible);
2167 case PROP_HAS_FRAME:
2168 g_value_set_boolean (value, priv->has_frame);
2171 case PROP_INNER_BORDER:
2172 g_value_set_boxed (value, gtk_entry_get_inner_border (entry));
2175 case PROP_INVISIBLE_CHAR:
2176 g_value_set_uint (value, priv->invisible_char);
2179 case PROP_ACTIVATES_DEFAULT:
2180 g_value_set_boolean (value, priv->activates_default);
2183 case PROP_WIDTH_CHARS:
2184 g_value_set_int (value, priv->width_chars);
2187 case PROP_SCROLL_OFFSET:
2188 g_value_set_int (value, priv->scroll_offset);
2192 g_value_set_string (value, gtk_entry_get_text (entry));
2196 g_value_set_float (value, gtk_entry_get_alignment (entry));
2199 case PROP_TRUNCATE_MULTILINE:
2200 g_value_set_boolean (value, priv->truncate_multiline);
2203 case PROP_SHADOW_TYPE:
2204 g_value_set_enum (value, priv->shadow_type);
2207 case PROP_OVERWRITE_MODE:
2208 g_value_set_boolean (value, priv->overwrite_mode);
2211 case PROP_TEXT_LENGTH:
2212 g_value_set_uint (value, gtk_entry_buffer_get_length (get_buffer (entry)));
2215 case PROP_INVISIBLE_CHAR_SET:
2216 g_value_set_boolean (value, priv->invisible_char_set);
2219 case PROP_IM_MODULE:
2220 g_value_set_string (value, priv->im_module);
2223 case PROP_CAPS_LOCK_WARNING:
2224 g_value_set_boolean (value, priv->caps_lock_warning);
2227 case PROP_PROGRESS_FRACTION:
2228 g_value_set_double (value, priv->progress_fraction);
2231 case PROP_PROGRESS_PULSE_STEP:
2232 g_value_set_double (value, priv->progress_pulse_fraction);
2235 case PROP_PLACEHOLDER_TEXT:
2236 g_value_set_string (value, gtk_entry_get_placeholder_text (entry));
2239 case PROP_PIXBUF_PRIMARY:
2240 g_value_set_object (value,
2241 gtk_entry_get_icon_pixbuf (entry,
2242 GTK_ENTRY_ICON_PRIMARY));
2245 case PROP_PIXBUF_SECONDARY:
2246 g_value_set_object (value,
2247 gtk_entry_get_icon_pixbuf (entry,
2248 GTK_ENTRY_ICON_SECONDARY));
2251 case PROP_STOCK_PRIMARY:
2252 g_value_set_string (value,
2253 gtk_entry_get_icon_stock (entry,
2254 GTK_ENTRY_ICON_PRIMARY));
2257 case PROP_STOCK_SECONDARY:
2258 g_value_set_string (value,
2259 gtk_entry_get_icon_stock (entry,
2260 GTK_ENTRY_ICON_SECONDARY));
2263 case PROP_ICON_NAME_PRIMARY:
2264 g_value_set_string (value,
2265 gtk_entry_get_icon_name (entry,
2266 GTK_ENTRY_ICON_PRIMARY));
2269 case PROP_ICON_NAME_SECONDARY:
2270 g_value_set_string (value,
2271 gtk_entry_get_icon_name (entry,
2272 GTK_ENTRY_ICON_SECONDARY));
2275 case PROP_GICON_PRIMARY:
2276 g_value_set_object (value,
2277 gtk_entry_get_icon_gicon (entry,
2278 GTK_ENTRY_ICON_PRIMARY));
2281 case PROP_GICON_SECONDARY:
2282 g_value_set_object (value,
2283 gtk_entry_get_icon_gicon (entry,
2284 GTK_ENTRY_ICON_SECONDARY));
2287 case PROP_STORAGE_TYPE_PRIMARY:
2288 g_value_set_enum (value,
2289 gtk_entry_get_icon_storage_type (entry,
2290 GTK_ENTRY_ICON_PRIMARY));
2293 case PROP_STORAGE_TYPE_SECONDARY:
2294 g_value_set_enum (value,
2295 gtk_entry_get_icon_storage_type (entry,
2296 GTK_ENTRY_ICON_SECONDARY));
2299 case PROP_ACTIVATABLE_PRIMARY:
2300 g_value_set_boolean (value,
2301 gtk_entry_get_icon_activatable (entry, GTK_ENTRY_ICON_PRIMARY));
2304 case PROP_ACTIVATABLE_SECONDARY:
2305 g_value_set_boolean (value,
2306 gtk_entry_get_icon_activatable (entry, GTK_ENTRY_ICON_SECONDARY));
2309 case PROP_SENSITIVE_PRIMARY:
2310 g_value_set_boolean (value,
2311 gtk_entry_get_icon_sensitive (entry, GTK_ENTRY_ICON_PRIMARY));
2314 case PROP_SENSITIVE_SECONDARY:
2315 g_value_set_boolean (value,
2316 gtk_entry_get_icon_sensitive (entry, GTK_ENTRY_ICON_SECONDARY));
2319 case PROP_TOOLTIP_TEXT_PRIMARY:
2320 g_value_take_string (value,
2321 gtk_entry_get_icon_tooltip_text (entry, GTK_ENTRY_ICON_PRIMARY));
2324 case PROP_TOOLTIP_TEXT_SECONDARY:
2325 g_value_take_string (value,
2326 gtk_entry_get_icon_tooltip_text (entry, GTK_ENTRY_ICON_SECONDARY));
2329 case PROP_TOOLTIP_MARKUP_PRIMARY:
2330 g_value_take_string (value,
2331 gtk_entry_get_icon_tooltip_markup (entry, GTK_ENTRY_ICON_PRIMARY));
2334 case PROP_TOOLTIP_MARKUP_SECONDARY:
2335 g_value_take_string (value,
2336 gtk_entry_get_icon_tooltip_markup (entry, GTK_ENTRY_ICON_SECONDARY));
2339 case PROP_EDITING_CANCELED:
2340 g_value_set_boolean (value,
2341 priv->editing_canceled);
2344 case PROP_COMPLETION:
2345 g_value_set_object (value, G_OBJECT (gtk_entry_get_completion (entry)));
2349 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2355 find_invisible_char (GtkWidget *widget)
2357 PangoLayout *layout;
2358 PangoAttrList *attr_list;
2360 gunichar invisible_chars [] = {
2362 0x25cf, /* BLACK CIRCLE */
2363 0x2022, /* BULLET */
2364 0x2731, /* HEAVY ASTERISK */
2365 0x273a /* SIXTEEN POINTED ASTERISK */
2368 gtk_widget_style_get (widget,
2369 "invisible-char", &invisible_chars[0],
2372 layout = gtk_widget_create_pango_layout (widget, NULL);
2374 attr_list = pango_attr_list_new ();
2375 pango_attr_list_insert (attr_list, pango_attr_fallback_new (FALSE));
2377 pango_layout_set_attributes (layout, attr_list);
2378 pango_attr_list_unref (attr_list);
2380 for (i = (invisible_chars[0] != 0 ? 0 : 1); i < G_N_ELEMENTS (invisible_chars); i++)
2382 gchar text[7] = { 0, };
2385 len = g_unichar_to_utf8 (invisible_chars[i], text);
2386 pango_layout_set_text (layout, text, len);
2388 count = pango_layout_get_unknown_glyphs_count (layout);
2392 g_object_unref (layout);
2393 return invisible_chars[i];
2397 g_object_unref (layout);
2403 gtk_entry_init (GtkEntry *entry)
2405 GtkStyleContext *context;
2406 GtkEntryPrivate *priv;
2408 entry->priv = G_TYPE_INSTANCE_GET_PRIVATE (entry,
2413 gtk_widget_set_can_focus (GTK_WIDGET (entry), TRUE);
2414 gtk_widget_set_has_window (GTK_WIDGET (entry), FALSE);
2416 priv->editable = TRUE;
2417 priv->visible = TRUE;
2418 priv->dnd_position = -1;
2419 priv->width_chars = -1;
2420 priv->is_cell_renderer = FALSE;
2421 priv->editing_canceled = FALSE;
2422 priv->has_frame = TRUE;
2423 priv->truncate_multiline = FALSE;
2424 priv->shadow_type = GTK_SHADOW_IN;
2426 priv->caps_lock_warning = TRUE;
2427 priv->caps_lock_warning_shown = FALSE;
2428 priv->progress_fraction = 0.0;
2429 priv->progress_pulse_fraction = 0.1;
2431 gtk_drag_dest_set (GTK_WIDGET (entry),
2432 GTK_DEST_DEFAULT_HIGHLIGHT,
2434 GDK_ACTION_COPY | GDK_ACTION_MOVE);
2435 gtk_drag_dest_add_text_targets (GTK_WIDGET (entry));
2437 /* This object is completely private. No external entity can gain a reference
2438 * to it; so we create it here and destroy it in finalize().
2440 priv->im_context = gtk_im_multicontext_new ();
2442 g_signal_connect (priv->im_context, "commit",
2443 G_CALLBACK (gtk_entry_commit_cb), entry);
2444 g_signal_connect (priv->im_context, "preedit-changed",
2445 G_CALLBACK (gtk_entry_preedit_changed_cb), entry);
2446 g_signal_connect (priv->im_context, "retrieve-surrounding",
2447 G_CALLBACK (gtk_entry_retrieve_surrounding_cb), entry);
2448 g_signal_connect (priv->im_context, "delete-surrounding",
2449 G_CALLBACK (gtk_entry_delete_surrounding_cb), entry);
2451 context = gtk_widget_get_style_context (GTK_WIDGET (entry));
2452 gtk_style_context_add_class (context, GTK_STYLE_CLASS_ENTRY);
2454 gtk_entry_update_cached_style_values (entry);
2458 get_icon_width (GtkEntry *entry,
2459 GtkEntryIconPosition icon_pos)
2461 GtkEntryPrivate *priv = entry->priv;
2462 EntryIconInfo *icon_info = priv->icons[icon_pos];
2464 GtkSettings *settings;
2465 gint menu_icon_width;
2467 if (!icon_info || icon_info->pixbuf == NULL)
2470 screen = gtk_widget_get_screen (GTK_WIDGET (entry));
2471 settings = gtk_settings_get_for_screen (screen);
2473 gtk_icon_size_lookup_for_settings (settings, GTK_ICON_SIZE_MENU,
2474 &menu_icon_width, NULL);
2476 return MAX (gdk_pixbuf_get_width (icon_info->pixbuf), menu_icon_width);
2480 get_icon_allocations (GtkEntry *entry,
2481 GtkAllocation *primary,
2482 GtkAllocation *secondary)
2485 GtkEntryPrivate *priv = entry->priv;
2486 gint x, y, width, height;
2488 get_text_area_size (entry, &x, &y, &width, &height);
2490 if (gtk_widget_has_focus (GTK_WIDGET (entry)) && !priv->interior_focus)
2491 y += priv->focus_width;
2494 primary->height = height;
2495 primary->width = get_icon_width (entry, GTK_ENTRY_ICON_PRIMARY);
2496 if (primary->width > 0)
2497 primary->width += 2 * priv->icon_margin;
2500 secondary->height = height;
2501 secondary->width = get_icon_width (entry, GTK_ENTRY_ICON_SECONDARY);
2502 if (secondary->width > 0)
2503 secondary->width += 2 * priv->icon_margin;
2505 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
2507 primary->x = x + width - primary->width;
2513 secondary->x = x + width - secondary->width;
2519 begin_change (GtkEntry *entry)
2521 GtkEntryPrivate *priv = entry->priv;
2523 priv->change_count++;
2527 end_change (GtkEntry *entry)
2529 GtkEditable *editable = GTK_EDITABLE (entry);
2530 GtkEntryPrivate *priv = entry->priv;
2532 g_return_if_fail (priv->change_count > 0);
2534 priv->change_count--;
2536 if (priv->change_count == 0)
2538 if (priv->real_changed)
2540 g_signal_emit_by_name (editable, "changed");
2541 priv->real_changed = FALSE;
2547 emit_changed (GtkEntry *entry)
2549 GtkEditable *editable = GTK_EDITABLE (entry);
2550 GtkEntryPrivate *priv = entry->priv;
2552 if (priv->change_count == 0)
2553 g_signal_emit_by_name (editable, "changed");
2555 priv->real_changed = TRUE;
2559 gtk_entry_destroy (GtkWidget *widget)
2561 GtkEntry *entry = GTK_ENTRY (widget);
2562 GtkEntryPrivate *priv = entry->priv;
2564 priv->current_pos = priv->selection_bound = 0;
2565 _gtk_entry_reset_im_context (entry);
2566 gtk_entry_reset_layout (entry);
2568 if (priv->blink_timeout)
2570 g_source_remove (priv->blink_timeout);
2571 priv->blink_timeout = 0;
2574 if (priv->recompute_idle)
2576 g_source_remove (priv->recompute_idle);
2577 priv->recompute_idle = 0;
2580 GTK_WIDGET_CLASS (gtk_entry_parent_class)->destroy (widget);
2584 gtk_entry_dispose (GObject *object)
2586 GtkEntry *entry = GTK_ENTRY (object);
2587 GtkEntryPrivate *priv = entry->priv;
2590 gtk_entry_set_icon_from_pixbuf (entry, GTK_ENTRY_ICON_PRIMARY, NULL);
2591 gtk_entry_set_icon_tooltip_markup (entry, GTK_ENTRY_ICON_PRIMARY, NULL);
2592 gtk_entry_set_icon_from_pixbuf (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
2593 gtk_entry_set_icon_tooltip_markup (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
2597 buffer_disconnect_signals (entry);
2598 g_object_unref (priv->buffer);
2599 priv->buffer = NULL;
2602 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (object)));
2603 g_signal_handlers_disconnect_by_func (keymap, keymap_state_changed, entry);
2604 g_signal_handlers_disconnect_by_func (keymap, keymap_direction_changed, entry);
2605 G_OBJECT_CLASS (gtk_entry_parent_class)->dispose (object);
2609 gtk_entry_finalize (GObject *object)
2611 GtkEntry *entry = GTK_ENTRY (object);
2612 GtkEntryPrivate *priv = entry->priv;
2613 EntryIconInfo *icon_info = NULL;
2616 for (i = 0; i < MAX_ICONS; i++)
2618 if ((icon_info = priv->icons[i]) != NULL)
2620 if (icon_info->target_list != NULL)
2622 gtk_target_list_unref (icon_info->target_list);
2623 icon_info->target_list = NULL;
2626 g_slice_free (EntryIconInfo, icon_info);
2627 priv->icons[i] = NULL;
2631 gtk_entry_set_completion (entry, NULL);
2633 if (priv->cached_layout)
2634 g_object_unref (priv->cached_layout);
2636 g_object_unref (priv->im_context);
2638 if (priv->blink_timeout)
2639 g_source_remove (priv->blink_timeout);
2641 if (priv->recompute_idle)
2642 g_source_remove (priv->recompute_idle);
2644 g_free (priv->placeholder_text);
2645 g_free (priv->im_module);
2647 G_OBJECT_CLASS (gtk_entry_parent_class)->finalize (object);
2651 gtk_entry_get_display_mode (GtkEntry *entry)
2653 GtkEntryPrivate *priv = entry->priv;
2656 return DISPLAY_NORMAL;
2658 if (priv->invisible_char == 0 && priv->invisible_char_set)
2659 return DISPLAY_BLANK;
2661 return DISPLAY_INVISIBLE;
2665 gtk_entry_get_display_text (GtkEntry *entry,
2669 GtkEntryPasswordHint *password_hint;
2670 GtkEntryPrivate *priv;
2671 gunichar invisible_char;
2682 text = gtk_entry_buffer_get_text (get_buffer (entry));
2683 length = gtk_entry_buffer_get_length (get_buffer (entry));
2687 if (start_pos > length)
2690 if (end_pos <= start_pos)
2691 return g_strdup ("");
2692 else if (priv->visible)
2694 start = g_utf8_offset_to_pointer (text, start_pos);
2695 end = g_utf8_offset_to_pointer (start, end_pos - start_pos);
2696 return g_strndup (start, end - start);
2700 str = g_string_sized_new (length * 2);
2702 /* Figure out what our invisible char is and encode it */
2703 if (!priv->invisible_char)
2704 invisible_char = priv->invisible_char_set ? ' ' : '*';
2706 invisible_char = priv->invisible_char;
2707 char_len = g_unichar_to_utf8 (invisible_char, char_str);
2710 * Add hidden characters for each character in the text
2711 * buffer. If there is a password hint, then keep that
2712 * character visible.
2715 password_hint = g_object_get_qdata (G_OBJECT (entry), quark_password_hint);
2716 for (i = start_pos; i < end_pos; ++i)
2718 if (password_hint && i == password_hint->position)
2720 start = g_utf8_offset_to_pointer (text, i);
2721 g_string_append_len (str, start, g_utf8_next_char (start) - start);
2725 g_string_append_len (str, char_str, char_len);
2729 return g_string_free (str, FALSE);
2734 update_cursors (GtkWidget *widget)
2736 GtkEntry *entry = GTK_ENTRY (widget);
2737 GtkEntryPrivate *priv = entry->priv;
2738 EntryIconInfo *icon_info = NULL;
2739 GdkDisplay *display;
2743 for (i = 0; i < MAX_ICONS; i++)
2745 if ((icon_info = priv->icons[i]) != NULL)
2747 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
2748 gdk_window_show_unraised (icon_info->window);
2750 /* The icon windows are not children of the visible entry window,
2751 * thus we can't just inherit the xterm cursor. Slight complication
2752 * here is that for the entry, insensitive => arrow cursor, but for
2753 * an icon in a sensitive entry, insensitive => xterm cursor.
2755 if (gtk_widget_is_sensitive (widget) &&
2756 (icon_info->insensitive ||
2757 (icon_info->nonactivatable && icon_info->target_list == NULL)))
2759 display = gtk_widget_get_display (widget);
2760 cursor = gdk_cursor_new_for_display (display, GDK_XTERM);
2761 gdk_window_set_cursor (icon_info->window, cursor);
2762 g_object_unref (cursor);
2766 gdk_window_set_cursor (icon_info->window, NULL);
2773 realize_icon_info (GtkWidget *widget,
2774 GtkEntryIconPosition icon_pos)
2776 GtkEntry *entry = GTK_ENTRY (widget);
2777 GtkEntryPrivate *priv = entry->priv;
2778 EntryIconInfo *icon_info = priv->icons[icon_pos];
2779 GdkWindowAttr attributes;
2780 gint attributes_mask;
2782 g_return_if_fail (icon_info != NULL);
2786 attributes.width = 1;
2787 attributes.height = 1;
2788 attributes.window_type = GDK_WINDOW_CHILD;
2789 attributes.wclass = GDK_INPUT_ONLY;
2790 attributes.event_mask = gtk_widget_get_events (widget);
2791 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
2792 GDK_BUTTON_RELEASE_MASK |
2793 GDK_BUTTON1_MOTION_MASK |
2794 GDK_BUTTON3_MOTION_MASK |
2795 GDK_POINTER_MOTION_HINT_MASK |
2796 GDK_POINTER_MOTION_MASK |
2797 GDK_ENTER_NOTIFY_MASK |
2798 GDK_LEAVE_NOTIFY_MASK);
2799 attributes_mask = GDK_WA_X | GDK_WA_Y;
2801 icon_info->window = gdk_window_new (gtk_widget_get_window (widget),
2804 gdk_window_set_user_data (icon_info->window, widget);
2806 gtk_widget_queue_resize (widget);
2809 static EntryIconInfo*
2810 construct_icon_info (GtkWidget *widget,
2811 GtkEntryIconPosition icon_pos)
2813 GtkEntry *entry = GTK_ENTRY (widget);
2814 GtkEntryPrivate *priv = entry->priv;
2815 EntryIconInfo *icon_info;
2817 g_return_val_if_fail (priv->icons[icon_pos] == NULL, NULL);
2819 icon_info = g_slice_new0 (EntryIconInfo);
2820 priv->icons[icon_pos] = icon_info;
2822 if (gtk_widget_get_realized (widget))
2823 realize_icon_info (widget, icon_pos);
2829 gtk_entry_map (GtkWidget *widget)
2831 GtkEntry *entry = GTK_ENTRY (widget);
2832 GtkEntryPrivate *priv = entry->priv;
2833 EntryIconInfo *icon_info = NULL;
2836 GTK_WIDGET_CLASS (gtk_entry_parent_class)->map (widget);
2838 gdk_window_show (priv->text_area);
2840 for (i = 0; i < MAX_ICONS; i++)
2842 if ((icon_info = priv->icons[i]) != NULL)
2844 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
2845 gdk_window_show (icon_info->window);
2849 update_cursors (widget);
2853 gtk_entry_unmap (GtkWidget *widget)
2855 GtkEntry *entry = GTK_ENTRY (widget);
2856 GtkEntryPrivate *priv = entry->priv;
2857 EntryIconInfo *icon_info = NULL;
2860 for (i = 0; i < MAX_ICONS; i++)
2862 if ((icon_info = priv->icons[i]) != NULL)
2864 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
2865 gdk_window_hide (icon_info->window);
2869 gdk_window_hide (priv->text_area);
2871 GTK_WIDGET_CLASS (gtk_entry_parent_class)->unmap (widget);
2875 gtk_entry_realize (GtkWidget *widget)
2878 GtkEntryPrivate *priv;
2879 EntryIconInfo *icon_info;
2881 GdkWindowAttr attributes;
2882 gint attributes_mask;
2883 gint frame_x, frame_y;
2886 gtk_widget_set_realized (widget, TRUE);
2887 window = gtk_widget_get_parent_window (widget);
2888 gtk_widget_set_window (widget, window);
2889 g_object_ref (window);
2891 entry = GTK_ENTRY (widget);
2894 attributes.window_type = GDK_WINDOW_CHILD;
2895 attributes.wclass = GDK_INPUT_ONLY;
2896 attributes.event_mask = gtk_widget_get_events (widget);
2897 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
2898 GDK_BUTTON_RELEASE_MASK |
2899 GDK_BUTTON1_MOTION_MASK |
2900 GDK_BUTTON3_MOTION_MASK |
2901 GDK_POINTER_MOTION_HINT_MASK |
2902 GDK_POINTER_MOTION_MASK |
2903 GDK_ENTER_NOTIFY_MASK |
2904 GDK_LEAVE_NOTIFY_MASK);
2905 attributes_mask = GDK_WA_X | GDK_WA_Y;
2907 get_text_area_size (entry, &attributes.x, &attributes.y, &attributes.width, &attributes.height);
2909 get_frame_size (entry, TRUE, &frame_x, &frame_y, NULL, NULL);
2910 attributes.x += frame_x;
2911 attributes.y += frame_y;
2913 if (gtk_widget_is_sensitive (widget))
2915 attributes.cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
2916 attributes_mask |= GDK_WA_CURSOR;
2919 priv->text_area = gdk_window_new (gtk_widget_get_window (widget),
2923 gdk_window_set_user_data (priv->text_area, entry);
2925 if (attributes_mask & GDK_WA_CURSOR)
2926 g_object_unref (attributes.cursor);
2928 gtk_im_context_set_client_window (priv->im_context, priv->text_area);
2930 gtk_entry_adjust_scroll (entry);
2931 gtk_entry_update_primary_selection (entry);
2934 /* If the icon positions are already setup, create their windows.
2935 * Otherwise if they don't exist yet, then construct_icon_info()
2936 * will create the windows once the widget is already realized.
2938 for (i = 0; i < MAX_ICONS; i++)
2940 if ((icon_info = priv->icons[i]) != NULL)
2942 if (icon_info->window == NULL)
2943 realize_icon_info (widget, i);
2949 gtk_entry_unrealize (GtkWidget *widget)
2951 GtkEntry *entry = GTK_ENTRY (widget);
2952 GtkEntryPrivate *priv = entry->priv;
2953 GtkClipboard *clipboard;
2954 EntryIconInfo *icon_info;
2957 gtk_entry_reset_layout (entry);
2959 gtk_im_context_set_client_window (priv->im_context, NULL);
2961 clipboard = gtk_widget_get_clipboard (widget, GDK_SELECTION_PRIMARY);
2962 if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (entry))
2963 gtk_clipboard_clear (clipboard);
2965 if (priv->text_area)
2967 gdk_window_set_user_data (priv->text_area, NULL);
2968 gdk_window_destroy (priv->text_area);
2969 priv->text_area = NULL;
2972 if (priv->popup_menu)
2974 gtk_widget_destroy (priv->popup_menu);
2975 priv->popup_menu = NULL;
2978 GTK_WIDGET_CLASS (gtk_entry_parent_class)->unrealize (widget);
2980 for (i = 0; i < MAX_ICONS; i++)
2982 if ((icon_info = priv->icons[i]) != NULL)
2984 if (icon_info->window != NULL)
2986 gdk_window_destroy (icon_info->window);
2987 icon_info->window = NULL;
2994 _gtk_entry_get_borders (GtkEntry *entry,
2998 GtkEntryPrivate *priv = entry->priv;
2999 GtkWidget *widget = GTK_WIDGET (entry);
3001 if (priv->has_frame)
3003 GtkStyleContext *context;
3006 context = gtk_widget_get_style_context (widget);
3007 gtk_style_context_get_padding (context, 0, &padding);
3009 *xborder = padding.left;
3010 *yborder = padding.top;
3018 if (!priv->interior_focus)
3020 *xborder += priv->focus_width;
3021 *yborder += priv->focus_width;
3026 gtk_entry_get_preferred_width (GtkWidget *widget,
3030 GtkEntry *entry = GTK_ENTRY (widget);
3031 GtkEntryPrivate *priv = entry->priv;
3032 PangoFontMetrics *metrics;
3033 gint xborder, yborder;
3034 GtkBorder inner_border;
3035 PangoContext *context;
3036 GtkStyleContext *style_context;
3037 GtkStateFlags state;
3038 gint icon_widths = 0;
3042 context = gtk_widget_get_pango_context (widget);
3044 style_context = gtk_widget_get_style_context (widget);
3045 state = gtk_widget_get_state_flags (widget);
3047 metrics = pango_context_get_metrics (context,
3048 gtk_style_context_get_font (style_context, state),
3049 pango_context_get_language (context));
3051 _gtk_entry_get_borders (entry, &xborder, &yborder);
3052 _gtk_entry_effective_inner_border (entry, &inner_border);
3054 if (priv->width_chars < 0)
3055 width = MIN_ENTRY_WIDTH + xborder * 2 + inner_border.left + inner_border.right;
3058 gint char_width = pango_font_metrics_get_approximate_char_width (metrics);
3059 gint digit_width = pango_font_metrics_get_approximate_digit_width (metrics);
3060 gint char_pixels = (MAX (char_width, digit_width) + PANGO_SCALE - 1) / PANGO_SCALE;
3062 width = char_pixels * priv->width_chars + xborder * 2 + inner_border.left + inner_border.right;
3065 for (i = 0; i < MAX_ICONS; i++)
3067 icon_width = get_icon_width (entry, i);
3069 icon_widths += icon_width + 2 * priv->icon_margin;
3072 if (icon_widths > width)
3073 width += icon_widths;
3075 pango_font_metrics_unref (metrics);
3082 gtk_entry_get_preferred_height (GtkWidget *widget,
3086 GtkEntry *entry = GTK_ENTRY (widget);
3087 GtkEntryPrivate *priv = entry->priv;
3088 PangoFontMetrics *metrics;
3089 gint xborder, yborder;
3090 GtkBorder inner_border;
3091 GtkStyleContext *style_context;
3092 GtkStateFlags state;
3093 PangoContext *context;
3096 context = gtk_widget_get_pango_context (widget);
3098 style_context = gtk_widget_get_style_context (widget);
3099 state = gtk_widget_get_state_flags (widget);
3101 metrics = pango_context_get_metrics (context,
3102 gtk_style_context_get_font (style_context, state),
3103 pango_context_get_language (context));
3105 priv->ascent = pango_font_metrics_get_ascent (metrics);
3106 priv->descent = pango_font_metrics_get_descent (metrics);
3108 _gtk_entry_get_borders (entry, &xborder, &yborder);
3109 _gtk_entry_effective_inner_border (entry, &inner_border);
3111 height = PANGO_PIXELS (priv->ascent + priv->descent) + yborder * 2 + inner_border.top + inner_border.bottom;
3113 pango_font_metrics_unref (metrics);
3120 place_windows (GtkEntry *entry)
3122 GtkWidget *widget = GTK_WIDGET (entry);
3123 GtkEntryPrivate *priv = entry->priv;
3124 gint x, y, width, height;
3125 gint frame_x, frame_y;
3126 GtkAllocation primary;
3127 GtkAllocation secondary;
3128 EntryIconInfo *icon_info = NULL;
3130 get_frame_size (entry, TRUE, &frame_x, &frame_y, NULL, NULL);
3131 get_text_area_size (entry, &x, &y, &width, &height);
3132 get_icon_allocations (entry, &primary, &secondary);
3134 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3135 y += priv->focus_width;
3137 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
3138 x += secondary.width;
3141 width -= primary.width + secondary.width;
3145 primary.x += frame_x;
3146 primary.y += frame_y;
3147 secondary.x += frame_x;
3148 secondary.y += frame_y;
3150 if ((icon_info = priv->icons[GTK_ENTRY_ICON_PRIMARY]) != NULL)
3151 gdk_window_move_resize (icon_info->window,
3152 primary.x, primary.y,
3153 primary.width, primary.height);
3155 if ((icon_info = priv->icons[GTK_ENTRY_ICON_SECONDARY]) != NULL)
3156 gdk_window_move_resize (icon_info->window,
3157 secondary.x, secondary.y,
3158 secondary.width, secondary.height);
3160 gdk_window_move_resize (priv->text_area, x, y, width, height);
3164 gtk_entry_get_text_area_size (GtkEntry *entry,
3170 GtkEntryPrivate *priv = entry->priv;
3171 GtkWidget *widget = GTK_WIDGET (entry);
3172 GtkAllocation allocation;
3173 GtkRequisition requisition;
3175 gint xborder, yborder;
3177 gtk_widget_get_preferred_size (widget, &requisition, NULL);
3178 gtk_widget_get_allocation (widget, &allocation);
3179 _gtk_entry_get_borders (entry, &xborder, &yborder);
3181 if (gtk_widget_get_realized (widget))
3182 get_frame_size (entry, TRUE, NULL, NULL, NULL, &frame_height);
3184 frame_height = requisition.height;
3186 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3187 frame_height -= 2 * priv->focus_width;
3193 *y = frame_height / 2 - (requisition.height - yborder * 2) / 2;
3196 *width = allocation.width - xborder * 2;
3199 *height = requisition.height - yborder * 2;
3203 get_text_area_size (GtkEntry *entry,
3209 GtkEntryClass *class;
3211 g_return_if_fail (GTK_IS_ENTRY (entry));
3213 class = GTK_ENTRY_GET_CLASS (entry);
3215 if (class->get_text_area_size)
3216 class->get_text_area_size (entry, x, y, width, height);
3221 get_frame_size (GtkEntry *entry,
3222 gboolean relative_to_window,
3228 GtkEntryPrivate *priv = entry->priv;
3229 GtkAllocation allocation;
3230 GtkRequisition requisition;
3231 GtkWidget *widget = GTK_WIDGET (entry);
3233 gtk_widget_get_preferred_size (widget, &requisition, NULL);
3234 gtk_widget_get_allocation (widget, &allocation);
3237 *x = relative_to_window ? allocation.x : 0;
3241 if (priv->is_cell_renderer)
3244 *y = (allocation.height - requisition.height) / 2;
3246 if (relative_to_window)
3251 *width = allocation.width;
3255 if (priv->is_cell_renderer)
3256 *height = allocation.height;
3258 *height = requisition.height;
3263 _gtk_entry_effective_inner_border (GtkEntry *entry,
3266 GtkBorder *tmp_border;
3268 tmp_border = g_object_get_qdata (G_OBJECT (entry), quark_inner_border);
3272 *border = *tmp_border;
3276 gtk_widget_style_get (GTK_WIDGET (entry), "inner-border", &tmp_border, NULL);
3280 *border = *tmp_border;
3281 gtk_border_free (tmp_border);
3285 *border = default_inner_border;
3289 gtk_entry_size_allocate (GtkWidget *widget,
3290 GtkAllocation *allocation)
3292 GtkEntry *entry = GTK_ENTRY (widget);
3294 gtk_widget_set_allocation (widget, allocation);
3296 if (gtk_widget_get_realized (widget))
3298 GtkEntryCompletion* completion;
3300 place_windows (entry);
3301 gtk_entry_recompute (entry);
3303 completion = gtk_entry_get_completion (entry);
3304 if (completion && gtk_widget_get_mapped (completion->priv->popup_window))
3305 _gtk_entry_completion_resize_popup (completion);
3310 should_prelight (GtkEntry *entry,
3311 GtkEntryIconPosition icon_pos)
3313 GtkEntryPrivate *priv = entry->priv;
3314 EntryIconInfo *icon_info = priv->icons[icon_pos];
3320 if (icon_info->nonactivatable && icon_info->target_list == NULL)
3323 if (icon_info->pressed)
3326 gtk_widget_style_get (GTK_WIDGET (entry),
3327 "icon-prelight", &prelight,
3334 draw_icon (GtkWidget *widget,
3336 GtkEntryIconPosition icon_pos)
3338 GtkEntry *entry = GTK_ENTRY (widget);
3339 GtkEntryPrivate *priv = entry->priv;
3340 EntryIconInfo *icon_info = priv->icons[icon_pos];
3342 gint x, y, width, height;
3343 GtkStyleContext *context;
3348 gtk_entry_ensure_pixbuf (entry, icon_pos);
3350 if (icon_info->pixbuf == NULL)
3353 width = gdk_window_get_width (icon_info->window);
3354 height = gdk_window_get_height (icon_info->window);
3356 context = gtk_widget_get_style_context (widget);
3358 /* size_allocate hasn't been called yet. These are the default values.
3360 if (width == 1 || height == 1)
3363 pixbuf = icon_info->pixbuf;
3364 g_object_ref (pixbuf);
3366 if (gdk_pixbuf_get_height (pixbuf) > height)
3368 GdkPixbuf *temp_pixbuf;
3371 scale = height - 2 * priv->icon_margin;
3372 temp_pixbuf = gdk_pixbuf_scale_simple (pixbuf, scale, scale,
3373 GDK_INTERP_BILINEAR);
3374 g_object_unref (pixbuf);
3375 pixbuf = temp_pixbuf;
3378 x = (width - gdk_pixbuf_get_width (pixbuf)) / 2;
3379 y = (height - gdk_pixbuf_get_height (pixbuf)) / 2;
3381 gtk_render_icon (context, cr, pixbuf, x, y);
3383 g_object_unref (pixbuf);
3388 gtk_entry_draw_frame (GtkWidget *widget,
3389 GtkStyleContext *context,
3392 GtkEntry *entry = GTK_ENTRY (widget);
3393 GtkEntryPrivate *priv = entry->priv;
3394 gint x = 0, y = 0, width, height;
3395 gint frame_x, frame_y;
3399 get_frame_size (GTK_ENTRY (widget), FALSE, &frame_x, &frame_y, &width, &height);
3401 cairo_translate (cr, frame_x, frame_y);
3403 /* Fix a problem with some themes which assume that entry->text_area's
3404 * width equals widget->window's width
3405 * http://bugzilla.gnome.org/show_bug.cgi?id=466000 */
3406 if (GTK_IS_SPIN_BUTTON (widget))
3408 gint xborder, yborder;
3410 gtk_entry_get_text_area_size (GTK_ENTRY (widget), &x, NULL, &width, NULL);
3411 _gtk_entry_get_borders (GTK_ENTRY (widget), &xborder, &yborder);
3414 width += xborder * 2;
3417 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3419 x += priv->focus_width;
3420 y += priv->focus_width;
3421 width -= 2 * priv->focus_width;
3422 height -= 2 * priv->focus_width;
3425 gtk_render_background (context, cr,
3426 x, y, width, height);
3428 if (priv->has_frame)
3429 gtk_render_frame (context, cr,
3430 x, y, width, height);
3432 gtk_entry_draw_progress (widget, context, cr);
3434 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3436 x -= priv->focus_width;
3437 y -= priv->focus_width;
3438 width += 2 * priv->focus_width;
3439 height += 2 * priv->focus_width;
3441 gtk_render_focus (context, cr,
3442 0, 0, width, height);
3449 get_progress_area (GtkWidget *widget,
3455 GtkEntry *entry = GTK_ENTRY (widget);
3456 GtkEntryPrivate *private = entry->priv;
3457 GtkBorder *progress_border;
3459 get_text_area_size (entry, x, y, width, height);
3461 if (!private->interior_focus)
3463 *x -= private->focus_width;
3464 *y -= private->focus_width;
3465 *width += 2 * private->focus_width;
3466 *height += 2 * private->focus_width;
3469 gtk_widget_style_get (widget, "progress-border", &progress_border, NULL);
3471 if (progress_border)
3473 *x += progress_border->left;
3474 *y += progress_border->top;
3475 *width -= progress_border->left + progress_border->right;
3476 *height -= progress_border->top + progress_border->bottom;
3478 gtk_border_free (progress_border);
3481 if (private->progress_pulse_mode)
3483 gdouble value = private->progress_pulse_current;
3485 *x += (gint) floor(value * (*width));
3486 *width = (gint) ceil(private->progress_pulse_fraction * (*width));
3488 else if (private->progress_fraction > 0)
3490 gdouble value = private->progress_fraction;
3492 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
3496 bar_width = floor(value * (*width) + 0.5);
3497 *x += *width - bar_width;
3502 *width = (gint) floor(value * (*width) + 0.5);
3513 gtk_entry_draw_progress (GtkWidget *widget,
3514 GtkStyleContext *context,
3517 gint x, y, width, height;
3519 get_progress_area (widget, &x, &y, &width, &height);
3521 if ((width <= 0) || (height <= 0))
3524 gtk_style_context_save (context);
3525 gtk_style_context_add_class (context, GTK_STYLE_CLASS_PROGRESSBAR);
3527 gtk_render_activity (context, cr,
3528 x, y, width, height);
3530 gtk_style_context_restore (context);
3534 gtk_entry_draw (GtkWidget *widget,
3537 GtkEntry *entry = GTK_ENTRY (widget);
3538 GtkStyleContext *context;
3539 GtkStateFlags state;
3540 GtkEntryPrivate *priv = entry->priv;
3543 context = gtk_widget_get_style_context (widget);
3544 state = gtk_widget_get_state_flags (widget);
3546 gtk_style_context_save (context);
3547 gtk_style_context_set_state (context, state);
3549 /* Draw entry_bg, shadow, progress and focus */
3550 gtk_entry_draw_frame (widget, context, cr);
3552 /* Draw text and cursor */
3555 gtk_cairo_transform_to_window (cr, widget, priv->text_area);
3557 if (priv->dnd_position != -1)
3558 gtk_entry_draw_cursor (GTK_ENTRY (widget), cr, CURSOR_DND);
3560 gtk_entry_draw_text (GTK_ENTRY (widget), cr);
3562 /* When no text is being displayed at all, don't show the cursor */
3563 if (gtk_entry_get_display_mode (entry) != DISPLAY_BLANK &&
3564 gtk_widget_has_focus (widget) &&
3565 priv->selection_bound == priv->current_pos && priv->cursor_visible)
3566 gtk_entry_draw_cursor (GTK_ENTRY (widget), cr, CURSOR_STANDARD);
3571 for (i = 0; i < MAX_ICONS; i++)
3573 EntryIconInfo *icon_info = priv->icons[i];
3575 if (icon_info != NULL)
3579 gtk_cairo_transform_to_window (cr, widget, icon_info->window);
3581 draw_icon (widget, cr, i);
3587 gtk_style_context_restore (context);
3593 gtk_entry_enter_notify (GtkWidget *widget,
3594 GdkEventCrossing *event)
3596 GtkEntry *entry = GTK_ENTRY (widget);
3597 GtkEntryPrivate *priv = entry->priv;
3600 for (i = 0; i < MAX_ICONS; i++)
3602 EntryIconInfo *icon_info = priv->icons[i];
3604 if (icon_info != NULL && event->window == icon_info->window)
3606 if (should_prelight (entry, i))
3608 icon_info->prelight = TRUE;
3609 gtk_widget_queue_draw (widget);
3620 gtk_entry_leave_notify (GtkWidget *widget,
3621 GdkEventCrossing *event)
3623 GtkEntry *entry = GTK_ENTRY (widget);
3624 GtkEntryPrivate *priv = entry->priv;
3627 for (i = 0; i < MAX_ICONS; i++)
3629 EntryIconInfo *icon_info = priv->icons[i];
3631 if (icon_info != NULL && event->window == icon_info->window)
3633 /* a grab means that we may never see the button release */
3634 if (event->mode == GDK_CROSSING_GRAB || event->mode == GDK_CROSSING_GTK_GRAB)
3635 icon_info->pressed = FALSE;
3637 if (should_prelight (entry, i))
3639 icon_info->prelight = FALSE;
3640 gtk_widget_queue_draw (widget);
3651 gtk_entry_get_pixel_ranges (GtkEntry *entry,
3655 gint start_char, end_char;
3657 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start_char, &end_char))
3659 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
3660 PangoLayoutLine *line = pango_layout_get_lines_readonly (layout)->data;
3661 const char *text = pango_layout_get_text (layout);
3662 gint start_index = g_utf8_offset_to_pointer (text, start_char) - text;
3663 gint end_index = g_utf8_offset_to_pointer (text, end_char) - text;
3664 gint real_n_ranges, i;
3666 pango_layout_line_get_x_ranges (line, start_index, end_index, ranges, &real_n_ranges);
3672 for (i = 0; i < real_n_ranges; ++i)
3674 r[2 * i + 1] = (r[2 * i + 1] - r[2 * i]) / PANGO_SCALE;
3675 r[2 * i] = r[2 * i] / PANGO_SCALE;
3680 *n_ranges = real_n_ranges;
3692 in_selection (GtkEntry *entry,
3697 gint retval = FALSE;
3699 gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
3701 for (i = 0; i < n_ranges; ++i)
3703 if (x >= ranges[2 * i] && x < ranges[2 * i] + ranges[2 * i + 1])
3715 gtk_entry_button_press (GtkWidget *widget,
3716 GdkEventButton *event)
3718 GtkEntry *entry = GTK_ENTRY (widget);
3719 GtkEditable *editable = GTK_EDITABLE (widget);
3720 GtkEntryPrivate *priv = entry->priv;
3721 EntryIconInfo *icon_info = NULL;
3723 gint sel_start, sel_end;
3726 for (i = 0; i < MAX_ICONS; i++)
3728 icon_info = priv->icons[i];
3730 if (!icon_info || icon_info->insensitive)
3733 if (event->window == icon_info->window)
3735 if (should_prelight (entry, i))
3737 icon_info->prelight = FALSE;
3738 gtk_widget_queue_draw (widget);
3741 priv->start_x = event->x;
3742 priv->start_y = event->y;
3743 icon_info->pressed = TRUE;
3745 if (!icon_info->nonactivatable)
3746 g_signal_emit (entry, signals[ICON_PRESS], 0, i, event);
3752 if (event->window != priv->text_area ||
3753 (priv->button && event->button != priv->button))
3756 gtk_entry_reset_blink_time (entry);
3758 priv->button = event->button;
3760 if (!gtk_widget_has_focus (widget))
3762 priv->in_click = TRUE;
3763 gtk_widget_grab_focus (widget);
3764 priv->in_click = FALSE;
3767 tmp_pos = gtk_entry_find_position (entry, event->x + priv->scroll_offset);
3769 if (event->button == 1)
3771 gboolean have_selection = gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end);
3773 priv->select_words = FALSE;
3774 priv->select_lines = FALSE;
3776 if (event->state & GDK_SHIFT_MASK)
3778 _gtk_entry_reset_im_context (entry);
3780 if (!have_selection) /* select from the current position to the clicked position */
3781 sel_start = sel_end = priv->current_pos;
3783 if (tmp_pos > sel_start && tmp_pos < sel_end)
3785 /* Truncate current selection, but keep it as big as possible */
3786 if (tmp_pos - sel_start > sel_end - tmp_pos)
3787 gtk_entry_set_positions (entry, sel_start, tmp_pos);
3789 gtk_entry_set_positions (entry, tmp_pos, sel_end);
3793 gboolean extend_to_left;
3796 /* Figure out what click selects and extend current selection */
3797 switch (event->type)
3799 case GDK_BUTTON_PRESS:
3800 gtk_entry_set_positions (entry, tmp_pos, tmp_pos);
3803 case GDK_2BUTTON_PRESS:
3804 priv->select_words = TRUE;
3805 gtk_entry_select_word (entry);
3808 case GDK_3BUTTON_PRESS:
3809 priv->select_lines = TRUE;
3810 gtk_entry_select_line (entry);
3817 start = MIN (priv->current_pos, priv->selection_bound);
3818 start = MIN (sel_start, start);
3820 end = MAX (priv->current_pos, priv->selection_bound);
3821 end = MAX (sel_end, end);
3823 if (tmp_pos == sel_start || tmp_pos == sel_end)
3824 extend_to_left = (tmp_pos == start);
3826 extend_to_left = (end == sel_end);
3829 gtk_entry_set_positions (entry, start, end);
3831 gtk_entry_set_positions (entry, end, start);
3834 else /* no shift key */
3835 switch (event->type)
3837 case GDK_BUTTON_PRESS:
3838 if (in_selection (entry, event->x + priv->scroll_offset))
3840 /* Click inside the selection - we'll either start a drag, or
3841 * clear the selection
3843 priv->in_drag = TRUE;
3844 priv->drag_start_x = event->x + priv->scroll_offset;
3845 priv->drag_start_y = event->y;
3848 gtk_editable_set_position (editable, tmp_pos);
3851 case GDK_2BUTTON_PRESS:
3852 /* We ALWAYS receive a GDK_BUTTON_PRESS immediately before
3853 * receiving a GDK_2BUTTON_PRESS so we need to reset
3854 * priv->in_drag which may have been set above
3856 priv->in_drag = FALSE;
3857 priv->select_words = TRUE;
3858 gtk_entry_select_word (entry);
3861 case GDK_3BUTTON_PRESS:
3862 /* We ALWAYS receive a GDK_BUTTON_PRESS immediately before
3863 * receiving a GDK_3BUTTON_PRESS so we need to reset
3864 * priv->in_drag which may have been set above
3866 priv->in_drag = FALSE;
3867 priv->select_lines = TRUE;
3868 gtk_entry_select_line (entry);
3877 else if (event->button == 2 && event->type == GDK_BUTTON_PRESS)
3881 priv->insert_pos = tmp_pos;
3882 gtk_entry_paste (entry, GDK_SELECTION_PRIMARY);
3887 gtk_widget_error_bell (widget);
3890 else if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
3892 gtk_entry_do_popup (entry, event);
3893 priv->button = 0; /* Don't wait for release, since the menu will gtk_grab_add */
3902 gtk_entry_button_release (GtkWidget *widget,
3903 GdkEventButton *event)
3905 GtkEntry *entry = GTK_ENTRY (widget);
3906 GtkEntryPrivate *priv = entry->priv;
3907 EntryIconInfo *icon_info = NULL;
3910 for (i = 0; i < MAX_ICONS; i++)
3912 icon_info = priv->icons[i];
3914 if (!icon_info || icon_info->insensitive)
3917 if (event->window == icon_info->window)
3919 icon_info->pressed = FALSE;
3921 if (should_prelight (entry, i) &&
3922 event->x >= 0 && event->y >= 0 &&
3923 event->x < gdk_window_get_width (icon_info->window) &&
3924 event->y < gdk_window_get_height (icon_info->window))
3926 icon_info->prelight = TRUE;
3927 gtk_widget_queue_draw (widget);
3930 if (!icon_info->nonactivatable)
3931 g_signal_emit (entry, signals[ICON_RELEASE], 0, i, event);
3937 if (event->window != priv->text_area || priv->button != event->button)
3942 gint tmp_pos = gtk_entry_find_position (entry, priv->drag_start_x);
3944 gtk_editable_set_position (GTK_EDITABLE (entry), tmp_pos);
3951 gtk_entry_update_primary_selection (entry);
3957 _gtk_entry_get_selected_text (GtkEntry *entry)
3959 GtkEditable *editable = GTK_EDITABLE (entry);
3960 gint start_text, end_text;
3963 if (gtk_editable_get_selection_bounds (editable, &start_text, &end_text))
3964 text = gtk_editable_get_chars (editable, start_text, end_text);
3970 gtk_entry_motion_notify (GtkWidget *widget,
3971 GdkEventMotion *event)
3973 GtkEntry *entry = GTK_ENTRY (widget);
3974 GtkEntryPrivate *priv = entry->priv;
3975 EntryIconInfo *icon_info = NULL;
3979 for (i = 0; i < MAX_ICONS; i++)
3981 icon_info = priv->icons[i];
3983 if (!icon_info || icon_info->insensitive)
3986 if (event->window == icon_info->window)
3988 if (icon_info->pressed &&
3989 icon_info->target_list != NULL &&
3990 gtk_drag_check_threshold (widget,
3996 icon_info->in_drag = TRUE;
3997 icon_info->pressed = FALSE;
3998 gtk_drag_begin (widget,
3999 icon_info->target_list,
4009 if (priv->mouse_cursor_obscured)
4013 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
4014 gdk_window_set_cursor (priv->text_area, cursor);
4015 g_object_unref (cursor);
4016 priv->mouse_cursor_obscured = FALSE;
4019 if (event->window != priv->text_area || priv->button != 1)
4022 if (priv->select_lines)
4025 gdk_event_request_motions (event);
4029 if (gtk_entry_get_display_mode (entry) == DISPLAY_NORMAL &&
4030 gtk_drag_check_threshold (widget,
4031 priv->drag_start_x, priv->drag_start_y,
4032 event->x + priv->scroll_offset, event->y))
4034 GdkDragContext *context;
4035 GtkTargetList *target_list = gtk_target_list_new (NULL, 0);
4036 guint actions = priv->editable ? GDK_ACTION_COPY | GDK_ACTION_MOVE : GDK_ACTION_COPY;
4038 cairo_surface_t *surface;
4040 gtk_target_list_add_text_targets (target_list, 0);
4042 text = _gtk_entry_get_selected_text (entry);
4043 surface = _gtk_text_util_create_drag_icon (widget, text, -1);
4045 context = gtk_drag_begin (widget, target_list, actions,
4046 priv->button, (GdkEvent *)event);
4049 gtk_drag_set_icon_surface (context, surface);
4051 gtk_drag_set_icon_default (context);
4054 cairo_surface_destroy (surface);
4057 priv->in_drag = FALSE;
4060 gtk_target_list_unref (target_list);
4067 else if (event->y >= gdk_window_get_height (priv->text_area))
4068 tmp_pos = gtk_entry_buffer_get_length (get_buffer (entry));
4070 tmp_pos = gtk_entry_find_position (entry, event->x + priv->scroll_offset);
4072 if (priv->select_words)
4075 gint old_min, old_max;
4078 min = gtk_entry_move_backward_word (entry, tmp_pos, TRUE);
4079 max = gtk_entry_move_forward_word (entry, tmp_pos, TRUE);
4081 pos = priv->current_pos;
4082 bound = priv->selection_bound;
4084 old_min = MIN(priv->current_pos, priv->selection_bound);
4085 old_max = MAX(priv->current_pos, priv->selection_bound);
4092 else if (old_max < max)
4097 else if (pos == old_min)
4099 if (priv->current_pos != min)
4104 if (priv->current_pos != max)
4108 gtk_entry_set_positions (entry, pos, bound);
4111 gtk_entry_set_positions (entry, tmp_pos, -1);
4118 set_invisible_cursor (GdkWindow *window)
4120 GdkDisplay *display;
4123 display = gdk_window_get_display (window);
4124 cursor = gdk_cursor_new_for_display (display, GDK_BLANK_CURSOR);
4126 gdk_window_set_cursor (window, cursor);
4128 g_object_unref (cursor);
4132 gtk_entry_obscure_mouse_cursor (GtkEntry *entry)
4134 GtkEntryPrivate *priv = entry->priv;
4136 if (priv->mouse_cursor_obscured)
4139 set_invisible_cursor (priv->text_area);
4141 priv->mouse_cursor_obscured = TRUE;
4145 gtk_entry_key_press (GtkWidget *widget,
4148 GtkEntry *entry = GTK_ENTRY (widget);
4149 GtkEntryPrivate *priv = entry->priv;
4151 gtk_entry_reset_blink_time (entry);
4152 gtk_entry_pend_cursor_blink (entry);
4156 if (gtk_im_context_filter_keypress (priv->im_context, event))
4158 gtk_entry_obscure_mouse_cursor (entry);
4159 priv->need_im_reset = TRUE;
4164 if (event->keyval == GDK_KEY_Return ||
4165 event->keyval == GDK_KEY_KP_Enter ||
4166 event->keyval == GDK_KEY_ISO_Enter ||
4167 event->keyval == GDK_KEY_Escape)
4169 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
4171 if (completion && completion->priv->completion_timeout)
4173 g_source_remove (completion->priv->completion_timeout);
4174 completion->priv->completion_timeout = 0;
4177 _gtk_entry_reset_im_context (entry);
4180 if (GTK_WIDGET_CLASS (gtk_entry_parent_class)->key_press_event (widget, event))
4181 /* Activate key bindings
4185 if (!priv->editable && event->length)
4186 gtk_widget_error_bell (widget);
4192 gtk_entry_key_release (GtkWidget *widget,
4195 GtkEntry *entry = GTK_ENTRY (widget);
4196 GtkEntryPrivate *priv = entry->priv;
4200 if (gtk_im_context_filter_keypress (priv->im_context, event))
4202 priv->need_im_reset = TRUE;
4207 return GTK_WIDGET_CLASS (gtk_entry_parent_class)->key_release_event (widget, event);
4211 gtk_entry_focus_in (GtkWidget *widget,
4212 GdkEventFocus *event)
4214 GtkEntry *entry = GTK_ENTRY (widget);
4215 GtkEntryPrivate *priv = entry->priv;
4218 gtk_widget_queue_draw (widget);
4220 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (widget));
4224 priv->need_im_reset = TRUE;
4225 gtk_im_context_focus_in (priv->im_context);
4226 keymap_state_changed (keymap, entry);
4227 g_signal_connect (keymap, "state-changed",
4228 G_CALLBACK (keymap_state_changed), entry);
4231 g_signal_connect (keymap, "direction-changed",
4232 G_CALLBACK (keymap_direction_changed), entry);
4234 if (gtk_entry_buffer_get_bytes (get_buffer (entry)) == 0 &&
4235 priv->placeholder_text != NULL)
4237 gtk_entry_recompute (entry);
4241 gtk_entry_reset_blink_time (entry);
4242 gtk_entry_check_cursor_blink (entry);
4249 gtk_entry_focus_out (GtkWidget *widget,
4250 GdkEventFocus *event)
4252 GtkEntry *entry = GTK_ENTRY (widget);
4253 GtkEntryPrivate *priv = entry->priv;
4254 GtkEntryCompletion *completion;
4257 gtk_widget_queue_draw (widget);
4259 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (widget));
4263 priv->need_im_reset = TRUE;
4264 gtk_im_context_focus_out (priv->im_context);
4265 remove_capslock_feedback (entry);
4268 if (gtk_entry_buffer_get_bytes (get_buffer (entry)) == 0 &&
4269 priv->placeholder_text != NULL)
4271 gtk_entry_recompute (entry);
4275 gtk_entry_check_cursor_blink (entry);
4278 g_signal_handlers_disconnect_by_func (keymap, keymap_state_changed, entry);
4279 g_signal_handlers_disconnect_by_func (keymap, keymap_direction_changed, entry);
4281 completion = gtk_entry_get_completion (entry);
4283 _gtk_entry_completion_popdown (completion);
4289 gtk_entry_grab_focus (GtkWidget *widget)
4291 GtkEntry *entry = GTK_ENTRY (widget);
4292 GtkEntryPrivate *priv = entry->priv;
4293 gboolean select_on_focus;
4295 GTK_WIDGET_CLASS (gtk_entry_parent_class)->grab_focus (widget);
4297 if (priv->editable && !priv->in_click)
4299 g_object_get (gtk_widget_get_settings (widget),
4300 "gtk-entry-select-on-focus",
4304 if (select_on_focus)
4305 gtk_editable_select_region (GTK_EDITABLE (widget), 0, -1);
4310 gtk_entry_direction_changed (GtkWidget *widget,
4311 GtkTextDirection previous_dir)
4313 GtkEntry *entry = GTK_ENTRY (widget);
4315 gtk_entry_recompute (entry);
4317 GTK_WIDGET_CLASS (gtk_entry_parent_class)->direction_changed (widget, previous_dir);
4321 gtk_entry_state_flags_changed (GtkWidget *widget,
4322 GtkStateFlags previous_state)
4324 GtkEntry *entry = GTK_ENTRY (widget);
4325 GtkEntryPrivate *priv = entry->priv;
4328 if (gtk_widget_get_realized (widget))
4330 if (gtk_widget_is_sensitive (widget))
4331 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
4335 gdk_window_set_cursor (priv->text_area, cursor);
4338 g_object_unref (cursor);
4340 priv->mouse_cursor_obscured = FALSE;
4342 update_cursors (widget);
4345 if (!gtk_widget_is_sensitive (widget))
4347 /* Clear any selection */
4348 gtk_editable_select_region (GTK_EDITABLE (entry), priv->current_pos, priv->current_pos);
4351 gtk_entry_update_cached_style_values (entry);
4355 gtk_entry_screen_changed (GtkWidget *widget,
4356 GdkScreen *old_screen)
4358 gtk_entry_recompute (GTK_ENTRY (widget));
4361 /* GtkEditable method implementations
4364 gtk_entry_insert_text (GtkEditable *editable,
4365 const gchar *new_text,
4366 gint new_text_length,
4369 g_object_ref (editable);
4372 * The incoming text may a password or other secret. We make sure
4373 * not to copy it into temporary buffers.
4376 g_signal_emit_by_name (editable, "insert-text", new_text, new_text_length, position);
4378 g_object_unref (editable);
4382 gtk_entry_delete_text (GtkEditable *editable,
4386 g_object_ref (editable);
4388 g_signal_emit_by_name (editable, "delete-text", start_pos, end_pos);
4390 g_object_unref (editable);
4394 gtk_entry_get_chars (GtkEditable *editable,
4398 GtkEntry *entry = GTK_ENTRY (editable);
4401 gint start_index, end_index;
4403 text = gtk_entry_buffer_get_text (get_buffer (entry));
4404 text_length = gtk_entry_buffer_get_length (get_buffer (entry));
4407 end_pos = text_length;
4409 start_pos = MIN (text_length, start_pos);
4410 end_pos = MIN (text_length, end_pos);
4412 start_index = g_utf8_offset_to_pointer (text, start_pos) - text;
4413 end_index = g_utf8_offset_to_pointer (text, end_pos) - text;
4415 return g_strndup (text + start_index, end_index - start_index);
4419 gtk_entry_real_set_position (GtkEditable *editable,
4422 GtkEntry *entry = GTK_ENTRY (editable);
4423 GtkEntryPrivate *priv = entry->priv;
4427 length = gtk_entry_buffer_get_length (get_buffer (entry));
4428 if (position < 0 || position > length)
4431 if (position != priv->current_pos ||
4432 position != priv->selection_bound)
4434 _gtk_entry_reset_im_context (entry);
4435 gtk_entry_set_positions (entry, position, position);
4440 gtk_entry_get_position (GtkEditable *editable)
4442 GtkEntry *entry = GTK_ENTRY (editable);
4443 GtkEntryPrivate *priv = entry->priv;
4445 return priv->current_pos;
4449 gtk_entry_set_selection_bounds (GtkEditable *editable,
4453 GtkEntry *entry = GTK_ENTRY (editable);
4456 length = gtk_entry_buffer_get_length (get_buffer (entry));
4462 _gtk_entry_reset_im_context (entry);
4464 gtk_entry_set_positions (entry,
4466 MIN (start, length));
4468 gtk_entry_update_primary_selection (entry);
4472 gtk_entry_get_selection_bounds (GtkEditable *editable,
4476 GtkEntry *entry = GTK_ENTRY (editable);
4477 GtkEntryPrivate *priv = entry->priv;
4479 *start = priv->selection_bound;
4480 *end = priv->current_pos;
4482 return (priv->selection_bound != priv->current_pos);
4486 icon_theme_changed (GtkEntry *entry)
4488 GtkEntryPrivate *priv = entry->priv;
4491 for (i = 0; i < MAX_ICONS; i++)
4493 EntryIconInfo *icon_info = priv->icons[i];
4494 if (icon_info != NULL)
4496 if (icon_info->storage_type == GTK_IMAGE_ICON_NAME)
4497 gtk_entry_set_icon_from_icon_name (entry, i, icon_info->icon_name);
4498 else if (icon_info->storage_type == GTK_IMAGE_STOCK)
4499 gtk_entry_set_icon_from_stock (entry, i, icon_info->stock_id);
4500 else if (icon_info->storage_type == GTK_IMAGE_GICON)
4501 gtk_entry_set_icon_from_gicon (entry, i, icon_info->gicon);
4505 gtk_widget_queue_draw (GTK_WIDGET (entry));
4509 icon_margin_changed (GtkEntry *entry)
4511 GtkEntryPrivate *priv = entry->priv;
4514 _gtk_entry_effective_inner_border (GTK_ENTRY (entry), &border);
4516 priv->icon_margin = border.left;
4520 gtk_entry_update_cached_style_values (GtkEntry *entry)
4522 GtkEntryPrivate *priv = entry->priv;
4524 gboolean interior_focus;
4526 gtk_widget_style_get (GTK_WIDGET (entry),
4527 "focus-line-width", &focus_width,
4528 "interior-focus", &interior_focus,
4530 priv->focus_width = focus_width;
4531 priv->interior_focus = interior_focus;
4533 if (!priv->invisible_char_set)
4535 gunichar ch = find_invisible_char (GTK_WIDGET (entry));
4537 if (priv->invisible_char != ch)
4539 priv->invisible_char = ch;
4540 g_object_notify (G_OBJECT (entry), "invisible-char");
4546 gtk_entry_style_updated (GtkWidget *widget)
4548 GtkEntry *entry = GTK_ENTRY (widget);
4550 GTK_WIDGET_CLASS (gtk_entry_parent_class)->style_updated (widget);
4552 gtk_entry_update_cached_style_values (entry);
4554 gtk_entry_recompute (entry);
4556 icon_theme_changed (entry);
4557 icon_margin_changed (entry);
4560 /* GtkCellEditable method implementations
4563 gtk_cell_editable_entry_activated (GtkEntry *entry, gpointer data)
4565 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4566 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4570 gtk_cell_editable_key_press_event (GtkEntry *entry,
4571 GdkEventKey *key_event,
4574 GtkEntryPrivate *priv = entry->priv;
4576 if (key_event->keyval == GDK_KEY_Escape)
4578 priv->editing_canceled = TRUE;
4579 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4580 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4585 /* override focus */
4586 if (key_event->keyval == GDK_KEY_Up || key_event->keyval == GDK_KEY_Down)
4588 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4589 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4598 gtk_entry_start_editing (GtkCellEditable *cell_editable,
4601 GtkEntry *entry = GTK_ENTRY (cell_editable);
4602 GtkEntryPrivate *priv = entry->priv;
4604 priv->is_cell_renderer = TRUE;
4606 g_signal_connect (cell_editable, "activate",
4607 G_CALLBACK (gtk_cell_editable_entry_activated), NULL);
4608 g_signal_connect (cell_editable, "key-press-event",
4609 G_CALLBACK (gtk_cell_editable_key_press_event), NULL);
4613 gtk_entry_password_hint_free (GtkEntryPasswordHint *password_hint)
4615 if (password_hint->source_id)
4616 g_source_remove (password_hint->source_id);
4618 g_slice_free (GtkEntryPasswordHint, password_hint);
4623 gtk_entry_remove_password_hint (gpointer data)
4625 GtkEntryPasswordHint *password_hint = g_object_get_qdata (data, quark_password_hint);
4626 password_hint->position = -1;
4628 /* Force the string to be redrawn, but now without a visible character */
4629 gtk_entry_recompute (GTK_ENTRY (data));
4633 /* Default signal handlers
4636 gtk_entry_real_insert_text (GtkEditable *editable,
4637 const gchar *new_text,
4638 gint new_text_length,
4644 n_chars = g_utf8_strlen (new_text, new_text_length);
4647 * The actual insertion into the buffer. This will end up firing the
4648 * following signal handlers: buffer_inserted_text(), buffer_notify_display_text(),
4649 * buffer_notify_text(), buffer_notify_length()
4651 begin_change (GTK_ENTRY (editable));
4652 g_object_freeze_notify (G_OBJECT (editable));
4654 n_inserted = gtk_entry_buffer_insert_text (get_buffer (GTK_ENTRY (editable)), *position, new_text, n_chars);
4656 g_object_thaw_notify (G_OBJECT (editable));
4657 end_change (GTK_ENTRY (editable));
4659 if (n_inserted != n_chars)
4660 gtk_widget_error_bell (GTK_WIDGET (editable));
4662 *position += n_inserted;
4666 gtk_entry_real_delete_text (GtkEditable *editable,
4671 * The actual deletion from the buffer. This will end up firing the
4672 * following signal handlers: buffer_deleted_text(), buffer_notify_display_text(),
4673 * buffer_notify_text(), buffer_notify_length()
4676 begin_change (GTK_ENTRY (editable));
4677 g_object_freeze_notify (G_OBJECT (editable));
4678 gtk_entry_buffer_delete_text (get_buffer (GTK_ENTRY (editable)), start_pos, end_pos - start_pos);
4679 g_object_thaw_notify (G_OBJECT (editable));
4680 end_change (GTK_ENTRY (editable));
4683 /* GtkEntryBuffer signal handlers
4686 buffer_inserted_text (GtkEntryBuffer *buffer,
4692 GtkEntryPrivate *priv = entry->priv;
4693 guint password_hint_timeout;
4695 gint selection_bound;
4697 current_pos = priv->current_pos;
4698 if (current_pos > position)
4699 current_pos += n_chars;
4701 selection_bound = priv->selection_bound;
4702 if (selection_bound > position)
4703 selection_bound += n_chars;
4705 gtk_entry_set_positions (entry, current_pos, selection_bound);
4707 /* Calculate the password hint if it needs to be displayed. */
4708 if (n_chars == 1 && !priv->visible)
4710 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
4711 "gtk-entry-password-hint-timeout", &password_hint_timeout,
4714 if (password_hint_timeout > 0)
4716 GtkEntryPasswordHint *password_hint = g_object_get_qdata (G_OBJECT (entry),
4717 quark_password_hint);
4720 password_hint = g_slice_new0 (GtkEntryPasswordHint);
4721 g_object_set_qdata_full (G_OBJECT (entry), quark_password_hint, password_hint,
4722 (GDestroyNotify)gtk_entry_password_hint_free);
4725 password_hint->position = position;
4726 if (password_hint->source_id)
4727 g_source_remove (password_hint->source_id);
4728 password_hint->source_id = gdk_threads_add_timeout (password_hint_timeout,
4729 (GSourceFunc)gtk_entry_remove_password_hint, entry);
4735 buffer_deleted_text (GtkEntryBuffer *buffer,
4740 GtkEntryPrivate *priv = entry->priv;
4741 guint end_pos = position + n_chars;
4742 gint selection_bound;
4745 current_pos = priv->current_pos;
4746 if (current_pos > position)
4747 current_pos -= MIN (current_pos, end_pos) - position;
4749 selection_bound = priv->selection_bound;
4750 if (selection_bound > position)
4751 selection_bound -= MIN (selection_bound, end_pos) - position;
4753 gtk_entry_set_positions (entry, current_pos, selection_bound);
4755 /* We might have deleted the selection */
4756 gtk_entry_update_primary_selection (entry);
4758 /* Disable the password hint if one exists. */
4761 GtkEntryPasswordHint *password_hint = g_object_get_qdata (G_OBJECT (entry),
4762 quark_password_hint);
4765 if (password_hint->source_id)
4766 g_source_remove (password_hint->source_id);
4767 password_hint->source_id = 0;
4768 password_hint->position = -1;
4774 buffer_notify_text (GtkEntryBuffer *buffer,
4778 gtk_entry_recompute (entry);
4779 emit_changed (entry);
4780 g_object_notify (G_OBJECT (entry), "text");
4784 buffer_notify_length (GtkEntryBuffer *buffer,
4788 g_object_notify (G_OBJECT (entry), "text-length");
4792 buffer_notify_max_length (GtkEntryBuffer *buffer,
4796 g_object_notify (G_OBJECT (entry), "max-length");
4800 buffer_connect_signals (GtkEntry *entry)
4802 g_signal_connect (get_buffer (entry), "inserted-text", G_CALLBACK (buffer_inserted_text), entry);
4803 g_signal_connect (get_buffer (entry), "deleted-text", G_CALLBACK (buffer_deleted_text), entry);
4804 g_signal_connect (get_buffer (entry), "notify::text", G_CALLBACK (buffer_notify_text), entry);
4805 g_signal_connect (get_buffer (entry), "notify::length", G_CALLBACK (buffer_notify_length), entry);
4806 g_signal_connect (get_buffer (entry), "notify::max-length", G_CALLBACK (buffer_notify_max_length), entry);
4810 buffer_disconnect_signals (GtkEntry *entry)
4812 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_inserted_text, entry);
4813 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_deleted_text, entry);
4814 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_text, entry);
4815 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_length, entry);
4816 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_max_length, entry);
4819 /* Compute the X position for an offset that corresponds to the "more important
4820 * cursor position for that offset. We use this when trying to guess to which
4821 * end of the selection we should go to when the user hits the left or
4825 get_better_cursor_x (GtkEntry *entry,
4828 GtkEntryPrivate *priv = entry->priv;
4829 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
4830 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
4831 gboolean split_cursor;
4833 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
4834 const gchar *text = pango_layout_get_text (layout);
4835 gint index = g_utf8_offset_to_pointer (text, offset) - text;
4837 PangoRectangle strong_pos, weak_pos;
4839 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
4840 "gtk-split-cursor", &split_cursor,
4843 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
4846 return strong_pos.x / PANGO_SCALE;
4848 return (keymap_direction == priv->resolved_dir) ? strong_pos.x / PANGO_SCALE : weak_pos.x / PANGO_SCALE;
4852 gtk_entry_move_cursor (GtkEntry *entry,
4853 GtkMovementStep step,
4855 gboolean extend_selection)
4857 GtkEntryPrivate *priv = entry->priv;
4858 gint new_pos = priv->current_pos;
4860 _gtk_entry_reset_im_context (entry);
4862 if (priv->current_pos != priv->selection_bound && !extend_selection)
4864 /* If we have a current selection and aren't extending it, move to the
4865 * start/or end of the selection as appropriate
4869 case GTK_MOVEMENT_VISUAL_POSITIONS:
4871 gint current_x = get_better_cursor_x (entry, priv->current_pos);
4872 gint bound_x = get_better_cursor_x (entry, priv->selection_bound);
4875 new_pos = current_x < bound_x ? priv->current_pos : priv->selection_bound;
4877 new_pos = current_x > bound_x ? priv->current_pos : priv->selection_bound;
4880 case GTK_MOVEMENT_LOGICAL_POSITIONS:
4881 case GTK_MOVEMENT_WORDS:
4883 new_pos = MIN (priv->current_pos, priv->selection_bound);
4885 new_pos = MAX (priv->current_pos, priv->selection_bound);
4887 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
4888 case GTK_MOVEMENT_PARAGRAPH_ENDS:
4889 case GTK_MOVEMENT_BUFFER_ENDS:
4890 new_pos = count < 0 ? 0 : gtk_entry_buffer_get_length (get_buffer (entry));
4892 case GTK_MOVEMENT_DISPLAY_LINES:
4893 case GTK_MOVEMENT_PARAGRAPHS:
4894 case GTK_MOVEMENT_PAGES:
4895 case GTK_MOVEMENT_HORIZONTAL_PAGES:
4903 case GTK_MOVEMENT_LOGICAL_POSITIONS:
4904 new_pos = gtk_entry_move_logically (entry, new_pos, count);
4906 case GTK_MOVEMENT_VISUAL_POSITIONS:
4907 new_pos = gtk_entry_move_visually (entry, new_pos, count);
4908 if (priv->current_pos == new_pos)
4910 if (!extend_selection)
4912 if (!gtk_widget_keynav_failed (GTK_WIDGET (entry),
4914 GTK_DIR_RIGHT : GTK_DIR_LEFT))
4916 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (entry));
4919 gtk_widget_child_focus (toplevel,
4921 GTK_DIR_RIGHT : GTK_DIR_LEFT);
4926 gtk_widget_error_bell (GTK_WIDGET (entry));
4930 case GTK_MOVEMENT_WORDS:
4933 new_pos = gtk_entry_move_forward_word (entry, new_pos, FALSE);
4938 new_pos = gtk_entry_move_backward_word (entry, new_pos, FALSE);
4941 if (priv->current_pos == new_pos)
4942 gtk_widget_error_bell (GTK_WIDGET (entry));
4944 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
4945 case GTK_MOVEMENT_PARAGRAPH_ENDS:
4946 case GTK_MOVEMENT_BUFFER_ENDS:
4947 new_pos = count < 0 ? 0 : gtk_entry_buffer_get_length (get_buffer (entry));
4948 if (priv->current_pos == new_pos)
4949 gtk_widget_error_bell (GTK_WIDGET (entry));
4951 case GTK_MOVEMENT_DISPLAY_LINES:
4952 case GTK_MOVEMENT_PARAGRAPHS:
4953 case GTK_MOVEMENT_PAGES:
4954 case GTK_MOVEMENT_HORIZONTAL_PAGES:
4959 if (extend_selection)
4960 gtk_editable_select_region (GTK_EDITABLE (entry), priv->selection_bound, new_pos);
4962 gtk_editable_set_position (GTK_EDITABLE (entry), new_pos);
4964 gtk_entry_pend_cursor_blink (entry);
4968 gtk_entry_insert_at_cursor (GtkEntry *entry,
4971 GtkEntryPrivate *priv = entry->priv;
4972 GtkEditable *editable = GTK_EDITABLE (entry);
4973 gint pos = priv->current_pos;
4977 _gtk_entry_reset_im_context (entry);
4979 gtk_editable_insert_text (editable, str, -1, &pos);
4980 gtk_editable_set_position (editable, pos);
4985 gtk_entry_delete_from_cursor (GtkEntry *entry,
4989 GtkEntryPrivate *priv = entry->priv;
4990 GtkEditable *editable = GTK_EDITABLE (entry);
4991 gint start_pos = priv->current_pos;
4992 gint end_pos = priv->current_pos;
4993 gint old_n_bytes = gtk_entry_buffer_get_bytes (get_buffer (entry));
4995 _gtk_entry_reset_im_context (entry);
4997 if (!priv->editable)
4999 gtk_widget_error_bell (GTK_WIDGET (entry));
5003 if (priv->selection_bound != priv->current_pos)
5005 gtk_editable_delete_selection (editable);
5011 case GTK_DELETE_CHARS:
5012 end_pos = gtk_entry_move_logically (entry, priv->current_pos, count);
5013 gtk_editable_delete_text (editable, MIN (start_pos, end_pos), MAX (start_pos, end_pos));
5015 case GTK_DELETE_WORDS:
5018 /* Move to end of current word, or if not on a word, end of previous word */
5019 end_pos = gtk_entry_move_backward_word (entry, end_pos, FALSE);
5020 end_pos = gtk_entry_move_forward_word (entry, end_pos, FALSE);
5024 /* Move to beginning of current word, or if not on a word, begining of next word */
5025 start_pos = gtk_entry_move_forward_word (entry, start_pos, FALSE);
5026 start_pos = gtk_entry_move_backward_word (entry, start_pos, FALSE);
5030 case GTK_DELETE_WORD_ENDS:
5033 start_pos = gtk_entry_move_backward_word (entry, start_pos, FALSE);
5038 end_pos = gtk_entry_move_forward_word (entry, end_pos, FALSE);
5041 gtk_editable_delete_text (editable, start_pos, end_pos);
5043 case GTK_DELETE_DISPLAY_LINE_ENDS:
5044 case GTK_DELETE_PARAGRAPH_ENDS:
5046 gtk_editable_delete_text (editable, 0, priv->current_pos);
5048 gtk_editable_delete_text (editable, priv->current_pos, -1);
5050 case GTK_DELETE_DISPLAY_LINES:
5051 case GTK_DELETE_PARAGRAPHS:
5052 gtk_editable_delete_text (editable, 0, -1);
5054 case GTK_DELETE_WHITESPACE:
5055 gtk_entry_delete_whitespace (entry);
5059 if (gtk_entry_buffer_get_bytes (get_buffer (entry)) == old_n_bytes)
5060 gtk_widget_error_bell (GTK_WIDGET (entry));
5062 gtk_entry_pend_cursor_blink (entry);
5066 gtk_entry_backspace (GtkEntry *entry)
5068 GtkEntryPrivate *priv = entry->priv;
5069 GtkEditable *editable = GTK_EDITABLE (entry);
5072 _gtk_entry_reset_im_context (entry);
5074 if (!priv->editable)
5076 gtk_widget_error_bell (GTK_WIDGET (entry));
5080 if (priv->selection_bound != priv->current_pos)
5082 gtk_editable_delete_selection (editable);
5086 prev_pos = gtk_entry_move_logically (entry, priv->current_pos, -1);
5088 if (prev_pos < priv->current_pos)
5090 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
5091 PangoLogAttr *log_attrs;
5094 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
5096 /* Deleting parts of characters */
5097 if (log_attrs[priv->current_pos].backspace_deletes_character)
5099 gchar *cluster_text;
5100 gchar *normalized_text;
5103 cluster_text = gtk_entry_get_display_text (entry, prev_pos,
5105 normalized_text = g_utf8_normalize (cluster_text,
5106 strlen (cluster_text),
5108 len = g_utf8_strlen (normalized_text, -1);
5110 gtk_editable_delete_text (editable, prev_pos, priv->current_pos);
5113 gint pos = priv->current_pos;
5115 gtk_editable_insert_text (editable, normalized_text,
5116 g_utf8_offset_to_pointer (normalized_text, len - 1) - normalized_text,
5118 gtk_editable_set_position (editable, pos);
5121 g_free (normalized_text);
5122 g_free (cluster_text);
5126 gtk_editable_delete_text (editable, prev_pos, priv->current_pos);
5133 gtk_widget_error_bell (GTK_WIDGET (entry));
5136 gtk_entry_pend_cursor_blink (entry);
5140 gtk_entry_copy_clipboard (GtkEntry *entry)
5142 GtkEntryPrivate *priv = entry->priv;
5143 GtkEditable *editable = GTK_EDITABLE (entry);
5147 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5151 gtk_widget_error_bell (GTK_WIDGET (entry));
5155 str = gtk_entry_get_display_text (entry, start, end);
5156 gtk_clipboard_set_text (gtk_widget_get_clipboard (GTK_WIDGET (entry),
5157 GDK_SELECTION_CLIPBOARD),
5164 gtk_entry_cut_clipboard (GtkEntry *entry)
5166 GtkEntryPrivate *priv = entry->priv;
5167 GtkEditable *editable = GTK_EDITABLE (entry);
5172 gtk_widget_error_bell (GTK_WIDGET (entry));
5176 gtk_entry_copy_clipboard (entry);
5180 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5181 gtk_editable_delete_text (editable, start, end);
5185 gtk_widget_error_bell (GTK_WIDGET (entry));
5190 gtk_entry_paste_clipboard (GtkEntry *entry)
5192 GtkEntryPrivate *priv = entry->priv;
5195 gtk_entry_paste (entry, GDK_SELECTION_CLIPBOARD);
5197 gtk_widget_error_bell (GTK_WIDGET (entry));
5201 gtk_entry_delete_cb (GtkEntry *entry)
5203 GtkEntryPrivate *priv = entry->priv;
5204 GtkEditable *editable = GTK_EDITABLE (entry);
5209 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5210 gtk_editable_delete_text (editable, start, end);
5215 gtk_entry_toggle_overwrite (GtkEntry *entry)
5217 GtkEntryPrivate *priv = entry->priv;
5219 priv->overwrite_mode = !priv->overwrite_mode;
5220 gtk_entry_pend_cursor_blink (entry);
5221 gtk_widget_queue_draw (GTK_WIDGET (entry));
5225 gtk_entry_select_all (GtkEntry *entry)
5227 gtk_entry_select_line (entry);
5231 gtk_entry_real_activate (GtkEntry *entry)
5233 GtkEntryPrivate *priv = entry->priv;
5235 GtkWidget *default_widget, *focus_widget;
5236 GtkWidget *toplevel;
5239 widget = GTK_WIDGET (entry);
5241 if (priv->activates_default)
5243 toplevel = gtk_widget_get_toplevel (widget);
5244 if (GTK_IS_WINDOW (toplevel))
5246 window = GTK_WINDOW (toplevel);
5250 default_widget = gtk_window_get_default_widget (window);
5251 focus_widget = gtk_window_get_focus (window);
5252 if (widget != default_widget &&
5253 !(widget == focus_widget && (!default_widget || !gtk_widget_get_sensitive (default_widget))))
5254 gtk_window_activate_default (window);
5261 keymap_direction_changed (GdkKeymap *keymap,
5264 gtk_entry_recompute (entry);
5267 /* IM Context Callbacks
5271 gtk_entry_commit_cb (GtkIMContext *context,
5275 GtkEntryPrivate *priv = entry->priv;
5278 gtk_entry_enter_text (entry, str);
5282 gtk_entry_preedit_changed_cb (GtkIMContext *context,
5285 GtkEntryPrivate *priv = entry->priv;
5289 gchar *preedit_string;
5292 gtk_im_context_get_preedit_string (priv->im_context,
5293 &preedit_string, NULL,
5295 g_signal_emit (entry, signals[PREEDIT_CHANGED], 0, preedit_string);
5296 priv->preedit_length = strlen (preedit_string);
5297 cursor_pos = CLAMP (cursor_pos, 0, g_utf8_strlen (preedit_string, -1));
5298 priv->preedit_cursor = cursor_pos;
5299 g_free (preedit_string);
5301 gtk_entry_recompute (entry);
5306 gtk_entry_retrieve_surrounding_cb (GtkIMContext *context,
5309 GtkEntryPrivate *priv = entry->priv;
5312 /* XXXX ??? does this even make sense when text is not visible? Should we return FALSE? */
5313 text = gtk_entry_get_display_text (entry, 0, -1);
5314 gtk_im_context_set_surrounding (context, text, strlen (text), /* Length in bytes */
5315 g_utf8_offset_to_pointer (text, priv->current_pos) - text);
5322 gtk_entry_delete_surrounding_cb (GtkIMContext *slave,
5327 GtkEntryPrivate *priv = entry->priv;
5330 gtk_editable_delete_text (GTK_EDITABLE (entry),
5331 priv->current_pos + offset,
5332 priv->current_pos + offset + n_chars);
5337 /* Internal functions
5340 /* Used for im_commit_cb and inserting Unicode chars */
5342 gtk_entry_enter_text (GtkEntry *entry,
5345 GtkEntryPrivate *priv = entry->priv;
5346 GtkEditable *editable = GTK_EDITABLE (entry);
5348 gboolean old_need_im_reset;
5350 old_need_im_reset = priv->need_im_reset;
5351 priv->need_im_reset = FALSE;
5353 if (gtk_editable_get_selection_bounds (editable, NULL, NULL))
5354 gtk_editable_delete_selection (editable);
5357 if (priv->overwrite_mode)
5358 gtk_entry_delete_from_cursor (entry, GTK_DELETE_CHARS, 1);
5361 tmp_pos = priv->current_pos;
5362 gtk_editable_insert_text (editable, str, strlen (str), &tmp_pos);
5363 gtk_editable_set_position (editable, tmp_pos);
5365 priv->need_im_reset = old_need_im_reset;
5368 /* All changes to priv->current_pos and priv->selection_bound
5369 * should go through this function.
5372 gtk_entry_set_positions (GtkEntry *entry,
5374 gint selection_bound)
5376 GtkEntryPrivate *priv = entry->priv;
5377 gboolean changed = FALSE;
5379 g_object_freeze_notify (G_OBJECT (entry));
5381 if (current_pos != -1 &&
5382 priv->current_pos != current_pos)
5384 priv->current_pos = current_pos;
5387 g_object_notify (G_OBJECT (entry), "cursor-position");
5390 if (selection_bound != -1 &&
5391 priv->selection_bound != selection_bound)
5393 priv->selection_bound = selection_bound;
5396 g_object_notify (G_OBJECT (entry), "selection-bound");
5399 g_object_thaw_notify (G_OBJECT (entry));
5403 gtk_entry_move_adjustments (entry);
5404 gtk_entry_recompute (entry);
5409 gtk_entry_reset_layout (GtkEntry *entry)
5411 GtkEntryPrivate *priv = entry->priv;
5413 if (priv->cached_layout)
5415 g_object_unref (priv->cached_layout);
5416 priv->cached_layout = NULL;
5421 update_im_cursor_location (GtkEntry *entry)
5423 GtkEntryPrivate *priv = entry->priv;
5426 gint strong_xoffset;
5427 gint area_width, area_height;
5429 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
5430 gtk_entry_get_text_area_size (entry, NULL, NULL, &area_width, &area_height);
5432 strong_xoffset = strong_x - priv->scroll_offset;
5433 if (strong_xoffset < 0)
5437 else if (strong_xoffset > area_width)
5439 strong_xoffset = area_width;
5441 area.x = strong_xoffset;
5444 area.height = area_height;
5446 gtk_im_context_set_cursor_location (priv->im_context, &area);
5450 recompute_idle_func (gpointer data)
5452 GtkEntry *entry = GTK_ENTRY (data);
5453 GtkEntryPrivate *priv = entry->priv;
5455 priv->recompute_idle = 0;
5457 if (gtk_widget_has_screen (GTK_WIDGET (entry)))
5459 gtk_entry_adjust_scroll (entry);
5460 gtk_widget_queue_draw (GTK_WIDGET (entry));
5462 update_im_cursor_location (entry);
5469 gtk_entry_recompute (GtkEntry *entry)
5471 GtkEntryPrivate *priv = entry->priv;
5473 gtk_entry_reset_layout (entry);
5474 gtk_entry_check_cursor_blink (entry);
5476 if (!priv->recompute_idle)
5478 priv->recompute_idle = gdk_threads_add_idle_full (G_PRIORITY_HIGH_IDLE + 15, /* between resize and redraw */
5479 recompute_idle_func, entry, NULL);
5484 gtk_entry_get_placeholder_text_color (GtkEntry *entry,
5487 GtkWidget *widget = GTK_WIDGET (entry);
5488 GtkStyleContext *context;
5489 GdkRGBA fg = { 0.5, 0.5, 0.5 };
5491 context = gtk_widget_get_style_context (widget);
5492 gtk_style_context_lookup_color (context, "placeholder_text_color", &fg);
5494 color->red = CLAMP (fg.red * 65535. + 0.5, 0, 65535);
5495 color->green = CLAMP (fg.green * 65535. + 0.5, 0, 65535);
5496 color->blue = CLAMP (fg.blue * 65535. + 0.5, 0, 65535);
5499 static inline gboolean
5500 show_placeholder_text (GtkEntry *entry)
5502 GtkEntryPrivate *priv = entry->priv;
5504 if (!gtk_widget_has_focus (GTK_WIDGET (entry)) &&
5505 gtk_entry_buffer_get_bytes (get_buffer (entry)) == 0 &&
5506 priv->placeholder_text != NULL)
5512 static PangoLayout *
5513 gtk_entry_create_layout (GtkEntry *entry,
5514 gboolean include_preedit)
5516 GtkEntryPrivate *priv = entry->priv;
5517 GtkWidget *widget = GTK_WIDGET (entry);
5518 PangoLayout *layout = gtk_widget_create_pango_layout (widget, NULL);
5519 PangoAttrList *tmp_attrs = pango_attr_list_new ();
5520 gboolean placeholder_layout = show_placeholder_text (entry);
5522 gchar *preedit_string = NULL;
5523 gint preedit_length = 0;
5524 PangoAttrList *preedit_attrs = NULL;
5529 pango_layout_set_single_paragraph_mode (layout, TRUE);
5531 display = placeholder_layout ? g_strdup (priv->placeholder_text) : gtk_entry_get_display_text (entry, 0, -1);
5532 n_bytes = strlen (display);
5534 if (!placeholder_layout && include_preedit)
5536 gtk_im_context_get_preedit_string (priv->im_context,
5537 &preedit_string, &preedit_attrs, NULL);
5538 preedit_length = priv->preedit_length;
5540 else if (placeholder_layout)
5543 PangoAttribute *attr;
5545 gtk_entry_get_placeholder_text_color (entry, &color);
5546 attr = pango_attr_foreground_new (color.red, color.green, color.blue);
5547 attr->start_index = 0;
5548 attr->end_index = G_MAXINT;
5549 pango_attr_list_insert (tmp_attrs, attr);
5554 GString *tmp_string = g_string_new (display);
5555 gint cursor_index = g_utf8_offset_to_pointer (display, priv->current_pos) - display;
5557 g_string_insert (tmp_string, cursor_index, preedit_string);
5559 pango_layout_set_text (layout, tmp_string->str, tmp_string->len);
5561 pango_attr_list_splice (tmp_attrs, preedit_attrs,
5562 cursor_index, preedit_length);
5564 g_string_free (tmp_string, TRUE);
5568 PangoDirection pango_dir;
5570 if (gtk_entry_get_display_mode (entry) == DISPLAY_NORMAL)
5571 pango_dir = pango_find_base_dir (display, n_bytes);
5573 pango_dir = PANGO_DIRECTION_NEUTRAL;
5575 if (pango_dir == PANGO_DIRECTION_NEUTRAL)
5577 if (gtk_widget_has_focus (widget))
5579 GdkDisplay *display = gtk_widget_get_display (widget);
5580 GdkKeymap *keymap = gdk_keymap_get_for_display (display);
5581 if (gdk_keymap_get_direction (keymap) == PANGO_DIRECTION_RTL)
5582 pango_dir = PANGO_DIRECTION_RTL;
5584 pango_dir = PANGO_DIRECTION_LTR;
5588 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
5589 pango_dir = PANGO_DIRECTION_RTL;
5591 pango_dir = PANGO_DIRECTION_LTR;
5595 pango_context_set_base_dir (gtk_widget_get_pango_context (widget),
5598 priv->resolved_dir = pango_dir;
5600 pango_layout_set_text (layout, display, n_bytes);
5603 pango_layout_set_attributes (layout, tmp_attrs);
5605 g_free (preedit_string);
5609 pango_attr_list_unref (preedit_attrs);
5611 pango_attr_list_unref (tmp_attrs);
5616 static PangoLayout *
5617 gtk_entry_ensure_layout (GtkEntry *entry,
5618 gboolean include_preedit)
5620 GtkEntryPrivate *priv = entry->priv;
5622 if (priv->preedit_length > 0 &&
5623 !include_preedit != !priv->cache_includes_preedit)
5624 gtk_entry_reset_layout (entry);
5626 if (!priv->cached_layout)
5628 priv->cached_layout = gtk_entry_create_layout (entry, include_preedit);
5629 priv->cache_includes_preedit = include_preedit;
5632 return priv->cached_layout;
5636 get_layout_position (GtkEntry *entry,
5640 GtkEntryPrivate *priv = entry->priv;
5641 PangoLayout *layout;
5642 PangoRectangle logical_rect;
5643 gint area_width, area_height;
5644 GtkBorder inner_border;
5646 PangoLayoutLine *line;
5648 layout = gtk_entry_ensure_layout (entry, TRUE);
5650 gtk_entry_get_text_area_size (entry, NULL, NULL, &area_width, &area_height);
5651 _gtk_entry_effective_inner_border (entry, &inner_border);
5653 area_height = PANGO_SCALE * (area_height - inner_border.top - inner_border.bottom);
5655 line = pango_layout_get_lines_readonly (layout)->data;
5656 pango_layout_line_get_extents (line, NULL, &logical_rect);
5658 /* Align primarily for locale's ascent/descent */
5659 y_pos = ((area_height - priv->ascent - priv->descent) / 2 +
5660 priv->ascent + logical_rect.y);
5662 /* Now see if we need to adjust to fit in actual drawn string */
5663 if (logical_rect.height > area_height)
5664 y_pos = (area_height - logical_rect.height) / 2;
5667 else if (y_pos + logical_rect.height > area_height)
5668 y_pos = area_height - logical_rect.height;
5670 y_pos = inner_border.top + y_pos / PANGO_SCALE;
5673 *x = inner_border.left - priv->scroll_offset;
5680 draw_text_with_color (GtkEntry *entry,
5682 GdkRGBA *default_color)
5684 GtkEntryPrivate *priv = entry->priv;
5685 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
5688 gint start_pos, end_pos;
5690 widget = GTK_WIDGET (entry);
5694 get_layout_position (entry, &x, &y);
5696 cairo_move_to (cr, x, y);
5697 gdk_cairo_set_source_rgba (cr, default_color);
5698 pango_cairo_show_layout (cr, layout);
5700 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start_pos, &end_pos))
5704 PangoRectangle logical_rect;
5705 GdkRGBA selection_color, text_color;
5706 GtkBorder inner_border;
5707 GtkStyleContext *context;
5708 GtkStateFlags state;
5710 context = gtk_widget_get_style_context (widget);
5711 pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
5712 gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
5714 state = GTK_STATE_FLAG_SELECTED;
5716 if (gtk_widget_has_focus (widget))
5717 state |= GTK_STATE_FLAG_FOCUSED;
5719 gtk_style_context_get_background_color (context, state, &selection_color);
5720 gtk_style_context_get_color (context, state, &text_color);
5722 _gtk_entry_effective_inner_border (entry, &inner_border);
5724 for (i = 0; i < n_ranges; ++i)
5725 cairo_rectangle (cr,
5726 inner_border.left - priv->scroll_offset + ranges[2 * i],
5729 logical_rect.height);
5733 gdk_cairo_set_source_rgba (cr, &selection_color);
5736 cairo_move_to (cr, x, y);
5737 gdk_cairo_set_source_rgba (cr, &text_color);
5738 pango_cairo_show_layout (cr, layout);
5746 gtk_entry_draw_text (GtkEntry *entry,
5749 GtkEntryPrivate *priv = entry->priv;
5750 GtkWidget *widget = GTK_WIDGET (entry);
5751 GtkStateFlags state = 0;
5752 GdkRGBA text_color, bar_text_color;
5753 GtkStyleContext *context;
5755 gint progress_x, progress_y, progress_width, progress_height;
5756 gint clip_width, clip_height;
5758 /* Nothing to display at all */
5759 if (gtk_entry_get_display_mode (entry) == DISPLAY_BLANK)
5762 state = gtk_widget_get_state_flags (widget);
5763 context = gtk_widget_get_style_context (widget);
5765 gtk_style_context_get_color (context, state, &text_color);
5767 /* Get foreground color for progressbars */
5768 gtk_style_context_save (context);
5769 gtk_style_context_add_class (context, GTK_STYLE_CLASS_PROGRESSBAR);
5770 gtk_style_context_get_color (context, state, &bar_text_color);
5771 gtk_style_context_restore (context);
5773 get_progress_area (widget,
5774 &progress_x, &progress_y,
5775 &progress_width, &progress_height);
5779 clip_width = gdk_window_get_width (priv->text_area);
5780 clip_height = gdk_window_get_height (priv->text_area);
5781 cairo_rectangle (cr, 0, 0, clip_width, clip_height);
5784 /* If the color is the same, or the progress area has a zero
5785 * size, then we only need to draw once. */
5786 if (gdk_rgba_equal (&text_color, &bar_text_color) ||
5787 ((progress_width == 0) || (progress_height == 0)))
5789 draw_text_with_color (entry, cr, &text_color);
5793 int frame_x, frame_y, area_x, area_y;
5795 width = gdk_window_get_width (priv->text_area);
5796 height = gdk_window_get_height (priv->text_area);
5800 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
5801 cairo_rectangle (cr, 0, 0, width, height);
5803 /* progres area is frame-relative, we need it text-area window
5805 get_frame_size (entry, TRUE, &frame_x, &frame_y, NULL, NULL);
5806 gdk_window_get_position (priv->text_area, &area_x, &area_y);
5807 progress_x += frame_x - area_x;
5808 progress_y += frame_y - area_y;
5810 cairo_rectangle (cr, progress_x, progress_y,
5811 progress_width, progress_height);
5813 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_WINDING);
5815 draw_text_with_color (entry, cr, &text_color);
5820 cairo_rectangle (cr, progress_x, progress_y,
5821 progress_width, progress_height);
5824 draw_text_with_color (entry, cr, &bar_text_color);
5833 draw_insertion_cursor (GtkEntry *entry,
5835 GdkRectangle *cursor_location,
5836 gboolean is_primary,
5837 PangoDirection direction,
5838 gboolean draw_arrow)
5840 GtkWidget *widget = GTK_WIDGET (entry);
5841 GtkTextDirection text_dir;
5843 if (direction == PANGO_DIRECTION_LTR)
5844 text_dir = GTK_TEXT_DIR_LTR;
5846 text_dir = GTK_TEXT_DIR_RTL;
5848 gtk_draw_insertion_cursor (widget, cr,
5850 is_primary, text_dir, draw_arrow);
5854 gtk_entry_draw_cursor (GtkEntry *entry,
5858 GtkEntryPrivate *priv = entry->priv;
5859 GtkWidget *widget = GTK_WIDGET (entry);
5860 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
5861 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
5862 GdkRectangle cursor_location;
5863 gboolean split_cursor;
5864 PangoRectangle cursor_rect;
5865 GtkBorder inner_border;
5867 gint text_area_height;
5870 gboolean block_at_line_end;
5871 PangoLayout *layout;
5874 _gtk_entry_effective_inner_border (entry, &inner_border);
5876 xoffset = inner_border.left - priv->scroll_offset;
5878 text_area_height = gdk_window_get_height (priv->text_area);
5880 layout = gtk_entry_ensure_layout (entry, TRUE);
5881 text = pango_layout_get_text (layout);
5882 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos + priv->preedit_cursor) - text;
5883 if (!priv->overwrite_mode)
5886 block = _gtk_text_util_get_block_cursor_location (layout,
5887 cursor_index, &cursor_rect, &block_at_line_end);
5891 gint strong_x, weak_x;
5892 PangoDirection dir1 = PANGO_DIRECTION_NEUTRAL;
5893 PangoDirection dir2 = PANGO_DIRECTION_NEUTRAL;
5897 gtk_entry_get_cursor_locations (entry, type, &strong_x, &weak_x);
5899 g_object_get (gtk_widget_get_settings (widget),
5900 "gtk-split-cursor", &split_cursor,
5903 dir1 = priv->resolved_dir;
5909 if (weak_x != strong_x)
5911 dir2 = (priv->resolved_dir == PANGO_DIRECTION_LTR) ? PANGO_DIRECTION_RTL : PANGO_DIRECTION_LTR;
5917 if (keymap_direction == priv->resolved_dir)
5923 cursor_location.x = xoffset + x1;
5924 cursor_location.y = inner_border.top;
5925 cursor_location.width = 0;
5926 cursor_location.height = text_area_height - inner_border.top - inner_border.bottom;
5928 draw_insertion_cursor (entry, cr,
5929 &cursor_location, TRUE, dir1,
5930 dir2 != PANGO_DIRECTION_NEUTRAL);
5932 if (dir2 != PANGO_DIRECTION_NEUTRAL)
5934 cursor_location.x = xoffset + x2;
5935 draw_insertion_cursor (entry, cr,
5936 &cursor_location, FALSE, dir2,
5940 else /* overwrite_mode */
5942 GtkStyleContext *context;
5943 GdkRGBA cursor_color;
5949 get_layout_position (entry, &x, &y);
5951 rect.x = PANGO_PIXELS (cursor_rect.x) + x;
5952 rect.y = PANGO_PIXELS (cursor_rect.y) + y;
5953 rect.width = PANGO_PIXELS (cursor_rect.width);
5954 rect.height = PANGO_PIXELS (cursor_rect.height);
5956 context = gtk_widget_get_style_context (widget);
5958 _gtk_style_context_get_cursor_color (context, &cursor_color, NULL);
5959 gdk_cairo_set_source_rgba (cr, &cursor_color);
5960 gdk_cairo_rectangle (cr, &rect);
5963 if (!block_at_line_end)
5965 GtkStateFlags state;
5968 state = gtk_widget_get_state_flags (widget);
5969 gtk_style_context_get_background_color (context, state, &color);
5971 gdk_cairo_rectangle (cr, &rect);
5973 cairo_move_to (cr, x, y);
5974 gdk_cairo_set_source_rgba (cr, &color);
5975 pango_cairo_show_layout (cr, layout);
5983 _gtk_entry_reset_im_context (GtkEntry *entry)
5985 GtkEntryPrivate *priv = entry->priv;
5987 if (priv->need_im_reset)
5989 priv->need_im_reset = FALSE;
5990 gtk_im_context_reset (priv->im_context);
5995 * gtk_entry_reset_im_context:
5996 * @entry: a #GtkEntry
5998 * Reset the input method context of the entry if needed.
6000 * This can be necessary in the case where modifying the buffer
6001 * would confuse on-going input method behavior.
6006 gtk_entry_reset_im_context (GtkEntry *entry)
6008 g_return_if_fail (GTK_IS_ENTRY (entry));
6010 _gtk_entry_reset_im_context (entry);
6014 * gtk_entry_im_context_filter_keypress:
6015 * @entry: a #GtkEntry
6016 * @event: (type Gdk.EventKey): the key event
6018 * Allow the #GtkEntry input method to internally handle key press
6019 * and release events. If this function returns %TRUE, then no further
6020 * processing should be done for this key event. See
6021 * gtk_im_context_filter_keypress().
6023 * Note that you are expected to call this function from your handler
6024 * when overriding key event handling. This is needed in the case when
6025 * you need to insert your own key handling between the input method
6026 * and the default key event handling of the #GtkEntry.
6027 * See gtk_text_view_reset_im_context() for an example of use.
6029 * Return value: %TRUE if the input method handled the key event.
6034 gtk_entry_im_context_filter_keypress (GtkEntry *entry,
6037 GtkEntryPrivate *priv;
6039 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
6043 return gtk_im_context_filter_keypress (priv->im_context, event);
6047 _gtk_entry_get_im_context (GtkEntry *entry)
6049 return entry->priv->im_context;
6053 gtk_entry_find_position (GtkEntry *entry,
6056 GtkEntryPrivate *priv = entry->priv;
6057 PangoLayout *layout;
6058 PangoLayoutLine *line;
6065 layout = gtk_entry_ensure_layout (entry, TRUE);
6066 text = pango_layout_get_text (layout);
6067 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos) - text;
6069 line = pango_layout_get_lines_readonly (layout)->data;
6070 pango_layout_line_x_to_index (line, x * PANGO_SCALE, &index, &trailing);
6072 if (index >= cursor_index && priv->preedit_length)
6074 if (index >= cursor_index + priv->preedit_length)
6075 index -= priv->preedit_length;
6078 index = cursor_index;
6083 pos = g_utf8_pointer_to_offset (text, text + index);
6090 gtk_entry_get_cursor_locations (GtkEntry *entry,
6095 GtkEntryPrivate *priv = entry->priv;
6096 DisplayMode mode = gtk_entry_get_display_mode (entry);
6098 /* Nothing to display at all, so no cursor is relevant */
6099 if (mode == DISPLAY_BLANK)
6109 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
6110 const gchar *text = pango_layout_get_text (layout);
6111 PangoRectangle strong_pos, weak_pos;
6114 if (type == CURSOR_STANDARD)
6116 index = g_utf8_offset_to_pointer (text, priv->current_pos + priv->preedit_cursor) - text;
6118 else /* type == CURSOR_DND */
6120 index = g_utf8_offset_to_pointer (text, priv->dnd_position) - text;
6122 if (priv->dnd_position > priv->current_pos)
6124 if (mode == DISPLAY_NORMAL)
6125 index += priv->preedit_length;
6128 gint preedit_len_chars = g_utf8_strlen (text, -1) - gtk_entry_buffer_get_length (get_buffer (entry));
6129 index += preedit_len_chars * g_unichar_to_utf8 (priv->invisible_char, NULL);
6134 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
6137 *strong_x = strong_pos.x / PANGO_SCALE;
6140 *weak_x = weak_pos.x / PANGO_SCALE;
6145 gtk_entry_adjust_scroll (GtkEntry *entry)
6147 GtkEntryPrivate *priv = entry->priv;
6148 gint min_offset, max_offset;
6149 gint text_area_width, text_width;
6150 GtkBorder inner_border;
6151 gint strong_x, weak_x;
6152 gint strong_xoffset, weak_xoffset;
6154 PangoLayout *layout;
6155 PangoLayoutLine *line;
6156 PangoRectangle logical_rect;
6158 if (!gtk_widget_get_realized (GTK_WIDGET (entry)))
6161 _gtk_entry_effective_inner_border (entry, &inner_border);
6163 text_area_width = gdk_window_get_width (priv->text_area);
6164 text_area_width -= inner_border.left + inner_border.right;
6165 if (text_area_width < 0)
6166 text_area_width = 0;
6168 layout = gtk_entry_ensure_layout (entry, TRUE);
6169 line = pango_layout_get_lines_readonly (layout)->data;
6171 pango_layout_line_get_extents (line, NULL, &logical_rect);
6173 /* Display as much text as we can */
6175 if (priv->resolved_dir == PANGO_DIRECTION_LTR)
6176 xalign = priv->xalign;
6178 xalign = 1.0 - priv->xalign;
6180 text_width = PANGO_PIXELS(logical_rect.width);
6182 if (text_width > text_area_width)
6185 max_offset = text_width - text_area_width;
6189 min_offset = (text_width - text_area_width) * xalign;
6190 max_offset = min_offset;
6193 priv->scroll_offset = CLAMP (priv->scroll_offset, min_offset, max_offset);
6195 /* And make sure cursors are on screen. Note that the cursor is
6196 * actually drawn one pixel into the INNER_BORDER space on
6197 * the right, when the scroll is at the utmost right. This
6198 * looks better to to me than confining the cursor inside the
6199 * border entirely, though it means that the cursor gets one
6200 * pixel closer to the edge of the widget on the right than
6201 * on the left. This might need changing if one changed
6202 * INNER_BORDER from 2 to 1, as one would do on a
6203 * small-screen-real-estate display.
6205 * We always make sure that the strong cursor is on screen, and
6206 * put the weak cursor on screen if possible.
6209 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, &weak_x);
6211 strong_xoffset = strong_x - priv->scroll_offset;
6213 if (strong_xoffset < 0)
6215 priv->scroll_offset += strong_xoffset;
6218 else if (strong_xoffset > text_area_width)
6220 priv->scroll_offset += strong_xoffset - text_area_width;
6221 strong_xoffset = text_area_width;
6224 weak_xoffset = weak_x - priv->scroll_offset;
6226 if (weak_xoffset < 0 && strong_xoffset - weak_xoffset <= text_area_width)
6228 priv->scroll_offset += weak_xoffset;
6230 else if (weak_xoffset > text_area_width &&
6231 strong_xoffset - (weak_xoffset - text_area_width) >= 0)
6233 priv->scroll_offset += weak_xoffset - text_area_width;
6236 g_object_notify (G_OBJECT (entry), "scroll-offset");
6240 gtk_entry_move_adjustments (GtkEntry *entry)
6242 GtkWidget *widget = GTK_WIDGET (entry);
6243 GtkAllocation allocation;
6244 GtkAdjustment *adjustment;
6245 PangoContext *context;
6246 PangoFontMetrics *metrics;
6247 GtkStyleContext *style_context;
6248 GtkStateFlags state;
6249 gint x, layout_x, border_x, border_y;
6252 adjustment = g_object_get_qdata (G_OBJECT (entry), quark_cursor_hadjustment);
6256 gtk_widget_get_allocation (widget, &allocation);
6258 /* Cursor position, layout offset, border width, and widget allocation */
6259 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &x, NULL);
6260 get_layout_position (entry, &layout_x, NULL);
6261 _gtk_entry_get_borders (entry, &border_x, &border_y);
6262 x += allocation.x + layout_x + border_x;
6264 /* Approximate width of a char, so user can see what is ahead/behind */
6265 context = gtk_widget_get_pango_context (widget);
6266 style_context = gtk_widget_get_style_context (widget);
6267 state = gtk_widget_get_state_flags (widget);
6269 metrics = pango_context_get_metrics (context,
6270 gtk_style_context_get_font (style_context, state),
6271 pango_context_get_language (context));
6272 char_width = pango_font_metrics_get_approximate_char_width (metrics) / PANGO_SCALE;
6275 gtk_adjustment_clamp_page (adjustment,
6276 x - (char_width + 1), /* one char + one pixel before */
6277 x + (char_width + 2)); /* one char + cursor + one pixel after */
6281 gtk_entry_move_visually (GtkEntry *entry,
6285 GtkEntryPrivate *priv = entry->priv;
6287 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6290 text = pango_layout_get_text (layout);
6292 index = g_utf8_offset_to_pointer (text, start) - text;
6296 int new_index, new_trailing;
6297 gboolean split_cursor;
6300 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
6301 "gtk-split-cursor", &split_cursor,
6308 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
6309 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
6311 strong = keymap_direction == priv->resolved_dir;
6316 pango_layout_move_cursor_visually (layout, strong, index, 0, 1, &new_index, &new_trailing);
6321 pango_layout_move_cursor_visually (layout, strong, index, 0, -1, &new_index, &new_trailing);
6327 else if (new_index != G_MAXINT)
6330 while (new_trailing--)
6331 index = g_utf8_next_char (text + index) - text;
6334 return g_utf8_pointer_to_offset (text, text + index);
6338 gtk_entry_move_logically (GtkEntry *entry,
6342 gint new_pos = start;
6345 length = gtk_entry_buffer_get_length (get_buffer (entry));
6347 /* Prevent any leak of information */
6348 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6350 new_pos = CLAMP (start + count, 0, length);
6354 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6355 PangoLogAttr *log_attrs;
6358 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6360 while (count > 0 && new_pos < length)
6364 while (new_pos < length && !log_attrs[new_pos].is_cursor_position);
6368 while (count < 0 && new_pos > 0)
6372 while (new_pos > 0 && !log_attrs[new_pos].is_cursor_position);
6384 gtk_entry_move_forward_word (GtkEntry *entry,
6386 gboolean allow_whitespace)
6388 gint new_pos = start;
6391 length = gtk_entry_buffer_get_length (get_buffer (entry));
6393 /* Prevent any leak of information */
6394 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6398 else if (new_pos < length)
6400 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6401 PangoLogAttr *log_attrs;
6404 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6406 /* Find the next word boundary */
6408 while (new_pos < n_attrs - 1 && !(log_attrs[new_pos].is_word_end ||
6409 (log_attrs[new_pos].is_word_start && allow_whitespace)))
6420 gtk_entry_move_backward_word (GtkEntry *entry,
6422 gboolean allow_whitespace)
6424 gint new_pos = start;
6426 /* Prevent any leak of information */
6427 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6433 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6434 PangoLogAttr *log_attrs;
6437 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6439 new_pos = start - 1;
6441 /* Find the previous word boundary */
6442 while (new_pos > 0 && !(log_attrs[new_pos].is_word_start ||
6443 (log_attrs[new_pos].is_word_end && allow_whitespace)))
6453 gtk_entry_delete_whitespace (GtkEntry *entry)
6455 GtkEntryPrivate *priv = entry->priv;
6456 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6457 PangoLogAttr *log_attrs;
6461 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6463 start = end = priv->current_pos;
6465 while (start > 0 && log_attrs[start-1].is_white)
6468 while (end < n_attrs && log_attrs[end].is_white)
6474 gtk_editable_delete_text (GTK_EDITABLE (entry), start, end);
6479 gtk_entry_select_word (GtkEntry *entry)
6481 GtkEntryPrivate *priv = entry->priv;
6482 gint start_pos = gtk_entry_move_backward_word (entry, priv->current_pos, TRUE);
6483 gint end_pos = gtk_entry_move_forward_word (entry, priv->current_pos, TRUE);
6485 gtk_editable_select_region (GTK_EDITABLE (entry), start_pos, end_pos);
6489 gtk_entry_select_line (GtkEntry *entry)
6491 gtk_editable_select_region (GTK_EDITABLE (entry), 0, -1);
6495 truncate_multiline (const gchar *text)
6500 text[length] && text[length] != '\n' && text[length] != '\r';
6507 paste_received (GtkClipboard *clipboard,
6511 GtkEntry *entry = GTK_ENTRY (data);
6512 GtkEditable *editable = GTK_EDITABLE (entry);
6513 GtkEntryPrivate *priv = entry->priv;
6515 if (priv->button == 2)
6517 gint pos, start, end;
6518 pos = priv->insert_pos;
6519 gtk_editable_get_selection_bounds (editable, &start, &end);
6520 if (!((start <= pos && pos <= end) || (end <= pos && pos <= start)))
6521 gtk_editable_select_region (editable, pos, pos);
6526 gint pos, start, end;
6528 gboolean popup_completion;
6529 GtkEntryCompletion *completion;
6531 completion = gtk_entry_get_completion (entry);
6533 if (priv->truncate_multiline)
6534 length = truncate_multiline (text);
6536 /* only complete if the selection is at the end */
6537 popup_completion = (gtk_entry_buffer_get_length (get_buffer (entry)) ==
6538 MAX (priv->current_pos, priv->selection_bound));
6542 if (gtk_widget_get_mapped (completion->priv->popup_window))
6543 _gtk_entry_completion_popdown (completion);
6545 if (!popup_completion && completion->priv->changed_id > 0)
6546 g_signal_handler_block (entry, completion->priv->changed_id);
6549 begin_change (entry);
6550 g_object_freeze_notify (G_OBJECT (entry));
6551 if (gtk_editable_get_selection_bounds (editable, &start, &end))
6552 gtk_editable_delete_text (editable, start, end);
6554 pos = priv->current_pos;
6555 gtk_editable_insert_text (editable, text, length, &pos);
6556 gtk_editable_set_position (editable, pos);
6557 g_object_thaw_notify (G_OBJECT (entry));
6561 !popup_completion && completion->priv->changed_id > 0)
6562 g_signal_handler_unblock (entry, completion->priv->changed_id);
6565 g_object_unref (entry);
6569 gtk_entry_paste (GtkEntry *entry,
6572 g_object_ref (entry);
6573 gtk_clipboard_request_text (gtk_widget_get_clipboard (GTK_WIDGET (entry), selection),
6574 paste_received, entry);
6578 primary_get_cb (GtkClipboard *clipboard,
6579 GtkSelectionData *selection_data,
6583 GtkEntry *entry = GTK_ENTRY (data);
6586 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end))
6588 gchar *str = gtk_entry_get_display_text (entry, start, end);
6589 gtk_selection_data_set_text (selection_data, str, -1);
6595 primary_clear_cb (GtkClipboard *clipboard,
6598 GtkEntry *entry = GTK_ENTRY (data);
6599 GtkEntryPrivate *priv = entry->priv;
6601 gtk_editable_select_region (GTK_EDITABLE (entry), priv->current_pos, priv->current_pos);
6605 gtk_entry_update_primary_selection (GtkEntry *entry)
6607 GtkTargetList *list;
6608 GtkTargetEntry *targets;
6609 GtkClipboard *clipboard;
6613 if (!gtk_widget_get_realized (GTK_WIDGET (entry)))
6616 list = gtk_target_list_new (NULL, 0);
6617 gtk_target_list_add_text_targets (list, 0);
6619 targets = gtk_target_table_new_from_list (list, &n_targets);
6621 clipboard = gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_PRIMARY);
6623 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end))
6625 if (!gtk_clipboard_set_with_owner (clipboard, targets, n_targets,
6626 primary_get_cb, primary_clear_cb, G_OBJECT (entry)))
6627 primary_clear_cb (clipboard, entry);
6631 if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (entry))
6632 gtk_clipboard_clear (clipboard);
6635 gtk_target_table_free (targets, n_targets);
6636 gtk_target_list_unref (list);
6640 gtk_entry_clear (GtkEntry *entry,
6641 GtkEntryIconPosition icon_pos)
6643 GtkEntryPrivate *priv = entry->priv;
6644 EntryIconInfo *icon_info = priv->icons[icon_pos];
6646 if (!icon_info || icon_info->storage_type == GTK_IMAGE_EMPTY)
6649 g_object_freeze_notify (G_OBJECT (entry));
6651 /* Explicitly check, as the pointer may become invalidated
6652 * during destruction.
6654 if (GDK_IS_WINDOW (icon_info->window))
6655 gdk_window_hide (icon_info->window);
6657 if (icon_info->pixbuf)
6659 g_object_unref (icon_info->pixbuf);
6660 icon_info->pixbuf = NULL;
6663 switch (icon_info->storage_type)
6665 case GTK_IMAGE_PIXBUF:
6666 g_object_notify (G_OBJECT (entry),
6667 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-pixbuf" : "secondary-icon-pixbuf");
6670 case GTK_IMAGE_STOCK:
6671 g_free (icon_info->stock_id);
6672 icon_info->stock_id = NULL;
6673 g_object_notify (G_OBJECT (entry),
6674 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-stock" : "secondary-icon-stock");
6677 case GTK_IMAGE_ICON_NAME:
6678 g_free (icon_info->icon_name);
6679 icon_info->icon_name = NULL;
6680 g_object_notify (G_OBJECT (entry),
6681 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-name" : "secondary-icon-name");
6684 case GTK_IMAGE_GICON:
6685 if (icon_info->gicon)
6687 g_object_unref (icon_info->gicon);
6688 icon_info->gicon = NULL;
6690 g_object_notify (G_OBJECT (entry),
6691 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-gicon" : "secondary-icon-gicon");
6695 g_assert_not_reached ();
6699 icon_info->storage_type = GTK_IMAGE_EMPTY;
6700 g_object_notify (G_OBJECT (entry),
6701 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-storage-type" : "secondary-icon-storage-type");
6703 g_object_thaw_notify (G_OBJECT (entry));
6707 create_normal_pixbuf (GtkStyleContext *context,
6708 const gchar *stock_id,
6709 GtkIconSize icon_size)
6711 GtkIconSet *icon_set;
6714 gtk_style_context_save (context);
6716 /* Unset any state */
6717 gtk_style_context_set_state (context, GTK_STATE_FLAG_NORMAL);
6719 icon_set = gtk_style_context_lookup_icon_set (context, stock_id);
6720 pixbuf = gtk_icon_set_render_icon_pixbuf (icon_set, context, icon_size);
6722 gtk_style_context_restore (context);
6728 ensure_stated_icon_from_info (GtkStyleContext *context,
6731 GdkPixbuf *retval = NULL;
6732 gboolean symbolic = FALSE;
6737 gtk_icon_info_load_symbolic_for_context (info,
6746 create_normal_pixbuf (context,
6747 GTK_STOCK_MISSING_IMAGE,
6748 GTK_ICON_SIZE_MENU);
6752 GdkPixbuf *temp_pixbuf;
6753 GtkIconSource *icon_source;
6755 icon_source = gtk_icon_source_new ();
6756 gtk_icon_source_set_pixbuf (icon_source, retval);
6757 gtk_icon_source_set_state_wildcarded (icon_source, TRUE);
6759 temp_pixbuf = gtk_render_icon_pixbuf (context, icon_source, (GtkIconSize)-1);
6761 gtk_icon_source_free (icon_source);
6763 g_object_unref (retval);
6764 retval = temp_pixbuf;
6771 gtk_entry_ensure_pixbuf (GtkEntry *entry,
6772 GtkEntryIconPosition icon_pos)
6774 GtkEntryPrivate *priv = entry->priv;
6775 EntryIconInfo *icon_info = priv->icons[icon_pos];
6776 GtkStyleContext *context;
6778 GtkIconTheme *icon_theme;
6779 GtkSettings *settings;
6783 GtkStateFlags state;
6785 widget = GTK_WIDGET (entry);
6786 context = gtk_widget_get_style_context (widget);
6788 state = GTK_STATE_FLAG_NORMAL;
6790 if (!gtk_widget_is_sensitive (widget) || icon_info->insensitive)
6791 state |= GTK_STATE_FLAG_INSENSITIVE;
6792 else if (icon_info->prelight)
6793 state |= GTK_STATE_FLAG_PRELIGHT;
6795 if ((icon_info == NULL) ||
6796 ((icon_info->pixbuf != NULL) && icon_info->last_state == state))
6799 icon_info->last_state = state;
6801 gtk_style_context_save (context);
6802 gtk_style_context_set_state (context, state);
6803 gtk_style_context_add_class (context, GTK_STYLE_CLASS_IMAGE);
6805 switch (icon_info->storage_type)
6807 case GTK_IMAGE_EMPTY:
6808 case GTK_IMAGE_PIXBUF:
6810 case GTK_IMAGE_STOCK:
6811 icon_info->pixbuf = create_normal_pixbuf (context, icon_info->stock_id,
6812 GTK_ICON_SIZE_MENU);
6814 if (!icon_info->pixbuf)
6815 icon_info->pixbuf = create_normal_pixbuf (context,
6816 GTK_STOCK_MISSING_IMAGE,
6817 GTK_ICON_SIZE_MENU);
6820 case GTK_IMAGE_ICON_NAME:
6821 screen = gtk_widget_get_screen (widget);
6824 icon_theme = gtk_icon_theme_get_for_screen (screen);
6825 settings = gtk_settings_get_for_screen (screen);
6827 gtk_icon_size_lookup_for_settings (settings,
6831 info = gtk_icon_theme_lookup_icon (icon_theme,
6832 icon_info->icon_name,
6833 MIN (width, height),
6837 ensure_stated_icon_from_info (context, info);
6840 gtk_icon_info_free (info);
6844 case GTK_IMAGE_GICON:
6845 screen = gtk_widget_get_screen (widget);
6848 icon_theme = gtk_icon_theme_get_for_screen (screen);
6849 settings = gtk_settings_get_for_screen (screen);
6851 gtk_icon_size_lookup_for_settings (settings,
6855 info = gtk_icon_theme_lookup_by_gicon (icon_theme,
6857 MIN (width, height),
6858 GTK_ICON_LOOKUP_USE_BUILTIN);
6861 ensure_stated_icon_from_info (context, info);
6864 gtk_icon_info_free (info);
6869 g_assert_not_reached ();
6873 gtk_style_context_restore (context);
6875 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
6876 gdk_window_show_unraised (icon_info->window);
6886 * Creates a new entry.
6888 * Return value: a new #GtkEntry.
6891 gtk_entry_new (void)
6893 return g_object_new (GTK_TYPE_ENTRY, NULL);
6897 * gtk_entry_new_with_buffer:
6898 * @buffer: The buffer to use for the new #GtkEntry.
6900 * Creates a new entry with the specified text buffer.
6902 * Return value: a new #GtkEntry
6907 gtk_entry_new_with_buffer (GtkEntryBuffer *buffer)
6909 g_return_val_if_fail (GTK_IS_ENTRY_BUFFER (buffer), NULL);
6910 return g_object_new (GTK_TYPE_ENTRY, "buffer", buffer, NULL);
6913 static GtkEntryBuffer*
6914 get_buffer (GtkEntry *entry)
6916 GtkEntryPrivate *priv = entry->priv;
6918 if (priv->buffer == NULL)
6920 GtkEntryBuffer *buffer;
6921 buffer = gtk_entry_buffer_new (NULL, 0);
6922 gtk_entry_set_buffer (entry, buffer);
6923 g_object_unref (buffer);
6926 return priv->buffer;
6930 * gtk_entry_get_buffer:
6931 * @entry: a #GtkEntry
6933 * Get the #GtkEntryBuffer object which holds the text for
6938 * Returns: (transfer none): A #GtkEntryBuffer object.
6941 gtk_entry_get_buffer (GtkEntry *entry)
6943 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
6945 return get_buffer (entry);
6949 * gtk_entry_set_buffer:
6950 * @entry: a #GtkEntry
6951 * @buffer: a #GtkEntryBuffer
6953 * Set the #GtkEntryBuffer object which holds the text for
6959 gtk_entry_set_buffer (GtkEntry *entry,
6960 GtkEntryBuffer *buffer)
6962 GtkEntryPrivate *priv;
6965 g_return_if_fail (GTK_IS_ENTRY (entry));
6971 g_return_if_fail (GTK_IS_ENTRY_BUFFER (buffer));
6972 g_object_ref (buffer);
6977 buffer_disconnect_signals (entry);
6978 g_object_unref (priv->buffer);
6981 priv->buffer = buffer;
6984 buffer_connect_signals (entry);
6986 obj = G_OBJECT (entry);
6987 g_object_freeze_notify (obj);
6988 g_object_notify (obj, "buffer");
6989 g_object_notify (obj, "text");
6990 g_object_notify (obj, "text-length");
6991 g_object_notify (obj, "max-length");
6992 g_object_notify (obj, "visibility");
6993 g_object_notify (obj, "invisible-char");
6994 g_object_notify (obj, "invisible-char-set");
6995 g_object_thaw_notify (obj);
6997 gtk_editable_set_position (GTK_EDITABLE (entry), 0);
6998 gtk_entry_recompute (entry);
7002 * gtk_entry_get_text_area:
7003 * @entry: a #GtkEntry
7004 * @text_area: (out): Return location for the text area.
7006 * Gets the area where the entry's text is drawn. This function is
7007 * useful when drawing something to the entry in a draw callback.
7009 * If the entry is not realized, @text_area is filled with zeros.
7011 * See also gtk_entry_get_icon_area().
7016 gtk_entry_get_text_area (GtkEntry *entry,
7017 GdkRectangle *text_area)
7019 GtkEntryPrivate *priv;
7021 g_return_if_fail (GTK_IS_ENTRY (entry));
7022 g_return_if_fail (text_area != NULL);
7026 if (priv->text_area)
7028 GtkAllocation allocation;
7031 gtk_widget_get_allocation (GTK_WIDGET (entry), &allocation);
7032 gdk_window_get_position (priv->text_area, &x, &y);
7034 text_area->x = x - allocation.x;
7035 text_area->y = y - allocation.y;
7036 text_area->width = gdk_window_get_width (priv->text_area);
7037 text_area->height = gdk_window_get_height (priv->text_area);
7043 text_area->width = 0;
7044 text_area->height = 0;
7049 * gtk_entry_set_text:
7050 * @entry: a #GtkEntry
7051 * @text: the new text
7053 * Sets the text in the widget to the given
7054 * value, replacing the current contents.
7056 * See gtk_entry_buffer_set_text().
7059 gtk_entry_set_text (GtkEntry *entry,
7063 GtkEntryCompletion *completion;
7065 g_return_if_fail (GTK_IS_ENTRY (entry));
7066 g_return_if_fail (text != NULL);
7068 /* Actually setting the text will affect the cursor and selection;
7069 * if the contents don't actually change, this will look odd to the user.
7071 if (strcmp (gtk_entry_buffer_get_text (get_buffer (entry)), text) == 0)
7074 completion = gtk_entry_get_completion (entry);
7075 if (completion && completion->priv->changed_id > 0)
7076 g_signal_handler_block (entry, completion->priv->changed_id);
7078 begin_change (entry);
7079 g_object_freeze_notify (G_OBJECT (entry));
7080 gtk_editable_delete_text (GTK_EDITABLE (entry), 0, -1);
7082 gtk_editable_insert_text (GTK_EDITABLE (entry), text, strlen (text), &tmp_pos);
7083 g_object_thaw_notify (G_OBJECT (entry));
7086 if (completion && completion->priv->changed_id > 0)
7087 g_signal_handler_unblock (entry, completion->priv->changed_id);
7091 * gtk_entry_set_visibility:
7092 * @entry: a #GtkEntry
7093 * @visible: %TRUE if the contents of the entry are displayed
7096 * Sets whether the contents of the entry are visible or not.
7097 * When visibility is set to %FALSE, characters are displayed
7098 * as the invisible char, and will also appear that way when
7099 * the text in the entry widget is copied elsewhere.
7101 * By default, GTK+ picks the best invisible character available
7102 * in the current font, but it can be changed with
7103 * gtk_entry_set_invisible_char().
7106 gtk_entry_set_visibility (GtkEntry *entry,
7109 GtkEntryPrivate *priv;
7111 g_return_if_fail (GTK_IS_ENTRY (entry));
7115 visible = visible != FALSE;
7117 if (priv->visible != visible)
7119 priv->visible = visible;
7121 g_object_notify (G_OBJECT (entry), "visibility");
7122 gtk_entry_recompute (entry);
7127 * gtk_entry_get_visibility:
7128 * @entry: a #GtkEntry
7130 * Retrieves whether the text in @entry is visible. See
7131 * gtk_entry_set_visibility().
7133 * Return value: %TRUE if the text is currently visible
7136 gtk_entry_get_visibility (GtkEntry *entry)
7138 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7140 return entry->priv->visible;
7144 * gtk_entry_set_invisible_char:
7145 * @entry: a #GtkEntry
7146 * @ch: a Unicode character
7148 * Sets the character to use in place of the actual text when
7149 * gtk_entry_set_visibility() has been called to set text visibility
7150 * to %FALSE. i.e. this is the character used in "password mode" to
7151 * show the user how many characters have been typed. By default, GTK+
7152 * picks the best invisible char available in the current font. If you
7153 * set the invisible char to 0, then the user will get no feedback
7154 * at all; there will be no text on the screen as they type.
7157 gtk_entry_set_invisible_char (GtkEntry *entry,
7160 GtkEntryPrivate *priv;
7162 g_return_if_fail (GTK_IS_ENTRY (entry));
7166 if (!priv->invisible_char_set)
7168 priv->invisible_char_set = TRUE;
7169 g_object_notify (G_OBJECT (entry), "invisible-char-set");
7172 if (ch == priv->invisible_char)
7175 priv->invisible_char = ch;
7176 g_object_notify (G_OBJECT (entry), "invisible-char");
7177 gtk_entry_recompute (entry);
7181 * gtk_entry_get_invisible_char:
7182 * @entry: a #GtkEntry
7184 * Retrieves the character displayed in place of the real characters
7185 * for entries with visibility set to false. See gtk_entry_set_invisible_char().
7187 * Return value: the current invisible char, or 0, if the entry does not
7188 * show invisible text at all.
7191 gtk_entry_get_invisible_char (GtkEntry *entry)
7193 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7195 return entry->priv->invisible_char;
7199 * gtk_entry_unset_invisible_char:
7200 * @entry: a #GtkEntry
7202 * Unsets the invisible char previously set with
7203 * gtk_entry_set_invisible_char(). So that the
7204 * default invisible char is used again.
7209 gtk_entry_unset_invisible_char (GtkEntry *entry)
7211 GtkEntryPrivate *priv;
7214 g_return_if_fail (GTK_IS_ENTRY (entry));
7218 if (!priv->invisible_char_set)
7221 priv->invisible_char_set = FALSE;
7222 ch = find_invisible_char (GTK_WIDGET (entry));
7224 if (priv->invisible_char != ch)
7226 priv->invisible_char = ch;
7227 g_object_notify (G_OBJECT (entry), "invisible-char");
7230 g_object_notify (G_OBJECT (entry), "invisible-char-set");
7231 gtk_entry_recompute (entry);
7235 * gtk_entry_set_overwrite_mode:
7236 * @entry: a #GtkEntry
7237 * @overwrite: new value
7239 * Sets whether the text is overwritten when typing in the #GtkEntry.
7244 gtk_entry_set_overwrite_mode (GtkEntry *entry,
7247 GtkEntryPrivate *priv = entry->priv;
7249 g_return_if_fail (GTK_IS_ENTRY (entry));
7251 if (priv->overwrite_mode == overwrite)
7254 gtk_entry_toggle_overwrite (entry);
7256 g_object_notify (G_OBJECT (entry), "overwrite-mode");
7260 * gtk_entry_get_overwrite_mode:
7261 * @entry: a #GtkEntry
7263 * Gets the value set by gtk_entry_set_overwrite_mode().
7265 * Return value: whether the text is overwritten when typing.
7270 gtk_entry_get_overwrite_mode (GtkEntry *entry)
7272 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7274 return entry->priv->overwrite_mode;
7278 * gtk_entry_get_text:
7279 * @entry: a #GtkEntry
7281 * Retrieves the contents of the entry widget.
7282 * See also gtk_editable_get_chars().
7284 * This is equivalent to:
7286 * <informalexample><programlisting>
7287 * gtk_entry_buffer_get_text (gtk_entry_get_buffer (entry));
7288 * </programlisting></informalexample>
7290 * Return value: a pointer to the contents of the widget as a
7291 * string. This string points to internally allocated
7292 * storage in the widget and must not be freed, modified or
7296 gtk_entry_get_text (GtkEntry *entry)
7298 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7300 return gtk_entry_buffer_get_text (get_buffer (entry));
7304 * gtk_entry_set_max_length:
7305 * @entry: a #GtkEntry
7306 * @max: the maximum length of the entry, or 0 for no maximum.
7307 * (other than the maximum length of entries.) The value passed in will
7308 * be clamped to the range 0-65536.
7310 * Sets the maximum allowed length of the contents of the widget. If
7311 * the current contents are longer than the given length, then they
7312 * will be truncated to fit.
7314 * This is equivalent to:
7316 * <informalexample><programlisting>
7317 * gtk_entry_buffer_set_max_length (gtk_entry_get_buffer (entry), max);
7318 * </programlisting></informalexample>
7321 gtk_entry_set_max_length (GtkEntry *entry,
7324 g_return_if_fail (GTK_IS_ENTRY (entry));
7325 gtk_entry_buffer_set_max_length (get_buffer (entry), max);
7329 * gtk_entry_get_max_length:
7330 * @entry: a #GtkEntry
7332 * Retrieves the maximum allowed length of the text in
7333 * @entry. See gtk_entry_set_max_length().
7335 * This is equivalent to:
7337 * <informalexample><programlisting>
7338 * gtk_entry_buffer_get_max_length (gtk_entry_get_buffer (entry));
7339 * </programlisting></informalexample>
7341 * Return value: the maximum allowed number of characters
7342 * in #GtkEntry, or 0 if there is no maximum.
7345 gtk_entry_get_max_length (GtkEntry *entry)
7347 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7349 return gtk_entry_buffer_get_max_length (get_buffer (entry));
7353 * gtk_entry_get_text_length:
7354 * @entry: a #GtkEntry
7356 * Retrieves the current length of the text in
7359 * This is equivalent to:
7361 * <informalexample><programlisting>
7362 * gtk_entry_buffer_get_length (gtk_entry_get_buffer (entry));
7363 * </programlisting></informalexample>
7365 * Return value: the current number of characters
7366 * in #GtkEntry, or 0 if there are none.
7371 gtk_entry_get_text_length (GtkEntry *entry)
7373 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7375 return gtk_entry_buffer_get_length (get_buffer (entry));
7379 * gtk_entry_set_activates_default:
7380 * @entry: a #GtkEntry
7381 * @setting: %TRUE to activate window's default widget on Enter keypress
7383 * If @setting is %TRUE, pressing Enter in the @entry will activate the default
7384 * widget for the window containing the entry. This usually means that
7385 * the dialog box containing the entry will be closed, since the default
7386 * widget is usually one of the dialog buttons.
7388 * (For experts: if @setting is %TRUE, the entry calls
7389 * gtk_window_activate_default() on the window containing the entry, in
7390 * the default handler for the #GtkWidget::activate signal.)
7393 gtk_entry_set_activates_default (GtkEntry *entry,
7396 GtkEntryPrivate *priv;
7398 g_return_if_fail (GTK_IS_ENTRY (entry));
7402 setting = setting != FALSE;
7404 if (setting != priv->activates_default)
7406 priv->activates_default = setting;
7407 g_object_notify (G_OBJECT (entry), "activates-default");
7412 * gtk_entry_get_activates_default:
7413 * @entry: a #GtkEntry
7415 * Retrieves the value set by gtk_entry_set_activates_default().
7417 * Return value: %TRUE if the entry will activate the default widget
7420 gtk_entry_get_activates_default (GtkEntry *entry)
7422 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7424 return entry->priv->activates_default;
7428 * gtk_entry_set_width_chars:
7429 * @entry: a #GtkEntry
7430 * @n_chars: width in chars
7432 * Changes the size request of the entry to be about the right size
7433 * for @n_chars characters. Note that it changes the size
7434 * <emphasis>request</emphasis>, the size can still be affected by
7435 * how you pack the widget into containers. If @n_chars is -1, the
7436 * size reverts to the default entry size.
7439 gtk_entry_set_width_chars (GtkEntry *entry,
7442 GtkEntryPrivate *priv;
7444 g_return_if_fail (GTK_IS_ENTRY (entry));
7448 if (priv->width_chars != n_chars)
7450 priv->width_chars = n_chars;
7451 g_object_notify (G_OBJECT (entry), "width-chars");
7452 gtk_widget_queue_resize (GTK_WIDGET (entry));
7457 * gtk_entry_get_width_chars:
7458 * @entry: a #GtkEntry
7460 * Gets the value set by gtk_entry_set_width_chars().
7462 * Return value: number of chars to request space for, or negative if unset
7465 gtk_entry_get_width_chars (GtkEntry *entry)
7467 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7469 return entry->priv->width_chars;
7473 * gtk_entry_set_has_frame:
7474 * @entry: a #GtkEntry
7475 * @setting: new value
7477 * Sets whether the entry has a beveled frame around it.
7480 gtk_entry_set_has_frame (GtkEntry *entry,
7483 GtkEntryPrivate *priv;
7485 g_return_if_fail (GTK_IS_ENTRY (entry));
7489 setting = (setting != FALSE);
7491 if (priv->has_frame == setting)
7494 gtk_widget_queue_resize (GTK_WIDGET (entry));
7495 priv->has_frame = setting;
7496 g_object_notify (G_OBJECT (entry), "has-frame");
7500 * gtk_entry_get_has_frame:
7501 * @entry: a #GtkEntry
7503 * Gets the value set by gtk_entry_set_has_frame().
7505 * Return value: whether the entry has a beveled frame
7508 gtk_entry_get_has_frame (GtkEntry *entry)
7510 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7512 return entry->priv->has_frame;
7516 * gtk_entry_set_inner_border:
7517 * @entry: a #GtkEntry
7518 * @border: (allow-none): a #GtkBorder, or %NULL
7520 * Sets %entry's inner-border property to %border, or clears it if %NULL
7521 * is passed. The inner-border is the area around the entry's text, but
7524 * If set, this property overrides the inner-border style property.
7525 * Overriding the style-provided border is useful when you want to do
7526 * in-place editing of some text in a canvas or list widget, where
7527 * pixel-exact positioning of the entry is important.
7532 gtk_entry_set_inner_border (GtkEntry *entry,
7533 const GtkBorder *border)
7535 g_return_if_fail (GTK_IS_ENTRY (entry));
7537 gtk_widget_queue_resize (GTK_WIDGET (entry));
7540 g_object_set_qdata_full (G_OBJECT (entry), quark_inner_border,
7541 gtk_border_copy (border),
7542 (GDestroyNotify) gtk_border_free);
7544 g_object_set_qdata (G_OBJECT (entry), quark_inner_border, NULL);
7546 g_object_notify (G_OBJECT (entry), "inner-border");
7550 * gtk_entry_get_inner_border:
7551 * @entry: a #GtkEntry
7553 * This function returns the entry's #GtkEntry:inner-border property. See
7554 * gtk_entry_set_inner_border() for more information.
7556 * Return value: (transfer none): the entry's #GtkBorder, or %NULL if none was set.
7561 gtk_entry_get_inner_border (GtkEntry *entry)
7563 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7565 return g_object_get_qdata (G_OBJECT (entry), quark_inner_border);
7569 * gtk_entry_get_layout:
7570 * @entry: a #GtkEntry
7572 * Gets the #PangoLayout used to display the entry.
7573 * The layout is useful to e.g. convert text positions to
7574 * pixel positions, in combination with gtk_entry_get_layout_offsets().
7575 * The returned layout is owned by the entry and must not be
7576 * modified or freed by the caller.
7578 * Keep in mind that the layout text may contain a preedit string, so
7579 * gtk_entry_layout_index_to_text_index() and
7580 * gtk_entry_text_index_to_layout_index() are needed to convert byte
7581 * indices in the layout to byte indices in the entry contents.
7583 * Return value: (transfer none): the #PangoLayout for this entry
7586 gtk_entry_get_layout (GtkEntry *entry)
7588 PangoLayout *layout;
7590 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7592 layout = gtk_entry_ensure_layout (entry, TRUE);
7599 * gtk_entry_layout_index_to_text_index:
7600 * @entry: a #GtkEntry
7601 * @layout_index: byte index into the entry layout text
7603 * Converts from a position in the entry contents (returned
7604 * by gtk_entry_get_text()) to a position in the
7605 * entry's #PangoLayout (returned by gtk_entry_get_layout(),
7606 * with text retrieved via pango_layout_get_text()).
7608 * Return value: byte index into the entry contents
7611 gtk_entry_layout_index_to_text_index (GtkEntry *entry,
7614 GtkEntryPrivate *priv;
7615 PangoLayout *layout;
7619 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7623 layout = gtk_entry_ensure_layout (entry, TRUE);
7624 text = pango_layout_get_text (layout);
7625 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos) - text;
7627 if (layout_index >= cursor_index && priv->preedit_length)
7629 if (layout_index >= cursor_index + priv->preedit_length)
7630 layout_index -= priv->preedit_length;
7632 layout_index = cursor_index;
7635 return layout_index;
7639 * gtk_entry_text_index_to_layout_index:
7640 * @entry: a #GtkEntry
7641 * @text_index: byte index into the entry contents
7643 * Converts from a position in the entry's #PangoLayout (returned by
7644 * gtk_entry_get_layout()) to a position in the entry contents
7645 * (returned by gtk_entry_get_text()).
7647 * Return value: byte index into the entry layout text
7650 gtk_entry_text_index_to_layout_index (GtkEntry *entry,
7653 GtkEntryPrivate *priv;
7654 PangoLayout *layout;
7658 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7662 layout = gtk_entry_ensure_layout (entry, TRUE);
7663 text = pango_layout_get_text (layout);
7664 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos) - text;
7666 if (text_index > cursor_index)
7667 text_index += priv->preedit_length;
7673 * gtk_entry_get_layout_offsets:
7674 * @entry: a #GtkEntry
7675 * @x: (out) (allow-none): location to store X offset of layout, or %NULL
7676 * @y: (out) (allow-none): location to store Y offset of layout, or %NULL
7679 * Obtains the position of the #PangoLayout used to render text
7680 * in the entry, in widget coordinates. Useful if you want to line
7681 * up the text in an entry with some other text, e.g. when using the
7682 * entry to implement editable cells in a sheet widget.
7684 * Also useful to convert mouse events into coordinates inside the
7685 * #PangoLayout, e.g. to take some action if some part of the entry text
7688 * Note that as the user scrolls around in the entry the offsets will
7689 * change; you'll need to connect to the "notify::scroll-offset"
7690 * signal to track this. Remember when using the #PangoLayout
7691 * functions you need to convert to and from pixels using
7692 * PANGO_PIXELS() or #PANGO_SCALE.
7694 * Keep in mind that the layout text may contain a preedit string, so
7695 * gtk_entry_layout_index_to_text_index() and
7696 * gtk_entry_text_index_to_layout_index() are needed to convert byte
7697 * indices in the layout to byte indices in the entry contents.
7700 gtk_entry_get_layout_offsets (GtkEntry *entry,
7704 gint text_area_x, text_area_y;
7706 g_return_if_fail (GTK_IS_ENTRY (entry));
7708 /* this gets coords relative to text area */
7709 get_layout_position (entry, x, y);
7711 /* convert to widget coords */
7712 gtk_entry_get_text_area_size (entry, &text_area_x, &text_area_y, NULL, NULL);
7723 * gtk_entry_set_alignment:
7724 * @entry: a #GtkEntry
7725 * @xalign: The horizontal alignment, from 0 (left) to 1 (right).
7726 * Reversed for RTL layouts
7728 * Sets the alignment for the contents of the entry. This controls
7729 * the horizontal positioning of the contents when the displayed
7730 * text is shorter than the width of the entry.
7735 gtk_entry_set_alignment (GtkEntry *entry, gfloat xalign)
7737 GtkEntryPrivate *priv;
7739 g_return_if_fail (GTK_IS_ENTRY (entry));
7745 else if (xalign > 1.0)
7748 if (xalign != priv->xalign)
7750 priv->xalign = xalign;
7752 gtk_entry_recompute (entry);
7754 g_object_notify (G_OBJECT (entry), "xalign");
7759 * gtk_entry_get_alignment:
7760 * @entry: a #GtkEntry
7762 * Gets the value set by gtk_entry_set_alignment().
7764 * Return value: the alignment
7769 gtk_entry_get_alignment (GtkEntry *entry)
7771 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
7773 return entry->priv->xalign;
7777 * gtk_entry_set_icon_from_pixbuf:
7778 * @entry: a #GtkEntry
7779 * @icon_pos: Icon position
7780 * @pixbuf: (allow-none): A #GdkPixbuf, or %NULL
7782 * Sets the icon shown in the specified position using a pixbuf.
7784 * If @pixbuf is %NULL, no icon will be shown in the specified position.
7789 gtk_entry_set_icon_from_pixbuf (GtkEntry *entry,
7790 GtkEntryIconPosition icon_pos,
7793 GtkEntryPrivate *priv;
7794 EntryIconInfo *icon_info;
7796 g_return_if_fail (GTK_IS_ENTRY (entry));
7797 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7801 if ((icon_info = priv->icons[icon_pos]) == NULL)
7802 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7804 g_object_freeze_notify (G_OBJECT (entry));
7807 g_object_ref (pixbuf);
7809 gtk_entry_clear (entry, icon_pos);
7813 icon_info->storage_type = GTK_IMAGE_PIXBUF;
7814 icon_info->pixbuf = pixbuf;
7816 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7818 g_object_notify (G_OBJECT (entry), "primary-icon-pixbuf");
7819 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7823 g_object_notify (G_OBJECT (entry), "secondary-icon-pixbuf");
7824 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7827 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7828 gdk_window_show_unraised (icon_info->window);
7831 gtk_entry_ensure_pixbuf (entry, icon_pos);
7833 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7834 gtk_widget_queue_resize (GTK_WIDGET (entry));
7836 g_object_thaw_notify (G_OBJECT (entry));
7840 * gtk_entry_set_icon_from_stock:
7841 * @entry: A #GtkEntry
7842 * @icon_pos: Icon position
7843 * @stock_id: (allow-none): The name of the stock item, or %NULL
7845 * Sets the icon shown in the entry at the specified position from
7848 * If @stock_id is %NULL, no icon will be shown in the specified position.
7853 gtk_entry_set_icon_from_stock (GtkEntry *entry,
7854 GtkEntryIconPosition icon_pos,
7855 const gchar *stock_id)
7857 GtkEntryPrivate *priv;
7858 EntryIconInfo *icon_info;
7861 g_return_if_fail (GTK_IS_ENTRY (entry));
7862 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7866 if ((icon_info = priv->icons[icon_pos]) == NULL)
7867 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7869 g_object_freeze_notify (G_OBJECT (entry));
7871 /* need to dup before clearing */
7872 new_id = g_strdup (stock_id);
7874 gtk_entry_clear (entry, icon_pos);
7878 icon_info->storage_type = GTK_IMAGE_STOCK;
7879 icon_info->stock_id = new_id;
7881 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7883 g_object_notify (G_OBJECT (entry), "primary-icon-stock");
7884 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7888 g_object_notify (G_OBJECT (entry), "secondary-icon-stock");
7889 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7892 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7893 gdk_window_show_unraised (icon_info->window);
7896 gtk_entry_ensure_pixbuf (entry, icon_pos);
7898 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7899 gtk_widget_queue_resize (GTK_WIDGET (entry));
7901 g_object_thaw_notify (G_OBJECT (entry));
7905 * gtk_entry_set_icon_from_icon_name:
7906 * @entry: A #GtkEntry
7907 * @icon_pos: The position at which to set the icon
7908 * @icon_name: (allow-none): An icon name, or %NULL
7910 * Sets the icon shown in the entry at the specified position
7911 * from the current icon theme.
7913 * If the icon name isn't known, a "broken image" icon will be displayed
7916 * If @icon_name is %NULL, no icon will be shown in the specified position.
7921 gtk_entry_set_icon_from_icon_name (GtkEntry *entry,
7922 GtkEntryIconPosition icon_pos,
7923 const gchar *icon_name)
7925 GtkEntryPrivate *priv;
7926 EntryIconInfo *icon_info;
7929 g_return_if_fail (GTK_IS_ENTRY (entry));
7930 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7934 if ((icon_info = priv->icons[icon_pos]) == NULL)
7935 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7937 g_object_freeze_notify (G_OBJECT (entry));
7939 /* need to dup before clearing */
7940 new_name = g_strdup (icon_name);
7942 gtk_entry_clear (entry, icon_pos);
7944 if (new_name != NULL)
7946 icon_info->storage_type = GTK_IMAGE_ICON_NAME;
7947 icon_info->icon_name = new_name;
7949 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7951 g_object_notify (G_OBJECT (entry), "primary-icon-name");
7952 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7956 g_object_notify (G_OBJECT (entry), "secondary-icon-name");
7957 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7960 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7961 gdk_window_show_unraised (icon_info->window);
7964 gtk_entry_ensure_pixbuf (entry, icon_pos);
7966 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7967 gtk_widget_queue_resize (GTK_WIDGET (entry));
7969 g_object_thaw_notify (G_OBJECT (entry));
7973 * gtk_entry_set_icon_from_gicon:
7974 * @entry: A #GtkEntry
7975 * @icon_pos: The position at which to set the icon
7976 * @icon: (allow-none): The icon to set, or %NULL
7978 * Sets the icon shown in the entry at the specified position
7979 * from the current icon theme.
7980 * If the icon isn't known, a "broken image" icon will be displayed
7983 * If @icon is %NULL, no icon will be shown in the specified position.
7988 gtk_entry_set_icon_from_gicon (GtkEntry *entry,
7989 GtkEntryIconPosition icon_pos,
7992 GtkEntryPrivate *priv;
7993 EntryIconInfo *icon_info;
7995 g_return_if_fail (GTK_IS_ENTRY (entry));
7996 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8000 if ((icon_info = priv->icons[icon_pos]) == NULL)
8001 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8003 g_object_freeze_notify (G_OBJECT (entry));
8005 /* need to ref before clearing */
8007 g_object_ref (icon);
8009 gtk_entry_clear (entry, icon_pos);
8013 icon_info->storage_type = GTK_IMAGE_GICON;
8014 icon_info->gicon = icon;
8016 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
8018 g_object_notify (G_OBJECT (entry), "primary-icon-gicon");
8019 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
8023 g_object_notify (G_OBJECT (entry), "secondary-icon-gicon");
8024 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
8027 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
8028 gdk_window_show_unraised (icon_info->window);
8031 gtk_entry_ensure_pixbuf (entry, icon_pos);
8033 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
8034 gtk_widget_queue_resize (GTK_WIDGET (entry));
8036 g_object_thaw_notify (G_OBJECT (entry));
8040 * gtk_entry_set_icon_activatable:
8041 * @entry: A #GtkEntry
8042 * @icon_pos: Icon position
8043 * @activatable: %TRUE if the icon should be activatable
8045 * Sets whether the icon is activatable.
8050 gtk_entry_set_icon_activatable (GtkEntry *entry,
8051 GtkEntryIconPosition icon_pos,
8052 gboolean activatable)
8054 GtkEntryPrivate *priv;
8055 EntryIconInfo *icon_info;
8057 g_return_if_fail (GTK_IS_ENTRY (entry));
8058 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8062 if ((icon_info = priv->icons[icon_pos]) == NULL)
8063 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8065 activatable = activatable != FALSE;
8067 if (icon_info->nonactivatable != !activatable)
8069 icon_info->nonactivatable = !activatable;
8071 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
8072 update_cursors (GTK_WIDGET (entry));
8074 g_object_notify (G_OBJECT (entry),
8075 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-activatable" : "secondary-icon-activatable");
8080 * gtk_entry_get_icon_activatable:
8081 * @entry: a #GtkEntry
8082 * @icon_pos: Icon position
8084 * Returns whether the icon is activatable.
8086 * Returns: %TRUE if the icon is activatable.
8091 gtk_entry_get_icon_activatable (GtkEntry *entry,
8092 GtkEntryIconPosition icon_pos)
8094 GtkEntryPrivate *priv;
8095 EntryIconInfo *icon_info;
8097 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
8098 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), FALSE);
8101 icon_info = priv->icons[icon_pos];
8103 return (!icon_info || !icon_info->nonactivatable);
8107 * gtk_entry_get_icon_pixbuf:
8108 * @entry: A #GtkEntry
8109 * @icon_pos: Icon position
8111 * Retrieves the image used for the icon.
8113 * Unlike the other methods of setting and getting icon data, this
8114 * method will work regardless of whether the icon was set using a
8115 * #GdkPixbuf, a #GIcon, a stock item, or an icon name.
8117 * Returns: (transfer none): A #GdkPixbuf, or %NULL if no icon is
8118 * set for this position.
8123 gtk_entry_get_icon_pixbuf (GtkEntry *entry,
8124 GtkEntryIconPosition icon_pos)
8126 GtkEntryPrivate *priv;
8127 EntryIconInfo *icon_info;
8129 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8130 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8134 icon_info = priv->icons[icon_pos];
8139 gtk_entry_ensure_pixbuf (entry, icon_pos);
8141 return icon_info->pixbuf;
8145 * gtk_entry_get_icon_gicon:
8146 * @entry: A #GtkEntry
8147 * @icon_pos: Icon position
8149 * Retrieves the #GIcon used for the icon, or %NULL if there is
8150 * no icon or if the icon was set by some other method (e.g., by
8151 * stock, pixbuf, or icon name).
8153 * Returns: (transfer none): A #GIcon, or %NULL if no icon is set
8154 * or if the icon is not a #GIcon
8159 gtk_entry_get_icon_gicon (GtkEntry *entry,
8160 GtkEntryIconPosition icon_pos)
8162 GtkEntryPrivate *priv;
8163 EntryIconInfo *icon_info;
8165 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8166 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8169 icon_info = priv->icons[icon_pos];
8174 return icon_info->storage_type == GTK_IMAGE_GICON ? icon_info->gicon : NULL;
8178 * gtk_entry_get_icon_stock:
8179 * @entry: A #GtkEntry
8180 * @icon_pos: Icon position
8182 * Retrieves the stock id used for the icon, or %NULL if there is
8183 * no icon or if the icon was set by some other method (e.g., by
8184 * pixbuf, icon name or gicon).
8186 * Returns: A stock id, or %NULL if no icon is set or if the icon
8187 * wasn't set from a stock id
8192 gtk_entry_get_icon_stock (GtkEntry *entry,
8193 GtkEntryIconPosition icon_pos)
8195 GtkEntryPrivate *priv;
8196 EntryIconInfo *icon_info;
8198 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8199 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8202 icon_info = priv->icons[icon_pos];
8207 return icon_info->storage_type == GTK_IMAGE_STOCK ? icon_info->stock_id : NULL;
8211 * gtk_entry_get_icon_name:
8212 * @entry: A #GtkEntry
8213 * @icon_pos: Icon position
8215 * Retrieves the icon name used for the icon, or %NULL if there is
8216 * no icon or if the icon was set by some other method (e.g., by
8217 * pixbuf, stock or gicon).
8219 * Returns: An icon name, or %NULL if no icon is set or if the icon
8220 * wasn't set from an icon name
8225 gtk_entry_get_icon_name (GtkEntry *entry,
8226 GtkEntryIconPosition icon_pos)
8228 GtkEntryPrivate *priv;
8229 EntryIconInfo *icon_info;
8231 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8232 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8235 icon_info = priv->icons[icon_pos];
8240 return icon_info->storage_type == GTK_IMAGE_ICON_NAME ? icon_info->icon_name : NULL;
8244 * gtk_entry_set_icon_sensitive:
8245 * @entry: A #GtkEntry
8246 * @icon_pos: Icon position
8247 * @sensitive: Specifies whether the icon should appear
8248 * sensitive or insensitive
8250 * Sets the sensitivity for the specified icon.
8255 gtk_entry_set_icon_sensitive (GtkEntry *entry,
8256 GtkEntryIconPosition icon_pos,
8259 GtkEntryPrivate *priv;
8260 EntryIconInfo *icon_info;
8262 g_return_if_fail (GTK_IS_ENTRY (entry));
8263 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8267 if ((icon_info = priv->icons[icon_pos]) == NULL)
8268 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8270 if (icon_info->insensitive != !sensitive)
8272 icon_info->insensitive = !sensitive;
8274 icon_info->pressed = FALSE;
8275 icon_info->prelight = FALSE;
8277 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
8278 update_cursors (GTK_WIDGET (entry));
8280 gtk_widget_queue_draw (GTK_WIDGET (entry));
8282 g_object_notify (G_OBJECT (entry),
8283 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-sensitive" : "secondary-icon-sensitive");
8288 * gtk_entry_get_icon_sensitive:
8289 * @entry: a #GtkEntry
8290 * @icon_pos: Icon position
8292 * Returns whether the icon appears sensitive or insensitive.
8294 * Returns: %TRUE if the icon is sensitive.
8299 gtk_entry_get_icon_sensitive (GtkEntry *entry,
8300 GtkEntryIconPosition icon_pos)
8302 GtkEntryPrivate *priv;
8303 EntryIconInfo *icon_info;
8305 g_return_val_if_fail (GTK_IS_ENTRY (entry), TRUE);
8306 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), TRUE);
8310 icon_info = priv->icons[icon_pos];
8312 return (!icon_info || !icon_info->insensitive);
8317 * gtk_entry_get_icon_storage_type:
8318 * @entry: a #GtkEntry
8319 * @icon_pos: Icon position
8321 * Gets the type of representation being used by the icon
8322 * to store image data. If the icon has no image data,
8323 * the return value will be %GTK_IMAGE_EMPTY.
8325 * Return value: image representation being used
8330 gtk_entry_get_icon_storage_type (GtkEntry *entry,
8331 GtkEntryIconPosition icon_pos)
8333 GtkEntryPrivate *priv;
8334 EntryIconInfo *icon_info;
8336 g_return_val_if_fail (GTK_IS_ENTRY (entry), GTK_IMAGE_EMPTY);
8337 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), GTK_IMAGE_EMPTY);
8341 icon_info = priv->icons[icon_pos];
8344 return GTK_IMAGE_EMPTY;
8346 return icon_info->storage_type;
8350 * gtk_entry_get_icon_at_pos:
8351 * @entry: a #GtkEntry
8352 * @x: the x coordinate of the position to find
8353 * @y: the y coordinate of the position to find
8355 * Finds the icon at the given position and return its index. The
8356 * position's coordinates are relative to the @entry's top left corner.
8357 * If @x, @y doesn't lie inside an icon, -1 is returned.
8358 * This function is intended for use in a #GtkWidget::query-tooltip
8361 * Returns: the index of the icon at the given position, or -1
8366 gtk_entry_get_icon_at_pos (GtkEntry *entry,
8370 GtkAllocation primary;
8371 GtkAllocation secondary;
8372 gint frame_x, frame_y;
8374 g_return_val_if_fail (GTK_IS_ENTRY (entry), -1);
8376 get_frame_size (entry, FALSE, &frame_x, &frame_y, NULL, NULL);
8380 get_icon_allocations (entry, &primary, &secondary);
8382 if (primary.x <= x && x < primary.x + primary.width &&
8383 primary.y <= y && y < primary.y + primary.height)
8384 return GTK_ENTRY_ICON_PRIMARY;
8386 if (secondary.x <= x && x < secondary.x + secondary.width &&
8387 secondary.y <= y && y < secondary.y + secondary.height)
8388 return GTK_ENTRY_ICON_SECONDARY;
8394 * gtk_entry_set_icon_drag_source:
8395 * @entry: a #GtkIconEntry
8396 * @icon_pos: icon position
8397 * @target_list: the targets (data formats) in which the data can be provided
8398 * @actions: a bitmask of the allowed drag actions
8400 * Sets up the icon at the given position so that GTK+ will start a drag
8401 * operation when the user clicks and drags the icon.
8403 * To handle the drag operation, you need to connect to the usual
8404 * #GtkWidget::drag-data-get (or possibly #GtkWidget::drag-data-delete)
8405 * signal, and use gtk_entry_get_current_icon_drag_source() in
8406 * your signal handler to find out if the drag was started from
8409 * By default, GTK+ uses the icon as the drag icon. You can use the
8410 * #GtkWidget::drag-begin signal to set a different icon. Note that you
8411 * have to use g_signal_connect_after() to ensure that your signal handler
8412 * gets executed after the default handler.
8417 gtk_entry_set_icon_drag_source (GtkEntry *entry,
8418 GtkEntryIconPosition icon_pos,
8419 GtkTargetList *target_list,
8420 GdkDragAction actions)
8422 GtkEntryPrivate *priv;
8423 EntryIconInfo *icon_info;
8425 g_return_if_fail (GTK_IS_ENTRY (entry));
8426 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8430 if ((icon_info = priv->icons[icon_pos]) == NULL)
8431 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8433 if (icon_info->target_list)
8434 gtk_target_list_unref (icon_info->target_list);
8435 icon_info->target_list = target_list;
8436 if (icon_info->target_list)
8437 gtk_target_list_ref (icon_info->target_list);
8439 icon_info->actions = actions;
8443 * gtk_entry_get_current_icon_drag_source:
8444 * @entry: a #GtkIconEntry
8446 * Returns the index of the icon which is the source of the current
8447 * DND operation, or -1.
8449 * This function is meant to be used in a #GtkWidget::drag-data-get
8452 * Returns: index of the icon which is the source of the current
8453 * DND operation, or -1.
8458 gtk_entry_get_current_icon_drag_source (GtkEntry *entry)
8460 GtkEntryPrivate *priv;
8461 EntryIconInfo *icon_info = NULL;
8464 g_return_val_if_fail (GTK_IS_ENTRY (entry), -1);
8468 for (i = 0; i < MAX_ICONS; i++)
8470 if ((icon_info = priv->icons[i]))
8472 if (icon_info->in_drag)
8481 * gtk_entry_get_icon_area:
8482 * @entry: A #GtkEntry
8483 * @icon_pos: Icon position
8484 * @icon_area: (out): Return location for the icon's area
8486 * Gets the area where entry's icon at @icon_pos is drawn.
8487 * This function is useful when drawing something to the
8488 * entry in a draw callback.
8490 * If the entry is not realized or has no icon at the given position,
8491 * @icon_area is filled with zeros.
8493 * See also gtk_entry_get_text_area()
8498 gtk_entry_get_icon_area (GtkEntry *entry,
8499 GtkEntryIconPosition icon_pos,
8500 GdkRectangle *icon_area)
8502 GtkEntryPrivate *priv;
8503 EntryIconInfo *icon_info;
8505 g_return_if_fail (GTK_IS_ENTRY (entry));
8506 g_return_if_fail (icon_area != NULL);
8510 icon_info = priv->icons[icon_pos];
8514 GtkAllocation primary;
8515 GtkAllocation secondary;
8517 get_icon_allocations (entry, &primary, &secondary);
8519 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
8520 *icon_area = primary;
8522 *icon_area = secondary;
8528 icon_area->width = 0;
8529 icon_area->height = 0;
8534 ensure_has_tooltip (GtkEntry *entry)
8536 GtkEntryPrivate *priv;
8537 EntryIconInfo *icon_info;
8539 gboolean has_tooltip = FALSE;
8543 for (i = 0; i < MAX_ICONS; i++)
8545 if ((icon_info = priv->icons[i]) != NULL)
8547 if (icon_info->tooltip != NULL)
8555 gtk_widget_set_has_tooltip (GTK_WIDGET (entry), has_tooltip);
8559 * gtk_entry_get_icon_tooltip_text:
8560 * @entry: a #GtkEntry
8561 * @icon_pos: the icon position
8563 * Gets the contents of the tooltip on the icon at the specified
8564 * position in @entry.
8566 * Returns: the tooltip text, or %NULL. Free the returned string
8567 * with g_free() when done.
8572 gtk_entry_get_icon_tooltip_text (GtkEntry *entry,
8573 GtkEntryIconPosition icon_pos)
8575 GtkEntryPrivate *priv;
8576 EntryIconInfo *icon_info;
8579 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8580 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8584 icon_info = priv->icons[icon_pos];
8589 if (icon_info->tooltip &&
8590 !pango_parse_markup (icon_info->tooltip, -1, 0, NULL, &text, NULL, NULL))
8591 g_assert (NULL == text); /* text should still be NULL in case of markup errors */
8597 * gtk_entry_set_icon_tooltip_text:
8598 * @entry: a #GtkEntry
8599 * @icon_pos: the icon position
8600 * @tooltip: (allow-none): the contents of the tooltip for the icon, or %NULL
8602 * Sets @tooltip as the contents of the tooltip for the icon
8603 * at the specified position.
8605 * Use %NULL for @tooltip to remove an existing tooltip.
8607 * See also gtk_widget_set_tooltip_text() and
8608 * gtk_entry_set_icon_tooltip_markup().
8613 gtk_entry_set_icon_tooltip_text (GtkEntry *entry,
8614 GtkEntryIconPosition icon_pos,
8615 const gchar *tooltip)
8617 GtkEntryPrivate *priv;
8618 EntryIconInfo *icon_info;
8620 g_return_if_fail (GTK_IS_ENTRY (entry));
8621 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8625 if ((icon_info = priv->icons[icon_pos]) == NULL)
8626 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8628 if (icon_info->tooltip)
8629 g_free (icon_info->tooltip);
8631 /* Treat an empty string as a NULL string,
8632 * because an empty string would be useless for a tooltip:
8634 if (tooltip && tooltip[0] == '\0')
8637 icon_info->tooltip = tooltip ? g_markup_escape_text (tooltip, -1) : NULL;
8639 ensure_has_tooltip (entry);
8643 * gtk_entry_get_icon_tooltip_markup:
8644 * @entry: a #GtkEntry
8645 * @icon_pos: the icon position
8647 * Gets the contents of the tooltip on the icon at the specified
8648 * position in @entry.
8650 * Returns: the tooltip text, or %NULL. Free the returned string
8651 * with g_free() when done.
8656 gtk_entry_get_icon_tooltip_markup (GtkEntry *entry,
8657 GtkEntryIconPosition icon_pos)
8659 GtkEntryPrivate *priv;
8660 EntryIconInfo *icon_info;
8662 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8663 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8667 icon_info = priv->icons[icon_pos];
8672 return g_strdup (icon_info->tooltip);
8676 * gtk_entry_set_icon_tooltip_markup:
8677 * @entry: a #GtkEntry
8678 * @icon_pos: the icon position
8679 * @tooltip: (allow-none): the contents of the tooltip for the icon, or %NULL
8681 * Sets @tooltip as the contents of the tooltip for the icon at
8682 * the specified position. @tooltip is assumed to be marked up with
8683 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
8685 * Use %NULL for @tooltip to remove an existing tooltip.
8687 * See also gtk_widget_set_tooltip_markup() and
8688 * gtk_enty_set_icon_tooltip_text().
8693 gtk_entry_set_icon_tooltip_markup (GtkEntry *entry,
8694 GtkEntryIconPosition icon_pos,
8695 const gchar *tooltip)
8697 GtkEntryPrivate *priv;
8698 EntryIconInfo *icon_info;
8700 g_return_if_fail (GTK_IS_ENTRY (entry));
8701 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8705 if ((icon_info = priv->icons[icon_pos]) == NULL)
8706 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8708 if (icon_info->tooltip)
8709 g_free (icon_info->tooltip);
8711 /* Treat an empty string as a NULL string,
8712 * because an empty string would be useless for a tooltip:
8714 if (tooltip && tooltip[0] == '\0')
8717 icon_info->tooltip = g_strdup (tooltip);
8719 ensure_has_tooltip (entry);
8723 gtk_entry_query_tooltip (GtkWidget *widget,
8726 gboolean keyboard_tip,
8727 GtkTooltip *tooltip)
8730 GtkEntryPrivate *priv;
8731 EntryIconInfo *icon_info;
8734 entry = GTK_ENTRY (widget);
8739 icon_pos = gtk_entry_get_icon_at_pos (entry, x, y);
8742 if ((icon_info = priv->icons[icon_pos]) != NULL)
8744 if (icon_info->tooltip)
8746 gtk_tooltip_set_markup (tooltip, icon_info->tooltip);
8755 return GTK_WIDGET_CLASS (gtk_entry_parent_class)->query_tooltip (widget,
8762 /* Quick hack of a popup menu
8765 activate_cb (GtkWidget *menuitem,
8768 const gchar *signal = g_object_get_data (G_OBJECT (menuitem), "gtk-signal");
8769 g_signal_emit_by_name (entry, signal);
8774 gtk_entry_mnemonic_activate (GtkWidget *widget,
8775 gboolean group_cycling)
8777 gtk_widget_grab_focus (widget);
8782 append_action_signal (GtkEntry *entry,
8784 const gchar *stock_id,
8785 const gchar *signal,
8788 GtkWidget *menuitem = gtk_image_menu_item_new_from_stock (stock_id, NULL);
8790 g_object_set_data (G_OBJECT (menuitem), I_("gtk-signal"), (char *)signal);
8791 g_signal_connect (menuitem, "activate",
8792 G_CALLBACK (activate_cb), entry);
8794 gtk_widget_set_sensitive (menuitem, sensitive);
8796 gtk_widget_show (menuitem);
8797 gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
8801 popup_menu_detach (GtkWidget *attach_widget,
8804 GtkEntry *entry_attach = GTK_ENTRY (attach_widget);
8805 GtkEntryPrivate *priv_attach = entry_attach->priv;
8807 priv_attach->popup_menu = NULL;
8811 popup_position_func (GtkMenu *menu,
8817 GtkEntry *entry = GTK_ENTRY (user_data);
8818 GtkEntryPrivate *priv = entry->priv;
8819 GtkWidget *widget = GTK_WIDGET (entry);
8821 GtkRequisition menu_req;
8822 GdkRectangle monitor;
8823 GtkBorder inner_border;
8824 gint monitor_num, strong_x, height;
8826 g_return_if_fail (gtk_widget_get_realized (widget));
8828 gdk_window_get_origin (priv->text_area, x, y);
8830 screen = gtk_widget_get_screen (widget);
8831 monitor_num = gdk_screen_get_monitor_at_window (screen, priv->text_area);
8832 if (monitor_num < 0)
8834 gtk_menu_set_monitor (menu, monitor_num);
8836 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
8837 gtk_widget_get_preferred_size (priv->popup_menu,
8839 height = gdk_window_get_height (priv->text_area);
8840 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
8841 _gtk_entry_effective_inner_border (entry, &inner_border);
8843 *x += inner_border.left + strong_x - priv->scroll_offset;
8844 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
8845 *x -= menu_req.width;
8847 if ((*y + height + menu_req.height) <= monitor.y + monitor.height)
8849 else if ((*y - menu_req.height) >= monitor.y)
8850 *y -= menu_req.height;
8851 else if (monitor.y + monitor.height - (*y + height) > *y)
8854 *y -= menu_req.height;
8860 unichar_chosen_func (const char *text,
8863 GtkEntry *entry = GTK_ENTRY (data);
8864 GtkEntryPrivate *priv = entry->priv;
8867 gtk_entry_enter_text (entry, text);
8878 popup_targets_received (GtkClipboard *clipboard,
8879 GtkSelectionData *data,
8882 PopupInfo *info = user_data;
8883 GtkEntry *entry = info->entry;
8884 GtkEntryPrivate *info_entry_priv = entry->priv;
8886 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
8889 gboolean clipboard_contains_text;
8890 GtkWidget *menuitem;
8892 gboolean show_input_method_menu;
8893 gboolean show_unicode_menu;
8895 clipboard_contains_text = gtk_selection_data_targets_include_text (data);
8896 if (info_entry_priv->popup_menu)
8897 gtk_widget_destroy (info_entry_priv->popup_menu);
8899 info_entry_priv->popup_menu = gtk_menu_new ();
8901 gtk_menu_attach_to_widget (GTK_MENU (info_entry_priv->popup_menu),
8905 mode = gtk_entry_get_display_mode (entry);
8906 append_action_signal (entry, info_entry_priv->popup_menu, GTK_STOCK_CUT, "cut-clipboard",
8907 info_entry_priv->editable && mode == DISPLAY_NORMAL &&
8908 info_entry_priv->current_pos != info_entry_priv->selection_bound);
8910 append_action_signal (entry, info_entry_priv->popup_menu, GTK_STOCK_COPY, "copy-clipboard",
8911 mode == DISPLAY_NORMAL &&
8912 info_entry_priv->current_pos != info_entry_priv->selection_bound);
8914 append_action_signal (entry, info_entry_priv->popup_menu, GTK_STOCK_PASTE, "paste-clipboard",
8915 info_entry_priv->editable && clipboard_contains_text);
8917 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_DELETE, NULL);
8918 gtk_widget_set_sensitive (menuitem, info_entry_priv->editable && info_entry_priv->current_pos != info_entry_priv->selection_bound);
8919 g_signal_connect_swapped (menuitem, "activate",
8920 G_CALLBACK (gtk_entry_delete_cb), entry);
8921 gtk_widget_show (menuitem);
8922 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8924 menuitem = gtk_separator_menu_item_new ();
8925 gtk_widget_show (menuitem);
8926 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8928 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_SELECT_ALL, NULL);
8929 gtk_widget_set_sensitive (menuitem, gtk_entry_buffer_get_length (info_entry_priv->buffer) > 0);
8930 g_signal_connect_swapped (menuitem, "activate",
8931 G_CALLBACK (gtk_entry_select_all), entry);
8932 gtk_widget_show (menuitem);
8933 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8935 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
8936 "gtk-show-input-method-menu", &show_input_method_menu,
8937 "gtk-show-unicode-menu", &show_unicode_menu,
8940 if (show_input_method_menu || show_unicode_menu)
8942 menuitem = gtk_separator_menu_item_new ();
8943 gtk_widget_show (menuitem);
8944 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8947 if (show_input_method_menu)
8949 menuitem = gtk_menu_item_new_with_mnemonic (_("Input _Methods"));
8950 gtk_widget_set_sensitive (menuitem, info_entry_priv->editable);
8951 gtk_widget_show (menuitem);
8952 submenu = gtk_menu_new ();
8953 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
8955 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8957 gtk_im_multicontext_append_menuitems (GTK_IM_MULTICONTEXT (info_entry_priv->im_context),
8958 GTK_MENU_SHELL (submenu));
8961 if (show_unicode_menu)
8963 menuitem = gtk_menu_item_new_with_mnemonic (_("_Insert Unicode Control Character"));
8964 gtk_widget_set_sensitive (menuitem, info_entry_priv->editable);
8965 gtk_widget_show (menuitem);
8967 submenu = gtk_menu_new ();
8968 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
8969 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8971 _gtk_text_util_append_special_char_menuitems (GTK_MENU_SHELL (submenu),
8972 unichar_chosen_func,
8976 g_signal_emit (entry,
8977 signals[POPULATE_POPUP],
8979 info_entry_priv->popup_menu);
8983 gtk_menu_popup (GTK_MENU (info_entry_priv->popup_menu), NULL, NULL,
8985 info->button, info->time);
8988 gtk_menu_popup (GTK_MENU (info_entry_priv->popup_menu), NULL, NULL,
8989 popup_position_func, entry,
8990 info->button, info->time);
8991 gtk_menu_shell_select_first (GTK_MENU_SHELL (info_entry_priv->popup_menu), FALSE);
8995 g_object_unref (entry);
8996 g_slice_free (PopupInfo, info);
9000 gtk_entry_do_popup (GtkEntry *entry,
9001 GdkEventButton *event)
9003 PopupInfo *info = g_slice_new (PopupInfo);
9005 /* In order to know what entries we should make sensitive, we
9006 * ask for the current targets of the clipboard, and when
9007 * we get them, then we actually pop up the menu.
9009 info->entry = g_object_ref (entry);
9013 info->button = event->button;
9014 info->time = event->time;
9019 info->time = gtk_get_current_event_time ();
9022 gtk_clipboard_request_contents (gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_CLIPBOARD),
9023 gdk_atom_intern_static_string ("TARGETS"),
9024 popup_targets_received,
9029 gtk_entry_popup_menu (GtkWidget *widget)
9031 gtk_entry_do_popup (GTK_ENTRY (widget), NULL);
9036 gtk_entry_drag_begin (GtkWidget *widget,
9037 GdkDragContext *context)
9039 GtkEntry *entry = GTK_ENTRY (widget);
9040 GtkEntryPrivate *priv = entry->priv;
9043 for (i = 0; i < MAX_ICONS; i++)
9045 EntryIconInfo *icon_info = priv->icons[i];
9047 if (icon_info != NULL)
9049 if (icon_info->in_drag)
9051 switch (icon_info->storage_type)
9053 case GTK_IMAGE_STOCK:
9054 gtk_drag_set_icon_stock (context, icon_info->stock_id, -2, -2);
9057 case GTK_IMAGE_ICON_NAME:
9058 gtk_drag_set_icon_name (context, icon_info->icon_name, -2, -2);
9061 /* FIXME: No GIcon support for dnd icons */
9062 case GTK_IMAGE_GICON:
9063 case GTK_IMAGE_PIXBUF:
9064 gtk_drag_set_icon_pixbuf (context, icon_info->pixbuf, -2, -2);
9067 g_assert_not_reached ();
9075 gtk_entry_drag_end (GtkWidget *widget,
9076 GdkDragContext *context)
9078 GtkEntry *entry = GTK_ENTRY (widget);
9079 GtkEntryPrivate *priv = entry->priv;
9082 for (i = 0; i < MAX_ICONS; i++)
9084 EntryIconInfo *icon_info = priv->icons[i];
9086 if (icon_info != NULL)
9087 icon_info->in_drag = 0;
9092 gtk_entry_drag_leave (GtkWidget *widget,
9093 GdkDragContext *context,
9096 GtkEntry *entry = GTK_ENTRY (widget);
9097 GtkEntryPrivate *priv = entry->priv;
9099 priv->dnd_position = -1;
9100 gtk_widget_queue_draw (widget);
9104 gtk_entry_drag_drop (GtkWidget *widget,
9105 GdkDragContext *context,
9110 GtkEntry *entry = GTK_ENTRY (widget);
9111 GtkEntryPrivate *priv = entry->priv;
9112 GdkAtom target = GDK_NONE;
9115 target = gtk_drag_dest_find_target (widget, context, NULL);
9117 if (target != GDK_NONE)
9118 gtk_drag_get_data (widget, context, target, time);
9120 gtk_drag_finish (context, FALSE, FALSE, time);
9126 gtk_entry_drag_motion (GtkWidget *widget,
9127 GdkDragContext *context,
9132 GtkEntry *entry = GTK_ENTRY (widget);
9133 GtkEntryPrivate *priv = entry->priv;
9134 GtkStyleContext *style_context;
9135 GtkWidget *source_widget;
9136 GdkDragAction suggested_action;
9137 gint new_position, old_position;
9141 style_context = gtk_widget_get_style_context (widget);
9142 gtk_style_context_get_padding (style_context, 0, &padding);
9146 old_position = priv->dnd_position;
9147 new_position = gtk_entry_find_position (entry, x + priv->scroll_offset);
9149 if (priv->editable &&
9150 gtk_drag_dest_find_target (widget, context, NULL) != GDK_NONE)
9152 source_widget = gtk_drag_get_source_widget (context);
9153 suggested_action = gdk_drag_context_get_suggested_action (context);
9155 if (!gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &sel1, &sel2) ||
9156 new_position < sel1 || new_position > sel2)
9158 if (source_widget == widget)
9160 /* Default to MOVE, unless the user has
9161 * pressed ctrl or alt to affect available actions
9163 if ((gdk_drag_context_get_actions (context) & GDK_ACTION_MOVE) != 0)
9164 suggested_action = GDK_ACTION_MOVE;
9167 priv->dnd_position = new_position;
9171 if (source_widget == widget)
9172 suggested_action = 0; /* Can't drop in selection where drag started */
9174 priv->dnd_position = -1;
9179 /* Entry not editable, or no text */
9180 suggested_action = 0;
9181 priv->dnd_position = -1;
9184 gdk_drag_status (context, suggested_action, time);
9186 if (priv->dnd_position != old_position)
9187 gtk_widget_queue_draw (widget);
9193 gtk_entry_drag_data_received (GtkWidget *widget,
9194 GdkDragContext *context,
9197 GtkSelectionData *selection_data,
9201 GtkEntry *entry = GTK_ENTRY (widget);
9202 GtkEntryPrivate *priv = entry->priv;
9203 GtkEditable *editable = GTK_EDITABLE (widget);
9204 GtkStyleContext *style_context;
9208 str = (gchar *) gtk_selection_data_get_text (selection_data);
9210 style_context = gtk_widget_get_style_context (widget);
9211 gtk_style_context_get_padding (style_context, 0, &padding);
9215 if (str && priv->editable)
9221 if (priv->truncate_multiline)
9222 length = truncate_multiline (str);
9224 new_position = gtk_entry_find_position (entry, x + priv->scroll_offset);
9226 if (!gtk_editable_get_selection_bounds (editable, &sel1, &sel2) ||
9227 new_position < sel1 || new_position > sel2)
9229 gtk_editable_insert_text (editable, str, length, &new_position);
9233 /* Replacing selection */
9234 begin_change (entry);
9235 g_object_freeze_notify (G_OBJECT (entry));
9236 gtk_editable_delete_text (editable, sel1, sel2);
9237 gtk_editable_insert_text (editable, str, length, &sel1);
9238 g_object_thaw_notify (G_OBJECT (entry));
9242 gtk_drag_finish (context, TRUE, gdk_drag_context_get_selected_action (context) == GDK_ACTION_MOVE, time);
9246 /* Drag and drop didn't happen! */
9247 gtk_drag_finish (context, FALSE, FALSE, time);
9254 gtk_entry_drag_data_get (GtkWidget *widget,
9255 GdkDragContext *context,
9256 GtkSelectionData *selection_data,
9260 GtkEntry *entry = GTK_ENTRY (widget);
9261 GtkEntryPrivate *priv = entry->priv;
9262 GtkEditable *editable = GTK_EDITABLE (widget);
9263 gint sel_start, sel_end;
9266 /* If there is an icon drag going on, exit early. */
9267 for (i = 0; i < MAX_ICONS; i++)
9269 EntryIconInfo *icon_info = priv->icons[i];
9271 if (icon_info != NULL)
9273 if (icon_info->in_drag)
9278 if (gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end))
9280 gchar *str = gtk_entry_get_display_text (GTK_ENTRY (widget), sel_start, sel_end);
9282 gtk_selection_data_set_text (selection_data, str, -1);
9290 gtk_entry_drag_data_delete (GtkWidget *widget,
9291 GdkDragContext *context)
9293 GtkEntry *entry = GTK_ENTRY (widget);
9294 GtkEntryPrivate *priv = entry->priv;
9295 GtkEditable *editable = GTK_EDITABLE (widget);
9296 gint sel_start, sel_end;
9299 /* If there is an icon drag going on, exit early. */
9300 for (i = 0; i < MAX_ICONS; i++)
9302 EntryIconInfo *icon_info = priv->icons[i];
9304 if (icon_info != NULL)
9306 if (icon_info->in_drag)
9311 if (priv->editable &&
9312 gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end))
9313 gtk_editable_delete_text (editable, sel_start, sel_end);
9316 /* We display the cursor when
9318 * - the selection is empty, AND
9319 * - the widget has focus
9322 #define CURSOR_ON_MULTIPLIER 2
9323 #define CURSOR_OFF_MULTIPLIER 1
9324 #define CURSOR_PEND_MULTIPLIER 3
9325 #define CURSOR_DIVIDER 3
9328 cursor_blinks (GtkEntry *entry)
9330 GtkEntryPrivate *priv = entry->priv;
9332 if (gtk_widget_has_focus (GTK_WIDGET (entry)) &&
9334 priv->selection_bound == priv->current_pos)
9336 GtkSettings *settings;
9339 settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9340 g_object_get (settings, "gtk-cursor-blink", &blink, NULL);
9349 get_cursor_time (GtkEntry *entry)
9351 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9354 g_object_get (settings, "gtk-cursor-blink-time", &time, NULL);
9360 get_cursor_blink_timeout (GtkEntry *entry)
9362 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9365 g_object_get (settings, "gtk-cursor-blink-timeout", &timeout, NULL);
9371 show_cursor (GtkEntry *entry)
9373 GtkEntryPrivate *priv = entry->priv;
9376 if (!priv->cursor_visible)
9378 priv->cursor_visible = TRUE;
9380 widget = GTK_WIDGET (entry);
9381 if (gtk_widget_has_focus (widget) && priv->selection_bound == priv->current_pos)
9382 gtk_widget_queue_draw (widget);
9387 hide_cursor (GtkEntry *entry)
9389 GtkEntryPrivate *priv = entry->priv;
9392 if (priv->cursor_visible)
9394 priv->cursor_visible = FALSE;
9396 widget = GTK_WIDGET (entry);
9397 if (gtk_widget_has_focus (widget) && priv->selection_bound == priv->current_pos)
9398 gtk_widget_queue_draw (widget);
9406 blink_cb (gpointer data)
9409 GtkEntryPrivate *priv;
9412 entry = GTK_ENTRY (data);
9415 if (!gtk_widget_has_focus (GTK_WIDGET (entry)))
9417 g_warning ("GtkEntry - did not receive focus-out-event. If you\n"
9418 "connect a handler to this signal, it must return\n"
9419 "FALSE so the entry gets the event as well");
9421 gtk_entry_check_cursor_blink (entry);
9426 g_assert (priv->selection_bound == priv->current_pos);
9428 blink_timeout = get_cursor_blink_timeout (entry);
9429 if (priv->blink_time > 1000 * blink_timeout &&
9430 blink_timeout < G_MAXINT/1000)
9432 /* we've blinked enough without the user doing anything, stop blinking */
9433 show_cursor (entry);
9434 priv->blink_timeout = 0;
9436 else if (priv->cursor_visible)
9438 hide_cursor (entry);
9439 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_OFF_MULTIPLIER / CURSOR_DIVIDER,
9445 show_cursor (entry);
9446 priv->blink_time += get_cursor_time (entry);
9447 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
9452 /* Remove ourselves */
9457 gtk_entry_check_cursor_blink (GtkEntry *entry)
9459 GtkEntryPrivate *priv = entry->priv;
9461 if (cursor_blinks (entry))
9463 if (!priv->blink_timeout)
9465 show_cursor (entry);
9466 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
9473 if (priv->blink_timeout)
9475 g_source_remove (priv->blink_timeout);
9476 priv->blink_timeout = 0;
9479 priv->cursor_visible = TRUE;
9484 gtk_entry_pend_cursor_blink (GtkEntry *entry)
9486 GtkEntryPrivate *priv = entry->priv;
9488 if (cursor_blinks (entry))
9490 if (priv->blink_timeout != 0)
9491 g_source_remove (priv->blink_timeout);
9493 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_PEND_MULTIPLIER / CURSOR_DIVIDER,
9496 show_cursor (entry);
9501 gtk_entry_reset_blink_time (GtkEntry *entry)
9503 GtkEntryPrivate *priv = entry->priv;
9505 priv->blink_time = 0;
9511 gtk_entry_completion_timeout (gpointer data)
9513 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (data);
9514 GtkEntryPrivate *completion_entry_priv = GTK_ENTRY (completion->priv->entry)->priv;
9516 completion->priv->completion_timeout = 0;
9518 if (completion->priv->filter_model &&
9519 g_utf8_strlen (gtk_entry_get_text (GTK_ENTRY (completion->priv->entry)), -1)
9520 >= completion->priv->minimum_key_length)
9524 GtkTreeSelection *s;
9525 gboolean popup_single;
9527 gtk_entry_completion_complete (completion);
9528 matches = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->filter_model), NULL);
9530 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9532 s = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view));
9534 gtk_tree_selection_unselect_all (s);
9536 actions = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->actions), NULL);
9538 g_object_get (completion, "popup-single-match", &popup_single, NULL);
9539 if ((matches > (popup_single ? 0: 1)) || actions > 0)
9541 if (gtk_widget_get_visible (completion->priv->popup_window))
9542 _gtk_entry_completion_resize_popup (completion);
9544 _gtk_entry_completion_popup (completion, completion_entry_priv->completion_device);
9547 _gtk_entry_completion_popdown (completion);
9549 else if (gtk_widget_get_visible (completion->priv->popup_window))
9550 _gtk_entry_completion_popdown (completion);
9555 static inline gboolean
9556 keyval_is_cursor_move (guint keyval)
9558 if (keyval == GDK_KEY_Up || keyval == GDK_KEY_KP_Up)
9561 if (keyval == GDK_KEY_Down || keyval == GDK_KEY_KP_Down)
9564 if (keyval == GDK_KEY_Page_Up)
9567 if (keyval == GDK_KEY_Page_Down)
9574 gtk_entry_completion_key_press (GtkWidget *widget,
9578 gint matches, actions = 0;
9579 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
9581 if (!gtk_widget_get_mapped (completion->priv->popup_window))
9584 matches = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->filter_model), NULL);
9586 if (completion->priv->actions)
9587 actions = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->actions), NULL);
9589 if (keyval_is_cursor_move (event->keyval))
9591 GtkTreePath *path = NULL;
9593 if (event->keyval == GDK_KEY_Up || event->keyval == GDK_KEY_KP_Up)
9595 if (completion->priv->current_selected < 0)
9596 completion->priv->current_selected = matches + actions - 1;
9598 completion->priv->current_selected--;
9600 else if (event->keyval == GDK_KEY_Down || event->keyval == GDK_KEY_KP_Down)
9602 if (completion->priv->current_selected < matches + actions - 1)
9603 completion->priv->current_selected++;
9605 completion->priv->current_selected = -1;
9607 else if (event->keyval == GDK_KEY_Page_Up)
9609 if (completion->priv->current_selected < 0)
9610 completion->priv->current_selected = matches + actions - 1;
9611 else if (completion->priv->current_selected == 0)
9612 completion->priv->current_selected = -1;
9613 else if (completion->priv->current_selected < matches)
9615 completion->priv->current_selected -= PAGE_STEP;
9616 if (completion->priv->current_selected < 0)
9617 completion->priv->current_selected = 0;
9621 completion->priv->current_selected -= PAGE_STEP;
9622 if (completion->priv->current_selected < matches - 1)
9623 completion->priv->current_selected = matches - 1;
9626 else if (event->keyval == GDK_KEY_Page_Down)
9628 if (completion->priv->current_selected < 0)
9629 completion->priv->current_selected = 0;
9630 else if (completion->priv->current_selected < matches - 1)
9632 completion->priv->current_selected += PAGE_STEP;
9633 if (completion->priv->current_selected > matches - 1)
9634 completion->priv->current_selected = matches - 1;
9636 else if (completion->priv->current_selected == matches + actions - 1)
9638 completion->priv->current_selected = -1;
9642 completion->priv->current_selected += PAGE_STEP;
9643 if (completion->priv->current_selected > matches + actions - 1)
9644 completion->priv->current_selected = matches + actions - 1;
9648 if (completion->priv->current_selected < 0)
9650 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9651 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view)));
9653 if (completion->priv->inline_selection &&
9654 completion->priv->completion_prefix)
9656 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9657 completion->priv->completion_prefix);
9658 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9661 else if (completion->priv->current_selected < matches)
9663 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view)));
9665 path = gtk_tree_path_new_from_indices (completion->priv->current_selected, -1);
9666 gtk_tree_view_set_cursor (GTK_TREE_VIEW (completion->priv->tree_view),
9669 if (completion->priv->inline_selection)
9673 GtkTreeIter child_iter;
9674 GtkTreeModel *model = NULL;
9675 GtkTreeSelection *sel;
9678 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view));
9679 if (!gtk_tree_selection_get_selected (sel, &model, &iter))
9682 gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (model), &child_iter, &iter);
9683 model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model));
9685 if (completion->priv->completion_prefix == NULL)
9686 completion->priv->completion_prefix = g_strdup (gtk_entry_get_text (GTK_ENTRY (completion->priv->entry)));
9688 g_signal_emit_by_name (completion, "cursor-on-match", model,
9689 &child_iter, &entry_set);
9692 else if (completion->priv->current_selected - matches >= 0)
9694 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9696 path = gtk_tree_path_new_from_indices (completion->priv->current_selected - matches, -1);
9697 gtk_tree_view_set_cursor (GTK_TREE_VIEW (completion->priv->action_view),
9700 if (completion->priv->inline_selection &&
9701 completion->priv->completion_prefix)
9703 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9704 completion->priv->completion_prefix);
9705 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9709 gtk_tree_path_free (path);
9713 else if (event->keyval == GDK_KEY_Escape ||
9714 event->keyval == GDK_KEY_Left ||
9715 event->keyval == GDK_KEY_KP_Left ||
9716 event->keyval == GDK_KEY_Right ||
9717 event->keyval == GDK_KEY_KP_Right)
9719 gboolean retval = TRUE;
9721 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9722 _gtk_entry_completion_popdown (completion);
9724 if (completion->priv->current_selected < 0)
9727 goto keypress_completion_out;
9729 else if (completion->priv->inline_selection)
9731 /* Escape rejects the tentative completion */
9732 if (event->keyval == GDK_KEY_Escape)
9734 if (completion->priv->completion_prefix)
9735 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9736 completion->priv->completion_prefix);
9738 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry), "");
9741 /* Move the cursor to the end for Right/Esc, to the
9742 beginning for Left */
9743 if (event->keyval == GDK_KEY_Right ||
9744 event->keyval == GDK_KEY_KP_Right ||
9745 event->keyval == GDK_KEY_Escape)
9746 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9748 gtk_editable_set_position (GTK_EDITABLE (widget), 0);
9751 keypress_completion_out:
9752 if (completion->priv->inline_selection)
9754 g_free (completion->priv->completion_prefix);
9755 completion->priv->completion_prefix = NULL;
9760 else if (event->keyval == GDK_KEY_Tab ||
9761 event->keyval == GDK_KEY_KP_Tab ||
9762 event->keyval == GDK_KEY_ISO_Left_Tab)
9764 GtkDirectionType dir = event->keyval == GDK_KEY_ISO_Left_Tab ?
9765 GTK_DIR_TAB_BACKWARD : GTK_DIR_TAB_FORWARD;
9767 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9768 _gtk_entry_completion_popdown (completion);
9770 g_free (completion->priv->completion_prefix);
9771 completion->priv->completion_prefix = NULL;
9773 gtk_widget_child_focus (gtk_widget_get_toplevel (widget), dir);
9777 else if (event->keyval == GDK_KEY_ISO_Enter ||
9778 event->keyval == GDK_KEY_KP_Enter ||
9779 event->keyval == GDK_KEY_Return)
9782 GtkTreeModel *model = NULL;
9783 GtkTreeModel *child_model;
9784 GtkTreeIter child_iter;
9785 GtkTreeSelection *sel;
9786 gboolean retval = TRUE;
9788 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9789 _gtk_entry_completion_popdown (completion);
9791 if (completion->priv->current_selected < matches)
9795 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view));
9796 if (gtk_tree_selection_get_selected (sel, &model, &iter))
9798 gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (model), &child_iter, &iter);
9799 child_model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model));
9800 g_signal_handler_block (widget, completion->priv->changed_id);
9801 g_signal_emit_by_name (completion, "match-selected",
9802 child_model, &child_iter, &entry_set);
9803 g_signal_handler_unblock (widget, completion->priv->changed_id);
9809 gtk_tree_model_get (model, &iter,
9810 completion->priv->text_column, &str,
9813 gtk_entry_set_text (GTK_ENTRY (widget), str);
9815 /* move the cursor to the end */
9816 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9824 else if (completion->priv->current_selected - matches >= 0)
9826 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view));
9827 if (gtk_tree_selection_get_selected (sel, &model, &iter))
9831 path = gtk_tree_path_new_from_indices (completion->priv->current_selected - matches, -1);
9832 g_signal_emit_by_name (completion, "action-activated",
9833 gtk_tree_path_get_indices (path)[0]);
9834 gtk_tree_path_free (path);
9840 g_free (completion->priv->completion_prefix);
9841 completion->priv->completion_prefix = NULL;
9850 gtk_entry_completion_changed (GtkWidget *widget,
9853 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
9854 GtkEntry *entry = GTK_ENTRY (widget);
9855 GtkEntryPrivate *priv = entry->priv;
9858 /* (re)install completion timeout */
9859 if (completion->priv->completion_timeout)
9860 g_source_remove (completion->priv->completion_timeout);
9862 if (!gtk_entry_get_text (entry))
9865 /* no need to normalize for this test */
9866 if (completion->priv->minimum_key_length > 0 &&
9867 strcmp ("", gtk_entry_get_text (entry)) == 0)
9869 if (gtk_widget_get_visible (completion->priv->popup_window))
9870 _gtk_entry_completion_popdown (completion);
9874 device = gtk_get_current_event_device ();
9876 if (device && gdk_device_get_source (device) == GDK_SOURCE_KEYBOARD)
9877 device = gdk_device_get_associated_device (device);
9880 priv->completion_device = device;
9882 completion->priv->completion_timeout =
9883 gdk_threads_add_timeout (COMPLETION_TIMEOUT,
9884 gtk_entry_completion_timeout,
9889 check_completion_callback (GtkEntryCompletion *completion)
9891 completion->priv->check_completion_idle = NULL;
9893 gtk_entry_completion_complete (completion);
9894 gtk_entry_completion_insert_prefix (completion);
9900 clear_completion_callback (GtkEntry *entry,
9903 if (pspec->name == I_("cursor-position") ||
9904 pspec->name == I_("selection-bound"))
9906 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
9908 completion->priv->has_completion = FALSE;
9913 accept_completion_callback (GtkEntry *entry)
9915 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
9917 if (completion->priv->has_completion)
9918 gtk_editable_set_position (GTK_EDITABLE (entry),
9919 gtk_entry_buffer_get_length (get_buffer (entry)));
9925 completion_insert_text_callback (GtkEntry *entry,
9929 GtkEntryCompletion *completion)
9931 /* idle to update the selection based on the file list */
9932 if (completion->priv->check_completion_idle == NULL)
9934 completion->priv->check_completion_idle = g_idle_source_new ();
9935 g_source_set_priority (completion->priv->check_completion_idle, G_PRIORITY_HIGH);
9936 g_source_set_closure (completion->priv->check_completion_idle,
9937 g_cclosure_new_object (G_CALLBACK (check_completion_callback),
9938 G_OBJECT (completion)));
9939 g_source_attach (completion->priv->check_completion_idle, NULL);
9944 completion_changed (GtkEntryCompletion *completion,
9948 GtkEntry *entry = GTK_ENTRY (data);
9950 if (pspec->name == I_("popup-completion") ||
9951 pspec->name == I_("inline-completion"))
9953 disconnect_completion_signals (entry, completion);
9954 connect_completion_signals (entry, completion);
9959 disconnect_completion_signals (GtkEntry *entry,
9960 GtkEntryCompletion *completion)
9962 g_signal_handlers_disconnect_by_func (completion,
9963 G_CALLBACK (completion_changed), entry);
9964 if (completion->priv->changed_id > 0 &&
9965 g_signal_handler_is_connected (entry, completion->priv->changed_id))
9967 g_signal_handler_disconnect (entry, completion->priv->changed_id);
9968 completion->priv->changed_id = 0;
9970 g_signal_handlers_disconnect_by_func (entry,
9971 G_CALLBACK (gtk_entry_completion_key_press), completion);
9972 if (completion->priv->insert_text_id > 0 &&
9973 g_signal_handler_is_connected (entry, completion->priv->insert_text_id))
9975 g_signal_handler_disconnect (entry, completion->priv->insert_text_id);
9976 completion->priv->insert_text_id = 0;
9978 g_signal_handlers_disconnect_by_func (entry,
9979 G_CALLBACK (completion_insert_text_callback), completion);
9980 g_signal_handlers_disconnect_by_func (entry,
9981 G_CALLBACK (clear_completion_callback), completion);
9982 g_signal_handlers_disconnect_by_func (entry,
9983 G_CALLBACK (accept_completion_callback), completion);
9987 connect_completion_signals (GtkEntry *entry,
9988 GtkEntryCompletion *completion)
9990 if (completion->priv->popup_completion)
9992 completion->priv->changed_id =
9993 g_signal_connect (entry, "changed",
9994 G_CALLBACK (gtk_entry_completion_changed), completion);
9995 g_signal_connect (entry, "key-press-event",
9996 G_CALLBACK (gtk_entry_completion_key_press), completion);
9999 if (completion->priv->inline_completion)
10001 completion->priv->insert_text_id =
10002 g_signal_connect (entry, "insert-text",
10003 G_CALLBACK (completion_insert_text_callback), completion);
10004 g_signal_connect (entry, "notify",
10005 G_CALLBACK (clear_completion_callback), completion);
10006 g_signal_connect (entry, "activate",
10007 G_CALLBACK (accept_completion_callback), completion);
10008 g_signal_connect (entry, "focus-out-event",
10009 G_CALLBACK (accept_completion_callback), completion);
10012 g_signal_connect (completion, "notify",
10013 G_CALLBACK (completion_changed), entry);
10017 * gtk_entry_set_completion:
10018 * @entry: A #GtkEntry
10019 * @completion: (allow-none): The #GtkEntryCompletion or %NULL
10021 * Sets @completion to be the auxiliary completion object to use with @entry.
10022 * All further configuration of the completion mechanism is done on
10023 * @completion using the #GtkEntryCompletion API. Completion is disabled if
10024 * @completion is set to %NULL.
10029 gtk_entry_set_completion (GtkEntry *entry,
10030 GtkEntryCompletion *completion)
10032 GtkEntryCompletion *old;
10034 g_return_if_fail (GTK_IS_ENTRY (entry));
10035 g_return_if_fail (!completion || GTK_IS_ENTRY_COMPLETION (completion));
10037 old = gtk_entry_get_completion (entry);
10039 if (old == completion)
10044 if (old->priv->completion_timeout)
10046 g_source_remove (old->priv->completion_timeout);
10047 old->priv->completion_timeout = 0;
10050 if (old->priv->check_completion_idle)
10052 g_source_destroy (old->priv->check_completion_idle);
10053 old->priv->check_completion_idle = NULL;
10056 if (gtk_widget_get_mapped (old->priv->popup_window))
10057 _gtk_entry_completion_popdown (old);
10059 disconnect_completion_signals (entry, old);
10060 old->priv->entry = NULL;
10062 g_object_unref (old);
10067 g_object_set_data (G_OBJECT (entry), I_(GTK_ENTRY_COMPLETION_KEY), NULL);
10071 /* hook into the entry */
10072 g_object_ref (completion);
10074 connect_completion_signals (entry, completion);
10075 completion->priv->entry = GTK_WIDGET (entry);
10076 g_object_set_data (G_OBJECT (entry), I_(GTK_ENTRY_COMPLETION_KEY), completion);
10078 g_object_notify (G_OBJECT (entry), "completion");
10082 * gtk_entry_get_completion:
10083 * @entry: A #GtkEntry
10085 * Returns the auxiliary completion object currently in use by @entry.
10087 * Return value: (transfer none): The auxiliary completion object currently
10088 * in use by @entry.
10092 GtkEntryCompletion *
10093 gtk_entry_get_completion (GtkEntry *entry)
10095 GtkEntryCompletion *completion;
10097 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
10099 completion = GTK_ENTRY_COMPLETION (g_object_get_data (G_OBJECT (entry),
10100 GTK_ENTRY_COMPLETION_KEY));
10106 * gtk_entry_set_cursor_hadjustment:
10107 * @entry: a #GtkEntry
10108 * @adjustment: an adjustment which should be adjusted when the cursor
10109 * is moved, or %NULL
10111 * Hooks up an adjustment to the cursor position in an entry, so that when
10112 * the cursor is moved, the adjustment is scrolled to show that position.
10113 * See gtk_scrolled_window_get_hadjustment() for a typical way of obtaining
10116 * The adjustment has to be in pixel units and in the same coordinate system
10122 gtk_entry_set_cursor_hadjustment (GtkEntry *entry,
10123 GtkAdjustment *adjustment)
10125 g_return_if_fail (GTK_IS_ENTRY (entry));
10127 g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
10130 g_object_ref (adjustment);
10132 g_object_set_qdata_full (G_OBJECT (entry),
10133 quark_cursor_hadjustment,
10139 * gtk_entry_get_cursor_hadjustment:
10140 * @entry: a #GtkEntry
10142 * Retrieves the horizontal cursor adjustment for the entry.
10143 * See gtk_entry_set_cursor_hadjustment().
10145 * Return value: (transfer none): the horizontal cursor adjustment, or %NULL
10146 * if none has been set.
10151 gtk_entry_get_cursor_hadjustment (GtkEntry *entry)
10153 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
10155 return g_object_get_qdata (G_OBJECT (entry), quark_cursor_hadjustment);
10159 * gtk_entry_set_progress_fraction:
10160 * @entry: a #GtkEntry
10161 * @fraction: fraction of the task that's been completed
10163 * Causes the entry's progress indicator to "fill in" the given
10164 * fraction of the bar. The fraction should be between 0.0 and 1.0,
10170 gtk_entry_set_progress_fraction (GtkEntry *entry,
10174 GtkEntryPrivate *private;
10175 gdouble old_fraction;
10176 gint x, y, width, height;
10177 gint old_x, old_y, old_width, old_height;
10179 g_return_if_fail (GTK_IS_ENTRY (entry));
10181 widget = GTK_WIDGET (entry);
10182 private = entry->priv;
10184 if (private->progress_pulse_mode)
10187 old_fraction = private->progress_fraction;
10189 if (gtk_widget_is_drawable (widget))
10190 get_progress_area (widget, &old_x, &old_y, &old_width, &old_height);
10192 fraction = CLAMP (fraction, 0.0, 1.0);
10194 private->progress_fraction = fraction;
10195 private->progress_pulse_mode = FALSE;
10196 private->progress_pulse_current = 0.0;
10198 if (gtk_widget_is_drawable (widget))
10200 get_progress_area (widget, &x, &y, &width, &height);
10202 if ((x != old_x) || (y != old_y) || (width != old_width) || (height != old_height))
10203 gtk_widget_queue_draw (widget);
10206 if (fraction != old_fraction)
10207 g_object_notify (G_OBJECT (entry), "progress-fraction");
10211 * gtk_entry_get_progress_fraction:
10212 * @entry: a #GtkEntry
10214 * Returns the current fraction of the task that's been completed.
10215 * See gtk_entry_set_progress_fraction().
10217 * Return value: a fraction from 0.0 to 1.0
10222 gtk_entry_get_progress_fraction (GtkEntry *entry)
10224 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
10226 return entry->priv->progress_fraction;
10230 * gtk_entry_set_progress_pulse_step:
10231 * @entry: a #GtkEntry
10232 * @fraction: fraction between 0.0 and 1.0
10234 * Sets the fraction of total entry width to move the progress
10235 * bouncing block for each call to gtk_entry_progress_pulse().
10240 gtk_entry_set_progress_pulse_step (GtkEntry *entry,
10243 GtkEntryPrivate *private;
10245 g_return_if_fail (GTK_IS_ENTRY (entry));
10247 private = entry->priv;
10249 fraction = CLAMP (fraction, 0.0, 1.0);
10251 if (fraction != private->progress_pulse_fraction)
10253 private->progress_pulse_fraction = fraction;
10255 gtk_widget_queue_draw (GTK_WIDGET (entry));
10257 g_object_notify (G_OBJECT (entry), "progress-pulse-step");
10262 * gtk_entry_get_progress_pulse_step:
10263 * @entry: a #GtkEntry
10265 * Retrieves the pulse step set with gtk_entry_set_progress_pulse_step().
10267 * Return value: a fraction from 0.0 to 1.0
10272 gtk_entry_get_progress_pulse_step (GtkEntry *entry)
10274 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
10276 return entry->priv->progress_pulse_fraction;
10280 * gtk_entry_progress_pulse:
10281 * @entry: a #GtkEntry
10283 * Indicates that some progress is made, but you don't know how much.
10284 * Causes the entry's progress indicator to enter "activity mode,"
10285 * where a block bounces back and forth. Each call to
10286 * gtk_entry_progress_pulse() causes the block to move by a little bit
10287 * (the amount of movement per pulse is determined by
10288 * gtk_entry_set_progress_pulse_step()).
10293 gtk_entry_progress_pulse (GtkEntry *entry)
10295 GtkEntryPrivate *private;
10297 g_return_if_fail (GTK_IS_ENTRY (entry));
10299 private = entry->priv;
10301 if (private->progress_pulse_mode)
10303 if (private->progress_pulse_way_back)
10305 private->progress_pulse_current -= private->progress_pulse_fraction;
10307 if (private->progress_pulse_current < 0.0)
10309 private->progress_pulse_current = 0.0;
10310 private->progress_pulse_way_back = FALSE;
10315 private->progress_pulse_current += private->progress_pulse_fraction;
10317 if (private->progress_pulse_current > 1.0 - private->progress_pulse_fraction)
10319 private->progress_pulse_current = 1.0 - private->progress_pulse_fraction;
10320 private->progress_pulse_way_back = TRUE;
10326 private->progress_fraction = 0.0;
10327 private->progress_pulse_mode = TRUE;
10328 private->progress_pulse_way_back = FALSE;
10329 private->progress_pulse_current = 0.0;
10332 gtk_widget_queue_draw (GTK_WIDGET (entry));
10336 * gtk_entry_set_placeholder_text:
10337 * @entry: a #GtkEntry
10338 * @text: a string to be displayed when @entry is empty an unfocused, or %NULL
10340 * Sets text to be displayed in @entry when
10341 * it is empty and unfocused. This can be used to give a visual hint
10342 * of the expected contents of the #GtkEntry.
10347 gtk_entry_set_placeholder_text (GtkEntry *entry,
10350 GtkEntryPrivate *priv;
10352 g_return_if_fail (GTK_IS_ENTRY (entry));
10354 priv = entry->priv;
10356 if (g_strcmp0 (priv->placeholder_text, text) == 0)
10359 g_free (priv->placeholder_text);
10360 priv->placeholder_text = g_strdup (text);
10362 gtk_entry_recompute (entry);
10364 g_object_notify (G_OBJECT (entry), "placeholder-text");
10368 * gtk_entry_get_placeholder_text:
10369 * @entry: a #GtkEntry
10371 * Retrieves the text that will be displayed when @entry is empty and unfocused
10373 * Returns: a pointer to the placeholder text as a string. This string points to internally allocated
10374 * storage in the widget and must not be freed, modified or stored.
10379 gtk_entry_get_placeholder_text (GtkEntry *entry)
10381 GtkEntryPrivate *priv;
10383 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
10385 priv = entry->priv;
10387 return priv->placeholder_text;
10390 /* Caps Lock warning for password entries */
10393 show_capslock_feedback (GtkEntry *entry,
10396 GtkEntryPrivate *priv = entry->priv;
10398 if (gtk_entry_get_icon_storage_type (entry, GTK_ENTRY_ICON_SECONDARY) == GTK_IMAGE_EMPTY)
10400 gtk_entry_set_icon_from_stock (entry, GTK_ENTRY_ICON_SECONDARY, GTK_STOCK_CAPS_LOCK_WARNING);
10401 gtk_entry_set_icon_activatable (entry, GTK_ENTRY_ICON_SECONDARY, FALSE);
10402 priv->caps_lock_warning_shown = TRUE;
10405 if (priv->caps_lock_warning_shown)
10406 gtk_entry_set_icon_tooltip_text (entry, GTK_ENTRY_ICON_SECONDARY, text);
10408 g_warning ("Can't show Caps Lock warning, since secondary icon is set");
10412 remove_capslock_feedback (GtkEntry *entry)
10414 GtkEntryPrivate *priv = entry->priv;
10416 if (priv->caps_lock_warning_shown)
10418 gtk_entry_set_icon_from_stock (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
10419 priv->caps_lock_warning_shown = FALSE;
10424 keymap_state_changed (GdkKeymap *keymap,
10427 GtkEntryPrivate *priv = entry->priv;
10430 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL && priv->caps_lock_warning)
10432 if (gdk_keymap_get_num_lock_state (keymap)
10433 && gdk_keymap_get_caps_lock_state (keymap))
10434 text = _("Caps Lock and Num Lock are on");
10435 else if (gdk_keymap_get_num_lock_state (keymap))
10436 text = _("Num Lock is on");
10437 else if (gdk_keymap_get_caps_lock_state (keymap))
10438 text = _("Caps Lock is on");
10442 show_capslock_feedback (entry, text);
10444 remove_capslock_feedback (entry);
10448 * _gtk_entry_set_is_cell_renderer:
10449 * @entry: a #GtkEntry
10450 * @is_cell_renderer: new value
10452 * This is a helper function for GtkComboBox. A GtkEntry in a GtkComboBox
10453 * is supposed to behave like a GtkCellEditable when placed in a combo box.
10455 * I.e take up its allocation and get GtkEntry->is_cell_renderer = TRUE.
10459 _gtk_entry_set_is_cell_renderer (GtkEntry *entry,
10460 gboolean is_cell_renderer)
10462 entry->priv->is_cell_renderer = is_cell_renderer;