1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* GTK - The GIMP Toolkit
3 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * Copyright (C) 2004-2006 Christian Hammond
5 * Copyright (C) 2008 Cody Russell
6 * Copyright (C) 2008 Red Hat, Inc.
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
25 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
26 * file for a list of people on the GTK+ Team. See the ChangeLog
27 * files for a list of changes. These files are distributed with
28 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
36 #include "gdk/gdkkeysyms.h"
37 #include "gtkalignment.h"
38 #include "gtkbindings.h"
39 #include "gtkcelleditable.h"
40 #include "gtkclipboard.h"
43 #include "gtkentrybuffer.h"
44 #include "gtkimagemenuitem.h"
45 #include "gtkimcontextsimple.h"
46 #include "gtkimmulticontext.h"
50 #include "gtkmarshalers.h"
52 #include "gtkmenuitem.h"
53 #include "gtkseparatormenuitem.h"
54 #include "gtkselection.h"
55 #include "gtksettings.h"
56 #include "gtkspinbutton.h"
58 #include "gtktextutil.h"
59 #include "gtkwindow.h"
60 #include "gtktreeview.h"
61 #include "gtktreeselection.h"
62 #include "gtkprivate.h"
63 #include "gtkentryprivate.h"
64 #include "gtkcelllayout.h"
65 #include "gtktooltip.h"
66 #include "gtkiconfactory.h"
67 #include "gtkicontheme.h"
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
78 #define IS_VALID_ICON_POSITION(pos) \
79 ((pos) == GTK_ENTRY_ICON_PRIMARY || \
80 (pos) == GTK_ENTRY_ICON_SECONDARY)
82 static const GtkBorder default_inner_border = { 2, 2, 2, 2 };
83 static GQuark quark_inner_border = 0;
84 static GQuark quark_password_hint = 0;
85 static GQuark quark_cursor_hadjustment = 0;
86 static GQuark quark_capslock_feedback = 0;
88 typedef struct _GtkEntryPrivate GtkEntryPrivate;
90 #define GTK_ENTRY_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_ENTRY, GtkEntryPrivate))
96 guint insensitive : 1;
97 guint nonactivatable : 1;
102 GtkImageType storage_type;
108 GtkTargetList *target_list;
109 GdkDragAction actions;
112 struct _GtkEntryPrivate
114 GtkEntryBuffer* buffer;
118 guint blink_time; /* time in msec the cursor has blinked since last user event */
119 guint interior_focus : 1;
120 guint real_changed : 1;
121 guint invisible_char_set : 1;
122 guint caps_lock_warning : 1;
123 guint caps_lock_warning_shown : 1;
124 guint change_count : 8;
125 guint progress_pulse_mode : 1;
126 guint progress_pulse_way_back : 1;
129 GtkShadowType shadow_type;
131 gdouble progress_fraction;
132 gdouble progress_pulse_fraction;
133 gdouble progress_pulse_current;
135 EntryIconInfo *icons[MAX_ICONS];
142 GdkDevice *completion_device;
145 typedef struct _GtkEntryPasswordHint GtkEntryPasswordHint;
147 struct _GtkEntryPasswordHint
149 gint position; /* Position (in text) of the last password hint */
150 guint source_id; /* Timeout source id */
153 typedef struct _GtkEntryCapslockFeedback GtkEntryCapslockFeedback;
155 struct _GtkEntryCapslockFeedback
182 PROP_CURSOR_POSITION,
183 PROP_SELECTION_BOUND,
190 PROP_ACTIVATES_DEFAULT,
195 PROP_TRUNCATE_MULTILINE,
199 PROP_INVISIBLE_CHAR_SET,
200 PROP_CAPS_LOCK_WARNING,
201 PROP_PROGRESS_FRACTION,
202 PROP_PROGRESS_PULSE_STEP,
204 PROP_PIXBUF_SECONDARY,
206 PROP_STOCK_SECONDARY,
207 PROP_ICON_NAME_PRIMARY,
208 PROP_ICON_NAME_SECONDARY,
210 PROP_GICON_SECONDARY,
211 PROP_STORAGE_TYPE_PRIMARY,
212 PROP_STORAGE_TYPE_SECONDARY,
213 PROP_ACTIVATABLE_PRIMARY,
214 PROP_ACTIVATABLE_SECONDARY,
215 PROP_SENSITIVE_PRIMARY,
216 PROP_SENSITIVE_SECONDARY,
217 PROP_TOOLTIP_TEXT_PRIMARY,
218 PROP_TOOLTIP_TEXT_SECONDARY,
219 PROP_TOOLTIP_MARKUP_PRIMARY,
220 PROP_TOOLTIP_MARKUP_SECONDARY,
222 PROP_EDITING_CANCELED
225 static guint signals[LAST_SIGNAL] = { 0 };
234 DISPLAY_NORMAL, /* The entry text is being shown */
235 DISPLAY_INVISIBLE, /* In invisible mode, text replaced by (eg) bullets */
236 DISPLAY_BLANK /* In invisible mode, nothing shown at all */
241 static void gtk_entry_editable_init (GtkEditableInterface *iface);
242 static void gtk_entry_cell_editable_init (GtkCellEditableIface *iface);
243 static void gtk_entry_set_property (GObject *object,
247 static void gtk_entry_get_property (GObject *object,
251 static void gtk_entry_finalize (GObject *object);
252 static void gtk_entry_dispose (GObject *object);
256 static void gtk_entry_destroy (GtkWidget *widget);
257 static void gtk_entry_realize (GtkWidget *widget);
258 static void gtk_entry_unrealize (GtkWidget *widget);
259 static void gtk_entry_map (GtkWidget *widget);
260 static void gtk_entry_unmap (GtkWidget *widget);
261 static void gtk_entry_size_request (GtkWidget *widget,
262 GtkRequisition *requisition);
263 static void gtk_entry_size_allocate (GtkWidget *widget,
264 GtkAllocation *allocation);
265 static void gtk_entry_draw_frame (GtkWidget *widget,
267 static void gtk_entry_draw_progress (GtkWidget *widget,
269 static gint gtk_entry_draw (GtkWidget *widget,
271 static gint gtk_entry_button_press (GtkWidget *widget,
272 GdkEventButton *event);
273 static gint gtk_entry_button_release (GtkWidget *widget,
274 GdkEventButton *event);
275 static gint gtk_entry_enter_notify (GtkWidget *widget,
276 GdkEventCrossing *event);
277 static gint gtk_entry_leave_notify (GtkWidget *widget,
278 GdkEventCrossing *event);
279 static gint gtk_entry_motion_notify (GtkWidget *widget,
280 GdkEventMotion *event);
281 static gint gtk_entry_key_press (GtkWidget *widget,
283 static gint gtk_entry_key_release (GtkWidget *widget,
285 static gint gtk_entry_focus_in (GtkWidget *widget,
286 GdkEventFocus *event);
287 static gint gtk_entry_focus_out (GtkWidget *widget,
288 GdkEventFocus *event);
289 static void gtk_entry_grab_focus (GtkWidget *widget);
290 static void gtk_entry_style_set (GtkWidget *widget,
291 GtkStyle *previous_style);
292 static gboolean gtk_entry_query_tooltip (GtkWidget *widget,
295 gboolean keyboard_tip,
296 GtkTooltip *tooltip);
297 static void gtk_entry_direction_changed (GtkWidget *widget,
298 GtkTextDirection previous_dir);
299 static void gtk_entry_state_changed (GtkWidget *widget,
300 GtkStateType previous_state);
301 static void gtk_entry_screen_changed (GtkWidget *widget,
302 GdkScreen *old_screen);
304 static gboolean gtk_entry_drag_drop (GtkWidget *widget,
305 GdkDragContext *context,
309 static gboolean gtk_entry_drag_motion (GtkWidget *widget,
310 GdkDragContext *context,
314 static void gtk_entry_drag_leave (GtkWidget *widget,
315 GdkDragContext *context,
317 static void gtk_entry_drag_data_received (GtkWidget *widget,
318 GdkDragContext *context,
321 GtkSelectionData *selection_data,
324 static void gtk_entry_drag_data_get (GtkWidget *widget,
325 GdkDragContext *context,
326 GtkSelectionData *selection_data,
329 static void gtk_entry_drag_data_delete (GtkWidget *widget,
330 GdkDragContext *context);
331 static void gtk_entry_drag_begin (GtkWidget *widget,
332 GdkDragContext *context);
333 static void gtk_entry_drag_end (GtkWidget *widget,
334 GdkDragContext *context);
337 /* GtkEditable method implementations
339 static void gtk_entry_insert_text (GtkEditable *editable,
340 const gchar *new_text,
341 gint new_text_length,
343 static void gtk_entry_delete_text (GtkEditable *editable,
346 static gchar * gtk_entry_get_chars (GtkEditable *editable,
349 static void gtk_entry_real_set_position (GtkEditable *editable,
351 static gint gtk_entry_get_position (GtkEditable *editable);
352 static void gtk_entry_set_selection_bounds (GtkEditable *editable,
355 static gboolean gtk_entry_get_selection_bounds (GtkEditable *editable,
359 /* GtkCellEditable method implementations
361 static void gtk_entry_start_editing (GtkCellEditable *cell_editable,
364 /* Default signal handlers
366 static void gtk_entry_real_insert_text (GtkEditable *editable,
367 const gchar *new_text,
368 gint new_text_length,
370 static void gtk_entry_real_delete_text (GtkEditable *editable,
373 static void gtk_entry_move_cursor (GtkEntry *entry,
374 GtkMovementStep step,
376 gboolean extend_selection);
377 static void gtk_entry_insert_at_cursor (GtkEntry *entry,
379 static void gtk_entry_delete_from_cursor (GtkEntry *entry,
382 static void gtk_entry_backspace (GtkEntry *entry);
383 static void gtk_entry_cut_clipboard (GtkEntry *entry);
384 static void gtk_entry_copy_clipboard (GtkEntry *entry);
385 static void gtk_entry_paste_clipboard (GtkEntry *entry);
386 static void gtk_entry_toggle_overwrite (GtkEntry *entry);
387 static void gtk_entry_select_all (GtkEntry *entry);
388 static void gtk_entry_real_activate (GtkEntry *entry);
389 static gboolean gtk_entry_popup_menu (GtkWidget *widget);
391 static void keymap_direction_changed (GdkKeymap *keymap,
393 static void keymap_state_changed (GdkKeymap *keymap,
395 static void remove_capslock_feedback (GtkEntry *entry);
397 /* IM Context Callbacks
399 static void gtk_entry_commit_cb (GtkIMContext *context,
402 static void gtk_entry_preedit_changed_cb (GtkIMContext *context,
404 static gboolean gtk_entry_retrieve_surrounding_cb (GtkIMContext *context,
406 static gboolean gtk_entry_delete_surrounding_cb (GtkIMContext *context,
413 static void gtk_entry_enter_text (GtkEntry *entry,
415 static void gtk_entry_set_positions (GtkEntry *entry,
417 gint selection_bound);
418 static void gtk_entry_draw_text (GtkEntry *entry,
420 static void gtk_entry_draw_cursor (GtkEntry *entry,
423 static PangoLayout *gtk_entry_ensure_layout (GtkEntry *entry,
424 gboolean include_preedit);
425 static void gtk_entry_reset_layout (GtkEntry *entry);
426 static void gtk_entry_queue_draw (GtkEntry *entry);
427 static void gtk_entry_recompute (GtkEntry *entry);
428 static gint gtk_entry_find_position (GtkEntry *entry,
430 static void gtk_entry_get_cursor_locations (GtkEntry *entry,
434 static void gtk_entry_adjust_scroll (GtkEntry *entry);
435 static gint gtk_entry_move_visually (GtkEntry *editable,
438 static gint gtk_entry_move_logically (GtkEntry *entry,
441 static gint gtk_entry_move_forward_word (GtkEntry *entry,
443 gboolean allow_whitespace);
444 static gint gtk_entry_move_backward_word (GtkEntry *entry,
446 gboolean allow_whitespace);
447 static void gtk_entry_delete_whitespace (GtkEntry *entry);
448 static void gtk_entry_select_word (GtkEntry *entry);
449 static void gtk_entry_select_line (GtkEntry *entry);
450 static void gtk_entry_paste (GtkEntry *entry,
452 static void gtk_entry_update_primary_selection (GtkEntry *entry);
453 static void gtk_entry_do_popup (GtkEntry *entry,
454 GdkEventButton *event);
455 static gboolean gtk_entry_mnemonic_activate (GtkWidget *widget,
456 gboolean group_cycling);
457 static void gtk_entry_check_cursor_blink (GtkEntry *entry);
458 static void gtk_entry_pend_cursor_blink (GtkEntry *entry);
459 static void gtk_entry_reset_blink_time (GtkEntry *entry);
460 static void gtk_entry_get_text_area_size (GtkEntry *entry,
465 static void get_text_area_size (GtkEntry *entry,
470 static void get_frame_size (GtkEntry *entry,
475 static void gtk_entry_move_adjustments (GtkEntry *entry);
476 static void gtk_entry_ensure_pixbuf (GtkEntry *entry,
477 GtkEntryIconPosition icon_pos);
481 static gint gtk_entry_completion_timeout (gpointer data);
482 static gboolean gtk_entry_completion_key_press (GtkWidget *widget,
485 static void gtk_entry_completion_changed (GtkWidget *entry,
487 static gboolean check_completion_callback (GtkEntryCompletion *completion);
488 static void clear_completion_callback (GtkEntry *entry,
490 static gboolean accept_completion_callback (GtkEntry *entry);
491 static void completion_insert_text_callback (GtkEntry *entry,
495 GtkEntryCompletion *completion);
496 static void completion_changed (GtkEntryCompletion *completion,
499 static void disconnect_completion_signals (GtkEntry *entry,
500 GtkEntryCompletion *completion);
501 static void connect_completion_signals (GtkEntry *entry,
502 GtkEntryCompletion *completion);
504 static void begin_change (GtkEntry *entry);
505 static void end_change (GtkEntry *entry);
506 static void emit_changed (GtkEntry *entry);
509 static void buffer_inserted_text (GtkEntryBuffer *buffer,
514 static void buffer_deleted_text (GtkEntryBuffer *buffer,
518 static void buffer_notify_text (GtkEntryBuffer *buffer,
521 static void buffer_notify_length (GtkEntryBuffer *buffer,
524 static void buffer_notify_max_length (GtkEntryBuffer *buffer,
527 static void buffer_connect_signals (GtkEntry *entry);
528 static void buffer_disconnect_signals (GtkEntry *entry);
529 static GtkEntryBuffer *get_buffer (GtkEntry *entry);
532 G_DEFINE_TYPE_WITH_CODE (GtkEntry, gtk_entry, GTK_TYPE_WIDGET,
533 G_IMPLEMENT_INTERFACE (GTK_TYPE_EDITABLE,
534 gtk_entry_editable_init)
535 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_EDITABLE,
536 gtk_entry_cell_editable_init))
539 add_move_binding (GtkBindingSet *binding_set,
542 GtkMovementStep step,
545 g_return_if_fail ((modmask & GDK_SHIFT_MASK) == 0);
547 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
551 G_TYPE_BOOLEAN, FALSE);
553 /* Selection-extending version */
554 gtk_binding_entry_add_signal (binding_set, keyval, modmask | GDK_SHIFT_MASK,
558 G_TYPE_BOOLEAN, TRUE);
562 gtk_entry_class_init (GtkEntryClass *class)
564 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
565 GtkWidgetClass *widget_class;
566 GtkBindingSet *binding_set;
568 widget_class = (GtkWidgetClass*) class;
570 gobject_class->dispose = gtk_entry_dispose;
571 gobject_class->finalize = gtk_entry_finalize;
572 gobject_class->set_property = gtk_entry_set_property;
573 gobject_class->get_property = gtk_entry_get_property;
575 widget_class->destroy = gtk_entry_destroy;
576 widget_class->map = gtk_entry_map;
577 widget_class->unmap = gtk_entry_unmap;
578 widget_class->realize = gtk_entry_realize;
579 widget_class->unrealize = gtk_entry_unrealize;
580 widget_class->size_request = gtk_entry_size_request;
581 widget_class->size_allocate = gtk_entry_size_allocate;
582 widget_class->draw = gtk_entry_draw;
583 widget_class->enter_notify_event = gtk_entry_enter_notify;
584 widget_class->leave_notify_event = gtk_entry_leave_notify;
585 widget_class->button_press_event = gtk_entry_button_press;
586 widget_class->button_release_event = gtk_entry_button_release;
587 widget_class->motion_notify_event = gtk_entry_motion_notify;
588 widget_class->key_press_event = gtk_entry_key_press;
589 widget_class->key_release_event = gtk_entry_key_release;
590 widget_class->focus_in_event = gtk_entry_focus_in;
591 widget_class->focus_out_event = gtk_entry_focus_out;
592 widget_class->grab_focus = gtk_entry_grab_focus;
593 widget_class->style_set = gtk_entry_style_set;
594 widget_class->query_tooltip = gtk_entry_query_tooltip;
595 widget_class->drag_begin = gtk_entry_drag_begin;
596 widget_class->drag_end = gtk_entry_drag_end;
597 widget_class->direction_changed = gtk_entry_direction_changed;
598 widget_class->state_changed = gtk_entry_state_changed;
599 widget_class->screen_changed = gtk_entry_screen_changed;
600 widget_class->mnemonic_activate = gtk_entry_mnemonic_activate;
602 widget_class->drag_drop = gtk_entry_drag_drop;
603 widget_class->drag_motion = gtk_entry_drag_motion;
604 widget_class->drag_leave = gtk_entry_drag_leave;
605 widget_class->drag_data_received = gtk_entry_drag_data_received;
606 widget_class->drag_data_get = gtk_entry_drag_data_get;
607 widget_class->drag_data_delete = gtk_entry_drag_data_delete;
609 widget_class->popup_menu = gtk_entry_popup_menu;
611 class->move_cursor = gtk_entry_move_cursor;
612 class->insert_at_cursor = gtk_entry_insert_at_cursor;
613 class->delete_from_cursor = gtk_entry_delete_from_cursor;
614 class->backspace = gtk_entry_backspace;
615 class->cut_clipboard = gtk_entry_cut_clipboard;
616 class->copy_clipboard = gtk_entry_copy_clipboard;
617 class->paste_clipboard = gtk_entry_paste_clipboard;
618 class->toggle_overwrite = gtk_entry_toggle_overwrite;
619 class->activate = gtk_entry_real_activate;
620 class->get_text_area_size = gtk_entry_get_text_area_size;
622 quark_inner_border = g_quark_from_static_string ("gtk-entry-inner-border");
623 quark_password_hint = g_quark_from_static_string ("gtk-entry-password-hint");
624 quark_cursor_hadjustment = g_quark_from_static_string ("gtk-hadjustment");
625 quark_capslock_feedback = g_quark_from_static_string ("gtk-entry-capslock-feedback");
627 g_object_class_override_property (gobject_class,
628 PROP_EDITING_CANCELED,
631 g_object_class_install_property (gobject_class,
633 g_param_spec_object ("buffer",
635 P_("Text buffer object which actually stores entry text"),
636 GTK_TYPE_ENTRY_BUFFER,
637 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT));
639 g_object_class_install_property (gobject_class,
640 PROP_CURSOR_POSITION,
641 g_param_spec_int ("cursor-position",
642 P_("Cursor Position"),
643 P_("The current position of the insertion cursor in chars"),
645 GTK_ENTRY_BUFFER_MAX_SIZE,
647 GTK_PARAM_READABLE));
649 g_object_class_install_property (gobject_class,
650 PROP_SELECTION_BOUND,
651 g_param_spec_int ("selection-bound",
652 P_("Selection Bound"),
653 P_("The position of the opposite end of the selection from the cursor in chars"),
655 GTK_ENTRY_BUFFER_MAX_SIZE,
657 GTK_PARAM_READABLE));
659 g_object_class_install_property (gobject_class,
661 g_param_spec_boolean ("editable",
663 P_("Whether the entry contents can be edited"),
665 GTK_PARAM_READWRITE));
667 g_object_class_install_property (gobject_class,
669 g_param_spec_int ("max-length",
670 P_("Maximum length"),
671 P_("Maximum number of characters for this entry. Zero if no maximum"),
673 GTK_ENTRY_BUFFER_MAX_SIZE,
675 GTK_PARAM_READWRITE));
676 g_object_class_install_property (gobject_class,
678 g_param_spec_boolean ("visibility",
680 P_("FALSE displays the \"invisible char\" instead of the actual text (password mode)"),
682 GTK_PARAM_READWRITE));
684 g_object_class_install_property (gobject_class,
686 g_param_spec_boolean ("has-frame",
688 P_("FALSE removes outside bevel from entry"),
690 GTK_PARAM_READWRITE));
692 g_object_class_install_property (gobject_class,
694 g_param_spec_boxed ("inner-border",
696 P_("Border between text and frame. Overrides the inner-border style property"),
698 GTK_PARAM_READWRITE));
700 g_object_class_install_property (gobject_class,
702 g_param_spec_unichar ("invisible-char",
703 P_("Invisible character"),
704 P_("The character to use when masking entry contents (in \"password mode\")"),
706 GTK_PARAM_READWRITE));
708 g_object_class_install_property (gobject_class,
709 PROP_ACTIVATES_DEFAULT,
710 g_param_spec_boolean ("activates-default",
711 P_("Activates default"),
712 P_("Whether to activate the default widget (such as the default button in a dialog) when Enter is pressed"),
714 GTK_PARAM_READWRITE));
715 g_object_class_install_property (gobject_class,
717 g_param_spec_int ("width-chars",
718 P_("Width in chars"),
719 P_("Number of characters to leave space for in the entry"),
723 GTK_PARAM_READWRITE));
725 g_object_class_install_property (gobject_class,
727 g_param_spec_int ("scroll-offset",
729 P_("Number of pixels of the entry scrolled off the screen to the left"),
733 GTK_PARAM_READABLE));
735 g_object_class_install_property (gobject_class,
737 g_param_spec_string ("text",
739 P_("The contents of the entry"),
741 GTK_PARAM_READWRITE));
746 * The horizontal alignment, from 0 (left) to 1 (right).
747 * Reversed for RTL layouts.
751 g_object_class_install_property (gobject_class,
753 g_param_spec_float ("xalign",
755 P_("The horizontal alignment, from 0 (left) to 1 (right). Reversed for RTL layouts."),
759 GTK_PARAM_READWRITE));
762 * GtkEntry:truncate-multiline:
764 * When %TRUE, pasted multi-line text is truncated to the first line.
768 g_object_class_install_property (gobject_class,
769 PROP_TRUNCATE_MULTILINE,
770 g_param_spec_boolean ("truncate-multiline",
771 P_("Truncate multiline"),
772 P_("Whether to truncate multiline pastes to one line."),
774 GTK_PARAM_READWRITE));
777 * GtkEntry:shadow-type:
779 * Which kind of shadow to draw around the entry when
780 * #GtkEntry:has-frame is set to %TRUE.
784 g_object_class_install_property (gobject_class,
786 g_param_spec_enum ("shadow-type",
788 P_("Which kind of shadow to draw around the entry when has-frame is set"),
789 GTK_TYPE_SHADOW_TYPE,
791 GTK_PARAM_READWRITE));
794 * GtkEntry:overwrite-mode:
796 * If text is overwritten when typing in the #GtkEntry.
800 g_object_class_install_property (gobject_class,
802 g_param_spec_boolean ("overwrite-mode",
803 P_("Overwrite mode"),
804 P_("Whether new text overwrites existing text"),
806 GTK_PARAM_READWRITE));
809 * GtkEntry:text-length:
811 * The length of the text in the #GtkEntry.
815 g_object_class_install_property (gobject_class,
817 g_param_spec_uint ("text-length",
819 P_("Length of the text currently in the entry"),
823 GTK_PARAM_READABLE));
825 * GtkEntry:invisible-char-set:
827 * Whether the invisible char has been set for the #GtkEntry.
831 g_object_class_install_property (gobject_class,
832 PROP_INVISIBLE_CHAR_SET,
833 g_param_spec_boolean ("invisible-char-set",
834 P_("Invisible character set"),
835 P_("Whether the invisible character has been set"),
837 GTK_PARAM_READWRITE));
840 * GtkEntry:caps-lock-warning
842 * Whether password entries will show a warning when Caps Lock is on.
844 * Note that the warning is shown using a secondary icon, and thus
845 * does not work if you are using the secondary icon position for some
850 g_object_class_install_property (gobject_class,
851 PROP_CAPS_LOCK_WARNING,
852 g_param_spec_boolean ("caps-lock-warning",
853 P_("Caps Lock warning"),
854 P_("Whether password entries will show a warning when Caps Lock is on"),
856 GTK_PARAM_READWRITE));
859 * GtkEntry:progress-fraction:
861 * The current fraction of the task that's been completed.
865 g_object_class_install_property (gobject_class,
866 PROP_PROGRESS_FRACTION,
867 g_param_spec_double ("progress-fraction",
868 P_("Progress Fraction"),
869 P_("The current fraction of the task that's been completed"),
873 GTK_PARAM_READWRITE));
876 * GtkEntry:progress-pulse-step:
878 * The fraction of total entry width to move the progress
879 * bouncing block for each call to gtk_entry_progress_pulse().
883 g_object_class_install_property (gobject_class,
884 PROP_PROGRESS_PULSE_STEP,
885 g_param_spec_double ("progress-pulse-step",
886 P_("Progress Pulse Step"),
887 P_("The fraction of total entry width to move the progress bouncing block for each call to gtk_entry_progress_pulse()"),
891 GTK_PARAM_READWRITE));
894 * GtkEntry:primary-icon-pixbuf:
896 * A pixbuf to use as the primary icon for the entry.
900 g_object_class_install_property (gobject_class,
902 g_param_spec_object ("primary-icon-pixbuf",
903 P_("Primary pixbuf"),
904 P_("Primary pixbuf for the entry"),
906 GTK_PARAM_READWRITE));
909 * GtkEntry:secondary-icon-pixbuf:
911 * An pixbuf to use as the secondary icon for the entry.
915 g_object_class_install_property (gobject_class,
916 PROP_PIXBUF_SECONDARY,
917 g_param_spec_object ("secondary-icon-pixbuf",
918 P_("Secondary pixbuf"),
919 P_("Secondary pixbuf for the entry"),
921 GTK_PARAM_READWRITE));
924 * GtkEntry:primary-icon-stock:
926 * The stock id to use for the primary icon for the entry.
930 g_object_class_install_property (gobject_class,
932 g_param_spec_string ("primary-icon-stock",
933 P_("Primary stock ID"),
934 P_("Stock ID for primary icon"),
936 GTK_PARAM_READWRITE));
939 * GtkEntry:secondary-icon-stock:
941 * The stock id to use for the secondary icon for the entry.
945 g_object_class_install_property (gobject_class,
946 PROP_STOCK_SECONDARY,
947 g_param_spec_string ("secondary-icon-stock",
948 P_("Secondary stock ID"),
949 P_("Stock ID for secondary icon"),
951 GTK_PARAM_READWRITE));
954 * GtkEntry:primary-icon-name:
956 * The icon name to use for the primary icon for the entry.
960 g_object_class_install_property (gobject_class,
961 PROP_ICON_NAME_PRIMARY,
962 g_param_spec_string ("primary-icon-name",
963 P_("Primary icon name"),
964 P_("Icon name for primary icon"),
966 GTK_PARAM_READWRITE));
969 * GtkEntry:secondary-icon-name:
971 * The icon name to use for the secondary icon for the entry.
975 g_object_class_install_property (gobject_class,
976 PROP_ICON_NAME_SECONDARY,
977 g_param_spec_string ("secondary-icon-name",
978 P_("Secondary icon name"),
979 P_("Icon name for secondary icon"),
981 GTK_PARAM_READWRITE));
984 * GtkEntry:primary-icon-gicon:
986 * The #GIcon to use for the primary icon for the entry.
990 g_object_class_install_property (gobject_class,
992 g_param_spec_object ("primary-icon-gicon",
994 P_("GIcon for primary icon"),
996 GTK_PARAM_READWRITE));
999 * GtkEntry:secondary-icon-gicon:
1001 * The #GIcon to use for the secondary icon for the entry.
1005 g_object_class_install_property (gobject_class,
1006 PROP_GICON_SECONDARY,
1007 g_param_spec_object ("secondary-icon-gicon",
1008 P_("Secondary GIcon"),
1009 P_("GIcon for secondary icon"),
1011 GTK_PARAM_READWRITE));
1014 * GtkEntry:primary-icon-storage-type:
1016 * The representation which is used for the primary icon of the entry.
1020 g_object_class_install_property (gobject_class,
1021 PROP_STORAGE_TYPE_PRIMARY,
1022 g_param_spec_enum ("primary-icon-storage-type",
1023 P_("Primary storage type"),
1024 P_("The representation being used for primary icon"),
1025 GTK_TYPE_IMAGE_TYPE,
1027 GTK_PARAM_READABLE));
1030 * GtkEntry:secondary-icon-storage-type:
1032 * The representation which is used for the secondary icon of the entry.
1036 g_object_class_install_property (gobject_class,
1037 PROP_STORAGE_TYPE_SECONDARY,
1038 g_param_spec_enum ("secondary-icon-storage-type",
1039 P_("Secondary storage type"),
1040 P_("The representation being used for secondary icon"),
1041 GTK_TYPE_IMAGE_TYPE,
1043 GTK_PARAM_READABLE));
1046 * GtkEntry:primary-icon-activatable:
1048 * Whether the primary icon is activatable.
1050 * GTK+ emits the #GtkEntry::icon-press and #GtkEntry::icon-release
1051 * signals only on sensitive, activatable icons.
1053 * Sensitive, but non-activatable icons can be used for purely
1054 * informational purposes.
1058 g_object_class_install_property (gobject_class,
1059 PROP_ACTIVATABLE_PRIMARY,
1060 g_param_spec_boolean ("primary-icon-activatable",
1061 P_("Primary icon activatable"),
1062 P_("Whether the primary icon is activatable"),
1064 GTK_PARAM_READWRITE));
1067 * GtkEntry:secondary-icon-activatable:
1069 * Whether the secondary icon is activatable.
1071 * GTK+ emits the #GtkEntry::icon-press and #GtkEntry::icon-release
1072 * signals only on sensitive, activatable icons.
1074 * Sensitive, but non-activatable icons can be used for purely
1075 * informational purposes.
1079 g_object_class_install_property (gobject_class,
1080 PROP_ACTIVATABLE_SECONDARY,
1081 g_param_spec_boolean ("secondary-icon-activatable",
1082 P_("Secondary icon activatable"),
1083 P_("Whether the secondary icon is activatable"),
1085 GTK_PARAM_READWRITE));
1089 * GtkEntry:primary-icon-sensitive:
1091 * Whether the primary icon is sensitive.
1093 * An insensitive icon appears grayed out. GTK+ does not emit the
1094 * #GtkEntry::icon-press and #GtkEntry::icon-release signals and
1095 * does not allow DND from insensitive icons.
1097 * An icon should be set insensitive if the action that would trigger
1098 * when clicked is currently not available.
1102 g_object_class_install_property (gobject_class,
1103 PROP_SENSITIVE_PRIMARY,
1104 g_param_spec_boolean ("primary-icon-sensitive",
1105 P_("Primary icon sensitive"),
1106 P_("Whether the primary icon is sensitive"),
1108 GTK_PARAM_READWRITE));
1111 * GtkEntry:secondary-icon-sensitive:
1113 * Whether the secondary icon is sensitive.
1115 * An insensitive icon appears grayed out. GTK+ does not emit the
1116 * #GtkEntry::icon-press and #GtkEntry::icon-release signals and
1117 * does not allow DND from insensitive icons.
1119 * An icon should be set insensitive if the action that would trigger
1120 * when clicked is currently not available.
1124 g_object_class_install_property (gobject_class,
1125 PROP_SENSITIVE_SECONDARY,
1126 g_param_spec_boolean ("secondary-icon-sensitive",
1127 P_("Secondary icon sensitive"),
1128 P_("Whether the secondary icon is sensitive"),
1130 GTK_PARAM_READWRITE));
1133 * GtkEntry:primary-icon-tooltip-text:
1135 * The contents of the tooltip on the primary icon.
1137 * Also see gtk_entry_set_icon_tooltip_text().
1141 g_object_class_install_property (gobject_class,
1142 PROP_TOOLTIP_TEXT_PRIMARY,
1143 g_param_spec_string ("primary-icon-tooltip-text",
1144 P_("Primary icon tooltip text"),
1145 P_("The contents of the tooltip on the primary icon"),
1147 GTK_PARAM_READWRITE));
1150 * GtkEntry:secondary-icon-tooltip-text:
1152 * The contents of the tooltip on the secondary icon.
1154 * Also see gtk_entry_set_icon_tooltip_text().
1158 g_object_class_install_property (gobject_class,
1159 PROP_TOOLTIP_TEXT_SECONDARY,
1160 g_param_spec_string ("secondary-icon-tooltip-text",
1161 P_("Secondary icon tooltip text"),
1162 P_("The contents of the tooltip on the secondary icon"),
1164 GTK_PARAM_READWRITE));
1167 * GtkEntry:primary-icon-tooltip-markup:
1169 * The contents of the tooltip on the primary icon, which is marked up
1170 * with the <link linkend="PangoMarkupFormat">Pango text markup
1173 * Also see gtk_entry_set_icon_tooltip_markup().
1177 g_object_class_install_property (gobject_class,
1178 PROP_TOOLTIP_MARKUP_PRIMARY,
1179 g_param_spec_string ("primary-icon-tooltip-markup",
1180 P_("Primary icon tooltip markup"),
1181 P_("The contents of the tooltip on the primary icon"),
1183 GTK_PARAM_READWRITE));
1186 * GtkEntry:secondary-icon-tooltip-markup:
1188 * The contents of the tooltip on the secondary icon, which is marked up
1189 * with the <link linkend="PangoMarkupFormat">Pango text markup
1192 * Also see gtk_entry_set_icon_tooltip_markup().
1196 g_object_class_install_property (gobject_class,
1197 PROP_TOOLTIP_MARKUP_SECONDARY,
1198 g_param_spec_string ("secondary-icon-tooltip-markup",
1199 P_("Secondary icon tooltip markup"),
1200 P_("The contents of the tooltip on the secondary icon"),
1202 GTK_PARAM_READWRITE));
1205 * GtkEntry:im-module:
1207 * Which IM (input method) module should be used for this entry.
1208 * See #GtkIMContext.
1210 * Setting this to a non-%NULL value overrides the
1211 * system-wide IM module setting. See the GtkSettings
1212 * #GtkSettings:gtk-im-module property.
1216 g_object_class_install_property (gobject_class,
1218 g_param_spec_string ("im-module",
1220 P_("Which IM module should be used"),
1222 GTK_PARAM_READWRITE));
1225 * GtkEntry:icon-prelight:
1227 * The prelight style property determines whether activatable
1228 * icons prelight on mouseover.
1232 gtk_widget_class_install_style_property (widget_class,
1233 g_param_spec_boolean ("icon-prelight",
1234 P_("Icon Prelight"),
1235 P_("Whether activatable icons should prelight when hovered"),
1237 GTK_PARAM_READABLE));
1240 * GtkEntry:progress-border:
1242 * The border around the progress bar in the entry.
1246 gtk_widget_class_install_style_property (widget_class,
1247 g_param_spec_boxed ("progress-border",
1248 P_("Progress Border"),
1249 P_("Border around the progress bar"),
1251 GTK_PARAM_READABLE));
1254 * GtkEntry:invisible-char:
1256 * The invisible character is used when masking entry contents (in
1257 * \"password mode\")"). When it is not explicitly set with the
1258 * #GtkEntry::invisible-char property, GTK+ determines the character
1259 * to use from a list of possible candidates, depending on availability
1260 * in the current font.
1262 * This style property allows the theme to prepend a character
1263 * to the list of candidates.
1267 gtk_widget_class_install_style_property (widget_class,
1268 g_param_spec_unichar ("invisible-char",
1269 P_("Invisible character"),
1270 P_("The character to use when masking entry contents (in \"password mode\")"),
1272 GTK_PARAM_READABLE));
1275 * GtkEntry::populate-popup:
1276 * @entry: The entry on which the signal is emitted
1277 * @menu: the menu that is being populated
1279 * The ::populate-popup signal gets emitted before showing the
1280 * context menu of the entry.
1282 * If you need to add items to the context menu, connect
1283 * to this signal and append your menuitems to the @menu.
1285 signals[POPULATE_POPUP] =
1286 g_signal_new (I_("populate-popup"),
1287 G_OBJECT_CLASS_TYPE (gobject_class),
1289 G_STRUCT_OFFSET (GtkEntryClass, populate_popup),
1291 _gtk_marshal_VOID__OBJECT,
1295 /* Action signals */
1298 * GtkEntry::activate:
1299 * @entry: The entry on which the signal is emitted
1301 * A <link linkend="keybinding-signals">keybinding signal</link>
1302 * which gets emitted when the user activates the entry.
1304 * Applications should not connect to it, but may emit it with
1305 * g_signal_emit_by_name() if they need to control activation
1308 * The default bindings for this signal are all forms of the Enter key.
1311 g_signal_new (I_("activate"),
1312 G_OBJECT_CLASS_TYPE (gobject_class),
1313 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1314 G_STRUCT_OFFSET (GtkEntryClass, activate),
1316 _gtk_marshal_VOID__VOID,
1318 widget_class->activate_signal = signals[ACTIVATE];
1321 * GtkEntry::move-cursor:
1322 * @entry: the object which received the signal
1323 * @step: the granularity of the move, as a #GtkMovementStep
1324 * @count: the number of @step units to move
1325 * @extend_selection: %TRUE if the move should extend the selection
1327 * The ::move-cursor signal is a
1328 * <link linkend="keybinding-signals">keybinding signal</link>
1329 * which gets emitted when the user initiates a cursor movement.
1330 * If the cursor is not visible in @entry, this signal causes
1331 * the viewport to be moved instead.
1333 * Applications should not connect to it, but may emit it with
1334 * g_signal_emit_by_name() if they need to control the cursor
1337 * The default bindings for this signal come in two variants,
1338 * the variant with the Shift modifier extends the selection,
1339 * the variant without the Shift modifer does not.
1340 * There are too many key combinations to list them all here.
1342 * <listitem>Arrow keys move by individual characters/lines</listitem>
1343 * <listitem>Ctrl-arrow key combinations move by words/paragraphs</listitem>
1344 * <listitem>Home/End keys move to the ends of the buffer</listitem>
1347 signals[MOVE_CURSOR] =
1348 g_signal_new (I_("move-cursor"),
1349 G_OBJECT_CLASS_TYPE (gobject_class),
1350 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1351 G_STRUCT_OFFSET (GtkEntryClass, move_cursor),
1353 _gtk_marshal_VOID__ENUM_INT_BOOLEAN,
1355 GTK_TYPE_MOVEMENT_STEP,
1360 * GtkEntry::insert-at-cursor:
1361 * @entry: the object which received the signal
1362 * @string: the string to insert
1364 * The ::insert-at-cursor signal is a
1365 * <link linkend="keybinding-signals">keybinding signal</link>
1366 * which gets emitted when the user initiates the insertion of a
1367 * fixed string at the cursor.
1369 * This signal has no default bindings.
1371 signals[INSERT_AT_CURSOR] =
1372 g_signal_new (I_("insert-at-cursor"),
1373 G_OBJECT_CLASS_TYPE (gobject_class),
1374 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1375 G_STRUCT_OFFSET (GtkEntryClass, insert_at_cursor),
1377 _gtk_marshal_VOID__STRING,
1382 * GtkEntry::delete-from-cursor:
1383 * @entry: the object which received the signal
1384 * @type: the granularity of the deletion, as a #GtkDeleteType
1385 * @count: the number of @type units to delete
1387 * The ::delete-from-cursor signal is a
1388 * <link linkend="keybinding-signals">keybinding signal</link>
1389 * which gets emitted when the user initiates a text deletion.
1391 * If the @type is %GTK_DELETE_CHARS, GTK+ deletes the selection
1392 * if there is one, otherwise it deletes the requested number
1395 * The default bindings for this signal are
1396 * Delete for deleting a character and Ctrl-Delete for
1399 signals[DELETE_FROM_CURSOR] =
1400 g_signal_new (I_("delete-from-cursor"),
1401 G_OBJECT_CLASS_TYPE (gobject_class),
1402 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1403 G_STRUCT_OFFSET (GtkEntryClass, delete_from_cursor),
1405 _gtk_marshal_VOID__ENUM_INT,
1407 GTK_TYPE_DELETE_TYPE,
1411 * GtkEntry::backspace:
1412 * @entry: the object which received the signal
1414 * The ::backspace signal is a
1415 * <link linkend="keybinding-signals">keybinding signal</link>
1416 * which gets emitted when the user asks for it.
1418 * The default bindings for this signal are
1419 * Backspace and Shift-Backspace.
1421 signals[BACKSPACE] =
1422 g_signal_new (I_("backspace"),
1423 G_OBJECT_CLASS_TYPE (gobject_class),
1424 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1425 G_STRUCT_OFFSET (GtkEntryClass, backspace),
1427 _gtk_marshal_VOID__VOID,
1431 * GtkEntry::cut-clipboard:
1432 * @entry: the object which received the signal
1434 * The ::cut-clipboard signal is a
1435 * <link linkend="keybinding-signals">keybinding signal</link>
1436 * which gets emitted to cut the selection to the clipboard.
1438 * The default bindings for this signal are
1439 * Ctrl-x and Shift-Delete.
1441 signals[CUT_CLIPBOARD] =
1442 g_signal_new (I_("cut-clipboard"),
1443 G_OBJECT_CLASS_TYPE (gobject_class),
1444 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1445 G_STRUCT_OFFSET (GtkEntryClass, cut_clipboard),
1447 _gtk_marshal_VOID__VOID,
1451 * GtkEntry::copy-clipboard:
1452 * @entry: the object which received the signal
1454 * The ::copy-clipboard signal is a
1455 * <link linkend="keybinding-signals">keybinding signal</link>
1456 * which gets emitted to copy the selection to the clipboard.
1458 * The default bindings for this signal are
1459 * Ctrl-c and Ctrl-Insert.
1461 signals[COPY_CLIPBOARD] =
1462 g_signal_new (I_("copy-clipboard"),
1463 G_OBJECT_CLASS_TYPE (gobject_class),
1464 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1465 G_STRUCT_OFFSET (GtkEntryClass, copy_clipboard),
1467 _gtk_marshal_VOID__VOID,
1471 * GtkEntry::paste-clipboard:
1472 * @entry: the object which received the signal
1474 * The ::paste-clipboard signal is a
1475 * <link linkend="keybinding-signals">keybinding signal</link>
1476 * which gets emitted to paste the contents of the clipboard
1477 * into the text view.
1479 * The default bindings for this signal are
1480 * Ctrl-v and Shift-Insert.
1482 signals[PASTE_CLIPBOARD] =
1483 g_signal_new (I_("paste-clipboard"),
1484 G_OBJECT_CLASS_TYPE (gobject_class),
1485 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1486 G_STRUCT_OFFSET (GtkEntryClass, paste_clipboard),
1488 _gtk_marshal_VOID__VOID,
1492 * GtkEntry::toggle-overwrite:
1493 * @entry: the object which received the signal
1495 * The ::toggle-overwrite signal is a
1496 * <link linkend="keybinding-signals">keybinding signal</link>
1497 * which gets emitted to toggle the overwrite mode of the entry.
1499 * The default bindings for this signal is Insert.
1501 signals[TOGGLE_OVERWRITE] =
1502 g_signal_new (I_("toggle-overwrite"),
1503 G_OBJECT_CLASS_TYPE (gobject_class),
1504 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1505 G_STRUCT_OFFSET (GtkEntryClass, toggle_overwrite),
1507 _gtk_marshal_VOID__VOID,
1511 * GtkEntry::icon-press:
1512 * @entry: The entry on which the signal is emitted
1513 * @icon_pos: The position of the clicked icon
1514 * @event: the button press event
1516 * The ::icon-press signal is emitted when an activatable icon
1521 signals[ICON_PRESS] =
1522 g_signal_new (I_("icon-press"),
1523 G_TYPE_FROM_CLASS (gobject_class),
1527 _gtk_marshal_VOID__ENUM_BOXED,
1529 GTK_TYPE_ENTRY_ICON_POSITION,
1530 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1533 * GtkEntry::icon-release:
1534 * @entry: The entry on which the signal is emitted
1535 * @icon_pos: The position of the clicked icon
1536 * @event: the button release event
1538 * The ::icon-release signal is emitted on the button release from a
1539 * mouse click over an activatable icon.
1543 signals[ICON_RELEASE] =
1544 g_signal_new (I_("icon-release"),
1545 G_TYPE_FROM_CLASS (gobject_class),
1549 _gtk_marshal_VOID__ENUM_BOXED,
1551 GTK_TYPE_ENTRY_ICON_POSITION,
1552 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1555 * GtkEntry::preedit-changed:
1556 * @entry: the object which received the signal
1557 * @preedit: the current preedit string
1559 * If an input method is used, the typed text will not immediately
1560 * be committed to the buffer. So if you are interested in the text,
1561 * connect to this signal.
1565 signals[PREEDIT_CHANGED] =
1566 g_signal_new_class_handler (I_("preedit-changed"),
1567 G_OBJECT_CLASS_TYPE (gobject_class),
1568 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1571 _gtk_marshal_VOID__STRING,
1580 binding_set = gtk_binding_set_by_class (class);
1582 /* Moving the insertion point */
1583 add_move_binding (binding_set, GDK_KEY_Right, 0,
1584 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1586 add_move_binding (binding_set, GDK_KEY_Left, 0,
1587 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1589 add_move_binding (binding_set, GDK_KEY_KP_Right, 0,
1590 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1592 add_move_binding (binding_set, GDK_KEY_KP_Left, 0,
1593 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1595 add_move_binding (binding_set, GDK_KEY_Right, GDK_CONTROL_MASK,
1596 GTK_MOVEMENT_WORDS, 1);
1598 add_move_binding (binding_set, GDK_KEY_Left, GDK_CONTROL_MASK,
1599 GTK_MOVEMENT_WORDS, -1);
1601 add_move_binding (binding_set, GDK_KEY_KP_Right, GDK_CONTROL_MASK,
1602 GTK_MOVEMENT_WORDS, 1);
1604 add_move_binding (binding_set, GDK_KEY_KP_Left, GDK_CONTROL_MASK,
1605 GTK_MOVEMENT_WORDS, -1);
1607 add_move_binding (binding_set, GDK_KEY_Home, 0,
1608 GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
1610 add_move_binding (binding_set, GDK_KEY_End, 0,
1611 GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
1613 add_move_binding (binding_set, GDK_KEY_KP_Home, 0,
1614 GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
1616 add_move_binding (binding_set, GDK_KEY_KP_End, 0,
1617 GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
1619 add_move_binding (binding_set, GDK_KEY_Home, GDK_CONTROL_MASK,
1620 GTK_MOVEMENT_BUFFER_ENDS, -1);
1622 add_move_binding (binding_set, GDK_KEY_End, GDK_CONTROL_MASK,
1623 GTK_MOVEMENT_BUFFER_ENDS, 1);
1625 add_move_binding (binding_set, GDK_KEY_KP_Home, GDK_CONTROL_MASK,
1626 GTK_MOVEMENT_BUFFER_ENDS, -1);
1628 add_move_binding (binding_set, GDK_KEY_KP_End, GDK_CONTROL_MASK,
1629 GTK_MOVEMENT_BUFFER_ENDS, 1);
1633 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK,
1635 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1637 G_TYPE_BOOLEAN, FALSE);
1638 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK,
1640 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1642 G_TYPE_BOOLEAN, TRUE);
1644 gtk_binding_entry_add_signal (binding_set, GDK_KEY_slash, GDK_CONTROL_MASK,
1646 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1648 G_TYPE_BOOLEAN, FALSE);
1649 gtk_binding_entry_add_signal (binding_set, GDK_KEY_slash, GDK_CONTROL_MASK,
1651 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1653 G_TYPE_BOOLEAN, TRUE);
1656 gtk_binding_entry_add_signal (binding_set, GDK_KEY_backslash, GDK_CONTROL_MASK,
1658 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_VISUAL_POSITIONS,
1660 G_TYPE_BOOLEAN, FALSE);
1661 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_SHIFT_MASK | GDK_CONTROL_MASK,
1663 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_VISUAL_POSITIONS,
1665 G_TYPE_BOOLEAN, FALSE);
1669 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Return, 0,
1671 gtk_binding_entry_add_signal (binding_set, GDK_KEY_ISO_Enter, 0,
1673 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Enter, 0,
1677 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, 0,
1678 "delete-from-cursor", 2,
1679 G_TYPE_ENUM, GTK_DELETE_CHARS,
1682 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Delete, 0,
1683 "delete-from-cursor", 2,
1684 G_TYPE_ENUM, GTK_DELETE_CHARS,
1687 gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, 0,
1690 /* Make this do the same as Backspace, to help with mis-typing */
1691 gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, GDK_SHIFT_MASK,
1694 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, GDK_CONTROL_MASK,
1695 "delete-from-cursor", 2,
1696 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1699 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Delete, GDK_CONTROL_MASK,
1700 "delete-from-cursor", 2,
1701 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1704 gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, GDK_CONTROL_MASK,
1705 "delete-from-cursor", 2,
1706 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1709 /* Cut/copy/paste */
1711 gtk_binding_entry_add_signal (binding_set, GDK_KEY_x, GDK_CONTROL_MASK,
1712 "cut-clipboard", 0);
1713 gtk_binding_entry_add_signal (binding_set, GDK_KEY_c, GDK_CONTROL_MASK,
1714 "copy-clipboard", 0);
1715 gtk_binding_entry_add_signal (binding_set, GDK_KEY_v, GDK_CONTROL_MASK,
1716 "paste-clipboard", 0);
1718 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, GDK_SHIFT_MASK,
1719 "cut-clipboard", 0);
1720 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, GDK_CONTROL_MASK,
1721 "copy-clipboard", 0);
1722 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, GDK_SHIFT_MASK,
1723 "paste-clipboard", 0);
1726 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, 0,
1727 "toggle-overwrite", 0);
1728 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Insert, 0,
1729 "toggle-overwrite", 0);
1732 * GtkEntry:inner-border:
1734 * Sets the text area's border between the text and the frame.
1738 gtk_widget_class_install_style_property (widget_class,
1739 g_param_spec_boxed ("inner-border",
1741 P_("Border between text and frame."),
1743 GTK_PARAM_READABLE));
1745 g_type_class_add_private (gobject_class, sizeof (GtkEntryPrivate));
1749 gtk_entry_editable_init (GtkEditableInterface *iface)
1751 iface->do_insert_text = gtk_entry_insert_text;
1752 iface->do_delete_text = gtk_entry_delete_text;
1753 iface->insert_text = gtk_entry_real_insert_text;
1754 iface->delete_text = gtk_entry_real_delete_text;
1755 iface->get_chars = gtk_entry_get_chars;
1756 iface->set_selection_bounds = gtk_entry_set_selection_bounds;
1757 iface->get_selection_bounds = gtk_entry_get_selection_bounds;
1758 iface->set_position = gtk_entry_real_set_position;
1759 iface->get_position = gtk_entry_get_position;
1763 gtk_entry_cell_editable_init (GtkCellEditableIface *iface)
1765 iface->start_editing = gtk_entry_start_editing;
1769 gtk_entry_set_property (GObject *object,
1771 const GValue *value,
1774 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (object);
1775 GtkEntry *entry = GTK_ENTRY (object);
1781 gtk_entry_set_buffer (entry, g_value_get_object (value));
1786 gboolean new_value = g_value_get_boolean (value);
1788 if (new_value != entry->editable)
1790 widget = GTK_WIDGET (entry);
1793 _gtk_entry_reset_im_context (entry);
1794 if (gtk_widget_has_focus (widget))
1795 gtk_im_context_focus_out (entry->im_context);
1797 entry->preedit_length = 0;
1798 entry->preedit_cursor = 0;
1801 entry->editable = new_value;
1803 if (new_value && gtk_widget_has_focus (widget))
1804 gtk_im_context_focus_in (entry->im_context);
1806 gtk_entry_queue_draw (entry);
1811 case PROP_MAX_LENGTH:
1812 gtk_entry_set_max_length (entry, g_value_get_int (value));
1815 case PROP_VISIBILITY:
1816 gtk_entry_set_visibility (entry, g_value_get_boolean (value));
1819 case PROP_HAS_FRAME:
1820 gtk_entry_set_has_frame (entry, g_value_get_boolean (value));
1823 case PROP_INNER_BORDER:
1824 gtk_entry_set_inner_border (entry, g_value_get_boxed (value));
1827 case PROP_INVISIBLE_CHAR:
1828 gtk_entry_set_invisible_char (entry, g_value_get_uint (value));
1831 case PROP_ACTIVATES_DEFAULT:
1832 gtk_entry_set_activates_default (entry, g_value_get_boolean (value));
1835 case PROP_WIDTH_CHARS:
1836 gtk_entry_set_width_chars (entry, g_value_get_int (value));
1840 gtk_entry_set_text (entry, g_value_get_string (value));
1844 gtk_entry_set_alignment (entry, g_value_get_float (value));
1847 case PROP_TRUNCATE_MULTILINE:
1848 entry->truncate_multiline = g_value_get_boolean (value);
1851 case PROP_SHADOW_TYPE:
1852 priv->shadow_type = g_value_get_enum (value);
1855 case PROP_OVERWRITE_MODE:
1856 gtk_entry_set_overwrite_mode (entry, g_value_get_boolean (value));
1859 case PROP_INVISIBLE_CHAR_SET:
1860 if (g_value_get_boolean (value))
1861 priv->invisible_char_set = TRUE;
1863 gtk_entry_unset_invisible_char (entry);
1866 case PROP_CAPS_LOCK_WARNING:
1867 priv->caps_lock_warning = g_value_get_boolean (value);
1870 case PROP_PROGRESS_FRACTION:
1871 gtk_entry_set_progress_fraction (entry, g_value_get_double (value));
1874 case PROP_PROGRESS_PULSE_STEP:
1875 gtk_entry_set_progress_pulse_step (entry, g_value_get_double (value));
1878 case PROP_PIXBUF_PRIMARY:
1879 gtk_entry_set_icon_from_pixbuf (entry,
1880 GTK_ENTRY_ICON_PRIMARY,
1881 g_value_get_object (value));
1884 case PROP_PIXBUF_SECONDARY:
1885 gtk_entry_set_icon_from_pixbuf (entry,
1886 GTK_ENTRY_ICON_SECONDARY,
1887 g_value_get_object (value));
1890 case PROP_STOCK_PRIMARY:
1891 gtk_entry_set_icon_from_stock (entry,
1892 GTK_ENTRY_ICON_PRIMARY,
1893 g_value_get_string (value));
1896 case PROP_STOCK_SECONDARY:
1897 gtk_entry_set_icon_from_stock (entry,
1898 GTK_ENTRY_ICON_SECONDARY,
1899 g_value_get_string (value));
1902 case PROP_ICON_NAME_PRIMARY:
1903 gtk_entry_set_icon_from_icon_name (entry,
1904 GTK_ENTRY_ICON_PRIMARY,
1905 g_value_get_string (value));
1908 case PROP_ICON_NAME_SECONDARY:
1909 gtk_entry_set_icon_from_icon_name (entry,
1910 GTK_ENTRY_ICON_SECONDARY,
1911 g_value_get_string (value));
1914 case PROP_GICON_PRIMARY:
1915 gtk_entry_set_icon_from_gicon (entry,
1916 GTK_ENTRY_ICON_PRIMARY,
1917 g_value_get_object (value));
1920 case PROP_GICON_SECONDARY:
1921 gtk_entry_set_icon_from_gicon (entry,
1922 GTK_ENTRY_ICON_SECONDARY,
1923 g_value_get_object (value));
1926 case PROP_ACTIVATABLE_PRIMARY:
1927 gtk_entry_set_icon_activatable (entry,
1928 GTK_ENTRY_ICON_PRIMARY,
1929 g_value_get_boolean (value));
1932 case PROP_ACTIVATABLE_SECONDARY:
1933 gtk_entry_set_icon_activatable (entry,
1934 GTK_ENTRY_ICON_SECONDARY,
1935 g_value_get_boolean (value));
1938 case PROP_SENSITIVE_PRIMARY:
1939 gtk_entry_set_icon_sensitive (entry,
1940 GTK_ENTRY_ICON_PRIMARY,
1941 g_value_get_boolean (value));
1944 case PROP_SENSITIVE_SECONDARY:
1945 gtk_entry_set_icon_sensitive (entry,
1946 GTK_ENTRY_ICON_SECONDARY,
1947 g_value_get_boolean (value));
1950 case PROP_TOOLTIP_TEXT_PRIMARY:
1951 gtk_entry_set_icon_tooltip_text (entry,
1952 GTK_ENTRY_ICON_PRIMARY,
1953 g_value_get_string (value));
1956 case PROP_TOOLTIP_TEXT_SECONDARY:
1957 gtk_entry_set_icon_tooltip_text (entry,
1958 GTK_ENTRY_ICON_SECONDARY,
1959 g_value_get_string (value));
1962 case PROP_TOOLTIP_MARKUP_PRIMARY:
1963 gtk_entry_set_icon_tooltip_markup (entry,
1964 GTK_ENTRY_ICON_PRIMARY,
1965 g_value_get_string (value));
1968 case PROP_TOOLTIP_MARKUP_SECONDARY:
1969 gtk_entry_set_icon_tooltip_markup (entry,
1970 GTK_ENTRY_ICON_SECONDARY,
1971 g_value_get_string (value));
1974 case PROP_IM_MODULE:
1975 g_free (priv->im_module);
1976 priv->im_module = g_value_dup_string (value);
1977 if (GTK_IS_IM_MULTICONTEXT (entry->im_context))
1978 gtk_im_multicontext_set_context_id (GTK_IM_MULTICONTEXT (entry->im_context), priv->im_module);
1981 case PROP_EDITING_CANCELED:
1982 entry->editing_canceled = g_value_get_boolean (value);
1985 case PROP_SCROLL_OFFSET:
1986 case PROP_CURSOR_POSITION:
1988 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1994 gtk_entry_get_property (GObject *object,
1999 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (object);
2000 GtkEntry *entry = GTK_ENTRY (object);
2005 g_value_set_object (value, gtk_entry_get_buffer (entry));
2008 case PROP_CURSOR_POSITION:
2009 g_value_set_int (value, entry->current_pos);
2012 case PROP_SELECTION_BOUND:
2013 g_value_set_int (value, entry->selection_bound);
2017 g_value_set_boolean (value, entry->editable);
2020 case PROP_MAX_LENGTH:
2021 g_value_set_int (value, gtk_entry_buffer_get_max_length (get_buffer (entry)));
2024 case PROP_VISIBILITY:
2025 g_value_set_boolean (value, entry->visible);
2028 case PROP_HAS_FRAME:
2029 g_value_set_boolean (value, entry->has_frame);
2032 case PROP_INNER_BORDER:
2033 g_value_set_boxed (value, gtk_entry_get_inner_border (entry));
2036 case PROP_INVISIBLE_CHAR:
2037 g_value_set_uint (value, entry->invisible_char);
2040 case PROP_ACTIVATES_DEFAULT:
2041 g_value_set_boolean (value, entry->activates_default);
2044 case PROP_WIDTH_CHARS:
2045 g_value_set_int (value, entry->width_chars);
2048 case PROP_SCROLL_OFFSET:
2049 g_value_set_int (value, entry->scroll_offset);
2053 g_value_set_string (value, gtk_entry_get_text (entry));
2057 g_value_set_float (value, gtk_entry_get_alignment (entry));
2060 case PROP_TRUNCATE_MULTILINE:
2061 g_value_set_boolean (value, entry->truncate_multiline);
2064 case PROP_SHADOW_TYPE:
2065 g_value_set_enum (value, priv->shadow_type);
2068 case PROP_OVERWRITE_MODE:
2069 g_value_set_boolean (value, entry->overwrite_mode);
2072 case PROP_TEXT_LENGTH:
2073 g_value_set_uint (value, gtk_entry_buffer_get_length (get_buffer (entry)));
2076 case PROP_INVISIBLE_CHAR_SET:
2077 g_value_set_boolean (value, priv->invisible_char_set);
2080 case PROP_IM_MODULE:
2081 g_value_set_string (value, priv->im_module);
2084 case PROP_CAPS_LOCK_WARNING:
2085 g_value_set_boolean (value, priv->caps_lock_warning);
2088 case PROP_PROGRESS_FRACTION:
2089 g_value_set_double (value, priv->progress_fraction);
2092 case PROP_PROGRESS_PULSE_STEP:
2093 g_value_set_double (value, priv->progress_pulse_fraction);
2096 case PROP_PIXBUF_PRIMARY:
2097 g_value_set_object (value,
2098 gtk_entry_get_icon_pixbuf (entry,
2099 GTK_ENTRY_ICON_PRIMARY));
2102 case PROP_PIXBUF_SECONDARY:
2103 g_value_set_object (value,
2104 gtk_entry_get_icon_pixbuf (entry,
2105 GTK_ENTRY_ICON_SECONDARY));
2108 case PROP_STOCK_PRIMARY:
2109 g_value_set_string (value,
2110 gtk_entry_get_icon_stock (entry,
2111 GTK_ENTRY_ICON_PRIMARY));
2114 case PROP_STOCK_SECONDARY:
2115 g_value_set_string (value,
2116 gtk_entry_get_icon_stock (entry,
2117 GTK_ENTRY_ICON_SECONDARY));
2120 case PROP_ICON_NAME_PRIMARY:
2121 g_value_set_string (value,
2122 gtk_entry_get_icon_name (entry,
2123 GTK_ENTRY_ICON_PRIMARY));
2126 case PROP_ICON_NAME_SECONDARY:
2127 g_value_set_string (value,
2128 gtk_entry_get_icon_name (entry,
2129 GTK_ENTRY_ICON_SECONDARY));
2132 case PROP_GICON_PRIMARY:
2133 g_value_set_object (value,
2134 gtk_entry_get_icon_gicon (entry,
2135 GTK_ENTRY_ICON_PRIMARY));
2138 case PROP_GICON_SECONDARY:
2139 g_value_set_object (value,
2140 gtk_entry_get_icon_gicon (entry,
2141 GTK_ENTRY_ICON_SECONDARY));
2144 case PROP_STORAGE_TYPE_PRIMARY:
2145 g_value_set_enum (value,
2146 gtk_entry_get_icon_storage_type (entry,
2147 GTK_ENTRY_ICON_PRIMARY));
2150 case PROP_STORAGE_TYPE_SECONDARY:
2151 g_value_set_enum (value,
2152 gtk_entry_get_icon_storage_type (entry,
2153 GTK_ENTRY_ICON_SECONDARY));
2156 case PROP_ACTIVATABLE_PRIMARY:
2157 g_value_set_boolean (value,
2158 gtk_entry_get_icon_activatable (entry, GTK_ENTRY_ICON_PRIMARY));
2161 case PROP_ACTIVATABLE_SECONDARY:
2162 g_value_set_boolean (value,
2163 gtk_entry_get_icon_activatable (entry, GTK_ENTRY_ICON_SECONDARY));
2166 case PROP_SENSITIVE_PRIMARY:
2167 g_value_set_boolean (value,
2168 gtk_entry_get_icon_sensitive (entry, GTK_ENTRY_ICON_PRIMARY));
2171 case PROP_SENSITIVE_SECONDARY:
2172 g_value_set_boolean (value,
2173 gtk_entry_get_icon_sensitive (entry, GTK_ENTRY_ICON_SECONDARY));
2176 case PROP_TOOLTIP_TEXT_PRIMARY:
2177 g_value_take_string (value,
2178 gtk_entry_get_icon_tooltip_text (entry, GTK_ENTRY_ICON_PRIMARY));
2181 case PROP_TOOLTIP_TEXT_SECONDARY:
2182 g_value_take_string (value,
2183 gtk_entry_get_icon_tooltip_text (entry, GTK_ENTRY_ICON_SECONDARY));
2186 case PROP_TOOLTIP_MARKUP_PRIMARY:
2187 g_value_take_string (value,
2188 gtk_entry_get_icon_tooltip_markup (entry, GTK_ENTRY_ICON_PRIMARY));
2191 case PROP_TOOLTIP_MARKUP_SECONDARY:
2192 g_value_take_string (value,
2193 gtk_entry_get_icon_tooltip_markup (entry, GTK_ENTRY_ICON_SECONDARY));
2196 case PROP_EDITING_CANCELED:
2197 g_value_set_boolean (value,
2198 entry->editing_canceled);
2202 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2208 find_invisible_char (GtkWidget *widget)
2210 PangoLayout *layout;
2211 PangoAttrList *attr_list;
2213 gunichar invisible_chars [] = {
2215 0x25cf, /* BLACK CIRCLE */
2216 0x2022, /* BULLET */
2217 0x2731, /* HEAVY ASTERISK */
2218 0x273a /* SIXTEEN POINTED ASTERISK */
2221 if (gtk_widget_get_style (widget))
2222 gtk_widget_style_get (widget,
2223 "invisible-char", &invisible_chars[0],
2226 layout = gtk_widget_create_pango_layout (widget, NULL);
2228 attr_list = pango_attr_list_new ();
2229 pango_attr_list_insert (attr_list, pango_attr_fallback_new (FALSE));
2231 pango_layout_set_attributes (layout, attr_list);
2232 pango_attr_list_unref (attr_list);
2234 for (i = (invisible_chars[0] != 0 ? 0 : 1); i < G_N_ELEMENTS (invisible_chars); i++)
2236 gchar text[7] = { 0, };
2239 len = g_unichar_to_utf8 (invisible_chars[i], text);
2240 pango_layout_set_text (layout, text, len);
2242 count = pango_layout_get_unknown_glyphs_count (layout);
2246 g_object_unref (layout);
2247 return invisible_chars[i];
2251 g_object_unref (layout);
2257 gtk_entry_init (GtkEntry *entry)
2259 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2261 gtk_widget_set_can_focus (GTK_WIDGET (entry), TRUE);
2262 gtk_widget_set_has_window (GTK_WIDGET (entry), FALSE);
2264 entry->editable = TRUE;
2265 entry->visible = TRUE;
2266 entry->invisible_char = find_invisible_char (GTK_WIDGET (entry));
2267 entry->dnd_position = -1;
2268 entry->width_chars = -1;
2269 entry->is_cell_renderer = FALSE;
2270 entry->editing_canceled = FALSE;
2271 entry->has_frame = TRUE;
2272 entry->truncate_multiline = FALSE;
2273 priv->shadow_type = GTK_SHADOW_IN;
2275 priv->caps_lock_warning = TRUE;
2276 priv->caps_lock_warning_shown = FALSE;
2277 priv->progress_fraction = 0.0;
2278 priv->progress_pulse_fraction = 0.1;
2280 gtk_drag_dest_set (GTK_WIDGET (entry),
2281 GTK_DEST_DEFAULT_HIGHLIGHT,
2283 GDK_ACTION_COPY | GDK_ACTION_MOVE);
2284 gtk_drag_dest_add_text_targets (GTK_WIDGET (entry));
2286 /* This object is completely private. No external entity can gain a reference
2287 * to it; so we create it here and destroy it in finalize().
2289 entry->im_context = gtk_im_multicontext_new ();
2291 g_signal_connect (entry->im_context, "commit",
2292 G_CALLBACK (gtk_entry_commit_cb), entry);
2293 g_signal_connect (entry->im_context, "preedit-changed",
2294 G_CALLBACK (gtk_entry_preedit_changed_cb), entry);
2295 g_signal_connect (entry->im_context, "retrieve-surrounding",
2296 G_CALLBACK (gtk_entry_retrieve_surrounding_cb), entry);
2297 g_signal_connect (entry->im_context, "delete-surrounding",
2298 G_CALLBACK (gtk_entry_delete_surrounding_cb), entry);
2303 get_icon_width (GtkEntry *entry,
2304 GtkEntryIconPosition icon_pos)
2306 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2307 EntryIconInfo *icon_info = priv->icons[icon_pos];
2309 GtkSettings *settings;
2310 gint menu_icon_width;
2312 if (!icon_info || icon_info->pixbuf == NULL)
2315 screen = gtk_widget_get_screen (GTK_WIDGET (entry));
2316 settings = gtk_settings_get_for_screen (screen);
2318 gtk_icon_size_lookup_for_settings (settings, GTK_ICON_SIZE_MENU,
2319 &menu_icon_width, NULL);
2321 return MAX (gdk_pixbuf_get_width (icon_info->pixbuf), menu_icon_width);
2325 get_icon_allocations (GtkEntry *entry,
2326 GtkAllocation *primary,
2327 GtkAllocation *secondary)
2330 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2331 gint x, y, width, height;
2333 get_text_area_size (entry, &x, &y, &width, &height);
2335 if (gtk_widget_has_focus (GTK_WIDGET (entry)) && !priv->interior_focus)
2336 y += priv->focus_width;
2339 primary->height = height;
2340 primary->width = get_icon_width (entry, GTK_ENTRY_ICON_PRIMARY);
2341 if (primary->width > 0)
2342 primary->width += 2 * priv->icon_margin;
2345 secondary->height = height;
2346 secondary->width = get_icon_width (entry, GTK_ENTRY_ICON_SECONDARY);
2347 if (secondary->width > 0)
2348 secondary->width += 2 * priv->icon_margin;
2350 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
2352 primary->x = x + width - primary->width;
2358 secondary->x = x + width - secondary->width;
2364 begin_change (GtkEntry *entry)
2366 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2368 priv->change_count++;
2372 end_change (GtkEntry *entry)
2374 GtkEditable *editable = GTK_EDITABLE (entry);
2375 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2377 g_return_if_fail (priv->change_count > 0);
2379 priv->change_count--;
2381 if (priv->change_count == 0)
2383 if (priv->real_changed)
2385 g_signal_emit_by_name (editable, "changed");
2386 priv->real_changed = FALSE;
2392 emit_changed (GtkEntry *entry)
2394 GtkEditable *editable = GTK_EDITABLE (entry);
2395 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2397 if (priv->change_count == 0)
2398 g_signal_emit_by_name (editable, "changed");
2400 priv->real_changed = TRUE;
2404 gtk_entry_destroy (GtkWidget *widget)
2406 GtkEntry *entry = GTK_ENTRY (widget);
2408 entry->current_pos = entry->selection_bound = 0;
2409 _gtk_entry_reset_im_context (entry);
2410 gtk_entry_reset_layout (entry);
2412 if (entry->blink_timeout)
2414 g_source_remove (entry->blink_timeout);
2415 entry->blink_timeout = 0;
2418 if (entry->recompute_idle)
2420 g_source_remove (entry->recompute_idle);
2421 entry->recompute_idle = 0;
2424 GTK_WIDGET_CLASS (gtk_entry_parent_class)->destroy (widget);
2428 gtk_entry_dispose (GObject *object)
2430 GtkEntry *entry = GTK_ENTRY (object);
2431 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2433 gtk_entry_set_icon_from_pixbuf (entry, GTK_ENTRY_ICON_PRIMARY, NULL);
2434 gtk_entry_set_icon_tooltip_markup (entry, GTK_ENTRY_ICON_PRIMARY, NULL);
2435 gtk_entry_set_icon_from_pixbuf (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
2436 gtk_entry_set_icon_tooltip_markup (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
2440 buffer_disconnect_signals (entry);
2441 g_object_unref (priv->buffer);
2442 priv->buffer = NULL;
2445 G_OBJECT_CLASS (gtk_entry_parent_class)->dispose (object);
2449 gtk_entry_finalize (GObject *object)
2451 GtkEntry *entry = GTK_ENTRY (object);
2452 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2453 EntryIconInfo *icon_info = NULL;
2456 for (i = 0; i < MAX_ICONS; i++)
2458 if ((icon_info = priv->icons[i]) != NULL)
2460 if (icon_info->target_list != NULL)
2462 gtk_target_list_unref (icon_info->target_list);
2463 icon_info->target_list = NULL;
2466 g_slice_free (EntryIconInfo, icon_info);
2467 priv->icons[i] = NULL;
2471 gtk_entry_set_completion (entry, NULL);
2473 if (entry->cached_layout)
2474 g_object_unref (entry->cached_layout);
2476 g_object_unref (entry->im_context);
2478 if (entry->blink_timeout)
2479 g_source_remove (entry->blink_timeout);
2481 if (entry->recompute_idle)
2482 g_source_remove (entry->recompute_idle);
2484 g_free (priv->im_module);
2486 G_OBJECT_CLASS (gtk_entry_parent_class)->finalize (object);
2490 gtk_entry_get_display_mode (GtkEntry *entry)
2492 GtkEntryPrivate *priv;
2494 return DISPLAY_NORMAL;
2495 priv = GTK_ENTRY_GET_PRIVATE (entry);
2496 if (entry->invisible_char == 0 && priv->invisible_char_set)
2497 return DISPLAY_BLANK;
2498 return DISPLAY_INVISIBLE;
2502 gtk_entry_get_display_text (GtkEntry *entry,
2506 GtkEntryPasswordHint *password_hint;
2507 GtkEntryPrivate *priv;
2508 gunichar invisible_char;
2518 priv = GTK_ENTRY_GET_PRIVATE (entry);
2519 text = gtk_entry_buffer_get_text (get_buffer (entry));
2520 length = gtk_entry_buffer_get_length (get_buffer (entry));
2524 if (start_pos > length)
2527 if (end_pos <= start_pos)
2528 return g_strdup ("");
2529 else if (entry->visible)
2531 start = g_utf8_offset_to_pointer (text, start_pos);
2532 end = g_utf8_offset_to_pointer (start, end_pos - start_pos);
2533 return g_strndup (start, end - start);
2537 str = g_string_sized_new (length * 2);
2539 /* Figure out what our invisible char is and encode it */
2540 if (!entry->invisible_char)
2541 invisible_char = priv->invisible_char_set ? ' ' : '*';
2543 invisible_char = entry->invisible_char;
2544 char_len = g_unichar_to_utf8 (invisible_char, char_str);
2547 * Add hidden characters for each character in the text
2548 * buffer. If there is a password hint, then keep that
2549 * character visible.
2552 password_hint = g_object_get_qdata (G_OBJECT (entry), quark_password_hint);
2553 for (i = start_pos; i < end_pos; ++i)
2555 if (password_hint && i == password_hint->position)
2557 start = g_utf8_offset_to_pointer (text, i);
2558 g_string_append_len (str, start, g_utf8_next_char (start) - start);
2562 g_string_append_len (str, char_str, char_len);
2566 return g_string_free (str, FALSE);
2572 update_cursors (GtkWidget *widget)
2574 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2575 EntryIconInfo *icon_info = NULL;
2576 GdkDisplay *display;
2580 for (i = 0; i < MAX_ICONS; i++)
2582 if ((icon_info = priv->icons[i]) != NULL)
2584 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
2585 gdk_window_show_unraised (icon_info->window);
2587 /* The icon windows are not children of the visible entry window,
2588 * thus we can't just inherit the xterm cursor. Slight complication
2589 * here is that for the entry, insensitive => arrow cursor, but for
2590 * an icon in a sensitive entry, insensitive => xterm cursor.
2592 if (gtk_widget_is_sensitive (widget) &&
2593 (icon_info->insensitive ||
2594 (icon_info->nonactivatable && icon_info->target_list == NULL)))
2596 display = gtk_widget_get_display (widget);
2597 cursor = gdk_cursor_new_for_display (display, GDK_XTERM);
2598 gdk_window_set_cursor (icon_info->window, cursor);
2599 gdk_cursor_unref (cursor);
2603 gdk_window_set_cursor (icon_info->window, NULL);
2610 realize_icon_info (GtkWidget *widget,
2611 GtkEntryIconPosition icon_pos)
2613 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2614 EntryIconInfo *icon_info = priv->icons[icon_pos];
2615 GdkWindowAttr attributes;
2616 gint attributes_mask;
2618 g_return_if_fail (icon_info != NULL);
2622 attributes.width = 1;
2623 attributes.height = 1;
2624 attributes.window_type = GDK_WINDOW_CHILD;
2625 attributes.wclass = GDK_INPUT_ONLY;
2626 attributes.event_mask = gtk_widget_get_events (widget);
2627 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
2628 GDK_BUTTON_RELEASE_MASK |
2629 GDK_BUTTON1_MOTION_MASK |
2630 GDK_BUTTON3_MOTION_MASK |
2631 GDK_POINTER_MOTION_HINT_MASK |
2632 GDK_POINTER_MOTION_MASK |
2633 GDK_ENTER_NOTIFY_MASK |
2634 GDK_LEAVE_NOTIFY_MASK);
2635 attributes_mask = GDK_WA_X | GDK_WA_Y;
2637 icon_info->window = gdk_window_new (gtk_widget_get_window (widget),
2640 gdk_window_set_user_data (icon_info->window, widget);
2642 gtk_widget_queue_resize (widget);
2645 static EntryIconInfo*
2646 construct_icon_info (GtkWidget *widget,
2647 GtkEntryIconPosition icon_pos)
2649 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2650 EntryIconInfo *icon_info;
2652 g_return_val_if_fail (priv->icons[icon_pos] == NULL, NULL);
2654 icon_info = g_slice_new0 (EntryIconInfo);
2655 priv->icons[icon_pos] = icon_info;
2657 if (gtk_widget_get_realized (widget))
2658 realize_icon_info (widget, icon_pos);
2664 gtk_entry_map (GtkWidget *widget)
2666 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2667 EntryIconInfo *icon_info = NULL;
2670 GTK_WIDGET_CLASS (gtk_entry_parent_class)->map (widget);
2672 for (i = 0; i < MAX_ICONS; i++)
2674 if ((icon_info = priv->icons[i]) != NULL)
2676 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
2677 gdk_window_show (icon_info->window);
2681 update_cursors (widget);
2685 gtk_entry_unmap (GtkWidget *widget)
2687 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2688 EntryIconInfo *icon_info = NULL;
2691 for (i = 0; i < MAX_ICONS; i++)
2693 if ((icon_info = priv->icons[i]) != NULL)
2695 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
2696 gdk_window_hide (icon_info->window);
2700 GTK_WIDGET_CLASS (gtk_entry_parent_class)->unmap (widget);
2704 gtk_entry_realize (GtkWidget *widget)
2707 GtkEntryPrivate *priv;
2708 EntryIconInfo *icon_info;
2710 GdkWindowAttr attributes;
2711 gint attributes_mask;
2712 gint frame_x, frame_y;
2715 gtk_widget_set_realized (widget, TRUE);
2716 window = gtk_widget_get_parent_window (widget);
2717 gtk_widget_set_window (widget, window);
2718 g_object_ref (window);
2720 entry = GTK_ENTRY (widget);
2721 priv = GTK_ENTRY_GET_PRIVATE (entry);
2723 attributes.window_type = GDK_WINDOW_CHILD;
2724 attributes.wclass = GDK_INPUT_ONLY;
2725 attributes.event_mask = gtk_widget_get_events (widget);
2726 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
2727 GDK_BUTTON_RELEASE_MASK |
2728 GDK_BUTTON1_MOTION_MASK |
2729 GDK_BUTTON3_MOTION_MASK |
2730 GDK_POINTER_MOTION_HINT_MASK |
2731 GDK_POINTER_MOTION_MASK |
2732 GDK_ENTER_NOTIFY_MASK |
2733 GDK_LEAVE_NOTIFY_MASK);
2734 attributes_mask = GDK_WA_X | GDK_WA_Y;
2736 get_text_area_size (entry, &attributes.x, &attributes.y, &attributes.width, &attributes.height);
2738 get_frame_size (entry, &frame_x, &frame_y, NULL, NULL);
2739 attributes.x += frame_x;
2740 attributes.y += frame_y;
2742 if (gtk_widget_is_sensitive (widget))
2744 attributes.cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
2745 attributes_mask |= GDK_WA_CURSOR;
2748 entry->text_area = gdk_window_new (gtk_widget_get_window (widget),
2752 gdk_window_set_user_data (entry->text_area, entry);
2754 if (attributes_mask & GDK_WA_CURSOR)
2755 gdk_cursor_unref (attributes.cursor);
2757 gtk_widget_style_attach (widget);
2759 gdk_window_show (entry->text_area);
2761 gtk_im_context_set_client_window (entry->im_context, entry->text_area);
2763 gtk_entry_adjust_scroll (entry);
2764 gtk_entry_update_primary_selection (entry);
2767 /* If the icon positions are already setup, create their windows.
2768 * Otherwise if they don't exist yet, then construct_icon_info()
2769 * will create the windows once the widget is already realized.
2771 for (i = 0; i < MAX_ICONS; i++)
2773 if ((icon_info = priv->icons[i]) != NULL)
2775 if (icon_info->window == NULL)
2776 realize_icon_info (widget, i);
2782 gtk_entry_unrealize (GtkWidget *widget)
2784 GtkEntry *entry = GTK_ENTRY (widget);
2785 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2786 GtkClipboard *clipboard;
2787 EntryIconInfo *icon_info;
2790 gtk_entry_reset_layout (entry);
2792 gtk_im_context_set_client_window (entry->im_context, NULL);
2794 clipboard = gtk_widget_get_clipboard (widget, GDK_SELECTION_PRIMARY);
2795 if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (entry))
2796 gtk_clipboard_clear (clipboard);
2798 if (entry->text_area)
2800 gdk_window_set_user_data (entry->text_area, NULL);
2801 gdk_window_destroy (entry->text_area);
2802 entry->text_area = NULL;
2805 if (entry->popup_menu)
2807 gtk_widget_destroy (entry->popup_menu);
2808 entry->popup_menu = NULL;
2811 GTK_WIDGET_CLASS (gtk_entry_parent_class)->unrealize (widget);
2813 for (i = 0; i < MAX_ICONS; i++)
2815 if ((icon_info = priv->icons[i]) != NULL)
2817 if (icon_info->window != NULL)
2819 gdk_window_destroy (icon_info->window);
2820 icon_info->window = NULL;
2827 _gtk_entry_get_borders (GtkEntry *entry,
2831 GtkWidget *widget = GTK_WIDGET (entry);
2832 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2835 if (entry->has_frame)
2837 style = gtk_widget_get_style (widget);
2839 *xborder = style->xthickness;
2840 *yborder = style->ythickness;
2848 if (!priv->interior_focus)
2850 *xborder += priv->focus_width;
2851 *yborder += priv->focus_width;
2856 gtk_entry_size_request (GtkWidget *widget,
2857 GtkRequisition *requisition)
2859 GtkEntry *entry = GTK_ENTRY (widget);
2860 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2861 PangoFontMetrics *metrics;
2862 gint xborder, yborder;
2863 GtkBorder inner_border;
2864 PangoContext *context;
2865 int icon_widths = 0;
2868 gtk_widget_ensure_style (widget);
2869 context = gtk_widget_get_pango_context (widget);
2870 metrics = pango_context_get_metrics (context,
2871 gtk_widget_get_style (widget)->font_desc,
2872 pango_context_get_language (context));
2874 entry->ascent = pango_font_metrics_get_ascent (metrics);
2875 entry->descent = pango_font_metrics_get_descent (metrics);
2877 _gtk_entry_get_borders (entry, &xborder, &yborder);
2878 _gtk_entry_effective_inner_border (entry, &inner_border);
2880 if (entry->width_chars < 0)
2881 requisition->width = MIN_ENTRY_WIDTH + xborder * 2 + inner_border.left + inner_border.right;
2884 gint char_width = pango_font_metrics_get_approximate_char_width (metrics);
2885 gint digit_width = pango_font_metrics_get_approximate_digit_width (metrics);
2886 gint char_pixels = (MAX (char_width, digit_width) + PANGO_SCALE - 1) / PANGO_SCALE;
2888 requisition->width = char_pixels * entry->width_chars + xborder * 2 + inner_border.left + inner_border.right;
2891 requisition->height = PANGO_PIXELS (entry->ascent + entry->descent) + yborder * 2 + inner_border.top + inner_border.bottom;
2893 for (i = 0; i < MAX_ICONS; i++)
2895 icon_width = get_icon_width (entry, i);
2897 icon_widths += icon_width + 2 * priv->icon_margin;
2900 if (icon_widths > requisition->width)
2901 requisition->width += icon_widths;
2903 pango_font_metrics_unref (metrics);
2907 place_windows (GtkEntry *entry)
2909 GtkWidget *widget = GTK_WIDGET (entry);
2910 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2911 gint x, y, width, height;
2912 gint frame_x, frame_y;
2913 GtkAllocation primary;
2914 GtkAllocation secondary;
2915 EntryIconInfo *icon_info = NULL;
2917 get_frame_size (entry, &frame_x, &frame_y, NULL, NULL);
2918 get_text_area_size (entry, &x, &y, &width, &height);
2919 get_icon_allocations (entry, &primary, &secondary);
2921 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
2922 y += priv->focus_width;
2924 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
2925 x += secondary.width;
2928 width -= primary.width + secondary.width;
2932 primary.x += frame_x;
2933 primary.y += frame_y;
2934 secondary.x += frame_x;
2935 secondary.y += frame_y;
2937 if ((icon_info = priv->icons[GTK_ENTRY_ICON_PRIMARY]) != NULL)
2938 gdk_window_move_resize (icon_info->window,
2939 primary.x, primary.y,
2940 primary.width, primary.height);
2942 if ((icon_info = priv->icons[GTK_ENTRY_ICON_SECONDARY]) != NULL)
2943 gdk_window_move_resize (icon_info->window,
2944 secondary.x, secondary.y,
2945 secondary.width, secondary.height);
2947 gdk_window_move_resize (entry->text_area, x, y, width, height);
2951 gtk_entry_get_text_area_size (GtkEntry *entry,
2957 GtkWidget *widget = GTK_WIDGET (entry);
2958 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2959 GtkAllocation allocation;
2960 GtkRequisition requisition;
2962 gint xborder, yborder;
2964 gtk_widget_get_preferred_size (widget, &requisition, NULL);
2965 gtk_widget_get_allocation (widget, &allocation);
2966 _gtk_entry_get_borders (entry, &xborder, &yborder);
2968 if (gtk_widget_get_realized (widget))
2969 get_frame_size (entry, NULL, NULL, NULL, &frame_height);
2971 frame_height = requisition.height;
2973 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
2974 frame_height -= 2 * priv->focus_width;
2980 *y = frame_height / 2 - (requisition.height - yborder * 2) / 2;
2983 *width = allocation.width - xborder * 2;
2986 *height = requisition.height - yborder * 2;
2990 get_text_area_size (GtkEntry *entry,
2996 GtkEntryClass *class;
2998 g_return_if_fail (GTK_IS_ENTRY (entry));
3000 class = GTK_ENTRY_GET_CLASS (entry);
3002 if (class->get_text_area_size)
3003 class->get_text_area_size (entry, x, y, width, height);
3008 get_frame_size (GtkEntry *entry,
3014 GtkAllocation allocation;
3015 GtkRequisition requisition;
3016 GtkWidget *widget = GTK_WIDGET (entry);
3018 gtk_widget_get_preferred_size (widget, &requisition, NULL);
3019 gtk_widget_get_allocation (widget, &allocation);
3026 if (entry->is_cell_renderer)
3029 *y = allocation.y + (allocation.height - requisition.height) / 2;
3033 *width = allocation.width;
3037 if (entry->is_cell_renderer)
3038 *height = allocation.height;
3040 *height = requisition.height;
3045 _gtk_entry_effective_inner_border (GtkEntry *entry,
3048 GtkBorder *tmp_border;
3050 tmp_border = g_object_get_qdata (G_OBJECT (entry), quark_inner_border);
3054 *border = *tmp_border;
3058 gtk_widget_style_get (GTK_WIDGET (entry), "inner-border", &tmp_border, NULL);
3062 *border = *tmp_border;
3063 gtk_border_free (tmp_border);
3067 *border = default_inner_border;
3071 gtk_entry_size_allocate (GtkWidget *widget,
3072 GtkAllocation *allocation)
3074 GtkEntry *entry = GTK_ENTRY (widget);
3076 gtk_widget_set_allocation (widget, allocation);
3078 if (gtk_widget_get_realized (widget))
3080 GtkEntryCompletion* completion;
3082 place_windows (entry);
3083 gtk_entry_recompute (entry);
3085 completion = gtk_entry_get_completion (entry);
3086 if (completion && gtk_widget_get_mapped (completion->priv->popup_window))
3087 _gtk_entry_completion_resize_popup (completion);
3091 /* Kudos to the gnome-panel guys. */
3093 colorshift_pixbuf (GdkPixbuf *dest,
3098 gint width, height, has_alpha, src_rowstride, dest_rowstride;
3099 guchar *target_pixels;
3100 guchar *original_pixels;
3106 has_alpha = gdk_pixbuf_get_has_alpha (src);
3107 width = gdk_pixbuf_get_width (src);
3108 height = gdk_pixbuf_get_height (src);
3109 src_rowstride = gdk_pixbuf_get_rowstride (src);
3110 dest_rowstride = gdk_pixbuf_get_rowstride (dest);
3111 original_pixels = gdk_pixbuf_get_pixels (src);
3112 target_pixels = gdk_pixbuf_get_pixels (dest);
3114 for (i = 0; i < height; i++)
3116 pix_dest = target_pixels + i * dest_rowstride;
3117 pix_src = original_pixels + i * src_rowstride;
3119 for (j = 0; j < width; j++)
3126 *(pix_dest++) = CLAMP (val, 0, 255);
3129 *(pix_dest++) = CLAMP (val, 0, 255);
3132 *(pix_dest++) = CLAMP (val, 0, 255);
3135 *(pix_dest++) = *(pix_src++);
3141 should_prelight (GtkEntry *entry,
3142 GtkEntryIconPosition icon_pos)
3144 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3145 EntryIconInfo *icon_info = priv->icons[icon_pos];
3151 if (icon_info->nonactivatable && icon_info->target_list == NULL)
3154 if (icon_info->pressed)
3157 gtk_widget_style_get (GTK_WIDGET (entry),
3158 "icon-prelight", &prelight,
3165 draw_icon (GtkWidget *widget,
3167 GtkEntryIconPosition icon_pos)
3169 GtkEntry *entry = GTK_ENTRY (widget);
3170 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3171 EntryIconInfo *icon_info = priv->icons[icon_pos];
3173 gint x, y, width, height;
3178 gtk_entry_ensure_pixbuf (entry, icon_pos);
3180 if (icon_info->pixbuf == NULL)
3183 width = gdk_window_get_width (icon_info->window);
3184 height = gdk_window_get_height (icon_info->window);
3186 /* size_allocate hasn't been called yet. These are the default values.
3188 if (width == 1 || height == 1)
3191 pixbuf = icon_info->pixbuf;
3192 g_object_ref (pixbuf);
3194 if (gdk_pixbuf_get_height (pixbuf) > height)
3196 GdkPixbuf *temp_pixbuf;
3199 scale = height - 2 * priv->icon_margin;
3200 temp_pixbuf = gdk_pixbuf_scale_simple (pixbuf, scale, scale,
3201 GDK_INTERP_BILINEAR);
3202 g_object_unref (pixbuf);
3203 pixbuf = temp_pixbuf;
3206 x = (width - gdk_pixbuf_get_width (pixbuf)) / 2;
3207 y = (height - gdk_pixbuf_get_height (pixbuf)) / 2;
3209 if (!gtk_widget_is_sensitive (widget) ||
3210 icon_info->insensitive)
3212 GdkPixbuf *temp_pixbuf;
3214 temp_pixbuf = gdk_pixbuf_copy (pixbuf);
3215 gdk_pixbuf_saturate_and_pixelate (pixbuf,
3219 g_object_unref (pixbuf);
3220 pixbuf = temp_pixbuf;
3222 else if (icon_info->prelight)
3224 GdkPixbuf *temp_pixbuf;
3226 temp_pixbuf = gdk_pixbuf_copy (pixbuf);
3227 colorshift_pixbuf (temp_pixbuf, pixbuf, 30);
3228 g_object_unref (pixbuf);
3229 pixbuf = temp_pixbuf;
3232 gdk_cairo_set_source_pixbuf (cr, pixbuf, x, y);
3235 g_object_unref (pixbuf);
3240 gtk_entry_draw_frame (GtkWidget *widget,
3243 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
3246 gint x = 0, y = 0, width, height;
3248 GtkAllocation allocation;
3249 gint frame_x, frame_y;
3253 window = gtk_widget_get_window (widget);
3255 get_frame_size (GTK_ENTRY (widget), &frame_x, &frame_y, &width, &height);
3256 gtk_widget_get_allocation (widget, &allocation);
3258 cairo_translate (cr, frame_x - allocation.x, frame_y - allocation.y);
3260 /* Fix a problem with some themes which assume that entry->text_area's
3261 * width equals widget->window's width
3262 * http://bugzilla.gnome.org/show_bug.cgi?id=466000 */
3263 if (GTK_IS_SPIN_BUTTON (widget))
3265 gint xborder, yborder;
3267 gtk_entry_get_text_area_size (GTK_ENTRY (widget), &x, NULL, &width, NULL);
3268 _gtk_entry_get_borders (GTK_ENTRY (widget), &xborder, &yborder);
3271 width += xborder * 2;
3274 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3276 x += priv->focus_width;
3277 y += priv->focus_width;
3278 width -= 2 * priv->focus_width;
3279 height -= 2 * priv->focus_width;
3282 style = gtk_widget_get_style (widget);
3283 state = gtk_widget_has_focus (widget) ?
3284 GTK_STATE_ACTIVE : gtk_widget_get_state (widget);
3286 gtk_paint_flat_box (style, cr,
3287 state, GTK_SHADOW_NONE,
3289 x, y, width, height);
3291 gtk_paint_shadow (style, cr,
3292 state, priv->shadow_type,
3293 widget, "entry", x, y, width, height);
3296 gtk_entry_draw_progress (widget, cr);
3298 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3300 x -= priv->focus_width;
3301 y -= priv->focus_width;
3302 width += 2 * priv->focus_width;
3303 height += 2 * priv->focus_width;
3305 gtk_paint_focus (style, cr,
3306 gtk_widget_get_state (widget),
3308 0, 0, width, height);
3315 gtk_entry_get_progress_border (GtkWidget *widget,
3316 GtkBorder *progress_border)
3318 GtkBorder *tmp_border;
3321 gtk_widget_style_get (widget, "progress-border", &tmp_border, NULL);
3324 *progress_border = *tmp_border;
3325 gtk_border_free (tmp_border);
3329 style = gtk_widget_get_style (widget);
3331 progress_border->left = style->xthickness;
3332 progress_border->right = style->xthickness;
3333 progress_border->top = style->ythickness;
3334 progress_border->bottom = style->ythickness;
3339 get_progress_area (GtkWidget *widget,
3345 GtkEntryPrivate *private = GTK_ENTRY_GET_PRIVATE (widget);
3346 GtkEntry *entry = GTK_ENTRY (widget);
3347 GtkBorder progress_border;
3348 gint frame_width, frame_height;
3350 get_frame_size (entry, NULL, NULL, &frame_width, &frame_height);
3351 gtk_entry_get_progress_border (widget, &progress_border);
3353 *x = progress_border.left;
3354 *y = progress_border.top;
3356 *width = frame_width
3357 - progress_border.left - progress_border.right;
3358 *height = frame_height
3359 - progress_border.top - progress_border.bottom;
3361 if (gtk_widget_has_focus (widget) && !private->interior_focus)
3363 *x += private->focus_width;
3364 *y += private->focus_width;
3365 *width -= 2 * private->focus_width;
3366 *height -= 2 * private->focus_width;
3369 if (private->progress_pulse_mode)
3371 gdouble value = private->progress_pulse_current;
3373 *x += (gint) floor(value * (*width));
3374 *width = (gint) ceil(private->progress_pulse_fraction * (*width));
3376 else if (private->progress_fraction > 0)
3378 gdouble value = private->progress_fraction;
3380 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
3384 bar_width = floor(value * (*width) + 0.5);
3385 *x += *width - bar_width;
3390 *width = (gint) floor(value * (*width) + 0.5);
3401 gtk_entry_draw_progress (GtkWidget *widget,
3404 gint x, y, width, height;
3407 get_progress_area (widget, &x, &y, &width, &height);
3409 if ((width <= 0) || (height <= 0))
3412 state = GTK_STATE_SELECTED;
3413 if (!gtk_widget_get_sensitive (widget))
3414 state = GTK_STATE_INSENSITIVE;
3416 gtk_paint_box (gtk_widget_get_style (widget), cr,
3417 state, GTK_SHADOW_OUT,
3418 widget, "entry-progress",
3424 gtk_entry_draw (GtkWidget *widget,
3427 GtkEntry *entry = GTK_ENTRY (widget);
3430 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3433 style = gtk_widget_get_style (widget);
3435 state = gtk_widget_has_focus (widget) ?
3436 GTK_STATE_ACTIVE : gtk_widget_get_state (widget);
3438 if (gtk_cairo_should_draw_window (cr, gtk_widget_get_window (widget)))
3440 /* Draw entry_bg, shadow, progress and focus */
3441 gtk_entry_draw_frame (widget, cr);
3443 /* Draw text and cursor */
3446 gtk_cairo_transform_to_window (cr, widget, entry->text_area);
3448 if (entry->dnd_position != -1)
3449 gtk_entry_draw_cursor (GTK_ENTRY (widget), cr, CURSOR_DND);
3451 gtk_entry_draw_text (GTK_ENTRY (widget), cr);
3453 /* When no text is being displayed at all, don't show the cursor */
3454 if (gtk_entry_get_display_mode (entry) != DISPLAY_BLANK &&
3455 gtk_widget_has_focus (widget) &&
3456 entry->selection_bound == entry->current_pos && entry->cursor_visible)
3457 gtk_entry_draw_cursor (GTK_ENTRY (widget), cr, CURSOR_STANDARD);
3462 for (i = 0; i < MAX_ICONS; i++)
3464 EntryIconInfo *icon_info = priv->icons[i];
3466 if (icon_info != NULL)
3470 gtk_cairo_transform_to_window (cr, widget, icon_info->window);
3472 draw_icon (widget, cr, i);
3483 gtk_entry_enter_notify (GtkWidget *widget,
3484 GdkEventCrossing *event)
3486 GtkEntry *entry = GTK_ENTRY (widget);
3487 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3490 for (i = 0; i < MAX_ICONS; i++)
3492 EntryIconInfo *icon_info = priv->icons[i];
3494 if (icon_info != NULL && event->window == icon_info->window)
3496 if (should_prelight (entry, i))
3498 icon_info->prelight = TRUE;
3499 gtk_widget_queue_draw (widget);
3510 gtk_entry_leave_notify (GtkWidget *widget,
3511 GdkEventCrossing *event)
3513 GtkEntry *entry = GTK_ENTRY (widget);
3514 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3517 for (i = 0; i < MAX_ICONS; i++)
3519 EntryIconInfo *icon_info = priv->icons[i];
3521 if (icon_info != NULL && event->window == icon_info->window)
3523 /* a grab means that we may never see the button release */
3524 if (event->mode == GDK_CROSSING_GRAB || event->mode == GDK_CROSSING_GTK_GRAB)
3525 icon_info->pressed = FALSE;
3527 if (should_prelight (entry, i))
3529 icon_info->prelight = FALSE;
3530 gtk_widget_queue_draw (widget);
3541 gtk_entry_get_pixel_ranges (GtkEntry *entry,
3545 gint start_char, end_char;
3547 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start_char, &end_char))
3549 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
3550 PangoLayoutLine *line = pango_layout_get_lines_readonly (layout)->data;
3551 const char *text = pango_layout_get_text (layout);
3552 gint start_index = g_utf8_offset_to_pointer (text, start_char) - text;
3553 gint end_index = g_utf8_offset_to_pointer (text, end_char) - text;
3554 gint real_n_ranges, i;
3556 pango_layout_line_get_x_ranges (line, start_index, end_index, ranges, &real_n_ranges);
3562 for (i = 0; i < real_n_ranges; ++i)
3564 r[2 * i + 1] = (r[2 * i + 1] - r[2 * i]) / PANGO_SCALE;
3565 r[2 * i] = r[2 * i] / PANGO_SCALE;
3570 *n_ranges = real_n_ranges;
3582 in_selection (GtkEntry *entry,
3587 gint retval = FALSE;
3589 gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
3591 for (i = 0; i < n_ranges; ++i)
3593 if (x >= ranges[2 * i] && x < ranges[2 * i] + ranges[2 * i + 1])
3605 gtk_entry_button_press (GtkWidget *widget,
3606 GdkEventButton *event)
3608 GtkEntry *entry = GTK_ENTRY (widget);
3609 GtkEditable *editable = GTK_EDITABLE (widget);
3610 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3611 EntryIconInfo *icon_info = NULL;
3613 gint sel_start, sel_end;
3616 for (i = 0; i < MAX_ICONS; i++)
3618 icon_info = priv->icons[i];
3620 if (!icon_info || icon_info->insensitive)
3623 if (event->window == icon_info->window)
3625 if (should_prelight (entry, i))
3627 icon_info->prelight = FALSE;
3628 gtk_widget_queue_draw (widget);
3631 priv->start_x = event->x;
3632 priv->start_y = event->y;
3633 icon_info->pressed = TRUE;
3635 if (!icon_info->nonactivatable)
3636 g_signal_emit (entry, signals[ICON_PRESS], 0, i, event);
3642 if (event->window != entry->text_area ||
3643 (entry->button && event->button != entry->button))
3646 gtk_entry_reset_blink_time (entry);
3648 entry->button = event->button;
3650 if (!gtk_widget_has_focus (widget))
3652 entry->in_click = TRUE;
3653 gtk_widget_grab_focus (widget);
3654 entry->in_click = FALSE;
3657 tmp_pos = gtk_entry_find_position (entry, event->x + entry->scroll_offset);
3659 if (event->button == 1)
3661 gboolean have_selection = gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end);
3663 entry->select_words = FALSE;
3664 entry->select_lines = FALSE;
3666 if (event->state & GDK_SHIFT_MASK)
3668 _gtk_entry_reset_im_context (entry);
3670 if (!have_selection) /* select from the current position to the clicked position */
3671 sel_start = sel_end = entry->current_pos;
3673 if (tmp_pos > sel_start && tmp_pos < sel_end)
3675 /* Truncate current selection, but keep it as big as possible */
3676 if (tmp_pos - sel_start > sel_end - tmp_pos)
3677 gtk_entry_set_positions (entry, sel_start, tmp_pos);
3679 gtk_entry_set_positions (entry, tmp_pos, sel_end);
3683 gboolean extend_to_left;
3686 /* Figure out what click selects and extend current selection */
3687 switch (event->type)
3689 case GDK_BUTTON_PRESS:
3690 gtk_entry_set_positions (entry, tmp_pos, tmp_pos);
3693 case GDK_2BUTTON_PRESS:
3694 entry->select_words = TRUE;
3695 gtk_entry_select_word (entry);
3698 case GDK_3BUTTON_PRESS:
3699 entry->select_lines = TRUE;
3700 gtk_entry_select_line (entry);
3707 start = MIN (entry->current_pos, entry->selection_bound);
3708 start = MIN (sel_start, start);
3710 end = MAX (entry->current_pos, entry->selection_bound);
3711 end = MAX (sel_end, end);
3713 if (tmp_pos == sel_start || tmp_pos == sel_end)
3714 extend_to_left = (tmp_pos == start);
3716 extend_to_left = (end == sel_end);
3719 gtk_entry_set_positions (entry, start, end);
3721 gtk_entry_set_positions (entry, end, start);
3724 else /* no shift key */
3725 switch (event->type)
3727 case GDK_BUTTON_PRESS:
3728 if (in_selection (entry, event->x + entry->scroll_offset))
3730 /* Click inside the selection - we'll either start a drag, or
3731 * clear the selection
3733 entry->in_drag = TRUE;
3734 entry->drag_start_x = event->x + entry->scroll_offset;
3735 entry->drag_start_y = event->y;
3738 gtk_editable_set_position (editable, tmp_pos);
3741 case GDK_2BUTTON_PRESS:
3742 /* We ALWAYS receive a GDK_BUTTON_PRESS immediately before
3743 * receiving a GDK_2BUTTON_PRESS so we need to reset
3744 * entry->in_drag which may have been set above
3746 entry->in_drag = FALSE;
3747 entry->select_words = TRUE;
3748 gtk_entry_select_word (entry);
3751 case GDK_3BUTTON_PRESS:
3752 /* We ALWAYS receive a GDK_BUTTON_PRESS immediately before
3753 * receiving a GDK_3BUTTON_PRESS so we need to reset
3754 * entry->in_drag which may have been set above
3756 entry->in_drag = FALSE;
3757 entry->select_lines = TRUE;
3758 gtk_entry_select_line (entry);
3767 else if (event->button == 2 && event->type == GDK_BUTTON_PRESS)
3769 if (entry->editable)
3771 priv->insert_pos = tmp_pos;
3772 gtk_entry_paste (entry, GDK_SELECTION_PRIMARY);
3777 gtk_widget_error_bell (widget);
3780 else if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
3782 gtk_entry_do_popup (entry, event);
3783 entry->button = 0; /* Don't wait for release, since the menu will gtk_grab_add */
3792 gtk_entry_button_release (GtkWidget *widget,
3793 GdkEventButton *event)
3795 GtkEntry *entry = GTK_ENTRY (widget);
3796 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
3797 EntryIconInfo *icon_info = NULL;
3800 for (i = 0; i < MAX_ICONS; i++)
3802 icon_info = priv->icons[i];
3804 if (!icon_info || icon_info->insensitive)
3807 if (event->window == icon_info->window)
3809 icon_info->pressed = FALSE;
3811 if (should_prelight (entry, i) &&
3812 event->x >= 0 && event->y >= 0 &&
3813 event->x < gdk_window_get_width (icon_info->window) &&
3814 event->y < gdk_window_get_height (icon_info->window))
3816 icon_info->prelight = TRUE;
3817 gtk_widget_queue_draw (widget);
3820 if (!icon_info->nonactivatable)
3821 g_signal_emit (entry, signals[ICON_RELEASE], 0, i, event);
3827 if (event->window != entry->text_area || entry->button != event->button)
3832 gint tmp_pos = gtk_entry_find_position (entry, entry->drag_start_x);
3834 gtk_editable_set_position (GTK_EDITABLE (entry), tmp_pos);
3841 gtk_entry_update_primary_selection (entry);
3847 _gtk_entry_get_selected_text (GtkEntry *entry)
3849 GtkEditable *editable = GTK_EDITABLE (entry);
3850 gint start_text, end_text;
3853 if (gtk_editable_get_selection_bounds (editable, &start_text, &end_text))
3854 text = gtk_editable_get_chars (editable, start_text, end_text);
3860 gtk_entry_motion_notify (GtkWidget *widget,
3861 GdkEventMotion *event)
3863 GtkEntry *entry = GTK_ENTRY (widget);
3864 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3865 EntryIconInfo *icon_info = NULL;
3866 GdkDragContext *context;
3870 for (i = 0; i < MAX_ICONS; i++)
3872 icon_info = priv->icons[i];
3874 if (!icon_info || icon_info->insensitive)
3877 if (event->window == icon_info->window)
3879 if (icon_info->pressed &&
3880 icon_info->target_list != NULL &&
3881 gtk_drag_check_threshold (widget,
3887 icon_info->in_drag = TRUE;
3888 icon_info->pressed = FALSE;
3889 context = gtk_drag_begin (widget,
3890 icon_info->target_list,
3900 if (entry->mouse_cursor_obscured)
3904 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
3905 gdk_window_set_cursor (entry->text_area, cursor);
3906 gdk_cursor_unref (cursor);
3907 entry->mouse_cursor_obscured = FALSE;
3910 if (event->window != entry->text_area || entry->button != 1)
3913 if (entry->select_lines)
3916 gdk_event_request_motions (event);
3920 if (gtk_entry_get_display_mode (entry) == DISPLAY_NORMAL &&
3921 gtk_drag_check_threshold (widget,
3922 entry->drag_start_x, entry->drag_start_y,
3923 event->x + entry->scroll_offset, event->y))
3925 GdkDragContext *context;
3926 GtkTargetList *target_list = gtk_target_list_new (NULL, 0);
3927 guint actions = entry->editable ? GDK_ACTION_COPY | GDK_ACTION_MOVE : GDK_ACTION_COPY;
3929 cairo_surface_t *surface;
3931 gtk_target_list_add_text_targets (target_list, 0);
3933 text = _gtk_entry_get_selected_text (entry);
3934 surface = _gtk_text_util_create_drag_icon (widget, text, -1);
3936 context = gtk_drag_begin (widget, target_list, actions,
3937 entry->button, (GdkEvent *)event);
3940 gtk_drag_set_icon_surface (context, surface);
3942 gtk_drag_set_icon_default (context);
3945 cairo_surface_destroy (surface);
3948 entry->in_drag = FALSE;
3951 gtk_target_list_unref (target_list);
3958 else if (event->y >= gdk_window_get_height (entry->text_area))
3959 tmp_pos = gtk_entry_buffer_get_length (get_buffer (entry));
3961 tmp_pos = gtk_entry_find_position (entry, event->x + entry->scroll_offset);
3963 if (entry->select_words)
3966 gint old_min, old_max;
3969 min = gtk_entry_move_backward_word (entry, tmp_pos, TRUE);
3970 max = gtk_entry_move_forward_word (entry, tmp_pos, TRUE);
3972 pos = entry->current_pos;
3973 bound = entry->selection_bound;
3975 old_min = MIN(entry->current_pos, entry->selection_bound);
3976 old_max = MAX(entry->current_pos, entry->selection_bound);
3983 else if (old_max < max)
3988 else if (pos == old_min)
3990 if (entry->current_pos != min)
3995 if (entry->current_pos != max)
3999 gtk_entry_set_positions (entry, pos, bound);
4002 gtk_entry_set_positions (entry, tmp_pos, -1);
4009 set_invisible_cursor (GdkWindow *window)
4011 GdkDisplay *display;
4014 display = gdk_window_get_display (window);
4015 cursor = gdk_cursor_new_for_display (display, GDK_BLANK_CURSOR);
4017 gdk_window_set_cursor (window, cursor);
4019 gdk_cursor_unref (cursor);
4023 gtk_entry_obscure_mouse_cursor (GtkEntry *entry)
4025 if (entry->mouse_cursor_obscured)
4028 set_invisible_cursor (entry->text_area);
4030 entry->mouse_cursor_obscured = TRUE;
4034 gtk_entry_key_press (GtkWidget *widget,
4037 GtkEntry *entry = GTK_ENTRY (widget);
4039 gtk_entry_reset_blink_time (entry);
4040 gtk_entry_pend_cursor_blink (entry);
4042 if (entry->editable)
4044 if (gtk_im_context_filter_keypress (entry->im_context, event))
4046 gtk_entry_obscure_mouse_cursor (entry);
4047 entry->need_im_reset = TRUE;
4052 if (event->keyval == GDK_KEY_Return ||
4053 event->keyval == GDK_KEY_KP_Enter ||
4054 event->keyval == GDK_KEY_ISO_Enter ||
4055 event->keyval == GDK_KEY_Escape)
4057 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
4059 if (completion && completion->priv->completion_timeout)
4061 g_source_remove (completion->priv->completion_timeout);
4062 completion->priv->completion_timeout = 0;
4065 _gtk_entry_reset_im_context (entry);
4068 if (GTK_WIDGET_CLASS (gtk_entry_parent_class)->key_press_event (widget, event))
4069 /* Activate key bindings
4073 if (!entry->editable && event->length)
4074 gtk_widget_error_bell (widget);
4080 gtk_entry_key_release (GtkWidget *widget,
4083 GtkEntry *entry = GTK_ENTRY (widget);
4085 if (entry->editable)
4087 if (gtk_im_context_filter_keypress (entry->im_context, event))
4089 entry->need_im_reset = TRUE;
4094 return GTK_WIDGET_CLASS (gtk_entry_parent_class)->key_release_event (widget, event);
4098 gtk_entry_focus_in (GtkWidget *widget,
4099 GdkEventFocus *event)
4101 GtkEntry *entry = GTK_ENTRY (widget);
4104 gtk_widget_queue_draw (widget);
4106 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (widget));
4108 if (entry->editable)
4110 entry->need_im_reset = TRUE;
4111 gtk_im_context_focus_in (entry->im_context);
4112 keymap_state_changed (keymap, entry);
4113 g_signal_connect (keymap, "state-changed",
4114 G_CALLBACK (keymap_state_changed), entry);
4117 g_signal_connect (keymap, "direction-changed",
4118 G_CALLBACK (keymap_direction_changed), entry);
4120 gtk_entry_reset_blink_time (entry);
4121 gtk_entry_check_cursor_blink (entry);
4127 gtk_entry_focus_out (GtkWidget *widget,
4128 GdkEventFocus *event)
4130 GtkEntry *entry = GTK_ENTRY (widget);
4131 GtkEntryCompletion *completion;
4134 gtk_widget_queue_draw (widget);
4136 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (widget));
4138 if (entry->editable)
4140 entry->need_im_reset = TRUE;
4141 gtk_im_context_focus_out (entry->im_context);
4142 remove_capslock_feedback (entry);
4145 gtk_entry_check_cursor_blink (entry);
4147 g_signal_handlers_disconnect_by_func (keymap, keymap_state_changed, entry);
4148 g_signal_handlers_disconnect_by_func (keymap, keymap_direction_changed, entry);
4150 completion = gtk_entry_get_completion (entry);
4152 _gtk_entry_completion_popdown (completion);
4158 gtk_entry_grab_focus (GtkWidget *widget)
4160 GtkEntry *entry = GTK_ENTRY (widget);
4161 gboolean select_on_focus;
4163 GTK_WIDGET_CLASS (gtk_entry_parent_class)->grab_focus (widget);
4165 if (entry->editable && !entry->in_click)
4167 g_object_get (gtk_widget_get_settings (widget),
4168 "gtk-entry-select-on-focus",
4172 if (select_on_focus)
4173 gtk_editable_select_region (GTK_EDITABLE (widget), 0, -1);
4178 gtk_entry_direction_changed (GtkWidget *widget,
4179 GtkTextDirection previous_dir)
4181 GtkEntry *entry = GTK_ENTRY (widget);
4183 gtk_entry_recompute (entry);
4185 GTK_WIDGET_CLASS (gtk_entry_parent_class)->direction_changed (widget, previous_dir);
4189 gtk_entry_state_changed (GtkWidget *widget,
4190 GtkStateType previous_state)
4192 GtkEntry *entry = GTK_ENTRY (widget);
4195 if (gtk_widget_get_realized (widget))
4197 if (gtk_widget_is_sensitive (widget))
4198 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
4202 gdk_window_set_cursor (entry->text_area, cursor);
4205 gdk_cursor_unref (cursor);
4207 entry->mouse_cursor_obscured = FALSE;
4209 update_cursors (widget);
4212 if (!gtk_widget_is_sensitive (widget))
4214 /* Clear any selection */
4215 gtk_editable_select_region (GTK_EDITABLE (entry), entry->current_pos, entry->current_pos);
4218 gtk_widget_queue_draw (widget);
4222 gtk_entry_screen_changed (GtkWidget *widget,
4223 GdkScreen *old_screen)
4225 gtk_entry_recompute (GTK_ENTRY (widget));
4228 /* GtkEditable method implementations
4231 gtk_entry_insert_text (GtkEditable *editable,
4232 const gchar *new_text,
4233 gint new_text_length,
4236 g_object_ref (editable);
4239 * The incoming text may a password or other secret. We make sure
4240 * not to copy it into temporary buffers.
4243 g_signal_emit_by_name (editable, "insert-text", new_text, new_text_length, position);
4245 g_object_unref (editable);
4249 gtk_entry_delete_text (GtkEditable *editable,
4253 g_object_ref (editable);
4255 g_signal_emit_by_name (editable, "delete-text", start_pos, end_pos);
4257 g_object_unref (editable);
4261 gtk_entry_get_chars (GtkEditable *editable,
4265 GtkEntry *entry = GTK_ENTRY (editable);
4268 gint start_index, end_index;
4270 text = gtk_entry_buffer_get_text (get_buffer (entry));
4271 text_length = gtk_entry_buffer_get_length (get_buffer (entry));
4274 end_pos = text_length;
4276 start_pos = MIN (text_length, start_pos);
4277 end_pos = MIN (text_length, end_pos);
4279 start_index = g_utf8_offset_to_pointer (text, start_pos) - text;
4280 end_index = g_utf8_offset_to_pointer (text, end_pos) - text;
4282 return g_strndup (text + start_index, end_index - start_index);
4286 gtk_entry_real_set_position (GtkEditable *editable,
4289 GtkEntry *entry = GTK_ENTRY (editable);
4293 length = gtk_entry_buffer_get_length (get_buffer (entry));
4294 if (position < 0 || position > length)
4297 if (position != entry->current_pos ||
4298 position != entry->selection_bound)
4300 _gtk_entry_reset_im_context (entry);
4301 gtk_entry_set_positions (entry, position, position);
4306 gtk_entry_get_position (GtkEditable *editable)
4308 return GTK_ENTRY (editable)->current_pos;
4312 gtk_entry_set_selection_bounds (GtkEditable *editable,
4316 GtkEntry *entry = GTK_ENTRY (editable);
4319 length = gtk_entry_buffer_get_length (get_buffer (entry));
4325 _gtk_entry_reset_im_context (entry);
4327 gtk_entry_set_positions (entry,
4329 MIN (start, length));
4331 gtk_entry_update_primary_selection (entry);
4335 gtk_entry_get_selection_bounds (GtkEditable *editable,
4339 GtkEntry *entry = GTK_ENTRY (editable);
4341 *start = entry->selection_bound;
4342 *end = entry->current_pos;
4344 return (entry->selection_bound != entry->current_pos);
4348 icon_theme_changed (GtkEntry *entry)
4350 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
4353 for (i = 0; i < MAX_ICONS; i++)
4355 EntryIconInfo *icon_info = priv->icons[i];
4356 if (icon_info != NULL)
4358 if (icon_info->storage_type == GTK_IMAGE_ICON_NAME)
4359 gtk_entry_set_icon_from_icon_name (entry, i, icon_info->icon_name);
4360 else if (icon_info->storage_type == GTK_IMAGE_STOCK)
4361 gtk_entry_set_icon_from_stock (entry, i, icon_info->stock_id);
4362 else if (icon_info->storage_type == GTK_IMAGE_GICON)
4363 gtk_entry_set_icon_from_gicon (entry, i, icon_info->gicon);
4367 gtk_widget_queue_draw (GTK_WIDGET (entry));
4371 icon_margin_changed (GtkEntry *entry)
4373 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
4376 _gtk_entry_effective_inner_border (GTK_ENTRY (entry), &border);
4378 priv->icon_margin = border.left;
4382 gtk_entry_style_set (GtkWidget *widget,
4383 GtkStyle *previous_style)
4385 GtkEntry *entry = GTK_ENTRY (widget);
4386 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
4388 gboolean interior_focus;
4390 gtk_widget_style_get (widget,
4391 "focus-line-width", &focus_width,
4392 "interior-focus", &interior_focus,
4395 priv->focus_width = focus_width;
4396 priv->interior_focus = interior_focus;
4398 if (!priv->invisible_char_set)
4399 entry->invisible_char = find_invisible_char (GTK_WIDGET (entry));
4401 gtk_entry_recompute (entry);
4403 icon_theme_changed (entry);
4404 icon_margin_changed (entry);
4407 /* GtkCellEditable method implementations
4410 gtk_cell_editable_entry_activated (GtkEntry *entry, gpointer data)
4412 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4413 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4417 gtk_cell_editable_key_press_event (GtkEntry *entry,
4418 GdkEventKey *key_event,
4421 if (key_event->keyval == GDK_KEY_Escape)
4423 entry->editing_canceled = TRUE;
4424 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4425 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4430 /* override focus */
4431 if (key_event->keyval == GDK_KEY_Up || key_event->keyval == GDK_KEY_Down)
4433 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4434 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4443 gtk_entry_start_editing (GtkCellEditable *cell_editable,
4446 GTK_ENTRY (cell_editable)->is_cell_renderer = TRUE;
4448 g_signal_connect (cell_editable, "activate",
4449 G_CALLBACK (gtk_cell_editable_entry_activated), NULL);
4450 g_signal_connect (cell_editable, "key-press-event",
4451 G_CALLBACK (gtk_cell_editable_key_press_event), NULL);
4455 gtk_entry_password_hint_free (GtkEntryPasswordHint *password_hint)
4457 if (password_hint->source_id)
4458 g_source_remove (password_hint->source_id);
4460 g_slice_free (GtkEntryPasswordHint, password_hint);
4465 gtk_entry_remove_password_hint (gpointer data)
4467 GtkEntryPasswordHint *password_hint = g_object_get_qdata (data, quark_password_hint);
4468 password_hint->position = -1;
4470 /* Force the string to be redrawn, but now without a visible character */
4471 gtk_entry_recompute (GTK_ENTRY (data));
4475 /* Default signal handlers
4478 gtk_entry_real_insert_text (GtkEditable *editable,
4479 const gchar *new_text,
4480 gint new_text_length,
4486 n_chars = g_utf8_strlen (new_text, new_text_length);
4489 * The actual insertion into the buffer. This will end up firing the
4490 * following signal handlers: buffer_inserted_text(), buffer_notify_display_text(),
4491 * buffer_notify_text(), buffer_notify_length()
4493 n_inserted = gtk_entry_buffer_insert_text (get_buffer (GTK_ENTRY (editable)), *position, new_text, n_chars);
4495 if (n_inserted != n_chars)
4496 gtk_widget_error_bell (GTK_WIDGET (editable));
4498 *position += n_inserted;
4502 gtk_entry_real_delete_text (GtkEditable *editable,
4507 * The actual deletion from the buffer. This will end up firing the
4508 * following signal handlers: buffer_deleted_text(), buffer_notify_display_text(),
4509 * buffer_notify_text(), buffer_notify_length()
4512 gtk_entry_buffer_delete_text (get_buffer (GTK_ENTRY (editable)), start_pos, end_pos - start_pos);
4515 /* GtkEntryBuffer signal handlers
4518 buffer_inserted_text (GtkEntryBuffer *buffer,
4524 guint password_hint_timeout;
4526 if (entry->current_pos > position)
4527 entry->current_pos += n_chars;
4529 if (entry->selection_bound > position)
4530 entry->selection_bound += n_chars;
4532 /* Calculate the password hint if it needs to be displayed. */
4533 if (n_chars == 1 && !entry->visible)
4535 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
4536 "gtk-entry-password-hint-timeout", &password_hint_timeout,
4539 if (password_hint_timeout > 0)
4541 GtkEntryPasswordHint *password_hint = g_object_get_qdata (G_OBJECT (entry),
4542 quark_password_hint);
4545 password_hint = g_slice_new0 (GtkEntryPasswordHint);
4546 g_object_set_qdata_full (G_OBJECT (entry), quark_password_hint, password_hint,
4547 (GDestroyNotify)gtk_entry_password_hint_free);
4550 password_hint->position = position;
4551 if (password_hint->source_id)
4552 g_source_remove (password_hint->source_id);
4553 password_hint->source_id = gdk_threads_add_timeout (password_hint_timeout,
4554 (GSourceFunc)gtk_entry_remove_password_hint, entry);
4560 buffer_deleted_text (GtkEntryBuffer *buffer,
4565 guint end_pos = position + n_chars;
4566 gint selection_bound;
4569 current_pos = entry->current_pos;
4570 if (current_pos > position)
4571 current_pos -= MIN (current_pos, end_pos) - position;
4573 selection_bound = entry->selection_bound;
4574 if (selection_bound > position)
4575 selection_bound -= MIN (selection_bound, end_pos) - position;
4577 gtk_entry_set_positions (entry, current_pos, selection_bound);
4579 /* We might have deleted the selection */
4580 gtk_entry_update_primary_selection (entry);
4582 /* Disable the password hint if one exists. */
4583 if (!entry->visible)
4585 GtkEntryPasswordHint *password_hint = g_object_get_qdata (G_OBJECT (entry),
4586 quark_password_hint);
4589 if (password_hint->source_id)
4590 g_source_remove (password_hint->source_id);
4591 password_hint->source_id = 0;
4592 password_hint->position = -1;
4598 buffer_notify_text (GtkEntryBuffer *buffer,
4602 gtk_entry_recompute (entry);
4603 emit_changed (entry);
4604 g_object_notify (G_OBJECT (entry), "text");
4608 buffer_notify_length (GtkEntryBuffer *buffer,
4612 g_object_notify (G_OBJECT (entry), "text-length");
4616 buffer_notify_max_length (GtkEntryBuffer *buffer,
4620 g_object_notify (G_OBJECT (entry), "max-length");
4624 buffer_connect_signals (GtkEntry *entry)
4626 g_signal_connect (get_buffer (entry), "inserted-text", G_CALLBACK (buffer_inserted_text), entry);
4627 g_signal_connect (get_buffer (entry), "deleted-text", G_CALLBACK (buffer_deleted_text), entry);
4628 g_signal_connect (get_buffer (entry), "notify::text", G_CALLBACK (buffer_notify_text), entry);
4629 g_signal_connect (get_buffer (entry), "notify::length", G_CALLBACK (buffer_notify_length), entry);
4630 g_signal_connect (get_buffer (entry), "notify::max-length", G_CALLBACK (buffer_notify_max_length), entry);
4634 buffer_disconnect_signals (GtkEntry *entry)
4636 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_inserted_text, entry);
4637 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_deleted_text, entry);
4638 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_text, entry);
4639 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_length, entry);
4640 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_max_length, entry);
4643 /* Compute the X position for an offset that corresponds to the "more important
4644 * cursor position for that offset. We use this when trying to guess to which
4645 * end of the selection we should go to when the user hits the left or
4649 get_better_cursor_x (GtkEntry *entry,
4652 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
4653 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
4654 gboolean split_cursor;
4656 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
4657 const gchar *text = pango_layout_get_text (layout);
4658 gint index = g_utf8_offset_to_pointer (text, offset) - text;
4660 PangoRectangle strong_pos, weak_pos;
4662 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
4663 "gtk-split-cursor", &split_cursor,
4666 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
4669 return strong_pos.x / PANGO_SCALE;
4671 return (keymap_direction == entry->resolved_dir) ? strong_pos.x / PANGO_SCALE : weak_pos.x / PANGO_SCALE;
4675 gtk_entry_move_cursor (GtkEntry *entry,
4676 GtkMovementStep step,
4678 gboolean extend_selection)
4680 gint new_pos = entry->current_pos;
4681 GtkEntryPrivate *priv;
4683 _gtk_entry_reset_im_context (entry);
4685 if (entry->current_pos != entry->selection_bound && !extend_selection)
4687 /* If we have a current selection and aren't extending it, move to the
4688 * start/or end of the selection as appropriate
4692 case GTK_MOVEMENT_VISUAL_POSITIONS:
4694 gint current_x = get_better_cursor_x (entry, entry->current_pos);
4695 gint bound_x = get_better_cursor_x (entry, entry->selection_bound);
4698 new_pos = current_x < bound_x ? entry->current_pos : entry->selection_bound;
4700 new_pos = current_x > bound_x ? entry->current_pos : entry->selection_bound;
4703 case GTK_MOVEMENT_LOGICAL_POSITIONS:
4704 case GTK_MOVEMENT_WORDS:
4706 new_pos = MIN (entry->current_pos, entry->selection_bound);
4708 new_pos = MAX (entry->current_pos, entry->selection_bound);
4710 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
4711 case GTK_MOVEMENT_PARAGRAPH_ENDS:
4712 case GTK_MOVEMENT_BUFFER_ENDS:
4713 priv = GTK_ENTRY_GET_PRIVATE (entry);
4714 new_pos = count < 0 ? 0 : gtk_entry_buffer_get_length (get_buffer (entry));
4716 case GTK_MOVEMENT_DISPLAY_LINES:
4717 case GTK_MOVEMENT_PARAGRAPHS:
4718 case GTK_MOVEMENT_PAGES:
4719 case GTK_MOVEMENT_HORIZONTAL_PAGES:
4727 case GTK_MOVEMENT_LOGICAL_POSITIONS:
4728 new_pos = gtk_entry_move_logically (entry, new_pos, count);
4730 case GTK_MOVEMENT_VISUAL_POSITIONS:
4731 new_pos = gtk_entry_move_visually (entry, new_pos, count);
4732 if (entry->current_pos == new_pos)
4734 if (!extend_selection)
4736 if (!gtk_widget_keynav_failed (GTK_WIDGET (entry),
4738 GTK_DIR_RIGHT : GTK_DIR_LEFT))
4740 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (entry));
4743 gtk_widget_child_focus (toplevel,
4745 GTK_DIR_RIGHT : GTK_DIR_LEFT);
4750 gtk_widget_error_bell (GTK_WIDGET (entry));
4754 case GTK_MOVEMENT_WORDS:
4757 new_pos = gtk_entry_move_forward_word (entry, new_pos, FALSE);
4762 new_pos = gtk_entry_move_backward_word (entry, new_pos, FALSE);
4765 if (entry->current_pos == new_pos)
4766 gtk_widget_error_bell (GTK_WIDGET (entry));
4768 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
4769 case GTK_MOVEMENT_PARAGRAPH_ENDS:
4770 case GTK_MOVEMENT_BUFFER_ENDS:
4771 priv = GTK_ENTRY_GET_PRIVATE (entry);
4772 new_pos = count < 0 ? 0 : gtk_entry_buffer_get_length (get_buffer (entry));
4773 if (entry->current_pos == new_pos)
4774 gtk_widget_error_bell (GTK_WIDGET (entry));
4776 case GTK_MOVEMENT_DISPLAY_LINES:
4777 case GTK_MOVEMENT_PARAGRAPHS:
4778 case GTK_MOVEMENT_PAGES:
4779 case GTK_MOVEMENT_HORIZONTAL_PAGES:
4784 if (extend_selection)
4785 gtk_editable_select_region (GTK_EDITABLE (entry), entry->selection_bound, new_pos);
4787 gtk_editable_set_position (GTK_EDITABLE (entry), new_pos);
4789 gtk_entry_pend_cursor_blink (entry);
4793 gtk_entry_insert_at_cursor (GtkEntry *entry,
4796 GtkEditable *editable = GTK_EDITABLE (entry);
4797 gint pos = entry->current_pos;
4799 if (entry->editable)
4801 _gtk_entry_reset_im_context (entry);
4803 gtk_editable_insert_text (editable, str, -1, &pos);
4804 gtk_editable_set_position (editable, pos);
4809 gtk_entry_delete_from_cursor (GtkEntry *entry,
4813 GtkEditable *editable = GTK_EDITABLE (entry);
4814 gint start_pos = entry->current_pos;
4815 gint end_pos = entry->current_pos;
4816 gint old_n_bytes = gtk_entry_buffer_get_bytes (get_buffer (entry));
4818 _gtk_entry_reset_im_context (entry);
4820 if (!entry->editable)
4822 gtk_widget_error_bell (GTK_WIDGET (entry));
4826 if (entry->selection_bound != entry->current_pos)
4828 gtk_editable_delete_selection (editable);
4834 case GTK_DELETE_CHARS:
4835 end_pos = gtk_entry_move_logically (entry, entry->current_pos, count);
4836 gtk_editable_delete_text (editable, MIN (start_pos, end_pos), MAX (start_pos, end_pos));
4838 case GTK_DELETE_WORDS:
4841 /* Move to end of current word, or if not on a word, end of previous word */
4842 end_pos = gtk_entry_move_backward_word (entry, end_pos, FALSE);
4843 end_pos = gtk_entry_move_forward_word (entry, end_pos, FALSE);
4847 /* Move to beginning of current word, or if not on a word, begining of next word */
4848 start_pos = gtk_entry_move_forward_word (entry, start_pos, FALSE);
4849 start_pos = gtk_entry_move_backward_word (entry, start_pos, FALSE);
4853 case GTK_DELETE_WORD_ENDS:
4856 start_pos = gtk_entry_move_backward_word (entry, start_pos, FALSE);
4861 end_pos = gtk_entry_move_forward_word (entry, end_pos, FALSE);
4864 gtk_editable_delete_text (editable, start_pos, end_pos);
4866 case GTK_DELETE_DISPLAY_LINE_ENDS:
4867 case GTK_DELETE_PARAGRAPH_ENDS:
4869 gtk_editable_delete_text (editable, 0, entry->current_pos);
4871 gtk_editable_delete_text (editable, entry->current_pos, -1);
4873 case GTK_DELETE_DISPLAY_LINES:
4874 case GTK_DELETE_PARAGRAPHS:
4875 gtk_editable_delete_text (editable, 0, -1);
4877 case GTK_DELETE_WHITESPACE:
4878 gtk_entry_delete_whitespace (entry);
4882 if (gtk_entry_buffer_get_bytes (get_buffer (entry)) == old_n_bytes)
4883 gtk_widget_error_bell (GTK_WIDGET (entry));
4885 gtk_entry_pend_cursor_blink (entry);
4889 gtk_entry_backspace (GtkEntry *entry)
4891 GtkEditable *editable = GTK_EDITABLE (entry);
4894 _gtk_entry_reset_im_context (entry);
4896 if (!entry->editable)
4898 gtk_widget_error_bell (GTK_WIDGET (entry));
4902 if (entry->selection_bound != entry->current_pos)
4904 gtk_editable_delete_selection (editable);
4908 prev_pos = gtk_entry_move_logically (entry, entry->current_pos, -1);
4910 if (prev_pos < entry->current_pos)
4912 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
4913 PangoLogAttr *log_attrs;
4916 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
4918 /* Deleting parts of characters */
4919 if (log_attrs[entry->current_pos].backspace_deletes_character)
4921 gchar *cluster_text;
4922 gchar *normalized_text;
4925 cluster_text = gtk_entry_get_display_text (entry, prev_pos,
4926 entry->current_pos);
4927 normalized_text = g_utf8_normalize (cluster_text,
4928 strlen (cluster_text),
4930 len = g_utf8_strlen (normalized_text, -1);
4932 gtk_editable_delete_text (editable, prev_pos, entry->current_pos);
4935 gint pos = entry->current_pos;
4937 gtk_editable_insert_text (editable, normalized_text,
4938 g_utf8_offset_to_pointer (normalized_text, len - 1) - normalized_text,
4940 gtk_editable_set_position (editable, pos);
4943 g_free (normalized_text);
4944 g_free (cluster_text);
4948 gtk_editable_delete_text (editable, prev_pos, entry->current_pos);
4955 gtk_widget_error_bell (GTK_WIDGET (entry));
4958 gtk_entry_pend_cursor_blink (entry);
4962 gtk_entry_copy_clipboard (GtkEntry *entry)
4964 GtkEditable *editable = GTK_EDITABLE (entry);
4968 if (gtk_editable_get_selection_bounds (editable, &start, &end))
4970 if (!entry->visible)
4972 gtk_widget_error_bell (GTK_WIDGET (entry));
4976 str = gtk_entry_get_display_text (entry, start, end);
4977 gtk_clipboard_set_text (gtk_widget_get_clipboard (GTK_WIDGET (entry),
4978 GDK_SELECTION_CLIPBOARD),
4985 gtk_entry_cut_clipboard (GtkEntry *entry)
4987 GtkEditable *editable = GTK_EDITABLE (entry);
4990 if (!entry->visible)
4992 gtk_widget_error_bell (GTK_WIDGET (entry));
4996 gtk_entry_copy_clipboard (entry);
4998 if (entry->editable)
5000 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5001 gtk_editable_delete_text (editable, start, end);
5005 gtk_widget_error_bell (GTK_WIDGET (entry));
5010 gtk_entry_paste_clipboard (GtkEntry *entry)
5012 if (entry->editable)
5013 gtk_entry_paste (entry, GDK_NONE);
5015 gtk_widget_error_bell (GTK_WIDGET (entry));
5019 gtk_entry_delete_cb (GtkEntry *entry)
5021 GtkEditable *editable = GTK_EDITABLE (entry);
5024 if (entry->editable)
5026 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5027 gtk_editable_delete_text (editable, start, end);
5032 gtk_entry_toggle_overwrite (GtkEntry *entry)
5034 entry->overwrite_mode = !entry->overwrite_mode;
5035 gtk_entry_pend_cursor_blink (entry);
5036 gtk_widget_queue_draw (GTK_WIDGET (entry));
5040 gtk_entry_select_all (GtkEntry *entry)
5042 gtk_entry_select_line (entry);
5046 gtk_entry_real_activate (GtkEntry *entry)
5049 GtkWidget *default_widget, *focus_widget;
5050 GtkWidget *toplevel;
5053 widget = GTK_WIDGET (entry);
5055 if (entry->activates_default)
5057 toplevel = gtk_widget_get_toplevel (widget);
5058 if (GTK_IS_WINDOW (toplevel))
5060 window = GTK_WINDOW (toplevel);
5064 default_widget = gtk_window_get_default_widget (window);
5065 focus_widget = gtk_window_get_focus (window);
5066 if (widget != default_widget &&
5067 !(widget == focus_widget && (!default_widget || !gtk_widget_get_sensitive (default_widget))))
5068 gtk_window_activate_default (window);
5075 keymap_direction_changed (GdkKeymap *keymap,
5078 gtk_entry_recompute (entry);
5081 /* IM Context Callbacks
5085 gtk_entry_commit_cb (GtkIMContext *context,
5089 if (entry->editable)
5090 gtk_entry_enter_text (entry, str);
5094 gtk_entry_preedit_changed_cb (GtkIMContext *context,
5097 if (entry->editable)
5099 gchar *preedit_string;
5102 gtk_im_context_get_preedit_string (entry->im_context,
5103 &preedit_string, NULL,
5105 g_signal_emit (entry, signals[PREEDIT_CHANGED], 0, preedit_string);
5106 entry->preedit_length = strlen (preedit_string);
5107 cursor_pos = CLAMP (cursor_pos, 0, g_utf8_strlen (preedit_string, -1));
5108 entry->preedit_cursor = cursor_pos;
5109 g_free (preedit_string);
5111 gtk_entry_recompute (entry);
5116 gtk_entry_retrieve_surrounding_cb (GtkIMContext *context,
5121 /* XXXX ??? does this even make sense when text is not visible? Should we return FALSE? */
5122 text = gtk_entry_get_display_text (entry, 0, -1);
5123 gtk_im_context_set_surrounding (context, text, strlen (text), /* Length in bytes */
5124 g_utf8_offset_to_pointer (text, entry->current_pos) - text);
5131 gtk_entry_delete_surrounding_cb (GtkIMContext *slave,
5136 if (entry->editable)
5137 gtk_editable_delete_text (GTK_EDITABLE (entry),
5138 entry->current_pos + offset,
5139 entry->current_pos + offset + n_chars);
5144 /* Internal functions
5147 /* Used for im_commit_cb and inserting Unicode chars */
5149 gtk_entry_enter_text (GtkEntry *entry,
5152 GtkEditable *editable = GTK_EDITABLE (entry);
5154 gboolean old_need_im_reset;
5156 old_need_im_reset = entry->need_im_reset;
5157 entry->need_im_reset = FALSE;
5159 if (gtk_editable_get_selection_bounds (editable, NULL, NULL))
5160 gtk_editable_delete_selection (editable);
5163 if (entry->overwrite_mode)
5164 gtk_entry_delete_from_cursor (entry, GTK_DELETE_CHARS, 1);
5167 tmp_pos = entry->current_pos;
5168 gtk_editable_insert_text (editable, str, strlen (str), &tmp_pos);
5169 gtk_editable_set_position (editable, tmp_pos);
5171 entry->need_im_reset = old_need_im_reset;
5174 /* All changes to entry->current_pos and entry->selection_bound
5175 * should go through this function.
5178 gtk_entry_set_positions (GtkEntry *entry,
5180 gint selection_bound)
5182 gboolean changed = FALSE;
5184 g_object_freeze_notify (G_OBJECT (entry));
5186 if (current_pos != -1 &&
5187 entry->current_pos != current_pos)
5189 entry->current_pos = current_pos;
5192 g_object_notify (G_OBJECT (entry), "cursor-position");
5195 if (selection_bound != -1 &&
5196 entry->selection_bound != selection_bound)
5198 entry->selection_bound = selection_bound;
5201 g_object_notify (G_OBJECT (entry), "selection-bound");
5204 g_object_thaw_notify (G_OBJECT (entry));
5208 gtk_entry_move_adjustments (entry);
5209 gtk_entry_recompute (entry);
5214 gtk_entry_reset_layout (GtkEntry *entry)
5216 if (entry->cached_layout)
5218 g_object_unref (entry->cached_layout);
5219 entry->cached_layout = NULL;
5224 update_im_cursor_location (GtkEntry *entry)
5228 gint strong_xoffset;
5229 gint area_width, area_height;
5231 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
5232 gtk_entry_get_text_area_size (entry, NULL, NULL, &area_width, &area_height);
5234 strong_xoffset = strong_x - entry->scroll_offset;
5235 if (strong_xoffset < 0)
5239 else if (strong_xoffset > area_width)
5241 strong_xoffset = area_width;
5243 area.x = strong_xoffset;
5246 area.height = area_height;
5248 gtk_im_context_set_cursor_location (entry->im_context, &area);
5252 recompute_idle_func (gpointer data)
5256 entry = GTK_ENTRY (data);
5258 entry->recompute_idle = 0;
5260 if (gtk_widget_has_screen (GTK_WIDGET (entry)))
5262 gtk_entry_adjust_scroll (entry);
5263 gtk_entry_queue_draw (entry);
5265 update_im_cursor_location (entry);
5272 gtk_entry_recompute (GtkEntry *entry)
5274 gtk_entry_reset_layout (entry);
5275 gtk_entry_check_cursor_blink (entry);
5277 if (!entry->recompute_idle)
5279 entry->recompute_idle = gdk_threads_add_idle_full (G_PRIORITY_HIGH_IDLE + 15, /* between resize and redraw */
5280 recompute_idle_func, entry, NULL);
5284 static PangoLayout *
5285 gtk_entry_create_layout (GtkEntry *entry,
5286 gboolean include_preedit)
5288 GtkWidget *widget = GTK_WIDGET (entry);
5289 PangoLayout *layout = gtk_widget_create_pango_layout (widget, NULL);
5290 PangoAttrList *tmp_attrs = pango_attr_list_new ();
5292 gchar *preedit_string = NULL;
5293 gint preedit_length = 0;
5294 PangoAttrList *preedit_attrs = NULL;
5299 pango_layout_set_single_paragraph_mode (layout, TRUE);
5301 display = gtk_entry_get_display_text (entry, 0, -1);
5302 n_bytes = strlen (display);
5304 if (include_preedit)
5306 gtk_im_context_get_preedit_string (entry->im_context,
5307 &preedit_string, &preedit_attrs, NULL);
5308 preedit_length = entry->preedit_length;
5313 GString *tmp_string = g_string_new (display);
5314 gint cursor_index = g_utf8_offset_to_pointer (display, entry->current_pos) - display;
5316 g_string_insert (tmp_string, cursor_index, preedit_string);
5318 pango_layout_set_text (layout, tmp_string->str, tmp_string->len);
5320 pango_attr_list_splice (tmp_attrs, preedit_attrs,
5321 cursor_index, preedit_length);
5323 g_string_free (tmp_string, TRUE);
5327 PangoDirection pango_dir;
5329 if (gtk_entry_get_display_mode (entry) == DISPLAY_NORMAL)
5330 pango_dir = pango_find_base_dir (display, n_bytes);
5332 pango_dir = PANGO_DIRECTION_NEUTRAL;
5334 if (pango_dir == PANGO_DIRECTION_NEUTRAL)
5336 if (gtk_widget_has_focus (widget))
5338 GdkDisplay *display = gtk_widget_get_display (widget);
5339 GdkKeymap *keymap = gdk_keymap_get_for_display (display);
5340 if (gdk_keymap_get_direction (keymap) == PANGO_DIRECTION_RTL)
5341 pango_dir = PANGO_DIRECTION_RTL;
5343 pango_dir = PANGO_DIRECTION_LTR;
5347 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
5348 pango_dir = PANGO_DIRECTION_RTL;
5350 pango_dir = PANGO_DIRECTION_LTR;
5354 pango_context_set_base_dir (gtk_widget_get_pango_context (widget),
5357 entry->resolved_dir = pango_dir;
5359 pango_layout_set_text (layout, display, n_bytes);
5362 pango_layout_set_attributes (layout, tmp_attrs);
5364 g_free (preedit_string);
5368 pango_attr_list_unref (preedit_attrs);
5370 pango_attr_list_unref (tmp_attrs);
5375 static PangoLayout *
5376 gtk_entry_ensure_layout (GtkEntry *entry,
5377 gboolean include_preedit)
5379 if (entry->preedit_length > 0 &&
5380 !include_preedit != !entry->cache_includes_preedit)
5381 gtk_entry_reset_layout (entry);
5383 if (!entry->cached_layout)
5385 entry->cached_layout = gtk_entry_create_layout (entry, include_preedit);
5386 entry->cache_includes_preedit = include_preedit;
5389 return entry->cached_layout;
5393 get_layout_position (GtkEntry *entry,
5397 PangoLayout *layout;
5398 PangoRectangle logical_rect;
5399 gint area_width, area_height;
5400 GtkBorder inner_border;
5402 PangoLayoutLine *line;
5404 layout = gtk_entry_ensure_layout (entry, TRUE);
5406 gtk_entry_get_text_area_size (entry, NULL, NULL, &area_width, &area_height);
5407 _gtk_entry_effective_inner_border (entry, &inner_border);
5409 area_height = PANGO_SCALE * (area_height - inner_border.top - inner_border.bottom);
5411 line = pango_layout_get_lines_readonly (layout)->data;
5412 pango_layout_line_get_extents (line, NULL, &logical_rect);
5414 /* Align primarily for locale's ascent/descent */
5415 y_pos = ((area_height - entry->ascent - entry->descent) / 2 +
5416 entry->ascent + logical_rect.y);
5418 /* Now see if we need to adjust to fit in actual drawn string */
5419 if (logical_rect.height > area_height)
5420 y_pos = (area_height - logical_rect.height) / 2;
5423 else if (y_pos + logical_rect.height > area_height)
5424 y_pos = area_height - logical_rect.height;
5426 y_pos = inner_border.top + y_pos / PANGO_SCALE;
5429 *x = inner_border.left - entry->scroll_offset;
5436 draw_text_with_color (GtkEntry *entry, cairo_t *cr, GdkColor *default_color)
5438 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
5441 gint start_pos, end_pos;
5443 widget = GTK_WIDGET (entry);
5447 get_layout_position (entry, &x, &y);
5449 cairo_move_to (cr, x, y);
5450 gdk_cairo_set_source_color (cr, default_color);
5451 pango_cairo_show_layout (cr, layout);
5453 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start_pos, &end_pos))
5457 PangoRectangle logical_rect;
5458 GdkColor *selection_color, *text_color;
5459 GtkBorder inner_border;
5462 pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
5463 gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
5465 style = gtk_widget_get_style (widget);
5467 if (gtk_widget_has_focus (widget))
5469 selection_color = &style->base [GTK_STATE_SELECTED];
5470 text_color = &style->text [GTK_STATE_SELECTED];
5474 selection_color = &style->base [GTK_STATE_ACTIVE];
5475 text_color = &style->text [GTK_STATE_ACTIVE];
5478 _gtk_entry_effective_inner_border (entry, &inner_border);
5480 for (i = 0; i < n_ranges; ++i)
5481 cairo_rectangle (cr,
5482 inner_border.left - entry->scroll_offset + ranges[2 * i],
5485 logical_rect.height);
5489 gdk_cairo_set_source_color (cr, selection_color);
5492 cairo_move_to (cr, x, y);
5493 gdk_cairo_set_source_color (cr, text_color);
5494 pango_cairo_show_layout (cr, layout);
5502 gtk_entry_draw_text (GtkEntry *entry,
5505 GtkWidget *widget = GTK_WIDGET (entry);
5508 GdkColor text_color, bar_text_color;
5511 gint progress_x, progress_y, progress_width, progress_height;
5512 gint clip_width, clip_height;
5514 /* Nothing to display at all */
5515 if (gtk_entry_get_display_mode (entry) == DISPLAY_BLANK)
5518 state = GTK_STATE_SELECTED;
5519 if (!gtk_widget_get_sensitive (widget))
5520 state = GTK_STATE_INSENSITIVE;
5521 style = gtk_widget_get_style (widget);
5522 text_color = style->text[gtk_widget_get_state (widget)];
5523 bar_text_color = style->fg[state];
5525 get_progress_area (widget,
5526 &progress_x, &progress_y,
5527 &progress_width, &progress_height);
5529 clip_width = gdk_window_get_width (entry->text_area);
5530 clip_height = gdk_window_get_height (entry->text_area);
5531 cairo_rectangle (cr, 0, 0, clip_width, clip_height);
5534 /* If the color is the same, or the progress area has a zero
5535 * size, then we only need to draw once. */
5536 if ((text_color.pixel == bar_text_color.pixel) ||
5537 ((progress_width == 0) || (progress_height == 0)))
5539 draw_text_with_color (entry, cr, &text_color);
5543 width = gdk_window_get_width (entry->text_area);
5544 height = gdk_window_get_height (entry->text_area);
5548 cairo_rectangle (cr, 0, 0, width, height);
5552 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
5553 cairo_rectangle (cr, 0, 0, width, height);
5555 gdk_window_get_position (entry->text_area, &pos_x, &pos_y);
5556 progress_x -= pos_x;
5557 progress_y -= pos_y;
5559 cairo_rectangle (cr, progress_x, progress_y,
5560 progress_width, progress_height);
5562 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_WINDING);
5564 draw_text_with_color (entry, cr, &text_color);
5567 cairo_rectangle (cr, progress_x, progress_y,
5568 progress_width, progress_height);
5571 draw_text_with_color (entry, cr, &bar_text_color);
5578 draw_insertion_cursor (GtkEntry *entry,
5580 GdkRectangle *cursor_location,
5581 gboolean is_primary,
5582 PangoDirection direction,
5583 gboolean draw_arrow)
5585 GtkWidget *widget = GTK_WIDGET (entry);
5586 GtkTextDirection text_dir;
5588 if (direction == PANGO_DIRECTION_LTR)
5589 text_dir = GTK_TEXT_DIR_LTR;
5591 text_dir = GTK_TEXT_DIR_RTL;
5593 gtk_draw_insertion_cursor (widget, cr,
5595 is_primary, text_dir, draw_arrow);
5599 gtk_entry_draw_cursor (GtkEntry *entry,
5603 GtkWidget *widget = GTK_WIDGET (entry);
5604 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
5605 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
5606 GdkRectangle cursor_location;
5607 gboolean split_cursor;
5608 PangoRectangle cursor_rect;
5609 GtkBorder inner_border;
5611 gint text_area_height;
5614 gboolean block_at_line_end;
5615 PangoLayout *layout;
5618 _gtk_entry_effective_inner_border (entry, &inner_border);
5620 xoffset = inner_border.left - entry->scroll_offset;
5622 text_area_height = gdk_window_get_height (entry->text_area);
5624 layout = gtk_entry_ensure_layout (entry, TRUE);
5625 text = pango_layout_get_text (layout);
5626 cursor_index = g_utf8_offset_to_pointer (text, entry->current_pos + entry->preedit_cursor) - text;
5627 if (!entry->overwrite_mode)
5630 block = _gtk_text_util_get_block_cursor_location (layout,
5631 cursor_index, &cursor_rect, &block_at_line_end);
5635 gint strong_x, weak_x;
5636 PangoDirection dir1 = PANGO_DIRECTION_NEUTRAL;
5637 PangoDirection dir2 = PANGO_DIRECTION_NEUTRAL;
5641 gtk_entry_get_cursor_locations (entry, type, &strong_x, &weak_x);
5643 g_object_get (gtk_widget_get_settings (widget),
5644 "gtk-split-cursor", &split_cursor,
5647 dir1 = entry->resolved_dir;
5653 if (weak_x != strong_x)
5655 dir2 = (entry->resolved_dir == PANGO_DIRECTION_LTR) ? PANGO_DIRECTION_RTL : PANGO_DIRECTION_LTR;
5661 if (keymap_direction == entry->resolved_dir)
5667 cursor_location.x = xoffset + x1;
5668 cursor_location.y = inner_border.top;
5669 cursor_location.width = 0;
5670 cursor_location.height = text_area_height - inner_border.top - inner_border.bottom;
5672 draw_insertion_cursor (entry, cr,
5673 &cursor_location, TRUE, dir1,
5674 dir2 != PANGO_DIRECTION_NEUTRAL);
5676 if (dir2 != PANGO_DIRECTION_NEUTRAL)
5678 cursor_location.x = xoffset + x2;
5679 draw_insertion_cursor (entry, cr,
5680 &cursor_location, FALSE, dir2,
5684 else /* overwrite_mode */
5686 GdkColor cursor_color;
5692 get_layout_position (entry, &x, &y);
5694 rect.x = PANGO_PIXELS (cursor_rect.x) + x;
5695 rect.y = PANGO_PIXELS (cursor_rect.y) + y;
5696 rect.width = PANGO_PIXELS (cursor_rect.width);
5697 rect.height = PANGO_PIXELS (cursor_rect.height);
5699 _gtk_widget_get_cursor_color (widget, &cursor_color);
5700 gdk_cairo_set_source_color (cr, &cursor_color);
5701 gdk_cairo_rectangle (cr, &rect);
5704 if (!block_at_line_end)
5706 gdk_cairo_rectangle (cr, &rect);
5708 cairo_move_to (cr, x, y);
5709 gdk_cairo_set_source_color (cr, >k_widget_get_style (widget)->base[gtk_widget_get_state (widget)]);
5710 pango_cairo_show_layout (cr, layout);
5718 gtk_entry_queue_draw (GtkEntry *entry)
5720 if (gtk_widget_is_drawable (GTK_WIDGET (entry)))
5721 gdk_window_invalidate_rect (gtk_widget_get_window (GTK_WIDGET (entry)),
5726 _gtk_entry_reset_im_context (GtkEntry *entry)
5728 if (entry->need_im_reset)
5730 entry->need_im_reset = FALSE;
5731 gtk_im_context_reset (entry->im_context);
5736 * gtk_entry_reset_im_context:
5737 * @entry: a #GtkEntry
5739 * Reset the input method context of the entry if needed.
5741 * This can be necessary in the case where modifying the buffer
5742 * would confuse on-going input method behavior.
5747 gtk_entry_reset_im_context (GtkEntry *entry)
5749 g_return_if_fail (GTK_IS_ENTRY (entry));
5751 _gtk_entry_reset_im_context (entry);
5755 * gtk_entry_im_context_filter_keypress:
5756 * @entry: a #GtkEntry
5757 * @event: the key event
5759 * Allow the #GtkEntry input method to internally handle key press
5760 * and release events. If this function returns %TRUE, then no further
5761 * processing should be done for this key event. See
5762 * gtk_im_context_filter_keypress().
5764 * Note that you are expected to call this function from your handler
5765 * when overriding key event handling. This is needed in the case when
5766 * you need to insert your own key handling between the input method
5767 * and the default key event handling of the #GtkEntry.
5768 * See gtk_text_view_reset_im_context() for an example of use.
5770 * Return value: %TRUE if the input method handled the key event.
5775 gtk_entry_im_context_filter_keypress (GtkEntry *entry,
5778 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
5780 return gtk_im_context_filter_keypress (entry->im_context, event);
5785 gtk_entry_find_position (GtkEntry *entry,
5788 PangoLayout *layout;
5789 PangoLayoutLine *line;
5796 layout = gtk_entry_ensure_layout (entry, TRUE);
5797 text = pango_layout_get_text (layout);
5798 cursor_index = g_utf8_offset_to_pointer (text, entry->current_pos) - text;
5800 line = pango_layout_get_lines_readonly (layout)->data;
5801 pango_layout_line_x_to_index (line, x * PANGO_SCALE, &index, &trailing);
5803 if (index >= cursor_index && entry->preedit_length)
5805 if (index >= cursor_index + entry->preedit_length)
5806 index -= entry->preedit_length;
5809 index = cursor_index;
5814 pos = g_utf8_pointer_to_offset (text, text + index);
5821 gtk_entry_get_cursor_locations (GtkEntry *entry,
5826 DisplayMode mode = gtk_entry_get_display_mode (entry);
5828 /* Nothing to display at all, so no cursor is relevant */
5829 if (mode == DISPLAY_BLANK)
5839 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
5840 const gchar *text = pango_layout_get_text (layout);
5841 PangoRectangle strong_pos, weak_pos;
5844 if (type == CURSOR_STANDARD)
5846 index = g_utf8_offset_to_pointer (text, entry->current_pos + entry->preedit_cursor) - text;
5848 else /* type == CURSOR_DND */
5850 index = g_utf8_offset_to_pointer (text, entry->dnd_position) - text;
5852 if (entry->dnd_position > entry->current_pos)
5854 if (mode == DISPLAY_NORMAL)
5855 index += entry->preedit_length;
5858 gint preedit_len_chars = g_utf8_strlen (text, -1) - gtk_entry_buffer_get_length (get_buffer (entry));
5859 index += preedit_len_chars * g_unichar_to_utf8 (entry->invisible_char, NULL);
5864 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
5867 *strong_x = strong_pos.x / PANGO_SCALE;
5870 *weak_x = weak_pos.x / PANGO_SCALE;
5875 gtk_entry_adjust_scroll (GtkEntry *entry)
5877 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
5878 gint min_offset, max_offset;
5879 gint text_area_width, text_width;
5880 GtkBorder inner_border;
5881 gint strong_x, weak_x;
5882 gint strong_xoffset, weak_xoffset;
5884 PangoLayout *layout;
5885 PangoLayoutLine *line;
5886 PangoRectangle logical_rect;
5888 if (!gtk_widget_get_realized (GTK_WIDGET (entry)))
5891 _gtk_entry_effective_inner_border (entry, &inner_border);
5893 text_area_width = gdk_window_get_width (entry->text_area);
5894 text_area_width -= inner_border.left + inner_border.right;
5895 if (text_area_width < 0)
5896 text_area_width = 0;
5898 layout = gtk_entry_ensure_layout (entry, TRUE);
5899 line = pango_layout_get_lines_readonly (layout)->data;
5901 pango_layout_line_get_extents (line, NULL, &logical_rect);
5903 /* Display as much text as we can */
5905 if (entry->resolved_dir == PANGO_DIRECTION_LTR)
5906 xalign = priv->xalign;
5908 xalign = 1.0 - priv->xalign;
5910 text_width = PANGO_PIXELS(logical_rect.width);
5912 if (text_width > text_area_width)
5915 max_offset = text_width - text_area_width;
5919 min_offset = (text_width - text_area_width) * xalign;
5920 max_offset = min_offset;
5923 entry->scroll_offset = CLAMP (entry->scroll_offset, min_offset, max_offset);
5925 /* And make sure cursors are on screen. Note that the cursor is
5926 * actually drawn one pixel into the INNER_BORDER space on
5927 * the right, when the scroll is at the utmost right. This
5928 * looks better to to me than confining the cursor inside the
5929 * border entirely, though it means that the cursor gets one
5930 * pixel closer to the edge of the widget on the right than
5931 * on the left. This might need changing if one changed
5932 * INNER_BORDER from 2 to 1, as one would do on a
5933 * small-screen-real-estate display.
5935 * We always make sure that the strong cursor is on screen, and
5936 * put the weak cursor on screen if possible.
5939 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, &weak_x);
5941 strong_xoffset = strong_x - entry->scroll_offset;
5943 if (strong_xoffset < 0)
5945 entry->scroll_offset += strong_xoffset;
5948 else if (strong_xoffset > text_area_width)
5950 entry->scroll_offset += strong_xoffset - text_area_width;
5951 strong_xoffset = text_area_width;
5954 weak_xoffset = weak_x - entry->scroll_offset;
5956 if (weak_xoffset < 0 && strong_xoffset - weak_xoffset <= text_area_width)
5958 entry->scroll_offset += weak_xoffset;
5960 else if (weak_xoffset > text_area_width &&
5961 strong_xoffset - (weak_xoffset - text_area_width) >= 0)
5963 entry->scroll_offset += weak_xoffset - text_area_width;
5966 g_object_notify (G_OBJECT (entry), "scroll-offset");
5970 gtk_entry_move_adjustments (GtkEntry *entry)
5972 GtkAllocation allocation;
5973 GtkAdjustment *adjustment;
5974 PangoContext *context;
5975 PangoFontMetrics *metrics;
5976 gint x, layout_x, border_x, border_y;
5979 adjustment = g_object_get_qdata (G_OBJECT (entry), quark_cursor_hadjustment);
5983 gtk_widget_get_allocation (&(entry->widget), &allocation);
5985 /* Cursor position, layout offset, border width, and widget allocation */
5986 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &x, NULL);
5987 get_layout_position (entry, &layout_x, NULL);
5988 _gtk_entry_get_borders (entry, &border_x, &border_y);
5989 x += allocation.x + layout_x + border_x;
5991 /* Approximate width of a char, so user can see what is ahead/behind */
5992 context = gtk_widget_get_pango_context (GTK_WIDGET (entry));
5993 metrics = pango_context_get_metrics (context,
5994 gtk_widget_get_style (&(entry->widget))->font_desc,
5995 pango_context_get_language (context));
5996 char_width = pango_font_metrics_get_approximate_char_width (metrics) / PANGO_SCALE;
5999 gtk_adjustment_clamp_page (adjustment,
6000 x - (char_width + 1), /* one char + one pixel before */
6001 x + (char_width + 2)); /* one char + cursor + one pixel after */
6005 gtk_entry_move_visually (GtkEntry *entry,
6010 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6013 text = pango_layout_get_text (layout);
6015 index = g_utf8_offset_to_pointer (text, start) - text;
6019 int new_index, new_trailing;
6020 gboolean split_cursor;
6023 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
6024 "gtk-split-cursor", &split_cursor,
6031 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
6032 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
6034 strong = keymap_direction == entry->resolved_dir;
6039 pango_layout_move_cursor_visually (layout, strong, index, 0, 1, &new_index, &new_trailing);
6044 pango_layout_move_cursor_visually (layout, strong, index, 0, -1, &new_index, &new_trailing);
6050 else if (new_index != G_MAXINT)
6053 while (new_trailing--)
6054 index = g_utf8_next_char (text + index) - text;
6057 return g_utf8_pointer_to_offset (text, text + index);
6061 gtk_entry_move_logically (GtkEntry *entry,
6065 gint new_pos = start;
6068 length = gtk_entry_buffer_get_length (get_buffer (entry));
6070 /* Prevent any leak of information */
6071 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6073 new_pos = CLAMP (start + count, 0, length);
6077 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6078 PangoLogAttr *log_attrs;
6081 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6083 while (count > 0 && new_pos < length)
6087 while (new_pos < length && !log_attrs[new_pos].is_cursor_position);
6091 while (count < 0 && new_pos > 0)
6095 while (new_pos > 0 && !log_attrs[new_pos].is_cursor_position);
6107 gtk_entry_move_forward_word (GtkEntry *entry,
6109 gboolean allow_whitespace)
6111 gint new_pos = start;
6114 length = gtk_entry_buffer_get_length (get_buffer (entry));
6116 /* Prevent any leak of information */
6117 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6121 else if (new_pos < length)
6123 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6124 PangoLogAttr *log_attrs;
6127 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6129 /* Find the next word boundary */
6131 while (new_pos < n_attrs - 1 && !(log_attrs[new_pos].is_word_end ||
6132 (log_attrs[new_pos].is_word_start && allow_whitespace)))
6143 gtk_entry_move_backward_word (GtkEntry *entry,
6145 gboolean allow_whitespace)
6147 gint new_pos = start;
6149 /* Prevent any leak of information */
6150 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6156 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6157 PangoLogAttr *log_attrs;
6160 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6162 new_pos = start - 1;
6164 /* Find the previous word boundary */
6165 while (new_pos > 0 && !(log_attrs[new_pos].is_word_start ||
6166 (log_attrs[new_pos].is_word_end && allow_whitespace)))
6176 gtk_entry_delete_whitespace (GtkEntry *entry)
6178 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6179 PangoLogAttr *log_attrs;
6183 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6185 start = end = entry->current_pos;
6187 while (start > 0 && log_attrs[start-1].is_white)
6190 while (end < n_attrs && log_attrs[end].is_white)
6196 gtk_editable_delete_text (GTK_EDITABLE (entry), start, end);
6201 gtk_entry_select_word (GtkEntry *entry)
6203 gint start_pos = gtk_entry_move_backward_word (entry, entry->current_pos, TRUE);
6204 gint end_pos = gtk_entry_move_forward_word (entry, entry->current_pos, TRUE);
6206 gtk_editable_select_region (GTK_EDITABLE (entry), start_pos, end_pos);
6210 gtk_entry_select_line (GtkEntry *entry)
6212 gtk_editable_select_region (GTK_EDITABLE (entry), 0, -1);
6216 truncate_multiline (const gchar *text)
6221 text[length] && text[length] != '\n' && text[length] != '\r';
6228 paste_received (GtkClipboard *clipboard,
6232 GtkEntry *entry = GTK_ENTRY (data);
6233 GtkEditable *editable = GTK_EDITABLE (entry);
6234 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
6236 if (entry->button == 2)
6238 gint pos, start, end;
6239 pos = priv->insert_pos;
6240 gtk_editable_get_selection_bounds (editable, &start, &end);
6241 if (!((start <= pos && pos <= end) || (end <= pos && pos <= start)))
6242 gtk_editable_select_region (editable, pos, pos);
6247 gint pos, start, end;
6249 gboolean popup_completion;
6250 GtkEntryCompletion *completion;
6252 completion = gtk_entry_get_completion (entry);
6254 if (entry->truncate_multiline)
6255 length = truncate_multiline (text);
6257 /* only complete if the selection is at the end */
6258 popup_completion = (gtk_entry_buffer_get_length (get_buffer (entry)) ==
6259 MAX (entry->current_pos, entry->selection_bound));
6263 if (gtk_widget_get_mapped (completion->priv->popup_window))
6264 _gtk_entry_completion_popdown (completion);
6266 if (!popup_completion && completion->priv->changed_id > 0)
6267 g_signal_handler_block (entry, completion->priv->changed_id);
6270 begin_change (entry);
6271 g_object_freeze_notify (G_OBJECT (entry));
6272 if (gtk_editable_get_selection_bounds (editable, &start, &end))
6273 gtk_editable_delete_text (editable, start, end);
6275 pos = entry->current_pos;
6276 gtk_editable_insert_text (editable, text, length, &pos);
6277 gtk_editable_set_position (editable, pos);
6278 g_object_thaw_notify (G_OBJECT (entry));
6282 !popup_completion && completion->priv->changed_id > 0)
6283 g_signal_handler_unblock (entry, completion->priv->changed_id);
6286 g_object_unref (entry);
6290 gtk_entry_paste (GtkEntry *entry,
6293 g_object_ref (entry);
6294 gtk_clipboard_request_text (gtk_widget_get_clipboard (GTK_WIDGET (entry), selection),
6295 paste_received, entry);
6299 primary_get_cb (GtkClipboard *clipboard,
6300 GtkSelectionData *selection_data,
6304 GtkEntry *entry = GTK_ENTRY (data);
6307 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end))
6309 gchar *str = gtk_entry_get_display_text (entry, start, end);
6310 gtk_selection_data_set_text (selection_data, str, -1);
6316 primary_clear_cb (GtkClipboard *clipboard,
6319 GtkEntry *entry = GTK_ENTRY (data);
6321 gtk_editable_select_region (GTK_EDITABLE (entry), entry->current_pos, entry->current_pos);
6325 gtk_entry_update_primary_selection (GtkEntry *entry)
6327 GtkTargetList *list;
6328 GtkTargetEntry *targets;
6329 GtkClipboard *clipboard;
6333 if (!gtk_widget_get_realized (GTK_WIDGET (entry)))
6336 list = gtk_target_list_new (NULL, 0);
6337 gtk_target_list_add_text_targets (list, 0);
6339 targets = gtk_target_table_new_from_list (list, &n_targets);
6341 clipboard = gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_PRIMARY);
6343 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end))
6345 if (!gtk_clipboard_set_with_owner (clipboard, targets, n_targets,
6346 primary_get_cb, primary_clear_cb, G_OBJECT (entry)))
6347 primary_clear_cb (clipboard, entry);
6351 if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (entry))
6352 gtk_clipboard_clear (clipboard);
6355 gtk_target_table_free (targets, n_targets);
6356 gtk_target_list_unref (list);
6360 gtk_entry_clear (GtkEntry *entry,
6361 GtkEntryIconPosition icon_pos)
6363 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
6364 EntryIconInfo *icon_info = priv->icons[icon_pos];
6366 if (!icon_info || icon_info->storage_type == GTK_IMAGE_EMPTY)
6369 g_object_freeze_notify (G_OBJECT (entry));
6371 /* Explicitly check, as the pointer may become invalidated
6372 * during destruction.
6374 if (GDK_IS_WINDOW (icon_info->window))
6375 gdk_window_hide (icon_info->window);
6377 if (icon_info->pixbuf)
6379 g_object_unref (icon_info->pixbuf);
6380 icon_info->pixbuf = NULL;
6383 switch (icon_info->storage_type)
6385 case GTK_IMAGE_PIXBUF:
6386 g_object_notify (G_OBJECT (entry),
6387 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-pixbuf" : "secondary-icon-pixbuf");
6390 case GTK_IMAGE_STOCK:
6391 g_free (icon_info->stock_id);
6392 icon_info->stock_id = NULL;
6393 g_object_notify (G_OBJECT (entry),
6394 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-stock" : "secondary-icon-stock");
6397 case GTK_IMAGE_ICON_NAME:
6398 g_free (icon_info->icon_name);
6399 icon_info->icon_name = NULL;
6400 g_object_notify (G_OBJECT (entry),
6401 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-name" : "secondary-icon-name");
6404 case GTK_IMAGE_GICON:
6405 if (icon_info->gicon)
6407 g_object_unref (icon_info->gicon);
6408 icon_info->gicon = NULL;
6410 g_object_notify (G_OBJECT (entry),
6411 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-gicon" : "secondary-icon-gicon");
6415 g_assert_not_reached ();
6419 icon_info->storage_type = GTK_IMAGE_EMPTY;
6420 g_object_notify (G_OBJECT (entry),
6421 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-storage-type" : "secondary-icon-storage-type");
6423 g_object_thaw_notify (G_OBJECT (entry));
6427 gtk_entry_ensure_pixbuf (GtkEntry *entry,
6428 GtkEntryIconPosition icon_pos)
6430 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
6431 EntryIconInfo *icon_info = priv->icons[icon_pos];
6433 GtkIconTheme *icon_theme;
6434 GtkSettings *settings;
6440 if (!icon_info || icon_info->pixbuf)
6443 widget = GTK_WIDGET (entry);
6445 switch (icon_info->storage_type)
6447 case GTK_IMAGE_EMPTY:
6448 case GTK_IMAGE_PIXBUF:
6450 case GTK_IMAGE_STOCK:
6451 state = gtk_widget_get_state (widget);
6452 gtk_widget_set_state (widget, GTK_STATE_NORMAL);
6453 icon_info->pixbuf = gtk_widget_render_icon (widget,
6454 icon_info->stock_id,
6457 if (!icon_info->pixbuf)
6458 icon_info->pixbuf = gtk_widget_render_icon (widget,
6459 GTK_STOCK_MISSING_IMAGE,
6462 gtk_widget_set_state (widget, state);
6465 case GTK_IMAGE_ICON_NAME:
6466 screen = gtk_widget_get_screen (widget);
6469 icon_theme = gtk_icon_theme_get_for_screen (screen);
6470 settings = gtk_settings_get_for_screen (screen);
6472 gtk_icon_size_lookup_for_settings (settings,
6476 icon_info->pixbuf = gtk_icon_theme_load_icon (icon_theme,
6477 icon_info->icon_name,
6478 MIN (width, height),
6481 if (icon_info->pixbuf == NULL)
6483 state = gtk_widget_get_state (widget);
6484 gtk_widget_set_state (widget, GTK_STATE_NORMAL);
6485 icon_info->pixbuf = gtk_widget_render_icon (widget,
6486 GTK_STOCK_MISSING_IMAGE,
6489 gtk_widget_set_state (widget, state);
6494 case GTK_IMAGE_GICON:
6495 screen = gtk_widget_get_screen (widget);
6498 icon_theme = gtk_icon_theme_get_for_screen (screen);
6499 settings = gtk_settings_get_for_screen (screen);
6501 gtk_icon_size_lookup_for_settings (settings,
6505 info = gtk_icon_theme_lookup_by_gicon (icon_theme,
6507 MIN (width, height),
6508 GTK_ICON_LOOKUP_USE_BUILTIN);
6511 icon_info->pixbuf = gtk_icon_info_load_icon (info, NULL);
6512 gtk_icon_info_free (info);
6515 if (icon_info->pixbuf == NULL)
6517 state = gtk_widget_get_state (widget);
6518 gtk_widget_set_state (widget, GTK_STATE_NORMAL);
6519 icon_info->pixbuf = gtk_widget_render_icon (widget,
6520 GTK_STOCK_MISSING_IMAGE,
6523 gtk_widget_set_state (widget, state);
6529 g_assert_not_reached ();
6533 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
6534 gdk_window_show_unraised (icon_info->window);
6544 * Creates a new entry.
6546 * Return value: a new #GtkEntry.
6549 gtk_entry_new (void)
6551 return g_object_new (GTK_TYPE_ENTRY, NULL);
6555 * gtk_entry_new_with_buffer:
6556 * @buffer: The buffer to use for the new #GtkEntry.
6558 * Creates a new entry with the specified text buffer.
6560 * Return value: a new #GtkEntry
6565 gtk_entry_new_with_buffer (GtkEntryBuffer *buffer)
6567 g_return_val_if_fail (GTK_IS_ENTRY_BUFFER (buffer), NULL);
6568 return g_object_new (GTK_TYPE_ENTRY, "buffer", buffer, NULL);
6571 static GtkEntryBuffer*
6572 get_buffer (GtkEntry *entry)
6574 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
6576 if (priv->buffer == NULL)
6578 GtkEntryBuffer *buffer;
6579 buffer = gtk_entry_buffer_new (NULL, 0);
6580 gtk_entry_set_buffer (entry, buffer);
6581 g_object_unref (buffer);
6584 return priv->buffer;
6588 * gtk_entry_get_buffer:
6589 * @entry: a #GtkEntry
6591 * Get the #GtkEntryBuffer object which holds the text for
6596 * Returns: (transfer none): A #GtkEntryBuffer object.
6599 gtk_entry_get_buffer (GtkEntry *entry)
6601 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
6603 return get_buffer (entry);
6607 * gtk_entry_set_buffer:
6608 * @entry: a #GtkEntry
6609 * @buffer: a #GtkEntryBuffer
6611 * Set the #GtkEntryBuffer object which holds the text for
6617 gtk_entry_set_buffer (GtkEntry *entry,
6618 GtkEntryBuffer *buffer)
6620 GtkEntryPrivate *priv;
6623 g_return_if_fail (GTK_IS_ENTRY (entry));
6624 priv = GTK_ENTRY_GET_PRIVATE (entry);
6628 g_return_if_fail (GTK_IS_ENTRY_BUFFER (buffer));
6629 g_object_ref (buffer);
6634 buffer_disconnect_signals (entry);
6635 g_object_unref (priv->buffer);
6638 priv->buffer = buffer;
6641 buffer_connect_signals (entry);
6643 obj = G_OBJECT (entry);
6644 g_object_freeze_notify (obj);
6645 g_object_notify (obj, "buffer");
6646 g_object_notify (obj, "text");
6647 g_object_notify (obj, "text-length");
6648 g_object_notify (obj, "max-length");
6649 g_object_notify (obj, "visibility");
6650 g_object_notify (obj, "invisible-char");
6651 g_object_notify (obj, "invisible-char-set");
6652 g_object_thaw_notify (obj);
6654 gtk_editable_set_position (GTK_EDITABLE (entry), 0);
6655 gtk_entry_recompute (entry);
6659 * gtk_entry_get_text_area:
6660 * @entry: a #GtkEntry
6661 * @text_area: Return location for the text area.
6663 * Returns the area where the entry's text is drawn. This function is
6664 * useful when drawing something to the entry in a draw callback.
6666 * See also gtk_entry_get_icon_area().
6671 gtk_entry_get_text_area (GtkEntry *entry,
6672 GdkRectangle *text_area)
6674 g_return_if_fail (GTK_IS_ENTRY (entry));
6675 g_return_if_fail (text_area != NULL);
6677 if (entry->text_area)
6679 GtkAllocation allocation;
6682 gtk_widget_get_allocation (GTK_WIDGET (entry), &allocation);
6683 gdk_window_get_position (entry->text_area, &x, &y);
6685 text_area->x = x - allocation.x;
6686 text_area->y = y - allocation.y;
6687 text_area->width = gdk_window_get_width (entry->text_area);
6688 text_area->height = gdk_window_get_height (entry->text_area);
6694 text_area->width = 0;
6695 text_area->height = 0;
6700 * gtk_entry_set_text:
6701 * @entry: a #GtkEntry
6702 * @text: the new text
6704 * Sets the text in the widget to the given
6705 * value, replacing the current contents.
6707 * See gtk_entry_buffer_set_text().
6710 gtk_entry_set_text (GtkEntry *entry,
6714 GtkEntryCompletion *completion;
6715 GtkEntryPrivate *priv;
6717 g_return_if_fail (GTK_IS_ENTRY (entry));
6718 g_return_if_fail (text != NULL);
6719 priv = GTK_ENTRY_GET_PRIVATE (entry);
6721 /* Actually setting the text will affect the cursor and selection;
6722 * if the contents don't actually change, this will look odd to the user.
6724 if (strcmp (gtk_entry_buffer_get_text (get_buffer (entry)), text) == 0)
6727 completion = gtk_entry_get_completion (entry);
6728 if (completion && completion->priv->changed_id > 0)
6729 g_signal_handler_block (entry, completion->priv->changed_id);
6731 begin_change (entry);
6732 g_object_freeze_notify (G_OBJECT (entry));
6733 gtk_editable_delete_text (GTK_EDITABLE (entry), 0, -1);
6735 gtk_editable_insert_text (GTK_EDITABLE (entry), text, strlen (text), &tmp_pos);
6736 g_object_thaw_notify (G_OBJECT (entry));
6739 if (completion && completion->priv->changed_id > 0)
6740 g_signal_handler_unblock (entry, completion->priv->changed_id);
6744 * gtk_entry_set_visibility:
6745 * @entry: a #GtkEntry
6746 * @visible: %TRUE if the contents of the entry are displayed
6749 * Sets whether the contents of the entry are visible or not.
6750 * When visibility is set to %FALSE, characters are displayed
6751 * as the invisible char, and will also appear that way when
6752 * the text in the entry widget is copied elsewhere.
6754 * By default, GTK+ picks the best invisible character available
6755 * in the current font, but it can be changed with
6756 * gtk_entry_set_invisible_char().
6759 gtk_entry_set_visibility (GtkEntry *entry,
6762 g_return_if_fail (GTK_IS_ENTRY (entry));
6764 visible = visible != FALSE;
6766 if (entry->visible != visible)
6768 entry->visible = visible;
6770 g_object_notify (G_OBJECT (entry), "visibility");
6771 gtk_entry_recompute (entry);
6776 * gtk_entry_get_visibility:
6777 * @entry: a #GtkEntry
6779 * Retrieves whether the text in @entry is visible. See
6780 * gtk_entry_set_visibility().
6782 * Return value: %TRUE if the text is currently visible
6785 gtk_entry_get_visibility (GtkEntry *entry)
6787 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
6789 return entry->visible;
6793 * gtk_entry_set_invisible_char:
6794 * @entry: a #GtkEntry
6795 * @ch: a Unicode character
6797 * Sets the character to use in place of the actual text when
6798 * gtk_entry_set_visibility() has been called to set text visibility
6799 * to %FALSE. i.e. this is the character used in "password mode" to
6800 * show the user how many characters have been typed. By default, GTK+
6801 * picks the best invisible char available in the current font. If you
6802 * set the invisible char to 0, then the user will get no feedback
6803 * at all; there will be no text on the screen as they type.
6806 gtk_entry_set_invisible_char (GtkEntry *entry,
6809 GtkEntryPrivate *priv;
6811 g_return_if_fail (GTK_IS_ENTRY (entry));
6813 priv = GTK_ENTRY_GET_PRIVATE (entry);
6815 if (!priv->invisible_char_set)
6817 priv->invisible_char_set = TRUE;
6818 g_object_notify (G_OBJECT (entry), "invisible-char-set");
6821 if (ch == entry->invisible_char)
6824 entry->invisible_char = ch;
6825 g_object_notify (G_OBJECT (entry), "invisible-char");
6826 gtk_entry_recompute (entry);
6830 * gtk_entry_get_invisible_char:
6831 * @entry: a #GtkEntry
6833 * Retrieves the character displayed in place of the real characters
6834 * for entries with visibility set to false. See gtk_entry_set_invisible_char().
6836 * Return value: the current invisible char, or 0, if the entry does not
6837 * show invisible text at all.
6840 gtk_entry_get_invisible_char (GtkEntry *entry)
6842 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
6844 return entry->invisible_char;
6848 * gtk_entry_unset_invisible_char:
6849 * @entry: a #GtkEntry
6851 * Unsets the invisible char previously set with
6852 * gtk_entry_set_invisible_char(). So that the
6853 * default invisible char is used again.
6858 gtk_entry_unset_invisible_char (GtkEntry *entry)
6860 GtkEntryPrivate *priv;
6863 g_return_if_fail (GTK_IS_ENTRY (entry));
6865 priv = GTK_ENTRY_GET_PRIVATE (entry);
6867 if (!priv->invisible_char_set)
6870 priv->invisible_char_set = FALSE;
6871 ch = find_invisible_char (GTK_WIDGET (entry));
6873 if (entry->invisible_char != ch)
6875 entry->invisible_char = ch;
6876 g_object_notify (G_OBJECT (entry), "invisible-char");
6879 g_object_notify (G_OBJECT (entry), "invisible-char-set");
6880 gtk_entry_recompute (entry);
6884 * gtk_entry_set_overwrite_mode:
6885 * @entry: a #GtkEntry
6886 * @overwrite: new value
6888 * Sets whether the text is overwritten when typing in the #GtkEntry.
6893 gtk_entry_set_overwrite_mode (GtkEntry *entry,
6896 g_return_if_fail (GTK_IS_ENTRY (entry));
6898 if (entry->overwrite_mode == overwrite)
6901 gtk_entry_toggle_overwrite (entry);
6903 g_object_notify (G_OBJECT (entry), "overwrite-mode");
6907 * gtk_entry_get_overwrite_mode:
6908 * @entry: a #GtkEntry
6910 * Gets the value set by gtk_entry_set_overwrite_mode().
6912 * Return value: whether the text is overwritten when typing.
6917 gtk_entry_get_overwrite_mode (GtkEntry *entry)
6919 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
6921 return entry->overwrite_mode;
6925 * gtk_entry_get_text:
6926 * @entry: a #GtkEntry
6928 * Retrieves the contents of the entry widget.
6929 * See also gtk_editable_get_chars().
6931 * This is equivalent to:
6933 * <informalexample><programlisting>
6934 * gtk_entry_buffer_get_text (gtk_entry_get_buffer (entry));
6935 * </programlisting></informalexample>
6937 * Return value: a pointer to the contents of the widget as a
6938 * string. This string points to internally allocated
6939 * storage in the widget and must not be freed, modified or
6942 G_CONST_RETURN gchar*
6943 gtk_entry_get_text (GtkEntry *entry)
6945 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
6946 return gtk_entry_buffer_get_text (get_buffer (entry));
6950 * gtk_entry_set_max_length:
6951 * @entry: a #GtkEntry
6952 * @max: the maximum length of the entry, or 0 for no maximum.
6953 * (other than the maximum length of entries.) The value passed in will
6954 * be clamped to the range 0-65536.
6956 * Sets the maximum allowed length of the contents of the widget. If
6957 * the current contents are longer than the given length, then they
6958 * will be truncated to fit.
6960 * This is equivalent to:
6962 * <informalexample><programlisting>
6963 * gtk_entry_buffer_set_max_length (gtk_entry_get_buffer (entry), max);
6964 * </programlisting></informalexample>
6967 gtk_entry_set_max_length (GtkEntry *entry,
6970 g_return_if_fail (GTK_IS_ENTRY (entry));
6971 gtk_entry_buffer_set_max_length (get_buffer (entry), max);
6975 * gtk_entry_get_max_length:
6976 * @entry: a #GtkEntry
6978 * Retrieves the maximum allowed length of the text in
6979 * @entry. See gtk_entry_set_max_length().
6981 * This is equivalent to:
6983 * <informalexample><programlisting>
6984 * gtk_entry_buffer_get_max_length (gtk_entry_get_buffer (entry));
6985 * </programlisting></informalexample>
6987 * Return value: the maximum allowed number of characters
6988 * in #GtkEntry, or 0 if there is no maximum.
6991 gtk_entry_get_max_length (GtkEntry *entry)
6993 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
6994 return gtk_entry_buffer_get_max_length (get_buffer (entry));
6998 * gtk_entry_get_text_length:
6999 * @entry: a #GtkEntry
7001 * Retrieves the current length of the text in
7004 * This is equivalent to:
7006 * <informalexample><programlisting>
7007 * gtk_entry_buffer_get_length (gtk_entry_get_buffer (entry));
7008 * </programlisting></informalexample>
7010 * Return value: the current number of characters
7011 * in #GtkEntry, or 0 if there are none.
7016 gtk_entry_get_text_length (GtkEntry *entry)
7018 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7019 return gtk_entry_buffer_get_length (get_buffer (entry));
7023 * gtk_entry_set_activates_default:
7024 * @entry: a #GtkEntry
7025 * @setting: %TRUE to activate window's default widget on Enter keypress
7027 * If @setting is %TRUE, pressing Enter in the @entry will activate the default
7028 * widget for the window containing the entry. This usually means that
7029 * the dialog box containing the entry will be closed, since the default
7030 * widget is usually one of the dialog buttons.
7032 * (For experts: if @setting is %TRUE, the entry calls
7033 * gtk_window_activate_default() on the window containing the entry, in
7034 * the default handler for the #GtkWidget::activate signal.)
7037 gtk_entry_set_activates_default (GtkEntry *entry,
7040 g_return_if_fail (GTK_IS_ENTRY (entry));
7041 setting = setting != FALSE;
7043 if (setting != entry->activates_default)
7045 entry->activates_default = setting;
7046 g_object_notify (G_OBJECT (entry), "activates-default");
7051 * gtk_entry_get_activates_default:
7052 * @entry: a #GtkEntry
7054 * Retrieves the value set by gtk_entry_set_activates_default().
7056 * Return value: %TRUE if the entry will activate the default widget
7059 gtk_entry_get_activates_default (GtkEntry *entry)
7061 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7063 return entry->activates_default;
7067 * gtk_entry_set_width_chars:
7068 * @entry: a #GtkEntry
7069 * @n_chars: width in chars
7071 * Changes the size request of the entry to be about the right size
7072 * for @n_chars characters. Note that it changes the size
7073 * <emphasis>request</emphasis>, the size can still be affected by
7074 * how you pack the widget into containers. If @n_chars is -1, the
7075 * size reverts to the default entry size.
7078 gtk_entry_set_width_chars (GtkEntry *entry,
7081 g_return_if_fail (GTK_IS_ENTRY (entry));
7083 if (entry->width_chars != n_chars)
7085 entry->width_chars = n_chars;
7086 g_object_notify (G_OBJECT (entry), "width-chars");
7087 gtk_widget_queue_resize (GTK_WIDGET (entry));
7092 * gtk_entry_get_width_chars:
7093 * @entry: a #GtkEntry
7095 * Gets the value set by gtk_entry_set_width_chars().
7097 * Return value: number of chars to request space for, or negative if unset
7100 gtk_entry_get_width_chars (GtkEntry *entry)
7102 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7104 return entry->width_chars;
7108 * gtk_entry_set_has_frame:
7109 * @entry: a #GtkEntry
7110 * @setting: new value
7112 * Sets whether the entry has a beveled frame around it.
7115 gtk_entry_set_has_frame (GtkEntry *entry,
7118 g_return_if_fail (GTK_IS_ENTRY (entry));
7120 setting = (setting != FALSE);
7122 if (entry->has_frame == setting)
7125 gtk_widget_queue_resize (GTK_WIDGET (entry));
7126 entry->has_frame = setting;
7127 g_object_notify (G_OBJECT (entry), "has-frame");
7131 * gtk_entry_get_has_frame:
7132 * @entry: a #GtkEntry
7134 * Gets the value set by gtk_entry_set_has_frame().
7136 * Return value: whether the entry has a beveled frame
7139 gtk_entry_get_has_frame (GtkEntry *entry)
7141 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7143 return entry->has_frame;
7147 * gtk_entry_set_inner_border:
7148 * @entry: a #GtkEntry
7149 * @border: (allow-none): a #GtkBorder, or %NULL
7151 * Sets %entry's inner-border property to %border, or clears it if %NULL
7152 * is passed. The inner-border is the area around the entry's text, but
7155 * If set, this property overrides the inner-border style property.
7156 * Overriding the style-provided border is useful when you want to do
7157 * in-place editing of some text in a canvas or list widget, where
7158 * pixel-exact positioning of the entry is important.
7163 gtk_entry_set_inner_border (GtkEntry *entry,
7164 const GtkBorder *border)
7166 g_return_if_fail (GTK_IS_ENTRY (entry));
7168 gtk_widget_queue_resize (GTK_WIDGET (entry));
7171 g_object_set_qdata_full (G_OBJECT (entry), quark_inner_border,
7172 gtk_border_copy (border),
7173 (GDestroyNotify) gtk_border_free);
7175 g_object_set_qdata (G_OBJECT (entry), quark_inner_border, NULL);
7177 g_object_notify (G_OBJECT (entry), "inner-border");
7181 * gtk_entry_get_inner_border:
7182 * @entry: a #GtkEntry
7184 * This function returns the entry's #GtkEntry:inner-border property. See
7185 * gtk_entry_set_inner_border() for more information.
7187 * Return value: (transfer none): the entry's #GtkBorder, or %NULL if none was set.
7191 G_CONST_RETURN GtkBorder *
7192 gtk_entry_get_inner_border (GtkEntry *entry)
7194 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7196 return g_object_get_qdata (G_OBJECT (entry), quark_inner_border);
7200 * gtk_entry_get_layout:
7201 * @entry: a #GtkEntry
7203 * Gets the #PangoLayout used to display the entry.
7204 * The layout is useful to e.g. convert text positions to
7205 * pixel positions, in combination with gtk_entry_get_layout_offsets().
7206 * The returned layout is owned by the entry and must not be
7207 * modified or freed by the caller.
7209 * Keep in mind that the layout text may contain a preedit string, so
7210 * gtk_entry_layout_index_to_text_index() and
7211 * gtk_entry_text_index_to_layout_index() are needed to convert byte
7212 * indices in the layout to byte indices in the entry contents.
7214 * Return value: (transfer none): the #PangoLayout for this entry
7217 gtk_entry_get_layout (GtkEntry *entry)
7219 PangoLayout *layout;
7221 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7223 layout = gtk_entry_ensure_layout (entry, TRUE);
7230 * gtk_entry_layout_index_to_text_index:
7231 * @entry: a #GtkEntry
7232 * @layout_index: byte index into the entry layout text
7234 * Converts from a position in the entry contents (returned
7235 * by gtk_entry_get_text()) to a position in the
7236 * entry's #PangoLayout (returned by gtk_entry_get_layout(),
7237 * with text retrieved via pango_layout_get_text()).
7239 * Return value: byte index into the entry contents
7242 gtk_entry_layout_index_to_text_index (GtkEntry *entry,
7245 PangoLayout *layout;
7249 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7251 layout = gtk_entry_ensure_layout (entry, TRUE);
7252 text = pango_layout_get_text (layout);
7253 cursor_index = g_utf8_offset_to_pointer (text, entry->current_pos) - text;
7255 if (layout_index >= cursor_index && entry->preedit_length)
7257 if (layout_index >= cursor_index + entry->preedit_length)
7258 layout_index -= entry->preedit_length;
7260 layout_index = cursor_index;
7263 return layout_index;
7267 * gtk_entry_text_index_to_layout_index:
7268 * @entry: a #GtkEntry
7269 * @text_index: byte index into the entry contents
7271 * Converts from a position in the entry's #PangoLayout (returned by
7272 * gtk_entry_get_layout()) to a position in the entry contents
7273 * (returned by gtk_entry_get_text()).
7275 * Return value: byte index into the entry layout text
7278 gtk_entry_text_index_to_layout_index (GtkEntry *entry,
7281 PangoLayout *layout;
7284 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7286 layout = gtk_entry_ensure_layout (entry, TRUE);
7287 text = pango_layout_get_text (layout);
7288 cursor_index = g_utf8_offset_to_pointer (text, entry->current_pos) - text;
7290 if (text_index > cursor_index)
7291 text_index += entry->preedit_length;
7297 * gtk_entry_get_layout_offsets:
7298 * @entry: a #GtkEntry
7299 * @x: (allow-none): location to store X offset of layout, or %NULL
7300 * @y: (allow-none): location to store Y offset of layout, or %NULL
7303 * Obtains the position of the #PangoLayout used to render text
7304 * in the entry, in widget coordinates. Useful if you want to line
7305 * up the text in an entry with some other text, e.g. when using the
7306 * entry to implement editable cells in a sheet widget.
7308 * Also useful to convert mouse events into coordinates inside the
7309 * #PangoLayout, e.g. to take some action if some part of the entry text
7312 * Note that as the user scrolls around in the entry the offsets will
7313 * change; you'll need to connect to the "notify::scroll-offset"
7314 * signal to track this. Remember when using the #PangoLayout
7315 * functions you need to convert to and from pixels using
7316 * PANGO_PIXELS() or #PANGO_SCALE.
7318 * Keep in mind that the layout text may contain a preedit string, so
7319 * gtk_entry_layout_index_to_text_index() and
7320 * gtk_entry_text_index_to_layout_index() are needed to convert byte
7321 * indices in the layout to byte indices in the entry contents.
7324 gtk_entry_get_layout_offsets (GtkEntry *entry,
7328 gint text_area_x, text_area_y;
7330 g_return_if_fail (GTK_IS_ENTRY (entry));
7332 /* this gets coords relative to text area */
7333 get_layout_position (entry, x, y);
7335 /* convert to widget coords */
7336 gtk_entry_get_text_area_size (entry, &text_area_x, &text_area_y, NULL, NULL);
7347 * gtk_entry_set_alignment:
7348 * @entry: a #GtkEntry
7349 * @xalign: The horizontal alignment, from 0 (left) to 1 (right).
7350 * Reversed for RTL layouts
7352 * Sets the alignment for the contents of the entry. This controls
7353 * the horizontal positioning of the contents when the displayed
7354 * text is shorter than the width of the entry.
7359 gtk_entry_set_alignment (GtkEntry *entry, gfloat xalign)
7361 GtkEntryPrivate *priv;
7363 g_return_if_fail (GTK_IS_ENTRY (entry));
7365 priv = GTK_ENTRY_GET_PRIVATE (entry);
7369 else if (xalign > 1.0)
7372 if (xalign != priv->xalign)
7374 priv->xalign = xalign;
7376 gtk_entry_recompute (entry);
7378 g_object_notify (G_OBJECT (entry), "xalign");
7383 * gtk_entry_get_alignment:
7384 * @entry: a #GtkEntry
7386 * Gets the value set by gtk_entry_set_alignment().
7388 * Return value: the alignment
7393 gtk_entry_get_alignment (GtkEntry *entry)
7395 GtkEntryPrivate *priv;
7397 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
7399 priv = GTK_ENTRY_GET_PRIVATE (entry);
7401 return priv->xalign;
7405 * gtk_entry_set_icon_from_pixbuf:
7406 * @entry: a #GtkEntry
7407 * @icon_pos: Icon position
7408 * @pixbuf: (allow-none): A #GdkPixbuf, or %NULL
7410 * Sets the icon shown in the specified position using a pixbuf.
7412 * If @pixbuf is %NULL, no icon will be shown in the specified position.
7417 gtk_entry_set_icon_from_pixbuf (GtkEntry *entry,
7418 GtkEntryIconPosition icon_pos,
7421 GtkEntryPrivate *priv;
7422 EntryIconInfo *icon_info;
7424 g_return_if_fail (GTK_IS_ENTRY (entry));
7425 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7427 priv = GTK_ENTRY_GET_PRIVATE (entry);
7429 if ((icon_info = priv->icons[icon_pos]) == NULL)
7430 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7432 g_object_freeze_notify (G_OBJECT (entry));
7435 g_object_ref (pixbuf);
7437 gtk_entry_clear (entry, icon_pos);
7441 icon_info->storage_type = GTK_IMAGE_PIXBUF;
7442 icon_info->pixbuf = pixbuf;
7444 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7446 g_object_notify (G_OBJECT (entry), "primary-icon-pixbuf");
7447 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7451 g_object_notify (G_OBJECT (entry), "secondary-icon-pixbuf");
7452 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7455 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7456 gdk_window_show_unraised (icon_info->window);
7459 gtk_entry_ensure_pixbuf (entry, icon_pos);
7461 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7462 gtk_widget_queue_resize (GTK_WIDGET (entry));
7464 g_object_thaw_notify (G_OBJECT (entry));
7468 * gtk_entry_set_icon_from_stock:
7469 * @entry: A #GtkEntry
7470 * @icon_pos: Icon position
7471 * @stock_id: (allow-none): The name of the stock item, or %NULL
7473 * Sets the icon shown in the entry at the specified position from
7476 * If @stock_id is %NULL, no icon will be shown in the specified position.
7481 gtk_entry_set_icon_from_stock (GtkEntry *entry,
7482 GtkEntryIconPosition icon_pos,
7483 const gchar *stock_id)
7485 GtkEntryPrivate *priv;
7486 EntryIconInfo *icon_info;
7489 g_return_if_fail (GTK_IS_ENTRY (entry));
7490 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7492 priv = GTK_ENTRY_GET_PRIVATE (entry);
7494 if ((icon_info = priv->icons[icon_pos]) == NULL)
7495 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7497 g_object_freeze_notify (G_OBJECT (entry));
7499 gtk_widget_ensure_style (GTK_WIDGET (entry));
7501 /* need to dup before clearing */
7502 new_id = g_strdup (stock_id);
7504 gtk_entry_clear (entry, icon_pos);
7508 icon_info->storage_type = GTK_IMAGE_STOCK;
7509 icon_info->stock_id = new_id;
7511 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7513 g_object_notify (G_OBJECT (entry), "primary-icon-stock");
7514 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7518 g_object_notify (G_OBJECT (entry), "secondary-icon-stock");
7519 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7522 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7523 gdk_window_show_unraised (icon_info->window);
7526 gtk_entry_ensure_pixbuf (entry, icon_pos);
7528 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7529 gtk_widget_queue_resize (GTK_WIDGET (entry));
7531 g_object_thaw_notify (G_OBJECT (entry));
7535 * gtk_entry_set_icon_from_icon_name:
7536 * @entry: A #GtkEntry
7537 * @icon_pos: The position at which to set the icon
7538 * @icon_name: (allow-none): An icon name, or %NULL
7540 * Sets the icon shown in the entry at the specified position
7541 * from the current icon theme.
7543 * If the icon name isn't known, a "broken image" icon will be displayed
7546 * If @icon_name is %NULL, no icon will be shown in the specified position.
7551 gtk_entry_set_icon_from_icon_name (GtkEntry *entry,
7552 GtkEntryIconPosition icon_pos,
7553 const gchar *icon_name)
7555 GtkEntryPrivate *priv;
7556 EntryIconInfo *icon_info;
7559 g_return_if_fail (GTK_IS_ENTRY (entry));
7560 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7562 priv = GTK_ENTRY_GET_PRIVATE (entry);
7564 if ((icon_info = priv->icons[icon_pos]) == NULL)
7565 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7567 g_object_freeze_notify (G_OBJECT (entry));
7569 gtk_widget_ensure_style (GTK_WIDGET (entry));
7571 /* need to dup before clearing */
7572 new_name = g_strdup (icon_name);
7574 gtk_entry_clear (entry, icon_pos);
7576 if (new_name != NULL)
7578 icon_info->storage_type = GTK_IMAGE_ICON_NAME;
7579 icon_info->icon_name = new_name;
7581 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7583 g_object_notify (G_OBJECT (entry), "primary-icon-name");
7584 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7588 g_object_notify (G_OBJECT (entry), "secondary-icon-name");
7589 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7592 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7593 gdk_window_show_unraised (icon_info->window);
7596 gtk_entry_ensure_pixbuf (entry, icon_pos);
7598 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7599 gtk_widget_queue_resize (GTK_WIDGET (entry));
7601 g_object_thaw_notify (G_OBJECT (entry));
7605 * gtk_entry_set_icon_from_gicon:
7606 * @entry: A #GtkEntry
7607 * @icon_pos: The position at which to set the icon
7608 * @icon: (allow-none): The icon to set, or %NULL
7610 * Sets the icon shown in the entry at the specified position
7611 * from the current icon theme.
7612 * If the icon isn't known, a "broken image" icon will be displayed
7615 * If @icon is %NULL, no icon will be shown in the specified position.
7620 gtk_entry_set_icon_from_gicon (GtkEntry *entry,
7621 GtkEntryIconPosition icon_pos,
7624 GtkEntryPrivate *priv;
7625 EntryIconInfo *icon_info;
7627 g_return_if_fail (GTK_IS_ENTRY (entry));
7628 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7630 priv = GTK_ENTRY_GET_PRIVATE (entry);
7632 if ((icon_info = priv->icons[icon_pos]) == NULL)
7633 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7635 g_object_freeze_notify (G_OBJECT (entry));
7637 /* need to ref before clearing */
7639 g_object_ref (icon);
7641 gtk_entry_clear (entry, icon_pos);
7645 icon_info->storage_type = GTK_IMAGE_GICON;
7646 icon_info->gicon = icon;
7648 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7650 g_object_notify (G_OBJECT (entry), "primary-icon-gicon");
7651 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7655 g_object_notify (G_OBJECT (entry), "secondary-icon-gicon");
7656 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7659 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7660 gdk_window_show_unraised (icon_info->window);
7663 gtk_entry_ensure_pixbuf (entry, icon_pos);
7665 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7666 gtk_widget_queue_resize (GTK_WIDGET (entry));
7668 g_object_thaw_notify (G_OBJECT (entry));
7672 * gtk_entry_set_icon_activatable:
7673 * @entry: A #GtkEntry
7674 * @icon_pos: Icon position
7675 * @activatable: %TRUE if the icon should be activatable
7677 * Sets whether the icon is activatable.
7682 gtk_entry_set_icon_activatable (GtkEntry *entry,
7683 GtkEntryIconPosition icon_pos,
7684 gboolean activatable)
7686 GtkEntryPrivate *priv;
7687 EntryIconInfo *icon_info;
7689 g_return_if_fail (GTK_IS_ENTRY (entry));
7690 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7692 priv = GTK_ENTRY_GET_PRIVATE (entry);
7694 if ((icon_info = priv->icons[icon_pos]) == NULL)
7695 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7697 activatable = activatable != FALSE;
7699 if (icon_info->nonactivatable != !activatable)
7701 icon_info->nonactivatable = !activatable;
7703 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
7704 update_cursors (GTK_WIDGET (entry));
7706 g_object_notify (G_OBJECT (entry),
7707 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-activatable" : "secondary-icon-activatable");
7712 * gtk_entry_get_icon_activatable:
7713 * @entry: a #GtkEntry
7714 * @icon_pos: Icon position
7716 * Returns whether the icon is activatable.
7718 * Returns: %TRUE if the icon is activatable.
7723 gtk_entry_get_icon_activatable (GtkEntry *entry,
7724 GtkEntryIconPosition icon_pos)
7726 GtkEntryPrivate *priv;
7727 EntryIconInfo *icon_info;
7729 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7730 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), FALSE);
7732 priv = GTK_ENTRY_GET_PRIVATE (entry);
7733 icon_info = priv->icons[icon_pos];
7735 return (icon_info != NULL && !icon_info->nonactivatable);
7739 * gtk_entry_get_icon_pixbuf:
7740 * @entry: A #GtkEntry
7741 * @icon_pos: Icon position
7743 * Retrieves the image used for the icon.
7745 * Unlike the other methods of setting and getting icon data, this
7746 * method will work regardless of whether the icon was set using a
7747 * #GdkPixbuf, a #GIcon, a stock item, or an icon name.
7749 * Returns: (transfer none): A #GdkPixbuf, or %NULL if no icon is
7750 * set for this position.
7755 gtk_entry_get_icon_pixbuf (GtkEntry *entry,
7756 GtkEntryIconPosition icon_pos)
7758 GtkEntryPrivate *priv;
7759 EntryIconInfo *icon_info;
7761 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7762 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7764 priv = GTK_ENTRY_GET_PRIVATE (entry);
7765 icon_info = priv->icons[icon_pos];
7770 gtk_entry_ensure_pixbuf (entry, icon_pos);
7772 return icon_info->pixbuf;
7776 * gtk_entry_get_icon_gicon:
7777 * @entry: A #GtkEntry
7778 * @icon_pos: Icon position
7780 * Retrieves the #GIcon used for the icon, or %NULL if there is
7781 * no icon or if the icon was set by some other method (e.g., by
7782 * stock, pixbuf, or icon name).
7784 * Returns: (transfer none): A #GIcon, or %NULL if no icon is set
7785 * or if the icon is not a #GIcon
7790 gtk_entry_get_icon_gicon (GtkEntry *entry,
7791 GtkEntryIconPosition icon_pos)
7793 GtkEntryPrivate *priv;
7794 EntryIconInfo *icon_info;
7796 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7797 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7799 priv = GTK_ENTRY_GET_PRIVATE (entry);
7800 icon_info = priv->icons[icon_pos];
7805 return icon_info->storage_type == GTK_IMAGE_GICON ? icon_info->gicon : NULL;
7809 * gtk_entry_get_icon_stock:
7810 * @entry: A #GtkEntry
7811 * @icon_pos: Icon position
7813 * Retrieves the stock id used for the icon, or %NULL if there is
7814 * no icon or if the icon was set by some other method (e.g., by
7815 * pixbuf, icon name or gicon).
7817 * Returns: A stock id, or %NULL if no icon is set or if the icon
7818 * wasn't set from a stock id
7823 gtk_entry_get_icon_stock (GtkEntry *entry,
7824 GtkEntryIconPosition icon_pos)
7826 GtkEntryPrivate *priv;
7827 EntryIconInfo *icon_info;
7829 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7830 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7832 priv = GTK_ENTRY_GET_PRIVATE (entry);
7833 icon_info = priv->icons[icon_pos];
7838 return icon_info->storage_type == GTK_IMAGE_STOCK ? icon_info->stock_id : NULL;
7842 * gtk_entry_get_icon_name:
7843 * @entry: A #GtkEntry
7844 * @icon_pos: Icon position
7846 * Retrieves the icon name used for the icon, or %NULL if there is
7847 * no icon or if the icon was set by some other method (e.g., by
7848 * pixbuf, stock or gicon).
7850 * Returns: An icon name, or %NULL if no icon is set or if the icon
7851 * wasn't set from an icon name
7856 gtk_entry_get_icon_name (GtkEntry *entry,
7857 GtkEntryIconPosition icon_pos)
7859 GtkEntryPrivate *priv;
7860 EntryIconInfo *icon_info;
7862 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7863 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7865 priv = GTK_ENTRY_GET_PRIVATE (entry);
7866 icon_info = priv->icons[icon_pos];
7871 return icon_info->storage_type == GTK_IMAGE_ICON_NAME ? icon_info->icon_name : NULL;
7875 * gtk_entry_set_icon_sensitive:
7876 * @entry: A #GtkEntry
7877 * @icon_pos: Icon position
7878 * @sensitive: Specifies whether the icon should appear
7879 * sensitive or insensitive
7881 * Sets the sensitivity for the specified icon.
7886 gtk_entry_set_icon_sensitive (GtkEntry *entry,
7887 GtkEntryIconPosition icon_pos,
7890 GtkEntryPrivate *priv;
7891 EntryIconInfo *icon_info;
7893 g_return_if_fail (GTK_IS_ENTRY (entry));
7894 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7896 priv = GTK_ENTRY_GET_PRIVATE (entry);
7898 if ((icon_info = priv->icons[icon_pos]) == NULL)
7899 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7901 if (icon_info->insensitive != !sensitive)
7903 icon_info->insensitive = !sensitive;
7905 icon_info->pressed = FALSE;
7906 icon_info->prelight = FALSE;
7908 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
7909 update_cursors (GTK_WIDGET (entry));
7911 gtk_widget_queue_draw (GTK_WIDGET (entry));
7913 g_object_notify (G_OBJECT (entry),
7914 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-sensitive" : "secondary-icon-sensitive");
7919 * gtk_entry_get_icon_sensitive:
7920 * @entry: a #GtkEntry
7921 * @icon_pos: Icon position
7923 * Returns whether the icon appears sensitive or insensitive.
7925 * Returns: %TRUE if the icon is sensitive.
7930 gtk_entry_get_icon_sensitive (GtkEntry *entry,
7931 GtkEntryIconPosition icon_pos)
7933 GtkEntryPrivate *priv;
7934 EntryIconInfo *icon_info;
7936 g_return_val_if_fail (GTK_IS_ENTRY (entry), TRUE);
7937 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), TRUE);
7939 priv = GTK_ENTRY_GET_PRIVATE (entry);
7940 icon_info = priv->icons[icon_pos];
7942 return (!icon_info || !icon_info->insensitive);
7947 * gtk_entry_get_icon_storage_type:
7948 * @entry: a #GtkEntry
7949 * @icon_pos: Icon position
7951 * Gets the type of representation being used by the icon
7952 * to store image data. If the icon has no image data,
7953 * the return value will be %GTK_IMAGE_EMPTY.
7955 * Return value: image representation being used
7960 gtk_entry_get_icon_storage_type (GtkEntry *entry,
7961 GtkEntryIconPosition icon_pos)
7963 GtkEntryPrivate *priv;
7964 EntryIconInfo *icon_info;
7966 g_return_val_if_fail (GTK_IS_ENTRY (entry), GTK_IMAGE_EMPTY);
7967 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), GTK_IMAGE_EMPTY);
7969 priv = GTK_ENTRY_GET_PRIVATE (entry);
7970 icon_info = priv->icons[icon_pos];
7973 return GTK_IMAGE_EMPTY;
7975 return icon_info->storage_type;
7979 * gtk_entry_get_icon_at_pos:
7980 * @entry: a #GtkEntry
7981 * @x: the x coordinate of the position to find
7982 * @y: the y coordinate of the position to find
7984 * Finds the icon at the given position and return its index.
7985 * If @x, @y doesn't lie inside an icon, -1 is returned.
7986 * This function is intended for use in a #GtkWidget::query-tooltip
7989 * Returns: the index of the icon at the given position, or -1
7994 gtk_entry_get_icon_at_pos (GtkEntry *entry,
7998 GtkAllocation primary;
7999 GtkAllocation secondary;
8000 gint frame_x, frame_y;
8002 g_return_val_if_fail (GTK_IS_ENTRY (entry), -1);
8004 get_frame_size (entry, &frame_x, &frame_y, NULL, NULL);
8008 get_icon_allocations (entry, &primary, &secondary);
8010 if (primary.x <= x && x < primary.x + primary.width &&
8011 primary.y <= y && y < primary.y + primary.height)
8012 return GTK_ENTRY_ICON_PRIMARY;
8014 if (secondary.x <= x && x < secondary.x + secondary.width &&
8015 secondary.y <= y && y < secondary.y + secondary.height)
8016 return GTK_ENTRY_ICON_SECONDARY;
8022 * gtk_entry_set_icon_drag_source:
8023 * @entry: a #GtkIconEntry
8024 * @icon_pos: icon position
8025 * @target_list: the targets (data formats) in which the data can be provided
8026 * @actions: a bitmask of the allowed drag actions
8028 * Sets up the icon at the given position so that GTK+ will start a drag
8029 * operation when the user clicks and drags the icon.
8031 * To handle the drag operation, you need to connect to the usual
8032 * #GtkWidget::drag-data-get (or possibly #GtkWidget::drag-data-delete)
8033 * signal, and use gtk_entry_get_current_icon_drag_source() in
8034 * your signal handler to find out if the drag was started from
8037 * By default, GTK+ uses the icon as the drag icon. You can use the
8038 * #GtkWidget::drag-begin signal to set a different icon. Note that you
8039 * have to use g_signal_connect_after() to ensure that your signal handler
8040 * gets executed after the default handler.
8045 gtk_entry_set_icon_drag_source (GtkEntry *entry,
8046 GtkEntryIconPosition icon_pos,
8047 GtkTargetList *target_list,
8048 GdkDragAction actions)
8050 GtkEntryPrivate *priv;
8051 EntryIconInfo *icon_info;
8053 g_return_if_fail (GTK_IS_ENTRY (entry));
8054 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8056 priv = GTK_ENTRY_GET_PRIVATE (entry);
8058 if ((icon_info = priv->icons[icon_pos]) == NULL)
8059 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8061 if (icon_info->target_list)
8062 gtk_target_list_unref (icon_info->target_list);
8063 icon_info->target_list = target_list;
8064 if (icon_info->target_list)
8065 gtk_target_list_ref (icon_info->target_list);
8067 icon_info->actions = actions;
8071 * gtk_entry_get_current_icon_drag_source:
8072 * @entry: a #GtkIconEntry
8074 * Returns the index of the icon which is the source of the current
8075 * DND operation, or -1.
8077 * This function is meant to be used in a #GtkWidget::drag-data-get
8080 * Returns: index of the icon which is the source of the current
8081 * DND operation, or -1.
8086 gtk_entry_get_current_icon_drag_source (GtkEntry *entry)
8088 GtkEntryPrivate *priv;
8089 EntryIconInfo *icon_info = NULL;
8092 g_return_val_if_fail (GTK_IS_ENTRY (entry), -1);
8094 priv = GTK_ENTRY_GET_PRIVATE (entry);
8096 for (i = 0; i < MAX_ICONS; i++)
8098 if ((icon_info = priv->icons[i]))
8100 if (icon_info->in_drag)
8109 * gtk_entry_get_icon_area:
8110 * @entry: A #GtkEntry
8111 * @icon_pos: Icon position
8112 * @icon_area: Return location for the icon's area
8114 * Returns the area where entry's icon at @icon_pos is drawn.
8115 * This function is useful when drawing something to the
8116 * entry in a draw callback.
8118 * See also gtk_entry_get_text_area()
8123 gtk_entry_get_icon_area (GtkEntry *entry,
8124 GtkEntryIconPosition icon_pos,
8125 GdkRectangle *icon_area)
8127 GtkEntryPrivate *priv;
8128 EntryIconInfo *icon_info;
8130 g_return_if_fail (GTK_IS_ENTRY (entry));
8131 g_return_if_fail (icon_area != NULL);
8133 priv = GTK_ENTRY_GET_PRIVATE (entry);
8135 icon_info = priv->icons[icon_pos];
8139 GtkAllocation primary;
8140 GtkAllocation secondary;
8142 get_icon_allocations (entry, &primary, &secondary);
8144 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
8145 *icon_area = primary;
8147 *icon_area = secondary;
8153 icon_area->width = 0;
8154 icon_area->height = 0;
8159 ensure_has_tooltip (GtkEntry *entry)
8161 GtkEntryPrivate *priv;
8162 EntryIconInfo *icon_info;
8164 gboolean has_tooltip = FALSE;
8166 priv = GTK_ENTRY_GET_PRIVATE (entry);
8168 for (i = 0; i < MAX_ICONS; i++)
8170 if ((icon_info = priv->icons[i]) != NULL)
8172 if (icon_info->tooltip != NULL)
8180 gtk_widget_set_has_tooltip (GTK_WIDGET (entry), has_tooltip);
8184 * gtk_entry_get_icon_tooltip_text:
8185 * @entry: a #GtkEntry
8186 * @icon_pos: the icon position
8188 * Gets the contents of the tooltip on the icon at the specified
8189 * position in @entry.
8191 * Returns: the tooltip text, or %NULL. Free the returned string
8192 * with g_free() when done.
8197 gtk_entry_get_icon_tooltip_text (GtkEntry *entry,
8198 GtkEntryIconPosition icon_pos)
8200 GtkEntryPrivate *priv;
8201 EntryIconInfo *icon_info;
8204 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8205 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8207 priv = GTK_ENTRY_GET_PRIVATE (entry);
8208 icon_info = priv->icons[icon_pos];
8213 if (icon_info->tooltip &&
8214 !pango_parse_markup (icon_info->tooltip, -1, 0, NULL, &text, NULL, NULL))
8215 g_assert (NULL == text); /* text should still be NULL in case of markup errors */
8221 * gtk_entry_set_icon_tooltip_text:
8222 * @entry: a #GtkEntry
8223 * @icon_pos: the icon position
8224 * @tooltip: (allow-none): the contents of the tooltip for the icon, or %NULL
8226 * Sets @tooltip as the contents of the tooltip for the icon
8227 * at the specified position.
8229 * Use %NULL for @tooltip to remove an existing tooltip.
8231 * See also gtk_widget_set_tooltip_text() and
8232 * gtk_entry_set_icon_tooltip_markup().
8237 gtk_entry_set_icon_tooltip_text (GtkEntry *entry,
8238 GtkEntryIconPosition icon_pos,
8239 const gchar *tooltip)
8241 GtkEntryPrivate *priv;
8242 EntryIconInfo *icon_info;
8244 g_return_if_fail (GTK_IS_ENTRY (entry));
8245 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8247 priv = GTK_ENTRY_GET_PRIVATE (entry);
8249 if (!(icon_info = priv->icons[icon_pos]))
8250 icon_info = priv->icons[icon_pos];
8252 if (icon_info->tooltip)
8253 g_free (icon_info->tooltip);
8255 /* Treat an empty string as a NULL string,
8256 * because an empty string would be useless for a tooltip:
8258 if (tooltip && tooltip[0] == '\0')
8261 icon_info->tooltip = tooltip ? g_markup_escape_text (tooltip, -1) : NULL;
8263 ensure_has_tooltip (entry);
8267 * gtk_entry_get_icon_tooltip_markup:
8268 * @entry: a #GtkEntry
8269 * @icon_pos: the icon position
8271 * Gets the contents of the tooltip on the icon at the specified
8272 * position in @entry.
8274 * Returns: the tooltip text, or %NULL. Free the returned string
8275 * with g_free() when done.
8280 gtk_entry_get_icon_tooltip_markup (GtkEntry *entry,
8281 GtkEntryIconPosition icon_pos)
8283 GtkEntryPrivate *priv;
8284 EntryIconInfo *icon_info;
8286 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8287 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8289 priv = GTK_ENTRY_GET_PRIVATE (entry);
8290 icon_info = priv->icons[icon_pos];
8295 return g_strdup (icon_info->tooltip);
8299 * gtk_entry_set_icon_tooltip_markup:
8300 * @entry: a #GtkEntry
8301 * @icon_pos: the icon position
8302 * @tooltip: (allow-none): the contents of the tooltip for the icon, or %NULL
8304 * Sets @tooltip as the contents of the tooltip for the icon at
8305 * the specified position. @tooltip is assumed to be marked up with
8306 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
8308 * Use %NULL for @tooltip to remove an existing tooltip.
8310 * See also gtk_widget_set_tooltip_markup() and
8311 * gtk_enty_set_icon_tooltip_text().
8316 gtk_entry_set_icon_tooltip_markup (GtkEntry *entry,
8317 GtkEntryIconPosition icon_pos,
8318 const gchar *tooltip)
8320 GtkEntryPrivate *priv;
8321 EntryIconInfo *icon_info;
8323 g_return_if_fail (GTK_IS_ENTRY (entry));
8324 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8326 priv = GTK_ENTRY_GET_PRIVATE (entry);
8328 if (!(icon_info = priv->icons[icon_pos]))
8329 icon_info = priv->icons[icon_pos];
8331 if (icon_info->tooltip)
8332 g_free (icon_info->tooltip);
8334 /* Treat an empty string as a NULL string,
8335 * because an empty string would be useless for a tooltip:
8337 if (tooltip && tooltip[0] == '\0')
8340 icon_info->tooltip = g_strdup (tooltip);
8342 ensure_has_tooltip (entry);
8346 gtk_entry_query_tooltip (GtkWidget *widget,
8349 gboolean keyboard_tip,
8350 GtkTooltip *tooltip)
8353 GtkEntryPrivate *priv;
8354 EntryIconInfo *icon_info;
8357 entry = GTK_ENTRY (widget);
8358 priv = GTK_ENTRY_GET_PRIVATE (entry);
8362 icon_pos = gtk_entry_get_icon_at_pos (entry, x, y);
8365 if ((icon_info = priv->icons[icon_pos]) != NULL)
8367 if (icon_info->tooltip)
8369 gtk_tooltip_set_markup (tooltip, icon_info->tooltip);
8378 return GTK_WIDGET_CLASS (gtk_entry_parent_class)->query_tooltip (widget,
8385 /* Quick hack of a popup menu
8388 activate_cb (GtkWidget *menuitem,
8391 const gchar *signal = g_object_get_data (G_OBJECT (menuitem), "gtk-signal");
8392 g_signal_emit_by_name (entry, signal);
8397 gtk_entry_mnemonic_activate (GtkWidget *widget,
8398 gboolean group_cycling)
8400 gtk_widget_grab_focus (widget);
8405 append_action_signal (GtkEntry *entry,
8407 const gchar *stock_id,
8408 const gchar *signal,
8411 GtkWidget *menuitem = gtk_image_menu_item_new_from_stock (stock_id, NULL);
8413 g_object_set_data (G_OBJECT (menuitem), I_("gtk-signal"), (char *)signal);
8414 g_signal_connect (menuitem, "activate",
8415 G_CALLBACK (activate_cb), entry);
8417 gtk_widget_set_sensitive (menuitem, sensitive);
8419 gtk_widget_show (menuitem);
8420 gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
8424 popup_menu_detach (GtkWidget *attach_widget,
8427 GTK_ENTRY (attach_widget)->popup_menu = NULL;
8431 popup_position_func (GtkMenu *menu,
8437 GtkEntry *entry = GTK_ENTRY (user_data);
8438 GtkWidget *widget = GTK_WIDGET (entry);
8440 GtkRequisition menu_req;
8441 GdkRectangle monitor;
8442 GtkBorder inner_border;
8443 gint monitor_num, strong_x, height;
8445 g_return_if_fail (gtk_widget_get_realized (widget));
8447 gdk_window_get_origin (entry->text_area, x, y);
8449 screen = gtk_widget_get_screen (widget);
8450 monitor_num = gdk_screen_get_monitor_at_window (screen, entry->text_area);
8451 if (monitor_num < 0)
8453 gtk_menu_set_monitor (menu, monitor_num);
8455 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
8456 gtk_widget_get_preferred_size (entry->popup_menu,
8458 height = gdk_window_get_height (entry->text_area);
8459 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
8460 _gtk_entry_effective_inner_border (entry, &inner_border);
8462 *x += inner_border.left + strong_x - entry->scroll_offset;
8463 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
8464 *x -= menu_req.width;
8466 if ((*y + height + menu_req.height) <= monitor.y + monitor.height)
8468 else if ((*y - menu_req.height) >= monitor.y)
8469 *y -= menu_req.height;
8470 else if (monitor.y + monitor.height - (*y + height) > *y)
8473 *y -= menu_req.height;
8479 unichar_chosen_func (const char *text,
8482 GtkEntry *entry = GTK_ENTRY (data);
8484 if (entry->editable)
8485 gtk_entry_enter_text (entry, text);
8496 popup_targets_received (GtkClipboard *clipboard,
8497 GtkSelectionData *data,
8500 PopupInfo *info = user_data;
8501 GtkEntry *entry = info->entry;
8503 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
8506 gboolean clipboard_contains_text;
8507 GtkWidget *menuitem;
8509 gboolean show_input_method_menu;
8510 gboolean show_unicode_menu;
8512 clipboard_contains_text = gtk_selection_data_targets_include_text (data);
8513 if (entry->popup_menu)
8514 gtk_widget_destroy (entry->popup_menu);
8516 entry->popup_menu = gtk_menu_new ();
8518 gtk_menu_attach_to_widget (GTK_MENU (entry->popup_menu),
8522 mode = gtk_entry_get_display_mode (entry);
8523 append_action_signal (entry, entry->popup_menu, GTK_STOCK_CUT, "cut-clipboard",
8524 entry->editable && mode == DISPLAY_NORMAL &&
8525 entry->current_pos != entry->selection_bound);
8527 append_action_signal (entry, entry->popup_menu, GTK_STOCK_COPY, "copy-clipboard",
8528 mode == DISPLAY_NORMAL &&
8529 entry->current_pos != entry->selection_bound);
8531 append_action_signal (entry, entry->popup_menu, GTK_STOCK_PASTE, "paste-clipboard",
8532 entry->editable && clipboard_contains_text);
8534 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_DELETE, NULL);
8535 gtk_widget_set_sensitive (menuitem, entry->editable && entry->current_pos != entry->selection_bound);
8536 g_signal_connect_swapped (menuitem, "activate",
8537 G_CALLBACK (gtk_entry_delete_cb), entry);
8538 gtk_widget_show (menuitem);
8539 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8541 menuitem = gtk_separator_menu_item_new ();
8542 gtk_widget_show (menuitem);
8543 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8545 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_SELECT_ALL, NULL);
8546 g_signal_connect_swapped (menuitem, "activate",
8547 G_CALLBACK (gtk_entry_select_all), entry);
8548 gtk_widget_show (menuitem);
8549 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8551 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
8552 "gtk-show-input-method-menu", &show_input_method_menu,
8553 "gtk-show-unicode-menu", &show_unicode_menu,
8556 if (show_input_method_menu || show_unicode_menu)
8558 menuitem = gtk_separator_menu_item_new ();
8559 gtk_widget_show (menuitem);
8560 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8563 if (show_input_method_menu)
8565 menuitem = gtk_menu_item_new_with_mnemonic (_("Input _Methods"));
8566 gtk_widget_set_sensitive (menuitem, entry->editable);
8567 gtk_widget_show (menuitem);
8568 submenu = gtk_menu_new ();
8569 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
8571 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8573 gtk_im_multicontext_append_menuitems (GTK_IM_MULTICONTEXT (entry->im_context),
8574 GTK_MENU_SHELL (submenu));
8577 if (show_unicode_menu)
8579 menuitem = gtk_menu_item_new_with_mnemonic (_("_Insert Unicode Control Character"));
8580 gtk_widget_set_sensitive (menuitem, entry->editable);
8581 gtk_widget_show (menuitem);
8583 submenu = gtk_menu_new ();
8584 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
8585 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8587 _gtk_text_util_append_special_char_menuitems (GTK_MENU_SHELL (submenu),
8588 unichar_chosen_func,
8592 g_signal_emit (entry,
8593 signals[POPULATE_POPUP],
8599 gtk_menu_popup (GTK_MENU (entry->popup_menu), NULL, NULL,
8601 info->button, info->time);
8604 gtk_menu_popup (GTK_MENU (entry->popup_menu), NULL, NULL,
8605 popup_position_func, entry,
8606 info->button, info->time);
8607 gtk_menu_shell_select_first (GTK_MENU_SHELL (entry->popup_menu), FALSE);
8611 g_object_unref (entry);
8612 g_slice_free (PopupInfo, info);
8616 gtk_entry_do_popup (GtkEntry *entry,
8617 GdkEventButton *event)
8619 PopupInfo *info = g_slice_new (PopupInfo);
8621 /* In order to know what entries we should make sensitive, we
8622 * ask for the current targets of the clipboard, and when
8623 * we get them, then we actually pop up the menu.
8625 info->entry = g_object_ref (entry);
8629 info->button = event->button;
8630 info->time = event->time;
8635 info->time = gtk_get_current_event_time ();
8638 gtk_clipboard_request_contents (gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_CLIPBOARD),
8639 gdk_atom_intern_static_string ("TARGETS"),
8640 popup_targets_received,
8645 gtk_entry_popup_menu (GtkWidget *widget)
8647 gtk_entry_do_popup (GTK_ENTRY (widget), NULL);
8652 gtk_entry_drag_begin (GtkWidget *widget,
8653 GdkDragContext *context)
8655 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
8658 for (i = 0; i < MAX_ICONS; i++)
8660 EntryIconInfo *icon_info = priv->icons[i];
8662 if (icon_info != NULL)
8664 if (icon_info->in_drag)
8666 switch (icon_info->storage_type)
8668 case GTK_IMAGE_STOCK:
8669 gtk_drag_set_icon_stock (context, icon_info->stock_id, -2, -2);
8672 case GTK_IMAGE_ICON_NAME:
8673 gtk_drag_set_icon_name (context, icon_info->icon_name, -2, -2);
8676 /* FIXME: No GIcon support for dnd icons */
8677 case GTK_IMAGE_GICON:
8678 case GTK_IMAGE_PIXBUF:
8679 gtk_drag_set_icon_pixbuf (context, icon_info->pixbuf, -2, -2);
8682 g_assert_not_reached ();
8690 gtk_entry_drag_end (GtkWidget *widget,
8691 GdkDragContext *context)
8693 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
8696 for (i = 0; i < MAX_ICONS; i++)
8698 EntryIconInfo *icon_info = priv->icons[i];
8700 if (icon_info != NULL)
8701 icon_info->in_drag = 0;
8706 gtk_entry_drag_leave (GtkWidget *widget,
8707 GdkDragContext *context,
8710 GtkEntry *entry = GTK_ENTRY (widget);
8712 entry->dnd_position = -1;
8713 gtk_widget_queue_draw (widget);
8717 gtk_entry_drag_drop (GtkWidget *widget,
8718 GdkDragContext *context,
8723 GtkEntry *entry = GTK_ENTRY (widget);
8724 GdkAtom target = GDK_NONE;
8726 if (entry->editable)
8727 target = gtk_drag_dest_find_target (widget, context, NULL);
8729 if (target != GDK_NONE)
8730 gtk_drag_get_data (widget, context, target, time);
8732 gtk_drag_finish (context, FALSE, FALSE, time);
8738 gtk_entry_drag_motion (GtkWidget *widget,
8739 GdkDragContext *context,
8744 GtkEntry *entry = GTK_ENTRY (widget);
8746 GtkWidget *source_widget;
8747 GdkDragAction suggested_action;
8748 gint new_position, old_position;
8751 style = gtk_widget_get_style (widget);
8752 x -= style->xthickness;
8753 y -= style->ythickness;
8755 old_position = entry->dnd_position;
8756 new_position = gtk_entry_find_position (entry, x + entry->scroll_offset);
8758 if (entry->editable &&
8759 gtk_drag_dest_find_target (widget, context, NULL) != GDK_NONE)
8761 source_widget = gtk_drag_get_source_widget (context);
8762 suggested_action = context->suggested_action;
8764 if (!gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &sel1, &sel2) ||
8765 new_position < sel1 || new_position > sel2)
8767 if (source_widget == widget)
8769 /* Default to MOVE, unless the user has
8770 * pressed ctrl or alt to affect available actions
8772 if ((context->actions & GDK_ACTION_MOVE) != 0)
8773 suggested_action = GDK_ACTION_MOVE;
8776 entry->dnd_position = new_position;
8780 if (source_widget == widget)
8781 suggested_action = 0; /* Can't drop in selection where drag started */
8783 entry->dnd_position = -1;
8788 /* Entry not editable, or no text */
8789 suggested_action = 0;
8790 entry->dnd_position = -1;
8793 gdk_drag_status (context, suggested_action, time);
8795 if (entry->dnd_position != old_position)
8796 gtk_widget_queue_draw (widget);
8802 gtk_entry_drag_data_received (GtkWidget *widget,
8803 GdkDragContext *context,
8806 GtkSelectionData *selection_data,
8810 GtkEntry *entry = GTK_ENTRY (widget);
8811 GtkEditable *editable = GTK_EDITABLE (widget);
8815 str = (gchar *) gtk_selection_data_get_text (selection_data);
8817 style = gtk_widget_get_style (widget);
8818 x -= style->xthickness;
8819 y -= style->ythickness;
8821 if (str && entry->editable)
8827 if (entry->truncate_multiline)
8828 length = truncate_multiline (str);
8830 new_position = gtk_entry_find_position (entry, x + entry->scroll_offset);
8832 if (!gtk_editable_get_selection_bounds (editable, &sel1, &sel2) ||
8833 new_position < sel1 || new_position > sel2)
8835 gtk_editable_insert_text (editable, str, length, &new_position);
8839 /* Replacing selection */
8840 begin_change (entry);
8841 g_object_freeze_notify (G_OBJECT (entry));
8842 gtk_editable_delete_text (editable, sel1, sel2);
8843 gtk_editable_insert_text (editable, str, length, &sel1);
8844 g_object_thaw_notify (G_OBJECT (entry));
8848 gtk_drag_finish (context, TRUE, context->action == GDK_ACTION_MOVE, time);
8852 /* Drag and drop didn't happen! */
8853 gtk_drag_finish (context, FALSE, FALSE, time);
8860 gtk_entry_drag_data_get (GtkWidget *widget,
8861 GdkDragContext *context,
8862 GtkSelectionData *selection_data,
8866 gint sel_start, sel_end;
8869 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
8870 GtkEditable *editable = GTK_EDITABLE (widget);
8872 /* If there is an icon drag going on, exit early. */
8873 for (i = 0; i < MAX_ICONS; i++)
8875 EntryIconInfo *icon_info = priv->icons[i];
8877 if (icon_info != NULL)
8879 if (icon_info->in_drag)
8884 if (gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end))
8886 gchar *str = gtk_entry_get_display_text (GTK_ENTRY (widget), sel_start, sel_end);
8888 gtk_selection_data_set_text (selection_data, str, -1);
8896 gtk_entry_drag_data_delete (GtkWidget *widget,
8897 GdkDragContext *context)
8899 gint sel_start, sel_end;
8902 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
8903 GtkEditable *editable = GTK_EDITABLE (widget);
8905 /* If there is an icon drag going on, exit early. */
8906 for (i = 0; i < MAX_ICONS; i++)
8908 EntryIconInfo *icon_info = priv->icons[i];
8910 if (icon_info != NULL)
8912 if (icon_info->in_drag)
8917 if (GTK_ENTRY (widget)->editable &&
8918 gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end))
8919 gtk_editable_delete_text (editable, sel_start, sel_end);
8922 /* We display the cursor when
8924 * - the selection is empty, AND
8925 * - the widget has focus
8928 #define CURSOR_ON_MULTIPLIER 2
8929 #define CURSOR_OFF_MULTIPLIER 1
8930 #define CURSOR_PEND_MULTIPLIER 3
8931 #define CURSOR_DIVIDER 3
8934 cursor_blinks (GtkEntry *entry)
8936 if (gtk_widget_has_focus (GTK_WIDGET (entry)) &&
8938 entry->selection_bound == entry->current_pos)
8940 GtkSettings *settings;
8943 settings = gtk_widget_get_settings (GTK_WIDGET (entry));
8944 g_object_get (settings, "gtk-cursor-blink", &blink, NULL);
8953 get_cursor_time (GtkEntry *entry)
8955 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (entry));
8958 g_object_get (settings, "gtk-cursor-blink-time", &time, NULL);
8964 get_cursor_blink_timeout (GtkEntry *entry)
8966 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (entry));
8969 g_object_get (settings, "gtk-cursor-blink-timeout", &timeout, NULL);
8975 show_cursor (GtkEntry *entry)
8979 if (!entry->cursor_visible)
8981 entry->cursor_visible = TRUE;
8983 widget = GTK_WIDGET (entry);
8984 if (gtk_widget_has_focus (widget) && entry->selection_bound == entry->current_pos)
8985 gtk_widget_queue_draw (widget);
8990 hide_cursor (GtkEntry *entry)
8994 if (entry->cursor_visible)
8996 entry->cursor_visible = FALSE;
8998 widget = GTK_WIDGET (entry);
8999 if (gtk_widget_has_focus (widget) && entry->selection_bound == entry->current_pos)
9000 gtk_widget_queue_draw (widget);
9008 blink_cb (gpointer data)
9011 GtkEntryPrivate *priv;
9014 entry = GTK_ENTRY (data);
9015 priv = GTK_ENTRY_GET_PRIVATE (entry);
9017 if (!gtk_widget_has_focus (GTK_WIDGET (entry)))
9019 g_warning ("GtkEntry - did not receive focus-out-event. If you\n"
9020 "connect a handler to this signal, it must return\n"
9021 "FALSE so the entry gets the event as well");
9023 gtk_entry_check_cursor_blink (entry);
9028 g_assert (entry->selection_bound == entry->current_pos);
9030 blink_timeout = get_cursor_blink_timeout (entry);
9031 if (priv->blink_time > 1000 * blink_timeout &&
9032 blink_timeout < G_MAXINT/1000)
9034 /* we've blinked enough without the user doing anything, stop blinking */
9035 show_cursor (entry);
9036 entry->blink_timeout = 0;
9038 else if (entry->cursor_visible)
9040 hide_cursor (entry);
9041 entry->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_OFF_MULTIPLIER / CURSOR_DIVIDER,
9047 show_cursor (entry);
9048 priv->blink_time += get_cursor_time (entry);
9049 entry->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
9054 /* Remove ourselves */
9059 gtk_entry_check_cursor_blink (GtkEntry *entry)
9061 GtkEntryPrivate *priv;
9063 priv = GTK_ENTRY_GET_PRIVATE (entry);
9065 if (cursor_blinks (entry))
9067 if (!entry->blink_timeout)
9069 show_cursor (entry);
9070 entry->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
9077 if (entry->blink_timeout)
9079 g_source_remove (entry->blink_timeout);
9080 entry->blink_timeout = 0;
9083 entry->cursor_visible = TRUE;
9089 gtk_entry_pend_cursor_blink (GtkEntry *entry)
9091 if (cursor_blinks (entry))
9093 if (entry->blink_timeout != 0)
9094 g_source_remove (entry->blink_timeout);
9096 entry->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_PEND_MULTIPLIER / CURSOR_DIVIDER,
9099 show_cursor (entry);
9104 gtk_entry_reset_blink_time (GtkEntry *entry)
9106 GtkEntryPrivate *priv;
9108 priv = GTK_ENTRY_GET_PRIVATE (entry);
9110 priv->blink_time = 0;
9116 gtk_entry_completion_timeout (gpointer data)
9118 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (data);
9119 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (completion->priv->entry);
9121 completion->priv->completion_timeout = 0;
9123 if (completion->priv->filter_model &&
9124 g_utf8_strlen (gtk_entry_get_text (GTK_ENTRY (completion->priv->entry)), -1)
9125 >= completion->priv->minimum_key_length)
9129 GtkTreeSelection *s;
9130 gboolean popup_single;
9132 gtk_entry_completion_complete (completion);
9133 matches = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->filter_model), NULL);
9135 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9137 s = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view));
9139 gtk_tree_selection_unselect_all (s);
9141 actions = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->actions), NULL);
9143 g_object_get (completion, "popup-single-match", &popup_single, NULL);
9144 if ((matches > (popup_single ? 0: 1)) || actions > 0)
9146 if (gtk_widget_get_visible (completion->priv->popup_window))
9147 _gtk_entry_completion_resize_popup (completion);
9149 _gtk_entry_completion_popup (completion, priv->completion_device);
9152 _gtk_entry_completion_popdown (completion);
9154 else if (gtk_widget_get_visible (completion->priv->popup_window))
9155 _gtk_entry_completion_popdown (completion);
9160 static inline gboolean
9161 keyval_is_cursor_move (guint keyval)
9163 if (keyval == GDK_KEY_Up || keyval == GDK_KEY_KP_Up)
9166 if (keyval == GDK_KEY_Down || keyval == GDK_KEY_KP_Down)
9169 if (keyval == GDK_KEY_Page_Up)
9172 if (keyval == GDK_KEY_Page_Down)
9179 gtk_entry_completion_key_press (GtkWidget *widget,
9183 gint matches, actions = 0;
9184 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
9186 if (!gtk_widget_get_mapped (completion->priv->popup_window))
9189 matches = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->filter_model), NULL);
9191 if (completion->priv->actions)
9192 actions = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->actions), NULL);
9194 if (keyval_is_cursor_move (event->keyval))
9196 GtkTreePath *path = NULL;
9198 if (event->keyval == GDK_KEY_Up || event->keyval == GDK_KEY_KP_Up)
9200 if (completion->priv->current_selected < 0)
9201 completion->priv->current_selected = matches + actions - 1;
9203 completion->priv->current_selected--;
9205 else if (event->keyval == GDK_KEY_Down || event->keyval == GDK_KEY_KP_Down)
9207 if (completion->priv->current_selected < matches + actions - 1)
9208 completion->priv->current_selected++;
9210 completion->priv->current_selected = -1;
9212 else if (event->keyval == GDK_KEY_Page_Up)
9214 if (completion->priv->current_selected < 0)
9215 completion->priv->current_selected = matches + actions - 1;
9216 else if (completion->priv->current_selected == 0)
9217 completion->priv->current_selected = -1;
9218 else if (completion->priv->current_selected < matches)
9220 completion->priv->current_selected -= 14;
9221 if (completion->priv->current_selected < 0)
9222 completion->priv->current_selected = 0;
9226 completion->priv->current_selected -= 14;
9227 if (completion->priv->current_selected < matches - 1)
9228 completion->priv->current_selected = matches - 1;
9231 else if (event->keyval == GDK_KEY_Page_Down)
9233 if (completion->priv->current_selected < 0)
9234 completion->priv->current_selected = 0;
9235 else if (completion->priv->current_selected < matches - 1)
9237 completion->priv->current_selected += 14;
9238 if (completion->priv->current_selected > matches - 1)
9239 completion->priv->current_selected = matches - 1;
9241 else if (completion->priv->current_selected == matches + actions - 1)
9243 completion->priv->current_selected = -1;
9247 completion->priv->current_selected += 14;
9248 if (completion->priv->current_selected > matches + actions - 1)
9249 completion->priv->current_selected = matches + actions - 1;
9253 if (completion->priv->current_selected < 0)
9255 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9256 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view)));
9258 if (completion->priv->inline_selection &&
9259 completion->priv->completion_prefix)
9261 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9262 completion->priv->completion_prefix);
9263 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9266 else if (completion->priv->current_selected < matches)
9268 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view)));
9270 path = gtk_tree_path_new_from_indices (completion->priv->current_selected, -1);
9271 gtk_tree_view_set_cursor (GTK_TREE_VIEW (completion->priv->tree_view),
9274 if (completion->priv->inline_selection)
9278 GtkTreeIter child_iter;
9279 GtkTreeModel *model = NULL;
9280 GtkTreeSelection *sel;
9283 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view));
9284 if (!gtk_tree_selection_get_selected (sel, &model, &iter))
9287 gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (model), &child_iter, &iter);
9288 model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model));
9290 if (completion->priv->completion_prefix == NULL)
9291 completion->priv->completion_prefix = g_strdup (gtk_entry_get_text (GTK_ENTRY (completion->priv->entry)));
9293 g_signal_emit_by_name (completion, "cursor-on-match", model,
9294 &child_iter, &entry_set);
9297 else if (completion->priv->current_selected - matches >= 0)
9299 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9301 path = gtk_tree_path_new_from_indices (completion->priv->current_selected - matches, -1);
9302 gtk_tree_view_set_cursor (GTK_TREE_VIEW (completion->priv->action_view),
9305 if (completion->priv->inline_selection &&
9306 completion->priv->completion_prefix)
9308 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9309 completion->priv->completion_prefix);
9310 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9314 gtk_tree_path_free (path);
9318 else if (event->keyval == GDK_KEY_Escape ||
9319 event->keyval == GDK_KEY_Left ||
9320 event->keyval == GDK_KEY_KP_Left ||
9321 event->keyval == GDK_KEY_Right ||
9322 event->keyval == GDK_KEY_KP_Right)
9324 gboolean retval = TRUE;
9326 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9327 _gtk_entry_completion_popdown (completion);
9329 if (completion->priv->current_selected < 0)
9332 goto keypress_completion_out;
9334 else if (completion->priv->inline_selection)
9336 /* Escape rejects the tentative completion */
9337 if (event->keyval == GDK_KEY_Escape)
9339 if (completion->priv->completion_prefix)
9340 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9341 completion->priv->completion_prefix);
9343 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry), "");
9346 /* Move the cursor to the end for Right/Esc, to the
9347 beginning for Left */
9348 if (event->keyval == GDK_KEY_Right ||
9349 event->keyval == GDK_KEY_KP_Right ||
9350 event->keyval == GDK_KEY_Escape)
9351 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9353 gtk_editable_set_position (GTK_EDITABLE (widget), 0);
9356 keypress_completion_out:
9357 if (completion->priv->inline_selection)
9359 g_free (completion->priv->completion_prefix);
9360 completion->priv->completion_prefix = NULL;
9365 else if (event->keyval == GDK_KEY_Tab ||
9366 event->keyval == GDK_KEY_KP_Tab ||
9367 event->keyval == GDK_KEY_ISO_Left_Tab)
9369 GtkDirectionType dir = event->keyval == GDK_KEY_ISO_Left_Tab ?
9370 GTK_DIR_TAB_BACKWARD : GTK_DIR_TAB_FORWARD;
9372 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9373 _gtk_entry_completion_popdown (completion);
9375 g_free (completion->priv->completion_prefix);
9376 completion->priv->completion_prefix = NULL;
9378 gtk_widget_child_focus (gtk_widget_get_toplevel (widget), dir);
9382 else if (event->keyval == GDK_KEY_ISO_Enter ||
9383 event->keyval == GDK_KEY_KP_Enter ||
9384 event->keyval == GDK_KEY_Return)
9387 GtkTreeModel *model = NULL;
9388 GtkTreeSelection *sel;
9389 gboolean retval = TRUE;
9391 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9392 _gtk_entry_completion_popdown (completion);
9394 if (completion->priv->current_selected < matches)
9398 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view));
9399 if (gtk_tree_selection_get_selected (sel, &model, &iter))
9401 g_signal_handler_block (widget, completion->priv->changed_id);
9402 g_signal_emit_by_name (completion, "match-selected",
9403 model, &iter, &entry_set);
9404 g_signal_handler_unblock (widget, completion->priv->changed_id);
9410 gtk_tree_model_get (model, &iter,
9411 completion->priv->text_column, &str,
9414 gtk_entry_set_text (GTK_ENTRY (widget), str);
9416 /* move the cursor to the end */
9417 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9425 else if (completion->priv->current_selected - matches >= 0)
9427 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view));
9428 if (gtk_tree_selection_get_selected (sel, &model, &iter))
9432 path = gtk_tree_path_new_from_indices (completion->priv->current_selected - matches, -1);
9433 g_signal_emit_by_name (completion, "action-activated",
9434 gtk_tree_path_get_indices (path)[0]);
9435 gtk_tree_path_free (path);
9441 g_free (completion->priv->completion_prefix);
9442 completion->priv->completion_prefix = NULL;
9451 gtk_entry_completion_changed (GtkWidget *entry,
9454 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
9455 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
9458 /* (re)install completion timeout */
9459 if (completion->priv->completion_timeout)
9460 g_source_remove (completion->priv->completion_timeout);
9462 if (!gtk_entry_get_text (GTK_ENTRY (entry)))
9465 /* no need to normalize for this test */
9466 if (completion->priv->minimum_key_length > 0 &&
9467 strcmp ("", gtk_entry_get_text (GTK_ENTRY (entry))) == 0)
9469 if (gtk_widget_get_visible (completion->priv->popup_window))
9470 _gtk_entry_completion_popdown (completion);
9474 device = gtk_get_current_event_device ();
9476 if (device && device->source == GDK_SOURCE_KEYBOARD)
9477 device = gdk_device_get_associated_device (device);
9480 priv->completion_device = device;
9482 completion->priv->completion_timeout =
9483 gdk_threads_add_timeout (COMPLETION_TIMEOUT,
9484 gtk_entry_completion_timeout,
9489 check_completion_callback (GtkEntryCompletion *completion)
9491 completion->priv->check_completion_idle = NULL;
9493 gtk_entry_completion_complete (completion);
9494 gtk_entry_completion_insert_prefix (completion);
9500 clear_completion_callback (GtkEntry *entry,
9503 if (pspec->name == I_("cursor-position") ||
9504 pspec->name == I_("selection-bound"))
9506 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
9508 completion->priv->has_completion = FALSE;
9513 accept_completion_callback (GtkEntry *entry)
9515 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
9517 if (completion->priv->has_completion)
9518 gtk_editable_set_position (GTK_EDITABLE (entry),
9519 gtk_entry_buffer_get_length (get_buffer (entry)));
9525 completion_insert_text_callback (GtkEntry *entry,
9529 GtkEntryCompletion *completion)
9531 /* idle to update the selection based on the file list */
9532 if (completion->priv->check_completion_idle == NULL)
9534 completion->priv->check_completion_idle = g_idle_source_new ();
9535 g_source_set_priority (completion->priv->check_completion_idle, G_PRIORITY_HIGH);
9536 g_source_set_closure (completion->priv->check_completion_idle,
9537 g_cclosure_new_object (G_CALLBACK (check_completion_callback),
9538 G_OBJECT (completion)));
9539 g_source_attach (completion->priv->check_completion_idle, NULL);
9544 completion_changed (GtkEntryCompletion *completion,
9548 GtkEntry *entry = GTK_ENTRY (data);
9550 if (pspec->name == I_("popup-completion") ||
9551 pspec->name == I_("inline-completion"))
9553 disconnect_completion_signals (entry, completion);
9554 connect_completion_signals (entry, completion);
9559 disconnect_completion_signals (GtkEntry *entry,
9560 GtkEntryCompletion *completion)
9562 g_signal_handlers_disconnect_by_func (completion,
9563 G_CALLBACK (completion_changed), entry);
9564 if (completion->priv->changed_id > 0 &&
9565 g_signal_handler_is_connected (entry, completion->priv->changed_id))
9567 g_signal_handler_disconnect (entry, completion->priv->changed_id);
9568 completion->priv->changed_id = 0;
9570 g_signal_handlers_disconnect_by_func (entry,
9571 G_CALLBACK (gtk_entry_completion_key_press), completion);
9572 if (completion->priv->insert_text_id > 0 &&
9573 g_signal_handler_is_connected (entry, completion->priv->insert_text_id))
9575 g_signal_handler_disconnect (entry, completion->priv->insert_text_id);
9576 completion->priv->insert_text_id = 0;
9578 g_signal_handlers_disconnect_by_func (entry,
9579 G_CALLBACK (completion_insert_text_callback), completion);
9580 g_signal_handlers_disconnect_by_func (entry,
9581 G_CALLBACK (clear_completion_callback), completion);
9582 g_signal_handlers_disconnect_by_func (entry,
9583 G_CALLBACK (accept_completion_callback), completion);
9587 connect_completion_signals (GtkEntry *entry,
9588 GtkEntryCompletion *completion)
9590 if (completion->priv->popup_completion)
9592 completion->priv->changed_id =
9593 g_signal_connect (entry, "changed",
9594 G_CALLBACK (gtk_entry_completion_changed), completion);
9595 g_signal_connect (entry, "key-press-event",
9596 G_CALLBACK (gtk_entry_completion_key_press), completion);
9599 if (completion->priv->inline_completion)
9601 completion->priv->insert_text_id =
9602 g_signal_connect (entry, "insert-text",
9603 G_CALLBACK (completion_insert_text_callback), completion);
9604 g_signal_connect (entry, "notify",
9605 G_CALLBACK (clear_completion_callback), completion);
9606 g_signal_connect (entry, "activate",
9607 G_CALLBACK (accept_completion_callback), completion);
9608 g_signal_connect (entry, "focus-out-event",
9609 G_CALLBACK (accept_completion_callback), completion);
9612 g_signal_connect (completion, "notify",
9613 G_CALLBACK (completion_changed), entry);
9617 * gtk_entry_set_completion:
9618 * @entry: A #GtkEntry
9619 * @completion: (allow-none): The #GtkEntryCompletion or %NULL
9621 * Sets @completion to be the auxiliary completion object to use with @entry.
9622 * All further configuration of the completion mechanism is done on
9623 * @completion using the #GtkEntryCompletion API. Completion is disabled if
9624 * @completion is set to %NULL.
9629 gtk_entry_set_completion (GtkEntry *entry,
9630 GtkEntryCompletion *completion)
9632 GtkEntryCompletion *old;
9634 g_return_if_fail (GTK_IS_ENTRY (entry));
9635 g_return_if_fail (!completion || GTK_IS_ENTRY_COMPLETION (completion));
9637 old = gtk_entry_get_completion (entry);
9639 if (old == completion)
9644 if (old->priv->completion_timeout)
9646 g_source_remove (old->priv->completion_timeout);
9647 old->priv->completion_timeout = 0;
9650 if (gtk_widget_get_mapped (old->priv->popup_window))
9651 _gtk_entry_completion_popdown (old);
9653 disconnect_completion_signals (entry, old);
9654 old->priv->entry = NULL;
9656 g_object_unref (old);
9661 g_object_set_data (G_OBJECT (entry), I_(GTK_ENTRY_COMPLETION_KEY), NULL);
9665 /* hook into the entry */
9666 g_object_ref (completion);
9668 connect_completion_signals (entry, completion);
9669 completion->priv->entry = GTK_WIDGET (entry);
9670 g_object_set_data (G_OBJECT (entry), I_(GTK_ENTRY_COMPLETION_KEY), completion);
9674 * gtk_entry_get_completion:
9675 * @entry: A #GtkEntry
9677 * Returns the auxiliary completion object currently in use by @entry.
9679 * Return value: (transfer none): The auxiliary completion object currently
9684 GtkEntryCompletion *
9685 gtk_entry_get_completion (GtkEntry *entry)
9687 GtkEntryCompletion *completion;
9689 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
9691 completion = GTK_ENTRY_COMPLETION (g_object_get_data (G_OBJECT (entry),
9692 GTK_ENTRY_COMPLETION_KEY));
9698 * gtk_entry_set_cursor_hadjustment:
9699 * @entry: a #GtkEntry
9700 * @adjustment: an adjustment which should be adjusted when the cursor
9701 * is moved, or %NULL
9703 * Hooks up an adjustment to the cursor position in an entry, so that when
9704 * the cursor is moved, the adjustment is scrolled to show that position.
9705 * See gtk_scrolled_window_get_hadjustment() for a typical way of obtaining
9708 * The adjustment has to be in pixel units and in the same coordinate system
9714 gtk_entry_set_cursor_hadjustment (GtkEntry *entry,
9715 GtkAdjustment *adjustment)
9717 g_return_if_fail (GTK_IS_ENTRY (entry));
9719 g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
9722 g_object_ref (adjustment);
9724 g_object_set_qdata_full (G_OBJECT (entry),
9725 quark_cursor_hadjustment,
9731 * gtk_entry_get_cursor_hadjustment:
9732 * @entry: a #GtkEntry
9734 * Retrieves the horizontal cursor adjustment for the entry.
9735 * See gtk_entry_set_cursor_hadjustment().
9737 * Return value: (transfer none): the horizontal cursor adjustment, or %NULL
9738 * if none has been set.
9743 gtk_entry_get_cursor_hadjustment (GtkEntry *entry)
9745 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
9747 return g_object_get_qdata (G_OBJECT (entry), quark_cursor_hadjustment);
9751 * gtk_entry_set_progress_fraction:
9752 * @entry: a #GtkEntry
9753 * @fraction: fraction of the task that's been completed
9755 * Causes the entry's progress indicator to "fill in" the given
9756 * fraction of the bar. The fraction should be between 0.0 and 1.0,
9762 gtk_entry_set_progress_fraction (GtkEntry *entry,
9766 GtkEntryPrivate *private;
9767 gdouble old_fraction;
9768 gint x, y, width, height;
9769 gint old_x, old_y, old_width, old_height;
9771 g_return_if_fail (GTK_IS_ENTRY (entry));
9773 widget = GTK_WIDGET (entry);
9774 private = GTK_ENTRY_GET_PRIVATE (entry);
9776 if (private->progress_pulse_mode)
9779 old_fraction = private->progress_fraction;
9781 if (gtk_widget_is_drawable (widget))
9782 get_progress_area (widget, &old_x, &old_y, &old_width, &old_height);
9784 fraction = CLAMP (fraction, 0.0, 1.0);
9786 private->progress_fraction = fraction;
9787 private->progress_pulse_mode = FALSE;
9788 private->progress_pulse_current = 0.0;
9790 if (gtk_widget_is_drawable (widget))
9792 get_progress_area (widget, &x, &y, &width, &height);
9794 if ((x != old_x) || (y != old_y) || (width != old_width) || (height != old_height))
9795 gtk_widget_queue_draw (widget);
9798 if (fraction != old_fraction)
9799 g_object_notify (G_OBJECT (entry), "progress-fraction");
9803 * gtk_entry_get_progress_fraction:
9804 * @entry: a #GtkEntry
9806 * Returns the current fraction of the task that's been completed.
9807 * See gtk_entry_set_progress_fraction().
9809 * Return value: a fraction from 0.0 to 1.0
9814 gtk_entry_get_progress_fraction (GtkEntry *entry)
9816 GtkEntryPrivate *private;
9818 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
9820 private = GTK_ENTRY_GET_PRIVATE (entry);
9822 return private->progress_fraction;
9826 * gtk_entry_set_progress_pulse_step:
9827 * @entry: a #GtkEntry
9828 * @fraction: fraction between 0.0 and 1.0
9830 * Sets the fraction of total entry width to move the progress
9831 * bouncing block for each call to gtk_entry_progress_pulse().
9836 gtk_entry_set_progress_pulse_step (GtkEntry *entry,
9839 GtkEntryPrivate *private;
9841 g_return_if_fail (GTK_IS_ENTRY (entry));
9843 private = GTK_ENTRY_GET_PRIVATE (entry);
9845 fraction = CLAMP (fraction, 0.0, 1.0);
9847 if (fraction != private->progress_pulse_fraction)
9849 private->progress_pulse_fraction = fraction;
9851 gtk_widget_queue_draw (GTK_WIDGET (entry));
9853 g_object_notify (G_OBJECT (entry), "progress-pulse-step");
9858 * gtk_entry_get_progress_pulse_step:
9859 * @entry: a #GtkEntry
9861 * Retrieves the pulse step set with gtk_entry_set_progress_pulse_step().
9863 * Return value: a fraction from 0.0 to 1.0
9868 gtk_entry_get_progress_pulse_step (GtkEntry *entry)
9870 GtkEntryPrivate *private;
9872 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
9874 private = GTK_ENTRY_GET_PRIVATE (entry);
9876 return private->progress_pulse_fraction;
9880 * gtk_entry_progress_pulse:
9881 * @entry: a #GtkEntry
9883 * Indicates that some progress is made, but you don't know how much.
9884 * Causes the entry's progress indicator to enter "activity mode,"
9885 * where a block bounces back and forth. Each call to
9886 * gtk_entry_progress_pulse() causes the block to move by a little bit
9887 * (the amount of movement per pulse is determined by
9888 * gtk_entry_set_progress_pulse_step()).
9893 gtk_entry_progress_pulse (GtkEntry *entry)
9895 GtkEntryPrivate *private;
9897 g_return_if_fail (GTK_IS_ENTRY (entry));
9899 private = GTK_ENTRY_GET_PRIVATE (entry);
9901 if (private->progress_pulse_mode)
9903 if (private->progress_pulse_way_back)
9905 private->progress_pulse_current -= private->progress_pulse_fraction;
9907 if (private->progress_pulse_current < 0.0)
9909 private->progress_pulse_current = 0.0;
9910 private->progress_pulse_way_back = FALSE;
9915 private->progress_pulse_current += private->progress_pulse_fraction;
9917 if (private->progress_pulse_current > 1.0 - private->progress_pulse_fraction)
9919 private->progress_pulse_current = 1.0 - private->progress_pulse_fraction;
9920 private->progress_pulse_way_back = TRUE;
9926 private->progress_fraction = 0.0;
9927 private->progress_pulse_mode = TRUE;
9928 private->progress_pulse_way_back = FALSE;
9929 private->progress_pulse_current = 0.0;
9932 gtk_widget_queue_draw (GTK_WIDGET (entry));
9935 /* Caps Lock warning for password entries */
9938 show_capslock_feedback (GtkEntry *entry,
9941 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
9943 if (gtk_entry_get_icon_storage_type (entry, GTK_ENTRY_ICON_SECONDARY) == GTK_IMAGE_EMPTY)
9945 gtk_entry_set_icon_from_stock (entry, GTK_ENTRY_ICON_SECONDARY, GTK_STOCK_CAPS_LOCK_WARNING);
9946 gtk_entry_set_icon_activatable (entry, GTK_ENTRY_ICON_SECONDARY, FALSE);
9947 priv->caps_lock_warning_shown = TRUE;
9950 if (priv->caps_lock_warning_shown)
9951 gtk_entry_set_icon_tooltip_text (entry, GTK_ENTRY_ICON_SECONDARY, text);
9953 g_warning ("Can't show Caps Lock warning, since secondary icon is set");
9957 remove_capslock_feedback (GtkEntry *entry)
9959 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
9961 if (priv->caps_lock_warning_shown)
9963 gtk_entry_set_icon_from_stock (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
9964 priv->caps_lock_warning_shown = FALSE;
9969 keymap_state_changed (GdkKeymap *keymap,
9972 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
9975 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL && priv->caps_lock_warning)
9977 if (gdk_keymap_get_num_lock_state (keymap)
9978 && gdk_keymap_get_caps_lock_state (keymap))
9979 text = _("Caps Lock and Num Lock are on");
9980 else if (gdk_keymap_get_num_lock_state (keymap))
9981 text = _("Num Lock is on");
9982 else if (gdk_keymap_get_caps_lock_state (keymap))
9983 text = _("Caps Lock is on");
9987 show_capslock_feedback (entry, text);
9989 remove_capslock_feedback (entry);