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 "gtkalignment.h"
37 #include "gtkbindings.h"
38 #include "gtkcelleditable.h"
39 #include "gtkclipboard.h"
42 #include "gtkentrybuffer.h"
43 #include "gtkimagemenuitem.h"
44 #include "gtkimcontextsimple.h"
45 #include "gtkimmulticontext.h"
49 #include "gtkmarshalers.h"
51 #include "gtkmenuitem.h"
52 #include "gtkseparatormenuitem.h"
53 #include "gtkselection.h"
54 #include "gtksettings.h"
55 #include "gtkspinbutton.h"
57 #include "gtktextutil.h"
58 #include "gtkwindow.h"
59 #include "gtktreeview.h"
60 #include "gtktreeselection.h"
61 #include "gtktypebuiltins.h"
62 #include "gtkprivate.h"
63 #include "gtkentryprivate.h"
64 #include "gtkcelllayout.h"
65 #include "gtktooltip.h"
66 #include "gtkiconfactory.h"
67 #include "gtkicontheme.h"
68 #include "gtkwidgetprivate.h"
69 #include "gtkstylecontextprivate.h"
73 * @Short_description: A single line text entry field
75 * @See_also: #GtkTextView, #GtkEntryCompletion
77 * The #GtkEntry widget is a single line text entry
78 * widget. A fairly large set of key bindings are supported
79 * by default. If the entered text is longer than the allocation
80 * of the widget, the widget will scroll so that the cursor
81 * position is visible.
83 * When using an entry for passwords and other sensitive information,
84 * it can be put into "password mode" using gtk_entry_set_visibility().
85 * In this mode, entered text is displayed using a 'invisible' character.
86 * By default, GTK+ picks the best invisible character that is available
87 * in the current font, but it can be changed with
88 * gtk_entry_set_invisible_char(). Since 2.16, GTK+ displays a warning
89 * when Caps Lock or input methods might interfere with entering text in
90 * a password entry. The warning can be turned off with the
91 * #GtkEntry:caps-lock-warning property.
93 * Since 2.16, GtkEntry has the ability to display progress or activity
94 * information behind the text. To make an entry display such information,
95 * use gtk_entry_set_progress_fraction() or gtk_entry_set_progress_pulse_step().
97 * Additionally, GtkEntry can show icons at either side of the entry. These
98 * icons can be activatable by clicking, can be set up as drag source and
99 * can have tooltips. To add an icon, use gtk_entry_set_icon_from_gicon() or
100 * one of the various other functions that set an icon from a stock id, an
101 * icon name or a pixbuf. To trigger an action when the user clicks an icon,
102 * connect to the #GtkEntry::icon-press signal. To allow DND operations
103 * from an icon, use gtk_entry_set_icon_drag_source(). To set a tooltip on
104 * an icon, use gtk_entry_set_icon_tooltip_text() or the corresponding function
107 * Note that functionality or information that is only available by clicking
108 * on an icon in an entry may not be accessible at all to users which are not
109 * able to use a mouse or other pointing device. It is therefore recommended
110 * that any such functionality should also be available by other means, e.g.
111 * via the context menu of the entry.
115 #define GTK_ENTRY_COMPLETION_KEY "gtk-entry-completion-key"
117 #define MIN_ENTRY_WIDTH 150
118 #define DRAW_TIMEOUT 20
119 #define COMPLETION_TIMEOUT 300
120 #define PASSWORD_HINT_MAX 8
124 #define IS_VALID_ICON_POSITION(pos) \
125 ((pos) == GTK_ENTRY_ICON_PRIMARY || \
126 (pos) == GTK_ENTRY_ICON_SECONDARY)
128 static const GtkBorder default_inner_border = { 2, 2, 2, 2 };
129 static GQuark quark_inner_border = 0;
130 static GQuark quark_password_hint = 0;
131 static GQuark quark_cursor_hadjustment = 0;
132 static GQuark quark_capslock_feedback = 0;
134 typedef struct _EntryIconInfo EntryIconInfo;
135 typedef struct _GtkEntryPasswordHint GtkEntryPasswordHint;
136 typedef struct _GtkEntryCapslockFeedback GtkEntryCapslockFeedback;
138 struct _GtkEntryPrivate
140 EntryIconInfo *icons[MAX_ICONS];
142 GtkEntryBuffer *buffer;
143 GtkIMContext *im_context;
144 GtkShadowType shadow_type;
145 GtkWidget *popup_menu;
147 GdkDevice *completion_device;
148 GdkWindow *text_area;
150 PangoLayout *cached_layout;
154 gdouble progress_fraction;
155 gdouble progress_pulse_fraction;
156 gdouble progress_pulse_current;
158 gchar *placeholder_text;
162 gint ascent; /* font ascent in pango units */
164 gint descent; /* font descent in pango units */
165 gint dnd_position; /* In chars, -1 == no DND cursor */
171 gint selection_bound;
177 gunichar invisible_char;
180 guint blink_time; /* time in msec the cursor has blinked since last user event */
182 guint recompute_idle;
184 guint16 x_text_size; /* allocated size, in bytes */
185 guint16 x_n_bytes; /* length in use, in bytes */
187 guint16 preedit_length; /* length of preedit string, in bytes */
188 guint16 preedit_cursor; /* offset of cursor within preedit string, in chars */
192 guint overwrite_mode : 1;
195 guint activates_default : 1;
196 guint cache_includes_preedit : 1;
197 guint caps_lock_warning : 1;
198 guint caps_lock_warning_shown : 1;
199 guint change_count : 8;
200 guint cursor_visible : 1;
201 guint editing_canceled : 1; /* Only used by GtkCellRendererText */
203 guint in_click : 1; /* Flag so we don't select all when clicking in entry to focus in */
204 guint is_cell_renderer : 1;
205 guint invisible_char_set : 1;
206 guint interior_focus : 1;
207 guint mouse_cursor_obscured : 1;
208 guint need_im_reset : 1;
209 guint progress_pulse_mode : 1;
210 guint progress_pulse_way_back : 1;
211 guint real_changed : 1;
212 guint resolved_dir : 4; /* PangoDirection */
213 guint select_words : 1;
214 guint select_lines : 1;
215 guint truncate_multiline : 1;
218 struct _EntryIconInfo
222 guint insensitive : 1;
223 guint nonactivatable : 1;
228 GtkImageType storage_type;
234 GtkTargetList *target_list;
235 GdkDragAction actions;
238 struct _GtkEntryPasswordHint
240 gint position; /* Position (in text) of the last password hint */
241 guint source_id; /* Timeout source id */
244 struct _GtkEntryCapslockFeedback
271 PROP_CURSOR_POSITION,
272 PROP_SELECTION_BOUND,
279 PROP_ACTIVATES_DEFAULT,
284 PROP_TRUNCATE_MULTILINE,
288 PROP_INVISIBLE_CHAR_SET,
289 PROP_CAPS_LOCK_WARNING,
290 PROP_PROGRESS_FRACTION,
291 PROP_PROGRESS_PULSE_STEP,
293 PROP_PIXBUF_SECONDARY,
295 PROP_STOCK_SECONDARY,
296 PROP_ICON_NAME_PRIMARY,
297 PROP_ICON_NAME_SECONDARY,
299 PROP_GICON_SECONDARY,
300 PROP_STORAGE_TYPE_PRIMARY,
301 PROP_STORAGE_TYPE_SECONDARY,
302 PROP_ACTIVATABLE_PRIMARY,
303 PROP_ACTIVATABLE_SECONDARY,
304 PROP_SENSITIVE_PRIMARY,
305 PROP_SENSITIVE_SECONDARY,
306 PROP_TOOLTIP_TEXT_PRIMARY,
307 PROP_TOOLTIP_TEXT_SECONDARY,
308 PROP_TOOLTIP_MARKUP_PRIMARY,
309 PROP_TOOLTIP_MARKUP_SECONDARY,
311 PROP_EDITING_CANCELED,
312 PROP_PLACEHOLDER_TEXT,
316 static guint signals[LAST_SIGNAL] = { 0 };
325 DISPLAY_NORMAL, /* The entry text is being shown */
326 DISPLAY_INVISIBLE, /* In invisible mode, text replaced by (eg) bullets */
327 DISPLAY_BLANK /* In invisible mode, nothing shown at all */
332 static void gtk_entry_editable_init (GtkEditableInterface *iface);
333 static void gtk_entry_cell_editable_init (GtkCellEditableIface *iface);
334 static void gtk_entry_set_property (GObject *object,
338 static void gtk_entry_get_property (GObject *object,
342 static void gtk_entry_finalize (GObject *object);
343 static void gtk_entry_dispose (GObject *object);
347 static void gtk_entry_destroy (GtkWidget *widget);
348 static void gtk_entry_realize (GtkWidget *widget);
349 static void gtk_entry_unrealize (GtkWidget *widget);
350 static void gtk_entry_map (GtkWidget *widget);
351 static void gtk_entry_unmap (GtkWidget *widget);
352 static void gtk_entry_get_preferred_width (GtkWidget *widget,
355 static void gtk_entry_get_preferred_height (GtkWidget *widget,
358 static void gtk_entry_size_allocate (GtkWidget *widget,
359 GtkAllocation *allocation);
360 static void gtk_entry_draw_frame (GtkWidget *widget,
361 GtkStyleContext *context,
363 static void gtk_entry_draw_progress (GtkWidget *widget,
364 GtkStyleContext *context,
366 static gint gtk_entry_draw (GtkWidget *widget,
368 static gint gtk_entry_button_press (GtkWidget *widget,
369 GdkEventButton *event);
370 static gint gtk_entry_button_release (GtkWidget *widget,
371 GdkEventButton *event);
372 static gint gtk_entry_enter_notify (GtkWidget *widget,
373 GdkEventCrossing *event);
374 static gint gtk_entry_leave_notify (GtkWidget *widget,
375 GdkEventCrossing *event);
376 static gint gtk_entry_motion_notify (GtkWidget *widget,
377 GdkEventMotion *event);
378 static gint gtk_entry_key_press (GtkWidget *widget,
380 static gint gtk_entry_key_release (GtkWidget *widget,
382 static gint gtk_entry_focus_in (GtkWidget *widget,
383 GdkEventFocus *event);
384 static gint gtk_entry_focus_out (GtkWidget *widget,
385 GdkEventFocus *event);
386 static void gtk_entry_grab_focus (GtkWidget *widget);
387 static void gtk_entry_style_updated (GtkWidget *widget);
388 static gboolean gtk_entry_query_tooltip (GtkWidget *widget,
391 gboolean keyboard_tip,
392 GtkTooltip *tooltip);
393 static void gtk_entry_direction_changed (GtkWidget *widget,
394 GtkTextDirection previous_dir);
395 static void gtk_entry_state_flags_changed (GtkWidget *widget,
396 GtkStateFlags previous_state);
397 static void gtk_entry_screen_changed (GtkWidget *widget,
398 GdkScreen *old_screen);
400 static gboolean gtk_entry_drag_drop (GtkWidget *widget,
401 GdkDragContext *context,
405 static gboolean gtk_entry_drag_motion (GtkWidget *widget,
406 GdkDragContext *context,
410 static void gtk_entry_drag_leave (GtkWidget *widget,
411 GdkDragContext *context,
413 static void gtk_entry_drag_data_received (GtkWidget *widget,
414 GdkDragContext *context,
417 GtkSelectionData *selection_data,
420 static void gtk_entry_drag_data_get (GtkWidget *widget,
421 GdkDragContext *context,
422 GtkSelectionData *selection_data,
425 static void gtk_entry_drag_data_delete (GtkWidget *widget,
426 GdkDragContext *context);
427 static void gtk_entry_drag_begin (GtkWidget *widget,
428 GdkDragContext *context);
429 static void gtk_entry_drag_end (GtkWidget *widget,
430 GdkDragContext *context);
433 /* GtkEditable method implementations
435 static void gtk_entry_insert_text (GtkEditable *editable,
436 const gchar *new_text,
437 gint new_text_length,
439 static void gtk_entry_delete_text (GtkEditable *editable,
442 static gchar * gtk_entry_get_chars (GtkEditable *editable,
445 static void gtk_entry_real_set_position (GtkEditable *editable,
447 static gint gtk_entry_get_position (GtkEditable *editable);
448 static void gtk_entry_set_selection_bounds (GtkEditable *editable,
451 static gboolean gtk_entry_get_selection_bounds (GtkEditable *editable,
455 /* GtkCellEditable method implementations
457 static void gtk_entry_start_editing (GtkCellEditable *cell_editable,
460 /* Default signal handlers
462 static void gtk_entry_real_insert_text (GtkEditable *editable,
463 const gchar *new_text,
464 gint new_text_length,
466 static void gtk_entry_real_delete_text (GtkEditable *editable,
469 static void gtk_entry_move_cursor (GtkEntry *entry,
470 GtkMovementStep step,
472 gboolean extend_selection);
473 static void gtk_entry_insert_at_cursor (GtkEntry *entry,
475 static void gtk_entry_delete_from_cursor (GtkEntry *entry,
478 static void gtk_entry_backspace (GtkEntry *entry);
479 static void gtk_entry_cut_clipboard (GtkEntry *entry);
480 static void gtk_entry_copy_clipboard (GtkEntry *entry);
481 static void gtk_entry_paste_clipboard (GtkEntry *entry);
482 static void gtk_entry_toggle_overwrite (GtkEntry *entry);
483 static void gtk_entry_select_all (GtkEntry *entry);
484 static void gtk_entry_real_activate (GtkEntry *entry);
485 static gboolean gtk_entry_popup_menu (GtkWidget *widget);
487 static void keymap_direction_changed (GdkKeymap *keymap,
489 static void keymap_state_changed (GdkKeymap *keymap,
491 static void remove_capslock_feedback (GtkEntry *entry);
493 /* IM Context Callbacks
495 static void gtk_entry_commit_cb (GtkIMContext *context,
498 static void gtk_entry_preedit_changed_cb (GtkIMContext *context,
500 static gboolean gtk_entry_retrieve_surrounding_cb (GtkIMContext *context,
502 static gboolean gtk_entry_delete_surrounding_cb (GtkIMContext *context,
509 static void gtk_entry_enter_text (GtkEntry *entry,
511 static void gtk_entry_set_positions (GtkEntry *entry,
513 gint selection_bound);
514 static void gtk_entry_draw_text (GtkEntry *entry,
516 static void gtk_entry_draw_cursor (GtkEntry *entry,
519 static PangoLayout *gtk_entry_ensure_layout (GtkEntry *entry,
520 gboolean include_preedit);
521 static void gtk_entry_reset_layout (GtkEntry *entry);
522 static void gtk_entry_recompute (GtkEntry *entry);
523 static gint gtk_entry_find_position (GtkEntry *entry,
525 static void gtk_entry_get_cursor_locations (GtkEntry *entry,
529 static void gtk_entry_adjust_scroll (GtkEntry *entry);
530 static gint gtk_entry_move_visually (GtkEntry *editable,
533 static gint gtk_entry_move_logically (GtkEntry *entry,
536 static gint gtk_entry_move_forward_word (GtkEntry *entry,
538 gboolean allow_whitespace);
539 static gint gtk_entry_move_backward_word (GtkEntry *entry,
541 gboolean allow_whitespace);
542 static void gtk_entry_delete_whitespace (GtkEntry *entry);
543 static void gtk_entry_select_word (GtkEntry *entry);
544 static void gtk_entry_select_line (GtkEntry *entry);
545 static void gtk_entry_paste (GtkEntry *entry,
547 static void gtk_entry_update_primary_selection (GtkEntry *entry);
548 static void gtk_entry_do_popup (GtkEntry *entry,
549 GdkEventButton *event);
550 static gboolean gtk_entry_mnemonic_activate (GtkWidget *widget,
551 gboolean group_cycling);
552 static void gtk_entry_check_cursor_blink (GtkEntry *entry);
553 static void gtk_entry_pend_cursor_blink (GtkEntry *entry);
554 static void gtk_entry_reset_blink_time (GtkEntry *entry);
555 static void gtk_entry_get_text_area_size (GtkEntry *entry,
560 static void get_text_area_size (GtkEntry *entry,
565 static void get_frame_size (GtkEntry *entry,
570 static void gtk_entry_move_adjustments (GtkEntry *entry);
571 static void gtk_entry_ensure_pixbuf (GtkEntry *entry,
572 GtkEntryIconPosition icon_pos);
576 static gint gtk_entry_completion_timeout (gpointer data);
577 static gboolean gtk_entry_completion_key_press (GtkWidget *widget,
580 static void gtk_entry_completion_changed (GtkWidget *entry,
582 static gboolean check_completion_callback (GtkEntryCompletion *completion);
583 static void clear_completion_callback (GtkEntry *entry,
585 static gboolean accept_completion_callback (GtkEntry *entry);
586 static void completion_insert_text_callback (GtkEntry *entry,
590 GtkEntryCompletion *completion);
591 static void completion_changed (GtkEntryCompletion *completion,
594 static void disconnect_completion_signals (GtkEntry *entry,
595 GtkEntryCompletion *completion);
596 static void connect_completion_signals (GtkEntry *entry,
597 GtkEntryCompletion *completion);
599 static void begin_change (GtkEntry *entry);
600 static void end_change (GtkEntry *entry);
601 static void emit_changed (GtkEntry *entry);
603 static void buffer_inserted_text (GtkEntryBuffer *buffer,
608 static void buffer_deleted_text (GtkEntryBuffer *buffer,
612 static void buffer_notify_text (GtkEntryBuffer *buffer,
615 static void buffer_notify_length (GtkEntryBuffer *buffer,
618 static void buffer_notify_max_length (GtkEntryBuffer *buffer,
621 static void buffer_connect_signals (GtkEntry *entry);
622 static void buffer_disconnect_signals (GtkEntry *entry);
623 static GtkEntryBuffer *get_buffer (GtkEntry *entry);
625 G_DEFINE_TYPE_WITH_CODE (GtkEntry, gtk_entry, GTK_TYPE_WIDGET,
626 G_IMPLEMENT_INTERFACE (GTK_TYPE_EDITABLE,
627 gtk_entry_editable_init)
628 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_EDITABLE,
629 gtk_entry_cell_editable_init))
632 add_move_binding (GtkBindingSet *binding_set,
635 GtkMovementStep step,
638 g_return_if_fail ((modmask & GDK_SHIFT_MASK) == 0);
640 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
644 G_TYPE_BOOLEAN, FALSE);
646 /* Selection-extending version */
647 gtk_binding_entry_add_signal (binding_set, keyval, modmask | GDK_SHIFT_MASK,
651 G_TYPE_BOOLEAN, TRUE);
655 gtk_entry_class_init (GtkEntryClass *class)
657 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
658 GtkWidgetClass *widget_class;
659 GtkBindingSet *binding_set;
661 widget_class = (GtkWidgetClass*) class;
663 gobject_class->dispose = gtk_entry_dispose;
664 gobject_class->finalize = gtk_entry_finalize;
665 gobject_class->set_property = gtk_entry_set_property;
666 gobject_class->get_property = gtk_entry_get_property;
668 widget_class->destroy = gtk_entry_destroy;
669 widget_class->map = gtk_entry_map;
670 widget_class->unmap = gtk_entry_unmap;
671 widget_class->realize = gtk_entry_realize;
672 widget_class->unrealize = gtk_entry_unrealize;
673 widget_class->get_preferred_width = gtk_entry_get_preferred_width;
674 widget_class->get_preferred_height = gtk_entry_get_preferred_height;
675 widget_class->size_allocate = gtk_entry_size_allocate;
676 widget_class->draw = gtk_entry_draw;
677 widget_class->enter_notify_event = gtk_entry_enter_notify;
678 widget_class->leave_notify_event = gtk_entry_leave_notify;
679 widget_class->button_press_event = gtk_entry_button_press;
680 widget_class->button_release_event = gtk_entry_button_release;
681 widget_class->motion_notify_event = gtk_entry_motion_notify;
682 widget_class->key_press_event = gtk_entry_key_press;
683 widget_class->key_release_event = gtk_entry_key_release;
684 widget_class->focus_in_event = gtk_entry_focus_in;
685 widget_class->focus_out_event = gtk_entry_focus_out;
686 widget_class->grab_focus = gtk_entry_grab_focus;
687 widget_class->style_updated = gtk_entry_style_updated;
688 widget_class->query_tooltip = gtk_entry_query_tooltip;
689 widget_class->drag_begin = gtk_entry_drag_begin;
690 widget_class->drag_end = gtk_entry_drag_end;
691 widget_class->direction_changed = gtk_entry_direction_changed;
692 widget_class->state_flags_changed = gtk_entry_state_flags_changed;
693 widget_class->screen_changed = gtk_entry_screen_changed;
694 widget_class->mnemonic_activate = gtk_entry_mnemonic_activate;
696 widget_class->drag_drop = gtk_entry_drag_drop;
697 widget_class->drag_motion = gtk_entry_drag_motion;
698 widget_class->drag_leave = gtk_entry_drag_leave;
699 widget_class->drag_data_received = gtk_entry_drag_data_received;
700 widget_class->drag_data_get = gtk_entry_drag_data_get;
701 widget_class->drag_data_delete = gtk_entry_drag_data_delete;
703 widget_class->popup_menu = gtk_entry_popup_menu;
705 class->move_cursor = gtk_entry_move_cursor;
706 class->insert_at_cursor = gtk_entry_insert_at_cursor;
707 class->delete_from_cursor = gtk_entry_delete_from_cursor;
708 class->backspace = gtk_entry_backspace;
709 class->cut_clipboard = gtk_entry_cut_clipboard;
710 class->copy_clipboard = gtk_entry_copy_clipboard;
711 class->paste_clipboard = gtk_entry_paste_clipboard;
712 class->toggle_overwrite = gtk_entry_toggle_overwrite;
713 class->activate = gtk_entry_real_activate;
714 class->get_text_area_size = gtk_entry_get_text_area_size;
716 quark_inner_border = g_quark_from_static_string ("gtk-entry-inner-border");
717 quark_password_hint = g_quark_from_static_string ("gtk-entry-password-hint");
718 quark_cursor_hadjustment = g_quark_from_static_string ("gtk-hadjustment");
719 quark_capslock_feedback = g_quark_from_static_string ("gtk-entry-capslock-feedback");
721 g_object_class_override_property (gobject_class,
722 PROP_EDITING_CANCELED,
725 g_object_class_install_property (gobject_class,
727 g_param_spec_object ("buffer",
729 P_("Text buffer object which actually stores entry text"),
730 GTK_TYPE_ENTRY_BUFFER,
731 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT));
733 g_object_class_install_property (gobject_class,
734 PROP_CURSOR_POSITION,
735 g_param_spec_int ("cursor-position",
736 P_("Cursor Position"),
737 P_("The current position of the insertion cursor in chars"),
739 GTK_ENTRY_BUFFER_MAX_SIZE,
741 GTK_PARAM_READABLE));
743 g_object_class_install_property (gobject_class,
744 PROP_SELECTION_BOUND,
745 g_param_spec_int ("selection-bound",
746 P_("Selection Bound"),
747 P_("The position of the opposite end of the selection from the cursor in chars"),
749 GTK_ENTRY_BUFFER_MAX_SIZE,
751 GTK_PARAM_READABLE));
753 g_object_class_install_property (gobject_class,
755 g_param_spec_boolean ("editable",
757 P_("Whether the entry contents can be edited"),
759 GTK_PARAM_READWRITE));
761 g_object_class_install_property (gobject_class,
763 g_param_spec_int ("max-length",
764 P_("Maximum length"),
765 P_("Maximum number of characters for this entry. Zero if no maximum"),
767 GTK_ENTRY_BUFFER_MAX_SIZE,
769 GTK_PARAM_READWRITE));
770 g_object_class_install_property (gobject_class,
772 g_param_spec_boolean ("visibility",
774 P_("FALSE displays the \"invisible char\" instead of the actual text (password mode)"),
776 GTK_PARAM_READWRITE));
778 g_object_class_install_property (gobject_class,
780 g_param_spec_boolean ("has-frame",
782 P_("FALSE removes outside bevel from entry"),
784 GTK_PARAM_READWRITE));
786 g_object_class_install_property (gobject_class,
788 g_param_spec_boxed ("inner-border",
790 P_("Border between text and frame. Overrides the inner-border style property"),
792 GTK_PARAM_READWRITE));
794 g_object_class_install_property (gobject_class,
796 g_param_spec_unichar ("invisible-char",
797 P_("Invisible character"),
798 P_("The character to use when masking entry contents (in \"password mode\")"),
800 GTK_PARAM_READWRITE));
802 g_object_class_install_property (gobject_class,
803 PROP_ACTIVATES_DEFAULT,
804 g_param_spec_boolean ("activates-default",
805 P_("Activates default"),
806 P_("Whether to activate the default widget (such as the default button in a dialog) when Enter is pressed"),
808 GTK_PARAM_READWRITE));
809 g_object_class_install_property (gobject_class,
811 g_param_spec_int ("width-chars",
812 P_("Width in chars"),
813 P_("Number of characters to leave space for in the entry"),
817 GTK_PARAM_READWRITE));
819 g_object_class_install_property (gobject_class,
821 g_param_spec_int ("scroll-offset",
823 P_("Number of pixels of the entry scrolled off the screen to the left"),
827 GTK_PARAM_READABLE));
829 g_object_class_install_property (gobject_class,
831 g_param_spec_string ("text",
833 P_("The contents of the entry"),
835 GTK_PARAM_READWRITE));
840 * The horizontal alignment, from 0 (left) to 1 (right).
841 * Reversed for RTL layouts.
845 g_object_class_install_property (gobject_class,
847 g_param_spec_float ("xalign",
849 P_("The horizontal alignment, from 0 (left) to 1 (right). Reversed for RTL layouts."),
853 GTK_PARAM_READWRITE));
856 * GtkEntry:truncate-multiline:
858 * When %TRUE, pasted multi-line text is truncated to the first line.
862 g_object_class_install_property (gobject_class,
863 PROP_TRUNCATE_MULTILINE,
864 g_param_spec_boolean ("truncate-multiline",
865 P_("Truncate multiline"),
866 P_("Whether to truncate multiline pastes to one line."),
868 GTK_PARAM_READWRITE));
871 * GtkEntry:shadow-type:
873 * Which kind of shadow to draw around the entry when
874 * #GtkEntry:has-frame is set to %TRUE.
878 g_object_class_install_property (gobject_class,
880 g_param_spec_enum ("shadow-type",
882 P_("Which kind of shadow to draw around the entry when has-frame is set"),
883 GTK_TYPE_SHADOW_TYPE,
885 GTK_PARAM_READWRITE));
888 * GtkEntry:overwrite-mode:
890 * If text is overwritten when typing in the #GtkEntry.
894 g_object_class_install_property (gobject_class,
896 g_param_spec_boolean ("overwrite-mode",
897 P_("Overwrite mode"),
898 P_("Whether new text overwrites existing text"),
900 GTK_PARAM_READWRITE));
903 * GtkEntry:text-length:
905 * The length of the text in the #GtkEntry.
909 g_object_class_install_property (gobject_class,
911 g_param_spec_uint ("text-length",
913 P_("Length of the text currently in the entry"),
917 GTK_PARAM_READABLE));
919 * GtkEntry:invisible-char-set:
921 * Whether the invisible char has been set for the #GtkEntry.
925 g_object_class_install_property (gobject_class,
926 PROP_INVISIBLE_CHAR_SET,
927 g_param_spec_boolean ("invisible-char-set",
928 P_("Invisible character set"),
929 P_("Whether the invisible character has been set"),
931 GTK_PARAM_READWRITE));
934 * GtkEntry:caps-lock-warning
936 * Whether password entries will show a warning when Caps Lock is on.
938 * Note that the warning is shown using a secondary icon, and thus
939 * does not work if you are using the secondary icon position for some
944 g_object_class_install_property (gobject_class,
945 PROP_CAPS_LOCK_WARNING,
946 g_param_spec_boolean ("caps-lock-warning",
947 P_("Caps Lock warning"),
948 P_("Whether password entries will show a warning when Caps Lock is on"),
950 GTK_PARAM_READWRITE));
953 * GtkEntry:progress-fraction:
955 * The current fraction of the task that's been completed.
959 g_object_class_install_property (gobject_class,
960 PROP_PROGRESS_FRACTION,
961 g_param_spec_double ("progress-fraction",
962 P_("Progress Fraction"),
963 P_("The current fraction of the task that's been completed"),
967 GTK_PARAM_READWRITE));
970 * GtkEntry:progress-pulse-step:
972 * The fraction of total entry width to move the progress
973 * bouncing block for each call to gtk_entry_progress_pulse().
977 g_object_class_install_property (gobject_class,
978 PROP_PROGRESS_PULSE_STEP,
979 g_param_spec_double ("progress-pulse-step",
980 P_("Progress Pulse Step"),
981 P_("The fraction of total entry width to move the progress bouncing block for each call to gtk_entry_progress_pulse()"),
985 GTK_PARAM_READWRITE));
988 * GtkEntry:placeholder-text:
990 * The text that will be displayed in the #GtkEntry when it is empty and unfocused.
994 g_object_class_install_property (gobject_class,
995 PROP_PLACEHOLDER_TEXT,
996 g_param_spec_string ("placeholder-text",
997 P_("Placeholder text"),
998 P_("Show text in the entry when it's empty and unfocused"),
1000 GTK_PARAM_READWRITE));
1003 * GtkEntry:primary-icon-pixbuf:
1005 * A pixbuf to use as the primary icon for the entry.
1009 g_object_class_install_property (gobject_class,
1010 PROP_PIXBUF_PRIMARY,
1011 g_param_spec_object ("primary-icon-pixbuf",
1012 P_("Primary pixbuf"),
1013 P_("Primary pixbuf for the entry"),
1015 GTK_PARAM_READWRITE));
1018 * GtkEntry:secondary-icon-pixbuf:
1020 * An pixbuf to use as the secondary icon for the entry.
1024 g_object_class_install_property (gobject_class,
1025 PROP_PIXBUF_SECONDARY,
1026 g_param_spec_object ("secondary-icon-pixbuf",
1027 P_("Secondary pixbuf"),
1028 P_("Secondary pixbuf for the entry"),
1030 GTK_PARAM_READWRITE));
1033 * GtkEntry:primary-icon-stock:
1035 * The stock id to use for the primary icon for the entry.
1039 g_object_class_install_property (gobject_class,
1041 g_param_spec_string ("primary-icon-stock",
1042 P_("Primary stock ID"),
1043 P_("Stock ID for primary icon"),
1045 GTK_PARAM_READWRITE));
1048 * GtkEntry:secondary-icon-stock:
1050 * The stock id to use for the secondary icon for the entry.
1054 g_object_class_install_property (gobject_class,
1055 PROP_STOCK_SECONDARY,
1056 g_param_spec_string ("secondary-icon-stock",
1057 P_("Secondary stock ID"),
1058 P_("Stock ID for secondary icon"),
1060 GTK_PARAM_READWRITE));
1063 * GtkEntry:primary-icon-name:
1065 * The icon name to use for the primary icon for the entry.
1069 g_object_class_install_property (gobject_class,
1070 PROP_ICON_NAME_PRIMARY,
1071 g_param_spec_string ("primary-icon-name",
1072 P_("Primary icon name"),
1073 P_("Icon name for primary icon"),
1075 GTK_PARAM_READWRITE));
1078 * GtkEntry:secondary-icon-name:
1080 * The icon name to use for the secondary icon for the entry.
1084 g_object_class_install_property (gobject_class,
1085 PROP_ICON_NAME_SECONDARY,
1086 g_param_spec_string ("secondary-icon-name",
1087 P_("Secondary icon name"),
1088 P_("Icon name for secondary icon"),
1090 GTK_PARAM_READWRITE));
1093 * GtkEntry:primary-icon-gicon:
1095 * The #GIcon to use for the primary icon for the entry.
1099 g_object_class_install_property (gobject_class,
1101 g_param_spec_object ("primary-icon-gicon",
1102 P_("Primary GIcon"),
1103 P_("GIcon for primary icon"),
1105 GTK_PARAM_READWRITE));
1108 * GtkEntry:secondary-icon-gicon:
1110 * The #GIcon to use for the secondary icon for the entry.
1114 g_object_class_install_property (gobject_class,
1115 PROP_GICON_SECONDARY,
1116 g_param_spec_object ("secondary-icon-gicon",
1117 P_("Secondary GIcon"),
1118 P_("GIcon for secondary icon"),
1120 GTK_PARAM_READWRITE));
1123 * GtkEntry:primary-icon-storage-type:
1125 * The representation which is used for the primary icon of the entry.
1129 g_object_class_install_property (gobject_class,
1130 PROP_STORAGE_TYPE_PRIMARY,
1131 g_param_spec_enum ("primary-icon-storage-type",
1132 P_("Primary storage type"),
1133 P_("The representation being used for primary icon"),
1134 GTK_TYPE_IMAGE_TYPE,
1136 GTK_PARAM_READABLE));
1139 * GtkEntry:secondary-icon-storage-type:
1141 * The representation which is used for the secondary icon of the entry.
1145 g_object_class_install_property (gobject_class,
1146 PROP_STORAGE_TYPE_SECONDARY,
1147 g_param_spec_enum ("secondary-icon-storage-type",
1148 P_("Secondary storage type"),
1149 P_("The representation being used for secondary icon"),
1150 GTK_TYPE_IMAGE_TYPE,
1152 GTK_PARAM_READABLE));
1155 * GtkEntry:primary-icon-activatable:
1157 * Whether the primary icon is activatable.
1159 * GTK+ emits the #GtkEntry::icon-press and #GtkEntry::icon-release
1160 * signals only on sensitive, activatable icons.
1162 * Sensitive, but non-activatable icons can be used for purely
1163 * informational purposes.
1167 g_object_class_install_property (gobject_class,
1168 PROP_ACTIVATABLE_PRIMARY,
1169 g_param_spec_boolean ("primary-icon-activatable",
1170 P_("Primary icon activatable"),
1171 P_("Whether the primary icon is activatable"),
1173 GTK_PARAM_READWRITE));
1176 * GtkEntry:secondary-icon-activatable:
1178 * Whether the secondary icon is activatable.
1180 * GTK+ emits the #GtkEntry::icon-press and #GtkEntry::icon-release
1181 * signals only on sensitive, activatable icons.
1183 * Sensitive, but non-activatable icons can be used for purely
1184 * informational purposes.
1188 g_object_class_install_property (gobject_class,
1189 PROP_ACTIVATABLE_SECONDARY,
1190 g_param_spec_boolean ("secondary-icon-activatable",
1191 P_("Secondary icon activatable"),
1192 P_("Whether the secondary icon is activatable"),
1194 GTK_PARAM_READWRITE));
1198 * GtkEntry:primary-icon-sensitive:
1200 * Whether the primary icon is sensitive.
1202 * An insensitive icon appears grayed out. GTK+ does not emit the
1203 * #GtkEntry::icon-press and #GtkEntry::icon-release signals and
1204 * does not allow DND from insensitive icons.
1206 * An icon should be set insensitive if the action that would trigger
1207 * when clicked is currently not available.
1211 g_object_class_install_property (gobject_class,
1212 PROP_SENSITIVE_PRIMARY,
1213 g_param_spec_boolean ("primary-icon-sensitive",
1214 P_("Primary icon sensitive"),
1215 P_("Whether the primary icon is sensitive"),
1217 GTK_PARAM_READWRITE));
1220 * GtkEntry:secondary-icon-sensitive:
1222 * Whether the secondary icon is sensitive.
1224 * An insensitive icon appears grayed out. GTK+ does not emit the
1225 * #GtkEntry::icon-press and #GtkEntry::icon-release signals and
1226 * does not allow DND from insensitive icons.
1228 * An icon should be set insensitive if the action that would trigger
1229 * when clicked is currently not available.
1233 g_object_class_install_property (gobject_class,
1234 PROP_SENSITIVE_SECONDARY,
1235 g_param_spec_boolean ("secondary-icon-sensitive",
1236 P_("Secondary icon sensitive"),
1237 P_("Whether the secondary icon is sensitive"),
1239 GTK_PARAM_READWRITE));
1242 * GtkEntry:primary-icon-tooltip-text:
1244 * The contents of the tooltip on the primary icon.
1246 * Also see gtk_entry_set_icon_tooltip_text().
1250 g_object_class_install_property (gobject_class,
1251 PROP_TOOLTIP_TEXT_PRIMARY,
1252 g_param_spec_string ("primary-icon-tooltip-text",
1253 P_("Primary icon tooltip text"),
1254 P_("The contents of the tooltip on the primary icon"),
1256 GTK_PARAM_READWRITE));
1259 * GtkEntry:secondary-icon-tooltip-text:
1261 * The contents of the tooltip on the secondary icon.
1263 * Also see gtk_entry_set_icon_tooltip_text().
1267 g_object_class_install_property (gobject_class,
1268 PROP_TOOLTIP_TEXT_SECONDARY,
1269 g_param_spec_string ("secondary-icon-tooltip-text",
1270 P_("Secondary icon tooltip text"),
1271 P_("The contents of the tooltip on the secondary icon"),
1273 GTK_PARAM_READWRITE));
1276 * GtkEntry:primary-icon-tooltip-markup:
1278 * The contents of the tooltip on the primary icon, which is marked up
1279 * with the <link linkend="PangoMarkupFormat">Pango text markup
1282 * Also see gtk_entry_set_icon_tooltip_markup().
1286 g_object_class_install_property (gobject_class,
1287 PROP_TOOLTIP_MARKUP_PRIMARY,
1288 g_param_spec_string ("primary-icon-tooltip-markup",
1289 P_("Primary icon tooltip markup"),
1290 P_("The contents of the tooltip on the primary icon"),
1292 GTK_PARAM_READWRITE));
1295 * GtkEntry:secondary-icon-tooltip-markup:
1297 * The contents of the tooltip on the secondary icon, which is marked up
1298 * with the <link linkend="PangoMarkupFormat">Pango text markup
1301 * Also see gtk_entry_set_icon_tooltip_markup().
1305 g_object_class_install_property (gobject_class,
1306 PROP_TOOLTIP_MARKUP_SECONDARY,
1307 g_param_spec_string ("secondary-icon-tooltip-markup",
1308 P_("Secondary icon tooltip markup"),
1309 P_("The contents of the tooltip on the secondary icon"),
1311 GTK_PARAM_READWRITE));
1314 * GtkEntry:im-module:
1316 * Which IM (input method) module should be used for this entry.
1317 * See #GtkIMContext.
1319 * Setting this to a non-%NULL value overrides the
1320 * system-wide IM module setting. See the GtkSettings
1321 * #GtkSettings:gtk-im-module property.
1325 g_object_class_install_property (gobject_class,
1327 g_param_spec_string ("im-module",
1329 P_("Which IM module should be used"),
1331 GTK_PARAM_READWRITE));
1334 * GtkEntry:completion:
1336 * The auxiliary completion object to use with the entry.
1340 g_object_class_install_property (gobject_class,
1342 g_param_spec_object ("completion",
1344 P_("The auxiliary completion object"),
1345 GTK_TYPE_ENTRY_COMPLETION,
1346 GTK_PARAM_READWRITE));
1349 * GtkEntry:icon-prelight:
1351 * The prelight style property determines whether activatable
1352 * icons prelight on mouseover.
1356 gtk_widget_class_install_style_property (widget_class,
1357 g_param_spec_boolean ("icon-prelight",
1358 P_("Icon Prelight"),
1359 P_("Whether activatable icons should prelight when hovered"),
1361 GTK_PARAM_READABLE));
1364 * GtkEntry:progress-border:
1366 * The border around the progress bar in the entry.
1370 gtk_widget_class_install_style_property (widget_class,
1371 g_param_spec_boxed ("progress-border",
1372 P_("Progress Border"),
1373 P_("Border around the progress bar"),
1375 GTK_PARAM_READABLE));
1378 * GtkEntry:invisible-char:
1380 * The invisible character is used when masking entry contents (in
1381 * \"password mode\")"). When it is not explicitly set with the
1382 * #GtkEntry::invisible-char property, GTK+ determines the character
1383 * to use from a list of possible candidates, depending on availability
1384 * in the current font.
1386 * This style property allows the theme to prepend a character
1387 * to the list of candidates.
1391 gtk_widget_class_install_style_property (widget_class,
1392 g_param_spec_unichar ("invisible-char",
1393 P_("Invisible character"),
1394 P_("The character to use when masking entry contents (in \"password mode\")"),
1396 GTK_PARAM_READABLE));
1399 * GtkEntry::populate-popup:
1400 * @entry: The entry on which the signal is emitted
1401 * @menu: the menu that is being populated
1403 * The ::populate-popup signal gets emitted before showing the
1404 * context menu of the entry.
1406 * If you need to add items to the context menu, connect
1407 * to this signal and append your menuitems to the @menu.
1409 signals[POPULATE_POPUP] =
1410 g_signal_new (I_("populate-popup"),
1411 G_OBJECT_CLASS_TYPE (gobject_class),
1413 G_STRUCT_OFFSET (GtkEntryClass, populate_popup),
1415 _gtk_marshal_VOID__OBJECT,
1419 /* Action signals */
1422 * GtkEntry::activate:
1423 * @entry: The entry on which the signal is emitted
1425 * A <link linkend="keybinding-signals">keybinding signal</link>
1426 * which gets emitted when the user activates the entry.
1428 * Applications should not connect to it, but may emit it with
1429 * g_signal_emit_by_name() if they need to control activation
1432 * The default bindings for this signal are all forms of the Enter key.
1435 g_signal_new (I_("activate"),
1436 G_OBJECT_CLASS_TYPE (gobject_class),
1437 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1438 G_STRUCT_OFFSET (GtkEntryClass, activate),
1440 _gtk_marshal_VOID__VOID,
1442 widget_class->activate_signal = signals[ACTIVATE];
1445 * GtkEntry::move-cursor:
1446 * @entry: the object which received the signal
1447 * @step: the granularity of the move, as a #GtkMovementStep
1448 * @count: the number of @step units to move
1449 * @extend_selection: %TRUE if the move should extend the selection
1451 * The ::move-cursor signal is a
1452 * <link linkend="keybinding-signals">keybinding signal</link>
1453 * which gets emitted when the user initiates a cursor movement.
1454 * If the cursor is not visible in @entry, this signal causes
1455 * the viewport to be moved instead.
1457 * Applications should not connect to it, but may emit it with
1458 * g_signal_emit_by_name() if they need to control the cursor
1461 * The default bindings for this signal come in two variants,
1462 * the variant with the Shift modifier extends the selection,
1463 * the variant without the Shift modifer does not.
1464 * There are too many key combinations to list them all here.
1466 * <listitem>Arrow keys move by individual characters/lines</listitem>
1467 * <listitem>Ctrl-arrow key combinations move by words/paragraphs</listitem>
1468 * <listitem>Home/End keys move to the ends of the buffer</listitem>
1471 signals[MOVE_CURSOR] =
1472 g_signal_new (I_("move-cursor"),
1473 G_OBJECT_CLASS_TYPE (gobject_class),
1474 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1475 G_STRUCT_OFFSET (GtkEntryClass, move_cursor),
1477 _gtk_marshal_VOID__ENUM_INT_BOOLEAN,
1479 GTK_TYPE_MOVEMENT_STEP,
1484 * GtkEntry::insert-at-cursor:
1485 * @entry: the object which received the signal
1486 * @string: the string to insert
1488 * The ::insert-at-cursor signal is a
1489 * <link linkend="keybinding-signals">keybinding signal</link>
1490 * which gets emitted when the user initiates the insertion of a
1491 * fixed string at the cursor.
1493 * This signal has no default bindings.
1495 signals[INSERT_AT_CURSOR] =
1496 g_signal_new (I_("insert-at-cursor"),
1497 G_OBJECT_CLASS_TYPE (gobject_class),
1498 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1499 G_STRUCT_OFFSET (GtkEntryClass, insert_at_cursor),
1501 _gtk_marshal_VOID__STRING,
1506 * GtkEntry::delete-from-cursor:
1507 * @entry: the object which received the signal
1508 * @type: the granularity of the deletion, as a #GtkDeleteType
1509 * @count: the number of @type units to delete
1511 * The ::delete-from-cursor signal is a
1512 * <link linkend="keybinding-signals">keybinding signal</link>
1513 * which gets emitted when the user initiates a text deletion.
1515 * If the @type is %GTK_DELETE_CHARS, GTK+ deletes the selection
1516 * if there is one, otherwise it deletes the requested number
1519 * The default bindings for this signal are
1520 * Delete for deleting a character and Ctrl-Delete for
1523 signals[DELETE_FROM_CURSOR] =
1524 g_signal_new (I_("delete-from-cursor"),
1525 G_OBJECT_CLASS_TYPE (gobject_class),
1526 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1527 G_STRUCT_OFFSET (GtkEntryClass, delete_from_cursor),
1529 _gtk_marshal_VOID__ENUM_INT,
1531 GTK_TYPE_DELETE_TYPE,
1535 * GtkEntry::backspace:
1536 * @entry: the object which received the signal
1538 * The ::backspace signal is a
1539 * <link linkend="keybinding-signals">keybinding signal</link>
1540 * which gets emitted when the user asks for it.
1542 * The default bindings for this signal are
1543 * Backspace and Shift-Backspace.
1545 signals[BACKSPACE] =
1546 g_signal_new (I_("backspace"),
1547 G_OBJECT_CLASS_TYPE (gobject_class),
1548 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1549 G_STRUCT_OFFSET (GtkEntryClass, backspace),
1551 _gtk_marshal_VOID__VOID,
1555 * GtkEntry::cut-clipboard:
1556 * @entry: the object which received the signal
1558 * The ::cut-clipboard signal is a
1559 * <link linkend="keybinding-signals">keybinding signal</link>
1560 * which gets emitted to cut the selection to the clipboard.
1562 * The default bindings for this signal are
1563 * Ctrl-x and Shift-Delete.
1565 signals[CUT_CLIPBOARD] =
1566 g_signal_new (I_("cut-clipboard"),
1567 G_OBJECT_CLASS_TYPE (gobject_class),
1568 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1569 G_STRUCT_OFFSET (GtkEntryClass, cut_clipboard),
1571 _gtk_marshal_VOID__VOID,
1575 * GtkEntry::copy-clipboard:
1576 * @entry: the object which received the signal
1578 * The ::copy-clipboard signal is a
1579 * <link linkend="keybinding-signals">keybinding signal</link>
1580 * which gets emitted to copy the selection to the clipboard.
1582 * The default bindings for this signal are
1583 * Ctrl-c and Ctrl-Insert.
1585 signals[COPY_CLIPBOARD] =
1586 g_signal_new (I_("copy-clipboard"),
1587 G_OBJECT_CLASS_TYPE (gobject_class),
1588 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1589 G_STRUCT_OFFSET (GtkEntryClass, copy_clipboard),
1591 _gtk_marshal_VOID__VOID,
1595 * GtkEntry::paste-clipboard:
1596 * @entry: the object which received the signal
1598 * The ::paste-clipboard signal is a
1599 * <link linkend="keybinding-signals">keybinding signal</link>
1600 * which gets emitted to paste the contents of the clipboard
1601 * into the text view.
1603 * The default bindings for this signal are
1604 * Ctrl-v and Shift-Insert.
1606 signals[PASTE_CLIPBOARD] =
1607 g_signal_new (I_("paste-clipboard"),
1608 G_OBJECT_CLASS_TYPE (gobject_class),
1609 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1610 G_STRUCT_OFFSET (GtkEntryClass, paste_clipboard),
1612 _gtk_marshal_VOID__VOID,
1616 * GtkEntry::toggle-overwrite:
1617 * @entry: the object which received the signal
1619 * The ::toggle-overwrite signal is a
1620 * <link linkend="keybinding-signals">keybinding signal</link>
1621 * which gets emitted to toggle the overwrite mode of the entry.
1623 * The default bindings for this signal is Insert.
1625 signals[TOGGLE_OVERWRITE] =
1626 g_signal_new (I_("toggle-overwrite"),
1627 G_OBJECT_CLASS_TYPE (gobject_class),
1628 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1629 G_STRUCT_OFFSET (GtkEntryClass, toggle_overwrite),
1631 _gtk_marshal_VOID__VOID,
1635 * GtkEntry::icon-press:
1636 * @entry: The entry on which the signal is emitted
1637 * @icon_pos: The position of the clicked icon
1638 * @event: (type Gdk.EventButton): the button press event
1640 * The ::icon-press signal is emitted when an activatable icon
1645 signals[ICON_PRESS] =
1646 g_signal_new (I_("icon-press"),
1647 G_TYPE_FROM_CLASS (gobject_class),
1651 _gtk_marshal_VOID__ENUM_BOXED,
1653 GTK_TYPE_ENTRY_ICON_POSITION,
1654 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1657 * GtkEntry::icon-release:
1658 * @entry: The entry on which the signal is emitted
1659 * @icon_pos: The position of the clicked icon
1660 * @event: (type Gdk.EventButton): the button release event
1662 * The ::icon-release signal is emitted on the button release from a
1663 * mouse click over an activatable icon.
1667 signals[ICON_RELEASE] =
1668 g_signal_new (I_("icon-release"),
1669 G_TYPE_FROM_CLASS (gobject_class),
1673 _gtk_marshal_VOID__ENUM_BOXED,
1675 GTK_TYPE_ENTRY_ICON_POSITION,
1676 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1679 * GtkEntry::preedit-changed:
1680 * @entry: the object which received the signal
1681 * @preedit: the current preedit string
1683 * If an input method is used, the typed text will not immediately
1684 * be committed to the buffer. So if you are interested in the text,
1685 * connect to this signal.
1689 signals[PREEDIT_CHANGED] =
1690 g_signal_new_class_handler (I_("preedit-changed"),
1691 G_OBJECT_CLASS_TYPE (gobject_class),
1692 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1695 _gtk_marshal_VOID__STRING,
1704 binding_set = gtk_binding_set_by_class (class);
1706 /* Moving the insertion point */
1707 add_move_binding (binding_set, GDK_KEY_Right, 0,
1708 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1710 add_move_binding (binding_set, GDK_KEY_Left, 0,
1711 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1713 add_move_binding (binding_set, GDK_KEY_KP_Right, 0,
1714 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1716 add_move_binding (binding_set, GDK_KEY_KP_Left, 0,
1717 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1719 add_move_binding (binding_set, GDK_KEY_Right, GDK_CONTROL_MASK,
1720 GTK_MOVEMENT_WORDS, 1);
1722 add_move_binding (binding_set, GDK_KEY_Left, GDK_CONTROL_MASK,
1723 GTK_MOVEMENT_WORDS, -1);
1725 add_move_binding (binding_set, GDK_KEY_KP_Right, GDK_CONTROL_MASK,
1726 GTK_MOVEMENT_WORDS, 1);
1728 add_move_binding (binding_set, GDK_KEY_KP_Left, GDK_CONTROL_MASK,
1729 GTK_MOVEMENT_WORDS, -1);
1731 add_move_binding (binding_set, GDK_KEY_Home, 0,
1732 GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
1734 add_move_binding (binding_set, GDK_KEY_End, 0,
1735 GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
1737 add_move_binding (binding_set, GDK_KEY_KP_Home, 0,
1738 GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
1740 add_move_binding (binding_set, GDK_KEY_KP_End, 0,
1741 GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
1743 add_move_binding (binding_set, GDK_KEY_Home, GDK_CONTROL_MASK,
1744 GTK_MOVEMENT_BUFFER_ENDS, -1);
1746 add_move_binding (binding_set, GDK_KEY_End, GDK_CONTROL_MASK,
1747 GTK_MOVEMENT_BUFFER_ENDS, 1);
1749 add_move_binding (binding_set, GDK_KEY_KP_Home, GDK_CONTROL_MASK,
1750 GTK_MOVEMENT_BUFFER_ENDS, -1);
1752 add_move_binding (binding_set, GDK_KEY_KP_End, GDK_CONTROL_MASK,
1753 GTK_MOVEMENT_BUFFER_ENDS, 1);
1757 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK,
1759 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1761 G_TYPE_BOOLEAN, FALSE);
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, TRUE);
1768 gtk_binding_entry_add_signal (binding_set, GDK_KEY_slash, GDK_CONTROL_MASK,
1770 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1772 G_TYPE_BOOLEAN, FALSE);
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, TRUE);
1780 gtk_binding_entry_add_signal (binding_set, GDK_KEY_backslash, GDK_CONTROL_MASK,
1782 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_VISUAL_POSITIONS,
1784 G_TYPE_BOOLEAN, FALSE);
1785 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_SHIFT_MASK | GDK_CONTROL_MASK,
1787 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_VISUAL_POSITIONS,
1789 G_TYPE_BOOLEAN, FALSE);
1793 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Return, 0,
1795 gtk_binding_entry_add_signal (binding_set, GDK_KEY_ISO_Enter, 0,
1797 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Enter, 0,
1801 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, 0,
1802 "delete-from-cursor", 2,
1803 G_TYPE_ENUM, GTK_DELETE_CHARS,
1806 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Delete, 0,
1807 "delete-from-cursor", 2,
1808 G_TYPE_ENUM, GTK_DELETE_CHARS,
1811 gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, 0,
1814 /* Make this do the same as Backspace, to help with mis-typing */
1815 gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, GDK_SHIFT_MASK,
1818 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, GDK_CONTROL_MASK,
1819 "delete-from-cursor", 2,
1820 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1823 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_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_BackSpace, GDK_CONTROL_MASK,
1829 "delete-from-cursor", 2,
1830 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1833 /* Cut/copy/paste */
1835 gtk_binding_entry_add_signal (binding_set, GDK_KEY_x, GDK_CONTROL_MASK,
1836 "cut-clipboard", 0);
1837 gtk_binding_entry_add_signal (binding_set, GDK_KEY_c, GDK_CONTROL_MASK,
1838 "copy-clipboard", 0);
1839 gtk_binding_entry_add_signal (binding_set, GDK_KEY_v, GDK_CONTROL_MASK,
1840 "paste-clipboard", 0);
1842 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, GDK_SHIFT_MASK,
1843 "cut-clipboard", 0);
1844 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, GDK_CONTROL_MASK,
1845 "copy-clipboard", 0);
1846 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, GDK_SHIFT_MASK,
1847 "paste-clipboard", 0);
1850 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, 0,
1851 "toggle-overwrite", 0);
1852 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Insert, 0,
1853 "toggle-overwrite", 0);
1856 * GtkEntry:inner-border:
1858 * Sets the text area's border between the text and the frame.
1862 gtk_widget_class_install_style_property (widget_class,
1863 g_param_spec_boxed ("inner-border",
1865 P_("Border between text and frame."),
1867 GTK_PARAM_READABLE));
1869 g_type_class_add_private (gobject_class, sizeof (GtkEntryPrivate));
1873 gtk_entry_editable_init (GtkEditableInterface *iface)
1875 iface->do_insert_text = gtk_entry_insert_text;
1876 iface->do_delete_text = gtk_entry_delete_text;
1877 iface->insert_text = gtk_entry_real_insert_text;
1878 iface->delete_text = gtk_entry_real_delete_text;
1879 iface->get_chars = gtk_entry_get_chars;
1880 iface->set_selection_bounds = gtk_entry_set_selection_bounds;
1881 iface->get_selection_bounds = gtk_entry_get_selection_bounds;
1882 iface->set_position = gtk_entry_real_set_position;
1883 iface->get_position = gtk_entry_get_position;
1887 gtk_entry_cell_editable_init (GtkCellEditableIface *iface)
1889 iface->start_editing = gtk_entry_start_editing;
1893 gtk_entry_set_property (GObject *object,
1895 const GValue *value,
1898 GtkEntry *entry = GTK_ENTRY (object);
1899 GtkEntryPrivate *priv = entry->priv;
1904 gtk_entry_set_buffer (entry, g_value_get_object (value));
1909 gboolean new_value = g_value_get_boolean (value);
1911 if (new_value != priv->editable)
1913 GtkWidget *widget = GTK_WIDGET (entry);
1917 _gtk_entry_reset_im_context (entry);
1918 if (gtk_widget_has_focus (widget))
1919 gtk_im_context_focus_out (priv->im_context);
1921 priv->preedit_length = 0;
1922 priv->preedit_cursor = 0;
1925 priv->editable = new_value;
1927 if (new_value && gtk_widget_has_focus (widget))
1928 gtk_im_context_focus_in (priv->im_context);
1930 gtk_widget_queue_draw (widget);
1935 case PROP_MAX_LENGTH:
1936 gtk_entry_set_max_length (entry, g_value_get_int (value));
1939 case PROP_VISIBILITY:
1940 gtk_entry_set_visibility (entry, g_value_get_boolean (value));
1943 case PROP_HAS_FRAME:
1944 gtk_entry_set_has_frame (entry, g_value_get_boolean (value));
1947 case PROP_INNER_BORDER:
1948 gtk_entry_set_inner_border (entry, g_value_get_boxed (value));
1951 case PROP_INVISIBLE_CHAR:
1952 gtk_entry_set_invisible_char (entry, g_value_get_uint (value));
1955 case PROP_ACTIVATES_DEFAULT:
1956 gtk_entry_set_activates_default (entry, g_value_get_boolean (value));
1959 case PROP_WIDTH_CHARS:
1960 gtk_entry_set_width_chars (entry, g_value_get_int (value));
1964 gtk_entry_set_text (entry, g_value_get_string (value));
1968 gtk_entry_set_alignment (entry, g_value_get_float (value));
1971 case PROP_TRUNCATE_MULTILINE:
1972 priv->truncate_multiline = g_value_get_boolean (value);
1975 case PROP_SHADOW_TYPE:
1976 priv->shadow_type = g_value_get_enum (value);
1979 case PROP_OVERWRITE_MODE:
1980 gtk_entry_set_overwrite_mode (entry, g_value_get_boolean (value));
1983 case PROP_INVISIBLE_CHAR_SET:
1984 if (g_value_get_boolean (value))
1985 priv->invisible_char_set = TRUE;
1987 gtk_entry_unset_invisible_char (entry);
1990 case PROP_CAPS_LOCK_WARNING:
1991 priv->caps_lock_warning = g_value_get_boolean (value);
1994 case PROP_PROGRESS_FRACTION:
1995 gtk_entry_set_progress_fraction (entry, g_value_get_double (value));
1998 case PROP_PROGRESS_PULSE_STEP:
1999 gtk_entry_set_progress_pulse_step (entry, g_value_get_double (value));
2002 case PROP_PLACEHOLDER_TEXT:
2003 gtk_entry_set_placeholder_text (entry, g_value_get_string (value));
2006 case PROP_PIXBUF_PRIMARY:
2007 gtk_entry_set_icon_from_pixbuf (entry,
2008 GTK_ENTRY_ICON_PRIMARY,
2009 g_value_get_object (value));
2012 case PROP_PIXBUF_SECONDARY:
2013 gtk_entry_set_icon_from_pixbuf (entry,
2014 GTK_ENTRY_ICON_SECONDARY,
2015 g_value_get_object (value));
2018 case PROP_STOCK_PRIMARY:
2019 gtk_entry_set_icon_from_stock (entry,
2020 GTK_ENTRY_ICON_PRIMARY,
2021 g_value_get_string (value));
2024 case PROP_STOCK_SECONDARY:
2025 gtk_entry_set_icon_from_stock (entry,
2026 GTK_ENTRY_ICON_SECONDARY,
2027 g_value_get_string (value));
2030 case PROP_ICON_NAME_PRIMARY:
2031 gtk_entry_set_icon_from_icon_name (entry,
2032 GTK_ENTRY_ICON_PRIMARY,
2033 g_value_get_string (value));
2036 case PROP_ICON_NAME_SECONDARY:
2037 gtk_entry_set_icon_from_icon_name (entry,
2038 GTK_ENTRY_ICON_SECONDARY,
2039 g_value_get_string (value));
2042 case PROP_GICON_PRIMARY:
2043 gtk_entry_set_icon_from_gicon (entry,
2044 GTK_ENTRY_ICON_PRIMARY,
2045 g_value_get_object (value));
2048 case PROP_GICON_SECONDARY:
2049 gtk_entry_set_icon_from_gicon (entry,
2050 GTK_ENTRY_ICON_SECONDARY,
2051 g_value_get_object (value));
2054 case PROP_ACTIVATABLE_PRIMARY:
2055 gtk_entry_set_icon_activatable (entry,
2056 GTK_ENTRY_ICON_PRIMARY,
2057 g_value_get_boolean (value));
2060 case PROP_ACTIVATABLE_SECONDARY:
2061 gtk_entry_set_icon_activatable (entry,
2062 GTK_ENTRY_ICON_SECONDARY,
2063 g_value_get_boolean (value));
2066 case PROP_SENSITIVE_PRIMARY:
2067 gtk_entry_set_icon_sensitive (entry,
2068 GTK_ENTRY_ICON_PRIMARY,
2069 g_value_get_boolean (value));
2072 case PROP_SENSITIVE_SECONDARY:
2073 gtk_entry_set_icon_sensitive (entry,
2074 GTK_ENTRY_ICON_SECONDARY,
2075 g_value_get_boolean (value));
2078 case PROP_TOOLTIP_TEXT_PRIMARY:
2079 gtk_entry_set_icon_tooltip_text (entry,
2080 GTK_ENTRY_ICON_PRIMARY,
2081 g_value_get_string (value));
2084 case PROP_TOOLTIP_TEXT_SECONDARY:
2085 gtk_entry_set_icon_tooltip_text (entry,
2086 GTK_ENTRY_ICON_SECONDARY,
2087 g_value_get_string (value));
2090 case PROP_TOOLTIP_MARKUP_PRIMARY:
2091 gtk_entry_set_icon_tooltip_markup (entry,
2092 GTK_ENTRY_ICON_PRIMARY,
2093 g_value_get_string (value));
2096 case PROP_TOOLTIP_MARKUP_SECONDARY:
2097 gtk_entry_set_icon_tooltip_markup (entry,
2098 GTK_ENTRY_ICON_SECONDARY,
2099 g_value_get_string (value));
2102 case PROP_IM_MODULE:
2103 g_free (priv->im_module);
2104 priv->im_module = g_value_dup_string (value);
2105 if (GTK_IS_IM_MULTICONTEXT (priv->im_context))
2106 gtk_im_multicontext_set_context_id (GTK_IM_MULTICONTEXT (priv->im_context), priv->im_module);
2109 case PROP_EDITING_CANCELED:
2110 priv->editing_canceled = g_value_get_boolean (value);
2113 case PROP_COMPLETION:
2114 gtk_entry_set_completion (entry, GTK_ENTRY_COMPLETION (g_value_get_object (value)));
2117 case PROP_SCROLL_OFFSET:
2118 case PROP_CURSOR_POSITION:
2120 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2126 gtk_entry_get_property (GObject *object,
2131 GtkEntry *entry = GTK_ENTRY (object);
2132 GtkEntryPrivate *priv = entry->priv;
2137 g_value_set_object (value, gtk_entry_get_buffer (entry));
2140 case PROP_CURSOR_POSITION:
2141 g_value_set_int (value, priv->current_pos);
2144 case PROP_SELECTION_BOUND:
2145 g_value_set_int (value, priv->selection_bound);
2149 g_value_set_boolean (value, priv->editable);
2152 case PROP_MAX_LENGTH:
2153 g_value_set_int (value, gtk_entry_buffer_get_max_length (get_buffer (entry)));
2156 case PROP_VISIBILITY:
2157 g_value_set_boolean (value, priv->visible);
2160 case PROP_HAS_FRAME:
2161 g_value_set_boolean (value, priv->has_frame);
2164 case PROP_INNER_BORDER:
2165 g_value_set_boxed (value, gtk_entry_get_inner_border (entry));
2168 case PROP_INVISIBLE_CHAR:
2169 g_value_set_uint (value, priv->invisible_char);
2172 case PROP_ACTIVATES_DEFAULT:
2173 g_value_set_boolean (value, priv->activates_default);
2176 case PROP_WIDTH_CHARS:
2177 g_value_set_int (value, priv->width_chars);
2180 case PROP_SCROLL_OFFSET:
2181 g_value_set_int (value, priv->scroll_offset);
2185 g_value_set_string (value, gtk_entry_get_text (entry));
2189 g_value_set_float (value, gtk_entry_get_alignment (entry));
2192 case PROP_TRUNCATE_MULTILINE:
2193 g_value_set_boolean (value, priv->truncate_multiline);
2196 case PROP_SHADOW_TYPE:
2197 g_value_set_enum (value, priv->shadow_type);
2200 case PROP_OVERWRITE_MODE:
2201 g_value_set_boolean (value, priv->overwrite_mode);
2204 case PROP_TEXT_LENGTH:
2205 g_value_set_uint (value, gtk_entry_buffer_get_length (get_buffer (entry)));
2208 case PROP_INVISIBLE_CHAR_SET:
2209 g_value_set_boolean (value, priv->invisible_char_set);
2212 case PROP_IM_MODULE:
2213 g_value_set_string (value, priv->im_module);
2216 case PROP_CAPS_LOCK_WARNING:
2217 g_value_set_boolean (value, priv->caps_lock_warning);
2220 case PROP_PROGRESS_FRACTION:
2221 g_value_set_double (value, priv->progress_fraction);
2224 case PROP_PROGRESS_PULSE_STEP:
2225 g_value_set_double (value, priv->progress_pulse_fraction);
2228 case PROP_PLACEHOLDER_TEXT:
2229 g_value_set_string (value, gtk_entry_get_placeholder_text (entry));
2232 case PROP_PIXBUF_PRIMARY:
2233 g_value_set_object (value,
2234 gtk_entry_get_icon_pixbuf (entry,
2235 GTK_ENTRY_ICON_PRIMARY));
2238 case PROP_PIXBUF_SECONDARY:
2239 g_value_set_object (value,
2240 gtk_entry_get_icon_pixbuf (entry,
2241 GTK_ENTRY_ICON_SECONDARY));
2244 case PROP_STOCK_PRIMARY:
2245 g_value_set_string (value,
2246 gtk_entry_get_icon_stock (entry,
2247 GTK_ENTRY_ICON_PRIMARY));
2250 case PROP_STOCK_SECONDARY:
2251 g_value_set_string (value,
2252 gtk_entry_get_icon_stock (entry,
2253 GTK_ENTRY_ICON_SECONDARY));
2256 case PROP_ICON_NAME_PRIMARY:
2257 g_value_set_string (value,
2258 gtk_entry_get_icon_name (entry,
2259 GTK_ENTRY_ICON_PRIMARY));
2262 case PROP_ICON_NAME_SECONDARY:
2263 g_value_set_string (value,
2264 gtk_entry_get_icon_name (entry,
2265 GTK_ENTRY_ICON_SECONDARY));
2268 case PROP_GICON_PRIMARY:
2269 g_value_set_object (value,
2270 gtk_entry_get_icon_gicon (entry,
2271 GTK_ENTRY_ICON_PRIMARY));
2274 case PROP_GICON_SECONDARY:
2275 g_value_set_object (value,
2276 gtk_entry_get_icon_gicon (entry,
2277 GTK_ENTRY_ICON_SECONDARY));
2280 case PROP_STORAGE_TYPE_PRIMARY:
2281 g_value_set_enum (value,
2282 gtk_entry_get_icon_storage_type (entry,
2283 GTK_ENTRY_ICON_PRIMARY));
2286 case PROP_STORAGE_TYPE_SECONDARY:
2287 g_value_set_enum (value,
2288 gtk_entry_get_icon_storage_type (entry,
2289 GTK_ENTRY_ICON_SECONDARY));
2292 case PROP_ACTIVATABLE_PRIMARY:
2293 g_value_set_boolean (value,
2294 gtk_entry_get_icon_activatable (entry, GTK_ENTRY_ICON_PRIMARY));
2297 case PROP_ACTIVATABLE_SECONDARY:
2298 g_value_set_boolean (value,
2299 gtk_entry_get_icon_activatable (entry, GTK_ENTRY_ICON_SECONDARY));
2302 case PROP_SENSITIVE_PRIMARY:
2303 g_value_set_boolean (value,
2304 gtk_entry_get_icon_sensitive (entry, GTK_ENTRY_ICON_PRIMARY));
2307 case PROP_SENSITIVE_SECONDARY:
2308 g_value_set_boolean (value,
2309 gtk_entry_get_icon_sensitive (entry, GTK_ENTRY_ICON_SECONDARY));
2312 case PROP_TOOLTIP_TEXT_PRIMARY:
2313 g_value_take_string (value,
2314 gtk_entry_get_icon_tooltip_text (entry, GTK_ENTRY_ICON_PRIMARY));
2317 case PROP_TOOLTIP_TEXT_SECONDARY:
2318 g_value_take_string (value,
2319 gtk_entry_get_icon_tooltip_text (entry, GTK_ENTRY_ICON_SECONDARY));
2322 case PROP_TOOLTIP_MARKUP_PRIMARY:
2323 g_value_take_string (value,
2324 gtk_entry_get_icon_tooltip_markup (entry, GTK_ENTRY_ICON_PRIMARY));
2327 case PROP_TOOLTIP_MARKUP_SECONDARY:
2328 g_value_take_string (value,
2329 gtk_entry_get_icon_tooltip_markup (entry, GTK_ENTRY_ICON_SECONDARY));
2332 case PROP_EDITING_CANCELED:
2333 g_value_set_boolean (value,
2334 priv->editing_canceled);
2337 case PROP_COMPLETION:
2338 g_value_set_object (value, G_OBJECT (gtk_entry_get_completion (entry)));
2342 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2348 find_invisible_char (GtkWidget *widget)
2350 PangoLayout *layout;
2351 PangoAttrList *attr_list;
2353 gunichar invisible_chars [] = {
2355 0x25cf, /* BLACK CIRCLE */
2356 0x2022, /* BULLET */
2357 0x2731, /* HEAVY ASTERISK */
2358 0x273a /* SIXTEEN POINTED ASTERISK */
2361 gtk_widget_style_get (widget,
2362 "invisible-char", &invisible_chars[0],
2365 layout = gtk_widget_create_pango_layout (widget, NULL);
2367 attr_list = pango_attr_list_new ();
2368 pango_attr_list_insert (attr_list, pango_attr_fallback_new (FALSE));
2370 pango_layout_set_attributes (layout, attr_list);
2371 pango_attr_list_unref (attr_list);
2373 for (i = (invisible_chars[0] != 0 ? 0 : 1); i < G_N_ELEMENTS (invisible_chars); i++)
2375 gchar text[7] = { 0, };
2378 len = g_unichar_to_utf8 (invisible_chars[i], text);
2379 pango_layout_set_text (layout, text, len);
2381 count = pango_layout_get_unknown_glyphs_count (layout);
2385 g_object_unref (layout);
2386 return invisible_chars[i];
2390 g_object_unref (layout);
2396 gtk_entry_init (GtkEntry *entry)
2398 GtkStyleContext *context;
2399 GtkEntryPrivate *priv;
2401 entry->priv = G_TYPE_INSTANCE_GET_PRIVATE (entry,
2406 gtk_widget_set_can_focus (GTK_WIDGET (entry), TRUE);
2407 gtk_widget_set_has_window (GTK_WIDGET (entry), FALSE);
2409 priv->editable = TRUE;
2410 priv->visible = TRUE;
2411 priv->invisible_char = find_invisible_char (GTK_WIDGET (entry));
2412 priv->dnd_position = -1;
2413 priv->width_chars = -1;
2414 priv->is_cell_renderer = FALSE;
2415 priv->editing_canceled = FALSE;
2416 priv->has_frame = TRUE;
2417 priv->truncate_multiline = FALSE;
2418 priv->shadow_type = GTK_SHADOW_IN;
2420 priv->caps_lock_warning = TRUE;
2421 priv->caps_lock_warning_shown = FALSE;
2422 priv->progress_fraction = 0.0;
2423 priv->progress_pulse_fraction = 0.1;
2425 gtk_drag_dest_set (GTK_WIDGET (entry),
2426 GTK_DEST_DEFAULT_HIGHLIGHT,
2428 GDK_ACTION_COPY | GDK_ACTION_MOVE);
2429 gtk_drag_dest_add_text_targets (GTK_WIDGET (entry));
2431 /* This object is completely private. No external entity can gain a reference
2432 * to it; so we create it here and destroy it in finalize().
2434 priv->im_context = gtk_im_multicontext_new ();
2436 g_signal_connect (priv->im_context, "commit",
2437 G_CALLBACK (gtk_entry_commit_cb), entry);
2438 g_signal_connect (priv->im_context, "preedit-changed",
2439 G_CALLBACK (gtk_entry_preedit_changed_cb), entry);
2440 g_signal_connect (priv->im_context, "retrieve-surrounding",
2441 G_CALLBACK (gtk_entry_retrieve_surrounding_cb), entry);
2442 g_signal_connect (priv->im_context, "delete-surrounding",
2443 G_CALLBACK (gtk_entry_delete_surrounding_cb), entry);
2445 context = gtk_widget_get_style_context (GTK_WIDGET (entry));
2446 gtk_style_context_add_class (context, GTK_STYLE_CLASS_ENTRY);
2450 get_icon_width (GtkEntry *entry,
2451 GtkEntryIconPosition icon_pos)
2453 GtkEntryPrivate *priv = entry->priv;
2454 EntryIconInfo *icon_info = priv->icons[icon_pos];
2456 GtkSettings *settings;
2457 gint menu_icon_width;
2459 if (!icon_info || icon_info->pixbuf == NULL)
2462 screen = gtk_widget_get_screen (GTK_WIDGET (entry));
2463 settings = gtk_settings_get_for_screen (screen);
2465 gtk_icon_size_lookup_for_settings (settings, GTK_ICON_SIZE_MENU,
2466 &menu_icon_width, NULL);
2468 return MAX (gdk_pixbuf_get_width (icon_info->pixbuf), menu_icon_width);
2472 get_icon_allocations (GtkEntry *entry,
2473 GtkAllocation *primary,
2474 GtkAllocation *secondary)
2477 GtkEntryPrivate *priv = entry->priv;
2478 gint x, y, width, height;
2480 get_text_area_size (entry, &x, &y, &width, &height);
2482 if (gtk_widget_has_focus (GTK_WIDGET (entry)) && !priv->interior_focus)
2483 y += priv->focus_width;
2486 primary->height = height;
2487 primary->width = get_icon_width (entry, GTK_ENTRY_ICON_PRIMARY);
2488 if (primary->width > 0)
2489 primary->width += 2 * priv->icon_margin;
2492 secondary->height = height;
2493 secondary->width = get_icon_width (entry, GTK_ENTRY_ICON_SECONDARY);
2494 if (secondary->width > 0)
2495 secondary->width += 2 * priv->icon_margin;
2497 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
2499 primary->x = x + width - primary->width;
2505 secondary->x = x + width - secondary->width;
2511 begin_change (GtkEntry *entry)
2513 GtkEntryPrivate *priv = entry->priv;
2515 priv->change_count++;
2519 end_change (GtkEntry *entry)
2521 GtkEditable *editable = GTK_EDITABLE (entry);
2522 GtkEntryPrivate *priv = entry->priv;
2524 g_return_if_fail (priv->change_count > 0);
2526 priv->change_count--;
2528 if (priv->change_count == 0)
2530 if (priv->real_changed)
2532 g_signal_emit_by_name (editable, "changed");
2533 priv->real_changed = FALSE;
2539 emit_changed (GtkEntry *entry)
2541 GtkEditable *editable = GTK_EDITABLE (entry);
2542 GtkEntryPrivate *priv = entry->priv;
2544 if (priv->change_count == 0)
2545 g_signal_emit_by_name (editable, "changed");
2547 priv->real_changed = TRUE;
2551 gtk_entry_destroy (GtkWidget *widget)
2553 GtkEntry *entry = GTK_ENTRY (widget);
2554 GtkEntryPrivate *priv = entry->priv;
2556 priv->current_pos = priv->selection_bound = 0;
2557 _gtk_entry_reset_im_context (entry);
2558 gtk_entry_reset_layout (entry);
2560 if (priv->blink_timeout)
2562 g_source_remove (priv->blink_timeout);
2563 priv->blink_timeout = 0;
2566 if (priv->recompute_idle)
2568 g_source_remove (priv->recompute_idle);
2569 priv->recompute_idle = 0;
2572 GTK_WIDGET_CLASS (gtk_entry_parent_class)->destroy (widget);
2576 gtk_entry_dispose (GObject *object)
2578 GtkEntry *entry = GTK_ENTRY (object);
2579 GtkEntryPrivate *priv = entry->priv;
2581 gtk_entry_set_icon_from_pixbuf (entry, GTK_ENTRY_ICON_PRIMARY, NULL);
2582 gtk_entry_set_icon_tooltip_markup (entry, GTK_ENTRY_ICON_PRIMARY, NULL);
2583 gtk_entry_set_icon_from_pixbuf (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
2584 gtk_entry_set_icon_tooltip_markup (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
2588 buffer_disconnect_signals (entry);
2589 g_object_unref (priv->buffer);
2590 priv->buffer = NULL;
2593 G_OBJECT_CLASS (gtk_entry_parent_class)->dispose (object);
2597 gtk_entry_finalize (GObject *object)
2599 GtkEntry *entry = GTK_ENTRY (object);
2600 GtkEntryPrivate *priv = entry->priv;
2601 EntryIconInfo *icon_info = NULL;
2604 for (i = 0; i < MAX_ICONS; i++)
2606 if ((icon_info = priv->icons[i]) != NULL)
2608 if (icon_info->target_list != NULL)
2610 gtk_target_list_unref (icon_info->target_list);
2611 icon_info->target_list = NULL;
2614 g_slice_free (EntryIconInfo, icon_info);
2615 priv->icons[i] = NULL;
2619 gtk_entry_set_completion (entry, NULL);
2621 if (priv->cached_layout)
2622 g_object_unref (priv->cached_layout);
2624 g_object_unref (priv->im_context);
2626 if (priv->blink_timeout)
2627 g_source_remove (priv->blink_timeout);
2629 if (priv->recompute_idle)
2630 g_source_remove (priv->recompute_idle);
2632 g_free (priv->placeholder_text);
2633 g_free (priv->im_module);
2635 G_OBJECT_CLASS (gtk_entry_parent_class)->finalize (object);
2639 gtk_entry_get_display_mode (GtkEntry *entry)
2641 GtkEntryPrivate *priv = entry->priv;
2644 return DISPLAY_NORMAL;
2646 if (priv->invisible_char == 0 && priv->invisible_char_set)
2647 return DISPLAY_BLANK;
2649 return DISPLAY_INVISIBLE;
2653 gtk_entry_get_display_text (GtkEntry *entry,
2657 GtkEntryPasswordHint *password_hint;
2658 GtkEntryPrivate *priv;
2659 gunichar invisible_char;
2670 text = gtk_entry_buffer_get_text (get_buffer (entry));
2671 length = gtk_entry_buffer_get_length (get_buffer (entry));
2675 if (start_pos > length)
2678 if (end_pos <= start_pos)
2679 return g_strdup ("");
2680 else if (priv->visible)
2682 start = g_utf8_offset_to_pointer (text, start_pos);
2683 end = g_utf8_offset_to_pointer (start, end_pos - start_pos);
2684 return g_strndup (start, end - start);
2688 str = g_string_sized_new (length * 2);
2690 /* Figure out what our invisible char is and encode it */
2691 if (!priv->invisible_char)
2692 invisible_char = priv->invisible_char_set ? ' ' : '*';
2694 invisible_char = priv->invisible_char;
2695 char_len = g_unichar_to_utf8 (invisible_char, char_str);
2698 * Add hidden characters for each character in the text
2699 * buffer. If there is a password hint, then keep that
2700 * character visible.
2703 password_hint = g_object_get_qdata (G_OBJECT (entry), quark_password_hint);
2704 for (i = start_pos; i < end_pos; ++i)
2706 if (password_hint && i == password_hint->position)
2708 start = g_utf8_offset_to_pointer (text, i);
2709 g_string_append_len (str, start, g_utf8_next_char (start) - start);
2713 g_string_append_len (str, char_str, char_len);
2717 return g_string_free (str, FALSE);
2722 update_cursors (GtkWidget *widget)
2724 GtkEntry *entry = GTK_ENTRY (widget);
2725 GtkEntryPrivate *priv = entry->priv;
2726 EntryIconInfo *icon_info = NULL;
2727 GdkDisplay *display;
2731 for (i = 0; i < MAX_ICONS; i++)
2733 if ((icon_info = priv->icons[i]) != NULL)
2735 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
2736 gdk_window_show_unraised (icon_info->window);
2738 /* The icon windows are not children of the visible entry window,
2739 * thus we can't just inherit the xterm cursor. Slight complication
2740 * here is that for the entry, insensitive => arrow cursor, but for
2741 * an icon in a sensitive entry, insensitive => xterm cursor.
2743 if (gtk_widget_is_sensitive (widget) &&
2744 (icon_info->insensitive ||
2745 (icon_info->nonactivatable && icon_info->target_list == NULL)))
2747 display = gtk_widget_get_display (widget);
2748 cursor = gdk_cursor_new_for_display (display, GDK_XTERM);
2749 gdk_window_set_cursor (icon_info->window, cursor);
2750 g_object_unref (cursor);
2754 gdk_window_set_cursor (icon_info->window, NULL);
2761 realize_icon_info (GtkWidget *widget,
2762 GtkEntryIconPosition icon_pos)
2764 GtkEntry *entry = GTK_ENTRY (widget);
2765 GtkEntryPrivate *priv = entry->priv;
2766 EntryIconInfo *icon_info = priv->icons[icon_pos];
2767 GdkWindowAttr attributes;
2768 gint attributes_mask;
2770 g_return_if_fail (icon_info != NULL);
2774 attributes.width = 1;
2775 attributes.height = 1;
2776 attributes.window_type = GDK_WINDOW_CHILD;
2777 attributes.wclass = GDK_INPUT_ONLY;
2778 attributes.event_mask = gtk_widget_get_events (widget);
2779 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
2780 GDK_BUTTON_RELEASE_MASK |
2781 GDK_BUTTON1_MOTION_MASK |
2782 GDK_BUTTON3_MOTION_MASK |
2783 GDK_POINTER_MOTION_HINT_MASK |
2784 GDK_POINTER_MOTION_MASK |
2785 GDK_ENTER_NOTIFY_MASK |
2786 GDK_LEAVE_NOTIFY_MASK);
2787 attributes_mask = GDK_WA_X | GDK_WA_Y;
2789 icon_info->window = gdk_window_new (gtk_widget_get_window (widget),
2792 gdk_window_set_user_data (icon_info->window, widget);
2794 gtk_widget_queue_resize (widget);
2797 static EntryIconInfo*
2798 construct_icon_info (GtkWidget *widget,
2799 GtkEntryIconPosition icon_pos)
2801 GtkEntry *entry = GTK_ENTRY (widget);
2802 GtkEntryPrivate *priv = entry->priv;
2803 EntryIconInfo *icon_info;
2805 g_return_val_if_fail (priv->icons[icon_pos] == NULL, NULL);
2807 icon_info = g_slice_new0 (EntryIconInfo);
2808 priv->icons[icon_pos] = icon_info;
2810 if (gtk_widget_get_realized (widget))
2811 realize_icon_info (widget, icon_pos);
2817 gtk_entry_map (GtkWidget *widget)
2819 GtkEntry *entry = GTK_ENTRY (widget);
2820 GtkEntryPrivate *priv = entry->priv;
2821 EntryIconInfo *icon_info = NULL;
2824 GTK_WIDGET_CLASS (gtk_entry_parent_class)->map (widget);
2826 gdk_window_show (priv->text_area);
2828 for (i = 0; i < MAX_ICONS; i++)
2830 if ((icon_info = priv->icons[i]) != NULL)
2832 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
2833 gdk_window_show (icon_info->window);
2837 update_cursors (widget);
2841 gtk_entry_unmap (GtkWidget *widget)
2843 GtkEntry *entry = GTK_ENTRY (widget);
2844 GtkEntryPrivate *priv = entry->priv;
2845 EntryIconInfo *icon_info = NULL;
2848 for (i = 0; i < MAX_ICONS; i++)
2850 if ((icon_info = priv->icons[i]) != NULL)
2852 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
2853 gdk_window_hide (icon_info->window);
2857 gdk_window_hide (priv->text_area);
2859 GTK_WIDGET_CLASS (gtk_entry_parent_class)->unmap (widget);
2863 gtk_entry_realize (GtkWidget *widget)
2866 GtkEntryPrivate *priv;
2867 EntryIconInfo *icon_info;
2869 GdkWindowAttr attributes;
2870 gint attributes_mask;
2871 gint frame_x, frame_y;
2874 gtk_widget_set_realized (widget, TRUE);
2875 window = gtk_widget_get_parent_window (widget);
2876 gtk_widget_set_window (widget, window);
2877 g_object_ref (window);
2879 entry = GTK_ENTRY (widget);
2882 attributes.window_type = GDK_WINDOW_CHILD;
2883 attributes.wclass = GDK_INPUT_ONLY;
2884 attributes.event_mask = gtk_widget_get_events (widget);
2885 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
2886 GDK_BUTTON_RELEASE_MASK |
2887 GDK_BUTTON1_MOTION_MASK |
2888 GDK_BUTTON3_MOTION_MASK |
2889 GDK_POINTER_MOTION_HINT_MASK |
2890 GDK_POINTER_MOTION_MASK |
2891 GDK_ENTER_NOTIFY_MASK |
2892 GDK_LEAVE_NOTIFY_MASK);
2893 attributes_mask = GDK_WA_X | GDK_WA_Y;
2895 get_text_area_size (entry, &attributes.x, &attributes.y, &attributes.width, &attributes.height);
2897 get_frame_size (entry, &frame_x, &frame_y, NULL, NULL);
2898 attributes.x += frame_x;
2899 attributes.y += frame_y;
2901 if (gtk_widget_is_sensitive (widget))
2903 attributes.cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
2904 attributes_mask |= GDK_WA_CURSOR;
2907 priv->text_area = gdk_window_new (gtk_widget_get_window (widget),
2911 gdk_window_set_user_data (priv->text_area, entry);
2913 if (attributes_mask & GDK_WA_CURSOR)
2914 g_object_unref (attributes.cursor);
2916 gtk_im_context_set_client_window (priv->im_context, priv->text_area);
2918 gtk_entry_adjust_scroll (entry);
2919 gtk_entry_update_primary_selection (entry);
2922 /* If the icon positions are already setup, create their windows.
2923 * Otherwise if they don't exist yet, then construct_icon_info()
2924 * will create the windows once the widget is already realized.
2926 for (i = 0; i < MAX_ICONS; i++)
2928 if ((icon_info = priv->icons[i]) != NULL)
2930 if (icon_info->window == NULL)
2931 realize_icon_info (widget, i);
2937 gtk_entry_unrealize (GtkWidget *widget)
2939 GtkEntry *entry = GTK_ENTRY (widget);
2940 GtkEntryPrivate *priv = entry->priv;
2941 GtkClipboard *clipboard;
2942 EntryIconInfo *icon_info;
2945 gtk_entry_reset_layout (entry);
2947 gtk_im_context_set_client_window (priv->im_context, NULL);
2949 clipboard = gtk_widget_get_clipboard (widget, GDK_SELECTION_PRIMARY);
2950 if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (entry))
2951 gtk_clipboard_clear (clipboard);
2953 if (priv->text_area)
2955 gdk_window_set_user_data (priv->text_area, NULL);
2956 gdk_window_destroy (priv->text_area);
2957 priv->text_area = NULL;
2960 if (priv->popup_menu)
2962 gtk_widget_destroy (priv->popup_menu);
2963 priv->popup_menu = NULL;
2966 GTK_WIDGET_CLASS (gtk_entry_parent_class)->unrealize (widget);
2968 for (i = 0; i < MAX_ICONS; i++)
2970 if ((icon_info = priv->icons[i]) != NULL)
2972 if (icon_info->window != NULL)
2974 gdk_window_destroy (icon_info->window);
2975 icon_info->window = NULL;
2982 _gtk_entry_get_borders (GtkEntry *entry,
2986 GtkEntryPrivate *priv = entry->priv;
2987 GtkWidget *widget = GTK_WIDGET (entry);
2989 if (priv->has_frame)
2991 GtkStyleContext *context;
2994 context = gtk_widget_get_style_context (widget);
2995 gtk_style_context_get_padding (context, 0, &padding);
2997 *xborder = padding.left;
2998 *yborder = padding.top;
3006 if (!priv->interior_focus)
3008 *xborder += priv->focus_width;
3009 *yborder += priv->focus_width;
3014 gtk_entry_get_preferred_width (GtkWidget *widget,
3018 GtkEntry *entry = GTK_ENTRY (widget);
3019 GtkEntryPrivate *priv = entry->priv;
3020 PangoFontMetrics *metrics;
3021 gint xborder, yborder;
3022 GtkBorder inner_border;
3023 PangoContext *context;
3024 GtkStyleContext *style_context;
3025 GtkStateFlags state;
3026 gint icon_widths = 0;
3030 context = gtk_widget_get_pango_context (widget);
3032 style_context = gtk_widget_get_style_context (widget);
3033 state = gtk_widget_get_state_flags (widget);
3035 metrics = pango_context_get_metrics (context,
3036 gtk_style_context_get_font (style_context, state),
3037 pango_context_get_language (context));
3039 _gtk_entry_get_borders (entry, &xborder, &yborder);
3040 _gtk_entry_effective_inner_border (entry, &inner_border);
3042 if (priv->width_chars < 0)
3043 width = MIN_ENTRY_WIDTH + xborder * 2 + inner_border.left + inner_border.right;
3046 gint char_width = pango_font_metrics_get_approximate_char_width (metrics);
3047 gint digit_width = pango_font_metrics_get_approximate_digit_width (metrics);
3048 gint char_pixels = (MAX (char_width, digit_width) + PANGO_SCALE - 1) / PANGO_SCALE;
3050 width = char_pixels * priv->width_chars + xborder * 2 + inner_border.left + inner_border.right;
3053 for (i = 0; i < MAX_ICONS; i++)
3055 icon_width = get_icon_width (entry, i);
3057 icon_widths += icon_width + 2 * priv->icon_margin;
3060 if (icon_widths > width)
3061 width += icon_widths;
3063 pango_font_metrics_unref (metrics);
3070 gtk_entry_get_preferred_height (GtkWidget *widget,
3074 GtkEntry *entry = GTK_ENTRY (widget);
3075 GtkEntryPrivate *priv = entry->priv;
3076 PangoFontMetrics *metrics;
3077 gint xborder, yborder;
3078 GtkBorder inner_border;
3079 GtkStyleContext *style_context;
3080 GtkStateFlags state;
3081 PangoContext *context;
3084 context = gtk_widget_get_pango_context (widget);
3086 style_context = gtk_widget_get_style_context (widget);
3087 state = gtk_widget_get_state_flags (widget);
3089 metrics = pango_context_get_metrics (context,
3090 gtk_style_context_get_font (style_context, state),
3091 pango_context_get_language (context));
3093 priv->ascent = pango_font_metrics_get_ascent (metrics);
3094 priv->descent = pango_font_metrics_get_descent (metrics);
3096 _gtk_entry_get_borders (entry, &xborder, &yborder);
3097 _gtk_entry_effective_inner_border (entry, &inner_border);
3099 height = PANGO_PIXELS (priv->ascent + priv->descent) + yborder * 2 + inner_border.top + inner_border.bottom;
3101 pango_font_metrics_unref (metrics);
3108 place_windows (GtkEntry *entry)
3110 GtkWidget *widget = GTK_WIDGET (entry);
3111 GtkEntryPrivate *priv = entry->priv;
3112 gint x, y, width, height;
3113 gint frame_x, frame_y;
3114 GtkAllocation primary;
3115 GtkAllocation secondary;
3116 EntryIconInfo *icon_info = NULL;
3118 get_frame_size (entry, &frame_x, &frame_y, NULL, NULL);
3119 get_text_area_size (entry, &x, &y, &width, &height);
3120 get_icon_allocations (entry, &primary, &secondary);
3122 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3123 y += priv->focus_width;
3125 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
3126 x += secondary.width;
3129 width -= primary.width + secondary.width;
3133 primary.x += frame_x;
3134 primary.y += frame_y;
3135 secondary.x += frame_x;
3136 secondary.y += frame_y;
3138 if ((icon_info = priv->icons[GTK_ENTRY_ICON_PRIMARY]) != NULL)
3139 gdk_window_move_resize (icon_info->window,
3140 primary.x, primary.y,
3141 primary.width, primary.height);
3143 if ((icon_info = priv->icons[GTK_ENTRY_ICON_SECONDARY]) != NULL)
3144 gdk_window_move_resize (icon_info->window,
3145 secondary.x, secondary.y,
3146 secondary.width, secondary.height);
3148 gdk_window_move_resize (priv->text_area, x, y, width, height);
3152 gtk_entry_get_text_area_size (GtkEntry *entry,
3158 GtkEntryPrivate *priv = entry->priv;
3159 GtkWidget *widget = GTK_WIDGET (entry);
3160 GtkAllocation allocation;
3161 GtkRequisition requisition;
3163 gint xborder, yborder;
3165 gtk_widget_get_preferred_size (widget, &requisition, NULL);
3166 gtk_widget_get_allocation (widget, &allocation);
3167 _gtk_entry_get_borders (entry, &xborder, &yborder);
3169 if (gtk_widget_get_realized (widget))
3170 get_frame_size (entry, NULL, NULL, NULL, &frame_height);
3172 frame_height = requisition.height;
3174 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3175 frame_height -= 2 * priv->focus_width;
3181 *y = frame_height / 2 - (requisition.height - yborder * 2) / 2;
3184 *width = allocation.width - xborder * 2;
3187 *height = requisition.height - yborder * 2;
3191 get_text_area_size (GtkEntry *entry,
3197 GtkEntryClass *class;
3199 g_return_if_fail (GTK_IS_ENTRY (entry));
3201 class = GTK_ENTRY_GET_CLASS (entry);
3203 if (class->get_text_area_size)
3204 class->get_text_area_size (entry, x, y, width, height);
3209 get_frame_size (GtkEntry *entry,
3215 GtkEntryPrivate *priv = entry->priv;
3216 GtkAllocation allocation;
3217 GtkRequisition requisition;
3218 GtkWidget *widget = GTK_WIDGET (entry);
3220 gtk_widget_get_preferred_size (widget, &requisition, NULL);
3221 gtk_widget_get_allocation (widget, &allocation);
3228 if (priv->is_cell_renderer)
3231 *y = allocation.y + (allocation.height - requisition.height) / 2;
3235 *width = allocation.width;
3239 if (priv->is_cell_renderer)
3240 *height = allocation.height;
3242 *height = requisition.height;
3247 _gtk_entry_effective_inner_border (GtkEntry *entry,
3250 GtkBorder *tmp_border;
3252 tmp_border = g_object_get_qdata (G_OBJECT (entry), quark_inner_border);
3256 *border = *tmp_border;
3260 gtk_widget_style_get (GTK_WIDGET (entry), "inner-border", &tmp_border, NULL);
3264 *border = *tmp_border;
3265 gtk_border_free (tmp_border);
3269 *border = default_inner_border;
3273 gtk_entry_size_allocate (GtkWidget *widget,
3274 GtkAllocation *allocation)
3276 GtkEntry *entry = GTK_ENTRY (widget);
3278 gtk_widget_set_allocation (widget, allocation);
3280 if (gtk_widget_get_realized (widget))
3282 GtkEntryCompletion* completion;
3284 place_windows (entry);
3285 gtk_entry_recompute (entry);
3287 completion = gtk_entry_get_completion (entry);
3288 if (completion && gtk_widget_get_mapped (completion->priv->popup_window))
3289 _gtk_entry_completion_resize_popup (completion);
3294 should_prelight (GtkEntry *entry,
3295 GtkEntryIconPosition icon_pos)
3297 GtkEntryPrivate *priv = entry->priv;
3298 EntryIconInfo *icon_info = priv->icons[icon_pos];
3304 if (icon_info->nonactivatable && icon_info->target_list == NULL)
3307 if (icon_info->pressed)
3310 gtk_widget_style_get (GTK_WIDGET (entry),
3311 "icon-prelight", &prelight,
3318 draw_icon (GtkWidget *widget,
3320 GtkEntryIconPosition icon_pos)
3322 GtkEntry *entry = GTK_ENTRY (widget);
3323 GtkEntryPrivate *priv = entry->priv;
3324 EntryIconInfo *icon_info = priv->icons[icon_pos];
3326 gint x, y, width, height;
3327 GtkStyleContext *context;
3328 GtkIconSource *icon_source;
3329 GtkStateFlags state;
3334 gtk_entry_ensure_pixbuf (entry, icon_pos);
3336 if (icon_info->pixbuf == NULL)
3339 width = gdk_window_get_width (icon_info->window);
3340 height = gdk_window_get_height (icon_info->window);
3342 /* size_allocate hasn't been called yet. These are the default values.
3344 if (width == 1 || height == 1)
3347 pixbuf = icon_info->pixbuf;
3348 g_object_ref (pixbuf);
3350 if (gdk_pixbuf_get_height (pixbuf) > height)
3352 GdkPixbuf *temp_pixbuf;
3355 scale = height - 2 * priv->icon_margin;
3356 temp_pixbuf = gdk_pixbuf_scale_simple (pixbuf, scale, scale,
3357 GDK_INTERP_BILINEAR);
3358 g_object_unref (pixbuf);
3359 pixbuf = temp_pixbuf;
3362 x = (width - gdk_pixbuf_get_width (pixbuf)) / 2;
3363 y = (height - gdk_pixbuf_get_height (pixbuf)) / 2;
3365 icon_source = gtk_icon_source_new ();
3366 gtk_icon_source_set_pixbuf (icon_source, pixbuf);
3367 gtk_icon_source_set_state_wildcarded (icon_source, TRUE);
3370 if (!gtk_widget_is_sensitive (widget) || icon_info->insensitive)
3371 state |= GTK_STATE_FLAG_INSENSITIVE;
3372 else if (icon_info->prelight)
3373 state |= GTK_STATE_FLAG_PRELIGHT;
3375 context = gtk_widget_get_style_context (widget);
3376 gtk_style_context_save (context);
3377 gtk_style_context_set_state (context, state);
3378 pixbuf = gtk_render_icon_pixbuf (context, icon_source, (GtkIconSize)-1);
3379 gtk_style_context_restore (context);
3381 gtk_icon_source_free (icon_source);
3383 gdk_cairo_set_source_pixbuf (cr, pixbuf, x, y);
3386 g_object_unref (pixbuf);
3391 gtk_entry_draw_frame (GtkWidget *widget,
3392 GtkStyleContext *context,
3395 GtkEntry *entry = GTK_ENTRY (widget);
3396 GtkEntryPrivate *priv = entry->priv;
3397 gint x = 0, y = 0, width, height;
3398 GtkAllocation allocation;
3399 gint frame_x, frame_y;
3403 get_frame_size (GTK_ENTRY (widget), &frame_x, &frame_y, &width, &height);
3404 gtk_widget_get_allocation (widget, &allocation);
3406 cairo_translate (cr, frame_x - allocation.x, frame_y - allocation.y);
3408 /* Fix a problem with some themes which assume that entry->text_area's
3409 * width equals widget->window's width
3410 * http://bugzilla.gnome.org/show_bug.cgi?id=466000 */
3411 if (GTK_IS_SPIN_BUTTON (widget))
3413 gint xborder, yborder;
3415 gtk_entry_get_text_area_size (GTK_ENTRY (widget), &x, NULL, &width, NULL);
3416 _gtk_entry_get_borders (GTK_ENTRY (widget), &xborder, &yborder);
3419 width += xborder * 2;
3422 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3424 x += priv->focus_width;
3425 y += priv->focus_width;
3426 width -= 2 * priv->focus_width;
3427 height -= 2 * priv->focus_width;
3430 gtk_render_background (context, cr,
3431 x, y, width, height);
3433 if (priv->has_frame)
3434 gtk_render_frame (context, cr,
3435 x, y, width, height);
3437 gtk_entry_draw_progress (widget, context, cr);
3439 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3441 x -= priv->focus_width;
3442 y -= priv->focus_width;
3443 width += 2 * priv->focus_width;
3444 height += 2 * priv->focus_width;
3446 gtk_render_focus (context, cr,
3447 0, 0, width, height);
3454 get_progress_area (GtkWidget *widget,
3460 GtkEntry *entry = GTK_ENTRY (widget);
3461 GtkEntryPrivate *private = entry->priv;
3462 GtkBorder *progress_border;
3464 get_text_area_size (entry, x, y, width, height);
3466 if (!private->interior_focus)
3468 *x -= private->focus_width;
3469 *y -= private->focus_width;
3470 *width += 2 * private->focus_width;
3471 *height += 2 * private->focus_width;
3474 gtk_widget_style_get (widget, "progress-border", &progress_border, NULL);
3476 if (progress_border)
3478 *x += progress_border->left;
3479 *y += progress_border->top;
3480 *width -= progress_border->left + progress_border->right;
3481 *height -= progress_border->top + progress_border->bottom;
3483 gtk_border_free (progress_border);
3486 if (private->progress_pulse_mode)
3488 gdouble value = private->progress_pulse_current;
3490 *x += (gint) floor(value * (*width));
3491 *width = (gint) ceil(private->progress_pulse_fraction * (*width));
3493 else if (private->progress_fraction > 0)
3495 gdouble value = private->progress_fraction;
3497 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
3501 bar_width = floor(value * (*width) + 0.5);
3502 *x += *width - bar_width;
3507 *width = (gint) floor(value * (*width) + 0.5);
3518 gtk_entry_draw_progress (GtkWidget *widget,
3519 GtkStyleContext *context,
3522 gint x, y, width, height;
3524 get_progress_area (widget, &x, &y, &width, &height);
3526 if ((width <= 0) || (height <= 0))
3529 gtk_style_context_save (context);
3530 gtk_style_context_add_class (context, GTK_STYLE_CLASS_PROGRESSBAR);
3532 gtk_render_activity (context, cr,
3533 x, y, width, height);
3535 gtk_style_context_restore (context);
3539 gtk_entry_draw (GtkWidget *widget,
3542 GtkEntry *entry = GTK_ENTRY (widget);
3543 GtkStyleContext *context;
3544 GtkStateFlags state;
3545 GtkEntryPrivate *priv = entry->priv;
3548 context = gtk_widget_get_style_context (widget);
3549 state = gtk_widget_get_state_flags (widget);
3551 gtk_style_context_save (context);
3552 gtk_style_context_set_state (context, state);
3554 if (gtk_cairo_should_draw_window (cr, gtk_widget_get_window (widget)))
3556 /* Draw entry_bg, shadow, progress and focus */
3557 gtk_entry_draw_frame (widget, context, cr);
3559 /* Draw text and cursor */
3562 gtk_cairo_transform_to_window (cr, widget, priv->text_area);
3564 if (priv->dnd_position != -1)
3565 gtk_entry_draw_cursor (GTK_ENTRY (widget), cr, CURSOR_DND);
3567 gtk_entry_draw_text (GTK_ENTRY (widget), cr);
3569 /* When no text is being displayed at all, don't show the cursor */
3570 if (gtk_entry_get_display_mode (entry) != DISPLAY_BLANK &&
3571 gtk_widget_has_focus (widget) &&
3572 priv->selection_bound == priv->current_pos && priv->cursor_visible)
3573 gtk_entry_draw_cursor (GTK_ENTRY (widget), cr, CURSOR_STANDARD);
3578 for (i = 0; i < MAX_ICONS; i++)
3580 EntryIconInfo *icon_info = priv->icons[i];
3582 if (icon_info != NULL)
3586 gtk_cairo_transform_to_window (cr, widget, icon_info->window);
3588 draw_icon (widget, cr, i);
3595 gtk_style_context_restore (context);
3601 gtk_entry_enter_notify (GtkWidget *widget,
3602 GdkEventCrossing *event)
3604 GtkEntry *entry = GTK_ENTRY (widget);
3605 GtkEntryPrivate *priv = entry->priv;
3608 for (i = 0; i < MAX_ICONS; i++)
3610 EntryIconInfo *icon_info = priv->icons[i];
3612 if (icon_info != NULL && event->window == icon_info->window)
3614 if (should_prelight (entry, i))
3616 icon_info->prelight = TRUE;
3617 gtk_widget_queue_draw (widget);
3628 gtk_entry_leave_notify (GtkWidget *widget,
3629 GdkEventCrossing *event)
3631 GtkEntry *entry = GTK_ENTRY (widget);
3632 GtkEntryPrivate *priv = entry->priv;
3635 for (i = 0; i < MAX_ICONS; i++)
3637 EntryIconInfo *icon_info = priv->icons[i];
3639 if (icon_info != NULL && event->window == icon_info->window)
3641 /* a grab means that we may never see the button release */
3642 if (event->mode == GDK_CROSSING_GRAB || event->mode == GDK_CROSSING_GTK_GRAB)
3643 icon_info->pressed = FALSE;
3645 if (should_prelight (entry, i))
3647 icon_info->prelight = FALSE;
3648 gtk_widget_queue_draw (widget);
3659 gtk_entry_get_pixel_ranges (GtkEntry *entry,
3663 gint start_char, end_char;
3665 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start_char, &end_char))
3667 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
3668 PangoLayoutLine *line = pango_layout_get_lines_readonly (layout)->data;
3669 const char *text = pango_layout_get_text (layout);
3670 gint start_index = g_utf8_offset_to_pointer (text, start_char) - text;
3671 gint end_index = g_utf8_offset_to_pointer (text, end_char) - text;
3672 gint real_n_ranges, i;
3674 pango_layout_line_get_x_ranges (line, start_index, end_index, ranges, &real_n_ranges);
3680 for (i = 0; i < real_n_ranges; ++i)
3682 r[2 * i + 1] = (r[2 * i + 1] - r[2 * i]) / PANGO_SCALE;
3683 r[2 * i] = r[2 * i] / PANGO_SCALE;
3688 *n_ranges = real_n_ranges;
3700 in_selection (GtkEntry *entry,
3705 gint retval = FALSE;
3707 gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
3709 for (i = 0; i < n_ranges; ++i)
3711 if (x >= ranges[2 * i] && x < ranges[2 * i] + ranges[2 * i + 1])
3723 gtk_entry_button_press (GtkWidget *widget,
3724 GdkEventButton *event)
3726 GtkEntry *entry = GTK_ENTRY (widget);
3727 GtkEditable *editable = GTK_EDITABLE (widget);
3728 GtkEntryPrivate *priv = entry->priv;
3729 EntryIconInfo *icon_info = NULL;
3731 gint sel_start, sel_end;
3734 for (i = 0; i < MAX_ICONS; i++)
3736 icon_info = priv->icons[i];
3738 if (!icon_info || icon_info->insensitive)
3741 if (event->window == icon_info->window)
3743 if (should_prelight (entry, i))
3745 icon_info->prelight = FALSE;
3746 gtk_widget_queue_draw (widget);
3749 priv->start_x = event->x;
3750 priv->start_y = event->y;
3751 icon_info->pressed = TRUE;
3753 if (!icon_info->nonactivatable)
3754 g_signal_emit (entry, signals[ICON_PRESS], 0, i, event);
3760 if (event->window != priv->text_area ||
3761 (priv->button && event->button != priv->button))
3764 gtk_entry_reset_blink_time (entry);
3766 priv->button = event->button;
3768 if (!gtk_widget_has_focus (widget))
3770 priv->in_click = TRUE;
3771 gtk_widget_grab_focus (widget);
3772 priv->in_click = FALSE;
3775 tmp_pos = gtk_entry_find_position (entry, event->x + priv->scroll_offset);
3777 if (event->button == 1)
3779 gboolean have_selection = gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end);
3781 priv->select_words = FALSE;
3782 priv->select_lines = FALSE;
3784 if (event->state & GDK_SHIFT_MASK)
3786 _gtk_entry_reset_im_context (entry);
3788 if (!have_selection) /* select from the current position to the clicked position */
3789 sel_start = sel_end = priv->current_pos;
3791 if (tmp_pos > sel_start && tmp_pos < sel_end)
3793 /* Truncate current selection, but keep it as big as possible */
3794 if (tmp_pos - sel_start > sel_end - tmp_pos)
3795 gtk_entry_set_positions (entry, sel_start, tmp_pos);
3797 gtk_entry_set_positions (entry, tmp_pos, sel_end);
3801 gboolean extend_to_left;
3804 /* Figure out what click selects and extend current selection */
3805 switch (event->type)
3807 case GDK_BUTTON_PRESS:
3808 gtk_entry_set_positions (entry, tmp_pos, tmp_pos);
3811 case GDK_2BUTTON_PRESS:
3812 priv->select_words = TRUE;
3813 gtk_entry_select_word (entry);
3816 case GDK_3BUTTON_PRESS:
3817 priv->select_lines = TRUE;
3818 gtk_entry_select_line (entry);
3825 start = MIN (priv->current_pos, priv->selection_bound);
3826 start = MIN (sel_start, start);
3828 end = MAX (priv->current_pos, priv->selection_bound);
3829 end = MAX (sel_end, end);
3831 if (tmp_pos == sel_start || tmp_pos == sel_end)
3832 extend_to_left = (tmp_pos == start);
3834 extend_to_left = (end == sel_end);
3837 gtk_entry_set_positions (entry, start, end);
3839 gtk_entry_set_positions (entry, end, start);
3842 else /* no shift key */
3843 switch (event->type)
3845 case GDK_BUTTON_PRESS:
3846 if (in_selection (entry, event->x + priv->scroll_offset))
3848 /* Click inside the selection - we'll either start a drag, or
3849 * clear the selection
3851 priv->in_drag = TRUE;
3852 priv->drag_start_x = event->x + priv->scroll_offset;
3853 priv->drag_start_y = event->y;
3856 gtk_editable_set_position (editable, tmp_pos);
3859 case GDK_2BUTTON_PRESS:
3860 /* We ALWAYS receive a GDK_BUTTON_PRESS immediately before
3861 * receiving a GDK_2BUTTON_PRESS so we need to reset
3862 * priv->in_drag which may have been set above
3864 priv->in_drag = FALSE;
3865 priv->select_words = TRUE;
3866 gtk_entry_select_word (entry);
3869 case GDK_3BUTTON_PRESS:
3870 /* We ALWAYS receive a GDK_BUTTON_PRESS immediately before
3871 * receiving a GDK_3BUTTON_PRESS so we need to reset
3872 * priv->in_drag which may have been set above
3874 priv->in_drag = FALSE;
3875 priv->select_lines = TRUE;
3876 gtk_entry_select_line (entry);
3885 else if (event->button == 2 && event->type == GDK_BUTTON_PRESS)
3889 priv->insert_pos = tmp_pos;
3890 gtk_entry_paste (entry, GDK_SELECTION_PRIMARY);
3895 gtk_widget_error_bell (widget);
3898 else if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
3900 gtk_entry_do_popup (entry, event);
3901 priv->button = 0; /* Don't wait for release, since the menu will gtk_grab_add */
3910 gtk_entry_button_release (GtkWidget *widget,
3911 GdkEventButton *event)
3913 GtkEntry *entry = GTK_ENTRY (widget);
3914 GtkEntryPrivate *priv = entry->priv;
3915 EntryIconInfo *icon_info = NULL;
3918 for (i = 0; i < MAX_ICONS; i++)
3920 icon_info = priv->icons[i];
3922 if (!icon_info || icon_info->insensitive)
3925 if (event->window == icon_info->window)
3927 icon_info->pressed = FALSE;
3929 if (should_prelight (entry, i) &&
3930 event->x >= 0 && event->y >= 0 &&
3931 event->x < gdk_window_get_width (icon_info->window) &&
3932 event->y < gdk_window_get_height (icon_info->window))
3934 icon_info->prelight = TRUE;
3935 gtk_widget_queue_draw (widget);
3938 if (!icon_info->nonactivatable)
3939 g_signal_emit (entry, signals[ICON_RELEASE], 0, i, event);
3945 if (event->window != priv->text_area || priv->button != event->button)
3950 gint tmp_pos = gtk_entry_find_position (entry, priv->drag_start_x);
3952 gtk_editable_set_position (GTK_EDITABLE (entry), tmp_pos);
3959 gtk_entry_update_primary_selection (entry);
3965 _gtk_entry_get_selected_text (GtkEntry *entry)
3967 GtkEditable *editable = GTK_EDITABLE (entry);
3968 gint start_text, end_text;
3971 if (gtk_editable_get_selection_bounds (editable, &start_text, &end_text))
3972 text = gtk_editable_get_chars (editable, start_text, end_text);
3978 gtk_entry_motion_notify (GtkWidget *widget,
3979 GdkEventMotion *event)
3981 GtkEntry *entry = GTK_ENTRY (widget);
3982 GtkEntryPrivate *priv = entry->priv;
3983 EntryIconInfo *icon_info = NULL;
3987 for (i = 0; i < MAX_ICONS; i++)
3989 icon_info = priv->icons[i];
3991 if (!icon_info || icon_info->insensitive)
3994 if (event->window == icon_info->window)
3996 if (icon_info->pressed &&
3997 icon_info->target_list != NULL &&
3998 gtk_drag_check_threshold (widget,
4004 icon_info->in_drag = TRUE;
4005 icon_info->pressed = FALSE;
4006 gtk_drag_begin (widget,
4007 icon_info->target_list,
4017 if (priv->mouse_cursor_obscured)
4021 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
4022 gdk_window_set_cursor (priv->text_area, cursor);
4023 g_object_unref (cursor);
4024 priv->mouse_cursor_obscured = FALSE;
4027 if (event->window != priv->text_area || priv->button != 1)
4030 if (priv->select_lines)
4033 gdk_event_request_motions (event);
4037 if (gtk_entry_get_display_mode (entry) == DISPLAY_NORMAL &&
4038 gtk_drag_check_threshold (widget,
4039 priv->drag_start_x, priv->drag_start_y,
4040 event->x + priv->scroll_offset, event->y))
4042 GdkDragContext *context;
4043 GtkTargetList *target_list = gtk_target_list_new (NULL, 0);
4044 guint actions = priv->editable ? GDK_ACTION_COPY | GDK_ACTION_MOVE : GDK_ACTION_COPY;
4046 cairo_surface_t *surface;
4048 gtk_target_list_add_text_targets (target_list, 0);
4050 text = _gtk_entry_get_selected_text (entry);
4051 surface = _gtk_text_util_create_drag_icon (widget, text, -1);
4053 context = gtk_drag_begin (widget, target_list, actions,
4054 priv->button, (GdkEvent *)event);
4057 gtk_drag_set_icon_surface (context, surface);
4059 gtk_drag_set_icon_default (context);
4062 cairo_surface_destroy (surface);
4065 priv->in_drag = FALSE;
4068 gtk_target_list_unref (target_list);
4075 else if (event->y >= gdk_window_get_height (priv->text_area))
4076 tmp_pos = gtk_entry_buffer_get_length (get_buffer (entry));
4078 tmp_pos = gtk_entry_find_position (entry, event->x + priv->scroll_offset);
4080 if (priv->select_words)
4083 gint old_min, old_max;
4086 min = gtk_entry_move_backward_word (entry, tmp_pos, TRUE);
4087 max = gtk_entry_move_forward_word (entry, tmp_pos, TRUE);
4089 pos = priv->current_pos;
4090 bound = priv->selection_bound;
4092 old_min = MIN(priv->current_pos, priv->selection_bound);
4093 old_max = MAX(priv->current_pos, priv->selection_bound);
4100 else if (old_max < max)
4105 else if (pos == old_min)
4107 if (priv->current_pos != min)
4112 if (priv->current_pos != max)
4116 gtk_entry_set_positions (entry, pos, bound);
4119 gtk_entry_set_positions (entry, tmp_pos, -1);
4126 set_invisible_cursor (GdkWindow *window)
4128 GdkDisplay *display;
4131 display = gdk_window_get_display (window);
4132 cursor = gdk_cursor_new_for_display (display, GDK_BLANK_CURSOR);
4134 gdk_window_set_cursor (window, cursor);
4136 g_object_unref (cursor);
4140 gtk_entry_obscure_mouse_cursor (GtkEntry *entry)
4142 GtkEntryPrivate *priv = entry->priv;
4144 if (priv->mouse_cursor_obscured)
4147 set_invisible_cursor (priv->text_area);
4149 priv->mouse_cursor_obscured = TRUE;
4153 gtk_entry_key_press (GtkWidget *widget,
4156 GtkEntry *entry = GTK_ENTRY (widget);
4157 GtkEntryPrivate *priv = entry->priv;
4159 gtk_entry_reset_blink_time (entry);
4160 gtk_entry_pend_cursor_blink (entry);
4164 if (gtk_im_context_filter_keypress (priv->im_context, event))
4166 gtk_entry_obscure_mouse_cursor (entry);
4167 priv->need_im_reset = TRUE;
4172 if (event->keyval == GDK_KEY_Return ||
4173 event->keyval == GDK_KEY_KP_Enter ||
4174 event->keyval == GDK_KEY_ISO_Enter ||
4175 event->keyval == GDK_KEY_Escape)
4177 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
4179 if (completion && completion->priv->completion_timeout)
4181 g_source_remove (completion->priv->completion_timeout);
4182 completion->priv->completion_timeout = 0;
4185 _gtk_entry_reset_im_context (entry);
4188 if (GTK_WIDGET_CLASS (gtk_entry_parent_class)->key_press_event (widget, event))
4189 /* Activate key bindings
4193 if (!priv->editable && event->length)
4194 gtk_widget_error_bell (widget);
4200 gtk_entry_key_release (GtkWidget *widget,
4203 GtkEntry *entry = GTK_ENTRY (widget);
4204 GtkEntryPrivate *priv = entry->priv;
4208 if (gtk_im_context_filter_keypress (priv->im_context, event))
4210 priv->need_im_reset = TRUE;
4215 return GTK_WIDGET_CLASS (gtk_entry_parent_class)->key_release_event (widget, event);
4219 gtk_entry_focus_in (GtkWidget *widget,
4220 GdkEventFocus *event)
4222 GtkEntry *entry = GTK_ENTRY (widget);
4223 GtkEntryPrivate *priv = entry->priv;
4226 gtk_widget_queue_draw (widget);
4228 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (widget));
4232 priv->need_im_reset = TRUE;
4233 gtk_im_context_focus_in (priv->im_context);
4234 keymap_state_changed (keymap, entry);
4235 g_signal_connect (keymap, "state-changed",
4236 G_CALLBACK (keymap_state_changed), entry);
4239 g_signal_connect (keymap, "direction-changed",
4240 G_CALLBACK (keymap_direction_changed), entry);
4242 if (gtk_entry_buffer_get_bytes (get_buffer (entry)) == 0 &&
4243 priv->placeholder_text != NULL)
4245 gtk_entry_recompute (entry);
4249 gtk_entry_reset_blink_time (entry);
4250 gtk_entry_check_cursor_blink (entry);
4257 gtk_entry_focus_out (GtkWidget *widget,
4258 GdkEventFocus *event)
4260 GtkEntry *entry = GTK_ENTRY (widget);
4261 GtkEntryPrivate *priv = entry->priv;
4262 GtkEntryCompletion *completion;
4265 gtk_widget_queue_draw (widget);
4267 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (widget));
4271 priv->need_im_reset = TRUE;
4272 gtk_im_context_focus_out (priv->im_context);
4273 remove_capslock_feedback (entry);
4276 if (gtk_entry_buffer_get_bytes (get_buffer (entry)) == 0 &&
4277 priv->placeholder_text != NULL)
4279 gtk_entry_recompute (entry);
4283 gtk_entry_check_cursor_blink (entry);
4286 g_signal_handlers_disconnect_by_func (keymap, keymap_state_changed, entry);
4287 g_signal_handlers_disconnect_by_func (keymap, keymap_direction_changed, entry);
4289 completion = gtk_entry_get_completion (entry);
4291 _gtk_entry_completion_popdown (completion);
4297 gtk_entry_grab_focus (GtkWidget *widget)
4299 GtkEntry *entry = GTK_ENTRY (widget);
4300 GtkEntryPrivate *priv = entry->priv;
4301 gboolean select_on_focus;
4303 GTK_WIDGET_CLASS (gtk_entry_parent_class)->grab_focus (widget);
4305 if (priv->editable && !priv->in_click)
4307 g_object_get (gtk_widget_get_settings (widget),
4308 "gtk-entry-select-on-focus",
4312 if (select_on_focus)
4313 gtk_editable_select_region (GTK_EDITABLE (widget), 0, -1);
4318 gtk_entry_direction_changed (GtkWidget *widget,
4319 GtkTextDirection previous_dir)
4321 GtkEntry *entry = GTK_ENTRY (widget);
4323 gtk_entry_recompute (entry);
4325 GTK_WIDGET_CLASS (gtk_entry_parent_class)->direction_changed (widget, previous_dir);
4329 gtk_entry_state_flags_changed (GtkWidget *widget,
4330 GtkStateFlags previous_state)
4332 GtkEntry *entry = GTK_ENTRY (widget);
4333 GtkEntryPrivate *priv = entry->priv;
4336 if (gtk_widget_get_realized (widget))
4338 if (gtk_widget_is_sensitive (widget))
4339 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
4343 gdk_window_set_cursor (priv->text_area, cursor);
4346 g_object_unref (cursor);
4348 priv->mouse_cursor_obscured = FALSE;
4350 update_cursors (widget);
4353 if (!gtk_widget_is_sensitive (widget))
4355 /* Clear any selection */
4356 gtk_editable_select_region (GTK_EDITABLE (entry), priv->current_pos, priv->current_pos);
4359 gtk_widget_queue_draw (widget);
4363 gtk_entry_screen_changed (GtkWidget *widget,
4364 GdkScreen *old_screen)
4366 gtk_entry_recompute (GTK_ENTRY (widget));
4369 /* GtkEditable method implementations
4372 gtk_entry_insert_text (GtkEditable *editable,
4373 const gchar *new_text,
4374 gint new_text_length,
4377 g_object_ref (editable);
4380 * The incoming text may a password or other secret. We make sure
4381 * not to copy it into temporary buffers.
4384 g_signal_emit_by_name (editable, "insert-text", new_text, new_text_length, position);
4386 g_object_unref (editable);
4390 gtk_entry_delete_text (GtkEditable *editable,
4394 g_object_ref (editable);
4396 g_signal_emit_by_name (editable, "delete-text", start_pos, end_pos);
4398 g_object_unref (editable);
4402 gtk_entry_get_chars (GtkEditable *editable,
4406 GtkEntry *entry = GTK_ENTRY (editable);
4409 gint start_index, end_index;
4411 text = gtk_entry_buffer_get_text (get_buffer (entry));
4412 text_length = gtk_entry_buffer_get_length (get_buffer (entry));
4415 end_pos = text_length;
4417 start_pos = MIN (text_length, start_pos);
4418 end_pos = MIN (text_length, end_pos);
4420 start_index = g_utf8_offset_to_pointer (text, start_pos) - text;
4421 end_index = g_utf8_offset_to_pointer (text, end_pos) - text;
4423 return g_strndup (text + start_index, end_index - start_index);
4427 gtk_entry_real_set_position (GtkEditable *editable,
4430 GtkEntry *entry = GTK_ENTRY (editable);
4431 GtkEntryPrivate *priv = entry->priv;
4435 length = gtk_entry_buffer_get_length (get_buffer (entry));
4436 if (position < 0 || position > length)
4439 if (position != priv->current_pos ||
4440 position != priv->selection_bound)
4442 _gtk_entry_reset_im_context (entry);
4443 gtk_entry_set_positions (entry, position, position);
4448 gtk_entry_get_position (GtkEditable *editable)
4450 GtkEntry *entry = GTK_ENTRY (editable);
4451 GtkEntryPrivate *priv = entry->priv;
4453 return priv->current_pos;
4457 gtk_entry_set_selection_bounds (GtkEditable *editable,
4461 GtkEntry *entry = GTK_ENTRY (editable);
4464 length = gtk_entry_buffer_get_length (get_buffer (entry));
4470 _gtk_entry_reset_im_context (entry);
4472 gtk_entry_set_positions (entry,
4474 MIN (start, length));
4476 gtk_entry_update_primary_selection (entry);
4480 gtk_entry_get_selection_bounds (GtkEditable *editable,
4484 GtkEntry *entry = GTK_ENTRY (editable);
4485 GtkEntryPrivate *priv = entry->priv;
4487 *start = priv->selection_bound;
4488 *end = priv->current_pos;
4490 return (priv->selection_bound != priv->current_pos);
4494 icon_theme_changed (GtkEntry *entry)
4496 GtkEntryPrivate *priv = entry->priv;
4499 for (i = 0; i < MAX_ICONS; i++)
4501 EntryIconInfo *icon_info = priv->icons[i];
4502 if (icon_info != NULL)
4504 if (icon_info->storage_type == GTK_IMAGE_ICON_NAME)
4505 gtk_entry_set_icon_from_icon_name (entry, i, icon_info->icon_name);
4506 else if (icon_info->storage_type == GTK_IMAGE_STOCK)
4507 gtk_entry_set_icon_from_stock (entry, i, icon_info->stock_id);
4508 else if (icon_info->storage_type == GTK_IMAGE_GICON)
4509 gtk_entry_set_icon_from_gicon (entry, i, icon_info->gicon);
4513 gtk_widget_queue_draw (GTK_WIDGET (entry));
4517 icon_margin_changed (GtkEntry *entry)
4519 GtkEntryPrivate *priv = entry->priv;
4522 _gtk_entry_effective_inner_border (GTK_ENTRY (entry), &border);
4524 priv->icon_margin = border.left;
4528 gtk_entry_style_updated (GtkWidget *widget)
4530 GtkEntry *entry = GTK_ENTRY (widget);
4531 GtkEntryPrivate *priv = entry->priv;
4533 gboolean interior_focus;
4535 GTK_WIDGET_CLASS (gtk_entry_parent_class)->style_updated (widget);
4537 gtk_widget_style_get (widget,
4538 "focus-line-width", &focus_width,
4539 "interior-focus", &interior_focus,
4542 priv->focus_width = focus_width;
4543 priv->interior_focus = interior_focus;
4545 if (!priv->invisible_char_set)
4546 priv->invisible_char = find_invisible_char (GTK_WIDGET (entry));
4548 gtk_entry_recompute (entry);
4550 icon_theme_changed (entry);
4551 icon_margin_changed (entry);
4554 /* GtkCellEditable method implementations
4557 gtk_cell_editable_entry_activated (GtkEntry *entry, gpointer data)
4559 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4560 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4564 gtk_cell_editable_key_press_event (GtkEntry *entry,
4565 GdkEventKey *key_event,
4568 GtkEntryPrivate *priv = entry->priv;
4570 if (key_event->keyval == GDK_KEY_Escape)
4572 priv->editing_canceled = TRUE;
4573 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4574 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4579 /* override focus */
4580 if (key_event->keyval == GDK_KEY_Up || key_event->keyval == GDK_KEY_Down)
4582 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4583 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4592 gtk_entry_start_editing (GtkCellEditable *cell_editable,
4595 GtkEntry *entry = GTK_ENTRY (cell_editable);
4596 GtkEntryPrivate *priv = entry->priv;
4598 priv->is_cell_renderer = TRUE;
4600 g_signal_connect (cell_editable, "activate",
4601 G_CALLBACK (gtk_cell_editable_entry_activated), NULL);
4602 g_signal_connect (cell_editable, "key-press-event",
4603 G_CALLBACK (gtk_cell_editable_key_press_event), NULL);
4607 gtk_entry_password_hint_free (GtkEntryPasswordHint *password_hint)
4609 if (password_hint->source_id)
4610 g_source_remove (password_hint->source_id);
4612 g_slice_free (GtkEntryPasswordHint, password_hint);
4617 gtk_entry_remove_password_hint (gpointer data)
4619 GtkEntryPasswordHint *password_hint = g_object_get_qdata (data, quark_password_hint);
4620 password_hint->position = -1;
4622 /* Force the string to be redrawn, but now without a visible character */
4623 gtk_entry_recompute (GTK_ENTRY (data));
4627 /* Default signal handlers
4630 gtk_entry_real_insert_text (GtkEditable *editable,
4631 const gchar *new_text,
4632 gint new_text_length,
4638 n_chars = g_utf8_strlen (new_text, new_text_length);
4641 * The actual insertion into the buffer. This will end up firing the
4642 * following signal handlers: buffer_inserted_text(), buffer_notify_display_text(),
4643 * buffer_notify_text(), buffer_notify_length()
4645 n_inserted = gtk_entry_buffer_insert_text (get_buffer (GTK_ENTRY (editable)), *position, new_text, n_chars);
4647 if (n_inserted != n_chars)
4648 gtk_widget_error_bell (GTK_WIDGET (editable));
4650 *position += n_inserted;
4654 gtk_entry_real_delete_text (GtkEditable *editable,
4659 * The actual deletion from the buffer. This will end up firing the
4660 * following signal handlers: buffer_deleted_text(), buffer_notify_display_text(),
4661 * buffer_notify_text(), buffer_notify_length()
4664 gtk_entry_buffer_delete_text (get_buffer (GTK_ENTRY (editable)), start_pos, end_pos - start_pos);
4667 /* GtkEntryBuffer signal handlers
4670 buffer_inserted_text (GtkEntryBuffer *buffer,
4676 GtkEntryPrivate *priv = entry->priv;
4677 guint password_hint_timeout;
4679 if (priv->current_pos > position)
4680 priv->current_pos += n_chars;
4682 if (priv->selection_bound > position)
4683 priv->selection_bound += n_chars;
4685 /* Calculate the password hint if it needs to be displayed. */
4686 if (n_chars == 1 && !priv->visible)
4688 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
4689 "gtk-entry-password-hint-timeout", &password_hint_timeout,
4692 if (password_hint_timeout > 0)
4694 GtkEntryPasswordHint *password_hint = g_object_get_qdata (G_OBJECT (entry),
4695 quark_password_hint);
4698 password_hint = g_slice_new0 (GtkEntryPasswordHint);
4699 g_object_set_qdata_full (G_OBJECT (entry), quark_password_hint, password_hint,
4700 (GDestroyNotify)gtk_entry_password_hint_free);
4703 password_hint->position = position;
4704 if (password_hint->source_id)
4705 g_source_remove (password_hint->source_id);
4706 password_hint->source_id = gdk_threads_add_timeout (password_hint_timeout,
4707 (GSourceFunc)gtk_entry_remove_password_hint, entry);
4713 buffer_deleted_text (GtkEntryBuffer *buffer,
4718 GtkEntryPrivate *priv = entry->priv;
4719 guint end_pos = position + n_chars;
4720 gint selection_bound;
4723 current_pos = priv->current_pos;
4724 if (current_pos > position)
4725 current_pos -= MIN (current_pos, end_pos) - position;
4727 selection_bound = priv->selection_bound;
4728 if (selection_bound > position)
4729 selection_bound -= MIN (selection_bound, end_pos) - position;
4731 gtk_entry_set_positions (entry, current_pos, selection_bound);
4733 /* We might have deleted the selection */
4734 gtk_entry_update_primary_selection (entry);
4736 /* Disable the password hint if one exists. */
4739 GtkEntryPasswordHint *password_hint = g_object_get_qdata (G_OBJECT (entry),
4740 quark_password_hint);
4743 if (password_hint->source_id)
4744 g_source_remove (password_hint->source_id);
4745 password_hint->source_id = 0;
4746 password_hint->position = -1;
4752 buffer_notify_text (GtkEntryBuffer *buffer,
4756 gtk_entry_recompute (entry);
4757 emit_changed (entry);
4758 g_object_notify (G_OBJECT (entry), "text");
4762 buffer_notify_length (GtkEntryBuffer *buffer,
4766 g_object_notify (G_OBJECT (entry), "text-length");
4770 buffer_notify_max_length (GtkEntryBuffer *buffer,
4774 g_object_notify (G_OBJECT (entry), "max-length");
4778 buffer_connect_signals (GtkEntry *entry)
4780 g_signal_connect (get_buffer (entry), "inserted-text", G_CALLBACK (buffer_inserted_text), entry);
4781 g_signal_connect (get_buffer (entry), "deleted-text", G_CALLBACK (buffer_deleted_text), entry);
4782 g_signal_connect (get_buffer (entry), "notify::text", G_CALLBACK (buffer_notify_text), entry);
4783 g_signal_connect (get_buffer (entry), "notify::length", G_CALLBACK (buffer_notify_length), entry);
4784 g_signal_connect (get_buffer (entry), "notify::max-length", G_CALLBACK (buffer_notify_max_length), entry);
4788 buffer_disconnect_signals (GtkEntry *entry)
4790 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_inserted_text, entry);
4791 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_deleted_text, entry);
4792 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_text, entry);
4793 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_length, entry);
4794 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_max_length, entry);
4797 /* Compute the X position for an offset that corresponds to the "more important
4798 * cursor position for that offset. We use this when trying to guess to which
4799 * end of the selection we should go to when the user hits the left or
4803 get_better_cursor_x (GtkEntry *entry,
4806 GtkEntryPrivate *priv = entry->priv;
4807 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
4808 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
4809 gboolean split_cursor;
4811 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
4812 const gchar *text = pango_layout_get_text (layout);
4813 gint index = g_utf8_offset_to_pointer (text, offset) - text;
4815 PangoRectangle strong_pos, weak_pos;
4817 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
4818 "gtk-split-cursor", &split_cursor,
4821 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
4824 return strong_pos.x / PANGO_SCALE;
4826 return (keymap_direction == priv->resolved_dir) ? strong_pos.x / PANGO_SCALE : weak_pos.x / PANGO_SCALE;
4830 gtk_entry_move_cursor (GtkEntry *entry,
4831 GtkMovementStep step,
4833 gboolean extend_selection)
4835 GtkEntryPrivate *priv = entry->priv;
4836 gint new_pos = priv->current_pos;
4838 _gtk_entry_reset_im_context (entry);
4840 if (priv->current_pos != priv->selection_bound && !extend_selection)
4842 /* If we have a current selection and aren't extending it, move to the
4843 * start/or end of the selection as appropriate
4847 case GTK_MOVEMENT_VISUAL_POSITIONS:
4849 gint current_x = get_better_cursor_x (entry, priv->current_pos);
4850 gint bound_x = get_better_cursor_x (entry, priv->selection_bound);
4853 new_pos = current_x < bound_x ? priv->current_pos : priv->selection_bound;
4855 new_pos = current_x > bound_x ? priv->current_pos : priv->selection_bound;
4858 case GTK_MOVEMENT_LOGICAL_POSITIONS:
4859 case GTK_MOVEMENT_WORDS:
4861 new_pos = MIN (priv->current_pos, priv->selection_bound);
4863 new_pos = MAX (priv->current_pos, priv->selection_bound);
4865 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
4866 case GTK_MOVEMENT_PARAGRAPH_ENDS:
4867 case GTK_MOVEMENT_BUFFER_ENDS:
4868 new_pos = count < 0 ? 0 : gtk_entry_buffer_get_length (get_buffer (entry));
4870 case GTK_MOVEMENT_DISPLAY_LINES:
4871 case GTK_MOVEMENT_PARAGRAPHS:
4872 case GTK_MOVEMENT_PAGES:
4873 case GTK_MOVEMENT_HORIZONTAL_PAGES:
4881 case GTK_MOVEMENT_LOGICAL_POSITIONS:
4882 new_pos = gtk_entry_move_logically (entry, new_pos, count);
4884 case GTK_MOVEMENT_VISUAL_POSITIONS:
4885 new_pos = gtk_entry_move_visually (entry, new_pos, count);
4886 if (priv->current_pos == new_pos)
4888 if (!extend_selection)
4890 if (!gtk_widget_keynav_failed (GTK_WIDGET (entry),
4892 GTK_DIR_RIGHT : GTK_DIR_LEFT))
4894 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (entry));
4897 gtk_widget_child_focus (toplevel,
4899 GTK_DIR_RIGHT : GTK_DIR_LEFT);
4904 gtk_widget_error_bell (GTK_WIDGET (entry));
4908 case GTK_MOVEMENT_WORDS:
4911 new_pos = gtk_entry_move_forward_word (entry, new_pos, FALSE);
4916 new_pos = gtk_entry_move_backward_word (entry, new_pos, FALSE);
4919 if (priv->current_pos == new_pos)
4920 gtk_widget_error_bell (GTK_WIDGET (entry));
4922 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
4923 case GTK_MOVEMENT_PARAGRAPH_ENDS:
4924 case GTK_MOVEMENT_BUFFER_ENDS:
4925 new_pos = count < 0 ? 0 : gtk_entry_buffer_get_length (get_buffer (entry));
4926 if (priv->current_pos == new_pos)
4927 gtk_widget_error_bell (GTK_WIDGET (entry));
4929 case GTK_MOVEMENT_DISPLAY_LINES:
4930 case GTK_MOVEMENT_PARAGRAPHS:
4931 case GTK_MOVEMENT_PAGES:
4932 case GTK_MOVEMENT_HORIZONTAL_PAGES:
4937 if (extend_selection)
4938 gtk_editable_select_region (GTK_EDITABLE (entry), priv->selection_bound, new_pos);
4940 gtk_editable_set_position (GTK_EDITABLE (entry), new_pos);
4942 gtk_entry_pend_cursor_blink (entry);
4946 gtk_entry_insert_at_cursor (GtkEntry *entry,
4949 GtkEntryPrivate *priv = entry->priv;
4950 GtkEditable *editable = GTK_EDITABLE (entry);
4951 gint pos = priv->current_pos;
4955 _gtk_entry_reset_im_context (entry);
4957 gtk_editable_insert_text (editable, str, -1, &pos);
4958 gtk_editable_set_position (editable, pos);
4963 gtk_entry_delete_from_cursor (GtkEntry *entry,
4967 GtkEntryPrivate *priv = entry->priv;
4968 GtkEditable *editable = GTK_EDITABLE (entry);
4969 gint start_pos = priv->current_pos;
4970 gint end_pos = priv->current_pos;
4971 gint old_n_bytes = gtk_entry_buffer_get_bytes (get_buffer (entry));
4973 _gtk_entry_reset_im_context (entry);
4975 if (!priv->editable)
4977 gtk_widget_error_bell (GTK_WIDGET (entry));
4981 if (priv->selection_bound != priv->current_pos)
4983 gtk_editable_delete_selection (editable);
4989 case GTK_DELETE_CHARS:
4990 end_pos = gtk_entry_move_logically (entry, priv->current_pos, count);
4991 gtk_editable_delete_text (editable, MIN (start_pos, end_pos), MAX (start_pos, end_pos));
4993 case GTK_DELETE_WORDS:
4996 /* Move to end of current word, or if not on a word, end of previous word */
4997 end_pos = gtk_entry_move_backward_word (entry, end_pos, FALSE);
4998 end_pos = gtk_entry_move_forward_word (entry, end_pos, FALSE);
5002 /* Move to beginning of current word, or if not on a word, begining of next word */
5003 start_pos = gtk_entry_move_forward_word (entry, start_pos, FALSE);
5004 start_pos = gtk_entry_move_backward_word (entry, start_pos, FALSE);
5008 case GTK_DELETE_WORD_ENDS:
5011 start_pos = gtk_entry_move_backward_word (entry, start_pos, FALSE);
5016 end_pos = gtk_entry_move_forward_word (entry, end_pos, FALSE);
5019 gtk_editable_delete_text (editable, start_pos, end_pos);
5021 case GTK_DELETE_DISPLAY_LINE_ENDS:
5022 case GTK_DELETE_PARAGRAPH_ENDS:
5024 gtk_editable_delete_text (editable, 0, priv->current_pos);
5026 gtk_editable_delete_text (editable, priv->current_pos, -1);
5028 case GTK_DELETE_DISPLAY_LINES:
5029 case GTK_DELETE_PARAGRAPHS:
5030 gtk_editable_delete_text (editable, 0, -1);
5032 case GTK_DELETE_WHITESPACE:
5033 gtk_entry_delete_whitespace (entry);
5037 if (gtk_entry_buffer_get_bytes (get_buffer (entry)) == old_n_bytes)
5038 gtk_widget_error_bell (GTK_WIDGET (entry));
5040 gtk_entry_pend_cursor_blink (entry);
5044 gtk_entry_backspace (GtkEntry *entry)
5046 GtkEntryPrivate *priv = entry->priv;
5047 GtkEditable *editable = GTK_EDITABLE (entry);
5050 _gtk_entry_reset_im_context (entry);
5052 if (!priv->editable)
5054 gtk_widget_error_bell (GTK_WIDGET (entry));
5058 if (priv->selection_bound != priv->current_pos)
5060 gtk_editable_delete_selection (editable);
5064 prev_pos = gtk_entry_move_logically (entry, priv->current_pos, -1);
5066 if (prev_pos < priv->current_pos)
5068 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
5069 PangoLogAttr *log_attrs;
5072 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
5074 /* Deleting parts of characters */
5075 if (log_attrs[priv->current_pos].backspace_deletes_character)
5077 gchar *cluster_text;
5078 gchar *normalized_text;
5081 cluster_text = gtk_entry_get_display_text (entry, prev_pos,
5083 normalized_text = g_utf8_normalize (cluster_text,
5084 strlen (cluster_text),
5086 len = g_utf8_strlen (normalized_text, -1);
5088 gtk_editable_delete_text (editable, prev_pos, priv->current_pos);
5091 gint pos = priv->current_pos;
5093 gtk_editable_insert_text (editable, normalized_text,
5094 g_utf8_offset_to_pointer (normalized_text, len - 1) - normalized_text,
5096 gtk_editable_set_position (editable, pos);
5099 g_free (normalized_text);
5100 g_free (cluster_text);
5104 gtk_editable_delete_text (editable, prev_pos, priv->current_pos);
5111 gtk_widget_error_bell (GTK_WIDGET (entry));
5114 gtk_entry_pend_cursor_blink (entry);
5118 gtk_entry_copy_clipboard (GtkEntry *entry)
5120 GtkEntryPrivate *priv = entry->priv;
5121 GtkEditable *editable = GTK_EDITABLE (entry);
5125 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5129 gtk_widget_error_bell (GTK_WIDGET (entry));
5133 str = gtk_entry_get_display_text (entry, start, end);
5134 gtk_clipboard_set_text (gtk_widget_get_clipboard (GTK_WIDGET (entry),
5135 GDK_SELECTION_CLIPBOARD),
5142 gtk_entry_cut_clipboard (GtkEntry *entry)
5144 GtkEntryPrivate *priv = entry->priv;
5145 GtkEditable *editable = GTK_EDITABLE (entry);
5150 gtk_widget_error_bell (GTK_WIDGET (entry));
5154 gtk_entry_copy_clipboard (entry);
5158 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5159 gtk_editable_delete_text (editable, start, end);
5163 gtk_widget_error_bell (GTK_WIDGET (entry));
5168 gtk_entry_paste_clipboard (GtkEntry *entry)
5170 GtkEntryPrivate *priv = entry->priv;
5173 gtk_entry_paste (entry, GDK_SELECTION_CLIPBOARD);
5175 gtk_widget_error_bell (GTK_WIDGET (entry));
5179 gtk_entry_delete_cb (GtkEntry *entry)
5181 GtkEntryPrivate *priv = entry->priv;
5182 GtkEditable *editable = GTK_EDITABLE (entry);
5187 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5188 gtk_editable_delete_text (editable, start, end);
5193 gtk_entry_toggle_overwrite (GtkEntry *entry)
5195 GtkEntryPrivate *priv = entry->priv;
5197 priv->overwrite_mode = !priv->overwrite_mode;
5198 gtk_entry_pend_cursor_blink (entry);
5199 gtk_widget_queue_draw (GTK_WIDGET (entry));
5203 gtk_entry_select_all (GtkEntry *entry)
5205 gtk_entry_select_line (entry);
5209 gtk_entry_real_activate (GtkEntry *entry)
5211 GtkEntryPrivate *priv = entry->priv;
5213 GtkWidget *default_widget, *focus_widget;
5214 GtkWidget *toplevel;
5217 widget = GTK_WIDGET (entry);
5219 if (priv->activates_default)
5221 toplevel = gtk_widget_get_toplevel (widget);
5222 if (GTK_IS_WINDOW (toplevel))
5224 window = GTK_WINDOW (toplevel);
5228 default_widget = gtk_window_get_default_widget (window);
5229 focus_widget = gtk_window_get_focus (window);
5230 if (widget != default_widget &&
5231 !(widget == focus_widget && (!default_widget || !gtk_widget_get_sensitive (default_widget))))
5232 gtk_window_activate_default (window);
5239 keymap_direction_changed (GdkKeymap *keymap,
5242 gtk_entry_recompute (entry);
5245 /* IM Context Callbacks
5249 gtk_entry_commit_cb (GtkIMContext *context,
5253 GtkEntryPrivate *priv = entry->priv;
5256 gtk_entry_enter_text (entry, str);
5260 gtk_entry_preedit_changed_cb (GtkIMContext *context,
5263 GtkEntryPrivate *priv = entry->priv;
5267 gchar *preedit_string;
5270 gtk_im_context_get_preedit_string (priv->im_context,
5271 &preedit_string, NULL,
5273 g_signal_emit (entry, signals[PREEDIT_CHANGED], 0, preedit_string);
5274 priv->preedit_length = strlen (preedit_string);
5275 cursor_pos = CLAMP (cursor_pos, 0, g_utf8_strlen (preedit_string, -1));
5276 priv->preedit_cursor = cursor_pos;
5277 g_free (preedit_string);
5279 gtk_entry_recompute (entry);
5284 gtk_entry_retrieve_surrounding_cb (GtkIMContext *context,
5287 GtkEntryPrivate *priv = entry->priv;
5290 /* XXXX ??? does this even make sense when text is not visible? Should we return FALSE? */
5291 text = gtk_entry_get_display_text (entry, 0, -1);
5292 gtk_im_context_set_surrounding (context, text, strlen (text), /* Length in bytes */
5293 g_utf8_offset_to_pointer (text, priv->current_pos) - text);
5300 gtk_entry_delete_surrounding_cb (GtkIMContext *slave,
5305 GtkEntryPrivate *priv = entry->priv;
5308 gtk_editable_delete_text (GTK_EDITABLE (entry),
5309 priv->current_pos + offset,
5310 priv->current_pos + offset + n_chars);
5315 /* Internal functions
5318 /* Used for im_commit_cb and inserting Unicode chars */
5320 gtk_entry_enter_text (GtkEntry *entry,
5323 GtkEntryPrivate *priv = entry->priv;
5324 GtkEditable *editable = GTK_EDITABLE (entry);
5326 gboolean old_need_im_reset;
5328 old_need_im_reset = priv->need_im_reset;
5329 priv->need_im_reset = FALSE;
5331 if (gtk_editable_get_selection_bounds (editable, NULL, NULL))
5332 gtk_editable_delete_selection (editable);
5335 if (priv->overwrite_mode)
5336 gtk_entry_delete_from_cursor (entry, GTK_DELETE_CHARS, 1);
5339 tmp_pos = priv->current_pos;
5340 gtk_editable_insert_text (editable, str, strlen (str), &tmp_pos);
5341 gtk_editable_set_position (editable, tmp_pos);
5343 priv->need_im_reset = old_need_im_reset;
5346 /* All changes to priv->current_pos and priv->selection_bound
5347 * should go through this function.
5350 gtk_entry_set_positions (GtkEntry *entry,
5352 gint selection_bound)
5354 GtkEntryPrivate *priv = entry->priv;
5355 gboolean changed = FALSE;
5357 g_object_freeze_notify (G_OBJECT (entry));
5359 if (current_pos != -1 &&
5360 priv->current_pos != current_pos)
5362 priv->current_pos = current_pos;
5365 g_object_notify (G_OBJECT (entry), "cursor-position");
5368 if (selection_bound != -1 &&
5369 priv->selection_bound != selection_bound)
5371 priv->selection_bound = selection_bound;
5374 g_object_notify (G_OBJECT (entry), "selection-bound");
5377 g_object_thaw_notify (G_OBJECT (entry));
5381 gtk_entry_move_adjustments (entry);
5382 gtk_entry_recompute (entry);
5387 gtk_entry_reset_layout (GtkEntry *entry)
5389 GtkEntryPrivate *priv = entry->priv;
5391 if (priv->cached_layout)
5393 g_object_unref (priv->cached_layout);
5394 priv->cached_layout = NULL;
5399 update_im_cursor_location (GtkEntry *entry)
5401 GtkEntryPrivate *priv = entry->priv;
5404 gint strong_xoffset;
5405 gint area_width, area_height;
5407 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
5408 gtk_entry_get_text_area_size (entry, NULL, NULL, &area_width, &area_height);
5410 strong_xoffset = strong_x - priv->scroll_offset;
5411 if (strong_xoffset < 0)
5415 else if (strong_xoffset > area_width)
5417 strong_xoffset = area_width;
5419 area.x = strong_xoffset;
5422 area.height = area_height;
5424 gtk_im_context_set_cursor_location (priv->im_context, &area);
5428 recompute_idle_func (gpointer data)
5430 GtkEntry *entry = GTK_ENTRY (data);
5431 GtkEntryPrivate *priv = entry->priv;
5433 priv->recompute_idle = 0;
5435 if (gtk_widget_has_screen (GTK_WIDGET (entry)))
5437 gtk_entry_adjust_scroll (entry);
5438 gtk_widget_queue_draw (GTK_WIDGET (entry));
5440 update_im_cursor_location (entry);
5447 gtk_entry_recompute (GtkEntry *entry)
5449 GtkEntryPrivate *priv = entry->priv;
5451 gtk_entry_reset_layout (entry);
5452 gtk_entry_check_cursor_blink (entry);
5454 if (!priv->recompute_idle)
5456 priv->recompute_idle = gdk_threads_add_idle_full (G_PRIORITY_HIGH_IDLE + 15, /* between resize and redraw */
5457 recompute_idle_func, entry, NULL);
5462 gtk_entry_get_placeholder_text_color (GtkEntry *entry,
5465 GtkWidget *widget = GTK_WIDGET (entry);
5466 GtkStyleContext *context;
5467 GdkRGBA fg = { 0.5, 0.5, 0.5 };
5469 context = gtk_widget_get_style_context (widget);
5470 gtk_style_context_lookup_color (context, "placeholder_text_color", &fg);
5472 color->red = CLAMP (fg.red * 65535. + 0.5, 0, 65535);
5473 color->green = CLAMP (fg.green * 65535. + 0.5, 0, 65535);
5474 color->blue = CLAMP (fg.blue * 65535. + 0.5, 0, 65535);
5477 static inline gboolean
5478 show_placeholder_text (GtkEntry *entry)
5480 GtkEntryPrivate *priv = entry->priv;
5482 if (!gtk_widget_has_focus (GTK_WIDGET (entry)) &&
5483 gtk_entry_buffer_get_bytes (get_buffer (entry)) == 0 &&
5484 priv->placeholder_text != NULL)
5490 static PangoLayout *
5491 gtk_entry_create_layout (GtkEntry *entry,
5492 gboolean include_preedit)
5494 GtkEntryPrivate *priv = entry->priv;
5495 GtkWidget *widget = GTK_WIDGET (entry);
5496 PangoLayout *layout = gtk_widget_create_pango_layout (widget, NULL);
5497 PangoAttrList *tmp_attrs = pango_attr_list_new ();
5498 gboolean placeholder_layout = show_placeholder_text (entry);
5500 gchar *preedit_string = NULL;
5501 gint preedit_length = 0;
5502 PangoAttrList *preedit_attrs = NULL;
5507 pango_layout_set_single_paragraph_mode (layout, TRUE);
5509 display = placeholder_layout ? g_strdup (priv->placeholder_text) : gtk_entry_get_display_text (entry, 0, -1);
5510 n_bytes = strlen (display);
5512 if (!placeholder_layout && include_preedit)
5514 gtk_im_context_get_preedit_string (priv->im_context,
5515 &preedit_string, &preedit_attrs, NULL);
5516 preedit_length = priv->preedit_length;
5518 else if (placeholder_layout)
5521 PangoAttribute *attr;
5523 gtk_entry_get_placeholder_text_color (entry, &color);
5524 attr = pango_attr_foreground_new (color.red, color.green, color.blue);
5525 attr->start_index = 0;
5526 attr->end_index = G_MAXINT;
5527 pango_attr_list_insert (tmp_attrs, attr);
5532 GString *tmp_string = g_string_new (display);
5533 gint cursor_index = g_utf8_offset_to_pointer (display, priv->current_pos) - display;
5535 g_string_insert (tmp_string, cursor_index, preedit_string);
5537 pango_layout_set_text (layout, tmp_string->str, tmp_string->len);
5539 pango_attr_list_splice (tmp_attrs, preedit_attrs,
5540 cursor_index, preedit_length);
5542 g_string_free (tmp_string, TRUE);
5546 PangoDirection pango_dir;
5548 if (gtk_entry_get_display_mode (entry) == DISPLAY_NORMAL)
5549 pango_dir = pango_find_base_dir (display, n_bytes);
5551 pango_dir = PANGO_DIRECTION_NEUTRAL;
5553 if (pango_dir == PANGO_DIRECTION_NEUTRAL)
5555 if (gtk_widget_has_focus (widget))
5557 GdkDisplay *display = gtk_widget_get_display (widget);
5558 GdkKeymap *keymap = gdk_keymap_get_for_display (display);
5559 if (gdk_keymap_get_direction (keymap) == PANGO_DIRECTION_RTL)
5560 pango_dir = PANGO_DIRECTION_RTL;
5562 pango_dir = PANGO_DIRECTION_LTR;
5566 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
5567 pango_dir = PANGO_DIRECTION_RTL;
5569 pango_dir = PANGO_DIRECTION_LTR;
5573 pango_context_set_base_dir (gtk_widget_get_pango_context (widget),
5576 priv->resolved_dir = pango_dir;
5578 pango_layout_set_text (layout, display, n_bytes);
5581 pango_layout_set_attributes (layout, tmp_attrs);
5583 g_free (preedit_string);
5587 pango_attr_list_unref (preedit_attrs);
5589 pango_attr_list_unref (tmp_attrs);
5594 static PangoLayout *
5595 gtk_entry_ensure_layout (GtkEntry *entry,
5596 gboolean include_preedit)
5598 GtkEntryPrivate *priv = entry->priv;
5600 if (priv->preedit_length > 0 &&
5601 !include_preedit != !priv->cache_includes_preedit)
5602 gtk_entry_reset_layout (entry);
5604 if (!priv->cached_layout)
5606 priv->cached_layout = gtk_entry_create_layout (entry, include_preedit);
5607 priv->cache_includes_preedit = include_preedit;
5610 return priv->cached_layout;
5614 get_layout_position (GtkEntry *entry,
5618 GtkEntryPrivate *priv = entry->priv;
5619 PangoLayout *layout;
5620 PangoRectangle logical_rect;
5621 gint area_width, area_height;
5622 GtkBorder inner_border;
5624 PangoLayoutLine *line;
5626 layout = gtk_entry_ensure_layout (entry, TRUE);
5628 gtk_entry_get_text_area_size (entry, NULL, NULL, &area_width, &area_height);
5629 _gtk_entry_effective_inner_border (entry, &inner_border);
5631 area_height = PANGO_SCALE * (area_height - inner_border.top - inner_border.bottom);
5633 line = pango_layout_get_lines_readonly (layout)->data;
5634 pango_layout_line_get_extents (line, NULL, &logical_rect);
5636 /* Align primarily for locale's ascent/descent */
5637 y_pos = ((area_height - priv->ascent - priv->descent) / 2 +
5638 priv->ascent + logical_rect.y);
5640 /* Now see if we need to adjust to fit in actual drawn string */
5641 if (logical_rect.height > area_height)
5642 y_pos = (area_height - logical_rect.height) / 2;
5645 else if (y_pos + logical_rect.height > area_height)
5646 y_pos = area_height - logical_rect.height;
5648 y_pos = inner_border.top + y_pos / PANGO_SCALE;
5651 *x = inner_border.left - priv->scroll_offset;
5658 draw_text_with_color (GtkEntry *entry,
5660 GdkRGBA *default_color)
5662 GtkEntryPrivate *priv = entry->priv;
5663 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
5666 gint start_pos, end_pos;
5668 widget = GTK_WIDGET (entry);
5672 get_layout_position (entry, &x, &y);
5674 cairo_move_to (cr, x, y);
5675 gdk_cairo_set_source_rgba (cr, default_color);
5676 pango_cairo_show_layout (cr, layout);
5678 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start_pos, &end_pos))
5682 PangoRectangle logical_rect;
5683 GdkRGBA selection_color, text_color;
5684 GtkBorder inner_border;
5685 GtkStyleContext *context;
5686 GtkStateFlags state;
5688 context = gtk_widget_get_style_context (widget);
5689 pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
5690 gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
5692 state = GTK_STATE_FLAG_SELECTED;
5694 if (gtk_widget_has_focus (widget))
5695 state |= GTK_STATE_FLAG_FOCUSED;
5697 gtk_style_context_get_background_color (context, state, &selection_color);
5698 gtk_style_context_get_color (context, state, &text_color);
5700 _gtk_entry_effective_inner_border (entry, &inner_border);
5702 for (i = 0; i < n_ranges; ++i)
5703 cairo_rectangle (cr,
5704 inner_border.left - priv->scroll_offset + ranges[2 * i],
5707 logical_rect.height);
5711 gdk_cairo_set_source_rgba (cr, &selection_color);
5714 cairo_move_to (cr, x, y);
5715 gdk_cairo_set_source_rgba (cr, &text_color);
5716 pango_cairo_show_layout (cr, layout);
5724 gtk_entry_draw_text (GtkEntry *entry,
5727 GtkEntryPrivate *priv = entry->priv;
5728 GtkWidget *widget = GTK_WIDGET (entry);
5729 GtkStateFlags state = 0;
5730 GdkRGBA text_color, bar_text_color;
5731 GtkStyleContext *context;
5734 gint progress_x, progress_y, progress_width, progress_height;
5735 gint clip_width, clip_height;
5737 /* Nothing to display at all */
5738 if (gtk_entry_get_display_mode (entry) == DISPLAY_BLANK)
5741 state = gtk_widget_get_state_flags (widget);
5742 context = gtk_widget_get_style_context (widget);
5744 gtk_style_context_get_color (context, state, &text_color);
5746 /* Get foreground color for progressbars */
5747 gtk_style_context_save (context);
5748 gtk_style_context_add_class (context, GTK_STYLE_CLASS_PROGRESSBAR);
5749 gtk_style_context_get_color (context, state, &bar_text_color);
5750 gtk_style_context_restore (context);
5752 get_progress_area (widget,
5753 &progress_x, &progress_y,
5754 &progress_width, &progress_height);
5756 clip_width = gdk_window_get_width (priv->text_area);
5757 clip_height = gdk_window_get_height (priv->text_area);
5758 cairo_rectangle (cr, 0, 0, clip_width, clip_height);
5761 /* If the color is the same, or the progress area has a zero
5762 * size, then we only need to draw once. */
5763 if (gdk_rgba_equal (&text_color, &bar_text_color) ||
5764 ((progress_width == 0) || (progress_height == 0)))
5766 draw_text_with_color (entry, cr, &text_color);
5770 width = gdk_window_get_width (priv->text_area);
5771 height = gdk_window_get_height (priv->text_area);
5775 cairo_rectangle (cr, 0, 0, width, height);
5779 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
5780 cairo_rectangle (cr, 0, 0, width, height);
5782 gdk_window_get_position (priv->text_area, &pos_x, &pos_y);
5783 progress_x -= pos_x;
5784 progress_y -= pos_y;
5786 cairo_rectangle (cr, progress_x, progress_y,
5787 progress_width, progress_height);
5789 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_WINDING);
5791 draw_text_with_color (entry, cr, &text_color);
5794 cairo_rectangle (cr, progress_x, progress_y,
5795 progress_width, progress_height);
5798 draw_text_with_color (entry, cr, &bar_text_color);
5805 draw_insertion_cursor (GtkEntry *entry,
5807 GdkRectangle *cursor_location,
5808 gboolean is_primary,
5809 PangoDirection direction,
5810 gboolean draw_arrow)
5812 GtkWidget *widget = GTK_WIDGET (entry);
5813 GtkTextDirection text_dir;
5815 if (direction == PANGO_DIRECTION_LTR)
5816 text_dir = GTK_TEXT_DIR_LTR;
5818 text_dir = GTK_TEXT_DIR_RTL;
5820 gtk_draw_insertion_cursor (widget, cr,
5822 is_primary, text_dir, draw_arrow);
5826 gtk_entry_draw_cursor (GtkEntry *entry,
5830 GtkEntryPrivate *priv = entry->priv;
5831 GtkWidget *widget = GTK_WIDGET (entry);
5832 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
5833 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
5834 GdkRectangle cursor_location;
5835 gboolean split_cursor;
5836 PangoRectangle cursor_rect;
5837 GtkBorder inner_border;
5839 gint text_area_height;
5842 gboolean block_at_line_end;
5843 PangoLayout *layout;
5846 _gtk_entry_effective_inner_border (entry, &inner_border);
5848 xoffset = inner_border.left - priv->scroll_offset;
5850 text_area_height = gdk_window_get_height (priv->text_area);
5852 layout = gtk_entry_ensure_layout (entry, TRUE);
5853 text = pango_layout_get_text (layout);
5854 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos + priv->preedit_cursor) - text;
5855 if (!priv->overwrite_mode)
5858 block = _gtk_text_util_get_block_cursor_location (layout,
5859 cursor_index, &cursor_rect, &block_at_line_end);
5863 gint strong_x, weak_x;
5864 PangoDirection dir1 = PANGO_DIRECTION_NEUTRAL;
5865 PangoDirection dir2 = PANGO_DIRECTION_NEUTRAL;
5869 gtk_entry_get_cursor_locations (entry, type, &strong_x, &weak_x);
5871 g_object_get (gtk_widget_get_settings (widget),
5872 "gtk-split-cursor", &split_cursor,
5875 dir1 = priv->resolved_dir;
5881 if (weak_x != strong_x)
5883 dir2 = (priv->resolved_dir == PANGO_DIRECTION_LTR) ? PANGO_DIRECTION_RTL : PANGO_DIRECTION_LTR;
5889 if (keymap_direction == priv->resolved_dir)
5895 cursor_location.x = xoffset + x1;
5896 cursor_location.y = inner_border.top;
5897 cursor_location.width = 0;
5898 cursor_location.height = text_area_height - inner_border.top - inner_border.bottom;
5900 draw_insertion_cursor (entry, cr,
5901 &cursor_location, TRUE, dir1,
5902 dir2 != PANGO_DIRECTION_NEUTRAL);
5904 if (dir2 != PANGO_DIRECTION_NEUTRAL)
5906 cursor_location.x = xoffset + x2;
5907 draw_insertion_cursor (entry, cr,
5908 &cursor_location, FALSE, dir2,
5912 else /* overwrite_mode */
5914 GtkStyleContext *context;
5915 GdkRGBA cursor_color;
5921 get_layout_position (entry, &x, &y);
5923 rect.x = PANGO_PIXELS (cursor_rect.x) + x;
5924 rect.y = PANGO_PIXELS (cursor_rect.y) + y;
5925 rect.width = PANGO_PIXELS (cursor_rect.width);
5926 rect.height = PANGO_PIXELS (cursor_rect.height);
5928 context = gtk_widget_get_style_context (widget);
5930 _gtk_style_context_get_cursor_color (context, &cursor_color, NULL);
5931 gdk_cairo_set_source_rgba (cr, &cursor_color);
5932 gdk_cairo_rectangle (cr, &rect);
5935 if (!block_at_line_end)
5937 GtkStateFlags state;
5940 state = gtk_widget_get_state_flags (widget);
5941 gtk_style_context_get_background_color (context, state, &color);
5943 gdk_cairo_rectangle (cr, &rect);
5945 cairo_move_to (cr, x, y);
5946 gdk_cairo_set_source_rgba (cr, &color);
5947 pango_cairo_show_layout (cr, layout);
5955 _gtk_entry_reset_im_context (GtkEntry *entry)
5957 GtkEntryPrivate *priv = entry->priv;
5959 if (priv->need_im_reset)
5961 priv->need_im_reset = FALSE;
5962 gtk_im_context_reset (priv->im_context);
5967 * gtk_entry_reset_im_context:
5968 * @entry: a #GtkEntry
5970 * Reset the input method context of the entry if needed.
5972 * This can be necessary in the case where modifying the buffer
5973 * would confuse on-going input method behavior.
5978 gtk_entry_reset_im_context (GtkEntry *entry)
5980 g_return_if_fail (GTK_IS_ENTRY (entry));
5982 _gtk_entry_reset_im_context (entry);
5986 * gtk_entry_im_context_filter_keypress:
5987 * @entry: a #GtkEntry
5988 * @event: (type Gdk.EventKey): the key event
5990 * Allow the #GtkEntry input method to internally handle key press
5991 * and release events. If this function returns %TRUE, then no further
5992 * processing should be done for this key event. See
5993 * gtk_im_context_filter_keypress().
5995 * Note that you are expected to call this function from your handler
5996 * when overriding key event handling. This is needed in the case when
5997 * you need to insert your own key handling between the input method
5998 * and the default key event handling of the #GtkEntry.
5999 * See gtk_text_view_reset_im_context() for an example of use.
6001 * Return value: %TRUE if the input method handled the key event.
6006 gtk_entry_im_context_filter_keypress (GtkEntry *entry,
6009 GtkEntryPrivate *priv;
6011 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
6015 return gtk_im_context_filter_keypress (priv->im_context, event);
6019 _gtk_entry_get_im_context (GtkEntry *entry)
6021 return entry->priv->im_context;
6025 gtk_entry_find_position (GtkEntry *entry,
6028 GtkEntryPrivate *priv = entry->priv;
6029 PangoLayout *layout;
6030 PangoLayoutLine *line;
6037 layout = gtk_entry_ensure_layout (entry, TRUE);
6038 text = pango_layout_get_text (layout);
6039 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos) - text;
6041 line = pango_layout_get_lines_readonly (layout)->data;
6042 pango_layout_line_x_to_index (line, x * PANGO_SCALE, &index, &trailing);
6044 if (index >= cursor_index && priv->preedit_length)
6046 if (index >= cursor_index + priv->preedit_length)
6047 index -= priv->preedit_length;
6050 index = cursor_index;
6055 pos = g_utf8_pointer_to_offset (text, text + index);
6062 gtk_entry_get_cursor_locations (GtkEntry *entry,
6067 GtkEntryPrivate *priv = entry->priv;
6068 DisplayMode mode = gtk_entry_get_display_mode (entry);
6070 /* Nothing to display at all, so no cursor is relevant */
6071 if (mode == DISPLAY_BLANK)
6081 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
6082 const gchar *text = pango_layout_get_text (layout);
6083 PangoRectangle strong_pos, weak_pos;
6086 if (type == CURSOR_STANDARD)
6088 index = g_utf8_offset_to_pointer (text, priv->current_pos + priv->preedit_cursor) - text;
6090 else /* type == CURSOR_DND */
6092 index = g_utf8_offset_to_pointer (text, priv->dnd_position) - text;
6094 if (priv->dnd_position > priv->current_pos)
6096 if (mode == DISPLAY_NORMAL)
6097 index += priv->preedit_length;
6100 gint preedit_len_chars = g_utf8_strlen (text, -1) - gtk_entry_buffer_get_length (get_buffer (entry));
6101 index += preedit_len_chars * g_unichar_to_utf8 (priv->invisible_char, NULL);
6106 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
6109 *strong_x = strong_pos.x / PANGO_SCALE;
6112 *weak_x = weak_pos.x / PANGO_SCALE;
6117 gtk_entry_adjust_scroll (GtkEntry *entry)
6119 GtkEntryPrivate *priv = entry->priv;
6120 gint min_offset, max_offset;
6121 gint text_area_width, text_width;
6122 GtkBorder inner_border;
6123 gint strong_x, weak_x;
6124 gint strong_xoffset, weak_xoffset;
6126 PangoLayout *layout;
6127 PangoLayoutLine *line;
6128 PangoRectangle logical_rect;
6130 if (!gtk_widget_get_realized (GTK_WIDGET (entry)))
6133 _gtk_entry_effective_inner_border (entry, &inner_border);
6135 text_area_width = gdk_window_get_width (priv->text_area);
6136 text_area_width -= inner_border.left + inner_border.right;
6137 if (text_area_width < 0)
6138 text_area_width = 0;
6140 layout = gtk_entry_ensure_layout (entry, TRUE);
6141 line = pango_layout_get_lines_readonly (layout)->data;
6143 pango_layout_line_get_extents (line, NULL, &logical_rect);
6145 /* Display as much text as we can */
6147 if (priv->resolved_dir == PANGO_DIRECTION_LTR)
6148 xalign = priv->xalign;
6150 xalign = 1.0 - priv->xalign;
6152 text_width = PANGO_PIXELS(logical_rect.width);
6154 if (text_width > text_area_width)
6157 max_offset = text_width - text_area_width;
6161 min_offset = (text_width - text_area_width) * xalign;
6162 max_offset = min_offset;
6165 priv->scroll_offset = CLAMP (priv->scroll_offset, min_offset, max_offset);
6167 /* And make sure cursors are on screen. Note that the cursor is
6168 * actually drawn one pixel into the INNER_BORDER space on
6169 * the right, when the scroll is at the utmost right. This
6170 * looks better to to me than confining the cursor inside the
6171 * border entirely, though it means that the cursor gets one
6172 * pixel closer to the edge of the widget on the right than
6173 * on the left. This might need changing if one changed
6174 * INNER_BORDER from 2 to 1, as one would do on a
6175 * small-screen-real-estate display.
6177 * We always make sure that the strong cursor is on screen, and
6178 * put the weak cursor on screen if possible.
6181 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, &weak_x);
6183 strong_xoffset = strong_x - priv->scroll_offset;
6185 if (strong_xoffset < 0)
6187 priv->scroll_offset += strong_xoffset;
6190 else if (strong_xoffset > text_area_width)
6192 priv->scroll_offset += strong_xoffset - text_area_width;
6193 strong_xoffset = text_area_width;
6196 weak_xoffset = weak_x - priv->scroll_offset;
6198 if (weak_xoffset < 0 && strong_xoffset - weak_xoffset <= text_area_width)
6200 priv->scroll_offset += weak_xoffset;
6202 else if (weak_xoffset > text_area_width &&
6203 strong_xoffset - (weak_xoffset - text_area_width) >= 0)
6205 priv->scroll_offset += weak_xoffset - text_area_width;
6208 g_object_notify (G_OBJECT (entry), "scroll-offset");
6212 gtk_entry_move_adjustments (GtkEntry *entry)
6214 GtkWidget *widget = GTK_WIDGET (entry);
6215 GtkAllocation allocation;
6216 GtkAdjustment *adjustment;
6217 PangoContext *context;
6218 PangoFontMetrics *metrics;
6219 GtkStyleContext *style_context;
6220 GtkStateFlags state;
6221 gint x, layout_x, border_x, border_y;
6224 adjustment = g_object_get_qdata (G_OBJECT (entry), quark_cursor_hadjustment);
6228 gtk_widget_get_allocation (widget, &allocation);
6230 /* Cursor position, layout offset, border width, and widget allocation */
6231 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &x, NULL);
6232 get_layout_position (entry, &layout_x, NULL);
6233 _gtk_entry_get_borders (entry, &border_x, &border_y);
6234 x += allocation.x + layout_x + border_x;
6236 /* Approximate width of a char, so user can see what is ahead/behind */
6237 context = gtk_widget_get_pango_context (widget);
6238 style_context = gtk_widget_get_style_context (widget);
6239 state = gtk_widget_get_state_flags (widget);
6241 metrics = pango_context_get_metrics (context,
6242 gtk_style_context_get_font (style_context, state),
6243 pango_context_get_language (context));
6244 char_width = pango_font_metrics_get_approximate_char_width (metrics) / PANGO_SCALE;
6247 gtk_adjustment_clamp_page (adjustment,
6248 x - (char_width + 1), /* one char + one pixel before */
6249 x + (char_width + 2)); /* one char + cursor + one pixel after */
6253 gtk_entry_move_visually (GtkEntry *entry,
6257 GtkEntryPrivate *priv = entry->priv;
6259 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6262 text = pango_layout_get_text (layout);
6264 index = g_utf8_offset_to_pointer (text, start) - text;
6268 int new_index, new_trailing;
6269 gboolean split_cursor;
6272 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
6273 "gtk-split-cursor", &split_cursor,
6280 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
6281 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
6283 strong = keymap_direction == priv->resolved_dir;
6288 pango_layout_move_cursor_visually (layout, strong, index, 0, 1, &new_index, &new_trailing);
6293 pango_layout_move_cursor_visually (layout, strong, index, 0, -1, &new_index, &new_trailing);
6299 else if (new_index != G_MAXINT)
6302 while (new_trailing--)
6303 index = g_utf8_next_char (text + index) - text;
6306 return g_utf8_pointer_to_offset (text, text + index);
6310 gtk_entry_move_logically (GtkEntry *entry,
6314 gint new_pos = start;
6317 length = gtk_entry_buffer_get_length (get_buffer (entry));
6319 /* Prevent any leak of information */
6320 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6322 new_pos = CLAMP (start + count, 0, length);
6326 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6327 PangoLogAttr *log_attrs;
6330 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6332 while (count > 0 && new_pos < length)
6336 while (new_pos < length && !log_attrs[new_pos].is_cursor_position);
6340 while (count < 0 && new_pos > 0)
6344 while (new_pos > 0 && !log_attrs[new_pos].is_cursor_position);
6356 gtk_entry_move_forward_word (GtkEntry *entry,
6358 gboolean allow_whitespace)
6360 gint new_pos = start;
6363 length = gtk_entry_buffer_get_length (get_buffer (entry));
6365 /* Prevent any leak of information */
6366 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6370 else if (new_pos < length)
6372 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6373 PangoLogAttr *log_attrs;
6376 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6378 /* Find the next word boundary */
6380 while (new_pos < n_attrs - 1 && !(log_attrs[new_pos].is_word_end ||
6381 (log_attrs[new_pos].is_word_start && allow_whitespace)))
6392 gtk_entry_move_backward_word (GtkEntry *entry,
6394 gboolean allow_whitespace)
6396 gint new_pos = start;
6398 /* Prevent any leak of information */
6399 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6405 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6406 PangoLogAttr *log_attrs;
6409 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6411 new_pos = start - 1;
6413 /* Find the previous word boundary */
6414 while (new_pos > 0 && !(log_attrs[new_pos].is_word_start ||
6415 (log_attrs[new_pos].is_word_end && allow_whitespace)))
6425 gtk_entry_delete_whitespace (GtkEntry *entry)
6427 GtkEntryPrivate *priv = entry->priv;
6428 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6429 PangoLogAttr *log_attrs;
6433 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6435 start = end = priv->current_pos;
6437 while (start > 0 && log_attrs[start-1].is_white)
6440 while (end < n_attrs && log_attrs[end].is_white)
6446 gtk_editable_delete_text (GTK_EDITABLE (entry), start, end);
6451 gtk_entry_select_word (GtkEntry *entry)
6453 GtkEntryPrivate *priv = entry->priv;
6454 gint start_pos = gtk_entry_move_backward_word (entry, priv->current_pos, TRUE);
6455 gint end_pos = gtk_entry_move_forward_word (entry, priv->current_pos, TRUE);
6457 gtk_editable_select_region (GTK_EDITABLE (entry), start_pos, end_pos);
6461 gtk_entry_select_line (GtkEntry *entry)
6463 gtk_editable_select_region (GTK_EDITABLE (entry), 0, -1);
6467 truncate_multiline (const gchar *text)
6472 text[length] && text[length] != '\n' && text[length] != '\r';
6479 paste_received (GtkClipboard *clipboard,
6483 GtkEntry *entry = GTK_ENTRY (data);
6484 GtkEditable *editable = GTK_EDITABLE (entry);
6485 GtkEntryPrivate *priv = entry->priv;
6487 if (priv->button == 2)
6489 gint pos, start, end;
6490 pos = priv->insert_pos;
6491 gtk_editable_get_selection_bounds (editable, &start, &end);
6492 if (!((start <= pos && pos <= end) || (end <= pos && pos <= start)))
6493 gtk_editable_select_region (editable, pos, pos);
6498 gint pos, start, end;
6500 gboolean popup_completion;
6501 GtkEntryCompletion *completion;
6503 completion = gtk_entry_get_completion (entry);
6505 if (priv->truncate_multiline)
6506 length = truncate_multiline (text);
6508 /* only complete if the selection is at the end */
6509 popup_completion = (gtk_entry_buffer_get_length (get_buffer (entry)) ==
6510 MAX (priv->current_pos, priv->selection_bound));
6514 if (gtk_widget_get_mapped (completion->priv->popup_window))
6515 _gtk_entry_completion_popdown (completion);
6517 if (!popup_completion && completion->priv->changed_id > 0)
6518 g_signal_handler_block (entry, completion->priv->changed_id);
6521 begin_change (entry);
6522 g_object_freeze_notify (G_OBJECT (entry));
6523 if (gtk_editable_get_selection_bounds (editable, &start, &end))
6524 gtk_editable_delete_text (editable, start, end);
6526 pos = priv->current_pos;
6527 gtk_editable_insert_text (editable, text, length, &pos);
6528 gtk_editable_set_position (editable, pos);
6529 g_object_thaw_notify (G_OBJECT (entry));
6533 !popup_completion && completion->priv->changed_id > 0)
6534 g_signal_handler_unblock (entry, completion->priv->changed_id);
6537 g_object_unref (entry);
6541 gtk_entry_paste (GtkEntry *entry,
6544 g_object_ref (entry);
6545 gtk_clipboard_request_text (gtk_widget_get_clipboard (GTK_WIDGET (entry), selection),
6546 paste_received, entry);
6550 primary_get_cb (GtkClipboard *clipboard,
6551 GtkSelectionData *selection_data,
6555 GtkEntry *entry = GTK_ENTRY (data);
6558 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end))
6560 gchar *str = gtk_entry_get_display_text (entry, start, end);
6561 gtk_selection_data_set_text (selection_data, str, -1);
6567 primary_clear_cb (GtkClipboard *clipboard,
6570 GtkEntry *entry = GTK_ENTRY (data);
6571 GtkEntryPrivate *priv = entry->priv;
6573 gtk_editable_select_region (GTK_EDITABLE (entry), priv->current_pos, priv->current_pos);
6577 gtk_entry_update_primary_selection (GtkEntry *entry)
6579 GtkTargetList *list;
6580 GtkTargetEntry *targets;
6581 GtkClipboard *clipboard;
6585 if (!gtk_widget_get_realized (GTK_WIDGET (entry)))
6588 list = gtk_target_list_new (NULL, 0);
6589 gtk_target_list_add_text_targets (list, 0);
6591 targets = gtk_target_table_new_from_list (list, &n_targets);
6593 clipboard = gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_PRIMARY);
6595 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end))
6597 if (!gtk_clipboard_set_with_owner (clipboard, targets, n_targets,
6598 primary_get_cb, primary_clear_cb, G_OBJECT (entry)))
6599 primary_clear_cb (clipboard, entry);
6603 if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (entry))
6604 gtk_clipboard_clear (clipboard);
6607 gtk_target_table_free (targets, n_targets);
6608 gtk_target_list_unref (list);
6612 gtk_entry_clear (GtkEntry *entry,
6613 GtkEntryIconPosition icon_pos)
6615 GtkEntryPrivate *priv = entry->priv;
6616 EntryIconInfo *icon_info = priv->icons[icon_pos];
6618 if (!icon_info || icon_info->storage_type == GTK_IMAGE_EMPTY)
6621 g_object_freeze_notify (G_OBJECT (entry));
6623 /* Explicitly check, as the pointer may become invalidated
6624 * during destruction.
6626 if (GDK_IS_WINDOW (icon_info->window))
6627 gdk_window_hide (icon_info->window);
6629 if (icon_info->pixbuf)
6631 g_object_unref (icon_info->pixbuf);
6632 icon_info->pixbuf = NULL;
6635 switch (icon_info->storage_type)
6637 case GTK_IMAGE_PIXBUF:
6638 g_object_notify (G_OBJECT (entry),
6639 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-pixbuf" : "secondary-icon-pixbuf");
6642 case GTK_IMAGE_STOCK:
6643 g_free (icon_info->stock_id);
6644 icon_info->stock_id = NULL;
6645 g_object_notify (G_OBJECT (entry),
6646 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-stock" : "secondary-icon-stock");
6649 case GTK_IMAGE_ICON_NAME:
6650 g_free (icon_info->icon_name);
6651 icon_info->icon_name = NULL;
6652 g_object_notify (G_OBJECT (entry),
6653 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-name" : "secondary-icon-name");
6656 case GTK_IMAGE_GICON:
6657 if (icon_info->gicon)
6659 g_object_unref (icon_info->gicon);
6660 icon_info->gicon = NULL;
6662 g_object_notify (G_OBJECT (entry),
6663 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-gicon" : "secondary-icon-gicon");
6667 g_assert_not_reached ();
6671 icon_info->storage_type = GTK_IMAGE_EMPTY;
6672 g_object_notify (G_OBJECT (entry),
6673 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-storage-type" : "secondary-icon-storage-type");
6675 g_object_thaw_notify (G_OBJECT (entry));
6679 create_normal_pixbuf (GtkStyleContext *context,
6680 const gchar *stock_id,
6681 GtkIconSize icon_size)
6683 GtkIconSet *icon_set;
6686 gtk_style_context_save (context);
6688 /* Unset any state */
6689 gtk_style_context_set_state (context, 0);
6691 icon_set = gtk_style_context_lookup_icon_set (context, stock_id);
6692 pixbuf = gtk_icon_set_render_icon_pixbuf (icon_set, context, icon_size);
6694 gtk_style_context_restore (context);
6700 gtk_entry_ensure_pixbuf (GtkEntry *entry,
6701 GtkEntryIconPosition icon_pos)
6703 GtkEntryPrivate *priv = entry->priv;
6704 EntryIconInfo *icon_info = priv->icons[icon_pos];
6705 GtkStyleContext *context;
6707 GtkIconTheme *icon_theme;
6708 GtkSettings *settings;
6713 if (!icon_info || icon_info->pixbuf)
6716 widget = GTK_WIDGET (entry);
6717 context = gtk_widget_get_style_context (widget);
6719 switch (icon_info->storage_type)
6721 case GTK_IMAGE_EMPTY:
6722 case GTK_IMAGE_PIXBUF:
6724 case GTK_IMAGE_STOCK:
6725 icon_info->pixbuf = create_normal_pixbuf (context, icon_info->stock_id,
6726 GTK_ICON_SIZE_MENU);
6728 if (!icon_info->pixbuf)
6729 icon_info->pixbuf = create_normal_pixbuf (context,
6730 GTK_STOCK_MISSING_IMAGE,
6731 GTK_ICON_SIZE_MENU);
6734 case GTK_IMAGE_ICON_NAME:
6735 screen = gtk_widget_get_screen (widget);
6738 icon_theme = gtk_icon_theme_get_for_screen (screen);
6739 settings = gtk_settings_get_for_screen (screen);
6741 gtk_icon_size_lookup_for_settings (settings,
6745 icon_info->pixbuf = gtk_icon_theme_load_icon (icon_theme,
6746 icon_info->icon_name,
6747 MIN (width, height),
6750 if (icon_info->pixbuf == NULL)
6751 icon_info->pixbuf = create_normal_pixbuf (context,
6752 GTK_STOCK_MISSING_IMAGE,
6753 GTK_ICON_SIZE_MENU);
6757 case GTK_IMAGE_GICON:
6758 screen = gtk_widget_get_screen (widget);
6761 icon_theme = gtk_icon_theme_get_for_screen (screen);
6762 settings = gtk_settings_get_for_screen (screen);
6764 gtk_icon_size_lookup_for_settings (settings,
6768 info = gtk_icon_theme_lookup_by_gicon (icon_theme,
6770 MIN (width, height),
6771 GTK_ICON_LOOKUP_USE_BUILTIN);
6774 icon_info->pixbuf = gtk_icon_info_load_icon (info, NULL);
6775 gtk_icon_info_free (info);
6778 if (icon_info->pixbuf == NULL)
6779 icon_info->pixbuf = create_normal_pixbuf (context,
6780 GTK_STOCK_MISSING_IMAGE,
6781 GTK_ICON_SIZE_MENU);
6786 g_assert_not_reached ();
6790 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
6791 gdk_window_show_unraised (icon_info->window);
6801 * Creates a new entry.
6803 * Return value: a new #GtkEntry.
6806 gtk_entry_new (void)
6808 return g_object_new (GTK_TYPE_ENTRY, NULL);
6812 * gtk_entry_new_with_buffer:
6813 * @buffer: The buffer to use for the new #GtkEntry.
6815 * Creates a new entry with the specified text buffer.
6817 * Return value: a new #GtkEntry
6822 gtk_entry_new_with_buffer (GtkEntryBuffer *buffer)
6824 g_return_val_if_fail (GTK_IS_ENTRY_BUFFER (buffer), NULL);
6825 return g_object_new (GTK_TYPE_ENTRY, "buffer", buffer, NULL);
6828 static GtkEntryBuffer*
6829 get_buffer (GtkEntry *entry)
6831 GtkEntryPrivate *priv = entry->priv;
6833 if (priv->buffer == NULL)
6835 GtkEntryBuffer *buffer;
6836 buffer = gtk_entry_buffer_new (NULL, 0);
6837 gtk_entry_set_buffer (entry, buffer);
6838 g_object_unref (buffer);
6841 return priv->buffer;
6845 * gtk_entry_get_buffer:
6846 * @entry: a #GtkEntry
6848 * Get the #GtkEntryBuffer object which holds the text for
6853 * Returns: (transfer none): A #GtkEntryBuffer object.
6856 gtk_entry_get_buffer (GtkEntry *entry)
6858 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
6860 return get_buffer (entry);
6864 * gtk_entry_set_buffer:
6865 * @entry: a #GtkEntry
6866 * @buffer: a #GtkEntryBuffer
6868 * Set the #GtkEntryBuffer object which holds the text for
6874 gtk_entry_set_buffer (GtkEntry *entry,
6875 GtkEntryBuffer *buffer)
6877 GtkEntryPrivate *priv;
6880 g_return_if_fail (GTK_IS_ENTRY (entry));
6886 g_return_if_fail (GTK_IS_ENTRY_BUFFER (buffer));
6887 g_object_ref (buffer);
6892 buffer_disconnect_signals (entry);
6893 g_object_unref (priv->buffer);
6896 priv->buffer = buffer;
6899 buffer_connect_signals (entry);
6901 obj = G_OBJECT (entry);
6902 g_object_freeze_notify (obj);
6903 g_object_notify (obj, "buffer");
6904 g_object_notify (obj, "text");
6905 g_object_notify (obj, "text-length");
6906 g_object_notify (obj, "max-length");
6907 g_object_notify (obj, "visibility");
6908 g_object_notify (obj, "invisible-char");
6909 g_object_notify (obj, "invisible-char-set");
6910 g_object_thaw_notify (obj);
6912 gtk_editable_set_position (GTK_EDITABLE (entry), 0);
6913 gtk_entry_recompute (entry);
6917 * gtk_entry_get_text_area:
6918 * @entry: a #GtkEntry
6919 * @text_area: (out): Return location for the text area.
6921 * Gets the area where the entry's text is drawn. This function is
6922 * useful when drawing something to the entry in a draw callback.
6924 * If the entry is not realized, @text_area is filled with zeros.
6926 * See also gtk_entry_get_icon_area().
6931 gtk_entry_get_text_area (GtkEntry *entry,
6932 GdkRectangle *text_area)
6934 GtkEntryPrivate *priv;
6936 g_return_if_fail (GTK_IS_ENTRY (entry));
6937 g_return_if_fail (text_area != NULL);
6941 if (priv->text_area)
6943 GtkAllocation allocation;
6946 gtk_widget_get_allocation (GTK_WIDGET (entry), &allocation);
6947 gdk_window_get_position (priv->text_area, &x, &y);
6949 text_area->x = x - allocation.x;
6950 text_area->y = y - allocation.y;
6951 text_area->width = gdk_window_get_width (priv->text_area);
6952 text_area->height = gdk_window_get_height (priv->text_area);
6958 text_area->width = 0;
6959 text_area->height = 0;
6964 * gtk_entry_set_text:
6965 * @entry: a #GtkEntry
6966 * @text: the new text
6968 * Sets the text in the widget to the given
6969 * value, replacing the current contents.
6971 * See gtk_entry_buffer_set_text().
6974 gtk_entry_set_text (GtkEntry *entry,
6978 GtkEntryCompletion *completion;
6980 g_return_if_fail (GTK_IS_ENTRY (entry));
6981 g_return_if_fail (text != NULL);
6983 /* Actually setting the text will affect the cursor and selection;
6984 * if the contents don't actually change, this will look odd to the user.
6986 if (strcmp (gtk_entry_buffer_get_text (get_buffer (entry)), text) == 0)
6989 completion = gtk_entry_get_completion (entry);
6990 if (completion && completion->priv->changed_id > 0)
6991 g_signal_handler_block (entry, completion->priv->changed_id);
6993 begin_change (entry);
6994 g_object_freeze_notify (G_OBJECT (entry));
6995 gtk_editable_delete_text (GTK_EDITABLE (entry), 0, -1);
6997 gtk_editable_insert_text (GTK_EDITABLE (entry), text, strlen (text), &tmp_pos);
6998 g_object_thaw_notify (G_OBJECT (entry));
7001 if (completion && completion->priv->changed_id > 0)
7002 g_signal_handler_unblock (entry, completion->priv->changed_id);
7006 * gtk_entry_set_visibility:
7007 * @entry: a #GtkEntry
7008 * @visible: %TRUE if the contents of the entry are displayed
7011 * Sets whether the contents of the entry are visible or not.
7012 * When visibility is set to %FALSE, characters are displayed
7013 * as the invisible char, and will also appear that way when
7014 * the text in the entry widget is copied elsewhere.
7016 * By default, GTK+ picks the best invisible character available
7017 * in the current font, but it can be changed with
7018 * gtk_entry_set_invisible_char().
7021 gtk_entry_set_visibility (GtkEntry *entry,
7024 GtkEntryPrivate *priv;
7026 g_return_if_fail (GTK_IS_ENTRY (entry));
7030 visible = visible != FALSE;
7032 if (priv->visible != visible)
7034 priv->visible = visible;
7036 g_object_notify (G_OBJECT (entry), "visibility");
7037 gtk_entry_recompute (entry);
7042 * gtk_entry_get_visibility:
7043 * @entry: a #GtkEntry
7045 * Retrieves whether the text in @entry is visible. See
7046 * gtk_entry_set_visibility().
7048 * Return value: %TRUE if the text is currently visible
7051 gtk_entry_get_visibility (GtkEntry *entry)
7053 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7055 return entry->priv->visible;
7059 * gtk_entry_set_invisible_char:
7060 * @entry: a #GtkEntry
7061 * @ch: a Unicode character
7063 * Sets the character to use in place of the actual text when
7064 * gtk_entry_set_visibility() has been called to set text visibility
7065 * to %FALSE. i.e. this is the character used in "password mode" to
7066 * show the user how many characters have been typed. By default, GTK+
7067 * picks the best invisible char available in the current font. If you
7068 * set the invisible char to 0, then the user will get no feedback
7069 * at all; there will be no text on the screen as they type.
7072 gtk_entry_set_invisible_char (GtkEntry *entry,
7075 GtkEntryPrivate *priv;
7077 g_return_if_fail (GTK_IS_ENTRY (entry));
7081 if (!priv->invisible_char_set)
7083 priv->invisible_char_set = TRUE;
7084 g_object_notify (G_OBJECT (entry), "invisible-char-set");
7087 if (ch == priv->invisible_char)
7090 priv->invisible_char = ch;
7091 g_object_notify (G_OBJECT (entry), "invisible-char");
7092 gtk_entry_recompute (entry);
7096 * gtk_entry_get_invisible_char:
7097 * @entry: a #GtkEntry
7099 * Retrieves the character displayed in place of the real characters
7100 * for entries with visibility set to false. See gtk_entry_set_invisible_char().
7102 * Return value: the current invisible char, or 0, if the entry does not
7103 * show invisible text at all.
7106 gtk_entry_get_invisible_char (GtkEntry *entry)
7108 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7110 return entry->priv->invisible_char;
7114 * gtk_entry_unset_invisible_char:
7115 * @entry: a #GtkEntry
7117 * Unsets the invisible char previously set with
7118 * gtk_entry_set_invisible_char(). So that the
7119 * default invisible char is used again.
7124 gtk_entry_unset_invisible_char (GtkEntry *entry)
7126 GtkEntryPrivate *priv;
7129 g_return_if_fail (GTK_IS_ENTRY (entry));
7133 if (!priv->invisible_char_set)
7136 priv->invisible_char_set = FALSE;
7137 ch = find_invisible_char (GTK_WIDGET (entry));
7139 if (priv->invisible_char != ch)
7141 priv->invisible_char = ch;
7142 g_object_notify (G_OBJECT (entry), "invisible-char");
7145 g_object_notify (G_OBJECT (entry), "invisible-char-set");
7146 gtk_entry_recompute (entry);
7150 * gtk_entry_set_overwrite_mode:
7151 * @entry: a #GtkEntry
7152 * @overwrite: new value
7154 * Sets whether the text is overwritten when typing in the #GtkEntry.
7159 gtk_entry_set_overwrite_mode (GtkEntry *entry,
7162 GtkEntryPrivate *priv = entry->priv;
7164 g_return_if_fail (GTK_IS_ENTRY (entry));
7166 if (priv->overwrite_mode == overwrite)
7169 gtk_entry_toggle_overwrite (entry);
7171 g_object_notify (G_OBJECT (entry), "overwrite-mode");
7175 * gtk_entry_get_overwrite_mode:
7176 * @entry: a #GtkEntry
7178 * Gets the value set by gtk_entry_set_overwrite_mode().
7180 * Return value: whether the text is overwritten when typing.
7185 gtk_entry_get_overwrite_mode (GtkEntry *entry)
7187 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7189 return entry->priv->overwrite_mode;
7193 * gtk_entry_get_text:
7194 * @entry: a #GtkEntry
7196 * Retrieves the contents of the entry widget.
7197 * See also gtk_editable_get_chars().
7199 * This is equivalent to:
7201 * <informalexample><programlisting>
7202 * gtk_entry_buffer_get_text (gtk_entry_get_buffer (entry));
7203 * </programlisting></informalexample>
7205 * Return value: a pointer to the contents of the widget as a
7206 * string. This string points to internally allocated
7207 * storage in the widget and must not be freed, modified or
7210 G_CONST_RETURN gchar*
7211 gtk_entry_get_text (GtkEntry *entry)
7213 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7215 return gtk_entry_buffer_get_text (get_buffer (entry));
7219 * gtk_entry_set_max_length:
7220 * @entry: a #GtkEntry
7221 * @max: the maximum length of the entry, or 0 for no maximum.
7222 * (other than the maximum length of entries.) The value passed in will
7223 * be clamped to the range 0-65536.
7225 * Sets the maximum allowed length of the contents of the widget. If
7226 * the current contents are longer than the given length, then they
7227 * will be truncated to fit.
7229 * This is equivalent to:
7231 * <informalexample><programlisting>
7232 * gtk_entry_buffer_set_max_length (gtk_entry_get_buffer (entry), max);
7233 * </programlisting></informalexample>
7236 gtk_entry_set_max_length (GtkEntry *entry,
7239 g_return_if_fail (GTK_IS_ENTRY (entry));
7240 gtk_entry_buffer_set_max_length (get_buffer (entry), max);
7244 * gtk_entry_get_max_length:
7245 * @entry: a #GtkEntry
7247 * Retrieves the maximum allowed length of the text in
7248 * @entry. See gtk_entry_set_max_length().
7250 * This is equivalent to:
7252 * <informalexample><programlisting>
7253 * gtk_entry_buffer_get_max_length (gtk_entry_get_buffer (entry));
7254 * </programlisting></informalexample>
7256 * Return value: the maximum allowed number of characters
7257 * in #GtkEntry, or 0 if there is no maximum.
7260 gtk_entry_get_max_length (GtkEntry *entry)
7262 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7264 return gtk_entry_buffer_get_max_length (get_buffer (entry));
7268 * gtk_entry_get_text_length:
7269 * @entry: a #GtkEntry
7271 * Retrieves the current length of the text in
7274 * This is equivalent to:
7276 * <informalexample><programlisting>
7277 * gtk_entry_buffer_get_length (gtk_entry_get_buffer (entry));
7278 * </programlisting></informalexample>
7280 * Return value: the current number of characters
7281 * in #GtkEntry, or 0 if there are none.
7286 gtk_entry_get_text_length (GtkEntry *entry)
7288 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7290 return gtk_entry_buffer_get_length (get_buffer (entry));
7294 * gtk_entry_set_activates_default:
7295 * @entry: a #GtkEntry
7296 * @setting: %TRUE to activate window's default widget on Enter keypress
7298 * If @setting is %TRUE, pressing Enter in the @entry will activate the default
7299 * widget for the window containing the entry. This usually means that
7300 * the dialog box containing the entry will be closed, since the default
7301 * widget is usually one of the dialog buttons.
7303 * (For experts: if @setting is %TRUE, the entry calls
7304 * gtk_window_activate_default() on the window containing the entry, in
7305 * the default handler for the #GtkWidget::activate signal.)
7308 gtk_entry_set_activates_default (GtkEntry *entry,
7311 GtkEntryPrivate *priv;
7313 g_return_if_fail (GTK_IS_ENTRY (entry));
7317 setting = setting != FALSE;
7319 if (setting != priv->activates_default)
7321 priv->activates_default = setting;
7322 g_object_notify (G_OBJECT (entry), "activates-default");
7327 * gtk_entry_get_activates_default:
7328 * @entry: a #GtkEntry
7330 * Retrieves the value set by gtk_entry_set_activates_default().
7332 * Return value: %TRUE if the entry will activate the default widget
7335 gtk_entry_get_activates_default (GtkEntry *entry)
7337 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7339 return entry->priv->activates_default;
7343 * gtk_entry_set_width_chars:
7344 * @entry: a #GtkEntry
7345 * @n_chars: width in chars
7347 * Changes the size request of the entry to be about the right size
7348 * for @n_chars characters. Note that it changes the size
7349 * <emphasis>request</emphasis>, the size can still be affected by
7350 * how you pack the widget into containers. If @n_chars is -1, the
7351 * size reverts to the default entry size.
7354 gtk_entry_set_width_chars (GtkEntry *entry,
7357 GtkEntryPrivate *priv;
7359 g_return_if_fail (GTK_IS_ENTRY (entry));
7363 if (priv->width_chars != n_chars)
7365 priv->width_chars = n_chars;
7366 g_object_notify (G_OBJECT (entry), "width-chars");
7367 gtk_widget_queue_resize (GTK_WIDGET (entry));
7372 * gtk_entry_get_width_chars:
7373 * @entry: a #GtkEntry
7375 * Gets the value set by gtk_entry_set_width_chars().
7377 * Return value: number of chars to request space for, or negative if unset
7380 gtk_entry_get_width_chars (GtkEntry *entry)
7382 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7384 return entry->priv->width_chars;
7388 * gtk_entry_set_has_frame:
7389 * @entry: a #GtkEntry
7390 * @setting: new value
7392 * Sets whether the entry has a beveled frame around it.
7395 gtk_entry_set_has_frame (GtkEntry *entry,
7398 GtkEntryPrivate *priv;
7400 g_return_if_fail (GTK_IS_ENTRY (entry));
7404 setting = (setting != FALSE);
7406 if (priv->has_frame == setting)
7409 gtk_widget_queue_resize (GTK_WIDGET (entry));
7410 priv->has_frame = setting;
7411 g_object_notify (G_OBJECT (entry), "has-frame");
7415 * gtk_entry_get_has_frame:
7416 * @entry: a #GtkEntry
7418 * Gets the value set by gtk_entry_set_has_frame().
7420 * Return value: whether the entry has a beveled frame
7423 gtk_entry_get_has_frame (GtkEntry *entry)
7425 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7427 return entry->priv->has_frame;
7431 * gtk_entry_set_inner_border:
7432 * @entry: a #GtkEntry
7433 * @border: (allow-none): a #GtkBorder, or %NULL
7435 * Sets %entry's inner-border property to %border, or clears it if %NULL
7436 * is passed. The inner-border is the area around the entry's text, but
7439 * If set, this property overrides the inner-border style property.
7440 * Overriding the style-provided border is useful when you want to do
7441 * in-place editing of some text in a canvas or list widget, where
7442 * pixel-exact positioning of the entry is important.
7447 gtk_entry_set_inner_border (GtkEntry *entry,
7448 const GtkBorder *border)
7450 g_return_if_fail (GTK_IS_ENTRY (entry));
7452 gtk_widget_queue_resize (GTK_WIDGET (entry));
7455 g_object_set_qdata_full (G_OBJECT (entry), quark_inner_border,
7456 gtk_border_copy (border),
7457 (GDestroyNotify) gtk_border_free);
7459 g_object_set_qdata (G_OBJECT (entry), quark_inner_border, NULL);
7461 g_object_notify (G_OBJECT (entry), "inner-border");
7465 * gtk_entry_get_inner_border:
7466 * @entry: a #GtkEntry
7468 * This function returns the entry's #GtkEntry:inner-border property. See
7469 * gtk_entry_set_inner_border() for more information.
7471 * Return value: (transfer none): the entry's #GtkBorder, or %NULL if none was set.
7475 G_CONST_RETURN GtkBorder *
7476 gtk_entry_get_inner_border (GtkEntry *entry)
7478 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7480 return g_object_get_qdata (G_OBJECT (entry), quark_inner_border);
7484 * gtk_entry_get_layout:
7485 * @entry: a #GtkEntry
7487 * Gets the #PangoLayout used to display the entry.
7488 * The layout is useful to e.g. convert text positions to
7489 * pixel positions, in combination with gtk_entry_get_layout_offsets().
7490 * The returned layout is owned by the entry and must not be
7491 * modified or freed by the caller.
7493 * Keep in mind that the layout text may contain a preedit string, so
7494 * gtk_entry_layout_index_to_text_index() and
7495 * gtk_entry_text_index_to_layout_index() are needed to convert byte
7496 * indices in the layout to byte indices in the entry contents.
7498 * Return value: (transfer none): the #PangoLayout for this entry
7501 gtk_entry_get_layout (GtkEntry *entry)
7503 PangoLayout *layout;
7505 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7507 layout = gtk_entry_ensure_layout (entry, TRUE);
7514 * gtk_entry_layout_index_to_text_index:
7515 * @entry: a #GtkEntry
7516 * @layout_index: byte index into the entry layout text
7518 * Converts from a position in the entry contents (returned
7519 * by gtk_entry_get_text()) to a position in the
7520 * entry's #PangoLayout (returned by gtk_entry_get_layout(),
7521 * with text retrieved via pango_layout_get_text()).
7523 * Return value: byte index into the entry contents
7526 gtk_entry_layout_index_to_text_index (GtkEntry *entry,
7529 GtkEntryPrivate *priv;
7530 PangoLayout *layout;
7534 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7538 layout = gtk_entry_ensure_layout (entry, TRUE);
7539 text = pango_layout_get_text (layout);
7540 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos) - text;
7542 if (layout_index >= cursor_index && priv->preedit_length)
7544 if (layout_index >= cursor_index + priv->preedit_length)
7545 layout_index -= priv->preedit_length;
7547 layout_index = cursor_index;
7550 return layout_index;
7554 * gtk_entry_text_index_to_layout_index:
7555 * @entry: a #GtkEntry
7556 * @text_index: byte index into the entry contents
7558 * Converts from a position in the entry's #PangoLayout (returned by
7559 * gtk_entry_get_layout()) to a position in the entry contents
7560 * (returned by gtk_entry_get_text()).
7562 * Return value: byte index into the entry layout text
7565 gtk_entry_text_index_to_layout_index (GtkEntry *entry,
7568 GtkEntryPrivate *priv;
7569 PangoLayout *layout;
7573 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7577 layout = gtk_entry_ensure_layout (entry, TRUE);
7578 text = pango_layout_get_text (layout);
7579 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos) - text;
7581 if (text_index > cursor_index)
7582 text_index += priv->preedit_length;
7588 * gtk_entry_get_layout_offsets:
7589 * @entry: a #GtkEntry
7590 * @x: (out) (allow-none): location to store X offset of layout, or %NULL
7591 * @y: (out) (allow-none): location to store Y offset of layout, or %NULL
7594 * Obtains the position of the #PangoLayout used to render text
7595 * in the entry, in widget coordinates. Useful if you want to line
7596 * up the text in an entry with some other text, e.g. when using the
7597 * entry to implement editable cells in a sheet widget.
7599 * Also useful to convert mouse events into coordinates inside the
7600 * #PangoLayout, e.g. to take some action if some part of the entry text
7603 * Note that as the user scrolls around in the entry the offsets will
7604 * change; you'll need to connect to the "notify::scroll-offset"
7605 * signal to track this. Remember when using the #PangoLayout
7606 * functions you need to convert to and from pixels using
7607 * PANGO_PIXELS() or #PANGO_SCALE.
7609 * Keep in mind that the layout text may contain a preedit string, so
7610 * gtk_entry_layout_index_to_text_index() and
7611 * gtk_entry_text_index_to_layout_index() are needed to convert byte
7612 * indices in the layout to byte indices in the entry contents.
7615 gtk_entry_get_layout_offsets (GtkEntry *entry,
7619 gint text_area_x, text_area_y;
7621 g_return_if_fail (GTK_IS_ENTRY (entry));
7623 /* this gets coords relative to text area */
7624 get_layout_position (entry, x, y);
7626 /* convert to widget coords */
7627 gtk_entry_get_text_area_size (entry, &text_area_x, &text_area_y, NULL, NULL);
7638 * gtk_entry_set_alignment:
7639 * @entry: a #GtkEntry
7640 * @xalign: The horizontal alignment, from 0 (left) to 1 (right).
7641 * Reversed for RTL layouts
7643 * Sets the alignment for the contents of the entry. This controls
7644 * the horizontal positioning of the contents when the displayed
7645 * text is shorter than the width of the entry.
7650 gtk_entry_set_alignment (GtkEntry *entry, gfloat xalign)
7652 GtkEntryPrivate *priv;
7654 g_return_if_fail (GTK_IS_ENTRY (entry));
7660 else if (xalign > 1.0)
7663 if (xalign != priv->xalign)
7665 priv->xalign = xalign;
7667 gtk_entry_recompute (entry);
7669 g_object_notify (G_OBJECT (entry), "xalign");
7674 * gtk_entry_get_alignment:
7675 * @entry: a #GtkEntry
7677 * Gets the value set by gtk_entry_set_alignment().
7679 * Return value: the alignment
7684 gtk_entry_get_alignment (GtkEntry *entry)
7686 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
7688 return entry->priv->xalign;
7692 * gtk_entry_set_icon_from_pixbuf:
7693 * @entry: a #GtkEntry
7694 * @icon_pos: Icon position
7695 * @pixbuf: (allow-none): A #GdkPixbuf, or %NULL
7697 * Sets the icon shown in the specified position using a pixbuf.
7699 * If @pixbuf is %NULL, no icon will be shown in the specified position.
7704 gtk_entry_set_icon_from_pixbuf (GtkEntry *entry,
7705 GtkEntryIconPosition icon_pos,
7708 GtkEntryPrivate *priv;
7709 EntryIconInfo *icon_info;
7711 g_return_if_fail (GTK_IS_ENTRY (entry));
7712 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7716 if ((icon_info = priv->icons[icon_pos]) == NULL)
7717 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7719 g_object_freeze_notify (G_OBJECT (entry));
7722 g_object_ref (pixbuf);
7724 gtk_entry_clear (entry, icon_pos);
7728 icon_info->storage_type = GTK_IMAGE_PIXBUF;
7729 icon_info->pixbuf = pixbuf;
7731 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7733 g_object_notify (G_OBJECT (entry), "primary-icon-pixbuf");
7734 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7738 g_object_notify (G_OBJECT (entry), "secondary-icon-pixbuf");
7739 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7742 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7743 gdk_window_show_unraised (icon_info->window);
7746 gtk_entry_ensure_pixbuf (entry, icon_pos);
7748 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7749 gtk_widget_queue_resize (GTK_WIDGET (entry));
7751 g_object_thaw_notify (G_OBJECT (entry));
7755 * gtk_entry_set_icon_from_stock:
7756 * @entry: A #GtkEntry
7757 * @icon_pos: Icon position
7758 * @stock_id: (allow-none): The name of the stock item, or %NULL
7760 * Sets the icon shown in the entry at the specified position from
7763 * If @stock_id is %NULL, no icon will be shown in the specified position.
7768 gtk_entry_set_icon_from_stock (GtkEntry *entry,
7769 GtkEntryIconPosition icon_pos,
7770 const gchar *stock_id)
7772 GtkEntryPrivate *priv;
7773 EntryIconInfo *icon_info;
7776 g_return_if_fail (GTK_IS_ENTRY (entry));
7777 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7781 if ((icon_info = priv->icons[icon_pos]) == NULL)
7782 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7784 g_object_freeze_notify (G_OBJECT (entry));
7786 /* need to dup before clearing */
7787 new_id = g_strdup (stock_id);
7789 gtk_entry_clear (entry, icon_pos);
7793 icon_info->storage_type = GTK_IMAGE_STOCK;
7794 icon_info->stock_id = new_id;
7796 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7798 g_object_notify (G_OBJECT (entry), "primary-icon-stock");
7799 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7803 g_object_notify (G_OBJECT (entry), "secondary-icon-stock");
7804 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7807 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7808 gdk_window_show_unraised (icon_info->window);
7811 gtk_entry_ensure_pixbuf (entry, icon_pos);
7813 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7814 gtk_widget_queue_resize (GTK_WIDGET (entry));
7816 g_object_thaw_notify (G_OBJECT (entry));
7820 * gtk_entry_set_icon_from_icon_name:
7821 * @entry: A #GtkEntry
7822 * @icon_pos: The position at which to set the icon
7823 * @icon_name: (allow-none): An icon name, or %NULL
7825 * Sets the icon shown in the entry at the specified position
7826 * from the current icon theme.
7828 * If the icon name isn't known, a "broken image" icon will be displayed
7831 * If @icon_name is %NULL, no icon will be shown in the specified position.
7836 gtk_entry_set_icon_from_icon_name (GtkEntry *entry,
7837 GtkEntryIconPosition icon_pos,
7838 const gchar *icon_name)
7840 GtkEntryPrivate *priv;
7841 EntryIconInfo *icon_info;
7844 g_return_if_fail (GTK_IS_ENTRY (entry));
7845 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7849 if ((icon_info = priv->icons[icon_pos]) == NULL)
7850 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7852 g_object_freeze_notify (G_OBJECT (entry));
7854 /* need to dup before clearing */
7855 new_name = g_strdup (icon_name);
7857 gtk_entry_clear (entry, icon_pos);
7859 if (new_name != NULL)
7861 icon_info->storage_type = GTK_IMAGE_ICON_NAME;
7862 icon_info->icon_name = new_name;
7864 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7866 g_object_notify (G_OBJECT (entry), "primary-icon-name");
7867 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7871 g_object_notify (G_OBJECT (entry), "secondary-icon-name");
7872 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7875 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7876 gdk_window_show_unraised (icon_info->window);
7879 gtk_entry_ensure_pixbuf (entry, icon_pos);
7881 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7882 gtk_widget_queue_resize (GTK_WIDGET (entry));
7884 g_object_thaw_notify (G_OBJECT (entry));
7888 * gtk_entry_set_icon_from_gicon:
7889 * @entry: A #GtkEntry
7890 * @icon_pos: The position at which to set the icon
7891 * @icon: (allow-none): The icon to set, or %NULL
7893 * Sets the icon shown in the entry at the specified position
7894 * from the current icon theme.
7895 * If the icon isn't known, a "broken image" icon will be displayed
7898 * If @icon is %NULL, no icon will be shown in the specified position.
7903 gtk_entry_set_icon_from_gicon (GtkEntry *entry,
7904 GtkEntryIconPosition icon_pos,
7907 GtkEntryPrivate *priv;
7908 EntryIconInfo *icon_info;
7910 g_return_if_fail (GTK_IS_ENTRY (entry));
7911 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7915 if ((icon_info = priv->icons[icon_pos]) == NULL)
7916 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7918 g_object_freeze_notify (G_OBJECT (entry));
7920 /* need to ref before clearing */
7922 g_object_ref (icon);
7924 gtk_entry_clear (entry, icon_pos);
7928 icon_info->storage_type = GTK_IMAGE_GICON;
7929 icon_info->gicon = icon;
7931 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7933 g_object_notify (G_OBJECT (entry), "primary-icon-gicon");
7934 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7938 g_object_notify (G_OBJECT (entry), "secondary-icon-gicon");
7939 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7942 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7943 gdk_window_show_unraised (icon_info->window);
7946 gtk_entry_ensure_pixbuf (entry, icon_pos);
7948 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7949 gtk_widget_queue_resize (GTK_WIDGET (entry));
7951 g_object_thaw_notify (G_OBJECT (entry));
7955 * gtk_entry_set_icon_activatable:
7956 * @entry: A #GtkEntry
7957 * @icon_pos: Icon position
7958 * @activatable: %TRUE if the icon should be activatable
7960 * Sets whether the icon is activatable.
7965 gtk_entry_set_icon_activatable (GtkEntry *entry,
7966 GtkEntryIconPosition icon_pos,
7967 gboolean activatable)
7969 GtkEntryPrivate *priv;
7970 EntryIconInfo *icon_info;
7972 g_return_if_fail (GTK_IS_ENTRY (entry));
7973 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7977 if ((icon_info = priv->icons[icon_pos]) == NULL)
7978 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7980 activatable = activatable != FALSE;
7982 if (icon_info->nonactivatable != !activatable)
7984 icon_info->nonactivatable = !activatable;
7986 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
7987 update_cursors (GTK_WIDGET (entry));
7989 g_object_notify (G_OBJECT (entry),
7990 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-activatable" : "secondary-icon-activatable");
7995 * gtk_entry_get_icon_activatable:
7996 * @entry: a #GtkEntry
7997 * @icon_pos: Icon position
7999 * Returns whether the icon is activatable.
8001 * Returns: %TRUE if the icon is activatable.
8006 gtk_entry_get_icon_activatable (GtkEntry *entry,
8007 GtkEntryIconPosition icon_pos)
8009 GtkEntryPrivate *priv;
8010 EntryIconInfo *icon_info;
8012 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
8013 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), FALSE);
8016 icon_info = priv->icons[icon_pos];
8018 return (!icon_info || !icon_info->nonactivatable);
8022 * gtk_entry_get_icon_pixbuf:
8023 * @entry: A #GtkEntry
8024 * @icon_pos: Icon position
8026 * Retrieves the image used for the icon.
8028 * Unlike the other methods of setting and getting icon data, this
8029 * method will work regardless of whether the icon was set using a
8030 * #GdkPixbuf, a #GIcon, a stock item, or an icon name.
8032 * Returns: (transfer none): A #GdkPixbuf, or %NULL if no icon is
8033 * set for this position.
8038 gtk_entry_get_icon_pixbuf (GtkEntry *entry,
8039 GtkEntryIconPosition icon_pos)
8041 GtkEntryPrivate *priv;
8042 EntryIconInfo *icon_info;
8044 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8045 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8049 icon_info = priv->icons[icon_pos];
8054 gtk_entry_ensure_pixbuf (entry, icon_pos);
8056 return icon_info->pixbuf;
8060 * gtk_entry_get_icon_gicon:
8061 * @entry: A #GtkEntry
8062 * @icon_pos: Icon position
8064 * Retrieves the #GIcon used for the icon, or %NULL if there is
8065 * no icon or if the icon was set by some other method (e.g., by
8066 * stock, pixbuf, or icon name).
8068 * Returns: (transfer none): A #GIcon, or %NULL if no icon is set
8069 * or if the icon is not a #GIcon
8074 gtk_entry_get_icon_gicon (GtkEntry *entry,
8075 GtkEntryIconPosition icon_pos)
8077 GtkEntryPrivate *priv;
8078 EntryIconInfo *icon_info;
8080 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8081 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8084 icon_info = priv->icons[icon_pos];
8089 return icon_info->storage_type == GTK_IMAGE_GICON ? icon_info->gicon : NULL;
8093 * gtk_entry_get_icon_stock:
8094 * @entry: A #GtkEntry
8095 * @icon_pos: Icon position
8097 * Retrieves the stock id used for the icon, or %NULL if there is
8098 * no icon or if the icon was set by some other method (e.g., by
8099 * pixbuf, icon name or gicon).
8101 * Returns: A stock id, or %NULL if no icon is set or if the icon
8102 * wasn't set from a stock id
8107 gtk_entry_get_icon_stock (GtkEntry *entry,
8108 GtkEntryIconPosition icon_pos)
8110 GtkEntryPrivate *priv;
8111 EntryIconInfo *icon_info;
8113 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8114 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8117 icon_info = priv->icons[icon_pos];
8122 return icon_info->storage_type == GTK_IMAGE_STOCK ? icon_info->stock_id : NULL;
8126 * gtk_entry_get_icon_name:
8127 * @entry: A #GtkEntry
8128 * @icon_pos: Icon position
8130 * Retrieves the icon name used for the icon, or %NULL if there is
8131 * no icon or if the icon was set by some other method (e.g., by
8132 * pixbuf, stock or gicon).
8134 * Returns: An icon name, or %NULL if no icon is set or if the icon
8135 * wasn't set from an icon name
8140 gtk_entry_get_icon_name (GtkEntry *entry,
8141 GtkEntryIconPosition icon_pos)
8143 GtkEntryPrivate *priv;
8144 EntryIconInfo *icon_info;
8146 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8147 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8150 icon_info = priv->icons[icon_pos];
8155 return icon_info->storage_type == GTK_IMAGE_ICON_NAME ? icon_info->icon_name : NULL;
8159 * gtk_entry_set_icon_sensitive:
8160 * @entry: A #GtkEntry
8161 * @icon_pos: Icon position
8162 * @sensitive: Specifies whether the icon should appear
8163 * sensitive or insensitive
8165 * Sets the sensitivity for the specified icon.
8170 gtk_entry_set_icon_sensitive (GtkEntry *entry,
8171 GtkEntryIconPosition icon_pos,
8174 GtkEntryPrivate *priv;
8175 EntryIconInfo *icon_info;
8177 g_return_if_fail (GTK_IS_ENTRY (entry));
8178 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8182 if ((icon_info = priv->icons[icon_pos]) == NULL)
8183 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8185 if (icon_info->insensitive != !sensitive)
8187 icon_info->insensitive = !sensitive;
8189 icon_info->pressed = FALSE;
8190 icon_info->prelight = FALSE;
8192 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
8193 update_cursors (GTK_WIDGET (entry));
8195 gtk_widget_queue_draw (GTK_WIDGET (entry));
8197 g_object_notify (G_OBJECT (entry),
8198 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-sensitive" : "secondary-icon-sensitive");
8203 * gtk_entry_get_icon_sensitive:
8204 * @entry: a #GtkEntry
8205 * @icon_pos: Icon position
8207 * Returns whether the icon appears sensitive or insensitive.
8209 * Returns: %TRUE if the icon is sensitive.
8214 gtk_entry_get_icon_sensitive (GtkEntry *entry,
8215 GtkEntryIconPosition icon_pos)
8217 GtkEntryPrivate *priv;
8218 EntryIconInfo *icon_info;
8220 g_return_val_if_fail (GTK_IS_ENTRY (entry), TRUE);
8221 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), TRUE);
8225 icon_info = priv->icons[icon_pos];
8227 return (!icon_info || !icon_info->insensitive);
8232 * gtk_entry_get_icon_storage_type:
8233 * @entry: a #GtkEntry
8234 * @icon_pos: Icon position
8236 * Gets the type of representation being used by the icon
8237 * to store image data. If the icon has no image data,
8238 * the return value will be %GTK_IMAGE_EMPTY.
8240 * Return value: image representation being used
8245 gtk_entry_get_icon_storage_type (GtkEntry *entry,
8246 GtkEntryIconPosition icon_pos)
8248 GtkEntryPrivate *priv;
8249 EntryIconInfo *icon_info;
8251 g_return_val_if_fail (GTK_IS_ENTRY (entry), GTK_IMAGE_EMPTY);
8252 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), GTK_IMAGE_EMPTY);
8256 icon_info = priv->icons[icon_pos];
8259 return GTK_IMAGE_EMPTY;
8261 return icon_info->storage_type;
8265 * gtk_entry_get_icon_at_pos:
8266 * @entry: a #GtkEntry
8267 * @x: the x coordinate of the position to find
8268 * @y: the y coordinate of the position to find
8270 * Finds the icon at the given position and return its index.
8271 * If @x, @y doesn't lie inside an icon, -1 is returned.
8272 * This function is intended for use in a #GtkWidget::query-tooltip
8275 * Returns: the index of the icon at the given position, or -1
8280 gtk_entry_get_icon_at_pos (GtkEntry *entry,
8284 GtkAllocation primary;
8285 GtkAllocation secondary;
8286 gint frame_x, frame_y;
8288 g_return_val_if_fail (GTK_IS_ENTRY (entry), -1);
8290 get_frame_size (entry, &frame_x, &frame_y, NULL, NULL);
8294 get_icon_allocations (entry, &primary, &secondary);
8296 if (primary.x <= x && x < primary.x + primary.width &&
8297 primary.y <= y && y < primary.y + primary.height)
8298 return GTK_ENTRY_ICON_PRIMARY;
8300 if (secondary.x <= x && x < secondary.x + secondary.width &&
8301 secondary.y <= y && y < secondary.y + secondary.height)
8302 return GTK_ENTRY_ICON_SECONDARY;
8308 * gtk_entry_set_icon_drag_source:
8309 * @entry: a #GtkIconEntry
8310 * @icon_pos: icon position
8311 * @target_list: the targets (data formats) in which the data can be provided
8312 * @actions: a bitmask of the allowed drag actions
8314 * Sets up the icon at the given position so that GTK+ will start a drag
8315 * operation when the user clicks and drags the icon.
8317 * To handle the drag operation, you need to connect to the usual
8318 * #GtkWidget::drag-data-get (or possibly #GtkWidget::drag-data-delete)
8319 * signal, and use gtk_entry_get_current_icon_drag_source() in
8320 * your signal handler to find out if the drag was started from
8323 * By default, GTK+ uses the icon as the drag icon. You can use the
8324 * #GtkWidget::drag-begin signal to set a different icon. Note that you
8325 * have to use g_signal_connect_after() to ensure that your signal handler
8326 * gets executed after the default handler.
8331 gtk_entry_set_icon_drag_source (GtkEntry *entry,
8332 GtkEntryIconPosition icon_pos,
8333 GtkTargetList *target_list,
8334 GdkDragAction actions)
8336 GtkEntryPrivate *priv;
8337 EntryIconInfo *icon_info;
8339 g_return_if_fail (GTK_IS_ENTRY (entry));
8340 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8344 if ((icon_info = priv->icons[icon_pos]) == NULL)
8345 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8347 if (icon_info->target_list)
8348 gtk_target_list_unref (icon_info->target_list);
8349 icon_info->target_list = target_list;
8350 if (icon_info->target_list)
8351 gtk_target_list_ref (icon_info->target_list);
8353 icon_info->actions = actions;
8357 * gtk_entry_get_current_icon_drag_source:
8358 * @entry: a #GtkIconEntry
8360 * Returns the index of the icon which is the source of the current
8361 * DND operation, or -1.
8363 * This function is meant to be used in a #GtkWidget::drag-data-get
8366 * Returns: index of the icon which is the source of the current
8367 * DND operation, or -1.
8372 gtk_entry_get_current_icon_drag_source (GtkEntry *entry)
8374 GtkEntryPrivate *priv;
8375 EntryIconInfo *icon_info = NULL;
8378 g_return_val_if_fail (GTK_IS_ENTRY (entry), -1);
8382 for (i = 0; i < MAX_ICONS; i++)
8384 if ((icon_info = priv->icons[i]))
8386 if (icon_info->in_drag)
8395 * gtk_entry_get_icon_area:
8396 * @entry: A #GtkEntry
8397 * @icon_pos: Icon position
8398 * @icon_area: (out): Return location for the icon's area
8400 * Gets the area where entry's icon at @icon_pos is drawn.
8401 * This function is useful when drawing something to the
8402 * entry in a draw callback.
8404 * If the entry is not realized or has no icon at the given position,
8405 * @icon_area is filled with zeros.
8407 * See also gtk_entry_get_text_area()
8412 gtk_entry_get_icon_area (GtkEntry *entry,
8413 GtkEntryIconPosition icon_pos,
8414 GdkRectangle *icon_area)
8416 GtkEntryPrivate *priv;
8417 EntryIconInfo *icon_info;
8419 g_return_if_fail (GTK_IS_ENTRY (entry));
8420 g_return_if_fail (icon_area != NULL);
8424 icon_info = priv->icons[icon_pos];
8428 GtkAllocation primary;
8429 GtkAllocation secondary;
8431 get_icon_allocations (entry, &primary, &secondary);
8433 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
8434 *icon_area = primary;
8436 *icon_area = secondary;
8442 icon_area->width = 0;
8443 icon_area->height = 0;
8448 ensure_has_tooltip (GtkEntry *entry)
8450 GtkEntryPrivate *priv;
8451 EntryIconInfo *icon_info;
8453 gboolean has_tooltip = FALSE;
8457 for (i = 0; i < MAX_ICONS; i++)
8459 if ((icon_info = priv->icons[i]) != NULL)
8461 if (icon_info->tooltip != NULL)
8469 gtk_widget_set_has_tooltip (GTK_WIDGET (entry), has_tooltip);
8473 * gtk_entry_get_icon_tooltip_text:
8474 * @entry: a #GtkEntry
8475 * @icon_pos: the icon position
8477 * Gets the contents of the tooltip on the icon at the specified
8478 * position in @entry.
8480 * Returns: the tooltip text, or %NULL. Free the returned string
8481 * with g_free() when done.
8486 gtk_entry_get_icon_tooltip_text (GtkEntry *entry,
8487 GtkEntryIconPosition icon_pos)
8489 GtkEntryPrivate *priv;
8490 EntryIconInfo *icon_info;
8493 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8494 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8498 icon_info = priv->icons[icon_pos];
8503 if (icon_info->tooltip &&
8504 !pango_parse_markup (icon_info->tooltip, -1, 0, NULL, &text, NULL, NULL))
8505 g_assert (NULL == text); /* text should still be NULL in case of markup errors */
8511 * gtk_entry_set_icon_tooltip_text:
8512 * @entry: a #GtkEntry
8513 * @icon_pos: the icon position
8514 * @tooltip: (allow-none): the contents of the tooltip for the icon, or %NULL
8516 * Sets @tooltip as the contents of the tooltip for the icon
8517 * at the specified position.
8519 * Use %NULL for @tooltip to remove an existing tooltip.
8521 * See also gtk_widget_set_tooltip_text() and
8522 * gtk_entry_set_icon_tooltip_markup().
8527 gtk_entry_set_icon_tooltip_text (GtkEntry *entry,
8528 GtkEntryIconPosition icon_pos,
8529 const gchar *tooltip)
8531 GtkEntryPrivate *priv;
8532 EntryIconInfo *icon_info;
8534 g_return_if_fail (GTK_IS_ENTRY (entry));
8535 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8539 if ((icon_info = priv->icons[icon_pos]) == NULL)
8540 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8542 if (icon_info->tooltip)
8543 g_free (icon_info->tooltip);
8545 /* Treat an empty string as a NULL string,
8546 * because an empty string would be useless for a tooltip:
8548 if (tooltip && tooltip[0] == '\0')
8551 icon_info->tooltip = tooltip ? g_markup_escape_text (tooltip, -1) : NULL;
8553 ensure_has_tooltip (entry);
8557 * gtk_entry_get_icon_tooltip_markup:
8558 * @entry: a #GtkEntry
8559 * @icon_pos: the icon position
8561 * Gets the contents of the tooltip on the icon at the specified
8562 * position in @entry.
8564 * Returns: the tooltip text, or %NULL. Free the returned string
8565 * with g_free() when done.
8570 gtk_entry_get_icon_tooltip_markup (GtkEntry *entry,
8571 GtkEntryIconPosition icon_pos)
8573 GtkEntryPrivate *priv;
8574 EntryIconInfo *icon_info;
8576 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8577 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8581 icon_info = priv->icons[icon_pos];
8586 return g_strdup (icon_info->tooltip);
8590 * gtk_entry_set_icon_tooltip_markup:
8591 * @entry: a #GtkEntry
8592 * @icon_pos: the icon position
8593 * @tooltip: (allow-none): the contents of the tooltip for the icon, or %NULL
8595 * Sets @tooltip as the contents of the tooltip for the icon at
8596 * the specified position. @tooltip is assumed to be marked up with
8597 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
8599 * Use %NULL for @tooltip to remove an existing tooltip.
8601 * See also gtk_widget_set_tooltip_markup() and
8602 * gtk_enty_set_icon_tooltip_text().
8607 gtk_entry_set_icon_tooltip_markup (GtkEntry *entry,
8608 GtkEntryIconPosition icon_pos,
8609 const gchar *tooltip)
8611 GtkEntryPrivate *priv;
8612 EntryIconInfo *icon_info;
8614 g_return_if_fail (GTK_IS_ENTRY (entry));
8615 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8619 if ((icon_info = priv->icons[icon_pos]) == NULL)
8620 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8622 if (icon_info->tooltip)
8623 g_free (icon_info->tooltip);
8625 /* Treat an empty string as a NULL string,
8626 * because an empty string would be useless for a tooltip:
8628 if (tooltip && tooltip[0] == '\0')
8631 icon_info->tooltip = g_strdup (tooltip);
8633 ensure_has_tooltip (entry);
8637 gtk_entry_query_tooltip (GtkWidget *widget,
8640 gboolean keyboard_tip,
8641 GtkTooltip *tooltip)
8644 GtkEntryPrivate *priv;
8645 EntryIconInfo *icon_info;
8648 entry = GTK_ENTRY (widget);
8653 icon_pos = gtk_entry_get_icon_at_pos (entry, x, y);
8656 if ((icon_info = priv->icons[icon_pos]) != NULL)
8658 if (icon_info->tooltip)
8660 gtk_tooltip_set_markup (tooltip, icon_info->tooltip);
8669 return GTK_WIDGET_CLASS (gtk_entry_parent_class)->query_tooltip (widget,
8676 /* Quick hack of a popup menu
8679 activate_cb (GtkWidget *menuitem,
8682 const gchar *signal = g_object_get_data (G_OBJECT (menuitem), "gtk-signal");
8683 g_signal_emit_by_name (entry, signal);
8688 gtk_entry_mnemonic_activate (GtkWidget *widget,
8689 gboolean group_cycling)
8691 gtk_widget_grab_focus (widget);
8696 append_action_signal (GtkEntry *entry,
8698 const gchar *stock_id,
8699 const gchar *signal,
8702 GtkWidget *menuitem = gtk_image_menu_item_new_from_stock (stock_id, NULL);
8704 g_object_set_data (G_OBJECT (menuitem), I_("gtk-signal"), (char *)signal);
8705 g_signal_connect (menuitem, "activate",
8706 G_CALLBACK (activate_cb), entry);
8708 gtk_widget_set_sensitive (menuitem, sensitive);
8710 gtk_widget_show (menuitem);
8711 gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
8715 popup_menu_detach (GtkWidget *attach_widget,
8718 GtkEntry *entry_attach = GTK_ENTRY (attach_widget);
8719 GtkEntryPrivate *priv_attach = entry_attach->priv;
8721 priv_attach->popup_menu = NULL;
8725 popup_position_func (GtkMenu *menu,
8731 GtkEntry *entry = GTK_ENTRY (user_data);
8732 GtkEntryPrivate *priv = entry->priv;
8733 GtkWidget *widget = GTK_WIDGET (entry);
8735 GtkRequisition menu_req;
8736 GdkRectangle monitor;
8737 GtkBorder inner_border;
8738 gint monitor_num, strong_x, height;
8740 g_return_if_fail (gtk_widget_get_realized (widget));
8742 gdk_window_get_origin (priv->text_area, x, y);
8744 screen = gtk_widget_get_screen (widget);
8745 monitor_num = gdk_screen_get_monitor_at_window (screen, priv->text_area);
8746 if (monitor_num < 0)
8748 gtk_menu_set_monitor (menu, monitor_num);
8750 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
8751 gtk_widget_get_preferred_size (priv->popup_menu,
8753 height = gdk_window_get_height (priv->text_area);
8754 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
8755 _gtk_entry_effective_inner_border (entry, &inner_border);
8757 *x += inner_border.left + strong_x - priv->scroll_offset;
8758 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
8759 *x -= menu_req.width;
8761 if ((*y + height + menu_req.height) <= monitor.y + monitor.height)
8763 else if ((*y - menu_req.height) >= monitor.y)
8764 *y -= menu_req.height;
8765 else if (monitor.y + monitor.height - (*y + height) > *y)
8768 *y -= menu_req.height;
8774 unichar_chosen_func (const char *text,
8777 GtkEntry *entry = GTK_ENTRY (data);
8778 GtkEntryPrivate *priv = entry->priv;
8781 gtk_entry_enter_text (entry, text);
8792 popup_targets_received (GtkClipboard *clipboard,
8793 GtkSelectionData *data,
8796 PopupInfo *info = user_data;
8797 GtkEntry *entry = info->entry;
8798 GtkEntryPrivate *info_entry_priv = entry->priv;
8800 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
8803 gboolean clipboard_contains_text;
8804 GtkWidget *menuitem;
8806 gboolean show_input_method_menu;
8807 gboolean show_unicode_menu;
8809 clipboard_contains_text = gtk_selection_data_targets_include_text (data);
8810 if (info_entry_priv->popup_menu)
8811 gtk_widget_destroy (info_entry_priv->popup_menu);
8813 info_entry_priv->popup_menu = gtk_menu_new ();
8815 gtk_menu_attach_to_widget (GTK_MENU (info_entry_priv->popup_menu),
8819 mode = gtk_entry_get_display_mode (entry);
8820 append_action_signal (entry, info_entry_priv->popup_menu, GTK_STOCK_CUT, "cut-clipboard",
8821 info_entry_priv->editable && mode == DISPLAY_NORMAL &&
8822 info_entry_priv->current_pos != info_entry_priv->selection_bound);
8824 append_action_signal (entry, info_entry_priv->popup_menu, GTK_STOCK_COPY, "copy-clipboard",
8825 mode == DISPLAY_NORMAL &&
8826 info_entry_priv->current_pos != info_entry_priv->selection_bound);
8828 append_action_signal (entry, info_entry_priv->popup_menu, GTK_STOCK_PASTE, "paste-clipboard",
8829 info_entry_priv->editable && clipboard_contains_text);
8831 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_DELETE, NULL);
8832 gtk_widget_set_sensitive (menuitem, info_entry_priv->editable && info_entry_priv->current_pos != info_entry_priv->selection_bound);
8833 g_signal_connect_swapped (menuitem, "activate",
8834 G_CALLBACK (gtk_entry_delete_cb), entry);
8835 gtk_widget_show (menuitem);
8836 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8838 menuitem = gtk_separator_menu_item_new ();
8839 gtk_widget_show (menuitem);
8840 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8842 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_SELECT_ALL, NULL);
8843 g_signal_connect_swapped (menuitem, "activate",
8844 G_CALLBACK (gtk_entry_select_all), entry);
8845 gtk_widget_show (menuitem);
8846 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8848 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
8849 "gtk-show-input-method-menu", &show_input_method_menu,
8850 "gtk-show-unicode-menu", &show_unicode_menu,
8853 if (show_input_method_menu || show_unicode_menu)
8855 menuitem = gtk_separator_menu_item_new ();
8856 gtk_widget_show (menuitem);
8857 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8860 if (show_input_method_menu)
8862 menuitem = gtk_menu_item_new_with_mnemonic (_("Input _Methods"));
8863 gtk_widget_set_sensitive (menuitem, info_entry_priv->editable);
8864 gtk_widget_show (menuitem);
8865 submenu = gtk_menu_new ();
8866 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
8868 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8870 gtk_im_multicontext_append_menuitems (GTK_IM_MULTICONTEXT (info_entry_priv->im_context),
8871 GTK_MENU_SHELL (submenu));
8874 if (show_unicode_menu)
8876 menuitem = gtk_menu_item_new_with_mnemonic (_("_Insert Unicode Control Character"));
8877 gtk_widget_set_sensitive (menuitem, info_entry_priv->editable);
8878 gtk_widget_show (menuitem);
8880 submenu = gtk_menu_new ();
8881 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
8882 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8884 _gtk_text_util_append_special_char_menuitems (GTK_MENU_SHELL (submenu),
8885 unichar_chosen_func,
8889 g_signal_emit (entry,
8890 signals[POPULATE_POPUP],
8892 info_entry_priv->popup_menu);
8896 gtk_menu_popup (GTK_MENU (info_entry_priv->popup_menu), NULL, NULL,
8898 info->button, info->time);
8901 gtk_menu_popup (GTK_MENU (info_entry_priv->popup_menu), NULL, NULL,
8902 popup_position_func, entry,
8903 info->button, info->time);
8904 gtk_menu_shell_select_first (GTK_MENU_SHELL (info_entry_priv->popup_menu), FALSE);
8908 g_object_unref (entry);
8909 g_slice_free (PopupInfo, info);
8913 gtk_entry_do_popup (GtkEntry *entry,
8914 GdkEventButton *event)
8916 PopupInfo *info = g_slice_new (PopupInfo);
8918 /* In order to know what entries we should make sensitive, we
8919 * ask for the current targets of the clipboard, and when
8920 * we get them, then we actually pop up the menu.
8922 info->entry = g_object_ref (entry);
8926 info->button = event->button;
8927 info->time = event->time;
8932 info->time = gtk_get_current_event_time ();
8935 gtk_clipboard_request_contents (gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_CLIPBOARD),
8936 gdk_atom_intern_static_string ("TARGETS"),
8937 popup_targets_received,
8942 gtk_entry_popup_menu (GtkWidget *widget)
8944 gtk_entry_do_popup (GTK_ENTRY (widget), NULL);
8949 gtk_entry_drag_begin (GtkWidget *widget,
8950 GdkDragContext *context)
8952 GtkEntry *entry = GTK_ENTRY (widget);
8953 GtkEntryPrivate *priv = entry->priv;
8956 for (i = 0; i < MAX_ICONS; i++)
8958 EntryIconInfo *icon_info = priv->icons[i];
8960 if (icon_info != NULL)
8962 if (icon_info->in_drag)
8964 switch (icon_info->storage_type)
8966 case GTK_IMAGE_STOCK:
8967 gtk_drag_set_icon_stock (context, icon_info->stock_id, -2, -2);
8970 case GTK_IMAGE_ICON_NAME:
8971 gtk_drag_set_icon_name (context, icon_info->icon_name, -2, -2);
8974 /* FIXME: No GIcon support for dnd icons */
8975 case GTK_IMAGE_GICON:
8976 case GTK_IMAGE_PIXBUF:
8977 gtk_drag_set_icon_pixbuf (context, icon_info->pixbuf, -2, -2);
8980 g_assert_not_reached ();
8988 gtk_entry_drag_end (GtkWidget *widget,
8989 GdkDragContext *context)
8991 GtkEntry *entry = GTK_ENTRY (widget);
8992 GtkEntryPrivate *priv = entry->priv;
8995 for (i = 0; i < MAX_ICONS; i++)
8997 EntryIconInfo *icon_info = priv->icons[i];
8999 if (icon_info != NULL)
9000 icon_info->in_drag = 0;
9005 gtk_entry_drag_leave (GtkWidget *widget,
9006 GdkDragContext *context,
9009 GtkEntry *entry = GTK_ENTRY (widget);
9010 GtkEntryPrivate *priv = entry->priv;
9012 priv->dnd_position = -1;
9013 gtk_widget_queue_draw (widget);
9017 gtk_entry_drag_drop (GtkWidget *widget,
9018 GdkDragContext *context,
9023 GtkEntry *entry = GTK_ENTRY (widget);
9024 GtkEntryPrivate *priv = entry->priv;
9025 GdkAtom target = GDK_NONE;
9028 target = gtk_drag_dest_find_target (widget, context, NULL);
9030 if (target != GDK_NONE)
9031 gtk_drag_get_data (widget, context, target, time);
9033 gtk_drag_finish (context, FALSE, FALSE, time);
9039 gtk_entry_drag_motion (GtkWidget *widget,
9040 GdkDragContext *context,
9045 GtkEntry *entry = GTK_ENTRY (widget);
9046 GtkEntryPrivate *priv = entry->priv;
9047 GtkStyleContext *style_context;
9048 GtkWidget *source_widget;
9049 GdkDragAction suggested_action;
9050 gint new_position, old_position;
9054 style_context = gtk_widget_get_style_context (widget);
9055 gtk_style_context_get_padding (style_context, 0, &padding);
9059 old_position = priv->dnd_position;
9060 new_position = gtk_entry_find_position (entry, x + priv->scroll_offset);
9062 if (priv->editable &&
9063 gtk_drag_dest_find_target (widget, context, NULL) != GDK_NONE)
9065 source_widget = gtk_drag_get_source_widget (context);
9066 suggested_action = gdk_drag_context_get_suggested_action (context);
9068 if (!gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &sel1, &sel2) ||
9069 new_position < sel1 || new_position > sel2)
9071 if (source_widget == widget)
9073 /* Default to MOVE, unless the user has
9074 * pressed ctrl or alt to affect available actions
9076 if ((gdk_drag_context_get_actions (context) & GDK_ACTION_MOVE) != 0)
9077 suggested_action = GDK_ACTION_MOVE;
9080 priv->dnd_position = new_position;
9084 if (source_widget == widget)
9085 suggested_action = 0; /* Can't drop in selection where drag started */
9087 priv->dnd_position = -1;
9092 /* Entry not editable, or no text */
9093 suggested_action = 0;
9094 priv->dnd_position = -1;
9097 gdk_drag_status (context, suggested_action, time);
9099 if (priv->dnd_position != old_position)
9100 gtk_widget_queue_draw (widget);
9106 gtk_entry_drag_data_received (GtkWidget *widget,
9107 GdkDragContext *context,
9110 GtkSelectionData *selection_data,
9114 GtkEntry *entry = GTK_ENTRY (widget);
9115 GtkEntryPrivate *priv = entry->priv;
9116 GtkEditable *editable = GTK_EDITABLE (widget);
9117 GtkStyleContext *style_context;
9121 str = (gchar *) gtk_selection_data_get_text (selection_data);
9123 style_context = gtk_widget_get_style_context (widget);
9124 gtk_style_context_get_padding (style_context, 0, &padding);
9128 if (str && priv->editable)
9134 if (priv->truncate_multiline)
9135 length = truncate_multiline (str);
9137 new_position = gtk_entry_find_position (entry, x + priv->scroll_offset);
9139 if (!gtk_editable_get_selection_bounds (editable, &sel1, &sel2) ||
9140 new_position < sel1 || new_position > sel2)
9142 gtk_editable_insert_text (editable, str, length, &new_position);
9146 /* Replacing selection */
9147 begin_change (entry);
9148 g_object_freeze_notify (G_OBJECT (entry));
9149 gtk_editable_delete_text (editable, sel1, sel2);
9150 gtk_editable_insert_text (editable, str, length, &sel1);
9151 g_object_thaw_notify (G_OBJECT (entry));
9155 gtk_drag_finish (context, TRUE, gdk_drag_context_get_selected_action (context) == GDK_ACTION_MOVE, time);
9159 /* Drag and drop didn't happen! */
9160 gtk_drag_finish (context, FALSE, FALSE, time);
9167 gtk_entry_drag_data_get (GtkWidget *widget,
9168 GdkDragContext *context,
9169 GtkSelectionData *selection_data,
9173 GtkEntry *entry = GTK_ENTRY (widget);
9174 GtkEntryPrivate *priv = entry->priv;
9175 GtkEditable *editable = GTK_EDITABLE (widget);
9176 gint sel_start, sel_end;
9179 /* If there is an icon drag going on, exit early. */
9180 for (i = 0; i < MAX_ICONS; i++)
9182 EntryIconInfo *icon_info = priv->icons[i];
9184 if (icon_info != NULL)
9186 if (icon_info->in_drag)
9191 if (gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end))
9193 gchar *str = gtk_entry_get_display_text (GTK_ENTRY (widget), sel_start, sel_end);
9195 gtk_selection_data_set_text (selection_data, str, -1);
9203 gtk_entry_drag_data_delete (GtkWidget *widget,
9204 GdkDragContext *context)
9206 GtkEntry *entry = GTK_ENTRY (widget);
9207 GtkEntryPrivate *priv = entry->priv;
9208 GtkEditable *editable = GTK_EDITABLE (widget);
9209 gint sel_start, sel_end;
9212 /* If there is an icon drag going on, exit early. */
9213 for (i = 0; i < MAX_ICONS; i++)
9215 EntryIconInfo *icon_info = priv->icons[i];
9217 if (icon_info != NULL)
9219 if (icon_info->in_drag)
9224 if (priv->editable &&
9225 gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end))
9226 gtk_editable_delete_text (editable, sel_start, sel_end);
9229 /* We display the cursor when
9231 * - the selection is empty, AND
9232 * - the widget has focus
9235 #define CURSOR_ON_MULTIPLIER 2
9236 #define CURSOR_OFF_MULTIPLIER 1
9237 #define CURSOR_PEND_MULTIPLIER 3
9238 #define CURSOR_DIVIDER 3
9241 cursor_blinks (GtkEntry *entry)
9243 GtkEntryPrivate *priv = entry->priv;
9245 if (gtk_widget_has_focus (GTK_WIDGET (entry)) &&
9247 priv->selection_bound == priv->current_pos)
9249 GtkSettings *settings;
9252 settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9253 g_object_get (settings, "gtk-cursor-blink", &blink, NULL);
9262 get_cursor_time (GtkEntry *entry)
9264 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9267 g_object_get (settings, "gtk-cursor-blink-time", &time, NULL);
9273 get_cursor_blink_timeout (GtkEntry *entry)
9275 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9278 g_object_get (settings, "gtk-cursor-blink-timeout", &timeout, NULL);
9284 show_cursor (GtkEntry *entry)
9286 GtkEntryPrivate *priv = entry->priv;
9289 if (!priv->cursor_visible)
9291 priv->cursor_visible = TRUE;
9293 widget = GTK_WIDGET (entry);
9294 if (gtk_widget_has_focus (widget) && priv->selection_bound == priv->current_pos)
9295 gtk_widget_queue_draw (widget);
9300 hide_cursor (GtkEntry *entry)
9302 GtkEntryPrivate *priv = entry->priv;
9305 if (priv->cursor_visible)
9307 priv->cursor_visible = FALSE;
9309 widget = GTK_WIDGET (entry);
9310 if (gtk_widget_has_focus (widget) && priv->selection_bound == priv->current_pos)
9311 gtk_widget_queue_draw (widget);
9319 blink_cb (gpointer data)
9322 GtkEntryPrivate *priv;
9325 entry = GTK_ENTRY (data);
9328 if (!gtk_widget_has_focus (GTK_WIDGET (entry)))
9330 g_warning ("GtkEntry - did not receive focus-out-event. If you\n"
9331 "connect a handler to this signal, it must return\n"
9332 "FALSE so the entry gets the event as well");
9334 gtk_entry_check_cursor_blink (entry);
9339 g_assert (priv->selection_bound == priv->current_pos);
9341 blink_timeout = get_cursor_blink_timeout (entry);
9342 if (priv->blink_time > 1000 * blink_timeout &&
9343 blink_timeout < G_MAXINT/1000)
9345 /* we've blinked enough without the user doing anything, stop blinking */
9346 show_cursor (entry);
9347 priv->blink_timeout = 0;
9349 else if (priv->cursor_visible)
9351 hide_cursor (entry);
9352 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_OFF_MULTIPLIER / CURSOR_DIVIDER,
9358 show_cursor (entry);
9359 priv->blink_time += get_cursor_time (entry);
9360 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
9365 /* Remove ourselves */
9370 gtk_entry_check_cursor_blink (GtkEntry *entry)
9372 GtkEntryPrivate *priv = entry->priv;
9374 if (cursor_blinks (entry))
9376 if (!priv->blink_timeout)
9378 show_cursor (entry);
9379 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
9386 if (priv->blink_timeout)
9388 g_source_remove (priv->blink_timeout);
9389 priv->blink_timeout = 0;
9392 priv->cursor_visible = TRUE;
9397 gtk_entry_pend_cursor_blink (GtkEntry *entry)
9399 GtkEntryPrivate *priv = entry->priv;
9401 if (cursor_blinks (entry))
9403 if (priv->blink_timeout != 0)
9404 g_source_remove (priv->blink_timeout);
9406 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_PEND_MULTIPLIER / CURSOR_DIVIDER,
9409 show_cursor (entry);
9414 gtk_entry_reset_blink_time (GtkEntry *entry)
9416 GtkEntryPrivate *priv = entry->priv;
9418 priv->blink_time = 0;
9424 gtk_entry_completion_timeout (gpointer data)
9426 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (data);
9427 GtkEntryPrivate *completion_entry_priv = GTK_ENTRY (completion->priv->entry)->priv;
9429 completion->priv->completion_timeout = 0;
9431 if (completion->priv->filter_model &&
9432 g_utf8_strlen (gtk_entry_get_text (GTK_ENTRY (completion->priv->entry)), -1)
9433 >= completion->priv->minimum_key_length)
9437 GtkTreeSelection *s;
9438 gboolean popup_single;
9440 gtk_entry_completion_complete (completion);
9441 matches = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->filter_model), NULL);
9443 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9445 s = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view));
9447 gtk_tree_selection_unselect_all (s);
9449 actions = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->actions), NULL);
9451 g_object_get (completion, "popup-single-match", &popup_single, NULL);
9452 if ((matches > (popup_single ? 0: 1)) || actions > 0)
9454 if (gtk_widget_get_visible (completion->priv->popup_window))
9455 _gtk_entry_completion_resize_popup (completion);
9457 _gtk_entry_completion_popup (completion, completion_entry_priv->completion_device);
9460 _gtk_entry_completion_popdown (completion);
9462 else if (gtk_widget_get_visible (completion->priv->popup_window))
9463 _gtk_entry_completion_popdown (completion);
9468 static inline gboolean
9469 keyval_is_cursor_move (guint keyval)
9471 if (keyval == GDK_KEY_Up || keyval == GDK_KEY_KP_Up)
9474 if (keyval == GDK_KEY_Down || keyval == GDK_KEY_KP_Down)
9477 if (keyval == GDK_KEY_Page_Up)
9480 if (keyval == GDK_KEY_Page_Down)
9487 gtk_entry_completion_key_press (GtkWidget *widget,
9491 gint matches, actions = 0;
9492 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
9494 if (!gtk_widget_get_mapped (completion->priv->popup_window))
9497 matches = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->filter_model), NULL);
9499 if (completion->priv->actions)
9500 actions = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->actions), NULL);
9502 if (keyval_is_cursor_move (event->keyval))
9504 GtkTreePath *path = NULL;
9506 if (event->keyval == GDK_KEY_Up || event->keyval == GDK_KEY_KP_Up)
9508 if (completion->priv->current_selected < 0)
9509 completion->priv->current_selected = matches + actions - 1;
9511 completion->priv->current_selected--;
9513 else if (event->keyval == GDK_KEY_Down || event->keyval == GDK_KEY_KP_Down)
9515 if (completion->priv->current_selected < matches + actions - 1)
9516 completion->priv->current_selected++;
9518 completion->priv->current_selected = -1;
9520 else if (event->keyval == GDK_KEY_Page_Up)
9522 if (completion->priv->current_selected < 0)
9523 completion->priv->current_selected = matches + actions - 1;
9524 else if (completion->priv->current_selected == 0)
9525 completion->priv->current_selected = -1;
9526 else if (completion->priv->current_selected < matches)
9528 completion->priv->current_selected -= 14;
9529 if (completion->priv->current_selected < 0)
9530 completion->priv->current_selected = 0;
9534 completion->priv->current_selected -= 14;
9535 if (completion->priv->current_selected < matches - 1)
9536 completion->priv->current_selected = matches - 1;
9539 else if (event->keyval == GDK_KEY_Page_Down)
9541 if (completion->priv->current_selected < 0)
9542 completion->priv->current_selected = 0;
9543 else if (completion->priv->current_selected < matches - 1)
9545 completion->priv->current_selected += 14;
9546 if (completion->priv->current_selected > matches - 1)
9547 completion->priv->current_selected = matches - 1;
9549 else if (completion->priv->current_selected == matches + actions - 1)
9551 completion->priv->current_selected = -1;
9555 completion->priv->current_selected += 14;
9556 if (completion->priv->current_selected > matches + actions - 1)
9557 completion->priv->current_selected = matches + actions - 1;
9561 if (completion->priv->current_selected < 0)
9563 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9564 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view)));
9566 if (completion->priv->inline_selection &&
9567 completion->priv->completion_prefix)
9569 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9570 completion->priv->completion_prefix);
9571 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9574 else if (completion->priv->current_selected < matches)
9576 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view)));
9578 path = gtk_tree_path_new_from_indices (completion->priv->current_selected, -1);
9579 gtk_tree_view_set_cursor (GTK_TREE_VIEW (completion->priv->tree_view),
9582 if (completion->priv->inline_selection)
9586 GtkTreeIter child_iter;
9587 GtkTreeModel *model = NULL;
9588 GtkTreeSelection *sel;
9591 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view));
9592 if (!gtk_tree_selection_get_selected (sel, &model, &iter))
9595 gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (model), &child_iter, &iter);
9596 model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model));
9598 if (completion->priv->completion_prefix == NULL)
9599 completion->priv->completion_prefix = g_strdup (gtk_entry_get_text (GTK_ENTRY (completion->priv->entry)));
9601 g_signal_emit_by_name (completion, "cursor-on-match", model,
9602 &child_iter, &entry_set);
9605 else if (completion->priv->current_selected - matches >= 0)
9607 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9609 path = gtk_tree_path_new_from_indices (completion->priv->current_selected - matches, -1);
9610 gtk_tree_view_set_cursor (GTK_TREE_VIEW (completion->priv->action_view),
9613 if (completion->priv->inline_selection &&
9614 completion->priv->completion_prefix)
9616 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9617 completion->priv->completion_prefix);
9618 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9622 gtk_tree_path_free (path);
9626 else if (event->keyval == GDK_KEY_Escape ||
9627 event->keyval == GDK_KEY_Left ||
9628 event->keyval == GDK_KEY_KP_Left ||
9629 event->keyval == GDK_KEY_Right ||
9630 event->keyval == GDK_KEY_KP_Right)
9632 gboolean retval = TRUE;
9634 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9635 _gtk_entry_completion_popdown (completion);
9637 if (completion->priv->current_selected < 0)
9640 goto keypress_completion_out;
9642 else if (completion->priv->inline_selection)
9644 /* Escape rejects the tentative completion */
9645 if (event->keyval == GDK_KEY_Escape)
9647 if (completion->priv->completion_prefix)
9648 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9649 completion->priv->completion_prefix);
9651 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry), "");
9654 /* Move the cursor to the end for Right/Esc, to the
9655 beginning for Left */
9656 if (event->keyval == GDK_KEY_Right ||
9657 event->keyval == GDK_KEY_KP_Right ||
9658 event->keyval == GDK_KEY_Escape)
9659 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9661 gtk_editable_set_position (GTK_EDITABLE (widget), 0);
9664 keypress_completion_out:
9665 if (completion->priv->inline_selection)
9667 g_free (completion->priv->completion_prefix);
9668 completion->priv->completion_prefix = NULL;
9673 else if (event->keyval == GDK_KEY_Tab ||
9674 event->keyval == GDK_KEY_KP_Tab ||
9675 event->keyval == GDK_KEY_ISO_Left_Tab)
9677 GtkDirectionType dir = event->keyval == GDK_KEY_ISO_Left_Tab ?
9678 GTK_DIR_TAB_BACKWARD : GTK_DIR_TAB_FORWARD;
9680 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9681 _gtk_entry_completion_popdown (completion);
9683 g_free (completion->priv->completion_prefix);
9684 completion->priv->completion_prefix = NULL;
9686 gtk_widget_child_focus (gtk_widget_get_toplevel (widget), dir);
9690 else if (event->keyval == GDK_KEY_ISO_Enter ||
9691 event->keyval == GDK_KEY_KP_Enter ||
9692 event->keyval == GDK_KEY_Return)
9695 GtkTreeModel *model = NULL;
9696 GtkTreeModel *child_model;
9697 GtkTreeIter child_iter;
9698 GtkTreeSelection *sel;
9699 gboolean retval = TRUE;
9701 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9702 _gtk_entry_completion_popdown (completion);
9704 if (completion->priv->current_selected < matches)
9708 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view));
9709 if (gtk_tree_selection_get_selected (sel, &model, &iter))
9711 gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (model), &child_iter, &iter);
9712 child_model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model));
9713 g_signal_handler_block (widget, completion->priv->changed_id);
9714 g_signal_emit_by_name (completion, "match-selected",
9715 child_model, &child_iter, &entry_set);
9716 g_signal_handler_unblock (widget, completion->priv->changed_id);
9722 gtk_tree_model_get (model, &iter,
9723 completion->priv->text_column, &str,
9726 gtk_entry_set_text (GTK_ENTRY (widget), str);
9728 /* move the cursor to the end */
9729 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9737 else if (completion->priv->current_selected - matches >= 0)
9739 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view));
9740 if (gtk_tree_selection_get_selected (sel, &model, &iter))
9744 path = gtk_tree_path_new_from_indices (completion->priv->current_selected - matches, -1);
9745 g_signal_emit_by_name (completion, "action-activated",
9746 gtk_tree_path_get_indices (path)[0]);
9747 gtk_tree_path_free (path);
9753 g_free (completion->priv->completion_prefix);
9754 completion->priv->completion_prefix = NULL;
9763 gtk_entry_completion_changed (GtkWidget *widget,
9766 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
9767 GtkEntry *entry = GTK_ENTRY (widget);
9768 GtkEntryPrivate *priv = entry->priv;
9771 /* (re)install completion timeout */
9772 if (completion->priv->completion_timeout)
9773 g_source_remove (completion->priv->completion_timeout);
9775 if (!gtk_entry_get_text (entry))
9778 /* no need to normalize for this test */
9779 if (completion->priv->minimum_key_length > 0 &&
9780 strcmp ("", gtk_entry_get_text (entry)) == 0)
9782 if (gtk_widget_get_visible (completion->priv->popup_window))
9783 _gtk_entry_completion_popdown (completion);
9787 device = gtk_get_current_event_device ();
9789 if (device && gdk_device_get_source (device) == GDK_SOURCE_KEYBOARD)
9790 device = gdk_device_get_associated_device (device);
9793 priv->completion_device = device;
9795 completion->priv->completion_timeout =
9796 gdk_threads_add_timeout (COMPLETION_TIMEOUT,
9797 gtk_entry_completion_timeout,
9802 check_completion_callback (GtkEntryCompletion *completion)
9804 completion->priv->check_completion_idle = NULL;
9806 gtk_entry_completion_complete (completion);
9807 gtk_entry_completion_insert_prefix (completion);
9813 clear_completion_callback (GtkEntry *entry,
9816 if (pspec->name == I_("cursor-position") ||
9817 pspec->name == I_("selection-bound"))
9819 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
9821 completion->priv->has_completion = FALSE;
9826 accept_completion_callback (GtkEntry *entry)
9828 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
9830 if (completion->priv->has_completion)
9831 gtk_editable_set_position (GTK_EDITABLE (entry),
9832 gtk_entry_buffer_get_length (get_buffer (entry)));
9838 completion_insert_text_callback (GtkEntry *entry,
9842 GtkEntryCompletion *completion)
9844 /* idle to update the selection based on the file list */
9845 if (completion->priv->check_completion_idle == NULL)
9847 completion->priv->check_completion_idle = g_idle_source_new ();
9848 g_source_set_priority (completion->priv->check_completion_idle, G_PRIORITY_HIGH);
9849 g_source_set_closure (completion->priv->check_completion_idle,
9850 g_cclosure_new_object (G_CALLBACK (check_completion_callback),
9851 G_OBJECT (completion)));
9852 g_source_attach (completion->priv->check_completion_idle, NULL);
9857 completion_changed (GtkEntryCompletion *completion,
9861 GtkEntry *entry = GTK_ENTRY (data);
9863 if (pspec->name == I_("popup-completion") ||
9864 pspec->name == I_("inline-completion"))
9866 disconnect_completion_signals (entry, completion);
9867 connect_completion_signals (entry, completion);
9872 disconnect_completion_signals (GtkEntry *entry,
9873 GtkEntryCompletion *completion)
9875 g_signal_handlers_disconnect_by_func (completion,
9876 G_CALLBACK (completion_changed), entry);
9877 if (completion->priv->changed_id > 0 &&
9878 g_signal_handler_is_connected (entry, completion->priv->changed_id))
9880 g_signal_handler_disconnect (entry, completion->priv->changed_id);
9881 completion->priv->changed_id = 0;
9883 g_signal_handlers_disconnect_by_func (entry,
9884 G_CALLBACK (gtk_entry_completion_key_press), completion);
9885 if (completion->priv->insert_text_id > 0 &&
9886 g_signal_handler_is_connected (entry, completion->priv->insert_text_id))
9888 g_signal_handler_disconnect (entry, completion->priv->insert_text_id);
9889 completion->priv->insert_text_id = 0;
9891 g_signal_handlers_disconnect_by_func (entry,
9892 G_CALLBACK (completion_insert_text_callback), completion);
9893 g_signal_handlers_disconnect_by_func (entry,
9894 G_CALLBACK (clear_completion_callback), completion);
9895 g_signal_handlers_disconnect_by_func (entry,
9896 G_CALLBACK (accept_completion_callback), completion);
9900 connect_completion_signals (GtkEntry *entry,
9901 GtkEntryCompletion *completion)
9903 if (completion->priv->popup_completion)
9905 completion->priv->changed_id =
9906 g_signal_connect (entry, "changed",
9907 G_CALLBACK (gtk_entry_completion_changed), completion);
9908 g_signal_connect (entry, "key-press-event",
9909 G_CALLBACK (gtk_entry_completion_key_press), completion);
9912 if (completion->priv->inline_completion)
9914 completion->priv->insert_text_id =
9915 g_signal_connect (entry, "insert-text",
9916 G_CALLBACK (completion_insert_text_callback), completion);
9917 g_signal_connect (entry, "notify",
9918 G_CALLBACK (clear_completion_callback), completion);
9919 g_signal_connect (entry, "activate",
9920 G_CALLBACK (accept_completion_callback), completion);
9921 g_signal_connect (entry, "focus-out-event",
9922 G_CALLBACK (accept_completion_callback), completion);
9925 g_signal_connect (completion, "notify",
9926 G_CALLBACK (completion_changed), entry);
9930 * gtk_entry_set_completion:
9931 * @entry: A #GtkEntry
9932 * @completion: (allow-none): The #GtkEntryCompletion or %NULL
9934 * Sets @completion to be the auxiliary completion object to use with @entry.
9935 * All further configuration of the completion mechanism is done on
9936 * @completion using the #GtkEntryCompletion API. Completion is disabled if
9937 * @completion is set to %NULL.
9942 gtk_entry_set_completion (GtkEntry *entry,
9943 GtkEntryCompletion *completion)
9945 GtkEntryCompletion *old;
9947 g_return_if_fail (GTK_IS_ENTRY (entry));
9948 g_return_if_fail (!completion || GTK_IS_ENTRY_COMPLETION (completion));
9950 old = gtk_entry_get_completion (entry);
9952 if (old == completion)
9957 if (old->priv->completion_timeout)
9959 g_source_remove (old->priv->completion_timeout);
9960 old->priv->completion_timeout = 0;
9963 if (gtk_widget_get_mapped (old->priv->popup_window))
9964 _gtk_entry_completion_popdown (old);
9966 disconnect_completion_signals (entry, old);
9967 old->priv->entry = NULL;
9969 g_object_unref (old);
9974 g_object_set_data (G_OBJECT (entry), I_(GTK_ENTRY_COMPLETION_KEY), NULL);
9978 /* hook into the entry */
9979 g_object_ref (completion);
9981 connect_completion_signals (entry, completion);
9982 completion->priv->entry = GTK_WIDGET (entry);
9983 g_object_set_data (G_OBJECT (entry), I_(GTK_ENTRY_COMPLETION_KEY), completion);
9985 g_object_notify (G_OBJECT (entry), "completion");
9989 * gtk_entry_get_completion:
9990 * @entry: A #GtkEntry
9992 * Returns the auxiliary completion object currently in use by @entry.
9994 * Return value: (transfer none): The auxiliary completion object currently
9999 GtkEntryCompletion *
10000 gtk_entry_get_completion (GtkEntry *entry)
10002 GtkEntryCompletion *completion;
10004 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
10006 completion = GTK_ENTRY_COMPLETION (g_object_get_data (G_OBJECT (entry),
10007 GTK_ENTRY_COMPLETION_KEY));
10013 * gtk_entry_set_cursor_hadjustment:
10014 * @entry: a #GtkEntry
10015 * @adjustment: an adjustment which should be adjusted when the cursor
10016 * is moved, or %NULL
10018 * Hooks up an adjustment to the cursor position in an entry, so that when
10019 * the cursor is moved, the adjustment is scrolled to show that position.
10020 * See gtk_scrolled_window_get_hadjustment() for a typical way of obtaining
10023 * The adjustment has to be in pixel units and in the same coordinate system
10029 gtk_entry_set_cursor_hadjustment (GtkEntry *entry,
10030 GtkAdjustment *adjustment)
10032 g_return_if_fail (GTK_IS_ENTRY (entry));
10034 g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
10037 g_object_ref (adjustment);
10039 g_object_set_qdata_full (G_OBJECT (entry),
10040 quark_cursor_hadjustment,
10046 * gtk_entry_get_cursor_hadjustment:
10047 * @entry: a #GtkEntry
10049 * Retrieves the horizontal cursor adjustment for the entry.
10050 * See gtk_entry_set_cursor_hadjustment().
10052 * Return value: (transfer none): the horizontal cursor adjustment, or %NULL
10053 * if none has been set.
10058 gtk_entry_get_cursor_hadjustment (GtkEntry *entry)
10060 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
10062 return g_object_get_qdata (G_OBJECT (entry), quark_cursor_hadjustment);
10066 * gtk_entry_set_progress_fraction:
10067 * @entry: a #GtkEntry
10068 * @fraction: fraction of the task that's been completed
10070 * Causes the entry's progress indicator to "fill in" the given
10071 * fraction of the bar. The fraction should be between 0.0 and 1.0,
10077 gtk_entry_set_progress_fraction (GtkEntry *entry,
10081 GtkEntryPrivate *private;
10082 gdouble old_fraction;
10083 gint x, y, width, height;
10084 gint old_x, old_y, old_width, old_height;
10086 g_return_if_fail (GTK_IS_ENTRY (entry));
10088 widget = GTK_WIDGET (entry);
10089 private = entry->priv;
10091 if (private->progress_pulse_mode)
10094 old_fraction = private->progress_fraction;
10096 if (gtk_widget_is_drawable (widget))
10097 get_progress_area (widget, &old_x, &old_y, &old_width, &old_height);
10099 fraction = CLAMP (fraction, 0.0, 1.0);
10101 private->progress_fraction = fraction;
10102 private->progress_pulse_mode = FALSE;
10103 private->progress_pulse_current = 0.0;
10105 if (gtk_widget_is_drawable (widget))
10107 get_progress_area (widget, &x, &y, &width, &height);
10109 if ((x != old_x) || (y != old_y) || (width != old_width) || (height != old_height))
10110 gtk_widget_queue_draw (widget);
10113 if (fraction != old_fraction)
10114 g_object_notify (G_OBJECT (entry), "progress-fraction");
10118 * gtk_entry_get_progress_fraction:
10119 * @entry: a #GtkEntry
10121 * Returns the current fraction of the task that's been completed.
10122 * See gtk_entry_set_progress_fraction().
10124 * Return value: a fraction from 0.0 to 1.0
10129 gtk_entry_get_progress_fraction (GtkEntry *entry)
10131 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
10133 return entry->priv->progress_fraction;
10137 * gtk_entry_set_progress_pulse_step:
10138 * @entry: a #GtkEntry
10139 * @fraction: fraction between 0.0 and 1.0
10141 * Sets the fraction of total entry width to move the progress
10142 * bouncing block for each call to gtk_entry_progress_pulse().
10147 gtk_entry_set_progress_pulse_step (GtkEntry *entry,
10150 GtkEntryPrivate *private;
10152 g_return_if_fail (GTK_IS_ENTRY (entry));
10154 private = entry->priv;
10156 fraction = CLAMP (fraction, 0.0, 1.0);
10158 if (fraction != private->progress_pulse_fraction)
10160 private->progress_pulse_fraction = fraction;
10162 gtk_widget_queue_draw (GTK_WIDGET (entry));
10164 g_object_notify (G_OBJECT (entry), "progress-pulse-step");
10169 * gtk_entry_get_progress_pulse_step:
10170 * @entry: a #GtkEntry
10172 * Retrieves the pulse step set with gtk_entry_set_progress_pulse_step().
10174 * Return value: a fraction from 0.0 to 1.0
10179 gtk_entry_get_progress_pulse_step (GtkEntry *entry)
10181 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
10183 return entry->priv->progress_pulse_fraction;
10187 * gtk_entry_progress_pulse:
10188 * @entry: a #GtkEntry
10190 * Indicates that some progress is made, but you don't know how much.
10191 * Causes the entry's progress indicator to enter "activity mode,"
10192 * where a block bounces back and forth. Each call to
10193 * gtk_entry_progress_pulse() causes the block to move by a little bit
10194 * (the amount of movement per pulse is determined by
10195 * gtk_entry_set_progress_pulse_step()).
10200 gtk_entry_progress_pulse (GtkEntry *entry)
10202 GtkEntryPrivate *private;
10204 g_return_if_fail (GTK_IS_ENTRY (entry));
10206 private = entry->priv;
10208 if (private->progress_pulse_mode)
10210 if (private->progress_pulse_way_back)
10212 private->progress_pulse_current -= private->progress_pulse_fraction;
10214 if (private->progress_pulse_current < 0.0)
10216 private->progress_pulse_current = 0.0;
10217 private->progress_pulse_way_back = FALSE;
10222 private->progress_pulse_current += private->progress_pulse_fraction;
10224 if (private->progress_pulse_current > 1.0 - private->progress_pulse_fraction)
10226 private->progress_pulse_current = 1.0 - private->progress_pulse_fraction;
10227 private->progress_pulse_way_back = TRUE;
10233 private->progress_fraction = 0.0;
10234 private->progress_pulse_mode = TRUE;
10235 private->progress_pulse_way_back = FALSE;
10236 private->progress_pulse_current = 0.0;
10239 gtk_widget_queue_draw (GTK_WIDGET (entry));
10243 * gtk_entry_set_placeholder_text:
10244 * @entry: a #GtkEntry
10245 * @text: a string to be displayed when @entry is empty an unfocused, or %NULL
10247 * Sets text to be displayed in @entry when
10248 * it is empty and unfocused. This can be used to give a visual hint
10249 * of the expected contents of the #GtkEntry.
10254 gtk_entry_set_placeholder_text (GtkEntry *entry,
10257 GtkEntryPrivate *priv;
10259 g_return_if_fail (GTK_IS_ENTRY (entry));
10261 priv = entry->priv;
10263 if (g_strcmp0 (priv->placeholder_text, text) == 0)
10266 g_free (priv->placeholder_text);
10267 priv->placeholder_text = g_strdup (text);
10269 gtk_entry_recompute (entry);
10271 g_object_notify (G_OBJECT (entry), "placeholder-text");
10275 * gtk_entry_get_placeholder_text:
10276 * @entry: a #GtkEntry
10278 * Retrieves the text that will be displayed when @entry is empty and unfocused
10280 * Returns: a pointer to the placeholder text as a string. This string points to internally allocated
10281 * storage in the widget and must not be freed, modified or stored.
10285 G_CONST_RETURN gchar *
10286 gtk_entry_get_placeholder_text (GtkEntry *entry)
10288 GtkEntryPrivate *priv;
10290 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
10292 priv = entry->priv;
10294 return priv->placeholder_text;
10297 /* Caps Lock warning for password entries */
10300 show_capslock_feedback (GtkEntry *entry,
10303 GtkEntryPrivate *priv = entry->priv;
10305 if (gtk_entry_get_icon_storage_type (entry, GTK_ENTRY_ICON_SECONDARY) == GTK_IMAGE_EMPTY)
10307 gtk_entry_set_icon_from_stock (entry, GTK_ENTRY_ICON_SECONDARY, GTK_STOCK_CAPS_LOCK_WARNING);
10308 gtk_entry_set_icon_activatable (entry, GTK_ENTRY_ICON_SECONDARY, FALSE);
10309 priv->caps_lock_warning_shown = TRUE;
10312 if (priv->caps_lock_warning_shown)
10313 gtk_entry_set_icon_tooltip_text (entry, GTK_ENTRY_ICON_SECONDARY, text);
10315 g_warning ("Can't show Caps Lock warning, since secondary icon is set");
10319 remove_capslock_feedback (GtkEntry *entry)
10321 GtkEntryPrivate *priv = entry->priv;
10323 if (priv->caps_lock_warning_shown)
10325 gtk_entry_set_icon_from_stock (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
10326 priv->caps_lock_warning_shown = FALSE;
10331 keymap_state_changed (GdkKeymap *keymap,
10334 GtkEntryPrivate *priv = entry->priv;
10337 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL && priv->caps_lock_warning)
10339 if (gdk_keymap_get_num_lock_state (keymap)
10340 && gdk_keymap_get_caps_lock_state (keymap))
10341 text = _("Caps Lock and Num Lock are on");
10342 else if (gdk_keymap_get_num_lock_state (keymap))
10343 text = _("Num Lock is on");
10344 else if (gdk_keymap_get_caps_lock_state (keymap))
10345 text = _("Caps Lock is on");
10349 show_capslock_feedback (entry, text);
10351 remove_capslock_feedback (entry);
10355 * _gtk_entry_set_is_cell_renderer:
10356 * @entry: a #GtkEntry
10357 * @is_cell_renderer: new value
10359 * This is a helper function for GtkComboBox. A GtkEntry in a GtkComboBox
10360 * is supposed to behave like a GtkCellEditable when placed in a combo box.
10362 * I.e take up its allocation and get GtkEntry->is_cell_renderer = TRUE.
10366 _gtk_entry_set_is_cell_renderer (GtkEntry *entry,
10367 gboolean is_cell_renderer)
10369 entry->priv->is_cell_renderer = is_cell_renderer;