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 the user hits
1447 * While this signal is used as a <link linkend="keybinding-signals">keybinding signal</link>,
1448 * it is also commonly used by applications to intercept
1449 * activation of entries.
1451 * The default bindings for this signal are all forms of the Enter key.
1454 g_signal_new (I_("activate"),
1455 G_OBJECT_CLASS_TYPE (gobject_class),
1456 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1457 G_STRUCT_OFFSET (GtkEntryClass, activate),
1459 _gtk_marshal_VOID__VOID,
1461 widget_class->activate_signal = signals[ACTIVATE];
1464 * GtkEntry::move-cursor:
1465 * @entry: the object which received the signal
1466 * @step: the granularity of the move, as a #GtkMovementStep
1467 * @count: the number of @step units to move
1468 * @extend_selection: %TRUE if the move should extend the selection
1470 * The ::move-cursor signal is a
1471 * <link linkend="keybinding-signals">keybinding signal</link>
1472 * which gets emitted when the user initiates a cursor movement.
1473 * If the cursor is not visible in @entry, this signal causes
1474 * the viewport to be moved instead.
1476 * Applications should not connect to it, but may emit it with
1477 * g_signal_emit_by_name() if they need to control the cursor
1480 * The default bindings for this signal come in two variants,
1481 * the variant with the Shift modifier extends the selection,
1482 * the variant without the Shift modifer does not.
1483 * There are too many key combinations to list them all here.
1485 * <listitem>Arrow keys move by individual characters/lines</listitem>
1486 * <listitem>Ctrl-arrow key combinations move by words/paragraphs</listitem>
1487 * <listitem>Home/End keys move to the ends of the buffer</listitem>
1490 signals[MOVE_CURSOR] =
1491 g_signal_new (I_("move-cursor"),
1492 G_OBJECT_CLASS_TYPE (gobject_class),
1493 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1494 G_STRUCT_OFFSET (GtkEntryClass, move_cursor),
1496 _gtk_marshal_VOID__ENUM_INT_BOOLEAN,
1498 GTK_TYPE_MOVEMENT_STEP,
1503 * GtkEntry::insert-at-cursor:
1504 * @entry: the object which received the signal
1505 * @string: the string to insert
1507 * The ::insert-at-cursor signal is a
1508 * <link linkend="keybinding-signals">keybinding signal</link>
1509 * which gets emitted when the user initiates the insertion of a
1510 * fixed string at the cursor.
1512 * This signal has no default bindings.
1514 signals[INSERT_AT_CURSOR] =
1515 g_signal_new (I_("insert-at-cursor"),
1516 G_OBJECT_CLASS_TYPE (gobject_class),
1517 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1518 G_STRUCT_OFFSET (GtkEntryClass, insert_at_cursor),
1520 _gtk_marshal_VOID__STRING,
1525 * GtkEntry::delete-from-cursor:
1526 * @entry: the object which received the signal
1527 * @type: the granularity of the deletion, as a #GtkDeleteType
1528 * @count: the number of @type units to delete
1530 * The ::delete-from-cursor signal is a
1531 * <link linkend="keybinding-signals">keybinding signal</link>
1532 * which gets emitted when the user initiates a text deletion.
1534 * If the @type is %GTK_DELETE_CHARS, GTK+ deletes the selection
1535 * if there is one, otherwise it deletes the requested number
1538 * The default bindings for this signal are
1539 * Delete for deleting a character and Ctrl-Delete for
1542 signals[DELETE_FROM_CURSOR] =
1543 g_signal_new (I_("delete-from-cursor"),
1544 G_OBJECT_CLASS_TYPE (gobject_class),
1545 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1546 G_STRUCT_OFFSET (GtkEntryClass, delete_from_cursor),
1548 _gtk_marshal_VOID__ENUM_INT,
1550 GTK_TYPE_DELETE_TYPE,
1554 * GtkEntry::backspace:
1555 * @entry: the object which received the signal
1557 * The ::backspace signal is a
1558 * <link linkend="keybinding-signals">keybinding signal</link>
1559 * which gets emitted when the user asks for it.
1561 * The default bindings for this signal are
1562 * Backspace and Shift-Backspace.
1564 signals[BACKSPACE] =
1565 g_signal_new (I_("backspace"),
1566 G_OBJECT_CLASS_TYPE (gobject_class),
1567 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1568 G_STRUCT_OFFSET (GtkEntryClass, backspace),
1570 _gtk_marshal_VOID__VOID,
1574 * GtkEntry::cut-clipboard:
1575 * @entry: the object which received the signal
1577 * The ::cut-clipboard signal is a
1578 * <link linkend="keybinding-signals">keybinding signal</link>
1579 * which gets emitted to cut the selection to the clipboard.
1581 * The default bindings for this signal are
1582 * Ctrl-x and Shift-Delete.
1584 signals[CUT_CLIPBOARD] =
1585 g_signal_new (I_("cut-clipboard"),
1586 G_OBJECT_CLASS_TYPE (gobject_class),
1587 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1588 G_STRUCT_OFFSET (GtkEntryClass, cut_clipboard),
1590 _gtk_marshal_VOID__VOID,
1594 * GtkEntry::copy-clipboard:
1595 * @entry: the object which received the signal
1597 * The ::copy-clipboard signal is a
1598 * <link linkend="keybinding-signals">keybinding signal</link>
1599 * which gets emitted to copy the selection to the clipboard.
1601 * The default bindings for this signal are
1602 * Ctrl-c and Ctrl-Insert.
1604 signals[COPY_CLIPBOARD] =
1605 g_signal_new (I_("copy-clipboard"),
1606 G_OBJECT_CLASS_TYPE (gobject_class),
1607 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1608 G_STRUCT_OFFSET (GtkEntryClass, copy_clipboard),
1610 _gtk_marshal_VOID__VOID,
1614 * GtkEntry::paste-clipboard:
1615 * @entry: the object which received the signal
1617 * The ::paste-clipboard signal is a
1618 * <link linkend="keybinding-signals">keybinding signal</link>
1619 * which gets emitted to paste the contents of the clipboard
1620 * into the text view.
1622 * The default bindings for this signal are
1623 * Ctrl-v and Shift-Insert.
1625 signals[PASTE_CLIPBOARD] =
1626 g_signal_new (I_("paste-clipboard"),
1627 G_OBJECT_CLASS_TYPE (gobject_class),
1628 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1629 G_STRUCT_OFFSET (GtkEntryClass, paste_clipboard),
1631 _gtk_marshal_VOID__VOID,
1635 * GtkEntry::toggle-overwrite:
1636 * @entry: the object which received the signal
1638 * The ::toggle-overwrite signal is a
1639 * <link linkend="keybinding-signals">keybinding signal</link>
1640 * which gets emitted to toggle the overwrite mode of the entry.
1642 * The default bindings for this signal is Insert.
1644 signals[TOGGLE_OVERWRITE] =
1645 g_signal_new (I_("toggle-overwrite"),
1646 G_OBJECT_CLASS_TYPE (gobject_class),
1647 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1648 G_STRUCT_OFFSET (GtkEntryClass, toggle_overwrite),
1650 _gtk_marshal_VOID__VOID,
1654 * GtkEntry::icon-press:
1655 * @entry: The entry on which the signal is emitted
1656 * @icon_pos: The position of the clicked icon
1657 * @event: (type Gdk.EventButton): the button press event
1659 * The ::icon-press signal is emitted when an activatable icon
1664 signals[ICON_PRESS] =
1665 g_signal_new (I_("icon-press"),
1666 G_TYPE_FROM_CLASS (gobject_class),
1670 _gtk_marshal_VOID__ENUM_BOXED,
1672 GTK_TYPE_ENTRY_ICON_POSITION,
1673 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1676 * GtkEntry::icon-release:
1677 * @entry: The entry on which the signal is emitted
1678 * @icon_pos: The position of the clicked icon
1679 * @event: (type Gdk.EventButton): the button release event
1681 * The ::icon-release signal is emitted on the button release from a
1682 * mouse click over an activatable icon.
1686 signals[ICON_RELEASE] =
1687 g_signal_new (I_("icon-release"),
1688 G_TYPE_FROM_CLASS (gobject_class),
1692 _gtk_marshal_VOID__ENUM_BOXED,
1694 GTK_TYPE_ENTRY_ICON_POSITION,
1695 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1698 * GtkEntry::preedit-changed:
1699 * @entry: the object which received the signal
1700 * @preedit: the current preedit string
1702 * If an input method is used, the typed text will not immediately
1703 * be committed to the buffer. So if you are interested in the text,
1704 * connect to this signal.
1708 signals[PREEDIT_CHANGED] =
1709 g_signal_new_class_handler (I_("preedit-changed"),
1710 G_OBJECT_CLASS_TYPE (gobject_class),
1711 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1714 _gtk_marshal_VOID__STRING,
1723 binding_set = gtk_binding_set_by_class (class);
1725 /* Moving the insertion point */
1726 add_move_binding (binding_set, GDK_KEY_Right, 0,
1727 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1729 add_move_binding (binding_set, GDK_KEY_Left, 0,
1730 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1732 add_move_binding (binding_set, GDK_KEY_KP_Right, 0,
1733 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1735 add_move_binding (binding_set, GDK_KEY_KP_Left, 0,
1736 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1738 add_move_binding (binding_set, GDK_KEY_Right, GDK_CONTROL_MASK,
1739 GTK_MOVEMENT_WORDS, 1);
1741 add_move_binding (binding_set, GDK_KEY_Left, GDK_CONTROL_MASK,
1742 GTK_MOVEMENT_WORDS, -1);
1744 add_move_binding (binding_set, GDK_KEY_KP_Right, GDK_CONTROL_MASK,
1745 GTK_MOVEMENT_WORDS, 1);
1747 add_move_binding (binding_set, GDK_KEY_KP_Left, GDK_CONTROL_MASK,
1748 GTK_MOVEMENT_WORDS, -1);
1750 add_move_binding (binding_set, GDK_KEY_Home, 0,
1751 GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
1753 add_move_binding (binding_set, GDK_KEY_End, 0,
1754 GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
1756 add_move_binding (binding_set, GDK_KEY_KP_Home, 0,
1757 GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
1759 add_move_binding (binding_set, GDK_KEY_KP_End, 0,
1760 GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
1762 add_move_binding (binding_set, GDK_KEY_Home, GDK_CONTROL_MASK,
1763 GTK_MOVEMENT_BUFFER_ENDS, -1);
1765 add_move_binding (binding_set, GDK_KEY_End, GDK_CONTROL_MASK,
1766 GTK_MOVEMENT_BUFFER_ENDS, 1);
1768 add_move_binding (binding_set, GDK_KEY_KP_Home, GDK_CONTROL_MASK,
1769 GTK_MOVEMENT_BUFFER_ENDS, -1);
1771 add_move_binding (binding_set, GDK_KEY_KP_End, GDK_CONTROL_MASK,
1772 GTK_MOVEMENT_BUFFER_ENDS, 1);
1776 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK,
1778 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1780 G_TYPE_BOOLEAN, FALSE);
1781 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK,
1783 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1785 G_TYPE_BOOLEAN, TRUE);
1787 gtk_binding_entry_add_signal (binding_set, GDK_KEY_slash, GDK_CONTROL_MASK,
1789 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1791 G_TYPE_BOOLEAN, FALSE);
1792 gtk_binding_entry_add_signal (binding_set, GDK_KEY_slash, GDK_CONTROL_MASK,
1794 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1796 G_TYPE_BOOLEAN, TRUE);
1799 gtk_binding_entry_add_signal (binding_set, GDK_KEY_backslash, GDK_CONTROL_MASK,
1801 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_VISUAL_POSITIONS,
1803 G_TYPE_BOOLEAN, FALSE);
1804 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_SHIFT_MASK | GDK_CONTROL_MASK,
1806 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_VISUAL_POSITIONS,
1808 G_TYPE_BOOLEAN, FALSE);
1812 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Return, 0,
1814 gtk_binding_entry_add_signal (binding_set, GDK_KEY_ISO_Enter, 0,
1816 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Enter, 0,
1820 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, 0,
1821 "delete-from-cursor", 2,
1822 G_TYPE_ENUM, GTK_DELETE_CHARS,
1825 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Delete, 0,
1826 "delete-from-cursor", 2,
1827 G_TYPE_ENUM, GTK_DELETE_CHARS,
1830 gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, 0,
1833 /* Make this do the same as Backspace, to help with mis-typing */
1834 gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, GDK_SHIFT_MASK,
1837 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, GDK_CONTROL_MASK,
1838 "delete-from-cursor", 2,
1839 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1842 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Delete, GDK_CONTROL_MASK,
1843 "delete-from-cursor", 2,
1844 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1847 gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, GDK_CONTROL_MASK,
1848 "delete-from-cursor", 2,
1849 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1852 /* Cut/copy/paste */
1854 gtk_binding_entry_add_signal (binding_set, GDK_KEY_x, GDK_CONTROL_MASK,
1855 "cut-clipboard", 0);
1856 gtk_binding_entry_add_signal (binding_set, GDK_KEY_c, GDK_CONTROL_MASK,
1857 "copy-clipboard", 0);
1858 gtk_binding_entry_add_signal (binding_set, GDK_KEY_v, GDK_CONTROL_MASK,
1859 "paste-clipboard", 0);
1861 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, GDK_SHIFT_MASK,
1862 "cut-clipboard", 0);
1863 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, GDK_CONTROL_MASK,
1864 "copy-clipboard", 0);
1865 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, GDK_SHIFT_MASK,
1866 "paste-clipboard", 0);
1869 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, 0,
1870 "toggle-overwrite", 0);
1871 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Insert, 0,
1872 "toggle-overwrite", 0);
1875 * GtkEntry:inner-border:
1877 * Sets the text area's border between the text and the frame.
1881 * Deprecated: 3.4: Use the standard border and padding CSS properties
1882 * (through objects like #GtkStyleContext and #GtkCssProvider); the value
1883 * of this style property is ignored.
1885 gtk_widget_class_install_style_property (widget_class,
1886 g_param_spec_boxed ("inner-border",
1888 P_("Border between text and frame."),
1890 GTK_PARAM_READABLE |
1891 G_PARAM_DEPRECATED));
1893 g_type_class_add_private (gobject_class, sizeof (GtkEntryPrivate));
1895 gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_ENTRY_ACCESSIBLE);
1899 gtk_entry_editable_init (GtkEditableInterface *iface)
1901 iface->do_insert_text = gtk_entry_insert_text;
1902 iface->do_delete_text = gtk_entry_delete_text;
1903 iface->insert_text = gtk_entry_real_insert_text;
1904 iface->delete_text = gtk_entry_real_delete_text;
1905 iface->get_chars = gtk_entry_get_chars;
1906 iface->set_selection_bounds = gtk_entry_set_selection_bounds;
1907 iface->get_selection_bounds = gtk_entry_get_selection_bounds;
1908 iface->set_position = gtk_entry_real_set_position;
1909 iface->get_position = gtk_entry_get_position;
1913 gtk_entry_cell_editable_init (GtkCellEditableIface *iface)
1915 iface->start_editing = gtk_entry_start_editing;
1918 /* for deprecated properties */
1920 gtk_entry_do_set_inner_border (GtkEntry *entry,
1921 const GtkBorder *border)
1924 g_object_set_qdata_full (G_OBJECT (entry), quark_inner_border,
1925 gtk_border_copy (border),
1926 (GDestroyNotify) gtk_border_free);
1928 g_object_set_qdata (G_OBJECT (entry), quark_inner_border, NULL);
1930 g_object_notify (G_OBJECT (entry), "inner-border");
1933 static const GtkBorder *
1934 gtk_entry_do_get_inner_border (GtkEntry *entry)
1936 return g_object_get_qdata (G_OBJECT (entry), quark_inner_border);
1940 gtk_entry_set_property (GObject *object,
1942 const GValue *value,
1945 GtkEntry *entry = GTK_ENTRY (object);
1946 GtkEntryPrivate *priv = entry->priv;
1951 gtk_entry_set_buffer (entry, g_value_get_object (value));
1956 gboolean new_value = g_value_get_boolean (value);
1958 if (new_value != priv->editable)
1960 GtkWidget *widget = GTK_WIDGET (entry);
1964 _gtk_entry_reset_im_context (entry);
1965 if (gtk_widget_has_focus (widget))
1966 gtk_im_context_focus_out (priv->im_context);
1968 priv->preedit_length = 0;
1969 priv->preedit_cursor = 0;
1972 priv->editable = new_value;
1974 if (new_value && gtk_widget_has_focus (widget))
1975 gtk_im_context_focus_in (priv->im_context);
1977 gtk_widget_queue_draw (widget);
1982 case PROP_MAX_LENGTH:
1983 gtk_entry_set_max_length (entry, g_value_get_int (value));
1986 case PROP_VISIBILITY:
1987 gtk_entry_set_visibility (entry, g_value_get_boolean (value));
1990 case PROP_HAS_FRAME:
1991 gtk_entry_set_has_frame (entry, g_value_get_boolean (value));
1994 case PROP_INNER_BORDER:
1995 gtk_entry_do_set_inner_border (entry, g_value_get_boxed (value));
1998 case PROP_INVISIBLE_CHAR:
1999 gtk_entry_set_invisible_char (entry, g_value_get_uint (value));
2002 case PROP_ACTIVATES_DEFAULT:
2003 gtk_entry_set_activates_default (entry, g_value_get_boolean (value));
2006 case PROP_WIDTH_CHARS:
2007 gtk_entry_set_width_chars (entry, g_value_get_int (value));
2011 gtk_entry_set_text (entry, g_value_get_string (value));
2015 gtk_entry_set_alignment (entry, g_value_get_float (value));
2018 case PROP_TRUNCATE_MULTILINE:
2019 priv->truncate_multiline = g_value_get_boolean (value);
2022 case PROP_SHADOW_TYPE:
2023 priv->shadow_type = g_value_get_enum (value);
2026 case PROP_OVERWRITE_MODE:
2027 gtk_entry_set_overwrite_mode (entry, g_value_get_boolean (value));
2030 case PROP_INVISIBLE_CHAR_SET:
2031 if (g_value_get_boolean (value))
2032 priv->invisible_char_set = TRUE;
2034 gtk_entry_unset_invisible_char (entry);
2037 case PROP_CAPS_LOCK_WARNING:
2038 priv->caps_lock_warning = g_value_get_boolean (value);
2041 case PROP_PROGRESS_FRACTION:
2042 gtk_entry_set_progress_fraction (entry, g_value_get_double (value));
2045 case PROP_PROGRESS_PULSE_STEP:
2046 gtk_entry_set_progress_pulse_step (entry, g_value_get_double (value));
2049 case PROP_PLACEHOLDER_TEXT:
2050 gtk_entry_set_placeholder_text (entry, g_value_get_string (value));
2053 case PROP_PIXBUF_PRIMARY:
2054 gtk_entry_set_icon_from_pixbuf (entry,
2055 GTK_ENTRY_ICON_PRIMARY,
2056 g_value_get_object (value));
2059 case PROP_PIXBUF_SECONDARY:
2060 gtk_entry_set_icon_from_pixbuf (entry,
2061 GTK_ENTRY_ICON_SECONDARY,
2062 g_value_get_object (value));
2065 case PROP_STOCK_PRIMARY:
2066 gtk_entry_set_icon_from_stock (entry,
2067 GTK_ENTRY_ICON_PRIMARY,
2068 g_value_get_string (value));
2071 case PROP_STOCK_SECONDARY:
2072 gtk_entry_set_icon_from_stock (entry,
2073 GTK_ENTRY_ICON_SECONDARY,
2074 g_value_get_string (value));
2077 case PROP_ICON_NAME_PRIMARY:
2078 gtk_entry_set_icon_from_icon_name (entry,
2079 GTK_ENTRY_ICON_PRIMARY,
2080 g_value_get_string (value));
2083 case PROP_ICON_NAME_SECONDARY:
2084 gtk_entry_set_icon_from_icon_name (entry,
2085 GTK_ENTRY_ICON_SECONDARY,
2086 g_value_get_string (value));
2089 case PROP_GICON_PRIMARY:
2090 gtk_entry_set_icon_from_gicon (entry,
2091 GTK_ENTRY_ICON_PRIMARY,
2092 g_value_get_object (value));
2095 case PROP_GICON_SECONDARY:
2096 gtk_entry_set_icon_from_gicon (entry,
2097 GTK_ENTRY_ICON_SECONDARY,
2098 g_value_get_object (value));
2101 case PROP_ACTIVATABLE_PRIMARY:
2102 gtk_entry_set_icon_activatable (entry,
2103 GTK_ENTRY_ICON_PRIMARY,
2104 g_value_get_boolean (value));
2107 case PROP_ACTIVATABLE_SECONDARY:
2108 gtk_entry_set_icon_activatable (entry,
2109 GTK_ENTRY_ICON_SECONDARY,
2110 g_value_get_boolean (value));
2113 case PROP_SENSITIVE_PRIMARY:
2114 gtk_entry_set_icon_sensitive (entry,
2115 GTK_ENTRY_ICON_PRIMARY,
2116 g_value_get_boolean (value));
2119 case PROP_SENSITIVE_SECONDARY:
2120 gtk_entry_set_icon_sensitive (entry,
2121 GTK_ENTRY_ICON_SECONDARY,
2122 g_value_get_boolean (value));
2125 case PROP_TOOLTIP_TEXT_PRIMARY:
2126 gtk_entry_set_icon_tooltip_text (entry,
2127 GTK_ENTRY_ICON_PRIMARY,
2128 g_value_get_string (value));
2131 case PROP_TOOLTIP_TEXT_SECONDARY:
2132 gtk_entry_set_icon_tooltip_text (entry,
2133 GTK_ENTRY_ICON_SECONDARY,
2134 g_value_get_string (value));
2137 case PROP_TOOLTIP_MARKUP_PRIMARY:
2138 gtk_entry_set_icon_tooltip_markup (entry,
2139 GTK_ENTRY_ICON_PRIMARY,
2140 g_value_get_string (value));
2143 case PROP_TOOLTIP_MARKUP_SECONDARY:
2144 gtk_entry_set_icon_tooltip_markup (entry,
2145 GTK_ENTRY_ICON_SECONDARY,
2146 g_value_get_string (value));
2149 case PROP_IM_MODULE:
2150 g_free (priv->im_module);
2151 priv->im_module = g_value_dup_string (value);
2152 if (GTK_IS_IM_MULTICONTEXT (priv->im_context))
2153 gtk_im_multicontext_set_context_id (GTK_IM_MULTICONTEXT (priv->im_context), priv->im_module);
2156 case PROP_EDITING_CANCELED:
2157 priv->editing_canceled = g_value_get_boolean (value);
2160 case PROP_COMPLETION:
2161 gtk_entry_set_completion (entry, GTK_ENTRY_COMPLETION (g_value_get_object (value)));
2164 case PROP_SCROLL_OFFSET:
2165 case PROP_CURSOR_POSITION:
2167 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2173 gtk_entry_get_property (GObject *object,
2178 GtkEntry *entry = GTK_ENTRY (object);
2179 GtkEntryPrivate *priv = entry->priv;
2184 g_value_set_object (value, gtk_entry_get_buffer (entry));
2187 case PROP_CURSOR_POSITION:
2188 g_value_set_int (value, priv->current_pos);
2191 case PROP_SELECTION_BOUND:
2192 g_value_set_int (value, priv->selection_bound);
2196 g_value_set_boolean (value, priv->editable);
2199 case PROP_MAX_LENGTH:
2200 g_value_set_int (value, gtk_entry_buffer_get_max_length (get_buffer (entry)));
2203 case PROP_VISIBILITY:
2204 g_value_set_boolean (value, priv->visible);
2207 case PROP_HAS_FRAME:
2208 g_value_set_boolean (value, priv->has_frame);
2211 case PROP_INNER_BORDER:
2212 g_value_set_boxed (value, gtk_entry_do_get_inner_border (entry));
2215 case PROP_INVISIBLE_CHAR:
2216 g_value_set_uint (value, priv->invisible_char);
2219 case PROP_ACTIVATES_DEFAULT:
2220 g_value_set_boolean (value, priv->activates_default);
2223 case PROP_WIDTH_CHARS:
2224 g_value_set_int (value, priv->width_chars);
2227 case PROP_SCROLL_OFFSET:
2228 g_value_set_int (value, priv->scroll_offset);
2232 g_value_set_string (value, gtk_entry_get_text (entry));
2236 g_value_set_float (value, gtk_entry_get_alignment (entry));
2239 case PROP_TRUNCATE_MULTILINE:
2240 g_value_set_boolean (value, priv->truncate_multiline);
2243 case PROP_SHADOW_TYPE:
2244 g_value_set_enum (value, priv->shadow_type);
2247 case PROP_OVERWRITE_MODE:
2248 g_value_set_boolean (value, priv->overwrite_mode);
2251 case PROP_TEXT_LENGTH:
2252 g_value_set_uint (value, gtk_entry_buffer_get_length (get_buffer (entry)));
2255 case PROP_INVISIBLE_CHAR_SET:
2256 g_value_set_boolean (value, priv->invisible_char_set);
2259 case PROP_IM_MODULE:
2260 g_value_set_string (value, priv->im_module);
2263 case PROP_CAPS_LOCK_WARNING:
2264 g_value_set_boolean (value, priv->caps_lock_warning);
2267 case PROP_PROGRESS_FRACTION:
2268 g_value_set_double (value, priv->progress_fraction);
2271 case PROP_PROGRESS_PULSE_STEP:
2272 g_value_set_double (value, priv->progress_pulse_fraction);
2275 case PROP_PLACEHOLDER_TEXT:
2276 g_value_set_string (value, gtk_entry_get_placeholder_text (entry));
2279 case PROP_PIXBUF_PRIMARY:
2280 g_value_set_object (value,
2281 gtk_entry_get_icon_pixbuf (entry,
2282 GTK_ENTRY_ICON_PRIMARY));
2285 case PROP_PIXBUF_SECONDARY:
2286 g_value_set_object (value,
2287 gtk_entry_get_icon_pixbuf (entry,
2288 GTK_ENTRY_ICON_SECONDARY));
2291 case PROP_STOCK_PRIMARY:
2292 g_value_set_string (value,
2293 gtk_entry_get_icon_stock (entry,
2294 GTK_ENTRY_ICON_PRIMARY));
2297 case PROP_STOCK_SECONDARY:
2298 g_value_set_string (value,
2299 gtk_entry_get_icon_stock (entry,
2300 GTK_ENTRY_ICON_SECONDARY));
2303 case PROP_ICON_NAME_PRIMARY:
2304 g_value_set_string (value,
2305 gtk_entry_get_icon_name (entry,
2306 GTK_ENTRY_ICON_PRIMARY));
2309 case PROP_ICON_NAME_SECONDARY:
2310 g_value_set_string (value,
2311 gtk_entry_get_icon_name (entry,
2312 GTK_ENTRY_ICON_SECONDARY));
2315 case PROP_GICON_PRIMARY:
2316 g_value_set_object (value,
2317 gtk_entry_get_icon_gicon (entry,
2318 GTK_ENTRY_ICON_PRIMARY));
2321 case PROP_GICON_SECONDARY:
2322 g_value_set_object (value,
2323 gtk_entry_get_icon_gicon (entry,
2324 GTK_ENTRY_ICON_SECONDARY));
2327 case PROP_STORAGE_TYPE_PRIMARY:
2328 g_value_set_enum (value,
2329 gtk_entry_get_icon_storage_type (entry,
2330 GTK_ENTRY_ICON_PRIMARY));
2333 case PROP_STORAGE_TYPE_SECONDARY:
2334 g_value_set_enum (value,
2335 gtk_entry_get_icon_storage_type (entry,
2336 GTK_ENTRY_ICON_SECONDARY));
2339 case PROP_ACTIVATABLE_PRIMARY:
2340 g_value_set_boolean (value,
2341 gtk_entry_get_icon_activatable (entry, GTK_ENTRY_ICON_PRIMARY));
2344 case PROP_ACTIVATABLE_SECONDARY:
2345 g_value_set_boolean (value,
2346 gtk_entry_get_icon_activatable (entry, GTK_ENTRY_ICON_SECONDARY));
2349 case PROP_SENSITIVE_PRIMARY:
2350 g_value_set_boolean (value,
2351 gtk_entry_get_icon_sensitive (entry, GTK_ENTRY_ICON_PRIMARY));
2354 case PROP_SENSITIVE_SECONDARY:
2355 g_value_set_boolean (value,
2356 gtk_entry_get_icon_sensitive (entry, GTK_ENTRY_ICON_SECONDARY));
2359 case PROP_TOOLTIP_TEXT_PRIMARY:
2360 g_value_take_string (value,
2361 gtk_entry_get_icon_tooltip_text (entry, GTK_ENTRY_ICON_PRIMARY));
2364 case PROP_TOOLTIP_TEXT_SECONDARY:
2365 g_value_take_string (value,
2366 gtk_entry_get_icon_tooltip_text (entry, GTK_ENTRY_ICON_SECONDARY));
2369 case PROP_TOOLTIP_MARKUP_PRIMARY:
2370 g_value_take_string (value,
2371 gtk_entry_get_icon_tooltip_markup (entry, GTK_ENTRY_ICON_PRIMARY));
2374 case PROP_TOOLTIP_MARKUP_SECONDARY:
2375 g_value_take_string (value,
2376 gtk_entry_get_icon_tooltip_markup (entry, GTK_ENTRY_ICON_SECONDARY));
2379 case PROP_EDITING_CANCELED:
2380 g_value_set_boolean (value,
2381 priv->editing_canceled);
2384 case PROP_COMPLETION:
2385 g_value_set_object (value, G_OBJECT (gtk_entry_get_completion (entry)));
2389 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2395 find_invisible_char (GtkWidget *widget)
2397 PangoLayout *layout;
2398 PangoAttrList *attr_list;
2400 gunichar invisible_chars [] = {
2402 0x25cf, /* BLACK CIRCLE */
2403 0x2022, /* BULLET */
2404 0x2731, /* HEAVY ASTERISK */
2405 0x273a /* SIXTEEN POINTED ASTERISK */
2408 gtk_widget_style_get (widget,
2409 "invisible-char", &invisible_chars[0],
2412 layout = gtk_widget_create_pango_layout (widget, NULL);
2414 attr_list = pango_attr_list_new ();
2415 pango_attr_list_insert (attr_list, pango_attr_fallback_new (FALSE));
2417 pango_layout_set_attributes (layout, attr_list);
2418 pango_attr_list_unref (attr_list);
2420 for (i = (invisible_chars[0] != 0 ? 0 : 1); i < G_N_ELEMENTS (invisible_chars); i++)
2422 gchar text[7] = { 0, };
2425 len = g_unichar_to_utf8 (invisible_chars[i], text);
2426 pango_layout_set_text (layout, text, len);
2428 count = pango_layout_get_unknown_glyphs_count (layout);
2432 g_object_unref (layout);
2433 return invisible_chars[i];
2437 g_object_unref (layout);
2443 gtk_entry_init (GtkEntry *entry)
2445 GtkStyleContext *context;
2446 GtkEntryPrivate *priv;
2448 entry->priv = G_TYPE_INSTANCE_GET_PRIVATE (entry,
2453 gtk_widget_set_can_focus (GTK_WIDGET (entry), TRUE);
2454 gtk_widget_set_has_window (GTK_WIDGET (entry), FALSE);
2456 priv->editable = TRUE;
2457 priv->visible = TRUE;
2458 priv->dnd_position = -1;
2459 priv->width_chars = -1;
2460 priv->is_cell_renderer = FALSE;
2461 priv->editing_canceled = FALSE;
2462 priv->has_frame = TRUE;
2463 priv->truncate_multiline = FALSE;
2464 priv->shadow_type = GTK_SHADOW_IN;
2466 priv->caps_lock_warning = TRUE;
2467 priv->caps_lock_warning_shown = FALSE;
2468 priv->progress_fraction = 0.0;
2469 priv->progress_pulse_fraction = 0.1;
2471 gtk_drag_dest_set (GTK_WIDGET (entry),
2472 GTK_DEST_DEFAULT_HIGHLIGHT,
2474 GDK_ACTION_COPY | GDK_ACTION_MOVE);
2475 gtk_drag_dest_add_text_targets (GTK_WIDGET (entry));
2477 /* This object is completely private. No external entity can gain a reference
2478 * to it; so we create it here and destroy it in finalize().
2480 priv->im_context = gtk_im_multicontext_new ();
2482 g_signal_connect (priv->im_context, "commit",
2483 G_CALLBACK (gtk_entry_commit_cb), entry);
2484 g_signal_connect (priv->im_context, "preedit-changed",
2485 G_CALLBACK (gtk_entry_preedit_changed_cb), entry);
2486 g_signal_connect (priv->im_context, "retrieve-surrounding",
2487 G_CALLBACK (gtk_entry_retrieve_surrounding_cb), entry);
2488 g_signal_connect (priv->im_context, "delete-surrounding",
2489 G_CALLBACK (gtk_entry_delete_surrounding_cb), entry);
2491 context = gtk_widget_get_style_context (GTK_WIDGET (entry));
2492 gtk_style_context_add_class (context, GTK_STYLE_CLASS_ENTRY);
2494 gtk_entry_update_cached_style_values (entry);
2498 gtk_entry_prepare_context_for_icon (GtkEntry *entry,
2499 GtkStyleContext *context,
2500 GtkEntryIconPosition icon_pos)
2502 GtkEntryPrivate *priv = entry->priv;
2503 EntryIconInfo *icon_info = priv->icons[icon_pos];
2505 GtkStateFlags state;
2507 widget = GTK_WIDGET (entry);
2508 state = gtk_widget_get_state_flags (widget);
2510 state &= ~(GTK_STATE_FLAG_PRELIGHT);
2512 if ((state & GTK_STATE_FLAG_INSENSITIVE) || icon_info->insensitive)
2513 state |= GTK_STATE_FLAG_INSENSITIVE;
2514 else if (icon_info->prelight)
2515 state |= GTK_STATE_FLAG_PRELIGHT;
2517 gtk_style_context_save (context);
2519 gtk_style_context_set_state (context, state);
2520 gtk_style_context_add_class (context, GTK_STYLE_CLASS_IMAGE);
2522 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
2524 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
2525 gtk_style_context_add_class (context, GTK_STYLE_CLASS_RIGHT);
2527 gtk_style_context_add_class (context, GTK_STYLE_CLASS_LEFT);
2531 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
2532 gtk_style_context_add_class (context, GTK_STYLE_CLASS_LEFT);
2534 gtk_style_context_add_class (context, GTK_STYLE_CLASS_RIGHT);
2539 get_icon_width (GtkEntry *entry,
2540 GtkEntryIconPosition icon_pos)
2542 GtkEntryPrivate *priv = entry->priv;
2543 EntryIconInfo *icon_info = priv->icons[icon_pos];
2544 GtkStyleContext *context;
2551 context = gtk_widget_get_style_context (GTK_WIDGET (entry));
2552 gtk_entry_prepare_context_for_icon (entry, context, icon_pos);
2553 gtk_style_context_get_padding (context, 0, &padding);
2555 _gtk_icon_helper_get_size (icon_info->icon_helper, context,
2557 gtk_style_context_restore (context);
2560 width += padding.left + padding.right;
2566 get_icon_allocations (GtkEntry *entry,
2567 GtkAllocation *primary,
2568 GtkAllocation *secondary)
2571 GtkEntryPrivate *priv = entry->priv;
2572 gint x, y, width, height;
2574 get_text_area_size (entry, &x, &y, &width, &height);
2576 if (gtk_widget_has_focus (GTK_WIDGET (entry)) && !priv->interior_focus)
2577 y += priv->focus_width;
2580 primary->height = height;
2581 primary->width = get_icon_width (entry, GTK_ENTRY_ICON_PRIMARY);
2584 secondary->height = height;
2585 secondary->width = get_icon_width (entry, GTK_ENTRY_ICON_SECONDARY);
2587 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
2589 primary->x = x + width - primary->width;
2595 secondary->x = x + width - secondary->width;
2601 begin_change (GtkEntry *entry)
2603 GtkEntryPrivate *priv = entry->priv;
2605 priv->change_count++;
2607 g_object_freeze_notify (G_OBJECT (entry));
2611 end_change (GtkEntry *entry)
2613 GtkEditable *editable = GTK_EDITABLE (entry);
2614 GtkEntryPrivate *priv = entry->priv;
2616 g_return_if_fail (priv->change_count > 0);
2618 g_object_thaw_notify (G_OBJECT (entry));
2620 priv->change_count--;
2622 if (priv->change_count == 0)
2624 if (priv->real_changed)
2626 g_signal_emit_by_name (editable, "changed");
2627 priv->real_changed = FALSE;
2633 emit_changed (GtkEntry *entry)
2635 GtkEditable *editable = GTK_EDITABLE (entry);
2636 GtkEntryPrivate *priv = entry->priv;
2638 if (priv->change_count == 0)
2639 g_signal_emit_by_name (editable, "changed");
2641 priv->real_changed = TRUE;
2645 gtk_entry_destroy (GtkWidget *widget)
2647 GtkEntry *entry = GTK_ENTRY (widget);
2648 GtkEntryPrivate *priv = entry->priv;
2650 priv->current_pos = priv->selection_bound = 0;
2651 _gtk_entry_reset_im_context (entry);
2652 gtk_entry_reset_layout (entry);
2654 if (priv->blink_timeout)
2656 g_source_remove (priv->blink_timeout);
2657 priv->blink_timeout = 0;
2660 if (priv->recompute_idle)
2662 g_source_remove (priv->recompute_idle);
2663 priv->recompute_idle = 0;
2666 GTK_WIDGET_CLASS (gtk_entry_parent_class)->destroy (widget);
2670 gtk_entry_dispose (GObject *object)
2672 GtkEntry *entry = GTK_ENTRY (object);
2673 GtkEntryPrivate *priv = entry->priv;
2676 gtk_entry_set_icon_from_pixbuf (entry, GTK_ENTRY_ICON_PRIMARY, NULL);
2677 gtk_entry_set_icon_tooltip_markup (entry, GTK_ENTRY_ICON_PRIMARY, NULL);
2678 gtk_entry_set_icon_from_pixbuf (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
2679 gtk_entry_set_icon_tooltip_markup (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
2683 buffer_disconnect_signals (entry);
2684 g_object_unref (priv->buffer);
2685 priv->buffer = NULL;
2688 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (object)));
2689 g_signal_handlers_disconnect_by_func (keymap, keymap_state_changed, entry);
2690 g_signal_handlers_disconnect_by_func (keymap, keymap_direction_changed, entry);
2691 G_OBJECT_CLASS (gtk_entry_parent_class)->dispose (object);
2695 gtk_entry_finalize (GObject *object)
2697 GtkEntry *entry = GTK_ENTRY (object);
2698 GtkEntryPrivate *priv = entry->priv;
2699 EntryIconInfo *icon_info = NULL;
2702 for (i = 0; i < MAX_ICONS; i++)
2704 if ((icon_info = priv->icons[i]) != NULL)
2706 if (icon_info->target_list != NULL)
2708 gtk_target_list_unref (icon_info->target_list);
2709 icon_info->target_list = NULL;
2712 g_clear_object (&icon_info->icon_helper);
2714 g_slice_free (EntryIconInfo, icon_info);
2715 priv->icons[i] = NULL;
2719 gtk_entry_set_completion (entry, NULL);
2721 if (priv->cached_layout)
2722 g_object_unref (priv->cached_layout);
2724 g_object_unref (priv->im_context);
2726 if (priv->blink_timeout)
2727 g_source_remove (priv->blink_timeout);
2729 if (priv->recompute_idle)
2730 g_source_remove (priv->recompute_idle);
2732 g_free (priv->placeholder_text);
2733 g_free (priv->im_module);
2735 G_OBJECT_CLASS (gtk_entry_parent_class)->finalize (object);
2739 gtk_entry_get_display_mode (GtkEntry *entry)
2741 GtkEntryPrivate *priv = entry->priv;
2744 return DISPLAY_NORMAL;
2746 if (priv->invisible_char == 0 && priv->invisible_char_set)
2747 return DISPLAY_BLANK;
2749 return DISPLAY_INVISIBLE;
2753 gtk_entry_get_display_text (GtkEntry *entry,
2757 GtkEntryPasswordHint *password_hint;
2758 GtkEntryPrivate *priv;
2759 gunichar invisible_char;
2770 text = gtk_entry_buffer_get_text (get_buffer (entry));
2771 length = gtk_entry_buffer_get_length (get_buffer (entry));
2775 if (start_pos > length)
2778 if (end_pos <= start_pos)
2779 return g_strdup ("");
2780 else if (priv->visible)
2782 start = g_utf8_offset_to_pointer (text, start_pos);
2783 end = g_utf8_offset_to_pointer (start, end_pos - start_pos);
2784 return g_strndup (start, end - start);
2788 str = g_string_sized_new (length * 2);
2790 /* Figure out what our invisible char is and encode it */
2791 if (!priv->invisible_char)
2792 invisible_char = priv->invisible_char_set ? ' ' : '*';
2794 invisible_char = priv->invisible_char;
2795 char_len = g_unichar_to_utf8 (invisible_char, char_str);
2798 * Add hidden characters for each character in the text
2799 * buffer. If there is a password hint, then keep that
2800 * character visible.
2803 password_hint = g_object_get_qdata (G_OBJECT (entry), quark_password_hint);
2804 for (i = start_pos; i < end_pos; ++i)
2806 if (password_hint && i == password_hint->position)
2808 start = g_utf8_offset_to_pointer (text, i);
2809 g_string_append_len (str, start, g_utf8_next_char (start) - start);
2813 g_string_append_len (str, char_str, char_len);
2817 return g_string_free (str, FALSE);
2822 update_cursors (GtkWidget *widget)
2824 GtkEntry *entry = GTK_ENTRY (widget);
2825 GtkEntryPrivate *priv = entry->priv;
2826 EntryIconInfo *icon_info = NULL;
2827 GdkDisplay *display;
2831 for (i = 0; i < MAX_ICONS; i++)
2833 if ((icon_info = priv->icons[i]) != NULL)
2835 if (!_gtk_icon_helper_get_is_empty (icon_info->icon_helper) &&
2836 icon_info->window != NULL)
2837 gdk_window_show_unraised (icon_info->window);
2839 /* The icon windows are not children of the visible entry window,
2840 * thus we can't just inherit the xterm cursor. Slight complication
2841 * here is that for the entry, insensitive => arrow cursor, but for
2842 * an icon in a sensitive entry, insensitive => xterm cursor.
2844 if (gtk_widget_is_sensitive (widget) &&
2845 (icon_info->insensitive ||
2846 (icon_info->nonactivatable && icon_info->target_list == NULL)))
2848 display = gtk_widget_get_display (widget);
2849 cursor = gdk_cursor_new_for_display (display, GDK_XTERM);
2850 gdk_window_set_cursor (icon_info->window, cursor);
2851 g_object_unref (cursor);
2855 gdk_window_set_cursor (icon_info->window, NULL);
2862 realize_icon_info (GtkWidget *widget,
2863 GtkEntryIconPosition icon_pos)
2865 GtkEntry *entry = GTK_ENTRY (widget);
2866 GtkEntryPrivate *priv = entry->priv;
2867 EntryIconInfo *icon_info = priv->icons[icon_pos];
2868 GdkWindowAttr attributes;
2869 gint attributes_mask;
2871 g_return_if_fail (icon_info != NULL);
2875 attributes.width = 1;
2876 attributes.height = 1;
2877 attributes.window_type = GDK_WINDOW_CHILD;
2878 attributes.wclass = GDK_INPUT_ONLY;
2879 attributes.event_mask = gtk_widget_get_events (widget);
2880 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
2881 GDK_BUTTON_RELEASE_MASK |
2882 GDK_BUTTON1_MOTION_MASK |
2883 GDK_BUTTON3_MOTION_MASK |
2884 GDK_POINTER_MOTION_HINT_MASK |
2885 GDK_POINTER_MOTION_MASK |
2886 GDK_ENTER_NOTIFY_MASK |
2887 GDK_LEAVE_NOTIFY_MASK);
2888 attributes_mask = GDK_WA_X | GDK_WA_Y;
2890 icon_info->window = gdk_window_new (gtk_widget_get_window (widget),
2893 gdk_window_set_user_data (icon_info->window, widget);
2895 gtk_widget_queue_resize (widget);
2898 static EntryIconInfo*
2899 construct_icon_info (GtkWidget *widget,
2900 GtkEntryIconPosition icon_pos)
2902 GtkEntry *entry = GTK_ENTRY (widget);
2903 GtkEntryPrivate *priv = entry->priv;
2904 EntryIconInfo *icon_info;
2906 g_return_val_if_fail (priv->icons[icon_pos] == NULL, NULL);
2908 icon_info = g_slice_new0 (EntryIconInfo);
2909 priv->icons[icon_pos] = icon_info;
2911 icon_info->icon_helper = _gtk_icon_helper_new ();
2913 if (gtk_widget_get_realized (widget))
2914 realize_icon_info (widget, icon_pos);
2920 gtk_entry_map (GtkWidget *widget)
2922 GtkEntry *entry = GTK_ENTRY (widget);
2923 GtkEntryPrivate *priv = entry->priv;
2924 EntryIconInfo *icon_info = NULL;
2927 GTK_WIDGET_CLASS (gtk_entry_parent_class)->map (widget);
2929 gdk_window_show (priv->text_area);
2931 for (i = 0; i < MAX_ICONS; i++)
2933 if ((icon_info = priv->icons[i]) != NULL)
2935 if (!_gtk_icon_helper_get_is_empty (icon_info->icon_helper) &&
2936 icon_info->window != NULL)
2937 gdk_window_show (icon_info->window);
2941 update_cursors (widget);
2945 gtk_entry_unmap (GtkWidget *widget)
2947 GtkEntry *entry = GTK_ENTRY (widget);
2948 GtkEntryPrivate *priv = entry->priv;
2949 EntryIconInfo *icon_info = NULL;
2952 for (i = 0; i < MAX_ICONS; i++)
2954 if ((icon_info = priv->icons[i]) != NULL)
2956 if (!_gtk_icon_helper_get_is_empty (icon_info->icon_helper) &&
2957 icon_info->window != NULL)
2958 gdk_window_hide (icon_info->window);
2962 gdk_window_hide (priv->text_area);
2964 GTK_WIDGET_CLASS (gtk_entry_parent_class)->unmap (widget);
2968 gtk_entry_realize (GtkWidget *widget)
2971 GtkEntryPrivate *priv;
2972 EntryIconInfo *icon_info;
2974 GdkWindowAttr attributes;
2975 gint attributes_mask;
2976 gint frame_x, frame_y;
2979 gtk_widget_set_realized (widget, TRUE);
2980 window = gtk_widget_get_parent_window (widget);
2981 gtk_widget_set_window (widget, window);
2982 g_object_ref (window);
2984 entry = GTK_ENTRY (widget);
2987 attributes.window_type = GDK_WINDOW_CHILD;
2988 attributes.wclass = GDK_INPUT_ONLY;
2989 attributes.event_mask = gtk_widget_get_events (widget);
2990 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
2991 GDK_BUTTON_RELEASE_MASK |
2992 GDK_BUTTON1_MOTION_MASK |
2993 GDK_BUTTON3_MOTION_MASK |
2994 GDK_POINTER_MOTION_HINT_MASK |
2995 GDK_POINTER_MOTION_MASK |
2996 GDK_ENTER_NOTIFY_MASK |
2997 GDK_LEAVE_NOTIFY_MASK);
2998 attributes_mask = GDK_WA_X | GDK_WA_Y;
3000 get_text_area_size (entry, &attributes.x, &attributes.y, &attributes.width, &attributes.height);
3002 get_frame_size (entry, TRUE, &frame_x, &frame_y, NULL, NULL);
3003 attributes.x += frame_x;
3004 attributes.y += frame_y;
3006 if (gtk_widget_is_sensitive (widget))
3008 attributes.cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
3009 attributes_mask |= GDK_WA_CURSOR;
3012 priv->text_area = gdk_window_new (gtk_widget_get_window (widget),
3016 gdk_window_set_user_data (priv->text_area, entry);
3018 if (attributes_mask & GDK_WA_CURSOR)
3019 g_object_unref (attributes.cursor);
3021 gtk_im_context_set_client_window (priv->im_context, priv->text_area);
3023 gtk_entry_adjust_scroll (entry);
3024 gtk_entry_update_primary_selection (entry);
3027 /* If the icon positions are already setup, create their windows.
3028 * Otherwise if they don't exist yet, then construct_icon_info()
3029 * will create the windows once the widget is already realized.
3031 for (i = 0; i < MAX_ICONS; i++)
3033 if ((icon_info = priv->icons[i]) != NULL)
3035 if (icon_info->window == NULL)
3036 realize_icon_info (widget, i);
3042 gtk_entry_unrealize (GtkWidget *widget)
3044 GtkEntry *entry = GTK_ENTRY (widget);
3045 GtkEntryPrivate *priv = entry->priv;
3046 GtkClipboard *clipboard;
3047 EntryIconInfo *icon_info;
3050 gtk_entry_reset_layout (entry);
3052 gtk_im_context_set_client_window (priv->im_context, NULL);
3054 clipboard = gtk_widget_get_clipboard (widget, GDK_SELECTION_PRIMARY);
3055 if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (entry))
3056 gtk_clipboard_clear (clipboard);
3058 if (priv->text_area)
3060 gdk_window_set_user_data (priv->text_area, NULL);
3061 gdk_window_destroy (priv->text_area);
3062 priv->text_area = NULL;
3065 if (priv->popup_menu)
3067 gtk_widget_destroy (priv->popup_menu);
3068 priv->popup_menu = NULL;
3071 GTK_WIDGET_CLASS (gtk_entry_parent_class)->unrealize (widget);
3073 for (i = 0; i < MAX_ICONS; i++)
3075 if ((icon_info = priv->icons[i]) != NULL)
3077 if (icon_info->window != NULL)
3079 gdk_window_destroy (icon_info->window);
3080 icon_info->window = NULL;
3087 _gtk_entry_get_borders (GtkEntry *entry,
3088 GtkBorder *border_out)
3090 GtkEntryPrivate *priv = entry->priv;
3091 GtkWidget *widget = GTK_WIDGET (entry);
3092 GtkBorder tmp = { 0, 0, 0, 0 };
3093 GtkStyleContext *context;
3095 context = gtk_widget_get_style_context (widget);
3096 gtk_style_context_get_padding (context, 0, &tmp);
3098 if (priv->has_frame)
3102 gtk_style_context_get_border (context, 0, &border);
3103 tmp.top += border.top;
3104 tmp.right += border.right;
3105 tmp.bottom += border.bottom;
3106 tmp.left += border.left;
3109 if (!priv->interior_focus)
3111 tmp.top += priv->focus_width;
3112 tmp.right += priv->focus_width;
3113 tmp.bottom += priv->focus_width;
3114 tmp.left += priv->focus_width;
3117 if (border_out != NULL)
3122 gtk_entry_get_preferred_width (GtkWidget *widget,
3126 GtkEntry *entry = GTK_ENTRY (widget);
3127 GtkEntryPrivate *priv = entry->priv;
3128 PangoFontMetrics *metrics;
3130 PangoContext *context;
3131 GtkStyleContext *style_context;
3132 GtkStateFlags state;
3133 gint icon_widths = 0;
3137 context = gtk_widget_get_pango_context (widget);
3139 style_context = gtk_widget_get_style_context (widget);
3140 state = gtk_widget_get_state_flags (widget);
3142 metrics = pango_context_get_metrics (context,
3143 gtk_style_context_get_font (style_context, state),
3144 pango_context_get_language (context));
3146 _gtk_entry_get_borders (entry, &borders);
3148 if (priv->width_chars < 0)
3149 width = MIN_ENTRY_WIDTH + borders.left + borders.right;
3152 gint char_width = pango_font_metrics_get_approximate_char_width (metrics);
3153 gint digit_width = pango_font_metrics_get_approximate_digit_width (metrics);
3154 gint char_pixels = (MAX (char_width, digit_width) + PANGO_SCALE - 1) / PANGO_SCALE;
3156 width = char_pixels * priv->width_chars + borders.left + borders.right;
3159 for (i = 0; i < MAX_ICONS; i++)
3161 icon_width = get_icon_width (entry, i);
3163 icon_widths += icon_width;
3166 if (icon_widths > width)
3167 width += icon_widths;
3169 pango_font_metrics_unref (metrics);
3176 gtk_entry_get_preferred_height (GtkWidget *widget,
3180 GtkEntry *entry = GTK_ENTRY (widget);
3181 GtkEntryPrivate *priv = entry->priv;
3182 PangoFontMetrics *metrics;
3184 GtkStyleContext *style_context;
3185 GtkStateFlags state;
3186 PangoContext *context;
3189 context = gtk_widget_get_pango_context (widget);
3191 style_context = gtk_widget_get_style_context (widget);
3192 state = gtk_widget_get_state_flags (widget);
3194 metrics = pango_context_get_metrics (context,
3195 gtk_style_context_get_font (style_context, state),
3196 pango_context_get_language (context));
3198 priv->ascent = pango_font_metrics_get_ascent (metrics);
3199 priv->descent = pango_font_metrics_get_descent (metrics);
3201 _gtk_entry_get_borders (entry, &borders);
3203 height = PANGO_PIXELS (priv->ascent + priv->descent) + borders.top + borders.bottom;
3205 pango_font_metrics_unref (metrics);
3212 place_windows (GtkEntry *entry)
3214 GtkWidget *widget = GTK_WIDGET (entry);
3215 GtkEntryPrivate *priv = entry->priv;
3216 gint x, y, width, height;
3217 gint frame_x, frame_y;
3218 GtkAllocation primary;
3219 GtkAllocation secondary;
3220 EntryIconInfo *icon_info = NULL;
3222 get_frame_size (entry, TRUE, &frame_x, &frame_y, NULL, NULL);
3223 get_text_area_size (entry, &x, &y, &width, &height);
3224 get_icon_allocations (entry, &primary, &secondary);
3226 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3227 y += priv->focus_width;
3229 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
3230 x += secondary.width;
3233 width -= primary.width + secondary.width;
3237 primary.x += frame_x;
3238 primary.y += frame_y;
3239 secondary.x += frame_x;
3240 secondary.y += frame_y;
3242 if ((icon_info = priv->icons[GTK_ENTRY_ICON_PRIMARY]) != NULL)
3243 gdk_window_move_resize (icon_info->window,
3244 primary.x, primary.y,
3245 primary.width, primary.height);
3247 if ((icon_info = priv->icons[GTK_ENTRY_ICON_SECONDARY]) != NULL)
3248 gdk_window_move_resize (icon_info->window,
3249 secondary.x, secondary.y,
3250 secondary.width, secondary.height);
3252 gdk_window_move_resize (priv->text_area, x, y, width, height);
3256 gtk_entry_get_text_area_size (GtkEntry *entry,
3262 GtkEntryPrivate *priv = entry->priv;
3263 GtkWidget *widget = GTK_WIDGET (entry);
3264 GtkAllocation allocation;
3265 GtkRequisition requisition;
3270 gtk_widget_get_preferred_size (widget, &requisition, NULL);
3271 req_height = requisition.height - gtk_widget_get_margin_top (widget) - gtk_widget_get_margin_bottom (widget);
3273 gtk_widget_get_allocation (widget, &allocation);
3274 _gtk_entry_get_borders (entry, &borders);
3276 if (gtk_widget_get_realized (widget))
3277 get_frame_size (entry, TRUE, NULL, NULL, NULL, &frame_height);
3279 frame_height = req_height;
3281 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3282 frame_height -= 2 * priv->focus_width;
3288 *y = floor ((frame_height - req_height) / 2) + borders.top;
3291 *width = allocation.width - borders.left - borders.right;
3294 *height = req_height - borders.top - borders.bottom;
3298 get_text_area_size (GtkEntry *entry,
3304 GtkEntryClass *class;
3306 g_return_if_fail (GTK_IS_ENTRY (entry));
3308 class = GTK_ENTRY_GET_CLASS (entry);
3310 if (class->get_text_area_size)
3311 class->get_text_area_size (entry, x, y, width, height);
3316 get_frame_size (GtkEntry *entry,
3317 gboolean relative_to_window,
3323 GtkEntryPrivate *priv = entry->priv;
3324 GtkAllocation allocation;
3325 GtkRequisition requisition;
3326 GtkWidget *widget = GTK_WIDGET (entry);
3329 gtk_widget_get_preferred_size (widget, &requisition, NULL);
3331 req_height = requisition.height - gtk_widget_get_margin_top (widget) - gtk_widget_get_margin_bottom (widget);
3333 gtk_widget_get_allocation (widget, &allocation);
3336 *x = relative_to_window ? allocation.x : 0;
3340 if (priv->is_cell_renderer)
3343 *y = (allocation.height - req_height) / 2;
3345 if (relative_to_window)
3350 *width = allocation.width;
3354 if (priv->is_cell_renderer)
3355 *height = allocation.height;
3357 *height = req_height;
3362 gtk_entry_size_allocate (GtkWidget *widget,
3363 GtkAllocation *allocation)
3365 GtkEntry *entry = GTK_ENTRY (widget);
3367 gtk_widget_set_allocation (widget, allocation);
3369 if (gtk_widget_get_realized (widget))
3371 GtkEntryCompletion* completion;
3373 place_windows (entry);
3374 gtk_entry_recompute (entry);
3376 completion = gtk_entry_get_completion (entry);
3377 if (completion && gtk_widget_get_mapped (completion->priv->popup_window))
3378 _gtk_entry_completion_resize_popup (completion);
3383 should_prelight (GtkEntry *entry,
3384 GtkEntryIconPosition icon_pos)
3386 GtkEntryPrivate *priv = entry->priv;
3387 EntryIconInfo *icon_info = priv->icons[icon_pos];
3393 if (icon_info->nonactivatable && icon_info->target_list == NULL)
3396 if (icon_info->pressed)
3399 gtk_widget_style_get (GTK_WIDGET (entry),
3400 "icon-prelight", &prelight,
3407 draw_icon (GtkWidget *widget,
3409 GtkEntryIconPosition icon_pos)
3411 GtkEntry *entry = GTK_ENTRY (widget);
3412 GtkEntryPrivate *priv = entry->priv;
3413 EntryIconInfo *icon_info = priv->icons[icon_pos];
3414 gint x, y, width, height, pix_width, pix_height;
3415 GtkStyleContext *context;
3421 width = gdk_window_get_width (icon_info->window);
3422 height = gdk_window_get_height (icon_info->window);
3424 /* size_allocate hasn't been called yet. These are the default values.
3426 if (width == 1 || height == 1)
3430 gtk_cairo_transform_to_window (cr, widget, icon_info->window);
3432 context = gtk_widget_get_style_context (widget);
3433 gtk_entry_prepare_context_for_icon (entry, context, icon_pos);
3434 _gtk_icon_helper_get_size (icon_info->icon_helper, context,
3435 &pix_width, &pix_height);
3436 gtk_style_context_get_padding (context, 0, &padding);
3438 x = MAX (0, padding.left);
3439 y = MAX (0, (height - pix_height) / 2);
3441 _gtk_icon_helper_draw (icon_info->icon_helper,
3445 gtk_style_context_restore (context);
3451 gtk_entry_draw_frame (GtkWidget *widget,
3452 GtkStyleContext *context,
3455 GtkEntry *entry = GTK_ENTRY (widget);
3456 GtkEntryPrivate *priv = entry->priv;
3457 gint x = 0, y = 0, width, height;
3458 gint frame_x, frame_y;
3462 get_frame_size (GTK_ENTRY (widget), FALSE, &frame_x, &frame_y, &width, &height);
3464 cairo_translate (cr, frame_x, frame_y);
3466 /* Fix a problem with some themes which assume that entry->text_area's
3467 * width equals widget->window's width
3468 * http://bugzilla.gnome.org/show_bug.cgi?id=466000 */
3469 if (GTK_IS_SPIN_BUTTON (widget))
3473 gtk_entry_get_text_area_size (GTK_ENTRY (widget), &x, NULL, &width, NULL);
3474 _gtk_entry_get_borders (GTK_ENTRY (widget), &borders);
3477 width += borders.left + borders.right;
3480 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3482 x += priv->focus_width;
3483 y += priv->focus_width;
3484 width -= 2 * priv->focus_width;
3485 height -= 2 * priv->focus_width;
3488 gtk_render_background (context, cr,
3489 x, y, width, height);
3491 if (priv->has_frame)
3492 gtk_render_frame (context, cr,
3493 x, y, width, height);
3495 gtk_entry_draw_progress (widget, context, cr);
3497 if (gtk_widget_has_visible_focus (widget) && !priv->interior_focus)
3499 x -= priv->focus_width;
3500 y -= priv->focus_width;
3501 width += 2 * priv->focus_width;
3502 height += 2 * priv->focus_width;
3504 gtk_render_focus (context, cr,
3505 0, 0, width, height);
3512 gtk_entry_prepare_context_for_progress (GtkEntry *entry,
3513 GtkStyleContext *context)
3515 GtkEntryPrivate *private = entry->priv;
3517 gtk_style_context_save (context);
3518 gtk_style_context_add_class (context, GTK_STYLE_CLASS_PROGRESSBAR);
3519 if (private->progress_pulse_mode)
3520 gtk_style_context_add_class (context, GTK_STYLE_CLASS_PULSE);
3524 get_progress_area (GtkWidget *widget,
3530 GtkEntry *entry = GTK_ENTRY (widget);
3531 GtkEntryPrivate *private = entry->priv;
3532 GtkStyleContext *context;
3533 GtkBorder margin, border, entry_borders;
3534 gint frame_width, text_area_width, text_area_height;
3536 context = gtk_widget_get_style_context (widget);
3537 _gtk_entry_get_borders (entry, &entry_borders);
3538 get_text_area_size (entry,
3540 &text_area_width, &text_area_height);
3541 get_frame_size (entry, FALSE,
3543 &frame_width, NULL);
3547 *width = text_area_width + entry_borders.left + entry_borders.right;
3548 *height = text_area_height + entry_borders.top + entry_borders.bottom;
3550 /* if the text area got resized by a subclass, subtract the left/right
3551 * border width, so that the progress bar won't extend over the resized
3554 if (frame_width > *width)
3556 gtk_style_context_get_border (context, 0, &border);
3557 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
3559 *x = (frame_width - *width) + border.left;
3560 *width -= border.left;
3564 *width -= border.right;
3568 gtk_entry_prepare_context_for_progress (entry, context);
3569 gtk_style_context_get_margin (context, 0, &margin);
3571 gtk_style_context_restore (context);
3575 *width -= margin.left + margin.right;
3576 *height -= margin.top + margin.bottom;
3578 if (private->progress_pulse_mode)
3580 gdouble value = private->progress_pulse_current;
3582 *x += (gint) floor(value * (*width));
3583 *width = (gint) ceil(private->progress_pulse_fraction * (*width));
3585 else if (private->progress_fraction > 0)
3587 gdouble value = private->progress_fraction;
3589 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
3593 bar_width = floor(value * (*width) + 0.5);
3594 *x += *width - bar_width;
3599 *width = (gint) floor(value * (*width) + 0.5);
3610 gtk_entry_draw_progress (GtkWidget *widget,
3611 GtkStyleContext *context,
3614 GtkEntry *entry = GTK_ENTRY (widget);
3615 gint x, y, width, height;
3617 get_progress_area (widget, &x, &y, &width, &height);
3619 if ((width <= 0) || (height <= 0))
3622 gtk_entry_prepare_context_for_progress (entry, context);
3623 gtk_render_activity (context, cr,
3624 x, y, width, height);
3626 gtk_style_context_restore (context);
3630 gtk_entry_draw (GtkWidget *widget,
3633 GtkEntry *entry = GTK_ENTRY (widget);
3634 GtkStyleContext *context;
3635 GtkEntryPrivate *priv = entry->priv;
3638 context = gtk_widget_get_style_context (widget);
3640 /* Draw entry_bg, shadow, progress and focus */
3641 gtk_entry_draw_frame (widget, context, cr);
3643 /* Draw text and cursor */
3646 gtk_cairo_transform_to_window (cr, widget, priv->text_area);
3648 if (priv->dnd_position != -1)
3649 gtk_entry_draw_cursor (GTK_ENTRY (widget), cr, CURSOR_DND);
3651 gtk_entry_draw_text (GTK_ENTRY (widget), cr);
3653 /* When no text is being displayed at all, don't show the cursor */
3654 if (gtk_entry_get_display_mode (entry) != DISPLAY_BLANK &&
3655 gtk_widget_has_focus (widget) &&
3656 priv->selection_bound == priv->current_pos && priv->cursor_visible)
3657 gtk_entry_draw_cursor (GTK_ENTRY (widget), cr, CURSOR_STANDARD);
3662 for (i = 0; i < MAX_ICONS; i++)
3664 EntryIconInfo *icon_info = priv->icons[i];
3666 if (icon_info != NULL)
3667 draw_icon (widget, cr, i);
3674 gtk_entry_enter_notify (GtkWidget *widget,
3675 GdkEventCrossing *event)
3677 GtkEntry *entry = GTK_ENTRY (widget);
3678 GtkEntryPrivate *priv = entry->priv;
3681 for (i = 0; i < MAX_ICONS; i++)
3683 EntryIconInfo *icon_info = priv->icons[i];
3685 if (icon_info != NULL && event->window == icon_info->window)
3687 if (should_prelight (entry, i))
3689 icon_info->prelight = TRUE;
3690 gtk_widget_queue_draw (widget);
3701 gtk_entry_leave_notify (GtkWidget *widget,
3702 GdkEventCrossing *event)
3704 GtkEntry *entry = GTK_ENTRY (widget);
3705 GtkEntryPrivate *priv = entry->priv;
3708 for (i = 0; i < MAX_ICONS; i++)
3710 EntryIconInfo *icon_info = priv->icons[i];
3712 if (icon_info != NULL && event->window == icon_info->window)
3714 /* a grab means that we may never see the button release */
3715 if (event->mode == GDK_CROSSING_GRAB || event->mode == GDK_CROSSING_GTK_GRAB)
3716 icon_info->pressed = FALSE;
3718 if (should_prelight (entry, i))
3720 icon_info->prelight = FALSE;
3721 gtk_widget_queue_draw (widget);
3732 gtk_entry_get_pixel_ranges (GtkEntry *entry,
3736 gint start_char, end_char;
3738 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start_char, &end_char))
3740 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
3741 PangoLayoutLine *line = pango_layout_get_lines_readonly (layout)->data;
3742 const char *text = pango_layout_get_text (layout);
3743 gint start_index = g_utf8_offset_to_pointer (text, start_char) - text;
3744 gint end_index = g_utf8_offset_to_pointer (text, end_char) - text;
3745 gint real_n_ranges, i;
3747 pango_layout_line_get_x_ranges (line, start_index, end_index, ranges, &real_n_ranges);
3753 for (i = 0; i < real_n_ranges; ++i)
3755 r[2 * i + 1] = (r[2 * i + 1] - r[2 * i]) / PANGO_SCALE;
3756 r[2 * i] = r[2 * i] / PANGO_SCALE;
3761 *n_ranges = real_n_ranges;
3773 in_selection (GtkEntry *entry,
3778 gint retval = FALSE;
3780 gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
3782 for (i = 0; i < n_ranges; ++i)
3784 if (x >= ranges[2 * i] && x < ranges[2 * i] + ranges[2 * i + 1])
3796 gtk_entry_button_press (GtkWidget *widget,
3797 GdkEventButton *event)
3799 GtkEntry *entry = GTK_ENTRY (widget);
3800 GtkEditable *editable = GTK_EDITABLE (widget);
3801 GtkEntryPrivate *priv = entry->priv;
3802 EntryIconInfo *icon_info = NULL;
3804 gint sel_start, sel_end;
3807 for (i = 0; i < MAX_ICONS; i++)
3809 icon_info = priv->icons[i];
3811 if (!icon_info || icon_info->insensitive)
3814 if (event->window == icon_info->window)
3816 if (should_prelight (entry, i))
3818 icon_info->prelight = FALSE;
3819 gtk_widget_queue_draw (widget);
3822 priv->start_x = event->x;
3823 priv->start_y = event->y;
3824 icon_info->pressed = TRUE;
3826 if (!icon_info->nonactivatable)
3827 g_signal_emit (entry, signals[ICON_PRESS], 0, i, event);
3833 if (event->window != priv->text_area ||
3834 (priv->button && event->button != priv->button))
3837 gtk_entry_reset_blink_time (entry);
3839 priv->button = event->button;
3840 priv->device = gdk_event_get_device ((GdkEvent *) event);
3842 if (!gtk_widget_has_focus (widget))
3844 priv->in_click = TRUE;
3845 gtk_widget_grab_focus (widget);
3846 priv->in_click = FALSE;
3849 tmp_pos = gtk_entry_find_position (entry, event->x + priv->scroll_offset);
3851 if (gdk_event_triggers_context_menu ((GdkEvent *) event))
3853 gtk_entry_do_popup (entry, event);
3854 priv->button = 0; /* Don't wait for release, since the menu will gtk_grab_add */
3855 priv->device = NULL;
3859 else if (event->button == GDK_BUTTON_PRIMARY)
3861 gboolean have_selection = gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end);
3863 priv->select_words = FALSE;
3864 priv->select_lines = FALSE;
3867 gtk_widget_get_modifier_mask (widget,
3868 GDK_MODIFIER_INTENT_EXTEND_SELECTION))
3870 _gtk_entry_reset_im_context (entry);
3872 if (!have_selection) /* select from the current position to the clicked position */
3873 sel_start = sel_end = priv->current_pos;
3875 if (tmp_pos > sel_start && tmp_pos < sel_end)
3877 /* Truncate current selection, but keep it as big as possible */
3878 if (tmp_pos - sel_start > sel_end - tmp_pos)
3879 gtk_entry_set_positions (entry, sel_start, tmp_pos);
3881 gtk_entry_set_positions (entry, tmp_pos, sel_end);
3885 gboolean extend_to_left;
3888 /* Figure out what click selects and extend current selection */
3889 switch (event->type)
3891 case GDK_BUTTON_PRESS:
3892 gtk_entry_set_positions (entry, tmp_pos, tmp_pos);
3895 case GDK_2BUTTON_PRESS:
3896 priv->select_words = TRUE;
3897 gtk_entry_select_word (entry);
3900 case GDK_3BUTTON_PRESS:
3901 priv->select_lines = TRUE;
3902 gtk_entry_select_line (entry);
3909 start = MIN (priv->current_pos, priv->selection_bound);
3910 start = MIN (sel_start, start);
3912 end = MAX (priv->current_pos, priv->selection_bound);
3913 end = MAX (sel_end, end);
3915 if (tmp_pos == sel_start || tmp_pos == sel_end)
3916 extend_to_left = (tmp_pos == start);
3918 extend_to_left = (end == sel_end);
3921 gtk_entry_set_positions (entry, start, end);
3923 gtk_entry_set_positions (entry, end, start);
3926 else /* no shift key */
3927 switch (event->type)
3929 case GDK_BUTTON_PRESS:
3930 if (in_selection (entry, event->x + priv->scroll_offset))
3932 /* Click inside the selection - we'll either start a drag, or
3933 * clear the selection
3935 priv->in_drag = TRUE;
3936 priv->drag_start_x = event->x + priv->scroll_offset;
3937 priv->drag_start_y = event->y;
3940 gtk_editable_set_position (editable, tmp_pos);
3943 case GDK_2BUTTON_PRESS:
3944 /* We ALWAYS receive a GDK_BUTTON_PRESS immediately before
3945 * receiving a GDK_2BUTTON_PRESS so we need to reset
3946 * priv->in_drag which may have been set above
3948 priv->in_drag = FALSE;
3949 priv->select_words = TRUE;
3950 gtk_entry_select_word (entry);
3953 case GDK_3BUTTON_PRESS:
3954 /* We ALWAYS receive a GDK_BUTTON_PRESS immediately before
3955 * receiving a GDK_3BUTTON_PRESS so we need to reset
3956 * priv->in_drag which may have been set above
3958 priv->in_drag = FALSE;
3959 priv->select_lines = TRUE;
3960 gtk_entry_select_line (entry);
3969 else if (event->type == GDK_BUTTON_PRESS &&
3970 event->button == GDK_BUTTON_MIDDLE &&
3971 get_middle_click_paste (entry))
3975 priv->insert_pos = tmp_pos;
3976 gtk_entry_paste (entry, GDK_SELECTION_PRIMARY);
3981 gtk_widget_error_bell (widget);
3989 gtk_entry_button_release (GtkWidget *widget,
3990 GdkEventButton *event)
3992 GtkEntry *entry = GTK_ENTRY (widget);
3993 GtkEntryPrivate *priv = entry->priv;
3994 EntryIconInfo *icon_info = NULL;
3997 for (i = 0; i < MAX_ICONS; i++)
3999 icon_info = priv->icons[i];
4001 if (!icon_info || icon_info->insensitive)
4004 if (event->window == icon_info->window)
4006 icon_info->pressed = FALSE;
4008 if (should_prelight (entry, i) &&
4009 event->x >= 0 && event->y >= 0 &&
4010 event->x < gdk_window_get_width (icon_info->window) &&
4011 event->y < gdk_window_get_height (icon_info->window))
4013 icon_info->prelight = TRUE;
4014 gtk_widget_queue_draw (widget);
4017 if (!icon_info->nonactivatable)
4018 g_signal_emit (entry, signals[ICON_RELEASE], 0, i, event);
4024 if (event->window != priv->text_area || priv->button != event->button)
4029 gint tmp_pos = gtk_entry_find_position (entry, priv->drag_start_x);
4031 gtk_editable_set_position (GTK_EDITABLE (entry), tmp_pos);
4037 priv->device = NULL;
4039 gtk_entry_update_primary_selection (entry);
4045 _gtk_entry_get_selected_text (GtkEntry *entry)
4047 GtkEditable *editable = GTK_EDITABLE (entry);
4048 gint start_text, end_text;
4051 if (gtk_editable_get_selection_bounds (editable, &start_text, &end_text))
4052 text = gtk_editable_get_chars (editable, start_text, end_text);
4058 gtk_entry_motion_notify (GtkWidget *widget,
4059 GdkEventMotion *event)
4061 GtkEntry *entry = GTK_ENTRY (widget);
4062 GtkEntryPrivate *priv = entry->priv;
4063 EntryIconInfo *icon_info = NULL;
4067 for (i = 0; i < MAX_ICONS; i++)
4069 icon_info = priv->icons[i];
4071 if (!icon_info || icon_info->insensitive)
4074 if (event->window == icon_info->window)
4076 if (icon_info->pressed &&
4077 icon_info->target_list != NULL &&
4078 gtk_drag_check_threshold (widget,
4084 icon_info->in_drag = TRUE;
4085 icon_info->pressed = FALSE;
4086 gtk_drag_begin (widget,
4087 icon_info->target_list,
4097 if (priv->mouse_cursor_obscured)
4101 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
4102 gdk_window_set_cursor (priv->text_area, cursor);
4103 g_object_unref (cursor);
4104 priv->mouse_cursor_obscured = FALSE;
4107 if (event->window != priv->text_area || priv->button != GDK_BUTTON_PRIMARY)
4110 if (priv->select_lines)
4113 gdk_event_request_motions (event);
4117 if (gtk_entry_get_display_mode (entry) == DISPLAY_NORMAL &&
4118 gtk_drag_check_threshold (widget,
4119 priv->drag_start_x, priv->drag_start_y,
4120 event->x + priv->scroll_offset, event->y))
4122 GdkDragContext *context;
4123 GtkTargetList *target_list = gtk_target_list_new (NULL, 0);
4124 guint actions = priv->editable ? GDK_ACTION_COPY | GDK_ACTION_MOVE : GDK_ACTION_COPY;
4126 cairo_surface_t *surface;
4128 gtk_target_list_add_text_targets (target_list, 0);
4130 text = _gtk_entry_get_selected_text (entry);
4131 surface = _gtk_text_util_create_drag_icon (widget, text, -1);
4133 context = gtk_drag_begin (widget, target_list, actions,
4134 priv->button, (GdkEvent *)event);
4137 gtk_drag_set_icon_surface (context, surface);
4139 gtk_drag_set_icon_default (context);
4142 cairo_surface_destroy (surface);
4145 priv->in_drag = FALSE;
4147 priv->device = NULL;
4149 gtk_target_list_unref (target_list);
4156 else if (event->y >= gdk_window_get_height (priv->text_area))
4157 tmp_pos = gtk_entry_buffer_get_length (get_buffer (entry));
4159 tmp_pos = gtk_entry_find_position (entry, event->x + priv->scroll_offset);
4161 if (priv->select_words)
4164 gint old_min, old_max;
4167 min = gtk_entry_move_backward_word (entry, tmp_pos, TRUE);
4168 max = gtk_entry_move_forward_word (entry, tmp_pos, TRUE);
4170 pos = priv->current_pos;
4171 bound = priv->selection_bound;
4173 old_min = MIN(priv->current_pos, priv->selection_bound);
4174 old_max = MAX(priv->current_pos, priv->selection_bound);
4181 else if (old_max < max)
4186 else if (pos == old_min)
4188 if (priv->current_pos != min)
4193 if (priv->current_pos != max)
4197 gtk_entry_set_positions (entry, pos, bound);
4200 gtk_entry_set_positions (entry, tmp_pos, -1);
4207 set_invisible_cursor (GdkWindow *window)
4209 GdkDisplay *display;
4212 display = gdk_window_get_display (window);
4213 cursor = gdk_cursor_new_for_display (display, GDK_BLANK_CURSOR);
4215 gdk_window_set_cursor (window, cursor);
4217 g_object_unref (cursor);
4221 gtk_entry_obscure_mouse_cursor (GtkEntry *entry)
4223 GtkEntryPrivate *priv = entry->priv;
4225 if (priv->mouse_cursor_obscured)
4228 set_invisible_cursor (priv->text_area);
4230 priv->mouse_cursor_obscured = TRUE;
4234 gtk_entry_key_press (GtkWidget *widget,
4237 GtkEntry *entry = GTK_ENTRY (widget);
4238 GtkEntryPrivate *priv = entry->priv;
4240 gtk_entry_reset_blink_time (entry);
4241 gtk_entry_pend_cursor_blink (entry);
4245 if (gtk_im_context_filter_keypress (priv->im_context, event))
4247 gtk_entry_obscure_mouse_cursor (entry);
4248 priv->need_im_reset = TRUE;
4253 if (event->keyval == GDK_KEY_Return ||
4254 event->keyval == GDK_KEY_KP_Enter ||
4255 event->keyval == GDK_KEY_ISO_Enter ||
4256 event->keyval == GDK_KEY_Escape)
4258 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
4260 if (completion && completion->priv->completion_timeout)
4262 g_source_remove (completion->priv->completion_timeout);
4263 completion->priv->completion_timeout = 0;
4266 _gtk_entry_reset_im_context (entry);
4269 if (GTK_WIDGET_CLASS (gtk_entry_parent_class)->key_press_event (widget, event))
4270 /* Activate key bindings
4274 if (!priv->editable && event->length)
4275 gtk_widget_error_bell (widget);
4281 gtk_entry_key_release (GtkWidget *widget,
4284 GtkEntry *entry = GTK_ENTRY (widget);
4285 GtkEntryPrivate *priv = entry->priv;
4289 if (gtk_im_context_filter_keypress (priv->im_context, event))
4291 priv->need_im_reset = TRUE;
4296 return GTK_WIDGET_CLASS (gtk_entry_parent_class)->key_release_event (widget, event);
4300 gtk_entry_focus_in (GtkWidget *widget,
4301 GdkEventFocus *event)
4303 GtkEntry *entry = GTK_ENTRY (widget);
4304 GtkEntryPrivate *priv = entry->priv;
4307 gtk_widget_queue_draw (widget);
4309 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (widget));
4313 priv->need_im_reset = TRUE;
4314 gtk_im_context_focus_in (priv->im_context);
4315 keymap_state_changed (keymap, entry);
4316 g_signal_connect (keymap, "state-changed",
4317 G_CALLBACK (keymap_state_changed), entry);
4320 g_signal_connect (keymap, "direction-changed",
4321 G_CALLBACK (keymap_direction_changed), entry);
4323 if (gtk_entry_buffer_get_bytes (get_buffer (entry)) == 0 &&
4324 priv->placeholder_text != NULL)
4326 gtk_entry_recompute (entry);
4330 gtk_entry_reset_blink_time (entry);
4331 gtk_entry_check_cursor_blink (entry);
4338 gtk_entry_focus_out (GtkWidget *widget,
4339 GdkEventFocus *event)
4341 GtkEntry *entry = GTK_ENTRY (widget);
4342 GtkEntryPrivate *priv = entry->priv;
4343 GtkEntryCompletion *completion;
4346 gtk_widget_queue_draw (widget);
4348 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (widget));
4352 priv->need_im_reset = TRUE;
4353 gtk_im_context_focus_out (priv->im_context);
4354 remove_capslock_feedback (entry);
4357 if (gtk_entry_buffer_get_bytes (get_buffer (entry)) == 0 &&
4358 priv->placeholder_text != NULL)
4360 gtk_entry_recompute (entry);
4364 gtk_entry_check_cursor_blink (entry);
4367 g_signal_handlers_disconnect_by_func (keymap, keymap_state_changed, entry);
4368 g_signal_handlers_disconnect_by_func (keymap, keymap_direction_changed, entry);
4370 completion = gtk_entry_get_completion (entry);
4372 _gtk_entry_completion_popdown (completion);
4378 gtk_entry_grab_focus (GtkWidget *widget)
4380 GtkEntry *entry = GTK_ENTRY (widget);
4381 GtkEntryPrivate *priv = entry->priv;
4382 gboolean select_on_focus;
4384 GTK_WIDGET_CLASS (gtk_entry_parent_class)->grab_focus (widget);
4386 if (priv->editable && !priv->in_click)
4388 g_object_get (gtk_widget_get_settings (widget),
4389 "gtk-entry-select-on-focus",
4393 if (select_on_focus)
4394 gtk_editable_select_region (GTK_EDITABLE (widget), 0, -1);
4399 gtk_entry_direction_changed (GtkWidget *widget,
4400 GtkTextDirection previous_dir)
4402 GtkEntry *entry = GTK_ENTRY (widget);
4404 gtk_entry_recompute (entry);
4406 GTK_WIDGET_CLASS (gtk_entry_parent_class)->direction_changed (widget, previous_dir);
4410 gtk_entry_state_flags_changed (GtkWidget *widget,
4411 GtkStateFlags previous_state)
4413 GtkEntry *entry = GTK_ENTRY (widget);
4414 GtkEntryPrivate *priv = entry->priv;
4417 if (gtk_widget_get_realized (widget))
4419 if (gtk_widget_is_sensitive (widget))
4420 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
4424 gdk_window_set_cursor (priv->text_area, cursor);
4427 g_object_unref (cursor);
4429 priv->mouse_cursor_obscured = FALSE;
4431 update_cursors (widget);
4434 if (!gtk_widget_is_sensitive (widget))
4436 /* Clear any selection */
4437 gtk_editable_select_region (GTK_EDITABLE (entry), priv->current_pos, priv->current_pos);
4440 gtk_entry_update_cached_style_values (entry);
4444 gtk_entry_screen_changed (GtkWidget *widget,
4445 GdkScreen *old_screen)
4447 gtk_entry_recompute (GTK_ENTRY (widget));
4450 /* GtkEditable method implementations
4453 gtk_entry_insert_text (GtkEditable *editable,
4454 const gchar *new_text,
4455 gint new_text_length,
4458 g_object_ref (editable);
4461 * The incoming text may a password or other secret. We make sure
4462 * not to copy it into temporary buffers.
4465 g_signal_emit_by_name (editable, "insert-text", new_text, new_text_length, position);
4467 g_object_unref (editable);
4471 gtk_entry_delete_text (GtkEditable *editable,
4475 g_object_ref (editable);
4477 g_signal_emit_by_name (editable, "delete-text", start_pos, end_pos);
4479 g_object_unref (editable);
4483 gtk_entry_get_chars (GtkEditable *editable,
4487 GtkEntry *entry = GTK_ENTRY (editable);
4490 gint start_index, end_index;
4492 text = gtk_entry_buffer_get_text (get_buffer (entry));
4493 text_length = gtk_entry_buffer_get_length (get_buffer (entry));
4496 end_pos = text_length;
4498 start_pos = MIN (text_length, start_pos);
4499 end_pos = MIN (text_length, end_pos);
4501 start_index = g_utf8_offset_to_pointer (text, start_pos) - text;
4502 end_index = g_utf8_offset_to_pointer (text, end_pos) - text;
4504 return g_strndup (text + start_index, end_index - start_index);
4508 gtk_entry_real_set_position (GtkEditable *editable,
4511 GtkEntry *entry = GTK_ENTRY (editable);
4512 GtkEntryPrivate *priv = entry->priv;
4516 length = gtk_entry_buffer_get_length (get_buffer (entry));
4517 if (position < 0 || position > length)
4520 if (position != priv->current_pos ||
4521 position != priv->selection_bound)
4523 _gtk_entry_reset_im_context (entry);
4524 gtk_entry_set_positions (entry, position, position);
4529 gtk_entry_get_position (GtkEditable *editable)
4531 GtkEntry *entry = GTK_ENTRY (editable);
4532 GtkEntryPrivate *priv = entry->priv;
4534 return priv->current_pos;
4538 gtk_entry_set_selection_bounds (GtkEditable *editable,
4542 GtkEntry *entry = GTK_ENTRY (editable);
4545 length = gtk_entry_buffer_get_length (get_buffer (entry));
4551 _gtk_entry_reset_im_context (entry);
4553 gtk_entry_set_positions (entry,
4555 MIN (start, length));
4557 gtk_entry_update_primary_selection (entry);
4561 gtk_entry_get_selection_bounds (GtkEditable *editable,
4565 GtkEntry *entry = GTK_ENTRY (editable);
4566 GtkEntryPrivate *priv = entry->priv;
4568 *start = priv->selection_bound;
4569 *end = priv->current_pos;
4571 return (priv->selection_bound != priv->current_pos);
4575 icon_theme_changed (GtkEntry *entry)
4577 GtkEntryPrivate *priv = entry->priv;
4580 for (i = 0; i < MAX_ICONS; i++)
4582 EntryIconInfo *icon_info = priv->icons[i];
4583 if (icon_info != NULL)
4584 _gtk_icon_helper_invalidate (icon_info->icon_helper);
4587 gtk_widget_queue_draw (GTK_WIDGET (entry));
4591 gtk_entry_update_cached_style_values (GtkEntry *entry)
4593 GtkEntryPrivate *priv = entry->priv;
4595 gboolean interior_focus;
4597 gtk_widget_style_get (GTK_WIDGET (entry),
4598 "focus-line-width", &focus_width,
4599 "interior-focus", &interior_focus,
4601 priv->focus_width = focus_width;
4602 priv->interior_focus = interior_focus;
4604 if (!priv->invisible_char_set)
4606 gunichar ch = find_invisible_char (GTK_WIDGET (entry));
4608 if (priv->invisible_char != ch)
4610 priv->invisible_char = ch;
4611 g_object_notify (G_OBJECT (entry), "invisible-char");
4617 gtk_entry_style_updated (GtkWidget *widget)
4619 GtkEntry *entry = GTK_ENTRY (widget);
4621 GTK_WIDGET_CLASS (gtk_entry_parent_class)->style_updated (widget);
4623 gtk_entry_update_cached_style_values (entry);
4625 gtk_entry_recompute (entry);
4627 icon_theme_changed (entry);
4630 /* GtkCellEditable method implementations
4633 gtk_cell_editable_entry_activated (GtkEntry *entry, gpointer data)
4635 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4636 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4640 gtk_cell_editable_key_press_event (GtkEntry *entry,
4641 GdkEventKey *key_event,
4644 GtkEntryPrivate *priv = entry->priv;
4646 if (key_event->keyval == GDK_KEY_Escape)
4648 priv->editing_canceled = TRUE;
4649 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4650 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4655 /* override focus */
4656 if (key_event->keyval == GDK_KEY_Up || key_event->keyval == GDK_KEY_Down)
4658 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4659 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4668 gtk_entry_start_editing (GtkCellEditable *cell_editable,
4671 GtkEntry *entry = GTK_ENTRY (cell_editable);
4672 GtkEntryPrivate *priv = entry->priv;
4674 priv->is_cell_renderer = TRUE;
4676 g_signal_connect (cell_editable, "activate",
4677 G_CALLBACK (gtk_cell_editable_entry_activated), NULL);
4678 g_signal_connect (cell_editable, "key-press-event",
4679 G_CALLBACK (gtk_cell_editable_key_press_event), NULL);
4683 gtk_entry_password_hint_free (GtkEntryPasswordHint *password_hint)
4685 if (password_hint->source_id)
4686 g_source_remove (password_hint->source_id);
4688 g_slice_free (GtkEntryPasswordHint, password_hint);
4693 gtk_entry_remove_password_hint (gpointer data)
4695 GtkEntryPasswordHint *password_hint = g_object_get_qdata (data, quark_password_hint);
4696 password_hint->position = -1;
4698 /* Force the string to be redrawn, but now without a visible character */
4699 gtk_entry_recompute (GTK_ENTRY (data));
4703 /* Default signal handlers
4706 gtk_entry_real_insert_text (GtkEditable *editable,
4707 const gchar *new_text,
4708 gint new_text_length,
4714 n_chars = g_utf8_strlen (new_text, new_text_length);
4717 * The actual insertion into the buffer. This will end up firing the
4718 * following signal handlers: buffer_inserted_text(), buffer_notify_display_text(),
4719 * buffer_notify_text(), buffer_notify_length()
4721 begin_change (GTK_ENTRY (editable));
4723 n_inserted = gtk_entry_buffer_insert_text (get_buffer (GTK_ENTRY (editable)), *position, new_text, n_chars);
4725 end_change (GTK_ENTRY (editable));
4727 if (n_inserted != n_chars)
4728 gtk_widget_error_bell (GTK_WIDGET (editable));
4730 *position += n_inserted;
4734 gtk_entry_real_delete_text (GtkEditable *editable,
4739 * The actual deletion from the buffer. This will end up firing the
4740 * following signal handlers: buffer_deleted_text(), buffer_notify_display_text(),
4741 * buffer_notify_text(), buffer_notify_length()
4744 begin_change (GTK_ENTRY (editable));
4746 gtk_entry_buffer_delete_text (get_buffer (GTK_ENTRY (editable)), start_pos, end_pos - start_pos);
4748 end_change (GTK_ENTRY (editable));
4751 /* GtkEntryBuffer signal handlers
4754 buffer_inserted_text (GtkEntryBuffer *buffer,
4760 GtkEntryPrivate *priv = entry->priv;
4761 guint password_hint_timeout;
4763 gint selection_bound;
4765 current_pos = priv->current_pos;
4766 if (current_pos > position)
4767 current_pos += n_chars;
4769 selection_bound = priv->selection_bound;
4770 if (selection_bound > position)
4771 selection_bound += n_chars;
4773 gtk_entry_set_positions (entry, current_pos, selection_bound);
4775 /* Calculate the password hint if it needs to be displayed. */
4776 if (n_chars == 1 && !priv->visible)
4778 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
4779 "gtk-entry-password-hint-timeout", &password_hint_timeout,
4782 if (password_hint_timeout > 0)
4784 GtkEntryPasswordHint *password_hint = g_object_get_qdata (G_OBJECT (entry),
4785 quark_password_hint);
4788 password_hint = g_slice_new0 (GtkEntryPasswordHint);
4789 g_object_set_qdata_full (G_OBJECT (entry), quark_password_hint, password_hint,
4790 (GDestroyNotify)gtk_entry_password_hint_free);
4793 password_hint->position = position;
4794 if (password_hint->source_id)
4795 g_source_remove (password_hint->source_id);
4796 password_hint->source_id = gdk_threads_add_timeout (password_hint_timeout,
4797 (GSourceFunc)gtk_entry_remove_password_hint, entry);
4803 buffer_deleted_text (GtkEntryBuffer *buffer,
4808 GtkEntryPrivate *priv = entry->priv;
4809 guint end_pos = position + n_chars;
4810 gint selection_bound;
4813 current_pos = priv->current_pos;
4814 if (current_pos > position)
4815 current_pos -= MIN (current_pos, end_pos) - position;
4817 selection_bound = priv->selection_bound;
4818 if (selection_bound > position)
4819 selection_bound -= MIN (selection_bound, end_pos) - position;
4821 gtk_entry_set_positions (entry, current_pos, selection_bound);
4823 /* We might have deleted the selection */
4824 gtk_entry_update_primary_selection (entry);
4826 /* Disable the password hint if one exists. */
4829 GtkEntryPasswordHint *password_hint = g_object_get_qdata (G_OBJECT (entry),
4830 quark_password_hint);
4833 if (password_hint->source_id)
4834 g_source_remove (password_hint->source_id);
4835 password_hint->source_id = 0;
4836 password_hint->position = -1;
4842 buffer_notify_text (GtkEntryBuffer *buffer,
4846 gtk_entry_recompute (entry);
4847 emit_changed (entry);
4848 g_object_notify (G_OBJECT (entry), "text");
4852 buffer_notify_length (GtkEntryBuffer *buffer,
4856 g_object_notify (G_OBJECT (entry), "text-length");
4860 buffer_notify_max_length (GtkEntryBuffer *buffer,
4864 g_object_notify (G_OBJECT (entry), "max-length");
4868 buffer_connect_signals (GtkEntry *entry)
4870 g_signal_connect (get_buffer (entry), "inserted-text", G_CALLBACK (buffer_inserted_text), entry);
4871 g_signal_connect (get_buffer (entry), "deleted-text", G_CALLBACK (buffer_deleted_text), entry);
4872 g_signal_connect (get_buffer (entry), "notify::text", G_CALLBACK (buffer_notify_text), entry);
4873 g_signal_connect (get_buffer (entry), "notify::length", G_CALLBACK (buffer_notify_length), entry);
4874 g_signal_connect (get_buffer (entry), "notify::max-length", G_CALLBACK (buffer_notify_max_length), entry);
4878 buffer_disconnect_signals (GtkEntry *entry)
4880 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_inserted_text, entry);
4881 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_deleted_text, entry);
4882 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_text, entry);
4883 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_length, entry);
4884 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_max_length, entry);
4887 /* Compute the X position for an offset that corresponds to the "more important
4888 * cursor position for that offset. We use this when trying to guess to which
4889 * end of the selection we should go to when the user hits the left or
4893 get_better_cursor_x (GtkEntry *entry,
4896 GtkEntryPrivate *priv = entry->priv;
4897 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
4898 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
4899 gboolean split_cursor;
4901 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
4902 const gchar *text = pango_layout_get_text (layout);
4903 gint index = g_utf8_offset_to_pointer (text, offset) - text;
4905 PangoRectangle strong_pos, weak_pos;
4907 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
4908 "gtk-split-cursor", &split_cursor,
4911 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
4914 return strong_pos.x / PANGO_SCALE;
4916 return (keymap_direction == priv->resolved_dir) ? strong_pos.x / PANGO_SCALE : weak_pos.x / PANGO_SCALE;
4920 gtk_entry_move_cursor (GtkEntry *entry,
4921 GtkMovementStep step,
4923 gboolean extend_selection)
4925 GtkEntryPrivate *priv = entry->priv;
4926 gint new_pos = priv->current_pos;
4928 _gtk_entry_reset_im_context (entry);
4930 if (priv->current_pos != priv->selection_bound && !extend_selection)
4932 /* If we have a current selection and aren't extending it, move to the
4933 * start/or end of the selection as appropriate
4937 case GTK_MOVEMENT_VISUAL_POSITIONS:
4939 gint current_x = get_better_cursor_x (entry, priv->current_pos);
4940 gint bound_x = get_better_cursor_x (entry, priv->selection_bound);
4943 new_pos = current_x < bound_x ? priv->current_pos : priv->selection_bound;
4945 new_pos = current_x > bound_x ? priv->current_pos : priv->selection_bound;
4948 case GTK_MOVEMENT_LOGICAL_POSITIONS:
4949 case GTK_MOVEMENT_WORDS:
4951 new_pos = MIN (priv->current_pos, priv->selection_bound);
4953 new_pos = MAX (priv->current_pos, priv->selection_bound);
4955 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
4956 case GTK_MOVEMENT_PARAGRAPH_ENDS:
4957 case GTK_MOVEMENT_BUFFER_ENDS:
4958 new_pos = count < 0 ? 0 : gtk_entry_buffer_get_length (get_buffer (entry));
4960 case GTK_MOVEMENT_DISPLAY_LINES:
4961 case GTK_MOVEMENT_PARAGRAPHS:
4962 case GTK_MOVEMENT_PAGES:
4963 case GTK_MOVEMENT_HORIZONTAL_PAGES:
4971 case GTK_MOVEMENT_LOGICAL_POSITIONS:
4972 new_pos = gtk_entry_move_logically (entry, new_pos, count);
4974 case GTK_MOVEMENT_VISUAL_POSITIONS:
4975 new_pos = gtk_entry_move_visually (entry, new_pos, count);
4976 if (priv->current_pos == new_pos)
4978 if (!extend_selection)
4980 if (!gtk_widget_keynav_failed (GTK_WIDGET (entry),
4982 GTK_DIR_RIGHT : GTK_DIR_LEFT))
4984 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (entry));
4987 gtk_widget_child_focus (toplevel,
4989 GTK_DIR_RIGHT : GTK_DIR_LEFT);
4994 gtk_widget_error_bell (GTK_WIDGET (entry));
4998 case GTK_MOVEMENT_WORDS:
5001 new_pos = gtk_entry_move_forward_word (entry, new_pos, FALSE);
5006 new_pos = gtk_entry_move_backward_word (entry, new_pos, FALSE);
5009 if (priv->current_pos == new_pos)
5010 gtk_widget_error_bell (GTK_WIDGET (entry));
5012 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
5013 case GTK_MOVEMENT_PARAGRAPH_ENDS:
5014 case GTK_MOVEMENT_BUFFER_ENDS:
5015 new_pos = count < 0 ? 0 : gtk_entry_buffer_get_length (get_buffer (entry));
5016 if (priv->current_pos == new_pos)
5017 gtk_widget_error_bell (GTK_WIDGET (entry));
5019 case GTK_MOVEMENT_DISPLAY_LINES:
5020 case GTK_MOVEMENT_PARAGRAPHS:
5021 case GTK_MOVEMENT_PAGES:
5022 case GTK_MOVEMENT_HORIZONTAL_PAGES:
5027 if (extend_selection)
5028 gtk_editable_select_region (GTK_EDITABLE (entry), priv->selection_bound, new_pos);
5030 gtk_editable_set_position (GTK_EDITABLE (entry), new_pos);
5032 gtk_entry_pend_cursor_blink (entry);
5036 gtk_entry_insert_at_cursor (GtkEntry *entry,
5039 GtkEntryPrivate *priv = entry->priv;
5040 GtkEditable *editable = GTK_EDITABLE (entry);
5041 gint pos = priv->current_pos;
5045 _gtk_entry_reset_im_context (entry);
5047 gtk_editable_insert_text (editable, str, -1, &pos);
5048 gtk_editable_set_position (editable, pos);
5053 gtk_entry_delete_from_cursor (GtkEntry *entry,
5057 GtkEntryPrivate *priv = entry->priv;
5058 GtkEditable *editable = GTK_EDITABLE (entry);
5059 gint start_pos = priv->current_pos;
5060 gint end_pos = priv->current_pos;
5061 gint old_n_bytes = gtk_entry_buffer_get_bytes (get_buffer (entry));
5063 _gtk_entry_reset_im_context (entry);
5065 if (!priv->editable)
5067 gtk_widget_error_bell (GTK_WIDGET (entry));
5071 if (priv->selection_bound != priv->current_pos)
5073 gtk_editable_delete_selection (editable);
5079 case GTK_DELETE_CHARS:
5080 end_pos = gtk_entry_move_logically (entry, priv->current_pos, count);
5081 gtk_editable_delete_text (editable, MIN (start_pos, end_pos), MAX (start_pos, end_pos));
5083 case GTK_DELETE_WORDS:
5086 /* Move to end of current word, or if not on a word, end of previous word */
5087 end_pos = gtk_entry_move_backward_word (entry, end_pos, FALSE);
5088 end_pos = gtk_entry_move_forward_word (entry, end_pos, FALSE);
5092 /* Move to beginning of current word, or if not on a word, begining of next word */
5093 start_pos = gtk_entry_move_forward_word (entry, start_pos, FALSE);
5094 start_pos = gtk_entry_move_backward_word (entry, start_pos, FALSE);
5098 case GTK_DELETE_WORD_ENDS:
5101 start_pos = gtk_entry_move_backward_word (entry, start_pos, FALSE);
5106 end_pos = gtk_entry_move_forward_word (entry, end_pos, FALSE);
5109 gtk_editable_delete_text (editable, start_pos, end_pos);
5111 case GTK_DELETE_DISPLAY_LINE_ENDS:
5112 case GTK_DELETE_PARAGRAPH_ENDS:
5114 gtk_editable_delete_text (editable, 0, priv->current_pos);
5116 gtk_editable_delete_text (editable, priv->current_pos, -1);
5118 case GTK_DELETE_DISPLAY_LINES:
5119 case GTK_DELETE_PARAGRAPHS:
5120 gtk_editable_delete_text (editable, 0, -1);
5122 case GTK_DELETE_WHITESPACE:
5123 gtk_entry_delete_whitespace (entry);
5127 if (gtk_entry_buffer_get_bytes (get_buffer (entry)) == old_n_bytes)
5128 gtk_widget_error_bell (GTK_WIDGET (entry));
5130 gtk_entry_pend_cursor_blink (entry);
5134 gtk_entry_backspace (GtkEntry *entry)
5136 GtkEntryPrivate *priv = entry->priv;
5137 GtkEditable *editable = GTK_EDITABLE (entry);
5140 _gtk_entry_reset_im_context (entry);
5142 if (!priv->editable)
5144 gtk_widget_error_bell (GTK_WIDGET (entry));
5148 if (priv->selection_bound != priv->current_pos)
5150 gtk_editable_delete_selection (editable);
5154 prev_pos = gtk_entry_move_logically (entry, priv->current_pos, -1);
5156 if (prev_pos < priv->current_pos)
5158 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
5159 PangoLogAttr *log_attrs;
5162 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
5164 /* Deleting parts of characters */
5165 if (log_attrs[priv->current_pos].backspace_deletes_character)
5167 gchar *cluster_text;
5168 gchar *normalized_text;
5171 cluster_text = gtk_entry_get_display_text (entry, prev_pos,
5173 normalized_text = g_utf8_normalize (cluster_text,
5174 strlen (cluster_text),
5176 len = g_utf8_strlen (normalized_text, -1);
5178 gtk_editable_delete_text (editable, prev_pos, priv->current_pos);
5181 gint pos = priv->current_pos;
5183 gtk_editable_insert_text (editable, normalized_text,
5184 g_utf8_offset_to_pointer (normalized_text, len - 1) - normalized_text,
5186 gtk_editable_set_position (editable, pos);
5189 g_free (normalized_text);
5190 g_free (cluster_text);
5194 gtk_editable_delete_text (editable, prev_pos, priv->current_pos);
5201 gtk_widget_error_bell (GTK_WIDGET (entry));
5204 gtk_entry_pend_cursor_blink (entry);
5208 gtk_entry_copy_clipboard (GtkEntry *entry)
5210 GtkEntryPrivate *priv = entry->priv;
5211 GtkEditable *editable = GTK_EDITABLE (entry);
5215 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5219 gtk_widget_error_bell (GTK_WIDGET (entry));
5223 str = gtk_entry_get_display_text (entry, start, end);
5224 gtk_clipboard_set_text (gtk_widget_get_clipboard (GTK_WIDGET (entry),
5225 GDK_SELECTION_CLIPBOARD),
5232 gtk_entry_cut_clipboard (GtkEntry *entry)
5234 GtkEntryPrivate *priv = entry->priv;
5235 GtkEditable *editable = GTK_EDITABLE (entry);
5240 gtk_widget_error_bell (GTK_WIDGET (entry));
5244 gtk_entry_copy_clipboard (entry);
5248 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5249 gtk_editable_delete_text (editable, start, end);
5253 gtk_widget_error_bell (GTK_WIDGET (entry));
5258 gtk_entry_paste_clipboard (GtkEntry *entry)
5260 GtkEntryPrivate *priv = entry->priv;
5263 gtk_entry_paste (entry, GDK_SELECTION_CLIPBOARD);
5265 gtk_widget_error_bell (GTK_WIDGET (entry));
5269 gtk_entry_delete_cb (GtkEntry *entry)
5271 GtkEntryPrivate *priv = entry->priv;
5272 GtkEditable *editable = GTK_EDITABLE (entry);
5277 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5278 gtk_editable_delete_text (editable, start, end);
5283 gtk_entry_toggle_overwrite (GtkEntry *entry)
5285 GtkEntryPrivate *priv = entry->priv;
5287 priv->overwrite_mode = !priv->overwrite_mode;
5288 gtk_entry_pend_cursor_blink (entry);
5289 gtk_widget_queue_draw (GTK_WIDGET (entry));
5293 gtk_entry_select_all (GtkEntry *entry)
5295 gtk_entry_select_line (entry);
5299 gtk_entry_real_activate (GtkEntry *entry)
5301 GtkEntryPrivate *priv = entry->priv;
5303 GtkWidget *default_widget, *focus_widget;
5304 GtkWidget *toplevel;
5307 widget = GTK_WIDGET (entry);
5309 if (priv->activates_default)
5311 toplevel = gtk_widget_get_toplevel (widget);
5312 if (GTK_IS_WINDOW (toplevel))
5314 window = GTK_WINDOW (toplevel);
5318 default_widget = gtk_window_get_default_widget (window);
5319 focus_widget = gtk_window_get_focus (window);
5320 if (widget != default_widget &&
5321 !(widget == focus_widget && (!default_widget || !gtk_widget_get_sensitive (default_widget))))
5322 gtk_window_activate_default (window);
5329 keymap_direction_changed (GdkKeymap *keymap,
5332 gtk_entry_recompute (entry);
5335 /* IM Context Callbacks
5339 gtk_entry_commit_cb (GtkIMContext *context,
5343 GtkEntryPrivate *priv = entry->priv;
5346 gtk_entry_enter_text (entry, str);
5350 gtk_entry_preedit_changed_cb (GtkIMContext *context,
5353 GtkEntryPrivate *priv = entry->priv;
5357 gchar *preedit_string;
5360 gtk_im_context_get_preedit_string (priv->im_context,
5361 &preedit_string, NULL,
5363 g_signal_emit (entry, signals[PREEDIT_CHANGED], 0, preedit_string);
5364 priv->preedit_length = strlen (preedit_string);
5365 cursor_pos = CLAMP (cursor_pos, 0, g_utf8_strlen (preedit_string, -1));
5366 priv->preedit_cursor = cursor_pos;
5367 g_free (preedit_string);
5369 gtk_entry_recompute (entry);
5374 gtk_entry_retrieve_surrounding_cb (GtkIMContext *context,
5377 GtkEntryPrivate *priv = entry->priv;
5380 /* XXXX ??? does this even make sense when text is not visible? Should we return FALSE? */
5381 text = gtk_entry_get_display_text (entry, 0, -1);
5382 gtk_im_context_set_surrounding (context, text, strlen (text), /* Length in bytes */
5383 g_utf8_offset_to_pointer (text, priv->current_pos) - text);
5390 gtk_entry_delete_surrounding_cb (GtkIMContext *slave,
5395 GtkEntryPrivate *priv = entry->priv;
5398 gtk_editable_delete_text (GTK_EDITABLE (entry),
5399 priv->current_pos + offset,
5400 priv->current_pos + offset + n_chars);
5405 /* Internal functions
5408 /* Used for im_commit_cb and inserting Unicode chars */
5410 gtk_entry_enter_text (GtkEntry *entry,
5413 GtkEntryPrivate *priv = entry->priv;
5414 GtkEditable *editable = GTK_EDITABLE (entry);
5416 gboolean old_need_im_reset;
5418 old_need_im_reset = priv->need_im_reset;
5419 priv->need_im_reset = FALSE;
5421 if (gtk_editable_get_selection_bounds (editable, NULL, NULL))
5422 gtk_editable_delete_selection (editable);
5425 if (priv->overwrite_mode)
5426 gtk_entry_delete_from_cursor (entry, GTK_DELETE_CHARS, 1);
5429 tmp_pos = priv->current_pos;
5430 gtk_editable_insert_text (editable, str, strlen (str), &tmp_pos);
5431 gtk_editable_set_position (editable, tmp_pos);
5433 priv->need_im_reset = old_need_im_reset;
5436 /* All changes to priv->current_pos and priv->selection_bound
5437 * should go through this function.
5440 gtk_entry_set_positions (GtkEntry *entry,
5442 gint selection_bound)
5444 GtkEntryPrivate *priv = entry->priv;
5445 gboolean changed = FALSE;
5447 g_object_freeze_notify (G_OBJECT (entry));
5449 if (current_pos != -1 &&
5450 priv->current_pos != current_pos)
5452 priv->current_pos = current_pos;
5455 g_object_notify (G_OBJECT (entry), "cursor-position");
5458 if (selection_bound != -1 &&
5459 priv->selection_bound != selection_bound)
5461 priv->selection_bound = selection_bound;
5464 g_object_notify (G_OBJECT (entry), "selection-bound");
5467 g_object_thaw_notify (G_OBJECT (entry));
5471 gtk_entry_move_adjustments (entry);
5472 gtk_entry_recompute (entry);
5477 gtk_entry_reset_layout (GtkEntry *entry)
5479 GtkEntryPrivate *priv = entry->priv;
5481 if (priv->cached_layout)
5483 g_object_unref (priv->cached_layout);
5484 priv->cached_layout = NULL;
5489 update_im_cursor_location (GtkEntry *entry)
5491 GtkEntryPrivate *priv = entry->priv;
5494 gint strong_xoffset;
5495 gint area_width, area_height;
5497 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
5498 gtk_entry_get_text_area_size (entry, NULL, NULL, &area_width, &area_height);
5500 strong_xoffset = strong_x - priv->scroll_offset;
5501 if (strong_xoffset < 0)
5505 else if (strong_xoffset > area_width)
5507 strong_xoffset = area_width;
5509 area.x = strong_xoffset;
5512 area.height = area_height;
5514 gtk_im_context_set_cursor_location (priv->im_context, &area);
5518 recompute_idle_func (gpointer data)
5520 GtkEntry *entry = GTK_ENTRY (data);
5521 GtkEntryPrivate *priv = entry->priv;
5523 priv->recompute_idle = 0;
5525 if (gtk_widget_has_screen (GTK_WIDGET (entry)))
5527 gtk_entry_adjust_scroll (entry);
5528 gtk_widget_queue_draw (GTK_WIDGET (entry));
5530 update_im_cursor_location (entry);
5537 gtk_entry_recompute (GtkEntry *entry)
5539 GtkEntryPrivate *priv = entry->priv;
5541 gtk_entry_reset_layout (entry);
5542 gtk_entry_check_cursor_blink (entry);
5544 if (!priv->recompute_idle)
5546 priv->recompute_idle = gdk_threads_add_idle_full (G_PRIORITY_HIGH_IDLE + 15, /* between resize and redraw */
5547 recompute_idle_func, entry, NULL);
5552 gtk_entry_get_placeholder_text_color (GtkEntry *entry,
5555 GtkWidget *widget = GTK_WIDGET (entry);
5556 GtkStyleContext *context;
5557 GdkRGBA fg = { 0.5, 0.5, 0.5 };
5559 context = gtk_widget_get_style_context (widget);
5560 gtk_style_context_lookup_color (context, "placeholder_text_color", &fg);
5562 color->red = CLAMP (fg.red * 65535. + 0.5, 0, 65535);
5563 color->green = CLAMP (fg.green * 65535. + 0.5, 0, 65535);
5564 color->blue = CLAMP (fg.blue * 65535. + 0.5, 0, 65535);
5567 static inline gboolean
5568 show_placeholder_text (GtkEntry *entry)
5570 GtkEntryPrivate *priv = entry->priv;
5572 if (!gtk_widget_has_focus (GTK_WIDGET (entry)) &&
5573 gtk_entry_buffer_get_bytes (get_buffer (entry)) == 0 &&
5574 priv->placeholder_text != NULL)
5580 static PangoLayout *
5581 gtk_entry_create_layout (GtkEntry *entry,
5582 gboolean include_preedit)
5584 GtkEntryPrivate *priv = entry->priv;
5585 GtkWidget *widget = GTK_WIDGET (entry);
5586 PangoLayout *layout = gtk_widget_create_pango_layout (widget, NULL);
5587 PangoAttrList *tmp_attrs = pango_attr_list_new ();
5588 gboolean placeholder_layout = show_placeholder_text (entry);
5590 gchar *preedit_string = NULL;
5591 gint preedit_length = 0;
5592 PangoAttrList *preedit_attrs = NULL;
5597 pango_layout_set_single_paragraph_mode (layout, TRUE);
5599 display = placeholder_layout ? g_strdup (priv->placeholder_text) : gtk_entry_get_display_text (entry, 0, -1);
5600 n_bytes = strlen (display);
5602 if (!placeholder_layout && include_preedit)
5604 gtk_im_context_get_preedit_string (priv->im_context,
5605 &preedit_string, &preedit_attrs, NULL);
5606 preedit_length = priv->preedit_length;
5608 else if (placeholder_layout)
5611 PangoAttribute *attr;
5613 gtk_entry_get_placeholder_text_color (entry, &color);
5614 attr = pango_attr_foreground_new (color.red, color.green, color.blue);
5615 attr->start_index = 0;
5616 attr->end_index = G_MAXINT;
5617 pango_attr_list_insert (tmp_attrs, attr);
5622 GString *tmp_string = g_string_new (display);
5623 gint cursor_index = g_utf8_offset_to_pointer (display, priv->current_pos) - display;
5625 g_string_insert (tmp_string, cursor_index, preedit_string);
5627 pango_layout_set_text (layout, tmp_string->str, tmp_string->len);
5629 pango_attr_list_splice (tmp_attrs, preedit_attrs,
5630 cursor_index, preedit_length);
5632 g_string_free (tmp_string, TRUE);
5636 PangoDirection pango_dir;
5638 if (gtk_entry_get_display_mode (entry) == DISPLAY_NORMAL)
5639 pango_dir = pango_find_base_dir (display, n_bytes);
5641 pango_dir = PANGO_DIRECTION_NEUTRAL;
5643 if (pango_dir == PANGO_DIRECTION_NEUTRAL)
5645 if (gtk_widget_has_focus (widget))
5647 GdkDisplay *display = gtk_widget_get_display (widget);
5648 GdkKeymap *keymap = gdk_keymap_get_for_display (display);
5649 if (gdk_keymap_get_direction (keymap) == PANGO_DIRECTION_RTL)
5650 pango_dir = PANGO_DIRECTION_RTL;
5652 pango_dir = PANGO_DIRECTION_LTR;
5656 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
5657 pango_dir = PANGO_DIRECTION_RTL;
5659 pango_dir = PANGO_DIRECTION_LTR;
5663 pango_context_set_base_dir (gtk_widget_get_pango_context (widget),
5666 priv->resolved_dir = pango_dir;
5668 pango_layout_set_text (layout, display, n_bytes);
5671 pango_layout_set_attributes (layout, tmp_attrs);
5673 g_free (preedit_string);
5677 pango_attr_list_unref (preedit_attrs);
5679 pango_attr_list_unref (tmp_attrs);
5684 static PangoLayout *
5685 gtk_entry_ensure_layout (GtkEntry *entry,
5686 gboolean include_preedit)
5688 GtkEntryPrivate *priv = entry->priv;
5690 if (priv->preedit_length > 0 &&
5691 !include_preedit != !priv->cache_includes_preedit)
5692 gtk_entry_reset_layout (entry);
5694 if (!priv->cached_layout)
5696 priv->cached_layout = gtk_entry_create_layout (entry, include_preedit);
5697 priv->cache_includes_preedit = include_preedit;
5700 return priv->cached_layout;
5704 get_layout_position (GtkEntry *entry,
5708 GtkEntryPrivate *priv = entry->priv;
5709 PangoLayout *layout;
5710 PangoRectangle logical_rect;
5711 gint area_width, area_height;
5713 PangoLayoutLine *line;
5715 layout = gtk_entry_ensure_layout (entry, TRUE);
5717 gtk_entry_get_text_area_size (entry, NULL, NULL, &area_width, &area_height);
5718 area_height = PANGO_SCALE * area_height;
5720 line = pango_layout_get_lines_readonly (layout)->data;
5721 pango_layout_line_get_extents (line, NULL, &logical_rect);
5723 /* Align primarily for locale's ascent/descent */
5724 y_pos = ((area_height - priv->ascent - priv->descent) / 2 +
5725 priv->ascent + logical_rect.y);
5727 /* Now see if we need to adjust to fit in actual drawn string */
5728 if (logical_rect.height > area_height)
5729 y_pos = (area_height - logical_rect.height) / 2;
5732 else if (y_pos + logical_rect.height > area_height)
5733 y_pos = area_height - logical_rect.height;
5735 y_pos = y_pos / PANGO_SCALE;
5738 *x = - priv->scroll_offset;
5745 draw_text_with_color (GtkEntry *entry,
5747 GdkRGBA *default_color)
5749 GtkEntryPrivate *priv = entry->priv;
5750 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
5753 gint start_pos, end_pos;
5755 widget = GTK_WIDGET (entry);
5759 get_layout_position (entry, &x, &y);
5761 cairo_move_to (cr, x, y);
5762 gdk_cairo_set_source_rgba (cr, default_color);
5763 pango_cairo_show_layout (cr, layout);
5765 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start_pos, &end_pos))
5769 PangoRectangle logical_rect;
5770 GdkRGBA selection_color, text_color;
5771 GtkStyleContext *context;
5772 GtkStateFlags state;
5774 context = gtk_widget_get_style_context (widget);
5775 pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
5776 gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
5778 state = gtk_widget_get_state_flags (widget);
5779 state |= GTK_STATE_FLAG_SELECTED;
5781 gtk_style_context_get_background_color (context, state, &selection_color);
5782 gtk_style_context_get_color (context, state, &text_color);
5784 for (i = 0; i < n_ranges; ++i)
5785 cairo_rectangle (cr,
5786 - priv->scroll_offset + ranges[2 * i],
5789 logical_rect.height);
5793 gdk_cairo_set_source_rgba (cr, &selection_color);
5796 cairo_move_to (cr, x, y);
5797 gdk_cairo_set_source_rgba (cr, &text_color);
5798 pango_cairo_show_layout (cr, layout);
5806 gtk_entry_draw_text (GtkEntry *entry,
5809 GtkEntryPrivate *priv = entry->priv;
5810 GtkWidget *widget = GTK_WIDGET (entry);
5811 GtkStateFlags state = 0;
5812 GdkRGBA text_color, bar_text_color;
5813 GtkStyleContext *context;
5815 gint progress_x, progress_y, progress_width, progress_height;
5816 gint clip_width, clip_height;
5818 /* Nothing to display at all */
5819 if (gtk_entry_get_display_mode (entry) == DISPLAY_BLANK)
5822 state = gtk_widget_get_state_flags (widget);
5823 context = gtk_widget_get_style_context (widget);
5825 gtk_style_context_get_color (context, state, &text_color);
5827 /* Get foreground color for progressbars */
5828 gtk_entry_prepare_context_for_progress (entry, context);
5829 gtk_style_context_get_color (context, state, &bar_text_color);
5830 gtk_style_context_restore (context);
5832 get_progress_area (widget,
5833 &progress_x, &progress_y,
5834 &progress_width, &progress_height);
5838 clip_width = gdk_window_get_width (priv->text_area);
5839 clip_height = gdk_window_get_height (priv->text_area);
5840 cairo_rectangle (cr, 0, 0, clip_width, clip_height);
5843 /* If the color is the same, or the progress area has a zero
5844 * size, then we only need to draw once. */
5845 if (gdk_rgba_equal (&text_color, &bar_text_color) ||
5846 ((progress_width == 0) || (progress_height == 0)))
5848 draw_text_with_color (entry, cr, &text_color);
5852 int frame_x, frame_y, area_x, area_y;
5854 width = gdk_window_get_width (priv->text_area);
5855 height = gdk_window_get_height (priv->text_area);
5859 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
5860 cairo_rectangle (cr, 0, 0, width, height);
5862 /* progres area is frame-relative, we need it text-area window
5864 get_frame_size (entry, TRUE, &frame_x, &frame_y, NULL, NULL);
5865 gdk_window_get_position (priv->text_area, &area_x, &area_y);
5866 progress_x += frame_x - area_x;
5867 progress_y += frame_y - area_y;
5869 cairo_rectangle (cr, progress_x, progress_y,
5870 progress_width, progress_height);
5872 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_WINDING);
5874 draw_text_with_color (entry, cr, &text_color);
5879 cairo_rectangle (cr, progress_x, progress_y,
5880 progress_width, progress_height);
5883 draw_text_with_color (entry, cr, &bar_text_color);
5892 gtk_entry_draw_cursor (GtkEntry *entry,
5896 GtkEntryPrivate *priv = entry->priv;
5897 GtkWidget *widget = GTK_WIDGET (entry);
5898 GtkStyleContext *context;
5899 PangoRectangle cursor_rect;
5902 gboolean block_at_line_end;
5903 PangoLayout *layout;
5907 context = gtk_widget_get_style_context (widget);
5909 layout = gtk_entry_ensure_layout (entry, TRUE);
5910 text = pango_layout_get_text (layout);
5911 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos + priv->preedit_cursor) - text;
5912 get_layout_position (entry, &x, &y);
5914 if (!priv->overwrite_mode)
5917 block = _gtk_text_util_get_block_cursor_location (layout,
5918 cursor_index, &cursor_rect, &block_at_line_end);
5922 gtk_render_insertion_cursor (context, cr,
5924 layout, cursor_index, priv->resolved_dir);
5926 else /* overwrite_mode */
5928 GdkRGBA cursor_color;
5933 rect.x = PANGO_PIXELS (cursor_rect.x) + x;
5934 rect.y = PANGO_PIXELS (cursor_rect.y) + y;
5935 rect.width = PANGO_PIXELS (cursor_rect.width);
5936 rect.height = PANGO_PIXELS (cursor_rect.height);
5938 _gtk_style_context_get_cursor_color (context, &cursor_color, NULL);
5939 gdk_cairo_set_source_rgba (cr, &cursor_color);
5940 gdk_cairo_rectangle (cr, &rect);
5943 if (!block_at_line_end)
5945 GtkStateFlags state;
5948 state = gtk_widget_get_state_flags (widget);
5949 gtk_style_context_get_background_color (context, state, &color);
5951 gdk_cairo_rectangle (cr, &rect);
5953 cairo_move_to (cr, x, y);
5954 gdk_cairo_set_source_rgba (cr, &color);
5955 pango_cairo_show_layout (cr, layout);
5963 _gtk_entry_reset_im_context (GtkEntry *entry)
5965 GtkEntryPrivate *priv = entry->priv;
5967 if (priv->need_im_reset)
5969 priv->need_im_reset = FALSE;
5970 gtk_im_context_reset (priv->im_context);
5975 * gtk_entry_reset_im_context:
5976 * @entry: a #GtkEntry
5978 * Reset the input method context of the entry if needed.
5980 * This can be necessary in the case where modifying the buffer
5981 * would confuse on-going input method behavior.
5986 gtk_entry_reset_im_context (GtkEntry *entry)
5988 g_return_if_fail (GTK_IS_ENTRY (entry));
5990 _gtk_entry_reset_im_context (entry);
5994 * gtk_entry_im_context_filter_keypress:
5995 * @entry: a #GtkEntry
5996 * @event: (type Gdk.EventKey): the key event
5998 * Allow the #GtkEntry input method to internally handle key press
5999 * and release events. If this function returns %TRUE, then no further
6000 * processing should be done for this key event. See
6001 * gtk_im_context_filter_keypress().
6003 * Note that you are expected to call this function from your handler
6004 * when overriding key event handling. This is needed in the case when
6005 * you need to insert your own key handling between the input method
6006 * and the default key event handling of the #GtkEntry.
6007 * See gtk_text_view_reset_im_context() for an example of use.
6009 * Return value: %TRUE if the input method handled the key event.
6014 gtk_entry_im_context_filter_keypress (GtkEntry *entry,
6017 GtkEntryPrivate *priv;
6019 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
6023 return gtk_im_context_filter_keypress (priv->im_context, event);
6027 _gtk_entry_get_im_context (GtkEntry *entry)
6029 return entry->priv->im_context;
6033 gtk_entry_find_position (GtkEntry *entry,
6036 GtkEntryPrivate *priv = entry->priv;
6037 PangoLayout *layout;
6038 PangoLayoutLine *line;
6045 layout = gtk_entry_ensure_layout (entry, TRUE);
6046 text = pango_layout_get_text (layout);
6047 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos) - text;
6049 line = pango_layout_get_lines_readonly (layout)->data;
6050 pango_layout_line_x_to_index (line, x * PANGO_SCALE, &index, &trailing);
6052 if (index >= cursor_index && priv->preedit_length)
6054 if (index >= cursor_index + priv->preedit_length)
6055 index -= priv->preedit_length;
6058 index = cursor_index;
6063 pos = g_utf8_pointer_to_offset (text, text + index);
6070 gtk_entry_get_cursor_locations (GtkEntry *entry,
6075 GtkEntryPrivate *priv = entry->priv;
6076 DisplayMode mode = gtk_entry_get_display_mode (entry);
6078 /* Nothing to display at all, so no cursor is relevant */
6079 if (mode == DISPLAY_BLANK)
6089 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
6090 const gchar *text = pango_layout_get_text (layout);
6091 PangoRectangle strong_pos, weak_pos;
6094 if (type == CURSOR_STANDARD)
6096 index = g_utf8_offset_to_pointer (text, priv->current_pos + priv->preedit_cursor) - text;
6098 else /* type == CURSOR_DND */
6100 index = g_utf8_offset_to_pointer (text, priv->dnd_position) - text;
6102 if (priv->dnd_position > priv->current_pos)
6104 if (mode == DISPLAY_NORMAL)
6105 index += priv->preedit_length;
6108 gint preedit_len_chars = g_utf8_strlen (text, -1) - gtk_entry_buffer_get_length (get_buffer (entry));
6109 index += preedit_len_chars * g_unichar_to_utf8 (priv->invisible_char, NULL);
6114 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
6117 *strong_x = strong_pos.x / PANGO_SCALE;
6120 *weak_x = weak_pos.x / PANGO_SCALE;
6125 gtk_entry_adjust_scroll (GtkEntry *entry)
6127 GtkEntryPrivate *priv = entry->priv;
6128 gint min_offset, max_offset;
6129 gint text_area_width, text_width;
6130 gint strong_x, weak_x;
6131 gint strong_xoffset, weak_xoffset;
6133 PangoLayout *layout;
6134 PangoLayoutLine *line;
6135 PangoRectangle logical_rect;
6137 if (!gtk_widget_get_realized (GTK_WIDGET (entry)))
6140 text_area_width = gdk_window_get_width (priv->text_area);
6142 if (text_area_width < 0)
6143 text_area_width = 0;
6145 layout = gtk_entry_ensure_layout (entry, TRUE);
6146 line = pango_layout_get_lines_readonly (layout)->data;
6148 pango_layout_line_get_extents (line, NULL, &logical_rect);
6150 /* Display as much text as we can */
6152 if (priv->resolved_dir == PANGO_DIRECTION_LTR)
6153 xalign = priv->xalign;
6155 xalign = 1.0 - priv->xalign;
6157 text_width = PANGO_PIXELS(logical_rect.width);
6159 if (text_width > text_area_width)
6162 max_offset = text_width - text_area_width;
6166 min_offset = (text_width - text_area_width) * xalign;
6167 max_offset = min_offset;
6170 priv->scroll_offset = CLAMP (priv->scroll_offset, min_offset, max_offset);
6172 /* And make sure cursors are on screen. Note that the cursor is
6173 * actually drawn one pixel into the INNER_BORDER space on
6174 * the right, when the scroll is at the utmost right. This
6175 * looks better to to me than confining the cursor inside the
6176 * border entirely, though it means that the cursor gets one
6177 * pixel closer to the edge of the widget on the right than
6178 * on the left. This might need changing if one changed
6179 * INNER_BORDER from 2 to 1, as one would do on a
6180 * small-screen-real-estate display.
6182 * We always make sure that the strong cursor is on screen, and
6183 * put the weak cursor on screen if possible.
6186 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, &weak_x);
6188 strong_xoffset = strong_x - priv->scroll_offset;
6190 if (strong_xoffset < 0)
6192 priv->scroll_offset += strong_xoffset;
6195 else if (strong_xoffset > text_area_width)
6197 priv->scroll_offset += strong_xoffset - text_area_width;
6198 strong_xoffset = text_area_width;
6201 weak_xoffset = weak_x - priv->scroll_offset;
6203 if (weak_xoffset < 0 && strong_xoffset - weak_xoffset <= text_area_width)
6205 priv->scroll_offset += weak_xoffset;
6207 else if (weak_xoffset > text_area_width &&
6208 strong_xoffset - (weak_xoffset - text_area_width) >= 0)
6210 priv->scroll_offset += weak_xoffset - text_area_width;
6213 g_object_notify (G_OBJECT (entry), "scroll-offset");
6217 gtk_entry_move_adjustments (GtkEntry *entry)
6219 GtkWidget *widget = GTK_WIDGET (entry);
6220 GtkAllocation allocation;
6221 GtkAdjustment *adjustment;
6222 PangoContext *context;
6223 PangoFontMetrics *metrics;
6224 GtkStyleContext *style_context;
6225 GtkStateFlags state;
6230 adjustment = g_object_get_qdata (G_OBJECT (entry), quark_cursor_hadjustment);
6234 gtk_widget_get_allocation (widget, &allocation);
6236 /* Cursor position, layout offset, border width, and widget allocation */
6237 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &x, NULL);
6238 get_layout_position (entry, &layout_x, NULL);
6239 _gtk_entry_get_borders (entry, &borders);
6240 x += allocation.x + layout_x + borders.left;
6242 /* Approximate width of a char, so user can see what is ahead/behind */
6243 context = gtk_widget_get_pango_context (widget);
6244 style_context = gtk_widget_get_style_context (widget);
6245 state = gtk_widget_get_state_flags (widget);
6247 metrics = pango_context_get_metrics (context,
6248 gtk_style_context_get_font (style_context, state),
6249 pango_context_get_language (context));
6250 char_width = pango_font_metrics_get_approximate_char_width (metrics) / PANGO_SCALE;
6253 gtk_adjustment_clamp_page (adjustment,
6254 x - (char_width + 1), /* one char + one pixel before */
6255 x + (char_width + 2)); /* one char + cursor + one pixel after */
6259 gtk_entry_move_visually (GtkEntry *entry,
6263 GtkEntryPrivate *priv = entry->priv;
6265 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6268 text = pango_layout_get_text (layout);
6270 index = g_utf8_offset_to_pointer (text, start) - text;
6274 int new_index, new_trailing;
6275 gboolean split_cursor;
6278 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
6279 "gtk-split-cursor", &split_cursor,
6286 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
6287 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
6289 strong = keymap_direction == priv->resolved_dir;
6294 pango_layout_move_cursor_visually (layout, strong, index, 0, 1, &new_index, &new_trailing);
6299 pango_layout_move_cursor_visually (layout, strong, index, 0, -1, &new_index, &new_trailing);
6305 else if (new_index != G_MAXINT)
6308 while (new_trailing--)
6309 index = g_utf8_next_char (text + index) - text;
6312 return g_utf8_pointer_to_offset (text, text + index);
6316 gtk_entry_move_logically (GtkEntry *entry,
6320 gint new_pos = start;
6323 length = gtk_entry_buffer_get_length (get_buffer (entry));
6325 /* Prevent any leak of information */
6326 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6328 new_pos = CLAMP (start + count, 0, length);
6332 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6333 PangoLogAttr *log_attrs;
6336 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6338 while (count > 0 && new_pos < length)
6342 while (new_pos < length && !log_attrs[new_pos].is_cursor_position);
6346 while (count < 0 && new_pos > 0)
6350 while (new_pos > 0 && !log_attrs[new_pos].is_cursor_position);
6362 gtk_entry_move_forward_word (GtkEntry *entry,
6364 gboolean allow_whitespace)
6366 gint new_pos = start;
6369 length = gtk_entry_buffer_get_length (get_buffer (entry));
6371 /* Prevent any leak of information */
6372 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6376 else if (new_pos < length)
6378 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6379 PangoLogAttr *log_attrs;
6382 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6384 /* Find the next word boundary */
6386 while (new_pos < n_attrs - 1 && !(log_attrs[new_pos].is_word_end ||
6387 (log_attrs[new_pos].is_word_start && allow_whitespace)))
6398 gtk_entry_move_backward_word (GtkEntry *entry,
6400 gboolean allow_whitespace)
6402 gint new_pos = start;
6404 /* Prevent any leak of information */
6405 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6411 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6412 PangoLogAttr *log_attrs;
6415 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6417 new_pos = start - 1;
6419 /* Find the previous word boundary */
6420 while (new_pos > 0 && !(log_attrs[new_pos].is_word_start ||
6421 (log_attrs[new_pos].is_word_end && allow_whitespace)))
6431 gtk_entry_delete_whitespace (GtkEntry *entry)
6433 GtkEntryPrivate *priv = entry->priv;
6434 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6435 PangoLogAttr *log_attrs;
6439 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6441 start = end = priv->current_pos;
6443 while (start > 0 && log_attrs[start-1].is_white)
6446 while (end < n_attrs && log_attrs[end].is_white)
6452 gtk_editable_delete_text (GTK_EDITABLE (entry), start, end);
6457 gtk_entry_select_word (GtkEntry *entry)
6459 GtkEntryPrivate *priv = entry->priv;
6460 gint start_pos = gtk_entry_move_backward_word (entry, priv->current_pos, TRUE);
6461 gint end_pos = gtk_entry_move_forward_word (entry, priv->current_pos, TRUE);
6463 gtk_editable_select_region (GTK_EDITABLE (entry), start_pos, end_pos);
6467 gtk_entry_select_line (GtkEntry *entry)
6469 gtk_editable_select_region (GTK_EDITABLE (entry), 0, -1);
6473 truncate_multiline (const gchar *text)
6478 text[length] && text[length] != '\n' && text[length] != '\r';
6485 paste_received (GtkClipboard *clipboard,
6489 GtkEntry *entry = GTK_ENTRY (data);
6490 GtkEditable *editable = GTK_EDITABLE (entry);
6491 GtkEntryPrivate *priv = entry->priv;
6493 if (priv->button == GDK_BUTTON_MIDDLE)
6495 gint pos, start, end;
6496 pos = priv->insert_pos;
6497 gtk_editable_get_selection_bounds (editable, &start, &end);
6498 if (!((start <= pos && pos <= end) || (end <= pos && pos <= start)))
6499 gtk_editable_select_region (editable, pos, pos);
6504 gint pos, start, end;
6506 gboolean popup_completion;
6507 GtkEntryCompletion *completion;
6509 completion = gtk_entry_get_completion (entry);
6511 if (priv->truncate_multiline)
6512 length = truncate_multiline (text);
6514 /* only complete if the selection is at the end */
6515 popup_completion = (gtk_entry_buffer_get_length (get_buffer (entry)) ==
6516 MAX (priv->current_pos, priv->selection_bound));
6520 if (gtk_widget_get_mapped (completion->priv->popup_window))
6521 _gtk_entry_completion_popdown (completion);
6523 if (!popup_completion && completion->priv->changed_id > 0)
6524 g_signal_handler_block (entry, completion->priv->changed_id);
6527 begin_change (entry);
6528 if (gtk_editable_get_selection_bounds (editable, &start, &end))
6529 gtk_editable_delete_text (editable, start, end);
6531 pos = priv->current_pos;
6532 gtk_editable_insert_text (editable, text, length, &pos);
6533 gtk_editable_set_position (editable, pos);
6537 !popup_completion && completion->priv->changed_id > 0)
6538 g_signal_handler_unblock (entry, completion->priv->changed_id);
6541 g_object_unref (entry);
6545 gtk_entry_paste (GtkEntry *entry,
6548 g_object_ref (entry);
6549 gtk_clipboard_request_text (gtk_widget_get_clipboard (GTK_WIDGET (entry), selection),
6550 paste_received, entry);
6554 primary_get_cb (GtkClipboard *clipboard,
6555 GtkSelectionData *selection_data,
6559 GtkEntry *entry = GTK_ENTRY (data);
6562 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end))
6564 gchar *str = gtk_entry_get_display_text (entry, start, end);
6565 gtk_selection_data_set_text (selection_data, str, -1);
6571 primary_clear_cb (GtkClipboard *clipboard,
6574 GtkEntry *entry = GTK_ENTRY (data);
6575 GtkEntryPrivate *priv = entry->priv;
6577 gtk_editable_select_region (GTK_EDITABLE (entry), priv->current_pos, priv->current_pos);
6581 gtk_entry_update_primary_selection (GtkEntry *entry)
6583 GtkTargetList *list;
6584 GtkTargetEntry *targets;
6585 GtkClipboard *clipboard;
6589 if (!gtk_widget_get_realized (GTK_WIDGET (entry)))
6592 list = gtk_target_list_new (NULL, 0);
6593 gtk_target_list_add_text_targets (list, 0);
6595 targets = gtk_target_table_new_from_list (list, &n_targets);
6597 clipboard = gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_PRIMARY);
6599 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end))
6601 if (!gtk_clipboard_set_with_owner (clipboard, targets, n_targets,
6602 primary_get_cb, primary_clear_cb, G_OBJECT (entry)))
6603 primary_clear_cb (clipboard, entry);
6607 if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (entry))
6608 gtk_clipboard_clear (clipboard);
6611 gtk_target_table_free (targets, n_targets);
6612 gtk_target_list_unref (list);
6616 gtk_entry_clear (GtkEntry *entry,
6617 GtkEntryIconPosition icon_pos)
6619 GtkEntryPrivate *priv = entry->priv;
6620 EntryIconInfo *icon_info = priv->icons[icon_pos];
6621 GtkImageType storage_type;
6623 if (icon_info && _gtk_icon_helper_get_is_empty (icon_info->icon_helper))
6626 g_object_freeze_notify (G_OBJECT (entry));
6628 /* Explicitly check, as the pointer may become invalidated
6629 * during destruction.
6631 if (GDK_IS_WINDOW (icon_info->window))
6632 gdk_window_hide (icon_info->window);
6634 storage_type = _gtk_icon_helper_get_storage_type (icon_info->icon_helper);
6636 switch (storage_type)
6638 case GTK_IMAGE_PIXBUF:
6639 g_object_notify (G_OBJECT (entry),
6640 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-pixbuf" : "secondary-icon-pixbuf");
6643 case GTK_IMAGE_STOCK:
6644 g_object_notify (G_OBJECT (entry),
6645 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-stock" : "secondary-icon-stock");
6648 case GTK_IMAGE_ICON_NAME:
6649 g_object_notify (G_OBJECT (entry),
6650 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-name" : "secondary-icon-name");
6653 case GTK_IMAGE_GICON:
6654 g_object_notify (G_OBJECT (entry),
6655 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-gicon" : "secondary-icon-gicon");
6659 g_assert_not_reached ();
6663 _gtk_icon_helper_clear (icon_info->icon_helper);
6665 g_object_notify (G_OBJECT (entry),
6666 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-storage-type" : "secondary-icon-storage-type");
6668 g_object_thaw_notify (G_OBJECT (entry));
6672 gtk_entry_ensure_pixbuf (GtkEntry *entry,
6673 GtkEntryIconPosition icon_pos)
6675 GtkEntryPrivate *priv = entry->priv;
6676 EntryIconInfo *icon_info = priv->icons[icon_pos];
6677 GtkStyleContext *context;
6680 context = gtk_widget_get_style_context (GTK_WIDGET (entry));
6681 gtk_entry_prepare_context_for_icon (entry, context, icon_pos);
6683 pix = _gtk_icon_helper_ensure_pixbuf (icon_info->icon_helper,
6686 gtk_style_context_restore (context);
6697 * Creates a new entry.
6699 * Return value: a new #GtkEntry.
6702 gtk_entry_new (void)
6704 return g_object_new (GTK_TYPE_ENTRY, NULL);
6708 * gtk_entry_new_with_buffer:
6709 * @buffer: The buffer to use for the new #GtkEntry.
6711 * Creates a new entry with the specified text buffer.
6713 * Return value: a new #GtkEntry
6718 gtk_entry_new_with_buffer (GtkEntryBuffer *buffer)
6720 g_return_val_if_fail (GTK_IS_ENTRY_BUFFER (buffer), NULL);
6721 return g_object_new (GTK_TYPE_ENTRY, "buffer", buffer, NULL);
6724 static GtkEntryBuffer*
6725 get_buffer (GtkEntry *entry)
6727 GtkEntryPrivate *priv = entry->priv;
6729 if (priv->buffer == NULL)
6731 GtkEntryBuffer *buffer;
6732 buffer = gtk_entry_buffer_new (NULL, 0);
6733 gtk_entry_set_buffer (entry, buffer);
6734 g_object_unref (buffer);
6737 return priv->buffer;
6741 * gtk_entry_get_buffer:
6742 * @entry: a #GtkEntry
6744 * Get the #GtkEntryBuffer object which holds the text for
6749 * Returns: (transfer none): A #GtkEntryBuffer object.
6752 gtk_entry_get_buffer (GtkEntry *entry)
6754 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
6756 return get_buffer (entry);
6760 * gtk_entry_set_buffer:
6761 * @entry: a #GtkEntry
6762 * @buffer: a #GtkEntryBuffer
6764 * Set the #GtkEntryBuffer object which holds the text for
6770 gtk_entry_set_buffer (GtkEntry *entry,
6771 GtkEntryBuffer *buffer)
6773 GtkEntryPrivate *priv;
6776 g_return_if_fail (GTK_IS_ENTRY (entry));
6782 g_return_if_fail (GTK_IS_ENTRY_BUFFER (buffer));
6783 g_object_ref (buffer);
6788 buffer_disconnect_signals (entry);
6789 g_object_unref (priv->buffer);
6792 priv->buffer = buffer;
6795 buffer_connect_signals (entry);
6797 obj = G_OBJECT (entry);
6798 g_object_freeze_notify (obj);
6799 g_object_notify (obj, "buffer");
6800 g_object_notify (obj, "text");
6801 g_object_notify (obj, "text-length");
6802 g_object_notify (obj, "max-length");
6803 g_object_notify (obj, "visibility");
6804 g_object_notify (obj, "invisible-char");
6805 g_object_notify (obj, "invisible-char-set");
6806 g_object_thaw_notify (obj);
6808 gtk_editable_set_position (GTK_EDITABLE (entry), 0);
6809 gtk_entry_recompute (entry);
6813 * gtk_entry_get_text_area:
6814 * @entry: a #GtkEntry
6815 * @text_area: (out): Return location for the text area.
6817 * Gets the area where the entry's text is drawn. This function is
6818 * useful when drawing something to the entry in a draw callback.
6820 * If the entry is not realized, @text_area is filled with zeros.
6822 * See also gtk_entry_get_icon_area().
6827 gtk_entry_get_text_area (GtkEntry *entry,
6828 GdkRectangle *text_area)
6830 GtkEntryPrivate *priv;
6832 g_return_if_fail (GTK_IS_ENTRY (entry));
6833 g_return_if_fail (text_area != NULL);
6837 if (priv->text_area)
6839 GtkAllocation allocation;
6842 gtk_widget_get_allocation (GTK_WIDGET (entry), &allocation);
6843 gdk_window_get_position (priv->text_area, &x, &y);
6845 text_area->x = x - allocation.x;
6846 text_area->y = y - allocation.y;
6847 text_area->width = gdk_window_get_width (priv->text_area);
6848 text_area->height = gdk_window_get_height (priv->text_area);
6854 text_area->width = 0;
6855 text_area->height = 0;
6860 * gtk_entry_set_text:
6861 * @entry: a #GtkEntry
6862 * @text: the new text
6864 * Sets the text in the widget to the given
6865 * value, replacing the current contents.
6867 * See gtk_entry_buffer_set_text().
6870 gtk_entry_set_text (GtkEntry *entry,
6874 GtkEntryCompletion *completion;
6876 g_return_if_fail (GTK_IS_ENTRY (entry));
6877 g_return_if_fail (text != NULL);
6879 /* Actually setting the text will affect the cursor and selection;
6880 * if the contents don't actually change, this will look odd to the user.
6882 if (strcmp (gtk_entry_buffer_get_text (get_buffer (entry)), text) == 0)
6885 completion = gtk_entry_get_completion (entry);
6886 if (completion && completion->priv->changed_id > 0)
6887 g_signal_handler_block (entry, completion->priv->changed_id);
6889 begin_change (entry);
6890 gtk_editable_delete_text (GTK_EDITABLE (entry), 0, -1);
6892 gtk_editable_insert_text (GTK_EDITABLE (entry), text, strlen (text), &tmp_pos);
6895 if (completion && completion->priv->changed_id > 0)
6896 g_signal_handler_unblock (entry, completion->priv->changed_id);
6900 * gtk_entry_set_visibility:
6901 * @entry: a #GtkEntry
6902 * @visible: %TRUE if the contents of the entry are displayed
6905 * Sets whether the contents of the entry are visible or not.
6906 * When visibility is set to %FALSE, characters are displayed
6907 * as the invisible char, and will also appear that way when
6908 * the text in the entry widget is copied elsewhere.
6910 * By default, GTK+ picks the best invisible character available
6911 * in the current font, but it can be changed with
6912 * gtk_entry_set_invisible_char().
6915 gtk_entry_set_visibility (GtkEntry *entry,
6918 GtkEntryPrivate *priv;
6920 g_return_if_fail (GTK_IS_ENTRY (entry));
6924 visible = visible != FALSE;
6926 if (priv->visible != visible)
6928 priv->visible = visible;
6930 g_object_notify (G_OBJECT (entry), "visibility");
6931 gtk_entry_recompute (entry);
6936 * gtk_entry_get_visibility:
6937 * @entry: a #GtkEntry
6939 * Retrieves whether the text in @entry is visible. See
6940 * gtk_entry_set_visibility().
6942 * Return value: %TRUE if the text is currently visible
6945 gtk_entry_get_visibility (GtkEntry *entry)
6947 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
6949 return entry->priv->visible;
6953 * gtk_entry_set_invisible_char:
6954 * @entry: a #GtkEntry
6955 * @ch: a Unicode character
6957 * Sets the character to use in place of the actual text when
6958 * gtk_entry_set_visibility() has been called to set text visibility
6959 * to %FALSE. i.e. this is the character used in "password mode" to
6960 * show the user how many characters have been typed. By default, GTK+
6961 * picks the best invisible char available in the current font. If you
6962 * set the invisible char to 0, then the user will get no feedback
6963 * at all; there will be no text on the screen as they type.
6966 gtk_entry_set_invisible_char (GtkEntry *entry,
6969 GtkEntryPrivate *priv;
6971 g_return_if_fail (GTK_IS_ENTRY (entry));
6975 if (!priv->invisible_char_set)
6977 priv->invisible_char_set = TRUE;
6978 g_object_notify (G_OBJECT (entry), "invisible-char-set");
6981 if (ch == priv->invisible_char)
6984 priv->invisible_char = ch;
6985 g_object_notify (G_OBJECT (entry), "invisible-char");
6986 gtk_entry_recompute (entry);
6990 * gtk_entry_get_invisible_char:
6991 * @entry: a #GtkEntry
6993 * Retrieves the character displayed in place of the real characters
6994 * for entries with visibility set to false. See gtk_entry_set_invisible_char().
6996 * Return value: the current invisible char, or 0, if the entry does not
6997 * show invisible text at all.
7000 gtk_entry_get_invisible_char (GtkEntry *entry)
7002 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7004 return entry->priv->invisible_char;
7008 * gtk_entry_unset_invisible_char:
7009 * @entry: a #GtkEntry
7011 * Unsets the invisible char previously set with
7012 * gtk_entry_set_invisible_char(). So that the
7013 * default invisible char is used again.
7018 gtk_entry_unset_invisible_char (GtkEntry *entry)
7020 GtkEntryPrivate *priv;
7023 g_return_if_fail (GTK_IS_ENTRY (entry));
7027 if (!priv->invisible_char_set)
7030 priv->invisible_char_set = FALSE;
7031 ch = find_invisible_char (GTK_WIDGET (entry));
7033 if (priv->invisible_char != ch)
7035 priv->invisible_char = ch;
7036 g_object_notify (G_OBJECT (entry), "invisible-char");
7039 g_object_notify (G_OBJECT (entry), "invisible-char-set");
7040 gtk_entry_recompute (entry);
7044 * gtk_entry_set_overwrite_mode:
7045 * @entry: a #GtkEntry
7046 * @overwrite: new value
7048 * Sets whether the text is overwritten when typing in the #GtkEntry.
7053 gtk_entry_set_overwrite_mode (GtkEntry *entry,
7056 GtkEntryPrivate *priv = entry->priv;
7058 g_return_if_fail (GTK_IS_ENTRY (entry));
7060 if (priv->overwrite_mode == overwrite)
7063 gtk_entry_toggle_overwrite (entry);
7065 g_object_notify (G_OBJECT (entry), "overwrite-mode");
7069 * gtk_entry_get_overwrite_mode:
7070 * @entry: a #GtkEntry
7072 * Gets the value set by gtk_entry_set_overwrite_mode().
7074 * Return value: whether the text is overwritten when typing.
7079 gtk_entry_get_overwrite_mode (GtkEntry *entry)
7081 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7083 return entry->priv->overwrite_mode;
7087 * gtk_entry_get_text:
7088 * @entry: a #GtkEntry
7090 * Retrieves the contents of the entry widget.
7091 * See also gtk_editable_get_chars().
7093 * This is equivalent to:
7095 * <informalexample><programlisting>
7096 * gtk_entry_buffer_get_text (gtk_entry_get_buffer (entry));
7097 * </programlisting></informalexample>
7099 * Return value: a pointer to the contents of the widget as a
7100 * string. This string points to internally allocated
7101 * storage in the widget and must not be freed, modified or
7105 gtk_entry_get_text (GtkEntry *entry)
7107 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7109 return gtk_entry_buffer_get_text (get_buffer (entry));
7113 * gtk_entry_set_max_length:
7114 * @entry: a #GtkEntry
7115 * @max: the maximum length of the entry, or 0 for no maximum.
7116 * (other than the maximum length of entries.) The value passed in will
7117 * be clamped to the range 0-65536.
7119 * Sets the maximum allowed length of the contents of the widget. If
7120 * the current contents are longer than the given length, then they
7121 * will be truncated to fit.
7123 * This is equivalent to:
7125 * <informalexample><programlisting>
7126 * gtk_entry_buffer_set_max_length (gtk_entry_get_buffer (entry), max);
7127 * </programlisting></informalexample>
7130 gtk_entry_set_max_length (GtkEntry *entry,
7133 g_return_if_fail (GTK_IS_ENTRY (entry));
7134 gtk_entry_buffer_set_max_length (get_buffer (entry), max);
7138 * gtk_entry_get_max_length:
7139 * @entry: a #GtkEntry
7141 * Retrieves the maximum allowed length of the text in
7142 * @entry. See gtk_entry_set_max_length().
7144 * This is equivalent to:
7146 * <informalexample><programlisting>
7147 * gtk_entry_buffer_get_max_length (gtk_entry_get_buffer (entry));
7148 * </programlisting></informalexample>
7150 * Return value: the maximum allowed number of characters
7151 * in #GtkEntry, or 0 if there is no maximum.
7154 gtk_entry_get_max_length (GtkEntry *entry)
7156 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7158 return gtk_entry_buffer_get_max_length (get_buffer (entry));
7162 * gtk_entry_get_text_length:
7163 * @entry: a #GtkEntry
7165 * Retrieves the current length of the text in
7168 * This is equivalent to:
7170 * <informalexample><programlisting>
7171 * gtk_entry_buffer_get_length (gtk_entry_get_buffer (entry));
7172 * </programlisting></informalexample>
7174 * Return value: the current number of characters
7175 * in #GtkEntry, or 0 if there are none.
7180 gtk_entry_get_text_length (GtkEntry *entry)
7182 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7184 return gtk_entry_buffer_get_length (get_buffer (entry));
7188 * gtk_entry_set_activates_default:
7189 * @entry: a #GtkEntry
7190 * @setting: %TRUE to activate window's default widget on Enter keypress
7192 * If @setting is %TRUE, pressing Enter in the @entry will activate the default
7193 * widget for the window containing the entry. This usually means that
7194 * the dialog box containing the entry will be closed, since the default
7195 * widget is usually one of the dialog buttons.
7197 * (For experts: if @setting is %TRUE, the entry calls
7198 * gtk_window_activate_default() on the window containing the entry, in
7199 * the default handler for the #GtkWidget::activate signal.)
7202 gtk_entry_set_activates_default (GtkEntry *entry,
7205 GtkEntryPrivate *priv;
7207 g_return_if_fail (GTK_IS_ENTRY (entry));
7211 setting = setting != FALSE;
7213 if (setting != priv->activates_default)
7215 priv->activates_default = setting;
7216 g_object_notify (G_OBJECT (entry), "activates-default");
7221 * gtk_entry_get_activates_default:
7222 * @entry: a #GtkEntry
7224 * Retrieves the value set by gtk_entry_set_activates_default().
7226 * Return value: %TRUE if the entry will activate the default widget
7229 gtk_entry_get_activates_default (GtkEntry *entry)
7231 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7233 return entry->priv->activates_default;
7237 * gtk_entry_set_width_chars:
7238 * @entry: a #GtkEntry
7239 * @n_chars: width in chars
7241 * Changes the size request of the entry to be about the right size
7242 * for @n_chars characters. Note that it changes the size
7243 * <emphasis>request</emphasis>, the size can still be affected by
7244 * how you pack the widget into containers. If @n_chars is -1, the
7245 * size reverts to the default entry size.
7248 gtk_entry_set_width_chars (GtkEntry *entry,
7251 GtkEntryPrivate *priv;
7253 g_return_if_fail (GTK_IS_ENTRY (entry));
7257 if (priv->width_chars != n_chars)
7259 priv->width_chars = n_chars;
7260 g_object_notify (G_OBJECT (entry), "width-chars");
7261 gtk_widget_queue_resize (GTK_WIDGET (entry));
7266 * gtk_entry_get_width_chars:
7267 * @entry: a #GtkEntry
7269 * Gets the value set by gtk_entry_set_width_chars().
7271 * Return value: number of chars to request space for, or negative if unset
7274 gtk_entry_get_width_chars (GtkEntry *entry)
7276 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7278 return entry->priv->width_chars;
7282 * gtk_entry_set_has_frame:
7283 * @entry: a #GtkEntry
7284 * @setting: new value
7286 * Sets whether the entry has a beveled frame around it.
7289 gtk_entry_set_has_frame (GtkEntry *entry,
7292 GtkEntryPrivate *priv;
7294 g_return_if_fail (GTK_IS_ENTRY (entry));
7298 setting = (setting != FALSE);
7300 if (priv->has_frame == setting)
7303 gtk_widget_queue_resize (GTK_WIDGET (entry));
7304 priv->has_frame = setting;
7305 g_object_notify (G_OBJECT (entry), "has-frame");
7309 * gtk_entry_get_has_frame:
7310 * @entry: a #GtkEntry
7312 * Gets the value set by gtk_entry_set_has_frame().
7314 * Return value: whether the entry has a beveled frame
7317 gtk_entry_get_has_frame (GtkEntry *entry)
7319 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7321 return entry->priv->has_frame;
7325 * gtk_entry_set_inner_border:
7326 * @entry: a #GtkEntry
7327 * @border: (allow-none): a #GtkBorder, or %NULL
7329 * Sets %entry's inner-border property to %border, or clears it if %NULL
7330 * is passed. The inner-border is the area around the entry's text, but
7333 * If set, this property overrides the inner-border style property.
7334 * Overriding the style-provided border is useful when you want to do
7335 * in-place editing of some text in a canvas or list widget, where
7336 * pixel-exact positioning of the entry is important.
7340 * Deprecated: 3.4: Use the standard border and padding CSS properties (through
7341 * objects like #GtkStyleContext and #GtkCssProvider); the value set with
7342 * this function is ignored by #GtkEntry.
7345 gtk_entry_set_inner_border (GtkEntry *entry,
7346 const GtkBorder *border)
7348 g_return_if_fail (GTK_IS_ENTRY (entry));
7350 gtk_entry_do_set_inner_border (entry, border);
7354 * gtk_entry_get_inner_border:
7355 * @entry: a #GtkEntry
7357 * This function returns the entry's #GtkEntry:inner-border property. See
7358 * gtk_entry_set_inner_border() for more information.
7360 * Return value: (transfer none): the entry's #GtkBorder, or %NULL if none was set.
7364 * Deprecated: 3.4: Use the standard border and padding CSS properties (through
7365 * objects like #GtkStyleContext and #GtkCssProvider); the value returned by
7366 * this function is ignored by #GtkEntry.
7369 gtk_entry_get_inner_border (GtkEntry *entry)
7371 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7373 return gtk_entry_do_get_inner_border (entry);
7377 * gtk_entry_get_layout:
7378 * @entry: a #GtkEntry
7380 * Gets the #PangoLayout used to display the entry.
7381 * The layout is useful to e.g. convert text positions to
7382 * pixel positions, in combination with gtk_entry_get_layout_offsets().
7383 * The returned layout is owned by the entry and must not be
7384 * modified or freed by the caller.
7386 * Keep in mind that the layout text may contain a preedit string, so
7387 * gtk_entry_layout_index_to_text_index() and
7388 * gtk_entry_text_index_to_layout_index() are needed to convert byte
7389 * indices in the layout to byte indices in the entry contents.
7391 * Return value: (transfer none): the #PangoLayout for this entry
7394 gtk_entry_get_layout (GtkEntry *entry)
7396 PangoLayout *layout;
7398 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7400 layout = gtk_entry_ensure_layout (entry, TRUE);
7407 * gtk_entry_layout_index_to_text_index:
7408 * @entry: a #GtkEntry
7409 * @layout_index: byte index into the entry layout text
7411 * Converts from a position in the entry contents (returned
7412 * by gtk_entry_get_text()) to a position in the
7413 * entry's #PangoLayout (returned by gtk_entry_get_layout(),
7414 * with text retrieved via pango_layout_get_text()).
7416 * Return value: byte index into the entry contents
7419 gtk_entry_layout_index_to_text_index (GtkEntry *entry,
7422 GtkEntryPrivate *priv;
7423 PangoLayout *layout;
7427 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7431 layout = gtk_entry_ensure_layout (entry, TRUE);
7432 text = pango_layout_get_text (layout);
7433 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos) - text;
7435 if (layout_index >= cursor_index && priv->preedit_length)
7437 if (layout_index >= cursor_index + priv->preedit_length)
7438 layout_index -= priv->preedit_length;
7440 layout_index = cursor_index;
7443 return layout_index;
7447 * gtk_entry_text_index_to_layout_index:
7448 * @entry: a #GtkEntry
7449 * @text_index: byte index into the entry contents
7451 * Converts from a position in the entry's #PangoLayout (returned by
7452 * gtk_entry_get_layout()) to a position in the entry contents
7453 * (returned by gtk_entry_get_text()).
7455 * Return value: byte index into the entry layout text
7458 gtk_entry_text_index_to_layout_index (GtkEntry *entry,
7461 GtkEntryPrivate *priv;
7462 PangoLayout *layout;
7466 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7470 layout = gtk_entry_ensure_layout (entry, TRUE);
7471 text = pango_layout_get_text (layout);
7472 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos) - text;
7474 if (text_index > cursor_index)
7475 text_index += priv->preedit_length;
7481 * gtk_entry_get_layout_offsets:
7482 * @entry: a #GtkEntry
7483 * @x: (out) (allow-none): location to store X offset of layout, or %NULL
7484 * @y: (out) (allow-none): location to store Y offset of layout, or %NULL
7487 * Obtains the position of the #PangoLayout used to render text
7488 * in the entry, in widget coordinates. Useful if you want to line
7489 * up the text in an entry with some other text, e.g. when using the
7490 * entry to implement editable cells in a sheet widget.
7492 * Also useful to convert mouse events into coordinates inside the
7493 * #PangoLayout, e.g. to take some action if some part of the entry text
7496 * Note that as the user scrolls around in the entry the offsets will
7497 * change; you'll need to connect to the "notify::scroll-offset"
7498 * signal to track this. Remember when using the #PangoLayout
7499 * functions you need to convert to and from pixels using
7500 * PANGO_PIXELS() or #PANGO_SCALE.
7502 * Keep in mind that the layout text may contain a preedit string, so
7503 * gtk_entry_layout_index_to_text_index() and
7504 * gtk_entry_text_index_to_layout_index() are needed to convert byte
7505 * indices in the layout to byte indices in the entry contents.
7508 gtk_entry_get_layout_offsets (GtkEntry *entry,
7512 gint text_area_x, text_area_y;
7514 g_return_if_fail (GTK_IS_ENTRY (entry));
7516 /* this gets coords relative to text area */
7517 get_layout_position (entry, x, y);
7519 /* convert to widget coords */
7520 gtk_entry_get_text_area_size (entry, &text_area_x, &text_area_y, NULL, NULL);
7531 * gtk_entry_set_alignment:
7532 * @entry: a #GtkEntry
7533 * @xalign: The horizontal alignment, from 0 (left) to 1 (right).
7534 * Reversed for RTL layouts
7536 * Sets the alignment for the contents of the entry. This controls
7537 * the horizontal positioning of the contents when the displayed
7538 * text is shorter than the width of the entry.
7543 gtk_entry_set_alignment (GtkEntry *entry, gfloat xalign)
7545 GtkEntryPrivate *priv;
7547 g_return_if_fail (GTK_IS_ENTRY (entry));
7553 else if (xalign > 1.0)
7556 if (xalign != priv->xalign)
7558 priv->xalign = xalign;
7560 gtk_entry_recompute (entry);
7562 g_object_notify (G_OBJECT (entry), "xalign");
7567 * gtk_entry_get_alignment:
7568 * @entry: a #GtkEntry
7570 * Gets the value set by gtk_entry_set_alignment().
7572 * Return value: the alignment
7577 gtk_entry_get_alignment (GtkEntry *entry)
7579 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
7581 return entry->priv->xalign;
7585 * gtk_entry_set_icon_from_pixbuf:
7586 * @entry: a #GtkEntry
7587 * @icon_pos: Icon position
7588 * @pixbuf: (allow-none): A #GdkPixbuf, or %NULL
7590 * Sets the icon shown in the specified position using a pixbuf.
7592 * If @pixbuf is %NULL, no icon will be shown in the specified position.
7597 gtk_entry_set_icon_from_pixbuf (GtkEntry *entry,
7598 GtkEntryIconPosition icon_pos,
7601 GtkEntryPrivate *priv;
7602 EntryIconInfo *icon_info;
7604 g_return_if_fail (GTK_IS_ENTRY (entry));
7605 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7609 if ((icon_info = priv->icons[icon_pos]) == NULL)
7610 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7612 g_object_freeze_notify (G_OBJECT (entry));
7615 g_object_ref (pixbuf);
7617 gtk_entry_clear (entry, icon_pos);
7621 _gtk_icon_helper_set_pixbuf (icon_info->icon_helper, pixbuf);
7623 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7625 g_object_notify (G_OBJECT (entry), "primary-icon-pixbuf");
7626 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7630 g_object_notify (G_OBJECT (entry), "secondary-icon-pixbuf");
7631 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7634 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7635 gdk_window_show_unraised (icon_info->window);
7637 g_object_unref (pixbuf);
7640 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7641 gtk_widget_queue_resize (GTK_WIDGET (entry));
7643 g_object_thaw_notify (G_OBJECT (entry));
7647 * gtk_entry_set_icon_from_stock:
7648 * @entry: A #GtkEntry
7649 * @icon_pos: Icon position
7650 * @stock_id: (allow-none): The name of the stock item, or %NULL
7652 * Sets the icon shown in the entry at the specified position from
7655 * If @stock_id is %NULL, no icon will be shown in the specified position.
7660 gtk_entry_set_icon_from_stock (GtkEntry *entry,
7661 GtkEntryIconPosition icon_pos,
7662 const gchar *stock_id)
7664 GtkEntryPrivate *priv;
7665 EntryIconInfo *icon_info;
7668 g_return_if_fail (GTK_IS_ENTRY (entry));
7669 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7673 if ((icon_info = priv->icons[icon_pos]) == NULL)
7674 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7676 g_object_freeze_notify (G_OBJECT (entry));
7678 /* need to dup before clearing */
7679 new_id = g_strdup (stock_id);
7681 gtk_entry_clear (entry, icon_pos);
7685 _gtk_icon_helper_set_stock_id (icon_info->icon_helper, new_id, GTK_ICON_SIZE_MENU);
7687 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7689 g_object_notify (G_OBJECT (entry), "primary-icon-stock");
7690 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7694 g_object_notify (G_OBJECT (entry), "secondary-icon-stock");
7695 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7698 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7699 gdk_window_show_unraised (icon_info->window);
7704 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7705 gtk_widget_queue_resize (GTK_WIDGET (entry));
7707 g_object_thaw_notify (G_OBJECT (entry));
7711 * gtk_entry_set_icon_from_icon_name:
7712 * @entry: A #GtkEntry
7713 * @icon_pos: The position at which to set the icon
7714 * @icon_name: (allow-none): An icon name, or %NULL
7716 * Sets the icon shown in the entry at the specified position
7717 * from the current icon theme.
7719 * If the icon name isn't known, a "broken image" icon will be displayed
7722 * If @icon_name is %NULL, no icon will be shown in the specified position.
7727 gtk_entry_set_icon_from_icon_name (GtkEntry *entry,
7728 GtkEntryIconPosition icon_pos,
7729 const gchar *icon_name)
7731 GtkEntryPrivate *priv;
7732 EntryIconInfo *icon_info;
7735 g_return_if_fail (GTK_IS_ENTRY (entry));
7736 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7740 if ((icon_info = priv->icons[icon_pos]) == NULL)
7741 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7743 g_object_freeze_notify (G_OBJECT (entry));
7745 /* need to dup before clearing */
7746 new_name = g_strdup (icon_name);
7748 gtk_entry_clear (entry, icon_pos);
7750 if (new_name != NULL)
7752 _gtk_icon_helper_set_icon_name (icon_info->icon_helper, new_name, GTK_ICON_SIZE_MENU);
7754 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7756 g_object_notify (G_OBJECT (entry), "primary-icon-name");
7757 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7761 g_object_notify (G_OBJECT (entry), "secondary-icon-name");
7762 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7765 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7766 gdk_window_show_unraised (icon_info->window);
7771 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7772 gtk_widget_queue_resize (GTK_WIDGET (entry));
7774 g_object_thaw_notify (G_OBJECT (entry));
7778 * gtk_entry_set_icon_from_gicon:
7779 * @entry: A #GtkEntry
7780 * @icon_pos: The position at which to set the icon
7781 * @icon: (allow-none): The icon to set, or %NULL
7783 * Sets the icon shown in the entry at the specified position
7784 * from the current icon theme.
7785 * If the icon isn't known, a "broken image" icon will be displayed
7788 * If @icon is %NULL, no icon will be shown in the specified position.
7793 gtk_entry_set_icon_from_gicon (GtkEntry *entry,
7794 GtkEntryIconPosition icon_pos,
7797 GtkEntryPrivate *priv;
7798 EntryIconInfo *icon_info;
7800 g_return_if_fail (GTK_IS_ENTRY (entry));
7801 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7805 if ((icon_info = priv->icons[icon_pos]) == NULL)
7806 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7808 g_object_freeze_notify (G_OBJECT (entry));
7810 /* need to ref before clearing */
7812 g_object_ref (icon);
7814 gtk_entry_clear (entry, icon_pos);
7818 _gtk_icon_helper_set_gicon (icon_info->icon_helper, icon, GTK_ICON_SIZE_MENU);
7820 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7822 g_object_notify (G_OBJECT (entry), "primary-icon-gicon");
7823 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7827 g_object_notify (G_OBJECT (entry), "secondary-icon-gicon");
7828 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7831 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7832 gdk_window_show_unraised (icon_info->window);
7834 g_object_unref (icon);
7837 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7838 gtk_widget_queue_resize (GTK_WIDGET (entry));
7840 g_object_thaw_notify (G_OBJECT (entry));
7844 * gtk_entry_set_icon_activatable:
7845 * @entry: A #GtkEntry
7846 * @icon_pos: Icon position
7847 * @activatable: %TRUE if the icon should be activatable
7849 * Sets whether the icon is activatable.
7854 gtk_entry_set_icon_activatable (GtkEntry *entry,
7855 GtkEntryIconPosition icon_pos,
7856 gboolean activatable)
7858 GtkEntryPrivate *priv;
7859 EntryIconInfo *icon_info;
7861 g_return_if_fail (GTK_IS_ENTRY (entry));
7862 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7866 if ((icon_info = priv->icons[icon_pos]) == NULL)
7867 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7869 activatable = activatable != FALSE;
7871 if (icon_info->nonactivatable != !activatable)
7873 icon_info->nonactivatable = !activatable;
7875 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
7876 update_cursors (GTK_WIDGET (entry));
7878 g_object_notify (G_OBJECT (entry),
7879 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-activatable" : "secondary-icon-activatable");
7884 * gtk_entry_get_icon_activatable:
7885 * @entry: a #GtkEntry
7886 * @icon_pos: Icon position
7888 * Returns whether the icon is activatable.
7890 * Returns: %TRUE if the icon is activatable.
7895 gtk_entry_get_icon_activatable (GtkEntry *entry,
7896 GtkEntryIconPosition icon_pos)
7898 GtkEntryPrivate *priv;
7899 EntryIconInfo *icon_info;
7901 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7902 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), FALSE);
7905 icon_info = priv->icons[icon_pos];
7907 return (!icon_info || !icon_info->nonactivatable);
7911 * gtk_entry_get_icon_pixbuf:
7912 * @entry: A #GtkEntry
7913 * @icon_pos: Icon position
7915 * Retrieves the image used for the icon.
7917 * Unlike the other methods of setting and getting icon data, this
7918 * method will work regardless of whether the icon was set using a
7919 * #GdkPixbuf, a #GIcon, a stock item, or an icon name.
7921 * Returns: (transfer none): A #GdkPixbuf, or %NULL if no icon is
7922 * set for this position.
7927 gtk_entry_get_icon_pixbuf (GtkEntry *entry,
7928 GtkEntryIconPosition icon_pos)
7930 GtkEntryPrivate *priv;
7931 EntryIconInfo *icon_info;
7934 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7935 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7939 icon_info = priv->icons[icon_pos];
7944 /* HACK: unfortunately this is transfer none, so we need to return
7945 * the icon helper's cache ref directly.
7947 pixbuf = gtk_entry_ensure_pixbuf (entry, icon_pos);
7948 g_object_unref (pixbuf);
7954 * gtk_entry_get_icon_gicon:
7955 * @entry: A #GtkEntry
7956 * @icon_pos: Icon position
7958 * Retrieves the #GIcon used for the icon, or %NULL if there is
7959 * no icon or if the icon was set by some other method (e.g., by
7960 * stock, pixbuf, or icon name).
7962 * Returns: (transfer none): A #GIcon, or %NULL if no icon is set
7963 * or if the icon is not a #GIcon
7968 gtk_entry_get_icon_gicon (GtkEntry *entry,
7969 GtkEntryIconPosition icon_pos)
7971 GtkEntryPrivate *priv;
7972 EntryIconInfo *icon_info;
7974 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7975 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7978 icon_info = priv->icons[icon_pos];
7983 return _gtk_icon_helper_peek_gicon (icon_info->icon_helper);
7987 * gtk_entry_get_icon_stock:
7988 * @entry: A #GtkEntry
7989 * @icon_pos: Icon position
7991 * Retrieves the stock id used for the icon, or %NULL if there is
7992 * no icon or if the icon was set by some other method (e.g., by
7993 * pixbuf, icon name or gicon).
7995 * Returns: A stock id, or %NULL if no icon is set or if the icon
7996 * wasn't set from a stock id
8001 gtk_entry_get_icon_stock (GtkEntry *entry,
8002 GtkEntryIconPosition icon_pos)
8004 GtkEntryPrivate *priv;
8005 EntryIconInfo *icon_info;
8007 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8008 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8011 icon_info = priv->icons[icon_pos];
8016 return _gtk_icon_helper_get_stock_id (icon_info->icon_helper);
8020 * gtk_entry_get_icon_name:
8021 * @entry: A #GtkEntry
8022 * @icon_pos: Icon position
8024 * Retrieves the icon name used for the icon, or %NULL if there is
8025 * no icon or if the icon was set by some other method (e.g., by
8026 * pixbuf, stock or gicon).
8028 * Returns: An icon name, or %NULL if no icon is set or if the icon
8029 * wasn't set from an icon name
8034 gtk_entry_get_icon_name (GtkEntry *entry,
8035 GtkEntryIconPosition icon_pos)
8037 GtkEntryPrivate *priv;
8038 EntryIconInfo *icon_info;
8040 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8041 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8044 icon_info = priv->icons[icon_pos];
8049 return _gtk_icon_helper_get_icon_name (icon_info->icon_helper);
8053 * gtk_entry_set_icon_sensitive:
8054 * @entry: A #GtkEntry
8055 * @icon_pos: Icon position
8056 * @sensitive: Specifies whether the icon should appear
8057 * sensitive or insensitive
8059 * Sets the sensitivity for the specified icon.
8064 gtk_entry_set_icon_sensitive (GtkEntry *entry,
8065 GtkEntryIconPosition icon_pos,
8068 GtkEntryPrivate *priv;
8069 EntryIconInfo *icon_info;
8071 g_return_if_fail (GTK_IS_ENTRY (entry));
8072 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8076 if ((icon_info = priv->icons[icon_pos]) == NULL)
8077 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8079 if (icon_info->insensitive != !sensitive)
8081 icon_info->insensitive = !sensitive;
8083 icon_info->pressed = FALSE;
8084 icon_info->prelight = FALSE;
8086 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
8087 update_cursors (GTK_WIDGET (entry));
8089 gtk_widget_queue_draw (GTK_WIDGET (entry));
8091 g_object_notify (G_OBJECT (entry),
8092 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-sensitive" : "secondary-icon-sensitive");
8097 * gtk_entry_get_icon_sensitive:
8098 * @entry: a #GtkEntry
8099 * @icon_pos: Icon position
8101 * Returns whether the icon appears sensitive or insensitive.
8103 * Returns: %TRUE if the icon is sensitive.
8108 gtk_entry_get_icon_sensitive (GtkEntry *entry,
8109 GtkEntryIconPosition icon_pos)
8111 GtkEntryPrivate *priv;
8112 EntryIconInfo *icon_info;
8114 g_return_val_if_fail (GTK_IS_ENTRY (entry), TRUE);
8115 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), TRUE);
8119 icon_info = priv->icons[icon_pos];
8121 return (!icon_info || !icon_info->insensitive);
8126 * gtk_entry_get_icon_storage_type:
8127 * @entry: a #GtkEntry
8128 * @icon_pos: Icon position
8130 * Gets the type of representation being used by the icon
8131 * to store image data. If the icon has no image data,
8132 * the return value will be %GTK_IMAGE_EMPTY.
8134 * Return value: image representation being used
8139 gtk_entry_get_icon_storage_type (GtkEntry *entry,
8140 GtkEntryIconPosition icon_pos)
8142 GtkEntryPrivate *priv;
8143 EntryIconInfo *icon_info;
8145 g_return_val_if_fail (GTK_IS_ENTRY (entry), GTK_IMAGE_EMPTY);
8146 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), GTK_IMAGE_EMPTY);
8150 icon_info = priv->icons[icon_pos];
8153 return GTK_IMAGE_EMPTY;
8155 return _gtk_icon_helper_get_storage_type (icon_info->icon_helper);
8159 * gtk_entry_get_icon_at_pos:
8160 * @entry: a #GtkEntry
8161 * @x: the x coordinate of the position to find
8162 * @y: the y coordinate of the position to find
8164 * Finds the icon at the given position and return its index. The
8165 * position's coordinates are relative to the @entry's top left corner.
8166 * If @x, @y doesn't lie inside an icon, -1 is returned.
8167 * This function is intended for use in a #GtkWidget::query-tooltip
8170 * Returns: the index of the icon at the given position, or -1
8175 gtk_entry_get_icon_at_pos (GtkEntry *entry,
8179 GtkAllocation primary;
8180 GtkAllocation secondary;
8181 gint frame_x, frame_y;
8183 g_return_val_if_fail (GTK_IS_ENTRY (entry), -1);
8185 get_frame_size (entry, FALSE, &frame_x, &frame_y, NULL, NULL);
8189 get_icon_allocations (entry, &primary, &secondary);
8191 if (primary.x <= x && x < primary.x + primary.width &&
8192 primary.y <= y && y < primary.y + primary.height)
8193 return GTK_ENTRY_ICON_PRIMARY;
8195 if (secondary.x <= x && x < secondary.x + secondary.width &&
8196 secondary.y <= y && y < secondary.y + secondary.height)
8197 return GTK_ENTRY_ICON_SECONDARY;
8203 * gtk_entry_set_icon_drag_source:
8204 * @entry: a #GtkIconEntry
8205 * @icon_pos: icon position
8206 * @target_list: the targets (data formats) in which the data can be provided
8207 * @actions: a bitmask of the allowed drag actions
8209 * Sets up the icon at the given position so that GTK+ will start a drag
8210 * operation when the user clicks and drags the icon.
8212 * To handle the drag operation, you need to connect to the usual
8213 * #GtkWidget::drag-data-get (or possibly #GtkWidget::drag-data-delete)
8214 * signal, and use gtk_entry_get_current_icon_drag_source() in
8215 * your signal handler to find out if the drag was started from
8218 * By default, GTK+ uses the icon as the drag icon. You can use the
8219 * #GtkWidget::drag-begin signal to set a different icon. Note that you
8220 * have to use g_signal_connect_after() to ensure that your signal handler
8221 * gets executed after the default handler.
8226 gtk_entry_set_icon_drag_source (GtkEntry *entry,
8227 GtkEntryIconPosition icon_pos,
8228 GtkTargetList *target_list,
8229 GdkDragAction actions)
8231 GtkEntryPrivate *priv;
8232 EntryIconInfo *icon_info;
8234 g_return_if_fail (GTK_IS_ENTRY (entry));
8235 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8239 if ((icon_info = priv->icons[icon_pos]) == NULL)
8240 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8242 if (icon_info->target_list)
8243 gtk_target_list_unref (icon_info->target_list);
8244 icon_info->target_list = target_list;
8245 if (icon_info->target_list)
8246 gtk_target_list_ref (icon_info->target_list);
8248 icon_info->actions = actions;
8252 * gtk_entry_get_current_icon_drag_source:
8253 * @entry: a #GtkIconEntry
8255 * Returns the index of the icon which is the source of the current
8256 * DND operation, or -1.
8258 * This function is meant to be used in a #GtkWidget::drag-data-get
8261 * Returns: index of the icon which is the source of the current
8262 * DND operation, or -1.
8267 gtk_entry_get_current_icon_drag_source (GtkEntry *entry)
8269 GtkEntryPrivate *priv;
8270 EntryIconInfo *icon_info = NULL;
8273 g_return_val_if_fail (GTK_IS_ENTRY (entry), -1);
8277 for (i = 0; i < MAX_ICONS; i++)
8279 if ((icon_info = priv->icons[i]))
8281 if (icon_info->in_drag)
8290 * gtk_entry_get_icon_area:
8291 * @entry: A #GtkEntry
8292 * @icon_pos: Icon position
8293 * @icon_area: (out): Return location for the icon's area
8295 * Gets the area where entry's icon at @icon_pos is drawn.
8296 * This function is useful when drawing something to the
8297 * entry in a draw callback.
8299 * If the entry is not realized or has no icon at the given position,
8300 * @icon_area is filled with zeros.
8302 * See also gtk_entry_get_text_area()
8307 gtk_entry_get_icon_area (GtkEntry *entry,
8308 GtkEntryIconPosition icon_pos,
8309 GdkRectangle *icon_area)
8311 GtkEntryPrivate *priv;
8312 EntryIconInfo *icon_info;
8314 g_return_if_fail (GTK_IS_ENTRY (entry));
8315 g_return_if_fail (icon_area != NULL);
8319 icon_info = priv->icons[icon_pos];
8323 GtkAllocation primary;
8324 GtkAllocation secondary;
8326 get_icon_allocations (entry, &primary, &secondary);
8328 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
8329 *icon_area = primary;
8331 *icon_area = secondary;
8337 icon_area->width = 0;
8338 icon_area->height = 0;
8343 ensure_has_tooltip (GtkEntry *entry)
8345 GtkEntryPrivate *priv;
8346 EntryIconInfo *icon_info;
8348 gboolean has_tooltip = FALSE;
8352 for (i = 0; i < MAX_ICONS; i++)
8354 if ((icon_info = priv->icons[i]) != NULL)
8356 if (icon_info->tooltip != NULL)
8364 gtk_widget_set_has_tooltip (GTK_WIDGET (entry), has_tooltip);
8368 * gtk_entry_get_icon_tooltip_text:
8369 * @entry: a #GtkEntry
8370 * @icon_pos: the icon position
8372 * Gets the contents of the tooltip on the icon at the specified
8373 * position in @entry.
8375 * Returns: the tooltip text, or %NULL. Free the returned string
8376 * with g_free() when done.
8381 gtk_entry_get_icon_tooltip_text (GtkEntry *entry,
8382 GtkEntryIconPosition icon_pos)
8384 GtkEntryPrivate *priv;
8385 EntryIconInfo *icon_info;
8388 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8389 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8393 icon_info = priv->icons[icon_pos];
8398 if (icon_info->tooltip &&
8399 !pango_parse_markup (icon_info->tooltip, -1, 0, NULL, &text, NULL, NULL))
8400 g_assert (NULL == text); /* text should still be NULL in case of markup errors */
8406 * gtk_entry_set_icon_tooltip_text:
8407 * @entry: a #GtkEntry
8408 * @icon_pos: the icon position
8409 * @tooltip: (allow-none): the contents of the tooltip for the icon, or %NULL
8411 * Sets @tooltip as the contents of the tooltip for the icon
8412 * at the specified position.
8414 * Use %NULL for @tooltip to remove an existing tooltip.
8416 * See also gtk_widget_set_tooltip_text() and
8417 * gtk_entry_set_icon_tooltip_markup().
8422 gtk_entry_set_icon_tooltip_text (GtkEntry *entry,
8423 GtkEntryIconPosition icon_pos,
8424 const gchar *tooltip)
8426 GtkEntryPrivate *priv;
8427 EntryIconInfo *icon_info;
8429 g_return_if_fail (GTK_IS_ENTRY (entry));
8430 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8434 if ((icon_info = priv->icons[icon_pos]) == NULL)
8435 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8437 if (icon_info->tooltip)
8438 g_free (icon_info->tooltip);
8440 /* Treat an empty string as a NULL string,
8441 * because an empty string would be useless for a tooltip:
8443 if (tooltip && tooltip[0] == '\0')
8446 icon_info->tooltip = tooltip ? g_markup_escape_text (tooltip, -1) : NULL;
8448 ensure_has_tooltip (entry);
8452 * gtk_entry_get_icon_tooltip_markup:
8453 * @entry: a #GtkEntry
8454 * @icon_pos: the icon position
8456 * Gets the contents of the tooltip on the icon at the specified
8457 * position in @entry.
8459 * Returns: the tooltip text, or %NULL. Free the returned string
8460 * with g_free() when done.
8465 gtk_entry_get_icon_tooltip_markup (GtkEntry *entry,
8466 GtkEntryIconPosition icon_pos)
8468 GtkEntryPrivate *priv;
8469 EntryIconInfo *icon_info;
8471 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8472 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8476 icon_info = priv->icons[icon_pos];
8481 return g_strdup (icon_info->tooltip);
8485 * gtk_entry_set_icon_tooltip_markup:
8486 * @entry: a #GtkEntry
8487 * @icon_pos: the icon position
8488 * @tooltip: (allow-none): the contents of the tooltip for the icon, or %NULL
8490 * Sets @tooltip as the contents of the tooltip for the icon at
8491 * the specified position. @tooltip is assumed to be marked up with
8492 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
8494 * Use %NULL for @tooltip to remove an existing tooltip.
8496 * See also gtk_widget_set_tooltip_markup() and
8497 * gtk_enty_set_icon_tooltip_text().
8502 gtk_entry_set_icon_tooltip_markup (GtkEntry *entry,
8503 GtkEntryIconPosition icon_pos,
8504 const gchar *tooltip)
8506 GtkEntryPrivate *priv;
8507 EntryIconInfo *icon_info;
8509 g_return_if_fail (GTK_IS_ENTRY (entry));
8510 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8514 if ((icon_info = priv->icons[icon_pos]) == NULL)
8515 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8517 if (icon_info->tooltip)
8518 g_free (icon_info->tooltip);
8520 /* Treat an empty string as a NULL string,
8521 * because an empty string would be useless for a tooltip:
8523 if (tooltip && tooltip[0] == '\0')
8526 icon_info->tooltip = g_strdup (tooltip);
8528 ensure_has_tooltip (entry);
8532 gtk_entry_query_tooltip (GtkWidget *widget,
8535 gboolean keyboard_tip,
8536 GtkTooltip *tooltip)
8539 GtkEntryPrivate *priv;
8540 EntryIconInfo *icon_info;
8543 entry = GTK_ENTRY (widget);
8548 icon_pos = gtk_entry_get_icon_at_pos (entry, x, y);
8551 if ((icon_info = priv->icons[icon_pos]) != NULL)
8553 if (icon_info->tooltip)
8555 gtk_tooltip_set_markup (tooltip, icon_info->tooltip);
8564 return GTK_WIDGET_CLASS (gtk_entry_parent_class)->query_tooltip (widget,
8571 /* Quick hack of a popup menu
8574 activate_cb (GtkWidget *menuitem,
8577 const gchar *signal = g_object_get_data (G_OBJECT (menuitem), "gtk-signal");
8578 g_signal_emit_by_name (entry, signal);
8583 gtk_entry_mnemonic_activate (GtkWidget *widget,
8584 gboolean group_cycling)
8586 gtk_widget_grab_focus (widget);
8591 gtk_entry_grab_notify (GtkWidget *widget,
8592 gboolean was_grabbed)
8594 GtkEntryPrivate *priv;
8596 priv = GTK_ENTRY (widget)->priv;
8599 gtk_widget_device_is_shadowed (widget, priv->device))
8601 /* Unset button so we don't expect
8602 * a button release anymore
8605 priv->device = NULL;
8606 priv->in_drag = FALSE;
8611 append_action_signal (GtkEntry *entry,
8613 const gchar *stock_id,
8614 const gchar *signal,
8617 GtkWidget *menuitem = gtk_image_menu_item_new_from_stock (stock_id, NULL);
8619 g_object_set_data (G_OBJECT (menuitem), I_("gtk-signal"), (char *)signal);
8620 g_signal_connect (menuitem, "activate",
8621 G_CALLBACK (activate_cb), entry);
8623 gtk_widget_set_sensitive (menuitem, sensitive);
8625 gtk_widget_show (menuitem);
8626 gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
8630 popup_menu_detach (GtkWidget *attach_widget,
8633 GtkEntry *entry_attach = GTK_ENTRY (attach_widget);
8634 GtkEntryPrivate *priv_attach = entry_attach->priv;
8636 priv_attach->popup_menu = NULL;
8640 popup_position_func (GtkMenu *menu,
8646 GtkEntry *entry = GTK_ENTRY (user_data);
8647 GtkEntryPrivate *priv = entry->priv;
8648 GtkWidget *widget = GTK_WIDGET (entry);
8650 GtkRequisition menu_req;
8651 GdkRectangle monitor;
8653 gint monitor_num, strong_x, height;
8655 g_return_if_fail (gtk_widget_get_realized (widget));
8657 gdk_window_get_origin (priv->text_area, x, y);
8659 screen = gtk_widget_get_screen (widget);
8660 monitor_num = gdk_screen_get_monitor_at_window (screen, priv->text_area);
8661 if (monitor_num < 0)
8663 gtk_menu_set_monitor (menu, monitor_num);
8665 gdk_screen_get_monitor_workarea (screen, monitor_num, &monitor);
8666 gtk_widget_get_preferred_size (priv->popup_menu,
8668 height = gdk_window_get_height (priv->text_area);
8669 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
8670 _gtk_entry_get_borders (entry, &borders);
8672 *x += borders.left + strong_x - priv->scroll_offset;
8673 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
8674 *x -= menu_req.width;
8676 if ((*y + height + menu_req.height) <= monitor.y + monitor.height)
8678 else if ((*y - menu_req.height) >= monitor.y)
8679 *y -= menu_req.height;
8680 else if (monitor.y + monitor.height - (*y + height) > *y)
8683 *y -= menu_req.height;
8689 unichar_chosen_func (const char *text,
8692 GtkEntry *entry = GTK_ENTRY (data);
8693 GtkEntryPrivate *priv = entry->priv;
8696 gtk_entry_enter_text (entry, text);
8708 popup_targets_received (GtkClipboard *clipboard,
8709 GtkSelectionData *data,
8712 PopupInfo *info = user_data;
8713 GtkEntry *entry = info->entry;
8714 GtkEntryPrivate *info_entry_priv = entry->priv;
8716 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
8719 gboolean clipboard_contains_text;
8720 GtkWidget *menuitem;
8722 gboolean show_input_method_menu;
8723 gboolean show_unicode_menu;
8725 clipboard_contains_text = gtk_selection_data_targets_include_text (data);
8726 if (info_entry_priv->popup_menu)
8727 gtk_widget_destroy (info_entry_priv->popup_menu);
8729 info_entry_priv->popup_menu = gtk_menu_new ();
8731 gtk_menu_attach_to_widget (GTK_MENU (info_entry_priv->popup_menu),
8735 mode = gtk_entry_get_display_mode (entry);
8736 append_action_signal (entry, info_entry_priv->popup_menu, GTK_STOCK_CUT, "cut-clipboard",
8737 info_entry_priv->editable && mode == DISPLAY_NORMAL &&
8738 info_entry_priv->current_pos != info_entry_priv->selection_bound);
8740 append_action_signal (entry, info_entry_priv->popup_menu, GTK_STOCK_COPY, "copy-clipboard",
8741 mode == DISPLAY_NORMAL &&
8742 info_entry_priv->current_pos != info_entry_priv->selection_bound);
8744 append_action_signal (entry, info_entry_priv->popup_menu, GTK_STOCK_PASTE, "paste-clipboard",
8745 info_entry_priv->editable && clipboard_contains_text);
8747 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_DELETE, NULL);
8748 gtk_widget_set_sensitive (menuitem, info_entry_priv->editable && info_entry_priv->current_pos != info_entry_priv->selection_bound);
8749 g_signal_connect_swapped (menuitem, "activate",
8750 G_CALLBACK (gtk_entry_delete_cb), entry);
8751 gtk_widget_show (menuitem);
8752 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8754 menuitem = gtk_separator_menu_item_new ();
8755 gtk_widget_show (menuitem);
8756 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8758 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_SELECT_ALL, NULL);
8759 gtk_widget_set_sensitive (menuitem, gtk_entry_buffer_get_length (info_entry_priv->buffer) > 0);
8760 g_signal_connect_swapped (menuitem, "activate",
8761 G_CALLBACK (gtk_entry_select_all), entry);
8762 gtk_widget_show (menuitem);
8763 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8765 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
8766 "gtk-show-input-method-menu", &show_input_method_menu,
8767 "gtk-show-unicode-menu", &show_unicode_menu,
8770 if (show_input_method_menu || show_unicode_menu)
8772 menuitem = gtk_separator_menu_item_new ();
8773 gtk_widget_show (menuitem);
8774 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8777 if (show_input_method_menu)
8779 menuitem = gtk_menu_item_new_with_mnemonic (_("Input _Methods"));
8780 gtk_widget_set_sensitive (menuitem, info_entry_priv->editable);
8781 gtk_widget_show (menuitem);
8782 submenu = gtk_menu_new ();
8783 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
8785 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8787 gtk_im_multicontext_append_menuitems (GTK_IM_MULTICONTEXT (info_entry_priv->im_context),
8788 GTK_MENU_SHELL (submenu));
8791 if (show_unicode_menu)
8793 menuitem = gtk_menu_item_new_with_mnemonic (_("_Insert Unicode Control Character"));
8794 gtk_widget_set_sensitive (menuitem, info_entry_priv->editable);
8795 gtk_widget_show (menuitem);
8797 submenu = gtk_menu_new ();
8798 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
8799 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8801 _gtk_text_util_append_special_char_menuitems (GTK_MENU_SHELL (submenu),
8802 unichar_chosen_func,
8806 g_signal_emit (entry,
8807 signals[POPULATE_POPUP],
8809 info_entry_priv->popup_menu);
8813 gtk_menu_popup_for_device (GTK_MENU (info_entry_priv->popup_menu),
8814 info->device, NULL, NULL, NULL, NULL, NULL,
8815 info->button, info->time);
8818 gtk_menu_popup (GTK_MENU (info_entry_priv->popup_menu), NULL, NULL,
8819 popup_position_func, entry,
8820 0, gtk_get_current_event_time ());
8821 gtk_menu_shell_select_first (GTK_MENU_SHELL (info_entry_priv->popup_menu), FALSE);
8825 g_object_unref (entry);
8826 g_slice_free (PopupInfo, info);
8830 gtk_entry_do_popup (GtkEntry *entry,
8831 GdkEventButton *event)
8833 PopupInfo *info = g_slice_new (PopupInfo);
8835 /* In order to know what entries we should make sensitive, we
8836 * ask for the current targets of the clipboard, and when
8837 * we get them, then we actually pop up the menu.
8839 info->entry = g_object_ref (entry);
8843 info->button = event->button;
8844 info->time = event->time;
8845 info->device = event->device;
8850 info->time = gtk_get_current_event_time ();
8851 info->device = NULL;
8854 gtk_clipboard_request_contents (gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_CLIPBOARD),
8855 gdk_atom_intern_static_string ("TARGETS"),
8856 popup_targets_received,
8861 gtk_entry_popup_menu (GtkWidget *widget)
8863 gtk_entry_do_popup (GTK_ENTRY (widget), NULL);
8868 gtk_entry_drag_begin (GtkWidget *widget,
8869 GdkDragContext *context)
8871 GtkEntry *entry = GTK_ENTRY (widget);
8872 GtkEntryPrivate *priv = entry->priv;
8875 for (i = 0; i < MAX_ICONS; i++)
8877 EntryIconInfo *icon_info = priv->icons[i];
8879 if (icon_info != NULL)
8881 if (icon_info->in_drag)
8885 pix = _gtk_icon_helper_ensure_pixbuf
8886 (icon_info->icon_helper,
8887 gtk_widget_get_style_context (GTK_WIDGET (entry)));
8888 gtk_drag_set_icon_pixbuf (context, pix, -2, -2);
8890 g_object_unref (pix);
8897 gtk_entry_drag_end (GtkWidget *widget,
8898 GdkDragContext *context)
8900 GtkEntry *entry = GTK_ENTRY (widget);
8901 GtkEntryPrivate *priv = entry->priv;
8904 for (i = 0; i < MAX_ICONS; i++)
8906 EntryIconInfo *icon_info = priv->icons[i];
8908 if (icon_info != NULL)
8909 icon_info->in_drag = 0;
8914 gtk_entry_drag_leave (GtkWidget *widget,
8915 GdkDragContext *context,
8918 GtkEntry *entry = GTK_ENTRY (widget);
8919 GtkEntryPrivate *priv = entry->priv;
8921 priv->dnd_position = -1;
8922 gtk_widget_queue_draw (widget);
8926 gtk_entry_drag_drop (GtkWidget *widget,
8927 GdkDragContext *context,
8932 GtkEntry *entry = GTK_ENTRY (widget);
8933 GtkEntryPrivate *priv = entry->priv;
8934 GdkAtom target = GDK_NONE;
8937 target = gtk_drag_dest_find_target (widget, context, NULL);
8939 if (target != GDK_NONE)
8940 gtk_drag_get_data (widget, context, target, time);
8942 gtk_drag_finish (context, FALSE, FALSE, time);
8948 gtk_entry_drag_motion (GtkWidget *widget,
8949 GdkDragContext *context,
8954 GtkEntry *entry = GTK_ENTRY (widget);
8955 GtkEntryPrivate *priv = entry->priv;
8956 GtkStyleContext *style_context;
8957 GtkWidget *source_widget;
8958 GdkDragAction suggested_action;
8959 gint new_position, old_position;
8963 style_context = gtk_widget_get_style_context (widget);
8964 gtk_style_context_get_padding (style_context, 0, &padding);
8968 old_position = priv->dnd_position;
8969 new_position = gtk_entry_find_position (entry, x + priv->scroll_offset);
8971 if (priv->editable &&
8972 gtk_drag_dest_find_target (widget, context, NULL) != GDK_NONE)
8974 source_widget = gtk_drag_get_source_widget (context);
8975 suggested_action = gdk_drag_context_get_suggested_action (context);
8977 if (!gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &sel1, &sel2) ||
8978 new_position < sel1 || new_position > sel2)
8980 if (source_widget == widget)
8982 /* Default to MOVE, unless the user has
8983 * pressed ctrl or alt to affect available actions
8985 if ((gdk_drag_context_get_actions (context) & GDK_ACTION_MOVE) != 0)
8986 suggested_action = GDK_ACTION_MOVE;
8989 priv->dnd_position = new_position;
8993 if (source_widget == widget)
8994 suggested_action = 0; /* Can't drop in selection where drag started */
8996 priv->dnd_position = -1;
9001 /* Entry not editable, or no text */
9002 suggested_action = 0;
9003 priv->dnd_position = -1;
9006 gdk_drag_status (context, suggested_action, time);
9008 if (priv->dnd_position != old_position)
9009 gtk_widget_queue_draw (widget);
9015 gtk_entry_drag_data_received (GtkWidget *widget,
9016 GdkDragContext *context,
9019 GtkSelectionData *selection_data,
9023 GtkEntry *entry = GTK_ENTRY (widget);
9024 GtkEntryPrivate *priv = entry->priv;
9025 GtkEditable *editable = GTK_EDITABLE (widget);
9026 GtkStyleContext *style_context;
9030 str = (gchar *) gtk_selection_data_get_text (selection_data);
9032 style_context = gtk_widget_get_style_context (widget);
9033 gtk_style_context_get_padding (style_context, 0, &padding);
9037 if (str && priv->editable)
9043 if (priv->truncate_multiline)
9044 length = truncate_multiline (str);
9046 new_position = gtk_entry_find_position (entry, x + priv->scroll_offset);
9048 if (!gtk_editable_get_selection_bounds (editable, &sel1, &sel2) ||
9049 new_position < sel1 || new_position > sel2)
9051 gtk_editable_insert_text (editable, str, length, &new_position);
9055 /* Replacing selection */
9056 begin_change (entry);
9057 gtk_editable_delete_text (editable, sel1, sel2);
9058 gtk_editable_insert_text (editable, str, length, &sel1);
9062 gtk_drag_finish (context, TRUE, gdk_drag_context_get_selected_action (context) == GDK_ACTION_MOVE, time);
9066 /* Drag and drop didn't happen! */
9067 gtk_drag_finish (context, FALSE, FALSE, time);
9074 gtk_entry_drag_data_get (GtkWidget *widget,
9075 GdkDragContext *context,
9076 GtkSelectionData *selection_data,
9080 GtkEntry *entry = GTK_ENTRY (widget);
9081 GtkEntryPrivate *priv = entry->priv;
9082 GtkEditable *editable = GTK_EDITABLE (widget);
9083 gint sel_start, sel_end;
9086 /* If there is an icon drag going on, exit early. */
9087 for (i = 0; i < MAX_ICONS; i++)
9089 EntryIconInfo *icon_info = priv->icons[i];
9091 if (icon_info != NULL)
9093 if (icon_info->in_drag)
9098 if (gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end))
9100 gchar *str = gtk_entry_get_display_text (GTK_ENTRY (widget), sel_start, sel_end);
9102 gtk_selection_data_set_text (selection_data, str, -1);
9110 gtk_entry_drag_data_delete (GtkWidget *widget,
9111 GdkDragContext *context)
9113 GtkEntry *entry = GTK_ENTRY (widget);
9114 GtkEntryPrivate *priv = entry->priv;
9115 GtkEditable *editable = GTK_EDITABLE (widget);
9116 gint sel_start, sel_end;
9119 /* If there is an icon drag going on, exit early. */
9120 for (i = 0; i < MAX_ICONS; i++)
9122 EntryIconInfo *icon_info = priv->icons[i];
9124 if (icon_info != NULL)
9126 if (icon_info->in_drag)
9131 if (priv->editable &&
9132 gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end))
9133 gtk_editable_delete_text (editable, sel_start, sel_end);
9136 /* We display the cursor when
9138 * - the selection is empty, AND
9139 * - the widget has focus
9142 #define CURSOR_ON_MULTIPLIER 2
9143 #define CURSOR_OFF_MULTIPLIER 1
9144 #define CURSOR_PEND_MULTIPLIER 3
9145 #define CURSOR_DIVIDER 3
9148 cursor_blinks (GtkEntry *entry)
9150 GtkEntryPrivate *priv = entry->priv;
9152 if (gtk_widget_has_focus (GTK_WIDGET (entry)) &&
9154 priv->selection_bound == priv->current_pos)
9156 GtkSettings *settings;
9159 settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9160 g_object_get (settings, "gtk-cursor-blink", &blink, NULL);
9169 get_middle_click_paste (GtkEntry *entry)
9171 GtkSettings *settings;
9174 settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9175 g_object_get (settings, "gtk-enable-primary-paste", &paste, NULL);
9181 get_cursor_time (GtkEntry *entry)
9183 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9186 g_object_get (settings, "gtk-cursor-blink-time", &time, NULL);
9192 get_cursor_blink_timeout (GtkEntry *entry)
9194 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9197 g_object_get (settings, "gtk-cursor-blink-timeout", &timeout, NULL);
9203 show_cursor (GtkEntry *entry)
9205 GtkEntryPrivate *priv = entry->priv;
9208 if (!priv->cursor_visible)
9210 priv->cursor_visible = TRUE;
9212 widget = GTK_WIDGET (entry);
9213 if (gtk_widget_has_focus (widget) && priv->selection_bound == priv->current_pos)
9214 gtk_widget_queue_draw (widget);
9219 hide_cursor (GtkEntry *entry)
9221 GtkEntryPrivate *priv = entry->priv;
9224 if (priv->cursor_visible)
9226 priv->cursor_visible = FALSE;
9228 widget = GTK_WIDGET (entry);
9229 if (gtk_widget_has_focus (widget) && priv->selection_bound == priv->current_pos)
9230 gtk_widget_queue_draw (widget);
9238 blink_cb (gpointer data)
9241 GtkEntryPrivate *priv;
9244 entry = GTK_ENTRY (data);
9247 if (!gtk_widget_has_focus (GTK_WIDGET (entry)))
9249 g_warning ("GtkEntry - did not receive focus-out-event. If you\n"
9250 "connect a handler to this signal, it must return\n"
9251 "FALSE so the entry gets the event as well");
9253 gtk_entry_check_cursor_blink (entry);
9258 g_assert (priv->selection_bound == priv->current_pos);
9260 blink_timeout = get_cursor_blink_timeout (entry);
9261 if (priv->blink_time > 1000 * blink_timeout &&
9262 blink_timeout < G_MAXINT/1000)
9264 /* we've blinked enough without the user doing anything, stop blinking */
9265 show_cursor (entry);
9266 priv->blink_timeout = 0;
9268 else if (priv->cursor_visible)
9270 hide_cursor (entry);
9271 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_OFF_MULTIPLIER / CURSOR_DIVIDER,
9277 show_cursor (entry);
9278 priv->blink_time += get_cursor_time (entry);
9279 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
9284 /* Remove ourselves */
9289 gtk_entry_check_cursor_blink (GtkEntry *entry)
9291 GtkEntryPrivate *priv = entry->priv;
9293 if (cursor_blinks (entry))
9295 if (!priv->blink_timeout)
9297 show_cursor (entry);
9298 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
9305 if (priv->blink_timeout)
9307 g_source_remove (priv->blink_timeout);
9308 priv->blink_timeout = 0;
9311 priv->cursor_visible = TRUE;
9316 gtk_entry_pend_cursor_blink (GtkEntry *entry)
9318 GtkEntryPrivate *priv = entry->priv;
9320 if (cursor_blinks (entry))
9322 if (priv->blink_timeout != 0)
9323 g_source_remove (priv->blink_timeout);
9325 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_PEND_MULTIPLIER / CURSOR_DIVIDER,
9328 show_cursor (entry);
9333 gtk_entry_reset_blink_time (GtkEntry *entry)
9335 GtkEntryPrivate *priv = entry->priv;
9337 priv->blink_time = 0;
9343 gtk_entry_completion_timeout (gpointer data)
9345 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (data);
9346 GtkEntryPrivate *completion_entry_priv = GTK_ENTRY (completion->priv->entry)->priv;
9348 completion->priv->completion_timeout = 0;
9350 if (completion->priv->filter_model &&
9351 g_utf8_strlen (gtk_entry_get_text (GTK_ENTRY (completion->priv->entry)), -1)
9352 >= completion->priv->minimum_key_length)
9356 GtkTreeSelection *s;
9357 gboolean popup_single;
9359 gtk_entry_completion_complete (completion);
9360 matches = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->filter_model), NULL);
9362 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9364 s = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view));
9366 gtk_tree_selection_unselect_all (s);
9368 actions = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->actions), NULL);
9370 g_object_get (completion, "popup-single-match", &popup_single, NULL);
9371 if ((matches > (popup_single ? 0: 1)) || actions > 0)
9373 if (gtk_widget_get_visible (completion->priv->popup_window))
9374 _gtk_entry_completion_resize_popup (completion);
9376 _gtk_entry_completion_popup (completion, completion_entry_priv->completion_device);
9379 _gtk_entry_completion_popdown (completion);
9381 else if (gtk_widget_get_visible (completion->priv->popup_window))
9382 _gtk_entry_completion_popdown (completion);
9387 static inline gboolean
9388 keyval_is_cursor_move (guint keyval)
9390 if (keyval == GDK_KEY_Up || keyval == GDK_KEY_KP_Up)
9393 if (keyval == GDK_KEY_Down || keyval == GDK_KEY_KP_Down)
9396 if (keyval == GDK_KEY_Page_Up)
9399 if (keyval == GDK_KEY_Page_Down)
9406 gtk_entry_completion_key_press (GtkWidget *widget,
9410 gint matches, actions = 0;
9411 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
9413 if (!gtk_widget_get_mapped (completion->priv->popup_window))
9416 matches = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->filter_model), NULL);
9418 if (completion->priv->actions)
9419 actions = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->actions), NULL);
9421 if (keyval_is_cursor_move (event->keyval))
9423 GtkTreePath *path = NULL;
9425 if (event->keyval == GDK_KEY_Up || event->keyval == GDK_KEY_KP_Up)
9427 if (completion->priv->current_selected < 0)
9428 completion->priv->current_selected = matches + actions - 1;
9430 completion->priv->current_selected--;
9432 else if (event->keyval == GDK_KEY_Down || event->keyval == GDK_KEY_KP_Down)
9434 if (completion->priv->current_selected < matches + actions - 1)
9435 completion->priv->current_selected++;
9437 completion->priv->current_selected = -1;
9439 else if (event->keyval == GDK_KEY_Page_Up)
9441 if (completion->priv->current_selected < 0)
9442 completion->priv->current_selected = matches + actions - 1;
9443 else if (completion->priv->current_selected == 0)
9444 completion->priv->current_selected = -1;
9445 else if (completion->priv->current_selected < matches)
9447 completion->priv->current_selected -= PAGE_STEP;
9448 if (completion->priv->current_selected < 0)
9449 completion->priv->current_selected = 0;
9453 completion->priv->current_selected -= PAGE_STEP;
9454 if (completion->priv->current_selected < matches - 1)
9455 completion->priv->current_selected = matches - 1;
9458 else if (event->keyval == GDK_KEY_Page_Down)
9460 if (completion->priv->current_selected < 0)
9461 completion->priv->current_selected = 0;
9462 else if (completion->priv->current_selected < matches - 1)
9464 completion->priv->current_selected += PAGE_STEP;
9465 if (completion->priv->current_selected > matches - 1)
9466 completion->priv->current_selected = matches - 1;
9468 else if (completion->priv->current_selected == matches + actions - 1)
9470 completion->priv->current_selected = -1;
9474 completion->priv->current_selected += PAGE_STEP;
9475 if (completion->priv->current_selected > matches + actions - 1)
9476 completion->priv->current_selected = matches + actions - 1;
9480 if (completion->priv->current_selected < 0)
9482 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9483 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view)));
9485 if (completion->priv->inline_selection &&
9486 completion->priv->completion_prefix)
9488 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9489 completion->priv->completion_prefix);
9490 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9493 else if (completion->priv->current_selected < matches)
9495 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view)));
9497 path = gtk_tree_path_new_from_indices (completion->priv->current_selected, -1);
9498 gtk_tree_view_set_cursor (GTK_TREE_VIEW (completion->priv->tree_view),
9501 if (completion->priv->inline_selection)
9505 GtkTreeIter child_iter;
9506 GtkTreeModel *model = NULL;
9507 GtkTreeSelection *sel;
9510 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view));
9511 if (!gtk_tree_selection_get_selected (sel, &model, &iter))
9514 gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (model), &child_iter, &iter);
9515 model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model));
9517 if (completion->priv->completion_prefix == NULL)
9518 completion->priv->completion_prefix = g_strdup (gtk_entry_get_text (GTK_ENTRY (completion->priv->entry)));
9520 g_signal_emit_by_name (completion, "cursor-on-match", model,
9521 &child_iter, &entry_set);
9524 else if (completion->priv->current_selected - matches >= 0)
9526 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9528 path = gtk_tree_path_new_from_indices (completion->priv->current_selected - matches, -1);
9529 gtk_tree_view_set_cursor (GTK_TREE_VIEW (completion->priv->action_view),
9532 if (completion->priv->inline_selection &&
9533 completion->priv->completion_prefix)
9535 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9536 completion->priv->completion_prefix);
9537 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9541 gtk_tree_path_free (path);
9545 else if (event->keyval == GDK_KEY_Escape ||
9546 event->keyval == GDK_KEY_Left ||
9547 event->keyval == GDK_KEY_KP_Left ||
9548 event->keyval == GDK_KEY_Right ||
9549 event->keyval == GDK_KEY_KP_Right)
9551 gboolean retval = TRUE;
9553 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9554 _gtk_entry_completion_popdown (completion);
9556 if (completion->priv->current_selected < 0)
9559 goto keypress_completion_out;
9561 else if (completion->priv->inline_selection)
9563 /* Escape rejects the tentative completion */
9564 if (event->keyval == GDK_KEY_Escape)
9566 if (completion->priv->completion_prefix)
9567 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9568 completion->priv->completion_prefix);
9570 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry), "");
9573 /* Move the cursor to the end for Right/Esc, to the
9574 beginning for Left */
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);
9580 gtk_editable_set_position (GTK_EDITABLE (widget), 0);
9583 keypress_completion_out:
9584 if (completion->priv->inline_selection)
9586 g_free (completion->priv->completion_prefix);
9587 completion->priv->completion_prefix = NULL;
9592 else if (event->keyval == GDK_KEY_Tab ||
9593 event->keyval == GDK_KEY_KP_Tab ||
9594 event->keyval == GDK_KEY_ISO_Left_Tab)
9596 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9597 _gtk_entry_completion_popdown (completion);
9599 g_free (completion->priv->completion_prefix);
9600 completion->priv->completion_prefix = NULL;
9604 else if (event->keyval == GDK_KEY_ISO_Enter ||
9605 event->keyval == GDK_KEY_KP_Enter ||
9606 event->keyval == GDK_KEY_Return)
9609 GtkTreeModel *model = NULL;
9610 GtkTreeModel *child_model;
9611 GtkTreeIter child_iter;
9612 GtkTreeSelection *sel;
9613 gboolean retval = TRUE;
9615 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9616 _gtk_entry_completion_popdown (completion);
9618 if (completion->priv->current_selected < matches)
9622 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view));
9623 if (gtk_tree_selection_get_selected (sel, &model, &iter))
9625 gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (model), &child_iter, &iter);
9626 child_model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model));
9627 g_signal_handler_block (widget, completion->priv->changed_id);
9628 g_signal_emit_by_name (completion, "match-selected",
9629 child_model, &child_iter, &entry_set);
9630 g_signal_handler_unblock (widget, completion->priv->changed_id);
9636 gtk_tree_model_get (model, &iter,
9637 completion->priv->text_column, &str,
9640 gtk_entry_set_text (GTK_ENTRY (widget), str);
9642 /* move the cursor to the end */
9643 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9651 else if (completion->priv->current_selected - matches >= 0)
9653 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view));
9654 if (gtk_tree_selection_get_selected (sel, &model, &iter))
9658 path = gtk_tree_path_new_from_indices (completion->priv->current_selected - matches, -1);
9659 g_signal_emit_by_name (completion, "action-activated",
9660 gtk_tree_path_get_indices (path)[0]);
9661 gtk_tree_path_free (path);
9667 g_free (completion->priv->completion_prefix);
9668 completion->priv->completion_prefix = NULL;
9677 gtk_entry_completion_changed (GtkWidget *widget,
9680 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
9681 GtkEntry *entry = GTK_ENTRY (widget);
9682 GtkEntryPrivate *priv = entry->priv;
9685 /* (re)install completion timeout */
9686 if (completion->priv->completion_timeout)
9687 g_source_remove (completion->priv->completion_timeout);
9689 if (!gtk_entry_get_text (entry))
9692 /* no need to normalize for this test */
9693 if (completion->priv->minimum_key_length > 0 &&
9694 strcmp ("", gtk_entry_get_text (entry)) == 0)
9696 if (gtk_widget_get_visible (completion->priv->popup_window))
9697 _gtk_entry_completion_popdown (completion);
9701 device = gtk_get_current_event_device ();
9703 if (device && gdk_device_get_source (device) == GDK_SOURCE_KEYBOARD)
9704 device = gdk_device_get_associated_device (device);
9707 priv->completion_device = device;
9709 completion->priv->completion_timeout =
9710 gdk_threads_add_timeout (COMPLETION_TIMEOUT,
9711 gtk_entry_completion_timeout,
9716 check_completion_callback (GtkEntryCompletion *completion)
9718 completion->priv->check_completion_idle = NULL;
9720 gtk_entry_completion_complete (completion);
9721 gtk_entry_completion_insert_prefix (completion);
9727 clear_completion_callback (GtkEntry *entry,
9730 if (pspec->name == I_("cursor-position") ||
9731 pspec->name == I_("selection-bound"))
9733 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
9735 completion->priv->has_completion = FALSE;
9740 accept_completion_callback (GtkEntry *entry)
9742 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
9744 if (completion->priv->has_completion)
9745 gtk_editable_set_position (GTK_EDITABLE (entry),
9746 gtk_entry_buffer_get_length (get_buffer (entry)));
9752 completion_insert_text_callback (GtkEntry *entry,
9756 GtkEntryCompletion *completion)
9758 /* idle to update the selection based on the file list */
9759 if (completion->priv->check_completion_idle == NULL)
9761 completion->priv->check_completion_idle = g_idle_source_new ();
9762 g_source_set_priority (completion->priv->check_completion_idle, G_PRIORITY_HIGH);
9763 g_source_set_closure (completion->priv->check_completion_idle,
9764 g_cclosure_new_object (G_CALLBACK (check_completion_callback),
9765 G_OBJECT (completion)));
9766 g_source_attach (completion->priv->check_completion_idle, NULL);
9771 completion_changed (GtkEntryCompletion *completion,
9775 GtkEntry *entry = GTK_ENTRY (data);
9777 if (pspec->name == I_("popup-completion") ||
9778 pspec->name == I_("inline-completion"))
9780 disconnect_completion_signals (entry, completion);
9781 connect_completion_signals (entry, completion);
9786 disconnect_completion_signals (GtkEntry *entry,
9787 GtkEntryCompletion *completion)
9789 g_signal_handlers_disconnect_by_func (completion,
9790 G_CALLBACK (completion_changed), entry);
9791 if (completion->priv->changed_id > 0 &&
9792 g_signal_handler_is_connected (entry, completion->priv->changed_id))
9794 g_signal_handler_disconnect (entry, completion->priv->changed_id);
9795 completion->priv->changed_id = 0;
9797 g_signal_handlers_disconnect_by_func (entry,
9798 G_CALLBACK (gtk_entry_completion_key_press), completion);
9799 if (completion->priv->insert_text_id > 0 &&
9800 g_signal_handler_is_connected (entry, completion->priv->insert_text_id))
9802 g_signal_handler_disconnect (entry, completion->priv->insert_text_id);
9803 completion->priv->insert_text_id = 0;
9805 g_signal_handlers_disconnect_by_func (entry,
9806 G_CALLBACK (completion_insert_text_callback), completion);
9807 g_signal_handlers_disconnect_by_func (entry,
9808 G_CALLBACK (clear_completion_callback), completion);
9809 g_signal_handlers_disconnect_by_func (entry,
9810 G_CALLBACK (accept_completion_callback), completion);
9814 connect_completion_signals (GtkEntry *entry,
9815 GtkEntryCompletion *completion)
9817 if (completion->priv->popup_completion)
9819 completion->priv->changed_id =
9820 g_signal_connect (entry, "changed",
9821 G_CALLBACK (gtk_entry_completion_changed), completion);
9822 g_signal_connect (entry, "key-press-event",
9823 G_CALLBACK (gtk_entry_completion_key_press), completion);
9826 if (completion->priv->inline_completion)
9828 completion->priv->insert_text_id =
9829 g_signal_connect (entry, "insert-text",
9830 G_CALLBACK (completion_insert_text_callback), completion);
9831 g_signal_connect (entry, "notify",
9832 G_CALLBACK (clear_completion_callback), completion);
9833 g_signal_connect (entry, "activate",
9834 G_CALLBACK (accept_completion_callback), completion);
9835 g_signal_connect (entry, "focus-out-event",
9836 G_CALLBACK (accept_completion_callback), completion);
9839 g_signal_connect (completion, "notify",
9840 G_CALLBACK (completion_changed), entry);
9844 * gtk_entry_set_completion:
9845 * @entry: A #GtkEntry
9846 * @completion: (allow-none): The #GtkEntryCompletion or %NULL
9848 * Sets @completion to be the auxiliary completion object to use with @entry.
9849 * All further configuration of the completion mechanism is done on
9850 * @completion using the #GtkEntryCompletion API. Completion is disabled if
9851 * @completion is set to %NULL.
9856 gtk_entry_set_completion (GtkEntry *entry,
9857 GtkEntryCompletion *completion)
9859 GtkEntryCompletion *old;
9861 g_return_if_fail (GTK_IS_ENTRY (entry));
9862 g_return_if_fail (!completion || GTK_IS_ENTRY_COMPLETION (completion));
9864 old = gtk_entry_get_completion (entry);
9866 if (old == completion)
9871 if (old->priv->completion_timeout)
9873 g_source_remove (old->priv->completion_timeout);
9874 old->priv->completion_timeout = 0;
9877 if (old->priv->check_completion_idle)
9879 g_source_destroy (old->priv->check_completion_idle);
9880 old->priv->check_completion_idle = NULL;
9883 if (gtk_widget_get_mapped (old->priv->popup_window))
9884 _gtk_entry_completion_popdown (old);
9886 disconnect_completion_signals (entry, old);
9887 old->priv->entry = NULL;
9889 g_object_unref (old);
9894 g_object_set_data (G_OBJECT (entry), I_(GTK_ENTRY_COMPLETION_KEY), NULL);
9898 /* hook into the entry */
9899 g_object_ref (completion);
9901 connect_completion_signals (entry, completion);
9902 completion->priv->entry = GTK_WIDGET (entry);
9903 g_object_set_data (G_OBJECT (entry), I_(GTK_ENTRY_COMPLETION_KEY), completion);
9905 g_object_notify (G_OBJECT (entry), "completion");
9909 * gtk_entry_get_completion:
9910 * @entry: A #GtkEntry
9912 * Returns the auxiliary completion object currently in use by @entry.
9914 * Return value: (transfer none): The auxiliary completion object currently
9919 GtkEntryCompletion *
9920 gtk_entry_get_completion (GtkEntry *entry)
9922 GtkEntryCompletion *completion;
9924 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
9926 completion = GTK_ENTRY_COMPLETION (g_object_get_data (G_OBJECT (entry),
9927 GTK_ENTRY_COMPLETION_KEY));
9933 * gtk_entry_set_cursor_hadjustment:
9934 * @entry: a #GtkEntry
9935 * @adjustment: an adjustment which should be adjusted when the cursor
9936 * is moved, or %NULL
9938 * Hooks up an adjustment to the cursor position in an entry, so that when
9939 * the cursor is moved, the adjustment is scrolled to show that position.
9940 * See gtk_scrolled_window_get_hadjustment() for a typical way of obtaining
9943 * The adjustment has to be in pixel units and in the same coordinate system
9949 gtk_entry_set_cursor_hadjustment (GtkEntry *entry,
9950 GtkAdjustment *adjustment)
9952 g_return_if_fail (GTK_IS_ENTRY (entry));
9954 g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
9957 g_object_ref (adjustment);
9959 g_object_set_qdata_full (G_OBJECT (entry),
9960 quark_cursor_hadjustment,
9966 * gtk_entry_get_cursor_hadjustment:
9967 * @entry: a #GtkEntry
9969 * Retrieves the horizontal cursor adjustment for the entry.
9970 * See gtk_entry_set_cursor_hadjustment().
9972 * Return value: (transfer none): the horizontal cursor adjustment, or %NULL
9973 * if none has been set.
9978 gtk_entry_get_cursor_hadjustment (GtkEntry *entry)
9980 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
9982 return g_object_get_qdata (G_OBJECT (entry), quark_cursor_hadjustment);
9986 * gtk_entry_set_progress_fraction:
9987 * @entry: a #GtkEntry
9988 * @fraction: fraction of the task that's been completed
9990 * Causes the entry's progress indicator to "fill in" the given
9991 * fraction of the bar. The fraction should be between 0.0 and 1.0,
9997 gtk_entry_set_progress_fraction (GtkEntry *entry,
10001 GtkEntryPrivate *private;
10002 gdouble old_fraction;
10003 gint x, y, width, height;
10004 gint old_x, old_y, old_width, old_height;
10006 g_return_if_fail (GTK_IS_ENTRY (entry));
10008 widget = GTK_WIDGET (entry);
10009 private = entry->priv;
10011 if (private->progress_pulse_mode)
10014 old_fraction = private->progress_fraction;
10016 if (gtk_widget_is_drawable (widget))
10017 get_progress_area (widget, &old_x, &old_y, &old_width, &old_height);
10019 fraction = CLAMP (fraction, 0.0, 1.0);
10021 private->progress_fraction = fraction;
10022 private->progress_pulse_mode = FALSE;
10023 private->progress_pulse_current = 0.0;
10025 if (gtk_widget_is_drawable (widget))
10027 get_progress_area (widget, &x, &y, &width, &height);
10029 if ((x != old_x) || (y != old_y) || (width != old_width) || (height != old_height))
10030 gtk_widget_queue_draw (widget);
10033 if (fraction != old_fraction)
10034 g_object_notify (G_OBJECT (entry), "progress-fraction");
10038 * gtk_entry_get_progress_fraction:
10039 * @entry: a #GtkEntry
10041 * Returns the current fraction of the task that's been completed.
10042 * See gtk_entry_set_progress_fraction().
10044 * Return value: a fraction from 0.0 to 1.0
10049 gtk_entry_get_progress_fraction (GtkEntry *entry)
10051 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
10053 return entry->priv->progress_fraction;
10057 * gtk_entry_set_progress_pulse_step:
10058 * @entry: a #GtkEntry
10059 * @fraction: fraction between 0.0 and 1.0
10061 * Sets the fraction of total entry width to move the progress
10062 * bouncing block for each call to gtk_entry_progress_pulse().
10067 gtk_entry_set_progress_pulse_step (GtkEntry *entry,
10070 GtkEntryPrivate *private;
10072 g_return_if_fail (GTK_IS_ENTRY (entry));
10074 private = entry->priv;
10076 fraction = CLAMP (fraction, 0.0, 1.0);
10078 if (fraction != private->progress_pulse_fraction)
10080 private->progress_pulse_fraction = fraction;
10082 gtk_widget_queue_draw (GTK_WIDGET (entry));
10084 g_object_notify (G_OBJECT (entry), "progress-pulse-step");
10089 * gtk_entry_get_progress_pulse_step:
10090 * @entry: a #GtkEntry
10092 * Retrieves the pulse step set with gtk_entry_set_progress_pulse_step().
10094 * Return value: a fraction from 0.0 to 1.0
10099 gtk_entry_get_progress_pulse_step (GtkEntry *entry)
10101 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
10103 return entry->priv->progress_pulse_fraction;
10107 * gtk_entry_progress_pulse:
10108 * @entry: a #GtkEntry
10110 * Indicates that some progress is made, but you don't know how much.
10111 * Causes the entry's progress indicator to enter "activity mode,"
10112 * where a block bounces back and forth. Each call to
10113 * gtk_entry_progress_pulse() causes the block to move by a little bit
10114 * (the amount of movement per pulse is determined by
10115 * gtk_entry_set_progress_pulse_step()).
10120 gtk_entry_progress_pulse (GtkEntry *entry)
10122 GtkEntryPrivate *private;
10124 g_return_if_fail (GTK_IS_ENTRY (entry));
10126 private = entry->priv;
10128 if (private->progress_pulse_mode)
10130 if (private->progress_pulse_way_back)
10132 private->progress_pulse_current -= private->progress_pulse_fraction;
10134 if (private->progress_pulse_current < 0.0)
10136 private->progress_pulse_current = 0.0;
10137 private->progress_pulse_way_back = FALSE;
10142 private->progress_pulse_current += private->progress_pulse_fraction;
10144 if (private->progress_pulse_current > 1.0 - private->progress_pulse_fraction)
10146 private->progress_pulse_current = 1.0 - private->progress_pulse_fraction;
10147 private->progress_pulse_way_back = TRUE;
10153 private->progress_fraction = 0.0;
10154 private->progress_pulse_mode = TRUE;
10155 private->progress_pulse_way_back = FALSE;
10156 private->progress_pulse_current = 0.0;
10159 gtk_widget_queue_draw (GTK_WIDGET (entry));
10163 * gtk_entry_set_placeholder_text:
10164 * @entry: a #GtkEntry
10165 * @text: a string to be displayed when @entry is empty an unfocused, or %NULL
10167 * Sets text to be displayed in @entry when it is empty and unfocused.
10168 * This can be used to give a visual hint of the expected contents of
10171 * Note that since the placeholder text gets removed when the entry
10172 * received focus, using this feature is a bit problematic if the entry
10173 * is given the initial focus in a window. Sometimes this can be
10174 * worked around by delaying the initial focus setting until the
10175 * first key event arrives.
10180 gtk_entry_set_placeholder_text (GtkEntry *entry,
10183 GtkEntryPrivate *priv;
10185 g_return_if_fail (GTK_IS_ENTRY (entry));
10187 priv = entry->priv;
10189 if (g_strcmp0 (priv->placeholder_text, text) == 0)
10192 g_free (priv->placeholder_text);
10193 priv->placeholder_text = g_strdup (text);
10195 gtk_entry_recompute (entry);
10197 g_object_notify (G_OBJECT (entry), "placeholder-text");
10201 * gtk_entry_get_placeholder_text:
10202 * @entry: a #GtkEntry
10204 * Retrieves the text that will be displayed when @entry is empty and unfocused
10206 * Returns: a pointer to the placeholder text as a string. This string points to internally allocated
10207 * storage in the widget and must not be freed, modified or stored.
10212 gtk_entry_get_placeholder_text (GtkEntry *entry)
10214 GtkEntryPrivate *priv;
10216 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
10218 priv = entry->priv;
10220 return priv->placeholder_text;
10223 /* Caps Lock warning for password entries */
10226 show_capslock_feedback (GtkEntry *entry,
10229 GtkEntryPrivate *priv = entry->priv;
10231 if (gtk_entry_get_icon_storage_type (entry, GTK_ENTRY_ICON_SECONDARY) == GTK_IMAGE_EMPTY)
10233 gtk_entry_set_icon_from_stock (entry, GTK_ENTRY_ICON_SECONDARY, GTK_STOCK_CAPS_LOCK_WARNING);
10234 gtk_entry_set_icon_activatable (entry, GTK_ENTRY_ICON_SECONDARY, FALSE);
10235 priv->caps_lock_warning_shown = TRUE;
10238 if (priv->caps_lock_warning_shown)
10239 gtk_entry_set_icon_tooltip_text (entry, GTK_ENTRY_ICON_SECONDARY, text);
10241 g_warning ("Can't show Caps Lock warning, since secondary icon is set");
10245 remove_capslock_feedback (GtkEntry *entry)
10247 GtkEntryPrivate *priv = entry->priv;
10249 if (priv->caps_lock_warning_shown)
10251 gtk_entry_set_icon_from_stock (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
10252 priv->caps_lock_warning_shown = FALSE;
10257 keymap_state_changed (GdkKeymap *keymap,
10260 GtkEntryPrivate *priv = entry->priv;
10263 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL && priv->caps_lock_warning)
10265 if (gdk_keymap_get_caps_lock_state (keymap))
10266 text = _("Caps Lock is on");
10270 show_capslock_feedback (entry, text);
10272 remove_capslock_feedback (entry);
10276 * _gtk_entry_set_is_cell_renderer:
10277 * @entry: a #GtkEntry
10278 * @is_cell_renderer: new value
10280 * This is a helper function for GtkComboBox. A GtkEntry in a GtkComboBox
10281 * is supposed to behave like a GtkCellEditable when placed in a combo box.
10283 * I.e take up its allocation and get GtkEntry->is_cell_renderer = TRUE.
10287 _gtk_entry_set_is_cell_renderer (GtkEntry *entry,
10288 gboolean is_cell_renderer)
10290 entry->priv->is_cell_renderer = is_cell_renderer;