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 "gdk/gdkkeysyms.h"
37 #include "gtkalignment.h"
38 #include "gtkbindings.h"
39 #include "gtkcelleditable.h"
40 #include "gtkclipboard.h"
43 #include "gtkentrybuffer.h"
44 #include "gtkimagemenuitem.h"
45 #include "gtkimcontextsimple.h"
46 #include "gtkimmulticontext.h"
50 #include "gtkmarshalers.h"
52 #include "gtkmenuitem.h"
53 #include "gtkseparatormenuitem.h"
54 #include "gtkselection.h"
55 #include "gtksettings.h"
56 #include "gtkspinbutton.h"
58 #include "gtktextutil.h"
59 #include "gtkwindow.h"
60 #include "gtktreeview.h"
61 #include "gtktreeselection.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"
72 * @Short_description: A single line text entry field
74 * @See_also: #GtkTextView, #GtkEntryCompletion
76 * The #GtkEntry widget is a single line text entry
77 * widget. A fairly large set of key bindings are supported
78 * by default. If the entered text is longer than the allocation
79 * of the widget, the widget will scroll so that the cursor
80 * position is visible.
82 * When using an entry for passwords and other sensitive information,
83 * it can be put into "password mode" using gtk_entry_set_visibility().
84 * In this mode, entered text is displayed using a 'invisible' character.
85 * By default, GTK+ picks the best invisible character that is available
86 * in the current font, but it can be changed with
87 * gtk_entry_set_invisible_char(). Since 2.16, GTK+ displays a warning
88 * when Caps Lock or input methods might interfere with entering text in
89 * a password entry. The warning can be turned off with the
90 * #GtkEntry:caps-lock-warning property.
92 * Since 2.16, GtkEntry has the ability to display progress or activity
93 * information behind the text. To make an entry display such information,
94 * use gtk_entry_set_progress_fraction() or gtk_entry_set_progress_pulse_step().
96 * Additionally, GtkEntry can show icons at either side of the entry. These
97 * icons can be activatable by clicking, can be set up as drag source and
98 * can have tooltips. To add an icon, use gtk_entry_set_icon_from_gicon() or
99 * one of the various other functions that set an icon from a stock id, an
100 * icon name or a pixbuf. To trigger an action when the user clicks an icon,
101 * connect to the #GtkEntry::icon-press signal. To allow DND operations
102 * from an icon, use gtk_entry_set_icon_drag_source(). To set a tooltip on
103 * an icon, use gtk_entry_set_icon_tooltip_text() or the corresponding function
106 * Note that functionality or information that is only available by clicking
107 * on an icon in an entry may not be accessible at all to users which are not
108 * able to use a mouse or other pointing device. It is therefore recommended
109 * that any such functionality should also be available by other means, e.g.
110 * via the context menu of the entry.
114 #define GTK_ENTRY_COMPLETION_KEY "gtk-entry-completion-key"
116 #define MIN_ENTRY_WIDTH 150
117 #define DRAW_TIMEOUT 20
118 #define COMPLETION_TIMEOUT 300
119 #define PASSWORD_HINT_MAX 8
123 #define IS_VALID_ICON_POSITION(pos) \
124 ((pos) == GTK_ENTRY_ICON_PRIMARY || \
125 (pos) == GTK_ENTRY_ICON_SECONDARY)
127 static const GtkBorder default_inner_border = { 2, 2, 2, 2 };
128 static GQuark quark_inner_border = 0;
129 static GQuark quark_password_hint = 0;
130 static GQuark quark_cursor_hadjustment = 0;
131 static GQuark quark_capslock_feedback = 0;
133 typedef struct _GtkEntryPrivate GtkEntryPrivate;
135 #define GTK_ENTRY_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_ENTRY, GtkEntryPrivate))
141 guint insensitive : 1;
142 guint nonactivatable : 1;
147 GtkImageType storage_type;
153 GtkTargetList *target_list;
154 GdkDragAction actions;
157 struct _GtkEntryPrivate
159 GtkEntryBuffer* buffer;
163 guint blink_time; /* time in msec the cursor has blinked since last user event */
164 guint interior_focus : 1;
165 guint real_changed : 1;
166 guint invisible_char_set : 1;
167 guint caps_lock_warning : 1;
168 guint caps_lock_warning_shown : 1;
169 guint change_count : 8;
170 guint progress_pulse_mode : 1;
171 guint progress_pulse_way_back : 1;
174 GtkShadowType shadow_type;
176 gdouble progress_fraction;
177 gdouble progress_pulse_fraction;
178 gdouble progress_pulse_current;
180 EntryIconInfo *icons[MAX_ICONS];
187 GdkDevice *completion_device;
190 typedef struct _GtkEntryPasswordHint GtkEntryPasswordHint;
192 struct _GtkEntryPasswordHint
194 gint position; /* Position (in text) of the last password hint */
195 guint source_id; /* Timeout source id */
198 typedef struct _GtkEntryCapslockFeedback GtkEntryCapslockFeedback;
200 struct _GtkEntryCapslockFeedback
227 PROP_CURSOR_POSITION,
228 PROP_SELECTION_BOUND,
235 PROP_ACTIVATES_DEFAULT,
240 PROP_TRUNCATE_MULTILINE,
244 PROP_INVISIBLE_CHAR_SET,
245 PROP_CAPS_LOCK_WARNING,
246 PROP_PROGRESS_FRACTION,
247 PROP_PROGRESS_PULSE_STEP,
249 PROP_PIXBUF_SECONDARY,
251 PROP_STOCK_SECONDARY,
252 PROP_ICON_NAME_PRIMARY,
253 PROP_ICON_NAME_SECONDARY,
255 PROP_GICON_SECONDARY,
256 PROP_STORAGE_TYPE_PRIMARY,
257 PROP_STORAGE_TYPE_SECONDARY,
258 PROP_ACTIVATABLE_PRIMARY,
259 PROP_ACTIVATABLE_SECONDARY,
260 PROP_SENSITIVE_PRIMARY,
261 PROP_SENSITIVE_SECONDARY,
262 PROP_TOOLTIP_TEXT_PRIMARY,
263 PROP_TOOLTIP_TEXT_SECONDARY,
264 PROP_TOOLTIP_MARKUP_PRIMARY,
265 PROP_TOOLTIP_MARKUP_SECONDARY,
267 PROP_EDITING_CANCELED
270 static guint signals[LAST_SIGNAL] = { 0 };
279 DISPLAY_NORMAL, /* The entry text is being shown */
280 DISPLAY_INVISIBLE, /* In invisible mode, text replaced by (eg) bullets */
281 DISPLAY_BLANK /* In invisible mode, nothing shown at all */
286 static void gtk_entry_editable_init (GtkEditableInterface *iface);
287 static void gtk_entry_cell_editable_init (GtkCellEditableIface *iface);
288 static void gtk_entry_set_property (GObject *object,
292 static void gtk_entry_get_property (GObject *object,
296 static void gtk_entry_finalize (GObject *object);
297 static void gtk_entry_dispose (GObject *object);
301 static void gtk_entry_destroy (GtkWidget *widget);
302 static void gtk_entry_realize (GtkWidget *widget);
303 static void gtk_entry_unrealize (GtkWidget *widget);
304 static void gtk_entry_map (GtkWidget *widget);
305 static void gtk_entry_unmap (GtkWidget *widget);
306 static void gtk_entry_get_preferred_width (GtkWidget *widget,
309 static void gtk_entry_get_preferred_height (GtkWidget *widget,
312 static void gtk_entry_size_allocate (GtkWidget *widget,
313 GtkAllocation *allocation);
314 static void gtk_entry_draw_frame (GtkWidget *widget,
316 static void gtk_entry_draw_progress (GtkWidget *widget,
318 static gint gtk_entry_draw (GtkWidget *widget,
320 static gint gtk_entry_button_press (GtkWidget *widget,
321 GdkEventButton *event);
322 static gint gtk_entry_button_release (GtkWidget *widget,
323 GdkEventButton *event);
324 static gint gtk_entry_enter_notify (GtkWidget *widget,
325 GdkEventCrossing *event);
326 static gint gtk_entry_leave_notify (GtkWidget *widget,
327 GdkEventCrossing *event);
328 static gint gtk_entry_motion_notify (GtkWidget *widget,
329 GdkEventMotion *event);
330 static gint gtk_entry_key_press (GtkWidget *widget,
332 static gint gtk_entry_key_release (GtkWidget *widget,
334 static gint gtk_entry_focus_in (GtkWidget *widget,
335 GdkEventFocus *event);
336 static gint gtk_entry_focus_out (GtkWidget *widget,
337 GdkEventFocus *event);
338 static void gtk_entry_grab_focus (GtkWidget *widget);
339 static void gtk_entry_style_set (GtkWidget *widget,
340 GtkStyle *previous_style);
341 static gboolean gtk_entry_query_tooltip (GtkWidget *widget,
344 gboolean keyboard_tip,
345 GtkTooltip *tooltip);
346 static void gtk_entry_direction_changed (GtkWidget *widget,
347 GtkTextDirection previous_dir);
348 static void gtk_entry_state_changed (GtkWidget *widget,
349 GtkStateType previous_state);
350 static void gtk_entry_screen_changed (GtkWidget *widget,
351 GdkScreen *old_screen);
353 static gboolean gtk_entry_drag_drop (GtkWidget *widget,
354 GdkDragContext *context,
358 static gboolean gtk_entry_drag_motion (GtkWidget *widget,
359 GdkDragContext *context,
363 static void gtk_entry_drag_leave (GtkWidget *widget,
364 GdkDragContext *context,
366 static void gtk_entry_drag_data_received (GtkWidget *widget,
367 GdkDragContext *context,
370 GtkSelectionData *selection_data,
373 static void gtk_entry_drag_data_get (GtkWidget *widget,
374 GdkDragContext *context,
375 GtkSelectionData *selection_data,
378 static void gtk_entry_drag_data_delete (GtkWidget *widget,
379 GdkDragContext *context);
380 static void gtk_entry_drag_begin (GtkWidget *widget,
381 GdkDragContext *context);
382 static void gtk_entry_drag_end (GtkWidget *widget,
383 GdkDragContext *context);
386 /* GtkEditable method implementations
388 static void gtk_entry_insert_text (GtkEditable *editable,
389 const gchar *new_text,
390 gint new_text_length,
392 static void gtk_entry_delete_text (GtkEditable *editable,
395 static gchar * gtk_entry_get_chars (GtkEditable *editable,
398 static void gtk_entry_real_set_position (GtkEditable *editable,
400 static gint gtk_entry_get_position (GtkEditable *editable);
401 static void gtk_entry_set_selection_bounds (GtkEditable *editable,
404 static gboolean gtk_entry_get_selection_bounds (GtkEditable *editable,
408 /* GtkCellEditable method implementations
410 static void gtk_entry_start_editing (GtkCellEditable *cell_editable,
413 /* Default signal handlers
415 static void gtk_entry_real_insert_text (GtkEditable *editable,
416 const gchar *new_text,
417 gint new_text_length,
419 static void gtk_entry_real_delete_text (GtkEditable *editable,
422 static void gtk_entry_move_cursor (GtkEntry *entry,
423 GtkMovementStep step,
425 gboolean extend_selection);
426 static void gtk_entry_insert_at_cursor (GtkEntry *entry,
428 static void gtk_entry_delete_from_cursor (GtkEntry *entry,
431 static void gtk_entry_backspace (GtkEntry *entry);
432 static void gtk_entry_cut_clipboard (GtkEntry *entry);
433 static void gtk_entry_copy_clipboard (GtkEntry *entry);
434 static void gtk_entry_paste_clipboard (GtkEntry *entry);
435 static void gtk_entry_toggle_overwrite (GtkEntry *entry);
436 static void gtk_entry_select_all (GtkEntry *entry);
437 static void gtk_entry_real_activate (GtkEntry *entry);
438 static gboolean gtk_entry_popup_menu (GtkWidget *widget);
440 static void keymap_direction_changed (GdkKeymap *keymap,
442 static void keymap_state_changed (GdkKeymap *keymap,
444 static void remove_capslock_feedback (GtkEntry *entry);
446 /* IM Context Callbacks
448 static void gtk_entry_commit_cb (GtkIMContext *context,
451 static void gtk_entry_preedit_changed_cb (GtkIMContext *context,
453 static gboolean gtk_entry_retrieve_surrounding_cb (GtkIMContext *context,
455 static gboolean gtk_entry_delete_surrounding_cb (GtkIMContext *context,
462 static void gtk_entry_enter_text (GtkEntry *entry,
464 static void gtk_entry_set_positions (GtkEntry *entry,
466 gint selection_bound);
467 static void gtk_entry_draw_text (GtkEntry *entry,
469 static void gtk_entry_draw_cursor (GtkEntry *entry,
472 static PangoLayout *gtk_entry_ensure_layout (GtkEntry *entry,
473 gboolean include_preedit);
474 static void gtk_entry_reset_layout (GtkEntry *entry);
475 static void gtk_entry_queue_draw (GtkEntry *entry);
476 static void gtk_entry_recompute (GtkEntry *entry);
477 static gint gtk_entry_find_position (GtkEntry *entry,
479 static void gtk_entry_get_cursor_locations (GtkEntry *entry,
483 static void gtk_entry_adjust_scroll (GtkEntry *entry);
484 static gint gtk_entry_move_visually (GtkEntry *editable,
487 static gint gtk_entry_move_logically (GtkEntry *entry,
490 static gint gtk_entry_move_forward_word (GtkEntry *entry,
492 gboolean allow_whitespace);
493 static gint gtk_entry_move_backward_word (GtkEntry *entry,
495 gboolean allow_whitespace);
496 static void gtk_entry_delete_whitespace (GtkEntry *entry);
497 static void gtk_entry_select_word (GtkEntry *entry);
498 static void gtk_entry_select_line (GtkEntry *entry);
499 static void gtk_entry_paste (GtkEntry *entry,
501 static void gtk_entry_update_primary_selection (GtkEntry *entry);
502 static void gtk_entry_do_popup (GtkEntry *entry,
503 GdkEventButton *event);
504 static gboolean gtk_entry_mnemonic_activate (GtkWidget *widget,
505 gboolean group_cycling);
506 static void gtk_entry_check_cursor_blink (GtkEntry *entry);
507 static void gtk_entry_pend_cursor_blink (GtkEntry *entry);
508 static void gtk_entry_reset_blink_time (GtkEntry *entry);
509 static void gtk_entry_get_text_area_size (GtkEntry *entry,
514 static void get_text_area_size (GtkEntry *entry,
519 static void get_frame_size (GtkEntry *entry,
524 static void gtk_entry_move_adjustments (GtkEntry *entry);
525 static void gtk_entry_ensure_pixbuf (GtkEntry *entry,
526 GtkEntryIconPosition icon_pos);
530 static gint gtk_entry_completion_timeout (gpointer data);
531 static gboolean gtk_entry_completion_key_press (GtkWidget *widget,
534 static void gtk_entry_completion_changed (GtkWidget *entry,
536 static gboolean check_completion_callback (GtkEntryCompletion *completion);
537 static void clear_completion_callback (GtkEntry *entry,
539 static gboolean accept_completion_callback (GtkEntry *entry);
540 static void completion_insert_text_callback (GtkEntry *entry,
544 GtkEntryCompletion *completion);
545 static void completion_changed (GtkEntryCompletion *completion,
548 static void disconnect_completion_signals (GtkEntry *entry,
549 GtkEntryCompletion *completion);
550 static void connect_completion_signals (GtkEntry *entry,
551 GtkEntryCompletion *completion);
553 static void begin_change (GtkEntry *entry);
554 static void end_change (GtkEntry *entry);
555 static void emit_changed (GtkEntry *entry);
558 static void buffer_inserted_text (GtkEntryBuffer *buffer,
563 static void buffer_deleted_text (GtkEntryBuffer *buffer,
567 static void buffer_notify_text (GtkEntryBuffer *buffer,
570 static void buffer_notify_length (GtkEntryBuffer *buffer,
573 static void buffer_notify_max_length (GtkEntryBuffer *buffer,
576 static void buffer_connect_signals (GtkEntry *entry);
577 static void buffer_disconnect_signals (GtkEntry *entry);
578 static GtkEntryBuffer *get_buffer (GtkEntry *entry);
581 G_DEFINE_TYPE_WITH_CODE (GtkEntry, gtk_entry, GTK_TYPE_WIDGET,
582 G_IMPLEMENT_INTERFACE (GTK_TYPE_EDITABLE,
583 gtk_entry_editable_init)
584 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_EDITABLE,
585 gtk_entry_cell_editable_init))
588 add_move_binding (GtkBindingSet *binding_set,
591 GtkMovementStep step,
594 g_return_if_fail ((modmask & GDK_SHIFT_MASK) == 0);
596 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
600 G_TYPE_BOOLEAN, FALSE);
602 /* Selection-extending version */
603 gtk_binding_entry_add_signal (binding_set, keyval, modmask | GDK_SHIFT_MASK,
607 G_TYPE_BOOLEAN, TRUE);
611 gtk_entry_class_init (GtkEntryClass *class)
613 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
614 GtkWidgetClass *widget_class;
615 GtkBindingSet *binding_set;
617 widget_class = (GtkWidgetClass*) class;
619 gobject_class->dispose = gtk_entry_dispose;
620 gobject_class->finalize = gtk_entry_finalize;
621 gobject_class->set_property = gtk_entry_set_property;
622 gobject_class->get_property = gtk_entry_get_property;
624 widget_class->destroy = gtk_entry_destroy;
625 widget_class->map = gtk_entry_map;
626 widget_class->unmap = gtk_entry_unmap;
627 widget_class->realize = gtk_entry_realize;
628 widget_class->unrealize = gtk_entry_unrealize;
629 widget_class->get_preferred_width = gtk_entry_get_preferred_width;
630 widget_class->get_preferred_height = gtk_entry_get_preferred_height;
631 widget_class->size_allocate = gtk_entry_size_allocate;
632 widget_class->draw = gtk_entry_draw;
633 widget_class->enter_notify_event = gtk_entry_enter_notify;
634 widget_class->leave_notify_event = gtk_entry_leave_notify;
635 widget_class->button_press_event = gtk_entry_button_press;
636 widget_class->button_release_event = gtk_entry_button_release;
637 widget_class->motion_notify_event = gtk_entry_motion_notify;
638 widget_class->key_press_event = gtk_entry_key_press;
639 widget_class->key_release_event = gtk_entry_key_release;
640 widget_class->focus_in_event = gtk_entry_focus_in;
641 widget_class->focus_out_event = gtk_entry_focus_out;
642 widget_class->grab_focus = gtk_entry_grab_focus;
643 widget_class->style_set = gtk_entry_style_set;
644 widget_class->query_tooltip = gtk_entry_query_tooltip;
645 widget_class->drag_begin = gtk_entry_drag_begin;
646 widget_class->drag_end = gtk_entry_drag_end;
647 widget_class->direction_changed = gtk_entry_direction_changed;
648 widget_class->state_changed = gtk_entry_state_changed;
649 widget_class->screen_changed = gtk_entry_screen_changed;
650 widget_class->mnemonic_activate = gtk_entry_mnemonic_activate;
652 widget_class->drag_drop = gtk_entry_drag_drop;
653 widget_class->drag_motion = gtk_entry_drag_motion;
654 widget_class->drag_leave = gtk_entry_drag_leave;
655 widget_class->drag_data_received = gtk_entry_drag_data_received;
656 widget_class->drag_data_get = gtk_entry_drag_data_get;
657 widget_class->drag_data_delete = gtk_entry_drag_data_delete;
659 widget_class->popup_menu = gtk_entry_popup_menu;
661 class->move_cursor = gtk_entry_move_cursor;
662 class->insert_at_cursor = gtk_entry_insert_at_cursor;
663 class->delete_from_cursor = gtk_entry_delete_from_cursor;
664 class->backspace = gtk_entry_backspace;
665 class->cut_clipboard = gtk_entry_cut_clipboard;
666 class->copy_clipboard = gtk_entry_copy_clipboard;
667 class->paste_clipboard = gtk_entry_paste_clipboard;
668 class->toggle_overwrite = gtk_entry_toggle_overwrite;
669 class->activate = gtk_entry_real_activate;
670 class->get_text_area_size = gtk_entry_get_text_area_size;
672 quark_inner_border = g_quark_from_static_string ("gtk-entry-inner-border");
673 quark_password_hint = g_quark_from_static_string ("gtk-entry-password-hint");
674 quark_cursor_hadjustment = g_quark_from_static_string ("gtk-hadjustment");
675 quark_capslock_feedback = g_quark_from_static_string ("gtk-entry-capslock-feedback");
677 g_object_class_override_property (gobject_class,
678 PROP_EDITING_CANCELED,
681 g_object_class_install_property (gobject_class,
683 g_param_spec_object ("buffer",
685 P_("Text buffer object which actually stores entry text"),
686 GTK_TYPE_ENTRY_BUFFER,
687 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT));
689 g_object_class_install_property (gobject_class,
690 PROP_CURSOR_POSITION,
691 g_param_spec_int ("cursor-position",
692 P_("Cursor Position"),
693 P_("The current position of the insertion cursor in chars"),
695 GTK_ENTRY_BUFFER_MAX_SIZE,
697 GTK_PARAM_READABLE));
699 g_object_class_install_property (gobject_class,
700 PROP_SELECTION_BOUND,
701 g_param_spec_int ("selection-bound",
702 P_("Selection Bound"),
703 P_("The position of the opposite end of the selection from the cursor in chars"),
705 GTK_ENTRY_BUFFER_MAX_SIZE,
707 GTK_PARAM_READABLE));
709 g_object_class_install_property (gobject_class,
711 g_param_spec_boolean ("editable",
713 P_("Whether the entry contents can be edited"),
715 GTK_PARAM_READWRITE));
717 g_object_class_install_property (gobject_class,
719 g_param_spec_int ("max-length",
720 P_("Maximum length"),
721 P_("Maximum number of characters for this entry. Zero if no maximum"),
723 GTK_ENTRY_BUFFER_MAX_SIZE,
725 GTK_PARAM_READWRITE));
726 g_object_class_install_property (gobject_class,
728 g_param_spec_boolean ("visibility",
730 P_("FALSE displays the \"invisible char\" instead of the actual text (password mode)"),
732 GTK_PARAM_READWRITE));
734 g_object_class_install_property (gobject_class,
736 g_param_spec_boolean ("has-frame",
738 P_("FALSE removes outside bevel from entry"),
740 GTK_PARAM_READWRITE));
742 g_object_class_install_property (gobject_class,
744 g_param_spec_boxed ("inner-border",
746 P_("Border between text and frame. Overrides the inner-border style property"),
748 GTK_PARAM_READWRITE));
750 g_object_class_install_property (gobject_class,
752 g_param_spec_unichar ("invisible-char",
753 P_("Invisible character"),
754 P_("The character to use when masking entry contents (in \"password mode\")"),
756 GTK_PARAM_READWRITE));
758 g_object_class_install_property (gobject_class,
759 PROP_ACTIVATES_DEFAULT,
760 g_param_spec_boolean ("activates-default",
761 P_("Activates default"),
762 P_("Whether to activate the default widget (such as the default button in a dialog) when Enter is pressed"),
764 GTK_PARAM_READWRITE));
765 g_object_class_install_property (gobject_class,
767 g_param_spec_int ("width-chars",
768 P_("Width in chars"),
769 P_("Number of characters to leave space for in the entry"),
773 GTK_PARAM_READWRITE));
775 g_object_class_install_property (gobject_class,
777 g_param_spec_int ("scroll-offset",
779 P_("Number of pixels of the entry scrolled off the screen to the left"),
783 GTK_PARAM_READABLE));
785 g_object_class_install_property (gobject_class,
787 g_param_spec_string ("text",
789 P_("The contents of the entry"),
791 GTK_PARAM_READWRITE));
796 * The horizontal alignment, from 0 (left) to 1 (right).
797 * Reversed for RTL layouts.
801 g_object_class_install_property (gobject_class,
803 g_param_spec_float ("xalign",
805 P_("The horizontal alignment, from 0 (left) to 1 (right). Reversed for RTL layouts."),
809 GTK_PARAM_READWRITE));
812 * GtkEntry:truncate-multiline:
814 * When %TRUE, pasted multi-line text is truncated to the first line.
818 g_object_class_install_property (gobject_class,
819 PROP_TRUNCATE_MULTILINE,
820 g_param_spec_boolean ("truncate-multiline",
821 P_("Truncate multiline"),
822 P_("Whether to truncate multiline pastes to one line."),
824 GTK_PARAM_READWRITE));
827 * GtkEntry:shadow-type:
829 * Which kind of shadow to draw around the entry when
830 * #GtkEntry:has-frame is set to %TRUE.
834 g_object_class_install_property (gobject_class,
836 g_param_spec_enum ("shadow-type",
838 P_("Which kind of shadow to draw around the entry when has-frame is set"),
839 GTK_TYPE_SHADOW_TYPE,
841 GTK_PARAM_READWRITE));
844 * GtkEntry:overwrite-mode:
846 * If text is overwritten when typing in the #GtkEntry.
850 g_object_class_install_property (gobject_class,
852 g_param_spec_boolean ("overwrite-mode",
853 P_("Overwrite mode"),
854 P_("Whether new text overwrites existing text"),
856 GTK_PARAM_READWRITE));
859 * GtkEntry:text-length:
861 * The length of the text in the #GtkEntry.
865 g_object_class_install_property (gobject_class,
867 g_param_spec_uint ("text-length",
869 P_("Length of the text currently in the entry"),
873 GTK_PARAM_READABLE));
875 * GtkEntry:invisible-char-set:
877 * Whether the invisible char has been set for the #GtkEntry.
881 g_object_class_install_property (gobject_class,
882 PROP_INVISIBLE_CHAR_SET,
883 g_param_spec_boolean ("invisible-char-set",
884 P_("Invisible character set"),
885 P_("Whether the invisible character has been set"),
887 GTK_PARAM_READWRITE));
890 * GtkEntry:caps-lock-warning
892 * Whether password entries will show a warning when Caps Lock is on.
894 * Note that the warning is shown using a secondary icon, and thus
895 * does not work if you are using the secondary icon position for some
900 g_object_class_install_property (gobject_class,
901 PROP_CAPS_LOCK_WARNING,
902 g_param_spec_boolean ("caps-lock-warning",
903 P_("Caps Lock warning"),
904 P_("Whether password entries will show a warning when Caps Lock is on"),
906 GTK_PARAM_READWRITE));
909 * GtkEntry:progress-fraction:
911 * The current fraction of the task that's been completed.
915 g_object_class_install_property (gobject_class,
916 PROP_PROGRESS_FRACTION,
917 g_param_spec_double ("progress-fraction",
918 P_("Progress Fraction"),
919 P_("The current fraction of the task that's been completed"),
923 GTK_PARAM_READWRITE));
926 * GtkEntry:progress-pulse-step:
928 * The fraction of total entry width to move the progress
929 * bouncing block for each call to gtk_entry_progress_pulse().
933 g_object_class_install_property (gobject_class,
934 PROP_PROGRESS_PULSE_STEP,
935 g_param_spec_double ("progress-pulse-step",
936 P_("Progress Pulse Step"),
937 P_("The fraction of total entry width to move the progress bouncing block for each call to gtk_entry_progress_pulse()"),
941 GTK_PARAM_READWRITE));
944 * GtkEntry:primary-icon-pixbuf:
946 * A pixbuf to use as the primary icon for the entry.
950 g_object_class_install_property (gobject_class,
952 g_param_spec_object ("primary-icon-pixbuf",
953 P_("Primary pixbuf"),
954 P_("Primary pixbuf for the entry"),
956 GTK_PARAM_READWRITE));
959 * GtkEntry:secondary-icon-pixbuf:
961 * An pixbuf to use as the secondary icon for the entry.
965 g_object_class_install_property (gobject_class,
966 PROP_PIXBUF_SECONDARY,
967 g_param_spec_object ("secondary-icon-pixbuf",
968 P_("Secondary pixbuf"),
969 P_("Secondary pixbuf for the entry"),
971 GTK_PARAM_READWRITE));
974 * GtkEntry:primary-icon-stock:
976 * The stock id to use for the primary icon for the entry.
980 g_object_class_install_property (gobject_class,
982 g_param_spec_string ("primary-icon-stock",
983 P_("Primary stock ID"),
984 P_("Stock ID for primary icon"),
986 GTK_PARAM_READWRITE));
989 * GtkEntry:secondary-icon-stock:
991 * The stock id to use for the secondary icon for the entry.
995 g_object_class_install_property (gobject_class,
996 PROP_STOCK_SECONDARY,
997 g_param_spec_string ("secondary-icon-stock",
998 P_("Secondary stock ID"),
999 P_("Stock ID for secondary icon"),
1001 GTK_PARAM_READWRITE));
1004 * GtkEntry:primary-icon-name:
1006 * The icon name to use for the primary icon for the entry.
1010 g_object_class_install_property (gobject_class,
1011 PROP_ICON_NAME_PRIMARY,
1012 g_param_spec_string ("primary-icon-name",
1013 P_("Primary icon name"),
1014 P_("Icon name for primary icon"),
1016 GTK_PARAM_READWRITE));
1019 * GtkEntry:secondary-icon-name:
1021 * The icon name to use for the secondary icon for the entry.
1025 g_object_class_install_property (gobject_class,
1026 PROP_ICON_NAME_SECONDARY,
1027 g_param_spec_string ("secondary-icon-name",
1028 P_("Secondary icon name"),
1029 P_("Icon name for secondary icon"),
1031 GTK_PARAM_READWRITE));
1034 * GtkEntry:primary-icon-gicon:
1036 * The #GIcon to use for the primary icon for the entry.
1040 g_object_class_install_property (gobject_class,
1042 g_param_spec_object ("primary-icon-gicon",
1043 P_("Primary GIcon"),
1044 P_("GIcon for primary icon"),
1046 GTK_PARAM_READWRITE));
1049 * GtkEntry:secondary-icon-gicon:
1051 * The #GIcon to use for the secondary icon for the entry.
1055 g_object_class_install_property (gobject_class,
1056 PROP_GICON_SECONDARY,
1057 g_param_spec_object ("secondary-icon-gicon",
1058 P_("Secondary GIcon"),
1059 P_("GIcon for secondary icon"),
1061 GTK_PARAM_READWRITE));
1064 * GtkEntry:primary-icon-storage-type:
1066 * The representation which is used for the primary icon of the entry.
1070 g_object_class_install_property (gobject_class,
1071 PROP_STORAGE_TYPE_PRIMARY,
1072 g_param_spec_enum ("primary-icon-storage-type",
1073 P_("Primary storage type"),
1074 P_("The representation being used for primary icon"),
1075 GTK_TYPE_IMAGE_TYPE,
1077 GTK_PARAM_READABLE));
1080 * GtkEntry:secondary-icon-storage-type:
1082 * The representation which is used for the secondary icon of the entry.
1086 g_object_class_install_property (gobject_class,
1087 PROP_STORAGE_TYPE_SECONDARY,
1088 g_param_spec_enum ("secondary-icon-storage-type",
1089 P_("Secondary storage type"),
1090 P_("The representation being used for secondary icon"),
1091 GTK_TYPE_IMAGE_TYPE,
1093 GTK_PARAM_READABLE));
1096 * GtkEntry:primary-icon-activatable:
1098 * Whether the primary icon is activatable.
1100 * GTK+ emits the #GtkEntry::icon-press and #GtkEntry::icon-release
1101 * signals only on sensitive, activatable icons.
1103 * Sensitive, but non-activatable icons can be used for purely
1104 * informational purposes.
1108 g_object_class_install_property (gobject_class,
1109 PROP_ACTIVATABLE_PRIMARY,
1110 g_param_spec_boolean ("primary-icon-activatable",
1111 P_("Primary icon activatable"),
1112 P_("Whether the primary icon is activatable"),
1114 GTK_PARAM_READWRITE));
1117 * GtkEntry:secondary-icon-activatable:
1119 * Whether the secondary icon is activatable.
1121 * GTK+ emits the #GtkEntry::icon-press and #GtkEntry::icon-release
1122 * signals only on sensitive, activatable icons.
1124 * Sensitive, but non-activatable icons can be used for purely
1125 * informational purposes.
1129 g_object_class_install_property (gobject_class,
1130 PROP_ACTIVATABLE_SECONDARY,
1131 g_param_spec_boolean ("secondary-icon-activatable",
1132 P_("Secondary icon activatable"),
1133 P_("Whether the secondary icon is activatable"),
1135 GTK_PARAM_READWRITE));
1139 * GtkEntry:primary-icon-sensitive:
1141 * Whether the primary icon is sensitive.
1143 * An insensitive icon appears grayed out. GTK+ does not emit the
1144 * #GtkEntry::icon-press and #GtkEntry::icon-release signals and
1145 * does not allow DND from insensitive icons.
1147 * An icon should be set insensitive if the action that would trigger
1148 * when clicked is currently not available.
1152 g_object_class_install_property (gobject_class,
1153 PROP_SENSITIVE_PRIMARY,
1154 g_param_spec_boolean ("primary-icon-sensitive",
1155 P_("Primary icon sensitive"),
1156 P_("Whether the primary icon is sensitive"),
1158 GTK_PARAM_READWRITE));
1161 * GtkEntry:secondary-icon-sensitive:
1163 * Whether the secondary icon is sensitive.
1165 * An insensitive icon appears grayed out. GTK+ does not emit the
1166 * #GtkEntry::icon-press and #GtkEntry::icon-release signals and
1167 * does not allow DND from insensitive icons.
1169 * An icon should be set insensitive if the action that would trigger
1170 * when clicked is currently not available.
1174 g_object_class_install_property (gobject_class,
1175 PROP_SENSITIVE_SECONDARY,
1176 g_param_spec_boolean ("secondary-icon-sensitive",
1177 P_("Secondary icon sensitive"),
1178 P_("Whether the secondary icon is sensitive"),
1180 GTK_PARAM_READWRITE));
1183 * GtkEntry:primary-icon-tooltip-text:
1185 * The contents of the tooltip on the primary icon.
1187 * Also see gtk_entry_set_icon_tooltip_text().
1191 g_object_class_install_property (gobject_class,
1192 PROP_TOOLTIP_TEXT_PRIMARY,
1193 g_param_spec_string ("primary-icon-tooltip-text",
1194 P_("Primary icon tooltip text"),
1195 P_("The contents of the tooltip on the primary icon"),
1197 GTK_PARAM_READWRITE));
1200 * GtkEntry:secondary-icon-tooltip-text:
1202 * The contents of the tooltip on the secondary icon.
1204 * Also see gtk_entry_set_icon_tooltip_text().
1208 g_object_class_install_property (gobject_class,
1209 PROP_TOOLTIP_TEXT_SECONDARY,
1210 g_param_spec_string ("secondary-icon-tooltip-text",
1211 P_("Secondary icon tooltip text"),
1212 P_("The contents of the tooltip on the secondary icon"),
1214 GTK_PARAM_READWRITE));
1217 * GtkEntry:primary-icon-tooltip-markup:
1219 * The contents of the tooltip on the primary icon, which is marked up
1220 * with the <link linkend="PangoMarkupFormat">Pango text markup
1223 * Also see gtk_entry_set_icon_tooltip_markup().
1227 g_object_class_install_property (gobject_class,
1228 PROP_TOOLTIP_MARKUP_PRIMARY,
1229 g_param_spec_string ("primary-icon-tooltip-markup",
1230 P_("Primary icon tooltip markup"),
1231 P_("The contents of the tooltip on the primary icon"),
1233 GTK_PARAM_READWRITE));
1236 * GtkEntry:secondary-icon-tooltip-markup:
1238 * The contents of the tooltip on the secondary icon, which is marked up
1239 * with the <link linkend="PangoMarkupFormat">Pango text markup
1242 * Also see gtk_entry_set_icon_tooltip_markup().
1246 g_object_class_install_property (gobject_class,
1247 PROP_TOOLTIP_MARKUP_SECONDARY,
1248 g_param_spec_string ("secondary-icon-tooltip-markup",
1249 P_("Secondary icon tooltip markup"),
1250 P_("The contents of the tooltip on the secondary icon"),
1252 GTK_PARAM_READWRITE));
1255 * GtkEntry:im-module:
1257 * Which IM (input method) module should be used for this entry.
1258 * See #GtkIMContext.
1260 * Setting this to a non-%NULL value overrides the
1261 * system-wide IM module setting. See the GtkSettings
1262 * #GtkSettings:gtk-im-module property.
1266 g_object_class_install_property (gobject_class,
1268 g_param_spec_string ("im-module",
1270 P_("Which IM module should be used"),
1272 GTK_PARAM_READWRITE));
1275 * GtkEntry:icon-prelight:
1277 * The prelight style property determines whether activatable
1278 * icons prelight on mouseover.
1282 gtk_widget_class_install_style_property (widget_class,
1283 g_param_spec_boolean ("icon-prelight",
1284 P_("Icon Prelight"),
1285 P_("Whether activatable icons should prelight when hovered"),
1287 GTK_PARAM_READABLE));
1290 * GtkEntry:progress-border:
1292 * The border around the progress bar in the entry.
1296 gtk_widget_class_install_style_property (widget_class,
1297 g_param_spec_boxed ("progress-border",
1298 P_("Progress Border"),
1299 P_("Border around the progress bar"),
1301 GTK_PARAM_READABLE));
1304 * GtkEntry:invisible-char:
1306 * The invisible character is used when masking entry contents (in
1307 * \"password mode\")"). When it is not explicitly set with the
1308 * #GtkEntry::invisible-char property, GTK+ determines the character
1309 * to use from a list of possible candidates, depending on availability
1310 * in the current font.
1312 * This style property allows the theme to prepend a character
1313 * to the list of candidates.
1317 gtk_widget_class_install_style_property (widget_class,
1318 g_param_spec_unichar ("invisible-char",
1319 P_("Invisible character"),
1320 P_("The character to use when masking entry contents (in \"password mode\")"),
1322 GTK_PARAM_READABLE));
1325 * GtkEntry::populate-popup:
1326 * @entry: The entry on which the signal is emitted
1327 * @menu: the menu that is being populated
1329 * The ::populate-popup signal gets emitted before showing the
1330 * context menu of the entry.
1332 * If you need to add items to the context menu, connect
1333 * to this signal and append your menuitems to the @menu.
1335 signals[POPULATE_POPUP] =
1336 g_signal_new (I_("populate-popup"),
1337 G_OBJECT_CLASS_TYPE (gobject_class),
1339 G_STRUCT_OFFSET (GtkEntryClass, populate_popup),
1341 _gtk_marshal_VOID__OBJECT,
1345 /* Action signals */
1348 * GtkEntry::activate:
1349 * @entry: The entry on which the signal is emitted
1351 * A <link linkend="keybinding-signals">keybinding signal</link>
1352 * which gets emitted when the user activates the entry.
1354 * Applications should not connect to it, but may emit it with
1355 * g_signal_emit_by_name() if they need to control activation
1358 * The default bindings for this signal are all forms of the Enter key.
1361 g_signal_new (I_("activate"),
1362 G_OBJECT_CLASS_TYPE (gobject_class),
1363 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1364 G_STRUCT_OFFSET (GtkEntryClass, activate),
1366 _gtk_marshal_VOID__VOID,
1368 widget_class->activate_signal = signals[ACTIVATE];
1371 * GtkEntry::move-cursor:
1372 * @entry: the object which received the signal
1373 * @step: the granularity of the move, as a #GtkMovementStep
1374 * @count: the number of @step units to move
1375 * @extend_selection: %TRUE if the move should extend the selection
1377 * The ::move-cursor signal is a
1378 * <link linkend="keybinding-signals">keybinding signal</link>
1379 * which gets emitted when the user initiates a cursor movement.
1380 * If the cursor is not visible in @entry, this signal causes
1381 * the viewport to be moved instead.
1383 * Applications should not connect to it, but may emit it with
1384 * g_signal_emit_by_name() if they need to control the cursor
1387 * The default bindings for this signal come in two variants,
1388 * the variant with the Shift modifier extends the selection,
1389 * the variant without the Shift modifer does not.
1390 * There are too many key combinations to list them all here.
1392 * <listitem>Arrow keys move by individual characters/lines</listitem>
1393 * <listitem>Ctrl-arrow key combinations move by words/paragraphs</listitem>
1394 * <listitem>Home/End keys move to the ends of the buffer</listitem>
1397 signals[MOVE_CURSOR] =
1398 g_signal_new (I_("move-cursor"),
1399 G_OBJECT_CLASS_TYPE (gobject_class),
1400 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1401 G_STRUCT_OFFSET (GtkEntryClass, move_cursor),
1403 _gtk_marshal_VOID__ENUM_INT_BOOLEAN,
1405 GTK_TYPE_MOVEMENT_STEP,
1410 * GtkEntry::insert-at-cursor:
1411 * @entry: the object which received the signal
1412 * @string: the string to insert
1414 * The ::insert-at-cursor signal is a
1415 * <link linkend="keybinding-signals">keybinding signal</link>
1416 * which gets emitted when the user initiates the insertion of a
1417 * fixed string at the cursor.
1419 * This signal has no default bindings.
1421 signals[INSERT_AT_CURSOR] =
1422 g_signal_new (I_("insert-at-cursor"),
1423 G_OBJECT_CLASS_TYPE (gobject_class),
1424 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1425 G_STRUCT_OFFSET (GtkEntryClass, insert_at_cursor),
1427 _gtk_marshal_VOID__STRING,
1432 * GtkEntry::delete-from-cursor:
1433 * @entry: the object which received the signal
1434 * @type: the granularity of the deletion, as a #GtkDeleteType
1435 * @count: the number of @type units to delete
1437 * The ::delete-from-cursor signal is a
1438 * <link linkend="keybinding-signals">keybinding signal</link>
1439 * which gets emitted when the user initiates a text deletion.
1441 * If the @type is %GTK_DELETE_CHARS, GTK+ deletes the selection
1442 * if there is one, otherwise it deletes the requested number
1445 * The default bindings for this signal are
1446 * Delete for deleting a character and Ctrl-Delete for
1449 signals[DELETE_FROM_CURSOR] =
1450 g_signal_new (I_("delete-from-cursor"),
1451 G_OBJECT_CLASS_TYPE (gobject_class),
1452 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1453 G_STRUCT_OFFSET (GtkEntryClass, delete_from_cursor),
1455 _gtk_marshal_VOID__ENUM_INT,
1457 GTK_TYPE_DELETE_TYPE,
1461 * GtkEntry::backspace:
1462 * @entry: the object which received the signal
1464 * The ::backspace signal is a
1465 * <link linkend="keybinding-signals">keybinding signal</link>
1466 * which gets emitted when the user asks for it.
1468 * The default bindings for this signal are
1469 * Backspace and Shift-Backspace.
1471 signals[BACKSPACE] =
1472 g_signal_new (I_("backspace"),
1473 G_OBJECT_CLASS_TYPE (gobject_class),
1474 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1475 G_STRUCT_OFFSET (GtkEntryClass, backspace),
1477 _gtk_marshal_VOID__VOID,
1481 * GtkEntry::cut-clipboard:
1482 * @entry: the object which received the signal
1484 * The ::cut-clipboard signal is a
1485 * <link linkend="keybinding-signals">keybinding signal</link>
1486 * which gets emitted to cut the selection to the clipboard.
1488 * The default bindings for this signal are
1489 * Ctrl-x and Shift-Delete.
1491 signals[CUT_CLIPBOARD] =
1492 g_signal_new (I_("cut-clipboard"),
1493 G_OBJECT_CLASS_TYPE (gobject_class),
1494 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1495 G_STRUCT_OFFSET (GtkEntryClass, cut_clipboard),
1497 _gtk_marshal_VOID__VOID,
1501 * GtkEntry::copy-clipboard:
1502 * @entry: the object which received the signal
1504 * The ::copy-clipboard signal is a
1505 * <link linkend="keybinding-signals">keybinding signal</link>
1506 * which gets emitted to copy the selection to the clipboard.
1508 * The default bindings for this signal are
1509 * Ctrl-c and Ctrl-Insert.
1511 signals[COPY_CLIPBOARD] =
1512 g_signal_new (I_("copy-clipboard"),
1513 G_OBJECT_CLASS_TYPE (gobject_class),
1514 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1515 G_STRUCT_OFFSET (GtkEntryClass, copy_clipboard),
1517 _gtk_marshal_VOID__VOID,
1521 * GtkEntry::paste-clipboard:
1522 * @entry: the object which received the signal
1524 * The ::paste-clipboard signal is a
1525 * <link linkend="keybinding-signals">keybinding signal</link>
1526 * which gets emitted to paste the contents of the clipboard
1527 * into the text view.
1529 * The default bindings for this signal are
1530 * Ctrl-v and Shift-Insert.
1532 signals[PASTE_CLIPBOARD] =
1533 g_signal_new (I_("paste-clipboard"),
1534 G_OBJECT_CLASS_TYPE (gobject_class),
1535 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1536 G_STRUCT_OFFSET (GtkEntryClass, paste_clipboard),
1538 _gtk_marshal_VOID__VOID,
1542 * GtkEntry::toggle-overwrite:
1543 * @entry: the object which received the signal
1545 * The ::toggle-overwrite signal is a
1546 * <link linkend="keybinding-signals">keybinding signal</link>
1547 * which gets emitted to toggle the overwrite mode of the entry.
1549 * The default bindings for this signal is Insert.
1551 signals[TOGGLE_OVERWRITE] =
1552 g_signal_new (I_("toggle-overwrite"),
1553 G_OBJECT_CLASS_TYPE (gobject_class),
1554 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1555 G_STRUCT_OFFSET (GtkEntryClass, toggle_overwrite),
1557 _gtk_marshal_VOID__VOID,
1561 * GtkEntry::icon-press:
1562 * @entry: The entry on which the signal is emitted
1563 * @icon_pos: The position of the clicked icon
1564 * @event: the button press event
1566 * The ::icon-press signal is emitted when an activatable icon
1571 signals[ICON_PRESS] =
1572 g_signal_new (I_("icon-press"),
1573 G_TYPE_FROM_CLASS (gobject_class),
1577 _gtk_marshal_VOID__ENUM_BOXED,
1579 GTK_TYPE_ENTRY_ICON_POSITION,
1580 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1583 * GtkEntry::icon-release:
1584 * @entry: The entry on which the signal is emitted
1585 * @icon_pos: The position of the clicked icon
1586 * @event: the button release event
1588 * The ::icon-release signal is emitted on the button release from a
1589 * mouse click over an activatable icon.
1593 signals[ICON_RELEASE] =
1594 g_signal_new (I_("icon-release"),
1595 G_TYPE_FROM_CLASS (gobject_class),
1599 _gtk_marshal_VOID__ENUM_BOXED,
1601 GTK_TYPE_ENTRY_ICON_POSITION,
1602 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1605 * GtkEntry::preedit-changed:
1606 * @entry: the object which received the signal
1607 * @preedit: the current preedit string
1609 * If an input method is used, the typed text will not immediately
1610 * be committed to the buffer. So if you are interested in the text,
1611 * connect to this signal.
1615 signals[PREEDIT_CHANGED] =
1616 g_signal_new_class_handler (I_("preedit-changed"),
1617 G_OBJECT_CLASS_TYPE (gobject_class),
1618 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1621 _gtk_marshal_VOID__STRING,
1630 binding_set = gtk_binding_set_by_class (class);
1632 /* Moving the insertion point */
1633 add_move_binding (binding_set, GDK_KEY_Right, 0,
1634 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1636 add_move_binding (binding_set, GDK_KEY_Left, 0,
1637 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1639 add_move_binding (binding_set, GDK_KEY_KP_Right, 0,
1640 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1642 add_move_binding (binding_set, GDK_KEY_KP_Left, 0,
1643 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1645 add_move_binding (binding_set, GDK_KEY_Right, GDK_CONTROL_MASK,
1646 GTK_MOVEMENT_WORDS, 1);
1648 add_move_binding (binding_set, GDK_KEY_Left, GDK_CONTROL_MASK,
1649 GTK_MOVEMENT_WORDS, -1);
1651 add_move_binding (binding_set, GDK_KEY_KP_Right, GDK_CONTROL_MASK,
1652 GTK_MOVEMENT_WORDS, 1);
1654 add_move_binding (binding_set, GDK_KEY_KP_Left, GDK_CONTROL_MASK,
1655 GTK_MOVEMENT_WORDS, -1);
1657 add_move_binding (binding_set, GDK_KEY_Home, 0,
1658 GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
1660 add_move_binding (binding_set, GDK_KEY_End, 0,
1661 GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
1663 add_move_binding (binding_set, GDK_KEY_KP_Home, 0,
1664 GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
1666 add_move_binding (binding_set, GDK_KEY_KP_End, 0,
1667 GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
1669 add_move_binding (binding_set, GDK_KEY_Home, GDK_CONTROL_MASK,
1670 GTK_MOVEMENT_BUFFER_ENDS, -1);
1672 add_move_binding (binding_set, GDK_KEY_End, GDK_CONTROL_MASK,
1673 GTK_MOVEMENT_BUFFER_ENDS, 1);
1675 add_move_binding (binding_set, GDK_KEY_KP_Home, GDK_CONTROL_MASK,
1676 GTK_MOVEMENT_BUFFER_ENDS, -1);
1678 add_move_binding (binding_set, GDK_KEY_KP_End, GDK_CONTROL_MASK,
1679 GTK_MOVEMENT_BUFFER_ENDS, 1);
1683 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK,
1685 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1687 G_TYPE_BOOLEAN, FALSE);
1688 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK,
1690 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1692 G_TYPE_BOOLEAN, TRUE);
1694 gtk_binding_entry_add_signal (binding_set, GDK_KEY_slash, GDK_CONTROL_MASK,
1696 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1698 G_TYPE_BOOLEAN, FALSE);
1699 gtk_binding_entry_add_signal (binding_set, GDK_KEY_slash, GDK_CONTROL_MASK,
1701 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1703 G_TYPE_BOOLEAN, TRUE);
1706 gtk_binding_entry_add_signal (binding_set, GDK_KEY_backslash, GDK_CONTROL_MASK,
1708 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_VISUAL_POSITIONS,
1710 G_TYPE_BOOLEAN, FALSE);
1711 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_SHIFT_MASK | GDK_CONTROL_MASK,
1713 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_VISUAL_POSITIONS,
1715 G_TYPE_BOOLEAN, FALSE);
1719 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Return, 0,
1721 gtk_binding_entry_add_signal (binding_set, GDK_KEY_ISO_Enter, 0,
1723 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Enter, 0,
1727 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, 0,
1728 "delete-from-cursor", 2,
1729 G_TYPE_ENUM, GTK_DELETE_CHARS,
1732 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Delete, 0,
1733 "delete-from-cursor", 2,
1734 G_TYPE_ENUM, GTK_DELETE_CHARS,
1737 gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, 0,
1740 /* Make this do the same as Backspace, to help with mis-typing */
1741 gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, GDK_SHIFT_MASK,
1744 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, GDK_CONTROL_MASK,
1745 "delete-from-cursor", 2,
1746 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1749 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Delete, GDK_CONTROL_MASK,
1750 "delete-from-cursor", 2,
1751 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1754 gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, GDK_CONTROL_MASK,
1755 "delete-from-cursor", 2,
1756 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1759 /* Cut/copy/paste */
1761 gtk_binding_entry_add_signal (binding_set, GDK_KEY_x, GDK_CONTROL_MASK,
1762 "cut-clipboard", 0);
1763 gtk_binding_entry_add_signal (binding_set, GDK_KEY_c, GDK_CONTROL_MASK,
1764 "copy-clipboard", 0);
1765 gtk_binding_entry_add_signal (binding_set, GDK_KEY_v, GDK_CONTROL_MASK,
1766 "paste-clipboard", 0);
1768 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, GDK_SHIFT_MASK,
1769 "cut-clipboard", 0);
1770 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, GDK_CONTROL_MASK,
1771 "copy-clipboard", 0);
1772 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, GDK_SHIFT_MASK,
1773 "paste-clipboard", 0);
1776 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, 0,
1777 "toggle-overwrite", 0);
1778 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Insert, 0,
1779 "toggle-overwrite", 0);
1782 * GtkEntry:inner-border:
1784 * Sets the text area's border between the text and the frame.
1788 gtk_widget_class_install_style_property (widget_class,
1789 g_param_spec_boxed ("inner-border",
1791 P_("Border between text and frame."),
1793 GTK_PARAM_READABLE));
1795 g_type_class_add_private (gobject_class, sizeof (GtkEntryPrivate));
1799 gtk_entry_editable_init (GtkEditableInterface *iface)
1801 iface->do_insert_text = gtk_entry_insert_text;
1802 iface->do_delete_text = gtk_entry_delete_text;
1803 iface->insert_text = gtk_entry_real_insert_text;
1804 iface->delete_text = gtk_entry_real_delete_text;
1805 iface->get_chars = gtk_entry_get_chars;
1806 iface->set_selection_bounds = gtk_entry_set_selection_bounds;
1807 iface->get_selection_bounds = gtk_entry_get_selection_bounds;
1808 iface->set_position = gtk_entry_real_set_position;
1809 iface->get_position = gtk_entry_get_position;
1813 gtk_entry_cell_editable_init (GtkCellEditableIface *iface)
1815 iface->start_editing = gtk_entry_start_editing;
1819 gtk_entry_set_property (GObject *object,
1821 const GValue *value,
1824 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (object);
1825 GtkEntry *entry = GTK_ENTRY (object);
1831 gtk_entry_set_buffer (entry, g_value_get_object (value));
1836 gboolean new_value = g_value_get_boolean (value);
1838 if (new_value != entry->editable)
1840 widget = GTK_WIDGET (entry);
1843 _gtk_entry_reset_im_context (entry);
1844 if (gtk_widget_has_focus (widget))
1845 gtk_im_context_focus_out (entry->im_context);
1847 entry->preedit_length = 0;
1848 entry->preedit_cursor = 0;
1851 entry->editable = new_value;
1853 if (new_value && gtk_widget_has_focus (widget))
1854 gtk_im_context_focus_in (entry->im_context);
1856 gtk_entry_queue_draw (entry);
1861 case PROP_MAX_LENGTH:
1862 gtk_entry_set_max_length (entry, g_value_get_int (value));
1865 case PROP_VISIBILITY:
1866 gtk_entry_set_visibility (entry, g_value_get_boolean (value));
1869 case PROP_HAS_FRAME:
1870 gtk_entry_set_has_frame (entry, g_value_get_boolean (value));
1873 case PROP_INNER_BORDER:
1874 gtk_entry_set_inner_border (entry, g_value_get_boxed (value));
1877 case PROP_INVISIBLE_CHAR:
1878 gtk_entry_set_invisible_char (entry, g_value_get_uint (value));
1881 case PROP_ACTIVATES_DEFAULT:
1882 gtk_entry_set_activates_default (entry, g_value_get_boolean (value));
1885 case PROP_WIDTH_CHARS:
1886 gtk_entry_set_width_chars (entry, g_value_get_int (value));
1890 gtk_entry_set_text (entry, g_value_get_string (value));
1894 gtk_entry_set_alignment (entry, g_value_get_float (value));
1897 case PROP_TRUNCATE_MULTILINE:
1898 entry->truncate_multiline = g_value_get_boolean (value);
1901 case PROP_SHADOW_TYPE:
1902 priv->shadow_type = g_value_get_enum (value);
1905 case PROP_OVERWRITE_MODE:
1906 gtk_entry_set_overwrite_mode (entry, g_value_get_boolean (value));
1909 case PROP_INVISIBLE_CHAR_SET:
1910 if (g_value_get_boolean (value))
1911 priv->invisible_char_set = TRUE;
1913 gtk_entry_unset_invisible_char (entry);
1916 case PROP_CAPS_LOCK_WARNING:
1917 priv->caps_lock_warning = g_value_get_boolean (value);
1920 case PROP_PROGRESS_FRACTION:
1921 gtk_entry_set_progress_fraction (entry, g_value_get_double (value));
1924 case PROP_PROGRESS_PULSE_STEP:
1925 gtk_entry_set_progress_pulse_step (entry, g_value_get_double (value));
1928 case PROP_PIXBUF_PRIMARY:
1929 gtk_entry_set_icon_from_pixbuf (entry,
1930 GTK_ENTRY_ICON_PRIMARY,
1931 g_value_get_object (value));
1934 case PROP_PIXBUF_SECONDARY:
1935 gtk_entry_set_icon_from_pixbuf (entry,
1936 GTK_ENTRY_ICON_SECONDARY,
1937 g_value_get_object (value));
1940 case PROP_STOCK_PRIMARY:
1941 gtk_entry_set_icon_from_stock (entry,
1942 GTK_ENTRY_ICON_PRIMARY,
1943 g_value_get_string (value));
1946 case PROP_STOCK_SECONDARY:
1947 gtk_entry_set_icon_from_stock (entry,
1948 GTK_ENTRY_ICON_SECONDARY,
1949 g_value_get_string (value));
1952 case PROP_ICON_NAME_PRIMARY:
1953 gtk_entry_set_icon_from_icon_name (entry,
1954 GTK_ENTRY_ICON_PRIMARY,
1955 g_value_get_string (value));
1958 case PROP_ICON_NAME_SECONDARY:
1959 gtk_entry_set_icon_from_icon_name (entry,
1960 GTK_ENTRY_ICON_SECONDARY,
1961 g_value_get_string (value));
1964 case PROP_GICON_PRIMARY:
1965 gtk_entry_set_icon_from_gicon (entry,
1966 GTK_ENTRY_ICON_PRIMARY,
1967 g_value_get_object (value));
1970 case PROP_GICON_SECONDARY:
1971 gtk_entry_set_icon_from_gicon (entry,
1972 GTK_ENTRY_ICON_SECONDARY,
1973 g_value_get_object (value));
1976 case PROP_ACTIVATABLE_PRIMARY:
1977 gtk_entry_set_icon_activatable (entry,
1978 GTK_ENTRY_ICON_PRIMARY,
1979 g_value_get_boolean (value));
1982 case PROP_ACTIVATABLE_SECONDARY:
1983 gtk_entry_set_icon_activatable (entry,
1984 GTK_ENTRY_ICON_SECONDARY,
1985 g_value_get_boolean (value));
1988 case PROP_SENSITIVE_PRIMARY:
1989 gtk_entry_set_icon_sensitive (entry,
1990 GTK_ENTRY_ICON_PRIMARY,
1991 g_value_get_boolean (value));
1994 case PROP_SENSITIVE_SECONDARY:
1995 gtk_entry_set_icon_sensitive (entry,
1996 GTK_ENTRY_ICON_SECONDARY,
1997 g_value_get_boolean (value));
2000 case PROP_TOOLTIP_TEXT_PRIMARY:
2001 gtk_entry_set_icon_tooltip_text (entry,
2002 GTK_ENTRY_ICON_PRIMARY,
2003 g_value_get_string (value));
2006 case PROP_TOOLTIP_TEXT_SECONDARY:
2007 gtk_entry_set_icon_tooltip_text (entry,
2008 GTK_ENTRY_ICON_SECONDARY,
2009 g_value_get_string (value));
2012 case PROP_TOOLTIP_MARKUP_PRIMARY:
2013 gtk_entry_set_icon_tooltip_markup (entry,
2014 GTK_ENTRY_ICON_PRIMARY,
2015 g_value_get_string (value));
2018 case PROP_TOOLTIP_MARKUP_SECONDARY:
2019 gtk_entry_set_icon_tooltip_markup (entry,
2020 GTK_ENTRY_ICON_SECONDARY,
2021 g_value_get_string (value));
2024 case PROP_IM_MODULE:
2025 g_free (priv->im_module);
2026 priv->im_module = g_value_dup_string (value);
2027 if (GTK_IS_IM_MULTICONTEXT (entry->im_context))
2028 gtk_im_multicontext_set_context_id (GTK_IM_MULTICONTEXT (entry->im_context), priv->im_module);
2031 case PROP_EDITING_CANCELED:
2032 entry->editing_canceled = g_value_get_boolean (value);
2035 case PROP_SCROLL_OFFSET:
2036 case PROP_CURSOR_POSITION:
2038 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2044 gtk_entry_get_property (GObject *object,
2049 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (object);
2050 GtkEntry *entry = GTK_ENTRY (object);
2055 g_value_set_object (value, gtk_entry_get_buffer (entry));
2058 case PROP_CURSOR_POSITION:
2059 g_value_set_int (value, entry->current_pos);
2062 case PROP_SELECTION_BOUND:
2063 g_value_set_int (value, entry->selection_bound);
2067 g_value_set_boolean (value, entry->editable);
2070 case PROP_MAX_LENGTH:
2071 g_value_set_int (value, gtk_entry_buffer_get_max_length (get_buffer (entry)));
2074 case PROP_VISIBILITY:
2075 g_value_set_boolean (value, entry->visible);
2078 case PROP_HAS_FRAME:
2079 g_value_set_boolean (value, entry->has_frame);
2082 case PROP_INNER_BORDER:
2083 g_value_set_boxed (value, gtk_entry_get_inner_border (entry));
2086 case PROP_INVISIBLE_CHAR:
2087 g_value_set_uint (value, entry->invisible_char);
2090 case PROP_ACTIVATES_DEFAULT:
2091 g_value_set_boolean (value, entry->activates_default);
2094 case PROP_WIDTH_CHARS:
2095 g_value_set_int (value, entry->width_chars);
2098 case PROP_SCROLL_OFFSET:
2099 g_value_set_int (value, entry->scroll_offset);
2103 g_value_set_string (value, gtk_entry_get_text (entry));
2107 g_value_set_float (value, gtk_entry_get_alignment (entry));
2110 case PROP_TRUNCATE_MULTILINE:
2111 g_value_set_boolean (value, entry->truncate_multiline);
2114 case PROP_SHADOW_TYPE:
2115 g_value_set_enum (value, priv->shadow_type);
2118 case PROP_OVERWRITE_MODE:
2119 g_value_set_boolean (value, entry->overwrite_mode);
2122 case PROP_TEXT_LENGTH:
2123 g_value_set_uint (value, gtk_entry_buffer_get_length (get_buffer (entry)));
2126 case PROP_INVISIBLE_CHAR_SET:
2127 g_value_set_boolean (value, priv->invisible_char_set);
2130 case PROP_IM_MODULE:
2131 g_value_set_string (value, priv->im_module);
2134 case PROP_CAPS_LOCK_WARNING:
2135 g_value_set_boolean (value, priv->caps_lock_warning);
2138 case PROP_PROGRESS_FRACTION:
2139 g_value_set_double (value, priv->progress_fraction);
2142 case PROP_PROGRESS_PULSE_STEP:
2143 g_value_set_double (value, priv->progress_pulse_fraction);
2146 case PROP_PIXBUF_PRIMARY:
2147 g_value_set_object (value,
2148 gtk_entry_get_icon_pixbuf (entry,
2149 GTK_ENTRY_ICON_PRIMARY));
2152 case PROP_PIXBUF_SECONDARY:
2153 g_value_set_object (value,
2154 gtk_entry_get_icon_pixbuf (entry,
2155 GTK_ENTRY_ICON_SECONDARY));
2158 case PROP_STOCK_PRIMARY:
2159 g_value_set_string (value,
2160 gtk_entry_get_icon_stock (entry,
2161 GTK_ENTRY_ICON_PRIMARY));
2164 case PROP_STOCK_SECONDARY:
2165 g_value_set_string (value,
2166 gtk_entry_get_icon_stock (entry,
2167 GTK_ENTRY_ICON_SECONDARY));
2170 case PROP_ICON_NAME_PRIMARY:
2171 g_value_set_string (value,
2172 gtk_entry_get_icon_name (entry,
2173 GTK_ENTRY_ICON_PRIMARY));
2176 case PROP_ICON_NAME_SECONDARY:
2177 g_value_set_string (value,
2178 gtk_entry_get_icon_name (entry,
2179 GTK_ENTRY_ICON_SECONDARY));
2182 case PROP_GICON_PRIMARY:
2183 g_value_set_object (value,
2184 gtk_entry_get_icon_gicon (entry,
2185 GTK_ENTRY_ICON_PRIMARY));
2188 case PROP_GICON_SECONDARY:
2189 g_value_set_object (value,
2190 gtk_entry_get_icon_gicon (entry,
2191 GTK_ENTRY_ICON_SECONDARY));
2194 case PROP_STORAGE_TYPE_PRIMARY:
2195 g_value_set_enum (value,
2196 gtk_entry_get_icon_storage_type (entry,
2197 GTK_ENTRY_ICON_PRIMARY));
2200 case PROP_STORAGE_TYPE_SECONDARY:
2201 g_value_set_enum (value,
2202 gtk_entry_get_icon_storage_type (entry,
2203 GTK_ENTRY_ICON_SECONDARY));
2206 case PROP_ACTIVATABLE_PRIMARY:
2207 g_value_set_boolean (value,
2208 gtk_entry_get_icon_activatable (entry, GTK_ENTRY_ICON_PRIMARY));
2211 case PROP_ACTIVATABLE_SECONDARY:
2212 g_value_set_boolean (value,
2213 gtk_entry_get_icon_activatable (entry, GTK_ENTRY_ICON_SECONDARY));
2216 case PROP_SENSITIVE_PRIMARY:
2217 g_value_set_boolean (value,
2218 gtk_entry_get_icon_sensitive (entry, GTK_ENTRY_ICON_PRIMARY));
2221 case PROP_SENSITIVE_SECONDARY:
2222 g_value_set_boolean (value,
2223 gtk_entry_get_icon_sensitive (entry, GTK_ENTRY_ICON_SECONDARY));
2226 case PROP_TOOLTIP_TEXT_PRIMARY:
2227 g_value_take_string (value,
2228 gtk_entry_get_icon_tooltip_text (entry, GTK_ENTRY_ICON_PRIMARY));
2231 case PROP_TOOLTIP_TEXT_SECONDARY:
2232 g_value_take_string (value,
2233 gtk_entry_get_icon_tooltip_text (entry, GTK_ENTRY_ICON_SECONDARY));
2236 case PROP_TOOLTIP_MARKUP_PRIMARY:
2237 g_value_take_string (value,
2238 gtk_entry_get_icon_tooltip_markup (entry, GTK_ENTRY_ICON_PRIMARY));
2241 case PROP_TOOLTIP_MARKUP_SECONDARY:
2242 g_value_take_string (value,
2243 gtk_entry_get_icon_tooltip_markup (entry, GTK_ENTRY_ICON_SECONDARY));
2246 case PROP_EDITING_CANCELED:
2247 g_value_set_boolean (value,
2248 entry->editing_canceled);
2252 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2258 find_invisible_char (GtkWidget *widget)
2260 PangoLayout *layout;
2261 PangoAttrList *attr_list;
2263 gunichar invisible_chars [] = {
2265 0x25cf, /* BLACK CIRCLE */
2266 0x2022, /* BULLET */
2267 0x2731, /* HEAVY ASTERISK */
2268 0x273a /* SIXTEEN POINTED ASTERISK */
2271 if (gtk_widget_get_style (widget))
2272 gtk_widget_style_get (widget,
2273 "invisible-char", &invisible_chars[0],
2276 layout = gtk_widget_create_pango_layout (widget, NULL);
2278 attr_list = pango_attr_list_new ();
2279 pango_attr_list_insert (attr_list, pango_attr_fallback_new (FALSE));
2281 pango_layout_set_attributes (layout, attr_list);
2282 pango_attr_list_unref (attr_list);
2284 for (i = (invisible_chars[0] != 0 ? 0 : 1); i < G_N_ELEMENTS (invisible_chars); i++)
2286 gchar text[7] = { 0, };
2289 len = g_unichar_to_utf8 (invisible_chars[i], text);
2290 pango_layout_set_text (layout, text, len);
2292 count = pango_layout_get_unknown_glyphs_count (layout);
2296 g_object_unref (layout);
2297 return invisible_chars[i];
2301 g_object_unref (layout);
2307 gtk_entry_init (GtkEntry *entry)
2309 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2311 gtk_widget_set_can_focus (GTK_WIDGET (entry), TRUE);
2312 gtk_widget_set_has_window (GTK_WIDGET (entry), FALSE);
2314 entry->editable = TRUE;
2315 entry->visible = TRUE;
2316 entry->invisible_char = find_invisible_char (GTK_WIDGET (entry));
2317 entry->dnd_position = -1;
2318 entry->width_chars = -1;
2319 entry->is_cell_renderer = FALSE;
2320 entry->editing_canceled = FALSE;
2321 entry->has_frame = TRUE;
2322 entry->truncate_multiline = FALSE;
2323 priv->shadow_type = GTK_SHADOW_IN;
2325 priv->caps_lock_warning = TRUE;
2326 priv->caps_lock_warning_shown = FALSE;
2327 priv->progress_fraction = 0.0;
2328 priv->progress_pulse_fraction = 0.1;
2330 gtk_drag_dest_set (GTK_WIDGET (entry),
2331 GTK_DEST_DEFAULT_HIGHLIGHT,
2333 GDK_ACTION_COPY | GDK_ACTION_MOVE);
2334 gtk_drag_dest_add_text_targets (GTK_WIDGET (entry));
2336 /* This object is completely private. No external entity can gain a reference
2337 * to it; so we create it here and destroy it in finalize().
2339 entry->im_context = gtk_im_multicontext_new ();
2341 g_signal_connect (entry->im_context, "commit",
2342 G_CALLBACK (gtk_entry_commit_cb), entry);
2343 g_signal_connect (entry->im_context, "preedit-changed",
2344 G_CALLBACK (gtk_entry_preedit_changed_cb), entry);
2345 g_signal_connect (entry->im_context, "retrieve-surrounding",
2346 G_CALLBACK (gtk_entry_retrieve_surrounding_cb), entry);
2347 g_signal_connect (entry->im_context, "delete-surrounding",
2348 G_CALLBACK (gtk_entry_delete_surrounding_cb), entry);
2353 get_icon_width (GtkEntry *entry,
2354 GtkEntryIconPosition icon_pos)
2356 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2357 EntryIconInfo *icon_info = priv->icons[icon_pos];
2359 GtkSettings *settings;
2360 gint menu_icon_width;
2362 if (!icon_info || icon_info->pixbuf == NULL)
2365 screen = gtk_widget_get_screen (GTK_WIDGET (entry));
2366 settings = gtk_settings_get_for_screen (screen);
2368 gtk_icon_size_lookup_for_settings (settings, GTK_ICON_SIZE_MENU,
2369 &menu_icon_width, NULL);
2371 return MAX (gdk_pixbuf_get_width (icon_info->pixbuf), menu_icon_width);
2375 get_icon_allocations (GtkEntry *entry,
2376 GtkAllocation *primary,
2377 GtkAllocation *secondary)
2380 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2381 gint x, y, width, height;
2383 get_text_area_size (entry, &x, &y, &width, &height);
2385 if (gtk_widget_has_focus (GTK_WIDGET (entry)) && !priv->interior_focus)
2386 y += priv->focus_width;
2389 primary->height = height;
2390 primary->width = get_icon_width (entry, GTK_ENTRY_ICON_PRIMARY);
2391 if (primary->width > 0)
2392 primary->width += 2 * priv->icon_margin;
2395 secondary->height = height;
2396 secondary->width = get_icon_width (entry, GTK_ENTRY_ICON_SECONDARY);
2397 if (secondary->width > 0)
2398 secondary->width += 2 * priv->icon_margin;
2400 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
2402 primary->x = x + width - primary->width;
2408 secondary->x = x + width - secondary->width;
2414 begin_change (GtkEntry *entry)
2416 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2418 priv->change_count++;
2422 end_change (GtkEntry *entry)
2424 GtkEditable *editable = GTK_EDITABLE (entry);
2425 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2427 g_return_if_fail (priv->change_count > 0);
2429 priv->change_count--;
2431 if (priv->change_count == 0)
2433 if (priv->real_changed)
2435 g_signal_emit_by_name (editable, "changed");
2436 priv->real_changed = FALSE;
2442 emit_changed (GtkEntry *entry)
2444 GtkEditable *editable = GTK_EDITABLE (entry);
2445 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2447 if (priv->change_count == 0)
2448 g_signal_emit_by_name (editable, "changed");
2450 priv->real_changed = TRUE;
2454 gtk_entry_destroy (GtkWidget *widget)
2456 GtkEntry *entry = GTK_ENTRY (widget);
2458 entry->current_pos = entry->selection_bound = 0;
2459 _gtk_entry_reset_im_context (entry);
2460 gtk_entry_reset_layout (entry);
2462 if (entry->blink_timeout)
2464 g_source_remove (entry->blink_timeout);
2465 entry->blink_timeout = 0;
2468 if (entry->recompute_idle)
2470 g_source_remove (entry->recompute_idle);
2471 entry->recompute_idle = 0;
2474 GTK_WIDGET_CLASS (gtk_entry_parent_class)->destroy (widget);
2478 gtk_entry_dispose (GObject *object)
2480 GtkEntry *entry = GTK_ENTRY (object);
2481 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2483 gtk_entry_set_icon_from_pixbuf (entry, GTK_ENTRY_ICON_PRIMARY, NULL);
2484 gtk_entry_set_icon_tooltip_markup (entry, GTK_ENTRY_ICON_PRIMARY, NULL);
2485 gtk_entry_set_icon_from_pixbuf (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
2486 gtk_entry_set_icon_tooltip_markup (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
2490 buffer_disconnect_signals (entry);
2491 g_object_unref (priv->buffer);
2492 priv->buffer = NULL;
2495 G_OBJECT_CLASS (gtk_entry_parent_class)->dispose (object);
2499 gtk_entry_finalize (GObject *object)
2501 GtkEntry *entry = GTK_ENTRY (object);
2502 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2503 EntryIconInfo *icon_info = NULL;
2506 for (i = 0; i < MAX_ICONS; i++)
2508 if ((icon_info = priv->icons[i]) != NULL)
2510 if (icon_info->target_list != NULL)
2512 gtk_target_list_unref (icon_info->target_list);
2513 icon_info->target_list = NULL;
2516 g_slice_free (EntryIconInfo, icon_info);
2517 priv->icons[i] = NULL;
2521 gtk_entry_set_completion (entry, NULL);
2523 if (entry->cached_layout)
2524 g_object_unref (entry->cached_layout);
2526 g_object_unref (entry->im_context);
2528 if (entry->blink_timeout)
2529 g_source_remove (entry->blink_timeout);
2531 if (entry->recompute_idle)
2532 g_source_remove (entry->recompute_idle);
2534 g_free (priv->im_module);
2536 G_OBJECT_CLASS (gtk_entry_parent_class)->finalize (object);
2540 gtk_entry_get_display_mode (GtkEntry *entry)
2542 GtkEntryPrivate *priv;
2544 return DISPLAY_NORMAL;
2545 priv = GTK_ENTRY_GET_PRIVATE (entry);
2546 if (entry->invisible_char == 0 && priv->invisible_char_set)
2547 return DISPLAY_BLANK;
2548 return DISPLAY_INVISIBLE;
2552 gtk_entry_get_display_text (GtkEntry *entry,
2556 GtkEntryPasswordHint *password_hint;
2557 GtkEntryPrivate *priv;
2558 gunichar invisible_char;
2568 priv = GTK_ENTRY_GET_PRIVATE (entry);
2569 text = gtk_entry_buffer_get_text (get_buffer (entry));
2570 length = gtk_entry_buffer_get_length (get_buffer (entry));
2574 if (start_pos > length)
2577 if (end_pos <= start_pos)
2578 return g_strdup ("");
2579 else if (entry->visible)
2581 start = g_utf8_offset_to_pointer (text, start_pos);
2582 end = g_utf8_offset_to_pointer (start, end_pos - start_pos);
2583 return g_strndup (start, end - start);
2587 str = g_string_sized_new (length * 2);
2589 /* Figure out what our invisible char is and encode it */
2590 if (!entry->invisible_char)
2591 invisible_char = priv->invisible_char_set ? ' ' : '*';
2593 invisible_char = entry->invisible_char;
2594 char_len = g_unichar_to_utf8 (invisible_char, char_str);
2597 * Add hidden characters for each character in the text
2598 * buffer. If there is a password hint, then keep that
2599 * character visible.
2602 password_hint = g_object_get_qdata (G_OBJECT (entry), quark_password_hint);
2603 for (i = start_pos; i < end_pos; ++i)
2605 if (password_hint && i == password_hint->position)
2607 start = g_utf8_offset_to_pointer (text, i);
2608 g_string_append_len (str, start, g_utf8_next_char (start) - start);
2612 g_string_append_len (str, char_str, char_len);
2616 return g_string_free (str, FALSE);
2622 update_cursors (GtkWidget *widget)
2624 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2625 EntryIconInfo *icon_info = NULL;
2626 GdkDisplay *display;
2630 for (i = 0; i < MAX_ICONS; i++)
2632 if ((icon_info = priv->icons[i]) != NULL)
2634 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
2635 gdk_window_show_unraised (icon_info->window);
2637 /* The icon windows are not children of the visible entry window,
2638 * thus we can't just inherit the xterm cursor. Slight complication
2639 * here is that for the entry, insensitive => arrow cursor, but for
2640 * an icon in a sensitive entry, insensitive => xterm cursor.
2642 if (gtk_widget_is_sensitive (widget) &&
2643 (icon_info->insensitive ||
2644 (icon_info->nonactivatable && icon_info->target_list == NULL)))
2646 display = gtk_widget_get_display (widget);
2647 cursor = gdk_cursor_new_for_display (display, GDK_XTERM);
2648 gdk_window_set_cursor (icon_info->window, cursor);
2649 gdk_cursor_unref (cursor);
2653 gdk_window_set_cursor (icon_info->window, NULL);
2660 realize_icon_info (GtkWidget *widget,
2661 GtkEntryIconPosition icon_pos)
2663 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2664 EntryIconInfo *icon_info = priv->icons[icon_pos];
2665 GdkWindowAttr attributes;
2666 gint attributes_mask;
2668 g_return_if_fail (icon_info != NULL);
2672 attributes.width = 1;
2673 attributes.height = 1;
2674 attributes.window_type = GDK_WINDOW_CHILD;
2675 attributes.wclass = GDK_INPUT_ONLY;
2676 attributes.event_mask = gtk_widget_get_events (widget);
2677 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
2678 GDK_BUTTON_RELEASE_MASK |
2679 GDK_BUTTON1_MOTION_MASK |
2680 GDK_BUTTON3_MOTION_MASK |
2681 GDK_POINTER_MOTION_HINT_MASK |
2682 GDK_POINTER_MOTION_MASK |
2683 GDK_ENTER_NOTIFY_MASK |
2684 GDK_LEAVE_NOTIFY_MASK);
2685 attributes_mask = GDK_WA_X | GDK_WA_Y;
2687 icon_info->window = gdk_window_new (gtk_widget_get_window (widget),
2690 gdk_window_set_user_data (icon_info->window, widget);
2692 gtk_widget_queue_resize (widget);
2695 static EntryIconInfo*
2696 construct_icon_info (GtkWidget *widget,
2697 GtkEntryIconPosition icon_pos)
2699 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2700 EntryIconInfo *icon_info;
2702 g_return_val_if_fail (priv->icons[icon_pos] == NULL, NULL);
2704 icon_info = g_slice_new0 (EntryIconInfo);
2705 priv->icons[icon_pos] = icon_info;
2707 if (gtk_widget_get_realized (widget))
2708 realize_icon_info (widget, icon_pos);
2714 gtk_entry_map (GtkWidget *widget)
2716 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2717 EntryIconInfo *icon_info = NULL;
2720 GTK_WIDGET_CLASS (gtk_entry_parent_class)->map (widget);
2722 for (i = 0; i < MAX_ICONS; i++)
2724 if ((icon_info = priv->icons[i]) != NULL)
2726 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
2727 gdk_window_show (icon_info->window);
2731 update_cursors (widget);
2735 gtk_entry_unmap (GtkWidget *widget)
2737 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2738 EntryIconInfo *icon_info = NULL;
2741 for (i = 0; i < MAX_ICONS; i++)
2743 if ((icon_info = priv->icons[i]) != NULL)
2745 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
2746 gdk_window_hide (icon_info->window);
2750 GTK_WIDGET_CLASS (gtk_entry_parent_class)->unmap (widget);
2754 gtk_entry_realize (GtkWidget *widget)
2757 GtkEntryPrivate *priv;
2758 EntryIconInfo *icon_info;
2760 GdkWindowAttr attributes;
2761 gint attributes_mask;
2762 gint frame_x, frame_y;
2765 gtk_widget_set_realized (widget, TRUE);
2766 window = gtk_widget_get_parent_window (widget);
2767 gtk_widget_set_window (widget, window);
2768 g_object_ref (window);
2770 entry = GTK_ENTRY (widget);
2771 priv = GTK_ENTRY_GET_PRIVATE (entry);
2773 attributes.window_type = GDK_WINDOW_CHILD;
2774 attributes.wclass = GDK_INPUT_ONLY;
2775 attributes.event_mask = gtk_widget_get_events (widget);
2776 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
2777 GDK_BUTTON_RELEASE_MASK |
2778 GDK_BUTTON1_MOTION_MASK |
2779 GDK_BUTTON3_MOTION_MASK |
2780 GDK_POINTER_MOTION_HINT_MASK |
2781 GDK_POINTER_MOTION_MASK |
2782 GDK_ENTER_NOTIFY_MASK |
2783 GDK_LEAVE_NOTIFY_MASK);
2784 attributes_mask = GDK_WA_X | GDK_WA_Y;
2786 get_text_area_size (entry, &attributes.x, &attributes.y, &attributes.width, &attributes.height);
2788 get_frame_size (entry, &frame_x, &frame_y, NULL, NULL);
2789 attributes.x += frame_x;
2790 attributes.y += frame_y;
2792 if (gtk_widget_is_sensitive (widget))
2794 attributes.cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
2795 attributes_mask |= GDK_WA_CURSOR;
2798 entry->text_area = gdk_window_new (gtk_widget_get_window (widget),
2802 gdk_window_set_user_data (entry->text_area, entry);
2804 if (attributes_mask & GDK_WA_CURSOR)
2805 gdk_cursor_unref (attributes.cursor);
2807 gtk_widget_style_attach (widget);
2809 gdk_window_show (entry->text_area);
2811 gtk_im_context_set_client_window (entry->im_context, entry->text_area);
2813 gtk_entry_adjust_scroll (entry);
2814 gtk_entry_update_primary_selection (entry);
2817 /* If the icon positions are already setup, create their windows.
2818 * Otherwise if they don't exist yet, then construct_icon_info()
2819 * will create the windows once the widget is already realized.
2821 for (i = 0; i < MAX_ICONS; i++)
2823 if ((icon_info = priv->icons[i]) != NULL)
2825 if (icon_info->window == NULL)
2826 realize_icon_info (widget, i);
2832 gtk_entry_unrealize (GtkWidget *widget)
2834 GtkEntry *entry = GTK_ENTRY (widget);
2835 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2836 GtkClipboard *clipboard;
2837 EntryIconInfo *icon_info;
2840 gtk_entry_reset_layout (entry);
2842 gtk_im_context_set_client_window (entry->im_context, NULL);
2844 clipboard = gtk_widget_get_clipboard (widget, GDK_SELECTION_PRIMARY);
2845 if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (entry))
2846 gtk_clipboard_clear (clipboard);
2848 if (entry->text_area)
2850 gdk_window_set_user_data (entry->text_area, NULL);
2851 gdk_window_destroy (entry->text_area);
2852 entry->text_area = NULL;
2855 if (entry->popup_menu)
2857 gtk_widget_destroy (entry->popup_menu);
2858 entry->popup_menu = NULL;
2861 GTK_WIDGET_CLASS (gtk_entry_parent_class)->unrealize (widget);
2863 for (i = 0; i < MAX_ICONS; i++)
2865 if ((icon_info = priv->icons[i]) != NULL)
2867 if (icon_info->window != NULL)
2869 gdk_window_destroy (icon_info->window);
2870 icon_info->window = NULL;
2877 _gtk_entry_get_borders (GtkEntry *entry,
2881 GtkWidget *widget = GTK_WIDGET (entry);
2882 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2885 if (entry->has_frame)
2887 style = gtk_widget_get_style (widget);
2889 *xborder = style->xthickness;
2890 *yborder = style->ythickness;
2898 if (!priv->interior_focus)
2900 *xborder += priv->focus_width;
2901 *yborder += priv->focus_width;
2906 gtk_entry_get_preferred_width (GtkWidget *widget,
2910 GtkEntry *entry = GTK_ENTRY (widget);
2911 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2912 PangoFontMetrics *metrics;
2913 gint xborder, yborder;
2914 GtkBorder inner_border;
2915 PangoContext *context;
2916 gint icon_widths = 0;
2920 gtk_widget_ensure_style (widget);
2921 context = gtk_widget_get_pango_context (widget);
2922 metrics = pango_context_get_metrics (context,
2923 gtk_widget_get_style (widget)->font_desc,
2924 pango_context_get_language (context));
2926 _gtk_entry_get_borders (entry, &xborder, &yborder);
2927 _gtk_entry_effective_inner_border (entry, &inner_border);
2929 if (entry->width_chars < 0)
2930 width = MIN_ENTRY_WIDTH + xborder * 2 + inner_border.left + inner_border.right;
2933 gint char_width = pango_font_metrics_get_approximate_char_width (metrics);
2934 gint digit_width = pango_font_metrics_get_approximate_digit_width (metrics);
2935 gint char_pixels = (MAX (char_width, digit_width) + PANGO_SCALE - 1) / PANGO_SCALE;
2937 width = char_pixels * entry->width_chars + xborder * 2 + inner_border.left + inner_border.right;
2940 for (i = 0; i < MAX_ICONS; i++)
2942 icon_width = get_icon_width (entry, i);
2944 icon_widths += icon_width + 2 * priv->icon_margin;
2947 if (icon_widths > width)
2948 width += icon_widths;
2950 pango_font_metrics_unref (metrics);
2957 gtk_entry_get_preferred_height (GtkWidget *widget,
2961 GtkEntry *entry = GTK_ENTRY (widget);
2962 PangoFontMetrics *metrics;
2963 gint xborder, yborder;
2964 GtkBorder inner_border;
2965 PangoContext *context;
2968 gtk_widget_ensure_style (widget);
2969 context = gtk_widget_get_pango_context (widget);
2970 metrics = pango_context_get_metrics (context,
2971 gtk_widget_get_style (widget)->font_desc,
2972 pango_context_get_language (context));
2974 entry->ascent = pango_font_metrics_get_ascent (metrics);
2975 entry->descent = pango_font_metrics_get_descent (metrics);
2977 _gtk_entry_get_borders (entry, &xborder, &yborder);
2978 _gtk_entry_effective_inner_border (entry, &inner_border);
2980 height = PANGO_PIXELS (entry->ascent + entry->descent) + yborder * 2 + inner_border.top + inner_border.bottom;
2982 pango_font_metrics_unref (metrics);
2989 place_windows (GtkEntry *entry)
2991 GtkWidget *widget = GTK_WIDGET (entry);
2992 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2993 gint x, y, width, height;
2994 gint frame_x, frame_y;
2995 GtkAllocation primary;
2996 GtkAllocation secondary;
2997 EntryIconInfo *icon_info = NULL;
2999 get_frame_size (entry, &frame_x, &frame_y, NULL, NULL);
3000 get_text_area_size (entry, &x, &y, &width, &height);
3001 get_icon_allocations (entry, &primary, &secondary);
3003 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3004 y += priv->focus_width;
3006 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
3007 x += secondary.width;
3010 width -= primary.width + secondary.width;
3014 primary.x += frame_x;
3015 primary.y += frame_y;
3016 secondary.x += frame_x;
3017 secondary.y += frame_y;
3019 if ((icon_info = priv->icons[GTK_ENTRY_ICON_PRIMARY]) != NULL)
3020 gdk_window_move_resize (icon_info->window,
3021 primary.x, primary.y,
3022 primary.width, primary.height);
3024 if ((icon_info = priv->icons[GTK_ENTRY_ICON_SECONDARY]) != NULL)
3025 gdk_window_move_resize (icon_info->window,
3026 secondary.x, secondary.y,
3027 secondary.width, secondary.height);
3029 gdk_window_move_resize (entry->text_area, x, y, width, height);
3033 gtk_entry_get_text_area_size (GtkEntry *entry,
3039 GtkWidget *widget = GTK_WIDGET (entry);
3040 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
3041 GtkAllocation allocation;
3042 GtkRequisition requisition;
3044 gint xborder, yborder;
3046 gtk_widget_get_preferred_size (widget, &requisition, NULL);
3047 gtk_widget_get_allocation (widget, &allocation);
3048 _gtk_entry_get_borders (entry, &xborder, &yborder);
3050 if (gtk_widget_get_realized (widget))
3051 get_frame_size (entry, NULL, NULL, NULL, &frame_height);
3053 frame_height = requisition.height;
3055 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3056 frame_height -= 2 * priv->focus_width;
3062 *y = frame_height / 2 - (requisition.height - yborder * 2) / 2;
3065 *width = allocation.width - xborder * 2;
3068 *height = requisition.height - yborder * 2;
3072 get_text_area_size (GtkEntry *entry,
3078 GtkEntryClass *class;
3080 g_return_if_fail (GTK_IS_ENTRY (entry));
3082 class = GTK_ENTRY_GET_CLASS (entry);
3084 if (class->get_text_area_size)
3085 class->get_text_area_size (entry, x, y, width, height);
3090 get_frame_size (GtkEntry *entry,
3096 GtkAllocation allocation;
3097 GtkRequisition requisition;
3098 GtkWidget *widget = GTK_WIDGET (entry);
3100 gtk_widget_get_preferred_size (widget, &requisition, NULL);
3101 gtk_widget_get_allocation (widget, &allocation);
3108 if (entry->is_cell_renderer)
3111 *y = allocation.y + (allocation.height - requisition.height) / 2;
3115 *width = allocation.width;
3119 if (entry->is_cell_renderer)
3120 *height = allocation.height;
3122 *height = requisition.height;
3127 _gtk_entry_effective_inner_border (GtkEntry *entry,
3130 GtkBorder *tmp_border;
3132 tmp_border = g_object_get_qdata (G_OBJECT (entry), quark_inner_border);
3136 *border = *tmp_border;
3140 gtk_widget_style_get (GTK_WIDGET (entry), "inner-border", &tmp_border, NULL);
3144 *border = *tmp_border;
3145 gtk_border_free (tmp_border);
3149 *border = default_inner_border;
3153 gtk_entry_size_allocate (GtkWidget *widget,
3154 GtkAllocation *allocation)
3156 GtkEntry *entry = GTK_ENTRY (widget);
3158 gtk_widget_set_allocation (widget, allocation);
3160 if (gtk_widget_get_realized (widget))
3162 GtkEntryCompletion* completion;
3164 place_windows (entry);
3165 gtk_entry_recompute (entry);
3167 completion = gtk_entry_get_completion (entry);
3168 if (completion && gtk_widget_get_mapped (completion->priv->popup_window))
3169 _gtk_entry_completion_resize_popup (completion);
3173 /* Kudos to the gnome-panel guys. */
3175 colorshift_pixbuf (GdkPixbuf *dest,
3180 gint width, height, has_alpha, src_rowstride, dest_rowstride;
3181 guchar *target_pixels;
3182 guchar *original_pixels;
3188 has_alpha = gdk_pixbuf_get_has_alpha (src);
3189 width = gdk_pixbuf_get_width (src);
3190 height = gdk_pixbuf_get_height (src);
3191 src_rowstride = gdk_pixbuf_get_rowstride (src);
3192 dest_rowstride = gdk_pixbuf_get_rowstride (dest);
3193 original_pixels = gdk_pixbuf_get_pixels (src);
3194 target_pixels = gdk_pixbuf_get_pixels (dest);
3196 for (i = 0; i < height; i++)
3198 pix_dest = target_pixels + i * dest_rowstride;
3199 pix_src = original_pixels + i * src_rowstride;
3201 for (j = 0; j < width; j++)
3208 *(pix_dest++) = CLAMP (val, 0, 255);
3211 *(pix_dest++) = CLAMP (val, 0, 255);
3214 *(pix_dest++) = CLAMP (val, 0, 255);
3217 *(pix_dest++) = *(pix_src++);
3223 should_prelight (GtkEntry *entry,
3224 GtkEntryIconPosition icon_pos)
3226 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3227 EntryIconInfo *icon_info = priv->icons[icon_pos];
3233 if (icon_info->nonactivatable && icon_info->target_list == NULL)
3236 if (icon_info->pressed)
3239 gtk_widget_style_get (GTK_WIDGET (entry),
3240 "icon-prelight", &prelight,
3247 draw_icon (GtkWidget *widget,
3249 GtkEntryIconPosition icon_pos)
3251 GtkEntry *entry = GTK_ENTRY (widget);
3252 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3253 EntryIconInfo *icon_info = priv->icons[icon_pos];
3255 gint x, y, width, height;
3260 gtk_entry_ensure_pixbuf (entry, icon_pos);
3262 if (icon_info->pixbuf == NULL)
3265 width = gdk_window_get_width (icon_info->window);
3266 height = gdk_window_get_height (icon_info->window);
3268 /* size_allocate hasn't been called yet. These are the default values.
3270 if (width == 1 || height == 1)
3273 pixbuf = icon_info->pixbuf;
3274 g_object_ref (pixbuf);
3276 if (gdk_pixbuf_get_height (pixbuf) > height)
3278 GdkPixbuf *temp_pixbuf;
3281 scale = height - 2 * priv->icon_margin;
3282 temp_pixbuf = gdk_pixbuf_scale_simple (pixbuf, scale, scale,
3283 GDK_INTERP_BILINEAR);
3284 g_object_unref (pixbuf);
3285 pixbuf = temp_pixbuf;
3288 x = (width - gdk_pixbuf_get_width (pixbuf)) / 2;
3289 y = (height - gdk_pixbuf_get_height (pixbuf)) / 2;
3291 if (!gtk_widget_is_sensitive (widget) ||
3292 icon_info->insensitive)
3294 GdkPixbuf *temp_pixbuf;
3296 temp_pixbuf = gdk_pixbuf_copy (pixbuf);
3297 gdk_pixbuf_saturate_and_pixelate (pixbuf,
3301 g_object_unref (pixbuf);
3302 pixbuf = temp_pixbuf;
3304 else if (icon_info->prelight)
3306 GdkPixbuf *temp_pixbuf;
3308 temp_pixbuf = gdk_pixbuf_copy (pixbuf);
3309 colorshift_pixbuf (temp_pixbuf, pixbuf, 30);
3310 g_object_unref (pixbuf);
3311 pixbuf = temp_pixbuf;
3314 gdk_cairo_set_source_pixbuf (cr, pixbuf, x, y);
3317 g_object_unref (pixbuf);
3322 gtk_entry_draw_frame (GtkWidget *widget,
3325 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
3328 gint x = 0, y = 0, width, height;
3330 GtkAllocation allocation;
3331 gint frame_x, frame_y;
3335 window = gtk_widget_get_window (widget);
3337 get_frame_size (GTK_ENTRY (widget), &frame_x, &frame_y, &width, &height);
3338 gtk_widget_get_allocation (widget, &allocation);
3340 cairo_translate (cr, frame_x - allocation.x, frame_y - allocation.y);
3342 /* Fix a problem with some themes which assume that entry->text_area's
3343 * width equals widget->window's width
3344 * http://bugzilla.gnome.org/show_bug.cgi?id=466000 */
3345 if (GTK_IS_SPIN_BUTTON (widget))
3347 gint xborder, yborder;
3349 gtk_entry_get_text_area_size (GTK_ENTRY (widget), &x, NULL, &width, NULL);
3350 _gtk_entry_get_borders (GTK_ENTRY (widget), &xborder, &yborder);
3353 width += xborder * 2;
3356 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3358 x += priv->focus_width;
3359 y += priv->focus_width;
3360 width -= 2 * priv->focus_width;
3361 height -= 2 * priv->focus_width;
3364 style = gtk_widget_get_style (widget);
3365 state = gtk_widget_has_focus (widget) ?
3366 GTK_STATE_ACTIVE : gtk_widget_get_state (widget);
3368 gtk_paint_flat_box (style, cr,
3369 state, GTK_SHADOW_NONE,
3371 x, y, width, height);
3373 gtk_paint_shadow (style, cr,
3374 state, priv->shadow_type,
3375 widget, "entry", x, y, width, height);
3378 gtk_entry_draw_progress (widget, cr);
3380 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3382 x -= priv->focus_width;
3383 y -= priv->focus_width;
3384 width += 2 * priv->focus_width;
3385 height += 2 * priv->focus_width;
3387 gtk_paint_focus (style, cr,
3388 gtk_widget_get_state (widget),
3390 0, 0, width, height);
3397 get_progress_area (GtkWidget *widget,
3403 GtkEntryPrivate *private = GTK_ENTRY_GET_PRIVATE (widget);
3404 GtkEntry *entry = GTK_ENTRY (widget);
3405 GtkBorder *progress_border;
3407 get_text_area_size (entry, x, y, width, height);
3409 if (!private->interior_focus)
3411 *x -= private->focus_width;
3412 *y -= private->focus_width;
3413 *width += 2 * private->focus_width;
3414 *height += 2 * private->focus_width;
3417 gtk_widget_style_get (widget, "progress-border", &progress_border, NULL);
3419 if (progress_border)
3421 *x += progress_border->left;
3422 *y += progress_border->top;
3423 *width -= progress_border->left + progress_border->right;
3424 *height -= progress_border->top + progress_border->bottom;
3426 gtk_border_free (progress_border);
3429 if (private->progress_pulse_mode)
3431 gdouble value = private->progress_pulse_current;
3433 *x += (gint) floor(value * (*width));
3434 *width = (gint) ceil(private->progress_pulse_fraction * (*width));
3436 else if (private->progress_fraction > 0)
3438 gdouble value = private->progress_fraction;
3440 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
3444 bar_width = floor(value * (*width) + 0.5);
3445 *x += *width - bar_width;
3450 *width = (gint) floor(value * (*width) + 0.5);
3461 gtk_entry_draw_progress (GtkWidget *widget,
3464 gint x, y, width, height;
3467 get_progress_area (widget, &x, &y, &width, &height);
3469 if ((width <= 0) || (height <= 0))
3472 state = GTK_STATE_SELECTED;
3473 if (!gtk_widget_get_sensitive (widget))
3474 state = GTK_STATE_INSENSITIVE;
3476 gtk_paint_box (gtk_widget_get_style (widget), cr,
3477 state, GTK_SHADOW_OUT,
3478 widget, "entry-progress",
3484 gtk_entry_draw (GtkWidget *widget,
3487 GtkEntry *entry = GTK_ENTRY (widget);
3490 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3493 style = gtk_widget_get_style (widget);
3495 state = gtk_widget_has_focus (widget) ?
3496 GTK_STATE_ACTIVE : gtk_widget_get_state (widget);
3498 if (gtk_cairo_should_draw_window (cr, gtk_widget_get_window (widget)))
3500 /* Draw entry_bg, shadow, progress and focus */
3501 gtk_entry_draw_frame (widget, cr);
3503 /* Draw text and cursor */
3506 gtk_cairo_transform_to_window (cr, widget, entry->text_area);
3508 if (entry->dnd_position != -1)
3509 gtk_entry_draw_cursor (GTK_ENTRY (widget), cr, CURSOR_DND);
3511 gtk_entry_draw_text (GTK_ENTRY (widget), cr);
3513 /* When no text is being displayed at all, don't show the cursor */
3514 if (gtk_entry_get_display_mode (entry) != DISPLAY_BLANK &&
3515 gtk_widget_has_focus (widget) &&
3516 entry->selection_bound == entry->current_pos && entry->cursor_visible)
3517 gtk_entry_draw_cursor (GTK_ENTRY (widget), cr, CURSOR_STANDARD);
3522 for (i = 0; i < MAX_ICONS; i++)
3524 EntryIconInfo *icon_info = priv->icons[i];
3526 if (icon_info != NULL)
3530 gtk_cairo_transform_to_window (cr, widget, icon_info->window);
3532 draw_icon (widget, cr, i);
3543 gtk_entry_enter_notify (GtkWidget *widget,
3544 GdkEventCrossing *event)
3546 GtkEntry *entry = GTK_ENTRY (widget);
3547 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3550 for (i = 0; i < MAX_ICONS; i++)
3552 EntryIconInfo *icon_info = priv->icons[i];
3554 if (icon_info != NULL && event->window == icon_info->window)
3556 if (should_prelight (entry, i))
3558 icon_info->prelight = TRUE;
3559 gtk_widget_queue_draw (widget);
3570 gtk_entry_leave_notify (GtkWidget *widget,
3571 GdkEventCrossing *event)
3573 GtkEntry *entry = GTK_ENTRY (widget);
3574 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3577 for (i = 0; i < MAX_ICONS; i++)
3579 EntryIconInfo *icon_info = priv->icons[i];
3581 if (icon_info != NULL && event->window == icon_info->window)
3583 /* a grab means that we may never see the button release */
3584 if (event->mode == GDK_CROSSING_GRAB || event->mode == GDK_CROSSING_GTK_GRAB)
3585 icon_info->pressed = FALSE;
3587 if (should_prelight (entry, i))
3589 icon_info->prelight = FALSE;
3590 gtk_widget_queue_draw (widget);
3601 gtk_entry_get_pixel_ranges (GtkEntry *entry,
3605 gint start_char, end_char;
3607 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start_char, &end_char))
3609 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
3610 PangoLayoutLine *line = pango_layout_get_lines_readonly (layout)->data;
3611 const char *text = pango_layout_get_text (layout);
3612 gint start_index = g_utf8_offset_to_pointer (text, start_char) - text;
3613 gint end_index = g_utf8_offset_to_pointer (text, end_char) - text;
3614 gint real_n_ranges, i;
3616 pango_layout_line_get_x_ranges (line, start_index, end_index, ranges, &real_n_ranges);
3622 for (i = 0; i < real_n_ranges; ++i)
3624 r[2 * i + 1] = (r[2 * i + 1] - r[2 * i]) / PANGO_SCALE;
3625 r[2 * i] = r[2 * i] / PANGO_SCALE;
3630 *n_ranges = real_n_ranges;
3642 in_selection (GtkEntry *entry,
3647 gint retval = FALSE;
3649 gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
3651 for (i = 0; i < n_ranges; ++i)
3653 if (x >= ranges[2 * i] && x < ranges[2 * i] + ranges[2 * i + 1])
3665 gtk_entry_button_press (GtkWidget *widget,
3666 GdkEventButton *event)
3668 GtkEntry *entry = GTK_ENTRY (widget);
3669 GtkEditable *editable = GTK_EDITABLE (widget);
3670 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3671 EntryIconInfo *icon_info = NULL;
3673 gint sel_start, sel_end;
3676 for (i = 0; i < MAX_ICONS; i++)
3678 icon_info = priv->icons[i];
3680 if (!icon_info || icon_info->insensitive)
3683 if (event->window == icon_info->window)
3685 if (should_prelight (entry, i))
3687 icon_info->prelight = FALSE;
3688 gtk_widget_queue_draw (widget);
3691 priv->start_x = event->x;
3692 priv->start_y = event->y;
3693 icon_info->pressed = TRUE;
3695 if (!icon_info->nonactivatable)
3696 g_signal_emit (entry, signals[ICON_PRESS], 0, i, event);
3702 if (event->window != entry->text_area ||
3703 (entry->button && event->button != entry->button))
3706 gtk_entry_reset_blink_time (entry);
3708 entry->button = event->button;
3710 if (!gtk_widget_has_focus (widget))
3712 entry->in_click = TRUE;
3713 gtk_widget_grab_focus (widget);
3714 entry->in_click = FALSE;
3717 tmp_pos = gtk_entry_find_position (entry, event->x + entry->scroll_offset);
3719 if (event->button == 1)
3721 gboolean have_selection = gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end);
3723 entry->select_words = FALSE;
3724 entry->select_lines = FALSE;
3726 if (event->state & GDK_SHIFT_MASK)
3728 _gtk_entry_reset_im_context (entry);
3730 if (!have_selection) /* select from the current position to the clicked position */
3731 sel_start = sel_end = entry->current_pos;
3733 if (tmp_pos > sel_start && tmp_pos < sel_end)
3735 /* Truncate current selection, but keep it as big as possible */
3736 if (tmp_pos - sel_start > sel_end - tmp_pos)
3737 gtk_entry_set_positions (entry, sel_start, tmp_pos);
3739 gtk_entry_set_positions (entry, tmp_pos, sel_end);
3743 gboolean extend_to_left;
3746 /* Figure out what click selects and extend current selection */
3747 switch (event->type)
3749 case GDK_BUTTON_PRESS:
3750 gtk_entry_set_positions (entry, tmp_pos, tmp_pos);
3753 case GDK_2BUTTON_PRESS:
3754 entry->select_words = TRUE;
3755 gtk_entry_select_word (entry);
3758 case GDK_3BUTTON_PRESS:
3759 entry->select_lines = TRUE;
3760 gtk_entry_select_line (entry);
3767 start = MIN (entry->current_pos, entry->selection_bound);
3768 start = MIN (sel_start, start);
3770 end = MAX (entry->current_pos, entry->selection_bound);
3771 end = MAX (sel_end, end);
3773 if (tmp_pos == sel_start || tmp_pos == sel_end)
3774 extend_to_left = (tmp_pos == start);
3776 extend_to_left = (end == sel_end);
3779 gtk_entry_set_positions (entry, start, end);
3781 gtk_entry_set_positions (entry, end, start);
3784 else /* no shift key */
3785 switch (event->type)
3787 case GDK_BUTTON_PRESS:
3788 if (in_selection (entry, event->x + entry->scroll_offset))
3790 /* Click inside the selection - we'll either start a drag, or
3791 * clear the selection
3793 entry->in_drag = TRUE;
3794 entry->drag_start_x = event->x + entry->scroll_offset;
3795 entry->drag_start_y = event->y;
3798 gtk_editable_set_position (editable, tmp_pos);
3801 case GDK_2BUTTON_PRESS:
3802 /* We ALWAYS receive a GDK_BUTTON_PRESS immediately before
3803 * receiving a GDK_2BUTTON_PRESS so we need to reset
3804 * entry->in_drag which may have been set above
3806 entry->in_drag = FALSE;
3807 entry->select_words = TRUE;
3808 gtk_entry_select_word (entry);
3811 case GDK_3BUTTON_PRESS:
3812 /* We ALWAYS receive a GDK_BUTTON_PRESS immediately before
3813 * receiving a GDK_3BUTTON_PRESS so we need to reset
3814 * entry->in_drag which may have been set above
3816 entry->in_drag = FALSE;
3817 entry->select_lines = TRUE;
3818 gtk_entry_select_line (entry);
3827 else if (event->button == 2 && event->type == GDK_BUTTON_PRESS)
3829 if (entry->editable)
3831 priv->insert_pos = tmp_pos;
3832 gtk_entry_paste (entry, GDK_SELECTION_PRIMARY);
3837 gtk_widget_error_bell (widget);
3840 else if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
3842 gtk_entry_do_popup (entry, event);
3843 entry->button = 0; /* Don't wait for release, since the menu will gtk_grab_add */
3852 gtk_entry_button_release (GtkWidget *widget,
3853 GdkEventButton *event)
3855 GtkEntry *entry = GTK_ENTRY (widget);
3856 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
3857 EntryIconInfo *icon_info = NULL;
3860 for (i = 0; i < MAX_ICONS; i++)
3862 icon_info = priv->icons[i];
3864 if (!icon_info || icon_info->insensitive)
3867 if (event->window == icon_info->window)
3869 icon_info->pressed = FALSE;
3871 if (should_prelight (entry, i) &&
3872 event->x >= 0 && event->y >= 0 &&
3873 event->x < gdk_window_get_width (icon_info->window) &&
3874 event->y < gdk_window_get_height (icon_info->window))
3876 icon_info->prelight = TRUE;
3877 gtk_widget_queue_draw (widget);
3880 if (!icon_info->nonactivatable)
3881 g_signal_emit (entry, signals[ICON_RELEASE], 0, i, event);
3887 if (event->window != entry->text_area || entry->button != event->button)
3892 gint tmp_pos = gtk_entry_find_position (entry, entry->drag_start_x);
3894 gtk_editable_set_position (GTK_EDITABLE (entry), tmp_pos);
3901 gtk_entry_update_primary_selection (entry);
3907 _gtk_entry_get_selected_text (GtkEntry *entry)
3909 GtkEditable *editable = GTK_EDITABLE (entry);
3910 gint start_text, end_text;
3913 if (gtk_editable_get_selection_bounds (editable, &start_text, &end_text))
3914 text = gtk_editable_get_chars (editable, start_text, end_text);
3920 gtk_entry_motion_notify (GtkWidget *widget,
3921 GdkEventMotion *event)
3923 GtkEntry *entry = GTK_ENTRY (widget);
3924 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3925 EntryIconInfo *icon_info = NULL;
3926 GdkDragContext *context;
3930 for (i = 0; i < MAX_ICONS; i++)
3932 icon_info = priv->icons[i];
3934 if (!icon_info || icon_info->insensitive)
3937 if (event->window == icon_info->window)
3939 if (icon_info->pressed &&
3940 icon_info->target_list != NULL &&
3941 gtk_drag_check_threshold (widget,
3947 icon_info->in_drag = TRUE;
3948 icon_info->pressed = FALSE;
3949 context = gtk_drag_begin (widget,
3950 icon_info->target_list,
3960 if (entry->mouse_cursor_obscured)
3964 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
3965 gdk_window_set_cursor (entry->text_area, cursor);
3966 gdk_cursor_unref (cursor);
3967 entry->mouse_cursor_obscured = FALSE;
3970 if (event->window != entry->text_area || entry->button != 1)
3973 if (entry->select_lines)
3976 gdk_event_request_motions (event);
3980 if (gtk_entry_get_display_mode (entry) == DISPLAY_NORMAL &&
3981 gtk_drag_check_threshold (widget,
3982 entry->drag_start_x, entry->drag_start_y,
3983 event->x + entry->scroll_offset, event->y))
3985 GdkDragContext *context;
3986 GtkTargetList *target_list = gtk_target_list_new (NULL, 0);
3987 guint actions = entry->editable ? GDK_ACTION_COPY | GDK_ACTION_MOVE : GDK_ACTION_COPY;
3989 cairo_surface_t *surface;
3991 gtk_target_list_add_text_targets (target_list, 0);
3993 text = _gtk_entry_get_selected_text (entry);
3994 surface = _gtk_text_util_create_drag_icon (widget, text, -1);
3996 context = gtk_drag_begin (widget, target_list, actions,
3997 entry->button, (GdkEvent *)event);
4000 gtk_drag_set_icon_surface (context, surface);
4002 gtk_drag_set_icon_default (context);
4005 cairo_surface_destroy (surface);
4008 entry->in_drag = FALSE;
4011 gtk_target_list_unref (target_list);
4018 else if (event->y >= gdk_window_get_height (entry->text_area))
4019 tmp_pos = gtk_entry_buffer_get_length (get_buffer (entry));
4021 tmp_pos = gtk_entry_find_position (entry, event->x + entry->scroll_offset);
4023 if (entry->select_words)
4026 gint old_min, old_max;
4029 min = gtk_entry_move_backward_word (entry, tmp_pos, TRUE);
4030 max = gtk_entry_move_forward_word (entry, tmp_pos, TRUE);
4032 pos = entry->current_pos;
4033 bound = entry->selection_bound;
4035 old_min = MIN(entry->current_pos, entry->selection_bound);
4036 old_max = MAX(entry->current_pos, entry->selection_bound);
4043 else if (old_max < max)
4048 else if (pos == old_min)
4050 if (entry->current_pos != min)
4055 if (entry->current_pos != max)
4059 gtk_entry_set_positions (entry, pos, bound);
4062 gtk_entry_set_positions (entry, tmp_pos, -1);
4069 set_invisible_cursor (GdkWindow *window)
4071 GdkDisplay *display;
4074 display = gdk_window_get_display (window);
4075 cursor = gdk_cursor_new_for_display (display, GDK_BLANK_CURSOR);
4077 gdk_window_set_cursor (window, cursor);
4079 gdk_cursor_unref (cursor);
4083 gtk_entry_obscure_mouse_cursor (GtkEntry *entry)
4085 if (entry->mouse_cursor_obscured)
4088 set_invisible_cursor (entry->text_area);
4090 entry->mouse_cursor_obscured = TRUE;
4094 gtk_entry_key_press (GtkWidget *widget,
4097 GtkEntry *entry = GTK_ENTRY (widget);
4099 gtk_entry_reset_blink_time (entry);
4100 gtk_entry_pend_cursor_blink (entry);
4102 if (entry->editable)
4104 if (gtk_im_context_filter_keypress (entry->im_context, event))
4106 gtk_entry_obscure_mouse_cursor (entry);
4107 entry->need_im_reset = TRUE;
4112 if (event->keyval == GDK_KEY_Return ||
4113 event->keyval == GDK_KEY_KP_Enter ||
4114 event->keyval == GDK_KEY_ISO_Enter ||
4115 event->keyval == GDK_KEY_Escape)
4117 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
4119 if (completion && completion->priv->completion_timeout)
4121 g_source_remove (completion->priv->completion_timeout);
4122 completion->priv->completion_timeout = 0;
4125 _gtk_entry_reset_im_context (entry);
4128 if (GTK_WIDGET_CLASS (gtk_entry_parent_class)->key_press_event (widget, event))
4129 /* Activate key bindings
4133 if (!entry->editable && event->length)
4134 gtk_widget_error_bell (widget);
4140 gtk_entry_key_release (GtkWidget *widget,
4143 GtkEntry *entry = GTK_ENTRY (widget);
4145 if (entry->editable)
4147 if (gtk_im_context_filter_keypress (entry->im_context, event))
4149 entry->need_im_reset = TRUE;
4154 return GTK_WIDGET_CLASS (gtk_entry_parent_class)->key_release_event (widget, event);
4158 gtk_entry_focus_in (GtkWidget *widget,
4159 GdkEventFocus *event)
4161 GtkEntry *entry = GTK_ENTRY (widget);
4164 gtk_widget_queue_draw (widget);
4166 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (widget));
4168 if (entry->editable)
4170 entry->need_im_reset = TRUE;
4171 gtk_im_context_focus_in (entry->im_context);
4172 keymap_state_changed (keymap, entry);
4173 g_signal_connect (keymap, "state-changed",
4174 G_CALLBACK (keymap_state_changed), entry);
4177 g_signal_connect (keymap, "direction-changed",
4178 G_CALLBACK (keymap_direction_changed), entry);
4180 gtk_entry_reset_blink_time (entry);
4181 gtk_entry_check_cursor_blink (entry);
4187 gtk_entry_focus_out (GtkWidget *widget,
4188 GdkEventFocus *event)
4190 GtkEntry *entry = GTK_ENTRY (widget);
4191 GtkEntryCompletion *completion;
4194 gtk_widget_queue_draw (widget);
4196 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (widget));
4198 if (entry->editable)
4200 entry->need_im_reset = TRUE;
4201 gtk_im_context_focus_out (entry->im_context);
4202 remove_capslock_feedback (entry);
4205 gtk_entry_check_cursor_blink (entry);
4207 g_signal_handlers_disconnect_by_func (keymap, keymap_state_changed, entry);
4208 g_signal_handlers_disconnect_by_func (keymap, keymap_direction_changed, entry);
4210 completion = gtk_entry_get_completion (entry);
4212 _gtk_entry_completion_popdown (completion);
4218 gtk_entry_grab_focus (GtkWidget *widget)
4220 GtkEntry *entry = GTK_ENTRY (widget);
4221 gboolean select_on_focus;
4223 GTK_WIDGET_CLASS (gtk_entry_parent_class)->grab_focus (widget);
4225 if (entry->editable && !entry->in_click)
4227 g_object_get (gtk_widget_get_settings (widget),
4228 "gtk-entry-select-on-focus",
4232 if (select_on_focus)
4233 gtk_editable_select_region (GTK_EDITABLE (widget), 0, -1);
4238 gtk_entry_direction_changed (GtkWidget *widget,
4239 GtkTextDirection previous_dir)
4241 GtkEntry *entry = GTK_ENTRY (widget);
4243 gtk_entry_recompute (entry);
4245 GTK_WIDGET_CLASS (gtk_entry_parent_class)->direction_changed (widget, previous_dir);
4249 gtk_entry_state_changed (GtkWidget *widget,
4250 GtkStateType previous_state)
4252 GtkEntry *entry = GTK_ENTRY (widget);
4255 if (gtk_widget_get_realized (widget))
4257 if (gtk_widget_is_sensitive (widget))
4258 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
4262 gdk_window_set_cursor (entry->text_area, cursor);
4265 gdk_cursor_unref (cursor);
4267 entry->mouse_cursor_obscured = FALSE;
4269 update_cursors (widget);
4272 if (!gtk_widget_is_sensitive (widget))
4274 /* Clear any selection */
4275 gtk_editable_select_region (GTK_EDITABLE (entry), entry->current_pos, entry->current_pos);
4278 gtk_widget_queue_draw (widget);
4282 gtk_entry_screen_changed (GtkWidget *widget,
4283 GdkScreen *old_screen)
4285 gtk_entry_recompute (GTK_ENTRY (widget));
4288 /* GtkEditable method implementations
4291 gtk_entry_insert_text (GtkEditable *editable,
4292 const gchar *new_text,
4293 gint new_text_length,
4296 g_object_ref (editable);
4299 * The incoming text may a password or other secret. We make sure
4300 * not to copy it into temporary buffers.
4303 g_signal_emit_by_name (editable, "insert-text", new_text, new_text_length, position);
4305 g_object_unref (editable);
4309 gtk_entry_delete_text (GtkEditable *editable,
4313 g_object_ref (editable);
4315 g_signal_emit_by_name (editable, "delete-text", start_pos, end_pos);
4317 g_object_unref (editable);
4321 gtk_entry_get_chars (GtkEditable *editable,
4325 GtkEntry *entry = GTK_ENTRY (editable);
4328 gint start_index, end_index;
4330 text = gtk_entry_buffer_get_text (get_buffer (entry));
4331 text_length = gtk_entry_buffer_get_length (get_buffer (entry));
4334 end_pos = text_length;
4336 start_pos = MIN (text_length, start_pos);
4337 end_pos = MIN (text_length, end_pos);
4339 start_index = g_utf8_offset_to_pointer (text, start_pos) - text;
4340 end_index = g_utf8_offset_to_pointer (text, end_pos) - text;
4342 return g_strndup (text + start_index, end_index - start_index);
4346 gtk_entry_real_set_position (GtkEditable *editable,
4349 GtkEntry *entry = GTK_ENTRY (editable);
4353 length = gtk_entry_buffer_get_length (get_buffer (entry));
4354 if (position < 0 || position > length)
4357 if (position != entry->current_pos ||
4358 position != entry->selection_bound)
4360 _gtk_entry_reset_im_context (entry);
4361 gtk_entry_set_positions (entry, position, position);
4366 gtk_entry_get_position (GtkEditable *editable)
4368 return GTK_ENTRY (editable)->current_pos;
4372 gtk_entry_set_selection_bounds (GtkEditable *editable,
4376 GtkEntry *entry = GTK_ENTRY (editable);
4379 length = gtk_entry_buffer_get_length (get_buffer (entry));
4385 _gtk_entry_reset_im_context (entry);
4387 gtk_entry_set_positions (entry,
4389 MIN (start, length));
4391 gtk_entry_update_primary_selection (entry);
4395 gtk_entry_get_selection_bounds (GtkEditable *editable,
4399 GtkEntry *entry = GTK_ENTRY (editable);
4401 *start = entry->selection_bound;
4402 *end = entry->current_pos;
4404 return (entry->selection_bound != entry->current_pos);
4408 icon_theme_changed (GtkEntry *entry)
4410 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
4413 for (i = 0; i < MAX_ICONS; i++)
4415 EntryIconInfo *icon_info = priv->icons[i];
4416 if (icon_info != NULL)
4418 if (icon_info->storage_type == GTK_IMAGE_ICON_NAME)
4419 gtk_entry_set_icon_from_icon_name (entry, i, icon_info->icon_name);
4420 else if (icon_info->storage_type == GTK_IMAGE_STOCK)
4421 gtk_entry_set_icon_from_stock (entry, i, icon_info->stock_id);
4422 else if (icon_info->storage_type == GTK_IMAGE_GICON)
4423 gtk_entry_set_icon_from_gicon (entry, i, icon_info->gicon);
4427 gtk_widget_queue_draw (GTK_WIDGET (entry));
4431 icon_margin_changed (GtkEntry *entry)
4433 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
4436 _gtk_entry_effective_inner_border (GTK_ENTRY (entry), &border);
4438 priv->icon_margin = border.left;
4442 gtk_entry_style_set (GtkWidget *widget,
4443 GtkStyle *previous_style)
4445 GtkEntry *entry = GTK_ENTRY (widget);
4446 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
4448 gboolean interior_focus;
4450 gtk_widget_style_get (widget,
4451 "focus-line-width", &focus_width,
4452 "interior-focus", &interior_focus,
4455 priv->focus_width = focus_width;
4456 priv->interior_focus = interior_focus;
4458 if (!priv->invisible_char_set)
4459 entry->invisible_char = find_invisible_char (GTK_WIDGET (entry));
4461 gtk_entry_recompute (entry);
4463 icon_theme_changed (entry);
4464 icon_margin_changed (entry);
4467 /* GtkCellEditable method implementations
4470 gtk_cell_editable_entry_activated (GtkEntry *entry, gpointer data)
4472 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4473 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4477 gtk_cell_editable_key_press_event (GtkEntry *entry,
4478 GdkEventKey *key_event,
4481 if (key_event->keyval == GDK_KEY_Escape)
4483 entry->editing_canceled = TRUE;
4484 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4485 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4490 /* override focus */
4491 if (key_event->keyval == GDK_KEY_Up || key_event->keyval == GDK_KEY_Down)
4493 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4494 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4503 gtk_entry_start_editing (GtkCellEditable *cell_editable,
4506 GTK_ENTRY (cell_editable)->is_cell_renderer = TRUE;
4508 g_signal_connect (cell_editable, "activate",
4509 G_CALLBACK (gtk_cell_editable_entry_activated), NULL);
4510 g_signal_connect (cell_editable, "key-press-event",
4511 G_CALLBACK (gtk_cell_editable_key_press_event), NULL);
4515 gtk_entry_password_hint_free (GtkEntryPasswordHint *password_hint)
4517 if (password_hint->source_id)
4518 g_source_remove (password_hint->source_id);
4520 g_slice_free (GtkEntryPasswordHint, password_hint);
4525 gtk_entry_remove_password_hint (gpointer data)
4527 GtkEntryPasswordHint *password_hint = g_object_get_qdata (data, quark_password_hint);
4528 password_hint->position = -1;
4530 /* Force the string to be redrawn, but now without a visible character */
4531 gtk_entry_recompute (GTK_ENTRY (data));
4535 /* Default signal handlers
4538 gtk_entry_real_insert_text (GtkEditable *editable,
4539 const gchar *new_text,
4540 gint new_text_length,
4546 n_chars = g_utf8_strlen (new_text, new_text_length);
4549 * The actual insertion into the buffer. This will end up firing the
4550 * following signal handlers: buffer_inserted_text(), buffer_notify_display_text(),
4551 * buffer_notify_text(), buffer_notify_length()
4553 n_inserted = gtk_entry_buffer_insert_text (get_buffer (GTK_ENTRY (editable)), *position, new_text, n_chars);
4555 if (n_inserted != n_chars)
4556 gtk_widget_error_bell (GTK_WIDGET (editable));
4558 *position += n_inserted;
4562 gtk_entry_real_delete_text (GtkEditable *editable,
4567 * The actual deletion from the buffer. This will end up firing the
4568 * following signal handlers: buffer_deleted_text(), buffer_notify_display_text(),
4569 * buffer_notify_text(), buffer_notify_length()
4572 gtk_entry_buffer_delete_text (get_buffer (GTK_ENTRY (editable)), start_pos, end_pos - start_pos);
4575 /* GtkEntryBuffer signal handlers
4578 buffer_inserted_text (GtkEntryBuffer *buffer,
4584 guint password_hint_timeout;
4586 if (entry->current_pos > position)
4587 entry->current_pos += n_chars;
4589 if (entry->selection_bound > position)
4590 entry->selection_bound += n_chars;
4592 /* Calculate the password hint if it needs to be displayed. */
4593 if (n_chars == 1 && !entry->visible)
4595 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
4596 "gtk-entry-password-hint-timeout", &password_hint_timeout,
4599 if (password_hint_timeout > 0)
4601 GtkEntryPasswordHint *password_hint = g_object_get_qdata (G_OBJECT (entry),
4602 quark_password_hint);
4605 password_hint = g_slice_new0 (GtkEntryPasswordHint);
4606 g_object_set_qdata_full (G_OBJECT (entry), quark_password_hint, password_hint,
4607 (GDestroyNotify)gtk_entry_password_hint_free);
4610 password_hint->position = position;
4611 if (password_hint->source_id)
4612 g_source_remove (password_hint->source_id);
4613 password_hint->source_id = gdk_threads_add_timeout (password_hint_timeout,
4614 (GSourceFunc)gtk_entry_remove_password_hint, entry);
4620 buffer_deleted_text (GtkEntryBuffer *buffer,
4625 guint end_pos = position + n_chars;
4626 gint selection_bound;
4629 current_pos = entry->current_pos;
4630 if (current_pos > position)
4631 current_pos -= MIN (current_pos, end_pos) - position;
4633 selection_bound = entry->selection_bound;
4634 if (selection_bound > position)
4635 selection_bound -= MIN (selection_bound, end_pos) - position;
4637 gtk_entry_set_positions (entry, current_pos, selection_bound);
4639 /* We might have deleted the selection */
4640 gtk_entry_update_primary_selection (entry);
4642 /* Disable the password hint if one exists. */
4643 if (!entry->visible)
4645 GtkEntryPasswordHint *password_hint = g_object_get_qdata (G_OBJECT (entry),
4646 quark_password_hint);
4649 if (password_hint->source_id)
4650 g_source_remove (password_hint->source_id);
4651 password_hint->source_id = 0;
4652 password_hint->position = -1;
4658 buffer_notify_text (GtkEntryBuffer *buffer,
4662 gtk_entry_recompute (entry);
4663 emit_changed (entry);
4664 g_object_notify (G_OBJECT (entry), "text");
4668 buffer_notify_length (GtkEntryBuffer *buffer,
4672 g_object_notify (G_OBJECT (entry), "text-length");
4676 buffer_notify_max_length (GtkEntryBuffer *buffer,
4680 g_object_notify (G_OBJECT (entry), "max-length");
4684 buffer_connect_signals (GtkEntry *entry)
4686 g_signal_connect (get_buffer (entry), "inserted-text", G_CALLBACK (buffer_inserted_text), entry);
4687 g_signal_connect (get_buffer (entry), "deleted-text", G_CALLBACK (buffer_deleted_text), entry);
4688 g_signal_connect (get_buffer (entry), "notify::text", G_CALLBACK (buffer_notify_text), entry);
4689 g_signal_connect (get_buffer (entry), "notify::length", G_CALLBACK (buffer_notify_length), entry);
4690 g_signal_connect (get_buffer (entry), "notify::max-length", G_CALLBACK (buffer_notify_max_length), entry);
4694 buffer_disconnect_signals (GtkEntry *entry)
4696 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_inserted_text, entry);
4697 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_deleted_text, entry);
4698 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_text, entry);
4699 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_length, entry);
4700 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_max_length, entry);
4703 /* Compute the X position for an offset that corresponds to the "more important
4704 * cursor position for that offset. We use this when trying to guess to which
4705 * end of the selection we should go to when the user hits the left or
4709 get_better_cursor_x (GtkEntry *entry,
4712 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
4713 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
4714 gboolean split_cursor;
4716 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
4717 const gchar *text = pango_layout_get_text (layout);
4718 gint index = g_utf8_offset_to_pointer (text, offset) - text;
4720 PangoRectangle strong_pos, weak_pos;
4722 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
4723 "gtk-split-cursor", &split_cursor,
4726 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
4729 return strong_pos.x / PANGO_SCALE;
4731 return (keymap_direction == entry->resolved_dir) ? strong_pos.x / PANGO_SCALE : weak_pos.x / PANGO_SCALE;
4735 gtk_entry_move_cursor (GtkEntry *entry,
4736 GtkMovementStep step,
4738 gboolean extend_selection)
4740 gint new_pos = entry->current_pos;
4741 GtkEntryPrivate *priv;
4743 _gtk_entry_reset_im_context (entry);
4745 if (entry->current_pos != entry->selection_bound && !extend_selection)
4747 /* If we have a current selection and aren't extending it, move to the
4748 * start/or end of the selection as appropriate
4752 case GTK_MOVEMENT_VISUAL_POSITIONS:
4754 gint current_x = get_better_cursor_x (entry, entry->current_pos);
4755 gint bound_x = get_better_cursor_x (entry, entry->selection_bound);
4758 new_pos = current_x < bound_x ? entry->current_pos : entry->selection_bound;
4760 new_pos = current_x > bound_x ? entry->current_pos : entry->selection_bound;
4763 case GTK_MOVEMENT_LOGICAL_POSITIONS:
4764 case GTK_MOVEMENT_WORDS:
4766 new_pos = MIN (entry->current_pos, entry->selection_bound);
4768 new_pos = MAX (entry->current_pos, entry->selection_bound);
4770 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
4771 case GTK_MOVEMENT_PARAGRAPH_ENDS:
4772 case GTK_MOVEMENT_BUFFER_ENDS:
4773 priv = GTK_ENTRY_GET_PRIVATE (entry);
4774 new_pos = count < 0 ? 0 : gtk_entry_buffer_get_length (get_buffer (entry));
4776 case GTK_MOVEMENT_DISPLAY_LINES:
4777 case GTK_MOVEMENT_PARAGRAPHS:
4778 case GTK_MOVEMENT_PAGES:
4779 case GTK_MOVEMENT_HORIZONTAL_PAGES:
4787 case GTK_MOVEMENT_LOGICAL_POSITIONS:
4788 new_pos = gtk_entry_move_logically (entry, new_pos, count);
4790 case GTK_MOVEMENT_VISUAL_POSITIONS:
4791 new_pos = gtk_entry_move_visually (entry, new_pos, count);
4792 if (entry->current_pos == new_pos)
4794 if (!extend_selection)
4796 if (!gtk_widget_keynav_failed (GTK_WIDGET (entry),
4798 GTK_DIR_RIGHT : GTK_DIR_LEFT))
4800 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (entry));
4803 gtk_widget_child_focus (toplevel,
4805 GTK_DIR_RIGHT : GTK_DIR_LEFT);
4810 gtk_widget_error_bell (GTK_WIDGET (entry));
4814 case GTK_MOVEMENT_WORDS:
4817 new_pos = gtk_entry_move_forward_word (entry, new_pos, FALSE);
4822 new_pos = gtk_entry_move_backward_word (entry, new_pos, FALSE);
4825 if (entry->current_pos == new_pos)
4826 gtk_widget_error_bell (GTK_WIDGET (entry));
4828 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
4829 case GTK_MOVEMENT_PARAGRAPH_ENDS:
4830 case GTK_MOVEMENT_BUFFER_ENDS:
4831 priv = GTK_ENTRY_GET_PRIVATE (entry);
4832 new_pos = count < 0 ? 0 : gtk_entry_buffer_get_length (get_buffer (entry));
4833 if (entry->current_pos == new_pos)
4834 gtk_widget_error_bell (GTK_WIDGET (entry));
4836 case GTK_MOVEMENT_DISPLAY_LINES:
4837 case GTK_MOVEMENT_PARAGRAPHS:
4838 case GTK_MOVEMENT_PAGES:
4839 case GTK_MOVEMENT_HORIZONTAL_PAGES:
4844 if (extend_selection)
4845 gtk_editable_select_region (GTK_EDITABLE (entry), entry->selection_bound, new_pos);
4847 gtk_editable_set_position (GTK_EDITABLE (entry), new_pos);
4849 gtk_entry_pend_cursor_blink (entry);
4853 gtk_entry_insert_at_cursor (GtkEntry *entry,
4856 GtkEditable *editable = GTK_EDITABLE (entry);
4857 gint pos = entry->current_pos;
4859 if (entry->editable)
4861 _gtk_entry_reset_im_context (entry);
4863 gtk_editable_insert_text (editable, str, -1, &pos);
4864 gtk_editable_set_position (editable, pos);
4869 gtk_entry_delete_from_cursor (GtkEntry *entry,
4873 GtkEditable *editable = GTK_EDITABLE (entry);
4874 gint start_pos = entry->current_pos;
4875 gint end_pos = entry->current_pos;
4876 gint old_n_bytes = gtk_entry_buffer_get_bytes (get_buffer (entry));
4878 _gtk_entry_reset_im_context (entry);
4880 if (!entry->editable)
4882 gtk_widget_error_bell (GTK_WIDGET (entry));
4886 if (entry->selection_bound != entry->current_pos)
4888 gtk_editable_delete_selection (editable);
4894 case GTK_DELETE_CHARS:
4895 end_pos = gtk_entry_move_logically (entry, entry->current_pos, count);
4896 gtk_editable_delete_text (editable, MIN (start_pos, end_pos), MAX (start_pos, end_pos));
4898 case GTK_DELETE_WORDS:
4901 /* Move to end of current word, or if not on a word, end of previous word */
4902 end_pos = gtk_entry_move_backward_word (entry, end_pos, FALSE);
4903 end_pos = gtk_entry_move_forward_word (entry, end_pos, FALSE);
4907 /* Move to beginning of current word, or if not on a word, begining of next word */
4908 start_pos = gtk_entry_move_forward_word (entry, start_pos, FALSE);
4909 start_pos = gtk_entry_move_backward_word (entry, start_pos, FALSE);
4913 case GTK_DELETE_WORD_ENDS:
4916 start_pos = gtk_entry_move_backward_word (entry, start_pos, FALSE);
4921 end_pos = gtk_entry_move_forward_word (entry, end_pos, FALSE);
4924 gtk_editable_delete_text (editable, start_pos, end_pos);
4926 case GTK_DELETE_DISPLAY_LINE_ENDS:
4927 case GTK_DELETE_PARAGRAPH_ENDS:
4929 gtk_editable_delete_text (editable, 0, entry->current_pos);
4931 gtk_editable_delete_text (editable, entry->current_pos, -1);
4933 case GTK_DELETE_DISPLAY_LINES:
4934 case GTK_DELETE_PARAGRAPHS:
4935 gtk_editable_delete_text (editable, 0, -1);
4937 case GTK_DELETE_WHITESPACE:
4938 gtk_entry_delete_whitespace (entry);
4942 if (gtk_entry_buffer_get_bytes (get_buffer (entry)) == old_n_bytes)
4943 gtk_widget_error_bell (GTK_WIDGET (entry));
4945 gtk_entry_pend_cursor_blink (entry);
4949 gtk_entry_backspace (GtkEntry *entry)
4951 GtkEditable *editable = GTK_EDITABLE (entry);
4954 _gtk_entry_reset_im_context (entry);
4956 if (!entry->editable)
4958 gtk_widget_error_bell (GTK_WIDGET (entry));
4962 if (entry->selection_bound != entry->current_pos)
4964 gtk_editable_delete_selection (editable);
4968 prev_pos = gtk_entry_move_logically (entry, entry->current_pos, -1);
4970 if (prev_pos < entry->current_pos)
4972 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
4973 PangoLogAttr *log_attrs;
4976 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
4978 /* Deleting parts of characters */
4979 if (log_attrs[entry->current_pos].backspace_deletes_character)
4981 gchar *cluster_text;
4982 gchar *normalized_text;
4985 cluster_text = gtk_entry_get_display_text (entry, prev_pos,
4986 entry->current_pos);
4987 normalized_text = g_utf8_normalize (cluster_text,
4988 strlen (cluster_text),
4990 len = g_utf8_strlen (normalized_text, -1);
4992 gtk_editable_delete_text (editable, prev_pos, entry->current_pos);
4995 gint pos = entry->current_pos;
4997 gtk_editable_insert_text (editable, normalized_text,
4998 g_utf8_offset_to_pointer (normalized_text, len - 1) - normalized_text,
5000 gtk_editable_set_position (editable, pos);
5003 g_free (normalized_text);
5004 g_free (cluster_text);
5008 gtk_editable_delete_text (editable, prev_pos, entry->current_pos);
5015 gtk_widget_error_bell (GTK_WIDGET (entry));
5018 gtk_entry_pend_cursor_blink (entry);
5022 gtk_entry_copy_clipboard (GtkEntry *entry)
5024 GtkEditable *editable = GTK_EDITABLE (entry);
5028 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5030 if (!entry->visible)
5032 gtk_widget_error_bell (GTK_WIDGET (entry));
5036 str = gtk_entry_get_display_text (entry, start, end);
5037 gtk_clipboard_set_text (gtk_widget_get_clipboard (GTK_WIDGET (entry),
5038 GDK_SELECTION_CLIPBOARD),
5045 gtk_entry_cut_clipboard (GtkEntry *entry)
5047 GtkEditable *editable = GTK_EDITABLE (entry);
5050 if (!entry->visible)
5052 gtk_widget_error_bell (GTK_WIDGET (entry));
5056 gtk_entry_copy_clipboard (entry);
5058 if (entry->editable)
5060 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5061 gtk_editable_delete_text (editable, start, end);
5065 gtk_widget_error_bell (GTK_WIDGET (entry));
5070 gtk_entry_paste_clipboard (GtkEntry *entry)
5072 if (entry->editable)
5073 gtk_entry_paste (entry, GDK_NONE);
5075 gtk_widget_error_bell (GTK_WIDGET (entry));
5079 gtk_entry_delete_cb (GtkEntry *entry)
5081 GtkEditable *editable = GTK_EDITABLE (entry);
5084 if (entry->editable)
5086 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5087 gtk_editable_delete_text (editable, start, end);
5092 gtk_entry_toggle_overwrite (GtkEntry *entry)
5094 entry->overwrite_mode = !entry->overwrite_mode;
5095 gtk_entry_pend_cursor_blink (entry);
5096 gtk_widget_queue_draw (GTK_WIDGET (entry));
5100 gtk_entry_select_all (GtkEntry *entry)
5102 gtk_entry_select_line (entry);
5106 gtk_entry_real_activate (GtkEntry *entry)
5109 GtkWidget *default_widget, *focus_widget;
5110 GtkWidget *toplevel;
5113 widget = GTK_WIDGET (entry);
5115 if (entry->activates_default)
5117 toplevel = gtk_widget_get_toplevel (widget);
5118 if (GTK_IS_WINDOW (toplevel))
5120 window = GTK_WINDOW (toplevel);
5124 default_widget = gtk_window_get_default_widget (window);
5125 focus_widget = gtk_window_get_focus (window);
5126 if (widget != default_widget &&
5127 !(widget == focus_widget && (!default_widget || !gtk_widget_get_sensitive (default_widget))))
5128 gtk_window_activate_default (window);
5135 keymap_direction_changed (GdkKeymap *keymap,
5138 gtk_entry_recompute (entry);
5141 /* IM Context Callbacks
5145 gtk_entry_commit_cb (GtkIMContext *context,
5149 if (entry->editable)
5150 gtk_entry_enter_text (entry, str);
5154 gtk_entry_preedit_changed_cb (GtkIMContext *context,
5157 if (entry->editable)
5159 gchar *preedit_string;
5162 gtk_im_context_get_preedit_string (entry->im_context,
5163 &preedit_string, NULL,
5165 g_signal_emit (entry, signals[PREEDIT_CHANGED], 0, preedit_string);
5166 entry->preedit_length = strlen (preedit_string);
5167 cursor_pos = CLAMP (cursor_pos, 0, g_utf8_strlen (preedit_string, -1));
5168 entry->preedit_cursor = cursor_pos;
5169 g_free (preedit_string);
5171 gtk_entry_recompute (entry);
5176 gtk_entry_retrieve_surrounding_cb (GtkIMContext *context,
5181 /* XXXX ??? does this even make sense when text is not visible? Should we return FALSE? */
5182 text = gtk_entry_get_display_text (entry, 0, -1);
5183 gtk_im_context_set_surrounding (context, text, strlen (text), /* Length in bytes */
5184 g_utf8_offset_to_pointer (text, entry->current_pos) - text);
5191 gtk_entry_delete_surrounding_cb (GtkIMContext *slave,
5196 if (entry->editable)
5197 gtk_editable_delete_text (GTK_EDITABLE (entry),
5198 entry->current_pos + offset,
5199 entry->current_pos + offset + n_chars);
5204 /* Internal functions
5207 /* Used for im_commit_cb and inserting Unicode chars */
5209 gtk_entry_enter_text (GtkEntry *entry,
5212 GtkEditable *editable = GTK_EDITABLE (entry);
5214 gboolean old_need_im_reset;
5216 old_need_im_reset = entry->need_im_reset;
5217 entry->need_im_reset = FALSE;
5219 if (gtk_editable_get_selection_bounds (editable, NULL, NULL))
5220 gtk_editable_delete_selection (editable);
5223 if (entry->overwrite_mode)
5224 gtk_entry_delete_from_cursor (entry, GTK_DELETE_CHARS, 1);
5227 tmp_pos = entry->current_pos;
5228 gtk_editable_insert_text (editable, str, strlen (str), &tmp_pos);
5229 gtk_editable_set_position (editable, tmp_pos);
5231 entry->need_im_reset = old_need_im_reset;
5234 /* All changes to entry->current_pos and entry->selection_bound
5235 * should go through this function.
5238 gtk_entry_set_positions (GtkEntry *entry,
5240 gint selection_bound)
5242 gboolean changed = FALSE;
5244 g_object_freeze_notify (G_OBJECT (entry));
5246 if (current_pos != -1 &&
5247 entry->current_pos != current_pos)
5249 entry->current_pos = current_pos;
5252 g_object_notify (G_OBJECT (entry), "cursor-position");
5255 if (selection_bound != -1 &&
5256 entry->selection_bound != selection_bound)
5258 entry->selection_bound = selection_bound;
5261 g_object_notify (G_OBJECT (entry), "selection-bound");
5264 g_object_thaw_notify (G_OBJECT (entry));
5268 gtk_entry_move_adjustments (entry);
5269 gtk_entry_recompute (entry);
5274 gtk_entry_reset_layout (GtkEntry *entry)
5276 if (entry->cached_layout)
5278 g_object_unref (entry->cached_layout);
5279 entry->cached_layout = NULL;
5284 update_im_cursor_location (GtkEntry *entry)
5288 gint strong_xoffset;
5289 gint area_width, area_height;
5291 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
5292 gtk_entry_get_text_area_size (entry, NULL, NULL, &area_width, &area_height);
5294 strong_xoffset = strong_x - entry->scroll_offset;
5295 if (strong_xoffset < 0)
5299 else if (strong_xoffset > area_width)
5301 strong_xoffset = area_width;
5303 area.x = strong_xoffset;
5306 area.height = area_height;
5308 gtk_im_context_set_cursor_location (entry->im_context, &area);
5312 recompute_idle_func (gpointer data)
5316 entry = GTK_ENTRY (data);
5318 entry->recompute_idle = 0;
5320 if (gtk_widget_has_screen (GTK_WIDGET (entry)))
5322 gtk_entry_adjust_scroll (entry);
5323 gtk_entry_queue_draw (entry);
5325 update_im_cursor_location (entry);
5332 gtk_entry_recompute (GtkEntry *entry)
5334 gtk_entry_reset_layout (entry);
5335 gtk_entry_check_cursor_blink (entry);
5337 if (!entry->recompute_idle)
5339 entry->recompute_idle = gdk_threads_add_idle_full (G_PRIORITY_HIGH_IDLE + 15, /* between resize and redraw */
5340 recompute_idle_func, entry, NULL);
5344 static PangoLayout *
5345 gtk_entry_create_layout (GtkEntry *entry,
5346 gboolean include_preedit)
5348 GtkWidget *widget = GTK_WIDGET (entry);
5349 PangoLayout *layout = gtk_widget_create_pango_layout (widget, NULL);
5350 PangoAttrList *tmp_attrs = pango_attr_list_new ();
5352 gchar *preedit_string = NULL;
5353 gint preedit_length = 0;
5354 PangoAttrList *preedit_attrs = NULL;
5359 pango_layout_set_single_paragraph_mode (layout, TRUE);
5361 display = gtk_entry_get_display_text (entry, 0, -1);
5362 n_bytes = strlen (display);
5364 if (include_preedit)
5366 gtk_im_context_get_preedit_string (entry->im_context,
5367 &preedit_string, &preedit_attrs, NULL);
5368 preedit_length = entry->preedit_length;
5373 GString *tmp_string = g_string_new (display);
5374 gint cursor_index = g_utf8_offset_to_pointer (display, entry->current_pos) - display;
5376 g_string_insert (tmp_string, cursor_index, preedit_string);
5378 pango_layout_set_text (layout, tmp_string->str, tmp_string->len);
5380 pango_attr_list_splice (tmp_attrs, preedit_attrs,
5381 cursor_index, preedit_length);
5383 g_string_free (tmp_string, TRUE);
5387 PangoDirection pango_dir;
5389 if (gtk_entry_get_display_mode (entry) == DISPLAY_NORMAL)
5390 pango_dir = pango_find_base_dir (display, n_bytes);
5392 pango_dir = PANGO_DIRECTION_NEUTRAL;
5394 if (pango_dir == PANGO_DIRECTION_NEUTRAL)
5396 if (gtk_widget_has_focus (widget))
5398 GdkDisplay *display = gtk_widget_get_display (widget);
5399 GdkKeymap *keymap = gdk_keymap_get_for_display (display);
5400 if (gdk_keymap_get_direction (keymap) == PANGO_DIRECTION_RTL)
5401 pango_dir = PANGO_DIRECTION_RTL;
5403 pango_dir = PANGO_DIRECTION_LTR;
5407 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
5408 pango_dir = PANGO_DIRECTION_RTL;
5410 pango_dir = PANGO_DIRECTION_LTR;
5414 pango_context_set_base_dir (gtk_widget_get_pango_context (widget),
5417 entry->resolved_dir = pango_dir;
5419 pango_layout_set_text (layout, display, n_bytes);
5422 pango_layout_set_attributes (layout, tmp_attrs);
5424 g_free (preedit_string);
5428 pango_attr_list_unref (preedit_attrs);
5430 pango_attr_list_unref (tmp_attrs);
5435 static PangoLayout *
5436 gtk_entry_ensure_layout (GtkEntry *entry,
5437 gboolean include_preedit)
5439 if (entry->preedit_length > 0 &&
5440 !include_preedit != !entry->cache_includes_preedit)
5441 gtk_entry_reset_layout (entry);
5443 if (!entry->cached_layout)
5445 entry->cached_layout = gtk_entry_create_layout (entry, include_preedit);
5446 entry->cache_includes_preedit = include_preedit;
5449 return entry->cached_layout;
5453 get_layout_position (GtkEntry *entry,
5457 PangoLayout *layout;
5458 PangoRectangle logical_rect;
5459 gint area_width, area_height;
5460 GtkBorder inner_border;
5462 PangoLayoutLine *line;
5464 layout = gtk_entry_ensure_layout (entry, TRUE);
5466 gtk_entry_get_text_area_size (entry, NULL, NULL, &area_width, &area_height);
5467 _gtk_entry_effective_inner_border (entry, &inner_border);
5469 area_height = PANGO_SCALE * (area_height - inner_border.top - inner_border.bottom);
5471 line = pango_layout_get_lines_readonly (layout)->data;
5472 pango_layout_line_get_extents (line, NULL, &logical_rect);
5474 /* Align primarily for locale's ascent/descent */
5475 y_pos = ((area_height - entry->ascent - entry->descent) / 2 +
5476 entry->ascent + logical_rect.y);
5478 /* Now see if we need to adjust to fit in actual drawn string */
5479 if (logical_rect.height > area_height)
5480 y_pos = (area_height - logical_rect.height) / 2;
5483 else if (y_pos + logical_rect.height > area_height)
5484 y_pos = area_height - logical_rect.height;
5486 y_pos = inner_border.top + y_pos / PANGO_SCALE;
5489 *x = inner_border.left - entry->scroll_offset;
5496 draw_text_with_color (GtkEntry *entry, cairo_t *cr, GdkColor *default_color)
5498 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
5501 gint start_pos, end_pos;
5503 widget = GTK_WIDGET (entry);
5507 get_layout_position (entry, &x, &y);
5509 cairo_move_to (cr, x, y);
5510 gdk_cairo_set_source_color (cr, default_color);
5511 pango_cairo_show_layout (cr, layout);
5513 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start_pos, &end_pos))
5517 PangoRectangle logical_rect;
5518 GdkColor *selection_color, *text_color;
5519 GtkBorder inner_border;
5522 pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
5523 gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
5525 style = gtk_widget_get_style (widget);
5527 if (gtk_widget_has_focus (widget))
5529 selection_color = &style->base [GTK_STATE_SELECTED];
5530 text_color = &style->text [GTK_STATE_SELECTED];
5534 selection_color = &style->base [GTK_STATE_ACTIVE];
5535 text_color = &style->text [GTK_STATE_ACTIVE];
5538 _gtk_entry_effective_inner_border (entry, &inner_border);
5540 for (i = 0; i < n_ranges; ++i)
5541 cairo_rectangle (cr,
5542 inner_border.left - entry->scroll_offset + ranges[2 * i],
5545 logical_rect.height);
5549 gdk_cairo_set_source_color (cr, selection_color);
5552 cairo_move_to (cr, x, y);
5553 gdk_cairo_set_source_color (cr, text_color);
5554 pango_cairo_show_layout (cr, layout);
5562 gtk_entry_draw_text (GtkEntry *entry,
5565 GtkWidget *widget = GTK_WIDGET (entry);
5568 GdkColor text_color, bar_text_color;
5571 gint progress_x, progress_y, progress_width, progress_height;
5572 gint clip_width, clip_height;
5574 /* Nothing to display at all */
5575 if (gtk_entry_get_display_mode (entry) == DISPLAY_BLANK)
5578 state = GTK_STATE_SELECTED;
5579 if (!gtk_widget_get_sensitive (widget))
5580 state = GTK_STATE_INSENSITIVE;
5581 style = gtk_widget_get_style (widget);
5582 text_color = style->text[gtk_widget_get_state (widget)];
5583 bar_text_color = style->fg[state];
5585 get_progress_area (widget,
5586 &progress_x, &progress_y,
5587 &progress_width, &progress_height);
5589 clip_width = gdk_window_get_width (entry->text_area);
5590 clip_height = gdk_window_get_height (entry->text_area);
5591 cairo_rectangle (cr, 0, 0, clip_width, clip_height);
5594 /* If the color is the same, or the progress area has a zero
5595 * size, then we only need to draw once. */
5596 if ((text_color.pixel == bar_text_color.pixel) ||
5597 ((progress_width == 0) || (progress_height == 0)))
5599 draw_text_with_color (entry, cr, &text_color);
5603 width = gdk_window_get_width (entry->text_area);
5604 height = gdk_window_get_height (entry->text_area);
5608 cairo_rectangle (cr, 0, 0, width, height);
5612 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
5613 cairo_rectangle (cr, 0, 0, width, height);
5615 gdk_window_get_position (entry->text_area, &pos_x, &pos_y);
5616 progress_x -= pos_x;
5617 progress_y -= pos_y;
5619 cairo_rectangle (cr, progress_x, progress_y,
5620 progress_width, progress_height);
5622 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_WINDING);
5624 draw_text_with_color (entry, cr, &text_color);
5627 cairo_rectangle (cr, progress_x, progress_y,
5628 progress_width, progress_height);
5631 draw_text_with_color (entry, cr, &bar_text_color);
5638 draw_insertion_cursor (GtkEntry *entry,
5640 GdkRectangle *cursor_location,
5641 gboolean is_primary,
5642 PangoDirection direction,
5643 gboolean draw_arrow)
5645 GtkWidget *widget = GTK_WIDGET (entry);
5646 GtkTextDirection text_dir;
5648 if (direction == PANGO_DIRECTION_LTR)
5649 text_dir = GTK_TEXT_DIR_LTR;
5651 text_dir = GTK_TEXT_DIR_RTL;
5653 gtk_draw_insertion_cursor (widget, cr,
5655 is_primary, text_dir, draw_arrow);
5659 gtk_entry_draw_cursor (GtkEntry *entry,
5663 GtkWidget *widget = GTK_WIDGET (entry);
5664 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
5665 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
5666 GdkRectangle cursor_location;
5667 gboolean split_cursor;
5668 PangoRectangle cursor_rect;
5669 GtkBorder inner_border;
5671 gint text_area_height;
5674 gboolean block_at_line_end;
5675 PangoLayout *layout;
5678 _gtk_entry_effective_inner_border (entry, &inner_border);
5680 xoffset = inner_border.left - entry->scroll_offset;
5682 text_area_height = gdk_window_get_height (entry->text_area);
5684 layout = gtk_entry_ensure_layout (entry, TRUE);
5685 text = pango_layout_get_text (layout);
5686 cursor_index = g_utf8_offset_to_pointer (text, entry->current_pos + entry->preedit_cursor) - text;
5687 if (!entry->overwrite_mode)
5690 block = _gtk_text_util_get_block_cursor_location (layout,
5691 cursor_index, &cursor_rect, &block_at_line_end);
5695 gint strong_x, weak_x;
5696 PangoDirection dir1 = PANGO_DIRECTION_NEUTRAL;
5697 PangoDirection dir2 = PANGO_DIRECTION_NEUTRAL;
5701 gtk_entry_get_cursor_locations (entry, type, &strong_x, &weak_x);
5703 g_object_get (gtk_widget_get_settings (widget),
5704 "gtk-split-cursor", &split_cursor,
5707 dir1 = entry->resolved_dir;
5713 if (weak_x != strong_x)
5715 dir2 = (entry->resolved_dir == PANGO_DIRECTION_LTR) ? PANGO_DIRECTION_RTL : PANGO_DIRECTION_LTR;
5721 if (keymap_direction == entry->resolved_dir)
5727 cursor_location.x = xoffset + x1;
5728 cursor_location.y = inner_border.top;
5729 cursor_location.width = 0;
5730 cursor_location.height = text_area_height - inner_border.top - inner_border.bottom;
5732 draw_insertion_cursor (entry, cr,
5733 &cursor_location, TRUE, dir1,
5734 dir2 != PANGO_DIRECTION_NEUTRAL);
5736 if (dir2 != PANGO_DIRECTION_NEUTRAL)
5738 cursor_location.x = xoffset + x2;
5739 draw_insertion_cursor (entry, cr,
5740 &cursor_location, FALSE, dir2,
5744 else /* overwrite_mode */
5746 GdkColor cursor_color;
5752 get_layout_position (entry, &x, &y);
5754 rect.x = PANGO_PIXELS (cursor_rect.x) + x;
5755 rect.y = PANGO_PIXELS (cursor_rect.y) + y;
5756 rect.width = PANGO_PIXELS (cursor_rect.width);
5757 rect.height = PANGO_PIXELS (cursor_rect.height);
5759 _gtk_widget_get_cursor_color (widget, &cursor_color);
5760 gdk_cairo_set_source_color (cr, &cursor_color);
5761 gdk_cairo_rectangle (cr, &rect);
5764 if (!block_at_line_end)
5766 gdk_cairo_rectangle (cr, &rect);
5768 cairo_move_to (cr, x, y);
5769 gdk_cairo_set_source_color (cr, >k_widget_get_style (widget)->base[gtk_widget_get_state (widget)]);
5770 pango_cairo_show_layout (cr, layout);
5778 gtk_entry_queue_draw (GtkEntry *entry)
5780 if (gtk_widget_is_drawable (GTK_WIDGET (entry)))
5781 gdk_window_invalidate_rect (gtk_widget_get_window (GTK_WIDGET (entry)),
5786 _gtk_entry_reset_im_context (GtkEntry *entry)
5788 if (entry->need_im_reset)
5790 entry->need_im_reset = FALSE;
5791 gtk_im_context_reset (entry->im_context);
5796 * gtk_entry_reset_im_context:
5797 * @entry: a #GtkEntry
5799 * Reset the input method context of the entry if needed.
5801 * This can be necessary in the case where modifying the buffer
5802 * would confuse on-going input method behavior.
5807 gtk_entry_reset_im_context (GtkEntry *entry)
5809 g_return_if_fail (GTK_IS_ENTRY (entry));
5811 _gtk_entry_reset_im_context (entry);
5815 * gtk_entry_im_context_filter_keypress:
5816 * @entry: a #GtkEntry
5817 * @event: the key event
5819 * Allow the #GtkEntry input method to internally handle key press
5820 * and release events. If this function returns %TRUE, then no further
5821 * processing should be done for this key event. See
5822 * gtk_im_context_filter_keypress().
5824 * Note that you are expected to call this function from your handler
5825 * when overriding key event handling. This is needed in the case when
5826 * you need to insert your own key handling between the input method
5827 * and the default key event handling of the #GtkEntry.
5828 * See gtk_text_view_reset_im_context() for an example of use.
5830 * Return value: %TRUE if the input method handled the key event.
5835 gtk_entry_im_context_filter_keypress (GtkEntry *entry,
5838 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
5840 return gtk_im_context_filter_keypress (entry->im_context, event);
5845 gtk_entry_find_position (GtkEntry *entry,
5848 PangoLayout *layout;
5849 PangoLayoutLine *line;
5856 layout = gtk_entry_ensure_layout (entry, TRUE);
5857 text = pango_layout_get_text (layout);
5858 cursor_index = g_utf8_offset_to_pointer (text, entry->current_pos) - text;
5860 line = pango_layout_get_lines_readonly (layout)->data;
5861 pango_layout_line_x_to_index (line, x * PANGO_SCALE, &index, &trailing);
5863 if (index >= cursor_index && entry->preedit_length)
5865 if (index >= cursor_index + entry->preedit_length)
5866 index -= entry->preedit_length;
5869 index = cursor_index;
5874 pos = g_utf8_pointer_to_offset (text, text + index);
5881 gtk_entry_get_cursor_locations (GtkEntry *entry,
5886 DisplayMode mode = gtk_entry_get_display_mode (entry);
5888 /* Nothing to display at all, so no cursor is relevant */
5889 if (mode == DISPLAY_BLANK)
5899 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
5900 const gchar *text = pango_layout_get_text (layout);
5901 PangoRectangle strong_pos, weak_pos;
5904 if (type == CURSOR_STANDARD)
5906 index = g_utf8_offset_to_pointer (text, entry->current_pos + entry->preedit_cursor) - text;
5908 else /* type == CURSOR_DND */
5910 index = g_utf8_offset_to_pointer (text, entry->dnd_position) - text;
5912 if (entry->dnd_position > entry->current_pos)
5914 if (mode == DISPLAY_NORMAL)
5915 index += entry->preedit_length;
5918 gint preedit_len_chars = g_utf8_strlen (text, -1) - gtk_entry_buffer_get_length (get_buffer (entry));
5919 index += preedit_len_chars * g_unichar_to_utf8 (entry->invisible_char, NULL);
5924 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
5927 *strong_x = strong_pos.x / PANGO_SCALE;
5930 *weak_x = weak_pos.x / PANGO_SCALE;
5935 gtk_entry_adjust_scroll (GtkEntry *entry)
5937 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
5938 gint min_offset, max_offset;
5939 gint text_area_width, text_width;
5940 GtkBorder inner_border;
5941 gint strong_x, weak_x;
5942 gint strong_xoffset, weak_xoffset;
5944 PangoLayout *layout;
5945 PangoLayoutLine *line;
5946 PangoRectangle logical_rect;
5948 if (!gtk_widget_get_realized (GTK_WIDGET (entry)))
5951 _gtk_entry_effective_inner_border (entry, &inner_border);
5953 text_area_width = gdk_window_get_width (entry->text_area);
5954 text_area_width -= inner_border.left + inner_border.right;
5955 if (text_area_width < 0)
5956 text_area_width = 0;
5958 layout = gtk_entry_ensure_layout (entry, TRUE);
5959 line = pango_layout_get_lines_readonly (layout)->data;
5961 pango_layout_line_get_extents (line, NULL, &logical_rect);
5963 /* Display as much text as we can */
5965 if (entry->resolved_dir == PANGO_DIRECTION_LTR)
5966 xalign = priv->xalign;
5968 xalign = 1.0 - priv->xalign;
5970 text_width = PANGO_PIXELS(logical_rect.width);
5972 if (text_width > text_area_width)
5975 max_offset = text_width - text_area_width;
5979 min_offset = (text_width - text_area_width) * xalign;
5980 max_offset = min_offset;
5983 entry->scroll_offset = CLAMP (entry->scroll_offset, min_offset, max_offset);
5985 /* And make sure cursors are on screen. Note that the cursor is
5986 * actually drawn one pixel into the INNER_BORDER space on
5987 * the right, when the scroll is at the utmost right. This
5988 * looks better to to me than confining the cursor inside the
5989 * border entirely, though it means that the cursor gets one
5990 * pixel closer to the edge of the widget on the right than
5991 * on the left. This might need changing if one changed
5992 * INNER_BORDER from 2 to 1, as one would do on a
5993 * small-screen-real-estate display.
5995 * We always make sure that the strong cursor is on screen, and
5996 * put the weak cursor on screen if possible.
5999 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, &weak_x);
6001 strong_xoffset = strong_x - entry->scroll_offset;
6003 if (strong_xoffset < 0)
6005 entry->scroll_offset += strong_xoffset;
6008 else if (strong_xoffset > text_area_width)
6010 entry->scroll_offset += strong_xoffset - text_area_width;
6011 strong_xoffset = text_area_width;
6014 weak_xoffset = weak_x - entry->scroll_offset;
6016 if (weak_xoffset < 0 && strong_xoffset - weak_xoffset <= text_area_width)
6018 entry->scroll_offset += weak_xoffset;
6020 else if (weak_xoffset > text_area_width &&
6021 strong_xoffset - (weak_xoffset - text_area_width) >= 0)
6023 entry->scroll_offset += weak_xoffset - text_area_width;
6026 g_object_notify (G_OBJECT (entry), "scroll-offset");
6030 gtk_entry_move_adjustments (GtkEntry *entry)
6032 GtkAllocation allocation;
6033 GtkAdjustment *adjustment;
6034 PangoContext *context;
6035 PangoFontMetrics *metrics;
6036 gint x, layout_x, border_x, border_y;
6039 adjustment = g_object_get_qdata (G_OBJECT (entry), quark_cursor_hadjustment);
6043 gtk_widget_get_allocation (&(entry->widget), &allocation);
6045 /* Cursor position, layout offset, border width, and widget allocation */
6046 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &x, NULL);
6047 get_layout_position (entry, &layout_x, NULL);
6048 _gtk_entry_get_borders (entry, &border_x, &border_y);
6049 x += allocation.x + layout_x + border_x;
6051 /* Approximate width of a char, so user can see what is ahead/behind */
6052 context = gtk_widget_get_pango_context (GTK_WIDGET (entry));
6053 metrics = pango_context_get_metrics (context,
6054 gtk_widget_get_style (&(entry->widget))->font_desc,
6055 pango_context_get_language (context));
6056 char_width = pango_font_metrics_get_approximate_char_width (metrics) / PANGO_SCALE;
6059 gtk_adjustment_clamp_page (adjustment,
6060 x - (char_width + 1), /* one char + one pixel before */
6061 x + (char_width + 2)); /* one char + cursor + one pixel after */
6065 gtk_entry_move_visually (GtkEntry *entry,
6070 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6073 text = pango_layout_get_text (layout);
6075 index = g_utf8_offset_to_pointer (text, start) - text;
6079 int new_index, new_trailing;
6080 gboolean split_cursor;
6083 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
6084 "gtk-split-cursor", &split_cursor,
6091 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
6092 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
6094 strong = keymap_direction == entry->resolved_dir;
6099 pango_layout_move_cursor_visually (layout, strong, index, 0, 1, &new_index, &new_trailing);
6104 pango_layout_move_cursor_visually (layout, strong, index, 0, -1, &new_index, &new_trailing);
6110 else if (new_index != G_MAXINT)
6113 while (new_trailing--)
6114 index = g_utf8_next_char (text + index) - text;
6117 return g_utf8_pointer_to_offset (text, text + index);
6121 gtk_entry_move_logically (GtkEntry *entry,
6125 gint new_pos = start;
6128 length = gtk_entry_buffer_get_length (get_buffer (entry));
6130 /* Prevent any leak of information */
6131 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6133 new_pos = CLAMP (start + count, 0, length);
6137 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6138 PangoLogAttr *log_attrs;
6141 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6143 while (count > 0 && new_pos < length)
6147 while (new_pos < length && !log_attrs[new_pos].is_cursor_position);
6151 while (count < 0 && new_pos > 0)
6155 while (new_pos > 0 && !log_attrs[new_pos].is_cursor_position);
6167 gtk_entry_move_forward_word (GtkEntry *entry,
6169 gboolean allow_whitespace)
6171 gint new_pos = start;
6174 length = gtk_entry_buffer_get_length (get_buffer (entry));
6176 /* Prevent any leak of information */
6177 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6181 else if (new_pos < length)
6183 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6184 PangoLogAttr *log_attrs;
6187 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6189 /* Find the next word boundary */
6191 while (new_pos < n_attrs - 1 && !(log_attrs[new_pos].is_word_end ||
6192 (log_attrs[new_pos].is_word_start && allow_whitespace)))
6203 gtk_entry_move_backward_word (GtkEntry *entry,
6205 gboolean allow_whitespace)
6207 gint new_pos = start;
6209 /* Prevent any leak of information */
6210 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6216 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6217 PangoLogAttr *log_attrs;
6220 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6222 new_pos = start - 1;
6224 /* Find the previous word boundary */
6225 while (new_pos > 0 && !(log_attrs[new_pos].is_word_start ||
6226 (log_attrs[new_pos].is_word_end && allow_whitespace)))
6236 gtk_entry_delete_whitespace (GtkEntry *entry)
6238 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6239 PangoLogAttr *log_attrs;
6243 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6245 start = end = entry->current_pos;
6247 while (start > 0 && log_attrs[start-1].is_white)
6250 while (end < n_attrs && log_attrs[end].is_white)
6256 gtk_editable_delete_text (GTK_EDITABLE (entry), start, end);
6261 gtk_entry_select_word (GtkEntry *entry)
6263 gint start_pos = gtk_entry_move_backward_word (entry, entry->current_pos, TRUE);
6264 gint end_pos = gtk_entry_move_forward_word (entry, entry->current_pos, TRUE);
6266 gtk_editable_select_region (GTK_EDITABLE (entry), start_pos, end_pos);
6270 gtk_entry_select_line (GtkEntry *entry)
6272 gtk_editable_select_region (GTK_EDITABLE (entry), 0, -1);
6276 truncate_multiline (const gchar *text)
6281 text[length] && text[length] != '\n' && text[length] != '\r';
6288 paste_received (GtkClipboard *clipboard,
6292 GtkEntry *entry = GTK_ENTRY (data);
6293 GtkEditable *editable = GTK_EDITABLE (entry);
6294 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
6296 if (entry->button == 2)
6298 gint pos, start, end;
6299 pos = priv->insert_pos;
6300 gtk_editable_get_selection_bounds (editable, &start, &end);
6301 if (!((start <= pos && pos <= end) || (end <= pos && pos <= start)))
6302 gtk_editable_select_region (editable, pos, pos);
6307 gint pos, start, end;
6309 gboolean popup_completion;
6310 GtkEntryCompletion *completion;
6312 completion = gtk_entry_get_completion (entry);
6314 if (entry->truncate_multiline)
6315 length = truncate_multiline (text);
6317 /* only complete if the selection is at the end */
6318 popup_completion = (gtk_entry_buffer_get_length (get_buffer (entry)) ==
6319 MAX (entry->current_pos, entry->selection_bound));
6323 if (gtk_widget_get_mapped (completion->priv->popup_window))
6324 _gtk_entry_completion_popdown (completion);
6326 if (!popup_completion && completion->priv->changed_id > 0)
6327 g_signal_handler_block (entry, completion->priv->changed_id);
6330 begin_change (entry);
6331 g_object_freeze_notify (G_OBJECT (entry));
6332 if (gtk_editable_get_selection_bounds (editable, &start, &end))
6333 gtk_editable_delete_text (editable, start, end);
6335 pos = entry->current_pos;
6336 gtk_editable_insert_text (editable, text, length, &pos);
6337 gtk_editable_set_position (editable, pos);
6338 g_object_thaw_notify (G_OBJECT (entry));
6342 !popup_completion && completion->priv->changed_id > 0)
6343 g_signal_handler_unblock (entry, completion->priv->changed_id);
6346 g_object_unref (entry);
6350 gtk_entry_paste (GtkEntry *entry,
6353 g_object_ref (entry);
6354 gtk_clipboard_request_text (gtk_widget_get_clipboard (GTK_WIDGET (entry), selection),
6355 paste_received, entry);
6359 primary_get_cb (GtkClipboard *clipboard,
6360 GtkSelectionData *selection_data,
6364 GtkEntry *entry = GTK_ENTRY (data);
6367 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end))
6369 gchar *str = gtk_entry_get_display_text (entry, start, end);
6370 gtk_selection_data_set_text (selection_data, str, -1);
6376 primary_clear_cb (GtkClipboard *clipboard,
6379 GtkEntry *entry = GTK_ENTRY (data);
6381 gtk_editable_select_region (GTK_EDITABLE (entry), entry->current_pos, entry->current_pos);
6385 gtk_entry_update_primary_selection (GtkEntry *entry)
6387 GtkTargetList *list;
6388 GtkTargetEntry *targets;
6389 GtkClipboard *clipboard;
6393 if (!gtk_widget_get_realized (GTK_WIDGET (entry)))
6396 list = gtk_target_list_new (NULL, 0);
6397 gtk_target_list_add_text_targets (list, 0);
6399 targets = gtk_target_table_new_from_list (list, &n_targets);
6401 clipboard = gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_PRIMARY);
6403 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end))
6405 if (!gtk_clipboard_set_with_owner (clipboard, targets, n_targets,
6406 primary_get_cb, primary_clear_cb, G_OBJECT (entry)))
6407 primary_clear_cb (clipboard, entry);
6411 if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (entry))
6412 gtk_clipboard_clear (clipboard);
6415 gtk_target_table_free (targets, n_targets);
6416 gtk_target_list_unref (list);
6420 gtk_entry_clear (GtkEntry *entry,
6421 GtkEntryIconPosition icon_pos)
6423 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
6424 EntryIconInfo *icon_info = priv->icons[icon_pos];
6426 if (!icon_info || icon_info->storage_type == GTK_IMAGE_EMPTY)
6429 g_object_freeze_notify (G_OBJECT (entry));
6431 /* Explicitly check, as the pointer may become invalidated
6432 * during destruction.
6434 if (GDK_IS_WINDOW (icon_info->window))
6435 gdk_window_hide (icon_info->window);
6437 if (icon_info->pixbuf)
6439 g_object_unref (icon_info->pixbuf);
6440 icon_info->pixbuf = NULL;
6443 switch (icon_info->storage_type)
6445 case GTK_IMAGE_PIXBUF:
6446 g_object_notify (G_OBJECT (entry),
6447 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-pixbuf" : "secondary-icon-pixbuf");
6450 case GTK_IMAGE_STOCK:
6451 g_free (icon_info->stock_id);
6452 icon_info->stock_id = NULL;
6453 g_object_notify (G_OBJECT (entry),
6454 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-stock" : "secondary-icon-stock");
6457 case GTK_IMAGE_ICON_NAME:
6458 g_free (icon_info->icon_name);
6459 icon_info->icon_name = NULL;
6460 g_object_notify (G_OBJECT (entry),
6461 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-name" : "secondary-icon-name");
6464 case GTK_IMAGE_GICON:
6465 if (icon_info->gicon)
6467 g_object_unref (icon_info->gicon);
6468 icon_info->gicon = NULL;
6470 g_object_notify (G_OBJECT (entry),
6471 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-gicon" : "secondary-icon-gicon");
6475 g_assert_not_reached ();
6479 icon_info->storage_type = GTK_IMAGE_EMPTY;
6480 g_object_notify (G_OBJECT (entry),
6481 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-storage-type" : "secondary-icon-storage-type");
6483 g_object_thaw_notify (G_OBJECT (entry));
6487 gtk_entry_ensure_pixbuf (GtkEntry *entry,
6488 GtkEntryIconPosition icon_pos)
6490 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
6491 EntryIconInfo *icon_info = priv->icons[icon_pos];
6493 GtkIconTheme *icon_theme;
6494 GtkSettings *settings;
6500 if (!icon_info || icon_info->pixbuf)
6503 widget = GTK_WIDGET (entry);
6505 switch (icon_info->storage_type)
6507 case GTK_IMAGE_EMPTY:
6508 case GTK_IMAGE_PIXBUF:
6510 case GTK_IMAGE_STOCK:
6511 state = gtk_widget_get_state (widget);
6512 gtk_widget_set_state (widget, GTK_STATE_NORMAL);
6513 icon_info->pixbuf = gtk_widget_render_icon (widget,
6514 icon_info->stock_id,
6517 if (!icon_info->pixbuf)
6518 icon_info->pixbuf = gtk_widget_render_icon (widget,
6519 GTK_STOCK_MISSING_IMAGE,
6522 gtk_widget_set_state (widget, state);
6525 case GTK_IMAGE_ICON_NAME:
6526 screen = gtk_widget_get_screen (widget);
6529 icon_theme = gtk_icon_theme_get_for_screen (screen);
6530 settings = gtk_settings_get_for_screen (screen);
6532 gtk_icon_size_lookup_for_settings (settings,
6536 icon_info->pixbuf = gtk_icon_theme_load_icon (icon_theme,
6537 icon_info->icon_name,
6538 MIN (width, height),
6541 if (icon_info->pixbuf == NULL)
6543 state = gtk_widget_get_state (widget);
6544 gtk_widget_set_state (widget, GTK_STATE_NORMAL);
6545 icon_info->pixbuf = gtk_widget_render_icon (widget,
6546 GTK_STOCK_MISSING_IMAGE,
6549 gtk_widget_set_state (widget, state);
6554 case GTK_IMAGE_GICON:
6555 screen = gtk_widget_get_screen (widget);
6558 icon_theme = gtk_icon_theme_get_for_screen (screen);
6559 settings = gtk_settings_get_for_screen (screen);
6561 gtk_icon_size_lookup_for_settings (settings,
6565 info = gtk_icon_theme_lookup_by_gicon (icon_theme,
6567 MIN (width, height),
6568 GTK_ICON_LOOKUP_USE_BUILTIN);
6571 icon_info->pixbuf = gtk_icon_info_load_icon (info, NULL);
6572 gtk_icon_info_free (info);
6575 if (icon_info->pixbuf == NULL)
6577 state = gtk_widget_get_state (widget);
6578 gtk_widget_set_state (widget, GTK_STATE_NORMAL);
6579 icon_info->pixbuf = gtk_widget_render_icon (widget,
6580 GTK_STOCK_MISSING_IMAGE,
6583 gtk_widget_set_state (widget, state);
6589 g_assert_not_reached ();
6593 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
6594 gdk_window_show_unraised (icon_info->window);
6604 * Creates a new entry.
6606 * Return value: a new #GtkEntry.
6609 gtk_entry_new (void)
6611 return g_object_new (GTK_TYPE_ENTRY, NULL);
6615 * gtk_entry_new_with_buffer:
6616 * @buffer: The buffer to use for the new #GtkEntry.
6618 * Creates a new entry with the specified text buffer.
6620 * Return value: a new #GtkEntry
6625 gtk_entry_new_with_buffer (GtkEntryBuffer *buffer)
6627 g_return_val_if_fail (GTK_IS_ENTRY_BUFFER (buffer), NULL);
6628 return g_object_new (GTK_TYPE_ENTRY, "buffer", buffer, NULL);
6631 static GtkEntryBuffer*
6632 get_buffer (GtkEntry *entry)
6634 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
6636 if (priv->buffer == NULL)
6638 GtkEntryBuffer *buffer;
6639 buffer = gtk_entry_buffer_new (NULL, 0);
6640 gtk_entry_set_buffer (entry, buffer);
6641 g_object_unref (buffer);
6644 return priv->buffer;
6648 * gtk_entry_get_buffer:
6649 * @entry: a #GtkEntry
6651 * Get the #GtkEntryBuffer object which holds the text for
6656 * Returns: (transfer none): A #GtkEntryBuffer object.
6659 gtk_entry_get_buffer (GtkEntry *entry)
6661 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
6663 return get_buffer (entry);
6667 * gtk_entry_set_buffer:
6668 * @entry: a #GtkEntry
6669 * @buffer: a #GtkEntryBuffer
6671 * Set the #GtkEntryBuffer object which holds the text for
6677 gtk_entry_set_buffer (GtkEntry *entry,
6678 GtkEntryBuffer *buffer)
6680 GtkEntryPrivate *priv;
6683 g_return_if_fail (GTK_IS_ENTRY (entry));
6684 priv = GTK_ENTRY_GET_PRIVATE (entry);
6688 g_return_if_fail (GTK_IS_ENTRY_BUFFER (buffer));
6689 g_object_ref (buffer);
6694 buffer_disconnect_signals (entry);
6695 g_object_unref (priv->buffer);
6698 priv->buffer = buffer;
6701 buffer_connect_signals (entry);
6703 obj = G_OBJECT (entry);
6704 g_object_freeze_notify (obj);
6705 g_object_notify (obj, "buffer");
6706 g_object_notify (obj, "text");
6707 g_object_notify (obj, "text-length");
6708 g_object_notify (obj, "max-length");
6709 g_object_notify (obj, "visibility");
6710 g_object_notify (obj, "invisible-char");
6711 g_object_notify (obj, "invisible-char-set");
6712 g_object_thaw_notify (obj);
6714 gtk_editable_set_position (GTK_EDITABLE (entry), 0);
6715 gtk_entry_recompute (entry);
6719 * gtk_entry_get_text_area:
6720 * @entry: a #GtkEntry
6721 * @text_area: Return location for the text area.
6723 * Gets the area where the entry's text is drawn. This function is
6724 * useful when drawing something to the entry in a draw callback.
6726 * If the entry is not realized, @text_area is filled with zeros.
6728 * See also gtk_entry_get_icon_area().
6733 gtk_entry_get_text_area (GtkEntry *entry,
6734 GdkRectangle *text_area)
6736 g_return_if_fail (GTK_IS_ENTRY (entry));
6737 g_return_if_fail (text_area != NULL);
6739 if (entry->text_area)
6741 GtkAllocation allocation;
6744 gtk_widget_get_allocation (GTK_WIDGET (entry), &allocation);
6745 gdk_window_get_position (entry->text_area, &x, &y);
6747 text_area->x = x - allocation.x;
6748 text_area->y = y - allocation.y;
6749 text_area->width = gdk_window_get_width (entry->text_area);
6750 text_area->height = gdk_window_get_height (entry->text_area);
6756 text_area->width = 0;
6757 text_area->height = 0;
6762 * gtk_entry_set_text:
6763 * @entry: a #GtkEntry
6764 * @text: the new text
6766 * Sets the text in the widget to the given
6767 * value, replacing the current contents.
6769 * See gtk_entry_buffer_set_text().
6772 gtk_entry_set_text (GtkEntry *entry,
6776 GtkEntryCompletion *completion;
6777 GtkEntryPrivate *priv;
6779 g_return_if_fail (GTK_IS_ENTRY (entry));
6780 g_return_if_fail (text != NULL);
6781 priv = GTK_ENTRY_GET_PRIVATE (entry);
6783 /* Actually setting the text will affect the cursor and selection;
6784 * if the contents don't actually change, this will look odd to the user.
6786 if (strcmp (gtk_entry_buffer_get_text (get_buffer (entry)), text) == 0)
6789 completion = gtk_entry_get_completion (entry);
6790 if (completion && completion->priv->changed_id > 0)
6791 g_signal_handler_block (entry, completion->priv->changed_id);
6793 begin_change (entry);
6794 g_object_freeze_notify (G_OBJECT (entry));
6795 gtk_editable_delete_text (GTK_EDITABLE (entry), 0, -1);
6797 gtk_editable_insert_text (GTK_EDITABLE (entry), text, strlen (text), &tmp_pos);
6798 g_object_thaw_notify (G_OBJECT (entry));
6801 if (completion && completion->priv->changed_id > 0)
6802 g_signal_handler_unblock (entry, completion->priv->changed_id);
6806 * gtk_entry_set_visibility:
6807 * @entry: a #GtkEntry
6808 * @visible: %TRUE if the contents of the entry are displayed
6811 * Sets whether the contents of the entry are visible or not.
6812 * When visibility is set to %FALSE, characters are displayed
6813 * as the invisible char, and will also appear that way when
6814 * the text in the entry widget is copied elsewhere.
6816 * By default, GTK+ picks the best invisible character available
6817 * in the current font, but it can be changed with
6818 * gtk_entry_set_invisible_char().
6821 gtk_entry_set_visibility (GtkEntry *entry,
6824 g_return_if_fail (GTK_IS_ENTRY (entry));
6826 visible = visible != FALSE;
6828 if (entry->visible != visible)
6830 entry->visible = visible;
6832 g_object_notify (G_OBJECT (entry), "visibility");
6833 gtk_entry_recompute (entry);
6838 * gtk_entry_get_visibility:
6839 * @entry: a #GtkEntry
6841 * Retrieves whether the text in @entry is visible. See
6842 * gtk_entry_set_visibility().
6844 * Return value: %TRUE if the text is currently visible
6847 gtk_entry_get_visibility (GtkEntry *entry)
6849 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
6851 return entry->visible;
6855 * gtk_entry_set_invisible_char:
6856 * @entry: a #GtkEntry
6857 * @ch: a Unicode character
6859 * Sets the character to use in place of the actual text when
6860 * gtk_entry_set_visibility() has been called to set text visibility
6861 * to %FALSE. i.e. this is the character used in "password mode" to
6862 * show the user how many characters have been typed. By default, GTK+
6863 * picks the best invisible char available in the current font. If you
6864 * set the invisible char to 0, then the user will get no feedback
6865 * at all; there will be no text on the screen as they type.
6868 gtk_entry_set_invisible_char (GtkEntry *entry,
6871 GtkEntryPrivate *priv;
6873 g_return_if_fail (GTK_IS_ENTRY (entry));
6875 priv = GTK_ENTRY_GET_PRIVATE (entry);
6877 if (!priv->invisible_char_set)
6879 priv->invisible_char_set = TRUE;
6880 g_object_notify (G_OBJECT (entry), "invisible-char-set");
6883 if (ch == entry->invisible_char)
6886 entry->invisible_char = ch;
6887 g_object_notify (G_OBJECT (entry), "invisible-char");
6888 gtk_entry_recompute (entry);
6892 * gtk_entry_get_invisible_char:
6893 * @entry: a #GtkEntry
6895 * Retrieves the character displayed in place of the real characters
6896 * for entries with visibility set to false. See gtk_entry_set_invisible_char().
6898 * Return value: the current invisible char, or 0, if the entry does not
6899 * show invisible text at all.
6902 gtk_entry_get_invisible_char (GtkEntry *entry)
6904 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
6906 return entry->invisible_char;
6910 * gtk_entry_unset_invisible_char:
6911 * @entry: a #GtkEntry
6913 * Unsets the invisible char previously set with
6914 * gtk_entry_set_invisible_char(). So that the
6915 * default invisible char is used again.
6920 gtk_entry_unset_invisible_char (GtkEntry *entry)
6922 GtkEntryPrivate *priv;
6925 g_return_if_fail (GTK_IS_ENTRY (entry));
6927 priv = GTK_ENTRY_GET_PRIVATE (entry);
6929 if (!priv->invisible_char_set)
6932 priv->invisible_char_set = FALSE;
6933 ch = find_invisible_char (GTK_WIDGET (entry));
6935 if (entry->invisible_char != ch)
6937 entry->invisible_char = ch;
6938 g_object_notify (G_OBJECT (entry), "invisible-char");
6941 g_object_notify (G_OBJECT (entry), "invisible-char-set");
6942 gtk_entry_recompute (entry);
6946 * gtk_entry_set_overwrite_mode:
6947 * @entry: a #GtkEntry
6948 * @overwrite: new value
6950 * Sets whether the text is overwritten when typing in the #GtkEntry.
6955 gtk_entry_set_overwrite_mode (GtkEntry *entry,
6958 g_return_if_fail (GTK_IS_ENTRY (entry));
6960 if (entry->overwrite_mode == overwrite)
6963 gtk_entry_toggle_overwrite (entry);
6965 g_object_notify (G_OBJECT (entry), "overwrite-mode");
6969 * gtk_entry_get_overwrite_mode:
6970 * @entry: a #GtkEntry
6972 * Gets the value set by gtk_entry_set_overwrite_mode().
6974 * Return value: whether the text is overwritten when typing.
6979 gtk_entry_get_overwrite_mode (GtkEntry *entry)
6981 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
6983 return entry->overwrite_mode;
6987 * gtk_entry_get_text:
6988 * @entry: a #GtkEntry
6990 * Retrieves the contents of the entry widget.
6991 * See also gtk_editable_get_chars().
6993 * This is equivalent to:
6995 * <informalexample><programlisting>
6996 * gtk_entry_buffer_get_text (gtk_entry_get_buffer (entry));
6997 * </programlisting></informalexample>
6999 * Return value: a pointer to the contents of the widget as a
7000 * string. This string points to internally allocated
7001 * storage in the widget and must not be freed, modified or
7004 G_CONST_RETURN gchar*
7005 gtk_entry_get_text (GtkEntry *entry)
7007 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7008 return gtk_entry_buffer_get_text (get_buffer (entry));
7012 * gtk_entry_set_max_length:
7013 * @entry: a #GtkEntry
7014 * @max: the maximum length of the entry, or 0 for no maximum.
7015 * (other than the maximum length of entries.) The value passed in will
7016 * be clamped to the range 0-65536.
7018 * Sets the maximum allowed length of the contents of the widget. If
7019 * the current contents are longer than the given length, then they
7020 * will be truncated to fit.
7022 * This is equivalent to:
7024 * <informalexample><programlisting>
7025 * gtk_entry_buffer_set_max_length (gtk_entry_get_buffer (entry), max);
7026 * </programlisting></informalexample>
7029 gtk_entry_set_max_length (GtkEntry *entry,
7032 g_return_if_fail (GTK_IS_ENTRY (entry));
7033 gtk_entry_buffer_set_max_length (get_buffer (entry), max);
7037 * gtk_entry_get_max_length:
7038 * @entry: a #GtkEntry
7040 * Retrieves the maximum allowed length of the text in
7041 * @entry. See gtk_entry_set_max_length().
7043 * This is equivalent to:
7045 * <informalexample><programlisting>
7046 * gtk_entry_buffer_get_max_length (gtk_entry_get_buffer (entry));
7047 * </programlisting></informalexample>
7049 * Return value: the maximum allowed number of characters
7050 * in #GtkEntry, or 0 if there is no maximum.
7053 gtk_entry_get_max_length (GtkEntry *entry)
7055 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7056 return gtk_entry_buffer_get_max_length (get_buffer (entry));
7060 * gtk_entry_get_text_length:
7061 * @entry: a #GtkEntry
7063 * Retrieves the current length of the text in
7066 * This is equivalent to:
7068 * <informalexample><programlisting>
7069 * gtk_entry_buffer_get_length (gtk_entry_get_buffer (entry));
7070 * </programlisting></informalexample>
7072 * Return value: the current number of characters
7073 * in #GtkEntry, or 0 if there are none.
7078 gtk_entry_get_text_length (GtkEntry *entry)
7080 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7081 return gtk_entry_buffer_get_length (get_buffer (entry));
7085 * gtk_entry_set_activates_default:
7086 * @entry: a #GtkEntry
7087 * @setting: %TRUE to activate window's default widget on Enter keypress
7089 * If @setting is %TRUE, pressing Enter in the @entry will activate the default
7090 * widget for the window containing the entry. This usually means that
7091 * the dialog box containing the entry will be closed, since the default
7092 * widget is usually one of the dialog buttons.
7094 * (For experts: if @setting is %TRUE, the entry calls
7095 * gtk_window_activate_default() on the window containing the entry, in
7096 * the default handler for the #GtkWidget::activate signal.)
7099 gtk_entry_set_activates_default (GtkEntry *entry,
7102 g_return_if_fail (GTK_IS_ENTRY (entry));
7103 setting = setting != FALSE;
7105 if (setting != entry->activates_default)
7107 entry->activates_default = setting;
7108 g_object_notify (G_OBJECT (entry), "activates-default");
7113 * gtk_entry_get_activates_default:
7114 * @entry: a #GtkEntry
7116 * Retrieves the value set by gtk_entry_set_activates_default().
7118 * Return value: %TRUE if the entry will activate the default widget
7121 gtk_entry_get_activates_default (GtkEntry *entry)
7123 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7125 return entry->activates_default;
7129 * gtk_entry_set_width_chars:
7130 * @entry: a #GtkEntry
7131 * @n_chars: width in chars
7133 * Changes the size request of the entry to be about the right size
7134 * for @n_chars characters. Note that it changes the size
7135 * <emphasis>request</emphasis>, the size can still be affected by
7136 * how you pack the widget into containers. If @n_chars is -1, the
7137 * size reverts to the default entry size.
7140 gtk_entry_set_width_chars (GtkEntry *entry,
7143 g_return_if_fail (GTK_IS_ENTRY (entry));
7145 if (entry->width_chars != n_chars)
7147 entry->width_chars = n_chars;
7148 g_object_notify (G_OBJECT (entry), "width-chars");
7149 gtk_widget_queue_resize (GTK_WIDGET (entry));
7154 * gtk_entry_get_width_chars:
7155 * @entry: a #GtkEntry
7157 * Gets the value set by gtk_entry_set_width_chars().
7159 * Return value: number of chars to request space for, or negative if unset
7162 gtk_entry_get_width_chars (GtkEntry *entry)
7164 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7166 return entry->width_chars;
7170 * gtk_entry_set_has_frame:
7171 * @entry: a #GtkEntry
7172 * @setting: new value
7174 * Sets whether the entry has a beveled frame around it.
7177 gtk_entry_set_has_frame (GtkEntry *entry,
7180 g_return_if_fail (GTK_IS_ENTRY (entry));
7182 setting = (setting != FALSE);
7184 if (entry->has_frame == setting)
7187 gtk_widget_queue_resize (GTK_WIDGET (entry));
7188 entry->has_frame = setting;
7189 g_object_notify (G_OBJECT (entry), "has-frame");
7193 * gtk_entry_get_has_frame:
7194 * @entry: a #GtkEntry
7196 * Gets the value set by gtk_entry_set_has_frame().
7198 * Return value: whether the entry has a beveled frame
7201 gtk_entry_get_has_frame (GtkEntry *entry)
7203 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7205 return entry->has_frame;
7209 * gtk_entry_set_inner_border:
7210 * @entry: a #GtkEntry
7211 * @border: (allow-none): a #GtkBorder, or %NULL
7213 * Sets %entry's inner-border property to %border, or clears it if %NULL
7214 * is passed. The inner-border is the area around the entry's text, but
7217 * If set, this property overrides the inner-border style property.
7218 * Overriding the style-provided border is useful when you want to do
7219 * in-place editing of some text in a canvas or list widget, where
7220 * pixel-exact positioning of the entry is important.
7225 gtk_entry_set_inner_border (GtkEntry *entry,
7226 const GtkBorder *border)
7228 g_return_if_fail (GTK_IS_ENTRY (entry));
7230 gtk_widget_queue_resize (GTK_WIDGET (entry));
7233 g_object_set_qdata_full (G_OBJECT (entry), quark_inner_border,
7234 gtk_border_copy (border),
7235 (GDestroyNotify) gtk_border_free);
7237 g_object_set_qdata (G_OBJECT (entry), quark_inner_border, NULL);
7239 g_object_notify (G_OBJECT (entry), "inner-border");
7243 * gtk_entry_get_inner_border:
7244 * @entry: a #GtkEntry
7246 * This function returns the entry's #GtkEntry:inner-border property. See
7247 * gtk_entry_set_inner_border() for more information.
7249 * Return value: (transfer none): the entry's #GtkBorder, or %NULL if none was set.
7253 G_CONST_RETURN GtkBorder *
7254 gtk_entry_get_inner_border (GtkEntry *entry)
7256 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7258 return g_object_get_qdata (G_OBJECT (entry), quark_inner_border);
7262 * gtk_entry_get_layout:
7263 * @entry: a #GtkEntry
7265 * Gets the #PangoLayout used to display the entry.
7266 * The layout is useful to e.g. convert text positions to
7267 * pixel positions, in combination with gtk_entry_get_layout_offsets().
7268 * The returned layout is owned by the entry and must not be
7269 * modified or freed by the caller.
7271 * Keep in mind that the layout text may contain a preedit string, so
7272 * gtk_entry_layout_index_to_text_index() and
7273 * gtk_entry_text_index_to_layout_index() are needed to convert byte
7274 * indices in the layout to byte indices in the entry contents.
7276 * Return value: (transfer none): the #PangoLayout for this entry
7279 gtk_entry_get_layout (GtkEntry *entry)
7281 PangoLayout *layout;
7283 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7285 layout = gtk_entry_ensure_layout (entry, TRUE);
7292 * gtk_entry_layout_index_to_text_index:
7293 * @entry: a #GtkEntry
7294 * @layout_index: byte index into the entry layout text
7296 * Converts from a position in the entry contents (returned
7297 * by gtk_entry_get_text()) to a position in the
7298 * entry's #PangoLayout (returned by gtk_entry_get_layout(),
7299 * with text retrieved via pango_layout_get_text()).
7301 * Return value: byte index into the entry contents
7304 gtk_entry_layout_index_to_text_index (GtkEntry *entry,
7307 PangoLayout *layout;
7311 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7313 layout = gtk_entry_ensure_layout (entry, TRUE);
7314 text = pango_layout_get_text (layout);
7315 cursor_index = g_utf8_offset_to_pointer (text, entry->current_pos) - text;
7317 if (layout_index >= cursor_index && entry->preedit_length)
7319 if (layout_index >= cursor_index + entry->preedit_length)
7320 layout_index -= entry->preedit_length;
7322 layout_index = cursor_index;
7325 return layout_index;
7329 * gtk_entry_text_index_to_layout_index:
7330 * @entry: a #GtkEntry
7331 * @text_index: byte index into the entry contents
7333 * Converts from a position in the entry's #PangoLayout (returned by
7334 * gtk_entry_get_layout()) to a position in the entry contents
7335 * (returned by gtk_entry_get_text()).
7337 * Return value: byte index into the entry layout text
7340 gtk_entry_text_index_to_layout_index (GtkEntry *entry,
7343 PangoLayout *layout;
7346 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7348 layout = gtk_entry_ensure_layout (entry, TRUE);
7349 text = pango_layout_get_text (layout);
7350 cursor_index = g_utf8_offset_to_pointer (text, entry->current_pos) - text;
7352 if (text_index > cursor_index)
7353 text_index += entry->preedit_length;
7359 * gtk_entry_get_layout_offsets:
7360 * @entry: a #GtkEntry
7361 * @x: (allow-none): location to store X offset of layout, or %NULL
7362 * @y: (allow-none): location to store Y offset of layout, or %NULL
7365 * Obtains the position of the #PangoLayout used to render text
7366 * in the entry, in widget coordinates. Useful if you want to line
7367 * up the text in an entry with some other text, e.g. when using the
7368 * entry to implement editable cells in a sheet widget.
7370 * Also useful to convert mouse events into coordinates inside the
7371 * #PangoLayout, e.g. to take some action if some part of the entry text
7374 * Note that as the user scrolls around in the entry the offsets will
7375 * change; you'll need to connect to the "notify::scroll-offset"
7376 * signal to track this. Remember when using the #PangoLayout
7377 * functions you need to convert to and from pixels using
7378 * PANGO_PIXELS() or #PANGO_SCALE.
7380 * Keep in mind that the layout text may contain a preedit string, so
7381 * gtk_entry_layout_index_to_text_index() and
7382 * gtk_entry_text_index_to_layout_index() are needed to convert byte
7383 * indices in the layout to byte indices in the entry contents.
7386 gtk_entry_get_layout_offsets (GtkEntry *entry,
7390 gint text_area_x, text_area_y;
7392 g_return_if_fail (GTK_IS_ENTRY (entry));
7394 /* this gets coords relative to text area */
7395 get_layout_position (entry, x, y);
7397 /* convert to widget coords */
7398 gtk_entry_get_text_area_size (entry, &text_area_x, &text_area_y, NULL, NULL);
7409 * gtk_entry_set_alignment:
7410 * @entry: a #GtkEntry
7411 * @xalign: The horizontal alignment, from 0 (left) to 1 (right).
7412 * Reversed for RTL layouts
7414 * Sets the alignment for the contents of the entry. This controls
7415 * the horizontal positioning of the contents when the displayed
7416 * text is shorter than the width of the entry.
7421 gtk_entry_set_alignment (GtkEntry *entry, gfloat xalign)
7423 GtkEntryPrivate *priv;
7425 g_return_if_fail (GTK_IS_ENTRY (entry));
7427 priv = GTK_ENTRY_GET_PRIVATE (entry);
7431 else if (xalign > 1.0)
7434 if (xalign != priv->xalign)
7436 priv->xalign = xalign;
7438 gtk_entry_recompute (entry);
7440 g_object_notify (G_OBJECT (entry), "xalign");
7445 * gtk_entry_get_alignment:
7446 * @entry: a #GtkEntry
7448 * Gets the value set by gtk_entry_set_alignment().
7450 * Return value: the alignment
7455 gtk_entry_get_alignment (GtkEntry *entry)
7457 GtkEntryPrivate *priv;
7459 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
7461 priv = GTK_ENTRY_GET_PRIVATE (entry);
7463 return priv->xalign;
7467 * gtk_entry_set_icon_from_pixbuf:
7468 * @entry: a #GtkEntry
7469 * @icon_pos: Icon position
7470 * @pixbuf: (allow-none): A #GdkPixbuf, or %NULL
7472 * Sets the icon shown in the specified position using a pixbuf.
7474 * If @pixbuf is %NULL, no icon will be shown in the specified position.
7479 gtk_entry_set_icon_from_pixbuf (GtkEntry *entry,
7480 GtkEntryIconPosition icon_pos,
7483 GtkEntryPrivate *priv;
7484 EntryIconInfo *icon_info;
7486 g_return_if_fail (GTK_IS_ENTRY (entry));
7487 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7489 priv = GTK_ENTRY_GET_PRIVATE (entry);
7491 if ((icon_info = priv->icons[icon_pos]) == NULL)
7492 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7494 g_object_freeze_notify (G_OBJECT (entry));
7497 g_object_ref (pixbuf);
7499 gtk_entry_clear (entry, icon_pos);
7503 icon_info->storage_type = GTK_IMAGE_PIXBUF;
7504 icon_info->pixbuf = pixbuf;
7506 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7508 g_object_notify (G_OBJECT (entry), "primary-icon-pixbuf");
7509 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7513 g_object_notify (G_OBJECT (entry), "secondary-icon-pixbuf");
7514 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7517 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7518 gdk_window_show_unraised (icon_info->window);
7521 gtk_entry_ensure_pixbuf (entry, icon_pos);
7523 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7524 gtk_widget_queue_resize (GTK_WIDGET (entry));
7526 g_object_thaw_notify (G_OBJECT (entry));
7530 * gtk_entry_set_icon_from_stock:
7531 * @entry: A #GtkEntry
7532 * @icon_pos: Icon position
7533 * @stock_id: (allow-none): The name of the stock item, or %NULL
7535 * Sets the icon shown in the entry at the specified position from
7538 * If @stock_id is %NULL, no icon will be shown in the specified position.
7543 gtk_entry_set_icon_from_stock (GtkEntry *entry,
7544 GtkEntryIconPosition icon_pos,
7545 const gchar *stock_id)
7547 GtkEntryPrivate *priv;
7548 EntryIconInfo *icon_info;
7551 g_return_if_fail (GTK_IS_ENTRY (entry));
7552 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7554 priv = GTK_ENTRY_GET_PRIVATE (entry);
7556 if ((icon_info = priv->icons[icon_pos]) == NULL)
7557 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7559 g_object_freeze_notify (G_OBJECT (entry));
7561 gtk_widget_ensure_style (GTK_WIDGET (entry));
7563 /* need to dup before clearing */
7564 new_id = g_strdup (stock_id);
7566 gtk_entry_clear (entry, icon_pos);
7570 icon_info->storage_type = GTK_IMAGE_STOCK;
7571 icon_info->stock_id = new_id;
7573 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7575 g_object_notify (G_OBJECT (entry), "primary-icon-stock");
7576 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7580 g_object_notify (G_OBJECT (entry), "secondary-icon-stock");
7581 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7584 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7585 gdk_window_show_unraised (icon_info->window);
7588 gtk_entry_ensure_pixbuf (entry, icon_pos);
7590 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7591 gtk_widget_queue_resize (GTK_WIDGET (entry));
7593 g_object_thaw_notify (G_OBJECT (entry));
7597 * gtk_entry_set_icon_from_icon_name:
7598 * @entry: A #GtkEntry
7599 * @icon_pos: The position at which to set the icon
7600 * @icon_name: (allow-none): An icon name, or %NULL
7602 * Sets the icon shown in the entry at the specified position
7603 * from the current icon theme.
7605 * If the icon name isn't known, a "broken image" icon will be displayed
7608 * If @icon_name is %NULL, no icon will be shown in the specified position.
7613 gtk_entry_set_icon_from_icon_name (GtkEntry *entry,
7614 GtkEntryIconPosition icon_pos,
7615 const gchar *icon_name)
7617 GtkEntryPrivate *priv;
7618 EntryIconInfo *icon_info;
7621 g_return_if_fail (GTK_IS_ENTRY (entry));
7622 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7624 priv = GTK_ENTRY_GET_PRIVATE (entry);
7626 if ((icon_info = priv->icons[icon_pos]) == NULL)
7627 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7629 g_object_freeze_notify (G_OBJECT (entry));
7631 gtk_widget_ensure_style (GTK_WIDGET (entry));
7633 /* need to dup before clearing */
7634 new_name = g_strdup (icon_name);
7636 gtk_entry_clear (entry, icon_pos);
7638 if (new_name != NULL)
7640 icon_info->storage_type = GTK_IMAGE_ICON_NAME;
7641 icon_info->icon_name = new_name;
7643 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7645 g_object_notify (G_OBJECT (entry), "primary-icon-name");
7646 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7650 g_object_notify (G_OBJECT (entry), "secondary-icon-name");
7651 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7654 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7655 gdk_window_show_unraised (icon_info->window);
7658 gtk_entry_ensure_pixbuf (entry, icon_pos);
7660 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7661 gtk_widget_queue_resize (GTK_WIDGET (entry));
7663 g_object_thaw_notify (G_OBJECT (entry));
7667 * gtk_entry_set_icon_from_gicon:
7668 * @entry: A #GtkEntry
7669 * @icon_pos: The position at which to set the icon
7670 * @icon: (allow-none): The icon to set, or %NULL
7672 * Sets the icon shown in the entry at the specified position
7673 * from the current icon theme.
7674 * If the icon isn't known, a "broken image" icon will be displayed
7677 * If @icon is %NULL, no icon will be shown in the specified position.
7682 gtk_entry_set_icon_from_gicon (GtkEntry *entry,
7683 GtkEntryIconPosition icon_pos,
7686 GtkEntryPrivate *priv;
7687 EntryIconInfo *icon_info;
7689 g_return_if_fail (GTK_IS_ENTRY (entry));
7690 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7692 priv = GTK_ENTRY_GET_PRIVATE (entry);
7694 if ((icon_info = priv->icons[icon_pos]) == NULL)
7695 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7697 g_object_freeze_notify (G_OBJECT (entry));
7699 /* need to ref before clearing */
7701 g_object_ref (icon);
7703 gtk_entry_clear (entry, icon_pos);
7707 icon_info->storage_type = GTK_IMAGE_GICON;
7708 icon_info->gicon = icon;
7710 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7712 g_object_notify (G_OBJECT (entry), "primary-icon-gicon");
7713 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7717 g_object_notify (G_OBJECT (entry), "secondary-icon-gicon");
7718 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7721 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7722 gdk_window_show_unraised (icon_info->window);
7725 gtk_entry_ensure_pixbuf (entry, icon_pos);
7727 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7728 gtk_widget_queue_resize (GTK_WIDGET (entry));
7730 g_object_thaw_notify (G_OBJECT (entry));
7734 * gtk_entry_set_icon_activatable:
7735 * @entry: A #GtkEntry
7736 * @icon_pos: Icon position
7737 * @activatable: %TRUE if the icon should be activatable
7739 * Sets whether the icon is activatable.
7744 gtk_entry_set_icon_activatable (GtkEntry *entry,
7745 GtkEntryIconPosition icon_pos,
7746 gboolean activatable)
7748 GtkEntryPrivate *priv;
7749 EntryIconInfo *icon_info;
7751 g_return_if_fail (GTK_IS_ENTRY (entry));
7752 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7754 priv = GTK_ENTRY_GET_PRIVATE (entry);
7756 if ((icon_info = priv->icons[icon_pos]) == NULL)
7757 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7759 activatable = activatable != FALSE;
7761 if (icon_info->nonactivatable != !activatable)
7763 icon_info->nonactivatable = !activatable;
7765 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
7766 update_cursors (GTK_WIDGET (entry));
7768 g_object_notify (G_OBJECT (entry),
7769 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-activatable" : "secondary-icon-activatable");
7774 * gtk_entry_get_icon_activatable:
7775 * @entry: a #GtkEntry
7776 * @icon_pos: Icon position
7778 * Returns whether the icon is activatable.
7780 * Returns: %TRUE if the icon is activatable.
7785 gtk_entry_get_icon_activatable (GtkEntry *entry,
7786 GtkEntryIconPosition icon_pos)
7788 GtkEntryPrivate *priv;
7789 EntryIconInfo *icon_info;
7791 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7792 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), FALSE);
7794 priv = GTK_ENTRY_GET_PRIVATE (entry);
7795 icon_info = priv->icons[icon_pos];
7797 return (icon_info != NULL && !icon_info->nonactivatable);
7801 * gtk_entry_get_icon_pixbuf:
7802 * @entry: A #GtkEntry
7803 * @icon_pos: Icon position
7805 * Retrieves the image used for the icon.
7807 * Unlike the other methods of setting and getting icon data, this
7808 * method will work regardless of whether the icon was set using a
7809 * #GdkPixbuf, a #GIcon, a stock item, or an icon name.
7811 * Returns: (transfer none): A #GdkPixbuf, or %NULL if no icon is
7812 * set for this position.
7817 gtk_entry_get_icon_pixbuf (GtkEntry *entry,
7818 GtkEntryIconPosition icon_pos)
7820 GtkEntryPrivate *priv;
7821 EntryIconInfo *icon_info;
7823 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7824 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7826 priv = GTK_ENTRY_GET_PRIVATE (entry);
7827 icon_info = priv->icons[icon_pos];
7832 gtk_entry_ensure_pixbuf (entry, icon_pos);
7834 return icon_info->pixbuf;
7838 * gtk_entry_get_icon_gicon:
7839 * @entry: A #GtkEntry
7840 * @icon_pos: Icon position
7842 * Retrieves the #GIcon used for the icon, or %NULL if there is
7843 * no icon or if the icon was set by some other method (e.g., by
7844 * stock, pixbuf, or icon name).
7846 * Returns: (transfer none): A #GIcon, or %NULL if no icon is set
7847 * or if the icon is not a #GIcon
7852 gtk_entry_get_icon_gicon (GtkEntry *entry,
7853 GtkEntryIconPosition icon_pos)
7855 GtkEntryPrivate *priv;
7856 EntryIconInfo *icon_info;
7858 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7859 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7861 priv = GTK_ENTRY_GET_PRIVATE (entry);
7862 icon_info = priv->icons[icon_pos];
7867 return icon_info->storage_type == GTK_IMAGE_GICON ? icon_info->gicon : NULL;
7871 * gtk_entry_get_icon_stock:
7872 * @entry: A #GtkEntry
7873 * @icon_pos: Icon position
7875 * Retrieves the stock id used for the icon, or %NULL if there is
7876 * no icon or if the icon was set by some other method (e.g., by
7877 * pixbuf, icon name or gicon).
7879 * Returns: A stock id, or %NULL if no icon is set or if the icon
7880 * wasn't set from a stock id
7885 gtk_entry_get_icon_stock (GtkEntry *entry,
7886 GtkEntryIconPosition icon_pos)
7888 GtkEntryPrivate *priv;
7889 EntryIconInfo *icon_info;
7891 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7892 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7894 priv = GTK_ENTRY_GET_PRIVATE (entry);
7895 icon_info = priv->icons[icon_pos];
7900 return icon_info->storage_type == GTK_IMAGE_STOCK ? icon_info->stock_id : NULL;
7904 * gtk_entry_get_icon_name:
7905 * @entry: A #GtkEntry
7906 * @icon_pos: Icon position
7908 * Retrieves the icon name used for the icon, or %NULL if there is
7909 * no icon or if the icon was set by some other method (e.g., by
7910 * pixbuf, stock or gicon).
7912 * Returns: An icon name, or %NULL if no icon is set or if the icon
7913 * wasn't set from an icon name
7918 gtk_entry_get_icon_name (GtkEntry *entry,
7919 GtkEntryIconPosition icon_pos)
7921 GtkEntryPrivate *priv;
7922 EntryIconInfo *icon_info;
7924 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7925 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7927 priv = GTK_ENTRY_GET_PRIVATE (entry);
7928 icon_info = priv->icons[icon_pos];
7933 return icon_info->storage_type == GTK_IMAGE_ICON_NAME ? icon_info->icon_name : NULL;
7937 * gtk_entry_set_icon_sensitive:
7938 * @entry: A #GtkEntry
7939 * @icon_pos: Icon position
7940 * @sensitive: Specifies whether the icon should appear
7941 * sensitive or insensitive
7943 * Sets the sensitivity for the specified icon.
7948 gtk_entry_set_icon_sensitive (GtkEntry *entry,
7949 GtkEntryIconPosition icon_pos,
7952 GtkEntryPrivate *priv;
7953 EntryIconInfo *icon_info;
7955 g_return_if_fail (GTK_IS_ENTRY (entry));
7956 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7958 priv = GTK_ENTRY_GET_PRIVATE (entry);
7960 if ((icon_info = priv->icons[icon_pos]) == NULL)
7961 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7963 if (icon_info->insensitive != !sensitive)
7965 icon_info->insensitive = !sensitive;
7967 icon_info->pressed = FALSE;
7968 icon_info->prelight = FALSE;
7970 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
7971 update_cursors (GTK_WIDGET (entry));
7973 gtk_widget_queue_draw (GTK_WIDGET (entry));
7975 g_object_notify (G_OBJECT (entry),
7976 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-sensitive" : "secondary-icon-sensitive");
7981 * gtk_entry_get_icon_sensitive:
7982 * @entry: a #GtkEntry
7983 * @icon_pos: Icon position
7985 * Returns whether the icon appears sensitive or insensitive.
7987 * Returns: %TRUE if the icon is sensitive.
7992 gtk_entry_get_icon_sensitive (GtkEntry *entry,
7993 GtkEntryIconPosition icon_pos)
7995 GtkEntryPrivate *priv;
7996 EntryIconInfo *icon_info;
7998 g_return_val_if_fail (GTK_IS_ENTRY (entry), TRUE);
7999 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), TRUE);
8001 priv = GTK_ENTRY_GET_PRIVATE (entry);
8002 icon_info = priv->icons[icon_pos];
8004 return (!icon_info || !icon_info->insensitive);
8009 * gtk_entry_get_icon_storage_type:
8010 * @entry: a #GtkEntry
8011 * @icon_pos: Icon position
8013 * Gets the type of representation being used by the icon
8014 * to store image data. If the icon has no image data,
8015 * the return value will be %GTK_IMAGE_EMPTY.
8017 * Return value: image representation being used
8022 gtk_entry_get_icon_storage_type (GtkEntry *entry,
8023 GtkEntryIconPosition icon_pos)
8025 GtkEntryPrivate *priv;
8026 EntryIconInfo *icon_info;
8028 g_return_val_if_fail (GTK_IS_ENTRY (entry), GTK_IMAGE_EMPTY);
8029 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), GTK_IMAGE_EMPTY);
8031 priv = GTK_ENTRY_GET_PRIVATE (entry);
8032 icon_info = priv->icons[icon_pos];
8035 return GTK_IMAGE_EMPTY;
8037 return icon_info->storage_type;
8041 * gtk_entry_get_icon_at_pos:
8042 * @entry: a #GtkEntry
8043 * @x: the x coordinate of the position to find
8044 * @y: the y coordinate of the position to find
8046 * Finds the icon at the given position and return its index.
8047 * If @x, @y doesn't lie inside an icon, -1 is returned.
8048 * This function is intended for use in a #GtkWidget::query-tooltip
8051 * Returns: the index of the icon at the given position, or -1
8056 gtk_entry_get_icon_at_pos (GtkEntry *entry,
8060 GtkAllocation primary;
8061 GtkAllocation secondary;
8062 gint frame_x, frame_y;
8064 g_return_val_if_fail (GTK_IS_ENTRY (entry), -1);
8066 get_frame_size (entry, &frame_x, &frame_y, NULL, NULL);
8070 get_icon_allocations (entry, &primary, &secondary);
8072 if (primary.x <= x && x < primary.x + primary.width &&
8073 primary.y <= y && y < primary.y + primary.height)
8074 return GTK_ENTRY_ICON_PRIMARY;
8076 if (secondary.x <= x && x < secondary.x + secondary.width &&
8077 secondary.y <= y && y < secondary.y + secondary.height)
8078 return GTK_ENTRY_ICON_SECONDARY;
8084 * gtk_entry_set_icon_drag_source:
8085 * @entry: a #GtkIconEntry
8086 * @icon_pos: icon position
8087 * @target_list: the targets (data formats) in which the data can be provided
8088 * @actions: a bitmask of the allowed drag actions
8090 * Sets up the icon at the given position so that GTK+ will start a drag
8091 * operation when the user clicks and drags the icon.
8093 * To handle the drag operation, you need to connect to the usual
8094 * #GtkWidget::drag-data-get (or possibly #GtkWidget::drag-data-delete)
8095 * signal, and use gtk_entry_get_current_icon_drag_source() in
8096 * your signal handler to find out if the drag was started from
8099 * By default, GTK+ uses the icon as the drag icon. You can use the
8100 * #GtkWidget::drag-begin signal to set a different icon. Note that you
8101 * have to use g_signal_connect_after() to ensure that your signal handler
8102 * gets executed after the default handler.
8107 gtk_entry_set_icon_drag_source (GtkEntry *entry,
8108 GtkEntryIconPosition icon_pos,
8109 GtkTargetList *target_list,
8110 GdkDragAction actions)
8112 GtkEntryPrivate *priv;
8113 EntryIconInfo *icon_info;
8115 g_return_if_fail (GTK_IS_ENTRY (entry));
8116 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8118 priv = GTK_ENTRY_GET_PRIVATE (entry);
8120 if ((icon_info = priv->icons[icon_pos]) == NULL)
8121 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8123 if (icon_info->target_list)
8124 gtk_target_list_unref (icon_info->target_list);
8125 icon_info->target_list = target_list;
8126 if (icon_info->target_list)
8127 gtk_target_list_ref (icon_info->target_list);
8129 icon_info->actions = actions;
8133 * gtk_entry_get_current_icon_drag_source:
8134 * @entry: a #GtkIconEntry
8136 * Returns the index of the icon which is the source of the current
8137 * DND operation, or -1.
8139 * This function is meant to be used in a #GtkWidget::drag-data-get
8142 * Returns: index of the icon which is the source of the current
8143 * DND operation, or -1.
8148 gtk_entry_get_current_icon_drag_source (GtkEntry *entry)
8150 GtkEntryPrivate *priv;
8151 EntryIconInfo *icon_info = NULL;
8154 g_return_val_if_fail (GTK_IS_ENTRY (entry), -1);
8156 priv = GTK_ENTRY_GET_PRIVATE (entry);
8158 for (i = 0; i < MAX_ICONS; i++)
8160 if ((icon_info = priv->icons[i]))
8162 if (icon_info->in_drag)
8171 * gtk_entry_get_icon_area:
8172 * @entry: A #GtkEntry
8173 * @icon_pos: Icon position
8174 * @icon_area: Return location for the icon's area
8176 * Gets the area where entry's icon at @icon_pos is drawn.
8177 * This function is useful when drawing something to the
8178 * entry in a draw callback.
8180 * If the entry is not realized or has no icon at the given position,
8181 * @icon_area is filled with zeros.
8183 * See also gtk_entry_get_text_area()
8188 gtk_entry_get_icon_area (GtkEntry *entry,
8189 GtkEntryIconPosition icon_pos,
8190 GdkRectangle *icon_area)
8192 GtkEntryPrivate *priv;
8193 EntryIconInfo *icon_info;
8195 g_return_if_fail (GTK_IS_ENTRY (entry));
8196 g_return_if_fail (icon_area != NULL);
8198 priv = GTK_ENTRY_GET_PRIVATE (entry);
8200 icon_info = priv->icons[icon_pos];
8204 GtkAllocation primary;
8205 GtkAllocation secondary;
8207 get_icon_allocations (entry, &primary, &secondary);
8209 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
8210 *icon_area = primary;
8212 *icon_area = secondary;
8218 icon_area->width = 0;
8219 icon_area->height = 0;
8224 ensure_has_tooltip (GtkEntry *entry)
8226 GtkEntryPrivate *priv;
8227 EntryIconInfo *icon_info;
8229 gboolean has_tooltip = FALSE;
8231 priv = GTK_ENTRY_GET_PRIVATE (entry);
8233 for (i = 0; i < MAX_ICONS; i++)
8235 if ((icon_info = priv->icons[i]) != NULL)
8237 if (icon_info->tooltip != NULL)
8245 gtk_widget_set_has_tooltip (GTK_WIDGET (entry), has_tooltip);
8249 * gtk_entry_get_icon_tooltip_text:
8250 * @entry: a #GtkEntry
8251 * @icon_pos: the icon position
8253 * Gets the contents of the tooltip on the icon at the specified
8254 * position in @entry.
8256 * Returns: the tooltip text, or %NULL. Free the returned string
8257 * with g_free() when done.
8262 gtk_entry_get_icon_tooltip_text (GtkEntry *entry,
8263 GtkEntryIconPosition icon_pos)
8265 GtkEntryPrivate *priv;
8266 EntryIconInfo *icon_info;
8269 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8270 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8272 priv = GTK_ENTRY_GET_PRIVATE (entry);
8273 icon_info = priv->icons[icon_pos];
8278 if (icon_info->tooltip &&
8279 !pango_parse_markup (icon_info->tooltip, -1, 0, NULL, &text, NULL, NULL))
8280 g_assert (NULL == text); /* text should still be NULL in case of markup errors */
8286 * gtk_entry_set_icon_tooltip_text:
8287 * @entry: a #GtkEntry
8288 * @icon_pos: the icon position
8289 * @tooltip: (allow-none): the contents of the tooltip for the icon, or %NULL
8291 * Sets @tooltip as the contents of the tooltip for the icon
8292 * at the specified position.
8294 * Use %NULL for @tooltip to remove an existing tooltip.
8296 * See also gtk_widget_set_tooltip_text() and
8297 * gtk_entry_set_icon_tooltip_markup().
8302 gtk_entry_set_icon_tooltip_text (GtkEntry *entry,
8303 GtkEntryIconPosition icon_pos,
8304 const gchar *tooltip)
8306 GtkEntryPrivate *priv;
8307 EntryIconInfo *icon_info;
8309 g_return_if_fail (GTK_IS_ENTRY (entry));
8310 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8312 priv = GTK_ENTRY_GET_PRIVATE (entry);
8314 if (!(icon_info = priv->icons[icon_pos]))
8315 icon_info = priv->icons[icon_pos];
8317 if (icon_info->tooltip)
8318 g_free (icon_info->tooltip);
8320 /* Treat an empty string as a NULL string,
8321 * because an empty string would be useless for a tooltip:
8323 if (tooltip && tooltip[0] == '\0')
8326 icon_info->tooltip = tooltip ? g_markup_escape_text (tooltip, -1) : NULL;
8328 ensure_has_tooltip (entry);
8332 * gtk_entry_get_icon_tooltip_markup:
8333 * @entry: a #GtkEntry
8334 * @icon_pos: the icon position
8336 * Gets the contents of the tooltip on the icon at the specified
8337 * position in @entry.
8339 * Returns: the tooltip text, or %NULL. Free the returned string
8340 * with g_free() when done.
8345 gtk_entry_get_icon_tooltip_markup (GtkEntry *entry,
8346 GtkEntryIconPosition icon_pos)
8348 GtkEntryPrivate *priv;
8349 EntryIconInfo *icon_info;
8351 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8352 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8354 priv = GTK_ENTRY_GET_PRIVATE (entry);
8355 icon_info = priv->icons[icon_pos];
8360 return g_strdup (icon_info->tooltip);
8364 * gtk_entry_set_icon_tooltip_markup:
8365 * @entry: a #GtkEntry
8366 * @icon_pos: the icon position
8367 * @tooltip: (allow-none): the contents of the tooltip for the icon, or %NULL
8369 * Sets @tooltip as the contents of the tooltip for the icon at
8370 * the specified position. @tooltip is assumed to be marked up with
8371 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
8373 * Use %NULL for @tooltip to remove an existing tooltip.
8375 * See also gtk_widget_set_tooltip_markup() and
8376 * gtk_enty_set_icon_tooltip_text().
8381 gtk_entry_set_icon_tooltip_markup (GtkEntry *entry,
8382 GtkEntryIconPosition icon_pos,
8383 const gchar *tooltip)
8385 GtkEntryPrivate *priv;
8386 EntryIconInfo *icon_info;
8388 g_return_if_fail (GTK_IS_ENTRY (entry));
8389 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8391 priv = GTK_ENTRY_GET_PRIVATE (entry);
8393 if (!(icon_info = priv->icons[icon_pos]))
8394 icon_info = priv->icons[icon_pos];
8396 if (icon_info->tooltip)
8397 g_free (icon_info->tooltip);
8399 /* Treat an empty string as a NULL string,
8400 * because an empty string would be useless for a tooltip:
8402 if (tooltip && tooltip[0] == '\0')
8405 icon_info->tooltip = g_strdup (tooltip);
8407 ensure_has_tooltip (entry);
8411 gtk_entry_query_tooltip (GtkWidget *widget,
8414 gboolean keyboard_tip,
8415 GtkTooltip *tooltip)
8418 GtkEntryPrivate *priv;
8419 EntryIconInfo *icon_info;
8422 entry = GTK_ENTRY (widget);
8423 priv = GTK_ENTRY_GET_PRIVATE (entry);
8427 icon_pos = gtk_entry_get_icon_at_pos (entry, x, y);
8430 if ((icon_info = priv->icons[icon_pos]) != NULL)
8432 if (icon_info->tooltip)
8434 gtk_tooltip_set_markup (tooltip, icon_info->tooltip);
8443 return GTK_WIDGET_CLASS (gtk_entry_parent_class)->query_tooltip (widget,
8450 /* Quick hack of a popup menu
8453 activate_cb (GtkWidget *menuitem,
8456 const gchar *signal = g_object_get_data (G_OBJECT (menuitem), "gtk-signal");
8457 g_signal_emit_by_name (entry, signal);
8462 gtk_entry_mnemonic_activate (GtkWidget *widget,
8463 gboolean group_cycling)
8465 gtk_widget_grab_focus (widget);
8470 append_action_signal (GtkEntry *entry,
8472 const gchar *stock_id,
8473 const gchar *signal,
8476 GtkWidget *menuitem = gtk_image_menu_item_new_from_stock (stock_id, NULL);
8478 g_object_set_data (G_OBJECT (menuitem), I_("gtk-signal"), (char *)signal);
8479 g_signal_connect (menuitem, "activate",
8480 G_CALLBACK (activate_cb), entry);
8482 gtk_widget_set_sensitive (menuitem, sensitive);
8484 gtk_widget_show (menuitem);
8485 gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
8489 popup_menu_detach (GtkWidget *attach_widget,
8492 GTK_ENTRY (attach_widget)->popup_menu = NULL;
8496 popup_position_func (GtkMenu *menu,
8502 GtkEntry *entry = GTK_ENTRY (user_data);
8503 GtkWidget *widget = GTK_WIDGET (entry);
8505 GtkRequisition menu_req;
8506 GdkRectangle monitor;
8507 GtkBorder inner_border;
8508 gint monitor_num, strong_x, height;
8510 g_return_if_fail (gtk_widget_get_realized (widget));
8512 gdk_window_get_origin (entry->text_area, x, y);
8514 screen = gtk_widget_get_screen (widget);
8515 monitor_num = gdk_screen_get_monitor_at_window (screen, entry->text_area);
8516 if (monitor_num < 0)
8518 gtk_menu_set_monitor (menu, monitor_num);
8520 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
8521 gtk_widget_get_preferred_size (entry->popup_menu,
8523 height = gdk_window_get_height (entry->text_area);
8524 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
8525 _gtk_entry_effective_inner_border (entry, &inner_border);
8527 *x += inner_border.left + strong_x - entry->scroll_offset;
8528 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
8529 *x -= menu_req.width;
8531 if ((*y + height + menu_req.height) <= monitor.y + monitor.height)
8533 else if ((*y - menu_req.height) >= monitor.y)
8534 *y -= menu_req.height;
8535 else if (monitor.y + monitor.height - (*y + height) > *y)
8538 *y -= menu_req.height;
8544 unichar_chosen_func (const char *text,
8547 GtkEntry *entry = GTK_ENTRY (data);
8549 if (entry->editable)
8550 gtk_entry_enter_text (entry, text);
8561 popup_targets_received (GtkClipboard *clipboard,
8562 GtkSelectionData *data,
8565 PopupInfo *info = user_data;
8566 GtkEntry *entry = info->entry;
8568 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
8571 gboolean clipboard_contains_text;
8572 GtkWidget *menuitem;
8574 gboolean show_input_method_menu;
8575 gboolean show_unicode_menu;
8577 clipboard_contains_text = gtk_selection_data_targets_include_text (data);
8578 if (entry->popup_menu)
8579 gtk_widget_destroy (entry->popup_menu);
8581 entry->popup_menu = gtk_menu_new ();
8583 gtk_menu_attach_to_widget (GTK_MENU (entry->popup_menu),
8587 mode = gtk_entry_get_display_mode (entry);
8588 append_action_signal (entry, entry->popup_menu, GTK_STOCK_CUT, "cut-clipboard",
8589 entry->editable && mode == DISPLAY_NORMAL &&
8590 entry->current_pos != entry->selection_bound);
8592 append_action_signal (entry, entry->popup_menu, GTK_STOCK_COPY, "copy-clipboard",
8593 mode == DISPLAY_NORMAL &&
8594 entry->current_pos != entry->selection_bound);
8596 append_action_signal (entry, entry->popup_menu, GTK_STOCK_PASTE, "paste-clipboard",
8597 entry->editable && clipboard_contains_text);
8599 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_DELETE, NULL);
8600 gtk_widget_set_sensitive (menuitem, entry->editable && entry->current_pos != entry->selection_bound);
8601 g_signal_connect_swapped (menuitem, "activate",
8602 G_CALLBACK (gtk_entry_delete_cb), entry);
8603 gtk_widget_show (menuitem);
8604 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8606 menuitem = gtk_separator_menu_item_new ();
8607 gtk_widget_show (menuitem);
8608 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8610 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_SELECT_ALL, NULL);
8611 g_signal_connect_swapped (menuitem, "activate",
8612 G_CALLBACK (gtk_entry_select_all), entry);
8613 gtk_widget_show (menuitem);
8614 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8616 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
8617 "gtk-show-input-method-menu", &show_input_method_menu,
8618 "gtk-show-unicode-menu", &show_unicode_menu,
8621 if (show_input_method_menu || show_unicode_menu)
8623 menuitem = gtk_separator_menu_item_new ();
8624 gtk_widget_show (menuitem);
8625 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8628 if (show_input_method_menu)
8630 menuitem = gtk_menu_item_new_with_mnemonic (_("Input _Methods"));
8631 gtk_widget_set_sensitive (menuitem, entry->editable);
8632 gtk_widget_show (menuitem);
8633 submenu = gtk_menu_new ();
8634 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
8636 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8638 gtk_im_multicontext_append_menuitems (GTK_IM_MULTICONTEXT (entry->im_context),
8639 GTK_MENU_SHELL (submenu));
8642 if (show_unicode_menu)
8644 menuitem = gtk_menu_item_new_with_mnemonic (_("_Insert Unicode Control Character"));
8645 gtk_widget_set_sensitive (menuitem, entry->editable);
8646 gtk_widget_show (menuitem);
8648 submenu = gtk_menu_new ();
8649 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
8650 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8652 _gtk_text_util_append_special_char_menuitems (GTK_MENU_SHELL (submenu),
8653 unichar_chosen_func,
8657 g_signal_emit (entry,
8658 signals[POPULATE_POPUP],
8664 gtk_menu_popup (GTK_MENU (entry->popup_menu), NULL, NULL,
8666 info->button, info->time);
8669 gtk_menu_popup (GTK_MENU (entry->popup_menu), NULL, NULL,
8670 popup_position_func, entry,
8671 info->button, info->time);
8672 gtk_menu_shell_select_first (GTK_MENU_SHELL (entry->popup_menu), FALSE);
8676 g_object_unref (entry);
8677 g_slice_free (PopupInfo, info);
8681 gtk_entry_do_popup (GtkEntry *entry,
8682 GdkEventButton *event)
8684 PopupInfo *info = g_slice_new (PopupInfo);
8686 /* In order to know what entries we should make sensitive, we
8687 * ask for the current targets of the clipboard, and when
8688 * we get them, then we actually pop up the menu.
8690 info->entry = g_object_ref (entry);
8694 info->button = event->button;
8695 info->time = event->time;
8700 info->time = gtk_get_current_event_time ();
8703 gtk_clipboard_request_contents (gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_CLIPBOARD),
8704 gdk_atom_intern_static_string ("TARGETS"),
8705 popup_targets_received,
8710 gtk_entry_popup_menu (GtkWidget *widget)
8712 gtk_entry_do_popup (GTK_ENTRY (widget), NULL);
8717 gtk_entry_drag_begin (GtkWidget *widget,
8718 GdkDragContext *context)
8720 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
8723 for (i = 0; i < MAX_ICONS; i++)
8725 EntryIconInfo *icon_info = priv->icons[i];
8727 if (icon_info != NULL)
8729 if (icon_info->in_drag)
8731 switch (icon_info->storage_type)
8733 case GTK_IMAGE_STOCK:
8734 gtk_drag_set_icon_stock (context, icon_info->stock_id, -2, -2);
8737 case GTK_IMAGE_ICON_NAME:
8738 gtk_drag_set_icon_name (context, icon_info->icon_name, -2, -2);
8741 /* FIXME: No GIcon support for dnd icons */
8742 case GTK_IMAGE_GICON:
8743 case GTK_IMAGE_PIXBUF:
8744 gtk_drag_set_icon_pixbuf (context, icon_info->pixbuf, -2, -2);
8747 g_assert_not_reached ();
8755 gtk_entry_drag_end (GtkWidget *widget,
8756 GdkDragContext *context)
8758 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
8761 for (i = 0; i < MAX_ICONS; i++)
8763 EntryIconInfo *icon_info = priv->icons[i];
8765 if (icon_info != NULL)
8766 icon_info->in_drag = 0;
8771 gtk_entry_drag_leave (GtkWidget *widget,
8772 GdkDragContext *context,
8775 GtkEntry *entry = GTK_ENTRY (widget);
8777 entry->dnd_position = -1;
8778 gtk_widget_queue_draw (widget);
8782 gtk_entry_drag_drop (GtkWidget *widget,
8783 GdkDragContext *context,
8788 GtkEntry *entry = GTK_ENTRY (widget);
8789 GdkAtom target = GDK_NONE;
8791 if (entry->editable)
8792 target = gtk_drag_dest_find_target (widget, context, NULL);
8794 if (target != GDK_NONE)
8795 gtk_drag_get_data (widget, context, target, time);
8797 gtk_drag_finish (context, FALSE, FALSE, time);
8803 gtk_entry_drag_motion (GtkWidget *widget,
8804 GdkDragContext *context,
8809 GtkEntry *entry = GTK_ENTRY (widget);
8811 GtkWidget *source_widget;
8812 GdkDragAction suggested_action;
8813 gint new_position, old_position;
8816 style = gtk_widget_get_style (widget);
8817 x -= style->xthickness;
8818 y -= style->ythickness;
8820 old_position = entry->dnd_position;
8821 new_position = gtk_entry_find_position (entry, x + entry->scroll_offset);
8823 if (entry->editable &&
8824 gtk_drag_dest_find_target (widget, context, NULL) != GDK_NONE)
8826 source_widget = gtk_drag_get_source_widget (context);
8827 suggested_action = context->suggested_action;
8829 if (!gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &sel1, &sel2) ||
8830 new_position < sel1 || new_position > sel2)
8832 if (source_widget == widget)
8834 /* Default to MOVE, unless the user has
8835 * pressed ctrl or alt to affect available actions
8837 if ((context->actions & GDK_ACTION_MOVE) != 0)
8838 suggested_action = GDK_ACTION_MOVE;
8841 entry->dnd_position = new_position;
8845 if (source_widget == widget)
8846 suggested_action = 0; /* Can't drop in selection where drag started */
8848 entry->dnd_position = -1;
8853 /* Entry not editable, or no text */
8854 suggested_action = 0;
8855 entry->dnd_position = -1;
8858 gdk_drag_status (context, suggested_action, time);
8860 if (entry->dnd_position != old_position)
8861 gtk_widget_queue_draw (widget);
8867 gtk_entry_drag_data_received (GtkWidget *widget,
8868 GdkDragContext *context,
8871 GtkSelectionData *selection_data,
8875 GtkEntry *entry = GTK_ENTRY (widget);
8876 GtkEditable *editable = GTK_EDITABLE (widget);
8880 str = (gchar *) gtk_selection_data_get_text (selection_data);
8882 style = gtk_widget_get_style (widget);
8883 x -= style->xthickness;
8884 y -= style->ythickness;
8886 if (str && entry->editable)
8892 if (entry->truncate_multiline)
8893 length = truncate_multiline (str);
8895 new_position = gtk_entry_find_position (entry, x + entry->scroll_offset);
8897 if (!gtk_editable_get_selection_bounds (editable, &sel1, &sel2) ||
8898 new_position < sel1 || new_position > sel2)
8900 gtk_editable_insert_text (editable, str, length, &new_position);
8904 /* Replacing selection */
8905 begin_change (entry);
8906 g_object_freeze_notify (G_OBJECT (entry));
8907 gtk_editable_delete_text (editable, sel1, sel2);
8908 gtk_editable_insert_text (editable, str, length, &sel1);
8909 g_object_thaw_notify (G_OBJECT (entry));
8913 gtk_drag_finish (context, TRUE, context->action == GDK_ACTION_MOVE, time);
8917 /* Drag and drop didn't happen! */
8918 gtk_drag_finish (context, FALSE, FALSE, time);
8925 gtk_entry_drag_data_get (GtkWidget *widget,
8926 GdkDragContext *context,
8927 GtkSelectionData *selection_data,
8931 gint sel_start, sel_end;
8934 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
8935 GtkEditable *editable = GTK_EDITABLE (widget);
8937 /* If there is an icon drag going on, exit early. */
8938 for (i = 0; i < MAX_ICONS; i++)
8940 EntryIconInfo *icon_info = priv->icons[i];
8942 if (icon_info != NULL)
8944 if (icon_info->in_drag)
8949 if (gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end))
8951 gchar *str = gtk_entry_get_display_text (GTK_ENTRY (widget), sel_start, sel_end);
8953 gtk_selection_data_set_text (selection_data, str, -1);
8961 gtk_entry_drag_data_delete (GtkWidget *widget,
8962 GdkDragContext *context)
8964 gint sel_start, sel_end;
8967 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
8968 GtkEditable *editable = GTK_EDITABLE (widget);
8970 /* If there is an icon drag going on, exit early. */
8971 for (i = 0; i < MAX_ICONS; i++)
8973 EntryIconInfo *icon_info = priv->icons[i];
8975 if (icon_info != NULL)
8977 if (icon_info->in_drag)
8982 if (GTK_ENTRY (widget)->editable &&
8983 gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end))
8984 gtk_editable_delete_text (editable, sel_start, sel_end);
8987 /* We display the cursor when
8989 * - the selection is empty, AND
8990 * - the widget has focus
8993 #define CURSOR_ON_MULTIPLIER 2
8994 #define CURSOR_OFF_MULTIPLIER 1
8995 #define CURSOR_PEND_MULTIPLIER 3
8996 #define CURSOR_DIVIDER 3
8999 cursor_blinks (GtkEntry *entry)
9001 if (gtk_widget_has_focus (GTK_WIDGET (entry)) &&
9003 entry->selection_bound == entry->current_pos)
9005 GtkSettings *settings;
9008 settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9009 g_object_get (settings, "gtk-cursor-blink", &blink, NULL);
9018 get_cursor_time (GtkEntry *entry)
9020 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9023 g_object_get (settings, "gtk-cursor-blink-time", &time, NULL);
9029 get_cursor_blink_timeout (GtkEntry *entry)
9031 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9034 g_object_get (settings, "gtk-cursor-blink-timeout", &timeout, NULL);
9040 show_cursor (GtkEntry *entry)
9044 if (!entry->cursor_visible)
9046 entry->cursor_visible = TRUE;
9048 widget = GTK_WIDGET (entry);
9049 if (gtk_widget_has_focus (widget) && entry->selection_bound == entry->current_pos)
9050 gtk_widget_queue_draw (widget);
9055 hide_cursor (GtkEntry *entry)
9059 if (entry->cursor_visible)
9061 entry->cursor_visible = FALSE;
9063 widget = GTK_WIDGET (entry);
9064 if (gtk_widget_has_focus (widget) && entry->selection_bound == entry->current_pos)
9065 gtk_widget_queue_draw (widget);
9073 blink_cb (gpointer data)
9076 GtkEntryPrivate *priv;
9079 entry = GTK_ENTRY (data);
9080 priv = GTK_ENTRY_GET_PRIVATE (entry);
9082 if (!gtk_widget_has_focus (GTK_WIDGET (entry)))
9084 g_warning ("GtkEntry - did not receive focus-out-event. If you\n"
9085 "connect a handler to this signal, it must return\n"
9086 "FALSE so the entry gets the event as well");
9088 gtk_entry_check_cursor_blink (entry);
9093 g_assert (entry->selection_bound == entry->current_pos);
9095 blink_timeout = get_cursor_blink_timeout (entry);
9096 if (priv->blink_time > 1000 * blink_timeout &&
9097 blink_timeout < G_MAXINT/1000)
9099 /* we've blinked enough without the user doing anything, stop blinking */
9100 show_cursor (entry);
9101 entry->blink_timeout = 0;
9103 else if (entry->cursor_visible)
9105 hide_cursor (entry);
9106 entry->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_OFF_MULTIPLIER / CURSOR_DIVIDER,
9112 show_cursor (entry);
9113 priv->blink_time += get_cursor_time (entry);
9114 entry->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
9119 /* Remove ourselves */
9124 gtk_entry_check_cursor_blink (GtkEntry *entry)
9126 GtkEntryPrivate *priv;
9128 priv = GTK_ENTRY_GET_PRIVATE (entry);
9130 if (cursor_blinks (entry))
9132 if (!entry->blink_timeout)
9134 show_cursor (entry);
9135 entry->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
9142 if (entry->blink_timeout)
9144 g_source_remove (entry->blink_timeout);
9145 entry->blink_timeout = 0;
9148 entry->cursor_visible = TRUE;
9154 gtk_entry_pend_cursor_blink (GtkEntry *entry)
9156 if (cursor_blinks (entry))
9158 if (entry->blink_timeout != 0)
9159 g_source_remove (entry->blink_timeout);
9161 entry->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_PEND_MULTIPLIER / CURSOR_DIVIDER,
9164 show_cursor (entry);
9169 gtk_entry_reset_blink_time (GtkEntry *entry)
9171 GtkEntryPrivate *priv;
9173 priv = GTK_ENTRY_GET_PRIVATE (entry);
9175 priv->blink_time = 0;
9181 gtk_entry_completion_timeout (gpointer data)
9183 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (data);
9184 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (completion->priv->entry);
9186 completion->priv->completion_timeout = 0;
9188 if (completion->priv->filter_model &&
9189 g_utf8_strlen (gtk_entry_get_text (GTK_ENTRY (completion->priv->entry)), -1)
9190 >= completion->priv->minimum_key_length)
9194 GtkTreeSelection *s;
9195 gboolean popup_single;
9197 gtk_entry_completion_complete (completion);
9198 matches = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->filter_model), NULL);
9200 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9202 s = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view));
9204 gtk_tree_selection_unselect_all (s);
9206 actions = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->actions), NULL);
9208 g_object_get (completion, "popup-single-match", &popup_single, NULL);
9209 if ((matches > (popup_single ? 0: 1)) || actions > 0)
9211 if (gtk_widget_get_visible (completion->priv->popup_window))
9212 _gtk_entry_completion_resize_popup (completion);
9214 _gtk_entry_completion_popup (completion, priv->completion_device);
9217 _gtk_entry_completion_popdown (completion);
9219 else if (gtk_widget_get_visible (completion->priv->popup_window))
9220 _gtk_entry_completion_popdown (completion);
9225 static inline gboolean
9226 keyval_is_cursor_move (guint keyval)
9228 if (keyval == GDK_KEY_Up || keyval == GDK_KEY_KP_Up)
9231 if (keyval == GDK_KEY_Down || keyval == GDK_KEY_KP_Down)
9234 if (keyval == GDK_KEY_Page_Up)
9237 if (keyval == GDK_KEY_Page_Down)
9244 gtk_entry_completion_key_press (GtkWidget *widget,
9248 gint matches, actions = 0;
9249 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
9251 if (!gtk_widget_get_mapped (completion->priv->popup_window))
9254 matches = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->filter_model), NULL);
9256 if (completion->priv->actions)
9257 actions = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->actions), NULL);
9259 if (keyval_is_cursor_move (event->keyval))
9261 GtkTreePath *path = NULL;
9263 if (event->keyval == GDK_KEY_Up || event->keyval == GDK_KEY_KP_Up)
9265 if (completion->priv->current_selected < 0)
9266 completion->priv->current_selected = matches + actions - 1;
9268 completion->priv->current_selected--;
9270 else if (event->keyval == GDK_KEY_Down || event->keyval == GDK_KEY_KP_Down)
9272 if (completion->priv->current_selected < matches + actions - 1)
9273 completion->priv->current_selected++;
9275 completion->priv->current_selected = -1;
9277 else if (event->keyval == GDK_KEY_Page_Up)
9279 if (completion->priv->current_selected < 0)
9280 completion->priv->current_selected = matches + actions - 1;
9281 else if (completion->priv->current_selected == 0)
9282 completion->priv->current_selected = -1;
9283 else if (completion->priv->current_selected < matches)
9285 completion->priv->current_selected -= 14;
9286 if (completion->priv->current_selected < 0)
9287 completion->priv->current_selected = 0;
9291 completion->priv->current_selected -= 14;
9292 if (completion->priv->current_selected < matches - 1)
9293 completion->priv->current_selected = matches - 1;
9296 else if (event->keyval == GDK_KEY_Page_Down)
9298 if (completion->priv->current_selected < 0)
9299 completion->priv->current_selected = 0;
9300 else if (completion->priv->current_selected < matches - 1)
9302 completion->priv->current_selected += 14;
9303 if (completion->priv->current_selected > matches - 1)
9304 completion->priv->current_selected = matches - 1;
9306 else if (completion->priv->current_selected == matches + actions - 1)
9308 completion->priv->current_selected = -1;
9312 completion->priv->current_selected += 14;
9313 if (completion->priv->current_selected > matches + actions - 1)
9314 completion->priv->current_selected = matches + actions - 1;
9318 if (completion->priv->current_selected < 0)
9320 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9321 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view)));
9323 if (completion->priv->inline_selection &&
9324 completion->priv->completion_prefix)
9326 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9327 completion->priv->completion_prefix);
9328 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9331 else if (completion->priv->current_selected < matches)
9333 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view)));
9335 path = gtk_tree_path_new_from_indices (completion->priv->current_selected, -1);
9336 gtk_tree_view_set_cursor (GTK_TREE_VIEW (completion->priv->tree_view),
9339 if (completion->priv->inline_selection)
9343 GtkTreeIter child_iter;
9344 GtkTreeModel *model = NULL;
9345 GtkTreeSelection *sel;
9348 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view));
9349 if (!gtk_tree_selection_get_selected (sel, &model, &iter))
9352 gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (model), &child_iter, &iter);
9353 model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model));
9355 if (completion->priv->completion_prefix == NULL)
9356 completion->priv->completion_prefix = g_strdup (gtk_entry_get_text (GTK_ENTRY (completion->priv->entry)));
9358 g_signal_emit_by_name (completion, "cursor-on-match", model,
9359 &child_iter, &entry_set);
9362 else if (completion->priv->current_selected - matches >= 0)
9364 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9366 path = gtk_tree_path_new_from_indices (completion->priv->current_selected - matches, -1);
9367 gtk_tree_view_set_cursor (GTK_TREE_VIEW (completion->priv->action_view),
9370 if (completion->priv->inline_selection &&
9371 completion->priv->completion_prefix)
9373 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9374 completion->priv->completion_prefix);
9375 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9379 gtk_tree_path_free (path);
9383 else if (event->keyval == GDK_KEY_Escape ||
9384 event->keyval == GDK_KEY_Left ||
9385 event->keyval == GDK_KEY_KP_Left ||
9386 event->keyval == GDK_KEY_Right ||
9387 event->keyval == GDK_KEY_KP_Right)
9389 gboolean retval = TRUE;
9391 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9392 _gtk_entry_completion_popdown (completion);
9394 if (completion->priv->current_selected < 0)
9397 goto keypress_completion_out;
9399 else if (completion->priv->inline_selection)
9401 /* Escape rejects the tentative completion */
9402 if (event->keyval == GDK_KEY_Escape)
9404 if (completion->priv->completion_prefix)
9405 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9406 completion->priv->completion_prefix);
9408 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry), "");
9411 /* Move the cursor to the end for Right/Esc, to the
9412 beginning for Left */
9413 if (event->keyval == GDK_KEY_Right ||
9414 event->keyval == GDK_KEY_KP_Right ||
9415 event->keyval == GDK_KEY_Escape)
9416 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9418 gtk_editable_set_position (GTK_EDITABLE (widget), 0);
9421 keypress_completion_out:
9422 if (completion->priv->inline_selection)
9424 g_free (completion->priv->completion_prefix);
9425 completion->priv->completion_prefix = NULL;
9430 else if (event->keyval == GDK_KEY_Tab ||
9431 event->keyval == GDK_KEY_KP_Tab ||
9432 event->keyval == GDK_KEY_ISO_Left_Tab)
9434 GtkDirectionType dir = event->keyval == GDK_KEY_ISO_Left_Tab ?
9435 GTK_DIR_TAB_BACKWARD : GTK_DIR_TAB_FORWARD;
9437 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9438 _gtk_entry_completion_popdown (completion);
9440 g_free (completion->priv->completion_prefix);
9441 completion->priv->completion_prefix = NULL;
9443 gtk_widget_child_focus (gtk_widget_get_toplevel (widget), dir);
9447 else if (event->keyval == GDK_KEY_ISO_Enter ||
9448 event->keyval == GDK_KEY_KP_Enter ||
9449 event->keyval == GDK_KEY_Return)
9452 GtkTreeModel *model = NULL;
9453 GtkTreeSelection *sel;
9454 gboolean retval = TRUE;
9456 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9457 _gtk_entry_completion_popdown (completion);
9459 if (completion->priv->current_selected < matches)
9463 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view));
9464 if (gtk_tree_selection_get_selected (sel, &model, &iter))
9466 g_signal_handler_block (widget, completion->priv->changed_id);
9467 g_signal_emit_by_name (completion, "match-selected",
9468 model, &iter, &entry_set);
9469 g_signal_handler_unblock (widget, completion->priv->changed_id);
9475 gtk_tree_model_get (model, &iter,
9476 completion->priv->text_column, &str,
9479 gtk_entry_set_text (GTK_ENTRY (widget), str);
9481 /* move the cursor to the end */
9482 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9490 else if (completion->priv->current_selected - matches >= 0)
9492 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view));
9493 if (gtk_tree_selection_get_selected (sel, &model, &iter))
9497 path = gtk_tree_path_new_from_indices (completion->priv->current_selected - matches, -1);
9498 g_signal_emit_by_name (completion, "action-activated",
9499 gtk_tree_path_get_indices (path)[0]);
9500 gtk_tree_path_free (path);
9506 g_free (completion->priv->completion_prefix);
9507 completion->priv->completion_prefix = NULL;
9516 gtk_entry_completion_changed (GtkWidget *entry,
9519 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
9520 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
9523 /* (re)install completion timeout */
9524 if (completion->priv->completion_timeout)
9525 g_source_remove (completion->priv->completion_timeout);
9527 if (!gtk_entry_get_text (GTK_ENTRY (entry)))
9530 /* no need to normalize for this test */
9531 if (completion->priv->minimum_key_length > 0 &&
9532 strcmp ("", gtk_entry_get_text (GTK_ENTRY (entry))) == 0)
9534 if (gtk_widget_get_visible (completion->priv->popup_window))
9535 _gtk_entry_completion_popdown (completion);
9539 device = gtk_get_current_event_device ();
9541 if (device && device->source == GDK_SOURCE_KEYBOARD)
9542 device = gdk_device_get_associated_device (device);
9545 priv->completion_device = device;
9547 completion->priv->completion_timeout =
9548 gdk_threads_add_timeout (COMPLETION_TIMEOUT,
9549 gtk_entry_completion_timeout,
9554 check_completion_callback (GtkEntryCompletion *completion)
9556 completion->priv->check_completion_idle = NULL;
9558 gtk_entry_completion_complete (completion);
9559 gtk_entry_completion_insert_prefix (completion);
9565 clear_completion_callback (GtkEntry *entry,
9568 if (pspec->name == I_("cursor-position") ||
9569 pspec->name == I_("selection-bound"))
9571 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
9573 completion->priv->has_completion = FALSE;
9578 accept_completion_callback (GtkEntry *entry)
9580 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
9582 if (completion->priv->has_completion)
9583 gtk_editable_set_position (GTK_EDITABLE (entry),
9584 gtk_entry_buffer_get_length (get_buffer (entry)));
9590 completion_insert_text_callback (GtkEntry *entry,
9594 GtkEntryCompletion *completion)
9596 /* idle to update the selection based on the file list */
9597 if (completion->priv->check_completion_idle == NULL)
9599 completion->priv->check_completion_idle = g_idle_source_new ();
9600 g_source_set_priority (completion->priv->check_completion_idle, G_PRIORITY_HIGH);
9601 g_source_set_closure (completion->priv->check_completion_idle,
9602 g_cclosure_new_object (G_CALLBACK (check_completion_callback),
9603 G_OBJECT (completion)));
9604 g_source_attach (completion->priv->check_completion_idle, NULL);
9609 completion_changed (GtkEntryCompletion *completion,
9613 GtkEntry *entry = GTK_ENTRY (data);
9615 if (pspec->name == I_("popup-completion") ||
9616 pspec->name == I_("inline-completion"))
9618 disconnect_completion_signals (entry, completion);
9619 connect_completion_signals (entry, completion);
9624 disconnect_completion_signals (GtkEntry *entry,
9625 GtkEntryCompletion *completion)
9627 g_signal_handlers_disconnect_by_func (completion,
9628 G_CALLBACK (completion_changed), entry);
9629 if (completion->priv->changed_id > 0 &&
9630 g_signal_handler_is_connected (entry, completion->priv->changed_id))
9632 g_signal_handler_disconnect (entry, completion->priv->changed_id);
9633 completion->priv->changed_id = 0;
9635 g_signal_handlers_disconnect_by_func (entry,
9636 G_CALLBACK (gtk_entry_completion_key_press), completion);
9637 if (completion->priv->insert_text_id > 0 &&
9638 g_signal_handler_is_connected (entry, completion->priv->insert_text_id))
9640 g_signal_handler_disconnect (entry, completion->priv->insert_text_id);
9641 completion->priv->insert_text_id = 0;
9643 g_signal_handlers_disconnect_by_func (entry,
9644 G_CALLBACK (completion_insert_text_callback), completion);
9645 g_signal_handlers_disconnect_by_func (entry,
9646 G_CALLBACK (clear_completion_callback), completion);
9647 g_signal_handlers_disconnect_by_func (entry,
9648 G_CALLBACK (accept_completion_callback), completion);
9652 connect_completion_signals (GtkEntry *entry,
9653 GtkEntryCompletion *completion)
9655 if (completion->priv->popup_completion)
9657 completion->priv->changed_id =
9658 g_signal_connect (entry, "changed",
9659 G_CALLBACK (gtk_entry_completion_changed), completion);
9660 g_signal_connect (entry, "key-press-event",
9661 G_CALLBACK (gtk_entry_completion_key_press), completion);
9664 if (completion->priv->inline_completion)
9666 completion->priv->insert_text_id =
9667 g_signal_connect (entry, "insert-text",
9668 G_CALLBACK (completion_insert_text_callback), completion);
9669 g_signal_connect (entry, "notify",
9670 G_CALLBACK (clear_completion_callback), completion);
9671 g_signal_connect (entry, "activate",
9672 G_CALLBACK (accept_completion_callback), completion);
9673 g_signal_connect (entry, "focus-out-event",
9674 G_CALLBACK (accept_completion_callback), completion);
9677 g_signal_connect (completion, "notify",
9678 G_CALLBACK (completion_changed), entry);
9682 * gtk_entry_set_completion:
9683 * @entry: A #GtkEntry
9684 * @completion: (allow-none): The #GtkEntryCompletion or %NULL
9686 * Sets @completion to be the auxiliary completion object to use with @entry.
9687 * All further configuration of the completion mechanism is done on
9688 * @completion using the #GtkEntryCompletion API. Completion is disabled if
9689 * @completion is set to %NULL.
9694 gtk_entry_set_completion (GtkEntry *entry,
9695 GtkEntryCompletion *completion)
9697 GtkEntryCompletion *old;
9699 g_return_if_fail (GTK_IS_ENTRY (entry));
9700 g_return_if_fail (!completion || GTK_IS_ENTRY_COMPLETION (completion));
9702 old = gtk_entry_get_completion (entry);
9704 if (old == completion)
9709 if (old->priv->completion_timeout)
9711 g_source_remove (old->priv->completion_timeout);
9712 old->priv->completion_timeout = 0;
9715 if (gtk_widget_get_mapped (old->priv->popup_window))
9716 _gtk_entry_completion_popdown (old);
9718 disconnect_completion_signals (entry, old);
9719 old->priv->entry = NULL;
9721 g_object_unref (old);
9726 g_object_set_data (G_OBJECT (entry), I_(GTK_ENTRY_COMPLETION_KEY), NULL);
9730 /* hook into the entry */
9731 g_object_ref (completion);
9733 connect_completion_signals (entry, completion);
9734 completion->priv->entry = GTK_WIDGET (entry);
9735 g_object_set_data (G_OBJECT (entry), I_(GTK_ENTRY_COMPLETION_KEY), completion);
9739 * gtk_entry_get_completion:
9740 * @entry: A #GtkEntry
9742 * Returns the auxiliary completion object currently in use by @entry.
9744 * Return value: (transfer none): The auxiliary completion object currently
9749 GtkEntryCompletion *
9750 gtk_entry_get_completion (GtkEntry *entry)
9752 GtkEntryCompletion *completion;
9754 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
9756 completion = GTK_ENTRY_COMPLETION (g_object_get_data (G_OBJECT (entry),
9757 GTK_ENTRY_COMPLETION_KEY));
9763 * gtk_entry_set_cursor_hadjustment:
9764 * @entry: a #GtkEntry
9765 * @adjustment: an adjustment which should be adjusted when the cursor
9766 * is moved, or %NULL
9768 * Hooks up an adjustment to the cursor position in an entry, so that when
9769 * the cursor is moved, the adjustment is scrolled to show that position.
9770 * See gtk_scrolled_window_get_hadjustment() for a typical way of obtaining
9773 * The adjustment has to be in pixel units and in the same coordinate system
9779 gtk_entry_set_cursor_hadjustment (GtkEntry *entry,
9780 GtkAdjustment *adjustment)
9782 g_return_if_fail (GTK_IS_ENTRY (entry));
9784 g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
9787 g_object_ref (adjustment);
9789 g_object_set_qdata_full (G_OBJECT (entry),
9790 quark_cursor_hadjustment,
9796 * gtk_entry_get_cursor_hadjustment:
9797 * @entry: a #GtkEntry
9799 * Retrieves the horizontal cursor adjustment for the entry.
9800 * See gtk_entry_set_cursor_hadjustment().
9802 * Return value: (transfer none): the horizontal cursor adjustment, or %NULL
9803 * if none has been set.
9808 gtk_entry_get_cursor_hadjustment (GtkEntry *entry)
9810 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
9812 return g_object_get_qdata (G_OBJECT (entry), quark_cursor_hadjustment);
9816 * gtk_entry_set_progress_fraction:
9817 * @entry: a #GtkEntry
9818 * @fraction: fraction of the task that's been completed
9820 * Causes the entry's progress indicator to "fill in" the given
9821 * fraction of the bar. The fraction should be between 0.0 and 1.0,
9827 gtk_entry_set_progress_fraction (GtkEntry *entry,
9831 GtkEntryPrivate *private;
9832 gdouble old_fraction;
9833 gint x, y, width, height;
9834 gint old_x, old_y, old_width, old_height;
9836 g_return_if_fail (GTK_IS_ENTRY (entry));
9838 widget = GTK_WIDGET (entry);
9839 private = GTK_ENTRY_GET_PRIVATE (entry);
9841 if (private->progress_pulse_mode)
9844 old_fraction = private->progress_fraction;
9846 if (gtk_widget_is_drawable (widget))
9847 get_progress_area (widget, &old_x, &old_y, &old_width, &old_height);
9849 fraction = CLAMP (fraction, 0.0, 1.0);
9851 private->progress_fraction = fraction;
9852 private->progress_pulse_mode = FALSE;
9853 private->progress_pulse_current = 0.0;
9855 if (gtk_widget_is_drawable (widget))
9857 get_progress_area (widget, &x, &y, &width, &height);
9859 if ((x != old_x) || (y != old_y) || (width != old_width) || (height != old_height))
9860 gtk_widget_queue_draw (widget);
9863 if (fraction != old_fraction)
9864 g_object_notify (G_OBJECT (entry), "progress-fraction");
9868 * gtk_entry_get_progress_fraction:
9869 * @entry: a #GtkEntry
9871 * Returns the current fraction of the task that's been completed.
9872 * See gtk_entry_set_progress_fraction().
9874 * Return value: a fraction from 0.0 to 1.0
9879 gtk_entry_get_progress_fraction (GtkEntry *entry)
9881 GtkEntryPrivate *private;
9883 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
9885 private = GTK_ENTRY_GET_PRIVATE (entry);
9887 return private->progress_fraction;
9891 * gtk_entry_set_progress_pulse_step:
9892 * @entry: a #GtkEntry
9893 * @fraction: fraction between 0.0 and 1.0
9895 * Sets the fraction of total entry width to move the progress
9896 * bouncing block for each call to gtk_entry_progress_pulse().
9901 gtk_entry_set_progress_pulse_step (GtkEntry *entry,
9904 GtkEntryPrivate *private;
9906 g_return_if_fail (GTK_IS_ENTRY (entry));
9908 private = GTK_ENTRY_GET_PRIVATE (entry);
9910 fraction = CLAMP (fraction, 0.0, 1.0);
9912 if (fraction != private->progress_pulse_fraction)
9914 private->progress_pulse_fraction = fraction;
9916 gtk_widget_queue_draw (GTK_WIDGET (entry));
9918 g_object_notify (G_OBJECT (entry), "progress-pulse-step");
9923 * gtk_entry_get_progress_pulse_step:
9924 * @entry: a #GtkEntry
9926 * Retrieves the pulse step set with gtk_entry_set_progress_pulse_step().
9928 * Return value: a fraction from 0.0 to 1.0
9933 gtk_entry_get_progress_pulse_step (GtkEntry *entry)
9935 GtkEntryPrivate *private;
9937 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
9939 private = GTK_ENTRY_GET_PRIVATE (entry);
9941 return private->progress_pulse_fraction;
9945 * gtk_entry_progress_pulse:
9946 * @entry: a #GtkEntry
9948 * Indicates that some progress is made, but you don't know how much.
9949 * Causes the entry's progress indicator to enter "activity mode,"
9950 * where a block bounces back and forth. Each call to
9951 * gtk_entry_progress_pulse() causes the block to move by a little bit
9952 * (the amount of movement per pulse is determined by
9953 * gtk_entry_set_progress_pulse_step()).
9958 gtk_entry_progress_pulse (GtkEntry *entry)
9960 GtkEntryPrivate *private;
9962 g_return_if_fail (GTK_IS_ENTRY (entry));
9964 private = GTK_ENTRY_GET_PRIVATE (entry);
9966 if (private->progress_pulse_mode)
9968 if (private->progress_pulse_way_back)
9970 private->progress_pulse_current -= private->progress_pulse_fraction;
9972 if (private->progress_pulse_current < 0.0)
9974 private->progress_pulse_current = 0.0;
9975 private->progress_pulse_way_back = FALSE;
9980 private->progress_pulse_current += private->progress_pulse_fraction;
9982 if (private->progress_pulse_current > 1.0 - private->progress_pulse_fraction)
9984 private->progress_pulse_current = 1.0 - private->progress_pulse_fraction;
9985 private->progress_pulse_way_back = TRUE;
9991 private->progress_fraction = 0.0;
9992 private->progress_pulse_mode = TRUE;
9993 private->progress_pulse_way_back = FALSE;
9994 private->progress_pulse_current = 0.0;
9997 gtk_widget_queue_draw (GTK_WIDGET (entry));
10000 /* Caps Lock warning for password entries */
10003 show_capslock_feedback (GtkEntry *entry,
10006 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
10008 if (gtk_entry_get_icon_storage_type (entry, GTK_ENTRY_ICON_SECONDARY) == GTK_IMAGE_EMPTY)
10010 gtk_entry_set_icon_from_stock (entry, GTK_ENTRY_ICON_SECONDARY, GTK_STOCK_CAPS_LOCK_WARNING);
10011 gtk_entry_set_icon_activatable (entry, GTK_ENTRY_ICON_SECONDARY, FALSE);
10012 priv->caps_lock_warning_shown = TRUE;
10015 if (priv->caps_lock_warning_shown)
10016 gtk_entry_set_icon_tooltip_text (entry, GTK_ENTRY_ICON_SECONDARY, text);
10018 g_warning ("Can't show Caps Lock warning, since secondary icon is set");
10022 remove_capslock_feedback (GtkEntry *entry)
10024 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
10026 if (priv->caps_lock_warning_shown)
10028 gtk_entry_set_icon_from_stock (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
10029 priv->caps_lock_warning_shown = FALSE;
10034 keymap_state_changed (GdkKeymap *keymap,
10037 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
10040 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL && priv->caps_lock_warning)
10042 if (gdk_keymap_get_num_lock_state (keymap)
10043 && gdk_keymap_get_caps_lock_state (keymap))
10044 text = _("Caps Lock and Num Lock are on");
10045 else if (gdk_keymap_get_num_lock_state (keymap))
10046 text = _("Num Lock is on");
10047 else if (gdk_keymap_get_caps_lock_state (keymap))
10048 text = _("Caps Lock is on");
10052 show_capslock_feedback (entry, text);
10054 remove_capslock_feedback (entry);