1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* GTK - The GIMP Toolkit
3 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * Copyright (C) 2004-2006 Christian Hammond
5 * Copyright (C) 2008 Cody Russell
6 * Copyright (C) 2008 Red Hat, Inc.
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
25 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
26 * file for a list of people on the GTK+ Team. See the ChangeLog
27 * files for a list of changes. These files are distributed with
28 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
36 #include "gdk/gdkkeysyms.h"
37 #include "gtkalignment.h"
38 #include "gtkbindings.h"
39 #include "gtkcelleditable.h"
40 #include "gtkclipboard.h"
43 #include "gtkentrybuffer.h"
44 #include "gtkimagemenuitem.h"
45 #include "gtkimcontextsimple.h"
46 #include "gtkimmulticontext.h"
50 #include "gtkmarshalers.h"
52 #include "gtkmenuitem.h"
53 #include "gtkseparatormenuitem.h"
54 #include "gtkselection.h"
55 #include "gtksettings.h"
56 #include "gtkspinbutton.h"
58 #include "gtktextutil.h"
59 #include "gtkwindow.h"
60 #include "gtktreeview.h"
61 #include "gtktreeselection.h"
62 #include "gtkprivate.h"
63 #include "gtkentryprivate.h"
64 #include "gtkcelllayout.h"
65 #include "gtktooltip.h"
66 #include "gtkiconfactory.h"
67 #include "gtkicontheme.h"
70 #define GTK_ENTRY_COMPLETION_KEY "gtk-entry-completion-key"
72 #define MIN_ENTRY_WIDTH 150
73 #define DRAW_TIMEOUT 20
74 #define COMPLETION_TIMEOUT 300
75 #define PASSWORD_HINT_MAX 8
79 #define IS_VALID_ICON_POSITION(pos) \
80 ((pos) == GTK_ENTRY_ICON_PRIMARY || \
81 (pos) == GTK_ENTRY_ICON_SECONDARY)
83 static const GtkBorder default_inner_border = { 2, 2, 2, 2 };
84 static GQuark quark_inner_border = 0;
85 static GQuark quark_password_hint = 0;
86 static GQuark quark_cursor_hadjustment = 0;
87 static GQuark quark_capslock_feedback = 0;
89 typedef struct _GtkEntryPrivate GtkEntryPrivate;
91 #define GTK_ENTRY_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_ENTRY, GtkEntryPrivate))
97 guint insensitive : 1;
98 guint nonactivatable : 1;
103 GtkImageType storage_type;
109 GtkTargetList *target_list;
110 GdkDragAction actions;
113 struct _GtkEntryPrivate
115 GtkEntryBuffer* buffer;
119 guint blink_time; /* time in msec the cursor has blinked since last user event */
120 guint interior_focus : 1;
121 guint real_changed : 1;
122 guint invisible_char_set : 1;
123 guint caps_lock_warning : 1;
124 guint caps_lock_warning_shown : 1;
125 guint change_count : 8;
126 guint progress_pulse_mode : 1;
127 guint progress_pulse_way_back : 1;
130 GtkShadowType shadow_type;
132 gdouble progress_fraction;
133 gdouble progress_pulse_fraction;
134 gdouble progress_pulse_current;
136 EntryIconInfo *icons[MAX_ICONS];
144 typedef struct _GtkEntryPasswordHint GtkEntryPasswordHint;
146 struct _GtkEntryPasswordHint
148 gint position; /* Position (in text) of the last password hint */
149 guint source_id; /* Timeout source id */
152 typedef struct _GtkEntryCapslockFeedback GtkEntryCapslockFeedback;
154 struct _GtkEntryCapslockFeedback
180 PROP_CURSOR_POSITION,
181 PROP_SELECTION_BOUND,
188 PROP_ACTIVATES_DEFAULT,
193 PROP_TRUNCATE_MULTILINE,
197 PROP_INVISIBLE_CHAR_SET,
198 PROP_CAPS_LOCK_WARNING,
199 PROP_PROGRESS_FRACTION,
200 PROP_PROGRESS_PULSE_STEP,
202 PROP_PIXBUF_SECONDARY,
204 PROP_STOCK_SECONDARY,
205 PROP_ICON_NAME_PRIMARY,
206 PROP_ICON_NAME_SECONDARY,
208 PROP_GICON_SECONDARY,
209 PROP_STORAGE_TYPE_PRIMARY,
210 PROP_STORAGE_TYPE_SECONDARY,
211 PROP_ACTIVATABLE_PRIMARY,
212 PROP_ACTIVATABLE_SECONDARY,
213 PROP_SENSITIVE_PRIMARY,
214 PROP_SENSITIVE_SECONDARY,
215 PROP_TOOLTIP_TEXT_PRIMARY,
216 PROP_TOOLTIP_TEXT_SECONDARY,
217 PROP_TOOLTIP_MARKUP_PRIMARY,
218 PROP_TOOLTIP_MARKUP_SECONDARY,
220 PROP_EDITING_CANCELED
223 static guint signals[LAST_SIGNAL] = { 0 };
232 DISPLAY_NORMAL, /* The entry text is being shown */
233 DISPLAY_INVISIBLE, /* In invisible mode, text replaced by (eg) bullets */
234 DISPLAY_BLANK /* In invisible mode, nothing shown at all */
237 /* GObject, GtkObject methods
239 static void gtk_entry_editable_init (GtkEditableClass *iface);
240 static void gtk_entry_cell_editable_init (GtkCellEditableIface *iface);
241 static void gtk_entry_set_property (GObject *object,
245 static void gtk_entry_get_property (GObject *object,
249 static void gtk_entry_finalize (GObject *object);
250 static void gtk_entry_destroy (GtkObject *object);
251 static void gtk_entry_dispose (GObject *object);
255 static void gtk_entry_realize (GtkWidget *widget);
256 static void gtk_entry_unrealize (GtkWidget *widget);
257 static void gtk_entry_map (GtkWidget *widget);
258 static void gtk_entry_unmap (GtkWidget *widget);
259 static void gtk_entry_size_request (GtkWidget *widget,
260 GtkRequisition *requisition);
261 static void gtk_entry_size_allocate (GtkWidget *widget,
262 GtkAllocation *allocation);
263 static void gtk_entry_draw_frame (GtkWidget *widget,
264 GdkEventExpose *event);
265 static void gtk_entry_draw_progress (GtkWidget *widget,
266 GdkEventExpose *event);
267 static gint gtk_entry_expose (GtkWidget *widget,
268 GdkEventExpose *event);
269 static gint gtk_entry_button_press (GtkWidget *widget,
270 GdkEventButton *event);
271 static gint gtk_entry_button_release (GtkWidget *widget,
272 GdkEventButton *event);
273 static gint gtk_entry_enter_notify (GtkWidget *widget,
274 GdkEventCrossing *event);
275 static gint gtk_entry_leave_notify (GtkWidget *widget,
276 GdkEventCrossing *event);
277 static gint gtk_entry_motion_notify (GtkWidget *widget,
278 GdkEventMotion *event);
279 static gint gtk_entry_key_press (GtkWidget *widget,
281 static gint gtk_entry_key_release (GtkWidget *widget,
283 static gint gtk_entry_focus_in (GtkWidget *widget,
284 GdkEventFocus *event);
285 static gint gtk_entry_focus_out (GtkWidget *widget,
286 GdkEventFocus *event);
287 static void gtk_entry_grab_focus (GtkWidget *widget);
288 static void gtk_entry_style_set (GtkWidget *widget,
289 GtkStyle *previous_style);
290 static gboolean gtk_entry_query_tooltip (GtkWidget *widget,
293 gboolean keyboard_tip,
294 GtkTooltip *tooltip);
295 static void gtk_entry_direction_changed (GtkWidget *widget,
296 GtkTextDirection previous_dir);
297 static void gtk_entry_state_changed (GtkWidget *widget,
298 GtkStateType previous_state);
299 static void gtk_entry_screen_changed (GtkWidget *widget,
300 GdkScreen *old_screen);
302 static gboolean gtk_entry_drag_drop (GtkWidget *widget,
303 GdkDragContext *context,
307 static gboolean gtk_entry_drag_motion (GtkWidget *widget,
308 GdkDragContext *context,
312 static void gtk_entry_drag_leave (GtkWidget *widget,
313 GdkDragContext *context,
315 static void gtk_entry_drag_data_received (GtkWidget *widget,
316 GdkDragContext *context,
319 GtkSelectionData *selection_data,
322 static void gtk_entry_drag_data_get (GtkWidget *widget,
323 GdkDragContext *context,
324 GtkSelectionData *selection_data,
327 static void gtk_entry_drag_data_delete (GtkWidget *widget,
328 GdkDragContext *context);
329 static void gtk_entry_drag_begin (GtkWidget *widget,
330 GdkDragContext *context);
331 static void gtk_entry_drag_end (GtkWidget *widget,
332 GdkDragContext *context);
335 /* GtkEditable method implementations
337 static void gtk_entry_insert_text (GtkEditable *editable,
338 const gchar *new_text,
339 gint new_text_length,
341 static void gtk_entry_delete_text (GtkEditable *editable,
344 static gchar * gtk_entry_get_chars (GtkEditable *editable,
347 static void gtk_entry_real_set_position (GtkEditable *editable,
349 static gint gtk_entry_get_position (GtkEditable *editable);
350 static void gtk_entry_set_selection_bounds (GtkEditable *editable,
353 static gboolean gtk_entry_get_selection_bounds (GtkEditable *editable,
357 /* GtkCellEditable method implementations
359 static void gtk_entry_start_editing (GtkCellEditable *cell_editable,
362 /* Default signal handlers
364 static void gtk_entry_real_insert_text (GtkEditable *editable,
365 const gchar *new_text,
366 gint new_text_length,
368 static void gtk_entry_real_delete_text (GtkEditable *editable,
371 static void gtk_entry_move_cursor (GtkEntry *entry,
372 GtkMovementStep step,
374 gboolean extend_selection);
375 static void gtk_entry_insert_at_cursor (GtkEntry *entry,
377 static void gtk_entry_delete_from_cursor (GtkEntry *entry,
380 static void gtk_entry_backspace (GtkEntry *entry);
381 static void gtk_entry_cut_clipboard (GtkEntry *entry);
382 static void gtk_entry_copy_clipboard (GtkEntry *entry);
383 static void gtk_entry_paste_clipboard (GtkEntry *entry);
384 static void gtk_entry_toggle_overwrite (GtkEntry *entry);
385 static void gtk_entry_select_all (GtkEntry *entry);
386 static void gtk_entry_real_activate (GtkEntry *entry);
387 static gboolean gtk_entry_popup_menu (GtkWidget *widget);
389 static void keymap_direction_changed (GdkKeymap *keymap,
391 static void keymap_state_changed (GdkKeymap *keymap,
393 static void remove_capslock_feedback (GtkEntry *entry);
395 /* IM Context Callbacks
397 static void gtk_entry_commit_cb (GtkIMContext *context,
400 static void gtk_entry_preedit_changed_cb (GtkIMContext *context,
402 static gboolean gtk_entry_retrieve_surrounding_cb (GtkIMContext *context,
404 static gboolean gtk_entry_delete_surrounding_cb (GtkIMContext *context,
411 static void gtk_entry_enter_text (GtkEntry *entry,
413 static void gtk_entry_set_positions (GtkEntry *entry,
415 gint selection_bound);
416 static void gtk_entry_draw_text (GtkEntry *entry);
417 static void gtk_entry_draw_cursor (GtkEntry *entry,
419 static PangoLayout *gtk_entry_ensure_layout (GtkEntry *entry,
420 gboolean include_preedit);
421 static void gtk_entry_reset_layout (GtkEntry *entry);
422 static void gtk_entry_queue_draw (GtkEntry *entry);
423 static void gtk_entry_recompute (GtkEntry *entry);
424 static gint gtk_entry_find_position (GtkEntry *entry,
426 static void gtk_entry_get_cursor_locations (GtkEntry *entry,
430 static void gtk_entry_adjust_scroll (GtkEntry *entry);
431 static gint gtk_entry_move_visually (GtkEntry *editable,
434 static gint gtk_entry_move_logically (GtkEntry *entry,
437 static gint gtk_entry_move_forward_word (GtkEntry *entry,
439 gboolean allow_whitespace);
440 static gint gtk_entry_move_backward_word (GtkEntry *entry,
442 gboolean allow_whitespace);
443 static void gtk_entry_delete_whitespace (GtkEntry *entry);
444 static void gtk_entry_select_word (GtkEntry *entry);
445 static void gtk_entry_select_line (GtkEntry *entry);
446 static void gtk_entry_paste (GtkEntry *entry,
448 static void gtk_entry_update_primary_selection (GtkEntry *entry);
449 static void gtk_entry_do_popup (GtkEntry *entry,
450 GdkEventButton *event);
451 static gboolean gtk_entry_mnemonic_activate (GtkWidget *widget,
452 gboolean group_cycling);
453 static void gtk_entry_check_cursor_blink (GtkEntry *entry);
454 static void gtk_entry_pend_cursor_blink (GtkEntry *entry);
455 static void gtk_entry_reset_blink_time (GtkEntry *entry);
456 static void gtk_entry_get_text_area_size (GtkEntry *entry,
461 static void get_text_area_size (GtkEntry *entry,
466 static void get_widget_window_size (GtkEntry *entry,
471 static void gtk_entry_move_adjustments (GtkEntry *entry);
472 static void gtk_entry_ensure_pixbuf (GtkEntry *entry,
473 GtkEntryIconPosition icon_pos);
477 static gint gtk_entry_completion_timeout (gpointer data);
478 static gboolean gtk_entry_completion_key_press (GtkWidget *widget,
481 static void gtk_entry_completion_changed (GtkWidget *entry,
483 static gboolean check_completion_callback (GtkEntryCompletion *completion);
484 static void clear_completion_callback (GtkEntry *entry,
486 static gboolean accept_completion_callback (GtkEntry *entry);
487 static void completion_insert_text_callback (GtkEntry *entry,
491 GtkEntryCompletion *completion);
492 static void completion_changed (GtkEntryCompletion *completion,
495 static void disconnect_completion_signals (GtkEntry *entry,
496 GtkEntryCompletion *completion);
497 static void connect_completion_signals (GtkEntry *entry,
498 GtkEntryCompletion *completion);
500 static void begin_change (GtkEntry *entry);
501 static void end_change (GtkEntry *entry);
502 static void emit_changed (GtkEntry *entry);
505 static void buffer_inserted_text (GtkEntryBuffer *buffer,
510 static void buffer_deleted_text (GtkEntryBuffer *buffer,
514 static void buffer_notify_text (GtkEntryBuffer *buffer,
517 static void buffer_notify_length (GtkEntryBuffer *buffer,
520 static void buffer_notify_max_length (GtkEntryBuffer *buffer,
523 static void buffer_connect_signals (GtkEntry *entry);
524 static void buffer_disconnect_signals (GtkEntry *entry);
525 static GtkEntryBuffer *get_buffer (GtkEntry *entry);
528 G_DEFINE_TYPE_WITH_CODE (GtkEntry, gtk_entry, GTK_TYPE_WIDGET,
529 G_IMPLEMENT_INTERFACE (GTK_TYPE_EDITABLE,
530 gtk_entry_editable_init)
531 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_EDITABLE,
532 gtk_entry_cell_editable_init))
535 add_move_binding (GtkBindingSet *binding_set,
538 GtkMovementStep step,
541 g_return_if_fail ((modmask & GDK_SHIFT_MASK) == 0);
543 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
547 G_TYPE_BOOLEAN, FALSE);
549 /* Selection-extending version */
550 gtk_binding_entry_add_signal (binding_set, keyval, modmask | GDK_SHIFT_MASK,
554 G_TYPE_BOOLEAN, TRUE);
558 gtk_entry_class_init (GtkEntryClass *class)
560 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
561 GtkWidgetClass *widget_class;
562 GtkObjectClass *gtk_object_class;
563 GtkBindingSet *binding_set;
565 widget_class = (GtkWidgetClass*) class;
566 gtk_object_class = (GtkObjectClass *)class;
568 gobject_class->dispose = gtk_entry_dispose;
569 gobject_class->finalize = gtk_entry_finalize;
570 gobject_class->set_property = gtk_entry_set_property;
571 gobject_class->get_property = gtk_entry_get_property;
573 widget_class->map = gtk_entry_map;
574 widget_class->unmap = gtk_entry_unmap;
575 widget_class->realize = gtk_entry_realize;
576 widget_class->unrealize = gtk_entry_unrealize;
577 widget_class->size_request = gtk_entry_size_request;
578 widget_class->size_allocate = gtk_entry_size_allocate;
579 widget_class->expose_event = gtk_entry_expose;
580 widget_class->enter_notify_event = gtk_entry_enter_notify;
581 widget_class->leave_notify_event = gtk_entry_leave_notify;
582 widget_class->button_press_event = gtk_entry_button_press;
583 widget_class->button_release_event = gtk_entry_button_release;
584 widget_class->motion_notify_event = gtk_entry_motion_notify;
585 widget_class->key_press_event = gtk_entry_key_press;
586 widget_class->key_release_event = gtk_entry_key_release;
587 widget_class->focus_in_event = gtk_entry_focus_in;
588 widget_class->focus_out_event = gtk_entry_focus_out;
589 widget_class->grab_focus = gtk_entry_grab_focus;
590 widget_class->style_set = gtk_entry_style_set;
591 widget_class->query_tooltip = gtk_entry_query_tooltip;
592 widget_class->drag_begin = gtk_entry_drag_begin;
593 widget_class->drag_end = gtk_entry_drag_end;
594 widget_class->direction_changed = gtk_entry_direction_changed;
595 widget_class->state_changed = gtk_entry_state_changed;
596 widget_class->screen_changed = gtk_entry_screen_changed;
597 widget_class->mnemonic_activate = gtk_entry_mnemonic_activate;
599 widget_class->drag_drop = gtk_entry_drag_drop;
600 widget_class->drag_motion = gtk_entry_drag_motion;
601 widget_class->drag_leave = gtk_entry_drag_leave;
602 widget_class->drag_data_received = gtk_entry_drag_data_received;
603 widget_class->drag_data_get = gtk_entry_drag_data_get;
604 widget_class->drag_data_delete = gtk_entry_drag_data_delete;
606 widget_class->popup_menu = gtk_entry_popup_menu;
608 gtk_object_class->destroy = gtk_entry_destroy;
610 class->move_cursor = gtk_entry_move_cursor;
611 class->insert_at_cursor = gtk_entry_insert_at_cursor;
612 class->delete_from_cursor = gtk_entry_delete_from_cursor;
613 class->backspace = gtk_entry_backspace;
614 class->cut_clipboard = gtk_entry_cut_clipboard;
615 class->copy_clipboard = gtk_entry_copy_clipboard;
616 class->paste_clipboard = gtk_entry_paste_clipboard;
617 class->toggle_overwrite = gtk_entry_toggle_overwrite;
618 class->activate = gtk_entry_real_activate;
619 class->get_text_area_size = gtk_entry_get_text_area_size;
621 quark_inner_border = g_quark_from_static_string ("gtk-entry-inner-border");
622 quark_password_hint = g_quark_from_static_string ("gtk-entry-password-hint");
623 quark_cursor_hadjustment = g_quark_from_static_string ("gtk-hadjustment");
624 quark_capslock_feedback = g_quark_from_static_string ("gtk-entry-capslock-feedback");
626 g_object_class_override_property (gobject_class,
627 PROP_EDITING_CANCELED,
630 g_object_class_install_property (gobject_class,
632 g_param_spec_object ("buffer",
634 P_("Text buffer object which actually stores entry text"),
635 GTK_TYPE_ENTRY_BUFFER,
636 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT));
638 g_object_class_install_property (gobject_class,
639 PROP_CURSOR_POSITION,
640 g_param_spec_int ("cursor-position",
641 P_("Cursor Position"),
642 P_("The current position of the insertion cursor in chars"),
644 GTK_ENTRY_BUFFER_MAX_SIZE,
646 GTK_PARAM_READABLE));
648 g_object_class_install_property (gobject_class,
649 PROP_SELECTION_BOUND,
650 g_param_spec_int ("selection-bound",
651 P_("Selection Bound"),
652 P_("The position of the opposite end of the selection from the cursor in chars"),
654 GTK_ENTRY_BUFFER_MAX_SIZE,
656 GTK_PARAM_READABLE));
658 g_object_class_install_property (gobject_class,
660 g_param_spec_boolean ("editable",
662 P_("Whether the entry contents can be edited"),
664 GTK_PARAM_READWRITE));
666 g_object_class_install_property (gobject_class,
668 g_param_spec_int ("max-length",
669 P_("Maximum length"),
670 P_("Maximum number of characters for this entry. Zero if no maximum"),
672 GTK_ENTRY_BUFFER_MAX_SIZE,
674 GTK_PARAM_READWRITE));
675 g_object_class_install_property (gobject_class,
677 g_param_spec_boolean ("visibility",
679 P_("FALSE displays the \"invisible char\" instead of the actual text (password mode)"),
681 GTK_PARAM_READWRITE));
683 g_object_class_install_property (gobject_class,
685 g_param_spec_boolean ("has-frame",
687 P_("FALSE removes outside bevel from entry"),
689 GTK_PARAM_READWRITE));
691 g_object_class_install_property (gobject_class,
693 g_param_spec_boxed ("inner-border",
695 P_("Border between text and frame. Overrides the inner-border style property"),
697 GTK_PARAM_READWRITE));
699 g_object_class_install_property (gobject_class,
701 g_param_spec_unichar ("invisible-char",
702 P_("Invisible character"),
703 P_("The character to use when masking entry contents (in \"password mode\")"),
705 GTK_PARAM_READWRITE));
707 g_object_class_install_property (gobject_class,
708 PROP_ACTIVATES_DEFAULT,
709 g_param_spec_boolean ("activates-default",
710 P_("Activates default"),
711 P_("Whether to activate the default widget (such as the default button in a dialog) when Enter is pressed"),
713 GTK_PARAM_READWRITE));
714 g_object_class_install_property (gobject_class,
716 g_param_spec_int ("width-chars",
717 P_("Width in chars"),
718 P_("Number of characters to leave space for in the entry"),
722 GTK_PARAM_READWRITE));
724 g_object_class_install_property (gobject_class,
726 g_param_spec_int ("scroll-offset",
728 P_("Number of pixels of the entry scrolled off the screen to the left"),
732 GTK_PARAM_READABLE));
734 g_object_class_install_property (gobject_class,
736 g_param_spec_string ("text",
738 P_("The contents of the entry"),
740 GTK_PARAM_READWRITE));
745 * The horizontal alignment, from 0 (left) to 1 (right).
746 * Reversed for RTL layouts.
750 g_object_class_install_property (gobject_class,
752 g_param_spec_float ("xalign",
754 P_("The horizontal alignment, from 0 (left) to 1 (right). Reversed for RTL layouts."),
758 GTK_PARAM_READWRITE));
761 * GtkEntry:truncate-multiline:
763 * When %TRUE, pasted multi-line text is truncated to the first line.
767 g_object_class_install_property (gobject_class,
768 PROP_TRUNCATE_MULTILINE,
769 g_param_spec_boolean ("truncate-multiline",
770 P_("Truncate multiline"),
771 P_("Whether to truncate multiline pastes to one line."),
773 GTK_PARAM_READWRITE));
776 * GtkEntry:shadow-type:
778 * Which kind of shadow to draw around the entry when
779 * #GtkEntry:has-frame is set to %TRUE.
783 g_object_class_install_property (gobject_class,
785 g_param_spec_enum ("shadow-type",
787 P_("Which kind of shadow to draw around the entry when has-frame is set"),
788 GTK_TYPE_SHADOW_TYPE,
790 GTK_PARAM_READWRITE));
793 * GtkEntry:overwrite-mode:
795 * If text is overwritten when typing in the #GtkEntry.
799 g_object_class_install_property (gobject_class,
801 g_param_spec_boolean ("overwrite-mode",
802 P_("Overwrite mode"),
803 P_("Whether new text overwrites existing text"),
805 GTK_PARAM_READWRITE));
808 * GtkEntry:text-length:
810 * The length of the text in the #GtkEntry.
814 g_object_class_install_property (gobject_class,
816 g_param_spec_uint ("text-length",
818 P_("Length of the text currently in the entry"),
822 GTK_PARAM_READABLE));
824 * GtkEntry:invisible-char-set:
826 * Whether the invisible char has been set for the #GtkEntry.
830 g_object_class_install_property (gobject_class,
831 PROP_INVISIBLE_CHAR_SET,
832 g_param_spec_boolean ("invisible-char-set",
833 P_("Invisible char set"),
834 P_("Whether the invisible char has been set"),
836 GTK_PARAM_READWRITE));
839 * GtkEntry:caps-lock-warning
841 * Whether password entries will show a warning when Caps Lock is on.
843 * Note that the warning is shown using a secondary icon, and thus
844 * does not work if you are using the secondary icon position for some
849 g_object_class_install_property (gobject_class,
850 PROP_CAPS_LOCK_WARNING,
851 g_param_spec_boolean ("caps-lock-warning",
852 P_("Caps Lock warning"),
853 P_("Whether password entries will show a warning when Caps Lock is on"),
855 GTK_PARAM_READWRITE));
858 * GtkEntry:progress-fraction:
860 * The current fraction of the task that's been completed.
864 g_object_class_install_property (gobject_class,
865 PROP_PROGRESS_FRACTION,
866 g_param_spec_double ("progress-fraction",
867 P_("Progress Fraction"),
868 P_("The current fraction of the task that's been completed"),
872 GTK_PARAM_READWRITE));
875 * GtkEntry:progress-pulse-step:
877 * The fraction of total entry width to move the progress
878 * bouncing block for each call to gtk_entry_progress_pulse().
882 g_object_class_install_property (gobject_class,
883 PROP_PROGRESS_PULSE_STEP,
884 g_param_spec_double ("progress-pulse-step",
885 P_("Progress Pulse Step"),
886 P_("The fraction of total entry width to move the progress bouncing block for each call to gtk_entry_progress_pulse()"),
890 GTK_PARAM_READWRITE));
893 * GtkEntry:primary-icon-pixbuf:
895 * A pixbuf to use as the primary icon for the entry.
899 g_object_class_install_property (gobject_class,
901 g_param_spec_object ("primary-icon-pixbuf",
902 P_("Primary pixbuf"),
903 P_("Primary pixbuf for the entry"),
905 GTK_PARAM_READWRITE));
908 * GtkEntry:secondary-icon-pixbuf:
910 * An pixbuf to use as the secondary icon for the entry.
914 g_object_class_install_property (gobject_class,
915 PROP_PIXBUF_SECONDARY,
916 g_param_spec_object ("secondary-icon-pixbuf",
917 P_("Secondary pixbuf"),
918 P_("Secondary pixbuf for the entry"),
920 GTK_PARAM_READWRITE));
923 * GtkEntry:primary-icon-stock:
925 * The stock id to use for the primary icon for the entry.
929 g_object_class_install_property (gobject_class,
931 g_param_spec_string ("primary-icon-stock",
932 P_("Primary stock ID"),
933 P_("Stock ID for primary icon"),
935 GTK_PARAM_READWRITE));
938 * GtkEntry:secondary-icon-stock:
940 * The stock id to use for the secondary icon for the entry.
944 g_object_class_install_property (gobject_class,
945 PROP_STOCK_SECONDARY,
946 g_param_spec_string ("secondary-icon-stock",
947 P_("Secondary stock ID"),
948 P_("Stock ID for secondary icon"),
950 GTK_PARAM_READWRITE));
953 * GtkEntry:primary-icon-name:
955 * The icon name to use for the primary icon for the entry.
959 g_object_class_install_property (gobject_class,
960 PROP_ICON_NAME_PRIMARY,
961 g_param_spec_string ("primary-icon-name",
962 P_("Primary icon name"),
963 P_("Icon name for primary icon"),
965 GTK_PARAM_READWRITE));
968 * GtkEntry:secondary-icon-name:
970 * The icon name to use for the secondary icon for the entry.
974 g_object_class_install_property (gobject_class,
975 PROP_ICON_NAME_SECONDARY,
976 g_param_spec_string ("secondary-icon-name",
977 P_("Secondary icon name"),
978 P_("Icon name for secondary icon"),
980 GTK_PARAM_READWRITE));
983 * GtkEntry:primary-icon-gicon:
985 * The #GIcon to use for the primary icon for the entry.
989 g_object_class_install_property (gobject_class,
991 g_param_spec_object ("primary-icon-gicon",
993 P_("GIcon for primary icon"),
995 GTK_PARAM_READWRITE));
998 * GtkEntry:secondary-icon-gicon:
1000 * The #GIcon to use for the secondary icon for the entry.
1004 g_object_class_install_property (gobject_class,
1005 PROP_GICON_SECONDARY,
1006 g_param_spec_object ("secondary-icon-gicon",
1007 P_("Secondary GIcon"),
1008 P_("GIcon for secondary icon"),
1010 GTK_PARAM_READWRITE));
1013 * GtkEntry:primary-icon-storage-type:
1015 * The representation which is used for the primary icon of the entry.
1019 g_object_class_install_property (gobject_class,
1020 PROP_STORAGE_TYPE_PRIMARY,
1021 g_param_spec_enum ("primary-icon-storage-type",
1022 P_("Primary storage type"),
1023 P_("The representation being used for primary icon"),
1024 GTK_TYPE_IMAGE_TYPE,
1026 GTK_PARAM_READABLE));
1029 * GtkEntry:secondary-icon-storage-type:
1031 * The representation which is used for the secondary icon of the entry.
1035 g_object_class_install_property (gobject_class,
1036 PROP_STORAGE_TYPE_SECONDARY,
1037 g_param_spec_enum ("secondary-icon-storage-type",
1038 P_("Secondary storage type"),
1039 P_("The representation being used for secondary icon"),
1040 GTK_TYPE_IMAGE_TYPE,
1042 GTK_PARAM_READABLE));
1045 * GtkEntry:primary-icon-activatable:
1047 * Whether the primary icon is activatable.
1049 * GTK+ emits the #GtkEntry::icon-press and #GtkEntry::icon-release
1050 * signals only on sensitive, activatable icons.
1052 * Sensitive, but non-activatable icons can be used for purely
1053 * informational purposes.
1057 g_object_class_install_property (gobject_class,
1058 PROP_ACTIVATABLE_PRIMARY,
1059 g_param_spec_boolean ("primary-icon-activatable",
1060 P_("Primary icon activatable"),
1061 P_("Whether the primary icon is activatable"),
1063 GTK_PARAM_READWRITE));
1066 * GtkEntry:secondary-icon-activatable:
1068 * Whether the secondary icon is activatable.
1070 * GTK+ emits the #GtkEntry::icon-press and #GtkEntry::icon-release
1071 * signals only on sensitive, activatable icons.
1073 * Sensitive, but non-activatable icons can be used for purely
1074 * informational purposes.
1078 g_object_class_install_property (gobject_class,
1079 PROP_ACTIVATABLE_SECONDARY,
1080 g_param_spec_boolean ("secondary-icon-activatable",
1081 P_("Secondary icon activatable"),
1082 P_("Whether the secondary icon is activatable"),
1084 GTK_PARAM_READWRITE));
1088 * GtkEntry:primary-icon-sensitive:
1090 * Whether the primary icon is sensitive.
1092 * An insensitive icon appears grayed out. GTK+ does not emit the
1093 * #GtkEntry::icon-press and #GtkEntry::icon-release signals and
1094 * does not allow DND from insensitive icons.
1096 * An icon should be set insensitive if the action that would trigger
1097 * when clicked is currently not available.
1101 g_object_class_install_property (gobject_class,
1102 PROP_SENSITIVE_PRIMARY,
1103 g_param_spec_boolean ("primary-icon-sensitive",
1104 P_("Primary icon sensitive"),
1105 P_("Whether the primary icon is sensitive"),
1107 GTK_PARAM_READWRITE));
1110 * GtkEntry:secondary-icon-sensitive:
1112 * Whether the secondary icon is sensitive.
1114 * An insensitive icon appears grayed out. GTK+ does not emit the
1115 * #GtkEntry::icon-press and #GtkEntry::icon-release signals and
1116 * does not allow DND from insensitive icons.
1118 * An icon should be set insensitive if the action that would trigger
1119 * when clicked is currently not available.
1123 g_object_class_install_property (gobject_class,
1124 PROP_SENSITIVE_SECONDARY,
1125 g_param_spec_boolean ("secondary-icon-sensitive",
1126 P_("Secondary icon sensitive"),
1127 P_("Whether the secondary icon is sensitive"),
1129 GTK_PARAM_READWRITE));
1132 * GtkEntry:primary-icon-tooltip-text:
1134 * The contents of the tooltip on the primary icon.
1136 * Also see gtk_entry_set_icon_tooltip_text().
1140 g_object_class_install_property (gobject_class,
1141 PROP_TOOLTIP_TEXT_PRIMARY,
1142 g_param_spec_string ("primary-icon-tooltip-text",
1143 P_("Primary icon tooltip text"),
1144 P_("The contents of the tooltip on the primary icon"),
1146 GTK_PARAM_READWRITE));
1149 * GtkEntry:secondary-icon-tooltip-text:
1151 * The contents of the tooltip on the secondary icon.
1153 * Also see gtk_entry_set_icon_tooltip_text().
1157 g_object_class_install_property (gobject_class,
1158 PROP_TOOLTIP_TEXT_SECONDARY,
1159 g_param_spec_string ("secondary-icon-tooltip-text",
1160 P_("Secondary icon tooltip text"),
1161 P_("The contents of the tooltip on the secondary icon"),
1163 GTK_PARAM_READWRITE));
1166 * GtkEntry:primary-icon-tooltip-markup:
1168 * The contents of the tooltip on the primary icon, which is marked up
1169 * with the <link linkend="PangoMarkupFormat">Pango text markup
1172 * Also see gtk_entry_set_icon_tooltip_markup().
1176 g_object_class_install_property (gobject_class,
1177 PROP_TOOLTIP_MARKUP_PRIMARY,
1178 g_param_spec_string ("primary-icon-tooltip-markup",
1179 P_("Primary icon tooltip markup"),
1180 P_("The contents of the tooltip on the primary icon"),
1182 GTK_PARAM_READWRITE));
1185 * GtkEntry:secondary-icon-tooltip-markup:
1187 * The contents of the tooltip on the secondary icon, which is marked up
1188 * with the <link linkend="PangoMarkupFormat">Pango text markup
1191 * Also see gtk_entry_set_icon_tooltip_markup().
1195 g_object_class_install_property (gobject_class,
1196 PROP_TOOLTIP_MARKUP_SECONDARY,
1197 g_param_spec_string ("secondary-icon-tooltip-markup",
1198 P_("Secondary icon tooltip markup"),
1199 P_("The contents of the tooltip on the secondary icon"),
1201 GTK_PARAM_READWRITE));
1204 * GtkEntry:im-module:
1206 * Which IM (input method) module should be used for this entry.
1207 * See #GtkIMContext.
1209 * Setting this to a non-%NULL value overrides the
1210 * system-wide IM module setting. See the GtkSettings
1211 * #GtkSettings:gtk-im-module property.
1215 g_object_class_install_property (gobject_class,
1217 g_param_spec_string ("im-module",
1219 P_("Which IM module should be used"),
1221 GTK_PARAM_READWRITE));
1224 * GtkEntry:icon-prelight:
1226 * The prelight style property determines whether activatable
1227 * icons prelight on mouseover.
1231 gtk_widget_class_install_style_property (widget_class,
1232 g_param_spec_boolean ("icon-prelight",
1233 P_("Icon Prelight"),
1234 P_("Whether activatable icons should prelight when hovered"),
1236 GTK_PARAM_READABLE));
1239 * GtkEntry:progress-border:
1241 * The border around the progress bar in the entry.
1245 gtk_widget_class_install_style_property (widget_class,
1246 g_param_spec_boxed ("progress-border",
1247 P_("Progress Border"),
1248 P_("Border around the progress bar"),
1250 GTK_PARAM_READABLE));
1253 * GtkEntry:invisible-char:
1255 * The invisible character is used when masking entry contents (in
1256 * \"password mode\")"). When it is not explicitly set with the
1257 * #GtkEntry::invisible-char property, GTK+ determines the character
1258 * to use from a list of possible candidates, depending on availability
1259 * in the current font.
1261 * This style property allows the theme to prepend a character
1262 * to the list of candidates.
1266 gtk_widget_class_install_style_property (widget_class,
1267 g_param_spec_unichar ("invisible-char",
1268 P_("Invisible character"),
1269 P_("The character to use when masking entry contents (in \"password mode\")"),
1271 GTK_PARAM_READABLE));
1274 * GtkEntry::populate-popup:
1275 * @entry: The entry on which the signal is emitted
1276 * @menu: the menu that is being populated
1278 * The ::populate-popup signal gets emitted before showing the
1279 * context menu of the entry.
1281 * If you need to add items to the context menu, connect
1282 * to this signal and append your menuitems to the @menu.
1284 signals[POPULATE_POPUP] =
1285 g_signal_new (I_("populate-popup"),
1286 G_OBJECT_CLASS_TYPE (gobject_class),
1288 G_STRUCT_OFFSET (GtkEntryClass, populate_popup),
1290 _gtk_marshal_VOID__OBJECT,
1294 /* Action signals */
1297 * GtkEntry::activate:
1298 * @entry: The entry on which the signal is emitted
1300 * A <link linkend="keybinding-signals">keybinding signal</link>
1301 * which gets emitted when the user activates the entry.
1303 * Applications should not connect to it, but may emit it with
1304 * g_signal_emit_by_name() if they need to control activation
1307 * The default bindings for this signal are all forms of the Enter key.
1310 g_signal_new (I_("activate"),
1311 G_OBJECT_CLASS_TYPE (gobject_class),
1312 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1313 G_STRUCT_OFFSET (GtkEntryClass, activate),
1315 _gtk_marshal_VOID__VOID,
1317 widget_class->activate_signal = signals[ACTIVATE];
1320 * GtkEntry::move-cursor:
1321 * @entry: the object which received the signal
1322 * @step: the granularity of the move, as a #GtkMovementStep
1323 * @count: the number of @step units to move
1324 * @extend_selection: %TRUE if the move should extend the selection
1326 * The ::move-cursor signal is a
1327 * <link linkend="keybinding-signals">keybinding signal</link>
1328 * which gets emitted when the user initiates a cursor movement.
1329 * If the cursor is not visible in @entry, this signal causes
1330 * the viewport to be moved instead.
1332 * Applications should not connect to it, but may emit it with
1333 * g_signal_emit_by_name() if they need to control the cursor
1336 * The default bindings for this signal come in two variants,
1337 * the variant with the Shift modifier extends the selection,
1338 * the variant without the Shift modifer does not.
1339 * There are too many key combinations to list them all here.
1341 * <listitem>Arrow keys move by individual characters/lines</listitem>
1342 * <listitem>Ctrl-arrow key combinations move by words/paragraphs</listitem>
1343 * <listitem>Home/End keys move to the ends of the buffer</listitem>
1346 signals[MOVE_CURSOR] =
1347 g_signal_new (I_("move-cursor"),
1348 G_OBJECT_CLASS_TYPE (gobject_class),
1349 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1350 G_STRUCT_OFFSET (GtkEntryClass, move_cursor),
1352 _gtk_marshal_VOID__ENUM_INT_BOOLEAN,
1354 GTK_TYPE_MOVEMENT_STEP,
1359 * GtkEntry::insert-at-cursor:
1360 * @entry: the object which received the signal
1361 * @string: the string to insert
1363 * The ::insert-at-cursor signal is a
1364 * <link linkend="keybinding-signals">keybinding signal</link>
1365 * which gets emitted when the user initiates the insertion of a
1366 * fixed string at the cursor.
1368 * This signal has no default bindings.
1370 signals[INSERT_AT_CURSOR] =
1371 g_signal_new (I_("insert-at-cursor"),
1372 G_OBJECT_CLASS_TYPE (gobject_class),
1373 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1374 G_STRUCT_OFFSET (GtkEntryClass, insert_at_cursor),
1376 _gtk_marshal_VOID__STRING,
1381 * GtkEntry::delete-from-cursor:
1382 * @entry: the object which received the signal
1383 * @type: the granularity of the deletion, as a #GtkDeleteType
1384 * @count: the number of @type units to delete
1386 * The ::delete-from-cursor signal is a
1387 * <link linkend="keybinding-signals">keybinding signal</link>
1388 * which gets emitted when the user initiates a text deletion.
1390 * If the @type is %GTK_DELETE_CHARS, GTK+ deletes the selection
1391 * if there is one, otherwise it deletes the requested number
1394 * The default bindings for this signal are
1395 * Delete for deleting a character and Ctrl-Delete for
1398 signals[DELETE_FROM_CURSOR] =
1399 g_signal_new (I_("delete-from-cursor"),
1400 G_OBJECT_CLASS_TYPE (gobject_class),
1401 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1402 G_STRUCT_OFFSET (GtkEntryClass, delete_from_cursor),
1404 _gtk_marshal_VOID__ENUM_INT,
1406 GTK_TYPE_DELETE_TYPE,
1410 * GtkEntry::backspace:
1411 * @entry: the object which received the signal
1413 * The ::backspace signal is a
1414 * <link linkend="keybinding-signals">keybinding signal</link>
1415 * which gets emitted when the user asks for it.
1417 * The default bindings for this signal are
1418 * Backspace and Shift-Backspace.
1420 signals[BACKSPACE] =
1421 g_signal_new (I_("backspace"),
1422 G_OBJECT_CLASS_TYPE (gobject_class),
1423 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1424 G_STRUCT_OFFSET (GtkEntryClass, backspace),
1426 _gtk_marshal_VOID__VOID,
1430 * GtkEntry::cut-clipboard:
1431 * @entry: the object which received the signal
1433 * The ::cut-clipboard signal is a
1434 * <link linkend="keybinding-signals">keybinding signal</link>
1435 * which gets emitted to cut the selection to the clipboard.
1437 * The default bindings for this signal are
1438 * Ctrl-x and Shift-Delete.
1440 signals[CUT_CLIPBOARD] =
1441 g_signal_new (I_("cut-clipboard"),
1442 G_OBJECT_CLASS_TYPE (gobject_class),
1443 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1444 G_STRUCT_OFFSET (GtkEntryClass, cut_clipboard),
1446 _gtk_marshal_VOID__VOID,
1450 * GtkEntry::copy-clipboard:
1451 * @entry: the object which received the signal
1453 * The ::copy-clipboard signal is a
1454 * <link linkend="keybinding-signals">keybinding signal</link>
1455 * which gets emitted to copy the selection to the clipboard.
1457 * The default bindings for this signal are
1458 * Ctrl-c and Ctrl-Insert.
1460 signals[COPY_CLIPBOARD] =
1461 g_signal_new (I_("copy-clipboard"),
1462 G_OBJECT_CLASS_TYPE (gobject_class),
1463 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1464 G_STRUCT_OFFSET (GtkEntryClass, copy_clipboard),
1466 _gtk_marshal_VOID__VOID,
1470 * GtkEntry::paste-clipboard:
1471 * @entry: the object which received the signal
1473 * The ::paste-clipboard signal is a
1474 * <link linkend="keybinding-signals">keybinding signal</link>
1475 * which gets emitted to paste the contents of the clipboard
1476 * into the text view.
1478 * The default bindings for this signal are
1479 * Ctrl-v and Shift-Insert.
1481 signals[PASTE_CLIPBOARD] =
1482 g_signal_new (I_("paste-clipboard"),
1483 G_OBJECT_CLASS_TYPE (gobject_class),
1484 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1485 G_STRUCT_OFFSET (GtkEntryClass, paste_clipboard),
1487 _gtk_marshal_VOID__VOID,
1491 * GtkEntry::toggle-overwrite:
1492 * @entry: the object which received the signal
1494 * The ::toggle-overwrite signal is a
1495 * <link linkend="keybinding-signals">keybinding signal</link>
1496 * which gets emitted to toggle the overwrite mode of the entry.
1498 * The default bindings for this signal is Insert.
1500 signals[TOGGLE_OVERWRITE] =
1501 g_signal_new (I_("toggle-overwrite"),
1502 G_OBJECT_CLASS_TYPE (gobject_class),
1503 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1504 G_STRUCT_OFFSET (GtkEntryClass, toggle_overwrite),
1506 _gtk_marshal_VOID__VOID,
1510 * GtkEntry::icon-press:
1511 * @entry: The entry on which the signal is emitted
1512 * @icon_pos: The position of the clicked icon
1513 * @event: the button press event
1515 * The ::icon-press signal is emitted when an activatable icon
1520 signals[ICON_PRESS] =
1521 g_signal_new (I_("icon-press"),
1522 G_TYPE_FROM_CLASS (gobject_class),
1526 _gtk_marshal_VOID__ENUM_BOXED,
1528 GTK_TYPE_ENTRY_ICON_POSITION,
1529 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1532 * GtkEntry::icon-release:
1533 * @entry: The entry on which the signal is emitted
1534 * @icon_pos: The position of the clicked icon
1535 * @event: the button release event
1537 * The ::icon-release signal is emitted on the button release from a
1538 * mouse click over an activatable icon.
1542 signals[ICON_RELEASE] =
1543 g_signal_new (I_("icon-release"),
1544 G_TYPE_FROM_CLASS (gobject_class),
1548 _gtk_marshal_VOID__ENUM_BOXED,
1550 GTK_TYPE_ENTRY_ICON_POSITION,
1551 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1558 binding_set = gtk_binding_set_by_class (class);
1560 /* Moving the insertion point */
1561 add_move_binding (binding_set, GDK_Right, 0,
1562 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1564 add_move_binding (binding_set, GDK_Left, 0,
1565 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1567 add_move_binding (binding_set, GDK_KP_Right, 0,
1568 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1570 add_move_binding (binding_set, GDK_KP_Left, 0,
1571 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1573 add_move_binding (binding_set, GDK_Right, GDK_CONTROL_MASK,
1574 GTK_MOVEMENT_WORDS, 1);
1576 add_move_binding (binding_set, GDK_Left, GDK_CONTROL_MASK,
1577 GTK_MOVEMENT_WORDS, -1);
1579 add_move_binding (binding_set, GDK_KP_Right, GDK_CONTROL_MASK,
1580 GTK_MOVEMENT_WORDS, 1);
1582 add_move_binding (binding_set, GDK_KP_Left, GDK_CONTROL_MASK,
1583 GTK_MOVEMENT_WORDS, -1);
1585 add_move_binding (binding_set, GDK_Home, 0,
1586 GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
1588 add_move_binding (binding_set, GDK_End, 0,
1589 GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
1591 add_move_binding (binding_set, GDK_KP_Home, 0,
1592 GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
1594 add_move_binding (binding_set, GDK_KP_End, 0,
1595 GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
1597 add_move_binding (binding_set, GDK_Home, GDK_CONTROL_MASK,
1598 GTK_MOVEMENT_BUFFER_ENDS, -1);
1600 add_move_binding (binding_set, GDK_End, GDK_CONTROL_MASK,
1601 GTK_MOVEMENT_BUFFER_ENDS, 1);
1603 add_move_binding (binding_set, GDK_KP_Home, GDK_CONTROL_MASK,
1604 GTK_MOVEMENT_BUFFER_ENDS, -1);
1606 add_move_binding (binding_set, GDK_KP_End, GDK_CONTROL_MASK,
1607 GTK_MOVEMENT_BUFFER_ENDS, 1);
1611 gtk_binding_entry_add_signal (binding_set, GDK_a, GDK_CONTROL_MASK,
1613 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1615 G_TYPE_BOOLEAN, FALSE);
1616 gtk_binding_entry_add_signal (binding_set, GDK_a, GDK_CONTROL_MASK,
1618 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1620 G_TYPE_BOOLEAN, TRUE);
1622 gtk_binding_entry_add_signal (binding_set, GDK_slash, GDK_CONTROL_MASK,
1624 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1626 G_TYPE_BOOLEAN, FALSE);
1627 gtk_binding_entry_add_signal (binding_set, GDK_slash, GDK_CONTROL_MASK,
1629 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1631 G_TYPE_BOOLEAN, TRUE);
1634 gtk_binding_entry_add_signal (binding_set, GDK_backslash, GDK_CONTROL_MASK,
1636 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_VISUAL_POSITIONS,
1638 G_TYPE_BOOLEAN, FALSE);
1639 gtk_binding_entry_add_signal (binding_set, GDK_a, GDK_SHIFT_MASK | GDK_CONTROL_MASK,
1641 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_VISUAL_POSITIONS,
1643 G_TYPE_BOOLEAN, FALSE);
1647 gtk_binding_entry_add_signal (binding_set, GDK_Return, 0,
1649 gtk_binding_entry_add_signal (binding_set, GDK_ISO_Enter, 0,
1651 gtk_binding_entry_add_signal (binding_set, GDK_KP_Enter, 0,
1655 gtk_binding_entry_add_signal (binding_set, GDK_Delete, 0,
1656 "delete-from-cursor", 2,
1657 G_TYPE_ENUM, GTK_DELETE_CHARS,
1660 gtk_binding_entry_add_signal (binding_set, GDK_KP_Delete, 0,
1661 "delete-from-cursor", 2,
1662 G_TYPE_ENUM, GTK_DELETE_CHARS,
1665 gtk_binding_entry_add_signal (binding_set, GDK_BackSpace, 0,
1668 /* Make this do the same as Backspace, to help with mis-typing */
1669 gtk_binding_entry_add_signal (binding_set, GDK_BackSpace, GDK_SHIFT_MASK,
1672 gtk_binding_entry_add_signal (binding_set, GDK_Delete, GDK_CONTROL_MASK,
1673 "delete-from-cursor", 2,
1674 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1677 gtk_binding_entry_add_signal (binding_set, GDK_KP_Delete, GDK_CONTROL_MASK,
1678 "delete-from-cursor", 2,
1679 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1682 gtk_binding_entry_add_signal (binding_set, GDK_BackSpace, GDK_CONTROL_MASK,
1683 "delete-from-cursor", 2,
1684 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1687 /* Cut/copy/paste */
1689 gtk_binding_entry_add_signal (binding_set, GDK_x, GDK_CONTROL_MASK,
1690 "cut-clipboard", 0);
1691 gtk_binding_entry_add_signal (binding_set, GDK_c, GDK_CONTROL_MASK,
1692 "copy-clipboard", 0);
1693 gtk_binding_entry_add_signal (binding_set, GDK_v, GDK_CONTROL_MASK,
1694 "paste-clipboard", 0);
1696 gtk_binding_entry_add_signal (binding_set, GDK_Delete, GDK_SHIFT_MASK,
1697 "cut-clipboard", 0);
1698 gtk_binding_entry_add_signal (binding_set, GDK_Insert, GDK_CONTROL_MASK,
1699 "copy-clipboard", 0);
1700 gtk_binding_entry_add_signal (binding_set, GDK_Insert, GDK_SHIFT_MASK,
1701 "paste-clipboard", 0);
1704 gtk_binding_entry_add_signal (binding_set, GDK_Insert, 0,
1705 "toggle-overwrite", 0);
1706 gtk_binding_entry_add_signal (binding_set, GDK_KP_Insert, 0,
1707 "toggle-overwrite", 0);
1710 * GtkEntry:inner-border:
1712 * Sets the text area's border between the text and the frame.
1716 gtk_widget_class_install_style_property (widget_class,
1717 g_param_spec_boxed ("inner-border",
1719 P_("Border between text and frame."),
1721 GTK_PARAM_READABLE));
1724 * GtkEntry:state-hint:
1726 * Indicates whether to pass a proper widget state when
1727 * drawing the shadow and the widget background.
1731 gtk_widget_class_install_style_property (widget_class,
1732 g_param_spec_boolean ("state-hint",
1734 P_("Whether to pass a proper state when drawing shadow or background"),
1736 GTK_PARAM_READABLE));
1738 gtk_settings_install_property (g_param_spec_boolean ("gtk-entry-select-on-focus",
1739 P_("Select on focus"),
1740 P_("Whether to select the contents of an entry when it is focused"),
1742 GTK_PARAM_READWRITE));
1745 * GtkSettings:gtk-entry-password-hint-timeout:
1747 * How long to show the last input character in hidden
1748 * entries. This value is in milliseconds. 0 disables showing the
1749 * last char. 600 is a good value for enabling it.
1753 gtk_settings_install_property (g_param_spec_uint ("gtk-entry-password-hint-timeout",
1754 P_("Password Hint Timeout"),
1755 P_("How long to show the last input character in hidden entries"),
1757 GTK_PARAM_READWRITE));
1759 g_type_class_add_private (gobject_class, sizeof (GtkEntryPrivate));
1763 gtk_entry_editable_init (GtkEditableClass *iface)
1765 iface->do_insert_text = gtk_entry_insert_text;
1766 iface->do_delete_text = gtk_entry_delete_text;
1767 iface->insert_text = gtk_entry_real_insert_text;
1768 iface->delete_text = gtk_entry_real_delete_text;
1769 iface->get_chars = gtk_entry_get_chars;
1770 iface->set_selection_bounds = gtk_entry_set_selection_bounds;
1771 iface->get_selection_bounds = gtk_entry_get_selection_bounds;
1772 iface->set_position = gtk_entry_real_set_position;
1773 iface->get_position = gtk_entry_get_position;
1777 gtk_entry_cell_editable_init (GtkCellEditableIface *iface)
1779 iface->start_editing = gtk_entry_start_editing;
1783 gtk_entry_set_property (GObject *object,
1785 const GValue *value,
1788 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (object);
1789 GtkEntry *entry = GTK_ENTRY (object);
1794 gtk_entry_set_buffer (entry, g_value_get_object (value));
1799 gboolean new_value = g_value_get_boolean (value);
1801 if (new_value != entry->editable)
1805 _gtk_entry_reset_im_context (entry);
1806 if (GTK_WIDGET_HAS_FOCUS (entry))
1807 gtk_im_context_focus_out (entry->im_context);
1809 entry->preedit_length = 0;
1810 entry->preedit_cursor = 0;
1813 entry->editable = new_value;
1815 if (new_value && GTK_WIDGET_HAS_FOCUS (entry))
1816 gtk_im_context_focus_in (entry->im_context);
1818 gtk_entry_queue_draw (entry);
1823 case PROP_MAX_LENGTH:
1824 gtk_entry_set_max_length (entry, g_value_get_int (value));
1827 case PROP_VISIBILITY:
1828 gtk_entry_set_visibility (entry, g_value_get_boolean (value));
1831 case PROP_HAS_FRAME:
1832 gtk_entry_set_has_frame (entry, g_value_get_boolean (value));
1835 case PROP_INNER_BORDER:
1836 gtk_entry_set_inner_border (entry, g_value_get_boxed (value));
1839 case PROP_INVISIBLE_CHAR:
1840 gtk_entry_set_invisible_char (entry, g_value_get_uint (value));
1843 case PROP_ACTIVATES_DEFAULT:
1844 gtk_entry_set_activates_default (entry, g_value_get_boolean (value));
1847 case PROP_WIDTH_CHARS:
1848 gtk_entry_set_width_chars (entry, g_value_get_int (value));
1852 gtk_entry_set_text (entry, g_value_get_string (value));
1856 gtk_entry_set_alignment (entry, g_value_get_float (value));
1859 case PROP_TRUNCATE_MULTILINE:
1860 entry->truncate_multiline = g_value_get_boolean (value);
1863 case PROP_SHADOW_TYPE:
1864 priv->shadow_type = g_value_get_enum (value);
1867 case PROP_OVERWRITE_MODE:
1868 gtk_entry_set_overwrite_mode (entry, g_value_get_boolean (value));
1871 case PROP_INVISIBLE_CHAR_SET:
1872 if (g_value_get_boolean (value))
1873 priv->invisible_char_set = TRUE;
1875 gtk_entry_unset_invisible_char (entry);
1878 case PROP_CAPS_LOCK_WARNING:
1879 priv->caps_lock_warning = g_value_get_boolean (value);
1882 case PROP_PROGRESS_FRACTION:
1883 gtk_entry_set_progress_fraction (entry, g_value_get_double (value));
1886 case PROP_PROGRESS_PULSE_STEP:
1887 gtk_entry_set_progress_pulse_step (entry, g_value_get_double (value));
1890 case PROP_PIXBUF_PRIMARY:
1891 gtk_entry_set_icon_from_pixbuf (entry,
1892 GTK_ENTRY_ICON_PRIMARY,
1893 g_value_get_object (value));
1896 case PROP_PIXBUF_SECONDARY:
1897 gtk_entry_set_icon_from_pixbuf (entry,
1898 GTK_ENTRY_ICON_SECONDARY,
1899 g_value_get_object (value));
1902 case PROP_STOCK_PRIMARY:
1903 gtk_entry_set_icon_from_stock (entry,
1904 GTK_ENTRY_ICON_PRIMARY,
1905 g_value_get_string (value));
1908 case PROP_STOCK_SECONDARY:
1909 gtk_entry_set_icon_from_stock (entry,
1910 GTK_ENTRY_ICON_SECONDARY,
1911 g_value_get_string (value));
1914 case PROP_ICON_NAME_PRIMARY:
1915 gtk_entry_set_icon_from_icon_name (entry,
1916 GTK_ENTRY_ICON_PRIMARY,
1917 g_value_get_string (value));
1920 case PROP_ICON_NAME_SECONDARY:
1921 gtk_entry_set_icon_from_icon_name (entry,
1922 GTK_ENTRY_ICON_SECONDARY,
1923 g_value_get_string (value));
1926 case PROP_GICON_PRIMARY:
1927 gtk_entry_set_icon_from_gicon (entry,
1928 GTK_ENTRY_ICON_PRIMARY,
1929 g_value_get_object (value));
1932 case PROP_GICON_SECONDARY:
1933 gtk_entry_set_icon_from_gicon (entry,
1934 GTK_ENTRY_ICON_SECONDARY,
1935 g_value_get_object (value));
1938 case PROP_ACTIVATABLE_PRIMARY:
1939 gtk_entry_set_icon_activatable (entry,
1940 GTK_ENTRY_ICON_PRIMARY,
1941 g_value_get_boolean (value));
1944 case PROP_ACTIVATABLE_SECONDARY:
1945 gtk_entry_set_icon_activatable (entry,
1946 GTK_ENTRY_ICON_SECONDARY,
1947 g_value_get_boolean (value));
1950 case PROP_SENSITIVE_PRIMARY:
1951 gtk_entry_set_icon_sensitive (entry,
1952 GTK_ENTRY_ICON_PRIMARY,
1953 g_value_get_boolean (value));
1956 case PROP_SENSITIVE_SECONDARY:
1957 gtk_entry_set_icon_sensitive (entry,
1958 GTK_ENTRY_ICON_SECONDARY,
1959 g_value_get_boolean (value));
1962 case PROP_TOOLTIP_TEXT_PRIMARY:
1963 gtk_entry_set_icon_tooltip_text (entry,
1964 GTK_ENTRY_ICON_PRIMARY,
1965 g_value_get_string (value));
1968 case PROP_TOOLTIP_TEXT_SECONDARY:
1969 gtk_entry_set_icon_tooltip_text (entry,
1970 GTK_ENTRY_ICON_SECONDARY,
1971 g_value_get_string (value));
1974 case PROP_TOOLTIP_MARKUP_PRIMARY:
1975 gtk_entry_set_icon_tooltip_markup (entry,
1976 GTK_ENTRY_ICON_PRIMARY,
1977 g_value_get_string (value));
1980 case PROP_TOOLTIP_MARKUP_SECONDARY:
1981 gtk_entry_set_icon_tooltip_markup (entry,
1982 GTK_ENTRY_ICON_SECONDARY,
1983 g_value_get_string (value));
1986 case PROP_IM_MODULE:
1987 g_free (priv->im_module);
1988 priv->im_module = g_value_dup_string (value);
1989 if (GTK_IS_IM_MULTICONTEXT (entry->im_context))
1990 gtk_im_multicontext_set_context_id (GTK_IM_MULTICONTEXT (entry->im_context), priv->im_module);
1993 case PROP_EDITING_CANCELED:
1994 entry->editing_canceled = g_value_get_boolean (value);
1997 case PROP_SCROLL_OFFSET:
1998 case PROP_CURSOR_POSITION:
2000 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2006 gtk_entry_get_property (GObject *object,
2011 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (object);
2012 GtkEntry *entry = GTK_ENTRY (object);
2017 g_value_set_object (value, gtk_entry_get_buffer (entry));
2020 case PROP_CURSOR_POSITION:
2021 g_value_set_int (value, entry->current_pos);
2024 case PROP_SELECTION_BOUND:
2025 g_value_set_int (value, entry->selection_bound);
2029 g_value_set_boolean (value, entry->editable);
2032 case PROP_MAX_LENGTH:
2033 g_value_set_int (value, gtk_entry_buffer_get_max_length (get_buffer (entry)));
2036 case PROP_VISIBILITY:
2037 g_value_set_boolean (value, entry->visible);
2040 case PROP_HAS_FRAME:
2041 g_value_set_boolean (value, entry->has_frame);
2044 case PROP_INNER_BORDER:
2045 g_value_set_boxed (value, gtk_entry_get_inner_border (entry));
2048 case PROP_INVISIBLE_CHAR:
2049 g_value_set_uint (value, entry->invisible_char);
2052 case PROP_ACTIVATES_DEFAULT:
2053 g_value_set_boolean (value, entry->activates_default);
2056 case PROP_WIDTH_CHARS:
2057 g_value_set_int (value, entry->width_chars);
2060 case PROP_SCROLL_OFFSET:
2061 g_value_set_int (value, entry->scroll_offset);
2065 g_value_set_string (value, gtk_entry_get_text (entry));
2069 g_value_set_float (value, gtk_entry_get_alignment (entry));
2072 case PROP_TRUNCATE_MULTILINE:
2073 g_value_set_boolean (value, entry->truncate_multiline);
2076 case PROP_SHADOW_TYPE:
2077 g_value_set_enum (value, priv->shadow_type);
2080 case PROP_OVERWRITE_MODE:
2081 g_value_set_boolean (value, entry->overwrite_mode);
2084 case PROP_TEXT_LENGTH:
2085 g_value_set_uint (value, gtk_entry_buffer_get_length (get_buffer (entry)));
2088 case PROP_INVISIBLE_CHAR_SET:
2089 g_value_set_boolean (value, priv->invisible_char_set);
2092 case PROP_IM_MODULE:
2093 g_value_set_string (value, priv->im_module);
2096 case PROP_CAPS_LOCK_WARNING:
2097 g_value_set_boolean (value, priv->caps_lock_warning);
2100 case PROP_PROGRESS_FRACTION:
2101 g_value_set_double (value, priv->progress_fraction);
2104 case PROP_PROGRESS_PULSE_STEP:
2105 g_value_set_double (value, priv->progress_pulse_fraction);
2108 case PROP_PIXBUF_PRIMARY:
2109 g_value_set_object (value,
2110 gtk_entry_get_icon_pixbuf (entry,
2111 GTK_ENTRY_ICON_PRIMARY));
2114 case PROP_PIXBUF_SECONDARY:
2115 g_value_set_object (value,
2116 gtk_entry_get_icon_pixbuf (entry,
2117 GTK_ENTRY_ICON_SECONDARY));
2120 case PROP_STOCK_PRIMARY:
2121 g_value_set_string (value,
2122 gtk_entry_get_icon_stock (entry,
2123 GTK_ENTRY_ICON_PRIMARY));
2126 case PROP_STOCK_SECONDARY:
2127 g_value_set_string (value,
2128 gtk_entry_get_icon_stock (entry,
2129 GTK_ENTRY_ICON_SECONDARY));
2132 case PROP_ICON_NAME_PRIMARY:
2133 g_value_set_string (value,
2134 gtk_entry_get_icon_name (entry,
2135 GTK_ENTRY_ICON_PRIMARY));
2138 case PROP_ICON_NAME_SECONDARY:
2139 g_value_set_string (value,
2140 gtk_entry_get_icon_name (entry,
2141 GTK_ENTRY_ICON_SECONDARY));
2144 case PROP_GICON_PRIMARY:
2145 g_value_set_object (value,
2146 gtk_entry_get_icon_gicon (entry,
2147 GTK_ENTRY_ICON_PRIMARY));
2150 case PROP_GICON_SECONDARY:
2151 g_value_set_object (value,
2152 gtk_entry_get_icon_gicon (entry,
2153 GTK_ENTRY_ICON_SECONDARY));
2156 case PROP_STORAGE_TYPE_PRIMARY:
2157 g_value_set_enum (value,
2158 gtk_entry_get_icon_storage_type (entry,
2159 GTK_ENTRY_ICON_PRIMARY));
2162 case PROP_STORAGE_TYPE_SECONDARY:
2163 g_value_set_enum (value,
2164 gtk_entry_get_icon_storage_type (entry,
2165 GTK_ENTRY_ICON_SECONDARY));
2168 case PROP_ACTIVATABLE_PRIMARY:
2169 g_value_set_boolean (value,
2170 gtk_entry_get_icon_activatable (entry, GTK_ENTRY_ICON_PRIMARY));
2173 case PROP_ACTIVATABLE_SECONDARY:
2174 g_value_set_boolean (value,
2175 gtk_entry_get_icon_activatable (entry, GTK_ENTRY_ICON_SECONDARY));
2178 case PROP_SENSITIVE_PRIMARY:
2179 g_value_set_boolean (value,
2180 gtk_entry_get_icon_sensitive (entry, GTK_ENTRY_ICON_PRIMARY));
2183 case PROP_SENSITIVE_SECONDARY:
2184 g_value_set_boolean (value,
2185 gtk_entry_get_icon_sensitive (entry, GTK_ENTRY_ICON_SECONDARY));
2188 case PROP_TOOLTIP_TEXT_PRIMARY:
2189 g_value_take_string (value,
2190 gtk_entry_get_icon_tooltip_text (entry, GTK_ENTRY_ICON_PRIMARY));
2193 case PROP_TOOLTIP_TEXT_SECONDARY:
2194 g_value_take_string (value,
2195 gtk_entry_get_icon_tooltip_text (entry, GTK_ENTRY_ICON_SECONDARY));
2198 case PROP_TOOLTIP_MARKUP_PRIMARY:
2199 g_value_take_string (value,
2200 gtk_entry_get_icon_tooltip_markup (entry, GTK_ENTRY_ICON_PRIMARY));
2203 case PROP_TOOLTIP_MARKUP_SECONDARY:
2204 g_value_take_string (value,
2205 gtk_entry_get_icon_tooltip_markup (entry, GTK_ENTRY_ICON_SECONDARY));
2208 case PROP_EDITING_CANCELED:
2209 g_value_set_boolean (value,
2210 entry->editing_canceled);
2214 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2220 find_invisible_char (GtkWidget *widget)
2222 PangoLayout *layout;
2223 PangoAttrList *attr_list;
2225 gunichar invisible_chars [] = {
2227 0x25cf, /* BLACK CIRCLE */
2228 0x2022, /* BULLET */
2229 0x2731, /* HEAVY ASTERISK */
2230 0x273a /* SIXTEEN POINTED ASTERISK */
2234 gtk_widget_style_get (widget,
2235 "invisible-char", &invisible_chars[0],
2238 layout = gtk_widget_create_pango_layout (widget, NULL);
2240 attr_list = pango_attr_list_new ();
2241 pango_attr_list_insert (attr_list, pango_attr_fallback_new (FALSE));
2243 pango_layout_set_attributes (layout, attr_list);
2244 pango_attr_list_unref (attr_list);
2246 for (i = (invisible_chars[0] != 0 ? 0 : 1); i < G_N_ELEMENTS (invisible_chars); i++)
2248 gchar text[7] = { 0, };
2251 len = g_unichar_to_utf8 (invisible_chars[i], text);
2252 pango_layout_set_text (layout, text, len);
2254 count = pango_layout_get_unknown_glyphs_count (layout);
2258 g_object_unref (layout);
2259 return invisible_chars[i];
2263 g_object_unref (layout);
2269 gtk_entry_init (GtkEntry *entry)
2271 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2273 GTK_WIDGET_SET_FLAGS (entry, GTK_CAN_FOCUS);
2275 entry->editable = TRUE;
2276 entry->visible = TRUE;
2277 entry->invisible_char = find_invisible_char (GTK_WIDGET (entry));
2278 entry->dnd_position = -1;
2279 entry->width_chars = -1;
2280 entry->is_cell_renderer = FALSE;
2281 entry->editing_canceled = FALSE;
2282 entry->has_frame = TRUE;
2283 entry->truncate_multiline = FALSE;
2284 priv->shadow_type = GTK_SHADOW_IN;
2286 priv->caps_lock_warning = TRUE;
2287 priv->caps_lock_warning_shown = FALSE;
2288 priv->progress_fraction = 0.0;
2289 priv->progress_pulse_fraction = 0.1;
2291 gtk_drag_dest_set (GTK_WIDGET (entry),
2292 GTK_DEST_DEFAULT_HIGHLIGHT,
2294 GDK_ACTION_COPY | GDK_ACTION_MOVE);
2295 gtk_drag_dest_add_text_targets (GTK_WIDGET (entry));
2297 /* This object is completely private. No external entity can gain a reference
2298 * to it; so we create it here and destroy it in finalize().
2300 entry->im_context = gtk_im_multicontext_new ();
2302 g_signal_connect (entry->im_context, "commit",
2303 G_CALLBACK (gtk_entry_commit_cb), entry);
2304 g_signal_connect (entry->im_context, "preedit-changed",
2305 G_CALLBACK (gtk_entry_preedit_changed_cb), entry);
2306 g_signal_connect (entry->im_context, "retrieve-surrounding",
2307 G_CALLBACK (gtk_entry_retrieve_surrounding_cb), entry);
2308 g_signal_connect (entry->im_context, "delete-surrounding",
2309 G_CALLBACK (gtk_entry_delete_surrounding_cb), entry);
2314 get_icon_width (GtkEntry *entry,
2315 GtkEntryIconPosition icon_pos)
2317 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2318 EntryIconInfo *icon_info = priv->icons[icon_pos];
2320 GtkSettings *settings;
2321 gint menu_icon_width;
2323 if (!icon_info || icon_info->pixbuf == NULL)
2326 screen = gtk_widget_get_screen (GTK_WIDGET (entry));
2327 settings = gtk_settings_get_for_screen (screen);
2329 gtk_icon_size_lookup_for_settings (settings, GTK_ICON_SIZE_MENU,
2330 &menu_icon_width, NULL);
2332 return MAX (gdk_pixbuf_get_width (icon_info->pixbuf), menu_icon_width);
2336 get_icon_allocations (GtkEntry *entry,
2337 GtkAllocation *primary,
2338 GtkAllocation *secondary)
2341 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2342 gint x, y, width, height;
2344 get_text_area_size (entry, &x, &y, &width, &height);
2346 if (GTK_WIDGET_HAS_FOCUS (entry) && !priv->interior_focus)
2347 y += priv->focus_width;
2350 primary->height = height;
2351 primary->width = get_icon_width (entry, GTK_ENTRY_ICON_PRIMARY);
2352 if (primary->width > 0)
2353 primary->width += 2 * priv->icon_margin;
2356 secondary->height = height;
2357 secondary->width = get_icon_width (entry, GTK_ENTRY_ICON_SECONDARY);
2358 if (secondary->width > 0)
2359 secondary->width += 2 * priv->icon_margin;
2361 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
2363 primary->x = x + width - primary->width;
2369 secondary->x = x + width - secondary->width;
2375 begin_change (GtkEntry *entry)
2377 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2379 priv->change_count++;
2383 end_change (GtkEntry *entry)
2385 GtkEditable *editable = GTK_EDITABLE (entry);
2386 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2388 g_return_if_fail (priv->change_count > 0);
2390 priv->change_count--;
2392 if (priv->change_count == 0)
2394 if (priv->real_changed)
2396 g_signal_emit_by_name (editable, "changed");
2397 priv->real_changed = FALSE;
2403 emit_changed (GtkEntry *entry)
2405 GtkEditable *editable = GTK_EDITABLE (entry);
2406 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2408 if (priv->change_count == 0)
2409 g_signal_emit_by_name (editable, "changed");
2411 priv->real_changed = TRUE;
2415 gtk_entry_destroy (GtkObject *object)
2417 GtkEntry *entry = GTK_ENTRY (object);
2419 entry->current_pos = entry->selection_bound = 0;
2420 _gtk_entry_reset_im_context (entry);
2421 gtk_entry_reset_layout (entry);
2423 if (entry->blink_timeout)
2425 g_source_remove (entry->blink_timeout);
2426 entry->blink_timeout = 0;
2429 if (entry->recompute_idle)
2431 g_source_remove (entry->recompute_idle);
2432 entry->recompute_idle = 0;
2435 GTK_OBJECT_CLASS (gtk_entry_parent_class)->destroy (object);
2439 gtk_entry_dispose (GObject *object)
2441 GtkEntry *entry = GTK_ENTRY (object);
2443 gtk_entry_set_icon_from_pixbuf (entry, GTK_ENTRY_ICON_PRIMARY, NULL);
2444 gtk_entry_set_icon_tooltip_markup (entry, GTK_ENTRY_ICON_PRIMARY, NULL);
2445 gtk_entry_set_icon_from_pixbuf (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
2446 gtk_entry_set_icon_tooltip_markup (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
2448 G_OBJECT_CLASS (gtk_entry_parent_class)->dispose (object);
2452 gtk_entry_finalize (GObject *object)
2454 GtkEntry *entry = GTK_ENTRY (object);
2455 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2456 EntryIconInfo *icon_info = NULL;
2459 for (i = 0; i < MAX_ICONS; i++)
2461 if ((icon_info = priv->icons[i]) != NULL)
2463 if (icon_info->target_list != NULL)
2465 gtk_target_list_unref (icon_info->target_list);
2466 icon_info->target_list = NULL;
2469 g_slice_free (EntryIconInfo, icon_info);
2470 priv->icons[i] = NULL;
2474 gtk_entry_set_completion (entry, NULL);
2476 if (entry->cached_layout)
2477 g_object_unref (entry->cached_layout);
2479 g_object_unref (entry->im_context);
2481 if (entry->blink_timeout)
2482 g_source_remove (entry->blink_timeout);
2484 if (entry->recompute_idle)
2485 g_source_remove (entry->recompute_idle);
2487 g_free (priv->im_module);
2489 /* COMPAT: entry->text is a deprecated field, and the allocation
2490 is owned by the buffer. */
2492 gtk_entry_set_buffer (entry, NULL);
2494 G_OBJECT_CLASS (gtk_entry_parent_class)->finalize (object);
2498 gtk_entry_get_display_mode (GtkEntry *entry)
2500 GtkEntryPrivate *priv;
2502 return DISPLAY_NORMAL;
2503 priv = GTK_ENTRY_GET_PRIVATE (entry);
2504 if (entry->invisible_char == 0 && priv->invisible_char_set)
2505 return DISPLAY_BLANK;
2506 return DISPLAY_INVISIBLE;
2510 gtk_entry_get_display_text (GtkEntry *entry,
2514 GtkEntryPasswordHint *password_hint;
2515 GtkEntryPrivate *priv;
2516 gunichar invisible_char;
2526 priv = GTK_ENTRY_GET_PRIVATE (entry);
2527 text = gtk_entry_buffer_get_text (get_buffer (entry));
2528 length = gtk_entry_buffer_get_length (get_buffer (entry));
2532 if (start_pos > length)
2535 if (end_pos <= start_pos)
2536 return g_strdup ("");
2537 else if (entry->visible)
2539 start = g_utf8_offset_to_pointer (text, start_pos);
2540 end = g_utf8_offset_to_pointer (start, end_pos - start_pos);
2541 return g_strndup (start, end - start);
2545 str = g_string_sized_new (length * 2);
2547 /* Figure out what our invisible char is and encode it */
2548 if (!entry->invisible_char)
2549 invisible_char = priv->invisible_char_set ? ' ' : '*';
2551 invisible_char = entry->invisible_char;
2552 char_len = g_unichar_to_utf8 (invisible_char, char_str);
2555 * Add hidden characters for each character in the text
2556 * buffer. If there is a password hint, then keep that
2557 * character visible.
2560 password_hint = g_object_get_qdata (G_OBJECT (entry), quark_password_hint);
2561 for (i = start_pos; i < end_pos; ++i)
2563 if (password_hint && i == password_hint->position)
2565 start = g_utf8_offset_to_pointer (text, i);
2566 g_string_append_len (str, start, g_utf8_next_char (start) - start);
2570 g_string_append_len (str, char_str, char_len);
2574 return g_string_free (str, FALSE);
2580 update_cursors (GtkWidget *widget)
2582 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2583 EntryIconInfo *icon_info = NULL;
2584 GdkDisplay *display;
2588 for (i = 0; i < MAX_ICONS; i++)
2590 if ((icon_info = priv->icons[i]) != NULL)
2592 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
2593 gdk_window_show_unraised (icon_info->window);
2595 /* The icon windows are not children of the visible entry window,
2596 * thus we can't just inherit the xterm cursor. Slight complication
2597 * here is that for the entry, insensitive => arrow cursor, but for
2598 * an icon in a sensitive entry, insensitive => xterm cursor.
2600 if (GTK_WIDGET_IS_SENSITIVE (widget) &&
2601 (icon_info->insensitive ||
2602 (icon_info->nonactivatable && icon_info->target_list == NULL)))
2604 display = gtk_widget_get_display (widget);
2605 cursor = gdk_cursor_new_for_display (display, GDK_XTERM);
2606 gdk_window_set_cursor (icon_info->window, cursor);
2607 gdk_cursor_unref (cursor);
2611 gdk_window_set_cursor (icon_info->window, NULL);
2618 realize_icon_info (GtkWidget *widget,
2619 GtkEntryIconPosition icon_pos)
2621 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2622 EntryIconInfo *icon_info = priv->icons[icon_pos];
2623 GdkWindowAttr attributes;
2624 gint attributes_mask;
2626 g_return_if_fail (icon_info != NULL);
2630 attributes.width = 1;
2631 attributes.height = 1;
2632 attributes.window_type = GDK_WINDOW_CHILD;
2633 attributes.wclass = GDK_INPUT_OUTPUT;
2634 attributes.visual = gtk_widget_get_visual (widget);
2635 attributes.colormap = gtk_widget_get_colormap (widget);
2636 attributes.event_mask = gtk_widget_get_events (widget);
2637 attributes.event_mask |= (GDK_EXPOSURE_MASK |
2638 GDK_BUTTON_PRESS_MASK |
2639 GDK_BUTTON_RELEASE_MASK |
2640 GDK_BUTTON1_MOTION_MASK |
2641 GDK_BUTTON3_MOTION_MASK |
2642 GDK_POINTER_MOTION_HINT_MASK |
2643 GDK_POINTER_MOTION_MASK |
2644 GDK_ENTER_NOTIFY_MASK |
2645 GDK_LEAVE_NOTIFY_MASK);
2646 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
2648 icon_info->window = gdk_window_new (widget->window,
2651 gdk_window_set_user_data (icon_info->window, widget);
2652 gdk_window_set_background (icon_info->window,
2653 &widget->style->base[GTK_WIDGET_STATE (widget)]);
2655 gtk_widget_queue_resize (widget);
2658 static EntryIconInfo*
2659 construct_icon_info (GtkWidget *widget,
2660 GtkEntryIconPosition icon_pos)
2662 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2663 EntryIconInfo *icon_info;
2665 g_return_val_if_fail (priv->icons[icon_pos] == NULL, NULL);
2667 icon_info = g_slice_new0 (EntryIconInfo);
2668 priv->icons[icon_pos] = icon_info;
2670 if (GTK_WIDGET_REALIZED (widget))
2671 realize_icon_info (widget, icon_pos);
2677 gtk_entry_map (GtkWidget *widget)
2679 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2680 EntryIconInfo *icon_info = NULL;
2683 if (GTK_WIDGET_REALIZED (widget) && !GTK_WIDGET_MAPPED (widget))
2685 GTK_WIDGET_CLASS (gtk_entry_parent_class)->map (widget);
2687 for (i = 0; i < MAX_ICONS; i++)
2689 if ((icon_info = priv->icons[i]) != NULL)
2691 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
2692 gdk_window_show (icon_info->window);
2696 update_cursors (widget);
2701 gtk_entry_unmap (GtkWidget *widget)
2703 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2704 EntryIconInfo *icon_info = NULL;
2707 if (GTK_WIDGET_MAPPED (widget))
2709 for (i = 0; i < MAX_ICONS; i++)
2711 if ((icon_info = priv->icons[i]) != NULL)
2713 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
2714 gdk_window_hide (icon_info->window);
2718 GTK_WIDGET_CLASS (gtk_entry_parent_class)->unmap (widget);
2723 gtk_entry_realize (GtkWidget *widget)
2726 GtkEntryPrivate *priv;
2727 EntryIconInfo *icon_info;
2728 GdkWindowAttr attributes;
2729 gint attributes_mask;
2732 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
2733 entry = GTK_ENTRY (widget);
2734 priv = GTK_ENTRY_GET_PRIVATE (entry);
2736 attributes.window_type = GDK_WINDOW_CHILD;
2738 get_widget_window_size (entry, &attributes.x, &attributes.y, &attributes.width, &attributes.height);
2740 attributes.wclass = GDK_INPUT_OUTPUT;
2741 attributes.visual = gtk_widget_get_visual (widget);
2742 attributes.colormap = gtk_widget_get_colormap (widget);
2743 attributes.event_mask = gtk_widget_get_events (widget);
2744 attributes.event_mask |= (GDK_EXPOSURE_MASK |
2745 GDK_BUTTON_PRESS_MASK |
2746 GDK_BUTTON_RELEASE_MASK |
2747 GDK_BUTTON1_MOTION_MASK |
2748 GDK_BUTTON3_MOTION_MASK |
2749 GDK_POINTER_MOTION_HINT_MASK |
2750 GDK_POINTER_MOTION_MASK |
2751 GDK_ENTER_NOTIFY_MASK |
2752 GDK_LEAVE_NOTIFY_MASK);
2753 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
2755 widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, attributes_mask);
2756 gdk_window_set_user_data (widget->window, entry);
2758 get_text_area_size (entry, &attributes.x, &attributes.y, &attributes.width, &attributes.height);
2760 if (GTK_WIDGET_IS_SENSITIVE (widget))
2762 attributes.cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
2763 attributes_mask |= GDK_WA_CURSOR;
2766 entry->text_area = gdk_window_new (widget->window, &attributes, attributes_mask);
2768 gdk_window_set_user_data (entry->text_area, entry);
2770 if (attributes_mask & GDK_WA_CURSOR)
2771 gdk_cursor_unref (attributes.cursor);
2773 widget->style = gtk_style_attach (widget->style, widget->window);
2775 gdk_window_set_background (widget->window, &widget->style->base[GTK_WIDGET_STATE (widget)]);
2776 gdk_window_set_background (entry->text_area, &widget->style->base[GTK_WIDGET_STATE (widget)]);
2778 gdk_window_show (entry->text_area);
2780 gtk_im_context_set_client_window (entry->im_context, entry->text_area);
2782 gtk_entry_adjust_scroll (entry);
2783 gtk_entry_update_primary_selection (entry);
2786 /* If the icon positions are already setup, create their windows.
2787 * Otherwise if they don't exist yet, then construct_icon_info()
2788 * will create the windows once the widget is already realized.
2790 for (i = 0; i < MAX_ICONS; i++)
2792 if ((icon_info = priv->icons[i]) != NULL)
2794 if (icon_info->window == NULL)
2795 realize_icon_info (widget, i);
2801 gtk_entry_unrealize (GtkWidget *widget)
2803 GtkEntry *entry = GTK_ENTRY (widget);
2804 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2805 GtkClipboard *clipboard;
2806 EntryIconInfo *icon_info;
2809 gtk_entry_reset_layout (entry);
2811 gtk_im_context_set_client_window (entry->im_context, NULL);
2813 clipboard = gtk_widget_get_clipboard (widget, GDK_SELECTION_PRIMARY);
2814 if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (entry))
2815 gtk_clipboard_clear (clipboard);
2817 if (entry->text_area)
2819 gdk_window_set_user_data (entry->text_area, NULL);
2820 gdk_window_destroy (entry->text_area);
2821 entry->text_area = NULL;
2824 if (entry->popup_menu)
2826 gtk_widget_destroy (entry->popup_menu);
2827 entry->popup_menu = NULL;
2830 GTK_WIDGET_CLASS (gtk_entry_parent_class)->unrealize (widget);
2832 for (i = 0; i < MAX_ICONS; i++)
2834 if ((icon_info = priv->icons[i]) != NULL)
2836 if (icon_info->window != NULL)
2838 gdk_window_destroy (icon_info->window);
2839 icon_info->window = NULL;
2846 _gtk_entry_get_borders (GtkEntry *entry,
2850 GtkWidget *widget = GTK_WIDGET (entry);
2851 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2853 if (entry->has_frame)
2855 *xborder = widget->style->xthickness;
2856 *yborder = widget->style->ythickness;
2864 if (!priv->interior_focus)
2866 *xborder += priv->focus_width;
2867 *yborder += priv->focus_width;
2872 gtk_entry_size_request (GtkWidget *widget,
2873 GtkRequisition *requisition)
2875 GtkEntry *entry = GTK_ENTRY (widget);
2876 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2877 PangoFontMetrics *metrics;
2878 gint xborder, yborder;
2879 GtkBorder inner_border;
2880 PangoContext *context;
2881 int icon_widths = 0;
2884 gtk_widget_ensure_style (widget);
2885 context = gtk_widget_get_pango_context (widget);
2886 metrics = pango_context_get_metrics (context,
2887 widget->style->font_desc,
2888 pango_context_get_language (context));
2890 entry->ascent = pango_font_metrics_get_ascent (metrics);
2891 entry->descent = pango_font_metrics_get_descent (metrics);
2893 _gtk_entry_get_borders (entry, &xborder, &yborder);
2894 _gtk_entry_effective_inner_border (entry, &inner_border);
2896 if (entry->width_chars < 0)
2897 requisition->width = MIN_ENTRY_WIDTH + xborder * 2 + inner_border.left + inner_border.right;
2900 gint char_width = pango_font_metrics_get_approximate_char_width (metrics);
2901 gint digit_width = pango_font_metrics_get_approximate_digit_width (metrics);
2902 gint char_pixels = (MAX (char_width, digit_width) + PANGO_SCALE - 1) / PANGO_SCALE;
2904 requisition->width = char_pixels * entry->width_chars + xborder * 2 + inner_border.left + inner_border.right;
2907 requisition->height = PANGO_PIXELS (entry->ascent + entry->descent) + yborder * 2 + inner_border.top + inner_border.bottom;
2909 for (i = 0; i < MAX_ICONS; i++)
2911 icon_width = get_icon_width (entry, i);
2913 icon_widths += icon_width + 2 * priv->icon_margin;
2916 if (icon_widths > requisition->width)
2917 requisition->width += icon_widths;
2919 pango_font_metrics_unref (metrics);
2923 place_windows (GtkEntry *entry)
2925 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2926 gint x, y, width, height;
2927 GtkAllocation primary;
2928 GtkAllocation secondary;
2929 EntryIconInfo *icon_info = NULL;
2931 get_text_area_size (entry, &x, &y, &width, &height);
2932 get_icon_allocations (entry, &primary, &secondary);
2934 if (GTK_WIDGET_HAS_FOCUS (entry) && !priv->interior_focus)
2935 y += priv->focus_width;
2937 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
2938 x += secondary.width;
2941 width -= primary.width + secondary.width;
2943 if ((icon_info = priv->icons[GTK_ENTRY_ICON_PRIMARY]) != NULL)
2944 gdk_window_move_resize (icon_info->window,
2945 primary.x, primary.y,
2946 primary.width, primary.height);
2948 if ((icon_info = priv->icons[GTK_ENTRY_ICON_SECONDARY]) != NULL)
2949 gdk_window_move_resize (icon_info->window,
2950 secondary.x, secondary.y,
2951 secondary.width, secondary.height);
2953 gdk_window_move_resize (GTK_ENTRY (entry)->text_area, x, y, width, height);
2957 gtk_entry_get_text_area_size (GtkEntry *entry,
2963 GtkWidget *widget = GTK_WIDGET (entry);
2964 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2966 gint xborder, yborder;
2967 GtkRequisition requisition;
2969 gtk_widget_get_child_requisition (widget, &requisition);
2970 _gtk_entry_get_borders (entry, &xborder, &yborder);
2972 if (GTK_WIDGET_REALIZED (widget))
2973 gdk_drawable_get_size (widget->window, NULL, &frame_height);
2975 frame_height = requisition.height;
2977 if (GTK_WIDGET_HAS_FOCUS (widget) && !priv->interior_focus)
2978 frame_height -= 2 * priv->focus_width;
2984 *y = frame_height / 2 - (requisition.height - yborder * 2) / 2;
2987 *width = GTK_WIDGET (entry)->allocation.width - xborder * 2;
2990 *height = requisition.height - yborder * 2;
2994 get_text_area_size (GtkEntry *entry,
3000 GtkEntryClass *class;
3002 g_return_if_fail (GTK_IS_ENTRY (entry));
3004 class = GTK_ENTRY_GET_CLASS (entry);
3006 if (class->get_text_area_size)
3007 class->get_text_area_size (entry, x, y, width, height);
3012 get_widget_window_size (GtkEntry *entry,
3018 GtkRequisition requisition;
3019 GtkWidget *widget = GTK_WIDGET (entry);
3021 gtk_widget_get_child_requisition (widget, &requisition);
3024 *x = widget->allocation.x;
3028 if (entry->is_cell_renderer)
3029 *y = widget->allocation.y;
3031 *y = widget->allocation.y + (widget->allocation.height - requisition.height) / 2;
3035 *width = widget->allocation.width;
3039 if (entry->is_cell_renderer)
3040 *height = widget->allocation.height;
3042 *height = requisition.height;
3047 _gtk_entry_effective_inner_border (GtkEntry *entry,
3050 GtkBorder *tmp_border;
3052 tmp_border = g_object_get_qdata (G_OBJECT (entry), quark_inner_border);
3056 *border = *tmp_border;
3060 gtk_widget_style_get (GTK_WIDGET (entry), "inner-border", &tmp_border, NULL);
3064 *border = *tmp_border;
3065 gtk_border_free (tmp_border);
3069 *border = default_inner_border;
3073 gtk_entry_size_allocate (GtkWidget *widget,
3074 GtkAllocation *allocation)
3076 GtkEntry *entry = GTK_ENTRY (widget);
3078 widget->allocation = *allocation;
3080 if (GTK_WIDGET_REALIZED (widget))
3082 /* We call gtk_widget_get_child_requisition, since we want (for
3083 * backwards compatibility reasons) the realization here to
3084 * be affected by the usize of the entry, if set
3086 gint x, y, width, height;
3087 GtkEntryCompletion* completion;
3089 get_widget_window_size (entry, &x, &y, &width, &height);
3090 gdk_window_move_resize (widget->window, x, y, width, height);
3092 place_windows (entry);
3093 gtk_entry_recompute (entry);
3095 completion = gtk_entry_get_completion (entry);
3096 if (completion && GTK_WIDGET_MAPPED (completion->priv->popup_window))
3097 _gtk_entry_completion_resize_popup (completion);
3101 /* Kudos to the gnome-panel guys. */
3103 colorshift_pixbuf (GdkPixbuf *dest,
3108 gint width, height, has_alpha, src_rowstride, dest_rowstride;
3109 guchar *target_pixels;
3110 guchar *original_pixels;
3116 has_alpha = gdk_pixbuf_get_has_alpha (src);
3117 width = gdk_pixbuf_get_width (src);
3118 height = gdk_pixbuf_get_height (src);
3119 src_rowstride = gdk_pixbuf_get_rowstride (src);
3120 dest_rowstride = gdk_pixbuf_get_rowstride (dest);
3121 original_pixels = gdk_pixbuf_get_pixels (src);
3122 target_pixels = gdk_pixbuf_get_pixels (dest);
3124 for (i = 0; i < height; i++)
3126 pix_dest = target_pixels + i * dest_rowstride;
3127 pix_src = original_pixels + i * src_rowstride;
3129 for (j = 0; j < width; j++)
3136 *(pix_dest++) = CLAMP (val, 0, 255);
3139 *(pix_dest++) = CLAMP (val, 0, 255);
3142 *(pix_dest++) = CLAMP (val, 0, 255);
3145 *(pix_dest++) = *(pix_src++);
3151 should_prelight (GtkEntry *entry,
3152 GtkEntryIconPosition icon_pos)
3154 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3155 EntryIconInfo *icon_info = priv->icons[icon_pos];
3161 if (icon_info->nonactivatable && icon_info->target_list == NULL)
3164 if (icon_info->pressed)
3167 gtk_widget_style_get (GTK_WIDGET (entry),
3168 "icon-prelight", &prelight,
3175 draw_icon (GtkWidget *widget,
3176 GtkEntryIconPosition icon_pos)
3178 GtkEntry *entry = GTK_ENTRY (widget);
3179 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3180 EntryIconInfo *icon_info = priv->icons[icon_pos];
3182 gint x, y, width, height;
3187 gtk_entry_ensure_pixbuf (entry, icon_pos);
3189 if (icon_info->pixbuf == NULL)
3192 gdk_drawable_get_size (icon_info->window, &width, &height);
3194 /* size_allocate hasn't been called yet. These are the default values.
3196 if (width == 1 || height == 1)
3199 pixbuf = icon_info->pixbuf;
3200 g_object_ref (pixbuf);
3202 if (gdk_pixbuf_get_height (pixbuf) > height)
3204 GdkPixbuf *temp_pixbuf;
3207 scale = height - 2 * priv->icon_margin;
3208 temp_pixbuf = gdk_pixbuf_scale_simple (pixbuf, scale, scale,
3209 GDK_INTERP_BILINEAR);
3210 g_object_unref (pixbuf);
3211 pixbuf = temp_pixbuf;
3214 x = (width - gdk_pixbuf_get_width (pixbuf)) / 2;
3215 y = (height - gdk_pixbuf_get_height (pixbuf)) / 2;
3217 if (!GTK_WIDGET_IS_SENSITIVE (widget) ||
3218 icon_info->insensitive)
3220 GdkPixbuf *temp_pixbuf;
3222 temp_pixbuf = gdk_pixbuf_copy (pixbuf);
3223 gdk_pixbuf_saturate_and_pixelate (pixbuf,
3227 g_object_unref (pixbuf);
3228 pixbuf = temp_pixbuf;
3230 else if (icon_info->prelight)
3232 GdkPixbuf *temp_pixbuf;
3234 temp_pixbuf = gdk_pixbuf_copy (pixbuf);
3235 colorshift_pixbuf (temp_pixbuf, pixbuf, 30);
3236 g_object_unref (pixbuf);
3237 pixbuf = temp_pixbuf;
3240 gdk_draw_pixbuf (icon_info->window, widget->style->black_gc, pixbuf,
3242 GDK_RGB_DITHER_NORMAL, 0, 0);
3244 g_object_unref (pixbuf);
3249 gtk_entry_draw_frame (GtkWidget *widget,
3250 GdkEventExpose *event)
3252 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
3253 gint x = 0, y = 0, width, height;
3254 gboolean state_hint;
3257 gdk_drawable_get_size (widget->window, &width, &height);
3259 /* Fix a problem with some themes which assume that entry->text_area's
3260 * width equals widget->window's width */
3261 if (GTK_IS_SPIN_BUTTON (widget))
3263 gint xborder, yborder;
3265 gtk_entry_get_text_area_size (GTK_ENTRY (widget), &x, NULL, &width, NULL);
3266 _gtk_entry_get_borders (GTK_ENTRY (widget), &xborder, &yborder);
3269 width += xborder * 2;
3272 if (GTK_WIDGET_HAS_FOCUS (widget) && !priv->interior_focus)
3274 x += priv->focus_width;
3275 y += priv->focus_width;
3276 width -= 2 * priv->focus_width;
3277 height -= 2 * priv->focus_width;
3280 gtk_widget_style_get (widget, "state-hint", &state_hint, NULL);
3282 state = GTK_WIDGET_HAS_FOCUS (widget) ?
3283 GTK_STATE_ACTIVE : GTK_WIDGET_STATE (widget);
3285 state = GTK_STATE_NORMAL;
3287 gtk_paint_shadow (widget->style, widget->window,
3288 state, priv->shadow_type,
3289 &event->area, widget, "entry", x, y, width, height);
3292 gtk_entry_draw_progress (widget, event);
3294 if (GTK_WIDGET_HAS_FOCUS (widget) && !priv->interior_focus)
3296 x -= priv->focus_width;
3297 y -= priv->focus_width;
3298 width += 2 * priv->focus_width;
3299 height += 2 * priv->focus_width;
3301 gtk_paint_focus (widget->style, widget->window, GTK_WIDGET_STATE (widget),
3302 &event->area, widget, "entry",
3303 0, 0, width, height);
3308 gtk_entry_get_progress_border (GtkWidget *widget,
3309 GtkBorder *progress_border)
3311 GtkBorder *tmp_border;
3313 gtk_widget_style_get (widget, "progress-border", &tmp_border, NULL);
3316 *progress_border = *tmp_border;
3317 gtk_border_free (tmp_border);
3321 progress_border->left = widget->style->xthickness;
3322 progress_border->right = widget->style->xthickness;
3323 progress_border->top = widget->style->ythickness;
3324 progress_border->bottom = widget->style->ythickness;
3329 get_progress_area (GtkWidget *widget,
3335 GtkEntryPrivate *private = GTK_ENTRY_GET_PRIVATE (widget);
3336 GtkEntry *entry = GTK_ENTRY (widget);
3337 GtkBorder progress_border;
3339 gtk_entry_get_progress_border (widget, &progress_border);
3341 *x = progress_border.left;
3342 *y = progress_border.top;
3344 gdk_drawable_get_size (widget->window, width, height);
3346 *width -= progress_border.left + progress_border.right;
3347 *height -= progress_border.top + progress_border.bottom;
3349 if (GTK_WIDGET_HAS_FOCUS (widget) && !private->interior_focus)
3351 *x += private->focus_width;
3352 *y += private->focus_width;
3353 *width -= 2 * private->focus_width;
3354 *height -= 2 * private->focus_width;
3357 if (private->progress_pulse_mode)
3359 gdouble value = private->progress_pulse_current;
3361 *x += (gint) floor(value * (*width));
3362 *width = (gint) ceil(private->progress_pulse_fraction * (*width));
3364 else if (private->progress_fraction > 0)
3366 gdouble value = private->progress_fraction;
3368 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
3372 bar_width = floor(value * (*width) + 0.5);
3373 *x += *width - bar_width;
3378 *width = (gint) floor(value * (*width) + 0.5);
3389 gtk_entry_draw_progress (GtkWidget *widget,
3390 GdkEventExpose *event)
3392 gint x, y, width, height;
3395 get_progress_area (widget, &x, &y, &width, &height);
3397 if ((width <= 0) || (height <= 0))
3400 if (event->window != widget->window)
3404 gdk_window_get_position (event->window, &pos_x, &pos_y);
3410 state = GTK_STATE_SELECTED;
3411 if (!GTK_WIDGET_SENSITIVE (widget))
3412 state = GTK_STATE_INSENSITIVE;
3414 gtk_paint_box (widget->style, event->window,
3415 state, GTK_SHADOW_OUT,
3416 &event->area, widget, "entry-progress",
3422 gtk_entry_expose (GtkWidget *widget,
3423 GdkEventExpose *event)
3425 GtkEntry *entry = GTK_ENTRY (widget);
3426 gboolean state_hint;
3428 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3430 gtk_widget_style_get (widget, "state-hint", &state_hint, NULL);
3432 state = GTK_WIDGET_HAS_FOCUS (widget) ?
3433 GTK_STATE_ACTIVE : GTK_WIDGET_STATE (widget);
3435 state = GTK_WIDGET_STATE(widget);
3437 if (widget->window == event->window)
3439 gtk_entry_draw_frame (widget, event);
3441 else if (entry->text_area == event->window)
3445 gdk_drawable_get_size (entry->text_area, &width, &height);
3447 gtk_paint_flat_box (widget->style, entry->text_area,
3448 state, GTK_SHADOW_NONE,
3449 &event->area, widget, "entry_bg",
3450 0, 0, width, height);
3452 gtk_entry_draw_progress (widget, event);
3454 if (entry->dnd_position != -1)
3455 gtk_entry_draw_cursor (GTK_ENTRY (widget), CURSOR_DND);
3457 gtk_entry_draw_text (GTK_ENTRY (widget));
3459 /* When no text is being displayed at all, don't show the cursor */
3460 if (gtk_entry_get_display_mode (entry) != DISPLAY_BLANK &&
3461 GTK_WIDGET_HAS_FOCUS (widget) &&
3462 entry->selection_bound == entry->current_pos && entry->cursor_visible)
3463 gtk_entry_draw_cursor (GTK_ENTRY (widget), CURSOR_STANDARD);
3469 for (i = 0; i < MAX_ICONS; i++)
3471 EntryIconInfo *icon_info = priv->icons[i];
3473 if (icon_info != NULL && event->window == icon_info->window)
3477 gdk_drawable_get_size (icon_info->window, &width, &height);
3479 gtk_paint_flat_box (widget->style, icon_info->window,
3480 GTK_WIDGET_STATE (widget), GTK_SHADOW_NONE,
3481 NULL, widget, "entry_bg",
3482 0, 0, width, height);
3484 gtk_entry_draw_progress (widget, event);
3485 draw_icon (widget, i);
3496 gtk_entry_enter_notify (GtkWidget *widget,
3497 GdkEventCrossing *event)
3499 GtkEntry *entry = GTK_ENTRY (widget);
3500 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3503 for (i = 0; i < MAX_ICONS; i++)
3505 EntryIconInfo *icon_info = priv->icons[i];
3507 if (icon_info != NULL && event->window == icon_info->window)
3509 if (should_prelight (entry, i))
3511 icon_info->prelight = TRUE;
3512 gtk_widget_queue_draw (widget);
3523 gtk_entry_leave_notify (GtkWidget *widget,
3524 GdkEventCrossing *event)
3526 GtkEntry *entry = GTK_ENTRY (widget);
3527 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3530 for (i = 0; i < MAX_ICONS; i++)
3532 EntryIconInfo *icon_info = priv->icons[i];
3534 if (icon_info != NULL && event->window == icon_info->window)
3536 /* a grab means that we may never see the button release */
3537 if (event->mode == GDK_CROSSING_GRAB || event->mode == GDK_CROSSING_GTK_GRAB)
3538 icon_info->pressed = FALSE;
3540 if (should_prelight (entry, i))
3542 icon_info->prelight = FALSE;
3543 gtk_widget_queue_draw (widget);
3554 gtk_entry_get_pixel_ranges (GtkEntry *entry,
3558 gint start_char, end_char;
3560 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start_char, &end_char))
3562 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
3563 PangoLayoutLine *line = pango_layout_get_lines_readonly (layout)->data;
3564 const char *text = pango_layout_get_text (layout);
3565 gint start_index = g_utf8_offset_to_pointer (text, start_char) - text;
3566 gint end_index = g_utf8_offset_to_pointer (text, end_char) - text;
3567 gint real_n_ranges, i;
3569 pango_layout_line_get_x_ranges (line, start_index, end_index, ranges, &real_n_ranges);
3575 for (i = 0; i < real_n_ranges; ++i)
3577 r[2 * i + 1] = (r[2 * i + 1] - r[2 * i]) / PANGO_SCALE;
3578 r[2 * i] = r[2 * i] / PANGO_SCALE;
3583 *n_ranges = real_n_ranges;
3595 in_selection (GtkEntry *entry,
3600 gint retval = FALSE;
3602 gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
3604 for (i = 0; i < n_ranges; ++i)
3606 if (x >= ranges[2 * i] && x < ranges[2 * i] + ranges[2 * i + 1])
3618 gtk_entry_button_press (GtkWidget *widget,
3619 GdkEventButton *event)
3621 GtkEntry *entry = GTK_ENTRY (widget);
3622 GtkEditable *editable = GTK_EDITABLE (widget);
3623 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3624 EntryIconInfo *icon_info = NULL;
3626 gint sel_start, sel_end;
3629 for (i = 0; i < MAX_ICONS; i++)
3631 icon_info = priv->icons[i];
3633 if (!icon_info || icon_info->insensitive)
3636 if (event->window == icon_info->window)
3638 if (should_prelight (entry, i))
3640 icon_info->prelight = FALSE;
3641 gtk_widget_queue_draw (widget);
3644 priv->start_x = event->x;
3645 priv->start_y = event->y;
3646 icon_info->pressed = TRUE;
3648 if (!icon_info->nonactivatable)
3649 g_signal_emit (entry, signals[ICON_PRESS], 0, i, event);
3655 if (event->window != entry->text_area ||
3656 (entry->button && event->button != entry->button))
3659 gtk_entry_reset_blink_time (entry);
3661 entry->button = event->button;
3663 if (!GTK_WIDGET_HAS_FOCUS (widget))
3665 entry->in_click = TRUE;
3666 gtk_widget_grab_focus (widget);
3667 entry->in_click = FALSE;
3670 tmp_pos = gtk_entry_find_position (entry, event->x + entry->scroll_offset);
3672 if (event->button == 1)
3674 gboolean have_selection = gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end);
3676 entry->select_words = FALSE;
3677 entry->select_lines = FALSE;
3679 if (event->state & GDK_SHIFT_MASK)
3681 _gtk_entry_reset_im_context (entry);
3683 if (!have_selection) /* select from the current position to the clicked position */
3684 sel_start = sel_end = entry->current_pos;
3686 if (tmp_pos > sel_start && tmp_pos < sel_end)
3688 /* Truncate current selection, but keep it as big as possible */
3689 if (tmp_pos - sel_start > sel_end - tmp_pos)
3690 gtk_entry_set_positions (entry, sel_start, tmp_pos);
3692 gtk_entry_set_positions (entry, tmp_pos, sel_end);
3696 gboolean extend_to_left;
3699 /* Figure out what click selects and extend current selection */
3700 switch (event->type)
3702 case GDK_BUTTON_PRESS:
3703 gtk_entry_set_positions (entry, tmp_pos, tmp_pos);
3706 case GDK_2BUTTON_PRESS:
3707 entry->select_words = TRUE;
3708 gtk_entry_select_word (entry);
3711 case GDK_3BUTTON_PRESS:
3712 entry->select_lines = TRUE;
3713 gtk_entry_select_line (entry);
3720 start = MIN (entry->current_pos, entry->selection_bound);
3721 start = MIN (sel_start, start);
3723 end = MAX (entry->current_pos, entry->selection_bound);
3724 end = MAX (sel_end, end);
3726 if (tmp_pos == sel_start || tmp_pos == sel_end)
3727 extend_to_left = (tmp_pos == start);
3729 extend_to_left = (end == sel_end);
3732 gtk_entry_set_positions (entry, start, end);
3734 gtk_entry_set_positions (entry, end, start);
3737 else /* no shift key */
3738 switch (event->type)
3740 case GDK_BUTTON_PRESS:
3741 if (in_selection (entry, event->x + entry->scroll_offset))
3743 /* Click inside the selection - we'll either start a drag, or
3744 * clear the selection
3746 entry->in_drag = TRUE;
3747 entry->drag_start_x = event->x + entry->scroll_offset;
3748 entry->drag_start_y = event->y;
3751 gtk_editable_set_position (editable, tmp_pos);
3754 case GDK_2BUTTON_PRESS:
3755 /* We ALWAYS receive a GDK_BUTTON_PRESS immediately before
3756 * receiving a GDK_2BUTTON_PRESS so we need to reset
3757 * entry->in_drag which may have been set above
3759 entry->in_drag = FALSE;
3760 entry->select_words = TRUE;
3761 gtk_entry_select_word (entry);
3764 case GDK_3BUTTON_PRESS:
3765 /* We ALWAYS receive a GDK_BUTTON_PRESS immediately before
3766 * receiving a GDK_3BUTTON_PRESS so we need to reset
3767 * entry->in_drag which may have been set above
3769 entry->in_drag = FALSE;
3770 entry->select_lines = TRUE;
3771 gtk_entry_select_line (entry);
3780 else if (event->button == 2 && event->type == GDK_BUTTON_PRESS)
3782 if (entry->editable)
3784 priv->insert_pos = tmp_pos;
3785 gtk_entry_paste (entry, GDK_SELECTION_PRIMARY);
3790 gtk_widget_error_bell (widget);
3793 else if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
3795 gtk_entry_do_popup (entry, event);
3796 entry->button = 0; /* Don't wait for release, since the menu will gtk_grab_add */
3805 gtk_entry_button_release (GtkWidget *widget,
3806 GdkEventButton *event)
3808 GtkEntry *entry = GTK_ENTRY (widget);
3809 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
3810 EntryIconInfo *icon_info = NULL;
3813 for (i = 0; i < MAX_ICONS; i++)
3815 icon_info = priv->icons[i];
3817 if (!icon_info || icon_info->insensitive)
3820 if (event->window == icon_info->window)
3824 gdk_drawable_get_size (icon_info->window, &width, &height);
3826 icon_info->pressed = FALSE;
3828 if (should_prelight (entry, i) &&
3829 event->x >= 0 && event->y >= 0 &&
3830 event->x < width && event->y < height)
3832 icon_info->prelight = TRUE;
3833 gtk_widget_queue_draw (widget);
3836 if (!icon_info->nonactivatable)
3837 g_signal_emit (entry, signals[ICON_RELEASE], 0, i, event);
3843 if (event->window != entry->text_area || entry->button != event->button)
3848 gint tmp_pos = gtk_entry_find_position (entry, entry->drag_start_x);
3850 gtk_editable_set_position (GTK_EDITABLE (entry), tmp_pos);
3857 gtk_entry_update_primary_selection (entry);
3863 _gtk_entry_get_selected_text (GtkEntry *entry)
3865 GtkEditable *editable = GTK_EDITABLE (entry);
3866 gint start_text, end_text;
3869 if (gtk_editable_get_selection_bounds (editable, &start_text, &end_text))
3870 text = gtk_editable_get_chars (editable, start_text, end_text);
3876 gtk_entry_motion_notify (GtkWidget *widget,
3877 GdkEventMotion *event)
3879 GtkEntry *entry = GTK_ENTRY (widget);
3880 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3881 EntryIconInfo *icon_info = NULL;
3882 GdkDragContext *context;
3886 for (i = 0; i < MAX_ICONS; i++)
3888 icon_info = priv->icons[i];
3890 if (!icon_info || icon_info->insensitive)
3893 if (event->window == icon_info->window)
3895 if (icon_info->pressed &&
3896 icon_info->target_list != NULL &&
3897 gtk_drag_check_threshold (widget,
3903 icon_info->in_drag = TRUE;
3904 icon_info->pressed = FALSE;
3905 context = gtk_drag_begin (widget,
3906 icon_info->target_list,
3916 if (entry->mouse_cursor_obscured)
3920 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
3921 gdk_window_set_cursor (entry->text_area, cursor);
3922 gdk_cursor_unref (cursor);
3923 entry->mouse_cursor_obscured = FALSE;
3926 if (event->window != entry->text_area || entry->button != 1)
3929 if (entry->select_lines)
3932 gdk_event_request_motions (event);
3936 if (gtk_entry_get_display_mode (entry) == DISPLAY_NORMAL &&
3937 gtk_drag_check_threshold (widget,
3938 entry->drag_start_x, entry->drag_start_y,
3939 event->x + entry->scroll_offset, event->y))
3941 GdkDragContext *context;
3942 GtkTargetList *target_list = gtk_target_list_new (NULL, 0);
3943 guint actions = entry->editable ? GDK_ACTION_COPY | GDK_ACTION_MOVE : GDK_ACTION_COPY;
3945 GdkPixmap *pixmap = NULL;
3947 gtk_target_list_add_text_targets (target_list, 0);
3949 text = _gtk_entry_get_selected_text (entry);
3950 pixmap = _gtk_text_util_create_drag_icon (widget, text, -1);
3952 context = gtk_drag_begin (widget, target_list, actions,
3953 entry->button, (GdkEvent *)event);
3956 gtk_drag_set_icon_pixmap (context,
3957 gdk_drawable_get_colormap (pixmap),
3962 gtk_drag_set_icon_default (context);
3965 g_object_unref (pixmap);
3968 entry->in_drag = FALSE;
3971 gtk_target_list_unref (target_list);
3977 gdk_drawable_get_size (entry->text_area, NULL, &height);
3981 else if (event->y >= height)
3982 tmp_pos = gtk_entry_buffer_get_length (get_buffer (entry));
3984 tmp_pos = gtk_entry_find_position (entry, event->x + entry->scroll_offset);
3986 if (entry->select_words)
3989 gint old_min, old_max;
3992 min = gtk_entry_move_backward_word (entry, tmp_pos, TRUE);
3993 max = gtk_entry_move_forward_word (entry, tmp_pos, TRUE);
3995 pos = entry->current_pos;
3996 bound = entry->selection_bound;
3998 old_min = MIN(entry->current_pos, entry->selection_bound);
3999 old_max = MAX(entry->current_pos, entry->selection_bound);
4006 else if (old_max < max)
4011 else if (pos == old_min)
4013 if (entry->current_pos != min)
4018 if (entry->current_pos != max)
4022 gtk_entry_set_positions (entry, pos, bound);
4025 gtk_entry_set_positions (entry, tmp_pos, -1);
4032 set_invisible_cursor (GdkWindow *window)
4034 GdkDisplay *display;
4037 display = gdk_drawable_get_display (window);
4038 cursor = gdk_cursor_new_for_display (display, GDK_BLANK_CURSOR);
4040 gdk_window_set_cursor (window, cursor);
4042 gdk_cursor_unref (cursor);
4046 gtk_entry_obscure_mouse_cursor (GtkEntry *entry)
4048 if (entry->mouse_cursor_obscured)
4051 set_invisible_cursor (entry->text_area);
4053 entry->mouse_cursor_obscured = TRUE;
4057 gtk_entry_key_press (GtkWidget *widget,
4060 GtkEntry *entry = GTK_ENTRY (widget);
4062 gtk_entry_reset_blink_time (entry);
4063 gtk_entry_pend_cursor_blink (entry);
4065 if (entry->editable)
4067 if (gtk_im_context_filter_keypress (entry->im_context, event))
4069 gtk_entry_obscure_mouse_cursor (entry);
4070 entry->need_im_reset = TRUE;
4075 if (event->keyval == GDK_Return ||
4076 event->keyval == GDK_KP_Enter ||
4077 event->keyval == GDK_ISO_Enter ||
4078 event->keyval == GDK_Escape)
4080 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
4082 if (completion && completion->priv->completion_timeout)
4084 g_source_remove (completion->priv->completion_timeout);
4085 completion->priv->completion_timeout = 0;
4088 _gtk_entry_reset_im_context (entry);
4091 if (GTK_WIDGET_CLASS (gtk_entry_parent_class)->key_press_event (widget, event))
4092 /* Activate key bindings
4096 if (!entry->editable && event->length)
4097 gtk_widget_error_bell (widget);
4103 gtk_entry_key_release (GtkWidget *widget,
4106 GtkEntry *entry = GTK_ENTRY (widget);
4108 if (entry->editable)
4110 if (gtk_im_context_filter_keypress (entry->im_context, event))
4112 entry->need_im_reset = TRUE;
4117 return GTK_WIDGET_CLASS (gtk_entry_parent_class)->key_release_event (widget, event);
4121 gtk_entry_focus_in (GtkWidget *widget,
4122 GdkEventFocus *event)
4124 GtkEntry *entry = GTK_ENTRY (widget);
4127 gtk_widget_queue_draw (widget);
4129 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (widget));
4131 if (entry->editable)
4133 entry->need_im_reset = TRUE;
4134 gtk_im_context_focus_in (entry->im_context);
4135 keymap_state_changed (keymap, entry);
4136 g_signal_connect (keymap, "state-changed",
4137 G_CALLBACK (keymap_state_changed), entry);
4140 g_signal_connect (keymap, "direction-changed",
4141 G_CALLBACK (keymap_direction_changed), entry);
4143 gtk_entry_reset_blink_time (entry);
4144 gtk_entry_check_cursor_blink (entry);
4150 gtk_entry_focus_out (GtkWidget *widget,
4151 GdkEventFocus *event)
4153 GtkEntry *entry = GTK_ENTRY (widget);
4154 GtkEntryCompletion *completion;
4157 gtk_widget_queue_draw (widget);
4159 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (widget));
4161 if (entry->editable)
4163 entry->need_im_reset = TRUE;
4164 gtk_im_context_focus_out (entry->im_context);
4165 remove_capslock_feedback (entry);
4168 gtk_entry_check_cursor_blink (entry);
4170 g_signal_handlers_disconnect_by_func (keymap, keymap_state_changed, entry);
4171 g_signal_handlers_disconnect_by_func (keymap, keymap_direction_changed, entry);
4173 completion = gtk_entry_get_completion (entry);
4175 _gtk_entry_completion_popdown (completion);
4181 gtk_entry_grab_focus (GtkWidget *widget)
4183 GtkEntry *entry = GTK_ENTRY (widget);
4184 gboolean select_on_focus;
4186 GTK_WIDGET_CLASS (gtk_entry_parent_class)->grab_focus (widget);
4188 if (entry->editable && !entry->in_click)
4190 g_object_get (gtk_widget_get_settings (widget),
4191 "gtk-entry-select-on-focus",
4195 if (select_on_focus)
4196 gtk_editable_select_region (GTK_EDITABLE (widget), 0, -1);
4201 gtk_entry_direction_changed (GtkWidget *widget,
4202 GtkTextDirection previous_dir)
4204 GtkEntry *entry = GTK_ENTRY (widget);
4206 gtk_entry_recompute (entry);
4208 GTK_WIDGET_CLASS (gtk_entry_parent_class)->direction_changed (widget, previous_dir);
4212 gtk_entry_state_changed (GtkWidget *widget,
4213 GtkStateType previous_state)
4215 GtkEntry *entry = GTK_ENTRY (widget);
4216 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
4220 if (GTK_WIDGET_REALIZED (widget))
4222 gdk_window_set_background (widget->window, &widget->style->base[GTK_WIDGET_STATE (widget)]);
4223 gdk_window_set_background (entry->text_area, &widget->style->base[GTK_WIDGET_STATE (widget)]);
4224 for (i = 0; i < MAX_ICONS; i++)
4226 EntryIconInfo *icon_info = priv->icons[i];
4227 if (icon_info && icon_info->window)
4228 gdk_window_set_background (icon_info->window, &widget->style->base[GTK_WIDGET_STATE (widget)]);
4231 if (GTK_WIDGET_IS_SENSITIVE (widget))
4232 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
4236 gdk_window_set_cursor (entry->text_area, cursor);
4239 gdk_cursor_unref (cursor);
4241 entry->mouse_cursor_obscured = FALSE;
4243 update_cursors (widget);
4246 if (!GTK_WIDGET_IS_SENSITIVE (widget))
4248 /* Clear any selection */
4249 gtk_editable_select_region (GTK_EDITABLE (entry), entry->current_pos, entry->current_pos);
4252 gtk_widget_queue_draw (widget);
4256 gtk_entry_screen_changed (GtkWidget *widget,
4257 GdkScreen *old_screen)
4259 gtk_entry_recompute (GTK_ENTRY (widget));
4262 /* GtkEditable method implementations
4265 gtk_entry_insert_text (GtkEditable *editable,
4266 const gchar *new_text,
4267 gint new_text_length,
4270 g_object_ref (editable);
4273 * The incoming text may a password or other secret. We make sure
4274 * not to copy it into temporary buffers.
4277 g_signal_emit_by_name (editable, "insert-text", new_text, new_text_length, position);
4279 g_object_unref (editable);
4283 gtk_entry_delete_text (GtkEditable *editable,
4287 g_object_ref (editable);
4289 g_signal_emit_by_name (editable, "delete-text", start_pos, end_pos);
4291 g_object_unref (editable);
4295 gtk_entry_get_chars (GtkEditable *editable,
4299 GtkEntry *entry = GTK_ENTRY (editable);
4302 gint start_index, end_index;
4304 text = gtk_entry_buffer_get_text (get_buffer (entry));
4305 text_length = gtk_entry_buffer_get_length (get_buffer (entry));
4308 end_pos = text_length;
4310 start_pos = MIN (text_length, start_pos);
4311 end_pos = MIN (text_length, end_pos);
4313 start_index = g_utf8_offset_to_pointer (text, start_pos) - entry->text;
4314 end_index = g_utf8_offset_to_pointer (text, end_pos) - entry->text;
4316 return g_strndup (text + start_index, end_index - start_index);
4320 gtk_entry_real_set_position (GtkEditable *editable,
4323 GtkEntry *entry = GTK_ENTRY (editable);
4327 length = gtk_entry_buffer_get_length (get_buffer (entry));
4328 if (position < 0 || position > length)
4331 if (position != entry->current_pos ||
4332 position != entry->selection_bound)
4334 _gtk_entry_reset_im_context (entry);
4335 gtk_entry_set_positions (entry, position, position);
4340 gtk_entry_get_position (GtkEditable *editable)
4342 return GTK_ENTRY (editable)->current_pos;
4346 gtk_entry_set_selection_bounds (GtkEditable *editable,
4350 GtkEntry *entry = GTK_ENTRY (editable);
4353 length = gtk_entry_buffer_get_length (get_buffer (entry));
4359 _gtk_entry_reset_im_context (entry);
4361 gtk_entry_set_positions (entry,
4363 MIN (start, length));
4365 gtk_entry_update_primary_selection (entry);
4369 gtk_entry_get_selection_bounds (GtkEditable *editable,
4373 GtkEntry *entry = GTK_ENTRY (editable);
4375 *start = entry->selection_bound;
4376 *end = entry->current_pos;
4378 return (entry->selection_bound != entry->current_pos);
4382 icon_theme_changed (GtkEntry *entry)
4384 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
4387 for (i = 0; i < MAX_ICONS; i++)
4389 EntryIconInfo *icon_info = priv->icons[i];
4390 if (icon_info != NULL)
4392 if (icon_info->storage_type == GTK_IMAGE_ICON_NAME)
4393 gtk_entry_set_icon_from_icon_name (entry, i, icon_info->icon_name);
4394 else if (icon_info->storage_type == GTK_IMAGE_STOCK)
4395 gtk_entry_set_icon_from_stock (entry, i, icon_info->stock_id);
4396 else if (icon_info->storage_type == GTK_IMAGE_GICON)
4397 gtk_entry_set_icon_from_gicon (entry, i, icon_info->gicon);
4401 gtk_widget_queue_draw (GTK_WIDGET (entry));
4405 icon_margin_changed (GtkEntry *entry)
4407 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
4410 _gtk_entry_effective_inner_border (GTK_ENTRY (entry), &border);
4412 priv->icon_margin = border.left;
4416 gtk_entry_style_set (GtkWidget *widget,
4417 GtkStyle *previous_style)
4419 GtkEntry *entry = GTK_ENTRY (widget);
4420 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
4422 gboolean interior_focus;
4425 gtk_widget_style_get (widget,
4426 "focus-line-width", &focus_width,
4427 "interior-focus", &interior_focus,
4430 priv->focus_width = focus_width;
4431 priv->interior_focus = interior_focus;
4433 if (!priv->invisible_char_set)
4434 entry->invisible_char = find_invisible_char (GTK_WIDGET (entry));
4436 gtk_entry_recompute (entry);
4438 if (previous_style && GTK_WIDGET_REALIZED (widget))
4440 gdk_window_set_background (widget->window, &widget->style->base[GTK_WIDGET_STATE (widget)]);
4441 gdk_window_set_background (entry->text_area, &widget->style->base[GTK_WIDGET_STATE (widget)]);
4442 for (i = 0; i < MAX_ICONS; i++)
4444 EntryIconInfo *icon_info = priv->icons[i];
4445 if (icon_info && icon_info->window)
4446 gdk_window_set_background (icon_info->window, &widget->style->base[GTK_WIDGET_STATE (widget)]);
4450 icon_theme_changed (entry);
4451 icon_margin_changed (entry);
4454 /* GtkCellEditable method implementations
4457 gtk_cell_editable_entry_activated (GtkEntry *entry, gpointer data)
4459 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4460 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4464 gtk_cell_editable_key_press_event (GtkEntry *entry,
4465 GdkEventKey *key_event,
4468 if (key_event->keyval == GDK_Escape)
4470 entry->editing_canceled = TRUE;
4471 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4472 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4477 /* override focus */
4478 if (key_event->keyval == GDK_Up || key_event->keyval == GDK_Down)
4480 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4481 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4490 gtk_entry_start_editing (GtkCellEditable *cell_editable,
4493 GTK_ENTRY (cell_editable)->is_cell_renderer = TRUE;
4495 g_signal_connect (cell_editable, "activate",
4496 G_CALLBACK (gtk_cell_editable_entry_activated), NULL);
4497 g_signal_connect (cell_editable, "key-press-event",
4498 G_CALLBACK (gtk_cell_editable_key_press_event), NULL);
4502 gtk_entry_password_hint_free (GtkEntryPasswordHint *password_hint)
4504 if (password_hint->source_id)
4505 g_source_remove (password_hint->source_id);
4507 g_slice_free (GtkEntryPasswordHint, password_hint);
4512 gtk_entry_remove_password_hint (gpointer data)
4514 GtkEntryPasswordHint *password_hint = g_object_get_qdata (data, quark_password_hint);
4515 password_hint->position = -1;
4517 /* Force the string to be redrawn, but now without a visible character */
4518 gtk_entry_recompute (GTK_ENTRY (data));
4522 /* Default signal handlers
4525 gtk_entry_real_insert_text (GtkEditable *editable,
4526 const gchar *new_text,
4527 gint new_text_length,
4533 n_chars = g_utf8_strlen (new_text, new_text_length);
4536 * The actual insertion into the buffer. This will end up firing the
4537 * following signal handlers: buffer_inserted_text(), buffer_notify_display_text(),
4538 * buffer_notify_text(), buffer_notify_length()
4540 n_inserted = gtk_entry_buffer_insert_text (get_buffer (GTK_ENTRY (editable)), *position, new_text, n_chars);
4542 if (n_inserted != n_chars)
4543 gtk_widget_error_bell (GTK_WIDGET (editable));
4545 *position += n_inserted;
4549 gtk_entry_real_delete_text (GtkEditable *editable,
4554 * The actual deletion from the buffer. This will end up firing the
4555 * following signal handlers: buffer_deleted_text(), buffer_notify_display_text(),
4556 * buffer_notify_text(), buffer_notify_length()
4559 gtk_entry_buffer_delete_text (get_buffer (GTK_ENTRY (editable)), start_pos, end_pos - start_pos);
4562 /* GtkEntryBuffer signal handlers
4565 buffer_inserted_text (GtkEntryBuffer *buffer,
4571 guint password_hint_timeout;
4573 if (entry->current_pos > position)
4574 entry->current_pos += n_chars;
4576 if (entry->selection_bound > position)
4577 entry->selection_bound += n_chars;
4579 /* Calculate the password hint if it needs to be displayed. */
4580 if (n_chars == 1 && !entry->visible)
4582 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
4583 "gtk-entry-password-hint-timeout", &password_hint_timeout,
4586 if (password_hint_timeout > 0)
4588 GtkEntryPasswordHint *password_hint = g_object_get_qdata (G_OBJECT (entry),
4589 quark_password_hint);
4592 password_hint = g_slice_new0 (GtkEntryPasswordHint);
4593 g_object_set_qdata_full (G_OBJECT (entry), quark_password_hint, password_hint,
4594 (GDestroyNotify)gtk_entry_password_hint_free);
4597 password_hint->position = position;
4598 if (password_hint->source_id)
4599 g_source_remove (password_hint->source_id);
4600 password_hint->source_id = gdk_threads_add_timeout (password_hint_timeout,
4601 (GSourceFunc)gtk_entry_remove_password_hint, entry);
4607 buffer_deleted_text (GtkEntryBuffer *buffer,
4612 guint end_pos = position + n_chars;
4613 gint selection_bound;
4616 current_pos = entry->current_pos;
4617 if (current_pos > position)
4618 current_pos -= MIN (current_pos, end_pos) - position;
4620 selection_bound = entry->selection_bound;
4621 if (selection_bound > position)
4622 selection_bound -= MIN (selection_bound, end_pos) - position;
4624 gtk_entry_set_positions (entry, current_pos, selection_bound);
4626 /* We might have deleted the selection */
4627 gtk_entry_update_primary_selection (entry);
4629 /* Disable the password hint if one exists. */
4630 if (!entry->visible)
4632 GtkEntryPasswordHint *password_hint = g_object_get_qdata (G_OBJECT (entry),
4633 quark_password_hint);
4636 if (password_hint->source_id)
4637 g_source_remove (password_hint->source_id);
4638 password_hint->source_id = 0;
4639 password_hint->position = -1;
4645 buffer_notify_text (GtkEntryBuffer *buffer,
4649 /* COMPAT: Deprecated, not used. This struct field will be removed in GTK+ 3.x */
4650 entry->text = (gchar*)gtk_entry_buffer_get_text (buffer);
4652 gtk_entry_recompute (entry);
4653 emit_changed (entry);
4654 g_object_notify (G_OBJECT (entry), "text");
4658 buffer_notify_length (GtkEntryBuffer *buffer,
4662 /* COMPAT: Deprecated, not used. This struct field will be removed in GTK+ 3.x */
4663 entry->text_length = gtk_entry_buffer_get_length (buffer);
4665 g_object_notify (G_OBJECT (entry), "text-length");
4669 buffer_notify_max_length (GtkEntryBuffer *buffer,
4673 /* COMPAT: Deprecated, not used. This struct field will be removed in GTK+ 3.x */
4674 entry->text_max_length = gtk_entry_buffer_get_max_length (buffer);
4676 g_object_notify (G_OBJECT (entry), "max-length");
4680 buffer_connect_signals (GtkEntry *entry)
4682 g_signal_connect (get_buffer (entry), "inserted-text", G_CALLBACK (buffer_inserted_text), entry);
4683 g_signal_connect (get_buffer (entry), "deleted-text", G_CALLBACK (buffer_deleted_text), entry);
4684 g_signal_connect (get_buffer (entry), "notify::text", G_CALLBACK (buffer_notify_text), entry);
4685 g_signal_connect (get_buffer (entry), "notify::length", G_CALLBACK (buffer_notify_length), entry);
4686 g_signal_connect (get_buffer (entry), "notify::max-length", G_CALLBACK (buffer_notify_max_length), entry);
4690 buffer_disconnect_signals (GtkEntry *entry)
4692 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_inserted_text, entry);
4693 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_deleted_text, entry);
4694 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_text, entry);
4695 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_length, entry);
4696 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_max_length, entry);
4699 /* Compute the X position for an offset that corresponds to the "more important
4700 * cursor position for that offset. We use this when trying to guess to which
4701 * end of the selection we should go to when the user hits the left or
4705 get_better_cursor_x (GtkEntry *entry,
4708 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
4709 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
4710 gboolean split_cursor;
4712 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
4713 const gchar *text = pango_layout_get_text (layout);
4714 gint index = g_utf8_offset_to_pointer (text, offset) - text;
4716 PangoRectangle strong_pos, weak_pos;
4718 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
4719 "gtk-split-cursor", &split_cursor,
4722 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
4725 return strong_pos.x / PANGO_SCALE;
4727 return (keymap_direction == entry->resolved_dir) ? strong_pos.x / PANGO_SCALE : weak_pos.x / PANGO_SCALE;
4731 gtk_entry_move_cursor (GtkEntry *entry,
4732 GtkMovementStep step,
4734 gboolean extend_selection)
4736 gint new_pos = entry->current_pos;
4737 GtkEntryPrivate *priv;
4739 _gtk_entry_reset_im_context (entry);
4741 if (entry->current_pos != entry->selection_bound && !extend_selection)
4743 /* If we have a current selection and aren't extending it, move to the
4744 * start/or end of the selection as appropriate
4748 case GTK_MOVEMENT_VISUAL_POSITIONS:
4750 gint current_x = get_better_cursor_x (entry, entry->current_pos);
4751 gint bound_x = get_better_cursor_x (entry, entry->selection_bound);
4754 new_pos = current_x < bound_x ? entry->current_pos : entry->selection_bound;
4756 new_pos = current_x > bound_x ? entry->current_pos : entry->selection_bound;
4759 case GTK_MOVEMENT_LOGICAL_POSITIONS:
4760 case GTK_MOVEMENT_WORDS:
4762 new_pos = MIN (entry->current_pos, entry->selection_bound);
4764 new_pos = MAX (entry->current_pos, entry->selection_bound);
4766 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
4767 case GTK_MOVEMENT_PARAGRAPH_ENDS:
4768 case GTK_MOVEMENT_BUFFER_ENDS:
4769 priv = GTK_ENTRY_GET_PRIVATE (entry);
4770 new_pos = count < 0 ? 0 : gtk_entry_buffer_get_length (get_buffer (entry));
4772 case GTK_MOVEMENT_DISPLAY_LINES:
4773 case GTK_MOVEMENT_PARAGRAPHS:
4774 case GTK_MOVEMENT_PAGES:
4775 case GTK_MOVEMENT_HORIZONTAL_PAGES:
4783 case GTK_MOVEMENT_LOGICAL_POSITIONS:
4784 new_pos = gtk_entry_move_logically (entry, new_pos, count);
4786 case GTK_MOVEMENT_VISUAL_POSITIONS:
4787 new_pos = gtk_entry_move_visually (entry, new_pos, count);
4788 if (entry->current_pos == new_pos)
4790 if (!extend_selection)
4792 if (!gtk_widget_keynav_failed (GTK_WIDGET (entry),
4794 GTK_DIR_RIGHT : GTK_DIR_LEFT))
4796 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (entry));
4799 gtk_widget_child_focus (toplevel,
4801 GTK_DIR_RIGHT : GTK_DIR_LEFT);
4806 gtk_widget_error_bell (GTK_WIDGET (entry));
4810 case GTK_MOVEMENT_WORDS:
4813 new_pos = gtk_entry_move_forward_word (entry, new_pos, FALSE);
4818 new_pos = gtk_entry_move_backward_word (entry, new_pos, FALSE);
4821 if (entry->current_pos == new_pos)
4822 gtk_widget_error_bell (GTK_WIDGET (entry));
4824 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
4825 case GTK_MOVEMENT_PARAGRAPH_ENDS:
4826 case GTK_MOVEMENT_BUFFER_ENDS:
4827 priv = GTK_ENTRY_GET_PRIVATE (entry);
4828 new_pos = count < 0 ? 0 : gtk_entry_buffer_get_length (get_buffer (entry));
4829 if (entry->current_pos == new_pos)
4830 gtk_widget_error_bell (GTK_WIDGET (entry));
4832 case GTK_MOVEMENT_DISPLAY_LINES:
4833 case GTK_MOVEMENT_PARAGRAPHS:
4834 case GTK_MOVEMENT_PAGES:
4835 case GTK_MOVEMENT_HORIZONTAL_PAGES:
4840 if (extend_selection)
4841 gtk_editable_select_region (GTK_EDITABLE (entry), entry->selection_bound, new_pos);
4843 gtk_editable_set_position (GTK_EDITABLE (entry), new_pos);
4845 gtk_entry_pend_cursor_blink (entry);
4849 gtk_entry_insert_at_cursor (GtkEntry *entry,
4852 GtkEditable *editable = GTK_EDITABLE (entry);
4853 gint pos = entry->current_pos;
4855 if (entry->editable)
4857 _gtk_entry_reset_im_context (entry);
4859 gtk_editable_insert_text (editable, str, -1, &pos);
4860 gtk_editable_set_position (editable, pos);
4865 gtk_entry_delete_from_cursor (GtkEntry *entry,
4869 GtkEditable *editable = GTK_EDITABLE (entry);
4870 gint start_pos = entry->current_pos;
4871 gint end_pos = entry->current_pos;
4872 gint old_n_bytes = gtk_entry_buffer_get_bytes (get_buffer (entry));
4874 _gtk_entry_reset_im_context (entry);
4876 if (!entry->editable)
4878 gtk_widget_error_bell (GTK_WIDGET (entry));
4882 if (entry->selection_bound != entry->current_pos)
4884 gtk_editable_delete_selection (editable);
4890 case GTK_DELETE_CHARS:
4891 end_pos = gtk_entry_move_logically (entry, entry->current_pos, count);
4892 gtk_editable_delete_text (editable, MIN (start_pos, end_pos), MAX (start_pos, end_pos));
4894 case GTK_DELETE_WORDS:
4897 /* Move to end of current word, or if not on a word, end of previous word */
4898 end_pos = gtk_entry_move_backward_word (entry, end_pos, FALSE);
4899 end_pos = gtk_entry_move_forward_word (entry, end_pos, FALSE);
4903 /* Move to beginning of current word, or if not on a word, begining of next word */
4904 start_pos = gtk_entry_move_forward_word (entry, start_pos, FALSE);
4905 start_pos = gtk_entry_move_backward_word (entry, start_pos, FALSE);
4909 case GTK_DELETE_WORD_ENDS:
4912 start_pos = gtk_entry_move_backward_word (entry, start_pos, FALSE);
4917 end_pos = gtk_entry_move_forward_word (entry, end_pos, FALSE);
4920 gtk_editable_delete_text (editable, start_pos, end_pos);
4922 case GTK_DELETE_DISPLAY_LINE_ENDS:
4923 case GTK_DELETE_PARAGRAPH_ENDS:
4925 gtk_editable_delete_text (editable, 0, entry->current_pos);
4927 gtk_editable_delete_text (editable, entry->current_pos, -1);
4929 case GTK_DELETE_DISPLAY_LINES:
4930 case GTK_DELETE_PARAGRAPHS:
4931 gtk_editable_delete_text (editable, 0, -1);
4933 case GTK_DELETE_WHITESPACE:
4934 gtk_entry_delete_whitespace (entry);
4938 if (gtk_entry_buffer_get_bytes (get_buffer (entry)) == old_n_bytes)
4939 gtk_widget_error_bell (GTK_WIDGET (entry));
4941 gtk_entry_pend_cursor_blink (entry);
4945 gtk_entry_backspace (GtkEntry *entry)
4947 GtkEditable *editable = GTK_EDITABLE (entry);
4950 _gtk_entry_reset_im_context (entry);
4952 if (!entry->editable)
4954 gtk_widget_error_bell (GTK_WIDGET (entry));
4958 if (entry->selection_bound != entry->current_pos)
4960 gtk_editable_delete_selection (editable);
4964 prev_pos = gtk_entry_move_logically (entry, entry->current_pos, -1);
4966 if (prev_pos < entry->current_pos)
4968 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
4969 PangoLogAttr *log_attrs;
4972 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
4974 /* Deleting parts of characters */
4975 if (log_attrs[entry->current_pos].backspace_deletes_character)
4977 gchar *cluster_text;
4978 gchar *normalized_text;
4981 cluster_text = gtk_entry_get_display_text (entry, prev_pos,
4982 entry->current_pos);
4983 normalized_text = g_utf8_normalize (cluster_text,
4984 strlen (cluster_text),
4986 len = g_utf8_strlen (normalized_text, -1);
4988 gtk_editable_delete_text (editable, prev_pos, entry->current_pos);
4991 gint pos = entry->current_pos;
4993 gtk_editable_insert_text (editable, normalized_text,
4994 g_utf8_offset_to_pointer (normalized_text, len - 1) - normalized_text,
4996 gtk_editable_set_position (editable, pos);
4999 g_free (normalized_text);
5000 g_free (cluster_text);
5004 gtk_editable_delete_text (editable, prev_pos, entry->current_pos);
5011 gtk_widget_error_bell (GTK_WIDGET (entry));
5014 gtk_entry_pend_cursor_blink (entry);
5018 gtk_entry_copy_clipboard (GtkEntry *entry)
5020 GtkEditable *editable = GTK_EDITABLE (entry);
5024 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5026 if (!entry->visible)
5028 gtk_widget_error_bell (GTK_WIDGET (entry));
5032 str = gtk_entry_get_display_text (entry, start, end);
5033 gtk_clipboard_set_text (gtk_widget_get_clipboard (GTK_WIDGET (entry),
5034 GDK_SELECTION_CLIPBOARD),
5041 gtk_entry_cut_clipboard (GtkEntry *entry)
5043 GtkEditable *editable = GTK_EDITABLE (entry);
5046 if (!entry->visible)
5048 gtk_widget_error_bell (GTK_WIDGET (entry));
5052 gtk_entry_copy_clipboard (entry);
5054 if (entry->editable)
5056 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5057 gtk_editable_delete_text (editable, start, end);
5061 gtk_widget_error_bell (GTK_WIDGET (entry));
5066 gtk_entry_paste_clipboard (GtkEntry *entry)
5068 if (entry->editable)
5069 gtk_entry_paste (entry, GDK_NONE);
5071 gtk_widget_error_bell (GTK_WIDGET (entry));
5075 gtk_entry_delete_cb (GtkEntry *entry)
5077 GtkEditable *editable = GTK_EDITABLE (entry);
5080 if (entry->editable)
5082 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5083 gtk_editable_delete_text (editable, start, end);
5088 gtk_entry_toggle_overwrite (GtkEntry *entry)
5090 entry->overwrite_mode = !entry->overwrite_mode;
5091 gtk_entry_pend_cursor_blink (entry);
5092 gtk_widget_queue_draw (GTK_WIDGET (entry));
5096 gtk_entry_select_all (GtkEntry *entry)
5098 gtk_entry_select_line (entry);
5102 gtk_entry_real_activate (GtkEntry *entry)
5105 GtkWidget *toplevel;
5108 widget = GTK_WIDGET (entry);
5110 if (entry->activates_default)
5112 toplevel = gtk_widget_get_toplevel (widget);
5113 if (GTK_IS_WINDOW (toplevel))
5115 window = GTK_WINDOW (toplevel);
5118 widget != window->default_widget &&
5119 !(widget == window->focus_widget &&
5120 (!window->default_widget || !GTK_WIDGET_SENSITIVE (window->default_widget))))
5121 gtk_window_activate_default (window);
5127 keymap_direction_changed (GdkKeymap *keymap,
5130 gtk_entry_recompute (entry);
5133 /* IM Context Callbacks
5137 gtk_entry_commit_cb (GtkIMContext *context,
5141 if (entry->editable)
5142 gtk_entry_enter_text (entry, str);
5146 gtk_entry_preedit_changed_cb (GtkIMContext *context,
5149 if (entry->editable)
5151 gchar *preedit_string;
5154 gtk_im_context_get_preedit_string (entry->im_context,
5155 &preedit_string, NULL,
5157 entry->preedit_length = strlen (preedit_string);
5158 cursor_pos = CLAMP (cursor_pos, 0, g_utf8_strlen (preedit_string, -1));
5159 entry->preedit_cursor = cursor_pos;
5160 g_free (preedit_string);
5162 gtk_entry_recompute (entry);
5167 gtk_entry_retrieve_surrounding_cb (GtkIMContext *context,
5172 /* XXXX ??? does this even make sense when text is not visible? Should we return FALSE? */
5173 text = gtk_entry_get_display_text (entry, 0, -1);
5174 gtk_im_context_set_surrounding (context, text, strlen (text), /* Length in bytes */
5175 g_utf8_offset_to_pointer (text, entry->current_pos) - text);
5182 gtk_entry_delete_surrounding_cb (GtkIMContext *slave,
5187 if (entry->editable)
5188 gtk_editable_delete_text (GTK_EDITABLE (entry),
5189 entry->current_pos + offset,
5190 entry->current_pos + offset + n_chars);
5195 /* Internal functions
5198 /* Used for im_commit_cb and inserting Unicode chars */
5200 gtk_entry_enter_text (GtkEntry *entry,
5203 GtkEditable *editable = GTK_EDITABLE (entry);
5205 gboolean old_need_im_reset;
5207 old_need_im_reset = entry->need_im_reset;
5208 entry->need_im_reset = FALSE;
5210 if (gtk_editable_get_selection_bounds (editable, NULL, NULL))
5211 gtk_editable_delete_selection (editable);
5214 if (entry->overwrite_mode)
5215 gtk_entry_delete_from_cursor (entry, GTK_DELETE_CHARS, 1);
5218 tmp_pos = entry->current_pos;
5219 gtk_editable_insert_text (editable, str, strlen (str), &tmp_pos);
5220 gtk_editable_set_position (editable, tmp_pos);
5222 entry->need_im_reset = old_need_im_reset;
5225 /* All changes to entry->current_pos and entry->selection_bound
5226 * should go through this function.
5229 gtk_entry_set_positions (GtkEntry *entry,
5231 gint selection_bound)
5233 gboolean changed = FALSE;
5235 g_object_freeze_notify (G_OBJECT (entry));
5237 if (current_pos != -1 &&
5238 entry->current_pos != current_pos)
5240 entry->current_pos = current_pos;
5243 g_object_notify (G_OBJECT (entry), "cursor-position");
5246 if (selection_bound != -1 &&
5247 entry->selection_bound != selection_bound)
5249 entry->selection_bound = selection_bound;
5252 g_object_notify (G_OBJECT (entry), "selection-bound");
5255 g_object_thaw_notify (G_OBJECT (entry));
5259 gtk_entry_move_adjustments (entry);
5260 gtk_entry_recompute (entry);
5265 gtk_entry_reset_layout (GtkEntry *entry)
5267 if (entry->cached_layout)
5269 g_object_unref (entry->cached_layout);
5270 entry->cached_layout = NULL;
5275 update_im_cursor_location (GtkEntry *entry)
5279 gint strong_xoffset;
5280 gint area_width, area_height;
5282 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
5283 gtk_entry_get_text_area_size (entry, NULL, NULL, &area_width, &area_height);
5285 strong_xoffset = strong_x - entry->scroll_offset;
5286 if (strong_xoffset < 0)
5290 else if (strong_xoffset > area_width)
5292 strong_xoffset = area_width;
5294 area.x = strong_xoffset;
5297 area.height = area_height;
5299 gtk_im_context_set_cursor_location (entry->im_context, &area);
5303 recompute_idle_func (gpointer data)
5307 entry = GTK_ENTRY (data);
5309 entry->recompute_idle = 0;
5311 if (gtk_widget_has_screen (GTK_WIDGET (entry)))
5313 gtk_entry_adjust_scroll (entry);
5314 gtk_entry_queue_draw (entry);
5316 update_im_cursor_location (entry);
5323 gtk_entry_recompute (GtkEntry *entry)
5325 gtk_entry_reset_layout (entry);
5326 gtk_entry_check_cursor_blink (entry);
5328 if (!entry->recompute_idle)
5330 entry->recompute_idle = gdk_threads_add_idle_full (G_PRIORITY_HIGH_IDLE + 15, /* between resize and redraw */
5331 recompute_idle_func, entry, NULL);
5335 static PangoLayout *
5336 gtk_entry_create_layout (GtkEntry *entry,
5337 gboolean include_preedit)
5339 GtkWidget *widget = GTK_WIDGET (entry);
5340 PangoLayout *layout = gtk_widget_create_pango_layout (widget, NULL);
5341 PangoAttrList *tmp_attrs = pango_attr_list_new ();
5343 gchar *preedit_string = NULL;
5344 gint preedit_length = 0;
5345 PangoAttrList *preedit_attrs = NULL;
5350 pango_layout_set_single_paragraph_mode (layout, TRUE);
5352 display = gtk_entry_get_display_text (entry, 0, -1);
5353 n_bytes = strlen (display);
5355 if (include_preedit)
5357 gtk_im_context_get_preedit_string (entry->im_context,
5358 &preedit_string, &preedit_attrs, NULL);
5359 preedit_length = entry->preedit_length;
5364 GString *tmp_string = g_string_new (display);
5365 gint cursor_index = g_utf8_offset_to_pointer (display, entry->current_pos) - display;
5367 g_string_insert (tmp_string, cursor_index, preedit_string);
5369 pango_layout_set_text (layout, tmp_string->str, tmp_string->len);
5371 pango_attr_list_splice (tmp_attrs, preedit_attrs,
5372 cursor_index, preedit_length);
5374 g_string_free (tmp_string, TRUE);
5378 PangoDirection pango_dir;
5380 if (gtk_entry_get_display_mode (entry) == DISPLAY_NORMAL)
5381 pango_dir = pango_find_base_dir (display, n_bytes);
5383 pango_dir = PANGO_DIRECTION_NEUTRAL;
5385 if (pango_dir == PANGO_DIRECTION_NEUTRAL)
5387 if (GTK_WIDGET_HAS_FOCUS (widget))
5389 GdkDisplay *display = gtk_widget_get_display (widget);
5390 GdkKeymap *keymap = gdk_keymap_get_for_display (display);
5391 if (gdk_keymap_get_direction (keymap) == PANGO_DIRECTION_RTL)
5392 pango_dir = PANGO_DIRECTION_RTL;
5394 pango_dir = PANGO_DIRECTION_LTR;
5398 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
5399 pango_dir = PANGO_DIRECTION_RTL;
5401 pango_dir = PANGO_DIRECTION_LTR;
5405 pango_context_set_base_dir (gtk_widget_get_pango_context (widget),
5408 entry->resolved_dir = pango_dir;
5410 pango_layout_set_text (layout, display, n_bytes);
5413 pango_layout_set_attributes (layout, tmp_attrs);
5415 g_free (preedit_string);
5419 pango_attr_list_unref (preedit_attrs);
5421 pango_attr_list_unref (tmp_attrs);
5426 static PangoLayout *
5427 gtk_entry_ensure_layout (GtkEntry *entry,
5428 gboolean include_preedit)
5430 if (entry->preedit_length > 0 &&
5431 !include_preedit != !entry->cache_includes_preedit)
5432 gtk_entry_reset_layout (entry);
5434 if (!entry->cached_layout)
5436 entry->cached_layout = gtk_entry_create_layout (entry, include_preedit);
5437 entry->cache_includes_preedit = include_preedit;
5440 return entry->cached_layout;
5444 get_layout_position (GtkEntry *entry,
5448 PangoLayout *layout;
5449 PangoRectangle logical_rect;
5450 gint area_width, area_height;
5451 GtkBorder inner_border;
5453 PangoLayoutLine *line;
5455 layout = gtk_entry_ensure_layout (entry, TRUE);
5457 gtk_entry_get_text_area_size (entry, NULL, NULL, &area_width, &area_height);
5458 _gtk_entry_effective_inner_border (entry, &inner_border);
5460 area_height = PANGO_SCALE * (area_height - inner_border.top - inner_border.bottom);
5462 line = pango_layout_get_lines_readonly (layout)->data;
5463 pango_layout_line_get_extents (line, NULL, &logical_rect);
5465 /* Align primarily for locale's ascent/descent */
5466 y_pos = ((area_height - entry->ascent - entry->descent) / 2 +
5467 entry->ascent + logical_rect.y);
5469 /* Now see if we need to adjust to fit in actual drawn string */
5470 if (logical_rect.height > area_height)
5471 y_pos = (area_height - logical_rect.height) / 2;
5474 else if (y_pos + logical_rect.height > area_height)
5475 y_pos = area_height - logical_rect.height;
5477 y_pos = inner_border.top + y_pos / PANGO_SCALE;
5480 *x = inner_border.left - entry->scroll_offset;
5487 draw_text_with_color (GtkEntry *entry, cairo_t *cr, GdkColor *default_color)
5489 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
5492 gint start_pos, end_pos;
5494 widget = GTK_WIDGET (entry);
5498 get_layout_position (entry, &x, &y);
5500 cairo_move_to (cr, x, y);
5501 gdk_cairo_set_source_color (cr, default_color);
5502 pango_cairo_show_layout (cr, layout);
5504 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start_pos, &end_pos))
5508 PangoRectangle logical_rect;
5509 GdkColor *selection_color, *text_color;
5510 GtkBorder inner_border;
5512 pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
5513 gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
5515 if (GTK_WIDGET_HAS_FOCUS (entry))
5517 selection_color = &widget->style->base [GTK_STATE_SELECTED];
5518 text_color = &widget->style->text [GTK_STATE_SELECTED];
5522 selection_color = &widget->style->base [GTK_STATE_ACTIVE];
5523 text_color = &widget->style->text [GTK_STATE_ACTIVE];
5526 _gtk_entry_effective_inner_border (entry, &inner_border);
5528 for (i = 0; i < n_ranges; ++i)
5529 cairo_rectangle (cr,
5530 inner_border.left - entry->scroll_offset + ranges[2 * i],
5533 logical_rect.height);
5537 gdk_cairo_set_source_color (cr, selection_color);
5540 cairo_move_to (cr, x, y);
5541 gdk_cairo_set_source_color (cr, text_color);
5542 pango_cairo_show_layout (cr, layout);
5550 gtk_entry_draw_text (GtkEntry *entry)
5552 GtkWidget *widget = GTK_WIDGET (entry);
5555 /* Nothing to display at all */
5556 if (gtk_entry_get_display_mode (entry) == DISPLAY_BLANK)
5559 if (GTK_WIDGET_DRAWABLE (entry))
5561 GdkColor text_color, bar_text_color;
5564 gint progress_x, progress_y, progress_width, progress_height;
5567 state = GTK_STATE_SELECTED;
5568 if (!GTK_WIDGET_SENSITIVE (widget))
5569 state = GTK_STATE_INSENSITIVE;
5570 text_color = widget->style->text[widget->state];
5571 bar_text_color = widget->style->fg[state];
5573 get_progress_area (widget,
5574 &progress_x, &progress_y,
5575 &progress_width, &progress_height);
5577 cr = gdk_cairo_create (entry->text_area);
5579 /* If the color is the same, or the progress area has a zero
5580 * size, then we only need to draw once. */
5581 if ((text_color.pixel == bar_text_color.pixel) ||
5582 ((progress_width == 0) || (progress_height == 0)))
5584 draw_text_with_color (entry, cr, &text_color);
5588 gdk_drawable_get_size (entry->text_area, &width, &height);
5590 cairo_rectangle (cr, 0, 0, width, height);
5594 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
5595 cairo_rectangle (cr, 0, 0, width, height);
5597 gdk_window_get_position (entry->text_area, &pos_x, &pos_y);
5598 progress_x -= pos_x;
5599 progress_y -= pos_y;
5601 cairo_rectangle (cr, progress_x, progress_y,
5602 progress_width, progress_height);
5604 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_WINDING);
5606 draw_text_with_color (entry, cr, &text_color);
5609 cairo_rectangle (cr, progress_x, progress_y,
5610 progress_width, progress_height);
5613 draw_text_with_color (entry, cr, &bar_text_color);
5621 draw_insertion_cursor (GtkEntry *entry,
5622 GdkRectangle *cursor_location,
5623 gboolean is_primary,
5624 PangoDirection direction,
5625 gboolean draw_arrow)
5627 GtkWidget *widget = GTK_WIDGET (entry);
5628 GtkTextDirection text_dir;
5630 if (direction == PANGO_DIRECTION_LTR)
5631 text_dir = GTK_TEXT_DIR_LTR;
5633 text_dir = GTK_TEXT_DIR_RTL;
5635 gtk_draw_insertion_cursor (widget, entry->text_area, NULL,
5637 is_primary, text_dir, draw_arrow);
5641 gtk_entry_draw_cursor (GtkEntry *entry,
5644 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
5645 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
5647 if (GTK_WIDGET_DRAWABLE (entry))
5649 GtkWidget *widget = GTK_WIDGET (entry);
5650 GdkRectangle cursor_location;
5651 gboolean split_cursor;
5652 PangoRectangle cursor_rect;
5653 GtkBorder inner_border;
5655 gint text_area_height;
5658 gboolean block_at_line_end;
5659 PangoLayout *layout;
5662 _gtk_entry_effective_inner_border (entry, &inner_border);
5664 xoffset = inner_border.left - entry->scroll_offset;
5666 gdk_drawable_get_size (entry->text_area, NULL, &text_area_height);
5668 layout = gtk_entry_ensure_layout (entry, TRUE);
5669 text = pango_layout_get_text (layout);
5670 cursor_index = g_utf8_offset_to_pointer (text, entry->current_pos + entry->preedit_cursor) - text;
5671 if (!entry->overwrite_mode)
5674 block = _gtk_text_util_get_block_cursor_location (layout,
5675 cursor_index, &cursor_rect, &block_at_line_end);
5679 gint strong_x, weak_x;
5680 PangoDirection dir1 = PANGO_DIRECTION_NEUTRAL;
5681 PangoDirection dir2 = PANGO_DIRECTION_NEUTRAL;
5685 gtk_entry_get_cursor_locations (entry, type, &strong_x, &weak_x);
5687 g_object_get (gtk_widget_get_settings (widget),
5688 "gtk-split-cursor", &split_cursor,
5691 dir1 = entry->resolved_dir;
5697 if (weak_x != strong_x)
5699 dir2 = (entry->resolved_dir == PANGO_DIRECTION_LTR) ? PANGO_DIRECTION_RTL : PANGO_DIRECTION_LTR;
5705 if (keymap_direction == entry->resolved_dir)
5711 cursor_location.x = xoffset + x1;
5712 cursor_location.y = inner_border.top;
5713 cursor_location.width = 0;
5714 cursor_location.height = text_area_height - inner_border.top - inner_border.bottom;
5716 draw_insertion_cursor (entry,
5717 &cursor_location, TRUE, dir1,
5718 dir2 != PANGO_DIRECTION_NEUTRAL);
5720 if (dir2 != PANGO_DIRECTION_NEUTRAL)
5722 cursor_location.x = xoffset + x2;
5723 draw_insertion_cursor (entry,
5724 &cursor_location, FALSE, dir2,
5728 else /* overwrite_mode */
5730 GdkColor cursor_color;
5735 get_layout_position (entry, &x, &y);
5737 rect.x = PANGO_PIXELS (cursor_rect.x) + x;
5738 rect.y = PANGO_PIXELS (cursor_rect.y) + y;
5739 rect.width = PANGO_PIXELS (cursor_rect.width);
5740 rect.height = PANGO_PIXELS (cursor_rect.height);
5742 cr = gdk_cairo_create (entry->text_area);
5744 _gtk_widget_get_cursor_color (widget, &cursor_color);
5745 gdk_cairo_set_source_color (cr, &cursor_color);
5746 gdk_cairo_rectangle (cr, &rect);
5749 if (!block_at_line_end)
5751 gdk_cairo_rectangle (cr, &rect);
5753 cairo_move_to (cr, x, y);
5754 gdk_cairo_set_source_color (cr, &widget->style->base[widget->state]);
5755 pango_cairo_show_layout (cr, layout);
5764 gtk_entry_queue_draw (GtkEntry *entry)
5766 if (GTK_WIDGET_DRAWABLE (entry))
5767 gdk_window_invalidate_rect (entry->text_area, NULL, FALSE);
5771 _gtk_entry_reset_im_context (GtkEntry *entry)
5773 if (entry->need_im_reset)
5775 entry->need_im_reset = FALSE;
5776 gtk_im_context_reset (entry->im_context);
5781 gtk_entry_find_position (GtkEntry *entry,
5784 PangoLayout *layout;
5785 PangoLayoutLine *line;
5792 layout = gtk_entry_ensure_layout (entry, TRUE);
5793 text = pango_layout_get_text (layout);
5794 cursor_index = g_utf8_offset_to_pointer (text, entry->current_pos) - text;
5796 line = pango_layout_get_lines_readonly (layout)->data;
5797 pango_layout_line_x_to_index (line, x * PANGO_SCALE, &index, &trailing);
5799 if (index >= cursor_index && entry->preedit_length)
5801 if (index >= cursor_index + entry->preedit_length)
5802 index -= entry->preedit_length;
5805 index = cursor_index;
5810 pos = g_utf8_pointer_to_offset (text, text + index);
5817 gtk_entry_get_cursor_locations (GtkEntry *entry,
5822 DisplayMode mode = gtk_entry_get_display_mode (entry);
5824 /* Nothing to display at all, so no cursor is relevant */
5825 if (mode == DISPLAY_BLANK)
5835 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
5836 const gchar *text = pango_layout_get_text (layout);
5837 PangoRectangle strong_pos, weak_pos;
5840 if (type == CURSOR_STANDARD)
5842 index = g_utf8_offset_to_pointer (text, entry->current_pos + entry->preedit_cursor) - text;
5844 else /* type == CURSOR_DND */
5846 index = g_utf8_offset_to_pointer (text, entry->dnd_position) - text;
5848 if (entry->dnd_position > entry->current_pos)
5850 if (mode == DISPLAY_NORMAL)
5851 index += entry->preedit_length;
5854 gint preedit_len_chars = g_utf8_strlen (text, -1) - gtk_entry_buffer_get_length (get_buffer (entry));
5855 index += preedit_len_chars * g_unichar_to_utf8 (entry->invisible_char, NULL);
5860 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
5863 *strong_x = strong_pos.x / PANGO_SCALE;
5866 *weak_x = weak_pos.x / PANGO_SCALE;
5871 gtk_entry_adjust_scroll (GtkEntry *entry)
5873 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
5874 gint min_offset, max_offset;
5875 gint text_area_width, text_width;
5876 GtkBorder inner_border;
5877 gint strong_x, weak_x;
5878 gint strong_xoffset, weak_xoffset;
5880 PangoLayout *layout;
5881 PangoLayoutLine *line;
5882 PangoRectangle logical_rect;
5884 if (!GTK_WIDGET_REALIZED (entry))
5887 _gtk_entry_effective_inner_border (entry, &inner_border);
5889 gdk_drawable_get_size (entry->text_area, &text_area_width, NULL);
5890 text_area_width -= inner_border.left + inner_border.right;
5891 if (text_area_width < 0)
5892 text_area_width = 0;
5894 layout = gtk_entry_ensure_layout (entry, TRUE);
5895 line = pango_layout_get_lines_readonly (layout)->data;
5897 pango_layout_line_get_extents (line, NULL, &logical_rect);
5899 /* Display as much text as we can */
5901 if (entry->resolved_dir == PANGO_DIRECTION_LTR)
5902 xalign = priv->xalign;
5904 xalign = 1.0 - priv->xalign;
5906 text_width = PANGO_PIXELS(logical_rect.width);
5908 if (text_width > text_area_width)
5911 max_offset = text_width - text_area_width;
5915 min_offset = (text_width - text_area_width) * xalign;
5916 max_offset = min_offset;
5919 entry->scroll_offset = CLAMP (entry->scroll_offset, min_offset, max_offset);
5921 /* And make sure cursors are on screen. Note that the cursor is
5922 * actually drawn one pixel into the INNER_BORDER space on
5923 * the right, when the scroll is at the utmost right. This
5924 * looks better to to me than confining the cursor inside the
5925 * border entirely, though it means that the cursor gets one
5926 * pixel closer to the edge of the widget on the right than
5927 * on the left. This might need changing if one changed
5928 * INNER_BORDER from 2 to 1, as one would do on a
5929 * small-screen-real-estate display.
5931 * We always make sure that the strong cursor is on screen, and
5932 * put the weak cursor on screen if possible.
5935 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, &weak_x);
5937 strong_xoffset = strong_x - entry->scroll_offset;
5939 if (strong_xoffset < 0)
5941 entry->scroll_offset += strong_xoffset;
5944 else if (strong_xoffset > text_area_width)
5946 entry->scroll_offset += strong_xoffset - text_area_width;
5947 strong_xoffset = text_area_width;
5950 weak_xoffset = weak_x - entry->scroll_offset;
5952 if (weak_xoffset < 0 && strong_xoffset - weak_xoffset <= text_area_width)
5954 entry->scroll_offset += weak_xoffset;
5956 else if (weak_xoffset > text_area_width &&
5957 strong_xoffset - (weak_xoffset - text_area_width) >= 0)
5959 entry->scroll_offset += weak_xoffset - text_area_width;
5962 g_object_notify (G_OBJECT (entry), "scroll-offset");
5966 gtk_entry_move_adjustments (GtkEntry *entry)
5968 PangoContext *context;
5969 PangoFontMetrics *metrics;
5970 gint x, layout_x, border_x, border_y;
5972 GtkAdjustment *adjustment;
5974 adjustment = g_object_get_qdata (G_OBJECT (entry), quark_cursor_hadjustment);
5978 /* Cursor position, layout offset, border width, and widget allocation */
5979 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &x, NULL);
5980 get_layout_position (entry, &layout_x, NULL);
5981 _gtk_entry_get_borders (entry, &border_x, &border_y);
5982 x += entry->widget.allocation.x + layout_x + border_x;
5984 /* Approximate width of a char, so user can see what is ahead/behind */
5985 context = gtk_widget_get_pango_context (GTK_WIDGET (entry));
5986 metrics = pango_context_get_metrics (context,
5987 entry->widget.style->font_desc,
5988 pango_context_get_language (context));
5989 char_width = pango_font_metrics_get_approximate_char_width (metrics) / PANGO_SCALE;
5992 gtk_adjustment_clamp_page (adjustment,
5993 x - (char_width + 1), /* one char + one pixel before */
5994 x + (char_width + 2)); /* one char + cursor + one pixel after */
5998 gtk_entry_move_visually (GtkEntry *entry,
6003 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6006 text = pango_layout_get_text (layout);
6008 index = g_utf8_offset_to_pointer (text, start) - text;
6012 int new_index, new_trailing;
6013 gboolean split_cursor;
6016 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
6017 "gtk-split-cursor", &split_cursor,
6024 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
6025 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
6027 strong = keymap_direction == entry->resolved_dir;
6032 pango_layout_move_cursor_visually (layout, strong, index, 0, 1, &new_index, &new_trailing);
6037 pango_layout_move_cursor_visually (layout, strong, index, 0, -1, &new_index, &new_trailing);
6043 else if (new_index != G_MAXINT)
6046 while (new_trailing--)
6047 index = g_utf8_next_char (text + index) - text;
6050 return g_utf8_pointer_to_offset (text, text + index);
6054 gtk_entry_move_logically (GtkEntry *entry,
6058 gint new_pos = start;
6061 length = gtk_entry_buffer_get_length (get_buffer (entry));
6063 /* Prevent any leak of information */
6064 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6066 new_pos = CLAMP (start + count, 0, length);
6070 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6071 PangoLogAttr *log_attrs;
6074 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6076 while (count > 0 && new_pos < length)
6080 while (new_pos < length && !log_attrs[new_pos].is_cursor_position);
6084 while (count < 0 && new_pos > 0)
6088 while (new_pos > 0 && !log_attrs[new_pos].is_cursor_position);
6100 gtk_entry_move_forward_word (GtkEntry *entry,
6102 gboolean allow_whitespace)
6104 gint new_pos = start;
6107 length = gtk_entry_buffer_get_length (get_buffer (entry));
6109 /* Prevent any leak of information */
6110 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6114 else if (new_pos < length)
6116 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6117 PangoLogAttr *log_attrs;
6120 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6122 /* Find the next word boundary */
6124 while (new_pos < n_attrs - 1 && !(log_attrs[new_pos].is_word_end ||
6125 (log_attrs[new_pos].is_word_start && allow_whitespace)))
6136 gtk_entry_move_backward_word (GtkEntry *entry,
6138 gboolean allow_whitespace)
6140 gint new_pos = start;
6142 /* Prevent any leak of information */
6143 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6149 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6150 PangoLogAttr *log_attrs;
6153 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6155 new_pos = start - 1;
6157 /* Find the previous word boundary */
6158 while (new_pos > 0 && !(log_attrs[new_pos].is_word_start ||
6159 (log_attrs[new_pos].is_word_end && allow_whitespace)))
6169 gtk_entry_delete_whitespace (GtkEntry *entry)
6171 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6172 PangoLogAttr *log_attrs;
6176 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6178 start = end = entry->current_pos;
6180 while (start > 0 && log_attrs[start-1].is_white)
6183 while (end < n_attrs && log_attrs[end].is_white)
6189 gtk_editable_delete_text (GTK_EDITABLE (entry), start, end);
6194 gtk_entry_select_word (GtkEntry *entry)
6196 gint start_pos = gtk_entry_move_backward_word (entry, entry->current_pos, TRUE);
6197 gint end_pos = gtk_entry_move_forward_word (entry, entry->current_pos, TRUE);
6199 gtk_editable_select_region (GTK_EDITABLE (entry), start_pos, end_pos);
6203 gtk_entry_select_line (GtkEntry *entry)
6205 gtk_editable_select_region (GTK_EDITABLE (entry), 0, -1);
6209 truncate_multiline (const gchar *text)
6214 text[length] && text[length] != '\n' && text[length] != '\r';
6221 paste_received (GtkClipboard *clipboard,
6225 GtkEntry *entry = GTK_ENTRY (data);
6226 GtkEditable *editable = GTK_EDITABLE (entry);
6227 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
6229 if (entry->button == 2)
6231 gint pos, start, end;
6232 pos = priv->insert_pos;
6233 gtk_editable_get_selection_bounds (editable, &start, &end);
6234 if (!((start <= pos && pos <= end) || (end <= pos && pos <= start)))
6235 gtk_editable_select_region (editable, pos, pos);
6240 gint pos, start, end;
6242 gboolean popup_completion;
6243 GtkEntryCompletion *completion;
6245 completion = gtk_entry_get_completion (entry);
6247 if (entry->truncate_multiline)
6248 length = truncate_multiline (text);
6250 /* only complete if the selection is at the end */
6251 popup_completion = (gtk_entry_buffer_get_length (get_buffer (entry)) ==
6252 MAX (entry->current_pos, entry->selection_bound));
6256 if (GTK_WIDGET_MAPPED (completion->priv->popup_window))
6257 _gtk_entry_completion_popdown (completion);
6259 if (!popup_completion && completion->priv->changed_id > 0)
6260 g_signal_handler_block (entry, completion->priv->changed_id);
6263 begin_change (entry);
6264 g_object_freeze_notify (G_OBJECT (entry));
6265 if (gtk_editable_get_selection_bounds (editable, &start, &end))
6266 gtk_editable_delete_text (editable, start, end);
6268 pos = entry->current_pos;
6269 gtk_editable_insert_text (editable, text, length, &pos);
6270 gtk_editable_set_position (editable, pos);
6271 g_object_thaw_notify (G_OBJECT (entry));
6275 !popup_completion && completion->priv->changed_id > 0)
6276 g_signal_handler_unblock (entry, completion->priv->changed_id);
6279 g_object_unref (entry);
6283 gtk_entry_paste (GtkEntry *entry,
6286 g_object_ref (entry);
6287 gtk_clipboard_request_text (gtk_widget_get_clipboard (GTK_WIDGET (entry), selection),
6288 paste_received, entry);
6292 primary_get_cb (GtkClipboard *clipboard,
6293 GtkSelectionData *selection_data,
6297 GtkEntry *entry = GTK_ENTRY (data);
6300 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end))
6302 gchar *str = gtk_entry_get_display_text (entry, start, end);
6303 gtk_selection_data_set_text (selection_data, str, -1);
6309 primary_clear_cb (GtkClipboard *clipboard,
6312 GtkEntry *entry = GTK_ENTRY (data);
6314 gtk_editable_select_region (GTK_EDITABLE (entry), entry->current_pos, entry->current_pos);
6318 gtk_entry_update_primary_selection (GtkEntry *entry)
6320 GtkTargetList *list;
6321 GtkTargetEntry *targets;
6322 GtkClipboard *clipboard;
6326 if (!GTK_WIDGET_REALIZED (entry))
6329 list = gtk_target_list_new (NULL, 0);
6330 gtk_target_list_add_text_targets (list, 0);
6332 targets = gtk_target_table_new_from_list (list, &n_targets);
6334 clipboard = gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_PRIMARY);
6336 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end))
6338 if (!gtk_clipboard_set_with_owner (clipboard, targets, n_targets,
6339 primary_get_cb, primary_clear_cb, G_OBJECT (entry)))
6340 primary_clear_cb (clipboard, entry);
6344 if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (entry))
6345 gtk_clipboard_clear (clipboard);
6348 gtk_target_table_free (targets, n_targets);
6349 gtk_target_list_unref (list);
6353 gtk_entry_clear (GtkEntry *entry,
6354 GtkEntryIconPosition icon_pos)
6356 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
6357 EntryIconInfo *icon_info = priv->icons[icon_pos];
6359 if (!icon_info || icon_info->storage_type == GTK_IMAGE_EMPTY)
6362 g_object_freeze_notify (G_OBJECT (entry));
6364 /* Explicitly check, as the pointer may become invalidated
6365 * during destruction.
6367 if (GDK_IS_WINDOW (icon_info->window))
6368 gdk_window_hide (icon_info->window);
6370 if (icon_info->pixbuf)
6372 g_object_unref (icon_info->pixbuf);
6373 icon_info->pixbuf = NULL;
6376 switch (icon_info->storage_type)
6378 case GTK_IMAGE_PIXBUF:
6379 g_object_notify (G_OBJECT (entry),
6380 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-pixbuf" : "secondary-icon-pixbuf");
6383 case GTK_IMAGE_STOCK:
6384 g_free (icon_info->stock_id);
6385 icon_info->stock_id = NULL;
6386 g_object_notify (G_OBJECT (entry),
6387 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-stock" : "secondary-icon-stock");
6390 case GTK_IMAGE_ICON_NAME:
6391 g_free (icon_info->icon_name);
6392 icon_info->icon_name = NULL;
6393 g_object_notify (G_OBJECT (entry),
6394 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-name" : "secondary-icon-name");
6397 case GTK_IMAGE_GICON:
6398 if (icon_info->gicon)
6400 g_object_unref (icon_info->gicon);
6401 icon_info->gicon = NULL;
6403 g_object_notify (G_OBJECT (entry),
6404 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-gicon" : "secondary-icon-gicon");
6408 g_assert_not_reached ();
6412 icon_info->storage_type = GTK_IMAGE_EMPTY;
6413 g_object_notify (G_OBJECT (entry),
6414 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-storage-type" : "secondary-icon-storage-type");
6416 g_object_thaw_notify (G_OBJECT (entry));
6420 gtk_entry_ensure_pixbuf (GtkEntry *entry,
6421 GtkEntryIconPosition icon_pos)
6423 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
6424 EntryIconInfo *icon_info = priv->icons[icon_pos];
6426 GtkIconTheme *icon_theme;
6427 GtkSettings *settings;
6432 if (!icon_info || icon_info->pixbuf)
6435 switch (icon_info->storage_type)
6437 case GTK_IMAGE_EMPTY:
6438 case GTK_IMAGE_PIXBUF:
6440 case GTK_IMAGE_STOCK:
6441 state = GTK_WIDGET_STATE (entry);
6442 GTK_WIDGET_STATE (entry) = GTK_STATE_NORMAL;
6443 icon_info->pixbuf = gtk_widget_render_icon (GTK_WIDGET (entry),
6444 icon_info->stock_id,
6447 if (!icon_info->pixbuf)
6448 icon_info->pixbuf = gtk_widget_render_icon (GTK_WIDGET (entry),
6449 GTK_STOCK_MISSING_IMAGE,
6452 GTK_WIDGET_STATE (entry) = state;
6455 case GTK_IMAGE_ICON_NAME:
6456 screen = gtk_widget_get_screen (GTK_WIDGET (entry));
6459 icon_theme = gtk_icon_theme_get_for_screen (screen);
6460 settings = gtk_settings_get_for_screen (screen);
6462 gtk_icon_size_lookup_for_settings (settings,
6466 icon_info->pixbuf = gtk_icon_theme_load_icon (icon_theme,
6467 icon_info->icon_name,
6468 MIN (width, height),
6471 if (icon_info->pixbuf == NULL)
6473 state = GTK_WIDGET_STATE (entry);
6474 GTK_WIDGET_STATE (entry) = GTK_STATE_NORMAL;
6475 icon_info->pixbuf = gtk_widget_render_icon (GTK_WIDGET (entry),
6476 GTK_STOCK_MISSING_IMAGE,
6479 GTK_WIDGET_STATE (entry) = state;
6484 case GTK_IMAGE_GICON:
6485 screen = gtk_widget_get_screen (GTK_WIDGET (entry));
6488 icon_theme = gtk_icon_theme_get_for_screen (screen);
6489 settings = gtk_settings_get_for_screen (screen);
6491 gtk_icon_size_lookup_for_settings (settings,
6495 info = gtk_icon_theme_lookup_by_gicon (icon_theme,
6497 MIN (width, height),
6498 GTK_ICON_LOOKUP_USE_BUILTIN);
6501 icon_info->pixbuf = gtk_icon_info_load_icon (info, NULL);
6502 gtk_icon_info_free (info);
6505 if (icon_info->pixbuf == NULL)
6507 state = GTK_WIDGET_STATE (entry);
6508 GTK_WIDGET_STATE (entry) = GTK_STATE_NORMAL;
6509 icon_info->pixbuf = gtk_widget_render_icon (GTK_WIDGET (entry),
6510 GTK_STOCK_MISSING_IMAGE,
6513 GTK_WIDGET_STATE (entry) = state;
6519 g_assert_not_reached ();
6523 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
6524 gdk_window_show_unraised (icon_info->window);
6534 * Creates a new entry.
6536 * Return value: a new #GtkEntry.
6539 gtk_entry_new (void)
6541 return g_object_new (GTK_TYPE_ENTRY, NULL);
6545 * gtk_entry_new_with_buffer:
6546 * @buffer: The buffer to use for the new #GtkEntry.
6548 * Creates a new entry with the specified text buffer.
6550 * Return value: a new #GtkEntry
6555 gtk_entry_new_with_buffer (GtkEntryBuffer *buffer)
6557 g_return_val_if_fail (GTK_IS_ENTRY_BUFFER (buffer), NULL);
6558 return g_object_new (GTK_TYPE_ENTRY, "buffer", buffer, NULL);
6562 * gtk_entry_new_with_max_length:
6563 * @max: the maximum length of the entry, or 0 for no maximum.
6564 * (other than the maximum length of entries.) The value passed in will
6565 * be clamped to the range 0-65536.
6567 * Creates a new #GtkEntry widget with the given maximum length.
6569 * Return value: a new #GtkEntry
6571 * Deprecated: Use gtk_entry_set_max_length() instead.
6574 gtk_entry_new_with_max_length (gint max)
6578 max = CLAMP (max, 0, GTK_ENTRY_BUFFER_MAX_SIZE);
6580 entry = g_object_new (GTK_TYPE_ENTRY, NULL);
6581 gtk_entry_buffer_set_max_length (get_buffer (entry), max);
6583 return GTK_WIDGET (entry);
6587 static GtkEntryBuffer*
6588 get_buffer (GtkEntry *entry)
6590 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
6592 if (priv->buffer == NULL)
6594 GtkEntryBuffer *buffer;
6595 buffer = gtk_entry_buffer_new (NULL, 0);
6596 gtk_entry_set_buffer (entry, buffer);
6597 g_object_unref (buffer);
6600 return priv->buffer;
6604 * gtk_entry_get_buffer:
6605 * @entry: a #GtkEntry
6607 * Get the #GtkEntryBuffer object which holds the text for
6612 * Returns: A #GtkEntryBuffer object.
6615 gtk_entry_get_buffer (GtkEntry *entry)
6617 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
6619 return get_buffer (entry);
6623 * gtk_entry_set_buffer:
6624 * @entry: a #GtkEntry
6625 * @buffer: a #GtkEntryBuffer
6627 * Set the #GtkEntryBuffer object which holds the text for
6633 gtk_entry_set_buffer (GtkEntry *entry,
6634 GtkEntryBuffer *buffer)
6636 GtkEntryPrivate *priv;
6639 g_return_if_fail (GTK_IS_ENTRY (entry));
6640 priv = GTK_ENTRY_GET_PRIVATE (entry);
6644 g_return_if_fail (GTK_IS_ENTRY_BUFFER (buffer));
6645 g_object_ref (buffer);
6650 buffer_disconnect_signals (entry);
6651 g_object_unref (priv->buffer);
6653 /* COMPAT: Deprecated. Not used. Setting these fields no longer necessary in GTK 3.x */
6655 entry->text_length = 0;
6656 entry->text_max_length = 0;
6659 priv->buffer = buffer;
6663 buffer_connect_signals (entry);
6665 /* COMPAT: Deprecated. Not used. Setting these fields no longer necessary in GTK 3.x */
6666 entry->text = (char*)gtk_entry_buffer_get_text (priv->buffer);
6667 entry->text_length = gtk_entry_buffer_get_length (priv->buffer);
6668 entry->text_max_length = gtk_entry_buffer_get_max_length (priv->buffer);
6671 obj = G_OBJECT (entry);
6672 g_object_freeze_notify (obj);
6673 g_object_notify (obj, "buffer");
6674 g_object_notify (obj, "text");
6675 g_object_notify (obj, "text-length");
6676 g_object_notify (obj, "max-length");
6677 g_object_notify (obj, "visibility");
6678 g_object_notify (obj, "invisible-char");
6679 g_object_notify (obj, "invisible-char-set");
6680 g_object_thaw_notify (obj);
6685 * gtk_entry_set_text:
6686 * @entry: a #GtkEntry
6687 * @text: the new text
6689 * Sets the text in the widget to the given
6690 * value, replacing the current contents.
6692 * See gtk_entry_buffer_set_text().
6695 gtk_entry_set_text (GtkEntry *entry,
6699 GtkEntryCompletion *completion;
6700 GtkEntryPrivate *priv;
6702 g_return_if_fail (GTK_IS_ENTRY (entry));
6703 g_return_if_fail (text != NULL);
6704 priv = GTK_ENTRY_GET_PRIVATE (entry);
6706 /* Actually setting the text will affect the cursor and selection;
6707 * if the contents don't actually change, this will look odd to the user.
6709 if (strcmp (gtk_entry_buffer_get_text (get_buffer (entry)), text) == 0)
6712 completion = gtk_entry_get_completion (entry);
6713 if (completion && completion->priv->changed_id > 0)
6714 g_signal_handler_block (entry, completion->priv->changed_id);
6716 begin_change (entry);
6717 g_object_freeze_notify (G_OBJECT (entry));
6718 gtk_editable_delete_text (GTK_EDITABLE (entry), 0, -1);
6720 gtk_editable_insert_text (GTK_EDITABLE (entry), text, strlen (text), &tmp_pos);
6721 g_object_thaw_notify (G_OBJECT (entry));
6724 if (completion && completion->priv->changed_id > 0)
6725 g_signal_handler_unblock (entry, completion->priv->changed_id);
6729 * gtk_entry_append_text:
6730 * @entry: a #GtkEntry
6731 * @text: the text to append
6733 * Appends the given text to the contents of the widget.
6735 * Deprecated: 2.0: Use gtk_editable_insert_text() instead.
6738 gtk_entry_append_text (GtkEntry *entry,
6741 GtkEntryPrivate *priv;
6744 g_return_if_fail (GTK_IS_ENTRY (entry));
6745 g_return_if_fail (text != NULL);
6746 priv = GTK_ENTRY_GET_PRIVATE (entry);
6748 tmp_pos = gtk_entry_buffer_get_length (get_buffer (entry));
6749 gtk_editable_insert_text (GTK_EDITABLE (entry), text, -1, &tmp_pos);
6753 * gtk_entry_prepend_text:
6754 * @entry: a #GtkEntry
6755 * @text: the text to prepend
6757 * Prepends the given text to the contents of the widget.
6759 * Deprecated: 2.0: Use gtk_editable_insert_text() instead.
6762 gtk_entry_prepend_text (GtkEntry *entry,
6767 g_return_if_fail (GTK_IS_ENTRY (entry));
6768 g_return_if_fail (text != NULL);
6771 gtk_editable_insert_text (GTK_EDITABLE (entry), text, -1, &tmp_pos);
6775 * gtk_entry_set_position:
6776 * @entry: a #GtkEntry
6777 * @position: the position of the cursor. The cursor is displayed
6778 * before the character with the given (base 0) index in the widget.
6779 * The value must be less than or equal to the number of characters
6780 * in the widget. A value of -1 indicates that the position should
6781 * be set after the last character in the entry. Note that this
6782 * position is in characters, not in bytes.
6784 * Sets the cursor position in an entry to the given value.
6786 * Deprecated: 2.0: Use gtk_editable_set_position() instead.
6789 gtk_entry_set_position (GtkEntry *entry,
6792 g_return_if_fail (GTK_IS_ENTRY (entry));
6794 gtk_editable_set_position (GTK_EDITABLE (entry), position);
6798 * gtk_entry_set_visibility:
6799 * @entry: a #GtkEntry
6800 * @visible: %TRUE if the contents of the entry are displayed
6803 * Sets whether the contents of the entry are visible or not.
6804 * When visibility is set to %FALSE, characters are displayed
6805 * as the invisible char, and will also appear that way when
6806 * the text in the entry widget is copied elsewhere.
6808 * By default, GTK+ picks the best invisible character available
6809 * in the current font, but it can be changed with
6810 * gtk_entry_set_invisible_char().
6813 gtk_entry_set_visibility (GtkEntry *entry,
6816 g_return_if_fail (GTK_IS_ENTRY (entry));
6818 visible = visible != FALSE;
6820 if (entry->visible != visible)
6822 entry->visible = visible;
6824 g_object_notify (G_OBJECT (entry), "visibility");
6825 gtk_entry_recompute (entry);
6830 * gtk_entry_get_visibility:
6831 * @entry: a #GtkEntry
6833 * Retrieves whether the text in @entry is visible. See
6834 * gtk_entry_set_visibility().
6836 * Return value: %TRUE if the text is currently visible
6839 gtk_entry_get_visibility (GtkEntry *entry)
6841 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
6843 return entry->visible;
6847 * gtk_entry_set_invisible_char:
6848 * @entry: a #GtkEntry
6849 * @ch: a Unicode character
6851 * Sets the character to use in place of the actual text when
6852 * gtk_entry_set_visibility() has been called to set text visibility
6853 * to %FALSE. i.e. this is the character used in "password mode" to
6854 * show the user how many characters have been typed. By default, GTK+
6855 * picks the best invisible char available in the current font. If you
6856 * set the invisible char to 0, then the user will get no feedback
6857 * at all; there will be no text on the screen as they type.
6860 gtk_entry_set_invisible_char (GtkEntry *entry,
6863 GtkEntryPrivate *priv;
6865 g_return_if_fail (GTK_IS_ENTRY (entry));
6867 priv = GTK_ENTRY_GET_PRIVATE (entry);
6869 if (!priv->invisible_char_set)
6871 priv->invisible_char_set = TRUE;
6872 g_object_notify (G_OBJECT (entry), "invisible-char-set");
6875 if (ch == entry->invisible_char)
6878 entry->invisible_char = ch;
6879 g_object_notify (G_OBJECT (entry), "invisible-char");
6880 gtk_entry_recompute (entry);
6884 * gtk_entry_get_invisible_char:
6885 * @entry: a #GtkEntry
6887 * Retrieves the character displayed in place of the real characters
6888 * for entries with visibility set to false. See gtk_entry_set_invisible_char().
6890 * Return value: the current invisible char, or 0, if the entry does not
6891 * show invisible text at all.
6894 gtk_entry_get_invisible_char (GtkEntry *entry)
6896 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
6898 return entry->invisible_char;
6902 * gtk_entry_unset_invisible_char:
6903 * @entry: a #GtkEntry
6905 * Unsets the invisible char previously set with
6906 * gtk_entry_set_invisible_char(). So that the
6907 * default invisible char is used again.
6912 gtk_entry_unset_invisible_char (GtkEntry *entry)
6914 GtkEntryPrivate *priv;
6917 g_return_if_fail (GTK_IS_ENTRY (entry));
6919 priv = GTK_ENTRY_GET_PRIVATE (entry);
6921 if (!priv->invisible_char_set)
6924 priv->invisible_char_set = FALSE;
6925 ch = find_invisible_char (GTK_WIDGET (entry));
6927 if (entry->invisible_char != ch)
6929 entry->invisible_char = ch;
6930 g_object_notify (G_OBJECT (entry), "invisible-char");
6933 g_object_notify (G_OBJECT (entry), "invisible-char-set");
6934 gtk_entry_recompute (entry);
6938 * gtk_entry_set_editable:
6939 * @entry: a #GtkEntry
6940 * @editable: %TRUE if the user is allowed to edit the text
6943 * Determines if the user can edit the text in the editable
6946 * Deprecated: 2.0: Use gtk_editable_set_editable() instead.
6949 gtk_entry_set_editable (GtkEntry *entry,
6952 g_return_if_fail (GTK_IS_ENTRY (entry));
6954 gtk_editable_set_editable (GTK_EDITABLE (entry), editable);
6958 * gtk_entry_set_overwrite_mode:
6959 * @entry: a #GtkEntry
6960 * @overwrite: new value
6962 * Sets whether the text is overwritten when typing in the #GtkEntry.
6967 gtk_entry_set_overwrite_mode (GtkEntry *entry,
6970 g_return_if_fail (GTK_IS_ENTRY (entry));
6972 if (entry->overwrite_mode == overwrite)
6975 gtk_entry_toggle_overwrite (entry);
6977 g_object_notify (G_OBJECT (entry), "overwrite-mode");
6981 * gtk_entry_get_overwrite_mode:
6982 * @entry: a #GtkEntry
6984 * Gets the value set by gtk_entry_set_overwrite_mode().
6986 * Return value: whether the text is overwritten when typing.
6991 gtk_entry_get_overwrite_mode (GtkEntry *entry)
6993 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
6995 return entry->overwrite_mode;
6999 * gtk_entry_get_text:
7000 * @entry: a #GtkEntry
7002 * Retrieves the contents of the entry widget.
7003 * See also gtk_editable_get_chars().
7005 * This is equivalent to:
7007 * <informalexample><programlisting>
7008 * gtk_entry_buffer_get_text (gtk_entry_get_buffer (entry));
7009 * </programlisting></informalexample>
7011 * Return value: a pointer to the contents of the widget as a
7012 * string. This string points to internally allocated
7013 * storage in the widget and must not be freed, modified or
7016 G_CONST_RETURN gchar*
7017 gtk_entry_get_text (GtkEntry *entry)
7019 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7020 return gtk_entry_buffer_get_text (get_buffer (entry));
7024 * gtk_entry_select_region:
7025 * @entry: a #GtkEntry
7026 * @start: the starting position
7027 * @end: the end position
7029 * Selects a region of text. The characters that are selected are
7030 * those characters at positions from @start_pos up to, but not
7031 * including @end_pos. If @end_pos is negative, then the the characters
7032 * selected will be those characters from @start_pos to the end of
7035 * Deprecated: 2.0: Use gtk_editable_select_region() instead.
7038 gtk_entry_select_region (GtkEntry *entry,
7042 gtk_editable_select_region (GTK_EDITABLE (entry), start, end);
7046 * gtk_entry_set_max_length:
7047 * @entry: a #GtkEntry
7048 * @max: the maximum length of the entry, or 0 for no maximum.
7049 * (other than the maximum length of entries.) The value passed in will
7050 * be clamped to the range 0-65536.
7052 * Sets the maximum allowed length of the contents of the widget. If
7053 * the current contents are longer than the given length, then they
7054 * will be truncated to fit.
7056 * This is equivalent to:
7058 * <informalexample><programlisting>
7059 * gtk_entry_buffer_set_max_length (gtk_entry_get_buffer (entry), max);
7060 * </programlisting></informalexample>
7063 gtk_entry_set_max_length (GtkEntry *entry,
7066 g_return_if_fail (GTK_IS_ENTRY (entry));
7067 gtk_entry_buffer_set_max_length (get_buffer (entry), max);
7071 * gtk_entry_get_max_length:
7072 * @entry: a #GtkEntry
7074 * Retrieves the maximum allowed length of the text in
7075 * @entry. See gtk_entry_set_max_length().
7077 * This is equivalent to:
7079 * <informalexample><programlisting>
7080 * gtk_entry_buffer_get_max_length (gtk_entry_get_buffer (entry));
7081 * </programlisting></informalexample>
7083 * Return value: the maximum allowed number of characters
7084 * in #GtkEntry, or 0 if there is no maximum.
7087 gtk_entry_get_max_length (GtkEntry *entry)
7089 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7090 return gtk_entry_buffer_get_max_length (get_buffer (entry));
7094 * gtk_entry_get_text_length:
7095 * @entry: a #GtkEntry
7097 * Retrieves the current length of the text in
7100 * This is equivalent to:
7102 * <informalexample><programlisting>
7103 * gtk_entry_buffer_get_length (gtk_entry_get_buffer (entry));
7104 * </programlisting></informalexample>
7106 * Return value: the current number of characters
7107 * in #GtkEntry, or 0 if there are none.
7112 gtk_entry_get_text_length (GtkEntry *entry)
7114 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7115 return gtk_entry_buffer_get_length (get_buffer (entry));
7119 * gtk_entry_set_activates_default:
7120 * @entry: a #GtkEntry
7121 * @setting: %TRUE to activate window's default widget on Enter keypress
7123 * If @setting is %TRUE, pressing Enter in the @entry will activate the default
7124 * widget for the window containing the entry. This usually means that
7125 * the dialog box containing the entry will be closed, since the default
7126 * widget is usually one of the dialog buttons.
7128 * (For experts: if @setting is %TRUE, the entry calls
7129 * gtk_window_activate_default() on the window containing the entry, in
7130 * the default handler for the #GtkWidget::activate signal.)
7133 gtk_entry_set_activates_default (GtkEntry *entry,
7136 g_return_if_fail (GTK_IS_ENTRY (entry));
7137 setting = setting != FALSE;
7139 if (setting != entry->activates_default)
7141 entry->activates_default = setting;
7142 g_object_notify (G_OBJECT (entry), "activates-default");
7147 * gtk_entry_get_activates_default:
7148 * @entry: a #GtkEntry
7150 * Retrieves the value set by gtk_entry_set_activates_default().
7152 * Return value: %TRUE if the entry will activate the default widget
7155 gtk_entry_get_activates_default (GtkEntry *entry)
7157 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7159 return entry->activates_default;
7163 * gtk_entry_set_width_chars:
7164 * @entry: a #GtkEntry
7165 * @n_chars: width in chars
7167 * Changes the size request of the entry to be about the right size
7168 * for @n_chars characters. Note that it changes the size
7169 * <emphasis>request</emphasis>, the size can still be affected by
7170 * how you pack the widget into containers. If @n_chars is -1, the
7171 * size reverts to the default entry size.
7174 gtk_entry_set_width_chars (GtkEntry *entry,
7177 g_return_if_fail (GTK_IS_ENTRY (entry));
7179 if (entry->width_chars != n_chars)
7181 entry->width_chars = n_chars;
7182 g_object_notify (G_OBJECT (entry), "width-chars");
7183 gtk_widget_queue_resize (GTK_WIDGET (entry));
7188 * gtk_entry_get_width_chars:
7189 * @entry: a #GtkEntry
7191 * Gets the value set by gtk_entry_set_width_chars().
7193 * Return value: number of chars to request space for, or negative if unset
7196 gtk_entry_get_width_chars (GtkEntry *entry)
7198 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7200 return entry->width_chars;
7204 * gtk_entry_set_has_frame:
7205 * @entry: a #GtkEntry
7206 * @setting: new value
7208 * Sets whether the entry has a beveled frame around it.
7211 gtk_entry_set_has_frame (GtkEntry *entry,
7214 g_return_if_fail (GTK_IS_ENTRY (entry));
7216 setting = (setting != FALSE);
7218 if (entry->has_frame == setting)
7221 gtk_widget_queue_resize (GTK_WIDGET (entry));
7222 entry->has_frame = setting;
7223 g_object_notify (G_OBJECT (entry), "has-frame");
7227 * gtk_entry_get_has_frame:
7228 * @entry: a #GtkEntry
7230 * Gets the value set by gtk_entry_set_has_frame().
7232 * Return value: whether the entry has a beveled frame
7235 gtk_entry_get_has_frame (GtkEntry *entry)
7237 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7239 return entry->has_frame;
7243 * gtk_entry_set_inner_border:
7244 * @entry: a #GtkEntry
7245 * @border: (allow-none): a #GtkBorder, or %NULL
7247 * Sets %entry's inner-border property to %border, or clears it if %NULL
7248 * is passed. The inner-border is the area around the entry's text, but
7251 * If set, this property overrides the inner-border style property.
7252 * Overriding the style-provided border is useful when you want to do
7253 * in-place editing of some text in a canvas or list widget, where
7254 * pixel-exact positioning of the entry is important.
7259 gtk_entry_set_inner_border (GtkEntry *entry,
7260 const GtkBorder *border)
7262 g_return_if_fail (GTK_IS_ENTRY (entry));
7264 gtk_widget_queue_resize (GTK_WIDGET (entry));
7267 g_object_set_qdata_full (G_OBJECT (entry), quark_inner_border,
7268 gtk_border_copy (border),
7269 (GDestroyNotify) gtk_border_free);
7271 g_object_set_qdata (G_OBJECT (entry), quark_inner_border, NULL);
7273 g_object_notify (G_OBJECT (entry), "inner-border");
7277 * gtk_entry_get_inner_border:
7278 * @entry: a #GtkEntry
7280 * This function returns the entry's #GtkEntry:inner-border property. See
7281 * gtk_entry_set_inner_border() for more information.
7283 * Return value: (transfer none): the entry's #GtkBorder, or %NULL if none was set.
7287 G_CONST_RETURN GtkBorder *
7288 gtk_entry_get_inner_border (GtkEntry *entry)
7290 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7292 return g_object_get_qdata (G_OBJECT (entry), quark_inner_border);
7296 * gtk_entry_get_layout:
7297 * @entry: a #GtkEntry
7299 * Gets the #PangoLayout used to display the entry.
7300 * The layout is useful to e.g. convert text positions to
7301 * pixel positions, in combination with gtk_entry_get_layout_offsets().
7302 * The returned layout is owned by the entry and must not be
7303 * modified or freed by the caller.
7305 * Keep in mind that the layout text may contain a preedit string, so
7306 * gtk_entry_layout_index_to_text_index() and
7307 * gtk_entry_text_index_to_layout_index() are needed to convert byte
7308 * indices in the layout to byte indices in the entry contents.
7310 * Return value: (transfer none): the #PangoLayout for this entry
7313 gtk_entry_get_layout (GtkEntry *entry)
7315 PangoLayout *layout;
7317 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7319 layout = gtk_entry_ensure_layout (entry, TRUE);
7326 * gtk_entry_layout_index_to_text_index:
7327 * @entry: a #GtkEntry
7328 * @layout_index: byte index into the entry layout text
7330 * Converts from a position in the entry contents (returned
7331 * by gtk_entry_get_text()) to a position in the
7332 * entry's #PangoLayout (returned by gtk_entry_get_layout(),
7333 * with text retrieved via pango_layout_get_text()).
7335 * Return value: byte index into the entry contents
7338 gtk_entry_layout_index_to_text_index (GtkEntry *entry,
7341 PangoLayout *layout;
7345 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7347 layout = gtk_entry_ensure_layout (entry, TRUE);
7348 text = pango_layout_get_text (layout);
7349 cursor_index = g_utf8_offset_to_pointer (text, entry->current_pos) - text;
7351 if (layout_index >= cursor_index && entry->preedit_length)
7353 if (layout_index >= cursor_index + entry->preedit_length)
7354 layout_index -= entry->preedit_length;
7356 layout_index = cursor_index;
7359 return layout_index;
7363 * gtk_entry_text_index_to_layout_index:
7364 * @entry: a #GtkEntry
7365 * @text_index: byte index into the entry contents
7367 * Converts from a position in the entry's #PangoLayout (returned by
7368 * gtk_entry_get_layout()) to a position in the entry contents
7369 * (returned by gtk_entry_get_text()).
7371 * Return value: byte index into the entry layout text
7374 gtk_entry_text_index_to_layout_index (GtkEntry *entry,
7377 PangoLayout *layout;
7380 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7382 layout = gtk_entry_ensure_layout (entry, TRUE);
7383 text = pango_layout_get_text (layout);
7384 cursor_index = g_utf8_offset_to_pointer (text, entry->current_pos) - text;
7386 if (text_index > cursor_index)
7387 text_index += entry->preedit_length;
7393 * gtk_entry_get_layout_offsets:
7394 * @entry: a #GtkEntry
7395 * @x: location to store X offset of layout, or %NULL
7396 * @y: location to store Y offset of layout, or %NULL
7399 * Obtains the position of the #PangoLayout used to render text
7400 * in the entry, in widget coordinates. Useful if you want to line
7401 * up the text in an entry with some other text, e.g. when using the
7402 * entry to implement editable cells in a sheet widget.
7404 * Also useful to convert mouse events into coordinates inside the
7405 * #PangoLayout, e.g. to take some action if some part of the entry text
7408 * Note that as the user scrolls around in the entry the offsets will
7409 * change; you'll need to connect to the "notify::scroll-offset"
7410 * signal to track this. Remember when using the #PangoLayout
7411 * functions you need to convert to and from pixels using
7412 * PANGO_PIXELS() or #PANGO_SCALE.
7414 * Keep in mind that the layout text may contain a preedit string, so
7415 * gtk_entry_layout_index_to_text_index() and
7416 * gtk_entry_text_index_to_layout_index() are needed to convert byte
7417 * indices in the layout to byte indices in the entry contents.
7420 gtk_entry_get_layout_offsets (GtkEntry *entry,
7424 gint text_area_x, text_area_y;
7426 g_return_if_fail (GTK_IS_ENTRY (entry));
7428 /* this gets coords relative to text area */
7429 get_layout_position (entry, x, y);
7431 /* convert to widget coords */
7432 gtk_entry_get_text_area_size (entry, &text_area_x, &text_area_y, NULL, NULL);
7443 * gtk_entry_set_alignment:
7444 * @entry: a #GtkEntry
7445 * @xalign: The horizontal alignment, from 0 (left) to 1 (right).
7446 * Reversed for RTL layouts
7448 * Sets the alignment for the contents of the entry. This controls
7449 * the horizontal positioning of the contents when the displayed
7450 * text is shorter than the width of the entry.
7455 gtk_entry_set_alignment (GtkEntry *entry, gfloat xalign)
7457 GtkEntryPrivate *priv;
7459 g_return_if_fail (GTK_IS_ENTRY (entry));
7461 priv = GTK_ENTRY_GET_PRIVATE (entry);
7465 else if (xalign > 1.0)
7468 if (xalign != priv->xalign)
7470 priv->xalign = xalign;
7472 gtk_entry_recompute (entry);
7474 g_object_notify (G_OBJECT (entry), "xalign");
7479 * gtk_entry_get_alignment:
7480 * @entry: a #GtkEntry
7482 * Gets the value set by gtk_entry_set_alignment().
7484 * Return value: the alignment
7489 gtk_entry_get_alignment (GtkEntry *entry)
7491 GtkEntryPrivate *priv;
7493 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
7495 priv = GTK_ENTRY_GET_PRIVATE (entry);
7497 return priv->xalign;
7501 * gtk_entry_set_icon_from_pixbuf:
7502 * @entry: a #GtkEntry
7503 * @icon_pos: Icon position
7504 * @pixbuf: A #GdkPixbuf, or %NULL
7506 * Sets the icon shown in the specified position using a pixbuf.
7508 * If @pixbuf is %NULL, no icon will be shown in the specified position.
7513 gtk_entry_set_icon_from_pixbuf (GtkEntry *entry,
7514 GtkEntryIconPosition icon_pos,
7517 GtkEntryPrivate *priv;
7518 EntryIconInfo *icon_info;
7520 g_return_if_fail (GTK_IS_ENTRY (entry));
7521 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7523 priv = GTK_ENTRY_GET_PRIVATE (entry);
7525 if ((icon_info = priv->icons[icon_pos]) == NULL)
7526 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7528 g_object_freeze_notify (G_OBJECT (entry));
7531 g_object_ref (pixbuf);
7533 gtk_entry_clear (entry, icon_pos);
7537 icon_info->storage_type = GTK_IMAGE_PIXBUF;
7538 icon_info->pixbuf = pixbuf;
7540 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7542 g_object_notify (G_OBJECT (entry), "primary-icon-pixbuf");
7543 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7547 g_object_notify (G_OBJECT (entry), "secondary-icon-pixbuf");
7548 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7551 if (GTK_WIDGET_MAPPED (entry))
7552 gdk_window_show_unraised (icon_info->window);
7555 gtk_entry_ensure_pixbuf (entry, icon_pos);
7557 if (GTK_WIDGET_VISIBLE (entry))
7558 gtk_widget_queue_resize (GTK_WIDGET (entry));
7560 g_object_thaw_notify (G_OBJECT (entry));
7564 * gtk_entry_set_icon_from_stock:
7565 * @entry: A #GtkEntry
7566 * @icon_pos: Icon position
7567 * @stock_id: The name of the stock item, or %NULL
7569 * Sets the icon shown in the entry at the specified position from
7572 * If @stock_id is %NULL, no icon will be shown in the specified position.
7577 gtk_entry_set_icon_from_stock (GtkEntry *entry,
7578 GtkEntryIconPosition icon_pos,
7579 const gchar *stock_id)
7581 GtkEntryPrivate *priv;
7582 EntryIconInfo *icon_info;
7585 g_return_if_fail (GTK_IS_ENTRY (entry));
7586 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7588 priv = GTK_ENTRY_GET_PRIVATE (entry);
7590 if ((icon_info = priv->icons[icon_pos]) == NULL)
7591 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7593 g_object_freeze_notify (G_OBJECT (entry));
7595 gtk_widget_ensure_style (GTK_WIDGET (entry));
7597 /* need to dup before clearing */
7598 new_id = g_strdup (stock_id);
7600 gtk_entry_clear (entry, icon_pos);
7604 icon_info->storage_type = GTK_IMAGE_STOCK;
7605 icon_info->stock_id = new_id;
7607 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7609 g_object_notify (G_OBJECT (entry), "primary-icon-stock");
7610 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7614 g_object_notify (G_OBJECT (entry), "secondary-icon-stock");
7615 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7618 if (GTK_WIDGET_MAPPED (entry))
7619 gdk_window_show_unraised (icon_info->window);
7622 gtk_entry_ensure_pixbuf (entry, icon_pos);
7624 if (GTK_WIDGET_VISIBLE (entry))
7625 gtk_widget_queue_resize (GTK_WIDGET (entry));
7627 g_object_thaw_notify (G_OBJECT (entry));
7631 * gtk_entry_set_icon_from_icon_name:
7632 * @entry: A #GtkEntry
7633 * @icon_pos: The position at which to set the icon
7634 * @icon_name: An icon name, or %NULL
7636 * Sets the icon shown in the entry at the specified position
7637 * from the current icon theme.
7639 * If the icon name isn't known, a "broken image" icon will be displayed
7642 * If @icon_name is %NULL, no icon will be shown in the specified position.
7647 gtk_entry_set_icon_from_icon_name (GtkEntry *entry,
7648 GtkEntryIconPosition icon_pos,
7649 const gchar *icon_name)
7651 GtkEntryPrivate *priv;
7652 EntryIconInfo *icon_info;
7655 g_return_if_fail (GTK_IS_ENTRY (entry));
7656 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7658 priv = GTK_ENTRY_GET_PRIVATE (entry);
7660 if ((icon_info = priv->icons[icon_pos]) == NULL)
7661 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7663 g_object_freeze_notify (G_OBJECT (entry));
7665 gtk_widget_ensure_style (GTK_WIDGET (entry));
7667 /* need to dup before clearing */
7668 new_name = g_strdup (icon_name);
7670 gtk_entry_clear (entry, icon_pos);
7672 if (new_name != NULL)
7674 icon_info->storage_type = GTK_IMAGE_ICON_NAME;
7675 icon_info->icon_name = new_name;
7677 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7679 g_object_notify (G_OBJECT (entry), "primary-icon-name");
7680 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7684 g_object_notify (G_OBJECT (entry), "secondary-icon-name");
7685 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7688 if (GTK_WIDGET_MAPPED (entry))
7689 gdk_window_show_unraised (icon_info->window);
7692 gtk_entry_ensure_pixbuf (entry, icon_pos);
7694 if (GTK_WIDGET_VISIBLE (entry))
7695 gtk_widget_queue_resize (GTK_WIDGET (entry));
7697 g_object_thaw_notify (G_OBJECT (entry));
7701 * gtk_entry_set_icon_from_gicon:
7702 * @entry: A #GtkEntry
7703 * @icon_pos: The position at which to set the icon
7704 * @icon: The icon to set, or %NULL
7706 * Sets the icon shown in the entry at the specified position
7707 * from the current icon theme.
7708 * If the icon isn't known, a "broken image" icon will be displayed
7711 * If @icon is %NULL, no icon will be shown in the specified position.
7716 gtk_entry_set_icon_from_gicon (GtkEntry *entry,
7717 GtkEntryIconPosition icon_pos,
7720 GtkEntryPrivate *priv;
7721 EntryIconInfo *icon_info;
7723 g_return_if_fail (GTK_IS_ENTRY (entry));
7724 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7726 priv = GTK_ENTRY_GET_PRIVATE (entry);
7728 if ((icon_info = priv->icons[icon_pos]) == NULL)
7729 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7731 g_object_freeze_notify (G_OBJECT (entry));
7733 /* need to ref before clearing */
7735 g_object_ref (icon);
7737 gtk_entry_clear (entry, icon_pos);
7741 icon_info->storage_type = GTK_IMAGE_GICON;
7742 icon_info->gicon = icon;
7744 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7746 g_object_notify (G_OBJECT (entry), "primary-icon-gicon");
7747 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7751 g_object_notify (G_OBJECT (entry), "secondary-icon-gicon");
7752 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7755 if (GTK_WIDGET_MAPPED (entry))
7756 gdk_window_show_unraised (icon_info->window);
7759 gtk_entry_ensure_pixbuf (entry, icon_pos);
7761 if (GTK_WIDGET_VISIBLE (entry))
7762 gtk_widget_queue_resize (GTK_WIDGET (entry));
7764 g_object_thaw_notify (G_OBJECT (entry));
7768 * gtk_entry_set_icon_activatable:
7769 * @entry: A #GtkEntry
7770 * @icon_pos: Icon position
7771 * @activatable: %TRUE if the icon should be activatable
7773 * Sets whether the icon is activatable.
7778 gtk_entry_set_icon_activatable (GtkEntry *entry,
7779 GtkEntryIconPosition icon_pos,
7780 gboolean activatable)
7782 GtkEntryPrivate *priv;
7783 EntryIconInfo *icon_info;
7785 g_return_if_fail (GTK_IS_ENTRY (entry));
7786 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7788 priv = GTK_ENTRY_GET_PRIVATE (entry);
7790 if ((icon_info = priv->icons[icon_pos]) == NULL)
7791 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7793 activatable = activatable != FALSE;
7795 if (icon_info->nonactivatable != !activatable)
7797 icon_info->nonactivatable = !activatable;
7799 if (GTK_WIDGET_REALIZED (GTK_WIDGET (entry)))
7800 update_cursors (GTK_WIDGET (entry));
7802 g_object_notify (G_OBJECT (entry),
7803 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-activatable" : "secondary-icon-activatable");
7808 * gtk_entry_get_icon_activatable:
7809 * @entry: a #GtkEntry
7810 * @icon_pos: Icon position
7812 * Returns whether the icon is activatable.
7814 * Returns: %TRUE if the icon is activatable.
7819 gtk_entry_get_icon_activatable (GtkEntry *entry,
7820 GtkEntryIconPosition icon_pos)
7822 GtkEntryPrivate *priv;
7823 EntryIconInfo *icon_info;
7825 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7826 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), FALSE);
7828 priv = GTK_ENTRY_GET_PRIVATE (entry);
7829 icon_info = priv->icons[icon_pos];
7831 return (icon_info != NULL && !icon_info->nonactivatable);
7835 * gtk_entry_get_icon_pixbuf:
7836 * @entry: A #GtkEntry
7837 * @icon_pos: Icon position
7839 * Retrieves the image used for the icon.
7841 * Unlike the other methods of setting and getting icon data, this
7842 * method will work regardless of whether the icon was set using a
7843 * #GdkPixbuf, a #GIcon, a stock item, or an icon name.
7845 * Returns: A #GdkPixbuf, or %NULL if no icon is set for this position.
7850 gtk_entry_get_icon_pixbuf (GtkEntry *entry,
7851 GtkEntryIconPosition icon_pos)
7853 GtkEntryPrivate *priv;
7854 EntryIconInfo *icon_info;
7856 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7857 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7859 priv = GTK_ENTRY_GET_PRIVATE (entry);
7860 icon_info = priv->icons[icon_pos];
7865 gtk_entry_ensure_pixbuf (entry, icon_pos);
7867 return icon_info->pixbuf;
7871 * gtk_entry_get_icon_gicon:
7872 * @entry: A #GtkEntry
7873 * @icon_pos: Icon position
7875 * Retrieves the #GIcon used for the icon, or %NULL if there is
7876 * no icon or if the icon was set by some other method (e.g., by
7877 * stock, pixbuf, or icon name).
7879 * Returns: A #GIcon, or %NULL if no icon is set or if the icon
7885 gtk_entry_get_icon_gicon (GtkEntry *entry,
7886 GtkEntryIconPosition icon_pos)
7888 GtkEntryPrivate *priv;
7889 EntryIconInfo *icon_info;
7891 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7892 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7894 priv = GTK_ENTRY_GET_PRIVATE (entry);
7895 icon_info = priv->icons[icon_pos];
7900 return icon_info->storage_type == GTK_IMAGE_GICON ? icon_info->gicon : NULL;
7904 * gtk_entry_get_icon_stock:
7905 * @entry: A #GtkEntry
7906 * @icon_pos: Icon position
7908 * Retrieves the stock id used for the icon, or %NULL if there is
7909 * no icon or if the icon was set by some other method (e.g., by
7910 * pixbuf, icon name or gicon).
7912 * Returns: A stock id, or %NULL if no icon is set or if the icon
7913 * wasn't set from a stock id
7918 gtk_entry_get_icon_stock (GtkEntry *entry,
7919 GtkEntryIconPosition icon_pos)
7921 GtkEntryPrivate *priv;
7922 EntryIconInfo *icon_info;
7924 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7925 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7927 priv = GTK_ENTRY_GET_PRIVATE (entry);
7928 icon_info = priv->icons[icon_pos];
7933 return icon_info->storage_type == GTK_IMAGE_STOCK ? icon_info->stock_id : NULL;
7937 * gtk_entry_get_icon_name:
7938 * @entry: A #GtkEntry
7939 * @icon_pos: Icon position
7941 * Retrieves the icon name used for the icon, or %NULL if there is
7942 * no icon or if the icon was set by some other method (e.g., by
7943 * pixbuf, stock or gicon).
7945 * Returns: An icon name, or %NULL if no icon is set or if the icon
7946 * wasn't set from an icon name
7951 gtk_entry_get_icon_name (GtkEntry *entry,
7952 GtkEntryIconPosition icon_pos)
7954 GtkEntryPrivate *priv;
7955 EntryIconInfo *icon_info;
7957 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7958 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7960 priv = GTK_ENTRY_GET_PRIVATE (entry);
7961 icon_info = priv->icons[icon_pos];
7966 return icon_info->storage_type == GTK_IMAGE_ICON_NAME ? icon_info->icon_name : NULL;
7970 * gtk_entry_set_icon_sensitive:
7971 * @entry: A #GtkEntry
7972 * @icon_pos: Icon position
7973 * @sensitive: Specifies whether the icon should appear
7974 * sensitive or insensitive
7976 * Sets the sensitivity for the specified icon.
7981 gtk_entry_set_icon_sensitive (GtkEntry *entry,
7982 GtkEntryIconPosition icon_pos,
7985 GtkEntryPrivate *priv;
7986 EntryIconInfo *icon_info;
7988 g_return_if_fail (GTK_IS_ENTRY (entry));
7989 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7991 priv = GTK_ENTRY_GET_PRIVATE (entry);
7993 if ((icon_info = priv->icons[icon_pos]) == NULL)
7994 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7996 if (icon_info->insensitive != !sensitive)
7998 icon_info->insensitive = !sensitive;
8000 icon_info->pressed = FALSE;
8001 icon_info->prelight = FALSE;
8003 if (GTK_WIDGET_REALIZED (GTK_WIDGET (entry)))
8004 update_cursors (GTK_WIDGET (entry));
8006 gtk_widget_queue_draw (GTK_WIDGET (entry));
8008 g_object_notify (G_OBJECT (entry),
8009 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-sensitive" : "secondary-icon-sensitive");
8014 * gtk_entry_get_icon_sensitive:
8015 * @entry: a #GtkEntry
8016 * @icon_pos: Icon position
8018 * Returns whether the icon appears sensitive or insensitive.
8020 * Returns: %TRUE if the icon is sensitive.
8025 gtk_entry_get_icon_sensitive (GtkEntry *entry,
8026 GtkEntryIconPosition icon_pos)
8028 GtkEntryPrivate *priv;
8029 EntryIconInfo *icon_info;
8031 g_return_val_if_fail (GTK_IS_ENTRY (entry), TRUE);
8032 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), TRUE);
8034 priv = GTK_ENTRY_GET_PRIVATE (entry);
8035 icon_info = priv->icons[icon_pos];
8037 return (!icon_info || !icon_info->insensitive);
8042 * gtk_entry_get_icon_storage_type:
8043 * @entry: a #GtkEntry
8044 * @icon_pos: Icon position
8046 * Gets the type of representation being used by the icon
8047 * to store image data. If the icon has no image data,
8048 * the return value will be %GTK_IMAGE_EMPTY.
8050 * Return value: image representation being used
8055 gtk_entry_get_icon_storage_type (GtkEntry *entry,
8056 GtkEntryIconPosition icon_pos)
8058 GtkEntryPrivate *priv;
8059 EntryIconInfo *icon_info;
8061 g_return_val_if_fail (GTK_IS_ENTRY (entry), GTK_IMAGE_EMPTY);
8062 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), GTK_IMAGE_EMPTY);
8064 priv = GTK_ENTRY_GET_PRIVATE (entry);
8065 icon_info = priv->icons[icon_pos];
8068 return GTK_IMAGE_EMPTY;
8070 return icon_info->storage_type;
8074 * gtk_entry_get_icon_at_pos:
8075 * @entry: a #GtkEntry
8076 * @x: the x coordinate of the position to find
8077 * @y: the y coordinate of the position to find
8079 * Finds the icon at the given position and return its index.
8080 * If @x, @y doesn't lie inside an icon, -1 is returned.
8081 * This function is intended for use in a #GtkWidget::query-tooltip
8084 * Returns: the index of the icon at the given position, or -1
8089 gtk_entry_get_icon_at_pos (GtkEntry *entry,
8093 GtkAllocation primary;
8094 GtkAllocation secondary;
8096 g_return_val_if_fail (GTK_IS_ENTRY (entry), -1);
8098 get_icon_allocations (entry, &primary, &secondary);
8100 if (primary.x <= x && x < primary.x + primary.width &&
8101 primary.y <= y && y < primary.y + primary.height)
8102 return GTK_ENTRY_ICON_PRIMARY;
8104 if (secondary.x <= x && x < secondary.x + secondary.width &&
8105 secondary.y <= y && y < secondary.y + secondary.height)
8106 return GTK_ENTRY_ICON_SECONDARY;
8112 * gtk_entry_set_icon_drag_source:
8113 * @entry: a #GtkIconEntry
8114 * @icon_pos: icon position
8115 * @target_list: the targets (data formats) in which the data can be provided
8116 * @actions: a bitmask of the allowed drag actions
8118 * Sets up the icon at the given position so that GTK+ will start a drag
8119 * operation when the user clicks and drags the icon.
8121 * To handle the drag operation, you need to connect to the usual
8122 * #GtkWidget::drag-data-get (or possibly #GtkWidget::drag-data-delete)
8123 * signal, and use gtk_entry_get_current_icon_drag_source() in
8124 * your signal handler to find out if the drag was started from
8127 * By default, GTK+ uses the icon as the drag icon. You can use the
8128 * #GtkWidget::drag-begin signal to set a different icon. Note that you
8129 * have to use g_signal_connect_after() to ensure that your signal handler
8130 * gets executed after the default handler.
8135 gtk_entry_set_icon_drag_source (GtkEntry *entry,
8136 GtkEntryIconPosition icon_pos,
8137 GtkTargetList *target_list,
8138 GdkDragAction actions)
8140 GtkEntryPrivate *priv;
8141 EntryIconInfo *icon_info;
8143 g_return_if_fail (GTK_IS_ENTRY (entry));
8144 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8146 priv = GTK_ENTRY_GET_PRIVATE (entry);
8148 if ((icon_info = priv->icons[icon_pos]) == NULL)
8149 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8151 if (icon_info->target_list)
8152 gtk_target_list_unref (icon_info->target_list);
8153 icon_info->target_list = target_list;
8154 if (icon_info->target_list)
8155 gtk_target_list_ref (icon_info->target_list);
8157 icon_info->actions = actions;
8161 * gtk_entry_get_current_icon_drag_source:
8162 * @entry: a #GtkIconEntry
8164 * Returns the index of the icon which is the source of the current
8165 * DND operation, or -1.
8167 * This function is meant to be used in a #GtkWidget::drag-data-get
8170 * Returns: index of the icon which is the source of the current
8171 * DND operation, or -1.
8176 gtk_entry_get_current_icon_drag_source (GtkEntry *entry)
8178 GtkEntryPrivate *priv;
8179 EntryIconInfo *icon_info = NULL;
8182 g_return_val_if_fail (GTK_IS_ENTRY (entry), -1);
8184 priv = GTK_ENTRY_GET_PRIVATE (entry);
8186 for (i = 0; i < MAX_ICONS; i++)
8188 if ((icon_info = priv->icons[i]))
8190 if (icon_info->in_drag)
8199 ensure_has_tooltip (GtkEntry *entry)
8201 GtkEntryPrivate *priv;
8202 EntryIconInfo *icon_info;
8204 gboolean has_tooltip = FALSE;
8206 priv = GTK_ENTRY_GET_PRIVATE (entry);
8208 for (i = 0; i < MAX_ICONS; i++)
8210 if ((icon_info = priv->icons[i]) != NULL)
8212 if (icon_info->tooltip != NULL)
8220 gtk_widget_set_has_tooltip (GTK_WIDGET (entry), has_tooltip);
8224 * gtk_entry_get_icon_tooltip_text:
8225 * @entry: a #GtkEntry
8226 * @icon_pos: the icon position
8228 * Gets the contents of the tooltip on the icon at the specified
8229 * position in @entry.
8231 * Returns: the tooltip text, or %NULL. Free the returned string
8232 * with g_free() when done.
8237 gtk_entry_get_icon_tooltip_text (GtkEntry *entry,
8238 GtkEntryIconPosition icon_pos)
8240 GtkEntryPrivate *priv;
8241 EntryIconInfo *icon_info;
8244 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8245 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8247 priv = GTK_ENTRY_GET_PRIVATE (entry);
8248 icon_info = priv->icons[icon_pos];
8253 if (icon_info->tooltip &&
8254 !pango_parse_markup (icon_info->tooltip, -1, 0, NULL, &text, NULL, NULL))
8255 g_assert (NULL == text); /* text should still be NULL in case of markup errors */
8261 * gtk_entry_set_icon_tooltip_text:
8262 * @entry: a #GtkEntry
8263 * @icon_pos: the icon position
8264 * @tooltip: the contents of the tooltip for the icon, or %NULL
8266 * Sets @tooltip as the contents of the tooltip for the icon
8267 * at the specified position.
8269 * Use %NULL for @tooltip to remove an existing tooltip.
8271 * See also gtk_widget_set_tooltip_text() and
8272 * gtk_entry_set_icon_tooltip_markup().
8277 gtk_entry_set_icon_tooltip_text (GtkEntry *entry,
8278 GtkEntryIconPosition icon_pos,
8279 const gchar *tooltip)
8281 GtkEntryPrivate *priv;
8282 EntryIconInfo *icon_info;
8284 g_return_if_fail (GTK_IS_ENTRY (entry));
8285 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8287 priv = GTK_ENTRY_GET_PRIVATE (entry);
8289 if (!(icon_info = priv->icons[icon_pos]))
8290 icon_info = priv->icons[icon_pos];
8292 if (icon_info->tooltip)
8293 g_free (icon_info->tooltip);
8295 /* Treat an empty string as a NULL string,
8296 * because an empty string would be useless for a tooltip:
8298 if (tooltip && tooltip[0] == '\0')
8301 icon_info->tooltip = tooltip ? g_markup_escape_text (tooltip, -1) : NULL;
8303 ensure_has_tooltip (entry);
8307 * gtk_entry_get_icon_tooltip_markup:
8308 * @entry: a #GtkEntry
8309 * @icon_pos: the icon position
8311 * Gets the contents of the tooltip on the icon at the specified
8312 * position in @entry.
8314 * Returns: the tooltip text, or %NULL. Free the returned string
8315 * with g_free() when done.
8320 gtk_entry_get_icon_tooltip_markup (GtkEntry *entry,
8321 GtkEntryIconPosition icon_pos)
8323 GtkEntryPrivate *priv;
8324 EntryIconInfo *icon_info;
8326 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8327 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8329 priv = GTK_ENTRY_GET_PRIVATE (entry);
8330 icon_info = priv->icons[icon_pos];
8335 return g_strdup (icon_info->tooltip);
8339 * gtk_entry_set_icon_tooltip_markup:
8340 * @entry: a #GtkEntry
8341 * @icon_pos: the icon position
8342 * @tooltip: the contents of the tooltip for the icon, or %NULL
8344 * Sets @tooltip as the contents of the tooltip for the icon at
8345 * the specified position. @tooltip is assumed to be marked up with
8346 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
8348 * Use %NULL for @tooltip to remove an existing tooltip.
8350 * See also gtk_widget_set_tooltip_markup() and
8351 * gtk_enty_set_icon_tooltip_text().
8356 gtk_entry_set_icon_tooltip_markup (GtkEntry *entry,
8357 GtkEntryIconPosition icon_pos,
8358 const gchar *tooltip)
8360 GtkEntryPrivate *priv;
8361 EntryIconInfo *icon_info;
8363 g_return_if_fail (GTK_IS_ENTRY (entry));
8364 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8366 priv = GTK_ENTRY_GET_PRIVATE (entry);
8368 if (!(icon_info = priv->icons[icon_pos]))
8369 icon_info = priv->icons[icon_pos];
8371 if (icon_info->tooltip)
8372 g_free (icon_info->tooltip);
8374 /* Treat an empty string as a NULL string,
8375 * because an empty string would be useless for a tooltip:
8377 if (tooltip && tooltip[0] == '\0')
8380 icon_info->tooltip = g_strdup (tooltip);
8382 ensure_has_tooltip (entry);
8386 gtk_entry_query_tooltip (GtkWidget *widget,
8389 gboolean keyboard_tip,
8390 GtkTooltip *tooltip)
8393 GtkEntryPrivate *priv;
8394 EntryIconInfo *icon_info;
8397 entry = GTK_ENTRY (widget);
8398 priv = GTK_ENTRY_GET_PRIVATE (entry);
8402 icon_pos = gtk_entry_get_icon_at_pos (entry, x, y);
8405 if ((icon_info = priv->icons[icon_pos]) != NULL)
8407 if (icon_info->tooltip)
8409 gtk_tooltip_set_markup (tooltip, icon_info->tooltip);
8418 return GTK_WIDGET_CLASS (gtk_entry_parent_class)->query_tooltip (widget,
8425 /* Quick hack of a popup menu
8428 activate_cb (GtkWidget *menuitem,
8431 const gchar *signal = g_object_get_data (G_OBJECT (menuitem), "gtk-signal");
8432 g_signal_emit_by_name (entry, signal);
8437 gtk_entry_mnemonic_activate (GtkWidget *widget,
8438 gboolean group_cycling)
8440 gtk_widget_grab_focus (widget);
8445 append_action_signal (GtkEntry *entry,
8447 const gchar *stock_id,
8448 const gchar *signal,
8451 GtkWidget *menuitem = gtk_image_menu_item_new_from_stock (stock_id, NULL);
8453 g_object_set_data (G_OBJECT (menuitem), I_("gtk-signal"), (char *)signal);
8454 g_signal_connect (menuitem, "activate",
8455 G_CALLBACK (activate_cb), entry);
8457 gtk_widget_set_sensitive (menuitem, sensitive);
8459 gtk_widget_show (menuitem);
8460 gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
8464 popup_menu_detach (GtkWidget *attach_widget,
8467 GTK_ENTRY (attach_widget)->popup_menu = NULL;
8471 popup_position_func (GtkMenu *menu,
8477 GtkEntry *entry = GTK_ENTRY (user_data);
8478 GtkWidget *widget = GTK_WIDGET (entry);
8480 GtkRequisition menu_req;
8481 GdkRectangle monitor;
8482 GtkBorder inner_border;
8483 gint monitor_num, strong_x, height;
8485 g_return_if_fail (GTK_WIDGET_REALIZED (entry));
8487 gdk_window_get_origin (entry->text_area, x, y);
8489 screen = gtk_widget_get_screen (widget);
8490 monitor_num = gdk_screen_get_monitor_at_window (screen, entry->text_area);
8491 if (monitor_num < 0)
8493 gtk_menu_set_monitor (menu, monitor_num);
8495 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
8496 gtk_widget_size_request (entry->popup_menu, &menu_req);
8497 gdk_drawable_get_size (entry->text_area, NULL, &height);
8498 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
8499 _gtk_entry_effective_inner_border (entry, &inner_border);
8501 *x += inner_border.left + strong_x - entry->scroll_offset;
8502 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
8503 *x -= menu_req.width;
8505 if ((*y + height + menu_req.height) <= monitor.y + monitor.height)
8507 else if ((*y - menu_req.height) >= monitor.y)
8508 *y -= menu_req.height;
8509 else if (monitor.y + monitor.height - (*y + height) > *y)
8512 *y -= menu_req.height;
8518 unichar_chosen_func (const char *text,
8521 GtkEntry *entry = GTK_ENTRY (data);
8523 if (entry->editable)
8524 gtk_entry_enter_text (entry, text);
8535 popup_targets_received (GtkClipboard *clipboard,
8536 GtkSelectionData *data,
8539 PopupInfo *info = user_data;
8540 GtkEntry *entry = info->entry;
8542 if (GTK_WIDGET_REALIZED (entry))
8545 gboolean clipboard_contains_text;
8546 GtkWidget *menuitem;
8548 gboolean show_input_method_menu;
8549 gboolean show_unicode_menu;
8551 clipboard_contains_text = gtk_selection_data_targets_include_text (data);
8552 if (entry->popup_menu)
8553 gtk_widget_destroy (entry->popup_menu);
8555 entry->popup_menu = gtk_menu_new ();
8557 gtk_menu_attach_to_widget (GTK_MENU (entry->popup_menu),
8561 mode = gtk_entry_get_display_mode (entry);
8562 append_action_signal (entry, entry->popup_menu, GTK_STOCK_CUT, "cut-clipboard",
8563 entry->editable && mode == DISPLAY_NORMAL &&
8564 entry->current_pos != entry->selection_bound);
8566 append_action_signal (entry, entry->popup_menu, GTK_STOCK_COPY, "copy-clipboard",
8567 mode == DISPLAY_NORMAL &&
8568 entry->current_pos != entry->selection_bound);
8570 append_action_signal (entry, entry->popup_menu, GTK_STOCK_PASTE, "paste-clipboard",
8571 entry->editable && clipboard_contains_text);
8573 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_DELETE, NULL);
8574 gtk_widget_set_sensitive (menuitem, entry->editable && entry->current_pos != entry->selection_bound);
8575 g_signal_connect_swapped (menuitem, "activate",
8576 G_CALLBACK (gtk_entry_delete_cb), entry);
8577 gtk_widget_show (menuitem);
8578 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8580 menuitem = gtk_separator_menu_item_new ();
8581 gtk_widget_show (menuitem);
8582 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8584 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_SELECT_ALL, NULL);
8585 g_signal_connect_swapped (menuitem, "activate",
8586 G_CALLBACK (gtk_entry_select_all), entry);
8587 gtk_widget_show (menuitem);
8588 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8590 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
8591 "gtk-show-input-method-menu", &show_input_method_menu,
8592 "gtk-show-unicode-menu", &show_unicode_menu,
8595 if (show_input_method_menu || show_unicode_menu)
8597 menuitem = gtk_separator_menu_item_new ();
8598 gtk_widget_show (menuitem);
8599 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8602 if (show_input_method_menu)
8604 menuitem = gtk_menu_item_new_with_mnemonic (_("Input _Methods"));
8605 gtk_widget_set_sensitive (menuitem, entry->editable);
8606 gtk_widget_show (menuitem);
8607 submenu = gtk_menu_new ();
8608 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
8610 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8612 gtk_im_multicontext_append_menuitems (GTK_IM_MULTICONTEXT (entry->im_context),
8613 GTK_MENU_SHELL (submenu));
8616 if (show_unicode_menu)
8618 menuitem = gtk_menu_item_new_with_mnemonic (_("_Insert Unicode Control Character"));
8619 gtk_widget_set_sensitive (menuitem, entry->editable);
8620 gtk_widget_show (menuitem);
8622 submenu = gtk_menu_new ();
8623 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
8624 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8626 _gtk_text_util_append_special_char_menuitems (GTK_MENU_SHELL (submenu),
8627 unichar_chosen_func,
8631 g_signal_emit (entry,
8632 signals[POPULATE_POPUP],
8638 gtk_menu_popup (GTK_MENU (entry->popup_menu), NULL, NULL,
8640 info->button, info->time);
8643 gtk_menu_popup (GTK_MENU (entry->popup_menu), NULL, NULL,
8644 popup_position_func, entry,
8645 info->button, info->time);
8646 gtk_menu_shell_select_first (GTK_MENU_SHELL (entry->popup_menu), FALSE);
8650 g_object_unref (entry);
8651 g_slice_free (PopupInfo, info);
8655 gtk_entry_do_popup (GtkEntry *entry,
8656 GdkEventButton *event)
8658 PopupInfo *info = g_slice_new (PopupInfo);
8660 /* In order to know what entries we should make sensitive, we
8661 * ask for the current targets of the clipboard, and when
8662 * we get them, then we actually pop up the menu.
8664 info->entry = g_object_ref (entry);
8668 info->button = event->button;
8669 info->time = event->time;
8674 info->time = gtk_get_current_event_time ();
8677 gtk_clipboard_request_contents (gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_CLIPBOARD),
8678 gdk_atom_intern_static_string ("TARGETS"),
8679 popup_targets_received,
8684 gtk_entry_popup_menu (GtkWidget *widget)
8686 gtk_entry_do_popup (GTK_ENTRY (widget), NULL);
8691 gtk_entry_drag_begin (GtkWidget *widget,
8692 GdkDragContext *context)
8694 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
8697 for (i = 0; i < MAX_ICONS; i++)
8699 EntryIconInfo *icon_info = priv->icons[i];
8701 if (icon_info != NULL)
8703 if (icon_info->in_drag)
8705 switch (icon_info->storage_type)
8707 case GTK_IMAGE_STOCK:
8708 gtk_drag_set_icon_stock (context, icon_info->stock_id, -2, -2);
8711 case GTK_IMAGE_ICON_NAME:
8712 gtk_drag_set_icon_name (context, icon_info->icon_name, -2, -2);
8715 /* FIXME: No GIcon support for dnd icons */
8716 case GTK_IMAGE_GICON:
8717 case GTK_IMAGE_PIXBUF:
8718 gtk_drag_set_icon_pixbuf (context, icon_info->pixbuf, -2, -2);
8721 g_assert_not_reached ();
8729 gtk_entry_drag_end (GtkWidget *widget,
8730 GdkDragContext *context)
8732 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
8735 for (i = 0; i < MAX_ICONS; i++)
8737 EntryIconInfo *icon_info = priv->icons[i];
8739 if (icon_info != NULL)
8740 icon_info->in_drag = 0;
8745 gtk_entry_drag_leave (GtkWidget *widget,
8746 GdkDragContext *context,
8749 GtkEntry *entry = GTK_ENTRY (widget);
8751 entry->dnd_position = -1;
8752 gtk_widget_queue_draw (widget);
8756 gtk_entry_drag_drop (GtkWidget *widget,
8757 GdkDragContext *context,
8762 GtkEntry *entry = GTK_ENTRY (widget);
8763 GdkAtom target = GDK_NONE;
8765 if (entry->editable)
8766 target = gtk_drag_dest_find_target (widget, context, NULL);
8768 if (target != GDK_NONE)
8769 gtk_drag_get_data (widget, context, target, time);
8771 gtk_drag_finish (context, FALSE, FALSE, time);
8777 gtk_entry_drag_motion (GtkWidget *widget,
8778 GdkDragContext *context,
8783 GtkEntry *entry = GTK_ENTRY (widget);
8784 GtkWidget *source_widget;
8785 GdkDragAction suggested_action;
8786 gint new_position, old_position;
8789 x -= widget->style->xthickness;
8790 y -= widget->style->ythickness;
8792 old_position = entry->dnd_position;
8793 new_position = gtk_entry_find_position (entry, x + entry->scroll_offset);
8795 if (entry->editable &&
8796 gtk_drag_dest_find_target (widget, context, NULL) != GDK_NONE)
8798 source_widget = gtk_drag_get_source_widget (context);
8799 suggested_action = context->suggested_action;
8801 if (!gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &sel1, &sel2) ||
8802 new_position < sel1 || new_position > sel2)
8804 if (source_widget == widget)
8806 /* Default to MOVE, unless the user has
8807 * pressed ctrl or alt to affect available actions
8809 if ((context->actions & GDK_ACTION_MOVE) != 0)
8810 suggested_action = GDK_ACTION_MOVE;
8813 entry->dnd_position = new_position;
8817 if (source_widget == widget)
8818 suggested_action = 0; /* Can't drop in selection where drag started */
8820 entry->dnd_position = -1;
8825 /* Entry not editable, or no text */
8826 suggested_action = 0;
8827 entry->dnd_position = -1;
8830 gdk_drag_status (context, suggested_action, time);
8832 if (entry->dnd_position != old_position)
8833 gtk_widget_queue_draw (widget);
8839 gtk_entry_drag_data_received (GtkWidget *widget,
8840 GdkDragContext *context,
8843 GtkSelectionData *selection_data,
8847 GtkEntry *entry = GTK_ENTRY (widget);
8848 GtkEditable *editable = GTK_EDITABLE (widget);
8851 str = (gchar *) gtk_selection_data_get_text (selection_data);
8853 x -= widget->style->xthickness;
8854 y -= widget->style->ythickness;
8856 if (str && entry->editable)
8862 if (entry->truncate_multiline)
8863 length = truncate_multiline (str);
8865 new_position = gtk_entry_find_position (entry, x + entry->scroll_offset);
8867 if (!gtk_editable_get_selection_bounds (editable, &sel1, &sel2) ||
8868 new_position < sel1 || new_position > sel2)
8870 gtk_editable_insert_text (editable, str, length, &new_position);
8874 /* Replacing selection */
8875 begin_change (entry);
8876 g_object_freeze_notify (G_OBJECT (entry));
8877 gtk_editable_delete_text (editable, sel1, sel2);
8878 gtk_editable_insert_text (editable, str, length, &sel1);
8879 g_object_thaw_notify (G_OBJECT (entry));
8883 gtk_drag_finish (context, TRUE, context->action == GDK_ACTION_MOVE, time);
8887 /* Drag and drop didn't happen! */
8888 gtk_drag_finish (context, FALSE, FALSE, time);
8895 gtk_entry_drag_data_get (GtkWidget *widget,
8896 GdkDragContext *context,
8897 GtkSelectionData *selection_data,
8901 gint sel_start, sel_end;
8904 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
8905 GtkEditable *editable = GTK_EDITABLE (widget);
8907 /* If there is an icon drag going on, exit early. */
8908 for (i = 0; i < MAX_ICONS; i++)
8910 EntryIconInfo *icon_info = priv->icons[i];
8912 if (icon_info != NULL)
8914 if (icon_info->in_drag)
8919 if (gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end))
8921 gchar *str = gtk_entry_get_display_text (GTK_ENTRY (widget), sel_start, sel_end);
8923 gtk_selection_data_set_text (selection_data, str, -1);
8931 gtk_entry_drag_data_delete (GtkWidget *widget,
8932 GdkDragContext *context)
8934 gint sel_start, sel_end;
8937 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
8938 GtkEditable *editable = GTK_EDITABLE (widget);
8940 /* If there is an icon drag going on, exit early. */
8941 for (i = 0; i < MAX_ICONS; i++)
8943 EntryIconInfo *icon_info = priv->icons[i];
8945 if (icon_info != NULL)
8947 if (icon_info->in_drag)
8952 if (GTK_ENTRY (widget)->editable &&
8953 gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end))
8954 gtk_editable_delete_text (editable, sel_start, sel_end);
8957 /* We display the cursor when
8959 * - the selection is empty, AND
8960 * - the widget has focus
8963 #define CURSOR_ON_MULTIPLIER 2
8964 #define CURSOR_OFF_MULTIPLIER 1
8965 #define CURSOR_PEND_MULTIPLIER 3
8966 #define CURSOR_DIVIDER 3
8969 cursor_blinks (GtkEntry *entry)
8971 if (GTK_WIDGET_HAS_FOCUS (entry) &&
8973 entry->selection_bound == entry->current_pos)
8975 GtkSettings *settings;
8978 settings = gtk_widget_get_settings (GTK_WIDGET (entry));
8979 g_object_get (settings, "gtk-cursor-blink", &blink, NULL);
8988 get_cursor_time (GtkEntry *entry)
8990 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (entry));
8993 g_object_get (settings, "gtk-cursor-blink-time", &time, NULL);
8999 get_cursor_blink_timeout (GtkEntry *entry)
9001 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9004 g_object_get (settings, "gtk-cursor-blink-timeout", &timeout, NULL);
9010 show_cursor (GtkEntry *entry)
9012 if (!entry->cursor_visible)
9014 entry->cursor_visible = TRUE;
9016 if (GTK_WIDGET_HAS_FOCUS (entry) && entry->selection_bound == entry->current_pos)
9017 gtk_widget_queue_draw (GTK_WIDGET (entry));
9022 hide_cursor (GtkEntry *entry)
9024 if (entry->cursor_visible)
9026 entry->cursor_visible = FALSE;
9028 if (GTK_WIDGET_HAS_FOCUS (entry) && entry->selection_bound == entry->current_pos)
9029 gtk_widget_queue_draw (GTK_WIDGET (entry));
9037 blink_cb (gpointer data)
9040 GtkEntryPrivate *priv;
9043 entry = GTK_ENTRY (data);
9044 priv = GTK_ENTRY_GET_PRIVATE (entry);
9046 if (!GTK_WIDGET_HAS_FOCUS (entry))
9048 g_warning ("GtkEntry - did not receive focus-out-event. If you\n"
9049 "connect a handler to this signal, it must return\n"
9050 "FALSE so the entry gets the event as well");
9052 gtk_entry_check_cursor_blink (entry);
9057 g_assert (entry->selection_bound == entry->current_pos);
9059 blink_timeout = get_cursor_blink_timeout (entry);
9060 if (priv->blink_time > 1000 * blink_timeout &&
9061 blink_timeout < G_MAXINT/1000)
9063 /* we've blinked enough without the user doing anything, stop blinking */
9064 show_cursor (entry);
9065 entry->blink_timeout = 0;
9067 else if (entry->cursor_visible)
9069 hide_cursor (entry);
9070 entry->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_OFF_MULTIPLIER / CURSOR_DIVIDER,
9076 show_cursor (entry);
9077 priv->blink_time += get_cursor_time (entry);
9078 entry->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
9083 /* Remove ourselves */
9088 gtk_entry_check_cursor_blink (GtkEntry *entry)
9090 GtkEntryPrivate *priv;
9092 priv = GTK_ENTRY_GET_PRIVATE (entry);
9094 if (cursor_blinks (entry))
9096 if (!entry->blink_timeout)
9098 show_cursor (entry);
9099 entry->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
9106 if (entry->blink_timeout)
9108 g_source_remove (entry->blink_timeout);
9109 entry->blink_timeout = 0;
9112 entry->cursor_visible = TRUE;
9118 gtk_entry_pend_cursor_blink (GtkEntry *entry)
9120 if (cursor_blinks (entry))
9122 if (entry->blink_timeout != 0)
9123 g_source_remove (entry->blink_timeout);
9125 entry->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_PEND_MULTIPLIER / CURSOR_DIVIDER,
9128 show_cursor (entry);
9133 gtk_entry_reset_blink_time (GtkEntry *entry)
9135 GtkEntryPrivate *priv;
9137 priv = GTK_ENTRY_GET_PRIVATE (entry);
9139 priv->blink_time = 0;
9145 gtk_entry_completion_timeout (gpointer data)
9147 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (data);
9149 completion->priv->completion_timeout = 0;
9151 if (completion->priv->filter_model &&
9152 g_utf8_strlen (gtk_entry_get_text (GTK_ENTRY (completion->priv->entry)), -1)
9153 >= completion->priv->minimum_key_length)
9157 GtkTreeSelection *s;
9158 gboolean popup_single;
9160 gtk_entry_completion_complete (completion);
9161 matches = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->filter_model), NULL);
9163 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9165 s = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view));
9167 gtk_tree_selection_unselect_all (s);
9169 actions = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->actions), NULL);
9171 g_object_get (completion, "popup-single-match", &popup_single, NULL);
9172 if ((matches > (popup_single ? 0: 1)) || actions > 0)
9174 if (GTK_WIDGET_VISIBLE (completion->priv->popup_window))
9175 _gtk_entry_completion_resize_popup (completion);
9177 _gtk_entry_completion_popup (completion);
9180 _gtk_entry_completion_popdown (completion);
9182 else if (GTK_WIDGET_VISIBLE (completion->priv->popup_window))
9183 _gtk_entry_completion_popdown (completion);
9188 static inline gboolean
9189 keyval_is_cursor_move (guint keyval)
9191 if (keyval == GDK_Up || keyval == GDK_KP_Up)
9194 if (keyval == GDK_Down || keyval == GDK_KP_Down)
9197 if (keyval == GDK_Page_Up)
9200 if (keyval == GDK_Page_Down)
9207 gtk_entry_completion_key_press (GtkWidget *widget,
9211 gint matches, actions = 0;
9212 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
9214 if (!GTK_WIDGET_MAPPED (completion->priv->popup_window))
9217 matches = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->filter_model), NULL);
9219 if (completion->priv->actions)
9220 actions = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->actions), NULL);
9222 if (keyval_is_cursor_move (event->keyval))
9224 GtkTreePath *path = NULL;
9226 if (event->keyval == GDK_Up || event->keyval == GDK_KP_Up)
9228 if (completion->priv->current_selected < 0)
9229 completion->priv->current_selected = matches + actions - 1;
9231 completion->priv->current_selected--;
9233 else if (event->keyval == GDK_Down || event->keyval == GDK_KP_Down)
9235 if (completion->priv->current_selected < matches + actions - 1)
9236 completion->priv->current_selected++;
9238 completion->priv->current_selected = -1;
9240 else if (event->keyval == GDK_Page_Up)
9242 if (completion->priv->current_selected < 0)
9243 completion->priv->current_selected = matches + actions - 1;
9244 else if (completion->priv->current_selected == 0)
9245 completion->priv->current_selected = -1;
9246 else if (completion->priv->current_selected < matches)
9248 completion->priv->current_selected -= 14;
9249 if (completion->priv->current_selected < 0)
9250 completion->priv->current_selected = 0;
9254 completion->priv->current_selected -= 14;
9255 if (completion->priv->current_selected < matches - 1)
9256 completion->priv->current_selected = matches - 1;
9259 else if (event->keyval == GDK_Page_Down)
9261 if (completion->priv->current_selected < 0)
9262 completion->priv->current_selected = 0;
9263 else if (completion->priv->current_selected < matches - 1)
9265 completion->priv->current_selected += 14;
9266 if (completion->priv->current_selected > matches - 1)
9267 completion->priv->current_selected = matches - 1;
9269 else if (completion->priv->current_selected == matches + actions - 1)
9271 completion->priv->current_selected = -1;
9275 completion->priv->current_selected += 14;
9276 if (completion->priv->current_selected > matches + actions - 1)
9277 completion->priv->current_selected = matches + actions - 1;
9281 if (completion->priv->current_selected < 0)
9283 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9284 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view)));
9286 if (completion->priv->inline_selection &&
9287 completion->priv->completion_prefix)
9289 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9290 completion->priv->completion_prefix);
9291 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9294 else if (completion->priv->current_selected < matches)
9296 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view)));
9298 path = gtk_tree_path_new_from_indices (completion->priv->current_selected, -1);
9299 gtk_tree_view_set_cursor (GTK_TREE_VIEW (completion->priv->tree_view),
9302 if (completion->priv->inline_selection)
9306 GtkTreeModel *model = NULL;
9307 GtkTreeSelection *sel;
9310 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view));
9311 if (!gtk_tree_selection_get_selected (sel, &model, &iter))
9314 if (completion->priv->completion_prefix == NULL)
9315 completion->priv->completion_prefix = g_strdup (gtk_entry_get_text (GTK_ENTRY (completion->priv->entry)));
9317 g_signal_emit_by_name (completion, "cursor-on-match", model,
9321 else if (completion->priv->current_selected - matches >= 0)
9323 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9325 path = gtk_tree_path_new_from_indices (completion->priv->current_selected - matches, -1);
9326 gtk_tree_view_set_cursor (GTK_TREE_VIEW (completion->priv->action_view),
9329 if (completion->priv->inline_selection &&
9330 completion->priv->completion_prefix)
9332 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9333 completion->priv->completion_prefix);
9334 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9338 gtk_tree_path_free (path);
9342 else if (event->keyval == GDK_Escape ||
9343 event->keyval == GDK_Left ||
9344 event->keyval == GDK_KP_Left ||
9345 event->keyval == GDK_Right ||
9346 event->keyval == GDK_KP_Right)
9348 gboolean retval = TRUE;
9350 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9351 _gtk_entry_completion_popdown (completion);
9353 if (completion->priv->current_selected < 0)
9356 goto keypress_completion_out;
9358 else if (completion->priv->inline_selection)
9360 /* Escape rejects the tentative completion */
9361 if (event->keyval == GDK_Escape)
9363 if (completion->priv->completion_prefix)
9364 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9365 completion->priv->completion_prefix);
9367 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry), "");
9370 /* Move the cursor to the end for Right/Esc, to the
9371 beginning for Left */
9372 if (event->keyval == GDK_Right ||
9373 event->keyval == GDK_KP_Right ||
9374 event->keyval == GDK_Escape)
9375 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9377 gtk_editable_set_position (GTK_EDITABLE (widget), 0);
9380 keypress_completion_out:
9381 if (completion->priv->inline_selection)
9383 g_free (completion->priv->completion_prefix);
9384 completion->priv->completion_prefix = NULL;
9389 else if (event->keyval == GDK_Tab ||
9390 event->keyval == GDK_KP_Tab ||
9391 event->keyval == GDK_ISO_Left_Tab)
9393 GtkDirectionType dir = event->keyval == GDK_ISO_Left_Tab ?
9394 GTK_DIR_TAB_BACKWARD : GTK_DIR_TAB_FORWARD;
9396 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9397 _gtk_entry_completion_popdown (completion);
9399 g_free (completion->priv->completion_prefix);
9400 completion->priv->completion_prefix = NULL;
9402 gtk_widget_child_focus (gtk_widget_get_toplevel (widget), dir);
9406 else if (event->keyval == GDK_ISO_Enter ||
9407 event->keyval == GDK_KP_Enter ||
9408 event->keyval == GDK_Return)
9411 GtkTreeModel *model = NULL;
9412 GtkTreeSelection *sel;
9413 gboolean retval = TRUE;
9415 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9416 _gtk_entry_completion_popdown (completion);
9418 if (completion->priv->current_selected < matches)
9422 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view));
9423 if (gtk_tree_selection_get_selected (sel, &model, &iter))
9425 g_signal_handler_block (widget, completion->priv->changed_id);
9426 g_signal_emit_by_name (completion, "match-selected",
9427 model, &iter, &entry_set);
9428 g_signal_handler_unblock (widget, completion->priv->changed_id);
9434 gtk_tree_model_get (model, &iter,
9435 completion->priv->text_column, &str,
9438 gtk_entry_set_text (GTK_ENTRY (widget), str);
9440 /* move the cursor to the end */
9441 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9449 else if (completion->priv->current_selected - matches >= 0)
9451 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view));
9452 if (gtk_tree_selection_get_selected (sel, &model, &iter))
9456 path = gtk_tree_path_new_from_indices (completion->priv->current_selected - matches, -1);
9457 g_signal_emit_by_name (completion, "action-activated",
9458 gtk_tree_path_get_indices (path)[0]);
9459 gtk_tree_path_free (path);
9465 g_free (completion->priv->completion_prefix);
9466 completion->priv->completion_prefix = NULL;
9475 gtk_entry_completion_changed (GtkWidget *entry,
9478 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
9480 /* (re)install completion timeout */
9481 if (completion->priv->completion_timeout)
9482 g_source_remove (completion->priv->completion_timeout);
9484 if (!gtk_entry_get_text (GTK_ENTRY (entry)))
9487 /* no need to normalize for this test */
9488 if (completion->priv->minimum_key_length > 0 &&
9489 strcmp ("", gtk_entry_get_text (GTK_ENTRY (entry))) == 0)
9491 if (GTK_WIDGET_VISIBLE (completion->priv->popup_window))
9492 _gtk_entry_completion_popdown (completion);
9496 completion->priv->completion_timeout =
9497 gdk_threads_add_timeout (COMPLETION_TIMEOUT,
9498 gtk_entry_completion_timeout,
9503 check_completion_callback (GtkEntryCompletion *completion)
9505 completion->priv->check_completion_idle = NULL;
9507 gtk_entry_completion_complete (completion);
9508 gtk_entry_completion_insert_prefix (completion);
9514 clear_completion_callback (GtkEntry *entry,
9517 if (pspec->name == I_("cursor-position") ||
9518 pspec->name == I_("selection-bound"))
9520 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
9522 completion->priv->has_completion = FALSE;
9527 accept_completion_callback (GtkEntry *entry)
9529 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
9531 if (completion->priv->has_completion)
9532 gtk_editable_set_position (GTK_EDITABLE (entry),
9533 gtk_entry_buffer_get_length (get_buffer (entry)));
9539 completion_insert_text_callback (GtkEntry *entry,
9543 GtkEntryCompletion *completion)
9545 /* idle to update the selection based on the file list */
9546 if (completion->priv->check_completion_idle == NULL)
9548 completion->priv->check_completion_idle = g_idle_source_new ();
9549 g_source_set_priority (completion->priv->check_completion_idle, G_PRIORITY_HIGH);
9550 g_source_set_closure (completion->priv->check_completion_idle,
9551 g_cclosure_new_object (G_CALLBACK (check_completion_callback),
9552 G_OBJECT (completion)));
9553 g_source_attach (completion->priv->check_completion_idle, NULL);
9558 completion_changed (GtkEntryCompletion *completion,
9562 GtkEntry *entry = GTK_ENTRY (data);
9564 if (pspec->name == I_("popup-completion") ||
9565 pspec->name == I_("inline-completion"))
9567 disconnect_completion_signals (entry, completion);
9568 connect_completion_signals (entry, completion);
9573 disconnect_completion_signals (GtkEntry *entry,
9574 GtkEntryCompletion *completion)
9576 g_signal_handlers_disconnect_by_func (completion,
9577 G_CALLBACK (completion_changed), entry);
9578 if (completion->priv->changed_id > 0 &&
9579 g_signal_handler_is_connected (entry, completion->priv->changed_id))
9581 g_signal_handler_disconnect (entry, completion->priv->changed_id);
9582 completion->priv->changed_id = 0;
9584 g_signal_handlers_disconnect_by_func (entry,
9585 G_CALLBACK (gtk_entry_completion_key_press), completion);
9586 if (completion->priv->insert_text_id > 0 &&
9587 g_signal_handler_is_connected (entry, completion->priv->insert_text_id))
9589 g_signal_handler_disconnect (entry, completion->priv->insert_text_id);
9590 completion->priv->insert_text_id = 0;
9592 g_signal_handlers_disconnect_by_func (entry,
9593 G_CALLBACK (completion_insert_text_callback), completion);
9594 g_signal_handlers_disconnect_by_func (entry,
9595 G_CALLBACK (clear_completion_callback), completion);
9596 g_signal_handlers_disconnect_by_func (entry,
9597 G_CALLBACK (accept_completion_callback), completion);
9601 connect_completion_signals (GtkEntry *entry,
9602 GtkEntryCompletion *completion)
9604 if (completion->priv->popup_completion)
9606 completion->priv->changed_id =
9607 g_signal_connect (entry, "changed",
9608 G_CALLBACK (gtk_entry_completion_changed), completion);
9609 g_signal_connect (entry, "key-press-event",
9610 G_CALLBACK (gtk_entry_completion_key_press), completion);
9613 if (completion->priv->inline_completion)
9615 completion->priv->insert_text_id =
9616 g_signal_connect (entry, "insert-text",
9617 G_CALLBACK (completion_insert_text_callback), completion);
9618 g_signal_connect (entry, "notify",
9619 G_CALLBACK (clear_completion_callback), completion);
9620 g_signal_connect (entry, "activate",
9621 G_CALLBACK (accept_completion_callback), completion);
9622 g_signal_connect (entry, "focus-out-event",
9623 G_CALLBACK (accept_completion_callback), completion);
9626 g_signal_connect (completion, "notify",
9627 G_CALLBACK (completion_changed), entry);
9631 * gtk_entry_set_completion:
9632 * @entry: A #GtkEntry
9633 * @completion: (allow-none): The #GtkEntryCompletion or %NULL
9635 * Sets @completion to be the auxiliary completion object to use with @entry.
9636 * All further configuration of the completion mechanism is done on
9637 * @completion using the #GtkEntryCompletion API. Completion is disabled if
9638 * @completion is set to %NULL.
9643 gtk_entry_set_completion (GtkEntry *entry,
9644 GtkEntryCompletion *completion)
9646 GtkEntryCompletion *old;
9648 g_return_if_fail (GTK_IS_ENTRY (entry));
9649 g_return_if_fail (!completion || GTK_IS_ENTRY_COMPLETION (completion));
9651 old = gtk_entry_get_completion (entry);
9653 if (old == completion)
9658 if (old->priv->completion_timeout)
9660 g_source_remove (old->priv->completion_timeout);
9661 old->priv->completion_timeout = 0;
9664 if (GTK_WIDGET_MAPPED (old->priv->popup_window))
9665 _gtk_entry_completion_popdown (old);
9667 disconnect_completion_signals (entry, old);
9668 old->priv->entry = NULL;
9670 g_object_unref (old);
9675 g_object_set_data (G_OBJECT (entry), I_(GTK_ENTRY_COMPLETION_KEY), NULL);
9679 /* hook into the entry */
9680 g_object_ref (completion);
9682 connect_completion_signals (entry, completion);
9683 completion->priv->entry = GTK_WIDGET (entry);
9684 g_object_set_data (G_OBJECT (entry), I_(GTK_ENTRY_COMPLETION_KEY), completion);
9688 * gtk_entry_get_completion:
9689 * @entry: A #GtkEntry
9691 * Returns the auxiliary completion object currently in use by @entry.
9693 * Return value: The auxiliary completion object currently in use by @entry.
9697 GtkEntryCompletion *
9698 gtk_entry_get_completion (GtkEntry *entry)
9700 GtkEntryCompletion *completion;
9702 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
9704 completion = GTK_ENTRY_COMPLETION (g_object_get_data (G_OBJECT (entry),
9705 GTK_ENTRY_COMPLETION_KEY));
9711 * gtk_entry_set_cursor_hadjustment:
9712 * @entry: a #GtkEntry
9713 * @adjustment: an adjustment which should be adjusted when the cursor
9714 * is moved, or %NULL
9716 * Hooks up an adjustment to the cursor position in an entry, so that when
9717 * the cursor is moved, the adjustment is scrolled to show that position.
9718 * See gtk_scrolled_window_get_hadjustment() for a typical way of obtaining
9721 * The adjustment has to be in pixel units and in the same coordinate system
9727 gtk_entry_set_cursor_hadjustment (GtkEntry *entry,
9728 GtkAdjustment *adjustment)
9730 g_return_if_fail (GTK_IS_ENTRY (entry));
9732 g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
9735 g_object_ref (adjustment);
9737 g_object_set_qdata_full (G_OBJECT (entry),
9738 quark_cursor_hadjustment,
9744 * gtk_entry_get_cursor_hadjustment:
9745 * @entry: a #GtkEntry
9747 * Retrieves the horizontal cursor adjustment for the entry.
9748 * See gtk_entry_set_cursor_hadjustment().
9750 * Return value: (transfer none): the horizontal cursor adjustment, or %NULL
9751 * if none has been set.
9756 gtk_entry_get_cursor_hadjustment (GtkEntry *entry)
9758 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
9760 return g_object_get_qdata (G_OBJECT (entry), quark_cursor_hadjustment);
9764 * gtk_entry_set_progress_fraction:
9765 * @entry: a #GtkEntry
9766 * @fraction: fraction of the task that's been completed
9768 * Causes the entry's progress indicator to "fill in" the given
9769 * fraction of the bar. The fraction should be between 0.0 and 1.0,
9775 gtk_entry_set_progress_fraction (GtkEntry *entry,
9778 GtkEntryPrivate *private;
9779 gdouble old_fraction;
9780 gint x, y, width, height;
9781 gint old_x, old_y, old_width, old_height;
9783 g_return_if_fail (GTK_IS_ENTRY (entry));
9785 private = GTK_ENTRY_GET_PRIVATE (entry);
9787 if (private->progress_pulse_mode)
9790 old_fraction = private->progress_fraction;
9792 if (GTK_WIDGET_DRAWABLE (GTK_WIDGET (entry)))
9793 get_progress_area (GTK_WIDGET(entry), &old_x, &old_y, &old_width, &old_height);
9795 fraction = CLAMP (fraction, 0.0, 1.0);
9797 private->progress_fraction = fraction;
9798 private->progress_pulse_mode = FALSE;
9799 private->progress_pulse_current = 0.0;
9801 if (GTK_WIDGET_DRAWABLE (GTK_WIDGET (entry)))
9803 get_progress_area (GTK_WIDGET(entry), &x, &y, &width, &height);
9805 if ((x != old_x) || (y != old_y) || (width != old_width) || (height != old_height))
9806 gtk_widget_queue_draw (GTK_WIDGET (entry));
9809 if (fraction != old_fraction)
9810 g_object_notify (G_OBJECT (entry), "progress-fraction");
9814 * gtk_entry_get_progress_fraction:
9815 * @entry: a #GtkEntry
9817 * Returns the current fraction of the task that's been completed.
9818 * See gtk_entry_set_progress_fraction().
9820 * Return value: a fraction from 0.0 to 1.0
9825 gtk_entry_get_progress_fraction (GtkEntry *entry)
9827 GtkEntryPrivate *private;
9829 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
9831 private = GTK_ENTRY_GET_PRIVATE (entry);
9833 return private->progress_fraction;
9837 * gtk_entry_set_progress_pulse_step:
9838 * @entry: a #GtkEntry
9839 * @fraction: fraction between 0.0 and 1.0
9841 * Sets the fraction of total entry width to move the progress
9842 * bouncing block for each call to gtk_entry_progress_pulse().
9847 gtk_entry_set_progress_pulse_step (GtkEntry *entry,
9850 GtkEntryPrivate *private;
9852 g_return_if_fail (GTK_IS_ENTRY (entry));
9854 private = GTK_ENTRY_GET_PRIVATE (entry);
9856 fraction = CLAMP (fraction, 0.0, 1.0);
9858 if (fraction != private->progress_pulse_fraction)
9860 private->progress_pulse_fraction = fraction;
9862 gtk_widget_queue_draw (GTK_WIDGET (entry));
9864 g_object_notify (G_OBJECT (entry), "progress-pulse-step");
9869 * gtk_entry_get_progress_pulse_step:
9870 * @entry: a #GtkEntry
9872 * Retrieves the pulse step set with gtk_entry_set_progress_pulse_step().
9874 * Return value: a fraction from 0.0 to 1.0
9879 gtk_entry_get_progress_pulse_step (GtkEntry *entry)
9881 GtkEntryPrivate *private;
9883 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
9885 private = GTK_ENTRY_GET_PRIVATE (entry);
9887 return private->progress_pulse_fraction;
9891 * gtk_entry_progress_pulse:
9892 * @entry: a #GtkEntry
9894 * Indicates that some progress is made, but you don't know how much.
9895 * Causes the entry's progress indicator to enter "activity mode,"
9896 * where a block bounces back and forth. Each call to
9897 * gtk_entry_progress_pulse() causes the block to move by a little bit
9898 * (the amount of movement per pulse is determined by
9899 * gtk_entry_set_progress_pulse_step()).
9904 gtk_entry_progress_pulse (GtkEntry *entry)
9906 GtkEntryPrivate *private;
9908 g_return_if_fail (GTK_IS_ENTRY (entry));
9910 private = GTK_ENTRY_GET_PRIVATE (entry);
9912 if (private->progress_pulse_mode)
9914 if (private->progress_pulse_way_back)
9916 private->progress_pulse_current -= private->progress_pulse_fraction;
9918 if (private->progress_pulse_current < 0.0)
9920 private->progress_pulse_current = 0.0;
9921 private->progress_pulse_way_back = FALSE;
9926 private->progress_pulse_current += private->progress_pulse_fraction;
9928 if (private->progress_pulse_current > 1.0 - private->progress_pulse_fraction)
9930 private->progress_pulse_current = 1.0 - private->progress_pulse_fraction;
9931 private->progress_pulse_way_back = TRUE;
9937 private->progress_fraction = 0.0;
9938 private->progress_pulse_mode = TRUE;
9939 private->progress_pulse_way_back = FALSE;
9940 private->progress_pulse_current = 0.0;
9943 gtk_widget_queue_draw (GTK_WIDGET (entry));
9946 /* Caps Lock warning for password entries */
9949 show_capslock_feedback (GtkEntry *entry,
9952 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
9954 if (gtk_entry_get_icon_storage_type (entry, GTK_ENTRY_ICON_SECONDARY) == GTK_IMAGE_EMPTY)
9956 gtk_entry_set_icon_from_stock (entry, GTK_ENTRY_ICON_SECONDARY, GTK_STOCK_CAPS_LOCK_WARNING);
9957 gtk_entry_set_icon_activatable (entry, GTK_ENTRY_ICON_SECONDARY, FALSE);
9958 priv->caps_lock_warning_shown = TRUE;
9961 if (priv->caps_lock_warning_shown)
9962 gtk_entry_set_icon_tooltip_text (entry, GTK_ENTRY_ICON_SECONDARY, text);
9964 g_warning ("Can't show Caps Lock warning, since secondary icon is set");
9968 remove_capslock_feedback (GtkEntry *entry)
9970 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
9972 if (priv->caps_lock_warning_shown)
9974 gtk_entry_set_icon_from_stock (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
9975 priv->caps_lock_warning_shown = FALSE;
9980 keymap_state_changed (GdkKeymap *keymap,
9983 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
9986 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL && priv->caps_lock_warning)
9988 if (gdk_keymap_get_caps_lock_state (keymap))
9989 text = _("Caps Lock is on");
9993 show_capslock_feedback (entry, text);
9995 remove_capslock_feedback (entry);
9998 #define __GTK_ENTRY_C__
9999 #include "gtkaliasdef.c"