1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* GTK - The GIMP Toolkit
3 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * Copyright (C) 2004-2006 Christian Hammond
5 * Copyright (C) 2008 Cody Russell
6 * Copyright (C) 2008 Red Hat, Inc.
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
25 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
26 * file for a list of people on the GTK+ Team. See the ChangeLog
27 * files for a list of changes. These files are distributed with
28 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
36 #include "gdk/gdkkeysyms.h"
37 #include "gtkalignment.h"
38 #include "gtkbindings.h"
39 #include "gtkcelleditable.h"
40 #include "gtkclipboard.h"
43 #include "gtkimagemenuitem.h"
44 #include "gtkimcontextsimple.h"
45 #include "gtkimmulticontext.h"
49 #include "gtkmarshalers.h"
51 #include "gtkmenuitem.h"
52 #include "gtkseparatormenuitem.h"
53 #include "gtkselection.h"
54 #include "gtksettings.h"
55 #include "gtkspinbutton.h"
57 #include "gtktextutil.h"
58 #include "gtkwindow.h"
59 #include "gtktreeview.h"
60 #include "gtktreeselection.h"
61 #include "gtkprivate.h"
62 #include "gtkentryprivate.h"
63 #include "gtkcelllayout.h"
64 #include "gtktooltip.h"
65 #include "gtkiconfactory.h"
66 #include "gtkicontheme.h"
69 #define GTK_ENTRY_COMPLETION_KEY "gtk-entry-completion-key"
71 #define MIN_ENTRY_WIDTH 150
72 #define DRAW_TIMEOUT 20
73 #define COMPLETION_TIMEOUT 300
74 #define PASSWORD_HINT_MAX 8
76 /* Initial size of buffer, in bytes */
79 /* Maximum size of text buffer, in bytes */
80 #define MAX_SIZE G_MAXUSHORT
84 #define IS_VALID_ICON_POSITION(pos) \
85 ((pos) == GTK_ENTRY_ICON_PRIMARY || \
86 (pos) == GTK_ENTRY_ICON_SECONDARY)
88 static const GtkBorder default_inner_border = { 2, 2, 2, 2 };
89 static GQuark quark_inner_border = 0;
90 static GQuark quark_password_hint = 0;
91 static GQuark quark_cursor_hadjustment = 0;
92 static GQuark quark_capslock_feedback = 0;
94 typedef struct _GtkEntryPrivate GtkEntryPrivate;
96 #define GTK_ENTRY_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_ENTRY, GtkEntryPrivate))
102 guint insensitive : 1;
103 guint nonactivatable : 1;
108 GtkImageType storage_type;
114 GtkTargetList *target_list;
115 GdkDragAction actions;
118 struct _GtkEntryPrivate
122 guint blink_time; /* time in msec the cursor has blinked since last user event */
123 guint interior_focus : 1;
124 guint real_changed : 1;
125 guint invisible_char_set : 1;
126 guint caps_lock_warning : 1;
127 guint caps_lock_warning_shown : 1;
128 guint change_count : 8;
129 guint progress_pulse_mode : 1;
130 guint progress_pulse_way_back : 1;
133 GtkShadowType shadow_type;
135 gdouble progress_fraction;
136 gdouble progress_pulse_fraction;
137 gdouble progress_pulse_current;
139 EntryIconInfo *icons[MAX_ICONS];
147 typedef struct _GtkEntryPasswordHint GtkEntryPasswordHint;
149 struct _GtkEntryPasswordHint
151 gchar password_hint[PASSWORD_HINT_MAX];
152 guint password_hint_timeout_id;
153 gint password_hint_length;
154 gint password_hint_position;
157 typedef struct _GtkEntryCapslockFeedback GtkEntryCapslockFeedback;
159 struct _GtkEntryCapslockFeedback
184 PROP_CURSOR_POSITION,
185 PROP_SELECTION_BOUND,
192 PROP_ACTIVATES_DEFAULT,
197 PROP_TRUNCATE_MULTILINE,
201 PROP_INVISIBLE_CHAR_SET,
202 PROP_CAPS_LOCK_WARNING,
203 PROP_PROGRESS_FRACTION,
204 PROP_PROGRESS_PULSE_STEP,
206 PROP_PIXBUF_SECONDARY,
208 PROP_STOCK_SECONDARY,
209 PROP_ICON_NAME_PRIMARY,
210 PROP_ICON_NAME_SECONDARY,
212 PROP_GICON_SECONDARY,
213 PROP_STORAGE_TYPE_PRIMARY,
214 PROP_STORAGE_TYPE_SECONDARY,
215 PROP_ACTIVATABLE_PRIMARY,
216 PROP_ACTIVATABLE_SECONDARY,
217 PROP_SENSITIVE_PRIMARY,
218 PROP_SENSITIVE_SECONDARY,
219 PROP_TOOLTIP_TEXT_PRIMARY,
220 PROP_TOOLTIP_TEXT_SECONDARY,
221 PROP_TOOLTIP_MARKUP_PRIMARY,
222 PROP_TOOLTIP_MARKUP_SECONDARY,
226 static guint signals[LAST_SIGNAL] = { 0 };
233 /* GObject, GtkObject methods
235 static void gtk_entry_editable_init (GtkEditableClass *iface);
236 static void gtk_entry_cell_editable_init (GtkCellEditableIface *iface);
237 static void gtk_entry_set_property (GObject *object,
241 static void gtk_entry_get_property (GObject *object,
245 static void gtk_entry_finalize (GObject *object);
246 static void gtk_entry_destroy (GtkObject *object);
247 static void gtk_entry_dispose (GObject *object);
251 static void gtk_entry_realize (GtkWidget *widget);
252 static void gtk_entry_unrealize (GtkWidget *widget);
253 static void gtk_entry_map (GtkWidget *widget);
254 static void gtk_entry_unmap (GtkWidget *widget);
255 static void gtk_entry_size_request (GtkWidget *widget,
256 GtkRequisition *requisition);
257 static void gtk_entry_size_allocate (GtkWidget *widget,
258 GtkAllocation *allocation);
259 static void gtk_entry_draw_frame (GtkWidget *widget,
260 GdkEventExpose *event);
261 static void gtk_entry_draw_progress (GtkWidget *widget,
262 GdkEventExpose *event);
263 static gint gtk_entry_expose (GtkWidget *widget,
264 GdkEventExpose *event);
265 static gint gtk_entry_button_press (GtkWidget *widget,
266 GdkEventButton *event);
267 static gint gtk_entry_button_release (GtkWidget *widget,
268 GdkEventButton *event);
269 static gint gtk_entry_enter_notify (GtkWidget *widget,
270 GdkEventCrossing *event);
271 static gint gtk_entry_leave_notify (GtkWidget *widget,
272 GdkEventCrossing *event);
273 static gint gtk_entry_motion_notify (GtkWidget *widget,
274 GdkEventMotion *event);
275 static gint gtk_entry_key_press (GtkWidget *widget,
277 static gint gtk_entry_key_release (GtkWidget *widget,
279 static gint gtk_entry_focus_in (GtkWidget *widget,
280 GdkEventFocus *event);
281 static gint gtk_entry_focus_out (GtkWidget *widget,
282 GdkEventFocus *event);
283 static void gtk_entry_grab_focus (GtkWidget *widget);
284 static void gtk_entry_style_set (GtkWidget *widget,
285 GtkStyle *previous_style);
286 static gboolean gtk_entry_query_tooltip (GtkWidget *widget,
289 gboolean keyboard_tip,
290 GtkTooltip *tooltip);
291 static void gtk_entry_direction_changed (GtkWidget *widget,
292 GtkTextDirection previous_dir);
293 static void gtk_entry_state_changed (GtkWidget *widget,
294 GtkStateType previous_state);
295 static void gtk_entry_screen_changed (GtkWidget *widget,
296 GdkScreen *old_screen);
298 static gboolean gtk_entry_drag_drop (GtkWidget *widget,
299 GdkDragContext *context,
303 static gboolean gtk_entry_drag_motion (GtkWidget *widget,
304 GdkDragContext *context,
308 static void gtk_entry_drag_leave (GtkWidget *widget,
309 GdkDragContext *context,
311 static void gtk_entry_drag_data_received (GtkWidget *widget,
312 GdkDragContext *context,
315 GtkSelectionData *selection_data,
318 static void gtk_entry_drag_data_get (GtkWidget *widget,
319 GdkDragContext *context,
320 GtkSelectionData *selection_data,
323 static void gtk_entry_drag_data_delete (GtkWidget *widget,
324 GdkDragContext *context);
325 static void gtk_entry_drag_begin (GtkWidget *widget,
326 GdkDragContext *context);
327 static void gtk_entry_drag_end (GtkWidget *widget,
328 GdkDragContext *context);
331 /* GtkEditable method implementations
333 static void gtk_entry_insert_text (GtkEditable *editable,
334 const gchar *new_text,
335 gint new_text_length,
337 static void gtk_entry_delete_text (GtkEditable *editable,
340 static gchar * gtk_entry_get_chars (GtkEditable *editable,
343 static void gtk_entry_real_set_position (GtkEditable *editable,
345 static gint gtk_entry_get_position (GtkEditable *editable);
346 static void gtk_entry_set_selection_bounds (GtkEditable *editable,
349 static gboolean gtk_entry_get_selection_bounds (GtkEditable *editable,
353 /* GtkCellEditable method implementations
355 static void gtk_entry_start_editing (GtkCellEditable *cell_editable,
358 /* Default signal handlers
360 static void gtk_entry_real_insert_text (GtkEditable *editable,
361 const gchar *new_text,
362 gint new_text_length,
364 static void gtk_entry_real_delete_text (GtkEditable *editable,
367 static void gtk_entry_move_cursor (GtkEntry *entry,
368 GtkMovementStep step,
370 gboolean extend_selection);
371 static void gtk_entry_insert_at_cursor (GtkEntry *entry,
373 static void gtk_entry_delete_from_cursor (GtkEntry *entry,
376 static void gtk_entry_backspace (GtkEntry *entry);
377 static void gtk_entry_cut_clipboard (GtkEntry *entry);
378 static void gtk_entry_copy_clipboard (GtkEntry *entry);
379 static void gtk_entry_paste_clipboard (GtkEntry *entry);
380 static void gtk_entry_toggle_overwrite (GtkEntry *entry);
381 static void gtk_entry_select_all (GtkEntry *entry);
382 static void gtk_entry_real_activate (GtkEntry *entry);
383 static gboolean gtk_entry_popup_menu (GtkWidget *widget);
385 static void keymap_direction_changed (GdkKeymap *keymap,
387 static void keymap_state_changed (GdkKeymap *keymap,
389 static void remove_capslock_feedback (GtkEntry *entry);
391 /* IM Context Callbacks
393 static void gtk_entry_commit_cb (GtkIMContext *context,
396 static void gtk_entry_preedit_changed_cb (GtkIMContext *context,
398 static gboolean gtk_entry_retrieve_surrounding_cb (GtkIMContext *context,
400 static gboolean gtk_entry_delete_surrounding_cb (GtkIMContext *context,
407 static void gtk_entry_enter_text (GtkEntry *entry,
409 static void gtk_entry_set_positions (GtkEntry *entry,
411 gint selection_bound);
412 static void gtk_entry_draw_text (GtkEntry *entry);
413 static void gtk_entry_draw_cursor (GtkEntry *entry,
415 static PangoLayout *gtk_entry_ensure_layout (GtkEntry *entry,
416 gboolean include_preedit);
417 static void gtk_entry_reset_layout (GtkEntry *entry);
418 static void gtk_entry_queue_draw (GtkEntry *entry);
419 static void gtk_entry_recompute (GtkEntry *entry);
420 static gint gtk_entry_find_position (GtkEntry *entry,
422 static void gtk_entry_get_cursor_locations (GtkEntry *entry,
426 static void gtk_entry_adjust_scroll (GtkEntry *entry);
427 static gint gtk_entry_move_visually (GtkEntry *editable,
430 static gint gtk_entry_move_logically (GtkEntry *entry,
433 static gint gtk_entry_move_forward_word (GtkEntry *entry,
435 gboolean allow_whitespace);
436 static gint gtk_entry_move_backward_word (GtkEntry *entry,
438 gboolean allow_whitespace);
439 static void gtk_entry_delete_whitespace (GtkEntry *entry);
440 static void gtk_entry_select_word (GtkEntry *entry);
441 static void gtk_entry_select_line (GtkEntry *entry);
442 static char * gtk_entry_get_public_chars (GtkEntry *entry,
445 static void gtk_entry_paste (GtkEntry *entry,
447 static void gtk_entry_update_primary_selection (GtkEntry *entry);
448 static void gtk_entry_do_popup (GtkEntry *entry,
449 GdkEventButton *event);
450 static gboolean gtk_entry_mnemonic_activate (GtkWidget *widget,
451 gboolean group_cycling);
452 static void gtk_entry_check_cursor_blink (GtkEntry *entry);
453 static void gtk_entry_pend_cursor_blink (GtkEntry *entry);
454 static void gtk_entry_reset_blink_time (GtkEntry *entry);
455 static void gtk_entry_get_text_area_size (GtkEntry *entry,
460 static void get_text_area_size (GtkEntry *entry,
465 static void get_widget_window_size (GtkEntry *entry,
470 static void gtk_entry_move_adjustments (GtkEntry *entry);
471 static void gtk_entry_ensure_pixbuf (GtkEntry *entry,
472 GtkEntryIconPosition icon_pos);
476 static gint gtk_entry_completion_timeout (gpointer data);
477 static gboolean gtk_entry_completion_key_press (GtkWidget *widget,
480 static void gtk_entry_completion_changed (GtkWidget *entry,
482 static gboolean check_completion_callback (GtkEntryCompletion *completion);
483 static void clear_completion_callback (GtkEntry *entry,
485 static gboolean accept_completion_callback (GtkEntry *entry);
486 static void completion_insert_text_callback (GtkEntry *entry,
490 GtkEntryCompletion *completion);
491 static void completion_changed (GtkEntryCompletion *completion,
494 static void disconnect_completion_signals (GtkEntry *entry,
495 GtkEntryCompletion *completion);
496 static void connect_completion_signals (GtkEntry *entry,
497 GtkEntryCompletion *completion);
499 static void begin_change (GtkEntry *entry);
500 static void end_change (GtkEntry *entry);
501 static void emit_changed (GtkEntry *entry);
504 G_DEFINE_TYPE_WITH_CODE (GtkEntry, gtk_entry, GTK_TYPE_WIDGET,
505 G_IMPLEMENT_INTERFACE (GTK_TYPE_EDITABLE,
506 gtk_entry_editable_init)
507 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_EDITABLE,
508 gtk_entry_cell_editable_init))
511 add_move_binding (GtkBindingSet *binding_set,
514 GtkMovementStep step,
517 g_return_if_fail ((modmask & GDK_SHIFT_MASK) == 0);
519 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
523 G_TYPE_BOOLEAN, FALSE);
525 /* Selection-extending version */
526 gtk_binding_entry_add_signal (binding_set, keyval, modmask | GDK_SHIFT_MASK,
530 G_TYPE_BOOLEAN, TRUE);
534 gtk_entry_class_init (GtkEntryClass *class)
536 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
537 GtkWidgetClass *widget_class;
538 GtkObjectClass *gtk_object_class;
539 GtkBindingSet *binding_set;
541 widget_class = (GtkWidgetClass*) class;
542 gtk_object_class = (GtkObjectClass *)class;
544 gobject_class->dispose = gtk_entry_dispose;
545 gobject_class->finalize = gtk_entry_finalize;
546 gobject_class->set_property = gtk_entry_set_property;
547 gobject_class->get_property = gtk_entry_get_property;
549 widget_class->map = gtk_entry_map;
550 widget_class->unmap = gtk_entry_unmap;
551 widget_class->realize = gtk_entry_realize;
552 widget_class->unrealize = gtk_entry_unrealize;
553 widget_class->size_request = gtk_entry_size_request;
554 widget_class->size_allocate = gtk_entry_size_allocate;
555 widget_class->expose_event = gtk_entry_expose;
556 widget_class->enter_notify_event = gtk_entry_enter_notify;
557 widget_class->leave_notify_event = gtk_entry_leave_notify;
558 widget_class->button_press_event = gtk_entry_button_press;
559 widget_class->button_release_event = gtk_entry_button_release;
560 widget_class->motion_notify_event = gtk_entry_motion_notify;
561 widget_class->key_press_event = gtk_entry_key_press;
562 widget_class->key_release_event = gtk_entry_key_release;
563 widget_class->focus_in_event = gtk_entry_focus_in;
564 widget_class->focus_out_event = gtk_entry_focus_out;
565 widget_class->grab_focus = gtk_entry_grab_focus;
566 widget_class->style_set = gtk_entry_style_set;
567 widget_class->query_tooltip = gtk_entry_query_tooltip;
568 widget_class->drag_begin = gtk_entry_drag_begin;
569 widget_class->drag_end = gtk_entry_drag_end;
570 widget_class->direction_changed = gtk_entry_direction_changed;
571 widget_class->state_changed = gtk_entry_state_changed;
572 widget_class->screen_changed = gtk_entry_screen_changed;
573 widget_class->mnemonic_activate = gtk_entry_mnemonic_activate;
575 widget_class->drag_drop = gtk_entry_drag_drop;
576 widget_class->drag_motion = gtk_entry_drag_motion;
577 widget_class->drag_leave = gtk_entry_drag_leave;
578 widget_class->drag_data_received = gtk_entry_drag_data_received;
579 widget_class->drag_data_get = gtk_entry_drag_data_get;
580 widget_class->drag_data_delete = gtk_entry_drag_data_delete;
582 widget_class->popup_menu = gtk_entry_popup_menu;
584 gtk_object_class->destroy = gtk_entry_destroy;
586 class->move_cursor = gtk_entry_move_cursor;
587 class->insert_at_cursor = gtk_entry_insert_at_cursor;
588 class->delete_from_cursor = gtk_entry_delete_from_cursor;
589 class->backspace = gtk_entry_backspace;
590 class->cut_clipboard = gtk_entry_cut_clipboard;
591 class->copy_clipboard = gtk_entry_copy_clipboard;
592 class->paste_clipboard = gtk_entry_paste_clipboard;
593 class->toggle_overwrite = gtk_entry_toggle_overwrite;
594 class->activate = gtk_entry_real_activate;
595 class->get_text_area_size = gtk_entry_get_text_area_size;
597 quark_inner_border = g_quark_from_static_string ("gtk-entry-inner-border");
598 quark_password_hint = g_quark_from_static_string ("gtk-entry-password-hint");
599 quark_cursor_hadjustment = g_quark_from_static_string ("gtk-hadjustment");
600 quark_capslock_feedback = g_quark_from_static_string ("gtk-entry-capslock-feedback");
602 g_object_class_install_property (gobject_class,
603 PROP_CURSOR_POSITION,
604 g_param_spec_int ("cursor-position",
605 P_("Cursor Position"),
606 P_("The current position of the insertion cursor in chars"),
610 GTK_PARAM_READABLE));
612 g_object_class_install_property (gobject_class,
613 PROP_SELECTION_BOUND,
614 g_param_spec_int ("selection-bound",
615 P_("Selection Bound"),
616 P_("The position of the opposite end of the selection from the cursor in chars"),
620 GTK_PARAM_READABLE));
622 g_object_class_install_property (gobject_class,
624 g_param_spec_boolean ("editable",
626 P_("Whether the entry contents can be edited"),
628 GTK_PARAM_READWRITE));
630 g_object_class_install_property (gobject_class,
632 g_param_spec_int ("max-length",
633 P_("Maximum length"),
634 P_("Maximum number of characters for this entry. Zero if no maximum"),
638 GTK_PARAM_READWRITE));
639 g_object_class_install_property (gobject_class,
641 g_param_spec_boolean ("visibility",
643 P_("FALSE displays the \"invisible char\" instead of the actual text (password mode)"),
645 GTK_PARAM_READWRITE));
647 g_object_class_install_property (gobject_class,
649 g_param_spec_boolean ("has-frame",
651 P_("FALSE removes outside bevel from entry"),
653 GTK_PARAM_READWRITE));
655 g_object_class_install_property (gobject_class,
657 g_param_spec_boxed ("inner-border",
659 P_("Border between text and frame. Overrides the inner-border style property"),
661 GTK_PARAM_READWRITE));
663 g_object_class_install_property (gobject_class,
665 g_param_spec_unichar ("invisible-char",
666 P_("Invisible character"),
667 P_("The character to use when masking entry contents (in \"password mode\")"),
669 GTK_PARAM_READWRITE));
671 g_object_class_install_property (gobject_class,
672 PROP_ACTIVATES_DEFAULT,
673 g_param_spec_boolean ("activates-default",
674 P_("Activates default"),
675 P_("Whether to activate the default widget (such as the default button in a dialog) when Enter is pressed"),
677 GTK_PARAM_READWRITE));
678 g_object_class_install_property (gobject_class,
680 g_param_spec_int ("width-chars",
681 P_("Width in chars"),
682 P_("Number of characters to leave space for in the entry"),
686 GTK_PARAM_READWRITE));
688 g_object_class_install_property (gobject_class,
690 g_param_spec_int ("scroll-offset",
692 P_("Number of pixels of the entry scrolled off the screen to the left"),
696 GTK_PARAM_READABLE));
698 g_object_class_install_property (gobject_class,
700 g_param_spec_string ("text",
702 P_("The contents of the entry"),
704 GTK_PARAM_READWRITE));
709 * The horizontal alignment, from 0 (left) to 1 (right).
710 * Reversed for RTL layouts.
714 g_object_class_install_property (gobject_class,
716 g_param_spec_float ("xalign",
718 P_("The horizontal alignment, from 0 (left) to 1 (right). Reversed for RTL layouts."),
722 GTK_PARAM_READWRITE));
725 * GtkEntry:truncate-multiline:
727 * When %TRUE, pasted multi-line text is truncated to the first line.
731 g_object_class_install_property (gobject_class,
732 PROP_TRUNCATE_MULTILINE,
733 g_param_spec_boolean ("truncate-multiline",
734 P_("Truncate multiline"),
735 P_("Whether to truncate multiline pastes to one line."),
737 GTK_PARAM_READWRITE));
740 * GtkEntry:shadow-type:
742 * Which kind of shadow to draw around the entry when
743 * #GtkEntry:has-frame is set to %TRUE.
747 g_object_class_install_property (gobject_class,
749 g_param_spec_enum ("shadow-type",
751 P_("Which kind of shadow to draw around the entry when has-frame is set"),
752 GTK_TYPE_SHADOW_TYPE,
754 GTK_PARAM_READWRITE));
757 * GtkEntry:overwrite-mode:
759 * If text is overwritten when typing in the #GtkEntry.
763 g_object_class_install_property (gobject_class,
765 g_param_spec_boolean ("overwrite-mode",
766 P_("Overwrite mode"),
767 P_("Whether new text overwrites existing text"),
769 GTK_PARAM_READWRITE));
772 * GtkEntry:text-length:
774 * The length of the text in the #GtkEntry.
778 g_object_class_install_property (gobject_class,
780 g_param_spec_uint ("text-length",
782 P_("Length of the text currently in the entry"),
786 GTK_PARAM_READABLE));
788 * GtkEntry:invisible-char-set:
790 * Whether the invisible char has been set for the #GtkEntry.
794 g_object_class_install_property (gobject_class,
795 PROP_INVISIBLE_CHAR_SET,
796 g_param_spec_boolean ("invisible-char-set",
797 P_("Invisible char set"),
798 P_("Whether the invisible char has been set"),
800 GTK_PARAM_READWRITE));
803 * GtkEntry:caps-lock-warning
805 * Whether password entries will show a warning when Caps Lock is on.
807 * Note that the warning is shown using a secondary icon, and thus
808 * does not work if you are using the secondary icon position for some
813 g_object_class_install_property (gobject_class,
814 PROP_CAPS_LOCK_WARNING,
815 g_param_spec_boolean ("caps-lock-warning",
816 P_("Caps Lock warning"),
817 P_("Whether password entries will show a warning when Caps Lock is on"),
819 GTK_PARAM_READWRITE));
822 * GtkEntry:progress-fraction:
824 * The current fraction of the task that's been completed.
828 g_object_class_install_property (gobject_class,
829 PROP_PROGRESS_FRACTION,
830 g_param_spec_double ("progress-fraction",
831 P_("Progress Fraction"),
832 P_("The current fraction of the task that's been completed"),
836 GTK_PARAM_READWRITE));
839 * GtkEntry:progress-pulse-step:
841 * The fraction of total entry width to move the progress
842 * bouncing block for each call to gtk_entry_progress_pulse().
846 g_object_class_install_property (gobject_class,
847 PROP_PROGRESS_PULSE_STEP,
848 g_param_spec_double ("progress-pulse-step",
849 P_("Progress Pulse Step"),
850 P_("The fraction of total entry width to move the progress bouncing block for each call to gtk_entry_progress_pulse()"),
854 GTK_PARAM_READWRITE));
857 * GtkEntry:primary-icon-pixbuf:
859 * A pixbuf to use as the primary icon for the entry.
863 g_object_class_install_property (gobject_class,
865 g_param_spec_object ("primary-icon-pixbuf",
866 P_("Primary pixbuf"),
867 P_("Primary pixbuf for the entry"),
869 GTK_PARAM_READWRITE));
872 * GtkEntry:secondary-icon-pixbuf:
874 * An pixbuf to use as the secondary icon for the entry.
878 g_object_class_install_property (gobject_class,
879 PROP_PIXBUF_SECONDARY,
880 g_param_spec_object ("secondary-icon-pixbuf",
881 P_("Secondary pixbuf"),
882 P_("Secondary pixbuf for the entry"),
884 GTK_PARAM_READWRITE));
887 * GtkEntry:primary-icon-stock:
889 * The stock id to use for the primary icon for the entry.
893 g_object_class_install_property (gobject_class,
895 g_param_spec_string ("primary-icon-stock",
896 P_("Primary stock ID"),
897 P_("Stock ID for primary icon"),
899 GTK_PARAM_READWRITE));
902 * GtkEntry:secondary-icon-stock:
904 * The stock id to use for the secondary icon for the entry.
908 g_object_class_install_property (gobject_class,
909 PROP_STOCK_SECONDARY,
910 g_param_spec_string ("secondary-icon-stock",
911 P_("Secondary stock ID"),
912 P_("Stock ID for secondary icon"),
914 GTK_PARAM_READWRITE));
917 * GtkEntry:primary-icon-name:
919 * The icon name to use for the primary icon for the entry.
923 g_object_class_install_property (gobject_class,
924 PROP_ICON_NAME_PRIMARY,
925 g_param_spec_string ("primary-icon-name",
926 P_("Primary icon name"),
927 P_("Icon name for primary icon"),
929 GTK_PARAM_READWRITE));
932 * GtkEntry:secondary-icon-name:
934 * The icon name to use for the secondary icon for the entry.
938 g_object_class_install_property (gobject_class,
939 PROP_ICON_NAME_SECONDARY,
940 g_param_spec_string ("secondary-icon-name",
941 P_("Secondary icon name"),
942 P_("Icon name for secondary icon"),
944 GTK_PARAM_READWRITE));
947 * GtkEntry:primary-icon-gicon:
949 * The #GIcon to use for the primary icon for the entry.
953 g_object_class_install_property (gobject_class,
955 g_param_spec_object ("primary-icon-gicon",
957 P_("GIcon for primary icon"),
959 GTK_PARAM_READWRITE));
962 * GtkEntry:secondary-icon-gicon:
964 * The #GIcon to use for the secondary icon for the entry.
968 g_object_class_install_property (gobject_class,
969 PROP_GICON_SECONDARY,
970 g_param_spec_object ("secondary-icon-gicon",
971 P_("Secondary GIcon"),
972 P_("GIcon for secondary icon"),
974 GTK_PARAM_READWRITE));
977 * GtkEntry:primary-icon-storage-type:
979 * The representation which is used for the primary icon of the entry.
983 g_object_class_install_property (gobject_class,
984 PROP_STORAGE_TYPE_PRIMARY,
985 g_param_spec_enum ("primary-icon-storage-type",
986 P_("Primary storage type"),
987 P_("The representation being used for primary icon"),
990 GTK_PARAM_READABLE));
993 * GtkEntry:secondary-icon-storage-type:
995 * The representation which is used for the secondary icon of the entry.
999 g_object_class_install_property (gobject_class,
1000 PROP_STORAGE_TYPE_SECONDARY,
1001 g_param_spec_enum ("secondary-icon-storage-type",
1002 P_("Secondary storage type"),
1003 P_("The representation being used for secondary icon"),
1004 GTK_TYPE_IMAGE_TYPE,
1006 GTK_PARAM_READABLE));
1009 * GtkEntry:primary-icon-activatable:
1011 * Whether the primary icon is activatable.
1013 * GTK+ emits the #GtkEntry::icon-press and #GtkEntry::icon-release
1014 * signals only on sensitive, activatable icons.
1016 * Sensitive, but non-activatable icons can be used for purely
1017 * informational purposes.
1021 g_object_class_install_property (gobject_class,
1022 PROP_ACTIVATABLE_PRIMARY,
1023 g_param_spec_boolean ("primary-icon-activatable",
1024 P_("Primary icon activatable"),
1025 P_("Whether the primary icon is activatable"),
1027 GTK_PARAM_READWRITE));
1030 * GtkEntry:secondary-icon-activatable:
1032 * Whether the secondary icon is activatable.
1034 * GTK+ emits the #GtkEntry::icon-press and #GtkEntry::icon-release
1035 * signals only on sensitive, activatable icons.
1037 * Sensitive, but non-activatable icons can be used for purely
1038 * informational purposes.
1042 g_object_class_install_property (gobject_class,
1043 PROP_ACTIVATABLE_SECONDARY,
1044 g_param_spec_boolean ("secondary-icon-activatable",
1045 P_("Secondary icon activatable"),
1046 P_("Whether the secondary icon is activatable"),
1048 GTK_PARAM_READWRITE));
1052 * GtkEntry:primary-icon-sensitive:
1054 * Whether the primary icon is sensitive.
1056 * An insensitive icon appears grayed out. GTK+ does not emit the
1057 * #GtkEntry::icon-press and #GtkEntry::icon-release signals and
1058 * does not allow DND from insensitive icons.
1060 * An icon should be set insensitive if the action that would trigger
1061 * when clicked is currently not available.
1065 g_object_class_install_property (gobject_class,
1066 PROP_SENSITIVE_PRIMARY,
1067 g_param_spec_boolean ("primary-icon-sensitive",
1068 P_("Primary icon sensitive"),
1069 P_("Whether the primary icon is sensitive"),
1071 GTK_PARAM_READWRITE));
1074 * GtkEntry:secondary-icon-sensitive:
1076 * Whether the secondary icon is sensitive.
1078 * An insensitive icon appears grayed out. GTK+ does not emit the
1079 * #GtkEntry::icon-press and #GtkEntry::icon-release signals and
1080 * does not allow DND from insensitive icons.
1082 * An icon should be set insensitive if the action that would trigger
1083 * when clicked is currently not available.
1087 g_object_class_install_property (gobject_class,
1088 PROP_SENSITIVE_SECONDARY,
1089 g_param_spec_boolean ("secondary-icon-sensitive",
1090 P_("Secondary icon sensitive"),
1091 P_("Whether the secondary icon is sensitive"),
1093 GTK_PARAM_READWRITE));
1096 * GtkEntry:primary-icon-tooltip-text:
1098 * The contents of the tooltip on the primary icon.
1100 * Also see gtk_entry_set_icon_tooltip_text().
1104 g_object_class_install_property (gobject_class,
1105 PROP_TOOLTIP_TEXT_PRIMARY,
1106 g_param_spec_string ("primary-icon-tooltip-text",
1107 P_("Primary icon tooltip text"),
1108 P_("The contents of the tooltip on the primary icon"),
1110 GTK_PARAM_READWRITE));
1113 * GtkEntry:secondary-icon-tooltip-text:
1115 * The contents of the tooltip on the secondary icon.
1117 * Also see gtk_entry_set_icon_tooltip_text().
1121 g_object_class_install_property (gobject_class,
1122 PROP_TOOLTIP_TEXT_SECONDARY,
1123 g_param_spec_string ("secondary-icon-tooltip-text",
1124 P_("Secondary icon tooltip text"),
1125 P_("The contents of the tooltip on the secondary icon"),
1127 GTK_PARAM_READWRITE));
1130 * GtkEntry:primary-icon-tooltip-markup:
1132 * The contents of the tooltip on the primary icon, which is marked up
1133 * with the <link linkend="PangoMarkupFormat">Pango text markup
1136 * Also see gtk_entry_set_icon_tooltip_markup().
1140 g_object_class_install_property (gobject_class,
1141 PROP_TOOLTIP_MARKUP_PRIMARY,
1142 g_param_spec_string ("primary-icon-tooltip-markup",
1143 P_("Primary icon tooltip markup"),
1144 P_("The contents of the tooltip on the primary icon"),
1146 GTK_PARAM_READWRITE));
1149 * GtkEntry:secondary-icon-tooltip-markup:
1151 * The contents of the tooltip on the secondary icon, which is marked up
1152 * with the <link linkend="PangoMarkupFormat">Pango text markup
1155 * Also see gtk_entry_set_icon_tooltip_markup().
1159 g_object_class_install_property (gobject_class,
1160 PROP_TOOLTIP_MARKUP_SECONDARY,
1161 g_param_spec_string ("secondary-icon-tooltip-markup",
1162 P_("Secondary icon tooltip markup"),
1163 P_("The contents of the tooltip on the secondary icon"),
1165 GTK_PARAM_READWRITE));
1168 * GtkEntry:im-module:
1170 * Which IM (input method) module should be used for this entry.
1171 * See #GtkIMContext.
1173 * Setting this to a non-%NULL value overrides the
1174 * system-wide IM module setting. See the GtkSettings
1175 * #GtkSettings:gtk-im-module property.
1179 g_object_class_install_property (gobject_class,
1181 g_param_spec_string ("im-module",
1183 P_("Which IM module should be used"),
1185 GTK_PARAM_READWRITE));
1188 * GtkEntry:icon-prelight:
1190 * The prelight style property determines whether activatable
1191 * icons prelight on mouseover.
1195 gtk_widget_class_install_style_property (widget_class,
1196 g_param_spec_boolean ("icon-prelight",
1197 P_("Icon Prelight"),
1198 P_("Whether activatable icons should prelight when hovered"),
1200 GTK_PARAM_READABLE));
1203 * GtkEntry::progress-border:
1205 * The border around the progress bar in the entry.
1209 gtk_widget_class_install_style_property (widget_class,
1210 g_param_spec_boxed ("progress-border",
1211 P_("Progress Border"),
1212 P_("Border around the progress bar"),
1214 GTK_PARAM_READABLE));
1217 * GtkEntry::populate-popup:
1218 * @entry: The entry on which the signal is emitted
1219 * @menu: the menu that is being populated
1221 * The ::populate-popup signal gets emitted before showing the
1222 * context menu of the entry.
1224 * If you need to add items to the context menu, connect
1225 * to this signal and append your menuitems to the @menu.
1227 signals[POPULATE_POPUP] =
1228 g_signal_new (I_("populate-popup"),
1229 G_OBJECT_CLASS_TYPE (gobject_class),
1231 G_STRUCT_OFFSET (GtkEntryClass, populate_popup),
1233 _gtk_marshal_VOID__OBJECT,
1237 /* Action signals */
1240 * GtkEntry::activate:
1241 * @entry: The entry on which the signal is emitted
1243 * A <link linkend="keybinding-signals">keybinding signal</link>
1244 * which gets emitted when the user activates the entry.
1246 * Applications should not connect to it, but may emit it with
1247 * g_signal_emit_by_name() if they need to control activation
1250 * The default bindings for this signal are all forms of the Enter key.
1253 g_signal_new (I_("activate"),
1254 G_OBJECT_CLASS_TYPE (gobject_class),
1255 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1256 G_STRUCT_OFFSET (GtkEntryClass, activate),
1258 _gtk_marshal_VOID__VOID,
1260 widget_class->activate_signal = signals[ACTIVATE];
1263 * GtkEntry::move-cursor:
1264 * @entry: the object which received the signal
1265 * @step: the granularity of the move, as a #GtkMovementStep
1266 * @count: the number of @step units to move
1267 * @extend_selection: %TRUE if the move should extend the selection
1269 * The ::move-cursor signal is a
1270 * <link linkend="keybinding-signals">keybinding signal</link>
1271 * which gets emitted when the user initiates a cursor movement.
1272 * If the cursor is not visible in @entry, this signal causes
1273 * the viewport to be moved instead.
1275 * Applications should not connect to it, but may emit it with
1276 * g_signal_emit_by_name() if they need to control the cursor
1279 * The default bindings for this signal come in two variants,
1280 * the variant with the Shift modifier extends the selection,
1281 * the variant without the Shift modifer does not.
1282 * There are too many key combinations to list them all here.
1284 * <listitem>Arrow keys move by individual characters/lines</listitem>
1285 * <listitem>Ctrl-arrow key combinations move by words/paragraphs</listitem>
1286 * <listitem>Home/End keys move to the ends of the buffer</listitem>
1289 signals[MOVE_CURSOR] =
1290 g_signal_new (I_("move-cursor"),
1291 G_OBJECT_CLASS_TYPE (gobject_class),
1292 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1293 G_STRUCT_OFFSET (GtkEntryClass, move_cursor),
1295 _gtk_marshal_VOID__ENUM_INT_BOOLEAN,
1297 GTK_TYPE_MOVEMENT_STEP,
1302 * GtkEntry::insert-at-cursor:
1303 * @entry: the object which received the signal
1304 * @string: the string to insert
1306 * The ::insert-at-cursor signal is a
1307 * <link linkend="keybinding-signals">keybinding signal</link>
1308 * which gets emitted when the user initiates the insertion of a
1309 * fixed string at the cursor.
1311 * This signal has no default bindings.
1313 signals[INSERT_AT_CURSOR] =
1314 g_signal_new (I_("insert-at-cursor"),
1315 G_OBJECT_CLASS_TYPE (gobject_class),
1316 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1317 G_STRUCT_OFFSET (GtkEntryClass, insert_at_cursor),
1319 _gtk_marshal_VOID__STRING,
1324 * GtkEntry::delete-from-cursor:
1325 * @entry: the object which received the signal
1326 * @type: the granularity of the deletion, as a #GtkDeleteType
1327 * @count: the number of @type units to delete
1329 * The ::delete-from-cursor signal is a
1330 * <link linkend="keybinding-signals">keybinding signal</link>
1331 * which gets emitted when the user initiates a text deletion.
1333 * If the @type is %GTK_DELETE_CHARS, GTK+ deletes the selection
1334 * if there is one, otherwise it deletes the requested number
1337 * The default bindings for this signal are
1338 * Delete for deleting a character and Ctrl-Delete for
1341 signals[DELETE_FROM_CURSOR] =
1342 g_signal_new (I_("delete-from-cursor"),
1343 G_OBJECT_CLASS_TYPE (gobject_class),
1344 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1345 G_STRUCT_OFFSET (GtkEntryClass, delete_from_cursor),
1347 _gtk_marshal_VOID__ENUM_INT,
1349 GTK_TYPE_DELETE_TYPE,
1353 * GtkEntry::backspace:
1354 * @entry: the object which received the signal
1356 * The ::backspace signal is a
1357 * <link linkend="keybinding-signals">keybinding signal</link>
1358 * which gets emitted when the user asks for it.
1360 * The default bindings for this signal are
1361 * Backspace and Shift-Backspace.
1363 signals[BACKSPACE] =
1364 g_signal_new (I_("backspace"),
1365 G_OBJECT_CLASS_TYPE (gobject_class),
1366 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1367 G_STRUCT_OFFSET (GtkEntryClass, backspace),
1369 _gtk_marshal_VOID__VOID,
1373 * GtkEntry::cut-clipboard:
1374 * @entry: the object which received the signal
1376 * The ::cut-clipboard signal is a
1377 * <link linkend="keybinding-signals">keybinding signal</link>
1378 * which gets emitted to cut the selection to the clipboard.
1380 * The default bindings for this signal are
1381 * Ctrl-x and Shift-Delete.
1383 signals[CUT_CLIPBOARD] =
1384 g_signal_new (I_("cut-clipboard"),
1385 G_OBJECT_CLASS_TYPE (gobject_class),
1386 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1387 G_STRUCT_OFFSET (GtkEntryClass, cut_clipboard),
1389 _gtk_marshal_VOID__VOID,
1393 * GtkEntry::copy-clipboard:
1394 * @entry: the object which received the signal
1396 * The ::copy-clipboard signal is a
1397 * <link linkend="keybinding-signals">keybinding signal</link>
1398 * which gets emitted to copy the selection to the clipboard.
1400 * The default bindings for this signal are
1401 * Ctrl-c and Ctrl-Insert.
1403 signals[COPY_CLIPBOARD] =
1404 g_signal_new (I_("copy-clipboard"),
1405 G_OBJECT_CLASS_TYPE (gobject_class),
1406 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1407 G_STRUCT_OFFSET (GtkEntryClass, copy_clipboard),
1409 _gtk_marshal_VOID__VOID,
1413 * GtkEntry::paste-clipboard:
1414 * @entry: the object which received the signal
1416 * The ::paste-clipboard signal is a
1417 * <link linkend="keybinding-signals">keybinding signal</link>
1418 * which gets emitted to paste the contents of the clipboard
1419 * into the text view.
1421 * The default bindings for this signal are
1422 * Ctrl-v and Shift-Insert.
1424 signals[PASTE_CLIPBOARD] =
1425 g_signal_new (I_("paste-clipboard"),
1426 G_OBJECT_CLASS_TYPE (gobject_class),
1427 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1428 G_STRUCT_OFFSET (GtkEntryClass, paste_clipboard),
1430 _gtk_marshal_VOID__VOID,
1434 * GtkEntry::toggle-overwrite:
1435 * @entry: the object which received the signal
1437 * The ::toggle-overwrite signal is a
1438 * <link linkend="keybinding-signals">keybinding signal</link>
1439 * which gets emitted to toggle the overwrite mode of the entry.
1441 * The default bindings for this signal is Insert.
1443 signals[TOGGLE_OVERWRITE] =
1444 g_signal_new (I_("toggle-overwrite"),
1445 G_OBJECT_CLASS_TYPE (gobject_class),
1446 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1447 G_STRUCT_OFFSET (GtkEntryClass, toggle_overwrite),
1449 _gtk_marshal_VOID__VOID,
1453 * GtkEntry::icon-press:
1454 * @entry: The entry on which the signal is emitted
1455 * @icon_pos: The position of the clicked icon
1456 * @event: the button press event
1458 * The ::icon-press signal is emitted when an activatable icon
1463 signals[ICON_PRESS] =
1464 g_signal_new (I_("icon-press"),
1465 G_TYPE_FROM_CLASS (gobject_class),
1466 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1469 _gtk_marshal_VOID__ENUM_BOXED,
1471 GTK_TYPE_ENTRY_ICON_POSITION,
1472 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1475 * GtkEntry::icon-release:
1476 * @entry: The entry on which the signal is emitted
1477 * @icon_pos: The position of the clicked icon
1478 * @event: the button release event
1480 * The ::icon-release signal is emitted on the button release from a
1481 * mouse click over an activatable icon.
1485 signals[ICON_RELEASE] =
1486 g_signal_new (I_("icon-release"),
1487 G_TYPE_FROM_CLASS (gobject_class),
1488 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1491 _gtk_marshal_VOID__ENUM_BOXED,
1493 GTK_TYPE_ENTRY_ICON_POSITION,
1494 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1501 binding_set = gtk_binding_set_by_class (class);
1503 /* Moving the insertion point */
1504 add_move_binding (binding_set, GDK_Right, 0,
1505 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1507 add_move_binding (binding_set, GDK_Left, 0,
1508 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1510 add_move_binding (binding_set, GDK_KP_Right, 0,
1511 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1513 add_move_binding (binding_set, GDK_KP_Left, 0,
1514 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1516 add_move_binding (binding_set, GDK_Right, GDK_CONTROL_MASK,
1517 GTK_MOVEMENT_WORDS, 1);
1519 add_move_binding (binding_set, GDK_Left, GDK_CONTROL_MASK,
1520 GTK_MOVEMENT_WORDS, -1);
1522 add_move_binding (binding_set, GDK_KP_Right, GDK_CONTROL_MASK,
1523 GTK_MOVEMENT_WORDS, 1);
1525 add_move_binding (binding_set, GDK_KP_Left, GDK_CONTROL_MASK,
1526 GTK_MOVEMENT_WORDS, -1);
1528 add_move_binding (binding_set, GDK_Home, 0,
1529 GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
1531 add_move_binding (binding_set, GDK_End, 0,
1532 GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
1534 add_move_binding (binding_set, GDK_KP_Home, 0,
1535 GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
1537 add_move_binding (binding_set, GDK_KP_End, 0,
1538 GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
1540 add_move_binding (binding_set, GDK_Home, GDK_CONTROL_MASK,
1541 GTK_MOVEMENT_BUFFER_ENDS, -1);
1543 add_move_binding (binding_set, GDK_End, GDK_CONTROL_MASK,
1544 GTK_MOVEMENT_BUFFER_ENDS, 1);
1546 add_move_binding (binding_set, GDK_KP_Home, GDK_CONTROL_MASK,
1547 GTK_MOVEMENT_BUFFER_ENDS, -1);
1549 add_move_binding (binding_set, GDK_KP_End, GDK_CONTROL_MASK,
1550 GTK_MOVEMENT_BUFFER_ENDS, 1);
1554 gtk_binding_entry_add_signal (binding_set, GDK_a, GDK_CONTROL_MASK,
1556 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1558 G_TYPE_BOOLEAN, FALSE);
1559 gtk_binding_entry_add_signal (binding_set, GDK_a, GDK_CONTROL_MASK,
1561 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1563 G_TYPE_BOOLEAN, TRUE);
1565 gtk_binding_entry_add_signal (binding_set, GDK_slash, GDK_CONTROL_MASK,
1567 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1569 G_TYPE_BOOLEAN, FALSE);
1570 gtk_binding_entry_add_signal (binding_set, GDK_slash, GDK_CONTROL_MASK,
1572 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1574 G_TYPE_BOOLEAN, TRUE);
1577 gtk_binding_entry_add_signal (binding_set, GDK_backslash, GDK_CONTROL_MASK,
1579 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_VISUAL_POSITIONS,
1581 G_TYPE_BOOLEAN, FALSE);
1582 gtk_binding_entry_add_signal (binding_set, GDK_a, GDK_SHIFT_MASK | GDK_CONTROL_MASK,
1584 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_VISUAL_POSITIONS,
1586 G_TYPE_BOOLEAN, FALSE);
1590 gtk_binding_entry_add_signal (binding_set, GDK_Return, 0,
1592 gtk_binding_entry_add_signal (binding_set, GDK_ISO_Enter, 0,
1594 gtk_binding_entry_add_signal (binding_set, GDK_KP_Enter, 0,
1598 gtk_binding_entry_add_signal (binding_set, GDK_Delete, 0,
1599 "delete-from-cursor", 2,
1600 G_TYPE_ENUM, GTK_DELETE_CHARS,
1603 gtk_binding_entry_add_signal (binding_set, GDK_KP_Delete, 0,
1604 "delete-from-cursor", 2,
1605 G_TYPE_ENUM, GTK_DELETE_CHARS,
1608 gtk_binding_entry_add_signal (binding_set, GDK_BackSpace, 0,
1611 /* Make this do the same as Backspace, to help with mis-typing */
1612 gtk_binding_entry_add_signal (binding_set, GDK_BackSpace, GDK_SHIFT_MASK,
1615 gtk_binding_entry_add_signal (binding_set, GDK_Delete, GDK_CONTROL_MASK,
1616 "delete-from-cursor", 2,
1617 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1620 gtk_binding_entry_add_signal (binding_set, GDK_KP_Delete, GDK_CONTROL_MASK,
1621 "delete-from-cursor", 2,
1622 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1625 gtk_binding_entry_add_signal (binding_set, GDK_BackSpace, GDK_CONTROL_MASK,
1626 "delete-from-cursor", 2,
1627 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1630 /* Cut/copy/paste */
1632 gtk_binding_entry_add_signal (binding_set, GDK_x, GDK_CONTROL_MASK,
1633 "cut-clipboard", 0);
1634 gtk_binding_entry_add_signal (binding_set, GDK_c, GDK_CONTROL_MASK,
1635 "copy-clipboard", 0);
1636 gtk_binding_entry_add_signal (binding_set, GDK_v, GDK_CONTROL_MASK,
1637 "paste-clipboard", 0);
1639 gtk_binding_entry_add_signal (binding_set, GDK_Delete, GDK_SHIFT_MASK,
1640 "cut-clipboard", 0);
1641 gtk_binding_entry_add_signal (binding_set, GDK_Insert, GDK_CONTROL_MASK,
1642 "copy-clipboard", 0);
1643 gtk_binding_entry_add_signal (binding_set, GDK_Insert, GDK_SHIFT_MASK,
1644 "paste-clipboard", 0);
1647 gtk_binding_entry_add_signal (binding_set, GDK_Insert, 0,
1648 "toggle-overwrite", 0);
1649 gtk_binding_entry_add_signal (binding_set, GDK_KP_Insert, 0,
1650 "toggle-overwrite", 0);
1653 * GtkEntry:inner-border:
1655 * Sets the text area's border between the text and the frame.
1659 gtk_widget_class_install_style_property (widget_class,
1660 g_param_spec_boxed ("inner-border",
1662 P_("Border between text and frame."),
1664 GTK_PARAM_READABLE));
1667 * GtkEntry:state-hint:
1669 * Indicates whether to pass a proper widget state when
1670 * drawing the shadow and the widget background.
1674 gtk_widget_class_install_style_property (widget_class,
1675 g_param_spec_boolean ("state-hint",
1677 P_("Whether to pass a proper state when drawing shadow or background"),
1679 GTK_PARAM_READABLE));
1681 gtk_settings_install_property (g_param_spec_boolean ("gtk-entry-select-on-focus",
1682 P_("Select on focus"),
1683 P_("Whether to select the contents of an entry when it is focused"),
1685 GTK_PARAM_READWRITE));
1688 * GtkSettings:gtk-entry-password-hint-timeout:
1690 * How long to show the last input character in hidden
1691 * entries. This value is in milliseconds. 0 disables showing the
1692 * last char. 600 is a good value for enabling it.
1696 gtk_settings_install_property (g_param_spec_uint ("gtk-entry-password-hint-timeout",
1697 P_("Password Hint Timeout"),
1698 P_("How long to show the last input character in hidden entries"),
1700 GTK_PARAM_READWRITE));
1702 g_type_class_add_private (gobject_class, sizeof (GtkEntryPrivate));
1706 gtk_entry_editable_init (GtkEditableClass *iface)
1708 iface->do_insert_text = gtk_entry_insert_text;
1709 iface->do_delete_text = gtk_entry_delete_text;
1710 iface->insert_text = gtk_entry_real_insert_text;
1711 iface->delete_text = gtk_entry_real_delete_text;
1712 iface->get_chars = gtk_entry_get_chars;
1713 iface->set_selection_bounds = gtk_entry_set_selection_bounds;
1714 iface->get_selection_bounds = gtk_entry_get_selection_bounds;
1715 iface->set_position = gtk_entry_real_set_position;
1716 iface->get_position = gtk_entry_get_position;
1720 gtk_entry_cell_editable_init (GtkCellEditableIface *iface)
1722 iface->start_editing = gtk_entry_start_editing;
1726 gtk_entry_set_property (GObject *object,
1728 const GValue *value,
1731 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (object);
1732 GtkEntry *entry = GTK_ENTRY (object);
1738 gboolean new_value = g_value_get_boolean (value);
1740 if (new_value != entry->editable)
1744 _gtk_entry_reset_im_context (entry);
1745 if (GTK_WIDGET_HAS_FOCUS (entry))
1746 gtk_im_context_focus_out (entry->im_context);
1748 entry->preedit_length = 0;
1749 entry->preedit_cursor = 0;
1752 entry->editable = new_value;
1754 if (new_value && GTK_WIDGET_HAS_FOCUS (entry))
1755 gtk_im_context_focus_in (entry->im_context);
1757 gtk_entry_queue_draw (entry);
1762 case PROP_MAX_LENGTH:
1763 gtk_entry_set_max_length (entry, g_value_get_int (value));
1766 case PROP_VISIBILITY:
1767 gtk_entry_set_visibility (entry, g_value_get_boolean (value));
1770 case PROP_HAS_FRAME:
1771 gtk_entry_set_has_frame (entry, g_value_get_boolean (value));
1774 case PROP_INNER_BORDER:
1775 gtk_entry_set_inner_border (entry, g_value_get_boxed (value));
1778 case PROP_INVISIBLE_CHAR:
1779 gtk_entry_set_invisible_char (entry, g_value_get_uint (value));
1782 case PROP_ACTIVATES_DEFAULT:
1783 gtk_entry_set_activates_default (entry, g_value_get_boolean (value));
1786 case PROP_WIDTH_CHARS:
1787 gtk_entry_set_width_chars (entry, g_value_get_int (value));
1791 gtk_entry_set_text (entry, g_value_get_string (value));
1795 gtk_entry_set_alignment (entry, g_value_get_float (value));
1798 case PROP_TRUNCATE_MULTILINE:
1799 entry->truncate_multiline = g_value_get_boolean (value);
1802 case PROP_SHADOW_TYPE:
1803 priv->shadow_type = g_value_get_enum (value);
1806 case PROP_OVERWRITE_MODE:
1807 gtk_entry_set_overwrite_mode (entry, g_value_get_boolean (value));
1810 case PROP_INVISIBLE_CHAR_SET:
1811 if (g_value_get_boolean (value))
1812 priv->invisible_char_set = TRUE;
1814 gtk_entry_unset_invisible_char (entry);
1817 case PROP_CAPS_LOCK_WARNING:
1818 priv->caps_lock_warning = g_value_get_boolean (value);
1821 case PROP_PROGRESS_FRACTION:
1822 gtk_entry_set_progress_fraction (entry, g_value_get_double (value));
1825 case PROP_PROGRESS_PULSE_STEP:
1826 gtk_entry_set_progress_pulse_step (entry, g_value_get_double (value));
1829 case PROP_PIXBUF_PRIMARY:
1830 gtk_entry_set_icon_from_pixbuf (entry,
1831 GTK_ENTRY_ICON_PRIMARY,
1832 g_value_get_object (value));
1835 case PROP_PIXBUF_SECONDARY:
1836 gtk_entry_set_icon_from_pixbuf (entry,
1837 GTK_ENTRY_ICON_SECONDARY,
1838 g_value_get_object (value));
1841 case PROP_STOCK_PRIMARY:
1842 gtk_entry_set_icon_from_stock (entry,
1843 GTK_ENTRY_ICON_PRIMARY,
1844 g_value_get_string (value));
1847 case PROP_STOCK_SECONDARY:
1848 gtk_entry_set_icon_from_stock (entry,
1849 GTK_ENTRY_ICON_SECONDARY,
1850 g_value_get_string (value));
1853 case PROP_ICON_NAME_PRIMARY:
1854 gtk_entry_set_icon_from_icon_name (entry,
1855 GTK_ENTRY_ICON_PRIMARY,
1856 g_value_get_string (value));
1859 case PROP_ICON_NAME_SECONDARY:
1860 gtk_entry_set_icon_from_icon_name (entry,
1861 GTK_ENTRY_ICON_SECONDARY,
1862 g_value_get_string (value));
1865 case PROP_GICON_PRIMARY:
1866 gtk_entry_set_icon_from_gicon (entry,
1867 GTK_ENTRY_ICON_PRIMARY,
1868 g_value_get_object (value));
1871 case PROP_GICON_SECONDARY:
1872 gtk_entry_set_icon_from_gicon (entry,
1873 GTK_ENTRY_ICON_SECONDARY,
1874 g_value_get_object (value));
1877 case PROP_ACTIVATABLE_PRIMARY:
1878 gtk_entry_set_icon_activatable (entry,
1879 GTK_ENTRY_ICON_PRIMARY,
1880 g_value_get_boolean (value));
1883 case PROP_ACTIVATABLE_SECONDARY:
1884 gtk_entry_set_icon_activatable (entry,
1885 GTK_ENTRY_ICON_SECONDARY,
1886 g_value_get_boolean (value));
1889 case PROP_SENSITIVE_PRIMARY:
1890 gtk_entry_set_icon_sensitive (entry,
1891 GTK_ENTRY_ICON_PRIMARY,
1892 g_value_get_boolean (value));
1895 case PROP_SENSITIVE_SECONDARY:
1896 gtk_entry_set_icon_sensitive (entry,
1897 GTK_ENTRY_ICON_SECONDARY,
1898 g_value_get_boolean (value));
1901 case PROP_TOOLTIP_TEXT_PRIMARY:
1902 gtk_entry_set_icon_tooltip_text (entry,
1903 GTK_ENTRY_ICON_PRIMARY,
1904 g_value_get_string (value));
1907 case PROP_TOOLTIP_TEXT_SECONDARY:
1908 gtk_entry_set_icon_tooltip_text (entry,
1909 GTK_ENTRY_ICON_SECONDARY,
1910 g_value_get_string (value));
1913 case PROP_TOOLTIP_MARKUP_PRIMARY:
1914 gtk_entry_set_icon_tooltip_markup (entry,
1915 GTK_ENTRY_ICON_PRIMARY,
1916 g_value_get_string (value));
1919 case PROP_TOOLTIP_MARKUP_SECONDARY:
1920 gtk_entry_set_icon_tooltip_markup (entry,
1921 GTK_ENTRY_ICON_SECONDARY,
1922 g_value_get_string (value));
1925 case PROP_IM_MODULE:
1926 g_free (priv->im_module);
1927 priv->im_module = g_strdup (g_value_get_string (value));
1928 if (GTK_IS_IM_MULTICONTEXT (entry->im_context))
1929 gtk_im_multicontext_set_context_id (GTK_IM_MULTICONTEXT (entry->im_context), priv->im_module);
1932 case PROP_SCROLL_OFFSET:
1933 case PROP_CURSOR_POSITION:
1935 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1941 gtk_entry_get_property (GObject *object,
1946 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (object);
1947 GtkEntry *entry = GTK_ENTRY (object);
1951 case PROP_CURSOR_POSITION:
1952 g_value_set_int (value, entry->current_pos);
1955 case PROP_SELECTION_BOUND:
1956 g_value_set_int (value, entry->selection_bound);
1960 g_value_set_boolean (value, entry->editable);
1963 case PROP_MAX_LENGTH:
1964 g_value_set_int (value, entry->text_max_length);
1967 case PROP_VISIBILITY:
1968 g_value_set_boolean (value, entry->visible);
1971 case PROP_HAS_FRAME:
1972 g_value_set_boolean (value, entry->has_frame);
1975 case PROP_INNER_BORDER:
1976 g_value_set_boxed (value, gtk_entry_get_inner_border (entry));
1979 case PROP_INVISIBLE_CHAR:
1980 g_value_set_uint (value, entry->invisible_char);
1983 case PROP_ACTIVATES_DEFAULT:
1984 g_value_set_boolean (value, entry->activates_default);
1987 case PROP_WIDTH_CHARS:
1988 g_value_set_int (value, entry->width_chars);
1991 case PROP_SCROLL_OFFSET:
1992 g_value_set_int (value, entry->scroll_offset);
1996 g_value_set_string (value, gtk_entry_get_text (entry));
2000 g_value_set_float (value, gtk_entry_get_alignment (entry));
2003 case PROP_TRUNCATE_MULTILINE:
2004 g_value_set_boolean (value, entry->truncate_multiline);
2007 case PROP_SHADOW_TYPE:
2008 g_value_set_enum (value, priv->shadow_type);
2011 case PROP_OVERWRITE_MODE:
2012 g_value_set_boolean (value, entry->overwrite_mode);
2015 case PROP_TEXT_LENGTH:
2016 g_value_set_uint (value, entry->text_length);
2019 case PROP_INVISIBLE_CHAR_SET:
2020 g_value_set_boolean (value, priv->invisible_char_set);
2023 case PROP_IM_MODULE:
2024 g_value_set_string (value, priv->im_module);
2027 case PROP_CAPS_LOCK_WARNING:
2028 g_value_set_boolean (value, priv->caps_lock_warning);
2031 case PROP_PROGRESS_FRACTION:
2032 g_value_set_double (value, priv->progress_fraction);
2035 case PROP_PROGRESS_PULSE_STEP:
2036 g_value_set_double (value, priv->progress_pulse_fraction);
2039 case PROP_PIXBUF_PRIMARY:
2040 g_value_set_object (value,
2041 gtk_entry_get_icon_pixbuf (entry,
2042 GTK_ENTRY_ICON_PRIMARY));
2045 case PROP_PIXBUF_SECONDARY:
2046 g_value_set_object (value,
2047 gtk_entry_get_icon_pixbuf (entry,
2048 GTK_ENTRY_ICON_SECONDARY));
2051 case PROP_STOCK_PRIMARY:
2052 g_value_set_string (value,
2053 gtk_entry_get_icon_stock (entry,
2054 GTK_ENTRY_ICON_PRIMARY));
2057 case PROP_STOCK_SECONDARY:
2058 g_value_set_string (value,
2059 gtk_entry_get_icon_stock (entry,
2060 GTK_ENTRY_ICON_SECONDARY));
2063 case PROP_ICON_NAME_PRIMARY:
2064 g_value_set_string (value,
2065 gtk_entry_get_icon_name (entry,
2066 GTK_ENTRY_ICON_PRIMARY));
2069 case PROP_ICON_NAME_SECONDARY:
2070 g_value_set_string (value,
2071 gtk_entry_get_icon_name (entry,
2072 GTK_ENTRY_ICON_SECONDARY));
2075 case PROP_GICON_PRIMARY:
2076 g_value_set_object (value,
2077 gtk_entry_get_icon_gicon (entry,
2078 GTK_ENTRY_ICON_PRIMARY));
2081 case PROP_GICON_SECONDARY:
2082 g_value_set_object (value,
2083 gtk_entry_get_icon_gicon (entry,
2084 GTK_ENTRY_ICON_SECONDARY));
2087 case PROP_STORAGE_TYPE_PRIMARY:
2088 g_value_set_enum (value,
2089 gtk_entry_get_icon_storage_type (entry,
2090 GTK_ENTRY_ICON_PRIMARY));
2093 case PROP_STORAGE_TYPE_SECONDARY:
2094 g_value_set_enum (value,
2095 gtk_entry_get_icon_storage_type (entry,
2096 GTK_ENTRY_ICON_SECONDARY));
2099 case PROP_ACTIVATABLE_PRIMARY:
2100 g_value_set_boolean (value,
2101 gtk_entry_get_icon_activatable (entry, GTK_ENTRY_ICON_PRIMARY));
2104 case PROP_ACTIVATABLE_SECONDARY:
2105 g_value_set_boolean (value,
2106 gtk_entry_get_icon_activatable (entry, GTK_ENTRY_ICON_SECONDARY));
2109 case PROP_SENSITIVE_PRIMARY:
2110 g_value_set_boolean (value,
2111 gtk_entry_get_icon_sensitive (entry, GTK_ENTRY_ICON_PRIMARY));
2114 case PROP_SENSITIVE_SECONDARY:
2115 g_value_set_boolean (value,
2116 gtk_entry_get_icon_sensitive (entry, GTK_ENTRY_ICON_SECONDARY));
2119 case PROP_TOOLTIP_TEXT_PRIMARY:
2120 g_value_take_string (value,
2121 gtk_entry_get_icon_tooltip_text (entry, GTK_ENTRY_ICON_PRIMARY));
2124 case PROP_TOOLTIP_TEXT_SECONDARY:
2125 g_value_take_string (value,
2126 gtk_entry_get_icon_tooltip_text (entry, GTK_ENTRY_ICON_SECONDARY));
2129 case PROP_TOOLTIP_MARKUP_PRIMARY:
2130 g_value_take_string (value,
2131 gtk_entry_get_icon_tooltip_markup (entry, GTK_ENTRY_ICON_PRIMARY));
2134 case PROP_TOOLTIP_MARKUP_SECONDARY:
2135 g_value_take_string (value,
2136 gtk_entry_get_icon_tooltip_markup (entry, GTK_ENTRY_ICON_SECONDARY));
2140 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2146 find_invisible_char (GtkWidget *widget)
2148 PangoLayout *layout;
2149 PangoAttrList *attr_list;
2151 gunichar invisible_chars [] = {
2152 0x25cf, /* BLACK CIRCLE */
2153 0x2022, /* BULLET */
2154 0x2731, /* HEAVY ASTERISK */
2155 0x273a /* SIXTEEN POINTED ASTERISK */
2158 layout = gtk_widget_create_pango_layout (widget, NULL);
2160 attr_list = pango_attr_list_new ();
2161 pango_attr_list_insert (attr_list, pango_attr_fallback_new (FALSE));
2163 pango_layout_set_attributes (layout, attr_list);
2164 pango_attr_list_unref (attr_list);
2166 for (i = 0; i < G_N_ELEMENTS (invisible_chars); i++)
2168 gchar text[7] = { 0, };
2171 len = g_unichar_to_utf8 (invisible_chars[i], text);
2172 pango_layout_set_text (layout, text, len);
2174 count = pango_layout_get_unknown_glyphs_count (layout);
2178 g_object_unref (layout);
2179 return invisible_chars[i];
2183 g_object_unref (layout);
2188 gtk_entry_init (GtkEntry *entry)
2190 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2192 GTK_WIDGET_SET_FLAGS (entry, GTK_CAN_FOCUS);
2194 entry->text_size = MIN_SIZE;
2195 entry->text = g_malloc (entry->text_size);
2196 entry->text[0] = '\0';
2198 entry->editable = TRUE;
2199 entry->visible = TRUE;
2200 entry->invisible_char = find_invisible_char (GTK_WIDGET (entry));
2201 entry->dnd_position = -1;
2202 entry->width_chars = -1;
2203 entry->is_cell_renderer = FALSE;
2204 entry->editing_canceled = FALSE;
2205 entry->has_frame = TRUE;
2206 entry->truncate_multiline = FALSE;
2207 priv->shadow_type = GTK_SHADOW_IN;
2209 priv->caps_lock_warning = TRUE;
2210 priv->caps_lock_warning_shown = FALSE;
2211 priv->progress_fraction = 0.0;
2212 priv->progress_pulse_fraction = 0.1;
2214 gtk_drag_dest_set (GTK_WIDGET (entry),
2215 GTK_DEST_DEFAULT_HIGHLIGHT,
2217 GDK_ACTION_COPY | GDK_ACTION_MOVE);
2218 gtk_drag_dest_add_text_targets (GTK_WIDGET (entry));
2220 /* This object is completely private. No external entity can gain a reference
2221 * to it; so we create it here and destroy it in finalize().
2223 entry->im_context = gtk_im_multicontext_new ();
2225 g_signal_connect (entry->im_context, "commit",
2226 G_CALLBACK (gtk_entry_commit_cb), entry);
2227 g_signal_connect (entry->im_context, "preedit-changed",
2228 G_CALLBACK (gtk_entry_preedit_changed_cb), entry);
2229 g_signal_connect (entry->im_context, "retrieve-surrounding",
2230 G_CALLBACK (gtk_entry_retrieve_surrounding_cb), entry);
2231 g_signal_connect (entry->im_context, "delete-surrounding",
2232 G_CALLBACK (gtk_entry_delete_surrounding_cb), entry);
2236 get_icon_width (GtkEntry *entry,
2237 GtkEntryIconPosition icon_pos)
2239 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2240 EntryIconInfo *icon_info = priv->icons[icon_pos];
2242 GtkSettings *settings;
2243 gint menu_icon_width;
2245 if (!icon_info || icon_info->pixbuf == NULL)
2248 screen = gtk_widget_get_screen (GTK_WIDGET (entry));
2249 settings = gtk_settings_get_for_screen (screen);
2251 gtk_icon_size_lookup_for_settings (settings, GTK_ICON_SIZE_MENU,
2252 &menu_icon_width, NULL);
2254 return MAX (gdk_pixbuf_get_width (icon_info->pixbuf), menu_icon_width);
2258 get_icon_allocations (GtkEntry *entry,
2259 GtkAllocation *primary,
2260 GtkAllocation *secondary)
2263 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2264 gint x, y, width, height;
2266 get_text_area_size (entry, &x, &y, &width, &height);
2269 primary->height = height;
2270 primary->width = get_icon_width (entry, GTK_ENTRY_ICON_PRIMARY);
2271 if (primary->width > 0)
2272 primary->width += 2 * priv->icon_margin;
2275 secondary->height = height;
2276 secondary->width = get_icon_width (entry, GTK_ENTRY_ICON_SECONDARY);
2277 if (secondary->width > 0)
2278 secondary->width += 2 * priv->icon_margin;
2280 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
2282 primary->x = x + width - primary->width;
2288 secondary->x = x + width - secondary->width;
2294 begin_change (GtkEntry *entry)
2296 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2298 priv->change_count++;
2302 end_change (GtkEntry *entry)
2304 GtkEditable *editable = GTK_EDITABLE (entry);
2305 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2307 g_return_if_fail (priv->change_count > 0);
2309 priv->change_count--;
2311 if (priv->change_count == 0)
2313 if (priv->real_changed)
2315 g_signal_emit_by_name (editable, "changed");
2316 priv->real_changed = FALSE;
2322 emit_changed (GtkEntry *entry)
2324 GtkEditable *editable = GTK_EDITABLE (entry);
2325 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2327 if (priv->change_count == 0)
2328 g_signal_emit_by_name (editable, "changed");
2330 priv->real_changed = TRUE;
2334 * Overwrite a memory that might contain sensitive information.
2337 trash_area (gchar *area, gsize len)
2339 volatile gchar *varea = (volatile gchar *)area;
2345 gtk_entry_destroy (GtkObject *object)
2347 GtkEntry *entry = GTK_ENTRY (object);
2350 entry->current_pos = entry->selection_bound = entry->text_length = 0;
2351 _gtk_entry_reset_im_context (entry);
2352 gtk_entry_reset_layout (entry);
2354 if (entry->blink_timeout)
2356 g_source_remove (entry->blink_timeout);
2357 entry->blink_timeout = 0;
2360 if (entry->recompute_idle)
2362 g_source_remove (entry->recompute_idle);
2363 entry->recompute_idle = 0;
2366 if (!entry->visible)
2368 /* We want to trash the text here because the entry might be leaked. */
2369 trash_area (entry->text, strlen (entry->text));
2372 GTK_OBJECT_CLASS (gtk_entry_parent_class)->destroy (object);
2376 gtk_entry_dispose (GObject *object)
2378 GtkEntry *entry = GTK_ENTRY (object);
2380 gtk_entry_set_icon_from_pixbuf (entry, GTK_ENTRY_ICON_PRIMARY, NULL);
2381 gtk_entry_set_icon_tooltip_markup (entry, GTK_ENTRY_ICON_PRIMARY, NULL);
2382 gtk_entry_set_icon_from_pixbuf (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
2383 gtk_entry_set_icon_tooltip_markup (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
2385 G_OBJECT_CLASS (gtk_entry_parent_class)->dispose (object);
2389 gtk_entry_finalize (GObject *object)
2391 GtkEntry *entry = GTK_ENTRY (object);
2392 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2393 EntryIconInfo *icon_info = NULL;
2396 for (i = 0; i < MAX_ICONS; i++)
2398 if ((icon_info = priv->icons[i]) != NULL)
2400 if (icon_info->target_list != NULL)
2402 gtk_target_list_unref (icon_info->target_list);
2403 icon_info->target_list = NULL;
2406 g_slice_free (EntryIconInfo, icon_info);
2407 priv->icons[i] = NULL;
2411 gtk_entry_set_completion (entry, NULL);
2413 if (entry->cached_layout)
2414 g_object_unref (entry->cached_layout);
2416 g_object_unref (entry->im_context);
2418 if (entry->blink_timeout)
2419 g_source_remove (entry->blink_timeout);
2421 if (entry->recompute_idle)
2422 g_source_remove (entry->recompute_idle);
2424 entry->text_size = 0;
2428 if (!entry->visible)
2429 trash_area (entry->text, strlen (entry->text));
2430 g_free (entry->text);
2434 g_free (priv->im_module);
2436 G_OBJECT_CLASS (gtk_entry_parent_class)->finalize (object);
2440 update_cursors (GtkWidget *widget)
2442 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2443 EntryIconInfo *icon_info = NULL;
2444 GdkDisplay *display;
2448 for (i = 0; i < MAX_ICONS; i++)
2450 if ((icon_info = priv->icons[i]) != NULL)
2452 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
2453 gdk_window_show_unraised (icon_info->window);
2455 /* The icon windows are not children of the visible entry window,
2456 * thus we can't just inherit the xterm cursor. Slight complication
2457 * here is that for the entry, insensitive => arrow cursor, but for
2458 * an icon in a sensitive entry, insensitive => xterm cursor.
2460 if (GTK_WIDGET_IS_SENSITIVE (widget) &&
2461 (icon_info->insensitive ||
2462 (icon_info->nonactivatable && icon_info->target_list == NULL)))
2464 display = gtk_widget_get_display (widget);
2465 cursor = gdk_cursor_new_for_display (display, GDK_XTERM);
2466 gdk_window_set_cursor (icon_info->window, cursor);
2467 gdk_cursor_unref (cursor);
2471 gdk_window_set_cursor (icon_info->window, NULL);
2478 realize_icon_info (GtkWidget *widget,
2479 GtkEntryIconPosition icon_pos)
2481 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2482 EntryIconInfo *icon_info = priv->icons[icon_pos];
2483 GdkWindowAttr attributes;
2484 gint attributes_mask;
2486 g_return_if_fail (icon_info != NULL);
2490 attributes.width = 1;
2491 attributes.height = 1;
2492 attributes.window_type = GDK_WINDOW_CHILD;
2493 attributes.wclass = GDK_INPUT_OUTPUT;
2494 attributes.visual = gtk_widget_get_visual (widget);
2495 attributes.colormap = gtk_widget_get_colormap (widget);
2496 attributes.event_mask = gtk_widget_get_events (widget);
2497 attributes.event_mask |= (GDK_EXPOSURE_MASK |
2498 GDK_BUTTON_PRESS_MASK |
2499 GDK_BUTTON_RELEASE_MASK |
2500 GDK_BUTTON1_MOTION_MASK |
2501 GDK_BUTTON3_MOTION_MASK |
2502 GDK_POINTER_MOTION_HINT_MASK |
2503 GDK_POINTER_MOTION_MASK |
2504 GDK_ENTER_NOTIFY_MASK |
2505 GDK_LEAVE_NOTIFY_MASK);
2506 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
2508 icon_info->window = gdk_window_new (widget->window,
2511 gdk_window_set_user_data (icon_info->window, widget);
2512 gdk_window_set_background (icon_info->window,
2513 &widget->style->base[GTK_WIDGET_STATE (widget)]);
2515 gtk_widget_queue_resize (widget);
2518 static EntryIconInfo*
2519 construct_icon_info (GtkWidget *widget,
2520 GtkEntryIconPosition icon_pos)
2522 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2523 EntryIconInfo *icon_info;
2525 g_return_val_if_fail (priv->icons[icon_pos] == NULL, NULL);
2527 icon_info = g_slice_new0 (EntryIconInfo);
2528 priv->icons[icon_pos] = icon_info;
2530 if (GTK_WIDGET_REALIZED (widget))
2531 realize_icon_info (widget, icon_pos);
2533 if (GTK_WIDGET_MAPPED (widget))
2534 gdk_window_show_unraised (icon_info->window);
2540 gtk_entry_map (GtkWidget *widget)
2542 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2543 EntryIconInfo *icon_info = NULL;
2546 if (GTK_WIDGET_REALIZED (widget) && !GTK_WIDGET_MAPPED (widget))
2548 GTK_WIDGET_CLASS (gtk_entry_parent_class)->map (widget);
2550 for (i = 0; i < MAX_ICONS; i++)
2552 if ((icon_info = priv->icons[i]) != NULL)
2554 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
2555 gdk_window_show (icon_info->window);
2559 update_cursors (widget);
2564 gtk_entry_unmap (GtkWidget *widget)
2566 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2567 EntryIconInfo *icon_info = NULL;
2570 if (GTK_WIDGET_MAPPED (widget))
2572 for (i = 0; i < MAX_ICONS; i++)
2574 if ((icon_info = priv->icons[i]) != NULL)
2576 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
2577 gdk_window_hide (icon_info->window);
2581 GTK_WIDGET_CLASS (gtk_entry_parent_class)->unmap (widget);
2586 gtk_entry_realize (GtkWidget *widget)
2589 GtkEntryPrivate *priv;
2590 EntryIconInfo *icon_info;
2591 GdkWindowAttr attributes;
2592 gint attributes_mask;
2595 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
2596 entry = GTK_ENTRY (widget);
2597 priv = GTK_ENTRY_GET_PRIVATE (entry);
2599 attributes.window_type = GDK_WINDOW_CHILD;
2601 get_widget_window_size (entry, &attributes.x, &attributes.y, &attributes.width, &attributes.height);
2603 attributes.wclass = GDK_INPUT_OUTPUT;
2604 attributes.visual = gtk_widget_get_visual (widget);
2605 attributes.colormap = gtk_widget_get_colormap (widget);
2606 attributes.event_mask = gtk_widget_get_events (widget);
2607 attributes.event_mask |= (GDK_EXPOSURE_MASK |
2608 GDK_BUTTON_PRESS_MASK |
2609 GDK_BUTTON_RELEASE_MASK |
2610 GDK_BUTTON1_MOTION_MASK |
2611 GDK_BUTTON3_MOTION_MASK |
2612 GDK_POINTER_MOTION_HINT_MASK |
2613 GDK_POINTER_MOTION_MASK |
2614 GDK_ENTER_NOTIFY_MASK |
2615 GDK_LEAVE_NOTIFY_MASK);
2616 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
2618 widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, attributes_mask);
2619 gdk_window_set_user_data (widget->window, entry);
2621 get_text_area_size (entry, &attributes.x, &attributes.y, &attributes.width, &attributes.height);
2623 if (GTK_WIDGET_IS_SENSITIVE (widget))
2625 attributes.cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
2626 attributes_mask |= GDK_WA_CURSOR;
2629 entry->text_area = gdk_window_new (widget->window, &attributes, attributes_mask);
2631 gdk_window_set_user_data (entry->text_area, entry);
2633 if (attributes_mask & GDK_WA_CURSOR)
2634 gdk_cursor_unref (attributes.cursor);
2636 widget->style = gtk_style_attach (widget->style, widget->window);
2638 gdk_window_set_background (widget->window, &widget->style->base[GTK_WIDGET_STATE (widget)]);
2639 gdk_window_set_background (entry->text_area, &widget->style->base[GTK_WIDGET_STATE (widget)]);
2641 gdk_window_show (entry->text_area);
2643 gtk_im_context_set_client_window (entry->im_context, entry->text_area);
2645 gtk_entry_adjust_scroll (entry);
2646 gtk_entry_update_primary_selection (entry);
2649 /* If the icon positions are already setup, create their windows.
2650 * Otherwise if they don't exist yet, then construct_icon_info()
2651 * will create the windows once the widget is already realized.
2653 for (i = 0; i < MAX_ICONS; i++)
2655 if ((icon_info = priv->icons[i]) != NULL)
2657 if (icon_info->window == NULL)
2658 realize_icon_info (widget, i);
2664 gtk_entry_unrealize (GtkWidget *widget)
2666 GtkEntry *entry = GTK_ENTRY (widget);
2667 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2668 GtkClipboard *clipboard;
2669 EntryIconInfo *icon_info;
2672 gtk_entry_reset_layout (entry);
2674 gtk_im_context_set_client_window (entry->im_context, NULL);
2676 clipboard = gtk_widget_get_clipboard (widget, GDK_SELECTION_PRIMARY);
2677 if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (entry))
2678 gtk_clipboard_clear (clipboard);
2680 if (entry->text_area)
2682 gdk_window_set_user_data (entry->text_area, NULL);
2683 gdk_window_destroy (entry->text_area);
2684 entry->text_area = NULL;
2687 if (entry->popup_menu)
2689 gtk_widget_destroy (entry->popup_menu);
2690 entry->popup_menu = NULL;
2693 GTK_WIDGET_CLASS (gtk_entry_parent_class)->unrealize (widget);
2695 for (i = 0; i < MAX_ICONS; i++)
2697 if ((icon_info = priv->icons[i]) != NULL)
2699 if (icon_info->window != NULL)
2701 gdk_window_destroy (icon_info->window);
2702 icon_info->window = NULL;
2709 _gtk_entry_get_borders (GtkEntry *entry,
2713 GtkWidget *widget = GTK_WIDGET (entry);
2714 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2716 if (entry->has_frame)
2718 *xborder = widget->style->xthickness;
2719 *yborder = widget->style->ythickness;
2727 if (!priv->interior_focus)
2729 *xborder += priv->focus_width;
2730 *yborder += priv->focus_width;
2735 gtk_entry_size_request (GtkWidget *widget,
2736 GtkRequisition *requisition)
2738 GtkEntry *entry = GTK_ENTRY (widget);
2739 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2740 PangoFontMetrics *metrics;
2741 gint xborder, yborder;
2742 GtkBorder inner_border;
2743 PangoContext *context;
2744 int icon_widths = 0;
2747 gtk_widget_ensure_style (widget);
2748 context = gtk_widget_get_pango_context (widget);
2749 metrics = pango_context_get_metrics (context,
2750 widget->style->font_desc,
2751 pango_context_get_language (context));
2753 entry->ascent = pango_font_metrics_get_ascent (metrics);
2754 entry->descent = pango_font_metrics_get_descent (metrics);
2756 _gtk_entry_get_borders (entry, &xborder, &yborder);
2757 _gtk_entry_effective_inner_border (entry, &inner_border);
2759 if (entry->width_chars < 0)
2760 requisition->width = MIN_ENTRY_WIDTH + xborder * 2 + inner_border.left + inner_border.right;
2763 gint char_width = pango_font_metrics_get_approximate_char_width (metrics);
2764 gint digit_width = pango_font_metrics_get_approximate_digit_width (metrics);
2765 gint char_pixels = (MAX (char_width, digit_width) + PANGO_SCALE - 1) / PANGO_SCALE;
2767 requisition->width = char_pixels * entry->width_chars + xborder * 2 + inner_border.left + inner_border.right;
2770 requisition->height = PANGO_PIXELS (entry->ascent + entry->descent) + yborder * 2 + inner_border.top + inner_border.bottom;
2772 for (i = 0; i < MAX_ICONS; i++)
2774 icon_width = get_icon_width (entry, i);
2776 icon_widths += icon_width + 2 * priv->icon_margin;
2779 if (icon_widths > requisition->width)
2780 requisition->width += icon_widths;
2782 pango_font_metrics_unref (metrics);
2786 place_windows (GtkEntry *entry)
2789 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2790 gint x, y, width, height;
2791 GtkAllocation primary;
2792 GtkAllocation secondary;
2793 EntryIconInfo *icon_info = NULL;
2795 get_text_area_size (entry, &x, &y, &width, &height);
2797 get_icon_allocations (entry, &primary, &secondary);
2799 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
2800 x += secondary.width;
2803 width -= primary.width + secondary.width;
2805 if ((icon_info = priv->icons[GTK_ENTRY_ICON_PRIMARY]) != NULL)
2806 gdk_window_move_resize (icon_info->window,
2807 primary.x, primary.y,
2808 primary.width, primary.height);
2810 if ((icon_info = priv->icons[GTK_ENTRY_ICON_SECONDARY]) != NULL)
2811 gdk_window_move_resize (icon_info->window,
2812 secondary.x, secondary.y,
2813 secondary.width, secondary.height);
2815 gdk_window_move_resize (GTK_ENTRY (entry)->text_area, x, y, width, height);
2819 gtk_entry_get_text_area_size (GtkEntry *entry,
2825 GtkWidget *widget = GTK_WIDGET (entry);
2826 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2828 gint xborder, yborder;
2829 GtkRequisition requisition;
2831 gtk_widget_get_child_requisition (widget, &requisition);
2832 _gtk_entry_get_borders (entry, &xborder, &yborder);
2834 if (GTK_WIDGET_REALIZED (widget))
2835 gdk_drawable_get_size (widget->window, NULL, &frame_height);
2837 frame_height = requisition.height;
2839 if (GTK_WIDGET_HAS_FOCUS (widget) && !priv->interior_focus)
2840 frame_height -= 2 * priv->focus_width;
2846 *y = frame_height / 2 - (requisition.height - yborder * 2) / 2;
2849 *width = GTK_WIDGET (entry)->allocation.width - xborder * 2;
2852 *height = requisition.height - yborder * 2;
2856 get_text_area_size (GtkEntry *entry,
2862 GtkEntryClass *class;
2864 g_return_if_fail (GTK_IS_ENTRY (entry));
2866 class = GTK_ENTRY_GET_CLASS (entry);
2868 if (class->get_text_area_size)
2869 class->get_text_area_size (entry, x, y, width, height);
2874 get_widget_window_size (GtkEntry *entry,
2880 GtkRequisition requisition;
2881 GtkWidget *widget = GTK_WIDGET (entry);
2883 gtk_widget_get_child_requisition (widget, &requisition);
2886 *x = widget->allocation.x;
2890 if (entry->is_cell_renderer)
2891 *y = widget->allocation.y;
2893 *y = widget->allocation.y + (widget->allocation.height - requisition.height) / 2;
2897 *width = widget->allocation.width;
2901 if (entry->is_cell_renderer)
2902 *height = widget->allocation.height;
2904 *height = requisition.height;
2909 _gtk_entry_effective_inner_border (GtkEntry *entry,
2912 GtkBorder *tmp_border;
2914 tmp_border = g_object_get_qdata (G_OBJECT (entry), quark_inner_border);
2918 *border = *tmp_border;
2922 gtk_widget_style_get (GTK_WIDGET (entry), "inner-border", &tmp_border, NULL);
2926 *border = *tmp_border;
2927 gtk_border_free (tmp_border);
2931 *border = default_inner_border;
2935 gtk_entry_size_allocate (GtkWidget *widget,
2936 GtkAllocation *allocation)
2938 GtkEntry *entry = GTK_ENTRY (widget);
2940 widget->allocation = *allocation;
2942 if (GTK_WIDGET_REALIZED (widget))
2944 /* We call gtk_widget_get_child_requisition, since we want (for
2945 * backwards compatibility reasons) the realization here to
2946 * be affected by the usize of the entry, if set
2948 gint x, y, width, height;
2949 GtkEntryCompletion* completion;
2951 get_widget_window_size (entry, &x, &y, &width, &height);
2952 gdk_window_move_resize (widget->window, x, y, width, height);
2954 place_windows (entry);
2955 gtk_entry_recompute (entry);
2957 completion = gtk_entry_get_completion (entry);
2958 if (completion && GTK_WIDGET_MAPPED (completion->priv->popup_window))
2959 _gtk_entry_completion_resize_popup (completion);
2963 /* Kudos to the gnome-panel guys. */
2965 colorshift_pixbuf (GdkPixbuf *dest,
2970 gint width, height, has_alpha, src_rowstride, dest_rowstride;
2971 guchar *target_pixels;
2972 guchar *original_pixels;
2978 has_alpha = gdk_pixbuf_get_has_alpha (src);
2979 width = gdk_pixbuf_get_width (src);
2980 height = gdk_pixbuf_get_height (src);
2981 src_rowstride = gdk_pixbuf_get_rowstride (src);
2982 dest_rowstride = gdk_pixbuf_get_rowstride (dest);
2983 original_pixels = gdk_pixbuf_get_pixels (src);
2984 target_pixels = gdk_pixbuf_get_pixels (dest);
2986 for (i = 0; i < height; i++)
2988 pix_dest = target_pixels + i * dest_rowstride;
2989 pix_src = original_pixels + i * src_rowstride;
2991 for (j = 0; j < width; j++)
2998 *(pix_dest++) = CLAMP (val, 0, 255);
3001 *(pix_dest++) = CLAMP (val, 0, 255);
3004 *(pix_dest++) = CLAMP (val, 0, 255);
3007 *(pix_dest++) = *(pix_src++);
3013 should_prelight (GtkEntry *entry,
3014 GtkEntryIconPosition icon_pos)
3016 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3017 EntryIconInfo *icon_info = priv->icons[icon_pos];
3023 if (icon_info->nonactivatable && icon_info->target_list == NULL)
3026 if (icon_info->pressed)
3029 gtk_widget_style_get (GTK_WIDGET (entry),
3030 "icon-prelight", &prelight,
3037 draw_icon (GtkWidget *widget,
3038 GtkEntryIconPosition icon_pos)
3040 GtkEntry *entry = GTK_ENTRY (widget);
3041 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3042 EntryIconInfo *icon_info = priv->icons[icon_pos];
3044 gint x, y, width, height;
3049 gtk_entry_ensure_pixbuf (entry, icon_pos);
3051 if (icon_info->pixbuf == NULL)
3054 gdk_drawable_get_size (icon_info->window, &width, &height);
3056 /* size_allocate hasn't been called yet. These are the default values.
3058 if (width == 1 || height == 1)
3061 pixbuf = icon_info->pixbuf;
3062 g_object_ref (pixbuf);
3064 if (gdk_pixbuf_get_height (pixbuf) > height)
3066 GdkPixbuf *temp_pixbuf;
3069 scale = height - 2 * priv->icon_margin;
3070 temp_pixbuf = gdk_pixbuf_scale_simple (pixbuf, scale, scale,
3071 GDK_INTERP_BILINEAR);
3072 g_object_unref (pixbuf);
3073 pixbuf = temp_pixbuf;
3076 x = (width - gdk_pixbuf_get_width (pixbuf)) / 2;
3077 y = (height - gdk_pixbuf_get_height (pixbuf)) / 2;
3079 if (!GTK_WIDGET_IS_SENSITIVE (widget) ||
3080 icon_info->insensitive)
3082 GdkPixbuf *temp_pixbuf;
3084 temp_pixbuf = gdk_pixbuf_copy (pixbuf);
3085 gdk_pixbuf_saturate_and_pixelate (pixbuf,
3089 g_object_unref (pixbuf);
3090 pixbuf = temp_pixbuf;
3092 else if (icon_info->prelight)
3094 GdkPixbuf *temp_pixbuf;
3096 temp_pixbuf = gdk_pixbuf_copy (pixbuf);
3097 colorshift_pixbuf (temp_pixbuf, pixbuf, 30);
3098 g_object_unref (pixbuf);
3099 pixbuf = temp_pixbuf;
3102 gdk_draw_pixbuf (icon_info->window, widget->style->black_gc, pixbuf,
3104 GDK_RGB_DITHER_NORMAL, 0, 0);
3106 g_object_unref (pixbuf);
3111 gtk_entry_draw_frame (GtkWidget *widget,
3112 GdkEventExpose *event)
3114 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
3115 gint x = 0, y = 0, width, height;
3116 gboolean state_hint;
3119 gdk_drawable_get_size (widget->window, &width, &height);
3121 /* Fix a problem with some themes which assume that entry->text_area's
3122 * width equals widget->window's width */
3123 if (GTK_IS_SPIN_BUTTON (widget))
3125 gint xborder, yborder;
3127 gtk_entry_get_text_area_size (GTK_ENTRY (widget), &x, NULL, &width, NULL);
3128 _gtk_entry_get_borders (GTK_ENTRY (widget), &xborder, &yborder);
3131 width += xborder * 2;
3134 if (GTK_WIDGET_HAS_FOCUS (widget) && !priv->interior_focus)
3136 x += priv->focus_width;
3137 y += priv->focus_width;
3138 width -= 2 * priv->focus_width;
3139 height -= 2 * priv->focus_width;
3142 gtk_widget_style_get (widget, "state-hint", &state_hint, NULL);
3144 state = GTK_WIDGET_HAS_FOCUS (widget) ?
3145 GTK_STATE_ACTIVE : GTK_WIDGET_STATE (widget);
3147 state = GTK_STATE_NORMAL;
3149 gtk_paint_shadow (widget->style, widget->window,
3150 state, priv->shadow_type,
3151 &event->area, widget, "entry", x, y, width, height);
3154 gtk_entry_draw_progress (widget, event);
3156 if (GTK_WIDGET_HAS_FOCUS (widget) && !priv->interior_focus)
3158 x -= priv->focus_width;
3159 y -= priv->focus_width;
3160 width += 2 * priv->focus_width;
3161 height += 2 * priv->focus_width;
3163 gtk_paint_focus (widget->style, widget->window, GTK_WIDGET_STATE (widget),
3164 &event->area, widget, "entry",
3165 0, 0, width, height);
3170 gtk_entry_get_progress_border (GtkWidget *widget,
3171 GtkBorder *progress_border)
3173 GtkBorder *tmp_border;
3175 gtk_widget_style_get (widget, "progress-border", &tmp_border, NULL);
3178 *progress_border = *tmp_border;
3179 gtk_border_free (tmp_border);
3183 progress_border->left = widget->style->xthickness;
3184 progress_border->right = widget->style->xthickness;
3185 progress_border->top = widget->style->ythickness;
3186 progress_border->bottom = widget->style->ythickness;
3191 get_progress_area (GtkWidget *widget,
3197 GtkEntryPrivate *private = GTK_ENTRY_GET_PRIVATE (widget);
3198 GtkEntry *entry = GTK_ENTRY (widget);
3199 GtkBorder progress_border;
3201 gtk_entry_get_progress_border (widget, &progress_border);
3203 *x = progress_border.left;
3204 *y = progress_border.top;
3206 gdk_drawable_get_size (widget->window, width, height);
3208 *width -= progress_border.left + progress_border.right;
3209 *height -= progress_border.top + progress_border.bottom;
3211 if (GTK_WIDGET_HAS_FOCUS (widget) && !private->interior_focus)
3213 *x += private->focus_width;
3214 *y += private->focus_width;
3215 *width -= 2 * private->focus_width;
3216 *height -= 2 * private->focus_width;
3219 if (private->progress_pulse_mode)
3221 gdouble value = private->progress_pulse_current;
3223 *x += (gint) floor(value * (*width));
3224 *width = (gint) ceil(private->progress_pulse_fraction * (*width));
3226 else if (private->progress_fraction > 0)
3228 gdouble value = private->progress_fraction;
3230 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
3234 bar_width = floor(value * (*width) + 0.5);
3235 *x += *width - bar_width;
3240 *width = (gint) floor(value * (*width) + 0.5);
3251 gtk_entry_draw_progress (GtkWidget *widget,
3252 GdkEventExpose *event)
3254 gint x, y, width, height;
3257 get_progress_area (widget, &x, &y, &width, &height);
3259 if ((width <= 0) || (height <= 0))
3262 if (event->window != widget->window)
3266 gdk_window_get_position (event->window, &pos_x, &pos_y);
3272 state = GTK_STATE_SELECTED;
3273 if (!GTK_WIDGET_SENSITIVE (widget))
3274 state = GTK_STATE_INSENSITIVE;
3276 gtk_paint_box (widget->style, event->window,
3277 state, GTK_SHADOW_OUT,
3278 &event->area, widget, "entry-progress",
3284 gtk_entry_expose (GtkWidget *widget,
3285 GdkEventExpose *event)
3287 GtkEntry *entry = GTK_ENTRY (widget);
3288 gboolean state_hint;
3290 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3292 gtk_widget_style_get (widget, "state-hint", &state_hint, NULL);
3294 state = GTK_WIDGET_HAS_FOCUS (widget) ?
3295 GTK_STATE_ACTIVE : GTK_WIDGET_STATE (widget);
3297 state = GTK_WIDGET_STATE(widget);
3299 if (widget->window == event->window)
3301 gtk_entry_draw_frame (widget, event);
3303 else if (entry->text_area == event->window)
3307 gdk_drawable_get_size (entry->text_area, &width, &height);
3309 gtk_paint_flat_box (widget->style, entry->text_area,
3310 state, GTK_SHADOW_NONE,
3311 &event->area, widget, "entry_bg",
3312 0, 0, width, height);
3314 gtk_entry_draw_progress (widget, event);
3316 if (entry->dnd_position != -1)
3317 gtk_entry_draw_cursor (GTK_ENTRY (widget), CURSOR_DND);
3319 gtk_entry_draw_text (GTK_ENTRY (widget));
3321 if ((entry->visible || entry->invisible_char != 0) &&
3322 GTK_WIDGET_HAS_FOCUS (widget) &&
3323 entry->selection_bound == entry->current_pos && entry->cursor_visible)
3324 gtk_entry_draw_cursor (GTK_ENTRY (widget), CURSOR_STANDARD);
3330 for (i = 0; i < MAX_ICONS; i++)
3332 EntryIconInfo *icon_info = priv->icons[i];
3334 if (icon_info != NULL && event->window == icon_info->window)
3338 gdk_drawable_get_size (icon_info->window, &width, &height);
3340 gtk_paint_flat_box (widget->style, icon_info->window,
3341 GTK_WIDGET_STATE (widget), GTK_SHADOW_NONE,
3342 NULL, widget, "entry_bg",
3343 0, 0, width, height);
3345 gtk_entry_draw_progress (widget, event);
3346 draw_icon (widget, i);
3357 gtk_entry_enter_notify (GtkWidget *widget,
3358 GdkEventCrossing *event)
3360 GtkEntry *entry = GTK_ENTRY (widget);
3361 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3364 for (i = 0; i < MAX_ICONS; i++)
3366 EntryIconInfo *icon_info = priv->icons[i];
3368 if (icon_info != NULL && event->window == icon_info->window)
3370 if (should_prelight (entry, i))
3372 icon_info->prelight = TRUE;
3373 gtk_widget_queue_draw (widget);
3384 gtk_entry_leave_notify (GtkWidget *widget,
3385 GdkEventCrossing *event)
3387 GtkEntry *entry = GTK_ENTRY (widget);
3388 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3391 for (i = 0; i < MAX_ICONS; i++)
3393 EntryIconInfo *icon_info = priv->icons[i];
3395 if (icon_info != NULL && event->window == icon_info->window)
3397 if (should_prelight (entry, i))
3399 icon_info->prelight = FALSE;
3400 gtk_widget_queue_draw (widget);
3411 gtk_entry_get_pixel_ranges (GtkEntry *entry,
3415 gint start_char, end_char;
3417 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start_char, &end_char))
3419 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
3420 PangoLayoutLine *line = pango_layout_get_lines_readonly (layout)->data;
3421 const char *text = pango_layout_get_text (layout);
3422 gint start_index = g_utf8_offset_to_pointer (text, start_char) - text;
3423 gint end_index = g_utf8_offset_to_pointer (text, end_char) - text;
3424 gint real_n_ranges, i;
3426 pango_layout_line_get_x_ranges (line, start_index, end_index, ranges, &real_n_ranges);
3432 for (i = 0; i < real_n_ranges; ++i)
3434 r[2 * i + 1] = (r[2 * i + 1] - r[2 * i]) / PANGO_SCALE;
3435 r[2 * i] = r[2 * i] / PANGO_SCALE;
3440 *n_ranges = real_n_ranges;
3452 in_selection (GtkEntry *entry,
3457 gint retval = FALSE;
3459 gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
3461 for (i = 0; i < n_ranges; ++i)
3463 if (x >= ranges[2 * i] && x < ranges[2 * i] + ranges[2 * i + 1])
3475 gtk_entry_button_press (GtkWidget *widget,
3476 GdkEventButton *event)
3478 GtkEntry *entry = GTK_ENTRY (widget);
3479 GtkEditable *editable = GTK_EDITABLE (widget);
3480 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3481 EntryIconInfo *icon_info = NULL;
3483 gint sel_start, sel_end;
3486 for (i = 0; i < MAX_ICONS; i++)
3488 icon_info = priv->icons[i];
3490 if (!icon_info || icon_info->insensitive)
3493 if (event->window == icon_info->window)
3495 if (should_prelight (entry, i))
3497 icon_info->prelight = FALSE;
3498 gtk_widget_queue_draw (widget);
3501 priv->start_x = event->x;
3502 priv->start_y = event->y;
3503 icon_info->pressed = TRUE;
3505 if (!icon_info->nonactivatable)
3506 g_signal_emit (entry, signals[ICON_PRESS], 0, i, event);
3512 if (event->window != entry->text_area ||
3513 (entry->button && event->button != entry->button))
3516 gtk_entry_reset_blink_time (entry);
3518 entry->button = event->button;
3520 if (!GTK_WIDGET_HAS_FOCUS (widget))
3522 entry->in_click = TRUE;
3523 gtk_widget_grab_focus (widget);
3524 entry->in_click = FALSE;
3527 tmp_pos = gtk_entry_find_position (entry, event->x + entry->scroll_offset);
3529 if (event->button == 1)
3531 gboolean have_selection = gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end);
3533 entry->select_words = FALSE;
3534 entry->select_lines = FALSE;
3536 if (event->state & GDK_SHIFT_MASK)
3538 _gtk_entry_reset_im_context (entry);
3540 if (!have_selection) /* select from the current position to the clicked position */
3541 sel_start = sel_end = entry->current_pos;
3543 if (tmp_pos > sel_start && tmp_pos < sel_end)
3545 /* Truncate current selection, but keep it as big as possible */
3546 if (tmp_pos - sel_start > sel_end - tmp_pos)
3547 gtk_entry_set_positions (entry, sel_start, tmp_pos);
3549 gtk_entry_set_positions (entry, tmp_pos, sel_end);
3553 gboolean extend_to_left;
3556 /* Figure out what click selects and extend current selection */
3557 switch (event->type)
3559 case GDK_BUTTON_PRESS:
3560 gtk_entry_set_positions (entry, tmp_pos, tmp_pos);
3563 case GDK_2BUTTON_PRESS:
3564 entry->select_words = TRUE;
3565 gtk_entry_select_word (entry);
3568 case GDK_3BUTTON_PRESS:
3569 entry->select_lines = TRUE;
3570 gtk_entry_select_line (entry);
3577 start = MIN (entry->current_pos, entry->selection_bound);
3578 start = MIN (sel_start, start);
3580 end = MAX (entry->current_pos, entry->selection_bound);
3581 end = MAX (sel_end, end);
3583 if (tmp_pos == sel_start || tmp_pos == sel_end)
3584 extend_to_left = (tmp_pos == start);
3586 extend_to_left = (end == sel_end);
3589 gtk_entry_set_positions (entry, start, end);
3591 gtk_entry_set_positions (entry, end, start);
3594 else /* no shift key */
3595 switch (event->type)
3597 case GDK_BUTTON_PRESS:
3598 if (in_selection (entry, event->x + entry->scroll_offset))
3600 /* Click inside the selection - we'll either start a drag, or
3601 * clear the selection
3603 entry->in_drag = TRUE;
3604 entry->drag_start_x = event->x + entry->scroll_offset;
3605 entry->drag_start_y = event->y;
3608 gtk_editable_set_position (editable, tmp_pos);
3611 case GDK_2BUTTON_PRESS:
3612 /* We ALWAYS receive a GDK_BUTTON_PRESS immediately before
3613 * receiving a GDK_2BUTTON_PRESS so we need to reset
3614 * entry->in_drag which may have been set above
3616 entry->in_drag = FALSE;
3617 entry->select_words = TRUE;
3618 gtk_entry_select_word (entry);
3621 case GDK_3BUTTON_PRESS:
3622 /* We ALWAYS receive a GDK_BUTTON_PRESS immediately before
3623 * receiving a GDK_3BUTTON_PRESS so we need to reset
3624 * entry->in_drag which may have been set above
3626 entry->in_drag = FALSE;
3627 entry->select_lines = TRUE;
3628 gtk_entry_select_line (entry);
3637 else if (event->button == 2 && event->type == GDK_BUTTON_PRESS)
3639 if (entry->editable)
3641 priv->insert_pos = tmp_pos;
3642 gtk_entry_paste (entry, GDK_SELECTION_PRIMARY);
3647 gtk_widget_error_bell (widget);
3650 else if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
3652 gtk_entry_do_popup (entry, event);
3653 entry->button = 0; /* Don't wait for release, since the menu will gtk_grab_add */
3662 gtk_entry_button_release (GtkWidget *widget,
3663 GdkEventButton *event)
3665 GtkEntry *entry = GTK_ENTRY (widget);
3666 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
3667 EntryIconInfo *icon_info = NULL;
3670 for (i = 0; i < MAX_ICONS; i++)
3672 icon_info = priv->icons[i];
3674 if (!icon_info || icon_info->insensitive)
3677 if (event->window == icon_info->window)
3681 gdk_drawable_get_size (icon_info->window, &width, &height);
3683 icon_info->pressed = FALSE;
3685 if (should_prelight (entry, i) &&
3686 event->x >= 0 && event->y >= 0 &&
3687 event->x < width && event->y < height)
3689 icon_info->prelight = TRUE;
3690 gtk_widget_queue_draw (widget);
3693 if (!icon_info->nonactivatable)
3694 g_signal_emit (entry, signals[ICON_RELEASE], 0, i, event);
3700 if (event->window != entry->text_area || entry->button != event->button)
3705 gint tmp_pos = gtk_entry_find_position (entry, entry->drag_start_x);
3707 gtk_editable_set_position (GTK_EDITABLE (entry), tmp_pos);
3714 gtk_entry_update_primary_selection (entry);
3720 _gtk_entry_get_selected_text (GtkEntry *entry)
3722 GtkEditable *editable = GTK_EDITABLE (entry);
3723 gint start_text, end_text;
3726 if (gtk_editable_get_selection_bounds (editable, &start_text, &end_text))
3727 text = gtk_editable_get_chars (editable, start_text, end_text);
3733 gtk_entry_motion_notify (GtkWidget *widget,
3734 GdkEventMotion *event)
3736 GtkEntry *entry = GTK_ENTRY (widget);
3737 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3738 EntryIconInfo *icon_info = NULL;
3739 GdkDragContext *context;
3743 for (i = 0; i < MAX_ICONS; i++)
3745 icon_info = priv->icons[i];
3747 if (!icon_info || icon_info->insensitive)
3750 if (event->window == icon_info->window)
3752 if (icon_info->pressed &&
3753 icon_info->target_list != NULL &&
3754 gtk_drag_check_threshold (widget,
3760 icon_info->in_drag = TRUE;
3761 icon_info->pressed = FALSE;
3762 context = gtk_drag_begin (widget,
3763 icon_info->target_list,
3773 if (entry->mouse_cursor_obscured)
3777 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
3778 gdk_window_set_cursor (entry->text_area, cursor);
3779 gdk_cursor_unref (cursor);
3780 entry->mouse_cursor_obscured = FALSE;
3783 if (event->window != entry->text_area || entry->button != 1)
3786 if (entry->select_lines)
3789 gdk_event_request_motions (event);
3793 if (entry->visible &&
3794 gtk_drag_check_threshold (widget,
3795 entry->drag_start_x, entry->drag_start_y,
3796 event->x + entry->scroll_offset, event->y))
3798 GdkDragContext *context;
3799 GtkTargetList *target_list = gtk_target_list_new (NULL, 0);
3800 guint actions = entry->editable ? GDK_ACTION_COPY | GDK_ACTION_MOVE : GDK_ACTION_COPY;
3802 GdkPixmap *pixmap = NULL;
3804 gtk_target_list_add_text_targets (target_list, 0);
3806 text = _gtk_entry_get_selected_text (entry);
3807 pixmap = _gtk_text_util_create_drag_icon (widget, text, -1);
3809 context = gtk_drag_begin (widget, target_list, actions,
3810 entry->button, (GdkEvent *)event);
3813 gtk_drag_set_icon_pixmap (context,
3814 gdk_drawable_get_colormap (pixmap),
3819 gtk_drag_set_icon_default (context);
3822 g_object_unref (pixmap);
3825 entry->in_drag = FALSE;
3828 gtk_target_list_unref (target_list);
3834 gdk_drawable_get_size (entry->text_area, NULL, &height);
3838 else if (event->y >= height)
3839 tmp_pos = entry->text_length;
3841 tmp_pos = gtk_entry_find_position (entry, event->x + entry->scroll_offset);
3843 if (entry->select_words)
3846 gint old_min, old_max;
3849 min = gtk_entry_move_backward_word (entry, tmp_pos, TRUE);
3850 max = gtk_entry_move_forward_word (entry, tmp_pos, TRUE);
3852 pos = entry->current_pos;
3853 bound = entry->selection_bound;
3855 old_min = MIN(entry->current_pos, entry->selection_bound);
3856 old_max = MAX(entry->current_pos, entry->selection_bound);
3863 else if (old_max < max)
3868 else if (pos == old_min)
3870 if (entry->current_pos != min)
3875 if (entry->current_pos != max)
3879 gtk_entry_set_positions (entry, pos, bound);
3882 gtk_entry_set_positions (entry, tmp_pos, -1);
3889 set_invisible_cursor (GdkWindow *window)
3891 GdkDisplay *display;
3894 display = gdk_drawable_get_display (window);
3895 cursor = gdk_cursor_new_for_display (display, GDK_BLANK_CURSOR);
3897 gdk_window_set_cursor (window, cursor);
3899 gdk_cursor_unref (cursor);
3903 gtk_entry_obscure_mouse_cursor (GtkEntry *entry)
3905 if (entry->mouse_cursor_obscured)
3908 set_invisible_cursor (entry->text_area);
3910 entry->mouse_cursor_obscured = TRUE;
3914 gtk_entry_key_press (GtkWidget *widget,
3917 GtkEntry *entry = GTK_ENTRY (widget);
3919 gtk_entry_reset_blink_time (entry);
3920 gtk_entry_pend_cursor_blink (entry);
3922 if (entry->editable)
3924 if (gtk_im_context_filter_keypress (entry->im_context, event))
3926 gtk_entry_obscure_mouse_cursor (entry);
3927 entry->need_im_reset = TRUE;
3932 if (event->keyval == GDK_Return ||
3933 event->keyval == GDK_KP_Enter ||
3934 event->keyval == GDK_ISO_Enter ||
3935 event->keyval == GDK_Escape)
3937 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
3939 if (completion && completion->priv->completion_timeout)
3941 g_source_remove (completion->priv->completion_timeout);
3942 completion->priv->completion_timeout = 0;
3945 _gtk_entry_reset_im_context (entry);
3948 if (GTK_WIDGET_CLASS (gtk_entry_parent_class)->key_press_event (widget, event))
3949 /* Activate key bindings
3953 if (!entry->editable && event->length)
3954 gtk_widget_error_bell (widget);
3960 gtk_entry_key_release (GtkWidget *widget,
3963 GtkEntry *entry = GTK_ENTRY (widget);
3965 if (entry->editable)
3967 if (gtk_im_context_filter_keypress (entry->im_context, event))
3969 entry->need_im_reset = TRUE;
3974 return GTK_WIDGET_CLASS (gtk_entry_parent_class)->key_release_event (widget, event);
3978 gtk_entry_focus_in (GtkWidget *widget,
3979 GdkEventFocus *event)
3981 GtkEntry *entry = GTK_ENTRY (widget);
3984 gtk_widget_queue_draw (widget);
3986 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (widget));
3988 if (entry->editable)
3990 entry->need_im_reset = TRUE;
3991 gtk_im_context_focus_in (entry->im_context);
3992 keymap_state_changed (keymap, entry);
3993 g_signal_connect (keymap, "state-changed",
3994 G_CALLBACK (keymap_state_changed), entry);
3997 g_signal_connect (keymap, "direction-changed",
3998 G_CALLBACK (keymap_direction_changed), entry);
4000 gtk_entry_reset_blink_time (entry);
4001 gtk_entry_check_cursor_blink (entry);
4007 gtk_entry_focus_out (GtkWidget *widget,
4008 GdkEventFocus *event)
4010 GtkEntry *entry = GTK_ENTRY (widget);
4011 GtkEntryCompletion *completion;
4014 gtk_widget_queue_draw (widget);
4016 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (widget));
4018 if (entry->editable)
4020 entry->need_im_reset = TRUE;
4021 gtk_im_context_focus_out (entry->im_context);
4022 remove_capslock_feedback (entry);
4025 gtk_entry_check_cursor_blink (entry);
4027 g_signal_handlers_disconnect_by_func (keymap, keymap_state_changed, entry);
4028 g_signal_handlers_disconnect_by_func (keymap, keymap_direction_changed, entry);
4030 completion = gtk_entry_get_completion (entry);
4032 _gtk_entry_completion_popdown (completion);
4038 gtk_entry_grab_focus (GtkWidget *widget)
4040 GtkEntry *entry = GTK_ENTRY (widget);
4041 gboolean select_on_focus;
4043 GTK_WIDGET_CLASS (gtk_entry_parent_class)->grab_focus (widget);
4045 if (entry->editable && !entry->in_click)
4047 g_object_get (gtk_widget_get_settings (widget),
4048 "gtk-entry-select-on-focus",
4052 if (select_on_focus)
4053 gtk_editable_select_region (GTK_EDITABLE (widget), 0, -1);
4058 gtk_entry_direction_changed (GtkWidget *widget,
4059 GtkTextDirection previous_dir)
4061 GtkEntry *entry = GTK_ENTRY (widget);
4063 gtk_entry_recompute (entry);
4065 GTK_WIDGET_CLASS (gtk_entry_parent_class)->direction_changed (widget, previous_dir);
4069 gtk_entry_state_changed (GtkWidget *widget,
4070 GtkStateType previous_state)
4072 GtkEntry *entry = GTK_ENTRY (widget);
4073 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
4077 if (GTK_WIDGET_REALIZED (widget))
4079 gdk_window_set_background (widget->window, &widget->style->base[GTK_WIDGET_STATE (widget)]);
4080 gdk_window_set_background (entry->text_area, &widget->style->base[GTK_WIDGET_STATE (widget)]);
4081 for (i = 0; i < MAX_ICONS; i++)
4083 EntryIconInfo *icon_info = priv->icons[i];
4084 if (icon_info && icon_info->window)
4085 gdk_window_set_background (icon_info->window, &widget->style->base[GTK_WIDGET_STATE (widget)]);
4088 if (GTK_WIDGET_IS_SENSITIVE (widget))
4089 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
4093 gdk_window_set_cursor (entry->text_area, cursor);
4096 gdk_cursor_unref (cursor);
4098 entry->mouse_cursor_obscured = FALSE;
4100 update_cursors (widget);
4103 if (!GTK_WIDGET_IS_SENSITIVE (widget))
4105 /* Clear any selection */
4106 gtk_editable_select_region (GTK_EDITABLE (entry), entry->current_pos, entry->current_pos);
4109 gtk_widget_queue_draw (widget);
4113 gtk_entry_screen_changed (GtkWidget *widget,
4114 GdkScreen *old_screen)
4116 gtk_entry_recompute (GTK_ENTRY (widget));
4119 /* GtkEditable method implementations
4122 gtk_entry_insert_text (GtkEditable *editable,
4123 const gchar *new_text,
4124 gint new_text_length,
4127 GtkEntry *entry = GTK_ENTRY (editable);
4131 if (*position < 0 || *position > entry->text_length)
4132 *position = entry->text_length;
4134 g_object_ref (editable);
4136 if (new_text_length <= 63)
4139 text = g_new (gchar, new_text_length + 1);
4141 text[new_text_length] = '\0';
4142 strncpy (text, new_text, new_text_length);
4144 g_signal_emit_by_name (editable, "insert-text", text, new_text_length, position);
4146 if (!entry->visible)
4147 trash_area (text, new_text_length);
4149 if (new_text_length > 63)
4152 g_object_unref (editable);
4156 gtk_entry_delete_text (GtkEditable *editable,
4160 GtkEntry *entry = GTK_ENTRY (editable);
4162 if (end_pos < 0 || end_pos > entry->text_length)
4163 end_pos = entry->text_length;
4166 if (start_pos > end_pos)
4167 start_pos = end_pos;
4169 g_object_ref (editable);
4171 g_signal_emit_by_name (editable, "delete-text", start_pos, end_pos);
4173 g_object_unref (editable);
4177 gtk_entry_get_chars (GtkEditable *editable,
4181 GtkEntry *entry = GTK_ENTRY (editable);
4182 gint start_index, end_index;
4185 end_pos = entry->text_length;
4187 start_pos = MIN (entry->text_length, start_pos);
4188 end_pos = MIN (entry->text_length, end_pos);
4190 start_index = g_utf8_offset_to_pointer (entry->text, start_pos) - entry->text;
4191 end_index = g_utf8_offset_to_pointer (entry->text, end_pos) - entry->text;
4193 return g_strndup (entry->text + start_index, end_index - start_index);
4197 gtk_entry_real_set_position (GtkEditable *editable,
4200 GtkEntry *entry = GTK_ENTRY (editable);
4202 if (position < 0 || position > entry->text_length)
4203 position = entry->text_length;
4205 if (position != entry->current_pos ||
4206 position != entry->selection_bound)
4208 _gtk_entry_reset_im_context (entry);
4209 gtk_entry_set_positions (entry, position, position);
4214 gtk_entry_get_position (GtkEditable *editable)
4216 return GTK_ENTRY (editable)->current_pos;
4220 gtk_entry_set_selection_bounds (GtkEditable *editable,
4224 GtkEntry *entry = GTK_ENTRY (editable);
4227 start = entry->text_length;
4229 end = entry->text_length;
4231 _gtk_entry_reset_im_context (entry);
4233 gtk_entry_set_positions (entry,
4234 MIN (end, entry->text_length),
4235 MIN (start, entry->text_length));
4237 gtk_entry_update_primary_selection (entry);
4241 gtk_entry_get_selection_bounds (GtkEditable *editable,
4245 GtkEntry *entry = GTK_ENTRY (editable);
4247 *start = entry->selection_bound;
4248 *end = entry->current_pos;
4250 return (entry->selection_bound != entry->current_pos);
4254 icon_theme_changed (GtkEntry *entry)
4256 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
4259 for (i = 0; i < MAX_ICONS; i++)
4261 EntryIconInfo *icon_info = priv->icons[i];
4262 if (icon_info != NULL)
4264 if (icon_info->storage_type == GTK_IMAGE_ICON_NAME)
4265 gtk_entry_set_icon_from_icon_name (entry, i, icon_info->icon_name);
4266 else if (icon_info->storage_type == GTK_IMAGE_STOCK)
4267 gtk_entry_set_icon_from_stock (entry, i, icon_info->stock_id);
4268 else if (icon_info->storage_type == GTK_IMAGE_GICON)
4269 gtk_entry_set_icon_from_gicon (entry, i, icon_info->gicon);
4273 gtk_widget_queue_draw (GTK_WIDGET (entry));
4277 icon_margin_changed (GtkEntry *entry)
4279 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
4282 _gtk_entry_effective_inner_border (GTK_ENTRY (entry), &border);
4284 priv->icon_margin = border.left;
4288 gtk_entry_style_set (GtkWidget *widget,
4289 GtkStyle *previous_style)
4291 GtkEntry *entry = GTK_ENTRY (widget);
4292 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
4294 gboolean interior_focus;
4297 gtk_widget_style_get (widget,
4298 "focus-line-width", &focus_width,
4299 "interior-focus", &interior_focus,
4302 priv->focus_width = focus_width;
4303 priv->interior_focus = interior_focus;
4305 if (!priv->invisible_char_set)
4306 entry->invisible_char = find_invisible_char (GTK_WIDGET (entry));
4308 gtk_entry_recompute (entry);
4310 if (previous_style && GTK_WIDGET_REALIZED (widget))
4312 gdk_window_set_background (widget->window, &widget->style->base[GTK_WIDGET_STATE (widget)]);
4313 gdk_window_set_background (entry->text_area, &widget->style->base[GTK_WIDGET_STATE (widget)]);
4314 for (i = 0; i < MAX_ICONS; i++)
4316 EntryIconInfo *icon_info = priv->icons[i];
4317 if (icon_info && icon_info->window)
4318 gdk_window_set_background (icon_info->window, &widget->style->base[GTK_WIDGET_STATE (widget)]);
4322 icon_theme_changed (entry);
4323 icon_margin_changed (entry);
4326 /* GtkCellEditable method implementations
4329 gtk_cell_editable_entry_activated (GtkEntry *entry, gpointer data)
4331 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4332 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4336 gtk_cell_editable_key_press_event (GtkEntry *entry,
4337 GdkEventKey *key_event,
4340 if (key_event->keyval == GDK_Escape)
4342 entry->editing_canceled = TRUE;
4343 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4344 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4349 /* override focus */
4350 if (key_event->keyval == GDK_Up || key_event->keyval == GDK_Down)
4352 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4353 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4362 gtk_entry_start_editing (GtkCellEditable *cell_editable,
4365 GTK_ENTRY (cell_editable)->is_cell_renderer = TRUE;
4367 g_signal_connect (cell_editable, "activate",
4368 G_CALLBACK (gtk_cell_editable_entry_activated), NULL);
4369 g_signal_connect (cell_editable, "key-press-event",
4370 G_CALLBACK (gtk_cell_editable_key_press_event), NULL);
4374 gtk_entry_password_hint_free (GtkEntryPasswordHint *password_hint)
4376 if (password_hint->password_hint_timeout_id)
4377 g_source_remove (password_hint->password_hint_timeout_id);
4379 g_slice_free (GtkEntryPasswordHint, password_hint);
4382 /* Default signal handlers
4385 gtk_entry_real_insert_text (GtkEditable *editable,
4386 const gchar *new_text,
4387 gint new_text_length,
4390 GtkEntry *entry = GTK_ENTRY (editable);
4394 if (new_text_length < 0)
4395 new_text_length = strlen (new_text);
4397 n_chars = g_utf8_strlen (new_text, new_text_length);
4398 if (entry->text_max_length > 0 && n_chars + entry->text_length > entry->text_max_length)
4400 gtk_widget_error_bell (GTK_WIDGET (entry));
4401 n_chars = entry->text_max_length - entry->text_length;
4402 new_text_length = g_utf8_offset_to_pointer (new_text, n_chars) - new_text;
4405 if (new_text_length + entry->n_bytes + 1 > entry->text_size)
4407 gsize prev_size = entry->text_size;
4409 while (new_text_length + entry->n_bytes + 1 > entry->text_size)
4411 if (entry->text_size == 0)
4412 entry->text_size = MIN_SIZE;
4415 if (2 * (guint)entry->text_size < MAX_SIZE &&
4416 2 * (guint)entry->text_size > entry->text_size)
4417 entry->text_size *= 2;
4420 entry->text_size = MAX_SIZE;
4421 if (new_text_length > (gint)entry->text_size - (gint)entry->n_bytes - 1)
4423 new_text_length = (gint)entry->text_size - (gint)entry->n_bytes - 1;
4424 new_text_length = g_utf8_find_prev_char (new_text, new_text + new_text_length + 1) - new_text;
4425 n_chars = g_utf8_strlen (new_text, new_text_length);
4433 entry->text = g_realloc (entry->text, entry->text_size);
4436 /* Same thing, just slower and without leaving stuff in memory. */
4437 gchar *et_new = g_malloc (entry->text_size);
4438 memcpy (et_new, entry->text, MIN (prev_size, entry->text_size));
4439 trash_area (entry->text, prev_size);
4440 g_free (entry->text);
4441 entry->text = et_new;
4445 index = g_utf8_offset_to_pointer (entry->text, *position) - entry->text;
4447 g_memmove (entry->text + index + new_text_length, entry->text + index, entry->n_bytes - index);
4448 memcpy (entry->text + index, new_text, new_text_length);
4450 entry->n_bytes += new_text_length;
4451 entry->text_length += n_chars;
4453 /* NUL terminate for safety and convenience */
4454 entry->text[entry->n_bytes] = '\0';
4456 if (entry->current_pos > *position)
4457 entry->current_pos += n_chars;
4459 if (entry->selection_bound > *position)
4460 entry->selection_bound += n_chars;
4462 if (n_chars == 1 && !entry->visible && (new_text_length < PASSWORD_HINT_MAX))
4464 guint password_hint_timeout;
4466 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
4467 "gtk-entry-password-hint-timeout", &password_hint_timeout,
4470 if (password_hint_timeout > 0)
4472 GtkEntryPasswordHint *password_hint = g_object_get_qdata (G_OBJECT (entry),
4473 quark_password_hint);
4477 password_hint = g_slice_new0 (GtkEntryPasswordHint);
4478 g_object_set_qdata_full (G_OBJECT (entry), quark_password_hint,
4480 (GDestroyNotify) gtk_entry_password_hint_free);
4483 memset (&password_hint->password_hint, 0x0, PASSWORD_HINT_MAX);
4484 password_hint->password_hint_length = new_text_length;
4485 memcpy (&password_hint->password_hint, new_text, new_text_length);
4486 password_hint->password_hint_position = *position + n_chars;
4491 g_object_set_qdata (G_OBJECT (entry), quark_password_hint, NULL);
4494 *position += n_chars;
4496 gtk_entry_recompute (entry);
4498 emit_changed (entry);
4499 g_object_notify (G_OBJECT (editable), "text");
4500 g_object_notify (G_OBJECT (editable), "text-length");
4504 gtk_entry_real_delete_text (GtkEditable *editable,
4508 GtkEntry *entry = GTK_ENTRY (editable);
4512 if (end_pos < 0 || end_pos > entry->text_length)
4513 end_pos = entry->text_length;
4515 if (start_pos < end_pos)
4517 gint start_index = g_utf8_offset_to_pointer (entry->text, start_pos) - entry->text;
4518 gint end_index = g_utf8_offset_to_pointer (entry->text, end_pos) - entry->text;
4520 gint selection_bound;
4522 g_memmove (entry->text + start_index, entry->text + end_index, entry->n_bytes + 1 - end_index);
4523 entry->text_length -= (end_pos - start_pos);
4524 entry->n_bytes -= (end_index - start_index);
4526 /* In password-mode, make sure we don't leave anything sensitive after
4527 * the terminating zero. Note, that the terminating zero already trashed
4530 if (!entry->visible)
4531 trash_area (entry->text + entry->n_bytes + 1, end_index - start_index - 1);
4533 current_pos = entry->current_pos;
4534 if (current_pos > start_pos)
4535 current_pos -= MIN (current_pos, end_pos) - start_pos;
4537 selection_bound = entry->selection_bound;
4538 if (selection_bound > start_pos)
4539 selection_bound -= MIN (selection_bound, end_pos) - start_pos;
4541 gtk_entry_set_positions (entry, current_pos, selection_bound);
4543 /* We might have deleted the selection
4545 gtk_entry_update_primary_selection (entry);
4547 gtk_entry_recompute (entry);
4549 emit_changed (entry);
4550 g_object_notify (G_OBJECT (editable), "text");
4551 g_object_notify (G_OBJECT (editable), "text-length");
4555 /* Compute the X position for an offset that corresponds to the "more important
4556 * cursor position for that offset. We use this when trying to guess to which
4557 * end of the selection we should go to when the user hits the left or
4561 get_better_cursor_x (GtkEntry *entry,
4564 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
4565 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
4566 gboolean split_cursor;
4568 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
4569 const gchar *text = pango_layout_get_text (layout);
4570 gint index = g_utf8_offset_to_pointer (text, offset) - text;
4572 PangoRectangle strong_pos, weak_pos;
4574 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
4575 "gtk-split-cursor", &split_cursor,
4578 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
4581 return strong_pos.x / PANGO_SCALE;
4583 return (keymap_direction == entry->resolved_dir) ? strong_pos.x / PANGO_SCALE : weak_pos.x / PANGO_SCALE;
4587 gtk_entry_move_cursor (GtkEntry *entry,
4588 GtkMovementStep step,
4590 gboolean extend_selection)
4592 gint new_pos = entry->current_pos;
4594 _gtk_entry_reset_im_context (entry);
4596 if (entry->current_pos != entry->selection_bound && !extend_selection)
4598 /* If we have a current selection and aren't extending it, move to the
4599 * start/or end of the selection as appropriate
4603 case GTK_MOVEMENT_VISUAL_POSITIONS:
4605 gint current_x = get_better_cursor_x (entry, entry->current_pos);
4606 gint bound_x = get_better_cursor_x (entry, entry->selection_bound);
4609 new_pos = current_x < bound_x ? entry->current_pos : entry->selection_bound;
4611 new_pos = current_x > bound_x ? entry->current_pos : entry->selection_bound;
4614 case GTK_MOVEMENT_LOGICAL_POSITIONS:
4615 case GTK_MOVEMENT_WORDS:
4617 new_pos = MIN (entry->current_pos, entry->selection_bound);
4619 new_pos = MAX (entry->current_pos, entry->selection_bound);
4621 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
4622 case GTK_MOVEMENT_PARAGRAPH_ENDS:
4623 case GTK_MOVEMENT_BUFFER_ENDS:
4624 new_pos = count < 0 ? 0 : entry->text_length;
4626 case GTK_MOVEMENT_DISPLAY_LINES:
4627 case GTK_MOVEMENT_PARAGRAPHS:
4628 case GTK_MOVEMENT_PAGES:
4629 case GTK_MOVEMENT_HORIZONTAL_PAGES:
4637 case GTK_MOVEMENT_LOGICAL_POSITIONS:
4638 new_pos = gtk_entry_move_logically (entry, new_pos, count);
4640 case GTK_MOVEMENT_VISUAL_POSITIONS:
4641 new_pos = gtk_entry_move_visually (entry, new_pos, count);
4642 if (entry->current_pos == new_pos)
4644 if (!extend_selection)
4646 if (!gtk_widget_keynav_failed (GTK_WIDGET (entry),
4648 GTK_DIR_RIGHT : GTK_DIR_LEFT))
4650 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (entry));
4653 gtk_widget_child_focus (toplevel,
4655 GTK_DIR_RIGHT : GTK_DIR_LEFT);
4660 gtk_widget_error_bell (GTK_WIDGET (entry));
4664 case GTK_MOVEMENT_WORDS:
4667 new_pos = gtk_entry_move_forward_word (entry, new_pos, FALSE);
4672 new_pos = gtk_entry_move_backward_word (entry, new_pos, FALSE);
4675 if (entry->current_pos == new_pos)
4676 gtk_widget_error_bell (GTK_WIDGET (entry));
4678 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
4679 case GTK_MOVEMENT_PARAGRAPH_ENDS:
4680 case GTK_MOVEMENT_BUFFER_ENDS:
4681 new_pos = count < 0 ? 0 : entry->text_length;
4682 if (entry->current_pos == new_pos)
4683 gtk_widget_error_bell (GTK_WIDGET (entry));
4685 case GTK_MOVEMENT_DISPLAY_LINES:
4686 case GTK_MOVEMENT_PARAGRAPHS:
4687 case GTK_MOVEMENT_PAGES:
4688 case GTK_MOVEMENT_HORIZONTAL_PAGES:
4693 if (extend_selection)
4694 gtk_editable_select_region (GTK_EDITABLE (entry), entry->selection_bound, new_pos);
4696 gtk_editable_set_position (GTK_EDITABLE (entry), new_pos);
4698 gtk_entry_pend_cursor_blink (entry);
4702 gtk_entry_insert_at_cursor (GtkEntry *entry,
4705 GtkEditable *editable = GTK_EDITABLE (entry);
4706 gint pos = entry->current_pos;
4708 if (entry->editable)
4710 _gtk_entry_reset_im_context (entry);
4712 gtk_editable_insert_text (editable, str, -1, &pos);
4713 gtk_editable_set_position (editable, pos);
4718 gtk_entry_delete_from_cursor (GtkEntry *entry,
4722 GtkEditable *editable = GTK_EDITABLE (entry);
4723 gint start_pos = entry->current_pos;
4724 gint end_pos = entry->current_pos;
4725 gint old_n_bytes = entry->n_bytes;
4727 _gtk_entry_reset_im_context (entry);
4729 if (!entry->editable)
4731 gtk_widget_error_bell (GTK_WIDGET (entry));
4735 if (entry->selection_bound != entry->current_pos)
4737 gtk_editable_delete_selection (editable);
4743 case GTK_DELETE_CHARS:
4744 end_pos = gtk_entry_move_logically (entry, entry->current_pos, count);
4745 gtk_editable_delete_text (editable, MIN (start_pos, end_pos), MAX (start_pos, end_pos));
4747 case GTK_DELETE_WORDS:
4750 /* Move to end of current word, or if not on a word, end of previous word */
4751 end_pos = gtk_entry_move_backward_word (entry, end_pos, FALSE);
4752 end_pos = gtk_entry_move_forward_word (entry, end_pos, FALSE);
4756 /* Move to beginning of current word, or if not on a word, begining of next word */
4757 start_pos = gtk_entry_move_forward_word (entry, start_pos, FALSE);
4758 start_pos = gtk_entry_move_backward_word (entry, start_pos, FALSE);
4762 case GTK_DELETE_WORD_ENDS:
4765 start_pos = gtk_entry_move_backward_word (entry, start_pos, FALSE);
4770 end_pos = gtk_entry_move_forward_word (entry, end_pos, FALSE);
4773 gtk_editable_delete_text (editable, start_pos, end_pos);
4775 case GTK_DELETE_DISPLAY_LINE_ENDS:
4776 case GTK_DELETE_PARAGRAPH_ENDS:
4778 gtk_editable_delete_text (editable, 0, entry->current_pos);
4780 gtk_editable_delete_text (editable, entry->current_pos, -1);
4782 case GTK_DELETE_DISPLAY_LINES:
4783 case GTK_DELETE_PARAGRAPHS:
4784 gtk_editable_delete_text (editable, 0, -1);
4786 case GTK_DELETE_WHITESPACE:
4787 gtk_entry_delete_whitespace (entry);
4791 if (entry->n_bytes == old_n_bytes)
4792 gtk_widget_error_bell (GTK_WIDGET (entry));
4794 gtk_entry_pend_cursor_blink (entry);
4798 gtk_entry_backspace (GtkEntry *entry)
4800 GtkEditable *editable = GTK_EDITABLE (entry);
4803 _gtk_entry_reset_im_context (entry);
4805 if (!entry->editable || !entry->text)
4807 gtk_widget_error_bell (GTK_WIDGET (entry));
4811 if (entry->selection_bound != entry->current_pos)
4813 gtk_editable_delete_selection (editable);
4817 prev_pos = gtk_entry_move_logically (entry, entry->current_pos, -1);
4819 if (prev_pos < entry->current_pos)
4821 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
4822 PangoLogAttr *log_attrs;
4825 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
4827 if (entry->visible &&
4828 log_attrs[entry->current_pos].backspace_deletes_character)
4830 gchar *cluster_text;
4831 gchar *normalized_text;
4834 cluster_text = gtk_editable_get_chars (editable,
4836 entry->current_pos);
4837 normalized_text = g_utf8_normalize (cluster_text,
4838 strlen (cluster_text),
4840 len = g_utf8_strlen (normalized_text, -1);
4842 gtk_editable_delete_text (editable, prev_pos, entry->current_pos);
4845 gint pos = entry->current_pos;
4847 gtk_editable_insert_text (editable, normalized_text,
4848 g_utf8_offset_to_pointer (normalized_text, len - 1) - normalized_text,
4850 gtk_editable_set_position (editable, pos);
4853 g_free (normalized_text);
4854 g_free (cluster_text);
4858 gtk_editable_delete_text (editable, prev_pos, entry->current_pos);
4865 gtk_widget_error_bell (GTK_WIDGET (entry));
4868 gtk_entry_pend_cursor_blink (entry);
4872 gtk_entry_copy_clipboard (GtkEntry *entry)
4874 GtkEditable *editable = GTK_EDITABLE (entry);
4878 if (gtk_editable_get_selection_bounds (editable, &start, &end))
4880 if (!entry->visible)
4882 gtk_widget_error_bell (GTK_WIDGET (entry));
4886 str = gtk_entry_get_public_chars (entry, start, end);
4887 gtk_clipboard_set_text (gtk_widget_get_clipboard (GTK_WIDGET (entry),
4888 GDK_SELECTION_CLIPBOARD),
4895 gtk_entry_cut_clipboard (GtkEntry *entry)
4897 GtkEditable *editable = GTK_EDITABLE (entry);
4900 if (!entry->visible)
4902 gtk_widget_error_bell (GTK_WIDGET (entry));
4906 gtk_entry_copy_clipboard (entry);
4908 if (entry->editable)
4910 if (gtk_editable_get_selection_bounds (editable, &start, &end))
4911 gtk_editable_delete_text (editable, start, end);
4915 gtk_widget_error_bell (GTK_WIDGET (entry));
4920 gtk_entry_paste_clipboard (GtkEntry *entry)
4922 if (entry->editable)
4923 gtk_entry_paste (entry, GDK_NONE);
4925 gtk_widget_error_bell (GTK_WIDGET (entry));
4929 gtk_entry_delete_cb (GtkEntry *entry)
4931 GtkEditable *editable = GTK_EDITABLE (entry);
4934 if (entry->editable)
4936 if (gtk_editable_get_selection_bounds (editable, &start, &end))
4937 gtk_editable_delete_text (editable, start, end);
4942 gtk_entry_toggle_overwrite (GtkEntry *entry)
4944 entry->overwrite_mode = !entry->overwrite_mode;
4945 gtk_entry_pend_cursor_blink (entry);
4946 gtk_widget_queue_draw (GTK_WIDGET (entry));
4950 gtk_entry_select_all (GtkEntry *entry)
4952 gtk_entry_select_line (entry);
4956 gtk_entry_real_activate (GtkEntry *entry)
4959 GtkWidget *toplevel;
4962 widget = GTK_WIDGET (entry);
4964 if (entry->activates_default)
4966 toplevel = gtk_widget_get_toplevel (widget);
4967 if (GTK_IS_WINDOW (toplevel))
4969 window = GTK_WINDOW (toplevel);
4972 widget != window->default_widget &&
4973 !(widget == window->focus_widget &&
4974 (!window->default_widget || !GTK_WIDGET_SENSITIVE (window->default_widget))))
4975 gtk_window_activate_default (window);
4981 keymap_direction_changed (GdkKeymap *keymap,
4984 gtk_entry_recompute (entry);
4987 /* IM Context Callbacks
4991 gtk_entry_commit_cb (GtkIMContext *context,
4995 if (entry->editable)
4996 gtk_entry_enter_text (entry, str);
5000 gtk_entry_preedit_changed_cb (GtkIMContext *context,
5003 if (entry->editable)
5005 gchar *preedit_string;
5008 gtk_im_context_get_preedit_string (entry->im_context,
5009 &preedit_string, NULL,
5011 entry->preedit_length = strlen (preedit_string);
5012 cursor_pos = CLAMP (cursor_pos, 0, g_utf8_strlen (preedit_string, -1));
5013 entry->preedit_cursor = cursor_pos;
5014 g_free (preedit_string);
5016 gtk_entry_recompute (entry);
5021 gtk_entry_retrieve_surrounding_cb (GtkIMContext *context,
5024 gtk_im_context_set_surrounding (context,
5027 g_utf8_offset_to_pointer (entry->text, entry->current_pos) - entry->text);
5033 gtk_entry_delete_surrounding_cb (GtkIMContext *slave,
5038 if (entry->editable)
5039 gtk_editable_delete_text (GTK_EDITABLE (entry),
5040 entry->current_pos + offset,
5041 entry->current_pos + offset + n_chars);
5046 /* Internal functions
5049 /* Used for im_commit_cb and inserting Unicode chars */
5051 gtk_entry_enter_text (GtkEntry *entry,
5054 GtkEditable *editable = GTK_EDITABLE (entry);
5056 gboolean old_need_im_reset;
5058 old_need_im_reset = entry->need_im_reset;
5059 entry->need_im_reset = FALSE;
5061 if (gtk_editable_get_selection_bounds (editable, NULL, NULL))
5062 gtk_editable_delete_selection (editable);
5065 if (entry->overwrite_mode)
5066 gtk_entry_delete_from_cursor (entry, GTK_DELETE_CHARS, 1);
5069 tmp_pos = entry->current_pos;
5070 gtk_editable_insert_text (editable, str, strlen (str), &tmp_pos);
5071 gtk_editable_set_position (editable, tmp_pos);
5073 entry->need_im_reset = old_need_im_reset;
5076 /* All changes to entry->current_pos and entry->selection_bound
5077 * should go through this function.
5080 gtk_entry_set_positions (GtkEntry *entry,
5082 gint selection_bound)
5084 gboolean changed = FALSE;
5086 g_object_freeze_notify (G_OBJECT (entry));
5088 if (current_pos != -1 &&
5089 entry->current_pos != current_pos)
5091 entry->current_pos = current_pos;
5094 g_object_notify (G_OBJECT (entry), "cursor-position");
5097 if (selection_bound != -1 &&
5098 entry->selection_bound != selection_bound)
5100 entry->selection_bound = selection_bound;
5103 g_object_notify (G_OBJECT (entry), "selection-bound");
5106 g_object_thaw_notify (G_OBJECT (entry));
5110 gtk_entry_move_adjustments (entry);
5111 gtk_entry_recompute (entry);
5116 gtk_entry_reset_layout (GtkEntry *entry)
5118 if (entry->cached_layout)
5120 g_object_unref (entry->cached_layout);
5121 entry->cached_layout = NULL;
5126 update_im_cursor_location (GtkEntry *entry)
5130 gint strong_xoffset;
5131 gint area_width, area_height;
5133 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
5134 gtk_entry_get_text_area_size (entry, NULL, NULL, &area_width, &area_height);
5136 strong_xoffset = strong_x - entry->scroll_offset;
5137 if (strong_xoffset < 0)
5141 else if (strong_xoffset > area_width)
5143 strong_xoffset = area_width;
5145 area.x = strong_xoffset;
5148 area.height = area_height;
5150 gtk_im_context_set_cursor_location (entry->im_context, &area);
5154 recompute_idle_func (gpointer data)
5158 entry = GTK_ENTRY (data);
5160 entry->recompute_idle = 0;
5162 if (gtk_widget_has_screen (GTK_WIDGET (entry)))
5164 gtk_entry_adjust_scroll (entry);
5165 gtk_entry_queue_draw (entry);
5167 update_im_cursor_location (entry);
5174 gtk_entry_recompute (GtkEntry *entry)
5176 gtk_entry_reset_layout (entry);
5177 gtk_entry_check_cursor_blink (entry);
5179 if (!entry->recompute_idle)
5181 entry->recompute_idle = gdk_threads_add_idle_full (G_PRIORITY_HIGH_IDLE + 15, /* between resize and redraw */
5182 recompute_idle_func, entry, NULL);
5187 append_char (GString *str,
5195 char_len = g_unichar_to_utf8 (ch, buf);
5200 g_string_append_len (str, buf, char_len);
5206 gtk_entry_remove_password_hint (gpointer data)
5208 /* Force the string to be redrawn, but now without a visible character */
5209 gtk_entry_recompute (GTK_ENTRY (data));
5214 static PangoLayout *
5215 gtk_entry_create_layout (GtkEntry *entry,
5216 gboolean include_preedit)
5218 GtkWidget *widget = GTK_WIDGET (entry);
5219 PangoLayout *layout = gtk_widget_create_pango_layout (widget, NULL);
5220 PangoAttrList *tmp_attrs = pango_attr_list_new ();
5222 gchar *preedit_string = NULL;
5223 gint preedit_length = 0;
5224 PangoAttrList *preedit_attrs = NULL;
5226 pango_layout_set_single_paragraph_mode (layout, TRUE);
5228 if (include_preedit)
5230 gtk_im_context_get_preedit_string (entry->im_context,
5231 &preedit_string, &preedit_attrs, NULL);
5232 preedit_length = entry->preedit_length;
5237 GString *tmp_string = g_string_new (NULL);
5239 gint cursor_index = g_utf8_offset_to_pointer (entry->text, entry->current_pos) - entry->text;
5243 g_string_prepend_len (tmp_string, entry->text, entry->n_bytes);
5244 g_string_insert (tmp_string, cursor_index, preedit_string);
5249 gunichar invisible_char;
5251 if (entry->invisible_char != 0)
5252 invisible_char = entry->invisible_char;
5254 invisible_char = ' '; /* just pick a char */
5256 ch_len = g_utf8_strlen (entry->text, entry->n_bytes);
5257 append_char (tmp_string, invisible_char, ch_len);
5259 g_utf8_offset_to_pointer (tmp_string->str, entry->current_pos) -
5261 g_string_insert (tmp_string, cursor_index, preedit_string);
5264 pango_layout_set_text (layout, tmp_string->str, tmp_string->len);
5266 pango_attr_list_splice (tmp_attrs, preedit_attrs,
5267 cursor_index, preedit_length);
5269 g_string_free (tmp_string, TRUE);
5273 PangoDirection pango_dir;
5276 pango_dir = pango_find_base_dir (entry->text, entry->n_bytes);
5279 pango_dir = PANGO_DIRECTION_NEUTRAL;
5281 if (pango_dir == PANGO_DIRECTION_NEUTRAL)
5283 if (GTK_WIDGET_HAS_FOCUS (widget))
5285 GdkDisplay *display = gtk_widget_get_display (widget);
5286 GdkKeymap *keymap = gdk_keymap_get_for_display (display);
5287 if (gdk_keymap_get_direction (keymap) == PANGO_DIRECTION_RTL)
5288 pango_dir = PANGO_DIRECTION_RTL;
5290 pango_dir = PANGO_DIRECTION_LTR;
5294 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
5295 pango_dir = PANGO_DIRECTION_RTL;
5297 pango_dir = PANGO_DIRECTION_LTR;
5301 pango_context_set_base_dir (gtk_widget_get_pango_context (widget),
5304 entry->resolved_dir = pango_dir;
5308 pango_layout_set_text (layout, entry->text, entry->n_bytes);
5312 GString *str = g_string_new (NULL);
5313 gunichar invisible_char;
5314 guint password_hint_timeout;
5315 GtkEntryPasswordHint *password_hint;
5317 g_object_get (gtk_widget_get_settings (widget),
5318 "gtk-entry-password-hint-timeout", &password_hint_timeout,
5321 if (entry->invisible_char != 0)
5322 invisible_char = entry->invisible_char;
5324 invisible_char = ' '; /* just pick a char */
5326 password_hint = g_object_get_qdata (G_OBJECT (entry),
5327 quark_password_hint);
5329 if (password_hint && password_hint->password_hint_timeout_id)
5331 g_source_remove (password_hint->password_hint_timeout_id);
5332 password_hint->password_hint_timeout_id = 0;
5335 if (password_hint_timeout == 0 || password_hint == NULL ||
5336 (password_hint && password_hint->password_hint_length == 0))
5338 append_char (str, invisible_char, entry->text_length);
5340 else if (password_hint)
5342 /* Draw hidden characters upto the inserted position,
5343 * then the real thing, pad up to full length
5345 if (password_hint->password_hint_position > 1)
5346 append_char (str, invisible_char,
5347 password_hint->password_hint_position - 1);
5349 g_string_append_len (str, password_hint->password_hint,
5350 password_hint->password_hint_length);
5352 if (password_hint->password_hint_position < entry->text_length)
5353 append_char (str, invisible_char,
5354 entry->text_length -
5355 password_hint->password_hint_position);
5357 /* Now remove this last input character, don't need
5360 memset (password_hint->password_hint, 0, PASSWORD_HINT_MAX);
5361 password_hint->password_hint_length = 0;
5363 password_hint->password_hint_timeout_id =
5364 gdk_threads_add_timeout (password_hint_timeout,
5365 (GSourceFunc) gtk_entry_remove_password_hint,
5369 pango_layout_set_text (layout, str->str, str->len);
5370 g_string_free (str, TRUE);
5374 pango_layout_set_attributes (layout, tmp_attrs);
5376 g_free (preedit_string);
5378 pango_attr_list_unref (preedit_attrs);
5380 pango_attr_list_unref (tmp_attrs);
5385 static PangoLayout *
5386 gtk_entry_ensure_layout (GtkEntry *entry,
5387 gboolean include_preedit)
5389 if (entry->preedit_length > 0 &&
5390 !include_preedit != !entry->cache_includes_preedit)
5391 gtk_entry_reset_layout (entry);
5393 if (!entry->cached_layout)
5395 entry->cached_layout = gtk_entry_create_layout (entry, include_preedit);
5396 entry->cache_includes_preedit = include_preedit;
5399 return entry->cached_layout;
5403 get_layout_position (GtkEntry *entry,
5407 PangoLayout *layout;
5408 PangoRectangle logical_rect;
5409 gint area_width, area_height;
5410 GtkBorder inner_border;
5412 PangoLayoutLine *line;
5414 layout = gtk_entry_ensure_layout (entry, TRUE);
5416 gtk_entry_get_text_area_size (entry, NULL, NULL, &area_width, &area_height);
5417 _gtk_entry_effective_inner_border (entry, &inner_border);
5419 area_height = PANGO_SCALE * (area_height - inner_border.top - inner_border.bottom);
5421 line = pango_layout_get_lines_readonly (layout)->data;
5422 pango_layout_line_get_extents (line, NULL, &logical_rect);
5424 /* Align primarily for locale's ascent/descent */
5425 y_pos = ((area_height - entry->ascent - entry->descent) / 2 +
5426 entry->ascent + logical_rect.y);
5428 /* Now see if we need to adjust to fit in actual drawn string */
5429 if (logical_rect.height > area_height)
5430 y_pos = (area_height - logical_rect.height) / 2;
5433 else if (y_pos + logical_rect.height > area_height)
5434 y_pos = area_height - logical_rect.height;
5436 y_pos = inner_border.top + y_pos / PANGO_SCALE;
5439 *x = inner_border.left - entry->scroll_offset;
5446 draw_text_with_color (GtkEntry *entry, cairo_t *cr, GdkColor *default_color)
5448 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
5451 gint start_pos, end_pos;
5453 widget = GTK_WIDGET (entry);
5457 get_layout_position (entry, &x, &y);
5459 cairo_move_to (cr, x, y);
5460 gdk_cairo_set_source_color (cr, default_color);
5461 pango_cairo_show_layout (cr, layout);
5463 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start_pos, &end_pos))
5467 PangoRectangle logical_rect;
5468 GdkColor *selection_color, *text_color;
5469 GtkBorder inner_border;
5471 pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
5472 gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
5474 if (GTK_WIDGET_HAS_FOCUS (entry))
5476 selection_color = &widget->style->base [GTK_STATE_SELECTED];
5477 text_color = &widget->style->text [GTK_STATE_SELECTED];
5481 selection_color = &widget->style->base [GTK_STATE_ACTIVE];
5482 text_color = &widget->style->text [GTK_STATE_ACTIVE];
5485 _gtk_entry_effective_inner_border (entry, &inner_border);
5487 for (i = 0; i < n_ranges; ++i)
5488 cairo_rectangle (cr,
5489 inner_border.left - entry->scroll_offset + ranges[2 * i],
5492 logical_rect.height);
5496 gdk_cairo_set_source_color (cr, selection_color);
5499 cairo_move_to (cr, x, y);
5500 gdk_cairo_set_source_color (cr, text_color);
5501 pango_cairo_show_layout (cr, layout);
5509 gtk_entry_draw_text (GtkEntry *entry)
5511 GtkWidget *widget = GTK_WIDGET (entry);
5514 if (!entry->visible && entry->invisible_char == 0)
5517 if (GTK_WIDGET_DRAWABLE (entry))
5519 GdkColor text_color, bar_text_color;
5522 gint progress_x, progress_y, progress_width, progress_height;
5525 state = GTK_STATE_SELECTED;
5526 if (!GTK_WIDGET_SENSITIVE (widget))
5527 state = GTK_STATE_INSENSITIVE;
5528 text_color = widget->style->text[widget->state];
5529 bar_text_color = widget->style->fg[state];
5531 get_progress_area (widget,
5532 &progress_x, &progress_y,
5533 &progress_width, &progress_height);
5535 cr = gdk_cairo_create (entry->text_area);
5537 /* If the color is the same, or the progress area has a zero
5538 * size, then we only need to draw once. */
5539 if ((text_color.pixel == bar_text_color.pixel) ||
5540 ((progress_width == 0) || (progress_height == 0)))
5542 draw_text_with_color (entry, cr, &text_color);
5546 gdk_drawable_get_size (entry->text_area, &width, &height);
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);
5579 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, entry->text_area, NULL,
5595 is_primary, text_dir, draw_arrow);
5599 gtk_entry_draw_cursor (GtkEntry *entry,
5602 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
5603 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
5605 if (GTK_WIDGET_DRAWABLE (entry))
5607 GtkWidget *widget = GTK_WIDGET (entry);
5608 GdkRectangle cursor_location;
5609 gboolean split_cursor;
5610 PangoRectangle cursor_rect;
5611 GtkBorder inner_border;
5613 gint text_area_height;
5616 gboolean block_at_line_end;
5617 PangoLayout *layout;
5620 _gtk_entry_effective_inner_border (entry, &inner_border);
5622 xoffset = inner_border.left - entry->scroll_offset;
5624 gdk_drawable_get_size (entry->text_area, NULL, &text_area_height);
5626 layout = gtk_entry_ensure_layout (entry, TRUE);
5627 text = pango_layout_get_text (layout);
5628 cursor_index = g_utf8_offset_to_pointer (text, entry->current_pos + entry->preedit_cursor) - text;
5629 if (!entry->overwrite_mode)
5632 block = _gtk_text_util_get_block_cursor_location (layout,
5633 cursor_index, &cursor_rect, &block_at_line_end);
5637 gint strong_x, weak_x;
5638 PangoDirection dir1 = PANGO_DIRECTION_NEUTRAL;
5639 PangoDirection dir2 = PANGO_DIRECTION_NEUTRAL;
5643 gtk_entry_get_cursor_locations (entry, type, &strong_x, &weak_x);
5645 g_object_get (gtk_widget_get_settings (widget),
5646 "gtk-split-cursor", &split_cursor,
5649 dir1 = entry->resolved_dir;
5655 if (weak_x != strong_x)
5657 dir2 = (entry->resolved_dir == PANGO_DIRECTION_LTR) ? PANGO_DIRECTION_RTL : PANGO_DIRECTION_LTR;
5663 if (keymap_direction == entry->resolved_dir)
5669 cursor_location.x = xoffset + x1;
5670 cursor_location.y = inner_border.top;
5671 cursor_location.width = 0;
5672 cursor_location.height = text_area_height - inner_border.top - inner_border.bottom;
5674 draw_insertion_cursor (entry,
5675 &cursor_location, TRUE, dir1,
5676 dir2 != PANGO_DIRECTION_NEUTRAL);
5678 if (dir2 != PANGO_DIRECTION_NEUTRAL)
5680 cursor_location.x = xoffset + x2;
5681 draw_insertion_cursor (entry,
5682 &cursor_location, FALSE, dir2,
5686 else /* overwrite_mode */
5688 GdkColor cursor_color;
5693 get_layout_position (entry, &x, &y);
5695 rect.x = PANGO_PIXELS (cursor_rect.x) + x;
5696 rect.y = PANGO_PIXELS (cursor_rect.y) + y;
5697 rect.width = PANGO_PIXELS (cursor_rect.width);
5698 rect.height = PANGO_PIXELS (cursor_rect.height);
5700 cr = gdk_cairo_create (entry->text_area);
5702 _gtk_widget_get_cursor_color (widget, &cursor_color);
5703 gdk_cairo_set_source_color (cr, &cursor_color);
5704 gdk_cairo_rectangle (cr, &rect);
5707 if (!block_at_line_end)
5709 gdk_cairo_rectangle (cr, &rect);
5711 cairo_move_to (cr, x, y);
5712 gdk_cairo_set_source_color (cr, &widget->style->base[widget->state]);
5713 pango_cairo_show_layout (cr, layout);
5722 gtk_entry_queue_draw (GtkEntry *entry)
5724 if (GTK_WIDGET_DRAWABLE (entry))
5725 gdk_window_invalidate_rect (entry->text_area, NULL, FALSE);
5729 _gtk_entry_reset_im_context (GtkEntry *entry)
5731 if (entry->need_im_reset)
5733 entry->need_im_reset = FALSE;
5734 gtk_im_context_reset (entry->im_context);
5739 gtk_entry_find_position (GtkEntry *entry,
5742 PangoLayout *layout;
5743 PangoLayoutLine *line;
5750 layout = gtk_entry_ensure_layout (entry, TRUE);
5751 text = pango_layout_get_text (layout);
5752 cursor_index = g_utf8_offset_to_pointer (text, entry->current_pos) - text;
5754 line = pango_layout_get_lines_readonly (layout)->data;
5755 pango_layout_line_x_to_index (line, x * PANGO_SCALE, &index, &trailing);
5757 if (index >= cursor_index && entry->preedit_length)
5759 if (index >= cursor_index + entry->preedit_length)
5760 index -= entry->preedit_length;
5763 index = cursor_index;
5768 pos = g_utf8_pointer_to_offset (text, text + index);
5775 gtk_entry_get_cursor_locations (GtkEntry *entry,
5780 if (!entry->visible && !entry->invisible_char)
5790 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
5791 const gchar *text = pango_layout_get_text (layout);
5792 PangoRectangle strong_pos, weak_pos;
5795 if (type == CURSOR_STANDARD)
5797 index = g_utf8_offset_to_pointer (text, entry->current_pos + entry->preedit_cursor) - text;
5799 else /* type == CURSOR_DND */
5801 index = g_utf8_offset_to_pointer (text, entry->dnd_position) - text;
5803 if (entry->dnd_position > entry->current_pos)
5806 index += entry->preedit_length;
5809 gint preedit_len_chars = g_utf8_strlen (text, -1) - entry->text_length;
5810 index += preedit_len_chars * g_unichar_to_utf8 (entry->invisible_char, NULL);
5815 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
5818 *strong_x = strong_pos.x / PANGO_SCALE;
5821 *weak_x = weak_pos.x / PANGO_SCALE;
5826 gtk_entry_adjust_scroll (GtkEntry *entry)
5828 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
5829 gint min_offset, max_offset;
5830 gint text_area_width, text_width;
5831 GtkBorder inner_border;
5832 gint strong_x, weak_x;
5833 gint strong_xoffset, weak_xoffset;
5835 PangoLayout *layout;
5836 PangoLayoutLine *line;
5837 PangoRectangle logical_rect;
5839 if (!GTK_WIDGET_REALIZED (entry))
5842 _gtk_entry_effective_inner_border (entry, &inner_border);
5844 gdk_drawable_get_size (entry->text_area, &text_area_width, NULL);
5845 text_area_width -= inner_border.left + inner_border.right;
5846 if (text_area_width < 0)
5847 text_area_width = 0;
5849 layout = gtk_entry_ensure_layout (entry, TRUE);
5850 line = pango_layout_get_lines_readonly (layout)->data;
5852 pango_layout_line_get_extents (line, NULL, &logical_rect);
5854 /* Display as much text as we can */
5856 if (entry->resolved_dir == PANGO_DIRECTION_LTR)
5857 xalign = priv->xalign;
5859 xalign = 1.0 - priv->xalign;
5861 text_width = PANGO_PIXELS(logical_rect.width);
5863 if (text_width > text_area_width)
5866 max_offset = text_width - text_area_width;
5870 min_offset = (text_width - text_area_width) * xalign;
5871 max_offset = min_offset;
5874 entry->scroll_offset = CLAMP (entry->scroll_offset, min_offset, max_offset);
5876 /* And make sure cursors are on screen. Note that the cursor is
5877 * actually drawn one pixel into the INNER_BORDER space on
5878 * the right, when the scroll is at the utmost right. This
5879 * looks better to to me than confining the cursor inside the
5880 * border entirely, though it means that the cursor gets one
5881 * pixel closer to the edge of the widget on the right than
5882 * on the left. This might need changing if one changed
5883 * INNER_BORDER from 2 to 1, as one would do on a
5884 * small-screen-real-estate display.
5886 * We always make sure that the strong cursor is on screen, and
5887 * put the weak cursor on screen if possible.
5890 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, &weak_x);
5892 strong_xoffset = strong_x - entry->scroll_offset;
5894 if (strong_xoffset < 0)
5896 entry->scroll_offset += strong_xoffset;
5899 else if (strong_xoffset > text_area_width)
5901 entry->scroll_offset += strong_xoffset - text_area_width;
5902 strong_xoffset = text_area_width;
5905 weak_xoffset = weak_x - entry->scroll_offset;
5907 if (weak_xoffset < 0 && strong_xoffset - weak_xoffset <= text_area_width)
5909 entry->scroll_offset += weak_xoffset;
5911 else if (weak_xoffset > text_area_width &&
5912 strong_xoffset - (weak_xoffset - text_area_width) >= 0)
5914 entry->scroll_offset += weak_xoffset - text_area_width;
5917 g_object_notify (G_OBJECT (entry), "scroll-offset");
5921 gtk_entry_move_adjustments (GtkEntry *entry)
5923 PangoContext *context;
5924 PangoFontMetrics *metrics;
5925 gint x, layout_x, border_x, border_y;
5927 GtkAdjustment *adjustment;
5929 adjustment = g_object_get_qdata (G_OBJECT (entry), quark_cursor_hadjustment);
5933 /* Cursor position, layout offset, border width, and widget allocation */
5934 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &x, NULL);
5935 get_layout_position (entry, &layout_x, NULL);
5936 _gtk_entry_get_borders (entry, &border_x, &border_y);
5937 x += entry->widget.allocation.x + layout_x + border_x;
5939 /* Approximate width of a char, so user can see what is ahead/behind */
5940 context = gtk_widget_get_pango_context (GTK_WIDGET (entry));
5941 metrics = pango_context_get_metrics (context,
5942 entry->widget.style->font_desc,
5943 pango_context_get_language (context));
5944 char_width = pango_font_metrics_get_approximate_char_width (metrics) / PANGO_SCALE;
5947 gtk_adjustment_clamp_page (adjustment,
5948 x - (char_width + 1), /* one char + one pixel before */
5949 x + (char_width + 2)); /* one char + cursor + one pixel after */
5953 gtk_entry_move_visually (GtkEntry *entry,
5958 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
5961 text = pango_layout_get_text (layout);
5963 index = g_utf8_offset_to_pointer (text, start) - text;
5967 int new_index, new_trailing;
5968 gboolean split_cursor;
5971 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
5972 "gtk-split-cursor", &split_cursor,
5979 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
5980 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
5982 strong = keymap_direction == entry->resolved_dir;
5987 pango_layout_move_cursor_visually (layout, strong, index, 0, 1, &new_index, &new_trailing);
5992 pango_layout_move_cursor_visually (layout, strong, index, 0, -1, &new_index, &new_trailing);
5998 else if (new_index != G_MAXINT)
6001 while (new_trailing--)
6002 index = g_utf8_next_char (text + index) - text;
6005 return g_utf8_pointer_to_offset (text, text + index);
6009 gtk_entry_move_logically (GtkEntry *entry,
6013 gint new_pos = start;
6015 /* Prevent any leak of information */
6016 if (!entry->visible)
6018 new_pos = CLAMP (start + count, 0, entry->text_length);
6020 else if (entry->text)
6022 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6023 PangoLogAttr *log_attrs;
6026 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6028 while (count > 0 && new_pos < entry->text_length)
6032 while (new_pos < entry->text_length && !log_attrs[new_pos].is_cursor_position);
6036 while (count < 0 && new_pos > 0)
6040 while (new_pos > 0 && !log_attrs[new_pos].is_cursor_position);
6052 gtk_entry_move_forward_word (GtkEntry *entry,
6054 gboolean allow_whitespace)
6056 gint new_pos = start;
6058 /* Prevent any leak of information */
6059 if (!entry->visible)
6061 new_pos = entry->text_length;
6063 else if (entry->text && (new_pos < entry->text_length))
6065 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6066 PangoLogAttr *log_attrs;
6069 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6071 /* Find the next word boundary */
6073 while (new_pos < n_attrs - 1 && !(log_attrs[new_pos].is_word_end ||
6074 (log_attrs[new_pos].is_word_start && allow_whitespace)))
6085 gtk_entry_move_backward_word (GtkEntry *entry,
6087 gboolean allow_whitespace)
6089 gint new_pos = start;
6091 /* Prevent any leak of information */
6092 if (!entry->visible)
6096 else if (entry->text && start > 0)
6098 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6099 PangoLogAttr *log_attrs;
6102 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6104 new_pos = start - 1;
6106 /* Find the previous word boundary */
6107 while (new_pos > 0 && !(log_attrs[new_pos].is_word_start ||
6108 (log_attrs[new_pos].is_word_end && allow_whitespace)))
6118 gtk_entry_delete_whitespace (GtkEntry *entry)
6120 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6121 PangoLogAttr *log_attrs;
6125 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6127 start = end = entry->current_pos;
6129 while (start > 0 && log_attrs[start-1].is_white)
6132 while (end < n_attrs && log_attrs[end].is_white)
6138 gtk_editable_delete_text (GTK_EDITABLE (entry), start, end);
6143 gtk_entry_select_word (GtkEntry *entry)
6145 gint start_pos = gtk_entry_move_backward_word (entry, entry->current_pos, TRUE);
6146 gint end_pos = gtk_entry_move_forward_word (entry, entry->current_pos, TRUE);
6148 gtk_editable_select_region (GTK_EDITABLE (entry), start_pos, end_pos);
6152 gtk_entry_select_line (GtkEntry *entry)
6154 gtk_editable_select_region (GTK_EDITABLE (entry), 0, -1);
6158 * Like gtk_editable_get_chars, but handle not-visible entries
6162 gtk_entry_get_public_chars (GtkEntry *entry,
6167 end = entry->text_length;
6170 return gtk_editable_get_chars (GTK_EDITABLE (entry), start, end);
6171 else if (!entry->invisible_char)
6172 return g_strdup ("");
6175 GString *str = g_string_new (NULL);
6176 append_char (str, entry->invisible_char, end - start);
6177 return g_string_free (str, FALSE);
6182 truncate_multiline (const gchar *text)
6187 text[length] && text[length] != '\n' && text[length] != '\r';
6194 paste_received (GtkClipboard *clipboard,
6198 GtkEntry *entry = GTK_ENTRY (data);
6199 GtkEditable *editable = GTK_EDITABLE (entry);
6200 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
6202 if (entry->button == 2)
6204 gint pos, start, end;
6205 pos = priv->insert_pos;
6206 gtk_editable_get_selection_bounds (editable, &start, &end);
6207 if (!((start <= pos && pos <= end) || (end <= pos && pos <= start)))
6208 gtk_editable_select_region (editable, pos, pos);
6213 gint pos, start, end;
6215 gboolean popup_completion;
6216 GtkEntryCompletion *completion;
6218 completion = gtk_entry_get_completion (entry);
6220 if (entry->truncate_multiline)
6221 length = truncate_multiline (text);
6223 /* only complete if the selection is at the end */
6224 popup_completion = (entry->text_length == MAX (entry->current_pos, entry->selection_bound));
6228 if (GTK_WIDGET_MAPPED (completion->priv->popup_window))
6229 _gtk_entry_completion_popdown (completion);
6231 if (!popup_completion && completion->priv->changed_id > 0)
6232 g_signal_handler_block (entry, completion->priv->changed_id);
6235 begin_change (entry);
6236 g_object_freeze_notify (G_OBJECT (entry));
6237 if (gtk_editable_get_selection_bounds (editable, &start, &end))
6238 gtk_editable_delete_text (editable, start, end);
6240 pos = entry->current_pos;
6241 gtk_editable_insert_text (editable, text, length, &pos);
6242 gtk_editable_set_position (editable, pos);
6243 g_object_thaw_notify (G_OBJECT (entry));
6247 !popup_completion && completion->priv->changed_id > 0)
6248 g_signal_handler_unblock (entry, completion->priv->changed_id);
6251 g_object_unref (entry);
6255 gtk_entry_paste (GtkEntry *entry,
6258 g_object_ref (entry);
6259 gtk_clipboard_request_text (gtk_widget_get_clipboard (GTK_WIDGET (entry), selection),
6260 paste_received, entry);
6264 primary_get_cb (GtkClipboard *clipboard,
6265 GtkSelectionData *selection_data,
6269 GtkEntry *entry = GTK_ENTRY (data);
6272 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end))
6274 gchar *str = gtk_entry_get_public_chars (entry, start, end);
6275 gtk_selection_data_set_text (selection_data, str, -1);
6281 primary_clear_cb (GtkClipboard *clipboard,
6284 GtkEntry *entry = GTK_ENTRY (data);
6286 gtk_editable_select_region (GTK_EDITABLE (entry), entry->current_pos, entry->current_pos);
6290 gtk_entry_update_primary_selection (GtkEntry *entry)
6292 GtkTargetList *list;
6293 GtkTargetEntry *targets;
6294 GtkClipboard *clipboard;
6298 if (!GTK_WIDGET_REALIZED (entry))
6301 list = gtk_target_list_new (NULL, 0);
6302 gtk_target_list_add_text_targets (list, 0);
6304 targets = gtk_target_table_new_from_list (list, &n_targets);
6306 clipboard = gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_PRIMARY);
6308 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end))
6310 if (!gtk_clipboard_set_with_owner (clipboard, targets, n_targets,
6311 primary_get_cb, primary_clear_cb, G_OBJECT (entry)))
6312 primary_clear_cb (clipboard, entry);
6316 if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (entry))
6317 gtk_clipboard_clear (clipboard);
6320 gtk_target_table_free (targets, n_targets);
6321 gtk_target_list_unref (list);
6325 gtk_entry_clear (GtkEntry *entry,
6326 GtkEntryIconPosition icon_pos)
6328 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
6329 EntryIconInfo *icon_info = priv->icons[icon_pos];
6331 if (!icon_info || icon_info->storage_type == GTK_IMAGE_EMPTY)
6334 g_object_freeze_notify (G_OBJECT (entry));
6336 /* Explicitly check, as the pointer may become invalidated
6337 * during destruction.
6339 if (GDK_IS_WINDOW (icon_info->window))
6340 gdk_window_hide (icon_info->window);
6342 if (icon_info->pixbuf)
6344 g_object_unref (icon_info->pixbuf);
6345 icon_info->pixbuf = NULL;
6348 switch (icon_info->storage_type)
6350 case GTK_IMAGE_PIXBUF:
6351 g_object_notify (G_OBJECT (entry),
6352 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-pixbuf" : "secondary-icon-pixbuf");
6355 case GTK_IMAGE_STOCK:
6356 g_free (icon_info->stock_id);
6357 icon_info->stock_id = NULL;
6358 g_object_notify (G_OBJECT (entry),
6359 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-stock" : "secondary-icon-stock");
6362 case GTK_IMAGE_ICON_NAME:
6363 g_free (icon_info->icon_name);
6364 icon_info->icon_name = NULL;
6365 g_object_notify (G_OBJECT (entry),
6366 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-name" : "secondary-icon-name");
6369 case GTK_IMAGE_GICON:
6370 if (icon_info->gicon)
6372 g_object_unref (icon_info->gicon);
6373 icon_info->gicon = NULL;
6375 g_object_notify (G_OBJECT (entry),
6376 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-gicon" : "secondary-icon-gicon");
6380 g_assert_not_reached ();
6384 icon_info->storage_type = GTK_IMAGE_EMPTY;
6385 g_object_notify (G_OBJECT (entry),
6386 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-storage-type" : "secondary-icon-storage-type");
6388 g_object_thaw_notify (G_OBJECT (entry));
6392 gtk_entry_ensure_pixbuf (GtkEntry *entry,
6393 GtkEntryIconPosition icon_pos)
6395 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
6396 EntryIconInfo *icon_info = priv->icons[icon_pos];
6398 GtkIconTheme *icon_theme;
6399 GtkSettings *settings;
6404 if (!icon_info || icon_info->pixbuf)
6407 switch (icon_info->storage_type)
6409 case GTK_IMAGE_EMPTY:
6410 case GTK_IMAGE_PIXBUF:
6412 case GTK_IMAGE_STOCK:
6413 state = GTK_WIDGET_STATE (entry);
6414 GTK_WIDGET_STATE (entry) = GTK_STATE_NORMAL;
6415 icon_info->pixbuf = gtk_widget_render_icon (GTK_WIDGET (entry),
6416 icon_info->stock_id,
6419 GTK_WIDGET_STATE (entry) = state;
6422 case GTK_IMAGE_ICON_NAME:
6423 screen = gtk_widget_get_screen (GTK_WIDGET (entry));
6426 icon_theme = gtk_icon_theme_get_for_screen (screen);
6427 settings = gtk_settings_get_for_screen (screen);
6429 gtk_icon_size_lookup_for_settings (settings,
6433 icon_info->pixbuf = gtk_icon_theme_load_icon (icon_theme,
6434 icon_info->icon_name,
6435 MIN (width, height),
6438 if (icon_info->pixbuf == NULL)
6440 state = GTK_WIDGET_STATE (entry);
6441 GTK_WIDGET_STATE (entry) = GTK_STATE_NORMAL;
6442 icon_info->pixbuf = gtk_widget_render_icon (GTK_WIDGET (entry),
6443 GTK_STOCK_MISSING_IMAGE,
6446 GTK_WIDGET_STATE (entry) = state;
6451 case GTK_IMAGE_GICON:
6452 screen = gtk_widget_get_screen (GTK_WIDGET (entry));
6455 icon_theme = gtk_icon_theme_get_for_screen (screen);
6456 settings = gtk_settings_get_for_screen (screen);
6458 gtk_icon_size_lookup_for_settings (settings,
6462 info = gtk_icon_theme_lookup_by_gicon (icon_theme,
6464 MIN (width, height),
6465 GTK_ICON_LOOKUP_USE_BUILTIN);
6468 icon_info->pixbuf = gtk_icon_info_load_icon (info, NULL);
6469 gtk_icon_info_free (info);
6472 if (icon_info->pixbuf == NULL)
6474 state = GTK_WIDGET_STATE (entry);
6475 GTK_WIDGET_STATE (entry) = GTK_STATE_NORMAL;
6476 icon_info->pixbuf = gtk_widget_render_icon (GTK_WIDGET (entry),
6477 GTK_STOCK_MISSING_IMAGE,
6480 GTK_WIDGET_STATE (entry) = state;
6486 g_assert_not_reached ();
6490 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
6491 gdk_window_show_unraised (icon_info->window);
6501 * Creates a new entry.
6503 * Return value: a new #GtkEntry.
6506 gtk_entry_new (void)
6508 return g_object_new (GTK_TYPE_ENTRY, NULL);
6512 * gtk_entry_new_with_max_length:
6513 * @max: the maximum length of the entry, or 0 for no maximum.
6514 * (other than the maximum length of entries.) The value passed in will
6515 * be clamped to the range 0-65536.
6517 * Creates a new #GtkEntry widget with the given maximum length.
6519 * Return value: a new #GtkEntry
6521 * Deprecated: Use gtk_entry_set_max_length() instead.
6524 gtk_entry_new_with_max_length (gint max)
6528 max = CLAMP (max, 0, MAX_SIZE);
6530 entry = g_object_new (GTK_TYPE_ENTRY, NULL);
6531 entry->text_max_length = max;
6533 return GTK_WIDGET (entry);
6537 * gtk_entry_set_text:
6538 * @entry: a #GtkEntry
6539 * @text: the new text
6541 * Sets the text in the widget to the given
6542 * value, replacing the current contents.
6545 gtk_entry_set_text (GtkEntry *entry,
6549 GtkEntryCompletion *completion;
6551 g_return_if_fail (GTK_IS_ENTRY (entry));
6552 g_return_if_fail (text != NULL);
6554 /* Actually setting the text will affect the cursor and selection;
6555 * if the contents don't actually change, this will look odd to the user.
6557 if (strcmp (entry->text, text) == 0)
6560 completion = gtk_entry_get_completion (entry);
6561 if (completion && completion->priv->changed_id > 0)
6562 g_signal_handler_block (entry, completion->priv->changed_id);
6564 begin_change (entry);
6565 g_object_freeze_notify (G_OBJECT (entry));
6566 gtk_editable_delete_text (GTK_EDITABLE (entry), 0, -1);
6569 gtk_editable_insert_text (GTK_EDITABLE (entry), text, strlen (text), &tmp_pos);
6570 g_object_thaw_notify (G_OBJECT (entry));
6573 if (completion && completion->priv->changed_id > 0)
6574 g_signal_handler_unblock (entry, completion->priv->changed_id);
6578 * gtk_entry_append_text:
6579 * @entry: a #GtkEntry
6580 * @text: the text to append
6582 * Appends the given text to the contents of the widget.
6584 * Deprecated: 2.0: Use gtk_editable_insert_text() instead.
6587 gtk_entry_append_text (GtkEntry *entry,
6592 g_return_if_fail (GTK_IS_ENTRY (entry));
6593 g_return_if_fail (text != NULL);
6595 tmp_pos = entry->text_length;
6596 gtk_editable_insert_text (GTK_EDITABLE (entry), text, -1, &tmp_pos);
6600 * gtk_entry_prepend_text:
6601 * @entry: a #GtkEntry
6602 * @text: the text to prepend
6604 * Prepends the given text to the contents of the widget.
6606 * Deprecated: 2.0: Use gtk_editable_insert_text() instead.
6609 gtk_entry_prepend_text (GtkEntry *entry,
6614 g_return_if_fail (GTK_IS_ENTRY (entry));
6615 g_return_if_fail (text != NULL);
6618 gtk_editable_insert_text (GTK_EDITABLE (entry), text, -1, &tmp_pos);
6622 * gtk_entry_set_position:
6623 * @entry: a #GtkEntry
6624 * @position: the position of the cursor. The cursor is displayed
6625 * before the character with the given (base 0) index in the widget.
6626 * The value must be less than or equal to the number of characters
6627 * in the widget. A value of -1 indicates that the position should
6628 * be set after the last character in the entry. Note that this
6629 * position is in characters, not in bytes.
6631 * Sets the cursor position in an entry to the given value.
6633 * Deprecated: 2.0: Use gtk_editable_set_position() instead.
6636 gtk_entry_set_position (GtkEntry *entry,
6639 g_return_if_fail (GTK_IS_ENTRY (entry));
6641 gtk_editable_set_position (GTK_EDITABLE (entry), position);
6645 * gtk_entry_set_visibility:
6646 * @entry: a #GtkEntry
6647 * @visible: %TRUE if the contents of the entry are displayed
6650 * Sets whether the contents of the entry are visible or not.
6651 * When visibility is set to %FALSE, characters are displayed
6652 * as the invisible char, and will also appear that way when
6653 * the text in the entry widget is copied elsewhere.
6655 * By default, GTK+ picks the best invisible character available
6656 * in the current font, but it can be changed with
6657 * gtk_entry_set_invisible_char().
6660 gtk_entry_set_visibility (GtkEntry *entry,
6663 g_return_if_fail (GTK_IS_ENTRY (entry));
6665 visible = visible != FALSE;
6667 if (entry->visible != visible)
6669 entry->visible = visible;
6671 g_object_notify (G_OBJECT (entry), "visibility");
6672 gtk_entry_recompute (entry);
6677 * gtk_entry_get_visibility:
6678 * @entry: a #GtkEntry
6680 * Retrieves whether the text in @entry is visible. See
6681 * gtk_entry_set_visibility().
6683 * Return value: %TRUE if the text is currently visible
6686 gtk_entry_get_visibility (GtkEntry *entry)
6688 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
6690 return entry->visible;
6694 * gtk_entry_set_invisible_char:
6695 * @entry: a #GtkEntry
6696 * @ch: a Unicode character
6698 * Sets the character to use in place of the actual text when
6699 * gtk_entry_set_visibility() has been called to set text visibility
6700 * to %FALSE. i.e. this is the character used in "password mode" to
6701 * show the user how many characters have been typed. By default, GTK+
6702 * picks the best invisible char available in the current font. If you
6703 * set the invisible char to 0, then the user will get no feedback
6704 * at all; there will be no text on the screen as they type.
6707 gtk_entry_set_invisible_char (GtkEntry *entry,
6710 GtkEntryPrivate *priv;
6712 g_return_if_fail (GTK_IS_ENTRY (entry));
6714 priv = GTK_ENTRY_GET_PRIVATE (entry);
6716 if (!priv->invisible_char_set)
6718 priv->invisible_char_set = TRUE;
6719 g_object_notify (G_OBJECT (entry), "invisible-char-set");
6722 if (ch == entry->invisible_char)
6725 entry->invisible_char = ch;
6726 g_object_notify (G_OBJECT (entry), "invisible-char");
6727 gtk_entry_recompute (entry);
6731 * gtk_entry_get_invisible_char:
6732 * @entry: a #GtkEntry
6734 * Retrieves the character displayed in place of the real characters
6735 * for entries with visibility set to false. See gtk_entry_set_invisible_char().
6737 * Return value: the current invisible char, or 0, if the entry does not
6738 * show invisible text at all.
6741 gtk_entry_get_invisible_char (GtkEntry *entry)
6743 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
6745 return entry->invisible_char;
6749 * gtk_entry_unset_invisible_char:
6750 * @entry: a #GtkEntry
6752 * Unsets the invisible char previously set with
6753 * gtk_entry_set_invisible_char(). So that the
6754 * default invisible char is used again.
6759 gtk_entry_unset_invisible_char (GtkEntry *entry)
6761 GtkEntryPrivate *priv;
6764 g_return_if_fail (GTK_IS_ENTRY (entry));
6766 priv = GTK_ENTRY_GET_PRIVATE (entry);
6768 if (!priv->invisible_char_set)
6771 priv->invisible_char_set = FALSE;
6772 ch = find_invisible_char (GTK_WIDGET (entry));
6774 if (entry->invisible_char != ch)
6776 entry->invisible_char = ch;
6777 g_object_notify (G_OBJECT (entry), "invisible-char");
6780 g_object_notify (G_OBJECT (entry), "invisible-char-set");
6781 gtk_entry_recompute (entry);
6785 * gtk_entry_set_editable:
6786 * @entry: a #GtkEntry
6787 * @editable: %TRUE if the user is allowed to edit the text
6790 * Determines if the user can edit the text in the editable
6793 * Deprecated: 2.0: Use gtk_editable_set_editable() instead.
6796 gtk_entry_set_editable (GtkEntry *entry,
6799 g_return_if_fail (GTK_IS_ENTRY (entry));
6801 gtk_editable_set_editable (GTK_EDITABLE (entry), editable);
6805 * gtk_entry_set_overwrite_mode:
6806 * @entry: a #GtkEntry
6807 * @overwrite: new value
6809 * Sets whether the text is overwritten when typing in the #GtkEntry.
6814 gtk_entry_set_overwrite_mode (GtkEntry *entry,
6817 g_return_if_fail (GTK_IS_ENTRY (entry));
6819 if (entry->overwrite_mode == overwrite)
6822 gtk_entry_toggle_overwrite (entry);
6824 g_object_notify (G_OBJECT (entry), "overwrite-mode");
6828 * gtk_entry_get_overwrite_mode:
6829 * @entry: a #GtkEntry
6831 * Gets the value set by gtk_entry_set_overwrite_mode().
6833 * Return value: whether the text is overwritten when typing.
6838 gtk_entry_get_overwrite_mode (GtkEntry *entry)
6840 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
6842 return entry->overwrite_mode;
6846 * gtk_entry_get_text:
6847 * @entry: a #GtkEntry
6849 * Retrieves the contents of the entry widget.
6850 * See also gtk_editable_get_chars().
6852 * Return value: a pointer to the contents of the widget as a
6853 * string. This string points to internally allocated
6854 * storage in the widget and must not be freed, modified or
6857 G_CONST_RETURN gchar*
6858 gtk_entry_get_text (GtkEntry *entry)
6860 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
6866 * gtk_entry_select_region:
6867 * @entry: a #GtkEntry
6868 * @start: the starting position
6869 * @end: the end position
6871 * Selects a region of text. The characters that are selected are
6872 * those characters at positions from @start_pos up to, but not
6873 * including @end_pos. If @end_pos is negative, then the the characters
6874 * selected will be those characters from @start_pos to the end of
6877 * Deprecated: 2.0: Use gtk_editable_select_region() instead.
6880 gtk_entry_select_region (GtkEntry *entry,
6884 gtk_editable_select_region (GTK_EDITABLE (entry), start, end);
6888 * gtk_entry_set_max_length:
6889 * @entry: a #GtkEntry
6890 * @max: the maximum length of the entry, or 0 for no maximum.
6891 * (other than the maximum length of entries.) The value passed in will
6892 * be clamped to the range 0-65536.
6894 * Sets the maximum allowed length of the contents of the widget. If
6895 * the current contents are longer than the given length, then they
6896 * will be truncated to fit.
6899 gtk_entry_set_max_length (GtkEntry *entry,
6902 g_return_if_fail (GTK_IS_ENTRY (entry));
6904 max = CLAMP (max, 0, MAX_SIZE);
6906 if (max > 0 && entry->text_length > max)
6907 gtk_editable_delete_text (GTK_EDITABLE (entry), max, -1);
6909 entry->text_max_length = max;
6910 g_object_notify (G_OBJECT (entry), "max-length");
6914 * gtk_entry_get_max_length:
6915 * @entry: a #GtkEntry
6917 * Retrieves the maximum allowed length of the text in
6918 * @entry. See gtk_entry_set_max_length().
6920 * Return value: the maximum allowed number of characters
6921 * in #GtkEntry, or 0 if there is no maximum.
6924 gtk_entry_get_max_length (GtkEntry *entry)
6926 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
6928 return entry->text_max_length;
6932 * gtk_entry_get_text_length:
6933 * @entry: a #GtkEntry
6935 * Retrieves the current length of the text in
6938 * Return value: the current number of characters
6939 * in #GtkEntry, or 0 if there are none.
6944 gtk_entry_get_text_length (GtkEntry *entry)
6946 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
6948 return entry->text_length;
6952 * gtk_entry_set_activates_default:
6953 * @entry: a #GtkEntry
6954 * @setting: %TRUE to activate window's default widget on Enter keypress
6956 * If @setting is %TRUE, pressing Enter in the @entry will activate the default
6957 * widget for the window containing the entry. This usually means that
6958 * the dialog box containing the entry will be closed, since the default
6959 * widget is usually one of the dialog buttons.
6961 * (For experts: if @setting is %TRUE, the entry calls
6962 * gtk_window_activate_default() on the window containing the entry, in
6963 * the default handler for the #GtkWidget::activate signal.)
6966 gtk_entry_set_activates_default (GtkEntry *entry,
6969 g_return_if_fail (GTK_IS_ENTRY (entry));
6970 setting = setting != FALSE;
6972 if (setting != entry->activates_default)
6974 entry->activates_default = setting;
6975 g_object_notify (G_OBJECT (entry), "activates-default");
6980 * gtk_entry_get_activates_default:
6981 * @entry: a #GtkEntry
6983 * Retrieves the value set by gtk_entry_set_activates_default().
6985 * Return value: %TRUE if the entry will activate the default widget
6988 gtk_entry_get_activates_default (GtkEntry *entry)
6990 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
6992 return entry->activates_default;
6996 * gtk_entry_set_width_chars:
6997 * @entry: a #GtkEntry
6998 * @n_chars: width in chars
7000 * Changes the size request of the entry to be about the right size
7001 * for @n_chars characters. Note that it changes the size
7002 * <emphasis>request</emphasis>, the size can still be affected by
7003 * how you pack the widget into containers. If @n_chars is -1, the
7004 * size reverts to the default entry size.
7007 gtk_entry_set_width_chars (GtkEntry *entry,
7010 g_return_if_fail (GTK_IS_ENTRY (entry));
7012 if (entry->width_chars != n_chars)
7014 entry->width_chars = n_chars;
7015 g_object_notify (G_OBJECT (entry), "width-chars");
7016 gtk_widget_queue_resize (GTK_WIDGET (entry));
7021 * gtk_entry_get_width_chars:
7022 * @entry: a #GtkEntry
7024 * Gets the value set by gtk_entry_set_width_chars().
7026 * Return value: number of chars to request space for, or negative if unset
7029 gtk_entry_get_width_chars (GtkEntry *entry)
7031 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7033 return entry->width_chars;
7037 * gtk_entry_set_has_frame:
7038 * @entry: a #GtkEntry
7039 * @setting: new value
7041 * Sets whether the entry has a beveled frame around it.
7044 gtk_entry_set_has_frame (GtkEntry *entry,
7047 g_return_if_fail (GTK_IS_ENTRY (entry));
7049 setting = (setting != FALSE);
7051 if (entry->has_frame == setting)
7054 gtk_widget_queue_resize (GTK_WIDGET (entry));
7055 entry->has_frame = setting;
7056 g_object_notify (G_OBJECT (entry), "has-frame");
7060 * gtk_entry_get_has_frame:
7061 * @entry: a #GtkEntry
7063 * Gets the value set by gtk_entry_set_has_frame().
7065 * Return value: whether the entry has a beveled frame
7068 gtk_entry_get_has_frame (GtkEntry *entry)
7070 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7072 return entry->has_frame;
7076 * gtk_entry_set_inner_border:
7077 * @entry: a #GtkEntry
7078 * @border: a #GtkBorder, or %NULL
7080 * Sets %entry's inner-border property to %border, or clears it if %NULL
7081 * is passed. The inner-border is the area around the entry's text, but
7084 * If set, this property overrides the inner-border style property.
7085 * Overriding the style-provided border is useful when you want to do
7086 * in-place editing of some text in a canvas or list widget, where
7087 * pixel-exact positioning of the entry is important.
7092 gtk_entry_set_inner_border (GtkEntry *entry,
7093 const GtkBorder *border)
7095 g_return_if_fail (GTK_IS_ENTRY (entry));
7097 gtk_widget_queue_resize (GTK_WIDGET (entry));
7100 g_object_set_qdata_full (G_OBJECT (entry), quark_inner_border,
7101 gtk_border_copy (border),
7102 (GDestroyNotify) gtk_border_free);
7104 g_object_set_qdata (G_OBJECT (entry), quark_inner_border, NULL);
7106 g_object_notify (G_OBJECT (entry), "inner-border");
7110 * gtk_entry_get_inner_border:
7111 * @entry: a #GtkEntry
7113 * This function returns the entry's #GtkEntry:inner-border property. See
7114 * gtk_entry_set_inner_border() for more information.
7116 * Return value: the entry's #GtkBorder, or %NULL if none was set.
7120 G_CONST_RETURN GtkBorder *
7121 gtk_entry_get_inner_border (GtkEntry *entry)
7123 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7125 return g_object_get_qdata (G_OBJECT (entry), quark_inner_border);
7129 * gtk_entry_get_layout:
7130 * @entry: a #GtkEntry
7132 * Gets the #PangoLayout used to display the entry.
7133 * The layout is useful to e.g. convert text positions to
7134 * pixel positions, in combination with gtk_entry_get_layout_offsets().
7135 * The returned layout is owned by the entry and must not be
7136 * modified or freed by the caller.
7138 * Keep in mind that the layout text may contain a preedit string, so
7139 * gtk_entry_layout_index_to_text_index() and
7140 * gtk_entry_text_index_to_layout_index() are needed to convert byte
7141 * indices in the layout to byte indices in the entry contents.
7143 * Return value: the #PangoLayout for this entry
7146 gtk_entry_get_layout (GtkEntry *entry)
7148 PangoLayout *layout;
7150 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7152 layout = gtk_entry_ensure_layout (entry, TRUE);
7159 * gtk_entry_layout_index_to_text_index:
7160 * @entry: a #GtkEntry
7161 * @layout_index: byte index into the entry layout text
7163 * Converts from a position in the entry contents (returned
7164 * by gtk_entry_get_text()) to a position in the
7165 * entry's #PangoLayout (returned by gtk_entry_get_layout(),
7166 * with text retrieved via pango_layout_get_text()).
7168 * Return value: byte index into the entry contents
7171 gtk_entry_layout_index_to_text_index (GtkEntry *entry,
7174 PangoLayout *layout;
7178 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7180 layout = gtk_entry_ensure_layout (entry, TRUE);
7181 text = pango_layout_get_text (layout);
7182 cursor_index = g_utf8_offset_to_pointer (text, entry->current_pos) - text;
7184 if (layout_index >= cursor_index && entry->preedit_length)
7186 if (layout_index >= cursor_index + entry->preedit_length)
7187 layout_index -= entry->preedit_length;
7189 layout_index = cursor_index;
7192 return layout_index;
7196 * gtk_entry_text_index_to_layout_index:
7197 * @entry: a #GtkEntry
7198 * @text_index: byte index into the entry contents
7200 * Converts from a position in the entry's #PangoLayout (returned by
7201 * gtk_entry_get_layout()) to a position in the entry contents
7202 * (returned by gtk_entry_get_text()).
7204 * Return value: byte index into the entry layout text
7207 gtk_entry_text_index_to_layout_index (GtkEntry *entry,
7210 PangoLayout *layout;
7213 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7215 layout = gtk_entry_ensure_layout (entry, TRUE);
7216 text = pango_layout_get_text (layout);
7217 cursor_index = g_utf8_offset_to_pointer (text, entry->current_pos) - text;
7219 if (text_index > cursor_index)
7220 text_index += entry->preedit_length;
7226 * gtk_entry_get_layout_offsets:
7227 * @entry: a #GtkEntry
7228 * @x: location to store X offset of layout, or %NULL
7229 * @y: location to store Y offset of layout, or %NULL
7232 * Obtains the position of the #PangoLayout used to render text
7233 * in the entry, in widget coordinates. Useful if you want to line
7234 * up the text in an entry with some other text, e.g. when using the
7235 * entry to implement editable cells in a sheet widget.
7237 * Also useful to convert mouse events into coordinates inside the
7238 * #PangoLayout, e.g. to take some action if some part of the entry text
7241 * Note that as the user scrolls around in the entry the offsets will
7242 * change; you'll need to connect to the "notify::scroll-offset"
7243 * signal to track this. Remember when using the #PangoLayout
7244 * functions you need to convert to and from pixels using
7245 * PANGO_PIXELS() or #PANGO_SCALE.
7247 * Keep in mind that the layout text may contain a preedit string, so
7248 * gtk_entry_layout_index_to_text_index() and
7249 * gtk_entry_text_index_to_layout_index() are needed to convert byte
7250 * indices in the layout to byte indices in the entry contents.
7253 gtk_entry_get_layout_offsets (GtkEntry *entry,
7257 gint text_area_x, text_area_y;
7259 g_return_if_fail (GTK_IS_ENTRY (entry));
7261 /* this gets coords relative to text area */
7262 get_layout_position (entry, x, y);
7264 /* convert to widget coords */
7265 gtk_entry_get_text_area_size (entry, &text_area_x, &text_area_y, NULL, NULL);
7276 * gtk_entry_set_alignment:
7277 * @entry: a #GtkEntry
7278 * @xalign: The horizontal alignment, from 0 (left) to 1 (right).
7279 * Reversed for RTL layouts
7281 * Sets the alignment for the contents of the entry. This controls
7282 * the horizontal positioning of the contents when the displayed
7283 * text is shorter than the width of the entry.
7288 gtk_entry_set_alignment (GtkEntry *entry, gfloat xalign)
7290 GtkEntryPrivate *priv;
7292 g_return_if_fail (GTK_IS_ENTRY (entry));
7294 priv = GTK_ENTRY_GET_PRIVATE (entry);
7298 else if (xalign > 1.0)
7301 if (xalign != priv->xalign)
7303 priv->xalign = xalign;
7305 gtk_entry_recompute (entry);
7307 g_object_notify (G_OBJECT (entry), "xalign");
7312 * gtk_entry_get_alignment:
7313 * @entry: a #GtkEntry
7315 * Gets the value set by gtk_entry_set_alignment().
7317 * Return value: the alignment
7322 gtk_entry_get_alignment (GtkEntry *entry)
7324 GtkEntryPrivate *priv;
7326 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
7328 priv = GTK_ENTRY_GET_PRIVATE (entry);
7330 return priv->xalign;
7334 * gtk_entry_set_icon_from_pixbuf:
7335 * @entry: a #GtkEntry
7336 * @icon_pos: Icon position
7337 * @pixbuf: A #GdkPixbuf, or %NULL
7339 * Sets the icon shown in the specified position using a pixbuf.
7341 * If @pixbuf is %NULL, no icon will be shown in the specified position.
7346 gtk_entry_set_icon_from_pixbuf (GtkEntry *entry,
7347 GtkEntryIconPosition icon_pos,
7350 GtkEntryPrivate *priv;
7351 EntryIconInfo *icon_info;
7353 g_return_if_fail (GTK_IS_ENTRY (entry));
7354 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7356 priv = GTK_ENTRY_GET_PRIVATE (entry);
7358 if ((icon_info = priv->icons[icon_pos]) == NULL)
7359 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7361 g_object_freeze_notify (G_OBJECT (entry));
7364 g_object_ref (pixbuf);
7366 gtk_entry_clear (entry, icon_pos);
7370 icon_info->storage_type = GTK_IMAGE_PIXBUF;
7371 icon_info->pixbuf = pixbuf;
7373 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7375 g_object_notify (G_OBJECT (entry), "primary-icon-pixbuf");
7376 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7380 g_object_notify (G_OBJECT (entry), "secondary-icon-pixbuf");
7381 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7385 gtk_entry_ensure_pixbuf (entry, icon_pos);
7387 if (GTK_WIDGET_VISIBLE (entry))
7388 gtk_widget_queue_resize (GTK_WIDGET (entry));
7390 g_object_thaw_notify (G_OBJECT (entry));
7394 * gtk_entry_set_icon_from_stock:
7395 * @entry: A #GtkEntry
7396 * @icon_pos: Icon position
7397 * @stock_id: The name of the stock item, or %NULL
7399 * Sets the icon shown in the entry at the specified position from
7402 * If @stock_id is %NULL, no icon will be shown in the specified position.
7407 gtk_entry_set_icon_from_stock (GtkEntry *entry,
7408 GtkEntryIconPosition icon_pos,
7409 const gchar *stock_id)
7411 GtkEntryPrivate *priv;
7412 EntryIconInfo *icon_info;
7415 g_return_if_fail (GTK_IS_ENTRY (entry));
7416 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7418 priv = GTK_ENTRY_GET_PRIVATE (entry);
7420 if ((icon_info = priv->icons[icon_pos]) == NULL)
7421 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7423 g_object_freeze_notify (G_OBJECT (entry));
7425 gtk_widget_ensure_style (GTK_WIDGET (entry));
7427 /* need to dup before clearing */
7428 new_id = g_strdup (stock_id);
7430 gtk_entry_clear (entry, icon_pos);
7434 icon_info->storage_type = GTK_IMAGE_STOCK;
7435 icon_info->stock_id = new_id;
7437 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7439 g_object_notify (G_OBJECT (entry), "primary-icon-stock");
7440 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7444 g_object_notify (G_OBJECT (entry), "secondary-icon-stock");
7445 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7449 gtk_entry_ensure_pixbuf (entry, icon_pos);
7451 if (GTK_WIDGET_VISIBLE (entry))
7452 gtk_widget_queue_resize (GTK_WIDGET (entry));
7454 g_object_thaw_notify (G_OBJECT (entry));
7458 * gtk_entry_set_icon_from_icon_name:
7459 * @entry: A #GtkEntry
7460 * @icon_pos: The position at which to set the icon
7461 * @icon_name: An icon name, or %NULL
7463 * Sets the icon shown in the entry at the specified position
7464 * from the current icon theme.
7466 * If the icon name isn't known, a "broken image" icon will be displayed
7469 * If @icon_name is %NULL, no icon will be shown in the specified position.
7474 gtk_entry_set_icon_from_icon_name (GtkEntry *entry,
7475 GtkEntryIconPosition icon_pos,
7476 const gchar *icon_name)
7478 GtkEntryPrivate *priv;
7479 EntryIconInfo *icon_info;
7482 g_return_if_fail (GTK_IS_ENTRY (entry));
7483 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7485 priv = GTK_ENTRY_GET_PRIVATE (entry);
7487 if ((icon_info = priv->icons[icon_pos]) == NULL)
7488 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7490 g_object_freeze_notify (G_OBJECT (entry));
7492 gtk_widget_ensure_style (GTK_WIDGET (entry));
7494 /* need to dup before clearing */
7495 new_name = g_strdup (icon_name);
7497 gtk_entry_clear (entry, icon_pos);
7499 if (new_name != NULL)
7501 icon_info->storage_type = GTK_IMAGE_ICON_NAME;
7502 icon_info->icon_name = new_name;
7504 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7506 g_object_notify (G_OBJECT (entry), "primary-icon-name");
7507 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7511 g_object_notify (G_OBJECT (entry), "secondary-icon-name");
7512 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7516 gtk_entry_ensure_pixbuf (entry, icon_pos);
7518 if (GTK_WIDGET_VISIBLE (entry))
7519 gtk_widget_queue_resize (GTK_WIDGET (entry));
7521 g_object_thaw_notify (G_OBJECT (entry));
7525 * gtk_entry_set_icon_from_gicon:
7526 * @entry: A #GtkEntry
7527 * @icon_pos: The position at which to set the icon
7528 * @icon: The icon to set, or %NULL
7530 * Sets the icon shown in the entry at the specified position
7531 * from the current icon theme.
7532 * If the icon isn't known, a "broken image" icon will be displayed
7535 * If @icon is %NULL, no icon will be shown in the specified position.
7540 gtk_entry_set_icon_from_gicon (GtkEntry *entry,
7541 GtkEntryIconPosition icon_pos,
7544 GtkEntryPrivate *priv;
7545 EntryIconInfo *icon_info;
7547 g_return_if_fail (GTK_IS_ENTRY (entry));
7548 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7550 priv = GTK_ENTRY_GET_PRIVATE (entry);
7552 if ((icon_info = priv->icons[icon_pos]) == NULL)
7553 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7555 g_object_freeze_notify (G_OBJECT (entry));
7557 /* need to ref before clearing */
7559 g_object_ref (icon);
7561 gtk_entry_clear (entry, icon_pos);
7565 icon_info->storage_type = GTK_IMAGE_GICON;
7566 icon_info->gicon = icon;
7568 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7570 g_object_notify (G_OBJECT (entry), "primary-icon-gicon");
7571 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7575 g_object_notify (G_OBJECT (entry), "secondary-icon-gicon");
7576 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7580 gtk_entry_ensure_pixbuf (entry, icon_pos);
7582 if (GTK_WIDGET_VISIBLE (entry))
7583 gtk_widget_queue_resize (GTK_WIDGET (entry));
7585 g_object_thaw_notify (G_OBJECT (entry));
7589 * gtk_entry_set_icon_activatable:
7590 * @entry: A #GtkEntry
7591 * @icon_pos: Icon position
7592 * @activatable: %TRUE if the icon should be activatable
7594 * Sets whether the icon is activatable.
7599 gtk_entry_set_icon_activatable (GtkEntry *entry,
7600 GtkEntryIconPosition icon_pos,
7601 gboolean activatable)
7603 GtkEntryPrivate *priv;
7604 EntryIconInfo *icon_info;
7606 g_return_if_fail (GTK_IS_ENTRY (entry));
7607 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7609 priv = GTK_ENTRY_GET_PRIVATE (entry);
7611 if ((icon_info = priv->icons[icon_pos]) == NULL)
7612 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7614 activatable = activatable != FALSE;
7616 if (icon_info->nonactivatable != !activatable)
7618 icon_info->nonactivatable = !activatable;
7620 if (GTK_WIDGET_REALIZED (GTK_WIDGET (entry)))
7621 update_cursors (GTK_WIDGET (entry));
7623 g_object_notify (G_OBJECT (entry),
7624 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-activatable" : "secondary-icon-activatable");
7629 * gtk_entry_get_icon_activatable:
7630 * @entry: a #GtkEntry
7631 * @icon_pos: Icon position
7633 * Returns whether the icon is activatable.
7635 * Returns: %TRUE if the icon is activatable.
7640 gtk_entry_get_icon_activatable (GtkEntry *entry,
7641 GtkEntryIconPosition icon_pos)
7643 GtkEntryPrivate *priv;
7644 EntryIconInfo *icon_info;
7646 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7647 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), FALSE);
7649 priv = GTK_ENTRY_GET_PRIVATE (entry);
7650 icon_info = priv->icons[icon_pos];
7652 return (icon_info != NULL && !icon_info->nonactivatable);
7656 * gtk_entry_get_icon_pixbuf:
7657 * @entry: A #GtkEntry
7658 * @icon_pos: Icon position
7660 * Retrieves the image used for the icon.
7662 * Unlike the other methods of setting and getting icon data, this
7663 * method will work regardless of whether the icon was set using a
7664 * #GdkPixbuf, a #GIcon, a stock item, or an icon name.
7666 * Returns: A #GdkPixbuf, or %NULL if no icon is set for this position.
7671 gtk_entry_get_icon_pixbuf (GtkEntry *entry,
7672 GtkEntryIconPosition icon_pos)
7674 GtkEntryPrivate *priv;
7675 EntryIconInfo *icon_info;
7677 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7678 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7680 priv = GTK_ENTRY_GET_PRIVATE (entry);
7681 icon_info = priv->icons[icon_pos];
7686 gtk_entry_ensure_pixbuf (entry, icon_pos);
7688 return icon_info->pixbuf;
7692 * gtk_entry_get_icon_gicon:
7693 * @entry: A #GtkEntry
7694 * @icon_pos: Icon position
7696 * Retrieves the #GIcon used for the icon, or %NULL if there is
7697 * no icon or if the icon was set by some other method (e.g., by
7698 * stock, pixbuf, or icon name).
7700 * Returns: A #GIcon, or %NULL if no icon is set or if the icon
7706 gtk_entry_get_icon_gicon (GtkEntry *entry,
7707 GtkEntryIconPosition icon_pos)
7709 GtkEntryPrivate *priv;
7710 EntryIconInfo *icon_info;
7712 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7713 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7715 priv = GTK_ENTRY_GET_PRIVATE (entry);
7716 icon_info = priv->icons[icon_pos];
7721 return icon_info->storage_type == GTK_IMAGE_GICON ? icon_info->gicon : NULL;
7725 * gtk_entry_get_icon_stock:
7726 * @entry: A #GtkEntry
7727 * @icon_pos: Icon position
7729 * Retrieves the stock id used for the icon, or %NULL if there is
7730 * no icon or if the icon was set by some other method (e.g., by
7731 * pixbuf, icon name or gicon).
7733 * Returns: A stock id, or %NULL if no icon is set or if the icon
7734 * wasn't set from a stock id
7739 gtk_entry_get_icon_stock (GtkEntry *entry,
7740 GtkEntryIconPosition icon_pos)
7742 GtkEntryPrivate *priv;
7743 EntryIconInfo *icon_info;
7745 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7746 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7748 priv = GTK_ENTRY_GET_PRIVATE (entry);
7749 icon_info = priv->icons[icon_pos];
7754 return icon_info->storage_type == GTK_IMAGE_STOCK ? icon_info->stock_id : NULL;
7758 * gtk_entry_get_icon_name:
7759 * @entry: A #GtkEntry
7760 * @icon_pos: Icon position
7762 * Retrieves the icon name used for the icon, or %NULL if there is
7763 * no icon or if the icon was set by some other method (e.g., by
7764 * pixbuf, stock or gicon).
7766 * Returns: An icon name, or %NULL if no icon is set or if the icon
7767 * wasn't set from an icon name
7772 gtk_entry_get_icon_name (GtkEntry *entry,
7773 GtkEntryIconPosition icon_pos)
7775 GtkEntryPrivate *priv;
7776 EntryIconInfo *icon_info;
7778 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7779 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7781 priv = GTK_ENTRY_GET_PRIVATE (entry);
7782 icon_info = priv->icons[icon_pos];
7787 return icon_info->storage_type == GTK_IMAGE_ICON_NAME ? icon_info->icon_name : NULL;
7791 * gtk_entry_set_icon_sensitive:
7792 * @entry: A #GtkEntry
7793 * @icon_pos: Icon position
7794 * @sensitive: Specifies whether the icon should appear
7795 * sensitive or insensitive
7797 * Sets the sensitivity for the specified icon.
7802 gtk_entry_set_icon_sensitive (GtkEntry *entry,
7803 GtkEntryIconPosition icon_pos,
7806 GtkEntryPrivate *priv;
7807 EntryIconInfo *icon_info;
7809 g_return_if_fail (GTK_IS_ENTRY (entry));
7810 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7812 priv = GTK_ENTRY_GET_PRIVATE (entry);
7814 if ((icon_info = priv->icons[icon_pos]) == NULL)
7815 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7817 if (icon_info->insensitive != !sensitive)
7819 icon_info->insensitive = !sensitive;
7821 if (GTK_WIDGET_REALIZED (GTK_WIDGET (entry)))
7822 update_cursors (GTK_WIDGET (entry));
7824 g_object_notify (G_OBJECT (entry),
7825 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-sensitive" : "secondary-icon-sensitive");
7830 * gtk_entry_get_icon_sensitive:
7831 * @entry: a #GtkEntry
7832 * @icon_pos: Icon position
7834 * Returns whether the icon appears sensitive or insensitive.
7836 * Returns: %TRUE if the icon is sensitive.
7841 gtk_entry_get_icon_sensitive (GtkEntry *entry,
7842 GtkEntryIconPosition icon_pos)
7844 GtkEntryPrivate *priv;
7845 EntryIconInfo *icon_info;
7847 g_return_val_if_fail (GTK_IS_ENTRY (entry), TRUE);
7848 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), TRUE);
7850 priv = GTK_ENTRY_GET_PRIVATE (entry);
7851 icon_info = priv->icons[icon_pos];
7853 return (!icon_info || !icon_info->insensitive);
7858 * gtk_entry_get_icon_storage_type:
7859 * @entry: a #GtkEntry
7860 * @icon_pos: Icon position
7862 * Gets the type of representation being used by the icon
7863 * to store image data. If the icon has no image data,
7864 * the return value will be %GTK_IMAGE_EMPTY.
7866 * Return value: image representation being used
7871 gtk_entry_get_icon_storage_type (GtkEntry *entry,
7872 GtkEntryIconPosition icon_pos)
7874 GtkEntryPrivate *priv;
7875 EntryIconInfo *icon_info;
7877 g_return_val_if_fail (GTK_IS_ENTRY (entry), GTK_IMAGE_EMPTY);
7878 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), GTK_IMAGE_EMPTY);
7880 priv = GTK_ENTRY_GET_PRIVATE (entry);
7881 icon_info = priv->icons[icon_pos];
7884 return GTK_IMAGE_EMPTY;
7886 return icon_info->storage_type;
7890 * gtk_entry_get_icon_at_pos:
7891 * @entry: a #GtkEntry
7892 * @x: the x coordinate of the position to find
7893 * @y: the y coordinate of the position to find
7895 * Finds the icon at the given position and return its index.
7896 * If @x, @y doesn't lie inside an icon, -1 is returned.
7897 * This function is intended for use in a #GtkWidget::query-tooltip
7900 * Returns: the index of the icon at the given position, or -1
7905 gtk_entry_get_icon_at_pos (GtkEntry *entry,
7909 GtkAllocation primary;
7910 GtkAllocation secondary;
7912 g_return_val_if_fail (GTK_IS_ENTRY (entry), -1);
7914 get_icon_allocations (entry, &primary, &secondary);
7916 if (primary.x <= x && x < primary.x + primary.width &&
7917 primary.y <= y && y < primary.y + primary.height)
7918 return GTK_ENTRY_ICON_PRIMARY;
7920 if (secondary.x <= x && x < secondary.x + secondary.width &&
7921 secondary.y <= y && y < secondary.y + secondary.height)
7922 return GTK_ENTRY_ICON_SECONDARY;
7928 * gtk_entry_set_icon_drag_source:
7929 * @entry: a #GtkIconEntry
7930 * @icon_pos: icon position
7931 * @target_list: the targets (data formats) in which the data can be provided
7932 * @actions: a bitmask of the allowed drag actions
7934 * Sets up the icon at the given position so that GTK+ will start a drag
7935 * operation when the user clicks and drags the icon.
7937 * To handle the drag operation, you need to connect to the usual
7938 * #GtkWidget::drag-data-get (or possibly #GtkWidget::drag-data-delete)
7939 * signal, and use gtk_entry_get_current_icon_drag_source() in
7940 * your signal handler to find out if the drag was started from
7943 * By default, GTK+ uses the icon as the drag icon. You can use the
7944 * #GtkWidget::drag-begin signal to set a different icon. Note that you
7945 * have to use g_signal_connect_after() to ensure that your signal handler
7946 * gets executed after the default handler.
7949 gtk_entry_set_icon_drag_source (GtkEntry *entry,
7950 GtkEntryIconPosition icon_pos,
7951 GtkTargetList *target_list,
7952 GdkDragAction actions)
7954 GtkEntryPrivate *priv;
7955 EntryIconInfo *icon_info;
7957 g_return_if_fail (GTK_IS_ENTRY (entry));
7958 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7960 priv = GTK_ENTRY_GET_PRIVATE (entry);
7962 if ((icon_info = priv->icons[icon_pos]) == NULL)
7963 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7965 if (icon_info->target_list)
7966 gtk_target_list_unref (icon_info->target_list);
7967 icon_info->target_list = target_list;
7968 if (icon_info->target_list)
7969 gtk_target_list_ref (icon_info->target_list);
7971 icon_info->actions = actions;
7975 * gtk_entry_get_current_icon_drag_source:
7976 * @entry: a #GtkIconEntry
7978 * Returns the index of the icon which is the source of the current
7979 * DND operation, or -1.
7981 * This function is meant to be used in a #GtkWidget::drag-data-get
7984 * Returns: index of the icon which is the source of the current
7985 * DND operation, or -1.
7988 gtk_entry_get_current_icon_drag_source (GtkEntry *entry)
7990 GtkEntryPrivate *priv;
7991 EntryIconInfo *icon_info = NULL;
7994 g_return_val_if_fail (GTK_IS_ENTRY (entry), -1);
7996 priv = GTK_ENTRY_GET_PRIVATE (entry);
7998 for (i = 0; i < MAX_ICONS; i++)
8000 if ((icon_info = priv->icons[i]))
8002 if (icon_info->in_drag)
8011 ensure_has_tooltip (GtkEntry *entry)
8013 GtkEntryPrivate *priv;
8014 EntryIconInfo *icon_info;
8016 gboolean has_tooltip = FALSE;
8018 priv = GTK_ENTRY_GET_PRIVATE (entry);
8020 for (i = 0; i < MAX_ICONS; i++)
8022 if ((icon_info = priv->icons[i]) != NULL)
8024 if (icon_info->tooltip != NULL)
8032 gtk_widget_set_has_tooltip (GTK_WIDGET (entry), has_tooltip);
8036 * gtk_entry_get_icon_tooltip_text:
8037 * @entry: a #GtkEntry
8038 * @icon_pos: the icon position
8040 * Gets the contents of the tooltip on the icon at the specified
8041 * position in @entry.
8043 * Returns: the tooltip text, or %NULL. Free the returned string
8044 * with g_free() when done.
8049 gtk_entry_get_icon_tooltip_text (GtkEntry *entry,
8050 GtkEntryIconPosition icon_pos)
8052 GtkEntryPrivate *priv;
8053 EntryIconInfo *icon_info;
8056 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8057 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8059 priv = GTK_ENTRY_GET_PRIVATE (entry);
8060 icon_info = priv->icons[icon_pos];
8065 if (icon_info->tooltip &&
8066 !pango_parse_markup (icon_info->tooltip, -1, 0, NULL, &text, NULL, NULL))
8067 g_assert (NULL == text); /* text should still be NULL in case of markup errors */
8073 * gtk_entry_set_icon_tooltip_text:
8074 * @entry: a #GtkEntry
8075 * @icon_pos: the icon position
8076 * @tooltip: the contents of the tooltip for the icon, or %NULL
8078 * Sets @tooltip as the contents of the tooltip for the icon
8079 * at the specified position.
8081 * Use %NULL for @tooltip to remove an existing tooltip.
8083 * See also gtk_widget_set_tooltip_text() and
8084 * gtk_entry_set_icon_tooltip_markup().
8089 gtk_entry_set_icon_tooltip_text (GtkEntry *entry,
8090 GtkEntryIconPosition icon_pos,
8091 const gchar *tooltip)
8093 GtkEntryPrivate *priv;
8094 EntryIconInfo *icon_info;
8096 g_return_if_fail (GTK_IS_ENTRY (entry));
8097 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8099 priv = GTK_ENTRY_GET_PRIVATE (entry);
8101 if (!(icon_info = priv->icons[icon_pos]))
8102 icon_info = priv->icons[icon_pos];
8104 if (icon_info->tooltip)
8105 g_free (icon_info->tooltip);
8107 /* Treat an empty string as a NULL string,
8108 * because an empty string would be useless for a tooltip:
8110 if (tooltip && tooltip[0] == '\0')
8113 icon_info->tooltip = tooltip ? g_markup_escape_text (tooltip, -1) : NULL;
8115 ensure_has_tooltip (entry);
8119 * gtk_entry_get_icon_tooltip_markup:
8120 * @entry: a #GtkEntry
8121 * @icon_pos: the icon position
8123 * Gets the contents of the tooltip on the icon at the specified
8124 * position in @entry.
8126 * Returns: the tooltip text, or %NULL. Free the returned string
8127 * with g_free() when done.
8132 gtk_entry_get_icon_tooltip_markup (GtkEntry *entry,
8133 GtkEntryIconPosition icon_pos)
8135 GtkEntryPrivate *priv;
8136 EntryIconInfo *icon_info;
8139 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8140 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8142 priv = GTK_ENTRY_GET_PRIVATE (entry);
8143 icon_info = priv->icons[icon_pos];
8148 return g_strdup (icon_info->tooltip);
8152 * gtk_entry_set_icon_tooltip_markup:
8153 * @entry: a #GtkEntry
8154 * @icon_pos: the icon position
8155 * @tooltip: the contents of the tooltip for the icon, or %NULL
8157 * Sets @tooltip as the contents of the tooltip for the icon at
8158 * the specified position. @tooltip is assumed to be marked up with
8159 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
8161 * Use %NULL for @tooltip to remove an existing tooltip.
8163 * See also gtk_widget_set_tooltip_markup() and
8164 * gtk_enty_set_icon_tooltip_text().
8169 gtk_entry_set_icon_tooltip_markup (GtkEntry *entry,
8170 GtkEntryIconPosition icon_pos,
8171 const gchar *tooltip)
8173 GtkEntryPrivate *priv;
8174 EntryIconInfo *icon_info;
8176 g_return_if_fail (GTK_IS_ENTRY (entry));
8177 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8179 priv = GTK_ENTRY_GET_PRIVATE (entry);
8181 if (!(icon_info = priv->icons[icon_pos]))
8182 icon_info = priv->icons[icon_pos];
8184 if (icon_info->tooltip)
8185 g_free (icon_info->tooltip);
8187 /* Treat an empty string as a NULL string,
8188 * because an empty string would be useless for a tooltip:
8190 if (tooltip && tooltip[0] == '\0')
8193 icon_info->tooltip = g_strdup (tooltip);
8195 ensure_has_tooltip (entry);
8199 gtk_entry_query_tooltip (GtkWidget *widget,
8202 gboolean keyboard_tip,
8203 GtkTooltip *tooltip)
8206 GtkEntryPrivate *priv;
8207 EntryIconInfo *icon_info;
8210 entry = GTK_ENTRY (widget);
8211 priv = GTK_ENTRY_GET_PRIVATE (entry);
8215 icon_pos = gtk_entry_get_icon_at_pos (entry, x, y);
8218 if ((icon_info = priv->icons[icon_pos]) != NULL)
8220 if (icon_info->tooltip)
8222 gtk_tooltip_set_markup (tooltip, icon_info->tooltip);
8231 return GTK_WIDGET_CLASS (gtk_entry_parent_class)->query_tooltip (widget,
8238 /* Quick hack of a popup menu
8241 activate_cb (GtkWidget *menuitem,
8244 const gchar *signal = g_object_get_data (G_OBJECT (menuitem), "gtk-signal");
8245 g_signal_emit_by_name (entry, signal);
8250 gtk_entry_mnemonic_activate (GtkWidget *widget,
8251 gboolean group_cycling)
8253 gtk_widget_grab_focus (widget);
8258 append_action_signal (GtkEntry *entry,
8260 const gchar *stock_id,
8261 const gchar *signal,
8264 GtkWidget *menuitem = gtk_image_menu_item_new_from_stock (stock_id, NULL);
8266 g_object_set_data (G_OBJECT (menuitem), I_("gtk-signal"), (char *)signal);
8267 g_signal_connect (menuitem, "activate",
8268 G_CALLBACK (activate_cb), entry);
8270 gtk_widget_set_sensitive (menuitem, sensitive);
8272 gtk_widget_show (menuitem);
8273 gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
8277 popup_menu_detach (GtkWidget *attach_widget,
8280 GTK_ENTRY (attach_widget)->popup_menu = NULL;
8284 popup_position_func (GtkMenu *menu,
8290 GtkEntry *entry = GTK_ENTRY (user_data);
8291 GtkWidget *widget = GTK_WIDGET (entry);
8293 GtkRequisition menu_req;
8294 GdkRectangle monitor;
8295 GtkBorder inner_border;
8296 gint monitor_num, strong_x, height;
8298 g_return_if_fail (GTK_WIDGET_REALIZED (entry));
8300 gdk_window_get_origin (entry->text_area, x, y);
8302 screen = gtk_widget_get_screen (widget);
8303 monitor_num = gdk_screen_get_monitor_at_window (screen, entry->text_area);
8304 if (monitor_num < 0)
8306 gtk_menu_set_monitor (menu, monitor_num);
8308 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
8309 gtk_widget_size_request (entry->popup_menu, &menu_req);
8310 gdk_drawable_get_size (entry->text_area, NULL, &height);
8311 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
8312 _gtk_entry_effective_inner_border (entry, &inner_border);
8314 *x += inner_border.left + strong_x - entry->scroll_offset;
8315 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
8316 *x -= menu_req.width;
8318 if ((*y + height + menu_req.height) <= monitor.y + monitor.height)
8320 else if ((*y - menu_req.height) >= monitor.y)
8321 *y -= menu_req.height;
8322 else if (monitor.y + monitor.height - (*y + height) > *y)
8325 *y -= menu_req.height;
8331 unichar_chosen_func (const char *text,
8334 GtkEntry *entry = GTK_ENTRY (data);
8336 if (entry->editable)
8337 gtk_entry_enter_text (entry, text);
8348 popup_targets_received (GtkClipboard *clipboard,
8349 GtkSelectionData *data,
8352 PopupInfo *info = user_data;
8353 GtkEntry *entry = info->entry;
8355 if (GTK_WIDGET_REALIZED (entry))
8357 gboolean clipboard_contains_text;
8358 GtkWidget *menuitem;
8360 gboolean show_input_method_menu;
8361 gboolean show_unicode_menu;
8363 clipboard_contains_text = gtk_selection_data_targets_include_text (data);
8364 if (entry->popup_menu)
8365 gtk_widget_destroy (entry->popup_menu);
8367 entry->popup_menu = gtk_menu_new ();
8369 gtk_menu_attach_to_widget (GTK_MENU (entry->popup_menu),
8373 append_action_signal (entry, entry->popup_menu, GTK_STOCK_CUT, "cut-clipboard",
8374 entry->editable && entry->visible && entry->current_pos != entry->selection_bound);
8375 append_action_signal (entry, entry->popup_menu, GTK_STOCK_COPY, "copy-clipboard",
8376 entry->visible && entry->current_pos != entry->selection_bound);
8377 append_action_signal (entry, entry->popup_menu, GTK_STOCK_PASTE, "paste-clipboard",
8378 entry->editable && clipboard_contains_text);
8380 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_DELETE, NULL);
8381 gtk_widget_set_sensitive (menuitem, entry->editable && entry->current_pos != entry->selection_bound);
8382 g_signal_connect_swapped (menuitem, "activate",
8383 G_CALLBACK (gtk_entry_delete_cb), entry);
8384 gtk_widget_show (menuitem);
8385 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8387 menuitem = gtk_separator_menu_item_new ();
8388 gtk_widget_show (menuitem);
8389 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8391 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_SELECT_ALL, NULL);
8392 g_signal_connect_swapped (menuitem, "activate",
8393 G_CALLBACK (gtk_entry_select_all), entry);
8394 gtk_widget_show (menuitem);
8395 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8397 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
8398 "gtk-show-input-method-menu", &show_input_method_menu,
8399 "gtk-show-unicode-menu", &show_unicode_menu,
8402 if (show_input_method_menu || show_unicode_menu)
8404 menuitem = gtk_separator_menu_item_new ();
8405 gtk_widget_show (menuitem);
8406 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8409 if (show_input_method_menu)
8411 menuitem = gtk_menu_item_new_with_mnemonic (_("Input _Methods"));
8412 gtk_widget_set_sensitive (menuitem, entry->editable);
8413 gtk_widget_show (menuitem);
8414 submenu = gtk_menu_new ();
8415 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
8417 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8419 gtk_im_multicontext_append_menuitems (GTK_IM_MULTICONTEXT (entry->im_context),
8420 GTK_MENU_SHELL (submenu));
8423 if (show_unicode_menu)
8425 menuitem = gtk_menu_item_new_with_mnemonic (_("_Insert Unicode Control Character"));
8426 gtk_widget_set_sensitive (menuitem, entry->editable);
8427 gtk_widget_show (menuitem);
8429 submenu = gtk_menu_new ();
8430 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
8431 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8433 _gtk_text_util_append_special_char_menuitems (GTK_MENU_SHELL (submenu),
8434 unichar_chosen_func,
8438 g_signal_emit (entry,
8439 signals[POPULATE_POPUP],
8445 gtk_menu_popup (GTK_MENU (entry->popup_menu), NULL, NULL,
8447 info->button, info->time);
8450 gtk_menu_popup (GTK_MENU (entry->popup_menu), NULL, NULL,
8451 popup_position_func, entry,
8452 info->button, info->time);
8453 gtk_menu_shell_select_first (GTK_MENU_SHELL (entry->popup_menu), FALSE);
8457 g_object_unref (entry);
8458 g_slice_free (PopupInfo, info);
8462 gtk_entry_do_popup (GtkEntry *entry,
8463 GdkEventButton *event)
8465 PopupInfo *info = g_slice_new (PopupInfo);
8467 /* In order to know what entries we should make sensitive, we
8468 * ask for the current targets of the clipboard, and when
8469 * we get them, then we actually pop up the menu.
8471 info->entry = g_object_ref (entry);
8475 info->button = event->button;
8476 info->time = event->time;
8481 info->time = gtk_get_current_event_time ();
8484 gtk_clipboard_request_contents (gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_CLIPBOARD),
8485 gdk_atom_intern_static_string ("TARGETS"),
8486 popup_targets_received,
8491 gtk_entry_popup_menu (GtkWidget *widget)
8493 gtk_entry_do_popup (GTK_ENTRY (widget), NULL);
8498 gtk_entry_drag_begin (GtkWidget *widget,
8499 GdkDragContext *context)
8501 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
8504 for (i = 0; i < MAX_ICONS; i++)
8506 EntryIconInfo *icon_info = priv->icons[i];
8508 if (icon_info != NULL)
8510 if (icon_info->in_drag)
8512 switch (icon_info->storage_type)
8514 case GTK_IMAGE_STOCK:
8515 gtk_drag_set_icon_stock (context, icon_info->stock_id, -2, -2);
8518 case GTK_IMAGE_ICON_NAME:
8519 gtk_drag_set_icon_name (context, icon_info->icon_name, -2, -2);
8522 /* FIXME: No GIcon support for dnd icons */
8523 case GTK_IMAGE_GICON:
8524 case GTK_IMAGE_PIXBUF:
8525 gtk_drag_set_icon_pixbuf (context, icon_info->pixbuf, -2, -2);
8528 g_assert_not_reached ();
8536 gtk_entry_drag_end (GtkWidget *widget,
8537 GdkDragContext *context)
8539 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
8542 for (i = 0; i < MAX_ICONS; i++)
8544 EntryIconInfo *icon_info = priv->icons[i];
8546 if (icon_info != NULL)
8547 icon_info->in_drag = 0;
8552 gtk_entry_drag_leave (GtkWidget *widget,
8553 GdkDragContext *context,
8556 GtkEntry *entry = GTK_ENTRY (widget);
8558 entry->dnd_position = -1;
8559 gtk_widget_queue_draw (widget);
8563 gtk_entry_drag_drop (GtkWidget *widget,
8564 GdkDragContext *context,
8569 GtkEntry *entry = GTK_ENTRY (widget);
8570 GdkAtom target = GDK_NONE;
8572 if (entry->editable)
8573 target = gtk_drag_dest_find_target (widget, context, NULL);
8575 if (target != GDK_NONE)
8576 gtk_drag_get_data (widget, context, target, time);
8578 gtk_drag_finish (context, FALSE, FALSE, time);
8584 gtk_entry_drag_motion (GtkWidget *widget,
8585 GdkDragContext *context,
8590 GtkEntry *entry = GTK_ENTRY (widget);
8591 GtkWidget *source_widget;
8592 GdkDragAction suggested_action;
8593 gint new_position, old_position;
8596 x -= widget->style->xthickness;
8597 y -= widget->style->ythickness;
8599 old_position = entry->dnd_position;
8600 new_position = gtk_entry_find_position (entry, x + entry->scroll_offset);
8602 if (entry->editable &&
8603 gtk_drag_dest_find_target (widget, context, NULL) != GDK_NONE)
8605 source_widget = gtk_drag_get_source_widget (context);
8606 suggested_action = context->suggested_action;
8608 if (!gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &sel1, &sel2) ||
8609 new_position < sel1 || new_position > sel2)
8611 if (source_widget == widget)
8613 /* Default to MOVE, unless the user has
8614 * pressed ctrl or alt to affect available actions
8616 if ((context->actions & GDK_ACTION_MOVE) != 0)
8617 suggested_action = GDK_ACTION_MOVE;
8620 entry->dnd_position = new_position;
8624 if (source_widget == widget)
8625 suggested_action = 0; /* Can't drop in selection where drag started */
8627 entry->dnd_position = -1;
8632 /* Entry not editable, or no text */
8633 suggested_action = 0;
8634 entry->dnd_position = -1;
8637 gdk_drag_status (context, suggested_action, time);
8639 if (entry->dnd_position != old_position)
8640 gtk_widget_queue_draw (widget);
8646 gtk_entry_drag_data_received (GtkWidget *widget,
8647 GdkDragContext *context,
8650 GtkSelectionData *selection_data,
8654 GtkEntry *entry = GTK_ENTRY (widget);
8655 GtkEditable *editable = GTK_EDITABLE (widget);
8658 str = (gchar *) gtk_selection_data_get_text (selection_data);
8660 x -= widget->style->xthickness;
8661 y -= widget->style->ythickness;
8663 if (str && entry->editable)
8669 if (entry->truncate_multiline)
8670 length = truncate_multiline (str);
8672 new_position = gtk_entry_find_position (entry, x + entry->scroll_offset);
8674 if (!gtk_editable_get_selection_bounds (editable, &sel1, &sel2) ||
8675 new_position < sel1 || new_position > sel2)
8677 gtk_editable_insert_text (editable, str, length, &new_position);
8681 /* Replacing selection */
8682 begin_change (entry);
8683 g_object_freeze_notify (G_OBJECT (entry));
8684 gtk_editable_delete_text (editable, sel1, sel2);
8685 gtk_editable_insert_text (editable, str, length, &sel1);
8686 g_object_thaw_notify (G_OBJECT (entry));
8690 gtk_drag_finish (context, TRUE, context->action == GDK_ACTION_MOVE, time);
8694 /* Drag and drop didn't happen! */
8695 gtk_drag_finish (context, FALSE, FALSE, time);
8702 gtk_entry_drag_data_get (GtkWidget *widget,
8703 GdkDragContext *context,
8704 GtkSelectionData *selection_data,
8708 gint sel_start, sel_end;
8711 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
8712 GtkEditable *editable = GTK_EDITABLE (widget);
8714 /* If there is an icon drag going on, exit early. */
8715 for (i = 0; i < MAX_ICONS; i++)
8717 EntryIconInfo *icon_info = priv->icons[i];
8719 if (icon_info != NULL)
8721 if (icon_info->in_drag)
8726 if (gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end))
8728 gchar *str = gtk_entry_get_public_chars (GTK_ENTRY (widget), sel_start, sel_end);
8730 gtk_selection_data_set_text (selection_data, str, -1);
8738 gtk_entry_drag_data_delete (GtkWidget *widget,
8739 GdkDragContext *context)
8741 gint sel_start, sel_end;
8744 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
8745 GtkEditable *editable = GTK_EDITABLE (widget);
8747 /* If there is an icon drag going on, exit early. */
8748 for (i = 0; i < MAX_ICONS; i++)
8750 EntryIconInfo *icon_info = priv->icons[i];
8752 if (icon_info != NULL)
8754 if (icon_info->in_drag)
8759 if (GTK_ENTRY (widget)->editable &&
8760 gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end))
8761 gtk_editable_delete_text (editable, sel_start, sel_end);
8764 /* We display the cursor when
8766 * - the selection is empty, AND
8767 * - the widget has focus
8770 #define CURSOR_ON_MULTIPLIER 2
8771 #define CURSOR_OFF_MULTIPLIER 1
8772 #define CURSOR_PEND_MULTIPLIER 3
8773 #define CURSOR_DIVIDER 3
8776 cursor_blinks (GtkEntry *entry)
8778 if (GTK_WIDGET_HAS_FOCUS (entry) &&
8780 entry->selection_bound == entry->current_pos)
8782 GtkSettings *settings;
8785 settings = gtk_widget_get_settings (GTK_WIDGET (entry));
8786 g_object_get (settings, "gtk-cursor-blink", &blink, NULL);
8795 get_cursor_time (GtkEntry *entry)
8797 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (entry));
8800 g_object_get (settings, "gtk-cursor-blink-time", &time, NULL);
8806 get_cursor_blink_timeout (GtkEntry *entry)
8808 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (entry));
8811 g_object_get (settings, "gtk-cursor-blink-timeout", &timeout, NULL);
8817 show_cursor (GtkEntry *entry)
8819 if (!entry->cursor_visible)
8821 entry->cursor_visible = TRUE;
8823 if (GTK_WIDGET_HAS_FOCUS (entry) && entry->selection_bound == entry->current_pos)
8824 gtk_widget_queue_draw (GTK_WIDGET (entry));
8829 hide_cursor (GtkEntry *entry)
8831 if (entry->cursor_visible)
8833 entry->cursor_visible = FALSE;
8835 if (GTK_WIDGET_HAS_FOCUS (entry) && entry->selection_bound == entry->current_pos)
8836 gtk_widget_queue_draw (GTK_WIDGET (entry));
8844 blink_cb (gpointer data)
8847 GtkEntryPrivate *priv;
8850 entry = GTK_ENTRY (data);
8851 priv = GTK_ENTRY_GET_PRIVATE (entry);
8853 if (!GTK_WIDGET_HAS_FOCUS (entry))
8855 g_warning ("GtkEntry - did not receive focus-out-event. If you\n"
8856 "connect a handler to this signal, it must return\n"
8857 "FALSE so the entry gets the event as well");
8859 gtk_entry_check_cursor_blink (entry);
8864 g_assert (entry->selection_bound == entry->current_pos);
8866 blink_timeout = get_cursor_blink_timeout (entry);
8867 if (priv->blink_time > 1000 * blink_timeout &&
8868 blink_timeout < G_MAXINT/1000)
8870 /* we've blinked enough without the user doing anything, stop blinking */
8871 show_cursor (entry);
8872 entry->blink_timeout = 0;
8874 else if (entry->cursor_visible)
8876 hide_cursor (entry);
8877 entry->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_OFF_MULTIPLIER / CURSOR_DIVIDER,
8883 show_cursor (entry);
8884 priv->blink_time += get_cursor_time (entry);
8885 entry->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
8890 /* Remove ourselves */
8895 gtk_entry_check_cursor_blink (GtkEntry *entry)
8897 GtkEntryPrivate *priv;
8899 priv = GTK_ENTRY_GET_PRIVATE (entry);
8901 if (cursor_blinks (entry))
8903 if (!entry->blink_timeout)
8905 show_cursor (entry);
8906 entry->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
8913 if (entry->blink_timeout)
8915 g_source_remove (entry->blink_timeout);
8916 entry->blink_timeout = 0;
8919 entry->cursor_visible = TRUE;
8925 gtk_entry_pend_cursor_blink (GtkEntry *entry)
8927 if (cursor_blinks (entry))
8929 if (entry->blink_timeout != 0)
8930 g_source_remove (entry->blink_timeout);
8932 entry->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_PEND_MULTIPLIER / CURSOR_DIVIDER,
8935 show_cursor (entry);
8940 gtk_entry_reset_blink_time (GtkEntry *entry)
8942 GtkEntryPrivate *priv;
8944 priv = GTK_ENTRY_GET_PRIVATE (entry);
8946 priv->blink_time = 0;
8952 gtk_entry_completion_timeout (gpointer data)
8954 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (data);
8956 completion->priv->completion_timeout = 0;
8958 if (completion->priv->filter_model &&
8959 g_utf8_strlen (gtk_entry_get_text (GTK_ENTRY (completion->priv->entry)), -1)
8960 >= completion->priv->minimum_key_length)
8964 GtkTreeSelection *s;
8965 gboolean popup_single;
8967 gtk_entry_completion_complete (completion);
8968 matches = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->filter_model), NULL);
8970 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
8972 s = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view));
8974 gtk_tree_selection_unselect_all (s);
8976 actions = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->actions), NULL);
8978 g_object_get (completion, "popup-single-match", &popup_single, NULL);
8979 if ((matches > (popup_single ? 0: 1)) || actions > 0)
8981 if (GTK_WIDGET_VISIBLE (completion->priv->popup_window))
8982 _gtk_entry_completion_resize_popup (completion);
8984 _gtk_entry_completion_popup (completion);
8987 _gtk_entry_completion_popdown (completion);
8989 else if (GTK_WIDGET_VISIBLE (completion->priv->popup_window))
8990 _gtk_entry_completion_popdown (completion);
8995 static inline gboolean
8996 keyval_is_cursor_move (guint keyval)
8998 if (keyval == GDK_Up || keyval == GDK_KP_Up)
9001 if (keyval == GDK_Down || keyval == GDK_KP_Down)
9004 if (keyval == GDK_Page_Up)
9007 if (keyval == GDK_Page_Down)
9014 gtk_entry_completion_key_press (GtkWidget *widget,
9018 gint matches, actions = 0;
9019 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
9021 if (!GTK_WIDGET_MAPPED (completion->priv->popup_window))
9024 matches = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->filter_model), NULL);
9026 if (completion->priv->actions)
9027 actions = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->actions), NULL);
9029 if (keyval_is_cursor_move (event->keyval))
9031 GtkTreePath *path = NULL;
9033 if (event->keyval == GDK_Up || event->keyval == GDK_KP_Up)
9035 if (completion->priv->current_selected < 0)
9036 completion->priv->current_selected = matches + actions - 1;
9038 completion->priv->current_selected--;
9040 else if (event->keyval == GDK_Down || event->keyval == GDK_KP_Down)
9042 if (completion->priv->current_selected < matches + actions - 1)
9043 completion->priv->current_selected++;
9045 completion->priv->current_selected = -1;
9047 else if (event->keyval == GDK_Page_Up)
9049 if (completion->priv->current_selected < 0)
9050 completion->priv->current_selected = matches + actions - 1;
9051 else if (completion->priv->current_selected == 0)
9052 completion->priv->current_selected = -1;
9053 else if (completion->priv->current_selected < matches)
9055 completion->priv->current_selected -= 14;
9056 if (completion->priv->current_selected < 0)
9057 completion->priv->current_selected = 0;
9061 completion->priv->current_selected -= 14;
9062 if (completion->priv->current_selected < matches - 1)
9063 completion->priv->current_selected = matches - 1;
9066 else if (event->keyval == GDK_Page_Down)
9068 if (completion->priv->current_selected < 0)
9069 completion->priv->current_selected = 0;
9070 else if (completion->priv->current_selected < matches - 1)
9072 completion->priv->current_selected += 14;
9073 if (completion->priv->current_selected > matches - 1)
9074 completion->priv->current_selected = matches - 1;
9076 else if (completion->priv->current_selected == matches + actions - 1)
9078 completion->priv->current_selected = -1;
9082 completion->priv->current_selected += 14;
9083 if (completion->priv->current_selected > matches + actions - 1)
9084 completion->priv->current_selected = matches + actions - 1;
9088 if (completion->priv->current_selected < 0)
9090 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9091 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view)));
9093 if (completion->priv->inline_selection &&
9094 completion->priv->completion_prefix)
9096 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9097 completion->priv->completion_prefix);
9098 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9101 else if (completion->priv->current_selected < matches)
9103 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view)));
9105 path = gtk_tree_path_new_from_indices (completion->priv->current_selected, -1);
9106 gtk_tree_view_set_cursor (GTK_TREE_VIEW (completion->priv->tree_view),
9109 if (completion->priv->inline_selection)
9113 GtkTreeModel *model = NULL;
9114 GtkTreeSelection *sel;
9117 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view));
9118 if (!gtk_tree_selection_get_selected (sel, &model, &iter))
9121 if (completion->priv->completion_prefix == NULL)
9122 completion->priv->completion_prefix = g_strdup (gtk_entry_get_text (GTK_ENTRY (completion->priv->entry)));
9124 g_signal_emit_by_name (completion, "cursor-on-match", model,
9128 else if (completion->priv->current_selected - matches >= 0)
9130 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9132 path = gtk_tree_path_new_from_indices (completion->priv->current_selected - matches, -1);
9133 gtk_tree_view_set_cursor (GTK_TREE_VIEW (completion->priv->action_view),
9136 if (completion->priv->inline_selection &&
9137 completion->priv->completion_prefix)
9139 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9140 completion->priv->completion_prefix);
9141 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9145 gtk_tree_path_free (path);
9149 else if (event->keyval == GDK_Escape ||
9150 event->keyval == GDK_Left ||
9151 event->keyval == GDK_KP_Left ||
9152 event->keyval == GDK_Right ||
9153 event->keyval == GDK_KP_Right)
9155 gboolean retval = TRUE;
9157 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9158 _gtk_entry_completion_popdown (completion);
9160 if (completion->priv->current_selected < 0)
9163 goto keypress_completion_out;
9165 else if (completion->priv->inline_selection)
9167 /* Escape rejects the tentative completion */
9168 if (event->keyval == GDK_Escape)
9170 if (completion->priv->completion_prefix)
9171 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9172 completion->priv->completion_prefix);
9174 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry), "");
9177 /* Move the cursor to the end for Right/Esc, to the
9178 beginning for Left */
9179 if (event->keyval == GDK_Right ||
9180 event->keyval == GDK_KP_Right ||
9181 event->keyval == GDK_Escape)
9182 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9184 gtk_editable_set_position (GTK_EDITABLE (widget), 0);
9187 keypress_completion_out:
9188 if (completion->priv->inline_selection)
9190 g_free (completion->priv->completion_prefix);
9191 completion->priv->completion_prefix = NULL;
9196 else if (event->keyval == GDK_Tab ||
9197 event->keyval == GDK_KP_Tab ||
9198 event->keyval == GDK_ISO_Left_Tab)
9200 GtkDirectionType dir = event->keyval == GDK_ISO_Left_Tab ?
9201 GTK_DIR_TAB_BACKWARD : GTK_DIR_TAB_FORWARD;
9203 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9204 _gtk_entry_completion_popdown (completion);
9206 g_free (completion->priv->completion_prefix);
9207 completion->priv->completion_prefix = NULL;
9209 gtk_widget_child_focus (gtk_widget_get_toplevel (widget), dir);
9213 else if (event->keyval == GDK_ISO_Enter ||
9214 event->keyval == GDK_KP_Enter ||
9215 event->keyval == GDK_Return)
9217 gboolean retval = TRUE;
9219 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9220 _gtk_entry_completion_popdown (completion);
9222 if (completion->priv->current_selected < matches)
9225 GtkTreeModel *model = NULL;
9226 GtkTreeSelection *sel;
9229 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view));
9230 if (gtk_tree_selection_get_selected (sel, &model, &iter))
9232 g_signal_handler_block (widget, completion->priv->changed_id);
9233 g_signal_emit_by_name (completion, "match-selected",
9234 model, &iter, &entry_set);
9235 g_signal_handler_unblock (widget, completion->priv->changed_id);
9241 gtk_tree_model_get (model, &iter,
9242 completion->priv->text_column, &str,
9245 gtk_entry_set_text (GTK_ENTRY (widget), str);
9247 /* move the cursor to the end */
9248 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9256 else if (completion->priv->current_selected - matches >= 0)
9260 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9262 path = gtk_tree_path_new_from_indices (completion->priv->current_selected - matches, -1);
9264 g_signal_emit_by_name (completion, "action-activated",
9265 gtk_tree_path_get_indices (path)[0]);
9266 gtk_tree_path_free (path);
9269 g_free (completion->priv->completion_prefix);
9270 completion->priv->completion_prefix = NULL;
9279 gtk_entry_completion_changed (GtkWidget *entry,
9282 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
9284 /* (re)install completion timeout */
9285 if (completion->priv->completion_timeout)
9286 g_source_remove (completion->priv->completion_timeout);
9288 if (!gtk_entry_get_text (GTK_ENTRY (entry)))
9291 /* no need to normalize for this test */
9292 if (completion->priv->minimum_key_length > 0 &&
9293 strcmp ("", gtk_entry_get_text (GTK_ENTRY (entry))) == 0)
9295 if (GTK_WIDGET_VISIBLE (completion->priv->popup_window))
9296 _gtk_entry_completion_popdown (completion);
9300 completion->priv->completion_timeout =
9301 gdk_threads_add_timeout (COMPLETION_TIMEOUT,
9302 gtk_entry_completion_timeout,
9307 check_completion_callback (GtkEntryCompletion *completion)
9309 completion->priv->check_completion_idle = NULL;
9311 gtk_entry_completion_complete (completion);
9312 gtk_entry_completion_insert_prefix (completion);
9318 clear_completion_callback (GtkEntry *entry,
9321 if (pspec->name == I_("cursor-position") ||
9322 pspec->name == I_("selection-bound"))
9324 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
9326 completion->priv->has_completion = FALSE;
9331 accept_completion_callback (GtkEntry *entry)
9333 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
9335 if (completion->priv->has_completion)
9336 gtk_editable_set_position (GTK_EDITABLE (entry),
9337 entry->text_length);
9343 completion_insert_text_callback (GtkEntry *entry,
9347 GtkEntryCompletion *completion)
9349 /* idle to update the selection based on the file list */
9350 if (completion->priv->check_completion_idle == NULL)
9352 completion->priv->check_completion_idle = g_idle_source_new ();
9353 g_source_set_priority (completion->priv->check_completion_idle, G_PRIORITY_HIGH);
9354 g_source_set_closure (completion->priv->check_completion_idle,
9355 g_cclosure_new_object (G_CALLBACK (check_completion_callback),
9356 G_OBJECT (completion)));
9357 g_source_attach (completion->priv->check_completion_idle, NULL);
9362 completion_changed (GtkEntryCompletion *completion,
9366 GtkEntry *entry = GTK_ENTRY (data);
9368 if (pspec->name == I_("popup-completion") ||
9369 pspec->name == I_("inline-completion"))
9371 disconnect_completion_signals (entry, completion);
9372 connect_completion_signals (entry, completion);
9377 disconnect_completion_signals (GtkEntry *entry,
9378 GtkEntryCompletion *completion)
9380 g_signal_handlers_disconnect_by_func (completion,
9381 G_CALLBACK (completion_changed), entry);
9382 if (completion->priv->changed_id > 0 &&
9383 g_signal_handler_is_connected (entry, completion->priv->changed_id))
9385 g_signal_handler_disconnect (entry, completion->priv->changed_id);
9386 completion->priv->changed_id = 0;
9388 g_signal_handlers_disconnect_by_func (entry,
9389 G_CALLBACK (gtk_entry_completion_key_press), completion);
9390 if (completion->priv->insert_text_id > 0 &&
9391 g_signal_handler_is_connected (entry, completion->priv->insert_text_id))
9393 g_signal_handler_disconnect (entry, completion->priv->insert_text_id);
9394 completion->priv->insert_text_id = 0;
9396 g_signal_handlers_disconnect_by_func (entry,
9397 G_CALLBACK (completion_insert_text_callback), completion);
9398 g_signal_handlers_disconnect_by_func (entry,
9399 G_CALLBACK (clear_completion_callback), completion);
9400 g_signal_handlers_disconnect_by_func (entry,
9401 G_CALLBACK (accept_completion_callback), completion);
9405 connect_completion_signals (GtkEntry *entry,
9406 GtkEntryCompletion *completion)
9408 if (completion->priv->popup_completion)
9410 completion->priv->changed_id =
9411 g_signal_connect (entry, "changed",
9412 G_CALLBACK (gtk_entry_completion_changed), completion);
9413 g_signal_connect (entry, "key-press-event",
9414 G_CALLBACK (gtk_entry_completion_key_press), completion);
9417 if (completion->priv->inline_completion)
9419 completion->priv->insert_text_id =
9420 g_signal_connect (entry, "insert-text",
9421 G_CALLBACK (completion_insert_text_callback), completion);
9422 g_signal_connect (entry, "notify",
9423 G_CALLBACK (clear_completion_callback), completion);
9424 g_signal_connect (entry, "activate",
9425 G_CALLBACK (accept_completion_callback), completion);
9426 g_signal_connect (entry, "focus-out-event",
9427 G_CALLBACK (accept_completion_callback), completion);
9430 g_signal_connect (completion, "notify",
9431 G_CALLBACK (completion_changed), entry);
9435 * gtk_entry_set_completion:
9436 * @entry: A #GtkEntry
9437 * @completion: The #GtkEntryCompletion or %NULL
9439 * Sets @completion to be the auxiliary completion object to use with @entry.
9440 * All further configuration of the completion mechanism is done on
9441 * @completion using the #GtkEntryCompletion API. Completion is disabled if
9442 * @completion is set to %NULL.
9447 gtk_entry_set_completion (GtkEntry *entry,
9448 GtkEntryCompletion *completion)
9450 GtkEntryCompletion *old;
9452 g_return_if_fail (GTK_IS_ENTRY (entry));
9453 g_return_if_fail (!completion || GTK_IS_ENTRY_COMPLETION (completion));
9455 old = gtk_entry_get_completion (entry);
9457 if (old == completion)
9462 if (old->priv->completion_timeout)
9464 g_source_remove (old->priv->completion_timeout);
9465 old->priv->completion_timeout = 0;
9468 if (GTK_WIDGET_MAPPED (old->priv->popup_window))
9469 _gtk_entry_completion_popdown (old);
9471 disconnect_completion_signals (entry, old);
9472 old->priv->entry = NULL;
9474 g_object_unref (old);
9479 g_object_set_data (G_OBJECT (entry), I_(GTK_ENTRY_COMPLETION_KEY), NULL);
9483 /* hook into the entry */
9484 g_object_ref (completion);
9486 connect_completion_signals (entry, completion);
9487 completion->priv->entry = GTK_WIDGET (entry);
9488 g_object_set_data (G_OBJECT (entry), I_(GTK_ENTRY_COMPLETION_KEY), completion);
9492 * gtk_entry_get_completion:
9493 * @entry: A #GtkEntry
9495 * Returns the auxiliary completion object currently in use by @entry.
9497 * Return value: The auxiliary completion object currently in use by @entry.
9501 GtkEntryCompletion *
9502 gtk_entry_get_completion (GtkEntry *entry)
9504 GtkEntryCompletion *completion;
9506 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
9508 completion = GTK_ENTRY_COMPLETION (g_object_get_data (G_OBJECT (entry),
9509 GTK_ENTRY_COMPLETION_KEY));
9515 * gtk_entry_set_cursor_hadjustment:
9516 * @entry: a #GtkEntry
9517 * @adjustment: an adjustment which should be adjusted when the cursor
9518 * is moved, or %NULL
9520 * Hooks up an adjustment to the cursor position in an entry, so that when
9521 * the cursor is moved, the adjustment is scrolled to show that position.
9522 * See gtk_scrolled_window_get_hadjustment() for a typical way of obtaining
9525 * The adjustment has to be in pixel units and in the same coordinate system
9531 gtk_entry_set_cursor_hadjustment (GtkEntry *entry,
9532 GtkAdjustment *adjustment)
9534 g_return_if_fail (GTK_IS_ENTRY (entry));
9536 g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
9539 g_object_ref (adjustment);
9541 g_object_set_qdata_full (G_OBJECT (entry),
9542 quark_cursor_hadjustment,
9548 * gtk_entry_get_cursor_hadjustment:
9549 * @entry: a #GtkEntry
9551 * Retrieves the horizontal cursor adjustment for the entry.
9552 * See gtk_entry_set_cursor_hadjustment().
9554 * Return value: the horizontal cursor adjustment, or %NULL
9555 * if none has been set.
9560 gtk_entry_get_cursor_hadjustment (GtkEntry *entry)
9562 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
9564 return g_object_get_qdata (G_OBJECT (entry), quark_cursor_hadjustment);
9568 * gtk_entry_set_progress_fraction:
9569 * @entry: a #GtkEntry
9570 * @fraction: fraction of the task that's been completed
9572 * Causes the entry's progress indicator to "fill in" the given
9573 * fraction of the bar. The fraction should be between 0.0 and 1.0,
9579 gtk_entry_set_progress_fraction (GtkEntry *entry,
9582 GtkEntryPrivate *private;
9583 gdouble old_fraction;
9584 gint x, y, width, height;
9585 gint old_x, old_y, old_width, old_height;
9587 g_return_if_fail (GTK_IS_ENTRY (entry));
9589 private = GTK_ENTRY_GET_PRIVATE (entry);
9591 if (private->progress_pulse_mode)
9594 old_fraction = private->progress_fraction;
9596 if (GTK_WIDGET_DRAWABLE (GTK_WIDGET (entry)))
9597 get_progress_area (GTK_WIDGET(entry), &old_x, &old_y, &old_width, &old_height);
9599 fraction = CLAMP (fraction, 0.0, 1.0);
9601 private->progress_fraction = fraction;
9602 private->progress_pulse_mode = FALSE;
9603 private->progress_pulse_current = 0.0;
9605 if (GTK_WIDGET_DRAWABLE (GTK_WIDGET (entry)))
9607 get_progress_area (GTK_WIDGET(entry), &x, &y, &width, &height);
9609 if ((x != old_x) || (y != old_y) || (width != old_width) || (height != old_height))
9610 gtk_widget_queue_draw (GTK_WIDGET (entry));
9613 if (fraction != old_fraction)
9614 g_object_notify (G_OBJECT (entry), "progress-fraction");
9618 * gtk_entry_get_progress_fraction:
9619 * @entry: a #GtkEntry
9621 * Returns the current fraction of the task that's been completed.
9622 * See gtk_entry_set_progress_fraction().
9624 * Return value: a fraction from 0.0 to 1.0
9629 gtk_entry_get_progress_fraction (GtkEntry *entry)
9631 GtkEntryPrivate *private;
9633 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
9635 private = GTK_ENTRY_GET_PRIVATE (entry);
9637 return private->progress_fraction;
9641 * gtk_entry_set_progress_pulse_step:
9642 * @entry: a #GtkEntry
9643 * @fraction: fraction between 0.0 and 1.0
9645 * Sets the fraction of total entry width to move the progress
9646 * bouncing block for each call to gtk_entry_progress_pulse().
9651 gtk_entry_set_progress_pulse_step (GtkEntry *entry,
9654 GtkEntryPrivate *private;
9656 g_return_if_fail (GTK_IS_ENTRY (entry));
9658 private = GTK_ENTRY_GET_PRIVATE (entry);
9660 fraction = CLAMP (fraction, 0.0, 1.0);
9662 if (fraction != private->progress_pulse_fraction)
9664 private->progress_pulse_fraction = fraction;
9666 gtk_widget_queue_draw (GTK_WIDGET (entry));
9668 g_object_notify (G_OBJECT (entry), "progress-pulse-step");
9673 * gtk_entry_get_progress_pulse_step:
9674 * @entry: a #GtkEntry
9676 * Retrieves the pulse step set with gtk_entry_set_progress_pulse_step().
9678 * Return value: a fraction from 0.0 to 1.0
9683 gtk_entry_get_progress_pulse_step (GtkEntry *entry)
9685 GtkEntryPrivate *private;
9687 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
9689 private = GTK_ENTRY_GET_PRIVATE (entry);
9691 return private->progress_pulse_fraction;
9695 * gtk_entry_progress_pulse:
9696 * @entry: a #GtkEntry
9698 * Indicates that some progress is made, but you don't know how much.
9699 * Causes the entry's progress indicator to enter "activity mode,"
9700 * where a block bounces back and forth. Each call to
9701 * gtk_entry_progress_pulse() causes the block to move by a little bit
9702 * (the amount of movement per pulse is determined by
9703 * gtk_entry_set_progress_pulse_step()).
9708 gtk_entry_progress_pulse (GtkEntry *entry)
9710 GtkEntryPrivate *private;
9712 g_return_if_fail (GTK_IS_ENTRY (entry));
9714 private = GTK_ENTRY_GET_PRIVATE (entry);
9716 if (private->progress_pulse_mode)
9718 if (private->progress_pulse_way_back)
9720 private->progress_pulse_current -= private->progress_pulse_fraction;
9722 if (private->progress_pulse_current < 0.0)
9724 private->progress_pulse_current = 0.0;
9725 private->progress_pulse_way_back = FALSE;
9730 private->progress_pulse_current += private->progress_pulse_fraction;
9732 if (private->progress_pulse_current > 1.0 - private->progress_pulse_fraction)
9734 private->progress_pulse_current = 1.0 - private->progress_pulse_fraction;
9735 private->progress_pulse_way_back = TRUE;
9741 private->progress_fraction = 0.0;
9742 private->progress_pulse_mode = TRUE;
9743 private->progress_pulse_way_back = FALSE;
9744 private->progress_pulse_current = 0.0;
9747 gtk_widget_queue_draw (GTK_WIDGET (entry));
9750 /* Caps Lock warning for password entries */
9753 show_capslock_feedback (GtkEntry *entry,
9756 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
9758 if (gtk_entry_get_icon_storage_type (entry, GTK_ENTRY_ICON_SECONDARY) == GTK_IMAGE_EMPTY)
9760 gtk_entry_set_icon_from_stock (entry, GTK_ENTRY_ICON_SECONDARY, GTK_STOCK_CAPS_LOCK_WARNING);
9761 gtk_entry_set_icon_activatable (entry, GTK_ENTRY_ICON_SECONDARY, FALSE);
9762 priv->caps_lock_warning_shown = TRUE;
9765 if (priv->caps_lock_warning_shown)
9766 gtk_entry_set_icon_tooltip_text (entry, GTK_ENTRY_ICON_SECONDARY, text);
9768 g_warning ("Can't show Caps Lock warning, since secondary icon is set");
9772 remove_capslock_feedback (GtkEntry *entry)
9774 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
9776 if (priv->caps_lock_warning_shown)
9778 gtk_entry_set_icon_from_stock (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
9779 priv->caps_lock_warning_shown = FALSE;
9784 keymap_state_changed (GdkKeymap *keymap,
9787 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
9790 if (!entry->visible && priv->caps_lock_warning)
9792 if (gdk_keymap_get_caps_lock_state (keymap))
9793 text = _("Caps Lock is on");
9797 show_capslock_feedback (entry, text);
9799 remove_capslock_feedback (entry);
9802 #define __GTK_ENTRY_C__
9803 #include "gtkaliasdef.c"