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 gtk_entry_get_progress_border (GtkWidget *widget,
3398 GtkBorder *progress_border)
3400 GtkBorder *tmp_border;
3403 gtk_widget_style_get (widget, "progress-border", &tmp_border, NULL);
3406 *progress_border = *tmp_border;
3407 gtk_border_free (tmp_border);
3411 style = gtk_widget_get_style (widget);
3413 progress_border->left = style->xthickness;
3414 progress_border->right = style->xthickness;
3415 progress_border->top = style->ythickness;
3416 progress_border->bottom = style->ythickness;
3421 get_progress_area (GtkWidget *widget,
3427 GtkEntryPrivate *private = GTK_ENTRY_GET_PRIVATE (widget);
3428 GtkEntry *entry = GTK_ENTRY (widget);
3429 GtkBorder progress_border;
3430 gint frame_width, frame_height;
3432 get_frame_size (entry, NULL, NULL, &frame_width, &frame_height);
3433 gtk_entry_get_progress_border (widget, &progress_border);
3435 *x = progress_border.left;
3436 *y = progress_border.top;
3438 *width = frame_width
3439 - progress_border.left - progress_border.right;
3440 *height = frame_height
3441 - progress_border.top - progress_border.bottom;
3443 if (gtk_widget_has_focus (widget) && !private->interior_focus)
3445 *x += private->focus_width;
3446 *y += private->focus_width;
3447 *width -= 2 * private->focus_width;
3448 *height -= 2 * private->focus_width;
3451 if (private->progress_pulse_mode)
3453 gdouble value = private->progress_pulse_current;
3455 *x += (gint) floor(value * (*width));
3456 *width = (gint) ceil(private->progress_pulse_fraction * (*width));
3458 else if (private->progress_fraction > 0)
3460 gdouble value = private->progress_fraction;
3462 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
3466 bar_width = floor(value * (*width) + 0.5);
3467 *x += *width - bar_width;
3472 *width = (gint) floor(value * (*width) + 0.5);
3483 gtk_entry_draw_progress (GtkWidget *widget,
3486 gint x, y, width, height;
3489 get_progress_area (widget, &x, &y, &width, &height);
3491 if ((width <= 0) || (height <= 0))
3494 state = GTK_STATE_SELECTED;
3495 if (!gtk_widget_get_sensitive (widget))
3496 state = GTK_STATE_INSENSITIVE;
3498 gtk_paint_box (gtk_widget_get_style (widget), cr,
3499 state, GTK_SHADOW_OUT,
3500 widget, "entry-progress",
3506 gtk_entry_draw (GtkWidget *widget,
3509 GtkEntry *entry = GTK_ENTRY (widget);
3512 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3515 style = gtk_widget_get_style (widget);
3517 state = gtk_widget_has_focus (widget) ?
3518 GTK_STATE_ACTIVE : gtk_widget_get_state (widget);
3520 if (gtk_cairo_should_draw_window (cr, gtk_widget_get_window (widget)))
3522 /* Draw entry_bg, shadow, progress and focus */
3523 gtk_entry_draw_frame (widget, cr);
3525 /* Draw text and cursor */
3528 gtk_cairo_transform_to_window (cr, widget, entry->text_area);
3530 if (entry->dnd_position != -1)
3531 gtk_entry_draw_cursor (GTK_ENTRY (widget), cr, CURSOR_DND);
3533 gtk_entry_draw_text (GTK_ENTRY (widget), cr);
3535 /* When no text is being displayed at all, don't show the cursor */
3536 if (gtk_entry_get_display_mode (entry) != DISPLAY_BLANK &&
3537 gtk_widget_has_focus (widget) &&
3538 entry->selection_bound == entry->current_pos && entry->cursor_visible)
3539 gtk_entry_draw_cursor (GTK_ENTRY (widget), cr, CURSOR_STANDARD);
3544 for (i = 0; i < MAX_ICONS; i++)
3546 EntryIconInfo *icon_info = priv->icons[i];
3548 if (icon_info != NULL)
3552 gtk_cairo_transform_to_window (cr, widget, icon_info->window);
3554 draw_icon (widget, cr, i);
3565 gtk_entry_enter_notify (GtkWidget *widget,
3566 GdkEventCrossing *event)
3568 GtkEntry *entry = GTK_ENTRY (widget);
3569 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3572 for (i = 0; i < MAX_ICONS; i++)
3574 EntryIconInfo *icon_info = priv->icons[i];
3576 if (icon_info != NULL && event->window == icon_info->window)
3578 if (should_prelight (entry, i))
3580 icon_info->prelight = TRUE;
3581 gtk_widget_queue_draw (widget);
3592 gtk_entry_leave_notify (GtkWidget *widget,
3593 GdkEventCrossing *event)
3595 GtkEntry *entry = GTK_ENTRY (widget);
3596 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3599 for (i = 0; i < MAX_ICONS; i++)
3601 EntryIconInfo *icon_info = priv->icons[i];
3603 if (icon_info != NULL && event->window == icon_info->window)
3605 /* a grab means that we may never see the button release */
3606 if (event->mode == GDK_CROSSING_GRAB || event->mode == GDK_CROSSING_GTK_GRAB)
3607 icon_info->pressed = FALSE;
3609 if (should_prelight (entry, i))
3611 icon_info->prelight = FALSE;
3612 gtk_widget_queue_draw (widget);
3623 gtk_entry_get_pixel_ranges (GtkEntry *entry,
3627 gint start_char, end_char;
3629 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start_char, &end_char))
3631 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
3632 PangoLayoutLine *line = pango_layout_get_lines_readonly (layout)->data;
3633 const char *text = pango_layout_get_text (layout);
3634 gint start_index = g_utf8_offset_to_pointer (text, start_char) - text;
3635 gint end_index = g_utf8_offset_to_pointer (text, end_char) - text;
3636 gint real_n_ranges, i;
3638 pango_layout_line_get_x_ranges (line, start_index, end_index, ranges, &real_n_ranges);
3644 for (i = 0; i < real_n_ranges; ++i)
3646 r[2 * i + 1] = (r[2 * i + 1] - r[2 * i]) / PANGO_SCALE;
3647 r[2 * i] = r[2 * i] / PANGO_SCALE;
3652 *n_ranges = real_n_ranges;
3664 in_selection (GtkEntry *entry,
3669 gint retval = FALSE;
3671 gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
3673 for (i = 0; i < n_ranges; ++i)
3675 if (x >= ranges[2 * i] && x < ranges[2 * i] + ranges[2 * i + 1])
3687 gtk_entry_button_press (GtkWidget *widget,
3688 GdkEventButton *event)
3690 GtkEntry *entry = GTK_ENTRY (widget);
3691 GtkEditable *editable = GTK_EDITABLE (widget);
3692 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3693 EntryIconInfo *icon_info = NULL;
3695 gint sel_start, sel_end;
3698 for (i = 0; i < MAX_ICONS; i++)
3700 icon_info = priv->icons[i];
3702 if (!icon_info || icon_info->insensitive)
3705 if (event->window == icon_info->window)
3707 if (should_prelight (entry, i))
3709 icon_info->prelight = FALSE;
3710 gtk_widget_queue_draw (widget);
3713 priv->start_x = event->x;
3714 priv->start_y = event->y;
3715 icon_info->pressed = TRUE;
3717 if (!icon_info->nonactivatable)
3718 g_signal_emit (entry, signals[ICON_PRESS], 0, i, event);
3724 if (event->window != entry->text_area ||
3725 (entry->button && event->button != entry->button))
3728 gtk_entry_reset_blink_time (entry);
3730 entry->button = event->button;
3732 if (!gtk_widget_has_focus (widget))
3734 entry->in_click = TRUE;
3735 gtk_widget_grab_focus (widget);
3736 entry->in_click = FALSE;
3739 tmp_pos = gtk_entry_find_position (entry, event->x + entry->scroll_offset);
3741 if (event->button == 1)
3743 gboolean have_selection = gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end);
3745 entry->select_words = FALSE;
3746 entry->select_lines = FALSE;
3748 if (event->state & GDK_SHIFT_MASK)
3750 _gtk_entry_reset_im_context (entry);
3752 if (!have_selection) /* select from the current position to the clicked position */
3753 sel_start = sel_end = entry->current_pos;
3755 if (tmp_pos > sel_start && tmp_pos < sel_end)
3757 /* Truncate current selection, but keep it as big as possible */
3758 if (tmp_pos - sel_start > sel_end - tmp_pos)
3759 gtk_entry_set_positions (entry, sel_start, tmp_pos);
3761 gtk_entry_set_positions (entry, tmp_pos, sel_end);
3765 gboolean extend_to_left;
3768 /* Figure out what click selects and extend current selection */
3769 switch (event->type)
3771 case GDK_BUTTON_PRESS:
3772 gtk_entry_set_positions (entry, tmp_pos, tmp_pos);
3775 case GDK_2BUTTON_PRESS:
3776 entry->select_words = TRUE;
3777 gtk_entry_select_word (entry);
3780 case GDK_3BUTTON_PRESS:
3781 entry->select_lines = TRUE;
3782 gtk_entry_select_line (entry);
3789 start = MIN (entry->current_pos, entry->selection_bound);
3790 start = MIN (sel_start, start);
3792 end = MAX (entry->current_pos, entry->selection_bound);
3793 end = MAX (sel_end, end);
3795 if (tmp_pos == sel_start || tmp_pos == sel_end)
3796 extend_to_left = (tmp_pos == start);
3798 extend_to_left = (end == sel_end);
3801 gtk_entry_set_positions (entry, start, end);
3803 gtk_entry_set_positions (entry, end, start);
3806 else /* no shift key */
3807 switch (event->type)
3809 case GDK_BUTTON_PRESS:
3810 if (in_selection (entry, event->x + entry->scroll_offset))
3812 /* Click inside the selection - we'll either start a drag, or
3813 * clear the selection
3815 entry->in_drag = TRUE;
3816 entry->drag_start_x = event->x + entry->scroll_offset;
3817 entry->drag_start_y = event->y;
3820 gtk_editable_set_position (editable, tmp_pos);
3823 case GDK_2BUTTON_PRESS:
3824 /* We ALWAYS receive a GDK_BUTTON_PRESS immediately before
3825 * receiving a GDK_2BUTTON_PRESS so we need to reset
3826 * entry->in_drag which may have been set above
3828 entry->in_drag = FALSE;
3829 entry->select_words = TRUE;
3830 gtk_entry_select_word (entry);
3833 case GDK_3BUTTON_PRESS:
3834 /* We ALWAYS receive a GDK_BUTTON_PRESS immediately before
3835 * receiving a GDK_3BUTTON_PRESS so we need to reset
3836 * entry->in_drag which may have been set above
3838 entry->in_drag = FALSE;
3839 entry->select_lines = TRUE;
3840 gtk_entry_select_line (entry);
3849 else if (event->button == 2 && event->type == GDK_BUTTON_PRESS)
3851 if (entry->editable)
3853 priv->insert_pos = tmp_pos;
3854 gtk_entry_paste (entry, GDK_SELECTION_PRIMARY);
3859 gtk_widget_error_bell (widget);
3862 else if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
3864 gtk_entry_do_popup (entry, event);
3865 entry->button = 0; /* Don't wait for release, since the menu will gtk_grab_add */
3874 gtk_entry_button_release (GtkWidget *widget,
3875 GdkEventButton *event)
3877 GtkEntry *entry = GTK_ENTRY (widget);
3878 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
3879 EntryIconInfo *icon_info = NULL;
3882 for (i = 0; i < MAX_ICONS; i++)
3884 icon_info = priv->icons[i];
3886 if (!icon_info || icon_info->insensitive)
3889 if (event->window == icon_info->window)
3891 icon_info->pressed = FALSE;
3893 if (should_prelight (entry, i) &&
3894 event->x >= 0 && event->y >= 0 &&
3895 event->x < gdk_window_get_width (icon_info->window) &&
3896 event->y < gdk_window_get_height (icon_info->window))
3898 icon_info->prelight = TRUE;
3899 gtk_widget_queue_draw (widget);
3902 if (!icon_info->nonactivatable)
3903 g_signal_emit (entry, signals[ICON_RELEASE], 0, i, event);
3909 if (event->window != entry->text_area || entry->button != event->button)
3914 gint tmp_pos = gtk_entry_find_position (entry, entry->drag_start_x);
3916 gtk_editable_set_position (GTK_EDITABLE (entry), tmp_pos);
3923 gtk_entry_update_primary_selection (entry);
3929 _gtk_entry_get_selected_text (GtkEntry *entry)
3931 GtkEditable *editable = GTK_EDITABLE (entry);
3932 gint start_text, end_text;
3935 if (gtk_editable_get_selection_bounds (editable, &start_text, &end_text))
3936 text = gtk_editable_get_chars (editable, start_text, end_text);
3942 gtk_entry_motion_notify (GtkWidget *widget,
3943 GdkEventMotion *event)
3945 GtkEntry *entry = GTK_ENTRY (widget);
3946 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3947 EntryIconInfo *icon_info = NULL;
3948 GdkDragContext *context;
3952 for (i = 0; i < MAX_ICONS; i++)
3954 icon_info = priv->icons[i];
3956 if (!icon_info || icon_info->insensitive)
3959 if (event->window == icon_info->window)
3961 if (icon_info->pressed &&
3962 icon_info->target_list != NULL &&
3963 gtk_drag_check_threshold (widget,
3969 icon_info->in_drag = TRUE;
3970 icon_info->pressed = FALSE;
3971 context = gtk_drag_begin (widget,
3972 icon_info->target_list,
3982 if (entry->mouse_cursor_obscured)
3986 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
3987 gdk_window_set_cursor (entry->text_area, cursor);
3988 gdk_cursor_unref (cursor);
3989 entry->mouse_cursor_obscured = FALSE;
3992 if (event->window != entry->text_area || entry->button != 1)
3995 if (entry->select_lines)
3998 gdk_event_request_motions (event);
4002 if (gtk_entry_get_display_mode (entry) == DISPLAY_NORMAL &&
4003 gtk_drag_check_threshold (widget,
4004 entry->drag_start_x, entry->drag_start_y,
4005 event->x + entry->scroll_offset, event->y))
4007 GdkDragContext *context;
4008 GtkTargetList *target_list = gtk_target_list_new (NULL, 0);
4009 guint actions = entry->editable ? GDK_ACTION_COPY | GDK_ACTION_MOVE : GDK_ACTION_COPY;
4011 cairo_surface_t *surface;
4013 gtk_target_list_add_text_targets (target_list, 0);
4015 text = _gtk_entry_get_selected_text (entry);
4016 surface = _gtk_text_util_create_drag_icon (widget, text, -1);
4018 context = gtk_drag_begin (widget, target_list, actions,
4019 entry->button, (GdkEvent *)event);
4022 gtk_drag_set_icon_surface (context, surface);
4024 gtk_drag_set_icon_default (context);
4027 cairo_surface_destroy (surface);
4030 entry->in_drag = FALSE;
4033 gtk_target_list_unref (target_list);
4040 else if (event->y >= gdk_window_get_height (entry->text_area))
4041 tmp_pos = gtk_entry_buffer_get_length (get_buffer (entry));
4043 tmp_pos = gtk_entry_find_position (entry, event->x + entry->scroll_offset);
4045 if (entry->select_words)
4048 gint old_min, old_max;
4051 min = gtk_entry_move_backward_word (entry, tmp_pos, TRUE);
4052 max = gtk_entry_move_forward_word (entry, tmp_pos, TRUE);
4054 pos = entry->current_pos;
4055 bound = entry->selection_bound;
4057 old_min = MIN(entry->current_pos, entry->selection_bound);
4058 old_max = MAX(entry->current_pos, entry->selection_bound);
4065 else if (old_max < max)
4070 else if (pos == old_min)
4072 if (entry->current_pos != min)
4077 if (entry->current_pos != max)
4081 gtk_entry_set_positions (entry, pos, bound);
4084 gtk_entry_set_positions (entry, tmp_pos, -1);
4091 set_invisible_cursor (GdkWindow *window)
4093 GdkDisplay *display;
4096 display = gdk_window_get_display (window);
4097 cursor = gdk_cursor_new_for_display (display, GDK_BLANK_CURSOR);
4099 gdk_window_set_cursor (window, cursor);
4101 gdk_cursor_unref (cursor);
4105 gtk_entry_obscure_mouse_cursor (GtkEntry *entry)
4107 if (entry->mouse_cursor_obscured)
4110 set_invisible_cursor (entry->text_area);
4112 entry->mouse_cursor_obscured = TRUE;
4116 gtk_entry_key_press (GtkWidget *widget,
4119 GtkEntry *entry = GTK_ENTRY (widget);
4121 gtk_entry_reset_blink_time (entry);
4122 gtk_entry_pend_cursor_blink (entry);
4124 if (entry->editable)
4126 if (gtk_im_context_filter_keypress (entry->im_context, event))
4128 gtk_entry_obscure_mouse_cursor (entry);
4129 entry->need_im_reset = TRUE;
4134 if (event->keyval == GDK_KEY_Return ||
4135 event->keyval == GDK_KEY_KP_Enter ||
4136 event->keyval == GDK_KEY_ISO_Enter ||
4137 event->keyval == GDK_KEY_Escape)
4139 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
4141 if (completion && completion->priv->completion_timeout)
4143 g_source_remove (completion->priv->completion_timeout);
4144 completion->priv->completion_timeout = 0;
4147 _gtk_entry_reset_im_context (entry);
4150 if (GTK_WIDGET_CLASS (gtk_entry_parent_class)->key_press_event (widget, event))
4151 /* Activate key bindings
4155 if (!entry->editable && event->length)
4156 gtk_widget_error_bell (widget);
4162 gtk_entry_key_release (GtkWidget *widget,
4165 GtkEntry *entry = GTK_ENTRY (widget);
4167 if (entry->editable)
4169 if (gtk_im_context_filter_keypress (entry->im_context, event))
4171 entry->need_im_reset = TRUE;
4176 return GTK_WIDGET_CLASS (gtk_entry_parent_class)->key_release_event (widget, event);
4180 gtk_entry_focus_in (GtkWidget *widget,
4181 GdkEventFocus *event)
4183 GtkEntry *entry = GTK_ENTRY (widget);
4186 gtk_widget_queue_draw (widget);
4188 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (widget));
4190 if (entry->editable)
4192 entry->need_im_reset = TRUE;
4193 gtk_im_context_focus_in (entry->im_context);
4194 keymap_state_changed (keymap, entry);
4195 g_signal_connect (keymap, "state-changed",
4196 G_CALLBACK (keymap_state_changed), entry);
4199 g_signal_connect (keymap, "direction-changed",
4200 G_CALLBACK (keymap_direction_changed), entry);
4202 gtk_entry_reset_blink_time (entry);
4203 gtk_entry_check_cursor_blink (entry);
4209 gtk_entry_focus_out (GtkWidget *widget,
4210 GdkEventFocus *event)
4212 GtkEntry *entry = GTK_ENTRY (widget);
4213 GtkEntryCompletion *completion;
4216 gtk_widget_queue_draw (widget);
4218 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (widget));
4220 if (entry->editable)
4222 entry->need_im_reset = TRUE;
4223 gtk_im_context_focus_out (entry->im_context);
4224 remove_capslock_feedback (entry);
4227 gtk_entry_check_cursor_blink (entry);
4229 g_signal_handlers_disconnect_by_func (keymap, keymap_state_changed, entry);
4230 g_signal_handlers_disconnect_by_func (keymap, keymap_direction_changed, entry);
4232 completion = gtk_entry_get_completion (entry);
4234 _gtk_entry_completion_popdown (completion);
4240 gtk_entry_grab_focus (GtkWidget *widget)
4242 GtkEntry *entry = GTK_ENTRY (widget);
4243 gboolean select_on_focus;
4245 GTK_WIDGET_CLASS (gtk_entry_parent_class)->grab_focus (widget);
4247 if (entry->editable && !entry->in_click)
4249 g_object_get (gtk_widget_get_settings (widget),
4250 "gtk-entry-select-on-focus",
4254 if (select_on_focus)
4255 gtk_editable_select_region (GTK_EDITABLE (widget), 0, -1);
4260 gtk_entry_direction_changed (GtkWidget *widget,
4261 GtkTextDirection previous_dir)
4263 GtkEntry *entry = GTK_ENTRY (widget);
4265 gtk_entry_recompute (entry);
4267 GTK_WIDGET_CLASS (gtk_entry_parent_class)->direction_changed (widget, previous_dir);
4271 gtk_entry_state_changed (GtkWidget *widget,
4272 GtkStateType previous_state)
4274 GtkEntry *entry = GTK_ENTRY (widget);
4277 if (gtk_widget_get_realized (widget))
4279 if (gtk_widget_is_sensitive (widget))
4280 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
4284 gdk_window_set_cursor (entry->text_area, cursor);
4287 gdk_cursor_unref (cursor);
4289 entry->mouse_cursor_obscured = FALSE;
4291 update_cursors (widget);
4294 if (!gtk_widget_is_sensitive (widget))
4296 /* Clear any selection */
4297 gtk_editable_select_region (GTK_EDITABLE (entry), entry->current_pos, entry->current_pos);
4300 gtk_widget_queue_draw (widget);
4304 gtk_entry_screen_changed (GtkWidget *widget,
4305 GdkScreen *old_screen)
4307 gtk_entry_recompute (GTK_ENTRY (widget));
4310 /* GtkEditable method implementations
4313 gtk_entry_insert_text (GtkEditable *editable,
4314 const gchar *new_text,
4315 gint new_text_length,
4318 g_object_ref (editable);
4321 * The incoming text may a password or other secret. We make sure
4322 * not to copy it into temporary buffers.
4325 g_signal_emit_by_name (editable, "insert-text", new_text, new_text_length, position);
4327 g_object_unref (editable);
4331 gtk_entry_delete_text (GtkEditable *editable,
4335 g_object_ref (editable);
4337 g_signal_emit_by_name (editable, "delete-text", start_pos, end_pos);
4339 g_object_unref (editable);
4343 gtk_entry_get_chars (GtkEditable *editable,
4347 GtkEntry *entry = GTK_ENTRY (editable);
4350 gint start_index, end_index;
4352 text = gtk_entry_buffer_get_text (get_buffer (entry));
4353 text_length = gtk_entry_buffer_get_length (get_buffer (entry));
4356 end_pos = text_length;
4358 start_pos = MIN (text_length, start_pos);
4359 end_pos = MIN (text_length, end_pos);
4361 start_index = g_utf8_offset_to_pointer (text, start_pos) - text;
4362 end_index = g_utf8_offset_to_pointer (text, end_pos) - text;
4364 return g_strndup (text + start_index, end_index - start_index);
4368 gtk_entry_real_set_position (GtkEditable *editable,
4371 GtkEntry *entry = GTK_ENTRY (editable);
4375 length = gtk_entry_buffer_get_length (get_buffer (entry));
4376 if (position < 0 || position > length)
4379 if (position != entry->current_pos ||
4380 position != entry->selection_bound)
4382 _gtk_entry_reset_im_context (entry);
4383 gtk_entry_set_positions (entry, position, position);
4388 gtk_entry_get_position (GtkEditable *editable)
4390 return GTK_ENTRY (editable)->current_pos;
4394 gtk_entry_set_selection_bounds (GtkEditable *editable,
4398 GtkEntry *entry = GTK_ENTRY (editable);
4401 length = gtk_entry_buffer_get_length (get_buffer (entry));
4407 _gtk_entry_reset_im_context (entry);
4409 gtk_entry_set_positions (entry,
4411 MIN (start, length));
4413 gtk_entry_update_primary_selection (entry);
4417 gtk_entry_get_selection_bounds (GtkEditable *editable,
4421 GtkEntry *entry = GTK_ENTRY (editable);
4423 *start = entry->selection_bound;
4424 *end = entry->current_pos;
4426 return (entry->selection_bound != entry->current_pos);
4430 icon_theme_changed (GtkEntry *entry)
4432 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
4435 for (i = 0; i < MAX_ICONS; i++)
4437 EntryIconInfo *icon_info = priv->icons[i];
4438 if (icon_info != NULL)
4440 if (icon_info->storage_type == GTK_IMAGE_ICON_NAME)
4441 gtk_entry_set_icon_from_icon_name (entry, i, icon_info->icon_name);
4442 else if (icon_info->storage_type == GTK_IMAGE_STOCK)
4443 gtk_entry_set_icon_from_stock (entry, i, icon_info->stock_id);
4444 else if (icon_info->storage_type == GTK_IMAGE_GICON)
4445 gtk_entry_set_icon_from_gicon (entry, i, icon_info->gicon);
4449 gtk_widget_queue_draw (GTK_WIDGET (entry));
4453 icon_margin_changed (GtkEntry *entry)
4455 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
4458 _gtk_entry_effective_inner_border (GTK_ENTRY (entry), &border);
4460 priv->icon_margin = border.left;
4464 gtk_entry_style_set (GtkWidget *widget,
4465 GtkStyle *previous_style)
4467 GtkEntry *entry = GTK_ENTRY (widget);
4468 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
4470 gboolean interior_focus;
4472 gtk_widget_style_get (widget,
4473 "focus-line-width", &focus_width,
4474 "interior-focus", &interior_focus,
4477 priv->focus_width = focus_width;
4478 priv->interior_focus = interior_focus;
4480 if (!priv->invisible_char_set)
4481 entry->invisible_char = find_invisible_char (GTK_WIDGET (entry));
4483 gtk_entry_recompute (entry);
4485 icon_theme_changed (entry);
4486 icon_margin_changed (entry);
4489 /* GtkCellEditable method implementations
4492 gtk_cell_editable_entry_activated (GtkEntry *entry, gpointer data)
4494 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4495 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4499 gtk_cell_editable_key_press_event (GtkEntry *entry,
4500 GdkEventKey *key_event,
4503 if (key_event->keyval == GDK_KEY_Escape)
4505 entry->editing_canceled = TRUE;
4506 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4507 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4512 /* override focus */
4513 if (key_event->keyval == GDK_KEY_Up || key_event->keyval == GDK_KEY_Down)
4515 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4516 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4525 gtk_entry_start_editing (GtkCellEditable *cell_editable,
4528 GTK_ENTRY (cell_editable)->is_cell_renderer = TRUE;
4530 g_signal_connect (cell_editable, "activate",
4531 G_CALLBACK (gtk_cell_editable_entry_activated), NULL);
4532 g_signal_connect (cell_editable, "key-press-event",
4533 G_CALLBACK (gtk_cell_editable_key_press_event), NULL);
4537 gtk_entry_password_hint_free (GtkEntryPasswordHint *password_hint)
4539 if (password_hint->source_id)
4540 g_source_remove (password_hint->source_id);
4542 g_slice_free (GtkEntryPasswordHint, password_hint);
4547 gtk_entry_remove_password_hint (gpointer data)
4549 GtkEntryPasswordHint *password_hint = g_object_get_qdata (data, quark_password_hint);
4550 password_hint->position = -1;
4552 /* Force the string to be redrawn, but now without a visible character */
4553 gtk_entry_recompute (GTK_ENTRY (data));
4557 /* Default signal handlers
4560 gtk_entry_real_insert_text (GtkEditable *editable,
4561 const gchar *new_text,
4562 gint new_text_length,
4568 n_chars = g_utf8_strlen (new_text, new_text_length);
4571 * The actual insertion into the buffer. This will end up firing the
4572 * following signal handlers: buffer_inserted_text(), buffer_notify_display_text(),
4573 * buffer_notify_text(), buffer_notify_length()
4575 n_inserted = gtk_entry_buffer_insert_text (get_buffer (GTK_ENTRY (editable)), *position, new_text, n_chars);
4577 if (n_inserted != n_chars)
4578 gtk_widget_error_bell (GTK_WIDGET (editable));
4580 *position += n_inserted;
4584 gtk_entry_real_delete_text (GtkEditable *editable,
4589 * The actual deletion from the buffer. This will end up firing the
4590 * following signal handlers: buffer_deleted_text(), buffer_notify_display_text(),
4591 * buffer_notify_text(), buffer_notify_length()
4594 gtk_entry_buffer_delete_text (get_buffer (GTK_ENTRY (editable)), start_pos, end_pos - start_pos);
4597 /* GtkEntryBuffer signal handlers
4600 buffer_inserted_text (GtkEntryBuffer *buffer,
4606 guint password_hint_timeout;
4608 if (entry->current_pos > position)
4609 entry->current_pos += n_chars;
4611 if (entry->selection_bound > position)
4612 entry->selection_bound += n_chars;
4614 /* Calculate the password hint if it needs to be displayed. */
4615 if (n_chars == 1 && !entry->visible)
4617 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
4618 "gtk-entry-password-hint-timeout", &password_hint_timeout,
4621 if (password_hint_timeout > 0)
4623 GtkEntryPasswordHint *password_hint = g_object_get_qdata (G_OBJECT (entry),
4624 quark_password_hint);
4627 password_hint = g_slice_new0 (GtkEntryPasswordHint);
4628 g_object_set_qdata_full (G_OBJECT (entry), quark_password_hint, password_hint,
4629 (GDestroyNotify)gtk_entry_password_hint_free);
4632 password_hint->position = position;
4633 if (password_hint->source_id)
4634 g_source_remove (password_hint->source_id);
4635 password_hint->source_id = gdk_threads_add_timeout (password_hint_timeout,
4636 (GSourceFunc)gtk_entry_remove_password_hint, entry);
4642 buffer_deleted_text (GtkEntryBuffer *buffer,
4647 guint end_pos = position + n_chars;
4648 gint selection_bound;
4651 current_pos = entry->current_pos;
4652 if (current_pos > position)
4653 current_pos -= MIN (current_pos, end_pos) - position;
4655 selection_bound = entry->selection_bound;
4656 if (selection_bound > position)
4657 selection_bound -= MIN (selection_bound, end_pos) - position;
4659 gtk_entry_set_positions (entry, current_pos, selection_bound);
4661 /* We might have deleted the selection */
4662 gtk_entry_update_primary_selection (entry);
4664 /* Disable the password hint if one exists. */
4665 if (!entry->visible)
4667 GtkEntryPasswordHint *password_hint = g_object_get_qdata (G_OBJECT (entry),
4668 quark_password_hint);
4671 if (password_hint->source_id)
4672 g_source_remove (password_hint->source_id);
4673 password_hint->source_id = 0;
4674 password_hint->position = -1;
4680 buffer_notify_text (GtkEntryBuffer *buffer,
4684 gtk_entry_recompute (entry);
4685 emit_changed (entry);
4686 g_object_notify (G_OBJECT (entry), "text");
4690 buffer_notify_length (GtkEntryBuffer *buffer,
4694 g_object_notify (G_OBJECT (entry), "text-length");
4698 buffer_notify_max_length (GtkEntryBuffer *buffer,
4702 g_object_notify (G_OBJECT (entry), "max-length");
4706 buffer_connect_signals (GtkEntry *entry)
4708 g_signal_connect (get_buffer (entry), "inserted-text", G_CALLBACK (buffer_inserted_text), entry);
4709 g_signal_connect (get_buffer (entry), "deleted-text", G_CALLBACK (buffer_deleted_text), entry);
4710 g_signal_connect (get_buffer (entry), "notify::text", G_CALLBACK (buffer_notify_text), entry);
4711 g_signal_connect (get_buffer (entry), "notify::length", G_CALLBACK (buffer_notify_length), entry);
4712 g_signal_connect (get_buffer (entry), "notify::max-length", G_CALLBACK (buffer_notify_max_length), entry);
4716 buffer_disconnect_signals (GtkEntry *entry)
4718 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_inserted_text, entry);
4719 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_deleted_text, entry);
4720 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_text, entry);
4721 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_length, entry);
4722 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_max_length, entry);
4725 /* Compute the X position for an offset that corresponds to the "more important
4726 * cursor position for that offset. We use this when trying to guess to which
4727 * end of the selection we should go to when the user hits the left or
4731 get_better_cursor_x (GtkEntry *entry,
4734 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
4735 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
4736 gboolean split_cursor;
4738 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
4739 const gchar *text = pango_layout_get_text (layout);
4740 gint index = g_utf8_offset_to_pointer (text, offset) - text;
4742 PangoRectangle strong_pos, weak_pos;
4744 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
4745 "gtk-split-cursor", &split_cursor,
4748 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
4751 return strong_pos.x / PANGO_SCALE;
4753 return (keymap_direction == entry->resolved_dir) ? strong_pos.x / PANGO_SCALE : weak_pos.x / PANGO_SCALE;
4757 gtk_entry_move_cursor (GtkEntry *entry,
4758 GtkMovementStep step,
4760 gboolean extend_selection)
4762 gint new_pos = entry->current_pos;
4763 GtkEntryPrivate *priv;
4765 _gtk_entry_reset_im_context (entry);
4767 if (entry->current_pos != entry->selection_bound && !extend_selection)
4769 /* If we have a current selection and aren't extending it, move to the
4770 * start/or end of the selection as appropriate
4774 case GTK_MOVEMENT_VISUAL_POSITIONS:
4776 gint current_x = get_better_cursor_x (entry, entry->current_pos);
4777 gint bound_x = get_better_cursor_x (entry, entry->selection_bound);
4780 new_pos = current_x < bound_x ? entry->current_pos : entry->selection_bound;
4782 new_pos = current_x > bound_x ? entry->current_pos : entry->selection_bound;
4785 case GTK_MOVEMENT_LOGICAL_POSITIONS:
4786 case GTK_MOVEMENT_WORDS:
4788 new_pos = MIN (entry->current_pos, entry->selection_bound);
4790 new_pos = MAX (entry->current_pos, entry->selection_bound);
4792 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
4793 case GTK_MOVEMENT_PARAGRAPH_ENDS:
4794 case GTK_MOVEMENT_BUFFER_ENDS:
4795 priv = GTK_ENTRY_GET_PRIVATE (entry);
4796 new_pos = count < 0 ? 0 : gtk_entry_buffer_get_length (get_buffer (entry));
4798 case GTK_MOVEMENT_DISPLAY_LINES:
4799 case GTK_MOVEMENT_PARAGRAPHS:
4800 case GTK_MOVEMENT_PAGES:
4801 case GTK_MOVEMENT_HORIZONTAL_PAGES:
4809 case GTK_MOVEMENT_LOGICAL_POSITIONS:
4810 new_pos = gtk_entry_move_logically (entry, new_pos, count);
4812 case GTK_MOVEMENT_VISUAL_POSITIONS:
4813 new_pos = gtk_entry_move_visually (entry, new_pos, count);
4814 if (entry->current_pos == new_pos)
4816 if (!extend_selection)
4818 if (!gtk_widget_keynav_failed (GTK_WIDGET (entry),
4820 GTK_DIR_RIGHT : GTK_DIR_LEFT))
4822 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (entry));
4825 gtk_widget_child_focus (toplevel,
4827 GTK_DIR_RIGHT : GTK_DIR_LEFT);
4832 gtk_widget_error_bell (GTK_WIDGET (entry));
4836 case GTK_MOVEMENT_WORDS:
4839 new_pos = gtk_entry_move_forward_word (entry, new_pos, FALSE);
4844 new_pos = gtk_entry_move_backward_word (entry, new_pos, FALSE);
4847 if (entry->current_pos == new_pos)
4848 gtk_widget_error_bell (GTK_WIDGET (entry));
4850 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
4851 case GTK_MOVEMENT_PARAGRAPH_ENDS:
4852 case GTK_MOVEMENT_BUFFER_ENDS:
4853 priv = GTK_ENTRY_GET_PRIVATE (entry);
4854 new_pos = count < 0 ? 0 : gtk_entry_buffer_get_length (get_buffer (entry));
4855 if (entry->current_pos == new_pos)
4856 gtk_widget_error_bell (GTK_WIDGET (entry));
4858 case GTK_MOVEMENT_DISPLAY_LINES:
4859 case GTK_MOVEMENT_PARAGRAPHS:
4860 case GTK_MOVEMENT_PAGES:
4861 case GTK_MOVEMENT_HORIZONTAL_PAGES:
4866 if (extend_selection)
4867 gtk_editable_select_region (GTK_EDITABLE (entry), entry->selection_bound, new_pos);
4869 gtk_editable_set_position (GTK_EDITABLE (entry), new_pos);
4871 gtk_entry_pend_cursor_blink (entry);
4875 gtk_entry_insert_at_cursor (GtkEntry *entry,
4878 GtkEditable *editable = GTK_EDITABLE (entry);
4879 gint pos = entry->current_pos;
4881 if (entry->editable)
4883 _gtk_entry_reset_im_context (entry);
4885 gtk_editable_insert_text (editable, str, -1, &pos);
4886 gtk_editable_set_position (editable, pos);
4891 gtk_entry_delete_from_cursor (GtkEntry *entry,
4895 GtkEditable *editable = GTK_EDITABLE (entry);
4896 gint start_pos = entry->current_pos;
4897 gint end_pos = entry->current_pos;
4898 gint old_n_bytes = gtk_entry_buffer_get_bytes (get_buffer (entry));
4900 _gtk_entry_reset_im_context (entry);
4902 if (!entry->editable)
4904 gtk_widget_error_bell (GTK_WIDGET (entry));
4908 if (entry->selection_bound != entry->current_pos)
4910 gtk_editable_delete_selection (editable);
4916 case GTK_DELETE_CHARS:
4917 end_pos = gtk_entry_move_logically (entry, entry->current_pos, count);
4918 gtk_editable_delete_text (editable, MIN (start_pos, end_pos), MAX (start_pos, end_pos));
4920 case GTK_DELETE_WORDS:
4923 /* Move to end of current word, or if not on a word, end of previous word */
4924 end_pos = gtk_entry_move_backward_word (entry, end_pos, FALSE);
4925 end_pos = gtk_entry_move_forward_word (entry, end_pos, FALSE);
4929 /* Move to beginning of current word, or if not on a word, begining of next word */
4930 start_pos = gtk_entry_move_forward_word (entry, start_pos, FALSE);
4931 start_pos = gtk_entry_move_backward_word (entry, start_pos, FALSE);
4935 case GTK_DELETE_WORD_ENDS:
4938 start_pos = gtk_entry_move_backward_word (entry, start_pos, FALSE);
4943 end_pos = gtk_entry_move_forward_word (entry, end_pos, FALSE);
4946 gtk_editable_delete_text (editable, start_pos, end_pos);
4948 case GTK_DELETE_DISPLAY_LINE_ENDS:
4949 case GTK_DELETE_PARAGRAPH_ENDS:
4951 gtk_editable_delete_text (editable, 0, entry->current_pos);
4953 gtk_editable_delete_text (editable, entry->current_pos, -1);
4955 case GTK_DELETE_DISPLAY_LINES:
4956 case GTK_DELETE_PARAGRAPHS:
4957 gtk_editable_delete_text (editable, 0, -1);
4959 case GTK_DELETE_WHITESPACE:
4960 gtk_entry_delete_whitespace (entry);
4964 if (gtk_entry_buffer_get_bytes (get_buffer (entry)) == old_n_bytes)
4965 gtk_widget_error_bell (GTK_WIDGET (entry));
4967 gtk_entry_pend_cursor_blink (entry);
4971 gtk_entry_backspace (GtkEntry *entry)
4973 GtkEditable *editable = GTK_EDITABLE (entry);
4976 _gtk_entry_reset_im_context (entry);
4978 if (!entry->editable)
4980 gtk_widget_error_bell (GTK_WIDGET (entry));
4984 if (entry->selection_bound != entry->current_pos)
4986 gtk_editable_delete_selection (editable);
4990 prev_pos = gtk_entry_move_logically (entry, entry->current_pos, -1);
4992 if (prev_pos < entry->current_pos)
4994 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
4995 PangoLogAttr *log_attrs;
4998 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
5000 /* Deleting parts of characters */
5001 if (log_attrs[entry->current_pos].backspace_deletes_character)
5003 gchar *cluster_text;
5004 gchar *normalized_text;
5007 cluster_text = gtk_entry_get_display_text (entry, prev_pos,
5008 entry->current_pos);
5009 normalized_text = g_utf8_normalize (cluster_text,
5010 strlen (cluster_text),
5012 len = g_utf8_strlen (normalized_text, -1);
5014 gtk_editable_delete_text (editable, prev_pos, entry->current_pos);
5017 gint pos = entry->current_pos;
5019 gtk_editable_insert_text (editable, normalized_text,
5020 g_utf8_offset_to_pointer (normalized_text, len - 1) - normalized_text,
5022 gtk_editable_set_position (editable, pos);
5025 g_free (normalized_text);
5026 g_free (cluster_text);
5030 gtk_editable_delete_text (editable, prev_pos, entry->current_pos);
5037 gtk_widget_error_bell (GTK_WIDGET (entry));
5040 gtk_entry_pend_cursor_blink (entry);
5044 gtk_entry_copy_clipboard (GtkEntry *entry)
5046 GtkEditable *editable = GTK_EDITABLE (entry);
5050 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5052 if (!entry->visible)
5054 gtk_widget_error_bell (GTK_WIDGET (entry));
5058 str = gtk_entry_get_display_text (entry, start, end);
5059 gtk_clipboard_set_text (gtk_widget_get_clipboard (GTK_WIDGET (entry),
5060 GDK_SELECTION_CLIPBOARD),
5067 gtk_entry_cut_clipboard (GtkEntry *entry)
5069 GtkEditable *editable = GTK_EDITABLE (entry);
5072 if (!entry->visible)
5074 gtk_widget_error_bell (GTK_WIDGET (entry));
5078 gtk_entry_copy_clipboard (entry);
5080 if (entry->editable)
5082 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5083 gtk_editable_delete_text (editable, start, end);
5087 gtk_widget_error_bell (GTK_WIDGET (entry));
5092 gtk_entry_paste_clipboard (GtkEntry *entry)
5094 if (entry->editable)
5095 gtk_entry_paste (entry, GDK_NONE);
5097 gtk_widget_error_bell (GTK_WIDGET (entry));
5101 gtk_entry_delete_cb (GtkEntry *entry)
5103 GtkEditable *editable = GTK_EDITABLE (entry);
5106 if (entry->editable)
5108 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5109 gtk_editable_delete_text (editable, start, end);
5114 gtk_entry_toggle_overwrite (GtkEntry *entry)
5116 entry->overwrite_mode = !entry->overwrite_mode;
5117 gtk_entry_pend_cursor_blink (entry);
5118 gtk_widget_queue_draw (GTK_WIDGET (entry));
5122 gtk_entry_select_all (GtkEntry *entry)
5124 gtk_entry_select_line (entry);
5128 gtk_entry_real_activate (GtkEntry *entry)
5131 GtkWidget *default_widget, *focus_widget;
5132 GtkWidget *toplevel;
5135 widget = GTK_WIDGET (entry);
5137 if (entry->activates_default)
5139 toplevel = gtk_widget_get_toplevel (widget);
5140 if (GTK_IS_WINDOW (toplevel))
5142 window = GTK_WINDOW (toplevel);
5146 default_widget = gtk_window_get_default_widget (window);
5147 focus_widget = gtk_window_get_focus (window);
5148 if (widget != default_widget &&
5149 !(widget == focus_widget && (!default_widget || !gtk_widget_get_sensitive (default_widget))))
5150 gtk_window_activate_default (window);
5157 keymap_direction_changed (GdkKeymap *keymap,
5160 gtk_entry_recompute (entry);
5163 /* IM Context Callbacks
5167 gtk_entry_commit_cb (GtkIMContext *context,
5171 if (entry->editable)
5172 gtk_entry_enter_text (entry, str);
5176 gtk_entry_preedit_changed_cb (GtkIMContext *context,
5179 if (entry->editable)
5181 gchar *preedit_string;
5184 gtk_im_context_get_preedit_string (entry->im_context,
5185 &preedit_string, NULL,
5187 g_signal_emit (entry, signals[PREEDIT_CHANGED], 0, preedit_string);
5188 entry->preedit_length = strlen (preedit_string);
5189 cursor_pos = CLAMP (cursor_pos, 0, g_utf8_strlen (preedit_string, -1));
5190 entry->preedit_cursor = cursor_pos;
5191 g_free (preedit_string);
5193 gtk_entry_recompute (entry);
5198 gtk_entry_retrieve_surrounding_cb (GtkIMContext *context,
5203 /* XXXX ??? does this even make sense when text is not visible? Should we return FALSE? */
5204 text = gtk_entry_get_display_text (entry, 0, -1);
5205 gtk_im_context_set_surrounding (context, text, strlen (text), /* Length in bytes */
5206 g_utf8_offset_to_pointer (text, entry->current_pos) - text);
5213 gtk_entry_delete_surrounding_cb (GtkIMContext *slave,
5218 if (entry->editable)
5219 gtk_editable_delete_text (GTK_EDITABLE (entry),
5220 entry->current_pos + offset,
5221 entry->current_pos + offset + n_chars);
5226 /* Internal functions
5229 /* Used for im_commit_cb and inserting Unicode chars */
5231 gtk_entry_enter_text (GtkEntry *entry,
5234 GtkEditable *editable = GTK_EDITABLE (entry);
5236 gboolean old_need_im_reset;
5238 old_need_im_reset = entry->need_im_reset;
5239 entry->need_im_reset = FALSE;
5241 if (gtk_editable_get_selection_bounds (editable, NULL, NULL))
5242 gtk_editable_delete_selection (editable);
5245 if (entry->overwrite_mode)
5246 gtk_entry_delete_from_cursor (entry, GTK_DELETE_CHARS, 1);
5249 tmp_pos = entry->current_pos;
5250 gtk_editable_insert_text (editable, str, strlen (str), &tmp_pos);
5251 gtk_editable_set_position (editable, tmp_pos);
5253 entry->need_im_reset = old_need_im_reset;
5256 /* All changes to entry->current_pos and entry->selection_bound
5257 * should go through this function.
5260 gtk_entry_set_positions (GtkEntry *entry,
5262 gint selection_bound)
5264 gboolean changed = FALSE;
5266 g_object_freeze_notify (G_OBJECT (entry));
5268 if (current_pos != -1 &&
5269 entry->current_pos != current_pos)
5271 entry->current_pos = current_pos;
5274 g_object_notify (G_OBJECT (entry), "cursor-position");
5277 if (selection_bound != -1 &&
5278 entry->selection_bound != selection_bound)
5280 entry->selection_bound = selection_bound;
5283 g_object_notify (G_OBJECT (entry), "selection-bound");
5286 g_object_thaw_notify (G_OBJECT (entry));
5290 gtk_entry_move_adjustments (entry);
5291 gtk_entry_recompute (entry);
5296 gtk_entry_reset_layout (GtkEntry *entry)
5298 if (entry->cached_layout)
5300 g_object_unref (entry->cached_layout);
5301 entry->cached_layout = NULL;
5306 update_im_cursor_location (GtkEntry *entry)
5310 gint strong_xoffset;
5311 gint area_width, area_height;
5313 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
5314 gtk_entry_get_text_area_size (entry, NULL, NULL, &area_width, &area_height);
5316 strong_xoffset = strong_x - entry->scroll_offset;
5317 if (strong_xoffset < 0)
5321 else if (strong_xoffset > area_width)
5323 strong_xoffset = area_width;
5325 area.x = strong_xoffset;
5328 area.height = area_height;
5330 gtk_im_context_set_cursor_location (entry->im_context, &area);
5334 recompute_idle_func (gpointer data)
5338 entry = GTK_ENTRY (data);
5340 entry->recompute_idle = 0;
5342 if (gtk_widget_has_screen (GTK_WIDGET (entry)))
5344 gtk_entry_adjust_scroll (entry);
5345 gtk_entry_queue_draw (entry);
5347 update_im_cursor_location (entry);
5354 gtk_entry_recompute (GtkEntry *entry)
5356 gtk_entry_reset_layout (entry);
5357 gtk_entry_check_cursor_blink (entry);
5359 if (!entry->recompute_idle)
5361 entry->recompute_idle = gdk_threads_add_idle_full (G_PRIORITY_HIGH_IDLE + 15, /* between resize and redraw */
5362 recompute_idle_func, entry, NULL);
5366 static PangoLayout *
5367 gtk_entry_create_layout (GtkEntry *entry,
5368 gboolean include_preedit)
5370 GtkWidget *widget = GTK_WIDGET (entry);
5371 PangoLayout *layout = gtk_widget_create_pango_layout (widget, NULL);
5372 PangoAttrList *tmp_attrs = pango_attr_list_new ();
5374 gchar *preedit_string = NULL;
5375 gint preedit_length = 0;
5376 PangoAttrList *preedit_attrs = NULL;
5381 pango_layout_set_single_paragraph_mode (layout, TRUE);
5383 display = gtk_entry_get_display_text (entry, 0, -1);
5384 n_bytes = strlen (display);
5386 if (include_preedit)
5388 gtk_im_context_get_preedit_string (entry->im_context,
5389 &preedit_string, &preedit_attrs, NULL);
5390 preedit_length = entry->preedit_length;
5395 GString *tmp_string = g_string_new (display);
5396 gint cursor_index = g_utf8_offset_to_pointer (display, entry->current_pos) - display;
5398 g_string_insert (tmp_string, cursor_index, preedit_string);
5400 pango_layout_set_text (layout, tmp_string->str, tmp_string->len);
5402 pango_attr_list_splice (tmp_attrs, preedit_attrs,
5403 cursor_index, preedit_length);
5405 g_string_free (tmp_string, TRUE);
5409 PangoDirection pango_dir;
5411 if (gtk_entry_get_display_mode (entry) == DISPLAY_NORMAL)
5412 pango_dir = pango_find_base_dir (display, n_bytes);
5414 pango_dir = PANGO_DIRECTION_NEUTRAL;
5416 if (pango_dir == PANGO_DIRECTION_NEUTRAL)
5418 if (gtk_widget_has_focus (widget))
5420 GdkDisplay *display = gtk_widget_get_display (widget);
5421 GdkKeymap *keymap = gdk_keymap_get_for_display (display);
5422 if (gdk_keymap_get_direction (keymap) == PANGO_DIRECTION_RTL)
5423 pango_dir = PANGO_DIRECTION_RTL;
5425 pango_dir = PANGO_DIRECTION_LTR;
5429 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
5430 pango_dir = PANGO_DIRECTION_RTL;
5432 pango_dir = PANGO_DIRECTION_LTR;
5436 pango_context_set_base_dir (gtk_widget_get_pango_context (widget),
5439 entry->resolved_dir = pango_dir;
5441 pango_layout_set_text (layout, display, n_bytes);
5444 pango_layout_set_attributes (layout, tmp_attrs);
5446 g_free (preedit_string);
5450 pango_attr_list_unref (preedit_attrs);
5452 pango_attr_list_unref (tmp_attrs);
5457 static PangoLayout *
5458 gtk_entry_ensure_layout (GtkEntry *entry,
5459 gboolean include_preedit)
5461 if (entry->preedit_length > 0 &&
5462 !include_preedit != !entry->cache_includes_preedit)
5463 gtk_entry_reset_layout (entry);
5465 if (!entry->cached_layout)
5467 entry->cached_layout = gtk_entry_create_layout (entry, include_preedit);
5468 entry->cache_includes_preedit = include_preedit;
5471 return entry->cached_layout;
5475 get_layout_position (GtkEntry *entry,
5479 PangoLayout *layout;
5480 PangoRectangle logical_rect;
5481 gint area_width, area_height;
5482 GtkBorder inner_border;
5484 PangoLayoutLine *line;
5486 layout = gtk_entry_ensure_layout (entry, TRUE);
5488 gtk_entry_get_text_area_size (entry, NULL, NULL, &area_width, &area_height);
5489 _gtk_entry_effective_inner_border (entry, &inner_border);
5491 area_height = PANGO_SCALE * (area_height - inner_border.top - inner_border.bottom);
5493 line = pango_layout_get_lines_readonly (layout)->data;
5494 pango_layout_line_get_extents (line, NULL, &logical_rect);
5496 /* Align primarily for locale's ascent/descent */
5497 y_pos = ((area_height - entry->ascent - entry->descent) / 2 +
5498 entry->ascent + logical_rect.y);
5500 /* Now see if we need to adjust to fit in actual drawn string */
5501 if (logical_rect.height > area_height)
5502 y_pos = (area_height - logical_rect.height) / 2;
5505 else if (y_pos + logical_rect.height > area_height)
5506 y_pos = area_height - logical_rect.height;
5508 y_pos = inner_border.top + y_pos / PANGO_SCALE;
5511 *x = inner_border.left - entry->scroll_offset;
5518 draw_text_with_color (GtkEntry *entry, cairo_t *cr, GdkColor *default_color)
5520 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
5523 gint start_pos, end_pos;
5525 widget = GTK_WIDGET (entry);
5529 get_layout_position (entry, &x, &y);
5531 cairo_move_to (cr, x, y);
5532 gdk_cairo_set_source_color (cr, default_color);
5533 pango_cairo_show_layout (cr, layout);
5535 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start_pos, &end_pos))
5539 PangoRectangle logical_rect;
5540 GdkColor *selection_color, *text_color;
5541 GtkBorder inner_border;
5544 pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
5545 gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
5547 style = gtk_widget_get_style (widget);
5549 if (gtk_widget_has_focus (widget))
5551 selection_color = &style->base [GTK_STATE_SELECTED];
5552 text_color = &style->text [GTK_STATE_SELECTED];
5556 selection_color = &style->base [GTK_STATE_ACTIVE];
5557 text_color = &style->text [GTK_STATE_ACTIVE];
5560 _gtk_entry_effective_inner_border (entry, &inner_border);
5562 for (i = 0; i < n_ranges; ++i)
5563 cairo_rectangle (cr,
5564 inner_border.left - entry->scroll_offset + ranges[2 * i],
5567 logical_rect.height);
5571 gdk_cairo_set_source_color (cr, selection_color);
5574 cairo_move_to (cr, x, y);
5575 gdk_cairo_set_source_color (cr, text_color);
5576 pango_cairo_show_layout (cr, layout);
5584 gtk_entry_draw_text (GtkEntry *entry,
5587 GtkWidget *widget = GTK_WIDGET (entry);
5590 GdkColor text_color, bar_text_color;
5593 gint progress_x, progress_y, progress_width, progress_height;
5594 gint clip_width, clip_height;
5596 /* Nothing to display at all */
5597 if (gtk_entry_get_display_mode (entry) == DISPLAY_BLANK)
5600 state = GTK_STATE_SELECTED;
5601 if (!gtk_widget_get_sensitive (widget))
5602 state = GTK_STATE_INSENSITIVE;
5603 style = gtk_widget_get_style (widget);
5604 text_color = style->text[gtk_widget_get_state (widget)];
5605 bar_text_color = style->fg[state];
5607 get_progress_area (widget,
5608 &progress_x, &progress_y,
5609 &progress_width, &progress_height);
5611 clip_width = gdk_window_get_width (entry->text_area);
5612 clip_height = gdk_window_get_height (entry->text_area);
5613 cairo_rectangle (cr, 0, 0, clip_width, clip_height);
5616 /* If the color is the same, or the progress area has a zero
5617 * size, then we only need to draw once. */
5618 if ((text_color.pixel == bar_text_color.pixel) ||
5619 ((progress_width == 0) || (progress_height == 0)))
5621 draw_text_with_color (entry, cr, &text_color);
5625 width = gdk_window_get_width (entry->text_area);
5626 height = gdk_window_get_height (entry->text_area);
5630 cairo_rectangle (cr, 0, 0, width, height);
5634 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
5635 cairo_rectangle (cr, 0, 0, width, height);
5637 gdk_window_get_position (entry->text_area, &pos_x, &pos_y);
5638 progress_x -= pos_x;
5639 progress_y -= pos_y;
5641 cairo_rectangle (cr, progress_x, progress_y,
5642 progress_width, progress_height);
5644 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_WINDING);
5646 draw_text_with_color (entry, cr, &text_color);
5649 cairo_rectangle (cr, progress_x, progress_y,
5650 progress_width, progress_height);
5653 draw_text_with_color (entry, cr, &bar_text_color);
5660 draw_insertion_cursor (GtkEntry *entry,
5662 GdkRectangle *cursor_location,
5663 gboolean is_primary,
5664 PangoDirection direction,
5665 gboolean draw_arrow)
5667 GtkWidget *widget = GTK_WIDGET (entry);
5668 GtkTextDirection text_dir;
5670 if (direction == PANGO_DIRECTION_LTR)
5671 text_dir = GTK_TEXT_DIR_LTR;
5673 text_dir = GTK_TEXT_DIR_RTL;
5675 gtk_draw_insertion_cursor (widget, cr,
5677 is_primary, text_dir, draw_arrow);
5681 gtk_entry_draw_cursor (GtkEntry *entry,
5685 GtkWidget *widget = GTK_WIDGET (entry);
5686 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
5687 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
5688 GdkRectangle cursor_location;
5689 gboolean split_cursor;
5690 PangoRectangle cursor_rect;
5691 GtkBorder inner_border;
5693 gint text_area_height;
5696 gboolean block_at_line_end;
5697 PangoLayout *layout;
5700 _gtk_entry_effective_inner_border (entry, &inner_border);
5702 xoffset = inner_border.left - entry->scroll_offset;
5704 text_area_height = gdk_window_get_height (entry->text_area);
5706 layout = gtk_entry_ensure_layout (entry, TRUE);
5707 text = pango_layout_get_text (layout);
5708 cursor_index = g_utf8_offset_to_pointer (text, entry->current_pos + entry->preedit_cursor) - text;
5709 if (!entry->overwrite_mode)
5712 block = _gtk_text_util_get_block_cursor_location (layout,
5713 cursor_index, &cursor_rect, &block_at_line_end);
5717 gint strong_x, weak_x;
5718 PangoDirection dir1 = PANGO_DIRECTION_NEUTRAL;
5719 PangoDirection dir2 = PANGO_DIRECTION_NEUTRAL;
5723 gtk_entry_get_cursor_locations (entry, type, &strong_x, &weak_x);
5725 g_object_get (gtk_widget_get_settings (widget),
5726 "gtk-split-cursor", &split_cursor,
5729 dir1 = entry->resolved_dir;
5735 if (weak_x != strong_x)
5737 dir2 = (entry->resolved_dir == PANGO_DIRECTION_LTR) ? PANGO_DIRECTION_RTL : PANGO_DIRECTION_LTR;
5743 if (keymap_direction == entry->resolved_dir)
5749 cursor_location.x = xoffset + x1;
5750 cursor_location.y = inner_border.top;
5751 cursor_location.width = 0;
5752 cursor_location.height = text_area_height - inner_border.top - inner_border.bottom;
5754 draw_insertion_cursor (entry, cr,
5755 &cursor_location, TRUE, dir1,
5756 dir2 != PANGO_DIRECTION_NEUTRAL);
5758 if (dir2 != PANGO_DIRECTION_NEUTRAL)
5760 cursor_location.x = xoffset + x2;
5761 draw_insertion_cursor (entry, cr,
5762 &cursor_location, FALSE, dir2,
5766 else /* overwrite_mode */
5768 GdkColor cursor_color;
5774 get_layout_position (entry, &x, &y);
5776 rect.x = PANGO_PIXELS (cursor_rect.x) + x;
5777 rect.y = PANGO_PIXELS (cursor_rect.y) + y;
5778 rect.width = PANGO_PIXELS (cursor_rect.width);
5779 rect.height = PANGO_PIXELS (cursor_rect.height);
5781 _gtk_widget_get_cursor_color (widget, &cursor_color);
5782 gdk_cairo_set_source_color (cr, &cursor_color);
5783 gdk_cairo_rectangle (cr, &rect);
5786 if (!block_at_line_end)
5788 gdk_cairo_rectangle (cr, &rect);
5790 cairo_move_to (cr, x, y);
5791 gdk_cairo_set_source_color (cr, >k_widget_get_style (widget)->base[gtk_widget_get_state (widget)]);
5792 pango_cairo_show_layout (cr, layout);
5800 gtk_entry_queue_draw (GtkEntry *entry)
5802 if (gtk_widget_is_drawable (GTK_WIDGET (entry)))
5803 gdk_window_invalidate_rect (gtk_widget_get_window (GTK_WIDGET (entry)),
5808 _gtk_entry_reset_im_context (GtkEntry *entry)
5810 if (entry->need_im_reset)
5812 entry->need_im_reset = FALSE;
5813 gtk_im_context_reset (entry->im_context);
5818 * gtk_entry_reset_im_context:
5819 * @entry: a #GtkEntry
5821 * Reset the input method context of the entry if needed.
5823 * This can be necessary in the case where modifying the buffer
5824 * would confuse on-going input method behavior.
5829 gtk_entry_reset_im_context (GtkEntry *entry)
5831 g_return_if_fail (GTK_IS_ENTRY (entry));
5833 _gtk_entry_reset_im_context (entry);
5837 * gtk_entry_im_context_filter_keypress:
5838 * @entry: a #GtkEntry
5839 * @event: the key event
5841 * Allow the #GtkEntry input method to internally handle key press
5842 * and release events. If this function returns %TRUE, then no further
5843 * processing should be done for this key event. See
5844 * gtk_im_context_filter_keypress().
5846 * Note that you are expected to call this function from your handler
5847 * when overriding key event handling. This is needed in the case when
5848 * you need to insert your own key handling between the input method
5849 * and the default key event handling of the #GtkEntry.
5850 * See gtk_text_view_reset_im_context() for an example of use.
5852 * Return value: %TRUE if the input method handled the key event.
5857 gtk_entry_im_context_filter_keypress (GtkEntry *entry,
5860 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
5862 return gtk_im_context_filter_keypress (entry->im_context, event);
5867 gtk_entry_find_position (GtkEntry *entry,
5870 PangoLayout *layout;
5871 PangoLayoutLine *line;
5878 layout = gtk_entry_ensure_layout (entry, TRUE);
5879 text = pango_layout_get_text (layout);
5880 cursor_index = g_utf8_offset_to_pointer (text, entry->current_pos) - text;
5882 line = pango_layout_get_lines_readonly (layout)->data;
5883 pango_layout_line_x_to_index (line, x * PANGO_SCALE, &index, &trailing);
5885 if (index >= cursor_index && entry->preedit_length)
5887 if (index >= cursor_index + entry->preedit_length)
5888 index -= entry->preedit_length;
5891 index = cursor_index;
5896 pos = g_utf8_pointer_to_offset (text, text + index);
5903 gtk_entry_get_cursor_locations (GtkEntry *entry,
5908 DisplayMode mode = gtk_entry_get_display_mode (entry);
5910 /* Nothing to display at all, so no cursor is relevant */
5911 if (mode == DISPLAY_BLANK)
5921 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
5922 const gchar *text = pango_layout_get_text (layout);
5923 PangoRectangle strong_pos, weak_pos;
5926 if (type == CURSOR_STANDARD)
5928 index = g_utf8_offset_to_pointer (text, entry->current_pos + entry->preedit_cursor) - text;
5930 else /* type == CURSOR_DND */
5932 index = g_utf8_offset_to_pointer (text, entry->dnd_position) - text;
5934 if (entry->dnd_position > entry->current_pos)
5936 if (mode == DISPLAY_NORMAL)
5937 index += entry->preedit_length;
5940 gint preedit_len_chars = g_utf8_strlen (text, -1) - gtk_entry_buffer_get_length (get_buffer (entry));
5941 index += preedit_len_chars * g_unichar_to_utf8 (entry->invisible_char, NULL);
5946 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
5949 *strong_x = strong_pos.x / PANGO_SCALE;
5952 *weak_x = weak_pos.x / PANGO_SCALE;
5957 gtk_entry_adjust_scroll (GtkEntry *entry)
5959 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
5960 gint min_offset, max_offset;
5961 gint text_area_width, text_width;
5962 GtkBorder inner_border;
5963 gint strong_x, weak_x;
5964 gint strong_xoffset, weak_xoffset;
5966 PangoLayout *layout;
5967 PangoLayoutLine *line;
5968 PangoRectangle logical_rect;
5970 if (!gtk_widget_get_realized (GTK_WIDGET (entry)))
5973 _gtk_entry_effective_inner_border (entry, &inner_border);
5975 text_area_width = gdk_window_get_width (entry->text_area);
5976 text_area_width -= inner_border.left + inner_border.right;
5977 if (text_area_width < 0)
5978 text_area_width = 0;
5980 layout = gtk_entry_ensure_layout (entry, TRUE);
5981 line = pango_layout_get_lines_readonly (layout)->data;
5983 pango_layout_line_get_extents (line, NULL, &logical_rect);
5985 /* Display as much text as we can */
5987 if (entry->resolved_dir == PANGO_DIRECTION_LTR)
5988 xalign = priv->xalign;
5990 xalign = 1.0 - priv->xalign;
5992 text_width = PANGO_PIXELS(logical_rect.width);
5994 if (text_width > text_area_width)
5997 max_offset = text_width - text_area_width;
6001 min_offset = (text_width - text_area_width) * xalign;
6002 max_offset = min_offset;
6005 entry->scroll_offset = CLAMP (entry->scroll_offset, min_offset, max_offset);
6007 /* And make sure cursors are on screen. Note that the cursor is
6008 * actually drawn one pixel into the INNER_BORDER space on
6009 * the right, when the scroll is at the utmost right. This
6010 * looks better to to me than confining the cursor inside the
6011 * border entirely, though it means that the cursor gets one
6012 * pixel closer to the edge of the widget on the right than
6013 * on the left. This might need changing if one changed
6014 * INNER_BORDER from 2 to 1, as one would do on a
6015 * small-screen-real-estate display.
6017 * We always make sure that the strong cursor is on screen, and
6018 * put the weak cursor on screen if possible.
6021 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, &weak_x);
6023 strong_xoffset = strong_x - entry->scroll_offset;
6025 if (strong_xoffset < 0)
6027 entry->scroll_offset += strong_xoffset;
6030 else if (strong_xoffset > text_area_width)
6032 entry->scroll_offset += strong_xoffset - text_area_width;
6033 strong_xoffset = text_area_width;
6036 weak_xoffset = weak_x - entry->scroll_offset;
6038 if (weak_xoffset < 0 && strong_xoffset - weak_xoffset <= text_area_width)
6040 entry->scroll_offset += weak_xoffset;
6042 else if (weak_xoffset > text_area_width &&
6043 strong_xoffset - (weak_xoffset - text_area_width) >= 0)
6045 entry->scroll_offset += weak_xoffset - text_area_width;
6048 g_object_notify (G_OBJECT (entry), "scroll-offset");
6052 gtk_entry_move_adjustments (GtkEntry *entry)
6054 GtkAllocation allocation;
6055 GtkAdjustment *adjustment;
6056 PangoContext *context;
6057 PangoFontMetrics *metrics;
6058 gint x, layout_x, border_x, border_y;
6061 adjustment = g_object_get_qdata (G_OBJECT (entry), quark_cursor_hadjustment);
6065 gtk_widget_get_allocation (&(entry->widget), &allocation);
6067 /* Cursor position, layout offset, border width, and widget allocation */
6068 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &x, NULL);
6069 get_layout_position (entry, &layout_x, NULL);
6070 _gtk_entry_get_borders (entry, &border_x, &border_y);
6071 x += allocation.x + layout_x + border_x;
6073 /* Approximate width of a char, so user can see what is ahead/behind */
6074 context = gtk_widget_get_pango_context (GTK_WIDGET (entry));
6075 metrics = pango_context_get_metrics (context,
6076 gtk_widget_get_style (&(entry->widget))->font_desc,
6077 pango_context_get_language (context));
6078 char_width = pango_font_metrics_get_approximate_char_width (metrics) / PANGO_SCALE;
6081 gtk_adjustment_clamp_page (adjustment,
6082 x - (char_width + 1), /* one char + one pixel before */
6083 x + (char_width + 2)); /* one char + cursor + one pixel after */
6087 gtk_entry_move_visually (GtkEntry *entry,
6092 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6095 text = pango_layout_get_text (layout);
6097 index = g_utf8_offset_to_pointer (text, start) - text;
6101 int new_index, new_trailing;
6102 gboolean split_cursor;
6105 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
6106 "gtk-split-cursor", &split_cursor,
6113 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
6114 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
6116 strong = keymap_direction == entry->resolved_dir;
6121 pango_layout_move_cursor_visually (layout, strong, index, 0, 1, &new_index, &new_trailing);
6126 pango_layout_move_cursor_visually (layout, strong, index, 0, -1, &new_index, &new_trailing);
6132 else if (new_index != G_MAXINT)
6135 while (new_trailing--)
6136 index = g_utf8_next_char (text + index) - text;
6139 return g_utf8_pointer_to_offset (text, text + index);
6143 gtk_entry_move_logically (GtkEntry *entry,
6147 gint new_pos = start;
6150 length = gtk_entry_buffer_get_length (get_buffer (entry));
6152 /* Prevent any leak of information */
6153 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6155 new_pos = CLAMP (start + count, 0, length);
6159 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6160 PangoLogAttr *log_attrs;
6163 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6165 while (count > 0 && new_pos < length)
6169 while (new_pos < length && !log_attrs[new_pos].is_cursor_position);
6173 while (count < 0 && new_pos > 0)
6177 while (new_pos > 0 && !log_attrs[new_pos].is_cursor_position);
6189 gtk_entry_move_forward_word (GtkEntry *entry,
6191 gboolean allow_whitespace)
6193 gint new_pos = start;
6196 length = gtk_entry_buffer_get_length (get_buffer (entry));
6198 /* Prevent any leak of information */
6199 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6203 else if (new_pos < length)
6205 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6206 PangoLogAttr *log_attrs;
6209 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6211 /* Find the next word boundary */
6213 while (new_pos < n_attrs - 1 && !(log_attrs[new_pos].is_word_end ||
6214 (log_attrs[new_pos].is_word_start && allow_whitespace)))
6225 gtk_entry_move_backward_word (GtkEntry *entry,
6227 gboolean allow_whitespace)
6229 gint new_pos = start;
6231 /* Prevent any leak of information */
6232 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6238 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6239 PangoLogAttr *log_attrs;
6242 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6244 new_pos = start - 1;
6246 /* Find the previous word boundary */
6247 while (new_pos > 0 && !(log_attrs[new_pos].is_word_start ||
6248 (log_attrs[new_pos].is_word_end && allow_whitespace)))
6258 gtk_entry_delete_whitespace (GtkEntry *entry)
6260 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6261 PangoLogAttr *log_attrs;
6265 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6267 start = end = entry->current_pos;
6269 while (start > 0 && log_attrs[start-1].is_white)
6272 while (end < n_attrs && log_attrs[end].is_white)
6278 gtk_editable_delete_text (GTK_EDITABLE (entry), start, end);
6283 gtk_entry_select_word (GtkEntry *entry)
6285 gint start_pos = gtk_entry_move_backward_word (entry, entry->current_pos, TRUE);
6286 gint end_pos = gtk_entry_move_forward_word (entry, entry->current_pos, TRUE);
6288 gtk_editable_select_region (GTK_EDITABLE (entry), start_pos, end_pos);
6292 gtk_entry_select_line (GtkEntry *entry)
6294 gtk_editable_select_region (GTK_EDITABLE (entry), 0, -1);
6298 truncate_multiline (const gchar *text)
6303 text[length] && text[length] != '\n' && text[length] != '\r';
6310 paste_received (GtkClipboard *clipboard,
6314 GtkEntry *entry = GTK_ENTRY (data);
6315 GtkEditable *editable = GTK_EDITABLE (entry);
6316 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
6318 if (entry->button == 2)
6320 gint pos, start, end;
6321 pos = priv->insert_pos;
6322 gtk_editable_get_selection_bounds (editable, &start, &end);
6323 if (!((start <= pos && pos <= end) || (end <= pos && pos <= start)))
6324 gtk_editable_select_region (editable, pos, pos);
6329 gint pos, start, end;
6331 gboolean popup_completion;
6332 GtkEntryCompletion *completion;
6334 completion = gtk_entry_get_completion (entry);
6336 if (entry->truncate_multiline)
6337 length = truncate_multiline (text);
6339 /* only complete if the selection is at the end */
6340 popup_completion = (gtk_entry_buffer_get_length (get_buffer (entry)) ==
6341 MAX (entry->current_pos, entry->selection_bound));
6345 if (gtk_widget_get_mapped (completion->priv->popup_window))
6346 _gtk_entry_completion_popdown (completion);
6348 if (!popup_completion && completion->priv->changed_id > 0)
6349 g_signal_handler_block (entry, completion->priv->changed_id);
6352 begin_change (entry);
6353 g_object_freeze_notify (G_OBJECT (entry));
6354 if (gtk_editable_get_selection_bounds (editable, &start, &end))
6355 gtk_editable_delete_text (editable, start, end);
6357 pos = entry->current_pos;
6358 gtk_editable_insert_text (editable, text, length, &pos);
6359 gtk_editable_set_position (editable, pos);
6360 g_object_thaw_notify (G_OBJECT (entry));
6364 !popup_completion && completion->priv->changed_id > 0)
6365 g_signal_handler_unblock (entry, completion->priv->changed_id);
6368 g_object_unref (entry);
6372 gtk_entry_paste (GtkEntry *entry,
6375 g_object_ref (entry);
6376 gtk_clipboard_request_text (gtk_widget_get_clipboard (GTK_WIDGET (entry), selection),
6377 paste_received, entry);
6381 primary_get_cb (GtkClipboard *clipboard,
6382 GtkSelectionData *selection_data,
6386 GtkEntry *entry = GTK_ENTRY (data);
6389 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end))
6391 gchar *str = gtk_entry_get_display_text (entry, start, end);
6392 gtk_selection_data_set_text (selection_data, str, -1);
6398 primary_clear_cb (GtkClipboard *clipboard,
6401 GtkEntry *entry = GTK_ENTRY (data);
6403 gtk_editable_select_region (GTK_EDITABLE (entry), entry->current_pos, entry->current_pos);
6407 gtk_entry_update_primary_selection (GtkEntry *entry)
6409 GtkTargetList *list;
6410 GtkTargetEntry *targets;
6411 GtkClipboard *clipboard;
6415 if (!gtk_widget_get_realized (GTK_WIDGET (entry)))
6418 list = gtk_target_list_new (NULL, 0);
6419 gtk_target_list_add_text_targets (list, 0);
6421 targets = gtk_target_table_new_from_list (list, &n_targets);
6423 clipboard = gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_PRIMARY);
6425 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end))
6427 if (!gtk_clipboard_set_with_owner (clipboard, targets, n_targets,
6428 primary_get_cb, primary_clear_cb, G_OBJECT (entry)))
6429 primary_clear_cb (clipboard, entry);
6433 if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (entry))
6434 gtk_clipboard_clear (clipboard);
6437 gtk_target_table_free (targets, n_targets);
6438 gtk_target_list_unref (list);
6442 gtk_entry_clear (GtkEntry *entry,
6443 GtkEntryIconPosition icon_pos)
6445 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
6446 EntryIconInfo *icon_info = priv->icons[icon_pos];
6448 if (!icon_info || icon_info->storage_type == GTK_IMAGE_EMPTY)
6451 g_object_freeze_notify (G_OBJECT (entry));
6453 /* Explicitly check, as the pointer may become invalidated
6454 * during destruction.
6456 if (GDK_IS_WINDOW (icon_info->window))
6457 gdk_window_hide (icon_info->window);
6459 if (icon_info->pixbuf)
6461 g_object_unref (icon_info->pixbuf);
6462 icon_info->pixbuf = NULL;
6465 switch (icon_info->storage_type)
6467 case GTK_IMAGE_PIXBUF:
6468 g_object_notify (G_OBJECT (entry),
6469 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-pixbuf" : "secondary-icon-pixbuf");
6472 case GTK_IMAGE_STOCK:
6473 g_free (icon_info->stock_id);
6474 icon_info->stock_id = NULL;
6475 g_object_notify (G_OBJECT (entry),
6476 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-stock" : "secondary-icon-stock");
6479 case GTK_IMAGE_ICON_NAME:
6480 g_free (icon_info->icon_name);
6481 icon_info->icon_name = NULL;
6482 g_object_notify (G_OBJECT (entry),
6483 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-name" : "secondary-icon-name");
6486 case GTK_IMAGE_GICON:
6487 if (icon_info->gicon)
6489 g_object_unref (icon_info->gicon);
6490 icon_info->gicon = NULL;
6492 g_object_notify (G_OBJECT (entry),
6493 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-gicon" : "secondary-icon-gicon");
6497 g_assert_not_reached ();
6501 icon_info->storage_type = GTK_IMAGE_EMPTY;
6502 g_object_notify (G_OBJECT (entry),
6503 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-storage-type" : "secondary-icon-storage-type");
6505 g_object_thaw_notify (G_OBJECT (entry));
6509 gtk_entry_ensure_pixbuf (GtkEntry *entry,
6510 GtkEntryIconPosition icon_pos)
6512 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
6513 EntryIconInfo *icon_info = priv->icons[icon_pos];
6515 GtkIconTheme *icon_theme;
6516 GtkSettings *settings;
6522 if (!icon_info || icon_info->pixbuf)
6525 widget = GTK_WIDGET (entry);
6527 switch (icon_info->storage_type)
6529 case GTK_IMAGE_EMPTY:
6530 case GTK_IMAGE_PIXBUF:
6532 case GTK_IMAGE_STOCK:
6533 state = gtk_widget_get_state (widget);
6534 gtk_widget_set_state (widget, GTK_STATE_NORMAL);
6535 icon_info->pixbuf = gtk_widget_render_icon (widget,
6536 icon_info->stock_id,
6539 if (!icon_info->pixbuf)
6540 icon_info->pixbuf = gtk_widget_render_icon (widget,
6541 GTK_STOCK_MISSING_IMAGE,
6544 gtk_widget_set_state (widget, state);
6547 case GTK_IMAGE_ICON_NAME:
6548 screen = gtk_widget_get_screen (widget);
6551 icon_theme = gtk_icon_theme_get_for_screen (screen);
6552 settings = gtk_settings_get_for_screen (screen);
6554 gtk_icon_size_lookup_for_settings (settings,
6558 icon_info->pixbuf = gtk_icon_theme_load_icon (icon_theme,
6559 icon_info->icon_name,
6560 MIN (width, height),
6563 if (icon_info->pixbuf == NULL)
6565 state = gtk_widget_get_state (widget);
6566 gtk_widget_set_state (widget, GTK_STATE_NORMAL);
6567 icon_info->pixbuf = gtk_widget_render_icon (widget,
6568 GTK_STOCK_MISSING_IMAGE,
6571 gtk_widget_set_state (widget, state);
6576 case GTK_IMAGE_GICON:
6577 screen = gtk_widget_get_screen (widget);
6580 icon_theme = gtk_icon_theme_get_for_screen (screen);
6581 settings = gtk_settings_get_for_screen (screen);
6583 gtk_icon_size_lookup_for_settings (settings,
6587 info = gtk_icon_theme_lookup_by_gicon (icon_theme,
6589 MIN (width, height),
6590 GTK_ICON_LOOKUP_USE_BUILTIN);
6593 icon_info->pixbuf = gtk_icon_info_load_icon (info, NULL);
6594 gtk_icon_info_free (info);
6597 if (icon_info->pixbuf == NULL)
6599 state = gtk_widget_get_state (widget);
6600 gtk_widget_set_state (widget, GTK_STATE_NORMAL);
6601 icon_info->pixbuf = gtk_widget_render_icon (widget,
6602 GTK_STOCK_MISSING_IMAGE,
6605 gtk_widget_set_state (widget, state);
6611 g_assert_not_reached ();
6615 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
6616 gdk_window_show_unraised (icon_info->window);
6626 * Creates a new entry.
6628 * Return value: a new #GtkEntry.
6631 gtk_entry_new (void)
6633 return g_object_new (GTK_TYPE_ENTRY, NULL);
6637 * gtk_entry_new_with_buffer:
6638 * @buffer: The buffer to use for the new #GtkEntry.
6640 * Creates a new entry with the specified text buffer.
6642 * Return value: a new #GtkEntry
6647 gtk_entry_new_with_buffer (GtkEntryBuffer *buffer)
6649 g_return_val_if_fail (GTK_IS_ENTRY_BUFFER (buffer), NULL);
6650 return g_object_new (GTK_TYPE_ENTRY, "buffer", buffer, NULL);
6653 static GtkEntryBuffer*
6654 get_buffer (GtkEntry *entry)
6656 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
6658 if (priv->buffer == NULL)
6660 GtkEntryBuffer *buffer;
6661 buffer = gtk_entry_buffer_new (NULL, 0);
6662 gtk_entry_set_buffer (entry, buffer);
6663 g_object_unref (buffer);
6666 return priv->buffer;
6670 * gtk_entry_get_buffer:
6671 * @entry: a #GtkEntry
6673 * Get the #GtkEntryBuffer object which holds the text for
6678 * Returns: (transfer none): A #GtkEntryBuffer object.
6681 gtk_entry_get_buffer (GtkEntry *entry)
6683 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
6685 return get_buffer (entry);
6689 * gtk_entry_set_buffer:
6690 * @entry: a #GtkEntry
6691 * @buffer: a #GtkEntryBuffer
6693 * Set the #GtkEntryBuffer object which holds the text for
6699 gtk_entry_set_buffer (GtkEntry *entry,
6700 GtkEntryBuffer *buffer)
6702 GtkEntryPrivate *priv;
6705 g_return_if_fail (GTK_IS_ENTRY (entry));
6706 priv = GTK_ENTRY_GET_PRIVATE (entry);
6710 g_return_if_fail (GTK_IS_ENTRY_BUFFER (buffer));
6711 g_object_ref (buffer);
6716 buffer_disconnect_signals (entry);
6717 g_object_unref (priv->buffer);
6720 priv->buffer = buffer;
6723 buffer_connect_signals (entry);
6725 obj = G_OBJECT (entry);
6726 g_object_freeze_notify (obj);
6727 g_object_notify (obj, "buffer");
6728 g_object_notify (obj, "text");
6729 g_object_notify (obj, "text-length");
6730 g_object_notify (obj, "max-length");
6731 g_object_notify (obj, "visibility");
6732 g_object_notify (obj, "invisible-char");
6733 g_object_notify (obj, "invisible-char-set");
6734 g_object_thaw_notify (obj);
6736 gtk_editable_set_position (GTK_EDITABLE (entry), 0);
6737 gtk_entry_recompute (entry);
6741 * gtk_entry_get_text_area:
6742 * @entry: a #GtkEntry
6743 * @text_area: Return location for the text area.
6745 * Gets the area where the entry's text is drawn. This function is
6746 * useful when drawing something to the entry in a draw callback.
6748 * If the entry is not realized, @text_area is filled with zeros.
6750 * See also gtk_entry_get_icon_area().
6755 gtk_entry_get_text_area (GtkEntry *entry,
6756 GdkRectangle *text_area)
6758 g_return_if_fail (GTK_IS_ENTRY (entry));
6759 g_return_if_fail (text_area != NULL);
6761 if (entry->text_area)
6763 GtkAllocation allocation;
6766 gtk_widget_get_allocation (GTK_WIDGET (entry), &allocation);
6767 gdk_window_get_position (entry->text_area, &x, &y);
6769 text_area->x = x - allocation.x;
6770 text_area->y = y - allocation.y;
6771 text_area->width = gdk_window_get_width (entry->text_area);
6772 text_area->height = gdk_window_get_height (entry->text_area);
6778 text_area->width = 0;
6779 text_area->height = 0;
6784 * gtk_entry_set_text:
6785 * @entry: a #GtkEntry
6786 * @text: the new text
6788 * Sets the text in the widget to the given
6789 * value, replacing the current contents.
6791 * See gtk_entry_buffer_set_text().
6794 gtk_entry_set_text (GtkEntry *entry,
6798 GtkEntryCompletion *completion;
6799 GtkEntryPrivate *priv;
6801 g_return_if_fail (GTK_IS_ENTRY (entry));
6802 g_return_if_fail (text != NULL);
6803 priv = GTK_ENTRY_GET_PRIVATE (entry);
6805 /* Actually setting the text will affect the cursor and selection;
6806 * if the contents don't actually change, this will look odd to the user.
6808 if (strcmp (gtk_entry_buffer_get_text (get_buffer (entry)), text) == 0)
6811 completion = gtk_entry_get_completion (entry);
6812 if (completion && completion->priv->changed_id > 0)
6813 g_signal_handler_block (entry, completion->priv->changed_id);
6815 begin_change (entry);
6816 g_object_freeze_notify (G_OBJECT (entry));
6817 gtk_editable_delete_text (GTK_EDITABLE (entry), 0, -1);
6819 gtk_editable_insert_text (GTK_EDITABLE (entry), text, strlen (text), &tmp_pos);
6820 g_object_thaw_notify (G_OBJECT (entry));
6823 if (completion && completion->priv->changed_id > 0)
6824 g_signal_handler_unblock (entry, completion->priv->changed_id);
6828 * gtk_entry_set_visibility:
6829 * @entry: a #GtkEntry
6830 * @visible: %TRUE if the contents of the entry are displayed
6833 * Sets whether the contents of the entry are visible or not.
6834 * When visibility is set to %FALSE, characters are displayed
6835 * as the invisible char, and will also appear that way when
6836 * the text in the entry widget is copied elsewhere.
6838 * By default, GTK+ picks the best invisible character available
6839 * in the current font, but it can be changed with
6840 * gtk_entry_set_invisible_char().
6843 gtk_entry_set_visibility (GtkEntry *entry,
6846 g_return_if_fail (GTK_IS_ENTRY (entry));
6848 visible = visible != FALSE;
6850 if (entry->visible != visible)
6852 entry->visible = visible;
6854 g_object_notify (G_OBJECT (entry), "visibility");
6855 gtk_entry_recompute (entry);
6860 * gtk_entry_get_visibility:
6861 * @entry: a #GtkEntry
6863 * Retrieves whether the text in @entry is visible. See
6864 * gtk_entry_set_visibility().
6866 * Return value: %TRUE if the text is currently visible
6869 gtk_entry_get_visibility (GtkEntry *entry)
6871 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
6873 return entry->visible;
6877 * gtk_entry_set_invisible_char:
6878 * @entry: a #GtkEntry
6879 * @ch: a Unicode character
6881 * Sets the character to use in place of the actual text when
6882 * gtk_entry_set_visibility() has been called to set text visibility
6883 * to %FALSE. i.e. this is the character used in "password mode" to
6884 * show the user how many characters have been typed. By default, GTK+
6885 * picks the best invisible char available in the current font. If you
6886 * set the invisible char to 0, then the user will get no feedback
6887 * at all; there will be no text on the screen as they type.
6890 gtk_entry_set_invisible_char (GtkEntry *entry,
6893 GtkEntryPrivate *priv;
6895 g_return_if_fail (GTK_IS_ENTRY (entry));
6897 priv = GTK_ENTRY_GET_PRIVATE (entry);
6899 if (!priv->invisible_char_set)
6901 priv->invisible_char_set = TRUE;
6902 g_object_notify (G_OBJECT (entry), "invisible-char-set");
6905 if (ch == entry->invisible_char)
6908 entry->invisible_char = ch;
6909 g_object_notify (G_OBJECT (entry), "invisible-char");
6910 gtk_entry_recompute (entry);
6914 * gtk_entry_get_invisible_char:
6915 * @entry: a #GtkEntry
6917 * Retrieves the character displayed in place of the real characters
6918 * for entries with visibility set to false. See gtk_entry_set_invisible_char().
6920 * Return value: the current invisible char, or 0, if the entry does not
6921 * show invisible text at all.
6924 gtk_entry_get_invisible_char (GtkEntry *entry)
6926 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
6928 return entry->invisible_char;
6932 * gtk_entry_unset_invisible_char:
6933 * @entry: a #GtkEntry
6935 * Unsets the invisible char previously set with
6936 * gtk_entry_set_invisible_char(). So that the
6937 * default invisible char is used again.
6942 gtk_entry_unset_invisible_char (GtkEntry *entry)
6944 GtkEntryPrivate *priv;
6947 g_return_if_fail (GTK_IS_ENTRY (entry));
6949 priv = GTK_ENTRY_GET_PRIVATE (entry);
6951 if (!priv->invisible_char_set)
6954 priv->invisible_char_set = FALSE;
6955 ch = find_invisible_char (GTK_WIDGET (entry));
6957 if (entry->invisible_char != ch)
6959 entry->invisible_char = ch;
6960 g_object_notify (G_OBJECT (entry), "invisible-char");
6963 g_object_notify (G_OBJECT (entry), "invisible-char-set");
6964 gtk_entry_recompute (entry);
6968 * gtk_entry_set_overwrite_mode:
6969 * @entry: a #GtkEntry
6970 * @overwrite: new value
6972 * Sets whether the text is overwritten when typing in the #GtkEntry.
6977 gtk_entry_set_overwrite_mode (GtkEntry *entry,
6980 g_return_if_fail (GTK_IS_ENTRY (entry));
6982 if (entry->overwrite_mode == overwrite)
6985 gtk_entry_toggle_overwrite (entry);
6987 g_object_notify (G_OBJECT (entry), "overwrite-mode");
6991 * gtk_entry_get_overwrite_mode:
6992 * @entry: a #GtkEntry
6994 * Gets the value set by gtk_entry_set_overwrite_mode().
6996 * Return value: whether the text is overwritten when typing.
7001 gtk_entry_get_overwrite_mode (GtkEntry *entry)
7003 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7005 return entry->overwrite_mode;
7009 * gtk_entry_get_text:
7010 * @entry: a #GtkEntry
7012 * Retrieves the contents of the entry widget.
7013 * See also gtk_editable_get_chars().
7015 * This is equivalent to:
7017 * <informalexample><programlisting>
7018 * gtk_entry_buffer_get_text (gtk_entry_get_buffer (entry));
7019 * </programlisting></informalexample>
7021 * Return value: a pointer to the contents of the widget as a
7022 * string. This string points to internally allocated
7023 * storage in the widget and must not be freed, modified or
7026 G_CONST_RETURN gchar*
7027 gtk_entry_get_text (GtkEntry *entry)
7029 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7030 return gtk_entry_buffer_get_text (get_buffer (entry));
7034 * gtk_entry_set_max_length:
7035 * @entry: a #GtkEntry
7036 * @max: the maximum length of the entry, or 0 for no maximum.
7037 * (other than the maximum length of entries.) The value passed in will
7038 * be clamped to the range 0-65536.
7040 * Sets the maximum allowed length of the contents of the widget. If
7041 * the current contents are longer than the given length, then they
7042 * will be truncated to fit.
7044 * This is equivalent to:
7046 * <informalexample><programlisting>
7047 * gtk_entry_buffer_set_max_length (gtk_entry_get_buffer (entry), max);
7048 * </programlisting></informalexample>
7051 gtk_entry_set_max_length (GtkEntry *entry,
7054 g_return_if_fail (GTK_IS_ENTRY (entry));
7055 gtk_entry_buffer_set_max_length (get_buffer (entry), max);
7059 * gtk_entry_get_max_length:
7060 * @entry: a #GtkEntry
7062 * Retrieves the maximum allowed length of the text in
7063 * @entry. See gtk_entry_set_max_length().
7065 * This is equivalent to:
7067 * <informalexample><programlisting>
7068 * gtk_entry_buffer_get_max_length (gtk_entry_get_buffer (entry));
7069 * </programlisting></informalexample>
7071 * Return value: the maximum allowed number of characters
7072 * in #GtkEntry, or 0 if there is no maximum.
7075 gtk_entry_get_max_length (GtkEntry *entry)
7077 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7078 return gtk_entry_buffer_get_max_length (get_buffer (entry));
7082 * gtk_entry_get_text_length:
7083 * @entry: a #GtkEntry
7085 * Retrieves the current length of the text in
7088 * This is equivalent to:
7090 * <informalexample><programlisting>
7091 * gtk_entry_buffer_get_length (gtk_entry_get_buffer (entry));
7092 * </programlisting></informalexample>
7094 * Return value: the current number of characters
7095 * in #GtkEntry, or 0 if there are none.
7100 gtk_entry_get_text_length (GtkEntry *entry)
7102 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7103 return gtk_entry_buffer_get_length (get_buffer (entry));
7107 * gtk_entry_set_activates_default:
7108 * @entry: a #GtkEntry
7109 * @setting: %TRUE to activate window's default widget on Enter keypress
7111 * If @setting is %TRUE, pressing Enter in the @entry will activate the default
7112 * widget for the window containing the entry. This usually means that
7113 * the dialog box containing the entry will be closed, since the default
7114 * widget is usually one of the dialog buttons.
7116 * (For experts: if @setting is %TRUE, the entry calls
7117 * gtk_window_activate_default() on the window containing the entry, in
7118 * the default handler for the #GtkWidget::activate signal.)
7121 gtk_entry_set_activates_default (GtkEntry *entry,
7124 g_return_if_fail (GTK_IS_ENTRY (entry));
7125 setting = setting != FALSE;
7127 if (setting != entry->activates_default)
7129 entry->activates_default = setting;
7130 g_object_notify (G_OBJECT (entry), "activates-default");
7135 * gtk_entry_get_activates_default:
7136 * @entry: a #GtkEntry
7138 * Retrieves the value set by gtk_entry_set_activates_default().
7140 * Return value: %TRUE if the entry will activate the default widget
7143 gtk_entry_get_activates_default (GtkEntry *entry)
7145 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7147 return entry->activates_default;
7151 * gtk_entry_set_width_chars:
7152 * @entry: a #GtkEntry
7153 * @n_chars: width in chars
7155 * Changes the size request of the entry to be about the right size
7156 * for @n_chars characters. Note that it changes the size
7157 * <emphasis>request</emphasis>, the size can still be affected by
7158 * how you pack the widget into containers. If @n_chars is -1, the
7159 * size reverts to the default entry size.
7162 gtk_entry_set_width_chars (GtkEntry *entry,
7165 g_return_if_fail (GTK_IS_ENTRY (entry));
7167 if (entry->width_chars != n_chars)
7169 entry->width_chars = n_chars;
7170 g_object_notify (G_OBJECT (entry), "width-chars");
7171 gtk_widget_queue_resize (GTK_WIDGET (entry));
7176 * gtk_entry_get_width_chars:
7177 * @entry: a #GtkEntry
7179 * Gets the value set by gtk_entry_set_width_chars().
7181 * Return value: number of chars to request space for, or negative if unset
7184 gtk_entry_get_width_chars (GtkEntry *entry)
7186 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7188 return entry->width_chars;
7192 * gtk_entry_set_has_frame:
7193 * @entry: a #GtkEntry
7194 * @setting: new value
7196 * Sets whether the entry has a beveled frame around it.
7199 gtk_entry_set_has_frame (GtkEntry *entry,
7202 g_return_if_fail (GTK_IS_ENTRY (entry));
7204 setting = (setting != FALSE);
7206 if (entry->has_frame == setting)
7209 gtk_widget_queue_resize (GTK_WIDGET (entry));
7210 entry->has_frame = setting;
7211 g_object_notify (G_OBJECT (entry), "has-frame");
7215 * gtk_entry_get_has_frame:
7216 * @entry: a #GtkEntry
7218 * Gets the value set by gtk_entry_set_has_frame().
7220 * Return value: whether the entry has a beveled frame
7223 gtk_entry_get_has_frame (GtkEntry *entry)
7225 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7227 return entry->has_frame;
7231 * gtk_entry_set_inner_border:
7232 * @entry: a #GtkEntry
7233 * @border: (allow-none): a #GtkBorder, or %NULL
7235 * Sets %entry's inner-border property to %border, or clears it if %NULL
7236 * is passed. The inner-border is the area around the entry's text, but
7239 * If set, this property overrides the inner-border style property.
7240 * Overriding the style-provided border is useful when you want to do
7241 * in-place editing of some text in a canvas or list widget, where
7242 * pixel-exact positioning of the entry is important.
7247 gtk_entry_set_inner_border (GtkEntry *entry,
7248 const GtkBorder *border)
7250 g_return_if_fail (GTK_IS_ENTRY (entry));
7252 gtk_widget_queue_resize (GTK_WIDGET (entry));
7255 g_object_set_qdata_full (G_OBJECT (entry), quark_inner_border,
7256 gtk_border_copy (border),
7257 (GDestroyNotify) gtk_border_free);
7259 g_object_set_qdata (G_OBJECT (entry), quark_inner_border, NULL);
7261 g_object_notify (G_OBJECT (entry), "inner-border");
7265 * gtk_entry_get_inner_border:
7266 * @entry: a #GtkEntry
7268 * This function returns the entry's #GtkEntry:inner-border property. See
7269 * gtk_entry_set_inner_border() for more information.
7271 * Return value: (transfer none): the entry's #GtkBorder, or %NULL if none was set.
7275 G_CONST_RETURN GtkBorder *
7276 gtk_entry_get_inner_border (GtkEntry *entry)
7278 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7280 return g_object_get_qdata (G_OBJECT (entry), quark_inner_border);
7284 * gtk_entry_get_layout:
7285 * @entry: a #GtkEntry
7287 * Gets the #PangoLayout used to display the entry.
7288 * The layout is useful to e.g. convert text positions to
7289 * pixel positions, in combination with gtk_entry_get_layout_offsets().
7290 * The returned layout is owned by the entry and must not be
7291 * modified or freed by the caller.
7293 * Keep in mind that the layout text may contain a preedit string, so
7294 * gtk_entry_layout_index_to_text_index() and
7295 * gtk_entry_text_index_to_layout_index() are needed to convert byte
7296 * indices in the layout to byte indices in the entry contents.
7298 * Return value: (transfer none): the #PangoLayout for this entry
7301 gtk_entry_get_layout (GtkEntry *entry)
7303 PangoLayout *layout;
7305 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7307 layout = gtk_entry_ensure_layout (entry, TRUE);
7314 * gtk_entry_layout_index_to_text_index:
7315 * @entry: a #GtkEntry
7316 * @layout_index: byte index into the entry layout text
7318 * Converts from a position in the entry contents (returned
7319 * by gtk_entry_get_text()) to a position in the
7320 * entry's #PangoLayout (returned by gtk_entry_get_layout(),
7321 * with text retrieved via pango_layout_get_text()).
7323 * Return value: byte index into the entry contents
7326 gtk_entry_layout_index_to_text_index (GtkEntry *entry,
7329 PangoLayout *layout;
7333 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7335 layout = gtk_entry_ensure_layout (entry, TRUE);
7336 text = pango_layout_get_text (layout);
7337 cursor_index = g_utf8_offset_to_pointer (text, entry->current_pos) - text;
7339 if (layout_index >= cursor_index && entry->preedit_length)
7341 if (layout_index >= cursor_index + entry->preedit_length)
7342 layout_index -= entry->preedit_length;
7344 layout_index = cursor_index;
7347 return layout_index;
7351 * gtk_entry_text_index_to_layout_index:
7352 * @entry: a #GtkEntry
7353 * @text_index: byte index into the entry contents
7355 * Converts from a position in the entry's #PangoLayout (returned by
7356 * gtk_entry_get_layout()) to a position in the entry contents
7357 * (returned by gtk_entry_get_text()).
7359 * Return value: byte index into the entry layout text
7362 gtk_entry_text_index_to_layout_index (GtkEntry *entry,
7365 PangoLayout *layout;
7368 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7370 layout = gtk_entry_ensure_layout (entry, TRUE);
7371 text = pango_layout_get_text (layout);
7372 cursor_index = g_utf8_offset_to_pointer (text, entry->current_pos) - text;
7374 if (text_index > cursor_index)
7375 text_index += entry->preedit_length;
7381 * gtk_entry_get_layout_offsets:
7382 * @entry: a #GtkEntry
7383 * @x: (allow-none): location to store X offset of layout, or %NULL
7384 * @y: (allow-none): location to store Y offset of layout, or %NULL
7387 * Obtains the position of the #PangoLayout used to render text
7388 * in the entry, in widget coordinates. Useful if you want to line
7389 * up the text in an entry with some other text, e.g. when using the
7390 * entry to implement editable cells in a sheet widget.
7392 * Also useful to convert mouse events into coordinates inside the
7393 * #PangoLayout, e.g. to take some action if some part of the entry text
7396 * Note that as the user scrolls around in the entry the offsets will
7397 * change; you'll need to connect to the "notify::scroll-offset"
7398 * signal to track this. Remember when using the #PangoLayout
7399 * functions you need to convert to and from pixels using
7400 * PANGO_PIXELS() or #PANGO_SCALE.
7402 * Keep in mind that the layout text may contain a preedit string, so
7403 * gtk_entry_layout_index_to_text_index() and
7404 * gtk_entry_text_index_to_layout_index() are needed to convert byte
7405 * indices in the layout to byte indices in the entry contents.
7408 gtk_entry_get_layout_offsets (GtkEntry *entry,
7412 gint text_area_x, text_area_y;
7414 g_return_if_fail (GTK_IS_ENTRY (entry));
7416 /* this gets coords relative to text area */
7417 get_layout_position (entry, x, y);
7419 /* convert to widget coords */
7420 gtk_entry_get_text_area_size (entry, &text_area_x, &text_area_y, NULL, NULL);
7431 * gtk_entry_set_alignment:
7432 * @entry: a #GtkEntry
7433 * @xalign: The horizontal alignment, from 0 (left) to 1 (right).
7434 * Reversed for RTL layouts
7436 * Sets the alignment for the contents of the entry. This controls
7437 * the horizontal positioning of the contents when the displayed
7438 * text is shorter than the width of the entry.
7443 gtk_entry_set_alignment (GtkEntry *entry, gfloat xalign)
7445 GtkEntryPrivate *priv;
7447 g_return_if_fail (GTK_IS_ENTRY (entry));
7449 priv = GTK_ENTRY_GET_PRIVATE (entry);
7453 else if (xalign > 1.0)
7456 if (xalign != priv->xalign)
7458 priv->xalign = xalign;
7460 gtk_entry_recompute (entry);
7462 g_object_notify (G_OBJECT (entry), "xalign");
7467 * gtk_entry_get_alignment:
7468 * @entry: a #GtkEntry
7470 * Gets the value set by gtk_entry_set_alignment().
7472 * Return value: the alignment
7477 gtk_entry_get_alignment (GtkEntry *entry)
7479 GtkEntryPrivate *priv;
7481 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
7483 priv = GTK_ENTRY_GET_PRIVATE (entry);
7485 return priv->xalign;
7489 * gtk_entry_set_icon_from_pixbuf:
7490 * @entry: a #GtkEntry
7491 * @icon_pos: Icon position
7492 * @pixbuf: (allow-none): A #GdkPixbuf, or %NULL
7494 * Sets the icon shown in the specified position using a pixbuf.
7496 * If @pixbuf is %NULL, no icon will be shown in the specified position.
7501 gtk_entry_set_icon_from_pixbuf (GtkEntry *entry,
7502 GtkEntryIconPosition icon_pos,
7505 GtkEntryPrivate *priv;
7506 EntryIconInfo *icon_info;
7508 g_return_if_fail (GTK_IS_ENTRY (entry));
7509 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7511 priv = GTK_ENTRY_GET_PRIVATE (entry);
7513 if ((icon_info = priv->icons[icon_pos]) == NULL)
7514 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7516 g_object_freeze_notify (G_OBJECT (entry));
7519 g_object_ref (pixbuf);
7521 gtk_entry_clear (entry, icon_pos);
7525 icon_info->storage_type = GTK_IMAGE_PIXBUF;
7526 icon_info->pixbuf = pixbuf;
7528 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7530 g_object_notify (G_OBJECT (entry), "primary-icon-pixbuf");
7531 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7535 g_object_notify (G_OBJECT (entry), "secondary-icon-pixbuf");
7536 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7539 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7540 gdk_window_show_unraised (icon_info->window);
7543 gtk_entry_ensure_pixbuf (entry, icon_pos);
7545 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7546 gtk_widget_queue_resize (GTK_WIDGET (entry));
7548 g_object_thaw_notify (G_OBJECT (entry));
7552 * gtk_entry_set_icon_from_stock:
7553 * @entry: A #GtkEntry
7554 * @icon_pos: Icon position
7555 * @stock_id: (allow-none): The name of the stock item, or %NULL
7557 * Sets the icon shown in the entry at the specified position from
7560 * If @stock_id is %NULL, no icon will be shown in the specified position.
7565 gtk_entry_set_icon_from_stock (GtkEntry *entry,
7566 GtkEntryIconPosition icon_pos,
7567 const gchar *stock_id)
7569 GtkEntryPrivate *priv;
7570 EntryIconInfo *icon_info;
7573 g_return_if_fail (GTK_IS_ENTRY (entry));
7574 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7576 priv = GTK_ENTRY_GET_PRIVATE (entry);
7578 if ((icon_info = priv->icons[icon_pos]) == NULL)
7579 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7581 g_object_freeze_notify (G_OBJECT (entry));
7583 gtk_widget_ensure_style (GTK_WIDGET (entry));
7585 /* need to dup before clearing */
7586 new_id = g_strdup (stock_id);
7588 gtk_entry_clear (entry, icon_pos);
7592 icon_info->storage_type = GTK_IMAGE_STOCK;
7593 icon_info->stock_id = new_id;
7595 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7597 g_object_notify (G_OBJECT (entry), "primary-icon-stock");
7598 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7602 g_object_notify (G_OBJECT (entry), "secondary-icon-stock");
7603 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7606 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7607 gdk_window_show_unraised (icon_info->window);
7610 gtk_entry_ensure_pixbuf (entry, icon_pos);
7612 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7613 gtk_widget_queue_resize (GTK_WIDGET (entry));
7615 g_object_thaw_notify (G_OBJECT (entry));
7619 * gtk_entry_set_icon_from_icon_name:
7620 * @entry: A #GtkEntry
7621 * @icon_pos: The position at which to set the icon
7622 * @icon_name: (allow-none): An icon name, or %NULL
7624 * Sets the icon shown in the entry at the specified position
7625 * from the current icon theme.
7627 * If the icon name isn't known, a "broken image" icon will be displayed
7630 * If @icon_name is %NULL, no icon will be shown in the specified position.
7635 gtk_entry_set_icon_from_icon_name (GtkEntry *entry,
7636 GtkEntryIconPosition icon_pos,
7637 const gchar *icon_name)
7639 GtkEntryPrivate *priv;
7640 EntryIconInfo *icon_info;
7643 g_return_if_fail (GTK_IS_ENTRY (entry));
7644 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7646 priv = GTK_ENTRY_GET_PRIVATE (entry);
7648 if ((icon_info = priv->icons[icon_pos]) == NULL)
7649 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7651 g_object_freeze_notify (G_OBJECT (entry));
7653 gtk_widget_ensure_style (GTK_WIDGET (entry));
7655 /* need to dup before clearing */
7656 new_name = g_strdup (icon_name);
7658 gtk_entry_clear (entry, icon_pos);
7660 if (new_name != NULL)
7662 icon_info->storage_type = GTK_IMAGE_ICON_NAME;
7663 icon_info->icon_name = new_name;
7665 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7667 g_object_notify (G_OBJECT (entry), "primary-icon-name");
7668 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7672 g_object_notify (G_OBJECT (entry), "secondary-icon-name");
7673 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7676 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7677 gdk_window_show_unraised (icon_info->window);
7680 gtk_entry_ensure_pixbuf (entry, icon_pos);
7682 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7683 gtk_widget_queue_resize (GTK_WIDGET (entry));
7685 g_object_thaw_notify (G_OBJECT (entry));
7689 * gtk_entry_set_icon_from_gicon:
7690 * @entry: A #GtkEntry
7691 * @icon_pos: The position at which to set the icon
7692 * @icon: (allow-none): The icon to set, or %NULL
7694 * Sets the icon shown in the entry at the specified position
7695 * from the current icon theme.
7696 * If the icon isn't known, a "broken image" icon will be displayed
7699 * If @icon is %NULL, no icon will be shown in the specified position.
7704 gtk_entry_set_icon_from_gicon (GtkEntry *entry,
7705 GtkEntryIconPosition icon_pos,
7708 GtkEntryPrivate *priv;
7709 EntryIconInfo *icon_info;
7711 g_return_if_fail (GTK_IS_ENTRY (entry));
7712 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7714 priv = GTK_ENTRY_GET_PRIVATE (entry);
7716 if ((icon_info = priv->icons[icon_pos]) == NULL)
7717 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7719 g_object_freeze_notify (G_OBJECT (entry));
7721 /* need to ref before clearing */
7723 g_object_ref (icon);
7725 gtk_entry_clear (entry, icon_pos);
7729 icon_info->storage_type = GTK_IMAGE_GICON;
7730 icon_info->gicon = icon;
7732 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7734 g_object_notify (G_OBJECT (entry), "primary-icon-gicon");
7735 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7739 g_object_notify (G_OBJECT (entry), "secondary-icon-gicon");
7740 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7743 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7744 gdk_window_show_unraised (icon_info->window);
7747 gtk_entry_ensure_pixbuf (entry, icon_pos);
7749 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7750 gtk_widget_queue_resize (GTK_WIDGET (entry));
7752 g_object_thaw_notify (G_OBJECT (entry));
7756 * gtk_entry_set_icon_activatable:
7757 * @entry: A #GtkEntry
7758 * @icon_pos: Icon position
7759 * @activatable: %TRUE if the icon should be activatable
7761 * Sets whether the icon is activatable.
7766 gtk_entry_set_icon_activatable (GtkEntry *entry,
7767 GtkEntryIconPosition icon_pos,
7768 gboolean activatable)
7770 GtkEntryPrivate *priv;
7771 EntryIconInfo *icon_info;
7773 g_return_if_fail (GTK_IS_ENTRY (entry));
7774 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7776 priv = GTK_ENTRY_GET_PRIVATE (entry);
7778 if ((icon_info = priv->icons[icon_pos]) == NULL)
7779 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7781 activatable = activatable != FALSE;
7783 if (icon_info->nonactivatable != !activatable)
7785 icon_info->nonactivatable = !activatable;
7787 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
7788 update_cursors (GTK_WIDGET (entry));
7790 g_object_notify (G_OBJECT (entry),
7791 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-activatable" : "secondary-icon-activatable");
7796 * gtk_entry_get_icon_activatable:
7797 * @entry: a #GtkEntry
7798 * @icon_pos: Icon position
7800 * Returns whether the icon is activatable.
7802 * Returns: %TRUE if the icon is activatable.
7807 gtk_entry_get_icon_activatable (GtkEntry *entry,
7808 GtkEntryIconPosition icon_pos)
7810 GtkEntryPrivate *priv;
7811 EntryIconInfo *icon_info;
7813 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7814 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), FALSE);
7816 priv = GTK_ENTRY_GET_PRIVATE (entry);
7817 icon_info = priv->icons[icon_pos];
7819 return (icon_info != NULL && !icon_info->nonactivatable);
7823 * gtk_entry_get_icon_pixbuf:
7824 * @entry: A #GtkEntry
7825 * @icon_pos: Icon position
7827 * Retrieves the image used for the icon.
7829 * Unlike the other methods of setting and getting icon data, this
7830 * method will work regardless of whether the icon was set using a
7831 * #GdkPixbuf, a #GIcon, a stock item, or an icon name.
7833 * Returns: (transfer none): A #GdkPixbuf, or %NULL if no icon is
7834 * set for this position.
7839 gtk_entry_get_icon_pixbuf (GtkEntry *entry,
7840 GtkEntryIconPosition icon_pos)
7842 GtkEntryPrivate *priv;
7843 EntryIconInfo *icon_info;
7845 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7846 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7848 priv = GTK_ENTRY_GET_PRIVATE (entry);
7849 icon_info = priv->icons[icon_pos];
7854 gtk_entry_ensure_pixbuf (entry, icon_pos);
7856 return icon_info->pixbuf;
7860 * gtk_entry_get_icon_gicon:
7861 * @entry: A #GtkEntry
7862 * @icon_pos: Icon position
7864 * Retrieves the #GIcon used for the icon, or %NULL if there is
7865 * no icon or if the icon was set by some other method (e.g., by
7866 * stock, pixbuf, or icon name).
7868 * Returns: (transfer none): A #GIcon, or %NULL if no icon is set
7869 * or if the icon is not a #GIcon
7874 gtk_entry_get_icon_gicon (GtkEntry *entry,
7875 GtkEntryIconPosition icon_pos)
7877 GtkEntryPrivate *priv;
7878 EntryIconInfo *icon_info;
7880 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7881 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7883 priv = GTK_ENTRY_GET_PRIVATE (entry);
7884 icon_info = priv->icons[icon_pos];
7889 return icon_info->storage_type == GTK_IMAGE_GICON ? icon_info->gicon : NULL;
7893 * gtk_entry_get_icon_stock:
7894 * @entry: A #GtkEntry
7895 * @icon_pos: Icon position
7897 * Retrieves the stock id used for the icon, or %NULL if there is
7898 * no icon or if the icon was set by some other method (e.g., by
7899 * pixbuf, icon name or gicon).
7901 * Returns: A stock id, or %NULL if no icon is set or if the icon
7902 * wasn't set from a stock id
7907 gtk_entry_get_icon_stock (GtkEntry *entry,
7908 GtkEntryIconPosition icon_pos)
7910 GtkEntryPrivate *priv;
7911 EntryIconInfo *icon_info;
7913 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7914 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7916 priv = GTK_ENTRY_GET_PRIVATE (entry);
7917 icon_info = priv->icons[icon_pos];
7922 return icon_info->storage_type == GTK_IMAGE_STOCK ? icon_info->stock_id : NULL;
7926 * gtk_entry_get_icon_name:
7927 * @entry: A #GtkEntry
7928 * @icon_pos: Icon position
7930 * Retrieves the icon name used for the icon, or %NULL if there is
7931 * no icon or if the icon was set by some other method (e.g., by
7932 * pixbuf, stock or gicon).
7934 * Returns: An icon name, or %NULL if no icon is set or if the icon
7935 * wasn't set from an icon name
7940 gtk_entry_get_icon_name (GtkEntry *entry,
7941 GtkEntryIconPosition icon_pos)
7943 GtkEntryPrivate *priv;
7944 EntryIconInfo *icon_info;
7946 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7947 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7949 priv = GTK_ENTRY_GET_PRIVATE (entry);
7950 icon_info = priv->icons[icon_pos];
7955 return icon_info->storage_type == GTK_IMAGE_ICON_NAME ? icon_info->icon_name : NULL;
7959 * gtk_entry_set_icon_sensitive:
7960 * @entry: A #GtkEntry
7961 * @icon_pos: Icon position
7962 * @sensitive: Specifies whether the icon should appear
7963 * sensitive or insensitive
7965 * Sets the sensitivity for the specified icon.
7970 gtk_entry_set_icon_sensitive (GtkEntry *entry,
7971 GtkEntryIconPosition icon_pos,
7974 GtkEntryPrivate *priv;
7975 EntryIconInfo *icon_info;
7977 g_return_if_fail (GTK_IS_ENTRY (entry));
7978 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7980 priv = GTK_ENTRY_GET_PRIVATE (entry);
7982 if ((icon_info = priv->icons[icon_pos]) == NULL)
7983 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7985 if (icon_info->insensitive != !sensitive)
7987 icon_info->insensitive = !sensitive;
7989 icon_info->pressed = FALSE;
7990 icon_info->prelight = FALSE;
7992 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
7993 update_cursors (GTK_WIDGET (entry));
7995 gtk_widget_queue_draw (GTK_WIDGET (entry));
7997 g_object_notify (G_OBJECT (entry),
7998 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-sensitive" : "secondary-icon-sensitive");
8003 * gtk_entry_get_icon_sensitive:
8004 * @entry: a #GtkEntry
8005 * @icon_pos: Icon position
8007 * Returns whether the icon appears sensitive or insensitive.
8009 * Returns: %TRUE if the icon is sensitive.
8014 gtk_entry_get_icon_sensitive (GtkEntry *entry,
8015 GtkEntryIconPosition icon_pos)
8017 GtkEntryPrivate *priv;
8018 EntryIconInfo *icon_info;
8020 g_return_val_if_fail (GTK_IS_ENTRY (entry), TRUE);
8021 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), TRUE);
8023 priv = GTK_ENTRY_GET_PRIVATE (entry);
8024 icon_info = priv->icons[icon_pos];
8026 return (!icon_info || !icon_info->insensitive);
8031 * gtk_entry_get_icon_storage_type:
8032 * @entry: a #GtkEntry
8033 * @icon_pos: Icon position
8035 * Gets the type of representation being used by the icon
8036 * to store image data. If the icon has no image data,
8037 * the return value will be %GTK_IMAGE_EMPTY.
8039 * Return value: image representation being used
8044 gtk_entry_get_icon_storage_type (GtkEntry *entry,
8045 GtkEntryIconPosition icon_pos)
8047 GtkEntryPrivate *priv;
8048 EntryIconInfo *icon_info;
8050 g_return_val_if_fail (GTK_IS_ENTRY (entry), GTK_IMAGE_EMPTY);
8051 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), GTK_IMAGE_EMPTY);
8053 priv = GTK_ENTRY_GET_PRIVATE (entry);
8054 icon_info = priv->icons[icon_pos];
8057 return GTK_IMAGE_EMPTY;
8059 return icon_info->storage_type;
8063 * gtk_entry_get_icon_at_pos:
8064 * @entry: a #GtkEntry
8065 * @x: the x coordinate of the position to find
8066 * @y: the y coordinate of the position to find
8068 * Finds the icon at the given position and return its index.
8069 * If @x, @y doesn't lie inside an icon, -1 is returned.
8070 * This function is intended for use in a #GtkWidget::query-tooltip
8073 * Returns: the index of the icon at the given position, or -1
8078 gtk_entry_get_icon_at_pos (GtkEntry *entry,
8082 GtkAllocation primary;
8083 GtkAllocation secondary;
8084 gint frame_x, frame_y;
8086 g_return_val_if_fail (GTK_IS_ENTRY (entry), -1);
8088 get_frame_size (entry, &frame_x, &frame_y, NULL, NULL);
8092 get_icon_allocations (entry, &primary, &secondary);
8094 if (primary.x <= x && x < primary.x + primary.width &&
8095 primary.y <= y && y < primary.y + primary.height)
8096 return GTK_ENTRY_ICON_PRIMARY;
8098 if (secondary.x <= x && x < secondary.x + secondary.width &&
8099 secondary.y <= y && y < secondary.y + secondary.height)
8100 return GTK_ENTRY_ICON_SECONDARY;
8106 * gtk_entry_set_icon_drag_source:
8107 * @entry: a #GtkIconEntry
8108 * @icon_pos: icon position
8109 * @target_list: the targets (data formats) in which the data can be provided
8110 * @actions: a bitmask of the allowed drag actions
8112 * Sets up the icon at the given position so that GTK+ will start a drag
8113 * operation when the user clicks and drags the icon.
8115 * To handle the drag operation, you need to connect to the usual
8116 * #GtkWidget::drag-data-get (or possibly #GtkWidget::drag-data-delete)
8117 * signal, and use gtk_entry_get_current_icon_drag_source() in
8118 * your signal handler to find out if the drag was started from
8121 * By default, GTK+ uses the icon as the drag icon. You can use the
8122 * #GtkWidget::drag-begin signal to set a different icon. Note that you
8123 * have to use g_signal_connect_after() to ensure that your signal handler
8124 * gets executed after the default handler.
8129 gtk_entry_set_icon_drag_source (GtkEntry *entry,
8130 GtkEntryIconPosition icon_pos,
8131 GtkTargetList *target_list,
8132 GdkDragAction actions)
8134 GtkEntryPrivate *priv;
8135 EntryIconInfo *icon_info;
8137 g_return_if_fail (GTK_IS_ENTRY (entry));
8138 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8140 priv = GTK_ENTRY_GET_PRIVATE (entry);
8142 if ((icon_info = priv->icons[icon_pos]) == NULL)
8143 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8145 if (icon_info->target_list)
8146 gtk_target_list_unref (icon_info->target_list);
8147 icon_info->target_list = target_list;
8148 if (icon_info->target_list)
8149 gtk_target_list_ref (icon_info->target_list);
8151 icon_info->actions = actions;
8155 * gtk_entry_get_current_icon_drag_source:
8156 * @entry: a #GtkIconEntry
8158 * Returns the index of the icon which is the source of the current
8159 * DND operation, or -1.
8161 * This function is meant to be used in a #GtkWidget::drag-data-get
8164 * Returns: index of the icon which is the source of the current
8165 * DND operation, or -1.
8170 gtk_entry_get_current_icon_drag_source (GtkEntry *entry)
8172 GtkEntryPrivate *priv;
8173 EntryIconInfo *icon_info = NULL;
8176 g_return_val_if_fail (GTK_IS_ENTRY (entry), -1);
8178 priv = GTK_ENTRY_GET_PRIVATE (entry);
8180 for (i = 0; i < MAX_ICONS; i++)
8182 if ((icon_info = priv->icons[i]))
8184 if (icon_info->in_drag)
8193 * gtk_entry_get_icon_area:
8194 * @entry: A #GtkEntry
8195 * @icon_pos: Icon position
8196 * @icon_area: Return location for the icon's area
8198 * Gets the area where entry's icon at @icon_pos is drawn.
8199 * This function is useful when drawing something to the
8200 * entry in a draw callback.
8202 * If the entry is not realized or has no icon at the given position,
8203 * @icon_area is filled with zeros.
8205 * See also gtk_entry_get_text_area()
8210 gtk_entry_get_icon_area (GtkEntry *entry,
8211 GtkEntryIconPosition icon_pos,
8212 GdkRectangle *icon_area)
8214 GtkEntryPrivate *priv;
8215 EntryIconInfo *icon_info;
8217 g_return_if_fail (GTK_IS_ENTRY (entry));
8218 g_return_if_fail (icon_area != NULL);
8220 priv = GTK_ENTRY_GET_PRIVATE (entry);
8222 icon_info = priv->icons[icon_pos];
8226 GtkAllocation primary;
8227 GtkAllocation secondary;
8229 get_icon_allocations (entry, &primary, &secondary);
8231 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
8232 *icon_area = primary;
8234 *icon_area = secondary;
8240 icon_area->width = 0;
8241 icon_area->height = 0;
8246 ensure_has_tooltip (GtkEntry *entry)
8248 GtkEntryPrivate *priv;
8249 EntryIconInfo *icon_info;
8251 gboolean has_tooltip = FALSE;
8253 priv = GTK_ENTRY_GET_PRIVATE (entry);
8255 for (i = 0; i < MAX_ICONS; i++)
8257 if ((icon_info = priv->icons[i]) != NULL)
8259 if (icon_info->tooltip != NULL)
8267 gtk_widget_set_has_tooltip (GTK_WIDGET (entry), has_tooltip);
8271 * gtk_entry_get_icon_tooltip_text:
8272 * @entry: a #GtkEntry
8273 * @icon_pos: the icon position
8275 * Gets the contents of the tooltip on the icon at the specified
8276 * position in @entry.
8278 * Returns: the tooltip text, or %NULL. Free the returned string
8279 * with g_free() when done.
8284 gtk_entry_get_icon_tooltip_text (GtkEntry *entry,
8285 GtkEntryIconPosition icon_pos)
8287 GtkEntryPrivate *priv;
8288 EntryIconInfo *icon_info;
8291 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8292 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8294 priv = GTK_ENTRY_GET_PRIVATE (entry);
8295 icon_info = priv->icons[icon_pos];
8300 if (icon_info->tooltip &&
8301 !pango_parse_markup (icon_info->tooltip, -1, 0, NULL, &text, NULL, NULL))
8302 g_assert (NULL == text); /* text should still be NULL in case of markup errors */
8308 * gtk_entry_set_icon_tooltip_text:
8309 * @entry: a #GtkEntry
8310 * @icon_pos: the icon position
8311 * @tooltip: (allow-none): the contents of the tooltip for the icon, or %NULL
8313 * Sets @tooltip as the contents of the tooltip for the icon
8314 * at the specified position.
8316 * Use %NULL for @tooltip to remove an existing tooltip.
8318 * See also gtk_widget_set_tooltip_text() and
8319 * gtk_entry_set_icon_tooltip_markup().
8324 gtk_entry_set_icon_tooltip_text (GtkEntry *entry,
8325 GtkEntryIconPosition icon_pos,
8326 const gchar *tooltip)
8328 GtkEntryPrivate *priv;
8329 EntryIconInfo *icon_info;
8331 g_return_if_fail (GTK_IS_ENTRY (entry));
8332 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8334 priv = GTK_ENTRY_GET_PRIVATE (entry);
8336 if (!(icon_info = priv->icons[icon_pos]))
8337 icon_info = priv->icons[icon_pos];
8339 if (icon_info->tooltip)
8340 g_free (icon_info->tooltip);
8342 /* Treat an empty string as a NULL string,
8343 * because an empty string would be useless for a tooltip:
8345 if (tooltip && tooltip[0] == '\0')
8348 icon_info->tooltip = tooltip ? g_markup_escape_text (tooltip, -1) : NULL;
8350 ensure_has_tooltip (entry);
8354 * gtk_entry_get_icon_tooltip_markup:
8355 * @entry: a #GtkEntry
8356 * @icon_pos: the icon position
8358 * Gets the contents of the tooltip on the icon at the specified
8359 * position in @entry.
8361 * Returns: the tooltip text, or %NULL. Free the returned string
8362 * with g_free() when done.
8367 gtk_entry_get_icon_tooltip_markup (GtkEntry *entry,
8368 GtkEntryIconPosition icon_pos)
8370 GtkEntryPrivate *priv;
8371 EntryIconInfo *icon_info;
8373 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8374 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8376 priv = GTK_ENTRY_GET_PRIVATE (entry);
8377 icon_info = priv->icons[icon_pos];
8382 return g_strdup (icon_info->tooltip);
8386 * gtk_entry_set_icon_tooltip_markup:
8387 * @entry: a #GtkEntry
8388 * @icon_pos: the icon position
8389 * @tooltip: (allow-none): the contents of the tooltip for the icon, or %NULL
8391 * Sets @tooltip as the contents of the tooltip for the icon at
8392 * the specified position. @tooltip is assumed to be marked up with
8393 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
8395 * Use %NULL for @tooltip to remove an existing tooltip.
8397 * See also gtk_widget_set_tooltip_markup() and
8398 * gtk_enty_set_icon_tooltip_text().
8403 gtk_entry_set_icon_tooltip_markup (GtkEntry *entry,
8404 GtkEntryIconPosition icon_pos,
8405 const gchar *tooltip)
8407 GtkEntryPrivate *priv;
8408 EntryIconInfo *icon_info;
8410 g_return_if_fail (GTK_IS_ENTRY (entry));
8411 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8413 priv = GTK_ENTRY_GET_PRIVATE (entry);
8415 if (!(icon_info = priv->icons[icon_pos]))
8416 icon_info = priv->icons[icon_pos];
8418 if (icon_info->tooltip)
8419 g_free (icon_info->tooltip);
8421 /* Treat an empty string as a NULL string,
8422 * because an empty string would be useless for a tooltip:
8424 if (tooltip && tooltip[0] == '\0')
8427 icon_info->tooltip = g_strdup (tooltip);
8429 ensure_has_tooltip (entry);
8433 gtk_entry_query_tooltip (GtkWidget *widget,
8436 gboolean keyboard_tip,
8437 GtkTooltip *tooltip)
8440 GtkEntryPrivate *priv;
8441 EntryIconInfo *icon_info;
8444 entry = GTK_ENTRY (widget);
8445 priv = GTK_ENTRY_GET_PRIVATE (entry);
8449 icon_pos = gtk_entry_get_icon_at_pos (entry, x, y);
8452 if ((icon_info = priv->icons[icon_pos]) != NULL)
8454 if (icon_info->tooltip)
8456 gtk_tooltip_set_markup (tooltip, icon_info->tooltip);
8465 return GTK_WIDGET_CLASS (gtk_entry_parent_class)->query_tooltip (widget,
8472 /* Quick hack of a popup menu
8475 activate_cb (GtkWidget *menuitem,
8478 const gchar *signal = g_object_get_data (G_OBJECT (menuitem), "gtk-signal");
8479 g_signal_emit_by_name (entry, signal);
8484 gtk_entry_mnemonic_activate (GtkWidget *widget,
8485 gboolean group_cycling)
8487 gtk_widget_grab_focus (widget);
8492 append_action_signal (GtkEntry *entry,
8494 const gchar *stock_id,
8495 const gchar *signal,
8498 GtkWidget *menuitem = gtk_image_menu_item_new_from_stock (stock_id, NULL);
8500 g_object_set_data (G_OBJECT (menuitem), I_("gtk-signal"), (char *)signal);
8501 g_signal_connect (menuitem, "activate",
8502 G_CALLBACK (activate_cb), entry);
8504 gtk_widget_set_sensitive (menuitem, sensitive);
8506 gtk_widget_show (menuitem);
8507 gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
8511 popup_menu_detach (GtkWidget *attach_widget,
8514 GTK_ENTRY (attach_widget)->popup_menu = NULL;
8518 popup_position_func (GtkMenu *menu,
8524 GtkEntry *entry = GTK_ENTRY (user_data);
8525 GtkWidget *widget = GTK_WIDGET (entry);
8527 GtkRequisition menu_req;
8528 GdkRectangle monitor;
8529 GtkBorder inner_border;
8530 gint monitor_num, strong_x, height;
8532 g_return_if_fail (gtk_widget_get_realized (widget));
8534 gdk_window_get_origin (entry->text_area, x, y);
8536 screen = gtk_widget_get_screen (widget);
8537 monitor_num = gdk_screen_get_monitor_at_window (screen, entry->text_area);
8538 if (monitor_num < 0)
8540 gtk_menu_set_monitor (menu, monitor_num);
8542 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
8543 gtk_widget_get_preferred_size (entry->popup_menu,
8545 height = gdk_window_get_height (entry->text_area);
8546 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
8547 _gtk_entry_effective_inner_border (entry, &inner_border);
8549 *x += inner_border.left + strong_x - entry->scroll_offset;
8550 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
8551 *x -= menu_req.width;
8553 if ((*y + height + menu_req.height) <= monitor.y + monitor.height)
8555 else if ((*y - menu_req.height) >= monitor.y)
8556 *y -= menu_req.height;
8557 else if (monitor.y + monitor.height - (*y + height) > *y)
8560 *y -= menu_req.height;
8566 unichar_chosen_func (const char *text,
8569 GtkEntry *entry = GTK_ENTRY (data);
8571 if (entry->editable)
8572 gtk_entry_enter_text (entry, text);
8583 popup_targets_received (GtkClipboard *clipboard,
8584 GtkSelectionData *data,
8587 PopupInfo *info = user_data;
8588 GtkEntry *entry = info->entry;
8590 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
8593 gboolean clipboard_contains_text;
8594 GtkWidget *menuitem;
8596 gboolean show_input_method_menu;
8597 gboolean show_unicode_menu;
8599 clipboard_contains_text = gtk_selection_data_targets_include_text (data);
8600 if (entry->popup_menu)
8601 gtk_widget_destroy (entry->popup_menu);
8603 entry->popup_menu = gtk_menu_new ();
8605 gtk_menu_attach_to_widget (GTK_MENU (entry->popup_menu),
8609 mode = gtk_entry_get_display_mode (entry);
8610 append_action_signal (entry, entry->popup_menu, GTK_STOCK_CUT, "cut-clipboard",
8611 entry->editable && mode == DISPLAY_NORMAL &&
8612 entry->current_pos != entry->selection_bound);
8614 append_action_signal (entry, entry->popup_menu, GTK_STOCK_COPY, "copy-clipboard",
8615 mode == DISPLAY_NORMAL &&
8616 entry->current_pos != entry->selection_bound);
8618 append_action_signal (entry, entry->popup_menu, GTK_STOCK_PASTE, "paste-clipboard",
8619 entry->editable && clipboard_contains_text);
8621 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_DELETE, NULL);
8622 gtk_widget_set_sensitive (menuitem, entry->editable && entry->current_pos != entry->selection_bound);
8623 g_signal_connect_swapped (menuitem, "activate",
8624 G_CALLBACK (gtk_entry_delete_cb), entry);
8625 gtk_widget_show (menuitem);
8626 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8628 menuitem = gtk_separator_menu_item_new ();
8629 gtk_widget_show (menuitem);
8630 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8632 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_SELECT_ALL, NULL);
8633 g_signal_connect_swapped (menuitem, "activate",
8634 G_CALLBACK (gtk_entry_select_all), entry);
8635 gtk_widget_show (menuitem);
8636 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8638 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
8639 "gtk-show-input-method-menu", &show_input_method_menu,
8640 "gtk-show-unicode-menu", &show_unicode_menu,
8643 if (show_input_method_menu || show_unicode_menu)
8645 menuitem = gtk_separator_menu_item_new ();
8646 gtk_widget_show (menuitem);
8647 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8650 if (show_input_method_menu)
8652 menuitem = gtk_menu_item_new_with_mnemonic (_("Input _Methods"));
8653 gtk_widget_set_sensitive (menuitem, entry->editable);
8654 gtk_widget_show (menuitem);
8655 submenu = gtk_menu_new ();
8656 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
8658 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8660 gtk_im_multicontext_append_menuitems (GTK_IM_MULTICONTEXT (entry->im_context),
8661 GTK_MENU_SHELL (submenu));
8664 if (show_unicode_menu)
8666 menuitem = gtk_menu_item_new_with_mnemonic (_("_Insert Unicode Control Character"));
8667 gtk_widget_set_sensitive (menuitem, entry->editable);
8668 gtk_widget_show (menuitem);
8670 submenu = gtk_menu_new ();
8671 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
8672 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8674 _gtk_text_util_append_special_char_menuitems (GTK_MENU_SHELL (submenu),
8675 unichar_chosen_func,
8679 g_signal_emit (entry,
8680 signals[POPULATE_POPUP],
8686 gtk_menu_popup (GTK_MENU (entry->popup_menu), NULL, NULL,
8688 info->button, info->time);
8691 gtk_menu_popup (GTK_MENU (entry->popup_menu), NULL, NULL,
8692 popup_position_func, entry,
8693 info->button, info->time);
8694 gtk_menu_shell_select_first (GTK_MENU_SHELL (entry->popup_menu), FALSE);
8698 g_object_unref (entry);
8699 g_slice_free (PopupInfo, info);
8703 gtk_entry_do_popup (GtkEntry *entry,
8704 GdkEventButton *event)
8706 PopupInfo *info = g_slice_new (PopupInfo);
8708 /* In order to know what entries we should make sensitive, we
8709 * ask for the current targets of the clipboard, and when
8710 * we get them, then we actually pop up the menu.
8712 info->entry = g_object_ref (entry);
8716 info->button = event->button;
8717 info->time = event->time;
8722 info->time = gtk_get_current_event_time ();
8725 gtk_clipboard_request_contents (gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_CLIPBOARD),
8726 gdk_atom_intern_static_string ("TARGETS"),
8727 popup_targets_received,
8732 gtk_entry_popup_menu (GtkWidget *widget)
8734 gtk_entry_do_popup (GTK_ENTRY (widget), NULL);
8739 gtk_entry_drag_begin (GtkWidget *widget,
8740 GdkDragContext *context)
8742 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
8745 for (i = 0; i < MAX_ICONS; i++)
8747 EntryIconInfo *icon_info = priv->icons[i];
8749 if (icon_info != NULL)
8751 if (icon_info->in_drag)
8753 switch (icon_info->storage_type)
8755 case GTK_IMAGE_STOCK:
8756 gtk_drag_set_icon_stock (context, icon_info->stock_id, -2, -2);
8759 case GTK_IMAGE_ICON_NAME:
8760 gtk_drag_set_icon_name (context, icon_info->icon_name, -2, -2);
8763 /* FIXME: No GIcon support for dnd icons */
8764 case GTK_IMAGE_GICON:
8765 case GTK_IMAGE_PIXBUF:
8766 gtk_drag_set_icon_pixbuf (context, icon_info->pixbuf, -2, -2);
8769 g_assert_not_reached ();
8777 gtk_entry_drag_end (GtkWidget *widget,
8778 GdkDragContext *context)
8780 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
8783 for (i = 0; i < MAX_ICONS; i++)
8785 EntryIconInfo *icon_info = priv->icons[i];
8787 if (icon_info != NULL)
8788 icon_info->in_drag = 0;
8793 gtk_entry_drag_leave (GtkWidget *widget,
8794 GdkDragContext *context,
8797 GtkEntry *entry = GTK_ENTRY (widget);
8799 entry->dnd_position = -1;
8800 gtk_widget_queue_draw (widget);
8804 gtk_entry_drag_drop (GtkWidget *widget,
8805 GdkDragContext *context,
8810 GtkEntry *entry = GTK_ENTRY (widget);
8811 GdkAtom target = GDK_NONE;
8813 if (entry->editable)
8814 target = gtk_drag_dest_find_target (widget, context, NULL);
8816 if (target != GDK_NONE)
8817 gtk_drag_get_data (widget, context, target, time);
8819 gtk_drag_finish (context, FALSE, FALSE, time);
8825 gtk_entry_drag_motion (GtkWidget *widget,
8826 GdkDragContext *context,
8831 GtkEntry *entry = GTK_ENTRY (widget);
8833 GtkWidget *source_widget;
8834 GdkDragAction suggested_action;
8835 gint new_position, old_position;
8838 style = gtk_widget_get_style (widget);
8839 x -= style->xthickness;
8840 y -= style->ythickness;
8842 old_position = entry->dnd_position;
8843 new_position = gtk_entry_find_position (entry, x + entry->scroll_offset);
8845 if (entry->editable &&
8846 gtk_drag_dest_find_target (widget, context, NULL) != GDK_NONE)
8848 source_widget = gtk_drag_get_source_widget (context);
8849 suggested_action = context->suggested_action;
8851 if (!gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &sel1, &sel2) ||
8852 new_position < sel1 || new_position > sel2)
8854 if (source_widget == widget)
8856 /* Default to MOVE, unless the user has
8857 * pressed ctrl or alt to affect available actions
8859 if ((context->actions & GDK_ACTION_MOVE) != 0)
8860 suggested_action = GDK_ACTION_MOVE;
8863 entry->dnd_position = new_position;
8867 if (source_widget == widget)
8868 suggested_action = 0; /* Can't drop in selection where drag started */
8870 entry->dnd_position = -1;
8875 /* Entry not editable, or no text */
8876 suggested_action = 0;
8877 entry->dnd_position = -1;
8880 gdk_drag_status (context, suggested_action, time);
8882 if (entry->dnd_position != old_position)
8883 gtk_widget_queue_draw (widget);
8889 gtk_entry_drag_data_received (GtkWidget *widget,
8890 GdkDragContext *context,
8893 GtkSelectionData *selection_data,
8897 GtkEntry *entry = GTK_ENTRY (widget);
8898 GtkEditable *editable = GTK_EDITABLE (widget);
8902 str = (gchar *) gtk_selection_data_get_text (selection_data);
8904 style = gtk_widget_get_style (widget);
8905 x -= style->xthickness;
8906 y -= style->ythickness;
8908 if (str && entry->editable)
8914 if (entry->truncate_multiline)
8915 length = truncate_multiline (str);
8917 new_position = gtk_entry_find_position (entry, x + entry->scroll_offset);
8919 if (!gtk_editable_get_selection_bounds (editable, &sel1, &sel2) ||
8920 new_position < sel1 || new_position > sel2)
8922 gtk_editable_insert_text (editable, str, length, &new_position);
8926 /* Replacing selection */
8927 begin_change (entry);
8928 g_object_freeze_notify (G_OBJECT (entry));
8929 gtk_editable_delete_text (editable, sel1, sel2);
8930 gtk_editable_insert_text (editable, str, length, &sel1);
8931 g_object_thaw_notify (G_OBJECT (entry));
8935 gtk_drag_finish (context, TRUE, context->action == GDK_ACTION_MOVE, time);
8939 /* Drag and drop didn't happen! */
8940 gtk_drag_finish (context, FALSE, FALSE, time);
8947 gtk_entry_drag_data_get (GtkWidget *widget,
8948 GdkDragContext *context,
8949 GtkSelectionData *selection_data,
8953 gint sel_start, sel_end;
8956 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
8957 GtkEditable *editable = GTK_EDITABLE (widget);
8959 /* If there is an icon drag going on, exit early. */
8960 for (i = 0; i < MAX_ICONS; i++)
8962 EntryIconInfo *icon_info = priv->icons[i];
8964 if (icon_info != NULL)
8966 if (icon_info->in_drag)
8971 if (gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end))
8973 gchar *str = gtk_entry_get_display_text (GTK_ENTRY (widget), sel_start, sel_end);
8975 gtk_selection_data_set_text (selection_data, str, -1);
8983 gtk_entry_drag_data_delete (GtkWidget *widget,
8984 GdkDragContext *context)
8986 gint sel_start, sel_end;
8989 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
8990 GtkEditable *editable = GTK_EDITABLE (widget);
8992 /* If there is an icon drag going on, exit early. */
8993 for (i = 0; i < MAX_ICONS; i++)
8995 EntryIconInfo *icon_info = priv->icons[i];
8997 if (icon_info != NULL)
8999 if (icon_info->in_drag)
9004 if (GTK_ENTRY (widget)->editable &&
9005 gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end))
9006 gtk_editable_delete_text (editable, sel_start, sel_end);
9009 /* We display the cursor when
9011 * - the selection is empty, AND
9012 * - the widget has focus
9015 #define CURSOR_ON_MULTIPLIER 2
9016 #define CURSOR_OFF_MULTIPLIER 1
9017 #define CURSOR_PEND_MULTIPLIER 3
9018 #define CURSOR_DIVIDER 3
9021 cursor_blinks (GtkEntry *entry)
9023 if (gtk_widget_has_focus (GTK_WIDGET (entry)) &&
9025 entry->selection_bound == entry->current_pos)
9027 GtkSettings *settings;
9030 settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9031 g_object_get (settings, "gtk-cursor-blink", &blink, NULL);
9040 get_cursor_time (GtkEntry *entry)
9042 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9045 g_object_get (settings, "gtk-cursor-blink-time", &time, NULL);
9051 get_cursor_blink_timeout (GtkEntry *entry)
9053 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9056 g_object_get (settings, "gtk-cursor-blink-timeout", &timeout, NULL);
9062 show_cursor (GtkEntry *entry)
9066 if (!entry->cursor_visible)
9068 entry->cursor_visible = TRUE;
9070 widget = GTK_WIDGET (entry);
9071 if (gtk_widget_has_focus (widget) && entry->selection_bound == entry->current_pos)
9072 gtk_widget_queue_draw (widget);
9077 hide_cursor (GtkEntry *entry)
9081 if (entry->cursor_visible)
9083 entry->cursor_visible = FALSE;
9085 widget = GTK_WIDGET (entry);
9086 if (gtk_widget_has_focus (widget) && entry->selection_bound == entry->current_pos)
9087 gtk_widget_queue_draw (widget);
9095 blink_cb (gpointer data)
9098 GtkEntryPrivate *priv;
9101 entry = GTK_ENTRY (data);
9102 priv = GTK_ENTRY_GET_PRIVATE (entry);
9104 if (!gtk_widget_has_focus (GTK_WIDGET (entry)))
9106 g_warning ("GtkEntry - did not receive focus-out-event. If you\n"
9107 "connect a handler to this signal, it must return\n"
9108 "FALSE so the entry gets the event as well");
9110 gtk_entry_check_cursor_blink (entry);
9115 g_assert (entry->selection_bound == entry->current_pos);
9117 blink_timeout = get_cursor_blink_timeout (entry);
9118 if (priv->blink_time > 1000 * blink_timeout &&
9119 blink_timeout < G_MAXINT/1000)
9121 /* we've blinked enough without the user doing anything, stop blinking */
9122 show_cursor (entry);
9123 entry->blink_timeout = 0;
9125 else if (entry->cursor_visible)
9127 hide_cursor (entry);
9128 entry->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_OFF_MULTIPLIER / CURSOR_DIVIDER,
9134 show_cursor (entry);
9135 priv->blink_time += get_cursor_time (entry);
9136 entry->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
9141 /* Remove ourselves */
9146 gtk_entry_check_cursor_blink (GtkEntry *entry)
9148 GtkEntryPrivate *priv;
9150 priv = GTK_ENTRY_GET_PRIVATE (entry);
9152 if (cursor_blinks (entry))
9154 if (!entry->blink_timeout)
9156 show_cursor (entry);
9157 entry->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
9164 if (entry->blink_timeout)
9166 g_source_remove (entry->blink_timeout);
9167 entry->blink_timeout = 0;
9170 entry->cursor_visible = TRUE;
9176 gtk_entry_pend_cursor_blink (GtkEntry *entry)
9178 if (cursor_blinks (entry))
9180 if (entry->blink_timeout != 0)
9181 g_source_remove (entry->blink_timeout);
9183 entry->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_PEND_MULTIPLIER / CURSOR_DIVIDER,
9186 show_cursor (entry);
9191 gtk_entry_reset_blink_time (GtkEntry *entry)
9193 GtkEntryPrivate *priv;
9195 priv = GTK_ENTRY_GET_PRIVATE (entry);
9197 priv->blink_time = 0;
9203 gtk_entry_completion_timeout (gpointer data)
9205 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (data);
9206 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (completion->priv->entry);
9208 completion->priv->completion_timeout = 0;
9210 if (completion->priv->filter_model &&
9211 g_utf8_strlen (gtk_entry_get_text (GTK_ENTRY (completion->priv->entry)), -1)
9212 >= completion->priv->minimum_key_length)
9216 GtkTreeSelection *s;
9217 gboolean popup_single;
9219 gtk_entry_completion_complete (completion);
9220 matches = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->filter_model), NULL);
9222 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9224 s = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view));
9226 gtk_tree_selection_unselect_all (s);
9228 actions = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->actions), NULL);
9230 g_object_get (completion, "popup-single-match", &popup_single, NULL);
9231 if ((matches > (popup_single ? 0: 1)) || actions > 0)
9233 if (gtk_widget_get_visible (completion->priv->popup_window))
9234 _gtk_entry_completion_resize_popup (completion);
9236 _gtk_entry_completion_popup (completion, priv->completion_device);
9239 _gtk_entry_completion_popdown (completion);
9241 else if (gtk_widget_get_visible (completion->priv->popup_window))
9242 _gtk_entry_completion_popdown (completion);
9247 static inline gboolean
9248 keyval_is_cursor_move (guint keyval)
9250 if (keyval == GDK_KEY_Up || keyval == GDK_KEY_KP_Up)
9253 if (keyval == GDK_KEY_Down || keyval == GDK_KEY_KP_Down)
9256 if (keyval == GDK_KEY_Page_Up)
9259 if (keyval == GDK_KEY_Page_Down)
9266 gtk_entry_completion_key_press (GtkWidget *widget,
9270 gint matches, actions = 0;
9271 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
9273 if (!gtk_widget_get_mapped (completion->priv->popup_window))
9276 matches = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->filter_model), NULL);
9278 if (completion->priv->actions)
9279 actions = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->actions), NULL);
9281 if (keyval_is_cursor_move (event->keyval))
9283 GtkTreePath *path = NULL;
9285 if (event->keyval == GDK_KEY_Up || event->keyval == GDK_KEY_KP_Up)
9287 if (completion->priv->current_selected < 0)
9288 completion->priv->current_selected = matches + actions - 1;
9290 completion->priv->current_selected--;
9292 else if (event->keyval == GDK_KEY_Down || event->keyval == GDK_KEY_KP_Down)
9294 if (completion->priv->current_selected < matches + actions - 1)
9295 completion->priv->current_selected++;
9297 completion->priv->current_selected = -1;
9299 else if (event->keyval == GDK_KEY_Page_Up)
9301 if (completion->priv->current_selected < 0)
9302 completion->priv->current_selected = matches + actions - 1;
9303 else if (completion->priv->current_selected == 0)
9304 completion->priv->current_selected = -1;
9305 else if (completion->priv->current_selected < matches)
9307 completion->priv->current_selected -= 14;
9308 if (completion->priv->current_selected < 0)
9309 completion->priv->current_selected = 0;
9313 completion->priv->current_selected -= 14;
9314 if (completion->priv->current_selected < matches - 1)
9315 completion->priv->current_selected = matches - 1;
9318 else if (event->keyval == GDK_KEY_Page_Down)
9320 if (completion->priv->current_selected < 0)
9321 completion->priv->current_selected = 0;
9322 else if (completion->priv->current_selected < matches - 1)
9324 completion->priv->current_selected += 14;
9325 if (completion->priv->current_selected > matches - 1)
9326 completion->priv->current_selected = matches - 1;
9328 else if (completion->priv->current_selected == matches + actions - 1)
9330 completion->priv->current_selected = -1;
9334 completion->priv->current_selected += 14;
9335 if (completion->priv->current_selected > matches + actions - 1)
9336 completion->priv->current_selected = matches + actions - 1;
9340 if (completion->priv->current_selected < 0)
9342 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9343 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view)));
9345 if (completion->priv->inline_selection &&
9346 completion->priv->completion_prefix)
9348 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9349 completion->priv->completion_prefix);
9350 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9353 else if (completion->priv->current_selected < matches)
9355 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view)));
9357 path = gtk_tree_path_new_from_indices (completion->priv->current_selected, -1);
9358 gtk_tree_view_set_cursor (GTK_TREE_VIEW (completion->priv->tree_view),
9361 if (completion->priv->inline_selection)
9365 GtkTreeIter child_iter;
9366 GtkTreeModel *model = NULL;
9367 GtkTreeSelection *sel;
9370 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view));
9371 if (!gtk_tree_selection_get_selected (sel, &model, &iter))
9374 gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (model), &child_iter, &iter);
9375 model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model));
9377 if (completion->priv->completion_prefix == NULL)
9378 completion->priv->completion_prefix = g_strdup (gtk_entry_get_text (GTK_ENTRY (completion->priv->entry)));
9380 g_signal_emit_by_name (completion, "cursor-on-match", model,
9381 &child_iter, &entry_set);
9384 else if (completion->priv->current_selected - matches >= 0)
9386 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9388 path = gtk_tree_path_new_from_indices (completion->priv->current_selected - matches, -1);
9389 gtk_tree_view_set_cursor (GTK_TREE_VIEW (completion->priv->action_view),
9392 if (completion->priv->inline_selection &&
9393 completion->priv->completion_prefix)
9395 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9396 completion->priv->completion_prefix);
9397 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9401 gtk_tree_path_free (path);
9405 else if (event->keyval == GDK_KEY_Escape ||
9406 event->keyval == GDK_KEY_Left ||
9407 event->keyval == GDK_KEY_KP_Left ||
9408 event->keyval == GDK_KEY_Right ||
9409 event->keyval == GDK_KEY_KP_Right)
9411 gboolean retval = TRUE;
9413 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9414 _gtk_entry_completion_popdown (completion);
9416 if (completion->priv->current_selected < 0)
9419 goto keypress_completion_out;
9421 else if (completion->priv->inline_selection)
9423 /* Escape rejects the tentative completion */
9424 if (event->keyval == GDK_KEY_Escape)
9426 if (completion->priv->completion_prefix)
9427 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9428 completion->priv->completion_prefix);
9430 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry), "");
9433 /* Move the cursor to the end for Right/Esc, to the
9434 beginning for Left */
9435 if (event->keyval == GDK_KEY_Right ||
9436 event->keyval == GDK_KEY_KP_Right ||
9437 event->keyval == GDK_KEY_Escape)
9438 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9440 gtk_editable_set_position (GTK_EDITABLE (widget), 0);
9443 keypress_completion_out:
9444 if (completion->priv->inline_selection)
9446 g_free (completion->priv->completion_prefix);
9447 completion->priv->completion_prefix = NULL;
9452 else if (event->keyval == GDK_KEY_Tab ||
9453 event->keyval == GDK_KEY_KP_Tab ||
9454 event->keyval == GDK_KEY_ISO_Left_Tab)
9456 GtkDirectionType dir = event->keyval == GDK_KEY_ISO_Left_Tab ?
9457 GTK_DIR_TAB_BACKWARD : GTK_DIR_TAB_FORWARD;
9459 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9460 _gtk_entry_completion_popdown (completion);
9462 g_free (completion->priv->completion_prefix);
9463 completion->priv->completion_prefix = NULL;
9465 gtk_widget_child_focus (gtk_widget_get_toplevel (widget), dir);
9469 else if (event->keyval == GDK_KEY_ISO_Enter ||
9470 event->keyval == GDK_KEY_KP_Enter ||
9471 event->keyval == GDK_KEY_Return)
9474 GtkTreeModel *model = NULL;
9475 GtkTreeSelection *sel;
9476 gboolean retval = TRUE;
9478 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9479 _gtk_entry_completion_popdown (completion);
9481 if (completion->priv->current_selected < matches)
9485 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view));
9486 if (gtk_tree_selection_get_selected (sel, &model, &iter))
9488 g_signal_handler_block (widget, completion->priv->changed_id);
9489 g_signal_emit_by_name (completion, "match-selected",
9490 model, &iter, &entry_set);
9491 g_signal_handler_unblock (widget, completion->priv->changed_id);
9497 gtk_tree_model_get (model, &iter,
9498 completion->priv->text_column, &str,
9501 gtk_entry_set_text (GTK_ENTRY (widget), str);
9503 /* move the cursor to the end */
9504 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9512 else if (completion->priv->current_selected - matches >= 0)
9514 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view));
9515 if (gtk_tree_selection_get_selected (sel, &model, &iter))
9519 path = gtk_tree_path_new_from_indices (completion->priv->current_selected - matches, -1);
9520 g_signal_emit_by_name (completion, "action-activated",
9521 gtk_tree_path_get_indices (path)[0]);
9522 gtk_tree_path_free (path);
9528 g_free (completion->priv->completion_prefix);
9529 completion->priv->completion_prefix = NULL;
9538 gtk_entry_completion_changed (GtkWidget *entry,
9541 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
9542 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
9545 /* (re)install completion timeout */
9546 if (completion->priv->completion_timeout)
9547 g_source_remove (completion->priv->completion_timeout);
9549 if (!gtk_entry_get_text (GTK_ENTRY (entry)))
9552 /* no need to normalize for this test */
9553 if (completion->priv->minimum_key_length > 0 &&
9554 strcmp ("", gtk_entry_get_text (GTK_ENTRY (entry))) == 0)
9556 if (gtk_widget_get_visible (completion->priv->popup_window))
9557 _gtk_entry_completion_popdown (completion);
9561 device = gtk_get_current_event_device ();
9563 if (device && device->source == GDK_SOURCE_KEYBOARD)
9564 device = gdk_device_get_associated_device (device);
9567 priv->completion_device = device;
9569 completion->priv->completion_timeout =
9570 gdk_threads_add_timeout (COMPLETION_TIMEOUT,
9571 gtk_entry_completion_timeout,
9576 check_completion_callback (GtkEntryCompletion *completion)
9578 completion->priv->check_completion_idle = NULL;
9580 gtk_entry_completion_complete (completion);
9581 gtk_entry_completion_insert_prefix (completion);
9587 clear_completion_callback (GtkEntry *entry,
9590 if (pspec->name == I_("cursor-position") ||
9591 pspec->name == I_("selection-bound"))
9593 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
9595 completion->priv->has_completion = FALSE;
9600 accept_completion_callback (GtkEntry *entry)
9602 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
9604 if (completion->priv->has_completion)
9605 gtk_editable_set_position (GTK_EDITABLE (entry),
9606 gtk_entry_buffer_get_length (get_buffer (entry)));
9612 completion_insert_text_callback (GtkEntry *entry,
9616 GtkEntryCompletion *completion)
9618 /* idle to update the selection based on the file list */
9619 if (completion->priv->check_completion_idle == NULL)
9621 completion->priv->check_completion_idle = g_idle_source_new ();
9622 g_source_set_priority (completion->priv->check_completion_idle, G_PRIORITY_HIGH);
9623 g_source_set_closure (completion->priv->check_completion_idle,
9624 g_cclosure_new_object (G_CALLBACK (check_completion_callback),
9625 G_OBJECT (completion)));
9626 g_source_attach (completion->priv->check_completion_idle, NULL);
9631 completion_changed (GtkEntryCompletion *completion,
9635 GtkEntry *entry = GTK_ENTRY (data);
9637 if (pspec->name == I_("popup-completion") ||
9638 pspec->name == I_("inline-completion"))
9640 disconnect_completion_signals (entry, completion);
9641 connect_completion_signals (entry, completion);
9646 disconnect_completion_signals (GtkEntry *entry,
9647 GtkEntryCompletion *completion)
9649 g_signal_handlers_disconnect_by_func (completion,
9650 G_CALLBACK (completion_changed), entry);
9651 if (completion->priv->changed_id > 0 &&
9652 g_signal_handler_is_connected (entry, completion->priv->changed_id))
9654 g_signal_handler_disconnect (entry, completion->priv->changed_id);
9655 completion->priv->changed_id = 0;
9657 g_signal_handlers_disconnect_by_func (entry,
9658 G_CALLBACK (gtk_entry_completion_key_press), completion);
9659 if (completion->priv->insert_text_id > 0 &&
9660 g_signal_handler_is_connected (entry, completion->priv->insert_text_id))
9662 g_signal_handler_disconnect (entry, completion->priv->insert_text_id);
9663 completion->priv->insert_text_id = 0;
9665 g_signal_handlers_disconnect_by_func (entry,
9666 G_CALLBACK (completion_insert_text_callback), completion);
9667 g_signal_handlers_disconnect_by_func (entry,
9668 G_CALLBACK (clear_completion_callback), completion);
9669 g_signal_handlers_disconnect_by_func (entry,
9670 G_CALLBACK (accept_completion_callback), completion);
9674 connect_completion_signals (GtkEntry *entry,
9675 GtkEntryCompletion *completion)
9677 if (completion->priv->popup_completion)
9679 completion->priv->changed_id =
9680 g_signal_connect (entry, "changed",
9681 G_CALLBACK (gtk_entry_completion_changed), completion);
9682 g_signal_connect (entry, "key-press-event",
9683 G_CALLBACK (gtk_entry_completion_key_press), completion);
9686 if (completion->priv->inline_completion)
9688 completion->priv->insert_text_id =
9689 g_signal_connect (entry, "insert-text",
9690 G_CALLBACK (completion_insert_text_callback), completion);
9691 g_signal_connect (entry, "notify",
9692 G_CALLBACK (clear_completion_callback), completion);
9693 g_signal_connect (entry, "activate",
9694 G_CALLBACK (accept_completion_callback), completion);
9695 g_signal_connect (entry, "focus-out-event",
9696 G_CALLBACK (accept_completion_callback), completion);
9699 g_signal_connect (completion, "notify",
9700 G_CALLBACK (completion_changed), entry);
9704 * gtk_entry_set_completion:
9705 * @entry: A #GtkEntry
9706 * @completion: (allow-none): The #GtkEntryCompletion or %NULL
9708 * Sets @completion to be the auxiliary completion object to use with @entry.
9709 * All further configuration of the completion mechanism is done on
9710 * @completion using the #GtkEntryCompletion API. Completion is disabled if
9711 * @completion is set to %NULL.
9716 gtk_entry_set_completion (GtkEntry *entry,
9717 GtkEntryCompletion *completion)
9719 GtkEntryCompletion *old;
9721 g_return_if_fail (GTK_IS_ENTRY (entry));
9722 g_return_if_fail (!completion || GTK_IS_ENTRY_COMPLETION (completion));
9724 old = gtk_entry_get_completion (entry);
9726 if (old == completion)
9731 if (old->priv->completion_timeout)
9733 g_source_remove (old->priv->completion_timeout);
9734 old->priv->completion_timeout = 0;
9737 if (gtk_widget_get_mapped (old->priv->popup_window))
9738 _gtk_entry_completion_popdown (old);
9740 disconnect_completion_signals (entry, old);
9741 old->priv->entry = NULL;
9743 g_object_unref (old);
9748 g_object_set_data (G_OBJECT (entry), I_(GTK_ENTRY_COMPLETION_KEY), NULL);
9752 /* hook into the entry */
9753 g_object_ref (completion);
9755 connect_completion_signals (entry, completion);
9756 completion->priv->entry = GTK_WIDGET (entry);
9757 g_object_set_data (G_OBJECT (entry), I_(GTK_ENTRY_COMPLETION_KEY), completion);
9761 * gtk_entry_get_completion:
9762 * @entry: A #GtkEntry
9764 * Returns the auxiliary completion object currently in use by @entry.
9766 * Return value: (transfer none): The auxiliary completion object currently
9771 GtkEntryCompletion *
9772 gtk_entry_get_completion (GtkEntry *entry)
9774 GtkEntryCompletion *completion;
9776 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
9778 completion = GTK_ENTRY_COMPLETION (g_object_get_data (G_OBJECT (entry),
9779 GTK_ENTRY_COMPLETION_KEY));
9785 * gtk_entry_set_cursor_hadjustment:
9786 * @entry: a #GtkEntry
9787 * @adjustment: an adjustment which should be adjusted when the cursor
9788 * is moved, or %NULL
9790 * Hooks up an adjustment to the cursor position in an entry, so that when
9791 * the cursor is moved, the adjustment is scrolled to show that position.
9792 * See gtk_scrolled_window_get_hadjustment() for a typical way of obtaining
9795 * The adjustment has to be in pixel units and in the same coordinate system
9801 gtk_entry_set_cursor_hadjustment (GtkEntry *entry,
9802 GtkAdjustment *adjustment)
9804 g_return_if_fail (GTK_IS_ENTRY (entry));
9806 g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
9809 g_object_ref (adjustment);
9811 g_object_set_qdata_full (G_OBJECT (entry),
9812 quark_cursor_hadjustment,
9818 * gtk_entry_get_cursor_hadjustment:
9819 * @entry: a #GtkEntry
9821 * Retrieves the horizontal cursor adjustment for the entry.
9822 * See gtk_entry_set_cursor_hadjustment().
9824 * Return value: (transfer none): the horizontal cursor adjustment, or %NULL
9825 * if none has been set.
9830 gtk_entry_get_cursor_hadjustment (GtkEntry *entry)
9832 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
9834 return g_object_get_qdata (G_OBJECT (entry), quark_cursor_hadjustment);
9838 * gtk_entry_set_progress_fraction:
9839 * @entry: a #GtkEntry
9840 * @fraction: fraction of the task that's been completed
9842 * Causes the entry's progress indicator to "fill in" the given
9843 * fraction of the bar. The fraction should be between 0.0 and 1.0,
9849 gtk_entry_set_progress_fraction (GtkEntry *entry,
9853 GtkEntryPrivate *private;
9854 gdouble old_fraction;
9855 gint x, y, width, height;
9856 gint old_x, old_y, old_width, old_height;
9858 g_return_if_fail (GTK_IS_ENTRY (entry));
9860 widget = GTK_WIDGET (entry);
9861 private = GTK_ENTRY_GET_PRIVATE (entry);
9863 if (private->progress_pulse_mode)
9866 old_fraction = private->progress_fraction;
9868 if (gtk_widget_is_drawable (widget))
9869 get_progress_area (widget, &old_x, &old_y, &old_width, &old_height);
9871 fraction = CLAMP (fraction, 0.0, 1.0);
9873 private->progress_fraction = fraction;
9874 private->progress_pulse_mode = FALSE;
9875 private->progress_pulse_current = 0.0;
9877 if (gtk_widget_is_drawable (widget))
9879 get_progress_area (widget, &x, &y, &width, &height);
9881 if ((x != old_x) || (y != old_y) || (width != old_width) || (height != old_height))
9882 gtk_widget_queue_draw (widget);
9885 if (fraction != old_fraction)
9886 g_object_notify (G_OBJECT (entry), "progress-fraction");
9890 * gtk_entry_get_progress_fraction:
9891 * @entry: a #GtkEntry
9893 * Returns the current fraction of the task that's been completed.
9894 * See gtk_entry_set_progress_fraction().
9896 * Return value: a fraction from 0.0 to 1.0
9901 gtk_entry_get_progress_fraction (GtkEntry *entry)
9903 GtkEntryPrivate *private;
9905 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
9907 private = GTK_ENTRY_GET_PRIVATE (entry);
9909 return private->progress_fraction;
9913 * gtk_entry_set_progress_pulse_step:
9914 * @entry: a #GtkEntry
9915 * @fraction: fraction between 0.0 and 1.0
9917 * Sets the fraction of total entry width to move the progress
9918 * bouncing block for each call to gtk_entry_progress_pulse().
9923 gtk_entry_set_progress_pulse_step (GtkEntry *entry,
9926 GtkEntryPrivate *private;
9928 g_return_if_fail (GTK_IS_ENTRY (entry));
9930 private = GTK_ENTRY_GET_PRIVATE (entry);
9932 fraction = CLAMP (fraction, 0.0, 1.0);
9934 if (fraction != private->progress_pulse_fraction)
9936 private->progress_pulse_fraction = fraction;
9938 gtk_widget_queue_draw (GTK_WIDGET (entry));
9940 g_object_notify (G_OBJECT (entry), "progress-pulse-step");
9945 * gtk_entry_get_progress_pulse_step:
9946 * @entry: a #GtkEntry
9948 * Retrieves the pulse step set with gtk_entry_set_progress_pulse_step().
9950 * Return value: a fraction from 0.0 to 1.0
9955 gtk_entry_get_progress_pulse_step (GtkEntry *entry)
9957 GtkEntryPrivate *private;
9959 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
9961 private = GTK_ENTRY_GET_PRIVATE (entry);
9963 return private->progress_pulse_fraction;
9967 * gtk_entry_progress_pulse:
9968 * @entry: a #GtkEntry
9970 * Indicates that some progress is made, but you don't know how much.
9971 * Causes the entry's progress indicator to enter "activity mode,"
9972 * where a block bounces back and forth. Each call to
9973 * gtk_entry_progress_pulse() causes the block to move by a little bit
9974 * (the amount of movement per pulse is determined by
9975 * gtk_entry_set_progress_pulse_step()).
9980 gtk_entry_progress_pulse (GtkEntry *entry)
9982 GtkEntryPrivate *private;
9984 g_return_if_fail (GTK_IS_ENTRY (entry));
9986 private = GTK_ENTRY_GET_PRIVATE (entry);
9988 if (private->progress_pulse_mode)
9990 if (private->progress_pulse_way_back)
9992 private->progress_pulse_current -= private->progress_pulse_fraction;
9994 if (private->progress_pulse_current < 0.0)
9996 private->progress_pulse_current = 0.0;
9997 private->progress_pulse_way_back = FALSE;
10002 private->progress_pulse_current += private->progress_pulse_fraction;
10004 if (private->progress_pulse_current > 1.0 - private->progress_pulse_fraction)
10006 private->progress_pulse_current = 1.0 - private->progress_pulse_fraction;
10007 private->progress_pulse_way_back = TRUE;
10013 private->progress_fraction = 0.0;
10014 private->progress_pulse_mode = TRUE;
10015 private->progress_pulse_way_back = FALSE;
10016 private->progress_pulse_current = 0.0;
10019 gtk_widget_queue_draw (GTK_WIDGET (entry));
10022 /* Caps Lock warning for password entries */
10025 show_capslock_feedback (GtkEntry *entry,
10028 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
10030 if (gtk_entry_get_icon_storage_type (entry, GTK_ENTRY_ICON_SECONDARY) == GTK_IMAGE_EMPTY)
10032 gtk_entry_set_icon_from_stock (entry, GTK_ENTRY_ICON_SECONDARY, GTK_STOCK_CAPS_LOCK_WARNING);
10033 gtk_entry_set_icon_activatable (entry, GTK_ENTRY_ICON_SECONDARY, FALSE);
10034 priv->caps_lock_warning_shown = TRUE;
10037 if (priv->caps_lock_warning_shown)
10038 gtk_entry_set_icon_tooltip_text (entry, GTK_ENTRY_ICON_SECONDARY, text);
10040 g_warning ("Can't show Caps Lock warning, since secondary icon is set");
10044 remove_capslock_feedback (GtkEntry *entry)
10046 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
10048 if (priv->caps_lock_warning_shown)
10050 gtk_entry_set_icon_from_stock (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
10051 priv->caps_lock_warning_shown = FALSE;
10056 keymap_state_changed (GdkKeymap *keymap,
10059 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
10062 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL && priv->caps_lock_warning)
10064 if (gdk_keymap_get_num_lock_state (keymap)
10065 && gdk_keymap_get_caps_lock_state (keymap))
10066 text = _("Caps Lock and Num Lock are on");
10067 else if (gdk_keymap_get_num_lock_state (keymap))
10068 text = _("Num Lock is on");
10069 else if (gdk_keymap_get_caps_lock_state (keymap))
10070 text = _("Caps Lock is on");
10074 show_capslock_feedback (entry, text);
10076 remove_capslock_feedback (entry);