1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* GTK - The GIMP Toolkit
3 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * Copyright (C) 2004-2006 Christian Hammond
5 * Copyright (C) 2008 Cody Russell
6 * Copyright (C) 2008 Red Hat, Inc.
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
25 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
26 * file for a list of people on the GTK+ Team. See the ChangeLog
27 * files for a list of changes. These files are distributed with
28 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
36 #include "gdk/gdkkeysyms.h"
37 #include "gtkalignment.h"
38 #include "gtkbindings.h"
39 #include "gtkcelleditable.h"
40 #include "gtkclipboard.h"
43 #include "gtkentrybuffer.h"
44 #include "gtkimagemenuitem.h"
45 #include "gtkimcontextsimple.h"
46 #include "gtkimmulticontext.h"
50 #include "gtkmarshalers.h"
52 #include "gtkmenuitem.h"
53 #include "gtkseparatormenuitem.h"
54 #include "gtkselection.h"
55 #include "gtksettings.h"
56 #include "gtkspinbutton.h"
58 #include "gtktextutil.h"
59 #include "gtkwindow.h"
60 #include "gtktreeview.h"
61 #include "gtktreeselection.h"
62 #include "gtkprivate.h"
63 #include "gtkentryprivate.h"
64 #include "gtkcelllayout.h"
65 #include "gtktooltip.h"
66 #include "gtkiconfactory.h"
67 #include "gtkicontheme.h"
69 #define GTK_ENTRY_COMPLETION_KEY "gtk-entry-completion-key"
71 #define MIN_ENTRY_WIDTH 150
72 #define DRAW_TIMEOUT 20
73 #define COMPLETION_TIMEOUT 300
74 #define PASSWORD_HINT_MAX 8
78 #define IS_VALID_ICON_POSITION(pos) \
79 ((pos) == GTK_ENTRY_ICON_PRIMARY || \
80 (pos) == GTK_ENTRY_ICON_SECONDARY)
82 static const GtkBorder default_inner_border = { 2, 2, 2, 2 };
83 static GQuark quark_inner_border = 0;
84 static GQuark quark_password_hint = 0;
85 static GQuark quark_cursor_hadjustment = 0;
86 static GQuark quark_capslock_feedback = 0;
88 typedef struct _GtkEntryPrivate GtkEntryPrivate;
90 #define GTK_ENTRY_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_ENTRY, GtkEntryPrivate))
96 guint insensitive : 1;
97 guint nonactivatable : 1;
102 GtkImageType storage_type;
108 GtkTargetList *target_list;
109 GdkDragAction actions;
112 struct _GtkEntryPrivate
114 GtkEntryBuffer* buffer;
118 guint blink_time; /* time in msec the cursor has blinked since last user event */
119 guint interior_focus : 1;
120 guint real_changed : 1;
121 guint invisible_char_set : 1;
122 guint caps_lock_warning : 1;
123 guint caps_lock_warning_shown : 1;
124 guint change_count : 8;
125 guint progress_pulse_mode : 1;
126 guint progress_pulse_way_back : 1;
129 GtkShadowType shadow_type;
131 gdouble progress_fraction;
132 gdouble progress_pulse_fraction;
133 gdouble progress_pulse_current;
135 EntryIconInfo *icons[MAX_ICONS];
142 GdkDevice *completion_device;
145 typedef struct _GtkEntryPasswordHint GtkEntryPasswordHint;
147 struct _GtkEntryPasswordHint
149 gint position; /* Position (in text) of the last password hint */
150 guint source_id; /* Timeout source id */
153 typedef struct _GtkEntryCapslockFeedback GtkEntryCapslockFeedback;
155 struct _GtkEntryCapslockFeedback
182 PROP_CURSOR_POSITION,
183 PROP_SELECTION_BOUND,
190 PROP_ACTIVATES_DEFAULT,
195 PROP_TRUNCATE_MULTILINE,
199 PROP_INVISIBLE_CHAR_SET,
200 PROP_CAPS_LOCK_WARNING,
201 PROP_PROGRESS_FRACTION,
202 PROP_PROGRESS_PULSE_STEP,
204 PROP_PIXBUF_SECONDARY,
206 PROP_STOCK_SECONDARY,
207 PROP_ICON_NAME_PRIMARY,
208 PROP_ICON_NAME_SECONDARY,
210 PROP_GICON_SECONDARY,
211 PROP_STORAGE_TYPE_PRIMARY,
212 PROP_STORAGE_TYPE_SECONDARY,
213 PROP_ACTIVATABLE_PRIMARY,
214 PROP_ACTIVATABLE_SECONDARY,
215 PROP_SENSITIVE_PRIMARY,
216 PROP_SENSITIVE_SECONDARY,
217 PROP_TOOLTIP_TEXT_PRIMARY,
218 PROP_TOOLTIP_TEXT_SECONDARY,
219 PROP_TOOLTIP_MARKUP_PRIMARY,
220 PROP_TOOLTIP_MARKUP_SECONDARY,
222 PROP_EDITING_CANCELED
225 static guint signals[LAST_SIGNAL] = { 0 };
234 DISPLAY_NORMAL, /* The entry text is being shown */
235 DISPLAY_INVISIBLE, /* In invisible mode, text replaced by (eg) bullets */
236 DISPLAY_BLANK /* In invisible mode, nothing shown at all */
241 static void gtk_entry_editable_init (GtkEditableInterface *iface);
242 static void gtk_entry_cell_editable_init (GtkCellEditableIface *iface);
243 static void gtk_entry_set_property (GObject *object,
247 static void gtk_entry_get_property (GObject *object,
251 static void gtk_entry_finalize (GObject *object);
252 static void gtk_entry_dispose (GObject *object);
256 static void gtk_entry_destroy (GtkWidget *widget);
257 static void gtk_entry_realize (GtkWidget *widget);
258 static void gtk_entry_unrealize (GtkWidget *widget);
259 static void gtk_entry_map (GtkWidget *widget);
260 static void gtk_entry_unmap (GtkWidget *widget);
261 static void gtk_entry_size_request (GtkWidget *widget,
262 GtkRequisition *requisition);
263 static void gtk_entry_size_allocate (GtkWidget *widget,
264 GtkAllocation *allocation);
265 static void gtk_entry_draw_frame (GtkWidget *widget,
267 static void gtk_entry_draw_progress (GtkWidget *widget,
270 static gint gtk_entry_draw (GtkWidget *widget,
272 static gint gtk_entry_button_press (GtkWidget *widget,
273 GdkEventButton *event);
274 static gint gtk_entry_button_release (GtkWidget *widget,
275 GdkEventButton *event);
276 static gint gtk_entry_enter_notify (GtkWidget *widget,
277 GdkEventCrossing *event);
278 static gint gtk_entry_leave_notify (GtkWidget *widget,
279 GdkEventCrossing *event);
280 static gint gtk_entry_motion_notify (GtkWidget *widget,
281 GdkEventMotion *event);
282 static gint gtk_entry_key_press (GtkWidget *widget,
284 static gint gtk_entry_key_release (GtkWidget *widget,
286 static gint gtk_entry_focus_in (GtkWidget *widget,
287 GdkEventFocus *event);
288 static gint gtk_entry_focus_out (GtkWidget *widget,
289 GdkEventFocus *event);
290 static void gtk_entry_grab_focus (GtkWidget *widget);
291 static void gtk_entry_style_set (GtkWidget *widget,
292 GtkStyle *previous_style);
293 static gboolean gtk_entry_query_tooltip (GtkWidget *widget,
296 gboolean keyboard_tip,
297 GtkTooltip *tooltip);
298 static void gtk_entry_direction_changed (GtkWidget *widget,
299 GtkTextDirection previous_dir);
300 static void gtk_entry_state_changed (GtkWidget *widget,
301 GtkStateType previous_state);
302 static void gtk_entry_screen_changed (GtkWidget *widget,
303 GdkScreen *old_screen);
305 static gboolean gtk_entry_drag_drop (GtkWidget *widget,
306 GdkDragContext *context,
310 static gboolean gtk_entry_drag_motion (GtkWidget *widget,
311 GdkDragContext *context,
315 static void gtk_entry_drag_leave (GtkWidget *widget,
316 GdkDragContext *context,
318 static void gtk_entry_drag_data_received (GtkWidget *widget,
319 GdkDragContext *context,
322 GtkSelectionData *selection_data,
325 static void gtk_entry_drag_data_get (GtkWidget *widget,
326 GdkDragContext *context,
327 GtkSelectionData *selection_data,
330 static void gtk_entry_drag_data_delete (GtkWidget *widget,
331 GdkDragContext *context);
332 static void gtk_entry_drag_begin (GtkWidget *widget,
333 GdkDragContext *context);
334 static void gtk_entry_drag_end (GtkWidget *widget,
335 GdkDragContext *context);
338 /* GtkEditable method implementations
340 static void gtk_entry_insert_text (GtkEditable *editable,
341 const gchar *new_text,
342 gint new_text_length,
344 static void gtk_entry_delete_text (GtkEditable *editable,
347 static gchar * gtk_entry_get_chars (GtkEditable *editable,
350 static void gtk_entry_real_set_position (GtkEditable *editable,
352 static gint gtk_entry_get_position (GtkEditable *editable);
353 static void gtk_entry_set_selection_bounds (GtkEditable *editable,
356 static gboolean gtk_entry_get_selection_bounds (GtkEditable *editable,
360 /* GtkCellEditable method implementations
362 static void gtk_entry_start_editing (GtkCellEditable *cell_editable,
365 /* Default signal handlers
367 static void gtk_entry_real_insert_text (GtkEditable *editable,
368 const gchar *new_text,
369 gint new_text_length,
371 static void gtk_entry_real_delete_text (GtkEditable *editable,
374 static void gtk_entry_move_cursor (GtkEntry *entry,
375 GtkMovementStep step,
377 gboolean extend_selection);
378 static void gtk_entry_insert_at_cursor (GtkEntry *entry,
380 static void gtk_entry_delete_from_cursor (GtkEntry *entry,
383 static void gtk_entry_backspace (GtkEntry *entry);
384 static void gtk_entry_cut_clipboard (GtkEntry *entry);
385 static void gtk_entry_copy_clipboard (GtkEntry *entry);
386 static void gtk_entry_paste_clipboard (GtkEntry *entry);
387 static void gtk_entry_toggle_overwrite (GtkEntry *entry);
388 static void gtk_entry_select_all (GtkEntry *entry);
389 static void gtk_entry_real_activate (GtkEntry *entry);
390 static gboolean gtk_entry_popup_menu (GtkWidget *widget);
392 static void keymap_direction_changed (GdkKeymap *keymap,
394 static void keymap_state_changed (GdkKeymap *keymap,
396 static void remove_capslock_feedback (GtkEntry *entry);
398 /* IM Context Callbacks
400 static void gtk_entry_commit_cb (GtkIMContext *context,
403 static void gtk_entry_preedit_changed_cb (GtkIMContext *context,
405 static gboolean gtk_entry_retrieve_surrounding_cb (GtkIMContext *context,
407 static gboolean gtk_entry_delete_surrounding_cb (GtkIMContext *context,
414 static void gtk_entry_enter_text (GtkEntry *entry,
416 static void gtk_entry_set_positions (GtkEntry *entry,
418 gint selection_bound);
419 static void gtk_entry_draw_text (GtkEntry *entry,
421 static void gtk_entry_draw_cursor (GtkEntry *entry,
424 static PangoLayout *gtk_entry_ensure_layout (GtkEntry *entry,
425 gboolean include_preedit);
426 static void gtk_entry_reset_layout (GtkEntry *entry);
427 static void gtk_entry_queue_draw (GtkEntry *entry);
428 static void gtk_entry_recompute (GtkEntry *entry);
429 static gint gtk_entry_find_position (GtkEntry *entry,
431 static void gtk_entry_get_cursor_locations (GtkEntry *entry,
435 static void gtk_entry_adjust_scroll (GtkEntry *entry);
436 static gint gtk_entry_move_visually (GtkEntry *editable,
439 static gint gtk_entry_move_logically (GtkEntry *entry,
442 static gint gtk_entry_move_forward_word (GtkEntry *entry,
444 gboolean allow_whitespace);
445 static gint gtk_entry_move_backward_word (GtkEntry *entry,
447 gboolean allow_whitespace);
448 static void gtk_entry_delete_whitespace (GtkEntry *entry);
449 static void gtk_entry_select_word (GtkEntry *entry);
450 static void gtk_entry_select_line (GtkEntry *entry);
451 static void gtk_entry_paste (GtkEntry *entry,
453 static void gtk_entry_update_primary_selection (GtkEntry *entry);
454 static void gtk_entry_do_popup (GtkEntry *entry,
455 GdkEventButton *event);
456 static gboolean gtk_entry_mnemonic_activate (GtkWidget *widget,
457 gboolean group_cycling);
458 static void gtk_entry_check_cursor_blink (GtkEntry *entry);
459 static void gtk_entry_pend_cursor_blink (GtkEntry *entry);
460 static void gtk_entry_reset_blink_time (GtkEntry *entry);
461 static void gtk_entry_get_text_area_size (GtkEntry *entry,
466 static void get_text_area_size (GtkEntry *entry,
471 static void get_widget_window_size (GtkEntry *entry,
476 static void gtk_entry_move_adjustments (GtkEntry *entry);
477 static void gtk_entry_ensure_pixbuf (GtkEntry *entry,
478 GtkEntryIconPosition icon_pos);
482 static gint gtk_entry_completion_timeout (gpointer data);
483 static gboolean gtk_entry_completion_key_press (GtkWidget *widget,
486 static void gtk_entry_completion_changed (GtkWidget *entry,
488 static gboolean check_completion_callback (GtkEntryCompletion *completion);
489 static void clear_completion_callback (GtkEntry *entry,
491 static gboolean accept_completion_callback (GtkEntry *entry);
492 static void completion_insert_text_callback (GtkEntry *entry,
496 GtkEntryCompletion *completion);
497 static void completion_changed (GtkEntryCompletion *completion,
500 static void disconnect_completion_signals (GtkEntry *entry,
501 GtkEntryCompletion *completion);
502 static void connect_completion_signals (GtkEntry *entry,
503 GtkEntryCompletion *completion);
505 static void begin_change (GtkEntry *entry);
506 static void end_change (GtkEntry *entry);
507 static void emit_changed (GtkEntry *entry);
510 static void buffer_inserted_text (GtkEntryBuffer *buffer,
515 static void buffer_deleted_text (GtkEntryBuffer *buffer,
519 static void buffer_notify_text (GtkEntryBuffer *buffer,
522 static void buffer_notify_length (GtkEntryBuffer *buffer,
525 static void buffer_notify_max_length (GtkEntryBuffer *buffer,
528 static void buffer_connect_signals (GtkEntry *entry);
529 static void buffer_disconnect_signals (GtkEntry *entry);
530 static GtkEntryBuffer *get_buffer (GtkEntry *entry);
533 G_DEFINE_TYPE_WITH_CODE (GtkEntry, gtk_entry, GTK_TYPE_WIDGET,
534 G_IMPLEMENT_INTERFACE (GTK_TYPE_EDITABLE,
535 gtk_entry_editable_init)
536 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_EDITABLE,
537 gtk_entry_cell_editable_init))
540 add_move_binding (GtkBindingSet *binding_set,
543 GtkMovementStep step,
546 g_return_if_fail ((modmask & GDK_SHIFT_MASK) == 0);
548 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
552 G_TYPE_BOOLEAN, FALSE);
554 /* Selection-extending version */
555 gtk_binding_entry_add_signal (binding_set, keyval, modmask | GDK_SHIFT_MASK,
559 G_TYPE_BOOLEAN, TRUE);
563 gtk_entry_class_init (GtkEntryClass *class)
565 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
566 GtkWidgetClass *widget_class;
567 GtkBindingSet *binding_set;
569 widget_class = (GtkWidgetClass*) class;
571 gobject_class->dispose = gtk_entry_dispose;
572 gobject_class->finalize = gtk_entry_finalize;
573 gobject_class->set_property = gtk_entry_set_property;
574 gobject_class->get_property = gtk_entry_get_property;
576 widget_class->destroy = gtk_entry_destroy;
577 widget_class->map = gtk_entry_map;
578 widget_class->unmap = gtk_entry_unmap;
579 widget_class->realize = gtk_entry_realize;
580 widget_class->unrealize = gtk_entry_unrealize;
581 widget_class->size_request = gtk_entry_size_request;
582 widget_class->size_allocate = gtk_entry_size_allocate;
583 widget_class->draw = gtk_entry_draw;
584 widget_class->enter_notify_event = gtk_entry_enter_notify;
585 widget_class->leave_notify_event = gtk_entry_leave_notify;
586 widget_class->button_press_event = gtk_entry_button_press;
587 widget_class->button_release_event = gtk_entry_button_release;
588 widget_class->motion_notify_event = gtk_entry_motion_notify;
589 widget_class->key_press_event = gtk_entry_key_press;
590 widget_class->key_release_event = gtk_entry_key_release;
591 widget_class->focus_in_event = gtk_entry_focus_in;
592 widget_class->focus_out_event = gtk_entry_focus_out;
593 widget_class->grab_focus = gtk_entry_grab_focus;
594 widget_class->style_set = gtk_entry_style_set;
595 widget_class->query_tooltip = gtk_entry_query_tooltip;
596 widget_class->drag_begin = gtk_entry_drag_begin;
597 widget_class->drag_end = gtk_entry_drag_end;
598 widget_class->direction_changed = gtk_entry_direction_changed;
599 widget_class->state_changed = gtk_entry_state_changed;
600 widget_class->screen_changed = gtk_entry_screen_changed;
601 widget_class->mnemonic_activate = gtk_entry_mnemonic_activate;
603 widget_class->drag_drop = gtk_entry_drag_drop;
604 widget_class->drag_motion = gtk_entry_drag_motion;
605 widget_class->drag_leave = gtk_entry_drag_leave;
606 widget_class->drag_data_received = gtk_entry_drag_data_received;
607 widget_class->drag_data_get = gtk_entry_drag_data_get;
608 widget_class->drag_data_delete = gtk_entry_drag_data_delete;
610 widget_class->popup_menu = gtk_entry_popup_menu;
612 class->move_cursor = gtk_entry_move_cursor;
613 class->insert_at_cursor = gtk_entry_insert_at_cursor;
614 class->delete_from_cursor = gtk_entry_delete_from_cursor;
615 class->backspace = gtk_entry_backspace;
616 class->cut_clipboard = gtk_entry_cut_clipboard;
617 class->copy_clipboard = gtk_entry_copy_clipboard;
618 class->paste_clipboard = gtk_entry_paste_clipboard;
619 class->toggle_overwrite = gtk_entry_toggle_overwrite;
620 class->activate = gtk_entry_real_activate;
621 class->get_text_area_size = gtk_entry_get_text_area_size;
623 quark_inner_border = g_quark_from_static_string ("gtk-entry-inner-border");
624 quark_password_hint = g_quark_from_static_string ("gtk-entry-password-hint");
625 quark_cursor_hadjustment = g_quark_from_static_string ("gtk-hadjustment");
626 quark_capslock_feedback = g_quark_from_static_string ("gtk-entry-capslock-feedback");
628 g_object_class_override_property (gobject_class,
629 PROP_EDITING_CANCELED,
632 g_object_class_install_property (gobject_class,
634 g_param_spec_object ("buffer",
636 P_("Text buffer object which actually stores entry text"),
637 GTK_TYPE_ENTRY_BUFFER,
638 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT));
640 g_object_class_install_property (gobject_class,
641 PROP_CURSOR_POSITION,
642 g_param_spec_int ("cursor-position",
643 P_("Cursor Position"),
644 P_("The current position of the insertion cursor in chars"),
646 GTK_ENTRY_BUFFER_MAX_SIZE,
648 GTK_PARAM_READABLE));
650 g_object_class_install_property (gobject_class,
651 PROP_SELECTION_BOUND,
652 g_param_spec_int ("selection-bound",
653 P_("Selection Bound"),
654 P_("The position of the opposite end of the selection from the cursor in chars"),
656 GTK_ENTRY_BUFFER_MAX_SIZE,
658 GTK_PARAM_READABLE));
660 g_object_class_install_property (gobject_class,
662 g_param_spec_boolean ("editable",
664 P_("Whether the entry contents can be edited"),
666 GTK_PARAM_READWRITE));
668 g_object_class_install_property (gobject_class,
670 g_param_spec_int ("max-length",
671 P_("Maximum length"),
672 P_("Maximum number of characters for this entry. Zero if no maximum"),
674 GTK_ENTRY_BUFFER_MAX_SIZE,
676 GTK_PARAM_READWRITE));
677 g_object_class_install_property (gobject_class,
679 g_param_spec_boolean ("visibility",
681 P_("FALSE displays the \"invisible char\" instead of the actual text (password mode)"),
683 GTK_PARAM_READWRITE));
685 g_object_class_install_property (gobject_class,
687 g_param_spec_boolean ("has-frame",
689 P_("FALSE removes outside bevel from entry"),
691 GTK_PARAM_READWRITE));
693 g_object_class_install_property (gobject_class,
695 g_param_spec_boxed ("inner-border",
697 P_("Border between text and frame. Overrides the inner-border style property"),
699 GTK_PARAM_READWRITE));
701 g_object_class_install_property (gobject_class,
703 g_param_spec_unichar ("invisible-char",
704 P_("Invisible character"),
705 P_("The character to use when masking entry contents (in \"password mode\")"),
707 GTK_PARAM_READWRITE));
709 g_object_class_install_property (gobject_class,
710 PROP_ACTIVATES_DEFAULT,
711 g_param_spec_boolean ("activates-default",
712 P_("Activates default"),
713 P_("Whether to activate the default widget (such as the default button in a dialog) when Enter is pressed"),
715 GTK_PARAM_READWRITE));
716 g_object_class_install_property (gobject_class,
718 g_param_spec_int ("width-chars",
719 P_("Width in chars"),
720 P_("Number of characters to leave space for in the entry"),
724 GTK_PARAM_READWRITE));
726 g_object_class_install_property (gobject_class,
728 g_param_spec_int ("scroll-offset",
730 P_("Number of pixels of the entry scrolled off the screen to the left"),
734 GTK_PARAM_READABLE));
736 g_object_class_install_property (gobject_class,
738 g_param_spec_string ("text",
740 P_("The contents of the entry"),
742 GTK_PARAM_READWRITE));
747 * The horizontal alignment, from 0 (left) to 1 (right).
748 * Reversed for RTL layouts.
752 g_object_class_install_property (gobject_class,
754 g_param_spec_float ("xalign",
756 P_("The horizontal alignment, from 0 (left) to 1 (right). Reversed for RTL layouts."),
760 GTK_PARAM_READWRITE));
763 * GtkEntry:truncate-multiline:
765 * When %TRUE, pasted multi-line text is truncated to the first line.
769 g_object_class_install_property (gobject_class,
770 PROP_TRUNCATE_MULTILINE,
771 g_param_spec_boolean ("truncate-multiline",
772 P_("Truncate multiline"),
773 P_("Whether to truncate multiline pastes to one line."),
775 GTK_PARAM_READWRITE));
778 * GtkEntry:shadow-type:
780 * Which kind of shadow to draw around the entry when
781 * #GtkEntry:has-frame is set to %TRUE.
785 g_object_class_install_property (gobject_class,
787 g_param_spec_enum ("shadow-type",
789 P_("Which kind of shadow to draw around the entry when has-frame is set"),
790 GTK_TYPE_SHADOW_TYPE,
792 GTK_PARAM_READWRITE));
795 * GtkEntry:overwrite-mode:
797 * If text is overwritten when typing in the #GtkEntry.
801 g_object_class_install_property (gobject_class,
803 g_param_spec_boolean ("overwrite-mode",
804 P_("Overwrite mode"),
805 P_("Whether new text overwrites existing text"),
807 GTK_PARAM_READWRITE));
810 * GtkEntry:text-length:
812 * The length of the text in the #GtkEntry.
816 g_object_class_install_property (gobject_class,
818 g_param_spec_uint ("text-length",
820 P_("Length of the text currently in the entry"),
824 GTK_PARAM_READABLE));
826 * GtkEntry:invisible-char-set:
828 * Whether the invisible char has been set for the #GtkEntry.
832 g_object_class_install_property (gobject_class,
833 PROP_INVISIBLE_CHAR_SET,
834 g_param_spec_boolean ("invisible-char-set",
835 P_("Invisible character set"),
836 P_("Whether the invisible character has been set"),
838 GTK_PARAM_READWRITE));
841 * GtkEntry:caps-lock-warning
843 * Whether password entries will show a warning when Caps Lock is on.
845 * Note that the warning is shown using a secondary icon, and thus
846 * does not work if you are using the secondary icon position for some
851 g_object_class_install_property (gobject_class,
852 PROP_CAPS_LOCK_WARNING,
853 g_param_spec_boolean ("caps-lock-warning",
854 P_("Caps Lock warning"),
855 P_("Whether password entries will show a warning when Caps Lock is on"),
857 GTK_PARAM_READWRITE));
860 * GtkEntry:progress-fraction:
862 * The current fraction of the task that's been completed.
866 g_object_class_install_property (gobject_class,
867 PROP_PROGRESS_FRACTION,
868 g_param_spec_double ("progress-fraction",
869 P_("Progress Fraction"),
870 P_("The current fraction of the task that's been completed"),
874 GTK_PARAM_READWRITE));
877 * GtkEntry:progress-pulse-step:
879 * The fraction of total entry width to move the progress
880 * bouncing block for each call to gtk_entry_progress_pulse().
884 g_object_class_install_property (gobject_class,
885 PROP_PROGRESS_PULSE_STEP,
886 g_param_spec_double ("progress-pulse-step",
887 P_("Progress Pulse Step"),
888 P_("The fraction of total entry width to move the progress bouncing block for each call to gtk_entry_progress_pulse()"),
892 GTK_PARAM_READWRITE));
895 * GtkEntry:primary-icon-pixbuf:
897 * A pixbuf to use as the primary icon for the entry.
901 g_object_class_install_property (gobject_class,
903 g_param_spec_object ("primary-icon-pixbuf",
904 P_("Primary pixbuf"),
905 P_("Primary pixbuf for the entry"),
907 GTK_PARAM_READWRITE));
910 * GtkEntry:secondary-icon-pixbuf:
912 * An pixbuf to use as the secondary icon for the entry.
916 g_object_class_install_property (gobject_class,
917 PROP_PIXBUF_SECONDARY,
918 g_param_spec_object ("secondary-icon-pixbuf",
919 P_("Secondary pixbuf"),
920 P_("Secondary pixbuf for the entry"),
922 GTK_PARAM_READWRITE));
925 * GtkEntry:primary-icon-stock:
927 * The stock id to use for the primary icon for the entry.
931 g_object_class_install_property (gobject_class,
933 g_param_spec_string ("primary-icon-stock",
934 P_("Primary stock ID"),
935 P_("Stock ID for primary icon"),
937 GTK_PARAM_READWRITE));
940 * GtkEntry:secondary-icon-stock:
942 * The stock id to use for the secondary icon for the entry.
946 g_object_class_install_property (gobject_class,
947 PROP_STOCK_SECONDARY,
948 g_param_spec_string ("secondary-icon-stock",
949 P_("Secondary stock ID"),
950 P_("Stock ID for secondary icon"),
952 GTK_PARAM_READWRITE));
955 * GtkEntry:primary-icon-name:
957 * The icon name to use for the primary icon for the entry.
961 g_object_class_install_property (gobject_class,
962 PROP_ICON_NAME_PRIMARY,
963 g_param_spec_string ("primary-icon-name",
964 P_("Primary icon name"),
965 P_("Icon name for primary icon"),
967 GTK_PARAM_READWRITE));
970 * GtkEntry:secondary-icon-name:
972 * The icon name to use for the secondary icon for the entry.
976 g_object_class_install_property (gobject_class,
977 PROP_ICON_NAME_SECONDARY,
978 g_param_spec_string ("secondary-icon-name",
979 P_("Secondary icon name"),
980 P_("Icon name for secondary icon"),
982 GTK_PARAM_READWRITE));
985 * GtkEntry:primary-icon-gicon:
987 * The #GIcon to use for the primary icon for the entry.
991 g_object_class_install_property (gobject_class,
993 g_param_spec_object ("primary-icon-gicon",
995 P_("GIcon for primary icon"),
997 GTK_PARAM_READWRITE));
1000 * GtkEntry:secondary-icon-gicon:
1002 * The #GIcon to use for the secondary icon for the entry.
1006 g_object_class_install_property (gobject_class,
1007 PROP_GICON_SECONDARY,
1008 g_param_spec_object ("secondary-icon-gicon",
1009 P_("Secondary GIcon"),
1010 P_("GIcon for secondary icon"),
1012 GTK_PARAM_READWRITE));
1015 * GtkEntry:primary-icon-storage-type:
1017 * The representation which is used for the primary icon of the entry.
1021 g_object_class_install_property (gobject_class,
1022 PROP_STORAGE_TYPE_PRIMARY,
1023 g_param_spec_enum ("primary-icon-storage-type",
1024 P_("Primary storage type"),
1025 P_("The representation being used for primary icon"),
1026 GTK_TYPE_IMAGE_TYPE,
1028 GTK_PARAM_READABLE));
1031 * GtkEntry:secondary-icon-storage-type:
1033 * The representation which is used for the secondary icon of the entry.
1037 g_object_class_install_property (gobject_class,
1038 PROP_STORAGE_TYPE_SECONDARY,
1039 g_param_spec_enum ("secondary-icon-storage-type",
1040 P_("Secondary storage type"),
1041 P_("The representation being used for secondary icon"),
1042 GTK_TYPE_IMAGE_TYPE,
1044 GTK_PARAM_READABLE));
1047 * GtkEntry:primary-icon-activatable:
1049 * Whether the primary icon is activatable.
1051 * GTK+ emits the #GtkEntry::icon-press and #GtkEntry::icon-release
1052 * signals only on sensitive, activatable icons.
1054 * Sensitive, but non-activatable icons can be used for purely
1055 * informational purposes.
1059 g_object_class_install_property (gobject_class,
1060 PROP_ACTIVATABLE_PRIMARY,
1061 g_param_spec_boolean ("primary-icon-activatable",
1062 P_("Primary icon activatable"),
1063 P_("Whether the primary icon is activatable"),
1065 GTK_PARAM_READWRITE));
1068 * GtkEntry:secondary-icon-activatable:
1070 * Whether the secondary icon is activatable.
1072 * GTK+ emits the #GtkEntry::icon-press and #GtkEntry::icon-release
1073 * signals only on sensitive, activatable icons.
1075 * Sensitive, but non-activatable icons can be used for purely
1076 * informational purposes.
1080 g_object_class_install_property (gobject_class,
1081 PROP_ACTIVATABLE_SECONDARY,
1082 g_param_spec_boolean ("secondary-icon-activatable",
1083 P_("Secondary icon activatable"),
1084 P_("Whether the secondary icon is activatable"),
1086 GTK_PARAM_READWRITE));
1090 * GtkEntry:primary-icon-sensitive:
1092 * Whether the primary icon is sensitive.
1094 * An insensitive icon appears grayed out. GTK+ does not emit the
1095 * #GtkEntry::icon-press and #GtkEntry::icon-release signals and
1096 * does not allow DND from insensitive icons.
1098 * An icon should be set insensitive if the action that would trigger
1099 * when clicked is currently not available.
1103 g_object_class_install_property (gobject_class,
1104 PROP_SENSITIVE_PRIMARY,
1105 g_param_spec_boolean ("primary-icon-sensitive",
1106 P_("Primary icon sensitive"),
1107 P_("Whether the primary icon is sensitive"),
1109 GTK_PARAM_READWRITE));
1112 * GtkEntry:secondary-icon-sensitive:
1114 * Whether the secondary icon is sensitive.
1116 * An insensitive icon appears grayed out. GTK+ does not emit the
1117 * #GtkEntry::icon-press and #GtkEntry::icon-release signals and
1118 * does not allow DND from insensitive icons.
1120 * An icon should be set insensitive if the action that would trigger
1121 * when clicked is currently not available.
1125 g_object_class_install_property (gobject_class,
1126 PROP_SENSITIVE_SECONDARY,
1127 g_param_spec_boolean ("secondary-icon-sensitive",
1128 P_("Secondary icon sensitive"),
1129 P_("Whether the secondary icon is sensitive"),
1131 GTK_PARAM_READWRITE));
1134 * GtkEntry:primary-icon-tooltip-text:
1136 * The contents of the tooltip on the primary icon.
1138 * Also see gtk_entry_set_icon_tooltip_text().
1142 g_object_class_install_property (gobject_class,
1143 PROP_TOOLTIP_TEXT_PRIMARY,
1144 g_param_spec_string ("primary-icon-tooltip-text",
1145 P_("Primary icon tooltip text"),
1146 P_("The contents of the tooltip on the primary icon"),
1148 GTK_PARAM_READWRITE));
1151 * GtkEntry:secondary-icon-tooltip-text:
1153 * The contents of the tooltip on the secondary icon.
1155 * Also see gtk_entry_set_icon_tooltip_text().
1159 g_object_class_install_property (gobject_class,
1160 PROP_TOOLTIP_TEXT_SECONDARY,
1161 g_param_spec_string ("secondary-icon-tooltip-text",
1162 P_("Secondary icon tooltip text"),
1163 P_("The contents of the tooltip on the secondary icon"),
1165 GTK_PARAM_READWRITE));
1168 * GtkEntry:primary-icon-tooltip-markup:
1170 * The contents of the tooltip on the primary icon, which is marked up
1171 * with the <link linkend="PangoMarkupFormat">Pango text markup
1174 * Also see gtk_entry_set_icon_tooltip_markup().
1178 g_object_class_install_property (gobject_class,
1179 PROP_TOOLTIP_MARKUP_PRIMARY,
1180 g_param_spec_string ("primary-icon-tooltip-markup",
1181 P_("Primary icon tooltip markup"),
1182 P_("The contents of the tooltip on the primary icon"),
1184 GTK_PARAM_READWRITE));
1187 * GtkEntry:secondary-icon-tooltip-markup:
1189 * The contents of the tooltip on the secondary icon, which is marked up
1190 * with the <link linkend="PangoMarkupFormat">Pango text markup
1193 * Also see gtk_entry_set_icon_tooltip_markup().
1197 g_object_class_install_property (gobject_class,
1198 PROP_TOOLTIP_MARKUP_SECONDARY,
1199 g_param_spec_string ("secondary-icon-tooltip-markup",
1200 P_("Secondary icon tooltip markup"),
1201 P_("The contents of the tooltip on the secondary icon"),
1203 GTK_PARAM_READWRITE));
1206 * GtkEntry:im-module:
1208 * Which IM (input method) module should be used for this entry.
1209 * See #GtkIMContext.
1211 * Setting this to a non-%NULL value overrides the
1212 * system-wide IM module setting. See the GtkSettings
1213 * #GtkSettings:gtk-im-module property.
1217 g_object_class_install_property (gobject_class,
1219 g_param_spec_string ("im-module",
1221 P_("Which IM module should be used"),
1223 GTK_PARAM_READWRITE));
1226 * GtkEntry:icon-prelight:
1228 * The prelight style property determines whether activatable
1229 * icons prelight on mouseover.
1233 gtk_widget_class_install_style_property (widget_class,
1234 g_param_spec_boolean ("icon-prelight",
1235 P_("Icon Prelight"),
1236 P_("Whether activatable icons should prelight when hovered"),
1238 GTK_PARAM_READABLE));
1241 * GtkEntry:progress-border:
1243 * The border around the progress bar in the entry.
1247 gtk_widget_class_install_style_property (widget_class,
1248 g_param_spec_boxed ("progress-border",
1249 P_("Progress Border"),
1250 P_("Border around the progress bar"),
1252 GTK_PARAM_READABLE));
1255 * GtkEntry:invisible-char:
1257 * The invisible character is used when masking entry contents (in
1258 * \"password mode\")"). When it is not explicitly set with the
1259 * #GtkEntry::invisible-char property, GTK+ determines the character
1260 * to use from a list of possible candidates, depending on availability
1261 * in the current font.
1263 * This style property allows the theme to prepend a character
1264 * to the list of candidates.
1268 gtk_widget_class_install_style_property (widget_class,
1269 g_param_spec_unichar ("invisible-char",
1270 P_("Invisible character"),
1271 P_("The character to use when masking entry contents (in \"password mode\")"),
1273 GTK_PARAM_READABLE));
1276 * GtkEntry::populate-popup:
1277 * @entry: The entry on which the signal is emitted
1278 * @menu: the menu that is being populated
1280 * The ::populate-popup signal gets emitted before showing the
1281 * context menu of the entry.
1283 * If you need to add items to the context menu, connect
1284 * to this signal and append your menuitems to the @menu.
1286 signals[POPULATE_POPUP] =
1287 g_signal_new (I_("populate-popup"),
1288 G_OBJECT_CLASS_TYPE (gobject_class),
1290 G_STRUCT_OFFSET (GtkEntryClass, populate_popup),
1292 _gtk_marshal_VOID__OBJECT,
1296 /* Action signals */
1299 * GtkEntry::activate:
1300 * @entry: The entry on which the signal is emitted
1302 * A <link linkend="keybinding-signals">keybinding signal</link>
1303 * which gets emitted when the user activates the entry.
1305 * Applications should not connect to it, but may emit it with
1306 * g_signal_emit_by_name() if they need to control activation
1309 * The default bindings for this signal are all forms of the Enter key.
1312 g_signal_new (I_("activate"),
1313 G_OBJECT_CLASS_TYPE (gobject_class),
1314 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1315 G_STRUCT_OFFSET (GtkEntryClass, activate),
1317 _gtk_marshal_VOID__VOID,
1319 widget_class->activate_signal = signals[ACTIVATE];
1322 * GtkEntry::move-cursor:
1323 * @entry: the object which received the signal
1324 * @step: the granularity of the move, as a #GtkMovementStep
1325 * @count: the number of @step units to move
1326 * @extend_selection: %TRUE if the move should extend the selection
1328 * The ::move-cursor signal is a
1329 * <link linkend="keybinding-signals">keybinding signal</link>
1330 * which gets emitted when the user initiates a cursor movement.
1331 * If the cursor is not visible in @entry, this signal causes
1332 * the viewport to be moved instead.
1334 * Applications should not connect to it, but may emit it with
1335 * g_signal_emit_by_name() if they need to control the cursor
1338 * The default bindings for this signal come in two variants,
1339 * the variant with the Shift modifier extends the selection,
1340 * the variant without the Shift modifer does not.
1341 * There are too many key combinations to list them all here.
1343 * <listitem>Arrow keys move by individual characters/lines</listitem>
1344 * <listitem>Ctrl-arrow key combinations move by words/paragraphs</listitem>
1345 * <listitem>Home/End keys move to the ends of the buffer</listitem>
1348 signals[MOVE_CURSOR] =
1349 g_signal_new (I_("move-cursor"),
1350 G_OBJECT_CLASS_TYPE (gobject_class),
1351 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1352 G_STRUCT_OFFSET (GtkEntryClass, move_cursor),
1354 _gtk_marshal_VOID__ENUM_INT_BOOLEAN,
1356 GTK_TYPE_MOVEMENT_STEP,
1361 * GtkEntry::insert-at-cursor:
1362 * @entry: the object which received the signal
1363 * @string: the string to insert
1365 * The ::insert-at-cursor signal is a
1366 * <link linkend="keybinding-signals">keybinding signal</link>
1367 * which gets emitted when the user initiates the insertion of a
1368 * fixed string at the cursor.
1370 * This signal has no default bindings.
1372 signals[INSERT_AT_CURSOR] =
1373 g_signal_new (I_("insert-at-cursor"),
1374 G_OBJECT_CLASS_TYPE (gobject_class),
1375 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1376 G_STRUCT_OFFSET (GtkEntryClass, insert_at_cursor),
1378 _gtk_marshal_VOID__STRING,
1383 * GtkEntry::delete-from-cursor:
1384 * @entry: the object which received the signal
1385 * @type: the granularity of the deletion, as a #GtkDeleteType
1386 * @count: the number of @type units to delete
1388 * The ::delete-from-cursor signal is a
1389 * <link linkend="keybinding-signals">keybinding signal</link>
1390 * which gets emitted when the user initiates a text deletion.
1392 * If the @type is %GTK_DELETE_CHARS, GTK+ deletes the selection
1393 * if there is one, otherwise it deletes the requested number
1396 * The default bindings for this signal are
1397 * Delete for deleting a character and Ctrl-Delete for
1400 signals[DELETE_FROM_CURSOR] =
1401 g_signal_new (I_("delete-from-cursor"),
1402 G_OBJECT_CLASS_TYPE (gobject_class),
1403 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1404 G_STRUCT_OFFSET (GtkEntryClass, delete_from_cursor),
1406 _gtk_marshal_VOID__ENUM_INT,
1408 GTK_TYPE_DELETE_TYPE,
1412 * GtkEntry::backspace:
1413 * @entry: the object which received the signal
1415 * The ::backspace signal is a
1416 * <link linkend="keybinding-signals">keybinding signal</link>
1417 * which gets emitted when the user asks for it.
1419 * The default bindings for this signal are
1420 * Backspace and Shift-Backspace.
1422 signals[BACKSPACE] =
1423 g_signal_new (I_("backspace"),
1424 G_OBJECT_CLASS_TYPE (gobject_class),
1425 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1426 G_STRUCT_OFFSET (GtkEntryClass, backspace),
1428 _gtk_marshal_VOID__VOID,
1432 * GtkEntry::cut-clipboard:
1433 * @entry: the object which received the signal
1435 * The ::cut-clipboard signal is a
1436 * <link linkend="keybinding-signals">keybinding signal</link>
1437 * which gets emitted to cut the selection to the clipboard.
1439 * The default bindings for this signal are
1440 * Ctrl-x and Shift-Delete.
1442 signals[CUT_CLIPBOARD] =
1443 g_signal_new (I_("cut-clipboard"),
1444 G_OBJECT_CLASS_TYPE (gobject_class),
1445 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1446 G_STRUCT_OFFSET (GtkEntryClass, cut_clipboard),
1448 _gtk_marshal_VOID__VOID,
1452 * GtkEntry::copy-clipboard:
1453 * @entry: the object which received the signal
1455 * The ::copy-clipboard signal is a
1456 * <link linkend="keybinding-signals">keybinding signal</link>
1457 * which gets emitted to copy the selection to the clipboard.
1459 * The default bindings for this signal are
1460 * Ctrl-c and Ctrl-Insert.
1462 signals[COPY_CLIPBOARD] =
1463 g_signal_new (I_("copy-clipboard"),
1464 G_OBJECT_CLASS_TYPE (gobject_class),
1465 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1466 G_STRUCT_OFFSET (GtkEntryClass, copy_clipboard),
1468 _gtk_marshal_VOID__VOID,
1472 * GtkEntry::paste-clipboard:
1473 * @entry: the object which received the signal
1475 * The ::paste-clipboard signal is a
1476 * <link linkend="keybinding-signals">keybinding signal</link>
1477 * which gets emitted to paste the contents of the clipboard
1478 * into the text view.
1480 * The default bindings for this signal are
1481 * Ctrl-v and Shift-Insert.
1483 signals[PASTE_CLIPBOARD] =
1484 g_signal_new (I_("paste-clipboard"),
1485 G_OBJECT_CLASS_TYPE (gobject_class),
1486 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1487 G_STRUCT_OFFSET (GtkEntryClass, paste_clipboard),
1489 _gtk_marshal_VOID__VOID,
1493 * GtkEntry::toggle-overwrite:
1494 * @entry: the object which received the signal
1496 * The ::toggle-overwrite signal is a
1497 * <link linkend="keybinding-signals">keybinding signal</link>
1498 * which gets emitted to toggle the overwrite mode of the entry.
1500 * The default bindings for this signal is Insert.
1502 signals[TOGGLE_OVERWRITE] =
1503 g_signal_new (I_("toggle-overwrite"),
1504 G_OBJECT_CLASS_TYPE (gobject_class),
1505 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1506 G_STRUCT_OFFSET (GtkEntryClass, toggle_overwrite),
1508 _gtk_marshal_VOID__VOID,
1512 * GtkEntry::icon-press:
1513 * @entry: The entry on which the signal is emitted
1514 * @icon_pos: The position of the clicked icon
1515 * @event: the button press event
1517 * The ::icon-press signal is emitted when an activatable icon
1522 signals[ICON_PRESS] =
1523 g_signal_new (I_("icon-press"),
1524 G_TYPE_FROM_CLASS (gobject_class),
1528 _gtk_marshal_VOID__ENUM_BOXED,
1530 GTK_TYPE_ENTRY_ICON_POSITION,
1531 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1534 * GtkEntry::icon-release:
1535 * @entry: The entry on which the signal is emitted
1536 * @icon_pos: The position of the clicked icon
1537 * @event: the button release event
1539 * The ::icon-release signal is emitted on the button release from a
1540 * mouse click over an activatable icon.
1544 signals[ICON_RELEASE] =
1545 g_signal_new (I_("icon-release"),
1546 G_TYPE_FROM_CLASS (gobject_class),
1550 _gtk_marshal_VOID__ENUM_BOXED,
1552 GTK_TYPE_ENTRY_ICON_POSITION,
1553 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1556 * GtkEntry::preedit-changed:
1557 * @entry: the object which received the signal
1558 * @preedit: the current preedit string
1560 * If an input method is used, the typed text will not immediately
1561 * be committed to the buffer. So if you are interested in the text,
1562 * connect to this signal.
1566 signals[PREEDIT_CHANGED] =
1567 g_signal_new_class_handler (I_("preedit-changed"),
1568 G_OBJECT_CLASS_TYPE (gobject_class),
1569 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1572 _gtk_marshal_VOID__STRING,
1581 binding_set = gtk_binding_set_by_class (class);
1583 /* Moving the insertion point */
1584 add_move_binding (binding_set, GDK_KEY_Right, 0,
1585 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1587 add_move_binding (binding_set, GDK_KEY_Left, 0,
1588 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1590 add_move_binding (binding_set, GDK_KEY_KP_Right, 0,
1591 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1593 add_move_binding (binding_set, GDK_KEY_KP_Left, 0,
1594 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1596 add_move_binding (binding_set, GDK_KEY_Right, GDK_CONTROL_MASK,
1597 GTK_MOVEMENT_WORDS, 1);
1599 add_move_binding (binding_set, GDK_KEY_Left, GDK_CONTROL_MASK,
1600 GTK_MOVEMENT_WORDS, -1);
1602 add_move_binding (binding_set, GDK_KEY_KP_Right, GDK_CONTROL_MASK,
1603 GTK_MOVEMENT_WORDS, 1);
1605 add_move_binding (binding_set, GDK_KEY_KP_Left, GDK_CONTROL_MASK,
1606 GTK_MOVEMENT_WORDS, -1);
1608 add_move_binding (binding_set, GDK_KEY_Home, 0,
1609 GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
1611 add_move_binding (binding_set, GDK_KEY_End, 0,
1612 GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
1614 add_move_binding (binding_set, GDK_KEY_KP_Home, 0,
1615 GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
1617 add_move_binding (binding_set, GDK_KEY_KP_End, 0,
1618 GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
1620 add_move_binding (binding_set, GDK_KEY_Home, GDK_CONTROL_MASK,
1621 GTK_MOVEMENT_BUFFER_ENDS, -1);
1623 add_move_binding (binding_set, GDK_KEY_End, GDK_CONTROL_MASK,
1624 GTK_MOVEMENT_BUFFER_ENDS, 1);
1626 add_move_binding (binding_set, GDK_KEY_KP_Home, GDK_CONTROL_MASK,
1627 GTK_MOVEMENT_BUFFER_ENDS, -1);
1629 add_move_binding (binding_set, GDK_KEY_KP_End, GDK_CONTROL_MASK,
1630 GTK_MOVEMENT_BUFFER_ENDS, 1);
1634 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK,
1636 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1638 G_TYPE_BOOLEAN, FALSE);
1639 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK,
1641 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1643 G_TYPE_BOOLEAN, TRUE);
1645 gtk_binding_entry_add_signal (binding_set, GDK_KEY_slash, GDK_CONTROL_MASK,
1647 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1649 G_TYPE_BOOLEAN, FALSE);
1650 gtk_binding_entry_add_signal (binding_set, GDK_KEY_slash, GDK_CONTROL_MASK,
1652 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1654 G_TYPE_BOOLEAN, TRUE);
1657 gtk_binding_entry_add_signal (binding_set, GDK_KEY_backslash, GDK_CONTROL_MASK,
1659 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_VISUAL_POSITIONS,
1661 G_TYPE_BOOLEAN, FALSE);
1662 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_SHIFT_MASK | GDK_CONTROL_MASK,
1664 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_VISUAL_POSITIONS,
1666 G_TYPE_BOOLEAN, FALSE);
1670 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Return, 0,
1672 gtk_binding_entry_add_signal (binding_set, GDK_KEY_ISO_Enter, 0,
1674 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Enter, 0,
1678 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, 0,
1679 "delete-from-cursor", 2,
1680 G_TYPE_ENUM, GTK_DELETE_CHARS,
1683 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Delete, 0,
1684 "delete-from-cursor", 2,
1685 G_TYPE_ENUM, GTK_DELETE_CHARS,
1688 gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, 0,
1691 /* Make this do the same as Backspace, to help with mis-typing */
1692 gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, GDK_SHIFT_MASK,
1695 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, GDK_CONTROL_MASK,
1696 "delete-from-cursor", 2,
1697 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1700 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Delete, GDK_CONTROL_MASK,
1701 "delete-from-cursor", 2,
1702 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1705 gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, GDK_CONTROL_MASK,
1706 "delete-from-cursor", 2,
1707 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1710 /* Cut/copy/paste */
1712 gtk_binding_entry_add_signal (binding_set, GDK_KEY_x, GDK_CONTROL_MASK,
1713 "cut-clipboard", 0);
1714 gtk_binding_entry_add_signal (binding_set, GDK_KEY_c, GDK_CONTROL_MASK,
1715 "copy-clipboard", 0);
1716 gtk_binding_entry_add_signal (binding_set, GDK_KEY_v, GDK_CONTROL_MASK,
1717 "paste-clipboard", 0);
1719 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, GDK_SHIFT_MASK,
1720 "cut-clipboard", 0);
1721 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, GDK_CONTROL_MASK,
1722 "copy-clipboard", 0);
1723 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, GDK_SHIFT_MASK,
1724 "paste-clipboard", 0);
1727 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, 0,
1728 "toggle-overwrite", 0);
1729 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Insert, 0,
1730 "toggle-overwrite", 0);
1733 * GtkEntry:inner-border:
1735 * Sets the text area's border between the text and the frame.
1739 gtk_widget_class_install_style_property (widget_class,
1740 g_param_spec_boxed ("inner-border",
1742 P_("Border between text and frame."),
1744 GTK_PARAM_READABLE));
1746 g_type_class_add_private (gobject_class, sizeof (GtkEntryPrivate));
1750 gtk_entry_editable_init (GtkEditableInterface *iface)
1752 iface->do_insert_text = gtk_entry_insert_text;
1753 iface->do_delete_text = gtk_entry_delete_text;
1754 iface->insert_text = gtk_entry_real_insert_text;
1755 iface->delete_text = gtk_entry_real_delete_text;
1756 iface->get_chars = gtk_entry_get_chars;
1757 iface->set_selection_bounds = gtk_entry_set_selection_bounds;
1758 iface->get_selection_bounds = gtk_entry_get_selection_bounds;
1759 iface->set_position = gtk_entry_real_set_position;
1760 iface->get_position = gtk_entry_get_position;
1764 gtk_entry_cell_editable_init (GtkCellEditableIface *iface)
1766 iface->start_editing = gtk_entry_start_editing;
1770 gtk_entry_set_property (GObject *object,
1772 const GValue *value,
1775 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (object);
1776 GtkEntry *entry = GTK_ENTRY (object);
1782 gtk_entry_set_buffer (entry, g_value_get_object (value));
1787 gboolean new_value = g_value_get_boolean (value);
1789 if (new_value != entry->editable)
1791 widget = GTK_WIDGET (entry);
1794 _gtk_entry_reset_im_context (entry);
1795 if (gtk_widget_has_focus (widget))
1796 gtk_im_context_focus_out (entry->im_context);
1798 entry->preedit_length = 0;
1799 entry->preedit_cursor = 0;
1802 entry->editable = new_value;
1804 if (new_value && gtk_widget_has_focus (widget))
1805 gtk_im_context_focus_in (entry->im_context);
1807 gtk_entry_queue_draw (entry);
1812 case PROP_MAX_LENGTH:
1813 gtk_entry_set_max_length (entry, g_value_get_int (value));
1816 case PROP_VISIBILITY:
1817 gtk_entry_set_visibility (entry, g_value_get_boolean (value));
1820 case PROP_HAS_FRAME:
1821 gtk_entry_set_has_frame (entry, g_value_get_boolean (value));
1824 case PROP_INNER_BORDER:
1825 gtk_entry_set_inner_border (entry, g_value_get_boxed (value));
1828 case PROP_INVISIBLE_CHAR:
1829 gtk_entry_set_invisible_char (entry, g_value_get_uint (value));
1832 case PROP_ACTIVATES_DEFAULT:
1833 gtk_entry_set_activates_default (entry, g_value_get_boolean (value));
1836 case PROP_WIDTH_CHARS:
1837 gtk_entry_set_width_chars (entry, g_value_get_int (value));
1841 gtk_entry_set_text (entry, g_value_get_string (value));
1845 gtk_entry_set_alignment (entry, g_value_get_float (value));
1848 case PROP_TRUNCATE_MULTILINE:
1849 entry->truncate_multiline = g_value_get_boolean (value);
1852 case PROP_SHADOW_TYPE:
1853 priv->shadow_type = g_value_get_enum (value);
1856 case PROP_OVERWRITE_MODE:
1857 gtk_entry_set_overwrite_mode (entry, g_value_get_boolean (value));
1860 case PROP_INVISIBLE_CHAR_SET:
1861 if (g_value_get_boolean (value))
1862 priv->invisible_char_set = TRUE;
1864 gtk_entry_unset_invisible_char (entry);
1867 case PROP_CAPS_LOCK_WARNING:
1868 priv->caps_lock_warning = g_value_get_boolean (value);
1871 case PROP_PROGRESS_FRACTION:
1872 gtk_entry_set_progress_fraction (entry, g_value_get_double (value));
1875 case PROP_PROGRESS_PULSE_STEP:
1876 gtk_entry_set_progress_pulse_step (entry, g_value_get_double (value));
1879 case PROP_PIXBUF_PRIMARY:
1880 gtk_entry_set_icon_from_pixbuf (entry,
1881 GTK_ENTRY_ICON_PRIMARY,
1882 g_value_get_object (value));
1885 case PROP_PIXBUF_SECONDARY:
1886 gtk_entry_set_icon_from_pixbuf (entry,
1887 GTK_ENTRY_ICON_SECONDARY,
1888 g_value_get_object (value));
1891 case PROP_STOCK_PRIMARY:
1892 gtk_entry_set_icon_from_stock (entry,
1893 GTK_ENTRY_ICON_PRIMARY,
1894 g_value_get_string (value));
1897 case PROP_STOCK_SECONDARY:
1898 gtk_entry_set_icon_from_stock (entry,
1899 GTK_ENTRY_ICON_SECONDARY,
1900 g_value_get_string (value));
1903 case PROP_ICON_NAME_PRIMARY:
1904 gtk_entry_set_icon_from_icon_name (entry,
1905 GTK_ENTRY_ICON_PRIMARY,
1906 g_value_get_string (value));
1909 case PROP_ICON_NAME_SECONDARY:
1910 gtk_entry_set_icon_from_icon_name (entry,
1911 GTK_ENTRY_ICON_SECONDARY,
1912 g_value_get_string (value));
1915 case PROP_GICON_PRIMARY:
1916 gtk_entry_set_icon_from_gicon (entry,
1917 GTK_ENTRY_ICON_PRIMARY,
1918 g_value_get_object (value));
1921 case PROP_GICON_SECONDARY:
1922 gtk_entry_set_icon_from_gicon (entry,
1923 GTK_ENTRY_ICON_SECONDARY,
1924 g_value_get_object (value));
1927 case PROP_ACTIVATABLE_PRIMARY:
1928 gtk_entry_set_icon_activatable (entry,
1929 GTK_ENTRY_ICON_PRIMARY,
1930 g_value_get_boolean (value));
1933 case PROP_ACTIVATABLE_SECONDARY:
1934 gtk_entry_set_icon_activatable (entry,
1935 GTK_ENTRY_ICON_SECONDARY,
1936 g_value_get_boolean (value));
1939 case PROP_SENSITIVE_PRIMARY:
1940 gtk_entry_set_icon_sensitive (entry,
1941 GTK_ENTRY_ICON_PRIMARY,
1942 g_value_get_boolean (value));
1945 case PROP_SENSITIVE_SECONDARY:
1946 gtk_entry_set_icon_sensitive (entry,
1947 GTK_ENTRY_ICON_SECONDARY,
1948 g_value_get_boolean (value));
1951 case PROP_TOOLTIP_TEXT_PRIMARY:
1952 gtk_entry_set_icon_tooltip_text (entry,
1953 GTK_ENTRY_ICON_PRIMARY,
1954 g_value_get_string (value));
1957 case PROP_TOOLTIP_TEXT_SECONDARY:
1958 gtk_entry_set_icon_tooltip_text (entry,
1959 GTK_ENTRY_ICON_SECONDARY,
1960 g_value_get_string (value));
1963 case PROP_TOOLTIP_MARKUP_PRIMARY:
1964 gtk_entry_set_icon_tooltip_markup (entry,
1965 GTK_ENTRY_ICON_PRIMARY,
1966 g_value_get_string (value));
1969 case PROP_TOOLTIP_MARKUP_SECONDARY:
1970 gtk_entry_set_icon_tooltip_markup (entry,
1971 GTK_ENTRY_ICON_SECONDARY,
1972 g_value_get_string (value));
1975 case PROP_IM_MODULE:
1976 g_free (priv->im_module);
1977 priv->im_module = g_value_dup_string (value);
1978 if (GTK_IS_IM_MULTICONTEXT (entry->im_context))
1979 gtk_im_multicontext_set_context_id (GTK_IM_MULTICONTEXT (entry->im_context), priv->im_module);
1982 case PROP_EDITING_CANCELED:
1983 entry->editing_canceled = g_value_get_boolean (value);
1986 case PROP_SCROLL_OFFSET:
1987 case PROP_CURSOR_POSITION:
1989 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1995 gtk_entry_get_property (GObject *object,
2000 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (object);
2001 GtkEntry *entry = GTK_ENTRY (object);
2006 g_value_set_object (value, gtk_entry_get_buffer (entry));
2009 case PROP_CURSOR_POSITION:
2010 g_value_set_int (value, entry->current_pos);
2013 case PROP_SELECTION_BOUND:
2014 g_value_set_int (value, entry->selection_bound);
2018 g_value_set_boolean (value, entry->editable);
2021 case PROP_MAX_LENGTH:
2022 g_value_set_int (value, gtk_entry_buffer_get_max_length (get_buffer (entry)));
2025 case PROP_VISIBILITY:
2026 g_value_set_boolean (value, entry->visible);
2029 case PROP_HAS_FRAME:
2030 g_value_set_boolean (value, entry->has_frame);
2033 case PROP_INNER_BORDER:
2034 g_value_set_boxed (value, gtk_entry_get_inner_border (entry));
2037 case PROP_INVISIBLE_CHAR:
2038 g_value_set_uint (value, entry->invisible_char);
2041 case PROP_ACTIVATES_DEFAULT:
2042 g_value_set_boolean (value, entry->activates_default);
2045 case PROP_WIDTH_CHARS:
2046 g_value_set_int (value, entry->width_chars);
2049 case PROP_SCROLL_OFFSET:
2050 g_value_set_int (value, entry->scroll_offset);
2054 g_value_set_string (value, gtk_entry_get_text (entry));
2058 g_value_set_float (value, gtk_entry_get_alignment (entry));
2061 case PROP_TRUNCATE_MULTILINE:
2062 g_value_set_boolean (value, entry->truncate_multiline);
2065 case PROP_SHADOW_TYPE:
2066 g_value_set_enum (value, priv->shadow_type);
2069 case PROP_OVERWRITE_MODE:
2070 g_value_set_boolean (value, entry->overwrite_mode);
2073 case PROP_TEXT_LENGTH:
2074 g_value_set_uint (value, gtk_entry_buffer_get_length (get_buffer (entry)));
2077 case PROP_INVISIBLE_CHAR_SET:
2078 g_value_set_boolean (value, priv->invisible_char_set);
2081 case PROP_IM_MODULE:
2082 g_value_set_string (value, priv->im_module);
2085 case PROP_CAPS_LOCK_WARNING:
2086 g_value_set_boolean (value, priv->caps_lock_warning);
2089 case PROP_PROGRESS_FRACTION:
2090 g_value_set_double (value, priv->progress_fraction);
2093 case PROP_PROGRESS_PULSE_STEP:
2094 g_value_set_double (value, priv->progress_pulse_fraction);
2097 case PROP_PIXBUF_PRIMARY:
2098 g_value_set_object (value,
2099 gtk_entry_get_icon_pixbuf (entry,
2100 GTK_ENTRY_ICON_PRIMARY));
2103 case PROP_PIXBUF_SECONDARY:
2104 g_value_set_object (value,
2105 gtk_entry_get_icon_pixbuf (entry,
2106 GTK_ENTRY_ICON_SECONDARY));
2109 case PROP_STOCK_PRIMARY:
2110 g_value_set_string (value,
2111 gtk_entry_get_icon_stock (entry,
2112 GTK_ENTRY_ICON_PRIMARY));
2115 case PROP_STOCK_SECONDARY:
2116 g_value_set_string (value,
2117 gtk_entry_get_icon_stock (entry,
2118 GTK_ENTRY_ICON_SECONDARY));
2121 case PROP_ICON_NAME_PRIMARY:
2122 g_value_set_string (value,
2123 gtk_entry_get_icon_name (entry,
2124 GTK_ENTRY_ICON_PRIMARY));
2127 case PROP_ICON_NAME_SECONDARY:
2128 g_value_set_string (value,
2129 gtk_entry_get_icon_name (entry,
2130 GTK_ENTRY_ICON_SECONDARY));
2133 case PROP_GICON_PRIMARY:
2134 g_value_set_object (value,
2135 gtk_entry_get_icon_gicon (entry,
2136 GTK_ENTRY_ICON_PRIMARY));
2139 case PROP_GICON_SECONDARY:
2140 g_value_set_object (value,
2141 gtk_entry_get_icon_gicon (entry,
2142 GTK_ENTRY_ICON_SECONDARY));
2145 case PROP_STORAGE_TYPE_PRIMARY:
2146 g_value_set_enum (value,
2147 gtk_entry_get_icon_storage_type (entry,
2148 GTK_ENTRY_ICON_PRIMARY));
2151 case PROP_STORAGE_TYPE_SECONDARY:
2152 g_value_set_enum (value,
2153 gtk_entry_get_icon_storage_type (entry,
2154 GTK_ENTRY_ICON_SECONDARY));
2157 case PROP_ACTIVATABLE_PRIMARY:
2158 g_value_set_boolean (value,
2159 gtk_entry_get_icon_activatable (entry, GTK_ENTRY_ICON_PRIMARY));
2162 case PROP_ACTIVATABLE_SECONDARY:
2163 g_value_set_boolean (value,
2164 gtk_entry_get_icon_activatable (entry, GTK_ENTRY_ICON_SECONDARY));
2167 case PROP_SENSITIVE_PRIMARY:
2168 g_value_set_boolean (value,
2169 gtk_entry_get_icon_sensitive (entry, GTK_ENTRY_ICON_PRIMARY));
2172 case PROP_SENSITIVE_SECONDARY:
2173 g_value_set_boolean (value,
2174 gtk_entry_get_icon_sensitive (entry, GTK_ENTRY_ICON_SECONDARY));
2177 case PROP_TOOLTIP_TEXT_PRIMARY:
2178 g_value_take_string (value,
2179 gtk_entry_get_icon_tooltip_text (entry, GTK_ENTRY_ICON_PRIMARY));
2182 case PROP_TOOLTIP_TEXT_SECONDARY:
2183 g_value_take_string (value,
2184 gtk_entry_get_icon_tooltip_text (entry, GTK_ENTRY_ICON_SECONDARY));
2187 case PROP_TOOLTIP_MARKUP_PRIMARY:
2188 g_value_take_string (value,
2189 gtk_entry_get_icon_tooltip_markup (entry, GTK_ENTRY_ICON_PRIMARY));
2192 case PROP_TOOLTIP_MARKUP_SECONDARY:
2193 g_value_take_string (value,
2194 gtk_entry_get_icon_tooltip_markup (entry, GTK_ENTRY_ICON_SECONDARY));
2197 case PROP_EDITING_CANCELED:
2198 g_value_set_boolean (value,
2199 entry->editing_canceled);
2203 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2209 find_invisible_char (GtkWidget *widget)
2211 PangoLayout *layout;
2212 PangoAttrList *attr_list;
2214 gunichar invisible_chars [] = {
2216 0x25cf, /* BLACK CIRCLE */
2217 0x2022, /* BULLET */
2218 0x2731, /* HEAVY ASTERISK */
2219 0x273a /* SIXTEEN POINTED ASTERISK */
2222 if (gtk_widget_get_style (widget))
2223 gtk_widget_style_get (widget,
2224 "invisible-char", &invisible_chars[0],
2227 layout = gtk_widget_create_pango_layout (widget, NULL);
2229 attr_list = pango_attr_list_new ();
2230 pango_attr_list_insert (attr_list, pango_attr_fallback_new (FALSE));
2232 pango_layout_set_attributes (layout, attr_list);
2233 pango_attr_list_unref (attr_list);
2235 for (i = (invisible_chars[0] != 0 ? 0 : 1); i < G_N_ELEMENTS (invisible_chars); i++)
2237 gchar text[7] = { 0, };
2240 len = g_unichar_to_utf8 (invisible_chars[i], text);
2241 pango_layout_set_text (layout, text, len);
2243 count = pango_layout_get_unknown_glyphs_count (layout);
2247 g_object_unref (layout);
2248 return invisible_chars[i];
2252 g_object_unref (layout);
2258 gtk_entry_init (GtkEntry *entry)
2260 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2262 gtk_widget_set_can_focus (GTK_WIDGET (entry), TRUE);
2264 entry->editable = TRUE;
2265 entry->visible = TRUE;
2266 entry->invisible_char = find_invisible_char (GTK_WIDGET (entry));
2267 entry->dnd_position = -1;
2268 entry->width_chars = -1;
2269 entry->is_cell_renderer = FALSE;
2270 entry->editing_canceled = FALSE;
2271 entry->has_frame = TRUE;
2272 entry->truncate_multiline = FALSE;
2273 priv->shadow_type = GTK_SHADOW_IN;
2275 priv->caps_lock_warning = TRUE;
2276 priv->caps_lock_warning_shown = FALSE;
2277 priv->progress_fraction = 0.0;
2278 priv->progress_pulse_fraction = 0.1;
2280 gtk_drag_dest_set (GTK_WIDGET (entry),
2281 GTK_DEST_DEFAULT_HIGHLIGHT,
2283 GDK_ACTION_COPY | GDK_ACTION_MOVE);
2284 gtk_drag_dest_add_text_targets (GTK_WIDGET (entry));
2286 /* This object is completely private. No external entity can gain a reference
2287 * to it; so we create it here and destroy it in finalize().
2289 entry->im_context = gtk_im_multicontext_new ();
2291 g_signal_connect (entry->im_context, "commit",
2292 G_CALLBACK (gtk_entry_commit_cb), entry);
2293 g_signal_connect (entry->im_context, "preedit-changed",
2294 G_CALLBACK (gtk_entry_preedit_changed_cb), entry);
2295 g_signal_connect (entry->im_context, "retrieve-surrounding",
2296 G_CALLBACK (gtk_entry_retrieve_surrounding_cb), entry);
2297 g_signal_connect (entry->im_context, "delete-surrounding",
2298 G_CALLBACK (gtk_entry_delete_surrounding_cb), entry);
2303 get_icon_width (GtkEntry *entry,
2304 GtkEntryIconPosition icon_pos)
2306 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2307 EntryIconInfo *icon_info = priv->icons[icon_pos];
2309 GtkSettings *settings;
2310 gint menu_icon_width;
2312 if (!icon_info || icon_info->pixbuf == NULL)
2315 screen = gtk_widget_get_screen (GTK_WIDGET (entry));
2316 settings = gtk_settings_get_for_screen (screen);
2318 gtk_icon_size_lookup_for_settings (settings, GTK_ICON_SIZE_MENU,
2319 &menu_icon_width, NULL);
2321 return MAX (gdk_pixbuf_get_width (icon_info->pixbuf), menu_icon_width);
2325 get_icon_allocations (GtkEntry *entry,
2326 GtkAllocation *primary,
2327 GtkAllocation *secondary)
2330 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2331 gint x, y, width, height;
2333 get_text_area_size (entry, &x, &y, &width, &height);
2335 if (gtk_widget_has_focus (GTK_WIDGET (entry)) && !priv->interior_focus)
2336 y += priv->focus_width;
2339 primary->height = height;
2340 primary->width = get_icon_width (entry, GTK_ENTRY_ICON_PRIMARY);
2341 if (primary->width > 0)
2342 primary->width += 2 * priv->icon_margin;
2345 secondary->height = height;
2346 secondary->width = get_icon_width (entry, GTK_ENTRY_ICON_SECONDARY);
2347 if (secondary->width > 0)
2348 secondary->width += 2 * priv->icon_margin;
2350 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
2352 primary->x = x + width - primary->width;
2358 secondary->x = x + width - secondary->width;
2364 begin_change (GtkEntry *entry)
2366 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2368 priv->change_count++;
2372 end_change (GtkEntry *entry)
2374 GtkEditable *editable = GTK_EDITABLE (entry);
2375 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2377 g_return_if_fail (priv->change_count > 0);
2379 priv->change_count--;
2381 if (priv->change_count == 0)
2383 if (priv->real_changed)
2385 g_signal_emit_by_name (editable, "changed");
2386 priv->real_changed = FALSE;
2392 emit_changed (GtkEntry *entry)
2394 GtkEditable *editable = GTK_EDITABLE (entry);
2395 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2397 if (priv->change_count == 0)
2398 g_signal_emit_by_name (editable, "changed");
2400 priv->real_changed = TRUE;
2404 gtk_entry_destroy (GtkWidget *widget)
2406 GtkEntry *entry = GTK_ENTRY (widget);
2408 entry->current_pos = entry->selection_bound = 0;
2409 _gtk_entry_reset_im_context (entry);
2410 gtk_entry_reset_layout (entry);
2412 if (entry->blink_timeout)
2414 g_source_remove (entry->blink_timeout);
2415 entry->blink_timeout = 0;
2418 if (entry->recompute_idle)
2420 g_source_remove (entry->recompute_idle);
2421 entry->recompute_idle = 0;
2424 GTK_WIDGET_CLASS (gtk_entry_parent_class)->destroy (widget);
2428 gtk_entry_dispose (GObject *object)
2430 GtkEntry *entry = GTK_ENTRY (object);
2431 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2433 gtk_entry_set_icon_from_pixbuf (entry, GTK_ENTRY_ICON_PRIMARY, NULL);
2434 gtk_entry_set_icon_tooltip_markup (entry, GTK_ENTRY_ICON_PRIMARY, NULL);
2435 gtk_entry_set_icon_from_pixbuf (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
2436 gtk_entry_set_icon_tooltip_markup (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
2440 buffer_disconnect_signals (entry);
2441 g_object_unref (priv->buffer);
2442 priv->buffer = NULL;
2445 G_OBJECT_CLASS (gtk_entry_parent_class)->dispose (object);
2449 gtk_entry_finalize (GObject *object)
2451 GtkEntry *entry = GTK_ENTRY (object);
2452 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2453 EntryIconInfo *icon_info = NULL;
2456 for (i = 0; i < MAX_ICONS; i++)
2458 if ((icon_info = priv->icons[i]) != NULL)
2460 if (icon_info->target_list != NULL)
2462 gtk_target_list_unref (icon_info->target_list);
2463 icon_info->target_list = NULL;
2466 g_slice_free (EntryIconInfo, icon_info);
2467 priv->icons[i] = NULL;
2471 gtk_entry_set_completion (entry, NULL);
2473 if (entry->cached_layout)
2474 g_object_unref (entry->cached_layout);
2476 g_object_unref (entry->im_context);
2478 if (entry->blink_timeout)
2479 g_source_remove (entry->blink_timeout);
2481 if (entry->recompute_idle)
2482 g_source_remove (entry->recompute_idle);
2484 g_free (priv->im_module);
2486 G_OBJECT_CLASS (gtk_entry_parent_class)->finalize (object);
2490 gtk_entry_get_display_mode (GtkEntry *entry)
2492 GtkEntryPrivate *priv;
2494 return DISPLAY_NORMAL;
2495 priv = GTK_ENTRY_GET_PRIVATE (entry);
2496 if (entry->invisible_char == 0 && priv->invisible_char_set)
2497 return DISPLAY_BLANK;
2498 return DISPLAY_INVISIBLE;
2502 gtk_entry_get_display_text (GtkEntry *entry,
2506 GtkEntryPasswordHint *password_hint;
2507 GtkEntryPrivate *priv;
2508 gunichar invisible_char;
2518 priv = GTK_ENTRY_GET_PRIVATE (entry);
2519 text = gtk_entry_buffer_get_text (get_buffer (entry));
2520 length = gtk_entry_buffer_get_length (get_buffer (entry));
2524 if (start_pos > length)
2527 if (end_pos <= start_pos)
2528 return g_strdup ("");
2529 else if (entry->visible)
2531 start = g_utf8_offset_to_pointer (text, start_pos);
2532 end = g_utf8_offset_to_pointer (start, end_pos - start_pos);
2533 return g_strndup (start, end - start);
2537 str = g_string_sized_new (length * 2);
2539 /* Figure out what our invisible char is and encode it */
2540 if (!entry->invisible_char)
2541 invisible_char = priv->invisible_char_set ? ' ' : '*';
2543 invisible_char = entry->invisible_char;
2544 char_len = g_unichar_to_utf8 (invisible_char, char_str);
2547 * Add hidden characters for each character in the text
2548 * buffer. If there is a password hint, then keep that
2549 * character visible.
2552 password_hint = g_object_get_qdata (G_OBJECT (entry), quark_password_hint);
2553 for (i = start_pos; i < end_pos; ++i)
2555 if (password_hint && i == password_hint->position)
2557 start = g_utf8_offset_to_pointer (text, i);
2558 g_string_append_len (str, start, g_utf8_next_char (start) - start);
2562 g_string_append_len (str, char_str, char_len);
2566 return g_string_free (str, FALSE);
2572 update_cursors (GtkWidget *widget)
2574 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2575 EntryIconInfo *icon_info = NULL;
2576 GdkDisplay *display;
2580 for (i = 0; i < MAX_ICONS; i++)
2582 if ((icon_info = priv->icons[i]) != NULL)
2584 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
2585 gdk_window_show_unraised (icon_info->window);
2587 /* The icon windows are not children of the visible entry window,
2588 * thus we can't just inherit the xterm cursor. Slight complication
2589 * here is that for the entry, insensitive => arrow cursor, but for
2590 * an icon in a sensitive entry, insensitive => xterm cursor.
2592 if (gtk_widget_is_sensitive (widget) &&
2593 (icon_info->insensitive ||
2594 (icon_info->nonactivatable && icon_info->target_list == NULL)))
2596 display = gtk_widget_get_display (widget);
2597 cursor = gdk_cursor_new_for_display (display, GDK_XTERM);
2598 gdk_window_set_cursor (icon_info->window, cursor);
2599 gdk_cursor_unref (cursor);
2603 gdk_window_set_cursor (icon_info->window, NULL);
2610 realize_icon_info (GtkWidget *widget,
2611 GtkEntryIconPosition icon_pos)
2613 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2614 EntryIconInfo *icon_info = priv->icons[icon_pos];
2615 GdkWindowAttr attributes;
2616 gint attributes_mask;
2618 g_return_if_fail (icon_info != NULL);
2622 attributes.width = 1;
2623 attributes.height = 1;
2624 attributes.window_type = GDK_WINDOW_CHILD;
2625 attributes.wclass = GDK_INPUT_OUTPUT;
2626 attributes.visual = gtk_widget_get_visual (widget);
2627 attributes.event_mask = gtk_widget_get_events (widget);
2628 attributes.event_mask |= (GDK_EXPOSURE_MASK |
2629 GDK_BUTTON_PRESS_MASK |
2630 GDK_BUTTON_RELEASE_MASK |
2631 GDK_BUTTON1_MOTION_MASK |
2632 GDK_BUTTON3_MOTION_MASK |
2633 GDK_POINTER_MOTION_HINT_MASK |
2634 GDK_POINTER_MOTION_MASK |
2635 GDK_ENTER_NOTIFY_MASK |
2636 GDK_LEAVE_NOTIFY_MASK);
2637 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL;
2639 icon_info->window = gdk_window_new (gtk_widget_get_window (widget),
2642 gdk_window_set_user_data (icon_info->window, widget);
2643 gdk_window_set_background (icon_info->window,
2644 >k_widget_get_style (widget)->base[gtk_widget_get_state (widget)]);
2646 gtk_widget_queue_resize (widget);
2649 static EntryIconInfo*
2650 construct_icon_info (GtkWidget *widget,
2651 GtkEntryIconPosition icon_pos)
2653 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2654 EntryIconInfo *icon_info;
2656 g_return_val_if_fail (priv->icons[icon_pos] == NULL, NULL);
2658 icon_info = g_slice_new0 (EntryIconInfo);
2659 priv->icons[icon_pos] = icon_info;
2661 if (gtk_widget_get_realized (widget))
2662 realize_icon_info (widget, icon_pos);
2668 gtk_entry_map (GtkWidget *widget)
2670 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2671 EntryIconInfo *icon_info = NULL;
2674 GTK_WIDGET_CLASS (gtk_entry_parent_class)->map (widget);
2676 for (i = 0; i < MAX_ICONS; i++)
2678 if ((icon_info = priv->icons[i]) != NULL)
2680 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
2681 gdk_window_show (icon_info->window);
2685 update_cursors (widget);
2689 gtk_entry_unmap (GtkWidget *widget)
2691 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2692 EntryIconInfo *icon_info = NULL;
2695 for (i = 0; i < MAX_ICONS; i++)
2697 if ((icon_info = priv->icons[i]) != NULL)
2699 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
2700 gdk_window_hide (icon_info->window);
2704 GTK_WIDGET_CLASS (gtk_entry_parent_class)->unmap (widget);
2708 gtk_entry_realize (GtkWidget *widget)
2711 GtkEntryPrivate *priv;
2714 EntryIconInfo *icon_info;
2716 GdkWindowAttr attributes;
2717 gint attributes_mask;
2720 gtk_widget_set_realized (widget, TRUE);
2721 entry = GTK_ENTRY (widget);
2722 priv = GTK_ENTRY_GET_PRIVATE (entry);
2724 attributes.window_type = GDK_WINDOW_CHILD;
2726 get_widget_window_size (entry, &attributes.x, &attributes.y, &attributes.width, &attributes.height);
2728 attributes.wclass = GDK_INPUT_OUTPUT;
2729 attributes.visual = gtk_widget_get_visual (widget);
2730 attributes.event_mask = gtk_widget_get_events (widget);
2731 attributes.event_mask |= (GDK_EXPOSURE_MASK |
2732 GDK_BUTTON_PRESS_MASK |
2733 GDK_BUTTON_RELEASE_MASK |
2734 GDK_BUTTON1_MOTION_MASK |
2735 GDK_BUTTON3_MOTION_MASK |
2736 GDK_POINTER_MOTION_HINT_MASK |
2737 GDK_POINTER_MOTION_MASK |
2738 GDK_ENTER_NOTIFY_MASK |
2739 GDK_LEAVE_NOTIFY_MASK);
2740 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL;
2742 window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, attributes_mask);
2743 gtk_widget_set_window (widget, window);
2744 gdk_window_set_user_data (window, entry);
2746 get_text_area_size (entry, &attributes.x, &attributes.y, &attributes.width, &attributes.height);
2748 if (gtk_widget_is_sensitive (widget))
2750 attributes.cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
2751 attributes_mask |= GDK_WA_CURSOR;
2754 entry->text_area = gdk_window_new (window, &attributes, attributes_mask);
2756 gdk_window_set_user_data (entry->text_area, entry);
2758 if (attributes_mask & GDK_WA_CURSOR)
2759 gdk_cursor_unref (attributes.cursor);
2761 gtk_widget_style_attach (widget);
2763 style = gtk_widget_get_style (widget);
2764 state = gtk_widget_get_state (widget);
2765 gdk_window_set_background (window, &style->base[state]);
2766 gdk_window_set_background (entry->text_area, &style->base[state]);
2768 gdk_window_show (entry->text_area);
2770 gtk_im_context_set_client_window (entry->im_context, entry->text_area);
2772 gtk_entry_adjust_scroll (entry);
2773 gtk_entry_update_primary_selection (entry);
2776 /* If the icon positions are already setup, create their windows.
2777 * Otherwise if they don't exist yet, then construct_icon_info()
2778 * will create the windows once the widget is already realized.
2780 for (i = 0; i < MAX_ICONS; i++)
2782 if ((icon_info = priv->icons[i]) != NULL)
2784 if (icon_info->window == NULL)
2785 realize_icon_info (widget, i);
2791 gtk_entry_unrealize (GtkWidget *widget)
2793 GtkEntry *entry = GTK_ENTRY (widget);
2794 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2795 GtkClipboard *clipboard;
2796 EntryIconInfo *icon_info;
2799 gtk_entry_reset_layout (entry);
2801 gtk_im_context_set_client_window (entry->im_context, NULL);
2803 clipboard = gtk_widget_get_clipboard (widget, GDK_SELECTION_PRIMARY);
2804 if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (entry))
2805 gtk_clipboard_clear (clipboard);
2807 if (entry->text_area)
2809 gdk_window_set_user_data (entry->text_area, NULL);
2810 gdk_window_destroy (entry->text_area);
2811 entry->text_area = NULL;
2814 if (entry->popup_menu)
2816 gtk_widget_destroy (entry->popup_menu);
2817 entry->popup_menu = NULL;
2820 GTK_WIDGET_CLASS (gtk_entry_parent_class)->unrealize (widget);
2822 for (i = 0; i < MAX_ICONS; i++)
2824 if ((icon_info = priv->icons[i]) != NULL)
2826 if (icon_info->window != NULL)
2828 gdk_window_destroy (icon_info->window);
2829 icon_info->window = NULL;
2836 _gtk_entry_get_borders (GtkEntry *entry,
2840 GtkWidget *widget = GTK_WIDGET (entry);
2841 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2844 if (entry->has_frame)
2846 style = gtk_widget_get_style (widget);
2848 *xborder = style->xthickness;
2849 *yborder = style->ythickness;
2857 if (!priv->interior_focus)
2859 *xborder += priv->focus_width;
2860 *yborder += priv->focus_width;
2865 gtk_entry_size_request (GtkWidget *widget,
2866 GtkRequisition *requisition)
2868 GtkEntry *entry = GTK_ENTRY (widget);
2869 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2870 PangoFontMetrics *metrics;
2871 gint xborder, yborder;
2872 GtkBorder inner_border;
2873 PangoContext *context;
2874 int icon_widths = 0;
2877 gtk_widget_ensure_style (widget);
2878 context = gtk_widget_get_pango_context (widget);
2879 metrics = pango_context_get_metrics (context,
2880 gtk_widget_get_style (widget)->font_desc,
2881 pango_context_get_language (context));
2883 entry->ascent = pango_font_metrics_get_ascent (metrics);
2884 entry->descent = pango_font_metrics_get_descent (metrics);
2886 _gtk_entry_get_borders (entry, &xborder, &yborder);
2887 _gtk_entry_effective_inner_border (entry, &inner_border);
2889 if (entry->width_chars < 0)
2890 requisition->width = MIN_ENTRY_WIDTH + xborder * 2 + inner_border.left + inner_border.right;
2893 gint char_width = pango_font_metrics_get_approximate_char_width (metrics);
2894 gint digit_width = pango_font_metrics_get_approximate_digit_width (metrics);
2895 gint char_pixels = (MAX (char_width, digit_width) + PANGO_SCALE - 1) / PANGO_SCALE;
2897 requisition->width = char_pixels * entry->width_chars + xborder * 2 + inner_border.left + inner_border.right;
2900 requisition->height = PANGO_PIXELS (entry->ascent + entry->descent) + yborder * 2 + inner_border.top + inner_border.bottom;
2902 for (i = 0; i < MAX_ICONS; i++)
2904 icon_width = get_icon_width (entry, i);
2906 icon_widths += icon_width + 2 * priv->icon_margin;
2909 if (icon_widths > requisition->width)
2910 requisition->width += icon_widths;
2912 pango_font_metrics_unref (metrics);
2916 place_windows (GtkEntry *entry)
2918 GtkWidget *widget = GTK_WIDGET (entry);
2919 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2920 gint x, y, width, height;
2921 GtkAllocation primary;
2922 GtkAllocation secondary;
2923 EntryIconInfo *icon_info = NULL;
2925 get_text_area_size (entry, &x, &y, &width, &height);
2926 get_icon_allocations (entry, &primary, &secondary);
2928 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
2929 y += priv->focus_width;
2931 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
2932 x += secondary.width;
2935 width -= primary.width + secondary.width;
2937 if ((icon_info = priv->icons[GTK_ENTRY_ICON_PRIMARY]) != NULL)
2938 gdk_window_move_resize (icon_info->window,
2939 primary.x, primary.y,
2940 primary.width, primary.height);
2942 if ((icon_info = priv->icons[GTK_ENTRY_ICON_SECONDARY]) != NULL)
2943 gdk_window_move_resize (icon_info->window,
2944 secondary.x, secondary.y,
2945 secondary.width, secondary.height);
2947 gdk_window_move_resize (entry->text_area, x, y, width, height);
2951 gtk_entry_get_text_area_size (GtkEntry *entry,
2957 GtkWidget *widget = GTK_WIDGET (entry);
2958 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2959 GtkAllocation allocation;
2960 GtkRequisition requisition;
2962 gint xborder, yborder;
2964 gtk_widget_get_preferred_size (widget, &requisition, NULL);
2965 gtk_widget_get_allocation (widget, &allocation);
2966 _gtk_entry_get_borders (entry, &xborder, &yborder);
2968 if (gtk_widget_get_realized (widget))
2969 frame_height = gdk_window_get_height (gtk_widget_get_window (widget));
2971 frame_height = requisition.height;
2973 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
2974 frame_height -= 2 * priv->focus_width;
2980 *y = frame_height / 2 - (requisition.height - yborder * 2) / 2;
2983 *width = allocation.width - xborder * 2;
2986 *height = requisition.height - yborder * 2;
2990 get_text_area_size (GtkEntry *entry,
2996 GtkEntryClass *class;
2998 g_return_if_fail (GTK_IS_ENTRY (entry));
3000 class = GTK_ENTRY_GET_CLASS (entry);
3002 if (class->get_text_area_size)
3003 class->get_text_area_size (entry, x, y, width, height);
3008 get_widget_window_size (GtkEntry *entry,
3014 GtkAllocation allocation;
3015 GtkRequisition requisition;
3016 GtkWidget *widget = GTK_WIDGET (entry);
3018 gtk_widget_get_preferred_size (widget, &requisition, NULL);
3019 gtk_widget_get_allocation (widget, &allocation);
3026 if (entry->is_cell_renderer)
3029 *y = allocation.y + (allocation.height - requisition.height) / 2;
3033 *width = allocation.width;
3037 if (entry->is_cell_renderer)
3038 *height = allocation.height;
3040 *height = requisition.height;
3045 _gtk_entry_effective_inner_border (GtkEntry *entry,
3048 GtkBorder *tmp_border;
3050 tmp_border = g_object_get_qdata (G_OBJECT (entry), quark_inner_border);
3054 *border = *tmp_border;
3058 gtk_widget_style_get (GTK_WIDGET (entry), "inner-border", &tmp_border, NULL);
3062 *border = *tmp_border;
3063 gtk_border_free (tmp_border);
3067 *border = default_inner_border;
3071 gtk_entry_size_allocate (GtkWidget *widget,
3072 GtkAllocation *allocation)
3074 GtkEntry *entry = GTK_ENTRY (widget);
3076 gtk_widget_set_allocation (widget, allocation);
3078 if (gtk_widget_get_realized (widget))
3080 gint x, y, width, height;
3081 GtkEntryCompletion* completion;
3083 get_widget_window_size (entry, &x, &y, &width, &height);
3084 gdk_window_move_resize (gtk_widget_get_window (widget),
3085 x, y, width, height);
3087 place_windows (entry);
3088 gtk_entry_recompute (entry);
3090 completion = gtk_entry_get_completion (entry);
3091 if (completion && gtk_widget_get_mapped (completion->priv->popup_window))
3092 _gtk_entry_completion_resize_popup (completion);
3096 /* Kudos to the gnome-panel guys. */
3098 colorshift_pixbuf (GdkPixbuf *dest,
3103 gint width, height, has_alpha, src_rowstride, dest_rowstride;
3104 guchar *target_pixels;
3105 guchar *original_pixels;
3111 has_alpha = gdk_pixbuf_get_has_alpha (src);
3112 width = gdk_pixbuf_get_width (src);
3113 height = gdk_pixbuf_get_height (src);
3114 src_rowstride = gdk_pixbuf_get_rowstride (src);
3115 dest_rowstride = gdk_pixbuf_get_rowstride (dest);
3116 original_pixels = gdk_pixbuf_get_pixels (src);
3117 target_pixels = gdk_pixbuf_get_pixels (dest);
3119 for (i = 0; i < height; i++)
3121 pix_dest = target_pixels + i * dest_rowstride;
3122 pix_src = original_pixels + i * src_rowstride;
3124 for (j = 0; j < width; j++)
3131 *(pix_dest++) = CLAMP (val, 0, 255);
3134 *(pix_dest++) = CLAMP (val, 0, 255);
3137 *(pix_dest++) = CLAMP (val, 0, 255);
3140 *(pix_dest++) = *(pix_src++);
3146 should_prelight (GtkEntry *entry,
3147 GtkEntryIconPosition icon_pos)
3149 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3150 EntryIconInfo *icon_info = priv->icons[icon_pos];
3156 if (icon_info->nonactivatable && icon_info->target_list == NULL)
3159 if (icon_info->pressed)
3162 gtk_widget_style_get (GTK_WIDGET (entry),
3163 "icon-prelight", &prelight,
3170 draw_icon (GtkWidget *widget,
3172 GtkEntryIconPosition icon_pos)
3174 GtkEntry *entry = GTK_ENTRY (widget);
3175 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3176 EntryIconInfo *icon_info = priv->icons[icon_pos];
3178 gint x, y, width, height;
3183 gtk_entry_ensure_pixbuf (entry, icon_pos);
3185 if (icon_info->pixbuf == NULL)
3188 width = gdk_window_get_width (icon_info->window);
3189 height = gdk_window_get_height (icon_info->window);
3191 /* size_allocate hasn't been called yet. These are the default values.
3193 if (width == 1 || height == 1)
3196 pixbuf = icon_info->pixbuf;
3197 g_object_ref (pixbuf);
3199 if (gdk_pixbuf_get_height (pixbuf) > height)
3201 GdkPixbuf *temp_pixbuf;
3204 scale = height - 2 * priv->icon_margin;
3205 temp_pixbuf = gdk_pixbuf_scale_simple (pixbuf, scale, scale,
3206 GDK_INTERP_BILINEAR);
3207 g_object_unref (pixbuf);
3208 pixbuf = temp_pixbuf;
3211 x = (width - gdk_pixbuf_get_width (pixbuf)) / 2;
3212 y = (height - gdk_pixbuf_get_height (pixbuf)) / 2;
3214 if (!gtk_widget_is_sensitive (widget) ||
3215 icon_info->insensitive)
3217 GdkPixbuf *temp_pixbuf;
3219 temp_pixbuf = gdk_pixbuf_copy (pixbuf);
3220 gdk_pixbuf_saturate_and_pixelate (pixbuf,
3224 g_object_unref (pixbuf);
3225 pixbuf = temp_pixbuf;
3227 else if (icon_info->prelight)
3229 GdkPixbuf *temp_pixbuf;
3231 temp_pixbuf = gdk_pixbuf_copy (pixbuf);
3232 colorshift_pixbuf (temp_pixbuf, pixbuf, 30);
3233 g_object_unref (pixbuf);
3234 pixbuf = temp_pixbuf;
3237 gdk_cairo_set_source_pixbuf (cr, pixbuf, x, y);
3240 g_object_unref (pixbuf);
3245 gtk_entry_draw_frame (GtkWidget *widget,
3248 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
3251 gint x = 0, y = 0, width, height;
3254 window = gtk_widget_get_window (widget);
3256 width = gdk_window_get_width (window);
3257 height = gdk_window_get_height (window);
3259 /* Fix a problem with some themes which assume that entry->text_area's
3260 * width equals widget->window's width
3261 * http://bugzilla.gnome.org/show_bug.cgi?id=466000 */
3262 if (GTK_IS_SPIN_BUTTON (widget))
3264 gint xborder, yborder;
3266 gtk_entry_get_text_area_size (GTK_ENTRY (widget), &x, NULL, &width, NULL);
3267 _gtk_entry_get_borders (GTK_ENTRY (widget), &xborder, &yborder);
3270 width += xborder * 2;
3273 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3275 x += priv->focus_width;
3276 y += priv->focus_width;
3277 width -= 2 * priv->focus_width;
3278 height -= 2 * priv->focus_width;
3281 style = gtk_widget_get_style (widget);
3282 state = gtk_widget_has_focus (widget) ?
3283 GTK_STATE_ACTIVE : gtk_widget_get_state (widget);
3285 gtk_paint_shadow (style, cr,
3286 state, priv->shadow_type,
3287 widget, "entry", x, y, width, height);
3290 gtk_entry_draw_progress (widget, cr, window);
3292 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3294 x -= priv->focus_width;
3295 y -= priv->focus_width;
3296 width += 2 * priv->focus_width;
3297 height += 2 * priv->focus_width;
3299 gtk_paint_focus (style, cr,
3300 gtk_widget_get_state (widget),
3302 0, 0, width, height);
3307 gtk_entry_get_progress_border (GtkWidget *widget,
3308 GtkBorder *progress_border)
3310 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 style = gtk_widget_get_style (widget);
3323 progress_border->left = style->xthickness;
3324 progress_border->right = style->xthickness;
3325 progress_border->top = style->ythickness;
3326 progress_border->bottom = style->ythickness;
3331 get_progress_area (GtkWidget *widget,
3337 GtkEntryPrivate *private = GTK_ENTRY_GET_PRIVATE (widget);
3338 GtkEntry *entry = GTK_ENTRY (widget);
3339 GtkBorder progress_border;
3341 gtk_entry_get_progress_border (widget, &progress_border);
3343 *x = progress_border.left;
3344 *y = progress_border.top;
3346 *width = gdk_window_get_width (gtk_widget_get_window (widget))
3347 - progress_border.left - progress_border.right;
3348 *height = gdk_window_get_height (gtk_widget_get_window (widget))
3349 - progress_border.top - progress_border.bottom;
3351 if (gtk_widget_has_focus (widget) && !private->interior_focus)
3353 *x += private->focus_width;
3354 *y += private->focus_width;
3355 *width -= 2 * private->focus_width;
3356 *height -= 2 * private->focus_width;
3359 if (private->progress_pulse_mode)
3361 gdouble value = private->progress_pulse_current;
3363 *x += (gint) floor(value * (*width));
3364 *width = (gint) ceil(private->progress_pulse_fraction * (*width));
3366 else if (private->progress_fraction > 0)
3368 gdouble value = private->progress_fraction;
3370 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
3374 bar_width = floor(value * (*width) + 0.5);
3375 *x += *width - bar_width;
3380 *width = (gint) floor(value * (*width) + 0.5);
3391 gtk_entry_draw_progress (GtkWidget *widget,
3395 gint x, y, width, height;
3398 get_progress_area (widget, &x, &y, &width, &height);
3400 if ((width <= 0) || (height <= 0))
3403 if (window != gtk_widget_get_window (widget))
3407 gdk_window_get_position (window, &pos_x, &pos_y);
3413 state = GTK_STATE_SELECTED;
3414 if (!gtk_widget_get_sensitive (widget))
3415 state = GTK_STATE_INSENSITIVE;
3417 gtk_paint_box (gtk_widget_get_style (widget), cr,
3418 state, GTK_SHADOW_OUT,
3419 widget, "entry-progress",
3425 gtk_entry_draw (GtkWidget *widget,
3428 GtkEntry *entry = GTK_ENTRY (widget);
3431 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3434 style = gtk_widget_get_style (widget);
3436 state = gtk_widget_has_focus (widget) ?
3437 GTK_STATE_ACTIVE : gtk_widget_get_state (widget);
3439 if (gtk_cairo_should_draw_window (cr, gtk_widget_get_window (widget)))
3440 gtk_entry_draw_frame (widget, cr);
3442 if (gtk_cairo_should_draw_window (cr, entry->text_area))
3446 gtk_cairo_transform_to_window (cr, widget, entry->text_area);
3448 gtk_paint_flat_box (style, cr,
3449 state, GTK_SHADOW_NONE,
3452 gdk_window_get_width (entry->text_area),
3453 gdk_window_get_height (entry->text_area));
3455 gtk_entry_draw_progress (widget, cr, entry->text_area);
3457 if (entry->dnd_position != -1)
3458 gtk_entry_draw_cursor (GTK_ENTRY (widget), cr, CURSOR_DND);
3460 gtk_entry_draw_text (GTK_ENTRY (widget), cr);
3462 /* When no text is being displayed at all, don't show the cursor */
3463 if (gtk_entry_get_display_mode (entry) != DISPLAY_BLANK &&
3464 gtk_widget_has_focus (widget) &&
3465 entry->selection_bound == entry->current_pos && entry->cursor_visible)
3466 gtk_entry_draw_cursor (GTK_ENTRY (widget), cr, CURSOR_STANDARD);
3471 for (i = 0; i < MAX_ICONS; i++)
3473 EntryIconInfo *icon_info = priv->icons[i];
3475 if (icon_info != NULL && gtk_cairo_should_draw_window (cr, icon_info->window))
3479 gtk_cairo_transform_to_window (cr, widget, icon_info->window);
3481 gtk_paint_flat_box (style, cr,
3482 state, GTK_SHADOW_NONE,
3485 gdk_window_get_width (icon_info->window),
3486 gdk_window_get_height (icon_info->window));
3488 gtk_entry_draw_progress (widget, cr, icon_info->window);
3489 draw_icon (widget, cr, i);
3501 gtk_entry_enter_notify (GtkWidget *widget,
3502 GdkEventCrossing *event)
3504 GtkEntry *entry = GTK_ENTRY (widget);
3505 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3508 for (i = 0; i < MAX_ICONS; i++)
3510 EntryIconInfo *icon_info = priv->icons[i];
3512 if (icon_info != NULL && event->window == icon_info->window)
3514 if (should_prelight (entry, i))
3516 icon_info->prelight = TRUE;
3517 gtk_widget_queue_draw (widget);
3528 gtk_entry_leave_notify (GtkWidget *widget,
3529 GdkEventCrossing *event)
3531 GtkEntry *entry = GTK_ENTRY (widget);
3532 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3535 for (i = 0; i < MAX_ICONS; i++)
3537 EntryIconInfo *icon_info = priv->icons[i];
3539 if (icon_info != NULL && event->window == icon_info->window)
3541 /* a grab means that we may never see the button release */
3542 if (event->mode == GDK_CROSSING_GRAB || event->mode == GDK_CROSSING_GTK_GRAB)
3543 icon_info->pressed = FALSE;
3545 if (should_prelight (entry, i))
3547 icon_info->prelight = FALSE;
3548 gtk_widget_queue_draw (widget);
3559 gtk_entry_get_pixel_ranges (GtkEntry *entry,
3563 gint start_char, end_char;
3565 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start_char, &end_char))
3567 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
3568 PangoLayoutLine *line = pango_layout_get_lines_readonly (layout)->data;
3569 const char *text = pango_layout_get_text (layout);
3570 gint start_index = g_utf8_offset_to_pointer (text, start_char) - text;
3571 gint end_index = g_utf8_offset_to_pointer (text, end_char) - text;
3572 gint real_n_ranges, i;
3574 pango_layout_line_get_x_ranges (line, start_index, end_index, ranges, &real_n_ranges);
3580 for (i = 0; i < real_n_ranges; ++i)
3582 r[2 * i + 1] = (r[2 * i + 1] - r[2 * i]) / PANGO_SCALE;
3583 r[2 * i] = r[2 * i] / PANGO_SCALE;
3588 *n_ranges = real_n_ranges;
3600 in_selection (GtkEntry *entry,
3605 gint retval = FALSE;
3607 gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
3609 for (i = 0; i < n_ranges; ++i)
3611 if (x >= ranges[2 * i] && x < ranges[2 * i] + ranges[2 * i + 1])
3623 gtk_entry_button_press (GtkWidget *widget,
3624 GdkEventButton *event)
3626 GtkEntry *entry = GTK_ENTRY (widget);
3627 GtkEditable *editable = GTK_EDITABLE (widget);
3628 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3629 EntryIconInfo *icon_info = NULL;
3631 gint sel_start, sel_end;
3634 for (i = 0; i < MAX_ICONS; i++)
3636 icon_info = priv->icons[i];
3638 if (!icon_info || icon_info->insensitive)
3641 if (event->window == icon_info->window)
3643 if (should_prelight (entry, i))
3645 icon_info->prelight = FALSE;
3646 gtk_widget_queue_draw (widget);
3649 priv->start_x = event->x;
3650 priv->start_y = event->y;
3651 icon_info->pressed = TRUE;
3653 if (!icon_info->nonactivatable)
3654 g_signal_emit (entry, signals[ICON_PRESS], 0, i, event);
3660 if (event->window != entry->text_area ||
3661 (entry->button && event->button != entry->button))
3664 gtk_entry_reset_blink_time (entry);
3666 entry->button = event->button;
3668 if (!gtk_widget_has_focus (widget))
3670 entry->in_click = TRUE;
3671 gtk_widget_grab_focus (widget);
3672 entry->in_click = FALSE;
3675 tmp_pos = gtk_entry_find_position (entry, event->x + entry->scroll_offset);
3677 if (event->button == 1)
3679 gboolean have_selection = gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end);
3681 entry->select_words = FALSE;
3682 entry->select_lines = FALSE;
3684 if (event->state & GDK_SHIFT_MASK)
3686 _gtk_entry_reset_im_context (entry);
3688 if (!have_selection) /* select from the current position to the clicked position */
3689 sel_start = sel_end = entry->current_pos;
3691 if (tmp_pos > sel_start && tmp_pos < sel_end)
3693 /* Truncate current selection, but keep it as big as possible */
3694 if (tmp_pos - sel_start > sel_end - tmp_pos)
3695 gtk_entry_set_positions (entry, sel_start, tmp_pos);
3697 gtk_entry_set_positions (entry, tmp_pos, sel_end);
3701 gboolean extend_to_left;
3704 /* Figure out what click selects and extend current selection */
3705 switch (event->type)
3707 case GDK_BUTTON_PRESS:
3708 gtk_entry_set_positions (entry, tmp_pos, tmp_pos);
3711 case GDK_2BUTTON_PRESS:
3712 entry->select_words = TRUE;
3713 gtk_entry_select_word (entry);
3716 case GDK_3BUTTON_PRESS:
3717 entry->select_lines = TRUE;
3718 gtk_entry_select_line (entry);
3725 start = MIN (entry->current_pos, entry->selection_bound);
3726 start = MIN (sel_start, start);
3728 end = MAX (entry->current_pos, entry->selection_bound);
3729 end = MAX (sel_end, end);
3731 if (tmp_pos == sel_start || tmp_pos == sel_end)
3732 extend_to_left = (tmp_pos == start);
3734 extend_to_left = (end == sel_end);
3737 gtk_entry_set_positions (entry, start, end);
3739 gtk_entry_set_positions (entry, end, start);
3742 else /* no shift key */
3743 switch (event->type)
3745 case GDK_BUTTON_PRESS:
3746 if (in_selection (entry, event->x + entry->scroll_offset))
3748 /* Click inside the selection - we'll either start a drag, or
3749 * clear the selection
3751 entry->in_drag = TRUE;
3752 entry->drag_start_x = event->x + entry->scroll_offset;
3753 entry->drag_start_y = event->y;
3756 gtk_editable_set_position (editable, tmp_pos);
3759 case GDK_2BUTTON_PRESS:
3760 /* We ALWAYS receive a GDK_BUTTON_PRESS immediately before
3761 * receiving a GDK_2BUTTON_PRESS so we need to reset
3762 * entry->in_drag which may have been set above
3764 entry->in_drag = FALSE;
3765 entry->select_words = TRUE;
3766 gtk_entry_select_word (entry);
3769 case GDK_3BUTTON_PRESS:
3770 /* We ALWAYS receive a GDK_BUTTON_PRESS immediately before
3771 * receiving a GDK_3BUTTON_PRESS so we need to reset
3772 * entry->in_drag which may have been set above
3774 entry->in_drag = FALSE;
3775 entry->select_lines = TRUE;
3776 gtk_entry_select_line (entry);
3785 else if (event->button == 2 && event->type == GDK_BUTTON_PRESS)
3787 if (entry->editable)
3789 priv->insert_pos = tmp_pos;
3790 gtk_entry_paste (entry, GDK_SELECTION_PRIMARY);
3795 gtk_widget_error_bell (widget);
3798 else if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
3800 gtk_entry_do_popup (entry, event);
3801 entry->button = 0; /* Don't wait for release, since the menu will gtk_grab_add */
3810 gtk_entry_button_release (GtkWidget *widget,
3811 GdkEventButton *event)
3813 GtkEntry *entry = GTK_ENTRY (widget);
3814 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
3815 EntryIconInfo *icon_info = NULL;
3818 for (i = 0; i < MAX_ICONS; i++)
3820 icon_info = priv->icons[i];
3822 if (!icon_info || icon_info->insensitive)
3825 if (event->window == icon_info->window)
3827 icon_info->pressed = FALSE;
3829 if (should_prelight (entry, i) &&
3830 event->x >= 0 && event->y >= 0 &&
3831 event->x < gdk_window_get_width (icon_info->window) &&
3832 event->y < gdk_window_get_height (icon_info->window))
3834 icon_info->prelight = TRUE;
3835 gtk_widget_queue_draw (widget);
3838 if (!icon_info->nonactivatable)
3839 g_signal_emit (entry, signals[ICON_RELEASE], 0, i, event);
3845 if (event->window != entry->text_area || entry->button != event->button)
3850 gint tmp_pos = gtk_entry_find_position (entry, entry->drag_start_x);
3852 gtk_editable_set_position (GTK_EDITABLE (entry), tmp_pos);
3859 gtk_entry_update_primary_selection (entry);
3865 _gtk_entry_get_selected_text (GtkEntry *entry)
3867 GtkEditable *editable = GTK_EDITABLE (entry);
3868 gint start_text, end_text;
3871 if (gtk_editable_get_selection_bounds (editable, &start_text, &end_text))
3872 text = gtk_editable_get_chars (editable, start_text, end_text);
3878 gtk_entry_motion_notify (GtkWidget *widget,
3879 GdkEventMotion *event)
3881 GtkEntry *entry = GTK_ENTRY (widget);
3882 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3883 EntryIconInfo *icon_info = NULL;
3884 GdkDragContext *context;
3888 for (i = 0; i < MAX_ICONS; i++)
3890 icon_info = priv->icons[i];
3892 if (!icon_info || icon_info->insensitive)
3895 if (event->window == icon_info->window)
3897 if (icon_info->pressed &&
3898 icon_info->target_list != NULL &&
3899 gtk_drag_check_threshold (widget,
3905 icon_info->in_drag = TRUE;
3906 icon_info->pressed = FALSE;
3907 context = gtk_drag_begin (widget,
3908 icon_info->target_list,
3918 if (entry->mouse_cursor_obscured)
3922 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
3923 gdk_window_set_cursor (entry->text_area, cursor);
3924 gdk_cursor_unref (cursor);
3925 entry->mouse_cursor_obscured = FALSE;
3928 if (event->window != entry->text_area || entry->button != 1)
3931 if (entry->select_lines)
3934 gdk_event_request_motions (event);
3938 if (gtk_entry_get_display_mode (entry) == DISPLAY_NORMAL &&
3939 gtk_drag_check_threshold (widget,
3940 entry->drag_start_x, entry->drag_start_y,
3941 event->x + entry->scroll_offset, event->y))
3943 GdkDragContext *context;
3944 GtkTargetList *target_list = gtk_target_list_new (NULL, 0);
3945 guint actions = entry->editable ? GDK_ACTION_COPY | GDK_ACTION_MOVE : GDK_ACTION_COPY;
3947 cairo_surface_t *surface;
3949 gtk_target_list_add_text_targets (target_list, 0);
3951 text = _gtk_entry_get_selected_text (entry);
3952 surface = _gtk_text_util_create_drag_icon (widget, text, -1);
3954 context = gtk_drag_begin (widget, target_list, actions,
3955 entry->button, (GdkEvent *)event);
3958 gtk_drag_set_icon_surface (context, surface);
3960 gtk_drag_set_icon_default (context);
3963 cairo_surface_destroy (surface);
3966 entry->in_drag = FALSE;
3969 gtk_target_list_unref (target_list);
3976 else if (event->y >= gdk_window_get_height (entry->text_area))
3977 tmp_pos = gtk_entry_buffer_get_length (get_buffer (entry));
3979 tmp_pos = gtk_entry_find_position (entry, event->x + entry->scroll_offset);
3981 if (entry->select_words)
3984 gint old_min, old_max;
3987 min = gtk_entry_move_backward_word (entry, tmp_pos, TRUE);
3988 max = gtk_entry_move_forward_word (entry, tmp_pos, TRUE);
3990 pos = entry->current_pos;
3991 bound = entry->selection_bound;
3993 old_min = MIN(entry->current_pos, entry->selection_bound);
3994 old_max = MAX(entry->current_pos, entry->selection_bound);
4001 else if (old_max < max)
4006 else if (pos == old_min)
4008 if (entry->current_pos != min)
4013 if (entry->current_pos != max)
4017 gtk_entry_set_positions (entry, pos, bound);
4020 gtk_entry_set_positions (entry, tmp_pos, -1);
4027 set_invisible_cursor (GdkWindow *window)
4029 GdkDisplay *display;
4032 display = gdk_window_get_display (window);
4033 cursor = gdk_cursor_new_for_display (display, GDK_BLANK_CURSOR);
4035 gdk_window_set_cursor (window, cursor);
4037 gdk_cursor_unref (cursor);
4041 gtk_entry_obscure_mouse_cursor (GtkEntry *entry)
4043 if (entry->mouse_cursor_obscured)
4046 set_invisible_cursor (entry->text_area);
4048 entry->mouse_cursor_obscured = TRUE;
4052 gtk_entry_key_press (GtkWidget *widget,
4055 GtkEntry *entry = GTK_ENTRY (widget);
4057 gtk_entry_reset_blink_time (entry);
4058 gtk_entry_pend_cursor_blink (entry);
4060 if (entry->editable)
4062 if (gtk_im_context_filter_keypress (entry->im_context, event))
4064 gtk_entry_obscure_mouse_cursor (entry);
4065 entry->need_im_reset = TRUE;
4070 if (event->keyval == GDK_KEY_Return ||
4071 event->keyval == GDK_KEY_KP_Enter ||
4072 event->keyval == GDK_KEY_ISO_Enter ||
4073 event->keyval == GDK_KEY_Escape)
4075 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
4077 if (completion && completion->priv->completion_timeout)
4079 g_source_remove (completion->priv->completion_timeout);
4080 completion->priv->completion_timeout = 0;
4083 _gtk_entry_reset_im_context (entry);
4086 if (GTK_WIDGET_CLASS (gtk_entry_parent_class)->key_press_event (widget, event))
4087 /* Activate key bindings
4091 if (!entry->editable && event->length)
4092 gtk_widget_error_bell (widget);
4098 gtk_entry_key_release (GtkWidget *widget,
4101 GtkEntry *entry = GTK_ENTRY (widget);
4103 if (entry->editable)
4105 if (gtk_im_context_filter_keypress (entry->im_context, event))
4107 entry->need_im_reset = TRUE;
4112 return GTK_WIDGET_CLASS (gtk_entry_parent_class)->key_release_event (widget, event);
4116 gtk_entry_focus_in (GtkWidget *widget,
4117 GdkEventFocus *event)
4119 GtkEntry *entry = GTK_ENTRY (widget);
4122 gtk_widget_queue_draw (widget);
4124 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (widget));
4126 if (entry->editable)
4128 entry->need_im_reset = TRUE;
4129 gtk_im_context_focus_in (entry->im_context);
4130 keymap_state_changed (keymap, entry);
4131 g_signal_connect (keymap, "state-changed",
4132 G_CALLBACK (keymap_state_changed), entry);
4135 g_signal_connect (keymap, "direction-changed",
4136 G_CALLBACK (keymap_direction_changed), entry);
4138 gtk_entry_reset_blink_time (entry);
4139 gtk_entry_check_cursor_blink (entry);
4145 gtk_entry_focus_out (GtkWidget *widget,
4146 GdkEventFocus *event)
4148 GtkEntry *entry = GTK_ENTRY (widget);
4149 GtkEntryCompletion *completion;
4152 gtk_widget_queue_draw (widget);
4154 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (widget));
4156 if (entry->editable)
4158 entry->need_im_reset = TRUE;
4159 gtk_im_context_focus_out (entry->im_context);
4160 remove_capslock_feedback (entry);
4163 gtk_entry_check_cursor_blink (entry);
4165 g_signal_handlers_disconnect_by_func (keymap, keymap_state_changed, entry);
4166 g_signal_handlers_disconnect_by_func (keymap, keymap_direction_changed, entry);
4168 completion = gtk_entry_get_completion (entry);
4170 _gtk_entry_completion_popdown (completion);
4176 gtk_entry_grab_focus (GtkWidget *widget)
4178 GtkEntry *entry = GTK_ENTRY (widget);
4179 gboolean select_on_focus;
4181 GTK_WIDGET_CLASS (gtk_entry_parent_class)->grab_focus (widget);
4183 if (entry->editable && !entry->in_click)
4185 g_object_get (gtk_widget_get_settings (widget),
4186 "gtk-entry-select-on-focus",
4190 if (select_on_focus)
4191 gtk_editable_select_region (GTK_EDITABLE (widget), 0, -1);
4196 gtk_entry_direction_changed (GtkWidget *widget,
4197 GtkTextDirection previous_dir)
4199 GtkEntry *entry = GTK_ENTRY (widget);
4201 gtk_entry_recompute (entry);
4203 GTK_WIDGET_CLASS (gtk_entry_parent_class)->direction_changed (widget, previous_dir);
4207 gtk_entry_state_changed (GtkWidget *widget,
4208 GtkStateType previous_state)
4210 GtkEntry *entry = GTK_ENTRY (widget);
4211 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
4215 if (gtk_widget_get_realized (widget))
4220 style = gtk_widget_get_style (widget);
4221 state = gtk_widget_get_state (widget);
4223 gdk_window_set_background (gtk_widget_get_window (widget),
4224 &style->base[state]);
4225 gdk_window_set_background (entry->text_area,
4226 &style->base[state]);
4227 for (i = 0; i < MAX_ICONS; i++)
4229 EntryIconInfo *icon_info = priv->icons[i];
4230 if (icon_info && icon_info->window)
4231 gdk_window_set_background (icon_info->window,
4232 &style->base[state]);
4235 if (gtk_widget_is_sensitive (widget))
4236 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
4240 gdk_window_set_cursor (entry->text_area, cursor);
4243 gdk_cursor_unref (cursor);
4245 entry->mouse_cursor_obscured = FALSE;
4247 update_cursors (widget);
4250 if (!gtk_widget_is_sensitive (widget))
4252 /* Clear any selection */
4253 gtk_editable_select_region (GTK_EDITABLE (entry), entry->current_pos, entry->current_pos);
4256 gtk_widget_queue_draw (widget);
4260 gtk_entry_screen_changed (GtkWidget *widget,
4261 GdkScreen *old_screen)
4263 gtk_entry_recompute (GTK_ENTRY (widget));
4266 /* GtkEditable method implementations
4269 gtk_entry_insert_text (GtkEditable *editable,
4270 const gchar *new_text,
4271 gint new_text_length,
4274 g_object_ref (editable);
4277 * The incoming text may a password or other secret. We make sure
4278 * not to copy it into temporary buffers.
4281 g_signal_emit_by_name (editable, "insert-text", new_text, new_text_length, position);
4283 g_object_unref (editable);
4287 gtk_entry_delete_text (GtkEditable *editable,
4291 g_object_ref (editable);
4293 g_signal_emit_by_name (editable, "delete-text", start_pos, end_pos);
4295 g_object_unref (editable);
4299 gtk_entry_get_chars (GtkEditable *editable,
4303 GtkEntry *entry = GTK_ENTRY (editable);
4306 gint start_index, end_index;
4308 text = gtk_entry_buffer_get_text (get_buffer (entry));
4309 text_length = gtk_entry_buffer_get_length (get_buffer (entry));
4312 end_pos = text_length;
4314 start_pos = MIN (text_length, start_pos);
4315 end_pos = MIN (text_length, end_pos);
4317 start_index = g_utf8_offset_to_pointer (text, start_pos) - text;
4318 end_index = g_utf8_offset_to_pointer (text, end_pos) - text;
4320 return g_strndup (text + start_index, end_index - start_index);
4324 gtk_entry_real_set_position (GtkEditable *editable,
4327 GtkEntry *entry = GTK_ENTRY (editable);
4331 length = gtk_entry_buffer_get_length (get_buffer (entry));
4332 if (position < 0 || position > length)
4335 if (position != entry->current_pos ||
4336 position != entry->selection_bound)
4338 _gtk_entry_reset_im_context (entry);
4339 gtk_entry_set_positions (entry, position, position);
4344 gtk_entry_get_position (GtkEditable *editable)
4346 return GTK_ENTRY (editable)->current_pos;
4350 gtk_entry_set_selection_bounds (GtkEditable *editable,
4354 GtkEntry *entry = GTK_ENTRY (editable);
4357 length = gtk_entry_buffer_get_length (get_buffer (entry));
4363 _gtk_entry_reset_im_context (entry);
4365 gtk_entry_set_positions (entry,
4367 MIN (start, length));
4369 gtk_entry_update_primary_selection (entry);
4373 gtk_entry_get_selection_bounds (GtkEditable *editable,
4377 GtkEntry *entry = GTK_ENTRY (editable);
4379 *start = entry->selection_bound;
4380 *end = entry->current_pos;
4382 return (entry->selection_bound != entry->current_pos);
4386 icon_theme_changed (GtkEntry *entry)
4388 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
4391 for (i = 0; i < MAX_ICONS; i++)
4393 EntryIconInfo *icon_info = priv->icons[i];
4394 if (icon_info != NULL)
4396 if (icon_info->storage_type == GTK_IMAGE_ICON_NAME)
4397 gtk_entry_set_icon_from_icon_name (entry, i, icon_info->icon_name);
4398 else if (icon_info->storage_type == GTK_IMAGE_STOCK)
4399 gtk_entry_set_icon_from_stock (entry, i, icon_info->stock_id);
4400 else if (icon_info->storage_type == GTK_IMAGE_GICON)
4401 gtk_entry_set_icon_from_gicon (entry, i, icon_info->gicon);
4405 gtk_widget_queue_draw (GTK_WIDGET (entry));
4409 icon_margin_changed (GtkEntry *entry)
4411 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
4414 _gtk_entry_effective_inner_border (GTK_ENTRY (entry), &border);
4416 priv->icon_margin = border.left;
4420 gtk_entry_style_set (GtkWidget *widget,
4421 GtkStyle *previous_style)
4423 GtkEntry *entry = GTK_ENTRY (widget);
4424 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
4426 gboolean interior_focus;
4429 gtk_widget_style_get (widget,
4430 "focus-line-width", &focus_width,
4431 "interior-focus", &interior_focus,
4434 priv->focus_width = focus_width;
4435 priv->interior_focus = interior_focus;
4437 if (!priv->invisible_char_set)
4438 entry->invisible_char = find_invisible_char (GTK_WIDGET (entry));
4440 gtk_entry_recompute (entry);
4442 if (previous_style && gtk_widget_get_realized (widget))
4446 style = gtk_widget_get_style (widget);
4448 gdk_window_set_background (gtk_widget_get_window (widget),
4449 &style->base[gtk_widget_get_state (widget)]);
4450 gdk_window_set_background (entry->text_area,
4451 &style->base[gtk_widget_get_state (widget)]);
4452 for (i = 0; i < MAX_ICONS; i++)
4454 EntryIconInfo *icon_info = priv->icons[i];
4455 if (icon_info && icon_info->window)
4456 gdk_window_set_background (icon_info->window,
4457 &style->base[gtk_widget_get_state (widget)]);
4461 icon_theme_changed (entry);
4462 icon_margin_changed (entry);
4465 /* GtkCellEditable method implementations
4468 gtk_cell_editable_entry_activated (GtkEntry *entry, gpointer data)
4470 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4471 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4475 gtk_cell_editable_key_press_event (GtkEntry *entry,
4476 GdkEventKey *key_event,
4479 if (key_event->keyval == GDK_KEY_Escape)
4481 entry->editing_canceled = TRUE;
4482 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4483 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4488 /* override focus */
4489 if (key_event->keyval == GDK_KEY_Up || key_event->keyval == GDK_KEY_Down)
4491 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4492 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4501 gtk_entry_start_editing (GtkCellEditable *cell_editable,
4504 GTK_ENTRY (cell_editable)->is_cell_renderer = TRUE;
4506 g_signal_connect (cell_editable, "activate",
4507 G_CALLBACK (gtk_cell_editable_entry_activated), NULL);
4508 g_signal_connect (cell_editable, "key-press-event",
4509 G_CALLBACK (gtk_cell_editable_key_press_event), NULL);
4513 gtk_entry_password_hint_free (GtkEntryPasswordHint *password_hint)
4515 if (password_hint->source_id)
4516 g_source_remove (password_hint->source_id);
4518 g_slice_free (GtkEntryPasswordHint, password_hint);
4523 gtk_entry_remove_password_hint (gpointer data)
4525 GtkEntryPasswordHint *password_hint = g_object_get_qdata (data, quark_password_hint);
4526 password_hint->position = -1;
4528 /* Force the string to be redrawn, but now without a visible character */
4529 gtk_entry_recompute (GTK_ENTRY (data));
4533 /* Default signal handlers
4536 gtk_entry_real_insert_text (GtkEditable *editable,
4537 const gchar *new_text,
4538 gint new_text_length,
4544 n_chars = g_utf8_strlen (new_text, new_text_length);
4547 * The actual insertion into the buffer. This will end up firing the
4548 * following signal handlers: buffer_inserted_text(), buffer_notify_display_text(),
4549 * buffer_notify_text(), buffer_notify_length()
4551 n_inserted = gtk_entry_buffer_insert_text (get_buffer (GTK_ENTRY (editable)), *position, new_text, n_chars);
4553 if (n_inserted != n_chars)
4554 gtk_widget_error_bell (GTK_WIDGET (editable));
4556 *position += n_inserted;
4560 gtk_entry_real_delete_text (GtkEditable *editable,
4565 * The actual deletion from the buffer. This will end up firing the
4566 * following signal handlers: buffer_deleted_text(), buffer_notify_display_text(),
4567 * buffer_notify_text(), buffer_notify_length()
4570 gtk_entry_buffer_delete_text (get_buffer (GTK_ENTRY (editable)), start_pos, end_pos - start_pos);
4573 /* GtkEntryBuffer signal handlers
4576 buffer_inserted_text (GtkEntryBuffer *buffer,
4582 guint password_hint_timeout;
4584 if (entry->current_pos > position)
4585 entry->current_pos += n_chars;
4587 if (entry->selection_bound > position)
4588 entry->selection_bound += n_chars;
4590 /* Calculate the password hint if it needs to be displayed. */
4591 if (n_chars == 1 && !entry->visible)
4593 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
4594 "gtk-entry-password-hint-timeout", &password_hint_timeout,
4597 if (password_hint_timeout > 0)
4599 GtkEntryPasswordHint *password_hint = g_object_get_qdata (G_OBJECT (entry),
4600 quark_password_hint);
4603 password_hint = g_slice_new0 (GtkEntryPasswordHint);
4604 g_object_set_qdata_full (G_OBJECT (entry), quark_password_hint, password_hint,
4605 (GDestroyNotify)gtk_entry_password_hint_free);
4608 password_hint->position = position;
4609 if (password_hint->source_id)
4610 g_source_remove (password_hint->source_id);
4611 password_hint->source_id = gdk_threads_add_timeout (password_hint_timeout,
4612 (GSourceFunc)gtk_entry_remove_password_hint, entry);
4618 buffer_deleted_text (GtkEntryBuffer *buffer,
4623 guint end_pos = position + n_chars;
4624 gint selection_bound;
4627 current_pos = entry->current_pos;
4628 if (current_pos > position)
4629 current_pos -= MIN (current_pos, end_pos) - position;
4631 selection_bound = entry->selection_bound;
4632 if (selection_bound > position)
4633 selection_bound -= MIN (selection_bound, end_pos) - position;
4635 gtk_entry_set_positions (entry, current_pos, selection_bound);
4637 /* We might have deleted the selection */
4638 gtk_entry_update_primary_selection (entry);
4640 /* Disable the password hint if one exists. */
4641 if (!entry->visible)
4643 GtkEntryPasswordHint *password_hint = g_object_get_qdata (G_OBJECT (entry),
4644 quark_password_hint);
4647 if (password_hint->source_id)
4648 g_source_remove (password_hint->source_id);
4649 password_hint->source_id = 0;
4650 password_hint->position = -1;
4656 buffer_notify_text (GtkEntryBuffer *buffer,
4660 gtk_entry_recompute (entry);
4661 emit_changed (entry);
4662 g_object_notify (G_OBJECT (entry), "text");
4666 buffer_notify_length (GtkEntryBuffer *buffer,
4670 g_object_notify (G_OBJECT (entry), "text-length");
4674 buffer_notify_max_length (GtkEntryBuffer *buffer,
4678 g_object_notify (G_OBJECT (entry), "max-length");
4682 buffer_connect_signals (GtkEntry *entry)
4684 g_signal_connect (get_buffer (entry), "inserted-text", G_CALLBACK (buffer_inserted_text), entry);
4685 g_signal_connect (get_buffer (entry), "deleted-text", G_CALLBACK (buffer_deleted_text), entry);
4686 g_signal_connect (get_buffer (entry), "notify::text", G_CALLBACK (buffer_notify_text), entry);
4687 g_signal_connect (get_buffer (entry), "notify::length", G_CALLBACK (buffer_notify_length), entry);
4688 g_signal_connect (get_buffer (entry), "notify::max-length", G_CALLBACK (buffer_notify_max_length), entry);
4692 buffer_disconnect_signals (GtkEntry *entry)
4694 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_inserted_text, entry);
4695 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_deleted_text, entry);
4696 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_text, entry);
4697 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_length, entry);
4698 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_max_length, entry);
4701 /* Compute the X position for an offset that corresponds to the "more important
4702 * cursor position for that offset. We use this when trying to guess to which
4703 * end of the selection we should go to when the user hits the left or
4707 get_better_cursor_x (GtkEntry *entry,
4710 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
4711 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
4712 gboolean split_cursor;
4714 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
4715 const gchar *text = pango_layout_get_text (layout);
4716 gint index = g_utf8_offset_to_pointer (text, offset) - text;
4718 PangoRectangle strong_pos, weak_pos;
4720 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
4721 "gtk-split-cursor", &split_cursor,
4724 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
4727 return strong_pos.x / PANGO_SCALE;
4729 return (keymap_direction == entry->resolved_dir) ? strong_pos.x / PANGO_SCALE : weak_pos.x / PANGO_SCALE;
4733 gtk_entry_move_cursor (GtkEntry *entry,
4734 GtkMovementStep step,
4736 gboolean extend_selection)
4738 gint new_pos = entry->current_pos;
4739 GtkEntryPrivate *priv;
4741 _gtk_entry_reset_im_context (entry);
4743 if (entry->current_pos != entry->selection_bound && !extend_selection)
4745 /* If we have a current selection and aren't extending it, move to the
4746 * start/or end of the selection as appropriate
4750 case GTK_MOVEMENT_VISUAL_POSITIONS:
4752 gint current_x = get_better_cursor_x (entry, entry->current_pos);
4753 gint bound_x = get_better_cursor_x (entry, entry->selection_bound);
4756 new_pos = current_x < bound_x ? entry->current_pos : entry->selection_bound;
4758 new_pos = current_x > bound_x ? entry->current_pos : entry->selection_bound;
4761 case GTK_MOVEMENT_LOGICAL_POSITIONS:
4762 case GTK_MOVEMENT_WORDS:
4764 new_pos = MIN (entry->current_pos, entry->selection_bound);
4766 new_pos = MAX (entry->current_pos, entry->selection_bound);
4768 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
4769 case GTK_MOVEMENT_PARAGRAPH_ENDS:
4770 case GTK_MOVEMENT_BUFFER_ENDS:
4771 priv = GTK_ENTRY_GET_PRIVATE (entry);
4772 new_pos = count < 0 ? 0 : gtk_entry_buffer_get_length (get_buffer (entry));
4774 case GTK_MOVEMENT_DISPLAY_LINES:
4775 case GTK_MOVEMENT_PARAGRAPHS:
4776 case GTK_MOVEMENT_PAGES:
4777 case GTK_MOVEMENT_HORIZONTAL_PAGES:
4785 case GTK_MOVEMENT_LOGICAL_POSITIONS:
4786 new_pos = gtk_entry_move_logically (entry, new_pos, count);
4788 case GTK_MOVEMENT_VISUAL_POSITIONS:
4789 new_pos = gtk_entry_move_visually (entry, new_pos, count);
4790 if (entry->current_pos == new_pos)
4792 if (!extend_selection)
4794 if (!gtk_widget_keynav_failed (GTK_WIDGET (entry),
4796 GTK_DIR_RIGHT : GTK_DIR_LEFT))
4798 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (entry));
4801 gtk_widget_child_focus (toplevel,
4803 GTK_DIR_RIGHT : GTK_DIR_LEFT);
4808 gtk_widget_error_bell (GTK_WIDGET (entry));
4812 case GTK_MOVEMENT_WORDS:
4815 new_pos = gtk_entry_move_forward_word (entry, new_pos, FALSE);
4820 new_pos = gtk_entry_move_backward_word (entry, new_pos, FALSE);
4823 if (entry->current_pos == new_pos)
4824 gtk_widget_error_bell (GTK_WIDGET (entry));
4826 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
4827 case GTK_MOVEMENT_PARAGRAPH_ENDS:
4828 case GTK_MOVEMENT_BUFFER_ENDS:
4829 priv = GTK_ENTRY_GET_PRIVATE (entry);
4830 new_pos = count < 0 ? 0 : gtk_entry_buffer_get_length (get_buffer (entry));
4831 if (entry->current_pos == new_pos)
4832 gtk_widget_error_bell (GTK_WIDGET (entry));
4834 case GTK_MOVEMENT_DISPLAY_LINES:
4835 case GTK_MOVEMENT_PARAGRAPHS:
4836 case GTK_MOVEMENT_PAGES:
4837 case GTK_MOVEMENT_HORIZONTAL_PAGES:
4842 if (extend_selection)
4843 gtk_editable_select_region (GTK_EDITABLE (entry), entry->selection_bound, new_pos);
4845 gtk_editable_set_position (GTK_EDITABLE (entry), new_pos);
4847 gtk_entry_pend_cursor_blink (entry);
4851 gtk_entry_insert_at_cursor (GtkEntry *entry,
4854 GtkEditable *editable = GTK_EDITABLE (entry);
4855 gint pos = entry->current_pos;
4857 if (entry->editable)
4859 _gtk_entry_reset_im_context (entry);
4861 gtk_editable_insert_text (editable, str, -1, &pos);
4862 gtk_editable_set_position (editable, pos);
4867 gtk_entry_delete_from_cursor (GtkEntry *entry,
4871 GtkEditable *editable = GTK_EDITABLE (entry);
4872 gint start_pos = entry->current_pos;
4873 gint end_pos = entry->current_pos;
4874 gint old_n_bytes = gtk_entry_buffer_get_bytes (get_buffer (entry));
4876 _gtk_entry_reset_im_context (entry);
4878 if (!entry->editable)
4880 gtk_widget_error_bell (GTK_WIDGET (entry));
4884 if (entry->selection_bound != entry->current_pos)
4886 gtk_editable_delete_selection (editable);
4892 case GTK_DELETE_CHARS:
4893 end_pos = gtk_entry_move_logically (entry, entry->current_pos, count);
4894 gtk_editable_delete_text (editable, MIN (start_pos, end_pos), MAX (start_pos, end_pos));
4896 case GTK_DELETE_WORDS:
4899 /* Move to end of current word, or if not on a word, end of previous word */
4900 end_pos = gtk_entry_move_backward_word (entry, end_pos, FALSE);
4901 end_pos = gtk_entry_move_forward_word (entry, end_pos, FALSE);
4905 /* Move to beginning of current word, or if not on a word, begining of next word */
4906 start_pos = gtk_entry_move_forward_word (entry, start_pos, FALSE);
4907 start_pos = gtk_entry_move_backward_word (entry, start_pos, FALSE);
4911 case GTK_DELETE_WORD_ENDS:
4914 start_pos = gtk_entry_move_backward_word (entry, start_pos, FALSE);
4919 end_pos = gtk_entry_move_forward_word (entry, end_pos, FALSE);
4922 gtk_editable_delete_text (editable, start_pos, end_pos);
4924 case GTK_DELETE_DISPLAY_LINE_ENDS:
4925 case GTK_DELETE_PARAGRAPH_ENDS:
4927 gtk_editable_delete_text (editable, 0, entry->current_pos);
4929 gtk_editable_delete_text (editable, entry->current_pos, -1);
4931 case GTK_DELETE_DISPLAY_LINES:
4932 case GTK_DELETE_PARAGRAPHS:
4933 gtk_editable_delete_text (editable, 0, -1);
4935 case GTK_DELETE_WHITESPACE:
4936 gtk_entry_delete_whitespace (entry);
4940 if (gtk_entry_buffer_get_bytes (get_buffer (entry)) == old_n_bytes)
4941 gtk_widget_error_bell (GTK_WIDGET (entry));
4943 gtk_entry_pend_cursor_blink (entry);
4947 gtk_entry_backspace (GtkEntry *entry)
4949 GtkEditable *editable = GTK_EDITABLE (entry);
4952 _gtk_entry_reset_im_context (entry);
4954 if (!entry->editable)
4956 gtk_widget_error_bell (GTK_WIDGET (entry));
4960 if (entry->selection_bound != entry->current_pos)
4962 gtk_editable_delete_selection (editable);
4966 prev_pos = gtk_entry_move_logically (entry, entry->current_pos, -1);
4968 if (prev_pos < entry->current_pos)
4970 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
4971 PangoLogAttr *log_attrs;
4974 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
4976 /* Deleting parts of characters */
4977 if (log_attrs[entry->current_pos].backspace_deletes_character)
4979 gchar *cluster_text;
4980 gchar *normalized_text;
4983 cluster_text = gtk_entry_get_display_text (entry, prev_pos,
4984 entry->current_pos);
4985 normalized_text = g_utf8_normalize (cluster_text,
4986 strlen (cluster_text),
4988 len = g_utf8_strlen (normalized_text, -1);
4990 gtk_editable_delete_text (editable, prev_pos, entry->current_pos);
4993 gint pos = entry->current_pos;
4995 gtk_editable_insert_text (editable, normalized_text,
4996 g_utf8_offset_to_pointer (normalized_text, len - 1) - normalized_text,
4998 gtk_editable_set_position (editable, pos);
5001 g_free (normalized_text);
5002 g_free (cluster_text);
5006 gtk_editable_delete_text (editable, prev_pos, entry->current_pos);
5013 gtk_widget_error_bell (GTK_WIDGET (entry));
5016 gtk_entry_pend_cursor_blink (entry);
5020 gtk_entry_copy_clipboard (GtkEntry *entry)
5022 GtkEditable *editable = GTK_EDITABLE (entry);
5026 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5028 if (!entry->visible)
5030 gtk_widget_error_bell (GTK_WIDGET (entry));
5034 str = gtk_entry_get_display_text (entry, start, end);
5035 gtk_clipboard_set_text (gtk_widget_get_clipboard (GTK_WIDGET (entry),
5036 GDK_SELECTION_CLIPBOARD),
5043 gtk_entry_cut_clipboard (GtkEntry *entry)
5045 GtkEditable *editable = GTK_EDITABLE (entry);
5048 if (!entry->visible)
5050 gtk_widget_error_bell (GTK_WIDGET (entry));
5054 gtk_entry_copy_clipboard (entry);
5056 if (entry->editable)
5058 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5059 gtk_editable_delete_text (editable, start, end);
5063 gtk_widget_error_bell (GTK_WIDGET (entry));
5068 gtk_entry_paste_clipboard (GtkEntry *entry)
5070 if (entry->editable)
5071 gtk_entry_paste (entry, GDK_NONE);
5073 gtk_widget_error_bell (GTK_WIDGET (entry));
5077 gtk_entry_delete_cb (GtkEntry *entry)
5079 GtkEditable *editable = GTK_EDITABLE (entry);
5082 if (entry->editable)
5084 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5085 gtk_editable_delete_text (editable, start, end);
5090 gtk_entry_toggle_overwrite (GtkEntry *entry)
5092 entry->overwrite_mode = !entry->overwrite_mode;
5093 gtk_entry_pend_cursor_blink (entry);
5094 gtk_widget_queue_draw (GTK_WIDGET (entry));
5098 gtk_entry_select_all (GtkEntry *entry)
5100 gtk_entry_select_line (entry);
5104 gtk_entry_real_activate (GtkEntry *entry)
5107 GtkWidget *default_widget, *focus_widget;
5108 GtkWidget *toplevel;
5111 widget = GTK_WIDGET (entry);
5113 if (entry->activates_default)
5115 toplevel = gtk_widget_get_toplevel (widget);
5116 if (GTK_IS_WINDOW (toplevel))
5118 window = GTK_WINDOW (toplevel);
5122 default_widget = gtk_window_get_default_widget (window);
5123 focus_widget = gtk_window_get_focus (window);
5124 if (widget != default_widget &&
5125 !(widget == focus_widget && (!default_widget || !gtk_widget_get_sensitive (default_widget))))
5126 gtk_window_activate_default (window);
5133 keymap_direction_changed (GdkKeymap *keymap,
5136 gtk_entry_recompute (entry);
5139 /* IM Context Callbacks
5143 gtk_entry_commit_cb (GtkIMContext *context,
5147 if (entry->editable)
5148 gtk_entry_enter_text (entry, str);
5152 gtk_entry_preedit_changed_cb (GtkIMContext *context,
5155 if (entry->editable)
5157 gchar *preedit_string;
5160 gtk_im_context_get_preedit_string (entry->im_context,
5161 &preedit_string, NULL,
5163 g_signal_emit (entry, signals[PREEDIT_CHANGED], 0, preedit_string);
5164 entry->preedit_length = strlen (preedit_string);
5165 cursor_pos = CLAMP (cursor_pos, 0, g_utf8_strlen (preedit_string, -1));
5166 entry->preedit_cursor = cursor_pos;
5167 g_free (preedit_string);
5169 gtk_entry_recompute (entry);
5174 gtk_entry_retrieve_surrounding_cb (GtkIMContext *context,
5179 /* XXXX ??? does this even make sense when text is not visible? Should we return FALSE? */
5180 text = gtk_entry_get_display_text (entry, 0, -1);
5181 gtk_im_context_set_surrounding (context, text, strlen (text), /* Length in bytes */
5182 g_utf8_offset_to_pointer (text, entry->current_pos) - text);
5189 gtk_entry_delete_surrounding_cb (GtkIMContext *slave,
5194 if (entry->editable)
5195 gtk_editable_delete_text (GTK_EDITABLE (entry),
5196 entry->current_pos + offset,
5197 entry->current_pos + offset + n_chars);
5202 /* Internal functions
5205 /* Used for im_commit_cb and inserting Unicode chars */
5207 gtk_entry_enter_text (GtkEntry *entry,
5210 GtkEditable *editable = GTK_EDITABLE (entry);
5212 gboolean old_need_im_reset;
5214 old_need_im_reset = entry->need_im_reset;
5215 entry->need_im_reset = FALSE;
5217 if (gtk_editable_get_selection_bounds (editable, NULL, NULL))
5218 gtk_editable_delete_selection (editable);
5221 if (entry->overwrite_mode)
5222 gtk_entry_delete_from_cursor (entry, GTK_DELETE_CHARS, 1);
5225 tmp_pos = entry->current_pos;
5226 gtk_editable_insert_text (editable, str, strlen (str), &tmp_pos);
5227 gtk_editable_set_position (editable, tmp_pos);
5229 entry->need_im_reset = old_need_im_reset;
5232 /* All changes to entry->current_pos and entry->selection_bound
5233 * should go through this function.
5236 gtk_entry_set_positions (GtkEntry *entry,
5238 gint selection_bound)
5240 gboolean changed = FALSE;
5242 g_object_freeze_notify (G_OBJECT (entry));
5244 if (current_pos != -1 &&
5245 entry->current_pos != current_pos)
5247 entry->current_pos = current_pos;
5250 g_object_notify (G_OBJECT (entry), "cursor-position");
5253 if (selection_bound != -1 &&
5254 entry->selection_bound != selection_bound)
5256 entry->selection_bound = selection_bound;
5259 g_object_notify (G_OBJECT (entry), "selection-bound");
5262 g_object_thaw_notify (G_OBJECT (entry));
5266 gtk_entry_move_adjustments (entry);
5267 gtk_entry_recompute (entry);
5272 gtk_entry_reset_layout (GtkEntry *entry)
5274 if (entry->cached_layout)
5276 g_object_unref (entry->cached_layout);
5277 entry->cached_layout = NULL;
5282 update_im_cursor_location (GtkEntry *entry)
5286 gint strong_xoffset;
5287 gint area_width, area_height;
5289 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
5290 gtk_entry_get_text_area_size (entry, NULL, NULL, &area_width, &area_height);
5292 strong_xoffset = strong_x - entry->scroll_offset;
5293 if (strong_xoffset < 0)
5297 else if (strong_xoffset > area_width)
5299 strong_xoffset = area_width;
5301 area.x = strong_xoffset;
5304 area.height = area_height;
5306 gtk_im_context_set_cursor_location (entry->im_context, &area);
5310 recompute_idle_func (gpointer data)
5314 entry = GTK_ENTRY (data);
5316 entry->recompute_idle = 0;
5318 if (gtk_widget_has_screen (GTK_WIDGET (entry)))
5320 gtk_entry_adjust_scroll (entry);
5321 gtk_entry_queue_draw (entry);
5323 update_im_cursor_location (entry);
5330 gtk_entry_recompute (GtkEntry *entry)
5332 gtk_entry_reset_layout (entry);
5333 gtk_entry_check_cursor_blink (entry);
5335 if (!entry->recompute_idle)
5337 entry->recompute_idle = gdk_threads_add_idle_full (G_PRIORITY_HIGH_IDLE + 15, /* between resize and redraw */
5338 recompute_idle_func, entry, NULL);
5342 static PangoLayout *
5343 gtk_entry_create_layout (GtkEntry *entry,
5344 gboolean include_preedit)
5346 GtkWidget *widget = GTK_WIDGET (entry);
5347 PangoLayout *layout = gtk_widget_create_pango_layout (widget, NULL);
5348 PangoAttrList *tmp_attrs = pango_attr_list_new ();
5350 gchar *preedit_string = NULL;
5351 gint preedit_length = 0;
5352 PangoAttrList *preedit_attrs = NULL;
5357 pango_layout_set_single_paragraph_mode (layout, TRUE);
5359 display = gtk_entry_get_display_text (entry, 0, -1);
5360 n_bytes = strlen (display);
5362 if (include_preedit)
5364 gtk_im_context_get_preedit_string (entry->im_context,
5365 &preedit_string, &preedit_attrs, NULL);
5366 preedit_length = entry->preedit_length;
5371 GString *tmp_string = g_string_new (display);
5372 gint cursor_index = g_utf8_offset_to_pointer (display, entry->current_pos) - display;
5374 g_string_insert (tmp_string, cursor_index, preedit_string);
5376 pango_layout_set_text (layout, tmp_string->str, tmp_string->len);
5378 pango_attr_list_splice (tmp_attrs, preedit_attrs,
5379 cursor_index, preedit_length);
5381 g_string_free (tmp_string, TRUE);
5385 PangoDirection pango_dir;
5387 if (gtk_entry_get_display_mode (entry) == DISPLAY_NORMAL)
5388 pango_dir = pango_find_base_dir (display, n_bytes);
5390 pango_dir = PANGO_DIRECTION_NEUTRAL;
5392 if (pango_dir == PANGO_DIRECTION_NEUTRAL)
5394 if (gtk_widget_has_focus (widget))
5396 GdkDisplay *display = gtk_widget_get_display (widget);
5397 GdkKeymap *keymap = gdk_keymap_get_for_display (display);
5398 if (gdk_keymap_get_direction (keymap) == PANGO_DIRECTION_RTL)
5399 pango_dir = PANGO_DIRECTION_RTL;
5401 pango_dir = PANGO_DIRECTION_LTR;
5405 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
5406 pango_dir = PANGO_DIRECTION_RTL;
5408 pango_dir = PANGO_DIRECTION_LTR;
5412 pango_context_set_base_dir (gtk_widget_get_pango_context (widget),
5415 entry->resolved_dir = pango_dir;
5417 pango_layout_set_text (layout, display, n_bytes);
5420 pango_layout_set_attributes (layout, tmp_attrs);
5422 g_free (preedit_string);
5426 pango_attr_list_unref (preedit_attrs);
5428 pango_attr_list_unref (tmp_attrs);
5433 static PangoLayout *
5434 gtk_entry_ensure_layout (GtkEntry *entry,
5435 gboolean include_preedit)
5437 if (entry->preedit_length > 0 &&
5438 !include_preedit != !entry->cache_includes_preedit)
5439 gtk_entry_reset_layout (entry);
5441 if (!entry->cached_layout)
5443 entry->cached_layout = gtk_entry_create_layout (entry, include_preedit);
5444 entry->cache_includes_preedit = include_preedit;
5447 return entry->cached_layout;
5451 get_layout_position (GtkEntry *entry,
5455 PangoLayout *layout;
5456 PangoRectangle logical_rect;
5457 gint area_width, area_height;
5458 GtkBorder inner_border;
5460 PangoLayoutLine *line;
5462 layout = gtk_entry_ensure_layout (entry, TRUE);
5464 gtk_entry_get_text_area_size (entry, NULL, NULL, &area_width, &area_height);
5465 _gtk_entry_effective_inner_border (entry, &inner_border);
5467 area_height = PANGO_SCALE * (area_height - inner_border.top - inner_border.bottom);
5469 line = pango_layout_get_lines_readonly (layout)->data;
5470 pango_layout_line_get_extents (line, NULL, &logical_rect);
5472 /* Align primarily for locale's ascent/descent */
5473 y_pos = ((area_height - entry->ascent - entry->descent) / 2 +
5474 entry->ascent + logical_rect.y);
5476 /* Now see if we need to adjust to fit in actual drawn string */
5477 if (logical_rect.height > area_height)
5478 y_pos = (area_height - logical_rect.height) / 2;
5481 else if (y_pos + logical_rect.height > area_height)
5482 y_pos = area_height - logical_rect.height;
5484 y_pos = inner_border.top + y_pos / PANGO_SCALE;
5487 *x = inner_border.left - entry->scroll_offset;
5494 draw_text_with_color (GtkEntry *entry, cairo_t *cr, GdkColor *default_color)
5496 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
5499 gint start_pos, end_pos;
5501 widget = GTK_WIDGET (entry);
5505 get_layout_position (entry, &x, &y);
5507 cairo_move_to (cr, x, y);
5508 gdk_cairo_set_source_color (cr, default_color);
5509 pango_cairo_show_layout (cr, layout);
5511 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start_pos, &end_pos))
5515 PangoRectangle logical_rect;
5516 GdkColor *selection_color, *text_color;
5517 GtkBorder inner_border;
5520 pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
5521 gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
5523 style = gtk_widget_get_style (widget);
5525 if (gtk_widget_has_focus (widget))
5527 selection_color = &style->base [GTK_STATE_SELECTED];
5528 text_color = &style->text [GTK_STATE_SELECTED];
5532 selection_color = &style->base [GTK_STATE_ACTIVE];
5533 text_color = &style->text [GTK_STATE_ACTIVE];
5536 _gtk_entry_effective_inner_border (entry, &inner_border);
5538 for (i = 0; i < n_ranges; ++i)
5539 cairo_rectangle (cr,
5540 inner_border.left - entry->scroll_offset + ranges[2 * i],
5543 logical_rect.height);
5547 gdk_cairo_set_source_color (cr, selection_color);
5550 cairo_move_to (cr, x, y);
5551 gdk_cairo_set_source_color (cr, text_color);
5552 pango_cairo_show_layout (cr, layout);
5560 gtk_entry_draw_text (GtkEntry *entry,
5563 GtkWidget *widget = GTK_WIDGET (entry);
5566 GdkColor text_color, bar_text_color;
5569 gint progress_x, progress_y, progress_width, progress_height;
5572 /* Nothing to display at all */
5573 if (gtk_entry_get_display_mode (entry) == DISPLAY_BLANK)
5576 state = GTK_STATE_SELECTED;
5577 if (!gtk_widget_get_sensitive (widget))
5578 state = GTK_STATE_INSENSITIVE;
5579 style = gtk_widget_get_style (widget);
5580 text_color = style->text[gtk_widget_get_state (widget)];
5581 bar_text_color = style->fg[state];
5583 get_progress_area (widget,
5584 &progress_x, &progress_y,
5585 &progress_width, &progress_height);
5587 /* If the color is the same, or the progress area has a zero
5588 * size, then we only need to draw once. */
5589 if ((text_color.pixel == bar_text_color.pixel) ||
5590 ((progress_width == 0) || (progress_height == 0)))
5592 draw_text_with_color (entry, cr, &text_color);
5596 width = gdk_window_get_width (entry->text_area);
5597 height = gdk_window_get_height (entry->text_area);
5601 cairo_rectangle (cr, 0, 0, width, height);
5605 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
5606 cairo_rectangle (cr, 0, 0, width, height);
5608 gdk_window_get_position (entry->text_area, &pos_x, &pos_y);
5609 progress_x -= pos_x;
5610 progress_y -= pos_y;
5612 cairo_rectangle (cr, progress_x, progress_y,
5613 progress_width, progress_height);
5615 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_WINDING);
5617 draw_text_with_color (entry, cr, &text_color);
5620 cairo_rectangle (cr, progress_x, progress_y,
5621 progress_width, progress_height);
5624 draw_text_with_color (entry, cr, &bar_text_color);
5631 draw_insertion_cursor (GtkEntry *entry,
5633 GdkRectangle *cursor_location,
5634 gboolean is_primary,
5635 PangoDirection direction,
5636 gboolean draw_arrow)
5638 GtkWidget *widget = GTK_WIDGET (entry);
5639 GtkTextDirection text_dir;
5641 if (direction == PANGO_DIRECTION_LTR)
5642 text_dir = GTK_TEXT_DIR_LTR;
5644 text_dir = GTK_TEXT_DIR_RTL;
5646 gtk_draw_insertion_cursor (widget, cr,
5648 is_primary, text_dir, draw_arrow);
5652 gtk_entry_draw_cursor (GtkEntry *entry,
5656 GtkWidget *widget = GTK_WIDGET (entry);
5657 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
5658 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
5659 GdkRectangle cursor_location;
5660 gboolean split_cursor;
5661 PangoRectangle cursor_rect;
5662 GtkBorder inner_border;
5664 gint text_area_height;
5667 gboolean block_at_line_end;
5668 PangoLayout *layout;
5671 _gtk_entry_effective_inner_border (entry, &inner_border);
5673 xoffset = inner_border.left - entry->scroll_offset;
5675 text_area_height = gdk_window_get_height (entry->text_area);
5677 layout = gtk_entry_ensure_layout (entry, TRUE);
5678 text = pango_layout_get_text (layout);
5679 cursor_index = g_utf8_offset_to_pointer (text, entry->current_pos + entry->preedit_cursor) - text;
5680 if (!entry->overwrite_mode)
5683 block = _gtk_text_util_get_block_cursor_location (layout,
5684 cursor_index, &cursor_rect, &block_at_line_end);
5688 gint strong_x, weak_x;
5689 PangoDirection dir1 = PANGO_DIRECTION_NEUTRAL;
5690 PangoDirection dir2 = PANGO_DIRECTION_NEUTRAL;
5694 gtk_entry_get_cursor_locations (entry, type, &strong_x, &weak_x);
5696 g_object_get (gtk_widget_get_settings (widget),
5697 "gtk-split-cursor", &split_cursor,
5700 dir1 = entry->resolved_dir;
5706 if (weak_x != strong_x)
5708 dir2 = (entry->resolved_dir == PANGO_DIRECTION_LTR) ? PANGO_DIRECTION_RTL : PANGO_DIRECTION_LTR;
5714 if (keymap_direction == entry->resolved_dir)
5720 cursor_location.x = xoffset + x1;
5721 cursor_location.y = inner_border.top;
5722 cursor_location.width = 0;
5723 cursor_location.height = text_area_height - inner_border.top - inner_border.bottom;
5725 draw_insertion_cursor (entry, cr,
5726 &cursor_location, TRUE, dir1,
5727 dir2 != PANGO_DIRECTION_NEUTRAL);
5729 if (dir2 != PANGO_DIRECTION_NEUTRAL)
5731 cursor_location.x = xoffset + x2;
5732 draw_insertion_cursor (entry, cr,
5733 &cursor_location, FALSE, dir2,
5737 else /* overwrite_mode */
5739 GdkColor cursor_color;
5745 get_layout_position (entry, &x, &y);
5747 rect.x = PANGO_PIXELS (cursor_rect.x) + x;
5748 rect.y = PANGO_PIXELS (cursor_rect.y) + y;
5749 rect.width = PANGO_PIXELS (cursor_rect.width);
5750 rect.height = PANGO_PIXELS (cursor_rect.height);
5752 _gtk_widget_get_cursor_color (widget, &cursor_color);
5753 gdk_cairo_set_source_color (cr, &cursor_color);
5754 gdk_cairo_rectangle (cr, &rect);
5757 if (!block_at_line_end)
5759 gdk_cairo_rectangle (cr, &rect);
5761 cairo_move_to (cr, x, y);
5762 gdk_cairo_set_source_color (cr, >k_widget_get_style (widget)->base[gtk_widget_get_state (widget)]);
5763 pango_cairo_show_layout (cr, layout);
5771 gtk_entry_queue_draw (GtkEntry *entry)
5773 if (gtk_widget_is_drawable (GTK_WIDGET (entry)))
5774 gdk_window_invalidate_rect (entry->text_area, NULL, FALSE);
5778 _gtk_entry_reset_im_context (GtkEntry *entry)
5780 if (entry->need_im_reset)
5782 entry->need_im_reset = FALSE;
5783 gtk_im_context_reset (entry->im_context);
5788 * gtk_entry_reset_im_context:
5789 * @entry: a #GtkEntry
5791 * Reset the input method context of the entry if needed.
5793 * This can be necessary in the case where modifying the buffer
5794 * would confuse on-going input method behavior.
5799 gtk_entry_reset_im_context (GtkEntry *entry)
5801 g_return_if_fail (GTK_IS_ENTRY (entry));
5803 _gtk_entry_reset_im_context (entry);
5807 * gtk_entry_im_context_filter_keypress:
5808 * @entry: a #GtkEntry
5809 * @event: the key event
5811 * Allow the #GtkEntry input method to internally handle key press
5812 * and release events. If this function returns %TRUE, then no further
5813 * processing should be done for this key event. See
5814 * gtk_im_context_filter_keypress().
5816 * Note that you are expected to call this function from your handler
5817 * when overriding key event handling. This is needed in the case when
5818 * you need to insert your own key handling between the input method
5819 * and the default key event handling of the #GtkEntry.
5820 * See gtk_text_view_reset_im_context() for an example of use.
5822 * Return value: %TRUE if the input method handled the key event.
5827 gtk_entry_im_context_filter_keypress (GtkEntry *entry,
5830 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
5832 return gtk_im_context_filter_keypress (entry->im_context, event);
5837 gtk_entry_find_position (GtkEntry *entry,
5840 PangoLayout *layout;
5841 PangoLayoutLine *line;
5848 layout = gtk_entry_ensure_layout (entry, TRUE);
5849 text = pango_layout_get_text (layout);
5850 cursor_index = g_utf8_offset_to_pointer (text, entry->current_pos) - text;
5852 line = pango_layout_get_lines_readonly (layout)->data;
5853 pango_layout_line_x_to_index (line, x * PANGO_SCALE, &index, &trailing);
5855 if (index >= cursor_index && entry->preedit_length)
5857 if (index >= cursor_index + entry->preedit_length)
5858 index -= entry->preedit_length;
5861 index = cursor_index;
5866 pos = g_utf8_pointer_to_offset (text, text + index);
5873 gtk_entry_get_cursor_locations (GtkEntry *entry,
5878 DisplayMode mode = gtk_entry_get_display_mode (entry);
5880 /* Nothing to display at all, so no cursor is relevant */
5881 if (mode == DISPLAY_BLANK)
5891 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
5892 const gchar *text = pango_layout_get_text (layout);
5893 PangoRectangle strong_pos, weak_pos;
5896 if (type == CURSOR_STANDARD)
5898 index = g_utf8_offset_to_pointer (text, entry->current_pos + entry->preedit_cursor) - text;
5900 else /* type == CURSOR_DND */
5902 index = g_utf8_offset_to_pointer (text, entry->dnd_position) - text;
5904 if (entry->dnd_position > entry->current_pos)
5906 if (mode == DISPLAY_NORMAL)
5907 index += entry->preedit_length;
5910 gint preedit_len_chars = g_utf8_strlen (text, -1) - gtk_entry_buffer_get_length (get_buffer (entry));
5911 index += preedit_len_chars * g_unichar_to_utf8 (entry->invisible_char, NULL);
5916 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
5919 *strong_x = strong_pos.x / PANGO_SCALE;
5922 *weak_x = weak_pos.x / PANGO_SCALE;
5927 gtk_entry_adjust_scroll (GtkEntry *entry)
5929 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
5930 gint min_offset, max_offset;
5931 gint text_area_width, text_width;
5932 GtkBorder inner_border;
5933 gint strong_x, weak_x;
5934 gint strong_xoffset, weak_xoffset;
5936 PangoLayout *layout;
5937 PangoLayoutLine *line;
5938 PangoRectangle logical_rect;
5940 if (!gtk_widget_get_realized (GTK_WIDGET (entry)))
5943 _gtk_entry_effective_inner_border (entry, &inner_border);
5945 text_area_width = gdk_window_get_width (entry->text_area);
5946 text_area_width -= inner_border.left + inner_border.right;
5947 if (text_area_width < 0)
5948 text_area_width = 0;
5950 layout = gtk_entry_ensure_layout (entry, TRUE);
5951 line = pango_layout_get_lines_readonly (layout)->data;
5953 pango_layout_line_get_extents (line, NULL, &logical_rect);
5955 /* Display as much text as we can */
5957 if (entry->resolved_dir == PANGO_DIRECTION_LTR)
5958 xalign = priv->xalign;
5960 xalign = 1.0 - priv->xalign;
5962 text_width = PANGO_PIXELS(logical_rect.width);
5964 if (text_width > text_area_width)
5967 max_offset = text_width - text_area_width;
5971 min_offset = (text_width - text_area_width) * xalign;
5972 max_offset = min_offset;
5975 entry->scroll_offset = CLAMP (entry->scroll_offset, min_offset, max_offset);
5977 /* And make sure cursors are on screen. Note that the cursor is
5978 * actually drawn one pixel into the INNER_BORDER space on
5979 * the right, when the scroll is at the utmost right. This
5980 * looks better to to me than confining the cursor inside the
5981 * border entirely, though it means that the cursor gets one
5982 * pixel closer to the edge of the widget on the right than
5983 * on the left. This might need changing if one changed
5984 * INNER_BORDER from 2 to 1, as one would do on a
5985 * small-screen-real-estate display.
5987 * We always make sure that the strong cursor is on screen, and
5988 * put the weak cursor on screen if possible.
5991 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, &weak_x);
5993 strong_xoffset = strong_x - entry->scroll_offset;
5995 if (strong_xoffset < 0)
5997 entry->scroll_offset += strong_xoffset;
6000 else if (strong_xoffset > text_area_width)
6002 entry->scroll_offset += strong_xoffset - text_area_width;
6003 strong_xoffset = text_area_width;
6006 weak_xoffset = weak_x - entry->scroll_offset;
6008 if (weak_xoffset < 0 && strong_xoffset - weak_xoffset <= text_area_width)
6010 entry->scroll_offset += weak_xoffset;
6012 else if (weak_xoffset > text_area_width &&
6013 strong_xoffset - (weak_xoffset - text_area_width) >= 0)
6015 entry->scroll_offset += weak_xoffset - text_area_width;
6018 g_object_notify (G_OBJECT (entry), "scroll-offset");
6022 gtk_entry_move_adjustments (GtkEntry *entry)
6024 GtkAllocation allocation;
6025 GtkAdjustment *adjustment;
6026 PangoContext *context;
6027 PangoFontMetrics *metrics;
6028 gint x, layout_x, border_x, border_y;
6031 adjustment = g_object_get_qdata (G_OBJECT (entry), quark_cursor_hadjustment);
6035 gtk_widget_get_allocation (&(entry->widget), &allocation);
6037 /* Cursor position, layout offset, border width, and widget allocation */
6038 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &x, NULL);
6039 get_layout_position (entry, &layout_x, NULL);
6040 _gtk_entry_get_borders (entry, &border_x, &border_y);
6041 x += allocation.x + layout_x + border_x;
6043 /* Approximate width of a char, so user can see what is ahead/behind */
6044 context = gtk_widget_get_pango_context (GTK_WIDGET (entry));
6045 metrics = pango_context_get_metrics (context,
6046 gtk_widget_get_style (&(entry->widget))->font_desc,
6047 pango_context_get_language (context));
6048 char_width = pango_font_metrics_get_approximate_char_width (metrics) / PANGO_SCALE;
6051 gtk_adjustment_clamp_page (adjustment,
6052 x - (char_width + 1), /* one char + one pixel before */
6053 x + (char_width + 2)); /* one char + cursor + one pixel after */
6057 gtk_entry_move_visually (GtkEntry *entry,
6062 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6065 text = pango_layout_get_text (layout);
6067 index = g_utf8_offset_to_pointer (text, start) - text;
6071 int new_index, new_trailing;
6072 gboolean split_cursor;
6075 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
6076 "gtk-split-cursor", &split_cursor,
6083 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
6084 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
6086 strong = keymap_direction == entry->resolved_dir;
6091 pango_layout_move_cursor_visually (layout, strong, index, 0, 1, &new_index, &new_trailing);
6096 pango_layout_move_cursor_visually (layout, strong, index, 0, -1, &new_index, &new_trailing);
6102 else if (new_index != G_MAXINT)
6105 while (new_trailing--)
6106 index = g_utf8_next_char (text + index) - text;
6109 return g_utf8_pointer_to_offset (text, text + index);
6113 gtk_entry_move_logically (GtkEntry *entry,
6117 gint new_pos = start;
6120 length = gtk_entry_buffer_get_length (get_buffer (entry));
6122 /* Prevent any leak of information */
6123 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6125 new_pos = CLAMP (start + count, 0, length);
6129 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6130 PangoLogAttr *log_attrs;
6133 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6135 while (count > 0 && new_pos < length)
6139 while (new_pos < length && !log_attrs[new_pos].is_cursor_position);
6143 while (count < 0 && new_pos > 0)
6147 while (new_pos > 0 && !log_attrs[new_pos].is_cursor_position);
6159 gtk_entry_move_forward_word (GtkEntry *entry,
6161 gboolean allow_whitespace)
6163 gint new_pos = start;
6166 length = gtk_entry_buffer_get_length (get_buffer (entry));
6168 /* Prevent any leak of information */
6169 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6173 else if (new_pos < length)
6175 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6176 PangoLogAttr *log_attrs;
6179 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6181 /* Find the next word boundary */
6183 while (new_pos < n_attrs - 1 && !(log_attrs[new_pos].is_word_end ||
6184 (log_attrs[new_pos].is_word_start && allow_whitespace)))
6195 gtk_entry_move_backward_word (GtkEntry *entry,
6197 gboolean allow_whitespace)
6199 gint new_pos = start;
6201 /* Prevent any leak of information */
6202 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6208 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6209 PangoLogAttr *log_attrs;
6212 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6214 new_pos = start - 1;
6216 /* Find the previous word boundary */
6217 while (new_pos > 0 && !(log_attrs[new_pos].is_word_start ||
6218 (log_attrs[new_pos].is_word_end && allow_whitespace)))
6228 gtk_entry_delete_whitespace (GtkEntry *entry)
6230 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6231 PangoLogAttr *log_attrs;
6235 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6237 start = end = entry->current_pos;
6239 while (start > 0 && log_attrs[start-1].is_white)
6242 while (end < n_attrs && log_attrs[end].is_white)
6248 gtk_editable_delete_text (GTK_EDITABLE (entry), start, end);
6253 gtk_entry_select_word (GtkEntry *entry)
6255 gint start_pos = gtk_entry_move_backward_word (entry, entry->current_pos, TRUE);
6256 gint end_pos = gtk_entry_move_forward_word (entry, entry->current_pos, TRUE);
6258 gtk_editable_select_region (GTK_EDITABLE (entry), start_pos, end_pos);
6262 gtk_entry_select_line (GtkEntry *entry)
6264 gtk_editable_select_region (GTK_EDITABLE (entry), 0, -1);
6268 truncate_multiline (const gchar *text)
6273 text[length] && text[length] != '\n' && text[length] != '\r';
6280 paste_received (GtkClipboard *clipboard,
6284 GtkEntry *entry = GTK_ENTRY (data);
6285 GtkEditable *editable = GTK_EDITABLE (entry);
6286 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
6288 if (entry->button == 2)
6290 gint pos, start, end;
6291 pos = priv->insert_pos;
6292 gtk_editable_get_selection_bounds (editable, &start, &end);
6293 if (!((start <= pos && pos <= end) || (end <= pos && pos <= start)))
6294 gtk_editable_select_region (editable, pos, pos);
6299 gint pos, start, end;
6301 gboolean popup_completion;
6302 GtkEntryCompletion *completion;
6304 completion = gtk_entry_get_completion (entry);
6306 if (entry->truncate_multiline)
6307 length = truncate_multiline (text);
6309 /* only complete if the selection is at the end */
6310 popup_completion = (gtk_entry_buffer_get_length (get_buffer (entry)) ==
6311 MAX (entry->current_pos, entry->selection_bound));
6315 if (gtk_widget_get_mapped (completion->priv->popup_window))
6316 _gtk_entry_completion_popdown (completion);
6318 if (!popup_completion && completion->priv->changed_id > 0)
6319 g_signal_handler_block (entry, completion->priv->changed_id);
6322 begin_change (entry);
6323 g_object_freeze_notify (G_OBJECT (entry));
6324 if (gtk_editable_get_selection_bounds (editable, &start, &end))
6325 gtk_editable_delete_text (editable, start, end);
6327 pos = entry->current_pos;
6328 gtk_editable_insert_text (editable, text, length, &pos);
6329 gtk_editable_set_position (editable, pos);
6330 g_object_thaw_notify (G_OBJECT (entry));
6334 !popup_completion && completion->priv->changed_id > 0)
6335 g_signal_handler_unblock (entry, completion->priv->changed_id);
6338 g_object_unref (entry);
6342 gtk_entry_paste (GtkEntry *entry,
6345 g_object_ref (entry);
6346 gtk_clipboard_request_text (gtk_widget_get_clipboard (GTK_WIDGET (entry), selection),
6347 paste_received, entry);
6351 primary_get_cb (GtkClipboard *clipboard,
6352 GtkSelectionData *selection_data,
6356 GtkEntry *entry = GTK_ENTRY (data);
6359 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end))
6361 gchar *str = gtk_entry_get_display_text (entry, start, end);
6362 gtk_selection_data_set_text (selection_data, str, -1);
6368 primary_clear_cb (GtkClipboard *clipboard,
6371 GtkEntry *entry = GTK_ENTRY (data);
6373 gtk_editable_select_region (GTK_EDITABLE (entry), entry->current_pos, entry->current_pos);
6377 gtk_entry_update_primary_selection (GtkEntry *entry)
6379 GtkTargetList *list;
6380 GtkTargetEntry *targets;
6381 GtkClipboard *clipboard;
6385 if (!gtk_widget_get_realized (GTK_WIDGET (entry)))
6388 list = gtk_target_list_new (NULL, 0);
6389 gtk_target_list_add_text_targets (list, 0);
6391 targets = gtk_target_table_new_from_list (list, &n_targets);
6393 clipboard = gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_PRIMARY);
6395 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end))
6397 if (!gtk_clipboard_set_with_owner (clipboard, targets, n_targets,
6398 primary_get_cb, primary_clear_cb, G_OBJECT (entry)))
6399 primary_clear_cb (clipboard, entry);
6403 if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (entry))
6404 gtk_clipboard_clear (clipboard);
6407 gtk_target_table_free (targets, n_targets);
6408 gtk_target_list_unref (list);
6412 gtk_entry_clear (GtkEntry *entry,
6413 GtkEntryIconPosition icon_pos)
6415 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
6416 EntryIconInfo *icon_info = priv->icons[icon_pos];
6418 if (!icon_info || icon_info->storage_type == GTK_IMAGE_EMPTY)
6421 g_object_freeze_notify (G_OBJECT (entry));
6423 /* Explicitly check, as the pointer may become invalidated
6424 * during destruction.
6426 if (GDK_IS_WINDOW (icon_info->window))
6427 gdk_window_hide (icon_info->window);
6429 if (icon_info->pixbuf)
6431 g_object_unref (icon_info->pixbuf);
6432 icon_info->pixbuf = NULL;
6435 switch (icon_info->storage_type)
6437 case GTK_IMAGE_PIXBUF:
6438 g_object_notify (G_OBJECT (entry),
6439 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-pixbuf" : "secondary-icon-pixbuf");
6442 case GTK_IMAGE_STOCK:
6443 g_free (icon_info->stock_id);
6444 icon_info->stock_id = NULL;
6445 g_object_notify (G_OBJECT (entry),
6446 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-stock" : "secondary-icon-stock");
6449 case GTK_IMAGE_ICON_NAME:
6450 g_free (icon_info->icon_name);
6451 icon_info->icon_name = NULL;
6452 g_object_notify (G_OBJECT (entry),
6453 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-name" : "secondary-icon-name");
6456 case GTK_IMAGE_GICON:
6457 if (icon_info->gicon)
6459 g_object_unref (icon_info->gicon);
6460 icon_info->gicon = NULL;
6462 g_object_notify (G_OBJECT (entry),
6463 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-gicon" : "secondary-icon-gicon");
6467 g_assert_not_reached ();
6471 icon_info->storage_type = GTK_IMAGE_EMPTY;
6472 g_object_notify (G_OBJECT (entry),
6473 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-storage-type" : "secondary-icon-storage-type");
6475 g_object_thaw_notify (G_OBJECT (entry));
6479 gtk_entry_ensure_pixbuf (GtkEntry *entry,
6480 GtkEntryIconPosition icon_pos)
6482 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
6483 EntryIconInfo *icon_info = priv->icons[icon_pos];
6485 GtkIconTheme *icon_theme;
6486 GtkSettings *settings;
6492 if (!icon_info || icon_info->pixbuf)
6495 widget = GTK_WIDGET (entry);
6497 switch (icon_info->storage_type)
6499 case GTK_IMAGE_EMPTY:
6500 case GTK_IMAGE_PIXBUF:
6502 case GTK_IMAGE_STOCK:
6503 state = gtk_widget_get_state (widget);
6504 gtk_widget_set_state (widget, GTK_STATE_NORMAL);
6505 icon_info->pixbuf = gtk_widget_render_icon (widget,
6506 icon_info->stock_id,
6509 if (!icon_info->pixbuf)
6510 icon_info->pixbuf = gtk_widget_render_icon (widget,
6511 GTK_STOCK_MISSING_IMAGE,
6514 gtk_widget_set_state (widget, state);
6517 case GTK_IMAGE_ICON_NAME:
6518 screen = gtk_widget_get_screen (widget);
6521 icon_theme = gtk_icon_theme_get_for_screen (screen);
6522 settings = gtk_settings_get_for_screen (screen);
6524 gtk_icon_size_lookup_for_settings (settings,
6528 icon_info->pixbuf = gtk_icon_theme_load_icon (icon_theme,
6529 icon_info->icon_name,
6530 MIN (width, height),
6533 if (icon_info->pixbuf == NULL)
6535 state = gtk_widget_get_state (widget);
6536 gtk_widget_set_state (widget, GTK_STATE_NORMAL);
6537 icon_info->pixbuf = gtk_widget_render_icon (widget,
6538 GTK_STOCK_MISSING_IMAGE,
6541 gtk_widget_set_state (widget, state);
6546 case GTK_IMAGE_GICON:
6547 screen = gtk_widget_get_screen (widget);
6550 icon_theme = gtk_icon_theme_get_for_screen (screen);
6551 settings = gtk_settings_get_for_screen (screen);
6553 gtk_icon_size_lookup_for_settings (settings,
6557 info = gtk_icon_theme_lookup_by_gicon (icon_theme,
6559 MIN (width, height),
6560 GTK_ICON_LOOKUP_USE_BUILTIN);
6563 icon_info->pixbuf = gtk_icon_info_load_icon (info, NULL);
6564 gtk_icon_info_free (info);
6567 if (icon_info->pixbuf == NULL)
6569 state = gtk_widget_get_state (widget);
6570 gtk_widget_set_state (widget, GTK_STATE_NORMAL);
6571 icon_info->pixbuf = gtk_widget_render_icon (widget,
6572 GTK_STOCK_MISSING_IMAGE,
6575 gtk_widget_set_state (widget, state);
6581 g_assert_not_reached ();
6585 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
6586 gdk_window_show_unraised (icon_info->window);
6596 * Creates a new entry.
6598 * Return value: a new #GtkEntry.
6601 gtk_entry_new (void)
6603 return g_object_new (GTK_TYPE_ENTRY, NULL);
6607 * gtk_entry_new_with_buffer:
6608 * @buffer: The buffer to use for the new #GtkEntry.
6610 * Creates a new entry with the specified text buffer.
6612 * Return value: a new #GtkEntry
6617 gtk_entry_new_with_buffer (GtkEntryBuffer *buffer)
6619 g_return_val_if_fail (GTK_IS_ENTRY_BUFFER (buffer), NULL);
6620 return g_object_new (GTK_TYPE_ENTRY, "buffer", buffer, NULL);
6623 static GtkEntryBuffer*
6624 get_buffer (GtkEntry *entry)
6626 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
6628 if (priv->buffer == NULL)
6630 GtkEntryBuffer *buffer;
6631 buffer = gtk_entry_buffer_new (NULL, 0);
6632 gtk_entry_set_buffer (entry, buffer);
6633 g_object_unref (buffer);
6636 return priv->buffer;
6640 * gtk_entry_get_buffer:
6641 * @entry: a #GtkEntry
6643 * Get the #GtkEntryBuffer object which holds the text for
6648 * Returns: (transfer none): A #GtkEntryBuffer object.
6651 gtk_entry_get_buffer (GtkEntry *entry)
6653 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
6655 return get_buffer (entry);
6659 * gtk_entry_set_buffer:
6660 * @entry: a #GtkEntry
6661 * @buffer: a #GtkEntryBuffer
6663 * Set the #GtkEntryBuffer object which holds the text for
6669 gtk_entry_set_buffer (GtkEntry *entry,
6670 GtkEntryBuffer *buffer)
6672 GtkEntryPrivate *priv;
6675 g_return_if_fail (GTK_IS_ENTRY (entry));
6676 priv = GTK_ENTRY_GET_PRIVATE (entry);
6680 g_return_if_fail (GTK_IS_ENTRY_BUFFER (buffer));
6681 g_object_ref (buffer);
6686 buffer_disconnect_signals (entry);
6687 g_object_unref (priv->buffer);
6690 priv->buffer = buffer;
6693 buffer_connect_signals (entry);
6695 obj = G_OBJECT (entry);
6696 g_object_freeze_notify (obj);
6697 g_object_notify (obj, "buffer");
6698 g_object_notify (obj, "text");
6699 g_object_notify (obj, "text-length");
6700 g_object_notify (obj, "max-length");
6701 g_object_notify (obj, "visibility");
6702 g_object_notify (obj, "invisible-char");
6703 g_object_notify (obj, "invisible-char-set");
6704 g_object_thaw_notify (obj);
6706 gtk_editable_set_position (GTK_EDITABLE (entry), 0);
6707 gtk_entry_recompute (entry);
6711 * gtk_entry_get_text_window:
6712 * @entry: a #GtkEntry
6714 * Returns the #GdkWindow which contains the text. This function is
6715 * useful when drawing something to the entry in a draw
6716 * callback because it enables the callback to distinguish between
6717 * the text window and entry's icon windows.
6719 * See also gtk_entry_get_icon_window().
6721 * Return value: (transfer none): the entry's text window.
6726 gtk_entry_get_text_window (GtkEntry *entry)
6728 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
6730 return entry->text_area;
6735 * gtk_entry_set_text:
6736 * @entry: a #GtkEntry
6737 * @text: the new text
6739 * Sets the text in the widget to the given
6740 * value, replacing the current contents.
6742 * See gtk_entry_buffer_set_text().
6745 gtk_entry_set_text (GtkEntry *entry,
6749 GtkEntryCompletion *completion;
6750 GtkEntryPrivate *priv;
6752 g_return_if_fail (GTK_IS_ENTRY (entry));
6753 g_return_if_fail (text != NULL);
6754 priv = GTK_ENTRY_GET_PRIVATE (entry);
6756 /* Actually setting the text will affect the cursor and selection;
6757 * if the contents don't actually change, this will look odd to the user.
6759 if (strcmp (gtk_entry_buffer_get_text (get_buffer (entry)), text) == 0)
6762 completion = gtk_entry_get_completion (entry);
6763 if (completion && completion->priv->changed_id > 0)
6764 g_signal_handler_block (entry, completion->priv->changed_id);
6766 begin_change (entry);
6767 g_object_freeze_notify (G_OBJECT (entry));
6768 gtk_editable_delete_text (GTK_EDITABLE (entry), 0, -1);
6770 gtk_editable_insert_text (GTK_EDITABLE (entry), text, strlen (text), &tmp_pos);
6771 g_object_thaw_notify (G_OBJECT (entry));
6774 if (completion && completion->priv->changed_id > 0)
6775 g_signal_handler_unblock (entry, completion->priv->changed_id);
6779 * gtk_entry_set_visibility:
6780 * @entry: a #GtkEntry
6781 * @visible: %TRUE if the contents of the entry are displayed
6784 * Sets whether the contents of the entry are visible or not.
6785 * When visibility is set to %FALSE, characters are displayed
6786 * as the invisible char, and will also appear that way when
6787 * the text in the entry widget is copied elsewhere.
6789 * By default, GTK+ picks the best invisible character available
6790 * in the current font, but it can be changed with
6791 * gtk_entry_set_invisible_char().
6794 gtk_entry_set_visibility (GtkEntry *entry,
6797 g_return_if_fail (GTK_IS_ENTRY (entry));
6799 visible = visible != FALSE;
6801 if (entry->visible != visible)
6803 entry->visible = visible;
6805 g_object_notify (G_OBJECT (entry), "visibility");
6806 gtk_entry_recompute (entry);
6811 * gtk_entry_get_visibility:
6812 * @entry: a #GtkEntry
6814 * Retrieves whether the text in @entry is visible. See
6815 * gtk_entry_set_visibility().
6817 * Return value: %TRUE if the text is currently visible
6820 gtk_entry_get_visibility (GtkEntry *entry)
6822 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
6824 return entry->visible;
6828 * gtk_entry_set_invisible_char:
6829 * @entry: a #GtkEntry
6830 * @ch: a Unicode character
6832 * Sets the character to use in place of the actual text when
6833 * gtk_entry_set_visibility() has been called to set text visibility
6834 * to %FALSE. i.e. this is the character used in "password mode" to
6835 * show the user how many characters have been typed. By default, GTK+
6836 * picks the best invisible char available in the current font. If you
6837 * set the invisible char to 0, then the user will get no feedback
6838 * at all; there will be no text on the screen as they type.
6841 gtk_entry_set_invisible_char (GtkEntry *entry,
6844 GtkEntryPrivate *priv;
6846 g_return_if_fail (GTK_IS_ENTRY (entry));
6848 priv = GTK_ENTRY_GET_PRIVATE (entry);
6850 if (!priv->invisible_char_set)
6852 priv->invisible_char_set = TRUE;
6853 g_object_notify (G_OBJECT (entry), "invisible-char-set");
6856 if (ch == entry->invisible_char)
6859 entry->invisible_char = ch;
6860 g_object_notify (G_OBJECT (entry), "invisible-char");
6861 gtk_entry_recompute (entry);
6865 * gtk_entry_get_invisible_char:
6866 * @entry: a #GtkEntry
6868 * Retrieves the character displayed in place of the real characters
6869 * for entries with visibility set to false. See gtk_entry_set_invisible_char().
6871 * Return value: the current invisible char, or 0, if the entry does not
6872 * show invisible text at all.
6875 gtk_entry_get_invisible_char (GtkEntry *entry)
6877 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
6879 return entry->invisible_char;
6883 * gtk_entry_unset_invisible_char:
6884 * @entry: a #GtkEntry
6886 * Unsets the invisible char previously set with
6887 * gtk_entry_set_invisible_char(). So that the
6888 * default invisible char is used again.
6893 gtk_entry_unset_invisible_char (GtkEntry *entry)
6895 GtkEntryPrivate *priv;
6898 g_return_if_fail (GTK_IS_ENTRY (entry));
6900 priv = GTK_ENTRY_GET_PRIVATE (entry);
6902 if (!priv->invisible_char_set)
6905 priv->invisible_char_set = FALSE;
6906 ch = find_invisible_char (GTK_WIDGET (entry));
6908 if (entry->invisible_char != ch)
6910 entry->invisible_char = ch;
6911 g_object_notify (G_OBJECT (entry), "invisible-char");
6914 g_object_notify (G_OBJECT (entry), "invisible-char-set");
6915 gtk_entry_recompute (entry);
6919 * gtk_entry_set_overwrite_mode:
6920 * @entry: a #GtkEntry
6921 * @overwrite: new value
6923 * Sets whether the text is overwritten when typing in the #GtkEntry.
6928 gtk_entry_set_overwrite_mode (GtkEntry *entry,
6931 g_return_if_fail (GTK_IS_ENTRY (entry));
6933 if (entry->overwrite_mode == overwrite)
6936 gtk_entry_toggle_overwrite (entry);
6938 g_object_notify (G_OBJECT (entry), "overwrite-mode");
6942 * gtk_entry_get_overwrite_mode:
6943 * @entry: a #GtkEntry
6945 * Gets the value set by gtk_entry_set_overwrite_mode().
6947 * Return value: whether the text is overwritten when typing.
6952 gtk_entry_get_overwrite_mode (GtkEntry *entry)
6954 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
6956 return entry->overwrite_mode;
6960 * gtk_entry_get_text:
6961 * @entry: a #GtkEntry
6963 * Retrieves the contents of the entry widget.
6964 * See also gtk_editable_get_chars().
6966 * This is equivalent to:
6968 * <informalexample><programlisting>
6969 * gtk_entry_buffer_get_text (gtk_entry_get_buffer (entry));
6970 * </programlisting></informalexample>
6972 * Return value: a pointer to the contents of the widget as a
6973 * string. This string points to internally allocated
6974 * storage in the widget and must not be freed, modified or
6977 G_CONST_RETURN gchar*
6978 gtk_entry_get_text (GtkEntry *entry)
6980 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
6981 return gtk_entry_buffer_get_text (get_buffer (entry));
6985 * gtk_entry_set_max_length:
6986 * @entry: a #GtkEntry
6987 * @max: the maximum length of the entry, or 0 for no maximum.
6988 * (other than the maximum length of entries.) The value passed in will
6989 * be clamped to the range 0-65536.
6991 * Sets the maximum allowed length of the contents of the widget. If
6992 * the current contents are longer than the given length, then they
6993 * will be truncated to fit.
6995 * This is equivalent to:
6997 * <informalexample><programlisting>
6998 * gtk_entry_buffer_set_max_length (gtk_entry_get_buffer (entry), max);
6999 * </programlisting></informalexample>
7002 gtk_entry_set_max_length (GtkEntry *entry,
7005 g_return_if_fail (GTK_IS_ENTRY (entry));
7006 gtk_entry_buffer_set_max_length (get_buffer (entry), max);
7010 * gtk_entry_get_max_length:
7011 * @entry: a #GtkEntry
7013 * Retrieves the maximum allowed length of the text in
7014 * @entry. See gtk_entry_set_max_length().
7016 * This is equivalent to:
7018 * <informalexample><programlisting>
7019 * gtk_entry_buffer_get_max_length (gtk_entry_get_buffer (entry));
7020 * </programlisting></informalexample>
7022 * Return value: the maximum allowed number of characters
7023 * in #GtkEntry, or 0 if there is no maximum.
7026 gtk_entry_get_max_length (GtkEntry *entry)
7028 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7029 return gtk_entry_buffer_get_max_length (get_buffer (entry));
7033 * gtk_entry_get_text_length:
7034 * @entry: a #GtkEntry
7036 * Retrieves the current length of the text in
7039 * This is equivalent to:
7041 * <informalexample><programlisting>
7042 * gtk_entry_buffer_get_length (gtk_entry_get_buffer (entry));
7043 * </programlisting></informalexample>
7045 * Return value: the current number of characters
7046 * in #GtkEntry, or 0 if there are none.
7051 gtk_entry_get_text_length (GtkEntry *entry)
7053 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7054 return gtk_entry_buffer_get_length (get_buffer (entry));
7058 * gtk_entry_set_activates_default:
7059 * @entry: a #GtkEntry
7060 * @setting: %TRUE to activate window's default widget on Enter keypress
7062 * If @setting is %TRUE, pressing Enter in the @entry will activate the default
7063 * widget for the window containing the entry. This usually means that
7064 * the dialog box containing the entry will be closed, since the default
7065 * widget is usually one of the dialog buttons.
7067 * (For experts: if @setting is %TRUE, the entry calls
7068 * gtk_window_activate_default() on the window containing the entry, in
7069 * the default handler for the #GtkWidget::activate signal.)
7072 gtk_entry_set_activates_default (GtkEntry *entry,
7075 g_return_if_fail (GTK_IS_ENTRY (entry));
7076 setting = setting != FALSE;
7078 if (setting != entry->activates_default)
7080 entry->activates_default = setting;
7081 g_object_notify (G_OBJECT (entry), "activates-default");
7086 * gtk_entry_get_activates_default:
7087 * @entry: a #GtkEntry
7089 * Retrieves the value set by gtk_entry_set_activates_default().
7091 * Return value: %TRUE if the entry will activate the default widget
7094 gtk_entry_get_activates_default (GtkEntry *entry)
7096 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7098 return entry->activates_default;
7102 * gtk_entry_set_width_chars:
7103 * @entry: a #GtkEntry
7104 * @n_chars: width in chars
7106 * Changes the size request of the entry to be about the right size
7107 * for @n_chars characters. Note that it changes the size
7108 * <emphasis>request</emphasis>, the size can still be affected by
7109 * how you pack the widget into containers. If @n_chars is -1, the
7110 * size reverts to the default entry size.
7113 gtk_entry_set_width_chars (GtkEntry *entry,
7116 g_return_if_fail (GTK_IS_ENTRY (entry));
7118 if (entry->width_chars != n_chars)
7120 entry->width_chars = n_chars;
7121 g_object_notify (G_OBJECT (entry), "width-chars");
7122 gtk_widget_queue_resize (GTK_WIDGET (entry));
7127 * gtk_entry_get_width_chars:
7128 * @entry: a #GtkEntry
7130 * Gets the value set by gtk_entry_set_width_chars().
7132 * Return value: number of chars to request space for, or negative if unset
7135 gtk_entry_get_width_chars (GtkEntry *entry)
7137 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7139 return entry->width_chars;
7143 * gtk_entry_set_has_frame:
7144 * @entry: a #GtkEntry
7145 * @setting: new value
7147 * Sets whether the entry has a beveled frame around it.
7150 gtk_entry_set_has_frame (GtkEntry *entry,
7153 g_return_if_fail (GTK_IS_ENTRY (entry));
7155 setting = (setting != FALSE);
7157 if (entry->has_frame == setting)
7160 gtk_widget_queue_resize (GTK_WIDGET (entry));
7161 entry->has_frame = setting;
7162 g_object_notify (G_OBJECT (entry), "has-frame");
7166 * gtk_entry_get_has_frame:
7167 * @entry: a #GtkEntry
7169 * Gets the value set by gtk_entry_set_has_frame().
7171 * Return value: whether the entry has a beveled frame
7174 gtk_entry_get_has_frame (GtkEntry *entry)
7176 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7178 return entry->has_frame;
7182 * gtk_entry_set_inner_border:
7183 * @entry: a #GtkEntry
7184 * @border: (allow-none): a #GtkBorder, or %NULL
7186 * Sets %entry's inner-border property to %border, or clears it if %NULL
7187 * is passed. The inner-border is the area around the entry's text, but
7190 * If set, this property overrides the inner-border style property.
7191 * Overriding the style-provided border is useful when you want to do
7192 * in-place editing of some text in a canvas or list widget, where
7193 * pixel-exact positioning of the entry is important.
7198 gtk_entry_set_inner_border (GtkEntry *entry,
7199 const GtkBorder *border)
7201 g_return_if_fail (GTK_IS_ENTRY (entry));
7203 gtk_widget_queue_resize (GTK_WIDGET (entry));
7206 g_object_set_qdata_full (G_OBJECT (entry), quark_inner_border,
7207 gtk_border_copy (border),
7208 (GDestroyNotify) gtk_border_free);
7210 g_object_set_qdata (G_OBJECT (entry), quark_inner_border, NULL);
7212 g_object_notify (G_OBJECT (entry), "inner-border");
7216 * gtk_entry_get_inner_border:
7217 * @entry: a #GtkEntry
7219 * This function returns the entry's #GtkEntry:inner-border property. See
7220 * gtk_entry_set_inner_border() for more information.
7222 * Return value: (transfer none): the entry's #GtkBorder, or %NULL if none was set.
7226 G_CONST_RETURN GtkBorder *
7227 gtk_entry_get_inner_border (GtkEntry *entry)
7229 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7231 return g_object_get_qdata (G_OBJECT (entry), quark_inner_border);
7235 * gtk_entry_get_layout:
7236 * @entry: a #GtkEntry
7238 * Gets the #PangoLayout used to display the entry.
7239 * The layout is useful to e.g. convert text positions to
7240 * pixel positions, in combination with gtk_entry_get_layout_offsets().
7241 * The returned layout is owned by the entry and must not be
7242 * modified or freed by the caller.
7244 * Keep in mind that the layout text may contain a preedit string, so
7245 * gtk_entry_layout_index_to_text_index() and
7246 * gtk_entry_text_index_to_layout_index() are needed to convert byte
7247 * indices in the layout to byte indices in the entry contents.
7249 * Return value: (transfer none): the #PangoLayout for this entry
7252 gtk_entry_get_layout (GtkEntry *entry)
7254 PangoLayout *layout;
7256 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7258 layout = gtk_entry_ensure_layout (entry, TRUE);
7265 * gtk_entry_layout_index_to_text_index:
7266 * @entry: a #GtkEntry
7267 * @layout_index: byte index into the entry layout text
7269 * Converts from a position in the entry contents (returned
7270 * by gtk_entry_get_text()) to a position in the
7271 * entry's #PangoLayout (returned by gtk_entry_get_layout(),
7272 * with text retrieved via pango_layout_get_text()).
7274 * Return value: byte index into the entry contents
7277 gtk_entry_layout_index_to_text_index (GtkEntry *entry,
7280 PangoLayout *layout;
7284 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7286 layout = gtk_entry_ensure_layout (entry, TRUE);
7287 text = pango_layout_get_text (layout);
7288 cursor_index = g_utf8_offset_to_pointer (text, entry->current_pos) - text;
7290 if (layout_index >= cursor_index && entry->preedit_length)
7292 if (layout_index >= cursor_index + entry->preedit_length)
7293 layout_index -= entry->preedit_length;
7295 layout_index = cursor_index;
7298 return layout_index;
7302 * gtk_entry_text_index_to_layout_index:
7303 * @entry: a #GtkEntry
7304 * @text_index: byte index into the entry contents
7306 * Converts from a position in the entry's #PangoLayout (returned by
7307 * gtk_entry_get_layout()) to a position in the entry contents
7308 * (returned by gtk_entry_get_text()).
7310 * Return value: byte index into the entry layout text
7313 gtk_entry_text_index_to_layout_index (GtkEntry *entry,
7316 PangoLayout *layout;
7319 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7321 layout = gtk_entry_ensure_layout (entry, TRUE);
7322 text = pango_layout_get_text (layout);
7323 cursor_index = g_utf8_offset_to_pointer (text, entry->current_pos) - text;
7325 if (text_index > cursor_index)
7326 text_index += entry->preedit_length;
7332 * gtk_entry_get_layout_offsets:
7333 * @entry: a #GtkEntry
7334 * @x: (allow-none): location to store X offset of layout, or %NULL
7335 * @y: (allow-none): location to store Y offset of layout, or %NULL
7338 * Obtains the position of the #PangoLayout used to render text
7339 * in the entry, in widget coordinates. Useful if you want to line
7340 * up the text in an entry with some other text, e.g. when using the
7341 * entry to implement editable cells in a sheet widget.
7343 * Also useful to convert mouse events into coordinates inside the
7344 * #PangoLayout, e.g. to take some action if some part of the entry text
7347 * Note that as the user scrolls around in the entry the offsets will
7348 * change; you'll need to connect to the "notify::scroll-offset"
7349 * signal to track this. Remember when using the #PangoLayout
7350 * functions you need to convert to and from pixels using
7351 * PANGO_PIXELS() or #PANGO_SCALE.
7353 * Keep in mind that the layout text may contain a preedit string, so
7354 * gtk_entry_layout_index_to_text_index() and
7355 * gtk_entry_text_index_to_layout_index() are needed to convert byte
7356 * indices in the layout to byte indices in the entry contents.
7359 gtk_entry_get_layout_offsets (GtkEntry *entry,
7363 gint text_area_x, text_area_y;
7365 g_return_if_fail (GTK_IS_ENTRY (entry));
7367 /* this gets coords relative to text area */
7368 get_layout_position (entry, x, y);
7370 /* convert to widget coords */
7371 gtk_entry_get_text_area_size (entry, &text_area_x, &text_area_y, NULL, NULL);
7382 * gtk_entry_set_alignment:
7383 * @entry: a #GtkEntry
7384 * @xalign: The horizontal alignment, from 0 (left) to 1 (right).
7385 * Reversed for RTL layouts
7387 * Sets the alignment for the contents of the entry. This controls
7388 * the horizontal positioning of the contents when the displayed
7389 * text is shorter than the width of the entry.
7394 gtk_entry_set_alignment (GtkEntry *entry, gfloat xalign)
7396 GtkEntryPrivate *priv;
7398 g_return_if_fail (GTK_IS_ENTRY (entry));
7400 priv = GTK_ENTRY_GET_PRIVATE (entry);
7404 else if (xalign > 1.0)
7407 if (xalign != priv->xalign)
7409 priv->xalign = xalign;
7411 gtk_entry_recompute (entry);
7413 g_object_notify (G_OBJECT (entry), "xalign");
7418 * gtk_entry_get_alignment:
7419 * @entry: a #GtkEntry
7421 * Gets the value set by gtk_entry_set_alignment().
7423 * Return value: the alignment
7428 gtk_entry_get_alignment (GtkEntry *entry)
7430 GtkEntryPrivate *priv;
7432 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
7434 priv = GTK_ENTRY_GET_PRIVATE (entry);
7436 return priv->xalign;
7440 * gtk_entry_set_icon_from_pixbuf:
7441 * @entry: a #GtkEntry
7442 * @icon_pos: Icon position
7443 * @pixbuf: (allow-none): A #GdkPixbuf, or %NULL
7445 * Sets the icon shown in the specified position using a pixbuf.
7447 * If @pixbuf is %NULL, no icon will be shown in the specified position.
7452 gtk_entry_set_icon_from_pixbuf (GtkEntry *entry,
7453 GtkEntryIconPosition icon_pos,
7456 GtkEntryPrivate *priv;
7457 EntryIconInfo *icon_info;
7459 g_return_if_fail (GTK_IS_ENTRY (entry));
7460 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7462 priv = GTK_ENTRY_GET_PRIVATE (entry);
7464 if ((icon_info = priv->icons[icon_pos]) == NULL)
7465 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7467 g_object_freeze_notify (G_OBJECT (entry));
7470 g_object_ref (pixbuf);
7472 gtk_entry_clear (entry, icon_pos);
7476 icon_info->storage_type = GTK_IMAGE_PIXBUF;
7477 icon_info->pixbuf = pixbuf;
7479 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7481 g_object_notify (G_OBJECT (entry), "primary-icon-pixbuf");
7482 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7486 g_object_notify (G_OBJECT (entry), "secondary-icon-pixbuf");
7487 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7490 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7491 gdk_window_show_unraised (icon_info->window);
7494 gtk_entry_ensure_pixbuf (entry, icon_pos);
7496 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7497 gtk_widget_queue_resize (GTK_WIDGET (entry));
7499 g_object_thaw_notify (G_OBJECT (entry));
7503 * gtk_entry_set_icon_from_stock:
7504 * @entry: A #GtkEntry
7505 * @icon_pos: Icon position
7506 * @stock_id: (allow-none): The name of the stock item, or %NULL
7508 * Sets the icon shown in the entry at the specified position from
7511 * If @stock_id is %NULL, no icon will be shown in the specified position.
7516 gtk_entry_set_icon_from_stock (GtkEntry *entry,
7517 GtkEntryIconPosition icon_pos,
7518 const gchar *stock_id)
7520 GtkEntryPrivate *priv;
7521 EntryIconInfo *icon_info;
7524 g_return_if_fail (GTK_IS_ENTRY (entry));
7525 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7527 priv = GTK_ENTRY_GET_PRIVATE (entry);
7529 if ((icon_info = priv->icons[icon_pos]) == NULL)
7530 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7532 g_object_freeze_notify (G_OBJECT (entry));
7534 gtk_widget_ensure_style (GTK_WIDGET (entry));
7536 /* need to dup before clearing */
7537 new_id = g_strdup (stock_id);
7539 gtk_entry_clear (entry, icon_pos);
7543 icon_info->storage_type = GTK_IMAGE_STOCK;
7544 icon_info->stock_id = new_id;
7546 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7548 g_object_notify (G_OBJECT (entry), "primary-icon-stock");
7549 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7553 g_object_notify (G_OBJECT (entry), "secondary-icon-stock");
7554 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7557 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7558 gdk_window_show_unraised (icon_info->window);
7561 gtk_entry_ensure_pixbuf (entry, icon_pos);
7563 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7564 gtk_widget_queue_resize (GTK_WIDGET (entry));
7566 g_object_thaw_notify (G_OBJECT (entry));
7570 * gtk_entry_set_icon_from_icon_name:
7571 * @entry: A #GtkEntry
7572 * @icon_pos: The position at which to set the icon
7573 * @icon_name: (allow-none): An icon name, or %NULL
7575 * Sets the icon shown in the entry at the specified position
7576 * from the current icon theme.
7578 * If the icon name isn't known, a "broken image" icon will be displayed
7581 * If @icon_name is %NULL, no icon will be shown in the specified position.
7586 gtk_entry_set_icon_from_icon_name (GtkEntry *entry,
7587 GtkEntryIconPosition icon_pos,
7588 const gchar *icon_name)
7590 GtkEntryPrivate *priv;
7591 EntryIconInfo *icon_info;
7594 g_return_if_fail (GTK_IS_ENTRY (entry));
7595 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7597 priv = GTK_ENTRY_GET_PRIVATE (entry);
7599 if ((icon_info = priv->icons[icon_pos]) == NULL)
7600 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7602 g_object_freeze_notify (G_OBJECT (entry));
7604 gtk_widget_ensure_style (GTK_WIDGET (entry));
7606 /* need to dup before clearing */
7607 new_name = g_strdup (icon_name);
7609 gtk_entry_clear (entry, icon_pos);
7611 if (new_name != NULL)
7613 icon_info->storage_type = GTK_IMAGE_ICON_NAME;
7614 icon_info->icon_name = new_name;
7616 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7618 g_object_notify (G_OBJECT (entry), "primary-icon-name");
7619 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7623 g_object_notify (G_OBJECT (entry), "secondary-icon-name");
7624 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7627 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7628 gdk_window_show_unraised (icon_info->window);
7631 gtk_entry_ensure_pixbuf (entry, icon_pos);
7633 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7634 gtk_widget_queue_resize (GTK_WIDGET (entry));
7636 g_object_thaw_notify (G_OBJECT (entry));
7640 * gtk_entry_set_icon_from_gicon:
7641 * @entry: A #GtkEntry
7642 * @icon_pos: The position at which to set the icon
7643 * @icon: (allow-none): The icon to set, or %NULL
7645 * Sets the icon shown in the entry at the specified position
7646 * from the current icon theme.
7647 * If the icon isn't known, a "broken image" icon will be displayed
7650 * If @icon is %NULL, no icon will be shown in the specified position.
7655 gtk_entry_set_icon_from_gicon (GtkEntry *entry,
7656 GtkEntryIconPosition icon_pos,
7659 GtkEntryPrivate *priv;
7660 EntryIconInfo *icon_info;
7662 g_return_if_fail (GTK_IS_ENTRY (entry));
7663 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7665 priv = GTK_ENTRY_GET_PRIVATE (entry);
7667 if ((icon_info = priv->icons[icon_pos]) == NULL)
7668 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7670 g_object_freeze_notify (G_OBJECT (entry));
7672 /* need to ref before clearing */
7674 g_object_ref (icon);
7676 gtk_entry_clear (entry, icon_pos);
7680 icon_info->storage_type = GTK_IMAGE_GICON;
7681 icon_info->gicon = icon;
7683 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7685 g_object_notify (G_OBJECT (entry), "primary-icon-gicon");
7686 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7690 g_object_notify (G_OBJECT (entry), "secondary-icon-gicon");
7691 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7694 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7695 gdk_window_show_unraised (icon_info->window);
7698 gtk_entry_ensure_pixbuf (entry, icon_pos);
7700 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7701 gtk_widget_queue_resize (GTK_WIDGET (entry));
7703 g_object_thaw_notify (G_OBJECT (entry));
7707 * gtk_entry_set_icon_activatable:
7708 * @entry: A #GtkEntry
7709 * @icon_pos: Icon position
7710 * @activatable: %TRUE if the icon should be activatable
7712 * Sets whether the icon is activatable.
7717 gtk_entry_set_icon_activatable (GtkEntry *entry,
7718 GtkEntryIconPosition icon_pos,
7719 gboolean activatable)
7721 GtkEntryPrivate *priv;
7722 EntryIconInfo *icon_info;
7724 g_return_if_fail (GTK_IS_ENTRY (entry));
7725 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7727 priv = GTK_ENTRY_GET_PRIVATE (entry);
7729 if ((icon_info = priv->icons[icon_pos]) == NULL)
7730 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7732 activatable = activatable != FALSE;
7734 if (icon_info->nonactivatable != !activatable)
7736 icon_info->nonactivatable = !activatable;
7738 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
7739 update_cursors (GTK_WIDGET (entry));
7741 g_object_notify (G_OBJECT (entry),
7742 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-activatable" : "secondary-icon-activatable");
7747 * gtk_entry_get_icon_activatable:
7748 * @entry: a #GtkEntry
7749 * @icon_pos: Icon position
7751 * Returns whether the icon is activatable.
7753 * Returns: %TRUE if the icon is activatable.
7758 gtk_entry_get_icon_activatable (GtkEntry *entry,
7759 GtkEntryIconPosition icon_pos)
7761 GtkEntryPrivate *priv;
7762 EntryIconInfo *icon_info;
7764 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7765 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), FALSE);
7767 priv = GTK_ENTRY_GET_PRIVATE (entry);
7768 icon_info = priv->icons[icon_pos];
7770 return (icon_info != NULL && !icon_info->nonactivatable);
7774 * gtk_entry_get_icon_pixbuf:
7775 * @entry: A #GtkEntry
7776 * @icon_pos: Icon position
7778 * Retrieves the image used for the icon.
7780 * Unlike the other methods of setting and getting icon data, this
7781 * method will work regardless of whether the icon was set using a
7782 * #GdkPixbuf, a #GIcon, a stock item, or an icon name.
7784 * Returns: (transfer none): A #GdkPixbuf, or %NULL if no icon is
7785 * set for this position.
7790 gtk_entry_get_icon_pixbuf (GtkEntry *entry,
7791 GtkEntryIconPosition icon_pos)
7793 GtkEntryPrivate *priv;
7794 EntryIconInfo *icon_info;
7796 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7797 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7799 priv = GTK_ENTRY_GET_PRIVATE (entry);
7800 icon_info = priv->icons[icon_pos];
7805 gtk_entry_ensure_pixbuf (entry, icon_pos);
7807 return icon_info->pixbuf;
7811 * gtk_entry_get_icon_gicon:
7812 * @entry: A #GtkEntry
7813 * @icon_pos: Icon position
7815 * Retrieves the #GIcon used for the icon, or %NULL if there is
7816 * no icon or if the icon was set by some other method (e.g., by
7817 * stock, pixbuf, or icon name).
7819 * Returns: (transfer none): A #GIcon, or %NULL if no icon is set
7820 * or if the icon is not a #GIcon
7825 gtk_entry_get_icon_gicon (GtkEntry *entry,
7826 GtkEntryIconPosition icon_pos)
7828 GtkEntryPrivate *priv;
7829 EntryIconInfo *icon_info;
7831 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7832 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7834 priv = GTK_ENTRY_GET_PRIVATE (entry);
7835 icon_info = priv->icons[icon_pos];
7840 return icon_info->storage_type == GTK_IMAGE_GICON ? icon_info->gicon : NULL;
7844 * gtk_entry_get_icon_stock:
7845 * @entry: A #GtkEntry
7846 * @icon_pos: Icon position
7848 * Retrieves the stock id used for the icon, or %NULL if there is
7849 * no icon or if the icon was set by some other method (e.g., by
7850 * pixbuf, icon name or gicon).
7852 * Returns: A stock id, or %NULL if no icon is set or if the icon
7853 * wasn't set from a stock id
7858 gtk_entry_get_icon_stock (GtkEntry *entry,
7859 GtkEntryIconPosition icon_pos)
7861 GtkEntryPrivate *priv;
7862 EntryIconInfo *icon_info;
7864 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7865 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7867 priv = GTK_ENTRY_GET_PRIVATE (entry);
7868 icon_info = priv->icons[icon_pos];
7873 return icon_info->storage_type == GTK_IMAGE_STOCK ? icon_info->stock_id : NULL;
7877 * gtk_entry_get_icon_name:
7878 * @entry: A #GtkEntry
7879 * @icon_pos: Icon position
7881 * Retrieves the icon name used for the icon, or %NULL if there is
7882 * no icon or if the icon was set by some other method (e.g., by
7883 * pixbuf, stock or gicon).
7885 * Returns: An icon name, or %NULL if no icon is set or if the icon
7886 * wasn't set from an icon name
7891 gtk_entry_get_icon_name (GtkEntry *entry,
7892 GtkEntryIconPosition icon_pos)
7894 GtkEntryPrivate *priv;
7895 EntryIconInfo *icon_info;
7897 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7898 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7900 priv = GTK_ENTRY_GET_PRIVATE (entry);
7901 icon_info = priv->icons[icon_pos];
7906 return icon_info->storage_type == GTK_IMAGE_ICON_NAME ? icon_info->icon_name : NULL;
7910 * gtk_entry_set_icon_sensitive:
7911 * @entry: A #GtkEntry
7912 * @icon_pos: Icon position
7913 * @sensitive: Specifies whether the icon should appear
7914 * sensitive or insensitive
7916 * Sets the sensitivity for the specified icon.
7921 gtk_entry_set_icon_sensitive (GtkEntry *entry,
7922 GtkEntryIconPosition icon_pos,
7925 GtkEntryPrivate *priv;
7926 EntryIconInfo *icon_info;
7928 g_return_if_fail (GTK_IS_ENTRY (entry));
7929 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7931 priv = GTK_ENTRY_GET_PRIVATE (entry);
7933 if ((icon_info = priv->icons[icon_pos]) == NULL)
7934 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7936 if (icon_info->insensitive != !sensitive)
7938 icon_info->insensitive = !sensitive;
7940 icon_info->pressed = FALSE;
7941 icon_info->prelight = FALSE;
7943 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
7944 update_cursors (GTK_WIDGET (entry));
7946 gtk_widget_queue_draw (GTK_WIDGET (entry));
7948 g_object_notify (G_OBJECT (entry),
7949 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-sensitive" : "secondary-icon-sensitive");
7954 * gtk_entry_get_icon_sensitive:
7955 * @entry: a #GtkEntry
7956 * @icon_pos: Icon position
7958 * Returns whether the icon appears sensitive or insensitive.
7960 * Returns: %TRUE if the icon is sensitive.
7965 gtk_entry_get_icon_sensitive (GtkEntry *entry,
7966 GtkEntryIconPosition icon_pos)
7968 GtkEntryPrivate *priv;
7969 EntryIconInfo *icon_info;
7971 g_return_val_if_fail (GTK_IS_ENTRY (entry), TRUE);
7972 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), TRUE);
7974 priv = GTK_ENTRY_GET_PRIVATE (entry);
7975 icon_info = priv->icons[icon_pos];
7977 return (!icon_info || !icon_info->insensitive);
7982 * gtk_entry_get_icon_storage_type:
7983 * @entry: a #GtkEntry
7984 * @icon_pos: Icon position
7986 * Gets the type of representation being used by the icon
7987 * to store image data. If the icon has no image data,
7988 * the return value will be %GTK_IMAGE_EMPTY.
7990 * Return value: image representation being used
7995 gtk_entry_get_icon_storage_type (GtkEntry *entry,
7996 GtkEntryIconPosition icon_pos)
7998 GtkEntryPrivate *priv;
7999 EntryIconInfo *icon_info;
8001 g_return_val_if_fail (GTK_IS_ENTRY (entry), GTK_IMAGE_EMPTY);
8002 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), GTK_IMAGE_EMPTY);
8004 priv = GTK_ENTRY_GET_PRIVATE (entry);
8005 icon_info = priv->icons[icon_pos];
8008 return GTK_IMAGE_EMPTY;
8010 return icon_info->storage_type;
8014 * gtk_entry_get_icon_at_pos:
8015 * @entry: a #GtkEntry
8016 * @x: the x coordinate of the position to find
8017 * @y: the y coordinate of the position to find
8019 * Finds the icon at the given position and return its index.
8020 * If @x, @y doesn't lie inside an icon, -1 is returned.
8021 * This function is intended for use in a #GtkWidget::query-tooltip
8024 * Returns: the index of the icon at the given position, or -1
8029 gtk_entry_get_icon_at_pos (GtkEntry *entry,
8033 GtkAllocation primary;
8034 GtkAllocation secondary;
8036 g_return_val_if_fail (GTK_IS_ENTRY (entry), -1);
8038 get_icon_allocations (entry, &primary, &secondary);
8040 if (primary.x <= x && x < primary.x + primary.width &&
8041 primary.y <= y && y < primary.y + primary.height)
8042 return GTK_ENTRY_ICON_PRIMARY;
8044 if (secondary.x <= x && x < secondary.x + secondary.width &&
8045 secondary.y <= y && y < secondary.y + secondary.height)
8046 return GTK_ENTRY_ICON_SECONDARY;
8052 * gtk_entry_set_icon_drag_source:
8053 * @entry: a #GtkIconEntry
8054 * @icon_pos: icon position
8055 * @target_list: the targets (data formats) in which the data can be provided
8056 * @actions: a bitmask of the allowed drag actions
8058 * Sets up the icon at the given position so that GTK+ will start a drag
8059 * operation when the user clicks and drags the icon.
8061 * To handle the drag operation, you need to connect to the usual
8062 * #GtkWidget::drag-data-get (or possibly #GtkWidget::drag-data-delete)
8063 * signal, and use gtk_entry_get_current_icon_drag_source() in
8064 * your signal handler to find out if the drag was started from
8067 * By default, GTK+ uses the icon as the drag icon. You can use the
8068 * #GtkWidget::drag-begin signal to set a different icon. Note that you
8069 * have to use g_signal_connect_after() to ensure that your signal handler
8070 * gets executed after the default handler.
8075 gtk_entry_set_icon_drag_source (GtkEntry *entry,
8076 GtkEntryIconPosition icon_pos,
8077 GtkTargetList *target_list,
8078 GdkDragAction actions)
8080 GtkEntryPrivate *priv;
8081 EntryIconInfo *icon_info;
8083 g_return_if_fail (GTK_IS_ENTRY (entry));
8084 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8086 priv = GTK_ENTRY_GET_PRIVATE (entry);
8088 if ((icon_info = priv->icons[icon_pos]) == NULL)
8089 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8091 if (icon_info->target_list)
8092 gtk_target_list_unref (icon_info->target_list);
8093 icon_info->target_list = target_list;
8094 if (icon_info->target_list)
8095 gtk_target_list_ref (icon_info->target_list);
8097 icon_info->actions = actions;
8101 * gtk_entry_get_current_icon_drag_source:
8102 * @entry: a #GtkIconEntry
8104 * Returns the index of the icon which is the source of the current
8105 * DND operation, or -1.
8107 * This function is meant to be used in a #GtkWidget::drag-data-get
8110 * Returns: index of the icon which is the source of the current
8111 * DND operation, or -1.
8116 gtk_entry_get_current_icon_drag_source (GtkEntry *entry)
8118 GtkEntryPrivate *priv;
8119 EntryIconInfo *icon_info = NULL;
8122 g_return_val_if_fail (GTK_IS_ENTRY (entry), -1);
8124 priv = GTK_ENTRY_GET_PRIVATE (entry);
8126 for (i = 0; i < MAX_ICONS; i++)
8128 if ((icon_info = priv->icons[i]))
8130 if (icon_info->in_drag)
8139 * gtk_entry_get_icon_window:
8140 * @entry: A #GtkEntry
8141 * @icon_pos: Icon position
8143 * Returns the #GdkWindow which contains the entry's icon at
8144 * @icon_pos. This function is useful when drawing something to the
8145 * entry in a draw callback because it enables the callback
8146 * to distinguish between the text window and entry's icon windows.
8148 * See also gtk_entry_get_text_window().
8150 * Return value: (transfer none): the entry's icon window at @icon_pos.
8155 gtk_entry_get_icon_window (GtkEntry *entry,
8156 GtkEntryIconPosition icon_pos)
8158 GtkEntryPrivate *priv;
8159 EntryIconInfo *icon_info;
8161 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8163 priv = GTK_ENTRY_GET_PRIVATE (entry);
8165 icon_info = priv->icons[icon_pos];
8168 return icon_info->window;
8174 ensure_has_tooltip (GtkEntry *entry)
8176 GtkEntryPrivate *priv;
8177 EntryIconInfo *icon_info;
8179 gboolean has_tooltip = FALSE;
8181 priv = GTK_ENTRY_GET_PRIVATE (entry);
8183 for (i = 0; i < MAX_ICONS; i++)
8185 if ((icon_info = priv->icons[i]) != NULL)
8187 if (icon_info->tooltip != NULL)
8195 gtk_widget_set_has_tooltip (GTK_WIDGET (entry), has_tooltip);
8199 * gtk_entry_get_icon_tooltip_text:
8200 * @entry: a #GtkEntry
8201 * @icon_pos: the icon position
8203 * Gets the contents of the tooltip on the icon at the specified
8204 * position in @entry.
8206 * Returns: the tooltip text, or %NULL. Free the returned string
8207 * with g_free() when done.
8212 gtk_entry_get_icon_tooltip_text (GtkEntry *entry,
8213 GtkEntryIconPosition icon_pos)
8215 GtkEntryPrivate *priv;
8216 EntryIconInfo *icon_info;
8219 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8220 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8222 priv = GTK_ENTRY_GET_PRIVATE (entry);
8223 icon_info = priv->icons[icon_pos];
8228 if (icon_info->tooltip &&
8229 !pango_parse_markup (icon_info->tooltip, -1, 0, NULL, &text, NULL, NULL))
8230 g_assert (NULL == text); /* text should still be NULL in case of markup errors */
8236 * gtk_entry_set_icon_tooltip_text:
8237 * @entry: a #GtkEntry
8238 * @icon_pos: the icon position
8239 * @tooltip: (allow-none): the contents of the tooltip for the icon, or %NULL
8241 * Sets @tooltip as the contents of the tooltip for the icon
8242 * at the specified position.
8244 * Use %NULL for @tooltip to remove an existing tooltip.
8246 * See also gtk_widget_set_tooltip_text() and
8247 * gtk_entry_set_icon_tooltip_markup().
8252 gtk_entry_set_icon_tooltip_text (GtkEntry *entry,
8253 GtkEntryIconPosition icon_pos,
8254 const gchar *tooltip)
8256 GtkEntryPrivate *priv;
8257 EntryIconInfo *icon_info;
8259 g_return_if_fail (GTK_IS_ENTRY (entry));
8260 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8262 priv = GTK_ENTRY_GET_PRIVATE (entry);
8264 if (!(icon_info = priv->icons[icon_pos]))
8265 icon_info = priv->icons[icon_pos];
8267 if (icon_info->tooltip)
8268 g_free (icon_info->tooltip);
8270 /* Treat an empty string as a NULL string,
8271 * because an empty string would be useless for a tooltip:
8273 if (tooltip && tooltip[0] == '\0')
8276 icon_info->tooltip = tooltip ? g_markup_escape_text (tooltip, -1) : NULL;
8278 ensure_has_tooltip (entry);
8282 * gtk_entry_get_icon_tooltip_markup:
8283 * @entry: a #GtkEntry
8284 * @icon_pos: the icon position
8286 * Gets the contents of the tooltip on the icon at the specified
8287 * position in @entry.
8289 * Returns: the tooltip text, or %NULL. Free the returned string
8290 * with g_free() when done.
8295 gtk_entry_get_icon_tooltip_markup (GtkEntry *entry,
8296 GtkEntryIconPosition icon_pos)
8298 GtkEntryPrivate *priv;
8299 EntryIconInfo *icon_info;
8301 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8302 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8304 priv = GTK_ENTRY_GET_PRIVATE (entry);
8305 icon_info = priv->icons[icon_pos];
8310 return g_strdup (icon_info->tooltip);
8314 * gtk_entry_set_icon_tooltip_markup:
8315 * @entry: a #GtkEntry
8316 * @icon_pos: the icon position
8317 * @tooltip: (allow-none): the contents of the tooltip for the icon, or %NULL
8319 * Sets @tooltip as the contents of the tooltip for the icon at
8320 * the specified position. @tooltip is assumed to be marked up with
8321 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
8323 * Use %NULL for @tooltip to remove an existing tooltip.
8325 * See also gtk_widget_set_tooltip_markup() and
8326 * gtk_enty_set_icon_tooltip_text().
8331 gtk_entry_set_icon_tooltip_markup (GtkEntry *entry,
8332 GtkEntryIconPosition icon_pos,
8333 const gchar *tooltip)
8335 GtkEntryPrivate *priv;
8336 EntryIconInfo *icon_info;
8338 g_return_if_fail (GTK_IS_ENTRY (entry));
8339 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8341 priv = GTK_ENTRY_GET_PRIVATE (entry);
8343 if (!(icon_info = priv->icons[icon_pos]))
8344 icon_info = priv->icons[icon_pos];
8346 if (icon_info->tooltip)
8347 g_free (icon_info->tooltip);
8349 /* Treat an empty string as a NULL string,
8350 * because an empty string would be useless for a tooltip:
8352 if (tooltip && tooltip[0] == '\0')
8355 icon_info->tooltip = g_strdup (tooltip);
8357 ensure_has_tooltip (entry);
8361 gtk_entry_query_tooltip (GtkWidget *widget,
8364 gboolean keyboard_tip,
8365 GtkTooltip *tooltip)
8368 GtkEntryPrivate *priv;
8369 EntryIconInfo *icon_info;
8372 entry = GTK_ENTRY (widget);
8373 priv = GTK_ENTRY_GET_PRIVATE (entry);
8377 icon_pos = gtk_entry_get_icon_at_pos (entry, x, y);
8380 if ((icon_info = priv->icons[icon_pos]) != NULL)
8382 if (icon_info->tooltip)
8384 gtk_tooltip_set_markup (tooltip, icon_info->tooltip);
8393 return GTK_WIDGET_CLASS (gtk_entry_parent_class)->query_tooltip (widget,
8400 /* Quick hack of a popup menu
8403 activate_cb (GtkWidget *menuitem,
8406 const gchar *signal = g_object_get_data (G_OBJECT (menuitem), "gtk-signal");
8407 g_signal_emit_by_name (entry, signal);
8412 gtk_entry_mnemonic_activate (GtkWidget *widget,
8413 gboolean group_cycling)
8415 gtk_widget_grab_focus (widget);
8420 append_action_signal (GtkEntry *entry,
8422 const gchar *stock_id,
8423 const gchar *signal,
8426 GtkWidget *menuitem = gtk_image_menu_item_new_from_stock (stock_id, NULL);
8428 g_object_set_data (G_OBJECT (menuitem), I_("gtk-signal"), (char *)signal);
8429 g_signal_connect (menuitem, "activate",
8430 G_CALLBACK (activate_cb), entry);
8432 gtk_widget_set_sensitive (menuitem, sensitive);
8434 gtk_widget_show (menuitem);
8435 gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
8439 popup_menu_detach (GtkWidget *attach_widget,
8442 GTK_ENTRY (attach_widget)->popup_menu = NULL;
8446 popup_position_func (GtkMenu *menu,
8452 GtkEntry *entry = GTK_ENTRY (user_data);
8453 GtkWidget *widget = GTK_WIDGET (entry);
8455 GtkRequisition menu_req;
8456 GdkRectangle monitor;
8457 GtkBorder inner_border;
8458 gint monitor_num, strong_x, height;
8460 g_return_if_fail (gtk_widget_get_realized (widget));
8462 gdk_window_get_origin (entry->text_area, x, y);
8464 screen = gtk_widget_get_screen (widget);
8465 monitor_num = gdk_screen_get_monitor_at_window (screen, entry->text_area);
8466 if (monitor_num < 0)
8468 gtk_menu_set_monitor (menu, monitor_num);
8470 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
8471 gtk_widget_get_preferred_size (entry->popup_menu,
8473 height = gdk_window_get_height (entry->text_area);
8474 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
8475 _gtk_entry_effective_inner_border (entry, &inner_border);
8477 *x += inner_border.left + strong_x - entry->scroll_offset;
8478 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
8479 *x -= menu_req.width;
8481 if ((*y + height + menu_req.height) <= monitor.y + monitor.height)
8483 else if ((*y - menu_req.height) >= monitor.y)
8484 *y -= menu_req.height;
8485 else if (monitor.y + monitor.height - (*y + height) > *y)
8488 *y -= menu_req.height;
8494 unichar_chosen_func (const char *text,
8497 GtkEntry *entry = GTK_ENTRY (data);
8499 if (entry->editable)
8500 gtk_entry_enter_text (entry, text);
8511 popup_targets_received (GtkClipboard *clipboard,
8512 GtkSelectionData *data,
8515 PopupInfo *info = user_data;
8516 GtkEntry *entry = info->entry;
8518 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
8521 gboolean clipboard_contains_text;
8522 GtkWidget *menuitem;
8524 gboolean show_input_method_menu;
8525 gboolean show_unicode_menu;
8527 clipboard_contains_text = gtk_selection_data_targets_include_text (data);
8528 if (entry->popup_menu)
8529 gtk_widget_destroy (entry->popup_menu);
8531 entry->popup_menu = gtk_menu_new ();
8533 gtk_menu_attach_to_widget (GTK_MENU (entry->popup_menu),
8537 mode = gtk_entry_get_display_mode (entry);
8538 append_action_signal (entry, entry->popup_menu, GTK_STOCK_CUT, "cut-clipboard",
8539 entry->editable && mode == DISPLAY_NORMAL &&
8540 entry->current_pos != entry->selection_bound);
8542 append_action_signal (entry, entry->popup_menu, GTK_STOCK_COPY, "copy-clipboard",
8543 mode == DISPLAY_NORMAL &&
8544 entry->current_pos != entry->selection_bound);
8546 append_action_signal (entry, entry->popup_menu, GTK_STOCK_PASTE, "paste-clipboard",
8547 entry->editable && clipboard_contains_text);
8549 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_DELETE, NULL);
8550 gtk_widget_set_sensitive (menuitem, entry->editable && entry->current_pos != entry->selection_bound);
8551 g_signal_connect_swapped (menuitem, "activate",
8552 G_CALLBACK (gtk_entry_delete_cb), entry);
8553 gtk_widget_show (menuitem);
8554 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8556 menuitem = gtk_separator_menu_item_new ();
8557 gtk_widget_show (menuitem);
8558 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8560 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_SELECT_ALL, NULL);
8561 g_signal_connect_swapped (menuitem, "activate",
8562 G_CALLBACK (gtk_entry_select_all), entry);
8563 gtk_widget_show (menuitem);
8564 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8566 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
8567 "gtk-show-input-method-menu", &show_input_method_menu,
8568 "gtk-show-unicode-menu", &show_unicode_menu,
8571 if (show_input_method_menu || show_unicode_menu)
8573 menuitem = gtk_separator_menu_item_new ();
8574 gtk_widget_show (menuitem);
8575 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8578 if (show_input_method_menu)
8580 menuitem = gtk_menu_item_new_with_mnemonic (_("Input _Methods"));
8581 gtk_widget_set_sensitive (menuitem, entry->editable);
8582 gtk_widget_show (menuitem);
8583 submenu = gtk_menu_new ();
8584 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
8586 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8588 gtk_im_multicontext_append_menuitems (GTK_IM_MULTICONTEXT (entry->im_context),
8589 GTK_MENU_SHELL (submenu));
8592 if (show_unicode_menu)
8594 menuitem = gtk_menu_item_new_with_mnemonic (_("_Insert Unicode Control Character"));
8595 gtk_widget_set_sensitive (menuitem, entry->editable);
8596 gtk_widget_show (menuitem);
8598 submenu = gtk_menu_new ();
8599 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
8600 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8602 _gtk_text_util_append_special_char_menuitems (GTK_MENU_SHELL (submenu),
8603 unichar_chosen_func,
8607 g_signal_emit (entry,
8608 signals[POPULATE_POPUP],
8614 gtk_menu_popup (GTK_MENU (entry->popup_menu), NULL, NULL,
8616 info->button, info->time);
8619 gtk_menu_popup (GTK_MENU (entry->popup_menu), NULL, NULL,
8620 popup_position_func, entry,
8621 info->button, info->time);
8622 gtk_menu_shell_select_first (GTK_MENU_SHELL (entry->popup_menu), FALSE);
8626 g_object_unref (entry);
8627 g_slice_free (PopupInfo, info);
8631 gtk_entry_do_popup (GtkEntry *entry,
8632 GdkEventButton *event)
8634 PopupInfo *info = g_slice_new (PopupInfo);
8636 /* In order to know what entries we should make sensitive, we
8637 * ask for the current targets of the clipboard, and when
8638 * we get them, then we actually pop up the menu.
8640 info->entry = g_object_ref (entry);
8644 info->button = event->button;
8645 info->time = event->time;
8650 info->time = gtk_get_current_event_time ();
8653 gtk_clipboard_request_contents (gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_CLIPBOARD),
8654 gdk_atom_intern_static_string ("TARGETS"),
8655 popup_targets_received,
8660 gtk_entry_popup_menu (GtkWidget *widget)
8662 gtk_entry_do_popup (GTK_ENTRY (widget), NULL);
8667 gtk_entry_drag_begin (GtkWidget *widget,
8668 GdkDragContext *context)
8670 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
8673 for (i = 0; i < MAX_ICONS; i++)
8675 EntryIconInfo *icon_info = priv->icons[i];
8677 if (icon_info != NULL)
8679 if (icon_info->in_drag)
8681 switch (icon_info->storage_type)
8683 case GTK_IMAGE_STOCK:
8684 gtk_drag_set_icon_stock (context, icon_info->stock_id, -2, -2);
8687 case GTK_IMAGE_ICON_NAME:
8688 gtk_drag_set_icon_name (context, icon_info->icon_name, -2, -2);
8691 /* FIXME: No GIcon support for dnd icons */
8692 case GTK_IMAGE_GICON:
8693 case GTK_IMAGE_PIXBUF:
8694 gtk_drag_set_icon_pixbuf (context, icon_info->pixbuf, -2, -2);
8697 g_assert_not_reached ();
8705 gtk_entry_drag_end (GtkWidget *widget,
8706 GdkDragContext *context)
8708 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
8711 for (i = 0; i < MAX_ICONS; i++)
8713 EntryIconInfo *icon_info = priv->icons[i];
8715 if (icon_info != NULL)
8716 icon_info->in_drag = 0;
8721 gtk_entry_drag_leave (GtkWidget *widget,
8722 GdkDragContext *context,
8725 GtkEntry *entry = GTK_ENTRY (widget);
8727 entry->dnd_position = -1;
8728 gtk_widget_queue_draw (widget);
8732 gtk_entry_drag_drop (GtkWidget *widget,
8733 GdkDragContext *context,
8738 GtkEntry *entry = GTK_ENTRY (widget);
8739 GdkAtom target = GDK_NONE;
8741 if (entry->editable)
8742 target = gtk_drag_dest_find_target (widget, context, NULL);
8744 if (target != GDK_NONE)
8745 gtk_drag_get_data (widget, context, target, time);
8747 gtk_drag_finish (context, FALSE, FALSE, time);
8753 gtk_entry_drag_motion (GtkWidget *widget,
8754 GdkDragContext *context,
8759 GtkEntry *entry = GTK_ENTRY (widget);
8761 GtkWidget *source_widget;
8762 GdkDragAction suggested_action;
8763 gint new_position, old_position;
8766 style = gtk_widget_get_style (widget);
8767 x -= style->xthickness;
8768 y -= style->ythickness;
8770 old_position = entry->dnd_position;
8771 new_position = gtk_entry_find_position (entry, x + entry->scroll_offset);
8773 if (entry->editable &&
8774 gtk_drag_dest_find_target (widget, context, NULL) != GDK_NONE)
8776 source_widget = gtk_drag_get_source_widget (context);
8777 suggested_action = context->suggested_action;
8779 if (!gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &sel1, &sel2) ||
8780 new_position < sel1 || new_position > sel2)
8782 if (source_widget == widget)
8784 /* Default to MOVE, unless the user has
8785 * pressed ctrl or alt to affect available actions
8787 if ((context->actions & GDK_ACTION_MOVE) != 0)
8788 suggested_action = GDK_ACTION_MOVE;
8791 entry->dnd_position = new_position;
8795 if (source_widget == widget)
8796 suggested_action = 0; /* Can't drop in selection where drag started */
8798 entry->dnd_position = -1;
8803 /* Entry not editable, or no text */
8804 suggested_action = 0;
8805 entry->dnd_position = -1;
8808 gdk_drag_status (context, suggested_action, time);
8810 if (entry->dnd_position != old_position)
8811 gtk_widget_queue_draw (widget);
8817 gtk_entry_drag_data_received (GtkWidget *widget,
8818 GdkDragContext *context,
8821 GtkSelectionData *selection_data,
8825 GtkEntry *entry = GTK_ENTRY (widget);
8826 GtkEditable *editable = GTK_EDITABLE (widget);
8830 str = (gchar *) gtk_selection_data_get_text (selection_data);
8832 style = gtk_widget_get_style (widget);
8833 x -= style->xthickness;
8834 y -= style->ythickness;
8836 if (str && entry->editable)
8842 if (entry->truncate_multiline)
8843 length = truncate_multiline (str);
8845 new_position = gtk_entry_find_position (entry, x + entry->scroll_offset);
8847 if (!gtk_editable_get_selection_bounds (editable, &sel1, &sel2) ||
8848 new_position < sel1 || new_position > sel2)
8850 gtk_editable_insert_text (editable, str, length, &new_position);
8854 /* Replacing selection */
8855 begin_change (entry);
8856 g_object_freeze_notify (G_OBJECT (entry));
8857 gtk_editable_delete_text (editable, sel1, sel2);
8858 gtk_editable_insert_text (editable, str, length, &sel1);
8859 g_object_thaw_notify (G_OBJECT (entry));
8863 gtk_drag_finish (context, TRUE, context->action == GDK_ACTION_MOVE, time);
8867 /* Drag and drop didn't happen! */
8868 gtk_drag_finish (context, FALSE, FALSE, time);
8875 gtk_entry_drag_data_get (GtkWidget *widget,
8876 GdkDragContext *context,
8877 GtkSelectionData *selection_data,
8881 gint sel_start, sel_end;
8884 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
8885 GtkEditable *editable = GTK_EDITABLE (widget);
8887 /* If there is an icon drag going on, exit early. */
8888 for (i = 0; i < MAX_ICONS; i++)
8890 EntryIconInfo *icon_info = priv->icons[i];
8892 if (icon_info != NULL)
8894 if (icon_info->in_drag)
8899 if (gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end))
8901 gchar *str = gtk_entry_get_display_text (GTK_ENTRY (widget), sel_start, sel_end);
8903 gtk_selection_data_set_text (selection_data, str, -1);
8911 gtk_entry_drag_data_delete (GtkWidget *widget,
8912 GdkDragContext *context)
8914 gint sel_start, sel_end;
8917 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
8918 GtkEditable *editable = GTK_EDITABLE (widget);
8920 /* If there is an icon drag going on, exit early. */
8921 for (i = 0; i < MAX_ICONS; i++)
8923 EntryIconInfo *icon_info = priv->icons[i];
8925 if (icon_info != NULL)
8927 if (icon_info->in_drag)
8932 if (GTK_ENTRY (widget)->editable &&
8933 gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end))
8934 gtk_editable_delete_text (editable, sel_start, sel_end);
8937 /* We display the cursor when
8939 * - the selection is empty, AND
8940 * - the widget has focus
8943 #define CURSOR_ON_MULTIPLIER 2
8944 #define CURSOR_OFF_MULTIPLIER 1
8945 #define CURSOR_PEND_MULTIPLIER 3
8946 #define CURSOR_DIVIDER 3
8949 cursor_blinks (GtkEntry *entry)
8951 if (gtk_widget_has_focus (GTK_WIDGET (entry)) &&
8953 entry->selection_bound == entry->current_pos)
8955 GtkSettings *settings;
8958 settings = gtk_widget_get_settings (GTK_WIDGET (entry));
8959 g_object_get (settings, "gtk-cursor-blink", &blink, NULL);
8968 get_cursor_time (GtkEntry *entry)
8970 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (entry));
8973 g_object_get (settings, "gtk-cursor-blink-time", &time, NULL);
8979 get_cursor_blink_timeout (GtkEntry *entry)
8981 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (entry));
8984 g_object_get (settings, "gtk-cursor-blink-timeout", &timeout, NULL);
8990 show_cursor (GtkEntry *entry)
8994 if (!entry->cursor_visible)
8996 entry->cursor_visible = TRUE;
8998 widget = GTK_WIDGET (entry);
8999 if (gtk_widget_has_focus (widget) && entry->selection_bound == entry->current_pos)
9000 gtk_widget_queue_draw (widget);
9005 hide_cursor (GtkEntry *entry)
9009 if (entry->cursor_visible)
9011 entry->cursor_visible = FALSE;
9013 widget = GTK_WIDGET (entry);
9014 if (gtk_widget_has_focus (widget) && entry->selection_bound == entry->current_pos)
9015 gtk_widget_queue_draw (widget);
9023 blink_cb (gpointer data)
9026 GtkEntryPrivate *priv;
9029 entry = GTK_ENTRY (data);
9030 priv = GTK_ENTRY_GET_PRIVATE (entry);
9032 if (!gtk_widget_has_focus (GTK_WIDGET (entry)))
9034 g_warning ("GtkEntry - did not receive focus-out-event. If you\n"
9035 "connect a handler to this signal, it must return\n"
9036 "FALSE so the entry gets the event as well");
9038 gtk_entry_check_cursor_blink (entry);
9043 g_assert (entry->selection_bound == entry->current_pos);
9045 blink_timeout = get_cursor_blink_timeout (entry);
9046 if (priv->blink_time > 1000 * blink_timeout &&
9047 blink_timeout < G_MAXINT/1000)
9049 /* we've blinked enough without the user doing anything, stop blinking */
9050 show_cursor (entry);
9051 entry->blink_timeout = 0;
9053 else if (entry->cursor_visible)
9055 hide_cursor (entry);
9056 entry->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_OFF_MULTIPLIER / CURSOR_DIVIDER,
9062 show_cursor (entry);
9063 priv->blink_time += get_cursor_time (entry);
9064 entry->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
9069 /* Remove ourselves */
9074 gtk_entry_check_cursor_blink (GtkEntry *entry)
9076 GtkEntryPrivate *priv;
9078 priv = GTK_ENTRY_GET_PRIVATE (entry);
9080 if (cursor_blinks (entry))
9082 if (!entry->blink_timeout)
9084 show_cursor (entry);
9085 entry->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
9092 if (entry->blink_timeout)
9094 g_source_remove (entry->blink_timeout);
9095 entry->blink_timeout = 0;
9098 entry->cursor_visible = TRUE;
9104 gtk_entry_pend_cursor_blink (GtkEntry *entry)
9106 if (cursor_blinks (entry))
9108 if (entry->blink_timeout != 0)
9109 g_source_remove (entry->blink_timeout);
9111 entry->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_PEND_MULTIPLIER / CURSOR_DIVIDER,
9114 show_cursor (entry);
9119 gtk_entry_reset_blink_time (GtkEntry *entry)
9121 GtkEntryPrivate *priv;
9123 priv = GTK_ENTRY_GET_PRIVATE (entry);
9125 priv->blink_time = 0;
9131 gtk_entry_completion_timeout (gpointer data)
9133 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (data);
9134 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (completion->priv->entry);
9136 completion->priv->completion_timeout = 0;
9138 if (completion->priv->filter_model &&
9139 g_utf8_strlen (gtk_entry_get_text (GTK_ENTRY (completion->priv->entry)), -1)
9140 >= completion->priv->minimum_key_length)
9144 GtkTreeSelection *s;
9145 gboolean popup_single;
9147 gtk_entry_completion_complete (completion);
9148 matches = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->filter_model), NULL);
9150 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9152 s = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view));
9154 gtk_tree_selection_unselect_all (s);
9156 actions = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->actions), NULL);
9158 g_object_get (completion, "popup-single-match", &popup_single, NULL);
9159 if ((matches > (popup_single ? 0: 1)) || actions > 0)
9161 if (gtk_widget_get_visible (completion->priv->popup_window))
9162 _gtk_entry_completion_resize_popup (completion);
9164 _gtk_entry_completion_popup (completion, priv->completion_device);
9167 _gtk_entry_completion_popdown (completion);
9169 else if (gtk_widget_get_visible (completion->priv->popup_window))
9170 _gtk_entry_completion_popdown (completion);
9175 static inline gboolean
9176 keyval_is_cursor_move (guint keyval)
9178 if (keyval == GDK_KEY_Up || keyval == GDK_KEY_KP_Up)
9181 if (keyval == GDK_KEY_Down || keyval == GDK_KEY_KP_Down)
9184 if (keyval == GDK_KEY_Page_Up)
9187 if (keyval == GDK_KEY_Page_Down)
9194 gtk_entry_completion_key_press (GtkWidget *widget,
9198 gint matches, actions = 0;
9199 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
9201 if (!gtk_widget_get_mapped (completion->priv->popup_window))
9204 matches = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->filter_model), NULL);
9206 if (completion->priv->actions)
9207 actions = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->actions), NULL);
9209 if (keyval_is_cursor_move (event->keyval))
9211 GtkTreePath *path = NULL;
9213 if (event->keyval == GDK_KEY_Up || event->keyval == GDK_KEY_KP_Up)
9215 if (completion->priv->current_selected < 0)
9216 completion->priv->current_selected = matches + actions - 1;
9218 completion->priv->current_selected--;
9220 else if (event->keyval == GDK_KEY_Down || event->keyval == GDK_KEY_KP_Down)
9222 if (completion->priv->current_selected < matches + actions - 1)
9223 completion->priv->current_selected++;
9225 completion->priv->current_selected = -1;
9227 else if (event->keyval == GDK_KEY_Page_Up)
9229 if (completion->priv->current_selected < 0)
9230 completion->priv->current_selected = matches + actions - 1;
9231 else if (completion->priv->current_selected == 0)
9232 completion->priv->current_selected = -1;
9233 else if (completion->priv->current_selected < matches)
9235 completion->priv->current_selected -= 14;
9236 if (completion->priv->current_selected < 0)
9237 completion->priv->current_selected = 0;
9241 completion->priv->current_selected -= 14;
9242 if (completion->priv->current_selected < matches - 1)
9243 completion->priv->current_selected = matches - 1;
9246 else if (event->keyval == GDK_KEY_Page_Down)
9248 if (completion->priv->current_selected < 0)
9249 completion->priv->current_selected = 0;
9250 else if (completion->priv->current_selected < matches - 1)
9252 completion->priv->current_selected += 14;
9253 if (completion->priv->current_selected > matches - 1)
9254 completion->priv->current_selected = matches - 1;
9256 else if (completion->priv->current_selected == matches + actions - 1)
9258 completion->priv->current_selected = -1;
9262 completion->priv->current_selected += 14;
9263 if (completion->priv->current_selected > matches + actions - 1)
9264 completion->priv->current_selected = matches + actions - 1;
9268 if (completion->priv->current_selected < 0)
9270 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9271 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view)));
9273 if (completion->priv->inline_selection &&
9274 completion->priv->completion_prefix)
9276 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9277 completion->priv->completion_prefix);
9278 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9281 else if (completion->priv->current_selected < matches)
9283 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view)));
9285 path = gtk_tree_path_new_from_indices (completion->priv->current_selected, -1);
9286 gtk_tree_view_set_cursor (GTK_TREE_VIEW (completion->priv->tree_view),
9289 if (completion->priv->inline_selection)
9293 GtkTreeIter child_iter;
9294 GtkTreeModel *model = NULL;
9295 GtkTreeSelection *sel;
9298 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view));
9299 if (!gtk_tree_selection_get_selected (sel, &model, &iter))
9302 gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (model), &child_iter, &iter);
9303 model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model));
9305 if (completion->priv->completion_prefix == NULL)
9306 completion->priv->completion_prefix = g_strdup (gtk_entry_get_text (GTK_ENTRY (completion->priv->entry)));
9308 g_signal_emit_by_name (completion, "cursor-on-match", model,
9309 &child_iter, &entry_set);
9312 else if (completion->priv->current_selected - matches >= 0)
9314 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9316 path = gtk_tree_path_new_from_indices (completion->priv->current_selected - matches, -1);
9317 gtk_tree_view_set_cursor (GTK_TREE_VIEW (completion->priv->action_view),
9320 if (completion->priv->inline_selection &&
9321 completion->priv->completion_prefix)
9323 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9324 completion->priv->completion_prefix);
9325 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9329 gtk_tree_path_free (path);
9333 else if (event->keyval == GDK_KEY_Escape ||
9334 event->keyval == GDK_KEY_Left ||
9335 event->keyval == GDK_KEY_KP_Left ||
9336 event->keyval == GDK_KEY_Right ||
9337 event->keyval == GDK_KEY_KP_Right)
9339 gboolean retval = TRUE;
9341 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9342 _gtk_entry_completion_popdown (completion);
9344 if (completion->priv->current_selected < 0)
9347 goto keypress_completion_out;
9349 else if (completion->priv->inline_selection)
9351 /* Escape rejects the tentative completion */
9352 if (event->keyval == GDK_KEY_Escape)
9354 if (completion->priv->completion_prefix)
9355 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9356 completion->priv->completion_prefix);
9358 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry), "");
9361 /* Move the cursor to the end for Right/Esc, to the
9362 beginning for Left */
9363 if (event->keyval == GDK_KEY_Right ||
9364 event->keyval == GDK_KEY_KP_Right ||
9365 event->keyval == GDK_KEY_Escape)
9366 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9368 gtk_editable_set_position (GTK_EDITABLE (widget), 0);
9371 keypress_completion_out:
9372 if (completion->priv->inline_selection)
9374 g_free (completion->priv->completion_prefix);
9375 completion->priv->completion_prefix = NULL;
9380 else if (event->keyval == GDK_KEY_Tab ||
9381 event->keyval == GDK_KEY_KP_Tab ||
9382 event->keyval == GDK_KEY_ISO_Left_Tab)
9384 GtkDirectionType dir = event->keyval == GDK_KEY_ISO_Left_Tab ?
9385 GTK_DIR_TAB_BACKWARD : GTK_DIR_TAB_FORWARD;
9387 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9388 _gtk_entry_completion_popdown (completion);
9390 g_free (completion->priv->completion_prefix);
9391 completion->priv->completion_prefix = NULL;
9393 gtk_widget_child_focus (gtk_widget_get_toplevel (widget), dir);
9397 else if (event->keyval == GDK_KEY_ISO_Enter ||
9398 event->keyval == GDK_KEY_KP_Enter ||
9399 event->keyval == GDK_KEY_Return)
9402 GtkTreeModel *model = NULL;
9403 GtkTreeSelection *sel;
9404 gboolean retval = TRUE;
9406 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9407 _gtk_entry_completion_popdown (completion);
9409 if (completion->priv->current_selected < matches)
9413 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view));
9414 if (gtk_tree_selection_get_selected (sel, &model, &iter))
9416 g_signal_handler_block (widget, completion->priv->changed_id);
9417 g_signal_emit_by_name (completion, "match-selected",
9418 model, &iter, &entry_set);
9419 g_signal_handler_unblock (widget, completion->priv->changed_id);
9425 gtk_tree_model_get (model, &iter,
9426 completion->priv->text_column, &str,
9429 gtk_entry_set_text (GTK_ENTRY (widget), str);
9431 /* move the cursor to the end */
9432 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9440 else if (completion->priv->current_selected - matches >= 0)
9442 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view));
9443 if (gtk_tree_selection_get_selected (sel, &model, &iter))
9447 path = gtk_tree_path_new_from_indices (completion->priv->current_selected - matches, -1);
9448 g_signal_emit_by_name (completion, "action-activated",
9449 gtk_tree_path_get_indices (path)[0]);
9450 gtk_tree_path_free (path);
9456 g_free (completion->priv->completion_prefix);
9457 completion->priv->completion_prefix = NULL;
9466 gtk_entry_completion_changed (GtkWidget *entry,
9469 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
9470 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
9473 /* (re)install completion timeout */
9474 if (completion->priv->completion_timeout)
9475 g_source_remove (completion->priv->completion_timeout);
9477 if (!gtk_entry_get_text (GTK_ENTRY (entry)))
9480 /* no need to normalize for this test */
9481 if (completion->priv->minimum_key_length > 0 &&
9482 strcmp ("", gtk_entry_get_text (GTK_ENTRY (entry))) == 0)
9484 if (gtk_widget_get_visible (completion->priv->popup_window))
9485 _gtk_entry_completion_popdown (completion);
9489 device = gtk_get_current_event_device ();
9491 if (device && device->source == GDK_SOURCE_KEYBOARD)
9492 device = gdk_device_get_associated_device (device);
9495 priv->completion_device = device;
9497 completion->priv->completion_timeout =
9498 gdk_threads_add_timeout (COMPLETION_TIMEOUT,
9499 gtk_entry_completion_timeout,
9504 check_completion_callback (GtkEntryCompletion *completion)
9506 completion->priv->check_completion_idle = NULL;
9508 gtk_entry_completion_complete (completion);
9509 gtk_entry_completion_insert_prefix (completion);
9515 clear_completion_callback (GtkEntry *entry,
9518 if (pspec->name == I_("cursor-position") ||
9519 pspec->name == I_("selection-bound"))
9521 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
9523 completion->priv->has_completion = FALSE;
9528 accept_completion_callback (GtkEntry *entry)
9530 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
9532 if (completion->priv->has_completion)
9533 gtk_editable_set_position (GTK_EDITABLE (entry),
9534 gtk_entry_buffer_get_length (get_buffer (entry)));
9540 completion_insert_text_callback (GtkEntry *entry,
9544 GtkEntryCompletion *completion)
9546 /* idle to update the selection based on the file list */
9547 if (completion->priv->check_completion_idle == NULL)
9549 completion->priv->check_completion_idle = g_idle_source_new ();
9550 g_source_set_priority (completion->priv->check_completion_idle, G_PRIORITY_HIGH);
9551 g_source_set_closure (completion->priv->check_completion_idle,
9552 g_cclosure_new_object (G_CALLBACK (check_completion_callback),
9553 G_OBJECT (completion)));
9554 g_source_attach (completion->priv->check_completion_idle, NULL);
9559 completion_changed (GtkEntryCompletion *completion,
9563 GtkEntry *entry = GTK_ENTRY (data);
9565 if (pspec->name == I_("popup-completion") ||
9566 pspec->name == I_("inline-completion"))
9568 disconnect_completion_signals (entry, completion);
9569 connect_completion_signals (entry, completion);
9574 disconnect_completion_signals (GtkEntry *entry,
9575 GtkEntryCompletion *completion)
9577 g_signal_handlers_disconnect_by_func (completion,
9578 G_CALLBACK (completion_changed), entry);
9579 if (completion->priv->changed_id > 0 &&
9580 g_signal_handler_is_connected (entry, completion->priv->changed_id))
9582 g_signal_handler_disconnect (entry, completion->priv->changed_id);
9583 completion->priv->changed_id = 0;
9585 g_signal_handlers_disconnect_by_func (entry,
9586 G_CALLBACK (gtk_entry_completion_key_press), completion);
9587 if (completion->priv->insert_text_id > 0 &&
9588 g_signal_handler_is_connected (entry, completion->priv->insert_text_id))
9590 g_signal_handler_disconnect (entry, completion->priv->insert_text_id);
9591 completion->priv->insert_text_id = 0;
9593 g_signal_handlers_disconnect_by_func (entry,
9594 G_CALLBACK (completion_insert_text_callback), completion);
9595 g_signal_handlers_disconnect_by_func (entry,
9596 G_CALLBACK (clear_completion_callback), completion);
9597 g_signal_handlers_disconnect_by_func (entry,
9598 G_CALLBACK (accept_completion_callback), completion);
9602 connect_completion_signals (GtkEntry *entry,
9603 GtkEntryCompletion *completion)
9605 if (completion->priv->popup_completion)
9607 completion->priv->changed_id =
9608 g_signal_connect (entry, "changed",
9609 G_CALLBACK (gtk_entry_completion_changed), completion);
9610 g_signal_connect (entry, "key-press-event",
9611 G_CALLBACK (gtk_entry_completion_key_press), completion);
9614 if (completion->priv->inline_completion)
9616 completion->priv->insert_text_id =
9617 g_signal_connect (entry, "insert-text",
9618 G_CALLBACK (completion_insert_text_callback), completion);
9619 g_signal_connect (entry, "notify",
9620 G_CALLBACK (clear_completion_callback), completion);
9621 g_signal_connect (entry, "activate",
9622 G_CALLBACK (accept_completion_callback), completion);
9623 g_signal_connect (entry, "focus-out-event",
9624 G_CALLBACK (accept_completion_callback), completion);
9627 g_signal_connect (completion, "notify",
9628 G_CALLBACK (completion_changed), entry);
9632 * gtk_entry_set_completion:
9633 * @entry: A #GtkEntry
9634 * @completion: (allow-none): The #GtkEntryCompletion or %NULL
9636 * Sets @completion to be the auxiliary completion object to use with @entry.
9637 * All further configuration of the completion mechanism is done on
9638 * @completion using the #GtkEntryCompletion API. Completion is disabled if
9639 * @completion is set to %NULL.
9644 gtk_entry_set_completion (GtkEntry *entry,
9645 GtkEntryCompletion *completion)
9647 GtkEntryCompletion *old;
9649 g_return_if_fail (GTK_IS_ENTRY (entry));
9650 g_return_if_fail (!completion || GTK_IS_ENTRY_COMPLETION (completion));
9652 old = gtk_entry_get_completion (entry);
9654 if (old == completion)
9659 if (old->priv->completion_timeout)
9661 g_source_remove (old->priv->completion_timeout);
9662 old->priv->completion_timeout = 0;
9665 if (gtk_widget_get_mapped (old->priv->popup_window))
9666 _gtk_entry_completion_popdown (old);
9668 disconnect_completion_signals (entry, old);
9669 old->priv->entry = NULL;
9671 g_object_unref (old);
9676 g_object_set_data (G_OBJECT (entry), I_(GTK_ENTRY_COMPLETION_KEY), NULL);
9680 /* hook into the entry */
9681 g_object_ref (completion);
9683 connect_completion_signals (entry, completion);
9684 completion->priv->entry = GTK_WIDGET (entry);
9685 g_object_set_data (G_OBJECT (entry), I_(GTK_ENTRY_COMPLETION_KEY), completion);
9689 * gtk_entry_get_completion:
9690 * @entry: A #GtkEntry
9692 * Returns the auxiliary completion object currently in use by @entry.
9694 * Return value: (transfer none): The auxiliary completion object currently
9699 GtkEntryCompletion *
9700 gtk_entry_get_completion (GtkEntry *entry)
9702 GtkEntryCompletion *completion;
9704 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
9706 completion = GTK_ENTRY_COMPLETION (g_object_get_data (G_OBJECT (entry),
9707 GTK_ENTRY_COMPLETION_KEY));
9713 * gtk_entry_set_cursor_hadjustment:
9714 * @entry: a #GtkEntry
9715 * @adjustment: an adjustment which should be adjusted when the cursor
9716 * is moved, or %NULL
9718 * Hooks up an adjustment to the cursor position in an entry, so that when
9719 * the cursor is moved, the adjustment is scrolled to show that position.
9720 * See gtk_scrolled_window_get_hadjustment() for a typical way of obtaining
9723 * The adjustment has to be in pixel units and in the same coordinate system
9729 gtk_entry_set_cursor_hadjustment (GtkEntry *entry,
9730 GtkAdjustment *adjustment)
9732 g_return_if_fail (GTK_IS_ENTRY (entry));
9734 g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
9737 g_object_ref (adjustment);
9739 g_object_set_qdata_full (G_OBJECT (entry),
9740 quark_cursor_hadjustment,
9746 * gtk_entry_get_cursor_hadjustment:
9747 * @entry: a #GtkEntry
9749 * Retrieves the horizontal cursor adjustment for the entry.
9750 * See gtk_entry_set_cursor_hadjustment().
9752 * Return value: (transfer none): the horizontal cursor adjustment, or %NULL
9753 * if none has been set.
9758 gtk_entry_get_cursor_hadjustment (GtkEntry *entry)
9760 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
9762 return g_object_get_qdata (G_OBJECT (entry), quark_cursor_hadjustment);
9766 * gtk_entry_set_progress_fraction:
9767 * @entry: a #GtkEntry
9768 * @fraction: fraction of the task that's been completed
9770 * Causes the entry's progress indicator to "fill in" the given
9771 * fraction of the bar. The fraction should be between 0.0 and 1.0,
9777 gtk_entry_set_progress_fraction (GtkEntry *entry,
9781 GtkEntryPrivate *private;
9782 gdouble old_fraction;
9783 gint x, y, width, height;
9784 gint old_x, old_y, old_width, old_height;
9786 g_return_if_fail (GTK_IS_ENTRY (entry));
9788 widget = GTK_WIDGET (entry);
9789 private = GTK_ENTRY_GET_PRIVATE (entry);
9791 if (private->progress_pulse_mode)
9794 old_fraction = private->progress_fraction;
9796 if (gtk_widget_is_drawable (widget))
9797 get_progress_area (widget, &old_x, &old_y, &old_width, &old_height);
9799 fraction = CLAMP (fraction, 0.0, 1.0);
9801 private->progress_fraction = fraction;
9802 private->progress_pulse_mode = FALSE;
9803 private->progress_pulse_current = 0.0;
9805 if (gtk_widget_is_drawable (widget))
9807 get_progress_area (widget, &x, &y, &width, &height);
9809 if ((x != old_x) || (y != old_y) || (width != old_width) || (height != old_height))
9810 gtk_widget_queue_draw (widget);
9813 if (fraction != old_fraction)
9814 g_object_notify (G_OBJECT (entry), "progress-fraction");
9818 * gtk_entry_get_progress_fraction:
9819 * @entry: a #GtkEntry
9821 * Returns the current fraction of the task that's been completed.
9822 * See gtk_entry_set_progress_fraction().
9824 * Return value: a fraction from 0.0 to 1.0
9829 gtk_entry_get_progress_fraction (GtkEntry *entry)
9831 GtkEntryPrivate *private;
9833 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
9835 private = GTK_ENTRY_GET_PRIVATE (entry);
9837 return private->progress_fraction;
9841 * gtk_entry_set_progress_pulse_step:
9842 * @entry: a #GtkEntry
9843 * @fraction: fraction between 0.0 and 1.0
9845 * Sets the fraction of total entry width to move the progress
9846 * bouncing block for each call to gtk_entry_progress_pulse().
9851 gtk_entry_set_progress_pulse_step (GtkEntry *entry,
9854 GtkEntryPrivate *private;
9856 g_return_if_fail (GTK_IS_ENTRY (entry));
9858 private = GTK_ENTRY_GET_PRIVATE (entry);
9860 fraction = CLAMP (fraction, 0.0, 1.0);
9862 if (fraction != private->progress_pulse_fraction)
9864 private->progress_pulse_fraction = fraction;
9866 gtk_widget_queue_draw (GTK_WIDGET (entry));
9868 g_object_notify (G_OBJECT (entry), "progress-pulse-step");
9873 * gtk_entry_get_progress_pulse_step:
9874 * @entry: a #GtkEntry
9876 * Retrieves the pulse step set with gtk_entry_set_progress_pulse_step().
9878 * Return value: a fraction from 0.0 to 1.0
9883 gtk_entry_get_progress_pulse_step (GtkEntry *entry)
9885 GtkEntryPrivate *private;
9887 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
9889 private = GTK_ENTRY_GET_PRIVATE (entry);
9891 return private->progress_pulse_fraction;
9895 * gtk_entry_progress_pulse:
9896 * @entry: a #GtkEntry
9898 * Indicates that some progress is made, but you don't know how much.
9899 * Causes the entry's progress indicator to enter "activity mode,"
9900 * where a block bounces back and forth. Each call to
9901 * gtk_entry_progress_pulse() causes the block to move by a little bit
9902 * (the amount of movement per pulse is determined by
9903 * gtk_entry_set_progress_pulse_step()).
9908 gtk_entry_progress_pulse (GtkEntry *entry)
9910 GtkEntryPrivate *private;
9912 g_return_if_fail (GTK_IS_ENTRY (entry));
9914 private = GTK_ENTRY_GET_PRIVATE (entry);
9916 if (private->progress_pulse_mode)
9918 if (private->progress_pulse_way_back)
9920 private->progress_pulse_current -= private->progress_pulse_fraction;
9922 if (private->progress_pulse_current < 0.0)
9924 private->progress_pulse_current = 0.0;
9925 private->progress_pulse_way_back = FALSE;
9930 private->progress_pulse_current += private->progress_pulse_fraction;
9932 if (private->progress_pulse_current > 1.0 - private->progress_pulse_fraction)
9934 private->progress_pulse_current = 1.0 - private->progress_pulse_fraction;
9935 private->progress_pulse_way_back = TRUE;
9941 private->progress_fraction = 0.0;
9942 private->progress_pulse_mode = TRUE;
9943 private->progress_pulse_way_back = FALSE;
9944 private->progress_pulse_current = 0.0;
9947 gtk_widget_queue_draw (GTK_WIDGET (entry));
9950 /* Caps Lock warning for password entries */
9953 show_capslock_feedback (GtkEntry *entry,
9956 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
9958 if (gtk_entry_get_icon_storage_type (entry, GTK_ENTRY_ICON_SECONDARY) == GTK_IMAGE_EMPTY)
9960 gtk_entry_set_icon_from_stock (entry, GTK_ENTRY_ICON_SECONDARY, GTK_STOCK_CAPS_LOCK_WARNING);
9961 gtk_entry_set_icon_activatable (entry, GTK_ENTRY_ICON_SECONDARY, FALSE);
9962 priv->caps_lock_warning_shown = TRUE;
9965 if (priv->caps_lock_warning_shown)
9966 gtk_entry_set_icon_tooltip_text (entry, GTK_ENTRY_ICON_SECONDARY, text);
9968 g_warning ("Can't show Caps Lock warning, since secondary icon is set");
9972 remove_capslock_feedback (GtkEntry *entry)
9974 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
9976 if (priv->caps_lock_warning_shown)
9978 gtk_entry_set_icon_from_stock (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
9979 priv->caps_lock_warning_shown = FALSE;
9984 keymap_state_changed (GdkKeymap *keymap,
9987 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
9990 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL && priv->caps_lock_warning)
9992 if (gdk_keymap_get_num_lock_state (keymap)
9993 && gdk_keymap_get_caps_lock_state (keymap))
9994 text = _("Caps Lock and Num Lock are on");
9995 else if (gdk_keymap_get_num_lock_state (keymap))
9996 text = _("Num Lock is on");
9997 else if (gdk_keymap_get_caps_lock_state (keymap))
9998 text = _("Caps Lock is on");
10002 show_capslock_feedback (entry, text);
10004 remove_capslock_feedback (entry);