1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* GTK - The GIMP Toolkit
3 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * Copyright (C) 2004-2006 Christian Hammond
5 * Copyright (C) 2008 Cody Russell
6 * Copyright (C) 2008 Red Hat, Inc.
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
25 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
26 * file for a list of people on the GTK+ Team. See the ChangeLog
27 * files for a list of changes. These files are distributed with
28 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
36 #include "gtkbindings.h"
37 #include "gtkcelleditable.h"
38 #include "gtkclipboard.h"
41 #include "gtkentrybuffer.h"
42 #include "gtkiconhelperprivate.h"
43 #include "gtkimagemenuitem.h"
44 #include "gtkimcontextsimple.h"
45 #include "gtkimmulticontext.h"
49 #include "gtkmarshalers.h"
51 #include "gtkmenuitem.h"
52 #include "gtkseparatormenuitem.h"
53 #include "gtkselection.h"
54 #include "gtksettings.h"
55 #include "gtkspinbutton.h"
57 #include "gtktextutil.h"
58 #include "gtkwindow.h"
59 #include "gtktreeview.h"
60 #include "gtktreeselection.h"
61 #include "gtktypebuiltins.h"
62 #include "gtkprivate.h"
63 #include "gtkentryprivate.h"
64 #include "gtkcelllayout.h"
65 #include "gtktooltip.h"
66 #include "gtkiconfactory.h"
67 #include "gtkicontheme.h"
68 #include "gtkwidgetprivate.h"
69 #include "gtkstylecontextprivate.h"
71 #include "a11y/gtkentryaccessible.h"
75 * @Short_description: A single line text entry field
77 * @See_also: #GtkTextView, #GtkEntryCompletion
79 * The #GtkEntry widget is a single line text entry
80 * widget. A fairly large set of key bindings are supported
81 * by default. If the entered text is longer than the allocation
82 * of the widget, the widget will scroll so that the cursor
83 * position is visible.
85 * When using an entry for passwords and other sensitive information,
86 * it can be put into "password mode" using gtk_entry_set_visibility().
87 * In this mode, entered text is displayed using a 'invisible' character.
88 * By default, GTK+ picks the best invisible character that is available
89 * in the current font, but it can be changed with
90 * gtk_entry_set_invisible_char(). Since 2.16, GTK+ displays a warning
91 * when Caps Lock or input methods might interfere with entering text in
92 * a password entry. The warning can be turned off with the
93 * #GtkEntry:caps-lock-warning property.
95 * Since 2.16, GtkEntry has the ability to display progress or activity
96 * information behind the text. To make an entry display such information,
97 * use gtk_entry_set_progress_fraction() or gtk_entry_set_progress_pulse_step().
99 * Additionally, GtkEntry can show icons at either side of the entry. These
100 * icons can be activatable by clicking, can be set up as drag source and
101 * can have tooltips. To add an icon, use gtk_entry_set_icon_from_gicon() or
102 * one of the various other functions that set an icon from a stock id, an
103 * icon name or a pixbuf. To trigger an action when the user clicks an icon,
104 * connect to the #GtkEntry::icon-press signal. To allow DND operations
105 * from an icon, use gtk_entry_set_icon_drag_source(). To set a tooltip on
106 * an icon, use gtk_entry_set_icon_tooltip_text() or the corresponding function
109 * Note that functionality or information that is only available by clicking
110 * on an icon in an entry may not be accessible at all to users which are not
111 * able to use a mouse or other pointing device. It is therefore recommended
112 * that any such functionality should also be available by other means, e.g.
113 * via the context menu of the entry.
117 #define GTK_ENTRY_COMPLETION_KEY "gtk-entry-completion-key"
119 #define MIN_ENTRY_WIDTH 150
120 #define DRAW_TIMEOUT 20
121 #define COMPLETION_TIMEOUT 300
122 #define PASSWORD_HINT_MAX 8
127 #define IS_VALID_ICON_POSITION(pos) \
128 ((pos) == GTK_ENTRY_ICON_PRIMARY || \
129 (pos) == GTK_ENTRY_ICON_SECONDARY)
131 static const GtkBorder default_inner_border = { 2, 2, 2, 2 };
132 static GQuark quark_inner_border = 0;
133 static GQuark quark_password_hint = 0;
134 static GQuark quark_cursor_hadjustment = 0;
135 static GQuark quark_capslock_feedback = 0;
137 typedef struct _EntryIconInfo EntryIconInfo;
138 typedef struct _GtkEntryPasswordHint GtkEntryPasswordHint;
139 typedef struct _GtkEntryCapslockFeedback GtkEntryCapslockFeedback;
141 struct _GtkEntryPrivate
143 EntryIconInfo *icons[MAX_ICONS];
145 GtkEntryBuffer *buffer;
146 GtkIMContext *im_context;
147 GtkShadowType shadow_type;
148 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 */
174 gint selection_bound;
180 gunichar invisible_char;
183 guint blink_time; /* time in msec the cursor has blinked since last user event */
185 guint recompute_idle;
187 guint16 x_text_size; /* allocated size, in bytes */
188 guint16 x_n_bytes; /* length in use, in bytes */
190 guint16 preedit_length; /* length of preedit string, in bytes */
191 guint16 preedit_cursor; /* offset of cursor within preedit string, in chars */
195 guint overwrite_mode : 1;
198 guint activates_default : 1;
199 guint cache_includes_preedit : 1;
200 guint caps_lock_warning : 1;
201 guint caps_lock_warning_shown : 1;
202 guint change_count : 8;
203 guint cursor_visible : 1;
204 guint editing_canceled : 1; /* Only used by GtkCellRendererText */
206 guint in_click : 1; /* Flag so we don't select all when clicking in entry to focus in */
207 guint is_cell_renderer : 1;
208 guint invisible_char_set : 1;
209 guint interior_focus : 1;
210 guint mouse_cursor_obscured : 1;
211 guint need_im_reset : 1;
212 guint progress_pulse_mode : 1;
213 guint progress_pulse_way_back : 1;
214 guint real_changed : 1;
215 guint resolved_dir : 4; /* PangoDirection */
216 guint select_words : 1;
217 guint select_lines : 1;
218 guint truncate_multiline : 1;
221 struct _EntryIconInfo
225 guint insensitive : 1;
226 guint nonactivatable : 1;
231 GtkIconHelper *icon_helper;
233 GtkTargetList *target_list;
234 GdkDragAction actions;
237 struct _GtkEntryPasswordHint
239 gint position; /* Position (in text) of the last password hint */
240 guint source_id; /* Timeout source id */
243 struct _GtkEntryCapslockFeedback
270 PROP_CURSOR_POSITION,
271 PROP_SELECTION_BOUND,
278 PROP_ACTIVATES_DEFAULT,
283 PROP_TRUNCATE_MULTILINE,
287 PROP_INVISIBLE_CHAR_SET,
288 PROP_CAPS_LOCK_WARNING,
289 PROP_PROGRESS_FRACTION,
290 PROP_PROGRESS_PULSE_STEP,
292 PROP_PIXBUF_SECONDARY,
294 PROP_STOCK_SECONDARY,
295 PROP_ICON_NAME_PRIMARY,
296 PROP_ICON_NAME_SECONDARY,
298 PROP_GICON_SECONDARY,
299 PROP_STORAGE_TYPE_PRIMARY,
300 PROP_STORAGE_TYPE_SECONDARY,
301 PROP_ACTIVATABLE_PRIMARY,
302 PROP_ACTIVATABLE_SECONDARY,
303 PROP_SENSITIVE_PRIMARY,
304 PROP_SENSITIVE_SECONDARY,
305 PROP_TOOLTIP_TEXT_PRIMARY,
306 PROP_TOOLTIP_TEXT_SECONDARY,
307 PROP_TOOLTIP_MARKUP_PRIMARY,
308 PROP_TOOLTIP_MARKUP_SECONDARY,
310 PROP_EDITING_CANCELED,
311 PROP_PLACEHOLDER_TEXT,
315 static guint signals[LAST_SIGNAL] = { 0 };
324 DISPLAY_NORMAL, /* The entry text is being shown */
325 DISPLAY_INVISIBLE, /* In invisible mode, text replaced by (eg) bullets */
326 DISPLAY_BLANK /* In invisible mode, nothing shown at all */
331 static void gtk_entry_editable_init (GtkEditableInterface *iface);
332 static void gtk_entry_cell_editable_init (GtkCellEditableIface *iface);
333 static void gtk_entry_set_property (GObject *object,
337 static void gtk_entry_get_property (GObject *object,
341 static void gtk_entry_finalize (GObject *object);
342 static void gtk_entry_dispose (GObject *object);
346 static void gtk_entry_destroy (GtkWidget *widget);
347 static void gtk_entry_realize (GtkWidget *widget);
348 static void gtk_entry_unrealize (GtkWidget *widget);
349 static void gtk_entry_map (GtkWidget *widget);
350 static void gtk_entry_unmap (GtkWidget *widget);
351 static void gtk_entry_get_preferred_width (GtkWidget *widget,
354 static void gtk_entry_get_preferred_height (GtkWidget *widget,
357 static void gtk_entry_size_allocate (GtkWidget *widget,
358 GtkAllocation *allocation);
359 static void gtk_entry_draw_frame (GtkWidget *widget,
360 GtkStyleContext *context,
362 static void gtk_entry_draw_progress (GtkWidget *widget,
363 GtkStyleContext *context,
365 static gint gtk_entry_draw (GtkWidget *widget,
367 static gint gtk_entry_button_press (GtkWidget *widget,
368 GdkEventButton *event);
369 static gint gtk_entry_button_release (GtkWidget *widget,
370 GdkEventButton *event);
371 static gint gtk_entry_enter_notify (GtkWidget *widget,
372 GdkEventCrossing *event);
373 static gint gtk_entry_leave_notify (GtkWidget *widget,
374 GdkEventCrossing *event);
375 static gint gtk_entry_motion_notify (GtkWidget *widget,
376 GdkEventMotion *event);
377 static gint gtk_entry_key_press (GtkWidget *widget,
379 static gint gtk_entry_key_release (GtkWidget *widget,
381 static gint gtk_entry_focus_in (GtkWidget *widget,
382 GdkEventFocus *event);
383 static gint gtk_entry_focus_out (GtkWidget *widget,
384 GdkEventFocus *event);
385 static void gtk_entry_grab_focus (GtkWidget *widget);
386 static void gtk_entry_style_updated (GtkWidget *widget);
387 static gboolean gtk_entry_query_tooltip (GtkWidget *widget,
390 gboolean keyboard_tip,
391 GtkTooltip *tooltip);
392 static void gtk_entry_direction_changed (GtkWidget *widget,
393 GtkTextDirection previous_dir);
394 static void gtk_entry_state_flags_changed (GtkWidget *widget,
395 GtkStateFlags previous_state);
396 static void gtk_entry_screen_changed (GtkWidget *widget,
397 GdkScreen *old_screen);
399 static gboolean gtk_entry_drag_drop (GtkWidget *widget,
400 GdkDragContext *context,
404 static gboolean gtk_entry_drag_motion (GtkWidget *widget,
405 GdkDragContext *context,
409 static void gtk_entry_drag_leave (GtkWidget *widget,
410 GdkDragContext *context,
412 static void gtk_entry_drag_data_received (GtkWidget *widget,
413 GdkDragContext *context,
416 GtkSelectionData *selection_data,
419 static void gtk_entry_drag_data_get (GtkWidget *widget,
420 GdkDragContext *context,
421 GtkSelectionData *selection_data,
424 static void gtk_entry_drag_data_delete (GtkWidget *widget,
425 GdkDragContext *context);
426 static void gtk_entry_drag_begin (GtkWidget *widget,
427 GdkDragContext *context);
428 static void gtk_entry_drag_end (GtkWidget *widget,
429 GdkDragContext *context);
432 /* GtkEditable method implementations
434 static void gtk_entry_insert_text (GtkEditable *editable,
435 const gchar *new_text,
436 gint new_text_length,
438 static void gtk_entry_delete_text (GtkEditable *editable,
441 static gchar * gtk_entry_get_chars (GtkEditable *editable,
444 static void gtk_entry_real_set_position (GtkEditable *editable,
446 static gint gtk_entry_get_position (GtkEditable *editable);
447 static void gtk_entry_set_selection_bounds (GtkEditable *editable,
450 static gboolean gtk_entry_get_selection_bounds (GtkEditable *editable,
454 /* GtkCellEditable method implementations
456 static void gtk_entry_start_editing (GtkCellEditable *cell_editable,
459 /* Default signal handlers
461 static void gtk_entry_real_insert_text (GtkEditable *editable,
462 const gchar *new_text,
463 gint new_text_length,
465 static void gtk_entry_real_delete_text (GtkEditable *editable,
468 static void gtk_entry_move_cursor (GtkEntry *entry,
469 GtkMovementStep step,
471 gboolean extend_selection);
472 static void gtk_entry_insert_at_cursor (GtkEntry *entry,
474 static void gtk_entry_delete_from_cursor (GtkEntry *entry,
477 static void gtk_entry_backspace (GtkEntry *entry);
478 static void gtk_entry_cut_clipboard (GtkEntry *entry);
479 static void gtk_entry_copy_clipboard (GtkEntry *entry);
480 static void gtk_entry_paste_clipboard (GtkEntry *entry);
481 static void gtk_entry_toggle_overwrite (GtkEntry *entry);
482 static void gtk_entry_select_all (GtkEntry *entry);
483 static void gtk_entry_real_activate (GtkEntry *entry);
484 static gboolean gtk_entry_popup_menu (GtkWidget *widget);
486 static void keymap_direction_changed (GdkKeymap *keymap,
488 static void keymap_state_changed (GdkKeymap *keymap,
490 static void remove_capslock_feedback (GtkEntry *entry);
492 /* IM Context Callbacks
494 static void gtk_entry_commit_cb (GtkIMContext *context,
497 static void gtk_entry_preedit_changed_cb (GtkIMContext *context,
499 static gboolean gtk_entry_retrieve_surrounding_cb (GtkIMContext *context,
501 static gboolean gtk_entry_delete_surrounding_cb (GtkIMContext *context,
508 static void gtk_entry_enter_text (GtkEntry *entry,
510 static void gtk_entry_set_positions (GtkEntry *entry,
512 gint selection_bound);
513 static void gtk_entry_draw_text (GtkEntry *entry,
515 static void gtk_entry_draw_cursor (GtkEntry *entry,
518 static PangoLayout *gtk_entry_ensure_layout (GtkEntry *entry,
519 gboolean include_preedit);
520 static void gtk_entry_reset_layout (GtkEntry *entry);
521 static void gtk_entry_recompute (GtkEntry *entry);
522 static gint gtk_entry_find_position (GtkEntry *entry,
524 static void gtk_entry_get_cursor_locations (GtkEntry *entry,
528 static void gtk_entry_adjust_scroll (GtkEntry *entry);
529 static gint gtk_entry_move_visually (GtkEntry *editable,
532 static gint gtk_entry_move_logically (GtkEntry *entry,
535 static gint gtk_entry_move_forward_word (GtkEntry *entry,
537 gboolean allow_whitespace);
538 static gint gtk_entry_move_backward_word (GtkEntry *entry,
540 gboolean allow_whitespace);
541 static void gtk_entry_delete_whitespace (GtkEntry *entry);
542 static void gtk_entry_select_word (GtkEntry *entry);
543 static void gtk_entry_select_line (GtkEntry *entry);
544 static void gtk_entry_paste (GtkEntry *entry,
546 static void gtk_entry_update_primary_selection (GtkEntry *entry);
547 static void gtk_entry_do_popup (GtkEntry *entry,
548 GdkEventButton *event);
549 static gboolean gtk_entry_mnemonic_activate (GtkWidget *widget,
550 gboolean group_cycling);
551 static void gtk_entry_check_cursor_blink (GtkEntry *entry);
552 static void gtk_entry_pend_cursor_blink (GtkEntry *entry);
553 static void gtk_entry_reset_blink_time (GtkEntry *entry);
554 static void gtk_entry_get_text_area_size (GtkEntry *entry,
559 static void get_text_area_size (GtkEntry *entry,
564 static void get_frame_size (GtkEntry *entry,
565 gboolean relative_to_window,
570 static void gtk_entry_move_adjustments (GtkEntry *entry);
571 static GdkPixbuf * gtk_entry_ensure_pixbuf (GtkEntry *entry,
572 GtkEntryIconPosition icon_pos);
573 static void gtk_entry_update_cached_style_values(GtkEntry *entry);
576 static gint gtk_entry_completion_timeout (gpointer data);
577 static gboolean gtk_entry_completion_key_press (GtkWidget *widget,
580 static void gtk_entry_completion_changed (GtkWidget *entry,
582 static gboolean check_completion_callback (GtkEntryCompletion *completion);
583 static void clear_completion_callback (GtkEntry *entry,
585 static gboolean accept_completion_callback (GtkEntry *entry);
586 static void completion_insert_text_callback (GtkEntry *entry,
590 GtkEntryCompletion *completion);
591 static void completion_changed (GtkEntryCompletion *completion,
594 static void disconnect_completion_signals (GtkEntry *entry,
595 GtkEntryCompletion *completion);
596 static void connect_completion_signals (GtkEntry *entry,
597 GtkEntryCompletion *completion);
599 static void begin_change (GtkEntry *entry);
600 static void end_change (GtkEntry *entry);
601 static void emit_changed (GtkEntry *entry);
603 static void buffer_inserted_text (GtkEntryBuffer *buffer,
608 static void buffer_deleted_text (GtkEntryBuffer *buffer,
612 static void buffer_notify_text (GtkEntryBuffer *buffer,
615 static void buffer_notify_length (GtkEntryBuffer *buffer,
618 static void buffer_notify_max_length (GtkEntryBuffer *buffer,
621 static void buffer_connect_signals (GtkEntry *entry);
622 static void buffer_disconnect_signals (GtkEntry *entry);
623 static GtkEntryBuffer *get_buffer (GtkEntry *entry);
625 G_DEFINE_TYPE_WITH_CODE (GtkEntry, gtk_entry, GTK_TYPE_WIDGET,
626 G_IMPLEMENT_INTERFACE (GTK_TYPE_EDITABLE,
627 gtk_entry_editable_init)
628 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_EDITABLE,
629 gtk_entry_cell_editable_init))
632 add_move_binding (GtkBindingSet *binding_set,
635 GtkMovementStep step,
638 g_return_if_fail ((modmask & GDK_SHIFT_MASK) == 0);
640 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
644 G_TYPE_BOOLEAN, FALSE);
646 /* Selection-extending version */
647 gtk_binding_entry_add_signal (binding_set, keyval, modmask | GDK_SHIFT_MASK,
651 G_TYPE_BOOLEAN, TRUE);
655 gtk_entry_class_init (GtkEntryClass *class)
657 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
658 GtkWidgetClass *widget_class;
659 GtkBindingSet *binding_set;
661 widget_class = (GtkWidgetClass*) class;
663 gobject_class->dispose = gtk_entry_dispose;
664 gobject_class->finalize = gtk_entry_finalize;
665 gobject_class->set_property = gtk_entry_set_property;
666 gobject_class->get_property = gtk_entry_get_property;
668 widget_class->destroy = gtk_entry_destroy;
669 widget_class->map = gtk_entry_map;
670 widget_class->unmap = gtk_entry_unmap;
671 widget_class->realize = gtk_entry_realize;
672 widget_class->unrealize = gtk_entry_unrealize;
673 widget_class->get_preferred_width = gtk_entry_get_preferred_width;
674 widget_class->get_preferred_height = gtk_entry_get_preferred_height;
675 widget_class->size_allocate = gtk_entry_size_allocate;
676 widget_class->draw = gtk_entry_draw;
677 widget_class->enter_notify_event = gtk_entry_enter_notify;
678 widget_class->leave_notify_event = gtk_entry_leave_notify;
679 widget_class->button_press_event = gtk_entry_button_press;
680 widget_class->button_release_event = gtk_entry_button_release;
681 widget_class->motion_notify_event = gtk_entry_motion_notify;
682 widget_class->key_press_event = gtk_entry_key_press;
683 widget_class->key_release_event = gtk_entry_key_release;
684 widget_class->focus_in_event = gtk_entry_focus_in;
685 widget_class->focus_out_event = gtk_entry_focus_out;
686 widget_class->grab_focus = gtk_entry_grab_focus;
687 widget_class->style_updated = gtk_entry_style_updated;
688 widget_class->query_tooltip = gtk_entry_query_tooltip;
689 widget_class->drag_begin = gtk_entry_drag_begin;
690 widget_class->drag_end = gtk_entry_drag_end;
691 widget_class->direction_changed = gtk_entry_direction_changed;
692 widget_class->state_flags_changed = gtk_entry_state_flags_changed;
693 widget_class->screen_changed = gtk_entry_screen_changed;
694 widget_class->mnemonic_activate = gtk_entry_mnemonic_activate;
696 widget_class->drag_drop = gtk_entry_drag_drop;
697 widget_class->drag_motion = gtk_entry_drag_motion;
698 widget_class->drag_leave = gtk_entry_drag_leave;
699 widget_class->drag_data_received = gtk_entry_drag_data_received;
700 widget_class->drag_data_get = gtk_entry_drag_data_get;
701 widget_class->drag_data_delete = gtk_entry_drag_data_delete;
703 widget_class->popup_menu = gtk_entry_popup_menu;
705 class->move_cursor = gtk_entry_move_cursor;
706 class->insert_at_cursor = gtk_entry_insert_at_cursor;
707 class->delete_from_cursor = gtk_entry_delete_from_cursor;
708 class->backspace = gtk_entry_backspace;
709 class->cut_clipboard = gtk_entry_cut_clipboard;
710 class->copy_clipboard = gtk_entry_copy_clipboard;
711 class->paste_clipboard = gtk_entry_paste_clipboard;
712 class->toggle_overwrite = gtk_entry_toggle_overwrite;
713 class->activate = gtk_entry_real_activate;
714 class->get_text_area_size = gtk_entry_get_text_area_size;
716 quark_inner_border = g_quark_from_static_string ("gtk-entry-inner-border");
717 quark_password_hint = g_quark_from_static_string ("gtk-entry-password-hint");
718 quark_cursor_hadjustment = g_quark_from_static_string ("gtk-hadjustment");
719 quark_capslock_feedback = g_quark_from_static_string ("gtk-entry-capslock-feedback");
721 g_object_class_override_property (gobject_class,
722 PROP_EDITING_CANCELED,
725 g_object_class_install_property (gobject_class,
727 g_param_spec_object ("buffer",
729 P_("Text buffer object which actually stores entry text"),
730 GTK_TYPE_ENTRY_BUFFER,
731 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT));
733 g_object_class_install_property (gobject_class,
734 PROP_CURSOR_POSITION,
735 g_param_spec_int ("cursor-position",
736 P_("Cursor Position"),
737 P_("The current position of the insertion cursor in chars"),
739 GTK_ENTRY_BUFFER_MAX_SIZE,
741 GTK_PARAM_READABLE));
743 g_object_class_install_property (gobject_class,
744 PROP_SELECTION_BOUND,
745 g_param_spec_int ("selection-bound",
746 P_("Selection Bound"),
747 P_("The position of the opposite end of the selection from the cursor in chars"),
749 GTK_ENTRY_BUFFER_MAX_SIZE,
751 GTK_PARAM_READABLE));
753 g_object_class_install_property (gobject_class,
755 g_param_spec_boolean ("editable",
757 P_("Whether the entry contents can be edited"),
759 GTK_PARAM_READWRITE));
761 g_object_class_install_property (gobject_class,
763 g_param_spec_int ("max-length",
764 P_("Maximum length"),
765 P_("Maximum number of characters for this entry. Zero if no maximum"),
767 GTK_ENTRY_BUFFER_MAX_SIZE,
769 GTK_PARAM_READWRITE));
770 g_object_class_install_property (gobject_class,
772 g_param_spec_boolean ("visibility",
774 P_("FALSE displays the \"invisible char\" instead of the actual text (password mode)"),
776 GTK_PARAM_READWRITE));
778 g_object_class_install_property (gobject_class,
780 g_param_spec_boolean ("has-frame",
782 P_("FALSE removes outside bevel from entry"),
784 GTK_PARAM_READWRITE));
787 * GtkEntry:inner-border:
789 * Sets the text area's border between the text and the frame.
791 * Deprecated: 3.4: Use the standard border and padding CSS properties;
792 * the value of this style property is ignored.
794 g_object_class_install_property (gobject_class,
796 g_param_spec_boxed ("inner-border",
798 P_("Border between text and frame. Overrides the inner-border style property"),
800 GTK_PARAM_READWRITE |
801 G_PARAM_DEPRECATED));
803 g_object_class_install_property (gobject_class,
805 g_param_spec_unichar ("invisible-char",
806 P_("Invisible character"),
807 P_("The character to use when masking entry contents (in \"password mode\")"),
809 GTK_PARAM_READWRITE));
811 g_object_class_install_property (gobject_class,
812 PROP_ACTIVATES_DEFAULT,
813 g_param_spec_boolean ("activates-default",
814 P_("Activates default"),
815 P_("Whether to activate the default widget (such as the default button in a dialog) when Enter is pressed"),
817 GTK_PARAM_READWRITE));
818 g_object_class_install_property (gobject_class,
820 g_param_spec_int ("width-chars",
821 P_("Width in chars"),
822 P_("Number of characters to leave space for in the entry"),
826 GTK_PARAM_READWRITE));
828 g_object_class_install_property (gobject_class,
830 g_param_spec_int ("scroll-offset",
832 P_("Number of pixels of the entry scrolled off the screen to the left"),
836 GTK_PARAM_READABLE));
838 g_object_class_install_property (gobject_class,
840 g_param_spec_string ("text",
842 P_("The contents of the entry"),
844 GTK_PARAM_READWRITE));
849 * The horizontal alignment, from 0 (left) to 1 (right).
850 * Reversed for RTL layouts.
854 g_object_class_install_property (gobject_class,
856 g_param_spec_float ("xalign",
858 P_("The horizontal alignment, from 0 (left) to 1 (right). Reversed for RTL layouts."),
862 GTK_PARAM_READWRITE));
865 * GtkEntry:truncate-multiline:
867 * When %TRUE, pasted multi-line text is truncated to the first line.
871 g_object_class_install_property (gobject_class,
872 PROP_TRUNCATE_MULTILINE,
873 g_param_spec_boolean ("truncate-multiline",
874 P_("Truncate multiline"),
875 P_("Whether to truncate multiline pastes to one line."),
877 GTK_PARAM_READWRITE));
880 * GtkEntry:shadow-type:
882 * Which kind of shadow to draw around the entry when
883 * #GtkEntry:has-frame is set to %TRUE.
887 g_object_class_install_property (gobject_class,
889 g_param_spec_enum ("shadow-type",
891 P_("Which kind of shadow to draw around the entry when has-frame is set"),
892 GTK_TYPE_SHADOW_TYPE,
894 GTK_PARAM_READWRITE));
897 * GtkEntry:overwrite-mode:
899 * If text is overwritten when typing in the #GtkEntry.
903 g_object_class_install_property (gobject_class,
905 g_param_spec_boolean ("overwrite-mode",
906 P_("Overwrite mode"),
907 P_("Whether new text overwrites existing text"),
909 GTK_PARAM_READWRITE));
912 * GtkEntry:text-length:
914 * The length of the text in the #GtkEntry.
918 g_object_class_install_property (gobject_class,
920 g_param_spec_uint ("text-length",
922 P_("Length of the text currently in the entry"),
926 GTK_PARAM_READABLE));
928 * GtkEntry:invisible-char-set:
930 * Whether the invisible char has been set for the #GtkEntry.
934 g_object_class_install_property (gobject_class,
935 PROP_INVISIBLE_CHAR_SET,
936 g_param_spec_boolean ("invisible-char-set",
937 P_("Invisible character set"),
938 P_("Whether the invisible character has been set"),
940 GTK_PARAM_READWRITE));
943 * GtkEntry:caps-lock-warning
945 * Whether password entries will show a warning when Caps Lock is on.
947 * Note that the warning is shown using a secondary icon, and thus
948 * does not work if you are using the secondary icon position for some
953 g_object_class_install_property (gobject_class,
954 PROP_CAPS_LOCK_WARNING,
955 g_param_spec_boolean ("caps-lock-warning",
956 P_("Caps Lock warning"),
957 P_("Whether password entries will show a warning when Caps Lock is on"),
959 GTK_PARAM_READWRITE));
962 * GtkEntry:progress-fraction:
964 * The current fraction of the task that's been completed.
968 g_object_class_install_property (gobject_class,
969 PROP_PROGRESS_FRACTION,
970 g_param_spec_double ("progress-fraction",
971 P_("Progress Fraction"),
972 P_("The current fraction of the task that's been completed"),
976 GTK_PARAM_READWRITE));
979 * GtkEntry:progress-pulse-step:
981 * The fraction of total entry width to move the progress
982 * bouncing block for each call to gtk_entry_progress_pulse().
986 g_object_class_install_property (gobject_class,
987 PROP_PROGRESS_PULSE_STEP,
988 g_param_spec_double ("progress-pulse-step",
989 P_("Progress Pulse Step"),
990 P_("The fraction of total entry width to move the progress bouncing block for each call to gtk_entry_progress_pulse()"),
994 GTK_PARAM_READWRITE));
997 * GtkEntry:placeholder-text:
999 * The text that will be displayed in the #GtkEntry when it is empty
1004 g_object_class_install_property (gobject_class,
1005 PROP_PLACEHOLDER_TEXT,
1006 g_param_spec_string ("placeholder-text",
1007 P_("Placeholder text"),
1008 P_("Show text in the entry when it's empty and unfocused"),
1010 GTK_PARAM_READWRITE));
1013 * GtkEntry:primary-icon-pixbuf:
1015 * A pixbuf to use as the primary icon for the entry.
1019 g_object_class_install_property (gobject_class,
1020 PROP_PIXBUF_PRIMARY,
1021 g_param_spec_object ("primary-icon-pixbuf",
1022 P_("Primary pixbuf"),
1023 P_("Primary pixbuf for the entry"),
1025 GTK_PARAM_READWRITE));
1028 * GtkEntry:secondary-icon-pixbuf:
1030 * An pixbuf to use as the secondary icon for the entry.
1034 g_object_class_install_property (gobject_class,
1035 PROP_PIXBUF_SECONDARY,
1036 g_param_spec_object ("secondary-icon-pixbuf",
1037 P_("Secondary pixbuf"),
1038 P_("Secondary pixbuf for the entry"),
1040 GTK_PARAM_READWRITE));
1043 * GtkEntry:primary-icon-stock:
1045 * The stock id to use for the primary icon for the entry.
1049 g_object_class_install_property (gobject_class,
1051 g_param_spec_string ("primary-icon-stock",
1052 P_("Primary stock ID"),
1053 P_("Stock ID for primary icon"),
1055 GTK_PARAM_READWRITE));
1058 * GtkEntry:secondary-icon-stock:
1060 * The stock id to use for the secondary icon for the entry.
1064 g_object_class_install_property (gobject_class,
1065 PROP_STOCK_SECONDARY,
1066 g_param_spec_string ("secondary-icon-stock",
1067 P_("Secondary stock ID"),
1068 P_("Stock ID for secondary icon"),
1070 GTK_PARAM_READWRITE));
1073 * GtkEntry:primary-icon-name:
1075 * The icon name to use for the primary icon for the entry.
1079 g_object_class_install_property (gobject_class,
1080 PROP_ICON_NAME_PRIMARY,
1081 g_param_spec_string ("primary-icon-name",
1082 P_("Primary icon name"),
1083 P_("Icon name for primary icon"),
1085 GTK_PARAM_READWRITE));
1088 * GtkEntry:secondary-icon-name:
1090 * The icon name to use for the secondary icon for the entry.
1094 g_object_class_install_property (gobject_class,
1095 PROP_ICON_NAME_SECONDARY,
1096 g_param_spec_string ("secondary-icon-name",
1097 P_("Secondary icon name"),
1098 P_("Icon name for secondary icon"),
1100 GTK_PARAM_READWRITE));
1103 * GtkEntry:primary-icon-gicon:
1105 * The #GIcon to use for the primary icon for the entry.
1109 g_object_class_install_property (gobject_class,
1111 g_param_spec_object ("primary-icon-gicon",
1112 P_("Primary GIcon"),
1113 P_("GIcon for primary icon"),
1115 GTK_PARAM_READWRITE));
1118 * GtkEntry:secondary-icon-gicon:
1120 * The #GIcon to use for the secondary icon for the entry.
1124 g_object_class_install_property (gobject_class,
1125 PROP_GICON_SECONDARY,
1126 g_param_spec_object ("secondary-icon-gicon",
1127 P_("Secondary GIcon"),
1128 P_("GIcon for secondary icon"),
1130 GTK_PARAM_READWRITE));
1133 * GtkEntry:primary-icon-storage-type:
1135 * The representation which is used for the primary icon of the entry.
1139 g_object_class_install_property (gobject_class,
1140 PROP_STORAGE_TYPE_PRIMARY,
1141 g_param_spec_enum ("primary-icon-storage-type",
1142 P_("Primary storage type"),
1143 P_("The representation being used for primary icon"),
1144 GTK_TYPE_IMAGE_TYPE,
1146 GTK_PARAM_READABLE));
1149 * GtkEntry:secondary-icon-storage-type:
1151 * The representation which is used for the secondary icon of the entry.
1155 g_object_class_install_property (gobject_class,
1156 PROP_STORAGE_TYPE_SECONDARY,
1157 g_param_spec_enum ("secondary-icon-storage-type",
1158 P_("Secondary storage type"),
1159 P_("The representation being used for secondary icon"),
1160 GTK_TYPE_IMAGE_TYPE,
1162 GTK_PARAM_READABLE));
1165 * GtkEntry:primary-icon-activatable:
1167 * Whether the primary icon is activatable.
1169 * GTK+ emits the #GtkEntry::icon-press and #GtkEntry::icon-release
1170 * signals only on sensitive, activatable icons.
1172 * Sensitive, but non-activatable icons can be used for purely
1173 * informational purposes.
1177 g_object_class_install_property (gobject_class,
1178 PROP_ACTIVATABLE_PRIMARY,
1179 g_param_spec_boolean ("primary-icon-activatable",
1180 P_("Primary icon activatable"),
1181 P_("Whether the primary icon is activatable"),
1183 GTK_PARAM_READWRITE));
1186 * GtkEntry:secondary-icon-activatable:
1188 * Whether the secondary icon is activatable.
1190 * GTK+ emits the #GtkEntry::icon-press and #GtkEntry::icon-release
1191 * signals only on sensitive, activatable icons.
1193 * Sensitive, but non-activatable icons can be used for purely
1194 * informational purposes.
1198 g_object_class_install_property (gobject_class,
1199 PROP_ACTIVATABLE_SECONDARY,
1200 g_param_spec_boolean ("secondary-icon-activatable",
1201 P_("Secondary icon activatable"),
1202 P_("Whether the secondary icon is activatable"),
1204 GTK_PARAM_READWRITE));
1208 * GtkEntry:primary-icon-sensitive:
1210 * Whether the primary icon is sensitive.
1212 * An insensitive icon appears grayed out. GTK+ does not emit the
1213 * #GtkEntry::icon-press and #GtkEntry::icon-release signals and
1214 * does not allow DND from insensitive icons.
1216 * An icon should be set insensitive if the action that would trigger
1217 * when clicked is currently not available.
1221 g_object_class_install_property (gobject_class,
1222 PROP_SENSITIVE_PRIMARY,
1223 g_param_spec_boolean ("primary-icon-sensitive",
1224 P_("Primary icon sensitive"),
1225 P_("Whether the primary icon is sensitive"),
1227 GTK_PARAM_READWRITE));
1230 * GtkEntry:secondary-icon-sensitive:
1232 * Whether the secondary icon is sensitive.
1234 * An insensitive icon appears grayed out. GTK+ does not emit the
1235 * #GtkEntry::icon-press and #GtkEntry::icon-release signals and
1236 * does not allow DND from insensitive icons.
1238 * An icon should be set insensitive if the action that would trigger
1239 * when clicked is currently not available.
1243 g_object_class_install_property (gobject_class,
1244 PROP_SENSITIVE_SECONDARY,
1245 g_param_spec_boolean ("secondary-icon-sensitive",
1246 P_("Secondary icon sensitive"),
1247 P_("Whether the secondary icon is sensitive"),
1249 GTK_PARAM_READWRITE));
1252 * GtkEntry:primary-icon-tooltip-text:
1254 * The contents of the tooltip on the primary icon.
1256 * Also see gtk_entry_set_icon_tooltip_text().
1260 g_object_class_install_property (gobject_class,
1261 PROP_TOOLTIP_TEXT_PRIMARY,
1262 g_param_spec_string ("primary-icon-tooltip-text",
1263 P_("Primary icon tooltip text"),
1264 P_("The contents of the tooltip on the primary icon"),
1266 GTK_PARAM_READWRITE));
1269 * GtkEntry:secondary-icon-tooltip-text:
1271 * The contents of the tooltip on the secondary icon.
1273 * Also see gtk_entry_set_icon_tooltip_text().
1277 g_object_class_install_property (gobject_class,
1278 PROP_TOOLTIP_TEXT_SECONDARY,
1279 g_param_spec_string ("secondary-icon-tooltip-text",
1280 P_("Secondary icon tooltip text"),
1281 P_("The contents of the tooltip on the secondary icon"),
1283 GTK_PARAM_READWRITE));
1286 * GtkEntry:primary-icon-tooltip-markup:
1288 * The contents of the tooltip on the primary icon, which is marked up
1289 * with the <link linkend="PangoMarkupFormat">Pango text markup
1292 * Also see gtk_entry_set_icon_tooltip_markup().
1296 g_object_class_install_property (gobject_class,
1297 PROP_TOOLTIP_MARKUP_PRIMARY,
1298 g_param_spec_string ("primary-icon-tooltip-markup",
1299 P_("Primary icon tooltip markup"),
1300 P_("The contents of the tooltip on the primary icon"),
1302 GTK_PARAM_READWRITE));
1305 * GtkEntry:secondary-icon-tooltip-markup:
1307 * The contents of the tooltip on the secondary icon, which is marked up
1308 * with the <link linkend="PangoMarkupFormat">Pango text markup
1311 * Also see gtk_entry_set_icon_tooltip_markup().
1315 g_object_class_install_property (gobject_class,
1316 PROP_TOOLTIP_MARKUP_SECONDARY,
1317 g_param_spec_string ("secondary-icon-tooltip-markup",
1318 P_("Secondary icon tooltip markup"),
1319 P_("The contents of the tooltip on the secondary icon"),
1321 GTK_PARAM_READWRITE));
1324 * GtkEntry:im-module:
1326 * Which IM (input method) module should be used for this entry.
1327 * See #GtkIMContext.
1329 * Setting this to a non-%NULL value overrides the
1330 * system-wide IM module setting. See the GtkSettings
1331 * #GtkSettings:gtk-im-module property.
1335 g_object_class_install_property (gobject_class,
1337 g_param_spec_string ("im-module",
1339 P_("Which IM module should be used"),
1341 GTK_PARAM_READWRITE));
1344 * GtkEntry:completion:
1346 * The auxiliary completion object to use with the entry.
1350 g_object_class_install_property (gobject_class,
1352 g_param_spec_object ("completion",
1354 P_("The auxiliary completion object"),
1355 GTK_TYPE_ENTRY_COMPLETION,
1356 GTK_PARAM_READWRITE));
1359 * GtkEntry:icon-prelight:
1361 * The prelight style property determines whether activatable
1362 * icons prelight on mouseover.
1366 gtk_widget_class_install_style_property (widget_class,
1367 g_param_spec_boolean ("icon-prelight",
1368 P_("Icon Prelight"),
1369 P_("Whether activatable icons should prelight when hovered"),
1371 GTK_PARAM_READABLE));
1374 * GtkEntry:progress-border:
1376 * The border around the progress bar in the entry.
1380 gtk_widget_class_install_style_property (widget_class,
1381 g_param_spec_boxed ("progress-border",
1382 P_("Progress Border"),
1383 P_("Border around the progress bar"),
1385 GTK_PARAM_READABLE));
1388 * GtkEntry:invisible-char:
1390 * The invisible character is used when masking entry contents (in
1391 * \"password mode\")"). When it is not explicitly set with the
1392 * #GtkEntry::invisible-char property, GTK+ determines the character
1393 * to use from a list of possible candidates, depending on availability
1394 * in the current font.
1396 * This style property allows the theme to prepend a character
1397 * to the list of candidates.
1401 gtk_widget_class_install_style_property (widget_class,
1402 g_param_spec_unichar ("invisible-char",
1403 P_("Invisible character"),
1404 P_("The character to use when masking entry contents (in \"password mode\")"),
1406 GTK_PARAM_READABLE));
1409 * GtkEntry::populate-popup:
1410 * @entry: The entry on which the signal is emitted
1411 * @menu: the menu that is being populated
1413 * The ::populate-popup signal gets emitted before showing the
1414 * context menu of the entry.
1416 * If you need to add items to the context menu, connect
1417 * to this signal and append your menuitems to the @menu.
1419 signals[POPULATE_POPUP] =
1420 g_signal_new (I_("populate-popup"),
1421 G_OBJECT_CLASS_TYPE (gobject_class),
1423 G_STRUCT_OFFSET (GtkEntryClass, populate_popup),
1425 _gtk_marshal_VOID__OBJECT,
1429 /* Action signals */
1432 * GtkEntry::activate:
1433 * @entry: The entry on which the signal is emitted
1435 * A <link linkend="keybinding-signals">keybinding signal</link>
1436 * which gets emitted when the user activates the entry.
1438 * Applications should not connect to it, but may emit it with
1439 * g_signal_emit_by_name() if they need to control activation
1442 * The default bindings for this signal are all forms of the Enter key.
1445 g_signal_new (I_("activate"),
1446 G_OBJECT_CLASS_TYPE (gobject_class),
1447 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1448 G_STRUCT_OFFSET (GtkEntryClass, activate),
1450 _gtk_marshal_VOID__VOID,
1452 widget_class->activate_signal = signals[ACTIVATE];
1455 * GtkEntry::move-cursor:
1456 * @entry: the object which received the signal
1457 * @step: the granularity of the move, as a #GtkMovementStep
1458 * @count: the number of @step units to move
1459 * @extend_selection: %TRUE if the move should extend the selection
1461 * The ::move-cursor signal is a
1462 * <link linkend="keybinding-signals">keybinding signal</link>
1463 * which gets emitted when the user initiates a cursor movement.
1464 * If the cursor is not visible in @entry, this signal causes
1465 * the viewport to be moved instead.
1467 * Applications should not connect to it, but may emit it with
1468 * g_signal_emit_by_name() if they need to control the cursor
1471 * The default bindings for this signal come in two variants,
1472 * the variant with the Shift modifier extends the selection,
1473 * the variant without the Shift modifer does not.
1474 * There are too many key combinations to list them all here.
1476 * <listitem>Arrow keys move by individual characters/lines</listitem>
1477 * <listitem>Ctrl-arrow key combinations move by words/paragraphs</listitem>
1478 * <listitem>Home/End keys move to the ends of the buffer</listitem>
1481 signals[MOVE_CURSOR] =
1482 g_signal_new (I_("move-cursor"),
1483 G_OBJECT_CLASS_TYPE (gobject_class),
1484 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1485 G_STRUCT_OFFSET (GtkEntryClass, move_cursor),
1487 _gtk_marshal_VOID__ENUM_INT_BOOLEAN,
1489 GTK_TYPE_MOVEMENT_STEP,
1494 * GtkEntry::insert-at-cursor:
1495 * @entry: the object which received the signal
1496 * @string: the string to insert
1498 * The ::insert-at-cursor signal is a
1499 * <link linkend="keybinding-signals">keybinding signal</link>
1500 * which gets emitted when the user initiates the insertion of a
1501 * fixed string at the cursor.
1503 * This signal has no default bindings.
1505 signals[INSERT_AT_CURSOR] =
1506 g_signal_new (I_("insert-at-cursor"),
1507 G_OBJECT_CLASS_TYPE (gobject_class),
1508 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1509 G_STRUCT_OFFSET (GtkEntryClass, insert_at_cursor),
1511 _gtk_marshal_VOID__STRING,
1516 * GtkEntry::delete-from-cursor:
1517 * @entry: the object which received the signal
1518 * @type: the granularity of the deletion, as a #GtkDeleteType
1519 * @count: the number of @type units to delete
1521 * The ::delete-from-cursor signal is a
1522 * <link linkend="keybinding-signals">keybinding signal</link>
1523 * which gets emitted when the user initiates a text deletion.
1525 * If the @type is %GTK_DELETE_CHARS, GTK+ deletes the selection
1526 * if there is one, otherwise it deletes the requested number
1529 * The default bindings for this signal are
1530 * Delete for deleting a character and Ctrl-Delete for
1533 signals[DELETE_FROM_CURSOR] =
1534 g_signal_new (I_("delete-from-cursor"),
1535 G_OBJECT_CLASS_TYPE (gobject_class),
1536 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1537 G_STRUCT_OFFSET (GtkEntryClass, delete_from_cursor),
1539 _gtk_marshal_VOID__ENUM_INT,
1541 GTK_TYPE_DELETE_TYPE,
1545 * GtkEntry::backspace:
1546 * @entry: the object which received the signal
1548 * The ::backspace signal is a
1549 * <link linkend="keybinding-signals">keybinding signal</link>
1550 * which gets emitted when the user asks for it.
1552 * The default bindings for this signal are
1553 * Backspace and Shift-Backspace.
1555 signals[BACKSPACE] =
1556 g_signal_new (I_("backspace"),
1557 G_OBJECT_CLASS_TYPE (gobject_class),
1558 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1559 G_STRUCT_OFFSET (GtkEntryClass, backspace),
1561 _gtk_marshal_VOID__VOID,
1565 * GtkEntry::cut-clipboard:
1566 * @entry: the object which received the signal
1568 * The ::cut-clipboard signal is a
1569 * <link linkend="keybinding-signals">keybinding signal</link>
1570 * which gets emitted to cut the selection to the clipboard.
1572 * The default bindings for this signal are
1573 * Ctrl-x and Shift-Delete.
1575 signals[CUT_CLIPBOARD] =
1576 g_signal_new (I_("cut-clipboard"),
1577 G_OBJECT_CLASS_TYPE (gobject_class),
1578 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1579 G_STRUCT_OFFSET (GtkEntryClass, cut_clipboard),
1581 _gtk_marshal_VOID__VOID,
1585 * GtkEntry::copy-clipboard:
1586 * @entry: the object which received the signal
1588 * The ::copy-clipboard signal is a
1589 * <link linkend="keybinding-signals">keybinding signal</link>
1590 * which gets emitted to copy the selection to the clipboard.
1592 * The default bindings for this signal are
1593 * Ctrl-c and Ctrl-Insert.
1595 signals[COPY_CLIPBOARD] =
1596 g_signal_new (I_("copy-clipboard"),
1597 G_OBJECT_CLASS_TYPE (gobject_class),
1598 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1599 G_STRUCT_OFFSET (GtkEntryClass, copy_clipboard),
1601 _gtk_marshal_VOID__VOID,
1605 * GtkEntry::paste-clipboard:
1606 * @entry: the object which received the signal
1608 * The ::paste-clipboard signal is a
1609 * <link linkend="keybinding-signals">keybinding signal</link>
1610 * which gets emitted to paste the contents of the clipboard
1611 * into the text view.
1613 * The default bindings for this signal are
1614 * Ctrl-v and Shift-Insert.
1616 signals[PASTE_CLIPBOARD] =
1617 g_signal_new (I_("paste-clipboard"),
1618 G_OBJECT_CLASS_TYPE (gobject_class),
1619 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1620 G_STRUCT_OFFSET (GtkEntryClass, paste_clipboard),
1622 _gtk_marshal_VOID__VOID,
1626 * GtkEntry::toggle-overwrite:
1627 * @entry: the object which received the signal
1629 * The ::toggle-overwrite signal is a
1630 * <link linkend="keybinding-signals">keybinding signal</link>
1631 * which gets emitted to toggle the overwrite mode of the entry.
1633 * The default bindings for this signal is Insert.
1635 signals[TOGGLE_OVERWRITE] =
1636 g_signal_new (I_("toggle-overwrite"),
1637 G_OBJECT_CLASS_TYPE (gobject_class),
1638 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1639 G_STRUCT_OFFSET (GtkEntryClass, toggle_overwrite),
1641 _gtk_marshal_VOID__VOID,
1645 * GtkEntry::icon-press:
1646 * @entry: The entry on which the signal is emitted
1647 * @icon_pos: The position of the clicked icon
1648 * @event: (type Gdk.EventButton): the button press event
1650 * The ::icon-press signal is emitted when an activatable icon
1655 signals[ICON_PRESS] =
1656 g_signal_new (I_("icon-press"),
1657 G_TYPE_FROM_CLASS (gobject_class),
1661 _gtk_marshal_VOID__ENUM_BOXED,
1663 GTK_TYPE_ENTRY_ICON_POSITION,
1664 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1667 * GtkEntry::icon-release:
1668 * @entry: The entry on which the signal is emitted
1669 * @icon_pos: The position of the clicked icon
1670 * @event: (type Gdk.EventButton): the button release event
1672 * The ::icon-release signal is emitted on the button release from a
1673 * mouse click over an activatable icon.
1677 signals[ICON_RELEASE] =
1678 g_signal_new (I_("icon-release"),
1679 G_TYPE_FROM_CLASS (gobject_class),
1683 _gtk_marshal_VOID__ENUM_BOXED,
1685 GTK_TYPE_ENTRY_ICON_POSITION,
1686 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1689 * GtkEntry::preedit-changed:
1690 * @entry: the object which received the signal
1691 * @preedit: the current preedit string
1693 * If an input method is used, the typed text will not immediately
1694 * be committed to the buffer. So if you are interested in the text,
1695 * connect to this signal.
1699 signals[PREEDIT_CHANGED] =
1700 g_signal_new_class_handler (I_("preedit-changed"),
1701 G_OBJECT_CLASS_TYPE (gobject_class),
1702 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1705 _gtk_marshal_VOID__STRING,
1714 binding_set = gtk_binding_set_by_class (class);
1716 /* Moving the insertion point */
1717 add_move_binding (binding_set, GDK_KEY_Right, 0,
1718 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1720 add_move_binding (binding_set, GDK_KEY_Left, 0,
1721 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1723 add_move_binding (binding_set, GDK_KEY_KP_Right, 0,
1724 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1726 add_move_binding (binding_set, GDK_KEY_KP_Left, 0,
1727 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1729 add_move_binding (binding_set, GDK_KEY_Right, GDK_CONTROL_MASK,
1730 GTK_MOVEMENT_WORDS, 1);
1732 add_move_binding (binding_set, GDK_KEY_Left, GDK_CONTROL_MASK,
1733 GTK_MOVEMENT_WORDS, -1);
1735 add_move_binding (binding_set, GDK_KEY_KP_Right, GDK_CONTROL_MASK,
1736 GTK_MOVEMENT_WORDS, 1);
1738 add_move_binding (binding_set, GDK_KEY_KP_Left, GDK_CONTROL_MASK,
1739 GTK_MOVEMENT_WORDS, -1);
1741 add_move_binding (binding_set, GDK_KEY_Home, 0,
1742 GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
1744 add_move_binding (binding_set, GDK_KEY_End, 0,
1745 GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
1747 add_move_binding (binding_set, GDK_KEY_KP_Home, 0,
1748 GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
1750 add_move_binding (binding_set, GDK_KEY_KP_End, 0,
1751 GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
1753 add_move_binding (binding_set, GDK_KEY_Home, GDK_CONTROL_MASK,
1754 GTK_MOVEMENT_BUFFER_ENDS, -1);
1756 add_move_binding (binding_set, GDK_KEY_End, GDK_CONTROL_MASK,
1757 GTK_MOVEMENT_BUFFER_ENDS, 1);
1759 add_move_binding (binding_set, GDK_KEY_KP_Home, GDK_CONTROL_MASK,
1760 GTK_MOVEMENT_BUFFER_ENDS, -1);
1762 add_move_binding (binding_set, GDK_KEY_KP_End, GDK_CONTROL_MASK,
1763 GTK_MOVEMENT_BUFFER_ENDS, 1);
1767 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK,
1769 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1771 G_TYPE_BOOLEAN, FALSE);
1772 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK,
1774 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1776 G_TYPE_BOOLEAN, TRUE);
1778 gtk_binding_entry_add_signal (binding_set, GDK_KEY_slash, GDK_CONTROL_MASK,
1780 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1782 G_TYPE_BOOLEAN, FALSE);
1783 gtk_binding_entry_add_signal (binding_set, GDK_KEY_slash, GDK_CONTROL_MASK,
1785 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1787 G_TYPE_BOOLEAN, TRUE);
1790 gtk_binding_entry_add_signal (binding_set, GDK_KEY_backslash, GDK_CONTROL_MASK,
1792 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_VISUAL_POSITIONS,
1794 G_TYPE_BOOLEAN, FALSE);
1795 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_SHIFT_MASK | GDK_CONTROL_MASK,
1797 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_VISUAL_POSITIONS,
1799 G_TYPE_BOOLEAN, FALSE);
1803 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Return, 0,
1805 gtk_binding_entry_add_signal (binding_set, GDK_KEY_ISO_Enter, 0,
1807 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Enter, 0,
1811 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, 0,
1812 "delete-from-cursor", 2,
1813 G_TYPE_ENUM, GTK_DELETE_CHARS,
1816 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Delete, 0,
1817 "delete-from-cursor", 2,
1818 G_TYPE_ENUM, GTK_DELETE_CHARS,
1821 gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, 0,
1824 /* Make this do the same as Backspace, to help with mis-typing */
1825 gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, GDK_SHIFT_MASK,
1828 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, GDK_CONTROL_MASK,
1829 "delete-from-cursor", 2,
1830 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1833 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Delete, GDK_CONTROL_MASK,
1834 "delete-from-cursor", 2,
1835 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1838 gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, GDK_CONTROL_MASK,
1839 "delete-from-cursor", 2,
1840 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1843 /* Cut/copy/paste */
1845 gtk_binding_entry_add_signal (binding_set, GDK_KEY_x, GDK_CONTROL_MASK,
1846 "cut-clipboard", 0);
1847 gtk_binding_entry_add_signal (binding_set, GDK_KEY_c, GDK_CONTROL_MASK,
1848 "copy-clipboard", 0);
1849 gtk_binding_entry_add_signal (binding_set, GDK_KEY_v, GDK_CONTROL_MASK,
1850 "paste-clipboard", 0);
1852 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, GDK_SHIFT_MASK,
1853 "cut-clipboard", 0);
1854 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, GDK_CONTROL_MASK,
1855 "copy-clipboard", 0);
1856 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, GDK_SHIFT_MASK,
1857 "paste-clipboard", 0);
1860 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, 0,
1861 "toggle-overwrite", 0);
1862 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Insert, 0,
1863 "toggle-overwrite", 0);
1866 * GtkEntry:inner-border:
1868 * Sets the text area's border between the text and the frame.
1872 * Deprecated: 3.4: Use the standard border and padding CSS properties;
1873 * the value of this style property is ignored.
1875 gtk_widget_class_install_style_property (widget_class,
1876 g_param_spec_boxed ("inner-border",
1878 P_("Border between text and frame."),
1880 GTK_PARAM_READABLE |
1881 G_PARAM_DEPRECATED));
1883 g_type_class_add_private (gobject_class, sizeof (GtkEntryPrivate));
1885 gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_ENTRY_ACCESSIBLE);
1889 gtk_entry_editable_init (GtkEditableInterface *iface)
1891 iface->do_insert_text = gtk_entry_insert_text;
1892 iface->do_delete_text = gtk_entry_delete_text;
1893 iface->insert_text = gtk_entry_real_insert_text;
1894 iface->delete_text = gtk_entry_real_delete_text;
1895 iface->get_chars = gtk_entry_get_chars;
1896 iface->set_selection_bounds = gtk_entry_set_selection_bounds;
1897 iface->get_selection_bounds = gtk_entry_get_selection_bounds;
1898 iface->set_position = gtk_entry_real_set_position;
1899 iface->get_position = gtk_entry_get_position;
1903 gtk_entry_cell_editable_init (GtkCellEditableIface *iface)
1905 iface->start_editing = gtk_entry_start_editing;
1908 /* for deprecated properties */
1910 gtk_entry_do_set_inner_border (GtkEntry *entry,
1911 const GtkBorder *border)
1914 g_object_set_qdata_full (G_OBJECT (entry), quark_inner_border,
1915 gtk_border_copy (border),
1916 (GDestroyNotify) gtk_border_free);
1918 g_object_set_qdata (G_OBJECT (entry), quark_inner_border, NULL);
1920 g_object_notify (G_OBJECT (entry), "inner-border");
1923 static const GtkBorder *
1924 gtk_entry_do_get_inner_border (GtkEntry *entry)
1926 return g_object_get_qdata (G_OBJECT (entry), quark_inner_border);
1930 gtk_entry_set_property (GObject *object,
1932 const GValue *value,
1935 GtkEntry *entry = GTK_ENTRY (object);
1936 GtkEntryPrivate *priv = entry->priv;
1941 gtk_entry_set_buffer (entry, g_value_get_object (value));
1946 gboolean new_value = g_value_get_boolean (value);
1948 if (new_value != priv->editable)
1950 GtkWidget *widget = GTK_WIDGET (entry);
1954 _gtk_entry_reset_im_context (entry);
1955 if (gtk_widget_has_focus (widget))
1956 gtk_im_context_focus_out (priv->im_context);
1958 priv->preedit_length = 0;
1959 priv->preedit_cursor = 0;
1962 priv->editable = new_value;
1964 if (new_value && gtk_widget_has_focus (widget))
1965 gtk_im_context_focus_in (priv->im_context);
1967 gtk_widget_queue_draw (widget);
1972 case PROP_MAX_LENGTH:
1973 gtk_entry_set_max_length (entry, g_value_get_int (value));
1976 case PROP_VISIBILITY:
1977 gtk_entry_set_visibility (entry, g_value_get_boolean (value));
1980 case PROP_HAS_FRAME:
1981 gtk_entry_set_has_frame (entry, g_value_get_boolean (value));
1984 case PROP_INNER_BORDER:
1985 gtk_entry_do_set_inner_border (entry, g_value_get_boxed (value));
1988 case PROP_INVISIBLE_CHAR:
1989 gtk_entry_set_invisible_char (entry, g_value_get_uint (value));
1992 case PROP_ACTIVATES_DEFAULT:
1993 gtk_entry_set_activates_default (entry, g_value_get_boolean (value));
1996 case PROP_WIDTH_CHARS:
1997 gtk_entry_set_width_chars (entry, g_value_get_int (value));
2001 gtk_entry_set_text (entry, g_value_get_string (value));
2005 gtk_entry_set_alignment (entry, g_value_get_float (value));
2008 case PROP_TRUNCATE_MULTILINE:
2009 priv->truncate_multiline = g_value_get_boolean (value);
2012 case PROP_SHADOW_TYPE:
2013 priv->shadow_type = g_value_get_enum (value);
2016 case PROP_OVERWRITE_MODE:
2017 gtk_entry_set_overwrite_mode (entry, g_value_get_boolean (value));
2020 case PROP_INVISIBLE_CHAR_SET:
2021 if (g_value_get_boolean (value))
2022 priv->invisible_char_set = TRUE;
2024 gtk_entry_unset_invisible_char (entry);
2027 case PROP_CAPS_LOCK_WARNING:
2028 priv->caps_lock_warning = g_value_get_boolean (value);
2031 case PROP_PROGRESS_FRACTION:
2032 gtk_entry_set_progress_fraction (entry, g_value_get_double (value));
2035 case PROP_PROGRESS_PULSE_STEP:
2036 gtk_entry_set_progress_pulse_step (entry, g_value_get_double (value));
2039 case PROP_PLACEHOLDER_TEXT:
2040 gtk_entry_set_placeholder_text (entry, g_value_get_string (value));
2043 case PROP_PIXBUF_PRIMARY:
2044 gtk_entry_set_icon_from_pixbuf (entry,
2045 GTK_ENTRY_ICON_PRIMARY,
2046 g_value_get_object (value));
2049 case PROP_PIXBUF_SECONDARY:
2050 gtk_entry_set_icon_from_pixbuf (entry,
2051 GTK_ENTRY_ICON_SECONDARY,
2052 g_value_get_object (value));
2055 case PROP_STOCK_PRIMARY:
2056 gtk_entry_set_icon_from_stock (entry,
2057 GTK_ENTRY_ICON_PRIMARY,
2058 g_value_get_string (value));
2061 case PROP_STOCK_SECONDARY:
2062 gtk_entry_set_icon_from_stock (entry,
2063 GTK_ENTRY_ICON_SECONDARY,
2064 g_value_get_string (value));
2067 case PROP_ICON_NAME_PRIMARY:
2068 gtk_entry_set_icon_from_icon_name (entry,
2069 GTK_ENTRY_ICON_PRIMARY,
2070 g_value_get_string (value));
2073 case PROP_ICON_NAME_SECONDARY:
2074 gtk_entry_set_icon_from_icon_name (entry,
2075 GTK_ENTRY_ICON_SECONDARY,
2076 g_value_get_string (value));
2079 case PROP_GICON_PRIMARY:
2080 gtk_entry_set_icon_from_gicon (entry,
2081 GTK_ENTRY_ICON_PRIMARY,
2082 g_value_get_object (value));
2085 case PROP_GICON_SECONDARY:
2086 gtk_entry_set_icon_from_gicon (entry,
2087 GTK_ENTRY_ICON_SECONDARY,
2088 g_value_get_object (value));
2091 case PROP_ACTIVATABLE_PRIMARY:
2092 gtk_entry_set_icon_activatable (entry,
2093 GTK_ENTRY_ICON_PRIMARY,
2094 g_value_get_boolean (value));
2097 case PROP_ACTIVATABLE_SECONDARY:
2098 gtk_entry_set_icon_activatable (entry,
2099 GTK_ENTRY_ICON_SECONDARY,
2100 g_value_get_boolean (value));
2103 case PROP_SENSITIVE_PRIMARY:
2104 gtk_entry_set_icon_sensitive (entry,
2105 GTK_ENTRY_ICON_PRIMARY,
2106 g_value_get_boolean (value));
2109 case PROP_SENSITIVE_SECONDARY:
2110 gtk_entry_set_icon_sensitive (entry,
2111 GTK_ENTRY_ICON_SECONDARY,
2112 g_value_get_boolean (value));
2115 case PROP_TOOLTIP_TEXT_PRIMARY:
2116 gtk_entry_set_icon_tooltip_text (entry,
2117 GTK_ENTRY_ICON_PRIMARY,
2118 g_value_get_string (value));
2121 case PROP_TOOLTIP_TEXT_SECONDARY:
2122 gtk_entry_set_icon_tooltip_text (entry,
2123 GTK_ENTRY_ICON_SECONDARY,
2124 g_value_get_string (value));
2127 case PROP_TOOLTIP_MARKUP_PRIMARY:
2128 gtk_entry_set_icon_tooltip_markup (entry,
2129 GTK_ENTRY_ICON_PRIMARY,
2130 g_value_get_string (value));
2133 case PROP_TOOLTIP_MARKUP_SECONDARY:
2134 gtk_entry_set_icon_tooltip_markup (entry,
2135 GTK_ENTRY_ICON_SECONDARY,
2136 g_value_get_string (value));
2139 case PROP_IM_MODULE:
2140 g_free (priv->im_module);
2141 priv->im_module = g_value_dup_string (value);
2142 if (GTK_IS_IM_MULTICONTEXT (priv->im_context))
2143 gtk_im_multicontext_set_context_id (GTK_IM_MULTICONTEXT (priv->im_context), priv->im_module);
2146 case PROP_EDITING_CANCELED:
2147 priv->editing_canceled = g_value_get_boolean (value);
2150 case PROP_COMPLETION:
2151 gtk_entry_set_completion (entry, GTK_ENTRY_COMPLETION (g_value_get_object (value)));
2154 case PROP_SCROLL_OFFSET:
2155 case PROP_CURSOR_POSITION:
2157 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2163 gtk_entry_get_property (GObject *object,
2168 GtkEntry *entry = GTK_ENTRY (object);
2169 GtkEntryPrivate *priv = entry->priv;
2174 g_value_set_object (value, gtk_entry_get_buffer (entry));
2177 case PROP_CURSOR_POSITION:
2178 g_value_set_int (value, priv->current_pos);
2181 case PROP_SELECTION_BOUND:
2182 g_value_set_int (value, priv->selection_bound);
2186 g_value_set_boolean (value, priv->editable);
2189 case PROP_MAX_LENGTH:
2190 g_value_set_int (value, gtk_entry_buffer_get_max_length (get_buffer (entry)));
2193 case PROP_VISIBILITY:
2194 g_value_set_boolean (value, priv->visible);
2197 case PROP_HAS_FRAME:
2198 g_value_set_boolean (value, priv->has_frame);
2201 case PROP_INNER_BORDER:
2202 g_value_set_boxed (value, gtk_entry_do_get_inner_border (entry));
2205 case PROP_INVISIBLE_CHAR:
2206 g_value_set_uint (value, priv->invisible_char);
2209 case PROP_ACTIVATES_DEFAULT:
2210 g_value_set_boolean (value, priv->activates_default);
2213 case PROP_WIDTH_CHARS:
2214 g_value_set_int (value, priv->width_chars);
2217 case PROP_SCROLL_OFFSET:
2218 g_value_set_int (value, priv->scroll_offset);
2222 g_value_set_string (value, gtk_entry_get_text (entry));
2226 g_value_set_float (value, gtk_entry_get_alignment (entry));
2229 case PROP_TRUNCATE_MULTILINE:
2230 g_value_set_boolean (value, priv->truncate_multiline);
2233 case PROP_SHADOW_TYPE:
2234 g_value_set_enum (value, priv->shadow_type);
2237 case PROP_OVERWRITE_MODE:
2238 g_value_set_boolean (value, priv->overwrite_mode);
2241 case PROP_TEXT_LENGTH:
2242 g_value_set_uint (value, gtk_entry_buffer_get_length (get_buffer (entry)));
2245 case PROP_INVISIBLE_CHAR_SET:
2246 g_value_set_boolean (value, priv->invisible_char_set);
2249 case PROP_IM_MODULE:
2250 g_value_set_string (value, priv->im_module);
2253 case PROP_CAPS_LOCK_WARNING:
2254 g_value_set_boolean (value, priv->caps_lock_warning);
2257 case PROP_PROGRESS_FRACTION:
2258 g_value_set_double (value, priv->progress_fraction);
2261 case PROP_PROGRESS_PULSE_STEP:
2262 g_value_set_double (value, priv->progress_pulse_fraction);
2265 case PROP_PLACEHOLDER_TEXT:
2266 g_value_set_string (value, gtk_entry_get_placeholder_text (entry));
2269 case PROP_PIXBUF_PRIMARY:
2270 g_value_set_object (value,
2271 gtk_entry_get_icon_pixbuf (entry,
2272 GTK_ENTRY_ICON_PRIMARY));
2275 case PROP_PIXBUF_SECONDARY:
2276 g_value_set_object (value,
2277 gtk_entry_get_icon_pixbuf (entry,
2278 GTK_ENTRY_ICON_SECONDARY));
2281 case PROP_STOCK_PRIMARY:
2282 g_value_set_string (value,
2283 gtk_entry_get_icon_stock (entry,
2284 GTK_ENTRY_ICON_PRIMARY));
2287 case PROP_STOCK_SECONDARY:
2288 g_value_set_string (value,
2289 gtk_entry_get_icon_stock (entry,
2290 GTK_ENTRY_ICON_SECONDARY));
2293 case PROP_ICON_NAME_PRIMARY:
2294 g_value_set_string (value,
2295 gtk_entry_get_icon_name (entry,
2296 GTK_ENTRY_ICON_PRIMARY));
2299 case PROP_ICON_NAME_SECONDARY:
2300 g_value_set_string (value,
2301 gtk_entry_get_icon_name (entry,
2302 GTK_ENTRY_ICON_SECONDARY));
2305 case PROP_GICON_PRIMARY:
2306 g_value_set_object (value,
2307 gtk_entry_get_icon_gicon (entry,
2308 GTK_ENTRY_ICON_PRIMARY));
2311 case PROP_GICON_SECONDARY:
2312 g_value_set_object (value,
2313 gtk_entry_get_icon_gicon (entry,
2314 GTK_ENTRY_ICON_SECONDARY));
2317 case PROP_STORAGE_TYPE_PRIMARY:
2318 g_value_set_enum (value,
2319 gtk_entry_get_icon_storage_type (entry,
2320 GTK_ENTRY_ICON_PRIMARY));
2323 case PROP_STORAGE_TYPE_SECONDARY:
2324 g_value_set_enum (value,
2325 gtk_entry_get_icon_storage_type (entry,
2326 GTK_ENTRY_ICON_SECONDARY));
2329 case PROP_ACTIVATABLE_PRIMARY:
2330 g_value_set_boolean (value,
2331 gtk_entry_get_icon_activatable (entry, GTK_ENTRY_ICON_PRIMARY));
2334 case PROP_ACTIVATABLE_SECONDARY:
2335 g_value_set_boolean (value,
2336 gtk_entry_get_icon_activatable (entry, GTK_ENTRY_ICON_SECONDARY));
2339 case PROP_SENSITIVE_PRIMARY:
2340 g_value_set_boolean (value,
2341 gtk_entry_get_icon_sensitive (entry, GTK_ENTRY_ICON_PRIMARY));
2344 case PROP_SENSITIVE_SECONDARY:
2345 g_value_set_boolean (value,
2346 gtk_entry_get_icon_sensitive (entry, GTK_ENTRY_ICON_SECONDARY));
2349 case PROP_TOOLTIP_TEXT_PRIMARY:
2350 g_value_take_string (value,
2351 gtk_entry_get_icon_tooltip_text (entry, GTK_ENTRY_ICON_PRIMARY));
2354 case PROP_TOOLTIP_TEXT_SECONDARY:
2355 g_value_take_string (value,
2356 gtk_entry_get_icon_tooltip_text (entry, GTK_ENTRY_ICON_SECONDARY));
2359 case PROP_TOOLTIP_MARKUP_PRIMARY:
2360 g_value_take_string (value,
2361 gtk_entry_get_icon_tooltip_markup (entry, GTK_ENTRY_ICON_PRIMARY));
2364 case PROP_TOOLTIP_MARKUP_SECONDARY:
2365 g_value_take_string (value,
2366 gtk_entry_get_icon_tooltip_markup (entry, GTK_ENTRY_ICON_SECONDARY));
2369 case PROP_EDITING_CANCELED:
2370 g_value_set_boolean (value,
2371 priv->editing_canceled);
2374 case PROP_COMPLETION:
2375 g_value_set_object (value, G_OBJECT (gtk_entry_get_completion (entry)));
2379 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2385 find_invisible_char (GtkWidget *widget)
2387 PangoLayout *layout;
2388 PangoAttrList *attr_list;
2390 gunichar invisible_chars [] = {
2392 0x25cf, /* BLACK CIRCLE */
2393 0x2022, /* BULLET */
2394 0x2731, /* HEAVY ASTERISK */
2395 0x273a /* SIXTEEN POINTED ASTERISK */
2398 gtk_widget_style_get (widget,
2399 "invisible-char", &invisible_chars[0],
2402 layout = gtk_widget_create_pango_layout (widget, NULL);
2404 attr_list = pango_attr_list_new ();
2405 pango_attr_list_insert (attr_list, pango_attr_fallback_new (FALSE));
2407 pango_layout_set_attributes (layout, attr_list);
2408 pango_attr_list_unref (attr_list);
2410 for (i = (invisible_chars[0] != 0 ? 0 : 1); i < G_N_ELEMENTS (invisible_chars); i++)
2412 gchar text[7] = { 0, };
2415 len = g_unichar_to_utf8 (invisible_chars[i], text);
2416 pango_layout_set_text (layout, text, len);
2418 count = pango_layout_get_unknown_glyphs_count (layout);
2422 g_object_unref (layout);
2423 return invisible_chars[i];
2427 g_object_unref (layout);
2433 gtk_entry_init (GtkEntry *entry)
2435 GtkStyleContext *context;
2436 GtkEntryPrivate *priv;
2438 entry->priv = G_TYPE_INSTANCE_GET_PRIVATE (entry,
2443 gtk_widget_set_can_focus (GTK_WIDGET (entry), TRUE);
2444 gtk_widget_set_has_window (GTK_WIDGET (entry), FALSE);
2446 priv->editable = TRUE;
2447 priv->visible = TRUE;
2448 priv->dnd_position = -1;
2449 priv->width_chars = -1;
2450 priv->is_cell_renderer = FALSE;
2451 priv->editing_canceled = FALSE;
2452 priv->has_frame = TRUE;
2453 priv->truncate_multiline = FALSE;
2454 priv->shadow_type = GTK_SHADOW_IN;
2456 priv->caps_lock_warning = TRUE;
2457 priv->caps_lock_warning_shown = FALSE;
2458 priv->progress_fraction = 0.0;
2459 priv->progress_pulse_fraction = 0.1;
2461 gtk_drag_dest_set (GTK_WIDGET (entry),
2462 GTK_DEST_DEFAULT_HIGHLIGHT,
2464 GDK_ACTION_COPY | GDK_ACTION_MOVE);
2465 gtk_drag_dest_add_text_targets (GTK_WIDGET (entry));
2467 /* This object is completely private. No external entity can gain a reference
2468 * to it; so we create it here and destroy it in finalize().
2470 priv->im_context = gtk_im_multicontext_new ();
2472 g_signal_connect (priv->im_context, "commit",
2473 G_CALLBACK (gtk_entry_commit_cb), entry);
2474 g_signal_connect (priv->im_context, "preedit-changed",
2475 G_CALLBACK (gtk_entry_preedit_changed_cb), entry);
2476 g_signal_connect (priv->im_context, "retrieve-surrounding",
2477 G_CALLBACK (gtk_entry_retrieve_surrounding_cb), entry);
2478 g_signal_connect (priv->im_context, "delete-surrounding",
2479 G_CALLBACK (gtk_entry_delete_surrounding_cb), entry);
2481 context = gtk_widget_get_style_context (GTK_WIDGET (entry));
2482 gtk_style_context_add_class (context, GTK_STYLE_CLASS_ENTRY);
2484 gtk_entry_update_cached_style_values (entry);
2488 gtk_entry_prepare_context_for_icon (GtkEntry *entry,
2489 GtkStyleContext *context,
2490 GtkEntryIconPosition icon_pos)
2492 GtkEntryPrivate *priv = entry->priv;
2493 EntryIconInfo *icon_info = priv->icons[icon_pos];
2495 GtkStateFlags state;
2497 widget = GTK_WIDGET (entry);
2498 state = gtk_widget_get_state_flags (widget);
2500 state &= ~(GTK_STATE_FLAG_PRELIGHT);
2502 if ((state & GTK_STATE_FLAG_INSENSITIVE) || icon_info->insensitive)
2503 state |= GTK_STATE_FLAG_INSENSITIVE;
2504 else if (icon_info->prelight)
2505 state |= GTK_STATE_FLAG_PRELIGHT;
2507 gtk_style_context_save (context);
2509 gtk_style_context_set_state (context, state);
2510 gtk_style_context_add_class (context, GTK_STYLE_CLASS_IMAGE);
2514 get_icon_width (GtkEntry *entry,
2515 GtkEntryIconPosition icon_pos)
2517 GtkEntryPrivate *priv = entry->priv;
2518 EntryIconInfo *icon_info = priv->icons[icon_pos];
2519 GtkStyleContext *context;
2525 context = gtk_widget_get_style_context (GTK_WIDGET (entry));
2526 gtk_entry_prepare_context_for_icon (entry, context, icon_pos);
2527 _gtk_icon_helper_get_size (icon_info->icon_helper, context,
2529 gtk_style_context_restore (context);
2535 get_icon_allocations (GtkEntry *entry,
2536 GtkAllocation *primary,
2537 GtkAllocation *secondary)
2540 GtkEntryPrivate *priv = entry->priv;
2541 gint x, y, width, height;
2543 get_text_area_size (entry, &x, &y, &width, &height);
2545 if (gtk_widget_has_focus (GTK_WIDGET (entry)) && !priv->interior_focus)
2546 y += priv->focus_width;
2549 primary->height = height;
2550 primary->width = get_icon_width (entry, GTK_ENTRY_ICON_PRIMARY);
2551 if (primary->width > 0)
2552 primary->width += 2 * priv->icon_margin;
2555 secondary->height = height;
2556 secondary->width = get_icon_width (entry, GTK_ENTRY_ICON_SECONDARY);
2557 if (secondary->width > 0)
2558 secondary->width += 2 * priv->icon_margin;
2560 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
2562 primary->x = x + width - primary->width;
2568 secondary->x = x + width - secondary->width;
2574 begin_change (GtkEntry *entry)
2576 GtkEntryPrivate *priv = entry->priv;
2578 priv->change_count++;
2580 g_object_freeze_notify (G_OBJECT (entry));
2584 end_change (GtkEntry *entry)
2586 GtkEditable *editable = GTK_EDITABLE (entry);
2587 GtkEntryPrivate *priv = entry->priv;
2589 g_return_if_fail (priv->change_count > 0);
2591 g_object_thaw_notify (G_OBJECT (entry));
2593 priv->change_count--;
2595 if (priv->change_count == 0)
2597 if (priv->real_changed)
2599 g_signal_emit_by_name (editable, "changed");
2600 priv->real_changed = FALSE;
2606 emit_changed (GtkEntry *entry)
2608 GtkEditable *editable = GTK_EDITABLE (entry);
2609 GtkEntryPrivate *priv = entry->priv;
2611 if (priv->change_count == 0)
2612 g_signal_emit_by_name (editable, "changed");
2614 priv->real_changed = TRUE;
2618 gtk_entry_destroy (GtkWidget *widget)
2620 GtkEntry *entry = GTK_ENTRY (widget);
2621 GtkEntryPrivate *priv = entry->priv;
2623 priv->current_pos = priv->selection_bound = 0;
2624 _gtk_entry_reset_im_context (entry);
2625 gtk_entry_reset_layout (entry);
2627 if (priv->blink_timeout)
2629 g_source_remove (priv->blink_timeout);
2630 priv->blink_timeout = 0;
2633 if (priv->recompute_idle)
2635 g_source_remove (priv->recompute_idle);
2636 priv->recompute_idle = 0;
2639 GTK_WIDGET_CLASS (gtk_entry_parent_class)->destroy (widget);
2643 gtk_entry_dispose (GObject *object)
2645 GtkEntry *entry = GTK_ENTRY (object);
2646 GtkEntryPrivate *priv = entry->priv;
2649 gtk_entry_set_icon_from_pixbuf (entry, GTK_ENTRY_ICON_PRIMARY, NULL);
2650 gtk_entry_set_icon_tooltip_markup (entry, GTK_ENTRY_ICON_PRIMARY, NULL);
2651 gtk_entry_set_icon_from_pixbuf (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
2652 gtk_entry_set_icon_tooltip_markup (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
2656 buffer_disconnect_signals (entry);
2657 g_object_unref (priv->buffer);
2658 priv->buffer = NULL;
2661 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (object)));
2662 g_signal_handlers_disconnect_by_func (keymap, keymap_state_changed, entry);
2663 g_signal_handlers_disconnect_by_func (keymap, keymap_direction_changed, entry);
2664 G_OBJECT_CLASS (gtk_entry_parent_class)->dispose (object);
2668 gtk_entry_finalize (GObject *object)
2670 GtkEntry *entry = GTK_ENTRY (object);
2671 GtkEntryPrivate *priv = entry->priv;
2672 EntryIconInfo *icon_info = NULL;
2675 for (i = 0; i < MAX_ICONS; i++)
2677 if ((icon_info = priv->icons[i]) != NULL)
2679 if (icon_info->target_list != NULL)
2681 gtk_target_list_unref (icon_info->target_list);
2682 icon_info->target_list = NULL;
2685 g_clear_object (&icon_info->icon_helper);
2687 g_slice_free (EntryIconInfo, icon_info);
2688 priv->icons[i] = NULL;
2692 gtk_entry_set_completion (entry, NULL);
2694 if (priv->cached_layout)
2695 g_object_unref (priv->cached_layout);
2697 g_object_unref (priv->im_context);
2699 if (priv->blink_timeout)
2700 g_source_remove (priv->blink_timeout);
2702 if (priv->recompute_idle)
2703 g_source_remove (priv->recompute_idle);
2705 g_free (priv->placeholder_text);
2706 g_free (priv->im_module);
2708 G_OBJECT_CLASS (gtk_entry_parent_class)->finalize (object);
2712 gtk_entry_get_display_mode (GtkEntry *entry)
2714 GtkEntryPrivate *priv = entry->priv;
2717 return DISPLAY_NORMAL;
2719 if (priv->invisible_char == 0 && priv->invisible_char_set)
2720 return DISPLAY_BLANK;
2722 return DISPLAY_INVISIBLE;
2726 gtk_entry_get_display_text (GtkEntry *entry,
2730 GtkEntryPasswordHint *password_hint;
2731 GtkEntryPrivate *priv;
2732 gunichar invisible_char;
2743 text = gtk_entry_buffer_get_text (get_buffer (entry));
2744 length = gtk_entry_buffer_get_length (get_buffer (entry));
2748 if (start_pos > length)
2751 if (end_pos <= start_pos)
2752 return g_strdup ("");
2753 else if (priv->visible)
2755 start = g_utf8_offset_to_pointer (text, start_pos);
2756 end = g_utf8_offset_to_pointer (start, end_pos - start_pos);
2757 return g_strndup (start, end - start);
2761 str = g_string_sized_new (length * 2);
2763 /* Figure out what our invisible char is and encode it */
2764 if (!priv->invisible_char)
2765 invisible_char = priv->invisible_char_set ? ' ' : '*';
2767 invisible_char = priv->invisible_char;
2768 char_len = g_unichar_to_utf8 (invisible_char, char_str);
2771 * Add hidden characters for each character in the text
2772 * buffer. If there is a password hint, then keep that
2773 * character visible.
2776 password_hint = g_object_get_qdata (G_OBJECT (entry), quark_password_hint);
2777 for (i = start_pos; i < end_pos; ++i)
2779 if (password_hint && i == password_hint->position)
2781 start = g_utf8_offset_to_pointer (text, i);
2782 g_string_append_len (str, start, g_utf8_next_char (start) - start);
2786 g_string_append_len (str, char_str, char_len);
2790 return g_string_free (str, FALSE);
2795 update_cursors (GtkWidget *widget)
2797 GtkEntry *entry = GTK_ENTRY (widget);
2798 GtkEntryPrivate *priv = entry->priv;
2799 EntryIconInfo *icon_info = NULL;
2800 GdkDisplay *display;
2804 for (i = 0; i < MAX_ICONS; i++)
2806 if ((icon_info = priv->icons[i]) != NULL)
2808 if (!_gtk_icon_helper_get_is_empty (icon_info->icon_helper) &&
2809 icon_info->window != NULL)
2810 gdk_window_show_unraised (icon_info->window);
2812 /* The icon windows are not children of the visible entry window,
2813 * thus we can't just inherit the xterm cursor. Slight complication
2814 * here is that for the entry, insensitive => arrow cursor, but for
2815 * an icon in a sensitive entry, insensitive => xterm cursor.
2817 if (gtk_widget_is_sensitive (widget) &&
2818 (icon_info->insensitive ||
2819 (icon_info->nonactivatable && icon_info->target_list == NULL)))
2821 display = gtk_widget_get_display (widget);
2822 cursor = gdk_cursor_new_for_display (display, GDK_XTERM);
2823 gdk_window_set_cursor (icon_info->window, cursor);
2824 g_object_unref (cursor);
2828 gdk_window_set_cursor (icon_info->window, NULL);
2835 realize_icon_info (GtkWidget *widget,
2836 GtkEntryIconPosition icon_pos)
2838 GtkEntry *entry = GTK_ENTRY (widget);
2839 GtkEntryPrivate *priv = entry->priv;
2840 EntryIconInfo *icon_info = priv->icons[icon_pos];
2841 GdkWindowAttr attributes;
2842 gint attributes_mask;
2844 g_return_if_fail (icon_info != NULL);
2848 attributes.width = 1;
2849 attributes.height = 1;
2850 attributes.window_type = GDK_WINDOW_CHILD;
2851 attributes.wclass = GDK_INPUT_ONLY;
2852 attributes.event_mask = gtk_widget_get_events (widget);
2853 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
2854 GDK_BUTTON_RELEASE_MASK |
2855 GDK_BUTTON1_MOTION_MASK |
2856 GDK_BUTTON3_MOTION_MASK |
2857 GDK_POINTER_MOTION_HINT_MASK |
2858 GDK_POINTER_MOTION_MASK |
2859 GDK_ENTER_NOTIFY_MASK |
2860 GDK_LEAVE_NOTIFY_MASK);
2861 attributes_mask = GDK_WA_X | GDK_WA_Y;
2863 icon_info->window = gdk_window_new (gtk_widget_get_window (widget),
2866 gdk_window_set_user_data (icon_info->window, widget);
2868 gtk_widget_queue_resize (widget);
2871 static EntryIconInfo*
2872 construct_icon_info (GtkWidget *widget,
2873 GtkEntryIconPosition icon_pos)
2875 GtkEntry *entry = GTK_ENTRY (widget);
2876 GtkEntryPrivate *priv = entry->priv;
2877 EntryIconInfo *icon_info;
2879 g_return_val_if_fail (priv->icons[icon_pos] == NULL, NULL);
2881 icon_info = g_slice_new0 (EntryIconInfo);
2882 priv->icons[icon_pos] = icon_info;
2884 icon_info->icon_helper = _gtk_icon_helper_new ();
2886 if (gtk_widget_get_realized (widget))
2887 realize_icon_info (widget, icon_pos);
2893 gtk_entry_map (GtkWidget *widget)
2895 GtkEntry *entry = GTK_ENTRY (widget);
2896 GtkEntryPrivate *priv = entry->priv;
2897 EntryIconInfo *icon_info = NULL;
2900 GTK_WIDGET_CLASS (gtk_entry_parent_class)->map (widget);
2902 gdk_window_show (priv->text_area);
2904 for (i = 0; i < MAX_ICONS; i++)
2906 if ((icon_info = priv->icons[i]) != NULL)
2908 if (!_gtk_icon_helper_get_is_empty (icon_info->icon_helper) &&
2909 icon_info->window != NULL)
2910 gdk_window_show (icon_info->window);
2914 update_cursors (widget);
2918 gtk_entry_unmap (GtkWidget *widget)
2920 GtkEntry *entry = GTK_ENTRY (widget);
2921 GtkEntryPrivate *priv = entry->priv;
2922 EntryIconInfo *icon_info = NULL;
2925 for (i = 0; i < MAX_ICONS; i++)
2927 if ((icon_info = priv->icons[i]) != NULL)
2929 if (!_gtk_icon_helper_get_is_empty (icon_info->icon_helper) &&
2930 icon_info->window != NULL)
2931 gdk_window_hide (icon_info->window);
2935 gdk_window_hide (priv->text_area);
2937 GTK_WIDGET_CLASS (gtk_entry_parent_class)->unmap (widget);
2941 gtk_entry_realize (GtkWidget *widget)
2944 GtkEntryPrivate *priv;
2945 EntryIconInfo *icon_info;
2947 GdkWindowAttr attributes;
2948 gint attributes_mask;
2949 gint frame_x, frame_y;
2952 gtk_widget_set_realized (widget, TRUE);
2953 window = gtk_widget_get_parent_window (widget);
2954 gtk_widget_set_window (widget, window);
2955 g_object_ref (window);
2957 entry = GTK_ENTRY (widget);
2960 attributes.window_type = GDK_WINDOW_CHILD;
2961 attributes.wclass = GDK_INPUT_ONLY;
2962 attributes.event_mask = gtk_widget_get_events (widget);
2963 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
2964 GDK_BUTTON_RELEASE_MASK |
2965 GDK_BUTTON1_MOTION_MASK |
2966 GDK_BUTTON3_MOTION_MASK |
2967 GDK_POINTER_MOTION_HINT_MASK |
2968 GDK_POINTER_MOTION_MASK |
2969 GDK_ENTER_NOTIFY_MASK |
2970 GDK_LEAVE_NOTIFY_MASK);
2971 attributes_mask = GDK_WA_X | GDK_WA_Y;
2973 get_text_area_size (entry, &attributes.x, &attributes.y, &attributes.width, &attributes.height);
2975 get_frame_size (entry, TRUE, &frame_x, &frame_y, NULL, NULL);
2976 attributes.x += frame_x;
2977 attributes.y += frame_y;
2979 if (gtk_widget_is_sensitive (widget))
2981 attributes.cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
2982 attributes_mask |= GDK_WA_CURSOR;
2985 priv->text_area = gdk_window_new (gtk_widget_get_window (widget),
2989 gdk_window_set_user_data (priv->text_area, entry);
2991 if (attributes_mask & GDK_WA_CURSOR)
2992 g_object_unref (attributes.cursor);
2994 gtk_im_context_set_client_window (priv->im_context, priv->text_area);
2996 gtk_entry_adjust_scroll (entry);
2997 gtk_entry_update_primary_selection (entry);
3000 /* If the icon positions are already setup, create their windows.
3001 * Otherwise if they don't exist yet, then construct_icon_info()
3002 * will create the windows once the widget is already realized.
3004 for (i = 0; i < MAX_ICONS; i++)
3006 if ((icon_info = priv->icons[i]) != NULL)
3008 if (icon_info->window == NULL)
3009 realize_icon_info (widget, i);
3015 gtk_entry_unrealize (GtkWidget *widget)
3017 GtkEntry *entry = GTK_ENTRY (widget);
3018 GtkEntryPrivate *priv = entry->priv;
3019 GtkClipboard *clipboard;
3020 EntryIconInfo *icon_info;
3023 gtk_entry_reset_layout (entry);
3025 gtk_im_context_set_client_window (priv->im_context, NULL);
3027 clipboard = gtk_widget_get_clipboard (widget, GDK_SELECTION_PRIMARY);
3028 if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (entry))
3029 gtk_clipboard_clear (clipboard);
3031 if (priv->text_area)
3033 gdk_window_set_user_data (priv->text_area, NULL);
3034 gdk_window_destroy (priv->text_area);
3035 priv->text_area = NULL;
3038 if (priv->popup_menu)
3040 gtk_widget_destroy (priv->popup_menu);
3041 priv->popup_menu = NULL;
3044 GTK_WIDGET_CLASS (gtk_entry_parent_class)->unrealize (widget);
3046 for (i = 0; i < MAX_ICONS; i++)
3048 if ((icon_info = priv->icons[i]) != NULL)
3050 if (icon_info->window != NULL)
3052 gdk_window_destroy (icon_info->window);
3053 icon_info->window = NULL;
3060 _gtk_entry_get_borders (GtkEntry *entry,
3061 GtkBorder *border_out)
3063 GtkEntryPrivate *priv = entry->priv;
3064 GtkWidget *widget = GTK_WIDGET (entry);
3065 GtkBorder tmp = { 0, 0, 0, 0 };
3066 GtkStyleContext *context;
3068 context = gtk_widget_get_style_context (widget);
3069 gtk_style_context_get_padding (context, 0, &tmp);
3071 if (priv->has_frame)
3075 gtk_style_context_get_border (context, 0, &border);
3076 tmp.top += border.top;
3077 tmp.right += border.right;
3078 tmp.bottom += border.bottom;
3079 tmp.left += border.left;
3082 if (!priv->interior_focus)
3084 tmp.top += priv->focus_width;
3085 tmp.right += priv->focus_width;
3086 tmp.bottom += priv->focus_width;
3087 tmp.left += priv->focus_width;
3090 if (border_out != NULL)
3095 gtk_entry_get_preferred_width (GtkWidget *widget,
3099 GtkEntry *entry = GTK_ENTRY (widget);
3100 GtkEntryPrivate *priv = entry->priv;
3101 PangoFontMetrics *metrics;
3103 PangoContext *context;
3104 GtkStyleContext *style_context;
3105 GtkStateFlags state;
3106 gint icon_widths = 0;
3110 context = gtk_widget_get_pango_context (widget);
3112 style_context = gtk_widget_get_style_context (widget);
3113 state = gtk_widget_get_state_flags (widget);
3115 metrics = pango_context_get_metrics (context,
3116 gtk_style_context_get_font (style_context, state),
3117 pango_context_get_language (context));
3119 _gtk_entry_get_borders (entry, &borders);
3121 if (priv->width_chars < 0)
3122 width = MIN_ENTRY_WIDTH + borders.left + borders.right;
3125 gint char_width = pango_font_metrics_get_approximate_char_width (metrics);
3126 gint digit_width = pango_font_metrics_get_approximate_digit_width (metrics);
3127 gint char_pixels = (MAX (char_width, digit_width) + PANGO_SCALE - 1) / PANGO_SCALE;
3129 width = char_pixels * priv->width_chars + borders.left + borders.right;
3132 for (i = 0; i < MAX_ICONS; i++)
3134 icon_width = get_icon_width (entry, i);
3136 icon_widths += icon_width + 2 * priv->icon_margin;
3139 if (icon_widths > width)
3140 width += icon_widths;
3142 pango_font_metrics_unref (metrics);
3149 gtk_entry_get_preferred_height (GtkWidget *widget,
3153 GtkEntry *entry = GTK_ENTRY (widget);
3154 GtkEntryPrivate *priv = entry->priv;
3155 PangoFontMetrics *metrics;
3157 GtkStyleContext *style_context;
3158 GtkStateFlags state;
3159 PangoContext *context;
3162 context = gtk_widget_get_pango_context (widget);
3164 style_context = gtk_widget_get_style_context (widget);
3165 state = gtk_widget_get_state_flags (widget);
3167 metrics = pango_context_get_metrics (context,
3168 gtk_style_context_get_font (style_context, state),
3169 pango_context_get_language (context));
3171 priv->ascent = pango_font_metrics_get_ascent (metrics);
3172 priv->descent = pango_font_metrics_get_descent (metrics);
3174 _gtk_entry_get_borders (entry, &borders);
3176 height = PANGO_PIXELS (priv->ascent + priv->descent) + borders.top + borders.bottom;
3178 pango_font_metrics_unref (metrics);
3185 place_windows (GtkEntry *entry)
3187 GtkWidget *widget = GTK_WIDGET (entry);
3188 GtkEntryPrivate *priv = entry->priv;
3189 gint x, y, width, height;
3190 gint frame_x, frame_y;
3191 GtkAllocation primary;
3192 GtkAllocation secondary;
3193 EntryIconInfo *icon_info = NULL;
3195 get_frame_size (entry, TRUE, &frame_x, &frame_y, NULL, NULL);
3196 get_text_area_size (entry, &x, &y, &width, &height);
3197 get_icon_allocations (entry, &primary, &secondary);
3199 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3200 y += priv->focus_width;
3202 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
3203 x += secondary.width;
3206 width -= primary.width + secondary.width;
3210 primary.x += frame_x;
3211 primary.y += frame_y;
3212 secondary.x += frame_x;
3213 secondary.y += frame_y;
3215 if ((icon_info = priv->icons[GTK_ENTRY_ICON_PRIMARY]) != NULL)
3216 gdk_window_move_resize (icon_info->window,
3217 primary.x, primary.y,
3218 primary.width, primary.height);
3220 if ((icon_info = priv->icons[GTK_ENTRY_ICON_SECONDARY]) != NULL)
3221 gdk_window_move_resize (icon_info->window,
3222 secondary.x, secondary.y,
3223 secondary.width, secondary.height);
3225 gdk_window_move_resize (priv->text_area, x, y, width, height);
3229 gtk_entry_get_text_area_size (GtkEntry *entry,
3235 GtkEntryPrivate *priv = entry->priv;
3236 GtkWidget *widget = GTK_WIDGET (entry);
3237 GtkAllocation allocation;
3238 GtkRequisition requisition;
3243 gtk_widget_get_preferred_size (widget, &requisition, NULL);
3244 req_height = requisition.height - gtk_widget_get_margin_top (widget) - gtk_widget_get_margin_bottom (widget);
3246 gtk_widget_get_allocation (widget, &allocation);
3247 _gtk_entry_get_borders (entry, &borders);
3249 if (gtk_widget_get_realized (widget))
3250 get_frame_size (entry, TRUE, NULL, NULL, NULL, &frame_height);
3252 frame_height = req_height;
3254 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3255 frame_height -= 2 * priv->focus_width;
3261 *y = floor ((frame_height - req_height) / 2) + borders.top;
3264 *width = allocation.width - borders.left - borders.right;
3267 *height = req_height - borders.top - borders.bottom;
3271 get_text_area_size (GtkEntry *entry,
3277 GtkEntryClass *class;
3279 g_return_if_fail (GTK_IS_ENTRY (entry));
3281 class = GTK_ENTRY_GET_CLASS (entry);
3283 if (class->get_text_area_size)
3284 class->get_text_area_size (entry, x, y, width, height);
3289 get_frame_size (GtkEntry *entry,
3290 gboolean relative_to_window,
3296 GtkEntryPrivate *priv = entry->priv;
3297 GtkAllocation allocation;
3298 GtkRequisition requisition;
3299 GtkWidget *widget = GTK_WIDGET (entry);
3302 gtk_widget_get_preferred_size (widget, &requisition, NULL);
3304 req_height = requisition.height - gtk_widget_get_margin_top (widget) - gtk_widget_get_margin_bottom (widget);
3306 gtk_widget_get_allocation (widget, &allocation);
3309 *x = relative_to_window ? allocation.x : 0;
3313 if (priv->is_cell_renderer)
3316 *y = (allocation.height - req_height) / 2;
3318 if (relative_to_window)
3323 *width = allocation.width;
3327 if (priv->is_cell_renderer)
3328 *height = allocation.height;
3330 *height = req_height;
3335 gtk_entry_size_allocate (GtkWidget *widget,
3336 GtkAllocation *allocation)
3338 GtkEntry *entry = GTK_ENTRY (widget);
3340 gtk_widget_set_allocation (widget, allocation);
3342 if (gtk_widget_get_realized (widget))
3344 GtkEntryCompletion* completion;
3346 place_windows (entry);
3347 gtk_entry_recompute (entry);
3349 completion = gtk_entry_get_completion (entry);
3350 if (completion && gtk_widget_get_mapped (completion->priv->popup_window))
3351 _gtk_entry_completion_resize_popup (completion);
3356 should_prelight (GtkEntry *entry,
3357 GtkEntryIconPosition icon_pos)
3359 GtkEntryPrivate *priv = entry->priv;
3360 EntryIconInfo *icon_info = priv->icons[icon_pos];
3366 if (icon_info->nonactivatable && icon_info->target_list == NULL)
3369 if (icon_info->pressed)
3372 gtk_widget_style_get (GTK_WIDGET (entry),
3373 "icon-prelight", &prelight,
3380 draw_icon (GtkWidget *widget,
3382 GtkEntryIconPosition icon_pos)
3384 GtkEntry *entry = GTK_ENTRY (widget);
3385 GtkEntryPrivate *priv = entry->priv;
3386 EntryIconInfo *icon_info = priv->icons[icon_pos];
3387 gint x, y, width, height, pix_width, pix_height;
3388 GtkStyleContext *context;
3393 width = gdk_window_get_width (icon_info->window);
3394 height = gdk_window_get_height (icon_info->window);
3396 /* size_allocate hasn't been called yet. These are the default values.
3398 if (width == 1 || height == 1)
3402 gtk_cairo_transform_to_window (cr, widget, icon_info->window);
3404 context = gtk_widget_get_style_context (widget);
3405 gtk_entry_prepare_context_for_icon (entry, context, icon_pos);
3406 _gtk_icon_helper_get_size (icon_info->icon_helper, context, &pix_width, &pix_height);
3408 x = MAX (0, (width - pix_width) / 2);
3409 y = MAX (0, (height - pix_height) / 2);
3411 _gtk_icon_helper_draw (icon_info->icon_helper,
3415 gtk_style_context_restore (context);
3421 gtk_entry_draw_frame (GtkWidget *widget,
3422 GtkStyleContext *context,
3425 GtkEntry *entry = GTK_ENTRY (widget);
3426 GtkEntryPrivate *priv = entry->priv;
3427 gint x = 0, y = 0, width, height;
3428 gint frame_x, frame_y;
3432 get_frame_size (GTK_ENTRY (widget), FALSE, &frame_x, &frame_y, &width, &height);
3434 cairo_translate (cr, frame_x, frame_y);
3436 /* Fix a problem with some themes which assume that entry->text_area's
3437 * width equals widget->window's width
3438 * http://bugzilla.gnome.org/show_bug.cgi?id=466000 */
3439 if (GTK_IS_SPIN_BUTTON (widget))
3443 gtk_entry_get_text_area_size (GTK_ENTRY (widget), &x, NULL, &width, NULL);
3444 _gtk_entry_get_borders (GTK_ENTRY (widget), &borders);
3447 width += borders.left + borders.right;
3450 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3452 x += priv->focus_width;
3453 y += priv->focus_width;
3454 width -= 2 * priv->focus_width;
3455 height -= 2 * priv->focus_width;
3458 gtk_render_background (context, cr,
3459 x, y, width, height);
3461 if (priv->has_frame)
3462 gtk_render_frame (context, cr,
3463 x, y, width, height);
3465 gtk_entry_draw_progress (widget, context, cr);
3467 if (gtk_widget_has_visible_focus (widget) && !priv->interior_focus)
3469 x -= priv->focus_width;
3470 y -= priv->focus_width;
3471 width += 2 * priv->focus_width;
3472 height += 2 * priv->focus_width;
3474 gtk_render_focus (context, cr,
3475 0, 0, width, height);
3482 get_progress_area (GtkWidget *widget,
3488 GtkEntry *entry = GTK_ENTRY (widget);
3489 GtkEntryPrivate *private = entry->priv;
3490 GtkBorder *progress_border;
3492 get_text_area_size (entry, x, y, width, height);
3494 if (!private->interior_focus)
3496 *x -= private->focus_width;
3497 *y -= private->focus_width;
3498 *width += 2 * private->focus_width;
3499 *height += 2 * private->focus_width;
3502 gtk_widget_style_get (widget, "progress-border", &progress_border, NULL);
3504 if (progress_border)
3506 *x += progress_border->left;
3507 *y += progress_border->top;
3508 *width -= progress_border->left + progress_border->right;
3509 *height -= progress_border->top + progress_border->bottom;
3511 gtk_border_free (progress_border);
3514 if (private->progress_pulse_mode)
3516 gdouble value = private->progress_pulse_current;
3518 *x += (gint) floor(value * (*width));
3519 *width = (gint) ceil(private->progress_pulse_fraction * (*width));
3521 else if (private->progress_fraction > 0)
3523 gdouble value = private->progress_fraction;
3525 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
3529 bar_width = floor(value * (*width) + 0.5);
3530 *x += *width - bar_width;
3535 *width = (gint) floor(value * (*width) + 0.5);
3546 gtk_entry_draw_progress (GtkWidget *widget,
3547 GtkStyleContext *context,
3550 GtkEntry *entry = GTK_ENTRY (widget);
3551 GtkEntryPrivate *private = entry->priv;
3552 gint x, y, width, height;
3554 get_progress_area (widget, &x, &y, &width, &height);
3556 if ((width <= 0) || (height <= 0))
3559 gtk_style_context_save (context);
3560 gtk_style_context_add_class (context, GTK_STYLE_CLASS_PROGRESSBAR);
3561 if (private->progress_pulse_mode)
3562 gtk_style_context_add_class (context, GTK_STYLE_CLASS_PULSE);
3564 gtk_render_activity (context, cr,
3565 x, y, width, height);
3567 gtk_style_context_restore (context);
3571 gtk_entry_draw (GtkWidget *widget,
3574 GtkEntry *entry = GTK_ENTRY (widget);
3575 GtkStyleContext *context;
3576 GtkEntryPrivate *priv = entry->priv;
3579 context = gtk_widget_get_style_context (widget);
3581 /* Draw entry_bg, shadow, progress and focus */
3582 gtk_entry_draw_frame (widget, context, cr);
3584 /* Draw text and cursor */
3587 gtk_cairo_transform_to_window (cr, widget, priv->text_area);
3589 if (priv->dnd_position != -1)
3590 gtk_entry_draw_cursor (GTK_ENTRY (widget), cr, CURSOR_DND);
3592 gtk_entry_draw_text (GTK_ENTRY (widget), cr);
3594 /* When no text is being displayed at all, don't show the cursor */
3595 if (gtk_entry_get_display_mode (entry) != DISPLAY_BLANK &&
3596 gtk_widget_has_focus (widget) &&
3597 priv->selection_bound == priv->current_pos && priv->cursor_visible)
3598 gtk_entry_draw_cursor (GTK_ENTRY (widget), cr, CURSOR_STANDARD);
3603 for (i = 0; i < MAX_ICONS; i++)
3605 EntryIconInfo *icon_info = priv->icons[i];
3607 if (icon_info != NULL)
3608 draw_icon (widget, cr, i);
3615 gtk_entry_enter_notify (GtkWidget *widget,
3616 GdkEventCrossing *event)
3618 GtkEntry *entry = GTK_ENTRY (widget);
3619 GtkEntryPrivate *priv = entry->priv;
3622 for (i = 0; i < MAX_ICONS; i++)
3624 EntryIconInfo *icon_info = priv->icons[i];
3626 if (icon_info != NULL && event->window == icon_info->window)
3628 if (should_prelight (entry, i))
3630 icon_info->prelight = TRUE;
3631 gtk_widget_queue_draw (widget);
3642 gtk_entry_leave_notify (GtkWidget *widget,
3643 GdkEventCrossing *event)
3645 GtkEntry *entry = GTK_ENTRY (widget);
3646 GtkEntryPrivate *priv = entry->priv;
3649 for (i = 0; i < MAX_ICONS; i++)
3651 EntryIconInfo *icon_info = priv->icons[i];
3653 if (icon_info != NULL && event->window == icon_info->window)
3655 /* a grab means that we may never see the button release */
3656 if (event->mode == GDK_CROSSING_GRAB || event->mode == GDK_CROSSING_GTK_GRAB)
3657 icon_info->pressed = FALSE;
3659 if (should_prelight (entry, i))
3661 icon_info->prelight = FALSE;
3662 gtk_widget_queue_draw (widget);
3673 gtk_entry_get_pixel_ranges (GtkEntry *entry,
3677 gint start_char, end_char;
3679 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start_char, &end_char))
3681 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
3682 PangoLayoutLine *line = pango_layout_get_lines_readonly (layout)->data;
3683 const char *text = pango_layout_get_text (layout);
3684 gint start_index = g_utf8_offset_to_pointer (text, start_char) - text;
3685 gint end_index = g_utf8_offset_to_pointer (text, end_char) - text;
3686 gint real_n_ranges, i;
3688 pango_layout_line_get_x_ranges (line, start_index, end_index, ranges, &real_n_ranges);
3694 for (i = 0; i < real_n_ranges; ++i)
3696 r[2 * i + 1] = (r[2 * i + 1] - r[2 * i]) / PANGO_SCALE;
3697 r[2 * i] = r[2 * i] / PANGO_SCALE;
3702 *n_ranges = real_n_ranges;
3714 in_selection (GtkEntry *entry,
3719 gint retval = FALSE;
3721 gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
3723 for (i = 0; i < n_ranges; ++i)
3725 if (x >= ranges[2 * i] && x < ranges[2 * i] + ranges[2 * i + 1])
3737 gtk_entry_button_press (GtkWidget *widget,
3738 GdkEventButton *event)
3740 GtkEntry *entry = GTK_ENTRY (widget);
3741 GtkEditable *editable = GTK_EDITABLE (widget);
3742 GtkEntryPrivate *priv = entry->priv;
3743 EntryIconInfo *icon_info = NULL;
3745 gint sel_start, sel_end;
3748 for (i = 0; i < MAX_ICONS; i++)
3750 icon_info = priv->icons[i];
3752 if (!icon_info || icon_info->insensitive)
3755 if (event->window == icon_info->window)
3757 if (should_prelight (entry, i))
3759 icon_info->prelight = FALSE;
3760 gtk_widget_queue_draw (widget);
3763 priv->start_x = event->x;
3764 priv->start_y = event->y;
3765 icon_info->pressed = TRUE;
3767 if (!icon_info->nonactivatable)
3768 g_signal_emit (entry, signals[ICON_PRESS], 0, i, event);
3774 if (event->window != priv->text_area ||
3775 (priv->button && event->button != priv->button))
3778 gtk_entry_reset_blink_time (entry);
3780 priv->button = event->button;
3782 if (!gtk_widget_has_focus (widget))
3784 priv->in_click = TRUE;
3785 gtk_widget_grab_focus (widget);
3786 priv->in_click = FALSE;
3789 tmp_pos = gtk_entry_find_position (entry, event->x + priv->scroll_offset);
3791 if (gdk_event_triggers_context_menu ((GdkEvent *) event))
3793 gtk_entry_do_popup (entry, event);
3794 priv->button = 0; /* Don't wait for release, since the menu will gtk_grab_add */
3798 else if (event->button == GDK_BUTTON_PRIMARY)
3800 gboolean have_selection = gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end);
3802 priv->select_words = FALSE;
3803 priv->select_lines = FALSE;
3806 gtk_widget_get_modifier_mask (widget,
3807 GDK_MODIFIER_INTENT_EXTEND_SELECTION))
3809 _gtk_entry_reset_im_context (entry);
3811 if (!have_selection) /* select from the current position to the clicked position */
3812 sel_start = sel_end = priv->current_pos;
3814 if (tmp_pos > sel_start && tmp_pos < sel_end)
3816 /* Truncate current selection, but keep it as big as possible */
3817 if (tmp_pos - sel_start > sel_end - tmp_pos)
3818 gtk_entry_set_positions (entry, sel_start, tmp_pos);
3820 gtk_entry_set_positions (entry, tmp_pos, sel_end);
3824 gboolean extend_to_left;
3827 /* Figure out what click selects and extend current selection */
3828 switch (event->type)
3830 case GDK_BUTTON_PRESS:
3831 gtk_entry_set_positions (entry, tmp_pos, tmp_pos);
3834 case GDK_2BUTTON_PRESS:
3835 priv->select_words = TRUE;
3836 gtk_entry_select_word (entry);
3839 case GDK_3BUTTON_PRESS:
3840 priv->select_lines = TRUE;
3841 gtk_entry_select_line (entry);
3848 start = MIN (priv->current_pos, priv->selection_bound);
3849 start = MIN (sel_start, start);
3851 end = MAX (priv->current_pos, priv->selection_bound);
3852 end = MAX (sel_end, end);
3854 if (tmp_pos == sel_start || tmp_pos == sel_end)
3855 extend_to_left = (tmp_pos == start);
3857 extend_to_left = (end == sel_end);
3860 gtk_entry_set_positions (entry, start, end);
3862 gtk_entry_set_positions (entry, end, start);
3865 else /* no shift key */
3866 switch (event->type)
3868 case GDK_BUTTON_PRESS:
3869 if (in_selection (entry, event->x + priv->scroll_offset))
3871 /* Click inside the selection - we'll either start a drag, or
3872 * clear the selection
3874 priv->in_drag = TRUE;
3875 priv->drag_start_x = event->x + priv->scroll_offset;
3876 priv->drag_start_y = event->y;
3879 gtk_editable_set_position (editable, tmp_pos);
3882 case GDK_2BUTTON_PRESS:
3883 /* We ALWAYS receive a GDK_BUTTON_PRESS immediately before
3884 * receiving a GDK_2BUTTON_PRESS so we need to reset
3885 * priv->in_drag which may have been set above
3887 priv->in_drag = FALSE;
3888 priv->select_words = TRUE;
3889 gtk_entry_select_word (entry);
3892 case GDK_3BUTTON_PRESS:
3893 /* We ALWAYS receive a GDK_BUTTON_PRESS immediately before
3894 * receiving a GDK_3BUTTON_PRESS so we need to reset
3895 * priv->in_drag which may have been set above
3897 priv->in_drag = FALSE;
3898 priv->select_lines = TRUE;
3899 gtk_entry_select_line (entry);
3908 else if (event->button == GDK_BUTTON_MIDDLE && event->type == GDK_BUTTON_PRESS)
3912 priv->insert_pos = tmp_pos;
3913 gtk_entry_paste (entry, GDK_SELECTION_PRIMARY);
3918 gtk_widget_error_bell (widget);
3926 gtk_entry_button_release (GtkWidget *widget,
3927 GdkEventButton *event)
3929 GtkEntry *entry = GTK_ENTRY (widget);
3930 GtkEntryPrivate *priv = entry->priv;
3931 EntryIconInfo *icon_info = NULL;
3934 for (i = 0; i < MAX_ICONS; i++)
3936 icon_info = priv->icons[i];
3938 if (!icon_info || icon_info->insensitive)
3941 if (event->window == icon_info->window)
3943 icon_info->pressed = FALSE;
3945 if (should_prelight (entry, i) &&
3946 event->x >= 0 && event->y >= 0 &&
3947 event->x < gdk_window_get_width (icon_info->window) &&
3948 event->y < gdk_window_get_height (icon_info->window))
3950 icon_info->prelight = TRUE;
3951 gtk_widget_queue_draw (widget);
3954 if (!icon_info->nonactivatable)
3955 g_signal_emit (entry, signals[ICON_RELEASE], 0, i, event);
3961 if (event->window != priv->text_area || priv->button != event->button)
3966 gint tmp_pos = gtk_entry_find_position (entry, priv->drag_start_x);
3968 gtk_editable_set_position (GTK_EDITABLE (entry), tmp_pos);
3975 gtk_entry_update_primary_selection (entry);
3981 _gtk_entry_get_selected_text (GtkEntry *entry)
3983 GtkEditable *editable = GTK_EDITABLE (entry);
3984 gint start_text, end_text;
3987 if (gtk_editable_get_selection_bounds (editable, &start_text, &end_text))
3988 text = gtk_editable_get_chars (editable, start_text, end_text);
3994 gtk_entry_motion_notify (GtkWidget *widget,
3995 GdkEventMotion *event)
3997 GtkEntry *entry = GTK_ENTRY (widget);
3998 GtkEntryPrivate *priv = entry->priv;
3999 EntryIconInfo *icon_info = NULL;
4003 for (i = 0; i < MAX_ICONS; i++)
4005 icon_info = priv->icons[i];
4007 if (!icon_info || icon_info->insensitive)
4010 if (event->window == icon_info->window)
4012 if (icon_info->pressed &&
4013 icon_info->target_list != NULL &&
4014 gtk_drag_check_threshold (widget,
4020 icon_info->in_drag = TRUE;
4021 icon_info->pressed = FALSE;
4022 gtk_drag_begin (widget,
4023 icon_info->target_list,
4033 if (priv->mouse_cursor_obscured)
4037 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
4038 gdk_window_set_cursor (priv->text_area, cursor);
4039 g_object_unref (cursor);
4040 priv->mouse_cursor_obscured = FALSE;
4043 if (event->window != priv->text_area || priv->button != GDK_BUTTON_PRIMARY)
4046 if (priv->select_lines)
4049 gdk_event_request_motions (event);
4053 if (gtk_entry_get_display_mode (entry) == DISPLAY_NORMAL &&
4054 gtk_drag_check_threshold (widget,
4055 priv->drag_start_x, priv->drag_start_y,
4056 event->x + priv->scroll_offset, event->y))
4058 GdkDragContext *context;
4059 GtkTargetList *target_list = gtk_target_list_new (NULL, 0);
4060 guint actions = priv->editable ? GDK_ACTION_COPY | GDK_ACTION_MOVE : GDK_ACTION_COPY;
4062 cairo_surface_t *surface;
4064 gtk_target_list_add_text_targets (target_list, 0);
4066 text = _gtk_entry_get_selected_text (entry);
4067 surface = _gtk_text_util_create_drag_icon (widget, text, -1);
4069 context = gtk_drag_begin (widget, target_list, actions,
4070 priv->button, (GdkEvent *)event);
4073 gtk_drag_set_icon_surface (context, surface);
4075 gtk_drag_set_icon_default (context);
4078 cairo_surface_destroy (surface);
4081 priv->in_drag = FALSE;
4084 gtk_target_list_unref (target_list);
4091 else if (event->y >= gdk_window_get_height (priv->text_area))
4092 tmp_pos = gtk_entry_buffer_get_length (get_buffer (entry));
4094 tmp_pos = gtk_entry_find_position (entry, event->x + priv->scroll_offset);
4096 if (priv->select_words)
4099 gint old_min, old_max;
4102 min = gtk_entry_move_backward_word (entry, tmp_pos, TRUE);
4103 max = gtk_entry_move_forward_word (entry, tmp_pos, TRUE);
4105 pos = priv->current_pos;
4106 bound = priv->selection_bound;
4108 old_min = MIN(priv->current_pos, priv->selection_bound);
4109 old_max = MAX(priv->current_pos, priv->selection_bound);
4116 else if (old_max < max)
4121 else if (pos == old_min)
4123 if (priv->current_pos != min)
4128 if (priv->current_pos != max)
4132 gtk_entry_set_positions (entry, pos, bound);
4135 gtk_entry_set_positions (entry, tmp_pos, -1);
4142 set_invisible_cursor (GdkWindow *window)
4144 GdkDisplay *display;
4147 display = gdk_window_get_display (window);
4148 cursor = gdk_cursor_new_for_display (display, GDK_BLANK_CURSOR);
4150 gdk_window_set_cursor (window, cursor);
4152 g_object_unref (cursor);
4156 gtk_entry_obscure_mouse_cursor (GtkEntry *entry)
4158 GtkEntryPrivate *priv = entry->priv;
4160 if (priv->mouse_cursor_obscured)
4163 set_invisible_cursor (priv->text_area);
4165 priv->mouse_cursor_obscured = TRUE;
4169 gtk_entry_key_press (GtkWidget *widget,
4172 GtkEntry *entry = GTK_ENTRY (widget);
4173 GtkEntryPrivate *priv = entry->priv;
4175 gtk_entry_reset_blink_time (entry);
4176 gtk_entry_pend_cursor_blink (entry);
4180 if (gtk_im_context_filter_keypress (priv->im_context, event))
4182 gtk_entry_obscure_mouse_cursor (entry);
4183 priv->need_im_reset = TRUE;
4188 if (event->keyval == GDK_KEY_Return ||
4189 event->keyval == GDK_KEY_KP_Enter ||
4190 event->keyval == GDK_KEY_ISO_Enter ||
4191 event->keyval == GDK_KEY_Escape)
4193 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
4195 if (completion && completion->priv->completion_timeout)
4197 g_source_remove (completion->priv->completion_timeout);
4198 completion->priv->completion_timeout = 0;
4201 _gtk_entry_reset_im_context (entry);
4204 if (GTK_WIDGET_CLASS (gtk_entry_parent_class)->key_press_event (widget, event))
4205 /* Activate key bindings
4209 if (!priv->editable && event->length)
4210 gtk_widget_error_bell (widget);
4216 gtk_entry_key_release (GtkWidget *widget,
4219 GtkEntry *entry = GTK_ENTRY (widget);
4220 GtkEntryPrivate *priv = entry->priv;
4224 if (gtk_im_context_filter_keypress (priv->im_context, event))
4226 priv->need_im_reset = TRUE;
4231 return GTK_WIDGET_CLASS (gtk_entry_parent_class)->key_release_event (widget, event);
4235 gtk_entry_focus_in (GtkWidget *widget,
4236 GdkEventFocus *event)
4238 GtkEntry *entry = GTK_ENTRY (widget);
4239 GtkEntryPrivate *priv = entry->priv;
4242 gtk_widget_queue_draw (widget);
4244 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (widget));
4248 priv->need_im_reset = TRUE;
4249 gtk_im_context_focus_in (priv->im_context);
4250 keymap_state_changed (keymap, entry);
4251 g_signal_connect (keymap, "state-changed",
4252 G_CALLBACK (keymap_state_changed), entry);
4255 g_signal_connect (keymap, "direction-changed",
4256 G_CALLBACK (keymap_direction_changed), entry);
4258 if (gtk_entry_buffer_get_bytes (get_buffer (entry)) == 0 &&
4259 priv->placeholder_text != NULL)
4261 gtk_entry_recompute (entry);
4265 gtk_entry_reset_blink_time (entry);
4266 gtk_entry_check_cursor_blink (entry);
4273 gtk_entry_focus_out (GtkWidget *widget,
4274 GdkEventFocus *event)
4276 GtkEntry *entry = GTK_ENTRY (widget);
4277 GtkEntryPrivate *priv = entry->priv;
4278 GtkEntryCompletion *completion;
4281 gtk_widget_queue_draw (widget);
4283 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (widget));
4287 priv->need_im_reset = TRUE;
4288 gtk_im_context_focus_out (priv->im_context);
4289 remove_capslock_feedback (entry);
4292 if (gtk_entry_buffer_get_bytes (get_buffer (entry)) == 0 &&
4293 priv->placeholder_text != NULL)
4295 gtk_entry_recompute (entry);
4299 gtk_entry_check_cursor_blink (entry);
4302 g_signal_handlers_disconnect_by_func (keymap, keymap_state_changed, entry);
4303 g_signal_handlers_disconnect_by_func (keymap, keymap_direction_changed, entry);
4305 completion = gtk_entry_get_completion (entry);
4307 _gtk_entry_completion_popdown (completion);
4313 gtk_entry_grab_focus (GtkWidget *widget)
4315 GtkEntry *entry = GTK_ENTRY (widget);
4316 GtkEntryPrivate *priv = entry->priv;
4317 gboolean select_on_focus;
4319 GTK_WIDGET_CLASS (gtk_entry_parent_class)->grab_focus (widget);
4321 if (priv->editable && !priv->in_click)
4323 g_object_get (gtk_widget_get_settings (widget),
4324 "gtk-entry-select-on-focus",
4328 if (select_on_focus)
4329 gtk_editable_select_region (GTK_EDITABLE (widget), 0, -1);
4334 gtk_entry_direction_changed (GtkWidget *widget,
4335 GtkTextDirection previous_dir)
4337 GtkEntry *entry = GTK_ENTRY (widget);
4339 gtk_entry_recompute (entry);
4341 GTK_WIDGET_CLASS (gtk_entry_parent_class)->direction_changed (widget, previous_dir);
4345 gtk_entry_state_flags_changed (GtkWidget *widget,
4346 GtkStateFlags previous_state)
4348 GtkEntry *entry = GTK_ENTRY (widget);
4349 GtkEntryPrivate *priv = entry->priv;
4352 if (gtk_widget_get_realized (widget))
4354 if (gtk_widget_is_sensitive (widget))
4355 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
4359 gdk_window_set_cursor (priv->text_area, cursor);
4362 g_object_unref (cursor);
4364 priv->mouse_cursor_obscured = FALSE;
4366 update_cursors (widget);
4369 if (!gtk_widget_is_sensitive (widget))
4371 /* Clear any selection */
4372 gtk_editable_select_region (GTK_EDITABLE (entry), priv->current_pos, priv->current_pos);
4375 gtk_entry_update_cached_style_values (entry);
4379 gtk_entry_screen_changed (GtkWidget *widget,
4380 GdkScreen *old_screen)
4382 gtk_entry_recompute (GTK_ENTRY (widget));
4385 /* GtkEditable method implementations
4388 gtk_entry_insert_text (GtkEditable *editable,
4389 const gchar *new_text,
4390 gint new_text_length,
4393 g_object_ref (editable);
4396 * The incoming text may a password or other secret. We make sure
4397 * not to copy it into temporary buffers.
4400 g_signal_emit_by_name (editable, "insert-text", new_text, new_text_length, position);
4402 g_object_unref (editable);
4406 gtk_entry_delete_text (GtkEditable *editable,
4410 g_object_ref (editable);
4412 g_signal_emit_by_name (editable, "delete-text", start_pos, end_pos);
4414 g_object_unref (editable);
4418 gtk_entry_get_chars (GtkEditable *editable,
4422 GtkEntry *entry = GTK_ENTRY (editable);
4425 gint start_index, end_index;
4427 text = gtk_entry_buffer_get_text (get_buffer (entry));
4428 text_length = gtk_entry_buffer_get_length (get_buffer (entry));
4431 end_pos = text_length;
4433 start_pos = MIN (text_length, start_pos);
4434 end_pos = MIN (text_length, end_pos);
4436 start_index = g_utf8_offset_to_pointer (text, start_pos) - text;
4437 end_index = g_utf8_offset_to_pointer (text, end_pos) - text;
4439 return g_strndup (text + start_index, end_index - start_index);
4443 gtk_entry_real_set_position (GtkEditable *editable,
4446 GtkEntry *entry = GTK_ENTRY (editable);
4447 GtkEntryPrivate *priv = entry->priv;
4451 length = gtk_entry_buffer_get_length (get_buffer (entry));
4452 if (position < 0 || position > length)
4455 if (position != priv->current_pos ||
4456 position != priv->selection_bound)
4458 _gtk_entry_reset_im_context (entry);
4459 gtk_entry_set_positions (entry, position, position);
4464 gtk_entry_get_position (GtkEditable *editable)
4466 GtkEntry *entry = GTK_ENTRY (editable);
4467 GtkEntryPrivate *priv = entry->priv;
4469 return priv->current_pos;
4473 gtk_entry_set_selection_bounds (GtkEditable *editable,
4477 GtkEntry *entry = GTK_ENTRY (editable);
4480 length = gtk_entry_buffer_get_length (get_buffer (entry));
4486 _gtk_entry_reset_im_context (entry);
4488 gtk_entry_set_positions (entry,
4490 MIN (start, length));
4492 gtk_entry_update_primary_selection (entry);
4496 gtk_entry_get_selection_bounds (GtkEditable *editable,
4500 GtkEntry *entry = GTK_ENTRY (editable);
4501 GtkEntryPrivate *priv = entry->priv;
4503 *start = priv->selection_bound;
4504 *end = priv->current_pos;
4506 return (priv->selection_bound != priv->current_pos);
4510 icon_theme_changed (GtkEntry *entry)
4512 GtkEntryPrivate *priv = entry->priv;
4515 for (i = 0; i < MAX_ICONS; i++)
4517 EntryIconInfo *icon_info = priv->icons[i];
4518 if (icon_info != NULL)
4519 _gtk_icon_helper_invalidate (icon_info->icon_helper);
4522 gtk_widget_queue_draw (GTK_WIDGET (entry));
4526 icon_margin_changed (GtkEntry *entry)
4528 GtkEntryPrivate *priv = entry->priv;
4531 _gtk_entry_get_borders (GTK_ENTRY (entry), &border);
4533 priv->icon_margin = border.left;
4537 gtk_entry_update_cached_style_values (GtkEntry *entry)
4539 GtkEntryPrivate *priv = entry->priv;
4541 gboolean interior_focus;
4543 gtk_widget_style_get (GTK_WIDGET (entry),
4544 "focus-line-width", &focus_width,
4545 "interior-focus", &interior_focus,
4547 priv->focus_width = focus_width;
4548 priv->interior_focus = interior_focus;
4550 if (!priv->invisible_char_set)
4552 gunichar ch = find_invisible_char (GTK_WIDGET (entry));
4554 if (priv->invisible_char != ch)
4556 priv->invisible_char = ch;
4557 g_object_notify (G_OBJECT (entry), "invisible-char");
4563 gtk_entry_style_updated (GtkWidget *widget)
4565 GtkEntry *entry = GTK_ENTRY (widget);
4567 GTK_WIDGET_CLASS (gtk_entry_parent_class)->style_updated (widget);
4569 gtk_entry_update_cached_style_values (entry);
4571 gtk_entry_recompute (entry);
4573 icon_theme_changed (entry);
4574 icon_margin_changed (entry);
4577 /* GtkCellEditable method implementations
4580 gtk_cell_editable_entry_activated (GtkEntry *entry, gpointer data)
4582 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4583 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4587 gtk_cell_editable_key_press_event (GtkEntry *entry,
4588 GdkEventKey *key_event,
4591 GtkEntryPrivate *priv = entry->priv;
4593 if (key_event->keyval == GDK_KEY_Escape)
4595 priv->editing_canceled = TRUE;
4596 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4597 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4602 /* override focus */
4603 if (key_event->keyval == GDK_KEY_Up || key_event->keyval == GDK_KEY_Down)
4605 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4606 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4615 gtk_entry_start_editing (GtkCellEditable *cell_editable,
4618 GtkEntry *entry = GTK_ENTRY (cell_editable);
4619 GtkEntryPrivate *priv = entry->priv;
4621 priv->is_cell_renderer = TRUE;
4623 g_signal_connect (cell_editable, "activate",
4624 G_CALLBACK (gtk_cell_editable_entry_activated), NULL);
4625 g_signal_connect (cell_editable, "key-press-event",
4626 G_CALLBACK (gtk_cell_editable_key_press_event), NULL);
4630 gtk_entry_password_hint_free (GtkEntryPasswordHint *password_hint)
4632 if (password_hint->source_id)
4633 g_source_remove (password_hint->source_id);
4635 g_slice_free (GtkEntryPasswordHint, password_hint);
4640 gtk_entry_remove_password_hint (gpointer data)
4642 GtkEntryPasswordHint *password_hint = g_object_get_qdata (data, quark_password_hint);
4643 password_hint->position = -1;
4645 /* Force the string to be redrawn, but now without a visible character */
4646 gtk_entry_recompute (GTK_ENTRY (data));
4650 /* Default signal handlers
4653 gtk_entry_real_insert_text (GtkEditable *editable,
4654 const gchar *new_text,
4655 gint new_text_length,
4661 n_chars = g_utf8_strlen (new_text, new_text_length);
4664 * The actual insertion into the buffer. This will end up firing the
4665 * following signal handlers: buffer_inserted_text(), buffer_notify_display_text(),
4666 * buffer_notify_text(), buffer_notify_length()
4668 begin_change (GTK_ENTRY (editable));
4670 n_inserted = gtk_entry_buffer_insert_text (get_buffer (GTK_ENTRY (editable)), *position, new_text, n_chars);
4672 end_change (GTK_ENTRY (editable));
4674 if (n_inserted != n_chars)
4675 gtk_widget_error_bell (GTK_WIDGET (editable));
4677 *position += n_inserted;
4681 gtk_entry_real_delete_text (GtkEditable *editable,
4686 * The actual deletion from the buffer. This will end up firing the
4687 * following signal handlers: buffer_deleted_text(), buffer_notify_display_text(),
4688 * buffer_notify_text(), buffer_notify_length()
4691 begin_change (GTK_ENTRY (editable));
4693 gtk_entry_buffer_delete_text (get_buffer (GTK_ENTRY (editable)), start_pos, end_pos - start_pos);
4695 end_change (GTK_ENTRY (editable));
4698 /* GtkEntryBuffer signal handlers
4701 buffer_inserted_text (GtkEntryBuffer *buffer,
4707 GtkEntryPrivate *priv = entry->priv;
4708 guint password_hint_timeout;
4710 gint selection_bound;
4712 current_pos = priv->current_pos;
4713 if (current_pos > position)
4714 current_pos += n_chars;
4716 selection_bound = priv->selection_bound;
4717 if (selection_bound > position)
4718 selection_bound += n_chars;
4720 gtk_entry_set_positions (entry, current_pos, selection_bound);
4722 /* Calculate the password hint if it needs to be displayed. */
4723 if (n_chars == 1 && !priv->visible)
4725 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
4726 "gtk-entry-password-hint-timeout", &password_hint_timeout,
4729 if (password_hint_timeout > 0)
4731 GtkEntryPasswordHint *password_hint = g_object_get_qdata (G_OBJECT (entry),
4732 quark_password_hint);
4735 password_hint = g_slice_new0 (GtkEntryPasswordHint);
4736 g_object_set_qdata_full (G_OBJECT (entry), quark_password_hint, password_hint,
4737 (GDestroyNotify)gtk_entry_password_hint_free);
4740 password_hint->position = position;
4741 if (password_hint->source_id)
4742 g_source_remove (password_hint->source_id);
4743 password_hint->source_id = gdk_threads_add_timeout (password_hint_timeout,
4744 (GSourceFunc)gtk_entry_remove_password_hint, entry);
4750 buffer_deleted_text (GtkEntryBuffer *buffer,
4755 GtkEntryPrivate *priv = entry->priv;
4756 guint end_pos = position + n_chars;
4757 gint selection_bound;
4760 current_pos = priv->current_pos;
4761 if (current_pos > position)
4762 current_pos -= MIN (current_pos, end_pos) - position;
4764 selection_bound = priv->selection_bound;
4765 if (selection_bound > position)
4766 selection_bound -= MIN (selection_bound, end_pos) - position;
4768 gtk_entry_set_positions (entry, current_pos, selection_bound);
4770 /* We might have deleted the selection */
4771 gtk_entry_update_primary_selection (entry);
4773 /* Disable the password hint if one exists. */
4776 GtkEntryPasswordHint *password_hint = g_object_get_qdata (G_OBJECT (entry),
4777 quark_password_hint);
4780 if (password_hint->source_id)
4781 g_source_remove (password_hint->source_id);
4782 password_hint->source_id = 0;
4783 password_hint->position = -1;
4789 buffer_notify_text (GtkEntryBuffer *buffer,
4793 gtk_entry_recompute (entry);
4794 emit_changed (entry);
4795 g_object_notify (G_OBJECT (entry), "text");
4799 buffer_notify_length (GtkEntryBuffer *buffer,
4803 g_object_notify (G_OBJECT (entry), "text-length");
4807 buffer_notify_max_length (GtkEntryBuffer *buffer,
4811 g_object_notify (G_OBJECT (entry), "max-length");
4815 buffer_connect_signals (GtkEntry *entry)
4817 g_signal_connect (get_buffer (entry), "inserted-text", G_CALLBACK (buffer_inserted_text), entry);
4818 g_signal_connect (get_buffer (entry), "deleted-text", G_CALLBACK (buffer_deleted_text), entry);
4819 g_signal_connect (get_buffer (entry), "notify::text", G_CALLBACK (buffer_notify_text), entry);
4820 g_signal_connect (get_buffer (entry), "notify::length", G_CALLBACK (buffer_notify_length), entry);
4821 g_signal_connect (get_buffer (entry), "notify::max-length", G_CALLBACK (buffer_notify_max_length), entry);
4825 buffer_disconnect_signals (GtkEntry *entry)
4827 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_inserted_text, entry);
4828 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_deleted_text, entry);
4829 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_text, entry);
4830 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_length, entry);
4831 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_max_length, entry);
4834 /* Compute the X position for an offset that corresponds to the "more important
4835 * cursor position for that offset. We use this when trying to guess to which
4836 * end of the selection we should go to when the user hits the left or
4840 get_better_cursor_x (GtkEntry *entry,
4843 GtkEntryPrivate *priv = entry->priv;
4844 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
4845 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
4846 gboolean split_cursor;
4848 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
4849 const gchar *text = pango_layout_get_text (layout);
4850 gint index = g_utf8_offset_to_pointer (text, offset) - text;
4852 PangoRectangle strong_pos, weak_pos;
4854 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
4855 "gtk-split-cursor", &split_cursor,
4858 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
4861 return strong_pos.x / PANGO_SCALE;
4863 return (keymap_direction == priv->resolved_dir) ? strong_pos.x / PANGO_SCALE : weak_pos.x / PANGO_SCALE;
4867 gtk_entry_move_cursor (GtkEntry *entry,
4868 GtkMovementStep step,
4870 gboolean extend_selection)
4872 GtkEntryPrivate *priv = entry->priv;
4873 gint new_pos = priv->current_pos;
4875 _gtk_entry_reset_im_context (entry);
4877 if (priv->current_pos != priv->selection_bound && !extend_selection)
4879 /* If we have a current selection and aren't extending it, move to the
4880 * start/or end of the selection as appropriate
4884 case GTK_MOVEMENT_VISUAL_POSITIONS:
4886 gint current_x = get_better_cursor_x (entry, priv->current_pos);
4887 gint bound_x = get_better_cursor_x (entry, priv->selection_bound);
4890 new_pos = current_x < bound_x ? priv->current_pos : priv->selection_bound;
4892 new_pos = current_x > bound_x ? priv->current_pos : priv->selection_bound;
4895 case GTK_MOVEMENT_LOGICAL_POSITIONS:
4896 case GTK_MOVEMENT_WORDS:
4898 new_pos = MIN (priv->current_pos, priv->selection_bound);
4900 new_pos = MAX (priv->current_pos, priv->selection_bound);
4902 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
4903 case GTK_MOVEMENT_PARAGRAPH_ENDS:
4904 case GTK_MOVEMENT_BUFFER_ENDS:
4905 new_pos = count < 0 ? 0 : gtk_entry_buffer_get_length (get_buffer (entry));
4907 case GTK_MOVEMENT_DISPLAY_LINES:
4908 case GTK_MOVEMENT_PARAGRAPHS:
4909 case GTK_MOVEMENT_PAGES:
4910 case GTK_MOVEMENT_HORIZONTAL_PAGES:
4918 case GTK_MOVEMENT_LOGICAL_POSITIONS:
4919 new_pos = gtk_entry_move_logically (entry, new_pos, count);
4921 case GTK_MOVEMENT_VISUAL_POSITIONS:
4922 new_pos = gtk_entry_move_visually (entry, new_pos, count);
4923 if (priv->current_pos == new_pos)
4925 if (!extend_selection)
4927 if (!gtk_widget_keynav_failed (GTK_WIDGET (entry),
4929 GTK_DIR_RIGHT : GTK_DIR_LEFT))
4931 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (entry));
4934 gtk_widget_child_focus (toplevel,
4936 GTK_DIR_RIGHT : GTK_DIR_LEFT);
4941 gtk_widget_error_bell (GTK_WIDGET (entry));
4945 case GTK_MOVEMENT_WORDS:
4948 new_pos = gtk_entry_move_forward_word (entry, new_pos, FALSE);
4953 new_pos = gtk_entry_move_backward_word (entry, new_pos, FALSE);
4956 if (priv->current_pos == new_pos)
4957 gtk_widget_error_bell (GTK_WIDGET (entry));
4959 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
4960 case GTK_MOVEMENT_PARAGRAPH_ENDS:
4961 case GTK_MOVEMENT_BUFFER_ENDS:
4962 new_pos = count < 0 ? 0 : gtk_entry_buffer_get_length (get_buffer (entry));
4963 if (priv->current_pos == new_pos)
4964 gtk_widget_error_bell (GTK_WIDGET (entry));
4966 case GTK_MOVEMENT_DISPLAY_LINES:
4967 case GTK_MOVEMENT_PARAGRAPHS:
4968 case GTK_MOVEMENT_PAGES:
4969 case GTK_MOVEMENT_HORIZONTAL_PAGES:
4974 if (extend_selection)
4975 gtk_editable_select_region (GTK_EDITABLE (entry), priv->selection_bound, new_pos);
4977 gtk_editable_set_position (GTK_EDITABLE (entry), new_pos);
4979 gtk_entry_pend_cursor_blink (entry);
4983 gtk_entry_insert_at_cursor (GtkEntry *entry,
4986 GtkEntryPrivate *priv = entry->priv;
4987 GtkEditable *editable = GTK_EDITABLE (entry);
4988 gint pos = priv->current_pos;
4992 _gtk_entry_reset_im_context (entry);
4994 gtk_editable_insert_text (editable, str, -1, &pos);
4995 gtk_editable_set_position (editable, pos);
5000 gtk_entry_delete_from_cursor (GtkEntry *entry,
5004 GtkEntryPrivate *priv = entry->priv;
5005 GtkEditable *editable = GTK_EDITABLE (entry);
5006 gint start_pos = priv->current_pos;
5007 gint end_pos = priv->current_pos;
5008 gint old_n_bytes = gtk_entry_buffer_get_bytes (get_buffer (entry));
5010 _gtk_entry_reset_im_context (entry);
5012 if (!priv->editable)
5014 gtk_widget_error_bell (GTK_WIDGET (entry));
5018 if (priv->selection_bound != priv->current_pos)
5020 gtk_editable_delete_selection (editable);
5026 case GTK_DELETE_CHARS:
5027 end_pos = gtk_entry_move_logically (entry, priv->current_pos, count);
5028 gtk_editable_delete_text (editable, MIN (start_pos, end_pos), MAX (start_pos, end_pos));
5030 case GTK_DELETE_WORDS:
5033 /* Move to end of current word, or if not on a word, end of previous word */
5034 end_pos = gtk_entry_move_backward_word (entry, end_pos, FALSE);
5035 end_pos = gtk_entry_move_forward_word (entry, end_pos, FALSE);
5039 /* Move to beginning of current word, or if not on a word, begining of next word */
5040 start_pos = gtk_entry_move_forward_word (entry, start_pos, FALSE);
5041 start_pos = gtk_entry_move_backward_word (entry, start_pos, FALSE);
5045 case GTK_DELETE_WORD_ENDS:
5048 start_pos = gtk_entry_move_backward_word (entry, start_pos, FALSE);
5053 end_pos = gtk_entry_move_forward_word (entry, end_pos, FALSE);
5056 gtk_editable_delete_text (editable, start_pos, end_pos);
5058 case GTK_DELETE_DISPLAY_LINE_ENDS:
5059 case GTK_DELETE_PARAGRAPH_ENDS:
5061 gtk_editable_delete_text (editable, 0, priv->current_pos);
5063 gtk_editable_delete_text (editable, priv->current_pos, -1);
5065 case GTK_DELETE_DISPLAY_LINES:
5066 case GTK_DELETE_PARAGRAPHS:
5067 gtk_editable_delete_text (editable, 0, -1);
5069 case GTK_DELETE_WHITESPACE:
5070 gtk_entry_delete_whitespace (entry);
5074 if (gtk_entry_buffer_get_bytes (get_buffer (entry)) == old_n_bytes)
5075 gtk_widget_error_bell (GTK_WIDGET (entry));
5077 gtk_entry_pend_cursor_blink (entry);
5081 gtk_entry_backspace (GtkEntry *entry)
5083 GtkEntryPrivate *priv = entry->priv;
5084 GtkEditable *editable = GTK_EDITABLE (entry);
5087 _gtk_entry_reset_im_context (entry);
5089 if (!priv->editable)
5091 gtk_widget_error_bell (GTK_WIDGET (entry));
5095 if (priv->selection_bound != priv->current_pos)
5097 gtk_editable_delete_selection (editable);
5101 prev_pos = gtk_entry_move_logically (entry, priv->current_pos, -1);
5103 if (prev_pos < priv->current_pos)
5105 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
5106 PangoLogAttr *log_attrs;
5109 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
5111 /* Deleting parts of characters */
5112 if (log_attrs[priv->current_pos].backspace_deletes_character)
5114 gchar *cluster_text;
5115 gchar *normalized_text;
5118 cluster_text = gtk_entry_get_display_text (entry, prev_pos,
5120 normalized_text = g_utf8_normalize (cluster_text,
5121 strlen (cluster_text),
5123 len = g_utf8_strlen (normalized_text, -1);
5125 gtk_editable_delete_text (editable, prev_pos, priv->current_pos);
5128 gint pos = priv->current_pos;
5130 gtk_editable_insert_text (editable, normalized_text,
5131 g_utf8_offset_to_pointer (normalized_text, len - 1) - normalized_text,
5133 gtk_editable_set_position (editable, pos);
5136 g_free (normalized_text);
5137 g_free (cluster_text);
5141 gtk_editable_delete_text (editable, prev_pos, priv->current_pos);
5148 gtk_widget_error_bell (GTK_WIDGET (entry));
5151 gtk_entry_pend_cursor_blink (entry);
5155 gtk_entry_copy_clipboard (GtkEntry *entry)
5157 GtkEntryPrivate *priv = entry->priv;
5158 GtkEditable *editable = GTK_EDITABLE (entry);
5162 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5166 gtk_widget_error_bell (GTK_WIDGET (entry));
5170 str = gtk_entry_get_display_text (entry, start, end);
5171 gtk_clipboard_set_text (gtk_widget_get_clipboard (GTK_WIDGET (entry),
5172 GDK_SELECTION_CLIPBOARD),
5179 gtk_entry_cut_clipboard (GtkEntry *entry)
5181 GtkEntryPrivate *priv = entry->priv;
5182 GtkEditable *editable = GTK_EDITABLE (entry);
5187 gtk_widget_error_bell (GTK_WIDGET (entry));
5191 gtk_entry_copy_clipboard (entry);
5195 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5196 gtk_editable_delete_text (editable, start, end);
5200 gtk_widget_error_bell (GTK_WIDGET (entry));
5205 gtk_entry_paste_clipboard (GtkEntry *entry)
5207 GtkEntryPrivate *priv = entry->priv;
5210 gtk_entry_paste (entry, GDK_SELECTION_CLIPBOARD);
5212 gtk_widget_error_bell (GTK_WIDGET (entry));
5216 gtk_entry_delete_cb (GtkEntry *entry)
5218 GtkEntryPrivate *priv = entry->priv;
5219 GtkEditable *editable = GTK_EDITABLE (entry);
5224 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5225 gtk_editable_delete_text (editable, start, end);
5230 gtk_entry_toggle_overwrite (GtkEntry *entry)
5232 GtkEntryPrivate *priv = entry->priv;
5234 priv->overwrite_mode = !priv->overwrite_mode;
5235 gtk_entry_pend_cursor_blink (entry);
5236 gtk_widget_queue_draw (GTK_WIDGET (entry));
5240 gtk_entry_select_all (GtkEntry *entry)
5242 gtk_entry_select_line (entry);
5246 gtk_entry_real_activate (GtkEntry *entry)
5248 GtkEntryPrivate *priv = entry->priv;
5250 GtkWidget *default_widget, *focus_widget;
5251 GtkWidget *toplevel;
5254 widget = GTK_WIDGET (entry);
5256 if (priv->activates_default)
5258 toplevel = gtk_widget_get_toplevel (widget);
5259 if (GTK_IS_WINDOW (toplevel))
5261 window = GTK_WINDOW (toplevel);
5265 default_widget = gtk_window_get_default_widget (window);
5266 focus_widget = gtk_window_get_focus (window);
5267 if (widget != default_widget &&
5268 !(widget == focus_widget && (!default_widget || !gtk_widget_get_sensitive (default_widget))))
5269 gtk_window_activate_default (window);
5276 keymap_direction_changed (GdkKeymap *keymap,
5279 gtk_entry_recompute (entry);
5282 /* IM Context Callbacks
5286 gtk_entry_commit_cb (GtkIMContext *context,
5290 GtkEntryPrivate *priv = entry->priv;
5293 gtk_entry_enter_text (entry, str);
5297 gtk_entry_preedit_changed_cb (GtkIMContext *context,
5300 GtkEntryPrivate *priv = entry->priv;
5304 gchar *preedit_string;
5307 gtk_im_context_get_preedit_string (priv->im_context,
5308 &preedit_string, NULL,
5310 g_signal_emit (entry, signals[PREEDIT_CHANGED], 0, preedit_string);
5311 priv->preedit_length = strlen (preedit_string);
5312 cursor_pos = CLAMP (cursor_pos, 0, g_utf8_strlen (preedit_string, -1));
5313 priv->preedit_cursor = cursor_pos;
5314 g_free (preedit_string);
5316 gtk_entry_recompute (entry);
5321 gtk_entry_retrieve_surrounding_cb (GtkIMContext *context,
5324 GtkEntryPrivate *priv = entry->priv;
5327 /* XXXX ??? does this even make sense when text is not visible? Should we return FALSE? */
5328 text = gtk_entry_get_display_text (entry, 0, -1);
5329 gtk_im_context_set_surrounding (context, text, strlen (text), /* Length in bytes */
5330 g_utf8_offset_to_pointer (text, priv->current_pos) - text);
5337 gtk_entry_delete_surrounding_cb (GtkIMContext *slave,
5342 GtkEntryPrivate *priv = entry->priv;
5345 gtk_editable_delete_text (GTK_EDITABLE (entry),
5346 priv->current_pos + offset,
5347 priv->current_pos + offset + n_chars);
5352 /* Internal functions
5355 /* Used for im_commit_cb and inserting Unicode chars */
5357 gtk_entry_enter_text (GtkEntry *entry,
5360 GtkEntryPrivate *priv = entry->priv;
5361 GtkEditable *editable = GTK_EDITABLE (entry);
5363 gboolean old_need_im_reset;
5365 old_need_im_reset = priv->need_im_reset;
5366 priv->need_im_reset = FALSE;
5368 if (gtk_editable_get_selection_bounds (editable, NULL, NULL))
5369 gtk_editable_delete_selection (editable);
5372 if (priv->overwrite_mode)
5373 gtk_entry_delete_from_cursor (entry, GTK_DELETE_CHARS, 1);
5376 tmp_pos = priv->current_pos;
5377 gtk_editable_insert_text (editable, str, strlen (str), &tmp_pos);
5378 gtk_editable_set_position (editable, tmp_pos);
5380 priv->need_im_reset = old_need_im_reset;
5383 /* All changes to priv->current_pos and priv->selection_bound
5384 * should go through this function.
5387 gtk_entry_set_positions (GtkEntry *entry,
5389 gint selection_bound)
5391 GtkEntryPrivate *priv = entry->priv;
5392 gboolean changed = FALSE;
5394 g_object_freeze_notify (G_OBJECT (entry));
5396 if (current_pos != -1 &&
5397 priv->current_pos != current_pos)
5399 priv->current_pos = current_pos;
5402 g_object_notify (G_OBJECT (entry), "cursor-position");
5405 if (selection_bound != -1 &&
5406 priv->selection_bound != selection_bound)
5408 priv->selection_bound = selection_bound;
5411 g_object_notify (G_OBJECT (entry), "selection-bound");
5414 g_object_thaw_notify (G_OBJECT (entry));
5418 gtk_entry_move_adjustments (entry);
5419 gtk_entry_recompute (entry);
5424 gtk_entry_reset_layout (GtkEntry *entry)
5426 GtkEntryPrivate *priv = entry->priv;
5428 if (priv->cached_layout)
5430 g_object_unref (priv->cached_layout);
5431 priv->cached_layout = NULL;
5436 update_im_cursor_location (GtkEntry *entry)
5438 GtkEntryPrivate *priv = entry->priv;
5441 gint strong_xoffset;
5442 gint area_width, area_height;
5444 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
5445 gtk_entry_get_text_area_size (entry, NULL, NULL, &area_width, &area_height);
5447 strong_xoffset = strong_x - priv->scroll_offset;
5448 if (strong_xoffset < 0)
5452 else if (strong_xoffset > area_width)
5454 strong_xoffset = area_width;
5456 area.x = strong_xoffset;
5459 area.height = area_height;
5461 gtk_im_context_set_cursor_location (priv->im_context, &area);
5465 recompute_idle_func (gpointer data)
5467 GtkEntry *entry = GTK_ENTRY (data);
5468 GtkEntryPrivate *priv = entry->priv;
5470 priv->recompute_idle = 0;
5472 if (gtk_widget_has_screen (GTK_WIDGET (entry)))
5474 gtk_entry_adjust_scroll (entry);
5475 gtk_widget_queue_draw (GTK_WIDGET (entry));
5477 update_im_cursor_location (entry);
5484 gtk_entry_recompute (GtkEntry *entry)
5486 GtkEntryPrivate *priv = entry->priv;
5488 gtk_entry_reset_layout (entry);
5489 gtk_entry_check_cursor_blink (entry);
5491 if (!priv->recompute_idle)
5493 priv->recompute_idle = gdk_threads_add_idle_full (G_PRIORITY_HIGH_IDLE + 15, /* between resize and redraw */
5494 recompute_idle_func, entry, NULL);
5499 gtk_entry_get_placeholder_text_color (GtkEntry *entry,
5502 GtkWidget *widget = GTK_WIDGET (entry);
5503 GtkStyleContext *context;
5504 GdkRGBA fg = { 0.5, 0.5, 0.5 };
5506 context = gtk_widget_get_style_context (widget);
5507 gtk_style_context_lookup_color (context, "placeholder_text_color", &fg);
5509 color->red = CLAMP (fg.red * 65535. + 0.5, 0, 65535);
5510 color->green = CLAMP (fg.green * 65535. + 0.5, 0, 65535);
5511 color->blue = CLAMP (fg.blue * 65535. + 0.5, 0, 65535);
5514 static inline gboolean
5515 show_placeholder_text (GtkEntry *entry)
5517 GtkEntryPrivate *priv = entry->priv;
5519 if (!gtk_widget_has_focus (GTK_WIDGET (entry)) &&
5520 gtk_entry_buffer_get_bytes (get_buffer (entry)) == 0 &&
5521 priv->placeholder_text != NULL)
5527 static PangoLayout *
5528 gtk_entry_create_layout (GtkEntry *entry,
5529 gboolean include_preedit)
5531 GtkEntryPrivate *priv = entry->priv;
5532 GtkWidget *widget = GTK_WIDGET (entry);
5533 PangoLayout *layout = gtk_widget_create_pango_layout (widget, NULL);
5534 PangoAttrList *tmp_attrs = pango_attr_list_new ();
5535 gboolean placeholder_layout = show_placeholder_text (entry);
5537 gchar *preedit_string = NULL;
5538 gint preedit_length = 0;
5539 PangoAttrList *preedit_attrs = NULL;
5544 pango_layout_set_single_paragraph_mode (layout, TRUE);
5546 display = placeholder_layout ? g_strdup (priv->placeholder_text) : gtk_entry_get_display_text (entry, 0, -1);
5547 n_bytes = strlen (display);
5549 if (!placeholder_layout && include_preedit)
5551 gtk_im_context_get_preedit_string (priv->im_context,
5552 &preedit_string, &preedit_attrs, NULL);
5553 preedit_length = priv->preedit_length;
5555 else if (placeholder_layout)
5558 PangoAttribute *attr;
5560 gtk_entry_get_placeholder_text_color (entry, &color);
5561 attr = pango_attr_foreground_new (color.red, color.green, color.blue);
5562 attr->start_index = 0;
5563 attr->end_index = G_MAXINT;
5564 pango_attr_list_insert (tmp_attrs, attr);
5569 GString *tmp_string = g_string_new (display);
5570 gint cursor_index = g_utf8_offset_to_pointer (display, priv->current_pos) - display;
5572 g_string_insert (tmp_string, cursor_index, preedit_string);
5574 pango_layout_set_text (layout, tmp_string->str, tmp_string->len);
5576 pango_attr_list_splice (tmp_attrs, preedit_attrs,
5577 cursor_index, preedit_length);
5579 g_string_free (tmp_string, TRUE);
5583 PangoDirection pango_dir;
5585 if (gtk_entry_get_display_mode (entry) == DISPLAY_NORMAL)
5586 pango_dir = pango_find_base_dir (display, n_bytes);
5588 pango_dir = PANGO_DIRECTION_NEUTRAL;
5590 if (pango_dir == PANGO_DIRECTION_NEUTRAL)
5592 if (gtk_widget_has_focus (widget))
5594 GdkDisplay *display = gtk_widget_get_display (widget);
5595 GdkKeymap *keymap = gdk_keymap_get_for_display (display);
5596 if (gdk_keymap_get_direction (keymap) == PANGO_DIRECTION_RTL)
5597 pango_dir = PANGO_DIRECTION_RTL;
5599 pango_dir = PANGO_DIRECTION_LTR;
5603 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
5604 pango_dir = PANGO_DIRECTION_RTL;
5606 pango_dir = PANGO_DIRECTION_LTR;
5610 pango_context_set_base_dir (gtk_widget_get_pango_context (widget),
5613 priv->resolved_dir = pango_dir;
5615 pango_layout_set_text (layout, display, n_bytes);
5618 pango_layout_set_attributes (layout, tmp_attrs);
5620 g_free (preedit_string);
5624 pango_attr_list_unref (preedit_attrs);
5626 pango_attr_list_unref (tmp_attrs);
5631 static PangoLayout *
5632 gtk_entry_ensure_layout (GtkEntry *entry,
5633 gboolean include_preedit)
5635 GtkEntryPrivate *priv = entry->priv;
5637 if (priv->preedit_length > 0 &&
5638 !include_preedit != !priv->cache_includes_preedit)
5639 gtk_entry_reset_layout (entry);
5641 if (!priv->cached_layout)
5643 priv->cached_layout = gtk_entry_create_layout (entry, include_preedit);
5644 priv->cache_includes_preedit = include_preedit;
5647 return priv->cached_layout;
5651 get_layout_position (GtkEntry *entry,
5655 GtkEntryPrivate *priv = entry->priv;
5656 PangoLayout *layout;
5657 PangoRectangle logical_rect;
5658 gint area_width, area_height;
5660 PangoLayoutLine *line;
5662 layout = gtk_entry_ensure_layout (entry, TRUE);
5664 gtk_entry_get_text_area_size (entry, NULL, NULL, &area_width, &area_height);
5665 area_height = PANGO_SCALE * area_height;
5667 line = pango_layout_get_lines_readonly (layout)->data;
5668 pango_layout_line_get_extents (line, NULL, &logical_rect);
5670 /* Align primarily for locale's ascent/descent */
5671 y_pos = ((area_height - priv->ascent - priv->descent) / 2 +
5672 priv->ascent + logical_rect.y);
5674 /* Now see if we need to adjust to fit in actual drawn string */
5675 if (logical_rect.height > area_height)
5676 y_pos = (area_height - logical_rect.height) / 2;
5679 else if (y_pos + logical_rect.height > area_height)
5680 y_pos = area_height - logical_rect.height;
5682 y_pos = y_pos / PANGO_SCALE;
5685 *x = - priv->scroll_offset;
5692 draw_text_with_color (GtkEntry *entry,
5694 GdkRGBA *default_color)
5696 GtkEntryPrivate *priv = entry->priv;
5697 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
5700 gint start_pos, end_pos;
5702 widget = GTK_WIDGET (entry);
5706 get_layout_position (entry, &x, &y);
5708 cairo_move_to (cr, x, y);
5709 gdk_cairo_set_source_rgba (cr, default_color);
5710 pango_cairo_show_layout (cr, layout);
5712 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start_pos, &end_pos))
5716 PangoRectangle logical_rect;
5717 GdkRGBA selection_color, text_color;
5718 GtkStyleContext *context;
5719 GtkStateFlags state;
5721 context = gtk_widget_get_style_context (widget);
5722 pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
5723 gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
5725 state = gtk_widget_get_state_flags (widget);
5726 state |= GTK_STATE_FLAG_SELECTED;
5728 gtk_style_context_get_background_color (context, state, &selection_color);
5729 gtk_style_context_get_color (context, state, &text_color);
5731 for (i = 0; i < n_ranges; ++i)
5732 cairo_rectangle (cr,
5733 - priv->scroll_offset + ranges[2 * i],
5736 logical_rect.height);
5740 gdk_cairo_set_source_rgba (cr, &selection_color);
5743 cairo_move_to (cr, x, y);
5744 gdk_cairo_set_source_rgba (cr, &text_color);
5745 pango_cairo_show_layout (cr, layout);
5753 gtk_entry_draw_text (GtkEntry *entry,
5756 GtkEntryPrivate *priv = entry->priv;
5757 GtkWidget *widget = GTK_WIDGET (entry);
5758 GtkStateFlags state = 0;
5759 GdkRGBA text_color, bar_text_color;
5760 GtkStyleContext *context;
5762 gint progress_x, progress_y, progress_width, progress_height;
5763 gint clip_width, clip_height;
5765 /* Nothing to display at all */
5766 if (gtk_entry_get_display_mode (entry) == DISPLAY_BLANK)
5769 state = gtk_widget_get_state_flags (widget);
5770 context = gtk_widget_get_style_context (widget);
5772 gtk_style_context_get_color (context, state, &text_color);
5774 /* Get foreground color for progressbars */
5775 gtk_style_context_save (context);
5776 gtk_style_context_add_class (context, GTK_STYLE_CLASS_PROGRESSBAR);
5777 gtk_style_context_get_color (context, state, &bar_text_color);
5778 gtk_style_context_restore (context);
5780 get_progress_area (widget,
5781 &progress_x, &progress_y,
5782 &progress_width, &progress_height);
5786 clip_width = gdk_window_get_width (priv->text_area);
5787 clip_height = gdk_window_get_height (priv->text_area);
5788 cairo_rectangle (cr, 0, 0, clip_width, clip_height);
5791 /* If the color is the same, or the progress area has a zero
5792 * size, then we only need to draw once. */
5793 if (gdk_rgba_equal (&text_color, &bar_text_color) ||
5794 ((progress_width == 0) || (progress_height == 0)))
5796 draw_text_with_color (entry, cr, &text_color);
5800 int frame_x, frame_y, area_x, area_y;
5802 width = gdk_window_get_width (priv->text_area);
5803 height = gdk_window_get_height (priv->text_area);
5807 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
5808 cairo_rectangle (cr, 0, 0, width, height);
5810 /* progres area is frame-relative, we need it text-area window
5812 get_frame_size (entry, TRUE, &frame_x, &frame_y, NULL, NULL);
5813 gdk_window_get_position (priv->text_area, &area_x, &area_y);
5814 progress_x += frame_x - area_x;
5815 progress_y += frame_y - area_y;
5817 cairo_rectangle (cr, progress_x, progress_y,
5818 progress_width, progress_height);
5820 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_WINDING);
5822 draw_text_with_color (entry, cr, &text_color);
5827 cairo_rectangle (cr, progress_x, progress_y,
5828 progress_width, progress_height);
5831 draw_text_with_color (entry, cr, &bar_text_color);
5840 gtk_entry_draw_cursor (GtkEntry *entry,
5844 GtkEntryPrivate *priv = entry->priv;
5845 GtkWidget *widget = GTK_WIDGET (entry);
5846 GtkStyleContext *context;
5847 PangoRectangle cursor_rect;
5850 gboolean block_at_line_end;
5851 PangoLayout *layout;
5854 context = gtk_widget_get_style_context (widget);
5856 layout = gtk_entry_ensure_layout (entry, TRUE);
5857 text = pango_layout_get_text (layout);
5858 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos + priv->preedit_cursor) - text;
5860 if (!priv->overwrite_mode)
5863 block = _gtk_text_util_get_block_cursor_location (layout,
5864 cursor_index, &cursor_rect, &block_at_line_end);
5868 gtk_render_insertion_cursor (context, cr,
5869 - priv->scroll_offset, 0,
5870 layout, cursor_index, priv->resolved_dir);
5872 else /* overwrite_mode */
5874 GdkRGBA cursor_color;
5880 get_layout_position (entry, &x, &y);
5882 rect.x = PANGO_PIXELS (cursor_rect.x) + x;
5883 rect.y = PANGO_PIXELS (cursor_rect.y) + y;
5884 rect.width = PANGO_PIXELS (cursor_rect.width);
5885 rect.height = PANGO_PIXELS (cursor_rect.height);
5887 _gtk_style_context_get_cursor_color (context, &cursor_color, NULL);
5888 gdk_cairo_set_source_rgba (cr, &cursor_color);
5889 gdk_cairo_rectangle (cr, &rect);
5892 if (!block_at_line_end)
5894 GtkStateFlags state;
5897 state = gtk_widget_get_state_flags (widget);
5898 gtk_style_context_get_background_color (context, state, &color);
5900 gdk_cairo_rectangle (cr, &rect);
5902 cairo_move_to (cr, x, y);
5903 gdk_cairo_set_source_rgba (cr, &color);
5904 pango_cairo_show_layout (cr, layout);
5912 _gtk_entry_reset_im_context (GtkEntry *entry)
5914 GtkEntryPrivate *priv = entry->priv;
5916 if (priv->need_im_reset)
5918 priv->need_im_reset = FALSE;
5919 gtk_im_context_reset (priv->im_context);
5924 * gtk_entry_reset_im_context:
5925 * @entry: a #GtkEntry
5927 * Reset the input method context of the entry if needed.
5929 * This can be necessary in the case where modifying the buffer
5930 * would confuse on-going input method behavior.
5935 gtk_entry_reset_im_context (GtkEntry *entry)
5937 g_return_if_fail (GTK_IS_ENTRY (entry));
5939 _gtk_entry_reset_im_context (entry);
5943 * gtk_entry_im_context_filter_keypress:
5944 * @entry: a #GtkEntry
5945 * @event: (type Gdk.EventKey): the key event
5947 * Allow the #GtkEntry input method to internally handle key press
5948 * and release events. If this function returns %TRUE, then no further
5949 * processing should be done for this key event. See
5950 * gtk_im_context_filter_keypress().
5952 * Note that you are expected to call this function from your handler
5953 * when overriding key event handling. This is needed in the case when
5954 * you need to insert your own key handling between the input method
5955 * and the default key event handling of the #GtkEntry.
5956 * See gtk_text_view_reset_im_context() for an example of use.
5958 * Return value: %TRUE if the input method handled the key event.
5963 gtk_entry_im_context_filter_keypress (GtkEntry *entry,
5966 GtkEntryPrivate *priv;
5968 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
5972 return gtk_im_context_filter_keypress (priv->im_context, event);
5976 _gtk_entry_get_im_context (GtkEntry *entry)
5978 return entry->priv->im_context;
5982 gtk_entry_find_position (GtkEntry *entry,
5985 GtkEntryPrivate *priv = entry->priv;
5986 PangoLayout *layout;
5987 PangoLayoutLine *line;
5994 layout = gtk_entry_ensure_layout (entry, TRUE);
5995 text = pango_layout_get_text (layout);
5996 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos) - text;
5998 line = pango_layout_get_lines_readonly (layout)->data;
5999 pango_layout_line_x_to_index (line, x * PANGO_SCALE, &index, &trailing);
6001 if (index >= cursor_index && priv->preedit_length)
6003 if (index >= cursor_index + priv->preedit_length)
6004 index -= priv->preedit_length;
6007 index = cursor_index;
6012 pos = g_utf8_pointer_to_offset (text, text + index);
6019 gtk_entry_get_cursor_locations (GtkEntry *entry,
6024 GtkEntryPrivate *priv = entry->priv;
6025 DisplayMode mode = gtk_entry_get_display_mode (entry);
6027 /* Nothing to display at all, so no cursor is relevant */
6028 if (mode == DISPLAY_BLANK)
6038 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
6039 const gchar *text = pango_layout_get_text (layout);
6040 PangoRectangle strong_pos, weak_pos;
6043 if (type == CURSOR_STANDARD)
6045 index = g_utf8_offset_to_pointer (text, priv->current_pos + priv->preedit_cursor) - text;
6047 else /* type == CURSOR_DND */
6049 index = g_utf8_offset_to_pointer (text, priv->dnd_position) - text;
6051 if (priv->dnd_position > priv->current_pos)
6053 if (mode == DISPLAY_NORMAL)
6054 index += priv->preedit_length;
6057 gint preedit_len_chars = g_utf8_strlen (text, -1) - gtk_entry_buffer_get_length (get_buffer (entry));
6058 index += preedit_len_chars * g_unichar_to_utf8 (priv->invisible_char, NULL);
6063 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
6066 *strong_x = strong_pos.x / PANGO_SCALE;
6069 *weak_x = weak_pos.x / PANGO_SCALE;
6074 gtk_entry_adjust_scroll (GtkEntry *entry)
6076 GtkEntryPrivate *priv = entry->priv;
6077 gint min_offset, max_offset;
6078 gint text_area_width, text_width;
6080 gint strong_x, weak_x;
6081 gint strong_xoffset, weak_xoffset;
6083 PangoLayout *layout;
6084 PangoLayoutLine *line;
6085 PangoRectangle logical_rect;
6087 if (!gtk_widget_get_realized (GTK_WIDGET (entry)))
6090 text_area_width = gdk_window_get_width (priv->text_area);
6092 if (text_area_width < 0)
6093 text_area_width = 0;
6095 layout = gtk_entry_ensure_layout (entry, TRUE);
6096 line = pango_layout_get_lines_readonly (layout)->data;
6098 pango_layout_line_get_extents (line, NULL, &logical_rect);
6100 /* Display as much text as we can */
6102 if (priv->resolved_dir == PANGO_DIRECTION_LTR)
6103 xalign = priv->xalign;
6105 xalign = 1.0 - priv->xalign;
6107 text_width = PANGO_PIXELS(logical_rect.width);
6109 if (text_width > text_area_width)
6112 max_offset = text_width - text_area_width;
6116 min_offset = (text_width - text_area_width) * xalign;
6117 max_offset = min_offset;
6120 priv->scroll_offset = CLAMP (priv->scroll_offset, min_offset, max_offset);
6122 /* And make sure cursors are on screen. Note that the cursor is
6123 * actually drawn one pixel into the INNER_BORDER space on
6124 * the right, when the scroll is at the utmost right. This
6125 * looks better to to me than confining the cursor inside the
6126 * border entirely, though it means that the cursor gets one
6127 * pixel closer to the edge of the widget on the right than
6128 * on the left. This might need changing if one changed
6129 * INNER_BORDER from 2 to 1, as one would do on a
6130 * small-screen-real-estate display.
6132 * We always make sure that the strong cursor is on screen, and
6133 * put the weak cursor on screen if possible.
6136 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, &weak_x);
6138 strong_xoffset = strong_x - priv->scroll_offset;
6140 if (strong_xoffset < 0)
6142 priv->scroll_offset += strong_xoffset;
6145 else if (strong_xoffset > text_area_width)
6147 priv->scroll_offset += strong_xoffset - text_area_width;
6148 strong_xoffset = text_area_width;
6151 weak_xoffset = weak_x - priv->scroll_offset;
6153 if (weak_xoffset < 0 && strong_xoffset - weak_xoffset <= text_area_width)
6155 priv->scroll_offset += weak_xoffset;
6157 else if (weak_xoffset > text_area_width &&
6158 strong_xoffset - (weak_xoffset - text_area_width) >= 0)
6160 priv->scroll_offset += weak_xoffset - text_area_width;
6163 g_object_notify (G_OBJECT (entry), "scroll-offset");
6167 gtk_entry_move_adjustments (GtkEntry *entry)
6169 GtkWidget *widget = GTK_WIDGET (entry);
6170 GtkAllocation allocation;
6171 GtkAdjustment *adjustment;
6172 PangoContext *context;
6173 PangoFontMetrics *metrics;
6174 GtkStyleContext *style_context;
6175 GtkStateFlags state;
6180 adjustment = g_object_get_qdata (G_OBJECT (entry), quark_cursor_hadjustment);
6184 gtk_widget_get_allocation (widget, &allocation);
6186 /* Cursor position, layout offset, border width, and widget allocation */
6187 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &x, NULL);
6188 get_layout_position (entry, &layout_x, NULL);
6189 _gtk_entry_get_borders (entry, &borders);
6190 x += allocation.x + layout_x + borders.left;
6192 /* Approximate width of a char, so user can see what is ahead/behind */
6193 context = gtk_widget_get_pango_context (widget);
6194 style_context = gtk_widget_get_style_context (widget);
6195 state = gtk_widget_get_state_flags (widget);
6197 metrics = pango_context_get_metrics (context,
6198 gtk_style_context_get_font (style_context, state),
6199 pango_context_get_language (context));
6200 char_width = pango_font_metrics_get_approximate_char_width (metrics) / PANGO_SCALE;
6203 gtk_adjustment_clamp_page (adjustment,
6204 x - (char_width + 1), /* one char + one pixel before */
6205 x + (char_width + 2)); /* one char + cursor + one pixel after */
6209 gtk_entry_move_visually (GtkEntry *entry,
6213 GtkEntryPrivate *priv = entry->priv;
6215 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6218 text = pango_layout_get_text (layout);
6220 index = g_utf8_offset_to_pointer (text, start) - text;
6224 int new_index, new_trailing;
6225 gboolean split_cursor;
6228 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
6229 "gtk-split-cursor", &split_cursor,
6236 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
6237 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
6239 strong = keymap_direction == priv->resolved_dir;
6244 pango_layout_move_cursor_visually (layout, strong, index, 0, 1, &new_index, &new_trailing);
6249 pango_layout_move_cursor_visually (layout, strong, index, 0, -1, &new_index, &new_trailing);
6255 else if (new_index != G_MAXINT)
6258 while (new_trailing--)
6259 index = g_utf8_next_char (text + index) - text;
6262 return g_utf8_pointer_to_offset (text, text + index);
6266 gtk_entry_move_logically (GtkEntry *entry,
6270 gint new_pos = start;
6273 length = gtk_entry_buffer_get_length (get_buffer (entry));
6275 /* Prevent any leak of information */
6276 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6278 new_pos = CLAMP (start + count, 0, length);
6282 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6283 PangoLogAttr *log_attrs;
6286 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6288 while (count > 0 && new_pos < length)
6292 while (new_pos < length && !log_attrs[new_pos].is_cursor_position);
6296 while (count < 0 && new_pos > 0)
6300 while (new_pos > 0 && !log_attrs[new_pos].is_cursor_position);
6312 gtk_entry_move_forward_word (GtkEntry *entry,
6314 gboolean allow_whitespace)
6316 gint new_pos = start;
6319 length = gtk_entry_buffer_get_length (get_buffer (entry));
6321 /* Prevent any leak of information */
6322 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6326 else if (new_pos < length)
6328 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6329 PangoLogAttr *log_attrs;
6332 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6334 /* Find the next word boundary */
6336 while (new_pos < n_attrs - 1 && !(log_attrs[new_pos].is_word_end ||
6337 (log_attrs[new_pos].is_word_start && allow_whitespace)))
6348 gtk_entry_move_backward_word (GtkEntry *entry,
6350 gboolean allow_whitespace)
6352 gint new_pos = start;
6354 /* Prevent any leak of information */
6355 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6361 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6362 PangoLogAttr *log_attrs;
6365 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6367 new_pos = start - 1;
6369 /* Find the previous word boundary */
6370 while (new_pos > 0 && !(log_attrs[new_pos].is_word_start ||
6371 (log_attrs[new_pos].is_word_end && allow_whitespace)))
6381 gtk_entry_delete_whitespace (GtkEntry *entry)
6383 GtkEntryPrivate *priv = entry->priv;
6384 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6385 PangoLogAttr *log_attrs;
6389 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6391 start = end = priv->current_pos;
6393 while (start > 0 && log_attrs[start-1].is_white)
6396 while (end < n_attrs && log_attrs[end].is_white)
6402 gtk_editable_delete_text (GTK_EDITABLE (entry), start, end);
6407 gtk_entry_select_word (GtkEntry *entry)
6409 GtkEntryPrivate *priv = entry->priv;
6410 gint start_pos = gtk_entry_move_backward_word (entry, priv->current_pos, TRUE);
6411 gint end_pos = gtk_entry_move_forward_word (entry, priv->current_pos, TRUE);
6413 gtk_editable_select_region (GTK_EDITABLE (entry), start_pos, end_pos);
6417 gtk_entry_select_line (GtkEntry *entry)
6419 gtk_editable_select_region (GTK_EDITABLE (entry), 0, -1);
6423 truncate_multiline (const gchar *text)
6428 text[length] && text[length] != '\n' && text[length] != '\r';
6435 paste_received (GtkClipboard *clipboard,
6439 GtkEntry *entry = GTK_ENTRY (data);
6440 GtkEditable *editable = GTK_EDITABLE (entry);
6441 GtkEntryPrivate *priv = entry->priv;
6443 if (priv->button == GDK_BUTTON_MIDDLE)
6445 gint pos, start, end;
6446 pos = priv->insert_pos;
6447 gtk_editable_get_selection_bounds (editable, &start, &end);
6448 if (!((start <= pos && pos <= end) || (end <= pos && pos <= start)))
6449 gtk_editable_select_region (editable, pos, pos);
6454 gint pos, start, end;
6456 gboolean popup_completion;
6457 GtkEntryCompletion *completion;
6459 completion = gtk_entry_get_completion (entry);
6461 if (priv->truncate_multiline)
6462 length = truncate_multiline (text);
6464 /* only complete if the selection is at the end */
6465 popup_completion = (gtk_entry_buffer_get_length (get_buffer (entry)) ==
6466 MAX (priv->current_pos, priv->selection_bound));
6470 if (gtk_widget_get_mapped (completion->priv->popup_window))
6471 _gtk_entry_completion_popdown (completion);
6473 if (!popup_completion && completion->priv->changed_id > 0)
6474 g_signal_handler_block (entry, completion->priv->changed_id);
6477 begin_change (entry);
6478 if (gtk_editable_get_selection_bounds (editable, &start, &end))
6479 gtk_editable_delete_text (editable, start, end);
6481 pos = priv->current_pos;
6482 gtk_editable_insert_text (editable, text, length, &pos);
6483 gtk_editable_set_position (editable, pos);
6487 !popup_completion && completion->priv->changed_id > 0)
6488 g_signal_handler_unblock (entry, completion->priv->changed_id);
6491 g_object_unref (entry);
6495 gtk_entry_paste (GtkEntry *entry,
6498 g_object_ref (entry);
6499 gtk_clipboard_request_text (gtk_widget_get_clipboard (GTK_WIDGET (entry), selection),
6500 paste_received, entry);
6504 primary_get_cb (GtkClipboard *clipboard,
6505 GtkSelectionData *selection_data,
6509 GtkEntry *entry = GTK_ENTRY (data);
6512 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end))
6514 gchar *str = gtk_entry_get_display_text (entry, start, end);
6515 gtk_selection_data_set_text (selection_data, str, -1);
6521 primary_clear_cb (GtkClipboard *clipboard,
6524 GtkEntry *entry = GTK_ENTRY (data);
6525 GtkEntryPrivate *priv = entry->priv;
6527 gtk_editable_select_region (GTK_EDITABLE (entry), priv->current_pos, priv->current_pos);
6531 gtk_entry_update_primary_selection (GtkEntry *entry)
6533 GtkTargetList *list;
6534 GtkTargetEntry *targets;
6535 GtkClipboard *clipboard;
6539 if (!gtk_widget_get_realized (GTK_WIDGET (entry)))
6542 list = gtk_target_list_new (NULL, 0);
6543 gtk_target_list_add_text_targets (list, 0);
6545 targets = gtk_target_table_new_from_list (list, &n_targets);
6547 clipboard = gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_PRIMARY);
6549 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end))
6551 if (!gtk_clipboard_set_with_owner (clipboard, targets, n_targets,
6552 primary_get_cb, primary_clear_cb, G_OBJECT (entry)))
6553 primary_clear_cb (clipboard, entry);
6557 if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (entry))
6558 gtk_clipboard_clear (clipboard);
6561 gtk_target_table_free (targets, n_targets);
6562 gtk_target_list_unref (list);
6566 gtk_entry_clear (GtkEntry *entry,
6567 GtkEntryIconPosition icon_pos)
6569 GtkEntryPrivate *priv = entry->priv;
6570 EntryIconInfo *icon_info = priv->icons[icon_pos];
6571 GtkImageType storage_type;
6573 if (icon_info && _gtk_icon_helper_get_is_empty (icon_info->icon_helper))
6576 g_object_freeze_notify (G_OBJECT (entry));
6578 /* Explicitly check, as the pointer may become invalidated
6579 * during destruction.
6581 if (GDK_IS_WINDOW (icon_info->window))
6582 gdk_window_hide (icon_info->window);
6584 storage_type = _gtk_icon_helper_get_storage_type (icon_info->icon_helper);
6586 switch (storage_type)
6588 case GTK_IMAGE_PIXBUF:
6589 g_object_notify (G_OBJECT (entry),
6590 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-pixbuf" : "secondary-icon-pixbuf");
6593 case GTK_IMAGE_STOCK:
6594 g_object_notify (G_OBJECT (entry),
6595 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-stock" : "secondary-icon-stock");
6598 case GTK_IMAGE_ICON_NAME:
6599 g_object_notify (G_OBJECT (entry),
6600 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-name" : "secondary-icon-name");
6603 case GTK_IMAGE_GICON:
6604 g_object_notify (G_OBJECT (entry),
6605 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-gicon" : "secondary-icon-gicon");
6609 g_assert_not_reached ();
6613 _gtk_icon_helper_clear (icon_info->icon_helper);
6615 g_object_notify (G_OBJECT (entry),
6616 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-storage-type" : "secondary-icon-storage-type");
6618 g_object_thaw_notify (G_OBJECT (entry));
6622 gtk_entry_ensure_pixbuf (GtkEntry *entry,
6623 GtkEntryIconPosition icon_pos)
6625 GtkEntryPrivate *priv = entry->priv;
6626 EntryIconInfo *icon_info = priv->icons[icon_pos];
6627 GtkStyleContext *context;
6630 context = gtk_widget_get_style_context (GTK_WIDGET (entry));
6631 gtk_entry_prepare_context_for_icon (entry, context, icon_pos);
6633 pix = _gtk_icon_helper_ensure_pixbuf (icon_info->icon_helper,
6636 gtk_style_context_restore (context);
6647 * Creates a new entry.
6649 * Return value: a new #GtkEntry.
6652 gtk_entry_new (void)
6654 return g_object_new (GTK_TYPE_ENTRY, NULL);
6658 * gtk_entry_new_with_buffer:
6659 * @buffer: The buffer to use for the new #GtkEntry.
6661 * Creates a new entry with the specified text buffer.
6663 * Return value: a new #GtkEntry
6668 gtk_entry_new_with_buffer (GtkEntryBuffer *buffer)
6670 g_return_val_if_fail (GTK_IS_ENTRY_BUFFER (buffer), NULL);
6671 return g_object_new (GTK_TYPE_ENTRY, "buffer", buffer, NULL);
6674 static GtkEntryBuffer*
6675 get_buffer (GtkEntry *entry)
6677 GtkEntryPrivate *priv = entry->priv;
6679 if (priv->buffer == NULL)
6681 GtkEntryBuffer *buffer;
6682 buffer = gtk_entry_buffer_new (NULL, 0);
6683 gtk_entry_set_buffer (entry, buffer);
6684 g_object_unref (buffer);
6687 return priv->buffer;
6691 * gtk_entry_get_buffer:
6692 * @entry: a #GtkEntry
6694 * Get the #GtkEntryBuffer object which holds the text for
6699 * Returns: (transfer none): A #GtkEntryBuffer object.
6702 gtk_entry_get_buffer (GtkEntry *entry)
6704 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
6706 return get_buffer (entry);
6710 * gtk_entry_set_buffer:
6711 * @entry: a #GtkEntry
6712 * @buffer: a #GtkEntryBuffer
6714 * Set the #GtkEntryBuffer object which holds the text for
6720 gtk_entry_set_buffer (GtkEntry *entry,
6721 GtkEntryBuffer *buffer)
6723 GtkEntryPrivate *priv;
6726 g_return_if_fail (GTK_IS_ENTRY (entry));
6732 g_return_if_fail (GTK_IS_ENTRY_BUFFER (buffer));
6733 g_object_ref (buffer);
6738 buffer_disconnect_signals (entry);
6739 g_object_unref (priv->buffer);
6742 priv->buffer = buffer;
6745 buffer_connect_signals (entry);
6747 obj = G_OBJECT (entry);
6748 g_object_freeze_notify (obj);
6749 g_object_notify (obj, "buffer");
6750 g_object_notify (obj, "text");
6751 g_object_notify (obj, "text-length");
6752 g_object_notify (obj, "max-length");
6753 g_object_notify (obj, "visibility");
6754 g_object_notify (obj, "invisible-char");
6755 g_object_notify (obj, "invisible-char-set");
6756 g_object_thaw_notify (obj);
6758 gtk_editable_set_position (GTK_EDITABLE (entry), 0);
6759 gtk_entry_recompute (entry);
6763 * gtk_entry_get_text_area:
6764 * @entry: a #GtkEntry
6765 * @text_area: (out): Return location for the text area.
6767 * Gets the area where the entry's text is drawn. This function is
6768 * useful when drawing something to the entry in a draw callback.
6770 * If the entry is not realized, @text_area is filled with zeros.
6772 * See also gtk_entry_get_icon_area().
6777 gtk_entry_get_text_area (GtkEntry *entry,
6778 GdkRectangle *text_area)
6780 GtkEntryPrivate *priv;
6782 g_return_if_fail (GTK_IS_ENTRY (entry));
6783 g_return_if_fail (text_area != NULL);
6787 if (priv->text_area)
6789 GtkAllocation allocation;
6792 gtk_widget_get_allocation (GTK_WIDGET (entry), &allocation);
6793 gdk_window_get_position (priv->text_area, &x, &y);
6795 text_area->x = x - allocation.x;
6796 text_area->y = y - allocation.y;
6797 text_area->width = gdk_window_get_width (priv->text_area);
6798 text_area->height = gdk_window_get_height (priv->text_area);
6804 text_area->width = 0;
6805 text_area->height = 0;
6810 * gtk_entry_set_text:
6811 * @entry: a #GtkEntry
6812 * @text: the new text
6814 * Sets the text in the widget to the given
6815 * value, replacing the current contents.
6817 * See gtk_entry_buffer_set_text().
6820 gtk_entry_set_text (GtkEntry *entry,
6824 GtkEntryCompletion *completion;
6826 g_return_if_fail (GTK_IS_ENTRY (entry));
6827 g_return_if_fail (text != NULL);
6829 /* Actually setting the text will affect the cursor and selection;
6830 * if the contents don't actually change, this will look odd to the user.
6832 if (strcmp (gtk_entry_buffer_get_text (get_buffer (entry)), text) == 0)
6835 completion = gtk_entry_get_completion (entry);
6836 if (completion && completion->priv->changed_id > 0)
6837 g_signal_handler_block (entry, completion->priv->changed_id);
6839 begin_change (entry);
6840 gtk_editable_delete_text (GTK_EDITABLE (entry), 0, -1);
6842 gtk_editable_insert_text (GTK_EDITABLE (entry), text, strlen (text), &tmp_pos);
6845 if (completion && completion->priv->changed_id > 0)
6846 g_signal_handler_unblock (entry, completion->priv->changed_id);
6850 * gtk_entry_set_visibility:
6851 * @entry: a #GtkEntry
6852 * @visible: %TRUE if the contents of the entry are displayed
6855 * Sets whether the contents of the entry are visible or not.
6856 * When visibility is set to %FALSE, characters are displayed
6857 * as the invisible char, and will also appear that way when
6858 * the text in the entry widget is copied elsewhere.
6860 * By default, GTK+ picks the best invisible character available
6861 * in the current font, but it can be changed with
6862 * gtk_entry_set_invisible_char().
6865 gtk_entry_set_visibility (GtkEntry *entry,
6868 GtkEntryPrivate *priv;
6870 g_return_if_fail (GTK_IS_ENTRY (entry));
6874 visible = visible != FALSE;
6876 if (priv->visible != visible)
6878 priv->visible = visible;
6880 g_object_notify (G_OBJECT (entry), "visibility");
6881 gtk_entry_recompute (entry);
6886 * gtk_entry_get_visibility:
6887 * @entry: a #GtkEntry
6889 * Retrieves whether the text in @entry is visible. See
6890 * gtk_entry_set_visibility().
6892 * Return value: %TRUE if the text is currently visible
6895 gtk_entry_get_visibility (GtkEntry *entry)
6897 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
6899 return entry->priv->visible;
6903 * gtk_entry_set_invisible_char:
6904 * @entry: a #GtkEntry
6905 * @ch: a Unicode character
6907 * Sets the character to use in place of the actual text when
6908 * gtk_entry_set_visibility() has been called to set text visibility
6909 * to %FALSE. i.e. this is the character used in "password mode" to
6910 * show the user how many characters have been typed. By default, GTK+
6911 * picks the best invisible char available in the current font. If you
6912 * set the invisible char to 0, then the user will get no feedback
6913 * at all; there will be no text on the screen as they type.
6916 gtk_entry_set_invisible_char (GtkEntry *entry,
6919 GtkEntryPrivate *priv;
6921 g_return_if_fail (GTK_IS_ENTRY (entry));
6925 if (!priv->invisible_char_set)
6927 priv->invisible_char_set = TRUE;
6928 g_object_notify (G_OBJECT (entry), "invisible-char-set");
6931 if (ch == priv->invisible_char)
6934 priv->invisible_char = ch;
6935 g_object_notify (G_OBJECT (entry), "invisible-char");
6936 gtk_entry_recompute (entry);
6940 * gtk_entry_get_invisible_char:
6941 * @entry: a #GtkEntry
6943 * Retrieves the character displayed in place of the real characters
6944 * for entries with visibility set to false. See gtk_entry_set_invisible_char().
6946 * Return value: the current invisible char, or 0, if the entry does not
6947 * show invisible text at all.
6950 gtk_entry_get_invisible_char (GtkEntry *entry)
6952 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
6954 return entry->priv->invisible_char;
6958 * gtk_entry_unset_invisible_char:
6959 * @entry: a #GtkEntry
6961 * Unsets the invisible char previously set with
6962 * gtk_entry_set_invisible_char(). So that the
6963 * default invisible char is used again.
6968 gtk_entry_unset_invisible_char (GtkEntry *entry)
6970 GtkEntryPrivate *priv;
6973 g_return_if_fail (GTK_IS_ENTRY (entry));
6977 if (!priv->invisible_char_set)
6980 priv->invisible_char_set = FALSE;
6981 ch = find_invisible_char (GTK_WIDGET (entry));
6983 if (priv->invisible_char != ch)
6985 priv->invisible_char = ch;
6986 g_object_notify (G_OBJECT (entry), "invisible-char");
6989 g_object_notify (G_OBJECT (entry), "invisible-char-set");
6990 gtk_entry_recompute (entry);
6994 * gtk_entry_set_overwrite_mode:
6995 * @entry: a #GtkEntry
6996 * @overwrite: new value
6998 * Sets whether the text is overwritten when typing in the #GtkEntry.
7003 gtk_entry_set_overwrite_mode (GtkEntry *entry,
7006 GtkEntryPrivate *priv = entry->priv;
7008 g_return_if_fail (GTK_IS_ENTRY (entry));
7010 if (priv->overwrite_mode == overwrite)
7013 gtk_entry_toggle_overwrite (entry);
7015 g_object_notify (G_OBJECT (entry), "overwrite-mode");
7019 * gtk_entry_get_overwrite_mode:
7020 * @entry: a #GtkEntry
7022 * Gets the value set by gtk_entry_set_overwrite_mode().
7024 * Return value: whether the text is overwritten when typing.
7029 gtk_entry_get_overwrite_mode (GtkEntry *entry)
7031 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7033 return entry->priv->overwrite_mode;
7037 * gtk_entry_get_text:
7038 * @entry: a #GtkEntry
7040 * Retrieves the contents of the entry widget.
7041 * See also gtk_editable_get_chars().
7043 * This is equivalent to:
7045 * <informalexample><programlisting>
7046 * gtk_entry_buffer_get_text (gtk_entry_get_buffer (entry));
7047 * </programlisting></informalexample>
7049 * Return value: a pointer to the contents of the widget as a
7050 * string. This string points to internally allocated
7051 * storage in the widget and must not be freed, modified or
7055 gtk_entry_get_text (GtkEntry *entry)
7057 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7059 return gtk_entry_buffer_get_text (get_buffer (entry));
7063 * gtk_entry_set_max_length:
7064 * @entry: a #GtkEntry
7065 * @max: the maximum length of the entry, or 0 for no maximum.
7066 * (other than the maximum length of entries.) The value passed in will
7067 * be clamped to the range 0-65536.
7069 * Sets the maximum allowed length of the contents of the widget. If
7070 * the current contents are longer than the given length, then they
7071 * will be truncated to fit.
7073 * This is equivalent to:
7075 * <informalexample><programlisting>
7076 * gtk_entry_buffer_set_max_length (gtk_entry_get_buffer (entry), max);
7077 * </programlisting></informalexample>
7080 gtk_entry_set_max_length (GtkEntry *entry,
7083 g_return_if_fail (GTK_IS_ENTRY (entry));
7084 gtk_entry_buffer_set_max_length (get_buffer (entry), max);
7088 * gtk_entry_get_max_length:
7089 * @entry: a #GtkEntry
7091 * Retrieves the maximum allowed length of the text in
7092 * @entry. See gtk_entry_set_max_length().
7094 * This is equivalent to:
7096 * <informalexample><programlisting>
7097 * gtk_entry_buffer_get_max_length (gtk_entry_get_buffer (entry));
7098 * </programlisting></informalexample>
7100 * Return value: the maximum allowed number of characters
7101 * in #GtkEntry, or 0 if there is no maximum.
7104 gtk_entry_get_max_length (GtkEntry *entry)
7106 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7108 return gtk_entry_buffer_get_max_length (get_buffer (entry));
7112 * gtk_entry_get_text_length:
7113 * @entry: a #GtkEntry
7115 * Retrieves the current length of the text in
7118 * This is equivalent to:
7120 * <informalexample><programlisting>
7121 * gtk_entry_buffer_get_length (gtk_entry_get_buffer (entry));
7122 * </programlisting></informalexample>
7124 * Return value: the current number of characters
7125 * in #GtkEntry, or 0 if there are none.
7130 gtk_entry_get_text_length (GtkEntry *entry)
7132 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7134 return gtk_entry_buffer_get_length (get_buffer (entry));
7138 * gtk_entry_set_activates_default:
7139 * @entry: a #GtkEntry
7140 * @setting: %TRUE to activate window's default widget on Enter keypress
7142 * If @setting is %TRUE, pressing Enter in the @entry will activate the default
7143 * widget for the window containing the entry. This usually means that
7144 * the dialog box containing the entry will be closed, since the default
7145 * widget is usually one of the dialog buttons.
7147 * (For experts: if @setting is %TRUE, the entry calls
7148 * gtk_window_activate_default() on the window containing the entry, in
7149 * the default handler for the #GtkWidget::activate signal.)
7152 gtk_entry_set_activates_default (GtkEntry *entry,
7155 GtkEntryPrivate *priv;
7157 g_return_if_fail (GTK_IS_ENTRY (entry));
7161 setting = setting != FALSE;
7163 if (setting != priv->activates_default)
7165 priv->activates_default = setting;
7166 g_object_notify (G_OBJECT (entry), "activates-default");
7171 * gtk_entry_get_activates_default:
7172 * @entry: a #GtkEntry
7174 * Retrieves the value set by gtk_entry_set_activates_default().
7176 * Return value: %TRUE if the entry will activate the default widget
7179 gtk_entry_get_activates_default (GtkEntry *entry)
7181 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7183 return entry->priv->activates_default;
7187 * gtk_entry_set_width_chars:
7188 * @entry: a #GtkEntry
7189 * @n_chars: width in chars
7191 * Changes the size request of the entry to be about the right size
7192 * for @n_chars characters. Note that it changes the size
7193 * <emphasis>request</emphasis>, the size can still be affected by
7194 * how you pack the widget into containers. If @n_chars is -1, the
7195 * size reverts to the default entry size.
7198 gtk_entry_set_width_chars (GtkEntry *entry,
7201 GtkEntryPrivate *priv;
7203 g_return_if_fail (GTK_IS_ENTRY (entry));
7207 if (priv->width_chars != n_chars)
7209 priv->width_chars = n_chars;
7210 g_object_notify (G_OBJECT (entry), "width-chars");
7211 gtk_widget_queue_resize (GTK_WIDGET (entry));
7216 * gtk_entry_get_width_chars:
7217 * @entry: a #GtkEntry
7219 * Gets the value set by gtk_entry_set_width_chars().
7221 * Return value: number of chars to request space for, or negative if unset
7224 gtk_entry_get_width_chars (GtkEntry *entry)
7226 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7228 return entry->priv->width_chars;
7232 * gtk_entry_set_has_frame:
7233 * @entry: a #GtkEntry
7234 * @setting: new value
7236 * Sets whether the entry has a beveled frame around it.
7239 gtk_entry_set_has_frame (GtkEntry *entry,
7242 GtkEntryPrivate *priv;
7244 g_return_if_fail (GTK_IS_ENTRY (entry));
7248 setting = (setting != FALSE);
7250 if (priv->has_frame == setting)
7253 gtk_widget_queue_resize (GTK_WIDGET (entry));
7254 priv->has_frame = setting;
7255 g_object_notify (G_OBJECT (entry), "has-frame");
7259 * gtk_entry_get_has_frame:
7260 * @entry: a #GtkEntry
7262 * Gets the value set by gtk_entry_set_has_frame().
7264 * Return value: whether the entry has a beveled frame
7267 gtk_entry_get_has_frame (GtkEntry *entry)
7269 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7271 return entry->priv->has_frame;
7275 * gtk_entry_set_inner_border:
7276 * @entry: a #GtkEntry
7277 * @border: (allow-none): a #GtkBorder, or %NULL
7279 * Sets %entry's inner-border property to %border, or clears it if %NULL
7280 * is passed. The inner-border is the area around the entry's text, but
7283 * If set, this property overrides the inner-border style property.
7284 * Overriding the style-provided border is useful when you want to do
7285 * in-place editing of some text in a canvas or list widget, where
7286 * pixel-exact positioning of the entry is important.
7290 * Deprecated: 3.4: Use the standard border and padding CSS properties;
7291 * the value set with this function is ignored by #GtkEntry.
7294 gtk_entry_set_inner_border (GtkEntry *entry,
7295 const GtkBorder *border)
7297 g_return_if_fail (GTK_IS_ENTRY (entry));
7299 gtk_entry_do_set_inner_border (entry, border);
7303 * gtk_entry_get_inner_border:
7304 * @entry: a #GtkEntry
7306 * This function returns the entry's #GtkEntry:inner-border property. See
7307 * gtk_entry_set_inner_border() for more information.
7309 * Return value: (transfer none): the entry's #GtkBorder, or %NULL if none was set.
7313 * Deprecated: 3.4: Use the standard border and padding CSS properties;
7314 * the value returned by this function is ignored by #GtkEntry.
7317 gtk_entry_get_inner_border (GtkEntry *entry)
7319 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7321 return gtk_entry_do_get_inner_border (entry);
7325 * gtk_entry_get_layout:
7326 * @entry: a #GtkEntry
7328 * Gets the #PangoLayout used to display the entry.
7329 * The layout is useful to e.g. convert text positions to
7330 * pixel positions, in combination with gtk_entry_get_layout_offsets().
7331 * The returned layout is owned by the entry and must not be
7332 * modified or freed by the caller.
7334 * Keep in mind that the layout text may contain a preedit string, so
7335 * gtk_entry_layout_index_to_text_index() and
7336 * gtk_entry_text_index_to_layout_index() are needed to convert byte
7337 * indices in the layout to byte indices in the entry contents.
7339 * Return value: (transfer none): the #PangoLayout for this entry
7342 gtk_entry_get_layout (GtkEntry *entry)
7344 PangoLayout *layout;
7346 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7348 layout = gtk_entry_ensure_layout (entry, TRUE);
7355 * gtk_entry_layout_index_to_text_index:
7356 * @entry: a #GtkEntry
7357 * @layout_index: byte index into the entry layout text
7359 * Converts from a position in the entry contents (returned
7360 * by gtk_entry_get_text()) to a position in the
7361 * entry's #PangoLayout (returned by gtk_entry_get_layout(),
7362 * with text retrieved via pango_layout_get_text()).
7364 * Return value: byte index into the entry contents
7367 gtk_entry_layout_index_to_text_index (GtkEntry *entry,
7370 GtkEntryPrivate *priv;
7371 PangoLayout *layout;
7375 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7379 layout = gtk_entry_ensure_layout (entry, TRUE);
7380 text = pango_layout_get_text (layout);
7381 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos) - text;
7383 if (layout_index >= cursor_index && priv->preedit_length)
7385 if (layout_index >= cursor_index + priv->preedit_length)
7386 layout_index -= priv->preedit_length;
7388 layout_index = cursor_index;
7391 return layout_index;
7395 * gtk_entry_text_index_to_layout_index:
7396 * @entry: a #GtkEntry
7397 * @text_index: byte index into the entry contents
7399 * Converts from a position in the entry's #PangoLayout (returned by
7400 * gtk_entry_get_layout()) to a position in the entry contents
7401 * (returned by gtk_entry_get_text()).
7403 * Return value: byte index into the entry layout text
7406 gtk_entry_text_index_to_layout_index (GtkEntry *entry,
7409 GtkEntryPrivate *priv;
7410 PangoLayout *layout;
7414 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7418 layout = gtk_entry_ensure_layout (entry, TRUE);
7419 text = pango_layout_get_text (layout);
7420 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos) - text;
7422 if (text_index > cursor_index)
7423 text_index += priv->preedit_length;
7429 * gtk_entry_get_layout_offsets:
7430 * @entry: a #GtkEntry
7431 * @x: (out) (allow-none): location to store X offset of layout, or %NULL
7432 * @y: (out) (allow-none): location to store Y offset of layout, or %NULL
7435 * Obtains the position of the #PangoLayout used to render text
7436 * in the entry, in widget coordinates. Useful if you want to line
7437 * up the text in an entry with some other text, e.g. when using the
7438 * entry to implement editable cells in a sheet widget.
7440 * Also useful to convert mouse events into coordinates inside the
7441 * #PangoLayout, e.g. to take some action if some part of the entry text
7444 * Note that as the user scrolls around in the entry the offsets will
7445 * change; you'll need to connect to the "notify::scroll-offset"
7446 * signal to track this. Remember when using the #PangoLayout
7447 * functions you need to convert to and from pixels using
7448 * PANGO_PIXELS() or #PANGO_SCALE.
7450 * Keep in mind that the layout text may contain a preedit string, so
7451 * gtk_entry_layout_index_to_text_index() and
7452 * gtk_entry_text_index_to_layout_index() are needed to convert byte
7453 * indices in the layout to byte indices in the entry contents.
7456 gtk_entry_get_layout_offsets (GtkEntry *entry,
7460 gint text_area_x, text_area_y;
7462 g_return_if_fail (GTK_IS_ENTRY (entry));
7464 /* this gets coords relative to text area */
7465 get_layout_position (entry, x, y);
7467 /* convert to widget coords */
7468 gtk_entry_get_text_area_size (entry, &text_area_x, &text_area_y, NULL, NULL);
7479 * gtk_entry_set_alignment:
7480 * @entry: a #GtkEntry
7481 * @xalign: The horizontal alignment, from 0 (left) to 1 (right).
7482 * Reversed for RTL layouts
7484 * Sets the alignment for the contents of the entry. This controls
7485 * the horizontal positioning of the contents when the displayed
7486 * text is shorter than the width of the entry.
7491 gtk_entry_set_alignment (GtkEntry *entry, gfloat xalign)
7493 GtkEntryPrivate *priv;
7495 g_return_if_fail (GTK_IS_ENTRY (entry));
7501 else if (xalign > 1.0)
7504 if (xalign != priv->xalign)
7506 priv->xalign = xalign;
7508 gtk_entry_recompute (entry);
7510 g_object_notify (G_OBJECT (entry), "xalign");
7515 * gtk_entry_get_alignment:
7516 * @entry: a #GtkEntry
7518 * Gets the value set by gtk_entry_set_alignment().
7520 * Return value: the alignment
7525 gtk_entry_get_alignment (GtkEntry *entry)
7527 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
7529 return entry->priv->xalign;
7533 * gtk_entry_set_icon_from_pixbuf:
7534 * @entry: a #GtkEntry
7535 * @icon_pos: Icon position
7536 * @pixbuf: (allow-none): A #GdkPixbuf, or %NULL
7538 * Sets the icon shown in the specified position using a pixbuf.
7540 * If @pixbuf is %NULL, no icon will be shown in the specified position.
7545 gtk_entry_set_icon_from_pixbuf (GtkEntry *entry,
7546 GtkEntryIconPosition icon_pos,
7549 GtkEntryPrivate *priv;
7550 EntryIconInfo *icon_info;
7552 g_return_if_fail (GTK_IS_ENTRY (entry));
7553 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7557 if ((icon_info = priv->icons[icon_pos]) == NULL)
7558 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7560 g_object_freeze_notify (G_OBJECT (entry));
7563 g_object_ref (pixbuf);
7565 gtk_entry_clear (entry, icon_pos);
7569 _gtk_icon_helper_set_pixbuf (icon_info->icon_helper, pixbuf);
7571 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7573 g_object_notify (G_OBJECT (entry), "primary-icon-pixbuf");
7574 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7578 g_object_notify (G_OBJECT (entry), "secondary-icon-pixbuf");
7579 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7582 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7583 gdk_window_show_unraised (icon_info->window);
7585 g_object_unref (pixbuf);
7588 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7589 gtk_widget_queue_resize (GTK_WIDGET (entry));
7591 g_object_thaw_notify (G_OBJECT (entry));
7595 * gtk_entry_set_icon_from_stock:
7596 * @entry: A #GtkEntry
7597 * @icon_pos: Icon position
7598 * @stock_id: (allow-none): The name of the stock item, or %NULL
7600 * Sets the icon shown in the entry at the specified position from
7603 * If @stock_id is %NULL, no icon will be shown in the specified position.
7608 gtk_entry_set_icon_from_stock (GtkEntry *entry,
7609 GtkEntryIconPosition icon_pos,
7610 const gchar *stock_id)
7612 GtkEntryPrivate *priv;
7613 EntryIconInfo *icon_info;
7616 g_return_if_fail (GTK_IS_ENTRY (entry));
7617 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7621 if ((icon_info = priv->icons[icon_pos]) == NULL)
7622 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7624 g_object_freeze_notify (G_OBJECT (entry));
7626 /* need to dup before clearing */
7627 new_id = g_strdup (stock_id);
7629 gtk_entry_clear (entry, icon_pos);
7633 _gtk_icon_helper_set_stock_id (icon_info->icon_helper, new_id, GTK_ICON_SIZE_MENU);
7635 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7637 g_object_notify (G_OBJECT (entry), "primary-icon-stock");
7638 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7642 g_object_notify (G_OBJECT (entry), "secondary-icon-stock");
7643 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7646 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7647 gdk_window_show_unraised (icon_info->window);
7652 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7653 gtk_widget_queue_resize (GTK_WIDGET (entry));
7655 g_object_thaw_notify (G_OBJECT (entry));
7659 * gtk_entry_set_icon_from_icon_name:
7660 * @entry: A #GtkEntry
7661 * @icon_pos: The position at which to set the icon
7662 * @icon_name: (allow-none): An icon name, or %NULL
7664 * Sets the icon shown in the entry at the specified position
7665 * from the current icon theme.
7667 * If the icon name isn't known, a "broken image" icon will be displayed
7670 * If @icon_name is %NULL, no icon will be shown in the specified position.
7675 gtk_entry_set_icon_from_icon_name (GtkEntry *entry,
7676 GtkEntryIconPosition icon_pos,
7677 const gchar *icon_name)
7679 GtkEntryPrivate *priv;
7680 EntryIconInfo *icon_info;
7683 g_return_if_fail (GTK_IS_ENTRY (entry));
7684 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7688 if ((icon_info = priv->icons[icon_pos]) == NULL)
7689 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7691 g_object_freeze_notify (G_OBJECT (entry));
7693 /* need to dup before clearing */
7694 new_name = g_strdup (icon_name);
7696 gtk_entry_clear (entry, icon_pos);
7698 if (new_name != NULL)
7700 _gtk_icon_helper_set_icon_name (icon_info->icon_helper, new_name, GTK_ICON_SIZE_MENU);
7702 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7704 g_object_notify (G_OBJECT (entry), "primary-icon-name");
7705 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7709 g_object_notify (G_OBJECT (entry), "secondary-icon-name");
7710 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7713 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7714 gdk_window_show_unraised (icon_info->window);
7719 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7720 gtk_widget_queue_resize (GTK_WIDGET (entry));
7722 g_object_thaw_notify (G_OBJECT (entry));
7726 * gtk_entry_set_icon_from_gicon:
7727 * @entry: A #GtkEntry
7728 * @icon_pos: The position at which to set the icon
7729 * @icon: (allow-none): The icon to set, or %NULL
7731 * Sets the icon shown in the entry at the specified position
7732 * from the current icon theme.
7733 * If the icon isn't known, a "broken image" icon will be displayed
7736 * If @icon is %NULL, no icon will be shown in the specified position.
7741 gtk_entry_set_icon_from_gicon (GtkEntry *entry,
7742 GtkEntryIconPosition icon_pos,
7745 GtkEntryPrivate *priv;
7746 EntryIconInfo *icon_info;
7748 g_return_if_fail (GTK_IS_ENTRY (entry));
7749 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7753 if ((icon_info = priv->icons[icon_pos]) == NULL)
7754 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7756 g_object_freeze_notify (G_OBJECT (entry));
7758 /* need to ref before clearing */
7760 g_object_ref (icon);
7762 gtk_entry_clear (entry, icon_pos);
7766 _gtk_icon_helper_set_gicon (icon_info->icon_helper, icon, GTK_ICON_SIZE_MENU);
7768 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7770 g_object_notify (G_OBJECT (entry), "primary-icon-gicon");
7771 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7775 g_object_notify (G_OBJECT (entry), "secondary-icon-gicon");
7776 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7779 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7780 gdk_window_show_unraised (icon_info->window);
7782 g_object_unref (icon);
7785 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7786 gtk_widget_queue_resize (GTK_WIDGET (entry));
7788 g_object_thaw_notify (G_OBJECT (entry));
7792 * gtk_entry_set_icon_activatable:
7793 * @entry: A #GtkEntry
7794 * @icon_pos: Icon position
7795 * @activatable: %TRUE if the icon should be activatable
7797 * Sets whether the icon is activatable.
7802 gtk_entry_set_icon_activatable (GtkEntry *entry,
7803 GtkEntryIconPosition icon_pos,
7804 gboolean activatable)
7806 GtkEntryPrivate *priv;
7807 EntryIconInfo *icon_info;
7809 g_return_if_fail (GTK_IS_ENTRY (entry));
7810 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7814 if ((icon_info = priv->icons[icon_pos]) == NULL)
7815 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7817 activatable = activatable != FALSE;
7819 if (icon_info->nonactivatable != !activatable)
7821 icon_info->nonactivatable = !activatable;
7823 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
7824 update_cursors (GTK_WIDGET (entry));
7826 g_object_notify (G_OBJECT (entry),
7827 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-activatable" : "secondary-icon-activatable");
7832 * gtk_entry_get_icon_activatable:
7833 * @entry: a #GtkEntry
7834 * @icon_pos: Icon position
7836 * Returns whether the icon is activatable.
7838 * Returns: %TRUE if the icon is activatable.
7843 gtk_entry_get_icon_activatable (GtkEntry *entry,
7844 GtkEntryIconPosition icon_pos)
7846 GtkEntryPrivate *priv;
7847 EntryIconInfo *icon_info;
7849 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7850 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), FALSE);
7853 icon_info = priv->icons[icon_pos];
7855 return (!icon_info || !icon_info->nonactivatable);
7859 * gtk_entry_get_icon_pixbuf:
7860 * @entry: A #GtkEntry
7861 * @icon_pos: Icon position
7863 * Retrieves the image used for the icon.
7865 * Unlike the other methods of setting and getting icon data, this
7866 * method will work regardless of whether the icon was set using a
7867 * #GdkPixbuf, a #GIcon, a stock item, or an icon name.
7869 * Returns: (transfer none): A #GdkPixbuf, or %NULL if no icon is
7870 * set for this position.
7875 gtk_entry_get_icon_pixbuf (GtkEntry *entry,
7876 GtkEntryIconPosition icon_pos)
7878 GtkEntryPrivate *priv;
7879 EntryIconInfo *icon_info;
7882 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7883 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7887 icon_info = priv->icons[icon_pos];
7892 /* HACK: unfortunately this is transfer none, so we need to return
7893 * the icon helper's cache ref directly.
7895 pixbuf = gtk_entry_ensure_pixbuf (entry, icon_pos);
7896 g_object_unref (pixbuf);
7902 * gtk_entry_get_icon_gicon:
7903 * @entry: A #GtkEntry
7904 * @icon_pos: Icon position
7906 * Retrieves the #GIcon used for the icon, or %NULL if there is
7907 * no icon or if the icon was set by some other method (e.g., by
7908 * stock, pixbuf, or icon name).
7910 * Returns: (transfer none): A #GIcon, or %NULL if no icon is set
7911 * or if the icon is not a #GIcon
7916 gtk_entry_get_icon_gicon (GtkEntry *entry,
7917 GtkEntryIconPosition icon_pos)
7919 GtkEntryPrivate *priv;
7920 EntryIconInfo *icon_info;
7922 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7923 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7926 icon_info = priv->icons[icon_pos];
7931 return _gtk_icon_helper_peek_gicon (icon_info->icon_helper);
7935 * gtk_entry_get_icon_stock:
7936 * @entry: A #GtkEntry
7937 * @icon_pos: Icon position
7939 * Retrieves the stock id used for the icon, or %NULL if there is
7940 * no icon or if the icon was set by some other method (e.g., by
7941 * pixbuf, icon name or gicon).
7943 * Returns: A stock id, or %NULL if no icon is set or if the icon
7944 * wasn't set from a stock id
7949 gtk_entry_get_icon_stock (GtkEntry *entry,
7950 GtkEntryIconPosition icon_pos)
7952 GtkEntryPrivate *priv;
7953 EntryIconInfo *icon_info;
7955 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7956 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7959 icon_info = priv->icons[icon_pos];
7964 return _gtk_icon_helper_get_stock_id (icon_info->icon_helper);
7968 * gtk_entry_get_icon_name:
7969 * @entry: A #GtkEntry
7970 * @icon_pos: Icon position
7972 * Retrieves the icon name used for the icon, or %NULL if there is
7973 * no icon or if the icon was set by some other method (e.g., by
7974 * pixbuf, stock or gicon).
7976 * Returns: An icon name, or %NULL if no icon is set or if the icon
7977 * wasn't set from an icon name
7982 gtk_entry_get_icon_name (GtkEntry *entry,
7983 GtkEntryIconPosition icon_pos)
7985 GtkEntryPrivate *priv;
7986 EntryIconInfo *icon_info;
7988 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7989 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7992 icon_info = priv->icons[icon_pos];
7997 return _gtk_icon_helper_get_icon_name (icon_info->icon_helper);
8001 * gtk_entry_set_icon_sensitive:
8002 * @entry: A #GtkEntry
8003 * @icon_pos: Icon position
8004 * @sensitive: Specifies whether the icon should appear
8005 * sensitive or insensitive
8007 * Sets the sensitivity for the specified icon.
8012 gtk_entry_set_icon_sensitive (GtkEntry *entry,
8013 GtkEntryIconPosition icon_pos,
8016 GtkEntryPrivate *priv;
8017 EntryIconInfo *icon_info;
8019 g_return_if_fail (GTK_IS_ENTRY (entry));
8020 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8024 if ((icon_info = priv->icons[icon_pos]) == NULL)
8025 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8027 if (icon_info->insensitive != !sensitive)
8029 icon_info->insensitive = !sensitive;
8031 icon_info->pressed = FALSE;
8032 icon_info->prelight = FALSE;
8034 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
8035 update_cursors (GTK_WIDGET (entry));
8037 gtk_widget_queue_draw (GTK_WIDGET (entry));
8039 g_object_notify (G_OBJECT (entry),
8040 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-sensitive" : "secondary-icon-sensitive");
8045 * gtk_entry_get_icon_sensitive:
8046 * @entry: a #GtkEntry
8047 * @icon_pos: Icon position
8049 * Returns whether the icon appears sensitive or insensitive.
8051 * Returns: %TRUE if the icon is sensitive.
8056 gtk_entry_get_icon_sensitive (GtkEntry *entry,
8057 GtkEntryIconPosition icon_pos)
8059 GtkEntryPrivate *priv;
8060 EntryIconInfo *icon_info;
8062 g_return_val_if_fail (GTK_IS_ENTRY (entry), TRUE);
8063 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), TRUE);
8067 icon_info = priv->icons[icon_pos];
8069 return (!icon_info || !icon_info->insensitive);
8074 * gtk_entry_get_icon_storage_type:
8075 * @entry: a #GtkEntry
8076 * @icon_pos: Icon position
8078 * Gets the type of representation being used by the icon
8079 * to store image data. If the icon has no image data,
8080 * the return value will be %GTK_IMAGE_EMPTY.
8082 * Return value: image representation being used
8087 gtk_entry_get_icon_storage_type (GtkEntry *entry,
8088 GtkEntryIconPosition icon_pos)
8090 GtkEntryPrivate *priv;
8091 EntryIconInfo *icon_info;
8093 g_return_val_if_fail (GTK_IS_ENTRY (entry), GTK_IMAGE_EMPTY);
8094 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), GTK_IMAGE_EMPTY);
8098 icon_info = priv->icons[icon_pos];
8101 return GTK_IMAGE_EMPTY;
8103 return _gtk_icon_helper_get_storage_type (icon_info->icon_helper);
8107 * gtk_entry_get_icon_at_pos:
8108 * @entry: a #GtkEntry
8109 * @x: the x coordinate of the position to find
8110 * @y: the y coordinate of the position to find
8112 * Finds the icon at the given position and return its index. The
8113 * position's coordinates are relative to the @entry's top left corner.
8114 * If @x, @y doesn't lie inside an icon, -1 is returned.
8115 * This function is intended for use in a #GtkWidget::query-tooltip
8118 * Returns: the index of the icon at the given position, or -1
8123 gtk_entry_get_icon_at_pos (GtkEntry *entry,
8127 GtkAllocation primary;
8128 GtkAllocation secondary;
8129 gint frame_x, frame_y;
8131 g_return_val_if_fail (GTK_IS_ENTRY (entry), -1);
8133 get_frame_size (entry, FALSE, &frame_x, &frame_y, NULL, NULL);
8137 get_icon_allocations (entry, &primary, &secondary);
8139 if (primary.x <= x && x < primary.x + primary.width &&
8140 primary.y <= y && y < primary.y + primary.height)
8141 return GTK_ENTRY_ICON_PRIMARY;
8143 if (secondary.x <= x && x < secondary.x + secondary.width &&
8144 secondary.y <= y && y < secondary.y + secondary.height)
8145 return GTK_ENTRY_ICON_SECONDARY;
8151 * gtk_entry_set_icon_drag_source:
8152 * @entry: a #GtkIconEntry
8153 * @icon_pos: icon position
8154 * @target_list: the targets (data formats) in which the data can be provided
8155 * @actions: a bitmask of the allowed drag actions
8157 * Sets up the icon at the given position so that GTK+ will start a drag
8158 * operation when the user clicks and drags the icon.
8160 * To handle the drag operation, you need to connect to the usual
8161 * #GtkWidget::drag-data-get (or possibly #GtkWidget::drag-data-delete)
8162 * signal, and use gtk_entry_get_current_icon_drag_source() in
8163 * your signal handler to find out if the drag was started from
8166 * By default, GTK+ uses the icon as the drag icon. You can use the
8167 * #GtkWidget::drag-begin signal to set a different icon. Note that you
8168 * have to use g_signal_connect_after() to ensure that your signal handler
8169 * gets executed after the default handler.
8174 gtk_entry_set_icon_drag_source (GtkEntry *entry,
8175 GtkEntryIconPosition icon_pos,
8176 GtkTargetList *target_list,
8177 GdkDragAction actions)
8179 GtkEntryPrivate *priv;
8180 EntryIconInfo *icon_info;
8182 g_return_if_fail (GTK_IS_ENTRY (entry));
8183 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8187 if ((icon_info = priv->icons[icon_pos]) == NULL)
8188 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8190 if (icon_info->target_list)
8191 gtk_target_list_unref (icon_info->target_list);
8192 icon_info->target_list = target_list;
8193 if (icon_info->target_list)
8194 gtk_target_list_ref (icon_info->target_list);
8196 icon_info->actions = actions;
8200 * gtk_entry_get_current_icon_drag_source:
8201 * @entry: a #GtkIconEntry
8203 * Returns the index of the icon which is the source of the current
8204 * DND operation, or -1.
8206 * This function is meant to be used in a #GtkWidget::drag-data-get
8209 * Returns: index of the icon which is the source of the current
8210 * DND operation, or -1.
8215 gtk_entry_get_current_icon_drag_source (GtkEntry *entry)
8217 GtkEntryPrivate *priv;
8218 EntryIconInfo *icon_info = NULL;
8221 g_return_val_if_fail (GTK_IS_ENTRY (entry), -1);
8225 for (i = 0; i < MAX_ICONS; i++)
8227 if ((icon_info = priv->icons[i]))
8229 if (icon_info->in_drag)
8238 * gtk_entry_get_icon_area:
8239 * @entry: A #GtkEntry
8240 * @icon_pos: Icon position
8241 * @icon_area: (out): Return location for the icon's area
8243 * Gets the area where entry's icon at @icon_pos is drawn.
8244 * This function is useful when drawing something to the
8245 * entry in a draw callback.
8247 * If the entry is not realized or has no icon at the given position,
8248 * @icon_area is filled with zeros.
8250 * See also gtk_entry_get_text_area()
8255 gtk_entry_get_icon_area (GtkEntry *entry,
8256 GtkEntryIconPosition icon_pos,
8257 GdkRectangle *icon_area)
8259 GtkEntryPrivate *priv;
8260 EntryIconInfo *icon_info;
8262 g_return_if_fail (GTK_IS_ENTRY (entry));
8263 g_return_if_fail (icon_area != NULL);
8267 icon_info = priv->icons[icon_pos];
8271 GtkAllocation primary;
8272 GtkAllocation secondary;
8274 get_icon_allocations (entry, &primary, &secondary);
8276 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
8277 *icon_area = primary;
8279 *icon_area = secondary;
8285 icon_area->width = 0;
8286 icon_area->height = 0;
8291 ensure_has_tooltip (GtkEntry *entry)
8293 GtkEntryPrivate *priv;
8294 EntryIconInfo *icon_info;
8296 gboolean has_tooltip = FALSE;
8300 for (i = 0; i < MAX_ICONS; i++)
8302 if ((icon_info = priv->icons[i]) != NULL)
8304 if (icon_info->tooltip != NULL)
8312 gtk_widget_set_has_tooltip (GTK_WIDGET (entry), has_tooltip);
8316 * gtk_entry_get_icon_tooltip_text:
8317 * @entry: a #GtkEntry
8318 * @icon_pos: the icon position
8320 * Gets the contents of the tooltip on the icon at the specified
8321 * position in @entry.
8323 * Returns: the tooltip text, or %NULL. Free the returned string
8324 * with g_free() when done.
8329 gtk_entry_get_icon_tooltip_text (GtkEntry *entry,
8330 GtkEntryIconPosition icon_pos)
8332 GtkEntryPrivate *priv;
8333 EntryIconInfo *icon_info;
8336 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8337 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8341 icon_info = priv->icons[icon_pos];
8346 if (icon_info->tooltip &&
8347 !pango_parse_markup (icon_info->tooltip, -1, 0, NULL, &text, NULL, NULL))
8348 g_assert (NULL == text); /* text should still be NULL in case of markup errors */
8354 * gtk_entry_set_icon_tooltip_text:
8355 * @entry: a #GtkEntry
8356 * @icon_pos: the icon position
8357 * @tooltip: (allow-none): the contents of the tooltip for the icon, or %NULL
8359 * Sets @tooltip as the contents of the tooltip for the icon
8360 * at the specified position.
8362 * Use %NULL for @tooltip to remove an existing tooltip.
8364 * See also gtk_widget_set_tooltip_text() and
8365 * gtk_entry_set_icon_tooltip_markup().
8370 gtk_entry_set_icon_tooltip_text (GtkEntry *entry,
8371 GtkEntryIconPosition icon_pos,
8372 const gchar *tooltip)
8374 GtkEntryPrivate *priv;
8375 EntryIconInfo *icon_info;
8377 g_return_if_fail (GTK_IS_ENTRY (entry));
8378 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8382 if ((icon_info = priv->icons[icon_pos]) == NULL)
8383 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8385 if (icon_info->tooltip)
8386 g_free (icon_info->tooltip);
8388 /* Treat an empty string as a NULL string,
8389 * because an empty string would be useless for a tooltip:
8391 if (tooltip && tooltip[0] == '\0')
8394 icon_info->tooltip = tooltip ? g_markup_escape_text (tooltip, -1) : NULL;
8396 ensure_has_tooltip (entry);
8400 * gtk_entry_get_icon_tooltip_markup:
8401 * @entry: a #GtkEntry
8402 * @icon_pos: the icon position
8404 * Gets the contents of the tooltip on the icon at the specified
8405 * position in @entry.
8407 * Returns: the tooltip text, or %NULL. Free the returned string
8408 * with g_free() when done.
8413 gtk_entry_get_icon_tooltip_markup (GtkEntry *entry,
8414 GtkEntryIconPosition icon_pos)
8416 GtkEntryPrivate *priv;
8417 EntryIconInfo *icon_info;
8419 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8420 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8424 icon_info = priv->icons[icon_pos];
8429 return g_strdup (icon_info->tooltip);
8433 * gtk_entry_set_icon_tooltip_markup:
8434 * @entry: a #GtkEntry
8435 * @icon_pos: the icon position
8436 * @tooltip: (allow-none): the contents of the tooltip for the icon, or %NULL
8438 * Sets @tooltip as the contents of the tooltip for the icon at
8439 * the specified position. @tooltip is assumed to be marked up with
8440 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
8442 * Use %NULL for @tooltip to remove an existing tooltip.
8444 * See also gtk_widget_set_tooltip_markup() and
8445 * gtk_enty_set_icon_tooltip_text().
8450 gtk_entry_set_icon_tooltip_markup (GtkEntry *entry,
8451 GtkEntryIconPosition icon_pos,
8452 const gchar *tooltip)
8454 GtkEntryPrivate *priv;
8455 EntryIconInfo *icon_info;
8457 g_return_if_fail (GTK_IS_ENTRY (entry));
8458 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8462 if ((icon_info = priv->icons[icon_pos]) == NULL)
8463 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8465 if (icon_info->tooltip)
8466 g_free (icon_info->tooltip);
8468 /* Treat an empty string as a NULL string,
8469 * because an empty string would be useless for a tooltip:
8471 if (tooltip && tooltip[0] == '\0')
8474 icon_info->tooltip = g_strdup (tooltip);
8476 ensure_has_tooltip (entry);
8480 gtk_entry_query_tooltip (GtkWidget *widget,
8483 gboolean keyboard_tip,
8484 GtkTooltip *tooltip)
8487 GtkEntryPrivate *priv;
8488 EntryIconInfo *icon_info;
8491 entry = GTK_ENTRY (widget);
8496 icon_pos = gtk_entry_get_icon_at_pos (entry, x, y);
8499 if ((icon_info = priv->icons[icon_pos]) != NULL)
8501 if (icon_info->tooltip)
8503 gtk_tooltip_set_markup (tooltip, icon_info->tooltip);
8512 return GTK_WIDGET_CLASS (gtk_entry_parent_class)->query_tooltip (widget,
8519 /* Quick hack of a popup menu
8522 activate_cb (GtkWidget *menuitem,
8525 const gchar *signal = g_object_get_data (G_OBJECT (menuitem), "gtk-signal");
8526 g_signal_emit_by_name (entry, signal);
8531 gtk_entry_mnemonic_activate (GtkWidget *widget,
8532 gboolean group_cycling)
8534 gtk_widget_grab_focus (widget);
8539 append_action_signal (GtkEntry *entry,
8541 const gchar *stock_id,
8542 const gchar *signal,
8545 GtkWidget *menuitem = gtk_image_menu_item_new_from_stock (stock_id, NULL);
8547 g_object_set_data (G_OBJECT (menuitem), I_("gtk-signal"), (char *)signal);
8548 g_signal_connect (menuitem, "activate",
8549 G_CALLBACK (activate_cb), entry);
8551 gtk_widget_set_sensitive (menuitem, sensitive);
8553 gtk_widget_show (menuitem);
8554 gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
8558 popup_menu_detach (GtkWidget *attach_widget,
8561 GtkEntry *entry_attach = GTK_ENTRY (attach_widget);
8562 GtkEntryPrivate *priv_attach = entry_attach->priv;
8564 priv_attach->popup_menu = NULL;
8568 popup_position_func (GtkMenu *menu,
8574 GtkEntry *entry = GTK_ENTRY (user_data);
8575 GtkEntryPrivate *priv = entry->priv;
8576 GtkWidget *widget = GTK_WIDGET (entry);
8578 GtkRequisition menu_req;
8579 GdkRectangle monitor;
8581 gint monitor_num, strong_x, height;
8583 g_return_if_fail (gtk_widget_get_realized (widget));
8585 gdk_window_get_origin (priv->text_area, x, y);
8587 screen = gtk_widget_get_screen (widget);
8588 monitor_num = gdk_screen_get_monitor_at_window (screen, priv->text_area);
8589 if (monitor_num < 0)
8591 gtk_menu_set_monitor (menu, monitor_num);
8593 gdk_screen_get_monitor_workarea (screen, monitor_num, &monitor);
8594 gtk_widget_get_preferred_size (priv->popup_menu,
8596 height = gdk_window_get_height (priv->text_area);
8597 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
8598 _gtk_entry_get_borders (entry, &borders);
8600 *x += borders.left + strong_x - priv->scroll_offset;
8601 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
8602 *x -= menu_req.width;
8604 if ((*y + height + menu_req.height) <= monitor.y + monitor.height)
8606 else if ((*y - menu_req.height) >= monitor.y)
8607 *y -= menu_req.height;
8608 else if (monitor.y + monitor.height - (*y + height) > *y)
8611 *y -= menu_req.height;
8617 unichar_chosen_func (const char *text,
8620 GtkEntry *entry = GTK_ENTRY (data);
8621 GtkEntryPrivate *priv = entry->priv;
8624 gtk_entry_enter_text (entry, text);
8636 popup_targets_received (GtkClipboard *clipboard,
8637 GtkSelectionData *data,
8640 PopupInfo *info = user_data;
8641 GtkEntry *entry = info->entry;
8642 GtkEntryPrivate *info_entry_priv = entry->priv;
8644 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
8647 gboolean clipboard_contains_text;
8648 GtkWidget *menuitem;
8650 gboolean show_input_method_menu;
8651 gboolean show_unicode_menu;
8653 clipboard_contains_text = gtk_selection_data_targets_include_text (data);
8654 if (info_entry_priv->popup_menu)
8655 gtk_widget_destroy (info_entry_priv->popup_menu);
8657 info_entry_priv->popup_menu = gtk_menu_new ();
8659 gtk_menu_attach_to_widget (GTK_MENU (info_entry_priv->popup_menu),
8663 mode = gtk_entry_get_display_mode (entry);
8664 append_action_signal (entry, info_entry_priv->popup_menu, GTK_STOCK_CUT, "cut-clipboard",
8665 info_entry_priv->editable && mode == DISPLAY_NORMAL &&
8666 info_entry_priv->current_pos != info_entry_priv->selection_bound);
8668 append_action_signal (entry, info_entry_priv->popup_menu, GTK_STOCK_COPY, "copy-clipboard",
8669 mode == DISPLAY_NORMAL &&
8670 info_entry_priv->current_pos != info_entry_priv->selection_bound);
8672 append_action_signal (entry, info_entry_priv->popup_menu, GTK_STOCK_PASTE, "paste-clipboard",
8673 info_entry_priv->editable && clipboard_contains_text);
8675 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_DELETE, NULL);
8676 gtk_widget_set_sensitive (menuitem, info_entry_priv->editable && info_entry_priv->current_pos != info_entry_priv->selection_bound);
8677 g_signal_connect_swapped (menuitem, "activate",
8678 G_CALLBACK (gtk_entry_delete_cb), entry);
8679 gtk_widget_show (menuitem);
8680 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8682 menuitem = gtk_separator_menu_item_new ();
8683 gtk_widget_show (menuitem);
8684 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8686 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_SELECT_ALL, NULL);
8687 gtk_widget_set_sensitive (menuitem, gtk_entry_buffer_get_length (info_entry_priv->buffer) > 0);
8688 g_signal_connect_swapped (menuitem, "activate",
8689 G_CALLBACK (gtk_entry_select_all), entry);
8690 gtk_widget_show (menuitem);
8691 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8693 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
8694 "gtk-show-input-method-menu", &show_input_method_menu,
8695 "gtk-show-unicode-menu", &show_unicode_menu,
8698 if (show_input_method_menu || show_unicode_menu)
8700 menuitem = gtk_separator_menu_item_new ();
8701 gtk_widget_show (menuitem);
8702 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8705 if (show_input_method_menu)
8707 menuitem = gtk_menu_item_new_with_mnemonic (_("Input _Methods"));
8708 gtk_widget_set_sensitive (menuitem, info_entry_priv->editable);
8709 gtk_widget_show (menuitem);
8710 submenu = gtk_menu_new ();
8711 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
8713 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8715 gtk_im_multicontext_append_menuitems (GTK_IM_MULTICONTEXT (info_entry_priv->im_context),
8716 GTK_MENU_SHELL (submenu));
8719 if (show_unicode_menu)
8721 menuitem = gtk_menu_item_new_with_mnemonic (_("_Insert Unicode Control Character"));
8722 gtk_widget_set_sensitive (menuitem, info_entry_priv->editable);
8723 gtk_widget_show (menuitem);
8725 submenu = gtk_menu_new ();
8726 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
8727 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8729 _gtk_text_util_append_special_char_menuitems (GTK_MENU_SHELL (submenu),
8730 unichar_chosen_func,
8734 g_signal_emit (entry,
8735 signals[POPULATE_POPUP],
8737 info_entry_priv->popup_menu);
8741 gtk_menu_popup_for_device (GTK_MENU (info_entry_priv->popup_menu),
8742 info->device, NULL, NULL, NULL, NULL, NULL,
8743 info->button, info->time);
8746 gtk_menu_popup (GTK_MENU (info_entry_priv->popup_menu), NULL, NULL,
8747 popup_position_func, entry,
8748 0, gtk_get_current_event_time ());
8749 gtk_menu_shell_select_first (GTK_MENU_SHELL (info_entry_priv->popup_menu), FALSE);
8753 g_object_unref (entry);
8754 g_slice_free (PopupInfo, info);
8758 gtk_entry_do_popup (GtkEntry *entry,
8759 GdkEventButton *event)
8761 PopupInfo *info = g_slice_new (PopupInfo);
8763 /* In order to know what entries we should make sensitive, we
8764 * ask for the current targets of the clipboard, and when
8765 * we get them, then we actually pop up the menu.
8767 info->entry = g_object_ref (entry);
8771 info->button = event->button;
8772 info->time = event->time;
8773 info->device = event->device;
8778 info->time = gtk_get_current_event_time ();
8779 info->device = NULL;
8782 gtk_clipboard_request_contents (gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_CLIPBOARD),
8783 gdk_atom_intern_static_string ("TARGETS"),
8784 popup_targets_received,
8789 gtk_entry_popup_menu (GtkWidget *widget)
8791 gtk_entry_do_popup (GTK_ENTRY (widget), NULL);
8796 gtk_entry_drag_begin (GtkWidget *widget,
8797 GdkDragContext *context)
8799 GtkEntry *entry = GTK_ENTRY (widget);
8800 GtkEntryPrivate *priv = entry->priv;
8803 for (i = 0; i < MAX_ICONS; i++)
8805 EntryIconInfo *icon_info = priv->icons[i];
8807 if (icon_info != NULL)
8809 if (icon_info->in_drag)
8813 pix = _gtk_icon_helper_ensure_pixbuf
8814 (icon_info->icon_helper,
8815 gtk_widget_get_style_context (GTK_WIDGET (entry)));
8816 gtk_drag_set_icon_pixbuf (context, pix, -2, -2);
8818 g_object_unref (pix);
8825 gtk_entry_drag_end (GtkWidget *widget,
8826 GdkDragContext *context)
8828 GtkEntry *entry = GTK_ENTRY (widget);
8829 GtkEntryPrivate *priv = entry->priv;
8832 for (i = 0; i < MAX_ICONS; i++)
8834 EntryIconInfo *icon_info = priv->icons[i];
8836 if (icon_info != NULL)
8837 icon_info->in_drag = 0;
8842 gtk_entry_drag_leave (GtkWidget *widget,
8843 GdkDragContext *context,
8846 GtkEntry *entry = GTK_ENTRY (widget);
8847 GtkEntryPrivate *priv = entry->priv;
8849 priv->dnd_position = -1;
8850 gtk_widget_queue_draw (widget);
8854 gtk_entry_drag_drop (GtkWidget *widget,
8855 GdkDragContext *context,
8860 GtkEntry *entry = GTK_ENTRY (widget);
8861 GtkEntryPrivate *priv = entry->priv;
8862 GdkAtom target = GDK_NONE;
8865 target = gtk_drag_dest_find_target (widget, context, NULL);
8867 if (target != GDK_NONE)
8868 gtk_drag_get_data (widget, context, target, time);
8870 gtk_drag_finish (context, FALSE, FALSE, time);
8876 gtk_entry_drag_motion (GtkWidget *widget,
8877 GdkDragContext *context,
8882 GtkEntry *entry = GTK_ENTRY (widget);
8883 GtkEntryPrivate *priv = entry->priv;
8884 GtkStyleContext *style_context;
8885 GtkWidget *source_widget;
8886 GdkDragAction suggested_action;
8887 gint new_position, old_position;
8891 style_context = gtk_widget_get_style_context (widget);
8892 gtk_style_context_get_padding (style_context, 0, &padding);
8896 old_position = priv->dnd_position;
8897 new_position = gtk_entry_find_position (entry, x + priv->scroll_offset);
8899 if (priv->editable &&
8900 gtk_drag_dest_find_target (widget, context, NULL) != GDK_NONE)
8902 source_widget = gtk_drag_get_source_widget (context);
8903 suggested_action = gdk_drag_context_get_suggested_action (context);
8905 if (!gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &sel1, &sel2) ||
8906 new_position < sel1 || new_position > sel2)
8908 if (source_widget == widget)
8910 /* Default to MOVE, unless the user has
8911 * pressed ctrl or alt to affect available actions
8913 if ((gdk_drag_context_get_actions (context) & GDK_ACTION_MOVE) != 0)
8914 suggested_action = GDK_ACTION_MOVE;
8917 priv->dnd_position = new_position;
8921 if (source_widget == widget)
8922 suggested_action = 0; /* Can't drop in selection where drag started */
8924 priv->dnd_position = -1;
8929 /* Entry not editable, or no text */
8930 suggested_action = 0;
8931 priv->dnd_position = -1;
8934 gdk_drag_status (context, suggested_action, time);
8936 if (priv->dnd_position != old_position)
8937 gtk_widget_queue_draw (widget);
8943 gtk_entry_drag_data_received (GtkWidget *widget,
8944 GdkDragContext *context,
8947 GtkSelectionData *selection_data,
8951 GtkEntry *entry = GTK_ENTRY (widget);
8952 GtkEntryPrivate *priv = entry->priv;
8953 GtkEditable *editable = GTK_EDITABLE (widget);
8954 GtkStyleContext *style_context;
8958 str = (gchar *) gtk_selection_data_get_text (selection_data);
8960 style_context = gtk_widget_get_style_context (widget);
8961 gtk_style_context_get_padding (style_context, 0, &padding);
8965 if (str && priv->editable)
8971 if (priv->truncate_multiline)
8972 length = truncate_multiline (str);
8974 new_position = gtk_entry_find_position (entry, x + priv->scroll_offset);
8976 if (!gtk_editable_get_selection_bounds (editable, &sel1, &sel2) ||
8977 new_position < sel1 || new_position > sel2)
8979 gtk_editable_insert_text (editable, str, length, &new_position);
8983 /* Replacing selection */
8984 begin_change (entry);
8985 gtk_editable_delete_text (editable, sel1, sel2);
8986 gtk_editable_insert_text (editable, str, length, &sel1);
8990 gtk_drag_finish (context, TRUE, gdk_drag_context_get_selected_action (context) == GDK_ACTION_MOVE, time);
8994 /* Drag and drop didn't happen! */
8995 gtk_drag_finish (context, FALSE, FALSE, time);
9002 gtk_entry_drag_data_get (GtkWidget *widget,
9003 GdkDragContext *context,
9004 GtkSelectionData *selection_data,
9008 GtkEntry *entry = GTK_ENTRY (widget);
9009 GtkEntryPrivate *priv = entry->priv;
9010 GtkEditable *editable = GTK_EDITABLE (widget);
9011 gint sel_start, sel_end;
9014 /* If there is an icon drag going on, exit early. */
9015 for (i = 0; i < MAX_ICONS; i++)
9017 EntryIconInfo *icon_info = priv->icons[i];
9019 if (icon_info != NULL)
9021 if (icon_info->in_drag)
9026 if (gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end))
9028 gchar *str = gtk_entry_get_display_text (GTK_ENTRY (widget), sel_start, sel_end);
9030 gtk_selection_data_set_text (selection_data, str, -1);
9038 gtk_entry_drag_data_delete (GtkWidget *widget,
9039 GdkDragContext *context)
9041 GtkEntry *entry = GTK_ENTRY (widget);
9042 GtkEntryPrivate *priv = entry->priv;
9043 GtkEditable *editable = GTK_EDITABLE (widget);
9044 gint sel_start, sel_end;
9047 /* If there is an icon drag going on, exit early. */
9048 for (i = 0; i < MAX_ICONS; i++)
9050 EntryIconInfo *icon_info = priv->icons[i];
9052 if (icon_info != NULL)
9054 if (icon_info->in_drag)
9059 if (priv->editable &&
9060 gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end))
9061 gtk_editable_delete_text (editable, sel_start, sel_end);
9064 /* We display the cursor when
9066 * - the selection is empty, AND
9067 * - the widget has focus
9070 #define CURSOR_ON_MULTIPLIER 2
9071 #define CURSOR_OFF_MULTIPLIER 1
9072 #define CURSOR_PEND_MULTIPLIER 3
9073 #define CURSOR_DIVIDER 3
9076 cursor_blinks (GtkEntry *entry)
9078 GtkEntryPrivate *priv = entry->priv;
9080 if (gtk_widget_has_focus (GTK_WIDGET (entry)) &&
9082 priv->selection_bound == priv->current_pos)
9084 GtkSettings *settings;
9087 settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9088 g_object_get (settings, "gtk-cursor-blink", &blink, NULL);
9097 get_cursor_time (GtkEntry *entry)
9099 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9102 g_object_get (settings, "gtk-cursor-blink-time", &time, NULL);
9108 get_cursor_blink_timeout (GtkEntry *entry)
9110 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9113 g_object_get (settings, "gtk-cursor-blink-timeout", &timeout, NULL);
9119 show_cursor (GtkEntry *entry)
9121 GtkEntryPrivate *priv = entry->priv;
9124 if (!priv->cursor_visible)
9126 priv->cursor_visible = TRUE;
9128 widget = GTK_WIDGET (entry);
9129 if (gtk_widget_has_focus (widget) && priv->selection_bound == priv->current_pos)
9130 gtk_widget_queue_draw (widget);
9135 hide_cursor (GtkEntry *entry)
9137 GtkEntryPrivate *priv = entry->priv;
9140 if (priv->cursor_visible)
9142 priv->cursor_visible = FALSE;
9144 widget = GTK_WIDGET (entry);
9145 if (gtk_widget_has_focus (widget) && priv->selection_bound == priv->current_pos)
9146 gtk_widget_queue_draw (widget);
9154 blink_cb (gpointer data)
9157 GtkEntryPrivate *priv;
9160 entry = GTK_ENTRY (data);
9163 if (!gtk_widget_has_focus (GTK_WIDGET (entry)))
9165 g_warning ("GtkEntry - did not receive focus-out-event. If you\n"
9166 "connect a handler to this signal, it must return\n"
9167 "FALSE so the entry gets the event as well");
9169 gtk_entry_check_cursor_blink (entry);
9174 g_assert (priv->selection_bound == priv->current_pos);
9176 blink_timeout = get_cursor_blink_timeout (entry);
9177 if (priv->blink_time > 1000 * blink_timeout &&
9178 blink_timeout < G_MAXINT/1000)
9180 /* we've blinked enough without the user doing anything, stop blinking */
9181 show_cursor (entry);
9182 priv->blink_timeout = 0;
9184 else if (priv->cursor_visible)
9186 hide_cursor (entry);
9187 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_OFF_MULTIPLIER / CURSOR_DIVIDER,
9193 show_cursor (entry);
9194 priv->blink_time += get_cursor_time (entry);
9195 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
9200 /* Remove ourselves */
9205 gtk_entry_check_cursor_blink (GtkEntry *entry)
9207 GtkEntryPrivate *priv = entry->priv;
9209 if (cursor_blinks (entry))
9211 if (!priv->blink_timeout)
9213 show_cursor (entry);
9214 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
9221 if (priv->blink_timeout)
9223 g_source_remove (priv->blink_timeout);
9224 priv->blink_timeout = 0;
9227 priv->cursor_visible = TRUE;
9232 gtk_entry_pend_cursor_blink (GtkEntry *entry)
9234 GtkEntryPrivate *priv = entry->priv;
9236 if (cursor_blinks (entry))
9238 if (priv->blink_timeout != 0)
9239 g_source_remove (priv->blink_timeout);
9241 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_PEND_MULTIPLIER / CURSOR_DIVIDER,
9244 show_cursor (entry);
9249 gtk_entry_reset_blink_time (GtkEntry *entry)
9251 GtkEntryPrivate *priv = entry->priv;
9253 priv->blink_time = 0;
9259 gtk_entry_completion_timeout (gpointer data)
9261 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (data);
9262 GtkEntryPrivate *completion_entry_priv = GTK_ENTRY (completion->priv->entry)->priv;
9264 completion->priv->completion_timeout = 0;
9266 if (completion->priv->filter_model &&
9267 g_utf8_strlen (gtk_entry_get_text (GTK_ENTRY (completion->priv->entry)), -1)
9268 >= completion->priv->minimum_key_length)
9272 GtkTreeSelection *s;
9273 gboolean popup_single;
9275 gtk_entry_completion_complete (completion);
9276 matches = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->filter_model), NULL);
9278 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9280 s = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view));
9282 gtk_tree_selection_unselect_all (s);
9284 actions = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->actions), NULL);
9286 g_object_get (completion, "popup-single-match", &popup_single, NULL);
9287 if ((matches > (popup_single ? 0: 1)) || actions > 0)
9289 if (gtk_widget_get_visible (completion->priv->popup_window))
9290 _gtk_entry_completion_resize_popup (completion);
9292 _gtk_entry_completion_popup (completion, completion_entry_priv->completion_device);
9295 _gtk_entry_completion_popdown (completion);
9297 else if (gtk_widget_get_visible (completion->priv->popup_window))
9298 _gtk_entry_completion_popdown (completion);
9303 static inline gboolean
9304 keyval_is_cursor_move (guint keyval)
9306 if (keyval == GDK_KEY_Up || keyval == GDK_KEY_KP_Up)
9309 if (keyval == GDK_KEY_Down || keyval == GDK_KEY_KP_Down)
9312 if (keyval == GDK_KEY_Page_Up)
9315 if (keyval == GDK_KEY_Page_Down)
9322 gtk_entry_completion_key_press (GtkWidget *widget,
9326 gint matches, actions = 0;
9327 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
9329 if (!gtk_widget_get_mapped (completion->priv->popup_window))
9332 matches = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->filter_model), NULL);
9334 if (completion->priv->actions)
9335 actions = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->actions), NULL);
9337 if (keyval_is_cursor_move (event->keyval))
9339 GtkTreePath *path = NULL;
9341 if (event->keyval == GDK_KEY_Up || event->keyval == GDK_KEY_KP_Up)
9343 if (completion->priv->current_selected < 0)
9344 completion->priv->current_selected = matches + actions - 1;
9346 completion->priv->current_selected--;
9348 else if (event->keyval == GDK_KEY_Down || event->keyval == GDK_KEY_KP_Down)
9350 if (completion->priv->current_selected < matches + actions - 1)
9351 completion->priv->current_selected++;
9353 completion->priv->current_selected = -1;
9355 else if (event->keyval == GDK_KEY_Page_Up)
9357 if (completion->priv->current_selected < 0)
9358 completion->priv->current_selected = matches + actions - 1;
9359 else if (completion->priv->current_selected == 0)
9360 completion->priv->current_selected = -1;
9361 else if (completion->priv->current_selected < matches)
9363 completion->priv->current_selected -= PAGE_STEP;
9364 if (completion->priv->current_selected < 0)
9365 completion->priv->current_selected = 0;
9369 completion->priv->current_selected -= PAGE_STEP;
9370 if (completion->priv->current_selected < matches - 1)
9371 completion->priv->current_selected = matches - 1;
9374 else if (event->keyval == GDK_KEY_Page_Down)
9376 if (completion->priv->current_selected < 0)
9377 completion->priv->current_selected = 0;
9378 else if (completion->priv->current_selected < matches - 1)
9380 completion->priv->current_selected += PAGE_STEP;
9381 if (completion->priv->current_selected > matches - 1)
9382 completion->priv->current_selected = matches - 1;
9384 else if (completion->priv->current_selected == matches + actions - 1)
9386 completion->priv->current_selected = -1;
9390 completion->priv->current_selected += PAGE_STEP;
9391 if (completion->priv->current_selected > matches + actions - 1)
9392 completion->priv->current_selected = matches + actions - 1;
9396 if (completion->priv->current_selected < 0)
9398 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9399 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view)));
9401 if (completion->priv->inline_selection &&
9402 completion->priv->completion_prefix)
9404 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9405 completion->priv->completion_prefix);
9406 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9409 else if (completion->priv->current_selected < matches)
9411 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view)));
9413 path = gtk_tree_path_new_from_indices (completion->priv->current_selected, -1);
9414 gtk_tree_view_set_cursor (GTK_TREE_VIEW (completion->priv->tree_view),
9417 if (completion->priv->inline_selection)
9421 GtkTreeIter child_iter;
9422 GtkTreeModel *model = NULL;
9423 GtkTreeSelection *sel;
9426 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view));
9427 if (!gtk_tree_selection_get_selected (sel, &model, &iter))
9430 gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (model), &child_iter, &iter);
9431 model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model));
9433 if (completion->priv->completion_prefix == NULL)
9434 completion->priv->completion_prefix = g_strdup (gtk_entry_get_text (GTK_ENTRY (completion->priv->entry)));
9436 g_signal_emit_by_name (completion, "cursor-on-match", model,
9437 &child_iter, &entry_set);
9440 else if (completion->priv->current_selected - matches >= 0)
9442 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9444 path = gtk_tree_path_new_from_indices (completion->priv->current_selected - matches, -1);
9445 gtk_tree_view_set_cursor (GTK_TREE_VIEW (completion->priv->action_view),
9448 if (completion->priv->inline_selection &&
9449 completion->priv->completion_prefix)
9451 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9452 completion->priv->completion_prefix);
9453 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9457 gtk_tree_path_free (path);
9461 else if (event->keyval == GDK_KEY_Escape ||
9462 event->keyval == GDK_KEY_Left ||
9463 event->keyval == GDK_KEY_KP_Left ||
9464 event->keyval == GDK_KEY_Right ||
9465 event->keyval == GDK_KEY_KP_Right)
9467 gboolean retval = TRUE;
9469 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9470 _gtk_entry_completion_popdown (completion);
9472 if (completion->priv->current_selected < 0)
9475 goto keypress_completion_out;
9477 else if (completion->priv->inline_selection)
9479 /* Escape rejects the tentative completion */
9480 if (event->keyval == GDK_KEY_Escape)
9482 if (completion->priv->completion_prefix)
9483 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9484 completion->priv->completion_prefix);
9486 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry), "");
9489 /* Move the cursor to the end for Right/Esc, to the
9490 beginning for Left */
9491 if (event->keyval == GDK_KEY_Right ||
9492 event->keyval == GDK_KEY_KP_Right ||
9493 event->keyval == GDK_KEY_Escape)
9494 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9496 gtk_editable_set_position (GTK_EDITABLE (widget), 0);
9499 keypress_completion_out:
9500 if (completion->priv->inline_selection)
9502 g_free (completion->priv->completion_prefix);
9503 completion->priv->completion_prefix = NULL;
9508 else if (event->keyval == GDK_KEY_Tab ||
9509 event->keyval == GDK_KEY_KP_Tab ||
9510 event->keyval == GDK_KEY_ISO_Left_Tab)
9512 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9513 _gtk_entry_completion_popdown (completion);
9515 g_free (completion->priv->completion_prefix);
9516 completion->priv->completion_prefix = NULL;
9520 else if (event->keyval == GDK_KEY_ISO_Enter ||
9521 event->keyval == GDK_KEY_KP_Enter ||
9522 event->keyval == GDK_KEY_Return)
9525 GtkTreeModel *model = NULL;
9526 GtkTreeModel *child_model;
9527 GtkTreeIter child_iter;
9528 GtkTreeSelection *sel;
9529 gboolean retval = TRUE;
9531 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9532 _gtk_entry_completion_popdown (completion);
9534 if (completion->priv->current_selected < matches)
9538 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view));
9539 if (gtk_tree_selection_get_selected (sel, &model, &iter))
9541 gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (model), &child_iter, &iter);
9542 child_model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model));
9543 g_signal_handler_block (widget, completion->priv->changed_id);
9544 g_signal_emit_by_name (completion, "match-selected",
9545 child_model, &child_iter, &entry_set);
9546 g_signal_handler_unblock (widget, completion->priv->changed_id);
9552 gtk_tree_model_get (model, &iter,
9553 completion->priv->text_column, &str,
9556 gtk_entry_set_text (GTK_ENTRY (widget), str);
9558 /* move the cursor to the end */
9559 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9567 else if (completion->priv->current_selected - matches >= 0)
9569 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view));
9570 if (gtk_tree_selection_get_selected (sel, &model, &iter))
9574 path = gtk_tree_path_new_from_indices (completion->priv->current_selected - matches, -1);
9575 g_signal_emit_by_name (completion, "action-activated",
9576 gtk_tree_path_get_indices (path)[0]);
9577 gtk_tree_path_free (path);
9583 g_free (completion->priv->completion_prefix);
9584 completion->priv->completion_prefix = NULL;
9593 gtk_entry_completion_changed (GtkWidget *widget,
9596 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
9597 GtkEntry *entry = GTK_ENTRY (widget);
9598 GtkEntryPrivate *priv = entry->priv;
9601 /* (re)install completion timeout */
9602 if (completion->priv->completion_timeout)
9603 g_source_remove (completion->priv->completion_timeout);
9605 if (!gtk_entry_get_text (entry))
9608 /* no need to normalize for this test */
9609 if (completion->priv->minimum_key_length > 0 &&
9610 strcmp ("", gtk_entry_get_text (entry)) == 0)
9612 if (gtk_widget_get_visible (completion->priv->popup_window))
9613 _gtk_entry_completion_popdown (completion);
9617 device = gtk_get_current_event_device ();
9619 if (device && gdk_device_get_source (device) == GDK_SOURCE_KEYBOARD)
9620 device = gdk_device_get_associated_device (device);
9623 priv->completion_device = device;
9625 completion->priv->completion_timeout =
9626 gdk_threads_add_timeout (COMPLETION_TIMEOUT,
9627 gtk_entry_completion_timeout,
9632 check_completion_callback (GtkEntryCompletion *completion)
9634 completion->priv->check_completion_idle = NULL;
9636 gtk_entry_completion_complete (completion);
9637 gtk_entry_completion_insert_prefix (completion);
9643 clear_completion_callback (GtkEntry *entry,
9646 if (pspec->name == I_("cursor-position") ||
9647 pspec->name == I_("selection-bound"))
9649 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
9651 completion->priv->has_completion = FALSE;
9656 accept_completion_callback (GtkEntry *entry)
9658 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
9660 if (completion->priv->has_completion)
9661 gtk_editable_set_position (GTK_EDITABLE (entry),
9662 gtk_entry_buffer_get_length (get_buffer (entry)));
9668 completion_insert_text_callback (GtkEntry *entry,
9672 GtkEntryCompletion *completion)
9674 /* idle to update the selection based on the file list */
9675 if (completion->priv->check_completion_idle == NULL)
9677 completion->priv->check_completion_idle = g_idle_source_new ();
9678 g_source_set_priority (completion->priv->check_completion_idle, G_PRIORITY_HIGH);
9679 g_source_set_closure (completion->priv->check_completion_idle,
9680 g_cclosure_new_object (G_CALLBACK (check_completion_callback),
9681 G_OBJECT (completion)));
9682 g_source_attach (completion->priv->check_completion_idle, NULL);
9687 completion_changed (GtkEntryCompletion *completion,
9691 GtkEntry *entry = GTK_ENTRY (data);
9693 if (pspec->name == I_("popup-completion") ||
9694 pspec->name == I_("inline-completion"))
9696 disconnect_completion_signals (entry, completion);
9697 connect_completion_signals (entry, completion);
9702 disconnect_completion_signals (GtkEntry *entry,
9703 GtkEntryCompletion *completion)
9705 g_signal_handlers_disconnect_by_func (completion,
9706 G_CALLBACK (completion_changed), entry);
9707 if (completion->priv->changed_id > 0 &&
9708 g_signal_handler_is_connected (entry, completion->priv->changed_id))
9710 g_signal_handler_disconnect (entry, completion->priv->changed_id);
9711 completion->priv->changed_id = 0;
9713 g_signal_handlers_disconnect_by_func (entry,
9714 G_CALLBACK (gtk_entry_completion_key_press), completion);
9715 if (completion->priv->insert_text_id > 0 &&
9716 g_signal_handler_is_connected (entry, completion->priv->insert_text_id))
9718 g_signal_handler_disconnect (entry, completion->priv->insert_text_id);
9719 completion->priv->insert_text_id = 0;
9721 g_signal_handlers_disconnect_by_func (entry,
9722 G_CALLBACK (completion_insert_text_callback), completion);
9723 g_signal_handlers_disconnect_by_func (entry,
9724 G_CALLBACK (clear_completion_callback), completion);
9725 g_signal_handlers_disconnect_by_func (entry,
9726 G_CALLBACK (accept_completion_callback), completion);
9730 connect_completion_signals (GtkEntry *entry,
9731 GtkEntryCompletion *completion)
9733 if (completion->priv->popup_completion)
9735 completion->priv->changed_id =
9736 g_signal_connect (entry, "changed",
9737 G_CALLBACK (gtk_entry_completion_changed), completion);
9738 g_signal_connect (entry, "key-press-event",
9739 G_CALLBACK (gtk_entry_completion_key_press), completion);
9742 if (completion->priv->inline_completion)
9744 completion->priv->insert_text_id =
9745 g_signal_connect (entry, "insert-text",
9746 G_CALLBACK (completion_insert_text_callback), completion);
9747 g_signal_connect (entry, "notify",
9748 G_CALLBACK (clear_completion_callback), completion);
9749 g_signal_connect (entry, "activate",
9750 G_CALLBACK (accept_completion_callback), completion);
9751 g_signal_connect (entry, "focus-out-event",
9752 G_CALLBACK (accept_completion_callback), completion);
9755 g_signal_connect (completion, "notify",
9756 G_CALLBACK (completion_changed), entry);
9760 * gtk_entry_set_completion:
9761 * @entry: A #GtkEntry
9762 * @completion: (allow-none): The #GtkEntryCompletion or %NULL
9764 * Sets @completion to be the auxiliary completion object to use with @entry.
9765 * All further configuration of the completion mechanism is done on
9766 * @completion using the #GtkEntryCompletion API. Completion is disabled if
9767 * @completion is set to %NULL.
9772 gtk_entry_set_completion (GtkEntry *entry,
9773 GtkEntryCompletion *completion)
9775 GtkEntryCompletion *old;
9777 g_return_if_fail (GTK_IS_ENTRY (entry));
9778 g_return_if_fail (!completion || GTK_IS_ENTRY_COMPLETION (completion));
9780 old = gtk_entry_get_completion (entry);
9782 if (old == completion)
9787 if (old->priv->completion_timeout)
9789 g_source_remove (old->priv->completion_timeout);
9790 old->priv->completion_timeout = 0;
9793 if (old->priv->check_completion_idle)
9795 g_source_destroy (old->priv->check_completion_idle);
9796 old->priv->check_completion_idle = NULL;
9799 if (gtk_widget_get_mapped (old->priv->popup_window))
9800 _gtk_entry_completion_popdown (old);
9802 disconnect_completion_signals (entry, old);
9803 old->priv->entry = NULL;
9805 g_object_unref (old);
9810 g_object_set_data (G_OBJECT (entry), I_(GTK_ENTRY_COMPLETION_KEY), NULL);
9814 /* hook into the entry */
9815 g_object_ref (completion);
9817 connect_completion_signals (entry, completion);
9818 completion->priv->entry = GTK_WIDGET (entry);
9819 g_object_set_data (G_OBJECT (entry), I_(GTK_ENTRY_COMPLETION_KEY), completion);
9821 g_object_notify (G_OBJECT (entry), "completion");
9825 * gtk_entry_get_completion:
9826 * @entry: A #GtkEntry
9828 * Returns the auxiliary completion object currently in use by @entry.
9830 * Return value: (transfer none): The auxiliary completion object currently
9835 GtkEntryCompletion *
9836 gtk_entry_get_completion (GtkEntry *entry)
9838 GtkEntryCompletion *completion;
9840 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
9842 completion = GTK_ENTRY_COMPLETION (g_object_get_data (G_OBJECT (entry),
9843 GTK_ENTRY_COMPLETION_KEY));
9849 * gtk_entry_set_cursor_hadjustment:
9850 * @entry: a #GtkEntry
9851 * @adjustment: an adjustment which should be adjusted when the cursor
9852 * is moved, or %NULL
9854 * Hooks up an adjustment to the cursor position in an entry, so that when
9855 * the cursor is moved, the adjustment is scrolled to show that position.
9856 * See gtk_scrolled_window_get_hadjustment() for a typical way of obtaining
9859 * The adjustment has to be in pixel units and in the same coordinate system
9865 gtk_entry_set_cursor_hadjustment (GtkEntry *entry,
9866 GtkAdjustment *adjustment)
9868 g_return_if_fail (GTK_IS_ENTRY (entry));
9870 g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
9873 g_object_ref (adjustment);
9875 g_object_set_qdata_full (G_OBJECT (entry),
9876 quark_cursor_hadjustment,
9882 * gtk_entry_get_cursor_hadjustment:
9883 * @entry: a #GtkEntry
9885 * Retrieves the horizontal cursor adjustment for the entry.
9886 * See gtk_entry_set_cursor_hadjustment().
9888 * Return value: (transfer none): the horizontal cursor adjustment, or %NULL
9889 * if none has been set.
9894 gtk_entry_get_cursor_hadjustment (GtkEntry *entry)
9896 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
9898 return g_object_get_qdata (G_OBJECT (entry), quark_cursor_hadjustment);
9902 * gtk_entry_set_progress_fraction:
9903 * @entry: a #GtkEntry
9904 * @fraction: fraction of the task that's been completed
9906 * Causes the entry's progress indicator to "fill in" the given
9907 * fraction of the bar. The fraction should be between 0.0 and 1.0,
9913 gtk_entry_set_progress_fraction (GtkEntry *entry,
9917 GtkEntryPrivate *private;
9918 gdouble old_fraction;
9919 gint x, y, width, height;
9920 gint old_x, old_y, old_width, old_height;
9922 g_return_if_fail (GTK_IS_ENTRY (entry));
9924 widget = GTK_WIDGET (entry);
9925 private = entry->priv;
9927 if (private->progress_pulse_mode)
9930 old_fraction = private->progress_fraction;
9932 if (gtk_widget_is_drawable (widget))
9933 get_progress_area (widget, &old_x, &old_y, &old_width, &old_height);
9935 fraction = CLAMP (fraction, 0.0, 1.0);
9937 private->progress_fraction = fraction;
9938 private->progress_pulse_mode = FALSE;
9939 private->progress_pulse_current = 0.0;
9941 if (gtk_widget_is_drawable (widget))
9943 get_progress_area (widget, &x, &y, &width, &height);
9945 if ((x != old_x) || (y != old_y) || (width != old_width) || (height != old_height))
9946 gtk_widget_queue_draw (widget);
9949 if (fraction != old_fraction)
9950 g_object_notify (G_OBJECT (entry), "progress-fraction");
9954 * gtk_entry_get_progress_fraction:
9955 * @entry: a #GtkEntry
9957 * Returns the current fraction of the task that's been completed.
9958 * See gtk_entry_set_progress_fraction().
9960 * Return value: a fraction from 0.0 to 1.0
9965 gtk_entry_get_progress_fraction (GtkEntry *entry)
9967 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
9969 return entry->priv->progress_fraction;
9973 * gtk_entry_set_progress_pulse_step:
9974 * @entry: a #GtkEntry
9975 * @fraction: fraction between 0.0 and 1.0
9977 * Sets the fraction of total entry width to move the progress
9978 * bouncing block for each call to gtk_entry_progress_pulse().
9983 gtk_entry_set_progress_pulse_step (GtkEntry *entry,
9986 GtkEntryPrivate *private;
9988 g_return_if_fail (GTK_IS_ENTRY (entry));
9990 private = entry->priv;
9992 fraction = CLAMP (fraction, 0.0, 1.0);
9994 if (fraction != private->progress_pulse_fraction)
9996 private->progress_pulse_fraction = fraction;
9998 gtk_widget_queue_draw (GTK_WIDGET (entry));
10000 g_object_notify (G_OBJECT (entry), "progress-pulse-step");
10005 * gtk_entry_get_progress_pulse_step:
10006 * @entry: a #GtkEntry
10008 * Retrieves the pulse step set with gtk_entry_set_progress_pulse_step().
10010 * Return value: a fraction from 0.0 to 1.0
10015 gtk_entry_get_progress_pulse_step (GtkEntry *entry)
10017 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
10019 return entry->priv->progress_pulse_fraction;
10023 * gtk_entry_progress_pulse:
10024 * @entry: a #GtkEntry
10026 * Indicates that some progress is made, but you don't know how much.
10027 * Causes the entry's progress indicator to enter "activity mode,"
10028 * where a block bounces back and forth. Each call to
10029 * gtk_entry_progress_pulse() causes the block to move by a little bit
10030 * (the amount of movement per pulse is determined by
10031 * gtk_entry_set_progress_pulse_step()).
10036 gtk_entry_progress_pulse (GtkEntry *entry)
10038 GtkEntryPrivate *private;
10040 g_return_if_fail (GTK_IS_ENTRY (entry));
10042 private = entry->priv;
10044 if (private->progress_pulse_mode)
10046 if (private->progress_pulse_way_back)
10048 private->progress_pulse_current -= private->progress_pulse_fraction;
10050 if (private->progress_pulse_current < 0.0)
10052 private->progress_pulse_current = 0.0;
10053 private->progress_pulse_way_back = FALSE;
10058 private->progress_pulse_current += private->progress_pulse_fraction;
10060 if (private->progress_pulse_current > 1.0 - private->progress_pulse_fraction)
10062 private->progress_pulse_current = 1.0 - private->progress_pulse_fraction;
10063 private->progress_pulse_way_back = TRUE;
10069 private->progress_fraction = 0.0;
10070 private->progress_pulse_mode = TRUE;
10071 private->progress_pulse_way_back = FALSE;
10072 private->progress_pulse_current = 0.0;
10075 gtk_widget_queue_draw (GTK_WIDGET (entry));
10079 * gtk_entry_set_placeholder_text:
10080 * @entry: a #GtkEntry
10081 * @text: a string to be displayed when @entry is empty an unfocused, or %NULL
10083 * Sets text to be displayed in @entry when it is empty and unfocused.
10084 * This can be used to give a visual hint of the expected contents of
10087 * Note that since the placeholder text gets removed when the entry
10088 * received focus, using this feature is a bit problematic if the entry
10089 * is given the initial focus in a window. Sometimes this can be
10090 * worked around by delaying the initial focus setting until the
10091 * first key event arrives.
10096 gtk_entry_set_placeholder_text (GtkEntry *entry,
10099 GtkEntryPrivate *priv;
10101 g_return_if_fail (GTK_IS_ENTRY (entry));
10103 priv = entry->priv;
10105 if (g_strcmp0 (priv->placeholder_text, text) == 0)
10108 g_free (priv->placeholder_text);
10109 priv->placeholder_text = g_strdup (text);
10111 gtk_entry_recompute (entry);
10113 g_object_notify (G_OBJECT (entry), "placeholder-text");
10117 * gtk_entry_get_placeholder_text:
10118 * @entry: a #GtkEntry
10120 * Retrieves the text that will be displayed when @entry is empty and unfocused
10122 * Returns: a pointer to the placeholder text as a string. This string points to internally allocated
10123 * storage in the widget and must not be freed, modified or stored.
10128 gtk_entry_get_placeholder_text (GtkEntry *entry)
10130 GtkEntryPrivate *priv;
10132 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
10134 priv = entry->priv;
10136 return priv->placeholder_text;
10139 /* Caps Lock warning for password entries */
10142 show_capslock_feedback (GtkEntry *entry,
10145 GtkEntryPrivate *priv = entry->priv;
10147 if (gtk_entry_get_icon_storage_type (entry, GTK_ENTRY_ICON_SECONDARY) == GTK_IMAGE_EMPTY)
10149 gtk_entry_set_icon_from_stock (entry, GTK_ENTRY_ICON_SECONDARY, GTK_STOCK_CAPS_LOCK_WARNING);
10150 gtk_entry_set_icon_activatable (entry, GTK_ENTRY_ICON_SECONDARY, FALSE);
10151 priv->caps_lock_warning_shown = TRUE;
10154 if (priv->caps_lock_warning_shown)
10155 gtk_entry_set_icon_tooltip_text (entry, GTK_ENTRY_ICON_SECONDARY, text);
10157 g_warning ("Can't show Caps Lock warning, since secondary icon is set");
10161 remove_capslock_feedback (GtkEntry *entry)
10163 GtkEntryPrivate *priv = entry->priv;
10165 if (priv->caps_lock_warning_shown)
10167 gtk_entry_set_icon_from_stock (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
10168 priv->caps_lock_warning_shown = FALSE;
10173 keymap_state_changed (GdkKeymap *keymap,
10176 GtkEntryPrivate *priv = entry->priv;
10179 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL && priv->caps_lock_warning)
10181 if (gdk_keymap_get_num_lock_state (keymap)
10182 && gdk_keymap_get_caps_lock_state (keymap))
10183 text = _("Caps Lock and Num Lock are on");
10184 else if (gdk_keymap_get_num_lock_state (keymap))
10185 text = _("Num Lock is on");
10186 else if (gdk_keymap_get_caps_lock_state (keymap))
10187 text = _("Caps Lock is on");
10191 show_capslock_feedback (entry, text);
10193 remove_capslock_feedback (entry);
10197 * _gtk_entry_set_is_cell_renderer:
10198 * @entry: a #GtkEntry
10199 * @is_cell_renderer: new value
10201 * This is a helper function for GtkComboBox. A GtkEntry in a GtkComboBox
10202 * is supposed to behave like a GtkCellEditable when placed in a combo box.
10204 * I.e take up its allocation and get GtkEntry->is_cell_renderer = TRUE.
10208 _gtk_entry_set_is_cell_renderer (GtkEntry *entry,
10209 gboolean is_cell_renderer)
10211 entry->priv->is_cell_renderer = is_cell_renderer;