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 "gtkimagemenuitem.h"
44 #include "gtkimcontextsimple.h"
45 #include "gtkimmulticontext.h"
49 #include "gtkmarshalers.h"
51 #include "gtkmenuitem.h"
52 #include "gtkseparatormenuitem.h"
53 #include "gtkselection.h"
54 #include "gtksettings.h"
55 #include "gtkspinbutton.h"
57 #include "gtktextutil.h"
58 #include "gtkwindow.h"
59 #include "gtktreeview.h"
60 #include "gtktreeselection.h"
61 #include "gtkprivate.h"
62 #include "gtkentryprivate.h"
63 #include "gtkcelllayout.h"
64 #include "gtktooltip.h"
65 #include "gtkiconfactory.h"
66 #include "gtkicontheme.h"
69 #define GTK_ENTRY_COMPLETION_KEY "gtk-entry-completion-key"
71 #define MIN_ENTRY_WIDTH 150
72 #define DRAW_TIMEOUT 20
73 #define COMPLETION_TIMEOUT 300
74 #define PASSWORD_HINT_MAX 8
76 /* Initial size of buffer, in bytes */
79 /* Maximum size of text buffer, in bytes */
80 #define MAX_SIZE G_MAXUSHORT
84 #define IS_VALID_ICON_POSITION(pos) \
85 ((pos) == GTK_ENTRY_ICON_PRIMARY || \
86 (pos) == GTK_ENTRY_ICON_SECONDARY)
88 static const GtkBorder default_inner_border = { 2, 2, 2, 2 };
89 static GQuark quark_inner_border = 0;
90 static GQuark quark_password_hint = 0;
91 static GQuark quark_cursor_hadjustment = 0;
92 static GQuark quark_capslock_feedback = 0;
94 typedef struct _GtkEntryPrivate GtkEntryPrivate;
96 #define GTK_ENTRY_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_ENTRY, GtkEntryPrivate))
102 guint insensitive : 1;
103 guint nonactivatable : 1;
108 GtkImageType storage_type;
114 GtkTargetList *target_list;
115 GdkDragAction actions;
118 struct _GtkEntryPrivate
122 guint blink_time; /* time in msec the cursor has blinked since last user event */
123 guint interior_focus : 1;
124 guint real_changed : 1;
125 guint invisible_char_set : 1;
126 guint caps_lock_warning : 1;
127 guint caps_lock_warning_shown : 1;
128 guint change_count : 8;
129 guint progress_pulse_mode : 1;
130 guint progress_pulse_way_back : 1;
133 GtkShadowType shadow_type;
135 gdouble progress_fraction;
136 gdouble progress_pulse_fraction;
137 gdouble progress_pulse_current;
139 EntryIconInfo *icons[MAX_ICONS];
147 typedef struct _GtkEntryPasswordHint GtkEntryPasswordHint;
149 struct _GtkEntryPasswordHint
151 gchar password_hint[PASSWORD_HINT_MAX];
152 guint password_hint_timeout_id;
153 gint password_hint_length;
154 gint password_hint_position;
157 typedef struct _GtkEntryCapslockFeedback GtkEntryCapslockFeedback;
159 struct _GtkEntryCapslockFeedback
184 PROP_CURSOR_POSITION,
185 PROP_SELECTION_BOUND,
192 PROP_ACTIVATES_DEFAULT,
197 PROP_TRUNCATE_MULTILINE,
201 PROP_INVISIBLE_CHAR_SET,
202 PROP_CAPS_LOCK_WARNING,
203 PROP_PROGRESS_FRACTION,
204 PROP_PROGRESS_PULSE_STEP,
206 PROP_PIXBUF_SECONDARY,
208 PROP_STOCK_SECONDARY,
209 PROP_ICON_NAME_PRIMARY,
210 PROP_ICON_NAME_SECONDARY,
212 PROP_GICON_SECONDARY,
213 PROP_STORAGE_TYPE_PRIMARY,
214 PROP_STORAGE_TYPE_SECONDARY,
215 PROP_ACTIVATABLE_PRIMARY,
216 PROP_ACTIVATABLE_SECONDARY,
217 PROP_SENSITIVE_PRIMARY,
218 PROP_SENSITIVE_SECONDARY,
222 static guint signals[LAST_SIGNAL] = { 0 };
229 /* GObject, GtkObject methods
231 static void gtk_entry_editable_init (GtkEditableClass *iface);
232 static void gtk_entry_cell_editable_init (GtkCellEditableIface *iface);
233 static void gtk_entry_set_property (GObject *object,
237 static void gtk_entry_get_property (GObject *object,
241 static void gtk_entry_finalize (GObject *object);
242 static void gtk_entry_destroy (GtkObject *object);
243 static void gtk_entry_dispose (GObject *object);
247 static void gtk_entry_realize (GtkWidget *widget);
248 static void gtk_entry_unrealize (GtkWidget *widget);
249 static void gtk_entry_map (GtkWidget *widget);
250 static void gtk_entry_unmap (GtkWidget *widget);
251 static void gtk_entry_size_request (GtkWidget *widget,
252 GtkRequisition *requisition);
253 static void gtk_entry_size_allocate (GtkWidget *widget,
254 GtkAllocation *allocation);
255 static void gtk_entry_draw_frame (GtkWidget *widget,
257 static void gtk_entry_draw_progress (GtkWidget *widget,
258 GdkEventExpose *event);
259 static gint gtk_entry_expose (GtkWidget *widget,
260 GdkEventExpose *event);
261 static gint gtk_entry_button_press (GtkWidget *widget,
262 GdkEventButton *event);
263 static gint gtk_entry_button_release (GtkWidget *widget,
264 GdkEventButton *event);
265 static gint gtk_entry_enter_notify (GtkWidget *widget,
266 GdkEventCrossing *event);
267 static gint gtk_entry_leave_notify (GtkWidget *widget,
268 GdkEventCrossing *event);
269 static gint gtk_entry_motion_notify (GtkWidget *widget,
270 GdkEventMotion *event);
271 static gint gtk_entry_key_press (GtkWidget *widget,
273 static gint gtk_entry_key_release (GtkWidget *widget,
275 static gint gtk_entry_focus_in (GtkWidget *widget,
276 GdkEventFocus *event);
277 static gint gtk_entry_focus_out (GtkWidget *widget,
278 GdkEventFocus *event);
279 static void gtk_entry_grab_focus (GtkWidget *widget);
280 static void gtk_entry_style_set (GtkWidget *widget,
281 GtkStyle *previous_style);
282 static gboolean gtk_entry_query_tooltip (GtkWidget *widget,
285 gboolean keyboard_tip,
286 GtkTooltip *tooltip);
287 static void gtk_entry_direction_changed (GtkWidget *widget,
288 GtkTextDirection previous_dir);
289 static void gtk_entry_state_changed (GtkWidget *widget,
290 GtkStateType previous_state);
291 static void gtk_entry_screen_changed (GtkWidget *widget,
292 GdkScreen *old_screen);
294 static gboolean gtk_entry_drag_drop (GtkWidget *widget,
295 GdkDragContext *context,
299 static gboolean gtk_entry_drag_motion (GtkWidget *widget,
300 GdkDragContext *context,
304 static void gtk_entry_drag_leave (GtkWidget *widget,
305 GdkDragContext *context,
307 static void gtk_entry_drag_data_received (GtkWidget *widget,
308 GdkDragContext *context,
311 GtkSelectionData *selection_data,
314 static void gtk_entry_drag_data_get (GtkWidget *widget,
315 GdkDragContext *context,
316 GtkSelectionData *selection_data,
319 static void gtk_entry_drag_data_delete (GtkWidget *widget,
320 GdkDragContext *context);
321 static void gtk_entry_drag_begin (GtkWidget *widget,
322 GdkDragContext *context);
323 static void gtk_entry_drag_end (GtkWidget *widget,
324 GdkDragContext *context);
327 /* GtkEditable method implementations
329 static void gtk_entry_insert_text (GtkEditable *editable,
330 const gchar *new_text,
331 gint new_text_length,
333 static void gtk_entry_delete_text (GtkEditable *editable,
336 static gchar * gtk_entry_get_chars (GtkEditable *editable,
339 static void gtk_entry_real_set_position (GtkEditable *editable,
341 static gint gtk_entry_get_position (GtkEditable *editable);
342 static void gtk_entry_set_selection_bounds (GtkEditable *editable,
345 static gboolean gtk_entry_get_selection_bounds (GtkEditable *editable,
349 /* GtkCellEditable method implementations
351 static void gtk_entry_start_editing (GtkCellEditable *cell_editable,
354 /* Default signal handlers
356 static void gtk_entry_real_insert_text (GtkEditable *editable,
357 const gchar *new_text,
358 gint new_text_length,
360 static void gtk_entry_real_delete_text (GtkEditable *editable,
363 static void gtk_entry_move_cursor (GtkEntry *entry,
364 GtkMovementStep step,
366 gboolean extend_selection);
367 static void gtk_entry_insert_at_cursor (GtkEntry *entry,
369 static void gtk_entry_delete_from_cursor (GtkEntry *entry,
372 static void gtk_entry_backspace (GtkEntry *entry);
373 static void gtk_entry_cut_clipboard (GtkEntry *entry);
374 static void gtk_entry_copy_clipboard (GtkEntry *entry);
375 static void gtk_entry_paste_clipboard (GtkEntry *entry);
376 static void gtk_entry_toggle_overwrite (GtkEntry *entry);
377 static void gtk_entry_select_all (GtkEntry *entry);
378 static void gtk_entry_real_activate (GtkEntry *entry);
379 static gboolean gtk_entry_popup_menu (GtkWidget *widget);
381 static void keymap_direction_changed (GdkKeymap *keymap,
383 static void keymap_state_changed (GdkKeymap *keymap,
385 static void remove_capslock_feedback (GtkEntry *entry);
387 /* IM Context Callbacks
389 static void gtk_entry_commit_cb (GtkIMContext *context,
392 static void gtk_entry_preedit_changed_cb (GtkIMContext *context,
394 static gboolean gtk_entry_retrieve_surrounding_cb (GtkIMContext *context,
396 static gboolean gtk_entry_delete_surrounding_cb (GtkIMContext *context,
403 static void gtk_entry_enter_text (GtkEntry *entry,
405 static void gtk_entry_set_positions (GtkEntry *entry,
407 gint selection_bound);
408 static void gtk_entry_draw_text (GtkEntry *entry);
409 static void gtk_entry_draw_cursor (GtkEntry *entry,
411 static PangoLayout *gtk_entry_ensure_layout (GtkEntry *entry,
412 gboolean include_preedit);
413 static void gtk_entry_reset_layout (GtkEntry *entry);
414 static void gtk_entry_queue_draw (GtkEntry *entry);
415 static void gtk_entry_recompute (GtkEntry *entry);
416 static gint gtk_entry_find_position (GtkEntry *entry,
418 static void gtk_entry_get_cursor_locations (GtkEntry *entry,
422 static void gtk_entry_adjust_scroll (GtkEntry *entry);
423 static gint gtk_entry_move_visually (GtkEntry *editable,
426 static gint gtk_entry_move_logically (GtkEntry *entry,
429 static gint gtk_entry_move_forward_word (GtkEntry *entry,
431 gboolean allow_whitespace);
432 static gint gtk_entry_move_backward_word (GtkEntry *entry,
434 gboolean allow_whitespace);
435 static void gtk_entry_delete_whitespace (GtkEntry *entry);
436 static void gtk_entry_select_word (GtkEntry *entry);
437 static void gtk_entry_select_line (GtkEntry *entry);
438 static char * gtk_entry_get_public_chars (GtkEntry *entry,
441 static void gtk_entry_paste (GtkEntry *entry,
443 static void gtk_entry_update_primary_selection (GtkEntry *entry);
444 static void gtk_entry_do_popup (GtkEntry *entry,
445 GdkEventButton *event);
446 static gboolean gtk_entry_mnemonic_activate (GtkWidget *widget,
447 gboolean group_cycling);
448 static void gtk_entry_state_changed (GtkWidget *widget,
449 GtkStateType previous_state);
450 static void gtk_entry_check_cursor_blink (GtkEntry *entry);
451 static void gtk_entry_pend_cursor_blink (GtkEntry *entry);
452 static void gtk_entry_reset_blink_time (GtkEntry *entry);
453 static void gtk_entry_get_text_area_size (GtkEntry *entry,
458 static void get_widget_window_size (GtkEntry *entry,
463 static void gtk_entry_move_adjustments (GtkEntry *entry);
464 static void gtk_entry_ensure_pixbuf (GtkEntry *entry,
465 GtkEntryIconPosition icon_pos);
469 static gint gtk_entry_completion_timeout (gpointer data);
470 static gboolean gtk_entry_completion_key_press (GtkWidget *widget,
473 static void gtk_entry_completion_changed (GtkWidget *entry,
475 static gboolean check_completion_callback (GtkEntryCompletion *completion);
476 static void clear_completion_callback (GtkEntry *entry,
478 static gboolean accept_completion_callback (GtkEntry *entry);
479 static void completion_insert_text_callback (GtkEntry *entry,
483 GtkEntryCompletion *completion);
484 static void completion_changed (GtkEntryCompletion *completion,
487 static void disconnect_completion_signals (GtkEntry *entry,
488 GtkEntryCompletion *completion);
489 static void connect_completion_signals (GtkEntry *entry,
490 GtkEntryCompletion *completion);
492 static void begin_change (GtkEntry *entry);
493 static void end_change (GtkEntry *entry);
494 static void emit_changed (GtkEntry *entry);
497 G_DEFINE_TYPE_WITH_CODE (GtkEntry, gtk_entry, GTK_TYPE_WIDGET,
498 G_IMPLEMENT_INTERFACE (GTK_TYPE_EDITABLE,
499 gtk_entry_editable_init)
500 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_EDITABLE,
501 gtk_entry_cell_editable_init))
504 add_move_binding (GtkBindingSet *binding_set,
507 GtkMovementStep step,
510 g_return_if_fail ((modmask & GDK_SHIFT_MASK) == 0);
512 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
516 G_TYPE_BOOLEAN, FALSE);
518 /* Selection-extending version */
519 gtk_binding_entry_add_signal (binding_set, keyval, modmask | GDK_SHIFT_MASK,
523 G_TYPE_BOOLEAN, TRUE);
527 gtk_entry_class_init (GtkEntryClass *class)
529 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
530 GtkWidgetClass *widget_class;
531 GtkObjectClass *gtk_object_class;
532 GtkBindingSet *binding_set;
534 widget_class = (GtkWidgetClass*) class;
535 gtk_object_class = (GtkObjectClass *)class;
537 gobject_class->dispose = gtk_entry_dispose;
538 gobject_class->finalize = gtk_entry_finalize;
539 gobject_class->set_property = gtk_entry_set_property;
540 gobject_class->get_property = gtk_entry_get_property;
542 widget_class->map = gtk_entry_map;
543 widget_class->unmap = gtk_entry_unmap;
544 widget_class->realize = gtk_entry_realize;
545 widget_class->unrealize = gtk_entry_unrealize;
546 widget_class->size_request = gtk_entry_size_request;
547 widget_class->size_allocate = gtk_entry_size_allocate;
548 widget_class->expose_event = gtk_entry_expose;
549 widget_class->enter_notify_event = gtk_entry_enter_notify;
550 widget_class->leave_notify_event = gtk_entry_leave_notify;
551 widget_class->button_press_event = gtk_entry_button_press;
552 widget_class->button_release_event = gtk_entry_button_release;
553 widget_class->motion_notify_event = gtk_entry_motion_notify;
554 widget_class->key_press_event = gtk_entry_key_press;
555 widget_class->key_release_event = gtk_entry_key_release;
556 widget_class->focus_in_event = gtk_entry_focus_in;
557 widget_class->focus_out_event = gtk_entry_focus_out;
558 widget_class->grab_focus = gtk_entry_grab_focus;
559 widget_class->style_set = gtk_entry_style_set;
560 widget_class->query_tooltip = gtk_entry_query_tooltip;
561 widget_class->drag_begin = gtk_entry_drag_begin;
562 widget_class->drag_end = gtk_entry_drag_end;
563 widget_class->direction_changed = gtk_entry_direction_changed;
564 widget_class->state_changed = gtk_entry_state_changed;
565 widget_class->screen_changed = gtk_entry_screen_changed;
566 widget_class->mnemonic_activate = gtk_entry_mnemonic_activate;
568 widget_class->drag_drop = gtk_entry_drag_drop;
569 widget_class->drag_motion = gtk_entry_drag_motion;
570 widget_class->drag_leave = gtk_entry_drag_leave;
571 widget_class->drag_data_received = gtk_entry_drag_data_received;
572 widget_class->drag_data_get = gtk_entry_drag_data_get;
573 widget_class->drag_data_delete = gtk_entry_drag_data_delete;
575 widget_class->popup_menu = gtk_entry_popup_menu;
577 gtk_object_class->destroy = gtk_entry_destroy;
579 class->move_cursor = gtk_entry_move_cursor;
580 class->insert_at_cursor = gtk_entry_insert_at_cursor;
581 class->delete_from_cursor = gtk_entry_delete_from_cursor;
582 class->backspace = gtk_entry_backspace;
583 class->cut_clipboard = gtk_entry_cut_clipboard;
584 class->copy_clipboard = gtk_entry_copy_clipboard;
585 class->paste_clipboard = gtk_entry_paste_clipboard;
586 class->toggle_overwrite = gtk_entry_toggle_overwrite;
587 class->activate = gtk_entry_real_activate;
588 class->get_text_area_size = gtk_entry_get_text_area_size;
590 quark_inner_border = g_quark_from_static_string ("gtk-entry-inner-border");
591 quark_password_hint = g_quark_from_static_string ("gtk-entry-password-hint");
592 quark_cursor_hadjustment = g_quark_from_static_string ("gtk-hadjustment");
593 quark_capslock_feedback = g_quark_from_static_string ("gtk-entry-capslock-feedback");
595 g_object_class_install_property (gobject_class,
596 PROP_CURSOR_POSITION,
597 g_param_spec_int ("cursor-position",
598 P_("Cursor Position"),
599 P_("The current position of the insertion cursor in chars"),
603 GTK_PARAM_READABLE));
605 g_object_class_install_property (gobject_class,
606 PROP_SELECTION_BOUND,
607 g_param_spec_int ("selection-bound",
608 P_("Selection Bound"),
609 P_("The position of the opposite end of the selection from the cursor in chars"),
613 GTK_PARAM_READABLE));
615 g_object_class_install_property (gobject_class,
617 g_param_spec_boolean ("editable",
619 P_("Whether the entry contents can be edited"),
621 GTK_PARAM_READWRITE));
623 g_object_class_install_property (gobject_class,
625 g_param_spec_int ("max-length",
626 P_("Maximum length"),
627 P_("Maximum number of characters for this entry. Zero if no maximum"),
631 GTK_PARAM_READWRITE));
632 g_object_class_install_property (gobject_class,
634 g_param_spec_boolean ("visibility",
636 P_("FALSE displays the \"invisible char\" instead of the actual text (password mode)"),
638 GTK_PARAM_READWRITE));
640 g_object_class_install_property (gobject_class,
642 g_param_spec_boolean ("has-frame",
644 P_("FALSE removes outside bevel from entry"),
646 GTK_PARAM_READWRITE));
648 g_object_class_install_property (gobject_class,
650 g_param_spec_boxed ("inner-border",
652 P_("Border between text and frame. Overrides the inner-border style property"),
654 GTK_PARAM_READWRITE));
656 g_object_class_install_property (gobject_class,
658 g_param_spec_unichar ("invisible-char",
659 P_("Invisible character"),
660 P_("The character to use when masking entry contents (in \"password mode\")"),
662 GTK_PARAM_READWRITE));
664 g_object_class_install_property (gobject_class,
665 PROP_ACTIVATES_DEFAULT,
666 g_param_spec_boolean ("activates-default",
667 P_("Activates default"),
668 P_("Whether to activate the default widget (such as the default button in a dialog) when Enter is pressed"),
670 GTK_PARAM_READWRITE));
671 g_object_class_install_property (gobject_class,
673 g_param_spec_int ("width-chars",
674 P_("Width in chars"),
675 P_("Number of characters to leave space for in the entry"),
679 GTK_PARAM_READWRITE));
681 g_object_class_install_property (gobject_class,
683 g_param_spec_int ("scroll-offset",
685 P_("Number of pixels of the entry scrolled off the screen to the left"),
689 GTK_PARAM_READABLE));
691 g_object_class_install_property (gobject_class,
693 g_param_spec_string ("text",
695 P_("The contents of the entry"),
697 GTK_PARAM_READWRITE));
702 * The horizontal alignment, from 0 (left) to 1 (right).
703 * Reversed for RTL layouts.
707 g_object_class_install_property (gobject_class,
709 g_param_spec_float ("xalign",
711 P_("The horizontal alignment, from 0 (left) to 1 (right). Reversed for RTL layouts."),
715 GTK_PARAM_READWRITE));
718 * GtkEntry:truncate-multiline:
720 * When %TRUE, pasted multi-line text is truncated to the first line.
724 g_object_class_install_property (gobject_class,
725 PROP_TRUNCATE_MULTILINE,
726 g_param_spec_boolean ("truncate-multiline",
727 P_("Truncate multiline"),
728 P_("Whether to truncate multiline pastes to one line."),
730 GTK_PARAM_READWRITE));
733 * GtkEntry:shadow-type:
735 * Which kind of shadow to draw around the entry when
736 * #GtkEntry:has-frame is set to %TRUE.
740 g_object_class_install_property (gobject_class,
742 g_param_spec_enum ("shadow-type",
744 P_("Which kind of shadow to draw around the entry when has-frame is set"),
745 GTK_TYPE_SHADOW_TYPE,
747 GTK_PARAM_READWRITE));
750 * GtkEntry:overwrite-mode:
752 * If text is overwritten when typing in the #GtkEntry.
756 g_object_class_install_property (gobject_class,
758 g_param_spec_boolean ("overwrite-mode",
759 P_("Overwrite mode"),
760 P_("Whether new text overwrites existing text"),
762 GTK_PARAM_READWRITE));
765 * GtkEntry:text-length:
767 * The length of the text in the #GtkEntry.
771 g_object_class_install_property (gobject_class,
773 g_param_spec_uint ("text-length",
775 P_("Length of the text currently in the entry"),
779 GTK_PARAM_READABLE));
781 * GtkEntry:invisible-char-set:
783 * Whether the invisible char has been set for the #GtkEntry.
787 g_object_class_install_property (gobject_class,
788 PROP_INVISIBLE_CHAR_SET,
789 g_param_spec_boolean ("invisible-char-set",
790 P_("Invisible char set"),
791 P_("Whether the invisible char has been set"),
793 GTK_PARAM_READWRITE));
796 * GtkEntry:caps-lock-warning
798 * Whether password entries will show a warning when Caps Lock is on
799 * or an input method is active.
801 * Note that the warning is shown using a secondary icon, and thus
802 * does not work if you are using the secondary icon position for some
807 g_object_class_install_property (gobject_class,
808 PROP_CAPS_LOCK_WARNING,
809 g_param_spec_boolean ("caps-lock-warning",
810 P_("Caps Lock warning"),
811 P_("Whether password entries will show a warning when Caps Lock is on or an input method is active"),
813 GTK_PARAM_READWRITE));
816 * GtkEntry:progress-fraction:
818 * The current fraction of the task that's been completed.
822 g_object_class_install_property (gobject_class,
823 PROP_PROGRESS_FRACTION,
824 g_param_spec_double ("progress-fraction",
825 P_("Progress Fraction"),
826 P_("The current fraction of the task that's been completed"),
830 GTK_PARAM_READWRITE));
833 * GtkEntry:progress-pulse-step:
835 * The fraction of total entry width to move the progress
836 * bouncing block for each call to gtk_entry_progress_pulse().
840 g_object_class_install_property (gobject_class,
841 PROP_PROGRESS_PULSE_STEP,
842 g_param_spec_double ("progress-pulse-step",
843 P_("Progress Pulse Step"),
844 P_("The fraction of total entry width to move the progress bouncing block for each call to gtk_entry_progress_pulse()"),
848 GTK_PARAM_READWRITE));
851 * GtkEntry:pixbuf-primary:
853 * A pixbuf to use as the primary icon for the entry.
857 g_object_class_install_property (gobject_class,
859 g_param_spec_object ("pixbuf-primary",
860 P_("Primary pixbuf"),
861 P_("Primary pixbuf for the entry"),
863 GTK_PARAM_READWRITE));
866 * GtkEntry:pixbuf-secondary:
868 * An pixbuf to use as the secondary icon for the entry.
872 g_object_class_install_property (gobject_class,
873 PROP_PIXBUF_SECONDARY,
874 g_param_spec_object ("pixbuf-secondary",
875 P_("Secondary pixbuf"),
876 P_("Secondary pixbuf for the entry"),
878 GTK_PARAM_READWRITE));
881 * GtkEntry:stock-primary:
883 * The stock id to use for the primary icon for the entry.
887 g_object_class_install_property (gobject_class,
889 g_param_spec_string ("stock-primary",
890 P_("Primary stock ID"),
891 P_("Stock ID for primary icon"),
893 GTK_PARAM_READWRITE));
896 * GtkEntry:stock-secondary:
898 * The stock id to use for the secondary icon for the entry.
902 g_object_class_install_property (gobject_class,
903 PROP_STOCK_SECONDARY,
904 g_param_spec_string ("stock-secondary",
905 P_("Secondary stock ID"),
906 P_("Stock ID for secondary icon"),
908 GTK_PARAM_READWRITE));
911 * GtkEntry:icon-name-primary:
913 * The icon name to use for the primary icon for the entry.
917 g_object_class_install_property (gobject_class,
918 PROP_ICON_NAME_PRIMARY,
919 g_param_spec_string ("icon-name-primary",
920 P_("Primary icon name"),
921 P_("Icon name for primary icon"),
923 GTK_PARAM_READWRITE));
926 * GtkEntry:icon-name-secondary:
928 * The icon name to use for the secondary icon for the entry.
932 g_object_class_install_property (gobject_class,
933 PROP_ICON_NAME_SECONDARY,
934 g_param_spec_string ("icon-name-secondary",
935 P_("Secondary icon name"),
936 P_("Icon name for secondary icon"),
938 GTK_PARAM_READWRITE));
941 * GtkEntry:gicon-primary:
943 * The #GIcon to use for the primary icon for the entry.
947 g_object_class_install_property (gobject_class,
949 g_param_spec_object ("gicon-primary",
951 P_("GIcon for primary icon"),
953 GTK_PARAM_READWRITE));
956 * GtkEntry:gicon-secondary:
958 * The #GIcon to use for the secondary icon for the entry.
962 g_object_class_install_property (gobject_class,
963 PROP_GICON_SECONDARY,
964 g_param_spec_object ("gicon-secondary",
965 P_("Secondary GIcon"),
966 P_("GIcon for secondary icon"),
968 GTK_PARAM_READWRITE));
971 * GtkEntry:storage-type-primary:
973 * The representation which is used for the primary icon of the entry.
977 g_object_class_install_property (gobject_class,
978 PROP_STORAGE_TYPE_PRIMARY,
979 g_param_spec_enum ("storage-type-primary",
980 P_("Primary storage type"),
981 P_("The representation being used for primary icon"),
984 GTK_PARAM_READABLE));
987 * GtkEntry:storage-type-secondary:
989 * The representation which is used for the secondary icon of the entry.
993 g_object_class_install_property (gobject_class,
994 PROP_STORAGE_TYPE_SECONDARY,
995 g_param_spec_enum ("storage-type-secondary",
996 P_("Secondary storage type"),
997 P_("The representation being used for secondary icon"),
1000 GTK_PARAM_READABLE));
1003 * GtkEntry:activatable-primary:
1005 * Whether the primary icon is activatable.
1007 * GTK+ emits the #GtkEntry::icon-press and #GtkEntry::icon-release
1008 * signals only on sensitive, activatable icons.
1010 * Sensitive, but non-activatable icons can be used for purely
1011 * informational purposes.
1015 g_object_class_install_property (gobject_class,
1016 PROP_ACTIVATABLE_PRIMARY,
1017 g_param_spec_boolean ("activatable-primary",
1018 P_("Primary icon activatable"),
1019 P_("Whether the primary icon is activatable"),
1021 GTK_PARAM_READWRITE));
1024 * GtkEntry:activatable-secondary:
1026 * Whether the secondary icon is activatable.
1028 * GTK+ emits the #GtkEntry::icon-press and #GtkEntry::icon-release
1029 * signals only on sensitive, activatable icons.
1031 * Sensitive, but non-activatable icons can be used for purely
1032 * informational purposes.
1036 g_object_class_install_property (gobject_class,
1037 PROP_ACTIVATABLE_SECONDARY,
1038 g_param_spec_boolean ("activatable-secondary",
1039 P_("Secondary icon activatable"),
1040 P_("Whether the secondary icon is activatable"),
1042 GTK_PARAM_READWRITE));
1046 * GtkEntry:sensitive-primary:
1048 * Whether the primary icon is sensitive.
1050 * An insensitive icon appears grayed out. GTK+ does not emit the
1051 * #GtkEntry::icon-press and #GtkEntry::icon-release signals and
1052 * does not allow DND from insensitive icons.
1054 * An icon should be set insensitive if the action that would trigger
1055 * when clicked is currently not available.
1059 g_object_class_install_property (gobject_class,
1060 PROP_SENSITIVE_PRIMARY,
1061 g_param_spec_boolean ("sensitive-primary",
1062 P_("Primary icon sensitive"),
1063 P_("Whether the primary icon is sensitive"),
1065 GTK_PARAM_READWRITE));
1068 * GtkEntry:sensitive-secondary:
1070 * Whether the secondary icon is sensitive.
1072 * An insensitive icon appears grayed out. GTK+ does not emit the
1073 * #GtkEntry::icon-press and #GtkEntry::icon-release signals and
1074 * does not allow DND from insensitive icons.
1076 * An icon should be set insensitive if the action that would trigger
1077 * when clicked is currently not available.
1081 g_object_class_install_property (gobject_class,
1082 PROP_SENSITIVE_SECONDARY,
1083 g_param_spec_boolean ("sensitive-secondary",
1084 P_("Secondary icon sensitive"),
1085 P_("Whether the secondary icon is sensitive"),
1087 GTK_PARAM_READWRITE));
1090 * GtkEntry:im-module:
1092 * Which IM module should be used for this entry.
1094 * Setting this to a non-%NULL value overrides the
1095 * system-wide IM module setting. See #GtkSettings:gtk-im-module
1099 g_object_class_install_property (gobject_class,
1101 g_param_spec_string ("im-module",
1103 P_("Which IM module should be used"),
1105 GTK_PARAM_READWRITE));
1108 * GtkEntry:prelight:
1110 * The prelight style property determines whether activatable
1111 * icons prelight on mouseover.
1115 gtk_widget_class_install_style_property (widget_class,
1116 g_param_spec_boolean ("prelight",
1118 P_("Whether activatable icons should prelight when hovered"),
1120 GTK_PARAM_READABLE));
1123 * GtkEntry::populate-popup:
1124 * @entry: The entry on which the signal is emitted
1125 * @menu: the menu that is being populated
1127 * The ::populate-popup signal gets emitted before showing the
1128 * context menu of the entry.
1130 * If you need to add items to the context menu, connect
1131 * to this signal and append your menuitems to the @menu.
1133 signals[POPULATE_POPUP] =
1134 g_signal_new (I_("populate-popup"),
1135 G_OBJECT_CLASS_TYPE (gobject_class),
1137 G_STRUCT_OFFSET (GtkEntryClass, populate_popup),
1139 _gtk_marshal_VOID__OBJECT,
1143 /* Action signals */
1146 * GtkEntry::activate:
1147 * @entry: The entry on which the signal is emitted
1149 * A <link linkend="keybinding-signals">keybinding signal</link>
1150 * which gets emitted when the user activates the entry.
1152 * Applications should not connect to it, but may emit it with
1153 * g_signal_emit_by_name() if they need to control scrolling
1156 * The default bindings for this signal are all forms of the Enter key.
1159 g_signal_new (I_("activate"),
1160 G_OBJECT_CLASS_TYPE (gobject_class),
1161 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1162 G_STRUCT_OFFSET (GtkEntryClass, activate),
1164 _gtk_marshal_VOID__VOID,
1166 widget_class->activate_signal = signals[ACTIVATE];
1169 * GtkEntry::move-cursor:
1170 * @entry: the object which received the signal
1171 * @step: the granularity of the move, as a #GtkMovementStep
1172 * @count: the number of @step units to move
1173 * @extend_selection: %TRUE if the move should extend the selection
1175 * The ::move-cursor signal is a
1176 * <link linkend="keybinding-signals">keybinding signal</link>
1177 * which gets emitted when the user initiates a cursor movement.
1178 * If the cursor is not visible in @entry, this signal causes
1179 * the viewport to be moved instead.
1181 * Applications should not connect to it, but may emit it with
1182 * g_signal_emit_by_name() if they need to control scrolling
1185 * The default bindings for this signal come in two variants,
1186 * the variant with the Shift modifier extends the selection,
1187 * the variant without the Shift modifer does not.
1188 * There are too many key combinations to list them all here.
1190 * <listitem>Arrow keys move by individual characters/lines</listitem>
1191 * <listitem>Ctrl-arrow key combinations move by words/paragraphs</listitem>
1192 * <listitem>Home/End keys move to the ends of the buffer</listitem>
1195 signals[MOVE_CURSOR] =
1196 g_signal_new (I_("move-cursor"),
1197 G_OBJECT_CLASS_TYPE (gobject_class),
1198 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1199 G_STRUCT_OFFSET (GtkEntryClass, move_cursor),
1201 _gtk_marshal_VOID__ENUM_INT_BOOLEAN,
1203 GTK_TYPE_MOVEMENT_STEP,
1208 * GtkEntry::insert-at-cursor:
1209 * @entry: the object which received the signal
1210 * @string: the string to insert
1212 * The ::insert-at-cursor signal is a
1213 * <link linkend="keybinding-signals">keybinding signal</link>
1214 * which gets emitted when the user initiates the insertion of a
1215 * fixed string at the cursor.
1217 * This signal has no default bindings.
1219 signals[INSERT_AT_CURSOR] =
1220 g_signal_new (I_("insert-at-cursor"),
1221 G_OBJECT_CLASS_TYPE (gobject_class),
1222 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1223 G_STRUCT_OFFSET (GtkEntryClass, insert_at_cursor),
1225 _gtk_marshal_VOID__STRING,
1230 * GtkEntry::delete-from-cursor:
1231 * @entry: the object which received the signal
1232 * @type: the granularity of the deletion, as a #GtkDeleteType
1233 * @count: the number of @type units to delete
1235 * The ::delete-from-cursor signal is a
1236 * <link linkend="keybinding-signals">keybinding signal</link>
1237 * which gets emitted when the user initiates a text deletion.
1239 * If the @type is %GTK_DELETE_CHARS, GTK+ deletes the selection
1240 * if there is one, otherwise it deletes the requested number
1243 * The default bindings for this signal are
1244 * Delete for deleting a character and Ctrl-Delete for
1247 signals[DELETE_FROM_CURSOR] =
1248 g_signal_new (I_("delete-from-cursor"),
1249 G_OBJECT_CLASS_TYPE (gobject_class),
1250 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1251 G_STRUCT_OFFSET (GtkEntryClass, delete_from_cursor),
1253 _gtk_marshal_VOID__ENUM_INT,
1255 GTK_TYPE_DELETE_TYPE,
1259 * GtkEntry::backspace:
1260 * @entry: the object which received the signal
1262 * The ::backspace signal is a
1263 * <link linkend="keybinding-signals">keybinding signal</link>
1264 * which gets emitted when the user asks for it.
1266 * The default bindings for this signal are
1267 * Backspace and Shift-Backspace.
1269 signals[BACKSPACE] =
1270 g_signal_new (I_("backspace"),
1271 G_OBJECT_CLASS_TYPE (gobject_class),
1272 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1273 G_STRUCT_OFFSET (GtkEntryClass, backspace),
1275 _gtk_marshal_VOID__VOID,
1279 * GtkEntry::cut-clipboard:
1280 * @entry: the object which received the signal
1282 * The ::cut-clipboard signal is a
1283 * <link linkend="keybinding-signals">keybinding signal</link>
1284 * which gets emitted to cut the selection to the clipboard.
1286 * The default bindings for this signal are
1287 * Ctrl-x and Shift-Delete.
1289 signals[CUT_CLIPBOARD] =
1290 g_signal_new (I_("cut-clipboard"),
1291 G_OBJECT_CLASS_TYPE (gobject_class),
1292 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1293 G_STRUCT_OFFSET (GtkEntryClass, cut_clipboard),
1295 _gtk_marshal_VOID__VOID,
1299 * GtkEntry::copy-clipboard:
1300 * @entry: the object which received the signal
1302 * The ::copy-clipboard signal is a
1303 * <link linkend="keybinding-signals">keybinding signal</link>
1304 * which gets emitted to copy the selection to the clipboard.
1306 * The default bindings for this signal are
1307 * Ctrl-c and Ctrl-Insert.
1309 signals[COPY_CLIPBOARD] =
1310 g_signal_new (I_("copy-clipboard"),
1311 G_OBJECT_CLASS_TYPE (gobject_class),
1312 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1313 G_STRUCT_OFFSET (GtkEntryClass, copy_clipboard),
1315 _gtk_marshal_VOID__VOID,
1319 * GtkEntry::paste-clipboard:
1320 * @entry: the object which received the signal
1322 * The ::paste-clipboard signal is a
1323 * <link linkend="keybinding-signals">keybinding signal</link>
1324 * which gets emitted to paste the contents of the clipboard
1325 * into the text view.
1327 * The default bindings for this signal are
1328 * Ctrl-v and Shift-Insert.
1330 signals[PASTE_CLIPBOARD] =
1331 g_signal_new (I_("paste-clipboard"),
1332 G_OBJECT_CLASS_TYPE (gobject_class),
1333 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1334 G_STRUCT_OFFSET (GtkEntryClass, paste_clipboard),
1336 _gtk_marshal_VOID__VOID,
1340 * GtkEntry::toggle-overwrite:
1341 * @entry: the object which received the signal
1343 * The ::toggle-overwrite signal is a
1344 * <link linkend="keybinding-signals">keybinding signal</link>
1345 * which gets emitted to toggle the overwrite mode of the entry.
1347 * The default bindings for this signal is Insert.
1349 signals[TOGGLE_OVERWRITE] =
1350 g_signal_new (I_("toggle-overwrite"),
1351 G_OBJECT_CLASS_TYPE (gobject_class),
1352 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1353 G_STRUCT_OFFSET (GtkEntryClass, toggle_overwrite),
1355 _gtk_marshal_VOID__VOID,
1359 * GtkEntry::icon-press:
1360 * @entry: The entry on which the signal is emitted
1361 * @icon_pos: The position of the clicked icon
1362 * @event: the button press event
1364 * The ::icon-press signal is emitted when an activatable icon
1369 signals[ICON_PRESS] =
1370 g_signal_new (I_("icon-press"),
1371 G_TYPE_FROM_CLASS (gobject_class),
1372 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1375 _gtk_marshal_VOID__ENUM_BOXED,
1377 GTK_TYPE_ENTRY_ICON_POSITION,
1378 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1381 * GtkEntry::icon-release:
1382 * @entry: The entry on which the signal is emitted
1383 * @icon_pos: The position of the clicked icon
1384 * @event: the button release event
1386 * The ::icon-release signal is emitted on the button release from a
1387 * mouse click over an activatable icon.
1391 signals[ICON_RELEASE] =
1392 g_signal_new (I_("icon-release"),
1393 G_TYPE_FROM_CLASS (gobject_class),
1394 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1397 _gtk_marshal_VOID__ENUM_BOXED,
1399 GTK_TYPE_ENTRY_ICON_POSITION,
1400 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1407 binding_set = gtk_binding_set_by_class (class);
1409 /* Moving the insertion point */
1410 add_move_binding (binding_set, GDK_Right, 0,
1411 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1413 add_move_binding (binding_set, GDK_Left, 0,
1414 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1416 add_move_binding (binding_set, GDK_KP_Right, 0,
1417 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1419 add_move_binding (binding_set, GDK_KP_Left, 0,
1420 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1422 add_move_binding (binding_set, GDK_Right, GDK_CONTROL_MASK,
1423 GTK_MOVEMENT_WORDS, 1);
1425 add_move_binding (binding_set, GDK_Left, GDK_CONTROL_MASK,
1426 GTK_MOVEMENT_WORDS, -1);
1428 add_move_binding (binding_set, GDK_KP_Right, GDK_CONTROL_MASK,
1429 GTK_MOVEMENT_WORDS, 1);
1431 add_move_binding (binding_set, GDK_KP_Left, GDK_CONTROL_MASK,
1432 GTK_MOVEMENT_WORDS, -1);
1434 add_move_binding (binding_set, GDK_Home, 0,
1435 GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
1437 add_move_binding (binding_set, GDK_End, 0,
1438 GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
1440 add_move_binding (binding_set, GDK_KP_Home, 0,
1441 GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
1443 add_move_binding (binding_set, GDK_KP_End, 0,
1444 GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
1446 add_move_binding (binding_set, GDK_Home, GDK_CONTROL_MASK,
1447 GTK_MOVEMENT_BUFFER_ENDS, -1);
1449 add_move_binding (binding_set, GDK_End, GDK_CONTROL_MASK,
1450 GTK_MOVEMENT_BUFFER_ENDS, 1);
1452 add_move_binding (binding_set, GDK_KP_Home, GDK_CONTROL_MASK,
1453 GTK_MOVEMENT_BUFFER_ENDS, -1);
1455 add_move_binding (binding_set, GDK_KP_End, GDK_CONTROL_MASK,
1456 GTK_MOVEMENT_BUFFER_ENDS, 1);
1460 gtk_binding_entry_add_signal (binding_set, GDK_a, GDK_CONTROL_MASK,
1462 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1464 G_TYPE_BOOLEAN, FALSE);
1465 gtk_binding_entry_add_signal (binding_set, GDK_a, GDK_CONTROL_MASK,
1467 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1469 G_TYPE_BOOLEAN, TRUE);
1471 gtk_binding_entry_add_signal (binding_set, GDK_slash, GDK_CONTROL_MASK,
1473 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1475 G_TYPE_BOOLEAN, FALSE);
1476 gtk_binding_entry_add_signal (binding_set, GDK_slash, GDK_CONTROL_MASK,
1478 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1480 G_TYPE_BOOLEAN, TRUE);
1483 gtk_binding_entry_add_signal (binding_set, GDK_backslash, GDK_CONTROL_MASK,
1485 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_VISUAL_POSITIONS,
1487 G_TYPE_BOOLEAN, FALSE);
1488 gtk_binding_entry_add_signal (binding_set, GDK_a, GDK_SHIFT_MASK | GDK_CONTROL_MASK,
1490 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_VISUAL_POSITIONS,
1492 G_TYPE_BOOLEAN, FALSE);
1496 gtk_binding_entry_add_signal (binding_set, GDK_Return, 0,
1498 gtk_binding_entry_add_signal (binding_set, GDK_ISO_Enter, 0,
1500 gtk_binding_entry_add_signal (binding_set, GDK_KP_Enter, 0,
1504 gtk_binding_entry_add_signal (binding_set, GDK_Delete, 0,
1505 "delete-from-cursor", 2,
1506 G_TYPE_ENUM, GTK_DELETE_CHARS,
1509 gtk_binding_entry_add_signal (binding_set, GDK_KP_Delete, 0,
1510 "delete-from-cursor", 2,
1511 G_TYPE_ENUM, GTK_DELETE_CHARS,
1514 gtk_binding_entry_add_signal (binding_set, GDK_BackSpace, 0,
1517 /* Make this do the same as Backspace, to help with mis-typing */
1518 gtk_binding_entry_add_signal (binding_set, GDK_BackSpace, GDK_SHIFT_MASK,
1521 gtk_binding_entry_add_signal (binding_set, GDK_Delete, GDK_CONTROL_MASK,
1522 "delete-from-cursor", 2,
1523 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1526 gtk_binding_entry_add_signal (binding_set, GDK_KP_Delete, GDK_CONTROL_MASK,
1527 "delete-from-cursor", 2,
1528 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1531 gtk_binding_entry_add_signal (binding_set, GDK_BackSpace, GDK_CONTROL_MASK,
1532 "delete-from-cursor", 2,
1533 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1536 /* Cut/copy/paste */
1538 gtk_binding_entry_add_signal (binding_set, GDK_x, GDK_CONTROL_MASK,
1539 "cut-clipboard", 0);
1540 gtk_binding_entry_add_signal (binding_set, GDK_c, GDK_CONTROL_MASK,
1541 "copy-clipboard", 0);
1542 gtk_binding_entry_add_signal (binding_set, GDK_v, GDK_CONTROL_MASK,
1543 "paste-clipboard", 0);
1545 gtk_binding_entry_add_signal (binding_set, GDK_Delete, GDK_SHIFT_MASK,
1546 "cut-clipboard", 0);
1547 gtk_binding_entry_add_signal (binding_set, GDK_Insert, GDK_CONTROL_MASK,
1548 "copy-clipboard", 0);
1549 gtk_binding_entry_add_signal (binding_set, GDK_Insert, GDK_SHIFT_MASK,
1550 "paste-clipboard", 0);
1553 gtk_binding_entry_add_signal (binding_set, GDK_Insert, 0,
1554 "toggle-overwrite", 0);
1555 gtk_binding_entry_add_signal (binding_set, GDK_KP_Insert, 0,
1556 "toggle-overwrite", 0);
1559 * GtkEntry:inner-border:
1561 * Sets the text area's border between the text and the frame.
1565 gtk_widget_class_install_style_property (widget_class,
1566 g_param_spec_boxed ("inner-border",
1568 P_("Border between text and frame."),
1570 GTK_PARAM_READABLE));
1573 * GtkEntry:state-hint:
1575 * Indicates whether to pass a proper widget state when
1576 * drawing the shadow and the widget background.
1580 gtk_widget_class_install_style_property (widget_class,
1581 g_param_spec_boolean ("state-hint",
1583 P_("Whether to pass a proper state when drawing shadow or background"),
1585 GTK_PARAM_READABLE));
1587 gtk_settings_install_property (g_param_spec_boolean ("gtk-entry-select-on-focus",
1588 P_("Select on focus"),
1589 P_("Whether to select the contents of an entry when it is focused"),
1591 GTK_PARAM_READWRITE));
1594 * GtkSettings:gtk-entry-password-hint-timeout:
1596 * How long to show the last input character in hidden
1597 * entries. This value is in milliseconds. 0 disables showing the
1598 * last char. 600 is a good value for enabling it.
1602 gtk_settings_install_property (g_param_spec_uint ("gtk-entry-password-hint-timeout",
1603 P_("Password Hint Timeout"),
1604 P_("How long to show the last input character in hidden entries"),
1606 GTK_PARAM_READWRITE));
1608 g_type_class_add_private (gobject_class, sizeof (GtkEntryPrivate));
1612 gtk_entry_editable_init (GtkEditableClass *iface)
1614 iface->do_insert_text = gtk_entry_insert_text;
1615 iface->do_delete_text = gtk_entry_delete_text;
1616 iface->insert_text = gtk_entry_real_insert_text;
1617 iface->delete_text = gtk_entry_real_delete_text;
1618 iface->get_chars = gtk_entry_get_chars;
1619 iface->set_selection_bounds = gtk_entry_set_selection_bounds;
1620 iface->get_selection_bounds = gtk_entry_get_selection_bounds;
1621 iface->set_position = gtk_entry_real_set_position;
1622 iface->get_position = gtk_entry_get_position;
1626 gtk_entry_cell_editable_init (GtkCellEditableIface *iface)
1628 iface->start_editing = gtk_entry_start_editing;
1632 gtk_entry_set_property (GObject *object,
1634 const GValue *value,
1637 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (object);
1638 GtkEntry *entry = GTK_ENTRY (object);
1644 gboolean new_value = g_value_get_boolean (value);
1646 if (new_value != entry->editable)
1650 _gtk_entry_reset_im_context (entry);
1651 if (GTK_WIDGET_HAS_FOCUS (entry))
1652 gtk_im_context_focus_out (entry->im_context);
1654 entry->preedit_length = 0;
1655 entry->preedit_cursor = 0;
1658 entry->editable = new_value;
1660 if (new_value && GTK_WIDGET_HAS_FOCUS (entry))
1661 gtk_im_context_focus_in (entry->im_context);
1663 gtk_entry_queue_draw (entry);
1668 case PROP_MAX_LENGTH:
1669 gtk_entry_set_max_length (entry, g_value_get_int (value));
1672 case PROP_VISIBILITY:
1673 gtk_entry_set_visibility (entry, g_value_get_boolean (value));
1676 case PROP_HAS_FRAME:
1677 gtk_entry_set_has_frame (entry, g_value_get_boolean (value));
1680 case PROP_INNER_BORDER:
1681 gtk_entry_set_inner_border (entry, g_value_get_boxed (value));
1684 case PROP_INVISIBLE_CHAR:
1685 gtk_entry_set_invisible_char (entry, g_value_get_uint (value));
1688 case PROP_ACTIVATES_DEFAULT:
1689 gtk_entry_set_activates_default (entry, g_value_get_boolean (value));
1692 case PROP_WIDTH_CHARS:
1693 gtk_entry_set_width_chars (entry, g_value_get_int (value));
1697 gtk_entry_set_text (entry, g_value_get_string (value));
1701 gtk_entry_set_alignment (entry, g_value_get_float (value));
1704 case PROP_TRUNCATE_MULTILINE:
1705 entry->truncate_multiline = g_value_get_boolean (value);
1708 case PROP_SHADOW_TYPE:
1709 priv->shadow_type = g_value_get_enum (value);
1712 case PROP_OVERWRITE_MODE:
1713 gtk_entry_set_overwrite_mode (entry, g_value_get_boolean (value));
1716 case PROP_INVISIBLE_CHAR_SET:
1717 if (g_value_get_boolean (value))
1718 priv->invisible_char_set = TRUE;
1720 gtk_entry_unset_invisible_char (entry);
1723 case PROP_CAPS_LOCK_WARNING:
1724 priv->caps_lock_warning = g_value_get_boolean (value);
1727 case PROP_PROGRESS_FRACTION:
1728 gtk_entry_set_progress_fraction (entry, g_value_get_double (value));
1731 case PROP_PROGRESS_PULSE_STEP:
1732 gtk_entry_set_progress_pulse_step (entry, g_value_get_double (value));
1735 case PROP_PIXBUF_PRIMARY:
1736 gtk_entry_set_icon_from_pixbuf (entry,
1737 GTK_ENTRY_ICON_PRIMARY,
1738 g_value_get_object (value));
1741 case PROP_PIXBUF_SECONDARY:
1742 gtk_entry_set_icon_from_pixbuf (entry,
1743 GTK_ENTRY_ICON_SECONDARY,
1744 g_value_get_object (value));
1747 case PROP_STOCK_PRIMARY:
1748 gtk_entry_set_icon_from_stock (entry,
1749 GTK_ENTRY_ICON_PRIMARY,
1750 g_value_get_string (value));
1753 case PROP_STOCK_SECONDARY:
1754 gtk_entry_set_icon_from_stock (entry,
1755 GTK_ENTRY_ICON_SECONDARY,
1756 g_value_get_string (value));
1759 case PROP_ICON_NAME_PRIMARY:
1760 gtk_entry_set_icon_from_icon_name (entry,
1761 GTK_ENTRY_ICON_PRIMARY,
1762 g_value_get_string (value));
1765 case PROP_ICON_NAME_SECONDARY:
1766 gtk_entry_set_icon_from_icon_name (entry,
1767 GTK_ENTRY_ICON_SECONDARY,
1768 g_value_get_string (value));
1771 case PROP_GICON_PRIMARY:
1772 gtk_entry_set_icon_from_gicon (entry,
1773 GTK_ENTRY_ICON_PRIMARY,
1774 g_value_get_object (value));
1777 case PROP_GICON_SECONDARY:
1778 gtk_entry_set_icon_from_gicon (entry,
1779 GTK_ENTRY_ICON_SECONDARY,
1780 g_value_get_object (value));
1783 case PROP_ACTIVATABLE_PRIMARY:
1784 gtk_entry_set_icon_activatable (entry,
1785 GTK_ENTRY_ICON_PRIMARY,
1786 g_value_get_boolean (value));
1789 case PROP_ACTIVATABLE_SECONDARY:
1790 gtk_entry_set_icon_activatable (entry,
1791 GTK_ENTRY_ICON_SECONDARY,
1792 g_value_get_boolean (value));
1795 case PROP_SENSITIVE_PRIMARY:
1796 gtk_entry_set_icon_sensitive (entry,
1797 GTK_ENTRY_ICON_PRIMARY,
1798 g_value_get_boolean (value));
1801 case PROP_SENSITIVE_SECONDARY:
1802 gtk_entry_set_icon_sensitive (entry,
1803 GTK_ENTRY_ICON_SECONDARY,
1804 g_value_get_boolean (value));
1807 case PROP_IM_MODULE:
1808 g_free (priv->im_module);
1809 priv->im_module = g_strdup (g_value_get_string (value));
1810 if (GTK_IS_IM_MULTICONTEXT (entry->im_context))
1811 gtk_im_multicontext_set_context_id (GTK_IM_MULTICONTEXT (entry->im_context), priv->im_module);
1814 case PROP_SCROLL_OFFSET:
1815 case PROP_CURSOR_POSITION:
1817 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1823 gtk_entry_get_property (GObject *object,
1828 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (object);
1829 GtkEntry *entry = GTK_ENTRY (object);
1833 case PROP_CURSOR_POSITION:
1834 g_value_set_int (value, entry->current_pos);
1837 case PROP_SELECTION_BOUND:
1838 g_value_set_int (value, entry->selection_bound);
1842 g_value_set_boolean (value, entry->editable);
1845 case PROP_MAX_LENGTH:
1846 g_value_set_int (value, entry->text_max_length);
1849 case PROP_VISIBILITY:
1850 g_value_set_boolean (value, entry->visible);
1853 case PROP_HAS_FRAME:
1854 g_value_set_boolean (value, entry->has_frame);
1857 case PROP_INNER_BORDER:
1858 g_value_set_boxed (value, gtk_entry_get_inner_border (entry));
1861 case PROP_INVISIBLE_CHAR:
1862 g_value_set_uint (value, entry->invisible_char);
1865 case PROP_ACTIVATES_DEFAULT:
1866 g_value_set_boolean (value, entry->activates_default);
1869 case PROP_WIDTH_CHARS:
1870 g_value_set_int (value, entry->width_chars);
1873 case PROP_SCROLL_OFFSET:
1874 g_value_set_int (value, entry->scroll_offset);
1878 g_value_set_string (value, gtk_entry_get_text (entry));
1882 g_value_set_float (value, gtk_entry_get_alignment (entry));
1885 case PROP_TRUNCATE_MULTILINE:
1886 g_value_set_boolean (value, entry->truncate_multiline);
1889 case PROP_SHADOW_TYPE:
1890 g_value_set_enum (value, priv->shadow_type);
1893 case PROP_OVERWRITE_MODE:
1894 g_value_set_boolean (value, entry->overwrite_mode);
1897 case PROP_TEXT_LENGTH:
1898 g_value_set_uint (value, entry->text_length);
1901 case PROP_INVISIBLE_CHAR_SET:
1902 g_value_set_boolean (value, priv->invisible_char_set);
1905 case PROP_IM_MODULE:
1906 g_value_set_string (value, priv->im_module);
1909 case PROP_CAPS_LOCK_WARNING:
1910 g_value_set_boolean (value, priv->caps_lock_warning);
1913 case PROP_PROGRESS_FRACTION:
1914 g_value_set_double (value, priv->progress_fraction);
1917 case PROP_PROGRESS_PULSE_STEP:
1918 g_value_set_double (value, priv->progress_pulse_fraction);
1921 case PROP_PIXBUF_PRIMARY:
1922 g_value_set_object (value,
1923 gtk_entry_get_pixbuf (entry,
1924 GTK_ENTRY_ICON_PRIMARY));
1927 case PROP_PIXBUF_SECONDARY:
1928 g_value_set_object (value,
1929 gtk_entry_get_pixbuf (entry,
1930 GTK_ENTRY_ICON_SECONDARY));
1933 case PROP_STOCK_PRIMARY:
1934 g_value_set_string (value,
1935 gtk_entry_get_stock (entry,
1936 GTK_ENTRY_ICON_PRIMARY));
1939 case PROP_STOCK_SECONDARY:
1940 g_value_set_string (value,
1941 gtk_entry_get_stock (entry,
1942 GTK_ENTRY_ICON_SECONDARY));
1945 case PROP_ICON_NAME_PRIMARY:
1946 g_value_set_string (value,
1947 gtk_entry_get_icon_name (entry,
1948 GTK_ENTRY_ICON_PRIMARY));
1951 case PROP_ICON_NAME_SECONDARY:
1952 g_value_set_string (value,
1953 gtk_entry_get_icon_name (entry,
1954 GTK_ENTRY_ICON_SECONDARY));
1957 case PROP_GICON_PRIMARY:
1958 g_value_set_object (value,
1959 gtk_entry_get_gicon (entry,
1960 GTK_ENTRY_ICON_PRIMARY));
1963 case PROP_GICON_SECONDARY:
1964 g_value_set_object (value,
1965 gtk_entry_get_gicon (entry,
1966 GTK_ENTRY_ICON_SECONDARY));
1969 case PROP_STORAGE_TYPE_PRIMARY:
1970 g_value_set_enum (value,
1971 gtk_entry_get_storage_type (entry, GTK_ENTRY_ICON_PRIMARY));
1974 case PROP_STORAGE_TYPE_SECONDARY:
1975 g_value_set_enum (value,
1976 gtk_entry_get_storage_type (entry, GTK_ENTRY_ICON_SECONDARY));
1979 case PROP_ACTIVATABLE_PRIMARY:
1980 g_value_set_boolean (value,
1981 gtk_entry_get_icon_activatable (entry, GTK_ENTRY_ICON_PRIMARY));
1984 case PROP_ACTIVATABLE_SECONDARY:
1985 g_value_set_boolean (value,
1986 gtk_entry_get_icon_activatable (entry, GTK_ENTRY_ICON_SECONDARY));
1989 case PROP_SENSITIVE_PRIMARY:
1990 g_value_set_boolean (value,
1991 gtk_entry_get_icon_sensitive (entry, GTK_ENTRY_ICON_PRIMARY));
1994 case PROP_SENSITIVE_SECONDARY:
1995 g_value_set_boolean (value,
1996 gtk_entry_get_icon_sensitive (entry, GTK_ENTRY_ICON_SECONDARY));
2000 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2006 find_invisible_char (GtkWidget *widget)
2008 PangoLayout *layout;
2009 PangoAttrList *attr_list;
2011 gunichar invisible_chars [] = {
2012 0x25cf, /* BLACK CIRCLE */
2013 0x2022, /* BULLET */
2014 0x2731, /* HEAVY ASTERISK */
2015 0x273a /* SIXTEEN POINTED ASTERISK */
2018 layout = gtk_widget_create_pango_layout (widget, NULL);
2020 attr_list = pango_attr_list_new ();
2021 pango_attr_list_insert (attr_list, pango_attr_fallback_new (FALSE));
2023 pango_layout_set_attributes (layout, attr_list);
2024 pango_attr_list_unref (attr_list);
2026 for (i = 0; i < G_N_ELEMENTS (invisible_chars); i++)
2028 gchar text[7] = { 0, };
2031 len = g_unichar_to_utf8 (invisible_chars[i], text);
2032 pango_layout_set_text (layout, text, len);
2034 count = pango_layout_get_unknown_glyphs_count (layout);
2038 g_object_unref (layout);
2039 return invisible_chars[i];
2043 g_object_unref (layout);
2048 gtk_entry_init (GtkEntry *entry)
2050 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2052 GTK_WIDGET_SET_FLAGS (entry, GTK_CAN_FOCUS);
2054 entry->text_size = MIN_SIZE;
2055 entry->text = g_malloc (entry->text_size);
2056 entry->text[0] = '\0';
2058 entry->editable = TRUE;
2059 entry->visible = TRUE;
2060 entry->invisible_char = find_invisible_char (GTK_WIDGET (entry));
2061 entry->dnd_position = -1;
2062 entry->width_chars = -1;
2063 entry->is_cell_renderer = FALSE;
2064 entry->editing_canceled = FALSE;
2065 entry->has_frame = TRUE;
2066 entry->truncate_multiline = FALSE;
2067 priv->shadow_type = GTK_SHADOW_IN;
2069 priv->caps_lock_warning = TRUE;
2070 priv->caps_lock_warning_shown = FALSE;
2071 priv->progress_fraction = 0.0;
2072 priv->progress_pulse_fraction = 0.1;
2074 gtk_drag_dest_set (GTK_WIDGET (entry),
2075 GTK_DEST_DEFAULT_HIGHLIGHT,
2077 GDK_ACTION_COPY | GDK_ACTION_MOVE);
2078 gtk_drag_dest_add_text_targets (GTK_WIDGET (entry));
2080 /* This object is completely private. No external entity can gain a reference
2081 * to it; so we create it here and destroy it in finalize().
2083 entry->im_context = gtk_im_multicontext_new ();
2085 g_signal_connect (entry->im_context, "commit",
2086 G_CALLBACK (gtk_entry_commit_cb), entry);
2087 g_signal_connect (entry->im_context, "preedit-changed",
2088 G_CALLBACK (gtk_entry_preedit_changed_cb), entry);
2089 g_signal_connect (entry->im_context, "retrieve-surrounding",
2090 G_CALLBACK (gtk_entry_retrieve_surrounding_cb), entry);
2091 g_signal_connect (entry->im_context, "delete-surrounding",
2092 G_CALLBACK (gtk_entry_delete_surrounding_cb), entry);
2096 get_icon_width (GtkEntry *entry,
2097 GtkEntryIconPosition icon_pos)
2099 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2100 EntryIconInfo *icon_info = priv->icons[icon_pos];
2102 GtkSettings *settings;
2103 gint menu_icon_width;
2105 if (!icon_info || icon_info->pixbuf == NULL)
2108 screen = gtk_widget_get_screen (GTK_WIDGET (entry));
2109 settings = gtk_settings_get_for_screen (screen);
2111 gtk_icon_size_lookup_for_settings (settings, GTK_ICON_SIZE_MENU,
2112 &menu_icon_width, NULL);
2114 return MAX (gdk_pixbuf_get_width (icon_info->pixbuf), menu_icon_width);
2118 get_icon_allocations (GtkEntry *entry,
2119 GtkAllocation *primary,
2120 GtkAllocation *secondary)
2123 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2124 gint x, y, width, height;
2126 gtk_entry_get_text_area_size (entry, &x, &y, &width, &height);
2129 primary->height = height;
2130 primary->width = get_icon_width (entry, GTK_ENTRY_ICON_PRIMARY);
2131 if (primary->width > 0)
2132 primary->width += 2 * priv->icon_margin;
2135 secondary->height = height;
2136 secondary->width = get_icon_width (entry, GTK_ENTRY_ICON_SECONDARY);
2137 if (secondary->width > 0)
2138 secondary->width += 2 * priv->icon_margin;
2140 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
2142 primary->x = x + width - primary->width;
2148 secondary->x = x + width - secondary->width;
2154 begin_change (GtkEntry *entry)
2156 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2158 priv->change_count++;
2162 end_change (GtkEntry *entry)
2164 GtkEditable *editable = GTK_EDITABLE (entry);
2165 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2167 g_return_if_fail (priv->change_count > 0);
2169 priv->change_count--;
2171 if (priv->change_count == 0)
2173 if (priv->real_changed)
2175 g_signal_emit_by_name (editable, "changed");
2176 priv->real_changed = FALSE;
2182 emit_changed (GtkEntry *entry)
2184 GtkEditable *editable = GTK_EDITABLE (entry);
2185 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2187 if (priv->change_count == 0)
2188 g_signal_emit_by_name (editable, "changed");
2190 priv->real_changed = TRUE;
2194 * Overwrite a memory that might contain sensitive information.
2197 trash_area (gchar *area, gsize len)
2199 volatile gchar *varea = (volatile gchar *)area;
2205 gtk_entry_destroy (GtkObject *object)
2207 GtkEntry *entry = GTK_ENTRY (object);
2210 entry->current_pos = entry->selection_bound = entry->text_length = 0;
2211 _gtk_entry_reset_im_context (entry);
2212 gtk_entry_reset_layout (entry);
2214 if (entry->blink_timeout)
2216 g_source_remove (entry->blink_timeout);
2217 entry->blink_timeout = 0;
2220 if (entry->recompute_idle)
2222 g_source_remove (entry->recompute_idle);
2223 entry->recompute_idle = 0;
2226 if (!entry->visible)
2228 /* We want to trash the text here because the entry might be leaked. */
2229 trash_area (entry->text, strlen (entry->text));
2232 GTK_OBJECT_CLASS (gtk_entry_parent_class)->destroy (object);
2236 gtk_entry_dispose (GObject *object)
2238 GtkEntry *entry = GTK_ENTRY (object);
2240 gtk_entry_set_icon_from_pixbuf (entry, GTK_ENTRY_ICON_PRIMARY, NULL);
2241 gtk_entry_set_icon_tooltip_markup (entry, GTK_ENTRY_ICON_PRIMARY, NULL);
2242 gtk_entry_set_icon_from_pixbuf (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
2243 gtk_entry_set_icon_tooltip_markup (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
2245 G_OBJECT_CLASS (gtk_entry_parent_class)->dispose (object);
2249 gtk_entry_finalize (GObject *object)
2251 GtkEntry *entry = GTK_ENTRY (object);
2252 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2253 EntryIconInfo *icon_info = NULL;
2256 for (i = 0; i < MAX_ICONS; i++)
2258 if ((icon_info = priv->icons[i]) != NULL)
2260 if (icon_info->target_list != NULL)
2262 gtk_target_list_unref (icon_info->target_list);
2263 icon_info->target_list = NULL;
2266 g_slice_free (EntryIconInfo, icon_info);
2267 priv->icons[i] = NULL;
2271 gtk_entry_set_completion (entry, NULL);
2273 if (entry->cached_layout)
2274 g_object_unref (entry->cached_layout);
2276 g_object_unref (entry->im_context);
2278 if (entry->blink_timeout)
2279 g_source_remove (entry->blink_timeout);
2281 if (entry->recompute_idle)
2282 g_source_remove (entry->recompute_idle);
2284 entry->text_size = 0;
2288 if (!entry->visible)
2289 trash_area (entry->text, strlen (entry->text));
2290 g_free (entry->text);
2294 g_free (priv->im_module);
2296 G_OBJECT_CLASS (gtk_entry_parent_class)->finalize (object);
2300 update_cursors (GtkWidget *widget)
2302 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2303 EntryIconInfo *icon_info = NULL;
2304 GdkDisplay *display;
2308 for (i = 0; i < MAX_ICONS; i++)
2310 if ((icon_info = priv->icons[i]) != NULL)
2312 if (icon_info->pixbuf != NULL)
2313 gdk_window_show (icon_info->window);
2315 /* The icon windows are not children of the visible entry window,
2316 * thus we can't just inherit the xterm cursor. Slight complication
2317 * here is that for the entry, insensitive => arrow cursor, but for
2318 * an icon in a sensitive entry, insensitive => xterm cursor.
2320 if (GTK_WIDGET_IS_SENSITIVE (widget) &&
2321 (icon_info->insensitive ||
2322 (icon_info->nonactivatable && icon_info->target_list == NULL)))
2324 display = gtk_widget_get_display (widget);
2325 cursor = gdk_cursor_new_for_display (display, GDK_XTERM);
2326 gdk_window_set_cursor (icon_info->window, cursor);
2327 gdk_cursor_unref (cursor);
2331 gdk_window_set_cursor (icon_info->window, NULL);
2338 realize_icon_info (GtkWidget *widget,
2339 GtkEntryIconPosition icon_pos)
2341 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2342 EntryIconInfo *icon_info = priv->icons[icon_pos];
2343 GdkWindowAttr attributes;
2344 gint attributes_mask;
2346 g_return_if_fail (icon_info != NULL);
2350 attributes.width = 1;
2351 attributes.height = 1;
2352 attributes.window_type = GDK_WINDOW_CHILD;
2353 attributes.wclass = GDK_INPUT_OUTPUT;
2354 attributes.visual = gtk_widget_get_visual (widget);
2355 attributes.colormap = gtk_widget_get_colormap (widget);
2356 attributes.event_mask = gtk_widget_get_events (widget);
2357 attributes.event_mask |= (GDK_EXPOSURE_MASK |
2358 GDK_BUTTON_PRESS_MASK |
2359 GDK_BUTTON_RELEASE_MASK |
2360 GDK_BUTTON1_MOTION_MASK |
2361 GDK_BUTTON3_MOTION_MASK |
2362 GDK_POINTER_MOTION_HINT_MASK |
2363 GDK_POINTER_MOTION_MASK |
2364 GDK_ENTER_NOTIFY_MASK |
2365 GDK_LEAVE_NOTIFY_MASK);
2366 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
2368 icon_info->window = gdk_window_new (widget->window,
2371 gdk_window_set_user_data (icon_info->window, widget);
2372 gdk_window_set_background (icon_info->window,
2373 &widget->style->base[GTK_WIDGET_STATE (widget)]);
2375 gtk_widget_queue_resize (widget);
2378 static EntryIconInfo*
2379 construct_icon_info (GtkWidget *widget,
2380 GtkEntryIconPosition icon_pos)
2382 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2383 EntryIconInfo *icon_info;
2385 g_return_val_if_fail (priv->icons[icon_pos] == NULL, NULL);
2387 icon_info = g_slice_new0 (EntryIconInfo);
2388 priv->icons[icon_pos] = icon_info;
2390 if (GTK_WIDGET_REALIZED (widget))
2391 realize_icon_info (widget, icon_pos);
2393 if (GTK_WIDGET_MAPPED (widget))
2394 gdk_window_show (icon_info->window);
2400 gtk_entry_map (GtkWidget *widget)
2402 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2403 EntryIconInfo *icon_info = NULL;
2406 if (GTK_WIDGET_REALIZED (widget) && !GTK_WIDGET_MAPPED (widget))
2408 GTK_WIDGET_CLASS (gtk_entry_parent_class)->map (widget);
2410 for (i = 0; i < MAX_ICONS; i++)
2412 if ((icon_info = priv->icons[i]) != NULL)
2414 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
2415 gdk_window_show (icon_info->window);
2419 update_cursors (widget);
2424 gtk_entry_unmap (GtkWidget *widget)
2426 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2427 EntryIconInfo *icon_info = NULL;
2430 if (GTK_WIDGET_MAPPED (widget))
2432 for (i = 0; i < MAX_ICONS; i++)
2434 if ((icon_info = priv->icons[i]) != NULL)
2436 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
2437 gdk_window_hide (icon_info->window);
2441 GTK_WIDGET_CLASS (gtk_entry_parent_class)->unmap (widget);
2446 gtk_entry_realize (GtkWidget *widget)
2449 GtkEntryPrivate *priv;
2450 EntryIconInfo *icon_info;
2451 GdkWindowAttr attributes;
2452 gint attributes_mask;
2455 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
2456 entry = GTK_ENTRY (widget);
2457 priv = GTK_ENTRY_GET_PRIVATE (entry);
2459 attributes.window_type = GDK_WINDOW_CHILD;
2461 get_widget_window_size (entry, &attributes.x, &attributes.y, &attributes.width, &attributes.height);
2463 attributes.wclass = GDK_INPUT_OUTPUT;
2464 attributes.visual = gtk_widget_get_visual (widget);
2465 attributes.colormap = gtk_widget_get_colormap (widget);
2466 attributes.event_mask = gtk_widget_get_events (widget);
2467 attributes.event_mask |= (GDK_EXPOSURE_MASK |
2468 GDK_BUTTON_PRESS_MASK |
2469 GDK_BUTTON_RELEASE_MASK |
2470 GDK_BUTTON1_MOTION_MASK |
2471 GDK_BUTTON3_MOTION_MASK |
2472 GDK_POINTER_MOTION_HINT_MASK |
2473 GDK_POINTER_MOTION_MASK |
2474 GDK_ENTER_NOTIFY_MASK |
2475 GDK_LEAVE_NOTIFY_MASK);
2476 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
2478 widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, attributes_mask);
2479 gdk_window_set_user_data (widget->window, entry);
2481 gtk_entry_get_text_area_size (entry, &attributes.x, &attributes.y, &attributes.width, &attributes.height);
2483 if (GTK_WIDGET_IS_SENSITIVE (widget))
2485 attributes.cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
2486 attributes_mask |= GDK_WA_CURSOR;
2489 entry->text_area = gdk_window_new (widget->window, &attributes, attributes_mask);
2491 gdk_window_set_user_data (entry->text_area, entry);
2493 if (attributes_mask & GDK_WA_CURSOR)
2494 gdk_cursor_unref (attributes.cursor);
2496 widget->style = gtk_style_attach (widget->style, widget->window);
2498 gdk_window_set_background (widget->window, &widget->style->base[GTK_WIDGET_STATE (widget)]);
2499 gdk_window_set_background (entry->text_area, &widget->style->base[GTK_WIDGET_STATE (widget)]);
2501 gdk_window_show (entry->text_area);
2503 gtk_im_context_set_client_window (entry->im_context, entry->text_area);
2505 gtk_entry_adjust_scroll (entry);
2506 gtk_entry_update_primary_selection (entry);
2509 /* If the icon positions are already setup, create their windows.
2510 * Otherwise if they don't exist yet, then construct_icon_info()
2511 * will create the windows once the widget is already realized.
2513 for (i = 0; i < MAX_ICONS; i++)
2515 if ((icon_info = priv->icons[i]) != NULL)
2517 if (icon_info->window == NULL)
2518 realize_icon_info (widget, i);
2524 gtk_entry_unrealize (GtkWidget *widget)
2526 GtkEntry *entry = GTK_ENTRY (widget);
2527 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2528 GtkClipboard *clipboard;
2529 EntryIconInfo *icon_info;
2532 gtk_entry_reset_layout (entry);
2534 gtk_im_context_set_client_window (entry->im_context, NULL);
2536 clipboard = gtk_widget_get_clipboard (widget, GDK_SELECTION_PRIMARY);
2537 if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (entry))
2538 gtk_clipboard_clear (clipboard);
2540 if (entry->text_area)
2542 gdk_window_set_user_data (entry->text_area, NULL);
2543 gdk_window_destroy (entry->text_area);
2544 entry->text_area = NULL;
2547 if (entry->popup_menu)
2549 gtk_widget_destroy (entry->popup_menu);
2550 entry->popup_menu = NULL;
2553 GTK_WIDGET_CLASS (gtk_entry_parent_class)->unrealize (widget);
2555 for (i = 0; i < MAX_ICONS; i++)
2557 if ((icon_info = priv->icons[i]) != NULL)
2559 if (icon_info->window != NULL)
2561 gdk_window_destroy (icon_info->window);
2562 icon_info->window = NULL;
2569 _gtk_entry_get_borders (GtkEntry *entry,
2573 GtkWidget *widget = GTK_WIDGET (entry);
2574 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2576 if (entry->has_frame)
2578 *xborder = widget->style->xthickness;
2579 *yborder = widget->style->ythickness;
2587 if (!priv->interior_focus)
2589 *xborder += priv->focus_width;
2590 *yborder += priv->focus_width;
2595 gtk_entry_size_request (GtkWidget *widget,
2596 GtkRequisition *requisition)
2598 GtkEntry *entry = GTK_ENTRY (widget);
2599 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2600 PangoFontMetrics *metrics;
2601 gint xborder, yborder;
2602 GtkBorder inner_border;
2603 PangoContext *context;
2604 int icon_widths = 0;
2607 gtk_widget_ensure_style (widget);
2608 context = gtk_widget_get_pango_context (widget);
2609 metrics = pango_context_get_metrics (context,
2610 widget->style->font_desc,
2611 pango_context_get_language (context));
2613 entry->ascent = pango_font_metrics_get_ascent (metrics);
2614 entry->descent = pango_font_metrics_get_descent (metrics);
2616 _gtk_entry_get_borders (entry, &xborder, &yborder);
2617 _gtk_entry_effective_inner_border (entry, &inner_border);
2619 if (entry->width_chars < 0)
2620 requisition->width = MIN_ENTRY_WIDTH + xborder * 2 + inner_border.left + inner_border.right;
2623 gint char_width = pango_font_metrics_get_approximate_char_width (metrics);
2624 gint digit_width = pango_font_metrics_get_approximate_digit_width (metrics);
2625 gint char_pixels = (MAX (char_width, digit_width) + PANGO_SCALE - 1) / PANGO_SCALE;
2627 requisition->width = char_pixels * entry->width_chars + xborder * 2 + inner_border.left + inner_border.right;
2630 requisition->height = PANGO_PIXELS (entry->ascent + entry->descent) + yborder * 2 + inner_border.top + inner_border.bottom;
2632 for (i = 0; i < MAX_ICONS; i++)
2634 icon_width = get_icon_width (entry, i);
2636 icon_widths += icon_width + 2 * priv->icon_margin;
2639 if (icon_widths > requisition->width)
2640 requisition->width += icon_widths;
2642 pango_font_metrics_unref (metrics);
2646 place_windows (GtkEntry *entry)
2649 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2650 gint x, y, width, height;
2651 GtkAllocation primary;
2652 GtkAllocation secondary;
2653 EntryIconInfo *icon_info = NULL;
2655 gtk_entry_get_text_area_size (entry, &x, &y, &width, &height);
2657 get_icon_allocations (entry, &primary, &secondary);
2659 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
2660 x += secondary.width;
2663 width -= primary.width + secondary.width;
2665 if ((icon_info = priv->icons[GTK_ENTRY_ICON_PRIMARY]) != NULL)
2666 gdk_window_move_resize (icon_info->window,
2667 primary.x, primary.y,
2668 primary.width, primary.height);
2670 if ((icon_info = priv->icons[GTK_ENTRY_ICON_SECONDARY]) != NULL)
2671 gdk_window_move_resize (icon_info->window,
2672 secondary.x, secondary.y,
2673 secondary.width, secondary.height);
2675 gdk_window_move_resize (GTK_ENTRY (entry)->text_area, x, y, width, height);
2679 gtk_entry_get_text_area_size (GtkEntry *entry,
2685 GtkWidget *widget = GTK_WIDGET (entry);
2686 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2688 gint xborder, yborder;
2689 GtkRequisition requisition;
2691 gtk_widget_get_child_requisition (widget, &requisition);
2692 _gtk_entry_get_borders (entry, &xborder, &yborder);
2694 if (GTK_WIDGET_REALIZED (widget))
2695 gdk_drawable_get_size (widget->window, NULL, &frame_height);
2697 frame_height = requisition.height;
2699 if (GTK_WIDGET_HAS_FOCUS (widget) && !priv->interior_focus)
2700 frame_height -= 2 * priv->focus_width;
2706 *y = frame_height / 2 - (requisition.height - yborder * 2) / 2;
2709 *width = GTK_WIDGET (entry)->allocation.width - xborder * 2;
2712 *height = requisition.height - yborder * 2;
2716 get_widget_window_size (GtkEntry *entry,
2722 GtkRequisition requisition;
2723 GtkWidget *widget = GTK_WIDGET (entry);
2725 gtk_widget_get_child_requisition (widget, &requisition);
2728 *x = widget->allocation.x;
2732 if (entry->is_cell_renderer)
2733 *y = widget->allocation.y;
2735 *y = widget->allocation.y + (widget->allocation.height - requisition.height) / 2;
2739 *width = widget->allocation.width;
2743 if (entry->is_cell_renderer)
2744 *height = widget->allocation.height;
2746 *height = requisition.height;
2751 _gtk_entry_effective_inner_border (GtkEntry *entry,
2754 GtkBorder *tmp_border;
2756 tmp_border = g_object_get_qdata (G_OBJECT (entry), quark_inner_border);
2760 *border = *tmp_border;
2764 gtk_widget_style_get (GTK_WIDGET (entry), "inner-border", &tmp_border, NULL);
2768 *border = *tmp_border;
2769 gtk_border_free (tmp_border);
2773 *border = default_inner_border;
2777 gtk_entry_size_allocate (GtkWidget *widget,
2778 GtkAllocation *allocation)
2780 GtkEntry *entry = GTK_ENTRY (widget);
2782 widget->allocation = *allocation;
2784 if (GTK_WIDGET_REALIZED (widget))
2786 /* We call gtk_widget_get_child_requisition, since we want (for
2787 * backwards compatibility reasons) the realization here to
2788 * be affected by the usize of the entry, if set
2790 gint x, y, width, height;
2791 GtkEntryCompletion* completion;
2793 get_widget_window_size (entry, &x, &y, &width, &height);
2794 gdk_window_move_resize (widget->window, x, y, width, height);
2796 place_windows (entry);
2797 gtk_entry_recompute (entry);
2799 completion = gtk_entry_get_completion (entry);
2800 if (completion && GTK_WIDGET_MAPPED (completion->priv->popup_window))
2801 _gtk_entry_completion_resize_popup (completion);
2805 /* Kudos to the gnome-panel guys. */
2807 colorshift_pixbuf (GdkPixbuf *dest,
2812 gint width, height, has_alpha, src_rowstride, dest_rowstride;
2813 guchar *target_pixels;
2814 guchar *original_pixels;
2820 has_alpha = gdk_pixbuf_get_has_alpha (src);
2821 width = gdk_pixbuf_get_width (src);
2822 height = gdk_pixbuf_get_height (src);
2823 src_rowstride = gdk_pixbuf_get_rowstride (src);
2824 dest_rowstride = gdk_pixbuf_get_rowstride (dest);
2825 original_pixels = gdk_pixbuf_get_pixels (src);
2826 target_pixels = gdk_pixbuf_get_pixels (dest);
2828 for (i = 0; i < height; i++)
2830 pix_dest = target_pixels + i * dest_rowstride;
2831 pix_src = original_pixels + i * src_rowstride;
2833 for (j = 0; j < width; j++)
2840 *(pix_dest++) = CLAMP (val, 0, 255);
2843 *(pix_dest++) = CLAMP (val, 0, 255);
2846 *(pix_dest++) = CLAMP (val, 0, 255);
2849 *(pix_dest++) = *(pix_src++);
2855 should_prelight (GtkEntry *entry,
2856 GtkEntryIconPosition icon_pos)
2858 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2859 EntryIconInfo *icon_info = priv->icons[icon_pos];
2865 if (icon_info->nonactivatable && icon_info->target_list == NULL)
2868 if (icon_info->pressed)
2871 gtk_widget_style_get (GTK_WIDGET (entry),
2872 "prelight", &prelight,
2879 draw_icon (GtkWidget *widget,
2880 GtkEntryIconPosition icon_pos)
2882 GtkEntry *entry = GTK_ENTRY (widget);
2883 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2884 EntryIconInfo *icon_info = priv->icons[icon_pos];
2886 gint x, y, width, height;
2891 gtk_entry_ensure_pixbuf (entry, icon_pos);
2893 if (icon_info->pixbuf == NULL)
2896 gdk_drawable_get_size (icon_info->window, &width, &height);
2898 /* size_allocate hasn't been called yet. These are the default values.
2900 if (width == 1 || height == 1)
2903 pixbuf = icon_info->pixbuf;
2904 g_object_ref (pixbuf);
2906 if (gdk_pixbuf_get_height (pixbuf) > height)
2908 GdkPixbuf *temp_pixbuf;
2911 scale = height - 2 * priv->icon_margin;
2912 temp_pixbuf = gdk_pixbuf_scale_simple (pixbuf, scale, scale,
2913 GDK_INTERP_BILINEAR);
2914 g_object_unref (pixbuf);
2915 pixbuf = temp_pixbuf;
2918 x = (width - gdk_pixbuf_get_width (pixbuf)) / 2;
2919 y = (height - gdk_pixbuf_get_height (pixbuf)) / 2;
2921 if (!GTK_WIDGET_IS_SENSITIVE (widget) ||
2922 icon_info->insensitive)
2924 GdkPixbuf *temp_pixbuf;
2926 temp_pixbuf = gdk_pixbuf_copy (pixbuf);
2927 gdk_pixbuf_saturate_and_pixelate (pixbuf,
2931 g_object_unref (pixbuf);
2932 pixbuf = temp_pixbuf;
2934 else if (icon_info->prelight)
2936 GdkPixbuf *temp_pixbuf;
2938 temp_pixbuf = gdk_pixbuf_copy (pixbuf);
2939 colorshift_pixbuf (temp_pixbuf, pixbuf, 30);
2940 g_object_unref (pixbuf);
2941 pixbuf = temp_pixbuf;
2944 gdk_draw_pixbuf (icon_info->window, widget->style->black_gc, pixbuf,
2946 GDK_RGB_DITHER_NORMAL, 0, 0);
2948 g_object_unref (pixbuf);
2953 gtk_entry_draw_frame (GtkWidget *widget,
2956 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2957 gint x = 0, y = 0, width, height;
2958 gboolean state_hint;
2961 gdk_drawable_get_size (widget->window, &width, &height);
2963 /* Fix a problem with some themes which assume that entry->text_area's
2964 * width equals widget->window's width */
2965 if (GTK_IS_SPIN_BUTTON (widget))
2967 gint xborder, yborder;
2969 gtk_entry_get_text_area_size (GTK_ENTRY (widget), &x, NULL, &width, NULL);
2970 _gtk_entry_get_borders (GTK_ENTRY (widget), &xborder, &yborder);
2973 width += xborder * 2;
2976 if (GTK_WIDGET_HAS_FOCUS (widget) && !priv->interior_focus)
2978 x += priv->focus_width;
2979 y += priv->focus_width;
2980 width -= 2 * priv->focus_width;
2981 height -= 2 * priv->focus_width;
2984 gtk_widget_style_get (widget, "state-hint", &state_hint, NULL);
2986 state = GTK_WIDGET_HAS_FOCUS (widget) ?
2987 GTK_STATE_ACTIVE : GTK_WIDGET_STATE (widget);
2989 state = GTK_STATE_NORMAL;
2991 gtk_paint_shadow (widget->style, widget->window,
2992 state, priv->shadow_type,
2993 area, widget, "entry", x, y, width, height);
2995 if (GTK_WIDGET_HAS_FOCUS (widget) && !priv->interior_focus)
2997 x -= priv->focus_width;
2998 y -= priv->focus_width;
2999 width += 2 * priv->focus_width;
3000 height += 2 * priv->focus_width;
3002 gtk_paint_focus (widget->style, widget->window, GTK_WIDGET_STATE (widget),
3003 area, widget, "entry",
3004 0, 0, width, height);
3009 gtk_entry_draw_progress (GtkWidget *widget,
3010 GdkEventExpose *event)
3012 GtkEntryPrivate *private = GTK_ENTRY_GET_PRIVATE (widget);
3013 GtkEntry *entry = GTK_ENTRY (widget);
3015 if (private->progress_pulse_mode)
3017 gdouble value = private->progress_pulse_current;
3018 gint area_width, area_height;
3020 gdk_drawable_get_size (entry->text_area, &area_width, &area_height);
3022 gtk_paint_box (widget->style, entry->text_area,
3023 GTK_STATE_SELECTED, GTK_SHADOW_OUT,
3024 &event->area, widget, "entry-progress",
3025 value * area_width, 0,
3026 private->progress_pulse_fraction * area_width, area_height);
3028 else if (private->progress_fraction > 0)
3030 gdouble value = private->progress_fraction;
3031 gint area_width, area_height;
3033 gdk_drawable_get_size (entry->text_area, &area_width, &area_height);
3035 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
3037 gtk_paint_box (widget->style, entry->text_area,
3038 GTK_STATE_SELECTED, GTK_SHADOW_OUT,
3039 &event->area, widget, "entry-progress",
3040 area_width - value * area_width, 0,
3041 value * area_width, area_height);
3045 gtk_paint_box (widget->style, entry->text_area,
3046 GTK_STATE_SELECTED, GTK_SHADOW_OUT,
3047 &event->area, widget, "entry-progress",
3049 value * area_width, area_height);
3055 gtk_entry_expose (GtkWidget *widget,
3056 GdkEventExpose *event)
3058 GtkEntry *entry = GTK_ENTRY (widget);
3059 gboolean state_hint;
3061 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3063 gtk_widget_style_get (widget, "state-hint", &state_hint, NULL);
3065 state = GTK_WIDGET_HAS_FOCUS (widget) ?
3066 GTK_STATE_ACTIVE : GTK_WIDGET_STATE (widget);
3068 state = GTK_WIDGET_STATE(widget);
3070 if (widget->window == event->window)
3072 gtk_entry_draw_frame (widget, &event->area);
3074 else if (entry->text_area == event->window)
3078 gdk_drawable_get_size (entry->text_area, &width, &height);
3080 gtk_paint_flat_box (widget->style, entry->text_area,
3081 state, GTK_SHADOW_NONE,
3082 &event->area, widget, "entry_bg",
3083 0, 0, width, height);
3085 gtk_entry_draw_progress (widget, event);
3087 if (entry->dnd_position != -1)
3088 gtk_entry_draw_cursor (GTK_ENTRY (widget), CURSOR_DND);
3090 gtk_entry_draw_text (GTK_ENTRY (widget));
3092 if ((entry->visible || entry->invisible_char != 0) &&
3093 GTK_WIDGET_HAS_FOCUS (widget) &&
3094 entry->selection_bound == entry->current_pos && entry->cursor_visible)
3095 gtk_entry_draw_cursor (GTK_ENTRY (widget), CURSOR_STANDARD);
3101 for (i = 0; i < MAX_ICONS; i++)
3103 EntryIconInfo *icon_info = priv->icons[i];
3105 if (icon_info != NULL && event->window == icon_info->window)
3109 gdk_drawable_get_size (icon_info->window, &width, &height);
3111 gtk_paint_flat_box (widget->style, icon_info->window,
3112 GTK_WIDGET_STATE (widget), GTK_SHADOW_NONE,
3113 NULL, widget, "entry_bg",
3114 0, 0, width, height);
3116 draw_icon (widget, i);
3127 gtk_entry_enter_notify (GtkWidget *widget,
3128 GdkEventCrossing *event)
3130 GtkEntry *entry = GTK_ENTRY (widget);
3131 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3134 for (i = 0; i < MAX_ICONS; i++)
3136 EntryIconInfo *icon_info = priv->icons[i];
3138 if (icon_info != NULL && event->window == icon_info->window)
3140 if (should_prelight (entry, i))
3142 icon_info->prelight = TRUE;
3143 gtk_widget_queue_draw (widget);
3154 gtk_entry_leave_notify (GtkWidget *widget,
3155 GdkEventCrossing *event)
3157 GtkEntry *entry = GTK_ENTRY (widget);
3158 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3161 for (i = 0; i < MAX_ICONS; i++)
3163 EntryIconInfo *icon_info = priv->icons[i];
3165 if (icon_info != NULL && event->window == icon_info->window)
3167 if (should_prelight (entry, i))
3169 icon_info->prelight = FALSE;
3170 gtk_widget_queue_draw (widget);
3181 gtk_entry_get_pixel_ranges (GtkEntry *entry,
3185 gint start_char, end_char;
3187 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start_char, &end_char))
3189 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
3190 PangoLayoutLine *line = pango_layout_get_lines_readonly (layout)->data;
3191 const char *text = pango_layout_get_text (layout);
3192 gint start_index = g_utf8_offset_to_pointer (text, start_char) - text;
3193 gint end_index = g_utf8_offset_to_pointer (text, end_char) - text;
3194 gint real_n_ranges, i;
3196 pango_layout_line_get_x_ranges (line, start_index, end_index, ranges, &real_n_ranges);
3202 for (i = 0; i < real_n_ranges; ++i)
3204 r[2 * i + 1] = (r[2 * i + 1] - r[2 * i]) / PANGO_SCALE;
3205 r[2 * i] = r[2 * i] / PANGO_SCALE;
3210 *n_ranges = real_n_ranges;
3222 in_selection (GtkEntry *entry,
3227 gint retval = FALSE;
3229 gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
3231 for (i = 0; i < n_ranges; ++i)
3233 if (x >= ranges[2 * i] && x < ranges[2 * i] + ranges[2 * i + 1])
3245 gtk_entry_button_press (GtkWidget *widget,
3246 GdkEventButton *event)
3248 GtkEntry *entry = GTK_ENTRY (widget);
3249 GtkEditable *editable = GTK_EDITABLE (widget);
3250 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3251 EntryIconInfo *icon_info = NULL;
3253 gint sel_start, sel_end;
3256 for (i = 0; i < MAX_ICONS; i++)
3258 icon_info = priv->icons[i];
3260 if (!icon_info || icon_info->insensitive)
3263 if (event->window == icon_info->window)
3265 if (should_prelight (entry, i))
3267 icon_info->prelight = FALSE;
3268 gtk_widget_queue_draw (widget);
3271 priv->start_x = event->x;
3272 priv->start_y = event->y;
3273 icon_info->pressed = TRUE;
3275 if (!icon_info->nonactivatable)
3276 g_signal_emit (entry, signals[ICON_PRESS], 0, i, event);
3282 if (event->window != entry->text_area ||
3283 (entry->button && event->button != entry->button))
3286 gtk_entry_reset_blink_time (entry);
3288 entry->button = event->button;
3290 if (!GTK_WIDGET_HAS_FOCUS (widget))
3292 entry->in_click = TRUE;
3293 gtk_widget_grab_focus (widget);
3294 entry->in_click = FALSE;
3297 tmp_pos = gtk_entry_find_position (entry, event->x + entry->scroll_offset);
3299 if (event->button == 1)
3301 gboolean have_selection = gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end);
3303 entry->select_words = FALSE;
3304 entry->select_lines = FALSE;
3306 if (event->state & GDK_SHIFT_MASK)
3308 _gtk_entry_reset_im_context (entry);
3310 if (!have_selection) /* select from the current position to the clicked position */
3311 sel_start = sel_end = entry->current_pos;
3313 if (tmp_pos > sel_start && tmp_pos < sel_end)
3315 /* Truncate current selection, but keep it as big as possible */
3316 if (tmp_pos - sel_start > sel_end - tmp_pos)
3317 gtk_entry_set_positions (entry, sel_start, tmp_pos);
3319 gtk_entry_set_positions (entry, tmp_pos, sel_end);
3323 gboolean extend_to_left;
3326 /* Figure out what click selects and extend current selection */
3327 switch (event->type)
3329 case GDK_BUTTON_PRESS:
3330 gtk_entry_set_positions (entry, tmp_pos, tmp_pos);
3333 case GDK_2BUTTON_PRESS:
3334 entry->select_words = TRUE;
3335 gtk_entry_select_word (entry);
3338 case GDK_3BUTTON_PRESS:
3339 entry->select_lines = TRUE;
3340 gtk_entry_select_line (entry);
3347 start = MIN (entry->current_pos, entry->selection_bound);
3348 start = MIN (sel_start, start);
3350 end = MAX (entry->current_pos, entry->selection_bound);
3351 end = MAX (sel_end, end);
3353 if (tmp_pos == sel_start || tmp_pos == sel_end)
3354 extend_to_left = (tmp_pos == start);
3356 extend_to_left = (end == sel_end);
3359 gtk_entry_set_positions (entry, start, end);
3361 gtk_entry_set_positions (entry, end, start);
3364 else /* no shift key */
3365 switch (event->type)
3367 case GDK_BUTTON_PRESS:
3368 if (in_selection (entry, event->x + entry->scroll_offset))
3370 /* Click inside the selection - we'll either start a drag, or
3371 * clear the selection
3373 entry->in_drag = TRUE;
3374 entry->drag_start_x = event->x + entry->scroll_offset;
3375 entry->drag_start_y = event->y;
3378 gtk_editable_set_position (editable, tmp_pos);
3381 case GDK_2BUTTON_PRESS:
3382 /* We ALWAYS receive a GDK_BUTTON_PRESS immediately before
3383 * receiving a GDK_2BUTTON_PRESS so we need to reset
3384 * entry->in_drag which may have been set above
3386 entry->in_drag = FALSE;
3387 entry->select_words = TRUE;
3388 gtk_entry_select_word (entry);
3391 case GDK_3BUTTON_PRESS:
3392 /* We ALWAYS receive a GDK_BUTTON_PRESS immediately before
3393 * receiving a GDK_3BUTTON_PRESS so we need to reset
3394 * entry->in_drag which may have been set above
3396 entry->in_drag = FALSE;
3397 entry->select_lines = TRUE;
3398 gtk_entry_select_line (entry);
3407 else if (event->button == 2 && event->type == GDK_BUTTON_PRESS)
3409 if (entry->editable)
3411 priv->insert_pos = tmp_pos;
3412 gtk_entry_paste (entry, GDK_SELECTION_PRIMARY);
3417 gtk_widget_error_bell (widget);
3420 else if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
3422 gtk_entry_do_popup (entry, event);
3423 entry->button = 0; /* Don't wait for release, since the menu will gtk_grab_add */
3432 gtk_entry_button_release (GtkWidget *widget,
3433 GdkEventButton *event)
3435 GtkEntry *entry = GTK_ENTRY (widget);
3436 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
3437 EntryIconInfo *icon_info = NULL;
3440 for (i = 0; i < MAX_ICONS; i++)
3442 icon_info = priv->icons[i];
3444 if (!icon_info || icon_info->insensitive)
3447 if (event->window == icon_info->window)
3451 gdk_drawable_get_size (icon_info->window, &width, &height);
3453 icon_info->pressed = FALSE;
3455 if (should_prelight (entry, i) &&
3456 event->x >= 0 && event->y >= 0 &&
3457 event->x < width && event->y < height)
3459 icon_info->prelight = TRUE;
3460 gtk_widget_queue_draw (widget);
3463 if (!icon_info->nonactivatable)
3464 g_signal_emit (entry, signals[ICON_RELEASE], 0, i, event);
3470 if (event->window != entry->text_area || entry->button != event->button)
3475 gint tmp_pos = gtk_entry_find_position (entry, entry->drag_start_x);
3477 gtk_editable_set_position (GTK_EDITABLE (entry), tmp_pos);
3484 gtk_entry_update_primary_selection (entry);
3490 _gtk_entry_get_selected_text (GtkEntry *entry)
3492 GtkEditable *editable = GTK_EDITABLE (entry);
3493 gint start_text, end_text;
3496 if (gtk_editable_get_selection_bounds (editable, &start_text, &end_text))
3497 text = gtk_editable_get_chars (editable, start_text, end_text);
3503 gtk_entry_motion_notify (GtkWidget *widget,
3504 GdkEventMotion *event)
3506 GtkEntry *entry = GTK_ENTRY (widget);
3507 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3508 EntryIconInfo *icon_info = NULL;
3509 GdkDragContext *context;
3513 for (i = 0; i < MAX_ICONS; i++)
3515 icon_info = priv->icons[i];
3517 if (!icon_info || icon_info->insensitive)
3520 if (event->window == icon_info->window)
3522 if (icon_info->pressed &&
3523 icon_info->target_list != NULL &&
3524 gtk_drag_check_threshold (widget,
3530 icon_info->in_drag = TRUE;
3531 icon_info->pressed = FALSE;
3532 context = gtk_drag_begin (widget,
3533 icon_info->target_list,
3543 if (entry->mouse_cursor_obscured)
3547 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
3548 gdk_window_set_cursor (entry->text_area, cursor);
3549 gdk_cursor_unref (cursor);
3550 entry->mouse_cursor_obscured = FALSE;
3553 if (event->window != entry->text_area || entry->button != 1)
3556 if (entry->select_lines)
3559 gdk_event_request_motions (event);
3563 if (entry->visible &&
3564 gtk_drag_check_threshold (widget,
3565 entry->drag_start_x, entry->drag_start_y,
3566 event->x + entry->scroll_offset, event->y))
3568 GdkDragContext *context;
3569 GtkTargetList *target_list = gtk_target_list_new (NULL, 0);
3570 guint actions = entry->editable ? GDK_ACTION_COPY | GDK_ACTION_MOVE : GDK_ACTION_COPY;
3572 GdkPixmap *pixmap = NULL;
3574 gtk_target_list_add_text_targets (target_list, 0);
3576 text = _gtk_entry_get_selected_text (entry);
3577 pixmap = _gtk_text_util_create_drag_icon (widget, text, -1);
3579 context = gtk_drag_begin (widget, target_list, actions,
3580 entry->button, (GdkEvent *)event);
3583 gtk_drag_set_icon_pixmap (context,
3584 gdk_drawable_get_colormap (pixmap),
3589 gtk_drag_set_icon_default (context);
3592 g_object_unref (pixmap);
3595 entry->in_drag = FALSE;
3598 gtk_target_list_unref (target_list);
3604 gdk_drawable_get_size (entry->text_area, NULL, &height);
3608 else if (event->y >= height)
3609 tmp_pos = entry->text_length;
3611 tmp_pos = gtk_entry_find_position (entry, event->x + entry->scroll_offset);
3613 if (entry->select_words)
3616 gint old_min, old_max;
3619 min = gtk_entry_move_backward_word (entry, tmp_pos, TRUE);
3620 max = gtk_entry_move_forward_word (entry, tmp_pos, TRUE);
3622 pos = entry->current_pos;
3623 bound = entry->selection_bound;
3625 old_min = MIN(entry->current_pos, entry->selection_bound);
3626 old_max = MAX(entry->current_pos, entry->selection_bound);
3633 else if (old_max < max)
3638 else if (pos == old_min)
3640 if (entry->current_pos != min)
3645 if (entry->current_pos != max)
3649 gtk_entry_set_positions (entry, pos, bound);
3652 gtk_entry_set_positions (entry, tmp_pos, -1);
3659 set_invisible_cursor (GdkWindow *window)
3661 GdkBitmap *empty_bitmap;
3664 char invisible_cursor_bits[] = { 0x0 };
3666 useless.red = useless.green = useless.blue = 0;
3669 empty_bitmap = gdk_bitmap_create_from_data (window,
3670 invisible_cursor_bits,
3673 cursor = gdk_cursor_new_from_pixmap (empty_bitmap,
3678 gdk_window_set_cursor (window, cursor);
3680 gdk_cursor_unref (cursor);
3682 g_object_unref (empty_bitmap);
3686 gtk_entry_obscure_mouse_cursor (GtkEntry *entry)
3688 if (entry->mouse_cursor_obscured)
3691 set_invisible_cursor (entry->text_area);
3693 entry->mouse_cursor_obscured = TRUE;
3697 gtk_entry_key_press (GtkWidget *widget,
3700 GtkEntry *entry = GTK_ENTRY (widget);
3702 gtk_entry_reset_blink_time (entry);
3703 gtk_entry_pend_cursor_blink (entry);
3705 if (entry->editable)
3707 if (gtk_im_context_filter_keypress (entry->im_context, event))
3709 gtk_entry_obscure_mouse_cursor (entry);
3710 entry->need_im_reset = TRUE;
3715 if (event->keyval == GDK_Return ||
3716 event->keyval == GDK_KP_Enter ||
3717 event->keyval == GDK_ISO_Enter ||
3718 event->keyval == GDK_Escape)
3720 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
3722 if (completion && completion->priv->completion_timeout)
3724 g_source_remove (completion->priv->completion_timeout);
3725 completion->priv->completion_timeout = 0;
3728 _gtk_entry_reset_im_context (entry);
3731 if (GTK_WIDGET_CLASS (gtk_entry_parent_class)->key_press_event (widget, event))
3732 /* Activate key bindings
3736 if (!entry->editable && event->length)
3737 gtk_widget_error_bell (widget);
3743 gtk_entry_key_release (GtkWidget *widget,
3746 GtkEntry *entry = GTK_ENTRY (widget);
3748 if (entry->editable)
3750 if (gtk_im_context_filter_keypress (entry->im_context, event))
3752 entry->need_im_reset = TRUE;
3757 return GTK_WIDGET_CLASS (gtk_entry_parent_class)->key_release_event (widget, event);
3761 gtk_entry_focus_in (GtkWidget *widget,
3762 GdkEventFocus *event)
3764 GtkEntry *entry = GTK_ENTRY (widget);
3767 gtk_widget_queue_draw (widget);
3769 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (widget));
3771 if (entry->editable)
3773 entry->need_im_reset = TRUE;
3774 gtk_im_context_focus_in (entry->im_context);
3775 keymap_state_changed (keymap, entry);
3776 g_signal_connect (keymap, "state-changed",
3777 G_CALLBACK (keymap_state_changed), entry);
3780 g_signal_connect (keymap, "direction-changed",
3781 G_CALLBACK (keymap_direction_changed), entry);
3783 gtk_entry_reset_blink_time (entry);
3784 gtk_entry_check_cursor_blink (entry);
3790 gtk_entry_focus_out (GtkWidget *widget,
3791 GdkEventFocus *event)
3793 GtkEntry *entry = GTK_ENTRY (widget);
3794 GtkEntryCompletion *completion;
3797 gtk_widget_queue_draw (widget);
3799 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (widget));
3801 if (entry->editable)
3803 entry->need_im_reset = TRUE;
3804 gtk_im_context_focus_out (entry->im_context);
3805 remove_capslock_feedback (entry);
3808 gtk_entry_check_cursor_blink (entry);
3810 g_signal_handlers_disconnect_by_func (keymap, keymap_state_changed, entry);
3811 g_signal_handlers_disconnect_by_func (keymap, keymap_direction_changed, entry);
3813 completion = gtk_entry_get_completion (entry);
3815 _gtk_entry_completion_popdown (completion);
3821 gtk_entry_grab_focus (GtkWidget *widget)
3823 GtkEntry *entry = GTK_ENTRY (widget);
3824 gboolean select_on_focus;
3826 GTK_WIDGET_CLASS (gtk_entry_parent_class)->grab_focus (widget);
3828 if (entry->editable && !entry->in_click)
3830 g_object_get (gtk_widget_get_settings (widget),
3831 "gtk-entry-select-on-focus",
3835 if (select_on_focus)
3836 gtk_editable_select_region (GTK_EDITABLE (widget), 0, -1);
3841 gtk_entry_direction_changed (GtkWidget *widget,
3842 GtkTextDirection previous_dir)
3844 GtkEntry *entry = GTK_ENTRY (widget);
3846 gtk_entry_recompute (entry);
3848 GTK_WIDGET_CLASS (gtk_entry_parent_class)->direction_changed (widget, previous_dir);
3852 gtk_entry_state_changed (GtkWidget *widget,
3853 GtkStateType previous_state)
3855 GtkEntry *entry = GTK_ENTRY (widget);
3856 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
3860 if (GTK_WIDGET_REALIZED (widget))
3862 gdk_window_set_background (widget->window, &widget->style->base[GTK_WIDGET_STATE (widget)]);
3863 gdk_window_set_background (entry->text_area, &widget->style->base[GTK_WIDGET_STATE (widget)]);
3864 for (i = 0; i < MAX_ICONS; i++)
3866 EntryIconInfo *icon_info = priv->icons[i];
3867 if (icon_info && icon_info->window)
3868 gdk_window_set_background (icon_info->window, &widget->style->base[GTK_WIDGET_STATE (widget)]);
3871 if (GTK_WIDGET_IS_SENSITIVE (widget))
3872 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
3876 gdk_window_set_cursor (entry->text_area, cursor);
3879 gdk_cursor_unref (cursor);
3881 entry->mouse_cursor_obscured = FALSE;
3883 update_cursors (widget);
3886 if (!GTK_WIDGET_IS_SENSITIVE (widget))
3888 /* Clear any selection */
3889 gtk_editable_select_region (GTK_EDITABLE (entry), entry->current_pos, entry->current_pos);
3892 gtk_widget_queue_draw (widget);
3896 gtk_entry_screen_changed (GtkWidget *widget,
3897 GdkScreen *old_screen)
3899 gtk_entry_recompute (GTK_ENTRY (widget));
3902 /* GtkEditable method implementations
3905 gtk_entry_insert_text (GtkEditable *editable,
3906 const gchar *new_text,
3907 gint new_text_length,
3910 GtkEntry *entry = GTK_ENTRY (editable);
3914 if (*position < 0 || *position > entry->text_length)
3915 *position = entry->text_length;
3917 g_object_ref (editable);
3919 if (new_text_length <= 63)
3922 text = g_new (gchar, new_text_length + 1);
3924 text[new_text_length] = '\0';
3925 strncpy (text, new_text, new_text_length);
3927 g_signal_emit_by_name (editable, "insert-text", text, new_text_length, position);
3929 if (!entry->visible)
3930 trash_area (text, new_text_length);
3932 if (new_text_length > 63)
3935 g_object_unref (editable);
3939 gtk_entry_delete_text (GtkEditable *editable,
3943 GtkEntry *entry = GTK_ENTRY (editable);
3945 if (end_pos < 0 || end_pos > entry->text_length)
3946 end_pos = entry->text_length;
3949 if (start_pos > end_pos)
3950 start_pos = end_pos;
3952 g_object_ref (editable);
3954 g_signal_emit_by_name (editable, "delete-text", start_pos, end_pos);
3956 g_object_unref (editable);
3960 gtk_entry_get_chars (GtkEditable *editable,
3964 GtkEntry *entry = GTK_ENTRY (editable);
3965 gint start_index, end_index;
3968 end_pos = entry->text_length;
3970 start_pos = MIN (entry->text_length, start_pos);
3971 end_pos = MIN (entry->text_length, end_pos);
3973 start_index = g_utf8_offset_to_pointer (entry->text, start_pos) - entry->text;
3974 end_index = g_utf8_offset_to_pointer (entry->text, end_pos) - entry->text;
3976 return g_strndup (entry->text + start_index, end_index - start_index);
3980 gtk_entry_real_set_position (GtkEditable *editable,
3983 GtkEntry *entry = GTK_ENTRY (editable);
3985 if (position < 0 || position > entry->text_length)
3986 position = entry->text_length;
3988 if (position != entry->current_pos ||
3989 position != entry->selection_bound)
3991 _gtk_entry_reset_im_context (entry);
3992 gtk_entry_set_positions (entry, position, position);
3997 gtk_entry_get_position (GtkEditable *editable)
3999 return GTK_ENTRY (editable)->current_pos;
4003 gtk_entry_set_selection_bounds (GtkEditable *editable,
4007 GtkEntry *entry = GTK_ENTRY (editable);
4010 start = entry->text_length;
4012 end = entry->text_length;
4014 _gtk_entry_reset_im_context (entry);
4016 gtk_entry_set_positions (entry,
4017 MIN (end, entry->text_length),
4018 MIN (start, entry->text_length));
4020 gtk_entry_update_primary_selection (entry);
4024 gtk_entry_get_selection_bounds (GtkEditable *editable,
4028 GtkEntry *entry = GTK_ENTRY (editable);
4030 *start = entry->selection_bound;
4031 *end = entry->current_pos;
4033 return (entry->selection_bound != entry->current_pos);
4037 icon_theme_changed (GtkEntry *entry)
4039 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
4042 for (i = 0; i < MAX_ICONS; i++)
4044 EntryIconInfo *icon_info = priv->icons[i];
4045 if (icon_info != NULL)
4047 if (icon_info->storage_type == GTK_IMAGE_ICON_NAME)
4048 gtk_entry_set_icon_from_icon_name (entry, i, icon_info->icon_name);
4049 else if (icon_info->storage_type == GTK_IMAGE_STOCK)
4050 gtk_entry_set_icon_from_stock (entry, i, icon_info->stock_id);
4051 else if (icon_info->storage_type == GTK_IMAGE_GICON)
4052 gtk_entry_set_icon_from_gicon (entry, i, icon_info->gicon);
4056 gtk_widget_queue_draw (GTK_WIDGET (entry));
4060 icon_margin_changed (GtkEntry *entry)
4062 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
4065 _gtk_entry_effective_inner_border (GTK_ENTRY (entry), &border);
4067 priv->icon_margin = border.left;
4071 gtk_entry_style_set (GtkWidget *widget,
4072 GtkStyle *previous_style)
4074 GtkEntry *entry = GTK_ENTRY (widget);
4075 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
4077 gboolean interior_focus;
4080 gtk_widget_style_get (widget,
4081 "focus-line-width", &focus_width,
4082 "interior-focus", &interior_focus,
4085 priv->focus_width = focus_width;
4086 priv->interior_focus = interior_focus;
4088 if (!priv->invisible_char_set)
4089 entry->invisible_char = find_invisible_char (GTK_WIDGET (entry));
4091 gtk_entry_recompute (entry);
4093 if (previous_style && GTK_WIDGET_REALIZED (widget))
4095 gdk_window_set_background (widget->window, &widget->style->base[GTK_WIDGET_STATE (widget)]);
4096 gdk_window_set_background (entry->text_area, &widget->style->base[GTK_WIDGET_STATE (widget)]);
4097 for (i = 0; i < MAX_ICONS; i++)
4099 EntryIconInfo *icon_info = priv->icons[i];
4100 if (icon_info && icon_info->window)
4101 gdk_window_set_background (icon_info->window, &widget->style->base[GTK_WIDGET_STATE (widget)]);
4105 icon_theme_changed (entry);
4106 icon_margin_changed (entry);
4109 /* GtkCellEditable method implementations
4112 gtk_cell_editable_entry_activated (GtkEntry *entry, gpointer data)
4114 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4115 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4119 gtk_cell_editable_key_press_event (GtkEntry *entry,
4120 GdkEventKey *key_event,
4123 if (key_event->keyval == GDK_Escape)
4125 entry->editing_canceled = TRUE;
4126 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4127 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4132 /* override focus */
4133 if (key_event->keyval == GDK_Up || key_event->keyval == GDK_Down)
4135 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4136 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4145 gtk_entry_start_editing (GtkCellEditable *cell_editable,
4148 GTK_ENTRY (cell_editable)->is_cell_renderer = TRUE;
4150 g_signal_connect (cell_editable, "activate",
4151 G_CALLBACK (gtk_cell_editable_entry_activated), NULL);
4152 g_signal_connect (cell_editable, "key-press-event",
4153 G_CALLBACK (gtk_cell_editable_key_press_event), NULL);
4157 gtk_entry_password_hint_free (GtkEntryPasswordHint *password_hint)
4159 if (password_hint->password_hint_timeout_id)
4160 g_source_remove (password_hint->password_hint_timeout_id);
4162 g_slice_free (GtkEntryPasswordHint, password_hint);
4165 /* Default signal handlers
4168 gtk_entry_real_insert_text (GtkEditable *editable,
4169 const gchar *new_text,
4170 gint new_text_length,
4173 GtkEntry *entry = GTK_ENTRY (editable);
4177 if (new_text_length < 0)
4178 new_text_length = strlen (new_text);
4180 n_chars = g_utf8_strlen (new_text, new_text_length);
4181 if (entry->text_max_length > 0 && n_chars + entry->text_length > entry->text_max_length)
4183 gtk_widget_error_bell (GTK_WIDGET (entry));
4184 n_chars = entry->text_max_length - entry->text_length;
4185 new_text_length = g_utf8_offset_to_pointer (new_text, n_chars) - new_text;
4188 if (new_text_length + entry->n_bytes + 1 > entry->text_size)
4190 gsize prev_size = entry->text_size;
4192 while (new_text_length + entry->n_bytes + 1 > entry->text_size)
4194 if (entry->text_size == 0)
4195 entry->text_size = MIN_SIZE;
4198 if (2 * (guint)entry->text_size < MAX_SIZE &&
4199 2 * (guint)entry->text_size > entry->text_size)
4200 entry->text_size *= 2;
4203 entry->text_size = MAX_SIZE;
4204 if (new_text_length > (gint)entry->text_size - (gint)entry->n_bytes - 1)
4206 new_text_length = (gint)entry->text_size - (gint)entry->n_bytes - 1;
4207 new_text_length = g_utf8_find_prev_char (new_text, new_text + new_text_length + 1) - new_text;
4208 n_chars = g_utf8_strlen (new_text, new_text_length);
4216 entry->text = g_realloc (entry->text, entry->text_size);
4219 /* Same thing, just slower and without leaving stuff in memory. */
4220 gchar *et_new = g_malloc (entry->text_size);
4221 memcpy (et_new, entry->text, MIN (prev_size, entry->text_size));
4222 trash_area (entry->text, prev_size);
4223 g_free (entry->text);
4224 entry->text = et_new;
4228 index = g_utf8_offset_to_pointer (entry->text, *position) - entry->text;
4230 g_memmove (entry->text + index + new_text_length, entry->text + index, entry->n_bytes - index);
4231 memcpy (entry->text + index, new_text, new_text_length);
4233 entry->n_bytes += new_text_length;
4234 entry->text_length += n_chars;
4236 /* NUL terminate for safety and convenience */
4237 entry->text[entry->n_bytes] = '\0';
4239 if (entry->current_pos > *position)
4240 entry->current_pos += n_chars;
4242 if (entry->selection_bound > *position)
4243 entry->selection_bound += n_chars;
4245 if (n_chars == 1 && !entry->visible && (new_text_length < PASSWORD_HINT_MAX))
4247 guint password_hint_timeout;
4249 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
4250 "gtk-entry-password-hint-timeout", &password_hint_timeout,
4253 if (password_hint_timeout > 0)
4255 GtkEntryPasswordHint *password_hint = g_object_get_qdata (G_OBJECT (entry),
4256 quark_password_hint);
4260 password_hint = g_slice_new0 (GtkEntryPasswordHint);
4261 g_object_set_qdata_full (G_OBJECT (entry), quark_password_hint,
4263 (GDestroyNotify) gtk_entry_password_hint_free);
4266 memset (&password_hint->password_hint, 0x0, PASSWORD_HINT_MAX);
4267 password_hint->password_hint_length = new_text_length;
4268 memcpy (&password_hint->password_hint, new_text, new_text_length);
4269 password_hint->password_hint_position = *position + n_chars;
4274 g_object_set_qdata (G_OBJECT (entry), quark_password_hint, NULL);
4277 *position += n_chars;
4279 gtk_entry_recompute (entry);
4281 emit_changed (entry);
4282 g_object_notify (G_OBJECT (editable), "text");
4283 g_object_notify (G_OBJECT (editable), "text-length");
4287 gtk_entry_real_delete_text (GtkEditable *editable,
4291 GtkEntry *entry = GTK_ENTRY (editable);
4295 if (end_pos < 0 || end_pos > entry->text_length)
4296 end_pos = entry->text_length;
4298 if (start_pos < end_pos)
4300 gint start_index = g_utf8_offset_to_pointer (entry->text, start_pos) - entry->text;
4301 gint end_index = g_utf8_offset_to_pointer (entry->text, end_pos) - entry->text;
4303 gint selection_bound;
4305 g_memmove (entry->text + start_index, entry->text + end_index, entry->n_bytes + 1 - end_index);
4306 entry->text_length -= (end_pos - start_pos);
4307 entry->n_bytes -= (end_index - start_index);
4309 /* In password-mode, make sure we don't leave anything sensitive after
4310 * the terminating zero. Note, that the terminating zero already trashed
4313 if (!entry->visible)
4314 trash_area (entry->text + entry->n_bytes + 1, end_index - start_index - 1);
4316 current_pos = entry->current_pos;
4317 if (current_pos > start_pos)
4318 current_pos -= MIN (current_pos, end_pos) - start_pos;
4320 selection_bound = entry->selection_bound;
4321 if (selection_bound > start_pos)
4322 selection_bound -= MIN (selection_bound, end_pos) - start_pos;
4324 gtk_entry_set_positions (entry, current_pos, selection_bound);
4326 /* We might have deleted the selection
4328 gtk_entry_update_primary_selection (entry);
4330 gtk_entry_recompute (entry);
4332 emit_changed (entry);
4333 g_object_notify (G_OBJECT (editable), "text");
4334 g_object_notify (G_OBJECT (editable), "text-length");
4338 /* Compute the X position for an offset that corresponds to the "more important
4339 * cursor position for that offset. We use this when trying to guess to which
4340 * end of the selection we should go to when the user hits the left or
4344 get_better_cursor_x (GtkEntry *entry,
4347 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
4348 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
4349 gboolean split_cursor;
4351 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
4352 const gchar *text = pango_layout_get_text (layout);
4353 gint index = g_utf8_offset_to_pointer (text, offset) - text;
4355 PangoRectangle strong_pos, weak_pos;
4357 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
4358 "gtk-split-cursor", &split_cursor,
4361 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
4364 return strong_pos.x / PANGO_SCALE;
4366 return (keymap_direction == entry->resolved_dir) ? strong_pos.x / PANGO_SCALE : weak_pos.x / PANGO_SCALE;
4370 gtk_entry_move_cursor (GtkEntry *entry,
4371 GtkMovementStep step,
4373 gboolean extend_selection)
4375 gint new_pos = entry->current_pos;
4377 _gtk_entry_reset_im_context (entry);
4379 if (entry->current_pos != entry->selection_bound && !extend_selection)
4381 /* If we have a current selection and aren't extending it, move to the
4382 * start/or end of the selection as appropriate
4386 case GTK_MOVEMENT_VISUAL_POSITIONS:
4388 gint current_x = get_better_cursor_x (entry, entry->current_pos);
4389 gint bound_x = get_better_cursor_x (entry, entry->selection_bound);
4392 new_pos = current_x < bound_x ? entry->current_pos : entry->selection_bound;
4394 new_pos = current_x > bound_x ? entry->current_pos : entry->selection_bound;
4397 case GTK_MOVEMENT_LOGICAL_POSITIONS:
4398 case GTK_MOVEMENT_WORDS:
4400 new_pos = MIN (entry->current_pos, entry->selection_bound);
4402 new_pos = MAX (entry->current_pos, entry->selection_bound);
4404 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
4405 case GTK_MOVEMENT_PARAGRAPH_ENDS:
4406 case GTK_MOVEMENT_BUFFER_ENDS:
4407 new_pos = count < 0 ? 0 : entry->text_length;
4409 case GTK_MOVEMENT_DISPLAY_LINES:
4410 case GTK_MOVEMENT_PARAGRAPHS:
4411 case GTK_MOVEMENT_PAGES:
4412 case GTK_MOVEMENT_HORIZONTAL_PAGES:
4420 case GTK_MOVEMENT_LOGICAL_POSITIONS:
4421 new_pos = gtk_entry_move_logically (entry, new_pos, count);
4423 case GTK_MOVEMENT_VISUAL_POSITIONS:
4424 new_pos = gtk_entry_move_visually (entry, new_pos, count);
4425 if (entry->current_pos == new_pos)
4427 if (!extend_selection)
4429 if (!gtk_widget_keynav_failed (GTK_WIDGET (entry),
4431 GTK_DIR_RIGHT : GTK_DIR_LEFT))
4433 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (entry));
4436 gtk_widget_child_focus (toplevel,
4438 GTK_DIR_RIGHT : GTK_DIR_LEFT);
4443 gtk_widget_error_bell (GTK_WIDGET (entry));
4447 case GTK_MOVEMENT_WORDS:
4450 new_pos = gtk_entry_move_forward_word (entry, new_pos, FALSE);
4455 new_pos = gtk_entry_move_backward_word (entry, new_pos, FALSE);
4458 if (entry->current_pos == new_pos)
4459 gtk_widget_error_bell (GTK_WIDGET (entry));
4461 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
4462 case GTK_MOVEMENT_PARAGRAPH_ENDS:
4463 case GTK_MOVEMENT_BUFFER_ENDS:
4464 new_pos = count < 0 ? 0 : entry->text_length;
4465 if (entry->current_pos == new_pos)
4466 gtk_widget_error_bell (GTK_WIDGET (entry));
4468 case GTK_MOVEMENT_DISPLAY_LINES:
4469 case GTK_MOVEMENT_PARAGRAPHS:
4470 case GTK_MOVEMENT_PAGES:
4471 case GTK_MOVEMENT_HORIZONTAL_PAGES:
4476 if (extend_selection)
4477 gtk_editable_select_region (GTK_EDITABLE (entry), entry->selection_bound, new_pos);
4479 gtk_editable_set_position (GTK_EDITABLE (entry), new_pos);
4481 gtk_entry_pend_cursor_blink (entry);
4485 gtk_entry_insert_at_cursor (GtkEntry *entry,
4488 GtkEditable *editable = GTK_EDITABLE (entry);
4489 gint pos = entry->current_pos;
4491 if (entry->editable)
4493 _gtk_entry_reset_im_context (entry);
4495 gtk_editable_insert_text (editable, str, -1, &pos);
4496 gtk_editable_set_position (editable, pos);
4501 gtk_entry_delete_from_cursor (GtkEntry *entry,
4505 GtkEditable *editable = GTK_EDITABLE (entry);
4506 gint start_pos = entry->current_pos;
4507 gint end_pos = entry->current_pos;
4508 gint old_n_bytes = entry->n_bytes;
4510 _gtk_entry_reset_im_context (entry);
4512 if (!entry->editable)
4514 gtk_widget_error_bell (GTK_WIDGET (entry));
4518 if (entry->selection_bound != entry->current_pos)
4520 gtk_editable_delete_selection (editable);
4526 case GTK_DELETE_CHARS:
4527 end_pos = gtk_entry_move_logically (entry, entry->current_pos, count);
4528 gtk_editable_delete_text (editable, MIN (start_pos, end_pos), MAX (start_pos, end_pos));
4530 case GTK_DELETE_WORDS:
4533 /* Move to end of current word, or if not on a word, end of previous word */
4534 end_pos = gtk_entry_move_backward_word (entry, end_pos, FALSE);
4535 end_pos = gtk_entry_move_forward_word (entry, end_pos, FALSE);
4539 /* Move to beginning of current word, or if not on a word, begining of next word */
4540 start_pos = gtk_entry_move_forward_word (entry, start_pos, FALSE);
4541 start_pos = gtk_entry_move_backward_word (entry, start_pos, FALSE);
4545 case GTK_DELETE_WORD_ENDS:
4548 start_pos = gtk_entry_move_backward_word (entry, start_pos, FALSE);
4553 end_pos = gtk_entry_move_forward_word (entry, end_pos, FALSE);
4556 gtk_editable_delete_text (editable, start_pos, end_pos);
4558 case GTK_DELETE_DISPLAY_LINE_ENDS:
4559 case GTK_DELETE_PARAGRAPH_ENDS:
4561 gtk_editable_delete_text (editable, 0, entry->current_pos);
4563 gtk_editable_delete_text (editable, entry->current_pos, -1);
4565 case GTK_DELETE_DISPLAY_LINES:
4566 case GTK_DELETE_PARAGRAPHS:
4567 gtk_editable_delete_text (editable, 0, -1);
4569 case GTK_DELETE_WHITESPACE:
4570 gtk_entry_delete_whitespace (entry);
4574 if (entry->n_bytes == old_n_bytes)
4575 gtk_widget_error_bell (GTK_WIDGET (entry));
4577 gtk_entry_pend_cursor_blink (entry);
4581 gtk_entry_backspace (GtkEntry *entry)
4583 GtkEditable *editable = GTK_EDITABLE (entry);
4586 _gtk_entry_reset_im_context (entry);
4588 if (!entry->editable || !entry->text)
4590 gtk_widget_error_bell (GTK_WIDGET (entry));
4594 if (entry->selection_bound != entry->current_pos)
4596 gtk_editable_delete_selection (editable);
4600 prev_pos = gtk_entry_move_logically (entry, entry->current_pos, -1);
4602 if (prev_pos < entry->current_pos)
4604 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
4605 PangoLogAttr *log_attrs;
4608 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
4610 if (entry->visible &&
4611 log_attrs[entry->current_pos].backspace_deletes_character)
4613 gchar *cluster_text;
4614 gchar *normalized_text;
4617 cluster_text = gtk_editable_get_chars (editable,
4619 entry->current_pos);
4620 normalized_text = g_utf8_normalize (cluster_text,
4621 strlen (cluster_text),
4623 len = g_utf8_strlen (normalized_text, -1);
4625 gtk_editable_delete_text (editable, prev_pos, entry->current_pos);
4628 gint pos = entry->current_pos;
4630 gtk_editable_insert_text (editable, normalized_text,
4631 g_utf8_offset_to_pointer (normalized_text, len - 1) - normalized_text,
4633 gtk_editable_set_position (editable, pos);
4636 g_free (normalized_text);
4637 g_free (cluster_text);
4641 gtk_editable_delete_text (editable, prev_pos, entry->current_pos);
4648 gtk_widget_error_bell (GTK_WIDGET (entry));
4651 gtk_entry_pend_cursor_blink (entry);
4655 gtk_entry_copy_clipboard (GtkEntry *entry)
4657 GtkEditable *editable = GTK_EDITABLE (entry);
4661 if (gtk_editable_get_selection_bounds (editable, &start, &end))
4663 if (!entry->visible)
4665 gtk_widget_error_bell (GTK_WIDGET (entry));
4669 str = gtk_entry_get_public_chars (entry, start, end);
4670 gtk_clipboard_set_text (gtk_widget_get_clipboard (GTK_WIDGET (entry),
4671 GDK_SELECTION_CLIPBOARD),
4678 gtk_entry_cut_clipboard (GtkEntry *entry)
4680 GtkEditable *editable = GTK_EDITABLE (entry);
4683 if (!entry->visible)
4685 gtk_widget_error_bell (GTK_WIDGET (entry));
4689 gtk_entry_copy_clipboard (entry);
4691 if (entry->editable)
4693 if (gtk_editable_get_selection_bounds (editable, &start, &end))
4694 gtk_editable_delete_text (editable, start, end);
4698 gtk_widget_error_bell (GTK_WIDGET (entry));
4703 gtk_entry_paste_clipboard (GtkEntry *entry)
4705 if (entry->editable)
4706 gtk_entry_paste (entry, GDK_NONE);
4708 gtk_widget_error_bell (GTK_WIDGET (entry));
4712 gtk_entry_delete_cb (GtkEntry *entry)
4714 GtkEditable *editable = GTK_EDITABLE (entry);
4717 if (entry->editable)
4719 if (gtk_editable_get_selection_bounds (editable, &start, &end))
4720 gtk_editable_delete_text (editable, start, end);
4725 gtk_entry_toggle_overwrite (GtkEntry *entry)
4727 entry->overwrite_mode = !entry->overwrite_mode;
4728 gtk_entry_pend_cursor_blink (entry);
4729 gtk_widget_queue_draw (GTK_WIDGET (entry));
4733 gtk_entry_select_all (GtkEntry *entry)
4735 gtk_entry_select_line (entry);
4739 gtk_entry_real_activate (GtkEntry *entry)
4742 GtkWidget *toplevel;
4745 widget = GTK_WIDGET (entry);
4747 if (entry->activates_default)
4749 toplevel = gtk_widget_get_toplevel (widget);
4750 if (GTK_IS_WINDOW (toplevel))
4752 window = GTK_WINDOW (toplevel);
4755 widget != window->default_widget &&
4756 !(widget == window->focus_widget &&
4757 (!window->default_widget || !GTK_WIDGET_SENSITIVE (window->default_widget))))
4758 gtk_window_activate_default (window);
4764 keymap_direction_changed (GdkKeymap *keymap,
4767 gtk_entry_recompute (entry);
4770 /* IM Context Callbacks
4774 gtk_entry_commit_cb (GtkIMContext *context,
4778 if (entry->editable)
4779 gtk_entry_enter_text (entry, str);
4783 gtk_entry_preedit_changed_cb (GtkIMContext *context,
4786 if (entry->editable)
4788 gchar *preedit_string;
4791 gtk_im_context_get_preedit_string (entry->im_context,
4792 &preedit_string, NULL,
4794 entry->preedit_length = strlen (preedit_string);
4795 cursor_pos = CLAMP (cursor_pos, 0, g_utf8_strlen (preedit_string, -1));
4796 entry->preedit_cursor = cursor_pos;
4797 g_free (preedit_string);
4799 gtk_entry_recompute (entry);
4804 gtk_entry_retrieve_surrounding_cb (GtkIMContext *context,
4807 gtk_im_context_set_surrounding (context,
4810 g_utf8_offset_to_pointer (entry->text, entry->current_pos) - entry->text);
4816 gtk_entry_delete_surrounding_cb (GtkIMContext *slave,
4821 if (entry->editable)
4822 gtk_editable_delete_text (GTK_EDITABLE (entry),
4823 entry->current_pos + offset,
4824 entry->current_pos + offset + n_chars);
4829 /* Internal functions
4832 /* Used for im_commit_cb and inserting Unicode chars */
4834 gtk_entry_enter_text (GtkEntry *entry,
4837 GtkEditable *editable = GTK_EDITABLE (entry);
4839 gboolean old_need_im_reset;
4841 old_need_im_reset = entry->need_im_reset;
4842 entry->need_im_reset = FALSE;
4844 if (gtk_editable_get_selection_bounds (editable, NULL, NULL))
4845 gtk_editable_delete_selection (editable);
4848 if (entry->overwrite_mode)
4849 gtk_entry_delete_from_cursor (entry, GTK_DELETE_CHARS, 1);
4852 tmp_pos = entry->current_pos;
4853 gtk_editable_insert_text (editable, str, strlen (str), &tmp_pos);
4854 gtk_editable_set_position (editable, tmp_pos);
4856 entry->need_im_reset = old_need_im_reset;
4859 /* All changes to entry->current_pos and entry->selection_bound
4860 * should go through this function.
4863 gtk_entry_set_positions (GtkEntry *entry,
4865 gint selection_bound)
4867 gboolean changed = FALSE;
4869 g_object_freeze_notify (G_OBJECT (entry));
4871 if (current_pos != -1 &&
4872 entry->current_pos != current_pos)
4874 entry->current_pos = current_pos;
4877 g_object_notify (G_OBJECT (entry), "cursor-position");
4880 if (selection_bound != -1 &&
4881 entry->selection_bound != selection_bound)
4883 entry->selection_bound = selection_bound;
4886 g_object_notify (G_OBJECT (entry), "selection-bound");
4889 g_object_thaw_notify (G_OBJECT (entry));
4893 gtk_entry_move_adjustments (entry);
4894 gtk_entry_recompute (entry);
4899 gtk_entry_reset_layout (GtkEntry *entry)
4901 if (entry->cached_layout)
4903 g_object_unref (entry->cached_layout);
4904 entry->cached_layout = NULL;
4909 update_im_cursor_location (GtkEntry *entry)
4913 gint strong_xoffset;
4914 gint area_width, area_height;
4916 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
4917 gtk_entry_get_text_area_size (entry, NULL, NULL, &area_width, &area_height);
4919 strong_xoffset = strong_x - entry->scroll_offset;
4920 if (strong_xoffset < 0)
4924 else if (strong_xoffset > area_width)
4926 strong_xoffset = area_width;
4928 area.x = strong_xoffset;
4931 area.height = area_height;
4933 gtk_im_context_set_cursor_location (entry->im_context, &area);
4937 recompute_idle_func (gpointer data)
4941 entry = GTK_ENTRY (data);
4943 entry->recompute_idle = 0;
4945 if (gtk_widget_has_screen (GTK_WIDGET (entry)))
4947 gtk_entry_adjust_scroll (entry);
4948 gtk_entry_queue_draw (entry);
4950 update_im_cursor_location (entry);
4957 gtk_entry_recompute (GtkEntry *entry)
4959 gtk_entry_reset_layout (entry);
4960 gtk_entry_check_cursor_blink (entry);
4962 if (!entry->recompute_idle)
4964 entry->recompute_idle = gdk_threads_add_idle_full (G_PRIORITY_HIGH_IDLE + 15, /* between resize and redraw */
4965 recompute_idle_func, entry, NULL);
4970 append_char (GString *str,
4978 char_len = g_unichar_to_utf8 (ch, buf);
4983 g_string_append_len (str, buf, char_len);
4989 gtk_entry_remove_password_hint (gpointer data)
4991 /* Force the string to be redrawn, but now without a visible character */
4992 gtk_entry_recompute (GTK_ENTRY (data));
4997 static PangoLayout *
4998 gtk_entry_create_layout (GtkEntry *entry,
4999 gboolean include_preedit)
5001 GtkWidget *widget = GTK_WIDGET (entry);
5002 PangoLayout *layout = gtk_widget_create_pango_layout (widget, NULL);
5003 PangoAttrList *tmp_attrs = pango_attr_list_new ();
5005 gchar *preedit_string = NULL;
5006 gint preedit_length = 0;
5007 PangoAttrList *preedit_attrs = NULL;
5009 pango_layout_set_single_paragraph_mode (layout, TRUE);
5011 if (include_preedit)
5013 gtk_im_context_get_preedit_string (entry->im_context,
5014 &preedit_string, &preedit_attrs, NULL);
5015 preedit_length = entry->preedit_length;
5020 GString *tmp_string = g_string_new (NULL);
5022 gint cursor_index = g_utf8_offset_to_pointer (entry->text, entry->current_pos) - entry->text;
5026 g_string_prepend_len (tmp_string, entry->text, entry->n_bytes);
5027 g_string_insert (tmp_string, cursor_index, preedit_string);
5032 gunichar invisible_char;
5034 if (entry->invisible_char != 0)
5035 invisible_char = entry->invisible_char;
5037 invisible_char = ' '; /* just pick a char */
5039 ch_len = g_utf8_strlen (entry->text, entry->n_bytes);
5040 append_char (tmp_string, invisible_char, ch_len);
5042 g_utf8_offset_to_pointer (tmp_string->str, entry->current_pos) -
5044 g_string_insert (tmp_string, cursor_index, preedit_string);
5047 pango_layout_set_text (layout, tmp_string->str, tmp_string->len);
5049 pango_attr_list_splice (tmp_attrs, preedit_attrs,
5050 cursor_index, preedit_length);
5052 g_string_free (tmp_string, TRUE);
5056 PangoDirection pango_dir;
5059 pango_dir = pango_find_base_dir (entry->text, entry->n_bytes);
5062 pango_dir = PANGO_DIRECTION_NEUTRAL;
5064 if (pango_dir == PANGO_DIRECTION_NEUTRAL)
5066 if (GTK_WIDGET_HAS_FOCUS (widget))
5068 GdkDisplay *display = gtk_widget_get_display (widget);
5069 GdkKeymap *keymap = gdk_keymap_get_for_display (display);
5070 if (gdk_keymap_get_direction (keymap) == PANGO_DIRECTION_RTL)
5071 pango_dir = PANGO_DIRECTION_RTL;
5073 pango_dir = PANGO_DIRECTION_LTR;
5077 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
5078 pango_dir = PANGO_DIRECTION_RTL;
5080 pango_dir = PANGO_DIRECTION_LTR;
5084 pango_context_set_base_dir (gtk_widget_get_pango_context (widget),
5087 entry->resolved_dir = pango_dir;
5091 pango_layout_set_text (layout, entry->text, entry->n_bytes);
5095 GString *str = g_string_new (NULL);
5096 gunichar invisible_char;
5097 guint password_hint_timeout;
5098 GtkEntryPasswordHint *password_hint;
5100 g_object_get (gtk_widget_get_settings (widget),
5101 "gtk-entry-password-hint-timeout", &password_hint_timeout,
5104 if (entry->invisible_char != 0)
5105 invisible_char = entry->invisible_char;
5107 invisible_char = ' '; /* just pick a char */
5109 password_hint = g_object_get_qdata (G_OBJECT (entry),
5110 quark_password_hint);
5112 if (password_hint && password_hint->password_hint_timeout_id)
5114 g_source_remove (password_hint->password_hint_timeout_id);
5115 password_hint->password_hint_timeout_id = 0;
5118 if (password_hint_timeout == 0 || password_hint == NULL ||
5119 (password_hint && password_hint->password_hint_length == 0))
5121 append_char (str, invisible_char, entry->text_length);
5123 else if (password_hint)
5125 /* Draw hidden characters upto the inserted position,
5126 * then the real thing, pad up to full length
5128 if (password_hint->password_hint_position > 1)
5129 append_char (str, invisible_char,
5130 password_hint->password_hint_position - 1);
5132 g_string_append_len (str, password_hint->password_hint,
5133 password_hint->password_hint_length);
5135 if (password_hint->password_hint_position < entry->text_length)
5136 append_char (str, invisible_char,
5137 entry->text_length -
5138 password_hint->password_hint_position);
5140 /* Now remove this last input character, don't need
5143 memset (password_hint->password_hint, 0, PASSWORD_HINT_MAX);
5144 password_hint->password_hint_length = 0;
5146 password_hint->password_hint_timeout_id =
5147 gdk_threads_add_timeout (password_hint_timeout,
5148 (GSourceFunc) gtk_entry_remove_password_hint,
5152 pango_layout_set_text (layout, str->str, str->len);
5153 g_string_free (str, TRUE);
5157 pango_layout_set_attributes (layout, tmp_attrs);
5159 g_free (preedit_string);
5161 pango_attr_list_unref (preedit_attrs);
5163 pango_attr_list_unref (tmp_attrs);
5168 static PangoLayout *
5169 gtk_entry_ensure_layout (GtkEntry *entry,
5170 gboolean include_preedit)
5172 if (entry->preedit_length > 0 &&
5173 !include_preedit != !entry->cache_includes_preedit)
5174 gtk_entry_reset_layout (entry);
5176 if (!entry->cached_layout)
5178 entry->cached_layout = gtk_entry_create_layout (entry, include_preedit);
5179 entry->cache_includes_preedit = include_preedit;
5182 return entry->cached_layout;
5186 get_layout_position (GtkEntry *entry,
5190 PangoLayout *layout;
5191 PangoRectangle logical_rect;
5192 gint area_width, area_height;
5193 GtkBorder inner_border;
5195 PangoLayoutLine *line;
5197 layout = gtk_entry_ensure_layout (entry, TRUE);
5199 gtk_entry_get_text_area_size (entry, NULL, NULL, &area_width, &area_height);
5200 _gtk_entry_effective_inner_border (entry, &inner_border);
5202 area_height = PANGO_SCALE * (area_height - inner_border.top - inner_border.bottom);
5204 line = pango_layout_get_lines_readonly (layout)->data;
5205 pango_layout_line_get_extents (line, NULL, &logical_rect);
5207 /* Align primarily for locale's ascent/descent */
5208 y_pos = ((area_height - entry->ascent - entry->descent) / 2 +
5209 entry->ascent + logical_rect.y);
5211 /* Now see if we need to adjust to fit in actual drawn string */
5212 if (logical_rect.height > area_height)
5213 y_pos = (area_height - logical_rect.height) / 2;
5216 else if (y_pos + logical_rect.height > area_height)
5217 y_pos = area_height - logical_rect.height;
5219 y_pos = inner_border.top + y_pos / PANGO_SCALE;
5222 *x = inner_border.left - entry->scroll_offset;
5229 gtk_entry_draw_text (GtkEntry *entry)
5233 if (!entry->visible && entry->invisible_char == 0)
5236 if (GTK_WIDGET_DRAWABLE (entry))
5238 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
5241 gint start_pos, end_pos;
5243 widget = GTK_WIDGET (entry);
5245 get_layout_position (entry, &x, &y);
5247 cr = gdk_cairo_create (entry->text_area);
5249 cairo_move_to (cr, x, y);
5250 gdk_cairo_set_source_color (cr, &widget->style->text [widget->state]);
5251 pango_cairo_show_layout (cr, layout);
5253 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start_pos, &end_pos))
5257 PangoRectangle logical_rect;
5258 GdkColor *selection_color, *text_color;
5259 GtkBorder inner_border;
5261 pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
5262 gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
5264 if (GTK_WIDGET_HAS_FOCUS (entry))
5266 selection_color = &widget->style->base [GTK_STATE_SELECTED];
5267 text_color = &widget->style->text [GTK_STATE_SELECTED];
5271 selection_color = &widget->style->base [GTK_STATE_ACTIVE];
5272 text_color = &widget->style->text [GTK_STATE_ACTIVE];
5275 _gtk_entry_effective_inner_border (entry, &inner_border);
5277 for (i = 0; i < n_ranges; ++i)
5278 cairo_rectangle (cr,
5279 inner_border.left - entry->scroll_offset + ranges[2 * i],
5282 logical_rect.height);
5286 gdk_cairo_set_source_color (cr, selection_color);
5289 cairo_move_to (cr, x, y);
5290 gdk_cairo_set_source_color (cr, text_color);
5291 pango_cairo_show_layout (cr, layout);
5301 draw_insertion_cursor (GtkEntry *entry,
5302 GdkRectangle *cursor_location,
5303 gboolean is_primary,
5304 PangoDirection direction,
5305 gboolean draw_arrow)
5307 GtkWidget *widget = GTK_WIDGET (entry);
5308 GtkTextDirection text_dir;
5310 if (direction == PANGO_DIRECTION_LTR)
5311 text_dir = GTK_TEXT_DIR_LTR;
5313 text_dir = GTK_TEXT_DIR_RTL;
5315 gtk_draw_insertion_cursor (widget, entry->text_area, NULL,
5317 is_primary, text_dir, draw_arrow);
5321 gtk_entry_draw_cursor (GtkEntry *entry,
5324 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
5325 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
5327 if (GTK_WIDGET_DRAWABLE (entry))
5329 GtkWidget *widget = GTK_WIDGET (entry);
5330 GdkRectangle cursor_location;
5331 gboolean split_cursor;
5332 PangoRectangle cursor_rect;
5333 GtkBorder inner_border;
5335 gint text_area_height;
5338 gboolean block_at_line_end;
5339 PangoLayout *layout;
5342 _gtk_entry_effective_inner_border (entry, &inner_border);
5344 xoffset = inner_border.left - entry->scroll_offset;
5346 gdk_drawable_get_size (entry->text_area, NULL, &text_area_height);
5348 layout = gtk_entry_ensure_layout (entry, TRUE);
5349 text = pango_layout_get_text (layout);
5350 cursor_index = g_utf8_offset_to_pointer (text, entry->current_pos + entry->preedit_cursor) - text;
5351 if (!entry->overwrite_mode)
5354 block = _gtk_text_util_get_block_cursor_location (layout,
5355 cursor_index, &cursor_rect, &block_at_line_end);
5359 gint strong_x, weak_x;
5360 PangoDirection dir1 = PANGO_DIRECTION_NEUTRAL;
5361 PangoDirection dir2 = PANGO_DIRECTION_NEUTRAL;
5365 gtk_entry_get_cursor_locations (entry, type, &strong_x, &weak_x);
5367 g_object_get (gtk_widget_get_settings (widget),
5368 "gtk-split-cursor", &split_cursor,
5371 dir1 = entry->resolved_dir;
5377 if (weak_x != strong_x)
5379 dir2 = (entry->resolved_dir == PANGO_DIRECTION_LTR) ? PANGO_DIRECTION_RTL : PANGO_DIRECTION_LTR;
5385 if (keymap_direction == entry->resolved_dir)
5391 cursor_location.x = xoffset + x1;
5392 cursor_location.y = inner_border.top;
5393 cursor_location.width = 0;
5394 cursor_location.height = text_area_height - inner_border.top - inner_border.bottom;
5396 draw_insertion_cursor (entry,
5397 &cursor_location, TRUE, dir1,
5398 dir2 != PANGO_DIRECTION_NEUTRAL);
5400 if (dir2 != PANGO_DIRECTION_NEUTRAL)
5402 cursor_location.x = xoffset + x2;
5403 draw_insertion_cursor (entry,
5404 &cursor_location, FALSE, dir2,
5408 else /* overwrite_mode */
5410 GdkColor cursor_color;
5415 get_layout_position (entry, &x, &y);
5417 rect.x = PANGO_PIXELS (cursor_rect.x) + x;
5418 rect.y = PANGO_PIXELS (cursor_rect.y) + y;
5419 rect.width = PANGO_PIXELS (cursor_rect.width);
5420 rect.height = PANGO_PIXELS (cursor_rect.height);
5422 cr = gdk_cairo_create (entry->text_area);
5424 _gtk_widget_get_cursor_color (widget, &cursor_color);
5425 gdk_cairo_set_source_color (cr, &cursor_color);
5426 gdk_cairo_rectangle (cr, &rect);
5429 if (!block_at_line_end)
5431 gdk_cairo_rectangle (cr, &rect);
5433 cairo_move_to (cr, x, y);
5434 gdk_cairo_set_source_color (cr, &widget->style->base[widget->state]);
5435 pango_cairo_show_layout (cr, layout);
5444 gtk_entry_queue_draw (GtkEntry *entry)
5446 if (GTK_WIDGET_DRAWABLE (entry))
5447 gdk_window_invalidate_rect (entry->text_area, NULL, FALSE);
5451 _gtk_entry_reset_im_context (GtkEntry *entry)
5453 if (entry->need_im_reset)
5455 entry->need_im_reset = FALSE;
5456 gtk_im_context_reset (entry->im_context);
5461 gtk_entry_find_position (GtkEntry *entry,
5464 PangoLayout *layout;
5465 PangoLayoutLine *line;
5472 layout = gtk_entry_ensure_layout (entry, TRUE);
5473 text = pango_layout_get_text (layout);
5474 cursor_index = g_utf8_offset_to_pointer (text, entry->current_pos) - text;
5476 line = pango_layout_get_lines_readonly (layout)->data;
5477 pango_layout_line_x_to_index (line, x * PANGO_SCALE, &index, &trailing);
5479 if (index >= cursor_index && entry->preedit_length)
5481 if (index >= cursor_index + entry->preedit_length)
5482 index -= entry->preedit_length;
5485 index = cursor_index;
5490 pos = g_utf8_pointer_to_offset (text, text + index);
5497 gtk_entry_get_cursor_locations (GtkEntry *entry,
5502 if (!entry->visible && !entry->invisible_char)
5512 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
5513 const gchar *text = pango_layout_get_text (layout);
5514 PangoRectangle strong_pos, weak_pos;
5517 if (type == CURSOR_STANDARD)
5519 index = g_utf8_offset_to_pointer (text, entry->current_pos + entry->preedit_cursor) - text;
5521 else /* type == CURSOR_DND */
5523 index = g_utf8_offset_to_pointer (text, entry->dnd_position) - text;
5525 if (entry->dnd_position > entry->current_pos)
5528 index += entry->preedit_length;
5531 gint preedit_len_chars = g_utf8_strlen (text, -1) - entry->text_length;
5532 index += preedit_len_chars * g_unichar_to_utf8 (entry->invisible_char, NULL);
5537 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
5540 *strong_x = strong_pos.x / PANGO_SCALE;
5543 *weak_x = weak_pos.x / PANGO_SCALE;
5548 gtk_entry_adjust_scroll (GtkEntry *entry)
5550 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
5551 gint min_offset, max_offset;
5552 gint text_area_width, text_width;
5553 GtkBorder inner_border;
5554 gint strong_x, weak_x;
5555 gint strong_xoffset, weak_xoffset;
5557 PangoLayout *layout;
5558 PangoLayoutLine *line;
5559 PangoRectangle logical_rect;
5561 if (!GTK_WIDGET_REALIZED (entry))
5564 _gtk_entry_effective_inner_border (entry, &inner_border);
5566 gdk_drawable_get_size (entry->text_area, &text_area_width, NULL);
5567 text_area_width -= inner_border.left + inner_border.right;
5568 if (text_area_width < 0)
5569 text_area_width = 0;
5571 layout = gtk_entry_ensure_layout (entry, TRUE);
5572 line = pango_layout_get_lines_readonly (layout)->data;
5574 pango_layout_line_get_extents (line, NULL, &logical_rect);
5576 /* Display as much text as we can */
5578 if (entry->resolved_dir == PANGO_DIRECTION_LTR)
5579 xalign = priv->xalign;
5581 xalign = 1.0 - priv->xalign;
5583 text_width = PANGO_PIXELS(logical_rect.width);
5585 if (text_width > text_area_width)
5588 max_offset = text_width - text_area_width;
5592 min_offset = (text_width - text_area_width) * xalign;
5593 max_offset = min_offset;
5596 entry->scroll_offset = CLAMP (entry->scroll_offset, min_offset, max_offset);
5598 /* And make sure cursors are on screen. Note that the cursor is
5599 * actually drawn one pixel into the INNER_BORDER space on
5600 * the right, when the scroll is at the utmost right. This
5601 * looks better to to me than confining the cursor inside the
5602 * border entirely, though it means that the cursor gets one
5603 * pixel closer to the edge of the widget on the right than
5604 * on the left. This might need changing if one changed
5605 * INNER_BORDER from 2 to 1, as one would do on a
5606 * small-screen-real-estate display.
5608 * We always make sure that the strong cursor is on screen, and
5609 * put the weak cursor on screen if possible.
5612 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, &weak_x);
5614 strong_xoffset = strong_x - entry->scroll_offset;
5616 if (strong_xoffset < 0)
5618 entry->scroll_offset += strong_xoffset;
5621 else if (strong_xoffset > text_area_width)
5623 entry->scroll_offset += strong_xoffset - text_area_width;
5624 strong_xoffset = text_area_width;
5627 weak_xoffset = weak_x - entry->scroll_offset;
5629 if (weak_xoffset < 0 && strong_xoffset - weak_xoffset <= text_area_width)
5631 entry->scroll_offset += weak_xoffset;
5633 else if (weak_xoffset > text_area_width &&
5634 strong_xoffset - (weak_xoffset - text_area_width) >= 0)
5636 entry->scroll_offset += weak_xoffset - text_area_width;
5639 g_object_notify (G_OBJECT (entry), "scroll-offset");
5643 gtk_entry_move_adjustments (GtkEntry *entry)
5645 PangoContext *context;
5646 PangoFontMetrics *metrics;
5647 gint x, layout_x, border_x, border_y;
5649 GtkAdjustment *adjustment;
5651 adjustment = g_object_get_qdata (G_OBJECT (entry), quark_cursor_hadjustment);
5655 /* Cursor position, layout offset, border width, and widget allocation */
5656 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &x, NULL);
5657 get_layout_position (entry, &layout_x, NULL);
5658 _gtk_entry_get_borders (entry, &border_x, &border_y);
5659 x += entry->widget.allocation.x + layout_x + border_x;
5661 /* Approximate width of a char, so user can see what is ahead/behind */
5662 context = gtk_widget_get_pango_context (GTK_WIDGET (entry));
5663 metrics = pango_context_get_metrics (context,
5664 entry->widget.style->font_desc,
5665 pango_context_get_language (context));
5666 char_width = pango_font_metrics_get_approximate_char_width (metrics) / PANGO_SCALE;
5669 gtk_adjustment_clamp_page (adjustment,
5670 x - (char_width + 1), /* one char + one pixel before */
5671 x + (char_width + 2)); /* one char + cursor + one pixel after */
5675 gtk_entry_move_visually (GtkEntry *entry,
5680 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
5683 text = pango_layout_get_text (layout);
5685 index = g_utf8_offset_to_pointer (text, start) - text;
5689 int new_index, new_trailing;
5690 gboolean split_cursor;
5693 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
5694 "gtk-split-cursor", &split_cursor,
5701 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
5702 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
5704 strong = keymap_direction == entry->resolved_dir;
5709 pango_layout_move_cursor_visually (layout, strong, index, 0, 1, &new_index, &new_trailing);
5714 pango_layout_move_cursor_visually (layout, strong, index, 0, -1, &new_index, &new_trailing);
5720 else if (new_index != G_MAXINT)
5723 while (new_trailing--)
5724 index = g_utf8_next_char (text + index) - text;
5727 return g_utf8_pointer_to_offset (text, text + index);
5731 gtk_entry_move_logically (GtkEntry *entry,
5735 gint new_pos = start;
5737 /* Prevent any leak of information */
5738 if (!entry->visible)
5740 new_pos = CLAMP (start + count, 0, entry->text_length);
5742 else if (entry->text)
5744 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
5745 PangoLogAttr *log_attrs;
5748 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
5750 while (count > 0 && new_pos < entry->text_length)
5754 while (new_pos < entry->text_length && !log_attrs[new_pos].is_cursor_position);
5758 while (count < 0 && new_pos > 0)
5762 while (new_pos > 0 && !log_attrs[new_pos].is_cursor_position);
5774 gtk_entry_move_forward_word (GtkEntry *entry,
5776 gboolean allow_whitespace)
5778 gint new_pos = start;
5780 /* Prevent any leak of information */
5781 if (!entry->visible)
5783 new_pos = entry->text_length;
5785 else if (entry->text && (new_pos < entry->text_length))
5787 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
5788 PangoLogAttr *log_attrs;
5791 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
5793 /* Find the next word boundary */
5795 while (new_pos < n_attrs - 1 && !(log_attrs[new_pos].is_word_end ||
5796 (log_attrs[new_pos].is_word_start && allow_whitespace)))
5807 gtk_entry_move_backward_word (GtkEntry *entry,
5809 gboolean allow_whitespace)
5811 gint new_pos = start;
5813 /* Prevent any leak of information */
5814 if (!entry->visible)
5818 else if (entry->text && start > 0)
5820 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
5821 PangoLogAttr *log_attrs;
5824 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
5826 new_pos = start - 1;
5828 /* Find the previous word boundary */
5829 while (new_pos > 0 && !(log_attrs[new_pos].is_word_start ||
5830 (log_attrs[new_pos].is_word_end && allow_whitespace)))
5840 gtk_entry_delete_whitespace (GtkEntry *entry)
5842 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
5843 PangoLogAttr *log_attrs;
5847 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
5849 start = end = entry->current_pos;
5851 while (start > 0 && log_attrs[start-1].is_white)
5854 while (end < n_attrs && log_attrs[end].is_white)
5860 gtk_editable_delete_text (GTK_EDITABLE (entry), start, end);
5865 gtk_entry_select_word (GtkEntry *entry)
5867 gint start_pos = gtk_entry_move_backward_word (entry, entry->current_pos, TRUE);
5868 gint end_pos = gtk_entry_move_forward_word (entry, entry->current_pos, TRUE);
5870 gtk_editable_select_region (GTK_EDITABLE (entry), start_pos, end_pos);
5874 gtk_entry_select_line (GtkEntry *entry)
5876 gtk_editable_select_region (GTK_EDITABLE (entry), 0, -1);
5880 * Like gtk_editable_get_chars, but handle not-visible entries
5884 gtk_entry_get_public_chars (GtkEntry *entry,
5889 end = entry->text_length;
5892 return gtk_editable_get_chars (GTK_EDITABLE (entry), start, end);
5893 else if (!entry->invisible_char)
5894 return g_strdup ("");
5897 GString *str = g_string_new (NULL);
5898 append_char (str, entry->invisible_char, end - start);
5899 return g_string_free (str, FALSE);
5904 truncate_multiline (const gchar *text)
5909 text[length] && text[length] != '\n' && text[length] != '\r';
5916 paste_received (GtkClipboard *clipboard,
5920 GtkEntry *entry = GTK_ENTRY (data);
5921 GtkEditable *editable = GTK_EDITABLE (entry);
5922 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
5924 if (entry->button == 2)
5926 gint pos, start, end;
5927 pos = priv->insert_pos;
5928 gtk_editable_get_selection_bounds (editable, &start, &end);
5929 if (!((start <= pos && pos <= end) || (end <= pos && pos <= start)))
5930 gtk_editable_select_region (editable, pos, pos);
5935 gint pos, start, end;
5937 gboolean popup_completion;
5938 GtkEntryCompletion *completion;
5940 completion = gtk_entry_get_completion (entry);
5942 if (entry->truncate_multiline)
5943 length = truncate_multiline (text);
5945 /* only complete if the selection is at the end */
5946 popup_completion = (entry->text_length == MAX (entry->current_pos, entry->selection_bound));
5950 if (GTK_WIDGET_MAPPED (completion->priv->popup_window))
5951 _gtk_entry_completion_popdown (completion);
5953 if (!popup_completion && completion->priv->changed_id > 0)
5954 g_signal_handler_block (entry, completion->priv->changed_id);
5957 begin_change (entry);
5958 g_object_freeze_notify (G_OBJECT (entry));
5959 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5960 gtk_editable_delete_text (editable, start, end);
5962 pos = entry->current_pos;
5963 gtk_editable_insert_text (editable, text, length, &pos);
5964 gtk_editable_set_position (editable, pos);
5965 g_object_thaw_notify (G_OBJECT (entry));
5969 !popup_completion && completion->priv->changed_id > 0)
5970 g_signal_handler_unblock (entry, completion->priv->changed_id);
5973 g_object_unref (entry);
5977 gtk_entry_paste (GtkEntry *entry,
5980 g_object_ref (entry);
5981 gtk_clipboard_request_text (gtk_widget_get_clipboard (GTK_WIDGET (entry), selection),
5982 paste_received, entry);
5986 primary_get_cb (GtkClipboard *clipboard,
5987 GtkSelectionData *selection_data,
5991 GtkEntry *entry = GTK_ENTRY (data);
5994 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end))
5996 gchar *str = gtk_entry_get_public_chars (entry, start, end);
5997 gtk_selection_data_set_text (selection_data, str, -1);
6003 primary_clear_cb (GtkClipboard *clipboard,
6006 GtkEntry *entry = GTK_ENTRY (data);
6008 gtk_editable_select_region (GTK_EDITABLE (entry), entry->current_pos, entry->current_pos);
6012 gtk_entry_update_primary_selection (GtkEntry *entry)
6014 GtkTargetList *list;
6015 GtkTargetEntry *targets;
6016 GtkClipboard *clipboard;
6020 if (!GTK_WIDGET_REALIZED (entry))
6023 list = gtk_target_list_new (NULL, 0);
6024 gtk_target_list_add_text_targets (list, 0);
6026 targets = gtk_target_table_new_from_list (list, &n_targets);
6028 clipboard = gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_PRIMARY);
6030 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end))
6032 if (!gtk_clipboard_set_with_owner (clipboard, targets, n_targets,
6033 primary_get_cb, primary_clear_cb, G_OBJECT (entry)))
6034 primary_clear_cb (clipboard, entry);
6038 if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (entry))
6039 gtk_clipboard_clear (clipboard);
6042 gtk_target_table_free (targets, n_targets);
6043 gtk_target_list_unref (list);
6047 gtk_entry_clear (GtkEntry *entry,
6048 GtkEntryIconPosition icon_pos)
6050 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
6051 EntryIconInfo *icon_info = priv->icons[icon_pos];
6053 if (!icon_info || icon_info->storage_type == GTK_IMAGE_EMPTY)
6056 g_object_freeze_notify (G_OBJECT (entry));
6058 /* Explicitly check, as the pointer may become invalidated
6059 * during destruction.
6061 if (GDK_IS_WINDOW (icon_info->window))
6062 gdk_window_hide (icon_info->window);
6064 if (icon_info->pixbuf)
6066 g_object_unref (icon_info->pixbuf);
6067 icon_info->pixbuf = NULL;
6070 switch (icon_info->storage_type)
6072 case GTK_IMAGE_PIXBUF:
6073 g_object_notify (G_OBJECT (entry),
6074 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "pixbuf-primary" : "pixbuf-secondary");
6077 case GTK_IMAGE_STOCK:
6078 g_free (icon_info->stock_id);
6079 icon_info->stock_id = NULL;
6080 g_object_notify (G_OBJECT (entry),
6081 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "stock-primary" : "stock-secondary");
6084 case GTK_IMAGE_ICON_NAME:
6085 g_free (icon_info->icon_name);
6086 icon_info->icon_name = NULL;
6087 g_object_notify (G_OBJECT (entry),
6088 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "icon-name-primary" : "icon-name-secondary");
6091 case GTK_IMAGE_GICON:
6092 if (icon_info->gicon)
6094 g_object_unref (icon_info->gicon);
6095 icon_info->gicon = NULL;
6097 g_object_notify (G_OBJECT (entry),
6098 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "gicon-primary" : "gicon-secondary");
6102 g_assert_not_reached ();
6106 icon_info->storage_type = GTK_IMAGE_EMPTY;
6107 g_object_notify (G_OBJECT (entry),
6108 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "storage-type-primary" : "storage-type-secondary");
6110 g_object_thaw_notify (G_OBJECT (entry));
6114 gtk_entry_ensure_pixbuf (GtkEntry *entry,
6115 GtkEntryIconPosition icon_pos)
6117 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
6118 EntryIconInfo *icon_info = priv->icons[icon_pos];
6120 GtkIconTheme *icon_theme;
6121 GtkSettings *settings;
6125 if (!icon_info || icon_info->pixbuf)
6128 switch (icon_info->storage_type)
6130 case GTK_IMAGE_EMPTY:
6131 case GTK_IMAGE_PIXBUF:
6133 case GTK_IMAGE_STOCK:
6134 icon_info->pixbuf = gtk_widget_render_icon (GTK_WIDGET (entry),
6135 icon_info->stock_id,
6140 case GTK_IMAGE_ICON_NAME:
6141 screen = gtk_widget_get_screen (GTK_WIDGET (entry));
6144 icon_theme = gtk_icon_theme_get_for_screen (screen);
6145 settings = gtk_settings_get_for_screen (screen);
6147 gtk_icon_size_lookup_for_settings (settings,
6151 icon_info->pixbuf = gtk_icon_theme_load_icon (icon_theme,
6152 icon_info->icon_name,
6153 MIN (width, height),
6156 if (icon_info->pixbuf == NULL)
6157 icon_info->pixbuf = gtk_widget_render_icon (GTK_WIDGET (entry),
6158 GTK_STOCK_MISSING_IMAGE,
6164 case GTK_IMAGE_GICON:
6165 screen = gtk_widget_get_screen (GTK_WIDGET (entry));
6168 icon_theme = gtk_icon_theme_get_for_screen (screen);
6169 settings = gtk_settings_get_for_screen (screen);
6171 gtk_icon_size_lookup_for_settings (settings,
6175 info = gtk_icon_theme_lookup_by_gicon (icon_theme,
6177 MIN (width, height),
6178 GTK_ICON_LOOKUP_USE_BUILTIN);
6181 icon_info->pixbuf = gtk_icon_info_load_icon (info, NULL);
6182 gtk_icon_info_free (info);
6185 if (icon_info->pixbuf == NULL)
6186 icon_info->pixbuf = gtk_widget_render_icon (GTK_WIDGET (entry),
6187 GTK_STOCK_MISSING_IMAGE,
6194 g_assert_not_reached ();
6198 if (GDK_IS_WINDOW (icon_info->window))
6199 gdk_window_show (icon_info->window);
6209 * Creates a new entry.
6211 * Return value: a new #GtkEntry.
6214 gtk_entry_new (void)
6216 return g_object_new (GTK_TYPE_ENTRY, NULL);
6220 * gtk_entry_new_with_max_length:
6221 * @max: the maximum length of the entry, or 0 for no maximum.
6222 * (other than the maximum length of entries.) The value passed in will
6223 * be clamped to the range 0-65536.
6225 * Creates a new #GtkEntry widget with the given maximum length.
6227 * Return value: a new #GtkEntry
6229 * Deprecated: Use gtk_entry_set_max_length() instead.
6232 gtk_entry_new_with_max_length (gint max)
6236 max = CLAMP (max, 0, MAX_SIZE);
6238 entry = g_object_new (GTK_TYPE_ENTRY, NULL);
6239 entry->text_max_length = max;
6241 return GTK_WIDGET (entry);
6245 * gtk_entry_set_text:
6246 * @entry: a #GtkEntry
6247 * @text: the new text
6249 * Sets the text in the widget to the given
6250 * value, replacing the current contents.
6253 gtk_entry_set_text (GtkEntry *entry,
6257 GtkEntryCompletion *completion;
6259 g_return_if_fail (GTK_IS_ENTRY (entry));
6260 g_return_if_fail (text != NULL);
6262 /* Actually setting the text will affect the cursor and selection;
6263 * if the contents don't actually change, this will look odd to the user.
6265 if (strcmp (entry->text, text) == 0)
6268 completion = gtk_entry_get_completion (entry);
6269 if (completion && completion->priv->changed_id > 0)
6270 g_signal_handler_block (entry, completion->priv->changed_id);
6272 begin_change (entry);
6273 g_object_freeze_notify (G_OBJECT (entry));
6274 gtk_editable_delete_text (GTK_EDITABLE (entry), 0, -1);
6277 gtk_editable_insert_text (GTK_EDITABLE (entry), text, strlen (text), &tmp_pos);
6278 g_object_thaw_notify (G_OBJECT (entry));
6281 if (completion && completion->priv->changed_id > 0)
6282 g_signal_handler_unblock (entry, completion->priv->changed_id);
6286 * gtk_entry_append_text:
6287 * @entry: a #GtkEntry
6288 * @text: the text to append
6290 * Appends the given text to the contents of the widget.
6292 * Deprecated: 2.0: Use gtk_editable_insert_text() instead.
6295 gtk_entry_append_text (GtkEntry *entry,
6300 g_return_if_fail (GTK_IS_ENTRY (entry));
6301 g_return_if_fail (text != NULL);
6303 tmp_pos = entry->text_length;
6304 gtk_editable_insert_text (GTK_EDITABLE (entry), text, -1, &tmp_pos);
6308 * gtk_entry_prepend_text:
6309 * @entry: a #GtkEntry
6310 * @text: the text to prepend
6312 * Prepends the given text to the contents of the widget.
6314 * Deprecated: 2.0: Use gtk_editable_insert_text() instead.
6317 gtk_entry_prepend_text (GtkEntry *entry,
6322 g_return_if_fail (GTK_IS_ENTRY (entry));
6323 g_return_if_fail (text != NULL);
6326 gtk_editable_insert_text (GTK_EDITABLE (entry), text, -1, &tmp_pos);
6330 * gtk_entry_set_position:
6331 * @entry: a #GtkEntry
6332 * @position: the position of the cursor. The cursor is displayed
6333 * before the character with the given (base 0) index in the widget.
6334 * The value must be less than or equal to the number of characters
6335 * in the widget. A value of -1 indicates that the position should
6336 * be set after the last character in the entry. Note that this
6337 * position is in characters, not in bytes.
6339 * Sets the cursor position in an entry to the given value.
6341 * Deprecated: 2.0: Use gtk_editable_set_position() instead.
6344 gtk_entry_set_position (GtkEntry *entry,
6347 g_return_if_fail (GTK_IS_ENTRY (entry));
6349 gtk_editable_set_position (GTK_EDITABLE (entry), position);
6353 * gtk_entry_set_visibility:
6354 * @entry: a #GtkEntry
6355 * @visible: %TRUE if the contents of the entry are displayed
6358 * Sets whether the contents of the entry are visible or not.
6359 * When visibility is set to %FALSE, characters are displayed
6360 * as the invisible char, and will also appear that way when
6361 * the text in the entry widget is copied elsewhere.
6363 * By default, GTK+ picks the best invisible character available
6364 * in the current font, but it can be changed with
6365 * gtk_entry_set_invisible_char().
6368 gtk_entry_set_visibility (GtkEntry *entry,
6371 g_return_if_fail (GTK_IS_ENTRY (entry));
6373 visible = visible != FALSE;
6375 if (entry->visible != visible)
6377 entry->visible = visible;
6379 g_object_notify (G_OBJECT (entry), "visibility");
6380 gtk_entry_recompute (entry);
6385 * gtk_entry_get_visibility:
6386 * @entry: a #GtkEntry
6388 * Retrieves whether the text in @entry is visible. See
6389 * gtk_entry_set_visibility().
6391 * Return value: %TRUE if the text is currently visible
6394 gtk_entry_get_visibility (GtkEntry *entry)
6396 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
6398 return entry->visible;
6402 * gtk_entry_set_invisible_char:
6403 * @entry: a #GtkEntry
6404 * @ch: a Unicode character
6406 * Sets the character to use in place of the actual text when
6407 * gtk_entry_set_visibility() has been called to set text visibility
6408 * to %FALSE. i.e. this is the character used in "password mode" to
6409 * show the user how many characters have been typed. By default, GTK+
6410 * picks the best invisible char available in the current font. If you
6411 * set the invisible char to 0, then the user will get no feedback
6412 * at all; there will be no text on the screen as they type.
6415 gtk_entry_set_invisible_char (GtkEntry *entry,
6418 GtkEntryPrivate *priv;
6420 g_return_if_fail (GTK_IS_ENTRY (entry));
6422 priv = GTK_ENTRY_GET_PRIVATE (entry);
6424 if (!priv->invisible_char_set)
6426 priv->invisible_char_set = TRUE;
6427 g_object_notify (G_OBJECT (entry), "invisible-char-set");
6430 if (ch == entry->invisible_char)
6433 entry->invisible_char = ch;
6434 g_object_notify (G_OBJECT (entry), "invisible-char");
6435 gtk_entry_recompute (entry);
6439 * gtk_entry_get_invisible_char:
6440 * @entry: a #GtkEntry
6442 * Retrieves the character displayed in place of the real characters
6443 * for entries with visibility set to false. See gtk_entry_set_invisible_char().
6445 * Return value: the current invisible char, or 0, if the entry does not
6446 * show invisible text at all.
6449 gtk_entry_get_invisible_char (GtkEntry *entry)
6451 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
6453 return entry->invisible_char;
6457 * gtk_entry_unset_invisible_char:
6458 * @entry: a #GtkEntry
6460 * Unsets the invisible char previously set with
6461 * gtk_entry_set_invisible_char(). So that the
6462 * default invisible char is used again.
6467 gtk_entry_unset_invisible_char (GtkEntry *entry)
6469 GtkEntryPrivate *priv;
6472 g_return_if_fail (GTK_IS_ENTRY (entry));
6474 priv = GTK_ENTRY_GET_PRIVATE (entry);
6476 if (!priv->invisible_char_set)
6479 priv->invisible_char_set = FALSE;
6480 ch = find_invisible_char (GTK_WIDGET (entry));
6482 if (entry->invisible_char != ch)
6484 entry->invisible_char = ch;
6485 g_object_notify (G_OBJECT (entry), "invisible-char");
6488 g_object_notify (G_OBJECT (entry), "invisible-char-set");
6489 gtk_entry_recompute (entry);
6493 * gtk_entry_set_editable:
6494 * @entry: a #GtkEntry
6495 * @editable: %TRUE if the user is allowed to edit the text
6498 * Determines if the user can edit the text in the editable
6501 * Deprecated: 2.0: Use gtk_editable_set_editable() instead.
6504 gtk_entry_set_editable (GtkEntry *entry,
6507 g_return_if_fail (GTK_IS_ENTRY (entry));
6509 gtk_editable_set_editable (GTK_EDITABLE (entry), editable);
6513 * gtk_entry_set_overwrite_mode:
6514 * @entry: a #GtkEntry
6515 * @overwrite: new value
6517 * Sets whether the text is overwritten when typing in the #GtkEntry.
6522 gtk_entry_set_overwrite_mode (GtkEntry *entry,
6525 g_return_if_fail (GTK_IS_ENTRY (entry));
6527 if (entry->overwrite_mode == overwrite)
6530 gtk_entry_toggle_overwrite (entry);
6532 g_object_notify (G_OBJECT (entry), "overwrite-mode");
6536 * gtk_entry_get_overwrite_mode:
6537 * @entry: a #GtkEntry
6539 * Gets the value set by gtk_entry_set_overwrite_mode().
6541 * Return value: whether the text is overwritten when typing.
6546 gtk_entry_get_overwrite_mode (GtkEntry *entry)
6548 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
6550 return entry->overwrite_mode;
6554 * gtk_entry_get_text:
6555 * @entry: a #GtkEntry
6557 * Retrieves the contents of the entry widget.
6558 * See also gtk_editable_get_chars().
6560 * Return value: a pointer to the contents of the widget as a
6561 * string. This string points to internally allocated
6562 * storage in the widget and must not be freed, modified or
6565 G_CONST_RETURN gchar*
6566 gtk_entry_get_text (GtkEntry *entry)
6568 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
6574 * gtk_entry_select_region:
6575 * @entry: a #GtkEntry
6576 * @start: the starting position
6577 * @end: the end position
6579 * Selects a region of text. The characters that are selected are
6580 * those characters at positions from @start_pos up to, but not
6581 * including @end_pos. If @end_pos is negative, then the the characters
6582 * selected will be those characters from @start_pos to the end of
6585 * Deprecated: 2.0: Use gtk_editable_select_region() instead.
6588 gtk_entry_select_region (GtkEntry *entry,
6592 gtk_editable_select_region (GTK_EDITABLE (entry), start, end);
6596 * gtk_entry_set_max_length:
6597 * @entry: a #GtkEntry
6598 * @max: the maximum length of the entry, or 0 for no maximum.
6599 * (other than the maximum length of entries.) The value passed in will
6600 * be clamped to the range 0-65536.
6602 * Sets the maximum allowed length of the contents of the widget. If
6603 * the current contents are longer than the given length, then they
6604 * will be truncated to fit.
6607 gtk_entry_set_max_length (GtkEntry *entry,
6610 g_return_if_fail (GTK_IS_ENTRY (entry));
6612 max = CLAMP (max, 0, MAX_SIZE);
6614 if (max > 0 && entry->text_length > max)
6615 gtk_editable_delete_text (GTK_EDITABLE (entry), max, -1);
6617 entry->text_max_length = max;
6618 g_object_notify (G_OBJECT (entry), "max-length");
6622 * gtk_entry_get_max_length:
6623 * @entry: a #GtkEntry
6625 * Retrieves the maximum allowed length of the text in
6626 * @entry. See gtk_entry_set_max_length().
6628 * Return value: the maximum allowed number of characters
6629 * in #GtkEntry, or 0 if there is no maximum.
6632 gtk_entry_get_max_length (GtkEntry *entry)
6634 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
6636 return entry->text_max_length;
6640 * gtk_entry_get_text_length:
6641 * @entry: a #GtkEntry
6643 * Retrieves the current length of the text in
6646 * Return value: the current number of characters
6647 * in #GtkEntry, or 0 if there are none.
6652 gtk_entry_get_text_length (GtkEntry *entry)
6654 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
6656 return entry->text_length;
6660 * gtk_entry_set_activates_default:
6661 * @entry: a #GtkEntry
6662 * @setting: %TRUE to activate window's default widget on Enter keypress
6664 * If @setting is %TRUE, pressing Enter in the @entry will activate the default
6665 * widget for the window containing the entry. This usually means that
6666 * the dialog box containing the entry will be closed, since the default
6667 * widget is usually one of the dialog buttons.
6669 * (For experts: if @setting is %TRUE, the entry calls
6670 * gtk_window_activate_default() on the window containing the entry, in
6671 * the default handler for the #GtkWidget::activate signal.)
6674 gtk_entry_set_activates_default (GtkEntry *entry,
6677 g_return_if_fail (GTK_IS_ENTRY (entry));
6678 setting = setting != FALSE;
6680 if (setting != entry->activates_default)
6682 entry->activates_default = setting;
6683 g_object_notify (G_OBJECT (entry), "activates-default");
6688 * gtk_entry_get_activates_default:
6689 * @entry: a #GtkEntry
6691 * Retrieves the value set by gtk_entry_set_activates_default().
6693 * Return value: %TRUE if the entry will activate the default widget
6696 gtk_entry_get_activates_default (GtkEntry *entry)
6698 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
6700 return entry->activates_default;
6704 * gtk_entry_set_width_chars:
6705 * @entry: a #GtkEntry
6706 * @n_chars: width in chars
6708 * Changes the size request of the entry to be about the right size
6709 * for @n_chars characters. Note that it changes the size
6710 * <emphasis>request</emphasis>, the size can still be affected by
6711 * how you pack the widget into containers. If @n_chars is -1, the
6712 * size reverts to the default entry size.
6715 gtk_entry_set_width_chars (GtkEntry *entry,
6718 g_return_if_fail (GTK_IS_ENTRY (entry));
6720 if (entry->width_chars != n_chars)
6722 entry->width_chars = n_chars;
6723 g_object_notify (G_OBJECT (entry), "width-chars");
6724 gtk_widget_queue_resize (GTK_WIDGET (entry));
6729 * gtk_entry_get_width_chars:
6730 * @entry: a #GtkEntry
6732 * Gets the value set by gtk_entry_set_width_chars().
6734 * Return value: number of chars to request space for, or negative if unset
6737 gtk_entry_get_width_chars (GtkEntry *entry)
6739 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
6741 return entry->width_chars;
6745 * gtk_entry_set_has_frame:
6746 * @entry: a #GtkEntry
6747 * @setting: new value
6749 * Sets whether the entry has a beveled frame around it.
6752 gtk_entry_set_has_frame (GtkEntry *entry,
6755 g_return_if_fail (GTK_IS_ENTRY (entry));
6757 setting = (setting != FALSE);
6759 if (entry->has_frame == setting)
6762 gtk_widget_queue_resize (GTK_WIDGET (entry));
6763 entry->has_frame = setting;
6764 g_object_notify (G_OBJECT (entry), "has-frame");
6768 * gtk_entry_get_has_frame:
6769 * @entry: a #GtkEntry
6771 * Gets the value set by gtk_entry_set_has_frame().
6773 * Return value: whether the entry has a beveled frame
6776 gtk_entry_get_has_frame (GtkEntry *entry)
6778 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
6780 return entry->has_frame;
6784 * gtk_entry_set_inner_border:
6785 * @entry: a #GtkEntry
6786 * @border: a #GtkBorder, or %NULL
6788 * Sets %entry's inner-border property to %border, or clears it if %NULL
6789 * is passed. The inner-border is the area around the entry's text, but
6792 * If set, this property overrides the inner-border style property.
6793 * Overriding the style-provided border is useful when you want to do
6794 * in-place editing of some text in a canvas or list widget, where
6795 * pixel-exact positioning of the entry is important.
6800 gtk_entry_set_inner_border (GtkEntry *entry,
6801 const GtkBorder *border)
6803 g_return_if_fail (GTK_IS_ENTRY (entry));
6805 gtk_widget_queue_resize (GTK_WIDGET (entry));
6808 g_object_set_qdata_full (G_OBJECT (entry), quark_inner_border,
6809 gtk_border_copy (border),
6810 (GDestroyNotify) gtk_border_free);
6812 g_object_set_qdata (G_OBJECT (entry), quark_inner_border, NULL);
6814 g_object_notify (G_OBJECT (entry), "inner-border");
6818 * gtk_entry_get_inner_border:
6819 * @entry: a #GtkEntry
6821 * This function returns the entry's #GtkEntry:inner-border property. See
6822 * gtk_entry_set_inner_border() for more information.
6824 * Return value: the entry's #GtkBorder, or %NULL if none was set.
6828 G_CONST_RETURN GtkBorder *
6829 gtk_entry_get_inner_border (GtkEntry *entry)
6831 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
6833 return g_object_get_qdata (G_OBJECT (entry), quark_inner_border);
6837 * gtk_entry_get_layout:
6838 * @entry: a #GtkEntry
6840 * Gets the #PangoLayout used to display the entry.
6841 * The layout is useful to e.g. convert text positions to
6842 * pixel positions, in combination with gtk_entry_get_layout_offsets().
6843 * The returned layout is owned by the entry and must not be
6844 * modified or freed by the caller.
6846 * Keep in mind that the layout text may contain a preedit string, so
6847 * gtk_entry_layout_index_to_text_index() and
6848 * gtk_entry_text_index_to_layout_index() are needed to convert byte
6849 * indices in the layout to byte indices in the entry contents.
6851 * Return value: the #PangoLayout for this entry
6854 gtk_entry_get_layout (GtkEntry *entry)
6856 PangoLayout *layout;
6858 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
6860 layout = gtk_entry_ensure_layout (entry, TRUE);
6867 * gtk_entry_layout_index_to_text_index:
6868 * @entry: a #GtkEntry
6869 * @layout_index: byte index into the entry layout text
6871 * Converts from a position in the entry contents (returned
6872 * by gtk_entry_get_text()) to a position in the
6873 * entry's #PangoLayout (returned by gtk_entry_get_layout(),
6874 * with text retrieved via pango_layout_get_text()).
6876 * Return value: byte index into the entry contents
6879 gtk_entry_layout_index_to_text_index (GtkEntry *entry,
6882 PangoLayout *layout;
6886 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
6888 layout = gtk_entry_ensure_layout (entry, TRUE);
6889 text = pango_layout_get_text (layout);
6890 cursor_index = g_utf8_offset_to_pointer (text, entry->current_pos) - text;
6892 if (layout_index >= cursor_index && entry->preedit_length)
6894 if (layout_index >= cursor_index + entry->preedit_length)
6895 layout_index -= entry->preedit_length;
6897 layout_index = cursor_index;
6900 return layout_index;
6904 * gtk_entry_text_index_to_layout_index:
6905 * @entry: a #GtkEntry
6906 * @text_index: byte index into the entry contents
6908 * Converts from a position in the entry's #PangoLayout (returned by
6909 * gtk_entry_get_layout()) to a position in the entry contents
6910 * (returned by gtk_entry_get_text()).
6912 * Return value: byte index into the entry layout text
6915 gtk_entry_text_index_to_layout_index (GtkEntry *entry,
6918 PangoLayout *layout;
6921 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
6923 layout = gtk_entry_ensure_layout (entry, TRUE);
6924 text = pango_layout_get_text (layout);
6925 cursor_index = g_utf8_offset_to_pointer (text, entry->current_pos) - text;
6927 if (text_index > cursor_index)
6928 text_index += entry->preedit_length;
6934 * gtk_entry_get_layout_offsets:
6935 * @entry: a #GtkEntry
6936 * @x: location to store X offset of layout, or %NULL
6937 * @y: location to store Y offset of layout, or %NULL
6940 * Obtains the position of the #PangoLayout used to render text
6941 * in the entry, in widget coordinates. Useful if you want to line
6942 * up the text in an entry with some other text, e.g. when using the
6943 * entry to implement editable cells in a sheet widget.
6945 * Also useful to convert mouse events into coordinates inside the
6946 * #PangoLayout, e.g. to take some action if some part of the entry text
6949 * Note that as the user scrolls around in the entry the offsets will
6950 * change; you'll need to connect to the "notify::scroll-offset"
6951 * signal to track this. Remember when using the #PangoLayout
6952 * functions you need to convert to and from pixels using
6953 * PANGO_PIXELS() or #PANGO_SCALE.
6955 * Keep in mind that the layout text may contain a preedit string, so
6956 * gtk_entry_layout_index_to_text_index() and
6957 * gtk_entry_text_index_to_layout_index() are needed to convert byte
6958 * indices in the layout to byte indices in the entry contents.
6961 gtk_entry_get_layout_offsets (GtkEntry *entry,
6965 gint text_area_x, text_area_y;
6967 g_return_if_fail (GTK_IS_ENTRY (entry));
6969 /* this gets coords relative to text area */
6970 get_layout_position (entry, x, y);
6972 /* convert to widget coords */
6973 gtk_entry_get_text_area_size (entry, &text_area_x, &text_area_y, NULL, NULL);
6984 * gtk_entry_set_alignment:
6985 * @entry: a #GtkEntry
6986 * @xalign: The horizontal alignment, from 0 (left) to 1 (right).
6987 * Reversed for RTL layouts
6989 * Sets the alignment for the contents of the entry. This controls
6990 * the horizontal positioning of the contents when the displayed
6991 * text is shorter than the width of the entry.
6996 gtk_entry_set_alignment (GtkEntry *entry, gfloat xalign)
6998 GtkEntryPrivate *priv;
7000 g_return_if_fail (GTK_IS_ENTRY (entry));
7002 priv = GTK_ENTRY_GET_PRIVATE (entry);
7006 else if (xalign > 1.0)
7009 if (xalign != priv->xalign)
7011 priv->xalign = xalign;
7013 gtk_entry_recompute (entry);
7015 g_object_notify (G_OBJECT (entry), "xalign");
7020 * gtk_entry_get_alignment:
7021 * @entry: a #GtkEntry
7023 * Gets the value set by gtk_entry_set_alignment().
7025 * Return value: the alignment
7030 gtk_entry_get_alignment (GtkEntry *entry)
7032 GtkEntryPrivate *priv;
7034 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
7036 priv = GTK_ENTRY_GET_PRIVATE (entry);
7038 return priv->xalign;
7042 * gtk_entry_set_icon_from_pixbuf:
7043 * @entry: a #GtkEntry
7044 * @icon_pos: Icon position
7045 * @pixbuf: A #GdkPixbuf, or %NULL
7047 * Sets the icon shown in the specified position using a pixbuf.
7049 * If @pixbuf is %NULL, no icon will be shown in the specified position.
7054 gtk_entry_set_icon_from_pixbuf (GtkEntry *entry,
7055 GtkEntryIconPosition icon_pos,
7058 GtkEntryPrivate *priv;
7059 EntryIconInfo *icon_info;
7061 g_return_if_fail (GTK_IS_ENTRY (entry));
7062 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7064 priv = GTK_ENTRY_GET_PRIVATE (entry);
7066 if ((icon_info = priv->icons[icon_pos]) == NULL)
7067 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7069 g_object_freeze_notify (G_OBJECT (entry));
7072 g_object_ref (pixbuf);
7074 gtk_entry_clear (entry, icon_pos);
7078 icon_info->storage_type = GTK_IMAGE_PIXBUF;
7079 icon_info->pixbuf = pixbuf;
7081 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7083 g_object_notify (G_OBJECT (entry), "pixbuf-primary");
7084 g_object_notify (G_OBJECT (entry), "storage-type-primary");
7088 g_object_notify (G_OBJECT (entry), "pixbuf-secondary");
7089 g_object_notify (G_OBJECT (entry), "storage-type-secondary");
7093 gtk_entry_ensure_pixbuf (entry, icon_pos);
7095 if (GTK_WIDGET_VISIBLE (entry))
7096 gtk_widget_queue_resize (GTK_WIDGET (entry));
7098 g_object_thaw_notify (G_OBJECT (entry));
7102 * gtk_entry_set_icon_from_stock:
7103 * @entry: A #GtkEntry
7104 * @icon_pos: Icon position
7105 * @stock_id: The name of the stock item, or %NULL
7107 * Sets the icon shown in the entry at the specified position from
7110 * If @stock_id is %NULL, no icon will be shown in the specified position.
7115 gtk_entry_set_icon_from_stock (GtkEntry *entry,
7116 GtkEntryIconPosition icon_pos,
7117 const gchar *stock_id)
7119 GtkEntryPrivate *priv;
7120 EntryIconInfo *icon_info;
7123 g_return_if_fail (GTK_IS_ENTRY (entry));
7124 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7126 priv = GTK_ENTRY_GET_PRIVATE (entry);
7128 if ((icon_info = priv->icons[icon_pos]) == NULL)
7129 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7131 g_object_freeze_notify (G_OBJECT (entry));
7133 gtk_widget_ensure_style (GTK_WIDGET (entry));
7135 /* need to dup before clearing */
7136 new_id = g_strdup (stock_id);
7138 gtk_entry_clear (entry, icon_pos);
7142 icon_info->storage_type = GTK_IMAGE_STOCK;
7143 icon_info->stock_id = new_id;
7145 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7147 g_object_notify (G_OBJECT (entry), "stock-primary");
7148 g_object_notify (G_OBJECT (entry), "storage-type-primary");
7152 g_object_notify (G_OBJECT (entry), "stock-secondary");
7153 g_object_notify (G_OBJECT (entry), "storage-type-secondary");
7157 gtk_entry_ensure_pixbuf (entry, icon_pos);
7159 if (GTK_WIDGET_VISIBLE (entry))
7160 gtk_widget_queue_resize (GTK_WIDGET (entry));
7162 g_object_thaw_notify (G_OBJECT (entry));
7166 * gtk_entry_set_icon_from_icon_name:
7167 * @entry: A #GtkEntry
7168 * @icon_pos: The position at which to set the icon
7169 * @icon_name: An icon name, or %NULL
7171 * Sets the icon shown in the entry at the specified position
7172 * from the current icon theme.
7174 * If the icon name isn't known, a "broken image" icon will be displayed
7177 * If @icon_name is %NULL, no icon will be shown in the specified position.
7182 gtk_entry_set_icon_from_icon_name (GtkEntry *entry,
7183 GtkEntryIconPosition icon_pos,
7184 const gchar *icon_name)
7186 GtkEntryPrivate *priv;
7187 EntryIconInfo *icon_info;
7190 g_return_if_fail (GTK_IS_ENTRY (entry));
7191 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7193 priv = GTK_ENTRY_GET_PRIVATE (entry);
7195 if ((icon_info = priv->icons[icon_pos]) == NULL)
7196 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7198 g_object_freeze_notify (G_OBJECT (entry));
7200 gtk_widget_ensure_style (GTK_WIDGET (entry));
7202 /* need to dup before clearing */
7203 new_name = g_strdup (icon_name);
7205 gtk_entry_clear (entry, icon_pos);
7207 if (new_name != NULL)
7209 icon_info->storage_type = GTK_IMAGE_ICON_NAME;
7210 icon_info->icon_name = new_name;
7212 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7214 g_object_notify (G_OBJECT (entry), "icon-name-primary");
7215 g_object_notify (G_OBJECT (entry), "storage-type-primary");
7219 g_object_notify (G_OBJECT (entry), "icon-name-secondary");
7220 g_object_notify (G_OBJECT (entry), "storage-type-secondary");
7224 gtk_entry_ensure_pixbuf (entry, icon_pos);
7226 if (GTK_WIDGET_VISIBLE (entry))
7227 gtk_widget_queue_resize (GTK_WIDGET (entry));
7229 g_object_thaw_notify (G_OBJECT (entry));
7233 * gtk_entry_set_icon_from_gicon:
7234 * @entry: A #GtkEntry
7235 * @icon_pos: The position at which to set the icon
7236 * @icon: The icon to set, or %NULL
7238 * Sets the icon shown in the entry at the specified position
7239 * from the current icon theme.
7240 * If the icon isn't known, a "broken image" icon will be displayed
7243 * If @icon is %NULL, no icon will be shown in the specified position.
7248 gtk_entry_set_icon_from_gicon (GtkEntry *entry,
7249 GtkEntryIconPosition icon_pos,
7252 GtkEntryPrivate *priv;
7253 EntryIconInfo *icon_info;
7255 g_return_if_fail (GTK_IS_ENTRY (entry));
7256 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7258 priv = GTK_ENTRY_GET_PRIVATE (entry);
7260 if ((icon_info = priv->icons[icon_pos]) == NULL)
7261 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7263 g_object_freeze_notify (G_OBJECT (entry));
7265 /* need to ref before clearing */
7267 g_object_ref (icon);
7269 gtk_entry_clear (entry, icon_pos);
7273 icon_info->storage_type = GTK_IMAGE_GICON;
7274 icon_info->gicon = icon;
7276 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7278 g_object_notify (G_OBJECT (entry), "gicon-primary");
7279 g_object_notify (G_OBJECT (entry), "storage-type-primary");
7283 g_object_notify (G_OBJECT (entry), "gicon-secondary");
7284 g_object_notify (G_OBJECT (entry), "storage-type-secondary");
7288 gtk_entry_ensure_pixbuf (entry, icon_pos);
7290 if (GTK_WIDGET_VISIBLE (entry))
7291 gtk_widget_queue_resize (GTK_WIDGET (entry));
7293 g_object_thaw_notify (G_OBJECT (entry));
7297 * gtk_entry_set_icon_activatable:
7298 * @entry: A #GtkEntry
7299 * @icon_pos: Icon position
7300 * @activatable: %TRUE if the icon should be activatable
7302 * Sets whether the icon is activatable.
7307 gtk_entry_set_icon_activatable (GtkEntry *entry,
7308 GtkEntryIconPosition icon_pos,
7309 gboolean activatable)
7311 GtkEntryPrivate *priv;
7312 EntryIconInfo *icon_info;
7314 g_return_if_fail (GTK_IS_ENTRY (entry));
7315 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7317 priv = GTK_ENTRY_GET_PRIVATE (entry);
7319 if ((icon_info = priv->icons[icon_pos]) == NULL)
7320 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7322 activatable = activatable != FALSE;
7324 if (icon_info->nonactivatable != !activatable)
7326 icon_info->nonactivatable = !activatable;
7328 if (GTK_WIDGET_REALIZED (GTK_WIDGET (entry)))
7329 update_cursors (GTK_WIDGET (entry));
7331 g_object_notify (G_OBJECT (entry),
7332 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "activatable-primary" : "activatable-secondary");
7337 * gtk_entry_get_icon_activatable:
7338 * @entry: a #GtkEntry
7339 * @icon_pos: Icon position
7341 * Returns whether the icon is activatable.
7343 * Returns: %TRUE if the icon is activatable.
7348 gtk_entry_get_icon_activatable (GtkEntry *entry,
7349 GtkEntryIconPosition icon_pos)
7351 GtkEntryPrivate *priv;
7352 EntryIconInfo *icon_info;
7354 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7355 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), FALSE);
7357 priv = GTK_ENTRY_GET_PRIVATE (entry);
7358 icon_info = priv->icons[icon_pos];
7360 return (icon_info != NULL && !icon_info->nonactivatable);
7364 * gtk_entry_get_pixbuf:
7365 * @entry: A #GtkEntry
7366 * @icon_pos: Icon position
7368 * Retrieves the image used for the icon.
7370 * Unlike the other methods of setting and getting icon data, this
7371 * method will work regardless of whether the icon was set using a
7372 * #GdkPixbuf, a #GIcon, a stock item, or an icon name.
7374 * Returns: A #GdkPixbuf, or %NULL if no icon is set for this position.
7379 gtk_entry_get_pixbuf (GtkEntry *entry,
7380 GtkEntryIconPosition icon_pos)
7382 GtkEntryPrivate *priv;
7383 EntryIconInfo *icon_info;
7385 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7386 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7388 priv = GTK_ENTRY_GET_PRIVATE (entry);
7389 icon_info = priv->icons[icon_pos];
7394 gtk_entry_ensure_pixbuf (entry, icon_pos);
7396 return icon_info->pixbuf;
7400 * gtk_entry_get_gicon:
7401 * @entry: A #GtkEntry
7402 * @icon_pos: Icon position
7404 * Retrieves the #GIcon used for the icon, or %NULL if there is
7405 * no icon or if the icon was set by some other method (e.g., by
7406 * stock, pixbuf, or icon name).
7408 * Returns: A #GIcon, or %NULL if no icon is set or if the icon
7414 gtk_entry_get_gicon (GtkEntry *entry,
7415 GtkEntryIconPosition icon_pos)
7417 GtkEntryPrivate *priv;
7418 EntryIconInfo *icon_info;
7420 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7421 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7423 priv = GTK_ENTRY_GET_PRIVATE (entry);
7424 icon_info = priv->icons[icon_pos];
7429 return icon_info->storage_type == GTK_IMAGE_GICON ? icon_info->gicon : NULL;
7433 * gtk_entry_get_stock:
7434 * @entry: A #GtkEntry
7435 * @icon_pos: Icon position
7437 * Retrieves the stock id used for the icon, or %NULL if there is
7438 * no icon or if the icon was set by some other method (e.g., by
7439 * pixbuf, icon name or gicon).
7441 * Returns: A stock id, or %NULL if no icon is set or if the icon
7442 * wasn't set from a stock id
7447 gtk_entry_get_stock (GtkEntry *entry,
7448 GtkEntryIconPosition icon_pos)
7450 GtkEntryPrivate *priv;
7451 EntryIconInfo *icon_info;
7453 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7454 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7456 priv = GTK_ENTRY_GET_PRIVATE (entry);
7457 icon_info = priv->icons[icon_pos];
7462 return icon_info->storage_type == GTK_IMAGE_STOCK ? icon_info->stock_id : NULL;
7466 * gtk_entry_get_icon_name:
7467 * @entry: A #GtkEntry
7468 * @icon_pos: Icon position
7470 * Retrieves the icon name used for the icon, or %NULL if there is
7471 * no icon or if the icon was set by some other method (e.g., by
7472 * pixbuf, stock or gicon).
7474 * Returns: An icon name, or %NULL if no icon is set or if the icon
7475 * wasn't set from an icon name
7480 gtk_entry_get_icon_name (GtkEntry *entry,
7481 GtkEntryIconPosition icon_pos)
7483 GtkEntryPrivate *priv;
7484 EntryIconInfo *icon_info;
7486 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7487 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7489 priv = GTK_ENTRY_GET_PRIVATE (entry);
7490 icon_info = priv->icons[icon_pos];
7495 return icon_info->storage_type == GTK_IMAGE_ICON_NAME ? icon_info->icon_name : NULL;
7499 * gtk_entry_set_icon_sensitive:
7500 * @entry: A #GtkEntry
7501 * @icon_pos: Icon position
7502 * @sensitive: Specifies whether the icon should appear
7503 * sensitive or insensitive
7505 * Sets the sensitivity for the specified icon.
7510 gtk_entry_set_icon_sensitive (GtkEntry *entry,
7511 GtkEntryIconPosition icon_pos,
7514 GtkEntryPrivate *priv;
7515 EntryIconInfo *icon_info;
7517 g_return_if_fail (GTK_IS_ENTRY (entry));
7518 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7520 priv = GTK_ENTRY_GET_PRIVATE (entry);
7522 if ((icon_info = priv->icons[icon_pos]) == NULL)
7523 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7525 if (icon_info->insensitive != !sensitive)
7527 icon_info->insensitive = !sensitive;
7529 if (GTK_WIDGET_REALIZED (GTK_WIDGET (entry)))
7530 update_cursors (GTK_WIDGET (entry));
7532 g_object_notify (G_OBJECT (entry),
7533 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "sensitive-primary" : "sensitive-secondary");
7538 * gtk_entry_get_icon_sensitive:
7539 * @entry: a #GtkEntry
7540 * @icon_pos: Icon position
7542 * Returns whether the icon appears sensitive or insensitive.
7544 * Returns: %TRUE if the icon is sensitive.
7549 gtk_entry_get_icon_sensitive (GtkEntry *entry,
7550 GtkEntryIconPosition icon_pos)
7552 GtkEntryPrivate *priv;
7553 EntryIconInfo *icon_info;
7555 g_return_val_if_fail (GTK_IS_ENTRY (entry), TRUE);
7556 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), TRUE);
7558 priv = GTK_ENTRY_GET_PRIVATE (entry);
7559 icon_info = priv->icons[icon_pos];
7561 return (!icon_info || !icon_info->insensitive);
7566 * gtk_entry_get_storage_type:
7567 * @entry: a #GtkEntry
7568 * @icon_pos: Icon position
7570 * Gets the type of representation being used by the icon
7571 * to store image data. If the icon has no image data,
7572 * the return value will be %GTK_IMAGE_EMPTY.
7574 * Return value: image representation being used
7579 gtk_entry_get_storage_type (GtkEntry *entry,
7580 GtkEntryIconPosition icon_pos)
7582 GtkEntryPrivate *priv;
7583 EntryIconInfo *icon_info;
7585 g_return_val_if_fail (GTK_IS_ENTRY (entry), GTK_IMAGE_EMPTY);
7586 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), GTK_IMAGE_EMPTY);
7588 priv = GTK_ENTRY_GET_PRIVATE (entry);
7589 icon_info = priv->icons[icon_pos];
7592 return GTK_IMAGE_EMPTY;
7594 return icon_info->storage_type;
7598 * gtk_entry_get_icon_at_pos:
7599 * @entry: a #GtkEntry
7600 * @x: the x coordinate of the position to find
7601 * @y: the y coordinate of the position to find
7603 * Finds the icon at the given position and return its index.
7604 * If @x, @y doesn't lie inside an icon, -1 is returned.
7605 * This function is intended for use in a #GtkWidget::query-tooltip
7608 * Returns: the index of the icon at the given position, or -1
7613 gtk_entry_get_icon_at_pos (GtkEntry *entry,
7617 GtkAllocation primary;
7618 GtkAllocation secondary;
7620 g_return_val_if_fail (GTK_IS_ENTRY (entry), -1);
7622 get_icon_allocations (entry, &primary, &secondary);
7624 if (primary.x <= x && x < primary.x + primary.width &&
7625 primary.y <= y && y < primary.y + primary.height)
7626 return GTK_ENTRY_ICON_PRIMARY;
7628 if (secondary.x <= x && x < secondary.x + secondary.width &&
7629 secondary.y <= y && y < secondary.y + secondary.height)
7630 return GTK_ENTRY_ICON_SECONDARY;
7636 * gtk_entry_set_icon_drag_source:
7637 * @entry: a #GtkIconEntry
7638 * @icon_pos: icon position
7639 * @target_list: the targets (data formats) in which the data can be provided
7640 * @actions: a bitmask of the allowed drag actions
7642 * Sets up the icon at the given position so that GTK+ will start a drag
7643 * operation when the user clicks and drags the icon.
7645 * To handle the drag operation, you need to connect to the usual
7646 * #GtkWidget::drag-data-get (or possibly #GtkWidget::drag-data-delete)
7647 * signal, and use gtk_entry_get_current_icon_drag_source() in
7648 * your signal handler to find out if the drag was started from
7651 * By default, GTK+ uses the icon as the drag icon. You can use the
7652 * #GtkWidget::drag-begin signal to set a different icon. Note that you
7653 * have to use g_signal_connect_after() to ensure that your signal handler
7654 * gets executed after the default handler.
7657 gtk_entry_set_icon_drag_source (GtkEntry *entry,
7658 GtkEntryIconPosition icon_pos,
7659 GtkTargetList *target_list,
7660 GdkDragAction actions)
7662 GtkEntryPrivate *priv;
7663 EntryIconInfo *icon_info;
7665 g_return_if_fail (GTK_IS_ENTRY (entry));
7666 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7668 priv = GTK_ENTRY_GET_PRIVATE (entry);
7670 if ((icon_info = priv->icons[icon_pos]) == NULL)
7671 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7673 if (icon_info->target_list)
7674 gtk_target_list_unref (icon_info->target_list);
7675 icon_info->target_list = target_list;
7676 if (icon_info->target_list)
7677 gtk_target_list_ref (icon_info->target_list);
7679 icon_info->actions = actions;
7683 * gtk_entry_get_current_icon_drag_source:
7684 * @entry: a #GtkIconEntry
7686 * Returns the index of the icon which is the source of the current
7687 * DND operation, or -1.
7689 * This function is meant to be used in a #GtkWidget::drag-data-get
7692 * Returns: index of the icon which is the source of the current
7693 * DND operation, or -1.
7696 gtk_entry_get_current_icon_drag_source (GtkEntry *entry)
7698 GtkEntryPrivate *priv;
7699 EntryIconInfo *icon_info = NULL;
7702 g_return_val_if_fail (GTK_IS_ENTRY (entry), -1);
7704 priv = GTK_ENTRY_GET_PRIVATE (entry);
7706 for (i = 0; i < MAX_ICONS; i++)
7708 if ((icon_info = priv->icons[i]))
7710 if (icon_info->in_drag)
7719 ensure_has_tooltip (GtkEntry *entry)
7721 GtkEntryPrivate *priv;
7722 EntryIconInfo *icon_info;
7724 gboolean has_tooltip = FALSE;
7726 priv = GTK_ENTRY_GET_PRIVATE (entry);
7728 for (i = 0; i < MAX_ICONS; i++)
7730 if ((icon_info = priv->icons[i]) != NULL)
7732 if (icon_info->tooltip != NULL)
7740 gtk_widget_set_has_tooltip (GTK_WIDGET (entry), has_tooltip);
7744 * gtk_entry_set_icon_tooltip_text:
7745 * @entry: a #GtkEntry
7746 * @icon_pos: the icon position
7747 * @tooltip: the contents of the tooltip for the icon, or %NULL
7749 * Sets @tooltip as the contents of the tooltip for the icon
7750 * at the specified position.
7752 * Use %NULL for @tooltip to remove an existing tooltip.
7754 * See also gtk_widget_set_tooltip_text() and
7755 * gtk_entry_set_icon_tooltip_markup().
7760 gtk_entry_set_icon_tooltip_text (GtkEntry *entry,
7761 GtkEntryIconPosition icon_pos,
7762 const gchar *tooltip)
7764 GtkEntryPrivate *priv;
7765 EntryIconInfo *icon_info;
7767 g_return_if_fail (GTK_IS_ENTRY (entry));
7768 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7770 priv = GTK_ENTRY_GET_PRIVATE (entry);
7772 if (!(icon_info = priv->icons[icon_pos]))
7773 icon_info = priv->icons[icon_pos];
7775 if (icon_info->tooltip)
7776 g_free (icon_info->tooltip);
7778 icon_info->tooltip = tooltip ? g_markup_escape_text (tooltip, -1) : NULL;
7780 ensure_has_tooltip (entry);
7784 * gtk_entry_set_icon_tooltip_markup:
7785 * @entry: a #GtkEntry
7786 * @icon_pos: the icon position
7787 * @tooltip: the contents of the tooltip for the icon, or %NULL
7789 * Sets @tooltip as the contents of the tooltip for the icon at
7790 * the specified position. @tooltip is assumed to be marked up with
7791 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
7793 * Use %NULL for @tooltip to remove an existing tooltip.
7795 * See also gtk_widget_set_tooltip_markup() and
7796 * gtk_enty_set_icon_tooltip_text().
7801 gtk_entry_set_icon_tooltip_markup (GtkEntry *entry,
7802 GtkEntryIconPosition icon_pos,
7803 const gchar *tooltip)
7805 GtkEntryPrivate *priv;
7806 EntryIconInfo *icon_info;
7808 g_return_if_fail (GTK_IS_ENTRY (entry));
7809 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7811 priv = GTK_ENTRY_GET_PRIVATE (entry);
7813 if (!(icon_info = priv->icons[icon_pos]))
7814 icon_info = priv->icons[icon_pos];
7816 if (icon_info->tooltip)
7817 g_free (icon_info->tooltip);
7819 icon_info->tooltip = g_strdup (tooltip);
7821 ensure_has_tooltip (entry);
7825 gtk_entry_query_tooltip (GtkWidget *widget,
7828 gboolean keyboard_tip,
7829 GtkTooltip *tooltip)
7832 GtkEntryPrivate *priv;
7833 EntryIconInfo *icon_info;
7836 entry = GTK_ENTRY (widget);
7837 priv = GTK_ENTRY_GET_PRIVATE (entry);
7841 icon_pos = gtk_entry_get_icon_at_pos (entry, x, y);
7844 if ((icon_info = priv->icons[icon_pos]) != NULL)
7846 if (icon_info->tooltip)
7848 gtk_tooltip_set_markup (tooltip, icon_info->tooltip);
7857 return GTK_WIDGET_CLASS (gtk_entry_parent_class)->query_tooltip (widget,
7864 /* Quick hack of a popup menu
7867 activate_cb (GtkWidget *menuitem,
7870 const gchar *signal = g_object_get_data (G_OBJECT (menuitem), "gtk-signal");
7871 g_signal_emit_by_name (entry, signal);
7876 gtk_entry_mnemonic_activate (GtkWidget *widget,
7877 gboolean group_cycling)
7879 gtk_widget_grab_focus (widget);
7884 append_action_signal (GtkEntry *entry,
7886 const gchar *stock_id,
7887 const gchar *signal,
7890 GtkWidget *menuitem = gtk_image_menu_item_new_from_stock (stock_id, NULL);
7892 g_object_set_data (G_OBJECT (menuitem), I_("gtk-signal"), (char *)signal);
7893 g_signal_connect (menuitem, "activate",
7894 G_CALLBACK (activate_cb), entry);
7896 gtk_widget_set_sensitive (menuitem, sensitive);
7898 gtk_widget_show (menuitem);
7899 gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
7903 popup_menu_detach (GtkWidget *attach_widget,
7906 GTK_ENTRY (attach_widget)->popup_menu = NULL;
7910 popup_position_func (GtkMenu *menu,
7916 GtkEntry *entry = GTK_ENTRY (user_data);
7917 GtkWidget *widget = GTK_WIDGET (entry);
7919 GtkRequisition menu_req;
7920 GdkRectangle monitor;
7921 GtkBorder inner_border;
7922 gint monitor_num, strong_x, height;
7924 g_return_if_fail (GTK_WIDGET_REALIZED (entry));
7926 gdk_window_get_origin (entry->text_area, x, y);
7928 screen = gtk_widget_get_screen (widget);
7929 monitor_num = gdk_screen_get_monitor_at_window (screen, entry->text_area);
7930 if (monitor_num < 0)
7932 gtk_menu_set_monitor (menu, monitor_num);
7934 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
7935 gtk_widget_size_request (entry->popup_menu, &menu_req);
7936 gdk_drawable_get_size (entry->text_area, NULL, &height);
7937 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
7938 _gtk_entry_effective_inner_border (entry, &inner_border);
7940 *x += inner_border.left + strong_x - entry->scroll_offset;
7941 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
7942 *x -= menu_req.width;
7944 if ((*y + height + menu_req.height) <= monitor.y + monitor.height)
7946 else if ((*y - menu_req.height) >= monitor.y)
7947 *y -= menu_req.height;
7948 else if (monitor.y + monitor.height - (*y + height) > *y)
7951 *y -= menu_req.height;
7957 unichar_chosen_func (const char *text,
7960 GtkEntry *entry = GTK_ENTRY (data);
7962 if (entry->editable)
7963 gtk_entry_enter_text (entry, text);
7974 popup_targets_received (GtkClipboard *clipboard,
7975 GtkSelectionData *data,
7978 PopupInfo *info = user_data;
7979 GtkEntry *entry = info->entry;
7981 if (GTK_WIDGET_REALIZED (entry))
7983 gboolean clipboard_contains_text;
7984 GtkWidget *menuitem;
7986 gboolean show_input_method_menu;
7987 gboolean show_unicode_menu;
7989 clipboard_contains_text = gtk_selection_data_targets_include_text (data);
7990 if (entry->popup_menu)
7991 gtk_widget_destroy (entry->popup_menu);
7993 entry->popup_menu = gtk_menu_new ();
7995 gtk_menu_attach_to_widget (GTK_MENU (entry->popup_menu),
7999 append_action_signal (entry, entry->popup_menu, GTK_STOCK_CUT, "cut-clipboard",
8000 entry->editable && entry->visible && entry->current_pos != entry->selection_bound);
8001 append_action_signal (entry, entry->popup_menu, GTK_STOCK_COPY, "copy-clipboard",
8002 entry->visible && entry->current_pos != entry->selection_bound);
8003 append_action_signal (entry, entry->popup_menu, GTK_STOCK_PASTE, "paste-clipboard",
8004 entry->editable && clipboard_contains_text);
8006 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_DELETE, NULL);
8007 gtk_widget_set_sensitive (menuitem, entry->editable && entry->current_pos != entry->selection_bound);
8008 g_signal_connect_swapped (menuitem, "activate",
8009 G_CALLBACK (gtk_entry_delete_cb), entry);
8010 gtk_widget_show (menuitem);
8011 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8013 menuitem = gtk_separator_menu_item_new ();
8014 gtk_widget_show (menuitem);
8015 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8017 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_SELECT_ALL, NULL);
8018 g_signal_connect_swapped (menuitem, "activate",
8019 G_CALLBACK (gtk_entry_select_all), entry);
8020 gtk_widget_show (menuitem);
8021 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8023 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
8024 "gtk-show-input-method-menu", &show_input_method_menu,
8025 "gtk-show-unicode-menu", &show_unicode_menu,
8028 if (show_input_method_menu || show_unicode_menu)
8030 menuitem = gtk_separator_menu_item_new ();
8031 gtk_widget_show (menuitem);
8032 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8035 if (show_input_method_menu)
8037 menuitem = gtk_menu_item_new_with_mnemonic (_("Input _Methods"));
8038 gtk_widget_set_sensitive (menuitem, entry->editable);
8039 gtk_widget_show (menuitem);
8040 submenu = gtk_menu_new ();
8041 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
8043 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8045 gtk_im_multicontext_append_menuitems (GTK_IM_MULTICONTEXT (entry->im_context),
8046 GTK_MENU_SHELL (submenu));
8049 if (show_unicode_menu)
8051 menuitem = gtk_menu_item_new_with_mnemonic (_("_Insert Unicode Control Character"));
8052 gtk_widget_set_sensitive (menuitem, entry->editable);
8053 gtk_widget_show (menuitem);
8055 submenu = gtk_menu_new ();
8056 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
8057 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8059 _gtk_text_util_append_special_char_menuitems (GTK_MENU_SHELL (submenu),
8060 unichar_chosen_func,
8064 g_signal_emit (entry,
8065 signals[POPULATE_POPUP],
8071 gtk_menu_popup (GTK_MENU (entry->popup_menu), NULL, NULL,
8073 info->button, info->time);
8076 gtk_menu_popup (GTK_MENU (entry->popup_menu), NULL, NULL,
8077 popup_position_func, entry,
8078 info->button, info->time);
8079 gtk_menu_shell_select_first (GTK_MENU_SHELL (entry->popup_menu), FALSE);
8083 g_object_unref (entry);
8084 g_slice_free (PopupInfo, info);
8088 gtk_entry_do_popup (GtkEntry *entry,
8089 GdkEventButton *event)
8091 PopupInfo *info = g_slice_new (PopupInfo);
8093 /* In order to know what entries we should make sensitive, we
8094 * ask for the current targets of the clipboard, and when
8095 * we get them, then we actually pop up the menu.
8097 info->entry = g_object_ref (entry);
8101 info->button = event->button;
8102 info->time = event->time;
8107 info->time = gtk_get_current_event_time ();
8110 gtk_clipboard_request_contents (gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_CLIPBOARD),
8111 gdk_atom_intern_static_string ("TARGETS"),
8112 popup_targets_received,
8117 gtk_entry_popup_menu (GtkWidget *widget)
8119 gtk_entry_do_popup (GTK_ENTRY (widget), NULL);
8124 gtk_entry_drag_begin (GtkWidget *widget,
8125 GdkDragContext *context)
8127 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
8130 for (i = 0; i < MAX_ICONS; i++)
8132 EntryIconInfo *icon_info = priv->icons[i];
8134 if (icon_info != NULL)
8136 if (icon_info->in_drag)
8138 switch (icon_info->storage_type)
8140 case GTK_IMAGE_STOCK:
8141 gtk_drag_set_icon_stock (context, icon_info->stock_id, -2, -2);
8144 case GTK_IMAGE_ICON_NAME:
8145 gtk_drag_set_icon_name (context, icon_info->icon_name, -2, -2);
8148 /* FIXME: No GIcon support for dnd icons */
8149 case GTK_IMAGE_GICON:
8150 case GTK_IMAGE_PIXBUF:
8151 gtk_drag_set_icon_pixbuf (context, icon_info->pixbuf, -2, -2);
8154 g_assert_not_reached ();
8162 gtk_entry_drag_end (GtkWidget *widget,
8163 GdkDragContext *context)
8165 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
8168 for (i = 0; i < MAX_ICONS; i++)
8170 EntryIconInfo *icon_info = priv->icons[i];
8172 if (icon_info != NULL)
8173 icon_info->in_drag = 0;
8178 gtk_entry_drag_leave (GtkWidget *widget,
8179 GdkDragContext *context,
8182 GtkEntry *entry = GTK_ENTRY (widget);
8184 entry->dnd_position = -1;
8185 gtk_widget_queue_draw (widget);
8189 gtk_entry_drag_drop (GtkWidget *widget,
8190 GdkDragContext *context,
8195 GtkEntry *entry = GTK_ENTRY (widget);
8196 GdkAtom target = GDK_NONE;
8198 if (entry->editable)
8199 target = gtk_drag_dest_find_target (widget, context, NULL);
8201 if (target != GDK_NONE)
8202 gtk_drag_get_data (widget, context, target, time);
8204 gtk_drag_finish (context, FALSE, FALSE, time);
8210 gtk_entry_drag_motion (GtkWidget *widget,
8211 GdkDragContext *context,
8216 GtkEntry *entry = GTK_ENTRY (widget);
8217 GtkWidget *source_widget;
8218 GdkDragAction suggested_action;
8219 gint new_position, old_position;
8222 x -= widget->style->xthickness;
8223 y -= widget->style->ythickness;
8225 old_position = entry->dnd_position;
8226 new_position = gtk_entry_find_position (entry, x + entry->scroll_offset);
8228 if (entry->editable &&
8229 gtk_drag_dest_find_target (widget, context, NULL) != GDK_NONE)
8231 source_widget = gtk_drag_get_source_widget (context);
8232 suggested_action = context->suggested_action;
8234 if (!gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &sel1, &sel2) ||
8235 new_position < sel1 || new_position > sel2)
8237 if (source_widget == widget)
8239 /* Default to MOVE, unless the user has
8240 * pressed ctrl or alt to affect available actions
8242 if ((context->actions & GDK_ACTION_MOVE) != 0)
8243 suggested_action = GDK_ACTION_MOVE;
8246 entry->dnd_position = new_position;
8250 if (source_widget == widget)
8251 suggested_action = 0; /* Can't drop in selection where drag started */
8253 entry->dnd_position = -1;
8258 /* Entry not editable, or no text */
8259 suggested_action = 0;
8260 entry->dnd_position = -1;
8263 gdk_drag_status (context, suggested_action, time);
8265 if (entry->dnd_position != old_position)
8266 gtk_widget_queue_draw (widget);
8272 gtk_entry_drag_data_received (GtkWidget *widget,
8273 GdkDragContext *context,
8276 GtkSelectionData *selection_data,
8280 GtkEntry *entry = GTK_ENTRY (widget);
8281 GtkEditable *editable = GTK_EDITABLE (widget);
8284 str = (gchar *) gtk_selection_data_get_text (selection_data);
8286 x -= widget->style->xthickness;
8287 y -= widget->style->ythickness;
8289 if (str && entry->editable)
8295 if (entry->truncate_multiline)
8296 length = truncate_multiline (str);
8298 new_position = gtk_entry_find_position (entry, x + entry->scroll_offset);
8300 if (!gtk_editable_get_selection_bounds (editable, &sel1, &sel2) ||
8301 new_position < sel1 || new_position > sel2)
8303 gtk_editable_insert_text (editable, str, length, &new_position);
8307 /* Replacing selection */
8308 begin_change (entry);
8309 g_object_freeze_notify (G_OBJECT (entry));
8310 gtk_editable_delete_text (editable, sel1, sel2);
8311 gtk_editable_insert_text (editable, str, length, &sel1);
8312 g_object_thaw_notify (G_OBJECT (entry));
8316 gtk_drag_finish (context, TRUE, context->action == GDK_ACTION_MOVE, time);
8320 /* Drag and drop didn't happen! */
8321 gtk_drag_finish (context, FALSE, FALSE, time);
8328 gtk_entry_drag_data_get (GtkWidget *widget,
8329 GdkDragContext *context,
8330 GtkSelectionData *selection_data,
8334 gint sel_start, sel_end;
8337 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
8338 GtkEditable *editable = GTK_EDITABLE (widget);
8340 /* If there is an icon drag going on, exit early. */
8341 for (i = 0; i < MAX_ICONS; i++)
8343 EntryIconInfo *icon_info = priv->icons[i];
8345 if (icon_info != NULL)
8347 if (icon_info->in_drag)
8352 if (gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end))
8354 gchar *str = gtk_entry_get_public_chars (GTK_ENTRY (widget), sel_start, sel_end);
8356 gtk_selection_data_set_text (selection_data, str, -1);
8364 gtk_entry_drag_data_delete (GtkWidget *widget,
8365 GdkDragContext *context)
8367 gint sel_start, sel_end;
8370 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
8371 GtkEditable *editable = GTK_EDITABLE (widget);
8373 /* If there is an icon drag going on, exit early. */
8374 for (i = 0; i < MAX_ICONS; i++)
8376 EntryIconInfo *icon_info = priv->icons[i];
8378 if (icon_info != NULL)
8380 if (icon_info->in_drag)
8385 if (GTK_ENTRY (widget)->editable &&
8386 gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end))
8387 gtk_editable_delete_text (editable, sel_start, sel_end);
8390 /* We display the cursor when
8392 * - the selection is empty, AND
8393 * - the widget has focus
8396 #define CURSOR_ON_MULTIPLIER 2
8397 #define CURSOR_OFF_MULTIPLIER 1
8398 #define CURSOR_PEND_MULTIPLIER 3
8399 #define CURSOR_DIVIDER 3
8402 cursor_blinks (GtkEntry *entry)
8404 if (GTK_WIDGET_HAS_FOCUS (entry) &&
8406 entry->selection_bound == entry->current_pos)
8408 GtkSettings *settings;
8411 settings = gtk_widget_get_settings (GTK_WIDGET (entry));
8412 g_object_get (settings, "gtk-cursor-blink", &blink, NULL);
8421 get_cursor_time (GtkEntry *entry)
8423 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (entry));
8426 g_object_get (settings, "gtk-cursor-blink-time", &time, NULL);
8432 get_cursor_blink_timeout (GtkEntry *entry)
8434 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (entry));
8437 g_object_get (settings, "gtk-cursor-blink-timeout", &timeout, NULL);
8443 show_cursor (GtkEntry *entry)
8445 if (!entry->cursor_visible)
8447 entry->cursor_visible = TRUE;
8449 if (GTK_WIDGET_HAS_FOCUS (entry) && entry->selection_bound == entry->current_pos)
8450 gtk_widget_queue_draw (GTK_WIDGET (entry));
8455 hide_cursor (GtkEntry *entry)
8457 if (entry->cursor_visible)
8459 entry->cursor_visible = FALSE;
8461 if (GTK_WIDGET_HAS_FOCUS (entry) && entry->selection_bound == entry->current_pos)
8462 gtk_widget_queue_draw (GTK_WIDGET (entry));
8470 blink_cb (gpointer data)
8473 GtkEntryPrivate *priv;
8476 entry = GTK_ENTRY (data);
8477 priv = GTK_ENTRY_GET_PRIVATE (entry);
8479 if (!GTK_WIDGET_HAS_FOCUS (entry))
8481 g_warning ("GtkEntry - did not receive focus-out-event. If you\n"
8482 "connect a handler to this signal, it must return\n"
8483 "FALSE so the entry gets the event as well");
8485 gtk_entry_check_cursor_blink (entry);
8490 g_assert (entry->selection_bound == entry->current_pos);
8492 blink_timeout = get_cursor_blink_timeout (entry);
8493 if (priv->blink_time > 1000 * blink_timeout &&
8494 blink_timeout < G_MAXINT/1000)
8496 /* we've blinked enough without the user doing anything, stop blinking */
8497 show_cursor (entry);
8498 entry->blink_timeout = 0;
8500 else if (entry->cursor_visible)
8502 hide_cursor (entry);
8503 entry->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_OFF_MULTIPLIER / CURSOR_DIVIDER,
8509 show_cursor (entry);
8510 priv->blink_time += get_cursor_time (entry);
8511 entry->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
8516 /* Remove ourselves */
8521 gtk_entry_check_cursor_blink (GtkEntry *entry)
8523 GtkEntryPrivate *priv;
8525 priv = GTK_ENTRY_GET_PRIVATE (entry);
8527 if (cursor_blinks (entry))
8529 if (!entry->blink_timeout)
8531 show_cursor (entry);
8532 entry->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
8539 if (entry->blink_timeout)
8541 g_source_remove (entry->blink_timeout);
8542 entry->blink_timeout = 0;
8545 entry->cursor_visible = TRUE;
8551 gtk_entry_pend_cursor_blink (GtkEntry *entry)
8553 if (cursor_blinks (entry))
8555 if (entry->blink_timeout != 0)
8556 g_source_remove (entry->blink_timeout);
8558 entry->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_PEND_MULTIPLIER / CURSOR_DIVIDER,
8561 show_cursor (entry);
8566 gtk_entry_reset_blink_time (GtkEntry *entry)
8568 GtkEntryPrivate *priv;
8570 priv = GTK_ENTRY_GET_PRIVATE (entry);
8572 priv->blink_time = 0;
8578 gtk_entry_completion_timeout (gpointer data)
8580 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (data);
8582 completion->priv->completion_timeout = 0;
8584 if (completion->priv->filter_model &&
8585 g_utf8_strlen (gtk_entry_get_text (GTK_ENTRY (completion->priv->entry)), -1)
8586 >= completion->priv->minimum_key_length)
8590 GtkTreeSelection *s;
8591 gboolean popup_single;
8593 gtk_entry_completion_complete (completion);
8594 matches = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->filter_model), NULL);
8596 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
8598 s = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view));
8600 gtk_tree_selection_unselect_all (s);
8602 actions = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->actions), NULL);
8604 g_object_get (completion, "popup-single-match", &popup_single, NULL);
8605 if ((matches > (popup_single ? 0: 1)) || actions > 0)
8607 if (GTK_WIDGET_VISIBLE (completion->priv->popup_window))
8608 _gtk_entry_completion_resize_popup (completion);
8610 _gtk_entry_completion_popup (completion);
8613 _gtk_entry_completion_popdown (completion);
8615 else if (GTK_WIDGET_VISIBLE (completion->priv->popup_window))
8616 _gtk_entry_completion_popdown (completion);
8621 static inline gboolean
8622 keyval_is_cursor_move (guint keyval)
8624 if (keyval == GDK_Up || keyval == GDK_KP_Up)
8627 if (keyval == GDK_Down || keyval == GDK_KP_Down)
8630 if (keyval == GDK_Page_Up)
8633 if (keyval == GDK_Page_Down)
8640 gtk_entry_completion_key_press (GtkWidget *widget,
8644 gint matches, actions = 0;
8645 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
8647 if (!GTK_WIDGET_MAPPED (completion->priv->popup_window))
8650 matches = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->filter_model), NULL);
8652 if (completion->priv->actions)
8653 actions = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->actions), NULL);
8655 if (keyval_is_cursor_move (event->keyval))
8657 GtkTreePath *path = NULL;
8659 if (event->keyval == GDK_Up || event->keyval == GDK_KP_Up)
8661 if (completion->priv->current_selected < 0)
8662 completion->priv->current_selected = matches + actions - 1;
8664 completion->priv->current_selected--;
8666 else if (event->keyval == GDK_Down || event->keyval == GDK_KP_Down)
8668 if (completion->priv->current_selected < matches + actions - 1)
8669 completion->priv->current_selected++;
8671 completion->priv->current_selected = -1;
8673 else if (event->keyval == GDK_Page_Up)
8675 if (completion->priv->current_selected < 0)
8676 completion->priv->current_selected = matches + actions - 1;
8677 else if (completion->priv->current_selected == 0)
8678 completion->priv->current_selected = -1;
8679 else if (completion->priv->current_selected < matches)
8681 completion->priv->current_selected -= 14;
8682 if (completion->priv->current_selected < 0)
8683 completion->priv->current_selected = 0;
8687 completion->priv->current_selected -= 14;
8688 if (completion->priv->current_selected < matches - 1)
8689 completion->priv->current_selected = matches - 1;
8692 else if (event->keyval == GDK_Page_Down)
8694 if (completion->priv->current_selected < 0)
8695 completion->priv->current_selected = 0;
8696 else if (completion->priv->current_selected < matches - 1)
8698 completion->priv->current_selected += 14;
8699 if (completion->priv->current_selected > matches - 1)
8700 completion->priv->current_selected = matches - 1;
8702 else if (completion->priv->current_selected == matches + actions - 1)
8704 completion->priv->current_selected = -1;
8708 completion->priv->current_selected += 14;
8709 if (completion->priv->current_selected > matches + actions - 1)
8710 completion->priv->current_selected = matches + actions - 1;
8714 if (completion->priv->current_selected < 0)
8716 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
8717 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view)));
8719 if (completion->priv->inline_selection &&
8720 completion->priv->completion_prefix)
8722 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
8723 completion->priv->completion_prefix);
8724 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
8727 else if (completion->priv->current_selected < matches)
8729 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view)));
8731 path = gtk_tree_path_new_from_indices (completion->priv->current_selected, -1);
8732 gtk_tree_view_set_cursor (GTK_TREE_VIEW (completion->priv->tree_view),
8735 if (completion->priv->inline_selection)
8739 GtkTreeModel *model = NULL;
8740 GtkTreeSelection *sel;
8743 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view));
8744 if (!gtk_tree_selection_get_selected (sel, &model, &iter))
8747 if (completion->priv->completion_prefix == NULL)
8748 completion->priv->completion_prefix = g_strdup (gtk_entry_get_text (GTK_ENTRY (completion->priv->entry)));
8750 g_signal_emit_by_name (completion, "cursor-on-match", model,
8754 else if (completion->priv->current_selected - matches >= 0)
8756 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
8758 path = gtk_tree_path_new_from_indices (completion->priv->current_selected - matches, -1);
8759 gtk_tree_view_set_cursor (GTK_TREE_VIEW (completion->priv->action_view),
8762 if (completion->priv->inline_selection &&
8763 completion->priv->completion_prefix)
8765 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
8766 completion->priv->completion_prefix);
8767 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
8771 gtk_tree_path_free (path);
8775 else if (event->keyval == GDK_Escape ||
8776 event->keyval == GDK_Left ||
8777 event->keyval == GDK_KP_Left ||
8778 event->keyval == GDK_Right ||
8779 event->keyval == GDK_KP_Right)
8781 gboolean retval = TRUE;
8783 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
8784 _gtk_entry_completion_popdown (completion);
8786 if (completion->priv->current_selected < 0)
8789 goto keypress_completion_out;
8791 else if (completion->priv->inline_selection)
8793 /* Escape rejects the tentative completion */
8794 if (event->keyval == GDK_Escape)
8796 if (completion->priv->completion_prefix)
8797 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
8798 completion->priv->completion_prefix);
8800 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry), "");
8803 /* Move the cursor to the end for Right/Esc, to the
8804 beginning for Left */
8805 if (event->keyval == GDK_Right ||
8806 event->keyval == GDK_KP_Right ||
8807 event->keyval == GDK_Escape)
8808 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
8810 gtk_editable_set_position (GTK_EDITABLE (widget), 0);
8813 keypress_completion_out:
8814 if (completion->priv->inline_selection)
8816 g_free (completion->priv->completion_prefix);
8817 completion->priv->completion_prefix = NULL;
8822 else if (event->keyval == GDK_Tab ||
8823 event->keyval == GDK_KP_Tab ||
8824 event->keyval == GDK_ISO_Left_Tab)
8826 GtkDirectionType dir = event->keyval == GDK_ISO_Left_Tab ?
8827 GTK_DIR_TAB_BACKWARD : GTK_DIR_TAB_FORWARD;
8829 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
8830 _gtk_entry_completion_popdown (completion);
8832 g_free (completion->priv->completion_prefix);
8833 completion->priv->completion_prefix = NULL;
8835 gtk_widget_child_focus (gtk_widget_get_toplevel (widget), dir);
8839 else if (event->keyval == GDK_ISO_Enter ||
8840 event->keyval == GDK_KP_Enter ||
8841 event->keyval == GDK_Return)
8843 gboolean retval = TRUE;
8845 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
8846 _gtk_entry_completion_popdown (completion);
8848 if (completion->priv->current_selected < matches)
8851 GtkTreeModel *model = NULL;
8852 GtkTreeSelection *sel;
8855 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view));
8856 if (gtk_tree_selection_get_selected (sel, &model, &iter))
8858 g_signal_handler_block (widget, completion->priv->changed_id);
8859 g_signal_emit_by_name (completion, "match-selected",
8860 model, &iter, &entry_set);
8861 g_signal_handler_unblock (widget, completion->priv->changed_id);
8867 gtk_tree_model_get (model, &iter,
8868 completion->priv->text_column, &str,
8871 gtk_entry_set_text (GTK_ENTRY (widget), str);
8873 /* move the cursor to the end */
8874 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
8882 else if (completion->priv->current_selected - matches >= 0)
8886 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
8888 path = gtk_tree_path_new_from_indices (completion->priv->current_selected - matches, -1);
8890 g_signal_emit_by_name (completion, "action-activated",
8891 gtk_tree_path_get_indices (path)[0]);
8892 gtk_tree_path_free (path);
8895 g_free (completion->priv->completion_prefix);
8896 completion->priv->completion_prefix = NULL;
8905 gtk_entry_completion_changed (GtkWidget *entry,
8908 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
8910 /* (re)install completion timeout */
8911 if (completion->priv->completion_timeout)
8912 g_source_remove (completion->priv->completion_timeout);
8914 if (!gtk_entry_get_text (GTK_ENTRY (entry)))
8917 /* no need to normalize for this test */
8918 if (completion->priv->minimum_key_length > 0 &&
8919 strcmp ("", gtk_entry_get_text (GTK_ENTRY (entry))) == 0)
8921 if (GTK_WIDGET_VISIBLE (completion->priv->popup_window))
8922 _gtk_entry_completion_popdown (completion);
8926 completion->priv->completion_timeout =
8927 gdk_threads_add_timeout (COMPLETION_TIMEOUT,
8928 gtk_entry_completion_timeout,
8933 check_completion_callback (GtkEntryCompletion *completion)
8935 completion->priv->check_completion_idle = NULL;
8937 gtk_entry_completion_complete (completion);
8938 gtk_entry_completion_insert_prefix (completion);
8944 clear_completion_callback (GtkEntry *entry,
8947 if (pspec->name == I_("cursor-position") ||
8948 pspec->name == I_("selection-bound"))
8950 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
8952 completion->priv->has_completion = FALSE;
8957 accept_completion_callback (GtkEntry *entry)
8959 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
8961 if (completion->priv->has_completion)
8962 gtk_editable_set_position (GTK_EDITABLE (entry),
8963 entry->text_length);
8969 completion_insert_text_callback (GtkEntry *entry,
8973 GtkEntryCompletion *completion)
8975 /* idle to update the selection based on the file list */
8976 if (completion->priv->check_completion_idle == NULL)
8978 completion->priv->check_completion_idle = g_idle_source_new ();
8979 g_source_set_priority (completion->priv->check_completion_idle, G_PRIORITY_HIGH);
8980 g_source_set_closure (completion->priv->check_completion_idle,
8981 g_cclosure_new_object (G_CALLBACK (check_completion_callback),
8982 G_OBJECT (completion)));
8983 g_source_attach (completion->priv->check_completion_idle, NULL);
8988 completion_changed (GtkEntryCompletion *completion,
8992 GtkEntry *entry = GTK_ENTRY (data);
8994 if (pspec->name == I_("popup-completion") ||
8995 pspec->name == I_("inline-completion"))
8997 disconnect_completion_signals (entry, completion);
8998 connect_completion_signals (entry, completion);
9003 disconnect_completion_signals (GtkEntry *entry,
9004 GtkEntryCompletion *completion)
9006 g_signal_handlers_disconnect_by_func (completion,
9007 G_CALLBACK (completion_changed), entry);
9008 if (completion->priv->changed_id > 0 &&
9009 g_signal_handler_is_connected (entry, completion->priv->changed_id))
9011 g_signal_handler_disconnect (entry, completion->priv->changed_id);
9012 completion->priv->changed_id = 0;
9014 g_signal_handlers_disconnect_by_func (entry,
9015 G_CALLBACK (gtk_entry_completion_key_press), completion);
9016 if (completion->priv->insert_text_id > 0 &&
9017 g_signal_handler_is_connected (entry, completion->priv->insert_text_id))
9019 g_signal_handler_disconnect (entry, completion->priv->insert_text_id);
9020 completion->priv->insert_text_id = 0;
9022 g_signal_handlers_disconnect_by_func (entry,
9023 G_CALLBACK (completion_insert_text_callback), completion);
9024 g_signal_handlers_disconnect_by_func (entry,
9025 G_CALLBACK (clear_completion_callback), completion);
9026 g_signal_handlers_disconnect_by_func (entry,
9027 G_CALLBACK (accept_completion_callback), completion);
9031 connect_completion_signals (GtkEntry *entry,
9032 GtkEntryCompletion *completion)
9034 if (completion->priv->popup_completion)
9036 completion->priv->changed_id =
9037 g_signal_connect (entry, "changed",
9038 G_CALLBACK (gtk_entry_completion_changed), completion);
9039 g_signal_connect (entry, "key-press-event",
9040 G_CALLBACK (gtk_entry_completion_key_press), completion);
9043 if (completion->priv->inline_completion)
9045 completion->priv->insert_text_id =
9046 g_signal_connect (entry, "insert-text",
9047 G_CALLBACK (completion_insert_text_callback), completion);
9048 g_signal_connect (entry, "notify",
9049 G_CALLBACK (clear_completion_callback), completion);
9050 g_signal_connect (entry, "activate",
9051 G_CALLBACK (accept_completion_callback), completion);
9052 g_signal_connect (entry, "focus-out-event",
9053 G_CALLBACK (accept_completion_callback), completion);
9056 g_signal_connect (completion, "notify",
9057 G_CALLBACK (completion_changed), entry);
9061 * gtk_entry_set_completion:
9062 * @entry: A #GtkEntry
9063 * @completion: The #GtkEntryCompletion or %NULL
9065 * Sets @completion to be the auxiliary completion object to use with @entry.
9066 * All further configuration of the completion mechanism is done on
9067 * @completion using the #GtkEntryCompletion API. Completion is disabled if
9068 * @completion is set to %NULL.
9073 gtk_entry_set_completion (GtkEntry *entry,
9074 GtkEntryCompletion *completion)
9076 GtkEntryCompletion *old;
9078 g_return_if_fail (GTK_IS_ENTRY (entry));
9079 g_return_if_fail (!completion || GTK_IS_ENTRY_COMPLETION (completion));
9081 old = gtk_entry_get_completion (entry);
9083 if (old == completion)
9088 if (old->priv->completion_timeout)
9090 g_source_remove (old->priv->completion_timeout);
9091 old->priv->completion_timeout = 0;
9094 if (GTK_WIDGET_MAPPED (old->priv->popup_window))
9095 _gtk_entry_completion_popdown (old);
9097 disconnect_completion_signals (entry, old);
9098 old->priv->entry = NULL;
9100 g_object_unref (old);
9105 g_object_set_data (G_OBJECT (entry), I_(GTK_ENTRY_COMPLETION_KEY), NULL);
9109 /* hook into the entry */
9110 g_object_ref (completion);
9112 connect_completion_signals (entry, completion);
9113 completion->priv->entry = GTK_WIDGET (entry);
9114 g_object_set_data (G_OBJECT (entry), I_(GTK_ENTRY_COMPLETION_KEY), completion);
9118 * gtk_entry_get_completion:
9119 * @entry: A #GtkEntry
9121 * Returns the auxiliary completion object currently in use by @entry.
9123 * Return value: The auxiliary completion object currently in use by @entry.
9127 GtkEntryCompletion *
9128 gtk_entry_get_completion (GtkEntry *entry)
9130 GtkEntryCompletion *completion;
9132 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
9134 completion = GTK_ENTRY_COMPLETION (g_object_get_data (G_OBJECT (entry),
9135 GTK_ENTRY_COMPLETION_KEY));
9141 * gtk_entry_set_cursor_hadjustment:
9142 * @entry: a #GtkEntry
9143 * @adjustment: an adjustment which should be adjusted when the cursor
9144 * is moved, or %NULL
9146 * Hooks up an adjustment to the cursor position in an entry, so that when
9147 * the cursor is moved, the adjustment is scrolled to show that position.
9148 * See gtk_scrolled_window_get_hadjustment() for a typical way of obtaining
9151 * The adjustment has to be in pixel units and in the same coordinate system
9157 gtk_entry_set_cursor_hadjustment (GtkEntry *entry,
9158 GtkAdjustment *adjustment)
9160 g_return_if_fail (GTK_IS_ENTRY (entry));
9162 g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
9165 g_object_ref (adjustment);
9167 g_object_set_qdata_full (G_OBJECT (entry),
9168 quark_cursor_hadjustment,
9174 * gtk_entry_get_cursor_hadjustment:
9175 * @entry: a #GtkEntry
9177 * Retrieves the horizontal cursor adjustment for the entry.
9178 * See gtk_entry_set_cursor_hadjustment().
9180 * Return value: the horizontal cursor adjustment, or %NULL
9181 * if none has been set.
9186 gtk_entry_get_cursor_hadjustment (GtkEntry *entry)
9188 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
9190 return g_object_get_qdata (G_OBJECT (entry), quark_cursor_hadjustment);
9194 * gtk_entry_set_progress_fraction:
9195 * @entry: a #GtkEntry
9196 * @fraction: fraction of the task that's been completed
9198 * Causes the entry's progress indicator to "fill in" the given
9199 * fraction of the bar. The fraction should be between 0.0 and 1.0,
9205 gtk_entry_set_progress_fraction (GtkEntry *entry,
9208 GtkEntryPrivate *private;
9209 gdouble old_fraction;
9211 g_return_if_fail (GTK_IS_ENTRY (entry));
9213 private = GTK_ENTRY_GET_PRIVATE (entry);
9215 if (private->progress_pulse_mode)
9218 old_fraction = private->progress_fraction;
9220 fraction = CLAMP (fraction, 0.0, 1.0);
9222 private->progress_fraction = fraction;
9223 private->progress_pulse_mode = FALSE;
9224 private->progress_pulse_current = 0.0;
9226 if (fabs (fraction - old_fraction) > 0.0001)
9227 gtk_entry_queue_draw (entry);
9229 if (fraction != old_fraction)
9230 g_object_notify (G_OBJECT (entry), "progress-fraction");
9234 * gtk_entry_get_progress_fraction:
9235 * @entry: a #GtkEntry
9237 * Returns the current fraction of the task that's been completed.
9238 * See gtk_entry_set_progress_fraction().
9240 * Return value: a fraction from 0.0 to 1.0
9245 gtk_entry_get_progress_fraction (GtkEntry *entry)
9247 GtkEntryPrivate *private;
9249 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
9251 private = GTK_ENTRY_GET_PRIVATE (entry);
9253 return private->progress_fraction;
9257 * gtk_entry_set_progress_pulse_step:
9258 * @entry: a #GtkEntry
9259 * @fraction: fraction between 0.0 and 1.0
9261 * Sets the fraction of total entry width to move the progress
9262 * bouncing block for each call to gtk_entry_progress_pulse().
9267 gtk_entry_set_progress_pulse_step (GtkEntry *entry,
9270 GtkEntryPrivate *private;
9272 g_return_if_fail (GTK_IS_ENTRY (entry));
9274 private = GTK_ENTRY_GET_PRIVATE (entry);
9276 fraction = CLAMP (fraction, 0.0, 1.0);
9278 if (fraction != private->progress_pulse_fraction)
9280 private->progress_pulse_fraction = fraction;
9282 gtk_entry_queue_draw (entry);
9284 g_object_notify (G_OBJECT (entry), "progress-pulse-step");
9289 * gtk_entry_get_progress_pulse_step:
9290 * @entry: a #GtkEntry
9292 * Retrieves the pulse step set with gtk_entry_set_progress_pulse_step().
9294 * Return value: a fraction from 0.0 to 1.0
9299 gtk_entry_get_progress_pulse_step (GtkEntry *entry)
9301 GtkEntryPrivate *private;
9303 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
9305 private = GTK_ENTRY_GET_PRIVATE (entry);
9307 return private->progress_pulse_fraction;
9311 * gtk_entry_progress_pulse:
9312 * @entry: a #GtkEntry
9314 * Indicates that some progress is made, but you don't know how much.
9315 * Causes the entry's progress indicator to enter "activity mode,"
9316 * where a block bounces back and forth. Each call to
9317 * gtk_entry_progress_pulse() causes the block to move by a little bit
9318 * (the amount of movement per pulse is determined by
9319 * gtk_entry_set_progress_pulse_step()).
9324 gtk_entry_progress_pulse (GtkEntry *entry)
9326 GtkEntryPrivate *private;
9328 g_return_if_fail (GTK_IS_ENTRY (entry));
9330 private = GTK_ENTRY_GET_PRIVATE (entry);
9332 if (private->progress_pulse_mode)
9334 if (private->progress_pulse_way_back)
9336 private->progress_pulse_current -= private->progress_pulse_fraction;
9338 if (private->progress_pulse_current < 0.0)
9340 private->progress_pulse_current = 0.0;
9341 private->progress_pulse_way_back = FALSE;
9346 private->progress_pulse_current += private->progress_pulse_fraction;
9348 if (private->progress_pulse_current > 1.0 - private->progress_pulse_fraction)
9350 private->progress_pulse_current = 1.0 - private->progress_pulse_fraction;
9351 private->progress_pulse_way_back = TRUE;
9357 private->progress_fraction = 0.0;
9358 private->progress_pulse_mode = TRUE;
9359 private->progress_pulse_way_back = FALSE;
9360 private->progress_pulse_current = 0.0;
9363 gtk_entry_queue_draw (entry);
9366 /* Caps Lock warning for password entries */
9369 show_capslock_feedback (GtkEntry *entry,
9372 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
9374 if (gtk_entry_get_storage_type (entry, GTK_ENTRY_ICON_SECONDARY) == GTK_IMAGE_EMPTY)
9376 gtk_entry_set_icon_from_stock (entry, GTK_ENTRY_ICON_SECONDARY, GTK_STOCK_CAPS_LOCK_WARNING);
9377 gtk_entry_set_icon_activatable (entry, GTK_ENTRY_ICON_SECONDARY, FALSE);
9378 priv->caps_lock_warning_shown = TRUE;
9381 if (priv->caps_lock_warning_shown)
9382 gtk_entry_set_icon_tooltip_text (entry, GTK_ENTRY_ICON_SECONDARY, text);
9384 g_warning ("Can't show Caps Lock warning, since secondary icon is set");
9388 remove_capslock_feedback (GtkEntry *entry)
9390 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
9392 if (priv->caps_lock_warning_shown)
9394 gtk_entry_set_icon_from_stock (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
9395 priv->caps_lock_warning_shown = FALSE;
9400 keymap_state_changed (GdkKeymap *keymap,
9403 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
9406 if (!entry->visible && priv->caps_lock_warning)
9408 gboolean capslock_on;
9411 capslock_on = gdk_keymap_get_caps_lock_state (keymap);
9412 im_on = g_strcmp0 (gtk_im_multicontext_get_context_id (GTK_IM_MULTICONTEXT (entry->im_context)), "gtk-im-context-simple") != 0;
9413 if (capslock_on && im_on)
9414 text = _("You have the Caps Lock key on\nand an active input method");
9415 else if (capslock_on)
9416 text = _("You have the Caps Lock key on");
9418 text = _("You have an active input method");
9422 show_capslock_feedback (entry, text);
9424 remove_capslock_feedback (entry);
9427 #define __GTK_ENTRY_C__
9428 #include "gtkaliasdef.c"