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,
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_state_changed (GtkWidget *widget,
453 GtkStateType previous_state);
454 static void gtk_entry_check_cursor_blink (GtkEntry *entry);
455 static void gtk_entry_pend_cursor_blink (GtkEntry *entry);
456 static void gtk_entry_reset_blink_time (GtkEntry *entry);
457 static void gtk_entry_get_text_area_size (GtkEntry *entry,
462 static void get_widget_window_size (GtkEntry *entry,
467 static void gtk_entry_move_adjustments (GtkEntry *entry);
468 static void gtk_entry_ensure_pixbuf (GtkEntry *entry,
469 GtkEntryIconPosition icon_pos);
473 static gint gtk_entry_completion_timeout (gpointer data);
474 static gboolean gtk_entry_completion_key_press (GtkWidget *widget,
477 static void gtk_entry_completion_changed (GtkWidget *entry,
479 static gboolean check_completion_callback (GtkEntryCompletion *completion);
480 static void clear_completion_callback (GtkEntry *entry,
482 static gboolean accept_completion_callback (GtkEntry *entry);
483 static void completion_insert_text_callback (GtkEntry *entry,
487 GtkEntryCompletion *completion);
488 static void completion_changed (GtkEntryCompletion *completion,
491 static void disconnect_completion_signals (GtkEntry *entry,
492 GtkEntryCompletion *completion);
493 static void connect_completion_signals (GtkEntry *entry,
494 GtkEntryCompletion *completion);
496 static void begin_change (GtkEntry *entry);
497 static void end_change (GtkEntry *entry);
498 static void emit_changed (GtkEntry *entry);
501 G_DEFINE_TYPE_WITH_CODE (GtkEntry, gtk_entry, GTK_TYPE_WIDGET,
502 G_IMPLEMENT_INTERFACE (GTK_TYPE_EDITABLE,
503 gtk_entry_editable_init)
504 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_EDITABLE,
505 gtk_entry_cell_editable_init))
508 add_move_binding (GtkBindingSet *binding_set,
511 GtkMovementStep step,
514 g_return_if_fail ((modmask & GDK_SHIFT_MASK) == 0);
516 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
520 G_TYPE_BOOLEAN, FALSE);
522 /* Selection-extending version */
523 gtk_binding_entry_add_signal (binding_set, keyval, modmask | GDK_SHIFT_MASK,
527 G_TYPE_BOOLEAN, TRUE);
531 gtk_entry_class_init (GtkEntryClass *class)
533 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
534 GtkWidgetClass *widget_class;
535 GtkObjectClass *gtk_object_class;
536 GtkBindingSet *binding_set;
538 widget_class = (GtkWidgetClass*) class;
539 gtk_object_class = (GtkObjectClass *)class;
541 gobject_class->dispose = gtk_entry_dispose;
542 gobject_class->finalize = gtk_entry_finalize;
543 gobject_class->set_property = gtk_entry_set_property;
544 gobject_class->get_property = gtk_entry_get_property;
546 widget_class->map = gtk_entry_map;
547 widget_class->unmap = gtk_entry_unmap;
548 widget_class->realize = gtk_entry_realize;
549 widget_class->unrealize = gtk_entry_unrealize;
550 widget_class->size_request = gtk_entry_size_request;
551 widget_class->size_allocate = gtk_entry_size_allocate;
552 widget_class->expose_event = gtk_entry_expose;
553 widget_class->enter_notify_event = gtk_entry_enter_notify;
554 widget_class->leave_notify_event = gtk_entry_leave_notify;
555 widget_class->button_press_event = gtk_entry_button_press;
556 widget_class->button_release_event = gtk_entry_button_release;
557 widget_class->motion_notify_event = gtk_entry_motion_notify;
558 widget_class->key_press_event = gtk_entry_key_press;
559 widget_class->key_release_event = gtk_entry_key_release;
560 widget_class->focus_in_event = gtk_entry_focus_in;
561 widget_class->focus_out_event = gtk_entry_focus_out;
562 widget_class->grab_focus = gtk_entry_grab_focus;
563 widget_class->style_set = gtk_entry_style_set;
564 widget_class->query_tooltip = gtk_entry_query_tooltip;
565 widget_class->drag_begin = gtk_entry_drag_begin;
566 widget_class->drag_end = gtk_entry_drag_end;
567 widget_class->direction_changed = gtk_entry_direction_changed;
568 widget_class->state_changed = gtk_entry_state_changed;
569 widget_class->screen_changed = gtk_entry_screen_changed;
570 widget_class->mnemonic_activate = gtk_entry_mnemonic_activate;
572 widget_class->drag_drop = gtk_entry_drag_drop;
573 widget_class->drag_motion = gtk_entry_drag_motion;
574 widget_class->drag_leave = gtk_entry_drag_leave;
575 widget_class->drag_data_received = gtk_entry_drag_data_received;
576 widget_class->drag_data_get = gtk_entry_drag_data_get;
577 widget_class->drag_data_delete = gtk_entry_drag_data_delete;
579 widget_class->popup_menu = gtk_entry_popup_menu;
581 gtk_object_class->destroy = gtk_entry_destroy;
583 class->move_cursor = gtk_entry_move_cursor;
584 class->insert_at_cursor = gtk_entry_insert_at_cursor;
585 class->delete_from_cursor = gtk_entry_delete_from_cursor;
586 class->backspace = gtk_entry_backspace;
587 class->cut_clipboard = gtk_entry_cut_clipboard;
588 class->copy_clipboard = gtk_entry_copy_clipboard;
589 class->paste_clipboard = gtk_entry_paste_clipboard;
590 class->toggle_overwrite = gtk_entry_toggle_overwrite;
591 class->activate = gtk_entry_real_activate;
592 class->get_text_area_size = gtk_entry_get_text_area_size;
594 quark_inner_border = g_quark_from_static_string ("gtk-entry-inner-border");
595 quark_password_hint = g_quark_from_static_string ("gtk-entry-password-hint");
596 quark_cursor_hadjustment = g_quark_from_static_string ("gtk-hadjustment");
597 quark_capslock_feedback = g_quark_from_static_string ("gtk-entry-capslock-feedback");
599 g_object_class_install_property (gobject_class,
600 PROP_CURSOR_POSITION,
601 g_param_spec_int ("cursor-position",
602 P_("Cursor Position"),
603 P_("The current position of the insertion cursor in chars"),
607 GTK_PARAM_READABLE));
609 g_object_class_install_property (gobject_class,
610 PROP_SELECTION_BOUND,
611 g_param_spec_int ("selection-bound",
612 P_("Selection Bound"),
613 P_("The position of the opposite end of the selection from the cursor in chars"),
617 GTK_PARAM_READABLE));
619 g_object_class_install_property (gobject_class,
621 g_param_spec_boolean ("editable",
623 P_("Whether the entry contents can be edited"),
625 GTK_PARAM_READWRITE));
627 g_object_class_install_property (gobject_class,
629 g_param_spec_int ("max-length",
630 P_("Maximum length"),
631 P_("Maximum number of characters for this entry. Zero if no maximum"),
635 GTK_PARAM_READWRITE));
636 g_object_class_install_property (gobject_class,
638 g_param_spec_boolean ("visibility",
640 P_("FALSE displays the \"invisible char\" instead of the actual text (password mode)"),
642 GTK_PARAM_READWRITE));
644 g_object_class_install_property (gobject_class,
646 g_param_spec_boolean ("has-frame",
648 P_("FALSE removes outside bevel from entry"),
650 GTK_PARAM_READWRITE));
652 g_object_class_install_property (gobject_class,
654 g_param_spec_boxed ("inner-border",
656 P_("Border between text and frame. Overrides the inner-border style property"),
658 GTK_PARAM_READWRITE));
660 g_object_class_install_property (gobject_class,
662 g_param_spec_unichar ("invisible-char",
663 P_("Invisible character"),
664 P_("The character to use when masking entry contents (in \"password mode\")"),
666 GTK_PARAM_READWRITE));
668 g_object_class_install_property (gobject_class,
669 PROP_ACTIVATES_DEFAULT,
670 g_param_spec_boolean ("activates-default",
671 P_("Activates default"),
672 P_("Whether to activate the default widget (such as the default button in a dialog) when Enter is pressed"),
674 GTK_PARAM_READWRITE));
675 g_object_class_install_property (gobject_class,
677 g_param_spec_int ("width-chars",
678 P_("Width in chars"),
679 P_("Number of characters to leave space for in the entry"),
683 GTK_PARAM_READWRITE));
685 g_object_class_install_property (gobject_class,
687 g_param_spec_int ("scroll-offset",
689 P_("Number of pixels of the entry scrolled off the screen to the left"),
693 GTK_PARAM_READABLE));
695 g_object_class_install_property (gobject_class,
697 g_param_spec_string ("text",
699 P_("The contents of the entry"),
701 GTK_PARAM_READWRITE));
706 * The horizontal alignment, from 0 (left) to 1 (right).
707 * Reversed for RTL layouts.
711 g_object_class_install_property (gobject_class,
713 g_param_spec_float ("xalign",
715 P_("The horizontal alignment, from 0 (left) to 1 (right). Reversed for RTL layouts."),
719 GTK_PARAM_READWRITE));
722 * GtkEntry:truncate-multiline:
724 * When %TRUE, pasted multi-line text is truncated to the first line.
728 g_object_class_install_property (gobject_class,
729 PROP_TRUNCATE_MULTILINE,
730 g_param_spec_boolean ("truncate-multiline",
731 P_("Truncate multiline"),
732 P_("Whether to truncate multiline pastes to one line."),
734 GTK_PARAM_READWRITE));
737 * GtkEntry:shadow-type:
739 * Which kind of shadow to draw around the entry when
740 * #GtkEntry:has-frame is set to %TRUE.
744 g_object_class_install_property (gobject_class,
746 g_param_spec_enum ("shadow-type",
748 P_("Which kind of shadow to draw around the entry when has-frame is set"),
749 GTK_TYPE_SHADOW_TYPE,
751 GTK_PARAM_READWRITE));
754 * GtkEntry:overwrite-mode:
756 * If text is overwritten when typing in the #GtkEntry.
760 g_object_class_install_property (gobject_class,
762 g_param_spec_boolean ("overwrite-mode",
763 P_("Overwrite mode"),
764 P_("Whether new text overwrites existing text"),
766 GTK_PARAM_READWRITE));
769 * GtkEntry:text-length:
771 * The length of the text in the #GtkEntry.
775 g_object_class_install_property (gobject_class,
777 g_param_spec_uint ("text-length",
779 P_("Length of the text currently in the entry"),
783 GTK_PARAM_READABLE));
785 * GtkEntry:invisible-char-set:
787 * Whether the invisible char has been set for the #GtkEntry.
791 g_object_class_install_property (gobject_class,
792 PROP_INVISIBLE_CHAR_SET,
793 g_param_spec_boolean ("invisible-char-set",
794 P_("Invisible char set"),
795 P_("Whether the invisible char has been set"),
797 GTK_PARAM_READWRITE));
800 * GtkEntry:caps-lock-warning
802 * Whether password entries will show a warning when Caps Lock is on
803 * or an input method is active.
805 * Note that the warning is shown using a secondary icon, and thus
806 * does not work if you are using the secondary icon position for some
811 g_object_class_install_property (gobject_class,
812 PROP_CAPS_LOCK_WARNING,
813 g_param_spec_boolean ("caps-lock-warning",
814 P_("Caps Lock warning"),
815 P_("Whether password entries will show a warning when Caps Lock is on or an input method is active"),
817 GTK_PARAM_READWRITE));
820 * GtkEntry:progress-fraction:
822 * The current fraction of the task that's been completed.
826 g_object_class_install_property (gobject_class,
827 PROP_PROGRESS_FRACTION,
828 g_param_spec_double ("progress-fraction",
829 P_("Progress Fraction"),
830 P_("The current fraction of the task that's been completed"),
834 GTK_PARAM_READWRITE));
837 * GtkEntry:progress-pulse-step:
839 * The fraction of total entry width to move the progress
840 * bouncing block for each call to gtk_entry_progress_pulse().
844 g_object_class_install_property (gobject_class,
845 PROP_PROGRESS_PULSE_STEP,
846 g_param_spec_double ("progress-pulse-step",
847 P_("Progress Pulse Step"),
848 P_("The fraction of total entry width to move the progress bouncing block for each call to gtk_entry_progress_pulse()"),
852 GTK_PARAM_READWRITE));
855 * GtkEntry:primary-icon-pixbuf:
857 * A pixbuf to use as the primary icon for the entry.
861 g_object_class_install_property (gobject_class,
863 g_param_spec_object ("primary-icon-pixbuf",
864 P_("Primary pixbuf"),
865 P_("Primary pixbuf for the entry"),
867 GTK_PARAM_READWRITE));
870 * GtkEntry:secondary-icon-pixbuf:
872 * An pixbuf to use as the secondary icon for the entry.
876 g_object_class_install_property (gobject_class,
877 PROP_PIXBUF_SECONDARY,
878 g_param_spec_object ("secondary-icon-pixbuf",
879 P_("Secondary pixbuf"),
880 P_("Secondary pixbuf for the entry"),
882 GTK_PARAM_READWRITE));
885 * GtkEntry:primary-icon-stock:
887 * The stock id to use for the primary icon for the entry.
891 g_object_class_install_property (gobject_class,
893 g_param_spec_string ("primary-icon-stock",
894 P_("Primary stock ID"),
895 P_("Stock ID for primary icon"),
897 GTK_PARAM_READWRITE));
900 * GtkEntry:secondary-icon-stock:
902 * The stock id to use for the secondary icon for the entry.
906 g_object_class_install_property (gobject_class,
907 PROP_STOCK_SECONDARY,
908 g_param_spec_string ("secondary-icon-stock",
909 P_("Secondary stock ID"),
910 P_("Stock ID for secondary icon"),
912 GTK_PARAM_READWRITE));
915 * GtkEntry:primary-icon-name:
917 * The icon name to use for the primary icon for the entry.
921 g_object_class_install_property (gobject_class,
922 PROP_ICON_NAME_PRIMARY,
923 g_param_spec_string ("primary-icon-name",
924 P_("Primary icon name"),
925 P_("Icon name for primary icon"),
927 GTK_PARAM_READWRITE));
930 * GtkEntry:secondary-icon-name:
932 * The icon name to use for the secondary icon for the entry.
936 g_object_class_install_property (gobject_class,
937 PROP_ICON_NAME_SECONDARY,
938 g_param_spec_string ("secondary-icon-name",
939 P_("Secondary icon name"),
940 P_("Icon name for secondary icon"),
942 GTK_PARAM_READWRITE));
945 * GtkEntry:primary-icon-gicon:
947 * The #GIcon to use for the primary icon for the entry.
951 g_object_class_install_property (gobject_class,
953 g_param_spec_object ("primary-icon-gicon",
955 P_("GIcon for primary icon"),
957 GTK_PARAM_READWRITE));
960 * GtkEntry:secondary-icon-gicon:
962 * The #GIcon to use for the secondary icon for the entry.
966 g_object_class_install_property (gobject_class,
967 PROP_GICON_SECONDARY,
968 g_param_spec_object ("secondary-icon-gicon",
969 P_("Secondary GIcon"),
970 P_("GIcon for secondary icon"),
972 GTK_PARAM_READWRITE));
975 * GtkEntry:primary-icon-storage-type:
977 * The representation which is used for the primary icon of the entry.
981 g_object_class_install_property (gobject_class,
982 PROP_STORAGE_TYPE_PRIMARY,
983 g_param_spec_enum ("primary-icon-storage-type",
984 P_("Primary storage type"),
985 P_("The representation being used for primary icon"),
988 GTK_PARAM_READABLE));
991 * GtkEntry:secondary-icon-storage-type:
993 * The representation which is used for the secondary icon of the entry.
997 g_object_class_install_property (gobject_class,
998 PROP_STORAGE_TYPE_SECONDARY,
999 g_param_spec_enum ("secondary-icon-storage-type",
1000 P_("Secondary storage type"),
1001 P_("The representation being used for secondary icon"),
1002 GTK_TYPE_IMAGE_TYPE,
1004 GTK_PARAM_READABLE));
1007 * GtkEntry:primary-icon-activatable:
1009 * Whether the primary icon is activatable.
1011 * GTK+ emits the #GtkEntry::icon-press and #GtkEntry::icon-release
1012 * signals only on sensitive, activatable icons.
1014 * Sensitive, but non-activatable icons can be used for purely
1015 * informational purposes.
1019 g_object_class_install_property (gobject_class,
1020 PROP_ACTIVATABLE_PRIMARY,
1021 g_param_spec_boolean ("primary-icon-activatable",
1022 P_("Primary icon activatable"),
1023 P_("Whether the primary icon is activatable"),
1025 GTK_PARAM_READWRITE));
1028 * GtkEntry:secondary-icon-activatable:
1030 * Whether the secondary icon is activatable.
1032 * GTK+ emits the #GtkEntry::icon-press and #GtkEntry::icon-release
1033 * signals only on sensitive, activatable icons.
1035 * Sensitive, but non-activatable icons can be used for purely
1036 * informational purposes.
1040 g_object_class_install_property (gobject_class,
1041 PROP_ACTIVATABLE_SECONDARY,
1042 g_param_spec_boolean ("secondary-icon-activatable",
1043 P_("Secondary icon activatable"),
1044 P_("Whether the secondary icon is activatable"),
1046 GTK_PARAM_READWRITE));
1050 * GtkEntry:primary-icon-sensitive:
1052 * Whether the primary icon is sensitive.
1054 * An insensitive icon appears grayed out. GTK+ does not emit the
1055 * #GtkEntry::icon-press and #GtkEntry::icon-release signals and
1056 * does not allow DND from insensitive icons.
1058 * An icon should be set insensitive if the action that would trigger
1059 * when clicked is currently not available.
1063 g_object_class_install_property (gobject_class,
1064 PROP_SENSITIVE_PRIMARY,
1065 g_param_spec_boolean ("primary-icon-sensitive",
1066 P_("Primary icon sensitive"),
1067 P_("Whether the primary icon is sensitive"),
1069 GTK_PARAM_READWRITE));
1072 * GtkEntry:secondary-icon-sensitive:
1074 * Whether the secondary icon is sensitive.
1076 * An insensitive icon appears grayed out. GTK+ does not emit the
1077 * #GtkEntry::icon-press and #GtkEntry::icon-release signals and
1078 * does not allow DND from insensitive icons.
1080 * An icon should be set insensitive if the action that would trigger
1081 * when clicked is currently not available.
1085 g_object_class_install_property (gobject_class,
1086 PROP_SENSITIVE_SECONDARY,
1087 g_param_spec_boolean ("secondary-icon-sensitive",
1088 P_("Secondary icon sensitive"),
1089 P_("Whether the secondary icon is sensitive"),
1091 GTK_PARAM_READWRITE));
1094 * GtkEntry:primary-icon-tooltip-text:
1096 * The contents of the tooltip on the primary icon.
1098 * Also see gtk_entry_set_icon_tooltip_text().
1102 g_object_class_install_property (gobject_class,
1103 PROP_TOOLTIP_TEXT_PRIMARY,
1104 g_param_spec_string ("primary-icon-tooltip-text",
1105 P_("Primary icon tooltip text"),
1106 P_("The contents of the tooltip on the primary icon"),
1108 GTK_PARAM_READWRITE));
1111 * GtkEntry:secondary-icon-tooltip-text:
1113 * The contents of the tooltip on the secondary icon.
1115 * Also see gtk_entry_set_icon_tooltip_text().
1119 g_object_class_install_property (gobject_class,
1120 PROP_TOOLTIP_TEXT_SECONDARY,
1121 g_param_spec_string ("secondary-icon-tooltip-text",
1122 P_("Secondary icon tooltip text"),
1123 P_("The contents of the tooltip on the secondary icon"),
1125 GTK_PARAM_READWRITE));
1128 * GtkEntry:primary-icon-tooltip-markup:
1130 * The contents of the tooltip on the primary icon, which is marked up
1131 * with the <link linkend="PangoMarkupFormat">Pango text markup
1134 * Also see gtk_entry_set_icon_tooltip_markup().
1138 g_object_class_install_property (gobject_class,
1139 PROP_TOOLTIP_MARKUP_PRIMARY,
1140 g_param_spec_string ("primary-icon-tooltip-markup",
1141 P_("Primary icon tooltip markup"),
1142 P_("The contents of the tooltip on the primary icon"),
1144 GTK_PARAM_READWRITE));
1147 * GtkEntry:secondary-icon-tooltip-markup:
1149 * The contents of the tooltip on the secondary icon, which is marked up
1150 * with the <link linkend="PangoMarkupFormat">Pango text markup
1153 * Also see gtk_entry_set_icon_tooltip_markup().
1157 g_object_class_install_property (gobject_class,
1158 PROP_TOOLTIP_MARKUP_SECONDARY,
1159 g_param_spec_string ("secondary-icon-tooltip-markup",
1160 P_("Secondary icon tooltip markup"),
1161 P_("The contents of the tooltip on the secondary icon"),
1163 GTK_PARAM_READWRITE));
1166 * GtkEntry:im-module:
1168 * Which IM (input method) module should be used for this entry.
1169 * See #GtkIMContext.
1171 * Setting this to a non-%NULL value overrides the
1172 * system-wide IM module setting. See the GtkSettings
1173 * #GtkSettings:gtk-im-module property.
1177 g_object_class_install_property (gobject_class,
1179 g_param_spec_string ("im-module",
1181 P_("Which IM module should be used"),
1183 GTK_PARAM_READWRITE));
1186 * GtkEntry:icon-prelight:
1188 * The prelight style property determines whether activatable
1189 * icons prelight on mouseover.
1193 gtk_widget_class_install_style_property (widget_class,
1194 g_param_spec_boolean ("icon-prelight",
1195 P_("Icon Prelight"),
1196 P_("Whether activatable icons should prelight when hovered"),
1198 GTK_PARAM_READABLE));
1201 * GtkEntry::populate-popup:
1202 * @entry: The entry on which the signal is emitted
1203 * @menu: the menu that is being populated
1205 * The ::populate-popup signal gets emitted before showing the
1206 * context menu of the entry.
1208 * If you need to add items to the context menu, connect
1209 * to this signal and append your menuitems to the @menu.
1211 signals[POPULATE_POPUP] =
1212 g_signal_new (I_("populate-popup"),
1213 G_OBJECT_CLASS_TYPE (gobject_class),
1215 G_STRUCT_OFFSET (GtkEntryClass, populate_popup),
1217 _gtk_marshal_VOID__OBJECT,
1221 /* Action signals */
1224 * GtkEntry::activate:
1225 * @entry: The entry on which the signal is emitted
1227 * A <link linkend="keybinding-signals">keybinding signal</link>
1228 * which gets emitted when the user activates the entry.
1230 * Applications should not connect to it, but may emit it with
1231 * g_signal_emit_by_name() if they need to control activation
1234 * The default bindings for this signal are all forms of the Enter key.
1237 g_signal_new (I_("activate"),
1238 G_OBJECT_CLASS_TYPE (gobject_class),
1239 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1240 G_STRUCT_OFFSET (GtkEntryClass, activate),
1242 _gtk_marshal_VOID__VOID,
1244 widget_class->activate_signal = signals[ACTIVATE];
1247 * GtkEntry::move-cursor:
1248 * @entry: the object which received the signal
1249 * @step: the granularity of the move, as a #GtkMovementStep
1250 * @count: the number of @step units to move
1251 * @extend_selection: %TRUE if the move should extend the selection
1253 * The ::move-cursor signal is a
1254 * <link linkend="keybinding-signals">keybinding signal</link>
1255 * which gets emitted when the user initiates a cursor movement.
1256 * If the cursor is not visible in @entry, this signal causes
1257 * the viewport to be moved instead.
1259 * Applications should not connect to it, but may emit it with
1260 * g_signal_emit_by_name() if they need to control the cursor
1263 * The default bindings for this signal come in two variants,
1264 * the variant with the Shift modifier extends the selection,
1265 * the variant without the Shift modifer does not.
1266 * There are too many key combinations to list them all here.
1268 * <listitem>Arrow keys move by individual characters/lines</listitem>
1269 * <listitem>Ctrl-arrow key combinations move by words/paragraphs</listitem>
1270 * <listitem>Home/End keys move to the ends of the buffer</listitem>
1273 signals[MOVE_CURSOR] =
1274 g_signal_new (I_("move-cursor"),
1275 G_OBJECT_CLASS_TYPE (gobject_class),
1276 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1277 G_STRUCT_OFFSET (GtkEntryClass, move_cursor),
1279 _gtk_marshal_VOID__ENUM_INT_BOOLEAN,
1281 GTK_TYPE_MOVEMENT_STEP,
1286 * GtkEntry::insert-at-cursor:
1287 * @entry: the object which received the signal
1288 * @string: the string to insert
1290 * The ::insert-at-cursor signal is a
1291 * <link linkend="keybinding-signals">keybinding signal</link>
1292 * which gets emitted when the user initiates the insertion of a
1293 * fixed string at the cursor.
1295 * This signal has no default bindings.
1297 signals[INSERT_AT_CURSOR] =
1298 g_signal_new (I_("insert-at-cursor"),
1299 G_OBJECT_CLASS_TYPE (gobject_class),
1300 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1301 G_STRUCT_OFFSET (GtkEntryClass, insert_at_cursor),
1303 _gtk_marshal_VOID__STRING,
1308 * GtkEntry::delete-from-cursor:
1309 * @entry: the object which received the signal
1310 * @type: the granularity of the deletion, as a #GtkDeleteType
1311 * @count: the number of @type units to delete
1313 * The ::delete-from-cursor signal is a
1314 * <link linkend="keybinding-signals">keybinding signal</link>
1315 * which gets emitted when the user initiates a text deletion.
1317 * If the @type is %GTK_DELETE_CHARS, GTK+ deletes the selection
1318 * if there is one, otherwise it deletes the requested number
1321 * The default bindings for this signal are
1322 * Delete for deleting a character and Ctrl-Delete for
1325 signals[DELETE_FROM_CURSOR] =
1326 g_signal_new (I_("delete-from-cursor"),
1327 G_OBJECT_CLASS_TYPE (gobject_class),
1328 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1329 G_STRUCT_OFFSET (GtkEntryClass, delete_from_cursor),
1331 _gtk_marshal_VOID__ENUM_INT,
1333 GTK_TYPE_DELETE_TYPE,
1337 * GtkEntry::backspace:
1338 * @entry: the object which received the signal
1340 * The ::backspace signal is a
1341 * <link linkend="keybinding-signals">keybinding signal</link>
1342 * which gets emitted when the user asks for it.
1344 * The default bindings for this signal are
1345 * Backspace and Shift-Backspace.
1347 signals[BACKSPACE] =
1348 g_signal_new (I_("backspace"),
1349 G_OBJECT_CLASS_TYPE (gobject_class),
1350 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1351 G_STRUCT_OFFSET (GtkEntryClass, backspace),
1353 _gtk_marshal_VOID__VOID,
1357 * GtkEntry::cut-clipboard:
1358 * @entry: the object which received the signal
1360 * The ::cut-clipboard signal is a
1361 * <link linkend="keybinding-signals">keybinding signal</link>
1362 * which gets emitted to cut the selection to the clipboard.
1364 * The default bindings for this signal are
1365 * Ctrl-x and Shift-Delete.
1367 signals[CUT_CLIPBOARD] =
1368 g_signal_new (I_("cut-clipboard"),
1369 G_OBJECT_CLASS_TYPE (gobject_class),
1370 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1371 G_STRUCT_OFFSET (GtkEntryClass, cut_clipboard),
1373 _gtk_marshal_VOID__VOID,
1377 * GtkEntry::copy-clipboard:
1378 * @entry: the object which received the signal
1380 * The ::copy-clipboard signal is a
1381 * <link linkend="keybinding-signals">keybinding signal</link>
1382 * which gets emitted to copy the selection to the clipboard.
1384 * The default bindings for this signal are
1385 * Ctrl-c and Ctrl-Insert.
1387 signals[COPY_CLIPBOARD] =
1388 g_signal_new (I_("copy-clipboard"),
1389 G_OBJECT_CLASS_TYPE (gobject_class),
1390 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1391 G_STRUCT_OFFSET (GtkEntryClass, copy_clipboard),
1393 _gtk_marshal_VOID__VOID,
1397 * GtkEntry::paste-clipboard:
1398 * @entry: the object which received the signal
1400 * The ::paste-clipboard signal is a
1401 * <link linkend="keybinding-signals">keybinding signal</link>
1402 * which gets emitted to paste the contents of the clipboard
1403 * into the text view.
1405 * The default bindings for this signal are
1406 * Ctrl-v and Shift-Insert.
1408 signals[PASTE_CLIPBOARD] =
1409 g_signal_new (I_("paste-clipboard"),
1410 G_OBJECT_CLASS_TYPE (gobject_class),
1411 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1412 G_STRUCT_OFFSET (GtkEntryClass, paste_clipboard),
1414 _gtk_marshal_VOID__VOID,
1418 * GtkEntry::toggle-overwrite:
1419 * @entry: the object which received the signal
1421 * The ::toggle-overwrite signal is a
1422 * <link linkend="keybinding-signals">keybinding signal</link>
1423 * which gets emitted to toggle the overwrite mode of the entry.
1425 * The default bindings for this signal is Insert.
1427 signals[TOGGLE_OVERWRITE] =
1428 g_signal_new (I_("toggle-overwrite"),
1429 G_OBJECT_CLASS_TYPE (gobject_class),
1430 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1431 G_STRUCT_OFFSET (GtkEntryClass, toggle_overwrite),
1433 _gtk_marshal_VOID__VOID,
1437 * GtkEntry::icon-press:
1438 * @entry: The entry on which the signal is emitted
1439 * @icon_pos: The position of the clicked icon
1440 * @event: the button press event
1442 * The ::icon-press signal is emitted when an activatable icon
1447 signals[ICON_PRESS] =
1448 g_signal_new (I_("icon-press"),
1449 G_TYPE_FROM_CLASS (gobject_class),
1450 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1453 _gtk_marshal_VOID__ENUM_BOXED,
1455 GTK_TYPE_ENTRY_ICON_POSITION,
1456 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1459 * GtkEntry::icon-release:
1460 * @entry: The entry on which the signal is emitted
1461 * @icon_pos: The position of the clicked icon
1462 * @event: the button release event
1464 * The ::icon-release signal is emitted on the button release from a
1465 * mouse click over an activatable icon.
1469 signals[ICON_RELEASE] =
1470 g_signal_new (I_("icon-release"),
1471 G_TYPE_FROM_CLASS (gobject_class),
1472 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1475 _gtk_marshal_VOID__ENUM_BOXED,
1477 GTK_TYPE_ENTRY_ICON_POSITION,
1478 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1485 binding_set = gtk_binding_set_by_class (class);
1487 /* Moving the insertion point */
1488 add_move_binding (binding_set, GDK_Right, 0,
1489 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1491 add_move_binding (binding_set, GDK_Left, 0,
1492 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1494 add_move_binding (binding_set, GDK_KP_Right, 0,
1495 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1497 add_move_binding (binding_set, GDK_KP_Left, 0,
1498 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1500 add_move_binding (binding_set, GDK_Right, GDK_CONTROL_MASK,
1501 GTK_MOVEMENT_WORDS, 1);
1503 add_move_binding (binding_set, GDK_Left, GDK_CONTROL_MASK,
1504 GTK_MOVEMENT_WORDS, -1);
1506 add_move_binding (binding_set, GDK_KP_Right, GDK_CONTROL_MASK,
1507 GTK_MOVEMENT_WORDS, 1);
1509 add_move_binding (binding_set, GDK_KP_Left, GDK_CONTROL_MASK,
1510 GTK_MOVEMENT_WORDS, -1);
1512 add_move_binding (binding_set, GDK_Home, 0,
1513 GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
1515 add_move_binding (binding_set, GDK_End, 0,
1516 GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
1518 add_move_binding (binding_set, GDK_KP_Home, 0,
1519 GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
1521 add_move_binding (binding_set, GDK_KP_End, 0,
1522 GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
1524 add_move_binding (binding_set, GDK_Home, GDK_CONTROL_MASK,
1525 GTK_MOVEMENT_BUFFER_ENDS, -1);
1527 add_move_binding (binding_set, GDK_End, GDK_CONTROL_MASK,
1528 GTK_MOVEMENT_BUFFER_ENDS, 1);
1530 add_move_binding (binding_set, GDK_KP_Home, GDK_CONTROL_MASK,
1531 GTK_MOVEMENT_BUFFER_ENDS, -1);
1533 add_move_binding (binding_set, GDK_KP_End, GDK_CONTROL_MASK,
1534 GTK_MOVEMENT_BUFFER_ENDS, 1);
1538 gtk_binding_entry_add_signal (binding_set, GDK_a, GDK_CONTROL_MASK,
1540 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1542 G_TYPE_BOOLEAN, FALSE);
1543 gtk_binding_entry_add_signal (binding_set, GDK_a, GDK_CONTROL_MASK,
1545 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1547 G_TYPE_BOOLEAN, TRUE);
1549 gtk_binding_entry_add_signal (binding_set, GDK_slash, GDK_CONTROL_MASK,
1551 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1553 G_TYPE_BOOLEAN, FALSE);
1554 gtk_binding_entry_add_signal (binding_set, GDK_slash, GDK_CONTROL_MASK,
1556 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1558 G_TYPE_BOOLEAN, TRUE);
1561 gtk_binding_entry_add_signal (binding_set, GDK_backslash, GDK_CONTROL_MASK,
1563 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_VISUAL_POSITIONS,
1565 G_TYPE_BOOLEAN, FALSE);
1566 gtk_binding_entry_add_signal (binding_set, GDK_a, GDK_SHIFT_MASK | GDK_CONTROL_MASK,
1568 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_VISUAL_POSITIONS,
1570 G_TYPE_BOOLEAN, FALSE);
1574 gtk_binding_entry_add_signal (binding_set, GDK_Return, 0,
1576 gtk_binding_entry_add_signal (binding_set, GDK_ISO_Enter, 0,
1578 gtk_binding_entry_add_signal (binding_set, GDK_KP_Enter, 0,
1582 gtk_binding_entry_add_signal (binding_set, GDK_Delete, 0,
1583 "delete-from-cursor", 2,
1584 G_TYPE_ENUM, GTK_DELETE_CHARS,
1587 gtk_binding_entry_add_signal (binding_set, GDK_KP_Delete, 0,
1588 "delete-from-cursor", 2,
1589 G_TYPE_ENUM, GTK_DELETE_CHARS,
1592 gtk_binding_entry_add_signal (binding_set, GDK_BackSpace, 0,
1595 /* Make this do the same as Backspace, to help with mis-typing */
1596 gtk_binding_entry_add_signal (binding_set, GDK_BackSpace, GDK_SHIFT_MASK,
1599 gtk_binding_entry_add_signal (binding_set, GDK_Delete, GDK_CONTROL_MASK,
1600 "delete-from-cursor", 2,
1601 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1604 gtk_binding_entry_add_signal (binding_set, GDK_KP_Delete, GDK_CONTROL_MASK,
1605 "delete-from-cursor", 2,
1606 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1609 gtk_binding_entry_add_signal (binding_set, GDK_BackSpace, GDK_CONTROL_MASK,
1610 "delete-from-cursor", 2,
1611 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1614 /* Cut/copy/paste */
1616 gtk_binding_entry_add_signal (binding_set, GDK_x, GDK_CONTROL_MASK,
1617 "cut-clipboard", 0);
1618 gtk_binding_entry_add_signal (binding_set, GDK_c, GDK_CONTROL_MASK,
1619 "copy-clipboard", 0);
1620 gtk_binding_entry_add_signal (binding_set, GDK_v, GDK_CONTROL_MASK,
1621 "paste-clipboard", 0);
1623 gtk_binding_entry_add_signal (binding_set, GDK_Delete, GDK_SHIFT_MASK,
1624 "cut-clipboard", 0);
1625 gtk_binding_entry_add_signal (binding_set, GDK_Insert, GDK_CONTROL_MASK,
1626 "copy-clipboard", 0);
1627 gtk_binding_entry_add_signal (binding_set, GDK_Insert, GDK_SHIFT_MASK,
1628 "paste-clipboard", 0);
1631 gtk_binding_entry_add_signal (binding_set, GDK_Insert, 0,
1632 "toggle-overwrite", 0);
1633 gtk_binding_entry_add_signal (binding_set, GDK_KP_Insert, 0,
1634 "toggle-overwrite", 0);
1637 * GtkEntry:inner-border:
1639 * Sets the text area's border between the text and the frame.
1643 gtk_widget_class_install_style_property (widget_class,
1644 g_param_spec_boxed ("inner-border",
1646 P_("Border between text and frame."),
1648 GTK_PARAM_READABLE));
1651 * GtkEntry:state-hint:
1653 * Indicates whether to pass a proper widget state when
1654 * drawing the shadow and the widget background.
1658 gtk_widget_class_install_style_property (widget_class,
1659 g_param_spec_boolean ("state-hint",
1661 P_("Whether to pass a proper state when drawing shadow or background"),
1663 GTK_PARAM_READABLE));
1665 gtk_settings_install_property (g_param_spec_boolean ("gtk-entry-select-on-focus",
1666 P_("Select on focus"),
1667 P_("Whether to select the contents of an entry when it is focused"),
1669 GTK_PARAM_READWRITE));
1672 * GtkSettings:gtk-entry-password-hint-timeout:
1674 * How long to show the last input character in hidden
1675 * entries. This value is in milliseconds. 0 disables showing the
1676 * last char. 600 is a good value for enabling it.
1680 gtk_settings_install_property (g_param_spec_uint ("gtk-entry-password-hint-timeout",
1681 P_("Password Hint Timeout"),
1682 P_("How long to show the last input character in hidden entries"),
1684 GTK_PARAM_READWRITE));
1686 g_type_class_add_private (gobject_class, sizeof (GtkEntryPrivate));
1690 gtk_entry_editable_init (GtkEditableClass *iface)
1692 iface->do_insert_text = gtk_entry_insert_text;
1693 iface->do_delete_text = gtk_entry_delete_text;
1694 iface->insert_text = gtk_entry_real_insert_text;
1695 iface->delete_text = gtk_entry_real_delete_text;
1696 iface->get_chars = gtk_entry_get_chars;
1697 iface->set_selection_bounds = gtk_entry_set_selection_bounds;
1698 iface->get_selection_bounds = gtk_entry_get_selection_bounds;
1699 iface->set_position = gtk_entry_real_set_position;
1700 iface->get_position = gtk_entry_get_position;
1704 gtk_entry_cell_editable_init (GtkCellEditableIface *iface)
1706 iface->start_editing = gtk_entry_start_editing;
1710 gtk_entry_set_property (GObject *object,
1712 const GValue *value,
1715 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (object);
1716 GtkEntry *entry = GTK_ENTRY (object);
1722 gboolean new_value = g_value_get_boolean (value);
1724 if (new_value != entry->editable)
1728 _gtk_entry_reset_im_context (entry);
1729 if (GTK_WIDGET_HAS_FOCUS (entry))
1730 gtk_im_context_focus_out (entry->im_context);
1732 entry->preedit_length = 0;
1733 entry->preedit_cursor = 0;
1736 entry->editable = new_value;
1738 if (new_value && GTK_WIDGET_HAS_FOCUS (entry))
1739 gtk_im_context_focus_in (entry->im_context);
1741 gtk_entry_queue_draw (entry);
1746 case PROP_MAX_LENGTH:
1747 gtk_entry_set_max_length (entry, g_value_get_int (value));
1750 case PROP_VISIBILITY:
1751 gtk_entry_set_visibility (entry, g_value_get_boolean (value));
1754 case PROP_HAS_FRAME:
1755 gtk_entry_set_has_frame (entry, g_value_get_boolean (value));
1758 case PROP_INNER_BORDER:
1759 gtk_entry_set_inner_border (entry, g_value_get_boxed (value));
1762 case PROP_INVISIBLE_CHAR:
1763 gtk_entry_set_invisible_char (entry, g_value_get_uint (value));
1766 case PROP_ACTIVATES_DEFAULT:
1767 gtk_entry_set_activates_default (entry, g_value_get_boolean (value));
1770 case PROP_WIDTH_CHARS:
1771 gtk_entry_set_width_chars (entry, g_value_get_int (value));
1775 gtk_entry_set_text (entry, g_value_get_string (value));
1779 gtk_entry_set_alignment (entry, g_value_get_float (value));
1782 case PROP_TRUNCATE_MULTILINE:
1783 entry->truncate_multiline = g_value_get_boolean (value);
1786 case PROP_SHADOW_TYPE:
1787 priv->shadow_type = g_value_get_enum (value);
1790 case PROP_OVERWRITE_MODE:
1791 gtk_entry_set_overwrite_mode (entry, g_value_get_boolean (value));
1794 case PROP_INVISIBLE_CHAR_SET:
1795 if (g_value_get_boolean (value))
1796 priv->invisible_char_set = TRUE;
1798 gtk_entry_unset_invisible_char (entry);
1801 case PROP_CAPS_LOCK_WARNING:
1802 priv->caps_lock_warning = g_value_get_boolean (value);
1805 case PROP_PROGRESS_FRACTION:
1806 gtk_entry_set_progress_fraction (entry, g_value_get_double (value));
1809 case PROP_PROGRESS_PULSE_STEP:
1810 gtk_entry_set_progress_pulse_step (entry, g_value_get_double (value));
1813 case PROP_PIXBUF_PRIMARY:
1814 gtk_entry_set_icon_from_pixbuf (entry,
1815 GTK_ENTRY_ICON_PRIMARY,
1816 g_value_get_object (value));
1819 case PROP_PIXBUF_SECONDARY:
1820 gtk_entry_set_icon_from_pixbuf (entry,
1821 GTK_ENTRY_ICON_SECONDARY,
1822 g_value_get_object (value));
1825 case PROP_STOCK_PRIMARY:
1826 gtk_entry_set_icon_from_stock (entry,
1827 GTK_ENTRY_ICON_PRIMARY,
1828 g_value_get_string (value));
1831 case PROP_STOCK_SECONDARY:
1832 gtk_entry_set_icon_from_stock (entry,
1833 GTK_ENTRY_ICON_SECONDARY,
1834 g_value_get_string (value));
1837 case PROP_ICON_NAME_PRIMARY:
1838 gtk_entry_set_icon_from_icon_name (entry,
1839 GTK_ENTRY_ICON_PRIMARY,
1840 g_value_get_string (value));
1843 case PROP_ICON_NAME_SECONDARY:
1844 gtk_entry_set_icon_from_icon_name (entry,
1845 GTK_ENTRY_ICON_SECONDARY,
1846 g_value_get_string (value));
1849 case PROP_GICON_PRIMARY:
1850 gtk_entry_set_icon_from_gicon (entry,
1851 GTK_ENTRY_ICON_PRIMARY,
1852 g_value_get_object (value));
1855 case PROP_GICON_SECONDARY:
1856 gtk_entry_set_icon_from_gicon (entry,
1857 GTK_ENTRY_ICON_SECONDARY,
1858 g_value_get_object (value));
1861 case PROP_ACTIVATABLE_PRIMARY:
1862 gtk_entry_set_icon_activatable (entry,
1863 GTK_ENTRY_ICON_PRIMARY,
1864 g_value_get_boolean (value));
1867 case PROP_ACTIVATABLE_SECONDARY:
1868 gtk_entry_set_icon_activatable (entry,
1869 GTK_ENTRY_ICON_SECONDARY,
1870 g_value_get_boolean (value));
1873 case PROP_SENSITIVE_PRIMARY:
1874 gtk_entry_set_icon_sensitive (entry,
1875 GTK_ENTRY_ICON_PRIMARY,
1876 g_value_get_boolean (value));
1879 case PROP_SENSITIVE_SECONDARY:
1880 gtk_entry_set_icon_sensitive (entry,
1881 GTK_ENTRY_ICON_SECONDARY,
1882 g_value_get_boolean (value));
1885 case PROP_TOOLTIP_TEXT_PRIMARY:
1886 gtk_entry_set_icon_tooltip_text (entry,
1887 GTK_ENTRY_ICON_PRIMARY,
1888 g_value_get_string (value));
1891 case PROP_TOOLTIP_TEXT_SECONDARY:
1892 gtk_entry_set_icon_tooltip_text (entry,
1893 GTK_ENTRY_ICON_SECONDARY,
1894 g_value_get_string (value));
1897 case PROP_TOOLTIP_MARKUP_PRIMARY:
1898 gtk_entry_set_icon_tooltip_markup (entry,
1899 GTK_ENTRY_ICON_PRIMARY,
1900 g_value_get_string (value));
1903 case PROP_TOOLTIP_MARKUP_SECONDARY:
1904 gtk_entry_set_icon_tooltip_markup (entry,
1905 GTK_ENTRY_ICON_SECONDARY,
1906 g_value_get_string (value));
1909 case PROP_IM_MODULE:
1910 g_free (priv->im_module);
1911 priv->im_module = g_strdup (g_value_get_string (value));
1912 if (GTK_IS_IM_MULTICONTEXT (entry->im_context))
1913 gtk_im_multicontext_set_context_id (GTK_IM_MULTICONTEXT (entry->im_context), priv->im_module);
1916 case PROP_SCROLL_OFFSET:
1917 case PROP_CURSOR_POSITION:
1919 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1925 gtk_entry_get_property (GObject *object,
1930 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (object);
1931 GtkEntry *entry = GTK_ENTRY (object);
1935 case PROP_CURSOR_POSITION:
1936 g_value_set_int (value, entry->current_pos);
1939 case PROP_SELECTION_BOUND:
1940 g_value_set_int (value, entry->selection_bound);
1944 g_value_set_boolean (value, entry->editable);
1947 case PROP_MAX_LENGTH:
1948 g_value_set_int (value, entry->text_max_length);
1951 case PROP_VISIBILITY:
1952 g_value_set_boolean (value, entry->visible);
1955 case PROP_HAS_FRAME:
1956 g_value_set_boolean (value, entry->has_frame);
1959 case PROP_INNER_BORDER:
1960 g_value_set_boxed (value, gtk_entry_get_inner_border (entry));
1963 case PROP_INVISIBLE_CHAR:
1964 g_value_set_uint (value, entry->invisible_char);
1967 case PROP_ACTIVATES_DEFAULT:
1968 g_value_set_boolean (value, entry->activates_default);
1971 case PROP_WIDTH_CHARS:
1972 g_value_set_int (value, entry->width_chars);
1975 case PROP_SCROLL_OFFSET:
1976 g_value_set_int (value, entry->scroll_offset);
1980 g_value_set_string (value, gtk_entry_get_text (entry));
1984 g_value_set_float (value, gtk_entry_get_alignment (entry));
1987 case PROP_TRUNCATE_MULTILINE:
1988 g_value_set_boolean (value, entry->truncate_multiline);
1991 case PROP_SHADOW_TYPE:
1992 g_value_set_enum (value, priv->shadow_type);
1995 case PROP_OVERWRITE_MODE:
1996 g_value_set_boolean (value, entry->overwrite_mode);
1999 case PROP_TEXT_LENGTH:
2000 g_value_set_uint (value, entry->text_length);
2003 case PROP_INVISIBLE_CHAR_SET:
2004 g_value_set_boolean (value, priv->invisible_char_set);
2007 case PROP_IM_MODULE:
2008 g_value_set_string (value, priv->im_module);
2011 case PROP_CAPS_LOCK_WARNING:
2012 g_value_set_boolean (value, priv->caps_lock_warning);
2015 case PROP_PROGRESS_FRACTION:
2016 g_value_set_double (value, priv->progress_fraction);
2019 case PROP_PROGRESS_PULSE_STEP:
2020 g_value_set_double (value, priv->progress_pulse_fraction);
2023 case PROP_PIXBUF_PRIMARY:
2024 g_value_set_object (value,
2025 gtk_entry_get_icon_pixbuf (entry,
2026 GTK_ENTRY_ICON_PRIMARY));
2029 case PROP_PIXBUF_SECONDARY:
2030 g_value_set_object (value,
2031 gtk_entry_get_icon_pixbuf (entry,
2032 GTK_ENTRY_ICON_SECONDARY));
2035 case PROP_STOCK_PRIMARY:
2036 g_value_set_string (value,
2037 gtk_entry_get_icon_stock (entry,
2038 GTK_ENTRY_ICON_PRIMARY));
2041 case PROP_STOCK_SECONDARY:
2042 g_value_set_string (value,
2043 gtk_entry_get_icon_stock (entry,
2044 GTK_ENTRY_ICON_SECONDARY));
2047 case PROP_ICON_NAME_PRIMARY:
2048 g_value_set_string (value,
2049 gtk_entry_get_icon_name (entry,
2050 GTK_ENTRY_ICON_PRIMARY));
2053 case PROP_ICON_NAME_SECONDARY:
2054 g_value_set_string (value,
2055 gtk_entry_get_icon_name (entry,
2056 GTK_ENTRY_ICON_SECONDARY));
2059 case PROP_GICON_PRIMARY:
2060 g_value_set_object (value,
2061 gtk_entry_get_icon_gicon (entry,
2062 GTK_ENTRY_ICON_PRIMARY));
2065 case PROP_GICON_SECONDARY:
2066 g_value_set_object (value,
2067 gtk_entry_get_icon_gicon (entry,
2068 GTK_ENTRY_ICON_SECONDARY));
2071 case PROP_STORAGE_TYPE_PRIMARY:
2072 g_value_set_enum (value,
2073 gtk_entry_get_icon_storage_type (entry,
2074 GTK_ENTRY_ICON_PRIMARY));
2077 case PROP_STORAGE_TYPE_SECONDARY:
2078 g_value_set_enum (value,
2079 gtk_entry_get_icon_storage_type (entry,
2080 GTK_ENTRY_ICON_SECONDARY));
2083 case PROP_ACTIVATABLE_PRIMARY:
2084 g_value_set_boolean (value,
2085 gtk_entry_get_icon_activatable (entry, GTK_ENTRY_ICON_PRIMARY));
2088 case PROP_ACTIVATABLE_SECONDARY:
2089 g_value_set_boolean (value,
2090 gtk_entry_get_icon_activatable (entry, GTK_ENTRY_ICON_SECONDARY));
2093 case PROP_SENSITIVE_PRIMARY:
2094 g_value_set_boolean (value,
2095 gtk_entry_get_icon_sensitive (entry, GTK_ENTRY_ICON_PRIMARY));
2098 case PROP_SENSITIVE_SECONDARY:
2099 g_value_set_boolean (value,
2100 gtk_entry_get_icon_sensitive (entry, GTK_ENTRY_ICON_SECONDARY));
2103 case PROP_TOOLTIP_TEXT_PRIMARY:
2104 g_value_take_string (value,
2105 gtk_entry_get_icon_tooltip_text (entry, GTK_ENTRY_ICON_PRIMARY));
2108 case PROP_TOOLTIP_TEXT_SECONDARY:
2109 g_value_take_string (value,
2110 gtk_entry_get_icon_tooltip_text (entry, GTK_ENTRY_ICON_SECONDARY));
2113 case PROP_TOOLTIP_MARKUP_PRIMARY:
2114 g_value_take_string (value,
2115 gtk_entry_get_icon_tooltip_markup (entry, GTK_ENTRY_ICON_PRIMARY));
2118 case PROP_TOOLTIP_MARKUP_SECONDARY:
2119 g_value_take_string (value,
2120 gtk_entry_get_icon_tooltip_markup (entry, GTK_ENTRY_ICON_SECONDARY));
2124 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2130 find_invisible_char (GtkWidget *widget)
2132 PangoLayout *layout;
2133 PangoAttrList *attr_list;
2135 gunichar invisible_chars [] = {
2136 0x25cf, /* BLACK CIRCLE */
2137 0x2022, /* BULLET */
2138 0x2731, /* HEAVY ASTERISK */
2139 0x273a /* SIXTEEN POINTED ASTERISK */
2142 layout = gtk_widget_create_pango_layout (widget, NULL);
2144 attr_list = pango_attr_list_new ();
2145 pango_attr_list_insert (attr_list, pango_attr_fallback_new (FALSE));
2147 pango_layout_set_attributes (layout, attr_list);
2148 pango_attr_list_unref (attr_list);
2150 for (i = 0; i < G_N_ELEMENTS (invisible_chars); i++)
2152 gchar text[7] = { 0, };
2155 len = g_unichar_to_utf8 (invisible_chars[i], text);
2156 pango_layout_set_text (layout, text, len);
2158 count = pango_layout_get_unknown_glyphs_count (layout);
2162 g_object_unref (layout);
2163 return invisible_chars[i];
2167 g_object_unref (layout);
2172 gtk_entry_init (GtkEntry *entry)
2174 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2176 GTK_WIDGET_SET_FLAGS (entry, GTK_CAN_FOCUS);
2178 entry->text_size = MIN_SIZE;
2179 entry->text = g_malloc (entry->text_size);
2180 entry->text[0] = '\0';
2182 entry->editable = TRUE;
2183 entry->visible = TRUE;
2184 entry->invisible_char = find_invisible_char (GTK_WIDGET (entry));
2185 entry->dnd_position = -1;
2186 entry->width_chars = -1;
2187 entry->is_cell_renderer = FALSE;
2188 entry->editing_canceled = FALSE;
2189 entry->has_frame = TRUE;
2190 entry->truncate_multiline = FALSE;
2191 priv->shadow_type = GTK_SHADOW_IN;
2193 priv->caps_lock_warning = TRUE;
2194 priv->caps_lock_warning_shown = FALSE;
2195 priv->progress_fraction = 0.0;
2196 priv->progress_pulse_fraction = 0.1;
2198 gtk_drag_dest_set (GTK_WIDGET (entry),
2199 GTK_DEST_DEFAULT_HIGHLIGHT,
2201 GDK_ACTION_COPY | GDK_ACTION_MOVE);
2202 gtk_drag_dest_add_text_targets (GTK_WIDGET (entry));
2204 /* This object is completely private. No external entity can gain a reference
2205 * to it; so we create it here and destroy it in finalize().
2207 entry->im_context = gtk_im_multicontext_new ();
2209 g_signal_connect (entry->im_context, "commit",
2210 G_CALLBACK (gtk_entry_commit_cb), entry);
2211 g_signal_connect (entry->im_context, "preedit-changed",
2212 G_CALLBACK (gtk_entry_preedit_changed_cb), entry);
2213 g_signal_connect (entry->im_context, "retrieve-surrounding",
2214 G_CALLBACK (gtk_entry_retrieve_surrounding_cb), entry);
2215 g_signal_connect (entry->im_context, "delete-surrounding",
2216 G_CALLBACK (gtk_entry_delete_surrounding_cb), entry);
2220 get_icon_width (GtkEntry *entry,
2221 GtkEntryIconPosition icon_pos)
2223 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2224 EntryIconInfo *icon_info = priv->icons[icon_pos];
2226 GtkSettings *settings;
2227 gint menu_icon_width;
2229 if (!icon_info || icon_info->pixbuf == NULL)
2232 screen = gtk_widget_get_screen (GTK_WIDGET (entry));
2233 settings = gtk_settings_get_for_screen (screen);
2235 gtk_icon_size_lookup_for_settings (settings, GTK_ICON_SIZE_MENU,
2236 &menu_icon_width, NULL);
2238 return MAX (gdk_pixbuf_get_width (icon_info->pixbuf), menu_icon_width);
2242 get_icon_allocations (GtkEntry *entry,
2243 GtkAllocation *primary,
2244 GtkAllocation *secondary)
2247 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2248 gint x, y, width, height;
2250 gtk_entry_get_text_area_size (entry, &x, &y, &width, &height);
2253 primary->height = height;
2254 primary->width = get_icon_width (entry, GTK_ENTRY_ICON_PRIMARY);
2255 if (primary->width > 0)
2256 primary->width += 2 * priv->icon_margin;
2259 secondary->height = height;
2260 secondary->width = get_icon_width (entry, GTK_ENTRY_ICON_SECONDARY);
2261 if (secondary->width > 0)
2262 secondary->width += 2 * priv->icon_margin;
2264 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
2266 primary->x = x + width - primary->width;
2272 secondary->x = x + width - secondary->width;
2278 begin_change (GtkEntry *entry)
2280 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2282 priv->change_count++;
2286 end_change (GtkEntry *entry)
2288 GtkEditable *editable = GTK_EDITABLE (entry);
2289 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2291 g_return_if_fail (priv->change_count > 0);
2293 priv->change_count--;
2295 if (priv->change_count == 0)
2297 if (priv->real_changed)
2299 g_signal_emit_by_name (editable, "changed");
2300 priv->real_changed = FALSE;
2306 emit_changed (GtkEntry *entry)
2308 GtkEditable *editable = GTK_EDITABLE (entry);
2309 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2311 if (priv->change_count == 0)
2312 g_signal_emit_by_name (editable, "changed");
2314 priv->real_changed = TRUE;
2318 * Overwrite a memory that might contain sensitive information.
2321 trash_area (gchar *area, gsize len)
2323 volatile gchar *varea = (volatile gchar *)area;
2329 gtk_entry_destroy (GtkObject *object)
2331 GtkEntry *entry = GTK_ENTRY (object);
2334 entry->current_pos = entry->selection_bound = entry->text_length = 0;
2335 _gtk_entry_reset_im_context (entry);
2336 gtk_entry_reset_layout (entry);
2338 if (entry->blink_timeout)
2340 g_source_remove (entry->blink_timeout);
2341 entry->blink_timeout = 0;
2344 if (entry->recompute_idle)
2346 g_source_remove (entry->recompute_idle);
2347 entry->recompute_idle = 0;
2350 if (!entry->visible)
2352 /* We want to trash the text here because the entry might be leaked. */
2353 trash_area (entry->text, strlen (entry->text));
2356 GTK_OBJECT_CLASS (gtk_entry_parent_class)->destroy (object);
2360 gtk_entry_dispose (GObject *object)
2362 GtkEntry *entry = GTK_ENTRY (object);
2364 gtk_entry_set_icon_from_pixbuf (entry, GTK_ENTRY_ICON_PRIMARY, NULL);
2365 gtk_entry_set_icon_tooltip_markup (entry, GTK_ENTRY_ICON_PRIMARY, NULL);
2366 gtk_entry_set_icon_from_pixbuf (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
2367 gtk_entry_set_icon_tooltip_markup (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
2369 G_OBJECT_CLASS (gtk_entry_parent_class)->dispose (object);
2373 gtk_entry_finalize (GObject *object)
2375 GtkEntry *entry = GTK_ENTRY (object);
2376 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2377 EntryIconInfo *icon_info = NULL;
2380 for (i = 0; i < MAX_ICONS; i++)
2382 if ((icon_info = priv->icons[i]) != NULL)
2384 if (icon_info->target_list != NULL)
2386 gtk_target_list_unref (icon_info->target_list);
2387 icon_info->target_list = NULL;
2390 g_slice_free (EntryIconInfo, icon_info);
2391 priv->icons[i] = NULL;
2395 gtk_entry_set_completion (entry, NULL);
2397 if (entry->cached_layout)
2398 g_object_unref (entry->cached_layout);
2400 g_object_unref (entry->im_context);
2402 if (entry->blink_timeout)
2403 g_source_remove (entry->blink_timeout);
2405 if (entry->recompute_idle)
2406 g_source_remove (entry->recompute_idle);
2408 entry->text_size = 0;
2412 if (!entry->visible)
2413 trash_area (entry->text, strlen (entry->text));
2414 g_free (entry->text);
2418 g_free (priv->im_module);
2420 G_OBJECT_CLASS (gtk_entry_parent_class)->finalize (object);
2424 update_cursors (GtkWidget *widget)
2426 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2427 EntryIconInfo *icon_info = NULL;
2428 GdkDisplay *display;
2432 for (i = 0; i < MAX_ICONS; i++)
2434 if ((icon_info = priv->icons[i]) != NULL)
2436 if (icon_info->pixbuf != NULL)
2437 gdk_window_show (icon_info->window);
2439 /* The icon windows are not children of the visible entry window,
2440 * thus we can't just inherit the xterm cursor. Slight complication
2441 * here is that for the entry, insensitive => arrow cursor, but for
2442 * an icon in a sensitive entry, insensitive => xterm cursor.
2444 if (GTK_WIDGET_IS_SENSITIVE (widget) &&
2445 (icon_info->insensitive ||
2446 (icon_info->nonactivatable && icon_info->target_list == NULL)))
2448 display = gtk_widget_get_display (widget);
2449 cursor = gdk_cursor_new_for_display (display, GDK_XTERM);
2450 gdk_window_set_cursor (icon_info->window, cursor);
2451 gdk_cursor_unref (cursor);
2455 gdk_window_set_cursor (icon_info->window, NULL);
2462 realize_icon_info (GtkWidget *widget,
2463 GtkEntryIconPosition icon_pos)
2465 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2466 EntryIconInfo *icon_info = priv->icons[icon_pos];
2467 GdkWindowAttr attributes;
2468 gint attributes_mask;
2470 g_return_if_fail (icon_info != NULL);
2474 attributes.width = 1;
2475 attributes.height = 1;
2476 attributes.window_type = GDK_WINDOW_CHILD;
2477 attributes.wclass = GDK_INPUT_OUTPUT;
2478 attributes.visual = gtk_widget_get_visual (widget);
2479 attributes.colormap = gtk_widget_get_colormap (widget);
2480 attributes.event_mask = gtk_widget_get_events (widget);
2481 attributes.event_mask |= (GDK_EXPOSURE_MASK |
2482 GDK_BUTTON_PRESS_MASK |
2483 GDK_BUTTON_RELEASE_MASK |
2484 GDK_BUTTON1_MOTION_MASK |
2485 GDK_BUTTON3_MOTION_MASK |
2486 GDK_POINTER_MOTION_HINT_MASK |
2487 GDK_POINTER_MOTION_MASK |
2488 GDK_ENTER_NOTIFY_MASK |
2489 GDK_LEAVE_NOTIFY_MASK);
2490 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
2492 icon_info->window = gdk_window_new (widget->window,
2495 gdk_window_set_user_data (icon_info->window, widget);
2496 gdk_window_set_background (icon_info->window,
2497 &widget->style->base[GTK_WIDGET_STATE (widget)]);
2499 gtk_widget_queue_resize (widget);
2502 static EntryIconInfo*
2503 construct_icon_info (GtkWidget *widget,
2504 GtkEntryIconPosition icon_pos)
2506 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2507 EntryIconInfo *icon_info;
2509 g_return_val_if_fail (priv->icons[icon_pos] == NULL, NULL);
2511 icon_info = g_slice_new0 (EntryIconInfo);
2512 priv->icons[icon_pos] = icon_info;
2514 if (GTK_WIDGET_REALIZED (widget))
2515 realize_icon_info (widget, icon_pos);
2517 if (GTK_WIDGET_MAPPED (widget))
2518 gdk_window_show (icon_info->window);
2524 gtk_entry_map (GtkWidget *widget)
2526 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2527 EntryIconInfo *icon_info = NULL;
2530 if (GTK_WIDGET_REALIZED (widget) && !GTK_WIDGET_MAPPED (widget))
2532 GTK_WIDGET_CLASS (gtk_entry_parent_class)->map (widget);
2534 for (i = 0; i < MAX_ICONS; i++)
2536 if ((icon_info = priv->icons[i]) != NULL)
2538 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
2539 gdk_window_show (icon_info->window);
2543 update_cursors (widget);
2548 gtk_entry_unmap (GtkWidget *widget)
2550 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2551 EntryIconInfo *icon_info = NULL;
2554 if (GTK_WIDGET_MAPPED (widget))
2556 for (i = 0; i < MAX_ICONS; i++)
2558 if ((icon_info = priv->icons[i]) != NULL)
2560 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
2561 gdk_window_hide (icon_info->window);
2565 GTK_WIDGET_CLASS (gtk_entry_parent_class)->unmap (widget);
2570 gtk_entry_realize (GtkWidget *widget)
2573 GtkEntryPrivate *priv;
2574 EntryIconInfo *icon_info;
2575 GdkWindowAttr attributes;
2576 gint attributes_mask;
2579 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
2580 entry = GTK_ENTRY (widget);
2581 priv = GTK_ENTRY_GET_PRIVATE (entry);
2583 attributes.window_type = GDK_WINDOW_CHILD;
2585 get_widget_window_size (entry, &attributes.x, &attributes.y, &attributes.width, &attributes.height);
2587 attributes.wclass = GDK_INPUT_OUTPUT;
2588 attributes.visual = gtk_widget_get_visual (widget);
2589 attributes.colormap = gtk_widget_get_colormap (widget);
2590 attributes.event_mask = gtk_widget_get_events (widget);
2591 attributes.event_mask |= (GDK_EXPOSURE_MASK |
2592 GDK_BUTTON_PRESS_MASK |
2593 GDK_BUTTON_RELEASE_MASK |
2594 GDK_BUTTON1_MOTION_MASK |
2595 GDK_BUTTON3_MOTION_MASK |
2596 GDK_POINTER_MOTION_HINT_MASK |
2597 GDK_POINTER_MOTION_MASK |
2598 GDK_ENTER_NOTIFY_MASK |
2599 GDK_LEAVE_NOTIFY_MASK);
2600 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
2602 widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, attributes_mask);
2603 gdk_window_set_user_data (widget->window, entry);
2605 gtk_entry_get_text_area_size (entry, &attributes.x, &attributes.y, &attributes.width, &attributes.height);
2607 if (GTK_WIDGET_IS_SENSITIVE (widget))
2609 attributes.cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
2610 attributes_mask |= GDK_WA_CURSOR;
2613 entry->text_area = gdk_window_new (widget->window, &attributes, attributes_mask);
2615 gdk_window_set_user_data (entry->text_area, entry);
2617 if (attributes_mask & GDK_WA_CURSOR)
2618 gdk_cursor_unref (attributes.cursor);
2620 widget->style = gtk_style_attach (widget->style, widget->window);
2622 gdk_window_set_background (widget->window, &widget->style->base[GTK_WIDGET_STATE (widget)]);
2623 gdk_window_set_background (entry->text_area, &widget->style->base[GTK_WIDGET_STATE (widget)]);
2625 gdk_window_show (entry->text_area);
2627 gtk_im_context_set_client_window (entry->im_context, entry->text_area);
2629 gtk_entry_adjust_scroll (entry);
2630 gtk_entry_update_primary_selection (entry);
2633 /* If the icon positions are already setup, create their windows.
2634 * Otherwise if they don't exist yet, then construct_icon_info()
2635 * will create the windows once the widget is already realized.
2637 for (i = 0; i < MAX_ICONS; i++)
2639 if ((icon_info = priv->icons[i]) != NULL)
2641 if (icon_info->window == NULL)
2642 realize_icon_info (widget, i);
2648 gtk_entry_unrealize (GtkWidget *widget)
2650 GtkEntry *entry = GTK_ENTRY (widget);
2651 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2652 GtkClipboard *clipboard;
2653 EntryIconInfo *icon_info;
2656 gtk_entry_reset_layout (entry);
2658 gtk_im_context_set_client_window (entry->im_context, NULL);
2660 clipboard = gtk_widget_get_clipboard (widget, GDK_SELECTION_PRIMARY);
2661 if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (entry))
2662 gtk_clipboard_clear (clipboard);
2664 if (entry->text_area)
2666 gdk_window_set_user_data (entry->text_area, NULL);
2667 gdk_window_destroy (entry->text_area);
2668 entry->text_area = NULL;
2671 if (entry->popup_menu)
2673 gtk_widget_destroy (entry->popup_menu);
2674 entry->popup_menu = NULL;
2677 GTK_WIDGET_CLASS (gtk_entry_parent_class)->unrealize (widget);
2679 for (i = 0; i < MAX_ICONS; i++)
2681 if ((icon_info = priv->icons[i]) != NULL)
2683 if (icon_info->window != NULL)
2685 gdk_window_destroy (icon_info->window);
2686 icon_info->window = NULL;
2693 _gtk_entry_get_borders (GtkEntry *entry,
2697 GtkWidget *widget = GTK_WIDGET (entry);
2698 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2700 if (entry->has_frame)
2702 *xborder = widget->style->xthickness;
2703 *yborder = widget->style->ythickness;
2711 if (!priv->interior_focus)
2713 *xborder += priv->focus_width;
2714 *yborder += priv->focus_width;
2719 gtk_entry_size_request (GtkWidget *widget,
2720 GtkRequisition *requisition)
2722 GtkEntry *entry = GTK_ENTRY (widget);
2723 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2724 PangoFontMetrics *metrics;
2725 gint xborder, yborder;
2726 GtkBorder inner_border;
2727 PangoContext *context;
2728 int icon_widths = 0;
2731 gtk_widget_ensure_style (widget);
2732 context = gtk_widget_get_pango_context (widget);
2733 metrics = pango_context_get_metrics (context,
2734 widget->style->font_desc,
2735 pango_context_get_language (context));
2737 entry->ascent = pango_font_metrics_get_ascent (metrics);
2738 entry->descent = pango_font_metrics_get_descent (metrics);
2740 _gtk_entry_get_borders (entry, &xborder, &yborder);
2741 _gtk_entry_effective_inner_border (entry, &inner_border);
2743 if (entry->width_chars < 0)
2744 requisition->width = MIN_ENTRY_WIDTH + xborder * 2 + inner_border.left + inner_border.right;
2747 gint char_width = pango_font_metrics_get_approximate_char_width (metrics);
2748 gint digit_width = pango_font_metrics_get_approximate_digit_width (metrics);
2749 gint char_pixels = (MAX (char_width, digit_width) + PANGO_SCALE - 1) / PANGO_SCALE;
2751 requisition->width = char_pixels * entry->width_chars + xborder * 2 + inner_border.left + inner_border.right;
2754 requisition->height = PANGO_PIXELS (entry->ascent + entry->descent) + yborder * 2 + inner_border.top + inner_border.bottom;
2756 for (i = 0; i < MAX_ICONS; i++)
2758 icon_width = get_icon_width (entry, i);
2760 icon_widths += icon_width + 2 * priv->icon_margin;
2763 if (icon_widths > requisition->width)
2764 requisition->width += icon_widths;
2766 pango_font_metrics_unref (metrics);
2770 place_windows (GtkEntry *entry)
2773 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2774 gint x, y, width, height;
2775 GtkAllocation primary;
2776 GtkAllocation secondary;
2777 EntryIconInfo *icon_info = NULL;
2779 gtk_entry_get_text_area_size (entry, &x, &y, &width, &height);
2781 get_icon_allocations (entry, &primary, &secondary);
2783 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
2784 x += secondary.width;
2787 width -= primary.width + secondary.width;
2789 if ((icon_info = priv->icons[GTK_ENTRY_ICON_PRIMARY]) != NULL)
2790 gdk_window_move_resize (icon_info->window,
2791 primary.x, primary.y,
2792 primary.width, primary.height);
2794 if ((icon_info = priv->icons[GTK_ENTRY_ICON_SECONDARY]) != NULL)
2795 gdk_window_move_resize (icon_info->window,
2796 secondary.x, secondary.y,
2797 secondary.width, secondary.height);
2799 gdk_window_move_resize (GTK_ENTRY (entry)->text_area, x, y, width, height);
2803 gtk_entry_get_text_area_size (GtkEntry *entry,
2809 GtkWidget *widget = GTK_WIDGET (entry);
2810 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2812 gint xborder, yborder;
2813 GtkRequisition requisition;
2815 gtk_widget_get_child_requisition (widget, &requisition);
2816 _gtk_entry_get_borders (entry, &xborder, &yborder);
2818 if (GTK_WIDGET_REALIZED (widget))
2819 gdk_drawable_get_size (widget->window, NULL, &frame_height);
2821 frame_height = requisition.height;
2823 if (GTK_WIDGET_HAS_FOCUS (widget) && !priv->interior_focus)
2824 frame_height -= 2 * priv->focus_width;
2830 *y = frame_height / 2 - (requisition.height - yborder * 2) / 2;
2833 *width = GTK_WIDGET (entry)->allocation.width - xborder * 2;
2836 *height = requisition.height - yborder * 2;
2840 get_widget_window_size (GtkEntry *entry,
2846 GtkRequisition requisition;
2847 GtkWidget *widget = GTK_WIDGET (entry);
2849 gtk_widget_get_child_requisition (widget, &requisition);
2852 *x = widget->allocation.x;
2856 if (entry->is_cell_renderer)
2857 *y = widget->allocation.y;
2859 *y = widget->allocation.y + (widget->allocation.height - requisition.height) / 2;
2863 *width = widget->allocation.width;
2867 if (entry->is_cell_renderer)
2868 *height = widget->allocation.height;
2870 *height = requisition.height;
2875 _gtk_entry_effective_inner_border (GtkEntry *entry,
2878 GtkBorder *tmp_border;
2880 tmp_border = g_object_get_qdata (G_OBJECT (entry), quark_inner_border);
2884 *border = *tmp_border;
2888 gtk_widget_style_get (GTK_WIDGET (entry), "inner-border", &tmp_border, NULL);
2892 *border = *tmp_border;
2893 gtk_border_free (tmp_border);
2897 *border = default_inner_border;
2901 gtk_entry_size_allocate (GtkWidget *widget,
2902 GtkAllocation *allocation)
2904 GtkEntry *entry = GTK_ENTRY (widget);
2906 widget->allocation = *allocation;
2908 if (GTK_WIDGET_REALIZED (widget))
2910 /* We call gtk_widget_get_child_requisition, since we want (for
2911 * backwards compatibility reasons) the realization here to
2912 * be affected by the usize of the entry, if set
2914 gint x, y, width, height;
2915 GtkEntryCompletion* completion;
2917 get_widget_window_size (entry, &x, &y, &width, &height);
2918 gdk_window_move_resize (widget->window, x, y, width, height);
2920 place_windows (entry);
2921 gtk_entry_recompute (entry);
2923 completion = gtk_entry_get_completion (entry);
2924 if (completion && GTK_WIDGET_MAPPED (completion->priv->popup_window))
2925 _gtk_entry_completion_resize_popup (completion);
2929 /* Kudos to the gnome-panel guys. */
2931 colorshift_pixbuf (GdkPixbuf *dest,
2936 gint width, height, has_alpha, src_rowstride, dest_rowstride;
2937 guchar *target_pixels;
2938 guchar *original_pixels;
2944 has_alpha = gdk_pixbuf_get_has_alpha (src);
2945 width = gdk_pixbuf_get_width (src);
2946 height = gdk_pixbuf_get_height (src);
2947 src_rowstride = gdk_pixbuf_get_rowstride (src);
2948 dest_rowstride = gdk_pixbuf_get_rowstride (dest);
2949 original_pixels = gdk_pixbuf_get_pixels (src);
2950 target_pixels = gdk_pixbuf_get_pixels (dest);
2952 for (i = 0; i < height; i++)
2954 pix_dest = target_pixels + i * dest_rowstride;
2955 pix_src = original_pixels + i * src_rowstride;
2957 for (j = 0; j < width; j++)
2964 *(pix_dest++) = CLAMP (val, 0, 255);
2967 *(pix_dest++) = CLAMP (val, 0, 255);
2970 *(pix_dest++) = CLAMP (val, 0, 255);
2973 *(pix_dest++) = *(pix_src++);
2979 should_prelight (GtkEntry *entry,
2980 GtkEntryIconPosition icon_pos)
2982 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2983 EntryIconInfo *icon_info = priv->icons[icon_pos];
2989 if (icon_info->nonactivatable && icon_info->target_list == NULL)
2992 if (icon_info->pressed)
2995 gtk_widget_style_get (GTK_WIDGET (entry),
2996 "icon-prelight", &prelight,
3003 draw_icon (GtkWidget *widget,
3004 GtkEntryIconPosition icon_pos)
3006 GtkEntry *entry = GTK_ENTRY (widget);
3007 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3008 EntryIconInfo *icon_info = priv->icons[icon_pos];
3010 gint x, y, width, height;
3015 gtk_entry_ensure_pixbuf (entry, icon_pos);
3017 if (icon_info->pixbuf == NULL)
3020 gdk_drawable_get_size (icon_info->window, &width, &height);
3022 /* size_allocate hasn't been called yet. These are the default values.
3024 if (width == 1 || height == 1)
3027 pixbuf = icon_info->pixbuf;
3028 g_object_ref (pixbuf);
3030 if (gdk_pixbuf_get_height (pixbuf) > height)
3032 GdkPixbuf *temp_pixbuf;
3035 scale = height - 2 * priv->icon_margin;
3036 temp_pixbuf = gdk_pixbuf_scale_simple (pixbuf, scale, scale,
3037 GDK_INTERP_BILINEAR);
3038 g_object_unref (pixbuf);
3039 pixbuf = temp_pixbuf;
3042 x = (width - gdk_pixbuf_get_width (pixbuf)) / 2;
3043 y = (height - gdk_pixbuf_get_height (pixbuf)) / 2;
3045 if (!GTK_WIDGET_IS_SENSITIVE (widget) ||
3046 icon_info->insensitive)
3048 GdkPixbuf *temp_pixbuf;
3050 temp_pixbuf = gdk_pixbuf_copy (pixbuf);
3051 gdk_pixbuf_saturate_and_pixelate (pixbuf,
3055 g_object_unref (pixbuf);
3056 pixbuf = temp_pixbuf;
3058 else if (icon_info->prelight)
3060 GdkPixbuf *temp_pixbuf;
3062 temp_pixbuf = gdk_pixbuf_copy (pixbuf);
3063 colorshift_pixbuf (temp_pixbuf, pixbuf, 30);
3064 g_object_unref (pixbuf);
3065 pixbuf = temp_pixbuf;
3068 gdk_draw_pixbuf (icon_info->window, widget->style->black_gc, pixbuf,
3070 GDK_RGB_DITHER_NORMAL, 0, 0);
3072 g_object_unref (pixbuf);
3077 gtk_entry_draw_frame (GtkWidget *widget,
3080 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
3081 gint x = 0, y = 0, width, height;
3082 gboolean state_hint;
3085 gdk_drawable_get_size (widget->window, &width, &height);
3087 /* Fix a problem with some themes which assume that entry->text_area's
3088 * width equals widget->window's width */
3089 if (GTK_IS_SPIN_BUTTON (widget))
3091 gint xborder, yborder;
3093 gtk_entry_get_text_area_size (GTK_ENTRY (widget), &x, NULL, &width, NULL);
3094 _gtk_entry_get_borders (GTK_ENTRY (widget), &xborder, &yborder);
3097 width += xborder * 2;
3100 if (GTK_WIDGET_HAS_FOCUS (widget) && !priv->interior_focus)
3102 x += priv->focus_width;
3103 y += priv->focus_width;
3104 width -= 2 * priv->focus_width;
3105 height -= 2 * priv->focus_width;
3108 gtk_widget_style_get (widget, "state-hint", &state_hint, NULL);
3110 state = GTK_WIDGET_HAS_FOCUS (widget) ?
3111 GTK_STATE_ACTIVE : GTK_WIDGET_STATE (widget);
3113 state = GTK_STATE_NORMAL;
3115 gtk_paint_shadow (widget->style, widget->window,
3116 state, priv->shadow_type,
3117 area, widget, "entry", x, y, width, height);
3119 if (GTK_WIDGET_HAS_FOCUS (widget) && !priv->interior_focus)
3121 x -= priv->focus_width;
3122 y -= priv->focus_width;
3123 width += 2 * priv->focus_width;
3124 height += 2 * priv->focus_width;
3126 gtk_paint_focus (widget->style, widget->window, GTK_WIDGET_STATE (widget),
3127 area, widget, "entry",
3128 0, 0, width, height);
3133 gtk_entry_draw_progress (GtkWidget *widget,
3134 GdkEventExpose *event)
3136 GtkEntryPrivate *private = GTK_ENTRY_GET_PRIVATE (widget);
3137 GtkEntry *entry = GTK_ENTRY (widget);
3139 if (private->progress_pulse_mode)
3141 gdouble value = private->progress_pulse_current;
3142 gint area_width, area_height;
3144 gdk_drawable_get_size (entry->text_area, &area_width, &area_height);
3146 gtk_paint_box (widget->style, entry->text_area,
3147 GTK_STATE_SELECTED, GTK_SHADOW_OUT,
3148 &event->area, widget, "entry-progress",
3149 value * area_width, 0,
3150 private->progress_pulse_fraction * area_width, area_height);
3152 else if (private->progress_fraction > 0)
3154 gdouble value = private->progress_fraction;
3155 gint area_width, area_height;
3157 gdk_drawable_get_size (entry->text_area, &area_width, &area_height);
3159 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
3161 gtk_paint_box (widget->style, entry->text_area,
3162 GTK_STATE_SELECTED, GTK_SHADOW_OUT,
3163 &event->area, widget, "entry-progress",
3164 area_width - value * area_width, 0,
3165 value * area_width, area_height);
3169 gtk_paint_box (widget->style, entry->text_area,
3170 GTK_STATE_SELECTED, GTK_SHADOW_OUT,
3171 &event->area, widget, "entry-progress",
3173 value * area_width, area_height);
3179 gtk_entry_expose (GtkWidget *widget,
3180 GdkEventExpose *event)
3182 GtkEntry *entry = GTK_ENTRY (widget);
3183 gboolean state_hint;
3185 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3187 gtk_widget_style_get (widget, "state-hint", &state_hint, NULL);
3189 state = GTK_WIDGET_HAS_FOCUS (widget) ?
3190 GTK_STATE_ACTIVE : GTK_WIDGET_STATE (widget);
3192 state = GTK_WIDGET_STATE(widget);
3194 if (widget->window == event->window)
3196 gtk_entry_draw_frame (widget, &event->area);
3198 else if (entry->text_area == event->window)
3202 gdk_drawable_get_size (entry->text_area, &width, &height);
3204 gtk_paint_flat_box (widget->style, entry->text_area,
3205 state, GTK_SHADOW_NONE,
3206 &event->area, widget, "entry_bg",
3207 0, 0, width, height);
3209 gtk_entry_draw_progress (widget, event);
3211 if (entry->dnd_position != -1)
3212 gtk_entry_draw_cursor (GTK_ENTRY (widget), CURSOR_DND);
3214 gtk_entry_draw_text (GTK_ENTRY (widget));
3216 if ((entry->visible || entry->invisible_char != 0) &&
3217 GTK_WIDGET_HAS_FOCUS (widget) &&
3218 entry->selection_bound == entry->current_pos && entry->cursor_visible)
3219 gtk_entry_draw_cursor (GTK_ENTRY (widget), CURSOR_STANDARD);
3225 for (i = 0; i < MAX_ICONS; i++)
3227 EntryIconInfo *icon_info = priv->icons[i];
3229 if (icon_info != NULL && event->window == icon_info->window)
3233 gdk_drawable_get_size (icon_info->window, &width, &height);
3235 gtk_paint_flat_box (widget->style, icon_info->window,
3236 GTK_WIDGET_STATE (widget), GTK_SHADOW_NONE,
3237 NULL, widget, "entry_bg",
3238 0, 0, width, height);
3240 draw_icon (widget, i);
3251 gtk_entry_enter_notify (GtkWidget *widget,
3252 GdkEventCrossing *event)
3254 GtkEntry *entry = GTK_ENTRY (widget);
3255 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3258 for (i = 0; i < MAX_ICONS; i++)
3260 EntryIconInfo *icon_info = priv->icons[i];
3262 if (icon_info != NULL && event->window == icon_info->window)
3264 if (should_prelight (entry, i))
3266 icon_info->prelight = TRUE;
3267 gtk_widget_queue_draw (widget);
3278 gtk_entry_leave_notify (GtkWidget *widget,
3279 GdkEventCrossing *event)
3281 GtkEntry *entry = GTK_ENTRY (widget);
3282 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3285 for (i = 0; i < MAX_ICONS; i++)
3287 EntryIconInfo *icon_info = priv->icons[i];
3289 if (icon_info != NULL && event->window == icon_info->window)
3291 if (should_prelight (entry, i))
3293 icon_info->prelight = FALSE;
3294 gtk_widget_queue_draw (widget);
3305 gtk_entry_get_pixel_ranges (GtkEntry *entry,
3309 gint start_char, end_char;
3311 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start_char, &end_char))
3313 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
3314 PangoLayoutLine *line = pango_layout_get_lines_readonly (layout)->data;
3315 const char *text = pango_layout_get_text (layout);
3316 gint start_index = g_utf8_offset_to_pointer (text, start_char) - text;
3317 gint end_index = g_utf8_offset_to_pointer (text, end_char) - text;
3318 gint real_n_ranges, i;
3320 pango_layout_line_get_x_ranges (line, start_index, end_index, ranges, &real_n_ranges);
3326 for (i = 0; i < real_n_ranges; ++i)
3328 r[2 * i + 1] = (r[2 * i + 1] - r[2 * i]) / PANGO_SCALE;
3329 r[2 * i] = r[2 * i] / PANGO_SCALE;
3334 *n_ranges = real_n_ranges;
3346 in_selection (GtkEntry *entry,
3351 gint retval = FALSE;
3353 gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
3355 for (i = 0; i < n_ranges; ++i)
3357 if (x >= ranges[2 * i] && x < ranges[2 * i] + ranges[2 * i + 1])
3369 gtk_entry_button_press (GtkWidget *widget,
3370 GdkEventButton *event)
3372 GtkEntry *entry = GTK_ENTRY (widget);
3373 GtkEditable *editable = GTK_EDITABLE (widget);
3374 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3375 EntryIconInfo *icon_info = NULL;
3377 gint sel_start, sel_end;
3380 for (i = 0; i < MAX_ICONS; i++)
3382 icon_info = priv->icons[i];
3384 if (!icon_info || icon_info->insensitive)
3387 if (event->window == icon_info->window)
3389 if (should_prelight (entry, i))
3391 icon_info->prelight = FALSE;
3392 gtk_widget_queue_draw (widget);
3395 priv->start_x = event->x;
3396 priv->start_y = event->y;
3397 icon_info->pressed = TRUE;
3399 if (!icon_info->nonactivatable)
3400 g_signal_emit (entry, signals[ICON_PRESS], 0, i, event);
3406 if (event->window != entry->text_area ||
3407 (entry->button && event->button != entry->button))
3410 gtk_entry_reset_blink_time (entry);
3412 entry->button = event->button;
3414 if (!GTK_WIDGET_HAS_FOCUS (widget))
3416 entry->in_click = TRUE;
3417 gtk_widget_grab_focus (widget);
3418 entry->in_click = FALSE;
3421 tmp_pos = gtk_entry_find_position (entry, event->x + entry->scroll_offset);
3423 if (event->button == 1)
3425 gboolean have_selection = gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end);
3427 entry->select_words = FALSE;
3428 entry->select_lines = FALSE;
3430 if (event->state & GDK_SHIFT_MASK)
3432 _gtk_entry_reset_im_context (entry);
3434 if (!have_selection) /* select from the current position to the clicked position */
3435 sel_start = sel_end = entry->current_pos;
3437 if (tmp_pos > sel_start && tmp_pos < sel_end)
3439 /* Truncate current selection, but keep it as big as possible */
3440 if (tmp_pos - sel_start > sel_end - tmp_pos)
3441 gtk_entry_set_positions (entry, sel_start, tmp_pos);
3443 gtk_entry_set_positions (entry, tmp_pos, sel_end);
3447 gboolean extend_to_left;
3450 /* Figure out what click selects and extend current selection */
3451 switch (event->type)
3453 case GDK_BUTTON_PRESS:
3454 gtk_entry_set_positions (entry, tmp_pos, tmp_pos);
3457 case GDK_2BUTTON_PRESS:
3458 entry->select_words = TRUE;
3459 gtk_entry_select_word (entry);
3462 case GDK_3BUTTON_PRESS:
3463 entry->select_lines = TRUE;
3464 gtk_entry_select_line (entry);
3471 start = MIN (entry->current_pos, entry->selection_bound);
3472 start = MIN (sel_start, start);
3474 end = MAX (entry->current_pos, entry->selection_bound);
3475 end = MAX (sel_end, end);
3477 if (tmp_pos == sel_start || tmp_pos == sel_end)
3478 extend_to_left = (tmp_pos == start);
3480 extend_to_left = (end == sel_end);
3483 gtk_entry_set_positions (entry, start, end);
3485 gtk_entry_set_positions (entry, end, start);
3488 else /* no shift key */
3489 switch (event->type)
3491 case GDK_BUTTON_PRESS:
3492 if (in_selection (entry, event->x + entry->scroll_offset))
3494 /* Click inside the selection - we'll either start a drag, or
3495 * clear the selection
3497 entry->in_drag = TRUE;
3498 entry->drag_start_x = event->x + entry->scroll_offset;
3499 entry->drag_start_y = event->y;
3502 gtk_editable_set_position (editable, tmp_pos);
3505 case GDK_2BUTTON_PRESS:
3506 /* We ALWAYS receive a GDK_BUTTON_PRESS immediately before
3507 * receiving a GDK_2BUTTON_PRESS so we need to reset
3508 * entry->in_drag which may have been set above
3510 entry->in_drag = FALSE;
3511 entry->select_words = TRUE;
3512 gtk_entry_select_word (entry);
3515 case GDK_3BUTTON_PRESS:
3516 /* We ALWAYS receive a GDK_BUTTON_PRESS immediately before
3517 * receiving a GDK_3BUTTON_PRESS so we need to reset
3518 * entry->in_drag which may have been set above
3520 entry->in_drag = FALSE;
3521 entry->select_lines = TRUE;
3522 gtk_entry_select_line (entry);
3531 else if (event->button == 2 && event->type == GDK_BUTTON_PRESS)
3533 if (entry->editable)
3535 priv->insert_pos = tmp_pos;
3536 gtk_entry_paste (entry, GDK_SELECTION_PRIMARY);
3541 gtk_widget_error_bell (widget);
3544 else if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
3546 gtk_entry_do_popup (entry, event);
3547 entry->button = 0; /* Don't wait for release, since the menu will gtk_grab_add */
3556 gtk_entry_button_release (GtkWidget *widget,
3557 GdkEventButton *event)
3559 GtkEntry *entry = GTK_ENTRY (widget);
3560 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
3561 EntryIconInfo *icon_info = NULL;
3564 for (i = 0; i < MAX_ICONS; i++)
3566 icon_info = priv->icons[i];
3568 if (!icon_info || icon_info->insensitive)
3571 if (event->window == icon_info->window)
3575 gdk_drawable_get_size (icon_info->window, &width, &height);
3577 icon_info->pressed = FALSE;
3579 if (should_prelight (entry, i) &&
3580 event->x >= 0 && event->y >= 0 &&
3581 event->x < width && event->y < height)
3583 icon_info->prelight = TRUE;
3584 gtk_widget_queue_draw (widget);
3587 if (!icon_info->nonactivatable)
3588 g_signal_emit (entry, signals[ICON_RELEASE], 0, i, event);
3594 if (event->window != entry->text_area || entry->button != event->button)
3599 gint tmp_pos = gtk_entry_find_position (entry, entry->drag_start_x);
3601 gtk_editable_set_position (GTK_EDITABLE (entry), tmp_pos);
3608 gtk_entry_update_primary_selection (entry);
3614 _gtk_entry_get_selected_text (GtkEntry *entry)
3616 GtkEditable *editable = GTK_EDITABLE (entry);
3617 gint start_text, end_text;
3620 if (gtk_editable_get_selection_bounds (editable, &start_text, &end_text))
3621 text = gtk_editable_get_chars (editable, start_text, end_text);
3627 gtk_entry_motion_notify (GtkWidget *widget,
3628 GdkEventMotion *event)
3630 GtkEntry *entry = GTK_ENTRY (widget);
3631 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3632 EntryIconInfo *icon_info = NULL;
3633 GdkDragContext *context;
3637 for (i = 0; i < MAX_ICONS; i++)
3639 icon_info = priv->icons[i];
3641 if (!icon_info || icon_info->insensitive)
3644 if (event->window == icon_info->window)
3646 if (icon_info->pressed &&
3647 icon_info->target_list != NULL &&
3648 gtk_drag_check_threshold (widget,
3654 icon_info->in_drag = TRUE;
3655 icon_info->pressed = FALSE;
3656 context = gtk_drag_begin (widget,
3657 icon_info->target_list,
3667 if (entry->mouse_cursor_obscured)
3671 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
3672 gdk_window_set_cursor (entry->text_area, cursor);
3673 gdk_cursor_unref (cursor);
3674 entry->mouse_cursor_obscured = FALSE;
3677 if (event->window != entry->text_area || entry->button != 1)
3680 if (entry->select_lines)
3683 gdk_event_request_motions (event);
3687 if (entry->visible &&
3688 gtk_drag_check_threshold (widget,
3689 entry->drag_start_x, entry->drag_start_y,
3690 event->x + entry->scroll_offset, event->y))
3692 GdkDragContext *context;
3693 GtkTargetList *target_list = gtk_target_list_new (NULL, 0);
3694 guint actions = entry->editable ? GDK_ACTION_COPY | GDK_ACTION_MOVE : GDK_ACTION_COPY;
3696 GdkPixmap *pixmap = NULL;
3698 gtk_target_list_add_text_targets (target_list, 0);
3700 text = _gtk_entry_get_selected_text (entry);
3701 pixmap = _gtk_text_util_create_drag_icon (widget, text, -1);
3703 context = gtk_drag_begin (widget, target_list, actions,
3704 entry->button, (GdkEvent *)event);
3707 gtk_drag_set_icon_pixmap (context,
3708 gdk_drawable_get_colormap (pixmap),
3713 gtk_drag_set_icon_default (context);
3716 g_object_unref (pixmap);
3719 entry->in_drag = FALSE;
3722 gtk_target_list_unref (target_list);
3728 gdk_drawable_get_size (entry->text_area, NULL, &height);
3732 else if (event->y >= height)
3733 tmp_pos = entry->text_length;
3735 tmp_pos = gtk_entry_find_position (entry, event->x + entry->scroll_offset);
3737 if (entry->select_words)
3740 gint old_min, old_max;
3743 min = gtk_entry_move_backward_word (entry, tmp_pos, TRUE);
3744 max = gtk_entry_move_forward_word (entry, tmp_pos, TRUE);
3746 pos = entry->current_pos;
3747 bound = entry->selection_bound;
3749 old_min = MIN(entry->current_pos, entry->selection_bound);
3750 old_max = MAX(entry->current_pos, entry->selection_bound);
3757 else if (old_max < max)
3762 else if (pos == old_min)
3764 if (entry->current_pos != min)
3769 if (entry->current_pos != max)
3773 gtk_entry_set_positions (entry, pos, bound);
3776 gtk_entry_set_positions (entry, tmp_pos, -1);
3783 set_invisible_cursor (GdkWindow *window)
3785 GdkDisplay *display;
3788 display = gdk_drawable_get_display (window);
3789 cursor = gdk_cursor_new_for_display (display, GDK_BLANK_CURSOR);
3791 gdk_window_set_cursor (window, cursor);
3793 gdk_cursor_unref (cursor);
3797 gtk_entry_obscure_mouse_cursor (GtkEntry *entry)
3799 if (entry->mouse_cursor_obscured)
3802 set_invisible_cursor (entry->text_area);
3804 entry->mouse_cursor_obscured = TRUE;
3808 gtk_entry_key_press (GtkWidget *widget,
3811 GtkEntry *entry = GTK_ENTRY (widget);
3813 gtk_entry_reset_blink_time (entry);
3814 gtk_entry_pend_cursor_blink (entry);
3816 if (entry->editable)
3818 if (gtk_im_context_filter_keypress (entry->im_context, event))
3820 gtk_entry_obscure_mouse_cursor (entry);
3821 entry->need_im_reset = TRUE;
3826 if (event->keyval == GDK_Return ||
3827 event->keyval == GDK_KP_Enter ||
3828 event->keyval == GDK_ISO_Enter ||
3829 event->keyval == GDK_Escape)
3831 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
3833 if (completion && completion->priv->completion_timeout)
3835 g_source_remove (completion->priv->completion_timeout);
3836 completion->priv->completion_timeout = 0;
3839 _gtk_entry_reset_im_context (entry);
3842 if (GTK_WIDGET_CLASS (gtk_entry_parent_class)->key_press_event (widget, event))
3843 /* Activate key bindings
3847 if (!entry->editable && event->length)
3848 gtk_widget_error_bell (widget);
3854 gtk_entry_key_release (GtkWidget *widget,
3857 GtkEntry *entry = GTK_ENTRY (widget);
3859 if (entry->editable)
3861 if (gtk_im_context_filter_keypress (entry->im_context, event))
3863 entry->need_im_reset = TRUE;
3868 return GTK_WIDGET_CLASS (gtk_entry_parent_class)->key_release_event (widget, event);
3872 gtk_entry_focus_in (GtkWidget *widget,
3873 GdkEventFocus *event)
3875 GtkEntry *entry = GTK_ENTRY (widget);
3878 gtk_widget_queue_draw (widget);
3880 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (widget));
3882 if (entry->editable)
3884 entry->need_im_reset = TRUE;
3885 gtk_im_context_focus_in (entry->im_context);
3886 keymap_state_changed (keymap, entry);
3887 g_signal_connect (keymap, "state-changed",
3888 G_CALLBACK (keymap_state_changed), entry);
3891 g_signal_connect (keymap, "direction-changed",
3892 G_CALLBACK (keymap_direction_changed), entry);
3894 gtk_entry_reset_blink_time (entry);
3895 gtk_entry_check_cursor_blink (entry);
3901 gtk_entry_focus_out (GtkWidget *widget,
3902 GdkEventFocus *event)
3904 GtkEntry *entry = GTK_ENTRY (widget);
3905 GtkEntryCompletion *completion;
3908 gtk_widget_queue_draw (widget);
3910 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (widget));
3912 if (entry->editable)
3914 entry->need_im_reset = TRUE;
3915 gtk_im_context_focus_out (entry->im_context);
3916 remove_capslock_feedback (entry);
3919 gtk_entry_check_cursor_blink (entry);
3921 g_signal_handlers_disconnect_by_func (keymap, keymap_state_changed, entry);
3922 g_signal_handlers_disconnect_by_func (keymap, keymap_direction_changed, entry);
3924 completion = gtk_entry_get_completion (entry);
3926 _gtk_entry_completion_popdown (completion);
3932 gtk_entry_grab_focus (GtkWidget *widget)
3934 GtkEntry *entry = GTK_ENTRY (widget);
3935 gboolean select_on_focus;
3937 GTK_WIDGET_CLASS (gtk_entry_parent_class)->grab_focus (widget);
3939 if (entry->editable && !entry->in_click)
3941 g_object_get (gtk_widget_get_settings (widget),
3942 "gtk-entry-select-on-focus",
3946 if (select_on_focus)
3947 gtk_editable_select_region (GTK_EDITABLE (widget), 0, -1);
3952 gtk_entry_direction_changed (GtkWidget *widget,
3953 GtkTextDirection previous_dir)
3955 GtkEntry *entry = GTK_ENTRY (widget);
3957 gtk_entry_recompute (entry);
3959 GTK_WIDGET_CLASS (gtk_entry_parent_class)->direction_changed (widget, previous_dir);
3963 gtk_entry_state_changed (GtkWidget *widget,
3964 GtkStateType previous_state)
3966 GtkEntry *entry = GTK_ENTRY (widget);
3967 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
3971 if (GTK_WIDGET_REALIZED (widget))
3973 gdk_window_set_background (widget->window, &widget->style->base[GTK_WIDGET_STATE (widget)]);
3974 gdk_window_set_background (entry->text_area, &widget->style->base[GTK_WIDGET_STATE (widget)]);
3975 for (i = 0; i < MAX_ICONS; i++)
3977 EntryIconInfo *icon_info = priv->icons[i];
3978 if (icon_info && icon_info->window)
3979 gdk_window_set_background (icon_info->window, &widget->style->base[GTK_WIDGET_STATE (widget)]);
3982 if (GTK_WIDGET_IS_SENSITIVE (widget))
3983 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
3987 gdk_window_set_cursor (entry->text_area, cursor);
3990 gdk_cursor_unref (cursor);
3992 entry->mouse_cursor_obscured = FALSE;
3994 update_cursors (widget);
3997 if (!GTK_WIDGET_IS_SENSITIVE (widget))
3999 /* Clear any selection */
4000 gtk_editable_select_region (GTK_EDITABLE (entry), entry->current_pos, entry->current_pos);
4003 gtk_widget_queue_draw (widget);
4007 gtk_entry_screen_changed (GtkWidget *widget,
4008 GdkScreen *old_screen)
4010 gtk_entry_recompute (GTK_ENTRY (widget));
4013 /* GtkEditable method implementations
4016 gtk_entry_insert_text (GtkEditable *editable,
4017 const gchar *new_text,
4018 gint new_text_length,
4021 GtkEntry *entry = GTK_ENTRY (editable);
4025 if (*position < 0 || *position > entry->text_length)
4026 *position = entry->text_length;
4028 g_object_ref (editable);
4030 if (new_text_length <= 63)
4033 text = g_new (gchar, new_text_length + 1);
4035 text[new_text_length] = '\0';
4036 strncpy (text, new_text, new_text_length);
4038 g_signal_emit_by_name (editable, "insert-text", text, new_text_length, position);
4040 if (!entry->visible)
4041 trash_area (text, new_text_length);
4043 if (new_text_length > 63)
4046 g_object_unref (editable);
4050 gtk_entry_delete_text (GtkEditable *editable,
4054 GtkEntry *entry = GTK_ENTRY (editable);
4056 if (end_pos < 0 || end_pos > entry->text_length)
4057 end_pos = entry->text_length;
4060 if (start_pos > end_pos)
4061 start_pos = end_pos;
4063 g_object_ref (editable);
4065 g_signal_emit_by_name (editable, "delete-text", start_pos, end_pos);
4067 g_object_unref (editable);
4071 gtk_entry_get_chars (GtkEditable *editable,
4075 GtkEntry *entry = GTK_ENTRY (editable);
4076 gint start_index, end_index;
4079 end_pos = entry->text_length;
4081 start_pos = MIN (entry->text_length, start_pos);
4082 end_pos = MIN (entry->text_length, end_pos);
4084 start_index = g_utf8_offset_to_pointer (entry->text, start_pos) - entry->text;
4085 end_index = g_utf8_offset_to_pointer (entry->text, end_pos) - entry->text;
4087 return g_strndup (entry->text + start_index, end_index - start_index);
4091 gtk_entry_real_set_position (GtkEditable *editable,
4094 GtkEntry *entry = GTK_ENTRY (editable);
4096 if (position < 0 || position > entry->text_length)
4097 position = entry->text_length;
4099 if (position != entry->current_pos ||
4100 position != entry->selection_bound)
4102 _gtk_entry_reset_im_context (entry);
4103 gtk_entry_set_positions (entry, position, position);
4108 gtk_entry_get_position (GtkEditable *editable)
4110 return GTK_ENTRY (editable)->current_pos;
4114 gtk_entry_set_selection_bounds (GtkEditable *editable,
4118 GtkEntry *entry = GTK_ENTRY (editable);
4121 start = entry->text_length;
4123 end = entry->text_length;
4125 _gtk_entry_reset_im_context (entry);
4127 gtk_entry_set_positions (entry,
4128 MIN (end, entry->text_length),
4129 MIN (start, entry->text_length));
4131 gtk_entry_update_primary_selection (entry);
4135 gtk_entry_get_selection_bounds (GtkEditable *editable,
4139 GtkEntry *entry = GTK_ENTRY (editable);
4141 *start = entry->selection_bound;
4142 *end = entry->current_pos;
4144 return (entry->selection_bound != entry->current_pos);
4148 icon_theme_changed (GtkEntry *entry)
4150 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
4153 for (i = 0; i < MAX_ICONS; i++)
4155 EntryIconInfo *icon_info = priv->icons[i];
4156 if (icon_info != NULL)
4158 if (icon_info->storage_type == GTK_IMAGE_ICON_NAME)
4159 gtk_entry_set_icon_from_icon_name (entry, i, icon_info->icon_name);
4160 else if (icon_info->storage_type == GTK_IMAGE_STOCK)
4161 gtk_entry_set_icon_from_stock (entry, i, icon_info->stock_id);
4162 else if (icon_info->storage_type == GTK_IMAGE_GICON)
4163 gtk_entry_set_icon_from_gicon (entry, i, icon_info->gicon);
4167 gtk_widget_queue_draw (GTK_WIDGET (entry));
4171 icon_margin_changed (GtkEntry *entry)
4173 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
4176 _gtk_entry_effective_inner_border (GTK_ENTRY (entry), &border);
4178 priv->icon_margin = border.left;
4182 gtk_entry_style_set (GtkWidget *widget,
4183 GtkStyle *previous_style)
4185 GtkEntry *entry = GTK_ENTRY (widget);
4186 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
4188 gboolean interior_focus;
4191 gtk_widget_style_get (widget,
4192 "focus-line-width", &focus_width,
4193 "interior-focus", &interior_focus,
4196 priv->focus_width = focus_width;
4197 priv->interior_focus = interior_focus;
4199 if (!priv->invisible_char_set)
4200 entry->invisible_char = find_invisible_char (GTK_WIDGET (entry));
4202 gtk_entry_recompute (entry);
4204 if (previous_style && GTK_WIDGET_REALIZED (widget))
4206 gdk_window_set_background (widget->window, &widget->style->base[GTK_WIDGET_STATE (widget)]);
4207 gdk_window_set_background (entry->text_area, &widget->style->base[GTK_WIDGET_STATE (widget)]);
4208 for (i = 0; i < MAX_ICONS; i++)
4210 EntryIconInfo *icon_info = priv->icons[i];
4211 if (icon_info && icon_info->window)
4212 gdk_window_set_background (icon_info->window, &widget->style->base[GTK_WIDGET_STATE (widget)]);
4216 icon_theme_changed (entry);
4217 icon_margin_changed (entry);
4220 /* GtkCellEditable method implementations
4223 gtk_cell_editable_entry_activated (GtkEntry *entry, gpointer data)
4225 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4226 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4230 gtk_cell_editable_key_press_event (GtkEntry *entry,
4231 GdkEventKey *key_event,
4234 if (key_event->keyval == GDK_Escape)
4236 entry->editing_canceled = TRUE;
4237 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4238 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4243 /* override focus */
4244 if (key_event->keyval == GDK_Up || key_event->keyval == GDK_Down)
4246 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4247 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4256 gtk_entry_start_editing (GtkCellEditable *cell_editable,
4259 GTK_ENTRY (cell_editable)->is_cell_renderer = TRUE;
4261 g_signal_connect (cell_editable, "activate",
4262 G_CALLBACK (gtk_cell_editable_entry_activated), NULL);
4263 g_signal_connect (cell_editable, "key-press-event",
4264 G_CALLBACK (gtk_cell_editable_key_press_event), NULL);
4268 gtk_entry_password_hint_free (GtkEntryPasswordHint *password_hint)
4270 if (password_hint->password_hint_timeout_id)
4271 g_source_remove (password_hint->password_hint_timeout_id);
4273 g_slice_free (GtkEntryPasswordHint, password_hint);
4276 /* Default signal handlers
4279 gtk_entry_real_insert_text (GtkEditable *editable,
4280 const gchar *new_text,
4281 gint new_text_length,
4284 GtkEntry *entry = GTK_ENTRY (editable);
4288 if (new_text_length < 0)
4289 new_text_length = strlen (new_text);
4291 n_chars = g_utf8_strlen (new_text, new_text_length);
4292 if (entry->text_max_length > 0 && n_chars + entry->text_length > entry->text_max_length)
4294 gtk_widget_error_bell (GTK_WIDGET (entry));
4295 n_chars = entry->text_max_length - entry->text_length;
4296 new_text_length = g_utf8_offset_to_pointer (new_text, n_chars) - new_text;
4299 if (new_text_length + entry->n_bytes + 1 > entry->text_size)
4301 gsize prev_size = entry->text_size;
4303 while (new_text_length + entry->n_bytes + 1 > entry->text_size)
4305 if (entry->text_size == 0)
4306 entry->text_size = MIN_SIZE;
4309 if (2 * (guint)entry->text_size < MAX_SIZE &&
4310 2 * (guint)entry->text_size > entry->text_size)
4311 entry->text_size *= 2;
4314 entry->text_size = MAX_SIZE;
4315 if (new_text_length > (gint)entry->text_size - (gint)entry->n_bytes - 1)
4317 new_text_length = (gint)entry->text_size - (gint)entry->n_bytes - 1;
4318 new_text_length = g_utf8_find_prev_char (new_text, new_text + new_text_length + 1) - new_text;
4319 n_chars = g_utf8_strlen (new_text, new_text_length);
4327 entry->text = g_realloc (entry->text, entry->text_size);
4330 /* Same thing, just slower and without leaving stuff in memory. */
4331 gchar *et_new = g_malloc (entry->text_size);
4332 memcpy (et_new, entry->text, MIN (prev_size, entry->text_size));
4333 trash_area (entry->text, prev_size);
4334 g_free (entry->text);
4335 entry->text = et_new;
4339 index = g_utf8_offset_to_pointer (entry->text, *position) - entry->text;
4341 g_memmove (entry->text + index + new_text_length, entry->text + index, entry->n_bytes - index);
4342 memcpy (entry->text + index, new_text, new_text_length);
4344 entry->n_bytes += new_text_length;
4345 entry->text_length += n_chars;
4347 /* NUL terminate for safety and convenience */
4348 entry->text[entry->n_bytes] = '\0';
4350 if (entry->current_pos > *position)
4351 entry->current_pos += n_chars;
4353 if (entry->selection_bound > *position)
4354 entry->selection_bound += n_chars;
4356 if (n_chars == 1 && !entry->visible && (new_text_length < PASSWORD_HINT_MAX))
4358 guint password_hint_timeout;
4360 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
4361 "gtk-entry-password-hint-timeout", &password_hint_timeout,
4364 if (password_hint_timeout > 0)
4366 GtkEntryPasswordHint *password_hint = g_object_get_qdata (G_OBJECT (entry),
4367 quark_password_hint);
4371 password_hint = g_slice_new0 (GtkEntryPasswordHint);
4372 g_object_set_qdata_full (G_OBJECT (entry), quark_password_hint,
4374 (GDestroyNotify) gtk_entry_password_hint_free);
4377 memset (&password_hint->password_hint, 0x0, PASSWORD_HINT_MAX);
4378 password_hint->password_hint_length = new_text_length;
4379 memcpy (&password_hint->password_hint, new_text, new_text_length);
4380 password_hint->password_hint_position = *position + n_chars;
4385 g_object_set_qdata (G_OBJECT (entry), quark_password_hint, NULL);
4388 *position += n_chars;
4390 gtk_entry_recompute (entry);
4392 emit_changed (entry);
4393 g_object_notify (G_OBJECT (editable), "text");
4394 g_object_notify (G_OBJECT (editable), "text-length");
4398 gtk_entry_real_delete_text (GtkEditable *editable,
4402 GtkEntry *entry = GTK_ENTRY (editable);
4406 if (end_pos < 0 || end_pos > entry->text_length)
4407 end_pos = entry->text_length;
4409 if (start_pos < end_pos)
4411 gint start_index = g_utf8_offset_to_pointer (entry->text, start_pos) - entry->text;
4412 gint end_index = g_utf8_offset_to_pointer (entry->text, end_pos) - entry->text;
4414 gint selection_bound;
4416 g_memmove (entry->text + start_index, entry->text + end_index, entry->n_bytes + 1 - end_index);
4417 entry->text_length -= (end_pos - start_pos);
4418 entry->n_bytes -= (end_index - start_index);
4420 /* In password-mode, make sure we don't leave anything sensitive after
4421 * the terminating zero. Note, that the terminating zero already trashed
4424 if (!entry->visible)
4425 trash_area (entry->text + entry->n_bytes + 1, end_index - start_index - 1);
4427 current_pos = entry->current_pos;
4428 if (current_pos > start_pos)
4429 current_pos -= MIN (current_pos, end_pos) - start_pos;
4431 selection_bound = entry->selection_bound;
4432 if (selection_bound > start_pos)
4433 selection_bound -= MIN (selection_bound, end_pos) - start_pos;
4435 gtk_entry_set_positions (entry, current_pos, selection_bound);
4437 /* We might have deleted the selection
4439 gtk_entry_update_primary_selection (entry);
4441 gtk_entry_recompute (entry);
4443 emit_changed (entry);
4444 g_object_notify (G_OBJECT (editable), "text");
4445 g_object_notify (G_OBJECT (editable), "text-length");
4449 /* Compute the X position for an offset that corresponds to the "more important
4450 * cursor position for that offset. We use this when trying to guess to which
4451 * end of the selection we should go to when the user hits the left or
4455 get_better_cursor_x (GtkEntry *entry,
4458 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
4459 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
4460 gboolean split_cursor;
4462 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
4463 const gchar *text = pango_layout_get_text (layout);
4464 gint index = g_utf8_offset_to_pointer (text, offset) - text;
4466 PangoRectangle strong_pos, weak_pos;
4468 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
4469 "gtk-split-cursor", &split_cursor,
4472 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
4475 return strong_pos.x / PANGO_SCALE;
4477 return (keymap_direction == entry->resolved_dir) ? strong_pos.x / PANGO_SCALE : weak_pos.x / PANGO_SCALE;
4481 gtk_entry_move_cursor (GtkEntry *entry,
4482 GtkMovementStep step,
4484 gboolean extend_selection)
4486 gint new_pos = entry->current_pos;
4488 _gtk_entry_reset_im_context (entry);
4490 if (entry->current_pos != entry->selection_bound && !extend_selection)
4492 /* If we have a current selection and aren't extending it, move to the
4493 * start/or end of the selection as appropriate
4497 case GTK_MOVEMENT_VISUAL_POSITIONS:
4499 gint current_x = get_better_cursor_x (entry, entry->current_pos);
4500 gint bound_x = get_better_cursor_x (entry, entry->selection_bound);
4503 new_pos = current_x < bound_x ? entry->current_pos : entry->selection_bound;
4505 new_pos = current_x > bound_x ? entry->current_pos : entry->selection_bound;
4508 case GTK_MOVEMENT_LOGICAL_POSITIONS:
4509 case GTK_MOVEMENT_WORDS:
4511 new_pos = MIN (entry->current_pos, entry->selection_bound);
4513 new_pos = MAX (entry->current_pos, entry->selection_bound);
4515 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
4516 case GTK_MOVEMENT_PARAGRAPH_ENDS:
4517 case GTK_MOVEMENT_BUFFER_ENDS:
4518 new_pos = count < 0 ? 0 : entry->text_length;
4520 case GTK_MOVEMENT_DISPLAY_LINES:
4521 case GTK_MOVEMENT_PARAGRAPHS:
4522 case GTK_MOVEMENT_PAGES:
4523 case GTK_MOVEMENT_HORIZONTAL_PAGES:
4531 case GTK_MOVEMENT_LOGICAL_POSITIONS:
4532 new_pos = gtk_entry_move_logically (entry, new_pos, count);
4534 case GTK_MOVEMENT_VISUAL_POSITIONS:
4535 new_pos = gtk_entry_move_visually (entry, new_pos, count);
4536 if (entry->current_pos == new_pos)
4538 if (!extend_selection)
4540 if (!gtk_widget_keynav_failed (GTK_WIDGET (entry),
4542 GTK_DIR_RIGHT : GTK_DIR_LEFT))
4544 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (entry));
4547 gtk_widget_child_focus (toplevel,
4549 GTK_DIR_RIGHT : GTK_DIR_LEFT);
4554 gtk_widget_error_bell (GTK_WIDGET (entry));
4558 case GTK_MOVEMENT_WORDS:
4561 new_pos = gtk_entry_move_forward_word (entry, new_pos, FALSE);
4566 new_pos = gtk_entry_move_backward_word (entry, new_pos, FALSE);
4569 if (entry->current_pos == new_pos)
4570 gtk_widget_error_bell (GTK_WIDGET (entry));
4572 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
4573 case GTK_MOVEMENT_PARAGRAPH_ENDS:
4574 case GTK_MOVEMENT_BUFFER_ENDS:
4575 new_pos = count < 0 ? 0 : entry->text_length;
4576 if (entry->current_pos == new_pos)
4577 gtk_widget_error_bell (GTK_WIDGET (entry));
4579 case GTK_MOVEMENT_DISPLAY_LINES:
4580 case GTK_MOVEMENT_PARAGRAPHS:
4581 case GTK_MOVEMENT_PAGES:
4582 case GTK_MOVEMENT_HORIZONTAL_PAGES:
4587 if (extend_selection)
4588 gtk_editable_select_region (GTK_EDITABLE (entry), entry->selection_bound, new_pos);
4590 gtk_editable_set_position (GTK_EDITABLE (entry), new_pos);
4592 gtk_entry_pend_cursor_blink (entry);
4596 gtk_entry_insert_at_cursor (GtkEntry *entry,
4599 GtkEditable *editable = GTK_EDITABLE (entry);
4600 gint pos = entry->current_pos;
4602 if (entry->editable)
4604 _gtk_entry_reset_im_context (entry);
4606 gtk_editable_insert_text (editable, str, -1, &pos);
4607 gtk_editable_set_position (editable, pos);
4612 gtk_entry_delete_from_cursor (GtkEntry *entry,
4616 GtkEditable *editable = GTK_EDITABLE (entry);
4617 gint start_pos = entry->current_pos;
4618 gint end_pos = entry->current_pos;
4619 gint old_n_bytes = entry->n_bytes;
4621 _gtk_entry_reset_im_context (entry);
4623 if (!entry->editable)
4625 gtk_widget_error_bell (GTK_WIDGET (entry));
4629 if (entry->selection_bound != entry->current_pos)
4631 gtk_editable_delete_selection (editable);
4637 case GTK_DELETE_CHARS:
4638 end_pos = gtk_entry_move_logically (entry, entry->current_pos, count);
4639 gtk_editable_delete_text (editable, MIN (start_pos, end_pos), MAX (start_pos, end_pos));
4641 case GTK_DELETE_WORDS:
4644 /* Move to end of current word, or if not on a word, end of previous word */
4645 end_pos = gtk_entry_move_backward_word (entry, end_pos, FALSE);
4646 end_pos = gtk_entry_move_forward_word (entry, end_pos, FALSE);
4650 /* Move to beginning of current word, or if not on a word, begining of next word */
4651 start_pos = gtk_entry_move_forward_word (entry, start_pos, FALSE);
4652 start_pos = gtk_entry_move_backward_word (entry, start_pos, FALSE);
4656 case GTK_DELETE_WORD_ENDS:
4659 start_pos = gtk_entry_move_backward_word (entry, start_pos, FALSE);
4664 end_pos = gtk_entry_move_forward_word (entry, end_pos, FALSE);
4667 gtk_editable_delete_text (editable, start_pos, end_pos);
4669 case GTK_DELETE_DISPLAY_LINE_ENDS:
4670 case GTK_DELETE_PARAGRAPH_ENDS:
4672 gtk_editable_delete_text (editable, 0, entry->current_pos);
4674 gtk_editable_delete_text (editable, entry->current_pos, -1);
4676 case GTK_DELETE_DISPLAY_LINES:
4677 case GTK_DELETE_PARAGRAPHS:
4678 gtk_editable_delete_text (editable, 0, -1);
4680 case GTK_DELETE_WHITESPACE:
4681 gtk_entry_delete_whitespace (entry);
4685 if (entry->n_bytes == old_n_bytes)
4686 gtk_widget_error_bell (GTK_WIDGET (entry));
4688 gtk_entry_pend_cursor_blink (entry);
4692 gtk_entry_backspace (GtkEntry *entry)
4694 GtkEditable *editable = GTK_EDITABLE (entry);
4697 _gtk_entry_reset_im_context (entry);
4699 if (!entry->editable || !entry->text)
4701 gtk_widget_error_bell (GTK_WIDGET (entry));
4705 if (entry->selection_bound != entry->current_pos)
4707 gtk_editable_delete_selection (editable);
4711 prev_pos = gtk_entry_move_logically (entry, entry->current_pos, -1);
4713 if (prev_pos < entry->current_pos)
4715 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
4716 PangoLogAttr *log_attrs;
4719 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
4721 if (entry->visible &&
4722 log_attrs[entry->current_pos].backspace_deletes_character)
4724 gchar *cluster_text;
4725 gchar *normalized_text;
4728 cluster_text = gtk_editable_get_chars (editable,
4730 entry->current_pos);
4731 normalized_text = g_utf8_normalize (cluster_text,
4732 strlen (cluster_text),
4734 len = g_utf8_strlen (normalized_text, -1);
4736 gtk_editable_delete_text (editable, prev_pos, entry->current_pos);
4739 gint pos = entry->current_pos;
4741 gtk_editable_insert_text (editable, normalized_text,
4742 g_utf8_offset_to_pointer (normalized_text, len - 1) - normalized_text,
4744 gtk_editable_set_position (editable, pos);
4747 g_free (normalized_text);
4748 g_free (cluster_text);
4752 gtk_editable_delete_text (editable, prev_pos, entry->current_pos);
4759 gtk_widget_error_bell (GTK_WIDGET (entry));
4762 gtk_entry_pend_cursor_blink (entry);
4766 gtk_entry_copy_clipboard (GtkEntry *entry)
4768 GtkEditable *editable = GTK_EDITABLE (entry);
4772 if (gtk_editable_get_selection_bounds (editable, &start, &end))
4774 if (!entry->visible)
4776 gtk_widget_error_bell (GTK_WIDGET (entry));
4780 str = gtk_entry_get_public_chars (entry, start, end);
4781 gtk_clipboard_set_text (gtk_widget_get_clipboard (GTK_WIDGET (entry),
4782 GDK_SELECTION_CLIPBOARD),
4789 gtk_entry_cut_clipboard (GtkEntry *entry)
4791 GtkEditable *editable = GTK_EDITABLE (entry);
4794 if (!entry->visible)
4796 gtk_widget_error_bell (GTK_WIDGET (entry));
4800 gtk_entry_copy_clipboard (entry);
4802 if (entry->editable)
4804 if (gtk_editable_get_selection_bounds (editable, &start, &end))
4805 gtk_editable_delete_text (editable, start, end);
4809 gtk_widget_error_bell (GTK_WIDGET (entry));
4814 gtk_entry_paste_clipboard (GtkEntry *entry)
4816 if (entry->editable)
4817 gtk_entry_paste (entry, GDK_NONE);
4819 gtk_widget_error_bell (GTK_WIDGET (entry));
4823 gtk_entry_delete_cb (GtkEntry *entry)
4825 GtkEditable *editable = GTK_EDITABLE (entry);
4828 if (entry->editable)
4830 if (gtk_editable_get_selection_bounds (editable, &start, &end))
4831 gtk_editable_delete_text (editable, start, end);
4836 gtk_entry_toggle_overwrite (GtkEntry *entry)
4838 entry->overwrite_mode = !entry->overwrite_mode;
4839 gtk_entry_pend_cursor_blink (entry);
4840 gtk_widget_queue_draw (GTK_WIDGET (entry));
4844 gtk_entry_select_all (GtkEntry *entry)
4846 gtk_entry_select_line (entry);
4850 gtk_entry_real_activate (GtkEntry *entry)
4853 GtkWidget *toplevel;
4856 widget = GTK_WIDGET (entry);
4858 if (entry->activates_default)
4860 toplevel = gtk_widget_get_toplevel (widget);
4861 if (GTK_IS_WINDOW (toplevel))
4863 window = GTK_WINDOW (toplevel);
4866 widget != window->default_widget &&
4867 !(widget == window->focus_widget &&
4868 (!window->default_widget || !GTK_WIDGET_SENSITIVE (window->default_widget))))
4869 gtk_window_activate_default (window);
4875 keymap_direction_changed (GdkKeymap *keymap,
4878 gtk_entry_recompute (entry);
4881 /* IM Context Callbacks
4885 gtk_entry_commit_cb (GtkIMContext *context,
4889 if (entry->editable)
4890 gtk_entry_enter_text (entry, str);
4894 gtk_entry_preedit_changed_cb (GtkIMContext *context,
4897 if (entry->editable)
4899 gchar *preedit_string;
4902 gtk_im_context_get_preedit_string (entry->im_context,
4903 &preedit_string, NULL,
4905 entry->preedit_length = strlen (preedit_string);
4906 cursor_pos = CLAMP (cursor_pos, 0, g_utf8_strlen (preedit_string, -1));
4907 entry->preedit_cursor = cursor_pos;
4908 g_free (preedit_string);
4910 gtk_entry_recompute (entry);
4915 gtk_entry_retrieve_surrounding_cb (GtkIMContext *context,
4918 gtk_im_context_set_surrounding (context,
4921 g_utf8_offset_to_pointer (entry->text, entry->current_pos) - entry->text);
4927 gtk_entry_delete_surrounding_cb (GtkIMContext *slave,
4932 if (entry->editable)
4933 gtk_editable_delete_text (GTK_EDITABLE (entry),
4934 entry->current_pos + offset,
4935 entry->current_pos + offset + n_chars);
4940 /* Internal functions
4943 /* Used for im_commit_cb and inserting Unicode chars */
4945 gtk_entry_enter_text (GtkEntry *entry,
4948 GtkEditable *editable = GTK_EDITABLE (entry);
4950 gboolean old_need_im_reset;
4952 old_need_im_reset = entry->need_im_reset;
4953 entry->need_im_reset = FALSE;
4955 if (gtk_editable_get_selection_bounds (editable, NULL, NULL))
4956 gtk_editable_delete_selection (editable);
4959 if (entry->overwrite_mode)
4960 gtk_entry_delete_from_cursor (entry, GTK_DELETE_CHARS, 1);
4963 tmp_pos = entry->current_pos;
4964 gtk_editable_insert_text (editable, str, strlen (str), &tmp_pos);
4965 gtk_editable_set_position (editable, tmp_pos);
4967 entry->need_im_reset = old_need_im_reset;
4970 /* All changes to entry->current_pos and entry->selection_bound
4971 * should go through this function.
4974 gtk_entry_set_positions (GtkEntry *entry,
4976 gint selection_bound)
4978 gboolean changed = FALSE;
4980 g_object_freeze_notify (G_OBJECT (entry));
4982 if (current_pos != -1 &&
4983 entry->current_pos != current_pos)
4985 entry->current_pos = current_pos;
4988 g_object_notify (G_OBJECT (entry), "cursor-position");
4991 if (selection_bound != -1 &&
4992 entry->selection_bound != selection_bound)
4994 entry->selection_bound = selection_bound;
4997 g_object_notify (G_OBJECT (entry), "selection-bound");
5000 g_object_thaw_notify (G_OBJECT (entry));
5004 gtk_entry_move_adjustments (entry);
5005 gtk_entry_recompute (entry);
5010 gtk_entry_reset_layout (GtkEntry *entry)
5012 if (entry->cached_layout)
5014 g_object_unref (entry->cached_layout);
5015 entry->cached_layout = NULL;
5020 update_im_cursor_location (GtkEntry *entry)
5024 gint strong_xoffset;
5025 gint area_width, area_height;
5027 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
5028 gtk_entry_get_text_area_size (entry, NULL, NULL, &area_width, &area_height);
5030 strong_xoffset = strong_x - entry->scroll_offset;
5031 if (strong_xoffset < 0)
5035 else if (strong_xoffset > area_width)
5037 strong_xoffset = area_width;
5039 area.x = strong_xoffset;
5042 area.height = area_height;
5044 gtk_im_context_set_cursor_location (entry->im_context, &area);
5048 recompute_idle_func (gpointer data)
5052 entry = GTK_ENTRY (data);
5054 entry->recompute_idle = 0;
5056 if (gtk_widget_has_screen (GTK_WIDGET (entry)))
5058 gtk_entry_adjust_scroll (entry);
5059 gtk_entry_queue_draw (entry);
5061 update_im_cursor_location (entry);
5068 gtk_entry_recompute (GtkEntry *entry)
5070 gtk_entry_reset_layout (entry);
5071 gtk_entry_check_cursor_blink (entry);
5073 if (!entry->recompute_idle)
5075 entry->recompute_idle = gdk_threads_add_idle_full (G_PRIORITY_HIGH_IDLE + 15, /* between resize and redraw */
5076 recompute_idle_func, entry, NULL);
5081 append_char (GString *str,
5089 char_len = g_unichar_to_utf8 (ch, buf);
5094 g_string_append_len (str, buf, char_len);
5100 gtk_entry_remove_password_hint (gpointer data)
5102 /* Force the string to be redrawn, but now without a visible character */
5103 gtk_entry_recompute (GTK_ENTRY (data));
5108 static PangoLayout *
5109 gtk_entry_create_layout (GtkEntry *entry,
5110 gboolean include_preedit)
5112 GtkWidget *widget = GTK_WIDGET (entry);
5113 PangoLayout *layout = gtk_widget_create_pango_layout (widget, NULL);
5114 PangoAttrList *tmp_attrs = pango_attr_list_new ();
5116 gchar *preedit_string = NULL;
5117 gint preedit_length = 0;
5118 PangoAttrList *preedit_attrs = NULL;
5120 pango_layout_set_single_paragraph_mode (layout, TRUE);
5122 if (include_preedit)
5124 gtk_im_context_get_preedit_string (entry->im_context,
5125 &preedit_string, &preedit_attrs, NULL);
5126 preedit_length = entry->preedit_length;
5131 GString *tmp_string = g_string_new (NULL);
5133 gint cursor_index = g_utf8_offset_to_pointer (entry->text, entry->current_pos) - entry->text;
5137 g_string_prepend_len (tmp_string, entry->text, entry->n_bytes);
5138 g_string_insert (tmp_string, cursor_index, preedit_string);
5143 gunichar invisible_char;
5145 if (entry->invisible_char != 0)
5146 invisible_char = entry->invisible_char;
5148 invisible_char = ' '; /* just pick a char */
5150 ch_len = g_utf8_strlen (entry->text, entry->n_bytes);
5151 append_char (tmp_string, invisible_char, ch_len);
5153 g_utf8_offset_to_pointer (tmp_string->str, entry->current_pos) -
5155 g_string_insert (tmp_string, cursor_index, preedit_string);
5158 pango_layout_set_text (layout, tmp_string->str, tmp_string->len);
5160 pango_attr_list_splice (tmp_attrs, preedit_attrs,
5161 cursor_index, preedit_length);
5163 g_string_free (tmp_string, TRUE);
5167 PangoDirection pango_dir;
5170 pango_dir = pango_find_base_dir (entry->text, entry->n_bytes);
5173 pango_dir = PANGO_DIRECTION_NEUTRAL;
5175 if (pango_dir == PANGO_DIRECTION_NEUTRAL)
5177 if (GTK_WIDGET_HAS_FOCUS (widget))
5179 GdkDisplay *display = gtk_widget_get_display (widget);
5180 GdkKeymap *keymap = gdk_keymap_get_for_display (display);
5181 if (gdk_keymap_get_direction (keymap) == PANGO_DIRECTION_RTL)
5182 pango_dir = PANGO_DIRECTION_RTL;
5184 pango_dir = PANGO_DIRECTION_LTR;
5188 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
5189 pango_dir = PANGO_DIRECTION_RTL;
5191 pango_dir = PANGO_DIRECTION_LTR;
5195 pango_context_set_base_dir (gtk_widget_get_pango_context (widget),
5198 entry->resolved_dir = pango_dir;
5202 pango_layout_set_text (layout, entry->text, entry->n_bytes);
5206 GString *str = g_string_new (NULL);
5207 gunichar invisible_char;
5208 guint password_hint_timeout;
5209 GtkEntryPasswordHint *password_hint;
5211 g_object_get (gtk_widget_get_settings (widget),
5212 "gtk-entry-password-hint-timeout", &password_hint_timeout,
5215 if (entry->invisible_char != 0)
5216 invisible_char = entry->invisible_char;
5218 invisible_char = ' '; /* just pick a char */
5220 password_hint = g_object_get_qdata (G_OBJECT (entry),
5221 quark_password_hint);
5223 if (password_hint && password_hint->password_hint_timeout_id)
5225 g_source_remove (password_hint->password_hint_timeout_id);
5226 password_hint->password_hint_timeout_id = 0;
5229 if (password_hint_timeout == 0 || password_hint == NULL ||
5230 (password_hint && password_hint->password_hint_length == 0))
5232 append_char (str, invisible_char, entry->text_length);
5234 else if (password_hint)
5236 /* Draw hidden characters upto the inserted position,
5237 * then the real thing, pad up to full length
5239 if (password_hint->password_hint_position > 1)
5240 append_char (str, invisible_char,
5241 password_hint->password_hint_position - 1);
5243 g_string_append_len (str, password_hint->password_hint,
5244 password_hint->password_hint_length);
5246 if (password_hint->password_hint_position < entry->text_length)
5247 append_char (str, invisible_char,
5248 entry->text_length -
5249 password_hint->password_hint_position);
5251 /* Now remove this last input character, don't need
5254 memset (password_hint->password_hint, 0, PASSWORD_HINT_MAX);
5255 password_hint->password_hint_length = 0;
5257 password_hint->password_hint_timeout_id =
5258 gdk_threads_add_timeout (password_hint_timeout,
5259 (GSourceFunc) gtk_entry_remove_password_hint,
5263 pango_layout_set_text (layout, str->str, str->len);
5264 g_string_free (str, TRUE);
5268 pango_layout_set_attributes (layout, tmp_attrs);
5270 g_free (preedit_string);
5272 pango_attr_list_unref (preedit_attrs);
5274 pango_attr_list_unref (tmp_attrs);
5279 static PangoLayout *
5280 gtk_entry_ensure_layout (GtkEntry *entry,
5281 gboolean include_preedit)
5283 if (entry->preedit_length > 0 &&
5284 !include_preedit != !entry->cache_includes_preedit)
5285 gtk_entry_reset_layout (entry);
5287 if (!entry->cached_layout)
5289 entry->cached_layout = gtk_entry_create_layout (entry, include_preedit);
5290 entry->cache_includes_preedit = include_preedit;
5293 return entry->cached_layout;
5297 get_layout_position (GtkEntry *entry,
5301 PangoLayout *layout;
5302 PangoRectangle logical_rect;
5303 gint area_width, area_height;
5304 GtkBorder inner_border;
5306 PangoLayoutLine *line;
5308 layout = gtk_entry_ensure_layout (entry, TRUE);
5310 gtk_entry_get_text_area_size (entry, NULL, NULL, &area_width, &area_height);
5311 _gtk_entry_effective_inner_border (entry, &inner_border);
5313 area_height = PANGO_SCALE * (area_height - inner_border.top - inner_border.bottom);
5315 line = pango_layout_get_lines_readonly (layout)->data;
5316 pango_layout_line_get_extents (line, NULL, &logical_rect);
5318 /* Align primarily for locale's ascent/descent */
5319 y_pos = ((area_height - entry->ascent - entry->descent) / 2 +
5320 entry->ascent + logical_rect.y);
5322 /* Now see if we need to adjust to fit in actual drawn string */
5323 if (logical_rect.height > area_height)
5324 y_pos = (area_height - logical_rect.height) / 2;
5327 else if (y_pos + logical_rect.height > area_height)
5328 y_pos = area_height - logical_rect.height;
5330 y_pos = inner_border.top + y_pos / PANGO_SCALE;
5333 *x = inner_border.left - entry->scroll_offset;
5340 gtk_entry_draw_text (GtkEntry *entry)
5344 if (!entry->visible && entry->invisible_char == 0)
5347 if (GTK_WIDGET_DRAWABLE (entry))
5349 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
5352 gint start_pos, end_pos;
5354 widget = GTK_WIDGET (entry);
5356 get_layout_position (entry, &x, &y);
5358 cr = gdk_cairo_create (entry->text_area);
5360 cairo_move_to (cr, x, y);
5361 gdk_cairo_set_source_color (cr, &widget->style->text [widget->state]);
5362 pango_cairo_show_layout (cr, layout);
5364 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start_pos, &end_pos))
5368 PangoRectangle logical_rect;
5369 GdkColor *selection_color, *text_color;
5370 GtkBorder inner_border;
5372 pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
5373 gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
5375 if (GTK_WIDGET_HAS_FOCUS (entry))
5377 selection_color = &widget->style->base [GTK_STATE_SELECTED];
5378 text_color = &widget->style->text [GTK_STATE_SELECTED];
5382 selection_color = &widget->style->base [GTK_STATE_ACTIVE];
5383 text_color = &widget->style->text [GTK_STATE_ACTIVE];
5386 _gtk_entry_effective_inner_border (entry, &inner_border);
5388 for (i = 0; i < n_ranges; ++i)
5389 cairo_rectangle (cr,
5390 inner_border.left - entry->scroll_offset + ranges[2 * i],
5393 logical_rect.height);
5397 gdk_cairo_set_source_color (cr, selection_color);
5400 cairo_move_to (cr, x, y);
5401 gdk_cairo_set_source_color (cr, text_color);
5402 pango_cairo_show_layout (cr, layout);
5412 draw_insertion_cursor (GtkEntry *entry,
5413 GdkRectangle *cursor_location,
5414 gboolean is_primary,
5415 PangoDirection direction,
5416 gboolean draw_arrow)
5418 GtkWidget *widget = GTK_WIDGET (entry);
5419 GtkTextDirection text_dir;
5421 if (direction == PANGO_DIRECTION_LTR)
5422 text_dir = GTK_TEXT_DIR_LTR;
5424 text_dir = GTK_TEXT_DIR_RTL;
5426 gtk_draw_insertion_cursor (widget, entry->text_area, NULL,
5428 is_primary, text_dir, draw_arrow);
5432 gtk_entry_draw_cursor (GtkEntry *entry,
5435 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
5436 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
5438 if (GTK_WIDGET_DRAWABLE (entry))
5440 GtkWidget *widget = GTK_WIDGET (entry);
5441 GdkRectangle cursor_location;
5442 gboolean split_cursor;
5443 PangoRectangle cursor_rect;
5444 GtkBorder inner_border;
5446 gint text_area_height;
5449 gboolean block_at_line_end;
5450 PangoLayout *layout;
5453 _gtk_entry_effective_inner_border (entry, &inner_border);
5455 xoffset = inner_border.left - entry->scroll_offset;
5457 gdk_drawable_get_size (entry->text_area, NULL, &text_area_height);
5459 layout = gtk_entry_ensure_layout (entry, TRUE);
5460 text = pango_layout_get_text (layout);
5461 cursor_index = g_utf8_offset_to_pointer (text, entry->current_pos + entry->preedit_cursor) - text;
5462 if (!entry->overwrite_mode)
5465 block = _gtk_text_util_get_block_cursor_location (layout,
5466 cursor_index, &cursor_rect, &block_at_line_end);
5470 gint strong_x, weak_x;
5471 PangoDirection dir1 = PANGO_DIRECTION_NEUTRAL;
5472 PangoDirection dir2 = PANGO_DIRECTION_NEUTRAL;
5476 gtk_entry_get_cursor_locations (entry, type, &strong_x, &weak_x);
5478 g_object_get (gtk_widget_get_settings (widget),
5479 "gtk-split-cursor", &split_cursor,
5482 dir1 = entry->resolved_dir;
5488 if (weak_x != strong_x)
5490 dir2 = (entry->resolved_dir == PANGO_DIRECTION_LTR) ? PANGO_DIRECTION_RTL : PANGO_DIRECTION_LTR;
5496 if (keymap_direction == entry->resolved_dir)
5502 cursor_location.x = xoffset + x1;
5503 cursor_location.y = inner_border.top;
5504 cursor_location.width = 0;
5505 cursor_location.height = text_area_height - inner_border.top - inner_border.bottom;
5507 draw_insertion_cursor (entry,
5508 &cursor_location, TRUE, dir1,
5509 dir2 != PANGO_DIRECTION_NEUTRAL);
5511 if (dir2 != PANGO_DIRECTION_NEUTRAL)
5513 cursor_location.x = xoffset + x2;
5514 draw_insertion_cursor (entry,
5515 &cursor_location, FALSE, dir2,
5519 else /* overwrite_mode */
5521 GdkColor cursor_color;
5526 get_layout_position (entry, &x, &y);
5528 rect.x = PANGO_PIXELS (cursor_rect.x) + x;
5529 rect.y = PANGO_PIXELS (cursor_rect.y) + y;
5530 rect.width = PANGO_PIXELS (cursor_rect.width);
5531 rect.height = PANGO_PIXELS (cursor_rect.height);
5533 cr = gdk_cairo_create (entry->text_area);
5535 _gtk_widget_get_cursor_color (widget, &cursor_color);
5536 gdk_cairo_set_source_color (cr, &cursor_color);
5537 gdk_cairo_rectangle (cr, &rect);
5540 if (!block_at_line_end)
5542 gdk_cairo_rectangle (cr, &rect);
5544 cairo_move_to (cr, x, y);
5545 gdk_cairo_set_source_color (cr, &widget->style->base[widget->state]);
5546 pango_cairo_show_layout (cr, layout);
5555 gtk_entry_queue_draw (GtkEntry *entry)
5557 if (GTK_WIDGET_DRAWABLE (entry))
5558 gdk_window_invalidate_rect (entry->text_area, NULL, FALSE);
5562 _gtk_entry_reset_im_context (GtkEntry *entry)
5564 if (entry->need_im_reset)
5566 entry->need_im_reset = FALSE;
5567 gtk_im_context_reset (entry->im_context);
5572 gtk_entry_find_position (GtkEntry *entry,
5575 PangoLayout *layout;
5576 PangoLayoutLine *line;
5583 layout = gtk_entry_ensure_layout (entry, TRUE);
5584 text = pango_layout_get_text (layout);
5585 cursor_index = g_utf8_offset_to_pointer (text, entry->current_pos) - text;
5587 line = pango_layout_get_lines_readonly (layout)->data;
5588 pango_layout_line_x_to_index (line, x * PANGO_SCALE, &index, &trailing);
5590 if (index >= cursor_index && entry->preedit_length)
5592 if (index >= cursor_index + entry->preedit_length)
5593 index -= entry->preedit_length;
5596 index = cursor_index;
5601 pos = g_utf8_pointer_to_offset (text, text + index);
5608 gtk_entry_get_cursor_locations (GtkEntry *entry,
5613 if (!entry->visible && !entry->invisible_char)
5623 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
5624 const gchar *text = pango_layout_get_text (layout);
5625 PangoRectangle strong_pos, weak_pos;
5628 if (type == CURSOR_STANDARD)
5630 index = g_utf8_offset_to_pointer (text, entry->current_pos + entry->preedit_cursor) - text;
5632 else /* type == CURSOR_DND */
5634 index = g_utf8_offset_to_pointer (text, entry->dnd_position) - text;
5636 if (entry->dnd_position > entry->current_pos)
5639 index += entry->preedit_length;
5642 gint preedit_len_chars = g_utf8_strlen (text, -1) - entry->text_length;
5643 index += preedit_len_chars * g_unichar_to_utf8 (entry->invisible_char, NULL);
5648 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
5651 *strong_x = strong_pos.x / PANGO_SCALE;
5654 *weak_x = weak_pos.x / PANGO_SCALE;
5659 gtk_entry_adjust_scroll (GtkEntry *entry)
5661 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
5662 gint min_offset, max_offset;
5663 gint text_area_width, text_width;
5664 GtkBorder inner_border;
5665 gint strong_x, weak_x;
5666 gint strong_xoffset, weak_xoffset;
5668 PangoLayout *layout;
5669 PangoLayoutLine *line;
5670 PangoRectangle logical_rect;
5672 if (!GTK_WIDGET_REALIZED (entry))
5675 _gtk_entry_effective_inner_border (entry, &inner_border);
5677 gdk_drawable_get_size (entry->text_area, &text_area_width, NULL);
5678 text_area_width -= inner_border.left + inner_border.right;
5679 if (text_area_width < 0)
5680 text_area_width = 0;
5682 layout = gtk_entry_ensure_layout (entry, TRUE);
5683 line = pango_layout_get_lines_readonly (layout)->data;
5685 pango_layout_line_get_extents (line, NULL, &logical_rect);
5687 /* Display as much text as we can */
5689 if (entry->resolved_dir == PANGO_DIRECTION_LTR)
5690 xalign = priv->xalign;
5692 xalign = 1.0 - priv->xalign;
5694 text_width = PANGO_PIXELS(logical_rect.width);
5696 if (text_width > text_area_width)
5699 max_offset = text_width - text_area_width;
5703 min_offset = (text_width - text_area_width) * xalign;
5704 max_offset = min_offset;
5707 entry->scroll_offset = CLAMP (entry->scroll_offset, min_offset, max_offset);
5709 /* And make sure cursors are on screen. Note that the cursor is
5710 * actually drawn one pixel into the INNER_BORDER space on
5711 * the right, when the scroll is at the utmost right. This
5712 * looks better to to me than confining the cursor inside the
5713 * border entirely, though it means that the cursor gets one
5714 * pixel closer to the edge of the widget on the right than
5715 * on the left. This might need changing if one changed
5716 * INNER_BORDER from 2 to 1, as one would do on a
5717 * small-screen-real-estate display.
5719 * We always make sure that the strong cursor is on screen, and
5720 * put the weak cursor on screen if possible.
5723 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, &weak_x);
5725 strong_xoffset = strong_x - entry->scroll_offset;
5727 if (strong_xoffset < 0)
5729 entry->scroll_offset += strong_xoffset;
5732 else if (strong_xoffset > text_area_width)
5734 entry->scroll_offset += strong_xoffset - text_area_width;
5735 strong_xoffset = text_area_width;
5738 weak_xoffset = weak_x - entry->scroll_offset;
5740 if (weak_xoffset < 0 && strong_xoffset - weak_xoffset <= text_area_width)
5742 entry->scroll_offset += weak_xoffset;
5744 else if (weak_xoffset > text_area_width &&
5745 strong_xoffset - (weak_xoffset - text_area_width) >= 0)
5747 entry->scroll_offset += weak_xoffset - text_area_width;
5750 g_object_notify (G_OBJECT (entry), "scroll-offset");
5754 gtk_entry_move_adjustments (GtkEntry *entry)
5756 PangoContext *context;
5757 PangoFontMetrics *metrics;
5758 gint x, layout_x, border_x, border_y;
5760 GtkAdjustment *adjustment;
5762 adjustment = g_object_get_qdata (G_OBJECT (entry), quark_cursor_hadjustment);
5766 /* Cursor position, layout offset, border width, and widget allocation */
5767 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &x, NULL);
5768 get_layout_position (entry, &layout_x, NULL);
5769 _gtk_entry_get_borders (entry, &border_x, &border_y);
5770 x += entry->widget.allocation.x + layout_x + border_x;
5772 /* Approximate width of a char, so user can see what is ahead/behind */
5773 context = gtk_widget_get_pango_context (GTK_WIDGET (entry));
5774 metrics = pango_context_get_metrics (context,
5775 entry->widget.style->font_desc,
5776 pango_context_get_language (context));
5777 char_width = pango_font_metrics_get_approximate_char_width (metrics) / PANGO_SCALE;
5780 gtk_adjustment_clamp_page (adjustment,
5781 x - (char_width + 1), /* one char + one pixel before */
5782 x + (char_width + 2)); /* one char + cursor + one pixel after */
5786 gtk_entry_move_visually (GtkEntry *entry,
5791 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
5794 text = pango_layout_get_text (layout);
5796 index = g_utf8_offset_to_pointer (text, start) - text;
5800 int new_index, new_trailing;
5801 gboolean split_cursor;
5804 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
5805 "gtk-split-cursor", &split_cursor,
5812 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
5813 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
5815 strong = keymap_direction == entry->resolved_dir;
5820 pango_layout_move_cursor_visually (layout, strong, index, 0, 1, &new_index, &new_trailing);
5825 pango_layout_move_cursor_visually (layout, strong, index, 0, -1, &new_index, &new_trailing);
5831 else if (new_index != G_MAXINT)
5834 while (new_trailing--)
5835 index = g_utf8_next_char (text + index) - text;
5838 return g_utf8_pointer_to_offset (text, text + index);
5842 gtk_entry_move_logically (GtkEntry *entry,
5846 gint new_pos = start;
5848 /* Prevent any leak of information */
5849 if (!entry->visible)
5851 new_pos = CLAMP (start + count, 0, entry->text_length);
5853 else if (entry->text)
5855 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
5856 PangoLogAttr *log_attrs;
5859 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
5861 while (count > 0 && new_pos < entry->text_length)
5865 while (new_pos < entry->text_length && !log_attrs[new_pos].is_cursor_position);
5869 while (count < 0 && new_pos > 0)
5873 while (new_pos > 0 && !log_attrs[new_pos].is_cursor_position);
5885 gtk_entry_move_forward_word (GtkEntry *entry,
5887 gboolean allow_whitespace)
5889 gint new_pos = start;
5891 /* Prevent any leak of information */
5892 if (!entry->visible)
5894 new_pos = entry->text_length;
5896 else if (entry->text && (new_pos < entry->text_length))
5898 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
5899 PangoLogAttr *log_attrs;
5902 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
5904 /* Find the next word boundary */
5906 while (new_pos < n_attrs - 1 && !(log_attrs[new_pos].is_word_end ||
5907 (log_attrs[new_pos].is_word_start && allow_whitespace)))
5918 gtk_entry_move_backward_word (GtkEntry *entry,
5920 gboolean allow_whitespace)
5922 gint new_pos = start;
5924 /* Prevent any leak of information */
5925 if (!entry->visible)
5929 else if (entry->text && start > 0)
5931 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
5932 PangoLogAttr *log_attrs;
5935 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
5937 new_pos = start - 1;
5939 /* Find the previous word boundary */
5940 while (new_pos > 0 && !(log_attrs[new_pos].is_word_start ||
5941 (log_attrs[new_pos].is_word_end && allow_whitespace)))
5951 gtk_entry_delete_whitespace (GtkEntry *entry)
5953 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
5954 PangoLogAttr *log_attrs;
5958 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
5960 start = end = entry->current_pos;
5962 while (start > 0 && log_attrs[start-1].is_white)
5965 while (end < n_attrs && log_attrs[end].is_white)
5971 gtk_editable_delete_text (GTK_EDITABLE (entry), start, end);
5976 gtk_entry_select_word (GtkEntry *entry)
5978 gint start_pos = gtk_entry_move_backward_word (entry, entry->current_pos, TRUE);
5979 gint end_pos = gtk_entry_move_forward_word (entry, entry->current_pos, TRUE);
5981 gtk_editable_select_region (GTK_EDITABLE (entry), start_pos, end_pos);
5985 gtk_entry_select_line (GtkEntry *entry)
5987 gtk_editable_select_region (GTK_EDITABLE (entry), 0, -1);
5991 * Like gtk_editable_get_chars, but handle not-visible entries
5995 gtk_entry_get_public_chars (GtkEntry *entry,
6000 end = entry->text_length;
6003 return gtk_editable_get_chars (GTK_EDITABLE (entry), start, end);
6004 else if (!entry->invisible_char)
6005 return g_strdup ("");
6008 GString *str = g_string_new (NULL);
6009 append_char (str, entry->invisible_char, end - start);
6010 return g_string_free (str, FALSE);
6015 truncate_multiline (const gchar *text)
6020 text[length] && text[length] != '\n' && text[length] != '\r';
6027 paste_received (GtkClipboard *clipboard,
6031 GtkEntry *entry = GTK_ENTRY (data);
6032 GtkEditable *editable = GTK_EDITABLE (entry);
6033 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
6035 if (entry->button == 2)
6037 gint pos, start, end;
6038 pos = priv->insert_pos;
6039 gtk_editable_get_selection_bounds (editable, &start, &end);
6040 if (!((start <= pos && pos <= end) || (end <= pos && pos <= start)))
6041 gtk_editable_select_region (editable, pos, pos);
6046 gint pos, start, end;
6048 gboolean popup_completion;
6049 GtkEntryCompletion *completion;
6051 completion = gtk_entry_get_completion (entry);
6053 if (entry->truncate_multiline)
6054 length = truncate_multiline (text);
6056 /* only complete if the selection is at the end */
6057 popup_completion = (entry->text_length == MAX (entry->current_pos, entry->selection_bound));
6061 if (GTK_WIDGET_MAPPED (completion->priv->popup_window))
6062 _gtk_entry_completion_popdown (completion);
6064 if (!popup_completion && completion->priv->changed_id > 0)
6065 g_signal_handler_block (entry, completion->priv->changed_id);
6068 begin_change (entry);
6069 g_object_freeze_notify (G_OBJECT (entry));
6070 if (gtk_editable_get_selection_bounds (editable, &start, &end))
6071 gtk_editable_delete_text (editable, start, end);
6073 pos = entry->current_pos;
6074 gtk_editable_insert_text (editable, text, length, &pos);
6075 gtk_editable_set_position (editable, pos);
6076 g_object_thaw_notify (G_OBJECT (entry));
6080 !popup_completion && completion->priv->changed_id > 0)
6081 g_signal_handler_unblock (entry, completion->priv->changed_id);
6084 g_object_unref (entry);
6088 gtk_entry_paste (GtkEntry *entry,
6091 g_object_ref (entry);
6092 gtk_clipboard_request_text (gtk_widget_get_clipboard (GTK_WIDGET (entry), selection),
6093 paste_received, entry);
6097 primary_get_cb (GtkClipboard *clipboard,
6098 GtkSelectionData *selection_data,
6102 GtkEntry *entry = GTK_ENTRY (data);
6105 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end))
6107 gchar *str = gtk_entry_get_public_chars (entry, start, end);
6108 gtk_selection_data_set_text (selection_data, str, -1);
6114 primary_clear_cb (GtkClipboard *clipboard,
6117 GtkEntry *entry = GTK_ENTRY (data);
6119 gtk_editable_select_region (GTK_EDITABLE (entry), entry->current_pos, entry->current_pos);
6123 gtk_entry_update_primary_selection (GtkEntry *entry)
6125 GtkTargetList *list;
6126 GtkTargetEntry *targets;
6127 GtkClipboard *clipboard;
6131 if (!GTK_WIDGET_REALIZED (entry))
6134 list = gtk_target_list_new (NULL, 0);
6135 gtk_target_list_add_text_targets (list, 0);
6137 targets = gtk_target_table_new_from_list (list, &n_targets);
6139 clipboard = gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_PRIMARY);
6141 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end))
6143 if (!gtk_clipboard_set_with_owner (clipboard, targets, n_targets,
6144 primary_get_cb, primary_clear_cb, G_OBJECT (entry)))
6145 primary_clear_cb (clipboard, entry);
6149 if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (entry))
6150 gtk_clipboard_clear (clipboard);
6153 gtk_target_table_free (targets, n_targets);
6154 gtk_target_list_unref (list);
6158 gtk_entry_clear (GtkEntry *entry,
6159 GtkEntryIconPosition icon_pos)
6161 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
6162 EntryIconInfo *icon_info = priv->icons[icon_pos];
6164 if (!icon_info || icon_info->storage_type == GTK_IMAGE_EMPTY)
6167 g_object_freeze_notify (G_OBJECT (entry));
6169 /* Explicitly check, as the pointer may become invalidated
6170 * during destruction.
6172 if (GDK_IS_WINDOW (icon_info->window))
6173 gdk_window_hide (icon_info->window);
6175 if (icon_info->pixbuf)
6177 g_object_unref (icon_info->pixbuf);
6178 icon_info->pixbuf = NULL;
6181 switch (icon_info->storage_type)
6183 case GTK_IMAGE_PIXBUF:
6184 g_object_notify (G_OBJECT (entry),
6185 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-pixbuf" : "secondary-icon-pixbuf");
6188 case GTK_IMAGE_STOCK:
6189 g_free (icon_info->stock_id);
6190 icon_info->stock_id = NULL;
6191 g_object_notify (G_OBJECT (entry),
6192 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-stock" : "secondary-icon-stock");
6195 case GTK_IMAGE_ICON_NAME:
6196 g_free (icon_info->icon_name);
6197 icon_info->icon_name = NULL;
6198 g_object_notify (G_OBJECT (entry),
6199 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-name" : "secondary-icon-name");
6202 case GTK_IMAGE_GICON:
6203 if (icon_info->gicon)
6205 g_object_unref (icon_info->gicon);
6206 icon_info->gicon = NULL;
6208 g_object_notify (G_OBJECT (entry),
6209 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-gicon" : "secondary-icon-gicon");
6213 g_assert_not_reached ();
6217 icon_info->storage_type = GTK_IMAGE_EMPTY;
6218 g_object_notify (G_OBJECT (entry),
6219 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-storage-type" : "secondary-icon-storage-type");
6221 g_object_thaw_notify (G_OBJECT (entry));
6225 gtk_entry_ensure_pixbuf (GtkEntry *entry,
6226 GtkEntryIconPosition icon_pos)
6228 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
6229 EntryIconInfo *icon_info = priv->icons[icon_pos];
6231 GtkIconTheme *icon_theme;
6232 GtkSettings *settings;
6236 if (!icon_info || icon_info->pixbuf)
6239 switch (icon_info->storage_type)
6241 case GTK_IMAGE_EMPTY:
6242 case GTK_IMAGE_PIXBUF:
6244 case GTK_IMAGE_STOCK:
6245 icon_info->pixbuf = gtk_widget_render_icon (GTK_WIDGET (entry),
6246 icon_info->stock_id,
6251 case GTK_IMAGE_ICON_NAME:
6252 screen = gtk_widget_get_screen (GTK_WIDGET (entry));
6255 icon_theme = gtk_icon_theme_get_for_screen (screen);
6256 settings = gtk_settings_get_for_screen (screen);
6258 gtk_icon_size_lookup_for_settings (settings,
6262 icon_info->pixbuf = gtk_icon_theme_load_icon (icon_theme,
6263 icon_info->icon_name,
6264 MIN (width, height),
6267 if (icon_info->pixbuf == NULL)
6268 icon_info->pixbuf = gtk_widget_render_icon (GTK_WIDGET (entry),
6269 GTK_STOCK_MISSING_IMAGE,
6275 case GTK_IMAGE_GICON:
6276 screen = gtk_widget_get_screen (GTK_WIDGET (entry));
6279 icon_theme = gtk_icon_theme_get_for_screen (screen);
6280 settings = gtk_settings_get_for_screen (screen);
6282 gtk_icon_size_lookup_for_settings (settings,
6286 info = gtk_icon_theme_lookup_by_gicon (icon_theme,
6288 MIN (width, height),
6289 GTK_ICON_LOOKUP_USE_BUILTIN);
6292 icon_info->pixbuf = gtk_icon_info_load_icon (info, NULL);
6293 gtk_icon_info_free (info);
6296 if (icon_info->pixbuf == NULL)
6297 icon_info->pixbuf = gtk_widget_render_icon (GTK_WIDGET (entry),
6298 GTK_STOCK_MISSING_IMAGE,
6305 g_assert_not_reached ();
6309 if (GDK_IS_WINDOW (icon_info->window))
6310 gdk_window_show (icon_info->window);
6320 * Creates a new entry.
6322 * Return value: a new #GtkEntry.
6325 gtk_entry_new (void)
6327 return g_object_new (GTK_TYPE_ENTRY, NULL);
6331 * gtk_entry_new_with_max_length:
6332 * @max: the maximum length of the entry, or 0 for no maximum.
6333 * (other than the maximum length of entries.) The value passed in will
6334 * be clamped to the range 0-65536.
6336 * Creates a new #GtkEntry widget with the given maximum length.
6338 * Return value: a new #GtkEntry
6340 * Deprecated: Use gtk_entry_set_max_length() instead.
6343 gtk_entry_new_with_max_length (gint max)
6347 max = CLAMP (max, 0, MAX_SIZE);
6349 entry = g_object_new (GTK_TYPE_ENTRY, NULL);
6350 entry->text_max_length = max;
6352 return GTK_WIDGET (entry);
6356 * gtk_entry_set_text:
6357 * @entry: a #GtkEntry
6358 * @text: the new text
6360 * Sets the text in the widget to the given
6361 * value, replacing the current contents.
6364 gtk_entry_set_text (GtkEntry *entry,
6368 GtkEntryCompletion *completion;
6370 g_return_if_fail (GTK_IS_ENTRY (entry));
6371 g_return_if_fail (text != NULL);
6373 /* Actually setting the text will affect the cursor and selection;
6374 * if the contents don't actually change, this will look odd to the user.
6376 if (strcmp (entry->text, text) == 0)
6379 completion = gtk_entry_get_completion (entry);
6380 if (completion && completion->priv->changed_id > 0)
6381 g_signal_handler_block (entry, completion->priv->changed_id);
6383 begin_change (entry);
6384 g_object_freeze_notify (G_OBJECT (entry));
6385 gtk_editable_delete_text (GTK_EDITABLE (entry), 0, -1);
6388 gtk_editable_insert_text (GTK_EDITABLE (entry), text, strlen (text), &tmp_pos);
6389 g_object_thaw_notify (G_OBJECT (entry));
6392 if (completion && completion->priv->changed_id > 0)
6393 g_signal_handler_unblock (entry, completion->priv->changed_id);
6397 * gtk_entry_append_text:
6398 * @entry: a #GtkEntry
6399 * @text: the text to append
6401 * Appends the given text to the contents of the widget.
6403 * Deprecated: 2.0: Use gtk_editable_insert_text() instead.
6406 gtk_entry_append_text (GtkEntry *entry,
6411 g_return_if_fail (GTK_IS_ENTRY (entry));
6412 g_return_if_fail (text != NULL);
6414 tmp_pos = entry->text_length;
6415 gtk_editable_insert_text (GTK_EDITABLE (entry), text, -1, &tmp_pos);
6419 * gtk_entry_prepend_text:
6420 * @entry: a #GtkEntry
6421 * @text: the text to prepend
6423 * Prepends the given text to the contents of the widget.
6425 * Deprecated: 2.0: Use gtk_editable_insert_text() instead.
6428 gtk_entry_prepend_text (GtkEntry *entry,
6433 g_return_if_fail (GTK_IS_ENTRY (entry));
6434 g_return_if_fail (text != NULL);
6437 gtk_editable_insert_text (GTK_EDITABLE (entry), text, -1, &tmp_pos);
6441 * gtk_entry_set_position:
6442 * @entry: a #GtkEntry
6443 * @position: the position of the cursor. The cursor is displayed
6444 * before the character with the given (base 0) index in the widget.
6445 * The value must be less than or equal to the number of characters
6446 * in the widget. A value of -1 indicates that the position should
6447 * be set after the last character in the entry. Note that this
6448 * position is in characters, not in bytes.
6450 * Sets the cursor position in an entry to the given value.
6452 * Deprecated: 2.0: Use gtk_editable_set_position() instead.
6455 gtk_entry_set_position (GtkEntry *entry,
6458 g_return_if_fail (GTK_IS_ENTRY (entry));
6460 gtk_editable_set_position (GTK_EDITABLE (entry), position);
6464 * gtk_entry_set_visibility:
6465 * @entry: a #GtkEntry
6466 * @visible: %TRUE if the contents of the entry are displayed
6469 * Sets whether the contents of the entry are visible or not.
6470 * When visibility is set to %FALSE, characters are displayed
6471 * as the invisible char, and will also appear that way when
6472 * the text in the entry widget is copied elsewhere.
6474 * By default, GTK+ picks the best invisible character available
6475 * in the current font, but it can be changed with
6476 * gtk_entry_set_invisible_char().
6479 gtk_entry_set_visibility (GtkEntry *entry,
6482 g_return_if_fail (GTK_IS_ENTRY (entry));
6484 visible = visible != FALSE;
6486 if (entry->visible != visible)
6488 entry->visible = visible;
6490 g_object_notify (G_OBJECT (entry), "visibility");
6491 gtk_entry_recompute (entry);
6496 * gtk_entry_get_visibility:
6497 * @entry: a #GtkEntry
6499 * Retrieves whether the text in @entry is visible. See
6500 * gtk_entry_set_visibility().
6502 * Return value: %TRUE if the text is currently visible
6505 gtk_entry_get_visibility (GtkEntry *entry)
6507 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
6509 return entry->visible;
6513 * gtk_entry_set_invisible_char:
6514 * @entry: a #GtkEntry
6515 * @ch: a Unicode character
6517 * Sets the character to use in place of the actual text when
6518 * gtk_entry_set_visibility() has been called to set text visibility
6519 * to %FALSE. i.e. this is the character used in "password mode" to
6520 * show the user how many characters have been typed. By default, GTK+
6521 * picks the best invisible char available in the current font. If you
6522 * set the invisible char to 0, then the user will get no feedback
6523 * at all; there will be no text on the screen as they type.
6526 gtk_entry_set_invisible_char (GtkEntry *entry,
6529 GtkEntryPrivate *priv;
6531 g_return_if_fail (GTK_IS_ENTRY (entry));
6533 priv = GTK_ENTRY_GET_PRIVATE (entry);
6535 if (!priv->invisible_char_set)
6537 priv->invisible_char_set = TRUE;
6538 g_object_notify (G_OBJECT (entry), "invisible-char-set");
6541 if (ch == entry->invisible_char)
6544 entry->invisible_char = ch;
6545 g_object_notify (G_OBJECT (entry), "invisible-char");
6546 gtk_entry_recompute (entry);
6550 * gtk_entry_get_invisible_char:
6551 * @entry: a #GtkEntry
6553 * Retrieves the character displayed in place of the real characters
6554 * for entries with visibility set to false. See gtk_entry_set_invisible_char().
6556 * Return value: the current invisible char, or 0, if the entry does not
6557 * show invisible text at all.
6560 gtk_entry_get_invisible_char (GtkEntry *entry)
6562 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
6564 return entry->invisible_char;
6568 * gtk_entry_unset_invisible_char:
6569 * @entry: a #GtkEntry
6571 * Unsets the invisible char previously set with
6572 * gtk_entry_set_invisible_char(). So that the
6573 * default invisible char is used again.
6578 gtk_entry_unset_invisible_char (GtkEntry *entry)
6580 GtkEntryPrivate *priv;
6583 g_return_if_fail (GTK_IS_ENTRY (entry));
6585 priv = GTK_ENTRY_GET_PRIVATE (entry);
6587 if (!priv->invisible_char_set)
6590 priv->invisible_char_set = FALSE;
6591 ch = find_invisible_char (GTK_WIDGET (entry));
6593 if (entry->invisible_char != ch)
6595 entry->invisible_char = ch;
6596 g_object_notify (G_OBJECT (entry), "invisible-char");
6599 g_object_notify (G_OBJECT (entry), "invisible-char-set");
6600 gtk_entry_recompute (entry);
6604 * gtk_entry_set_editable:
6605 * @entry: a #GtkEntry
6606 * @editable: %TRUE if the user is allowed to edit the text
6609 * Determines if the user can edit the text in the editable
6612 * Deprecated: 2.0: Use gtk_editable_set_editable() instead.
6615 gtk_entry_set_editable (GtkEntry *entry,
6618 g_return_if_fail (GTK_IS_ENTRY (entry));
6620 gtk_editable_set_editable (GTK_EDITABLE (entry), editable);
6624 * gtk_entry_set_overwrite_mode:
6625 * @entry: a #GtkEntry
6626 * @overwrite: new value
6628 * Sets whether the text is overwritten when typing in the #GtkEntry.
6633 gtk_entry_set_overwrite_mode (GtkEntry *entry,
6636 g_return_if_fail (GTK_IS_ENTRY (entry));
6638 if (entry->overwrite_mode == overwrite)
6641 gtk_entry_toggle_overwrite (entry);
6643 g_object_notify (G_OBJECT (entry), "overwrite-mode");
6647 * gtk_entry_get_overwrite_mode:
6648 * @entry: a #GtkEntry
6650 * Gets the value set by gtk_entry_set_overwrite_mode().
6652 * Return value: whether the text is overwritten when typing.
6657 gtk_entry_get_overwrite_mode (GtkEntry *entry)
6659 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
6661 return entry->overwrite_mode;
6665 * gtk_entry_get_text:
6666 * @entry: a #GtkEntry
6668 * Retrieves the contents of the entry widget.
6669 * See also gtk_editable_get_chars().
6671 * Return value: a pointer to the contents of the widget as a
6672 * string. This string points to internally allocated
6673 * storage in the widget and must not be freed, modified or
6676 G_CONST_RETURN gchar*
6677 gtk_entry_get_text (GtkEntry *entry)
6679 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
6685 * gtk_entry_select_region:
6686 * @entry: a #GtkEntry
6687 * @start: the starting position
6688 * @end: the end position
6690 * Selects a region of text. The characters that are selected are
6691 * those characters at positions from @start_pos up to, but not
6692 * including @end_pos. If @end_pos is negative, then the the characters
6693 * selected will be those characters from @start_pos to the end of
6696 * Deprecated: 2.0: Use gtk_editable_select_region() instead.
6699 gtk_entry_select_region (GtkEntry *entry,
6703 gtk_editable_select_region (GTK_EDITABLE (entry), start, end);
6707 * gtk_entry_set_max_length:
6708 * @entry: a #GtkEntry
6709 * @max: the maximum length of the entry, or 0 for no maximum.
6710 * (other than the maximum length of entries.) The value passed in will
6711 * be clamped to the range 0-65536.
6713 * Sets the maximum allowed length of the contents of the widget. If
6714 * the current contents are longer than the given length, then they
6715 * will be truncated to fit.
6718 gtk_entry_set_max_length (GtkEntry *entry,
6721 g_return_if_fail (GTK_IS_ENTRY (entry));
6723 max = CLAMP (max, 0, MAX_SIZE);
6725 if (max > 0 && entry->text_length > max)
6726 gtk_editable_delete_text (GTK_EDITABLE (entry), max, -1);
6728 entry->text_max_length = max;
6729 g_object_notify (G_OBJECT (entry), "max-length");
6733 * gtk_entry_get_max_length:
6734 * @entry: a #GtkEntry
6736 * Retrieves the maximum allowed length of the text in
6737 * @entry. See gtk_entry_set_max_length().
6739 * Return value: the maximum allowed number of characters
6740 * in #GtkEntry, or 0 if there is no maximum.
6743 gtk_entry_get_max_length (GtkEntry *entry)
6745 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
6747 return entry->text_max_length;
6751 * gtk_entry_get_text_length:
6752 * @entry: a #GtkEntry
6754 * Retrieves the current length of the text in
6757 * Return value: the current number of characters
6758 * in #GtkEntry, or 0 if there are none.
6763 gtk_entry_get_text_length (GtkEntry *entry)
6765 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
6767 return entry->text_length;
6771 * gtk_entry_set_activates_default:
6772 * @entry: a #GtkEntry
6773 * @setting: %TRUE to activate window's default widget on Enter keypress
6775 * If @setting is %TRUE, pressing Enter in the @entry will activate the default
6776 * widget for the window containing the entry. This usually means that
6777 * the dialog box containing the entry will be closed, since the default
6778 * widget is usually one of the dialog buttons.
6780 * (For experts: if @setting is %TRUE, the entry calls
6781 * gtk_window_activate_default() on the window containing the entry, in
6782 * the default handler for the #GtkWidget::activate signal.)
6785 gtk_entry_set_activates_default (GtkEntry *entry,
6788 g_return_if_fail (GTK_IS_ENTRY (entry));
6789 setting = setting != FALSE;
6791 if (setting != entry->activates_default)
6793 entry->activates_default = setting;
6794 g_object_notify (G_OBJECT (entry), "activates-default");
6799 * gtk_entry_get_activates_default:
6800 * @entry: a #GtkEntry
6802 * Retrieves the value set by gtk_entry_set_activates_default().
6804 * Return value: %TRUE if the entry will activate the default widget
6807 gtk_entry_get_activates_default (GtkEntry *entry)
6809 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
6811 return entry->activates_default;
6815 * gtk_entry_set_width_chars:
6816 * @entry: a #GtkEntry
6817 * @n_chars: width in chars
6819 * Changes the size request of the entry to be about the right size
6820 * for @n_chars characters. Note that it changes the size
6821 * <emphasis>request</emphasis>, the size can still be affected by
6822 * how you pack the widget into containers. If @n_chars is -1, the
6823 * size reverts to the default entry size.
6826 gtk_entry_set_width_chars (GtkEntry *entry,
6829 g_return_if_fail (GTK_IS_ENTRY (entry));
6831 if (entry->width_chars != n_chars)
6833 entry->width_chars = n_chars;
6834 g_object_notify (G_OBJECT (entry), "width-chars");
6835 gtk_widget_queue_resize (GTK_WIDGET (entry));
6840 * gtk_entry_get_width_chars:
6841 * @entry: a #GtkEntry
6843 * Gets the value set by gtk_entry_set_width_chars().
6845 * Return value: number of chars to request space for, or negative if unset
6848 gtk_entry_get_width_chars (GtkEntry *entry)
6850 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
6852 return entry->width_chars;
6856 * gtk_entry_set_has_frame:
6857 * @entry: a #GtkEntry
6858 * @setting: new value
6860 * Sets whether the entry has a beveled frame around it.
6863 gtk_entry_set_has_frame (GtkEntry *entry,
6866 g_return_if_fail (GTK_IS_ENTRY (entry));
6868 setting = (setting != FALSE);
6870 if (entry->has_frame == setting)
6873 gtk_widget_queue_resize (GTK_WIDGET (entry));
6874 entry->has_frame = setting;
6875 g_object_notify (G_OBJECT (entry), "has-frame");
6879 * gtk_entry_get_has_frame:
6880 * @entry: a #GtkEntry
6882 * Gets the value set by gtk_entry_set_has_frame().
6884 * Return value: whether the entry has a beveled frame
6887 gtk_entry_get_has_frame (GtkEntry *entry)
6889 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
6891 return entry->has_frame;
6895 * gtk_entry_set_inner_border:
6896 * @entry: a #GtkEntry
6897 * @border: a #GtkBorder, or %NULL
6899 * Sets %entry's inner-border property to %border, or clears it if %NULL
6900 * is passed. The inner-border is the area around the entry's text, but
6903 * If set, this property overrides the inner-border style property.
6904 * Overriding the style-provided border is useful when you want to do
6905 * in-place editing of some text in a canvas or list widget, where
6906 * pixel-exact positioning of the entry is important.
6911 gtk_entry_set_inner_border (GtkEntry *entry,
6912 const GtkBorder *border)
6914 g_return_if_fail (GTK_IS_ENTRY (entry));
6916 gtk_widget_queue_resize (GTK_WIDGET (entry));
6919 g_object_set_qdata_full (G_OBJECT (entry), quark_inner_border,
6920 gtk_border_copy (border),
6921 (GDestroyNotify) gtk_border_free);
6923 g_object_set_qdata (G_OBJECT (entry), quark_inner_border, NULL);
6925 g_object_notify (G_OBJECT (entry), "inner-border");
6929 * gtk_entry_get_inner_border:
6930 * @entry: a #GtkEntry
6932 * This function returns the entry's #GtkEntry:inner-border property. See
6933 * gtk_entry_set_inner_border() for more information.
6935 * Return value: the entry's #GtkBorder, or %NULL if none was set.
6939 G_CONST_RETURN GtkBorder *
6940 gtk_entry_get_inner_border (GtkEntry *entry)
6942 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
6944 return g_object_get_qdata (G_OBJECT (entry), quark_inner_border);
6948 * gtk_entry_get_layout:
6949 * @entry: a #GtkEntry
6951 * Gets the #PangoLayout used to display the entry.
6952 * The layout is useful to e.g. convert text positions to
6953 * pixel positions, in combination with gtk_entry_get_layout_offsets().
6954 * The returned layout is owned by the entry and must not be
6955 * modified or freed by the caller.
6957 * Keep in mind that the layout text may contain a preedit string, so
6958 * gtk_entry_layout_index_to_text_index() and
6959 * gtk_entry_text_index_to_layout_index() are needed to convert byte
6960 * indices in the layout to byte indices in the entry contents.
6962 * Return value: the #PangoLayout for this entry
6965 gtk_entry_get_layout (GtkEntry *entry)
6967 PangoLayout *layout;
6969 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
6971 layout = gtk_entry_ensure_layout (entry, TRUE);
6978 * gtk_entry_layout_index_to_text_index:
6979 * @entry: a #GtkEntry
6980 * @layout_index: byte index into the entry layout text
6982 * Converts from a position in the entry contents (returned
6983 * by gtk_entry_get_text()) to a position in the
6984 * entry's #PangoLayout (returned by gtk_entry_get_layout(),
6985 * with text retrieved via pango_layout_get_text()).
6987 * Return value: byte index into the entry contents
6990 gtk_entry_layout_index_to_text_index (GtkEntry *entry,
6993 PangoLayout *layout;
6997 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
6999 layout = gtk_entry_ensure_layout (entry, TRUE);
7000 text = pango_layout_get_text (layout);
7001 cursor_index = g_utf8_offset_to_pointer (text, entry->current_pos) - text;
7003 if (layout_index >= cursor_index && entry->preedit_length)
7005 if (layout_index >= cursor_index + entry->preedit_length)
7006 layout_index -= entry->preedit_length;
7008 layout_index = cursor_index;
7011 return layout_index;
7015 * gtk_entry_text_index_to_layout_index:
7016 * @entry: a #GtkEntry
7017 * @text_index: byte index into the entry contents
7019 * Converts from a position in the entry's #PangoLayout (returned by
7020 * gtk_entry_get_layout()) to a position in the entry contents
7021 * (returned by gtk_entry_get_text()).
7023 * Return value: byte index into the entry layout text
7026 gtk_entry_text_index_to_layout_index (GtkEntry *entry,
7029 PangoLayout *layout;
7032 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7034 layout = gtk_entry_ensure_layout (entry, TRUE);
7035 text = pango_layout_get_text (layout);
7036 cursor_index = g_utf8_offset_to_pointer (text, entry->current_pos) - text;
7038 if (text_index > cursor_index)
7039 text_index += entry->preedit_length;
7045 * gtk_entry_get_layout_offsets:
7046 * @entry: a #GtkEntry
7047 * @x: location to store X offset of layout, or %NULL
7048 * @y: location to store Y offset of layout, or %NULL
7051 * Obtains the position of the #PangoLayout used to render text
7052 * in the entry, in widget coordinates. Useful if you want to line
7053 * up the text in an entry with some other text, e.g. when using the
7054 * entry to implement editable cells in a sheet widget.
7056 * Also useful to convert mouse events into coordinates inside the
7057 * #PangoLayout, e.g. to take some action if some part of the entry text
7060 * Note that as the user scrolls around in the entry the offsets will
7061 * change; you'll need to connect to the "notify::scroll-offset"
7062 * signal to track this. Remember when using the #PangoLayout
7063 * functions you need to convert to and from pixels using
7064 * PANGO_PIXELS() or #PANGO_SCALE.
7066 * Keep in mind that the layout text may contain a preedit string, so
7067 * gtk_entry_layout_index_to_text_index() and
7068 * gtk_entry_text_index_to_layout_index() are needed to convert byte
7069 * indices in the layout to byte indices in the entry contents.
7072 gtk_entry_get_layout_offsets (GtkEntry *entry,
7076 gint text_area_x, text_area_y;
7078 g_return_if_fail (GTK_IS_ENTRY (entry));
7080 /* this gets coords relative to text area */
7081 get_layout_position (entry, x, y);
7083 /* convert to widget coords */
7084 gtk_entry_get_text_area_size (entry, &text_area_x, &text_area_y, NULL, NULL);
7095 * gtk_entry_set_alignment:
7096 * @entry: a #GtkEntry
7097 * @xalign: The horizontal alignment, from 0 (left) to 1 (right).
7098 * Reversed for RTL layouts
7100 * Sets the alignment for the contents of the entry. This controls
7101 * the horizontal positioning of the contents when the displayed
7102 * text is shorter than the width of the entry.
7107 gtk_entry_set_alignment (GtkEntry *entry, gfloat xalign)
7109 GtkEntryPrivate *priv;
7111 g_return_if_fail (GTK_IS_ENTRY (entry));
7113 priv = GTK_ENTRY_GET_PRIVATE (entry);
7117 else if (xalign > 1.0)
7120 if (xalign != priv->xalign)
7122 priv->xalign = xalign;
7124 gtk_entry_recompute (entry);
7126 g_object_notify (G_OBJECT (entry), "xalign");
7131 * gtk_entry_get_alignment:
7132 * @entry: a #GtkEntry
7134 * Gets the value set by gtk_entry_set_alignment().
7136 * Return value: the alignment
7141 gtk_entry_get_alignment (GtkEntry *entry)
7143 GtkEntryPrivate *priv;
7145 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
7147 priv = GTK_ENTRY_GET_PRIVATE (entry);
7149 return priv->xalign;
7153 * gtk_entry_set_icon_from_pixbuf:
7154 * @entry: a #GtkEntry
7155 * @icon_pos: Icon position
7156 * @pixbuf: A #GdkPixbuf, or %NULL
7158 * Sets the icon shown in the specified position using a pixbuf.
7160 * If @pixbuf is %NULL, no icon will be shown in the specified position.
7165 gtk_entry_set_icon_from_pixbuf (GtkEntry *entry,
7166 GtkEntryIconPosition icon_pos,
7169 GtkEntryPrivate *priv;
7170 EntryIconInfo *icon_info;
7172 g_return_if_fail (GTK_IS_ENTRY (entry));
7173 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7175 priv = GTK_ENTRY_GET_PRIVATE (entry);
7177 if ((icon_info = priv->icons[icon_pos]) == NULL)
7178 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7180 g_object_freeze_notify (G_OBJECT (entry));
7183 g_object_ref (pixbuf);
7185 gtk_entry_clear (entry, icon_pos);
7189 icon_info->storage_type = GTK_IMAGE_PIXBUF;
7190 icon_info->pixbuf = pixbuf;
7192 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7194 g_object_notify (G_OBJECT (entry), "primary-icon-pixbuf");
7195 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7199 g_object_notify (G_OBJECT (entry), "secondary-icon-pixbuf");
7200 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7204 gtk_entry_ensure_pixbuf (entry, icon_pos);
7206 if (GTK_WIDGET_VISIBLE (entry))
7207 gtk_widget_queue_resize (GTK_WIDGET (entry));
7209 g_object_thaw_notify (G_OBJECT (entry));
7213 * gtk_entry_set_icon_from_stock:
7214 * @entry: A #GtkEntry
7215 * @icon_pos: Icon position
7216 * @stock_id: The name of the stock item, or %NULL
7218 * Sets the icon shown in the entry at the specified position from
7221 * If @stock_id is %NULL, no icon will be shown in the specified position.
7226 gtk_entry_set_icon_from_stock (GtkEntry *entry,
7227 GtkEntryIconPosition icon_pos,
7228 const gchar *stock_id)
7230 GtkEntryPrivate *priv;
7231 EntryIconInfo *icon_info;
7234 g_return_if_fail (GTK_IS_ENTRY (entry));
7235 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7237 priv = GTK_ENTRY_GET_PRIVATE (entry);
7239 if ((icon_info = priv->icons[icon_pos]) == NULL)
7240 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7242 g_object_freeze_notify (G_OBJECT (entry));
7244 gtk_widget_ensure_style (GTK_WIDGET (entry));
7246 /* need to dup before clearing */
7247 new_id = g_strdup (stock_id);
7249 gtk_entry_clear (entry, icon_pos);
7253 icon_info->storage_type = GTK_IMAGE_STOCK;
7254 icon_info->stock_id = new_id;
7256 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7258 g_object_notify (G_OBJECT (entry), "primary-icon-stock");
7259 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7263 g_object_notify (G_OBJECT (entry), "secondary-icon-stock");
7264 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7268 gtk_entry_ensure_pixbuf (entry, icon_pos);
7270 if (GTK_WIDGET_VISIBLE (entry))
7271 gtk_widget_queue_resize (GTK_WIDGET (entry));
7273 g_object_thaw_notify (G_OBJECT (entry));
7277 * gtk_entry_set_icon_from_icon_name:
7278 * @entry: A #GtkEntry
7279 * @icon_pos: The position at which to set the icon
7280 * @icon_name: An icon name, or %NULL
7282 * Sets the icon shown in the entry at the specified position
7283 * from the current icon theme.
7285 * If the icon name isn't known, a "broken image" icon will be displayed
7288 * If @icon_name is %NULL, no icon will be shown in the specified position.
7293 gtk_entry_set_icon_from_icon_name (GtkEntry *entry,
7294 GtkEntryIconPosition icon_pos,
7295 const gchar *icon_name)
7297 GtkEntryPrivate *priv;
7298 EntryIconInfo *icon_info;
7301 g_return_if_fail (GTK_IS_ENTRY (entry));
7302 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7304 priv = GTK_ENTRY_GET_PRIVATE (entry);
7306 if ((icon_info = priv->icons[icon_pos]) == NULL)
7307 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7309 g_object_freeze_notify (G_OBJECT (entry));
7311 gtk_widget_ensure_style (GTK_WIDGET (entry));
7313 /* need to dup before clearing */
7314 new_name = g_strdup (icon_name);
7316 gtk_entry_clear (entry, icon_pos);
7318 if (new_name != NULL)
7320 icon_info->storage_type = GTK_IMAGE_ICON_NAME;
7321 icon_info->icon_name = new_name;
7323 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7325 g_object_notify (G_OBJECT (entry), "primary-icon-name");
7326 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7330 g_object_notify (G_OBJECT (entry), "secondary-icon-name");
7331 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7335 gtk_entry_ensure_pixbuf (entry, icon_pos);
7337 if (GTK_WIDGET_VISIBLE (entry))
7338 gtk_widget_queue_resize (GTK_WIDGET (entry));
7340 g_object_thaw_notify (G_OBJECT (entry));
7344 * gtk_entry_set_icon_from_gicon:
7345 * @entry: A #GtkEntry
7346 * @icon_pos: The position at which to set the icon
7347 * @icon: The icon to set, or %NULL
7349 * Sets the icon shown in the entry at the specified position
7350 * from the current icon theme.
7351 * If the icon isn't known, a "broken image" icon will be displayed
7354 * If @icon is %NULL, no icon will be shown in the specified position.
7359 gtk_entry_set_icon_from_gicon (GtkEntry *entry,
7360 GtkEntryIconPosition icon_pos,
7363 GtkEntryPrivate *priv;
7364 EntryIconInfo *icon_info;
7366 g_return_if_fail (GTK_IS_ENTRY (entry));
7367 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7369 priv = GTK_ENTRY_GET_PRIVATE (entry);
7371 if ((icon_info = priv->icons[icon_pos]) == NULL)
7372 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7374 g_object_freeze_notify (G_OBJECT (entry));
7376 /* need to ref before clearing */
7378 g_object_ref (icon);
7380 gtk_entry_clear (entry, icon_pos);
7384 icon_info->storage_type = GTK_IMAGE_GICON;
7385 icon_info->gicon = icon;
7387 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7389 g_object_notify (G_OBJECT (entry), "primary-icon-gicon");
7390 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7394 g_object_notify (G_OBJECT (entry), "secondary-icon-gicon");
7395 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7399 gtk_entry_ensure_pixbuf (entry, icon_pos);
7401 if (GTK_WIDGET_VISIBLE (entry))
7402 gtk_widget_queue_resize (GTK_WIDGET (entry));
7404 g_object_thaw_notify (G_OBJECT (entry));
7408 * gtk_entry_set_icon_activatable:
7409 * @entry: A #GtkEntry
7410 * @icon_pos: Icon position
7411 * @activatable: %TRUE if the icon should be activatable
7413 * Sets whether the icon is activatable.
7418 gtk_entry_set_icon_activatable (GtkEntry *entry,
7419 GtkEntryIconPosition icon_pos,
7420 gboolean activatable)
7422 GtkEntryPrivate *priv;
7423 EntryIconInfo *icon_info;
7425 g_return_if_fail (GTK_IS_ENTRY (entry));
7426 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7428 priv = GTK_ENTRY_GET_PRIVATE (entry);
7430 if ((icon_info = priv->icons[icon_pos]) == NULL)
7431 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7433 activatable = activatable != FALSE;
7435 if (icon_info->nonactivatable != !activatable)
7437 icon_info->nonactivatable = !activatable;
7439 if (GTK_WIDGET_REALIZED (GTK_WIDGET (entry)))
7440 update_cursors (GTK_WIDGET (entry));
7442 g_object_notify (G_OBJECT (entry),
7443 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-activatable" : "secondary-icon-activatable");
7448 * gtk_entry_get_icon_activatable:
7449 * @entry: a #GtkEntry
7450 * @icon_pos: Icon position
7452 * Returns whether the icon is activatable.
7454 * Returns: %TRUE if the icon is activatable.
7459 gtk_entry_get_icon_activatable (GtkEntry *entry,
7460 GtkEntryIconPosition icon_pos)
7462 GtkEntryPrivate *priv;
7463 EntryIconInfo *icon_info;
7465 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7466 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), FALSE);
7468 priv = GTK_ENTRY_GET_PRIVATE (entry);
7469 icon_info = priv->icons[icon_pos];
7471 return (icon_info != NULL && !icon_info->nonactivatable);
7475 * gtk_entry_get_icon_pixbuf:
7476 * @entry: A #GtkEntry
7477 * @icon_pos: Icon position
7479 * Retrieves the image used for the icon.
7481 * Unlike the other methods of setting and getting icon data, this
7482 * method will work regardless of whether the icon was set using a
7483 * #GdkPixbuf, a #GIcon, a stock item, or an icon name.
7485 * Returns: A #GdkPixbuf, or %NULL if no icon is set for this position.
7490 gtk_entry_get_icon_pixbuf (GtkEntry *entry,
7491 GtkEntryIconPosition icon_pos)
7493 GtkEntryPrivate *priv;
7494 EntryIconInfo *icon_info;
7496 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7497 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7499 priv = GTK_ENTRY_GET_PRIVATE (entry);
7500 icon_info = priv->icons[icon_pos];
7505 gtk_entry_ensure_pixbuf (entry, icon_pos);
7507 return icon_info->pixbuf;
7511 * gtk_entry_get_icon_gicon:
7512 * @entry: A #GtkEntry
7513 * @icon_pos: Icon position
7515 * Retrieves the #GIcon used for the icon, or %NULL if there is
7516 * no icon or if the icon was set by some other method (e.g., by
7517 * stock, pixbuf, or icon name).
7519 * Returns: A #GIcon, or %NULL if no icon is set or if the icon
7525 gtk_entry_get_icon_gicon (GtkEntry *entry,
7526 GtkEntryIconPosition icon_pos)
7528 GtkEntryPrivate *priv;
7529 EntryIconInfo *icon_info;
7531 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7532 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7534 priv = GTK_ENTRY_GET_PRIVATE (entry);
7535 icon_info = priv->icons[icon_pos];
7540 return icon_info->storage_type == GTK_IMAGE_GICON ? icon_info->gicon : NULL;
7544 * gtk_entry_get_icon_stock:
7545 * @entry: A #GtkEntry
7546 * @icon_pos: Icon position
7548 * Retrieves the stock id used for the icon, or %NULL if there is
7549 * no icon or if the icon was set by some other method (e.g., by
7550 * pixbuf, icon name or gicon).
7552 * Returns: A stock id, or %NULL if no icon is set or if the icon
7553 * wasn't set from a stock id
7558 gtk_entry_get_icon_stock (GtkEntry *entry,
7559 GtkEntryIconPosition icon_pos)
7561 GtkEntryPrivate *priv;
7562 EntryIconInfo *icon_info;
7564 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7565 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7567 priv = GTK_ENTRY_GET_PRIVATE (entry);
7568 icon_info = priv->icons[icon_pos];
7573 return icon_info->storage_type == GTK_IMAGE_STOCK ? icon_info->stock_id : NULL;
7577 * gtk_entry_get_icon_name:
7578 * @entry: A #GtkEntry
7579 * @icon_pos: Icon position
7581 * Retrieves the icon name used for the icon, or %NULL if there is
7582 * no icon or if the icon was set by some other method (e.g., by
7583 * pixbuf, stock or gicon).
7585 * Returns: An icon name, or %NULL if no icon is set or if the icon
7586 * wasn't set from an icon name
7591 gtk_entry_get_icon_name (GtkEntry *entry,
7592 GtkEntryIconPosition icon_pos)
7594 GtkEntryPrivate *priv;
7595 EntryIconInfo *icon_info;
7597 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7598 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7600 priv = GTK_ENTRY_GET_PRIVATE (entry);
7601 icon_info = priv->icons[icon_pos];
7606 return icon_info->storage_type == GTK_IMAGE_ICON_NAME ? icon_info->icon_name : NULL;
7610 * gtk_entry_set_icon_sensitive:
7611 * @entry: A #GtkEntry
7612 * @icon_pos: Icon position
7613 * @sensitive: Specifies whether the icon should appear
7614 * sensitive or insensitive
7616 * Sets the sensitivity for the specified icon.
7621 gtk_entry_set_icon_sensitive (GtkEntry *entry,
7622 GtkEntryIconPosition icon_pos,
7625 GtkEntryPrivate *priv;
7626 EntryIconInfo *icon_info;
7628 g_return_if_fail (GTK_IS_ENTRY (entry));
7629 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7631 priv = GTK_ENTRY_GET_PRIVATE (entry);
7633 if ((icon_info = priv->icons[icon_pos]) == NULL)
7634 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7636 if (icon_info->insensitive != !sensitive)
7638 icon_info->insensitive = !sensitive;
7640 if (GTK_WIDGET_REALIZED (GTK_WIDGET (entry)))
7641 update_cursors (GTK_WIDGET (entry));
7643 g_object_notify (G_OBJECT (entry),
7644 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-sensitive" : "secondary-icon-sensitive");
7649 * gtk_entry_get_icon_sensitive:
7650 * @entry: a #GtkEntry
7651 * @icon_pos: Icon position
7653 * Returns whether the icon appears sensitive or insensitive.
7655 * Returns: %TRUE if the icon is sensitive.
7660 gtk_entry_get_icon_sensitive (GtkEntry *entry,
7661 GtkEntryIconPosition icon_pos)
7663 GtkEntryPrivate *priv;
7664 EntryIconInfo *icon_info;
7666 g_return_val_if_fail (GTK_IS_ENTRY (entry), TRUE);
7667 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), TRUE);
7669 priv = GTK_ENTRY_GET_PRIVATE (entry);
7670 icon_info = priv->icons[icon_pos];
7672 return (!icon_info || !icon_info->insensitive);
7677 * gtk_entry_get_icon_storage_type:
7678 * @entry: a #GtkEntry
7679 * @icon_pos: Icon position
7681 * Gets the type of representation being used by the icon
7682 * to store image data. If the icon has no image data,
7683 * the return value will be %GTK_IMAGE_EMPTY.
7685 * Return value: image representation being used
7690 gtk_entry_get_icon_storage_type (GtkEntry *entry,
7691 GtkEntryIconPosition icon_pos)
7693 GtkEntryPrivate *priv;
7694 EntryIconInfo *icon_info;
7696 g_return_val_if_fail (GTK_IS_ENTRY (entry), GTK_IMAGE_EMPTY);
7697 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), GTK_IMAGE_EMPTY);
7699 priv = GTK_ENTRY_GET_PRIVATE (entry);
7700 icon_info = priv->icons[icon_pos];
7703 return GTK_IMAGE_EMPTY;
7705 return icon_info->storage_type;
7709 * gtk_entry_get_icon_at_pos:
7710 * @entry: a #GtkEntry
7711 * @x: the x coordinate of the position to find
7712 * @y: the y coordinate of the position to find
7714 * Finds the icon at the given position and return its index.
7715 * If @x, @y doesn't lie inside an icon, -1 is returned.
7716 * This function is intended for use in a #GtkWidget::query-tooltip
7719 * Returns: the index of the icon at the given position, or -1
7724 gtk_entry_get_icon_at_pos (GtkEntry *entry,
7728 GtkAllocation primary;
7729 GtkAllocation secondary;
7731 g_return_val_if_fail (GTK_IS_ENTRY (entry), -1);
7733 get_icon_allocations (entry, &primary, &secondary);
7735 if (primary.x <= x && x < primary.x + primary.width &&
7736 primary.y <= y && y < primary.y + primary.height)
7737 return GTK_ENTRY_ICON_PRIMARY;
7739 if (secondary.x <= x && x < secondary.x + secondary.width &&
7740 secondary.y <= y && y < secondary.y + secondary.height)
7741 return GTK_ENTRY_ICON_SECONDARY;
7747 * gtk_entry_set_icon_drag_source:
7748 * @entry: a #GtkIconEntry
7749 * @icon_pos: icon position
7750 * @target_list: the targets (data formats) in which the data can be provided
7751 * @actions: a bitmask of the allowed drag actions
7753 * Sets up the icon at the given position so that GTK+ will start a drag
7754 * operation when the user clicks and drags the icon.
7756 * To handle the drag operation, you need to connect to the usual
7757 * #GtkWidget::drag-data-get (or possibly #GtkWidget::drag-data-delete)
7758 * signal, and use gtk_entry_get_current_icon_drag_source() in
7759 * your signal handler to find out if the drag was started from
7762 * By default, GTK+ uses the icon as the drag icon. You can use the
7763 * #GtkWidget::drag-begin signal to set a different icon. Note that you
7764 * have to use g_signal_connect_after() to ensure that your signal handler
7765 * gets executed after the default handler.
7768 gtk_entry_set_icon_drag_source (GtkEntry *entry,
7769 GtkEntryIconPosition icon_pos,
7770 GtkTargetList *target_list,
7771 GdkDragAction actions)
7773 GtkEntryPrivate *priv;
7774 EntryIconInfo *icon_info;
7776 g_return_if_fail (GTK_IS_ENTRY (entry));
7777 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7779 priv = GTK_ENTRY_GET_PRIVATE (entry);
7781 if ((icon_info = priv->icons[icon_pos]) == NULL)
7782 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7784 if (icon_info->target_list)
7785 gtk_target_list_unref (icon_info->target_list);
7786 icon_info->target_list = target_list;
7787 if (icon_info->target_list)
7788 gtk_target_list_ref (icon_info->target_list);
7790 icon_info->actions = actions;
7794 * gtk_entry_get_current_icon_drag_source:
7795 * @entry: a #GtkIconEntry
7797 * Returns the index of the icon which is the source of the current
7798 * DND operation, or -1.
7800 * This function is meant to be used in a #GtkWidget::drag-data-get
7803 * Returns: index of the icon which is the source of the current
7804 * DND operation, or -1.
7807 gtk_entry_get_current_icon_drag_source (GtkEntry *entry)
7809 GtkEntryPrivate *priv;
7810 EntryIconInfo *icon_info = NULL;
7813 g_return_val_if_fail (GTK_IS_ENTRY (entry), -1);
7815 priv = GTK_ENTRY_GET_PRIVATE (entry);
7817 for (i = 0; i < MAX_ICONS; i++)
7819 if ((icon_info = priv->icons[i]))
7821 if (icon_info->in_drag)
7830 ensure_has_tooltip (GtkEntry *entry)
7832 GtkEntryPrivate *priv;
7833 EntryIconInfo *icon_info;
7835 gboolean has_tooltip = FALSE;
7837 priv = GTK_ENTRY_GET_PRIVATE (entry);
7839 for (i = 0; i < MAX_ICONS; i++)
7841 if ((icon_info = priv->icons[i]) != NULL)
7843 if (icon_info->tooltip != NULL)
7851 gtk_widget_set_has_tooltip (GTK_WIDGET (entry), has_tooltip);
7855 * gtk_entry_get_icon_tooltip_text:
7856 * @entry: a #GtkEntry
7857 * @icon_pos: the icon position
7859 * Gets the contents of the tooltip on the icon at the specified
7860 * position in @entry.
7862 * Returns: the tooltip text, or %NULL. Free the returned string
7863 * with g_free() when done.
7868 gtk_entry_get_icon_tooltip_text (GtkEntry *entry,
7869 GtkEntryIconPosition icon_pos)
7871 GtkEntryPrivate *priv;
7872 EntryIconInfo *icon_info;
7875 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7876 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7878 priv = GTK_ENTRY_GET_PRIVATE (entry);
7879 icon_info = priv->icons[icon_pos];
7884 if (icon_info->tooltip &&
7885 !pango_parse_markup (icon_info->tooltip, -1, 0, NULL, &text, NULL, NULL))
7886 g_assert (NULL == text); /* text should still be NULL in case of markup errors */
7892 * gtk_entry_set_icon_tooltip_text:
7893 * @entry: a #GtkEntry
7894 * @icon_pos: the icon position
7895 * @tooltip: the contents of the tooltip for the icon, or %NULL
7897 * Sets @tooltip as the contents of the tooltip for the icon
7898 * at the specified position.
7900 * Use %NULL for @tooltip to remove an existing tooltip.
7902 * See also gtk_widget_set_tooltip_text() and
7903 * gtk_entry_set_icon_tooltip_markup().
7908 gtk_entry_set_icon_tooltip_text (GtkEntry *entry,
7909 GtkEntryIconPosition icon_pos,
7910 const gchar *tooltip)
7912 GtkEntryPrivate *priv;
7913 EntryIconInfo *icon_info;
7915 g_return_if_fail (GTK_IS_ENTRY (entry));
7916 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7918 priv = GTK_ENTRY_GET_PRIVATE (entry);
7920 if (!(icon_info = priv->icons[icon_pos]))
7921 icon_info = priv->icons[icon_pos];
7923 if (icon_info->tooltip)
7924 g_free (icon_info->tooltip);
7926 /* Treat an empty string as a NULL string,
7927 * because an empty string would be useless for a tooltip:
7929 if (tooltip && tooltip[0] == '\0')
7932 icon_info->tooltip = tooltip ? g_markup_escape_text (tooltip, -1) : NULL;
7934 ensure_has_tooltip (entry);
7938 * gtk_entry_get_icon_tooltip_markup:
7939 * @entry: a #GtkEntry
7940 * @icon_pos: the icon position
7942 * Gets the contents of the tooltip on the icon at the specified
7943 * position in @entry.
7945 * Returns: the tooltip text, or %NULL. Free the returned string
7946 * with g_free() when done.
7951 gtk_entry_get_icon_tooltip_markup (GtkEntry *entry,
7952 GtkEntryIconPosition icon_pos)
7954 GtkEntryPrivate *priv;
7955 EntryIconInfo *icon_info;
7958 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7959 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7961 priv = GTK_ENTRY_GET_PRIVATE (entry);
7962 icon_info = priv->icons[icon_pos];
7967 return g_strdup (icon_info->tooltip);
7971 * gtk_entry_set_icon_tooltip_markup:
7972 * @entry: a #GtkEntry
7973 * @icon_pos: the icon position
7974 * @tooltip: the contents of the tooltip for the icon, or %NULL
7976 * Sets @tooltip as the contents of the tooltip for the icon at
7977 * the specified position. @tooltip is assumed to be marked up with
7978 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
7980 * Use %NULL for @tooltip to remove an existing tooltip.
7982 * See also gtk_widget_set_tooltip_markup() and
7983 * gtk_enty_set_icon_tooltip_text().
7988 gtk_entry_set_icon_tooltip_markup (GtkEntry *entry,
7989 GtkEntryIconPosition icon_pos,
7990 const gchar *tooltip)
7992 GtkEntryPrivate *priv;
7993 EntryIconInfo *icon_info;
7995 g_return_if_fail (GTK_IS_ENTRY (entry));
7996 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7998 priv = GTK_ENTRY_GET_PRIVATE (entry);
8000 if (!(icon_info = priv->icons[icon_pos]))
8001 icon_info = priv->icons[icon_pos];
8003 if (icon_info->tooltip)
8004 g_free (icon_info->tooltip);
8006 /* Treat an empty string as a NULL string,
8007 * because an empty string would be useless for a tooltip:
8009 if (tooltip && tooltip[0] == '\0')
8012 icon_info->tooltip = g_strdup (tooltip);
8014 ensure_has_tooltip (entry);
8018 gtk_entry_query_tooltip (GtkWidget *widget,
8021 gboolean keyboard_tip,
8022 GtkTooltip *tooltip)
8025 GtkEntryPrivate *priv;
8026 EntryIconInfo *icon_info;
8029 entry = GTK_ENTRY (widget);
8030 priv = GTK_ENTRY_GET_PRIVATE (entry);
8034 icon_pos = gtk_entry_get_icon_at_pos (entry, x, y);
8037 if ((icon_info = priv->icons[icon_pos]) != NULL)
8039 if (icon_info->tooltip)
8041 gtk_tooltip_set_markup (tooltip, icon_info->tooltip);
8050 return GTK_WIDGET_CLASS (gtk_entry_parent_class)->query_tooltip (widget,
8057 /* Quick hack of a popup menu
8060 activate_cb (GtkWidget *menuitem,
8063 const gchar *signal = g_object_get_data (G_OBJECT (menuitem), "gtk-signal");
8064 g_signal_emit_by_name (entry, signal);
8069 gtk_entry_mnemonic_activate (GtkWidget *widget,
8070 gboolean group_cycling)
8072 gtk_widget_grab_focus (widget);
8077 append_action_signal (GtkEntry *entry,
8079 const gchar *stock_id,
8080 const gchar *signal,
8083 GtkWidget *menuitem = gtk_image_menu_item_new_from_stock (stock_id, NULL);
8085 g_object_set_data (G_OBJECT (menuitem), I_("gtk-signal"), (char *)signal);
8086 g_signal_connect (menuitem, "activate",
8087 G_CALLBACK (activate_cb), entry);
8089 gtk_widget_set_sensitive (menuitem, sensitive);
8091 gtk_widget_show (menuitem);
8092 gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
8096 popup_menu_detach (GtkWidget *attach_widget,
8099 GTK_ENTRY (attach_widget)->popup_menu = NULL;
8103 popup_position_func (GtkMenu *menu,
8109 GtkEntry *entry = GTK_ENTRY (user_data);
8110 GtkWidget *widget = GTK_WIDGET (entry);
8112 GtkRequisition menu_req;
8113 GdkRectangle monitor;
8114 GtkBorder inner_border;
8115 gint monitor_num, strong_x, height;
8117 g_return_if_fail (GTK_WIDGET_REALIZED (entry));
8119 gdk_window_get_origin (entry->text_area, x, y);
8121 screen = gtk_widget_get_screen (widget);
8122 monitor_num = gdk_screen_get_monitor_at_window (screen, entry->text_area);
8123 if (monitor_num < 0)
8125 gtk_menu_set_monitor (menu, monitor_num);
8127 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
8128 gtk_widget_size_request (entry->popup_menu, &menu_req);
8129 gdk_drawable_get_size (entry->text_area, NULL, &height);
8130 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
8131 _gtk_entry_effective_inner_border (entry, &inner_border);
8133 *x += inner_border.left + strong_x - entry->scroll_offset;
8134 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
8135 *x -= menu_req.width;
8137 if ((*y + height + menu_req.height) <= monitor.y + monitor.height)
8139 else if ((*y - menu_req.height) >= monitor.y)
8140 *y -= menu_req.height;
8141 else if (monitor.y + monitor.height - (*y + height) > *y)
8144 *y -= menu_req.height;
8150 unichar_chosen_func (const char *text,
8153 GtkEntry *entry = GTK_ENTRY (data);
8155 if (entry->editable)
8156 gtk_entry_enter_text (entry, text);
8167 popup_targets_received (GtkClipboard *clipboard,
8168 GtkSelectionData *data,
8171 PopupInfo *info = user_data;
8172 GtkEntry *entry = info->entry;
8174 if (GTK_WIDGET_REALIZED (entry))
8176 gboolean clipboard_contains_text;
8177 GtkWidget *menuitem;
8179 gboolean show_input_method_menu;
8180 gboolean show_unicode_menu;
8182 clipboard_contains_text = gtk_selection_data_targets_include_text (data);
8183 if (entry->popup_menu)
8184 gtk_widget_destroy (entry->popup_menu);
8186 entry->popup_menu = gtk_menu_new ();
8188 gtk_menu_attach_to_widget (GTK_MENU (entry->popup_menu),
8192 append_action_signal (entry, entry->popup_menu, GTK_STOCK_CUT, "cut-clipboard",
8193 entry->editable && entry->visible && entry->current_pos != entry->selection_bound);
8194 append_action_signal (entry, entry->popup_menu, GTK_STOCK_COPY, "copy-clipboard",
8195 entry->visible && entry->current_pos != entry->selection_bound);
8196 append_action_signal (entry, entry->popup_menu, GTK_STOCK_PASTE, "paste-clipboard",
8197 entry->editable && clipboard_contains_text);
8199 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_DELETE, NULL);
8200 gtk_widget_set_sensitive (menuitem, entry->editable && entry->current_pos != entry->selection_bound);
8201 g_signal_connect_swapped (menuitem, "activate",
8202 G_CALLBACK (gtk_entry_delete_cb), entry);
8203 gtk_widget_show (menuitem);
8204 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8206 menuitem = gtk_separator_menu_item_new ();
8207 gtk_widget_show (menuitem);
8208 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8210 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_SELECT_ALL, NULL);
8211 g_signal_connect_swapped (menuitem, "activate",
8212 G_CALLBACK (gtk_entry_select_all), entry);
8213 gtk_widget_show (menuitem);
8214 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8216 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
8217 "gtk-show-input-method-menu", &show_input_method_menu,
8218 "gtk-show-unicode-menu", &show_unicode_menu,
8221 if (show_input_method_menu || show_unicode_menu)
8223 menuitem = gtk_separator_menu_item_new ();
8224 gtk_widget_show (menuitem);
8225 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8228 if (show_input_method_menu)
8230 menuitem = gtk_menu_item_new_with_mnemonic (_("Input _Methods"));
8231 gtk_widget_set_sensitive (menuitem, entry->editable);
8232 gtk_widget_show (menuitem);
8233 submenu = gtk_menu_new ();
8234 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
8236 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8238 gtk_im_multicontext_append_menuitems (GTK_IM_MULTICONTEXT (entry->im_context),
8239 GTK_MENU_SHELL (submenu));
8242 if (show_unicode_menu)
8244 menuitem = gtk_menu_item_new_with_mnemonic (_("_Insert Unicode Control Character"));
8245 gtk_widget_set_sensitive (menuitem, entry->editable);
8246 gtk_widget_show (menuitem);
8248 submenu = gtk_menu_new ();
8249 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
8250 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8252 _gtk_text_util_append_special_char_menuitems (GTK_MENU_SHELL (submenu),
8253 unichar_chosen_func,
8257 g_signal_emit (entry,
8258 signals[POPULATE_POPUP],
8264 gtk_menu_popup (GTK_MENU (entry->popup_menu), NULL, NULL,
8266 info->button, info->time);
8269 gtk_menu_popup (GTK_MENU (entry->popup_menu), NULL, NULL,
8270 popup_position_func, entry,
8271 info->button, info->time);
8272 gtk_menu_shell_select_first (GTK_MENU_SHELL (entry->popup_menu), FALSE);
8276 g_object_unref (entry);
8277 g_slice_free (PopupInfo, info);
8281 gtk_entry_do_popup (GtkEntry *entry,
8282 GdkEventButton *event)
8284 PopupInfo *info = g_slice_new (PopupInfo);
8286 /* In order to know what entries we should make sensitive, we
8287 * ask for the current targets of the clipboard, and when
8288 * we get them, then we actually pop up the menu.
8290 info->entry = g_object_ref (entry);
8294 info->button = event->button;
8295 info->time = event->time;
8300 info->time = gtk_get_current_event_time ();
8303 gtk_clipboard_request_contents (gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_CLIPBOARD),
8304 gdk_atom_intern_static_string ("TARGETS"),
8305 popup_targets_received,
8310 gtk_entry_popup_menu (GtkWidget *widget)
8312 gtk_entry_do_popup (GTK_ENTRY (widget), NULL);
8317 gtk_entry_drag_begin (GtkWidget *widget,
8318 GdkDragContext *context)
8320 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
8323 for (i = 0; i < MAX_ICONS; i++)
8325 EntryIconInfo *icon_info = priv->icons[i];
8327 if (icon_info != NULL)
8329 if (icon_info->in_drag)
8331 switch (icon_info->storage_type)
8333 case GTK_IMAGE_STOCK:
8334 gtk_drag_set_icon_stock (context, icon_info->stock_id, -2, -2);
8337 case GTK_IMAGE_ICON_NAME:
8338 gtk_drag_set_icon_name (context, icon_info->icon_name, -2, -2);
8341 /* FIXME: No GIcon support for dnd icons */
8342 case GTK_IMAGE_GICON:
8343 case GTK_IMAGE_PIXBUF:
8344 gtk_drag_set_icon_pixbuf (context, icon_info->pixbuf, -2, -2);
8347 g_assert_not_reached ();
8355 gtk_entry_drag_end (GtkWidget *widget,
8356 GdkDragContext *context)
8358 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
8361 for (i = 0; i < MAX_ICONS; i++)
8363 EntryIconInfo *icon_info = priv->icons[i];
8365 if (icon_info != NULL)
8366 icon_info->in_drag = 0;
8371 gtk_entry_drag_leave (GtkWidget *widget,
8372 GdkDragContext *context,
8375 GtkEntry *entry = GTK_ENTRY (widget);
8377 entry->dnd_position = -1;
8378 gtk_widget_queue_draw (widget);
8382 gtk_entry_drag_drop (GtkWidget *widget,
8383 GdkDragContext *context,
8388 GtkEntry *entry = GTK_ENTRY (widget);
8389 GdkAtom target = GDK_NONE;
8391 if (entry->editable)
8392 target = gtk_drag_dest_find_target (widget, context, NULL);
8394 if (target != GDK_NONE)
8395 gtk_drag_get_data (widget, context, target, time);
8397 gtk_drag_finish (context, FALSE, FALSE, time);
8403 gtk_entry_drag_motion (GtkWidget *widget,
8404 GdkDragContext *context,
8409 GtkEntry *entry = GTK_ENTRY (widget);
8410 GtkWidget *source_widget;
8411 GdkDragAction suggested_action;
8412 gint new_position, old_position;
8415 x -= widget->style->xthickness;
8416 y -= widget->style->ythickness;
8418 old_position = entry->dnd_position;
8419 new_position = gtk_entry_find_position (entry, x + entry->scroll_offset);
8421 if (entry->editable &&
8422 gtk_drag_dest_find_target (widget, context, NULL) != GDK_NONE)
8424 source_widget = gtk_drag_get_source_widget (context);
8425 suggested_action = context->suggested_action;
8427 if (!gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &sel1, &sel2) ||
8428 new_position < sel1 || new_position > sel2)
8430 if (source_widget == widget)
8432 /* Default to MOVE, unless the user has
8433 * pressed ctrl or alt to affect available actions
8435 if ((context->actions & GDK_ACTION_MOVE) != 0)
8436 suggested_action = GDK_ACTION_MOVE;
8439 entry->dnd_position = new_position;
8443 if (source_widget == widget)
8444 suggested_action = 0; /* Can't drop in selection where drag started */
8446 entry->dnd_position = -1;
8451 /* Entry not editable, or no text */
8452 suggested_action = 0;
8453 entry->dnd_position = -1;
8456 gdk_drag_status (context, suggested_action, time);
8458 if (entry->dnd_position != old_position)
8459 gtk_widget_queue_draw (widget);
8465 gtk_entry_drag_data_received (GtkWidget *widget,
8466 GdkDragContext *context,
8469 GtkSelectionData *selection_data,
8473 GtkEntry *entry = GTK_ENTRY (widget);
8474 GtkEditable *editable = GTK_EDITABLE (widget);
8477 str = (gchar *) gtk_selection_data_get_text (selection_data);
8479 x -= widget->style->xthickness;
8480 y -= widget->style->ythickness;
8482 if (str && entry->editable)
8488 if (entry->truncate_multiline)
8489 length = truncate_multiline (str);
8491 new_position = gtk_entry_find_position (entry, x + entry->scroll_offset);
8493 if (!gtk_editable_get_selection_bounds (editable, &sel1, &sel2) ||
8494 new_position < sel1 || new_position > sel2)
8496 gtk_editable_insert_text (editable, str, length, &new_position);
8500 /* Replacing selection */
8501 begin_change (entry);
8502 g_object_freeze_notify (G_OBJECT (entry));
8503 gtk_editable_delete_text (editable, sel1, sel2);
8504 gtk_editable_insert_text (editable, str, length, &sel1);
8505 g_object_thaw_notify (G_OBJECT (entry));
8509 gtk_drag_finish (context, TRUE, context->action == GDK_ACTION_MOVE, time);
8513 /* Drag and drop didn't happen! */
8514 gtk_drag_finish (context, FALSE, FALSE, time);
8521 gtk_entry_drag_data_get (GtkWidget *widget,
8522 GdkDragContext *context,
8523 GtkSelectionData *selection_data,
8527 gint sel_start, sel_end;
8530 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
8531 GtkEditable *editable = GTK_EDITABLE (widget);
8533 /* If there is an icon drag going on, exit early. */
8534 for (i = 0; i < MAX_ICONS; i++)
8536 EntryIconInfo *icon_info = priv->icons[i];
8538 if (icon_info != NULL)
8540 if (icon_info->in_drag)
8545 if (gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end))
8547 gchar *str = gtk_entry_get_public_chars (GTK_ENTRY (widget), sel_start, sel_end);
8549 gtk_selection_data_set_text (selection_data, str, -1);
8557 gtk_entry_drag_data_delete (GtkWidget *widget,
8558 GdkDragContext *context)
8560 gint sel_start, sel_end;
8563 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
8564 GtkEditable *editable = GTK_EDITABLE (widget);
8566 /* If there is an icon drag going on, exit early. */
8567 for (i = 0; i < MAX_ICONS; i++)
8569 EntryIconInfo *icon_info = priv->icons[i];
8571 if (icon_info != NULL)
8573 if (icon_info->in_drag)
8578 if (GTK_ENTRY (widget)->editable &&
8579 gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end))
8580 gtk_editable_delete_text (editable, sel_start, sel_end);
8583 /* We display the cursor when
8585 * - the selection is empty, AND
8586 * - the widget has focus
8589 #define CURSOR_ON_MULTIPLIER 2
8590 #define CURSOR_OFF_MULTIPLIER 1
8591 #define CURSOR_PEND_MULTIPLIER 3
8592 #define CURSOR_DIVIDER 3
8595 cursor_blinks (GtkEntry *entry)
8597 if (GTK_WIDGET_HAS_FOCUS (entry) &&
8599 entry->selection_bound == entry->current_pos)
8601 GtkSettings *settings;
8604 settings = gtk_widget_get_settings (GTK_WIDGET (entry));
8605 g_object_get (settings, "gtk-cursor-blink", &blink, NULL);
8614 get_cursor_time (GtkEntry *entry)
8616 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (entry));
8619 g_object_get (settings, "gtk-cursor-blink-time", &time, NULL);
8625 get_cursor_blink_timeout (GtkEntry *entry)
8627 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (entry));
8630 g_object_get (settings, "gtk-cursor-blink-timeout", &timeout, NULL);
8636 show_cursor (GtkEntry *entry)
8638 if (!entry->cursor_visible)
8640 entry->cursor_visible = TRUE;
8642 if (GTK_WIDGET_HAS_FOCUS (entry) && entry->selection_bound == entry->current_pos)
8643 gtk_widget_queue_draw (GTK_WIDGET (entry));
8648 hide_cursor (GtkEntry *entry)
8650 if (entry->cursor_visible)
8652 entry->cursor_visible = FALSE;
8654 if (GTK_WIDGET_HAS_FOCUS (entry) && entry->selection_bound == entry->current_pos)
8655 gtk_widget_queue_draw (GTK_WIDGET (entry));
8663 blink_cb (gpointer data)
8666 GtkEntryPrivate *priv;
8669 entry = GTK_ENTRY (data);
8670 priv = GTK_ENTRY_GET_PRIVATE (entry);
8672 if (!GTK_WIDGET_HAS_FOCUS (entry))
8674 g_warning ("GtkEntry - did not receive focus-out-event. If you\n"
8675 "connect a handler to this signal, it must return\n"
8676 "FALSE so the entry gets the event as well");
8678 gtk_entry_check_cursor_blink (entry);
8683 g_assert (entry->selection_bound == entry->current_pos);
8685 blink_timeout = get_cursor_blink_timeout (entry);
8686 if (priv->blink_time > 1000 * blink_timeout &&
8687 blink_timeout < G_MAXINT/1000)
8689 /* we've blinked enough without the user doing anything, stop blinking */
8690 show_cursor (entry);
8691 entry->blink_timeout = 0;
8693 else if (entry->cursor_visible)
8695 hide_cursor (entry);
8696 entry->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_OFF_MULTIPLIER / CURSOR_DIVIDER,
8702 show_cursor (entry);
8703 priv->blink_time += get_cursor_time (entry);
8704 entry->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
8709 /* Remove ourselves */
8714 gtk_entry_check_cursor_blink (GtkEntry *entry)
8716 GtkEntryPrivate *priv;
8718 priv = GTK_ENTRY_GET_PRIVATE (entry);
8720 if (cursor_blinks (entry))
8722 if (!entry->blink_timeout)
8724 show_cursor (entry);
8725 entry->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
8732 if (entry->blink_timeout)
8734 g_source_remove (entry->blink_timeout);
8735 entry->blink_timeout = 0;
8738 entry->cursor_visible = TRUE;
8744 gtk_entry_pend_cursor_blink (GtkEntry *entry)
8746 if (cursor_blinks (entry))
8748 if (entry->blink_timeout != 0)
8749 g_source_remove (entry->blink_timeout);
8751 entry->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_PEND_MULTIPLIER / CURSOR_DIVIDER,
8754 show_cursor (entry);
8759 gtk_entry_reset_blink_time (GtkEntry *entry)
8761 GtkEntryPrivate *priv;
8763 priv = GTK_ENTRY_GET_PRIVATE (entry);
8765 priv->blink_time = 0;
8771 gtk_entry_completion_timeout (gpointer data)
8773 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (data);
8775 completion->priv->completion_timeout = 0;
8777 if (completion->priv->filter_model &&
8778 g_utf8_strlen (gtk_entry_get_text (GTK_ENTRY (completion->priv->entry)), -1)
8779 >= completion->priv->minimum_key_length)
8783 GtkTreeSelection *s;
8784 gboolean popup_single;
8786 gtk_entry_completion_complete (completion);
8787 matches = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->filter_model), NULL);
8789 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
8791 s = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view));
8793 gtk_tree_selection_unselect_all (s);
8795 actions = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->actions), NULL);
8797 g_object_get (completion, "popup-single-match", &popup_single, NULL);
8798 if ((matches > (popup_single ? 0: 1)) || actions > 0)
8800 if (GTK_WIDGET_VISIBLE (completion->priv->popup_window))
8801 _gtk_entry_completion_resize_popup (completion);
8803 _gtk_entry_completion_popup (completion);
8806 _gtk_entry_completion_popdown (completion);
8808 else if (GTK_WIDGET_VISIBLE (completion->priv->popup_window))
8809 _gtk_entry_completion_popdown (completion);
8814 static inline gboolean
8815 keyval_is_cursor_move (guint keyval)
8817 if (keyval == GDK_Up || keyval == GDK_KP_Up)
8820 if (keyval == GDK_Down || keyval == GDK_KP_Down)
8823 if (keyval == GDK_Page_Up)
8826 if (keyval == GDK_Page_Down)
8833 gtk_entry_completion_key_press (GtkWidget *widget,
8837 gint matches, actions = 0;
8838 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
8840 if (!GTK_WIDGET_MAPPED (completion->priv->popup_window))
8843 matches = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->filter_model), NULL);
8845 if (completion->priv->actions)
8846 actions = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->actions), NULL);
8848 if (keyval_is_cursor_move (event->keyval))
8850 GtkTreePath *path = NULL;
8852 if (event->keyval == GDK_Up || event->keyval == GDK_KP_Up)
8854 if (completion->priv->current_selected < 0)
8855 completion->priv->current_selected = matches + actions - 1;
8857 completion->priv->current_selected--;
8859 else if (event->keyval == GDK_Down || event->keyval == GDK_KP_Down)
8861 if (completion->priv->current_selected < matches + actions - 1)
8862 completion->priv->current_selected++;
8864 completion->priv->current_selected = -1;
8866 else if (event->keyval == GDK_Page_Up)
8868 if (completion->priv->current_selected < 0)
8869 completion->priv->current_selected = matches + actions - 1;
8870 else if (completion->priv->current_selected == 0)
8871 completion->priv->current_selected = -1;
8872 else if (completion->priv->current_selected < matches)
8874 completion->priv->current_selected -= 14;
8875 if (completion->priv->current_selected < 0)
8876 completion->priv->current_selected = 0;
8880 completion->priv->current_selected -= 14;
8881 if (completion->priv->current_selected < matches - 1)
8882 completion->priv->current_selected = matches - 1;
8885 else if (event->keyval == GDK_Page_Down)
8887 if (completion->priv->current_selected < 0)
8888 completion->priv->current_selected = 0;
8889 else if (completion->priv->current_selected < matches - 1)
8891 completion->priv->current_selected += 14;
8892 if (completion->priv->current_selected > matches - 1)
8893 completion->priv->current_selected = matches - 1;
8895 else if (completion->priv->current_selected == matches + actions - 1)
8897 completion->priv->current_selected = -1;
8901 completion->priv->current_selected += 14;
8902 if (completion->priv->current_selected > matches + actions - 1)
8903 completion->priv->current_selected = matches + actions - 1;
8907 if (completion->priv->current_selected < 0)
8909 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
8910 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view)));
8912 if (completion->priv->inline_selection &&
8913 completion->priv->completion_prefix)
8915 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
8916 completion->priv->completion_prefix);
8917 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
8920 else if (completion->priv->current_selected < matches)
8922 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view)));
8924 path = gtk_tree_path_new_from_indices (completion->priv->current_selected, -1);
8925 gtk_tree_view_set_cursor (GTK_TREE_VIEW (completion->priv->tree_view),
8928 if (completion->priv->inline_selection)
8932 GtkTreeModel *model = NULL;
8933 GtkTreeSelection *sel;
8936 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view));
8937 if (!gtk_tree_selection_get_selected (sel, &model, &iter))
8940 if (completion->priv->completion_prefix == NULL)
8941 completion->priv->completion_prefix = g_strdup (gtk_entry_get_text (GTK_ENTRY (completion->priv->entry)));
8943 g_signal_emit_by_name (completion, "cursor-on-match", model,
8947 else if (completion->priv->current_selected - matches >= 0)
8949 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
8951 path = gtk_tree_path_new_from_indices (completion->priv->current_selected - matches, -1);
8952 gtk_tree_view_set_cursor (GTK_TREE_VIEW (completion->priv->action_view),
8955 if (completion->priv->inline_selection &&
8956 completion->priv->completion_prefix)
8958 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
8959 completion->priv->completion_prefix);
8960 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
8964 gtk_tree_path_free (path);
8968 else if (event->keyval == GDK_Escape ||
8969 event->keyval == GDK_Left ||
8970 event->keyval == GDK_KP_Left ||
8971 event->keyval == GDK_Right ||
8972 event->keyval == GDK_KP_Right)
8974 gboolean retval = TRUE;
8976 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
8977 _gtk_entry_completion_popdown (completion);
8979 if (completion->priv->current_selected < 0)
8982 goto keypress_completion_out;
8984 else if (completion->priv->inline_selection)
8986 /* Escape rejects the tentative completion */
8987 if (event->keyval == GDK_Escape)
8989 if (completion->priv->completion_prefix)
8990 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
8991 completion->priv->completion_prefix);
8993 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry), "");
8996 /* Move the cursor to the end for Right/Esc, to the
8997 beginning for Left */
8998 if (event->keyval == GDK_Right ||
8999 event->keyval == GDK_KP_Right ||
9000 event->keyval == GDK_Escape)
9001 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9003 gtk_editable_set_position (GTK_EDITABLE (widget), 0);
9006 keypress_completion_out:
9007 if (completion->priv->inline_selection)
9009 g_free (completion->priv->completion_prefix);
9010 completion->priv->completion_prefix = NULL;
9015 else if (event->keyval == GDK_Tab ||
9016 event->keyval == GDK_KP_Tab ||
9017 event->keyval == GDK_ISO_Left_Tab)
9019 GtkDirectionType dir = event->keyval == GDK_ISO_Left_Tab ?
9020 GTK_DIR_TAB_BACKWARD : GTK_DIR_TAB_FORWARD;
9022 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9023 _gtk_entry_completion_popdown (completion);
9025 g_free (completion->priv->completion_prefix);
9026 completion->priv->completion_prefix = NULL;
9028 gtk_widget_child_focus (gtk_widget_get_toplevel (widget), dir);
9032 else if (event->keyval == GDK_ISO_Enter ||
9033 event->keyval == GDK_KP_Enter ||
9034 event->keyval == GDK_Return)
9036 gboolean retval = TRUE;
9038 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9039 _gtk_entry_completion_popdown (completion);
9041 if (completion->priv->current_selected < matches)
9044 GtkTreeModel *model = NULL;
9045 GtkTreeSelection *sel;
9048 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view));
9049 if (gtk_tree_selection_get_selected (sel, &model, &iter))
9051 g_signal_handler_block (widget, completion->priv->changed_id);
9052 g_signal_emit_by_name (completion, "match-selected",
9053 model, &iter, &entry_set);
9054 g_signal_handler_unblock (widget, completion->priv->changed_id);
9060 gtk_tree_model_get (model, &iter,
9061 completion->priv->text_column, &str,
9064 gtk_entry_set_text (GTK_ENTRY (widget), str);
9066 /* move the cursor to the end */
9067 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9075 else if (completion->priv->current_selected - matches >= 0)
9079 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9081 path = gtk_tree_path_new_from_indices (completion->priv->current_selected - matches, -1);
9083 g_signal_emit_by_name (completion, "action-activated",
9084 gtk_tree_path_get_indices (path)[0]);
9085 gtk_tree_path_free (path);
9088 g_free (completion->priv->completion_prefix);
9089 completion->priv->completion_prefix = NULL;
9098 gtk_entry_completion_changed (GtkWidget *entry,
9101 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
9103 /* (re)install completion timeout */
9104 if (completion->priv->completion_timeout)
9105 g_source_remove (completion->priv->completion_timeout);
9107 if (!gtk_entry_get_text (GTK_ENTRY (entry)))
9110 /* no need to normalize for this test */
9111 if (completion->priv->minimum_key_length > 0 &&
9112 strcmp ("", gtk_entry_get_text (GTK_ENTRY (entry))) == 0)
9114 if (GTK_WIDGET_VISIBLE (completion->priv->popup_window))
9115 _gtk_entry_completion_popdown (completion);
9119 completion->priv->completion_timeout =
9120 gdk_threads_add_timeout (COMPLETION_TIMEOUT,
9121 gtk_entry_completion_timeout,
9126 check_completion_callback (GtkEntryCompletion *completion)
9128 completion->priv->check_completion_idle = NULL;
9130 gtk_entry_completion_complete (completion);
9131 gtk_entry_completion_insert_prefix (completion);
9137 clear_completion_callback (GtkEntry *entry,
9140 if (pspec->name == I_("cursor-position") ||
9141 pspec->name == I_("selection-bound"))
9143 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
9145 completion->priv->has_completion = FALSE;
9150 accept_completion_callback (GtkEntry *entry)
9152 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
9154 if (completion->priv->has_completion)
9155 gtk_editable_set_position (GTK_EDITABLE (entry),
9156 entry->text_length);
9162 completion_insert_text_callback (GtkEntry *entry,
9166 GtkEntryCompletion *completion)
9168 /* idle to update the selection based on the file list */
9169 if (completion->priv->check_completion_idle == NULL)
9171 completion->priv->check_completion_idle = g_idle_source_new ();
9172 g_source_set_priority (completion->priv->check_completion_idle, G_PRIORITY_HIGH);
9173 g_source_set_closure (completion->priv->check_completion_idle,
9174 g_cclosure_new_object (G_CALLBACK (check_completion_callback),
9175 G_OBJECT (completion)));
9176 g_source_attach (completion->priv->check_completion_idle, NULL);
9181 completion_changed (GtkEntryCompletion *completion,
9185 GtkEntry *entry = GTK_ENTRY (data);
9187 if (pspec->name == I_("popup-completion") ||
9188 pspec->name == I_("inline-completion"))
9190 disconnect_completion_signals (entry, completion);
9191 connect_completion_signals (entry, completion);
9196 disconnect_completion_signals (GtkEntry *entry,
9197 GtkEntryCompletion *completion)
9199 g_signal_handlers_disconnect_by_func (completion,
9200 G_CALLBACK (completion_changed), entry);
9201 if (completion->priv->changed_id > 0 &&
9202 g_signal_handler_is_connected (entry, completion->priv->changed_id))
9204 g_signal_handler_disconnect (entry, completion->priv->changed_id);
9205 completion->priv->changed_id = 0;
9207 g_signal_handlers_disconnect_by_func (entry,
9208 G_CALLBACK (gtk_entry_completion_key_press), completion);
9209 if (completion->priv->insert_text_id > 0 &&
9210 g_signal_handler_is_connected (entry, completion->priv->insert_text_id))
9212 g_signal_handler_disconnect (entry, completion->priv->insert_text_id);
9213 completion->priv->insert_text_id = 0;
9215 g_signal_handlers_disconnect_by_func (entry,
9216 G_CALLBACK (completion_insert_text_callback), completion);
9217 g_signal_handlers_disconnect_by_func (entry,
9218 G_CALLBACK (clear_completion_callback), completion);
9219 g_signal_handlers_disconnect_by_func (entry,
9220 G_CALLBACK (accept_completion_callback), completion);
9224 connect_completion_signals (GtkEntry *entry,
9225 GtkEntryCompletion *completion)
9227 if (completion->priv->popup_completion)
9229 completion->priv->changed_id =
9230 g_signal_connect (entry, "changed",
9231 G_CALLBACK (gtk_entry_completion_changed), completion);
9232 g_signal_connect (entry, "key-press-event",
9233 G_CALLBACK (gtk_entry_completion_key_press), completion);
9236 if (completion->priv->inline_completion)
9238 completion->priv->insert_text_id =
9239 g_signal_connect (entry, "insert-text",
9240 G_CALLBACK (completion_insert_text_callback), completion);
9241 g_signal_connect (entry, "notify",
9242 G_CALLBACK (clear_completion_callback), completion);
9243 g_signal_connect (entry, "activate",
9244 G_CALLBACK (accept_completion_callback), completion);
9245 g_signal_connect (entry, "focus-out-event",
9246 G_CALLBACK (accept_completion_callback), completion);
9249 g_signal_connect (completion, "notify",
9250 G_CALLBACK (completion_changed), entry);
9254 * gtk_entry_set_completion:
9255 * @entry: A #GtkEntry
9256 * @completion: The #GtkEntryCompletion or %NULL
9258 * Sets @completion to be the auxiliary completion object to use with @entry.
9259 * All further configuration of the completion mechanism is done on
9260 * @completion using the #GtkEntryCompletion API. Completion is disabled if
9261 * @completion is set to %NULL.
9266 gtk_entry_set_completion (GtkEntry *entry,
9267 GtkEntryCompletion *completion)
9269 GtkEntryCompletion *old;
9271 g_return_if_fail (GTK_IS_ENTRY (entry));
9272 g_return_if_fail (!completion || GTK_IS_ENTRY_COMPLETION (completion));
9274 old = gtk_entry_get_completion (entry);
9276 if (old == completion)
9281 if (old->priv->completion_timeout)
9283 g_source_remove (old->priv->completion_timeout);
9284 old->priv->completion_timeout = 0;
9287 if (GTK_WIDGET_MAPPED (old->priv->popup_window))
9288 _gtk_entry_completion_popdown (old);
9290 disconnect_completion_signals (entry, old);
9291 old->priv->entry = NULL;
9293 g_object_unref (old);
9298 g_object_set_data (G_OBJECT (entry), I_(GTK_ENTRY_COMPLETION_KEY), NULL);
9302 /* hook into the entry */
9303 g_object_ref (completion);
9305 connect_completion_signals (entry, completion);
9306 completion->priv->entry = GTK_WIDGET (entry);
9307 g_object_set_data (G_OBJECT (entry), I_(GTK_ENTRY_COMPLETION_KEY), completion);
9311 * gtk_entry_get_completion:
9312 * @entry: A #GtkEntry
9314 * Returns the auxiliary completion object currently in use by @entry.
9316 * Return value: The auxiliary completion object currently in use by @entry.
9320 GtkEntryCompletion *
9321 gtk_entry_get_completion (GtkEntry *entry)
9323 GtkEntryCompletion *completion;
9325 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
9327 completion = GTK_ENTRY_COMPLETION (g_object_get_data (G_OBJECT (entry),
9328 GTK_ENTRY_COMPLETION_KEY));
9334 * gtk_entry_set_cursor_hadjustment:
9335 * @entry: a #GtkEntry
9336 * @adjustment: an adjustment which should be adjusted when the cursor
9337 * is moved, or %NULL
9339 * Hooks up an adjustment to the cursor position in an entry, so that when
9340 * the cursor is moved, the adjustment is scrolled to show that position.
9341 * See gtk_scrolled_window_get_hadjustment() for a typical way of obtaining
9344 * The adjustment has to be in pixel units and in the same coordinate system
9350 gtk_entry_set_cursor_hadjustment (GtkEntry *entry,
9351 GtkAdjustment *adjustment)
9353 g_return_if_fail (GTK_IS_ENTRY (entry));
9355 g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
9358 g_object_ref (adjustment);
9360 g_object_set_qdata_full (G_OBJECT (entry),
9361 quark_cursor_hadjustment,
9367 * gtk_entry_get_cursor_hadjustment:
9368 * @entry: a #GtkEntry
9370 * Retrieves the horizontal cursor adjustment for the entry.
9371 * See gtk_entry_set_cursor_hadjustment().
9373 * Return value: the horizontal cursor adjustment, or %NULL
9374 * if none has been set.
9379 gtk_entry_get_cursor_hadjustment (GtkEntry *entry)
9381 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
9383 return g_object_get_qdata (G_OBJECT (entry), quark_cursor_hadjustment);
9387 * gtk_entry_set_progress_fraction:
9388 * @entry: a #GtkEntry
9389 * @fraction: fraction of the task that's been completed
9391 * Causes the entry's progress indicator to "fill in" the given
9392 * fraction of the bar. The fraction should be between 0.0 and 1.0,
9398 gtk_entry_set_progress_fraction (GtkEntry *entry,
9401 GtkEntryPrivate *private;
9402 gdouble old_fraction;
9404 g_return_if_fail (GTK_IS_ENTRY (entry));
9406 private = GTK_ENTRY_GET_PRIVATE (entry);
9408 if (private->progress_pulse_mode)
9411 old_fraction = private->progress_fraction;
9413 fraction = CLAMP (fraction, 0.0, 1.0);
9415 private->progress_fraction = fraction;
9416 private->progress_pulse_mode = FALSE;
9417 private->progress_pulse_current = 0.0;
9419 if (fabs (fraction - old_fraction) > 0.0001)
9420 gtk_entry_queue_draw (entry);
9422 if (fraction != old_fraction)
9423 g_object_notify (G_OBJECT (entry), "progress-fraction");
9427 * gtk_entry_get_progress_fraction:
9428 * @entry: a #GtkEntry
9430 * Returns the current fraction of the task that's been completed.
9431 * See gtk_entry_set_progress_fraction().
9433 * Return value: a fraction from 0.0 to 1.0
9438 gtk_entry_get_progress_fraction (GtkEntry *entry)
9440 GtkEntryPrivate *private;
9442 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
9444 private = GTK_ENTRY_GET_PRIVATE (entry);
9446 return private->progress_fraction;
9450 * gtk_entry_set_progress_pulse_step:
9451 * @entry: a #GtkEntry
9452 * @fraction: fraction between 0.0 and 1.0
9454 * Sets the fraction of total entry width to move the progress
9455 * bouncing block for each call to gtk_entry_progress_pulse().
9460 gtk_entry_set_progress_pulse_step (GtkEntry *entry,
9463 GtkEntryPrivate *private;
9465 g_return_if_fail (GTK_IS_ENTRY (entry));
9467 private = GTK_ENTRY_GET_PRIVATE (entry);
9469 fraction = CLAMP (fraction, 0.0, 1.0);
9471 if (fraction != private->progress_pulse_fraction)
9473 private->progress_pulse_fraction = fraction;
9475 gtk_entry_queue_draw (entry);
9477 g_object_notify (G_OBJECT (entry), "progress-pulse-step");
9482 * gtk_entry_get_progress_pulse_step:
9483 * @entry: a #GtkEntry
9485 * Retrieves the pulse step set with gtk_entry_set_progress_pulse_step().
9487 * Return value: a fraction from 0.0 to 1.0
9492 gtk_entry_get_progress_pulse_step (GtkEntry *entry)
9494 GtkEntryPrivate *private;
9496 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
9498 private = GTK_ENTRY_GET_PRIVATE (entry);
9500 return private->progress_pulse_fraction;
9504 * gtk_entry_progress_pulse:
9505 * @entry: a #GtkEntry
9507 * Indicates that some progress is made, but you don't know how much.
9508 * Causes the entry's progress indicator to enter "activity mode,"
9509 * where a block bounces back and forth. Each call to
9510 * gtk_entry_progress_pulse() causes the block to move by a little bit
9511 * (the amount of movement per pulse is determined by
9512 * gtk_entry_set_progress_pulse_step()).
9517 gtk_entry_progress_pulse (GtkEntry *entry)
9519 GtkEntryPrivate *private;
9521 g_return_if_fail (GTK_IS_ENTRY (entry));
9523 private = GTK_ENTRY_GET_PRIVATE (entry);
9525 if (private->progress_pulse_mode)
9527 if (private->progress_pulse_way_back)
9529 private->progress_pulse_current -= private->progress_pulse_fraction;
9531 if (private->progress_pulse_current < 0.0)
9533 private->progress_pulse_current = 0.0;
9534 private->progress_pulse_way_back = FALSE;
9539 private->progress_pulse_current += private->progress_pulse_fraction;
9541 if (private->progress_pulse_current > 1.0 - private->progress_pulse_fraction)
9543 private->progress_pulse_current = 1.0 - private->progress_pulse_fraction;
9544 private->progress_pulse_way_back = TRUE;
9550 private->progress_fraction = 0.0;
9551 private->progress_pulse_mode = TRUE;
9552 private->progress_pulse_way_back = FALSE;
9553 private->progress_pulse_current = 0.0;
9556 gtk_entry_queue_draw (entry);
9559 /* Caps Lock warning for password entries */
9562 show_capslock_feedback (GtkEntry *entry,
9565 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
9567 if (gtk_entry_get_icon_storage_type (entry, GTK_ENTRY_ICON_SECONDARY) == GTK_IMAGE_EMPTY)
9569 gtk_entry_set_icon_from_stock (entry, GTK_ENTRY_ICON_SECONDARY, GTK_STOCK_CAPS_LOCK_WARNING);
9570 gtk_entry_set_icon_activatable (entry, GTK_ENTRY_ICON_SECONDARY, FALSE);
9571 priv->caps_lock_warning_shown = TRUE;
9574 if (priv->caps_lock_warning_shown)
9575 gtk_entry_set_icon_tooltip_text (entry, GTK_ENTRY_ICON_SECONDARY, text);
9577 g_warning ("Can't show Caps Lock warning, since secondary icon is set");
9581 remove_capslock_feedback (GtkEntry *entry)
9583 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
9585 if (priv->caps_lock_warning_shown)
9587 gtk_entry_set_icon_from_stock (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
9588 priv->caps_lock_warning_shown = FALSE;
9593 keymap_state_changed (GdkKeymap *keymap,
9596 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
9599 if (!entry->visible && priv->caps_lock_warning)
9601 gboolean capslock_on;
9604 capslock_on = gdk_keymap_get_caps_lock_state (keymap);
9605 im_on = g_strcmp0 (gtk_im_multicontext_get_context_id (GTK_IM_MULTICONTEXT (entry->im_context)), "gtk-im-context-simple") != 0;
9606 if (capslock_on && im_on)
9607 text = _("You have the Caps Lock key on\nand an active input method");
9608 else if (capslock_on)
9609 text = _("You have the Caps Lock key on");
9611 text = _("You have an active input method");
9615 show_capslock_feedback (entry, text);
9617 remove_capslock_feedback (entry);
9620 #define __GTK_ENTRY_C__
9621 #include "gtkaliasdef.c"