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 change_count : 8;
128 guint progress_pulse_mode : 1;
129 guint progress_pulse_way_back : 1;
132 GtkShadowType shadow_type;
134 gdouble progress_fraction;
135 gdouble progress_pulse_fraction;
136 gdouble progress_pulse_current;
138 EntryIconInfo *icons[MAX_ICONS];
144 typedef struct _GtkEntryPasswordHint GtkEntryPasswordHint;
146 struct _GtkEntryPasswordHint
148 gchar password_hint[PASSWORD_HINT_MAX];
149 guint password_hint_timeout_id;
150 gint password_hint_length;
151 gint password_hint_position;
154 typedef struct _GtkEntryCapslockFeedback GtkEntryCapslockFeedback;
156 struct _GtkEntryCapslockFeedback
181 PROP_CURSOR_POSITION,
182 PROP_SELECTION_BOUND,
189 PROP_ACTIVATES_DEFAULT,
194 PROP_TRUNCATE_MULTILINE,
198 PROP_INVISIBLE_CHAR_SET,
199 PROP_CAPS_LOCK_WARNING,
200 PROP_PROGRESS_FRACTION,
201 PROP_PROGRESS_PULSE_STEP,
203 PROP_PIXBUF_SECONDARY,
205 PROP_STOCK_SECONDARY,
206 PROP_ICON_NAME_PRIMARY,
207 PROP_ICON_NAME_SECONDARY,
209 PROP_GICON_SECONDARY,
210 PROP_STORAGE_TYPE_PRIMARY,
211 PROP_STORAGE_TYPE_SECONDARY,
212 PROP_ACTIVATABLE_PRIMARY,
213 PROP_ACTIVATABLE_SECONDARY,
214 PROP_SENSITIVE_PRIMARY,
215 PROP_SENSITIVE_SECONDARY
218 static guint signals[LAST_SIGNAL] = { 0 };
225 /* GObject, GtkObject methods
227 static void gtk_entry_editable_init (GtkEditableClass *iface);
228 static void gtk_entry_cell_editable_init (GtkCellEditableIface *iface);
229 static void gtk_entry_set_property (GObject *object,
233 static void gtk_entry_get_property (GObject *object,
237 static void gtk_entry_finalize (GObject *object);
238 static void gtk_entry_destroy (GtkObject *object);
239 static void gtk_entry_dispose (GObject *object);
243 static void gtk_entry_realize (GtkWidget *widget);
244 static void gtk_entry_unrealize (GtkWidget *widget);
245 static void gtk_entry_map (GtkWidget *widget);
246 static void gtk_entry_unmap (GtkWidget *widget);
247 static void gtk_entry_size_request (GtkWidget *widget,
248 GtkRequisition *requisition);
249 static void gtk_entry_size_allocate (GtkWidget *widget,
250 GtkAllocation *allocation);
251 static void gtk_entry_draw_frame (GtkWidget *widget,
253 static void gtk_entry_draw_progress (GtkWidget *widget,
254 GdkEventExpose *event);
255 static gint gtk_entry_expose (GtkWidget *widget,
256 GdkEventExpose *event);
257 static gint gtk_entry_button_press (GtkWidget *widget,
258 GdkEventButton *event);
259 static gint gtk_entry_button_release (GtkWidget *widget,
260 GdkEventButton *event);
261 static gint gtk_entry_enter_notify (GtkWidget *widget,
262 GdkEventCrossing *event);
263 static gint gtk_entry_leave_notify (GtkWidget *widget,
264 GdkEventCrossing *event);
265 static gint gtk_entry_motion_notify (GtkWidget *widget,
266 GdkEventMotion *event);
267 static gint gtk_entry_key_press (GtkWidget *widget,
269 static gint gtk_entry_key_release (GtkWidget *widget,
271 static gint gtk_entry_focus_in (GtkWidget *widget,
272 GdkEventFocus *event);
273 static gint gtk_entry_focus_out (GtkWidget *widget,
274 GdkEventFocus *event);
275 static void gtk_entry_grab_focus (GtkWidget *widget);
276 static void gtk_entry_style_set (GtkWidget *widget,
277 GtkStyle *previous_style);
278 static gboolean gtk_entry_query_tooltip (GtkWidget *widget,
281 gboolean keyboard_tip,
282 GtkTooltip *tooltip);
283 static void gtk_entry_direction_changed (GtkWidget *widget,
284 GtkTextDirection previous_dir);
285 static void gtk_entry_state_changed (GtkWidget *widget,
286 GtkStateType previous_state);
287 static void gtk_entry_screen_changed (GtkWidget *widget,
288 GdkScreen *old_screen);
290 static gboolean gtk_entry_drag_drop (GtkWidget *widget,
291 GdkDragContext *context,
295 static gboolean gtk_entry_drag_motion (GtkWidget *widget,
296 GdkDragContext *context,
300 static void gtk_entry_drag_leave (GtkWidget *widget,
301 GdkDragContext *context,
303 static void gtk_entry_drag_data_received (GtkWidget *widget,
304 GdkDragContext *context,
307 GtkSelectionData *selection_data,
310 static void gtk_entry_drag_data_get (GtkWidget *widget,
311 GdkDragContext *context,
312 GtkSelectionData *selection_data,
315 static void gtk_entry_drag_data_delete (GtkWidget *widget,
316 GdkDragContext *context);
317 static void gtk_entry_drag_begin (GtkWidget *widget,
318 GdkDragContext *context);
319 static void gtk_entry_drag_end (GtkWidget *widget,
320 GdkDragContext *context);
323 /* GtkEditable method implementations
325 static void gtk_entry_insert_text (GtkEditable *editable,
326 const gchar *new_text,
327 gint new_text_length,
329 static void gtk_entry_delete_text (GtkEditable *editable,
332 static gchar * gtk_entry_get_chars (GtkEditable *editable,
335 static void gtk_entry_real_set_position (GtkEditable *editable,
337 static gint gtk_entry_get_position (GtkEditable *editable);
338 static void gtk_entry_set_selection_bounds (GtkEditable *editable,
341 static gboolean gtk_entry_get_selection_bounds (GtkEditable *editable,
345 /* GtkCellEditable method implementations
347 static void gtk_entry_start_editing (GtkCellEditable *cell_editable,
350 /* Default signal handlers
352 static void gtk_entry_real_insert_text (GtkEditable *editable,
353 const gchar *new_text,
354 gint new_text_length,
356 static void gtk_entry_real_delete_text (GtkEditable *editable,
359 static void gtk_entry_move_cursor (GtkEntry *entry,
360 GtkMovementStep step,
362 gboolean extend_selection);
363 static void gtk_entry_insert_at_cursor (GtkEntry *entry,
365 static void gtk_entry_delete_from_cursor (GtkEntry *entry,
368 static void gtk_entry_backspace (GtkEntry *entry);
369 static void gtk_entry_cut_clipboard (GtkEntry *entry);
370 static void gtk_entry_copy_clipboard (GtkEntry *entry);
371 static void gtk_entry_paste_clipboard (GtkEntry *entry);
372 static void gtk_entry_toggle_overwrite (GtkEntry *entry);
373 static void gtk_entry_select_all (GtkEntry *entry);
374 static void gtk_entry_real_activate (GtkEntry *entry);
375 static gboolean gtk_entry_popup_menu (GtkWidget *widget);
377 static void keymap_direction_changed (GdkKeymap *keymap,
379 static void keymap_state_changed (GdkKeymap *keymap,
381 static void remove_capslock_feedback (GtkEntry *entry);
383 /* IM Context Callbacks
385 static void gtk_entry_commit_cb (GtkIMContext *context,
388 static void gtk_entry_preedit_changed_cb (GtkIMContext *context,
390 static gboolean gtk_entry_retrieve_surrounding_cb (GtkIMContext *context,
392 static gboolean gtk_entry_delete_surrounding_cb (GtkIMContext *context,
399 static void gtk_entry_enter_text (GtkEntry *entry,
401 static void gtk_entry_set_positions (GtkEntry *entry,
403 gint selection_bound);
404 static void gtk_entry_draw_text (GtkEntry *entry);
405 static void gtk_entry_draw_cursor (GtkEntry *entry,
407 static PangoLayout *gtk_entry_ensure_layout (GtkEntry *entry,
408 gboolean include_preedit);
409 static void gtk_entry_reset_layout (GtkEntry *entry);
410 static void gtk_entry_queue_draw (GtkEntry *entry);
411 static void gtk_entry_recompute (GtkEntry *entry);
412 static gint gtk_entry_find_position (GtkEntry *entry,
414 static void gtk_entry_get_cursor_locations (GtkEntry *entry,
418 static void gtk_entry_adjust_scroll (GtkEntry *entry);
419 static gint gtk_entry_move_visually (GtkEntry *editable,
422 static gint gtk_entry_move_logically (GtkEntry *entry,
425 static gint gtk_entry_move_forward_word (GtkEntry *entry,
427 gboolean allow_whitespace);
428 static gint gtk_entry_move_backward_word (GtkEntry *entry,
430 gboolean allow_whitespace);
431 static void gtk_entry_delete_whitespace (GtkEntry *entry);
432 static void gtk_entry_select_word (GtkEntry *entry);
433 static void gtk_entry_select_line (GtkEntry *entry);
434 static char * gtk_entry_get_public_chars (GtkEntry *entry,
437 static void gtk_entry_paste (GtkEntry *entry,
439 static void gtk_entry_update_primary_selection (GtkEntry *entry);
440 static void gtk_entry_do_popup (GtkEntry *entry,
441 GdkEventButton *event);
442 static gboolean gtk_entry_mnemonic_activate (GtkWidget *widget,
443 gboolean group_cycling);
444 static void gtk_entry_state_changed (GtkWidget *widget,
445 GtkStateType previous_state);
446 static void gtk_entry_check_cursor_blink (GtkEntry *entry);
447 static void gtk_entry_pend_cursor_blink (GtkEntry *entry);
448 static void gtk_entry_reset_blink_time (GtkEntry *entry);
449 static void get_text_area_size (GtkEntry *entry,
450 GtkAllocation *alloc);
451 static void gtk_entry_get_text_area_size (GtkEntry *entry,
456 static void get_widget_window_size (GtkEntry *entry,
461 static void gtk_entry_move_adjustments (GtkEntry *entry);
462 static void gtk_entry_ensure_pixbuf (GtkEntry *entry,
463 GtkEntryIconPosition icon_pos);
467 static gint gtk_entry_completion_timeout (gpointer data);
468 static gboolean gtk_entry_completion_key_press (GtkWidget *widget,
471 static void gtk_entry_completion_changed (GtkWidget *entry,
473 static gboolean check_completion_callback (GtkEntryCompletion *completion);
474 static void clear_completion_callback (GtkEntry *entry,
476 static gboolean accept_completion_callback (GtkEntry *entry);
477 static void completion_insert_text_callback (GtkEntry *entry,
481 GtkEntryCompletion *completion);
482 static void completion_changed (GtkEntryCompletion *completion,
485 static void disconnect_completion_signals (GtkEntry *entry,
486 GtkEntryCompletion *completion);
487 static void connect_completion_signals (GtkEntry *entry,
488 GtkEntryCompletion *completion);
490 static void begin_change (GtkEntry *entry);
491 static void end_change (GtkEntry *entry);
492 static void emit_changed (GtkEntry *entry);
495 G_DEFINE_TYPE_WITH_CODE (GtkEntry, gtk_entry, GTK_TYPE_WIDGET,
496 G_IMPLEMENT_INTERFACE (GTK_TYPE_EDITABLE,
497 gtk_entry_editable_init)
498 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_EDITABLE,
499 gtk_entry_cell_editable_init))
502 add_move_binding (GtkBindingSet *binding_set,
505 GtkMovementStep step,
508 g_return_if_fail ((modmask & GDK_SHIFT_MASK) == 0);
510 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
514 G_TYPE_BOOLEAN, FALSE);
516 /* Selection-extending version */
517 gtk_binding_entry_add_signal (binding_set, keyval, modmask | GDK_SHIFT_MASK,
521 G_TYPE_BOOLEAN, TRUE);
525 gtk_entry_class_init (GtkEntryClass *class)
527 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
528 GtkWidgetClass *widget_class;
529 GtkObjectClass *gtk_object_class;
530 GtkBindingSet *binding_set;
532 widget_class = (GtkWidgetClass*) class;
533 gtk_object_class = (GtkObjectClass *)class;
535 gobject_class->dispose = gtk_entry_dispose;
536 gobject_class->finalize = gtk_entry_finalize;
537 gobject_class->set_property = gtk_entry_set_property;
538 gobject_class->get_property = gtk_entry_get_property;
540 widget_class->map = gtk_entry_map;
541 widget_class->unmap = gtk_entry_unmap;
542 widget_class->realize = gtk_entry_realize;
543 widget_class->unrealize = gtk_entry_unrealize;
544 widget_class->size_request = gtk_entry_size_request;
545 widget_class->size_allocate = gtk_entry_size_allocate;
546 widget_class->expose_event = gtk_entry_expose;
547 widget_class->enter_notify_event = gtk_entry_enter_notify;
548 widget_class->leave_notify_event = gtk_entry_leave_notify;
549 widget_class->button_press_event = gtk_entry_button_press;
550 widget_class->button_release_event = gtk_entry_button_release;
551 widget_class->motion_notify_event = gtk_entry_motion_notify;
552 widget_class->key_press_event = gtk_entry_key_press;
553 widget_class->key_release_event = gtk_entry_key_release;
554 widget_class->focus_in_event = gtk_entry_focus_in;
555 widget_class->focus_out_event = gtk_entry_focus_out;
556 widget_class->grab_focus = gtk_entry_grab_focus;
557 widget_class->style_set = gtk_entry_style_set;
558 widget_class->query_tooltip = gtk_entry_query_tooltip;
559 widget_class->drag_begin = gtk_entry_drag_begin;
560 widget_class->drag_end = gtk_entry_drag_end;
561 widget_class->direction_changed = gtk_entry_direction_changed;
562 widget_class->state_changed = gtk_entry_state_changed;
563 widget_class->screen_changed = gtk_entry_screen_changed;
564 widget_class->mnemonic_activate = gtk_entry_mnemonic_activate;
566 widget_class->drag_drop = gtk_entry_drag_drop;
567 widget_class->drag_motion = gtk_entry_drag_motion;
568 widget_class->drag_leave = gtk_entry_drag_leave;
569 widget_class->drag_data_received = gtk_entry_drag_data_received;
570 widget_class->drag_data_get = gtk_entry_drag_data_get;
571 widget_class->drag_data_delete = gtk_entry_drag_data_delete;
573 widget_class->popup_menu = gtk_entry_popup_menu;
575 gtk_object_class->destroy = gtk_entry_destroy;
577 class->move_cursor = gtk_entry_move_cursor;
578 class->insert_at_cursor = gtk_entry_insert_at_cursor;
579 class->delete_from_cursor = gtk_entry_delete_from_cursor;
580 class->backspace = gtk_entry_backspace;
581 class->cut_clipboard = gtk_entry_cut_clipboard;
582 class->copy_clipboard = gtk_entry_copy_clipboard;
583 class->paste_clipboard = gtk_entry_paste_clipboard;
584 class->toggle_overwrite = gtk_entry_toggle_overwrite;
585 class->activate = gtk_entry_real_activate;
586 class->get_text_area_size = gtk_entry_get_text_area_size;
588 quark_inner_border = g_quark_from_static_string ("gtk-entry-inner-border");
589 quark_password_hint = g_quark_from_static_string ("gtk-entry-password-hint");
590 quark_cursor_hadjustment = g_quark_from_static_string ("gtk-hadjustment");
591 quark_capslock_feedback = g_quark_from_static_string ("gtk-entry-capslock-feedback");
593 g_object_class_install_property (gobject_class,
594 PROP_CURSOR_POSITION,
595 g_param_spec_int ("cursor-position",
596 P_("Cursor Position"),
597 P_("The current position of the insertion cursor in chars"),
601 GTK_PARAM_READABLE));
603 g_object_class_install_property (gobject_class,
604 PROP_SELECTION_BOUND,
605 g_param_spec_int ("selection-bound",
606 P_("Selection Bound"),
607 P_("The position of the opposite end of the selection from the cursor in chars"),
611 GTK_PARAM_READABLE));
613 g_object_class_install_property (gobject_class,
615 g_param_spec_boolean ("editable",
617 P_("Whether the entry contents can be edited"),
619 GTK_PARAM_READWRITE));
621 g_object_class_install_property (gobject_class,
623 g_param_spec_int ("max-length",
624 P_("Maximum length"),
625 P_("Maximum number of characters for this entry. Zero if no maximum"),
629 GTK_PARAM_READWRITE));
630 g_object_class_install_property (gobject_class,
632 g_param_spec_boolean ("visibility",
634 P_("FALSE displays the \"invisible char\" instead of the actual text (password mode)"),
636 GTK_PARAM_READWRITE));
638 g_object_class_install_property (gobject_class,
640 g_param_spec_boolean ("has-frame",
642 P_("FALSE removes outside bevel from entry"),
644 GTK_PARAM_READWRITE));
646 g_object_class_install_property (gobject_class,
648 g_param_spec_boxed ("inner-border",
650 P_("Border between text and frame. Overrides the inner-border style property"),
652 GTK_PARAM_READWRITE));
654 g_object_class_install_property (gobject_class,
656 g_param_spec_unichar ("invisible-char",
657 P_("Invisible character"),
658 P_("The character to use when masking entry contents (in \"password mode\")"),
660 GTK_PARAM_READWRITE));
662 g_object_class_install_property (gobject_class,
663 PROP_ACTIVATES_DEFAULT,
664 g_param_spec_boolean ("activates-default",
665 P_("Activates default"),
666 P_("Whether to activate the default widget (such as the default button in a dialog) when Enter is pressed"),
668 GTK_PARAM_READWRITE));
669 g_object_class_install_property (gobject_class,
671 g_param_spec_int ("width-chars",
672 P_("Width in chars"),
673 P_("Number of characters to leave space for in the entry"),
677 GTK_PARAM_READWRITE));
679 g_object_class_install_property (gobject_class,
681 g_param_spec_int ("scroll-offset",
683 P_("Number of pixels of the entry scrolled off the screen to the left"),
687 GTK_PARAM_READABLE));
689 g_object_class_install_property (gobject_class,
691 g_param_spec_string ("text",
693 P_("The contents of the entry"),
695 GTK_PARAM_READWRITE));
700 * The horizontal alignment, from 0 (left) to 1 (right).
701 * Reversed for RTL layouts.
705 g_object_class_install_property (gobject_class,
707 g_param_spec_float ("xalign",
709 P_("The horizontal alignment, from 0 (left) to 1 (right). Reversed for RTL layouts."),
713 GTK_PARAM_READWRITE));
716 * GtkEntry:truncate-multiline:
718 * When %TRUE, pasted multi-line text is truncated to the first line.
722 g_object_class_install_property (gobject_class,
723 PROP_TRUNCATE_MULTILINE,
724 g_param_spec_boolean ("truncate-multiline",
725 P_("Truncate multiline"),
726 P_("Whether to truncate multiline pastes to one line."),
728 GTK_PARAM_READWRITE));
731 * GtkEntry:shadow-type:
733 * Which kind of shadow to draw around the entry when
734 * #GtkEntry:has-frame is set to %TRUE.
738 g_object_class_install_property (gobject_class,
740 g_param_spec_enum ("shadow-type",
742 P_("Which kind of shadow to draw around the entry when has-frame is set"),
743 GTK_TYPE_SHADOW_TYPE,
745 GTK_PARAM_READWRITE));
748 * GtkEntry:overwrite-mode:
750 * If text is overwritten when typing in the #GtkEntry.
754 g_object_class_install_property (gobject_class,
756 g_param_spec_boolean ("overwrite-mode",
757 P_("Overwrite mode"),
758 P_("Whether new text overwrites existing text"),
760 GTK_PARAM_READWRITE));
763 * GtkEntry:text-length:
765 * The length of the text in the #GtkEntry.
769 g_object_class_install_property (gobject_class,
771 g_param_spec_uint ("text-length",
773 P_("Length of the text currently in the entry"),
777 GTK_PARAM_READABLE));
779 * GtkEntry:invisible-char-set:
781 * Whether the invisible char has been set for the #GtkEntry.
785 g_object_class_install_property (gobject_class,
786 PROP_INVISIBLE_CHAR_SET,
787 g_param_spec_boolean ("invisible-char-set",
788 P_("Invisible char set"),
789 P_("Whether the invisible char has been set"),
791 GTK_PARAM_READWRITE));
794 * GtkEntry:caps-lock-warning
796 * Whether password entries will show a warning when Caps Lock is on
797 * or an input method is active.
801 g_object_class_install_property (gobject_class,
802 PROP_CAPS_LOCK_WARNING,
803 g_param_spec_boolean ("caps-lock-warning",
804 P_("Caps Lock warning"),
805 P_("Whether password entries will show a warning when Caps Lock is on or an input method is active"),
807 GTK_PARAM_READWRITE));
810 * GtkEntry:progress-fraction:
812 * The current fraction of the task that's been completed.
816 g_object_class_install_property (gobject_class,
817 PROP_PROGRESS_FRACTION,
818 g_param_spec_double ("progress-fraction",
819 P_("Progress Fraction"),
820 P_("The current fraction of the task that's been completed"),
824 GTK_PARAM_READWRITE));
827 * GtkEntry:progress-pulse-step:
829 * The fraction of total entry width to move the progress
830 * bouncing block for each call to gtk_entry_progress_pulse().
834 g_object_class_install_property (gobject_class,
835 PROP_PROGRESS_PULSE_STEP,
836 g_param_spec_double ("progress-pulse-step",
837 P_("Progress Pulse Step"),
838 P_("The fraction of total entry width to move the progress bouncing block for each call to gtk_entry_progress_pulse()"),
842 GTK_PARAM_READWRITE));
845 * GtkEntry:pixbuf-primary:
847 * A pixbuf to use as the primary icon for the entry.
851 g_object_class_install_property (gobject_class,
853 g_param_spec_object ("pixbuf-primary",
854 P_("Primary pixbuf"),
855 P_("Primary pixbuf for the entry"),
857 GTK_PARAM_READWRITE));
860 * GtkEntry:pixbuf-secondary:
862 * An pixbuf to use as the secondary icon for the entry.
866 g_object_class_install_property (gobject_class,
867 PROP_PIXBUF_SECONDARY,
868 g_param_spec_object ("pixbuf-secondary",
869 P_("Secondary pixbuf"),
870 P_("Secondary pixbuf for the entry"),
872 GTK_PARAM_READWRITE));
875 * GtkEntry:stock-primary:
877 * The stock id to use for the primary icon for the entry.
881 g_object_class_install_property (gobject_class,
883 g_param_spec_string ("stock-primary",
884 P_("Primary stock ID"),
885 P_("Stock ID for primary icon"),
887 GTK_PARAM_WRITABLE));
890 * GtkEntry:stock-secondary:
892 * The stock id to use for the secondary icon for the entry.
896 g_object_class_install_property (gobject_class,
897 PROP_STOCK_SECONDARY,
898 g_param_spec_string ("stock-secondary",
899 P_("Secondary stock ID"),
900 P_("Stock ID for secondary icon"),
902 GTK_PARAM_WRITABLE));
905 * GtkEntry:icon-name-primary:
907 * The icon name to use for the primary icon for the entry.
911 g_object_class_install_property (gobject_class,
912 PROP_ICON_NAME_PRIMARY,
913 g_param_spec_string ("icon-name-primary",
914 P_("Primary icon name"),
915 P_("Icon name for primary icon"),
917 GTK_PARAM_WRITABLE));
920 * GtkEntry:icon-name-secondary:
922 * The icon name to use for the secondary icon for the entry.
926 g_object_class_install_property (gobject_class,
927 PROP_ICON_NAME_SECONDARY,
928 g_param_spec_string ("icon-name-secondary",
929 P_("Secondary icon name"),
930 P_("Icon name for secondary icon"),
932 GTK_PARAM_WRITABLE));
935 * GtkEntry:gicon-primary:
937 * The #GIcon to use for the primary icon for the entry.
941 g_object_class_install_property (gobject_class,
943 g_param_spec_object ("gicon-primary",
945 P_("GIcon for primary icon"),
947 GTK_PARAM_READWRITE));
950 * GtkEntry:gicon-secondary:
952 * The #GIcon to use for the secondary icon for the entry.
956 g_object_class_install_property (gobject_class,
957 PROP_GICON_SECONDARY,
958 g_param_spec_object ("gicon-secondary",
959 P_("Secondary GIcon"),
960 P_("GIcon for secondary icon"),
962 GTK_PARAM_READWRITE));
965 * GtkEntry:storage-type-primary:
967 * The representation which is used for the primary icon of the entry.
971 g_object_class_install_property (gobject_class,
972 PROP_STORAGE_TYPE_PRIMARY,
973 g_param_spec_enum ("storage-type-primary",
974 P_("Primary storage type"),
975 P_("The representation being used for primary icon"),
978 GTK_PARAM_READABLE));
981 * GtkEntry:storage-type-secondary:
983 * The representation which is used for the secondary icon of the entry.
987 g_object_class_install_property (gobject_class,
988 PROP_STORAGE_TYPE_SECONDARY,
989 g_param_spec_enum ("storage-type-secondary",
990 P_("Secondary storage type"),
991 P_("The representation being used for secondary icon"),
994 GTK_PARAM_READABLE));
997 * GtkEntry:activatable-primary:
999 * Whether the primary icon is activatable.
1001 * GTK+ emits the #GtkEntry::icon-pressed and #GtkEntry::icon-released
1002 * signals only on sensitive, activatable icons.
1004 * Sensitive, but non-activatable icons can be used for purely
1005 * informational purposes.
1009 g_object_class_install_property (gobject_class,
1010 PROP_ACTIVATABLE_PRIMARY,
1011 g_param_spec_boolean ("activatable-primary",
1012 P_("Primary icon activatable"),
1013 P_("Whether the primary icon is activatable"),
1015 GTK_PARAM_READWRITE));
1018 * GtkEntry:activatable-secondary:
1020 * Whether the secondary icon is activatable.
1022 * GTK+ emits the #GtkEntry::icon-pressed and #GtkEntry::icon-released
1023 * signals only on sensitive, activatable icons.
1025 * Sensitive, but non-activatable icons can be used for purely
1026 * informational purposes.
1030 g_object_class_install_property (gobject_class,
1031 PROP_ACTIVATABLE_SECONDARY,
1032 g_param_spec_boolean ("activatable-secondary",
1033 P_("Secondary icon activatable"),
1034 P_("Whether the secondary icon is activatable"),
1036 GTK_PARAM_READWRITE));
1040 * GtkEntry:sensitive-primary:
1042 * Whether the primary icon is sensitive.
1044 * An insensitive icon appears grayed out. GTK+ does not emit the
1045 * #GtkEntry::icon-pressed and #GtkEntry::icon-released signals and
1046 * does not allow DND from insensitive icons.
1048 * An icon should be set insensitive if the action that would trigger
1049 * when clicked is currently not available.
1053 g_object_class_install_property (gobject_class,
1054 PROP_SENSITIVE_PRIMARY,
1055 g_param_spec_boolean ("sensitive-primary",
1056 P_("Primary icon sensitive"),
1057 P_("Whether the primary icon is sensitive"),
1059 GTK_PARAM_READWRITE));
1062 * GtkEntry:sensitive-secondary:
1064 * Whether the secondary icon is sensitive.
1066 * An insensitive icon appears grayed out. GTK+ does not emit the
1067 * #GtkEntry::icon-pressed and #GtkEntry::icon-released signals and
1068 * does not allow DND from insensitive icons.
1070 * An icon should be set insensitive if the action that would trigger
1071 * when clicked is currently not available.
1075 g_object_class_install_property (gobject_class,
1076 PROP_SENSITIVE_SECONDARY,
1077 g_param_spec_boolean ("sensitive-secondary",
1078 P_("Secondary icon sensitive"),
1079 P_("Whether the secondary icon is sensitive"),
1081 GTK_PARAM_READWRITE));
1084 * GtkEntry:prelight:
1086 * The prelight style property determines whether activatable
1087 * icons prelight on mouseover.
1091 gtk_widget_class_install_style_property (widget_class,
1092 g_param_spec_boolean ("prelight",
1094 P_("Whether activatable icons should prelight when hovered"),
1096 GTK_PARAM_READABLE));
1098 signals[POPULATE_POPUP] =
1099 g_signal_new (I_("populate-popup"),
1100 G_OBJECT_CLASS_TYPE (gobject_class),
1102 G_STRUCT_OFFSET (GtkEntryClass, populate_popup),
1104 _gtk_marshal_VOID__OBJECT,
1108 /* Action signals */
1111 g_signal_new (I_("activate"),
1112 G_OBJECT_CLASS_TYPE (gobject_class),
1113 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1114 G_STRUCT_OFFSET (GtkEntryClass, activate),
1116 _gtk_marshal_VOID__VOID,
1118 widget_class->activate_signal = signals[ACTIVATE];
1120 signals[MOVE_CURSOR] =
1121 g_signal_new (I_("move-cursor"),
1122 G_OBJECT_CLASS_TYPE (gobject_class),
1123 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1124 G_STRUCT_OFFSET (GtkEntryClass, move_cursor),
1126 _gtk_marshal_VOID__ENUM_INT_BOOLEAN,
1128 GTK_TYPE_MOVEMENT_STEP,
1132 signals[INSERT_AT_CURSOR] =
1133 g_signal_new (I_("insert-at-cursor"),
1134 G_OBJECT_CLASS_TYPE (gobject_class),
1135 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1136 G_STRUCT_OFFSET (GtkEntryClass, insert_at_cursor),
1138 _gtk_marshal_VOID__STRING,
1142 signals[DELETE_FROM_CURSOR] =
1143 g_signal_new (I_("delete-from-cursor"),
1144 G_OBJECT_CLASS_TYPE (gobject_class),
1145 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1146 G_STRUCT_OFFSET (GtkEntryClass, delete_from_cursor),
1148 _gtk_marshal_VOID__ENUM_INT,
1150 GTK_TYPE_DELETE_TYPE,
1153 signals[BACKSPACE] =
1154 g_signal_new (I_("backspace"),
1155 G_OBJECT_CLASS_TYPE (gobject_class),
1156 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1157 G_STRUCT_OFFSET (GtkEntryClass, backspace),
1159 _gtk_marshal_VOID__VOID,
1162 signals[CUT_CLIPBOARD] =
1163 g_signal_new (I_("cut-clipboard"),
1164 G_OBJECT_CLASS_TYPE (gobject_class),
1165 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1166 G_STRUCT_OFFSET (GtkEntryClass, cut_clipboard),
1168 _gtk_marshal_VOID__VOID,
1171 signals[COPY_CLIPBOARD] =
1172 g_signal_new (I_("copy-clipboard"),
1173 G_OBJECT_CLASS_TYPE (gobject_class),
1174 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1175 G_STRUCT_OFFSET (GtkEntryClass, copy_clipboard),
1177 _gtk_marshal_VOID__VOID,
1180 signals[PASTE_CLIPBOARD] =
1181 g_signal_new (I_("paste-clipboard"),
1182 G_OBJECT_CLASS_TYPE (gobject_class),
1183 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1184 G_STRUCT_OFFSET (GtkEntryClass, paste_clipboard),
1186 _gtk_marshal_VOID__VOID,
1189 signals[TOGGLE_OVERWRITE] =
1190 g_signal_new (I_("toggle-overwrite"),
1191 G_OBJECT_CLASS_TYPE (gobject_class),
1192 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1193 G_STRUCT_OFFSET (GtkEntryClass, toggle_overwrite),
1195 _gtk_marshal_VOID__VOID,
1199 * GtkEntry::icon-pressed:
1200 * @entry: The entry on which the signal is emitted
1201 * @icon_pos: The position of the clicked icon
1202 * @event: the button press event
1204 * The ::icon-pressed signal is emitted when an activatable icon
1209 signals[ICON_PRESSED] =
1210 g_signal_new (I_("icon-pressed"),
1211 G_TYPE_FROM_CLASS (gobject_class),
1212 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1215 _gtk_marshal_VOID__ENUM_BOXED,
1217 GTK_TYPE_ENTRY_ICON_POSITION,
1221 * GtkEntry::icon-released:
1222 * @entry: The entry on which the signal is emitted
1223 * @icon_pos: The position of the clicked icon
1224 * @event: the button release event
1226 * The ::icon-released signal is emitted on the button release from a
1227 * mouse click over an activatable icon.
1231 signals[ICON_RELEASED] =
1232 g_signal_new (I_("icon-released"),
1233 G_TYPE_FROM_CLASS (gobject_class),
1234 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1237 _gtk_marshal_VOID__ENUM_BOXED,
1239 GTK_TYPE_ENTRY_ICON_POSITION,
1247 binding_set = gtk_binding_set_by_class (class);
1249 /* Moving the insertion point */
1250 add_move_binding (binding_set, GDK_Right, 0,
1251 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1253 add_move_binding (binding_set, GDK_Left, 0,
1254 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1256 add_move_binding (binding_set, GDK_KP_Right, 0,
1257 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1259 add_move_binding (binding_set, GDK_KP_Left, 0,
1260 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1262 add_move_binding (binding_set, GDK_Right, GDK_CONTROL_MASK,
1263 GTK_MOVEMENT_WORDS, 1);
1265 add_move_binding (binding_set, GDK_Left, GDK_CONTROL_MASK,
1266 GTK_MOVEMENT_WORDS, -1);
1268 add_move_binding (binding_set, GDK_KP_Right, GDK_CONTROL_MASK,
1269 GTK_MOVEMENT_WORDS, 1);
1271 add_move_binding (binding_set, GDK_KP_Left, GDK_CONTROL_MASK,
1272 GTK_MOVEMENT_WORDS, -1);
1274 add_move_binding (binding_set, GDK_Home, 0,
1275 GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
1277 add_move_binding (binding_set, GDK_End, 0,
1278 GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
1280 add_move_binding (binding_set, GDK_KP_Home, 0,
1281 GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
1283 add_move_binding (binding_set, GDK_KP_End, 0,
1284 GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
1286 add_move_binding (binding_set, GDK_Home, GDK_CONTROL_MASK,
1287 GTK_MOVEMENT_BUFFER_ENDS, -1);
1289 add_move_binding (binding_set, GDK_End, GDK_CONTROL_MASK,
1290 GTK_MOVEMENT_BUFFER_ENDS, 1);
1292 add_move_binding (binding_set, GDK_KP_Home, GDK_CONTROL_MASK,
1293 GTK_MOVEMENT_BUFFER_ENDS, -1);
1295 add_move_binding (binding_set, GDK_KP_End, GDK_CONTROL_MASK,
1296 GTK_MOVEMENT_BUFFER_ENDS, 1);
1300 gtk_binding_entry_add_signal (binding_set, GDK_a, GDK_CONTROL_MASK,
1302 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1304 G_TYPE_BOOLEAN, FALSE);
1305 gtk_binding_entry_add_signal (binding_set, GDK_a, GDK_CONTROL_MASK,
1307 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1309 G_TYPE_BOOLEAN, TRUE);
1311 gtk_binding_entry_add_signal (binding_set, GDK_slash, GDK_CONTROL_MASK,
1313 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1315 G_TYPE_BOOLEAN, FALSE);
1316 gtk_binding_entry_add_signal (binding_set, GDK_slash, GDK_CONTROL_MASK,
1318 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1320 G_TYPE_BOOLEAN, TRUE);
1323 gtk_binding_entry_add_signal (binding_set, GDK_backslash, GDK_CONTROL_MASK,
1325 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_VISUAL_POSITIONS,
1327 G_TYPE_BOOLEAN, FALSE);
1328 gtk_binding_entry_add_signal (binding_set, GDK_a, GDK_SHIFT_MASK | GDK_CONTROL_MASK,
1330 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_VISUAL_POSITIONS,
1332 G_TYPE_BOOLEAN, FALSE);
1336 gtk_binding_entry_add_signal (binding_set, GDK_Return, 0,
1338 gtk_binding_entry_add_signal (binding_set, GDK_ISO_Enter, 0,
1340 gtk_binding_entry_add_signal (binding_set, GDK_KP_Enter, 0,
1344 gtk_binding_entry_add_signal (binding_set, GDK_Delete, 0,
1345 "delete-from-cursor", 2,
1346 G_TYPE_ENUM, GTK_DELETE_CHARS,
1349 gtk_binding_entry_add_signal (binding_set, GDK_KP_Delete, 0,
1350 "delete-from-cursor", 2,
1351 G_TYPE_ENUM, GTK_DELETE_CHARS,
1354 gtk_binding_entry_add_signal (binding_set, GDK_BackSpace, 0,
1357 /* Make this do the same as Backspace, to help with mis-typing */
1358 gtk_binding_entry_add_signal (binding_set, GDK_BackSpace, GDK_SHIFT_MASK,
1361 gtk_binding_entry_add_signal (binding_set, GDK_Delete, GDK_CONTROL_MASK,
1362 "delete-from-cursor", 2,
1363 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1366 gtk_binding_entry_add_signal (binding_set, GDK_KP_Delete, GDK_CONTROL_MASK,
1367 "delete-from-cursor", 2,
1368 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1371 gtk_binding_entry_add_signal (binding_set, GDK_BackSpace, GDK_CONTROL_MASK,
1372 "delete-from-cursor", 2,
1373 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1376 /* Cut/copy/paste */
1378 gtk_binding_entry_add_signal (binding_set, GDK_x, GDK_CONTROL_MASK,
1379 "cut-clipboard", 0);
1380 gtk_binding_entry_add_signal (binding_set, GDK_c, GDK_CONTROL_MASK,
1381 "copy-clipboard", 0);
1382 gtk_binding_entry_add_signal (binding_set, GDK_v, GDK_CONTROL_MASK,
1383 "paste-clipboard", 0);
1385 gtk_binding_entry_add_signal (binding_set, GDK_Delete, GDK_SHIFT_MASK,
1386 "cut-clipboard", 0);
1387 gtk_binding_entry_add_signal (binding_set, GDK_Insert, GDK_CONTROL_MASK,
1388 "copy-clipboard", 0);
1389 gtk_binding_entry_add_signal (binding_set, GDK_Insert, GDK_SHIFT_MASK,
1390 "paste-clipboard", 0);
1393 gtk_binding_entry_add_signal (binding_set, GDK_Insert, 0,
1394 "toggle-overwrite", 0);
1395 gtk_binding_entry_add_signal (binding_set, GDK_KP_Insert, 0,
1396 "toggle-overwrite", 0);
1399 * GtkEntry:inner-border:
1401 * Sets the text area's border between the text and the frame.
1405 gtk_widget_class_install_style_property (widget_class,
1406 g_param_spec_boxed ("inner-border",
1408 P_("Border between text and frame."),
1410 GTK_PARAM_READABLE));
1413 * GtkEntry:state-hint:
1415 * Indicates whether to pass a proper widget state when
1416 * drawing the shadow and the widget background.
1420 gtk_widget_class_install_style_property (widget_class,
1421 g_param_spec_boolean ("state-hint",
1423 P_("Whether to pass a proper state when drawing shadow or background"),
1425 GTK_PARAM_READABLE));
1427 gtk_settings_install_property (g_param_spec_boolean ("gtk-entry-select-on-focus",
1428 P_("Select on focus"),
1429 P_("Whether to select the contents of an entry when it is focused"),
1431 GTK_PARAM_READWRITE));
1434 * GtkSettings:gtk-entry-password-hint-timeout:
1436 * How long to show the last input character in hidden
1437 * entries. This value is in milliseconds. 0 disables showing the
1438 * last char. 600 is a good value for enabling it.
1442 gtk_settings_install_property (g_param_spec_uint ("gtk-entry-password-hint-timeout",
1443 P_("Password Hint Timeout"),
1444 P_("How long to show the last input character in hidden entries"),
1446 GTK_PARAM_READWRITE));
1448 g_type_class_add_private (gobject_class, sizeof (GtkEntryPrivate));
1452 gtk_entry_editable_init (GtkEditableClass *iface)
1454 iface->do_insert_text = gtk_entry_insert_text;
1455 iface->do_delete_text = gtk_entry_delete_text;
1456 iface->insert_text = gtk_entry_real_insert_text;
1457 iface->delete_text = gtk_entry_real_delete_text;
1458 iface->get_chars = gtk_entry_get_chars;
1459 iface->set_selection_bounds = gtk_entry_set_selection_bounds;
1460 iface->get_selection_bounds = gtk_entry_get_selection_bounds;
1461 iface->set_position = gtk_entry_real_set_position;
1462 iface->get_position = gtk_entry_get_position;
1466 gtk_entry_cell_editable_init (GtkCellEditableIface *iface)
1468 iface->start_editing = gtk_entry_start_editing;
1472 gtk_entry_set_property (GObject *object,
1474 const GValue *value,
1477 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (object);
1478 GtkEntry *entry = GTK_ENTRY (object);
1484 gboolean new_value = g_value_get_boolean (value);
1486 if (new_value != entry->editable)
1490 _gtk_entry_reset_im_context (entry);
1491 if (GTK_WIDGET_HAS_FOCUS (entry))
1492 gtk_im_context_focus_out (entry->im_context);
1494 entry->preedit_length = 0;
1495 entry->preedit_cursor = 0;
1498 entry->editable = new_value;
1500 if (new_value && GTK_WIDGET_HAS_FOCUS (entry))
1501 gtk_im_context_focus_in (entry->im_context);
1503 gtk_entry_queue_draw (entry);
1508 case PROP_MAX_LENGTH:
1509 gtk_entry_set_max_length (entry, g_value_get_int (value));
1512 case PROP_VISIBILITY:
1513 gtk_entry_set_visibility (entry, g_value_get_boolean (value));
1516 case PROP_HAS_FRAME:
1517 gtk_entry_set_has_frame (entry, g_value_get_boolean (value));
1520 case PROP_INNER_BORDER:
1521 gtk_entry_set_inner_border (entry, g_value_get_boxed (value));
1524 case PROP_INVISIBLE_CHAR:
1525 gtk_entry_set_invisible_char (entry, g_value_get_uint (value));
1528 case PROP_ACTIVATES_DEFAULT:
1529 gtk_entry_set_activates_default (entry, g_value_get_boolean (value));
1532 case PROP_WIDTH_CHARS:
1533 gtk_entry_set_width_chars (entry, g_value_get_int (value));
1537 gtk_entry_set_text (entry, g_value_get_string (value));
1541 gtk_entry_set_alignment (entry, g_value_get_float (value));
1544 case PROP_TRUNCATE_MULTILINE:
1545 entry->truncate_multiline = g_value_get_boolean (value);
1548 case PROP_SHADOW_TYPE:
1549 priv->shadow_type = g_value_get_enum (value);
1552 case PROP_OVERWRITE_MODE:
1553 gtk_entry_set_overwrite_mode (entry, g_value_get_boolean (value));
1556 case PROP_INVISIBLE_CHAR_SET:
1557 if (g_value_get_boolean (value))
1558 priv->invisible_char_set = TRUE;
1560 gtk_entry_unset_invisible_char (entry);
1563 case PROP_CAPS_LOCK_WARNING:
1564 priv->caps_lock_warning = g_value_get_boolean (value);
1567 case PROP_PROGRESS_FRACTION:
1568 gtk_entry_set_progress_fraction (entry, g_value_get_double (value));
1571 case PROP_PROGRESS_PULSE_STEP:
1572 gtk_entry_set_progress_pulse_step (entry, g_value_get_double (value));
1574 case PROP_PIXBUF_PRIMARY:
1575 gtk_entry_set_icon_from_pixbuf (entry,
1576 GTK_ENTRY_ICON_PRIMARY,
1577 g_value_get_object (value));
1580 case PROP_PIXBUF_SECONDARY:
1581 gtk_entry_set_icon_from_pixbuf (entry,
1582 GTK_ENTRY_ICON_SECONDARY,
1583 g_value_get_object (value));
1586 case PROP_STOCK_PRIMARY:
1587 gtk_entry_set_icon_from_stock (entry,
1588 GTK_ENTRY_ICON_PRIMARY,
1589 g_value_get_string (value));
1592 case PROP_STOCK_SECONDARY:
1593 gtk_entry_set_icon_from_stock (entry,
1594 GTK_ENTRY_ICON_SECONDARY,
1595 g_value_get_string (value));
1598 case PROP_ICON_NAME_PRIMARY:
1599 gtk_entry_set_icon_from_icon_name (entry,
1600 GTK_ENTRY_ICON_PRIMARY,
1601 g_value_get_string (value));
1604 case PROP_ICON_NAME_SECONDARY:
1605 gtk_entry_set_icon_from_icon_name (entry,
1606 GTK_ENTRY_ICON_SECONDARY,
1607 g_value_get_string (value));
1610 case PROP_GICON_PRIMARY:
1611 gtk_entry_set_icon_from_gicon (entry,
1612 GTK_ENTRY_ICON_PRIMARY,
1613 g_value_get_object (value));
1616 case PROP_GICON_SECONDARY:
1617 gtk_entry_set_icon_from_gicon (entry,
1618 GTK_ENTRY_ICON_SECONDARY,
1619 g_value_get_object (value));
1622 case PROP_ACTIVATABLE_PRIMARY:
1623 gtk_entry_set_icon_activatable (entry,
1624 GTK_ENTRY_ICON_PRIMARY,
1625 g_value_get_boolean (value));
1628 case PROP_ACTIVATABLE_SECONDARY:
1629 gtk_entry_set_icon_activatable (entry,
1630 GTK_ENTRY_ICON_SECONDARY,
1631 g_value_get_boolean (value));
1634 case PROP_SENSITIVE_PRIMARY:
1635 gtk_entry_set_icon_sensitive (entry,
1636 GTK_ENTRY_ICON_PRIMARY,
1637 g_value_get_boolean (value));
1640 case PROP_SENSITIVE_SECONDARY:
1641 gtk_entry_set_icon_sensitive (entry,
1642 GTK_ENTRY_ICON_SECONDARY,
1643 g_value_get_boolean (value));
1646 case PROP_SCROLL_OFFSET:
1647 case PROP_CURSOR_POSITION:
1649 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1655 gtk_entry_get_property (GObject *object,
1660 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (object);
1661 GtkEntry *entry = GTK_ENTRY (object);
1665 case PROP_CURSOR_POSITION:
1666 g_value_set_int (value, entry->current_pos);
1669 case PROP_SELECTION_BOUND:
1670 g_value_set_int (value, entry->selection_bound);
1674 g_value_set_boolean (value, entry->editable);
1677 case PROP_MAX_LENGTH:
1678 g_value_set_int (value, entry->text_max_length);
1681 case PROP_VISIBILITY:
1682 g_value_set_boolean (value, entry->visible);
1685 case PROP_HAS_FRAME:
1686 g_value_set_boolean (value, entry->has_frame);
1689 case PROP_INNER_BORDER:
1690 g_value_set_boxed (value, gtk_entry_get_inner_border (entry));
1693 case PROP_INVISIBLE_CHAR:
1694 g_value_set_uint (value, entry->invisible_char);
1697 case PROP_ACTIVATES_DEFAULT:
1698 g_value_set_boolean (value, entry->activates_default);
1701 case PROP_WIDTH_CHARS:
1702 g_value_set_int (value, entry->width_chars);
1705 case PROP_SCROLL_OFFSET:
1706 g_value_set_int (value, entry->scroll_offset);
1710 g_value_set_string (value, gtk_entry_get_text (entry));
1714 g_value_set_float (value, gtk_entry_get_alignment (entry));
1717 case PROP_TRUNCATE_MULTILINE:
1718 g_value_set_boolean (value, entry->truncate_multiline);
1721 case PROP_SHADOW_TYPE:
1722 g_value_set_enum (value, priv->shadow_type);
1725 case PROP_OVERWRITE_MODE:
1726 g_value_set_boolean (value, entry->overwrite_mode);
1729 case PROP_TEXT_LENGTH:
1730 g_value_set_uint (value, entry->text_length);
1733 case PROP_INVISIBLE_CHAR_SET:
1734 g_value_set_boolean (value, priv->invisible_char_set);
1737 case PROP_CAPS_LOCK_WARNING:
1738 g_value_set_boolean (value, priv->caps_lock_warning);
1741 case PROP_PROGRESS_FRACTION:
1742 g_value_set_double (value, priv->progress_fraction);
1745 case PROP_PROGRESS_PULSE_STEP:
1746 g_value_set_double (value, priv->progress_pulse_fraction);
1748 case PROP_PIXBUF_PRIMARY:
1749 g_value_set_object (value,
1750 gtk_entry_get_pixbuf (entry,
1751 GTK_ENTRY_ICON_PRIMARY));
1754 case PROP_PIXBUF_SECONDARY:
1755 g_value_set_object (value,
1756 gtk_entry_get_pixbuf (entry,
1757 GTK_ENTRY_ICON_SECONDARY));
1760 case PROP_STOCK_PRIMARY:
1761 g_value_set_string (value,
1762 gtk_entry_get_stock (entry,
1763 GTK_ENTRY_ICON_PRIMARY));
1766 case PROP_STOCK_SECONDARY:
1767 g_value_set_string (value,
1768 gtk_entry_get_stock (entry,
1769 GTK_ENTRY_ICON_SECONDARY));
1772 case PROP_ICON_NAME_PRIMARY:
1773 g_value_set_string (value,
1774 gtk_entry_get_icon_name (entry,
1775 GTK_ENTRY_ICON_PRIMARY));
1778 case PROP_ICON_NAME_SECONDARY:
1779 g_value_set_string (value,
1780 gtk_entry_get_icon_name (entry,
1781 GTK_ENTRY_ICON_SECONDARY));
1784 case PROP_GICON_PRIMARY:
1785 g_value_set_object (value,
1786 gtk_entry_get_gicon (entry,
1787 GTK_ENTRY_ICON_PRIMARY));
1790 case PROP_GICON_SECONDARY:
1791 g_value_set_object (value,
1792 gtk_entry_get_gicon (entry,
1793 GTK_ENTRY_ICON_SECONDARY));
1795 case PROP_STORAGE_TYPE_PRIMARY:
1796 g_value_set_enum (value,
1797 gtk_entry_get_storage_type (entry, GTK_ENTRY_ICON_PRIMARY));
1800 case PROP_STORAGE_TYPE_SECONDARY:
1801 g_value_set_enum (value,
1802 gtk_entry_get_storage_type (entry, GTK_ENTRY_ICON_SECONDARY));
1805 case PROP_ACTIVATABLE_PRIMARY:
1806 g_value_set_boolean (value,
1807 gtk_entry_get_icon_activatable (entry, GTK_ENTRY_ICON_PRIMARY));
1810 case PROP_ACTIVATABLE_SECONDARY:
1811 g_value_set_boolean (value,
1812 gtk_entry_get_icon_activatable (entry, GTK_ENTRY_ICON_SECONDARY));
1815 case PROP_SENSITIVE_PRIMARY:
1816 g_value_set_boolean (value,
1817 gtk_entry_get_icon_sensitive (entry, GTK_ENTRY_ICON_PRIMARY));
1820 case PROP_SENSITIVE_SECONDARY:
1821 g_value_set_boolean (value,
1822 gtk_entry_get_icon_sensitive (entry, GTK_ENTRY_ICON_SECONDARY));
1826 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1832 find_invisible_char (GtkWidget *widget)
1834 PangoLayout *layout;
1835 PangoAttrList *attr_list;
1837 gunichar invisible_chars [] = {
1838 0x25cf, /* BLACK CIRCLE */
1839 0x2022, /* BULLET */
1840 0x2731, /* HEAVY ASTERISK */
1841 0x273a /* SIXTEEN POINTED ASTERISK */
1844 layout = gtk_widget_create_pango_layout (widget, NULL);
1846 attr_list = pango_attr_list_new ();
1847 pango_attr_list_insert (attr_list, pango_attr_fallback_new (FALSE));
1849 pango_layout_set_attributes (layout, attr_list);
1850 pango_attr_list_unref (attr_list);
1852 for (i = 0; i < G_N_ELEMENTS (invisible_chars); i++)
1854 gchar text[7] = { 0, };
1857 len = g_unichar_to_utf8 (invisible_chars[i], text);
1858 pango_layout_set_text (layout, text, len);
1860 count = pango_layout_get_unknown_glyphs_count (layout);
1864 g_object_unref (layout);
1865 return invisible_chars[i];
1869 g_object_unref (layout);
1874 gtk_entry_init (GtkEntry *entry)
1876 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
1878 GTK_WIDGET_SET_FLAGS (entry, GTK_CAN_FOCUS);
1880 entry->text_size = MIN_SIZE;
1881 entry->text = g_malloc (entry->text_size);
1882 entry->text[0] = '\0';
1884 entry->editable = TRUE;
1885 entry->visible = TRUE;
1886 entry->invisible_char = find_invisible_char (GTK_WIDGET (entry));
1887 entry->dnd_position = -1;
1888 entry->width_chars = -1;
1889 entry->is_cell_renderer = FALSE;
1890 entry->editing_canceled = FALSE;
1891 entry->has_frame = TRUE;
1892 entry->truncate_multiline = FALSE;
1893 priv->shadow_type = GTK_SHADOW_IN;
1895 priv->caps_lock_warning = TRUE;
1896 priv->progress_fraction = 0.0;
1897 priv->progress_pulse_fraction = 0.1;
1899 gtk_drag_dest_set (GTK_WIDGET (entry),
1900 GTK_DEST_DEFAULT_HIGHLIGHT,
1902 GDK_ACTION_COPY | GDK_ACTION_MOVE);
1903 gtk_drag_dest_add_text_targets (GTK_WIDGET (entry));
1905 /* This object is completely private. No external entity can gain a reference
1906 * to it; so we create it here and destroy it in finalize().
1908 entry->im_context = gtk_im_multicontext_new ();
1910 g_signal_connect (entry->im_context, "commit",
1911 G_CALLBACK (gtk_entry_commit_cb), entry);
1912 g_signal_connect (entry->im_context, "preedit-changed",
1913 G_CALLBACK (gtk_entry_preedit_changed_cb), entry);
1914 g_signal_connect (entry->im_context, "retrieve-surrounding",
1915 G_CALLBACK (gtk_entry_retrieve_surrounding_cb), entry);
1916 g_signal_connect (entry->im_context, "delete-surrounding",
1917 G_CALLBACK (gtk_entry_delete_surrounding_cb), entry);
1921 get_icon_width (GtkEntry *entry,
1922 GtkEntryIconPosition icon_pos)
1924 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
1925 EntryIconInfo *icon_info;
1927 GtkSettings *settings;
1928 gint menu_icon_width;
1930 if (!(icon_info = priv->icons[icon_pos]))
1933 if (icon_info->pixbuf == NULL)
1936 if (priv->icons[icon_pos] == NULL)
1939 screen = gtk_widget_get_screen (GTK_WIDGET (entry));
1940 settings = gtk_settings_get_for_screen (screen);
1942 gtk_icon_size_lookup_for_settings (settings, GTK_ICON_SIZE_MENU,
1943 &menu_icon_width, NULL);
1945 return MAX (gdk_pixbuf_get_width (icon_info->pixbuf), menu_icon_width);
1949 get_icon_allocation (GtkEntry *entry,
1951 GtkAllocation *widget_alloc,
1952 GtkAllocation *text_area_alloc,
1953 GtkAllocation *allocation,
1954 GtkEntryIconPosition *icon_pos)
1956 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
1959 rtl = (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL);
1962 *icon_pos = (rtl ? GTK_ENTRY_ICON_SECONDARY : GTK_ENTRY_ICON_PRIMARY);
1964 *icon_pos = (rtl ? GTK_ENTRY_ICON_PRIMARY : GTK_ENTRY_ICON_SECONDARY);
1966 allocation->y = text_area_alloc->y;
1967 allocation->width = get_icon_width (entry, *icon_pos);
1968 allocation->height = text_area_alloc->height;
1970 if (allocation->width > 0)
1971 allocation->width += 2 * priv->icon_margin;
1974 allocation->x = text_area_alloc->x;
1976 allocation->x = text_area_alloc->x + text_area_alloc->width - allocation->width;
1981 begin_change (GtkEntry *entry)
1983 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
1985 priv->change_count++;
1989 end_change (GtkEntry *entry)
1991 GtkEditable *editable = GTK_EDITABLE (entry);
1992 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
1994 g_return_if_fail (priv->change_count > 0);
1996 priv->change_count--;
1998 if (priv->change_count == 0)
2000 if (priv->real_changed)
2002 g_signal_emit_by_name (editable, "changed");
2003 priv->real_changed = FALSE;
2009 emit_changed (GtkEntry *entry)
2011 GtkEditable *editable = GTK_EDITABLE (entry);
2012 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2014 if (priv->change_count == 0)
2015 g_signal_emit_by_name (editable, "changed");
2017 priv->real_changed = TRUE;
2021 * Overwrite a memory that might contain sensitive information.
2024 trash_area (gchar *area, gsize len)
2026 volatile gchar *varea = (volatile gchar *)area;
2032 gtk_entry_destroy (GtkObject *object)
2034 GtkEntry *entry = GTK_ENTRY (object);
2037 entry->current_pos = entry->selection_bound = entry->text_length = 0;
2038 _gtk_entry_reset_im_context (entry);
2039 gtk_entry_reset_layout (entry);
2041 if (entry->blink_timeout)
2043 g_source_remove (entry->blink_timeout);
2044 entry->blink_timeout = 0;
2047 if (entry->recompute_idle)
2049 g_source_remove (entry->recompute_idle);
2050 entry->recompute_idle = 0;
2053 if (!entry->visible)
2055 /* We want to trash the text here because the entry might be leaked. */
2056 trash_area (entry->text, strlen (entry->text));
2059 GTK_OBJECT_CLASS (gtk_entry_parent_class)->destroy (object);
2063 gtk_entry_dispose (GObject *object)
2065 GtkEntry *entry = GTK_ENTRY (object);
2067 gtk_entry_set_icon_from_pixbuf (entry, GTK_ENTRY_ICON_PRIMARY, NULL);
2068 gtk_entry_set_icon_tooltip_markup (entry, GTK_ENTRY_ICON_PRIMARY, NULL);
2069 gtk_entry_set_icon_from_pixbuf (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
2070 gtk_entry_set_icon_tooltip_markup (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
2072 G_OBJECT_CLASS (gtk_entry_parent_class)->dispose (object);
2076 gtk_entry_finalize (GObject *object)
2078 GtkEntry *entry = GTK_ENTRY (object);
2079 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2080 EntryIconInfo *icon_info = NULL;
2083 for (i = 0; i < MAX_ICONS; i++)
2085 if ((icon_info = priv->icons[i]) != NULL)
2087 if (icon_info->target_list != NULL)
2089 gtk_target_list_unref (icon_info->target_list);
2090 icon_info->target_list = NULL;
2093 g_slice_free (EntryIconInfo, icon_info);
2094 priv->icons[i] = NULL;
2098 gtk_entry_set_completion (entry, NULL);
2100 if (entry->cached_layout)
2101 g_object_unref (entry->cached_layout);
2103 g_object_unref (entry->im_context);
2105 if (entry->blink_timeout)
2106 g_source_remove (entry->blink_timeout);
2108 if (entry->recompute_idle)
2109 g_source_remove (entry->recompute_idle);
2111 entry->text_size = 0;
2115 if (!entry->visible)
2116 trash_area (entry->text, strlen (entry->text));
2117 g_free (entry->text);
2121 G_OBJECT_CLASS (gtk_entry_parent_class)->finalize (object);
2125 update_cursors (GtkWidget *widget)
2127 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2128 EntryIconInfo *icon_info = NULL;
2129 GdkDisplay *display;
2133 for (i = 0; i < MAX_ICONS; i++)
2135 if ((icon_info = priv->icons[i]) != NULL)
2137 if (icon_info->pixbuf != NULL)
2138 gdk_window_show (icon_info->window);
2140 /* The icon windows are not children of the visible entry window,
2141 * thus we can't just inherit the xterm cursor. Slight complication
2142 * here is that for the entry, insensitive => arrow cursor, but for
2143 * an icon in a sensitive entry, insensitive => xterm cursor.
2145 if (GTK_WIDGET_IS_SENSITIVE (widget) &&
2146 (icon_info->insensitive ||
2147 (icon_info->nonactivatable && icon_info->target_list == NULL)))
2149 display = gtk_widget_get_display (widget);
2150 cursor = gdk_cursor_new_for_display (display, GDK_XTERM);
2151 gdk_window_set_cursor (icon_info->window, cursor);
2152 gdk_cursor_unref (cursor);
2156 gdk_window_set_cursor (icon_info->window, NULL);
2163 realize_icon_info (GtkWidget *widget, GtkEntryIconPosition icon_pos)
2165 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2166 EntryIconInfo *icon_info = priv->icons[icon_pos];
2167 GdkWindowAttr attributes;
2168 gint attributes_mask;
2170 g_return_if_fail (icon_info != NULL);
2174 attributes.width = 1;
2175 attributes.height = 1;
2176 attributes.window_type = GDK_WINDOW_CHILD;
2177 attributes.wclass = GDK_INPUT_OUTPUT;
2178 attributes.visual = gtk_widget_get_visual (widget);
2179 attributes.colormap = gtk_widget_get_colormap (widget);
2180 attributes.event_mask = gtk_widget_get_events (widget);
2181 attributes.event_mask |= (GDK_EXPOSURE_MASK |
2182 GDK_BUTTON_PRESS_MASK |
2183 GDK_BUTTON_RELEASE_MASK |
2184 GDK_BUTTON1_MOTION_MASK |
2185 GDK_BUTTON3_MOTION_MASK |
2186 GDK_POINTER_MOTION_HINT_MASK |
2187 GDK_POINTER_MOTION_MASK |
2188 GDK_ENTER_NOTIFY_MASK |
2189 GDK_LEAVE_NOTIFY_MASK);
2190 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
2192 icon_info->window = gdk_window_new (widget->window,
2195 gdk_window_set_user_data (icon_info->window, widget);
2196 gdk_window_set_background (icon_info->window,
2197 &widget->style->base[GTK_WIDGET_STATE (widget)]);
2199 gtk_widget_queue_resize (widget);
2202 static EntryIconInfo*
2203 construct_icon_info (GtkWidget *widget, GtkEntryIconPosition icon_pos)
2205 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2206 EntryIconInfo *icon_info;
2208 g_return_val_if_fail (priv->icons[icon_pos] == NULL, NULL);
2210 icon_info = g_slice_new0 (EntryIconInfo);
2211 priv->icons[icon_pos] = icon_info;
2213 if (GTK_WIDGET_REALIZED (widget))
2215 realize_icon_info (widget, icon_pos);
2218 if (GTK_WIDGET_MAPPED (widget))
2219 gdk_window_show (icon_info->window);
2225 gtk_entry_map (GtkWidget *widget)
2227 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2228 EntryIconInfo *icon_info = NULL;
2231 if (GTK_WIDGET_REALIZED (widget) && !GTK_WIDGET_MAPPED (widget))
2233 GTK_WIDGET_CLASS (gtk_entry_parent_class)->map (widget);
2235 for (i = 0; i < MAX_ICONS; i++)
2237 if ((icon_info = priv->icons[i]) != NULL)
2239 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
2240 gdk_window_show (icon_info->window);
2244 update_cursors (widget);
2249 gtk_entry_unmap (GtkWidget *widget)
2251 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2252 EntryIconInfo *icon_info = NULL;
2255 if (GTK_WIDGET_MAPPED (widget))
2257 for (i = 0; i < MAX_ICONS; i++)
2259 if ((icon_info = priv->icons[i]) != NULL)
2261 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
2262 gdk_window_hide (icon_info->window);
2266 GTK_WIDGET_CLASS (gtk_entry_parent_class)->unmap (widget);
2271 gtk_entry_realize (GtkWidget *widget)
2274 GtkEntryPrivate *priv;
2275 EntryIconInfo *icon_info;
2276 GdkWindowAttr attributes;
2277 gint attributes_mask;
2280 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
2281 entry = GTK_ENTRY (widget);
2282 priv = GTK_ENTRY_GET_PRIVATE (entry);
2284 attributes.window_type = GDK_WINDOW_CHILD;
2286 get_widget_window_size (entry, &attributes.x, &attributes.y, &attributes.width, &attributes.height);
2288 attributes.wclass = GDK_INPUT_OUTPUT;
2289 attributes.visual = gtk_widget_get_visual (widget);
2290 attributes.colormap = gtk_widget_get_colormap (widget);
2291 attributes.event_mask = gtk_widget_get_events (widget);
2292 attributes.event_mask |= (GDK_EXPOSURE_MASK |
2293 GDK_BUTTON_PRESS_MASK |
2294 GDK_BUTTON_RELEASE_MASK |
2295 GDK_BUTTON1_MOTION_MASK |
2296 GDK_BUTTON3_MOTION_MASK |
2297 GDK_POINTER_MOTION_HINT_MASK |
2298 GDK_POINTER_MOTION_MASK |
2299 GDK_ENTER_NOTIFY_MASK |
2300 GDK_LEAVE_NOTIFY_MASK);
2301 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
2303 widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, attributes_mask);
2304 gdk_window_set_user_data (widget->window, entry);
2306 gtk_entry_get_text_area_size (entry, &attributes.x, &attributes.y, &attributes.width, &attributes.height);
2308 if (GTK_WIDGET_IS_SENSITIVE (widget))
2310 attributes.cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
2311 attributes_mask |= GDK_WA_CURSOR;
2314 entry->text_area = gdk_window_new (widget->window, &attributes, attributes_mask);
2316 gdk_window_set_user_data (entry->text_area, entry);
2318 if (attributes_mask & GDK_WA_CURSOR)
2319 gdk_cursor_unref (attributes.cursor);
2321 widget->style = gtk_style_attach (widget->style, widget->window);
2323 gdk_window_set_background (widget->window, &widget->style->base[GTK_WIDGET_STATE (widget)]);
2324 gdk_window_set_background (entry->text_area, &widget->style->base[GTK_WIDGET_STATE (widget)]);
2326 gdk_window_show (entry->text_area);
2328 gtk_im_context_set_client_window (entry->im_context, entry->text_area);
2330 gtk_entry_adjust_scroll (entry);
2331 gtk_entry_update_primary_selection (entry);
2334 /* If the icon positions are already setup, create their windows.
2335 * Otherwise if they don't exist yet, then construct_icon_info()
2336 * will create the windows once the widget is already realized.
2338 for (i = 0; i < MAX_ICONS; i++)
2340 if ((icon_info = priv->icons[i]) != NULL)
2342 if (icon_info->window == NULL)
2343 realize_icon_info (widget, i);
2347 gtk_widget_queue_resize (widget);
2351 gtk_entry_unrealize (GtkWidget *widget)
2353 GtkEntry *entry = GTK_ENTRY (widget);
2354 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2355 GtkClipboard *clipboard;
2356 EntryIconInfo *icon_info;
2359 gtk_entry_reset_layout (entry);
2361 gtk_im_context_set_client_window (entry->im_context, NULL);
2363 clipboard = gtk_widget_get_clipboard (widget, GDK_SELECTION_PRIMARY);
2364 if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (entry))
2365 gtk_clipboard_clear (clipboard);
2367 if (entry->text_area)
2369 gdk_window_set_user_data (entry->text_area, NULL);
2370 gdk_window_destroy (entry->text_area);
2371 entry->text_area = NULL;
2374 if (entry->popup_menu)
2376 gtk_widget_destroy (entry->popup_menu);
2377 entry->popup_menu = NULL;
2380 GTK_WIDGET_CLASS (gtk_entry_parent_class)->unrealize (widget);
2382 for (i = 0; i < MAX_ICONS; i++)
2384 if ((icon_info = priv->icons[i]) != NULL)
2386 if (icon_info->window != NULL)
2388 gdk_window_destroy (icon_info->window);
2389 icon_info->window = NULL;
2396 _gtk_entry_get_borders (GtkEntry *entry,
2400 GtkWidget *widget = GTK_WIDGET (entry);
2401 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2403 if (entry->has_frame)
2405 *xborder = widget->style->xthickness;
2406 *yborder = widget->style->ythickness;
2414 if (!priv->interior_focus)
2416 *xborder += priv->focus_width;
2417 *yborder += priv->focus_width;
2422 gtk_entry_size_request (GtkWidget *widget,
2423 GtkRequisition *requisition)
2425 GtkEntry *entry = GTK_ENTRY (widget);
2426 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2427 PangoFontMetrics *metrics;
2428 gint xborder, yborder;
2429 GtkBorder inner_border;
2430 PangoContext *context;
2431 int icon_widths = 0;
2434 gtk_widget_ensure_style (widget);
2435 context = gtk_widget_get_pango_context (widget);
2436 metrics = pango_context_get_metrics (context,
2437 widget->style->font_desc,
2438 pango_context_get_language (context));
2440 entry->ascent = pango_font_metrics_get_ascent (metrics);
2441 entry->descent = pango_font_metrics_get_descent (metrics);
2443 _gtk_entry_get_borders (entry, &xborder, &yborder);
2444 _gtk_entry_effective_inner_border (entry, &inner_border);
2446 if (entry->width_chars < 0)
2447 requisition->width = MIN_ENTRY_WIDTH + xborder * 2 + inner_border.left + inner_border.right;
2450 gint char_width = pango_font_metrics_get_approximate_char_width (metrics);
2451 gint digit_width = pango_font_metrics_get_approximate_digit_width (metrics);
2452 gint char_pixels = (MAX (char_width, digit_width) + PANGO_SCALE - 1) / PANGO_SCALE;
2454 requisition->width = char_pixels * entry->width_chars + xborder * 2 + inner_border.left + inner_border.right;
2457 requisition->height = PANGO_PIXELS (entry->ascent + entry->descent) + yborder * 2 + inner_border.top + inner_border.bottom;
2459 for (i = 0; i < MAX_ICONS; i++)
2461 icon_width = get_icon_width (entry, i);
2463 icon_widths += icon_width + 2 * priv->icon_margin;
2466 if (icon_widths > requisition->width)
2467 requisition->width += icon_widths;
2469 pango_font_metrics_unref (metrics);
2473 place_windows (GtkEntry *entry,
2474 GtkAllocation *widget_alloc)
2476 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2477 GtkEntryIconPosition left_icon_pos;
2478 GtkEntryIconPosition right_icon_pos;
2479 GtkAllocation left_icon_alloc;
2480 GtkAllocation right_icon_alloc;
2481 GtkAllocation text_area_alloc;
2482 EntryIconInfo *icon_info = NULL;
2484 get_text_area_size (entry, &text_area_alloc);
2485 get_icon_allocation (entry, TRUE, widget_alloc, &text_area_alloc,
2486 &left_icon_alloc, &left_icon_pos);
2487 get_icon_allocation (entry, FALSE, widget_alloc, &text_area_alloc,
2488 &right_icon_alloc, &right_icon_pos);
2490 if (left_icon_alloc.width > 0)
2492 text_area_alloc.x = left_icon_alloc.x + left_icon_alloc.width;
2493 text_area_alloc.width -= left_icon_alloc.width;
2496 if (right_icon_alloc.width > 0)
2497 text_area_alloc.width -= right_icon_alloc.width;
2499 if ((icon_info = priv->icons[left_icon_pos]) != NULL)
2500 gdk_window_move_resize (icon_info->window,
2501 left_icon_alloc.x, left_icon_alloc.y,
2502 left_icon_alloc.width, left_icon_alloc.height);
2504 if ((icon_info = priv->icons[right_icon_pos]) != NULL)
2505 gdk_window_move_resize (icon_info->window,
2506 right_icon_alloc.x, right_icon_alloc.y,
2507 right_icon_alloc.width, right_icon_alloc.height);
2509 gdk_window_move_resize (GTK_ENTRY (entry)->text_area,
2510 text_area_alloc.x, text_area_alloc.y,
2511 text_area_alloc.width, text_area_alloc.height);
2513 gtk_entry_adjust_scroll (GTK_ENTRY (entry));
2517 get_text_area_size (GtkEntry *entry,
2518 GtkAllocation *alloc)
2520 gtk_entry_get_text_area_size (entry,
2528 gtk_entry_get_text_area_size (GtkEntry *entry,
2535 gint xborder, yborder;
2536 GtkRequisition requisition;
2537 GtkWidget *widget = GTK_WIDGET (entry);
2538 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2540 gtk_widget_get_child_requisition (widget, &requisition);
2541 _gtk_entry_get_borders (entry, &xborder, &yborder);
2543 if (GTK_WIDGET_REALIZED (widget))
2544 gdk_drawable_get_size (widget->window, NULL, &frame_height);
2546 frame_height = requisition.height;
2548 if (GTK_WIDGET_HAS_FOCUS (widget) && !priv->interior_focus)
2549 frame_height -= 2 * priv->focus_width;
2555 *y = frame_height / 2 - (requisition.height - yborder * 2) / 2;
2558 *width = GTK_WIDGET (entry)->allocation.width - xborder * 2;
2561 *height = requisition.height - yborder * 2;
2565 get_widget_window_size (GtkEntry *entry,
2571 GtkRequisition requisition;
2572 GtkWidget *widget = GTK_WIDGET (entry);
2574 gtk_widget_get_child_requisition (widget, &requisition);
2577 *x = widget->allocation.x;
2581 if (entry->is_cell_renderer)
2582 *y = widget->allocation.y;
2584 *y = widget->allocation.y + (widget->allocation.height - requisition.height) / 2;
2588 *width = widget->allocation.width;
2592 if (entry->is_cell_renderer)
2593 *height = widget->allocation.height;
2595 *height = requisition.height;
2600 _gtk_entry_effective_inner_border (GtkEntry *entry,
2603 GtkBorder *tmp_border;
2605 tmp_border = g_object_get_qdata (G_OBJECT (entry), quark_inner_border);
2609 *border = *tmp_border;
2613 gtk_widget_style_get (GTK_WIDGET (entry), "inner-border", &tmp_border, NULL);
2617 *border = *tmp_border;
2618 gtk_border_free (tmp_border);
2622 *border = default_inner_border;
2626 gtk_entry_size_allocate (GtkWidget *widget,
2627 GtkAllocation *allocation)
2629 GtkEntry *entry = GTK_ENTRY (widget);
2631 widget->allocation = *allocation;
2633 if (GTK_WIDGET_REALIZED (widget))
2635 /* We call gtk_widget_get_child_requisition, since we want (for
2636 * backwards compatibility reasons) the realization here to
2637 * be affected by the usize of the entry, if set
2639 gint x, y, width, height;
2640 GtkEntryCompletion* completion;
2642 get_widget_window_size (entry, &x, &y, &width, &height);
2644 gdk_window_move_resize (widget->window,
2645 x, y, width, height);
2647 gtk_entry_get_text_area_size (entry, &x, &y, &width, &height);
2649 gdk_window_move_resize (entry->text_area,
2650 x, y, width, height);
2652 gtk_entry_recompute (entry);
2654 completion = gtk_entry_get_completion (entry);
2655 if (completion && GTK_WIDGET_MAPPED (completion->priv->popup_window))
2656 _gtk_entry_completion_resize_popup (completion);
2658 place_windows (entry, allocation);
2662 /* Kudos to the gnome-panel guys. */
2664 colorshift_pixbuf (GdkPixbuf *dest,
2669 gint width, height, has_alpha, src_rowstride, dest_rowstride;
2670 guchar *target_pixels;
2671 guchar *original_pixels;
2677 has_alpha = gdk_pixbuf_get_has_alpha (src);
2678 width = gdk_pixbuf_get_width (src);
2679 height = gdk_pixbuf_get_height (src);
2680 src_rowstride = gdk_pixbuf_get_rowstride (src);
2681 dest_rowstride = gdk_pixbuf_get_rowstride (dest);
2682 original_pixels = gdk_pixbuf_get_pixels (src);
2683 target_pixels = gdk_pixbuf_get_pixels (dest);
2685 for (i = 0; i < height; i++)
2687 pix_dest = target_pixels + i * dest_rowstride;
2688 pix_src = original_pixels + i * src_rowstride;
2690 for (j = 0; j < width; j++)
2697 *(pix_dest++) = CLAMP (val, 0, 255);
2700 *(pix_dest++) = CLAMP (val, 0, 255);
2703 *(pix_dest++) = CLAMP (val, 0, 255);
2706 *(pix_dest++) = *(pix_src++);
2712 should_prelight (GtkEntry *entry,
2713 GtkEntryIconPosition icon_pos)
2715 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2716 EntryIconInfo *icon_info = NULL;
2719 if (!(icon_info = priv->icons[icon_pos]))
2722 if (icon_info->nonactivatable && icon_info->target_list == NULL)
2725 if (icon_info->pressed)
2728 gtk_widget_style_get (GTK_WIDGET (entry),
2729 "prelight", &prelight,
2736 draw_icon (GtkWidget *widget,
2737 GtkEntryIconPosition icon_pos)
2739 GtkEntry *entry = GTK_ENTRY (widget);
2740 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2741 EntryIconInfo *icon_info = NULL;
2743 gint x, y, width, height;
2745 if (!(icon_info = priv->icons[icon_pos]))
2748 gtk_entry_ensure_pixbuf (entry, icon_pos);
2750 if (icon_info->pixbuf == NULL)
2753 gdk_drawable_get_size (icon_info->window, &width, &height);
2755 /* size_allocate hasn't been called yet. These are the default values.
2757 if (width == 1 || height == 1)
2760 pixbuf = icon_info->pixbuf;
2761 g_object_ref (pixbuf);
2763 if (gdk_pixbuf_get_height (pixbuf) > height)
2765 GdkPixbuf *temp_pixbuf;
2768 scale = height - 2 * priv->icon_margin;
2769 temp_pixbuf = gdk_pixbuf_scale_simple (pixbuf, scale, scale,
2770 GDK_INTERP_BILINEAR);
2771 g_object_unref (pixbuf);
2772 pixbuf = temp_pixbuf;
2775 x = (width - gdk_pixbuf_get_width (pixbuf)) / 2;
2776 y = (height - gdk_pixbuf_get_height (pixbuf)) / 2;
2778 if (!GTK_WIDGET_IS_SENSITIVE (widget) ||
2779 icon_info->insensitive)
2781 GdkPixbuf *temp_pixbuf;
2783 temp_pixbuf = gdk_pixbuf_copy (pixbuf);
2784 gdk_pixbuf_saturate_and_pixelate (pixbuf,
2788 g_object_unref (pixbuf);
2789 pixbuf = temp_pixbuf;
2791 else if (icon_info->prelight)
2793 GdkPixbuf *temp_pixbuf;
2795 temp_pixbuf = gdk_pixbuf_copy (pixbuf);
2796 colorshift_pixbuf (temp_pixbuf, pixbuf, 30);
2797 g_object_unref (pixbuf);
2798 pixbuf = temp_pixbuf;
2801 gdk_draw_pixbuf (icon_info->window, widget->style->black_gc, pixbuf,
2803 GDK_RGB_DITHER_NORMAL, 0, 0);
2805 g_object_unref (pixbuf);
2810 gtk_entry_draw_frame (GtkWidget *widget,
2813 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2814 gint x = 0, y = 0, width, height;
2815 gboolean state_hint;
2818 gdk_drawable_get_size (widget->window, &width, &height);
2820 /* Fix a problem with some themes which assume that entry->text_area's
2821 * width equals widget->window's width */
2822 if (GTK_IS_SPIN_BUTTON (widget))
2824 gint xborder, yborder;
2826 gtk_entry_get_text_area_size (GTK_ENTRY (widget), &x, NULL, &width, NULL);
2827 _gtk_entry_get_borders (GTK_ENTRY (widget), &xborder, &yborder);
2830 width += xborder * 2;
2833 if (GTK_WIDGET_HAS_FOCUS (widget) && !priv->interior_focus)
2835 x += priv->focus_width;
2836 y += priv->focus_width;
2837 width -= 2 * priv->focus_width;
2838 height -= 2 * priv->focus_width;
2841 gtk_widget_style_get (widget, "state-hint", &state_hint, NULL);
2843 state = GTK_WIDGET_HAS_FOCUS (widget) ?
2844 GTK_STATE_ACTIVE : GTK_WIDGET_STATE (widget);
2846 state = GTK_STATE_NORMAL;
2848 gtk_paint_shadow (widget->style, widget->window,
2849 state, priv->shadow_type,
2850 area, widget, "entry", x, y, width, height);
2852 if (GTK_WIDGET_HAS_FOCUS (widget) && !priv->interior_focus)
2854 x -= priv->focus_width;
2855 y -= priv->focus_width;
2856 width += 2 * priv->focus_width;
2857 height += 2 * priv->focus_width;
2859 gtk_paint_focus (widget->style, widget->window, GTK_WIDGET_STATE (widget),
2860 area, widget, "entry",
2861 0, 0, width, height);
2866 gtk_entry_draw_progress (GtkWidget *widget,
2867 GdkEventExpose *event)
2869 GtkEntryPrivate *private = GTK_ENTRY_GET_PRIVATE (widget);
2870 GtkEntry *entry = GTK_ENTRY (widget);
2872 if (private->progress_pulse_mode)
2874 gdouble value = private->progress_pulse_current;
2875 gint area_width, area_height;
2877 gdk_drawable_get_size (entry->text_area, &area_width, &area_height);
2879 gtk_paint_box (widget->style, entry->text_area,
2880 GTK_STATE_SELECTED, GTK_SHADOW_OUT,
2881 &event->area, widget, "entry-progress",
2882 value * area_width, 0,
2883 private->progress_pulse_fraction * area_width, area_height);
2885 else if (private->progress_fraction > 0)
2887 gdouble value = private->progress_fraction;
2888 gint area_width, area_height;
2890 gdk_drawable_get_size (entry->text_area, &area_width, &area_height);
2892 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
2894 gtk_paint_box (widget->style, entry->text_area,
2895 GTK_STATE_SELECTED, GTK_SHADOW_OUT,
2896 &event->area, widget, "entry-progress",
2897 area_width - value * area_width, 0,
2898 value * area_width, area_height);
2902 gtk_paint_box (widget->style, entry->text_area,
2903 GTK_STATE_SELECTED, GTK_SHADOW_OUT,
2904 &event->area, widget, "entry-progress",
2906 value * area_width, area_height);
2912 gtk_entry_expose (GtkWidget *widget,
2913 GdkEventExpose *event)
2915 GtkEntry *entry = GTK_ENTRY (widget);
2916 gboolean state_hint;
2918 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2920 if (widget->window == event->window)
2922 gtk_entry_draw_frame (widget, &event->area);
2924 else if (entry->text_area == event->window)
2926 gint area_width, area_height;
2927 gdk_drawable_get_size (entry->text_area, &area_width, &area_height);
2929 gtk_widget_style_get (widget, "state-hint", &state_hint, NULL);
2931 state = GTK_WIDGET_HAS_FOCUS (widget) ?
2932 GTK_STATE_ACTIVE : GTK_WIDGET_STATE (widget);
2934 state = GTK_WIDGET_STATE(widget);
2936 gtk_paint_flat_box (widget->style, entry->text_area,
2937 state, GTK_SHADOW_NONE,
2938 &event->area, widget, "entry_bg",
2939 0, 0, area_width, area_height);
2941 gtk_entry_draw_progress (widget, event);
2943 if (entry->dnd_position != -1)
2944 gtk_entry_draw_cursor (GTK_ENTRY (widget), CURSOR_DND);
2946 gtk_entry_draw_text (GTK_ENTRY (widget));
2948 if ((entry->visible || entry->invisible_char != 0) &&
2949 GTK_WIDGET_HAS_FOCUS (widget) &&
2950 entry->selection_bound == entry->current_pos && entry->cursor_visible)
2951 gtk_entry_draw_cursor (GTK_ENTRY (widget), CURSOR_STANDARD);
2955 gboolean found = FALSE;
2958 for (i = 0; i < MAX_ICONS && !found; i++)
2960 EntryIconInfo *icon_info = NULL;
2962 if ((icon_info = priv->icons[i]) != NULL)
2964 if (event->window == icon_info->window)
2967 GtkAllocation text_area_alloc;
2969 get_text_area_size (entry, &text_area_alloc);
2970 gdk_drawable_get_size (icon_info->window, &width, NULL);
2972 gtk_paint_flat_box (widget->style, icon_info->window,
2973 GTK_WIDGET_STATE (widget), GTK_SHADOW_NONE,
2974 NULL, widget, "entry_bg",
2975 0, 0, width, text_area_alloc.height);
2977 draw_icon (widget, i);
2989 gtk_entry_enter_notify (GtkWidget *widget,
2990 GdkEventCrossing *event)
2992 GtkEntry *entry = GTK_ENTRY (widget);
2993 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2994 EntryIconInfo *icon_info = NULL;
2997 for (i = 0; i < MAX_ICONS; i++)
2999 if ((icon_info = priv->icons[i]) != NULL)
3001 if (event->window == icon_info->window)
3003 if (should_prelight (entry, i))
3005 icon_info->prelight = TRUE;
3006 gtk_widget_queue_draw (widget);
3017 gtk_entry_leave_notify (GtkWidget *widget,
3018 GdkEventCrossing *event)
3020 GtkEntry *entry = GTK_ENTRY (widget);
3021 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3022 EntryIconInfo *icon_info = NULL;
3025 for (i = 0; i < MAX_ICONS; i++)
3027 if ((icon_info = priv->icons[i]) != NULL)
3029 if (event->window == icon_info->window)
3031 if (should_prelight (entry, i))
3033 icon_info->prelight = FALSE;
3034 gtk_widget_queue_draw (widget);
3045 gtk_entry_get_pixel_ranges (GtkEntry *entry,
3049 gint start_char, end_char;
3051 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start_char, &end_char))
3053 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
3054 PangoLayoutLine *line = pango_layout_get_lines_readonly (layout)->data;
3055 const char *text = pango_layout_get_text (layout);
3056 gint start_index = g_utf8_offset_to_pointer (text, start_char) - text;
3057 gint end_index = g_utf8_offset_to_pointer (text, end_char) - text;
3058 gint real_n_ranges, i;
3060 pango_layout_line_get_x_ranges (line, start_index, end_index, ranges, &real_n_ranges);
3066 for (i = 0; i < real_n_ranges; ++i)
3068 r[2 * i + 1] = (r[2 * i + 1] - r[2 * i]) / PANGO_SCALE;
3069 r[2 * i] = r[2 * i] / PANGO_SCALE;
3074 *n_ranges = real_n_ranges;
3086 in_selection (GtkEntry *entry,
3091 gint retval = FALSE;
3093 gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
3095 for (i = 0; i < n_ranges; ++i)
3097 if (x >= ranges[2 * i] && x < ranges[2 * i] + ranges[2 * i + 1])
3109 gtk_entry_button_press (GtkWidget *widget,
3110 GdkEventButton *event)
3112 GtkEntry *entry = GTK_ENTRY (widget);
3113 GtkEditable *editable = GTK_EDITABLE (widget);
3114 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3115 EntryIconInfo *icon_info = NULL;
3117 gint sel_start, sel_end;
3120 for (i = 0; i < MAX_ICONS; i++)
3122 icon_info = priv->icons[i];
3124 if (!icon_info || icon_info->insensitive)
3127 if (event->window == icon_info->window)
3129 if (should_prelight (entry, i))
3131 icon_info->prelight = FALSE;
3132 gtk_widget_queue_draw (widget);
3135 priv->start_x = event->x;
3136 priv->start_y = event->y;
3137 icon_info->pressed = TRUE;
3139 if (!icon_info->nonactivatable)
3140 g_signal_emit (entry, signals[ICON_PRESSED], 0, i, event);
3146 if (event->window != entry->text_area ||
3147 (entry->button && event->button != entry->button))
3150 gtk_entry_reset_blink_time (entry);
3152 entry->button = event->button;
3154 if (!GTK_WIDGET_HAS_FOCUS (widget))
3156 entry->in_click = TRUE;
3157 gtk_widget_grab_focus (widget);
3158 entry->in_click = FALSE;
3161 tmp_pos = gtk_entry_find_position (entry, event->x + entry->scroll_offset);
3163 if (event->button == 1)
3165 gboolean have_selection = gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end);
3167 entry->select_words = FALSE;
3168 entry->select_lines = FALSE;
3170 if (event->state & GDK_SHIFT_MASK)
3172 _gtk_entry_reset_im_context (entry);
3174 if (!have_selection) /* select from the current position to the clicked position */
3175 sel_start = sel_end = entry->current_pos;
3177 if (tmp_pos > sel_start && tmp_pos < sel_end)
3179 /* Truncate current selection, but keep it as big as possible */
3180 if (tmp_pos - sel_start > sel_end - tmp_pos)
3181 gtk_entry_set_positions (entry, sel_start, tmp_pos);
3183 gtk_entry_set_positions (entry, tmp_pos, sel_end);
3187 gboolean extend_to_left;
3190 /* Figure out what click selects and extend current selection */
3191 switch (event->type)
3193 case GDK_BUTTON_PRESS:
3194 gtk_entry_set_positions (entry, tmp_pos, tmp_pos);
3197 case GDK_2BUTTON_PRESS:
3198 entry->select_words = TRUE;
3199 gtk_entry_select_word (entry);
3202 case GDK_3BUTTON_PRESS:
3203 entry->select_lines = TRUE;
3204 gtk_entry_select_line (entry);
3211 start = MIN (entry->current_pos, entry->selection_bound);
3212 start = MIN (sel_start, start);
3214 end = MAX (entry->current_pos, entry->selection_bound);
3215 end = MAX (sel_end, end);
3217 if (tmp_pos == sel_start || tmp_pos == sel_end)
3218 extend_to_left = (tmp_pos == start);
3220 extend_to_left = (end == sel_end);
3223 gtk_entry_set_positions (entry, start, end);
3225 gtk_entry_set_positions (entry, end, start);
3228 else /* no shift key */
3229 switch (event->type)
3231 case GDK_BUTTON_PRESS:
3232 if (in_selection (entry, event->x + entry->scroll_offset))
3234 /* Click inside the selection - we'll either start a drag, or
3235 * clear the selection
3237 entry->in_drag = TRUE;
3238 entry->drag_start_x = event->x + entry->scroll_offset;
3239 entry->drag_start_y = event->y;
3242 gtk_editable_set_position (editable, tmp_pos);
3245 case GDK_2BUTTON_PRESS:
3246 /* We ALWAYS receive a GDK_BUTTON_PRESS immediately before
3247 * receiving a GDK_2BUTTON_PRESS so we need to reset
3248 * entry->in_drag which may have been set above
3250 entry->in_drag = FALSE;
3251 entry->select_words = TRUE;
3252 gtk_entry_select_word (entry);
3255 case GDK_3BUTTON_PRESS:
3256 /* We ALWAYS receive a GDK_BUTTON_PRESS immediately before
3257 * receiving a GDK_3BUTTON_PRESS so we need to reset
3258 * entry->in_drag which may have been set above
3260 entry->in_drag = FALSE;
3261 entry->select_lines = TRUE;
3262 gtk_entry_select_line (entry);
3271 else if (event->button == 2 && event->type == GDK_BUTTON_PRESS)
3273 if (entry->editable)
3275 priv->insert_pos = tmp_pos;
3276 gtk_entry_paste (entry, GDK_SELECTION_PRIMARY);
3281 gtk_widget_error_bell (widget);
3284 else if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
3286 gtk_entry_do_popup (entry, event);
3287 entry->button = 0; /* Don't wait for release, since the menu will gtk_grab_add */
3296 gtk_entry_button_release (GtkWidget *widget,
3297 GdkEventButton *event)
3299 GtkEntry *entry = GTK_ENTRY (widget);
3300 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
3301 EntryIconInfo *icon_info = NULL;
3304 for (i = 0; i < MAX_ICONS; i++)
3306 icon_info = priv->icons[i];
3308 if (!icon_info || icon_info->insensitive)
3311 if (event->window == icon_info->window)
3315 gdk_drawable_get_size (icon_info->window, &width, &height);
3317 icon_info->pressed = FALSE;
3319 if (should_prelight (entry, i) &&
3320 event->x >= 0 && event->y >= 0 &&
3321 event->x < width && event->y < height)
3323 icon_info->prelight = TRUE;
3324 gtk_widget_queue_draw (widget);
3327 if (!icon_info->nonactivatable)
3328 g_signal_emit (entry, signals[ICON_RELEASED], 0, i, event);
3334 if (event->window != entry->text_area || entry->button != event->button)
3339 gint tmp_pos = gtk_entry_find_position (entry, entry->drag_start_x);
3341 gtk_editable_set_position (GTK_EDITABLE (entry), tmp_pos);
3348 gtk_entry_update_primary_selection (entry);
3354 _gtk_entry_get_selected_text (GtkEntry *entry)
3356 GtkEditable *editable = GTK_EDITABLE (entry);
3357 gint start_text, end_text;
3360 if (gtk_editable_get_selection_bounds (editable, &start_text, &end_text))
3361 text = gtk_editable_get_chars (editable, start_text, end_text);
3367 gtk_entry_motion_notify (GtkWidget *widget,
3368 GdkEventMotion *event)
3370 GtkEntry *entry = GTK_ENTRY (widget);
3371 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3372 EntryIconInfo *icon_info = NULL;
3373 GdkDragContext *context;
3377 for (i = 0; i < MAX_ICONS; i++)
3379 icon_info = priv->icons[i];
3381 if (!icon_info || icon_info->insensitive)
3384 if (event->window == icon_info->window)
3386 if (icon_info->pressed &&
3387 icon_info->target_list != NULL &&
3388 gtk_drag_check_threshold (widget,
3394 icon_info->in_drag = TRUE;
3395 icon_info->pressed = FALSE;
3396 context = gtk_drag_begin (widget,
3397 icon_info->target_list,
3407 if (entry->mouse_cursor_obscured)
3411 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
3412 gdk_window_set_cursor (entry->text_area, cursor);
3413 gdk_cursor_unref (cursor);
3414 entry->mouse_cursor_obscured = FALSE;
3417 if (event->window != entry->text_area || entry->button != 1)
3420 if (entry->select_lines)
3423 gdk_event_request_motions (event);
3427 if (entry->visible &&
3428 gtk_drag_check_threshold (widget,
3429 entry->drag_start_x, entry->drag_start_y,
3430 event->x + entry->scroll_offset, event->y))
3432 GdkDragContext *context;
3433 GtkTargetList *target_list = gtk_target_list_new (NULL, 0);
3434 guint actions = entry->editable ? GDK_ACTION_COPY | GDK_ACTION_MOVE : GDK_ACTION_COPY;
3436 GdkPixmap *pixmap = NULL;
3438 gtk_target_list_add_text_targets (target_list, 0);
3440 text = _gtk_entry_get_selected_text (entry);
3441 pixmap = _gtk_text_util_create_drag_icon (widget, text, -1);
3443 context = gtk_drag_begin (widget, target_list, actions,
3444 entry->button, (GdkEvent *)event);
3447 gtk_drag_set_icon_pixmap (context,
3448 gdk_drawable_get_colormap (pixmap),
3453 gtk_drag_set_icon_default (context);
3456 g_object_unref (pixmap);
3459 entry->in_drag = FALSE;
3462 gtk_target_list_unref (target_list);
3468 gdk_drawable_get_size (entry->text_area, NULL, &height);
3472 else if (event->y >= height)
3473 tmp_pos = entry->text_length;
3475 tmp_pos = gtk_entry_find_position (entry, event->x + entry->scroll_offset);
3477 if (entry->select_words)
3480 gint old_min, old_max;
3483 min = gtk_entry_move_backward_word (entry, tmp_pos, TRUE);
3484 max = gtk_entry_move_forward_word (entry, tmp_pos, TRUE);
3486 pos = entry->current_pos;
3487 bound = entry->selection_bound;
3489 old_min = MIN(entry->current_pos, entry->selection_bound);
3490 old_max = MAX(entry->current_pos, entry->selection_bound);
3497 else if (old_max < max)
3502 else if (pos == old_min)
3504 if (entry->current_pos != min)
3509 if (entry->current_pos != max)
3513 gtk_entry_set_positions (entry, pos, bound);
3516 gtk_entry_set_positions (entry, tmp_pos, -1);
3523 set_invisible_cursor (GdkWindow *window)
3525 GdkBitmap *empty_bitmap;
3528 char invisible_cursor_bits[] = { 0x0 };
3530 useless.red = useless.green = useless.blue = 0;
3533 empty_bitmap = gdk_bitmap_create_from_data (window,
3534 invisible_cursor_bits,
3537 cursor = gdk_cursor_new_from_pixmap (empty_bitmap,
3542 gdk_window_set_cursor (window, cursor);
3544 gdk_cursor_unref (cursor);
3546 g_object_unref (empty_bitmap);
3550 gtk_entry_obscure_mouse_cursor (GtkEntry *entry)
3552 if (entry->mouse_cursor_obscured)
3555 set_invisible_cursor (entry->text_area);
3557 entry->mouse_cursor_obscured = TRUE;
3561 gtk_entry_key_press (GtkWidget *widget,
3564 GtkEntry *entry = GTK_ENTRY (widget);
3566 gtk_entry_reset_blink_time (entry);
3567 gtk_entry_pend_cursor_blink (entry);
3569 if (entry->editable)
3571 if (gtk_im_context_filter_keypress (entry->im_context, event))
3573 gtk_entry_obscure_mouse_cursor (entry);
3574 entry->need_im_reset = TRUE;
3579 if (event->keyval == GDK_Return ||
3580 event->keyval == GDK_KP_Enter ||
3581 event->keyval == GDK_ISO_Enter ||
3582 event->keyval == GDK_Escape)
3584 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
3586 if (completion && completion->priv->completion_timeout)
3588 g_source_remove (completion->priv->completion_timeout);
3589 completion->priv->completion_timeout = 0;
3592 _gtk_entry_reset_im_context (entry);
3595 if (GTK_WIDGET_CLASS (gtk_entry_parent_class)->key_press_event (widget, event))
3596 /* Activate key bindings
3600 if (!entry->editable && event->length)
3601 gtk_widget_error_bell (widget);
3607 gtk_entry_key_release (GtkWidget *widget,
3610 GtkEntry *entry = GTK_ENTRY (widget);
3612 if (entry->editable)
3614 if (gtk_im_context_filter_keypress (entry->im_context, event))
3616 entry->need_im_reset = TRUE;
3621 return GTK_WIDGET_CLASS (gtk_entry_parent_class)->key_release_event (widget, event);
3625 gtk_entry_focus_in (GtkWidget *widget,
3626 GdkEventFocus *event)
3628 GtkEntry *entry = GTK_ENTRY (widget);
3631 gtk_widget_queue_draw (widget);
3633 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (widget));
3635 if (entry->editable)
3637 entry->need_im_reset = TRUE;
3638 gtk_im_context_focus_in (entry->im_context);
3639 keymap_state_changed (keymap, entry);
3640 g_signal_connect (keymap, "state-changed",
3641 G_CALLBACK (keymap_state_changed), entry);
3644 g_signal_connect (keymap, "direction-changed",
3645 G_CALLBACK (keymap_direction_changed), entry);
3647 gtk_entry_reset_blink_time (entry);
3648 gtk_entry_check_cursor_blink (entry);
3654 gtk_entry_focus_out (GtkWidget *widget,
3655 GdkEventFocus *event)
3657 GtkEntry *entry = GTK_ENTRY (widget);
3658 GtkEntryCompletion *completion;
3661 gtk_widget_queue_draw (widget);
3663 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (widget));
3665 if (entry->editable)
3667 entry->need_im_reset = TRUE;
3668 gtk_im_context_focus_out (entry->im_context);
3669 remove_capslock_feedback (entry);
3672 gtk_entry_check_cursor_blink (entry);
3674 g_signal_handlers_disconnect_by_func (keymap, keymap_state_changed, entry);
3675 g_signal_handlers_disconnect_by_func (keymap, keymap_direction_changed, entry);
3677 completion = gtk_entry_get_completion (entry);
3679 _gtk_entry_completion_popdown (completion);
3685 gtk_entry_grab_focus (GtkWidget *widget)
3687 GtkEntry *entry = GTK_ENTRY (widget);
3688 gboolean select_on_focus;
3690 GTK_WIDGET_CLASS (gtk_entry_parent_class)->grab_focus (widget);
3692 if (entry->editable && !entry->in_click)
3694 g_object_get (gtk_widget_get_settings (widget),
3695 "gtk-entry-select-on-focus",
3699 if (select_on_focus)
3700 gtk_editable_select_region (GTK_EDITABLE (widget), 0, -1);
3705 gtk_entry_direction_changed (GtkWidget *widget,
3706 GtkTextDirection previous_dir)
3708 GtkEntry *entry = GTK_ENTRY (widget);
3710 gtk_entry_recompute (entry);
3712 GTK_WIDGET_CLASS (gtk_entry_parent_class)->direction_changed (widget, previous_dir);
3716 gtk_entry_state_changed (GtkWidget *widget,
3717 GtkStateType previous_state)
3719 GtkEntry *entry = GTK_ENTRY (widget);
3722 if (GTK_WIDGET_REALIZED (widget))
3724 gdk_window_set_background (widget->window, &widget->style->base[GTK_WIDGET_STATE (widget)]);
3725 gdk_window_set_background (entry->text_area, &widget->style->base[GTK_WIDGET_STATE (widget)]);
3727 if (GTK_WIDGET_IS_SENSITIVE (widget))
3728 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
3732 gdk_window_set_cursor (entry->text_area, cursor);
3735 gdk_cursor_unref (cursor);
3737 entry->mouse_cursor_obscured = FALSE;
3739 update_cursors (widget);
3742 if (!GTK_WIDGET_IS_SENSITIVE (widget))
3744 /* Clear any selection */
3745 gtk_editable_select_region (GTK_EDITABLE (entry), entry->current_pos, entry->current_pos);
3748 gtk_widget_queue_draw (widget);
3752 gtk_entry_screen_changed (GtkWidget *widget,
3753 GdkScreen *old_screen)
3755 gtk_entry_recompute (GTK_ENTRY (widget));
3758 /* GtkEditable method implementations
3761 gtk_entry_insert_text (GtkEditable *editable,
3762 const gchar *new_text,
3763 gint new_text_length,
3766 GtkEntry *entry = GTK_ENTRY (editable);
3770 if (*position < 0 || *position > entry->text_length)
3771 *position = entry->text_length;
3773 g_object_ref (editable);
3775 if (new_text_length <= 63)
3778 text = g_new (gchar, new_text_length + 1);
3780 text[new_text_length] = '\0';
3781 strncpy (text, new_text, new_text_length);
3783 g_signal_emit_by_name (editable, "insert-text", text, new_text_length, position);
3785 if (!entry->visible)
3786 trash_area (text, new_text_length);
3788 if (new_text_length > 63)
3791 g_object_unref (editable);
3795 gtk_entry_delete_text (GtkEditable *editable,
3799 GtkEntry *entry = GTK_ENTRY (editable);
3801 if (end_pos < 0 || end_pos > entry->text_length)
3802 end_pos = entry->text_length;
3805 if (start_pos > end_pos)
3806 start_pos = end_pos;
3808 g_object_ref (editable);
3810 g_signal_emit_by_name (editable, "delete-text", start_pos, end_pos);
3812 g_object_unref (editable);
3816 gtk_entry_get_chars (GtkEditable *editable,
3820 GtkEntry *entry = GTK_ENTRY (editable);
3821 gint start_index, end_index;
3824 end_pos = entry->text_length;
3826 start_pos = MIN (entry->text_length, start_pos);
3827 end_pos = MIN (entry->text_length, end_pos);
3829 start_index = g_utf8_offset_to_pointer (entry->text, start_pos) - entry->text;
3830 end_index = g_utf8_offset_to_pointer (entry->text, end_pos) - entry->text;
3832 return g_strndup (entry->text + start_index, end_index - start_index);
3836 gtk_entry_real_set_position (GtkEditable *editable,
3839 GtkEntry *entry = GTK_ENTRY (editable);
3841 if (position < 0 || position > entry->text_length)
3842 position = entry->text_length;
3844 if (position != entry->current_pos ||
3845 position != entry->selection_bound)
3847 _gtk_entry_reset_im_context (entry);
3848 gtk_entry_set_positions (entry, position, position);
3853 gtk_entry_get_position (GtkEditable *editable)
3855 return GTK_ENTRY (editable)->current_pos;
3859 gtk_entry_set_selection_bounds (GtkEditable *editable,
3863 GtkEntry *entry = GTK_ENTRY (editable);
3866 start = entry->text_length;
3868 end = entry->text_length;
3870 _gtk_entry_reset_im_context (entry);
3872 gtk_entry_set_positions (entry,
3873 MIN (end, entry->text_length),
3874 MIN (start, entry->text_length));
3876 gtk_entry_update_primary_selection (entry);
3880 gtk_entry_get_selection_bounds (GtkEditable *editable,
3884 GtkEntry *entry = GTK_ENTRY (editable);
3886 *start = entry->selection_bound;
3887 *end = entry->current_pos;
3889 return (entry->selection_bound != entry->current_pos);
3893 icon_theme_changed (GtkEntry *entry)
3895 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3896 EntryIconInfo *icon_info = NULL;
3899 for (i = 0; i < MAX_ICONS; i++)
3901 if ((icon_info = priv->icons[i]) != NULL)
3903 if (icon_info->storage_type == GTK_IMAGE_ICON_NAME)
3904 gtk_entry_set_icon_from_icon_name (entry, i, icon_info->icon_name);
3905 else if (icon_info->storage_type == GTK_IMAGE_STOCK)
3906 gtk_entry_set_icon_from_stock (entry, i, icon_info->stock_id);
3907 else if (icon_info->storage_type == GTK_IMAGE_GICON)
3908 gtk_entry_set_icon_from_gicon (entry, i, icon_info->gicon);
3912 gtk_widget_queue_draw (GTK_WIDGET (entry));
3916 icon_margin_changed (GtkEntry *entry)
3918 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3921 _gtk_entry_effective_inner_border (GTK_ENTRY (entry), &border);
3923 priv->icon_margin = border.left;
3927 gtk_entry_style_set (GtkWidget *widget,
3928 GtkStyle *previous_style)
3930 GtkEntry *entry = GTK_ENTRY (widget);
3931 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3933 gboolean interior_focus;
3935 gtk_widget_style_get (widget,
3936 "focus-line-width", &focus_width,
3937 "interior-focus", &interior_focus,
3940 priv->focus_width = focus_width;
3941 priv->interior_focus = interior_focus;
3943 if (!priv->invisible_char_set)
3944 entry->invisible_char = find_invisible_char (GTK_WIDGET (entry));
3946 gtk_entry_recompute (entry);
3948 if (previous_style && GTK_WIDGET_REALIZED (widget))
3950 gdk_window_set_background (widget->window, &widget->style->base[GTK_WIDGET_STATE (widget)]);
3951 gdk_window_set_background (entry->text_area, &widget->style->base[GTK_WIDGET_STATE (widget)]);
3954 icon_theme_changed (entry);
3955 icon_margin_changed (entry);
3958 /* GtkCellEditable method implementations
3961 gtk_cell_editable_entry_activated (GtkEntry *entry, gpointer data)
3963 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
3964 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
3968 gtk_cell_editable_key_press_event (GtkEntry *entry,
3969 GdkEventKey *key_event,
3972 if (key_event->keyval == GDK_Escape)
3974 entry->editing_canceled = TRUE;
3975 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
3976 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
3981 /* override focus */
3982 if (key_event->keyval == GDK_Up || key_event->keyval == GDK_Down)
3984 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
3985 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
3994 gtk_entry_start_editing (GtkCellEditable *cell_editable,
3997 GTK_ENTRY (cell_editable)->is_cell_renderer = TRUE;
3999 g_signal_connect (cell_editable, "activate",
4000 G_CALLBACK (gtk_cell_editable_entry_activated), NULL);
4001 g_signal_connect (cell_editable, "key-press-event",
4002 G_CALLBACK (gtk_cell_editable_key_press_event), NULL);
4006 gtk_entry_password_hint_free (GtkEntryPasswordHint *password_hint)
4008 if (password_hint->password_hint_timeout_id)
4009 g_source_remove (password_hint->password_hint_timeout_id);
4011 g_slice_free (GtkEntryPasswordHint, password_hint);
4014 /* Default signal handlers
4017 gtk_entry_real_insert_text (GtkEditable *editable,
4018 const gchar *new_text,
4019 gint new_text_length,
4022 GtkEntry *entry = GTK_ENTRY (editable);
4026 if (new_text_length < 0)
4027 new_text_length = strlen (new_text);
4029 n_chars = g_utf8_strlen (new_text, new_text_length);
4030 if (entry->text_max_length > 0 && n_chars + entry->text_length > entry->text_max_length)
4032 gtk_widget_error_bell (GTK_WIDGET (entry));
4033 n_chars = entry->text_max_length - entry->text_length;
4034 new_text_length = g_utf8_offset_to_pointer (new_text, n_chars) - new_text;
4037 if (new_text_length + entry->n_bytes + 1 > entry->text_size)
4039 gsize prev_size = entry->text_size;
4041 while (new_text_length + entry->n_bytes + 1 > entry->text_size)
4043 if (entry->text_size == 0)
4044 entry->text_size = MIN_SIZE;
4047 if (2 * (guint)entry->text_size < MAX_SIZE &&
4048 2 * (guint)entry->text_size > entry->text_size)
4049 entry->text_size *= 2;
4052 entry->text_size = MAX_SIZE;
4053 if (new_text_length > (gint)entry->text_size - (gint)entry->n_bytes - 1)
4055 new_text_length = (gint)entry->text_size - (gint)entry->n_bytes - 1;
4056 new_text_length = g_utf8_find_prev_char (new_text, new_text + new_text_length + 1) - new_text;
4057 n_chars = g_utf8_strlen (new_text, new_text_length);
4065 entry->text = g_realloc (entry->text, entry->text_size);
4068 /* Same thing, just slower and without leaving stuff in memory. */
4069 gchar *et_new = g_malloc (entry->text_size);
4070 memcpy (et_new, entry->text, MIN (prev_size, entry->text_size));
4071 trash_area (entry->text, prev_size);
4072 g_free (entry->text);
4073 entry->text = et_new;
4077 index = g_utf8_offset_to_pointer (entry->text, *position) - entry->text;
4079 g_memmove (entry->text + index + new_text_length, entry->text + index, entry->n_bytes - index);
4080 memcpy (entry->text + index, new_text, new_text_length);
4082 entry->n_bytes += new_text_length;
4083 entry->text_length += n_chars;
4085 /* NUL terminate for safety and convenience */
4086 entry->text[entry->n_bytes] = '\0';
4088 if (entry->current_pos > *position)
4089 entry->current_pos += n_chars;
4091 if (entry->selection_bound > *position)
4092 entry->selection_bound += n_chars;
4094 if (n_chars == 1 && !entry->visible && (new_text_length < PASSWORD_HINT_MAX))
4096 guint password_hint_timeout;
4098 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
4099 "gtk-entry-password-hint-timeout", &password_hint_timeout,
4102 if (password_hint_timeout > 0)
4104 GtkEntryPasswordHint *password_hint = g_object_get_qdata (G_OBJECT (entry),
4105 quark_password_hint);
4109 password_hint = g_slice_new0 (GtkEntryPasswordHint);
4110 g_object_set_qdata_full (G_OBJECT (entry), quark_password_hint,
4112 (GDestroyNotify) gtk_entry_password_hint_free);
4115 memset (&password_hint->password_hint, 0x0, PASSWORD_HINT_MAX);
4116 password_hint->password_hint_length = new_text_length;
4117 memcpy (&password_hint->password_hint, new_text, new_text_length);
4118 password_hint->password_hint_position = *position + n_chars;
4123 g_object_set_qdata (G_OBJECT (entry), quark_password_hint, NULL);
4126 *position += n_chars;
4128 gtk_entry_recompute (entry);
4130 emit_changed (entry);
4131 g_object_notify (G_OBJECT (editable), "text");
4132 g_object_notify (G_OBJECT (editable), "text-length");
4136 gtk_entry_real_delete_text (GtkEditable *editable,
4140 GtkEntry *entry = GTK_ENTRY (editable);
4144 if (end_pos < 0 || end_pos > entry->text_length)
4145 end_pos = entry->text_length;
4147 if (start_pos < end_pos)
4149 gint start_index = g_utf8_offset_to_pointer (entry->text, start_pos) - entry->text;
4150 gint end_index = g_utf8_offset_to_pointer (entry->text, end_pos) - entry->text;
4152 gint selection_bound;
4154 g_memmove (entry->text + start_index, entry->text + end_index, entry->n_bytes + 1 - end_index);
4155 entry->text_length -= (end_pos - start_pos);
4156 entry->n_bytes -= (end_index - start_index);
4158 /* In password-mode, make sure we don't leave anything sensitive after
4159 * the terminating zero. Note, that the terminating zero already trashed
4162 if (!entry->visible)
4163 trash_area (entry->text + entry->n_bytes + 1, end_index - start_index - 1);
4165 current_pos = entry->current_pos;
4166 if (current_pos > start_pos)
4167 current_pos -= MIN (current_pos, end_pos) - start_pos;
4169 selection_bound = entry->selection_bound;
4170 if (selection_bound > start_pos)
4171 selection_bound -= MIN (selection_bound, end_pos) - start_pos;
4173 gtk_entry_set_positions (entry, current_pos, selection_bound);
4175 /* We might have deleted the selection
4177 gtk_entry_update_primary_selection (entry);
4179 gtk_entry_recompute (entry);
4181 emit_changed (entry);
4182 g_object_notify (G_OBJECT (editable), "text");
4183 g_object_notify (G_OBJECT (editable), "text-length");
4187 /* Compute the X position for an offset that corresponds to the "more important
4188 * cursor position for that offset. We use this when trying to guess to which
4189 * end of the selection we should go to when the user hits the left or
4193 get_better_cursor_x (GtkEntry *entry,
4196 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
4197 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
4198 gboolean split_cursor;
4200 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
4201 const gchar *text = pango_layout_get_text (layout);
4202 gint index = g_utf8_offset_to_pointer (text, offset) - text;
4204 PangoRectangle strong_pos, weak_pos;
4206 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
4207 "gtk-split-cursor", &split_cursor,
4210 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
4213 return strong_pos.x / PANGO_SCALE;
4215 return (keymap_direction == entry->resolved_dir) ? strong_pos.x / PANGO_SCALE : weak_pos.x / PANGO_SCALE;
4219 gtk_entry_move_cursor (GtkEntry *entry,
4220 GtkMovementStep step,
4222 gboolean extend_selection)
4224 gint new_pos = entry->current_pos;
4226 _gtk_entry_reset_im_context (entry);
4228 if (entry->current_pos != entry->selection_bound && !extend_selection)
4230 /* If we have a current selection and aren't extending it, move to the
4231 * start/or end of the selection as appropriate
4235 case GTK_MOVEMENT_VISUAL_POSITIONS:
4237 gint current_x = get_better_cursor_x (entry, entry->current_pos);
4238 gint bound_x = get_better_cursor_x (entry, entry->selection_bound);
4241 new_pos = current_x < bound_x ? entry->current_pos : entry->selection_bound;
4243 new_pos = current_x > bound_x ? entry->current_pos : entry->selection_bound;
4246 case GTK_MOVEMENT_LOGICAL_POSITIONS:
4247 case GTK_MOVEMENT_WORDS:
4249 new_pos = MIN (entry->current_pos, entry->selection_bound);
4251 new_pos = MAX (entry->current_pos, entry->selection_bound);
4253 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
4254 case GTK_MOVEMENT_PARAGRAPH_ENDS:
4255 case GTK_MOVEMENT_BUFFER_ENDS:
4256 new_pos = count < 0 ? 0 : entry->text_length;
4258 case GTK_MOVEMENT_DISPLAY_LINES:
4259 case GTK_MOVEMENT_PARAGRAPHS:
4260 case GTK_MOVEMENT_PAGES:
4261 case GTK_MOVEMENT_HORIZONTAL_PAGES:
4269 case GTK_MOVEMENT_LOGICAL_POSITIONS:
4270 new_pos = gtk_entry_move_logically (entry, new_pos, count);
4272 case GTK_MOVEMENT_VISUAL_POSITIONS:
4273 new_pos = gtk_entry_move_visually (entry, new_pos, count);
4274 if (entry->current_pos == new_pos)
4276 if (!extend_selection)
4278 if (!gtk_widget_keynav_failed (GTK_WIDGET (entry),
4280 GTK_DIR_RIGHT : GTK_DIR_LEFT))
4282 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (entry));
4285 gtk_widget_child_focus (toplevel,
4287 GTK_DIR_RIGHT : GTK_DIR_LEFT);
4292 gtk_widget_error_bell (GTK_WIDGET (entry));
4296 case GTK_MOVEMENT_WORDS:
4299 new_pos = gtk_entry_move_forward_word (entry, new_pos, FALSE);
4304 new_pos = gtk_entry_move_backward_word (entry, new_pos, FALSE);
4307 if (entry->current_pos == new_pos)
4308 gtk_widget_error_bell (GTK_WIDGET (entry));
4310 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
4311 case GTK_MOVEMENT_PARAGRAPH_ENDS:
4312 case GTK_MOVEMENT_BUFFER_ENDS:
4313 new_pos = count < 0 ? 0 : entry->text_length;
4314 if (entry->current_pos == new_pos)
4315 gtk_widget_error_bell (GTK_WIDGET (entry));
4317 case GTK_MOVEMENT_DISPLAY_LINES:
4318 case GTK_MOVEMENT_PARAGRAPHS:
4319 case GTK_MOVEMENT_PAGES:
4320 case GTK_MOVEMENT_HORIZONTAL_PAGES:
4325 if (extend_selection)
4326 gtk_editable_select_region (GTK_EDITABLE (entry), entry->selection_bound, new_pos);
4328 gtk_editable_set_position (GTK_EDITABLE (entry), new_pos);
4330 gtk_entry_pend_cursor_blink (entry);
4334 gtk_entry_insert_at_cursor (GtkEntry *entry,
4337 GtkEditable *editable = GTK_EDITABLE (entry);
4338 gint pos = entry->current_pos;
4340 if (entry->editable)
4342 _gtk_entry_reset_im_context (entry);
4344 gtk_editable_insert_text (editable, str, -1, &pos);
4345 gtk_editable_set_position (editable, pos);
4350 gtk_entry_delete_from_cursor (GtkEntry *entry,
4354 GtkEditable *editable = GTK_EDITABLE (entry);
4355 gint start_pos = entry->current_pos;
4356 gint end_pos = entry->current_pos;
4357 gint old_n_bytes = entry->n_bytes;
4359 _gtk_entry_reset_im_context (entry);
4361 if (!entry->editable)
4363 gtk_widget_error_bell (GTK_WIDGET (entry));
4367 if (entry->selection_bound != entry->current_pos)
4369 gtk_editable_delete_selection (editable);
4375 case GTK_DELETE_CHARS:
4376 end_pos = gtk_entry_move_logically (entry, entry->current_pos, count);
4377 gtk_editable_delete_text (editable, MIN (start_pos, end_pos), MAX (start_pos, end_pos));
4379 case GTK_DELETE_WORDS:
4382 /* Move to end of current word, or if not on a word, end of previous word */
4383 end_pos = gtk_entry_move_backward_word (entry, end_pos, FALSE);
4384 end_pos = gtk_entry_move_forward_word (entry, end_pos, FALSE);
4388 /* Move to beginning of current word, or if not on a word, begining of next word */
4389 start_pos = gtk_entry_move_forward_word (entry, start_pos, FALSE);
4390 start_pos = gtk_entry_move_backward_word (entry, start_pos, FALSE);
4394 case GTK_DELETE_WORD_ENDS:
4397 start_pos = gtk_entry_move_backward_word (entry, start_pos, FALSE);
4402 end_pos = gtk_entry_move_forward_word (entry, end_pos, FALSE);
4405 gtk_editable_delete_text (editable, start_pos, end_pos);
4407 case GTK_DELETE_DISPLAY_LINE_ENDS:
4408 case GTK_DELETE_PARAGRAPH_ENDS:
4410 gtk_editable_delete_text (editable, 0, entry->current_pos);
4412 gtk_editable_delete_text (editable, entry->current_pos, -1);
4414 case GTK_DELETE_DISPLAY_LINES:
4415 case GTK_DELETE_PARAGRAPHS:
4416 gtk_editable_delete_text (editable, 0, -1);
4418 case GTK_DELETE_WHITESPACE:
4419 gtk_entry_delete_whitespace (entry);
4423 if (entry->n_bytes == old_n_bytes)
4424 gtk_widget_error_bell (GTK_WIDGET (entry));
4426 gtk_entry_pend_cursor_blink (entry);
4430 gtk_entry_backspace (GtkEntry *entry)
4432 GtkEditable *editable = GTK_EDITABLE (entry);
4435 _gtk_entry_reset_im_context (entry);
4437 if (!entry->editable || !entry->text)
4439 gtk_widget_error_bell (GTK_WIDGET (entry));
4443 if (entry->selection_bound != entry->current_pos)
4445 gtk_editable_delete_selection (editable);
4449 prev_pos = gtk_entry_move_logically (entry, entry->current_pos, -1);
4451 if (prev_pos < entry->current_pos)
4453 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
4454 PangoLogAttr *log_attrs;
4457 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
4459 if (entry->visible &&
4460 log_attrs[entry->current_pos].backspace_deletes_character)
4462 gchar *cluster_text;
4463 gchar *normalized_text;
4466 cluster_text = gtk_editable_get_chars (editable,
4468 entry->current_pos);
4469 normalized_text = g_utf8_normalize (cluster_text,
4470 strlen (cluster_text),
4472 len = g_utf8_strlen (normalized_text, -1);
4474 gtk_editable_delete_text (editable, prev_pos, entry->current_pos);
4477 gint pos = entry->current_pos;
4479 gtk_editable_insert_text (editable, normalized_text,
4480 g_utf8_offset_to_pointer (normalized_text, len - 1) - normalized_text,
4482 gtk_editable_set_position (editable, pos);
4485 g_free (normalized_text);
4486 g_free (cluster_text);
4490 gtk_editable_delete_text (editable, prev_pos, entry->current_pos);
4497 gtk_widget_error_bell (GTK_WIDGET (entry));
4500 gtk_entry_pend_cursor_blink (entry);
4504 gtk_entry_copy_clipboard (GtkEntry *entry)
4506 GtkEditable *editable = GTK_EDITABLE (entry);
4510 if (gtk_editable_get_selection_bounds (editable, &start, &end))
4512 if (!entry->visible)
4514 gtk_widget_error_bell (GTK_WIDGET (entry));
4518 str = gtk_entry_get_public_chars (entry, start, end);
4519 gtk_clipboard_set_text (gtk_widget_get_clipboard (GTK_WIDGET (entry),
4520 GDK_SELECTION_CLIPBOARD),
4527 gtk_entry_cut_clipboard (GtkEntry *entry)
4529 GtkEditable *editable = GTK_EDITABLE (entry);
4532 if (!entry->visible)
4534 gtk_widget_error_bell (GTK_WIDGET (entry));
4538 gtk_entry_copy_clipboard (entry);
4540 if (entry->editable)
4542 if (gtk_editable_get_selection_bounds (editable, &start, &end))
4543 gtk_editable_delete_text (editable, start, end);
4547 gtk_widget_error_bell (GTK_WIDGET (entry));
4552 gtk_entry_paste_clipboard (GtkEntry *entry)
4554 if (entry->editable)
4555 gtk_entry_paste (entry, GDK_NONE);
4557 gtk_widget_error_bell (GTK_WIDGET (entry));
4561 gtk_entry_delete_cb (GtkEntry *entry)
4563 GtkEditable *editable = GTK_EDITABLE (entry);
4566 if (entry->editable)
4568 if (gtk_editable_get_selection_bounds (editable, &start, &end))
4569 gtk_editable_delete_text (editable, start, end);
4574 gtk_entry_toggle_overwrite (GtkEntry *entry)
4576 entry->overwrite_mode = !entry->overwrite_mode;
4577 gtk_entry_pend_cursor_blink (entry);
4578 gtk_widget_queue_draw (GTK_WIDGET (entry));
4582 gtk_entry_select_all (GtkEntry *entry)
4584 gtk_entry_select_line (entry);
4588 gtk_entry_real_activate (GtkEntry *entry)
4591 GtkWidget *toplevel;
4594 widget = GTK_WIDGET (entry);
4596 if (entry->activates_default)
4598 toplevel = gtk_widget_get_toplevel (widget);
4599 if (GTK_IS_WINDOW (toplevel))
4601 window = GTK_WINDOW (toplevel);
4604 widget != window->default_widget &&
4605 !(widget == window->focus_widget &&
4606 (!window->default_widget || !GTK_WIDGET_SENSITIVE (window->default_widget))))
4607 gtk_window_activate_default (window);
4613 keymap_direction_changed (GdkKeymap *keymap,
4616 gtk_entry_recompute (entry);
4619 /* IM Context Callbacks
4623 gtk_entry_commit_cb (GtkIMContext *context,
4627 if (entry->editable)
4628 gtk_entry_enter_text (entry, str);
4632 gtk_entry_preedit_changed_cb (GtkIMContext *context,
4635 if (entry->editable)
4637 gchar *preedit_string;
4640 gtk_im_context_get_preedit_string (entry->im_context,
4641 &preedit_string, NULL,
4643 entry->preedit_length = strlen (preedit_string);
4644 cursor_pos = CLAMP (cursor_pos, 0, g_utf8_strlen (preedit_string, -1));
4645 entry->preedit_cursor = cursor_pos;
4646 g_free (preedit_string);
4648 gtk_entry_recompute (entry);
4653 gtk_entry_retrieve_surrounding_cb (GtkIMContext *context,
4656 gtk_im_context_set_surrounding (context,
4659 g_utf8_offset_to_pointer (entry->text, entry->current_pos) - entry->text);
4665 gtk_entry_delete_surrounding_cb (GtkIMContext *slave,
4670 if (entry->editable)
4671 gtk_editable_delete_text (GTK_EDITABLE (entry),
4672 entry->current_pos + offset,
4673 entry->current_pos + offset + n_chars);
4678 /* Internal functions
4681 /* Used for im_commit_cb and inserting Unicode chars */
4683 gtk_entry_enter_text (GtkEntry *entry,
4686 GtkEditable *editable = GTK_EDITABLE (entry);
4688 gboolean old_need_im_reset;
4690 old_need_im_reset = entry->need_im_reset;
4691 entry->need_im_reset = FALSE;
4693 if (gtk_editable_get_selection_bounds (editable, NULL, NULL))
4694 gtk_editable_delete_selection (editable);
4697 if (entry->overwrite_mode)
4698 gtk_entry_delete_from_cursor (entry, GTK_DELETE_CHARS, 1);
4701 tmp_pos = entry->current_pos;
4702 gtk_editable_insert_text (editable, str, strlen (str), &tmp_pos);
4703 gtk_editable_set_position (editable, tmp_pos);
4705 entry->need_im_reset = old_need_im_reset;
4708 /* All changes to entry->current_pos and entry->selection_bound
4709 * should go through this function.
4712 gtk_entry_set_positions (GtkEntry *entry,
4714 gint selection_bound)
4716 gboolean changed = FALSE;
4718 g_object_freeze_notify (G_OBJECT (entry));
4720 if (current_pos != -1 &&
4721 entry->current_pos != current_pos)
4723 entry->current_pos = current_pos;
4726 g_object_notify (G_OBJECT (entry), "cursor-position");
4729 if (selection_bound != -1 &&
4730 entry->selection_bound != selection_bound)
4732 entry->selection_bound = selection_bound;
4735 g_object_notify (G_OBJECT (entry), "selection-bound");
4738 g_object_thaw_notify (G_OBJECT (entry));
4742 gtk_entry_move_adjustments (entry);
4743 gtk_entry_recompute (entry);
4748 gtk_entry_reset_layout (GtkEntry *entry)
4750 if (entry->cached_layout)
4752 g_object_unref (entry->cached_layout);
4753 entry->cached_layout = NULL;
4758 update_im_cursor_location (GtkEntry *entry)
4762 gint strong_xoffset;
4763 gint area_width, area_height;
4765 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
4766 gtk_entry_get_text_area_size (entry, NULL, NULL, &area_width, &area_height);
4768 strong_xoffset = strong_x - entry->scroll_offset;
4769 if (strong_xoffset < 0)
4773 else if (strong_xoffset > area_width)
4775 strong_xoffset = area_width;
4777 area.x = strong_xoffset;
4780 area.height = area_height;
4782 gtk_im_context_set_cursor_location (entry->im_context, &area);
4786 recompute_idle_func (gpointer data)
4790 entry = GTK_ENTRY (data);
4792 entry->recompute_idle = 0;
4794 if (gtk_widget_has_screen (GTK_WIDGET (entry)))
4796 gtk_entry_adjust_scroll (entry);
4797 gtk_entry_queue_draw (entry);
4799 update_im_cursor_location (entry);
4806 gtk_entry_recompute (GtkEntry *entry)
4808 gtk_entry_reset_layout (entry);
4809 gtk_entry_check_cursor_blink (entry);
4811 if (!entry->recompute_idle)
4813 entry->recompute_idle = gdk_threads_add_idle_full (G_PRIORITY_HIGH_IDLE + 15, /* between resize and redraw */
4814 recompute_idle_func, entry, NULL);
4819 append_char (GString *str,
4827 char_len = g_unichar_to_utf8 (ch, buf);
4832 g_string_append_len (str, buf, char_len);
4838 gtk_entry_remove_password_hint (gpointer data)
4840 /* Force the string to be redrawn, but now without a visible character */
4841 gtk_entry_recompute (GTK_ENTRY (data));
4846 static PangoLayout *
4847 gtk_entry_create_layout (GtkEntry *entry,
4848 gboolean include_preedit)
4850 GtkWidget *widget = GTK_WIDGET (entry);
4851 PangoLayout *layout = gtk_widget_create_pango_layout (widget, NULL);
4852 PangoAttrList *tmp_attrs = pango_attr_list_new ();
4854 gchar *preedit_string = NULL;
4855 gint preedit_length = 0;
4856 PangoAttrList *preedit_attrs = NULL;
4858 pango_layout_set_single_paragraph_mode (layout, TRUE);
4860 if (include_preedit)
4862 gtk_im_context_get_preedit_string (entry->im_context,
4863 &preedit_string, &preedit_attrs, NULL);
4864 preedit_length = entry->preedit_length;
4869 GString *tmp_string = g_string_new (NULL);
4871 gint cursor_index = g_utf8_offset_to_pointer (entry->text, entry->current_pos) - entry->text;
4875 g_string_prepend_len (tmp_string, entry->text, entry->n_bytes);
4876 g_string_insert (tmp_string, cursor_index, preedit_string);
4881 gunichar invisible_char;
4883 if (entry->invisible_char != 0)
4884 invisible_char = entry->invisible_char;
4886 invisible_char = ' '; /* just pick a char */
4888 ch_len = g_utf8_strlen (entry->text, entry->n_bytes);
4889 append_char (tmp_string, invisible_char, ch_len);
4891 g_utf8_offset_to_pointer (tmp_string->str, entry->current_pos) -
4893 g_string_insert (tmp_string, cursor_index, preedit_string);
4896 pango_layout_set_text (layout, tmp_string->str, tmp_string->len);
4898 pango_attr_list_splice (tmp_attrs, preedit_attrs,
4899 cursor_index, preedit_length);
4901 g_string_free (tmp_string, TRUE);
4905 PangoDirection pango_dir;
4908 pango_dir = pango_find_base_dir (entry->text, entry->n_bytes);
4911 pango_dir = PANGO_DIRECTION_NEUTRAL;
4913 if (pango_dir == PANGO_DIRECTION_NEUTRAL)
4915 if (GTK_WIDGET_HAS_FOCUS (widget))
4917 GdkDisplay *display = gtk_widget_get_display (widget);
4918 GdkKeymap *keymap = gdk_keymap_get_for_display (display);
4919 if (gdk_keymap_get_direction (keymap) == PANGO_DIRECTION_RTL)
4920 pango_dir = PANGO_DIRECTION_RTL;
4922 pango_dir = PANGO_DIRECTION_LTR;
4926 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
4927 pango_dir = PANGO_DIRECTION_RTL;
4929 pango_dir = PANGO_DIRECTION_LTR;
4933 pango_context_set_base_dir (gtk_widget_get_pango_context (widget),
4936 entry->resolved_dir = pango_dir;
4940 pango_layout_set_text (layout, entry->text, entry->n_bytes);
4944 GString *str = g_string_new (NULL);
4945 gunichar invisible_char;
4946 guint password_hint_timeout;
4947 GtkEntryPasswordHint *password_hint;
4949 g_object_get (gtk_widget_get_settings (widget),
4950 "gtk-entry-password-hint-timeout", &password_hint_timeout,
4953 if (entry->invisible_char != 0)
4954 invisible_char = entry->invisible_char;
4956 invisible_char = ' '; /* just pick a char */
4958 password_hint = g_object_get_qdata (G_OBJECT (entry),
4959 quark_password_hint);
4961 if (password_hint && password_hint->password_hint_timeout_id)
4963 g_source_remove (password_hint->password_hint_timeout_id);
4964 password_hint->password_hint_timeout_id = 0;
4967 if (password_hint_timeout == 0 || password_hint == NULL ||
4968 (password_hint && password_hint->password_hint_length == 0))
4970 append_char (str, invisible_char, entry->text_length);
4972 else if (password_hint)
4974 /* Draw hidden characters upto the inserted position,
4975 * then the real thing, pad up to full length
4977 if (password_hint->password_hint_position > 1)
4978 append_char (str, invisible_char,
4979 password_hint->password_hint_position - 1);
4981 g_string_append_len (str, password_hint->password_hint,
4982 password_hint->password_hint_length);
4984 if (password_hint->password_hint_position < entry->text_length)
4985 append_char (str, invisible_char,
4986 entry->text_length -
4987 password_hint->password_hint_position);
4989 /* Now remove this last input character, don't need
4992 memset (password_hint->password_hint, 0, PASSWORD_HINT_MAX);
4993 password_hint->password_hint_length = 0;
4995 password_hint->password_hint_timeout_id =
4996 gdk_threads_add_timeout (password_hint_timeout,
4997 (GSourceFunc) gtk_entry_remove_password_hint,
5001 pango_layout_set_text (layout, str->str, str->len);
5002 g_string_free (str, TRUE);
5006 pango_layout_set_attributes (layout, tmp_attrs);
5008 g_free (preedit_string);
5010 pango_attr_list_unref (preedit_attrs);
5012 pango_attr_list_unref (tmp_attrs);
5017 static PangoLayout *
5018 gtk_entry_ensure_layout (GtkEntry *entry,
5019 gboolean include_preedit)
5021 if (entry->preedit_length > 0 &&
5022 !include_preedit != !entry->cache_includes_preedit)
5023 gtk_entry_reset_layout (entry);
5025 if (!entry->cached_layout)
5027 entry->cached_layout = gtk_entry_create_layout (entry, include_preedit);
5028 entry->cache_includes_preedit = include_preedit;
5031 return entry->cached_layout;
5035 get_layout_position (GtkEntry *entry,
5039 PangoLayout *layout;
5040 PangoRectangle logical_rect;
5041 gint area_width, area_height;
5042 GtkBorder inner_border;
5044 PangoLayoutLine *line;
5046 layout = gtk_entry_ensure_layout (entry, TRUE);
5048 gtk_entry_get_text_area_size (entry, NULL, NULL, &area_width, &area_height);
5049 _gtk_entry_effective_inner_border (entry, &inner_border);
5051 area_height = PANGO_SCALE * (area_height - inner_border.top - inner_border.bottom);
5053 line = pango_layout_get_lines_readonly (layout)->data;
5054 pango_layout_line_get_extents (line, NULL, &logical_rect);
5056 /* Align primarily for locale's ascent/descent */
5057 y_pos = ((area_height - entry->ascent - entry->descent) / 2 +
5058 entry->ascent + logical_rect.y);
5060 /* Now see if we need to adjust to fit in actual drawn string */
5061 if (logical_rect.height > area_height)
5062 y_pos = (area_height - logical_rect.height) / 2;
5065 else if (y_pos + logical_rect.height > area_height)
5066 y_pos = area_height - logical_rect.height;
5068 y_pos = inner_border.top + y_pos / PANGO_SCALE;
5071 *x = inner_border.left - entry->scroll_offset;
5078 gtk_entry_draw_text (GtkEntry *entry)
5082 if (!entry->visible && entry->invisible_char == 0)
5085 if (GTK_WIDGET_DRAWABLE (entry))
5087 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
5090 gint start_pos, end_pos;
5092 widget = GTK_WIDGET (entry);
5094 get_layout_position (entry, &x, &y);
5096 cr = gdk_cairo_create (entry->text_area);
5098 cairo_move_to (cr, x, y);
5099 gdk_cairo_set_source_color (cr, &widget->style->text [widget->state]);
5100 pango_cairo_show_layout (cr, layout);
5102 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start_pos, &end_pos))
5106 PangoRectangle logical_rect;
5107 GdkColor *selection_color, *text_color;
5108 GtkBorder inner_border;
5110 pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
5111 gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
5113 if (GTK_WIDGET_HAS_FOCUS (entry))
5115 selection_color = &widget->style->base [GTK_STATE_SELECTED];
5116 text_color = &widget->style->text [GTK_STATE_SELECTED];
5120 selection_color = &widget->style->base [GTK_STATE_ACTIVE];
5121 text_color = &widget->style->text [GTK_STATE_ACTIVE];
5124 _gtk_entry_effective_inner_border (entry, &inner_border);
5126 for (i = 0; i < n_ranges; ++i)
5127 cairo_rectangle (cr,
5128 inner_border.left - entry->scroll_offset + ranges[2 * i],
5131 logical_rect.height);
5135 gdk_cairo_set_source_color (cr, selection_color);
5138 cairo_move_to (cr, x, y);
5139 gdk_cairo_set_source_color (cr, text_color);
5140 pango_cairo_show_layout (cr, layout);
5150 draw_insertion_cursor (GtkEntry *entry,
5151 GdkRectangle *cursor_location,
5152 gboolean is_primary,
5153 PangoDirection direction,
5154 gboolean draw_arrow)
5156 GtkWidget *widget = GTK_WIDGET (entry);
5157 GtkTextDirection text_dir;
5159 if (direction == PANGO_DIRECTION_LTR)
5160 text_dir = GTK_TEXT_DIR_LTR;
5162 text_dir = GTK_TEXT_DIR_RTL;
5164 gtk_draw_insertion_cursor (widget, entry->text_area, NULL,
5166 is_primary, text_dir, draw_arrow);
5170 gtk_entry_draw_cursor (GtkEntry *entry,
5173 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
5174 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
5176 if (GTK_WIDGET_DRAWABLE (entry))
5178 GtkWidget *widget = GTK_WIDGET (entry);
5179 GdkRectangle cursor_location;
5180 gboolean split_cursor;
5181 PangoRectangle cursor_rect;
5182 GtkBorder inner_border;
5184 gint text_area_height;
5187 gboolean block_at_line_end;
5188 PangoLayout *layout;
5191 _gtk_entry_effective_inner_border (entry, &inner_border);
5193 xoffset = inner_border.left - entry->scroll_offset;
5195 gdk_drawable_get_size (entry->text_area, NULL, &text_area_height);
5197 layout = gtk_entry_ensure_layout (entry, TRUE);
5198 text = pango_layout_get_text (layout);
5199 cursor_index = g_utf8_offset_to_pointer (text, entry->current_pos + entry->preedit_cursor) - text;
5200 if (!entry->overwrite_mode)
5203 block = _gtk_text_util_get_block_cursor_location (layout,
5204 cursor_index, &cursor_rect, &block_at_line_end);
5208 gint strong_x, weak_x;
5209 PangoDirection dir1 = PANGO_DIRECTION_NEUTRAL;
5210 PangoDirection dir2 = PANGO_DIRECTION_NEUTRAL;
5214 gtk_entry_get_cursor_locations (entry, type, &strong_x, &weak_x);
5216 g_object_get (gtk_widget_get_settings (widget),
5217 "gtk-split-cursor", &split_cursor,
5220 dir1 = entry->resolved_dir;
5226 if (weak_x != strong_x)
5228 dir2 = (entry->resolved_dir == PANGO_DIRECTION_LTR) ? PANGO_DIRECTION_RTL : PANGO_DIRECTION_LTR;
5234 if (keymap_direction == entry->resolved_dir)
5240 cursor_location.x = xoffset + x1;
5241 cursor_location.y = inner_border.top;
5242 cursor_location.width = 0;
5243 cursor_location.height = text_area_height - inner_border.top - inner_border.bottom;
5245 draw_insertion_cursor (entry,
5246 &cursor_location, TRUE, dir1,
5247 dir2 != PANGO_DIRECTION_NEUTRAL);
5249 if (dir2 != PANGO_DIRECTION_NEUTRAL)
5251 cursor_location.x = xoffset + x2;
5252 draw_insertion_cursor (entry,
5253 &cursor_location, FALSE, dir2,
5257 else /* overwrite_mode */
5259 GdkColor cursor_color;
5264 get_layout_position (entry, &x, &y);
5266 rect.x = PANGO_PIXELS (cursor_rect.x) + x;
5267 rect.y = PANGO_PIXELS (cursor_rect.y) + y;
5268 rect.width = PANGO_PIXELS (cursor_rect.width);
5269 rect.height = PANGO_PIXELS (cursor_rect.height);
5271 cr = gdk_cairo_create (entry->text_area);
5273 _gtk_widget_get_cursor_color (widget, &cursor_color);
5274 gdk_cairo_set_source_color (cr, &cursor_color);
5275 gdk_cairo_rectangle (cr, &rect);
5278 if (!block_at_line_end)
5280 gdk_cairo_rectangle (cr, &rect);
5282 cairo_move_to (cr, x, y);
5283 gdk_cairo_set_source_color (cr, &widget->style->base[widget->state]);
5284 pango_cairo_show_layout (cr, layout);
5293 gtk_entry_queue_draw (GtkEntry *entry)
5295 if (GTK_WIDGET_DRAWABLE (entry))
5296 gdk_window_invalidate_rect (entry->text_area, NULL, FALSE);
5300 _gtk_entry_reset_im_context (GtkEntry *entry)
5302 if (entry->need_im_reset)
5304 entry->need_im_reset = FALSE;
5305 gtk_im_context_reset (entry->im_context);
5310 gtk_entry_find_position (GtkEntry *entry,
5313 PangoLayout *layout;
5314 PangoLayoutLine *line;
5321 layout = gtk_entry_ensure_layout (entry, TRUE);
5322 text = pango_layout_get_text (layout);
5323 cursor_index = g_utf8_offset_to_pointer (text, entry->current_pos) - text;
5325 line = pango_layout_get_lines_readonly (layout)->data;
5326 pango_layout_line_x_to_index (line, x * PANGO_SCALE, &index, &trailing);
5328 if (index >= cursor_index && entry->preedit_length)
5330 if (index >= cursor_index + entry->preedit_length)
5331 index -= entry->preedit_length;
5334 index = cursor_index;
5339 pos = g_utf8_pointer_to_offset (text, text + index);
5346 gtk_entry_get_cursor_locations (GtkEntry *entry,
5351 if (!entry->visible && !entry->invisible_char)
5361 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
5362 const gchar *text = pango_layout_get_text (layout);
5363 PangoRectangle strong_pos, weak_pos;
5366 if (type == CURSOR_STANDARD)
5368 index = g_utf8_offset_to_pointer (text, entry->current_pos + entry->preedit_cursor) - text;
5370 else /* type == CURSOR_DND */
5372 index = g_utf8_offset_to_pointer (text, entry->dnd_position) - text;
5374 if (entry->dnd_position > entry->current_pos)
5377 index += entry->preedit_length;
5380 gint preedit_len_chars = g_utf8_strlen (text, -1) - entry->text_length;
5381 index += preedit_len_chars * g_unichar_to_utf8 (entry->invisible_char, NULL);
5386 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
5389 *strong_x = strong_pos.x / PANGO_SCALE;
5392 *weak_x = weak_pos.x / PANGO_SCALE;
5397 gtk_entry_adjust_scroll (GtkEntry *entry)
5399 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
5400 gint min_offset, max_offset;
5401 gint text_area_width, text_width;
5402 GtkBorder inner_border;
5403 gint strong_x, weak_x;
5404 gint strong_xoffset, weak_xoffset;
5406 PangoLayout *layout;
5407 PangoLayoutLine *line;
5408 PangoRectangle logical_rect;
5410 if (!GTK_WIDGET_REALIZED (entry))
5413 _gtk_entry_effective_inner_border (entry, &inner_border);
5415 gdk_drawable_get_size (entry->text_area, &text_area_width, NULL);
5416 text_area_width -= inner_border.left + inner_border.right;
5417 if (text_area_width < 0)
5418 text_area_width = 0;
5420 layout = gtk_entry_ensure_layout (entry, TRUE);
5421 line = pango_layout_get_lines_readonly (layout)->data;
5423 pango_layout_line_get_extents (line, NULL, &logical_rect);
5425 /* Display as much text as we can */
5427 if (entry->resolved_dir == PANGO_DIRECTION_LTR)
5428 xalign = priv->xalign;
5430 xalign = 1.0 - priv->xalign;
5432 text_width = PANGO_PIXELS(logical_rect.width);
5434 if (text_width > text_area_width)
5437 max_offset = text_width - text_area_width;
5441 min_offset = (text_width - text_area_width) * xalign;
5442 max_offset = min_offset;
5445 entry->scroll_offset = CLAMP (entry->scroll_offset, min_offset, max_offset);
5447 /* And make sure cursors are on screen. Note that the cursor is
5448 * actually drawn one pixel into the INNER_BORDER space on
5449 * the right, when the scroll is at the utmost right. This
5450 * looks better to to me than confining the cursor inside the
5451 * border entirely, though it means that the cursor gets one
5452 * pixel closer to the edge of the widget on the right than
5453 * on the left. This might need changing if one changed
5454 * INNER_BORDER from 2 to 1, as one would do on a
5455 * small-screen-real-estate display.
5457 * We always make sure that the strong cursor is on screen, and
5458 * put the weak cursor on screen if possible.
5461 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, &weak_x);
5463 strong_xoffset = strong_x - entry->scroll_offset;
5465 if (strong_xoffset < 0)
5467 entry->scroll_offset += strong_xoffset;
5470 else if (strong_xoffset > text_area_width)
5472 entry->scroll_offset += strong_xoffset - text_area_width;
5473 strong_xoffset = text_area_width;
5476 weak_xoffset = weak_x - entry->scroll_offset;
5478 if (weak_xoffset < 0 && strong_xoffset - weak_xoffset <= text_area_width)
5480 entry->scroll_offset += weak_xoffset;
5482 else if (weak_xoffset > text_area_width &&
5483 strong_xoffset - (weak_xoffset - text_area_width) >= 0)
5485 entry->scroll_offset += weak_xoffset - text_area_width;
5488 g_object_notify (G_OBJECT (entry), "scroll-offset");
5492 gtk_entry_move_adjustments (GtkEntry *entry)
5494 PangoContext *context;
5495 PangoFontMetrics *metrics;
5496 gint x, layout_x, border_x, border_y;
5498 GtkAdjustment *adjustment;
5500 adjustment = g_object_get_qdata (G_OBJECT (entry), quark_cursor_hadjustment);
5504 /* Cursor position, layout offset, border width, and widget allocation */
5505 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &x, NULL);
5506 get_layout_position (entry, &layout_x, NULL);
5507 _gtk_entry_get_borders (entry, &border_x, &border_y);
5508 x += entry->widget.allocation.x + layout_x + border_x;
5510 /* Approximate width of a char, so user can see what is ahead/behind */
5511 context = gtk_widget_get_pango_context (GTK_WIDGET (entry));
5512 metrics = pango_context_get_metrics (context,
5513 entry->widget.style->font_desc,
5514 pango_context_get_language (context));
5515 char_width = pango_font_metrics_get_approximate_char_width (metrics) / PANGO_SCALE;
5518 gtk_adjustment_clamp_page (adjustment,
5519 x - (char_width + 1), /* one char + one pixel before */
5520 x + (char_width + 2)); /* one char + cursor + one pixel after */
5524 gtk_entry_move_visually (GtkEntry *entry,
5529 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
5532 text = pango_layout_get_text (layout);
5534 index = g_utf8_offset_to_pointer (text, start) - text;
5538 int new_index, new_trailing;
5539 gboolean split_cursor;
5542 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
5543 "gtk-split-cursor", &split_cursor,
5550 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
5551 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
5553 strong = keymap_direction == entry->resolved_dir;
5558 pango_layout_move_cursor_visually (layout, strong, index, 0, 1, &new_index, &new_trailing);
5563 pango_layout_move_cursor_visually (layout, strong, index, 0, -1, &new_index, &new_trailing);
5569 else if (new_index != G_MAXINT)
5572 while (new_trailing--)
5573 index = g_utf8_next_char (text + index) - text;
5576 return g_utf8_pointer_to_offset (text, text + index);
5580 gtk_entry_move_logically (GtkEntry *entry,
5584 gint new_pos = start;
5586 /* Prevent any leak of information */
5587 if (!entry->visible)
5589 new_pos = CLAMP (start + count, 0, entry->text_length);
5591 else if (entry->text)
5593 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
5594 PangoLogAttr *log_attrs;
5597 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
5599 while (count > 0 && new_pos < entry->text_length)
5603 while (new_pos < entry->text_length && !log_attrs[new_pos].is_cursor_position);
5607 while (count < 0 && new_pos > 0)
5611 while (new_pos > 0 && !log_attrs[new_pos].is_cursor_position);
5623 gtk_entry_move_forward_word (GtkEntry *entry,
5625 gboolean allow_whitespace)
5627 gint new_pos = start;
5629 /* Prevent any leak of information */
5630 if (!entry->visible)
5632 new_pos = entry->text_length;
5634 else if (entry->text && (new_pos < entry->text_length))
5636 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
5637 PangoLogAttr *log_attrs;
5640 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
5642 /* Find the next word boundary */
5644 while (new_pos < n_attrs - 1 && !(log_attrs[new_pos].is_word_end ||
5645 (log_attrs[new_pos].is_word_start && allow_whitespace)))
5656 gtk_entry_move_backward_word (GtkEntry *entry,
5658 gboolean allow_whitespace)
5660 gint new_pos = start;
5662 /* Prevent any leak of information */
5663 if (!entry->visible)
5667 else if (entry->text && start > 0)
5669 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
5670 PangoLogAttr *log_attrs;
5673 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
5675 new_pos = start - 1;
5677 /* Find the previous word boundary */
5678 while (new_pos > 0 && !(log_attrs[new_pos].is_word_start ||
5679 (log_attrs[new_pos].is_word_end && allow_whitespace)))
5689 gtk_entry_delete_whitespace (GtkEntry *entry)
5691 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
5692 PangoLogAttr *log_attrs;
5696 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
5698 start = end = entry->current_pos;
5700 while (start > 0 && log_attrs[start-1].is_white)
5703 while (end < n_attrs && log_attrs[end].is_white)
5709 gtk_editable_delete_text (GTK_EDITABLE (entry), start, end);
5714 gtk_entry_select_word (GtkEntry *entry)
5716 gint start_pos = gtk_entry_move_backward_word (entry, entry->current_pos, TRUE);
5717 gint end_pos = gtk_entry_move_forward_word (entry, entry->current_pos, TRUE);
5719 gtk_editable_select_region (GTK_EDITABLE (entry), start_pos, end_pos);
5723 gtk_entry_select_line (GtkEntry *entry)
5725 gtk_editable_select_region (GTK_EDITABLE (entry), 0, -1);
5729 * Like gtk_editable_get_chars, but handle not-visible entries
5733 gtk_entry_get_public_chars (GtkEntry *entry,
5738 end = entry->text_length;
5741 return gtk_editable_get_chars (GTK_EDITABLE (entry), start, end);
5742 else if (!entry->invisible_char)
5743 return g_strdup ("");
5746 GString *str = g_string_new (NULL);
5747 append_char (str, entry->invisible_char, end - start);
5748 return g_string_free (str, FALSE);
5753 truncate_multiline (const gchar *text)
5758 text[length] && text[length] != '\n' && text[length] != '\r';
5765 paste_received (GtkClipboard *clipboard,
5769 GtkEntry *entry = GTK_ENTRY (data);
5770 GtkEditable *editable = GTK_EDITABLE (entry);
5771 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
5773 if (entry->button == 2)
5775 gint pos, start, end;
5776 pos = priv->insert_pos;
5777 gtk_editable_get_selection_bounds (editable, &start, &end);
5778 if (!((start <= pos && pos <= end) || (end <= pos && pos <= start)))
5779 gtk_editable_select_region (editable, pos, pos);
5784 gint pos, start, end;
5786 gboolean popup_completion;
5787 GtkEntryCompletion *completion;
5789 completion = gtk_entry_get_completion (entry);
5791 if (entry->truncate_multiline)
5792 length = truncate_multiline (text);
5794 /* only complete if the selection is at the end */
5795 popup_completion = (entry->text_length == MAX (entry->current_pos, entry->selection_bound));
5799 if (GTK_WIDGET_MAPPED (completion->priv->popup_window))
5800 _gtk_entry_completion_popdown (completion);
5802 if (!popup_completion && completion->priv->changed_id > 0)
5803 g_signal_handler_block (entry, completion->priv->changed_id);
5806 begin_change (entry);
5807 g_object_freeze_notify (G_OBJECT (entry));
5808 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5809 gtk_editable_delete_text (editable, start, end);
5811 pos = entry->current_pos;
5812 gtk_editable_insert_text (editable, text, length, &pos);
5813 gtk_editable_set_position (editable, pos);
5814 g_object_thaw_notify (G_OBJECT (entry));
5818 !popup_completion && completion->priv->changed_id > 0)
5819 g_signal_handler_unblock (entry, completion->priv->changed_id);
5822 g_object_unref (entry);
5826 gtk_entry_paste (GtkEntry *entry,
5829 g_object_ref (entry);
5830 gtk_clipboard_request_text (gtk_widget_get_clipboard (GTK_WIDGET (entry), selection),
5831 paste_received, entry);
5835 primary_get_cb (GtkClipboard *clipboard,
5836 GtkSelectionData *selection_data,
5840 GtkEntry *entry = GTK_ENTRY (data);
5843 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end))
5845 gchar *str = gtk_entry_get_public_chars (entry, start, end);
5846 gtk_selection_data_set_text (selection_data, str, -1);
5852 primary_clear_cb (GtkClipboard *clipboard,
5855 GtkEntry *entry = GTK_ENTRY (data);
5857 gtk_editable_select_region (GTK_EDITABLE (entry), entry->current_pos, entry->current_pos);
5861 gtk_entry_update_primary_selection (GtkEntry *entry)
5863 GtkTargetList *list;
5864 GtkTargetEntry *targets;
5865 GtkClipboard *clipboard;
5869 if (!GTK_WIDGET_REALIZED (entry))
5872 list = gtk_target_list_new (NULL, 0);
5873 gtk_target_list_add_text_targets (list, 0);
5875 targets = gtk_target_table_new_from_list (list, &n_targets);
5877 clipboard = gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_PRIMARY);
5879 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end))
5881 if (!gtk_clipboard_set_with_owner (clipboard, targets, n_targets,
5882 primary_get_cb, primary_clear_cb, G_OBJECT (entry)))
5883 primary_clear_cb (clipboard, entry);
5887 if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (entry))
5888 gtk_clipboard_clear (clipboard);
5891 gtk_target_table_free (targets, n_targets);
5892 gtk_target_list_unref (list);
5896 gtk_entry_clear (GtkEntry *entry,
5897 GtkEntryIconPosition icon_pos)
5899 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
5900 EntryIconInfo *icon_info = priv->icons[icon_pos];
5902 if (!icon_info || icon_info->storage_type == GTK_IMAGE_EMPTY)
5905 g_object_freeze_notify (G_OBJECT (entry));
5907 /* Explicitly check, as the pointer may become invalidated
5908 * during destruction.
5910 if (GDK_IS_WINDOW (icon_info->window))
5911 gdk_window_hide (icon_info->window);
5913 if (icon_info->pixbuf)
5915 g_object_unref (icon_info->pixbuf);
5916 icon_info->pixbuf = NULL;
5919 switch (icon_info->storage_type)
5921 case GTK_IMAGE_PIXBUF:
5922 g_object_notify (G_OBJECT (entry),
5923 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "pixbuf-primary" : "pixbuf-secondary");
5926 case GTK_IMAGE_STOCK:
5927 g_free (icon_info->stock_id);
5928 icon_info->stock_id = NULL;
5929 g_object_notify (G_OBJECT (entry),
5930 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "stock-primary" : "stock-secondary");
5933 case GTK_IMAGE_ICON_NAME:
5934 g_free (icon_info->icon_name);
5935 icon_info->icon_name = NULL;
5936 g_object_notify (G_OBJECT (entry),
5937 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "icon-name-primary" : "icon-name-secondary");
5940 case GTK_IMAGE_GICON:
5941 if (icon_info->gicon)
5943 g_object_unref (icon_info->gicon);
5944 icon_info->gicon = NULL;
5946 g_object_notify (G_OBJECT (entry),
5947 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "gicon-primary" : "gicon-secondary");
5951 g_assert_not_reached ();
5955 icon_info->storage_type = GTK_IMAGE_EMPTY;
5956 g_object_notify (G_OBJECT (entry),
5957 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "storage-type-primary" : "storage-type-secondary");
5959 g_object_thaw_notify (G_OBJECT (entry));
5963 gtk_entry_ensure_pixbuf (GtkEntry *entry,
5964 GtkEntryIconPosition icon_pos)
5966 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
5967 EntryIconInfo *icon_info = priv->icons[icon_pos];
5969 GtkIconTheme *icon_theme;
5970 GtkSettings *settings;
5974 if (!icon_info || icon_info->pixbuf)
5977 switch (icon_info->storage_type)
5979 case GTK_IMAGE_EMPTY:
5980 case GTK_IMAGE_PIXBUF:
5982 case GTK_IMAGE_STOCK:
5983 icon_info->pixbuf = gtk_widget_render_icon (GTK_WIDGET (entry),
5984 icon_info->stock_id,
5989 case GTK_IMAGE_ICON_NAME:
5990 screen = gtk_widget_get_screen (GTK_WIDGET (entry));
5993 icon_theme = gtk_icon_theme_get_for_screen (screen);
5994 settings = gtk_settings_get_for_screen (screen);
5996 gtk_icon_size_lookup_for_settings (settings,
6000 icon_info->pixbuf = gtk_icon_theme_load_icon (icon_theme,
6001 icon_info->icon_name,
6002 MIN (width, height),
6005 if (icon_info->pixbuf == NULL)
6006 icon_info->pixbuf = gtk_widget_render_icon (GTK_WIDGET (entry),
6007 GTK_STOCK_MISSING_IMAGE,
6013 case GTK_IMAGE_GICON:
6014 screen = gtk_widget_get_screen (GTK_WIDGET (entry));
6017 icon_theme = gtk_icon_theme_get_for_screen (screen);
6018 settings = gtk_settings_get_for_screen (screen);
6020 gtk_icon_size_lookup_for_settings (settings,
6024 info = gtk_icon_theme_lookup_by_gicon (icon_theme,
6026 MIN (width, height),
6027 GTK_ICON_LOOKUP_USE_BUILTIN);
6030 icon_info->pixbuf = gtk_icon_info_load_icon (info, NULL);
6031 gtk_icon_info_free (info);
6034 if (icon_info->pixbuf == NULL)
6035 icon_info->pixbuf = gtk_widget_render_icon (GTK_WIDGET (entry),
6036 GTK_STOCK_MISSING_IMAGE,
6043 g_assert_not_reached ();
6047 if (GDK_IS_WINDOW (icon_info->window))
6048 gdk_window_show (icon_info->window);
6050 gtk_widget_queue_resize (GTK_WIDGET (entry));
6060 * Creates a new entry.
6062 * Return value: a new #GtkEntry.
6065 gtk_entry_new (void)
6067 return g_object_new (GTK_TYPE_ENTRY, NULL);
6071 * gtk_entry_new_with_max_length:
6072 * @max: the maximum length of the entry, or 0 for no maximum.
6073 * (other than the maximum length of entries.) The value passed in will
6074 * be clamped to the range 0-65536.
6076 * Creates a new #GtkEntry widget with the given maximum length.
6078 * Return value: a new #GtkEntry
6080 * Deprecated: Use gtk_entry_set_max_length() instead.
6083 gtk_entry_new_with_max_length (gint max)
6087 max = CLAMP (max, 0, MAX_SIZE);
6089 entry = g_object_new (GTK_TYPE_ENTRY, NULL);
6090 entry->text_max_length = max;
6092 return GTK_WIDGET (entry);
6096 * gtk_entry_set_text:
6097 * @entry: a #GtkEntry
6098 * @text: the new text
6100 * Sets the text in the widget to the given
6101 * value, replacing the current contents.
6104 gtk_entry_set_text (GtkEntry *entry,
6108 GtkEntryCompletion *completion;
6110 g_return_if_fail (GTK_IS_ENTRY (entry));
6111 g_return_if_fail (text != NULL);
6113 /* Actually setting the text will affect the cursor and selection;
6114 * if the contents don't actually change, this will look odd to the user.
6116 if (strcmp (entry->text, text) == 0)
6119 completion = gtk_entry_get_completion (entry);
6120 if (completion && completion->priv->changed_id > 0)
6121 g_signal_handler_block (entry, completion->priv->changed_id);
6123 begin_change (entry);
6124 g_object_freeze_notify (G_OBJECT (entry));
6125 gtk_editable_delete_text (GTK_EDITABLE (entry), 0, -1);
6128 gtk_editable_insert_text (GTK_EDITABLE (entry), text, strlen (text), &tmp_pos);
6129 g_object_thaw_notify (G_OBJECT (entry));
6132 if (completion && completion->priv->changed_id > 0)
6133 g_signal_handler_unblock (entry, completion->priv->changed_id);
6137 * gtk_entry_append_text:
6138 * @entry: a #GtkEntry
6139 * @text: the text to append
6141 * Appends the given text to the contents of the widget.
6143 * Deprecated: 2.0: Use gtk_editable_insert_text() instead.
6146 gtk_entry_append_text (GtkEntry *entry,
6151 g_return_if_fail (GTK_IS_ENTRY (entry));
6152 g_return_if_fail (text != NULL);
6154 tmp_pos = entry->text_length;
6155 gtk_editable_insert_text (GTK_EDITABLE (entry), text, -1, &tmp_pos);
6159 * gtk_entry_prepend_text:
6160 * @entry: a #GtkEntry
6161 * @text: the text to prepend
6163 * Prepends the given text to the contents of the widget.
6165 * Deprecated: 2.0: Use gtk_editable_insert_text() instead.
6168 gtk_entry_prepend_text (GtkEntry *entry,
6173 g_return_if_fail (GTK_IS_ENTRY (entry));
6174 g_return_if_fail (text != NULL);
6177 gtk_editable_insert_text (GTK_EDITABLE (entry), text, -1, &tmp_pos);
6181 * gtk_entry_set_position:
6182 * @entry: a #GtkEntry
6183 * @position: the position of the cursor. The cursor is displayed
6184 * before the character with the given (base 0) index in the widget.
6185 * The value must be less than or equal to the number of characters
6186 * in the widget. A value of -1 indicates that the position should
6187 * be set after the last character in the entry. Note that this
6188 * position is in characters, not in bytes.
6190 * Sets the cursor position in an entry to the given value.
6192 * Deprecated: 2.0: Use gtk_editable_set_position() instead.
6195 gtk_entry_set_position (GtkEntry *entry,
6198 g_return_if_fail (GTK_IS_ENTRY (entry));
6200 gtk_editable_set_position (GTK_EDITABLE (entry), position);
6204 * gtk_entry_set_visibility:
6205 * @entry: a #GtkEntry
6206 * @visible: %TRUE if the contents of the entry are displayed
6209 * Sets whether the contents of the entry are visible or not.
6210 * When visibility is set to %FALSE, characters are displayed
6211 * as the invisible char, and will also appear that way when
6212 * the text in the entry widget is copied elsewhere.
6214 * By default, GTK+ picks the best invisible character available
6215 * in the current font, but it can be changed with
6216 * gtk_entry_set_invisible_char().
6219 gtk_entry_set_visibility (GtkEntry *entry,
6222 g_return_if_fail (GTK_IS_ENTRY (entry));
6224 visible = visible != FALSE;
6226 if (entry->visible != visible)
6228 entry->visible = visible;
6230 g_object_notify (G_OBJECT (entry), "visibility");
6231 gtk_entry_recompute (entry);
6236 * gtk_entry_get_visibility:
6237 * @entry: a #GtkEntry
6239 * Retrieves whether the text in @entry is visible. See
6240 * gtk_entry_set_visibility().
6242 * Return value: %TRUE if the text is currently visible
6245 gtk_entry_get_visibility (GtkEntry *entry)
6247 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
6249 return entry->visible;
6253 * gtk_entry_set_invisible_char:
6254 * @entry: a #GtkEntry
6255 * @ch: a Unicode character
6257 * Sets the character to use in place of the actual text when
6258 * gtk_entry_set_visibility() has been called to set text visibility
6259 * to %FALSE. i.e. this is the character used in "password mode" to
6260 * show the user how many characters have been typed. By default, GTK+
6261 * picks the best invisible char available in the current font. If you
6262 * set the invisible char to 0, then the user will get no feedback
6263 * at all; there will be no text on the screen as they type.
6266 gtk_entry_set_invisible_char (GtkEntry *entry,
6269 GtkEntryPrivate *priv;
6271 g_return_if_fail (GTK_IS_ENTRY (entry));
6273 priv = GTK_ENTRY_GET_PRIVATE (entry);
6275 if (!priv->invisible_char_set)
6277 priv->invisible_char_set = TRUE;
6278 g_object_notify (G_OBJECT (entry), "invisible-char-set");
6281 if (ch == entry->invisible_char)
6284 entry->invisible_char = ch;
6285 g_object_notify (G_OBJECT (entry), "invisible-char");
6286 gtk_entry_recompute (entry);
6290 * gtk_entry_get_invisible_char:
6291 * @entry: a #GtkEntry
6293 * Retrieves the character displayed in place of the real characters
6294 * for entries with visibility set to false. See gtk_entry_set_invisible_char().
6296 * Return value: the current invisible char, or 0, if the entry does not
6297 * show invisible text at all.
6300 gtk_entry_get_invisible_char (GtkEntry *entry)
6302 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
6304 return entry->invisible_char;
6308 * gtk_entry_unset_invisible_char:
6309 * @entry: a #GtkEntry
6311 * Unsets the invisible char previously set with
6312 * gtk_entry_set_invisible_char(). So that the
6313 * default invisible char is used again.
6318 gtk_entry_unset_invisible_char (GtkEntry *entry)
6320 GtkEntryPrivate *priv;
6323 g_return_if_fail (GTK_IS_ENTRY (entry));
6325 priv = GTK_ENTRY_GET_PRIVATE (entry);
6327 if (!priv->invisible_char_set)
6330 priv->invisible_char_set = FALSE;
6331 ch = find_invisible_char (GTK_WIDGET (entry));
6333 if (entry->invisible_char != ch)
6335 entry->invisible_char = ch;
6336 g_object_notify (G_OBJECT (entry), "invisible-char");
6339 g_object_notify (G_OBJECT (entry), "invisible-char-set");
6340 gtk_entry_recompute (entry);
6344 * gtk_entry_set_editable:
6345 * @entry: a #GtkEntry
6346 * @editable: %TRUE if the user is allowed to edit the text
6349 * Determines if the user can edit the text in the editable
6352 * Deprecated: 2.0: Use gtk_editable_set_editable() instead.
6355 gtk_entry_set_editable (GtkEntry *entry,
6358 g_return_if_fail (GTK_IS_ENTRY (entry));
6360 gtk_editable_set_editable (GTK_EDITABLE (entry), editable);
6364 * gtk_entry_set_overwrite_mode:
6365 * @entry: a #GtkEntry
6366 * @overwrite: new value
6368 * Sets whether the text is overwritten when typing in the #GtkEntry.
6373 gtk_entry_set_overwrite_mode (GtkEntry *entry,
6376 g_return_if_fail (GTK_IS_ENTRY (entry));
6378 if (entry->overwrite_mode == overwrite)
6381 gtk_entry_toggle_overwrite (entry);
6383 g_object_notify (G_OBJECT (entry), "overwrite-mode");
6387 * gtk_entry_get_overwrite_mode:
6388 * @entry: a #GtkEntry
6390 * Gets the value set by gtk_entry_set_overwrite_mode().
6392 * Return value: whether the text is overwritten when typing.
6397 gtk_entry_get_overwrite_mode (GtkEntry *entry)
6399 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
6401 return entry->overwrite_mode;
6405 * gtk_entry_get_text:
6406 * @entry: a #GtkEntry
6408 * Retrieves the contents of the entry widget.
6409 * See also gtk_editable_get_chars().
6411 * Return value: a pointer to the contents of the widget as a
6412 * string. This string points to internally allocated
6413 * storage in the widget and must not be freed, modified or
6416 G_CONST_RETURN gchar*
6417 gtk_entry_get_text (GtkEntry *entry)
6419 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
6425 * gtk_entry_select_region:
6426 * @entry: a #GtkEntry
6427 * @start: the starting position
6428 * @end: the end position
6430 * Selects a region of text. The characters that are selected are
6431 * those characters at positions from @start_pos up to, but not
6432 * including @end_pos. If @end_pos is negative, then the the characters
6433 * selected will be those characters from @start_pos to the end of
6436 * Deprecated: 2.0: Use gtk_editable_select_region() instead.
6439 gtk_entry_select_region (GtkEntry *entry,
6443 gtk_editable_select_region (GTK_EDITABLE (entry), start, end);
6447 * gtk_entry_set_max_length:
6448 * @entry: a #GtkEntry
6449 * @max: the maximum length of the entry, or 0 for no maximum.
6450 * (other than the maximum length of entries.) The value passed in will
6451 * be clamped to the range 0-65536.
6453 * Sets the maximum allowed length of the contents of the widget. If
6454 * the current contents are longer than the given length, then they
6455 * will be truncated to fit.
6458 gtk_entry_set_max_length (GtkEntry *entry,
6461 g_return_if_fail (GTK_IS_ENTRY (entry));
6463 max = CLAMP (max, 0, MAX_SIZE);
6465 if (max > 0 && entry->text_length > max)
6466 gtk_editable_delete_text (GTK_EDITABLE (entry), max, -1);
6468 entry->text_max_length = max;
6469 g_object_notify (G_OBJECT (entry), "max-length");
6473 * gtk_entry_get_max_length:
6474 * @entry: a #GtkEntry
6476 * Retrieves the maximum allowed length of the text in
6477 * @entry. See gtk_entry_set_max_length().
6479 * Return value: the maximum allowed number of characters
6480 * in #GtkEntry, or 0 if there is no maximum.
6483 gtk_entry_get_max_length (GtkEntry *entry)
6485 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
6487 return entry->text_max_length;
6491 * gtk_entry_get_text_length:
6492 * @entry: a #GtkEntry
6494 * Retrieves the current length of the text in
6497 * Return value: the current number of characters
6498 * in #GtkEntry, or 0 if there are none.
6503 gtk_entry_get_text_length (GtkEntry *entry)
6505 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
6507 return entry->text_length;
6511 * gtk_entry_set_activates_default:
6512 * @entry: a #GtkEntry
6513 * @setting: %TRUE to activate window's default widget on Enter keypress
6515 * If @setting is %TRUE, pressing Enter in the @entry will activate the default
6516 * widget for the window containing the entry. This usually means that
6517 * the dialog box containing the entry will be closed, since the default
6518 * widget is usually one of the dialog buttons.
6520 * (For experts: if @setting is %TRUE, the entry calls
6521 * gtk_window_activate_default() on the window containing the entry, in
6522 * the default handler for the #GtkWidget::activate signal.)
6525 gtk_entry_set_activates_default (GtkEntry *entry,
6528 g_return_if_fail (GTK_IS_ENTRY (entry));
6529 setting = setting != FALSE;
6531 if (setting != entry->activates_default)
6533 entry->activates_default = setting;
6534 g_object_notify (G_OBJECT (entry), "activates-default");
6539 * gtk_entry_get_activates_default:
6540 * @entry: a #GtkEntry
6542 * Retrieves the value set by gtk_entry_set_activates_default().
6544 * Return value: %TRUE if the entry will activate the default widget
6547 gtk_entry_get_activates_default (GtkEntry *entry)
6549 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
6551 return entry->activates_default;
6555 * gtk_entry_set_width_chars:
6556 * @entry: a #GtkEntry
6557 * @n_chars: width in chars
6559 * Changes the size request of the entry to be about the right size
6560 * for @n_chars characters. Note that it changes the size
6561 * <emphasis>request</emphasis>, the size can still be affected by
6562 * how you pack the widget into containers. If @n_chars is -1, the
6563 * size reverts to the default entry size.
6566 gtk_entry_set_width_chars (GtkEntry *entry,
6569 g_return_if_fail (GTK_IS_ENTRY (entry));
6571 if (entry->width_chars != n_chars)
6573 entry->width_chars = n_chars;
6574 g_object_notify (G_OBJECT (entry), "width-chars");
6575 gtk_widget_queue_resize (GTK_WIDGET (entry));
6580 * gtk_entry_get_width_chars:
6581 * @entry: a #GtkEntry
6583 * Gets the value set by gtk_entry_set_width_chars().
6585 * Return value: number of chars to request space for, or negative if unset
6588 gtk_entry_get_width_chars (GtkEntry *entry)
6590 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
6592 return entry->width_chars;
6596 * gtk_entry_set_has_frame:
6597 * @entry: a #GtkEntry
6598 * @setting: new value
6600 * Sets whether the entry has a beveled frame around it.
6603 gtk_entry_set_has_frame (GtkEntry *entry,
6606 g_return_if_fail (GTK_IS_ENTRY (entry));
6608 setting = (setting != FALSE);
6610 if (entry->has_frame == setting)
6613 gtk_widget_queue_resize (GTK_WIDGET (entry));
6614 entry->has_frame = setting;
6615 g_object_notify (G_OBJECT (entry), "has-frame");
6619 * gtk_entry_get_has_frame:
6620 * @entry: a #GtkEntry
6622 * Gets the value set by gtk_entry_set_has_frame().
6624 * Return value: whether the entry has a beveled frame
6627 gtk_entry_get_has_frame (GtkEntry *entry)
6629 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
6631 return entry->has_frame;
6635 * gtk_entry_set_inner_border:
6636 * @entry: a #GtkEntry
6637 * @border: a #GtkBorder, or %NULL
6639 * Sets %entry's inner-border property to %border, or clears it if %NULL
6640 * is passed. The inner-border is the area around the entry's text, but
6643 * If set, this property overrides the inner-border style property.
6644 * Overriding the style-provided border is useful when you want to do
6645 * in-place editing of some text in a canvas or list widget, where
6646 * pixel-exact positioning of the entry is important.
6651 gtk_entry_set_inner_border (GtkEntry *entry,
6652 const GtkBorder *border)
6654 g_return_if_fail (GTK_IS_ENTRY (entry));
6656 gtk_widget_queue_resize (GTK_WIDGET (entry));
6659 g_object_set_qdata_full (G_OBJECT (entry), quark_inner_border,
6660 gtk_border_copy (border),
6661 (GDestroyNotify) gtk_border_free);
6663 g_object_set_qdata (G_OBJECT (entry), quark_inner_border, NULL);
6665 g_object_notify (G_OBJECT (entry), "inner-border");
6669 * gtk_entry_get_inner_border:
6670 * @entry: a #GtkEntry
6672 * This function returns the entry's #GtkEntry:inner-border property. See
6673 * gtk_entry_set_inner_border() for more information.
6675 * Return value: the entry's #GtkBorder, or %NULL if none was set.
6679 G_CONST_RETURN GtkBorder *
6680 gtk_entry_get_inner_border (GtkEntry *entry)
6682 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
6684 return g_object_get_qdata (G_OBJECT (entry), quark_inner_border);
6688 * gtk_entry_get_layout:
6689 * @entry: a #GtkEntry
6691 * Gets the #PangoLayout used to display the entry.
6692 * The layout is useful to e.g. convert text positions to
6693 * pixel positions, in combination with gtk_entry_get_layout_offsets().
6694 * The returned layout is owned by the entry and must not be
6695 * modified or freed by the caller.
6697 * Keep in mind that the layout text may contain a preedit string, so
6698 * gtk_entry_layout_index_to_text_index() and
6699 * gtk_entry_text_index_to_layout_index() are needed to convert byte
6700 * indices in the layout to byte indices in the entry contents.
6702 * Return value: the #PangoLayout for this entry
6705 gtk_entry_get_layout (GtkEntry *entry)
6707 PangoLayout *layout;
6709 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
6711 layout = gtk_entry_ensure_layout (entry, TRUE);
6718 * gtk_entry_layout_index_to_text_index:
6719 * @entry: a #GtkEntry
6720 * @layout_index: byte index into the entry layout text
6722 * Converts from a position in the entry contents (returned
6723 * by gtk_entry_get_text()) to a position in the
6724 * entry's #PangoLayout (returned by gtk_entry_get_layout(),
6725 * with text retrieved via pango_layout_get_text()).
6727 * Return value: byte index into the entry contents
6730 gtk_entry_layout_index_to_text_index (GtkEntry *entry,
6733 PangoLayout *layout;
6737 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
6739 layout = gtk_entry_ensure_layout (entry, TRUE);
6740 text = pango_layout_get_text (layout);
6741 cursor_index = g_utf8_offset_to_pointer (text, entry->current_pos) - text;
6743 if (layout_index >= cursor_index && entry->preedit_length)
6745 if (layout_index >= cursor_index + entry->preedit_length)
6746 layout_index -= entry->preedit_length;
6748 layout_index = cursor_index;
6751 return layout_index;
6755 * gtk_entry_text_index_to_layout_index:
6756 * @entry: a #GtkEntry
6757 * @text_index: byte index into the entry contents
6759 * Converts from a position in the entry's #PangoLayout (returned by
6760 * gtk_entry_get_layout()) to a position in the entry contents
6761 * (returned by gtk_entry_get_text()).
6763 * Return value: byte index into the entry layout text
6766 gtk_entry_text_index_to_layout_index (GtkEntry *entry,
6769 PangoLayout *layout;
6772 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
6774 layout = gtk_entry_ensure_layout (entry, TRUE);
6775 text = pango_layout_get_text (layout);
6776 cursor_index = g_utf8_offset_to_pointer (text, entry->current_pos) - text;
6778 if (text_index > cursor_index)
6779 text_index += entry->preedit_length;
6785 * gtk_entry_get_layout_offsets:
6786 * @entry: a #GtkEntry
6787 * @x: location to store X offset of layout, or %NULL
6788 * @y: location to store Y offset of layout, or %NULL
6791 * Obtains the position of the #PangoLayout used to render text
6792 * in the entry, in widget coordinates. Useful if you want to line
6793 * up the text in an entry with some other text, e.g. when using the
6794 * entry to implement editable cells in a sheet widget.
6796 * Also useful to convert mouse events into coordinates inside the
6797 * #PangoLayout, e.g. to take some action if some part of the entry text
6800 * Note that as the user scrolls around in the entry the offsets will
6801 * change; you'll need to connect to the "notify::scroll-offset"
6802 * signal to track this. Remember when using the #PangoLayout
6803 * functions you need to convert to and from pixels using
6804 * PANGO_PIXELS() or #PANGO_SCALE.
6806 * Keep in mind that the layout text may contain a preedit string, so
6807 * gtk_entry_layout_index_to_text_index() and
6808 * gtk_entry_text_index_to_layout_index() are needed to convert byte
6809 * indices in the layout to byte indices in the entry contents.
6812 gtk_entry_get_layout_offsets (GtkEntry *entry,
6816 gint text_area_x, text_area_y;
6818 g_return_if_fail (GTK_IS_ENTRY (entry));
6820 /* this gets coords relative to text area */
6821 get_layout_position (entry, x, y);
6823 /* convert to widget coords */
6824 gtk_entry_get_text_area_size (entry, &text_area_x, &text_area_y, NULL, NULL);
6835 * gtk_entry_set_alignment:
6836 * @entry: a #GtkEntry
6837 * @xalign: The horizontal alignment, from 0 (left) to 1 (right).
6838 * Reversed for RTL layouts
6840 * Sets the alignment for the contents of the entry. This controls
6841 * the horizontal positioning of the contents when the displayed
6842 * text is shorter than the width of the entry.
6847 gtk_entry_set_alignment (GtkEntry *entry, gfloat xalign)
6849 GtkEntryPrivate *priv;
6851 g_return_if_fail (GTK_IS_ENTRY (entry));
6853 priv = GTK_ENTRY_GET_PRIVATE (entry);
6857 else if (xalign > 1.0)
6860 if (xalign != priv->xalign)
6862 priv->xalign = xalign;
6864 gtk_entry_recompute (entry);
6866 g_object_notify (G_OBJECT (entry), "xalign");
6871 * gtk_entry_get_alignment:
6872 * @entry: a #GtkEntry
6874 * Gets the value set by gtk_entry_set_alignment().
6876 * Return value: the alignment
6881 gtk_entry_get_alignment (GtkEntry *entry)
6883 GtkEntryPrivate *priv;
6885 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
6887 priv = GTK_ENTRY_GET_PRIVATE (entry);
6889 return priv->xalign;
6893 * gtk_entry_set_icon_from_pixbuf:
6894 * @entry: a #GtkEntry
6895 * @icon_pos: Icon position
6896 * @pixbuf: A #GdkPixbuf, or %NULL
6898 * Sets the icon shown in the specified position using a pixbuf.
6900 * If @pixbuf is %NULL, no icon will be shown in the specified position.
6905 gtk_entry_set_icon_from_pixbuf (GtkEntry *entry,
6906 GtkEntryIconPosition icon_pos,
6909 GtkEntryPrivate *priv;
6910 EntryIconInfo *icon_info;
6912 g_return_if_fail (GTK_IS_ENTRY (entry));
6913 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
6915 priv = GTK_ENTRY_GET_PRIVATE (entry);
6917 if (!(icon_info = priv->icons[icon_pos]))
6918 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
6920 g_object_freeze_notify (G_OBJECT (entry));
6923 g_object_ref (pixbuf);
6925 gtk_entry_clear (entry, icon_pos);
6929 icon_info->storage_type = GTK_IMAGE_PIXBUF;
6930 icon_info->pixbuf = pixbuf;
6932 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
6934 g_object_notify (G_OBJECT (entry), "pixbuf-primary");
6935 g_object_notify (G_OBJECT (entry), "storage-type-primary");
6939 g_object_notify (G_OBJECT (entry), "pixbuf-secondary");
6940 g_object_notify (G_OBJECT (entry), "storage-type-secondary");
6944 gtk_entry_ensure_pixbuf (entry, icon_pos);
6946 g_object_thaw_notify (G_OBJECT (entry));
6950 * gtk_entry_set_icon_from_stock:
6951 * @entry: A #GtkEntry
6952 * @icon_pos: Icon position
6953 * @stock_id: The name of the stock item, or %NULL
6955 * Sets the icon shown in the entry at the specified position from
6958 * If @stock_id is %NULL, no icon will be shown in the specified position.
6963 gtk_entry_set_icon_from_stock (GtkEntry *entry,
6964 GtkEntryIconPosition icon_pos,
6965 const gchar *stock_id)
6967 GtkEntryPrivate *priv;
6968 EntryIconInfo *icon_info;
6971 g_return_if_fail (GTK_IS_ENTRY (entry));
6972 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
6974 priv = GTK_ENTRY_GET_PRIVATE (entry);
6976 if (!(icon_info = priv->icons[icon_pos]))
6977 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
6979 g_object_freeze_notify (G_OBJECT (entry));
6981 gtk_widget_ensure_style (GTK_WIDGET (entry));
6983 /* need to dup before clearing */
6984 new_id = g_strdup (stock_id);
6986 gtk_entry_clear (entry, icon_pos);
6990 icon_info->storage_type = GTK_IMAGE_STOCK;
6991 icon_info->stock_id = new_id;
6993 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
6995 g_object_notify (G_OBJECT (entry), "stock-primary");
6996 g_object_notify (G_OBJECT (entry), "storage-type-primary");
7000 g_object_notify (G_OBJECT (entry), "stock-secondary");
7001 g_object_notify (G_OBJECT (entry), "storage-type-secondary");
7005 gtk_entry_ensure_pixbuf (entry, icon_pos);
7007 g_object_thaw_notify (G_OBJECT (entry));
7011 * gtk_entry_set_icon_from_icon_name:
7012 * @entry: A #GtkEntry
7013 * @icon_pos: The position at which to set the icon
7014 * @icon_name: An icon name, or %NULL
7016 * Sets the icon shown in the entry at the specified position
7017 * from the current icon theme.
7019 * If the icon name isn't known, a "broken image" icon will be displayed
7022 * If @icon_name is %NULL, no icon will be shown in the specified position.
7027 gtk_entry_set_icon_from_icon_name (GtkEntry *entry,
7028 GtkEntryIconPosition icon_pos,
7029 const gchar *icon_name)
7031 GtkEntryPrivate *priv;
7032 EntryIconInfo *icon_info;
7035 g_return_if_fail (GTK_IS_ENTRY (entry));
7036 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7038 priv = GTK_ENTRY_GET_PRIVATE (entry);
7040 if (!(icon_info = priv->icons[icon_pos]))
7041 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7043 g_object_freeze_notify (G_OBJECT (entry));
7045 gtk_widget_ensure_style (GTK_WIDGET (entry));
7047 /* need to dup before clearing */
7048 new_name = g_strdup (icon_name);
7050 gtk_entry_clear (entry, icon_pos);
7052 if (new_name != NULL)
7054 icon_info->storage_type = GTK_IMAGE_ICON_NAME;
7055 icon_info->icon_name = new_name;
7057 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7059 g_object_notify (G_OBJECT (entry), "icon-name-primary");
7060 g_object_notify (G_OBJECT (entry), "storage-type-primary");
7064 g_object_notify (G_OBJECT (entry), "icon-name-secondary");
7065 g_object_notify (G_OBJECT (entry), "storage-type-secondary");
7069 gtk_entry_ensure_pixbuf (entry, icon_pos);
7071 g_object_thaw_notify (G_OBJECT (entry));
7075 * gtk_entry_set_icon_from_gicon:
7076 * @entry: A #GtkEntry
7077 * @icon_pos: The position at which to set the icon
7078 * @icon: The icon to set, or %NULL
7080 * Sets the icon shown in the entry at the specified position
7081 * from the current icon theme.
7082 * If the icon isn't known, a "broken image" icon will be displayed
7085 * If @icon is %NULL, no icon will be shown in the specified position.
7090 gtk_entry_set_icon_from_gicon (GtkEntry *entry,
7091 GtkEntryIconPosition icon_pos,
7094 GtkEntryPrivate *priv;
7095 EntryIconInfo *icon_info;
7097 g_return_if_fail (GTK_IS_ENTRY (entry));
7098 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7100 priv = GTK_ENTRY_GET_PRIVATE (entry);
7102 if (!(icon_info = priv->icons[icon_pos]))
7103 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7105 g_object_freeze_notify (G_OBJECT (entry));
7107 /* need to ref before clearing */
7109 g_object_ref (icon);
7111 gtk_entry_clear (entry, icon_pos);
7115 icon_info->storage_type = GTK_IMAGE_GICON;
7116 icon_info->gicon = icon;
7118 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7120 g_object_notify (G_OBJECT (entry), "gicon-primary");
7121 g_object_notify (G_OBJECT (entry), "storage-type-primary");
7125 g_object_notify (G_OBJECT (entry), "gicon-secondary");
7126 g_object_notify (G_OBJECT (entry), "storage-type-secondary");
7130 gtk_entry_ensure_pixbuf (entry, icon_pos);
7132 g_object_thaw_notify (G_OBJECT (entry));
7136 * gtk_entry_set_icon_activatable:
7137 * @entry: A #GtkEntry
7138 * @icon_pos: Icon position
7139 * @activatable: %TRUE if the icon should be activatable
7141 * Sets whether the icon is activatable.
7146 gtk_entry_set_icon_activatable (GtkEntry *entry,
7147 GtkEntryIconPosition icon_pos,
7148 gboolean activatable)
7150 GtkEntryPrivate *priv;
7151 EntryIconInfo *icon_info;
7153 g_return_if_fail (GTK_IS_ENTRY (entry));
7154 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7156 priv = GTK_ENTRY_GET_PRIVATE (entry);
7158 if (!(icon_info = priv->icons[icon_pos]))
7159 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7161 activatable = activatable != FALSE;
7163 if (icon_info->nonactivatable != !activatable)
7165 icon_info->nonactivatable = !activatable;
7167 if (GTK_WIDGET_REALIZED (GTK_WIDGET (entry)))
7168 update_cursors (GTK_WIDGET (entry));
7170 g_object_notify (G_OBJECT (entry),
7171 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "activatable-primary" : "activatable-secondary");
7176 * gtk_entry_get_icon_activtable:
7177 * @entry: a #GtkEntry
7178 * @icon_pos: Icon position
7180 * Returns whether the icon is activatable.
7182 * Returns: %TRUE if the icon is activatable.
7187 gtk_entry_get_icon_activatable (GtkEntry *entry,
7188 GtkEntryIconPosition icon_pos)
7190 GtkEntryPrivate *priv;
7191 EntryIconInfo *icon_info;
7193 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7194 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), FALSE);
7196 priv = GTK_ENTRY_GET_PRIVATE (entry);
7197 icon_info = priv->icons[icon_pos];
7199 return (icon_info != NULL && !icon_info->nonactivatable);
7203 * gtk_entry_get_pixbuf:
7204 * @entry: A #GtkEntry
7205 * @icon_pos: Icon position
7207 * Retrieves the image used for the icon.
7209 * Unlike the other methods of setting and getting icon data, this
7210 * method will work regardless of whether the icon was set using a
7211 * #GdkPixbuf, a #GIcon, a stock item, or an icon name.
7213 * Returns: A #GdkPixbuf, or %NULL if no icon is set for this position.
7218 gtk_entry_get_pixbuf (GtkEntry *entry,
7219 GtkEntryIconPosition icon_pos)
7221 GtkEntryPrivate *priv;
7222 EntryIconInfo *icon_info;
7224 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7225 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7227 priv = GTK_ENTRY_GET_PRIVATE (entry);
7228 icon_info = priv->icons[icon_pos];
7233 gtk_entry_ensure_pixbuf (entry, icon_pos);
7235 return icon_info->pixbuf;
7239 * gtk_entry_get_gicon:
7240 * @entry: A #GtkEntry
7241 * @icon_pos: Icon position
7243 * Retrieves the #GIcon used for the icon, or %NULL if there is
7244 * no icon or if the icon was set by some other method (e.g., by
7245 * stock, pixbuf, or icon name).
7247 * Returns: A #GIcon, or %NULL if no icon is set or if the icon
7253 gtk_entry_get_gicon (GtkEntry *entry,
7254 GtkEntryIconPosition icon_pos)
7256 GtkEntryPrivate *priv;
7257 EntryIconInfo *icon_info;
7259 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7260 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7262 priv = GTK_ENTRY_GET_PRIVATE (entry);
7263 icon_info = priv->icons[icon_pos];
7268 return icon_info->storage_type == GTK_IMAGE_GICON ? icon_info->gicon : NULL;
7272 * gtk_entry_get_stock:
7273 * @entry: A #GtkEntry
7274 * @icon_pos: Icon position
7276 * Retrieves the stock id used for the icon, or %NULL if there is
7277 * no icon or if the icon was set by some other method (e.g., by
7278 * pixbuf, icon name or gicon).
7280 * Returns: A stock id, or %NULL if no icon is set or if the icon
7281 * wasn't set from a stock id
7286 gtk_entry_get_stock (GtkEntry *entry,
7287 GtkEntryIconPosition icon_pos)
7289 GtkEntryPrivate *priv;
7290 EntryIconInfo *icon_info;
7292 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7293 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7295 priv = GTK_ENTRY_GET_PRIVATE (entry);
7296 icon_info = priv->icons[icon_pos];
7301 return icon_info->storage_type == GTK_IMAGE_STOCK ? icon_info->stock_id : NULL;
7305 * gtk_entry_get_icon_name:
7306 * @entry: A #GtkEntry
7307 * @icon_pos: Icon position
7309 * Retrieves the icon name used for the icon, or %NULL if there is
7310 * no icon or if the icon was set by some other method (e.g., by
7311 * pixbuf, stock or gicon).
7313 * Returns: An icon name, or %NULL if no icon is set or if the icon
7314 * wasn't set from an icon name
7319 gtk_entry_get_icon_name (GtkEntry *entry,
7320 GtkEntryIconPosition icon_pos)
7322 GtkEntryPrivate *priv;
7323 EntryIconInfo *icon_info;
7325 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7326 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7328 priv = GTK_ENTRY_GET_PRIVATE (entry);
7329 icon_info = priv->icons[icon_pos];
7334 return icon_info->storage_type == GTK_IMAGE_ICON_NAME ? icon_info->icon_name : NULL;
7338 * gtk_entry_set_icon_sensitive:
7339 * @entry: A #GtkEntry
7340 * @icon_pos: Icon position
7341 * @sensitive: Specifies whether the icon should appear
7342 * sensitive or insensitive
7344 * Sets the sensitivity for the specified icon.
7349 gtk_entry_set_icon_sensitive (GtkEntry *entry,
7350 GtkEntryIconPosition icon_pos,
7353 GtkEntryPrivate *priv;
7354 EntryIconInfo *icon_info;
7356 g_return_if_fail (GTK_IS_ENTRY (entry));
7357 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7359 priv = GTK_ENTRY_GET_PRIVATE (entry);
7361 if (!(icon_info = priv->icons[icon_pos]))
7362 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7364 if (icon_info->insensitive != !sensitive)
7366 icon_info->insensitive = !sensitive;
7368 if (GTK_WIDGET_REALIZED (GTK_WIDGET (entry)))
7369 update_cursors (GTK_WIDGET (entry));
7371 g_object_notify (G_OBJECT (entry),
7372 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "sensitive-primary" : "sensitive-secondary");
7377 * gtk_entry_get_icon_sensitive:
7378 * @entry: a #GtkEntry
7379 * @icon_pos: Icon position
7381 * Returns whether the icon appears sensitive or insensitive.
7383 * Returns: %TRUE if the icon is sensitive.
7388 gtk_entry_get_icon_sensitive (GtkEntry *entry,
7389 GtkEntryIconPosition icon_pos)
7391 GtkEntryPrivate *priv;
7392 EntryIconInfo *icon_info;
7394 g_return_val_if_fail (GTK_IS_ENTRY (entry), TRUE);
7395 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), TRUE);
7397 priv = GTK_ENTRY_GET_PRIVATE (entry);
7398 icon_info = priv->icons[icon_pos];
7400 return (icon_info != NULL && !icon_info->insensitive);
7404 * gtk_entry_get_storage_type:
7405 * @image: a #GtkImage
7407 * Gets the type of representation being used by the icon
7408 * to store image data. If the icon has no image data,
7409 * the return value will be %GTK_IMAGE_EMPTY.
7411 * Return value: image representation being used
7416 gtk_entry_get_storage_type (GtkEntry *entry,
7417 GtkEntryIconPosition icon_pos)
7419 GtkEntryPrivate *priv;
7420 EntryIconInfo *icon_info;
7422 g_return_val_if_fail (GTK_IS_ENTRY (entry), GTK_IMAGE_EMPTY);
7423 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), GTK_IMAGE_EMPTY);
7425 priv = GTK_ENTRY_GET_PRIVATE (entry);
7426 icon_info = priv->icons[icon_pos];
7429 return GTK_IMAGE_EMPTY;
7431 return icon_info->storage_type;
7435 * gtk_entry_get_icon_at_pos:
7436 * @entry: a #GtkEntry
7437 * @x: the x coordinate of the position to find
7438 * @y: the y coordinate of the position to find
7440 * Finds the icon at the given position and return its index.
7441 * If @x, @y doesn't lie inside an icon, -1 is returned.
7442 * This function is intended for use in a #GtkWidget::query-tooltip
7445 * Returns: the index of the icon at the given position, or -1
7450 gtk_entry_get_icon_at_pos (GtkEntry *entry,
7454 GtkEntryPrivate *priv;
7455 GtkEntryIconPosition left_icon_pos;
7456 GtkEntryIconPosition right_icon_pos;
7457 GtkAllocation left_icon_alloc;
7458 GtkAllocation right_icon_alloc;
7459 GtkAllocation text_area_alloc;
7460 GtkAllocation *widget_alloc;
7462 g_return_val_if_fail (GTK_IS_ENTRY (entry), -1);
7464 priv = GTK_ENTRY_GET_PRIVATE (entry);
7466 widget_alloc = >K_WIDGET (entry)->allocation;
7468 get_text_area_size (entry, &text_area_alloc);
7469 get_icon_allocation (entry, TRUE, widget_alloc, &text_area_alloc,
7470 &left_icon_alloc, &left_icon_pos);
7471 get_icon_allocation (entry, FALSE, widget_alloc, &text_area_alloc,
7472 &right_icon_alloc, &right_icon_pos);
7474 if (left_icon_alloc.width > 0)
7475 text_area_alloc.x = left_icon_alloc.x + left_icon_alloc.width + priv->icon_margin;
7477 if (right_icon_alloc.width > 0)
7478 text_area_alloc.width -= right_icon_alloc.width + priv->icon_margin;
7480 text_area_alloc.width -= text_area_alloc.x;
7482 if (left_icon_alloc.x <= x &&
7483 left_icon_alloc.y <= y &&
7484 x < left_icon_alloc.x + left_icon_alloc.width &&
7485 y < left_icon_alloc.y + left_icon_alloc.height)
7486 return left_icon_pos;
7488 if (right_icon_alloc.x <= x &&
7489 right_icon_alloc.y <= y &&
7490 x < right_icon_alloc.x + right_icon_alloc.width &&
7491 y < right_icon_alloc.y + right_icon_alloc.height)
7492 return right_icon_pos;
7498 * gtk_entry_set_icon_drag_source:
7499 * @entry: a #GtkIconEntry
7500 * @icon_pos: icon position
7501 * @target_list: the targets (data formats) in which the data can be provided
7502 * @actions: a bitmask of the allowed drag actions
7504 * Sets up the icon at the given position so that GTK+ will start a drag
7505 * operation when the user clicks and drags the icon.
7507 * To handle the drag operation, you need to connect to the usual
7508 * #GtkWidget::drag-data-get (or possibly #GtkWidget::drag-data-delete)
7509 * signal, and use gtk_icon_entry_get_current_icon_drag_source() in
7510 * your signal handler to find out if the drag was started from
7514 gtk_entry_set_icon_drag_source (GtkEntry *entry,
7515 GtkEntryIconPosition icon_pos,
7516 GtkTargetList *target_list,
7517 GdkDragAction actions)
7519 GtkEntryPrivate *priv;
7520 EntryIconInfo *icon_info;
7522 g_return_if_fail (GTK_IS_ENTRY (entry));
7523 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7525 priv = GTK_ENTRY_GET_PRIVATE (entry);
7527 if (!(icon_info = priv->icons[icon_pos]))
7528 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7530 if (icon_info->target_list)
7531 gtk_target_list_unref (icon_info->target_list);
7532 icon_info->target_list = target_list;
7533 if (icon_info->target_list)
7534 gtk_target_list_ref (icon_info->target_list);
7536 icon_info->actions = actions;
7540 * gtk_entry_get_current_icon_drag_source:
7541 * @entry: a #GtkIconEntry
7543 * Returns the index of the icon which is the source of the current
7544 * DND operation, or -1.
7546 * This function is meant to be used in a #GtkWidget::drag-data-get
7549 * Returns: index of the icon which is the source of the current
7550 * DND operation, or -1.
7553 gtk_entry_get_current_icon_drag_source (GtkEntry *entry)
7555 GtkEntryPrivate *priv;
7556 EntryIconInfo *icon_info = NULL;
7559 g_return_val_if_fail (GTK_IS_ENTRY (entry), -1);
7561 priv = GTK_ENTRY_GET_PRIVATE (entry);
7563 for (i = 0; i < MAX_ICONS; i++)
7565 if ((icon_info = priv->icons[i]))
7567 if (icon_info->in_drag)
7576 ensure_has_tooltip (GtkEntry *entry)
7578 GtkEntryPrivate *priv;
7579 EntryIconInfo *icon_info;
7581 gboolean has_tooltip = FALSE;
7583 priv = GTK_ENTRY_GET_PRIVATE (entry);
7585 for (i = 0; i < MAX_ICONS; i++)
7587 if ((icon_info = priv->icons[i]) != NULL)
7589 if (icon_info->tooltip != NULL)
7597 gtk_widget_set_has_tooltip (GTK_WIDGET (entry), has_tooltip);
7601 * gtk_entry_set_icon_tooltip_text:
7602 * @entry: a #GtkEntry
7603 * @icon_pos: the icon position
7604 * @tooltip: the contents of the tooltip for the icon, or %NULL
7606 * Sets @tooltip as the contents of the tooltip for the icon
7607 * at the specified position.
7609 * Use %NULL for @tooltip to remove an existing tooltip.
7611 * See also gtk_widget_set_tooltip_text() and
7612 * gtk_entry_set_icon_tooltip_markup().
7617 gtk_entry_set_icon_tooltip_text (GtkEntry *entry,
7618 GtkEntryIconPosition icon_pos,
7619 const gchar *tooltip)
7621 GtkEntryPrivate *priv;
7622 EntryIconInfo *icon_info;
7624 g_return_if_fail (GTK_IS_ENTRY (entry));
7625 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7627 priv = GTK_ENTRY_GET_PRIVATE (entry);
7629 if (!(icon_info = priv->icons[icon_pos]))
7630 icon_info = priv->icons[icon_pos];
7632 if (icon_info->tooltip)
7633 g_free (icon_info->tooltip);
7635 icon_info->tooltip = tooltip ? g_markup_escape_text (tooltip, -1) : NULL;
7637 ensure_has_tooltip (entry);
7641 * gtk_entry_set_icon_tooltip_markup:
7642 * @entry: a #GtkEntry
7643 * @icon_pos: the icon position
7644 * @tooltip: the contents of the tooltip for the icon, or %NULL
7646 * Sets @tooltip as the contents of the tooltip for the icon at
7647 * the specified position. @tooltip is assumed to be marked up with
7648 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
7650 * Use %NULL for @tooltip to remove an existing tooltip.
7652 * See also gtk_widget_set_tooltip_markup() and
7653 * gtk_enty_set_icon_tooltip_text().
7658 gtk_entry_set_icon_tooltip_markup (GtkEntry *entry,
7659 GtkEntryIconPosition icon_pos,
7660 const gchar *tooltip)
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]))
7671 icon_info = priv->icons[icon_pos];
7673 if (icon_info->tooltip)
7674 g_free (icon_info->tooltip);
7676 icon_info->tooltip = g_strdup (tooltip);
7678 ensure_has_tooltip (entry);
7682 gtk_entry_query_tooltip (GtkWidget *widget,
7685 gboolean keyboard_tip,
7686 GtkTooltip *tooltip)
7689 GtkEntryPrivate *priv;
7690 EntryIconInfo *icon_info;
7693 entry = GTK_ENTRY (widget);
7694 priv = GTK_ENTRY_GET_PRIVATE (entry);
7698 icon_pos = gtk_entry_get_icon_at_pos (entry, x, y);
7701 if ((icon_info = priv->icons[icon_pos]) != NULL)
7703 if (icon_info->tooltip)
7705 gtk_tooltip_set_markup (tooltip, icon_info->tooltip);
7714 return GTK_WIDGET_CLASS (gtk_entry_parent_class)->query_tooltip (widget,
7721 /* Quick hack of a popup menu
7724 activate_cb (GtkWidget *menuitem,
7727 const gchar *signal = g_object_get_data (G_OBJECT (menuitem), "gtk-signal");
7728 g_signal_emit_by_name (entry, signal);
7733 gtk_entry_mnemonic_activate (GtkWidget *widget,
7734 gboolean group_cycling)
7736 gtk_widget_grab_focus (widget);
7741 append_action_signal (GtkEntry *entry,
7743 const gchar *stock_id,
7744 const gchar *signal,
7747 GtkWidget *menuitem = gtk_image_menu_item_new_from_stock (stock_id, NULL);
7749 g_object_set_data (G_OBJECT (menuitem), I_("gtk-signal"), (char *)signal);
7750 g_signal_connect (menuitem, "activate",
7751 G_CALLBACK (activate_cb), entry);
7753 gtk_widget_set_sensitive (menuitem, sensitive);
7755 gtk_widget_show (menuitem);
7756 gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
7760 popup_menu_detach (GtkWidget *attach_widget,
7763 GTK_ENTRY (attach_widget)->popup_menu = NULL;
7767 popup_position_func (GtkMenu *menu,
7773 GtkEntry *entry = GTK_ENTRY (user_data);
7774 GtkWidget *widget = GTK_WIDGET (entry);
7776 GtkRequisition menu_req;
7777 GdkRectangle monitor;
7778 GtkBorder inner_border;
7779 gint monitor_num, strong_x, height;
7781 g_return_if_fail (GTK_WIDGET_REALIZED (entry));
7783 gdk_window_get_origin (entry->text_area, x, y);
7785 screen = gtk_widget_get_screen (widget);
7786 monitor_num = gdk_screen_get_monitor_at_window (screen, entry->text_area);
7787 if (monitor_num < 0)
7789 gtk_menu_set_monitor (menu, monitor_num);
7791 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
7792 gtk_widget_size_request (entry->popup_menu, &menu_req);
7793 gdk_drawable_get_size (entry->text_area, NULL, &height);
7794 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
7795 _gtk_entry_effective_inner_border (entry, &inner_border);
7797 *x += inner_border.left + strong_x - entry->scroll_offset;
7798 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
7799 *x -= menu_req.width;
7801 if ((*y + height + menu_req.height) <= monitor.y + monitor.height)
7803 else if ((*y - menu_req.height) >= monitor.y)
7804 *y -= menu_req.height;
7805 else if (monitor.y + monitor.height - (*y + height) > *y)
7808 *y -= menu_req.height;
7814 unichar_chosen_func (const char *text,
7817 GtkEntry *entry = GTK_ENTRY (data);
7819 if (entry->editable)
7820 gtk_entry_enter_text (entry, text);
7831 popup_targets_received (GtkClipboard *clipboard,
7832 GtkSelectionData *data,
7835 PopupInfo *info = user_data;
7836 GtkEntry *entry = info->entry;
7838 if (GTK_WIDGET_REALIZED (entry))
7840 gboolean clipboard_contains_text;
7841 GtkWidget *menuitem;
7843 gboolean show_input_method_menu;
7844 gboolean show_unicode_menu;
7846 clipboard_contains_text = gtk_selection_data_targets_include_text (data);
7847 if (entry->popup_menu)
7848 gtk_widget_destroy (entry->popup_menu);
7850 entry->popup_menu = gtk_menu_new ();
7852 gtk_menu_attach_to_widget (GTK_MENU (entry->popup_menu),
7856 append_action_signal (entry, entry->popup_menu, GTK_STOCK_CUT, "cut-clipboard",
7857 entry->editable && entry->visible && entry->current_pos != entry->selection_bound);
7858 append_action_signal (entry, entry->popup_menu, GTK_STOCK_COPY, "copy-clipboard",
7859 entry->visible && entry->current_pos != entry->selection_bound);
7860 append_action_signal (entry, entry->popup_menu, GTK_STOCK_PASTE, "paste-clipboard",
7861 entry->editable && clipboard_contains_text);
7863 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_DELETE, NULL);
7864 gtk_widget_set_sensitive (menuitem, entry->editable && entry->current_pos != entry->selection_bound);
7865 g_signal_connect_swapped (menuitem, "activate",
7866 G_CALLBACK (gtk_entry_delete_cb), entry);
7867 gtk_widget_show (menuitem);
7868 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
7870 menuitem = gtk_separator_menu_item_new ();
7871 gtk_widget_show (menuitem);
7872 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
7874 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_SELECT_ALL, NULL);
7875 g_signal_connect_swapped (menuitem, "activate",
7876 G_CALLBACK (gtk_entry_select_all), entry);
7877 gtk_widget_show (menuitem);
7878 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
7880 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
7881 "gtk-show-input-method-menu", &show_input_method_menu,
7882 "gtk-show-unicode-menu", &show_unicode_menu,
7885 if (show_input_method_menu || show_unicode_menu)
7887 menuitem = gtk_separator_menu_item_new ();
7888 gtk_widget_show (menuitem);
7889 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
7892 if (show_input_method_menu)
7894 menuitem = gtk_menu_item_new_with_mnemonic (_("Input _Methods"));
7895 gtk_widget_set_sensitive (menuitem, entry->editable);
7896 gtk_widget_show (menuitem);
7897 submenu = gtk_menu_new ();
7898 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
7900 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
7902 gtk_im_multicontext_append_menuitems (GTK_IM_MULTICONTEXT (entry->im_context),
7903 GTK_MENU_SHELL (submenu));
7906 if (show_unicode_menu)
7908 menuitem = gtk_menu_item_new_with_mnemonic (_("_Insert Unicode Control Character"));
7909 gtk_widget_set_sensitive (menuitem, entry->editable);
7910 gtk_widget_show (menuitem);
7912 submenu = gtk_menu_new ();
7913 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
7914 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
7916 _gtk_text_util_append_special_char_menuitems (GTK_MENU_SHELL (submenu),
7917 unichar_chosen_func,
7921 g_signal_emit (entry,
7922 signals[POPULATE_POPUP],
7928 gtk_menu_popup (GTK_MENU (entry->popup_menu), NULL, NULL,
7930 info->button, info->time);
7933 gtk_menu_popup (GTK_MENU (entry->popup_menu), NULL, NULL,
7934 popup_position_func, entry,
7935 info->button, info->time);
7936 gtk_menu_shell_select_first (GTK_MENU_SHELL (entry->popup_menu), FALSE);
7940 g_object_unref (entry);
7941 g_slice_free (PopupInfo, info);
7945 gtk_entry_do_popup (GtkEntry *entry,
7946 GdkEventButton *event)
7948 PopupInfo *info = g_slice_new (PopupInfo);
7950 /* In order to know what entries we should make sensitive, we
7951 * ask for the current targets of the clipboard, and when
7952 * we get them, then we actually pop up the menu.
7954 info->entry = g_object_ref (entry);
7958 info->button = event->button;
7959 info->time = event->time;
7964 info->time = gtk_get_current_event_time ();
7967 gtk_clipboard_request_contents (gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_CLIPBOARD),
7968 gdk_atom_intern_static_string ("TARGETS"),
7969 popup_targets_received,
7974 gtk_entry_popup_menu (GtkWidget *widget)
7976 gtk_entry_do_popup (GTK_ENTRY (widget), NULL);
7981 gtk_entry_drag_begin (GtkWidget *widget,
7982 GdkDragContext *context)
7984 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
7985 EntryIconInfo *icon_info;
7988 for (i = 0; i < MAX_ICONS; i++)
7990 if ((icon_info = priv->icons[i]) != NULL)
7992 if (icon_info->in_drag)
7994 switch (icon_info->storage_type)
7996 case GTK_IMAGE_STOCK:
7997 gtk_drag_set_icon_stock (context, icon_info->stock_id, -2, -2);
8000 case GTK_IMAGE_ICON_NAME:
8001 gtk_drag_set_icon_name (context, icon_info->icon_name, -2, -2);
8004 /* FIXME: No GIcon support for dnd icons */
8005 case GTK_IMAGE_GICON:
8006 case GTK_IMAGE_PIXBUF:
8007 gtk_drag_set_icon_pixbuf (context, icon_info->pixbuf, -2, -2);
8010 g_assert_not_reached ();
8018 gtk_entry_drag_end (GtkWidget *widget,
8019 GdkDragContext *context)
8021 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
8024 for (i = 0; i < MAX_ICONS; i++)
8026 EntryIconInfo *icon_info;
8028 if ((icon_info = priv->icons[i]) != NULL)
8029 icon_info->in_drag = 0;
8034 gtk_entry_drag_leave (GtkWidget *widget,
8035 GdkDragContext *context,
8038 GtkEntry *entry = GTK_ENTRY (widget);
8040 entry->dnd_position = -1;
8041 gtk_widget_queue_draw (widget);
8045 gtk_entry_drag_drop (GtkWidget *widget,
8046 GdkDragContext *context,
8051 GtkEntry *entry = GTK_ENTRY (widget);
8052 GdkAtom target = GDK_NONE;
8054 if (entry->editable)
8055 target = gtk_drag_dest_find_target (widget, context, NULL);
8057 if (target != GDK_NONE)
8058 gtk_drag_get_data (widget, context, target, time);
8060 gtk_drag_finish (context, FALSE, FALSE, time);
8066 gtk_entry_drag_motion (GtkWidget *widget,
8067 GdkDragContext *context,
8072 GtkEntry *entry = GTK_ENTRY (widget);
8073 GtkWidget *source_widget;
8074 GdkDragAction suggested_action;
8075 gint new_position, old_position;
8078 x -= widget->style->xthickness;
8079 y -= widget->style->ythickness;
8081 old_position = entry->dnd_position;
8082 new_position = gtk_entry_find_position (entry, x + entry->scroll_offset);
8084 if (entry->editable &&
8085 gtk_drag_dest_find_target (widget, context, NULL) != GDK_NONE)
8087 source_widget = gtk_drag_get_source_widget (context);
8088 suggested_action = context->suggested_action;
8090 if (!gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &sel1, &sel2) ||
8091 new_position < sel1 || new_position > sel2)
8093 if (source_widget == widget)
8095 /* Default to MOVE, unless the user has
8096 * pressed ctrl or alt to affect available actions
8098 if ((context->actions & GDK_ACTION_MOVE) != 0)
8099 suggested_action = GDK_ACTION_MOVE;
8102 entry->dnd_position = new_position;
8106 if (source_widget == widget)
8107 suggested_action = 0; /* Can't drop in selection where drag started */
8109 entry->dnd_position = -1;
8114 /* Entry not editable, or no text */
8115 suggested_action = 0;
8116 entry->dnd_position = -1;
8119 gdk_drag_status (context, suggested_action, time);
8121 if (entry->dnd_position != old_position)
8122 gtk_widget_queue_draw (widget);
8128 gtk_entry_drag_data_received (GtkWidget *widget,
8129 GdkDragContext *context,
8132 GtkSelectionData *selection_data,
8136 GtkEntry *entry = GTK_ENTRY (widget);
8137 GtkEditable *editable = GTK_EDITABLE (widget);
8140 str = (gchar *) gtk_selection_data_get_text (selection_data);
8142 x -= widget->style->xthickness;
8143 y -= widget->style->ythickness;
8145 if (str && entry->editable)
8151 if (entry->truncate_multiline)
8152 length = truncate_multiline (str);
8154 new_position = gtk_entry_find_position (entry, x + entry->scroll_offset);
8156 if (!gtk_editable_get_selection_bounds (editable, &sel1, &sel2) ||
8157 new_position < sel1 || new_position > sel2)
8159 gtk_editable_insert_text (editable, str, length, &new_position);
8163 /* Replacing selection */
8164 begin_change (entry);
8165 g_object_freeze_notify (G_OBJECT (entry));
8166 gtk_editable_delete_text (editable, sel1, sel2);
8167 gtk_editable_insert_text (editable, str, length, &sel1);
8168 g_object_thaw_notify (G_OBJECT (entry));
8172 gtk_drag_finish (context, TRUE, context->action == GDK_ACTION_MOVE, time);
8176 /* Drag and drop didn't happen! */
8177 gtk_drag_finish (context, FALSE, FALSE, time);
8184 gtk_entry_drag_data_get (GtkWidget *widget,
8185 GdkDragContext *context,
8186 GtkSelectionData *selection_data,
8190 gint sel_start, sel_end;
8193 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
8194 GtkEditable *editable = GTK_EDITABLE (widget);
8195 EntryIconInfo *icon_info = NULL;
8197 /* If there is an icon drag going on, exit early. */
8198 for (i = 0; i < MAX_ICONS; i++)
8200 if ((icon_info = priv->icons[i]) != NULL)
8202 if (icon_info->in_drag)
8207 if (gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end))
8209 gchar *str = gtk_entry_get_public_chars (GTK_ENTRY (widget), sel_start, sel_end);
8211 gtk_selection_data_set_text (selection_data, str, -1);
8219 gtk_entry_drag_data_delete (GtkWidget *widget,
8220 GdkDragContext *context)
8222 gint sel_start, sel_end;
8225 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
8226 GtkEditable *editable = GTK_EDITABLE (widget);
8227 EntryIconInfo *icon_info = NULL;
8229 /* If there is an icon drag going on, exit early. */
8230 for (i = 0; i < MAX_ICONS; i++)
8232 if ((icon_info = priv->icons[i]) != NULL)
8234 if (icon_info->in_drag)
8239 if (GTK_ENTRY (widget)->editable &&
8240 gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end))
8241 gtk_editable_delete_text (editable, sel_start, sel_end);
8244 /* We display the cursor when
8246 * - the selection is empty, AND
8247 * - the widget has focus
8250 #define CURSOR_ON_MULTIPLIER 2
8251 #define CURSOR_OFF_MULTIPLIER 1
8252 #define CURSOR_PEND_MULTIPLIER 3
8253 #define CURSOR_DIVIDER 3
8256 cursor_blinks (GtkEntry *entry)
8258 if (GTK_WIDGET_HAS_FOCUS (entry) &&
8260 entry->selection_bound == entry->current_pos)
8262 GtkSettings *settings;
8265 settings = gtk_widget_get_settings (GTK_WIDGET (entry));
8266 g_object_get (settings, "gtk-cursor-blink", &blink, NULL);
8275 get_cursor_time (GtkEntry *entry)
8277 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (entry));
8280 g_object_get (settings, "gtk-cursor-blink-time", &time, NULL);
8286 get_cursor_blink_timeout (GtkEntry *entry)
8288 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (entry));
8291 g_object_get (settings, "gtk-cursor-blink-timeout", &timeout, NULL);
8297 show_cursor (GtkEntry *entry)
8299 if (!entry->cursor_visible)
8301 entry->cursor_visible = TRUE;
8303 if (GTK_WIDGET_HAS_FOCUS (entry) && entry->selection_bound == entry->current_pos)
8304 gtk_widget_queue_draw (GTK_WIDGET (entry));
8309 hide_cursor (GtkEntry *entry)
8311 if (entry->cursor_visible)
8313 entry->cursor_visible = FALSE;
8315 if (GTK_WIDGET_HAS_FOCUS (entry) && entry->selection_bound == entry->current_pos)
8316 gtk_widget_queue_draw (GTK_WIDGET (entry));
8324 blink_cb (gpointer data)
8327 GtkEntryPrivate *priv;
8330 entry = GTK_ENTRY (data);
8331 priv = GTK_ENTRY_GET_PRIVATE (entry);
8333 if (!GTK_WIDGET_HAS_FOCUS (entry))
8335 g_warning ("GtkEntry - did not receive focus-out-event. If you\n"
8336 "connect a handler to this signal, it must return\n"
8337 "FALSE so the entry gets the event as well");
8339 gtk_entry_check_cursor_blink (entry);
8344 g_assert (entry->selection_bound == entry->current_pos);
8346 blink_timeout = get_cursor_blink_timeout (entry);
8347 if (priv->blink_time > 1000 * blink_timeout &&
8348 blink_timeout < G_MAXINT/1000)
8350 /* we've blinked enough without the user doing anything, stop blinking */
8351 show_cursor (entry);
8352 entry->blink_timeout = 0;
8354 else if (entry->cursor_visible)
8356 hide_cursor (entry);
8357 entry->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_OFF_MULTIPLIER / CURSOR_DIVIDER,
8363 show_cursor (entry);
8364 priv->blink_time += get_cursor_time (entry);
8365 entry->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
8370 /* Remove ourselves */
8375 gtk_entry_check_cursor_blink (GtkEntry *entry)
8377 GtkEntryPrivate *priv;
8379 priv = GTK_ENTRY_GET_PRIVATE (entry);
8381 if (cursor_blinks (entry))
8383 if (!entry->blink_timeout)
8385 show_cursor (entry);
8386 entry->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
8393 if (entry->blink_timeout)
8395 g_source_remove (entry->blink_timeout);
8396 entry->blink_timeout = 0;
8399 entry->cursor_visible = TRUE;
8405 gtk_entry_pend_cursor_blink (GtkEntry *entry)
8407 if (cursor_blinks (entry))
8409 if (entry->blink_timeout != 0)
8410 g_source_remove (entry->blink_timeout);
8412 entry->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_PEND_MULTIPLIER / CURSOR_DIVIDER,
8415 show_cursor (entry);
8420 gtk_entry_reset_blink_time (GtkEntry *entry)
8422 GtkEntryPrivate *priv;
8424 priv = GTK_ENTRY_GET_PRIVATE (entry);
8426 priv->blink_time = 0;
8432 gtk_entry_completion_timeout (gpointer data)
8434 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (data);
8436 completion->priv->completion_timeout = 0;
8438 if (completion->priv->filter_model &&
8439 g_utf8_strlen (gtk_entry_get_text (GTK_ENTRY (completion->priv->entry)), -1)
8440 >= completion->priv->minimum_key_length)
8444 GtkTreeSelection *s;
8445 gboolean popup_single;
8447 gtk_entry_completion_complete (completion);
8448 matches = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->filter_model), NULL);
8450 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
8452 s = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view));
8454 gtk_tree_selection_unselect_all (s);
8456 actions = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->actions), NULL);
8458 g_object_get (completion, "popup-single-match", &popup_single, NULL);
8459 if ((matches > (popup_single ? 0: 1)) || actions > 0)
8461 if (GTK_WIDGET_VISIBLE (completion->priv->popup_window))
8462 _gtk_entry_completion_resize_popup (completion);
8464 _gtk_entry_completion_popup (completion);
8467 _gtk_entry_completion_popdown (completion);
8469 else if (GTK_WIDGET_VISIBLE (completion->priv->popup_window))
8470 _gtk_entry_completion_popdown (completion);
8475 static inline gboolean
8476 keyval_is_cursor_move (guint keyval)
8478 if (keyval == GDK_Up || keyval == GDK_KP_Up)
8481 if (keyval == GDK_Down || keyval == GDK_KP_Down)
8484 if (keyval == GDK_Page_Up)
8487 if (keyval == GDK_Page_Down)
8494 gtk_entry_completion_key_press (GtkWidget *widget,
8498 gint matches, actions = 0;
8499 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
8501 if (!GTK_WIDGET_MAPPED (completion->priv->popup_window))
8504 matches = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->filter_model), NULL);
8506 if (completion->priv->actions)
8507 actions = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->actions), NULL);
8509 if (keyval_is_cursor_move (event->keyval))
8511 GtkTreePath *path = NULL;
8513 if (event->keyval == GDK_Up || event->keyval == GDK_KP_Up)
8515 if (completion->priv->current_selected < 0)
8516 completion->priv->current_selected = matches + actions - 1;
8518 completion->priv->current_selected--;
8520 else if (event->keyval == GDK_Down || event->keyval == GDK_KP_Down)
8522 if (completion->priv->current_selected < matches + actions - 1)
8523 completion->priv->current_selected++;
8525 completion->priv->current_selected = -1;
8527 else if (event->keyval == GDK_Page_Up)
8529 if (completion->priv->current_selected < 0)
8530 completion->priv->current_selected = matches + actions - 1;
8531 else if (completion->priv->current_selected == 0)
8532 completion->priv->current_selected = -1;
8533 else if (completion->priv->current_selected < matches)
8535 completion->priv->current_selected -= 14;
8536 if (completion->priv->current_selected < 0)
8537 completion->priv->current_selected = 0;
8541 completion->priv->current_selected -= 14;
8542 if (completion->priv->current_selected < matches - 1)
8543 completion->priv->current_selected = matches - 1;
8546 else if (event->keyval == GDK_Page_Down)
8548 if (completion->priv->current_selected < 0)
8549 completion->priv->current_selected = 0;
8550 else if (completion->priv->current_selected < matches - 1)
8552 completion->priv->current_selected += 14;
8553 if (completion->priv->current_selected > matches - 1)
8554 completion->priv->current_selected = matches - 1;
8556 else if (completion->priv->current_selected == matches + actions - 1)
8558 completion->priv->current_selected = -1;
8562 completion->priv->current_selected += 14;
8563 if (completion->priv->current_selected > matches + actions - 1)
8564 completion->priv->current_selected = matches + actions - 1;
8568 if (completion->priv->current_selected < 0)
8570 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
8571 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view)));
8573 if (completion->priv->inline_selection &&
8574 completion->priv->completion_prefix)
8576 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
8577 completion->priv->completion_prefix);
8578 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
8581 else if (completion->priv->current_selected < matches)
8583 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view)));
8585 path = gtk_tree_path_new_from_indices (completion->priv->current_selected, -1);
8586 gtk_tree_view_set_cursor (GTK_TREE_VIEW (completion->priv->tree_view),
8589 if (completion->priv->inline_selection)
8593 GtkTreeModel *model = NULL;
8594 GtkTreeSelection *sel;
8597 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view));
8598 if (!gtk_tree_selection_get_selected (sel, &model, &iter))
8601 if (completion->priv->completion_prefix == NULL)
8602 completion->priv->completion_prefix = g_strdup (gtk_entry_get_text (GTK_ENTRY (completion->priv->entry)));
8604 g_signal_emit_by_name (completion, "cursor-on-match", model,
8608 else if (completion->priv->current_selected - matches >= 0)
8610 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
8612 path = gtk_tree_path_new_from_indices (completion->priv->current_selected - matches, -1);
8613 gtk_tree_view_set_cursor (GTK_TREE_VIEW (completion->priv->action_view),
8616 if (completion->priv->inline_selection &&
8617 completion->priv->completion_prefix)
8619 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
8620 completion->priv->completion_prefix);
8621 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
8625 gtk_tree_path_free (path);
8629 else if (event->keyval == GDK_Escape ||
8630 event->keyval == GDK_Left ||
8631 event->keyval == GDK_KP_Left ||
8632 event->keyval == GDK_Right ||
8633 event->keyval == GDK_KP_Right)
8635 gboolean retval = TRUE;
8637 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
8638 _gtk_entry_completion_popdown (completion);
8640 if (completion->priv->current_selected < 0)
8643 goto keypress_completion_out;
8645 else if (completion->priv->inline_selection)
8647 /* Escape rejects the tentative completion */
8648 if (event->keyval == GDK_Escape)
8650 if (completion->priv->completion_prefix)
8651 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
8652 completion->priv->completion_prefix);
8654 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry), "");
8657 /* Move the cursor to the end for Right/Esc, to the
8658 beginning for Left */
8659 if (event->keyval == GDK_Right ||
8660 event->keyval == GDK_KP_Right ||
8661 event->keyval == GDK_Escape)
8662 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
8664 gtk_editable_set_position (GTK_EDITABLE (widget), 0);
8667 keypress_completion_out:
8668 if (completion->priv->inline_selection)
8670 g_free (completion->priv->completion_prefix);
8671 completion->priv->completion_prefix = NULL;
8676 else if (event->keyval == GDK_Tab ||
8677 event->keyval == GDK_KP_Tab ||
8678 event->keyval == GDK_ISO_Left_Tab)
8680 GtkDirectionType dir = event->keyval == GDK_ISO_Left_Tab ?
8681 GTK_DIR_TAB_BACKWARD : GTK_DIR_TAB_FORWARD;
8683 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
8684 _gtk_entry_completion_popdown (completion);
8686 g_free (completion->priv->completion_prefix);
8687 completion->priv->completion_prefix = NULL;
8689 gtk_widget_child_focus (gtk_widget_get_toplevel (widget), dir);
8693 else if (event->keyval == GDK_ISO_Enter ||
8694 event->keyval == GDK_KP_Enter ||
8695 event->keyval == GDK_Return)
8697 gboolean retval = TRUE;
8699 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
8700 _gtk_entry_completion_popdown (completion);
8702 if (completion->priv->current_selected < matches)
8705 GtkTreeModel *model = NULL;
8706 GtkTreeSelection *sel;
8709 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view));
8710 if (gtk_tree_selection_get_selected (sel, &model, &iter))
8712 g_signal_handler_block (widget, completion->priv->changed_id);
8713 g_signal_emit_by_name (completion, "match-selected",
8714 model, &iter, &entry_set);
8715 g_signal_handler_unblock (widget, completion->priv->changed_id);
8721 gtk_tree_model_get (model, &iter,
8722 completion->priv->text_column, &str,
8725 gtk_entry_set_text (GTK_ENTRY (widget), str);
8727 /* move the cursor to the end */
8728 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
8736 else if (completion->priv->current_selected - matches >= 0)
8740 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
8742 path = gtk_tree_path_new_from_indices (completion->priv->current_selected - matches, -1);
8744 g_signal_emit_by_name (completion, "action-activated",
8745 gtk_tree_path_get_indices (path)[0]);
8746 gtk_tree_path_free (path);
8749 g_free (completion->priv->completion_prefix);
8750 completion->priv->completion_prefix = NULL;
8759 gtk_entry_completion_changed (GtkWidget *entry,
8762 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
8764 /* (re)install completion timeout */
8765 if (completion->priv->completion_timeout)
8766 g_source_remove (completion->priv->completion_timeout);
8768 if (!gtk_entry_get_text (GTK_ENTRY (entry)))
8771 /* no need to normalize for this test */
8772 if (completion->priv->minimum_key_length > 0 &&
8773 strcmp ("", gtk_entry_get_text (GTK_ENTRY (entry))) == 0)
8775 if (GTK_WIDGET_VISIBLE (completion->priv->popup_window))
8776 _gtk_entry_completion_popdown (completion);
8780 completion->priv->completion_timeout =
8781 gdk_threads_add_timeout (COMPLETION_TIMEOUT,
8782 gtk_entry_completion_timeout,
8787 check_completion_callback (GtkEntryCompletion *completion)
8789 completion->priv->check_completion_idle = NULL;
8791 gtk_entry_completion_complete (completion);
8792 gtk_entry_completion_insert_prefix (completion);
8798 clear_completion_callback (GtkEntry *entry,
8801 if (pspec->name == I_("cursor-position") ||
8802 pspec->name == I_("selection-bound"))
8804 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
8806 completion->priv->has_completion = FALSE;
8811 accept_completion_callback (GtkEntry *entry)
8813 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
8815 if (completion->priv->has_completion)
8816 gtk_editable_set_position (GTK_EDITABLE (entry),
8817 entry->text_length);
8823 completion_insert_text_callback (GtkEntry *entry,
8827 GtkEntryCompletion *completion)
8829 /* idle to update the selection based on the file list */
8830 if (completion->priv->check_completion_idle == NULL)
8832 completion->priv->check_completion_idle = g_idle_source_new ();
8833 g_source_set_priority (completion->priv->check_completion_idle, G_PRIORITY_HIGH);
8834 g_source_set_closure (completion->priv->check_completion_idle,
8835 g_cclosure_new_object (G_CALLBACK (check_completion_callback),
8836 G_OBJECT (completion)));
8837 g_source_attach (completion->priv->check_completion_idle, NULL);
8842 completion_changed (GtkEntryCompletion *completion,
8846 GtkEntry *entry = GTK_ENTRY (data);
8848 if (pspec->name == I_("popup-completion") ||
8849 pspec->name == I_("inline-completion"))
8851 disconnect_completion_signals (entry, completion);
8852 connect_completion_signals (entry, completion);
8857 disconnect_completion_signals (GtkEntry *entry,
8858 GtkEntryCompletion *completion)
8860 g_signal_handlers_disconnect_by_func (completion,
8861 G_CALLBACK (completion_changed), entry);
8862 if (completion->priv->changed_id > 0 &&
8863 g_signal_handler_is_connected (entry, completion->priv->changed_id))
8865 g_signal_handler_disconnect (entry, completion->priv->changed_id);
8866 completion->priv->changed_id = 0;
8868 g_signal_handlers_disconnect_by_func (entry,
8869 G_CALLBACK (gtk_entry_completion_key_press), completion);
8870 if (completion->priv->insert_text_id > 0 &&
8871 g_signal_handler_is_connected (entry, completion->priv->insert_text_id))
8873 g_signal_handler_disconnect (entry, completion->priv->insert_text_id);
8874 completion->priv->insert_text_id = 0;
8876 g_signal_handlers_disconnect_by_func (entry,
8877 G_CALLBACK (completion_insert_text_callback), completion);
8878 g_signal_handlers_disconnect_by_func (entry,
8879 G_CALLBACK (clear_completion_callback), completion);
8880 g_signal_handlers_disconnect_by_func (entry,
8881 G_CALLBACK (accept_completion_callback), completion);
8885 connect_completion_signals (GtkEntry *entry,
8886 GtkEntryCompletion *completion)
8888 if (completion->priv->popup_completion)
8890 completion->priv->changed_id =
8891 g_signal_connect (entry, "changed",
8892 G_CALLBACK (gtk_entry_completion_changed), completion);
8893 g_signal_connect (entry, "key-press-event",
8894 G_CALLBACK (gtk_entry_completion_key_press), completion);
8897 if (completion->priv->inline_completion)
8899 completion->priv->insert_text_id =
8900 g_signal_connect (entry, "insert-text",
8901 G_CALLBACK (completion_insert_text_callback), completion);
8902 g_signal_connect (entry, "notify",
8903 G_CALLBACK (clear_completion_callback), completion);
8904 g_signal_connect (entry, "activate",
8905 G_CALLBACK (accept_completion_callback), completion);
8906 g_signal_connect (entry, "focus-out-event",
8907 G_CALLBACK (accept_completion_callback), completion);
8910 g_signal_connect (completion, "notify",
8911 G_CALLBACK (completion_changed), entry);
8915 * gtk_entry_set_completion:
8916 * @entry: A #GtkEntry
8917 * @completion: The #GtkEntryCompletion or %NULL
8919 * Sets @completion to be the auxiliary completion object to use with @entry.
8920 * All further configuration of the completion mechanism is done on
8921 * @completion using the #GtkEntryCompletion API. Completion is disabled if
8922 * @completion is set to %NULL.
8927 gtk_entry_set_completion (GtkEntry *entry,
8928 GtkEntryCompletion *completion)
8930 GtkEntryCompletion *old;
8932 g_return_if_fail (GTK_IS_ENTRY (entry));
8933 g_return_if_fail (!completion || GTK_IS_ENTRY_COMPLETION (completion));
8935 old = gtk_entry_get_completion (entry);
8937 if (old == completion)
8942 if (old->priv->completion_timeout)
8944 g_source_remove (old->priv->completion_timeout);
8945 old->priv->completion_timeout = 0;
8948 if (GTK_WIDGET_MAPPED (old->priv->popup_window))
8949 _gtk_entry_completion_popdown (old);
8951 disconnect_completion_signals (entry, old);
8952 old->priv->entry = NULL;
8954 g_object_unref (old);
8959 g_object_set_data (G_OBJECT (entry), I_(GTK_ENTRY_COMPLETION_KEY), NULL);
8963 /* hook into the entry */
8964 g_object_ref (completion);
8966 connect_completion_signals (entry, completion);
8967 completion->priv->entry = GTK_WIDGET (entry);
8968 g_object_set_data (G_OBJECT (entry), I_(GTK_ENTRY_COMPLETION_KEY), completion);
8972 * gtk_entry_get_completion:
8973 * @entry: A #GtkEntry
8975 * Returns the auxiliary completion object currently in use by @entry.
8977 * Return value: The auxiliary completion object currently in use by @entry.
8981 GtkEntryCompletion *
8982 gtk_entry_get_completion (GtkEntry *entry)
8984 GtkEntryCompletion *completion;
8986 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8988 completion = GTK_ENTRY_COMPLETION (g_object_get_data (G_OBJECT (entry),
8989 GTK_ENTRY_COMPLETION_KEY));
8995 * gtk_entry_set_cursor_hadjustment:
8996 * @entry: a #GtkEntry
8997 * @adjustment: an adjustment which should be adjusted when the cursor
8998 * is moved, or %NULL
9000 * Hooks up an adjustment to the cursor position in an entry, so that when
9001 * the cursor is moved, the adjustment is scrolled to show that position.
9002 * See gtk_scrolled_window_get_hadjustment() for a typical way of obtaining
9005 * The adjustment has to be in pixel units and in the same coordinate system
9011 gtk_entry_set_cursor_hadjustment (GtkEntry *entry,
9012 GtkAdjustment *adjustment)
9014 g_return_if_fail (GTK_IS_ENTRY (entry));
9016 g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
9019 g_object_ref (adjustment);
9021 g_object_set_qdata_full (G_OBJECT (entry),
9022 quark_cursor_hadjustment,
9028 * gtk_entry_get_cursor_hadjustment:
9029 * @entry: a #GtkEntry
9031 * Retrieves the horizontal cursor adjustment for the entry.
9032 * See gtk_entry_set_cursor_hadjustment().
9034 * Return value: the horizontal cursor adjustment, or %NULL
9035 * if none has been set.
9040 gtk_entry_get_cursor_hadjustment (GtkEntry *entry)
9042 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
9044 return g_object_get_qdata (G_OBJECT (entry), quark_cursor_hadjustment);
9048 * gtk_entry_set_progress_fraction:
9049 * @entry: a #GtkEntry
9050 * @fraction: fraction of the task that's been completed
9052 * Causes the entry's progress indicator to "fill in" the given
9053 * fraction of the bar. The fraction should be between 0.0 and 1.0,
9059 gtk_entry_set_progress_fraction (GtkEntry *entry,
9062 GtkEntryPrivate *private;
9063 gdouble old_fraction;
9065 g_return_if_fail (GTK_IS_ENTRY (entry));
9067 private = GTK_ENTRY_GET_PRIVATE (entry);
9069 if (private->progress_pulse_mode)
9072 old_fraction = private->progress_fraction;
9074 fraction = CLAMP (fraction, 0.0, 1.0);
9076 private->progress_fraction = fraction;
9077 private->progress_pulse_mode = FALSE;
9078 private->progress_pulse_current = 0.0;
9080 if (fabs (fraction - old_fraction) > 0.0001)
9081 gtk_entry_queue_draw (entry);
9083 if (fraction != old_fraction)
9084 g_object_notify (G_OBJECT (entry), "progress-fraction");
9088 * gtk_entry_get_progress_fraction:
9089 * @entry: a #GtkEntry
9091 * Returns the current fraction of the task that's been completed.
9092 * See gtk_entry_set_progress_fraction().
9094 * Return value: a fraction from 0.0 to 1.0
9099 gtk_entry_get_progress_fraction (GtkEntry *entry)
9101 GtkEntryPrivate *private;
9103 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
9105 private = GTK_ENTRY_GET_PRIVATE (entry);
9107 return private->progress_fraction;
9111 * gtk_entry_set_progress_pulse_step:
9112 * @entry: a #GtkEntry
9113 * @fraction: fraction between 0.0 and 1.0
9115 * Sets the fraction of total entry width to move the progress
9116 * bouncing block for each call to gtk_entry_progress_pulse().
9121 gtk_entry_set_progress_pulse_step (GtkEntry *entry,
9124 GtkEntryPrivate *private;
9126 g_return_if_fail (GTK_IS_ENTRY (entry));
9128 private = GTK_ENTRY_GET_PRIVATE (entry);
9130 fraction = CLAMP (fraction, 0.0, 1.0);
9132 if (fraction != private->progress_pulse_fraction)
9134 private->progress_pulse_fraction = fraction;
9136 gtk_entry_queue_draw (entry);
9138 g_object_notify (G_OBJECT (entry), "progress-pulse-step");
9143 * gtk_entry_get_progress_pulse_step:
9144 * @entry: a #GtkEntry
9146 * Retrieves the pulse step set with gtk_entry_set_progress_pulse_step().
9148 * Return value: a fraction from 0.0 to 1.0
9153 gtk_entry_get_progress_pulse_step (GtkEntry *entry)
9155 GtkEntryPrivate *private;
9157 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
9159 private = GTK_ENTRY_GET_PRIVATE (entry);
9161 return private->progress_pulse_fraction;
9165 * gtk_entry_progress_pulse:
9166 * @entry: a #GtkEntry
9168 * Indicates that some progress is made, but you don't know how much.
9169 * Causes the entry's progress indicator to enter "activity mode,"
9170 * where a block bounces back and forth. Each call to
9171 * gtk_entry_progress_pulse() causes the block to move by a little bit
9172 * (the amount of movement per pulse is determined by
9173 * gtk_entry_set_progress_pulse_step()).
9178 gtk_entry_progress_pulse (GtkEntry *entry)
9180 GtkEntryPrivate *private;
9182 g_return_if_fail (GTK_IS_ENTRY (entry));
9184 private = GTK_ENTRY_GET_PRIVATE (entry);
9186 if (private->progress_pulse_mode)
9188 if (private->progress_pulse_way_back)
9190 private->progress_pulse_current -= private->progress_pulse_fraction;
9192 if (private->progress_pulse_current < 0.0)
9194 private->progress_pulse_current = 0.0;
9195 private->progress_pulse_way_back = FALSE;
9200 private->progress_pulse_current += private->progress_pulse_fraction;
9202 if (private->progress_pulse_current > 1.0 - private->progress_pulse_fraction)
9204 private->progress_pulse_current = 1.0 - private->progress_pulse_fraction;
9205 private->progress_pulse_way_back = TRUE;
9211 private->progress_fraction = 0.0;
9212 private->progress_pulse_mode = TRUE;
9213 private->progress_pulse_way_back = FALSE;
9214 private->progress_pulse_current = 0.0;
9217 gtk_entry_queue_draw (entry);
9220 /* Caps Lock warning for password entries */
9223 capslock_feedback_free (GtkEntryCapslockFeedback *feedback)
9225 if (feedback->window)
9226 gtk_widget_destroy (feedback->window);
9228 g_slice_free (GtkEntryCapslockFeedback, feedback);
9232 capslock_feedback_expose_event_cb (GtkWidget *widget,
9233 GdkEventExpose *event,
9234 GtkEntryCapslockFeedback *feedback)
9236 gtk_paint_flat_box (feedback->window->style,
9237 feedback->window->window,
9244 feedback->window->allocation.width,
9245 feedback->window->allocation.height);
9250 capslock_feedback_enter_notify (GtkWidget *widget,
9251 GdkEventCrossing *event,
9252 GtkEntryCapslockFeedback *feedback)
9254 remove_capslock_feedback (GTK_ENTRY (feedback->entry));
9259 create_capslock_feedback_window (GtkEntryCapslockFeedback *feedback)
9262 GtkWidget *alignment;
9265 /* Keep in sync with gtk_tooltip_init() */
9266 window = feedback->window = gtk_window_new (GTK_WINDOW_POPUP);
9267 gtk_window_set_type_hint (GTK_WINDOW (window), GDK_WINDOW_TYPE_HINT_TOOLTIP);
9268 gtk_widget_set_app_paintable (window, TRUE);
9269 gtk_window_set_resizable (GTK_WINDOW (window), FALSE);
9270 gtk_widget_set_name (window, "gtk-tooltip");
9272 alignment = gtk_alignment_new (0.5, 0.5, 1.0, 1.0);
9273 gtk_alignment_set_padding (GTK_ALIGNMENT (alignment),
9274 window->style->ythickness,
9275 window->style->ythickness,
9276 window->style->xthickness,
9277 window->style->xthickness);
9278 gtk_container_add (GTK_CONTAINER (window), alignment);
9279 gtk_widget_show (alignment);
9281 g_signal_connect (window, "expose-event",
9282 G_CALLBACK (capslock_feedback_expose_event_cb), feedback);
9283 g_signal_connect (window, "enter-notify-event",
9284 G_CALLBACK (capslock_feedback_enter_notify), feedback);
9286 label = feedback->label = gtk_label_new (NULL);
9287 gtk_container_add (GTK_CONTAINER (alignment), label);
9288 gtk_widget_show (label);
9292 show_capslock_feedback_window (GtkEntryCapslockFeedback *feedback)
9294 GtkRequisition feedback_req;
9295 gint entry_x, entry_y;
9296 GtkAllocation *entry_allocation;
9297 int feedback_x, feedback_y;
9300 GdkRectangle monitor;
9303 entry = feedback->entry;
9304 screen = gtk_widget_get_screen (entry);
9305 monitor_num = gdk_screen_get_monitor_at_window (screen, entry->window);
9306 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
9308 feedback = g_object_get_qdata (G_OBJECT (entry), quark_capslock_feedback);
9310 gtk_widget_size_request (feedback->window, &feedback_req);
9312 gdk_window_get_origin (entry->window, &entry_x, &entry_y);
9313 entry_allocation = &(entry->allocation);
9315 if (entry_x + feedback_req.width <= monitor.x + monitor.width)
9316 feedback_x = MAX (entry_x, monitor.x);
9318 feedback_x = monitor.x + monitor.width - feedback_req.width;
9320 if (entry_y + entry_allocation->height + feedback_req.height <= monitor.y + monitor.height)
9321 feedback_y = entry_y + entry_allocation->height;
9323 feedback_y = MAX (entry_y - feedback_req.height, monitor.y);
9325 gtk_window_move (GTK_WINDOW (feedback->window), feedback_x, feedback_y);
9326 gtk_widget_show (feedback->window);
9330 pop_up_capslock_feedback (GtkEntry *entry,
9333 GtkEntryCapslockFeedback *feedback;
9335 feedback = g_object_get_qdata (G_OBJECT (entry), quark_capslock_feedback);
9337 if (feedback == NULL)
9339 feedback = g_slice_new0 (GtkEntryCapslockFeedback);
9340 feedback->entry = GTK_WIDGET (entry);
9341 g_object_set_qdata_full (G_OBJECT (entry), quark_capslock_feedback,
9343 (GDestroyNotify) capslock_feedback_free);
9344 create_capslock_feedback_window (feedback);
9347 gtk_label_set_text (GTK_LABEL (feedback->label), text);
9348 show_capslock_feedback_window (feedback);
9352 remove_capslock_feedback (GtkEntry *entry)
9354 g_object_set_qdata (G_OBJECT (entry), quark_capslock_feedback, NULL);
9358 keymap_state_changed (GdkKeymap *keymap,
9361 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
9364 if (!entry->visible && priv->caps_lock_warning)
9366 gboolean capslock_on;
9369 capslock_on = gdk_keymap_get_caps_lock_state (keymap);
9370 im_on = g_strcmp0 (gtk_im_multicontext_get_context_id (GTK_IM_MULTICONTEXT (entry->im_context)), "gtk-im-context-simple") != 0;
9371 if (capslock_on && im_on)
9372 text = _("You have the Caps Lock key on\nand an active input method");
9373 else if (capslock_on)
9374 text = _("You have the Caps Lock key on");
9376 text = _("You have an active input method");
9380 pop_up_capslock_feedback (entry, text);
9382 remove_capslock_feedback (entry);
9385 #define __GTK_ENTRY_C__
9386 #include "gtkaliasdef.c"