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,
566 gboolean relative_to_window,
571 static void gtk_entry_move_adjustments (GtkEntry *entry);
572 static void gtk_entry_ensure_pixbuf (GtkEntry *entry,
573 GtkEntryIconPosition icon_pos);
574 static void gtk_entry_update_cached_style_values(GtkEntry *entry);
577 static gint gtk_entry_completion_timeout (gpointer data);
578 static gboolean gtk_entry_completion_key_press (GtkWidget *widget,
581 static void gtk_entry_completion_changed (GtkWidget *entry,
583 static gboolean check_completion_callback (GtkEntryCompletion *completion);
584 static void clear_completion_callback (GtkEntry *entry,
586 static gboolean accept_completion_callback (GtkEntry *entry);
587 static void completion_insert_text_callback (GtkEntry *entry,
591 GtkEntryCompletion *completion);
592 static void completion_changed (GtkEntryCompletion *completion,
595 static void disconnect_completion_signals (GtkEntry *entry,
596 GtkEntryCompletion *completion);
597 static void connect_completion_signals (GtkEntry *entry,
598 GtkEntryCompletion *completion);
600 static void begin_change (GtkEntry *entry);
601 static void end_change (GtkEntry *entry);
602 static void emit_changed (GtkEntry *entry);
604 static void buffer_inserted_text (GtkEntryBuffer *buffer,
609 static void buffer_deleted_text (GtkEntryBuffer *buffer,
613 static void buffer_notify_text (GtkEntryBuffer *buffer,
616 static void buffer_notify_length (GtkEntryBuffer *buffer,
619 static void buffer_notify_max_length (GtkEntryBuffer *buffer,
622 static void buffer_connect_signals (GtkEntry *entry);
623 static void buffer_disconnect_signals (GtkEntry *entry);
624 static GtkEntryBuffer *get_buffer (GtkEntry *entry);
626 G_DEFINE_TYPE_WITH_CODE (GtkEntry, gtk_entry, GTK_TYPE_WIDGET,
627 G_IMPLEMENT_INTERFACE (GTK_TYPE_EDITABLE,
628 gtk_entry_editable_init)
629 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_EDITABLE,
630 gtk_entry_cell_editable_init))
633 add_move_binding (GtkBindingSet *binding_set,
636 GtkMovementStep step,
639 g_return_if_fail ((modmask & GDK_SHIFT_MASK) == 0);
641 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
645 G_TYPE_BOOLEAN, FALSE);
647 /* Selection-extending version */
648 gtk_binding_entry_add_signal (binding_set, keyval, modmask | GDK_SHIFT_MASK,
652 G_TYPE_BOOLEAN, TRUE);
656 gtk_entry_class_init (GtkEntryClass *class)
658 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
659 GtkWidgetClass *widget_class;
660 GtkBindingSet *binding_set;
662 widget_class = (GtkWidgetClass*) class;
664 gobject_class->dispose = gtk_entry_dispose;
665 gobject_class->finalize = gtk_entry_finalize;
666 gobject_class->set_property = gtk_entry_set_property;
667 gobject_class->get_property = gtk_entry_get_property;
669 widget_class->destroy = gtk_entry_destroy;
670 widget_class->map = gtk_entry_map;
671 widget_class->unmap = gtk_entry_unmap;
672 widget_class->realize = gtk_entry_realize;
673 widget_class->unrealize = gtk_entry_unrealize;
674 widget_class->get_preferred_width = gtk_entry_get_preferred_width;
675 widget_class->get_preferred_height = gtk_entry_get_preferred_height;
676 widget_class->size_allocate = gtk_entry_size_allocate;
677 widget_class->draw = gtk_entry_draw;
678 widget_class->enter_notify_event = gtk_entry_enter_notify;
679 widget_class->leave_notify_event = gtk_entry_leave_notify;
680 widget_class->button_press_event = gtk_entry_button_press;
681 widget_class->button_release_event = gtk_entry_button_release;
682 widget_class->motion_notify_event = gtk_entry_motion_notify;
683 widget_class->key_press_event = gtk_entry_key_press;
684 widget_class->key_release_event = gtk_entry_key_release;
685 widget_class->focus_in_event = gtk_entry_focus_in;
686 widget_class->focus_out_event = gtk_entry_focus_out;
687 widget_class->grab_focus = gtk_entry_grab_focus;
688 widget_class->style_updated = gtk_entry_style_updated;
689 widget_class->query_tooltip = gtk_entry_query_tooltip;
690 widget_class->drag_begin = gtk_entry_drag_begin;
691 widget_class->drag_end = gtk_entry_drag_end;
692 widget_class->direction_changed = gtk_entry_direction_changed;
693 widget_class->state_flags_changed = gtk_entry_state_flags_changed;
694 widget_class->screen_changed = gtk_entry_screen_changed;
695 widget_class->mnemonic_activate = gtk_entry_mnemonic_activate;
697 widget_class->drag_drop = gtk_entry_drag_drop;
698 widget_class->drag_motion = gtk_entry_drag_motion;
699 widget_class->drag_leave = gtk_entry_drag_leave;
700 widget_class->drag_data_received = gtk_entry_drag_data_received;
701 widget_class->drag_data_get = gtk_entry_drag_data_get;
702 widget_class->drag_data_delete = gtk_entry_drag_data_delete;
704 widget_class->popup_menu = gtk_entry_popup_menu;
706 class->move_cursor = gtk_entry_move_cursor;
707 class->insert_at_cursor = gtk_entry_insert_at_cursor;
708 class->delete_from_cursor = gtk_entry_delete_from_cursor;
709 class->backspace = gtk_entry_backspace;
710 class->cut_clipboard = gtk_entry_cut_clipboard;
711 class->copy_clipboard = gtk_entry_copy_clipboard;
712 class->paste_clipboard = gtk_entry_paste_clipboard;
713 class->toggle_overwrite = gtk_entry_toggle_overwrite;
714 class->activate = gtk_entry_real_activate;
715 class->get_text_area_size = gtk_entry_get_text_area_size;
717 quark_inner_border = g_quark_from_static_string ("gtk-entry-inner-border");
718 quark_password_hint = g_quark_from_static_string ("gtk-entry-password-hint");
719 quark_cursor_hadjustment = g_quark_from_static_string ("gtk-hadjustment");
720 quark_capslock_feedback = g_quark_from_static_string ("gtk-entry-capslock-feedback");
722 g_object_class_override_property (gobject_class,
723 PROP_EDITING_CANCELED,
726 g_object_class_install_property (gobject_class,
728 g_param_spec_object ("buffer",
730 P_("Text buffer object which actually stores entry text"),
731 GTK_TYPE_ENTRY_BUFFER,
732 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT));
734 g_object_class_install_property (gobject_class,
735 PROP_CURSOR_POSITION,
736 g_param_spec_int ("cursor-position",
737 P_("Cursor Position"),
738 P_("The current position of the insertion cursor in chars"),
740 GTK_ENTRY_BUFFER_MAX_SIZE,
742 GTK_PARAM_READABLE));
744 g_object_class_install_property (gobject_class,
745 PROP_SELECTION_BOUND,
746 g_param_spec_int ("selection-bound",
747 P_("Selection Bound"),
748 P_("The position of the opposite end of the selection from the cursor in chars"),
750 GTK_ENTRY_BUFFER_MAX_SIZE,
752 GTK_PARAM_READABLE));
754 g_object_class_install_property (gobject_class,
756 g_param_spec_boolean ("editable",
758 P_("Whether the entry contents can be edited"),
760 GTK_PARAM_READWRITE));
762 g_object_class_install_property (gobject_class,
764 g_param_spec_int ("max-length",
765 P_("Maximum length"),
766 P_("Maximum number of characters for this entry. Zero if no maximum"),
768 GTK_ENTRY_BUFFER_MAX_SIZE,
770 GTK_PARAM_READWRITE));
771 g_object_class_install_property (gobject_class,
773 g_param_spec_boolean ("visibility",
775 P_("FALSE displays the \"invisible char\" instead of the actual text (password mode)"),
777 GTK_PARAM_READWRITE));
779 g_object_class_install_property (gobject_class,
781 g_param_spec_boolean ("has-frame",
783 P_("FALSE removes outside bevel from entry"),
785 GTK_PARAM_READWRITE));
787 g_object_class_install_property (gobject_class,
789 g_param_spec_boxed ("inner-border",
791 P_("Border between text and frame. Overrides the inner-border style property"),
793 GTK_PARAM_READWRITE));
795 g_object_class_install_property (gobject_class,
797 g_param_spec_unichar ("invisible-char",
798 P_("Invisible character"),
799 P_("The character to use when masking entry contents (in \"password mode\")"),
801 GTK_PARAM_READWRITE));
803 g_object_class_install_property (gobject_class,
804 PROP_ACTIVATES_DEFAULT,
805 g_param_spec_boolean ("activates-default",
806 P_("Activates default"),
807 P_("Whether to activate the default widget (such as the default button in a dialog) when Enter is pressed"),
809 GTK_PARAM_READWRITE));
810 g_object_class_install_property (gobject_class,
812 g_param_spec_int ("width-chars",
813 P_("Width in chars"),
814 P_("Number of characters to leave space for in the entry"),
818 GTK_PARAM_READWRITE));
820 g_object_class_install_property (gobject_class,
822 g_param_spec_int ("scroll-offset",
824 P_("Number of pixels of the entry scrolled off the screen to the left"),
828 GTK_PARAM_READABLE));
830 g_object_class_install_property (gobject_class,
832 g_param_spec_string ("text",
834 P_("The contents of the entry"),
836 GTK_PARAM_READWRITE));
841 * The horizontal alignment, from 0 (left) to 1 (right).
842 * Reversed for RTL layouts.
846 g_object_class_install_property (gobject_class,
848 g_param_spec_float ("xalign",
850 P_("The horizontal alignment, from 0 (left) to 1 (right). Reversed for RTL layouts."),
854 GTK_PARAM_READWRITE));
857 * GtkEntry:truncate-multiline:
859 * When %TRUE, pasted multi-line text is truncated to the first line.
863 g_object_class_install_property (gobject_class,
864 PROP_TRUNCATE_MULTILINE,
865 g_param_spec_boolean ("truncate-multiline",
866 P_("Truncate multiline"),
867 P_("Whether to truncate multiline pastes to one line."),
869 GTK_PARAM_READWRITE));
872 * GtkEntry:shadow-type:
874 * Which kind of shadow to draw around the entry when
875 * #GtkEntry:has-frame is set to %TRUE.
879 g_object_class_install_property (gobject_class,
881 g_param_spec_enum ("shadow-type",
883 P_("Which kind of shadow to draw around the entry when has-frame is set"),
884 GTK_TYPE_SHADOW_TYPE,
886 GTK_PARAM_READWRITE));
889 * GtkEntry:overwrite-mode:
891 * If text is overwritten when typing in the #GtkEntry.
895 g_object_class_install_property (gobject_class,
897 g_param_spec_boolean ("overwrite-mode",
898 P_("Overwrite mode"),
899 P_("Whether new text overwrites existing text"),
901 GTK_PARAM_READWRITE));
904 * GtkEntry:text-length:
906 * The length of the text in the #GtkEntry.
910 g_object_class_install_property (gobject_class,
912 g_param_spec_uint ("text-length",
914 P_("Length of the text currently in the entry"),
918 GTK_PARAM_READABLE));
920 * GtkEntry:invisible-char-set:
922 * Whether the invisible char has been set for the #GtkEntry.
926 g_object_class_install_property (gobject_class,
927 PROP_INVISIBLE_CHAR_SET,
928 g_param_spec_boolean ("invisible-char-set",
929 P_("Invisible character set"),
930 P_("Whether the invisible character has been set"),
932 GTK_PARAM_READWRITE));
935 * GtkEntry:caps-lock-warning
937 * Whether password entries will show a warning when Caps Lock is on.
939 * Note that the warning is shown using a secondary icon, and thus
940 * does not work if you are using the secondary icon position for some
945 g_object_class_install_property (gobject_class,
946 PROP_CAPS_LOCK_WARNING,
947 g_param_spec_boolean ("caps-lock-warning",
948 P_("Caps Lock warning"),
949 P_("Whether password entries will show a warning when Caps Lock is on"),
951 GTK_PARAM_READWRITE));
954 * GtkEntry:progress-fraction:
956 * The current fraction of the task that's been completed.
960 g_object_class_install_property (gobject_class,
961 PROP_PROGRESS_FRACTION,
962 g_param_spec_double ("progress-fraction",
963 P_("Progress Fraction"),
964 P_("The current fraction of the task that's been completed"),
968 GTK_PARAM_READWRITE));
971 * GtkEntry:progress-pulse-step:
973 * The fraction of total entry width to move the progress
974 * bouncing block for each call to gtk_entry_progress_pulse().
978 g_object_class_install_property (gobject_class,
979 PROP_PROGRESS_PULSE_STEP,
980 g_param_spec_double ("progress-pulse-step",
981 P_("Progress Pulse Step"),
982 P_("The fraction of total entry width to move the progress bouncing block for each call to gtk_entry_progress_pulse()"),
986 GTK_PARAM_READWRITE));
989 * GtkEntry:placeholder-text:
991 * The text that will be displayed in the #GtkEntry when it is empty and unfocused.
995 g_object_class_install_property (gobject_class,
996 PROP_PLACEHOLDER_TEXT,
997 g_param_spec_string ("placeholder-text",
998 P_("Placeholder text"),
999 P_("Show text in the entry when it's empty and unfocused"),
1001 GTK_PARAM_READWRITE));
1004 * GtkEntry:primary-icon-pixbuf:
1006 * A pixbuf to use as the primary icon for the entry.
1010 g_object_class_install_property (gobject_class,
1011 PROP_PIXBUF_PRIMARY,
1012 g_param_spec_object ("primary-icon-pixbuf",
1013 P_("Primary pixbuf"),
1014 P_("Primary pixbuf for the entry"),
1016 GTK_PARAM_READWRITE));
1019 * GtkEntry:secondary-icon-pixbuf:
1021 * An pixbuf to use as the secondary icon for the entry.
1025 g_object_class_install_property (gobject_class,
1026 PROP_PIXBUF_SECONDARY,
1027 g_param_spec_object ("secondary-icon-pixbuf",
1028 P_("Secondary pixbuf"),
1029 P_("Secondary pixbuf for the entry"),
1031 GTK_PARAM_READWRITE));
1034 * GtkEntry:primary-icon-stock:
1036 * The stock id to use for the primary icon for the entry.
1040 g_object_class_install_property (gobject_class,
1042 g_param_spec_string ("primary-icon-stock",
1043 P_("Primary stock ID"),
1044 P_("Stock ID for primary icon"),
1046 GTK_PARAM_READWRITE));
1049 * GtkEntry:secondary-icon-stock:
1051 * The stock id to use for the secondary icon for the entry.
1055 g_object_class_install_property (gobject_class,
1056 PROP_STOCK_SECONDARY,
1057 g_param_spec_string ("secondary-icon-stock",
1058 P_("Secondary stock ID"),
1059 P_("Stock ID for secondary icon"),
1061 GTK_PARAM_READWRITE));
1064 * GtkEntry:primary-icon-name:
1066 * The icon name to use for the primary icon for the entry.
1070 g_object_class_install_property (gobject_class,
1071 PROP_ICON_NAME_PRIMARY,
1072 g_param_spec_string ("primary-icon-name",
1073 P_("Primary icon name"),
1074 P_("Icon name for primary icon"),
1076 GTK_PARAM_READWRITE));
1079 * GtkEntry:secondary-icon-name:
1081 * The icon name to use for the secondary icon for the entry.
1085 g_object_class_install_property (gobject_class,
1086 PROP_ICON_NAME_SECONDARY,
1087 g_param_spec_string ("secondary-icon-name",
1088 P_("Secondary icon name"),
1089 P_("Icon name for secondary icon"),
1091 GTK_PARAM_READWRITE));
1094 * GtkEntry:primary-icon-gicon:
1096 * The #GIcon to use for the primary icon for the entry.
1100 g_object_class_install_property (gobject_class,
1102 g_param_spec_object ("primary-icon-gicon",
1103 P_("Primary GIcon"),
1104 P_("GIcon for primary icon"),
1106 GTK_PARAM_READWRITE));
1109 * GtkEntry:secondary-icon-gicon:
1111 * The #GIcon to use for the secondary icon for the entry.
1115 g_object_class_install_property (gobject_class,
1116 PROP_GICON_SECONDARY,
1117 g_param_spec_object ("secondary-icon-gicon",
1118 P_("Secondary GIcon"),
1119 P_("GIcon for secondary icon"),
1121 GTK_PARAM_READWRITE));
1124 * GtkEntry:primary-icon-storage-type:
1126 * The representation which is used for the primary icon of the entry.
1130 g_object_class_install_property (gobject_class,
1131 PROP_STORAGE_TYPE_PRIMARY,
1132 g_param_spec_enum ("primary-icon-storage-type",
1133 P_("Primary storage type"),
1134 P_("The representation being used for primary icon"),
1135 GTK_TYPE_IMAGE_TYPE,
1137 GTK_PARAM_READABLE));
1140 * GtkEntry:secondary-icon-storage-type:
1142 * The representation which is used for the secondary icon of the entry.
1146 g_object_class_install_property (gobject_class,
1147 PROP_STORAGE_TYPE_SECONDARY,
1148 g_param_spec_enum ("secondary-icon-storage-type",
1149 P_("Secondary storage type"),
1150 P_("The representation being used for secondary icon"),
1151 GTK_TYPE_IMAGE_TYPE,
1153 GTK_PARAM_READABLE));
1156 * GtkEntry:primary-icon-activatable:
1158 * Whether the primary icon is activatable.
1160 * GTK+ emits the #GtkEntry::icon-press and #GtkEntry::icon-release
1161 * signals only on sensitive, activatable icons.
1163 * Sensitive, but non-activatable icons can be used for purely
1164 * informational purposes.
1168 g_object_class_install_property (gobject_class,
1169 PROP_ACTIVATABLE_PRIMARY,
1170 g_param_spec_boolean ("primary-icon-activatable",
1171 P_("Primary icon activatable"),
1172 P_("Whether the primary icon is activatable"),
1174 GTK_PARAM_READWRITE));
1177 * GtkEntry:secondary-icon-activatable:
1179 * Whether the secondary icon is activatable.
1181 * GTK+ emits the #GtkEntry::icon-press and #GtkEntry::icon-release
1182 * signals only on sensitive, activatable icons.
1184 * Sensitive, but non-activatable icons can be used for purely
1185 * informational purposes.
1189 g_object_class_install_property (gobject_class,
1190 PROP_ACTIVATABLE_SECONDARY,
1191 g_param_spec_boolean ("secondary-icon-activatable",
1192 P_("Secondary icon activatable"),
1193 P_("Whether the secondary icon is activatable"),
1195 GTK_PARAM_READWRITE));
1199 * GtkEntry:primary-icon-sensitive:
1201 * Whether the primary icon is sensitive.
1203 * An insensitive icon appears grayed out. GTK+ does not emit the
1204 * #GtkEntry::icon-press and #GtkEntry::icon-release signals and
1205 * does not allow DND from insensitive icons.
1207 * An icon should be set insensitive if the action that would trigger
1208 * when clicked is currently not available.
1212 g_object_class_install_property (gobject_class,
1213 PROP_SENSITIVE_PRIMARY,
1214 g_param_spec_boolean ("primary-icon-sensitive",
1215 P_("Primary icon sensitive"),
1216 P_("Whether the primary icon is sensitive"),
1218 GTK_PARAM_READWRITE));
1221 * GtkEntry:secondary-icon-sensitive:
1223 * Whether the secondary icon is sensitive.
1225 * An insensitive icon appears grayed out. GTK+ does not emit the
1226 * #GtkEntry::icon-press and #GtkEntry::icon-release signals and
1227 * does not allow DND from insensitive icons.
1229 * An icon should be set insensitive if the action that would trigger
1230 * when clicked is currently not available.
1234 g_object_class_install_property (gobject_class,
1235 PROP_SENSITIVE_SECONDARY,
1236 g_param_spec_boolean ("secondary-icon-sensitive",
1237 P_("Secondary icon sensitive"),
1238 P_("Whether the secondary icon is sensitive"),
1240 GTK_PARAM_READWRITE));
1243 * GtkEntry:primary-icon-tooltip-text:
1245 * The contents of the tooltip on the primary icon.
1247 * Also see gtk_entry_set_icon_tooltip_text().
1251 g_object_class_install_property (gobject_class,
1252 PROP_TOOLTIP_TEXT_PRIMARY,
1253 g_param_spec_string ("primary-icon-tooltip-text",
1254 P_("Primary icon tooltip text"),
1255 P_("The contents of the tooltip on the primary icon"),
1257 GTK_PARAM_READWRITE));
1260 * GtkEntry:secondary-icon-tooltip-text:
1262 * The contents of the tooltip on the secondary icon.
1264 * Also see gtk_entry_set_icon_tooltip_text().
1268 g_object_class_install_property (gobject_class,
1269 PROP_TOOLTIP_TEXT_SECONDARY,
1270 g_param_spec_string ("secondary-icon-tooltip-text",
1271 P_("Secondary icon tooltip text"),
1272 P_("The contents of the tooltip on the secondary icon"),
1274 GTK_PARAM_READWRITE));
1277 * GtkEntry:primary-icon-tooltip-markup:
1279 * The contents of the tooltip on the primary icon, which is marked up
1280 * with the <link linkend="PangoMarkupFormat">Pango text markup
1283 * Also see gtk_entry_set_icon_tooltip_markup().
1287 g_object_class_install_property (gobject_class,
1288 PROP_TOOLTIP_MARKUP_PRIMARY,
1289 g_param_spec_string ("primary-icon-tooltip-markup",
1290 P_("Primary icon tooltip markup"),
1291 P_("The contents of the tooltip on the primary icon"),
1293 GTK_PARAM_READWRITE));
1296 * GtkEntry:secondary-icon-tooltip-markup:
1298 * The contents of the tooltip on the secondary icon, which is marked up
1299 * with the <link linkend="PangoMarkupFormat">Pango text markup
1302 * Also see gtk_entry_set_icon_tooltip_markup().
1306 g_object_class_install_property (gobject_class,
1307 PROP_TOOLTIP_MARKUP_SECONDARY,
1308 g_param_spec_string ("secondary-icon-tooltip-markup",
1309 P_("Secondary icon tooltip markup"),
1310 P_("The contents of the tooltip on the secondary icon"),
1312 GTK_PARAM_READWRITE));
1315 * GtkEntry:im-module:
1317 * Which IM (input method) module should be used for this entry.
1318 * See #GtkIMContext.
1320 * Setting this to a non-%NULL value overrides the
1321 * system-wide IM module setting. See the GtkSettings
1322 * #GtkSettings:gtk-im-module property.
1326 g_object_class_install_property (gobject_class,
1328 g_param_spec_string ("im-module",
1330 P_("Which IM module should be used"),
1332 GTK_PARAM_READWRITE));
1335 * GtkEntry:completion:
1337 * The auxiliary completion object to use with the entry.
1341 g_object_class_install_property (gobject_class,
1343 g_param_spec_object ("completion",
1345 P_("The auxiliary completion object"),
1346 GTK_TYPE_ENTRY_COMPLETION,
1347 GTK_PARAM_READWRITE));
1350 * GtkEntry:icon-prelight:
1352 * The prelight style property determines whether activatable
1353 * icons prelight on mouseover.
1357 gtk_widget_class_install_style_property (widget_class,
1358 g_param_spec_boolean ("icon-prelight",
1359 P_("Icon Prelight"),
1360 P_("Whether activatable icons should prelight when hovered"),
1362 GTK_PARAM_READABLE));
1365 * GtkEntry:progress-border:
1367 * The border around the progress bar in the entry.
1371 gtk_widget_class_install_style_property (widget_class,
1372 g_param_spec_boxed ("progress-border",
1373 P_("Progress Border"),
1374 P_("Border around the progress bar"),
1376 GTK_PARAM_READABLE));
1379 * GtkEntry:invisible-char:
1381 * The invisible character is used when masking entry contents (in
1382 * \"password mode\")"). When it is not explicitly set with the
1383 * #GtkEntry::invisible-char property, GTK+ determines the character
1384 * to use from a list of possible candidates, depending on availability
1385 * in the current font.
1387 * This style property allows the theme to prepend a character
1388 * to the list of candidates.
1392 gtk_widget_class_install_style_property (widget_class,
1393 g_param_spec_unichar ("invisible-char",
1394 P_("Invisible character"),
1395 P_("The character to use when masking entry contents (in \"password mode\")"),
1397 GTK_PARAM_READABLE));
1400 * GtkEntry::populate-popup:
1401 * @entry: The entry on which the signal is emitted
1402 * @menu: the menu that is being populated
1404 * The ::populate-popup signal gets emitted before showing the
1405 * context menu of the entry.
1407 * If you need to add items to the context menu, connect
1408 * to this signal and append your menuitems to the @menu.
1410 signals[POPULATE_POPUP] =
1411 g_signal_new (I_("populate-popup"),
1412 G_OBJECT_CLASS_TYPE (gobject_class),
1414 G_STRUCT_OFFSET (GtkEntryClass, populate_popup),
1416 _gtk_marshal_VOID__OBJECT,
1420 /* Action signals */
1423 * GtkEntry::activate:
1424 * @entry: The entry on which the signal is emitted
1426 * A <link linkend="keybinding-signals">keybinding signal</link>
1427 * which gets emitted when the user activates the entry.
1429 * Applications should not connect to it, but may emit it with
1430 * g_signal_emit_by_name() if they need to control activation
1433 * The default bindings for this signal are all forms of the Enter key.
1436 g_signal_new (I_("activate"),
1437 G_OBJECT_CLASS_TYPE (gobject_class),
1438 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1439 G_STRUCT_OFFSET (GtkEntryClass, activate),
1441 _gtk_marshal_VOID__VOID,
1443 widget_class->activate_signal = signals[ACTIVATE];
1446 * GtkEntry::move-cursor:
1447 * @entry: the object which received the signal
1448 * @step: the granularity of the move, as a #GtkMovementStep
1449 * @count: the number of @step units to move
1450 * @extend_selection: %TRUE if the move should extend the selection
1452 * The ::move-cursor signal is a
1453 * <link linkend="keybinding-signals">keybinding signal</link>
1454 * which gets emitted when the user initiates a cursor movement.
1455 * If the cursor is not visible in @entry, this signal causes
1456 * the viewport to be moved instead.
1458 * Applications should not connect to it, but may emit it with
1459 * g_signal_emit_by_name() if they need to control the cursor
1462 * The default bindings for this signal come in two variants,
1463 * the variant with the Shift modifier extends the selection,
1464 * the variant without the Shift modifer does not.
1465 * There are too many key combinations to list them all here.
1467 * <listitem>Arrow keys move by individual characters/lines</listitem>
1468 * <listitem>Ctrl-arrow key combinations move by words/paragraphs</listitem>
1469 * <listitem>Home/End keys move to the ends of the buffer</listitem>
1472 signals[MOVE_CURSOR] =
1473 g_signal_new (I_("move-cursor"),
1474 G_OBJECT_CLASS_TYPE (gobject_class),
1475 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1476 G_STRUCT_OFFSET (GtkEntryClass, move_cursor),
1478 _gtk_marshal_VOID__ENUM_INT_BOOLEAN,
1480 GTK_TYPE_MOVEMENT_STEP,
1485 * GtkEntry::insert-at-cursor:
1486 * @entry: the object which received the signal
1487 * @string: the string to insert
1489 * The ::insert-at-cursor signal is a
1490 * <link linkend="keybinding-signals">keybinding signal</link>
1491 * which gets emitted when the user initiates the insertion of a
1492 * fixed string at the cursor.
1494 * This signal has no default bindings.
1496 signals[INSERT_AT_CURSOR] =
1497 g_signal_new (I_("insert-at-cursor"),
1498 G_OBJECT_CLASS_TYPE (gobject_class),
1499 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1500 G_STRUCT_OFFSET (GtkEntryClass, insert_at_cursor),
1502 _gtk_marshal_VOID__STRING,
1507 * GtkEntry::delete-from-cursor:
1508 * @entry: the object which received the signal
1509 * @type: the granularity of the deletion, as a #GtkDeleteType
1510 * @count: the number of @type units to delete
1512 * The ::delete-from-cursor signal is a
1513 * <link linkend="keybinding-signals">keybinding signal</link>
1514 * which gets emitted when the user initiates a text deletion.
1516 * If the @type is %GTK_DELETE_CHARS, GTK+ deletes the selection
1517 * if there is one, otherwise it deletes the requested number
1520 * The default bindings for this signal are
1521 * Delete for deleting a character and Ctrl-Delete for
1524 signals[DELETE_FROM_CURSOR] =
1525 g_signal_new (I_("delete-from-cursor"),
1526 G_OBJECT_CLASS_TYPE (gobject_class),
1527 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1528 G_STRUCT_OFFSET (GtkEntryClass, delete_from_cursor),
1530 _gtk_marshal_VOID__ENUM_INT,
1532 GTK_TYPE_DELETE_TYPE,
1536 * GtkEntry::backspace:
1537 * @entry: the object which received the signal
1539 * The ::backspace signal is a
1540 * <link linkend="keybinding-signals">keybinding signal</link>
1541 * which gets emitted when the user asks for it.
1543 * The default bindings for this signal are
1544 * Backspace and Shift-Backspace.
1546 signals[BACKSPACE] =
1547 g_signal_new (I_("backspace"),
1548 G_OBJECT_CLASS_TYPE (gobject_class),
1549 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1550 G_STRUCT_OFFSET (GtkEntryClass, backspace),
1552 _gtk_marshal_VOID__VOID,
1556 * GtkEntry::cut-clipboard:
1557 * @entry: the object which received the signal
1559 * The ::cut-clipboard signal is a
1560 * <link linkend="keybinding-signals">keybinding signal</link>
1561 * which gets emitted to cut the selection to the clipboard.
1563 * The default bindings for this signal are
1564 * Ctrl-x and Shift-Delete.
1566 signals[CUT_CLIPBOARD] =
1567 g_signal_new (I_("cut-clipboard"),
1568 G_OBJECT_CLASS_TYPE (gobject_class),
1569 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1570 G_STRUCT_OFFSET (GtkEntryClass, cut_clipboard),
1572 _gtk_marshal_VOID__VOID,
1576 * GtkEntry::copy-clipboard:
1577 * @entry: the object which received the signal
1579 * The ::copy-clipboard signal is a
1580 * <link linkend="keybinding-signals">keybinding signal</link>
1581 * which gets emitted to copy the selection to the clipboard.
1583 * The default bindings for this signal are
1584 * Ctrl-c and Ctrl-Insert.
1586 signals[COPY_CLIPBOARD] =
1587 g_signal_new (I_("copy-clipboard"),
1588 G_OBJECT_CLASS_TYPE (gobject_class),
1589 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1590 G_STRUCT_OFFSET (GtkEntryClass, copy_clipboard),
1592 _gtk_marshal_VOID__VOID,
1596 * GtkEntry::paste-clipboard:
1597 * @entry: the object which received the signal
1599 * The ::paste-clipboard signal is a
1600 * <link linkend="keybinding-signals">keybinding signal</link>
1601 * which gets emitted to paste the contents of the clipboard
1602 * into the text view.
1604 * The default bindings for this signal are
1605 * Ctrl-v and Shift-Insert.
1607 signals[PASTE_CLIPBOARD] =
1608 g_signal_new (I_("paste-clipboard"),
1609 G_OBJECT_CLASS_TYPE (gobject_class),
1610 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1611 G_STRUCT_OFFSET (GtkEntryClass, paste_clipboard),
1613 _gtk_marshal_VOID__VOID,
1617 * GtkEntry::toggle-overwrite:
1618 * @entry: the object which received the signal
1620 * The ::toggle-overwrite signal is a
1621 * <link linkend="keybinding-signals">keybinding signal</link>
1622 * which gets emitted to toggle the overwrite mode of the entry.
1624 * The default bindings for this signal is Insert.
1626 signals[TOGGLE_OVERWRITE] =
1627 g_signal_new (I_("toggle-overwrite"),
1628 G_OBJECT_CLASS_TYPE (gobject_class),
1629 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1630 G_STRUCT_OFFSET (GtkEntryClass, toggle_overwrite),
1632 _gtk_marshal_VOID__VOID,
1636 * GtkEntry::icon-press:
1637 * @entry: The entry on which the signal is emitted
1638 * @icon_pos: The position of the clicked icon
1639 * @event: (type Gdk.EventButton): the button press event
1641 * The ::icon-press signal is emitted when an activatable icon
1646 signals[ICON_PRESS] =
1647 g_signal_new (I_("icon-press"),
1648 G_TYPE_FROM_CLASS (gobject_class),
1652 _gtk_marshal_VOID__ENUM_BOXED,
1654 GTK_TYPE_ENTRY_ICON_POSITION,
1655 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1658 * GtkEntry::icon-release:
1659 * @entry: The entry on which the signal is emitted
1660 * @icon_pos: The position of the clicked icon
1661 * @event: (type Gdk.EventButton): the button release event
1663 * The ::icon-release signal is emitted on the button release from a
1664 * mouse click over an activatable icon.
1668 signals[ICON_RELEASE] =
1669 g_signal_new (I_("icon-release"),
1670 G_TYPE_FROM_CLASS (gobject_class),
1674 _gtk_marshal_VOID__ENUM_BOXED,
1676 GTK_TYPE_ENTRY_ICON_POSITION,
1677 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1680 * GtkEntry::preedit-changed:
1681 * @entry: the object which received the signal
1682 * @preedit: the current preedit string
1684 * If an input method is used, the typed text will not immediately
1685 * be committed to the buffer. So if you are interested in the text,
1686 * connect to this signal.
1690 signals[PREEDIT_CHANGED] =
1691 g_signal_new_class_handler (I_("preedit-changed"),
1692 G_OBJECT_CLASS_TYPE (gobject_class),
1693 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1696 _gtk_marshal_VOID__STRING,
1705 binding_set = gtk_binding_set_by_class (class);
1707 /* Moving the insertion point */
1708 add_move_binding (binding_set, GDK_KEY_Right, 0,
1709 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1711 add_move_binding (binding_set, GDK_KEY_Left, 0,
1712 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1714 add_move_binding (binding_set, GDK_KEY_KP_Right, 0,
1715 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1717 add_move_binding (binding_set, GDK_KEY_KP_Left, 0,
1718 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1720 add_move_binding (binding_set, GDK_KEY_Right, GDK_CONTROL_MASK,
1721 GTK_MOVEMENT_WORDS, 1);
1723 add_move_binding (binding_set, GDK_KEY_Left, GDK_CONTROL_MASK,
1724 GTK_MOVEMENT_WORDS, -1);
1726 add_move_binding (binding_set, GDK_KEY_KP_Right, GDK_CONTROL_MASK,
1727 GTK_MOVEMENT_WORDS, 1);
1729 add_move_binding (binding_set, GDK_KEY_KP_Left, GDK_CONTROL_MASK,
1730 GTK_MOVEMENT_WORDS, -1);
1732 add_move_binding (binding_set, GDK_KEY_Home, 0,
1733 GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
1735 add_move_binding (binding_set, GDK_KEY_End, 0,
1736 GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
1738 add_move_binding (binding_set, GDK_KEY_KP_Home, 0,
1739 GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
1741 add_move_binding (binding_set, GDK_KEY_KP_End, 0,
1742 GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
1744 add_move_binding (binding_set, GDK_KEY_Home, GDK_CONTROL_MASK,
1745 GTK_MOVEMENT_BUFFER_ENDS, -1);
1747 add_move_binding (binding_set, GDK_KEY_End, GDK_CONTROL_MASK,
1748 GTK_MOVEMENT_BUFFER_ENDS, 1);
1750 add_move_binding (binding_set, GDK_KEY_KP_Home, GDK_CONTROL_MASK,
1751 GTK_MOVEMENT_BUFFER_ENDS, -1);
1753 add_move_binding (binding_set, GDK_KEY_KP_End, GDK_CONTROL_MASK,
1754 GTK_MOVEMENT_BUFFER_ENDS, 1);
1758 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK,
1760 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1762 G_TYPE_BOOLEAN, FALSE);
1763 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK,
1765 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1767 G_TYPE_BOOLEAN, TRUE);
1769 gtk_binding_entry_add_signal (binding_set, GDK_KEY_slash, GDK_CONTROL_MASK,
1771 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1773 G_TYPE_BOOLEAN, FALSE);
1774 gtk_binding_entry_add_signal (binding_set, GDK_KEY_slash, GDK_CONTROL_MASK,
1776 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1778 G_TYPE_BOOLEAN, TRUE);
1781 gtk_binding_entry_add_signal (binding_set, GDK_KEY_backslash, GDK_CONTROL_MASK,
1783 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_VISUAL_POSITIONS,
1785 G_TYPE_BOOLEAN, FALSE);
1786 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_SHIFT_MASK | GDK_CONTROL_MASK,
1788 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_VISUAL_POSITIONS,
1790 G_TYPE_BOOLEAN, FALSE);
1794 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Return, 0,
1796 gtk_binding_entry_add_signal (binding_set, GDK_KEY_ISO_Enter, 0,
1798 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Enter, 0,
1802 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, 0,
1803 "delete-from-cursor", 2,
1804 G_TYPE_ENUM, GTK_DELETE_CHARS,
1807 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Delete, 0,
1808 "delete-from-cursor", 2,
1809 G_TYPE_ENUM, GTK_DELETE_CHARS,
1812 gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, 0,
1815 /* Make this do the same as Backspace, to help with mis-typing */
1816 gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, GDK_SHIFT_MASK,
1819 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, GDK_CONTROL_MASK,
1820 "delete-from-cursor", 2,
1821 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1824 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Delete, GDK_CONTROL_MASK,
1825 "delete-from-cursor", 2,
1826 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1829 gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, GDK_CONTROL_MASK,
1830 "delete-from-cursor", 2,
1831 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1834 /* Cut/copy/paste */
1836 gtk_binding_entry_add_signal (binding_set, GDK_KEY_x, GDK_CONTROL_MASK,
1837 "cut-clipboard", 0);
1838 gtk_binding_entry_add_signal (binding_set, GDK_KEY_c, GDK_CONTROL_MASK,
1839 "copy-clipboard", 0);
1840 gtk_binding_entry_add_signal (binding_set, GDK_KEY_v, GDK_CONTROL_MASK,
1841 "paste-clipboard", 0);
1843 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, GDK_SHIFT_MASK,
1844 "cut-clipboard", 0);
1845 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, GDK_CONTROL_MASK,
1846 "copy-clipboard", 0);
1847 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, GDK_SHIFT_MASK,
1848 "paste-clipboard", 0);
1851 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, 0,
1852 "toggle-overwrite", 0);
1853 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Insert, 0,
1854 "toggle-overwrite", 0);
1857 * GtkEntry:inner-border:
1859 * Sets the text area's border between the text and the frame.
1863 gtk_widget_class_install_style_property (widget_class,
1864 g_param_spec_boxed ("inner-border",
1866 P_("Border between text and frame."),
1868 GTK_PARAM_READABLE));
1870 g_type_class_add_private (gobject_class, sizeof (GtkEntryPrivate));
1874 gtk_entry_editable_init (GtkEditableInterface *iface)
1876 iface->do_insert_text = gtk_entry_insert_text;
1877 iface->do_delete_text = gtk_entry_delete_text;
1878 iface->insert_text = gtk_entry_real_insert_text;
1879 iface->delete_text = gtk_entry_real_delete_text;
1880 iface->get_chars = gtk_entry_get_chars;
1881 iface->set_selection_bounds = gtk_entry_set_selection_bounds;
1882 iface->get_selection_bounds = gtk_entry_get_selection_bounds;
1883 iface->set_position = gtk_entry_real_set_position;
1884 iface->get_position = gtk_entry_get_position;
1888 gtk_entry_cell_editable_init (GtkCellEditableIface *iface)
1890 iface->start_editing = gtk_entry_start_editing;
1894 gtk_entry_set_property (GObject *object,
1896 const GValue *value,
1899 GtkEntry *entry = GTK_ENTRY (object);
1900 GtkEntryPrivate *priv = entry->priv;
1905 gtk_entry_set_buffer (entry, g_value_get_object (value));
1910 gboolean new_value = g_value_get_boolean (value);
1912 if (new_value != priv->editable)
1914 GtkWidget *widget = GTK_WIDGET (entry);
1918 _gtk_entry_reset_im_context (entry);
1919 if (gtk_widget_has_focus (widget))
1920 gtk_im_context_focus_out (priv->im_context);
1922 priv->preedit_length = 0;
1923 priv->preedit_cursor = 0;
1926 priv->editable = new_value;
1928 if (new_value && gtk_widget_has_focus (widget))
1929 gtk_im_context_focus_in (priv->im_context);
1931 gtk_widget_queue_draw (widget);
1936 case PROP_MAX_LENGTH:
1937 gtk_entry_set_max_length (entry, g_value_get_int (value));
1940 case PROP_VISIBILITY:
1941 gtk_entry_set_visibility (entry, g_value_get_boolean (value));
1944 case PROP_HAS_FRAME:
1945 gtk_entry_set_has_frame (entry, g_value_get_boolean (value));
1948 case PROP_INNER_BORDER:
1949 gtk_entry_set_inner_border (entry, g_value_get_boxed (value));
1952 case PROP_INVISIBLE_CHAR:
1953 gtk_entry_set_invisible_char (entry, g_value_get_uint (value));
1956 case PROP_ACTIVATES_DEFAULT:
1957 gtk_entry_set_activates_default (entry, g_value_get_boolean (value));
1960 case PROP_WIDTH_CHARS:
1961 gtk_entry_set_width_chars (entry, g_value_get_int (value));
1965 gtk_entry_set_text (entry, g_value_get_string (value));
1969 gtk_entry_set_alignment (entry, g_value_get_float (value));
1972 case PROP_TRUNCATE_MULTILINE:
1973 priv->truncate_multiline = g_value_get_boolean (value);
1976 case PROP_SHADOW_TYPE:
1977 priv->shadow_type = g_value_get_enum (value);
1980 case PROP_OVERWRITE_MODE:
1981 gtk_entry_set_overwrite_mode (entry, g_value_get_boolean (value));
1984 case PROP_INVISIBLE_CHAR_SET:
1985 if (g_value_get_boolean (value))
1986 priv->invisible_char_set = TRUE;
1988 gtk_entry_unset_invisible_char (entry);
1991 case PROP_CAPS_LOCK_WARNING:
1992 priv->caps_lock_warning = g_value_get_boolean (value);
1995 case PROP_PROGRESS_FRACTION:
1996 gtk_entry_set_progress_fraction (entry, g_value_get_double (value));
1999 case PROP_PROGRESS_PULSE_STEP:
2000 gtk_entry_set_progress_pulse_step (entry, g_value_get_double (value));
2003 case PROP_PLACEHOLDER_TEXT:
2004 gtk_entry_set_placeholder_text (entry, g_value_get_string (value));
2007 case PROP_PIXBUF_PRIMARY:
2008 gtk_entry_set_icon_from_pixbuf (entry,
2009 GTK_ENTRY_ICON_PRIMARY,
2010 g_value_get_object (value));
2013 case PROP_PIXBUF_SECONDARY:
2014 gtk_entry_set_icon_from_pixbuf (entry,
2015 GTK_ENTRY_ICON_SECONDARY,
2016 g_value_get_object (value));
2019 case PROP_STOCK_PRIMARY:
2020 gtk_entry_set_icon_from_stock (entry,
2021 GTK_ENTRY_ICON_PRIMARY,
2022 g_value_get_string (value));
2025 case PROP_STOCK_SECONDARY:
2026 gtk_entry_set_icon_from_stock (entry,
2027 GTK_ENTRY_ICON_SECONDARY,
2028 g_value_get_string (value));
2031 case PROP_ICON_NAME_PRIMARY:
2032 gtk_entry_set_icon_from_icon_name (entry,
2033 GTK_ENTRY_ICON_PRIMARY,
2034 g_value_get_string (value));
2037 case PROP_ICON_NAME_SECONDARY:
2038 gtk_entry_set_icon_from_icon_name (entry,
2039 GTK_ENTRY_ICON_SECONDARY,
2040 g_value_get_string (value));
2043 case PROP_GICON_PRIMARY:
2044 gtk_entry_set_icon_from_gicon (entry,
2045 GTK_ENTRY_ICON_PRIMARY,
2046 g_value_get_object (value));
2049 case PROP_GICON_SECONDARY:
2050 gtk_entry_set_icon_from_gicon (entry,
2051 GTK_ENTRY_ICON_SECONDARY,
2052 g_value_get_object (value));
2055 case PROP_ACTIVATABLE_PRIMARY:
2056 gtk_entry_set_icon_activatable (entry,
2057 GTK_ENTRY_ICON_PRIMARY,
2058 g_value_get_boolean (value));
2061 case PROP_ACTIVATABLE_SECONDARY:
2062 gtk_entry_set_icon_activatable (entry,
2063 GTK_ENTRY_ICON_SECONDARY,
2064 g_value_get_boolean (value));
2067 case PROP_SENSITIVE_PRIMARY:
2068 gtk_entry_set_icon_sensitive (entry,
2069 GTK_ENTRY_ICON_PRIMARY,
2070 g_value_get_boolean (value));
2073 case PROP_SENSITIVE_SECONDARY:
2074 gtk_entry_set_icon_sensitive (entry,
2075 GTK_ENTRY_ICON_SECONDARY,
2076 g_value_get_boolean (value));
2079 case PROP_TOOLTIP_TEXT_PRIMARY:
2080 gtk_entry_set_icon_tooltip_text (entry,
2081 GTK_ENTRY_ICON_PRIMARY,
2082 g_value_get_string (value));
2085 case PROP_TOOLTIP_TEXT_SECONDARY:
2086 gtk_entry_set_icon_tooltip_text (entry,
2087 GTK_ENTRY_ICON_SECONDARY,
2088 g_value_get_string (value));
2091 case PROP_TOOLTIP_MARKUP_PRIMARY:
2092 gtk_entry_set_icon_tooltip_markup (entry,
2093 GTK_ENTRY_ICON_PRIMARY,
2094 g_value_get_string (value));
2097 case PROP_TOOLTIP_MARKUP_SECONDARY:
2098 gtk_entry_set_icon_tooltip_markup (entry,
2099 GTK_ENTRY_ICON_SECONDARY,
2100 g_value_get_string (value));
2103 case PROP_IM_MODULE:
2104 g_free (priv->im_module);
2105 priv->im_module = g_value_dup_string (value);
2106 if (GTK_IS_IM_MULTICONTEXT (priv->im_context))
2107 gtk_im_multicontext_set_context_id (GTK_IM_MULTICONTEXT (priv->im_context), priv->im_module);
2110 case PROP_EDITING_CANCELED:
2111 priv->editing_canceled = g_value_get_boolean (value);
2114 case PROP_COMPLETION:
2115 gtk_entry_set_completion (entry, GTK_ENTRY_COMPLETION (g_value_get_object (value)));
2118 case PROP_SCROLL_OFFSET:
2119 case PROP_CURSOR_POSITION:
2121 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2127 gtk_entry_get_property (GObject *object,
2132 GtkEntry *entry = GTK_ENTRY (object);
2133 GtkEntryPrivate *priv = entry->priv;
2138 g_value_set_object (value, gtk_entry_get_buffer (entry));
2141 case PROP_CURSOR_POSITION:
2142 g_value_set_int (value, priv->current_pos);
2145 case PROP_SELECTION_BOUND:
2146 g_value_set_int (value, priv->selection_bound);
2150 g_value_set_boolean (value, priv->editable);
2153 case PROP_MAX_LENGTH:
2154 g_value_set_int (value, gtk_entry_buffer_get_max_length (get_buffer (entry)));
2157 case PROP_VISIBILITY:
2158 g_value_set_boolean (value, priv->visible);
2161 case PROP_HAS_FRAME:
2162 g_value_set_boolean (value, priv->has_frame);
2165 case PROP_INNER_BORDER:
2166 g_value_set_boxed (value, gtk_entry_get_inner_border (entry));
2169 case PROP_INVISIBLE_CHAR:
2170 g_value_set_uint (value, priv->invisible_char);
2173 case PROP_ACTIVATES_DEFAULT:
2174 g_value_set_boolean (value, priv->activates_default);
2177 case PROP_WIDTH_CHARS:
2178 g_value_set_int (value, priv->width_chars);
2181 case PROP_SCROLL_OFFSET:
2182 g_value_set_int (value, priv->scroll_offset);
2186 g_value_set_string (value, gtk_entry_get_text (entry));
2190 g_value_set_float (value, gtk_entry_get_alignment (entry));
2193 case PROP_TRUNCATE_MULTILINE:
2194 g_value_set_boolean (value, priv->truncate_multiline);
2197 case PROP_SHADOW_TYPE:
2198 g_value_set_enum (value, priv->shadow_type);
2201 case PROP_OVERWRITE_MODE:
2202 g_value_set_boolean (value, priv->overwrite_mode);
2205 case PROP_TEXT_LENGTH:
2206 g_value_set_uint (value, gtk_entry_buffer_get_length (get_buffer (entry)));
2209 case PROP_INVISIBLE_CHAR_SET:
2210 g_value_set_boolean (value, priv->invisible_char_set);
2213 case PROP_IM_MODULE:
2214 g_value_set_string (value, priv->im_module);
2217 case PROP_CAPS_LOCK_WARNING:
2218 g_value_set_boolean (value, priv->caps_lock_warning);
2221 case PROP_PROGRESS_FRACTION:
2222 g_value_set_double (value, priv->progress_fraction);
2225 case PROP_PROGRESS_PULSE_STEP:
2226 g_value_set_double (value, priv->progress_pulse_fraction);
2229 case PROP_PLACEHOLDER_TEXT:
2230 g_value_set_string (value, gtk_entry_get_placeholder_text (entry));
2233 case PROP_PIXBUF_PRIMARY:
2234 g_value_set_object (value,
2235 gtk_entry_get_icon_pixbuf (entry,
2236 GTK_ENTRY_ICON_PRIMARY));
2239 case PROP_PIXBUF_SECONDARY:
2240 g_value_set_object (value,
2241 gtk_entry_get_icon_pixbuf (entry,
2242 GTK_ENTRY_ICON_SECONDARY));
2245 case PROP_STOCK_PRIMARY:
2246 g_value_set_string (value,
2247 gtk_entry_get_icon_stock (entry,
2248 GTK_ENTRY_ICON_PRIMARY));
2251 case PROP_STOCK_SECONDARY:
2252 g_value_set_string (value,
2253 gtk_entry_get_icon_stock (entry,
2254 GTK_ENTRY_ICON_SECONDARY));
2257 case PROP_ICON_NAME_PRIMARY:
2258 g_value_set_string (value,
2259 gtk_entry_get_icon_name (entry,
2260 GTK_ENTRY_ICON_PRIMARY));
2263 case PROP_ICON_NAME_SECONDARY:
2264 g_value_set_string (value,
2265 gtk_entry_get_icon_name (entry,
2266 GTK_ENTRY_ICON_SECONDARY));
2269 case PROP_GICON_PRIMARY:
2270 g_value_set_object (value,
2271 gtk_entry_get_icon_gicon (entry,
2272 GTK_ENTRY_ICON_PRIMARY));
2275 case PROP_GICON_SECONDARY:
2276 g_value_set_object (value,
2277 gtk_entry_get_icon_gicon (entry,
2278 GTK_ENTRY_ICON_SECONDARY));
2281 case PROP_STORAGE_TYPE_PRIMARY:
2282 g_value_set_enum (value,
2283 gtk_entry_get_icon_storage_type (entry,
2284 GTK_ENTRY_ICON_PRIMARY));
2287 case PROP_STORAGE_TYPE_SECONDARY:
2288 g_value_set_enum (value,
2289 gtk_entry_get_icon_storage_type (entry,
2290 GTK_ENTRY_ICON_SECONDARY));
2293 case PROP_ACTIVATABLE_PRIMARY:
2294 g_value_set_boolean (value,
2295 gtk_entry_get_icon_activatable (entry, GTK_ENTRY_ICON_PRIMARY));
2298 case PROP_ACTIVATABLE_SECONDARY:
2299 g_value_set_boolean (value,
2300 gtk_entry_get_icon_activatable (entry, GTK_ENTRY_ICON_SECONDARY));
2303 case PROP_SENSITIVE_PRIMARY:
2304 g_value_set_boolean (value,
2305 gtk_entry_get_icon_sensitive (entry, GTK_ENTRY_ICON_PRIMARY));
2308 case PROP_SENSITIVE_SECONDARY:
2309 g_value_set_boolean (value,
2310 gtk_entry_get_icon_sensitive (entry, GTK_ENTRY_ICON_SECONDARY));
2313 case PROP_TOOLTIP_TEXT_PRIMARY:
2314 g_value_take_string (value,
2315 gtk_entry_get_icon_tooltip_text (entry, GTK_ENTRY_ICON_PRIMARY));
2318 case PROP_TOOLTIP_TEXT_SECONDARY:
2319 g_value_take_string (value,
2320 gtk_entry_get_icon_tooltip_text (entry, GTK_ENTRY_ICON_SECONDARY));
2323 case PROP_TOOLTIP_MARKUP_PRIMARY:
2324 g_value_take_string (value,
2325 gtk_entry_get_icon_tooltip_markup (entry, GTK_ENTRY_ICON_PRIMARY));
2328 case PROP_TOOLTIP_MARKUP_SECONDARY:
2329 g_value_take_string (value,
2330 gtk_entry_get_icon_tooltip_markup (entry, GTK_ENTRY_ICON_SECONDARY));
2333 case PROP_EDITING_CANCELED:
2334 g_value_set_boolean (value,
2335 priv->editing_canceled);
2338 case PROP_COMPLETION:
2339 g_value_set_object (value, G_OBJECT (gtk_entry_get_completion (entry)));
2343 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2349 find_invisible_char (GtkWidget *widget)
2351 PangoLayout *layout;
2352 PangoAttrList *attr_list;
2354 gunichar invisible_chars [] = {
2356 0x25cf, /* BLACK CIRCLE */
2357 0x2022, /* BULLET */
2358 0x2731, /* HEAVY ASTERISK */
2359 0x273a /* SIXTEEN POINTED ASTERISK */
2362 gtk_widget_style_get (widget,
2363 "invisible-char", &invisible_chars[0],
2366 layout = gtk_widget_create_pango_layout (widget, NULL);
2368 attr_list = pango_attr_list_new ();
2369 pango_attr_list_insert (attr_list, pango_attr_fallback_new (FALSE));
2371 pango_layout_set_attributes (layout, attr_list);
2372 pango_attr_list_unref (attr_list);
2374 for (i = (invisible_chars[0] != 0 ? 0 : 1); i < G_N_ELEMENTS (invisible_chars); i++)
2376 gchar text[7] = { 0, };
2379 len = g_unichar_to_utf8 (invisible_chars[i], text);
2380 pango_layout_set_text (layout, text, len);
2382 count = pango_layout_get_unknown_glyphs_count (layout);
2386 g_object_unref (layout);
2387 return invisible_chars[i];
2391 g_object_unref (layout);
2397 gtk_entry_init (GtkEntry *entry)
2399 GtkStyleContext *context;
2400 GtkEntryPrivate *priv;
2402 entry->priv = G_TYPE_INSTANCE_GET_PRIVATE (entry,
2407 gtk_widget_set_can_focus (GTK_WIDGET (entry), TRUE);
2408 gtk_widget_set_has_window (GTK_WIDGET (entry), FALSE);
2410 priv->editable = TRUE;
2411 priv->visible = TRUE;
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);
2448 gtk_entry_update_cached_style_values (entry);
2452 get_icon_width (GtkEntry *entry,
2453 GtkEntryIconPosition icon_pos)
2455 GtkEntryPrivate *priv = entry->priv;
2456 EntryIconInfo *icon_info = priv->icons[icon_pos];
2458 GtkSettings *settings;
2459 gint menu_icon_width;
2461 if (!icon_info || icon_info->pixbuf == NULL)
2464 screen = gtk_widget_get_screen (GTK_WIDGET (entry));
2465 settings = gtk_settings_get_for_screen (screen);
2467 gtk_icon_size_lookup_for_settings (settings, GTK_ICON_SIZE_MENU,
2468 &menu_icon_width, NULL);
2470 return MAX (gdk_pixbuf_get_width (icon_info->pixbuf), menu_icon_width);
2474 get_icon_allocations (GtkEntry *entry,
2475 GtkAllocation *primary,
2476 GtkAllocation *secondary)
2479 GtkEntryPrivate *priv = entry->priv;
2480 gint x, y, width, height;
2482 get_text_area_size (entry, &x, &y, &width, &height);
2484 if (gtk_widget_has_focus (GTK_WIDGET (entry)) && !priv->interior_focus)
2485 y += priv->focus_width;
2488 primary->height = height;
2489 primary->width = get_icon_width (entry, GTK_ENTRY_ICON_PRIMARY);
2490 if (primary->width > 0)
2491 primary->width += 2 * priv->icon_margin;
2494 secondary->height = height;
2495 secondary->width = get_icon_width (entry, GTK_ENTRY_ICON_SECONDARY);
2496 if (secondary->width > 0)
2497 secondary->width += 2 * priv->icon_margin;
2499 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
2501 primary->x = x + width - primary->width;
2507 secondary->x = x + width - secondary->width;
2513 begin_change (GtkEntry *entry)
2515 GtkEntryPrivate *priv = entry->priv;
2517 priv->change_count++;
2521 end_change (GtkEntry *entry)
2523 GtkEditable *editable = GTK_EDITABLE (entry);
2524 GtkEntryPrivate *priv = entry->priv;
2526 g_return_if_fail (priv->change_count > 0);
2528 priv->change_count--;
2530 if (priv->change_count == 0)
2532 if (priv->real_changed)
2534 g_signal_emit_by_name (editable, "changed");
2535 priv->real_changed = FALSE;
2541 emit_changed (GtkEntry *entry)
2543 GtkEditable *editable = GTK_EDITABLE (entry);
2544 GtkEntryPrivate *priv = entry->priv;
2546 if (priv->change_count == 0)
2547 g_signal_emit_by_name (editable, "changed");
2549 priv->real_changed = TRUE;
2553 gtk_entry_destroy (GtkWidget *widget)
2555 GtkEntry *entry = GTK_ENTRY (widget);
2556 GtkEntryPrivate *priv = entry->priv;
2558 priv->current_pos = priv->selection_bound = 0;
2559 _gtk_entry_reset_im_context (entry);
2560 gtk_entry_reset_layout (entry);
2562 if (priv->blink_timeout)
2564 g_source_remove (priv->blink_timeout);
2565 priv->blink_timeout = 0;
2568 if (priv->recompute_idle)
2570 g_source_remove (priv->recompute_idle);
2571 priv->recompute_idle = 0;
2574 GTK_WIDGET_CLASS (gtk_entry_parent_class)->destroy (widget);
2578 gtk_entry_dispose (GObject *object)
2580 GtkEntry *entry = GTK_ENTRY (object);
2581 GtkEntryPrivate *priv = entry->priv;
2583 gtk_entry_set_icon_from_pixbuf (entry, GTK_ENTRY_ICON_PRIMARY, NULL);
2584 gtk_entry_set_icon_tooltip_markup (entry, GTK_ENTRY_ICON_PRIMARY, NULL);
2585 gtk_entry_set_icon_from_pixbuf (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
2586 gtk_entry_set_icon_tooltip_markup (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
2590 buffer_disconnect_signals (entry);
2591 g_object_unref (priv->buffer);
2592 priv->buffer = NULL;
2595 G_OBJECT_CLASS (gtk_entry_parent_class)->dispose (object);
2599 gtk_entry_finalize (GObject *object)
2601 GtkEntry *entry = GTK_ENTRY (object);
2602 GtkEntryPrivate *priv = entry->priv;
2603 EntryIconInfo *icon_info = NULL;
2606 for (i = 0; i < MAX_ICONS; i++)
2608 if ((icon_info = priv->icons[i]) != NULL)
2610 if (icon_info->target_list != NULL)
2612 gtk_target_list_unref (icon_info->target_list);
2613 icon_info->target_list = NULL;
2616 g_slice_free (EntryIconInfo, icon_info);
2617 priv->icons[i] = NULL;
2621 gtk_entry_set_completion (entry, NULL);
2623 if (priv->cached_layout)
2624 g_object_unref (priv->cached_layout);
2626 g_object_unref (priv->im_context);
2628 if (priv->blink_timeout)
2629 g_source_remove (priv->blink_timeout);
2631 if (priv->recompute_idle)
2632 g_source_remove (priv->recompute_idle);
2634 g_free (priv->placeholder_text);
2635 g_free (priv->im_module);
2637 G_OBJECT_CLASS (gtk_entry_parent_class)->finalize (object);
2641 gtk_entry_get_display_mode (GtkEntry *entry)
2643 GtkEntryPrivate *priv = entry->priv;
2646 return DISPLAY_NORMAL;
2648 if (priv->invisible_char == 0 && priv->invisible_char_set)
2649 return DISPLAY_BLANK;
2651 return DISPLAY_INVISIBLE;
2655 gtk_entry_get_display_text (GtkEntry *entry,
2659 GtkEntryPasswordHint *password_hint;
2660 GtkEntryPrivate *priv;
2661 gunichar invisible_char;
2672 text = gtk_entry_buffer_get_text (get_buffer (entry));
2673 length = gtk_entry_buffer_get_length (get_buffer (entry));
2677 if (start_pos > length)
2680 if (end_pos <= start_pos)
2681 return g_strdup ("");
2682 else if (priv->visible)
2684 start = g_utf8_offset_to_pointer (text, start_pos);
2685 end = g_utf8_offset_to_pointer (start, end_pos - start_pos);
2686 return g_strndup (start, end - start);
2690 str = g_string_sized_new (length * 2);
2692 /* Figure out what our invisible char is and encode it */
2693 if (!priv->invisible_char)
2694 invisible_char = priv->invisible_char_set ? ' ' : '*';
2696 invisible_char = priv->invisible_char;
2697 char_len = g_unichar_to_utf8 (invisible_char, char_str);
2700 * Add hidden characters for each character in the text
2701 * buffer. If there is a password hint, then keep that
2702 * character visible.
2705 password_hint = g_object_get_qdata (G_OBJECT (entry), quark_password_hint);
2706 for (i = start_pos; i < end_pos; ++i)
2708 if (password_hint && i == password_hint->position)
2710 start = g_utf8_offset_to_pointer (text, i);
2711 g_string_append_len (str, start, g_utf8_next_char (start) - start);
2715 g_string_append_len (str, char_str, char_len);
2719 return g_string_free (str, FALSE);
2724 update_cursors (GtkWidget *widget)
2726 GtkEntry *entry = GTK_ENTRY (widget);
2727 GtkEntryPrivate *priv = entry->priv;
2728 EntryIconInfo *icon_info = NULL;
2729 GdkDisplay *display;
2733 for (i = 0; i < MAX_ICONS; i++)
2735 if ((icon_info = priv->icons[i]) != NULL)
2737 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
2738 gdk_window_show_unraised (icon_info->window);
2740 /* The icon windows are not children of the visible entry window,
2741 * thus we can't just inherit the xterm cursor. Slight complication
2742 * here is that for the entry, insensitive => arrow cursor, but for
2743 * an icon in a sensitive entry, insensitive => xterm cursor.
2745 if (gtk_widget_is_sensitive (widget) &&
2746 (icon_info->insensitive ||
2747 (icon_info->nonactivatable && icon_info->target_list == NULL)))
2749 display = gtk_widget_get_display (widget);
2750 cursor = gdk_cursor_new_for_display (display, GDK_XTERM);
2751 gdk_window_set_cursor (icon_info->window, cursor);
2752 g_object_unref (cursor);
2756 gdk_window_set_cursor (icon_info->window, NULL);
2763 realize_icon_info (GtkWidget *widget,
2764 GtkEntryIconPosition icon_pos)
2766 GtkEntry *entry = GTK_ENTRY (widget);
2767 GtkEntryPrivate *priv = entry->priv;
2768 EntryIconInfo *icon_info = priv->icons[icon_pos];
2769 GdkWindowAttr attributes;
2770 gint attributes_mask;
2772 g_return_if_fail (icon_info != NULL);
2776 attributes.width = 1;
2777 attributes.height = 1;
2778 attributes.window_type = GDK_WINDOW_CHILD;
2779 attributes.wclass = GDK_INPUT_ONLY;
2780 attributes.event_mask = gtk_widget_get_events (widget);
2781 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
2782 GDK_BUTTON_RELEASE_MASK |
2783 GDK_BUTTON1_MOTION_MASK |
2784 GDK_BUTTON3_MOTION_MASK |
2785 GDK_POINTER_MOTION_HINT_MASK |
2786 GDK_POINTER_MOTION_MASK |
2787 GDK_ENTER_NOTIFY_MASK |
2788 GDK_LEAVE_NOTIFY_MASK);
2789 attributes_mask = GDK_WA_X | GDK_WA_Y;
2791 icon_info->window = gdk_window_new (gtk_widget_get_window (widget),
2794 gdk_window_set_user_data (icon_info->window, widget);
2796 gtk_widget_queue_resize (widget);
2799 static EntryIconInfo*
2800 construct_icon_info (GtkWidget *widget,
2801 GtkEntryIconPosition icon_pos)
2803 GtkEntry *entry = GTK_ENTRY (widget);
2804 GtkEntryPrivate *priv = entry->priv;
2805 EntryIconInfo *icon_info;
2807 g_return_val_if_fail (priv->icons[icon_pos] == NULL, NULL);
2809 icon_info = g_slice_new0 (EntryIconInfo);
2810 priv->icons[icon_pos] = icon_info;
2812 if (gtk_widget_get_realized (widget))
2813 realize_icon_info (widget, icon_pos);
2819 gtk_entry_map (GtkWidget *widget)
2821 GtkEntry *entry = GTK_ENTRY (widget);
2822 GtkEntryPrivate *priv = entry->priv;
2823 EntryIconInfo *icon_info = NULL;
2826 GTK_WIDGET_CLASS (gtk_entry_parent_class)->map (widget);
2828 gdk_window_show (priv->text_area);
2830 for (i = 0; i < MAX_ICONS; i++)
2832 if ((icon_info = priv->icons[i]) != NULL)
2834 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
2835 gdk_window_show (icon_info->window);
2839 update_cursors (widget);
2843 gtk_entry_unmap (GtkWidget *widget)
2845 GtkEntry *entry = GTK_ENTRY (widget);
2846 GtkEntryPrivate *priv = entry->priv;
2847 EntryIconInfo *icon_info = NULL;
2850 for (i = 0; i < MAX_ICONS; i++)
2852 if ((icon_info = priv->icons[i]) != NULL)
2854 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
2855 gdk_window_hide (icon_info->window);
2859 gdk_window_hide (priv->text_area);
2861 GTK_WIDGET_CLASS (gtk_entry_parent_class)->unmap (widget);
2865 gtk_entry_realize (GtkWidget *widget)
2868 GtkEntryPrivate *priv;
2869 EntryIconInfo *icon_info;
2871 GdkWindowAttr attributes;
2872 gint attributes_mask;
2873 gint frame_x, frame_y;
2876 gtk_widget_set_realized (widget, TRUE);
2877 window = gtk_widget_get_parent_window (widget);
2878 gtk_widget_set_window (widget, window);
2879 g_object_ref (window);
2881 entry = GTK_ENTRY (widget);
2884 attributes.window_type = GDK_WINDOW_CHILD;
2885 attributes.wclass = GDK_INPUT_ONLY;
2886 attributes.event_mask = gtk_widget_get_events (widget);
2887 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
2888 GDK_BUTTON_RELEASE_MASK |
2889 GDK_BUTTON1_MOTION_MASK |
2890 GDK_BUTTON3_MOTION_MASK |
2891 GDK_POINTER_MOTION_HINT_MASK |
2892 GDK_POINTER_MOTION_MASK |
2893 GDK_ENTER_NOTIFY_MASK |
2894 GDK_LEAVE_NOTIFY_MASK);
2895 attributes_mask = GDK_WA_X | GDK_WA_Y;
2897 get_text_area_size (entry, &attributes.x, &attributes.y, &attributes.width, &attributes.height);
2899 get_frame_size (entry, TRUE, &frame_x, &frame_y, NULL, NULL);
2900 attributes.x += frame_x;
2901 attributes.y += frame_y;
2903 if (gtk_widget_is_sensitive (widget))
2905 attributes.cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
2906 attributes_mask |= GDK_WA_CURSOR;
2909 priv->text_area = gdk_window_new (gtk_widget_get_window (widget),
2913 gdk_window_set_user_data (priv->text_area, entry);
2915 if (attributes_mask & GDK_WA_CURSOR)
2916 g_object_unref (attributes.cursor);
2918 gtk_im_context_set_client_window (priv->im_context, priv->text_area);
2920 gtk_entry_adjust_scroll (entry);
2921 gtk_entry_update_primary_selection (entry);
2924 /* If the icon positions are already setup, create their windows.
2925 * Otherwise if they don't exist yet, then construct_icon_info()
2926 * will create the windows once the widget is already realized.
2928 for (i = 0; i < MAX_ICONS; i++)
2930 if ((icon_info = priv->icons[i]) != NULL)
2932 if (icon_info->window == NULL)
2933 realize_icon_info (widget, i);
2939 gtk_entry_unrealize (GtkWidget *widget)
2941 GtkEntry *entry = GTK_ENTRY (widget);
2942 GtkEntryPrivate *priv = entry->priv;
2943 GtkClipboard *clipboard;
2944 EntryIconInfo *icon_info;
2947 gtk_entry_reset_layout (entry);
2949 gtk_im_context_set_client_window (priv->im_context, NULL);
2951 clipboard = gtk_widget_get_clipboard (widget, GDK_SELECTION_PRIMARY);
2952 if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (entry))
2953 gtk_clipboard_clear (clipboard);
2955 if (priv->text_area)
2957 gdk_window_set_user_data (priv->text_area, NULL);
2958 gdk_window_destroy (priv->text_area);
2959 priv->text_area = NULL;
2962 if (priv->popup_menu)
2964 gtk_widget_destroy (priv->popup_menu);
2965 priv->popup_menu = NULL;
2968 GTK_WIDGET_CLASS (gtk_entry_parent_class)->unrealize (widget);
2970 for (i = 0; i < MAX_ICONS; i++)
2972 if ((icon_info = priv->icons[i]) != NULL)
2974 if (icon_info->window != NULL)
2976 gdk_window_destroy (icon_info->window);
2977 icon_info->window = NULL;
2984 _gtk_entry_get_borders (GtkEntry *entry,
2988 GtkEntryPrivate *priv = entry->priv;
2989 GtkWidget *widget = GTK_WIDGET (entry);
2991 if (priv->has_frame)
2993 GtkStyleContext *context;
2996 context = gtk_widget_get_style_context (widget);
2997 gtk_style_context_get_padding (context, 0, &padding);
2999 *xborder = padding.left;
3000 *yborder = padding.top;
3008 if (!priv->interior_focus)
3010 *xborder += priv->focus_width;
3011 *yborder += priv->focus_width;
3016 gtk_entry_get_preferred_width (GtkWidget *widget,
3020 GtkEntry *entry = GTK_ENTRY (widget);
3021 GtkEntryPrivate *priv = entry->priv;
3022 PangoFontMetrics *metrics;
3023 gint xborder, yborder;
3024 GtkBorder inner_border;
3025 PangoContext *context;
3026 GtkStyleContext *style_context;
3027 GtkStateFlags state;
3028 gint icon_widths = 0;
3032 context = gtk_widget_get_pango_context (widget);
3034 style_context = gtk_widget_get_style_context (widget);
3035 state = gtk_widget_get_state_flags (widget);
3037 metrics = pango_context_get_metrics (context,
3038 gtk_style_context_get_font (style_context, state),
3039 pango_context_get_language (context));
3041 _gtk_entry_get_borders (entry, &xborder, &yborder);
3042 _gtk_entry_effective_inner_border (entry, &inner_border);
3044 if (priv->width_chars < 0)
3045 width = MIN_ENTRY_WIDTH + xborder * 2 + inner_border.left + inner_border.right;
3048 gint char_width = pango_font_metrics_get_approximate_char_width (metrics);
3049 gint digit_width = pango_font_metrics_get_approximate_digit_width (metrics);
3050 gint char_pixels = (MAX (char_width, digit_width) + PANGO_SCALE - 1) / PANGO_SCALE;
3052 width = char_pixels * priv->width_chars + xborder * 2 + inner_border.left + inner_border.right;
3055 for (i = 0; i < MAX_ICONS; i++)
3057 icon_width = get_icon_width (entry, i);
3059 icon_widths += icon_width + 2 * priv->icon_margin;
3062 if (icon_widths > width)
3063 width += icon_widths;
3065 pango_font_metrics_unref (metrics);
3072 gtk_entry_get_preferred_height (GtkWidget *widget,
3076 GtkEntry *entry = GTK_ENTRY (widget);
3077 GtkEntryPrivate *priv = entry->priv;
3078 PangoFontMetrics *metrics;
3079 gint xborder, yborder;
3080 GtkBorder inner_border;
3081 GtkStyleContext *style_context;
3082 GtkStateFlags state;
3083 PangoContext *context;
3086 context = gtk_widget_get_pango_context (widget);
3088 style_context = gtk_widget_get_style_context (widget);
3089 state = gtk_widget_get_state_flags (widget);
3091 metrics = pango_context_get_metrics (context,
3092 gtk_style_context_get_font (style_context, state),
3093 pango_context_get_language (context));
3095 priv->ascent = pango_font_metrics_get_ascent (metrics);
3096 priv->descent = pango_font_metrics_get_descent (metrics);
3098 _gtk_entry_get_borders (entry, &xborder, &yborder);
3099 _gtk_entry_effective_inner_border (entry, &inner_border);
3101 height = PANGO_PIXELS (priv->ascent + priv->descent) + yborder * 2 + inner_border.top + inner_border.bottom;
3103 pango_font_metrics_unref (metrics);
3110 place_windows (GtkEntry *entry)
3112 GtkWidget *widget = GTK_WIDGET (entry);
3113 GtkEntryPrivate *priv = entry->priv;
3114 gint x, y, width, height;
3115 gint frame_x, frame_y;
3116 GtkAllocation primary;
3117 GtkAllocation secondary;
3118 EntryIconInfo *icon_info = NULL;
3120 get_frame_size (entry, TRUE, &frame_x, &frame_y, NULL, NULL);
3121 get_text_area_size (entry, &x, &y, &width, &height);
3122 get_icon_allocations (entry, &primary, &secondary);
3124 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3125 y += priv->focus_width;
3127 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
3128 x += secondary.width;
3131 width -= primary.width + secondary.width;
3135 primary.x += frame_x;
3136 primary.y += frame_y;
3137 secondary.x += frame_x;
3138 secondary.y += frame_y;
3140 if ((icon_info = priv->icons[GTK_ENTRY_ICON_PRIMARY]) != NULL)
3141 gdk_window_move_resize (icon_info->window,
3142 primary.x, primary.y,
3143 primary.width, primary.height);
3145 if ((icon_info = priv->icons[GTK_ENTRY_ICON_SECONDARY]) != NULL)
3146 gdk_window_move_resize (icon_info->window,
3147 secondary.x, secondary.y,
3148 secondary.width, secondary.height);
3150 gdk_window_move_resize (priv->text_area, x, y, width, height);
3154 gtk_entry_get_text_area_size (GtkEntry *entry,
3160 GtkEntryPrivate *priv = entry->priv;
3161 GtkWidget *widget = GTK_WIDGET (entry);
3162 GtkAllocation allocation;
3163 GtkRequisition requisition;
3165 gint xborder, yborder;
3167 gtk_widget_get_preferred_size (widget, &requisition, NULL);
3168 gtk_widget_get_allocation (widget, &allocation);
3169 _gtk_entry_get_borders (entry, &xborder, &yborder);
3171 if (gtk_widget_get_realized (widget))
3172 get_frame_size (entry, TRUE, NULL, NULL, NULL, &frame_height);
3174 frame_height = requisition.height;
3176 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3177 frame_height -= 2 * priv->focus_width;
3183 *y = frame_height / 2 - (requisition.height - yborder * 2) / 2;
3186 *width = allocation.width - xborder * 2;
3189 *height = requisition.height - yborder * 2;
3193 get_text_area_size (GtkEntry *entry,
3199 GtkEntryClass *class;
3201 g_return_if_fail (GTK_IS_ENTRY (entry));
3203 class = GTK_ENTRY_GET_CLASS (entry);
3205 if (class->get_text_area_size)
3206 class->get_text_area_size (entry, x, y, width, height);
3211 get_frame_size (GtkEntry *entry,
3212 gboolean relative_to_window,
3218 GtkEntryPrivate *priv = entry->priv;
3219 GtkAllocation allocation;
3220 GtkRequisition requisition;
3221 GtkWidget *widget = GTK_WIDGET (entry);
3223 gtk_widget_get_preferred_size (widget, &requisition, NULL);
3224 gtk_widget_get_allocation (widget, &allocation);
3227 *x = relative_to_window ? allocation.x : 0;
3231 if (priv->is_cell_renderer)
3234 *y = (allocation.height - requisition.height) / 2;
3236 if (relative_to_window)
3241 *width = allocation.width;
3245 if (priv->is_cell_renderer)
3246 *height = allocation.height;
3248 *height = requisition.height;
3253 _gtk_entry_effective_inner_border (GtkEntry *entry,
3256 GtkBorder *tmp_border;
3258 tmp_border = g_object_get_qdata (G_OBJECT (entry), quark_inner_border);
3262 *border = *tmp_border;
3266 gtk_widget_style_get (GTK_WIDGET (entry), "inner-border", &tmp_border, NULL);
3270 *border = *tmp_border;
3271 gtk_border_free (tmp_border);
3275 *border = default_inner_border;
3279 gtk_entry_size_allocate (GtkWidget *widget,
3280 GtkAllocation *allocation)
3282 GtkEntry *entry = GTK_ENTRY (widget);
3284 gtk_widget_set_allocation (widget, allocation);
3286 if (gtk_widget_get_realized (widget))
3288 GtkEntryCompletion* completion;
3290 place_windows (entry);
3291 gtk_entry_recompute (entry);
3293 completion = gtk_entry_get_completion (entry);
3294 if (completion && gtk_widget_get_mapped (completion->priv->popup_window))
3295 _gtk_entry_completion_resize_popup (completion);
3300 should_prelight (GtkEntry *entry,
3301 GtkEntryIconPosition icon_pos)
3303 GtkEntryPrivate *priv = entry->priv;
3304 EntryIconInfo *icon_info = priv->icons[icon_pos];
3310 if (icon_info->nonactivatable && icon_info->target_list == NULL)
3313 if (icon_info->pressed)
3316 gtk_widget_style_get (GTK_WIDGET (entry),
3317 "icon-prelight", &prelight,
3324 draw_icon (GtkWidget *widget,
3326 GtkEntryIconPosition icon_pos)
3328 GtkEntry *entry = GTK_ENTRY (widget);
3329 GtkEntryPrivate *priv = entry->priv;
3330 EntryIconInfo *icon_info = priv->icons[icon_pos];
3332 gint x, y, width, height;
3333 GtkStyleContext *context;
3334 GtkIconSource *icon_source;
3335 GtkStateFlags state;
3340 gtk_entry_ensure_pixbuf (entry, icon_pos);
3342 if (icon_info->pixbuf == NULL)
3345 width = gdk_window_get_width (icon_info->window);
3346 height = gdk_window_get_height (icon_info->window);
3348 /* size_allocate hasn't been called yet. These are the default values.
3350 if (width == 1 || height == 1)
3353 pixbuf = icon_info->pixbuf;
3354 g_object_ref (pixbuf);
3356 if (gdk_pixbuf_get_height (pixbuf) > height)
3358 GdkPixbuf *temp_pixbuf;
3361 scale = height - 2 * priv->icon_margin;
3362 temp_pixbuf = gdk_pixbuf_scale_simple (pixbuf, scale, scale,
3363 GDK_INTERP_BILINEAR);
3364 g_object_unref (pixbuf);
3365 pixbuf = temp_pixbuf;
3368 x = (width - gdk_pixbuf_get_width (pixbuf)) / 2;
3369 y = (height - gdk_pixbuf_get_height (pixbuf)) / 2;
3371 icon_source = gtk_icon_source_new ();
3372 gtk_icon_source_set_pixbuf (icon_source, pixbuf);
3373 gtk_icon_source_set_state_wildcarded (icon_source, TRUE);
3376 if (!gtk_widget_is_sensitive (widget) || icon_info->insensitive)
3377 state |= GTK_STATE_FLAG_INSENSITIVE;
3378 else if (icon_info->prelight)
3379 state |= GTK_STATE_FLAG_PRELIGHT;
3381 context = gtk_widget_get_style_context (widget);
3382 gtk_style_context_save (context);
3383 gtk_style_context_set_state (context, state);
3384 pixbuf = gtk_render_icon_pixbuf (context, icon_source, (GtkIconSize)-1);
3385 gtk_style_context_restore (context);
3387 gtk_icon_source_free (icon_source);
3389 gdk_cairo_set_source_pixbuf (cr, pixbuf, x, y);
3392 g_object_unref (pixbuf);
3397 gtk_entry_draw_frame (GtkWidget *widget,
3398 GtkStyleContext *context,
3401 GtkEntry *entry = GTK_ENTRY (widget);
3402 GtkEntryPrivate *priv = entry->priv;
3403 gint x = 0, y = 0, width, height;
3404 gint frame_x, frame_y;
3408 get_frame_size (GTK_ENTRY (widget), FALSE, &frame_x, &frame_y, &width, &height);
3410 cairo_translate (cr, frame_x, frame_y);
3412 /* Fix a problem with some themes which assume that entry->text_area's
3413 * width equals widget->window's width
3414 * http://bugzilla.gnome.org/show_bug.cgi?id=466000 */
3415 if (GTK_IS_SPIN_BUTTON (widget))
3417 gint xborder, yborder;
3419 gtk_entry_get_text_area_size (GTK_ENTRY (widget), &x, NULL, &width, NULL);
3420 _gtk_entry_get_borders (GTK_ENTRY (widget), &xborder, &yborder);
3423 width += xborder * 2;
3426 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3428 x += priv->focus_width;
3429 y += priv->focus_width;
3430 width -= 2 * priv->focus_width;
3431 height -= 2 * priv->focus_width;
3434 gtk_render_background (context, cr,
3435 x, y, width, height);
3437 if (priv->has_frame)
3438 gtk_render_frame (context, cr,
3439 x, y, width, height);
3441 gtk_entry_draw_progress (widget, context, cr);
3443 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3445 x -= priv->focus_width;
3446 y -= priv->focus_width;
3447 width += 2 * priv->focus_width;
3448 height += 2 * priv->focus_width;
3450 gtk_render_focus (context, cr,
3451 0, 0, width, height);
3458 get_progress_area (GtkWidget *widget,
3464 GtkEntry *entry = GTK_ENTRY (widget);
3465 GtkEntryPrivate *private = entry->priv;
3466 GtkBorder *progress_border;
3468 get_text_area_size (entry, x, y, width, height);
3470 if (!private->interior_focus)
3472 *x -= private->focus_width;
3473 *y -= private->focus_width;
3474 *width += 2 * private->focus_width;
3475 *height += 2 * private->focus_width;
3478 gtk_widget_style_get (widget, "progress-border", &progress_border, NULL);
3480 if (progress_border)
3482 *x += progress_border->left;
3483 *y += progress_border->top;
3484 *width -= progress_border->left + progress_border->right;
3485 *height -= progress_border->top + progress_border->bottom;
3487 gtk_border_free (progress_border);
3490 if (private->progress_pulse_mode)
3492 gdouble value = private->progress_pulse_current;
3494 *x += (gint) floor(value * (*width));
3495 *width = (gint) ceil(private->progress_pulse_fraction * (*width));
3497 else if (private->progress_fraction > 0)
3499 gdouble value = private->progress_fraction;
3501 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
3505 bar_width = floor(value * (*width) + 0.5);
3506 *x += *width - bar_width;
3511 *width = (gint) floor(value * (*width) + 0.5);
3522 gtk_entry_draw_progress (GtkWidget *widget,
3523 GtkStyleContext *context,
3526 gint x, y, width, height;
3528 get_progress_area (widget, &x, &y, &width, &height);
3530 if ((width <= 0) || (height <= 0))
3533 gtk_style_context_save (context);
3534 gtk_style_context_add_class (context, GTK_STYLE_CLASS_PROGRESSBAR);
3536 gtk_render_activity (context, cr,
3537 x, y, width, height);
3539 gtk_style_context_restore (context);
3543 gtk_entry_draw (GtkWidget *widget,
3546 GtkEntry *entry = GTK_ENTRY (widget);
3547 GtkStyleContext *context;
3548 GtkStateFlags state;
3549 GtkEntryPrivate *priv = entry->priv;
3552 context = gtk_widget_get_style_context (widget);
3553 state = gtk_widget_get_state_flags (widget);
3555 gtk_style_context_save (context);
3556 gtk_style_context_set_state (context, state);
3558 /* Draw entry_bg, shadow, progress and focus */
3559 gtk_entry_draw_frame (widget, context, cr);
3561 /* Draw text and cursor */
3564 gtk_cairo_transform_to_window (cr, widget, priv->text_area);
3566 if (priv->dnd_position != -1)
3567 gtk_entry_draw_cursor (GTK_ENTRY (widget), cr, CURSOR_DND);
3569 gtk_entry_draw_text (GTK_ENTRY (widget), cr);
3571 /* When no text is being displayed at all, don't show the cursor */
3572 if (gtk_entry_get_display_mode (entry) != DISPLAY_BLANK &&
3573 gtk_widget_has_focus (widget) &&
3574 priv->selection_bound == priv->current_pos && priv->cursor_visible)
3575 gtk_entry_draw_cursor (GTK_ENTRY (widget), cr, CURSOR_STANDARD);
3580 for (i = 0; i < MAX_ICONS; i++)
3582 EntryIconInfo *icon_info = priv->icons[i];
3584 if (icon_info != NULL)
3588 gtk_cairo_transform_to_window (cr, widget, icon_info->window);
3590 draw_icon (widget, cr, i);
3596 gtk_style_context_restore (context);
3602 gtk_entry_enter_notify (GtkWidget *widget,
3603 GdkEventCrossing *event)
3605 GtkEntry *entry = GTK_ENTRY (widget);
3606 GtkEntryPrivate *priv = entry->priv;
3609 for (i = 0; i < MAX_ICONS; i++)
3611 EntryIconInfo *icon_info = priv->icons[i];
3613 if (icon_info != NULL && event->window == icon_info->window)
3615 if (should_prelight (entry, i))
3617 icon_info->prelight = TRUE;
3618 gtk_widget_queue_draw (widget);
3629 gtk_entry_leave_notify (GtkWidget *widget,
3630 GdkEventCrossing *event)
3632 GtkEntry *entry = GTK_ENTRY (widget);
3633 GtkEntryPrivate *priv = entry->priv;
3636 for (i = 0; i < MAX_ICONS; i++)
3638 EntryIconInfo *icon_info = priv->icons[i];
3640 if (icon_info != NULL && event->window == icon_info->window)
3642 /* a grab means that we may never see the button release */
3643 if (event->mode == GDK_CROSSING_GRAB || event->mode == GDK_CROSSING_GTK_GRAB)
3644 icon_info->pressed = FALSE;
3646 if (should_prelight (entry, i))
3648 icon_info->prelight = FALSE;
3649 gtk_widget_queue_draw (widget);
3660 gtk_entry_get_pixel_ranges (GtkEntry *entry,
3664 gint start_char, end_char;
3666 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start_char, &end_char))
3668 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
3669 PangoLayoutLine *line = pango_layout_get_lines_readonly (layout)->data;
3670 const char *text = pango_layout_get_text (layout);
3671 gint start_index = g_utf8_offset_to_pointer (text, start_char) - text;
3672 gint end_index = g_utf8_offset_to_pointer (text, end_char) - text;
3673 gint real_n_ranges, i;
3675 pango_layout_line_get_x_ranges (line, start_index, end_index, ranges, &real_n_ranges);
3681 for (i = 0; i < real_n_ranges; ++i)
3683 r[2 * i + 1] = (r[2 * i + 1] - r[2 * i]) / PANGO_SCALE;
3684 r[2 * i] = r[2 * i] / PANGO_SCALE;
3689 *n_ranges = real_n_ranges;
3701 in_selection (GtkEntry *entry,
3706 gint retval = FALSE;
3708 gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
3710 for (i = 0; i < n_ranges; ++i)
3712 if (x >= ranges[2 * i] && x < ranges[2 * i] + ranges[2 * i + 1])
3724 gtk_entry_button_press (GtkWidget *widget,
3725 GdkEventButton *event)
3727 GtkEntry *entry = GTK_ENTRY (widget);
3728 GtkEditable *editable = GTK_EDITABLE (widget);
3729 GtkEntryPrivate *priv = entry->priv;
3730 EntryIconInfo *icon_info = NULL;
3732 gint sel_start, sel_end;
3735 for (i = 0; i < MAX_ICONS; i++)
3737 icon_info = priv->icons[i];
3739 if (!icon_info || icon_info->insensitive)
3742 if (event->window == icon_info->window)
3744 if (should_prelight (entry, i))
3746 icon_info->prelight = FALSE;
3747 gtk_widget_queue_draw (widget);
3750 priv->start_x = event->x;
3751 priv->start_y = event->y;
3752 icon_info->pressed = TRUE;
3754 if (!icon_info->nonactivatable)
3755 g_signal_emit (entry, signals[ICON_PRESS], 0, i, event);
3761 if (event->window != priv->text_area ||
3762 (priv->button && event->button != priv->button))
3765 gtk_entry_reset_blink_time (entry);
3767 priv->button = event->button;
3769 if (!gtk_widget_has_focus (widget))
3771 priv->in_click = TRUE;
3772 gtk_widget_grab_focus (widget);
3773 priv->in_click = FALSE;
3776 tmp_pos = gtk_entry_find_position (entry, event->x + priv->scroll_offset);
3778 if (event->button == 1)
3780 gboolean have_selection = gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end);
3782 priv->select_words = FALSE;
3783 priv->select_lines = FALSE;
3785 if (event->state & GDK_SHIFT_MASK)
3787 _gtk_entry_reset_im_context (entry);
3789 if (!have_selection) /* select from the current position to the clicked position */
3790 sel_start = sel_end = priv->current_pos;
3792 if (tmp_pos > sel_start && tmp_pos < sel_end)
3794 /* Truncate current selection, but keep it as big as possible */
3795 if (tmp_pos - sel_start > sel_end - tmp_pos)
3796 gtk_entry_set_positions (entry, sel_start, tmp_pos);
3798 gtk_entry_set_positions (entry, tmp_pos, sel_end);
3802 gboolean extend_to_left;
3805 /* Figure out what click selects and extend current selection */
3806 switch (event->type)
3808 case GDK_BUTTON_PRESS:
3809 gtk_entry_set_positions (entry, tmp_pos, tmp_pos);
3812 case GDK_2BUTTON_PRESS:
3813 priv->select_words = TRUE;
3814 gtk_entry_select_word (entry);
3817 case GDK_3BUTTON_PRESS:
3818 priv->select_lines = TRUE;
3819 gtk_entry_select_line (entry);
3826 start = MIN (priv->current_pos, priv->selection_bound);
3827 start = MIN (sel_start, start);
3829 end = MAX (priv->current_pos, priv->selection_bound);
3830 end = MAX (sel_end, end);
3832 if (tmp_pos == sel_start || tmp_pos == sel_end)
3833 extend_to_left = (tmp_pos == start);
3835 extend_to_left = (end == sel_end);
3838 gtk_entry_set_positions (entry, start, end);
3840 gtk_entry_set_positions (entry, end, start);
3843 else /* no shift key */
3844 switch (event->type)
3846 case GDK_BUTTON_PRESS:
3847 if (in_selection (entry, event->x + priv->scroll_offset))
3849 /* Click inside the selection - we'll either start a drag, or
3850 * clear the selection
3852 priv->in_drag = TRUE;
3853 priv->drag_start_x = event->x + priv->scroll_offset;
3854 priv->drag_start_y = event->y;
3857 gtk_editable_set_position (editable, tmp_pos);
3860 case GDK_2BUTTON_PRESS:
3861 /* We ALWAYS receive a GDK_BUTTON_PRESS immediately before
3862 * receiving a GDK_2BUTTON_PRESS so we need to reset
3863 * priv->in_drag which may have been set above
3865 priv->in_drag = FALSE;
3866 priv->select_words = TRUE;
3867 gtk_entry_select_word (entry);
3870 case GDK_3BUTTON_PRESS:
3871 /* We ALWAYS receive a GDK_BUTTON_PRESS immediately before
3872 * receiving a GDK_3BUTTON_PRESS so we need to reset
3873 * priv->in_drag which may have been set above
3875 priv->in_drag = FALSE;
3876 priv->select_lines = TRUE;
3877 gtk_entry_select_line (entry);
3886 else if (event->button == 2 && event->type == GDK_BUTTON_PRESS)
3890 priv->insert_pos = tmp_pos;
3891 gtk_entry_paste (entry, GDK_SELECTION_PRIMARY);
3896 gtk_widget_error_bell (widget);
3899 else if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
3901 gtk_entry_do_popup (entry, event);
3902 priv->button = 0; /* Don't wait for release, since the menu will gtk_grab_add */
3911 gtk_entry_button_release (GtkWidget *widget,
3912 GdkEventButton *event)
3914 GtkEntry *entry = GTK_ENTRY (widget);
3915 GtkEntryPrivate *priv = entry->priv;
3916 EntryIconInfo *icon_info = NULL;
3919 for (i = 0; i < MAX_ICONS; i++)
3921 icon_info = priv->icons[i];
3923 if (!icon_info || icon_info->insensitive)
3926 if (event->window == icon_info->window)
3928 icon_info->pressed = FALSE;
3930 if (should_prelight (entry, i) &&
3931 event->x >= 0 && event->y >= 0 &&
3932 event->x < gdk_window_get_width (icon_info->window) &&
3933 event->y < gdk_window_get_height (icon_info->window))
3935 icon_info->prelight = TRUE;
3936 gtk_widget_queue_draw (widget);
3939 if (!icon_info->nonactivatable)
3940 g_signal_emit (entry, signals[ICON_RELEASE], 0, i, event);
3946 if (event->window != priv->text_area || priv->button != event->button)
3951 gint tmp_pos = gtk_entry_find_position (entry, priv->drag_start_x);
3953 gtk_editable_set_position (GTK_EDITABLE (entry), tmp_pos);
3960 gtk_entry_update_primary_selection (entry);
3966 _gtk_entry_get_selected_text (GtkEntry *entry)
3968 GtkEditable *editable = GTK_EDITABLE (entry);
3969 gint start_text, end_text;
3972 if (gtk_editable_get_selection_bounds (editable, &start_text, &end_text))
3973 text = gtk_editable_get_chars (editable, start_text, end_text);
3979 gtk_entry_motion_notify (GtkWidget *widget,
3980 GdkEventMotion *event)
3982 GtkEntry *entry = GTK_ENTRY (widget);
3983 GtkEntryPrivate *priv = entry->priv;
3984 EntryIconInfo *icon_info = NULL;
3988 for (i = 0; i < MAX_ICONS; i++)
3990 icon_info = priv->icons[i];
3992 if (!icon_info || icon_info->insensitive)
3995 if (event->window == icon_info->window)
3997 if (icon_info->pressed &&
3998 icon_info->target_list != NULL &&
3999 gtk_drag_check_threshold (widget,
4005 icon_info->in_drag = TRUE;
4006 icon_info->pressed = FALSE;
4007 gtk_drag_begin (widget,
4008 icon_info->target_list,
4018 if (priv->mouse_cursor_obscured)
4022 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
4023 gdk_window_set_cursor (priv->text_area, cursor);
4024 g_object_unref (cursor);
4025 priv->mouse_cursor_obscured = FALSE;
4028 if (event->window != priv->text_area || priv->button != 1)
4031 if (priv->select_lines)
4034 gdk_event_request_motions (event);
4038 if (gtk_entry_get_display_mode (entry) == DISPLAY_NORMAL &&
4039 gtk_drag_check_threshold (widget,
4040 priv->drag_start_x, priv->drag_start_y,
4041 event->x + priv->scroll_offset, event->y))
4043 GdkDragContext *context;
4044 GtkTargetList *target_list = gtk_target_list_new (NULL, 0);
4045 guint actions = priv->editable ? GDK_ACTION_COPY | GDK_ACTION_MOVE : GDK_ACTION_COPY;
4047 cairo_surface_t *surface;
4049 gtk_target_list_add_text_targets (target_list, 0);
4051 text = _gtk_entry_get_selected_text (entry);
4052 surface = _gtk_text_util_create_drag_icon (widget, text, -1);
4054 context = gtk_drag_begin (widget, target_list, actions,
4055 priv->button, (GdkEvent *)event);
4058 gtk_drag_set_icon_surface (context, surface);
4060 gtk_drag_set_icon_default (context);
4063 cairo_surface_destroy (surface);
4066 priv->in_drag = FALSE;
4069 gtk_target_list_unref (target_list);
4076 else if (event->y >= gdk_window_get_height (priv->text_area))
4077 tmp_pos = gtk_entry_buffer_get_length (get_buffer (entry));
4079 tmp_pos = gtk_entry_find_position (entry, event->x + priv->scroll_offset);
4081 if (priv->select_words)
4084 gint old_min, old_max;
4087 min = gtk_entry_move_backward_word (entry, tmp_pos, TRUE);
4088 max = gtk_entry_move_forward_word (entry, tmp_pos, TRUE);
4090 pos = priv->current_pos;
4091 bound = priv->selection_bound;
4093 old_min = MIN(priv->current_pos, priv->selection_bound);
4094 old_max = MAX(priv->current_pos, priv->selection_bound);
4101 else if (old_max < max)
4106 else if (pos == old_min)
4108 if (priv->current_pos != min)
4113 if (priv->current_pos != max)
4117 gtk_entry_set_positions (entry, pos, bound);
4120 gtk_entry_set_positions (entry, tmp_pos, -1);
4127 set_invisible_cursor (GdkWindow *window)
4129 GdkDisplay *display;
4132 display = gdk_window_get_display (window);
4133 cursor = gdk_cursor_new_for_display (display, GDK_BLANK_CURSOR);
4135 gdk_window_set_cursor (window, cursor);
4137 g_object_unref (cursor);
4141 gtk_entry_obscure_mouse_cursor (GtkEntry *entry)
4143 GtkEntryPrivate *priv = entry->priv;
4145 if (priv->mouse_cursor_obscured)
4148 set_invisible_cursor (priv->text_area);
4150 priv->mouse_cursor_obscured = TRUE;
4154 gtk_entry_key_press (GtkWidget *widget,
4157 GtkEntry *entry = GTK_ENTRY (widget);
4158 GtkEntryPrivate *priv = entry->priv;
4160 gtk_entry_reset_blink_time (entry);
4161 gtk_entry_pend_cursor_blink (entry);
4165 if (gtk_im_context_filter_keypress (priv->im_context, event))
4167 gtk_entry_obscure_mouse_cursor (entry);
4168 priv->need_im_reset = TRUE;
4173 if (event->keyval == GDK_KEY_Return ||
4174 event->keyval == GDK_KEY_KP_Enter ||
4175 event->keyval == GDK_KEY_ISO_Enter ||
4176 event->keyval == GDK_KEY_Escape)
4178 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
4180 if (completion && completion->priv->completion_timeout)
4182 g_source_remove (completion->priv->completion_timeout);
4183 completion->priv->completion_timeout = 0;
4186 _gtk_entry_reset_im_context (entry);
4189 if (GTK_WIDGET_CLASS (gtk_entry_parent_class)->key_press_event (widget, event))
4190 /* Activate key bindings
4194 if (!priv->editable && event->length)
4195 gtk_widget_error_bell (widget);
4201 gtk_entry_key_release (GtkWidget *widget,
4204 GtkEntry *entry = GTK_ENTRY (widget);
4205 GtkEntryPrivate *priv = entry->priv;
4209 if (gtk_im_context_filter_keypress (priv->im_context, event))
4211 priv->need_im_reset = TRUE;
4216 return GTK_WIDGET_CLASS (gtk_entry_parent_class)->key_release_event (widget, event);
4220 gtk_entry_focus_in (GtkWidget *widget,
4221 GdkEventFocus *event)
4223 GtkEntry *entry = GTK_ENTRY (widget);
4224 GtkEntryPrivate *priv = entry->priv;
4227 gtk_widget_queue_draw (widget);
4229 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (widget));
4233 priv->need_im_reset = TRUE;
4234 gtk_im_context_focus_in (priv->im_context);
4235 keymap_state_changed (keymap, entry);
4236 g_signal_connect (keymap, "state-changed",
4237 G_CALLBACK (keymap_state_changed), entry);
4240 g_signal_connect (keymap, "direction-changed",
4241 G_CALLBACK (keymap_direction_changed), entry);
4243 if (gtk_entry_buffer_get_bytes (get_buffer (entry)) == 0 &&
4244 priv->placeholder_text != NULL)
4246 gtk_entry_recompute (entry);
4250 gtk_entry_reset_blink_time (entry);
4251 gtk_entry_check_cursor_blink (entry);
4258 gtk_entry_focus_out (GtkWidget *widget,
4259 GdkEventFocus *event)
4261 GtkEntry *entry = GTK_ENTRY (widget);
4262 GtkEntryPrivate *priv = entry->priv;
4263 GtkEntryCompletion *completion;
4266 gtk_widget_queue_draw (widget);
4268 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (widget));
4272 priv->need_im_reset = TRUE;
4273 gtk_im_context_focus_out (priv->im_context);
4274 remove_capslock_feedback (entry);
4277 if (gtk_entry_buffer_get_bytes (get_buffer (entry)) == 0 &&
4278 priv->placeholder_text != NULL)
4280 gtk_entry_recompute (entry);
4284 gtk_entry_check_cursor_blink (entry);
4287 g_signal_handlers_disconnect_by_func (keymap, keymap_state_changed, entry);
4288 g_signal_handlers_disconnect_by_func (keymap, keymap_direction_changed, entry);
4290 completion = gtk_entry_get_completion (entry);
4292 _gtk_entry_completion_popdown (completion);
4298 gtk_entry_grab_focus (GtkWidget *widget)
4300 GtkEntry *entry = GTK_ENTRY (widget);
4301 GtkEntryPrivate *priv = entry->priv;
4302 gboolean select_on_focus;
4304 GTK_WIDGET_CLASS (gtk_entry_parent_class)->grab_focus (widget);
4306 if (priv->editable && !priv->in_click)
4308 g_object_get (gtk_widget_get_settings (widget),
4309 "gtk-entry-select-on-focus",
4313 if (select_on_focus)
4314 gtk_editable_select_region (GTK_EDITABLE (widget), 0, -1);
4319 gtk_entry_direction_changed (GtkWidget *widget,
4320 GtkTextDirection previous_dir)
4322 GtkEntry *entry = GTK_ENTRY (widget);
4324 gtk_entry_recompute (entry);
4326 GTK_WIDGET_CLASS (gtk_entry_parent_class)->direction_changed (widget, previous_dir);
4330 gtk_entry_state_flags_changed (GtkWidget *widget,
4331 GtkStateFlags previous_state)
4333 GtkEntry *entry = GTK_ENTRY (widget);
4334 GtkEntryPrivate *priv = entry->priv;
4337 if (gtk_widget_get_realized (widget))
4339 if (gtk_widget_is_sensitive (widget))
4340 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
4344 gdk_window_set_cursor (priv->text_area, cursor);
4347 g_object_unref (cursor);
4349 priv->mouse_cursor_obscured = FALSE;
4351 update_cursors (widget);
4354 if (!gtk_widget_is_sensitive (widget))
4356 /* Clear any selection */
4357 gtk_editable_select_region (GTK_EDITABLE (entry), priv->current_pos, priv->current_pos);
4360 gtk_widget_queue_draw (widget);
4364 gtk_entry_screen_changed (GtkWidget *widget,
4365 GdkScreen *old_screen)
4367 gtk_entry_recompute (GTK_ENTRY (widget));
4370 /* GtkEditable method implementations
4373 gtk_entry_insert_text (GtkEditable *editable,
4374 const gchar *new_text,
4375 gint new_text_length,
4378 g_object_ref (editable);
4381 * The incoming text may a password or other secret. We make sure
4382 * not to copy it into temporary buffers.
4385 g_signal_emit_by_name (editable, "insert-text", new_text, new_text_length, position);
4387 g_object_unref (editable);
4391 gtk_entry_delete_text (GtkEditable *editable,
4395 g_object_ref (editable);
4397 g_signal_emit_by_name (editable, "delete-text", start_pos, end_pos);
4399 g_object_unref (editable);
4403 gtk_entry_get_chars (GtkEditable *editable,
4407 GtkEntry *entry = GTK_ENTRY (editable);
4410 gint start_index, end_index;
4412 text = gtk_entry_buffer_get_text (get_buffer (entry));
4413 text_length = gtk_entry_buffer_get_length (get_buffer (entry));
4416 end_pos = text_length;
4418 start_pos = MIN (text_length, start_pos);
4419 end_pos = MIN (text_length, end_pos);
4421 start_index = g_utf8_offset_to_pointer (text, start_pos) - text;
4422 end_index = g_utf8_offset_to_pointer (text, end_pos) - text;
4424 return g_strndup (text + start_index, end_index - start_index);
4428 gtk_entry_real_set_position (GtkEditable *editable,
4431 GtkEntry *entry = GTK_ENTRY (editable);
4432 GtkEntryPrivate *priv = entry->priv;
4436 length = gtk_entry_buffer_get_length (get_buffer (entry));
4437 if (position < 0 || position > length)
4440 if (position != priv->current_pos ||
4441 position != priv->selection_bound)
4443 _gtk_entry_reset_im_context (entry);
4444 gtk_entry_set_positions (entry, position, position);
4449 gtk_entry_get_position (GtkEditable *editable)
4451 GtkEntry *entry = GTK_ENTRY (editable);
4452 GtkEntryPrivate *priv = entry->priv;
4454 return priv->current_pos;
4458 gtk_entry_set_selection_bounds (GtkEditable *editable,
4462 GtkEntry *entry = GTK_ENTRY (editable);
4465 length = gtk_entry_buffer_get_length (get_buffer (entry));
4471 _gtk_entry_reset_im_context (entry);
4473 gtk_entry_set_positions (entry,
4475 MIN (start, length));
4477 gtk_entry_update_primary_selection (entry);
4481 gtk_entry_get_selection_bounds (GtkEditable *editable,
4485 GtkEntry *entry = GTK_ENTRY (editable);
4486 GtkEntryPrivate *priv = entry->priv;
4488 *start = priv->selection_bound;
4489 *end = priv->current_pos;
4491 return (priv->selection_bound != priv->current_pos);
4495 icon_theme_changed (GtkEntry *entry)
4497 GtkEntryPrivate *priv = entry->priv;
4500 for (i = 0; i < MAX_ICONS; i++)
4502 EntryIconInfo *icon_info = priv->icons[i];
4503 if (icon_info != NULL)
4505 if (icon_info->storage_type == GTK_IMAGE_ICON_NAME)
4506 gtk_entry_set_icon_from_icon_name (entry, i, icon_info->icon_name);
4507 else if (icon_info->storage_type == GTK_IMAGE_STOCK)
4508 gtk_entry_set_icon_from_stock (entry, i, icon_info->stock_id);
4509 else if (icon_info->storage_type == GTK_IMAGE_GICON)
4510 gtk_entry_set_icon_from_gicon (entry, i, icon_info->gicon);
4514 gtk_widget_queue_draw (GTK_WIDGET (entry));
4518 icon_margin_changed (GtkEntry *entry)
4520 GtkEntryPrivate *priv = entry->priv;
4523 _gtk_entry_effective_inner_border (GTK_ENTRY (entry), &border);
4525 priv->icon_margin = border.left;
4529 gtk_entry_update_cached_style_values (GtkEntry *entry)
4531 GtkEntryPrivate *priv = entry->priv;
4533 gboolean interior_focus;
4535 gtk_widget_style_get (GTK_WIDGET (entry),
4536 "focus-line-width", &focus_width,
4537 "interior-focus", &interior_focus,
4539 priv->focus_width = focus_width;
4540 priv->interior_focus = interior_focus;
4542 if (!priv->invisible_char_set)
4544 gunichar ch = find_invisible_char (GTK_WIDGET (entry));
4546 if (priv->invisible_char != ch)
4548 priv->invisible_char = ch;
4549 g_object_notify (G_OBJECT (entry), "invisible-char");
4555 gtk_entry_style_updated (GtkWidget *widget)
4557 GtkEntry *entry = GTK_ENTRY (widget);
4559 GTK_WIDGET_CLASS (gtk_entry_parent_class)->style_updated (widget);
4561 gtk_entry_update_cached_style_values (entry);
4563 gtk_entry_recompute (entry);
4565 icon_theme_changed (entry);
4566 icon_margin_changed (entry);
4569 /* GtkCellEditable method implementations
4572 gtk_cell_editable_entry_activated (GtkEntry *entry, gpointer data)
4574 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4575 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4579 gtk_cell_editable_key_press_event (GtkEntry *entry,
4580 GdkEventKey *key_event,
4583 GtkEntryPrivate *priv = entry->priv;
4585 if (key_event->keyval == GDK_KEY_Escape)
4587 priv->editing_canceled = TRUE;
4588 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4589 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4594 /* override focus */
4595 if (key_event->keyval == GDK_KEY_Up || key_event->keyval == GDK_KEY_Down)
4597 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4598 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4607 gtk_entry_start_editing (GtkCellEditable *cell_editable,
4610 GtkEntry *entry = GTK_ENTRY (cell_editable);
4611 GtkEntryPrivate *priv = entry->priv;
4613 priv->is_cell_renderer = TRUE;
4615 g_signal_connect (cell_editable, "activate",
4616 G_CALLBACK (gtk_cell_editable_entry_activated), NULL);
4617 g_signal_connect (cell_editable, "key-press-event",
4618 G_CALLBACK (gtk_cell_editable_key_press_event), NULL);
4622 gtk_entry_password_hint_free (GtkEntryPasswordHint *password_hint)
4624 if (password_hint->source_id)
4625 g_source_remove (password_hint->source_id);
4627 g_slice_free (GtkEntryPasswordHint, password_hint);
4632 gtk_entry_remove_password_hint (gpointer data)
4634 GtkEntryPasswordHint *password_hint = g_object_get_qdata (data, quark_password_hint);
4635 password_hint->position = -1;
4637 /* Force the string to be redrawn, but now without a visible character */
4638 gtk_entry_recompute (GTK_ENTRY (data));
4642 /* Default signal handlers
4645 gtk_entry_real_insert_text (GtkEditable *editable,
4646 const gchar *new_text,
4647 gint new_text_length,
4653 n_chars = g_utf8_strlen (new_text, new_text_length);
4656 * The actual insertion into the buffer. This will end up firing the
4657 * following signal handlers: buffer_inserted_text(), buffer_notify_display_text(),
4658 * buffer_notify_text(), buffer_notify_length()
4660 n_inserted = gtk_entry_buffer_insert_text (get_buffer (GTK_ENTRY (editable)), *position, new_text, n_chars);
4662 if (n_inserted != n_chars)
4663 gtk_widget_error_bell (GTK_WIDGET (editable));
4665 *position += n_inserted;
4669 gtk_entry_real_delete_text (GtkEditable *editable,
4674 * The actual deletion from the buffer. This will end up firing the
4675 * following signal handlers: buffer_deleted_text(), buffer_notify_display_text(),
4676 * buffer_notify_text(), buffer_notify_length()
4679 gtk_entry_buffer_delete_text (get_buffer (GTK_ENTRY (editable)), start_pos, end_pos - start_pos);
4682 /* GtkEntryBuffer signal handlers
4685 buffer_inserted_text (GtkEntryBuffer *buffer,
4691 GtkEntryPrivate *priv = entry->priv;
4692 guint password_hint_timeout;
4694 if (priv->current_pos > position)
4695 priv->current_pos += n_chars;
4697 if (priv->selection_bound > position)
4698 priv->selection_bound += n_chars;
4700 /* Calculate the password hint if it needs to be displayed. */
4701 if (n_chars == 1 && !priv->visible)
4703 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
4704 "gtk-entry-password-hint-timeout", &password_hint_timeout,
4707 if (password_hint_timeout > 0)
4709 GtkEntryPasswordHint *password_hint = g_object_get_qdata (G_OBJECT (entry),
4710 quark_password_hint);
4713 password_hint = g_slice_new0 (GtkEntryPasswordHint);
4714 g_object_set_qdata_full (G_OBJECT (entry), quark_password_hint, password_hint,
4715 (GDestroyNotify)gtk_entry_password_hint_free);
4718 password_hint->position = position;
4719 if (password_hint->source_id)
4720 g_source_remove (password_hint->source_id);
4721 password_hint->source_id = gdk_threads_add_timeout (password_hint_timeout,
4722 (GSourceFunc)gtk_entry_remove_password_hint, entry);
4728 buffer_deleted_text (GtkEntryBuffer *buffer,
4733 GtkEntryPrivate *priv = entry->priv;
4734 guint end_pos = position + n_chars;
4735 gint selection_bound;
4738 current_pos = priv->current_pos;
4739 if (current_pos > position)
4740 current_pos -= MIN (current_pos, end_pos) - position;
4742 selection_bound = priv->selection_bound;
4743 if (selection_bound > position)
4744 selection_bound -= MIN (selection_bound, end_pos) - position;
4746 gtk_entry_set_positions (entry, current_pos, selection_bound);
4748 /* We might have deleted the selection */
4749 gtk_entry_update_primary_selection (entry);
4751 /* Disable the password hint if one exists. */
4754 GtkEntryPasswordHint *password_hint = g_object_get_qdata (G_OBJECT (entry),
4755 quark_password_hint);
4758 if (password_hint->source_id)
4759 g_source_remove (password_hint->source_id);
4760 password_hint->source_id = 0;
4761 password_hint->position = -1;
4767 buffer_notify_text (GtkEntryBuffer *buffer,
4771 gtk_entry_recompute (entry);
4772 emit_changed (entry);
4773 g_object_notify (G_OBJECT (entry), "text");
4777 buffer_notify_length (GtkEntryBuffer *buffer,
4781 g_object_notify (G_OBJECT (entry), "text-length");
4785 buffer_notify_max_length (GtkEntryBuffer *buffer,
4789 g_object_notify (G_OBJECT (entry), "max-length");
4793 buffer_connect_signals (GtkEntry *entry)
4795 g_signal_connect (get_buffer (entry), "inserted-text", G_CALLBACK (buffer_inserted_text), entry);
4796 g_signal_connect (get_buffer (entry), "deleted-text", G_CALLBACK (buffer_deleted_text), entry);
4797 g_signal_connect (get_buffer (entry), "notify::text", G_CALLBACK (buffer_notify_text), entry);
4798 g_signal_connect (get_buffer (entry), "notify::length", G_CALLBACK (buffer_notify_length), entry);
4799 g_signal_connect (get_buffer (entry), "notify::max-length", G_CALLBACK (buffer_notify_max_length), entry);
4803 buffer_disconnect_signals (GtkEntry *entry)
4805 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_inserted_text, entry);
4806 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_deleted_text, entry);
4807 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_text, entry);
4808 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_length, entry);
4809 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_max_length, entry);
4812 /* Compute the X position for an offset that corresponds to the "more important
4813 * cursor position for that offset. We use this when trying to guess to which
4814 * end of the selection we should go to when the user hits the left or
4818 get_better_cursor_x (GtkEntry *entry,
4821 GtkEntryPrivate *priv = entry->priv;
4822 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
4823 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
4824 gboolean split_cursor;
4826 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
4827 const gchar *text = pango_layout_get_text (layout);
4828 gint index = g_utf8_offset_to_pointer (text, offset) - text;
4830 PangoRectangle strong_pos, weak_pos;
4832 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
4833 "gtk-split-cursor", &split_cursor,
4836 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
4839 return strong_pos.x / PANGO_SCALE;
4841 return (keymap_direction == priv->resolved_dir) ? strong_pos.x / PANGO_SCALE : weak_pos.x / PANGO_SCALE;
4845 gtk_entry_move_cursor (GtkEntry *entry,
4846 GtkMovementStep step,
4848 gboolean extend_selection)
4850 GtkEntryPrivate *priv = entry->priv;
4851 gint new_pos = priv->current_pos;
4853 _gtk_entry_reset_im_context (entry);
4855 if (priv->current_pos != priv->selection_bound && !extend_selection)
4857 /* If we have a current selection and aren't extending it, move to the
4858 * start/or end of the selection as appropriate
4862 case GTK_MOVEMENT_VISUAL_POSITIONS:
4864 gint current_x = get_better_cursor_x (entry, priv->current_pos);
4865 gint bound_x = get_better_cursor_x (entry, priv->selection_bound);
4868 new_pos = current_x < bound_x ? priv->current_pos : priv->selection_bound;
4870 new_pos = current_x > bound_x ? priv->current_pos : priv->selection_bound;
4873 case GTK_MOVEMENT_LOGICAL_POSITIONS:
4874 case GTK_MOVEMENT_WORDS:
4876 new_pos = MIN (priv->current_pos, priv->selection_bound);
4878 new_pos = MAX (priv->current_pos, priv->selection_bound);
4880 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
4881 case GTK_MOVEMENT_PARAGRAPH_ENDS:
4882 case GTK_MOVEMENT_BUFFER_ENDS:
4883 new_pos = count < 0 ? 0 : gtk_entry_buffer_get_length (get_buffer (entry));
4885 case GTK_MOVEMENT_DISPLAY_LINES:
4886 case GTK_MOVEMENT_PARAGRAPHS:
4887 case GTK_MOVEMENT_PAGES:
4888 case GTK_MOVEMENT_HORIZONTAL_PAGES:
4896 case GTK_MOVEMENT_LOGICAL_POSITIONS:
4897 new_pos = gtk_entry_move_logically (entry, new_pos, count);
4899 case GTK_MOVEMENT_VISUAL_POSITIONS:
4900 new_pos = gtk_entry_move_visually (entry, new_pos, count);
4901 if (priv->current_pos == new_pos)
4903 if (!extend_selection)
4905 if (!gtk_widget_keynav_failed (GTK_WIDGET (entry),
4907 GTK_DIR_RIGHT : GTK_DIR_LEFT))
4909 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (entry));
4912 gtk_widget_child_focus (toplevel,
4914 GTK_DIR_RIGHT : GTK_DIR_LEFT);
4919 gtk_widget_error_bell (GTK_WIDGET (entry));
4923 case GTK_MOVEMENT_WORDS:
4926 new_pos = gtk_entry_move_forward_word (entry, new_pos, FALSE);
4931 new_pos = gtk_entry_move_backward_word (entry, new_pos, FALSE);
4934 if (priv->current_pos == new_pos)
4935 gtk_widget_error_bell (GTK_WIDGET (entry));
4937 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
4938 case GTK_MOVEMENT_PARAGRAPH_ENDS:
4939 case GTK_MOVEMENT_BUFFER_ENDS:
4940 new_pos = count < 0 ? 0 : gtk_entry_buffer_get_length (get_buffer (entry));
4941 if (priv->current_pos == new_pos)
4942 gtk_widget_error_bell (GTK_WIDGET (entry));
4944 case GTK_MOVEMENT_DISPLAY_LINES:
4945 case GTK_MOVEMENT_PARAGRAPHS:
4946 case GTK_MOVEMENT_PAGES:
4947 case GTK_MOVEMENT_HORIZONTAL_PAGES:
4952 if (extend_selection)
4953 gtk_editable_select_region (GTK_EDITABLE (entry), priv->selection_bound, new_pos);
4955 gtk_editable_set_position (GTK_EDITABLE (entry), new_pos);
4957 gtk_entry_pend_cursor_blink (entry);
4961 gtk_entry_insert_at_cursor (GtkEntry *entry,
4964 GtkEntryPrivate *priv = entry->priv;
4965 GtkEditable *editable = GTK_EDITABLE (entry);
4966 gint pos = priv->current_pos;
4970 _gtk_entry_reset_im_context (entry);
4972 gtk_editable_insert_text (editable, str, -1, &pos);
4973 gtk_editable_set_position (editable, pos);
4978 gtk_entry_delete_from_cursor (GtkEntry *entry,
4982 GtkEntryPrivate *priv = entry->priv;
4983 GtkEditable *editable = GTK_EDITABLE (entry);
4984 gint start_pos = priv->current_pos;
4985 gint end_pos = priv->current_pos;
4986 gint old_n_bytes = gtk_entry_buffer_get_bytes (get_buffer (entry));
4988 _gtk_entry_reset_im_context (entry);
4990 if (!priv->editable)
4992 gtk_widget_error_bell (GTK_WIDGET (entry));
4996 if (priv->selection_bound != priv->current_pos)
4998 gtk_editable_delete_selection (editable);
5004 case GTK_DELETE_CHARS:
5005 end_pos = gtk_entry_move_logically (entry, priv->current_pos, count);
5006 gtk_editable_delete_text (editable, MIN (start_pos, end_pos), MAX (start_pos, end_pos));
5008 case GTK_DELETE_WORDS:
5011 /* Move to end of current word, or if not on a word, end of previous word */
5012 end_pos = gtk_entry_move_backward_word (entry, end_pos, FALSE);
5013 end_pos = gtk_entry_move_forward_word (entry, end_pos, FALSE);
5017 /* Move to beginning of current word, or if not on a word, begining of next word */
5018 start_pos = gtk_entry_move_forward_word (entry, start_pos, FALSE);
5019 start_pos = gtk_entry_move_backward_word (entry, start_pos, FALSE);
5023 case GTK_DELETE_WORD_ENDS:
5026 start_pos = gtk_entry_move_backward_word (entry, start_pos, FALSE);
5031 end_pos = gtk_entry_move_forward_word (entry, end_pos, FALSE);
5034 gtk_editable_delete_text (editable, start_pos, end_pos);
5036 case GTK_DELETE_DISPLAY_LINE_ENDS:
5037 case GTK_DELETE_PARAGRAPH_ENDS:
5039 gtk_editable_delete_text (editable, 0, priv->current_pos);
5041 gtk_editable_delete_text (editable, priv->current_pos, -1);
5043 case GTK_DELETE_DISPLAY_LINES:
5044 case GTK_DELETE_PARAGRAPHS:
5045 gtk_editable_delete_text (editable, 0, -1);
5047 case GTK_DELETE_WHITESPACE:
5048 gtk_entry_delete_whitespace (entry);
5052 if (gtk_entry_buffer_get_bytes (get_buffer (entry)) == old_n_bytes)
5053 gtk_widget_error_bell (GTK_WIDGET (entry));
5055 gtk_entry_pend_cursor_blink (entry);
5059 gtk_entry_backspace (GtkEntry *entry)
5061 GtkEntryPrivate *priv = entry->priv;
5062 GtkEditable *editable = GTK_EDITABLE (entry);
5065 _gtk_entry_reset_im_context (entry);
5067 if (!priv->editable)
5069 gtk_widget_error_bell (GTK_WIDGET (entry));
5073 if (priv->selection_bound != priv->current_pos)
5075 gtk_editable_delete_selection (editable);
5079 prev_pos = gtk_entry_move_logically (entry, priv->current_pos, -1);
5081 if (prev_pos < priv->current_pos)
5083 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
5084 PangoLogAttr *log_attrs;
5087 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
5089 /* Deleting parts of characters */
5090 if (log_attrs[priv->current_pos].backspace_deletes_character)
5092 gchar *cluster_text;
5093 gchar *normalized_text;
5096 cluster_text = gtk_entry_get_display_text (entry, prev_pos,
5098 normalized_text = g_utf8_normalize (cluster_text,
5099 strlen (cluster_text),
5101 len = g_utf8_strlen (normalized_text, -1);
5103 gtk_editable_delete_text (editable, prev_pos, priv->current_pos);
5106 gint pos = priv->current_pos;
5108 gtk_editable_insert_text (editable, normalized_text,
5109 g_utf8_offset_to_pointer (normalized_text, len - 1) - normalized_text,
5111 gtk_editable_set_position (editable, pos);
5114 g_free (normalized_text);
5115 g_free (cluster_text);
5119 gtk_editable_delete_text (editable, prev_pos, priv->current_pos);
5126 gtk_widget_error_bell (GTK_WIDGET (entry));
5129 gtk_entry_pend_cursor_blink (entry);
5133 gtk_entry_copy_clipboard (GtkEntry *entry)
5135 GtkEntryPrivate *priv = entry->priv;
5136 GtkEditable *editable = GTK_EDITABLE (entry);
5140 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5144 gtk_widget_error_bell (GTK_WIDGET (entry));
5148 str = gtk_entry_get_display_text (entry, start, end);
5149 gtk_clipboard_set_text (gtk_widget_get_clipboard (GTK_WIDGET (entry),
5150 GDK_SELECTION_CLIPBOARD),
5157 gtk_entry_cut_clipboard (GtkEntry *entry)
5159 GtkEntryPrivate *priv = entry->priv;
5160 GtkEditable *editable = GTK_EDITABLE (entry);
5165 gtk_widget_error_bell (GTK_WIDGET (entry));
5169 gtk_entry_copy_clipboard (entry);
5173 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5174 gtk_editable_delete_text (editable, start, end);
5178 gtk_widget_error_bell (GTK_WIDGET (entry));
5183 gtk_entry_paste_clipboard (GtkEntry *entry)
5185 GtkEntryPrivate *priv = entry->priv;
5188 gtk_entry_paste (entry, GDK_SELECTION_CLIPBOARD);
5190 gtk_widget_error_bell (GTK_WIDGET (entry));
5194 gtk_entry_delete_cb (GtkEntry *entry)
5196 GtkEntryPrivate *priv = entry->priv;
5197 GtkEditable *editable = GTK_EDITABLE (entry);
5202 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5203 gtk_editable_delete_text (editable, start, end);
5208 gtk_entry_toggle_overwrite (GtkEntry *entry)
5210 GtkEntryPrivate *priv = entry->priv;
5212 priv->overwrite_mode = !priv->overwrite_mode;
5213 gtk_entry_pend_cursor_blink (entry);
5214 gtk_widget_queue_draw (GTK_WIDGET (entry));
5218 gtk_entry_select_all (GtkEntry *entry)
5220 gtk_entry_select_line (entry);
5224 gtk_entry_real_activate (GtkEntry *entry)
5226 GtkEntryPrivate *priv = entry->priv;
5228 GtkWidget *default_widget, *focus_widget;
5229 GtkWidget *toplevel;
5232 widget = GTK_WIDGET (entry);
5234 if (priv->activates_default)
5236 toplevel = gtk_widget_get_toplevel (widget);
5237 if (GTK_IS_WINDOW (toplevel))
5239 window = GTK_WINDOW (toplevel);
5243 default_widget = gtk_window_get_default_widget (window);
5244 focus_widget = gtk_window_get_focus (window);
5245 if (widget != default_widget &&
5246 !(widget == focus_widget && (!default_widget || !gtk_widget_get_sensitive (default_widget))))
5247 gtk_window_activate_default (window);
5254 keymap_direction_changed (GdkKeymap *keymap,
5257 gtk_entry_recompute (entry);
5260 /* IM Context Callbacks
5264 gtk_entry_commit_cb (GtkIMContext *context,
5268 GtkEntryPrivate *priv = entry->priv;
5271 gtk_entry_enter_text (entry, str);
5275 gtk_entry_preedit_changed_cb (GtkIMContext *context,
5278 GtkEntryPrivate *priv = entry->priv;
5282 gchar *preedit_string;
5285 gtk_im_context_get_preedit_string (priv->im_context,
5286 &preedit_string, NULL,
5288 g_signal_emit (entry, signals[PREEDIT_CHANGED], 0, preedit_string);
5289 priv->preedit_length = strlen (preedit_string);
5290 cursor_pos = CLAMP (cursor_pos, 0, g_utf8_strlen (preedit_string, -1));
5291 priv->preedit_cursor = cursor_pos;
5292 g_free (preedit_string);
5294 gtk_entry_recompute (entry);
5299 gtk_entry_retrieve_surrounding_cb (GtkIMContext *context,
5302 GtkEntryPrivate *priv = entry->priv;
5305 /* XXXX ??? does this even make sense when text is not visible? Should we return FALSE? */
5306 text = gtk_entry_get_display_text (entry, 0, -1);
5307 gtk_im_context_set_surrounding (context, text, strlen (text), /* Length in bytes */
5308 g_utf8_offset_to_pointer (text, priv->current_pos) - text);
5315 gtk_entry_delete_surrounding_cb (GtkIMContext *slave,
5320 GtkEntryPrivate *priv = entry->priv;
5323 gtk_editable_delete_text (GTK_EDITABLE (entry),
5324 priv->current_pos + offset,
5325 priv->current_pos + offset + n_chars);
5330 /* Internal functions
5333 /* Used for im_commit_cb and inserting Unicode chars */
5335 gtk_entry_enter_text (GtkEntry *entry,
5338 GtkEntryPrivate *priv = entry->priv;
5339 GtkEditable *editable = GTK_EDITABLE (entry);
5341 gboolean old_need_im_reset;
5343 old_need_im_reset = priv->need_im_reset;
5344 priv->need_im_reset = FALSE;
5346 if (gtk_editable_get_selection_bounds (editable, NULL, NULL))
5347 gtk_editable_delete_selection (editable);
5350 if (priv->overwrite_mode)
5351 gtk_entry_delete_from_cursor (entry, GTK_DELETE_CHARS, 1);
5354 tmp_pos = priv->current_pos;
5355 gtk_editable_insert_text (editable, str, strlen (str), &tmp_pos);
5356 gtk_editable_set_position (editable, tmp_pos);
5358 priv->need_im_reset = old_need_im_reset;
5361 /* All changes to priv->current_pos and priv->selection_bound
5362 * should go through this function.
5365 gtk_entry_set_positions (GtkEntry *entry,
5367 gint selection_bound)
5369 GtkEntryPrivate *priv = entry->priv;
5370 gboolean changed = FALSE;
5372 g_object_freeze_notify (G_OBJECT (entry));
5374 if (current_pos != -1 &&
5375 priv->current_pos != current_pos)
5377 priv->current_pos = current_pos;
5380 g_object_notify (G_OBJECT (entry), "cursor-position");
5383 if (selection_bound != -1 &&
5384 priv->selection_bound != selection_bound)
5386 priv->selection_bound = selection_bound;
5389 g_object_notify (G_OBJECT (entry), "selection-bound");
5392 g_object_thaw_notify (G_OBJECT (entry));
5396 gtk_entry_move_adjustments (entry);
5397 gtk_entry_recompute (entry);
5402 gtk_entry_reset_layout (GtkEntry *entry)
5404 GtkEntryPrivate *priv = entry->priv;
5406 if (priv->cached_layout)
5408 g_object_unref (priv->cached_layout);
5409 priv->cached_layout = NULL;
5414 update_im_cursor_location (GtkEntry *entry)
5416 GtkEntryPrivate *priv = entry->priv;
5419 gint strong_xoffset;
5420 gint area_width, area_height;
5422 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
5423 gtk_entry_get_text_area_size (entry, NULL, NULL, &area_width, &area_height);
5425 strong_xoffset = strong_x - priv->scroll_offset;
5426 if (strong_xoffset < 0)
5430 else if (strong_xoffset > area_width)
5432 strong_xoffset = area_width;
5434 area.x = strong_xoffset;
5437 area.height = area_height;
5439 gtk_im_context_set_cursor_location (priv->im_context, &area);
5443 recompute_idle_func (gpointer data)
5445 GtkEntry *entry = GTK_ENTRY (data);
5446 GtkEntryPrivate *priv = entry->priv;
5448 priv->recompute_idle = 0;
5450 if (gtk_widget_has_screen (GTK_WIDGET (entry)))
5452 gtk_entry_adjust_scroll (entry);
5453 gtk_widget_queue_draw (GTK_WIDGET (entry));
5455 update_im_cursor_location (entry);
5462 gtk_entry_recompute (GtkEntry *entry)
5464 GtkEntryPrivate *priv = entry->priv;
5466 gtk_entry_reset_layout (entry);
5467 gtk_entry_check_cursor_blink (entry);
5469 if (!priv->recompute_idle)
5471 priv->recompute_idle = gdk_threads_add_idle_full (G_PRIORITY_HIGH_IDLE + 15, /* between resize and redraw */
5472 recompute_idle_func, entry, NULL);
5477 gtk_entry_get_placeholder_text_color (GtkEntry *entry,
5480 GtkWidget *widget = GTK_WIDGET (entry);
5481 GtkStyleContext *context;
5482 GdkRGBA fg = { 0.5, 0.5, 0.5 };
5484 context = gtk_widget_get_style_context (widget);
5485 gtk_style_context_lookup_color (context, "placeholder_text_color", &fg);
5487 color->red = CLAMP (fg.red * 65535. + 0.5, 0, 65535);
5488 color->green = CLAMP (fg.green * 65535. + 0.5, 0, 65535);
5489 color->blue = CLAMP (fg.blue * 65535. + 0.5, 0, 65535);
5492 static inline gboolean
5493 show_placeholder_text (GtkEntry *entry)
5495 GtkEntryPrivate *priv = entry->priv;
5497 if (!gtk_widget_has_focus (GTK_WIDGET (entry)) &&
5498 gtk_entry_buffer_get_bytes (get_buffer (entry)) == 0 &&
5499 priv->placeholder_text != NULL)
5505 static PangoLayout *
5506 gtk_entry_create_layout (GtkEntry *entry,
5507 gboolean include_preedit)
5509 GtkEntryPrivate *priv = entry->priv;
5510 GtkWidget *widget = GTK_WIDGET (entry);
5511 PangoLayout *layout = gtk_widget_create_pango_layout (widget, NULL);
5512 PangoAttrList *tmp_attrs = pango_attr_list_new ();
5513 gboolean placeholder_layout = show_placeholder_text (entry);
5515 gchar *preedit_string = NULL;
5516 gint preedit_length = 0;
5517 PangoAttrList *preedit_attrs = NULL;
5522 pango_layout_set_single_paragraph_mode (layout, TRUE);
5524 display = placeholder_layout ? g_strdup (priv->placeholder_text) : gtk_entry_get_display_text (entry, 0, -1);
5525 n_bytes = strlen (display);
5527 if (!placeholder_layout && include_preedit)
5529 gtk_im_context_get_preedit_string (priv->im_context,
5530 &preedit_string, &preedit_attrs, NULL);
5531 preedit_length = priv->preedit_length;
5533 else if (placeholder_layout)
5536 PangoAttribute *attr;
5538 gtk_entry_get_placeholder_text_color (entry, &color);
5539 attr = pango_attr_foreground_new (color.red, color.green, color.blue);
5540 attr->start_index = 0;
5541 attr->end_index = G_MAXINT;
5542 pango_attr_list_insert (tmp_attrs, attr);
5547 GString *tmp_string = g_string_new (display);
5548 gint cursor_index = g_utf8_offset_to_pointer (display, priv->current_pos) - display;
5550 g_string_insert (tmp_string, cursor_index, preedit_string);
5552 pango_layout_set_text (layout, tmp_string->str, tmp_string->len);
5554 pango_attr_list_splice (tmp_attrs, preedit_attrs,
5555 cursor_index, preedit_length);
5557 g_string_free (tmp_string, TRUE);
5561 PangoDirection pango_dir;
5563 if (gtk_entry_get_display_mode (entry) == DISPLAY_NORMAL)
5564 pango_dir = pango_find_base_dir (display, n_bytes);
5566 pango_dir = PANGO_DIRECTION_NEUTRAL;
5568 if (pango_dir == PANGO_DIRECTION_NEUTRAL)
5570 if (gtk_widget_has_focus (widget))
5572 GdkDisplay *display = gtk_widget_get_display (widget);
5573 GdkKeymap *keymap = gdk_keymap_get_for_display (display);
5574 if (gdk_keymap_get_direction (keymap) == PANGO_DIRECTION_RTL)
5575 pango_dir = PANGO_DIRECTION_RTL;
5577 pango_dir = PANGO_DIRECTION_LTR;
5581 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
5582 pango_dir = PANGO_DIRECTION_RTL;
5584 pango_dir = PANGO_DIRECTION_LTR;
5588 pango_context_set_base_dir (gtk_widget_get_pango_context (widget),
5591 priv->resolved_dir = pango_dir;
5593 pango_layout_set_text (layout, display, n_bytes);
5596 pango_layout_set_attributes (layout, tmp_attrs);
5598 g_free (preedit_string);
5602 pango_attr_list_unref (preedit_attrs);
5604 pango_attr_list_unref (tmp_attrs);
5609 static PangoLayout *
5610 gtk_entry_ensure_layout (GtkEntry *entry,
5611 gboolean include_preedit)
5613 GtkEntryPrivate *priv = entry->priv;
5615 if (priv->preedit_length > 0 &&
5616 !include_preedit != !priv->cache_includes_preedit)
5617 gtk_entry_reset_layout (entry);
5619 if (!priv->cached_layout)
5621 priv->cached_layout = gtk_entry_create_layout (entry, include_preedit);
5622 priv->cache_includes_preedit = include_preedit;
5625 return priv->cached_layout;
5629 get_layout_position (GtkEntry *entry,
5633 GtkEntryPrivate *priv = entry->priv;
5634 PangoLayout *layout;
5635 PangoRectangle logical_rect;
5636 gint area_width, area_height;
5637 GtkBorder inner_border;
5639 PangoLayoutLine *line;
5641 layout = gtk_entry_ensure_layout (entry, TRUE);
5643 gtk_entry_get_text_area_size (entry, NULL, NULL, &area_width, &area_height);
5644 _gtk_entry_effective_inner_border (entry, &inner_border);
5646 area_height = PANGO_SCALE * (area_height - inner_border.top - inner_border.bottom);
5648 line = pango_layout_get_lines_readonly (layout)->data;
5649 pango_layout_line_get_extents (line, NULL, &logical_rect);
5651 /* Align primarily for locale's ascent/descent */
5652 y_pos = ((area_height - priv->ascent - priv->descent) / 2 +
5653 priv->ascent + logical_rect.y);
5655 /* Now see if we need to adjust to fit in actual drawn string */
5656 if (logical_rect.height > area_height)
5657 y_pos = (area_height - logical_rect.height) / 2;
5660 else if (y_pos + logical_rect.height > area_height)
5661 y_pos = area_height - logical_rect.height;
5663 y_pos = inner_border.top + y_pos / PANGO_SCALE;
5666 *x = inner_border.left - priv->scroll_offset;
5673 draw_text_with_color (GtkEntry *entry,
5675 GdkRGBA *default_color)
5677 GtkEntryPrivate *priv = entry->priv;
5678 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
5681 gint start_pos, end_pos;
5683 widget = GTK_WIDGET (entry);
5687 get_layout_position (entry, &x, &y);
5689 cairo_move_to (cr, x, y);
5690 gdk_cairo_set_source_rgba (cr, default_color);
5691 pango_cairo_show_layout (cr, layout);
5693 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start_pos, &end_pos))
5697 PangoRectangle logical_rect;
5698 GdkRGBA selection_color, text_color;
5699 GtkBorder inner_border;
5700 GtkStyleContext *context;
5701 GtkStateFlags state;
5703 context = gtk_widget_get_style_context (widget);
5704 pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
5705 gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
5707 state = GTK_STATE_FLAG_SELECTED;
5709 if (gtk_widget_has_focus (widget))
5710 state |= GTK_STATE_FLAG_FOCUSED;
5712 gtk_style_context_get_background_color (context, state, &selection_color);
5713 gtk_style_context_get_color (context, state, &text_color);
5715 _gtk_entry_effective_inner_border (entry, &inner_border);
5717 for (i = 0; i < n_ranges; ++i)
5718 cairo_rectangle (cr,
5719 inner_border.left - priv->scroll_offset + ranges[2 * i],
5722 logical_rect.height);
5726 gdk_cairo_set_source_rgba (cr, &selection_color);
5729 cairo_move_to (cr, x, y);
5730 gdk_cairo_set_source_rgba (cr, &text_color);
5731 pango_cairo_show_layout (cr, layout);
5739 gtk_entry_draw_text (GtkEntry *entry,
5742 GtkEntryPrivate *priv = entry->priv;
5743 GtkWidget *widget = GTK_WIDGET (entry);
5744 GtkStateFlags state = 0;
5745 GdkRGBA text_color, bar_text_color;
5746 GtkStyleContext *context;
5749 gint progress_x, progress_y, progress_width, progress_height;
5750 gint clip_width, clip_height;
5752 /* Nothing to display at all */
5753 if (gtk_entry_get_display_mode (entry) == DISPLAY_BLANK)
5756 state = gtk_widget_get_state_flags (widget);
5757 context = gtk_widget_get_style_context (widget);
5759 gtk_style_context_get_color (context, state, &text_color);
5761 /* Get foreground color for progressbars */
5762 gtk_style_context_save (context);
5763 gtk_style_context_add_class (context, GTK_STYLE_CLASS_PROGRESSBAR);
5764 gtk_style_context_get_color (context, state, &bar_text_color);
5765 gtk_style_context_restore (context);
5767 get_progress_area (widget,
5768 &progress_x, &progress_y,
5769 &progress_width, &progress_height);
5773 clip_width = gdk_window_get_width (priv->text_area);
5774 clip_height = gdk_window_get_height (priv->text_area);
5775 cairo_rectangle (cr, 0, 0, clip_width, clip_height);
5778 /* If the color is the same, or the progress area has a zero
5779 * size, then we only need to draw once. */
5780 if (gdk_rgba_equal (&text_color, &bar_text_color) ||
5781 ((progress_width == 0) || (progress_height == 0)))
5783 draw_text_with_color (entry, cr, &text_color);
5787 width = gdk_window_get_width (priv->text_area);
5788 height = gdk_window_get_height (priv->text_area);
5792 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
5793 cairo_rectangle (cr, 0, 0, width, height);
5795 gdk_window_get_position (priv->text_area, &pos_x, &pos_y);
5796 progress_x -= pos_x;
5797 progress_y -= pos_y;
5799 cairo_rectangle (cr, progress_x, progress_y,
5800 progress_width, progress_height);
5802 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_WINDING);
5804 draw_text_with_color (entry, cr, &text_color);
5809 cairo_rectangle (cr, progress_x, progress_y,
5810 progress_width, progress_height);
5813 draw_text_with_color (entry, cr, &bar_text_color);
5822 draw_insertion_cursor (GtkEntry *entry,
5824 GdkRectangle *cursor_location,
5825 gboolean is_primary,
5826 PangoDirection direction,
5827 gboolean draw_arrow)
5829 GtkWidget *widget = GTK_WIDGET (entry);
5830 GtkTextDirection text_dir;
5832 if (direction == PANGO_DIRECTION_LTR)
5833 text_dir = GTK_TEXT_DIR_LTR;
5835 text_dir = GTK_TEXT_DIR_RTL;
5837 gtk_draw_insertion_cursor (widget, cr,
5839 is_primary, text_dir, draw_arrow);
5843 gtk_entry_draw_cursor (GtkEntry *entry,
5847 GtkEntryPrivate *priv = entry->priv;
5848 GtkWidget *widget = GTK_WIDGET (entry);
5849 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
5850 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
5851 GdkRectangle cursor_location;
5852 gboolean split_cursor;
5853 PangoRectangle cursor_rect;
5854 GtkBorder inner_border;
5856 gint text_area_height;
5859 gboolean block_at_line_end;
5860 PangoLayout *layout;
5863 _gtk_entry_effective_inner_border (entry, &inner_border);
5865 xoffset = inner_border.left - priv->scroll_offset;
5867 text_area_height = gdk_window_get_height (priv->text_area);
5869 layout = gtk_entry_ensure_layout (entry, TRUE);
5870 text = pango_layout_get_text (layout);
5871 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos + priv->preedit_cursor) - text;
5872 if (!priv->overwrite_mode)
5875 block = _gtk_text_util_get_block_cursor_location (layout,
5876 cursor_index, &cursor_rect, &block_at_line_end);
5880 gint strong_x, weak_x;
5881 PangoDirection dir1 = PANGO_DIRECTION_NEUTRAL;
5882 PangoDirection dir2 = PANGO_DIRECTION_NEUTRAL;
5886 gtk_entry_get_cursor_locations (entry, type, &strong_x, &weak_x);
5888 g_object_get (gtk_widget_get_settings (widget),
5889 "gtk-split-cursor", &split_cursor,
5892 dir1 = priv->resolved_dir;
5898 if (weak_x != strong_x)
5900 dir2 = (priv->resolved_dir == PANGO_DIRECTION_LTR) ? PANGO_DIRECTION_RTL : PANGO_DIRECTION_LTR;
5906 if (keymap_direction == priv->resolved_dir)
5912 cursor_location.x = xoffset + x1;
5913 cursor_location.y = inner_border.top;
5914 cursor_location.width = 0;
5915 cursor_location.height = text_area_height - inner_border.top - inner_border.bottom;
5917 draw_insertion_cursor (entry, cr,
5918 &cursor_location, TRUE, dir1,
5919 dir2 != PANGO_DIRECTION_NEUTRAL);
5921 if (dir2 != PANGO_DIRECTION_NEUTRAL)
5923 cursor_location.x = xoffset + x2;
5924 draw_insertion_cursor (entry, cr,
5925 &cursor_location, FALSE, dir2,
5929 else /* overwrite_mode */
5931 GtkStyleContext *context;
5932 GdkRGBA cursor_color;
5938 get_layout_position (entry, &x, &y);
5940 rect.x = PANGO_PIXELS (cursor_rect.x) + x;
5941 rect.y = PANGO_PIXELS (cursor_rect.y) + y;
5942 rect.width = PANGO_PIXELS (cursor_rect.width);
5943 rect.height = PANGO_PIXELS (cursor_rect.height);
5945 context = gtk_widget_get_style_context (widget);
5947 _gtk_style_context_get_cursor_color (context, &cursor_color, NULL);
5948 gdk_cairo_set_source_rgba (cr, &cursor_color);
5949 gdk_cairo_rectangle (cr, &rect);
5952 if (!block_at_line_end)
5954 GtkStateFlags state;
5957 state = gtk_widget_get_state_flags (widget);
5958 gtk_style_context_get_background_color (context, state, &color);
5960 gdk_cairo_rectangle (cr, &rect);
5962 cairo_move_to (cr, x, y);
5963 gdk_cairo_set_source_rgba (cr, &color);
5964 pango_cairo_show_layout (cr, layout);
5972 _gtk_entry_reset_im_context (GtkEntry *entry)
5974 GtkEntryPrivate *priv = entry->priv;
5976 if (priv->need_im_reset)
5978 priv->need_im_reset = FALSE;
5979 gtk_im_context_reset (priv->im_context);
5984 * gtk_entry_reset_im_context:
5985 * @entry: a #GtkEntry
5987 * Reset the input method context of the entry if needed.
5989 * This can be necessary in the case where modifying the buffer
5990 * would confuse on-going input method behavior.
5995 gtk_entry_reset_im_context (GtkEntry *entry)
5997 g_return_if_fail (GTK_IS_ENTRY (entry));
5999 _gtk_entry_reset_im_context (entry);
6003 * gtk_entry_im_context_filter_keypress:
6004 * @entry: a #GtkEntry
6005 * @event: (type Gdk.EventKey): the key event
6007 * Allow the #GtkEntry input method to internally handle key press
6008 * and release events. If this function returns %TRUE, then no further
6009 * processing should be done for this key event. See
6010 * gtk_im_context_filter_keypress().
6012 * Note that you are expected to call this function from your handler
6013 * when overriding key event handling. This is needed in the case when
6014 * you need to insert your own key handling between the input method
6015 * and the default key event handling of the #GtkEntry.
6016 * See gtk_text_view_reset_im_context() for an example of use.
6018 * Return value: %TRUE if the input method handled the key event.
6023 gtk_entry_im_context_filter_keypress (GtkEntry *entry,
6026 GtkEntryPrivate *priv;
6028 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
6032 return gtk_im_context_filter_keypress (priv->im_context, event);
6036 _gtk_entry_get_im_context (GtkEntry *entry)
6038 return entry->priv->im_context;
6042 gtk_entry_find_position (GtkEntry *entry,
6045 GtkEntryPrivate *priv = entry->priv;
6046 PangoLayout *layout;
6047 PangoLayoutLine *line;
6054 layout = gtk_entry_ensure_layout (entry, TRUE);
6055 text = pango_layout_get_text (layout);
6056 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos) - text;
6058 line = pango_layout_get_lines_readonly (layout)->data;
6059 pango_layout_line_x_to_index (line, x * PANGO_SCALE, &index, &trailing);
6061 if (index >= cursor_index && priv->preedit_length)
6063 if (index >= cursor_index + priv->preedit_length)
6064 index -= priv->preedit_length;
6067 index = cursor_index;
6072 pos = g_utf8_pointer_to_offset (text, text + index);
6079 gtk_entry_get_cursor_locations (GtkEntry *entry,
6084 GtkEntryPrivate *priv = entry->priv;
6085 DisplayMode mode = gtk_entry_get_display_mode (entry);
6087 /* Nothing to display at all, so no cursor is relevant */
6088 if (mode == DISPLAY_BLANK)
6098 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
6099 const gchar *text = pango_layout_get_text (layout);
6100 PangoRectangle strong_pos, weak_pos;
6103 if (type == CURSOR_STANDARD)
6105 index = g_utf8_offset_to_pointer (text, priv->current_pos + priv->preedit_cursor) - text;
6107 else /* type == CURSOR_DND */
6109 index = g_utf8_offset_to_pointer (text, priv->dnd_position) - text;
6111 if (priv->dnd_position > priv->current_pos)
6113 if (mode == DISPLAY_NORMAL)
6114 index += priv->preedit_length;
6117 gint preedit_len_chars = g_utf8_strlen (text, -1) - gtk_entry_buffer_get_length (get_buffer (entry));
6118 index += preedit_len_chars * g_unichar_to_utf8 (priv->invisible_char, NULL);
6123 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
6126 *strong_x = strong_pos.x / PANGO_SCALE;
6129 *weak_x = weak_pos.x / PANGO_SCALE;
6134 gtk_entry_adjust_scroll (GtkEntry *entry)
6136 GtkEntryPrivate *priv = entry->priv;
6137 gint min_offset, max_offset;
6138 gint text_area_width, text_width;
6139 GtkBorder inner_border;
6140 gint strong_x, weak_x;
6141 gint strong_xoffset, weak_xoffset;
6143 PangoLayout *layout;
6144 PangoLayoutLine *line;
6145 PangoRectangle logical_rect;
6147 if (!gtk_widget_get_realized (GTK_WIDGET (entry)))
6150 _gtk_entry_effective_inner_border (entry, &inner_border);
6152 text_area_width = gdk_window_get_width (priv->text_area);
6153 text_area_width -= inner_border.left + inner_border.right;
6154 if (text_area_width < 0)
6155 text_area_width = 0;
6157 layout = gtk_entry_ensure_layout (entry, TRUE);
6158 line = pango_layout_get_lines_readonly (layout)->data;
6160 pango_layout_line_get_extents (line, NULL, &logical_rect);
6162 /* Display as much text as we can */
6164 if (priv->resolved_dir == PANGO_DIRECTION_LTR)
6165 xalign = priv->xalign;
6167 xalign = 1.0 - priv->xalign;
6169 text_width = PANGO_PIXELS(logical_rect.width);
6171 if (text_width > text_area_width)
6174 max_offset = text_width - text_area_width;
6178 min_offset = (text_width - text_area_width) * xalign;
6179 max_offset = min_offset;
6182 priv->scroll_offset = CLAMP (priv->scroll_offset, min_offset, max_offset);
6184 /* And make sure cursors are on screen. Note that the cursor is
6185 * actually drawn one pixel into the INNER_BORDER space on
6186 * the right, when the scroll is at the utmost right. This
6187 * looks better to to me than confining the cursor inside the
6188 * border entirely, though it means that the cursor gets one
6189 * pixel closer to the edge of the widget on the right than
6190 * on the left. This might need changing if one changed
6191 * INNER_BORDER from 2 to 1, as one would do on a
6192 * small-screen-real-estate display.
6194 * We always make sure that the strong cursor is on screen, and
6195 * put the weak cursor on screen if possible.
6198 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, &weak_x);
6200 strong_xoffset = strong_x - priv->scroll_offset;
6202 if (strong_xoffset < 0)
6204 priv->scroll_offset += strong_xoffset;
6207 else if (strong_xoffset > text_area_width)
6209 priv->scroll_offset += strong_xoffset - text_area_width;
6210 strong_xoffset = text_area_width;
6213 weak_xoffset = weak_x - priv->scroll_offset;
6215 if (weak_xoffset < 0 && strong_xoffset - weak_xoffset <= text_area_width)
6217 priv->scroll_offset += weak_xoffset;
6219 else if (weak_xoffset > text_area_width &&
6220 strong_xoffset - (weak_xoffset - text_area_width) >= 0)
6222 priv->scroll_offset += weak_xoffset - text_area_width;
6225 g_object_notify (G_OBJECT (entry), "scroll-offset");
6229 gtk_entry_move_adjustments (GtkEntry *entry)
6231 GtkWidget *widget = GTK_WIDGET (entry);
6232 GtkAllocation allocation;
6233 GtkAdjustment *adjustment;
6234 PangoContext *context;
6235 PangoFontMetrics *metrics;
6236 GtkStyleContext *style_context;
6237 GtkStateFlags state;
6238 gint x, layout_x, border_x, border_y;
6241 adjustment = g_object_get_qdata (G_OBJECT (entry), quark_cursor_hadjustment);
6245 gtk_widget_get_allocation (widget, &allocation);
6247 /* Cursor position, layout offset, border width, and widget allocation */
6248 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &x, NULL);
6249 get_layout_position (entry, &layout_x, NULL);
6250 _gtk_entry_get_borders (entry, &border_x, &border_y);
6251 x += allocation.x + layout_x + border_x;
6253 /* Approximate width of a char, so user can see what is ahead/behind */
6254 context = gtk_widget_get_pango_context (widget);
6255 style_context = gtk_widget_get_style_context (widget);
6256 state = gtk_widget_get_state_flags (widget);
6258 metrics = pango_context_get_metrics (context,
6259 gtk_style_context_get_font (style_context, state),
6260 pango_context_get_language (context));
6261 char_width = pango_font_metrics_get_approximate_char_width (metrics) / PANGO_SCALE;
6264 gtk_adjustment_clamp_page (adjustment,
6265 x - (char_width + 1), /* one char + one pixel before */
6266 x + (char_width + 2)); /* one char + cursor + one pixel after */
6270 gtk_entry_move_visually (GtkEntry *entry,
6274 GtkEntryPrivate *priv = entry->priv;
6276 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6279 text = pango_layout_get_text (layout);
6281 index = g_utf8_offset_to_pointer (text, start) - text;
6285 int new_index, new_trailing;
6286 gboolean split_cursor;
6289 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
6290 "gtk-split-cursor", &split_cursor,
6297 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
6298 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
6300 strong = keymap_direction == priv->resolved_dir;
6305 pango_layout_move_cursor_visually (layout, strong, index, 0, 1, &new_index, &new_trailing);
6310 pango_layout_move_cursor_visually (layout, strong, index, 0, -1, &new_index, &new_trailing);
6316 else if (new_index != G_MAXINT)
6319 while (new_trailing--)
6320 index = g_utf8_next_char (text + index) - text;
6323 return g_utf8_pointer_to_offset (text, text + index);
6327 gtk_entry_move_logically (GtkEntry *entry,
6331 gint new_pos = start;
6334 length = gtk_entry_buffer_get_length (get_buffer (entry));
6336 /* Prevent any leak of information */
6337 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6339 new_pos = CLAMP (start + count, 0, length);
6343 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6344 PangoLogAttr *log_attrs;
6347 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6349 while (count > 0 && new_pos < length)
6353 while (new_pos < length && !log_attrs[new_pos].is_cursor_position);
6357 while (count < 0 && new_pos > 0)
6361 while (new_pos > 0 && !log_attrs[new_pos].is_cursor_position);
6373 gtk_entry_move_forward_word (GtkEntry *entry,
6375 gboolean allow_whitespace)
6377 gint new_pos = start;
6380 length = gtk_entry_buffer_get_length (get_buffer (entry));
6382 /* Prevent any leak of information */
6383 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6387 else if (new_pos < length)
6389 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6390 PangoLogAttr *log_attrs;
6393 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6395 /* Find the next word boundary */
6397 while (new_pos < n_attrs - 1 && !(log_attrs[new_pos].is_word_end ||
6398 (log_attrs[new_pos].is_word_start && allow_whitespace)))
6409 gtk_entry_move_backward_word (GtkEntry *entry,
6411 gboolean allow_whitespace)
6413 gint new_pos = start;
6415 /* Prevent any leak of information */
6416 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6422 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6423 PangoLogAttr *log_attrs;
6426 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6428 new_pos = start - 1;
6430 /* Find the previous word boundary */
6431 while (new_pos > 0 && !(log_attrs[new_pos].is_word_start ||
6432 (log_attrs[new_pos].is_word_end && allow_whitespace)))
6442 gtk_entry_delete_whitespace (GtkEntry *entry)
6444 GtkEntryPrivate *priv = entry->priv;
6445 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6446 PangoLogAttr *log_attrs;
6450 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6452 start = end = priv->current_pos;
6454 while (start > 0 && log_attrs[start-1].is_white)
6457 while (end < n_attrs && log_attrs[end].is_white)
6463 gtk_editable_delete_text (GTK_EDITABLE (entry), start, end);
6468 gtk_entry_select_word (GtkEntry *entry)
6470 GtkEntryPrivate *priv = entry->priv;
6471 gint start_pos = gtk_entry_move_backward_word (entry, priv->current_pos, TRUE);
6472 gint end_pos = gtk_entry_move_forward_word (entry, priv->current_pos, TRUE);
6474 gtk_editable_select_region (GTK_EDITABLE (entry), start_pos, end_pos);
6478 gtk_entry_select_line (GtkEntry *entry)
6480 gtk_editable_select_region (GTK_EDITABLE (entry), 0, -1);
6484 truncate_multiline (const gchar *text)
6489 text[length] && text[length] != '\n' && text[length] != '\r';
6496 paste_received (GtkClipboard *clipboard,
6500 GtkEntry *entry = GTK_ENTRY (data);
6501 GtkEditable *editable = GTK_EDITABLE (entry);
6502 GtkEntryPrivate *priv = entry->priv;
6504 if (priv->button == 2)
6506 gint pos, start, end;
6507 pos = priv->insert_pos;
6508 gtk_editable_get_selection_bounds (editable, &start, &end);
6509 if (!((start <= pos && pos <= end) || (end <= pos && pos <= start)))
6510 gtk_editable_select_region (editable, pos, pos);
6515 gint pos, start, end;
6517 gboolean popup_completion;
6518 GtkEntryCompletion *completion;
6520 completion = gtk_entry_get_completion (entry);
6522 if (priv->truncate_multiline)
6523 length = truncate_multiline (text);
6525 /* only complete if the selection is at the end */
6526 popup_completion = (gtk_entry_buffer_get_length (get_buffer (entry)) ==
6527 MAX (priv->current_pos, priv->selection_bound));
6531 if (gtk_widget_get_mapped (completion->priv->popup_window))
6532 _gtk_entry_completion_popdown (completion);
6534 if (!popup_completion && completion->priv->changed_id > 0)
6535 g_signal_handler_block (entry, completion->priv->changed_id);
6538 begin_change (entry);
6539 g_object_freeze_notify (G_OBJECT (entry));
6540 if (gtk_editable_get_selection_bounds (editable, &start, &end))
6541 gtk_editable_delete_text (editable, start, end);
6543 pos = priv->current_pos;
6544 gtk_editable_insert_text (editable, text, length, &pos);
6545 gtk_editable_set_position (editable, pos);
6546 g_object_thaw_notify (G_OBJECT (entry));
6550 !popup_completion && completion->priv->changed_id > 0)
6551 g_signal_handler_unblock (entry, completion->priv->changed_id);
6554 g_object_unref (entry);
6558 gtk_entry_paste (GtkEntry *entry,
6561 g_object_ref (entry);
6562 gtk_clipboard_request_text (gtk_widget_get_clipboard (GTK_WIDGET (entry), selection),
6563 paste_received, entry);
6567 primary_get_cb (GtkClipboard *clipboard,
6568 GtkSelectionData *selection_data,
6572 GtkEntry *entry = GTK_ENTRY (data);
6575 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end))
6577 gchar *str = gtk_entry_get_display_text (entry, start, end);
6578 gtk_selection_data_set_text (selection_data, str, -1);
6584 primary_clear_cb (GtkClipboard *clipboard,
6587 GtkEntry *entry = GTK_ENTRY (data);
6588 GtkEntryPrivate *priv = entry->priv;
6590 gtk_editable_select_region (GTK_EDITABLE (entry), priv->current_pos, priv->current_pos);
6594 gtk_entry_update_primary_selection (GtkEntry *entry)
6596 GtkTargetList *list;
6597 GtkTargetEntry *targets;
6598 GtkClipboard *clipboard;
6602 if (!gtk_widget_get_realized (GTK_WIDGET (entry)))
6605 list = gtk_target_list_new (NULL, 0);
6606 gtk_target_list_add_text_targets (list, 0);
6608 targets = gtk_target_table_new_from_list (list, &n_targets);
6610 clipboard = gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_PRIMARY);
6612 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end))
6614 if (!gtk_clipboard_set_with_owner (clipboard, targets, n_targets,
6615 primary_get_cb, primary_clear_cb, G_OBJECT (entry)))
6616 primary_clear_cb (clipboard, entry);
6620 if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (entry))
6621 gtk_clipboard_clear (clipboard);
6624 gtk_target_table_free (targets, n_targets);
6625 gtk_target_list_unref (list);
6629 gtk_entry_clear (GtkEntry *entry,
6630 GtkEntryIconPosition icon_pos)
6632 GtkEntryPrivate *priv = entry->priv;
6633 EntryIconInfo *icon_info = priv->icons[icon_pos];
6635 if (!icon_info || icon_info->storage_type == GTK_IMAGE_EMPTY)
6638 g_object_freeze_notify (G_OBJECT (entry));
6640 /* Explicitly check, as the pointer may become invalidated
6641 * during destruction.
6643 if (GDK_IS_WINDOW (icon_info->window))
6644 gdk_window_hide (icon_info->window);
6646 if (icon_info->pixbuf)
6648 g_object_unref (icon_info->pixbuf);
6649 icon_info->pixbuf = NULL;
6652 switch (icon_info->storage_type)
6654 case GTK_IMAGE_PIXBUF:
6655 g_object_notify (G_OBJECT (entry),
6656 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-pixbuf" : "secondary-icon-pixbuf");
6659 case GTK_IMAGE_STOCK:
6660 g_free (icon_info->stock_id);
6661 icon_info->stock_id = NULL;
6662 g_object_notify (G_OBJECT (entry),
6663 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-stock" : "secondary-icon-stock");
6666 case GTK_IMAGE_ICON_NAME:
6667 g_free (icon_info->icon_name);
6668 icon_info->icon_name = NULL;
6669 g_object_notify (G_OBJECT (entry),
6670 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-name" : "secondary-icon-name");
6673 case GTK_IMAGE_GICON:
6674 if (icon_info->gicon)
6676 g_object_unref (icon_info->gicon);
6677 icon_info->gicon = NULL;
6679 g_object_notify (G_OBJECT (entry),
6680 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-gicon" : "secondary-icon-gicon");
6684 g_assert_not_reached ();
6688 icon_info->storage_type = GTK_IMAGE_EMPTY;
6689 g_object_notify (G_OBJECT (entry),
6690 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-storage-type" : "secondary-icon-storage-type");
6692 g_object_thaw_notify (G_OBJECT (entry));
6696 create_normal_pixbuf (GtkStyleContext *context,
6697 const gchar *stock_id,
6698 GtkIconSize icon_size)
6700 GtkIconSet *icon_set;
6703 gtk_style_context_save (context);
6705 /* Unset any state */
6706 gtk_style_context_set_state (context, 0);
6708 icon_set = gtk_style_context_lookup_icon_set (context, stock_id);
6709 pixbuf = gtk_icon_set_render_icon_pixbuf (icon_set, context, icon_size);
6711 gtk_style_context_restore (context);
6717 gtk_entry_ensure_pixbuf (GtkEntry *entry,
6718 GtkEntryIconPosition icon_pos)
6720 GtkEntryPrivate *priv = entry->priv;
6721 EntryIconInfo *icon_info = priv->icons[icon_pos];
6722 GtkStyleContext *context;
6724 GtkIconTheme *icon_theme;
6725 GtkSettings *settings;
6730 if (!icon_info || icon_info->pixbuf)
6733 widget = GTK_WIDGET (entry);
6734 context = gtk_widget_get_style_context (widget);
6736 switch (icon_info->storage_type)
6738 case GTK_IMAGE_EMPTY:
6739 case GTK_IMAGE_PIXBUF:
6741 case GTK_IMAGE_STOCK:
6742 icon_info->pixbuf = create_normal_pixbuf (context, icon_info->stock_id,
6743 GTK_ICON_SIZE_MENU);
6745 if (!icon_info->pixbuf)
6746 icon_info->pixbuf = create_normal_pixbuf (context,
6747 GTK_STOCK_MISSING_IMAGE,
6748 GTK_ICON_SIZE_MENU);
6751 case GTK_IMAGE_ICON_NAME:
6752 screen = gtk_widget_get_screen (widget);
6755 icon_theme = gtk_icon_theme_get_for_screen (screen);
6756 settings = gtk_settings_get_for_screen (screen);
6758 gtk_icon_size_lookup_for_settings (settings,
6762 icon_info->pixbuf = gtk_icon_theme_load_icon (icon_theme,
6763 icon_info->icon_name,
6764 MIN (width, height),
6767 if (icon_info->pixbuf == NULL)
6768 icon_info->pixbuf = create_normal_pixbuf (context,
6769 GTK_STOCK_MISSING_IMAGE,
6770 GTK_ICON_SIZE_MENU);
6774 case GTK_IMAGE_GICON:
6775 screen = gtk_widget_get_screen (widget);
6778 icon_theme = gtk_icon_theme_get_for_screen (screen);
6779 settings = gtk_settings_get_for_screen (screen);
6781 gtk_icon_size_lookup_for_settings (settings,
6785 info = gtk_icon_theme_lookup_by_gicon (icon_theme,
6787 MIN (width, height),
6788 GTK_ICON_LOOKUP_USE_BUILTIN);
6791 icon_info->pixbuf = gtk_icon_info_load_icon (info, NULL);
6792 gtk_icon_info_free (info);
6795 if (icon_info->pixbuf == NULL)
6796 icon_info->pixbuf = create_normal_pixbuf (context,
6797 GTK_STOCK_MISSING_IMAGE,
6798 GTK_ICON_SIZE_MENU);
6803 g_assert_not_reached ();
6807 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
6808 gdk_window_show_unraised (icon_info->window);
6818 * Creates a new entry.
6820 * Return value: a new #GtkEntry.
6823 gtk_entry_new (void)
6825 return g_object_new (GTK_TYPE_ENTRY, NULL);
6829 * gtk_entry_new_with_buffer:
6830 * @buffer: The buffer to use for the new #GtkEntry.
6832 * Creates a new entry with the specified text buffer.
6834 * Return value: a new #GtkEntry
6839 gtk_entry_new_with_buffer (GtkEntryBuffer *buffer)
6841 g_return_val_if_fail (GTK_IS_ENTRY_BUFFER (buffer), NULL);
6842 return g_object_new (GTK_TYPE_ENTRY, "buffer", buffer, NULL);
6845 static GtkEntryBuffer*
6846 get_buffer (GtkEntry *entry)
6848 GtkEntryPrivate *priv = entry->priv;
6850 if (priv->buffer == NULL)
6852 GtkEntryBuffer *buffer;
6853 buffer = gtk_entry_buffer_new (NULL, 0);
6854 gtk_entry_set_buffer (entry, buffer);
6855 g_object_unref (buffer);
6858 return priv->buffer;
6862 * gtk_entry_get_buffer:
6863 * @entry: a #GtkEntry
6865 * Get the #GtkEntryBuffer object which holds the text for
6870 * Returns: (transfer none): A #GtkEntryBuffer object.
6873 gtk_entry_get_buffer (GtkEntry *entry)
6875 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
6877 return get_buffer (entry);
6881 * gtk_entry_set_buffer:
6882 * @entry: a #GtkEntry
6883 * @buffer: a #GtkEntryBuffer
6885 * Set the #GtkEntryBuffer object which holds the text for
6891 gtk_entry_set_buffer (GtkEntry *entry,
6892 GtkEntryBuffer *buffer)
6894 GtkEntryPrivate *priv;
6897 g_return_if_fail (GTK_IS_ENTRY (entry));
6903 g_return_if_fail (GTK_IS_ENTRY_BUFFER (buffer));
6904 g_object_ref (buffer);
6909 buffer_disconnect_signals (entry);
6910 g_object_unref (priv->buffer);
6913 priv->buffer = buffer;
6916 buffer_connect_signals (entry);
6918 obj = G_OBJECT (entry);
6919 g_object_freeze_notify (obj);
6920 g_object_notify (obj, "buffer");
6921 g_object_notify (obj, "text");
6922 g_object_notify (obj, "text-length");
6923 g_object_notify (obj, "max-length");
6924 g_object_notify (obj, "visibility");
6925 g_object_notify (obj, "invisible-char");
6926 g_object_notify (obj, "invisible-char-set");
6927 g_object_thaw_notify (obj);
6929 gtk_editable_set_position (GTK_EDITABLE (entry), 0);
6930 gtk_entry_recompute (entry);
6934 * gtk_entry_get_text_area:
6935 * @entry: a #GtkEntry
6936 * @text_area: (out): Return location for the text area.
6938 * Gets the area where the entry's text is drawn. This function is
6939 * useful when drawing something to the entry in a draw callback.
6941 * If the entry is not realized, @text_area is filled with zeros.
6943 * See also gtk_entry_get_icon_area().
6948 gtk_entry_get_text_area (GtkEntry *entry,
6949 GdkRectangle *text_area)
6951 GtkEntryPrivate *priv;
6953 g_return_if_fail (GTK_IS_ENTRY (entry));
6954 g_return_if_fail (text_area != NULL);
6958 if (priv->text_area)
6960 GtkAllocation allocation;
6963 gtk_widget_get_allocation (GTK_WIDGET (entry), &allocation);
6964 gdk_window_get_position (priv->text_area, &x, &y);
6966 text_area->x = x - allocation.x;
6967 text_area->y = y - allocation.y;
6968 text_area->width = gdk_window_get_width (priv->text_area);
6969 text_area->height = gdk_window_get_height (priv->text_area);
6975 text_area->width = 0;
6976 text_area->height = 0;
6981 * gtk_entry_set_text:
6982 * @entry: a #GtkEntry
6983 * @text: the new text
6985 * Sets the text in the widget to the given
6986 * value, replacing the current contents.
6988 * See gtk_entry_buffer_set_text().
6991 gtk_entry_set_text (GtkEntry *entry,
6995 GtkEntryCompletion *completion;
6997 g_return_if_fail (GTK_IS_ENTRY (entry));
6998 g_return_if_fail (text != NULL);
7000 /* Actually setting the text will affect the cursor and selection;
7001 * if the contents don't actually change, this will look odd to the user.
7003 if (strcmp (gtk_entry_buffer_get_text (get_buffer (entry)), text) == 0)
7006 completion = gtk_entry_get_completion (entry);
7007 if (completion && completion->priv->changed_id > 0)
7008 g_signal_handler_block (entry, completion->priv->changed_id);
7010 begin_change (entry);
7011 g_object_freeze_notify (G_OBJECT (entry));
7012 gtk_editable_delete_text (GTK_EDITABLE (entry), 0, -1);
7014 gtk_editable_insert_text (GTK_EDITABLE (entry), text, strlen (text), &tmp_pos);
7015 g_object_thaw_notify (G_OBJECT (entry));
7018 if (completion && completion->priv->changed_id > 0)
7019 g_signal_handler_unblock (entry, completion->priv->changed_id);
7023 * gtk_entry_set_visibility:
7024 * @entry: a #GtkEntry
7025 * @visible: %TRUE if the contents of the entry are displayed
7028 * Sets whether the contents of the entry are visible or not.
7029 * When visibility is set to %FALSE, characters are displayed
7030 * as the invisible char, and will also appear that way when
7031 * the text in the entry widget is copied elsewhere.
7033 * By default, GTK+ picks the best invisible character available
7034 * in the current font, but it can be changed with
7035 * gtk_entry_set_invisible_char().
7038 gtk_entry_set_visibility (GtkEntry *entry,
7041 GtkEntryPrivate *priv;
7043 g_return_if_fail (GTK_IS_ENTRY (entry));
7047 visible = visible != FALSE;
7049 if (priv->visible != visible)
7051 priv->visible = visible;
7053 g_object_notify (G_OBJECT (entry), "visibility");
7054 gtk_entry_recompute (entry);
7059 * gtk_entry_get_visibility:
7060 * @entry: a #GtkEntry
7062 * Retrieves whether the text in @entry is visible. See
7063 * gtk_entry_set_visibility().
7065 * Return value: %TRUE if the text is currently visible
7068 gtk_entry_get_visibility (GtkEntry *entry)
7070 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7072 return entry->priv->visible;
7076 * gtk_entry_set_invisible_char:
7077 * @entry: a #GtkEntry
7078 * @ch: a Unicode character
7080 * Sets the character to use in place of the actual text when
7081 * gtk_entry_set_visibility() has been called to set text visibility
7082 * to %FALSE. i.e. this is the character used in "password mode" to
7083 * show the user how many characters have been typed. By default, GTK+
7084 * picks the best invisible char available in the current font. If you
7085 * set the invisible char to 0, then the user will get no feedback
7086 * at all; there will be no text on the screen as they type.
7089 gtk_entry_set_invisible_char (GtkEntry *entry,
7092 GtkEntryPrivate *priv;
7094 g_return_if_fail (GTK_IS_ENTRY (entry));
7098 if (!priv->invisible_char_set)
7100 priv->invisible_char_set = TRUE;
7101 g_object_notify (G_OBJECT (entry), "invisible-char-set");
7104 if (ch == priv->invisible_char)
7107 priv->invisible_char = ch;
7108 g_object_notify (G_OBJECT (entry), "invisible-char");
7109 gtk_entry_recompute (entry);
7113 * gtk_entry_get_invisible_char:
7114 * @entry: a #GtkEntry
7116 * Retrieves the character displayed in place of the real characters
7117 * for entries with visibility set to false. See gtk_entry_set_invisible_char().
7119 * Return value: the current invisible char, or 0, if the entry does not
7120 * show invisible text at all.
7123 gtk_entry_get_invisible_char (GtkEntry *entry)
7125 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7127 return entry->priv->invisible_char;
7131 * gtk_entry_unset_invisible_char:
7132 * @entry: a #GtkEntry
7134 * Unsets the invisible char previously set with
7135 * gtk_entry_set_invisible_char(). So that the
7136 * default invisible char is used again.
7141 gtk_entry_unset_invisible_char (GtkEntry *entry)
7143 GtkEntryPrivate *priv;
7146 g_return_if_fail (GTK_IS_ENTRY (entry));
7150 if (!priv->invisible_char_set)
7153 priv->invisible_char_set = FALSE;
7154 ch = find_invisible_char (GTK_WIDGET (entry));
7156 if (priv->invisible_char != ch)
7158 priv->invisible_char = ch;
7159 g_object_notify (G_OBJECT (entry), "invisible-char");
7162 g_object_notify (G_OBJECT (entry), "invisible-char-set");
7163 gtk_entry_recompute (entry);
7167 * gtk_entry_set_overwrite_mode:
7168 * @entry: a #GtkEntry
7169 * @overwrite: new value
7171 * Sets whether the text is overwritten when typing in the #GtkEntry.
7176 gtk_entry_set_overwrite_mode (GtkEntry *entry,
7179 GtkEntryPrivate *priv = entry->priv;
7181 g_return_if_fail (GTK_IS_ENTRY (entry));
7183 if (priv->overwrite_mode == overwrite)
7186 gtk_entry_toggle_overwrite (entry);
7188 g_object_notify (G_OBJECT (entry), "overwrite-mode");
7192 * gtk_entry_get_overwrite_mode:
7193 * @entry: a #GtkEntry
7195 * Gets the value set by gtk_entry_set_overwrite_mode().
7197 * Return value: whether the text is overwritten when typing.
7202 gtk_entry_get_overwrite_mode (GtkEntry *entry)
7204 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7206 return entry->priv->overwrite_mode;
7210 * gtk_entry_get_text:
7211 * @entry: a #GtkEntry
7213 * Retrieves the contents of the entry widget.
7214 * See also gtk_editable_get_chars().
7216 * This is equivalent to:
7218 * <informalexample><programlisting>
7219 * gtk_entry_buffer_get_text (gtk_entry_get_buffer (entry));
7220 * </programlisting></informalexample>
7222 * Return value: a pointer to the contents of the widget as a
7223 * string. This string points to internally allocated
7224 * storage in the widget and must not be freed, modified or
7227 G_CONST_RETURN gchar*
7228 gtk_entry_get_text (GtkEntry *entry)
7230 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7232 return gtk_entry_buffer_get_text (get_buffer (entry));
7236 * gtk_entry_set_max_length:
7237 * @entry: a #GtkEntry
7238 * @max: the maximum length of the entry, or 0 for no maximum.
7239 * (other than the maximum length of entries.) The value passed in will
7240 * be clamped to the range 0-65536.
7242 * Sets the maximum allowed length of the contents of the widget. If
7243 * the current contents are longer than the given length, then they
7244 * will be truncated to fit.
7246 * This is equivalent to:
7248 * <informalexample><programlisting>
7249 * gtk_entry_buffer_set_max_length (gtk_entry_get_buffer (entry), max);
7250 * </programlisting></informalexample>
7253 gtk_entry_set_max_length (GtkEntry *entry,
7256 g_return_if_fail (GTK_IS_ENTRY (entry));
7257 gtk_entry_buffer_set_max_length (get_buffer (entry), max);
7261 * gtk_entry_get_max_length:
7262 * @entry: a #GtkEntry
7264 * Retrieves the maximum allowed length of the text in
7265 * @entry. See gtk_entry_set_max_length().
7267 * This is equivalent to:
7269 * <informalexample><programlisting>
7270 * gtk_entry_buffer_get_max_length (gtk_entry_get_buffer (entry));
7271 * </programlisting></informalexample>
7273 * Return value: the maximum allowed number of characters
7274 * in #GtkEntry, or 0 if there is no maximum.
7277 gtk_entry_get_max_length (GtkEntry *entry)
7279 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7281 return gtk_entry_buffer_get_max_length (get_buffer (entry));
7285 * gtk_entry_get_text_length:
7286 * @entry: a #GtkEntry
7288 * Retrieves the current length of the text in
7291 * This is equivalent to:
7293 * <informalexample><programlisting>
7294 * gtk_entry_buffer_get_length (gtk_entry_get_buffer (entry));
7295 * </programlisting></informalexample>
7297 * Return value: the current number of characters
7298 * in #GtkEntry, or 0 if there are none.
7303 gtk_entry_get_text_length (GtkEntry *entry)
7305 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7307 return gtk_entry_buffer_get_length (get_buffer (entry));
7311 * gtk_entry_set_activates_default:
7312 * @entry: a #GtkEntry
7313 * @setting: %TRUE to activate window's default widget on Enter keypress
7315 * If @setting is %TRUE, pressing Enter in the @entry will activate the default
7316 * widget for the window containing the entry. This usually means that
7317 * the dialog box containing the entry will be closed, since the default
7318 * widget is usually one of the dialog buttons.
7320 * (For experts: if @setting is %TRUE, the entry calls
7321 * gtk_window_activate_default() on the window containing the entry, in
7322 * the default handler for the #GtkWidget::activate signal.)
7325 gtk_entry_set_activates_default (GtkEntry *entry,
7328 GtkEntryPrivate *priv;
7330 g_return_if_fail (GTK_IS_ENTRY (entry));
7334 setting = setting != FALSE;
7336 if (setting != priv->activates_default)
7338 priv->activates_default = setting;
7339 g_object_notify (G_OBJECT (entry), "activates-default");
7344 * gtk_entry_get_activates_default:
7345 * @entry: a #GtkEntry
7347 * Retrieves the value set by gtk_entry_set_activates_default().
7349 * Return value: %TRUE if the entry will activate the default widget
7352 gtk_entry_get_activates_default (GtkEntry *entry)
7354 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7356 return entry->priv->activates_default;
7360 * gtk_entry_set_width_chars:
7361 * @entry: a #GtkEntry
7362 * @n_chars: width in chars
7364 * Changes the size request of the entry to be about the right size
7365 * for @n_chars characters. Note that it changes the size
7366 * <emphasis>request</emphasis>, the size can still be affected by
7367 * how you pack the widget into containers. If @n_chars is -1, the
7368 * size reverts to the default entry size.
7371 gtk_entry_set_width_chars (GtkEntry *entry,
7374 GtkEntryPrivate *priv;
7376 g_return_if_fail (GTK_IS_ENTRY (entry));
7380 if (priv->width_chars != n_chars)
7382 priv->width_chars = n_chars;
7383 g_object_notify (G_OBJECT (entry), "width-chars");
7384 gtk_widget_queue_resize (GTK_WIDGET (entry));
7389 * gtk_entry_get_width_chars:
7390 * @entry: a #GtkEntry
7392 * Gets the value set by gtk_entry_set_width_chars().
7394 * Return value: number of chars to request space for, or negative if unset
7397 gtk_entry_get_width_chars (GtkEntry *entry)
7399 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7401 return entry->priv->width_chars;
7405 * gtk_entry_set_has_frame:
7406 * @entry: a #GtkEntry
7407 * @setting: new value
7409 * Sets whether the entry has a beveled frame around it.
7412 gtk_entry_set_has_frame (GtkEntry *entry,
7415 GtkEntryPrivate *priv;
7417 g_return_if_fail (GTK_IS_ENTRY (entry));
7421 setting = (setting != FALSE);
7423 if (priv->has_frame == setting)
7426 gtk_widget_queue_resize (GTK_WIDGET (entry));
7427 priv->has_frame = setting;
7428 g_object_notify (G_OBJECT (entry), "has-frame");
7432 * gtk_entry_get_has_frame:
7433 * @entry: a #GtkEntry
7435 * Gets the value set by gtk_entry_set_has_frame().
7437 * Return value: whether the entry has a beveled frame
7440 gtk_entry_get_has_frame (GtkEntry *entry)
7442 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7444 return entry->priv->has_frame;
7448 * gtk_entry_set_inner_border:
7449 * @entry: a #GtkEntry
7450 * @border: (allow-none): a #GtkBorder, or %NULL
7452 * Sets %entry's inner-border property to %border, or clears it if %NULL
7453 * is passed. The inner-border is the area around the entry's text, but
7456 * If set, this property overrides the inner-border style property.
7457 * Overriding the style-provided border is useful when you want to do
7458 * in-place editing of some text in a canvas or list widget, where
7459 * pixel-exact positioning of the entry is important.
7464 gtk_entry_set_inner_border (GtkEntry *entry,
7465 const GtkBorder *border)
7467 g_return_if_fail (GTK_IS_ENTRY (entry));
7469 gtk_widget_queue_resize (GTK_WIDGET (entry));
7472 g_object_set_qdata_full (G_OBJECT (entry), quark_inner_border,
7473 gtk_border_copy (border),
7474 (GDestroyNotify) gtk_border_free);
7476 g_object_set_qdata (G_OBJECT (entry), quark_inner_border, NULL);
7478 g_object_notify (G_OBJECT (entry), "inner-border");
7482 * gtk_entry_get_inner_border:
7483 * @entry: a #GtkEntry
7485 * This function returns the entry's #GtkEntry:inner-border property. See
7486 * gtk_entry_set_inner_border() for more information.
7488 * Return value: (transfer none): the entry's #GtkBorder, or %NULL if none was set.
7492 G_CONST_RETURN GtkBorder *
7493 gtk_entry_get_inner_border (GtkEntry *entry)
7495 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7497 return g_object_get_qdata (G_OBJECT (entry), quark_inner_border);
7501 * gtk_entry_get_layout:
7502 * @entry: a #GtkEntry
7504 * Gets the #PangoLayout used to display the entry.
7505 * The layout is useful to e.g. convert text positions to
7506 * pixel positions, in combination with gtk_entry_get_layout_offsets().
7507 * The returned layout is owned by the entry and must not be
7508 * modified or freed by the caller.
7510 * Keep in mind that the layout text may contain a preedit string, so
7511 * gtk_entry_layout_index_to_text_index() and
7512 * gtk_entry_text_index_to_layout_index() are needed to convert byte
7513 * indices in the layout to byte indices in the entry contents.
7515 * Return value: (transfer none): the #PangoLayout for this entry
7518 gtk_entry_get_layout (GtkEntry *entry)
7520 PangoLayout *layout;
7522 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7524 layout = gtk_entry_ensure_layout (entry, TRUE);
7531 * gtk_entry_layout_index_to_text_index:
7532 * @entry: a #GtkEntry
7533 * @layout_index: byte index into the entry layout text
7535 * Converts from a position in the entry contents (returned
7536 * by gtk_entry_get_text()) to a position in the
7537 * entry's #PangoLayout (returned by gtk_entry_get_layout(),
7538 * with text retrieved via pango_layout_get_text()).
7540 * Return value: byte index into the entry contents
7543 gtk_entry_layout_index_to_text_index (GtkEntry *entry,
7546 GtkEntryPrivate *priv;
7547 PangoLayout *layout;
7551 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7555 layout = gtk_entry_ensure_layout (entry, TRUE);
7556 text = pango_layout_get_text (layout);
7557 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos) - text;
7559 if (layout_index >= cursor_index && priv->preedit_length)
7561 if (layout_index >= cursor_index + priv->preedit_length)
7562 layout_index -= priv->preedit_length;
7564 layout_index = cursor_index;
7567 return layout_index;
7571 * gtk_entry_text_index_to_layout_index:
7572 * @entry: a #GtkEntry
7573 * @text_index: byte index into the entry contents
7575 * Converts from a position in the entry's #PangoLayout (returned by
7576 * gtk_entry_get_layout()) to a position in the entry contents
7577 * (returned by gtk_entry_get_text()).
7579 * Return value: byte index into the entry layout text
7582 gtk_entry_text_index_to_layout_index (GtkEntry *entry,
7585 GtkEntryPrivate *priv;
7586 PangoLayout *layout;
7590 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7594 layout = gtk_entry_ensure_layout (entry, TRUE);
7595 text = pango_layout_get_text (layout);
7596 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos) - text;
7598 if (text_index > cursor_index)
7599 text_index += priv->preedit_length;
7605 * gtk_entry_get_layout_offsets:
7606 * @entry: a #GtkEntry
7607 * @x: (out) (allow-none): location to store X offset of layout, or %NULL
7608 * @y: (out) (allow-none): location to store Y offset of layout, or %NULL
7611 * Obtains the position of the #PangoLayout used to render text
7612 * in the entry, in widget coordinates. Useful if you want to line
7613 * up the text in an entry with some other text, e.g. when using the
7614 * entry to implement editable cells in a sheet widget.
7616 * Also useful to convert mouse events into coordinates inside the
7617 * #PangoLayout, e.g. to take some action if some part of the entry text
7620 * Note that as the user scrolls around in the entry the offsets will
7621 * change; you'll need to connect to the "notify::scroll-offset"
7622 * signal to track this. Remember when using the #PangoLayout
7623 * functions you need to convert to and from pixels using
7624 * PANGO_PIXELS() or #PANGO_SCALE.
7626 * Keep in mind that the layout text may contain a preedit string, so
7627 * gtk_entry_layout_index_to_text_index() and
7628 * gtk_entry_text_index_to_layout_index() are needed to convert byte
7629 * indices in the layout to byte indices in the entry contents.
7632 gtk_entry_get_layout_offsets (GtkEntry *entry,
7636 gint text_area_x, text_area_y;
7638 g_return_if_fail (GTK_IS_ENTRY (entry));
7640 /* this gets coords relative to text area */
7641 get_layout_position (entry, x, y);
7643 /* convert to widget coords */
7644 gtk_entry_get_text_area_size (entry, &text_area_x, &text_area_y, NULL, NULL);
7655 * gtk_entry_set_alignment:
7656 * @entry: a #GtkEntry
7657 * @xalign: The horizontal alignment, from 0 (left) to 1 (right).
7658 * Reversed for RTL layouts
7660 * Sets the alignment for the contents of the entry. This controls
7661 * the horizontal positioning of the contents when the displayed
7662 * text is shorter than the width of the entry.
7667 gtk_entry_set_alignment (GtkEntry *entry, gfloat xalign)
7669 GtkEntryPrivate *priv;
7671 g_return_if_fail (GTK_IS_ENTRY (entry));
7677 else if (xalign > 1.0)
7680 if (xalign != priv->xalign)
7682 priv->xalign = xalign;
7684 gtk_entry_recompute (entry);
7686 g_object_notify (G_OBJECT (entry), "xalign");
7691 * gtk_entry_get_alignment:
7692 * @entry: a #GtkEntry
7694 * Gets the value set by gtk_entry_set_alignment().
7696 * Return value: the alignment
7701 gtk_entry_get_alignment (GtkEntry *entry)
7703 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
7705 return entry->priv->xalign;
7709 * gtk_entry_set_icon_from_pixbuf:
7710 * @entry: a #GtkEntry
7711 * @icon_pos: Icon position
7712 * @pixbuf: (allow-none): A #GdkPixbuf, or %NULL
7714 * Sets the icon shown in the specified position using a pixbuf.
7716 * If @pixbuf is %NULL, no icon will be shown in the specified position.
7721 gtk_entry_set_icon_from_pixbuf (GtkEntry *entry,
7722 GtkEntryIconPosition icon_pos,
7725 GtkEntryPrivate *priv;
7726 EntryIconInfo *icon_info;
7728 g_return_if_fail (GTK_IS_ENTRY (entry));
7729 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7733 if ((icon_info = priv->icons[icon_pos]) == NULL)
7734 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7736 g_object_freeze_notify (G_OBJECT (entry));
7739 g_object_ref (pixbuf);
7741 gtk_entry_clear (entry, icon_pos);
7745 icon_info->storage_type = GTK_IMAGE_PIXBUF;
7746 icon_info->pixbuf = pixbuf;
7748 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7750 g_object_notify (G_OBJECT (entry), "primary-icon-pixbuf");
7751 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7755 g_object_notify (G_OBJECT (entry), "secondary-icon-pixbuf");
7756 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7759 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7760 gdk_window_show_unraised (icon_info->window);
7763 gtk_entry_ensure_pixbuf (entry, icon_pos);
7765 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7766 gtk_widget_queue_resize (GTK_WIDGET (entry));
7768 g_object_thaw_notify (G_OBJECT (entry));
7772 * gtk_entry_set_icon_from_stock:
7773 * @entry: A #GtkEntry
7774 * @icon_pos: Icon position
7775 * @stock_id: (allow-none): The name of the stock item, or %NULL
7777 * Sets the icon shown in the entry at the specified position from
7780 * If @stock_id is %NULL, no icon will be shown in the specified position.
7785 gtk_entry_set_icon_from_stock (GtkEntry *entry,
7786 GtkEntryIconPosition icon_pos,
7787 const gchar *stock_id)
7789 GtkEntryPrivate *priv;
7790 EntryIconInfo *icon_info;
7793 g_return_if_fail (GTK_IS_ENTRY (entry));
7794 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7798 if ((icon_info = priv->icons[icon_pos]) == NULL)
7799 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7801 g_object_freeze_notify (G_OBJECT (entry));
7803 /* need to dup before clearing */
7804 new_id = g_strdup (stock_id);
7806 gtk_entry_clear (entry, icon_pos);
7810 icon_info->storage_type = GTK_IMAGE_STOCK;
7811 icon_info->stock_id = new_id;
7813 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7815 g_object_notify (G_OBJECT (entry), "primary-icon-stock");
7816 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7820 g_object_notify (G_OBJECT (entry), "secondary-icon-stock");
7821 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7824 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7825 gdk_window_show_unraised (icon_info->window);
7828 gtk_entry_ensure_pixbuf (entry, icon_pos);
7830 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7831 gtk_widget_queue_resize (GTK_WIDGET (entry));
7833 g_object_thaw_notify (G_OBJECT (entry));
7837 * gtk_entry_set_icon_from_icon_name:
7838 * @entry: A #GtkEntry
7839 * @icon_pos: The position at which to set the icon
7840 * @icon_name: (allow-none): An icon name, or %NULL
7842 * Sets the icon shown in the entry at the specified position
7843 * from the current icon theme.
7845 * If the icon name isn't known, a "broken image" icon will be displayed
7848 * If @icon_name is %NULL, no icon will be shown in the specified position.
7853 gtk_entry_set_icon_from_icon_name (GtkEntry *entry,
7854 GtkEntryIconPosition icon_pos,
7855 const gchar *icon_name)
7857 GtkEntryPrivate *priv;
7858 EntryIconInfo *icon_info;
7861 g_return_if_fail (GTK_IS_ENTRY (entry));
7862 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7866 if ((icon_info = priv->icons[icon_pos]) == NULL)
7867 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7869 g_object_freeze_notify (G_OBJECT (entry));
7871 /* need to dup before clearing */
7872 new_name = g_strdup (icon_name);
7874 gtk_entry_clear (entry, icon_pos);
7876 if (new_name != NULL)
7878 icon_info->storage_type = GTK_IMAGE_ICON_NAME;
7879 icon_info->icon_name = new_name;
7881 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7883 g_object_notify (G_OBJECT (entry), "primary-icon-name");
7884 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7888 g_object_notify (G_OBJECT (entry), "secondary-icon-name");
7889 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7892 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7893 gdk_window_show_unraised (icon_info->window);
7896 gtk_entry_ensure_pixbuf (entry, icon_pos);
7898 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7899 gtk_widget_queue_resize (GTK_WIDGET (entry));
7901 g_object_thaw_notify (G_OBJECT (entry));
7905 * gtk_entry_set_icon_from_gicon:
7906 * @entry: A #GtkEntry
7907 * @icon_pos: The position at which to set the icon
7908 * @icon: (allow-none): The icon to set, or %NULL
7910 * Sets the icon shown in the entry at the specified position
7911 * from the current icon theme.
7912 * If the icon isn't known, a "broken image" icon will be displayed
7915 * If @icon is %NULL, no icon will be shown in the specified position.
7920 gtk_entry_set_icon_from_gicon (GtkEntry *entry,
7921 GtkEntryIconPosition icon_pos,
7924 GtkEntryPrivate *priv;
7925 EntryIconInfo *icon_info;
7927 g_return_if_fail (GTK_IS_ENTRY (entry));
7928 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7932 if ((icon_info = priv->icons[icon_pos]) == NULL)
7933 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7935 g_object_freeze_notify (G_OBJECT (entry));
7937 /* need to ref before clearing */
7939 g_object_ref (icon);
7941 gtk_entry_clear (entry, icon_pos);
7945 icon_info->storage_type = GTK_IMAGE_GICON;
7946 icon_info->gicon = icon;
7948 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7950 g_object_notify (G_OBJECT (entry), "primary-icon-gicon");
7951 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7955 g_object_notify (G_OBJECT (entry), "secondary-icon-gicon");
7956 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7959 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7960 gdk_window_show_unraised (icon_info->window);
7963 gtk_entry_ensure_pixbuf (entry, icon_pos);
7965 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7966 gtk_widget_queue_resize (GTK_WIDGET (entry));
7968 g_object_thaw_notify (G_OBJECT (entry));
7972 * gtk_entry_set_icon_activatable:
7973 * @entry: A #GtkEntry
7974 * @icon_pos: Icon position
7975 * @activatable: %TRUE if the icon should be activatable
7977 * Sets whether the icon is activatable.
7982 gtk_entry_set_icon_activatable (GtkEntry *entry,
7983 GtkEntryIconPosition icon_pos,
7984 gboolean activatable)
7986 GtkEntryPrivate *priv;
7987 EntryIconInfo *icon_info;
7989 g_return_if_fail (GTK_IS_ENTRY (entry));
7990 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7994 if ((icon_info = priv->icons[icon_pos]) == NULL)
7995 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7997 activatable = activatable != FALSE;
7999 if (icon_info->nonactivatable != !activatable)
8001 icon_info->nonactivatable = !activatable;
8003 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
8004 update_cursors (GTK_WIDGET (entry));
8006 g_object_notify (G_OBJECT (entry),
8007 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-activatable" : "secondary-icon-activatable");
8012 * gtk_entry_get_icon_activatable:
8013 * @entry: a #GtkEntry
8014 * @icon_pos: Icon position
8016 * Returns whether the icon is activatable.
8018 * Returns: %TRUE if the icon is activatable.
8023 gtk_entry_get_icon_activatable (GtkEntry *entry,
8024 GtkEntryIconPosition icon_pos)
8026 GtkEntryPrivate *priv;
8027 EntryIconInfo *icon_info;
8029 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
8030 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), FALSE);
8033 icon_info = priv->icons[icon_pos];
8035 return (!icon_info || !icon_info->nonactivatable);
8039 * gtk_entry_get_icon_pixbuf:
8040 * @entry: A #GtkEntry
8041 * @icon_pos: Icon position
8043 * Retrieves the image used for the icon.
8045 * Unlike the other methods of setting and getting icon data, this
8046 * method will work regardless of whether the icon was set using a
8047 * #GdkPixbuf, a #GIcon, a stock item, or an icon name.
8049 * Returns: (transfer none): A #GdkPixbuf, or %NULL if no icon is
8050 * set for this position.
8055 gtk_entry_get_icon_pixbuf (GtkEntry *entry,
8056 GtkEntryIconPosition icon_pos)
8058 GtkEntryPrivate *priv;
8059 EntryIconInfo *icon_info;
8061 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8062 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8066 icon_info = priv->icons[icon_pos];
8071 gtk_entry_ensure_pixbuf (entry, icon_pos);
8073 return icon_info->pixbuf;
8077 * gtk_entry_get_icon_gicon:
8078 * @entry: A #GtkEntry
8079 * @icon_pos: Icon position
8081 * Retrieves the #GIcon used for the icon, or %NULL if there is
8082 * no icon or if the icon was set by some other method (e.g., by
8083 * stock, pixbuf, or icon name).
8085 * Returns: (transfer none): A #GIcon, or %NULL if no icon is set
8086 * or if the icon is not a #GIcon
8091 gtk_entry_get_icon_gicon (GtkEntry *entry,
8092 GtkEntryIconPosition icon_pos)
8094 GtkEntryPrivate *priv;
8095 EntryIconInfo *icon_info;
8097 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8098 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8101 icon_info = priv->icons[icon_pos];
8106 return icon_info->storage_type == GTK_IMAGE_GICON ? icon_info->gicon : NULL;
8110 * gtk_entry_get_icon_stock:
8111 * @entry: A #GtkEntry
8112 * @icon_pos: Icon position
8114 * Retrieves the stock id used for the icon, or %NULL if there is
8115 * no icon or if the icon was set by some other method (e.g., by
8116 * pixbuf, icon name or gicon).
8118 * Returns: A stock id, or %NULL if no icon is set or if the icon
8119 * wasn't set from a stock id
8124 gtk_entry_get_icon_stock (GtkEntry *entry,
8125 GtkEntryIconPosition icon_pos)
8127 GtkEntryPrivate *priv;
8128 EntryIconInfo *icon_info;
8130 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8131 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8134 icon_info = priv->icons[icon_pos];
8139 return icon_info->storage_type == GTK_IMAGE_STOCK ? icon_info->stock_id : NULL;
8143 * gtk_entry_get_icon_name:
8144 * @entry: A #GtkEntry
8145 * @icon_pos: Icon position
8147 * Retrieves the icon name used for the icon, or %NULL if there is
8148 * no icon or if the icon was set by some other method (e.g., by
8149 * pixbuf, stock or gicon).
8151 * Returns: An icon name, or %NULL if no icon is set or if the icon
8152 * wasn't set from an icon name
8157 gtk_entry_get_icon_name (GtkEntry *entry,
8158 GtkEntryIconPosition icon_pos)
8160 GtkEntryPrivate *priv;
8161 EntryIconInfo *icon_info;
8163 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8164 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8167 icon_info = priv->icons[icon_pos];
8172 return icon_info->storage_type == GTK_IMAGE_ICON_NAME ? icon_info->icon_name : NULL;
8176 * gtk_entry_set_icon_sensitive:
8177 * @entry: A #GtkEntry
8178 * @icon_pos: Icon position
8179 * @sensitive: Specifies whether the icon should appear
8180 * sensitive or insensitive
8182 * Sets the sensitivity for the specified icon.
8187 gtk_entry_set_icon_sensitive (GtkEntry *entry,
8188 GtkEntryIconPosition icon_pos,
8191 GtkEntryPrivate *priv;
8192 EntryIconInfo *icon_info;
8194 g_return_if_fail (GTK_IS_ENTRY (entry));
8195 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8199 if ((icon_info = priv->icons[icon_pos]) == NULL)
8200 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8202 if (icon_info->insensitive != !sensitive)
8204 icon_info->insensitive = !sensitive;
8206 icon_info->pressed = FALSE;
8207 icon_info->prelight = FALSE;
8209 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
8210 update_cursors (GTK_WIDGET (entry));
8212 gtk_widget_queue_draw (GTK_WIDGET (entry));
8214 g_object_notify (G_OBJECT (entry),
8215 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-sensitive" : "secondary-icon-sensitive");
8220 * gtk_entry_get_icon_sensitive:
8221 * @entry: a #GtkEntry
8222 * @icon_pos: Icon position
8224 * Returns whether the icon appears sensitive or insensitive.
8226 * Returns: %TRUE if the icon is sensitive.
8231 gtk_entry_get_icon_sensitive (GtkEntry *entry,
8232 GtkEntryIconPosition icon_pos)
8234 GtkEntryPrivate *priv;
8235 EntryIconInfo *icon_info;
8237 g_return_val_if_fail (GTK_IS_ENTRY (entry), TRUE);
8238 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), TRUE);
8242 icon_info = priv->icons[icon_pos];
8244 return (!icon_info || !icon_info->insensitive);
8249 * gtk_entry_get_icon_storage_type:
8250 * @entry: a #GtkEntry
8251 * @icon_pos: Icon position
8253 * Gets the type of representation being used by the icon
8254 * to store image data. If the icon has no image data,
8255 * the return value will be %GTK_IMAGE_EMPTY.
8257 * Return value: image representation being used
8262 gtk_entry_get_icon_storage_type (GtkEntry *entry,
8263 GtkEntryIconPosition icon_pos)
8265 GtkEntryPrivate *priv;
8266 EntryIconInfo *icon_info;
8268 g_return_val_if_fail (GTK_IS_ENTRY (entry), GTK_IMAGE_EMPTY);
8269 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), GTK_IMAGE_EMPTY);
8273 icon_info = priv->icons[icon_pos];
8276 return GTK_IMAGE_EMPTY;
8278 return icon_info->storage_type;
8282 * gtk_entry_get_icon_at_pos:
8283 * @entry: a #GtkEntry
8284 * @x: the x coordinate of the position to find
8285 * @y: the y coordinate of the position to find
8287 * Finds the icon at the given position and return its index. The
8288 * position's coordinates are relative to the @entry's top left corner.
8289 * If @x, @y doesn't lie inside an icon, -1 is returned.
8290 * This function is intended for use in a #GtkWidget::query-tooltip
8293 * Returns: the index of the icon at the given position, or -1
8298 gtk_entry_get_icon_at_pos (GtkEntry *entry,
8302 GtkAllocation primary;
8303 GtkAllocation secondary;
8304 gint frame_x, frame_y;
8306 g_return_val_if_fail (GTK_IS_ENTRY (entry), -1);
8308 get_frame_size (entry, FALSE, &frame_x, &frame_y, NULL, NULL);
8312 get_icon_allocations (entry, &primary, &secondary);
8314 if (primary.x <= x && x < primary.x + primary.width &&
8315 primary.y <= y && y < primary.y + primary.height)
8316 return GTK_ENTRY_ICON_PRIMARY;
8318 if (secondary.x <= x && x < secondary.x + secondary.width &&
8319 secondary.y <= y && y < secondary.y + secondary.height)
8320 return GTK_ENTRY_ICON_SECONDARY;
8326 * gtk_entry_set_icon_drag_source:
8327 * @entry: a #GtkIconEntry
8328 * @icon_pos: icon position
8329 * @target_list: the targets (data formats) in which the data can be provided
8330 * @actions: a bitmask of the allowed drag actions
8332 * Sets up the icon at the given position so that GTK+ will start a drag
8333 * operation when the user clicks and drags the icon.
8335 * To handle the drag operation, you need to connect to the usual
8336 * #GtkWidget::drag-data-get (or possibly #GtkWidget::drag-data-delete)
8337 * signal, and use gtk_entry_get_current_icon_drag_source() in
8338 * your signal handler to find out if the drag was started from
8341 * By default, GTK+ uses the icon as the drag icon. You can use the
8342 * #GtkWidget::drag-begin signal to set a different icon. Note that you
8343 * have to use g_signal_connect_after() to ensure that your signal handler
8344 * gets executed after the default handler.
8349 gtk_entry_set_icon_drag_source (GtkEntry *entry,
8350 GtkEntryIconPosition icon_pos,
8351 GtkTargetList *target_list,
8352 GdkDragAction actions)
8354 GtkEntryPrivate *priv;
8355 EntryIconInfo *icon_info;
8357 g_return_if_fail (GTK_IS_ENTRY (entry));
8358 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8362 if ((icon_info = priv->icons[icon_pos]) == NULL)
8363 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8365 if (icon_info->target_list)
8366 gtk_target_list_unref (icon_info->target_list);
8367 icon_info->target_list = target_list;
8368 if (icon_info->target_list)
8369 gtk_target_list_ref (icon_info->target_list);
8371 icon_info->actions = actions;
8375 * gtk_entry_get_current_icon_drag_source:
8376 * @entry: a #GtkIconEntry
8378 * Returns the index of the icon which is the source of the current
8379 * DND operation, or -1.
8381 * This function is meant to be used in a #GtkWidget::drag-data-get
8384 * Returns: index of the icon which is the source of the current
8385 * DND operation, or -1.
8390 gtk_entry_get_current_icon_drag_source (GtkEntry *entry)
8392 GtkEntryPrivate *priv;
8393 EntryIconInfo *icon_info = NULL;
8396 g_return_val_if_fail (GTK_IS_ENTRY (entry), -1);
8400 for (i = 0; i < MAX_ICONS; i++)
8402 if ((icon_info = priv->icons[i]))
8404 if (icon_info->in_drag)
8413 * gtk_entry_get_icon_area:
8414 * @entry: A #GtkEntry
8415 * @icon_pos: Icon position
8416 * @icon_area: (out): Return location for the icon's area
8418 * Gets the area where entry's icon at @icon_pos is drawn.
8419 * This function is useful when drawing something to the
8420 * entry in a draw callback.
8422 * If the entry is not realized or has no icon at the given position,
8423 * @icon_area is filled with zeros.
8425 * See also gtk_entry_get_text_area()
8430 gtk_entry_get_icon_area (GtkEntry *entry,
8431 GtkEntryIconPosition icon_pos,
8432 GdkRectangle *icon_area)
8434 GtkEntryPrivate *priv;
8435 EntryIconInfo *icon_info;
8437 g_return_if_fail (GTK_IS_ENTRY (entry));
8438 g_return_if_fail (icon_area != NULL);
8442 icon_info = priv->icons[icon_pos];
8446 GtkAllocation primary;
8447 GtkAllocation secondary;
8449 get_icon_allocations (entry, &primary, &secondary);
8451 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
8452 *icon_area = primary;
8454 *icon_area = secondary;
8460 icon_area->width = 0;
8461 icon_area->height = 0;
8466 ensure_has_tooltip (GtkEntry *entry)
8468 GtkEntryPrivate *priv;
8469 EntryIconInfo *icon_info;
8471 gboolean has_tooltip = FALSE;
8475 for (i = 0; i < MAX_ICONS; i++)
8477 if ((icon_info = priv->icons[i]) != NULL)
8479 if (icon_info->tooltip != NULL)
8487 gtk_widget_set_has_tooltip (GTK_WIDGET (entry), has_tooltip);
8491 * gtk_entry_get_icon_tooltip_text:
8492 * @entry: a #GtkEntry
8493 * @icon_pos: the icon position
8495 * Gets the contents of the tooltip on the icon at the specified
8496 * position in @entry.
8498 * Returns: the tooltip text, or %NULL. Free the returned string
8499 * with g_free() when done.
8504 gtk_entry_get_icon_tooltip_text (GtkEntry *entry,
8505 GtkEntryIconPosition icon_pos)
8507 GtkEntryPrivate *priv;
8508 EntryIconInfo *icon_info;
8511 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8512 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8516 icon_info = priv->icons[icon_pos];
8521 if (icon_info->tooltip &&
8522 !pango_parse_markup (icon_info->tooltip, -1, 0, NULL, &text, NULL, NULL))
8523 g_assert (NULL == text); /* text should still be NULL in case of markup errors */
8529 * gtk_entry_set_icon_tooltip_text:
8530 * @entry: a #GtkEntry
8531 * @icon_pos: the icon position
8532 * @tooltip: (allow-none): the contents of the tooltip for the icon, or %NULL
8534 * Sets @tooltip as the contents of the tooltip for the icon
8535 * at the specified position.
8537 * Use %NULL for @tooltip to remove an existing tooltip.
8539 * See also gtk_widget_set_tooltip_text() and
8540 * gtk_entry_set_icon_tooltip_markup().
8545 gtk_entry_set_icon_tooltip_text (GtkEntry *entry,
8546 GtkEntryIconPosition icon_pos,
8547 const gchar *tooltip)
8549 GtkEntryPrivate *priv;
8550 EntryIconInfo *icon_info;
8552 g_return_if_fail (GTK_IS_ENTRY (entry));
8553 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8557 if ((icon_info = priv->icons[icon_pos]) == NULL)
8558 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8560 if (icon_info->tooltip)
8561 g_free (icon_info->tooltip);
8563 /* Treat an empty string as a NULL string,
8564 * because an empty string would be useless for a tooltip:
8566 if (tooltip && tooltip[0] == '\0')
8569 icon_info->tooltip = tooltip ? g_markup_escape_text (tooltip, -1) : NULL;
8571 ensure_has_tooltip (entry);
8575 * gtk_entry_get_icon_tooltip_markup:
8576 * @entry: a #GtkEntry
8577 * @icon_pos: the icon position
8579 * Gets the contents of the tooltip on the icon at the specified
8580 * position in @entry.
8582 * Returns: the tooltip text, or %NULL. Free the returned string
8583 * with g_free() when done.
8588 gtk_entry_get_icon_tooltip_markup (GtkEntry *entry,
8589 GtkEntryIconPosition icon_pos)
8591 GtkEntryPrivate *priv;
8592 EntryIconInfo *icon_info;
8594 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8595 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8599 icon_info = priv->icons[icon_pos];
8604 return g_strdup (icon_info->tooltip);
8608 * gtk_entry_set_icon_tooltip_markup:
8609 * @entry: a #GtkEntry
8610 * @icon_pos: the icon position
8611 * @tooltip: (allow-none): the contents of the tooltip for the icon, or %NULL
8613 * Sets @tooltip as the contents of the tooltip for the icon at
8614 * the specified position. @tooltip is assumed to be marked up with
8615 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
8617 * Use %NULL for @tooltip to remove an existing tooltip.
8619 * See also gtk_widget_set_tooltip_markup() and
8620 * gtk_enty_set_icon_tooltip_text().
8625 gtk_entry_set_icon_tooltip_markup (GtkEntry *entry,
8626 GtkEntryIconPosition icon_pos,
8627 const gchar *tooltip)
8629 GtkEntryPrivate *priv;
8630 EntryIconInfo *icon_info;
8632 g_return_if_fail (GTK_IS_ENTRY (entry));
8633 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8637 if ((icon_info = priv->icons[icon_pos]) == NULL)
8638 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8640 if (icon_info->tooltip)
8641 g_free (icon_info->tooltip);
8643 /* Treat an empty string as a NULL string,
8644 * because an empty string would be useless for a tooltip:
8646 if (tooltip && tooltip[0] == '\0')
8649 icon_info->tooltip = g_strdup (tooltip);
8651 ensure_has_tooltip (entry);
8655 gtk_entry_query_tooltip (GtkWidget *widget,
8658 gboolean keyboard_tip,
8659 GtkTooltip *tooltip)
8662 GtkEntryPrivate *priv;
8663 EntryIconInfo *icon_info;
8666 entry = GTK_ENTRY (widget);
8671 icon_pos = gtk_entry_get_icon_at_pos (entry, x, y);
8674 if ((icon_info = priv->icons[icon_pos]) != NULL)
8676 if (icon_info->tooltip)
8678 gtk_tooltip_set_markup (tooltip, icon_info->tooltip);
8687 return GTK_WIDGET_CLASS (gtk_entry_parent_class)->query_tooltip (widget,
8694 /* Quick hack of a popup menu
8697 activate_cb (GtkWidget *menuitem,
8700 const gchar *signal = g_object_get_data (G_OBJECT (menuitem), "gtk-signal");
8701 g_signal_emit_by_name (entry, signal);
8706 gtk_entry_mnemonic_activate (GtkWidget *widget,
8707 gboolean group_cycling)
8709 gtk_widget_grab_focus (widget);
8714 append_action_signal (GtkEntry *entry,
8716 const gchar *stock_id,
8717 const gchar *signal,
8720 GtkWidget *menuitem = gtk_image_menu_item_new_from_stock (stock_id, NULL);
8722 g_object_set_data (G_OBJECT (menuitem), I_("gtk-signal"), (char *)signal);
8723 g_signal_connect (menuitem, "activate",
8724 G_CALLBACK (activate_cb), entry);
8726 gtk_widget_set_sensitive (menuitem, sensitive);
8728 gtk_widget_show (menuitem);
8729 gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
8733 popup_menu_detach (GtkWidget *attach_widget,
8736 GtkEntry *entry_attach = GTK_ENTRY (attach_widget);
8737 GtkEntryPrivate *priv_attach = entry_attach->priv;
8739 priv_attach->popup_menu = NULL;
8743 popup_position_func (GtkMenu *menu,
8749 GtkEntry *entry = GTK_ENTRY (user_data);
8750 GtkEntryPrivate *priv = entry->priv;
8751 GtkWidget *widget = GTK_WIDGET (entry);
8753 GtkRequisition menu_req;
8754 GdkRectangle monitor;
8755 GtkBorder inner_border;
8756 gint monitor_num, strong_x, height;
8758 g_return_if_fail (gtk_widget_get_realized (widget));
8760 gdk_window_get_origin (priv->text_area, x, y);
8762 screen = gtk_widget_get_screen (widget);
8763 monitor_num = gdk_screen_get_monitor_at_window (screen, priv->text_area);
8764 if (monitor_num < 0)
8766 gtk_menu_set_monitor (menu, monitor_num);
8768 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
8769 gtk_widget_get_preferred_size (priv->popup_menu,
8771 height = gdk_window_get_height (priv->text_area);
8772 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
8773 _gtk_entry_effective_inner_border (entry, &inner_border);
8775 *x += inner_border.left + strong_x - priv->scroll_offset;
8776 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
8777 *x -= menu_req.width;
8779 if ((*y + height + menu_req.height) <= monitor.y + monitor.height)
8781 else if ((*y - menu_req.height) >= monitor.y)
8782 *y -= menu_req.height;
8783 else if (monitor.y + monitor.height - (*y + height) > *y)
8786 *y -= menu_req.height;
8792 unichar_chosen_func (const char *text,
8795 GtkEntry *entry = GTK_ENTRY (data);
8796 GtkEntryPrivate *priv = entry->priv;
8799 gtk_entry_enter_text (entry, text);
8810 popup_targets_received (GtkClipboard *clipboard,
8811 GtkSelectionData *data,
8814 PopupInfo *info = user_data;
8815 GtkEntry *entry = info->entry;
8816 GtkEntryPrivate *info_entry_priv = entry->priv;
8818 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
8821 gboolean clipboard_contains_text;
8822 GtkWidget *menuitem;
8824 gboolean show_input_method_menu;
8825 gboolean show_unicode_menu;
8827 clipboard_contains_text = gtk_selection_data_targets_include_text (data);
8828 if (info_entry_priv->popup_menu)
8829 gtk_widget_destroy (info_entry_priv->popup_menu);
8831 info_entry_priv->popup_menu = gtk_menu_new ();
8833 gtk_menu_attach_to_widget (GTK_MENU (info_entry_priv->popup_menu),
8837 mode = gtk_entry_get_display_mode (entry);
8838 append_action_signal (entry, info_entry_priv->popup_menu, GTK_STOCK_CUT, "cut-clipboard",
8839 info_entry_priv->editable && mode == DISPLAY_NORMAL &&
8840 info_entry_priv->current_pos != info_entry_priv->selection_bound);
8842 append_action_signal (entry, info_entry_priv->popup_menu, GTK_STOCK_COPY, "copy-clipboard",
8843 mode == DISPLAY_NORMAL &&
8844 info_entry_priv->current_pos != info_entry_priv->selection_bound);
8846 append_action_signal (entry, info_entry_priv->popup_menu, GTK_STOCK_PASTE, "paste-clipboard",
8847 info_entry_priv->editable && clipboard_contains_text);
8849 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_DELETE, NULL);
8850 gtk_widget_set_sensitive (menuitem, info_entry_priv->editable && info_entry_priv->current_pos != info_entry_priv->selection_bound);
8851 g_signal_connect_swapped (menuitem, "activate",
8852 G_CALLBACK (gtk_entry_delete_cb), entry);
8853 gtk_widget_show (menuitem);
8854 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8856 menuitem = gtk_separator_menu_item_new ();
8857 gtk_widget_show (menuitem);
8858 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8860 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_SELECT_ALL, NULL);
8861 g_signal_connect_swapped (menuitem, "activate",
8862 G_CALLBACK (gtk_entry_select_all), entry);
8863 gtk_widget_show (menuitem);
8864 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8866 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
8867 "gtk-show-input-method-menu", &show_input_method_menu,
8868 "gtk-show-unicode-menu", &show_unicode_menu,
8871 if (show_input_method_menu || show_unicode_menu)
8873 menuitem = gtk_separator_menu_item_new ();
8874 gtk_widget_show (menuitem);
8875 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8878 if (show_input_method_menu)
8880 menuitem = gtk_menu_item_new_with_mnemonic (_("Input _Methods"));
8881 gtk_widget_set_sensitive (menuitem, info_entry_priv->editable);
8882 gtk_widget_show (menuitem);
8883 submenu = gtk_menu_new ();
8884 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
8886 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8888 gtk_im_multicontext_append_menuitems (GTK_IM_MULTICONTEXT (info_entry_priv->im_context),
8889 GTK_MENU_SHELL (submenu));
8892 if (show_unicode_menu)
8894 menuitem = gtk_menu_item_new_with_mnemonic (_("_Insert Unicode Control Character"));
8895 gtk_widget_set_sensitive (menuitem, info_entry_priv->editable);
8896 gtk_widget_show (menuitem);
8898 submenu = gtk_menu_new ();
8899 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
8900 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8902 _gtk_text_util_append_special_char_menuitems (GTK_MENU_SHELL (submenu),
8903 unichar_chosen_func,
8907 g_signal_emit (entry,
8908 signals[POPULATE_POPUP],
8910 info_entry_priv->popup_menu);
8914 gtk_menu_popup (GTK_MENU (info_entry_priv->popup_menu), NULL, NULL,
8916 info->button, info->time);
8919 gtk_menu_popup (GTK_MENU (info_entry_priv->popup_menu), NULL, NULL,
8920 popup_position_func, entry,
8921 info->button, info->time);
8922 gtk_menu_shell_select_first (GTK_MENU_SHELL (info_entry_priv->popup_menu), FALSE);
8926 g_object_unref (entry);
8927 g_slice_free (PopupInfo, info);
8931 gtk_entry_do_popup (GtkEntry *entry,
8932 GdkEventButton *event)
8934 PopupInfo *info = g_slice_new (PopupInfo);
8936 /* In order to know what entries we should make sensitive, we
8937 * ask for the current targets of the clipboard, and when
8938 * we get them, then we actually pop up the menu.
8940 info->entry = g_object_ref (entry);
8944 info->button = event->button;
8945 info->time = event->time;
8950 info->time = gtk_get_current_event_time ();
8953 gtk_clipboard_request_contents (gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_CLIPBOARD),
8954 gdk_atom_intern_static_string ("TARGETS"),
8955 popup_targets_received,
8960 gtk_entry_popup_menu (GtkWidget *widget)
8962 gtk_entry_do_popup (GTK_ENTRY (widget), NULL);
8967 gtk_entry_drag_begin (GtkWidget *widget,
8968 GdkDragContext *context)
8970 GtkEntry *entry = GTK_ENTRY (widget);
8971 GtkEntryPrivate *priv = entry->priv;
8974 for (i = 0; i < MAX_ICONS; i++)
8976 EntryIconInfo *icon_info = priv->icons[i];
8978 if (icon_info != NULL)
8980 if (icon_info->in_drag)
8982 switch (icon_info->storage_type)
8984 case GTK_IMAGE_STOCK:
8985 gtk_drag_set_icon_stock (context, icon_info->stock_id, -2, -2);
8988 case GTK_IMAGE_ICON_NAME:
8989 gtk_drag_set_icon_name (context, icon_info->icon_name, -2, -2);
8992 /* FIXME: No GIcon support for dnd icons */
8993 case GTK_IMAGE_GICON:
8994 case GTK_IMAGE_PIXBUF:
8995 gtk_drag_set_icon_pixbuf (context, icon_info->pixbuf, -2, -2);
8998 g_assert_not_reached ();
9006 gtk_entry_drag_end (GtkWidget *widget,
9007 GdkDragContext *context)
9009 GtkEntry *entry = GTK_ENTRY (widget);
9010 GtkEntryPrivate *priv = entry->priv;
9013 for (i = 0; i < MAX_ICONS; i++)
9015 EntryIconInfo *icon_info = priv->icons[i];
9017 if (icon_info != NULL)
9018 icon_info->in_drag = 0;
9023 gtk_entry_drag_leave (GtkWidget *widget,
9024 GdkDragContext *context,
9027 GtkEntry *entry = GTK_ENTRY (widget);
9028 GtkEntryPrivate *priv = entry->priv;
9030 priv->dnd_position = -1;
9031 gtk_widget_queue_draw (widget);
9035 gtk_entry_drag_drop (GtkWidget *widget,
9036 GdkDragContext *context,
9041 GtkEntry *entry = GTK_ENTRY (widget);
9042 GtkEntryPrivate *priv = entry->priv;
9043 GdkAtom target = GDK_NONE;
9046 target = gtk_drag_dest_find_target (widget, context, NULL);
9048 if (target != GDK_NONE)
9049 gtk_drag_get_data (widget, context, target, time);
9051 gtk_drag_finish (context, FALSE, FALSE, time);
9057 gtk_entry_drag_motion (GtkWidget *widget,
9058 GdkDragContext *context,
9063 GtkEntry *entry = GTK_ENTRY (widget);
9064 GtkEntryPrivate *priv = entry->priv;
9065 GtkStyleContext *style_context;
9066 GtkWidget *source_widget;
9067 GdkDragAction suggested_action;
9068 gint new_position, old_position;
9072 style_context = gtk_widget_get_style_context (widget);
9073 gtk_style_context_get_padding (style_context, 0, &padding);
9077 old_position = priv->dnd_position;
9078 new_position = gtk_entry_find_position (entry, x + priv->scroll_offset);
9080 if (priv->editable &&
9081 gtk_drag_dest_find_target (widget, context, NULL) != GDK_NONE)
9083 source_widget = gtk_drag_get_source_widget (context);
9084 suggested_action = gdk_drag_context_get_suggested_action (context);
9086 if (!gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &sel1, &sel2) ||
9087 new_position < sel1 || new_position > sel2)
9089 if (source_widget == widget)
9091 /* Default to MOVE, unless the user has
9092 * pressed ctrl or alt to affect available actions
9094 if ((gdk_drag_context_get_actions (context) & GDK_ACTION_MOVE) != 0)
9095 suggested_action = GDK_ACTION_MOVE;
9098 priv->dnd_position = new_position;
9102 if (source_widget == widget)
9103 suggested_action = 0; /* Can't drop in selection where drag started */
9105 priv->dnd_position = -1;
9110 /* Entry not editable, or no text */
9111 suggested_action = 0;
9112 priv->dnd_position = -1;
9115 gdk_drag_status (context, suggested_action, time);
9117 if (priv->dnd_position != old_position)
9118 gtk_widget_queue_draw (widget);
9124 gtk_entry_drag_data_received (GtkWidget *widget,
9125 GdkDragContext *context,
9128 GtkSelectionData *selection_data,
9132 GtkEntry *entry = GTK_ENTRY (widget);
9133 GtkEntryPrivate *priv = entry->priv;
9134 GtkEditable *editable = GTK_EDITABLE (widget);
9135 GtkStyleContext *style_context;
9139 str = (gchar *) gtk_selection_data_get_text (selection_data);
9141 style_context = gtk_widget_get_style_context (widget);
9142 gtk_style_context_get_padding (style_context, 0, &padding);
9146 if (str && priv->editable)
9152 if (priv->truncate_multiline)
9153 length = truncate_multiline (str);
9155 new_position = gtk_entry_find_position (entry, x + priv->scroll_offset);
9157 if (!gtk_editable_get_selection_bounds (editable, &sel1, &sel2) ||
9158 new_position < sel1 || new_position > sel2)
9160 gtk_editable_insert_text (editable, str, length, &new_position);
9164 /* Replacing selection */
9165 begin_change (entry);
9166 g_object_freeze_notify (G_OBJECT (entry));
9167 gtk_editable_delete_text (editable, sel1, sel2);
9168 gtk_editable_insert_text (editable, str, length, &sel1);
9169 g_object_thaw_notify (G_OBJECT (entry));
9173 gtk_drag_finish (context, TRUE, gdk_drag_context_get_selected_action (context) == GDK_ACTION_MOVE, time);
9177 /* Drag and drop didn't happen! */
9178 gtk_drag_finish (context, FALSE, FALSE, time);
9185 gtk_entry_drag_data_get (GtkWidget *widget,
9186 GdkDragContext *context,
9187 GtkSelectionData *selection_data,
9191 GtkEntry *entry = GTK_ENTRY (widget);
9192 GtkEntryPrivate *priv = entry->priv;
9193 GtkEditable *editable = GTK_EDITABLE (widget);
9194 gint sel_start, sel_end;
9197 /* If there is an icon drag going on, exit early. */
9198 for (i = 0; i < MAX_ICONS; i++)
9200 EntryIconInfo *icon_info = priv->icons[i];
9202 if (icon_info != NULL)
9204 if (icon_info->in_drag)
9209 if (gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end))
9211 gchar *str = gtk_entry_get_display_text (GTK_ENTRY (widget), sel_start, sel_end);
9213 gtk_selection_data_set_text (selection_data, str, -1);
9221 gtk_entry_drag_data_delete (GtkWidget *widget,
9222 GdkDragContext *context)
9224 GtkEntry *entry = GTK_ENTRY (widget);
9225 GtkEntryPrivate *priv = entry->priv;
9226 GtkEditable *editable = GTK_EDITABLE (widget);
9227 gint sel_start, sel_end;
9230 /* If there is an icon drag going on, exit early. */
9231 for (i = 0; i < MAX_ICONS; i++)
9233 EntryIconInfo *icon_info = priv->icons[i];
9235 if (icon_info != NULL)
9237 if (icon_info->in_drag)
9242 if (priv->editable &&
9243 gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end))
9244 gtk_editable_delete_text (editable, sel_start, sel_end);
9247 /* We display the cursor when
9249 * - the selection is empty, AND
9250 * - the widget has focus
9253 #define CURSOR_ON_MULTIPLIER 2
9254 #define CURSOR_OFF_MULTIPLIER 1
9255 #define CURSOR_PEND_MULTIPLIER 3
9256 #define CURSOR_DIVIDER 3
9259 cursor_blinks (GtkEntry *entry)
9261 GtkEntryPrivate *priv = entry->priv;
9263 if (gtk_widget_has_focus (GTK_WIDGET (entry)) &&
9265 priv->selection_bound == priv->current_pos)
9267 GtkSettings *settings;
9270 settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9271 g_object_get (settings, "gtk-cursor-blink", &blink, NULL);
9280 get_cursor_time (GtkEntry *entry)
9282 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9285 g_object_get (settings, "gtk-cursor-blink-time", &time, NULL);
9291 get_cursor_blink_timeout (GtkEntry *entry)
9293 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9296 g_object_get (settings, "gtk-cursor-blink-timeout", &timeout, NULL);
9302 show_cursor (GtkEntry *entry)
9304 GtkEntryPrivate *priv = entry->priv;
9307 if (!priv->cursor_visible)
9309 priv->cursor_visible = TRUE;
9311 widget = GTK_WIDGET (entry);
9312 if (gtk_widget_has_focus (widget) && priv->selection_bound == priv->current_pos)
9313 gtk_widget_queue_draw (widget);
9318 hide_cursor (GtkEntry *entry)
9320 GtkEntryPrivate *priv = entry->priv;
9323 if (priv->cursor_visible)
9325 priv->cursor_visible = FALSE;
9327 widget = GTK_WIDGET (entry);
9328 if (gtk_widget_has_focus (widget) && priv->selection_bound == priv->current_pos)
9329 gtk_widget_queue_draw (widget);
9337 blink_cb (gpointer data)
9340 GtkEntryPrivate *priv;
9343 entry = GTK_ENTRY (data);
9346 if (!gtk_widget_has_focus (GTK_WIDGET (entry)))
9348 g_warning ("GtkEntry - did not receive focus-out-event. If you\n"
9349 "connect a handler to this signal, it must return\n"
9350 "FALSE so the entry gets the event as well");
9352 gtk_entry_check_cursor_blink (entry);
9357 g_assert (priv->selection_bound == priv->current_pos);
9359 blink_timeout = get_cursor_blink_timeout (entry);
9360 if (priv->blink_time > 1000 * blink_timeout &&
9361 blink_timeout < G_MAXINT/1000)
9363 /* we've blinked enough without the user doing anything, stop blinking */
9364 show_cursor (entry);
9365 priv->blink_timeout = 0;
9367 else if (priv->cursor_visible)
9369 hide_cursor (entry);
9370 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_OFF_MULTIPLIER / CURSOR_DIVIDER,
9376 show_cursor (entry);
9377 priv->blink_time += get_cursor_time (entry);
9378 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
9383 /* Remove ourselves */
9388 gtk_entry_check_cursor_blink (GtkEntry *entry)
9390 GtkEntryPrivate *priv = entry->priv;
9392 if (cursor_blinks (entry))
9394 if (!priv->blink_timeout)
9396 show_cursor (entry);
9397 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
9404 if (priv->blink_timeout)
9406 g_source_remove (priv->blink_timeout);
9407 priv->blink_timeout = 0;
9410 priv->cursor_visible = TRUE;
9415 gtk_entry_pend_cursor_blink (GtkEntry *entry)
9417 GtkEntryPrivate *priv = entry->priv;
9419 if (cursor_blinks (entry))
9421 if (priv->blink_timeout != 0)
9422 g_source_remove (priv->blink_timeout);
9424 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_PEND_MULTIPLIER / CURSOR_DIVIDER,
9427 show_cursor (entry);
9432 gtk_entry_reset_blink_time (GtkEntry *entry)
9434 GtkEntryPrivate *priv = entry->priv;
9436 priv->blink_time = 0;
9442 gtk_entry_completion_timeout (gpointer data)
9444 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (data);
9445 GtkEntryPrivate *completion_entry_priv = GTK_ENTRY (completion->priv->entry)->priv;
9447 completion->priv->completion_timeout = 0;
9449 if (completion->priv->filter_model &&
9450 g_utf8_strlen (gtk_entry_get_text (GTK_ENTRY (completion->priv->entry)), -1)
9451 >= completion->priv->minimum_key_length)
9455 GtkTreeSelection *s;
9456 gboolean popup_single;
9458 gtk_entry_completion_complete (completion);
9459 matches = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->filter_model), NULL);
9461 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9463 s = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view));
9465 gtk_tree_selection_unselect_all (s);
9467 actions = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->actions), NULL);
9469 g_object_get (completion, "popup-single-match", &popup_single, NULL);
9470 if ((matches > (popup_single ? 0: 1)) || actions > 0)
9472 if (gtk_widget_get_visible (completion->priv->popup_window))
9473 _gtk_entry_completion_resize_popup (completion);
9475 _gtk_entry_completion_popup (completion, completion_entry_priv->completion_device);
9478 _gtk_entry_completion_popdown (completion);
9480 else if (gtk_widget_get_visible (completion->priv->popup_window))
9481 _gtk_entry_completion_popdown (completion);
9486 static inline gboolean
9487 keyval_is_cursor_move (guint keyval)
9489 if (keyval == GDK_KEY_Up || keyval == GDK_KEY_KP_Up)
9492 if (keyval == GDK_KEY_Down || keyval == GDK_KEY_KP_Down)
9495 if (keyval == GDK_KEY_Page_Up)
9498 if (keyval == GDK_KEY_Page_Down)
9505 gtk_entry_completion_key_press (GtkWidget *widget,
9509 gint matches, actions = 0;
9510 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
9512 if (!gtk_widget_get_mapped (completion->priv->popup_window))
9515 matches = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->filter_model), NULL);
9517 if (completion->priv->actions)
9518 actions = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->actions), NULL);
9520 if (keyval_is_cursor_move (event->keyval))
9522 GtkTreePath *path = NULL;
9524 if (event->keyval == GDK_KEY_Up || event->keyval == GDK_KEY_KP_Up)
9526 if (completion->priv->current_selected < 0)
9527 completion->priv->current_selected = matches + actions - 1;
9529 completion->priv->current_selected--;
9531 else if (event->keyval == GDK_KEY_Down || event->keyval == GDK_KEY_KP_Down)
9533 if (completion->priv->current_selected < matches + actions - 1)
9534 completion->priv->current_selected++;
9536 completion->priv->current_selected = -1;
9538 else if (event->keyval == GDK_KEY_Page_Up)
9540 if (completion->priv->current_selected < 0)
9541 completion->priv->current_selected = matches + actions - 1;
9542 else if (completion->priv->current_selected == 0)
9543 completion->priv->current_selected = -1;
9544 else if (completion->priv->current_selected < matches)
9546 completion->priv->current_selected -= 14;
9547 if (completion->priv->current_selected < 0)
9548 completion->priv->current_selected = 0;
9552 completion->priv->current_selected -= 14;
9553 if (completion->priv->current_selected < matches - 1)
9554 completion->priv->current_selected = matches - 1;
9557 else if (event->keyval == GDK_KEY_Page_Down)
9559 if (completion->priv->current_selected < 0)
9560 completion->priv->current_selected = 0;
9561 else if (completion->priv->current_selected < matches - 1)
9563 completion->priv->current_selected += 14;
9564 if (completion->priv->current_selected > matches - 1)
9565 completion->priv->current_selected = matches - 1;
9567 else if (completion->priv->current_selected == matches + actions - 1)
9569 completion->priv->current_selected = -1;
9573 completion->priv->current_selected += 14;
9574 if (completion->priv->current_selected > matches + actions - 1)
9575 completion->priv->current_selected = matches + actions - 1;
9579 if (completion->priv->current_selected < 0)
9581 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9582 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view)));
9584 if (completion->priv->inline_selection &&
9585 completion->priv->completion_prefix)
9587 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9588 completion->priv->completion_prefix);
9589 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9592 else if (completion->priv->current_selected < matches)
9594 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view)));
9596 path = gtk_tree_path_new_from_indices (completion->priv->current_selected, -1);
9597 gtk_tree_view_set_cursor (GTK_TREE_VIEW (completion->priv->tree_view),
9600 if (completion->priv->inline_selection)
9604 GtkTreeIter child_iter;
9605 GtkTreeModel *model = NULL;
9606 GtkTreeSelection *sel;
9609 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view));
9610 if (!gtk_tree_selection_get_selected (sel, &model, &iter))
9613 gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (model), &child_iter, &iter);
9614 model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model));
9616 if (completion->priv->completion_prefix == NULL)
9617 completion->priv->completion_prefix = g_strdup (gtk_entry_get_text (GTK_ENTRY (completion->priv->entry)));
9619 g_signal_emit_by_name (completion, "cursor-on-match", model,
9620 &child_iter, &entry_set);
9623 else if (completion->priv->current_selected - matches >= 0)
9625 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9627 path = gtk_tree_path_new_from_indices (completion->priv->current_selected - matches, -1);
9628 gtk_tree_view_set_cursor (GTK_TREE_VIEW (completion->priv->action_view),
9631 if (completion->priv->inline_selection &&
9632 completion->priv->completion_prefix)
9634 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9635 completion->priv->completion_prefix);
9636 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9640 gtk_tree_path_free (path);
9644 else if (event->keyval == GDK_KEY_Escape ||
9645 event->keyval == GDK_KEY_Left ||
9646 event->keyval == GDK_KEY_KP_Left ||
9647 event->keyval == GDK_KEY_Right ||
9648 event->keyval == GDK_KEY_KP_Right)
9650 gboolean retval = TRUE;
9652 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9653 _gtk_entry_completion_popdown (completion);
9655 if (completion->priv->current_selected < 0)
9658 goto keypress_completion_out;
9660 else if (completion->priv->inline_selection)
9662 /* Escape rejects the tentative completion */
9663 if (event->keyval == GDK_KEY_Escape)
9665 if (completion->priv->completion_prefix)
9666 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9667 completion->priv->completion_prefix);
9669 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry), "");
9672 /* Move the cursor to the end for Right/Esc, to the
9673 beginning for Left */
9674 if (event->keyval == GDK_KEY_Right ||
9675 event->keyval == GDK_KEY_KP_Right ||
9676 event->keyval == GDK_KEY_Escape)
9677 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9679 gtk_editable_set_position (GTK_EDITABLE (widget), 0);
9682 keypress_completion_out:
9683 if (completion->priv->inline_selection)
9685 g_free (completion->priv->completion_prefix);
9686 completion->priv->completion_prefix = NULL;
9691 else if (event->keyval == GDK_KEY_Tab ||
9692 event->keyval == GDK_KEY_KP_Tab ||
9693 event->keyval == GDK_KEY_ISO_Left_Tab)
9695 GtkDirectionType dir = event->keyval == GDK_KEY_ISO_Left_Tab ?
9696 GTK_DIR_TAB_BACKWARD : GTK_DIR_TAB_FORWARD;
9698 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9699 _gtk_entry_completion_popdown (completion);
9701 g_free (completion->priv->completion_prefix);
9702 completion->priv->completion_prefix = NULL;
9704 gtk_widget_child_focus (gtk_widget_get_toplevel (widget), dir);
9708 else if (event->keyval == GDK_KEY_ISO_Enter ||
9709 event->keyval == GDK_KEY_KP_Enter ||
9710 event->keyval == GDK_KEY_Return)
9713 GtkTreeModel *model = NULL;
9714 GtkTreeModel *child_model;
9715 GtkTreeIter child_iter;
9716 GtkTreeSelection *sel;
9717 gboolean retval = TRUE;
9719 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9720 _gtk_entry_completion_popdown (completion);
9722 if (completion->priv->current_selected < matches)
9726 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view));
9727 if (gtk_tree_selection_get_selected (sel, &model, &iter))
9729 gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (model), &child_iter, &iter);
9730 child_model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model));
9731 g_signal_handler_block (widget, completion->priv->changed_id);
9732 g_signal_emit_by_name (completion, "match-selected",
9733 child_model, &child_iter, &entry_set);
9734 g_signal_handler_unblock (widget, completion->priv->changed_id);
9740 gtk_tree_model_get (model, &iter,
9741 completion->priv->text_column, &str,
9744 gtk_entry_set_text (GTK_ENTRY (widget), str);
9746 /* move the cursor to the end */
9747 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9755 else if (completion->priv->current_selected - matches >= 0)
9757 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view));
9758 if (gtk_tree_selection_get_selected (sel, &model, &iter))
9762 path = gtk_tree_path_new_from_indices (completion->priv->current_selected - matches, -1);
9763 g_signal_emit_by_name (completion, "action-activated",
9764 gtk_tree_path_get_indices (path)[0]);
9765 gtk_tree_path_free (path);
9771 g_free (completion->priv->completion_prefix);
9772 completion->priv->completion_prefix = NULL;
9781 gtk_entry_completion_changed (GtkWidget *widget,
9784 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
9785 GtkEntry *entry = GTK_ENTRY (widget);
9786 GtkEntryPrivate *priv = entry->priv;
9789 /* (re)install completion timeout */
9790 if (completion->priv->completion_timeout)
9791 g_source_remove (completion->priv->completion_timeout);
9793 if (!gtk_entry_get_text (entry))
9796 /* no need to normalize for this test */
9797 if (completion->priv->minimum_key_length > 0 &&
9798 strcmp ("", gtk_entry_get_text (entry)) == 0)
9800 if (gtk_widget_get_visible (completion->priv->popup_window))
9801 _gtk_entry_completion_popdown (completion);
9805 device = gtk_get_current_event_device ();
9807 if (device && gdk_device_get_source (device) == GDK_SOURCE_KEYBOARD)
9808 device = gdk_device_get_associated_device (device);
9811 priv->completion_device = device;
9813 completion->priv->completion_timeout =
9814 gdk_threads_add_timeout (COMPLETION_TIMEOUT,
9815 gtk_entry_completion_timeout,
9820 check_completion_callback (GtkEntryCompletion *completion)
9822 completion->priv->check_completion_idle = NULL;
9824 gtk_entry_completion_complete (completion);
9825 gtk_entry_completion_insert_prefix (completion);
9831 clear_completion_callback (GtkEntry *entry,
9834 if (pspec->name == I_("cursor-position") ||
9835 pspec->name == I_("selection-bound"))
9837 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
9839 completion->priv->has_completion = FALSE;
9844 accept_completion_callback (GtkEntry *entry)
9846 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
9848 if (completion->priv->has_completion)
9849 gtk_editable_set_position (GTK_EDITABLE (entry),
9850 gtk_entry_buffer_get_length (get_buffer (entry)));
9856 completion_insert_text_callback (GtkEntry *entry,
9860 GtkEntryCompletion *completion)
9862 /* idle to update the selection based on the file list */
9863 if (completion->priv->check_completion_idle == NULL)
9865 completion->priv->check_completion_idle = g_idle_source_new ();
9866 g_source_set_priority (completion->priv->check_completion_idle, G_PRIORITY_HIGH);
9867 g_source_set_closure (completion->priv->check_completion_idle,
9868 g_cclosure_new_object (G_CALLBACK (check_completion_callback),
9869 G_OBJECT (completion)));
9870 g_source_attach (completion->priv->check_completion_idle, NULL);
9875 completion_changed (GtkEntryCompletion *completion,
9879 GtkEntry *entry = GTK_ENTRY (data);
9881 if (pspec->name == I_("popup-completion") ||
9882 pspec->name == I_("inline-completion"))
9884 disconnect_completion_signals (entry, completion);
9885 connect_completion_signals (entry, completion);
9890 disconnect_completion_signals (GtkEntry *entry,
9891 GtkEntryCompletion *completion)
9893 g_signal_handlers_disconnect_by_func (completion,
9894 G_CALLBACK (completion_changed), entry);
9895 if (completion->priv->changed_id > 0 &&
9896 g_signal_handler_is_connected (entry, completion->priv->changed_id))
9898 g_signal_handler_disconnect (entry, completion->priv->changed_id);
9899 completion->priv->changed_id = 0;
9901 g_signal_handlers_disconnect_by_func (entry,
9902 G_CALLBACK (gtk_entry_completion_key_press), completion);
9903 if (completion->priv->insert_text_id > 0 &&
9904 g_signal_handler_is_connected (entry, completion->priv->insert_text_id))
9906 g_signal_handler_disconnect (entry, completion->priv->insert_text_id);
9907 completion->priv->insert_text_id = 0;
9909 g_signal_handlers_disconnect_by_func (entry,
9910 G_CALLBACK (completion_insert_text_callback), completion);
9911 g_signal_handlers_disconnect_by_func (entry,
9912 G_CALLBACK (clear_completion_callback), completion);
9913 g_signal_handlers_disconnect_by_func (entry,
9914 G_CALLBACK (accept_completion_callback), completion);
9918 connect_completion_signals (GtkEntry *entry,
9919 GtkEntryCompletion *completion)
9921 if (completion->priv->popup_completion)
9923 completion->priv->changed_id =
9924 g_signal_connect (entry, "changed",
9925 G_CALLBACK (gtk_entry_completion_changed), completion);
9926 g_signal_connect (entry, "key-press-event",
9927 G_CALLBACK (gtk_entry_completion_key_press), completion);
9930 if (completion->priv->inline_completion)
9932 completion->priv->insert_text_id =
9933 g_signal_connect (entry, "insert-text",
9934 G_CALLBACK (completion_insert_text_callback), completion);
9935 g_signal_connect (entry, "notify",
9936 G_CALLBACK (clear_completion_callback), completion);
9937 g_signal_connect (entry, "activate",
9938 G_CALLBACK (accept_completion_callback), completion);
9939 g_signal_connect (entry, "focus-out-event",
9940 G_CALLBACK (accept_completion_callback), completion);
9943 g_signal_connect (completion, "notify",
9944 G_CALLBACK (completion_changed), entry);
9948 * gtk_entry_set_completion:
9949 * @entry: A #GtkEntry
9950 * @completion: (allow-none): The #GtkEntryCompletion or %NULL
9952 * Sets @completion to be the auxiliary completion object to use with @entry.
9953 * All further configuration of the completion mechanism is done on
9954 * @completion using the #GtkEntryCompletion API. Completion is disabled if
9955 * @completion is set to %NULL.
9960 gtk_entry_set_completion (GtkEntry *entry,
9961 GtkEntryCompletion *completion)
9963 GtkEntryCompletion *old;
9965 g_return_if_fail (GTK_IS_ENTRY (entry));
9966 g_return_if_fail (!completion || GTK_IS_ENTRY_COMPLETION (completion));
9968 old = gtk_entry_get_completion (entry);
9970 if (old == completion)
9975 if (old->priv->completion_timeout)
9977 g_source_remove (old->priv->completion_timeout);
9978 old->priv->completion_timeout = 0;
9981 if (gtk_widget_get_mapped (old->priv->popup_window))
9982 _gtk_entry_completion_popdown (old);
9984 disconnect_completion_signals (entry, old);
9985 old->priv->entry = NULL;
9987 g_object_unref (old);
9992 g_object_set_data (G_OBJECT (entry), I_(GTK_ENTRY_COMPLETION_KEY), NULL);
9996 /* hook into the entry */
9997 g_object_ref (completion);
9999 connect_completion_signals (entry, completion);
10000 completion->priv->entry = GTK_WIDGET (entry);
10001 g_object_set_data (G_OBJECT (entry), I_(GTK_ENTRY_COMPLETION_KEY), completion);
10003 g_object_notify (G_OBJECT (entry), "completion");
10007 * gtk_entry_get_completion:
10008 * @entry: A #GtkEntry
10010 * Returns the auxiliary completion object currently in use by @entry.
10012 * Return value: (transfer none): The auxiliary completion object currently
10013 * in use by @entry.
10017 GtkEntryCompletion *
10018 gtk_entry_get_completion (GtkEntry *entry)
10020 GtkEntryCompletion *completion;
10022 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
10024 completion = GTK_ENTRY_COMPLETION (g_object_get_data (G_OBJECT (entry),
10025 GTK_ENTRY_COMPLETION_KEY));
10031 * gtk_entry_set_cursor_hadjustment:
10032 * @entry: a #GtkEntry
10033 * @adjustment: an adjustment which should be adjusted when the cursor
10034 * is moved, or %NULL
10036 * Hooks up an adjustment to the cursor position in an entry, so that when
10037 * the cursor is moved, the adjustment is scrolled to show that position.
10038 * See gtk_scrolled_window_get_hadjustment() for a typical way of obtaining
10041 * The adjustment has to be in pixel units and in the same coordinate system
10047 gtk_entry_set_cursor_hadjustment (GtkEntry *entry,
10048 GtkAdjustment *adjustment)
10050 g_return_if_fail (GTK_IS_ENTRY (entry));
10052 g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
10055 g_object_ref (adjustment);
10057 g_object_set_qdata_full (G_OBJECT (entry),
10058 quark_cursor_hadjustment,
10064 * gtk_entry_get_cursor_hadjustment:
10065 * @entry: a #GtkEntry
10067 * Retrieves the horizontal cursor adjustment for the entry.
10068 * See gtk_entry_set_cursor_hadjustment().
10070 * Return value: (transfer none): the horizontal cursor adjustment, or %NULL
10071 * if none has been set.
10076 gtk_entry_get_cursor_hadjustment (GtkEntry *entry)
10078 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
10080 return g_object_get_qdata (G_OBJECT (entry), quark_cursor_hadjustment);
10084 * gtk_entry_set_progress_fraction:
10085 * @entry: a #GtkEntry
10086 * @fraction: fraction of the task that's been completed
10088 * Causes the entry's progress indicator to "fill in" the given
10089 * fraction of the bar. The fraction should be between 0.0 and 1.0,
10095 gtk_entry_set_progress_fraction (GtkEntry *entry,
10099 GtkEntryPrivate *private;
10100 gdouble old_fraction;
10101 gint x, y, width, height;
10102 gint old_x, old_y, old_width, old_height;
10104 g_return_if_fail (GTK_IS_ENTRY (entry));
10106 widget = GTK_WIDGET (entry);
10107 private = entry->priv;
10109 if (private->progress_pulse_mode)
10112 old_fraction = private->progress_fraction;
10114 if (gtk_widget_is_drawable (widget))
10115 get_progress_area (widget, &old_x, &old_y, &old_width, &old_height);
10117 fraction = CLAMP (fraction, 0.0, 1.0);
10119 private->progress_fraction = fraction;
10120 private->progress_pulse_mode = FALSE;
10121 private->progress_pulse_current = 0.0;
10123 if (gtk_widget_is_drawable (widget))
10125 get_progress_area (widget, &x, &y, &width, &height);
10127 if ((x != old_x) || (y != old_y) || (width != old_width) || (height != old_height))
10128 gtk_widget_queue_draw (widget);
10131 if (fraction != old_fraction)
10132 g_object_notify (G_OBJECT (entry), "progress-fraction");
10136 * gtk_entry_get_progress_fraction:
10137 * @entry: a #GtkEntry
10139 * Returns the current fraction of the task that's been completed.
10140 * See gtk_entry_set_progress_fraction().
10142 * Return value: a fraction from 0.0 to 1.0
10147 gtk_entry_get_progress_fraction (GtkEntry *entry)
10149 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
10151 return entry->priv->progress_fraction;
10155 * gtk_entry_set_progress_pulse_step:
10156 * @entry: a #GtkEntry
10157 * @fraction: fraction between 0.0 and 1.0
10159 * Sets the fraction of total entry width to move the progress
10160 * bouncing block for each call to gtk_entry_progress_pulse().
10165 gtk_entry_set_progress_pulse_step (GtkEntry *entry,
10168 GtkEntryPrivate *private;
10170 g_return_if_fail (GTK_IS_ENTRY (entry));
10172 private = entry->priv;
10174 fraction = CLAMP (fraction, 0.0, 1.0);
10176 if (fraction != private->progress_pulse_fraction)
10178 private->progress_pulse_fraction = fraction;
10180 gtk_widget_queue_draw (GTK_WIDGET (entry));
10182 g_object_notify (G_OBJECT (entry), "progress-pulse-step");
10187 * gtk_entry_get_progress_pulse_step:
10188 * @entry: a #GtkEntry
10190 * Retrieves the pulse step set with gtk_entry_set_progress_pulse_step().
10192 * Return value: a fraction from 0.0 to 1.0
10197 gtk_entry_get_progress_pulse_step (GtkEntry *entry)
10199 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
10201 return entry->priv->progress_pulse_fraction;
10205 * gtk_entry_progress_pulse:
10206 * @entry: a #GtkEntry
10208 * Indicates that some progress is made, but you don't know how much.
10209 * Causes the entry's progress indicator to enter "activity mode,"
10210 * where a block bounces back and forth. Each call to
10211 * gtk_entry_progress_pulse() causes the block to move by a little bit
10212 * (the amount of movement per pulse is determined by
10213 * gtk_entry_set_progress_pulse_step()).
10218 gtk_entry_progress_pulse (GtkEntry *entry)
10220 GtkEntryPrivate *private;
10222 g_return_if_fail (GTK_IS_ENTRY (entry));
10224 private = entry->priv;
10226 if (private->progress_pulse_mode)
10228 if (private->progress_pulse_way_back)
10230 private->progress_pulse_current -= private->progress_pulse_fraction;
10232 if (private->progress_pulse_current < 0.0)
10234 private->progress_pulse_current = 0.0;
10235 private->progress_pulse_way_back = FALSE;
10240 private->progress_pulse_current += private->progress_pulse_fraction;
10242 if (private->progress_pulse_current > 1.0 - private->progress_pulse_fraction)
10244 private->progress_pulse_current = 1.0 - private->progress_pulse_fraction;
10245 private->progress_pulse_way_back = TRUE;
10251 private->progress_fraction = 0.0;
10252 private->progress_pulse_mode = TRUE;
10253 private->progress_pulse_way_back = FALSE;
10254 private->progress_pulse_current = 0.0;
10257 gtk_widget_queue_draw (GTK_WIDGET (entry));
10261 * gtk_entry_set_placeholder_text:
10262 * @entry: a #GtkEntry
10263 * @text: a string to be displayed when @entry is empty an unfocused, or %NULL
10265 * Sets text to be displayed in @entry when
10266 * it is empty and unfocused. This can be used to give a visual hint
10267 * of the expected contents of the #GtkEntry.
10272 gtk_entry_set_placeholder_text (GtkEntry *entry,
10275 GtkEntryPrivate *priv;
10277 g_return_if_fail (GTK_IS_ENTRY (entry));
10279 priv = entry->priv;
10281 if (g_strcmp0 (priv->placeholder_text, text) == 0)
10284 g_free (priv->placeholder_text);
10285 priv->placeholder_text = g_strdup (text);
10287 gtk_entry_recompute (entry);
10289 g_object_notify (G_OBJECT (entry), "placeholder-text");
10293 * gtk_entry_get_placeholder_text:
10294 * @entry: a #GtkEntry
10296 * Retrieves the text that will be displayed when @entry is empty and unfocused
10298 * Returns: a pointer to the placeholder text as a string. This string points to internally allocated
10299 * storage in the widget and must not be freed, modified or stored.
10303 G_CONST_RETURN gchar *
10304 gtk_entry_get_placeholder_text (GtkEntry *entry)
10306 GtkEntryPrivate *priv;
10308 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
10310 priv = entry->priv;
10312 return priv->placeholder_text;
10315 /* Caps Lock warning for password entries */
10318 show_capslock_feedback (GtkEntry *entry,
10321 GtkEntryPrivate *priv = entry->priv;
10323 if (gtk_entry_get_icon_storage_type (entry, GTK_ENTRY_ICON_SECONDARY) == GTK_IMAGE_EMPTY)
10325 gtk_entry_set_icon_from_stock (entry, GTK_ENTRY_ICON_SECONDARY, GTK_STOCK_CAPS_LOCK_WARNING);
10326 gtk_entry_set_icon_activatable (entry, GTK_ENTRY_ICON_SECONDARY, FALSE);
10327 priv->caps_lock_warning_shown = TRUE;
10330 if (priv->caps_lock_warning_shown)
10331 gtk_entry_set_icon_tooltip_text (entry, GTK_ENTRY_ICON_SECONDARY, text);
10333 g_warning ("Can't show Caps Lock warning, since secondary icon is set");
10337 remove_capslock_feedback (GtkEntry *entry)
10339 GtkEntryPrivate *priv = entry->priv;
10341 if (priv->caps_lock_warning_shown)
10343 gtk_entry_set_icon_from_stock (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
10344 priv->caps_lock_warning_shown = FALSE;
10349 keymap_state_changed (GdkKeymap *keymap,
10352 GtkEntryPrivate *priv = entry->priv;
10355 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL && priv->caps_lock_warning)
10357 if (gdk_keymap_get_num_lock_state (keymap)
10358 && gdk_keymap_get_caps_lock_state (keymap))
10359 text = _("Caps Lock and Num Lock are on");
10360 else if (gdk_keymap_get_num_lock_state (keymap))
10361 text = _("Num Lock is on");
10362 else if (gdk_keymap_get_caps_lock_state (keymap))
10363 text = _("Caps Lock is on");
10367 show_capslock_feedback (entry, text);
10369 remove_capslock_feedback (entry);
10373 * _gtk_entry_set_is_cell_renderer:
10374 * @entry: a #GtkEntry
10375 * @is_cell_renderer: new value
10377 * This is a helper function for GtkComboBox. A GtkEntry in a GtkComboBox
10378 * is supposed to behave like a GtkCellEditable when placed in a combo box.
10380 * I.e take up its allocation and get GtkEntry->is_cell_renderer = TRUE.
10384 _gtk_entry_set_is_cell_renderer (GtkEntry *entry,
10385 gboolean is_cell_renderer)
10387 entry->priv->is_cell_renderer = is_cell_renderer;