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_set_text:
6660 * @entry: a #GtkEntry
6661 * @text: the new text
6663 * Sets the text in the widget to the given
6664 * value, replacing the current contents.
6666 * See gtk_entry_buffer_set_text().
6669 gtk_entry_set_text (GtkEntry *entry,
6673 GtkEntryCompletion *completion;
6674 GtkEntryPrivate *priv;
6676 g_return_if_fail (GTK_IS_ENTRY (entry));
6677 g_return_if_fail (text != NULL);
6678 priv = GTK_ENTRY_GET_PRIVATE (entry);
6680 /* Actually setting the text will affect the cursor and selection;
6681 * if the contents don't actually change, this will look odd to the user.
6683 if (strcmp (gtk_entry_buffer_get_text (get_buffer (entry)), text) == 0)
6686 completion = gtk_entry_get_completion (entry);
6687 if (completion && completion->priv->changed_id > 0)
6688 g_signal_handler_block (entry, completion->priv->changed_id);
6690 begin_change (entry);
6691 g_object_freeze_notify (G_OBJECT (entry));
6692 gtk_editable_delete_text (GTK_EDITABLE (entry), 0, -1);
6694 gtk_editable_insert_text (GTK_EDITABLE (entry), text, strlen (text), &tmp_pos);
6695 g_object_thaw_notify (G_OBJECT (entry));
6698 if (completion && completion->priv->changed_id > 0)
6699 g_signal_handler_unblock (entry, completion->priv->changed_id);
6703 * gtk_entry_set_visibility:
6704 * @entry: a #GtkEntry
6705 * @visible: %TRUE if the contents of the entry are displayed
6708 * Sets whether the contents of the entry are visible or not.
6709 * When visibility is set to %FALSE, characters are displayed
6710 * as the invisible char, and will also appear that way when
6711 * the text in the entry widget is copied elsewhere.
6713 * By default, GTK+ picks the best invisible character available
6714 * in the current font, but it can be changed with
6715 * gtk_entry_set_invisible_char().
6718 gtk_entry_set_visibility (GtkEntry *entry,
6721 g_return_if_fail (GTK_IS_ENTRY (entry));
6723 visible = visible != FALSE;
6725 if (entry->visible != visible)
6727 entry->visible = visible;
6729 g_object_notify (G_OBJECT (entry), "visibility");
6730 gtk_entry_recompute (entry);
6735 * gtk_entry_get_visibility:
6736 * @entry: a #GtkEntry
6738 * Retrieves whether the text in @entry is visible. See
6739 * gtk_entry_set_visibility().
6741 * Return value: %TRUE if the text is currently visible
6744 gtk_entry_get_visibility (GtkEntry *entry)
6746 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
6748 return entry->visible;
6752 * gtk_entry_set_invisible_char:
6753 * @entry: a #GtkEntry
6754 * @ch: a Unicode character
6756 * Sets the character to use in place of the actual text when
6757 * gtk_entry_set_visibility() has been called to set text visibility
6758 * to %FALSE. i.e. this is the character used in "password mode" to
6759 * show the user how many characters have been typed. By default, GTK+
6760 * picks the best invisible char available in the current font. If you
6761 * set the invisible char to 0, then the user will get no feedback
6762 * at all; there will be no text on the screen as they type.
6765 gtk_entry_set_invisible_char (GtkEntry *entry,
6768 GtkEntryPrivate *priv;
6770 g_return_if_fail (GTK_IS_ENTRY (entry));
6772 priv = GTK_ENTRY_GET_PRIVATE (entry);
6774 if (!priv->invisible_char_set)
6776 priv->invisible_char_set = TRUE;
6777 g_object_notify (G_OBJECT (entry), "invisible-char-set");
6780 if (ch == entry->invisible_char)
6783 entry->invisible_char = ch;
6784 g_object_notify (G_OBJECT (entry), "invisible-char");
6785 gtk_entry_recompute (entry);
6789 * gtk_entry_get_invisible_char:
6790 * @entry: a #GtkEntry
6792 * Retrieves the character displayed in place of the real characters
6793 * for entries with visibility set to false. See gtk_entry_set_invisible_char().
6795 * Return value: the current invisible char, or 0, if the entry does not
6796 * show invisible text at all.
6799 gtk_entry_get_invisible_char (GtkEntry *entry)
6801 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
6803 return entry->invisible_char;
6807 * gtk_entry_unset_invisible_char:
6808 * @entry: a #GtkEntry
6810 * Unsets the invisible char previously set with
6811 * gtk_entry_set_invisible_char(). So that the
6812 * default invisible char is used again.
6817 gtk_entry_unset_invisible_char (GtkEntry *entry)
6819 GtkEntryPrivate *priv;
6822 g_return_if_fail (GTK_IS_ENTRY (entry));
6824 priv = GTK_ENTRY_GET_PRIVATE (entry);
6826 if (!priv->invisible_char_set)
6829 priv->invisible_char_set = FALSE;
6830 ch = find_invisible_char (GTK_WIDGET (entry));
6832 if (entry->invisible_char != ch)
6834 entry->invisible_char = ch;
6835 g_object_notify (G_OBJECT (entry), "invisible-char");
6838 g_object_notify (G_OBJECT (entry), "invisible-char-set");
6839 gtk_entry_recompute (entry);
6843 * gtk_entry_set_overwrite_mode:
6844 * @entry: a #GtkEntry
6845 * @overwrite: new value
6847 * Sets whether the text is overwritten when typing in the #GtkEntry.
6852 gtk_entry_set_overwrite_mode (GtkEntry *entry,
6855 g_return_if_fail (GTK_IS_ENTRY (entry));
6857 if (entry->overwrite_mode == overwrite)
6860 gtk_entry_toggle_overwrite (entry);
6862 g_object_notify (G_OBJECT (entry), "overwrite-mode");
6866 * gtk_entry_get_overwrite_mode:
6867 * @entry: a #GtkEntry
6869 * Gets the value set by gtk_entry_set_overwrite_mode().
6871 * Return value: whether the text is overwritten when typing.
6876 gtk_entry_get_overwrite_mode (GtkEntry *entry)
6878 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
6880 return entry->overwrite_mode;
6884 * gtk_entry_get_text:
6885 * @entry: a #GtkEntry
6887 * Retrieves the contents of the entry widget.
6888 * See also gtk_editable_get_chars().
6890 * This is equivalent to:
6892 * <informalexample><programlisting>
6893 * gtk_entry_buffer_get_text (gtk_entry_get_buffer (entry));
6894 * </programlisting></informalexample>
6896 * Return value: a pointer to the contents of the widget as a
6897 * string. This string points to internally allocated
6898 * storage in the widget and must not be freed, modified or
6901 G_CONST_RETURN gchar*
6902 gtk_entry_get_text (GtkEntry *entry)
6904 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
6905 return gtk_entry_buffer_get_text (get_buffer (entry));
6909 * gtk_entry_set_max_length:
6910 * @entry: a #GtkEntry
6911 * @max: the maximum length of the entry, or 0 for no maximum.
6912 * (other than the maximum length of entries.) The value passed in will
6913 * be clamped to the range 0-65536.
6915 * Sets the maximum allowed length of the contents of the widget. If
6916 * the current contents are longer than the given length, then they
6917 * will be truncated to fit.
6919 * This is equivalent to:
6921 * <informalexample><programlisting>
6922 * gtk_entry_buffer_set_max_length (gtk_entry_get_buffer (entry), max);
6923 * </programlisting></informalexample>
6926 gtk_entry_set_max_length (GtkEntry *entry,
6929 g_return_if_fail (GTK_IS_ENTRY (entry));
6930 gtk_entry_buffer_set_max_length (get_buffer (entry), max);
6934 * gtk_entry_get_max_length:
6935 * @entry: a #GtkEntry
6937 * Retrieves the maximum allowed length of the text in
6938 * @entry. See gtk_entry_set_max_length().
6940 * This is equivalent to:
6942 * <informalexample><programlisting>
6943 * gtk_entry_buffer_get_max_length (gtk_entry_get_buffer (entry));
6944 * </programlisting></informalexample>
6946 * Return value: the maximum allowed number of characters
6947 * in #GtkEntry, or 0 if there is no maximum.
6950 gtk_entry_get_max_length (GtkEntry *entry)
6952 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
6953 return gtk_entry_buffer_get_max_length (get_buffer (entry));
6957 * gtk_entry_get_text_length:
6958 * @entry: a #GtkEntry
6960 * Retrieves the current length of the text in
6963 * This is equivalent to:
6965 * <informalexample><programlisting>
6966 * gtk_entry_buffer_get_length (gtk_entry_get_buffer (entry));
6967 * </programlisting></informalexample>
6969 * Return value: the current number of characters
6970 * in #GtkEntry, or 0 if there are none.
6975 gtk_entry_get_text_length (GtkEntry *entry)
6977 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
6978 return gtk_entry_buffer_get_length (get_buffer (entry));
6982 * gtk_entry_set_activates_default:
6983 * @entry: a #GtkEntry
6984 * @setting: %TRUE to activate window's default widget on Enter keypress
6986 * If @setting is %TRUE, pressing Enter in the @entry will activate the default
6987 * widget for the window containing the entry. This usually means that
6988 * the dialog box containing the entry will be closed, since the default
6989 * widget is usually one of the dialog buttons.
6991 * (For experts: if @setting is %TRUE, the entry calls
6992 * gtk_window_activate_default() on the window containing the entry, in
6993 * the default handler for the #GtkWidget::activate signal.)
6996 gtk_entry_set_activates_default (GtkEntry *entry,
6999 g_return_if_fail (GTK_IS_ENTRY (entry));
7000 setting = setting != FALSE;
7002 if (setting != entry->activates_default)
7004 entry->activates_default = setting;
7005 g_object_notify (G_OBJECT (entry), "activates-default");
7010 * gtk_entry_get_activates_default:
7011 * @entry: a #GtkEntry
7013 * Retrieves the value set by gtk_entry_set_activates_default().
7015 * Return value: %TRUE if the entry will activate the default widget
7018 gtk_entry_get_activates_default (GtkEntry *entry)
7020 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7022 return entry->activates_default;
7026 * gtk_entry_set_width_chars:
7027 * @entry: a #GtkEntry
7028 * @n_chars: width in chars
7030 * Changes the size request of the entry to be about the right size
7031 * for @n_chars characters. Note that it changes the size
7032 * <emphasis>request</emphasis>, the size can still be affected by
7033 * how you pack the widget into containers. If @n_chars is -1, the
7034 * size reverts to the default entry size.
7037 gtk_entry_set_width_chars (GtkEntry *entry,
7040 g_return_if_fail (GTK_IS_ENTRY (entry));
7042 if (entry->width_chars != n_chars)
7044 entry->width_chars = n_chars;
7045 g_object_notify (G_OBJECT (entry), "width-chars");
7046 gtk_widget_queue_resize (GTK_WIDGET (entry));
7051 * gtk_entry_get_width_chars:
7052 * @entry: a #GtkEntry
7054 * Gets the value set by gtk_entry_set_width_chars().
7056 * Return value: number of chars to request space for, or negative if unset
7059 gtk_entry_get_width_chars (GtkEntry *entry)
7061 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7063 return entry->width_chars;
7067 * gtk_entry_set_has_frame:
7068 * @entry: a #GtkEntry
7069 * @setting: new value
7071 * Sets whether the entry has a beveled frame around it.
7074 gtk_entry_set_has_frame (GtkEntry *entry,
7077 g_return_if_fail (GTK_IS_ENTRY (entry));
7079 setting = (setting != FALSE);
7081 if (entry->has_frame == setting)
7084 gtk_widget_queue_resize (GTK_WIDGET (entry));
7085 entry->has_frame = setting;
7086 g_object_notify (G_OBJECT (entry), "has-frame");
7090 * gtk_entry_get_has_frame:
7091 * @entry: a #GtkEntry
7093 * Gets the value set by gtk_entry_set_has_frame().
7095 * Return value: whether the entry has a beveled frame
7098 gtk_entry_get_has_frame (GtkEntry *entry)
7100 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7102 return entry->has_frame;
7106 * gtk_entry_set_inner_border:
7107 * @entry: a #GtkEntry
7108 * @border: (allow-none): a #GtkBorder, or %NULL
7110 * Sets %entry's inner-border property to %border, or clears it if %NULL
7111 * is passed. The inner-border is the area around the entry's text, but
7114 * If set, this property overrides the inner-border style property.
7115 * Overriding the style-provided border is useful when you want to do
7116 * in-place editing of some text in a canvas or list widget, where
7117 * pixel-exact positioning of the entry is important.
7122 gtk_entry_set_inner_border (GtkEntry *entry,
7123 const GtkBorder *border)
7125 g_return_if_fail (GTK_IS_ENTRY (entry));
7127 gtk_widget_queue_resize (GTK_WIDGET (entry));
7130 g_object_set_qdata_full (G_OBJECT (entry), quark_inner_border,
7131 gtk_border_copy (border),
7132 (GDestroyNotify) gtk_border_free);
7134 g_object_set_qdata (G_OBJECT (entry), quark_inner_border, NULL);
7136 g_object_notify (G_OBJECT (entry), "inner-border");
7140 * gtk_entry_get_inner_border:
7141 * @entry: a #GtkEntry
7143 * This function returns the entry's #GtkEntry:inner-border property. See
7144 * gtk_entry_set_inner_border() for more information.
7146 * Return value: (transfer none): the entry's #GtkBorder, or %NULL if none was set.
7150 G_CONST_RETURN GtkBorder *
7151 gtk_entry_get_inner_border (GtkEntry *entry)
7153 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7155 return g_object_get_qdata (G_OBJECT (entry), quark_inner_border);
7159 * gtk_entry_get_layout:
7160 * @entry: a #GtkEntry
7162 * Gets the #PangoLayout used to display the entry.
7163 * The layout is useful to e.g. convert text positions to
7164 * pixel positions, in combination with gtk_entry_get_layout_offsets().
7165 * The returned layout is owned by the entry and must not be
7166 * modified or freed by the caller.
7168 * Keep in mind that the layout text may contain a preedit string, so
7169 * gtk_entry_layout_index_to_text_index() and
7170 * gtk_entry_text_index_to_layout_index() are needed to convert byte
7171 * indices in the layout to byte indices in the entry contents.
7173 * Return value: (transfer none): the #PangoLayout for this entry
7176 gtk_entry_get_layout (GtkEntry *entry)
7178 PangoLayout *layout;
7180 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7182 layout = gtk_entry_ensure_layout (entry, TRUE);
7189 * gtk_entry_layout_index_to_text_index:
7190 * @entry: a #GtkEntry
7191 * @layout_index: byte index into the entry layout text
7193 * Converts from a position in the entry contents (returned
7194 * by gtk_entry_get_text()) to a position in the
7195 * entry's #PangoLayout (returned by gtk_entry_get_layout(),
7196 * with text retrieved via pango_layout_get_text()).
7198 * Return value: byte index into the entry contents
7201 gtk_entry_layout_index_to_text_index (GtkEntry *entry,
7204 PangoLayout *layout;
7208 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7210 layout = gtk_entry_ensure_layout (entry, TRUE);
7211 text = pango_layout_get_text (layout);
7212 cursor_index = g_utf8_offset_to_pointer (text, entry->current_pos) - text;
7214 if (layout_index >= cursor_index && entry->preedit_length)
7216 if (layout_index >= cursor_index + entry->preedit_length)
7217 layout_index -= entry->preedit_length;
7219 layout_index = cursor_index;
7222 return layout_index;
7226 * gtk_entry_text_index_to_layout_index:
7227 * @entry: a #GtkEntry
7228 * @text_index: byte index into the entry contents
7230 * Converts from a position in the entry's #PangoLayout (returned by
7231 * gtk_entry_get_layout()) to a position in the entry contents
7232 * (returned by gtk_entry_get_text()).
7234 * Return value: byte index into the entry layout text
7237 gtk_entry_text_index_to_layout_index (GtkEntry *entry,
7240 PangoLayout *layout;
7243 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7245 layout = gtk_entry_ensure_layout (entry, TRUE);
7246 text = pango_layout_get_text (layout);
7247 cursor_index = g_utf8_offset_to_pointer (text, entry->current_pos) - text;
7249 if (text_index > cursor_index)
7250 text_index += entry->preedit_length;
7256 * gtk_entry_get_layout_offsets:
7257 * @entry: a #GtkEntry
7258 * @x: (allow-none): location to store X offset of layout, or %NULL
7259 * @y: (allow-none): location to store Y offset of layout, or %NULL
7262 * Obtains the position of the #PangoLayout used to render text
7263 * in the entry, in widget coordinates. Useful if you want to line
7264 * up the text in an entry with some other text, e.g. when using the
7265 * entry to implement editable cells in a sheet widget.
7267 * Also useful to convert mouse events into coordinates inside the
7268 * #PangoLayout, e.g. to take some action if some part of the entry text
7271 * Note that as the user scrolls around in the entry the offsets will
7272 * change; you'll need to connect to the "notify::scroll-offset"
7273 * signal to track this. Remember when using the #PangoLayout
7274 * functions you need to convert to and from pixels using
7275 * PANGO_PIXELS() or #PANGO_SCALE.
7277 * Keep in mind that the layout text may contain a preedit string, so
7278 * gtk_entry_layout_index_to_text_index() and
7279 * gtk_entry_text_index_to_layout_index() are needed to convert byte
7280 * indices in the layout to byte indices in the entry contents.
7283 gtk_entry_get_layout_offsets (GtkEntry *entry,
7287 gint text_area_x, text_area_y;
7289 g_return_if_fail (GTK_IS_ENTRY (entry));
7291 /* this gets coords relative to text area */
7292 get_layout_position (entry, x, y);
7294 /* convert to widget coords */
7295 gtk_entry_get_text_area_size (entry, &text_area_x, &text_area_y, NULL, NULL);
7306 * gtk_entry_set_alignment:
7307 * @entry: a #GtkEntry
7308 * @xalign: The horizontal alignment, from 0 (left) to 1 (right).
7309 * Reversed for RTL layouts
7311 * Sets the alignment for the contents of the entry. This controls
7312 * the horizontal positioning of the contents when the displayed
7313 * text is shorter than the width of the entry.
7318 gtk_entry_set_alignment (GtkEntry *entry, gfloat xalign)
7320 GtkEntryPrivate *priv;
7322 g_return_if_fail (GTK_IS_ENTRY (entry));
7324 priv = GTK_ENTRY_GET_PRIVATE (entry);
7328 else if (xalign > 1.0)
7331 if (xalign != priv->xalign)
7333 priv->xalign = xalign;
7335 gtk_entry_recompute (entry);
7337 g_object_notify (G_OBJECT (entry), "xalign");
7342 * gtk_entry_get_alignment:
7343 * @entry: a #GtkEntry
7345 * Gets the value set by gtk_entry_set_alignment().
7347 * Return value: the alignment
7352 gtk_entry_get_alignment (GtkEntry *entry)
7354 GtkEntryPrivate *priv;
7356 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
7358 priv = GTK_ENTRY_GET_PRIVATE (entry);
7360 return priv->xalign;
7364 * gtk_entry_set_icon_from_pixbuf:
7365 * @entry: a #GtkEntry
7366 * @icon_pos: Icon position
7367 * @pixbuf: (allow-none): A #GdkPixbuf, or %NULL
7369 * Sets the icon shown in the specified position using a pixbuf.
7371 * If @pixbuf is %NULL, no icon will be shown in the specified position.
7376 gtk_entry_set_icon_from_pixbuf (GtkEntry *entry,
7377 GtkEntryIconPosition icon_pos,
7380 GtkEntryPrivate *priv;
7381 EntryIconInfo *icon_info;
7383 g_return_if_fail (GTK_IS_ENTRY (entry));
7384 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7386 priv = GTK_ENTRY_GET_PRIVATE (entry);
7388 if ((icon_info = priv->icons[icon_pos]) == NULL)
7389 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7391 g_object_freeze_notify (G_OBJECT (entry));
7394 g_object_ref (pixbuf);
7396 gtk_entry_clear (entry, icon_pos);
7400 icon_info->storage_type = GTK_IMAGE_PIXBUF;
7401 icon_info->pixbuf = pixbuf;
7403 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7405 g_object_notify (G_OBJECT (entry), "primary-icon-pixbuf");
7406 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7410 g_object_notify (G_OBJECT (entry), "secondary-icon-pixbuf");
7411 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7414 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7415 gdk_window_show_unraised (icon_info->window);
7418 gtk_entry_ensure_pixbuf (entry, icon_pos);
7420 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7421 gtk_widget_queue_resize (GTK_WIDGET (entry));
7423 g_object_thaw_notify (G_OBJECT (entry));
7427 * gtk_entry_set_icon_from_stock:
7428 * @entry: A #GtkEntry
7429 * @icon_pos: Icon position
7430 * @stock_id: (allow-none): The name of the stock item, or %NULL
7432 * Sets the icon shown in the entry at the specified position from
7435 * If @stock_id is %NULL, no icon will be shown in the specified position.
7440 gtk_entry_set_icon_from_stock (GtkEntry *entry,
7441 GtkEntryIconPosition icon_pos,
7442 const gchar *stock_id)
7444 GtkEntryPrivate *priv;
7445 EntryIconInfo *icon_info;
7448 g_return_if_fail (GTK_IS_ENTRY (entry));
7449 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7451 priv = GTK_ENTRY_GET_PRIVATE (entry);
7453 if ((icon_info = priv->icons[icon_pos]) == NULL)
7454 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7456 g_object_freeze_notify (G_OBJECT (entry));
7458 gtk_widget_ensure_style (GTK_WIDGET (entry));
7460 /* need to dup before clearing */
7461 new_id = g_strdup (stock_id);
7463 gtk_entry_clear (entry, icon_pos);
7467 icon_info->storage_type = GTK_IMAGE_STOCK;
7468 icon_info->stock_id = new_id;
7470 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7472 g_object_notify (G_OBJECT (entry), "primary-icon-stock");
7473 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7477 g_object_notify (G_OBJECT (entry), "secondary-icon-stock");
7478 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7481 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7482 gdk_window_show_unraised (icon_info->window);
7485 gtk_entry_ensure_pixbuf (entry, icon_pos);
7487 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7488 gtk_widget_queue_resize (GTK_WIDGET (entry));
7490 g_object_thaw_notify (G_OBJECT (entry));
7494 * gtk_entry_set_icon_from_icon_name:
7495 * @entry: A #GtkEntry
7496 * @icon_pos: The position at which to set the icon
7497 * @icon_name: (allow-none): An icon name, or %NULL
7499 * Sets the icon shown in the entry at the specified position
7500 * from the current icon theme.
7502 * If the icon name isn't known, a "broken image" icon will be displayed
7505 * If @icon_name is %NULL, no icon will be shown in the specified position.
7510 gtk_entry_set_icon_from_icon_name (GtkEntry *entry,
7511 GtkEntryIconPosition icon_pos,
7512 const gchar *icon_name)
7514 GtkEntryPrivate *priv;
7515 EntryIconInfo *icon_info;
7518 g_return_if_fail (GTK_IS_ENTRY (entry));
7519 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7521 priv = GTK_ENTRY_GET_PRIVATE (entry);
7523 if ((icon_info = priv->icons[icon_pos]) == NULL)
7524 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7526 g_object_freeze_notify (G_OBJECT (entry));
7528 gtk_widget_ensure_style (GTK_WIDGET (entry));
7530 /* need to dup before clearing */
7531 new_name = g_strdup (icon_name);
7533 gtk_entry_clear (entry, icon_pos);
7535 if (new_name != NULL)
7537 icon_info->storage_type = GTK_IMAGE_ICON_NAME;
7538 icon_info->icon_name = new_name;
7540 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7542 g_object_notify (G_OBJECT (entry), "primary-icon-name");
7543 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7547 g_object_notify (G_OBJECT (entry), "secondary-icon-name");
7548 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7551 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7552 gdk_window_show_unraised (icon_info->window);
7555 gtk_entry_ensure_pixbuf (entry, icon_pos);
7557 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7558 gtk_widget_queue_resize (GTK_WIDGET (entry));
7560 g_object_thaw_notify (G_OBJECT (entry));
7564 * gtk_entry_set_icon_from_gicon:
7565 * @entry: A #GtkEntry
7566 * @icon_pos: The position at which to set the icon
7567 * @icon: (allow-none): The icon to set, or %NULL
7569 * Sets the icon shown in the entry at the specified position
7570 * from the current icon theme.
7571 * If the icon isn't known, a "broken image" icon will be displayed
7574 * If @icon is %NULL, no icon will be shown in the specified position.
7579 gtk_entry_set_icon_from_gicon (GtkEntry *entry,
7580 GtkEntryIconPosition icon_pos,
7583 GtkEntryPrivate *priv;
7584 EntryIconInfo *icon_info;
7586 g_return_if_fail (GTK_IS_ENTRY (entry));
7587 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7589 priv = GTK_ENTRY_GET_PRIVATE (entry);
7591 if ((icon_info = priv->icons[icon_pos]) == NULL)
7592 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7594 g_object_freeze_notify (G_OBJECT (entry));
7596 /* need to ref before clearing */
7598 g_object_ref (icon);
7600 gtk_entry_clear (entry, icon_pos);
7604 icon_info->storage_type = GTK_IMAGE_GICON;
7605 icon_info->gicon = icon;
7607 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7609 g_object_notify (G_OBJECT (entry), "primary-icon-gicon");
7610 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7614 g_object_notify (G_OBJECT (entry), "secondary-icon-gicon");
7615 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7618 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7619 gdk_window_show_unraised (icon_info->window);
7622 gtk_entry_ensure_pixbuf (entry, icon_pos);
7624 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7625 gtk_widget_queue_resize (GTK_WIDGET (entry));
7627 g_object_thaw_notify (G_OBJECT (entry));
7631 * gtk_entry_set_icon_activatable:
7632 * @entry: A #GtkEntry
7633 * @icon_pos: Icon position
7634 * @activatable: %TRUE if the icon should be activatable
7636 * Sets whether the icon is activatable.
7641 gtk_entry_set_icon_activatable (GtkEntry *entry,
7642 GtkEntryIconPosition icon_pos,
7643 gboolean activatable)
7645 GtkEntryPrivate *priv;
7646 EntryIconInfo *icon_info;
7648 g_return_if_fail (GTK_IS_ENTRY (entry));
7649 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7651 priv = GTK_ENTRY_GET_PRIVATE (entry);
7653 if ((icon_info = priv->icons[icon_pos]) == NULL)
7654 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7656 activatable = activatable != FALSE;
7658 if (icon_info->nonactivatable != !activatable)
7660 icon_info->nonactivatable = !activatable;
7662 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
7663 update_cursors (GTK_WIDGET (entry));
7665 g_object_notify (G_OBJECT (entry),
7666 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-activatable" : "secondary-icon-activatable");
7671 * gtk_entry_get_icon_activatable:
7672 * @entry: a #GtkEntry
7673 * @icon_pos: Icon position
7675 * Returns whether the icon is activatable.
7677 * Returns: %TRUE if the icon is activatable.
7682 gtk_entry_get_icon_activatable (GtkEntry *entry,
7683 GtkEntryIconPosition icon_pos)
7685 GtkEntryPrivate *priv;
7686 EntryIconInfo *icon_info;
7688 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7689 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), FALSE);
7691 priv = GTK_ENTRY_GET_PRIVATE (entry);
7692 icon_info = priv->icons[icon_pos];
7694 return (icon_info != NULL && !icon_info->nonactivatable);
7698 * gtk_entry_get_icon_pixbuf:
7699 * @entry: A #GtkEntry
7700 * @icon_pos: Icon position
7702 * Retrieves the image used for the icon.
7704 * Unlike the other methods of setting and getting icon data, this
7705 * method will work regardless of whether the icon was set using a
7706 * #GdkPixbuf, a #GIcon, a stock item, or an icon name.
7708 * Returns: (transfer none): A #GdkPixbuf, or %NULL if no icon is
7709 * set for this position.
7714 gtk_entry_get_icon_pixbuf (GtkEntry *entry,
7715 GtkEntryIconPosition icon_pos)
7717 GtkEntryPrivate *priv;
7718 EntryIconInfo *icon_info;
7720 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7721 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7723 priv = GTK_ENTRY_GET_PRIVATE (entry);
7724 icon_info = priv->icons[icon_pos];
7729 gtk_entry_ensure_pixbuf (entry, icon_pos);
7731 return icon_info->pixbuf;
7735 * gtk_entry_get_icon_gicon:
7736 * @entry: A #GtkEntry
7737 * @icon_pos: Icon position
7739 * Retrieves the #GIcon used for the icon, or %NULL if there is
7740 * no icon or if the icon was set by some other method (e.g., by
7741 * stock, pixbuf, or icon name).
7743 * Returns: (transfer none): A #GIcon, or %NULL if no icon is set
7744 * or if the icon is not a #GIcon
7749 gtk_entry_get_icon_gicon (GtkEntry *entry,
7750 GtkEntryIconPosition icon_pos)
7752 GtkEntryPrivate *priv;
7753 EntryIconInfo *icon_info;
7755 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7756 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7758 priv = GTK_ENTRY_GET_PRIVATE (entry);
7759 icon_info = priv->icons[icon_pos];
7764 return icon_info->storage_type == GTK_IMAGE_GICON ? icon_info->gicon : NULL;
7768 * gtk_entry_get_icon_stock:
7769 * @entry: A #GtkEntry
7770 * @icon_pos: Icon position
7772 * Retrieves the stock id used for the icon, or %NULL if there is
7773 * no icon or if the icon was set by some other method (e.g., by
7774 * pixbuf, icon name or gicon).
7776 * Returns: A stock id, or %NULL if no icon is set or if the icon
7777 * wasn't set from a stock id
7782 gtk_entry_get_icon_stock (GtkEntry *entry,
7783 GtkEntryIconPosition icon_pos)
7785 GtkEntryPrivate *priv;
7786 EntryIconInfo *icon_info;
7788 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7789 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7791 priv = GTK_ENTRY_GET_PRIVATE (entry);
7792 icon_info = priv->icons[icon_pos];
7797 return icon_info->storage_type == GTK_IMAGE_STOCK ? icon_info->stock_id : NULL;
7801 * gtk_entry_get_icon_name:
7802 * @entry: A #GtkEntry
7803 * @icon_pos: Icon position
7805 * Retrieves the icon name used for the icon, or %NULL if there is
7806 * no icon or if the icon was set by some other method (e.g., by
7807 * pixbuf, stock or gicon).
7809 * Returns: An icon name, or %NULL if no icon is set or if the icon
7810 * wasn't set from an icon name
7815 gtk_entry_get_icon_name (GtkEntry *entry,
7816 GtkEntryIconPosition icon_pos)
7818 GtkEntryPrivate *priv;
7819 EntryIconInfo *icon_info;
7821 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7822 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7824 priv = GTK_ENTRY_GET_PRIVATE (entry);
7825 icon_info = priv->icons[icon_pos];
7830 return icon_info->storage_type == GTK_IMAGE_ICON_NAME ? icon_info->icon_name : NULL;
7834 * gtk_entry_set_icon_sensitive:
7835 * @entry: A #GtkEntry
7836 * @icon_pos: Icon position
7837 * @sensitive: Specifies whether the icon should appear
7838 * sensitive or insensitive
7840 * Sets the sensitivity for the specified icon.
7845 gtk_entry_set_icon_sensitive (GtkEntry *entry,
7846 GtkEntryIconPosition icon_pos,
7849 GtkEntryPrivate *priv;
7850 EntryIconInfo *icon_info;
7852 g_return_if_fail (GTK_IS_ENTRY (entry));
7853 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7855 priv = GTK_ENTRY_GET_PRIVATE (entry);
7857 if ((icon_info = priv->icons[icon_pos]) == NULL)
7858 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7860 if (icon_info->insensitive != !sensitive)
7862 icon_info->insensitive = !sensitive;
7864 icon_info->pressed = FALSE;
7865 icon_info->prelight = FALSE;
7867 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
7868 update_cursors (GTK_WIDGET (entry));
7870 gtk_widget_queue_draw (GTK_WIDGET (entry));
7872 g_object_notify (G_OBJECT (entry),
7873 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-sensitive" : "secondary-icon-sensitive");
7878 * gtk_entry_get_icon_sensitive:
7879 * @entry: a #GtkEntry
7880 * @icon_pos: Icon position
7882 * Returns whether the icon appears sensitive or insensitive.
7884 * Returns: %TRUE if the icon is sensitive.
7889 gtk_entry_get_icon_sensitive (GtkEntry *entry,
7890 GtkEntryIconPosition icon_pos)
7892 GtkEntryPrivate *priv;
7893 EntryIconInfo *icon_info;
7895 g_return_val_if_fail (GTK_IS_ENTRY (entry), TRUE);
7896 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), TRUE);
7898 priv = GTK_ENTRY_GET_PRIVATE (entry);
7899 icon_info = priv->icons[icon_pos];
7901 return (!icon_info || !icon_info->insensitive);
7906 * gtk_entry_get_icon_storage_type:
7907 * @entry: a #GtkEntry
7908 * @icon_pos: Icon position
7910 * Gets the type of representation being used by the icon
7911 * to store image data. If the icon has no image data,
7912 * the return value will be %GTK_IMAGE_EMPTY.
7914 * Return value: image representation being used
7919 gtk_entry_get_icon_storage_type (GtkEntry *entry,
7920 GtkEntryIconPosition icon_pos)
7922 GtkEntryPrivate *priv;
7923 EntryIconInfo *icon_info;
7925 g_return_val_if_fail (GTK_IS_ENTRY (entry), GTK_IMAGE_EMPTY);
7926 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), GTK_IMAGE_EMPTY);
7928 priv = GTK_ENTRY_GET_PRIVATE (entry);
7929 icon_info = priv->icons[icon_pos];
7932 return GTK_IMAGE_EMPTY;
7934 return icon_info->storage_type;
7938 * gtk_entry_get_icon_at_pos:
7939 * @entry: a #GtkEntry
7940 * @x: the x coordinate of the position to find
7941 * @y: the y coordinate of the position to find
7943 * Finds the icon at the given position and return its index.
7944 * If @x, @y doesn't lie inside an icon, -1 is returned.
7945 * This function is intended for use in a #GtkWidget::query-tooltip
7948 * Returns: the index of the icon at the given position, or -1
7953 gtk_entry_get_icon_at_pos (GtkEntry *entry,
7957 GtkAllocation primary;
7958 GtkAllocation secondary;
7959 gint frame_x, frame_y;
7961 g_return_val_if_fail (GTK_IS_ENTRY (entry), -1);
7963 get_frame_size (entry, &frame_x, &frame_y, NULL, NULL);
7967 get_icon_allocations (entry, &primary, &secondary);
7969 if (primary.x <= x && x < primary.x + primary.width &&
7970 primary.y <= y && y < primary.y + primary.height)
7971 return GTK_ENTRY_ICON_PRIMARY;
7973 if (secondary.x <= x && x < secondary.x + secondary.width &&
7974 secondary.y <= y && y < secondary.y + secondary.height)
7975 return GTK_ENTRY_ICON_SECONDARY;
7981 * gtk_entry_set_icon_drag_source:
7982 * @entry: a #GtkIconEntry
7983 * @icon_pos: icon position
7984 * @target_list: the targets (data formats) in which the data can be provided
7985 * @actions: a bitmask of the allowed drag actions
7987 * Sets up the icon at the given position so that GTK+ will start a drag
7988 * operation when the user clicks and drags the icon.
7990 * To handle the drag operation, you need to connect to the usual
7991 * #GtkWidget::drag-data-get (or possibly #GtkWidget::drag-data-delete)
7992 * signal, and use gtk_entry_get_current_icon_drag_source() in
7993 * your signal handler to find out if the drag was started from
7996 * By default, GTK+ uses the icon as the drag icon. You can use the
7997 * #GtkWidget::drag-begin signal to set a different icon. Note that you
7998 * have to use g_signal_connect_after() to ensure that your signal handler
7999 * gets executed after the default handler.
8004 gtk_entry_set_icon_drag_source (GtkEntry *entry,
8005 GtkEntryIconPosition icon_pos,
8006 GtkTargetList *target_list,
8007 GdkDragAction actions)
8009 GtkEntryPrivate *priv;
8010 EntryIconInfo *icon_info;
8012 g_return_if_fail (GTK_IS_ENTRY (entry));
8013 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8015 priv = GTK_ENTRY_GET_PRIVATE (entry);
8017 if ((icon_info = priv->icons[icon_pos]) == NULL)
8018 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8020 if (icon_info->target_list)
8021 gtk_target_list_unref (icon_info->target_list);
8022 icon_info->target_list = target_list;
8023 if (icon_info->target_list)
8024 gtk_target_list_ref (icon_info->target_list);
8026 icon_info->actions = actions;
8030 * gtk_entry_get_current_icon_drag_source:
8031 * @entry: a #GtkIconEntry
8033 * Returns the index of the icon which is the source of the current
8034 * DND operation, or -1.
8036 * This function is meant to be used in a #GtkWidget::drag-data-get
8039 * Returns: index of the icon which is the source of the current
8040 * DND operation, or -1.
8045 gtk_entry_get_current_icon_drag_source (GtkEntry *entry)
8047 GtkEntryPrivate *priv;
8048 EntryIconInfo *icon_info = NULL;
8051 g_return_val_if_fail (GTK_IS_ENTRY (entry), -1);
8053 priv = GTK_ENTRY_GET_PRIVATE (entry);
8055 for (i = 0; i < MAX_ICONS; i++)
8057 if ((icon_info = priv->icons[i]))
8059 if (icon_info->in_drag)
8068 ensure_has_tooltip (GtkEntry *entry)
8070 GtkEntryPrivate *priv;
8071 EntryIconInfo *icon_info;
8073 gboolean has_tooltip = FALSE;
8075 priv = GTK_ENTRY_GET_PRIVATE (entry);
8077 for (i = 0; i < MAX_ICONS; i++)
8079 if ((icon_info = priv->icons[i]) != NULL)
8081 if (icon_info->tooltip != NULL)
8089 gtk_widget_set_has_tooltip (GTK_WIDGET (entry), has_tooltip);
8093 * gtk_entry_get_icon_tooltip_text:
8094 * @entry: a #GtkEntry
8095 * @icon_pos: the icon position
8097 * Gets the contents of the tooltip on the icon at the specified
8098 * position in @entry.
8100 * Returns: the tooltip text, or %NULL. Free the returned string
8101 * with g_free() when done.
8106 gtk_entry_get_icon_tooltip_text (GtkEntry *entry,
8107 GtkEntryIconPosition icon_pos)
8109 GtkEntryPrivate *priv;
8110 EntryIconInfo *icon_info;
8113 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8114 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8116 priv = GTK_ENTRY_GET_PRIVATE (entry);
8117 icon_info = priv->icons[icon_pos];
8122 if (icon_info->tooltip &&
8123 !pango_parse_markup (icon_info->tooltip, -1, 0, NULL, &text, NULL, NULL))
8124 g_assert (NULL == text); /* text should still be NULL in case of markup errors */
8130 * gtk_entry_set_icon_tooltip_text:
8131 * @entry: a #GtkEntry
8132 * @icon_pos: the icon position
8133 * @tooltip: (allow-none): the contents of the tooltip for the icon, or %NULL
8135 * Sets @tooltip as the contents of the tooltip for the icon
8136 * at the specified position.
8138 * Use %NULL for @tooltip to remove an existing tooltip.
8140 * See also gtk_widget_set_tooltip_text() and
8141 * gtk_entry_set_icon_tooltip_markup().
8146 gtk_entry_set_icon_tooltip_text (GtkEntry *entry,
8147 GtkEntryIconPosition icon_pos,
8148 const gchar *tooltip)
8150 GtkEntryPrivate *priv;
8151 EntryIconInfo *icon_info;
8153 g_return_if_fail (GTK_IS_ENTRY (entry));
8154 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8156 priv = GTK_ENTRY_GET_PRIVATE (entry);
8158 if (!(icon_info = priv->icons[icon_pos]))
8159 icon_info = priv->icons[icon_pos];
8161 if (icon_info->tooltip)
8162 g_free (icon_info->tooltip);
8164 /* Treat an empty string as a NULL string,
8165 * because an empty string would be useless for a tooltip:
8167 if (tooltip && tooltip[0] == '\0')
8170 icon_info->tooltip = tooltip ? g_markup_escape_text (tooltip, -1) : NULL;
8172 ensure_has_tooltip (entry);
8176 * gtk_entry_get_icon_tooltip_markup:
8177 * @entry: a #GtkEntry
8178 * @icon_pos: the icon position
8180 * Gets the contents of the tooltip on the icon at the specified
8181 * position in @entry.
8183 * Returns: the tooltip text, or %NULL. Free the returned string
8184 * with g_free() when done.
8189 gtk_entry_get_icon_tooltip_markup (GtkEntry *entry,
8190 GtkEntryIconPosition icon_pos)
8192 GtkEntryPrivate *priv;
8193 EntryIconInfo *icon_info;
8195 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8196 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8198 priv = GTK_ENTRY_GET_PRIVATE (entry);
8199 icon_info = priv->icons[icon_pos];
8204 return g_strdup (icon_info->tooltip);
8208 * gtk_entry_set_icon_tooltip_markup:
8209 * @entry: a #GtkEntry
8210 * @icon_pos: the icon position
8211 * @tooltip: (allow-none): the contents of the tooltip for the icon, or %NULL
8213 * Sets @tooltip as the contents of the tooltip for the icon at
8214 * the specified position. @tooltip is assumed to be marked up with
8215 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
8217 * Use %NULL for @tooltip to remove an existing tooltip.
8219 * See also gtk_widget_set_tooltip_markup() and
8220 * gtk_enty_set_icon_tooltip_text().
8225 gtk_entry_set_icon_tooltip_markup (GtkEntry *entry,
8226 GtkEntryIconPosition icon_pos,
8227 const gchar *tooltip)
8229 GtkEntryPrivate *priv;
8230 EntryIconInfo *icon_info;
8232 g_return_if_fail (GTK_IS_ENTRY (entry));
8233 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8235 priv = GTK_ENTRY_GET_PRIVATE (entry);
8237 if (!(icon_info = priv->icons[icon_pos]))
8238 icon_info = priv->icons[icon_pos];
8240 if (icon_info->tooltip)
8241 g_free (icon_info->tooltip);
8243 /* Treat an empty string as a NULL string,
8244 * because an empty string would be useless for a tooltip:
8246 if (tooltip && tooltip[0] == '\0')
8249 icon_info->tooltip = g_strdup (tooltip);
8251 ensure_has_tooltip (entry);
8255 gtk_entry_query_tooltip (GtkWidget *widget,
8258 gboolean keyboard_tip,
8259 GtkTooltip *tooltip)
8262 GtkEntryPrivate *priv;
8263 EntryIconInfo *icon_info;
8266 entry = GTK_ENTRY (widget);
8267 priv = GTK_ENTRY_GET_PRIVATE (entry);
8271 icon_pos = gtk_entry_get_icon_at_pos (entry, x, y);
8274 if ((icon_info = priv->icons[icon_pos]) != NULL)
8276 if (icon_info->tooltip)
8278 gtk_tooltip_set_markup (tooltip, icon_info->tooltip);
8287 return GTK_WIDGET_CLASS (gtk_entry_parent_class)->query_tooltip (widget,
8294 /* Quick hack of a popup menu
8297 activate_cb (GtkWidget *menuitem,
8300 const gchar *signal = g_object_get_data (G_OBJECT (menuitem), "gtk-signal");
8301 g_signal_emit_by_name (entry, signal);
8306 gtk_entry_mnemonic_activate (GtkWidget *widget,
8307 gboolean group_cycling)
8309 gtk_widget_grab_focus (widget);
8314 append_action_signal (GtkEntry *entry,
8316 const gchar *stock_id,
8317 const gchar *signal,
8320 GtkWidget *menuitem = gtk_image_menu_item_new_from_stock (stock_id, NULL);
8322 g_object_set_data (G_OBJECT (menuitem), I_("gtk-signal"), (char *)signal);
8323 g_signal_connect (menuitem, "activate",
8324 G_CALLBACK (activate_cb), entry);
8326 gtk_widget_set_sensitive (menuitem, sensitive);
8328 gtk_widget_show (menuitem);
8329 gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
8333 popup_menu_detach (GtkWidget *attach_widget,
8336 GTK_ENTRY (attach_widget)->popup_menu = NULL;
8340 popup_position_func (GtkMenu *menu,
8346 GtkEntry *entry = GTK_ENTRY (user_data);
8347 GtkWidget *widget = GTK_WIDGET (entry);
8349 GtkRequisition menu_req;
8350 GdkRectangle monitor;
8351 GtkBorder inner_border;
8352 gint monitor_num, strong_x, height;
8354 g_return_if_fail (gtk_widget_get_realized (widget));
8356 gdk_window_get_origin (entry->text_area, x, y);
8358 screen = gtk_widget_get_screen (widget);
8359 monitor_num = gdk_screen_get_monitor_at_window (screen, entry->text_area);
8360 if (monitor_num < 0)
8362 gtk_menu_set_monitor (menu, monitor_num);
8364 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
8365 gtk_widget_get_preferred_size (entry->popup_menu,
8367 height = gdk_window_get_height (entry->text_area);
8368 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
8369 _gtk_entry_effective_inner_border (entry, &inner_border);
8371 *x += inner_border.left + strong_x - entry->scroll_offset;
8372 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
8373 *x -= menu_req.width;
8375 if ((*y + height + menu_req.height) <= monitor.y + monitor.height)
8377 else if ((*y - menu_req.height) >= monitor.y)
8378 *y -= menu_req.height;
8379 else if (monitor.y + monitor.height - (*y + height) > *y)
8382 *y -= menu_req.height;
8388 unichar_chosen_func (const char *text,
8391 GtkEntry *entry = GTK_ENTRY (data);
8393 if (entry->editable)
8394 gtk_entry_enter_text (entry, text);
8405 popup_targets_received (GtkClipboard *clipboard,
8406 GtkSelectionData *data,
8409 PopupInfo *info = user_data;
8410 GtkEntry *entry = info->entry;
8412 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
8415 gboolean clipboard_contains_text;
8416 GtkWidget *menuitem;
8418 gboolean show_input_method_menu;
8419 gboolean show_unicode_menu;
8421 clipboard_contains_text = gtk_selection_data_targets_include_text (data);
8422 if (entry->popup_menu)
8423 gtk_widget_destroy (entry->popup_menu);
8425 entry->popup_menu = gtk_menu_new ();
8427 gtk_menu_attach_to_widget (GTK_MENU (entry->popup_menu),
8431 mode = gtk_entry_get_display_mode (entry);
8432 append_action_signal (entry, entry->popup_menu, GTK_STOCK_CUT, "cut-clipboard",
8433 entry->editable && mode == DISPLAY_NORMAL &&
8434 entry->current_pos != entry->selection_bound);
8436 append_action_signal (entry, entry->popup_menu, GTK_STOCK_COPY, "copy-clipboard",
8437 mode == DISPLAY_NORMAL &&
8438 entry->current_pos != entry->selection_bound);
8440 append_action_signal (entry, entry->popup_menu, GTK_STOCK_PASTE, "paste-clipboard",
8441 entry->editable && clipboard_contains_text);
8443 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_DELETE, NULL);
8444 gtk_widget_set_sensitive (menuitem, entry->editable && entry->current_pos != entry->selection_bound);
8445 g_signal_connect_swapped (menuitem, "activate",
8446 G_CALLBACK (gtk_entry_delete_cb), entry);
8447 gtk_widget_show (menuitem);
8448 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8450 menuitem = gtk_separator_menu_item_new ();
8451 gtk_widget_show (menuitem);
8452 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8454 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_SELECT_ALL, NULL);
8455 g_signal_connect_swapped (menuitem, "activate",
8456 G_CALLBACK (gtk_entry_select_all), entry);
8457 gtk_widget_show (menuitem);
8458 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8460 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
8461 "gtk-show-input-method-menu", &show_input_method_menu,
8462 "gtk-show-unicode-menu", &show_unicode_menu,
8465 if (show_input_method_menu || show_unicode_menu)
8467 menuitem = gtk_separator_menu_item_new ();
8468 gtk_widget_show (menuitem);
8469 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8472 if (show_input_method_menu)
8474 menuitem = gtk_menu_item_new_with_mnemonic (_("Input _Methods"));
8475 gtk_widget_set_sensitive (menuitem, entry->editable);
8476 gtk_widget_show (menuitem);
8477 submenu = gtk_menu_new ();
8478 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
8480 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8482 gtk_im_multicontext_append_menuitems (GTK_IM_MULTICONTEXT (entry->im_context),
8483 GTK_MENU_SHELL (submenu));
8486 if (show_unicode_menu)
8488 menuitem = gtk_menu_item_new_with_mnemonic (_("_Insert Unicode Control Character"));
8489 gtk_widget_set_sensitive (menuitem, entry->editable);
8490 gtk_widget_show (menuitem);
8492 submenu = gtk_menu_new ();
8493 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
8494 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8496 _gtk_text_util_append_special_char_menuitems (GTK_MENU_SHELL (submenu),
8497 unichar_chosen_func,
8501 g_signal_emit (entry,
8502 signals[POPULATE_POPUP],
8508 gtk_menu_popup (GTK_MENU (entry->popup_menu), NULL, NULL,
8510 info->button, info->time);
8513 gtk_menu_popup (GTK_MENU (entry->popup_menu), NULL, NULL,
8514 popup_position_func, entry,
8515 info->button, info->time);
8516 gtk_menu_shell_select_first (GTK_MENU_SHELL (entry->popup_menu), FALSE);
8520 g_object_unref (entry);
8521 g_slice_free (PopupInfo, info);
8525 gtk_entry_do_popup (GtkEntry *entry,
8526 GdkEventButton *event)
8528 PopupInfo *info = g_slice_new (PopupInfo);
8530 /* In order to know what entries we should make sensitive, we
8531 * ask for the current targets of the clipboard, and when
8532 * we get them, then we actually pop up the menu.
8534 info->entry = g_object_ref (entry);
8538 info->button = event->button;
8539 info->time = event->time;
8544 info->time = gtk_get_current_event_time ();
8547 gtk_clipboard_request_contents (gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_CLIPBOARD),
8548 gdk_atom_intern_static_string ("TARGETS"),
8549 popup_targets_received,
8554 gtk_entry_popup_menu (GtkWidget *widget)
8556 gtk_entry_do_popup (GTK_ENTRY (widget), NULL);
8561 gtk_entry_drag_begin (GtkWidget *widget,
8562 GdkDragContext *context)
8564 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
8567 for (i = 0; i < MAX_ICONS; i++)
8569 EntryIconInfo *icon_info = priv->icons[i];
8571 if (icon_info != NULL)
8573 if (icon_info->in_drag)
8575 switch (icon_info->storage_type)
8577 case GTK_IMAGE_STOCK:
8578 gtk_drag_set_icon_stock (context, icon_info->stock_id, -2, -2);
8581 case GTK_IMAGE_ICON_NAME:
8582 gtk_drag_set_icon_name (context, icon_info->icon_name, -2, -2);
8585 /* FIXME: No GIcon support for dnd icons */
8586 case GTK_IMAGE_GICON:
8587 case GTK_IMAGE_PIXBUF:
8588 gtk_drag_set_icon_pixbuf (context, icon_info->pixbuf, -2, -2);
8591 g_assert_not_reached ();
8599 gtk_entry_drag_end (GtkWidget *widget,
8600 GdkDragContext *context)
8602 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
8605 for (i = 0; i < MAX_ICONS; i++)
8607 EntryIconInfo *icon_info = priv->icons[i];
8609 if (icon_info != NULL)
8610 icon_info->in_drag = 0;
8615 gtk_entry_drag_leave (GtkWidget *widget,
8616 GdkDragContext *context,
8619 GtkEntry *entry = GTK_ENTRY (widget);
8621 entry->dnd_position = -1;
8622 gtk_widget_queue_draw (widget);
8626 gtk_entry_drag_drop (GtkWidget *widget,
8627 GdkDragContext *context,
8632 GtkEntry *entry = GTK_ENTRY (widget);
8633 GdkAtom target = GDK_NONE;
8635 if (entry->editable)
8636 target = gtk_drag_dest_find_target (widget, context, NULL);
8638 if (target != GDK_NONE)
8639 gtk_drag_get_data (widget, context, target, time);
8641 gtk_drag_finish (context, FALSE, FALSE, time);
8647 gtk_entry_drag_motion (GtkWidget *widget,
8648 GdkDragContext *context,
8653 GtkEntry *entry = GTK_ENTRY (widget);
8655 GtkWidget *source_widget;
8656 GdkDragAction suggested_action;
8657 gint new_position, old_position;
8660 style = gtk_widget_get_style (widget);
8661 x -= style->xthickness;
8662 y -= style->ythickness;
8664 old_position = entry->dnd_position;
8665 new_position = gtk_entry_find_position (entry, x + entry->scroll_offset);
8667 if (entry->editable &&
8668 gtk_drag_dest_find_target (widget, context, NULL) != GDK_NONE)
8670 source_widget = gtk_drag_get_source_widget (context);
8671 suggested_action = context->suggested_action;
8673 if (!gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &sel1, &sel2) ||
8674 new_position < sel1 || new_position > sel2)
8676 if (source_widget == widget)
8678 /* Default to MOVE, unless the user has
8679 * pressed ctrl or alt to affect available actions
8681 if ((context->actions & GDK_ACTION_MOVE) != 0)
8682 suggested_action = GDK_ACTION_MOVE;
8685 entry->dnd_position = new_position;
8689 if (source_widget == widget)
8690 suggested_action = 0; /* Can't drop in selection where drag started */
8692 entry->dnd_position = -1;
8697 /* Entry not editable, or no text */
8698 suggested_action = 0;
8699 entry->dnd_position = -1;
8702 gdk_drag_status (context, suggested_action, time);
8704 if (entry->dnd_position != old_position)
8705 gtk_widget_queue_draw (widget);
8711 gtk_entry_drag_data_received (GtkWidget *widget,
8712 GdkDragContext *context,
8715 GtkSelectionData *selection_data,
8719 GtkEntry *entry = GTK_ENTRY (widget);
8720 GtkEditable *editable = GTK_EDITABLE (widget);
8724 str = (gchar *) gtk_selection_data_get_text (selection_data);
8726 style = gtk_widget_get_style (widget);
8727 x -= style->xthickness;
8728 y -= style->ythickness;
8730 if (str && entry->editable)
8736 if (entry->truncate_multiline)
8737 length = truncate_multiline (str);
8739 new_position = gtk_entry_find_position (entry, x + entry->scroll_offset);
8741 if (!gtk_editable_get_selection_bounds (editable, &sel1, &sel2) ||
8742 new_position < sel1 || new_position > sel2)
8744 gtk_editable_insert_text (editable, str, length, &new_position);
8748 /* Replacing selection */
8749 begin_change (entry);
8750 g_object_freeze_notify (G_OBJECT (entry));
8751 gtk_editable_delete_text (editable, sel1, sel2);
8752 gtk_editable_insert_text (editable, str, length, &sel1);
8753 g_object_thaw_notify (G_OBJECT (entry));
8757 gtk_drag_finish (context, TRUE, context->action == GDK_ACTION_MOVE, time);
8761 /* Drag and drop didn't happen! */
8762 gtk_drag_finish (context, FALSE, FALSE, time);
8769 gtk_entry_drag_data_get (GtkWidget *widget,
8770 GdkDragContext *context,
8771 GtkSelectionData *selection_data,
8775 gint sel_start, sel_end;
8778 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
8779 GtkEditable *editable = GTK_EDITABLE (widget);
8781 /* If there is an icon drag going on, exit early. */
8782 for (i = 0; i < MAX_ICONS; i++)
8784 EntryIconInfo *icon_info = priv->icons[i];
8786 if (icon_info != NULL)
8788 if (icon_info->in_drag)
8793 if (gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end))
8795 gchar *str = gtk_entry_get_display_text (GTK_ENTRY (widget), sel_start, sel_end);
8797 gtk_selection_data_set_text (selection_data, str, -1);
8805 gtk_entry_drag_data_delete (GtkWidget *widget,
8806 GdkDragContext *context)
8808 gint sel_start, sel_end;
8811 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
8812 GtkEditable *editable = GTK_EDITABLE (widget);
8814 /* If there is an icon drag going on, exit early. */
8815 for (i = 0; i < MAX_ICONS; i++)
8817 EntryIconInfo *icon_info = priv->icons[i];
8819 if (icon_info != NULL)
8821 if (icon_info->in_drag)
8826 if (GTK_ENTRY (widget)->editable &&
8827 gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end))
8828 gtk_editable_delete_text (editable, sel_start, sel_end);
8831 /* We display the cursor when
8833 * - the selection is empty, AND
8834 * - the widget has focus
8837 #define CURSOR_ON_MULTIPLIER 2
8838 #define CURSOR_OFF_MULTIPLIER 1
8839 #define CURSOR_PEND_MULTIPLIER 3
8840 #define CURSOR_DIVIDER 3
8843 cursor_blinks (GtkEntry *entry)
8845 if (gtk_widget_has_focus (GTK_WIDGET (entry)) &&
8847 entry->selection_bound == entry->current_pos)
8849 GtkSettings *settings;
8852 settings = gtk_widget_get_settings (GTK_WIDGET (entry));
8853 g_object_get (settings, "gtk-cursor-blink", &blink, NULL);
8862 get_cursor_time (GtkEntry *entry)
8864 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (entry));
8867 g_object_get (settings, "gtk-cursor-blink-time", &time, NULL);
8873 get_cursor_blink_timeout (GtkEntry *entry)
8875 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (entry));
8878 g_object_get (settings, "gtk-cursor-blink-timeout", &timeout, NULL);
8884 show_cursor (GtkEntry *entry)
8888 if (!entry->cursor_visible)
8890 entry->cursor_visible = TRUE;
8892 widget = GTK_WIDGET (entry);
8893 if (gtk_widget_has_focus (widget) && entry->selection_bound == entry->current_pos)
8894 gtk_widget_queue_draw (widget);
8899 hide_cursor (GtkEntry *entry)
8903 if (entry->cursor_visible)
8905 entry->cursor_visible = FALSE;
8907 widget = GTK_WIDGET (entry);
8908 if (gtk_widget_has_focus (widget) && entry->selection_bound == entry->current_pos)
8909 gtk_widget_queue_draw (widget);
8917 blink_cb (gpointer data)
8920 GtkEntryPrivate *priv;
8923 entry = GTK_ENTRY (data);
8924 priv = GTK_ENTRY_GET_PRIVATE (entry);
8926 if (!gtk_widget_has_focus (GTK_WIDGET (entry)))
8928 g_warning ("GtkEntry - did not receive focus-out-event. If you\n"
8929 "connect a handler to this signal, it must return\n"
8930 "FALSE so the entry gets the event as well");
8932 gtk_entry_check_cursor_blink (entry);
8937 g_assert (entry->selection_bound == entry->current_pos);
8939 blink_timeout = get_cursor_blink_timeout (entry);
8940 if (priv->blink_time > 1000 * blink_timeout &&
8941 blink_timeout < G_MAXINT/1000)
8943 /* we've blinked enough without the user doing anything, stop blinking */
8944 show_cursor (entry);
8945 entry->blink_timeout = 0;
8947 else if (entry->cursor_visible)
8949 hide_cursor (entry);
8950 entry->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_OFF_MULTIPLIER / CURSOR_DIVIDER,
8956 show_cursor (entry);
8957 priv->blink_time += get_cursor_time (entry);
8958 entry->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
8963 /* Remove ourselves */
8968 gtk_entry_check_cursor_blink (GtkEntry *entry)
8970 GtkEntryPrivate *priv;
8972 priv = GTK_ENTRY_GET_PRIVATE (entry);
8974 if (cursor_blinks (entry))
8976 if (!entry->blink_timeout)
8978 show_cursor (entry);
8979 entry->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
8986 if (entry->blink_timeout)
8988 g_source_remove (entry->blink_timeout);
8989 entry->blink_timeout = 0;
8992 entry->cursor_visible = TRUE;
8998 gtk_entry_pend_cursor_blink (GtkEntry *entry)
9000 if (cursor_blinks (entry))
9002 if (entry->blink_timeout != 0)
9003 g_source_remove (entry->blink_timeout);
9005 entry->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_PEND_MULTIPLIER / CURSOR_DIVIDER,
9008 show_cursor (entry);
9013 gtk_entry_reset_blink_time (GtkEntry *entry)
9015 GtkEntryPrivate *priv;
9017 priv = GTK_ENTRY_GET_PRIVATE (entry);
9019 priv->blink_time = 0;
9025 gtk_entry_completion_timeout (gpointer data)
9027 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (data);
9028 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (completion->priv->entry);
9030 completion->priv->completion_timeout = 0;
9032 if (completion->priv->filter_model &&
9033 g_utf8_strlen (gtk_entry_get_text (GTK_ENTRY (completion->priv->entry)), -1)
9034 >= completion->priv->minimum_key_length)
9038 GtkTreeSelection *s;
9039 gboolean popup_single;
9041 gtk_entry_completion_complete (completion);
9042 matches = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->filter_model), NULL);
9044 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9046 s = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view));
9048 gtk_tree_selection_unselect_all (s);
9050 actions = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->actions), NULL);
9052 g_object_get (completion, "popup-single-match", &popup_single, NULL);
9053 if ((matches > (popup_single ? 0: 1)) || actions > 0)
9055 if (gtk_widget_get_visible (completion->priv->popup_window))
9056 _gtk_entry_completion_resize_popup (completion);
9058 _gtk_entry_completion_popup (completion, priv->completion_device);
9061 _gtk_entry_completion_popdown (completion);
9063 else if (gtk_widget_get_visible (completion->priv->popup_window))
9064 _gtk_entry_completion_popdown (completion);
9069 static inline gboolean
9070 keyval_is_cursor_move (guint keyval)
9072 if (keyval == GDK_KEY_Up || keyval == GDK_KEY_KP_Up)
9075 if (keyval == GDK_KEY_Down || keyval == GDK_KEY_KP_Down)
9078 if (keyval == GDK_KEY_Page_Up)
9081 if (keyval == GDK_KEY_Page_Down)
9088 gtk_entry_completion_key_press (GtkWidget *widget,
9092 gint matches, actions = 0;
9093 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
9095 if (!gtk_widget_get_mapped (completion->priv->popup_window))
9098 matches = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->filter_model), NULL);
9100 if (completion->priv->actions)
9101 actions = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->actions), NULL);
9103 if (keyval_is_cursor_move (event->keyval))
9105 GtkTreePath *path = NULL;
9107 if (event->keyval == GDK_KEY_Up || event->keyval == GDK_KEY_KP_Up)
9109 if (completion->priv->current_selected < 0)
9110 completion->priv->current_selected = matches + actions - 1;
9112 completion->priv->current_selected--;
9114 else if (event->keyval == GDK_KEY_Down || event->keyval == GDK_KEY_KP_Down)
9116 if (completion->priv->current_selected < matches + actions - 1)
9117 completion->priv->current_selected++;
9119 completion->priv->current_selected = -1;
9121 else if (event->keyval == GDK_KEY_Page_Up)
9123 if (completion->priv->current_selected < 0)
9124 completion->priv->current_selected = matches + actions - 1;
9125 else if (completion->priv->current_selected == 0)
9126 completion->priv->current_selected = -1;
9127 else if (completion->priv->current_selected < matches)
9129 completion->priv->current_selected -= 14;
9130 if (completion->priv->current_selected < 0)
9131 completion->priv->current_selected = 0;
9135 completion->priv->current_selected -= 14;
9136 if (completion->priv->current_selected < matches - 1)
9137 completion->priv->current_selected = matches - 1;
9140 else if (event->keyval == GDK_KEY_Page_Down)
9142 if (completion->priv->current_selected < 0)
9143 completion->priv->current_selected = 0;
9144 else if (completion->priv->current_selected < matches - 1)
9146 completion->priv->current_selected += 14;
9147 if (completion->priv->current_selected > matches - 1)
9148 completion->priv->current_selected = matches - 1;
9150 else if (completion->priv->current_selected == matches + actions - 1)
9152 completion->priv->current_selected = -1;
9156 completion->priv->current_selected += 14;
9157 if (completion->priv->current_selected > matches + actions - 1)
9158 completion->priv->current_selected = matches + actions - 1;
9162 if (completion->priv->current_selected < 0)
9164 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9165 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view)));
9167 if (completion->priv->inline_selection &&
9168 completion->priv->completion_prefix)
9170 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9171 completion->priv->completion_prefix);
9172 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9175 else if (completion->priv->current_selected < matches)
9177 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view)));
9179 path = gtk_tree_path_new_from_indices (completion->priv->current_selected, -1);
9180 gtk_tree_view_set_cursor (GTK_TREE_VIEW (completion->priv->tree_view),
9183 if (completion->priv->inline_selection)
9187 GtkTreeIter child_iter;
9188 GtkTreeModel *model = NULL;
9189 GtkTreeSelection *sel;
9192 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view));
9193 if (!gtk_tree_selection_get_selected (sel, &model, &iter))
9196 gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (model), &child_iter, &iter);
9197 model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model));
9199 if (completion->priv->completion_prefix == NULL)
9200 completion->priv->completion_prefix = g_strdup (gtk_entry_get_text (GTK_ENTRY (completion->priv->entry)));
9202 g_signal_emit_by_name (completion, "cursor-on-match", model,
9203 &child_iter, &entry_set);
9206 else if (completion->priv->current_selected - matches >= 0)
9208 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9210 path = gtk_tree_path_new_from_indices (completion->priv->current_selected - matches, -1);
9211 gtk_tree_view_set_cursor (GTK_TREE_VIEW (completion->priv->action_view),
9214 if (completion->priv->inline_selection &&
9215 completion->priv->completion_prefix)
9217 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9218 completion->priv->completion_prefix);
9219 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9223 gtk_tree_path_free (path);
9227 else if (event->keyval == GDK_KEY_Escape ||
9228 event->keyval == GDK_KEY_Left ||
9229 event->keyval == GDK_KEY_KP_Left ||
9230 event->keyval == GDK_KEY_Right ||
9231 event->keyval == GDK_KEY_KP_Right)
9233 gboolean retval = TRUE;
9235 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9236 _gtk_entry_completion_popdown (completion);
9238 if (completion->priv->current_selected < 0)
9241 goto keypress_completion_out;
9243 else if (completion->priv->inline_selection)
9245 /* Escape rejects the tentative completion */
9246 if (event->keyval == GDK_KEY_Escape)
9248 if (completion->priv->completion_prefix)
9249 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9250 completion->priv->completion_prefix);
9252 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry), "");
9255 /* Move the cursor to the end for Right/Esc, to the
9256 beginning for Left */
9257 if (event->keyval == GDK_KEY_Right ||
9258 event->keyval == GDK_KEY_KP_Right ||
9259 event->keyval == GDK_KEY_Escape)
9260 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9262 gtk_editable_set_position (GTK_EDITABLE (widget), 0);
9265 keypress_completion_out:
9266 if (completion->priv->inline_selection)
9268 g_free (completion->priv->completion_prefix);
9269 completion->priv->completion_prefix = NULL;
9274 else if (event->keyval == GDK_KEY_Tab ||
9275 event->keyval == GDK_KEY_KP_Tab ||
9276 event->keyval == GDK_KEY_ISO_Left_Tab)
9278 GtkDirectionType dir = event->keyval == GDK_KEY_ISO_Left_Tab ?
9279 GTK_DIR_TAB_BACKWARD : GTK_DIR_TAB_FORWARD;
9281 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9282 _gtk_entry_completion_popdown (completion);
9284 g_free (completion->priv->completion_prefix);
9285 completion->priv->completion_prefix = NULL;
9287 gtk_widget_child_focus (gtk_widget_get_toplevel (widget), dir);
9291 else if (event->keyval == GDK_KEY_ISO_Enter ||
9292 event->keyval == GDK_KEY_KP_Enter ||
9293 event->keyval == GDK_KEY_Return)
9296 GtkTreeModel *model = NULL;
9297 GtkTreeSelection *sel;
9298 gboolean retval = TRUE;
9300 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9301 _gtk_entry_completion_popdown (completion);
9303 if (completion->priv->current_selected < matches)
9307 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view));
9308 if (gtk_tree_selection_get_selected (sel, &model, &iter))
9310 g_signal_handler_block (widget, completion->priv->changed_id);
9311 g_signal_emit_by_name (completion, "match-selected",
9312 model, &iter, &entry_set);
9313 g_signal_handler_unblock (widget, completion->priv->changed_id);
9319 gtk_tree_model_get (model, &iter,
9320 completion->priv->text_column, &str,
9323 gtk_entry_set_text (GTK_ENTRY (widget), str);
9325 /* move the cursor to the end */
9326 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9334 else if (completion->priv->current_selected - matches >= 0)
9336 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view));
9337 if (gtk_tree_selection_get_selected (sel, &model, &iter))
9341 path = gtk_tree_path_new_from_indices (completion->priv->current_selected - matches, -1);
9342 g_signal_emit_by_name (completion, "action-activated",
9343 gtk_tree_path_get_indices (path)[0]);
9344 gtk_tree_path_free (path);
9350 g_free (completion->priv->completion_prefix);
9351 completion->priv->completion_prefix = NULL;
9360 gtk_entry_completion_changed (GtkWidget *entry,
9363 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
9364 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
9367 /* (re)install completion timeout */
9368 if (completion->priv->completion_timeout)
9369 g_source_remove (completion->priv->completion_timeout);
9371 if (!gtk_entry_get_text (GTK_ENTRY (entry)))
9374 /* no need to normalize for this test */
9375 if (completion->priv->minimum_key_length > 0 &&
9376 strcmp ("", gtk_entry_get_text (GTK_ENTRY (entry))) == 0)
9378 if (gtk_widget_get_visible (completion->priv->popup_window))
9379 _gtk_entry_completion_popdown (completion);
9383 device = gtk_get_current_event_device ();
9385 if (device && device->source == GDK_SOURCE_KEYBOARD)
9386 device = gdk_device_get_associated_device (device);
9389 priv->completion_device = device;
9391 completion->priv->completion_timeout =
9392 gdk_threads_add_timeout (COMPLETION_TIMEOUT,
9393 gtk_entry_completion_timeout,
9398 check_completion_callback (GtkEntryCompletion *completion)
9400 completion->priv->check_completion_idle = NULL;
9402 gtk_entry_completion_complete (completion);
9403 gtk_entry_completion_insert_prefix (completion);
9409 clear_completion_callback (GtkEntry *entry,
9412 if (pspec->name == I_("cursor-position") ||
9413 pspec->name == I_("selection-bound"))
9415 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
9417 completion->priv->has_completion = FALSE;
9422 accept_completion_callback (GtkEntry *entry)
9424 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
9426 if (completion->priv->has_completion)
9427 gtk_editable_set_position (GTK_EDITABLE (entry),
9428 gtk_entry_buffer_get_length (get_buffer (entry)));
9434 completion_insert_text_callback (GtkEntry *entry,
9438 GtkEntryCompletion *completion)
9440 /* idle to update the selection based on the file list */
9441 if (completion->priv->check_completion_idle == NULL)
9443 completion->priv->check_completion_idle = g_idle_source_new ();
9444 g_source_set_priority (completion->priv->check_completion_idle, G_PRIORITY_HIGH);
9445 g_source_set_closure (completion->priv->check_completion_idle,
9446 g_cclosure_new_object (G_CALLBACK (check_completion_callback),
9447 G_OBJECT (completion)));
9448 g_source_attach (completion->priv->check_completion_idle, NULL);
9453 completion_changed (GtkEntryCompletion *completion,
9457 GtkEntry *entry = GTK_ENTRY (data);
9459 if (pspec->name == I_("popup-completion") ||
9460 pspec->name == I_("inline-completion"))
9462 disconnect_completion_signals (entry, completion);
9463 connect_completion_signals (entry, completion);
9468 disconnect_completion_signals (GtkEntry *entry,
9469 GtkEntryCompletion *completion)
9471 g_signal_handlers_disconnect_by_func (completion,
9472 G_CALLBACK (completion_changed), entry);
9473 if (completion->priv->changed_id > 0 &&
9474 g_signal_handler_is_connected (entry, completion->priv->changed_id))
9476 g_signal_handler_disconnect (entry, completion->priv->changed_id);
9477 completion->priv->changed_id = 0;
9479 g_signal_handlers_disconnect_by_func (entry,
9480 G_CALLBACK (gtk_entry_completion_key_press), completion);
9481 if (completion->priv->insert_text_id > 0 &&
9482 g_signal_handler_is_connected (entry, completion->priv->insert_text_id))
9484 g_signal_handler_disconnect (entry, completion->priv->insert_text_id);
9485 completion->priv->insert_text_id = 0;
9487 g_signal_handlers_disconnect_by_func (entry,
9488 G_CALLBACK (completion_insert_text_callback), completion);
9489 g_signal_handlers_disconnect_by_func (entry,
9490 G_CALLBACK (clear_completion_callback), completion);
9491 g_signal_handlers_disconnect_by_func (entry,
9492 G_CALLBACK (accept_completion_callback), completion);
9496 connect_completion_signals (GtkEntry *entry,
9497 GtkEntryCompletion *completion)
9499 if (completion->priv->popup_completion)
9501 completion->priv->changed_id =
9502 g_signal_connect (entry, "changed",
9503 G_CALLBACK (gtk_entry_completion_changed), completion);
9504 g_signal_connect (entry, "key-press-event",
9505 G_CALLBACK (gtk_entry_completion_key_press), completion);
9508 if (completion->priv->inline_completion)
9510 completion->priv->insert_text_id =
9511 g_signal_connect (entry, "insert-text",
9512 G_CALLBACK (completion_insert_text_callback), completion);
9513 g_signal_connect (entry, "notify",
9514 G_CALLBACK (clear_completion_callback), completion);
9515 g_signal_connect (entry, "activate",
9516 G_CALLBACK (accept_completion_callback), completion);
9517 g_signal_connect (entry, "focus-out-event",
9518 G_CALLBACK (accept_completion_callback), completion);
9521 g_signal_connect (completion, "notify",
9522 G_CALLBACK (completion_changed), entry);
9526 * gtk_entry_set_completion:
9527 * @entry: A #GtkEntry
9528 * @completion: (allow-none): The #GtkEntryCompletion or %NULL
9530 * Sets @completion to be the auxiliary completion object to use with @entry.
9531 * All further configuration of the completion mechanism is done on
9532 * @completion using the #GtkEntryCompletion API. Completion is disabled if
9533 * @completion is set to %NULL.
9538 gtk_entry_set_completion (GtkEntry *entry,
9539 GtkEntryCompletion *completion)
9541 GtkEntryCompletion *old;
9543 g_return_if_fail (GTK_IS_ENTRY (entry));
9544 g_return_if_fail (!completion || GTK_IS_ENTRY_COMPLETION (completion));
9546 old = gtk_entry_get_completion (entry);
9548 if (old == completion)
9553 if (old->priv->completion_timeout)
9555 g_source_remove (old->priv->completion_timeout);
9556 old->priv->completion_timeout = 0;
9559 if (gtk_widget_get_mapped (old->priv->popup_window))
9560 _gtk_entry_completion_popdown (old);
9562 disconnect_completion_signals (entry, old);
9563 old->priv->entry = NULL;
9565 g_object_unref (old);
9570 g_object_set_data (G_OBJECT (entry), I_(GTK_ENTRY_COMPLETION_KEY), NULL);
9574 /* hook into the entry */
9575 g_object_ref (completion);
9577 connect_completion_signals (entry, completion);
9578 completion->priv->entry = GTK_WIDGET (entry);
9579 g_object_set_data (G_OBJECT (entry), I_(GTK_ENTRY_COMPLETION_KEY), completion);
9583 * gtk_entry_get_completion:
9584 * @entry: A #GtkEntry
9586 * Returns the auxiliary completion object currently in use by @entry.
9588 * Return value: (transfer none): The auxiliary completion object currently
9593 GtkEntryCompletion *
9594 gtk_entry_get_completion (GtkEntry *entry)
9596 GtkEntryCompletion *completion;
9598 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
9600 completion = GTK_ENTRY_COMPLETION (g_object_get_data (G_OBJECT (entry),
9601 GTK_ENTRY_COMPLETION_KEY));
9607 * gtk_entry_set_cursor_hadjustment:
9608 * @entry: a #GtkEntry
9609 * @adjustment: an adjustment which should be adjusted when the cursor
9610 * is moved, or %NULL
9612 * Hooks up an adjustment to the cursor position in an entry, so that when
9613 * the cursor is moved, the adjustment is scrolled to show that position.
9614 * See gtk_scrolled_window_get_hadjustment() for a typical way of obtaining
9617 * The adjustment has to be in pixel units and in the same coordinate system
9623 gtk_entry_set_cursor_hadjustment (GtkEntry *entry,
9624 GtkAdjustment *adjustment)
9626 g_return_if_fail (GTK_IS_ENTRY (entry));
9628 g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
9631 g_object_ref (adjustment);
9633 g_object_set_qdata_full (G_OBJECT (entry),
9634 quark_cursor_hadjustment,
9640 * gtk_entry_get_cursor_hadjustment:
9641 * @entry: a #GtkEntry
9643 * Retrieves the horizontal cursor adjustment for the entry.
9644 * See gtk_entry_set_cursor_hadjustment().
9646 * Return value: (transfer none): the horizontal cursor adjustment, or %NULL
9647 * if none has been set.
9652 gtk_entry_get_cursor_hadjustment (GtkEntry *entry)
9654 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
9656 return g_object_get_qdata (G_OBJECT (entry), quark_cursor_hadjustment);
9660 * gtk_entry_set_progress_fraction:
9661 * @entry: a #GtkEntry
9662 * @fraction: fraction of the task that's been completed
9664 * Causes the entry's progress indicator to "fill in" the given
9665 * fraction of the bar. The fraction should be between 0.0 and 1.0,
9671 gtk_entry_set_progress_fraction (GtkEntry *entry,
9675 GtkEntryPrivate *private;
9676 gdouble old_fraction;
9677 gint x, y, width, height;
9678 gint old_x, old_y, old_width, old_height;
9680 g_return_if_fail (GTK_IS_ENTRY (entry));
9682 widget = GTK_WIDGET (entry);
9683 private = GTK_ENTRY_GET_PRIVATE (entry);
9685 if (private->progress_pulse_mode)
9688 old_fraction = private->progress_fraction;
9690 if (gtk_widget_is_drawable (widget))
9691 get_progress_area (widget, &old_x, &old_y, &old_width, &old_height);
9693 fraction = CLAMP (fraction, 0.0, 1.0);
9695 private->progress_fraction = fraction;
9696 private->progress_pulse_mode = FALSE;
9697 private->progress_pulse_current = 0.0;
9699 if (gtk_widget_is_drawable (widget))
9701 get_progress_area (widget, &x, &y, &width, &height);
9703 if ((x != old_x) || (y != old_y) || (width != old_width) || (height != old_height))
9704 gtk_widget_queue_draw (widget);
9707 if (fraction != old_fraction)
9708 g_object_notify (G_OBJECT (entry), "progress-fraction");
9712 * gtk_entry_get_progress_fraction:
9713 * @entry: a #GtkEntry
9715 * Returns the current fraction of the task that's been completed.
9716 * See gtk_entry_set_progress_fraction().
9718 * Return value: a fraction from 0.0 to 1.0
9723 gtk_entry_get_progress_fraction (GtkEntry *entry)
9725 GtkEntryPrivate *private;
9727 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
9729 private = GTK_ENTRY_GET_PRIVATE (entry);
9731 return private->progress_fraction;
9735 * gtk_entry_set_progress_pulse_step:
9736 * @entry: a #GtkEntry
9737 * @fraction: fraction between 0.0 and 1.0
9739 * Sets the fraction of total entry width to move the progress
9740 * bouncing block for each call to gtk_entry_progress_pulse().
9745 gtk_entry_set_progress_pulse_step (GtkEntry *entry,
9748 GtkEntryPrivate *private;
9750 g_return_if_fail (GTK_IS_ENTRY (entry));
9752 private = GTK_ENTRY_GET_PRIVATE (entry);
9754 fraction = CLAMP (fraction, 0.0, 1.0);
9756 if (fraction != private->progress_pulse_fraction)
9758 private->progress_pulse_fraction = fraction;
9760 gtk_widget_queue_draw (GTK_WIDGET (entry));
9762 g_object_notify (G_OBJECT (entry), "progress-pulse-step");
9767 * gtk_entry_get_progress_pulse_step:
9768 * @entry: a #GtkEntry
9770 * Retrieves the pulse step set with gtk_entry_set_progress_pulse_step().
9772 * Return value: a fraction from 0.0 to 1.0
9777 gtk_entry_get_progress_pulse_step (GtkEntry *entry)
9779 GtkEntryPrivate *private;
9781 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
9783 private = GTK_ENTRY_GET_PRIVATE (entry);
9785 return private->progress_pulse_fraction;
9789 * gtk_entry_progress_pulse:
9790 * @entry: a #GtkEntry
9792 * Indicates that some progress is made, but you don't know how much.
9793 * Causes the entry's progress indicator to enter "activity mode,"
9794 * where a block bounces back and forth. Each call to
9795 * gtk_entry_progress_pulse() causes the block to move by a little bit
9796 * (the amount of movement per pulse is determined by
9797 * gtk_entry_set_progress_pulse_step()).
9802 gtk_entry_progress_pulse (GtkEntry *entry)
9804 GtkEntryPrivate *private;
9806 g_return_if_fail (GTK_IS_ENTRY (entry));
9808 private = GTK_ENTRY_GET_PRIVATE (entry);
9810 if (private->progress_pulse_mode)
9812 if (private->progress_pulse_way_back)
9814 private->progress_pulse_current -= private->progress_pulse_fraction;
9816 if (private->progress_pulse_current < 0.0)
9818 private->progress_pulse_current = 0.0;
9819 private->progress_pulse_way_back = FALSE;
9824 private->progress_pulse_current += private->progress_pulse_fraction;
9826 if (private->progress_pulse_current > 1.0 - private->progress_pulse_fraction)
9828 private->progress_pulse_current = 1.0 - private->progress_pulse_fraction;
9829 private->progress_pulse_way_back = TRUE;
9835 private->progress_fraction = 0.0;
9836 private->progress_pulse_mode = TRUE;
9837 private->progress_pulse_way_back = FALSE;
9838 private->progress_pulse_current = 0.0;
9841 gtk_widget_queue_draw (GTK_WIDGET (entry));
9844 /* Caps Lock warning for password entries */
9847 show_capslock_feedback (GtkEntry *entry,
9850 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
9852 if (gtk_entry_get_icon_storage_type (entry, GTK_ENTRY_ICON_SECONDARY) == GTK_IMAGE_EMPTY)
9854 gtk_entry_set_icon_from_stock (entry, GTK_ENTRY_ICON_SECONDARY, GTK_STOCK_CAPS_LOCK_WARNING);
9855 gtk_entry_set_icon_activatable (entry, GTK_ENTRY_ICON_SECONDARY, FALSE);
9856 priv->caps_lock_warning_shown = TRUE;
9859 if (priv->caps_lock_warning_shown)
9860 gtk_entry_set_icon_tooltip_text (entry, GTK_ENTRY_ICON_SECONDARY, text);
9862 g_warning ("Can't show Caps Lock warning, since secondary icon is set");
9866 remove_capslock_feedback (GtkEntry *entry)
9868 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
9870 if (priv->caps_lock_warning_shown)
9872 gtk_entry_set_icon_from_stock (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
9873 priv->caps_lock_warning_shown = FALSE;
9878 keymap_state_changed (GdkKeymap *keymap,
9881 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
9884 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL && priv->caps_lock_warning)
9886 if (gdk_keymap_get_num_lock_state (keymap)
9887 && gdk_keymap_get_caps_lock_state (keymap))
9888 text = _("Caps Lock and Num Lock are on");
9889 else if (gdk_keymap_get_num_lock_state (keymap))
9890 text = _("Num Lock is on");
9891 else if (gdk_keymap_get_caps_lock_state (keymap))
9892 text = _("Caps Lock is on");
9896 show_capslock_feedback (entry, text);
9898 remove_capslock_feedback (entry);