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, see <http://www.gnu.org/licenses/>.
23 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
24 * file for a list of people on the GTK+ Team. See the ChangeLog
25 * files for a list of changes. These files are distributed with
26 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
34 #include "gtkbindings.h"
35 #include "gtkcelleditable.h"
36 #include "gtkclipboard.h"
39 #include "gtkentrybuffer.h"
40 #include "gtkiconhelperprivate.h"
41 #include "gtkimagemenuitem.h"
42 #include "gtkimcontextsimple.h"
43 #include "gtkimmulticontext.h"
47 #include "gtkmarshalers.h"
49 #include "gtkmenuitem.h"
50 #include "gtkseparatormenuitem.h"
51 #include "gtkselection.h"
52 #include "gtksettings.h"
53 #include "gtkspinbutton.h"
55 #include "gtktextutil.h"
56 #include "gtkwindow.h"
57 #include "gtktreeview.h"
58 #include "gtktreeselection.h"
59 #include "gtktypebuiltins.h"
60 #include "gtkprivate.h"
61 #include "gtkentryprivate.h"
62 #include "gtkcelllayout.h"
63 #include "gtktooltip.h"
64 #include "gtkiconfactory.h"
65 #include "gtkicontheme.h"
66 #include "gtkwidgetprivate.h"
67 #include "gtkstylecontextprivate.h"
69 #include "a11y/gtkentryaccessible.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
125 #define IS_VALID_ICON_POSITION(pos) \
126 ((pos) == GTK_ENTRY_ICON_PRIMARY || \
127 (pos) == GTK_ENTRY_ICON_SECONDARY)
129 static const GtkBorder default_inner_border = { 2, 2, 2, 2 };
130 static GQuark quark_inner_border = 0;
131 static GQuark quark_password_hint = 0;
132 static GQuark quark_cursor_hadjustment = 0;
133 static GQuark quark_capslock_feedback = 0;
135 typedef struct _EntryIconInfo EntryIconInfo;
136 typedef struct _GtkEntryPasswordHint GtkEntryPasswordHint;
137 typedef struct _GtkEntryCapslockFeedback GtkEntryCapslockFeedback;
139 struct _GtkEntryPrivate
141 EntryIconInfo *icons[MAX_ICONS];
143 GtkEntryBuffer *buffer;
144 GtkIMContext *im_context;
145 GtkShadowType shadow_type;
146 GtkWidget *popup_menu;
150 GdkDevice *completion_device;
151 GdkWindow *text_area;
153 PangoLayout *cached_layout;
157 gdouble progress_fraction;
158 gdouble progress_pulse_fraction;
159 gdouble progress_pulse_current;
161 gchar *placeholder_text;
165 gint ascent; /* font ascent in pango units */
167 gint descent; /* font descent in pango units */
168 gint dnd_position; /* In chars, -1 == no DND cursor */
173 gint selection_bound;
179 gunichar invisible_char;
182 guint blink_time; /* time in msec the cursor has blinked since last user event */
184 guint recompute_idle;
186 guint16 x_text_size; /* allocated size, in bytes */
187 guint16 x_n_bytes; /* length in use, in bytes */
189 guint16 preedit_length; /* length of preedit string, in bytes */
190 guint16 preedit_cursor; /* offset of cursor within preedit string, in chars */
194 guint overwrite_mode : 1;
197 guint activates_default : 1;
198 guint cache_includes_preedit : 1;
199 guint caps_lock_warning : 1;
200 guint caps_lock_warning_shown : 1;
201 guint change_count : 8;
202 guint cursor_visible : 1;
203 guint editing_canceled : 1; /* Only used by GtkCellRendererText */
205 guint in_click : 1; /* Flag so we don't select all when clicking in entry to focus in */
206 guint is_cell_renderer : 1;
207 guint invisible_char_set : 1;
208 guint interior_focus : 1;
209 guint mouse_cursor_obscured : 1;
210 guint need_im_reset : 1;
211 guint progress_pulse_mode : 1;
212 guint progress_pulse_way_back : 1;
213 guint real_changed : 1;
214 guint resolved_dir : 4; /* PangoDirection */
215 guint select_words : 1;
216 guint select_lines : 1;
217 guint truncate_multiline : 1;
220 struct _EntryIconInfo
224 guint insensitive : 1;
225 guint nonactivatable : 1;
230 GtkIconHelper *icon_helper;
232 GtkTargetList *target_list;
233 GdkDragAction actions;
236 struct _GtkEntryPasswordHint
238 gint position; /* Position (in text) of the last password hint */
239 guint source_id; /* Timeout source id */
242 struct _GtkEntryCapslockFeedback
269 PROP_CURSOR_POSITION,
270 PROP_SELECTION_BOUND,
277 PROP_ACTIVATES_DEFAULT,
282 PROP_TRUNCATE_MULTILINE,
286 PROP_INVISIBLE_CHAR_SET,
287 PROP_CAPS_LOCK_WARNING,
288 PROP_PROGRESS_FRACTION,
289 PROP_PROGRESS_PULSE_STEP,
291 PROP_PIXBUF_SECONDARY,
293 PROP_STOCK_SECONDARY,
294 PROP_ICON_NAME_PRIMARY,
295 PROP_ICON_NAME_SECONDARY,
297 PROP_GICON_SECONDARY,
298 PROP_STORAGE_TYPE_PRIMARY,
299 PROP_STORAGE_TYPE_SECONDARY,
300 PROP_ACTIVATABLE_PRIMARY,
301 PROP_ACTIVATABLE_SECONDARY,
302 PROP_SENSITIVE_PRIMARY,
303 PROP_SENSITIVE_SECONDARY,
304 PROP_TOOLTIP_TEXT_PRIMARY,
305 PROP_TOOLTIP_TEXT_SECONDARY,
306 PROP_TOOLTIP_MARKUP_PRIMARY,
307 PROP_TOOLTIP_MARKUP_SECONDARY,
309 PROP_EDITING_CANCELED,
310 PROP_PLACEHOLDER_TEXT,
314 static guint signals[LAST_SIGNAL] = { 0 };
323 DISPLAY_NORMAL, /* The entry text is being shown */
324 DISPLAY_INVISIBLE, /* In invisible mode, text replaced by (eg) bullets */
325 DISPLAY_BLANK /* In invisible mode, nothing shown at all */
330 static void gtk_entry_editable_init (GtkEditableInterface *iface);
331 static void gtk_entry_cell_editable_init (GtkCellEditableIface *iface);
332 static void gtk_entry_set_property (GObject *object,
336 static void gtk_entry_get_property (GObject *object,
340 static void gtk_entry_finalize (GObject *object);
341 static void gtk_entry_dispose (GObject *object);
345 static void gtk_entry_destroy (GtkWidget *widget);
346 static void gtk_entry_realize (GtkWidget *widget);
347 static void gtk_entry_unrealize (GtkWidget *widget);
348 static void gtk_entry_map (GtkWidget *widget);
349 static void gtk_entry_unmap (GtkWidget *widget);
350 static void gtk_entry_get_preferred_width (GtkWidget *widget,
353 static void gtk_entry_get_preferred_height (GtkWidget *widget,
356 static void gtk_entry_size_allocate (GtkWidget *widget,
357 GtkAllocation *allocation);
358 static void gtk_entry_draw_frame (GtkWidget *widget,
359 GtkStyleContext *context,
361 static void gtk_entry_draw_progress (GtkWidget *widget,
362 GtkStyleContext *context,
364 static gint gtk_entry_draw (GtkWidget *widget,
366 static gint gtk_entry_button_press (GtkWidget *widget,
367 GdkEventButton *event);
368 static gint gtk_entry_button_release (GtkWidget *widget,
369 GdkEventButton *event);
370 static gint gtk_entry_enter_notify (GtkWidget *widget,
371 GdkEventCrossing *event);
372 static gint gtk_entry_leave_notify (GtkWidget *widget,
373 GdkEventCrossing *event);
374 static gint gtk_entry_motion_notify (GtkWidget *widget,
375 GdkEventMotion *event);
376 static gint gtk_entry_key_press (GtkWidget *widget,
378 static gint gtk_entry_key_release (GtkWidget *widget,
380 static gint gtk_entry_focus_in (GtkWidget *widget,
381 GdkEventFocus *event);
382 static gint gtk_entry_focus_out (GtkWidget *widget,
383 GdkEventFocus *event);
384 static void gtk_entry_grab_focus (GtkWidget *widget);
385 static void gtk_entry_style_updated (GtkWidget *widget);
386 static gboolean gtk_entry_query_tooltip (GtkWidget *widget,
389 gboolean keyboard_tip,
390 GtkTooltip *tooltip);
391 static void gtk_entry_direction_changed (GtkWidget *widget,
392 GtkTextDirection previous_dir);
393 static void gtk_entry_state_flags_changed (GtkWidget *widget,
394 GtkStateFlags previous_state);
395 static void gtk_entry_screen_changed (GtkWidget *widget,
396 GdkScreen *old_screen);
398 static gboolean gtk_entry_drag_drop (GtkWidget *widget,
399 GdkDragContext *context,
403 static gboolean gtk_entry_drag_motion (GtkWidget *widget,
404 GdkDragContext *context,
408 static void gtk_entry_drag_leave (GtkWidget *widget,
409 GdkDragContext *context,
411 static void gtk_entry_drag_data_received (GtkWidget *widget,
412 GdkDragContext *context,
415 GtkSelectionData *selection_data,
418 static void gtk_entry_drag_data_get (GtkWidget *widget,
419 GdkDragContext *context,
420 GtkSelectionData *selection_data,
423 static void gtk_entry_drag_data_delete (GtkWidget *widget,
424 GdkDragContext *context);
425 static void gtk_entry_drag_begin (GtkWidget *widget,
426 GdkDragContext *context);
427 static void gtk_entry_drag_end (GtkWidget *widget,
428 GdkDragContext *context);
431 /* GtkEditable method implementations
433 static void gtk_entry_insert_text (GtkEditable *editable,
434 const gchar *new_text,
435 gint new_text_length,
437 static void gtk_entry_delete_text (GtkEditable *editable,
440 static gchar * gtk_entry_get_chars (GtkEditable *editable,
443 static void gtk_entry_real_set_position (GtkEditable *editable,
445 static gint gtk_entry_get_position (GtkEditable *editable);
446 static void gtk_entry_set_selection_bounds (GtkEditable *editable,
449 static gboolean gtk_entry_get_selection_bounds (GtkEditable *editable,
453 /* GtkCellEditable method implementations
455 static void gtk_entry_start_editing (GtkCellEditable *cell_editable,
458 /* Default signal handlers
460 static void gtk_entry_real_insert_text (GtkEditable *editable,
461 const gchar *new_text,
462 gint new_text_length,
464 static void gtk_entry_real_delete_text (GtkEditable *editable,
467 static void gtk_entry_move_cursor (GtkEntry *entry,
468 GtkMovementStep step,
470 gboolean extend_selection);
471 static void gtk_entry_insert_at_cursor (GtkEntry *entry,
473 static void gtk_entry_delete_from_cursor (GtkEntry *entry,
476 static void gtk_entry_backspace (GtkEntry *entry);
477 static void gtk_entry_cut_clipboard (GtkEntry *entry);
478 static void gtk_entry_copy_clipboard (GtkEntry *entry);
479 static void gtk_entry_paste_clipboard (GtkEntry *entry);
480 static void gtk_entry_toggle_overwrite (GtkEntry *entry);
481 static void gtk_entry_select_all (GtkEntry *entry);
482 static void gtk_entry_real_activate (GtkEntry *entry);
483 static gboolean gtk_entry_popup_menu (GtkWidget *widget);
485 static void keymap_direction_changed (GdkKeymap *keymap,
487 static void keymap_state_changed (GdkKeymap *keymap,
489 static void remove_capslock_feedback (GtkEntry *entry);
491 /* IM Context Callbacks
493 static void gtk_entry_commit_cb (GtkIMContext *context,
496 static void gtk_entry_preedit_changed_cb (GtkIMContext *context,
498 static gboolean gtk_entry_retrieve_surrounding_cb (GtkIMContext *context,
500 static gboolean gtk_entry_delete_surrounding_cb (GtkIMContext *context,
507 static void gtk_entry_enter_text (GtkEntry *entry,
509 static void gtk_entry_set_positions (GtkEntry *entry,
511 gint selection_bound);
512 static void gtk_entry_draw_text (GtkEntry *entry,
514 static void gtk_entry_draw_cursor (GtkEntry *entry,
517 static PangoLayout *gtk_entry_ensure_layout (GtkEntry *entry,
518 gboolean include_preedit);
519 static void gtk_entry_reset_layout (GtkEntry *entry);
520 static void gtk_entry_recompute (GtkEntry *entry);
521 static gint gtk_entry_find_position (GtkEntry *entry,
523 static void gtk_entry_get_cursor_locations (GtkEntry *entry,
527 static void gtk_entry_adjust_scroll (GtkEntry *entry);
528 static gint gtk_entry_move_visually (GtkEntry *editable,
531 static gint gtk_entry_move_logically (GtkEntry *entry,
534 static gint gtk_entry_move_forward_word (GtkEntry *entry,
536 gboolean allow_whitespace);
537 static gint gtk_entry_move_backward_word (GtkEntry *entry,
539 gboolean allow_whitespace);
540 static void gtk_entry_delete_whitespace (GtkEntry *entry);
541 static void gtk_entry_select_word (GtkEntry *entry);
542 static void gtk_entry_select_line (GtkEntry *entry);
543 static void gtk_entry_paste (GtkEntry *entry,
545 static void gtk_entry_update_primary_selection (GtkEntry *entry);
546 static void gtk_entry_do_popup (GtkEntry *entry,
547 GdkEventButton *event);
548 static gboolean gtk_entry_mnemonic_activate (GtkWidget *widget,
549 gboolean group_cycling);
550 static void gtk_entry_grab_notify (GtkWidget *widget,
551 gboolean was_grabbed);
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 GdkPixbuf * gtk_entry_ensure_pixbuf (GtkEntry *entry,
573 GtkEntryIconPosition icon_pos);
574 static void gtk_entry_update_cached_style_values(GtkEntry *entry);
575 static gboolean get_middle_click_paste (GtkEntry *entry);
578 static gint gtk_entry_completion_timeout (gpointer data);
579 static gboolean gtk_entry_completion_key_press (GtkWidget *widget,
582 static void gtk_entry_completion_changed (GtkWidget *entry,
584 static gboolean check_completion_callback (GtkEntryCompletion *completion);
585 static void clear_completion_callback (GtkEntry *entry,
587 static gboolean accept_completion_callback (GtkEntry *entry);
588 static void completion_insert_text_callback (GtkEntry *entry,
592 GtkEntryCompletion *completion);
593 static void completion_changed (GtkEntryCompletion *completion,
596 static void disconnect_completion_signals (GtkEntry *entry,
597 GtkEntryCompletion *completion);
598 static void connect_completion_signals (GtkEntry *entry,
599 GtkEntryCompletion *completion);
601 static void begin_change (GtkEntry *entry);
602 static void end_change (GtkEntry *entry);
603 static void emit_changed (GtkEntry *entry);
605 static void buffer_inserted_text (GtkEntryBuffer *buffer,
610 static void buffer_deleted_text (GtkEntryBuffer *buffer,
614 static void buffer_notify_text (GtkEntryBuffer *buffer,
617 static void buffer_notify_length (GtkEntryBuffer *buffer,
620 static void buffer_notify_max_length (GtkEntryBuffer *buffer,
623 static void buffer_connect_signals (GtkEntry *entry);
624 static void buffer_disconnect_signals (GtkEntry *entry);
625 static GtkEntryBuffer *get_buffer (GtkEntry *entry);
627 G_DEFINE_TYPE_WITH_CODE (GtkEntry, gtk_entry, GTK_TYPE_WIDGET,
628 G_IMPLEMENT_INTERFACE (GTK_TYPE_EDITABLE,
629 gtk_entry_editable_init)
630 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_EDITABLE,
631 gtk_entry_cell_editable_init))
634 add_move_binding (GtkBindingSet *binding_set,
637 GtkMovementStep step,
640 g_return_if_fail ((modmask & GDK_SHIFT_MASK) == 0);
642 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
646 G_TYPE_BOOLEAN, FALSE);
648 /* Selection-extending version */
649 gtk_binding_entry_add_signal (binding_set, keyval, modmask | GDK_SHIFT_MASK,
653 G_TYPE_BOOLEAN, TRUE);
657 gtk_entry_class_init (GtkEntryClass *class)
659 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
660 GtkWidgetClass *widget_class;
661 GtkBindingSet *binding_set;
663 widget_class = (GtkWidgetClass*) class;
665 gobject_class->dispose = gtk_entry_dispose;
666 gobject_class->finalize = gtk_entry_finalize;
667 gobject_class->set_property = gtk_entry_set_property;
668 gobject_class->get_property = gtk_entry_get_property;
670 widget_class->destroy = gtk_entry_destroy;
671 widget_class->map = gtk_entry_map;
672 widget_class->unmap = gtk_entry_unmap;
673 widget_class->realize = gtk_entry_realize;
674 widget_class->unrealize = gtk_entry_unrealize;
675 widget_class->get_preferred_width = gtk_entry_get_preferred_width;
676 widget_class->get_preferred_height = gtk_entry_get_preferred_height;
677 widget_class->size_allocate = gtk_entry_size_allocate;
678 widget_class->draw = gtk_entry_draw;
679 widget_class->enter_notify_event = gtk_entry_enter_notify;
680 widget_class->leave_notify_event = gtk_entry_leave_notify;
681 widget_class->button_press_event = gtk_entry_button_press;
682 widget_class->button_release_event = gtk_entry_button_release;
683 widget_class->motion_notify_event = gtk_entry_motion_notify;
684 widget_class->key_press_event = gtk_entry_key_press;
685 widget_class->key_release_event = gtk_entry_key_release;
686 widget_class->focus_in_event = gtk_entry_focus_in;
687 widget_class->focus_out_event = gtk_entry_focus_out;
688 widget_class->grab_focus = gtk_entry_grab_focus;
689 widget_class->style_updated = gtk_entry_style_updated;
690 widget_class->query_tooltip = gtk_entry_query_tooltip;
691 widget_class->drag_begin = gtk_entry_drag_begin;
692 widget_class->drag_end = gtk_entry_drag_end;
693 widget_class->direction_changed = gtk_entry_direction_changed;
694 widget_class->state_flags_changed = gtk_entry_state_flags_changed;
695 widget_class->screen_changed = gtk_entry_screen_changed;
696 widget_class->mnemonic_activate = gtk_entry_mnemonic_activate;
697 widget_class->grab_notify = gtk_entry_grab_notify;
699 widget_class->drag_drop = gtk_entry_drag_drop;
700 widget_class->drag_motion = gtk_entry_drag_motion;
701 widget_class->drag_leave = gtk_entry_drag_leave;
702 widget_class->drag_data_received = gtk_entry_drag_data_received;
703 widget_class->drag_data_get = gtk_entry_drag_data_get;
704 widget_class->drag_data_delete = gtk_entry_drag_data_delete;
706 widget_class->popup_menu = gtk_entry_popup_menu;
708 class->move_cursor = gtk_entry_move_cursor;
709 class->insert_at_cursor = gtk_entry_insert_at_cursor;
710 class->delete_from_cursor = gtk_entry_delete_from_cursor;
711 class->backspace = gtk_entry_backspace;
712 class->cut_clipboard = gtk_entry_cut_clipboard;
713 class->copy_clipboard = gtk_entry_copy_clipboard;
714 class->paste_clipboard = gtk_entry_paste_clipboard;
715 class->toggle_overwrite = gtk_entry_toggle_overwrite;
716 class->activate = gtk_entry_real_activate;
717 class->get_text_area_size = gtk_entry_get_text_area_size;
719 quark_inner_border = g_quark_from_static_string ("gtk-entry-inner-border");
720 quark_password_hint = g_quark_from_static_string ("gtk-entry-password-hint");
721 quark_cursor_hadjustment = g_quark_from_static_string ("gtk-hadjustment");
722 quark_capslock_feedback = g_quark_from_static_string ("gtk-entry-capslock-feedback");
724 g_object_class_override_property (gobject_class,
725 PROP_EDITING_CANCELED,
728 g_object_class_install_property (gobject_class,
730 g_param_spec_object ("buffer",
732 P_("Text buffer object which actually stores entry text"),
733 GTK_TYPE_ENTRY_BUFFER,
734 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT));
736 g_object_class_install_property (gobject_class,
737 PROP_CURSOR_POSITION,
738 g_param_spec_int ("cursor-position",
739 P_("Cursor Position"),
740 P_("The current position of the insertion cursor in chars"),
742 GTK_ENTRY_BUFFER_MAX_SIZE,
744 GTK_PARAM_READABLE));
746 g_object_class_install_property (gobject_class,
747 PROP_SELECTION_BOUND,
748 g_param_spec_int ("selection-bound",
749 P_("Selection Bound"),
750 P_("The position of the opposite end of the selection from the cursor in chars"),
752 GTK_ENTRY_BUFFER_MAX_SIZE,
754 GTK_PARAM_READABLE));
756 g_object_class_install_property (gobject_class,
758 g_param_spec_boolean ("editable",
760 P_("Whether the entry contents can be edited"),
762 GTK_PARAM_READWRITE));
764 g_object_class_install_property (gobject_class,
766 g_param_spec_int ("max-length",
767 P_("Maximum length"),
768 P_("Maximum number of characters for this entry. Zero if no maximum"),
770 GTK_ENTRY_BUFFER_MAX_SIZE,
772 GTK_PARAM_READWRITE));
773 g_object_class_install_property (gobject_class,
775 g_param_spec_boolean ("visibility",
777 P_("FALSE displays the \"invisible char\" instead of the actual text (password mode)"),
779 GTK_PARAM_READWRITE));
781 g_object_class_install_property (gobject_class,
783 g_param_spec_boolean ("has-frame",
785 P_("FALSE removes outside bevel from entry"),
787 GTK_PARAM_READWRITE));
790 * GtkEntry:inner-border:
792 * Sets the text area's border between the text and the frame.
794 * Deprecated: 3.4: Use the standard border and padding CSS properties
795 * (through objects like #GtkStyleContext and #GtkCssProvider); the value
796 * of this style property is ignored.
798 g_object_class_install_property (gobject_class,
800 g_param_spec_boxed ("inner-border",
802 P_("Border between text and frame. Overrides the inner-border style property"),
804 GTK_PARAM_READWRITE |
805 G_PARAM_DEPRECATED));
807 g_object_class_install_property (gobject_class,
809 g_param_spec_unichar ("invisible-char",
810 P_("Invisible character"),
811 P_("The character to use when masking entry contents (in \"password mode\")"),
813 GTK_PARAM_READWRITE));
815 g_object_class_install_property (gobject_class,
816 PROP_ACTIVATES_DEFAULT,
817 g_param_spec_boolean ("activates-default",
818 P_("Activates default"),
819 P_("Whether to activate the default widget (such as the default button in a dialog) when Enter is pressed"),
821 GTK_PARAM_READWRITE));
822 g_object_class_install_property (gobject_class,
824 g_param_spec_int ("width-chars",
825 P_("Width in chars"),
826 P_("Number of characters to leave space for in the entry"),
830 GTK_PARAM_READWRITE));
832 g_object_class_install_property (gobject_class,
834 g_param_spec_int ("scroll-offset",
836 P_("Number of pixels of the entry scrolled off the screen to the left"),
840 GTK_PARAM_READABLE));
842 g_object_class_install_property (gobject_class,
844 g_param_spec_string ("text",
846 P_("The contents of the entry"),
848 GTK_PARAM_READWRITE));
853 * The horizontal alignment, from 0 (left) to 1 (right).
854 * Reversed for RTL layouts.
858 g_object_class_install_property (gobject_class,
860 g_param_spec_float ("xalign",
862 P_("The horizontal alignment, from 0 (left) to 1 (right). Reversed for RTL layouts."),
866 GTK_PARAM_READWRITE));
869 * GtkEntry:truncate-multiline:
871 * When %TRUE, pasted multi-line text is truncated to the first line.
875 g_object_class_install_property (gobject_class,
876 PROP_TRUNCATE_MULTILINE,
877 g_param_spec_boolean ("truncate-multiline",
878 P_("Truncate multiline"),
879 P_("Whether to truncate multiline pastes to one line."),
881 GTK_PARAM_READWRITE));
884 * GtkEntry:shadow-type:
886 * Which kind of shadow to draw around the entry when
887 * #GtkEntry:has-frame is set to %TRUE.
891 g_object_class_install_property (gobject_class,
893 g_param_spec_enum ("shadow-type",
895 P_("Which kind of shadow to draw around the entry when has-frame is set"),
896 GTK_TYPE_SHADOW_TYPE,
898 GTK_PARAM_READWRITE));
901 * GtkEntry:overwrite-mode:
903 * If text is overwritten when typing in the #GtkEntry.
907 g_object_class_install_property (gobject_class,
909 g_param_spec_boolean ("overwrite-mode",
910 P_("Overwrite mode"),
911 P_("Whether new text overwrites existing text"),
913 GTK_PARAM_READWRITE));
916 * GtkEntry:text-length:
918 * The length of the text in the #GtkEntry.
922 g_object_class_install_property (gobject_class,
924 g_param_spec_uint ("text-length",
926 P_("Length of the text currently in the entry"),
930 GTK_PARAM_READABLE));
932 * GtkEntry:invisible-char-set:
934 * Whether the invisible char has been set for the #GtkEntry.
938 g_object_class_install_property (gobject_class,
939 PROP_INVISIBLE_CHAR_SET,
940 g_param_spec_boolean ("invisible-char-set",
941 P_("Invisible character set"),
942 P_("Whether the invisible character has been set"),
944 GTK_PARAM_READWRITE));
947 * GtkEntry:caps-lock-warning:
949 * Whether password entries will show a warning when Caps Lock is on.
951 * Note that the warning is shown using a secondary icon, and thus
952 * does not work if you are using the secondary icon position for some
957 g_object_class_install_property (gobject_class,
958 PROP_CAPS_LOCK_WARNING,
959 g_param_spec_boolean ("caps-lock-warning",
960 P_("Caps Lock warning"),
961 P_("Whether password entries will show a warning when Caps Lock is on"),
963 GTK_PARAM_READWRITE));
966 * GtkEntry:progress-fraction:
968 * The current fraction of the task that's been completed.
972 g_object_class_install_property (gobject_class,
973 PROP_PROGRESS_FRACTION,
974 g_param_spec_double ("progress-fraction",
975 P_("Progress Fraction"),
976 P_("The current fraction of the task that's been completed"),
980 GTK_PARAM_READWRITE));
983 * GtkEntry:progress-pulse-step:
985 * The fraction of total entry width to move the progress
986 * bouncing block for each call to gtk_entry_progress_pulse().
990 g_object_class_install_property (gobject_class,
991 PROP_PROGRESS_PULSE_STEP,
992 g_param_spec_double ("progress-pulse-step",
993 P_("Progress Pulse Step"),
994 P_("The fraction of total entry width to move the progress bouncing block for each call to gtk_entry_progress_pulse()"),
998 GTK_PARAM_READWRITE));
1001 * GtkEntry:placeholder-text:
1003 * The text that will be displayed in the #GtkEntry when it is empty
1008 g_object_class_install_property (gobject_class,
1009 PROP_PLACEHOLDER_TEXT,
1010 g_param_spec_string ("placeholder-text",
1011 P_("Placeholder text"),
1012 P_("Show text in the entry when it's empty and unfocused"),
1014 GTK_PARAM_READWRITE));
1017 * GtkEntry:primary-icon-pixbuf:
1019 * A pixbuf to use as the primary icon for the entry.
1023 g_object_class_install_property (gobject_class,
1024 PROP_PIXBUF_PRIMARY,
1025 g_param_spec_object ("primary-icon-pixbuf",
1026 P_("Primary pixbuf"),
1027 P_("Primary pixbuf for the entry"),
1029 GTK_PARAM_READWRITE));
1032 * GtkEntry:secondary-icon-pixbuf:
1034 * An pixbuf to use as the secondary icon for the entry.
1038 g_object_class_install_property (gobject_class,
1039 PROP_PIXBUF_SECONDARY,
1040 g_param_spec_object ("secondary-icon-pixbuf",
1041 P_("Secondary pixbuf"),
1042 P_("Secondary pixbuf for the entry"),
1044 GTK_PARAM_READWRITE));
1047 * GtkEntry:primary-icon-stock:
1049 * The stock id to use for the primary icon for the entry.
1053 g_object_class_install_property (gobject_class,
1055 g_param_spec_string ("primary-icon-stock",
1056 P_("Primary stock ID"),
1057 P_("Stock ID for primary icon"),
1059 GTK_PARAM_READWRITE));
1062 * GtkEntry:secondary-icon-stock:
1064 * The stock id to use for the secondary icon for the entry.
1068 g_object_class_install_property (gobject_class,
1069 PROP_STOCK_SECONDARY,
1070 g_param_spec_string ("secondary-icon-stock",
1071 P_("Secondary stock ID"),
1072 P_("Stock ID for secondary icon"),
1074 GTK_PARAM_READWRITE));
1077 * GtkEntry:primary-icon-name:
1079 * The icon name to use for the primary icon for the entry.
1083 g_object_class_install_property (gobject_class,
1084 PROP_ICON_NAME_PRIMARY,
1085 g_param_spec_string ("primary-icon-name",
1086 P_("Primary icon name"),
1087 P_("Icon name for primary icon"),
1089 GTK_PARAM_READWRITE));
1092 * GtkEntry:secondary-icon-name:
1094 * The icon name to use for the secondary icon for the entry.
1098 g_object_class_install_property (gobject_class,
1099 PROP_ICON_NAME_SECONDARY,
1100 g_param_spec_string ("secondary-icon-name",
1101 P_("Secondary icon name"),
1102 P_("Icon name for secondary icon"),
1104 GTK_PARAM_READWRITE));
1107 * GtkEntry:primary-icon-gicon:
1109 * The #GIcon to use for the primary icon for the entry.
1113 g_object_class_install_property (gobject_class,
1115 g_param_spec_object ("primary-icon-gicon",
1116 P_("Primary GIcon"),
1117 P_("GIcon for primary icon"),
1119 GTK_PARAM_READWRITE));
1122 * GtkEntry:secondary-icon-gicon:
1124 * The #GIcon to use for the secondary icon for the entry.
1128 g_object_class_install_property (gobject_class,
1129 PROP_GICON_SECONDARY,
1130 g_param_spec_object ("secondary-icon-gicon",
1131 P_("Secondary GIcon"),
1132 P_("GIcon for secondary icon"),
1134 GTK_PARAM_READWRITE));
1137 * GtkEntry:primary-icon-storage-type:
1139 * The representation which is used for the primary icon of the entry.
1143 g_object_class_install_property (gobject_class,
1144 PROP_STORAGE_TYPE_PRIMARY,
1145 g_param_spec_enum ("primary-icon-storage-type",
1146 P_("Primary storage type"),
1147 P_("The representation being used for primary icon"),
1148 GTK_TYPE_IMAGE_TYPE,
1150 GTK_PARAM_READABLE));
1153 * GtkEntry:secondary-icon-storage-type:
1155 * The representation which is used for the secondary icon of the entry.
1159 g_object_class_install_property (gobject_class,
1160 PROP_STORAGE_TYPE_SECONDARY,
1161 g_param_spec_enum ("secondary-icon-storage-type",
1162 P_("Secondary storage type"),
1163 P_("The representation being used for secondary icon"),
1164 GTK_TYPE_IMAGE_TYPE,
1166 GTK_PARAM_READABLE));
1169 * GtkEntry:primary-icon-activatable:
1171 * Whether the primary icon is activatable.
1173 * GTK+ emits the #GtkEntry::icon-press and #GtkEntry::icon-release
1174 * signals only on sensitive, activatable icons.
1176 * Sensitive, but non-activatable icons can be used for purely
1177 * informational purposes.
1181 g_object_class_install_property (gobject_class,
1182 PROP_ACTIVATABLE_PRIMARY,
1183 g_param_spec_boolean ("primary-icon-activatable",
1184 P_("Primary icon activatable"),
1185 P_("Whether the primary icon is activatable"),
1187 GTK_PARAM_READWRITE));
1190 * GtkEntry:secondary-icon-activatable:
1192 * Whether the secondary icon is activatable.
1194 * GTK+ emits the #GtkEntry::icon-press and #GtkEntry::icon-release
1195 * signals only on sensitive, activatable icons.
1197 * Sensitive, but non-activatable icons can be used for purely
1198 * informational purposes.
1202 g_object_class_install_property (gobject_class,
1203 PROP_ACTIVATABLE_SECONDARY,
1204 g_param_spec_boolean ("secondary-icon-activatable",
1205 P_("Secondary icon activatable"),
1206 P_("Whether the secondary icon is activatable"),
1208 GTK_PARAM_READWRITE));
1212 * GtkEntry:primary-icon-sensitive:
1214 * Whether the primary icon is sensitive.
1216 * An insensitive icon appears grayed out. GTK+ does not emit the
1217 * #GtkEntry::icon-press and #GtkEntry::icon-release signals and
1218 * does not allow DND from insensitive icons.
1220 * An icon should be set insensitive if the action that would trigger
1221 * when clicked is currently not available.
1225 g_object_class_install_property (gobject_class,
1226 PROP_SENSITIVE_PRIMARY,
1227 g_param_spec_boolean ("primary-icon-sensitive",
1228 P_("Primary icon sensitive"),
1229 P_("Whether the primary icon is sensitive"),
1231 GTK_PARAM_READWRITE));
1234 * GtkEntry:secondary-icon-sensitive:
1236 * Whether the secondary icon is sensitive.
1238 * An insensitive icon appears grayed out. GTK+ does not emit the
1239 * #GtkEntry::icon-press and #GtkEntry::icon-release signals and
1240 * does not allow DND from insensitive icons.
1242 * An icon should be set insensitive if the action that would trigger
1243 * when clicked is currently not available.
1247 g_object_class_install_property (gobject_class,
1248 PROP_SENSITIVE_SECONDARY,
1249 g_param_spec_boolean ("secondary-icon-sensitive",
1250 P_("Secondary icon sensitive"),
1251 P_("Whether the secondary icon is sensitive"),
1253 GTK_PARAM_READWRITE));
1256 * GtkEntry:primary-icon-tooltip-text:
1258 * The contents of the tooltip on the primary icon.
1260 * Also see gtk_entry_set_icon_tooltip_text().
1264 g_object_class_install_property (gobject_class,
1265 PROP_TOOLTIP_TEXT_PRIMARY,
1266 g_param_spec_string ("primary-icon-tooltip-text",
1267 P_("Primary icon tooltip text"),
1268 P_("The contents of the tooltip on the primary icon"),
1270 GTK_PARAM_READWRITE));
1273 * GtkEntry:secondary-icon-tooltip-text:
1275 * The contents of the tooltip on the secondary icon.
1277 * Also see gtk_entry_set_icon_tooltip_text().
1281 g_object_class_install_property (gobject_class,
1282 PROP_TOOLTIP_TEXT_SECONDARY,
1283 g_param_spec_string ("secondary-icon-tooltip-text",
1284 P_("Secondary icon tooltip text"),
1285 P_("The contents of the tooltip on the secondary icon"),
1287 GTK_PARAM_READWRITE));
1290 * GtkEntry:primary-icon-tooltip-markup:
1292 * The contents of the tooltip on the primary icon, which is marked up
1293 * with the <link linkend="PangoMarkupFormat">Pango text markup
1296 * Also see gtk_entry_set_icon_tooltip_markup().
1300 g_object_class_install_property (gobject_class,
1301 PROP_TOOLTIP_MARKUP_PRIMARY,
1302 g_param_spec_string ("primary-icon-tooltip-markup",
1303 P_("Primary icon tooltip markup"),
1304 P_("The contents of the tooltip on the primary icon"),
1306 GTK_PARAM_READWRITE));
1309 * GtkEntry:secondary-icon-tooltip-markup:
1311 * The contents of the tooltip on the secondary icon, which is marked up
1312 * with the <link linkend="PangoMarkupFormat">Pango text markup
1315 * Also see gtk_entry_set_icon_tooltip_markup().
1319 g_object_class_install_property (gobject_class,
1320 PROP_TOOLTIP_MARKUP_SECONDARY,
1321 g_param_spec_string ("secondary-icon-tooltip-markup",
1322 P_("Secondary icon tooltip markup"),
1323 P_("The contents of the tooltip on the secondary icon"),
1325 GTK_PARAM_READWRITE));
1328 * GtkEntry:im-module:
1330 * Which IM (input method) module should be used for this entry.
1331 * See #GtkIMContext.
1333 * Setting this to a non-%NULL value overrides the
1334 * system-wide IM module setting. See the GtkSettings
1335 * #GtkSettings:gtk-im-module property.
1339 g_object_class_install_property (gobject_class,
1341 g_param_spec_string ("im-module",
1343 P_("Which IM module should be used"),
1345 GTK_PARAM_READWRITE));
1348 * GtkEntry:completion:
1350 * The auxiliary completion object to use with the entry.
1354 g_object_class_install_property (gobject_class,
1356 g_param_spec_object ("completion",
1358 P_("The auxiliary completion object"),
1359 GTK_TYPE_ENTRY_COMPLETION,
1360 GTK_PARAM_READWRITE));
1363 * GtkEntry:icon-prelight:
1365 * The prelight style property determines whether activatable
1366 * icons prelight on mouseover.
1370 gtk_widget_class_install_style_property (widget_class,
1371 g_param_spec_boolean ("icon-prelight",
1372 P_("Icon Prelight"),
1373 P_("Whether activatable icons should prelight when hovered"),
1375 GTK_PARAM_READABLE));
1378 * GtkEntry:progress-border:
1380 * The border around the progress bar in the entry.
1384 * Deprecated: 3.4: Use the standard margin CSS property (through objects
1385 * like #GtkStyleContext and #GtkCssProvider); the value of this style
1386 * property is ignored.
1388 gtk_widget_class_install_style_property (widget_class,
1389 g_param_spec_boxed ("progress-border",
1390 P_("Progress Border"),
1391 P_("Border around the progress bar"),
1393 GTK_PARAM_READABLE |
1394 G_PARAM_DEPRECATED));
1397 * GtkEntry:invisible-char:
1399 * The invisible character is used when masking entry contents (in
1400 * \"password mode\")"). When it is not explicitly set with the
1401 * #GtkEntry:invisible-char property, GTK+ determines the character
1402 * to use from a list of possible candidates, depending on availability
1403 * in the current font.
1405 * This style property allows the theme to prepend a character
1406 * to the list of candidates.
1410 gtk_widget_class_install_style_property (widget_class,
1411 g_param_spec_unichar ("invisible-char",
1412 P_("Invisible character"),
1413 P_("The character to use when masking entry contents (in \"password mode\")"),
1415 GTK_PARAM_READABLE));
1418 * GtkEntry::populate-popup:
1419 * @entry: The entry on which the signal is emitted
1420 * @menu: the menu that is being populated
1422 * The ::populate-popup signal gets emitted before showing the
1423 * context menu of the entry.
1425 * If you need to add items to the context menu, connect
1426 * to this signal and append your menuitems to the @menu.
1428 signals[POPULATE_POPUP] =
1429 g_signal_new (I_("populate-popup"),
1430 G_OBJECT_CLASS_TYPE (gobject_class),
1432 G_STRUCT_OFFSET (GtkEntryClass, populate_popup),
1434 _gtk_marshal_VOID__OBJECT,
1438 /* Action signals */
1441 * GtkEntry::activate:
1442 * @entry: The entry on which the signal is emitted
1444 * The ::activate signal is emitted when the user hits
1447 * While this signal is used as a
1448 * <link linkend="keybinding-signals">keybinding signal</link>,
1449 * it is also commonly used by applications to intercept
1450 * activation of entries.
1452 * The default bindings for this signal are all forms of the Enter key.
1455 g_signal_new (I_("activate"),
1456 G_OBJECT_CLASS_TYPE (gobject_class),
1457 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1458 G_STRUCT_OFFSET (GtkEntryClass, activate),
1460 _gtk_marshal_VOID__VOID,
1462 widget_class->activate_signal = signals[ACTIVATE];
1465 * GtkEntry::move-cursor:
1466 * @entry: the object which received the signal
1467 * @step: the granularity of the move, as a #GtkMovementStep
1468 * @count: the number of @step units to move
1469 * @extend_selection: %TRUE if the move should extend the selection
1471 * The ::move-cursor signal is a
1472 * <link linkend="keybinding-signals">keybinding signal</link>
1473 * which gets emitted when the user initiates a cursor movement.
1474 * If the cursor is not visible in @entry, this signal causes
1475 * the viewport to be moved instead.
1477 * Applications should not connect to it, but may emit it with
1478 * g_signal_emit_by_name() if they need to control the cursor
1481 * The default bindings for this signal come in two variants,
1482 * the variant with the Shift modifier extends the selection,
1483 * the variant without the Shift modifer does not.
1484 * There are too many key combinations to list them all here.
1486 * <listitem>Arrow keys move by individual characters/lines</listitem>
1487 * <listitem>Ctrl-arrow key combinations move by words/paragraphs</listitem>
1488 * <listitem>Home/End keys move to the ends of the buffer</listitem>
1491 signals[MOVE_CURSOR] =
1492 g_signal_new (I_("move-cursor"),
1493 G_OBJECT_CLASS_TYPE (gobject_class),
1494 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1495 G_STRUCT_OFFSET (GtkEntryClass, move_cursor),
1497 _gtk_marshal_VOID__ENUM_INT_BOOLEAN,
1499 GTK_TYPE_MOVEMENT_STEP,
1504 * GtkEntry::insert-at-cursor:
1505 * @entry: the object which received the signal
1506 * @string: the string to insert
1508 * The ::insert-at-cursor signal is a
1509 * <link linkend="keybinding-signals">keybinding signal</link>
1510 * which gets emitted when the user initiates the insertion of a
1511 * fixed string at the cursor.
1513 * This signal has no default bindings.
1515 signals[INSERT_AT_CURSOR] =
1516 g_signal_new (I_("insert-at-cursor"),
1517 G_OBJECT_CLASS_TYPE (gobject_class),
1518 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1519 G_STRUCT_OFFSET (GtkEntryClass, insert_at_cursor),
1521 _gtk_marshal_VOID__STRING,
1526 * GtkEntry::delete-from-cursor:
1527 * @entry: the object which received the signal
1528 * @type: the granularity of the deletion, as a #GtkDeleteType
1529 * @count: the number of @type units to delete
1531 * The ::delete-from-cursor signal is a
1532 * <link linkend="keybinding-signals">keybinding signal</link>
1533 * which gets emitted when the user initiates a text deletion.
1535 * If the @type is %GTK_DELETE_CHARS, GTK+ deletes the selection
1536 * if there is one, otherwise it deletes the requested number
1539 * The default bindings for this signal are
1540 * Delete for deleting a character and Ctrl-Delete for
1543 signals[DELETE_FROM_CURSOR] =
1544 g_signal_new (I_("delete-from-cursor"),
1545 G_OBJECT_CLASS_TYPE (gobject_class),
1546 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1547 G_STRUCT_OFFSET (GtkEntryClass, delete_from_cursor),
1549 _gtk_marshal_VOID__ENUM_INT,
1551 GTK_TYPE_DELETE_TYPE,
1555 * GtkEntry::backspace:
1556 * @entry: the object which received the signal
1558 * The ::backspace signal is a
1559 * <link linkend="keybinding-signals">keybinding signal</link>
1560 * which gets emitted when the user asks for it.
1562 * The default bindings for this signal are
1563 * Backspace and Shift-Backspace.
1565 signals[BACKSPACE] =
1566 g_signal_new (I_("backspace"),
1567 G_OBJECT_CLASS_TYPE (gobject_class),
1568 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1569 G_STRUCT_OFFSET (GtkEntryClass, backspace),
1571 _gtk_marshal_VOID__VOID,
1575 * GtkEntry::cut-clipboard:
1576 * @entry: the object which received the signal
1578 * The ::cut-clipboard signal is a
1579 * <link linkend="keybinding-signals">keybinding signal</link>
1580 * which gets emitted to cut the selection to the clipboard.
1582 * The default bindings for this signal are
1583 * Ctrl-x and Shift-Delete.
1585 signals[CUT_CLIPBOARD] =
1586 g_signal_new (I_("cut-clipboard"),
1587 G_OBJECT_CLASS_TYPE (gobject_class),
1588 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1589 G_STRUCT_OFFSET (GtkEntryClass, cut_clipboard),
1591 _gtk_marshal_VOID__VOID,
1595 * GtkEntry::copy-clipboard:
1596 * @entry: the object which received the signal
1598 * The ::copy-clipboard signal is a
1599 * <link linkend="keybinding-signals">keybinding signal</link>
1600 * which gets emitted to copy the selection to the clipboard.
1602 * The default bindings for this signal are
1603 * Ctrl-c and Ctrl-Insert.
1605 signals[COPY_CLIPBOARD] =
1606 g_signal_new (I_("copy-clipboard"),
1607 G_OBJECT_CLASS_TYPE (gobject_class),
1608 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1609 G_STRUCT_OFFSET (GtkEntryClass, copy_clipboard),
1611 _gtk_marshal_VOID__VOID,
1615 * GtkEntry::paste-clipboard:
1616 * @entry: the object which received the signal
1618 * The ::paste-clipboard signal is a
1619 * <link linkend="keybinding-signals">keybinding signal</link>
1620 * which gets emitted to paste the contents of the clipboard
1621 * into the text view.
1623 * The default bindings for this signal are
1624 * Ctrl-v and Shift-Insert.
1626 signals[PASTE_CLIPBOARD] =
1627 g_signal_new (I_("paste-clipboard"),
1628 G_OBJECT_CLASS_TYPE (gobject_class),
1629 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1630 G_STRUCT_OFFSET (GtkEntryClass, paste_clipboard),
1632 _gtk_marshal_VOID__VOID,
1636 * GtkEntry::toggle-overwrite:
1637 * @entry: the object which received the signal
1639 * The ::toggle-overwrite signal is a
1640 * <link linkend="keybinding-signals">keybinding signal</link>
1641 * which gets emitted to toggle the overwrite mode of the entry.
1643 * The default bindings for this signal is Insert.
1645 signals[TOGGLE_OVERWRITE] =
1646 g_signal_new (I_("toggle-overwrite"),
1647 G_OBJECT_CLASS_TYPE (gobject_class),
1648 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1649 G_STRUCT_OFFSET (GtkEntryClass, toggle_overwrite),
1651 _gtk_marshal_VOID__VOID,
1655 * GtkEntry::icon-press:
1656 * @entry: The entry on which the signal is emitted
1657 * @icon_pos: The position of the clicked icon
1658 * @event: (type Gdk.EventButton): the button press event
1660 * The ::icon-press signal is emitted when an activatable icon
1665 signals[ICON_PRESS] =
1666 g_signal_new (I_("icon-press"),
1667 G_TYPE_FROM_CLASS (gobject_class),
1671 _gtk_marshal_VOID__ENUM_BOXED,
1673 GTK_TYPE_ENTRY_ICON_POSITION,
1674 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1677 * GtkEntry::icon-release:
1678 * @entry: The entry on which the signal is emitted
1679 * @icon_pos: The position of the clicked icon
1680 * @event: (type Gdk.EventButton): the button release event
1682 * The ::icon-release signal is emitted on the button release from a
1683 * mouse click over an activatable icon.
1687 signals[ICON_RELEASE] =
1688 g_signal_new (I_("icon-release"),
1689 G_TYPE_FROM_CLASS (gobject_class),
1693 _gtk_marshal_VOID__ENUM_BOXED,
1695 GTK_TYPE_ENTRY_ICON_POSITION,
1696 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1699 * GtkEntry::preedit-changed:
1700 * @entry: the object which received the signal
1701 * @preedit: the current preedit string
1703 * If an input method is used, the typed text will not immediately
1704 * be committed to the buffer. So if you are interested in the text,
1705 * connect to this signal.
1709 signals[PREEDIT_CHANGED] =
1710 g_signal_new_class_handler (I_("preedit-changed"),
1711 G_OBJECT_CLASS_TYPE (gobject_class),
1712 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1715 _gtk_marshal_VOID__STRING,
1724 binding_set = gtk_binding_set_by_class (class);
1726 /* Moving the insertion point */
1727 add_move_binding (binding_set, GDK_KEY_Right, 0,
1728 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1730 add_move_binding (binding_set, GDK_KEY_Left, 0,
1731 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1733 add_move_binding (binding_set, GDK_KEY_KP_Right, 0,
1734 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1736 add_move_binding (binding_set, GDK_KEY_KP_Left, 0,
1737 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1739 add_move_binding (binding_set, GDK_KEY_Right, GDK_CONTROL_MASK,
1740 GTK_MOVEMENT_WORDS, 1);
1742 add_move_binding (binding_set, GDK_KEY_Left, GDK_CONTROL_MASK,
1743 GTK_MOVEMENT_WORDS, -1);
1745 add_move_binding (binding_set, GDK_KEY_KP_Right, GDK_CONTROL_MASK,
1746 GTK_MOVEMENT_WORDS, 1);
1748 add_move_binding (binding_set, GDK_KEY_KP_Left, GDK_CONTROL_MASK,
1749 GTK_MOVEMENT_WORDS, -1);
1751 add_move_binding (binding_set, GDK_KEY_Home, 0,
1752 GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
1754 add_move_binding (binding_set, GDK_KEY_End, 0,
1755 GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
1757 add_move_binding (binding_set, GDK_KEY_KP_Home, 0,
1758 GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
1760 add_move_binding (binding_set, GDK_KEY_KP_End, 0,
1761 GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
1763 add_move_binding (binding_set, GDK_KEY_Home, GDK_CONTROL_MASK,
1764 GTK_MOVEMENT_BUFFER_ENDS, -1);
1766 add_move_binding (binding_set, GDK_KEY_End, GDK_CONTROL_MASK,
1767 GTK_MOVEMENT_BUFFER_ENDS, 1);
1769 add_move_binding (binding_set, GDK_KEY_KP_Home, GDK_CONTROL_MASK,
1770 GTK_MOVEMENT_BUFFER_ENDS, -1);
1772 add_move_binding (binding_set, GDK_KEY_KP_End, GDK_CONTROL_MASK,
1773 GTK_MOVEMENT_BUFFER_ENDS, 1);
1777 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK,
1779 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1781 G_TYPE_BOOLEAN, FALSE);
1782 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK,
1784 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1786 G_TYPE_BOOLEAN, TRUE);
1788 gtk_binding_entry_add_signal (binding_set, GDK_KEY_slash, GDK_CONTROL_MASK,
1790 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1792 G_TYPE_BOOLEAN, FALSE);
1793 gtk_binding_entry_add_signal (binding_set, GDK_KEY_slash, GDK_CONTROL_MASK,
1795 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1797 G_TYPE_BOOLEAN, TRUE);
1800 gtk_binding_entry_add_signal (binding_set, GDK_KEY_backslash, GDK_CONTROL_MASK,
1802 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_VISUAL_POSITIONS,
1804 G_TYPE_BOOLEAN, FALSE);
1805 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_SHIFT_MASK | GDK_CONTROL_MASK,
1807 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_VISUAL_POSITIONS,
1809 G_TYPE_BOOLEAN, FALSE);
1813 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Return, 0,
1815 gtk_binding_entry_add_signal (binding_set, GDK_KEY_ISO_Enter, 0,
1817 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Enter, 0,
1821 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, 0,
1822 "delete-from-cursor", 2,
1823 G_TYPE_ENUM, GTK_DELETE_CHARS,
1826 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Delete, 0,
1827 "delete-from-cursor", 2,
1828 G_TYPE_ENUM, GTK_DELETE_CHARS,
1831 gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, 0,
1834 /* Make this do the same as Backspace, to help with mis-typing */
1835 gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, GDK_SHIFT_MASK,
1838 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, GDK_CONTROL_MASK,
1839 "delete-from-cursor", 2,
1840 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1843 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Delete, GDK_CONTROL_MASK,
1844 "delete-from-cursor", 2,
1845 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1848 gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, GDK_CONTROL_MASK,
1849 "delete-from-cursor", 2,
1850 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1853 /* Cut/copy/paste */
1855 gtk_binding_entry_add_signal (binding_set, GDK_KEY_x, GDK_CONTROL_MASK,
1856 "cut-clipboard", 0);
1857 gtk_binding_entry_add_signal (binding_set, GDK_KEY_c, GDK_CONTROL_MASK,
1858 "copy-clipboard", 0);
1859 gtk_binding_entry_add_signal (binding_set, GDK_KEY_v, GDK_CONTROL_MASK,
1860 "paste-clipboard", 0);
1862 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, GDK_SHIFT_MASK,
1863 "cut-clipboard", 0);
1864 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, GDK_CONTROL_MASK,
1865 "copy-clipboard", 0);
1866 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, GDK_SHIFT_MASK,
1867 "paste-clipboard", 0);
1870 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, 0,
1871 "toggle-overwrite", 0);
1872 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Insert, 0,
1873 "toggle-overwrite", 0);
1876 * GtkEntry:inner-border:
1878 * Sets the text area's border between the text and the frame.
1882 * Deprecated: 3.4: Use the standard border and padding CSS properties
1883 * (through objects like #GtkStyleContext and #GtkCssProvider); the value
1884 * of this style property is ignored.
1886 gtk_widget_class_install_style_property (widget_class,
1887 g_param_spec_boxed ("inner-border",
1889 P_("Border between text and frame."),
1891 GTK_PARAM_READABLE |
1892 G_PARAM_DEPRECATED));
1894 g_type_class_add_private (gobject_class, sizeof (GtkEntryPrivate));
1896 gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_ENTRY_ACCESSIBLE);
1900 gtk_entry_editable_init (GtkEditableInterface *iface)
1902 iface->do_insert_text = gtk_entry_insert_text;
1903 iface->do_delete_text = gtk_entry_delete_text;
1904 iface->insert_text = gtk_entry_real_insert_text;
1905 iface->delete_text = gtk_entry_real_delete_text;
1906 iface->get_chars = gtk_entry_get_chars;
1907 iface->set_selection_bounds = gtk_entry_set_selection_bounds;
1908 iface->get_selection_bounds = gtk_entry_get_selection_bounds;
1909 iface->set_position = gtk_entry_real_set_position;
1910 iface->get_position = gtk_entry_get_position;
1914 gtk_entry_cell_editable_init (GtkCellEditableIface *iface)
1916 iface->start_editing = gtk_entry_start_editing;
1919 /* for deprecated properties */
1921 gtk_entry_do_set_inner_border (GtkEntry *entry,
1922 const GtkBorder *border)
1925 g_object_set_qdata_full (G_OBJECT (entry), quark_inner_border,
1926 gtk_border_copy (border),
1927 (GDestroyNotify) gtk_border_free);
1929 g_object_set_qdata (G_OBJECT (entry), quark_inner_border, NULL);
1931 g_object_notify (G_OBJECT (entry), "inner-border");
1934 static const GtkBorder *
1935 gtk_entry_do_get_inner_border (GtkEntry *entry)
1937 return g_object_get_qdata (G_OBJECT (entry), quark_inner_border);
1941 gtk_entry_set_property (GObject *object,
1943 const GValue *value,
1946 GtkEntry *entry = GTK_ENTRY (object);
1947 GtkEntryPrivate *priv = entry->priv;
1952 gtk_entry_set_buffer (entry, g_value_get_object (value));
1957 gboolean new_value = g_value_get_boolean (value);
1959 if (new_value != priv->editable)
1961 GtkWidget *widget = GTK_WIDGET (entry);
1965 _gtk_entry_reset_im_context (entry);
1966 if (gtk_widget_has_focus (widget))
1967 gtk_im_context_focus_out (priv->im_context);
1969 priv->preedit_length = 0;
1970 priv->preedit_cursor = 0;
1973 priv->editable = new_value;
1975 if (new_value && gtk_widget_has_focus (widget))
1976 gtk_im_context_focus_in (priv->im_context);
1978 gtk_widget_queue_draw (widget);
1983 case PROP_MAX_LENGTH:
1984 gtk_entry_set_max_length (entry, g_value_get_int (value));
1987 case PROP_VISIBILITY:
1988 gtk_entry_set_visibility (entry, g_value_get_boolean (value));
1991 case PROP_HAS_FRAME:
1992 gtk_entry_set_has_frame (entry, g_value_get_boolean (value));
1995 case PROP_INNER_BORDER:
1996 gtk_entry_do_set_inner_border (entry, g_value_get_boxed (value));
1999 case PROP_INVISIBLE_CHAR:
2000 gtk_entry_set_invisible_char (entry, g_value_get_uint (value));
2003 case PROP_ACTIVATES_DEFAULT:
2004 gtk_entry_set_activates_default (entry, g_value_get_boolean (value));
2007 case PROP_WIDTH_CHARS:
2008 gtk_entry_set_width_chars (entry, g_value_get_int (value));
2012 gtk_entry_set_text (entry, g_value_get_string (value));
2016 gtk_entry_set_alignment (entry, g_value_get_float (value));
2019 case PROP_TRUNCATE_MULTILINE:
2020 priv->truncate_multiline = g_value_get_boolean (value);
2023 case PROP_SHADOW_TYPE:
2024 priv->shadow_type = g_value_get_enum (value);
2027 case PROP_OVERWRITE_MODE:
2028 gtk_entry_set_overwrite_mode (entry, g_value_get_boolean (value));
2031 case PROP_INVISIBLE_CHAR_SET:
2032 if (g_value_get_boolean (value))
2033 priv->invisible_char_set = TRUE;
2035 gtk_entry_unset_invisible_char (entry);
2038 case PROP_CAPS_LOCK_WARNING:
2039 priv->caps_lock_warning = g_value_get_boolean (value);
2042 case PROP_PROGRESS_FRACTION:
2043 gtk_entry_set_progress_fraction (entry, g_value_get_double (value));
2046 case PROP_PROGRESS_PULSE_STEP:
2047 gtk_entry_set_progress_pulse_step (entry, g_value_get_double (value));
2050 case PROP_PLACEHOLDER_TEXT:
2051 gtk_entry_set_placeholder_text (entry, g_value_get_string (value));
2054 case PROP_PIXBUF_PRIMARY:
2055 gtk_entry_set_icon_from_pixbuf (entry,
2056 GTK_ENTRY_ICON_PRIMARY,
2057 g_value_get_object (value));
2060 case PROP_PIXBUF_SECONDARY:
2061 gtk_entry_set_icon_from_pixbuf (entry,
2062 GTK_ENTRY_ICON_SECONDARY,
2063 g_value_get_object (value));
2066 case PROP_STOCK_PRIMARY:
2067 gtk_entry_set_icon_from_stock (entry,
2068 GTK_ENTRY_ICON_PRIMARY,
2069 g_value_get_string (value));
2072 case PROP_STOCK_SECONDARY:
2073 gtk_entry_set_icon_from_stock (entry,
2074 GTK_ENTRY_ICON_SECONDARY,
2075 g_value_get_string (value));
2078 case PROP_ICON_NAME_PRIMARY:
2079 gtk_entry_set_icon_from_icon_name (entry,
2080 GTK_ENTRY_ICON_PRIMARY,
2081 g_value_get_string (value));
2084 case PROP_ICON_NAME_SECONDARY:
2085 gtk_entry_set_icon_from_icon_name (entry,
2086 GTK_ENTRY_ICON_SECONDARY,
2087 g_value_get_string (value));
2090 case PROP_GICON_PRIMARY:
2091 gtk_entry_set_icon_from_gicon (entry,
2092 GTK_ENTRY_ICON_PRIMARY,
2093 g_value_get_object (value));
2096 case PROP_GICON_SECONDARY:
2097 gtk_entry_set_icon_from_gicon (entry,
2098 GTK_ENTRY_ICON_SECONDARY,
2099 g_value_get_object (value));
2102 case PROP_ACTIVATABLE_PRIMARY:
2103 gtk_entry_set_icon_activatable (entry,
2104 GTK_ENTRY_ICON_PRIMARY,
2105 g_value_get_boolean (value));
2108 case PROP_ACTIVATABLE_SECONDARY:
2109 gtk_entry_set_icon_activatable (entry,
2110 GTK_ENTRY_ICON_SECONDARY,
2111 g_value_get_boolean (value));
2114 case PROP_SENSITIVE_PRIMARY:
2115 gtk_entry_set_icon_sensitive (entry,
2116 GTK_ENTRY_ICON_PRIMARY,
2117 g_value_get_boolean (value));
2120 case PROP_SENSITIVE_SECONDARY:
2121 gtk_entry_set_icon_sensitive (entry,
2122 GTK_ENTRY_ICON_SECONDARY,
2123 g_value_get_boolean (value));
2126 case PROP_TOOLTIP_TEXT_PRIMARY:
2127 gtk_entry_set_icon_tooltip_text (entry,
2128 GTK_ENTRY_ICON_PRIMARY,
2129 g_value_get_string (value));
2132 case PROP_TOOLTIP_TEXT_SECONDARY:
2133 gtk_entry_set_icon_tooltip_text (entry,
2134 GTK_ENTRY_ICON_SECONDARY,
2135 g_value_get_string (value));
2138 case PROP_TOOLTIP_MARKUP_PRIMARY:
2139 gtk_entry_set_icon_tooltip_markup (entry,
2140 GTK_ENTRY_ICON_PRIMARY,
2141 g_value_get_string (value));
2144 case PROP_TOOLTIP_MARKUP_SECONDARY:
2145 gtk_entry_set_icon_tooltip_markup (entry,
2146 GTK_ENTRY_ICON_SECONDARY,
2147 g_value_get_string (value));
2150 case PROP_IM_MODULE:
2151 g_free (priv->im_module);
2152 priv->im_module = g_value_dup_string (value);
2153 if (GTK_IS_IM_MULTICONTEXT (priv->im_context))
2154 gtk_im_multicontext_set_context_id (GTK_IM_MULTICONTEXT (priv->im_context), priv->im_module);
2157 case PROP_EDITING_CANCELED:
2158 priv->editing_canceled = g_value_get_boolean (value);
2161 case PROP_COMPLETION:
2162 gtk_entry_set_completion (entry, GTK_ENTRY_COMPLETION (g_value_get_object (value)));
2165 case PROP_SCROLL_OFFSET:
2166 case PROP_CURSOR_POSITION:
2168 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2174 gtk_entry_get_property (GObject *object,
2179 GtkEntry *entry = GTK_ENTRY (object);
2180 GtkEntryPrivate *priv = entry->priv;
2185 g_value_set_object (value, gtk_entry_get_buffer (entry));
2188 case PROP_CURSOR_POSITION:
2189 g_value_set_int (value, priv->current_pos);
2192 case PROP_SELECTION_BOUND:
2193 g_value_set_int (value, priv->selection_bound);
2197 g_value_set_boolean (value, priv->editable);
2200 case PROP_MAX_LENGTH:
2201 g_value_set_int (value, gtk_entry_buffer_get_max_length (get_buffer (entry)));
2204 case PROP_VISIBILITY:
2205 g_value_set_boolean (value, priv->visible);
2208 case PROP_HAS_FRAME:
2209 g_value_set_boolean (value, priv->has_frame);
2212 case PROP_INNER_BORDER:
2213 g_value_set_boxed (value, gtk_entry_do_get_inner_border (entry));
2216 case PROP_INVISIBLE_CHAR:
2217 g_value_set_uint (value, priv->invisible_char);
2220 case PROP_ACTIVATES_DEFAULT:
2221 g_value_set_boolean (value, priv->activates_default);
2224 case PROP_WIDTH_CHARS:
2225 g_value_set_int (value, priv->width_chars);
2228 case PROP_SCROLL_OFFSET:
2229 g_value_set_int (value, priv->scroll_offset);
2233 g_value_set_string (value, gtk_entry_get_text (entry));
2237 g_value_set_float (value, gtk_entry_get_alignment (entry));
2240 case PROP_TRUNCATE_MULTILINE:
2241 g_value_set_boolean (value, priv->truncate_multiline);
2244 case PROP_SHADOW_TYPE:
2245 g_value_set_enum (value, priv->shadow_type);
2248 case PROP_OVERWRITE_MODE:
2249 g_value_set_boolean (value, priv->overwrite_mode);
2252 case PROP_TEXT_LENGTH:
2253 g_value_set_uint (value, gtk_entry_buffer_get_length (get_buffer (entry)));
2256 case PROP_INVISIBLE_CHAR_SET:
2257 g_value_set_boolean (value, priv->invisible_char_set);
2260 case PROP_IM_MODULE:
2261 g_value_set_string (value, priv->im_module);
2264 case PROP_CAPS_LOCK_WARNING:
2265 g_value_set_boolean (value, priv->caps_lock_warning);
2268 case PROP_PROGRESS_FRACTION:
2269 g_value_set_double (value, priv->progress_fraction);
2272 case PROP_PROGRESS_PULSE_STEP:
2273 g_value_set_double (value, priv->progress_pulse_fraction);
2276 case PROP_PLACEHOLDER_TEXT:
2277 g_value_set_string (value, gtk_entry_get_placeholder_text (entry));
2280 case PROP_PIXBUF_PRIMARY:
2281 g_value_set_object (value,
2282 gtk_entry_get_icon_pixbuf (entry,
2283 GTK_ENTRY_ICON_PRIMARY));
2286 case PROP_PIXBUF_SECONDARY:
2287 g_value_set_object (value,
2288 gtk_entry_get_icon_pixbuf (entry,
2289 GTK_ENTRY_ICON_SECONDARY));
2292 case PROP_STOCK_PRIMARY:
2293 g_value_set_string (value,
2294 gtk_entry_get_icon_stock (entry,
2295 GTK_ENTRY_ICON_PRIMARY));
2298 case PROP_STOCK_SECONDARY:
2299 g_value_set_string (value,
2300 gtk_entry_get_icon_stock (entry,
2301 GTK_ENTRY_ICON_SECONDARY));
2304 case PROP_ICON_NAME_PRIMARY:
2305 g_value_set_string (value,
2306 gtk_entry_get_icon_name (entry,
2307 GTK_ENTRY_ICON_PRIMARY));
2310 case PROP_ICON_NAME_SECONDARY:
2311 g_value_set_string (value,
2312 gtk_entry_get_icon_name (entry,
2313 GTK_ENTRY_ICON_SECONDARY));
2316 case PROP_GICON_PRIMARY:
2317 g_value_set_object (value,
2318 gtk_entry_get_icon_gicon (entry,
2319 GTK_ENTRY_ICON_PRIMARY));
2322 case PROP_GICON_SECONDARY:
2323 g_value_set_object (value,
2324 gtk_entry_get_icon_gicon (entry,
2325 GTK_ENTRY_ICON_SECONDARY));
2328 case PROP_STORAGE_TYPE_PRIMARY:
2329 g_value_set_enum (value,
2330 gtk_entry_get_icon_storage_type (entry,
2331 GTK_ENTRY_ICON_PRIMARY));
2334 case PROP_STORAGE_TYPE_SECONDARY:
2335 g_value_set_enum (value,
2336 gtk_entry_get_icon_storage_type (entry,
2337 GTK_ENTRY_ICON_SECONDARY));
2340 case PROP_ACTIVATABLE_PRIMARY:
2341 g_value_set_boolean (value,
2342 gtk_entry_get_icon_activatable (entry, GTK_ENTRY_ICON_PRIMARY));
2345 case PROP_ACTIVATABLE_SECONDARY:
2346 g_value_set_boolean (value,
2347 gtk_entry_get_icon_activatable (entry, GTK_ENTRY_ICON_SECONDARY));
2350 case PROP_SENSITIVE_PRIMARY:
2351 g_value_set_boolean (value,
2352 gtk_entry_get_icon_sensitive (entry, GTK_ENTRY_ICON_PRIMARY));
2355 case PROP_SENSITIVE_SECONDARY:
2356 g_value_set_boolean (value,
2357 gtk_entry_get_icon_sensitive (entry, GTK_ENTRY_ICON_SECONDARY));
2360 case PROP_TOOLTIP_TEXT_PRIMARY:
2361 g_value_take_string (value,
2362 gtk_entry_get_icon_tooltip_text (entry, GTK_ENTRY_ICON_PRIMARY));
2365 case PROP_TOOLTIP_TEXT_SECONDARY:
2366 g_value_take_string (value,
2367 gtk_entry_get_icon_tooltip_text (entry, GTK_ENTRY_ICON_SECONDARY));
2370 case PROP_TOOLTIP_MARKUP_PRIMARY:
2371 g_value_take_string (value,
2372 gtk_entry_get_icon_tooltip_markup (entry, GTK_ENTRY_ICON_PRIMARY));
2375 case PROP_TOOLTIP_MARKUP_SECONDARY:
2376 g_value_take_string (value,
2377 gtk_entry_get_icon_tooltip_markup (entry, GTK_ENTRY_ICON_SECONDARY));
2380 case PROP_EDITING_CANCELED:
2381 g_value_set_boolean (value,
2382 priv->editing_canceled);
2385 case PROP_COMPLETION:
2386 g_value_set_object (value, G_OBJECT (gtk_entry_get_completion (entry)));
2390 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2396 find_invisible_char (GtkWidget *widget)
2398 PangoLayout *layout;
2399 PangoAttrList *attr_list;
2401 gunichar invisible_chars [] = {
2403 0x25cf, /* BLACK CIRCLE */
2404 0x2022, /* BULLET */
2405 0x2731, /* HEAVY ASTERISK */
2406 0x273a /* SIXTEEN POINTED ASTERISK */
2409 gtk_widget_style_get (widget,
2410 "invisible-char", &invisible_chars[0],
2413 layout = gtk_widget_create_pango_layout (widget, NULL);
2415 attr_list = pango_attr_list_new ();
2416 pango_attr_list_insert (attr_list, pango_attr_fallback_new (FALSE));
2418 pango_layout_set_attributes (layout, attr_list);
2419 pango_attr_list_unref (attr_list);
2421 for (i = (invisible_chars[0] != 0 ? 0 : 1); i < G_N_ELEMENTS (invisible_chars); i++)
2423 gchar text[7] = { 0, };
2426 len = g_unichar_to_utf8 (invisible_chars[i], text);
2427 pango_layout_set_text (layout, text, len);
2429 count = pango_layout_get_unknown_glyphs_count (layout);
2433 g_object_unref (layout);
2434 return invisible_chars[i];
2438 g_object_unref (layout);
2444 gtk_entry_init (GtkEntry *entry)
2446 GtkStyleContext *context;
2447 GtkEntryPrivate *priv;
2449 entry->priv = G_TYPE_INSTANCE_GET_PRIVATE (entry,
2454 gtk_widget_set_can_focus (GTK_WIDGET (entry), TRUE);
2455 gtk_widget_set_has_window (GTK_WIDGET (entry), FALSE);
2457 priv->editable = TRUE;
2458 priv->visible = TRUE;
2459 priv->dnd_position = -1;
2460 priv->width_chars = -1;
2461 priv->is_cell_renderer = FALSE;
2462 priv->editing_canceled = FALSE;
2463 priv->has_frame = TRUE;
2464 priv->truncate_multiline = FALSE;
2465 priv->shadow_type = GTK_SHADOW_IN;
2467 priv->caps_lock_warning = TRUE;
2468 priv->caps_lock_warning_shown = FALSE;
2469 priv->progress_fraction = 0.0;
2470 priv->progress_pulse_fraction = 0.1;
2472 gtk_drag_dest_set (GTK_WIDGET (entry),
2473 GTK_DEST_DEFAULT_HIGHLIGHT,
2475 GDK_ACTION_COPY | GDK_ACTION_MOVE);
2476 gtk_drag_dest_add_text_targets (GTK_WIDGET (entry));
2478 /* This object is completely private. No external entity can gain a reference
2479 * to it; so we create it here and destroy it in finalize().
2481 priv->im_context = gtk_im_multicontext_new ();
2483 g_signal_connect (priv->im_context, "commit",
2484 G_CALLBACK (gtk_entry_commit_cb), entry);
2485 g_signal_connect (priv->im_context, "preedit-changed",
2486 G_CALLBACK (gtk_entry_preedit_changed_cb), entry);
2487 g_signal_connect (priv->im_context, "retrieve-surrounding",
2488 G_CALLBACK (gtk_entry_retrieve_surrounding_cb), entry);
2489 g_signal_connect (priv->im_context, "delete-surrounding",
2490 G_CALLBACK (gtk_entry_delete_surrounding_cb), entry);
2492 context = gtk_widget_get_style_context (GTK_WIDGET (entry));
2493 gtk_style_context_add_class (context, GTK_STYLE_CLASS_ENTRY);
2495 gtk_entry_update_cached_style_values (entry);
2499 gtk_entry_prepare_context_for_icon (GtkEntry *entry,
2500 GtkStyleContext *context,
2501 GtkEntryIconPosition icon_pos)
2503 GtkEntryPrivate *priv = entry->priv;
2504 EntryIconInfo *icon_info = priv->icons[icon_pos];
2506 GtkStateFlags state;
2508 widget = GTK_WIDGET (entry);
2509 state = gtk_widget_get_state_flags (widget);
2511 state &= ~(GTK_STATE_FLAG_PRELIGHT);
2513 if ((state & GTK_STATE_FLAG_INSENSITIVE) || icon_info->insensitive)
2514 state |= GTK_STATE_FLAG_INSENSITIVE;
2515 else if (icon_info->prelight)
2516 state |= GTK_STATE_FLAG_PRELIGHT;
2518 gtk_style_context_save (context);
2520 gtk_style_context_set_state (context, state);
2521 gtk_style_context_add_class (context, GTK_STYLE_CLASS_IMAGE);
2523 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
2525 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
2526 gtk_style_context_add_class (context, GTK_STYLE_CLASS_RIGHT);
2528 gtk_style_context_add_class (context, GTK_STYLE_CLASS_LEFT);
2532 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
2533 gtk_style_context_add_class (context, GTK_STYLE_CLASS_LEFT);
2535 gtk_style_context_add_class (context, GTK_STYLE_CLASS_RIGHT);
2540 get_icon_width (GtkEntry *entry,
2541 GtkEntryIconPosition icon_pos)
2543 GtkEntryPrivate *priv = entry->priv;
2544 EntryIconInfo *icon_info = priv->icons[icon_pos];
2545 GtkStyleContext *context;
2552 context = gtk_widget_get_style_context (GTK_WIDGET (entry));
2553 gtk_entry_prepare_context_for_icon (entry, context, icon_pos);
2554 gtk_style_context_get_padding (context, 0, &padding);
2556 _gtk_icon_helper_get_size (icon_info->icon_helper, context,
2558 gtk_style_context_restore (context);
2561 width += padding.left + padding.right;
2567 get_icon_allocations (GtkEntry *entry,
2568 GtkAllocation *primary,
2569 GtkAllocation *secondary)
2572 GtkEntryPrivate *priv = entry->priv;
2573 gint x, y, width, height;
2575 get_text_area_size (entry, &x, &y, &width, &height);
2577 if (gtk_widget_has_focus (GTK_WIDGET (entry)) && !priv->interior_focus)
2578 y += priv->focus_width;
2581 primary->height = height;
2582 primary->width = get_icon_width (entry, GTK_ENTRY_ICON_PRIMARY);
2585 secondary->height = height;
2586 secondary->width = get_icon_width (entry, GTK_ENTRY_ICON_SECONDARY);
2588 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
2590 primary->x = x + width - primary->width;
2596 secondary->x = x + width - secondary->width;
2602 begin_change (GtkEntry *entry)
2604 GtkEntryPrivate *priv = entry->priv;
2606 priv->change_count++;
2608 g_object_freeze_notify (G_OBJECT (entry));
2612 end_change (GtkEntry *entry)
2614 GtkEditable *editable = GTK_EDITABLE (entry);
2615 GtkEntryPrivate *priv = entry->priv;
2617 g_return_if_fail (priv->change_count > 0);
2619 g_object_thaw_notify (G_OBJECT (entry));
2621 priv->change_count--;
2623 if (priv->change_count == 0)
2625 if (priv->real_changed)
2627 g_signal_emit_by_name (editable, "changed");
2628 priv->real_changed = FALSE;
2634 emit_changed (GtkEntry *entry)
2636 GtkEditable *editable = GTK_EDITABLE (entry);
2637 GtkEntryPrivate *priv = entry->priv;
2639 if (priv->change_count == 0)
2640 g_signal_emit_by_name (editable, "changed");
2642 priv->real_changed = TRUE;
2646 gtk_entry_destroy (GtkWidget *widget)
2648 GtkEntry *entry = GTK_ENTRY (widget);
2649 GtkEntryPrivate *priv = entry->priv;
2651 priv->current_pos = priv->selection_bound = 0;
2652 _gtk_entry_reset_im_context (entry);
2653 gtk_entry_reset_layout (entry);
2655 if (priv->blink_timeout)
2657 g_source_remove (priv->blink_timeout);
2658 priv->blink_timeout = 0;
2661 if (priv->recompute_idle)
2663 g_source_remove (priv->recompute_idle);
2664 priv->recompute_idle = 0;
2667 GTK_WIDGET_CLASS (gtk_entry_parent_class)->destroy (widget);
2671 gtk_entry_dispose (GObject *object)
2673 GtkEntry *entry = GTK_ENTRY (object);
2674 GtkEntryPrivate *priv = entry->priv;
2677 gtk_entry_set_icon_from_pixbuf (entry, GTK_ENTRY_ICON_PRIMARY, NULL);
2678 gtk_entry_set_icon_tooltip_markup (entry, GTK_ENTRY_ICON_PRIMARY, NULL);
2679 gtk_entry_set_icon_from_pixbuf (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
2680 gtk_entry_set_icon_tooltip_markup (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
2684 buffer_disconnect_signals (entry);
2685 g_object_unref (priv->buffer);
2686 priv->buffer = NULL;
2689 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (object)));
2690 g_signal_handlers_disconnect_by_func (keymap, keymap_state_changed, entry);
2691 g_signal_handlers_disconnect_by_func (keymap, keymap_direction_changed, entry);
2692 G_OBJECT_CLASS (gtk_entry_parent_class)->dispose (object);
2696 gtk_entry_finalize (GObject *object)
2698 GtkEntry *entry = GTK_ENTRY (object);
2699 GtkEntryPrivate *priv = entry->priv;
2700 EntryIconInfo *icon_info = NULL;
2703 for (i = 0; i < MAX_ICONS; i++)
2705 if ((icon_info = priv->icons[i]) != NULL)
2707 if (icon_info->target_list != NULL)
2709 gtk_target_list_unref (icon_info->target_list);
2710 icon_info->target_list = NULL;
2713 g_clear_object (&icon_info->icon_helper);
2715 g_slice_free (EntryIconInfo, icon_info);
2716 priv->icons[i] = NULL;
2720 gtk_entry_set_completion (entry, NULL);
2722 if (priv->cached_layout)
2723 g_object_unref (priv->cached_layout);
2725 g_object_unref (priv->im_context);
2727 if (priv->blink_timeout)
2728 g_source_remove (priv->blink_timeout);
2730 if (priv->recompute_idle)
2731 g_source_remove (priv->recompute_idle);
2733 g_free (priv->placeholder_text);
2734 g_free (priv->im_module);
2736 G_OBJECT_CLASS (gtk_entry_parent_class)->finalize (object);
2740 gtk_entry_get_display_mode (GtkEntry *entry)
2742 GtkEntryPrivate *priv = entry->priv;
2745 return DISPLAY_NORMAL;
2747 if (priv->invisible_char == 0 && priv->invisible_char_set)
2748 return DISPLAY_BLANK;
2750 return DISPLAY_INVISIBLE;
2754 gtk_entry_get_display_text (GtkEntry *entry,
2758 GtkEntryPasswordHint *password_hint;
2759 GtkEntryPrivate *priv;
2760 gunichar invisible_char;
2771 text = gtk_entry_buffer_get_text (get_buffer (entry));
2772 length = gtk_entry_buffer_get_length (get_buffer (entry));
2776 if (start_pos > length)
2779 if (end_pos <= start_pos)
2780 return g_strdup ("");
2781 else if (priv->visible)
2783 start = g_utf8_offset_to_pointer (text, start_pos);
2784 end = g_utf8_offset_to_pointer (start, end_pos - start_pos);
2785 return g_strndup (start, end - start);
2789 str = g_string_sized_new (length * 2);
2791 /* Figure out what our invisible char is and encode it */
2792 if (!priv->invisible_char)
2793 invisible_char = priv->invisible_char_set ? ' ' : '*';
2795 invisible_char = priv->invisible_char;
2796 char_len = g_unichar_to_utf8 (invisible_char, char_str);
2799 * Add hidden characters for each character in the text
2800 * buffer. If there is a password hint, then keep that
2801 * character visible.
2804 password_hint = g_object_get_qdata (G_OBJECT (entry), quark_password_hint);
2805 for (i = start_pos; i < end_pos; ++i)
2807 if (password_hint && i == password_hint->position)
2809 start = g_utf8_offset_to_pointer (text, i);
2810 g_string_append_len (str, start, g_utf8_next_char (start) - start);
2814 g_string_append_len (str, char_str, char_len);
2818 return g_string_free (str, FALSE);
2823 update_cursors (GtkWidget *widget)
2825 GtkEntry *entry = GTK_ENTRY (widget);
2826 GtkEntryPrivate *priv = entry->priv;
2827 EntryIconInfo *icon_info = NULL;
2828 GdkDisplay *display;
2832 for (i = 0; i < MAX_ICONS; i++)
2834 if ((icon_info = priv->icons[i]) != NULL)
2836 if (!_gtk_icon_helper_get_is_empty (icon_info->icon_helper) &&
2837 icon_info->window != NULL)
2838 gdk_window_show_unraised (icon_info->window);
2840 /* The icon windows are not children of the visible entry window,
2841 * thus we can't just inherit the xterm cursor. Slight complication
2842 * here is that for the entry, insensitive => arrow cursor, but for
2843 * an icon in a sensitive entry, insensitive => xterm cursor.
2845 if (gtk_widget_is_sensitive (widget) &&
2846 (icon_info->insensitive ||
2847 (icon_info->nonactivatable && icon_info->target_list == NULL)))
2849 display = gtk_widget_get_display (widget);
2850 cursor = gdk_cursor_new_for_display (display, GDK_XTERM);
2851 gdk_window_set_cursor (icon_info->window, cursor);
2852 g_object_unref (cursor);
2856 gdk_window_set_cursor (icon_info->window, NULL);
2863 realize_icon_info (GtkWidget *widget,
2864 GtkEntryIconPosition icon_pos)
2866 GtkEntry *entry = GTK_ENTRY (widget);
2867 GtkEntryPrivate *priv = entry->priv;
2868 EntryIconInfo *icon_info = priv->icons[icon_pos];
2869 GdkWindowAttr attributes;
2870 gint attributes_mask;
2872 g_return_if_fail (icon_info != NULL);
2876 attributes.width = 1;
2877 attributes.height = 1;
2878 attributes.window_type = GDK_WINDOW_CHILD;
2879 attributes.wclass = GDK_INPUT_ONLY;
2880 attributes.event_mask = gtk_widget_get_events (widget);
2881 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
2882 GDK_BUTTON_RELEASE_MASK |
2883 GDK_BUTTON1_MOTION_MASK |
2884 GDK_BUTTON3_MOTION_MASK |
2885 GDK_POINTER_MOTION_HINT_MASK |
2886 GDK_POINTER_MOTION_MASK |
2887 GDK_ENTER_NOTIFY_MASK |
2888 GDK_LEAVE_NOTIFY_MASK);
2889 attributes_mask = GDK_WA_X | GDK_WA_Y;
2891 icon_info->window = gdk_window_new (gtk_widget_get_window (widget),
2894 gdk_window_set_user_data (icon_info->window, widget);
2896 gtk_widget_queue_resize (widget);
2899 static EntryIconInfo*
2900 construct_icon_info (GtkWidget *widget,
2901 GtkEntryIconPosition icon_pos)
2903 GtkEntry *entry = GTK_ENTRY (widget);
2904 GtkEntryPrivate *priv = entry->priv;
2905 EntryIconInfo *icon_info;
2907 g_return_val_if_fail (priv->icons[icon_pos] == NULL, NULL);
2909 icon_info = g_slice_new0 (EntryIconInfo);
2910 priv->icons[icon_pos] = icon_info;
2912 icon_info->icon_helper = _gtk_icon_helper_new ();
2914 if (gtk_widget_get_realized (widget))
2915 realize_icon_info (widget, icon_pos);
2921 gtk_entry_map (GtkWidget *widget)
2923 GtkEntry *entry = GTK_ENTRY (widget);
2924 GtkEntryPrivate *priv = entry->priv;
2925 EntryIconInfo *icon_info = NULL;
2928 GTK_WIDGET_CLASS (gtk_entry_parent_class)->map (widget);
2930 gdk_window_show (priv->text_area);
2932 for (i = 0; i < MAX_ICONS; i++)
2934 if ((icon_info = priv->icons[i]) != NULL)
2936 if (!_gtk_icon_helper_get_is_empty (icon_info->icon_helper) &&
2937 icon_info->window != NULL)
2938 gdk_window_show (icon_info->window);
2942 update_cursors (widget);
2946 gtk_entry_unmap (GtkWidget *widget)
2948 GtkEntry *entry = GTK_ENTRY (widget);
2949 GtkEntryPrivate *priv = entry->priv;
2950 EntryIconInfo *icon_info = NULL;
2953 for (i = 0; i < MAX_ICONS; i++)
2955 if ((icon_info = priv->icons[i]) != NULL)
2957 if (!_gtk_icon_helper_get_is_empty (icon_info->icon_helper) &&
2958 icon_info->window != NULL)
2959 gdk_window_hide (icon_info->window);
2963 gdk_window_hide (priv->text_area);
2965 GTK_WIDGET_CLASS (gtk_entry_parent_class)->unmap (widget);
2969 gtk_entry_realize (GtkWidget *widget)
2972 GtkEntryPrivate *priv;
2973 EntryIconInfo *icon_info;
2975 GdkWindowAttr attributes;
2976 gint attributes_mask;
2977 gint frame_x, frame_y;
2980 gtk_widget_set_realized (widget, TRUE);
2981 window = gtk_widget_get_parent_window (widget);
2982 gtk_widget_set_window (widget, window);
2983 g_object_ref (window);
2985 entry = GTK_ENTRY (widget);
2988 attributes.window_type = GDK_WINDOW_CHILD;
2989 attributes.wclass = GDK_INPUT_ONLY;
2990 attributes.event_mask = gtk_widget_get_events (widget);
2991 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
2992 GDK_BUTTON_RELEASE_MASK |
2993 GDK_BUTTON1_MOTION_MASK |
2994 GDK_BUTTON3_MOTION_MASK |
2995 GDK_POINTER_MOTION_HINT_MASK |
2996 GDK_POINTER_MOTION_MASK |
2997 GDK_ENTER_NOTIFY_MASK |
2998 GDK_LEAVE_NOTIFY_MASK);
2999 attributes_mask = GDK_WA_X | GDK_WA_Y;
3001 get_text_area_size (entry, &attributes.x, &attributes.y, &attributes.width, &attributes.height);
3003 get_frame_size (entry, TRUE, &frame_x, &frame_y, NULL, NULL);
3004 attributes.x += frame_x;
3005 attributes.y += frame_y;
3007 if (gtk_widget_is_sensitive (widget))
3009 attributes.cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
3010 attributes_mask |= GDK_WA_CURSOR;
3013 priv->text_area = gdk_window_new (gtk_widget_get_window (widget),
3017 gdk_window_set_user_data (priv->text_area, entry);
3019 if (attributes_mask & GDK_WA_CURSOR)
3020 g_object_unref (attributes.cursor);
3022 gtk_im_context_set_client_window (priv->im_context, priv->text_area);
3024 gtk_entry_adjust_scroll (entry);
3025 gtk_entry_update_primary_selection (entry);
3028 /* If the icon positions are already setup, create their windows.
3029 * Otherwise if they don't exist yet, then construct_icon_info()
3030 * will create the windows once the widget is already realized.
3032 for (i = 0; i < MAX_ICONS; i++)
3034 if ((icon_info = priv->icons[i]) != NULL)
3036 if (icon_info->window == NULL)
3037 realize_icon_info (widget, i);
3043 gtk_entry_unrealize (GtkWidget *widget)
3045 GtkEntry *entry = GTK_ENTRY (widget);
3046 GtkEntryPrivate *priv = entry->priv;
3047 GtkClipboard *clipboard;
3048 EntryIconInfo *icon_info;
3051 gtk_entry_reset_layout (entry);
3053 gtk_im_context_set_client_window (priv->im_context, NULL);
3055 clipboard = gtk_widget_get_clipboard (widget, GDK_SELECTION_PRIMARY);
3056 if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (entry))
3057 gtk_clipboard_clear (clipboard);
3059 if (priv->text_area)
3061 gdk_window_set_user_data (priv->text_area, NULL);
3062 gdk_window_destroy (priv->text_area);
3063 priv->text_area = NULL;
3066 if (priv->popup_menu)
3068 gtk_widget_destroy (priv->popup_menu);
3069 priv->popup_menu = NULL;
3072 GTK_WIDGET_CLASS (gtk_entry_parent_class)->unrealize (widget);
3074 for (i = 0; i < MAX_ICONS; i++)
3076 if ((icon_info = priv->icons[i]) != NULL)
3078 if (icon_info->window != NULL)
3080 gdk_window_destroy (icon_info->window);
3081 icon_info->window = NULL;
3088 _gtk_entry_get_borders (GtkEntry *entry,
3089 GtkBorder *border_out)
3091 GtkEntryPrivate *priv = entry->priv;
3092 GtkWidget *widget = GTK_WIDGET (entry);
3093 GtkBorder tmp = { 0, 0, 0, 0 };
3094 GtkStyleContext *context;
3096 context = gtk_widget_get_style_context (widget);
3097 gtk_style_context_get_padding (context, 0, &tmp);
3099 if (priv->has_frame)
3103 gtk_style_context_get_border (context, 0, &border);
3104 tmp.top += border.top;
3105 tmp.right += border.right;
3106 tmp.bottom += border.bottom;
3107 tmp.left += border.left;
3110 if (!priv->interior_focus)
3112 tmp.top += priv->focus_width;
3113 tmp.right += priv->focus_width;
3114 tmp.bottom += priv->focus_width;
3115 tmp.left += priv->focus_width;
3118 if (border_out != NULL)
3123 gtk_entry_get_preferred_width (GtkWidget *widget,
3127 GtkEntry *entry = GTK_ENTRY (widget);
3128 GtkEntryPrivate *priv = entry->priv;
3129 PangoFontMetrics *metrics;
3131 PangoContext *context;
3132 GtkStyleContext *style_context;
3133 GtkStateFlags state;
3134 gint icon_widths = 0;
3138 context = gtk_widget_get_pango_context (widget);
3140 style_context = gtk_widget_get_style_context (widget);
3141 state = gtk_widget_get_state_flags (widget);
3143 metrics = pango_context_get_metrics (context,
3144 gtk_style_context_get_font (style_context, state),
3145 pango_context_get_language (context));
3147 _gtk_entry_get_borders (entry, &borders);
3149 if (priv->width_chars < 0)
3150 width = MIN_ENTRY_WIDTH + borders.left + borders.right;
3153 gint char_width = pango_font_metrics_get_approximate_char_width (metrics);
3154 gint digit_width = pango_font_metrics_get_approximate_digit_width (metrics);
3155 gint char_pixels = (MAX (char_width, digit_width) + PANGO_SCALE - 1) / PANGO_SCALE;
3157 width = char_pixels * priv->width_chars + borders.left + borders.right;
3160 for (i = 0; i < MAX_ICONS; i++)
3162 icon_width = get_icon_width (entry, i);
3164 icon_widths += icon_width;
3167 if (icon_widths > width)
3168 width += icon_widths;
3170 pango_font_metrics_unref (metrics);
3177 gtk_entry_get_preferred_height (GtkWidget *widget,
3181 GtkEntry *entry = GTK_ENTRY (widget);
3182 GtkEntryPrivate *priv = entry->priv;
3183 PangoFontMetrics *metrics;
3185 GtkStyleContext *style_context;
3186 GtkStateFlags state;
3187 PangoContext *context;
3190 context = gtk_widget_get_pango_context (widget);
3192 style_context = gtk_widget_get_style_context (widget);
3193 state = gtk_widget_get_state_flags (widget);
3195 metrics = pango_context_get_metrics (context,
3196 gtk_style_context_get_font (style_context, state),
3197 pango_context_get_language (context));
3199 priv->ascent = pango_font_metrics_get_ascent (metrics);
3200 priv->descent = pango_font_metrics_get_descent (metrics);
3202 _gtk_entry_get_borders (entry, &borders);
3204 height = PANGO_PIXELS (priv->ascent + priv->descent) + borders.top + borders.bottom;
3206 pango_font_metrics_unref (metrics);
3213 place_windows (GtkEntry *entry)
3215 GtkWidget *widget = GTK_WIDGET (entry);
3216 GtkEntryPrivate *priv = entry->priv;
3217 gint x, y, width, height;
3218 gint frame_x, frame_y;
3219 GtkAllocation primary;
3220 GtkAllocation secondary;
3221 EntryIconInfo *icon_info = NULL;
3223 get_frame_size (entry, TRUE, &frame_x, &frame_y, NULL, NULL);
3224 get_text_area_size (entry, &x, &y, &width, &height);
3225 get_icon_allocations (entry, &primary, &secondary);
3227 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3228 y += priv->focus_width;
3230 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
3231 x += secondary.width;
3234 width -= primary.width + secondary.width;
3238 primary.x += frame_x;
3239 primary.y += frame_y;
3240 secondary.x += frame_x;
3241 secondary.y += frame_y;
3243 if ((icon_info = priv->icons[GTK_ENTRY_ICON_PRIMARY]) != NULL)
3244 gdk_window_move_resize (icon_info->window,
3245 primary.x, primary.y,
3246 primary.width, primary.height);
3248 if ((icon_info = priv->icons[GTK_ENTRY_ICON_SECONDARY]) != NULL)
3249 gdk_window_move_resize (icon_info->window,
3250 secondary.x, secondary.y,
3251 secondary.width, secondary.height);
3253 gdk_window_move_resize (priv->text_area, x, y, width, height);
3257 gtk_entry_get_text_area_size (GtkEntry *entry,
3263 GtkEntryPrivate *priv = entry->priv;
3264 GtkWidget *widget = GTK_WIDGET (entry);
3265 GtkAllocation allocation;
3266 GtkRequisition requisition;
3271 gtk_widget_get_preferred_size (widget, &requisition, NULL);
3272 req_height = requisition.height - gtk_widget_get_margin_top (widget) - gtk_widget_get_margin_bottom (widget);
3274 gtk_widget_get_allocation (widget, &allocation);
3275 _gtk_entry_get_borders (entry, &borders);
3277 if (gtk_widget_get_realized (widget))
3278 get_frame_size (entry, TRUE, NULL, NULL, NULL, &frame_height);
3280 frame_height = req_height;
3282 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3283 frame_height -= 2 * priv->focus_width;
3289 *y = floor ((frame_height - req_height) / 2) + borders.top;
3292 *width = allocation.width - borders.left - borders.right;
3295 *height = req_height - borders.top - borders.bottom;
3299 get_text_area_size (GtkEntry *entry,
3305 GtkEntryClass *class;
3307 g_return_if_fail (GTK_IS_ENTRY (entry));
3309 class = GTK_ENTRY_GET_CLASS (entry);
3311 if (class->get_text_area_size)
3312 class->get_text_area_size (entry, x, y, width, height);
3317 get_frame_size (GtkEntry *entry,
3318 gboolean relative_to_window,
3324 GtkEntryPrivate *priv = entry->priv;
3325 GtkAllocation allocation;
3326 GtkRequisition requisition;
3327 GtkWidget *widget = GTK_WIDGET (entry);
3330 gtk_widget_get_preferred_size (widget, &requisition, NULL);
3332 req_height = requisition.height - gtk_widget_get_margin_top (widget) - gtk_widget_get_margin_bottom (widget);
3334 gtk_widget_get_allocation (widget, &allocation);
3337 *x = relative_to_window ? allocation.x : 0;
3341 if (priv->is_cell_renderer)
3344 *y = (allocation.height - req_height) / 2;
3346 if (relative_to_window)
3351 *width = allocation.width;
3355 if (priv->is_cell_renderer)
3356 *height = allocation.height;
3358 *height = req_height;
3363 gtk_entry_size_allocate (GtkWidget *widget,
3364 GtkAllocation *allocation)
3366 GtkEntry *entry = GTK_ENTRY (widget);
3368 gtk_widget_set_allocation (widget, allocation);
3370 if (gtk_widget_get_realized (widget))
3372 GtkEntryCompletion* completion;
3374 place_windows (entry);
3375 gtk_entry_recompute (entry);
3377 completion = gtk_entry_get_completion (entry);
3378 if (completion && gtk_widget_get_mapped (completion->priv->popup_window))
3379 _gtk_entry_completion_resize_popup (completion);
3384 should_prelight (GtkEntry *entry,
3385 GtkEntryIconPosition icon_pos)
3387 GtkEntryPrivate *priv = entry->priv;
3388 EntryIconInfo *icon_info = priv->icons[icon_pos];
3394 if (icon_info->nonactivatable && icon_info->target_list == NULL)
3397 if (icon_info->pressed)
3400 gtk_widget_style_get (GTK_WIDGET (entry),
3401 "icon-prelight", &prelight,
3408 draw_icon (GtkWidget *widget,
3410 GtkEntryIconPosition icon_pos)
3412 GtkEntry *entry = GTK_ENTRY (widget);
3413 GtkEntryPrivate *priv = entry->priv;
3414 EntryIconInfo *icon_info = priv->icons[icon_pos];
3415 gint x, y, width, height, pix_width, pix_height;
3416 GtkStyleContext *context;
3422 width = gdk_window_get_width (icon_info->window);
3423 height = gdk_window_get_height (icon_info->window);
3425 /* size_allocate hasn't been called yet. These are the default values.
3427 if (width == 1 || height == 1)
3431 gtk_cairo_transform_to_window (cr, widget, icon_info->window);
3433 context = gtk_widget_get_style_context (widget);
3434 gtk_entry_prepare_context_for_icon (entry, context, icon_pos);
3435 _gtk_icon_helper_get_size (icon_info->icon_helper, context,
3436 &pix_width, &pix_height);
3437 gtk_style_context_get_padding (context, 0, &padding);
3439 x = MAX (0, padding.left);
3440 y = MAX (0, (height - pix_height) / 2);
3442 _gtk_icon_helper_draw (icon_info->icon_helper,
3446 gtk_style_context_restore (context);
3452 gtk_entry_draw_frame (GtkWidget *widget,
3453 GtkStyleContext *context,
3456 GtkEntry *entry = GTK_ENTRY (widget);
3457 GtkEntryPrivate *priv = entry->priv;
3458 gint x = 0, y = 0, width, height;
3459 gint frame_x, frame_y;
3463 get_frame_size (GTK_ENTRY (widget), FALSE, &frame_x, &frame_y, &width, &height);
3465 cairo_translate (cr, frame_x, frame_y);
3467 /* Fix a problem with some themes which assume that entry->text_area's
3468 * width equals widget->window's width
3469 * http://bugzilla.gnome.org/show_bug.cgi?id=466000 */
3470 if (GTK_IS_SPIN_BUTTON (widget))
3474 gtk_entry_get_text_area_size (GTK_ENTRY (widget), &x, NULL, &width, NULL);
3475 _gtk_entry_get_borders (GTK_ENTRY (widget), &borders);
3478 width += borders.left + borders.right;
3481 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3483 x += priv->focus_width;
3484 y += priv->focus_width;
3485 width -= 2 * priv->focus_width;
3486 height -= 2 * priv->focus_width;
3489 gtk_render_background (context, cr,
3490 x, y, width, height);
3492 if (priv->has_frame)
3493 gtk_render_frame (context, cr,
3494 x, y, width, height);
3496 gtk_entry_draw_progress (widget, context, cr);
3498 if (gtk_widget_has_visible_focus (widget) && !priv->interior_focus)
3500 x -= priv->focus_width;
3501 y -= priv->focus_width;
3502 width += 2 * priv->focus_width;
3503 height += 2 * priv->focus_width;
3505 gtk_render_focus (context, cr,
3506 0, 0, width, height);
3513 gtk_entry_prepare_context_for_progress (GtkEntry *entry,
3514 GtkStyleContext *context)
3516 GtkEntryPrivate *private = entry->priv;
3518 gtk_style_context_save (context);
3519 gtk_style_context_add_class (context, GTK_STYLE_CLASS_PROGRESSBAR);
3520 if (private->progress_pulse_mode)
3521 gtk_style_context_add_class (context, GTK_STYLE_CLASS_PULSE);
3525 get_progress_area (GtkWidget *widget,
3531 GtkEntry *entry = GTK_ENTRY (widget);
3532 GtkEntryPrivate *private = entry->priv;
3533 GtkStyleContext *context;
3534 GtkBorder margin, border, entry_borders;
3535 gint frame_width, text_area_width, text_area_height;
3537 context = gtk_widget_get_style_context (widget);
3538 _gtk_entry_get_borders (entry, &entry_borders);
3539 get_text_area_size (entry,
3541 &text_area_width, &text_area_height);
3542 get_frame_size (entry, FALSE,
3544 &frame_width, NULL);
3548 *width = text_area_width + entry_borders.left + entry_borders.right;
3549 *height = text_area_height + entry_borders.top + entry_borders.bottom;
3551 /* if the text area got resized by a subclass, subtract the left/right
3552 * border width, so that the progress bar won't extend over the resized
3555 if (frame_width > *width)
3557 gtk_style_context_get_border (context, 0, &border);
3558 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
3560 *x = (frame_width - *width) + border.left;
3561 *width -= border.left;
3565 *width -= border.right;
3569 gtk_entry_prepare_context_for_progress (entry, context);
3570 gtk_style_context_get_margin (context, 0, &margin);
3572 gtk_style_context_restore (context);
3576 *width -= margin.left + margin.right;
3577 *height -= margin.top + margin.bottom;
3579 if (private->progress_pulse_mode)
3581 gdouble value = private->progress_pulse_current;
3583 *x += (gint) floor(value * (*width));
3584 *width = (gint) ceil(private->progress_pulse_fraction * (*width));
3586 else if (private->progress_fraction > 0)
3588 gdouble value = private->progress_fraction;
3590 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
3594 bar_width = floor(value * (*width) + 0.5);
3595 *x += *width - bar_width;
3600 *width = (gint) floor(value * (*width) + 0.5);
3611 gtk_entry_draw_progress (GtkWidget *widget,
3612 GtkStyleContext *context,
3615 GtkEntry *entry = GTK_ENTRY (widget);
3616 gint x, y, width, height;
3618 get_progress_area (widget, &x, &y, &width, &height);
3620 if ((width <= 0) || (height <= 0))
3623 gtk_entry_prepare_context_for_progress (entry, context);
3624 gtk_render_activity (context, cr,
3625 x, y, width, height);
3627 gtk_style_context_restore (context);
3631 gtk_entry_draw (GtkWidget *widget,
3634 GtkEntry *entry = GTK_ENTRY (widget);
3635 GtkStyleContext *context;
3636 GtkEntryPrivate *priv = entry->priv;
3639 context = gtk_widget_get_style_context (widget);
3641 /* Draw entry_bg, shadow, progress and focus */
3642 gtk_entry_draw_frame (widget, context, cr);
3644 /* Draw text and cursor */
3647 gtk_cairo_transform_to_window (cr, widget, priv->text_area);
3649 if (priv->dnd_position != -1)
3650 gtk_entry_draw_cursor (GTK_ENTRY (widget), cr, CURSOR_DND);
3652 gtk_entry_draw_text (GTK_ENTRY (widget), cr);
3654 /* When no text is being displayed at all, don't show the cursor */
3655 if (gtk_entry_get_display_mode (entry) != DISPLAY_BLANK &&
3656 gtk_widget_has_focus (widget) &&
3657 priv->selection_bound == priv->current_pos && priv->cursor_visible)
3658 gtk_entry_draw_cursor (GTK_ENTRY (widget), cr, CURSOR_STANDARD);
3663 for (i = 0; i < MAX_ICONS; i++)
3665 EntryIconInfo *icon_info = priv->icons[i];
3667 if (icon_info != NULL)
3668 draw_icon (widget, cr, i);
3675 gtk_entry_enter_notify (GtkWidget *widget,
3676 GdkEventCrossing *event)
3678 GtkEntry *entry = GTK_ENTRY (widget);
3679 GtkEntryPrivate *priv = entry->priv;
3682 for (i = 0; i < MAX_ICONS; i++)
3684 EntryIconInfo *icon_info = priv->icons[i];
3686 if (icon_info != NULL && event->window == icon_info->window)
3688 if (should_prelight (entry, i))
3690 icon_info->prelight = TRUE;
3691 gtk_widget_queue_draw (widget);
3702 gtk_entry_leave_notify (GtkWidget *widget,
3703 GdkEventCrossing *event)
3705 GtkEntry *entry = GTK_ENTRY (widget);
3706 GtkEntryPrivate *priv = entry->priv;
3709 for (i = 0; i < MAX_ICONS; i++)
3711 EntryIconInfo *icon_info = priv->icons[i];
3713 if (icon_info != NULL && event->window == icon_info->window)
3715 /* a grab means that we may never see the button release */
3716 if (event->mode == GDK_CROSSING_GRAB || event->mode == GDK_CROSSING_GTK_GRAB)
3717 icon_info->pressed = FALSE;
3719 if (should_prelight (entry, i))
3721 icon_info->prelight = FALSE;
3722 gtk_widget_queue_draw (widget);
3733 gtk_entry_get_pixel_ranges (GtkEntry *entry,
3737 gint start_char, end_char;
3739 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start_char, &end_char))
3741 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
3742 PangoLayoutLine *line = pango_layout_get_lines_readonly (layout)->data;
3743 const char *text = pango_layout_get_text (layout);
3744 gint start_index = g_utf8_offset_to_pointer (text, start_char) - text;
3745 gint end_index = g_utf8_offset_to_pointer (text, end_char) - text;
3746 gint real_n_ranges, i;
3748 pango_layout_line_get_x_ranges (line, start_index, end_index, ranges, &real_n_ranges);
3754 for (i = 0; i < real_n_ranges; ++i)
3756 r[2 * i + 1] = (r[2 * i + 1] - r[2 * i]) / PANGO_SCALE;
3757 r[2 * i] = r[2 * i] / PANGO_SCALE;
3762 *n_ranges = real_n_ranges;
3774 in_selection (GtkEntry *entry,
3779 gint retval = FALSE;
3781 gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
3783 for (i = 0; i < n_ranges; ++i)
3785 if (x >= ranges[2 * i] && x < ranges[2 * i] + ranges[2 * i + 1])
3797 gtk_entry_button_press (GtkWidget *widget,
3798 GdkEventButton *event)
3800 GtkEntry *entry = GTK_ENTRY (widget);
3801 GtkEditable *editable = GTK_EDITABLE (widget);
3802 GtkEntryPrivate *priv = entry->priv;
3803 EntryIconInfo *icon_info = NULL;
3805 gint sel_start, sel_end;
3808 for (i = 0; i < MAX_ICONS; i++)
3810 icon_info = priv->icons[i];
3812 if (!icon_info || icon_info->insensitive)
3815 if (event->window == icon_info->window)
3817 if (should_prelight (entry, i))
3819 icon_info->prelight = FALSE;
3820 gtk_widget_queue_draw (widget);
3823 priv->start_x = event->x;
3824 priv->start_y = event->y;
3825 icon_info->pressed = TRUE;
3827 if (!icon_info->nonactivatable)
3828 g_signal_emit (entry, signals[ICON_PRESS], 0, i, event);
3834 if (event->window != priv->text_area ||
3835 (priv->button && event->button != priv->button))
3838 gtk_entry_reset_blink_time (entry);
3840 priv->button = event->button;
3841 priv->device = gdk_event_get_device ((GdkEvent *) event);
3843 if (!gtk_widget_has_focus (widget))
3845 priv->in_click = TRUE;
3846 gtk_widget_grab_focus (widget);
3847 priv->in_click = FALSE;
3850 tmp_pos = gtk_entry_find_position (entry, event->x + priv->scroll_offset);
3852 if (gdk_event_triggers_context_menu ((GdkEvent *) event))
3854 gtk_entry_do_popup (entry, event);
3855 priv->button = 0; /* Don't wait for release, since the menu will gtk_grab_add */
3856 priv->device = NULL;
3860 else if (event->button == GDK_BUTTON_PRIMARY)
3862 gboolean have_selection = gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end);
3864 priv->select_words = FALSE;
3865 priv->select_lines = FALSE;
3868 gtk_widget_get_modifier_mask (widget,
3869 GDK_MODIFIER_INTENT_EXTEND_SELECTION))
3871 _gtk_entry_reset_im_context (entry);
3873 if (!have_selection) /* select from the current position to the clicked position */
3874 sel_start = sel_end = priv->current_pos;
3876 if (tmp_pos > sel_start && tmp_pos < sel_end)
3878 /* Truncate current selection, but keep it as big as possible */
3879 if (tmp_pos - sel_start > sel_end - tmp_pos)
3880 gtk_entry_set_positions (entry, sel_start, tmp_pos);
3882 gtk_entry_set_positions (entry, tmp_pos, sel_end);
3886 gboolean extend_to_left;
3889 /* Figure out what click selects and extend current selection */
3890 switch (event->type)
3892 case GDK_BUTTON_PRESS:
3893 gtk_entry_set_positions (entry, tmp_pos, tmp_pos);
3896 case GDK_2BUTTON_PRESS:
3897 priv->select_words = TRUE;
3898 gtk_entry_select_word (entry);
3901 case GDK_3BUTTON_PRESS:
3902 priv->select_lines = TRUE;
3903 gtk_entry_select_line (entry);
3910 start = MIN (priv->current_pos, priv->selection_bound);
3911 start = MIN (sel_start, start);
3913 end = MAX (priv->current_pos, priv->selection_bound);
3914 end = MAX (sel_end, end);
3916 if (tmp_pos == sel_start || tmp_pos == sel_end)
3917 extend_to_left = (tmp_pos == start);
3919 extend_to_left = (end == sel_end);
3922 gtk_entry_set_positions (entry, start, end);
3924 gtk_entry_set_positions (entry, end, start);
3927 else /* no shift key */
3928 switch (event->type)
3930 case GDK_BUTTON_PRESS:
3931 if (in_selection (entry, event->x + priv->scroll_offset))
3933 /* Click inside the selection - we'll either start a drag, or
3934 * clear the selection
3936 priv->in_drag = TRUE;
3937 priv->drag_start_x = event->x + priv->scroll_offset;
3938 priv->drag_start_y = event->y;
3941 gtk_editable_set_position (editable, tmp_pos);
3944 case GDK_2BUTTON_PRESS:
3945 /* We ALWAYS receive a GDK_BUTTON_PRESS immediately before
3946 * receiving a GDK_2BUTTON_PRESS so we need to reset
3947 * priv->in_drag which may have been set above
3949 priv->in_drag = FALSE;
3950 priv->select_words = TRUE;
3951 gtk_entry_select_word (entry);
3954 case GDK_3BUTTON_PRESS:
3955 /* We ALWAYS receive a GDK_BUTTON_PRESS immediately before
3956 * receiving a GDK_3BUTTON_PRESS so we need to reset
3957 * priv->in_drag which may have been set above
3959 priv->in_drag = FALSE;
3960 priv->select_lines = TRUE;
3961 gtk_entry_select_line (entry);
3970 else if (event->type == GDK_BUTTON_PRESS &&
3971 event->button == GDK_BUTTON_MIDDLE &&
3972 get_middle_click_paste (entry))
3976 priv->insert_pos = tmp_pos;
3977 gtk_entry_paste (entry, GDK_SELECTION_PRIMARY);
3982 gtk_widget_error_bell (widget);
3990 gtk_entry_button_release (GtkWidget *widget,
3991 GdkEventButton *event)
3993 GtkEntry *entry = GTK_ENTRY (widget);
3994 GtkEntryPrivate *priv = entry->priv;
3995 EntryIconInfo *icon_info = NULL;
3998 for (i = 0; i < MAX_ICONS; i++)
4000 icon_info = priv->icons[i];
4002 if (!icon_info || icon_info->insensitive)
4005 if (event->window == icon_info->window)
4007 icon_info->pressed = FALSE;
4009 if (should_prelight (entry, i) &&
4010 event->x >= 0 && event->y >= 0 &&
4011 event->x < gdk_window_get_width (icon_info->window) &&
4012 event->y < gdk_window_get_height (icon_info->window))
4014 icon_info->prelight = TRUE;
4015 gtk_widget_queue_draw (widget);
4018 if (!icon_info->nonactivatable)
4019 g_signal_emit (entry, signals[ICON_RELEASE], 0, i, event);
4025 if (event->window != priv->text_area || priv->button != event->button)
4030 gint tmp_pos = gtk_entry_find_position (entry, priv->drag_start_x);
4032 gtk_editable_set_position (GTK_EDITABLE (entry), tmp_pos);
4038 priv->device = NULL;
4040 gtk_entry_update_primary_selection (entry);
4046 _gtk_entry_get_selected_text (GtkEntry *entry)
4048 GtkEditable *editable = GTK_EDITABLE (entry);
4049 gint start_text, end_text;
4052 if (gtk_editable_get_selection_bounds (editable, &start_text, &end_text))
4053 text = gtk_editable_get_chars (editable, start_text, end_text);
4059 gtk_entry_motion_notify (GtkWidget *widget,
4060 GdkEventMotion *event)
4062 GtkEntry *entry = GTK_ENTRY (widget);
4063 GtkEntryPrivate *priv = entry->priv;
4064 EntryIconInfo *icon_info = NULL;
4068 for (i = 0; i < MAX_ICONS; i++)
4070 icon_info = priv->icons[i];
4072 if (!icon_info || icon_info->insensitive)
4075 if (event->window == icon_info->window)
4077 if (icon_info->pressed &&
4078 icon_info->target_list != NULL &&
4079 gtk_drag_check_threshold (widget,
4085 icon_info->in_drag = TRUE;
4086 icon_info->pressed = FALSE;
4087 gtk_drag_begin (widget,
4088 icon_info->target_list,
4098 if (priv->mouse_cursor_obscured)
4102 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
4103 gdk_window_set_cursor (priv->text_area, cursor);
4104 g_object_unref (cursor);
4105 priv->mouse_cursor_obscured = FALSE;
4108 if (event->window != priv->text_area || priv->button != GDK_BUTTON_PRIMARY)
4111 if (priv->select_lines)
4114 gdk_event_request_motions (event);
4118 if (gtk_entry_get_display_mode (entry) == DISPLAY_NORMAL &&
4119 gtk_drag_check_threshold (widget,
4120 priv->drag_start_x, priv->drag_start_y,
4121 event->x + priv->scroll_offset, event->y))
4123 GdkDragContext *context;
4124 GtkTargetList *target_list = gtk_target_list_new (NULL, 0);
4125 guint actions = priv->editable ? GDK_ACTION_COPY | GDK_ACTION_MOVE : GDK_ACTION_COPY;
4127 cairo_surface_t *surface;
4129 gtk_target_list_add_text_targets (target_list, 0);
4131 text = _gtk_entry_get_selected_text (entry);
4132 surface = _gtk_text_util_create_drag_icon (widget, text, -1);
4134 context = gtk_drag_begin (widget, target_list, actions,
4135 priv->button, (GdkEvent *)event);
4138 gtk_drag_set_icon_surface (context, surface);
4140 gtk_drag_set_icon_default (context);
4143 cairo_surface_destroy (surface);
4146 priv->in_drag = FALSE;
4148 priv->device = NULL;
4150 gtk_target_list_unref (target_list);
4157 else if (event->y >= gdk_window_get_height (priv->text_area))
4158 tmp_pos = gtk_entry_buffer_get_length (get_buffer (entry));
4160 tmp_pos = gtk_entry_find_position (entry, event->x + priv->scroll_offset);
4162 if (priv->select_words)
4165 gint old_min, old_max;
4168 min = gtk_entry_move_backward_word (entry, tmp_pos, TRUE);
4169 max = gtk_entry_move_forward_word (entry, tmp_pos, TRUE);
4171 pos = priv->current_pos;
4172 bound = priv->selection_bound;
4174 old_min = MIN(priv->current_pos, priv->selection_bound);
4175 old_max = MAX(priv->current_pos, priv->selection_bound);
4182 else if (old_max < max)
4187 else if (pos == old_min)
4189 if (priv->current_pos != min)
4194 if (priv->current_pos != max)
4198 gtk_entry_set_positions (entry, pos, bound);
4201 gtk_entry_set_positions (entry, tmp_pos, -1);
4208 set_invisible_cursor (GdkWindow *window)
4210 GdkDisplay *display;
4213 display = gdk_window_get_display (window);
4214 cursor = gdk_cursor_new_for_display (display, GDK_BLANK_CURSOR);
4216 gdk_window_set_cursor (window, cursor);
4218 g_object_unref (cursor);
4222 gtk_entry_obscure_mouse_cursor (GtkEntry *entry)
4224 GtkEntryPrivate *priv = entry->priv;
4226 if (priv->mouse_cursor_obscured)
4229 set_invisible_cursor (priv->text_area);
4231 priv->mouse_cursor_obscured = TRUE;
4235 gtk_entry_key_press (GtkWidget *widget,
4238 GtkEntry *entry = GTK_ENTRY (widget);
4239 GtkEntryPrivate *priv = entry->priv;
4241 gtk_entry_reset_blink_time (entry);
4242 gtk_entry_pend_cursor_blink (entry);
4246 if (gtk_im_context_filter_keypress (priv->im_context, event))
4248 gtk_entry_obscure_mouse_cursor (entry);
4249 priv->need_im_reset = TRUE;
4254 if (event->keyval == GDK_KEY_Return ||
4255 event->keyval == GDK_KEY_KP_Enter ||
4256 event->keyval == GDK_KEY_ISO_Enter ||
4257 event->keyval == GDK_KEY_Escape)
4259 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
4261 if (completion && completion->priv->completion_timeout)
4263 g_source_remove (completion->priv->completion_timeout);
4264 completion->priv->completion_timeout = 0;
4267 _gtk_entry_reset_im_context (entry);
4270 if (GTK_WIDGET_CLASS (gtk_entry_parent_class)->key_press_event (widget, event))
4271 /* Activate key bindings
4275 if (!priv->editable && event->length)
4276 gtk_widget_error_bell (widget);
4282 gtk_entry_key_release (GtkWidget *widget,
4285 GtkEntry *entry = GTK_ENTRY (widget);
4286 GtkEntryPrivate *priv = entry->priv;
4290 if (gtk_im_context_filter_keypress (priv->im_context, event))
4292 priv->need_im_reset = TRUE;
4297 return GTK_WIDGET_CLASS (gtk_entry_parent_class)->key_release_event (widget, event);
4301 gtk_entry_focus_in (GtkWidget *widget,
4302 GdkEventFocus *event)
4304 GtkEntry *entry = GTK_ENTRY (widget);
4305 GtkEntryPrivate *priv = entry->priv;
4308 gtk_widget_queue_draw (widget);
4310 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (widget));
4314 priv->need_im_reset = TRUE;
4315 gtk_im_context_focus_in (priv->im_context);
4316 keymap_state_changed (keymap, entry);
4317 g_signal_connect (keymap, "state-changed",
4318 G_CALLBACK (keymap_state_changed), entry);
4321 g_signal_connect (keymap, "direction-changed",
4322 G_CALLBACK (keymap_direction_changed), entry);
4324 if (gtk_entry_buffer_get_bytes (get_buffer (entry)) == 0 &&
4325 priv->placeholder_text != NULL)
4327 gtk_entry_recompute (entry);
4331 gtk_entry_reset_blink_time (entry);
4332 gtk_entry_check_cursor_blink (entry);
4339 gtk_entry_focus_out (GtkWidget *widget,
4340 GdkEventFocus *event)
4342 GtkEntry *entry = GTK_ENTRY (widget);
4343 GtkEntryPrivate *priv = entry->priv;
4344 GtkEntryCompletion *completion;
4347 gtk_widget_queue_draw (widget);
4349 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (widget));
4353 priv->need_im_reset = TRUE;
4354 gtk_im_context_focus_out (priv->im_context);
4355 remove_capslock_feedback (entry);
4358 if (gtk_entry_buffer_get_bytes (get_buffer (entry)) == 0 &&
4359 priv->placeholder_text != NULL)
4361 gtk_entry_recompute (entry);
4365 gtk_entry_check_cursor_blink (entry);
4368 g_signal_handlers_disconnect_by_func (keymap, keymap_state_changed, entry);
4369 g_signal_handlers_disconnect_by_func (keymap, keymap_direction_changed, entry);
4371 completion = gtk_entry_get_completion (entry);
4373 _gtk_entry_completion_popdown (completion);
4379 gtk_entry_grab_focus (GtkWidget *widget)
4381 GtkEntry *entry = GTK_ENTRY (widget);
4382 GtkEntryPrivate *priv = entry->priv;
4383 gboolean select_on_focus;
4385 GTK_WIDGET_CLASS (gtk_entry_parent_class)->grab_focus (widget);
4387 if (priv->editable && !priv->in_click)
4389 g_object_get (gtk_widget_get_settings (widget),
4390 "gtk-entry-select-on-focus",
4394 if (select_on_focus)
4395 gtk_editable_select_region (GTK_EDITABLE (widget), 0, -1);
4400 gtk_entry_direction_changed (GtkWidget *widget,
4401 GtkTextDirection previous_dir)
4403 GtkEntry *entry = GTK_ENTRY (widget);
4405 gtk_entry_recompute (entry);
4407 GTK_WIDGET_CLASS (gtk_entry_parent_class)->direction_changed (widget, previous_dir);
4411 gtk_entry_state_flags_changed (GtkWidget *widget,
4412 GtkStateFlags previous_state)
4414 GtkEntry *entry = GTK_ENTRY (widget);
4415 GtkEntryPrivate *priv = entry->priv;
4418 if (gtk_widget_get_realized (widget))
4420 if (gtk_widget_is_sensitive (widget))
4421 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
4425 gdk_window_set_cursor (priv->text_area, cursor);
4428 g_object_unref (cursor);
4430 priv->mouse_cursor_obscured = FALSE;
4432 update_cursors (widget);
4435 if (!gtk_widget_is_sensitive (widget))
4437 /* Clear any selection */
4438 gtk_editable_select_region (GTK_EDITABLE (entry), priv->current_pos, priv->current_pos);
4441 gtk_entry_update_cached_style_values (entry);
4445 gtk_entry_screen_changed (GtkWidget *widget,
4446 GdkScreen *old_screen)
4448 gtk_entry_recompute (GTK_ENTRY (widget));
4451 /* GtkEditable method implementations
4454 gtk_entry_insert_text (GtkEditable *editable,
4455 const gchar *new_text,
4456 gint new_text_length,
4459 g_object_ref (editable);
4462 * The incoming text may a password or other secret. We make sure
4463 * not to copy it into temporary buffers.
4466 g_signal_emit_by_name (editable, "insert-text", new_text, new_text_length, position);
4468 g_object_unref (editable);
4472 gtk_entry_delete_text (GtkEditable *editable,
4476 g_object_ref (editable);
4478 g_signal_emit_by_name (editable, "delete-text", start_pos, end_pos);
4480 g_object_unref (editable);
4484 gtk_entry_get_chars (GtkEditable *editable,
4488 GtkEntry *entry = GTK_ENTRY (editable);
4491 gint start_index, end_index;
4493 text = gtk_entry_buffer_get_text (get_buffer (entry));
4494 text_length = gtk_entry_buffer_get_length (get_buffer (entry));
4497 end_pos = text_length;
4499 start_pos = MIN (text_length, start_pos);
4500 end_pos = MIN (text_length, end_pos);
4502 start_index = g_utf8_offset_to_pointer (text, start_pos) - text;
4503 end_index = g_utf8_offset_to_pointer (text, end_pos) - text;
4505 return g_strndup (text + start_index, end_index - start_index);
4509 gtk_entry_real_set_position (GtkEditable *editable,
4512 GtkEntry *entry = GTK_ENTRY (editable);
4513 GtkEntryPrivate *priv = entry->priv;
4517 length = gtk_entry_buffer_get_length (get_buffer (entry));
4518 if (position < 0 || position > length)
4521 if (position != priv->current_pos ||
4522 position != priv->selection_bound)
4524 _gtk_entry_reset_im_context (entry);
4525 gtk_entry_set_positions (entry, position, position);
4530 gtk_entry_get_position (GtkEditable *editable)
4532 GtkEntry *entry = GTK_ENTRY (editable);
4533 GtkEntryPrivate *priv = entry->priv;
4535 return priv->current_pos;
4539 gtk_entry_set_selection_bounds (GtkEditable *editable,
4543 GtkEntry *entry = GTK_ENTRY (editable);
4546 length = gtk_entry_buffer_get_length (get_buffer (entry));
4552 _gtk_entry_reset_im_context (entry);
4554 gtk_entry_set_positions (entry,
4556 MIN (start, length));
4558 gtk_entry_update_primary_selection (entry);
4562 gtk_entry_get_selection_bounds (GtkEditable *editable,
4566 GtkEntry *entry = GTK_ENTRY (editable);
4567 GtkEntryPrivate *priv = entry->priv;
4569 *start = priv->selection_bound;
4570 *end = priv->current_pos;
4572 return (priv->selection_bound != priv->current_pos);
4576 icon_theme_changed (GtkEntry *entry)
4578 GtkEntryPrivate *priv = entry->priv;
4581 for (i = 0; i < MAX_ICONS; i++)
4583 EntryIconInfo *icon_info = priv->icons[i];
4584 if (icon_info != NULL)
4585 _gtk_icon_helper_invalidate (icon_info->icon_helper);
4588 gtk_widget_queue_draw (GTK_WIDGET (entry));
4592 gtk_entry_update_cached_style_values (GtkEntry *entry)
4594 GtkEntryPrivate *priv = entry->priv;
4596 gboolean interior_focus;
4598 gtk_widget_style_get (GTK_WIDGET (entry),
4599 "focus-line-width", &focus_width,
4600 "interior-focus", &interior_focus,
4602 priv->focus_width = focus_width;
4603 priv->interior_focus = interior_focus;
4605 if (!priv->invisible_char_set)
4607 gunichar ch = find_invisible_char (GTK_WIDGET (entry));
4609 if (priv->invisible_char != ch)
4611 priv->invisible_char = ch;
4612 g_object_notify (G_OBJECT (entry), "invisible-char");
4618 gtk_entry_style_updated (GtkWidget *widget)
4620 GtkEntry *entry = GTK_ENTRY (widget);
4622 GTK_WIDGET_CLASS (gtk_entry_parent_class)->style_updated (widget);
4624 gtk_entry_update_cached_style_values (entry);
4626 gtk_entry_recompute (entry);
4628 icon_theme_changed (entry);
4631 /* GtkCellEditable method implementations
4634 gtk_cell_editable_entry_activated (GtkEntry *entry, gpointer data)
4636 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4637 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4641 gtk_cell_editable_key_press_event (GtkEntry *entry,
4642 GdkEventKey *key_event,
4645 GtkEntryPrivate *priv = entry->priv;
4647 if (key_event->keyval == GDK_KEY_Escape)
4649 priv->editing_canceled = TRUE;
4650 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4651 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4656 /* override focus */
4657 if (key_event->keyval == GDK_KEY_Up || key_event->keyval == GDK_KEY_Down)
4659 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4660 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4669 gtk_entry_start_editing (GtkCellEditable *cell_editable,
4672 GtkEntry *entry = GTK_ENTRY (cell_editable);
4673 GtkEntryPrivate *priv = entry->priv;
4675 priv->is_cell_renderer = TRUE;
4677 g_signal_connect (cell_editable, "activate",
4678 G_CALLBACK (gtk_cell_editable_entry_activated), NULL);
4679 g_signal_connect (cell_editable, "key-press-event",
4680 G_CALLBACK (gtk_cell_editable_key_press_event), NULL);
4684 gtk_entry_password_hint_free (GtkEntryPasswordHint *password_hint)
4686 if (password_hint->source_id)
4687 g_source_remove (password_hint->source_id);
4689 g_slice_free (GtkEntryPasswordHint, password_hint);
4694 gtk_entry_remove_password_hint (gpointer data)
4696 GtkEntryPasswordHint *password_hint = g_object_get_qdata (data, quark_password_hint);
4697 password_hint->position = -1;
4699 /* Force the string to be redrawn, but now without a visible character */
4700 gtk_entry_recompute (GTK_ENTRY (data));
4704 /* Default signal handlers
4707 gtk_entry_real_insert_text (GtkEditable *editable,
4708 const gchar *new_text,
4709 gint new_text_length,
4715 n_chars = g_utf8_strlen (new_text, new_text_length);
4718 * The actual insertion into the buffer. This will end up firing the
4719 * following signal handlers: buffer_inserted_text(), buffer_notify_display_text(),
4720 * buffer_notify_text(), buffer_notify_length()
4722 begin_change (GTK_ENTRY (editable));
4724 n_inserted = gtk_entry_buffer_insert_text (get_buffer (GTK_ENTRY (editable)), *position, new_text, n_chars);
4726 end_change (GTK_ENTRY (editable));
4728 if (n_inserted != n_chars)
4729 gtk_widget_error_bell (GTK_WIDGET (editable));
4731 *position += n_inserted;
4735 gtk_entry_real_delete_text (GtkEditable *editable,
4740 * The actual deletion from the buffer. This will end up firing the
4741 * following signal handlers: buffer_deleted_text(), buffer_notify_display_text(),
4742 * buffer_notify_text(), buffer_notify_length()
4745 begin_change (GTK_ENTRY (editable));
4747 gtk_entry_buffer_delete_text (get_buffer (GTK_ENTRY (editable)), start_pos, end_pos - start_pos);
4749 end_change (GTK_ENTRY (editable));
4752 /* GtkEntryBuffer signal handlers
4755 buffer_inserted_text (GtkEntryBuffer *buffer,
4761 GtkEntryPrivate *priv = entry->priv;
4762 guint password_hint_timeout;
4764 gint selection_bound;
4766 current_pos = priv->current_pos;
4767 if (current_pos > position)
4768 current_pos += n_chars;
4770 selection_bound = priv->selection_bound;
4771 if (selection_bound > position)
4772 selection_bound += n_chars;
4774 gtk_entry_set_positions (entry, current_pos, selection_bound);
4776 /* Calculate the password hint if it needs to be displayed. */
4777 if (n_chars == 1 && !priv->visible)
4779 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
4780 "gtk-entry-password-hint-timeout", &password_hint_timeout,
4783 if (password_hint_timeout > 0)
4785 GtkEntryPasswordHint *password_hint = g_object_get_qdata (G_OBJECT (entry),
4786 quark_password_hint);
4789 password_hint = g_slice_new0 (GtkEntryPasswordHint);
4790 g_object_set_qdata_full (G_OBJECT (entry), quark_password_hint, password_hint,
4791 (GDestroyNotify)gtk_entry_password_hint_free);
4794 password_hint->position = position;
4795 if (password_hint->source_id)
4796 g_source_remove (password_hint->source_id);
4797 password_hint->source_id = gdk_threads_add_timeout (password_hint_timeout,
4798 (GSourceFunc)gtk_entry_remove_password_hint, entry);
4804 buffer_deleted_text (GtkEntryBuffer *buffer,
4809 GtkEntryPrivate *priv = entry->priv;
4810 guint end_pos = position + n_chars;
4811 gint selection_bound;
4814 current_pos = priv->current_pos;
4815 if (current_pos > position)
4816 current_pos -= MIN (current_pos, end_pos) - position;
4818 selection_bound = priv->selection_bound;
4819 if (selection_bound > position)
4820 selection_bound -= MIN (selection_bound, end_pos) - position;
4822 gtk_entry_set_positions (entry, current_pos, selection_bound);
4824 /* We might have deleted the selection */
4825 gtk_entry_update_primary_selection (entry);
4827 /* Disable the password hint if one exists. */
4830 GtkEntryPasswordHint *password_hint = g_object_get_qdata (G_OBJECT (entry),
4831 quark_password_hint);
4834 if (password_hint->source_id)
4835 g_source_remove (password_hint->source_id);
4836 password_hint->source_id = 0;
4837 password_hint->position = -1;
4843 buffer_notify_text (GtkEntryBuffer *buffer,
4847 gtk_entry_recompute (entry);
4848 emit_changed (entry);
4849 g_object_notify (G_OBJECT (entry), "text");
4853 buffer_notify_length (GtkEntryBuffer *buffer,
4857 g_object_notify (G_OBJECT (entry), "text-length");
4861 buffer_notify_max_length (GtkEntryBuffer *buffer,
4865 g_object_notify (G_OBJECT (entry), "max-length");
4869 buffer_connect_signals (GtkEntry *entry)
4871 g_signal_connect (get_buffer (entry), "inserted-text", G_CALLBACK (buffer_inserted_text), entry);
4872 g_signal_connect (get_buffer (entry), "deleted-text", G_CALLBACK (buffer_deleted_text), entry);
4873 g_signal_connect (get_buffer (entry), "notify::text", G_CALLBACK (buffer_notify_text), entry);
4874 g_signal_connect (get_buffer (entry), "notify::length", G_CALLBACK (buffer_notify_length), entry);
4875 g_signal_connect (get_buffer (entry), "notify::max-length", G_CALLBACK (buffer_notify_max_length), entry);
4879 buffer_disconnect_signals (GtkEntry *entry)
4881 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_inserted_text, entry);
4882 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_deleted_text, entry);
4883 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_text, entry);
4884 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_length, entry);
4885 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_max_length, entry);
4888 /* Compute the X position for an offset that corresponds to the "more important
4889 * cursor position for that offset. We use this when trying to guess to which
4890 * end of the selection we should go to when the user hits the left or
4894 get_better_cursor_x (GtkEntry *entry,
4897 GtkEntryPrivate *priv = entry->priv;
4898 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
4899 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
4900 gboolean split_cursor;
4902 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
4903 const gchar *text = pango_layout_get_text (layout);
4904 gint index = g_utf8_offset_to_pointer (text, offset) - text;
4906 PangoRectangle strong_pos, weak_pos;
4908 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
4909 "gtk-split-cursor", &split_cursor,
4912 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
4915 return strong_pos.x / PANGO_SCALE;
4917 return (keymap_direction == priv->resolved_dir) ? strong_pos.x / PANGO_SCALE : weak_pos.x / PANGO_SCALE;
4921 gtk_entry_move_cursor (GtkEntry *entry,
4922 GtkMovementStep step,
4924 gboolean extend_selection)
4926 GtkEntryPrivate *priv = entry->priv;
4927 gint new_pos = priv->current_pos;
4929 _gtk_entry_reset_im_context (entry);
4931 if (priv->current_pos != priv->selection_bound && !extend_selection)
4933 /* If we have a current selection and aren't extending it, move to the
4934 * start/or end of the selection as appropriate
4938 case GTK_MOVEMENT_VISUAL_POSITIONS:
4940 gint current_x = get_better_cursor_x (entry, priv->current_pos);
4941 gint bound_x = get_better_cursor_x (entry, priv->selection_bound);
4944 new_pos = current_x < bound_x ? priv->current_pos : priv->selection_bound;
4946 new_pos = current_x > bound_x ? priv->current_pos : priv->selection_bound;
4949 case GTK_MOVEMENT_LOGICAL_POSITIONS:
4950 case GTK_MOVEMENT_WORDS:
4952 new_pos = MIN (priv->current_pos, priv->selection_bound);
4954 new_pos = MAX (priv->current_pos, priv->selection_bound);
4956 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
4957 case GTK_MOVEMENT_PARAGRAPH_ENDS:
4958 case GTK_MOVEMENT_BUFFER_ENDS:
4959 new_pos = count < 0 ? 0 : gtk_entry_buffer_get_length (get_buffer (entry));
4961 case GTK_MOVEMENT_DISPLAY_LINES:
4962 case GTK_MOVEMENT_PARAGRAPHS:
4963 case GTK_MOVEMENT_PAGES:
4964 case GTK_MOVEMENT_HORIZONTAL_PAGES:
4972 case GTK_MOVEMENT_LOGICAL_POSITIONS:
4973 new_pos = gtk_entry_move_logically (entry, new_pos, count);
4975 case GTK_MOVEMENT_VISUAL_POSITIONS:
4976 new_pos = gtk_entry_move_visually (entry, new_pos, count);
4977 if (priv->current_pos == new_pos)
4979 if (!extend_selection)
4981 if (!gtk_widget_keynav_failed (GTK_WIDGET (entry),
4983 GTK_DIR_RIGHT : GTK_DIR_LEFT))
4985 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (entry));
4988 gtk_widget_child_focus (toplevel,
4990 GTK_DIR_RIGHT : GTK_DIR_LEFT);
4995 gtk_widget_error_bell (GTK_WIDGET (entry));
4999 case GTK_MOVEMENT_WORDS:
5002 new_pos = gtk_entry_move_forward_word (entry, new_pos, FALSE);
5007 new_pos = gtk_entry_move_backward_word (entry, new_pos, FALSE);
5010 if (priv->current_pos == new_pos)
5011 gtk_widget_error_bell (GTK_WIDGET (entry));
5013 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
5014 case GTK_MOVEMENT_PARAGRAPH_ENDS:
5015 case GTK_MOVEMENT_BUFFER_ENDS:
5016 new_pos = count < 0 ? 0 : gtk_entry_buffer_get_length (get_buffer (entry));
5017 if (priv->current_pos == new_pos)
5018 gtk_widget_error_bell (GTK_WIDGET (entry));
5020 case GTK_MOVEMENT_DISPLAY_LINES:
5021 case GTK_MOVEMENT_PARAGRAPHS:
5022 case GTK_MOVEMENT_PAGES:
5023 case GTK_MOVEMENT_HORIZONTAL_PAGES:
5028 if (extend_selection)
5029 gtk_editable_select_region (GTK_EDITABLE (entry), priv->selection_bound, new_pos);
5031 gtk_editable_set_position (GTK_EDITABLE (entry), new_pos);
5033 gtk_entry_pend_cursor_blink (entry);
5037 gtk_entry_insert_at_cursor (GtkEntry *entry,
5040 GtkEntryPrivate *priv = entry->priv;
5041 GtkEditable *editable = GTK_EDITABLE (entry);
5042 gint pos = priv->current_pos;
5046 _gtk_entry_reset_im_context (entry);
5048 gtk_editable_insert_text (editable, str, -1, &pos);
5049 gtk_editable_set_position (editable, pos);
5054 gtk_entry_delete_from_cursor (GtkEntry *entry,
5058 GtkEntryPrivate *priv = entry->priv;
5059 GtkEditable *editable = GTK_EDITABLE (entry);
5060 gint start_pos = priv->current_pos;
5061 gint end_pos = priv->current_pos;
5062 gint old_n_bytes = gtk_entry_buffer_get_bytes (get_buffer (entry));
5064 _gtk_entry_reset_im_context (entry);
5066 if (!priv->editable)
5068 gtk_widget_error_bell (GTK_WIDGET (entry));
5072 if (priv->selection_bound != priv->current_pos)
5074 gtk_editable_delete_selection (editable);
5080 case GTK_DELETE_CHARS:
5081 end_pos = gtk_entry_move_logically (entry, priv->current_pos, count);
5082 gtk_editable_delete_text (editable, MIN (start_pos, end_pos), MAX (start_pos, end_pos));
5084 case GTK_DELETE_WORDS:
5087 /* Move to end of current word, or if not on a word, end of previous word */
5088 end_pos = gtk_entry_move_backward_word (entry, end_pos, FALSE);
5089 end_pos = gtk_entry_move_forward_word (entry, end_pos, FALSE);
5093 /* Move to beginning of current word, or if not on a word, begining of next word */
5094 start_pos = gtk_entry_move_forward_word (entry, start_pos, FALSE);
5095 start_pos = gtk_entry_move_backward_word (entry, start_pos, FALSE);
5099 case GTK_DELETE_WORD_ENDS:
5102 start_pos = gtk_entry_move_backward_word (entry, start_pos, FALSE);
5107 end_pos = gtk_entry_move_forward_word (entry, end_pos, FALSE);
5110 gtk_editable_delete_text (editable, start_pos, end_pos);
5112 case GTK_DELETE_DISPLAY_LINE_ENDS:
5113 case GTK_DELETE_PARAGRAPH_ENDS:
5115 gtk_editable_delete_text (editable, 0, priv->current_pos);
5117 gtk_editable_delete_text (editable, priv->current_pos, -1);
5119 case GTK_DELETE_DISPLAY_LINES:
5120 case GTK_DELETE_PARAGRAPHS:
5121 gtk_editable_delete_text (editable, 0, -1);
5123 case GTK_DELETE_WHITESPACE:
5124 gtk_entry_delete_whitespace (entry);
5128 if (gtk_entry_buffer_get_bytes (get_buffer (entry)) == old_n_bytes)
5129 gtk_widget_error_bell (GTK_WIDGET (entry));
5131 gtk_entry_pend_cursor_blink (entry);
5135 gtk_entry_backspace (GtkEntry *entry)
5137 GtkEntryPrivate *priv = entry->priv;
5138 GtkEditable *editable = GTK_EDITABLE (entry);
5141 _gtk_entry_reset_im_context (entry);
5143 if (!priv->editable)
5145 gtk_widget_error_bell (GTK_WIDGET (entry));
5149 if (priv->selection_bound != priv->current_pos)
5151 gtk_editable_delete_selection (editable);
5155 prev_pos = gtk_entry_move_logically (entry, priv->current_pos, -1);
5157 if (prev_pos < priv->current_pos)
5159 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
5160 PangoLogAttr *log_attrs;
5163 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
5165 /* Deleting parts of characters */
5166 if (log_attrs[priv->current_pos].backspace_deletes_character)
5168 gchar *cluster_text;
5169 gchar *normalized_text;
5172 cluster_text = gtk_entry_get_display_text (entry, prev_pos,
5174 normalized_text = g_utf8_normalize (cluster_text,
5175 strlen (cluster_text),
5177 len = g_utf8_strlen (normalized_text, -1);
5179 gtk_editable_delete_text (editable, prev_pos, priv->current_pos);
5182 gint pos = priv->current_pos;
5184 gtk_editable_insert_text (editable, normalized_text,
5185 g_utf8_offset_to_pointer (normalized_text, len - 1) - normalized_text,
5187 gtk_editable_set_position (editable, pos);
5190 g_free (normalized_text);
5191 g_free (cluster_text);
5195 gtk_editable_delete_text (editable, prev_pos, priv->current_pos);
5202 gtk_widget_error_bell (GTK_WIDGET (entry));
5205 gtk_entry_pend_cursor_blink (entry);
5209 gtk_entry_copy_clipboard (GtkEntry *entry)
5211 GtkEntryPrivate *priv = entry->priv;
5212 GtkEditable *editable = GTK_EDITABLE (entry);
5216 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5220 gtk_widget_error_bell (GTK_WIDGET (entry));
5224 str = gtk_entry_get_display_text (entry, start, end);
5225 gtk_clipboard_set_text (gtk_widget_get_clipboard (GTK_WIDGET (entry),
5226 GDK_SELECTION_CLIPBOARD),
5233 gtk_entry_cut_clipboard (GtkEntry *entry)
5235 GtkEntryPrivate *priv = entry->priv;
5236 GtkEditable *editable = GTK_EDITABLE (entry);
5241 gtk_widget_error_bell (GTK_WIDGET (entry));
5245 gtk_entry_copy_clipboard (entry);
5249 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5250 gtk_editable_delete_text (editable, start, end);
5254 gtk_widget_error_bell (GTK_WIDGET (entry));
5259 gtk_entry_paste_clipboard (GtkEntry *entry)
5261 GtkEntryPrivate *priv = entry->priv;
5264 gtk_entry_paste (entry, GDK_SELECTION_CLIPBOARD);
5266 gtk_widget_error_bell (GTK_WIDGET (entry));
5270 gtk_entry_delete_cb (GtkEntry *entry)
5272 GtkEntryPrivate *priv = entry->priv;
5273 GtkEditable *editable = GTK_EDITABLE (entry);
5278 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5279 gtk_editable_delete_text (editable, start, end);
5284 gtk_entry_toggle_overwrite (GtkEntry *entry)
5286 GtkEntryPrivate *priv = entry->priv;
5288 priv->overwrite_mode = !priv->overwrite_mode;
5289 gtk_entry_pend_cursor_blink (entry);
5290 gtk_widget_queue_draw (GTK_WIDGET (entry));
5294 gtk_entry_select_all (GtkEntry *entry)
5296 gtk_entry_select_line (entry);
5300 gtk_entry_real_activate (GtkEntry *entry)
5302 GtkEntryPrivate *priv = entry->priv;
5304 GtkWidget *default_widget, *focus_widget;
5305 GtkWidget *toplevel;
5308 widget = GTK_WIDGET (entry);
5310 if (priv->activates_default)
5312 toplevel = gtk_widget_get_toplevel (widget);
5313 if (GTK_IS_WINDOW (toplevel))
5315 window = GTK_WINDOW (toplevel);
5319 default_widget = gtk_window_get_default_widget (window);
5320 focus_widget = gtk_window_get_focus (window);
5321 if (widget != default_widget &&
5322 !(widget == focus_widget && (!default_widget || !gtk_widget_get_sensitive (default_widget))))
5323 gtk_window_activate_default (window);
5330 keymap_direction_changed (GdkKeymap *keymap,
5333 gtk_entry_recompute (entry);
5336 /* IM Context Callbacks
5340 gtk_entry_commit_cb (GtkIMContext *context,
5344 GtkEntryPrivate *priv = entry->priv;
5347 gtk_entry_enter_text (entry, str);
5351 gtk_entry_preedit_changed_cb (GtkIMContext *context,
5354 GtkEntryPrivate *priv = entry->priv;
5358 gchar *preedit_string;
5361 gtk_im_context_get_preedit_string (priv->im_context,
5362 &preedit_string, NULL,
5364 g_signal_emit (entry, signals[PREEDIT_CHANGED], 0, preedit_string);
5365 priv->preedit_length = strlen (preedit_string);
5366 cursor_pos = CLAMP (cursor_pos, 0, g_utf8_strlen (preedit_string, -1));
5367 priv->preedit_cursor = cursor_pos;
5368 g_free (preedit_string);
5370 gtk_entry_recompute (entry);
5375 gtk_entry_retrieve_surrounding_cb (GtkIMContext *context,
5378 GtkEntryPrivate *priv = entry->priv;
5381 /* XXXX ??? does this even make sense when text is not visible? Should we return FALSE? */
5382 text = gtk_entry_get_display_text (entry, 0, -1);
5383 gtk_im_context_set_surrounding (context, text, strlen (text), /* Length in bytes */
5384 g_utf8_offset_to_pointer (text, priv->current_pos) - text);
5391 gtk_entry_delete_surrounding_cb (GtkIMContext *slave,
5396 GtkEntryPrivate *priv = entry->priv;
5399 gtk_editable_delete_text (GTK_EDITABLE (entry),
5400 priv->current_pos + offset,
5401 priv->current_pos + offset + n_chars);
5406 /* Internal functions
5409 /* Used for im_commit_cb and inserting Unicode chars */
5411 gtk_entry_enter_text (GtkEntry *entry,
5414 GtkEntryPrivate *priv = entry->priv;
5415 GtkEditable *editable = GTK_EDITABLE (entry);
5417 gboolean old_need_im_reset;
5419 old_need_im_reset = priv->need_im_reset;
5420 priv->need_im_reset = FALSE;
5422 if (gtk_editable_get_selection_bounds (editable, NULL, NULL))
5423 gtk_editable_delete_selection (editable);
5426 if (priv->overwrite_mode)
5427 gtk_entry_delete_from_cursor (entry, GTK_DELETE_CHARS, 1);
5430 tmp_pos = priv->current_pos;
5431 gtk_editable_insert_text (editable, str, strlen (str), &tmp_pos);
5432 gtk_editable_set_position (editable, tmp_pos);
5434 priv->need_im_reset = old_need_im_reset;
5437 /* All changes to priv->current_pos and priv->selection_bound
5438 * should go through this function.
5441 gtk_entry_set_positions (GtkEntry *entry,
5443 gint selection_bound)
5445 GtkEntryPrivate *priv = entry->priv;
5446 gboolean changed = FALSE;
5448 g_object_freeze_notify (G_OBJECT (entry));
5450 if (current_pos != -1 &&
5451 priv->current_pos != current_pos)
5453 priv->current_pos = current_pos;
5456 g_object_notify (G_OBJECT (entry), "cursor-position");
5459 if (selection_bound != -1 &&
5460 priv->selection_bound != selection_bound)
5462 priv->selection_bound = selection_bound;
5465 g_object_notify (G_OBJECT (entry), "selection-bound");
5468 g_object_thaw_notify (G_OBJECT (entry));
5472 gtk_entry_move_adjustments (entry);
5473 gtk_entry_recompute (entry);
5478 gtk_entry_reset_layout (GtkEntry *entry)
5480 GtkEntryPrivate *priv = entry->priv;
5482 if (priv->cached_layout)
5484 g_object_unref (priv->cached_layout);
5485 priv->cached_layout = NULL;
5490 update_im_cursor_location (GtkEntry *entry)
5492 GtkEntryPrivate *priv = entry->priv;
5495 gint strong_xoffset;
5496 gint area_width, area_height;
5498 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
5499 gtk_entry_get_text_area_size (entry, NULL, NULL, &area_width, &area_height);
5501 strong_xoffset = strong_x - priv->scroll_offset;
5502 if (strong_xoffset < 0)
5506 else if (strong_xoffset > area_width)
5508 strong_xoffset = area_width;
5510 area.x = strong_xoffset;
5513 area.height = area_height;
5515 gtk_im_context_set_cursor_location (priv->im_context, &area);
5519 recompute_idle_func (gpointer data)
5521 GtkEntry *entry = GTK_ENTRY (data);
5522 GtkEntryPrivate *priv = entry->priv;
5524 priv->recompute_idle = 0;
5526 if (gtk_widget_has_screen (GTK_WIDGET (entry)))
5528 gtk_entry_adjust_scroll (entry);
5529 gtk_widget_queue_draw (GTK_WIDGET (entry));
5531 update_im_cursor_location (entry);
5538 gtk_entry_recompute (GtkEntry *entry)
5540 GtkEntryPrivate *priv = entry->priv;
5542 gtk_entry_reset_layout (entry);
5543 gtk_entry_check_cursor_blink (entry);
5545 if (!priv->recompute_idle)
5547 priv->recompute_idle = gdk_threads_add_idle_full (G_PRIORITY_HIGH_IDLE + 15, /* between resize and redraw */
5548 recompute_idle_func, entry, NULL);
5553 gtk_entry_get_placeholder_text_color (GtkEntry *entry,
5556 GtkWidget *widget = GTK_WIDGET (entry);
5557 GtkStyleContext *context;
5558 GdkRGBA fg = { 0.5, 0.5, 0.5 };
5560 context = gtk_widget_get_style_context (widget);
5561 gtk_style_context_lookup_color (context, "placeholder_text_color", &fg);
5563 color->red = CLAMP (fg.red * 65535. + 0.5, 0, 65535);
5564 color->green = CLAMP (fg.green * 65535. + 0.5, 0, 65535);
5565 color->blue = CLAMP (fg.blue * 65535. + 0.5, 0, 65535);
5568 static inline gboolean
5569 show_placeholder_text (GtkEntry *entry)
5571 GtkEntryPrivate *priv = entry->priv;
5573 if (!gtk_widget_has_focus (GTK_WIDGET (entry)) &&
5574 gtk_entry_buffer_get_bytes (get_buffer (entry)) == 0 &&
5575 priv->placeholder_text != NULL)
5581 static PangoLayout *
5582 gtk_entry_create_layout (GtkEntry *entry,
5583 gboolean include_preedit)
5585 GtkEntryPrivate *priv = entry->priv;
5586 GtkWidget *widget = GTK_WIDGET (entry);
5587 PangoLayout *layout = gtk_widget_create_pango_layout (widget, NULL);
5588 PangoAttrList *tmp_attrs = pango_attr_list_new ();
5589 gboolean placeholder_layout = show_placeholder_text (entry);
5591 gchar *preedit_string = NULL;
5592 gint preedit_length = 0;
5593 PangoAttrList *preedit_attrs = NULL;
5598 pango_layout_set_single_paragraph_mode (layout, TRUE);
5600 display = placeholder_layout ? g_strdup (priv->placeholder_text) : gtk_entry_get_display_text (entry, 0, -1);
5601 n_bytes = strlen (display);
5603 if (!placeholder_layout && include_preedit)
5605 gtk_im_context_get_preedit_string (priv->im_context,
5606 &preedit_string, &preedit_attrs, NULL);
5607 preedit_length = priv->preedit_length;
5609 else if (placeholder_layout)
5612 PangoAttribute *attr;
5614 gtk_entry_get_placeholder_text_color (entry, &color);
5615 attr = pango_attr_foreground_new (color.red, color.green, color.blue);
5616 attr->start_index = 0;
5617 attr->end_index = G_MAXINT;
5618 pango_attr_list_insert (tmp_attrs, attr);
5623 GString *tmp_string = g_string_new (display);
5624 gint cursor_index = g_utf8_offset_to_pointer (display, priv->current_pos) - display;
5626 g_string_insert (tmp_string, cursor_index, preedit_string);
5628 pango_layout_set_text (layout, tmp_string->str, tmp_string->len);
5630 pango_attr_list_splice (tmp_attrs, preedit_attrs,
5631 cursor_index, preedit_length);
5633 g_string_free (tmp_string, TRUE);
5637 PangoDirection pango_dir;
5639 if (gtk_entry_get_display_mode (entry) == DISPLAY_NORMAL)
5640 pango_dir = pango_find_base_dir (display, n_bytes);
5642 pango_dir = PANGO_DIRECTION_NEUTRAL;
5644 if (pango_dir == PANGO_DIRECTION_NEUTRAL)
5646 if (gtk_widget_has_focus (widget))
5648 GdkDisplay *display = gtk_widget_get_display (widget);
5649 GdkKeymap *keymap = gdk_keymap_get_for_display (display);
5650 if (gdk_keymap_get_direction (keymap) == PANGO_DIRECTION_RTL)
5651 pango_dir = PANGO_DIRECTION_RTL;
5653 pango_dir = PANGO_DIRECTION_LTR;
5657 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
5658 pango_dir = PANGO_DIRECTION_RTL;
5660 pango_dir = PANGO_DIRECTION_LTR;
5664 pango_context_set_base_dir (gtk_widget_get_pango_context (widget),
5667 priv->resolved_dir = pango_dir;
5669 pango_layout_set_text (layout, display, n_bytes);
5672 pango_layout_set_attributes (layout, tmp_attrs);
5674 g_free (preedit_string);
5678 pango_attr_list_unref (preedit_attrs);
5680 pango_attr_list_unref (tmp_attrs);
5685 static PangoLayout *
5686 gtk_entry_ensure_layout (GtkEntry *entry,
5687 gboolean include_preedit)
5689 GtkEntryPrivate *priv = entry->priv;
5691 if (priv->preedit_length > 0 &&
5692 !include_preedit != !priv->cache_includes_preedit)
5693 gtk_entry_reset_layout (entry);
5695 if (!priv->cached_layout)
5697 priv->cached_layout = gtk_entry_create_layout (entry, include_preedit);
5698 priv->cache_includes_preedit = include_preedit;
5701 return priv->cached_layout;
5705 get_layout_position (GtkEntry *entry,
5709 GtkEntryPrivate *priv = entry->priv;
5710 PangoLayout *layout;
5711 PangoRectangle logical_rect;
5712 gint area_width, area_height;
5714 PangoLayoutLine *line;
5716 layout = gtk_entry_ensure_layout (entry, TRUE);
5718 gtk_entry_get_text_area_size (entry, NULL, NULL, &area_width, &area_height);
5719 area_height = PANGO_SCALE * area_height;
5721 line = pango_layout_get_lines_readonly (layout)->data;
5722 pango_layout_line_get_extents (line, NULL, &logical_rect);
5724 /* Align primarily for locale's ascent/descent */
5725 y_pos = ((area_height - priv->ascent - priv->descent) / 2 +
5726 priv->ascent + logical_rect.y);
5728 /* Now see if we need to adjust to fit in actual drawn string */
5729 if (logical_rect.height > area_height)
5730 y_pos = (area_height - logical_rect.height) / 2;
5733 else if (y_pos + logical_rect.height > area_height)
5734 y_pos = area_height - logical_rect.height;
5736 y_pos = y_pos / PANGO_SCALE;
5739 *x = - priv->scroll_offset;
5746 draw_text_with_color (GtkEntry *entry,
5748 GdkRGBA *default_color)
5750 GtkEntryPrivate *priv = entry->priv;
5751 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
5754 gint start_pos, end_pos;
5756 widget = GTK_WIDGET (entry);
5760 get_layout_position (entry, &x, &y);
5762 cairo_move_to (cr, x, y);
5763 gdk_cairo_set_source_rgba (cr, default_color);
5764 pango_cairo_show_layout (cr, layout);
5766 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start_pos, &end_pos))
5770 PangoRectangle logical_rect;
5771 GdkRGBA selection_color, text_color;
5772 GtkStyleContext *context;
5773 GtkStateFlags state;
5775 context = gtk_widget_get_style_context (widget);
5776 pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
5777 gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
5779 state = gtk_widget_get_state_flags (widget);
5780 state |= GTK_STATE_FLAG_SELECTED;
5782 gtk_style_context_get_background_color (context, state, &selection_color);
5783 gtk_style_context_get_color (context, state, &text_color);
5785 for (i = 0; i < n_ranges; ++i)
5786 cairo_rectangle (cr,
5787 - priv->scroll_offset + ranges[2 * i],
5790 logical_rect.height);
5794 gdk_cairo_set_source_rgba (cr, &selection_color);
5797 cairo_move_to (cr, x, y);
5798 gdk_cairo_set_source_rgba (cr, &text_color);
5799 pango_cairo_show_layout (cr, layout);
5807 gtk_entry_draw_text (GtkEntry *entry,
5810 GtkEntryPrivate *priv = entry->priv;
5811 GtkWidget *widget = GTK_WIDGET (entry);
5812 GtkStateFlags state = 0;
5813 GdkRGBA text_color, bar_text_color;
5814 GtkStyleContext *context;
5816 gint progress_x, progress_y, progress_width, progress_height;
5817 gint clip_width, clip_height;
5819 /* Nothing to display at all */
5820 if (gtk_entry_get_display_mode (entry) == DISPLAY_BLANK)
5823 state = gtk_widget_get_state_flags (widget);
5824 context = gtk_widget_get_style_context (widget);
5826 gtk_style_context_get_color (context, state, &text_color);
5828 /* Get foreground color for progressbars */
5829 gtk_entry_prepare_context_for_progress (entry, context);
5830 gtk_style_context_get_color (context, state, &bar_text_color);
5831 gtk_style_context_restore (context);
5833 get_progress_area (widget,
5834 &progress_x, &progress_y,
5835 &progress_width, &progress_height);
5839 clip_width = gdk_window_get_width (priv->text_area);
5840 clip_height = gdk_window_get_height (priv->text_area);
5841 cairo_rectangle (cr, 0, 0, clip_width, clip_height);
5844 /* If the color is the same, or the progress area has a zero
5845 * size, then we only need to draw once. */
5846 if (gdk_rgba_equal (&text_color, &bar_text_color) ||
5847 ((progress_width == 0) || (progress_height == 0)))
5849 draw_text_with_color (entry, cr, &text_color);
5853 int frame_x, frame_y, area_x, area_y;
5855 width = gdk_window_get_width (priv->text_area);
5856 height = gdk_window_get_height (priv->text_area);
5860 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
5861 cairo_rectangle (cr, 0, 0, width, height);
5863 /* progres area is frame-relative, we need it text-area window
5865 get_frame_size (entry, TRUE, &frame_x, &frame_y, NULL, NULL);
5866 gdk_window_get_position (priv->text_area, &area_x, &area_y);
5867 progress_x += frame_x - area_x;
5868 progress_y += frame_y - area_y;
5870 cairo_rectangle (cr, progress_x, progress_y,
5871 progress_width, progress_height);
5873 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_WINDING);
5875 draw_text_with_color (entry, cr, &text_color);
5880 cairo_rectangle (cr, progress_x, progress_y,
5881 progress_width, progress_height);
5884 draw_text_with_color (entry, cr, &bar_text_color);
5893 gtk_entry_draw_cursor (GtkEntry *entry,
5897 GtkEntryPrivate *priv = entry->priv;
5898 GtkWidget *widget = GTK_WIDGET (entry);
5899 GtkStyleContext *context;
5900 PangoRectangle cursor_rect;
5903 gboolean block_at_line_end;
5904 PangoLayout *layout;
5908 context = gtk_widget_get_style_context (widget);
5910 layout = gtk_entry_ensure_layout (entry, TRUE);
5911 text = pango_layout_get_text (layout);
5912 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos + priv->preedit_cursor) - text;
5913 get_layout_position (entry, &x, &y);
5915 if (!priv->overwrite_mode)
5918 block = _gtk_text_util_get_block_cursor_location (layout,
5919 cursor_index, &cursor_rect, &block_at_line_end);
5923 gtk_render_insertion_cursor (context, cr,
5925 layout, cursor_index, priv->resolved_dir);
5927 else /* overwrite_mode */
5929 GdkRGBA cursor_color;
5934 rect.x = PANGO_PIXELS (cursor_rect.x) + x;
5935 rect.y = PANGO_PIXELS (cursor_rect.y) + y;
5936 rect.width = PANGO_PIXELS (cursor_rect.width);
5937 rect.height = PANGO_PIXELS (cursor_rect.height);
5939 _gtk_style_context_get_cursor_color (context, &cursor_color, NULL);
5940 gdk_cairo_set_source_rgba (cr, &cursor_color);
5941 gdk_cairo_rectangle (cr, &rect);
5944 if (!block_at_line_end)
5946 GtkStateFlags state;
5949 state = gtk_widget_get_state_flags (widget);
5950 gtk_style_context_get_background_color (context, state, &color);
5952 gdk_cairo_rectangle (cr, &rect);
5954 cairo_move_to (cr, x, y);
5955 gdk_cairo_set_source_rgba (cr, &color);
5956 pango_cairo_show_layout (cr, layout);
5964 _gtk_entry_reset_im_context (GtkEntry *entry)
5966 GtkEntryPrivate *priv = entry->priv;
5968 if (priv->need_im_reset)
5970 priv->need_im_reset = FALSE;
5971 gtk_im_context_reset (priv->im_context);
5976 * gtk_entry_reset_im_context:
5977 * @entry: a #GtkEntry
5979 * Reset the input method context of the entry if needed.
5981 * This can be necessary in the case where modifying the buffer
5982 * would confuse on-going input method behavior.
5987 gtk_entry_reset_im_context (GtkEntry *entry)
5989 g_return_if_fail (GTK_IS_ENTRY (entry));
5991 _gtk_entry_reset_im_context (entry);
5995 * gtk_entry_im_context_filter_keypress:
5996 * @entry: a #GtkEntry
5997 * @event: (type Gdk.EventKey): the key event
5999 * Allow the #GtkEntry input method to internally handle key press
6000 * and release events. If this function returns %TRUE, then no further
6001 * processing should be done for this key event. See
6002 * gtk_im_context_filter_keypress().
6004 * Note that you are expected to call this function from your handler
6005 * when overriding key event handling. This is needed in the case when
6006 * you need to insert your own key handling between the input method
6007 * and the default key event handling of the #GtkEntry.
6008 * See gtk_text_view_reset_im_context() for an example of use.
6010 * Return value: %TRUE if the input method handled the key event.
6015 gtk_entry_im_context_filter_keypress (GtkEntry *entry,
6018 GtkEntryPrivate *priv;
6020 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
6024 return gtk_im_context_filter_keypress (priv->im_context, event);
6028 _gtk_entry_get_im_context (GtkEntry *entry)
6030 return entry->priv->im_context;
6034 gtk_entry_find_position (GtkEntry *entry,
6037 GtkEntryPrivate *priv = entry->priv;
6038 PangoLayout *layout;
6039 PangoLayoutLine *line;
6046 layout = gtk_entry_ensure_layout (entry, TRUE);
6047 text = pango_layout_get_text (layout);
6048 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos) - text;
6050 line = pango_layout_get_lines_readonly (layout)->data;
6051 pango_layout_line_x_to_index (line, x * PANGO_SCALE, &index, &trailing);
6053 if (index >= cursor_index && priv->preedit_length)
6055 if (index >= cursor_index + priv->preedit_length)
6056 index -= priv->preedit_length;
6059 index = cursor_index;
6064 pos = g_utf8_pointer_to_offset (text, text + index);
6071 gtk_entry_get_cursor_locations (GtkEntry *entry,
6076 GtkEntryPrivate *priv = entry->priv;
6077 DisplayMode mode = gtk_entry_get_display_mode (entry);
6079 /* Nothing to display at all, so no cursor is relevant */
6080 if (mode == DISPLAY_BLANK)
6090 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
6091 const gchar *text = pango_layout_get_text (layout);
6092 PangoRectangle strong_pos, weak_pos;
6095 if (type == CURSOR_STANDARD)
6097 index = g_utf8_offset_to_pointer (text, priv->current_pos + priv->preedit_cursor) - text;
6099 else /* type == CURSOR_DND */
6101 index = g_utf8_offset_to_pointer (text, priv->dnd_position) - text;
6103 if (priv->dnd_position > priv->current_pos)
6105 if (mode == DISPLAY_NORMAL)
6106 index += priv->preedit_length;
6109 gint preedit_len_chars = g_utf8_strlen (text, -1) - gtk_entry_buffer_get_length (get_buffer (entry));
6110 index += preedit_len_chars * g_unichar_to_utf8 (priv->invisible_char, NULL);
6115 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
6118 *strong_x = strong_pos.x / PANGO_SCALE;
6121 *weak_x = weak_pos.x / PANGO_SCALE;
6126 gtk_entry_adjust_scroll (GtkEntry *entry)
6128 GtkEntryPrivate *priv = entry->priv;
6129 gint min_offset, max_offset;
6130 gint text_area_width, text_width;
6131 gint strong_x, weak_x;
6132 gint strong_xoffset, weak_xoffset;
6134 PangoLayout *layout;
6135 PangoLayoutLine *line;
6136 PangoRectangle logical_rect;
6138 if (!gtk_widget_get_realized (GTK_WIDGET (entry)))
6141 text_area_width = gdk_window_get_width (priv->text_area);
6143 if (text_area_width < 0)
6144 text_area_width = 0;
6146 layout = gtk_entry_ensure_layout (entry, TRUE);
6147 line = pango_layout_get_lines_readonly (layout)->data;
6149 pango_layout_line_get_extents (line, NULL, &logical_rect);
6151 /* Display as much text as we can */
6153 if (priv->resolved_dir == PANGO_DIRECTION_LTR)
6154 xalign = priv->xalign;
6156 xalign = 1.0 - priv->xalign;
6158 text_width = PANGO_PIXELS(logical_rect.width);
6160 if (text_width > text_area_width)
6163 max_offset = text_width - text_area_width;
6167 min_offset = (text_width - text_area_width) * xalign;
6168 max_offset = min_offset;
6171 priv->scroll_offset = CLAMP (priv->scroll_offset, min_offset, max_offset);
6173 /* And make sure cursors are on screen. Note that the cursor is
6174 * actually drawn one pixel into the INNER_BORDER space on
6175 * the right, when the scroll is at the utmost right. This
6176 * looks better to to me than confining the cursor inside the
6177 * border entirely, though it means that the cursor gets one
6178 * pixel closer to the edge of the widget on the right than
6179 * on the left. This might need changing if one changed
6180 * INNER_BORDER from 2 to 1, as one would do on a
6181 * small-screen-real-estate display.
6183 * We always make sure that the strong cursor is on screen, and
6184 * put the weak cursor on screen if possible.
6187 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, &weak_x);
6189 strong_xoffset = strong_x - priv->scroll_offset;
6191 if (strong_xoffset < 0)
6193 priv->scroll_offset += strong_xoffset;
6196 else if (strong_xoffset > text_area_width)
6198 priv->scroll_offset += strong_xoffset - text_area_width;
6199 strong_xoffset = text_area_width;
6202 weak_xoffset = weak_x - priv->scroll_offset;
6204 if (weak_xoffset < 0 && strong_xoffset - weak_xoffset <= text_area_width)
6206 priv->scroll_offset += weak_xoffset;
6208 else if (weak_xoffset > text_area_width &&
6209 strong_xoffset - (weak_xoffset - text_area_width) >= 0)
6211 priv->scroll_offset += weak_xoffset - text_area_width;
6214 g_object_notify (G_OBJECT (entry), "scroll-offset");
6218 gtk_entry_move_adjustments (GtkEntry *entry)
6220 GtkWidget *widget = GTK_WIDGET (entry);
6221 GtkAllocation allocation;
6222 GtkAdjustment *adjustment;
6223 PangoContext *context;
6224 PangoFontMetrics *metrics;
6225 GtkStyleContext *style_context;
6226 GtkStateFlags state;
6231 adjustment = g_object_get_qdata (G_OBJECT (entry), quark_cursor_hadjustment);
6235 gtk_widget_get_allocation (widget, &allocation);
6237 /* Cursor position, layout offset, border width, and widget allocation */
6238 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &x, NULL);
6239 get_layout_position (entry, &layout_x, NULL);
6240 _gtk_entry_get_borders (entry, &borders);
6241 x += allocation.x + layout_x + borders.left;
6243 /* Approximate width of a char, so user can see what is ahead/behind */
6244 context = gtk_widget_get_pango_context (widget);
6245 style_context = gtk_widget_get_style_context (widget);
6246 state = gtk_widget_get_state_flags (widget);
6248 metrics = pango_context_get_metrics (context,
6249 gtk_style_context_get_font (style_context, state),
6250 pango_context_get_language (context));
6251 char_width = pango_font_metrics_get_approximate_char_width (metrics) / PANGO_SCALE;
6254 gtk_adjustment_clamp_page (adjustment,
6255 x - (char_width + 1), /* one char + one pixel before */
6256 x + (char_width + 2)); /* one char + cursor + one pixel after */
6260 gtk_entry_move_visually (GtkEntry *entry,
6264 GtkEntryPrivate *priv = entry->priv;
6266 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6269 text = pango_layout_get_text (layout);
6271 index = g_utf8_offset_to_pointer (text, start) - text;
6275 int new_index, new_trailing;
6276 gboolean split_cursor;
6279 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
6280 "gtk-split-cursor", &split_cursor,
6287 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
6288 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
6290 strong = keymap_direction == priv->resolved_dir;
6295 pango_layout_move_cursor_visually (layout, strong, index, 0, 1, &new_index, &new_trailing);
6300 pango_layout_move_cursor_visually (layout, strong, index, 0, -1, &new_index, &new_trailing);
6306 else if (new_index != G_MAXINT)
6309 while (new_trailing--)
6310 index = g_utf8_next_char (text + index) - text;
6313 return g_utf8_pointer_to_offset (text, text + index);
6317 gtk_entry_move_logically (GtkEntry *entry,
6321 gint new_pos = start;
6324 length = gtk_entry_buffer_get_length (get_buffer (entry));
6326 /* Prevent any leak of information */
6327 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6329 new_pos = CLAMP (start + count, 0, length);
6333 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6334 PangoLogAttr *log_attrs;
6337 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6339 while (count > 0 && new_pos < length)
6343 while (new_pos < length && !log_attrs[new_pos].is_cursor_position);
6347 while (count < 0 && new_pos > 0)
6351 while (new_pos > 0 && !log_attrs[new_pos].is_cursor_position);
6363 gtk_entry_move_forward_word (GtkEntry *entry,
6365 gboolean allow_whitespace)
6367 gint new_pos = start;
6370 length = gtk_entry_buffer_get_length (get_buffer (entry));
6372 /* Prevent any leak of information */
6373 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6377 else if (new_pos < length)
6379 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6380 PangoLogAttr *log_attrs;
6383 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6385 /* Find the next word boundary */
6387 while (new_pos < n_attrs - 1 && !(log_attrs[new_pos].is_word_end ||
6388 (log_attrs[new_pos].is_word_start && allow_whitespace)))
6399 gtk_entry_move_backward_word (GtkEntry *entry,
6401 gboolean allow_whitespace)
6403 gint new_pos = start;
6405 /* Prevent any leak of information */
6406 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6412 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6413 PangoLogAttr *log_attrs;
6416 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6418 new_pos = start - 1;
6420 /* Find the previous word boundary */
6421 while (new_pos > 0 && !(log_attrs[new_pos].is_word_start ||
6422 (log_attrs[new_pos].is_word_end && allow_whitespace)))
6432 gtk_entry_delete_whitespace (GtkEntry *entry)
6434 GtkEntryPrivate *priv = entry->priv;
6435 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6436 PangoLogAttr *log_attrs;
6440 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6442 start = end = priv->current_pos;
6444 while (start > 0 && log_attrs[start-1].is_white)
6447 while (end < n_attrs && log_attrs[end].is_white)
6453 gtk_editable_delete_text (GTK_EDITABLE (entry), start, end);
6458 gtk_entry_select_word (GtkEntry *entry)
6460 GtkEntryPrivate *priv = entry->priv;
6461 gint start_pos = gtk_entry_move_backward_word (entry, priv->current_pos, TRUE);
6462 gint end_pos = gtk_entry_move_forward_word (entry, priv->current_pos, TRUE);
6464 gtk_editable_select_region (GTK_EDITABLE (entry), start_pos, end_pos);
6468 gtk_entry_select_line (GtkEntry *entry)
6470 gtk_editable_select_region (GTK_EDITABLE (entry), 0, -1);
6474 truncate_multiline (const gchar *text)
6479 text[length] && text[length] != '\n' && text[length] != '\r';
6486 paste_received (GtkClipboard *clipboard,
6490 GtkEntry *entry = GTK_ENTRY (data);
6491 GtkEditable *editable = GTK_EDITABLE (entry);
6492 GtkEntryPrivate *priv = entry->priv;
6494 if (priv->button == GDK_BUTTON_MIDDLE)
6496 gint pos, start, end;
6497 pos = priv->insert_pos;
6498 gtk_editable_get_selection_bounds (editable, &start, &end);
6499 if (!((start <= pos && pos <= end) || (end <= pos && pos <= start)))
6500 gtk_editable_select_region (editable, pos, pos);
6505 gint pos, start, end;
6507 gboolean popup_completion;
6508 GtkEntryCompletion *completion;
6510 completion = gtk_entry_get_completion (entry);
6512 if (priv->truncate_multiline)
6513 length = truncate_multiline (text);
6515 /* only complete if the selection is at the end */
6516 popup_completion = (gtk_entry_buffer_get_length (get_buffer (entry)) ==
6517 MAX (priv->current_pos, priv->selection_bound));
6521 if (gtk_widget_get_mapped (completion->priv->popup_window))
6522 _gtk_entry_completion_popdown (completion);
6524 if (!popup_completion && completion->priv->changed_id > 0)
6525 g_signal_handler_block (entry, completion->priv->changed_id);
6528 begin_change (entry);
6529 if (gtk_editable_get_selection_bounds (editable, &start, &end))
6530 gtk_editable_delete_text (editable, start, end);
6532 pos = priv->current_pos;
6533 gtk_editable_insert_text (editable, text, length, &pos);
6534 gtk_editable_set_position (editable, pos);
6538 !popup_completion && completion->priv->changed_id > 0)
6539 g_signal_handler_unblock (entry, completion->priv->changed_id);
6542 g_object_unref (entry);
6546 gtk_entry_paste (GtkEntry *entry,
6549 g_object_ref (entry);
6550 gtk_clipboard_request_text (gtk_widget_get_clipboard (GTK_WIDGET (entry), selection),
6551 paste_received, entry);
6555 primary_get_cb (GtkClipboard *clipboard,
6556 GtkSelectionData *selection_data,
6560 GtkEntry *entry = GTK_ENTRY (data);
6563 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end))
6565 gchar *str = gtk_entry_get_display_text (entry, start, end);
6566 gtk_selection_data_set_text (selection_data, str, -1);
6572 primary_clear_cb (GtkClipboard *clipboard,
6575 GtkEntry *entry = GTK_ENTRY (data);
6576 GtkEntryPrivate *priv = entry->priv;
6578 gtk_editable_select_region (GTK_EDITABLE (entry), priv->current_pos, priv->current_pos);
6582 gtk_entry_update_primary_selection (GtkEntry *entry)
6584 GtkTargetList *list;
6585 GtkTargetEntry *targets;
6586 GtkClipboard *clipboard;
6590 if (!gtk_widget_get_realized (GTK_WIDGET (entry)))
6593 list = gtk_target_list_new (NULL, 0);
6594 gtk_target_list_add_text_targets (list, 0);
6596 targets = gtk_target_table_new_from_list (list, &n_targets);
6598 clipboard = gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_PRIMARY);
6600 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end))
6602 if (!gtk_clipboard_set_with_owner (clipboard, targets, n_targets,
6603 primary_get_cb, primary_clear_cb, G_OBJECT (entry)))
6604 primary_clear_cb (clipboard, entry);
6608 if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (entry))
6609 gtk_clipboard_clear (clipboard);
6612 gtk_target_table_free (targets, n_targets);
6613 gtk_target_list_unref (list);
6617 gtk_entry_clear (GtkEntry *entry,
6618 GtkEntryIconPosition icon_pos)
6620 GtkEntryPrivate *priv = entry->priv;
6621 EntryIconInfo *icon_info = priv->icons[icon_pos];
6622 GtkImageType storage_type;
6624 if (icon_info && _gtk_icon_helper_get_is_empty (icon_info->icon_helper))
6627 g_object_freeze_notify (G_OBJECT (entry));
6629 /* Explicitly check, as the pointer may become invalidated
6630 * during destruction.
6632 if (GDK_IS_WINDOW (icon_info->window))
6633 gdk_window_hide (icon_info->window);
6635 storage_type = _gtk_icon_helper_get_storage_type (icon_info->icon_helper);
6637 switch (storage_type)
6639 case GTK_IMAGE_PIXBUF:
6640 g_object_notify (G_OBJECT (entry),
6641 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-pixbuf" : "secondary-icon-pixbuf");
6644 case GTK_IMAGE_STOCK:
6645 g_object_notify (G_OBJECT (entry),
6646 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-stock" : "secondary-icon-stock");
6649 case GTK_IMAGE_ICON_NAME:
6650 g_object_notify (G_OBJECT (entry),
6651 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-name" : "secondary-icon-name");
6654 case GTK_IMAGE_GICON:
6655 g_object_notify (G_OBJECT (entry),
6656 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-gicon" : "secondary-icon-gicon");
6660 g_assert_not_reached ();
6664 _gtk_icon_helper_clear (icon_info->icon_helper);
6666 g_object_notify (G_OBJECT (entry),
6667 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-storage-type" : "secondary-icon-storage-type");
6669 g_object_thaw_notify (G_OBJECT (entry));
6673 gtk_entry_ensure_pixbuf (GtkEntry *entry,
6674 GtkEntryIconPosition icon_pos)
6676 GtkEntryPrivate *priv = entry->priv;
6677 EntryIconInfo *icon_info = priv->icons[icon_pos];
6678 GtkStyleContext *context;
6681 context = gtk_widget_get_style_context (GTK_WIDGET (entry));
6682 gtk_entry_prepare_context_for_icon (entry, context, icon_pos);
6684 pix = _gtk_icon_helper_ensure_pixbuf (icon_info->icon_helper,
6687 gtk_style_context_restore (context);
6698 * Creates a new entry.
6700 * Return value: a new #GtkEntry.
6703 gtk_entry_new (void)
6705 return g_object_new (GTK_TYPE_ENTRY, NULL);
6709 * gtk_entry_new_with_buffer:
6710 * @buffer: The buffer to use for the new #GtkEntry.
6712 * Creates a new entry with the specified text buffer.
6714 * Return value: a new #GtkEntry
6719 gtk_entry_new_with_buffer (GtkEntryBuffer *buffer)
6721 g_return_val_if_fail (GTK_IS_ENTRY_BUFFER (buffer), NULL);
6722 return g_object_new (GTK_TYPE_ENTRY, "buffer", buffer, NULL);
6725 static GtkEntryBuffer*
6726 get_buffer (GtkEntry *entry)
6728 GtkEntryPrivate *priv = entry->priv;
6730 if (priv->buffer == NULL)
6732 GtkEntryBuffer *buffer;
6733 buffer = gtk_entry_buffer_new (NULL, 0);
6734 gtk_entry_set_buffer (entry, buffer);
6735 g_object_unref (buffer);
6738 return priv->buffer;
6742 * gtk_entry_get_buffer:
6743 * @entry: a #GtkEntry
6745 * Get the #GtkEntryBuffer object which holds the text for
6750 * Returns: (transfer none): A #GtkEntryBuffer object.
6753 gtk_entry_get_buffer (GtkEntry *entry)
6755 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
6757 return get_buffer (entry);
6761 * gtk_entry_set_buffer:
6762 * @entry: a #GtkEntry
6763 * @buffer: a #GtkEntryBuffer
6765 * Set the #GtkEntryBuffer object which holds the text for
6771 gtk_entry_set_buffer (GtkEntry *entry,
6772 GtkEntryBuffer *buffer)
6774 GtkEntryPrivate *priv;
6777 g_return_if_fail (GTK_IS_ENTRY (entry));
6783 g_return_if_fail (GTK_IS_ENTRY_BUFFER (buffer));
6784 g_object_ref (buffer);
6789 buffer_disconnect_signals (entry);
6790 g_object_unref (priv->buffer);
6793 priv->buffer = buffer;
6796 buffer_connect_signals (entry);
6798 obj = G_OBJECT (entry);
6799 g_object_freeze_notify (obj);
6800 g_object_notify (obj, "buffer");
6801 g_object_notify (obj, "text");
6802 g_object_notify (obj, "text-length");
6803 g_object_notify (obj, "max-length");
6804 g_object_notify (obj, "visibility");
6805 g_object_notify (obj, "invisible-char");
6806 g_object_notify (obj, "invisible-char-set");
6807 g_object_thaw_notify (obj);
6809 gtk_editable_set_position (GTK_EDITABLE (entry), 0);
6810 gtk_entry_recompute (entry);
6814 * gtk_entry_get_text_area:
6815 * @entry: a #GtkEntry
6816 * @text_area: (out): Return location for the text area.
6818 * Gets the area where the entry's text is drawn. This function is
6819 * useful when drawing something to the entry in a draw callback.
6821 * If the entry is not realized, @text_area is filled with zeros.
6823 * See also gtk_entry_get_icon_area().
6828 gtk_entry_get_text_area (GtkEntry *entry,
6829 GdkRectangle *text_area)
6831 GtkEntryPrivate *priv;
6833 g_return_if_fail (GTK_IS_ENTRY (entry));
6834 g_return_if_fail (text_area != NULL);
6838 if (priv->text_area)
6840 GtkAllocation allocation;
6843 gtk_widget_get_allocation (GTK_WIDGET (entry), &allocation);
6844 gdk_window_get_position (priv->text_area, &x, &y);
6846 text_area->x = x - allocation.x;
6847 text_area->y = y - allocation.y;
6848 text_area->width = gdk_window_get_width (priv->text_area);
6849 text_area->height = gdk_window_get_height (priv->text_area);
6855 text_area->width = 0;
6856 text_area->height = 0;
6861 * gtk_entry_set_text:
6862 * @entry: a #GtkEntry
6863 * @text: the new text
6865 * Sets the text in the widget to the given
6866 * value, replacing the current contents.
6868 * See gtk_entry_buffer_set_text().
6871 gtk_entry_set_text (GtkEntry *entry,
6875 GtkEntryCompletion *completion;
6877 g_return_if_fail (GTK_IS_ENTRY (entry));
6878 g_return_if_fail (text != NULL);
6880 /* Actually setting the text will affect the cursor and selection;
6881 * if the contents don't actually change, this will look odd to the user.
6883 if (strcmp (gtk_entry_buffer_get_text (get_buffer (entry)), text) == 0)
6886 completion = gtk_entry_get_completion (entry);
6887 if (completion && completion->priv->changed_id > 0)
6888 g_signal_handler_block (entry, completion->priv->changed_id);
6890 begin_change (entry);
6891 gtk_editable_delete_text (GTK_EDITABLE (entry), 0, -1);
6893 gtk_editable_insert_text (GTK_EDITABLE (entry), text, strlen (text), &tmp_pos);
6896 if (completion && completion->priv->changed_id > 0)
6897 g_signal_handler_unblock (entry, completion->priv->changed_id);
6901 * gtk_entry_set_visibility:
6902 * @entry: a #GtkEntry
6903 * @visible: %TRUE if the contents of the entry are displayed
6906 * Sets whether the contents of the entry are visible or not.
6907 * When visibility is set to %FALSE, characters are displayed
6908 * as the invisible char, and will also appear that way when
6909 * the text in the entry widget is copied elsewhere.
6911 * By default, GTK+ picks the best invisible character available
6912 * in the current font, but it can be changed with
6913 * gtk_entry_set_invisible_char().
6916 gtk_entry_set_visibility (GtkEntry *entry,
6919 GtkEntryPrivate *priv;
6921 g_return_if_fail (GTK_IS_ENTRY (entry));
6925 visible = visible != FALSE;
6927 if (priv->visible != visible)
6929 priv->visible = visible;
6931 g_object_notify (G_OBJECT (entry), "visibility");
6932 gtk_entry_recompute (entry);
6937 * gtk_entry_get_visibility:
6938 * @entry: a #GtkEntry
6940 * Retrieves whether the text in @entry is visible. See
6941 * gtk_entry_set_visibility().
6943 * Return value: %TRUE if the text is currently visible
6946 gtk_entry_get_visibility (GtkEntry *entry)
6948 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
6950 return entry->priv->visible;
6954 * gtk_entry_set_invisible_char:
6955 * @entry: a #GtkEntry
6956 * @ch: a Unicode character
6958 * Sets the character to use in place of the actual text when
6959 * gtk_entry_set_visibility() has been called to set text visibility
6960 * to %FALSE. i.e. this is the character used in "password mode" to
6961 * show the user how many characters have been typed. By default, GTK+
6962 * picks the best invisible char available in the current font. If you
6963 * set the invisible char to 0, then the user will get no feedback
6964 * at all; there will be no text on the screen as they type.
6967 gtk_entry_set_invisible_char (GtkEntry *entry,
6970 GtkEntryPrivate *priv;
6972 g_return_if_fail (GTK_IS_ENTRY (entry));
6976 if (!priv->invisible_char_set)
6978 priv->invisible_char_set = TRUE;
6979 g_object_notify (G_OBJECT (entry), "invisible-char-set");
6982 if (ch == priv->invisible_char)
6985 priv->invisible_char = ch;
6986 g_object_notify (G_OBJECT (entry), "invisible-char");
6987 gtk_entry_recompute (entry);
6991 * gtk_entry_get_invisible_char:
6992 * @entry: a #GtkEntry
6994 * Retrieves the character displayed in place of the real characters
6995 * for entries with visibility set to false. See gtk_entry_set_invisible_char().
6997 * Return value: the current invisible char, or 0, if the entry does not
6998 * show invisible text at all.
7001 gtk_entry_get_invisible_char (GtkEntry *entry)
7003 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7005 return entry->priv->invisible_char;
7009 * gtk_entry_unset_invisible_char:
7010 * @entry: a #GtkEntry
7012 * Unsets the invisible char previously set with
7013 * gtk_entry_set_invisible_char(). So that the
7014 * default invisible char is used again.
7019 gtk_entry_unset_invisible_char (GtkEntry *entry)
7021 GtkEntryPrivate *priv;
7024 g_return_if_fail (GTK_IS_ENTRY (entry));
7028 if (!priv->invisible_char_set)
7031 priv->invisible_char_set = FALSE;
7032 ch = find_invisible_char (GTK_WIDGET (entry));
7034 if (priv->invisible_char != ch)
7036 priv->invisible_char = ch;
7037 g_object_notify (G_OBJECT (entry), "invisible-char");
7040 g_object_notify (G_OBJECT (entry), "invisible-char-set");
7041 gtk_entry_recompute (entry);
7045 * gtk_entry_set_overwrite_mode:
7046 * @entry: a #GtkEntry
7047 * @overwrite: new value
7049 * Sets whether the text is overwritten when typing in the #GtkEntry.
7054 gtk_entry_set_overwrite_mode (GtkEntry *entry,
7057 GtkEntryPrivate *priv = entry->priv;
7059 g_return_if_fail (GTK_IS_ENTRY (entry));
7061 if (priv->overwrite_mode == overwrite)
7064 gtk_entry_toggle_overwrite (entry);
7066 g_object_notify (G_OBJECT (entry), "overwrite-mode");
7070 * gtk_entry_get_overwrite_mode:
7071 * @entry: a #GtkEntry
7073 * Gets the value set by gtk_entry_set_overwrite_mode().
7075 * Return value: whether the text is overwritten when typing.
7080 gtk_entry_get_overwrite_mode (GtkEntry *entry)
7082 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7084 return entry->priv->overwrite_mode;
7088 * gtk_entry_get_text:
7089 * @entry: a #GtkEntry
7091 * Retrieves the contents of the entry widget.
7092 * See also gtk_editable_get_chars().
7094 * This is equivalent to:
7096 * <informalexample><programlisting>
7097 * gtk_entry_buffer_get_text (gtk_entry_get_buffer (entry));
7098 * </programlisting></informalexample>
7100 * Return value: a pointer to the contents of the widget as a
7101 * string. This string points to internally allocated
7102 * storage in the widget and must not be freed, modified or
7106 gtk_entry_get_text (GtkEntry *entry)
7108 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7110 return gtk_entry_buffer_get_text (get_buffer (entry));
7114 * gtk_entry_set_max_length:
7115 * @entry: a #GtkEntry
7116 * @max: the maximum length of the entry, or 0 for no maximum.
7117 * (other than the maximum length of entries.) The value passed in will
7118 * be clamped to the range 0-65536.
7120 * Sets the maximum allowed length of the contents of the widget. If
7121 * the current contents are longer than the given length, then they
7122 * will be truncated to fit.
7124 * This is equivalent to:
7126 * <informalexample><programlisting>
7127 * gtk_entry_buffer_set_max_length (gtk_entry_get_buffer (entry), max);
7128 * </programlisting></informalexample>
7131 gtk_entry_set_max_length (GtkEntry *entry,
7134 g_return_if_fail (GTK_IS_ENTRY (entry));
7135 gtk_entry_buffer_set_max_length (get_buffer (entry), max);
7139 * gtk_entry_get_max_length:
7140 * @entry: a #GtkEntry
7142 * Retrieves the maximum allowed length of the text in
7143 * @entry. See gtk_entry_set_max_length().
7145 * This is equivalent to:
7147 * <informalexample><programlisting>
7148 * gtk_entry_buffer_get_max_length (gtk_entry_get_buffer (entry));
7149 * </programlisting></informalexample>
7151 * Return value: the maximum allowed number of characters
7152 * in #GtkEntry, or 0 if there is no maximum.
7155 gtk_entry_get_max_length (GtkEntry *entry)
7157 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7159 return gtk_entry_buffer_get_max_length (get_buffer (entry));
7163 * gtk_entry_get_text_length:
7164 * @entry: a #GtkEntry
7166 * Retrieves the current length of the text in
7169 * This is equivalent to:
7171 * <informalexample><programlisting>
7172 * gtk_entry_buffer_get_length (gtk_entry_get_buffer (entry));
7173 * </programlisting></informalexample>
7175 * Return value: the current number of characters
7176 * in #GtkEntry, or 0 if there are none.
7181 gtk_entry_get_text_length (GtkEntry *entry)
7183 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7185 return gtk_entry_buffer_get_length (get_buffer (entry));
7189 * gtk_entry_set_activates_default:
7190 * @entry: a #GtkEntry
7191 * @setting: %TRUE to activate window's default widget on Enter keypress
7193 * If @setting is %TRUE, pressing Enter in the @entry will activate the default
7194 * widget for the window containing the entry. This usually means that
7195 * the dialog box containing the entry will be closed, since the default
7196 * widget is usually one of the dialog buttons.
7198 * (For experts: if @setting is %TRUE, the entry calls
7199 * gtk_window_activate_default() on the window containing the entry, in
7200 * the default handler for the #GtkEntry::activate signal.)
7203 gtk_entry_set_activates_default (GtkEntry *entry,
7206 GtkEntryPrivate *priv;
7208 g_return_if_fail (GTK_IS_ENTRY (entry));
7212 setting = setting != FALSE;
7214 if (setting != priv->activates_default)
7216 priv->activates_default = setting;
7217 g_object_notify (G_OBJECT (entry), "activates-default");
7222 * gtk_entry_get_activates_default:
7223 * @entry: a #GtkEntry
7225 * Retrieves the value set by gtk_entry_set_activates_default().
7227 * Return value: %TRUE if the entry will activate the default widget
7230 gtk_entry_get_activates_default (GtkEntry *entry)
7232 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7234 return entry->priv->activates_default;
7238 * gtk_entry_set_width_chars:
7239 * @entry: a #GtkEntry
7240 * @n_chars: width in chars
7242 * Changes the size request of the entry to be about the right size
7243 * for @n_chars characters. Note that it changes the size
7244 * <emphasis>request</emphasis>, the size can still be affected by
7245 * how you pack the widget into containers. If @n_chars is -1, the
7246 * size reverts to the default entry size.
7249 gtk_entry_set_width_chars (GtkEntry *entry,
7252 GtkEntryPrivate *priv;
7254 g_return_if_fail (GTK_IS_ENTRY (entry));
7258 if (priv->width_chars != n_chars)
7260 priv->width_chars = n_chars;
7261 g_object_notify (G_OBJECT (entry), "width-chars");
7262 gtk_widget_queue_resize (GTK_WIDGET (entry));
7267 * gtk_entry_get_width_chars:
7268 * @entry: a #GtkEntry
7270 * Gets the value set by gtk_entry_set_width_chars().
7272 * Return value: number of chars to request space for, or negative if unset
7275 gtk_entry_get_width_chars (GtkEntry *entry)
7277 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7279 return entry->priv->width_chars;
7283 * gtk_entry_set_has_frame:
7284 * @entry: a #GtkEntry
7285 * @setting: new value
7287 * Sets whether the entry has a beveled frame around it.
7290 gtk_entry_set_has_frame (GtkEntry *entry,
7293 GtkEntryPrivate *priv;
7295 g_return_if_fail (GTK_IS_ENTRY (entry));
7299 setting = (setting != FALSE);
7301 if (priv->has_frame == setting)
7304 gtk_widget_queue_resize (GTK_WIDGET (entry));
7305 priv->has_frame = setting;
7306 g_object_notify (G_OBJECT (entry), "has-frame");
7310 * gtk_entry_get_has_frame:
7311 * @entry: a #GtkEntry
7313 * Gets the value set by gtk_entry_set_has_frame().
7315 * Return value: whether the entry has a beveled frame
7318 gtk_entry_get_has_frame (GtkEntry *entry)
7320 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7322 return entry->priv->has_frame;
7326 * gtk_entry_set_inner_border:
7327 * @entry: a #GtkEntry
7328 * @border: (allow-none): a #GtkBorder, or %NULL
7330 * Sets %entry's inner-border property to %border, or clears it if %NULL
7331 * is passed. The inner-border is the area around the entry's text, but
7334 * If set, this property overrides the inner-border style property.
7335 * Overriding the style-provided border is useful when you want to do
7336 * in-place editing of some text in a canvas or list widget, where
7337 * pixel-exact positioning of the entry is important.
7341 * Deprecated: 3.4: Use the standard border and padding CSS properties (through
7342 * objects like #GtkStyleContext and #GtkCssProvider); the value set with
7343 * this function is ignored by #GtkEntry.
7346 gtk_entry_set_inner_border (GtkEntry *entry,
7347 const GtkBorder *border)
7349 g_return_if_fail (GTK_IS_ENTRY (entry));
7351 gtk_entry_do_set_inner_border (entry, border);
7355 * gtk_entry_get_inner_border:
7356 * @entry: a #GtkEntry
7358 * This function returns the entry's #GtkEntry:inner-border property. See
7359 * gtk_entry_set_inner_border() for more information.
7361 * Return value: (transfer none): the entry's #GtkBorder, or %NULL if none was set.
7365 * Deprecated: 3.4: Use the standard border and padding CSS properties (through
7366 * objects like #GtkStyleContext and #GtkCssProvider); the value returned by
7367 * this function is ignored by #GtkEntry.
7370 gtk_entry_get_inner_border (GtkEntry *entry)
7372 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7374 return gtk_entry_do_get_inner_border (entry);
7378 * gtk_entry_get_layout:
7379 * @entry: a #GtkEntry
7381 * Gets the #PangoLayout used to display the entry.
7382 * The layout is useful to e.g. convert text positions to
7383 * pixel positions, in combination with gtk_entry_get_layout_offsets().
7384 * The returned layout is owned by the entry and must not be
7385 * modified or freed by the caller.
7387 * Keep in mind that the layout text may contain a preedit string, so
7388 * gtk_entry_layout_index_to_text_index() and
7389 * gtk_entry_text_index_to_layout_index() are needed to convert byte
7390 * indices in the layout to byte indices in the entry contents.
7392 * Return value: (transfer none): the #PangoLayout for this entry
7395 gtk_entry_get_layout (GtkEntry *entry)
7397 PangoLayout *layout;
7399 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7401 layout = gtk_entry_ensure_layout (entry, TRUE);
7408 * gtk_entry_layout_index_to_text_index:
7409 * @entry: a #GtkEntry
7410 * @layout_index: byte index into the entry layout text
7412 * Converts from a position in the entry contents (returned
7413 * by gtk_entry_get_text()) to a position in the
7414 * entry's #PangoLayout (returned by gtk_entry_get_layout(),
7415 * with text retrieved via pango_layout_get_text()).
7417 * Return value: byte index into the entry contents
7420 gtk_entry_layout_index_to_text_index (GtkEntry *entry,
7423 GtkEntryPrivate *priv;
7424 PangoLayout *layout;
7428 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7432 layout = gtk_entry_ensure_layout (entry, TRUE);
7433 text = pango_layout_get_text (layout);
7434 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos) - text;
7436 if (layout_index >= cursor_index && priv->preedit_length)
7438 if (layout_index >= cursor_index + priv->preedit_length)
7439 layout_index -= priv->preedit_length;
7441 layout_index = cursor_index;
7444 return layout_index;
7448 * gtk_entry_text_index_to_layout_index:
7449 * @entry: a #GtkEntry
7450 * @text_index: byte index into the entry contents
7452 * Converts from a position in the entry's #PangoLayout (returned by
7453 * gtk_entry_get_layout()) to a position in the entry contents
7454 * (returned by gtk_entry_get_text()).
7456 * Return value: byte index into the entry layout text
7459 gtk_entry_text_index_to_layout_index (GtkEntry *entry,
7462 GtkEntryPrivate *priv;
7463 PangoLayout *layout;
7467 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7471 layout = gtk_entry_ensure_layout (entry, TRUE);
7472 text = pango_layout_get_text (layout);
7473 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos) - text;
7475 if (text_index > cursor_index)
7476 text_index += priv->preedit_length;
7482 * gtk_entry_get_layout_offsets:
7483 * @entry: a #GtkEntry
7484 * @x: (out) (allow-none): location to store X offset of layout, or %NULL
7485 * @y: (out) (allow-none): location to store Y offset of layout, or %NULL
7488 * Obtains the position of the #PangoLayout used to render text
7489 * in the entry, in widget coordinates. Useful if you want to line
7490 * up the text in an entry with some other text, e.g. when using the
7491 * entry to implement editable cells in a sheet widget.
7493 * Also useful to convert mouse events into coordinates inside the
7494 * #PangoLayout, e.g. to take some action if some part of the entry text
7497 * Note that as the user scrolls around in the entry the offsets will
7498 * change; you'll need to connect to the "notify::scroll-offset"
7499 * signal to track this. Remember when using the #PangoLayout
7500 * functions you need to convert to and from pixels using
7501 * PANGO_PIXELS() or #PANGO_SCALE.
7503 * Keep in mind that the layout text may contain a preedit string, so
7504 * gtk_entry_layout_index_to_text_index() and
7505 * gtk_entry_text_index_to_layout_index() are needed to convert byte
7506 * indices in the layout to byte indices in the entry contents.
7509 gtk_entry_get_layout_offsets (GtkEntry *entry,
7513 gint text_area_x, text_area_y;
7515 g_return_if_fail (GTK_IS_ENTRY (entry));
7517 /* this gets coords relative to text area */
7518 get_layout_position (entry, x, y);
7520 /* convert to widget coords */
7521 gtk_entry_get_text_area_size (entry, &text_area_x, &text_area_y, NULL, NULL);
7532 * gtk_entry_set_alignment:
7533 * @entry: a #GtkEntry
7534 * @xalign: The horizontal alignment, from 0 (left) to 1 (right).
7535 * Reversed for RTL layouts
7537 * Sets the alignment for the contents of the entry. This controls
7538 * the horizontal positioning of the contents when the displayed
7539 * text is shorter than the width of the entry.
7544 gtk_entry_set_alignment (GtkEntry *entry, gfloat xalign)
7546 GtkEntryPrivate *priv;
7548 g_return_if_fail (GTK_IS_ENTRY (entry));
7554 else if (xalign > 1.0)
7557 if (xalign != priv->xalign)
7559 priv->xalign = xalign;
7561 gtk_entry_recompute (entry);
7563 g_object_notify (G_OBJECT (entry), "xalign");
7568 * gtk_entry_get_alignment:
7569 * @entry: a #GtkEntry
7571 * Gets the value set by gtk_entry_set_alignment().
7573 * Return value: the alignment
7578 gtk_entry_get_alignment (GtkEntry *entry)
7580 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
7582 return entry->priv->xalign;
7586 * gtk_entry_set_icon_from_pixbuf:
7587 * @entry: a #GtkEntry
7588 * @icon_pos: Icon position
7589 * @pixbuf: (allow-none): A #GdkPixbuf, or %NULL
7591 * Sets the icon shown in the specified position using a pixbuf.
7593 * If @pixbuf is %NULL, no icon will be shown in the specified position.
7598 gtk_entry_set_icon_from_pixbuf (GtkEntry *entry,
7599 GtkEntryIconPosition icon_pos,
7602 GtkEntryPrivate *priv;
7603 EntryIconInfo *icon_info;
7605 g_return_if_fail (GTK_IS_ENTRY (entry));
7606 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7610 if ((icon_info = priv->icons[icon_pos]) == NULL)
7611 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7613 g_object_freeze_notify (G_OBJECT (entry));
7616 g_object_ref (pixbuf);
7618 gtk_entry_clear (entry, icon_pos);
7622 _gtk_icon_helper_set_pixbuf (icon_info->icon_helper, pixbuf);
7624 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7626 g_object_notify (G_OBJECT (entry), "primary-icon-pixbuf");
7627 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7631 g_object_notify (G_OBJECT (entry), "secondary-icon-pixbuf");
7632 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7635 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7636 gdk_window_show_unraised (icon_info->window);
7638 g_object_unref (pixbuf);
7641 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7642 gtk_widget_queue_resize (GTK_WIDGET (entry));
7644 g_object_thaw_notify (G_OBJECT (entry));
7648 * gtk_entry_set_icon_from_stock:
7649 * @entry: A #GtkEntry
7650 * @icon_pos: Icon position
7651 * @stock_id: (allow-none): The name of the stock item, or %NULL
7653 * Sets the icon shown in the entry at the specified position from
7656 * If @stock_id is %NULL, no icon will be shown in the specified position.
7661 gtk_entry_set_icon_from_stock (GtkEntry *entry,
7662 GtkEntryIconPosition icon_pos,
7663 const gchar *stock_id)
7665 GtkEntryPrivate *priv;
7666 EntryIconInfo *icon_info;
7669 g_return_if_fail (GTK_IS_ENTRY (entry));
7670 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7674 if ((icon_info = priv->icons[icon_pos]) == NULL)
7675 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7677 g_object_freeze_notify (G_OBJECT (entry));
7679 /* need to dup before clearing */
7680 new_id = g_strdup (stock_id);
7682 gtk_entry_clear (entry, icon_pos);
7686 _gtk_icon_helper_set_stock_id (icon_info->icon_helper, new_id, GTK_ICON_SIZE_MENU);
7688 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7690 g_object_notify (G_OBJECT (entry), "primary-icon-stock");
7691 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7695 g_object_notify (G_OBJECT (entry), "secondary-icon-stock");
7696 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7699 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7700 gdk_window_show_unraised (icon_info->window);
7705 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7706 gtk_widget_queue_resize (GTK_WIDGET (entry));
7708 g_object_thaw_notify (G_OBJECT (entry));
7712 * gtk_entry_set_icon_from_icon_name:
7713 * @entry: A #GtkEntry
7714 * @icon_pos: The position at which to set the icon
7715 * @icon_name: (allow-none): An icon name, or %NULL
7717 * Sets the icon shown in the entry at the specified position
7718 * from the current icon theme.
7720 * If the icon name isn't known, a "broken image" icon will be displayed
7723 * If @icon_name is %NULL, no icon will be shown in the specified position.
7728 gtk_entry_set_icon_from_icon_name (GtkEntry *entry,
7729 GtkEntryIconPosition icon_pos,
7730 const gchar *icon_name)
7732 GtkEntryPrivate *priv;
7733 EntryIconInfo *icon_info;
7736 g_return_if_fail (GTK_IS_ENTRY (entry));
7737 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7741 if ((icon_info = priv->icons[icon_pos]) == NULL)
7742 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7744 g_object_freeze_notify (G_OBJECT (entry));
7746 /* need to dup before clearing */
7747 new_name = g_strdup (icon_name);
7749 gtk_entry_clear (entry, icon_pos);
7751 if (new_name != NULL)
7753 _gtk_icon_helper_set_icon_name (icon_info->icon_helper, new_name, GTK_ICON_SIZE_MENU);
7755 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7757 g_object_notify (G_OBJECT (entry), "primary-icon-name");
7758 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7762 g_object_notify (G_OBJECT (entry), "secondary-icon-name");
7763 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7766 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7767 gdk_window_show_unraised (icon_info->window);
7772 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7773 gtk_widget_queue_resize (GTK_WIDGET (entry));
7775 g_object_thaw_notify (G_OBJECT (entry));
7779 * gtk_entry_set_icon_from_gicon:
7780 * @entry: A #GtkEntry
7781 * @icon_pos: The position at which to set the icon
7782 * @icon: (allow-none): The icon to set, or %NULL
7784 * Sets the icon shown in the entry at the specified position
7785 * from the current icon theme.
7786 * If the icon isn't known, a "broken image" icon will be displayed
7789 * If @icon is %NULL, no icon will be shown in the specified position.
7794 gtk_entry_set_icon_from_gicon (GtkEntry *entry,
7795 GtkEntryIconPosition icon_pos,
7798 GtkEntryPrivate *priv;
7799 EntryIconInfo *icon_info;
7801 g_return_if_fail (GTK_IS_ENTRY (entry));
7802 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7806 if ((icon_info = priv->icons[icon_pos]) == NULL)
7807 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7809 g_object_freeze_notify (G_OBJECT (entry));
7811 /* need to ref before clearing */
7813 g_object_ref (icon);
7815 gtk_entry_clear (entry, icon_pos);
7819 _gtk_icon_helper_set_gicon (icon_info->icon_helper, icon, GTK_ICON_SIZE_MENU);
7821 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7823 g_object_notify (G_OBJECT (entry), "primary-icon-gicon");
7824 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7828 g_object_notify (G_OBJECT (entry), "secondary-icon-gicon");
7829 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7832 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7833 gdk_window_show_unraised (icon_info->window);
7835 g_object_unref (icon);
7838 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7839 gtk_widget_queue_resize (GTK_WIDGET (entry));
7841 g_object_thaw_notify (G_OBJECT (entry));
7845 * gtk_entry_set_icon_activatable:
7846 * @entry: A #GtkEntry
7847 * @icon_pos: Icon position
7848 * @activatable: %TRUE if the icon should be activatable
7850 * Sets whether the icon is activatable.
7855 gtk_entry_set_icon_activatable (GtkEntry *entry,
7856 GtkEntryIconPosition icon_pos,
7857 gboolean activatable)
7859 GtkEntryPrivate *priv;
7860 EntryIconInfo *icon_info;
7862 g_return_if_fail (GTK_IS_ENTRY (entry));
7863 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7867 if ((icon_info = priv->icons[icon_pos]) == NULL)
7868 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7870 activatable = activatable != FALSE;
7872 if (icon_info->nonactivatable != !activatable)
7874 icon_info->nonactivatable = !activatable;
7876 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
7877 update_cursors (GTK_WIDGET (entry));
7879 g_object_notify (G_OBJECT (entry),
7880 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-activatable" : "secondary-icon-activatable");
7885 * gtk_entry_get_icon_activatable:
7886 * @entry: a #GtkEntry
7887 * @icon_pos: Icon position
7889 * Returns whether the icon is activatable.
7891 * Returns: %TRUE if the icon is activatable.
7896 gtk_entry_get_icon_activatable (GtkEntry *entry,
7897 GtkEntryIconPosition icon_pos)
7899 GtkEntryPrivate *priv;
7900 EntryIconInfo *icon_info;
7902 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7903 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), FALSE);
7906 icon_info = priv->icons[icon_pos];
7908 return (!icon_info || !icon_info->nonactivatable);
7912 * gtk_entry_get_icon_pixbuf:
7913 * @entry: A #GtkEntry
7914 * @icon_pos: Icon position
7916 * Retrieves the image used for the icon.
7918 * Unlike the other methods of setting and getting icon data, this
7919 * method will work regardless of whether the icon was set using a
7920 * #GdkPixbuf, a #GIcon, a stock item, or an icon name.
7922 * Returns: (transfer none): A #GdkPixbuf, or %NULL if no icon is
7923 * set for this position.
7928 gtk_entry_get_icon_pixbuf (GtkEntry *entry,
7929 GtkEntryIconPosition icon_pos)
7931 GtkEntryPrivate *priv;
7932 EntryIconInfo *icon_info;
7935 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7936 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7940 icon_info = priv->icons[icon_pos];
7945 /* HACK: unfortunately this is transfer none, so we need to return
7946 * the icon helper's cache ref directly.
7948 pixbuf = gtk_entry_ensure_pixbuf (entry, icon_pos);
7949 g_object_unref (pixbuf);
7955 * gtk_entry_get_icon_gicon:
7956 * @entry: A #GtkEntry
7957 * @icon_pos: Icon position
7959 * Retrieves the #GIcon used for the icon, or %NULL if there is
7960 * no icon or if the icon was set by some other method (e.g., by
7961 * stock, pixbuf, or icon name).
7963 * Returns: (transfer none): A #GIcon, or %NULL if no icon is set
7964 * or if the icon is not a #GIcon
7969 gtk_entry_get_icon_gicon (GtkEntry *entry,
7970 GtkEntryIconPosition icon_pos)
7972 GtkEntryPrivate *priv;
7973 EntryIconInfo *icon_info;
7975 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7976 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7979 icon_info = priv->icons[icon_pos];
7984 return _gtk_icon_helper_peek_gicon (icon_info->icon_helper);
7988 * gtk_entry_get_icon_stock:
7989 * @entry: A #GtkEntry
7990 * @icon_pos: Icon position
7992 * Retrieves the stock id used for the icon, or %NULL if there is
7993 * no icon or if the icon was set by some other method (e.g., by
7994 * pixbuf, icon name or gicon).
7996 * Returns: A stock id, or %NULL if no icon is set or if the icon
7997 * wasn't set from a stock id
8002 gtk_entry_get_icon_stock (GtkEntry *entry,
8003 GtkEntryIconPosition icon_pos)
8005 GtkEntryPrivate *priv;
8006 EntryIconInfo *icon_info;
8008 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8009 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8012 icon_info = priv->icons[icon_pos];
8017 return _gtk_icon_helper_get_stock_id (icon_info->icon_helper);
8021 * gtk_entry_get_icon_name:
8022 * @entry: A #GtkEntry
8023 * @icon_pos: Icon position
8025 * Retrieves the icon name used for the icon, or %NULL if there is
8026 * no icon or if the icon was set by some other method (e.g., by
8027 * pixbuf, stock or gicon).
8029 * Returns: An icon name, or %NULL if no icon is set or if the icon
8030 * wasn't set from an icon name
8035 gtk_entry_get_icon_name (GtkEntry *entry,
8036 GtkEntryIconPosition icon_pos)
8038 GtkEntryPrivate *priv;
8039 EntryIconInfo *icon_info;
8041 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8042 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8045 icon_info = priv->icons[icon_pos];
8050 return _gtk_icon_helper_get_icon_name (icon_info->icon_helper);
8054 * gtk_entry_set_icon_sensitive:
8055 * @entry: A #GtkEntry
8056 * @icon_pos: Icon position
8057 * @sensitive: Specifies whether the icon should appear
8058 * sensitive or insensitive
8060 * Sets the sensitivity for the specified icon.
8065 gtk_entry_set_icon_sensitive (GtkEntry *entry,
8066 GtkEntryIconPosition icon_pos,
8069 GtkEntryPrivate *priv;
8070 EntryIconInfo *icon_info;
8072 g_return_if_fail (GTK_IS_ENTRY (entry));
8073 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8077 if ((icon_info = priv->icons[icon_pos]) == NULL)
8078 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8080 if (icon_info->insensitive != !sensitive)
8082 icon_info->insensitive = !sensitive;
8084 icon_info->pressed = FALSE;
8085 icon_info->prelight = FALSE;
8087 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
8088 update_cursors (GTK_WIDGET (entry));
8090 gtk_widget_queue_draw (GTK_WIDGET (entry));
8092 g_object_notify (G_OBJECT (entry),
8093 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-sensitive" : "secondary-icon-sensitive");
8098 * gtk_entry_get_icon_sensitive:
8099 * @entry: a #GtkEntry
8100 * @icon_pos: Icon position
8102 * Returns whether the icon appears sensitive or insensitive.
8104 * Returns: %TRUE if the icon is sensitive.
8109 gtk_entry_get_icon_sensitive (GtkEntry *entry,
8110 GtkEntryIconPosition icon_pos)
8112 GtkEntryPrivate *priv;
8113 EntryIconInfo *icon_info;
8115 g_return_val_if_fail (GTK_IS_ENTRY (entry), TRUE);
8116 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), TRUE);
8120 icon_info = priv->icons[icon_pos];
8122 return (!icon_info || !icon_info->insensitive);
8127 * gtk_entry_get_icon_storage_type:
8128 * @entry: a #GtkEntry
8129 * @icon_pos: Icon position
8131 * Gets the type of representation being used by the icon
8132 * to store image data. If the icon has no image data,
8133 * the return value will be %GTK_IMAGE_EMPTY.
8135 * Return value: image representation being used
8140 gtk_entry_get_icon_storage_type (GtkEntry *entry,
8141 GtkEntryIconPosition icon_pos)
8143 GtkEntryPrivate *priv;
8144 EntryIconInfo *icon_info;
8146 g_return_val_if_fail (GTK_IS_ENTRY (entry), GTK_IMAGE_EMPTY);
8147 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), GTK_IMAGE_EMPTY);
8151 icon_info = priv->icons[icon_pos];
8154 return GTK_IMAGE_EMPTY;
8156 return _gtk_icon_helper_get_storage_type (icon_info->icon_helper);
8160 * gtk_entry_get_icon_at_pos:
8161 * @entry: a #GtkEntry
8162 * @x: the x coordinate of the position to find
8163 * @y: the y coordinate of the position to find
8165 * Finds the icon at the given position and return its index. The
8166 * position's coordinates are relative to the @entry's top left corner.
8167 * If @x, @y doesn't lie inside an icon, -1 is returned.
8168 * This function is intended for use in a #GtkWidget::query-tooltip
8171 * Returns: the index of the icon at the given position, or -1
8176 gtk_entry_get_icon_at_pos (GtkEntry *entry,
8180 GtkAllocation primary;
8181 GtkAllocation secondary;
8182 gint frame_x, frame_y;
8184 g_return_val_if_fail (GTK_IS_ENTRY (entry), -1);
8186 get_frame_size (entry, FALSE, &frame_x, &frame_y, NULL, NULL);
8190 get_icon_allocations (entry, &primary, &secondary);
8192 if (primary.x <= x && x < primary.x + primary.width &&
8193 primary.y <= y && y < primary.y + primary.height)
8194 return GTK_ENTRY_ICON_PRIMARY;
8196 if (secondary.x <= x && x < secondary.x + secondary.width &&
8197 secondary.y <= y && y < secondary.y + secondary.height)
8198 return GTK_ENTRY_ICON_SECONDARY;
8204 * gtk_entry_set_icon_drag_source:
8205 * @entry: a #GtkEntry
8206 * @icon_pos: icon position
8207 * @target_list: the targets (data formats) in which the data can be provided
8208 * @actions: a bitmask of the allowed drag actions
8210 * Sets up the icon at the given position so that GTK+ will start a drag
8211 * operation when the user clicks and drags the icon.
8213 * To handle the drag operation, you need to connect to the usual
8214 * #GtkWidget::drag-data-get (or possibly #GtkWidget::drag-data-delete)
8215 * signal, and use gtk_entry_get_current_icon_drag_source() in
8216 * your signal handler to find out if the drag was started from
8219 * By default, GTK+ uses the icon as the drag icon. You can use the
8220 * #GtkWidget::drag-begin signal to set a different icon. Note that you
8221 * have to use g_signal_connect_after() to ensure that your signal handler
8222 * gets executed after the default handler.
8227 gtk_entry_set_icon_drag_source (GtkEntry *entry,
8228 GtkEntryIconPosition icon_pos,
8229 GtkTargetList *target_list,
8230 GdkDragAction actions)
8232 GtkEntryPrivate *priv;
8233 EntryIconInfo *icon_info;
8235 g_return_if_fail (GTK_IS_ENTRY (entry));
8236 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8240 if ((icon_info = priv->icons[icon_pos]) == NULL)
8241 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8243 if (icon_info->target_list)
8244 gtk_target_list_unref (icon_info->target_list);
8245 icon_info->target_list = target_list;
8246 if (icon_info->target_list)
8247 gtk_target_list_ref (icon_info->target_list);
8249 icon_info->actions = actions;
8253 * gtk_entry_get_current_icon_drag_source:
8254 * @entry: a #GtkIconEntry
8256 * Returns the index of the icon which is the source of the current
8257 * DND operation, or -1.
8259 * This function is meant to be used in a #GtkWidget::drag-data-get
8262 * Returns: index of the icon which is the source of the current
8263 * DND operation, or -1.
8268 gtk_entry_get_current_icon_drag_source (GtkEntry *entry)
8270 GtkEntryPrivate *priv;
8271 EntryIconInfo *icon_info = NULL;
8274 g_return_val_if_fail (GTK_IS_ENTRY (entry), -1);
8278 for (i = 0; i < MAX_ICONS; i++)
8280 if ((icon_info = priv->icons[i]))
8282 if (icon_info->in_drag)
8291 * gtk_entry_get_icon_area:
8292 * @entry: A #GtkEntry
8293 * @icon_pos: Icon position
8294 * @icon_area: (out): Return location for the icon's area
8296 * Gets the area where entry's icon at @icon_pos is drawn.
8297 * This function is useful when drawing something to the
8298 * entry in a draw callback.
8300 * If the entry is not realized or has no icon at the given position,
8301 * @icon_area is filled with zeros.
8303 * See also gtk_entry_get_text_area()
8308 gtk_entry_get_icon_area (GtkEntry *entry,
8309 GtkEntryIconPosition icon_pos,
8310 GdkRectangle *icon_area)
8312 GtkEntryPrivate *priv;
8313 EntryIconInfo *icon_info;
8315 g_return_if_fail (GTK_IS_ENTRY (entry));
8316 g_return_if_fail (icon_area != NULL);
8320 icon_info = priv->icons[icon_pos];
8324 GtkAllocation primary;
8325 GtkAllocation secondary;
8327 get_icon_allocations (entry, &primary, &secondary);
8329 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
8330 *icon_area = primary;
8332 *icon_area = secondary;
8338 icon_area->width = 0;
8339 icon_area->height = 0;
8344 ensure_has_tooltip (GtkEntry *entry)
8346 GtkEntryPrivate *priv;
8347 EntryIconInfo *icon_info;
8349 gboolean has_tooltip = FALSE;
8353 for (i = 0; i < MAX_ICONS; i++)
8355 if ((icon_info = priv->icons[i]) != NULL)
8357 if (icon_info->tooltip != NULL)
8365 gtk_widget_set_has_tooltip (GTK_WIDGET (entry), has_tooltip);
8369 * gtk_entry_get_icon_tooltip_text:
8370 * @entry: a #GtkEntry
8371 * @icon_pos: the icon position
8373 * Gets the contents of the tooltip on the icon at the specified
8374 * position in @entry.
8376 * Returns: the tooltip text, or %NULL. Free the returned string
8377 * with g_free() when done.
8382 gtk_entry_get_icon_tooltip_text (GtkEntry *entry,
8383 GtkEntryIconPosition icon_pos)
8385 GtkEntryPrivate *priv;
8386 EntryIconInfo *icon_info;
8389 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8390 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8394 icon_info = priv->icons[icon_pos];
8399 if (icon_info->tooltip &&
8400 !pango_parse_markup (icon_info->tooltip, -1, 0, NULL, &text, NULL, NULL))
8401 g_assert (NULL == text); /* text should still be NULL in case of markup errors */
8407 * gtk_entry_set_icon_tooltip_text:
8408 * @entry: a #GtkEntry
8409 * @icon_pos: the icon position
8410 * @tooltip: (allow-none): the contents of the tooltip for the icon, or %NULL
8412 * Sets @tooltip as the contents of the tooltip for the icon
8413 * at the specified position.
8415 * Use %NULL for @tooltip to remove an existing tooltip.
8417 * See also gtk_widget_set_tooltip_text() and
8418 * gtk_entry_set_icon_tooltip_markup().
8423 gtk_entry_set_icon_tooltip_text (GtkEntry *entry,
8424 GtkEntryIconPosition icon_pos,
8425 const gchar *tooltip)
8427 GtkEntryPrivate *priv;
8428 EntryIconInfo *icon_info;
8430 g_return_if_fail (GTK_IS_ENTRY (entry));
8431 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8435 if ((icon_info = priv->icons[icon_pos]) == NULL)
8436 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8438 if (icon_info->tooltip)
8439 g_free (icon_info->tooltip);
8441 /* Treat an empty string as a NULL string,
8442 * because an empty string would be useless for a tooltip:
8444 if (tooltip && tooltip[0] == '\0')
8447 icon_info->tooltip = tooltip ? g_markup_escape_text (tooltip, -1) : NULL;
8449 ensure_has_tooltip (entry);
8453 * gtk_entry_get_icon_tooltip_markup:
8454 * @entry: a #GtkEntry
8455 * @icon_pos: the icon position
8457 * Gets the contents of the tooltip on the icon at the specified
8458 * position in @entry.
8460 * Returns: the tooltip text, or %NULL. Free the returned string
8461 * with g_free() when done.
8466 gtk_entry_get_icon_tooltip_markup (GtkEntry *entry,
8467 GtkEntryIconPosition icon_pos)
8469 GtkEntryPrivate *priv;
8470 EntryIconInfo *icon_info;
8472 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8473 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8477 icon_info = priv->icons[icon_pos];
8482 return g_strdup (icon_info->tooltip);
8486 * gtk_entry_set_icon_tooltip_markup:
8487 * @entry: a #GtkEntry
8488 * @icon_pos: the icon position
8489 * @tooltip: (allow-none): the contents of the tooltip for the icon, or %NULL
8491 * Sets @tooltip as the contents of the tooltip for the icon at
8492 * the specified position. @tooltip is assumed to be marked up with
8493 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
8495 * Use %NULL for @tooltip to remove an existing tooltip.
8497 * See also gtk_widget_set_tooltip_markup() and
8498 * gtk_entry_set_icon_tooltip_text().
8503 gtk_entry_set_icon_tooltip_markup (GtkEntry *entry,
8504 GtkEntryIconPosition icon_pos,
8505 const gchar *tooltip)
8507 GtkEntryPrivate *priv;
8508 EntryIconInfo *icon_info;
8510 g_return_if_fail (GTK_IS_ENTRY (entry));
8511 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8515 if ((icon_info = priv->icons[icon_pos]) == NULL)
8516 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8518 if (icon_info->tooltip)
8519 g_free (icon_info->tooltip);
8521 /* Treat an empty string as a NULL string,
8522 * because an empty string would be useless for a tooltip:
8524 if (tooltip && tooltip[0] == '\0')
8527 icon_info->tooltip = g_strdup (tooltip);
8529 ensure_has_tooltip (entry);
8533 gtk_entry_query_tooltip (GtkWidget *widget,
8536 gboolean keyboard_tip,
8537 GtkTooltip *tooltip)
8540 GtkEntryPrivate *priv;
8541 EntryIconInfo *icon_info;
8544 entry = GTK_ENTRY (widget);
8549 icon_pos = gtk_entry_get_icon_at_pos (entry, x, y);
8552 if ((icon_info = priv->icons[icon_pos]) != NULL)
8554 if (icon_info->tooltip)
8556 gtk_tooltip_set_markup (tooltip, icon_info->tooltip);
8565 return GTK_WIDGET_CLASS (gtk_entry_parent_class)->query_tooltip (widget,
8572 /* Quick hack of a popup menu
8575 activate_cb (GtkWidget *menuitem,
8578 const gchar *signal = g_object_get_data (G_OBJECT (menuitem), "gtk-signal");
8579 g_signal_emit_by_name (entry, signal);
8584 gtk_entry_mnemonic_activate (GtkWidget *widget,
8585 gboolean group_cycling)
8587 gtk_widget_grab_focus (widget);
8592 gtk_entry_grab_notify (GtkWidget *widget,
8593 gboolean was_grabbed)
8595 GtkEntryPrivate *priv;
8597 priv = GTK_ENTRY (widget)->priv;
8600 gtk_widget_device_is_shadowed (widget, priv->device))
8602 /* Unset button so we don't expect
8603 * a button release anymore
8606 priv->device = NULL;
8607 priv->in_drag = FALSE;
8612 append_action_signal (GtkEntry *entry,
8614 const gchar *stock_id,
8615 const gchar *signal,
8618 GtkWidget *menuitem = gtk_image_menu_item_new_from_stock (stock_id, NULL);
8620 g_object_set_data (G_OBJECT (menuitem), I_("gtk-signal"), (char *)signal);
8621 g_signal_connect (menuitem, "activate",
8622 G_CALLBACK (activate_cb), entry);
8624 gtk_widget_set_sensitive (menuitem, sensitive);
8626 gtk_widget_show (menuitem);
8627 gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
8631 popup_menu_detach (GtkWidget *attach_widget,
8634 GtkEntry *entry_attach = GTK_ENTRY (attach_widget);
8635 GtkEntryPrivate *priv_attach = entry_attach->priv;
8637 priv_attach->popup_menu = NULL;
8641 popup_position_func (GtkMenu *menu,
8647 GtkEntry *entry = GTK_ENTRY (user_data);
8648 GtkEntryPrivate *priv = entry->priv;
8649 GtkWidget *widget = GTK_WIDGET (entry);
8651 GtkRequisition menu_req;
8652 GdkRectangle monitor;
8654 gint monitor_num, strong_x, height;
8656 g_return_if_fail (gtk_widget_get_realized (widget));
8658 gdk_window_get_origin (priv->text_area, x, y);
8660 screen = gtk_widget_get_screen (widget);
8661 monitor_num = gdk_screen_get_monitor_at_window (screen, priv->text_area);
8662 if (monitor_num < 0)
8664 gtk_menu_set_monitor (menu, monitor_num);
8666 gdk_screen_get_monitor_workarea (screen, monitor_num, &monitor);
8667 gtk_widget_get_preferred_size (priv->popup_menu,
8669 height = gdk_window_get_height (priv->text_area);
8670 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
8671 _gtk_entry_get_borders (entry, &borders);
8673 *x += borders.left + strong_x - priv->scroll_offset;
8674 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
8675 *x -= menu_req.width;
8677 if ((*y + height + menu_req.height) <= monitor.y + monitor.height)
8679 else if ((*y - menu_req.height) >= monitor.y)
8680 *y -= menu_req.height;
8681 else if (monitor.y + monitor.height - (*y + height) > *y)
8684 *y -= menu_req.height;
8690 unichar_chosen_func (const char *text,
8693 GtkEntry *entry = GTK_ENTRY (data);
8694 GtkEntryPrivate *priv = entry->priv;
8697 gtk_entry_enter_text (entry, text);
8709 popup_targets_received (GtkClipboard *clipboard,
8710 GtkSelectionData *data,
8713 PopupInfo *info = user_data;
8714 GtkEntry *entry = info->entry;
8715 GtkEntryPrivate *info_entry_priv = entry->priv;
8717 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
8720 gboolean clipboard_contains_text;
8721 GtkWidget *menuitem;
8723 gboolean show_input_method_menu;
8724 gboolean show_unicode_menu;
8726 clipboard_contains_text = gtk_selection_data_targets_include_text (data);
8727 if (info_entry_priv->popup_menu)
8728 gtk_widget_destroy (info_entry_priv->popup_menu);
8730 info_entry_priv->popup_menu = gtk_menu_new ();
8732 gtk_menu_attach_to_widget (GTK_MENU (info_entry_priv->popup_menu),
8736 mode = gtk_entry_get_display_mode (entry);
8737 append_action_signal (entry, info_entry_priv->popup_menu, GTK_STOCK_CUT, "cut-clipboard",
8738 info_entry_priv->editable && mode == DISPLAY_NORMAL &&
8739 info_entry_priv->current_pos != info_entry_priv->selection_bound);
8741 append_action_signal (entry, info_entry_priv->popup_menu, GTK_STOCK_COPY, "copy-clipboard",
8742 mode == DISPLAY_NORMAL &&
8743 info_entry_priv->current_pos != info_entry_priv->selection_bound);
8745 append_action_signal (entry, info_entry_priv->popup_menu, GTK_STOCK_PASTE, "paste-clipboard",
8746 info_entry_priv->editable && clipboard_contains_text);
8748 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_DELETE, NULL);
8749 gtk_widget_set_sensitive (menuitem, info_entry_priv->editable && info_entry_priv->current_pos != info_entry_priv->selection_bound);
8750 g_signal_connect_swapped (menuitem, "activate",
8751 G_CALLBACK (gtk_entry_delete_cb), entry);
8752 gtk_widget_show (menuitem);
8753 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8755 menuitem = gtk_separator_menu_item_new ();
8756 gtk_widget_show (menuitem);
8757 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8759 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_SELECT_ALL, NULL);
8760 gtk_widget_set_sensitive (menuitem, gtk_entry_buffer_get_length (info_entry_priv->buffer) > 0);
8761 g_signal_connect_swapped (menuitem, "activate",
8762 G_CALLBACK (gtk_entry_select_all), entry);
8763 gtk_widget_show (menuitem);
8764 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8766 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
8767 "gtk-show-input-method-menu", &show_input_method_menu,
8768 "gtk-show-unicode-menu", &show_unicode_menu,
8771 if (show_input_method_menu || show_unicode_menu)
8773 menuitem = gtk_separator_menu_item_new ();
8774 gtk_widget_show (menuitem);
8775 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8778 if (show_input_method_menu)
8780 menuitem = gtk_menu_item_new_with_mnemonic (_("Input _Methods"));
8781 gtk_widget_set_sensitive (menuitem, info_entry_priv->editable);
8782 gtk_widget_show (menuitem);
8783 submenu = gtk_menu_new ();
8784 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
8786 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8788 gtk_im_multicontext_append_menuitems (GTK_IM_MULTICONTEXT (info_entry_priv->im_context),
8789 GTK_MENU_SHELL (submenu));
8792 if (show_unicode_menu)
8794 menuitem = gtk_menu_item_new_with_mnemonic (_("_Insert Unicode Control Character"));
8795 gtk_widget_set_sensitive (menuitem, info_entry_priv->editable);
8796 gtk_widget_show (menuitem);
8798 submenu = gtk_menu_new ();
8799 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
8800 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8802 _gtk_text_util_append_special_char_menuitems (GTK_MENU_SHELL (submenu),
8803 unichar_chosen_func,
8807 g_signal_emit (entry,
8808 signals[POPULATE_POPUP],
8810 info_entry_priv->popup_menu);
8814 gtk_menu_popup_for_device (GTK_MENU (info_entry_priv->popup_menu),
8815 info->device, NULL, NULL, NULL, NULL, NULL,
8816 info->button, info->time);
8819 gtk_menu_popup (GTK_MENU (info_entry_priv->popup_menu), NULL, NULL,
8820 popup_position_func, entry,
8821 0, gtk_get_current_event_time ());
8822 gtk_menu_shell_select_first (GTK_MENU_SHELL (info_entry_priv->popup_menu), FALSE);
8826 g_object_unref (entry);
8827 g_slice_free (PopupInfo, info);
8831 gtk_entry_do_popup (GtkEntry *entry,
8832 GdkEventButton *event)
8834 PopupInfo *info = g_slice_new (PopupInfo);
8836 /* In order to know what entries we should make sensitive, we
8837 * ask for the current targets of the clipboard, and when
8838 * we get them, then we actually pop up the menu.
8840 info->entry = g_object_ref (entry);
8844 info->button = event->button;
8845 info->time = event->time;
8846 info->device = event->device;
8851 info->time = gtk_get_current_event_time ();
8852 info->device = NULL;
8855 gtk_clipboard_request_contents (gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_CLIPBOARD),
8856 gdk_atom_intern_static_string ("TARGETS"),
8857 popup_targets_received,
8862 gtk_entry_popup_menu (GtkWidget *widget)
8864 gtk_entry_do_popup (GTK_ENTRY (widget), NULL);
8869 gtk_entry_drag_begin (GtkWidget *widget,
8870 GdkDragContext *context)
8872 GtkEntry *entry = GTK_ENTRY (widget);
8873 GtkEntryPrivate *priv = entry->priv;
8876 for (i = 0; i < MAX_ICONS; i++)
8878 EntryIconInfo *icon_info = priv->icons[i];
8880 if (icon_info != NULL)
8882 if (icon_info->in_drag)
8886 pix = _gtk_icon_helper_ensure_pixbuf
8887 (icon_info->icon_helper,
8888 gtk_widget_get_style_context (GTK_WIDGET (entry)));
8889 gtk_drag_set_icon_pixbuf (context, pix, -2, -2);
8891 g_object_unref (pix);
8898 gtk_entry_drag_end (GtkWidget *widget,
8899 GdkDragContext *context)
8901 GtkEntry *entry = GTK_ENTRY (widget);
8902 GtkEntryPrivate *priv = entry->priv;
8905 for (i = 0; i < MAX_ICONS; i++)
8907 EntryIconInfo *icon_info = priv->icons[i];
8909 if (icon_info != NULL)
8910 icon_info->in_drag = 0;
8915 gtk_entry_drag_leave (GtkWidget *widget,
8916 GdkDragContext *context,
8919 GtkEntry *entry = GTK_ENTRY (widget);
8920 GtkEntryPrivate *priv = entry->priv;
8922 priv->dnd_position = -1;
8923 gtk_widget_queue_draw (widget);
8927 gtk_entry_drag_drop (GtkWidget *widget,
8928 GdkDragContext *context,
8933 GtkEntry *entry = GTK_ENTRY (widget);
8934 GtkEntryPrivate *priv = entry->priv;
8935 GdkAtom target = GDK_NONE;
8938 target = gtk_drag_dest_find_target (widget, context, NULL);
8940 if (target != GDK_NONE)
8941 gtk_drag_get_data (widget, context, target, time);
8943 gtk_drag_finish (context, FALSE, FALSE, time);
8949 gtk_entry_drag_motion (GtkWidget *widget,
8950 GdkDragContext *context,
8955 GtkEntry *entry = GTK_ENTRY (widget);
8956 GtkEntryPrivate *priv = entry->priv;
8957 GtkStyleContext *style_context;
8958 GtkWidget *source_widget;
8959 GdkDragAction suggested_action;
8960 gint new_position, old_position;
8964 style_context = gtk_widget_get_style_context (widget);
8965 gtk_style_context_get_padding (style_context, 0, &padding);
8969 old_position = priv->dnd_position;
8970 new_position = gtk_entry_find_position (entry, x + priv->scroll_offset);
8972 if (priv->editable &&
8973 gtk_drag_dest_find_target (widget, context, NULL) != GDK_NONE)
8975 source_widget = gtk_drag_get_source_widget (context);
8976 suggested_action = gdk_drag_context_get_suggested_action (context);
8978 if (!gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &sel1, &sel2) ||
8979 new_position < sel1 || new_position > sel2)
8981 if (source_widget == widget)
8983 /* Default to MOVE, unless the user has
8984 * pressed ctrl or alt to affect available actions
8986 if ((gdk_drag_context_get_actions (context) & GDK_ACTION_MOVE) != 0)
8987 suggested_action = GDK_ACTION_MOVE;
8990 priv->dnd_position = new_position;
8994 if (source_widget == widget)
8995 suggested_action = 0; /* Can't drop in selection where drag started */
8997 priv->dnd_position = -1;
9002 /* Entry not editable, or no text */
9003 suggested_action = 0;
9004 priv->dnd_position = -1;
9007 gdk_drag_status (context, suggested_action, time);
9009 if (priv->dnd_position != old_position)
9010 gtk_widget_queue_draw (widget);
9016 gtk_entry_drag_data_received (GtkWidget *widget,
9017 GdkDragContext *context,
9020 GtkSelectionData *selection_data,
9024 GtkEntry *entry = GTK_ENTRY (widget);
9025 GtkEntryPrivate *priv = entry->priv;
9026 GtkEditable *editable = GTK_EDITABLE (widget);
9027 GtkStyleContext *style_context;
9031 str = (gchar *) gtk_selection_data_get_text (selection_data);
9033 style_context = gtk_widget_get_style_context (widget);
9034 gtk_style_context_get_padding (style_context, 0, &padding);
9038 if (str && priv->editable)
9044 if (priv->truncate_multiline)
9045 length = truncate_multiline (str);
9047 new_position = gtk_entry_find_position (entry, x + priv->scroll_offset);
9049 if (!gtk_editable_get_selection_bounds (editable, &sel1, &sel2) ||
9050 new_position < sel1 || new_position > sel2)
9052 gtk_editable_insert_text (editable, str, length, &new_position);
9056 /* Replacing selection */
9057 begin_change (entry);
9058 gtk_editable_delete_text (editable, sel1, sel2);
9059 gtk_editable_insert_text (editable, str, length, &sel1);
9063 gtk_drag_finish (context, TRUE, gdk_drag_context_get_selected_action (context) == GDK_ACTION_MOVE, time);
9067 /* Drag and drop didn't happen! */
9068 gtk_drag_finish (context, FALSE, FALSE, time);
9075 gtk_entry_drag_data_get (GtkWidget *widget,
9076 GdkDragContext *context,
9077 GtkSelectionData *selection_data,
9081 GtkEntry *entry = GTK_ENTRY (widget);
9082 GtkEntryPrivate *priv = entry->priv;
9083 GtkEditable *editable = GTK_EDITABLE (widget);
9084 gint sel_start, sel_end;
9087 /* If there is an icon drag going on, exit early. */
9088 for (i = 0; i < MAX_ICONS; i++)
9090 EntryIconInfo *icon_info = priv->icons[i];
9092 if (icon_info != NULL)
9094 if (icon_info->in_drag)
9099 if (gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end))
9101 gchar *str = gtk_entry_get_display_text (GTK_ENTRY (widget), sel_start, sel_end);
9103 gtk_selection_data_set_text (selection_data, str, -1);
9111 gtk_entry_drag_data_delete (GtkWidget *widget,
9112 GdkDragContext *context)
9114 GtkEntry *entry = GTK_ENTRY (widget);
9115 GtkEntryPrivate *priv = entry->priv;
9116 GtkEditable *editable = GTK_EDITABLE (widget);
9117 gint sel_start, sel_end;
9120 /* If there is an icon drag going on, exit early. */
9121 for (i = 0; i < MAX_ICONS; i++)
9123 EntryIconInfo *icon_info = priv->icons[i];
9125 if (icon_info != NULL)
9127 if (icon_info->in_drag)
9132 if (priv->editable &&
9133 gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end))
9134 gtk_editable_delete_text (editable, sel_start, sel_end);
9137 /* We display the cursor when
9139 * - the selection is empty, AND
9140 * - the widget has focus
9143 #define CURSOR_ON_MULTIPLIER 2
9144 #define CURSOR_OFF_MULTIPLIER 1
9145 #define CURSOR_PEND_MULTIPLIER 3
9146 #define CURSOR_DIVIDER 3
9149 cursor_blinks (GtkEntry *entry)
9151 GtkEntryPrivate *priv = entry->priv;
9153 if (gtk_widget_has_focus (GTK_WIDGET (entry)) &&
9155 priv->selection_bound == priv->current_pos)
9157 GtkSettings *settings;
9160 settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9161 g_object_get (settings, "gtk-cursor-blink", &blink, NULL);
9170 get_middle_click_paste (GtkEntry *entry)
9172 GtkSettings *settings;
9175 settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9176 g_object_get (settings, "gtk-enable-primary-paste", &paste, NULL);
9182 get_cursor_time (GtkEntry *entry)
9184 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9187 g_object_get (settings, "gtk-cursor-blink-time", &time, NULL);
9193 get_cursor_blink_timeout (GtkEntry *entry)
9195 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9198 g_object_get (settings, "gtk-cursor-blink-timeout", &timeout, NULL);
9204 show_cursor (GtkEntry *entry)
9206 GtkEntryPrivate *priv = entry->priv;
9209 if (!priv->cursor_visible)
9211 priv->cursor_visible = TRUE;
9213 widget = GTK_WIDGET (entry);
9214 if (gtk_widget_has_focus (widget) && priv->selection_bound == priv->current_pos)
9215 gtk_widget_queue_draw (widget);
9220 hide_cursor (GtkEntry *entry)
9222 GtkEntryPrivate *priv = entry->priv;
9225 if (priv->cursor_visible)
9227 priv->cursor_visible = FALSE;
9229 widget = GTK_WIDGET (entry);
9230 if (gtk_widget_has_focus (widget) && priv->selection_bound == priv->current_pos)
9231 gtk_widget_queue_draw (widget);
9239 blink_cb (gpointer data)
9242 GtkEntryPrivate *priv;
9245 entry = GTK_ENTRY (data);
9248 if (!gtk_widget_has_focus (GTK_WIDGET (entry)))
9250 g_warning ("GtkEntry - did not receive focus-out-event. If you\n"
9251 "connect a handler to this signal, it must return\n"
9252 "FALSE so the entry gets the event as well");
9254 gtk_entry_check_cursor_blink (entry);
9259 g_assert (priv->selection_bound == priv->current_pos);
9261 blink_timeout = get_cursor_blink_timeout (entry);
9262 if (priv->blink_time > 1000 * blink_timeout &&
9263 blink_timeout < G_MAXINT/1000)
9265 /* we've blinked enough without the user doing anything, stop blinking */
9266 show_cursor (entry);
9267 priv->blink_timeout = 0;
9269 else if (priv->cursor_visible)
9271 hide_cursor (entry);
9272 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_OFF_MULTIPLIER / CURSOR_DIVIDER,
9278 show_cursor (entry);
9279 priv->blink_time += get_cursor_time (entry);
9280 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
9285 /* Remove ourselves */
9290 gtk_entry_check_cursor_blink (GtkEntry *entry)
9292 GtkEntryPrivate *priv = entry->priv;
9294 if (cursor_blinks (entry))
9296 if (!priv->blink_timeout)
9298 show_cursor (entry);
9299 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
9306 if (priv->blink_timeout)
9308 g_source_remove (priv->blink_timeout);
9309 priv->blink_timeout = 0;
9312 priv->cursor_visible = TRUE;
9317 gtk_entry_pend_cursor_blink (GtkEntry *entry)
9319 GtkEntryPrivate *priv = entry->priv;
9321 if (cursor_blinks (entry))
9323 if (priv->blink_timeout != 0)
9324 g_source_remove (priv->blink_timeout);
9326 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_PEND_MULTIPLIER / CURSOR_DIVIDER,
9329 show_cursor (entry);
9334 gtk_entry_reset_blink_time (GtkEntry *entry)
9336 GtkEntryPrivate *priv = entry->priv;
9338 priv->blink_time = 0;
9344 gtk_entry_completion_timeout (gpointer data)
9346 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (data);
9347 GtkEntryPrivate *completion_entry_priv = GTK_ENTRY (completion->priv->entry)->priv;
9349 completion->priv->completion_timeout = 0;
9351 if (completion->priv->filter_model &&
9352 g_utf8_strlen (gtk_entry_get_text (GTK_ENTRY (completion->priv->entry)), -1)
9353 >= completion->priv->minimum_key_length)
9357 GtkTreeSelection *s;
9358 gboolean popup_single;
9360 gtk_entry_completion_complete (completion);
9361 matches = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->filter_model), NULL);
9363 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9365 s = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view));
9367 gtk_tree_selection_unselect_all (s);
9369 actions = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->actions), NULL);
9371 g_object_get (completion, "popup-single-match", &popup_single, NULL);
9372 if ((matches > (popup_single ? 0: 1)) || actions > 0)
9374 if (gtk_widget_get_visible (completion->priv->popup_window))
9375 _gtk_entry_completion_resize_popup (completion);
9377 _gtk_entry_completion_popup (completion, completion_entry_priv->completion_device);
9380 _gtk_entry_completion_popdown (completion);
9382 else if (gtk_widget_get_visible (completion->priv->popup_window))
9383 _gtk_entry_completion_popdown (completion);
9388 static inline gboolean
9389 keyval_is_cursor_move (guint keyval)
9391 if (keyval == GDK_KEY_Up || keyval == GDK_KEY_KP_Up)
9394 if (keyval == GDK_KEY_Down || keyval == GDK_KEY_KP_Down)
9397 if (keyval == GDK_KEY_Page_Up)
9400 if (keyval == GDK_KEY_Page_Down)
9407 gtk_entry_completion_key_press (GtkWidget *widget,
9411 gint matches, actions = 0;
9412 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
9414 if (!gtk_widget_get_mapped (completion->priv->popup_window))
9417 matches = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->filter_model), NULL);
9419 if (completion->priv->actions)
9420 actions = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->actions), NULL);
9422 if (keyval_is_cursor_move (event->keyval))
9424 GtkTreePath *path = NULL;
9426 if (event->keyval == GDK_KEY_Up || event->keyval == GDK_KEY_KP_Up)
9428 if (completion->priv->current_selected < 0)
9429 completion->priv->current_selected = matches + actions - 1;
9431 completion->priv->current_selected--;
9433 else if (event->keyval == GDK_KEY_Down || event->keyval == GDK_KEY_KP_Down)
9435 if (completion->priv->current_selected < matches + actions - 1)
9436 completion->priv->current_selected++;
9438 completion->priv->current_selected = -1;
9440 else if (event->keyval == GDK_KEY_Page_Up)
9442 if (completion->priv->current_selected < 0)
9443 completion->priv->current_selected = matches + actions - 1;
9444 else if (completion->priv->current_selected == 0)
9445 completion->priv->current_selected = -1;
9446 else if (completion->priv->current_selected < matches)
9448 completion->priv->current_selected -= PAGE_STEP;
9449 if (completion->priv->current_selected < 0)
9450 completion->priv->current_selected = 0;
9454 completion->priv->current_selected -= PAGE_STEP;
9455 if (completion->priv->current_selected < matches - 1)
9456 completion->priv->current_selected = matches - 1;
9459 else if (event->keyval == GDK_KEY_Page_Down)
9461 if (completion->priv->current_selected < 0)
9462 completion->priv->current_selected = 0;
9463 else if (completion->priv->current_selected < matches - 1)
9465 completion->priv->current_selected += PAGE_STEP;
9466 if (completion->priv->current_selected > matches - 1)
9467 completion->priv->current_selected = matches - 1;
9469 else if (completion->priv->current_selected == matches + actions - 1)
9471 completion->priv->current_selected = -1;
9475 completion->priv->current_selected += PAGE_STEP;
9476 if (completion->priv->current_selected > matches + actions - 1)
9477 completion->priv->current_selected = matches + actions - 1;
9481 if (completion->priv->current_selected < 0)
9483 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9484 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view)));
9486 if (completion->priv->inline_selection &&
9487 completion->priv->completion_prefix)
9489 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9490 completion->priv->completion_prefix);
9491 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9494 else if (completion->priv->current_selected < matches)
9496 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view)));
9498 path = gtk_tree_path_new_from_indices (completion->priv->current_selected, -1);
9499 gtk_tree_view_set_cursor (GTK_TREE_VIEW (completion->priv->tree_view),
9502 if (completion->priv->inline_selection)
9506 GtkTreeIter child_iter;
9507 GtkTreeModel *model = NULL;
9508 GtkTreeSelection *sel;
9511 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view));
9512 if (!gtk_tree_selection_get_selected (sel, &model, &iter))
9515 gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (model), &child_iter, &iter);
9516 model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model));
9518 if (completion->priv->completion_prefix == NULL)
9519 completion->priv->completion_prefix = g_strdup (gtk_entry_get_text (GTK_ENTRY (completion->priv->entry)));
9521 g_signal_emit_by_name (completion, "cursor-on-match", model,
9522 &child_iter, &entry_set);
9525 else if (completion->priv->current_selected - matches >= 0)
9527 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9529 path = gtk_tree_path_new_from_indices (completion->priv->current_selected - matches, -1);
9530 gtk_tree_view_set_cursor (GTK_TREE_VIEW (completion->priv->action_view),
9533 if (completion->priv->inline_selection &&
9534 completion->priv->completion_prefix)
9536 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9537 completion->priv->completion_prefix);
9538 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9542 gtk_tree_path_free (path);
9546 else if (event->keyval == GDK_KEY_Escape ||
9547 event->keyval == GDK_KEY_Left ||
9548 event->keyval == GDK_KEY_KP_Left ||
9549 event->keyval == GDK_KEY_Right ||
9550 event->keyval == GDK_KEY_KP_Right)
9552 gboolean retval = TRUE;
9554 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9555 _gtk_entry_completion_popdown (completion);
9557 if (completion->priv->current_selected < 0)
9560 goto keypress_completion_out;
9562 else if (completion->priv->inline_selection)
9564 /* Escape rejects the tentative completion */
9565 if (event->keyval == GDK_KEY_Escape)
9567 if (completion->priv->completion_prefix)
9568 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9569 completion->priv->completion_prefix);
9571 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry), "");
9574 /* Move the cursor to the end for Right/Esc */
9575 if (event->keyval == GDK_KEY_Right ||
9576 event->keyval == GDK_KEY_KP_Right ||
9577 event->keyval == GDK_KEY_Escape)
9578 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9579 /* Let the default keybindings run for Left, i.e. either move to the
9580 * previous character or select word if a modifier is used */
9585 keypress_completion_out:
9586 if (completion->priv->inline_selection)
9588 g_free (completion->priv->completion_prefix);
9589 completion->priv->completion_prefix = NULL;
9594 else if (event->keyval == GDK_KEY_Tab ||
9595 event->keyval == GDK_KEY_KP_Tab ||
9596 event->keyval == GDK_KEY_ISO_Left_Tab)
9598 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9599 _gtk_entry_completion_popdown (completion);
9601 g_free (completion->priv->completion_prefix);
9602 completion->priv->completion_prefix = NULL;
9606 else if (event->keyval == GDK_KEY_ISO_Enter ||
9607 event->keyval == GDK_KEY_KP_Enter ||
9608 event->keyval == GDK_KEY_Return)
9611 GtkTreeModel *model = NULL;
9612 GtkTreeModel *child_model;
9613 GtkTreeIter child_iter;
9614 GtkTreeSelection *sel;
9615 gboolean retval = TRUE;
9617 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9618 _gtk_entry_completion_popdown (completion);
9620 if (completion->priv->current_selected < matches)
9624 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view));
9625 if (gtk_tree_selection_get_selected (sel, &model, &iter))
9627 gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (model), &child_iter, &iter);
9628 child_model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model));
9629 g_signal_handler_block (widget, completion->priv->changed_id);
9630 g_signal_emit_by_name (completion, "match-selected",
9631 child_model, &child_iter, &entry_set);
9632 g_signal_handler_unblock (widget, completion->priv->changed_id);
9638 gtk_tree_model_get (model, &iter,
9639 completion->priv->text_column, &str,
9642 gtk_entry_set_text (GTK_ENTRY (widget), str);
9644 /* move the cursor to the end */
9645 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9653 else if (completion->priv->current_selected - matches >= 0)
9655 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view));
9656 if (gtk_tree_selection_get_selected (sel, &model, &iter))
9660 path = gtk_tree_path_new_from_indices (completion->priv->current_selected - matches, -1);
9661 g_signal_emit_by_name (completion, "action-activated",
9662 gtk_tree_path_get_indices (path)[0]);
9663 gtk_tree_path_free (path);
9669 g_free (completion->priv->completion_prefix);
9670 completion->priv->completion_prefix = NULL;
9679 gtk_entry_completion_changed (GtkWidget *widget,
9682 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
9683 GtkEntry *entry = GTK_ENTRY (widget);
9684 GtkEntryPrivate *priv = entry->priv;
9687 /* (re)install completion timeout */
9688 if (completion->priv->completion_timeout)
9689 g_source_remove (completion->priv->completion_timeout);
9691 if (!gtk_entry_get_text (entry))
9694 /* no need to normalize for this test */
9695 if (completion->priv->minimum_key_length > 0 &&
9696 strcmp ("", gtk_entry_get_text (entry)) == 0)
9698 if (gtk_widget_get_visible (completion->priv->popup_window))
9699 _gtk_entry_completion_popdown (completion);
9703 device = gtk_get_current_event_device ();
9705 if (device && gdk_device_get_source (device) == GDK_SOURCE_KEYBOARD)
9706 device = gdk_device_get_associated_device (device);
9709 priv->completion_device = device;
9711 completion->priv->completion_timeout =
9712 gdk_threads_add_timeout (COMPLETION_TIMEOUT,
9713 gtk_entry_completion_timeout,
9718 check_completion_callback (GtkEntryCompletion *completion)
9720 completion->priv->check_completion_idle = NULL;
9722 gtk_entry_completion_complete (completion);
9723 gtk_entry_completion_insert_prefix (completion);
9729 clear_completion_callback (GtkEntry *entry,
9732 if (pspec->name == I_("cursor-position") ||
9733 pspec->name == I_("selection-bound"))
9735 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
9737 completion->priv->has_completion = FALSE;
9742 accept_completion_callback (GtkEntry *entry)
9744 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
9746 if (completion->priv->has_completion)
9747 gtk_editable_set_position (GTK_EDITABLE (entry),
9748 gtk_entry_buffer_get_length (get_buffer (entry)));
9754 completion_insert_text_callback (GtkEntry *entry,
9758 GtkEntryCompletion *completion)
9760 /* idle to update the selection based on the file list */
9761 if (completion->priv->check_completion_idle == NULL)
9763 completion->priv->check_completion_idle = g_idle_source_new ();
9764 g_source_set_priority (completion->priv->check_completion_idle, G_PRIORITY_HIGH);
9765 g_source_set_closure (completion->priv->check_completion_idle,
9766 g_cclosure_new_object (G_CALLBACK (check_completion_callback),
9767 G_OBJECT (completion)));
9768 g_source_attach (completion->priv->check_completion_idle, NULL);
9773 completion_changed (GtkEntryCompletion *completion,
9777 GtkEntry *entry = GTK_ENTRY (data);
9779 if (pspec->name == I_("popup-completion") ||
9780 pspec->name == I_("inline-completion"))
9782 disconnect_completion_signals (entry, completion);
9783 connect_completion_signals (entry, completion);
9788 disconnect_completion_signals (GtkEntry *entry,
9789 GtkEntryCompletion *completion)
9791 g_signal_handlers_disconnect_by_func (completion,
9792 G_CALLBACK (completion_changed), entry);
9793 if (completion->priv->changed_id > 0 &&
9794 g_signal_handler_is_connected (entry, completion->priv->changed_id))
9796 g_signal_handler_disconnect (entry, completion->priv->changed_id);
9797 completion->priv->changed_id = 0;
9799 g_signal_handlers_disconnect_by_func (entry,
9800 G_CALLBACK (gtk_entry_completion_key_press), completion);
9801 if (completion->priv->insert_text_id > 0 &&
9802 g_signal_handler_is_connected (entry, completion->priv->insert_text_id))
9804 g_signal_handler_disconnect (entry, completion->priv->insert_text_id);
9805 completion->priv->insert_text_id = 0;
9807 g_signal_handlers_disconnect_by_func (entry,
9808 G_CALLBACK (completion_insert_text_callback), completion);
9809 g_signal_handlers_disconnect_by_func (entry,
9810 G_CALLBACK (clear_completion_callback), completion);
9811 g_signal_handlers_disconnect_by_func (entry,
9812 G_CALLBACK (accept_completion_callback), completion);
9816 connect_completion_signals (GtkEntry *entry,
9817 GtkEntryCompletion *completion)
9819 if (completion->priv->popup_completion)
9821 completion->priv->changed_id =
9822 g_signal_connect (entry, "changed",
9823 G_CALLBACK (gtk_entry_completion_changed), completion);
9824 g_signal_connect (entry, "key-press-event",
9825 G_CALLBACK (gtk_entry_completion_key_press), completion);
9828 if (completion->priv->inline_completion)
9830 completion->priv->insert_text_id =
9831 g_signal_connect (entry, "insert-text",
9832 G_CALLBACK (completion_insert_text_callback), completion);
9833 g_signal_connect (entry, "notify",
9834 G_CALLBACK (clear_completion_callback), completion);
9835 g_signal_connect (entry, "activate",
9836 G_CALLBACK (accept_completion_callback), completion);
9837 g_signal_connect (entry, "focus-out-event",
9838 G_CALLBACK (accept_completion_callback), completion);
9841 g_signal_connect (completion, "notify",
9842 G_CALLBACK (completion_changed), entry);
9846 * gtk_entry_set_completion:
9847 * @entry: A #GtkEntry
9848 * @completion: (allow-none): The #GtkEntryCompletion or %NULL
9850 * Sets @completion to be the auxiliary completion object to use with @entry.
9851 * All further configuration of the completion mechanism is done on
9852 * @completion using the #GtkEntryCompletion API. Completion is disabled if
9853 * @completion is set to %NULL.
9858 gtk_entry_set_completion (GtkEntry *entry,
9859 GtkEntryCompletion *completion)
9861 GtkEntryCompletion *old;
9863 g_return_if_fail (GTK_IS_ENTRY (entry));
9864 g_return_if_fail (!completion || GTK_IS_ENTRY_COMPLETION (completion));
9866 old = gtk_entry_get_completion (entry);
9868 if (old == completion)
9873 if (old->priv->completion_timeout)
9875 g_source_remove (old->priv->completion_timeout);
9876 old->priv->completion_timeout = 0;
9879 if (old->priv->check_completion_idle)
9881 g_source_destroy (old->priv->check_completion_idle);
9882 old->priv->check_completion_idle = NULL;
9885 if (gtk_widget_get_mapped (old->priv->popup_window))
9886 _gtk_entry_completion_popdown (old);
9888 disconnect_completion_signals (entry, old);
9889 old->priv->entry = NULL;
9891 g_object_unref (old);
9896 g_object_set_data (G_OBJECT (entry), I_(GTK_ENTRY_COMPLETION_KEY), NULL);
9900 /* hook into the entry */
9901 g_object_ref (completion);
9903 connect_completion_signals (entry, completion);
9904 completion->priv->entry = GTK_WIDGET (entry);
9905 g_object_set_data (G_OBJECT (entry), I_(GTK_ENTRY_COMPLETION_KEY), completion);
9907 g_object_notify (G_OBJECT (entry), "completion");
9911 * gtk_entry_get_completion:
9912 * @entry: A #GtkEntry
9914 * Returns the auxiliary completion object currently in use by @entry.
9916 * Return value: (transfer none): The auxiliary completion object currently
9921 GtkEntryCompletion *
9922 gtk_entry_get_completion (GtkEntry *entry)
9924 GtkEntryCompletion *completion;
9926 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
9928 completion = GTK_ENTRY_COMPLETION (g_object_get_data (G_OBJECT (entry),
9929 GTK_ENTRY_COMPLETION_KEY));
9935 * gtk_entry_set_cursor_hadjustment:
9936 * @entry: a #GtkEntry
9937 * @adjustment: an adjustment which should be adjusted when the cursor
9938 * is moved, or %NULL
9940 * Hooks up an adjustment to the cursor position in an entry, so that when
9941 * the cursor is moved, the adjustment is scrolled to show that position.
9942 * See gtk_scrolled_window_get_hadjustment() for a typical way of obtaining
9945 * The adjustment has to be in pixel units and in the same coordinate system
9951 gtk_entry_set_cursor_hadjustment (GtkEntry *entry,
9952 GtkAdjustment *adjustment)
9954 g_return_if_fail (GTK_IS_ENTRY (entry));
9956 g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
9959 g_object_ref (adjustment);
9961 g_object_set_qdata_full (G_OBJECT (entry),
9962 quark_cursor_hadjustment,
9968 * gtk_entry_get_cursor_hadjustment:
9969 * @entry: a #GtkEntry
9971 * Retrieves the horizontal cursor adjustment for the entry.
9972 * See gtk_entry_set_cursor_hadjustment().
9974 * Return value: (transfer none): the horizontal cursor adjustment, or %NULL
9975 * if none has been set.
9980 gtk_entry_get_cursor_hadjustment (GtkEntry *entry)
9982 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
9984 return g_object_get_qdata (G_OBJECT (entry), quark_cursor_hadjustment);
9988 * gtk_entry_set_progress_fraction:
9989 * @entry: a #GtkEntry
9990 * @fraction: fraction of the task that's been completed
9992 * Causes the entry's progress indicator to "fill in" the given
9993 * fraction of the bar. The fraction should be between 0.0 and 1.0,
9999 gtk_entry_set_progress_fraction (GtkEntry *entry,
10003 GtkEntryPrivate *private;
10004 gdouble old_fraction;
10005 gint x, y, width, height;
10006 gint old_x, old_y, old_width, old_height;
10008 g_return_if_fail (GTK_IS_ENTRY (entry));
10010 widget = GTK_WIDGET (entry);
10011 private = entry->priv;
10013 if (private->progress_pulse_mode)
10016 old_fraction = private->progress_fraction;
10018 if (gtk_widget_is_drawable (widget))
10019 get_progress_area (widget, &old_x, &old_y, &old_width, &old_height);
10021 fraction = CLAMP (fraction, 0.0, 1.0);
10023 private->progress_fraction = fraction;
10024 private->progress_pulse_mode = FALSE;
10025 private->progress_pulse_current = 0.0;
10027 if (gtk_widget_is_drawable (widget))
10029 get_progress_area (widget, &x, &y, &width, &height);
10031 if ((x != old_x) || (y != old_y) || (width != old_width) || (height != old_height))
10032 gtk_widget_queue_draw (widget);
10035 if (fraction != old_fraction)
10036 g_object_notify (G_OBJECT (entry), "progress-fraction");
10040 * gtk_entry_get_progress_fraction:
10041 * @entry: a #GtkEntry
10043 * Returns the current fraction of the task that's been completed.
10044 * See gtk_entry_set_progress_fraction().
10046 * Return value: a fraction from 0.0 to 1.0
10051 gtk_entry_get_progress_fraction (GtkEntry *entry)
10053 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
10055 return entry->priv->progress_fraction;
10059 * gtk_entry_set_progress_pulse_step:
10060 * @entry: a #GtkEntry
10061 * @fraction: fraction between 0.0 and 1.0
10063 * Sets the fraction of total entry width to move the progress
10064 * bouncing block for each call to gtk_entry_progress_pulse().
10069 gtk_entry_set_progress_pulse_step (GtkEntry *entry,
10072 GtkEntryPrivate *private;
10074 g_return_if_fail (GTK_IS_ENTRY (entry));
10076 private = entry->priv;
10078 fraction = CLAMP (fraction, 0.0, 1.0);
10080 if (fraction != private->progress_pulse_fraction)
10082 private->progress_pulse_fraction = fraction;
10084 gtk_widget_queue_draw (GTK_WIDGET (entry));
10086 g_object_notify (G_OBJECT (entry), "progress-pulse-step");
10091 * gtk_entry_get_progress_pulse_step:
10092 * @entry: a #GtkEntry
10094 * Retrieves the pulse step set with gtk_entry_set_progress_pulse_step().
10096 * Return value: a fraction from 0.0 to 1.0
10101 gtk_entry_get_progress_pulse_step (GtkEntry *entry)
10103 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
10105 return entry->priv->progress_pulse_fraction;
10109 * gtk_entry_progress_pulse:
10110 * @entry: a #GtkEntry
10112 * Indicates that some progress is made, but you don't know how much.
10113 * Causes the entry's progress indicator to enter "activity mode,"
10114 * where a block bounces back and forth. Each call to
10115 * gtk_entry_progress_pulse() causes the block to move by a little bit
10116 * (the amount of movement per pulse is determined by
10117 * gtk_entry_set_progress_pulse_step()).
10122 gtk_entry_progress_pulse (GtkEntry *entry)
10124 GtkEntryPrivate *private;
10126 g_return_if_fail (GTK_IS_ENTRY (entry));
10128 private = entry->priv;
10130 if (private->progress_pulse_mode)
10132 if (private->progress_pulse_way_back)
10134 private->progress_pulse_current -= private->progress_pulse_fraction;
10136 if (private->progress_pulse_current < 0.0)
10138 private->progress_pulse_current = 0.0;
10139 private->progress_pulse_way_back = FALSE;
10144 private->progress_pulse_current += private->progress_pulse_fraction;
10146 if (private->progress_pulse_current > 1.0 - private->progress_pulse_fraction)
10148 private->progress_pulse_current = 1.0 - private->progress_pulse_fraction;
10149 private->progress_pulse_way_back = TRUE;
10155 private->progress_fraction = 0.0;
10156 private->progress_pulse_mode = TRUE;
10157 private->progress_pulse_way_back = FALSE;
10158 private->progress_pulse_current = 0.0;
10161 gtk_widget_queue_draw (GTK_WIDGET (entry));
10165 * gtk_entry_set_placeholder_text:
10166 * @entry: a #GtkEntry
10167 * @text: a string to be displayed when @entry is empty an unfocused, or %NULL
10169 * Sets text to be displayed in @entry when it is empty and unfocused.
10170 * This can be used to give a visual hint of the expected contents of
10173 * Note that since the placeholder text gets removed when the entry
10174 * received focus, using this feature is a bit problematic if the entry
10175 * is given the initial focus in a window. Sometimes this can be
10176 * worked around by delaying the initial focus setting until the
10177 * first key event arrives.
10182 gtk_entry_set_placeholder_text (GtkEntry *entry,
10185 GtkEntryPrivate *priv;
10187 g_return_if_fail (GTK_IS_ENTRY (entry));
10189 priv = entry->priv;
10191 if (g_strcmp0 (priv->placeholder_text, text) == 0)
10194 g_free (priv->placeholder_text);
10195 priv->placeholder_text = g_strdup (text);
10197 gtk_entry_recompute (entry);
10199 g_object_notify (G_OBJECT (entry), "placeholder-text");
10203 * gtk_entry_get_placeholder_text:
10204 * @entry: a #GtkEntry
10206 * Retrieves the text that will be displayed when @entry is empty and unfocused
10208 * Returns: a pointer to the placeholder text as a string. This string points to internally allocated
10209 * storage in the widget and must not be freed, modified or stored.
10214 gtk_entry_get_placeholder_text (GtkEntry *entry)
10216 GtkEntryPrivate *priv;
10218 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
10220 priv = entry->priv;
10222 return priv->placeholder_text;
10225 /* Caps Lock warning for password entries */
10228 show_capslock_feedback (GtkEntry *entry,
10231 GtkEntryPrivate *priv = entry->priv;
10233 if (gtk_entry_get_icon_storage_type (entry, GTK_ENTRY_ICON_SECONDARY) == GTK_IMAGE_EMPTY)
10235 gtk_entry_set_icon_from_stock (entry, GTK_ENTRY_ICON_SECONDARY, GTK_STOCK_CAPS_LOCK_WARNING);
10236 gtk_entry_set_icon_activatable (entry, GTK_ENTRY_ICON_SECONDARY, FALSE);
10237 priv->caps_lock_warning_shown = TRUE;
10240 if (priv->caps_lock_warning_shown)
10241 gtk_entry_set_icon_tooltip_text (entry, GTK_ENTRY_ICON_SECONDARY, text);
10243 g_warning ("Can't show Caps Lock warning, since secondary icon is set");
10247 remove_capslock_feedback (GtkEntry *entry)
10249 GtkEntryPrivate *priv = entry->priv;
10251 if (priv->caps_lock_warning_shown)
10253 gtk_entry_set_icon_from_stock (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
10254 priv->caps_lock_warning_shown = FALSE;
10259 keymap_state_changed (GdkKeymap *keymap,
10262 GtkEntryPrivate *priv = entry->priv;
10265 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL && priv->caps_lock_warning)
10267 if (gdk_keymap_get_caps_lock_state (keymap))
10268 text = _("Caps Lock is on");
10272 show_capslock_feedback (entry, text);
10274 remove_capslock_feedback (entry);
10278 * _gtk_entry_set_is_cell_renderer:
10279 * @entry: a #GtkEntry
10280 * @is_cell_renderer: new value
10282 * This is a helper function for GtkComboBox. A GtkEntry in a GtkComboBox
10283 * is supposed to behave like a GtkCellEditable when placed in a combo box.
10285 * I.e take up its allocation and get GtkEntry->is_cell_renderer = TRUE.
10289 _gtk_entry_set_is_cell_renderer (GtkEntry *entry,
10290 gboolean is_cell_renderer)
10292 entry->priv->is_cell_renderer = is_cell_renderer;