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"
72 * @Short_description: A single line text entry field
74 * @See_also: #GtkTextView, #GtkEntryCompletion
76 * The #GtkEntry widget is a single line text entry
77 * widget. A fairly large set of key bindings are supported
78 * by default. If the entered text is longer than the allocation
79 * of the widget, the widget will scroll so that the cursor
80 * position is visible.
82 * When using an entry for passwords and other sensitive information,
83 * it can be put into "password mode" using gtk_entry_set_visibility().
84 * In this mode, entered text is displayed using a 'invisible' character.
85 * By default, GTK+ picks the best invisible character that is available
86 * in the current font, but it can be changed with
87 * gtk_entry_set_invisible_char(). Since 2.16, GTK+ displays a warning
88 * when Caps Lock or input methods might interfere with entering text in
89 * a password entry. The warning can be turned off with the
90 * #GtkEntry:caps-lock-warning property.
92 * Since 2.16, GtkEntry has the ability to display progress or activity
93 * information behind the text. To make an entry display such information,
94 * use gtk_entry_set_progress_fraction() or gtk_entry_set_progress_pulse_step().
96 * Additionally, GtkEntry can show icons at either side of the entry. These
97 * icons can be activatable by clicking, can be set up as drag source and
98 * can have tooltips. To add an icon, use gtk_entry_set_icon_from_gicon() or
99 * one of the various other functions that set an icon from a stock id, an
100 * icon name or a pixbuf. To trigger an action when the user clicks an icon,
101 * connect to the #GtkEntry::icon-press signal. To allow DND operations
102 * from an icon, use gtk_entry_set_icon_drag_source(). To set a tooltip on
103 * an icon, use gtk_entry_set_icon_tooltip_text() or the corresponding function
106 * Note that functionality or information that is only available by clicking
107 * on an icon in an entry may not be accessible at all to users which are not
108 * able to use a mouse or other pointing device. It is therefore recommended
109 * that any such functionality should also be available by other means, e.g.
110 * via the context menu of the entry.
114 #define GTK_ENTRY_COMPLETION_KEY "gtk-entry-completion-key"
116 #define MIN_ENTRY_WIDTH 150
117 #define DRAW_TIMEOUT 20
118 #define COMPLETION_TIMEOUT 300
119 #define PASSWORD_HINT_MAX 8
123 #define IS_VALID_ICON_POSITION(pos) \
124 ((pos) == GTK_ENTRY_ICON_PRIMARY || \
125 (pos) == GTK_ENTRY_ICON_SECONDARY)
127 static const GtkBorder default_inner_border = { 2, 2, 2, 2 };
128 static GQuark quark_inner_border = 0;
129 static GQuark quark_password_hint = 0;
130 static GQuark quark_cursor_hadjustment = 0;
131 static GQuark quark_capslock_feedback = 0;
133 typedef struct _EntryIconInfo EntryIconInfo;
134 typedef struct _GtkEntryPasswordHint GtkEntryPasswordHint;
135 typedef struct _GtkEntryCapslockFeedback GtkEntryCapslockFeedback;
137 struct _GtkEntryPrivate
139 EntryIconInfo *icons[MAX_ICONS];
141 GtkEntryBuffer *buffer;
142 GtkIMContext *im_context;
143 GtkShadowType shadow_type;
144 GtkWidget *popup_menu;
146 GdkDevice *completion_device;
147 GdkWindow *text_area;
149 PangoLayout *cached_layout;
153 gdouble progress_fraction;
154 gdouble progress_pulse_fraction;
155 gdouble progress_pulse_current;
159 gint ascent; /* font ascent in pango units */
161 gint descent; /* font descent in pango units */
162 gint dnd_position; /* In chars, -1 == no DND cursor */
168 gint selection_bound;
174 gunichar invisible_char;
177 guint blink_time; /* time in msec the cursor has blinked since last user event */
179 guint recompute_idle;
181 guint16 x_text_size; /* allocated size, in bytes */
182 guint16 x_n_bytes; /* length in use, in bytes */
184 guint16 preedit_length; /* length of preedit string, in bytes */
185 guint16 preedit_cursor; /* offset of cursor within preedit string, in chars */
189 guint overwrite_mode : 1;
192 guint activates_default : 1;
193 guint cache_includes_preedit : 1;
194 guint caps_lock_warning : 1;
195 guint caps_lock_warning_shown : 1;
196 guint change_count : 8;
197 guint cursor_visible : 1;
198 guint editing_canceled : 1; /* Only used by GtkCellRendererText */
200 guint in_click : 1; /* Flag so we don't select all when clicking in entry to focus in */
201 guint is_cell_renderer : 1;
202 guint invisible_char_set : 1;
203 guint interior_focus : 1;
204 guint mouse_cursor_obscured : 1;
205 guint need_im_reset : 1;
206 guint progress_pulse_mode : 1;
207 guint progress_pulse_way_back : 1;
208 guint real_changed : 1;
209 guint resolved_dir : 4; /* PangoDirection */
210 guint select_words : 1;
211 guint select_lines : 1;
212 guint truncate_multiline : 1;
215 struct _EntryIconInfo
219 guint insensitive : 1;
220 guint nonactivatable : 1;
225 GtkImageType storage_type;
231 GtkTargetList *target_list;
232 GdkDragAction actions;
235 struct _GtkEntryPasswordHint
237 gint position; /* Position (in text) of the last password hint */
238 guint source_id; /* Timeout source id */
241 struct _GtkEntryCapslockFeedback
268 PROP_CURSOR_POSITION,
269 PROP_SELECTION_BOUND,
276 PROP_ACTIVATES_DEFAULT,
281 PROP_TRUNCATE_MULTILINE,
285 PROP_INVISIBLE_CHAR_SET,
286 PROP_CAPS_LOCK_WARNING,
287 PROP_PROGRESS_FRACTION,
288 PROP_PROGRESS_PULSE_STEP,
290 PROP_PIXBUF_SECONDARY,
292 PROP_STOCK_SECONDARY,
293 PROP_ICON_NAME_PRIMARY,
294 PROP_ICON_NAME_SECONDARY,
296 PROP_GICON_SECONDARY,
297 PROP_STORAGE_TYPE_PRIMARY,
298 PROP_STORAGE_TYPE_SECONDARY,
299 PROP_ACTIVATABLE_PRIMARY,
300 PROP_ACTIVATABLE_SECONDARY,
301 PROP_SENSITIVE_PRIMARY,
302 PROP_SENSITIVE_SECONDARY,
303 PROP_TOOLTIP_TEXT_PRIMARY,
304 PROP_TOOLTIP_TEXT_SECONDARY,
305 PROP_TOOLTIP_MARKUP_PRIMARY,
306 PROP_TOOLTIP_MARKUP_SECONDARY,
308 PROP_EDITING_CANCELED
311 static guint signals[LAST_SIGNAL] = { 0 };
320 DISPLAY_NORMAL, /* The entry text is being shown */
321 DISPLAY_INVISIBLE, /* In invisible mode, text replaced by (eg) bullets */
322 DISPLAY_BLANK /* In invisible mode, nothing shown at all */
327 static void gtk_entry_editable_init (GtkEditableInterface *iface);
328 static void gtk_entry_cell_editable_init (GtkCellEditableIface *iface);
329 static void gtk_entry_set_property (GObject *object,
333 static void gtk_entry_get_property (GObject *object,
337 static void gtk_entry_finalize (GObject *object);
338 static void gtk_entry_dispose (GObject *object);
342 static void gtk_entry_destroy (GtkWidget *widget);
343 static void gtk_entry_realize (GtkWidget *widget);
344 static void gtk_entry_unrealize (GtkWidget *widget);
345 static void gtk_entry_map (GtkWidget *widget);
346 static void gtk_entry_unmap (GtkWidget *widget);
347 static void gtk_entry_get_preferred_width (GtkWidget *widget,
350 static void gtk_entry_get_preferred_height (GtkWidget *widget,
353 static void gtk_entry_size_allocate (GtkWidget *widget,
354 GtkAllocation *allocation);
355 static void gtk_entry_draw_frame (GtkWidget *widget,
357 static void gtk_entry_draw_progress (GtkWidget *widget,
359 static gint gtk_entry_draw (GtkWidget *widget,
361 static gint gtk_entry_button_press (GtkWidget *widget,
362 GdkEventButton *event);
363 static gint gtk_entry_button_release (GtkWidget *widget,
364 GdkEventButton *event);
365 static gint gtk_entry_enter_notify (GtkWidget *widget,
366 GdkEventCrossing *event);
367 static gint gtk_entry_leave_notify (GtkWidget *widget,
368 GdkEventCrossing *event);
369 static gint gtk_entry_motion_notify (GtkWidget *widget,
370 GdkEventMotion *event);
371 static gint gtk_entry_key_press (GtkWidget *widget,
373 static gint gtk_entry_key_release (GtkWidget *widget,
375 static gint gtk_entry_focus_in (GtkWidget *widget,
376 GdkEventFocus *event);
377 static gint gtk_entry_focus_out (GtkWidget *widget,
378 GdkEventFocus *event);
379 static void gtk_entry_grab_focus (GtkWidget *widget);
380 static void gtk_entry_style_set (GtkWidget *widget,
381 GtkStyle *previous_style);
382 static gboolean gtk_entry_query_tooltip (GtkWidget *widget,
385 gboolean keyboard_tip,
386 GtkTooltip *tooltip);
387 static void gtk_entry_direction_changed (GtkWidget *widget,
388 GtkTextDirection previous_dir);
389 static void gtk_entry_state_changed (GtkWidget *widget,
390 GtkStateType previous_state);
391 static void gtk_entry_screen_changed (GtkWidget *widget,
392 GdkScreen *old_screen);
394 static gboolean gtk_entry_drag_drop (GtkWidget *widget,
395 GdkDragContext *context,
399 static gboolean gtk_entry_drag_motion (GtkWidget *widget,
400 GdkDragContext *context,
404 static void gtk_entry_drag_leave (GtkWidget *widget,
405 GdkDragContext *context,
407 static void gtk_entry_drag_data_received (GtkWidget *widget,
408 GdkDragContext *context,
411 GtkSelectionData *selection_data,
414 static void gtk_entry_drag_data_get (GtkWidget *widget,
415 GdkDragContext *context,
416 GtkSelectionData *selection_data,
419 static void gtk_entry_drag_data_delete (GtkWidget *widget,
420 GdkDragContext *context);
421 static void gtk_entry_drag_begin (GtkWidget *widget,
422 GdkDragContext *context);
423 static void gtk_entry_drag_end (GtkWidget *widget,
424 GdkDragContext *context);
427 /* GtkEditable method implementations
429 static void gtk_entry_insert_text (GtkEditable *editable,
430 const gchar *new_text,
431 gint new_text_length,
433 static void gtk_entry_delete_text (GtkEditable *editable,
436 static gchar * gtk_entry_get_chars (GtkEditable *editable,
439 static void gtk_entry_real_set_position (GtkEditable *editable,
441 static gint gtk_entry_get_position (GtkEditable *editable);
442 static void gtk_entry_set_selection_bounds (GtkEditable *editable,
445 static gboolean gtk_entry_get_selection_bounds (GtkEditable *editable,
449 /* GtkCellEditable method implementations
451 static void gtk_entry_start_editing (GtkCellEditable *cell_editable,
454 /* Default signal handlers
456 static void gtk_entry_real_insert_text (GtkEditable *editable,
457 const gchar *new_text,
458 gint new_text_length,
460 static void gtk_entry_real_delete_text (GtkEditable *editable,
463 static void gtk_entry_move_cursor (GtkEntry *entry,
464 GtkMovementStep step,
466 gboolean extend_selection);
467 static void gtk_entry_insert_at_cursor (GtkEntry *entry,
469 static void gtk_entry_delete_from_cursor (GtkEntry *entry,
472 static void gtk_entry_backspace (GtkEntry *entry);
473 static void gtk_entry_cut_clipboard (GtkEntry *entry);
474 static void gtk_entry_copy_clipboard (GtkEntry *entry);
475 static void gtk_entry_paste_clipboard (GtkEntry *entry);
476 static void gtk_entry_toggle_overwrite (GtkEntry *entry);
477 static void gtk_entry_select_all (GtkEntry *entry);
478 static void gtk_entry_real_activate (GtkEntry *entry);
479 static gboolean gtk_entry_popup_menu (GtkWidget *widget);
481 static void keymap_direction_changed (GdkKeymap *keymap,
483 static void keymap_state_changed (GdkKeymap *keymap,
485 static void remove_capslock_feedback (GtkEntry *entry);
487 /* IM Context Callbacks
489 static void gtk_entry_commit_cb (GtkIMContext *context,
492 static void gtk_entry_preedit_changed_cb (GtkIMContext *context,
494 static gboolean gtk_entry_retrieve_surrounding_cb (GtkIMContext *context,
496 static gboolean gtk_entry_delete_surrounding_cb (GtkIMContext *context,
503 static void gtk_entry_enter_text (GtkEntry *entry,
505 static void gtk_entry_set_positions (GtkEntry *entry,
507 gint selection_bound);
508 static void gtk_entry_draw_text (GtkEntry *entry,
510 static void gtk_entry_draw_cursor (GtkEntry *entry,
513 static PangoLayout *gtk_entry_ensure_layout (GtkEntry *entry,
514 gboolean include_preedit);
515 static void gtk_entry_reset_layout (GtkEntry *entry);
516 static void gtk_entry_queue_draw (GtkEntry *entry);
517 static void gtk_entry_recompute (GtkEntry *entry);
518 static gint gtk_entry_find_position (GtkEntry *entry,
520 static void gtk_entry_get_cursor_locations (GtkEntry *entry,
524 static void gtk_entry_adjust_scroll (GtkEntry *entry);
525 static gint gtk_entry_move_visually (GtkEntry *editable,
528 static gint gtk_entry_move_logically (GtkEntry *entry,
531 static gint gtk_entry_move_forward_word (GtkEntry *entry,
533 gboolean allow_whitespace);
534 static gint gtk_entry_move_backward_word (GtkEntry *entry,
536 gboolean allow_whitespace);
537 static void gtk_entry_delete_whitespace (GtkEntry *entry);
538 static void gtk_entry_select_word (GtkEntry *entry);
539 static void gtk_entry_select_line (GtkEntry *entry);
540 static void gtk_entry_paste (GtkEntry *entry,
542 static void gtk_entry_update_primary_selection (GtkEntry *entry);
543 static void gtk_entry_do_popup (GtkEntry *entry,
544 GdkEventButton *event);
545 static gboolean gtk_entry_mnemonic_activate (GtkWidget *widget,
546 gboolean group_cycling);
547 static void gtk_entry_check_cursor_blink (GtkEntry *entry);
548 static void gtk_entry_pend_cursor_blink (GtkEntry *entry);
549 static void gtk_entry_reset_blink_time (GtkEntry *entry);
550 static void gtk_entry_get_text_area_size (GtkEntry *entry,
555 static void get_text_area_size (GtkEntry *entry,
560 static void get_frame_size (GtkEntry *entry,
565 static void gtk_entry_move_adjustments (GtkEntry *entry);
566 static void gtk_entry_ensure_pixbuf (GtkEntry *entry,
567 GtkEntryIconPosition icon_pos);
571 static gint gtk_entry_completion_timeout (gpointer data);
572 static gboolean gtk_entry_completion_key_press (GtkWidget *widget,
575 static void gtk_entry_completion_changed (GtkWidget *entry,
577 static gboolean check_completion_callback (GtkEntryCompletion *completion);
578 static void clear_completion_callback (GtkEntry *entry,
580 static gboolean accept_completion_callback (GtkEntry *entry);
581 static void completion_insert_text_callback (GtkEntry *entry,
585 GtkEntryCompletion *completion);
586 static void completion_changed (GtkEntryCompletion *completion,
589 static void disconnect_completion_signals (GtkEntry *entry,
590 GtkEntryCompletion *completion);
591 static void connect_completion_signals (GtkEntry *entry,
592 GtkEntryCompletion *completion);
594 static void begin_change (GtkEntry *entry);
595 static void end_change (GtkEntry *entry);
596 static void emit_changed (GtkEntry *entry);
599 static void buffer_inserted_text (GtkEntryBuffer *buffer,
604 static void buffer_deleted_text (GtkEntryBuffer *buffer,
608 static void buffer_notify_text (GtkEntryBuffer *buffer,
611 static void buffer_notify_length (GtkEntryBuffer *buffer,
614 static void buffer_notify_max_length (GtkEntryBuffer *buffer,
617 static void buffer_connect_signals (GtkEntry *entry);
618 static void buffer_disconnect_signals (GtkEntry *entry);
619 static GtkEntryBuffer *get_buffer (GtkEntry *entry);
622 G_DEFINE_TYPE_WITH_CODE (GtkEntry, gtk_entry, GTK_TYPE_WIDGET,
623 G_IMPLEMENT_INTERFACE (GTK_TYPE_EDITABLE,
624 gtk_entry_editable_init)
625 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_EDITABLE,
626 gtk_entry_cell_editable_init))
629 add_move_binding (GtkBindingSet *binding_set,
632 GtkMovementStep step,
635 g_return_if_fail ((modmask & GDK_SHIFT_MASK) == 0);
637 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
641 G_TYPE_BOOLEAN, FALSE);
643 /* Selection-extending version */
644 gtk_binding_entry_add_signal (binding_set, keyval, modmask | GDK_SHIFT_MASK,
648 G_TYPE_BOOLEAN, TRUE);
652 gtk_entry_class_init (GtkEntryClass *class)
654 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
655 GtkWidgetClass *widget_class;
656 GtkBindingSet *binding_set;
658 widget_class = (GtkWidgetClass*) class;
660 gobject_class->dispose = gtk_entry_dispose;
661 gobject_class->finalize = gtk_entry_finalize;
662 gobject_class->set_property = gtk_entry_set_property;
663 gobject_class->get_property = gtk_entry_get_property;
665 widget_class->destroy = gtk_entry_destroy;
666 widget_class->map = gtk_entry_map;
667 widget_class->unmap = gtk_entry_unmap;
668 widget_class->realize = gtk_entry_realize;
669 widget_class->unrealize = gtk_entry_unrealize;
670 widget_class->get_preferred_width = gtk_entry_get_preferred_width;
671 widget_class->get_preferred_height = gtk_entry_get_preferred_height;
672 widget_class->size_allocate = gtk_entry_size_allocate;
673 widget_class->draw = gtk_entry_draw;
674 widget_class->enter_notify_event = gtk_entry_enter_notify;
675 widget_class->leave_notify_event = gtk_entry_leave_notify;
676 widget_class->button_press_event = gtk_entry_button_press;
677 widget_class->button_release_event = gtk_entry_button_release;
678 widget_class->motion_notify_event = gtk_entry_motion_notify;
679 widget_class->key_press_event = gtk_entry_key_press;
680 widget_class->key_release_event = gtk_entry_key_release;
681 widget_class->focus_in_event = gtk_entry_focus_in;
682 widget_class->focus_out_event = gtk_entry_focus_out;
683 widget_class->grab_focus = gtk_entry_grab_focus;
684 widget_class->style_set = gtk_entry_style_set;
685 widget_class->query_tooltip = gtk_entry_query_tooltip;
686 widget_class->drag_begin = gtk_entry_drag_begin;
687 widget_class->drag_end = gtk_entry_drag_end;
688 widget_class->direction_changed = gtk_entry_direction_changed;
689 widget_class->state_changed = gtk_entry_state_changed;
690 widget_class->screen_changed = gtk_entry_screen_changed;
691 widget_class->mnemonic_activate = gtk_entry_mnemonic_activate;
693 widget_class->drag_drop = gtk_entry_drag_drop;
694 widget_class->drag_motion = gtk_entry_drag_motion;
695 widget_class->drag_leave = gtk_entry_drag_leave;
696 widget_class->drag_data_received = gtk_entry_drag_data_received;
697 widget_class->drag_data_get = gtk_entry_drag_data_get;
698 widget_class->drag_data_delete = gtk_entry_drag_data_delete;
700 widget_class->popup_menu = gtk_entry_popup_menu;
702 class->move_cursor = gtk_entry_move_cursor;
703 class->insert_at_cursor = gtk_entry_insert_at_cursor;
704 class->delete_from_cursor = gtk_entry_delete_from_cursor;
705 class->backspace = gtk_entry_backspace;
706 class->cut_clipboard = gtk_entry_cut_clipboard;
707 class->copy_clipboard = gtk_entry_copy_clipboard;
708 class->paste_clipboard = gtk_entry_paste_clipboard;
709 class->toggle_overwrite = gtk_entry_toggle_overwrite;
710 class->activate = gtk_entry_real_activate;
711 class->get_text_area_size = gtk_entry_get_text_area_size;
713 quark_inner_border = g_quark_from_static_string ("gtk-entry-inner-border");
714 quark_password_hint = g_quark_from_static_string ("gtk-entry-password-hint");
715 quark_cursor_hadjustment = g_quark_from_static_string ("gtk-hadjustment");
716 quark_capslock_feedback = g_quark_from_static_string ("gtk-entry-capslock-feedback");
718 g_object_class_override_property (gobject_class,
719 PROP_EDITING_CANCELED,
722 g_object_class_install_property (gobject_class,
724 g_param_spec_object ("buffer",
726 P_("Text buffer object which actually stores entry text"),
727 GTK_TYPE_ENTRY_BUFFER,
728 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT));
730 g_object_class_install_property (gobject_class,
731 PROP_CURSOR_POSITION,
732 g_param_spec_int ("cursor-position",
733 P_("Cursor Position"),
734 P_("The current position of the insertion cursor in chars"),
736 GTK_ENTRY_BUFFER_MAX_SIZE,
738 GTK_PARAM_READABLE));
740 g_object_class_install_property (gobject_class,
741 PROP_SELECTION_BOUND,
742 g_param_spec_int ("selection-bound",
743 P_("Selection Bound"),
744 P_("The position of the opposite end of the selection from the cursor in chars"),
746 GTK_ENTRY_BUFFER_MAX_SIZE,
748 GTK_PARAM_READABLE));
750 g_object_class_install_property (gobject_class,
752 g_param_spec_boolean ("editable",
754 P_("Whether the entry contents can be edited"),
756 GTK_PARAM_READWRITE));
758 g_object_class_install_property (gobject_class,
760 g_param_spec_int ("max-length",
761 P_("Maximum length"),
762 P_("Maximum number of characters for this entry. Zero if no maximum"),
764 GTK_ENTRY_BUFFER_MAX_SIZE,
766 GTK_PARAM_READWRITE));
767 g_object_class_install_property (gobject_class,
769 g_param_spec_boolean ("visibility",
771 P_("FALSE displays the \"invisible char\" instead of the actual text (password mode)"),
773 GTK_PARAM_READWRITE));
775 g_object_class_install_property (gobject_class,
777 g_param_spec_boolean ("has-frame",
779 P_("FALSE removes outside bevel from entry"),
781 GTK_PARAM_READWRITE));
783 g_object_class_install_property (gobject_class,
785 g_param_spec_boxed ("inner-border",
787 P_("Border between text and frame. Overrides the inner-border style property"),
789 GTK_PARAM_READWRITE));
791 g_object_class_install_property (gobject_class,
793 g_param_spec_unichar ("invisible-char",
794 P_("Invisible character"),
795 P_("The character to use when masking entry contents (in \"password mode\")"),
797 GTK_PARAM_READWRITE));
799 g_object_class_install_property (gobject_class,
800 PROP_ACTIVATES_DEFAULT,
801 g_param_spec_boolean ("activates-default",
802 P_("Activates default"),
803 P_("Whether to activate the default widget (such as the default button in a dialog) when Enter is pressed"),
805 GTK_PARAM_READWRITE));
806 g_object_class_install_property (gobject_class,
808 g_param_spec_int ("width-chars",
809 P_("Width in chars"),
810 P_("Number of characters to leave space for in the entry"),
814 GTK_PARAM_READWRITE));
816 g_object_class_install_property (gobject_class,
818 g_param_spec_int ("scroll-offset",
820 P_("Number of pixels of the entry scrolled off the screen to the left"),
824 GTK_PARAM_READABLE));
826 g_object_class_install_property (gobject_class,
828 g_param_spec_string ("text",
830 P_("The contents of the entry"),
832 GTK_PARAM_READWRITE));
837 * The horizontal alignment, from 0 (left) to 1 (right).
838 * Reversed for RTL layouts.
842 g_object_class_install_property (gobject_class,
844 g_param_spec_float ("xalign",
846 P_("The horizontal alignment, from 0 (left) to 1 (right). Reversed for RTL layouts."),
850 GTK_PARAM_READWRITE));
853 * GtkEntry:truncate-multiline:
855 * When %TRUE, pasted multi-line text is truncated to the first line.
859 g_object_class_install_property (gobject_class,
860 PROP_TRUNCATE_MULTILINE,
861 g_param_spec_boolean ("truncate-multiline",
862 P_("Truncate multiline"),
863 P_("Whether to truncate multiline pastes to one line."),
865 GTK_PARAM_READWRITE));
868 * GtkEntry:shadow-type:
870 * Which kind of shadow to draw around the entry when
871 * #GtkEntry:has-frame is set to %TRUE.
875 g_object_class_install_property (gobject_class,
877 g_param_spec_enum ("shadow-type",
879 P_("Which kind of shadow to draw around the entry when has-frame is set"),
880 GTK_TYPE_SHADOW_TYPE,
882 GTK_PARAM_READWRITE));
885 * GtkEntry:overwrite-mode:
887 * If text is overwritten when typing in the #GtkEntry.
891 g_object_class_install_property (gobject_class,
893 g_param_spec_boolean ("overwrite-mode",
894 P_("Overwrite mode"),
895 P_("Whether new text overwrites existing text"),
897 GTK_PARAM_READWRITE));
900 * GtkEntry:text-length:
902 * The length of the text in the #GtkEntry.
906 g_object_class_install_property (gobject_class,
908 g_param_spec_uint ("text-length",
910 P_("Length of the text currently in the entry"),
914 GTK_PARAM_READABLE));
916 * GtkEntry:invisible-char-set:
918 * Whether the invisible char has been set for the #GtkEntry.
922 g_object_class_install_property (gobject_class,
923 PROP_INVISIBLE_CHAR_SET,
924 g_param_spec_boolean ("invisible-char-set",
925 P_("Invisible character set"),
926 P_("Whether the invisible character has been set"),
928 GTK_PARAM_READWRITE));
931 * GtkEntry:caps-lock-warning
933 * Whether password entries will show a warning when Caps Lock is on.
935 * Note that the warning is shown using a secondary icon, and thus
936 * does not work if you are using the secondary icon position for some
941 g_object_class_install_property (gobject_class,
942 PROP_CAPS_LOCK_WARNING,
943 g_param_spec_boolean ("caps-lock-warning",
944 P_("Caps Lock warning"),
945 P_("Whether password entries will show a warning when Caps Lock is on"),
947 GTK_PARAM_READWRITE));
950 * GtkEntry:progress-fraction:
952 * The current fraction of the task that's been completed.
956 g_object_class_install_property (gobject_class,
957 PROP_PROGRESS_FRACTION,
958 g_param_spec_double ("progress-fraction",
959 P_("Progress Fraction"),
960 P_("The current fraction of the task that's been completed"),
964 GTK_PARAM_READWRITE));
967 * GtkEntry:progress-pulse-step:
969 * The fraction of total entry width to move the progress
970 * bouncing block for each call to gtk_entry_progress_pulse().
974 g_object_class_install_property (gobject_class,
975 PROP_PROGRESS_PULSE_STEP,
976 g_param_spec_double ("progress-pulse-step",
977 P_("Progress Pulse Step"),
978 P_("The fraction of total entry width to move the progress bouncing block for each call to gtk_entry_progress_pulse()"),
982 GTK_PARAM_READWRITE));
985 * GtkEntry:primary-icon-pixbuf:
987 * A pixbuf to use as the primary icon for the entry.
991 g_object_class_install_property (gobject_class,
993 g_param_spec_object ("primary-icon-pixbuf",
994 P_("Primary pixbuf"),
995 P_("Primary pixbuf for the entry"),
997 GTK_PARAM_READWRITE));
1000 * GtkEntry:secondary-icon-pixbuf:
1002 * An pixbuf to use as the secondary icon for the entry.
1006 g_object_class_install_property (gobject_class,
1007 PROP_PIXBUF_SECONDARY,
1008 g_param_spec_object ("secondary-icon-pixbuf",
1009 P_("Secondary pixbuf"),
1010 P_("Secondary pixbuf for the entry"),
1012 GTK_PARAM_READWRITE));
1015 * GtkEntry:primary-icon-stock:
1017 * The stock id to use for the primary icon for the entry.
1021 g_object_class_install_property (gobject_class,
1023 g_param_spec_string ("primary-icon-stock",
1024 P_("Primary stock ID"),
1025 P_("Stock ID for primary icon"),
1027 GTK_PARAM_READWRITE));
1030 * GtkEntry:secondary-icon-stock:
1032 * The stock id to use for the secondary icon for the entry.
1036 g_object_class_install_property (gobject_class,
1037 PROP_STOCK_SECONDARY,
1038 g_param_spec_string ("secondary-icon-stock",
1039 P_("Secondary stock ID"),
1040 P_("Stock ID for secondary icon"),
1042 GTK_PARAM_READWRITE));
1045 * GtkEntry:primary-icon-name:
1047 * The icon name to use for the primary icon for the entry.
1051 g_object_class_install_property (gobject_class,
1052 PROP_ICON_NAME_PRIMARY,
1053 g_param_spec_string ("primary-icon-name",
1054 P_("Primary icon name"),
1055 P_("Icon name for primary icon"),
1057 GTK_PARAM_READWRITE));
1060 * GtkEntry:secondary-icon-name:
1062 * The icon name to use for the secondary icon for the entry.
1066 g_object_class_install_property (gobject_class,
1067 PROP_ICON_NAME_SECONDARY,
1068 g_param_spec_string ("secondary-icon-name",
1069 P_("Secondary icon name"),
1070 P_("Icon name for secondary icon"),
1072 GTK_PARAM_READWRITE));
1075 * GtkEntry:primary-icon-gicon:
1077 * The #GIcon to use for the primary icon for the entry.
1081 g_object_class_install_property (gobject_class,
1083 g_param_spec_object ("primary-icon-gicon",
1084 P_("Primary GIcon"),
1085 P_("GIcon for primary icon"),
1087 GTK_PARAM_READWRITE));
1090 * GtkEntry:secondary-icon-gicon:
1092 * The #GIcon to use for the secondary icon for the entry.
1096 g_object_class_install_property (gobject_class,
1097 PROP_GICON_SECONDARY,
1098 g_param_spec_object ("secondary-icon-gicon",
1099 P_("Secondary GIcon"),
1100 P_("GIcon for secondary icon"),
1102 GTK_PARAM_READWRITE));
1105 * GtkEntry:primary-icon-storage-type:
1107 * The representation which is used for the primary icon of the entry.
1111 g_object_class_install_property (gobject_class,
1112 PROP_STORAGE_TYPE_PRIMARY,
1113 g_param_spec_enum ("primary-icon-storage-type",
1114 P_("Primary storage type"),
1115 P_("The representation being used for primary icon"),
1116 GTK_TYPE_IMAGE_TYPE,
1118 GTK_PARAM_READABLE));
1121 * GtkEntry:secondary-icon-storage-type:
1123 * The representation which is used for the secondary icon of the entry.
1127 g_object_class_install_property (gobject_class,
1128 PROP_STORAGE_TYPE_SECONDARY,
1129 g_param_spec_enum ("secondary-icon-storage-type",
1130 P_("Secondary storage type"),
1131 P_("The representation being used for secondary icon"),
1132 GTK_TYPE_IMAGE_TYPE,
1134 GTK_PARAM_READABLE));
1137 * GtkEntry:primary-icon-activatable:
1139 * Whether the primary icon is activatable.
1141 * GTK+ emits the #GtkEntry::icon-press and #GtkEntry::icon-release
1142 * signals only on sensitive, activatable icons.
1144 * Sensitive, but non-activatable icons can be used for purely
1145 * informational purposes.
1149 g_object_class_install_property (gobject_class,
1150 PROP_ACTIVATABLE_PRIMARY,
1151 g_param_spec_boolean ("primary-icon-activatable",
1152 P_("Primary icon activatable"),
1153 P_("Whether the primary icon is activatable"),
1155 GTK_PARAM_READWRITE));
1158 * GtkEntry:secondary-icon-activatable:
1160 * Whether the secondary icon is activatable.
1162 * GTK+ emits the #GtkEntry::icon-press and #GtkEntry::icon-release
1163 * signals only on sensitive, activatable icons.
1165 * Sensitive, but non-activatable icons can be used for purely
1166 * informational purposes.
1170 g_object_class_install_property (gobject_class,
1171 PROP_ACTIVATABLE_SECONDARY,
1172 g_param_spec_boolean ("secondary-icon-activatable",
1173 P_("Secondary icon activatable"),
1174 P_("Whether the secondary icon is activatable"),
1176 GTK_PARAM_READWRITE));
1180 * GtkEntry:primary-icon-sensitive:
1182 * Whether the primary icon is sensitive.
1184 * An insensitive icon appears grayed out. GTK+ does not emit the
1185 * #GtkEntry::icon-press and #GtkEntry::icon-release signals and
1186 * does not allow DND from insensitive icons.
1188 * An icon should be set insensitive if the action that would trigger
1189 * when clicked is currently not available.
1193 g_object_class_install_property (gobject_class,
1194 PROP_SENSITIVE_PRIMARY,
1195 g_param_spec_boolean ("primary-icon-sensitive",
1196 P_("Primary icon sensitive"),
1197 P_("Whether the primary icon is sensitive"),
1199 GTK_PARAM_READWRITE));
1202 * GtkEntry:secondary-icon-sensitive:
1204 * Whether the secondary icon is sensitive.
1206 * An insensitive icon appears grayed out. GTK+ does not emit the
1207 * #GtkEntry::icon-press and #GtkEntry::icon-release signals and
1208 * does not allow DND from insensitive icons.
1210 * An icon should be set insensitive if the action that would trigger
1211 * when clicked is currently not available.
1215 g_object_class_install_property (gobject_class,
1216 PROP_SENSITIVE_SECONDARY,
1217 g_param_spec_boolean ("secondary-icon-sensitive",
1218 P_("Secondary icon sensitive"),
1219 P_("Whether the secondary icon is sensitive"),
1221 GTK_PARAM_READWRITE));
1224 * GtkEntry:primary-icon-tooltip-text:
1226 * The contents of the tooltip on the primary icon.
1228 * Also see gtk_entry_set_icon_tooltip_text().
1232 g_object_class_install_property (gobject_class,
1233 PROP_TOOLTIP_TEXT_PRIMARY,
1234 g_param_spec_string ("primary-icon-tooltip-text",
1235 P_("Primary icon tooltip text"),
1236 P_("The contents of the tooltip on the primary icon"),
1238 GTK_PARAM_READWRITE));
1241 * GtkEntry:secondary-icon-tooltip-text:
1243 * The contents of the tooltip on the secondary icon.
1245 * Also see gtk_entry_set_icon_tooltip_text().
1249 g_object_class_install_property (gobject_class,
1250 PROP_TOOLTIP_TEXT_SECONDARY,
1251 g_param_spec_string ("secondary-icon-tooltip-text",
1252 P_("Secondary icon tooltip text"),
1253 P_("The contents of the tooltip on the secondary icon"),
1255 GTK_PARAM_READWRITE));
1258 * GtkEntry:primary-icon-tooltip-markup:
1260 * The contents of the tooltip on the primary icon, which is marked up
1261 * with the <link linkend="PangoMarkupFormat">Pango text markup
1264 * Also see gtk_entry_set_icon_tooltip_markup().
1268 g_object_class_install_property (gobject_class,
1269 PROP_TOOLTIP_MARKUP_PRIMARY,
1270 g_param_spec_string ("primary-icon-tooltip-markup",
1271 P_("Primary icon tooltip markup"),
1272 P_("The contents of the tooltip on the primary icon"),
1274 GTK_PARAM_READWRITE));
1277 * GtkEntry:secondary-icon-tooltip-markup:
1279 * The contents of the tooltip on the secondary icon, which is marked up
1280 * with the <link linkend="PangoMarkupFormat">Pango text markup
1283 * Also see gtk_entry_set_icon_tooltip_markup().
1287 g_object_class_install_property (gobject_class,
1288 PROP_TOOLTIP_MARKUP_SECONDARY,
1289 g_param_spec_string ("secondary-icon-tooltip-markup",
1290 P_("Secondary icon tooltip markup"),
1291 P_("The contents of the tooltip on the secondary icon"),
1293 GTK_PARAM_READWRITE));
1296 * GtkEntry:im-module:
1298 * Which IM (input method) module should be used for this entry.
1299 * See #GtkIMContext.
1301 * Setting this to a non-%NULL value overrides the
1302 * system-wide IM module setting. See the GtkSettings
1303 * #GtkSettings:gtk-im-module property.
1307 g_object_class_install_property (gobject_class,
1309 g_param_spec_string ("im-module",
1311 P_("Which IM module should be used"),
1313 GTK_PARAM_READWRITE));
1316 * GtkEntry:icon-prelight:
1318 * The prelight style property determines whether activatable
1319 * icons prelight on mouseover.
1323 gtk_widget_class_install_style_property (widget_class,
1324 g_param_spec_boolean ("icon-prelight",
1325 P_("Icon Prelight"),
1326 P_("Whether activatable icons should prelight when hovered"),
1328 GTK_PARAM_READABLE));
1331 * GtkEntry:progress-border:
1333 * The border around the progress bar in the entry.
1337 gtk_widget_class_install_style_property (widget_class,
1338 g_param_spec_boxed ("progress-border",
1339 P_("Progress Border"),
1340 P_("Border around the progress bar"),
1342 GTK_PARAM_READABLE));
1345 * GtkEntry:invisible-char:
1347 * The invisible character is used when masking entry contents (in
1348 * \"password mode\")"). When it is not explicitly set with the
1349 * #GtkEntry::invisible-char property, GTK+ determines the character
1350 * to use from a list of possible candidates, depending on availability
1351 * in the current font.
1353 * This style property allows the theme to prepend a character
1354 * to the list of candidates.
1358 gtk_widget_class_install_style_property (widget_class,
1359 g_param_spec_unichar ("invisible-char",
1360 P_("Invisible character"),
1361 P_("The character to use when masking entry contents (in \"password mode\")"),
1363 GTK_PARAM_READABLE));
1366 * GtkEntry::populate-popup:
1367 * @entry: The entry on which the signal is emitted
1368 * @menu: the menu that is being populated
1370 * The ::populate-popup signal gets emitted before showing the
1371 * context menu of the entry.
1373 * If you need to add items to the context menu, connect
1374 * to this signal and append your menuitems to the @menu.
1376 signals[POPULATE_POPUP] =
1377 g_signal_new (I_("populate-popup"),
1378 G_OBJECT_CLASS_TYPE (gobject_class),
1380 G_STRUCT_OFFSET (GtkEntryClass, populate_popup),
1382 _gtk_marshal_VOID__OBJECT,
1386 /* Action signals */
1389 * GtkEntry::activate:
1390 * @entry: The entry on which the signal is emitted
1392 * A <link linkend="keybinding-signals">keybinding signal</link>
1393 * which gets emitted when the user activates the entry.
1395 * Applications should not connect to it, but may emit it with
1396 * g_signal_emit_by_name() if they need to control activation
1399 * The default bindings for this signal are all forms of the Enter key.
1402 g_signal_new (I_("activate"),
1403 G_OBJECT_CLASS_TYPE (gobject_class),
1404 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1405 G_STRUCT_OFFSET (GtkEntryClass, activate),
1407 _gtk_marshal_VOID__VOID,
1409 widget_class->activate_signal = signals[ACTIVATE];
1412 * GtkEntry::move-cursor:
1413 * @entry: the object which received the signal
1414 * @step: the granularity of the move, as a #GtkMovementStep
1415 * @count: the number of @step units to move
1416 * @extend_selection: %TRUE if the move should extend the selection
1418 * The ::move-cursor signal is a
1419 * <link linkend="keybinding-signals">keybinding signal</link>
1420 * which gets emitted when the user initiates a cursor movement.
1421 * If the cursor is not visible in @entry, this signal causes
1422 * the viewport to be moved instead.
1424 * Applications should not connect to it, but may emit it with
1425 * g_signal_emit_by_name() if they need to control the cursor
1428 * The default bindings for this signal come in two variants,
1429 * the variant with the Shift modifier extends the selection,
1430 * the variant without the Shift modifer does not.
1431 * There are too many key combinations to list them all here.
1433 * <listitem>Arrow keys move by individual characters/lines</listitem>
1434 * <listitem>Ctrl-arrow key combinations move by words/paragraphs</listitem>
1435 * <listitem>Home/End keys move to the ends of the buffer</listitem>
1438 signals[MOVE_CURSOR] =
1439 g_signal_new (I_("move-cursor"),
1440 G_OBJECT_CLASS_TYPE (gobject_class),
1441 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1442 G_STRUCT_OFFSET (GtkEntryClass, move_cursor),
1444 _gtk_marshal_VOID__ENUM_INT_BOOLEAN,
1446 GTK_TYPE_MOVEMENT_STEP,
1451 * GtkEntry::insert-at-cursor:
1452 * @entry: the object which received the signal
1453 * @string: the string to insert
1455 * The ::insert-at-cursor signal is a
1456 * <link linkend="keybinding-signals">keybinding signal</link>
1457 * which gets emitted when the user initiates the insertion of a
1458 * fixed string at the cursor.
1460 * This signal has no default bindings.
1462 signals[INSERT_AT_CURSOR] =
1463 g_signal_new (I_("insert-at-cursor"),
1464 G_OBJECT_CLASS_TYPE (gobject_class),
1465 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1466 G_STRUCT_OFFSET (GtkEntryClass, insert_at_cursor),
1468 _gtk_marshal_VOID__STRING,
1473 * GtkEntry::delete-from-cursor:
1474 * @entry: the object which received the signal
1475 * @type: the granularity of the deletion, as a #GtkDeleteType
1476 * @count: the number of @type units to delete
1478 * The ::delete-from-cursor signal is a
1479 * <link linkend="keybinding-signals">keybinding signal</link>
1480 * which gets emitted when the user initiates a text deletion.
1482 * If the @type is %GTK_DELETE_CHARS, GTK+ deletes the selection
1483 * if there is one, otherwise it deletes the requested number
1486 * The default bindings for this signal are
1487 * Delete for deleting a character and Ctrl-Delete for
1490 signals[DELETE_FROM_CURSOR] =
1491 g_signal_new (I_("delete-from-cursor"),
1492 G_OBJECT_CLASS_TYPE (gobject_class),
1493 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1494 G_STRUCT_OFFSET (GtkEntryClass, delete_from_cursor),
1496 _gtk_marshal_VOID__ENUM_INT,
1498 GTK_TYPE_DELETE_TYPE,
1502 * GtkEntry::backspace:
1503 * @entry: the object which received the signal
1505 * The ::backspace signal is a
1506 * <link linkend="keybinding-signals">keybinding signal</link>
1507 * which gets emitted when the user asks for it.
1509 * The default bindings for this signal are
1510 * Backspace and Shift-Backspace.
1512 signals[BACKSPACE] =
1513 g_signal_new (I_("backspace"),
1514 G_OBJECT_CLASS_TYPE (gobject_class),
1515 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1516 G_STRUCT_OFFSET (GtkEntryClass, backspace),
1518 _gtk_marshal_VOID__VOID,
1522 * GtkEntry::cut-clipboard:
1523 * @entry: the object which received the signal
1525 * The ::cut-clipboard signal is a
1526 * <link linkend="keybinding-signals">keybinding signal</link>
1527 * which gets emitted to cut the selection to the clipboard.
1529 * The default bindings for this signal are
1530 * Ctrl-x and Shift-Delete.
1532 signals[CUT_CLIPBOARD] =
1533 g_signal_new (I_("cut-clipboard"),
1534 G_OBJECT_CLASS_TYPE (gobject_class),
1535 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1536 G_STRUCT_OFFSET (GtkEntryClass, cut_clipboard),
1538 _gtk_marshal_VOID__VOID,
1542 * GtkEntry::copy-clipboard:
1543 * @entry: the object which received the signal
1545 * The ::copy-clipboard signal is a
1546 * <link linkend="keybinding-signals">keybinding signal</link>
1547 * which gets emitted to copy the selection to the clipboard.
1549 * The default bindings for this signal are
1550 * Ctrl-c and Ctrl-Insert.
1552 signals[COPY_CLIPBOARD] =
1553 g_signal_new (I_("copy-clipboard"),
1554 G_OBJECT_CLASS_TYPE (gobject_class),
1555 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1556 G_STRUCT_OFFSET (GtkEntryClass, copy_clipboard),
1558 _gtk_marshal_VOID__VOID,
1562 * GtkEntry::paste-clipboard:
1563 * @entry: the object which received the signal
1565 * The ::paste-clipboard signal is a
1566 * <link linkend="keybinding-signals">keybinding signal</link>
1567 * which gets emitted to paste the contents of the clipboard
1568 * into the text view.
1570 * The default bindings for this signal are
1571 * Ctrl-v and Shift-Insert.
1573 signals[PASTE_CLIPBOARD] =
1574 g_signal_new (I_("paste-clipboard"),
1575 G_OBJECT_CLASS_TYPE (gobject_class),
1576 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1577 G_STRUCT_OFFSET (GtkEntryClass, paste_clipboard),
1579 _gtk_marshal_VOID__VOID,
1583 * GtkEntry::toggle-overwrite:
1584 * @entry: the object which received the signal
1586 * The ::toggle-overwrite signal is a
1587 * <link linkend="keybinding-signals">keybinding signal</link>
1588 * which gets emitted to toggle the overwrite mode of the entry.
1590 * The default bindings for this signal is Insert.
1592 signals[TOGGLE_OVERWRITE] =
1593 g_signal_new (I_("toggle-overwrite"),
1594 G_OBJECT_CLASS_TYPE (gobject_class),
1595 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1596 G_STRUCT_OFFSET (GtkEntryClass, toggle_overwrite),
1598 _gtk_marshal_VOID__VOID,
1602 * GtkEntry::icon-press:
1603 * @entry: The entry on which the signal is emitted
1604 * @icon_pos: The position of the clicked icon
1605 * @event: the button press event
1607 * The ::icon-press signal is emitted when an activatable icon
1612 signals[ICON_PRESS] =
1613 g_signal_new (I_("icon-press"),
1614 G_TYPE_FROM_CLASS (gobject_class),
1618 _gtk_marshal_VOID__ENUM_BOXED,
1620 GTK_TYPE_ENTRY_ICON_POSITION,
1621 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1624 * GtkEntry::icon-release:
1625 * @entry: The entry on which the signal is emitted
1626 * @icon_pos: The position of the clicked icon
1627 * @event: the button release event
1629 * The ::icon-release signal is emitted on the button release from a
1630 * mouse click over an activatable icon.
1634 signals[ICON_RELEASE] =
1635 g_signal_new (I_("icon-release"),
1636 G_TYPE_FROM_CLASS (gobject_class),
1640 _gtk_marshal_VOID__ENUM_BOXED,
1642 GTK_TYPE_ENTRY_ICON_POSITION,
1643 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1646 * GtkEntry::preedit-changed:
1647 * @entry: the object which received the signal
1648 * @preedit: the current preedit string
1650 * If an input method is used, the typed text will not immediately
1651 * be committed to the buffer. So if you are interested in the text,
1652 * connect to this signal.
1656 signals[PREEDIT_CHANGED] =
1657 g_signal_new_class_handler (I_("preedit-changed"),
1658 G_OBJECT_CLASS_TYPE (gobject_class),
1659 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1662 _gtk_marshal_VOID__STRING,
1671 binding_set = gtk_binding_set_by_class (class);
1673 /* Moving the insertion point */
1674 add_move_binding (binding_set, GDK_KEY_Right, 0,
1675 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1677 add_move_binding (binding_set, GDK_KEY_Left, 0,
1678 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1680 add_move_binding (binding_set, GDK_KEY_KP_Right, 0,
1681 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1683 add_move_binding (binding_set, GDK_KEY_KP_Left, 0,
1684 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1686 add_move_binding (binding_set, GDK_KEY_Right, GDK_CONTROL_MASK,
1687 GTK_MOVEMENT_WORDS, 1);
1689 add_move_binding (binding_set, GDK_KEY_Left, GDK_CONTROL_MASK,
1690 GTK_MOVEMENT_WORDS, -1);
1692 add_move_binding (binding_set, GDK_KEY_KP_Right, GDK_CONTROL_MASK,
1693 GTK_MOVEMENT_WORDS, 1);
1695 add_move_binding (binding_set, GDK_KEY_KP_Left, GDK_CONTROL_MASK,
1696 GTK_MOVEMENT_WORDS, -1);
1698 add_move_binding (binding_set, GDK_KEY_Home, 0,
1699 GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
1701 add_move_binding (binding_set, GDK_KEY_End, 0,
1702 GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
1704 add_move_binding (binding_set, GDK_KEY_KP_Home, 0,
1705 GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
1707 add_move_binding (binding_set, GDK_KEY_KP_End, 0,
1708 GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
1710 add_move_binding (binding_set, GDK_KEY_Home, GDK_CONTROL_MASK,
1711 GTK_MOVEMENT_BUFFER_ENDS, -1);
1713 add_move_binding (binding_set, GDK_KEY_End, GDK_CONTROL_MASK,
1714 GTK_MOVEMENT_BUFFER_ENDS, 1);
1716 add_move_binding (binding_set, GDK_KEY_KP_Home, GDK_CONTROL_MASK,
1717 GTK_MOVEMENT_BUFFER_ENDS, -1);
1719 add_move_binding (binding_set, GDK_KEY_KP_End, GDK_CONTROL_MASK,
1720 GTK_MOVEMENT_BUFFER_ENDS, 1);
1724 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK,
1726 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1728 G_TYPE_BOOLEAN, FALSE);
1729 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK,
1731 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1733 G_TYPE_BOOLEAN, TRUE);
1735 gtk_binding_entry_add_signal (binding_set, GDK_KEY_slash, GDK_CONTROL_MASK,
1737 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1739 G_TYPE_BOOLEAN, FALSE);
1740 gtk_binding_entry_add_signal (binding_set, GDK_KEY_slash, GDK_CONTROL_MASK,
1742 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1744 G_TYPE_BOOLEAN, TRUE);
1747 gtk_binding_entry_add_signal (binding_set, GDK_KEY_backslash, GDK_CONTROL_MASK,
1749 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_VISUAL_POSITIONS,
1751 G_TYPE_BOOLEAN, FALSE);
1752 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_SHIFT_MASK | GDK_CONTROL_MASK,
1754 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_VISUAL_POSITIONS,
1756 G_TYPE_BOOLEAN, FALSE);
1760 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Return, 0,
1762 gtk_binding_entry_add_signal (binding_set, GDK_KEY_ISO_Enter, 0,
1764 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Enter, 0,
1768 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, 0,
1769 "delete-from-cursor", 2,
1770 G_TYPE_ENUM, GTK_DELETE_CHARS,
1773 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Delete, 0,
1774 "delete-from-cursor", 2,
1775 G_TYPE_ENUM, GTK_DELETE_CHARS,
1778 gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, 0,
1781 /* Make this do the same as Backspace, to help with mis-typing */
1782 gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, GDK_SHIFT_MASK,
1785 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, GDK_CONTROL_MASK,
1786 "delete-from-cursor", 2,
1787 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1790 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Delete, GDK_CONTROL_MASK,
1791 "delete-from-cursor", 2,
1792 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1795 gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, GDK_CONTROL_MASK,
1796 "delete-from-cursor", 2,
1797 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1800 /* Cut/copy/paste */
1802 gtk_binding_entry_add_signal (binding_set, GDK_KEY_x, GDK_CONTROL_MASK,
1803 "cut-clipboard", 0);
1804 gtk_binding_entry_add_signal (binding_set, GDK_KEY_c, GDK_CONTROL_MASK,
1805 "copy-clipboard", 0);
1806 gtk_binding_entry_add_signal (binding_set, GDK_KEY_v, GDK_CONTROL_MASK,
1807 "paste-clipboard", 0);
1809 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, GDK_SHIFT_MASK,
1810 "cut-clipboard", 0);
1811 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, GDK_CONTROL_MASK,
1812 "copy-clipboard", 0);
1813 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, GDK_SHIFT_MASK,
1814 "paste-clipboard", 0);
1817 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, 0,
1818 "toggle-overwrite", 0);
1819 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Insert, 0,
1820 "toggle-overwrite", 0);
1823 * GtkEntry:inner-border:
1825 * Sets the text area's border between the text and the frame.
1829 gtk_widget_class_install_style_property (widget_class,
1830 g_param_spec_boxed ("inner-border",
1832 P_("Border between text and frame."),
1834 GTK_PARAM_READABLE));
1836 g_type_class_add_private (gobject_class, sizeof (GtkEntryPrivate));
1840 gtk_entry_editable_init (GtkEditableInterface *iface)
1842 iface->do_insert_text = gtk_entry_insert_text;
1843 iface->do_delete_text = gtk_entry_delete_text;
1844 iface->insert_text = gtk_entry_real_insert_text;
1845 iface->delete_text = gtk_entry_real_delete_text;
1846 iface->get_chars = gtk_entry_get_chars;
1847 iface->set_selection_bounds = gtk_entry_set_selection_bounds;
1848 iface->get_selection_bounds = gtk_entry_get_selection_bounds;
1849 iface->set_position = gtk_entry_real_set_position;
1850 iface->get_position = gtk_entry_get_position;
1854 gtk_entry_cell_editable_init (GtkCellEditableIface *iface)
1856 iface->start_editing = gtk_entry_start_editing;
1860 gtk_entry_set_property (GObject *object,
1862 const GValue *value,
1865 GtkEntry *entry = GTK_ENTRY (object);
1866 GtkEntryPrivate *priv = entry->priv;
1872 gtk_entry_set_buffer (entry, g_value_get_object (value));
1877 gboolean new_value = g_value_get_boolean (value);
1879 if (new_value != priv->editable)
1881 widget = GTK_WIDGET (entry);
1884 _gtk_entry_reset_im_context (entry);
1885 if (gtk_widget_has_focus (widget))
1886 gtk_im_context_focus_out (priv->im_context);
1888 priv->preedit_length = 0;
1889 priv->preedit_cursor = 0;
1892 priv->editable = new_value;
1894 if (new_value && gtk_widget_has_focus (widget))
1895 gtk_im_context_focus_in (priv->im_context);
1897 gtk_entry_queue_draw (entry);
1902 case PROP_MAX_LENGTH:
1903 gtk_entry_set_max_length (entry, g_value_get_int (value));
1906 case PROP_VISIBILITY:
1907 gtk_entry_set_visibility (entry, g_value_get_boolean (value));
1910 case PROP_HAS_FRAME:
1911 gtk_entry_set_has_frame (entry, g_value_get_boolean (value));
1914 case PROP_INNER_BORDER:
1915 gtk_entry_set_inner_border (entry, g_value_get_boxed (value));
1918 case PROP_INVISIBLE_CHAR:
1919 gtk_entry_set_invisible_char (entry, g_value_get_uint (value));
1922 case PROP_ACTIVATES_DEFAULT:
1923 gtk_entry_set_activates_default (entry, g_value_get_boolean (value));
1926 case PROP_WIDTH_CHARS:
1927 gtk_entry_set_width_chars (entry, g_value_get_int (value));
1931 gtk_entry_set_text (entry, g_value_get_string (value));
1935 gtk_entry_set_alignment (entry, g_value_get_float (value));
1938 case PROP_TRUNCATE_MULTILINE:
1939 priv->truncate_multiline = g_value_get_boolean (value);
1942 case PROP_SHADOW_TYPE:
1943 priv->shadow_type = g_value_get_enum (value);
1946 case PROP_OVERWRITE_MODE:
1947 gtk_entry_set_overwrite_mode (entry, g_value_get_boolean (value));
1950 case PROP_INVISIBLE_CHAR_SET:
1951 if (g_value_get_boolean (value))
1952 priv->invisible_char_set = TRUE;
1954 gtk_entry_unset_invisible_char (entry);
1957 case PROP_CAPS_LOCK_WARNING:
1958 priv->caps_lock_warning = g_value_get_boolean (value);
1961 case PROP_PROGRESS_FRACTION:
1962 gtk_entry_set_progress_fraction (entry, g_value_get_double (value));
1965 case PROP_PROGRESS_PULSE_STEP:
1966 gtk_entry_set_progress_pulse_step (entry, g_value_get_double (value));
1969 case PROP_PIXBUF_PRIMARY:
1970 gtk_entry_set_icon_from_pixbuf (entry,
1971 GTK_ENTRY_ICON_PRIMARY,
1972 g_value_get_object (value));
1975 case PROP_PIXBUF_SECONDARY:
1976 gtk_entry_set_icon_from_pixbuf (entry,
1977 GTK_ENTRY_ICON_SECONDARY,
1978 g_value_get_object (value));
1981 case PROP_STOCK_PRIMARY:
1982 gtk_entry_set_icon_from_stock (entry,
1983 GTK_ENTRY_ICON_PRIMARY,
1984 g_value_get_string (value));
1987 case PROP_STOCK_SECONDARY:
1988 gtk_entry_set_icon_from_stock (entry,
1989 GTK_ENTRY_ICON_SECONDARY,
1990 g_value_get_string (value));
1993 case PROP_ICON_NAME_PRIMARY:
1994 gtk_entry_set_icon_from_icon_name (entry,
1995 GTK_ENTRY_ICON_PRIMARY,
1996 g_value_get_string (value));
1999 case PROP_ICON_NAME_SECONDARY:
2000 gtk_entry_set_icon_from_icon_name (entry,
2001 GTK_ENTRY_ICON_SECONDARY,
2002 g_value_get_string (value));
2005 case PROP_GICON_PRIMARY:
2006 gtk_entry_set_icon_from_gicon (entry,
2007 GTK_ENTRY_ICON_PRIMARY,
2008 g_value_get_object (value));
2011 case PROP_GICON_SECONDARY:
2012 gtk_entry_set_icon_from_gicon (entry,
2013 GTK_ENTRY_ICON_SECONDARY,
2014 g_value_get_object (value));
2017 case PROP_ACTIVATABLE_PRIMARY:
2018 gtk_entry_set_icon_activatable (entry,
2019 GTK_ENTRY_ICON_PRIMARY,
2020 g_value_get_boolean (value));
2023 case PROP_ACTIVATABLE_SECONDARY:
2024 gtk_entry_set_icon_activatable (entry,
2025 GTK_ENTRY_ICON_SECONDARY,
2026 g_value_get_boolean (value));
2029 case PROP_SENSITIVE_PRIMARY:
2030 gtk_entry_set_icon_sensitive (entry,
2031 GTK_ENTRY_ICON_PRIMARY,
2032 g_value_get_boolean (value));
2035 case PROP_SENSITIVE_SECONDARY:
2036 gtk_entry_set_icon_sensitive (entry,
2037 GTK_ENTRY_ICON_SECONDARY,
2038 g_value_get_boolean (value));
2041 case PROP_TOOLTIP_TEXT_PRIMARY:
2042 gtk_entry_set_icon_tooltip_text (entry,
2043 GTK_ENTRY_ICON_PRIMARY,
2044 g_value_get_string (value));
2047 case PROP_TOOLTIP_TEXT_SECONDARY:
2048 gtk_entry_set_icon_tooltip_text (entry,
2049 GTK_ENTRY_ICON_SECONDARY,
2050 g_value_get_string (value));
2053 case PROP_TOOLTIP_MARKUP_PRIMARY:
2054 gtk_entry_set_icon_tooltip_markup (entry,
2055 GTK_ENTRY_ICON_PRIMARY,
2056 g_value_get_string (value));
2059 case PROP_TOOLTIP_MARKUP_SECONDARY:
2060 gtk_entry_set_icon_tooltip_markup (entry,
2061 GTK_ENTRY_ICON_SECONDARY,
2062 g_value_get_string (value));
2065 case PROP_IM_MODULE:
2066 g_free (priv->im_module);
2067 priv->im_module = g_value_dup_string (value);
2068 if (GTK_IS_IM_MULTICONTEXT (priv->im_context))
2069 gtk_im_multicontext_set_context_id (GTK_IM_MULTICONTEXT (priv->im_context), priv->im_module);
2072 case PROP_EDITING_CANCELED:
2073 priv->editing_canceled = g_value_get_boolean (value);
2076 case PROP_SCROLL_OFFSET:
2077 case PROP_CURSOR_POSITION:
2079 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2085 gtk_entry_get_property (GObject *object,
2090 GtkEntry *entry = GTK_ENTRY (object);
2091 GtkEntryPrivate *priv = entry->priv;
2096 g_value_set_object (value, gtk_entry_get_buffer (entry));
2099 case PROP_CURSOR_POSITION:
2100 g_value_set_int (value, priv->current_pos);
2103 case PROP_SELECTION_BOUND:
2104 g_value_set_int (value, priv->selection_bound);
2108 g_value_set_boolean (value, priv->editable);
2111 case PROP_MAX_LENGTH:
2112 g_value_set_int (value, gtk_entry_buffer_get_max_length (get_buffer (entry)));
2115 case PROP_VISIBILITY:
2116 g_value_set_boolean (value, priv->visible);
2119 case PROP_HAS_FRAME:
2120 g_value_set_boolean (value, priv->has_frame);
2123 case PROP_INNER_BORDER:
2124 g_value_set_boxed (value, gtk_entry_get_inner_border (entry));
2127 case PROP_INVISIBLE_CHAR:
2128 g_value_set_uint (value, priv->invisible_char);
2131 case PROP_ACTIVATES_DEFAULT:
2132 g_value_set_boolean (value, priv->activates_default);
2135 case PROP_WIDTH_CHARS:
2136 g_value_set_int (value, priv->width_chars);
2139 case PROP_SCROLL_OFFSET:
2140 g_value_set_int (value, priv->scroll_offset);
2144 g_value_set_string (value, gtk_entry_get_text (entry));
2148 g_value_set_float (value, gtk_entry_get_alignment (entry));
2151 case PROP_TRUNCATE_MULTILINE:
2152 g_value_set_boolean (value, priv->truncate_multiline);
2155 case PROP_SHADOW_TYPE:
2156 g_value_set_enum (value, priv->shadow_type);
2159 case PROP_OVERWRITE_MODE:
2160 g_value_set_boolean (value, priv->overwrite_mode);
2163 case PROP_TEXT_LENGTH:
2164 g_value_set_uint (value, gtk_entry_buffer_get_length (get_buffer (entry)));
2167 case PROP_INVISIBLE_CHAR_SET:
2168 g_value_set_boolean (value, priv->invisible_char_set);
2171 case PROP_IM_MODULE:
2172 g_value_set_string (value, priv->im_module);
2175 case PROP_CAPS_LOCK_WARNING:
2176 g_value_set_boolean (value, priv->caps_lock_warning);
2179 case PROP_PROGRESS_FRACTION:
2180 g_value_set_double (value, priv->progress_fraction);
2183 case PROP_PROGRESS_PULSE_STEP:
2184 g_value_set_double (value, priv->progress_pulse_fraction);
2187 case PROP_PIXBUF_PRIMARY:
2188 g_value_set_object (value,
2189 gtk_entry_get_icon_pixbuf (entry,
2190 GTK_ENTRY_ICON_PRIMARY));
2193 case PROP_PIXBUF_SECONDARY:
2194 g_value_set_object (value,
2195 gtk_entry_get_icon_pixbuf (entry,
2196 GTK_ENTRY_ICON_SECONDARY));
2199 case PROP_STOCK_PRIMARY:
2200 g_value_set_string (value,
2201 gtk_entry_get_icon_stock (entry,
2202 GTK_ENTRY_ICON_PRIMARY));
2205 case PROP_STOCK_SECONDARY:
2206 g_value_set_string (value,
2207 gtk_entry_get_icon_stock (entry,
2208 GTK_ENTRY_ICON_SECONDARY));
2211 case PROP_ICON_NAME_PRIMARY:
2212 g_value_set_string (value,
2213 gtk_entry_get_icon_name (entry,
2214 GTK_ENTRY_ICON_PRIMARY));
2217 case PROP_ICON_NAME_SECONDARY:
2218 g_value_set_string (value,
2219 gtk_entry_get_icon_name (entry,
2220 GTK_ENTRY_ICON_SECONDARY));
2223 case PROP_GICON_PRIMARY:
2224 g_value_set_object (value,
2225 gtk_entry_get_icon_gicon (entry,
2226 GTK_ENTRY_ICON_PRIMARY));
2229 case PROP_GICON_SECONDARY:
2230 g_value_set_object (value,
2231 gtk_entry_get_icon_gicon (entry,
2232 GTK_ENTRY_ICON_SECONDARY));
2235 case PROP_STORAGE_TYPE_PRIMARY:
2236 g_value_set_enum (value,
2237 gtk_entry_get_icon_storage_type (entry,
2238 GTK_ENTRY_ICON_PRIMARY));
2241 case PROP_STORAGE_TYPE_SECONDARY:
2242 g_value_set_enum (value,
2243 gtk_entry_get_icon_storage_type (entry,
2244 GTK_ENTRY_ICON_SECONDARY));
2247 case PROP_ACTIVATABLE_PRIMARY:
2248 g_value_set_boolean (value,
2249 gtk_entry_get_icon_activatable (entry, GTK_ENTRY_ICON_PRIMARY));
2252 case PROP_ACTIVATABLE_SECONDARY:
2253 g_value_set_boolean (value,
2254 gtk_entry_get_icon_activatable (entry, GTK_ENTRY_ICON_SECONDARY));
2257 case PROP_SENSITIVE_PRIMARY:
2258 g_value_set_boolean (value,
2259 gtk_entry_get_icon_sensitive (entry, GTK_ENTRY_ICON_PRIMARY));
2262 case PROP_SENSITIVE_SECONDARY:
2263 g_value_set_boolean (value,
2264 gtk_entry_get_icon_sensitive (entry, GTK_ENTRY_ICON_SECONDARY));
2267 case PROP_TOOLTIP_TEXT_PRIMARY:
2268 g_value_take_string (value,
2269 gtk_entry_get_icon_tooltip_text (entry, GTK_ENTRY_ICON_PRIMARY));
2272 case PROP_TOOLTIP_TEXT_SECONDARY:
2273 g_value_take_string (value,
2274 gtk_entry_get_icon_tooltip_text (entry, GTK_ENTRY_ICON_SECONDARY));
2277 case PROP_TOOLTIP_MARKUP_PRIMARY:
2278 g_value_take_string (value,
2279 gtk_entry_get_icon_tooltip_markup (entry, GTK_ENTRY_ICON_PRIMARY));
2282 case PROP_TOOLTIP_MARKUP_SECONDARY:
2283 g_value_take_string (value,
2284 gtk_entry_get_icon_tooltip_markup (entry, GTK_ENTRY_ICON_SECONDARY));
2287 case PROP_EDITING_CANCELED:
2288 g_value_set_boolean (value,
2289 priv->editing_canceled);
2293 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2299 find_invisible_char (GtkWidget *widget)
2301 PangoLayout *layout;
2302 PangoAttrList *attr_list;
2304 gunichar invisible_chars [] = {
2306 0x25cf, /* BLACK CIRCLE */
2307 0x2022, /* BULLET */
2308 0x2731, /* HEAVY ASTERISK */
2309 0x273a /* SIXTEEN POINTED ASTERISK */
2312 if (gtk_widget_get_style (widget))
2313 gtk_widget_style_get (widget,
2314 "invisible-char", &invisible_chars[0],
2317 layout = gtk_widget_create_pango_layout (widget, NULL);
2319 attr_list = pango_attr_list_new ();
2320 pango_attr_list_insert (attr_list, pango_attr_fallback_new (FALSE));
2322 pango_layout_set_attributes (layout, attr_list);
2323 pango_attr_list_unref (attr_list);
2325 for (i = (invisible_chars[0] != 0 ? 0 : 1); i < G_N_ELEMENTS (invisible_chars); i++)
2327 gchar text[7] = { 0, };
2330 len = g_unichar_to_utf8 (invisible_chars[i], text);
2331 pango_layout_set_text (layout, text, len);
2333 count = pango_layout_get_unknown_glyphs_count (layout);
2337 g_object_unref (layout);
2338 return invisible_chars[i];
2342 g_object_unref (layout);
2348 gtk_entry_init (GtkEntry *entry)
2350 GtkEntryPrivate *priv;
2352 entry->priv = G_TYPE_INSTANCE_GET_PRIVATE (entry,
2357 gtk_widget_set_can_focus (GTK_WIDGET (entry), TRUE);
2358 gtk_widget_set_has_window (GTK_WIDGET (entry), FALSE);
2360 priv->editable = TRUE;
2361 priv->visible = TRUE;
2362 priv->invisible_char = find_invisible_char (GTK_WIDGET (entry));
2363 priv->dnd_position = -1;
2364 priv->width_chars = -1;
2365 priv->is_cell_renderer = FALSE;
2366 priv->editing_canceled = FALSE;
2367 priv->has_frame = TRUE;
2368 priv->truncate_multiline = FALSE;
2369 priv->shadow_type = GTK_SHADOW_IN;
2371 priv->caps_lock_warning = TRUE;
2372 priv->caps_lock_warning_shown = FALSE;
2373 priv->progress_fraction = 0.0;
2374 priv->progress_pulse_fraction = 0.1;
2376 gtk_drag_dest_set (GTK_WIDGET (entry),
2377 GTK_DEST_DEFAULT_HIGHLIGHT,
2379 GDK_ACTION_COPY | GDK_ACTION_MOVE);
2380 gtk_drag_dest_add_text_targets (GTK_WIDGET (entry));
2382 /* This object is completely private. No external entity can gain a reference
2383 * to it; so we create it here and destroy it in finalize().
2385 priv->im_context = gtk_im_multicontext_new ();
2387 g_signal_connect (priv->im_context, "commit",
2388 G_CALLBACK (gtk_entry_commit_cb), entry);
2389 g_signal_connect (priv->im_context, "preedit-changed",
2390 G_CALLBACK (gtk_entry_preedit_changed_cb), entry);
2391 g_signal_connect (priv->im_context, "retrieve-surrounding",
2392 G_CALLBACK (gtk_entry_retrieve_surrounding_cb), entry);
2393 g_signal_connect (priv->im_context, "delete-surrounding",
2394 G_CALLBACK (gtk_entry_delete_surrounding_cb), entry);
2399 get_icon_width (GtkEntry *entry,
2400 GtkEntryIconPosition icon_pos)
2402 GtkEntryPrivate *priv = entry->priv;
2403 EntryIconInfo *icon_info = priv->icons[icon_pos];
2405 GtkSettings *settings;
2406 gint menu_icon_width;
2408 if (!icon_info || icon_info->pixbuf == NULL)
2411 screen = gtk_widget_get_screen (GTK_WIDGET (entry));
2412 settings = gtk_settings_get_for_screen (screen);
2414 gtk_icon_size_lookup_for_settings (settings, GTK_ICON_SIZE_MENU,
2415 &menu_icon_width, NULL);
2417 return MAX (gdk_pixbuf_get_width (icon_info->pixbuf), menu_icon_width);
2421 get_icon_allocations (GtkEntry *entry,
2422 GtkAllocation *primary,
2423 GtkAllocation *secondary)
2426 GtkEntryPrivate *priv = entry->priv;
2427 gint x, y, width, height;
2429 get_text_area_size (entry, &x, &y, &width, &height);
2431 if (gtk_widget_has_focus (GTK_WIDGET (entry)) && !priv->interior_focus)
2432 y += priv->focus_width;
2435 primary->height = height;
2436 primary->width = get_icon_width (entry, GTK_ENTRY_ICON_PRIMARY);
2437 if (primary->width > 0)
2438 primary->width += 2 * priv->icon_margin;
2441 secondary->height = height;
2442 secondary->width = get_icon_width (entry, GTK_ENTRY_ICON_SECONDARY);
2443 if (secondary->width > 0)
2444 secondary->width += 2 * priv->icon_margin;
2446 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
2448 primary->x = x + width - primary->width;
2454 secondary->x = x + width - secondary->width;
2460 begin_change (GtkEntry *entry)
2462 GtkEntryPrivate *priv = entry->priv;
2464 priv->change_count++;
2468 end_change (GtkEntry *entry)
2470 GtkEditable *editable = GTK_EDITABLE (entry);
2471 GtkEntryPrivate *priv = entry->priv;
2473 g_return_if_fail (priv->change_count > 0);
2475 priv->change_count--;
2477 if (priv->change_count == 0)
2479 if (priv->real_changed)
2481 g_signal_emit_by_name (editable, "changed");
2482 priv->real_changed = FALSE;
2488 emit_changed (GtkEntry *entry)
2490 GtkEditable *editable = GTK_EDITABLE (entry);
2491 GtkEntryPrivate *priv = entry->priv;
2493 if (priv->change_count == 0)
2494 g_signal_emit_by_name (editable, "changed");
2496 priv->real_changed = TRUE;
2500 gtk_entry_destroy (GtkWidget *widget)
2502 GtkEntry *entry = GTK_ENTRY (widget);
2503 GtkEntryPrivate *priv = entry->priv;
2505 priv->current_pos = priv->selection_bound = 0;
2506 _gtk_entry_reset_im_context (entry);
2507 gtk_entry_reset_layout (entry);
2509 if (priv->blink_timeout)
2511 g_source_remove (priv->blink_timeout);
2512 priv->blink_timeout = 0;
2515 if (priv->recompute_idle)
2517 g_source_remove (priv->recompute_idle);
2518 priv->recompute_idle = 0;
2521 GTK_WIDGET_CLASS (gtk_entry_parent_class)->destroy (widget);
2525 gtk_entry_dispose (GObject *object)
2527 GtkEntry *entry = GTK_ENTRY (object);
2528 GtkEntryPrivate *priv = entry->priv;
2530 gtk_entry_set_icon_from_pixbuf (entry, GTK_ENTRY_ICON_PRIMARY, NULL);
2531 gtk_entry_set_icon_tooltip_markup (entry, GTK_ENTRY_ICON_PRIMARY, NULL);
2532 gtk_entry_set_icon_from_pixbuf (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
2533 gtk_entry_set_icon_tooltip_markup (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
2537 buffer_disconnect_signals (entry);
2538 g_object_unref (priv->buffer);
2539 priv->buffer = NULL;
2542 G_OBJECT_CLASS (gtk_entry_parent_class)->dispose (object);
2546 gtk_entry_finalize (GObject *object)
2548 GtkEntry *entry = GTK_ENTRY (object);
2549 GtkEntryPrivate *priv = entry->priv;
2550 EntryIconInfo *icon_info = NULL;
2553 for (i = 0; i < MAX_ICONS; i++)
2555 if ((icon_info = priv->icons[i]) != NULL)
2557 if (icon_info->target_list != NULL)
2559 gtk_target_list_unref (icon_info->target_list);
2560 icon_info->target_list = NULL;
2563 g_slice_free (EntryIconInfo, icon_info);
2564 priv->icons[i] = NULL;
2568 gtk_entry_set_completion (entry, NULL);
2570 if (priv->cached_layout)
2571 g_object_unref (priv->cached_layout);
2573 g_object_unref (priv->im_context);
2575 if (priv->blink_timeout)
2576 g_source_remove (priv->blink_timeout);
2578 if (priv->recompute_idle)
2579 g_source_remove (priv->recompute_idle);
2581 g_free (priv->im_module);
2583 G_OBJECT_CLASS (gtk_entry_parent_class)->finalize (object);
2587 gtk_entry_get_display_mode (GtkEntry *entry)
2589 GtkEntryPrivate *priv = entry->priv;
2592 return DISPLAY_NORMAL;
2594 if (priv->invisible_char == 0 && priv->invisible_char_set)
2595 return DISPLAY_BLANK;
2597 return DISPLAY_INVISIBLE;
2601 gtk_entry_get_display_text (GtkEntry *entry,
2605 GtkEntryPasswordHint *password_hint;
2606 GtkEntryPrivate *priv;
2607 gunichar invisible_char;
2618 text = gtk_entry_buffer_get_text (get_buffer (entry));
2619 length = gtk_entry_buffer_get_length (get_buffer (entry));
2623 if (start_pos > length)
2626 if (end_pos <= start_pos)
2627 return g_strdup ("");
2628 else if (priv->visible)
2630 start = g_utf8_offset_to_pointer (text, start_pos);
2631 end = g_utf8_offset_to_pointer (start, end_pos - start_pos);
2632 return g_strndup (start, end - start);
2636 str = g_string_sized_new (length * 2);
2638 /* Figure out what our invisible char is and encode it */
2639 if (!priv->invisible_char)
2640 invisible_char = priv->invisible_char_set ? ' ' : '*';
2642 invisible_char = priv->invisible_char;
2643 char_len = g_unichar_to_utf8 (invisible_char, char_str);
2646 * Add hidden characters for each character in the text
2647 * buffer. If there is a password hint, then keep that
2648 * character visible.
2651 password_hint = g_object_get_qdata (G_OBJECT (entry), quark_password_hint);
2652 for (i = start_pos; i < end_pos; ++i)
2654 if (password_hint && i == password_hint->position)
2656 start = g_utf8_offset_to_pointer (text, i);
2657 g_string_append_len (str, start, g_utf8_next_char (start) - start);
2661 g_string_append_len (str, char_str, char_len);
2665 return g_string_free (str, FALSE);
2671 update_cursors (GtkWidget *widget)
2673 GtkEntry *entry = GTK_ENTRY (widget);
2674 GtkEntryPrivate *priv = entry->priv;
2675 EntryIconInfo *icon_info = NULL;
2676 GdkDisplay *display;
2680 for (i = 0; i < MAX_ICONS; i++)
2682 if ((icon_info = priv->icons[i]) != NULL)
2684 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
2685 gdk_window_show_unraised (icon_info->window);
2687 /* The icon windows are not children of the visible entry window,
2688 * thus we can't just inherit the xterm cursor. Slight complication
2689 * here is that for the entry, insensitive => arrow cursor, but for
2690 * an icon in a sensitive entry, insensitive => xterm cursor.
2692 if (gtk_widget_is_sensitive (widget) &&
2693 (icon_info->insensitive ||
2694 (icon_info->nonactivatable && icon_info->target_list == NULL)))
2696 display = gtk_widget_get_display (widget);
2697 cursor = gdk_cursor_new_for_display (display, GDK_XTERM);
2698 gdk_window_set_cursor (icon_info->window, cursor);
2699 gdk_cursor_unref (cursor);
2703 gdk_window_set_cursor (icon_info->window, NULL);
2710 realize_icon_info (GtkWidget *widget,
2711 GtkEntryIconPosition icon_pos)
2713 GtkEntry *entry = GTK_ENTRY (widget);
2714 GtkEntryPrivate *priv = entry->priv;
2715 EntryIconInfo *icon_info = priv->icons[icon_pos];
2716 GdkWindowAttr attributes;
2717 gint attributes_mask;
2719 g_return_if_fail (icon_info != NULL);
2723 attributes.width = 1;
2724 attributes.height = 1;
2725 attributes.window_type = GDK_WINDOW_CHILD;
2726 attributes.wclass = GDK_INPUT_ONLY;
2727 attributes.event_mask = gtk_widget_get_events (widget);
2728 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
2729 GDK_BUTTON_RELEASE_MASK |
2730 GDK_BUTTON1_MOTION_MASK |
2731 GDK_BUTTON3_MOTION_MASK |
2732 GDK_POINTER_MOTION_HINT_MASK |
2733 GDK_POINTER_MOTION_MASK |
2734 GDK_ENTER_NOTIFY_MASK |
2735 GDK_LEAVE_NOTIFY_MASK);
2736 attributes_mask = GDK_WA_X | GDK_WA_Y;
2738 icon_info->window = gdk_window_new (gtk_widget_get_window (widget),
2741 gdk_window_set_user_data (icon_info->window, widget);
2743 gtk_widget_queue_resize (widget);
2746 static EntryIconInfo*
2747 construct_icon_info (GtkWidget *widget,
2748 GtkEntryIconPosition icon_pos)
2750 GtkEntry *entry = GTK_ENTRY (widget);
2751 GtkEntryPrivate *priv = entry->priv;
2752 EntryIconInfo *icon_info;
2754 g_return_val_if_fail (priv->icons[icon_pos] == NULL, NULL);
2756 icon_info = g_slice_new0 (EntryIconInfo);
2757 priv->icons[icon_pos] = icon_info;
2759 if (gtk_widget_get_realized (widget))
2760 realize_icon_info (widget, icon_pos);
2766 gtk_entry_map (GtkWidget *widget)
2768 GtkEntry *entry = GTK_ENTRY (widget);
2769 GtkEntryPrivate *priv = entry->priv;
2770 EntryIconInfo *icon_info = NULL;
2773 GTK_WIDGET_CLASS (gtk_entry_parent_class)->map (widget);
2775 for (i = 0; i < MAX_ICONS; i++)
2777 if ((icon_info = priv->icons[i]) != NULL)
2779 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
2780 gdk_window_show (icon_info->window);
2784 update_cursors (widget);
2788 gtk_entry_unmap (GtkWidget *widget)
2790 GtkEntry *entry = GTK_ENTRY (widget);
2791 GtkEntryPrivate *priv = entry->priv;
2792 EntryIconInfo *icon_info = NULL;
2795 for (i = 0; i < MAX_ICONS; i++)
2797 if ((icon_info = priv->icons[i]) != NULL)
2799 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
2800 gdk_window_hide (icon_info->window);
2804 GTK_WIDGET_CLASS (gtk_entry_parent_class)->unmap (widget);
2808 gtk_entry_realize (GtkWidget *widget)
2811 GtkEntryPrivate *priv;
2812 EntryIconInfo *icon_info;
2814 GdkWindowAttr attributes;
2815 gint attributes_mask;
2816 gint frame_x, frame_y;
2819 gtk_widget_set_realized (widget, TRUE);
2820 window = gtk_widget_get_parent_window (widget);
2821 gtk_widget_set_window (widget, window);
2822 g_object_ref (window);
2824 entry = GTK_ENTRY (widget);
2827 attributes.window_type = GDK_WINDOW_CHILD;
2828 attributes.wclass = GDK_INPUT_ONLY;
2829 attributes.event_mask = gtk_widget_get_events (widget);
2830 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
2831 GDK_BUTTON_RELEASE_MASK |
2832 GDK_BUTTON1_MOTION_MASK |
2833 GDK_BUTTON3_MOTION_MASK |
2834 GDK_POINTER_MOTION_HINT_MASK |
2835 GDK_POINTER_MOTION_MASK |
2836 GDK_ENTER_NOTIFY_MASK |
2837 GDK_LEAVE_NOTIFY_MASK);
2838 attributes_mask = GDK_WA_X | GDK_WA_Y;
2840 get_text_area_size (entry, &attributes.x, &attributes.y, &attributes.width, &attributes.height);
2842 get_frame_size (entry, &frame_x, &frame_y, NULL, NULL);
2843 attributes.x += frame_x;
2844 attributes.y += frame_y;
2846 if (gtk_widget_is_sensitive (widget))
2848 attributes.cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
2849 attributes_mask |= GDK_WA_CURSOR;
2852 priv->text_area = gdk_window_new (gtk_widget_get_window (widget),
2856 gdk_window_set_user_data (priv->text_area, entry);
2858 if (attributes_mask & GDK_WA_CURSOR)
2859 gdk_cursor_unref (attributes.cursor);
2861 gtk_widget_style_attach (widget);
2863 gdk_window_show (priv->text_area);
2865 gtk_im_context_set_client_window (priv->im_context, priv->text_area);
2867 gtk_entry_adjust_scroll (entry);
2868 gtk_entry_update_primary_selection (entry);
2871 /* If the icon positions are already setup, create their windows.
2872 * Otherwise if they don't exist yet, then construct_icon_info()
2873 * will create the windows once the widget is already realized.
2875 for (i = 0; i < MAX_ICONS; i++)
2877 if ((icon_info = priv->icons[i]) != NULL)
2879 if (icon_info->window == NULL)
2880 realize_icon_info (widget, i);
2886 gtk_entry_unrealize (GtkWidget *widget)
2888 GtkEntry *entry = GTK_ENTRY (widget);
2889 GtkEntryPrivate *priv = entry->priv;
2890 GtkClipboard *clipboard;
2891 EntryIconInfo *icon_info;
2894 gtk_entry_reset_layout (entry);
2896 gtk_im_context_set_client_window (priv->im_context, NULL);
2898 clipboard = gtk_widget_get_clipboard (widget, GDK_SELECTION_PRIMARY);
2899 if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (entry))
2900 gtk_clipboard_clear (clipboard);
2902 if (priv->text_area)
2904 gdk_window_set_user_data (priv->text_area, NULL);
2905 gdk_window_destroy (priv->text_area);
2906 priv->text_area = NULL;
2909 if (priv->popup_menu)
2911 gtk_widget_destroy (priv->popup_menu);
2912 priv->popup_menu = NULL;
2915 GTK_WIDGET_CLASS (gtk_entry_parent_class)->unrealize (widget);
2917 for (i = 0; i < MAX_ICONS; i++)
2919 if ((icon_info = priv->icons[i]) != NULL)
2921 if (icon_info->window != NULL)
2923 gdk_window_destroy (icon_info->window);
2924 icon_info->window = NULL;
2931 _gtk_entry_get_borders (GtkEntry *entry,
2935 GtkEntryPrivate *priv = entry->priv;
2936 GtkWidget *widget = GTK_WIDGET (entry);
2939 if (priv->has_frame)
2941 style = gtk_widget_get_style (widget);
2943 *xborder = style->xthickness;
2944 *yborder = style->ythickness;
2952 if (!priv->interior_focus)
2954 *xborder += priv->focus_width;
2955 *yborder += priv->focus_width;
2960 gtk_entry_get_preferred_width (GtkWidget *widget,
2964 GtkEntry *entry = GTK_ENTRY (widget);
2965 GtkEntryPrivate *priv = entry->priv;
2966 PangoFontMetrics *metrics;
2967 gint xborder, yborder;
2968 GtkBorder inner_border;
2969 PangoContext *context;
2970 gint icon_widths = 0;
2974 gtk_widget_ensure_style (widget);
2975 context = gtk_widget_get_pango_context (widget);
2976 metrics = pango_context_get_metrics (context,
2977 gtk_widget_get_style (widget)->font_desc,
2978 pango_context_get_language (context));
2980 _gtk_entry_get_borders (entry, &xborder, &yborder);
2981 _gtk_entry_effective_inner_border (entry, &inner_border);
2983 if (priv->width_chars < 0)
2984 width = MIN_ENTRY_WIDTH + xborder * 2 + inner_border.left + inner_border.right;
2987 gint char_width = pango_font_metrics_get_approximate_char_width (metrics);
2988 gint digit_width = pango_font_metrics_get_approximate_digit_width (metrics);
2989 gint char_pixels = (MAX (char_width, digit_width) + PANGO_SCALE - 1) / PANGO_SCALE;
2991 width = char_pixels * priv->width_chars + xborder * 2 + inner_border.left + inner_border.right;
2994 for (i = 0; i < MAX_ICONS; i++)
2996 icon_width = get_icon_width (entry, i);
2998 icon_widths += icon_width + 2 * priv->icon_margin;
3001 if (icon_widths > width)
3002 width += icon_widths;
3004 pango_font_metrics_unref (metrics);
3011 gtk_entry_get_preferred_height (GtkWidget *widget,
3015 GtkEntry *entry = GTK_ENTRY (widget);
3016 GtkEntryPrivate *priv = entry->priv;
3017 PangoFontMetrics *metrics;
3018 gint xborder, yborder;
3019 GtkBorder inner_border;
3020 PangoContext *context;
3023 gtk_widget_ensure_style (widget);
3024 context = gtk_widget_get_pango_context (widget);
3025 metrics = pango_context_get_metrics (context,
3026 gtk_widget_get_style (widget)->font_desc,
3027 pango_context_get_language (context));
3029 priv->ascent = pango_font_metrics_get_ascent (metrics);
3030 priv->descent = pango_font_metrics_get_descent (metrics);
3032 _gtk_entry_get_borders (entry, &xborder, &yborder);
3033 _gtk_entry_effective_inner_border (entry, &inner_border);
3035 height = PANGO_PIXELS (priv->ascent + priv->descent) + yborder * 2 + inner_border.top + inner_border.bottom;
3037 pango_font_metrics_unref (metrics);
3044 place_windows (GtkEntry *entry)
3046 GtkWidget *widget = GTK_WIDGET (entry);
3047 GtkEntryPrivate *priv = entry->priv;
3048 gint x, y, width, height;
3049 gint frame_x, frame_y;
3050 GtkAllocation primary;
3051 GtkAllocation secondary;
3052 EntryIconInfo *icon_info = NULL;
3054 get_frame_size (entry, &frame_x, &frame_y, NULL, NULL);
3055 get_text_area_size (entry, &x, &y, &width, &height);
3056 get_icon_allocations (entry, &primary, &secondary);
3058 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3059 y += priv->focus_width;
3061 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
3062 x += secondary.width;
3065 width -= primary.width + secondary.width;
3069 primary.x += frame_x;
3070 primary.y += frame_y;
3071 secondary.x += frame_x;
3072 secondary.y += frame_y;
3074 if ((icon_info = priv->icons[GTK_ENTRY_ICON_PRIMARY]) != NULL)
3075 gdk_window_move_resize (icon_info->window,
3076 primary.x, primary.y,
3077 primary.width, primary.height);
3079 if ((icon_info = priv->icons[GTK_ENTRY_ICON_SECONDARY]) != NULL)
3080 gdk_window_move_resize (icon_info->window,
3081 secondary.x, secondary.y,
3082 secondary.width, secondary.height);
3084 gdk_window_move_resize (priv->text_area, x, y, width, height);
3088 gtk_entry_get_text_area_size (GtkEntry *entry,
3094 GtkEntryPrivate *priv = entry->priv;
3095 GtkWidget *widget = GTK_WIDGET (entry);
3096 GtkAllocation allocation;
3097 GtkRequisition requisition;
3099 gint xborder, yborder;
3101 gtk_widget_get_preferred_size (widget, &requisition, NULL);
3102 gtk_widget_get_allocation (widget, &allocation);
3103 _gtk_entry_get_borders (entry, &xborder, &yborder);
3105 if (gtk_widget_get_realized (widget))
3106 get_frame_size (entry, NULL, NULL, NULL, &frame_height);
3108 frame_height = requisition.height;
3110 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3111 frame_height -= 2 * priv->focus_width;
3117 *y = frame_height / 2 - (requisition.height - yborder * 2) / 2;
3120 *width = allocation.width - xborder * 2;
3123 *height = requisition.height - yborder * 2;
3127 get_text_area_size (GtkEntry *entry,
3133 GtkEntryClass *class;
3135 g_return_if_fail (GTK_IS_ENTRY (entry));
3137 class = GTK_ENTRY_GET_CLASS (entry);
3139 if (class->get_text_area_size)
3140 class->get_text_area_size (entry, x, y, width, height);
3145 get_frame_size (GtkEntry *entry,
3151 GtkEntryPrivate *priv = entry->priv;
3152 GtkAllocation allocation;
3153 GtkRequisition requisition;
3154 GtkWidget *widget = GTK_WIDGET (entry);
3156 gtk_widget_get_preferred_size (widget, &requisition, NULL);
3157 gtk_widget_get_allocation (widget, &allocation);
3164 if (priv->is_cell_renderer)
3167 *y = allocation.y + (allocation.height - requisition.height) / 2;
3171 *width = allocation.width;
3175 if (priv->is_cell_renderer)
3176 *height = allocation.height;
3178 *height = requisition.height;
3183 _gtk_entry_effective_inner_border (GtkEntry *entry,
3186 GtkBorder *tmp_border;
3188 tmp_border = g_object_get_qdata (G_OBJECT (entry), quark_inner_border);
3192 *border = *tmp_border;
3196 gtk_widget_style_get (GTK_WIDGET (entry), "inner-border", &tmp_border, NULL);
3200 *border = *tmp_border;
3201 gtk_border_free (tmp_border);
3205 *border = default_inner_border;
3209 gtk_entry_size_allocate (GtkWidget *widget,
3210 GtkAllocation *allocation)
3212 GtkEntry *entry = GTK_ENTRY (widget);
3214 gtk_widget_set_allocation (widget, allocation);
3216 if (gtk_widget_get_realized (widget))
3218 GtkEntryCompletion* completion;
3220 place_windows (entry);
3221 gtk_entry_recompute (entry);
3223 completion = gtk_entry_get_completion (entry);
3224 if (completion && gtk_widget_get_mapped (completion->priv->popup_window))
3225 _gtk_entry_completion_resize_popup (completion);
3229 /* Kudos to the gnome-panel guys. */
3231 colorshift_pixbuf (GdkPixbuf *dest,
3236 gint width, height, has_alpha, src_rowstride, dest_rowstride;
3237 guchar *target_pixels;
3238 guchar *original_pixels;
3244 has_alpha = gdk_pixbuf_get_has_alpha (src);
3245 width = gdk_pixbuf_get_width (src);
3246 height = gdk_pixbuf_get_height (src);
3247 src_rowstride = gdk_pixbuf_get_rowstride (src);
3248 dest_rowstride = gdk_pixbuf_get_rowstride (dest);
3249 original_pixels = gdk_pixbuf_get_pixels (src);
3250 target_pixels = gdk_pixbuf_get_pixels (dest);
3252 for (i = 0; i < height; i++)
3254 pix_dest = target_pixels + i * dest_rowstride;
3255 pix_src = original_pixels + i * src_rowstride;
3257 for (j = 0; j < width; j++)
3264 *(pix_dest++) = CLAMP (val, 0, 255);
3267 *(pix_dest++) = CLAMP (val, 0, 255);
3270 *(pix_dest++) = CLAMP (val, 0, 255);
3273 *(pix_dest++) = *(pix_src++);
3279 should_prelight (GtkEntry *entry,
3280 GtkEntryIconPosition icon_pos)
3282 GtkEntryPrivate *priv = entry->priv;
3283 EntryIconInfo *icon_info = priv->icons[icon_pos];
3289 if (icon_info->nonactivatable && icon_info->target_list == NULL)
3292 if (icon_info->pressed)
3295 gtk_widget_style_get (GTK_WIDGET (entry),
3296 "icon-prelight", &prelight,
3303 draw_icon (GtkWidget *widget,
3305 GtkEntryIconPosition icon_pos)
3307 GtkEntry *entry = GTK_ENTRY (widget);
3308 GtkEntryPrivate *priv = entry->priv;
3309 EntryIconInfo *icon_info = priv->icons[icon_pos];
3311 gint x, y, width, height;
3316 gtk_entry_ensure_pixbuf (entry, icon_pos);
3318 if (icon_info->pixbuf == NULL)
3321 width = gdk_window_get_width (icon_info->window);
3322 height = gdk_window_get_height (icon_info->window);
3324 /* size_allocate hasn't been called yet. These are the default values.
3326 if (width == 1 || height == 1)
3329 pixbuf = icon_info->pixbuf;
3330 g_object_ref (pixbuf);
3332 if (gdk_pixbuf_get_height (pixbuf) > height)
3334 GdkPixbuf *temp_pixbuf;
3337 scale = height - 2 * priv->icon_margin;
3338 temp_pixbuf = gdk_pixbuf_scale_simple (pixbuf, scale, scale,
3339 GDK_INTERP_BILINEAR);
3340 g_object_unref (pixbuf);
3341 pixbuf = temp_pixbuf;
3344 x = (width - gdk_pixbuf_get_width (pixbuf)) / 2;
3345 y = (height - gdk_pixbuf_get_height (pixbuf)) / 2;
3347 if (!gtk_widget_is_sensitive (widget) ||
3348 icon_info->insensitive)
3350 GdkPixbuf *temp_pixbuf;
3352 temp_pixbuf = gdk_pixbuf_copy (pixbuf);
3353 gdk_pixbuf_saturate_and_pixelate (pixbuf,
3357 g_object_unref (pixbuf);
3358 pixbuf = temp_pixbuf;
3360 else if (icon_info->prelight)
3362 GdkPixbuf *temp_pixbuf;
3364 temp_pixbuf = gdk_pixbuf_copy (pixbuf);
3365 colorshift_pixbuf (temp_pixbuf, pixbuf, 30);
3366 g_object_unref (pixbuf);
3367 pixbuf = temp_pixbuf;
3370 gdk_cairo_set_source_pixbuf (cr, pixbuf, x, y);
3373 g_object_unref (pixbuf);
3378 gtk_entry_draw_frame (GtkWidget *widget,
3381 GtkEntry *entry = GTK_ENTRY (widget);
3382 GtkEntryPrivate *priv = entry->priv;
3385 gint x = 0, y = 0, width, height;
3387 GtkAllocation allocation;
3388 gint frame_x, frame_y;
3392 window = gtk_widget_get_window (widget);
3394 get_frame_size (GTK_ENTRY (widget), &frame_x, &frame_y, &width, &height);
3395 gtk_widget_get_allocation (widget, &allocation);
3397 cairo_translate (cr, frame_x - allocation.x, frame_y - allocation.y);
3399 /* Fix a problem with some themes which assume that entry->text_area's
3400 * width equals widget->window's width
3401 * http://bugzilla.gnome.org/show_bug.cgi?id=466000 */
3402 if (GTK_IS_SPIN_BUTTON (widget))
3404 gint xborder, yborder;
3406 gtk_entry_get_text_area_size (GTK_ENTRY (widget), &x, NULL, &width, NULL);
3407 _gtk_entry_get_borders (GTK_ENTRY (widget), &xborder, &yborder);
3410 width += xborder * 2;
3413 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3415 x += priv->focus_width;
3416 y += priv->focus_width;
3417 width -= 2 * priv->focus_width;
3418 height -= 2 * priv->focus_width;
3421 style = gtk_widget_get_style (widget);
3422 state = gtk_widget_get_state (widget);
3424 gtk_paint_flat_box (style, cr,
3425 state, GTK_SHADOW_NONE,
3427 x, y, width, height);
3429 if (priv->has_frame)
3430 gtk_paint_shadow (style, cr,
3431 state, priv->shadow_type,
3432 widget, "entry", x, y, width, height);
3434 gtk_entry_draw_progress (widget, cr);
3436 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3438 x -= priv->focus_width;
3439 y -= priv->focus_width;
3440 width += 2 * priv->focus_width;
3441 height += 2 * priv->focus_width;
3443 gtk_paint_focus (style, cr,
3444 gtk_widget_get_state (widget),
3446 0, 0, width, height);
3453 get_progress_area (GtkWidget *widget,
3459 GtkEntry *entry = GTK_ENTRY (widget);
3460 GtkEntryPrivate *private = entry->priv;
3461 GtkBorder *progress_border;
3463 get_text_area_size (entry, x, y, width, height);
3465 if (!private->interior_focus)
3467 *x -= private->focus_width;
3468 *y -= private->focus_width;
3469 *width += 2 * private->focus_width;
3470 *height += 2 * private->focus_width;
3473 gtk_widget_style_get (widget, "progress-border", &progress_border, NULL);
3475 if (progress_border)
3477 *x += progress_border->left;
3478 *y += progress_border->top;
3479 *width -= progress_border->left + progress_border->right;
3480 *height -= progress_border->top + progress_border->bottom;
3482 gtk_border_free (progress_border);
3485 if (private->progress_pulse_mode)
3487 gdouble value = private->progress_pulse_current;
3489 *x += (gint) floor(value * (*width));
3490 *width = (gint) ceil(private->progress_pulse_fraction * (*width));
3492 else if (private->progress_fraction > 0)
3494 gdouble value = private->progress_fraction;
3496 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
3500 bar_width = floor(value * (*width) + 0.5);
3501 *x += *width - bar_width;
3506 *width = (gint) floor(value * (*width) + 0.5);
3517 gtk_entry_draw_progress (GtkWidget *widget,
3520 gint x, y, width, height;
3523 get_progress_area (widget, &x, &y, &width, &height);
3525 if ((width <= 0) || (height <= 0))
3528 state = GTK_STATE_SELECTED;
3529 if (!gtk_widget_get_sensitive (widget))
3530 state = GTK_STATE_INSENSITIVE;
3532 gtk_paint_box (gtk_widget_get_style (widget), cr,
3533 state, GTK_SHADOW_OUT,
3534 widget, "entry-progress",
3540 gtk_entry_draw (GtkWidget *widget,
3543 GtkEntry *entry = GTK_ENTRY (widget);
3546 GtkEntryPrivate *priv = entry->priv;
3549 style = gtk_widget_get_style (widget);
3551 state = gtk_widget_has_focus (widget) ?
3552 GTK_STATE_ACTIVE : gtk_widget_get_state (widget);
3554 if (gtk_cairo_should_draw_window (cr, gtk_widget_get_window (widget)))
3556 /* Draw entry_bg, shadow, progress and focus */
3557 gtk_entry_draw_frame (widget, cr);
3559 /* Draw text and cursor */
3562 gtk_cairo_transform_to_window (cr, widget, priv->text_area);
3564 if (priv->dnd_position != -1)
3565 gtk_entry_draw_cursor (GTK_ENTRY (widget), cr, CURSOR_DND);
3567 gtk_entry_draw_text (GTK_ENTRY (widget), cr);
3569 /* When no text is being displayed at all, don't show the cursor */
3570 if (gtk_entry_get_display_mode (entry) != DISPLAY_BLANK &&
3571 gtk_widget_has_focus (widget) &&
3572 priv->selection_bound == priv->current_pos && priv->cursor_visible)
3573 gtk_entry_draw_cursor (GTK_ENTRY (widget), cr, CURSOR_STANDARD);
3578 for (i = 0; i < MAX_ICONS; i++)
3580 EntryIconInfo *icon_info = priv->icons[i];
3582 if (icon_info != NULL)
3586 gtk_cairo_transform_to_window (cr, widget, icon_info->window);
3588 draw_icon (widget, cr, i);
3599 gtk_entry_enter_notify (GtkWidget *widget,
3600 GdkEventCrossing *event)
3602 GtkEntry *entry = GTK_ENTRY (widget);
3603 GtkEntryPrivate *priv = entry->priv;
3606 for (i = 0; i < MAX_ICONS; i++)
3608 EntryIconInfo *icon_info = priv->icons[i];
3610 if (icon_info != NULL && event->window == icon_info->window)
3612 if (should_prelight (entry, i))
3614 icon_info->prelight = TRUE;
3615 gtk_widget_queue_draw (widget);
3626 gtk_entry_leave_notify (GtkWidget *widget,
3627 GdkEventCrossing *event)
3629 GtkEntry *entry = GTK_ENTRY (widget);
3630 GtkEntryPrivate *priv = entry->priv;
3633 for (i = 0; i < MAX_ICONS; i++)
3635 EntryIconInfo *icon_info = priv->icons[i];
3637 if (icon_info != NULL && event->window == icon_info->window)
3639 /* a grab means that we may never see the button release */
3640 if (event->mode == GDK_CROSSING_GRAB || event->mode == GDK_CROSSING_GTK_GRAB)
3641 icon_info->pressed = FALSE;
3643 if (should_prelight (entry, i))
3645 icon_info->prelight = FALSE;
3646 gtk_widget_queue_draw (widget);
3657 gtk_entry_get_pixel_ranges (GtkEntry *entry,
3661 gint start_char, end_char;
3663 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start_char, &end_char))
3665 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
3666 PangoLayoutLine *line = pango_layout_get_lines_readonly (layout)->data;
3667 const char *text = pango_layout_get_text (layout);
3668 gint start_index = g_utf8_offset_to_pointer (text, start_char) - text;
3669 gint end_index = g_utf8_offset_to_pointer (text, end_char) - text;
3670 gint real_n_ranges, i;
3672 pango_layout_line_get_x_ranges (line, start_index, end_index, ranges, &real_n_ranges);
3678 for (i = 0; i < real_n_ranges; ++i)
3680 r[2 * i + 1] = (r[2 * i + 1] - r[2 * i]) / PANGO_SCALE;
3681 r[2 * i] = r[2 * i] / PANGO_SCALE;
3686 *n_ranges = real_n_ranges;
3698 in_selection (GtkEntry *entry,
3703 gint retval = FALSE;
3705 gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
3707 for (i = 0; i < n_ranges; ++i)
3709 if (x >= ranges[2 * i] && x < ranges[2 * i] + ranges[2 * i + 1])
3721 gtk_entry_button_press (GtkWidget *widget,
3722 GdkEventButton *event)
3724 GtkEntry *entry = GTK_ENTRY (widget);
3725 GtkEditable *editable = GTK_EDITABLE (widget);
3726 GtkEntryPrivate *priv = entry->priv;
3727 EntryIconInfo *icon_info = NULL;
3729 gint sel_start, sel_end;
3732 for (i = 0; i < MAX_ICONS; i++)
3734 icon_info = priv->icons[i];
3736 if (!icon_info || icon_info->insensitive)
3739 if (event->window == icon_info->window)
3741 if (should_prelight (entry, i))
3743 icon_info->prelight = FALSE;
3744 gtk_widget_queue_draw (widget);
3747 priv->start_x = event->x;
3748 priv->start_y = event->y;
3749 icon_info->pressed = TRUE;
3751 if (!icon_info->nonactivatable)
3752 g_signal_emit (entry, signals[ICON_PRESS], 0, i, event);
3758 if (event->window != priv->text_area ||
3759 (priv->button && event->button != priv->button))
3762 gtk_entry_reset_blink_time (entry);
3764 priv->button = event->button;
3766 if (!gtk_widget_has_focus (widget))
3768 priv->in_click = TRUE;
3769 gtk_widget_grab_focus (widget);
3770 priv->in_click = FALSE;
3773 tmp_pos = gtk_entry_find_position (entry, event->x + priv->scroll_offset);
3775 if (event->button == 1)
3777 gboolean have_selection = gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end);
3779 priv->select_words = FALSE;
3780 priv->select_lines = FALSE;
3782 if (event->state & GDK_SHIFT_MASK)
3784 _gtk_entry_reset_im_context (entry);
3786 if (!have_selection) /* select from the current position to the clicked position */
3787 sel_start = sel_end = priv->current_pos;
3789 if (tmp_pos > sel_start && tmp_pos < sel_end)
3791 /* Truncate current selection, but keep it as big as possible */
3792 if (tmp_pos - sel_start > sel_end - tmp_pos)
3793 gtk_entry_set_positions (entry, sel_start, tmp_pos);
3795 gtk_entry_set_positions (entry, tmp_pos, sel_end);
3799 gboolean extend_to_left;
3802 /* Figure out what click selects and extend current selection */
3803 switch (event->type)
3805 case GDK_BUTTON_PRESS:
3806 gtk_entry_set_positions (entry, tmp_pos, tmp_pos);
3809 case GDK_2BUTTON_PRESS:
3810 priv->select_words = TRUE;
3811 gtk_entry_select_word (entry);
3814 case GDK_3BUTTON_PRESS:
3815 priv->select_lines = TRUE;
3816 gtk_entry_select_line (entry);
3823 start = MIN (priv->current_pos, priv->selection_bound);
3824 start = MIN (sel_start, start);
3826 end = MAX (priv->current_pos, priv->selection_bound);
3827 end = MAX (sel_end, end);
3829 if (tmp_pos == sel_start || tmp_pos == sel_end)
3830 extend_to_left = (tmp_pos == start);
3832 extend_to_left = (end == sel_end);
3835 gtk_entry_set_positions (entry, start, end);
3837 gtk_entry_set_positions (entry, end, start);
3840 else /* no shift key */
3841 switch (event->type)
3843 case GDK_BUTTON_PRESS:
3844 if (in_selection (entry, event->x + priv->scroll_offset))
3846 /* Click inside the selection - we'll either start a drag, or
3847 * clear the selection
3849 priv->in_drag = TRUE;
3850 priv->drag_start_x = event->x + priv->scroll_offset;
3851 priv->drag_start_y = event->y;
3854 gtk_editable_set_position (editable, tmp_pos);
3857 case GDK_2BUTTON_PRESS:
3858 /* We ALWAYS receive a GDK_BUTTON_PRESS immediately before
3859 * receiving a GDK_2BUTTON_PRESS so we need to reset
3860 * priv->in_drag which may have been set above
3862 priv->in_drag = FALSE;
3863 priv->select_words = TRUE;
3864 gtk_entry_select_word (entry);
3867 case GDK_3BUTTON_PRESS:
3868 /* We ALWAYS receive a GDK_BUTTON_PRESS immediately before
3869 * receiving a GDK_3BUTTON_PRESS so we need to reset
3870 * priv->in_drag which may have been set above
3872 priv->in_drag = FALSE;
3873 priv->select_lines = TRUE;
3874 gtk_entry_select_line (entry);
3883 else if (event->button == 2 && event->type == GDK_BUTTON_PRESS)
3887 priv->insert_pos = tmp_pos;
3888 gtk_entry_paste (entry, GDK_SELECTION_PRIMARY);
3893 gtk_widget_error_bell (widget);
3896 else if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
3898 gtk_entry_do_popup (entry, event);
3899 priv->button = 0; /* Don't wait for release, since the menu will gtk_grab_add */
3908 gtk_entry_button_release (GtkWidget *widget,
3909 GdkEventButton *event)
3911 GtkEntry *entry = GTK_ENTRY (widget);
3912 GtkEntryPrivate *priv = entry->priv;
3913 EntryIconInfo *icon_info = NULL;
3916 for (i = 0; i < MAX_ICONS; i++)
3918 icon_info = priv->icons[i];
3920 if (!icon_info || icon_info->insensitive)
3923 if (event->window == icon_info->window)
3925 icon_info->pressed = FALSE;
3927 if (should_prelight (entry, i) &&
3928 event->x >= 0 && event->y >= 0 &&
3929 event->x < gdk_window_get_width (icon_info->window) &&
3930 event->y < gdk_window_get_height (icon_info->window))
3932 icon_info->prelight = TRUE;
3933 gtk_widget_queue_draw (widget);
3936 if (!icon_info->nonactivatable)
3937 g_signal_emit (entry, signals[ICON_RELEASE], 0, i, event);
3943 if (event->window != priv->text_area || priv->button != event->button)
3948 gint tmp_pos = gtk_entry_find_position (entry, priv->drag_start_x);
3950 gtk_editable_set_position (GTK_EDITABLE (entry), tmp_pos);
3957 gtk_entry_update_primary_selection (entry);
3963 _gtk_entry_get_selected_text (GtkEntry *entry)
3965 GtkEditable *editable = GTK_EDITABLE (entry);
3966 gint start_text, end_text;
3969 if (gtk_editable_get_selection_bounds (editable, &start_text, &end_text))
3970 text = gtk_editable_get_chars (editable, start_text, end_text);
3976 gtk_entry_motion_notify (GtkWidget *widget,
3977 GdkEventMotion *event)
3979 GtkEntry *entry = GTK_ENTRY (widget);
3980 GtkEntryPrivate *priv = entry->priv;
3981 EntryIconInfo *icon_info = NULL;
3982 GdkDragContext *context;
3986 for (i = 0; i < MAX_ICONS; i++)
3988 icon_info = priv->icons[i];
3990 if (!icon_info || icon_info->insensitive)
3993 if (event->window == icon_info->window)
3995 if (icon_info->pressed &&
3996 icon_info->target_list != NULL &&
3997 gtk_drag_check_threshold (widget,
4003 icon_info->in_drag = TRUE;
4004 icon_info->pressed = FALSE;
4005 context = gtk_drag_begin (widget,
4006 icon_info->target_list,
4016 if (priv->mouse_cursor_obscured)
4020 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
4021 gdk_window_set_cursor (priv->text_area, cursor);
4022 gdk_cursor_unref (cursor);
4023 priv->mouse_cursor_obscured = FALSE;
4026 if (event->window != priv->text_area || priv->button != 1)
4029 if (priv->select_lines)
4032 gdk_event_request_motions (event);
4036 if (gtk_entry_get_display_mode (entry) == DISPLAY_NORMAL &&
4037 gtk_drag_check_threshold (widget,
4038 priv->drag_start_x, priv->drag_start_y,
4039 event->x + priv->scroll_offset, event->y))
4041 GdkDragContext *context;
4042 GtkTargetList *target_list = gtk_target_list_new (NULL, 0);
4043 guint actions = priv->editable ? GDK_ACTION_COPY | GDK_ACTION_MOVE : GDK_ACTION_COPY;
4045 cairo_surface_t *surface;
4047 gtk_target_list_add_text_targets (target_list, 0);
4049 text = _gtk_entry_get_selected_text (entry);
4050 surface = _gtk_text_util_create_drag_icon (widget, text, -1);
4052 context = gtk_drag_begin (widget, target_list, actions,
4053 priv->button, (GdkEvent *)event);
4056 gtk_drag_set_icon_surface (context, surface);
4058 gtk_drag_set_icon_default (context);
4061 cairo_surface_destroy (surface);
4064 priv->in_drag = FALSE;
4067 gtk_target_list_unref (target_list);
4074 else if (event->y >= gdk_window_get_height (priv->text_area))
4075 tmp_pos = gtk_entry_buffer_get_length (get_buffer (entry));
4077 tmp_pos = gtk_entry_find_position (entry, event->x + priv->scroll_offset);
4079 if (priv->select_words)
4082 gint old_min, old_max;
4085 min = gtk_entry_move_backward_word (entry, tmp_pos, TRUE);
4086 max = gtk_entry_move_forward_word (entry, tmp_pos, TRUE);
4088 pos = priv->current_pos;
4089 bound = priv->selection_bound;
4091 old_min = MIN(priv->current_pos, priv->selection_bound);
4092 old_max = MAX(priv->current_pos, priv->selection_bound);
4099 else if (old_max < max)
4104 else if (pos == old_min)
4106 if (priv->current_pos != min)
4111 if (priv->current_pos != max)
4115 gtk_entry_set_positions (entry, pos, bound);
4118 gtk_entry_set_positions (entry, tmp_pos, -1);
4125 set_invisible_cursor (GdkWindow *window)
4127 GdkDisplay *display;
4130 display = gdk_window_get_display (window);
4131 cursor = gdk_cursor_new_for_display (display, GDK_BLANK_CURSOR);
4133 gdk_window_set_cursor (window, cursor);
4135 gdk_cursor_unref (cursor);
4139 gtk_entry_obscure_mouse_cursor (GtkEntry *entry)
4141 GtkEntryPrivate *priv = entry->priv;
4143 if (priv->mouse_cursor_obscured)
4146 set_invisible_cursor (priv->text_area);
4148 priv->mouse_cursor_obscured = TRUE;
4152 gtk_entry_key_press (GtkWidget *widget,
4155 GtkEntry *entry = GTK_ENTRY (widget);
4156 GtkEntryPrivate *priv = entry->priv;
4158 gtk_entry_reset_blink_time (entry);
4159 gtk_entry_pend_cursor_blink (entry);
4163 if (gtk_im_context_filter_keypress (priv->im_context, event))
4165 gtk_entry_obscure_mouse_cursor (entry);
4166 priv->need_im_reset = TRUE;
4171 if (event->keyval == GDK_KEY_Return ||
4172 event->keyval == GDK_KEY_KP_Enter ||
4173 event->keyval == GDK_KEY_ISO_Enter ||
4174 event->keyval == GDK_KEY_Escape)
4176 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
4178 if (completion && completion->priv->completion_timeout)
4180 g_source_remove (completion->priv->completion_timeout);
4181 completion->priv->completion_timeout = 0;
4184 _gtk_entry_reset_im_context (entry);
4187 if (GTK_WIDGET_CLASS (gtk_entry_parent_class)->key_press_event (widget, event))
4188 /* Activate key bindings
4192 if (!priv->editable && event->length)
4193 gtk_widget_error_bell (widget);
4199 gtk_entry_key_release (GtkWidget *widget,
4202 GtkEntry *entry = GTK_ENTRY (widget);
4203 GtkEntryPrivate *priv = entry->priv;
4207 if (gtk_im_context_filter_keypress (priv->im_context, event))
4209 priv->need_im_reset = TRUE;
4214 return GTK_WIDGET_CLASS (gtk_entry_parent_class)->key_release_event (widget, event);
4218 gtk_entry_focus_in (GtkWidget *widget,
4219 GdkEventFocus *event)
4221 GtkEntry *entry = GTK_ENTRY (widget);
4222 GtkEntryPrivate *priv = entry->priv;
4225 gtk_widget_queue_draw (widget);
4227 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (widget));
4231 priv->need_im_reset = TRUE;
4232 gtk_im_context_focus_in (priv->im_context);
4233 keymap_state_changed (keymap, entry);
4234 g_signal_connect (keymap, "state-changed",
4235 G_CALLBACK (keymap_state_changed), entry);
4238 g_signal_connect (keymap, "direction-changed",
4239 G_CALLBACK (keymap_direction_changed), entry);
4241 gtk_entry_reset_blink_time (entry);
4242 gtk_entry_check_cursor_blink (entry);
4248 gtk_entry_focus_out (GtkWidget *widget,
4249 GdkEventFocus *event)
4251 GtkEntry *entry = GTK_ENTRY (widget);
4252 GtkEntryPrivate *priv = entry->priv;
4253 GtkEntryCompletion *completion;
4256 gtk_widget_queue_draw (widget);
4258 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (widget));
4262 priv->need_im_reset = TRUE;
4263 gtk_im_context_focus_out (priv->im_context);
4264 remove_capslock_feedback (entry);
4267 gtk_entry_check_cursor_blink (entry);
4269 g_signal_handlers_disconnect_by_func (keymap, keymap_state_changed, entry);
4270 g_signal_handlers_disconnect_by_func (keymap, keymap_direction_changed, entry);
4272 completion = gtk_entry_get_completion (entry);
4274 _gtk_entry_completion_popdown (completion);
4280 gtk_entry_grab_focus (GtkWidget *widget)
4282 GtkEntry *entry = GTK_ENTRY (widget);
4283 GtkEntryPrivate *priv = entry->priv;
4284 gboolean select_on_focus;
4286 GTK_WIDGET_CLASS (gtk_entry_parent_class)->grab_focus (widget);
4288 if (priv->editable && !priv->in_click)
4290 g_object_get (gtk_widget_get_settings (widget),
4291 "gtk-entry-select-on-focus",
4295 if (select_on_focus)
4296 gtk_editable_select_region (GTK_EDITABLE (widget), 0, -1);
4301 gtk_entry_direction_changed (GtkWidget *widget,
4302 GtkTextDirection previous_dir)
4304 GtkEntry *entry = GTK_ENTRY (widget);
4306 gtk_entry_recompute (entry);
4308 GTK_WIDGET_CLASS (gtk_entry_parent_class)->direction_changed (widget, previous_dir);
4312 gtk_entry_state_changed (GtkWidget *widget,
4313 GtkStateType previous_state)
4315 GtkEntry *entry = GTK_ENTRY (widget);
4316 GtkEntryPrivate *priv = entry->priv;
4319 if (gtk_widget_get_realized (widget))
4321 if (gtk_widget_is_sensitive (widget))
4322 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
4326 gdk_window_set_cursor (priv->text_area, cursor);
4329 gdk_cursor_unref (cursor);
4331 priv->mouse_cursor_obscured = FALSE;
4333 update_cursors (widget);
4336 if (!gtk_widget_is_sensitive (widget))
4338 /* Clear any selection */
4339 gtk_editable_select_region (GTK_EDITABLE (entry), priv->current_pos, priv->current_pos);
4342 gtk_widget_queue_draw (widget);
4346 gtk_entry_screen_changed (GtkWidget *widget,
4347 GdkScreen *old_screen)
4349 gtk_entry_recompute (GTK_ENTRY (widget));
4352 /* GtkEditable method implementations
4355 gtk_entry_insert_text (GtkEditable *editable,
4356 const gchar *new_text,
4357 gint new_text_length,
4360 g_object_ref (editable);
4363 * The incoming text may a password or other secret. We make sure
4364 * not to copy it into temporary buffers.
4367 g_signal_emit_by_name (editable, "insert-text", new_text, new_text_length, position);
4369 g_object_unref (editable);
4373 gtk_entry_delete_text (GtkEditable *editable,
4377 g_object_ref (editable);
4379 g_signal_emit_by_name (editable, "delete-text", start_pos, end_pos);
4381 g_object_unref (editable);
4385 gtk_entry_get_chars (GtkEditable *editable,
4389 GtkEntry *entry = GTK_ENTRY (editable);
4392 gint start_index, end_index;
4394 text = gtk_entry_buffer_get_text (get_buffer (entry));
4395 text_length = gtk_entry_buffer_get_length (get_buffer (entry));
4398 end_pos = text_length;
4400 start_pos = MIN (text_length, start_pos);
4401 end_pos = MIN (text_length, end_pos);
4403 start_index = g_utf8_offset_to_pointer (text, start_pos) - text;
4404 end_index = g_utf8_offset_to_pointer (text, end_pos) - text;
4406 return g_strndup (text + start_index, end_index - start_index);
4410 gtk_entry_real_set_position (GtkEditable *editable,
4413 GtkEntry *entry = GTK_ENTRY (editable);
4414 GtkEntryPrivate *priv = entry->priv;
4418 length = gtk_entry_buffer_get_length (get_buffer (entry));
4419 if (position < 0 || position > length)
4422 if (position != priv->current_pos ||
4423 position != priv->selection_bound)
4425 _gtk_entry_reset_im_context (entry);
4426 gtk_entry_set_positions (entry, position, position);
4431 gtk_entry_get_position (GtkEditable *editable)
4433 GtkEntry *entry = GTK_ENTRY (editable);
4434 GtkEntryPrivate *priv = entry->priv;
4436 return priv->current_pos;
4440 gtk_entry_set_selection_bounds (GtkEditable *editable,
4444 GtkEntry *entry = GTK_ENTRY (editable);
4447 length = gtk_entry_buffer_get_length (get_buffer (entry));
4453 _gtk_entry_reset_im_context (entry);
4455 gtk_entry_set_positions (entry,
4457 MIN (start, length));
4459 gtk_entry_update_primary_selection (entry);
4463 gtk_entry_get_selection_bounds (GtkEditable *editable,
4467 GtkEntry *entry = GTK_ENTRY (editable);
4468 GtkEntryPrivate *priv = entry->priv;
4470 *start = priv->selection_bound;
4471 *end = priv->current_pos;
4473 return (priv->selection_bound != priv->current_pos);
4477 icon_theme_changed (GtkEntry *entry)
4479 GtkEntryPrivate *priv = entry->priv;
4482 for (i = 0; i < MAX_ICONS; i++)
4484 EntryIconInfo *icon_info = priv->icons[i];
4485 if (icon_info != NULL)
4487 if (icon_info->storage_type == GTK_IMAGE_ICON_NAME)
4488 gtk_entry_set_icon_from_icon_name (entry, i, icon_info->icon_name);
4489 else if (icon_info->storage_type == GTK_IMAGE_STOCK)
4490 gtk_entry_set_icon_from_stock (entry, i, icon_info->stock_id);
4491 else if (icon_info->storage_type == GTK_IMAGE_GICON)
4492 gtk_entry_set_icon_from_gicon (entry, i, icon_info->gicon);
4496 gtk_widget_queue_draw (GTK_WIDGET (entry));
4500 icon_margin_changed (GtkEntry *entry)
4502 GtkEntryPrivate *priv = entry->priv;
4505 _gtk_entry_effective_inner_border (GTK_ENTRY (entry), &border);
4507 priv->icon_margin = border.left;
4511 gtk_entry_style_set (GtkWidget *widget,
4512 GtkStyle *previous_style)
4514 GtkEntry *entry = GTK_ENTRY (widget);
4515 GtkEntryPrivate *priv = entry->priv;
4517 gboolean interior_focus;
4519 gtk_widget_style_get (widget,
4520 "focus-line-width", &focus_width,
4521 "interior-focus", &interior_focus,
4524 priv->focus_width = focus_width;
4525 priv->interior_focus = interior_focus;
4527 if (!priv->invisible_char_set)
4528 priv->invisible_char = find_invisible_char (GTK_WIDGET (entry));
4530 gtk_entry_recompute (entry);
4532 icon_theme_changed (entry);
4533 icon_margin_changed (entry);
4536 /* GtkCellEditable method implementations
4539 gtk_cell_editable_entry_activated (GtkEntry *entry, gpointer data)
4541 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4542 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4546 gtk_cell_editable_key_press_event (GtkEntry *entry,
4547 GdkEventKey *key_event,
4550 GtkEntryPrivate *priv = entry->priv;
4552 if (key_event->keyval == GDK_KEY_Escape)
4554 priv->editing_canceled = TRUE;
4555 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4556 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4561 /* override focus */
4562 if (key_event->keyval == GDK_KEY_Up || key_event->keyval == GDK_KEY_Down)
4564 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4565 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4574 gtk_entry_start_editing (GtkCellEditable *cell_editable,
4577 GtkEntry *entry = GTK_ENTRY (cell_editable);
4578 GtkEntryPrivate *priv = entry->priv;
4580 priv->is_cell_renderer = TRUE;
4582 g_signal_connect (cell_editable, "activate",
4583 G_CALLBACK (gtk_cell_editable_entry_activated), NULL);
4584 g_signal_connect (cell_editable, "key-press-event",
4585 G_CALLBACK (gtk_cell_editable_key_press_event), NULL);
4589 gtk_entry_password_hint_free (GtkEntryPasswordHint *password_hint)
4591 if (password_hint->source_id)
4592 g_source_remove (password_hint->source_id);
4594 g_slice_free (GtkEntryPasswordHint, password_hint);
4599 gtk_entry_remove_password_hint (gpointer data)
4601 GtkEntryPasswordHint *password_hint = g_object_get_qdata (data, quark_password_hint);
4602 password_hint->position = -1;
4604 /* Force the string to be redrawn, but now without a visible character */
4605 gtk_entry_recompute (GTK_ENTRY (data));
4609 /* Default signal handlers
4612 gtk_entry_real_insert_text (GtkEditable *editable,
4613 const gchar *new_text,
4614 gint new_text_length,
4620 n_chars = g_utf8_strlen (new_text, new_text_length);
4623 * The actual insertion into the buffer. This will end up firing the
4624 * following signal handlers: buffer_inserted_text(), buffer_notify_display_text(),
4625 * buffer_notify_text(), buffer_notify_length()
4627 n_inserted = gtk_entry_buffer_insert_text (get_buffer (GTK_ENTRY (editable)), *position, new_text, n_chars);
4629 if (n_inserted != n_chars)
4630 gtk_widget_error_bell (GTK_WIDGET (editable));
4632 *position += n_inserted;
4636 gtk_entry_real_delete_text (GtkEditable *editable,
4641 * The actual deletion from the buffer. This will end up firing the
4642 * following signal handlers: buffer_deleted_text(), buffer_notify_display_text(),
4643 * buffer_notify_text(), buffer_notify_length()
4646 gtk_entry_buffer_delete_text (get_buffer (GTK_ENTRY (editable)), start_pos, end_pos - start_pos);
4649 /* GtkEntryBuffer signal handlers
4652 buffer_inserted_text (GtkEntryBuffer *buffer,
4658 GtkEntryPrivate *priv = entry->priv;
4659 guint password_hint_timeout;
4661 if (priv->current_pos > position)
4662 priv->current_pos += n_chars;
4664 if (priv->selection_bound > position)
4665 priv->selection_bound += n_chars;
4667 /* Calculate the password hint if it needs to be displayed. */
4668 if (n_chars == 1 && !priv->visible)
4670 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
4671 "gtk-entry-password-hint-timeout", &password_hint_timeout,
4674 if (password_hint_timeout > 0)
4676 GtkEntryPasswordHint *password_hint = g_object_get_qdata (G_OBJECT (entry),
4677 quark_password_hint);
4680 password_hint = g_slice_new0 (GtkEntryPasswordHint);
4681 g_object_set_qdata_full (G_OBJECT (entry), quark_password_hint, password_hint,
4682 (GDestroyNotify)gtk_entry_password_hint_free);
4685 password_hint->position = position;
4686 if (password_hint->source_id)
4687 g_source_remove (password_hint->source_id);
4688 password_hint->source_id = gdk_threads_add_timeout (password_hint_timeout,
4689 (GSourceFunc)gtk_entry_remove_password_hint, entry);
4695 buffer_deleted_text (GtkEntryBuffer *buffer,
4700 GtkEntryPrivate *priv = entry->priv;
4701 guint end_pos = position + n_chars;
4702 gint selection_bound;
4705 current_pos = priv->current_pos;
4706 if (current_pos > position)
4707 current_pos -= MIN (current_pos, end_pos) - position;
4709 selection_bound = priv->selection_bound;
4710 if (selection_bound > position)
4711 selection_bound -= MIN (selection_bound, end_pos) - position;
4713 gtk_entry_set_positions (entry, current_pos, selection_bound);
4715 /* We might have deleted the selection */
4716 gtk_entry_update_primary_selection (entry);
4718 /* Disable the password hint if one exists. */
4721 GtkEntryPasswordHint *password_hint = g_object_get_qdata (G_OBJECT (entry),
4722 quark_password_hint);
4725 if (password_hint->source_id)
4726 g_source_remove (password_hint->source_id);
4727 password_hint->source_id = 0;
4728 password_hint->position = -1;
4734 buffer_notify_text (GtkEntryBuffer *buffer,
4738 gtk_entry_recompute (entry);
4739 emit_changed (entry);
4740 g_object_notify (G_OBJECT (entry), "text");
4744 buffer_notify_length (GtkEntryBuffer *buffer,
4748 g_object_notify (G_OBJECT (entry), "text-length");
4752 buffer_notify_max_length (GtkEntryBuffer *buffer,
4756 g_object_notify (G_OBJECT (entry), "max-length");
4760 buffer_connect_signals (GtkEntry *entry)
4762 g_signal_connect (get_buffer (entry), "inserted-text", G_CALLBACK (buffer_inserted_text), entry);
4763 g_signal_connect (get_buffer (entry), "deleted-text", G_CALLBACK (buffer_deleted_text), entry);
4764 g_signal_connect (get_buffer (entry), "notify::text", G_CALLBACK (buffer_notify_text), entry);
4765 g_signal_connect (get_buffer (entry), "notify::length", G_CALLBACK (buffer_notify_length), entry);
4766 g_signal_connect (get_buffer (entry), "notify::max-length", G_CALLBACK (buffer_notify_max_length), entry);
4770 buffer_disconnect_signals (GtkEntry *entry)
4772 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_inserted_text, entry);
4773 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_deleted_text, entry);
4774 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_text, entry);
4775 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_length, entry);
4776 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_max_length, entry);
4779 /* Compute the X position for an offset that corresponds to the "more important
4780 * cursor position for that offset. We use this when trying to guess to which
4781 * end of the selection we should go to when the user hits the left or
4785 get_better_cursor_x (GtkEntry *entry,
4788 GtkEntryPrivate *priv = entry->priv;
4789 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
4790 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
4791 gboolean split_cursor;
4793 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
4794 const gchar *text = pango_layout_get_text (layout);
4795 gint index = g_utf8_offset_to_pointer (text, offset) - text;
4797 PangoRectangle strong_pos, weak_pos;
4799 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
4800 "gtk-split-cursor", &split_cursor,
4803 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
4806 return strong_pos.x / PANGO_SCALE;
4808 return (keymap_direction == priv->resolved_dir) ? strong_pos.x / PANGO_SCALE : weak_pos.x / PANGO_SCALE;
4812 gtk_entry_move_cursor (GtkEntry *entry,
4813 GtkMovementStep step,
4815 gboolean extend_selection)
4817 GtkEntryPrivate *priv = entry->priv;
4818 gint new_pos = priv->current_pos;
4820 _gtk_entry_reset_im_context (entry);
4822 if (priv->current_pos != priv->selection_bound && !extend_selection)
4824 /* If we have a current selection and aren't extending it, move to the
4825 * start/or end of the selection as appropriate
4829 case GTK_MOVEMENT_VISUAL_POSITIONS:
4831 gint current_x = get_better_cursor_x (entry, priv->current_pos);
4832 gint bound_x = get_better_cursor_x (entry, priv->selection_bound);
4835 new_pos = current_x < bound_x ? priv->current_pos : priv->selection_bound;
4837 new_pos = current_x > bound_x ? priv->current_pos : priv->selection_bound;
4840 case GTK_MOVEMENT_LOGICAL_POSITIONS:
4841 case GTK_MOVEMENT_WORDS:
4843 new_pos = MIN (priv->current_pos, priv->selection_bound);
4845 new_pos = MAX (priv->current_pos, priv->selection_bound);
4847 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
4848 case GTK_MOVEMENT_PARAGRAPH_ENDS:
4849 case GTK_MOVEMENT_BUFFER_ENDS:
4850 new_pos = count < 0 ? 0 : gtk_entry_buffer_get_length (get_buffer (entry));
4852 case GTK_MOVEMENT_DISPLAY_LINES:
4853 case GTK_MOVEMENT_PARAGRAPHS:
4854 case GTK_MOVEMENT_PAGES:
4855 case GTK_MOVEMENT_HORIZONTAL_PAGES:
4863 case GTK_MOVEMENT_LOGICAL_POSITIONS:
4864 new_pos = gtk_entry_move_logically (entry, new_pos, count);
4866 case GTK_MOVEMENT_VISUAL_POSITIONS:
4867 new_pos = gtk_entry_move_visually (entry, new_pos, count);
4868 if (priv->current_pos == new_pos)
4870 if (!extend_selection)
4872 if (!gtk_widget_keynav_failed (GTK_WIDGET (entry),
4874 GTK_DIR_RIGHT : GTK_DIR_LEFT))
4876 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (entry));
4879 gtk_widget_child_focus (toplevel,
4881 GTK_DIR_RIGHT : GTK_DIR_LEFT);
4886 gtk_widget_error_bell (GTK_WIDGET (entry));
4890 case GTK_MOVEMENT_WORDS:
4893 new_pos = gtk_entry_move_forward_word (entry, new_pos, FALSE);
4898 new_pos = gtk_entry_move_backward_word (entry, new_pos, FALSE);
4901 if (priv->current_pos == new_pos)
4902 gtk_widget_error_bell (GTK_WIDGET (entry));
4904 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
4905 case GTK_MOVEMENT_PARAGRAPH_ENDS:
4906 case GTK_MOVEMENT_BUFFER_ENDS:
4907 new_pos = count < 0 ? 0 : gtk_entry_buffer_get_length (get_buffer (entry));
4908 if (priv->current_pos == new_pos)
4909 gtk_widget_error_bell (GTK_WIDGET (entry));
4911 case GTK_MOVEMENT_DISPLAY_LINES:
4912 case GTK_MOVEMENT_PARAGRAPHS:
4913 case GTK_MOVEMENT_PAGES:
4914 case GTK_MOVEMENT_HORIZONTAL_PAGES:
4919 if (extend_selection)
4920 gtk_editable_select_region (GTK_EDITABLE (entry), priv->selection_bound, new_pos);
4922 gtk_editable_set_position (GTK_EDITABLE (entry), new_pos);
4924 gtk_entry_pend_cursor_blink (entry);
4928 gtk_entry_insert_at_cursor (GtkEntry *entry,
4931 GtkEntryPrivate *priv = entry->priv;
4932 GtkEditable *editable = GTK_EDITABLE (entry);
4933 gint pos = priv->current_pos;
4937 _gtk_entry_reset_im_context (entry);
4939 gtk_editable_insert_text (editable, str, -1, &pos);
4940 gtk_editable_set_position (editable, pos);
4945 gtk_entry_delete_from_cursor (GtkEntry *entry,
4949 GtkEntryPrivate *priv = entry->priv;
4950 GtkEditable *editable = GTK_EDITABLE (entry);
4951 gint start_pos = priv->current_pos;
4952 gint end_pos = priv->current_pos;
4953 gint old_n_bytes = gtk_entry_buffer_get_bytes (get_buffer (entry));
4955 _gtk_entry_reset_im_context (entry);
4957 if (!priv->editable)
4959 gtk_widget_error_bell (GTK_WIDGET (entry));
4963 if (priv->selection_bound != priv->current_pos)
4965 gtk_editable_delete_selection (editable);
4971 case GTK_DELETE_CHARS:
4972 end_pos = gtk_entry_move_logically (entry, priv->current_pos, count);
4973 gtk_editable_delete_text (editable, MIN (start_pos, end_pos), MAX (start_pos, end_pos));
4975 case GTK_DELETE_WORDS:
4978 /* Move to end of current word, or if not on a word, end of previous word */
4979 end_pos = gtk_entry_move_backward_word (entry, end_pos, FALSE);
4980 end_pos = gtk_entry_move_forward_word (entry, end_pos, FALSE);
4984 /* Move to beginning of current word, or if not on a word, begining of next word */
4985 start_pos = gtk_entry_move_forward_word (entry, start_pos, FALSE);
4986 start_pos = gtk_entry_move_backward_word (entry, start_pos, FALSE);
4990 case GTK_DELETE_WORD_ENDS:
4993 start_pos = gtk_entry_move_backward_word (entry, start_pos, FALSE);
4998 end_pos = gtk_entry_move_forward_word (entry, end_pos, FALSE);
5001 gtk_editable_delete_text (editable, start_pos, end_pos);
5003 case GTK_DELETE_DISPLAY_LINE_ENDS:
5004 case GTK_DELETE_PARAGRAPH_ENDS:
5006 gtk_editable_delete_text (editable, 0, priv->current_pos);
5008 gtk_editable_delete_text (editable, priv->current_pos, -1);
5010 case GTK_DELETE_DISPLAY_LINES:
5011 case GTK_DELETE_PARAGRAPHS:
5012 gtk_editable_delete_text (editable, 0, -1);
5014 case GTK_DELETE_WHITESPACE:
5015 gtk_entry_delete_whitespace (entry);
5019 if (gtk_entry_buffer_get_bytes (get_buffer (entry)) == old_n_bytes)
5020 gtk_widget_error_bell (GTK_WIDGET (entry));
5022 gtk_entry_pend_cursor_blink (entry);
5026 gtk_entry_backspace (GtkEntry *entry)
5028 GtkEntryPrivate *priv = entry->priv;
5029 GtkEditable *editable = GTK_EDITABLE (entry);
5032 _gtk_entry_reset_im_context (entry);
5034 if (!priv->editable)
5036 gtk_widget_error_bell (GTK_WIDGET (entry));
5040 if (priv->selection_bound != priv->current_pos)
5042 gtk_editable_delete_selection (editable);
5046 prev_pos = gtk_entry_move_logically (entry, priv->current_pos, -1);
5048 if (prev_pos < priv->current_pos)
5050 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
5051 PangoLogAttr *log_attrs;
5054 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
5056 /* Deleting parts of characters */
5057 if (log_attrs[priv->current_pos].backspace_deletes_character)
5059 gchar *cluster_text;
5060 gchar *normalized_text;
5063 cluster_text = gtk_entry_get_display_text (entry, prev_pos,
5065 normalized_text = g_utf8_normalize (cluster_text,
5066 strlen (cluster_text),
5068 len = g_utf8_strlen (normalized_text, -1);
5070 gtk_editable_delete_text (editable, prev_pos, priv->current_pos);
5073 gint pos = priv->current_pos;
5075 gtk_editable_insert_text (editable, normalized_text,
5076 g_utf8_offset_to_pointer (normalized_text, len - 1) - normalized_text,
5078 gtk_editable_set_position (editable, pos);
5081 g_free (normalized_text);
5082 g_free (cluster_text);
5086 gtk_editable_delete_text (editable, prev_pos, priv->current_pos);
5093 gtk_widget_error_bell (GTK_WIDGET (entry));
5096 gtk_entry_pend_cursor_blink (entry);
5100 gtk_entry_copy_clipboard (GtkEntry *entry)
5102 GtkEntryPrivate *priv = entry->priv;
5103 GtkEditable *editable = GTK_EDITABLE (entry);
5107 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5111 gtk_widget_error_bell (GTK_WIDGET (entry));
5115 str = gtk_entry_get_display_text (entry, start, end);
5116 gtk_clipboard_set_text (gtk_widget_get_clipboard (GTK_WIDGET (entry),
5117 GDK_SELECTION_CLIPBOARD),
5124 gtk_entry_cut_clipboard (GtkEntry *entry)
5126 GtkEntryPrivate *priv = entry->priv;
5127 GtkEditable *editable = GTK_EDITABLE (entry);
5132 gtk_widget_error_bell (GTK_WIDGET (entry));
5136 gtk_entry_copy_clipboard (entry);
5140 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5141 gtk_editable_delete_text (editable, start, end);
5145 gtk_widget_error_bell (GTK_WIDGET (entry));
5150 gtk_entry_paste_clipboard (GtkEntry *entry)
5152 GtkEntryPrivate *priv = entry->priv;
5155 gtk_entry_paste (entry, GDK_NONE);
5157 gtk_widget_error_bell (GTK_WIDGET (entry));
5161 gtk_entry_delete_cb (GtkEntry *entry)
5163 GtkEntryPrivate *priv = entry->priv;
5164 GtkEditable *editable = GTK_EDITABLE (entry);
5169 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5170 gtk_editable_delete_text (editable, start, end);
5175 gtk_entry_toggle_overwrite (GtkEntry *entry)
5177 GtkEntryPrivate *priv = entry->priv;
5179 priv->overwrite_mode = !priv->overwrite_mode;
5180 gtk_entry_pend_cursor_blink (entry);
5181 gtk_widget_queue_draw (GTK_WIDGET (entry));
5185 gtk_entry_select_all (GtkEntry *entry)
5187 gtk_entry_select_line (entry);
5191 gtk_entry_real_activate (GtkEntry *entry)
5193 GtkEntryPrivate *priv = entry->priv;
5195 GtkWidget *default_widget, *focus_widget;
5196 GtkWidget *toplevel;
5199 widget = GTK_WIDGET (entry);
5201 if (priv->activates_default)
5203 toplevel = gtk_widget_get_toplevel (widget);
5204 if (GTK_IS_WINDOW (toplevel))
5206 window = GTK_WINDOW (toplevel);
5210 default_widget = gtk_window_get_default_widget (window);
5211 focus_widget = gtk_window_get_focus (window);
5212 if (widget != default_widget &&
5213 !(widget == focus_widget && (!default_widget || !gtk_widget_get_sensitive (default_widget))))
5214 gtk_window_activate_default (window);
5221 keymap_direction_changed (GdkKeymap *keymap,
5224 gtk_entry_recompute (entry);
5227 /* IM Context Callbacks
5231 gtk_entry_commit_cb (GtkIMContext *context,
5235 GtkEntryPrivate *priv = entry->priv;
5238 gtk_entry_enter_text (entry, str);
5242 gtk_entry_preedit_changed_cb (GtkIMContext *context,
5245 GtkEntryPrivate *priv = entry->priv;
5249 gchar *preedit_string;
5252 gtk_im_context_get_preedit_string (priv->im_context,
5253 &preedit_string, NULL,
5255 g_signal_emit (entry, signals[PREEDIT_CHANGED], 0, preedit_string);
5256 priv->preedit_length = strlen (preedit_string);
5257 cursor_pos = CLAMP (cursor_pos, 0, g_utf8_strlen (preedit_string, -1));
5258 priv->preedit_cursor = cursor_pos;
5259 g_free (preedit_string);
5261 gtk_entry_recompute (entry);
5266 gtk_entry_retrieve_surrounding_cb (GtkIMContext *context,
5269 GtkEntryPrivate *priv = entry->priv;
5272 /* XXXX ??? does this even make sense when text is not visible? Should we return FALSE? */
5273 text = gtk_entry_get_display_text (entry, 0, -1);
5274 gtk_im_context_set_surrounding (context, text, strlen (text), /* Length in bytes */
5275 g_utf8_offset_to_pointer (text, priv->current_pos) - text);
5282 gtk_entry_delete_surrounding_cb (GtkIMContext *slave,
5287 GtkEntryPrivate *priv = entry->priv;
5290 gtk_editable_delete_text (GTK_EDITABLE (entry),
5291 priv->current_pos + offset,
5292 priv->current_pos + offset + n_chars);
5297 /* Internal functions
5300 /* Used for im_commit_cb and inserting Unicode chars */
5302 gtk_entry_enter_text (GtkEntry *entry,
5305 GtkEntryPrivate *priv = entry->priv;
5306 GtkEditable *editable = GTK_EDITABLE (entry);
5308 gboolean old_need_im_reset;
5310 old_need_im_reset = priv->need_im_reset;
5311 priv->need_im_reset = FALSE;
5313 if (gtk_editable_get_selection_bounds (editable, NULL, NULL))
5314 gtk_editable_delete_selection (editable);
5317 if (priv->overwrite_mode)
5318 gtk_entry_delete_from_cursor (entry, GTK_DELETE_CHARS, 1);
5321 tmp_pos = priv->current_pos;
5322 gtk_editable_insert_text (editable, str, strlen (str), &tmp_pos);
5323 gtk_editable_set_position (editable, tmp_pos);
5325 priv->need_im_reset = old_need_im_reset;
5328 /* All changes to priv->current_pos and priv->selection_bound
5329 * should go through this function.
5332 gtk_entry_set_positions (GtkEntry *entry,
5334 gint selection_bound)
5336 GtkEntryPrivate *priv = entry->priv;
5337 gboolean changed = FALSE;
5339 g_object_freeze_notify (G_OBJECT (entry));
5341 if (current_pos != -1 &&
5342 priv->current_pos != current_pos)
5344 priv->current_pos = current_pos;
5347 g_object_notify (G_OBJECT (entry), "cursor-position");
5350 if (selection_bound != -1 &&
5351 priv->selection_bound != selection_bound)
5353 priv->selection_bound = selection_bound;
5356 g_object_notify (G_OBJECT (entry), "selection-bound");
5359 g_object_thaw_notify (G_OBJECT (entry));
5363 gtk_entry_move_adjustments (entry);
5364 gtk_entry_recompute (entry);
5369 gtk_entry_reset_layout (GtkEntry *entry)
5371 GtkEntryPrivate *priv = entry->priv;
5373 if (priv->cached_layout)
5375 g_object_unref (priv->cached_layout);
5376 priv->cached_layout = NULL;
5381 update_im_cursor_location (GtkEntry *entry)
5383 GtkEntryPrivate *priv = entry->priv;
5386 gint strong_xoffset;
5387 gint area_width, area_height;
5389 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
5390 gtk_entry_get_text_area_size (entry, NULL, NULL, &area_width, &area_height);
5392 strong_xoffset = strong_x - priv->scroll_offset;
5393 if (strong_xoffset < 0)
5397 else if (strong_xoffset > area_width)
5399 strong_xoffset = area_width;
5401 area.x = strong_xoffset;
5404 area.height = area_height;
5406 gtk_im_context_set_cursor_location (priv->im_context, &area);
5410 recompute_idle_func (gpointer data)
5412 GtkEntry *entry = GTK_ENTRY (data);
5413 GtkEntryPrivate *priv = entry->priv;
5415 priv->recompute_idle = 0;
5417 if (gtk_widget_has_screen (GTK_WIDGET (entry)))
5419 gtk_entry_adjust_scroll (entry);
5420 gtk_entry_queue_draw (entry);
5422 update_im_cursor_location (entry);
5429 gtk_entry_recompute (GtkEntry *entry)
5431 GtkEntryPrivate *priv = entry->priv;
5433 gtk_entry_reset_layout (entry);
5434 gtk_entry_check_cursor_blink (entry);
5436 if (!priv->recompute_idle)
5438 priv->recompute_idle = gdk_threads_add_idle_full (G_PRIORITY_HIGH_IDLE + 15, /* between resize and redraw */
5439 recompute_idle_func, entry, NULL);
5443 static PangoLayout *
5444 gtk_entry_create_layout (GtkEntry *entry,
5445 gboolean include_preedit)
5447 GtkEntryPrivate *priv = entry->priv;
5448 GtkWidget *widget = GTK_WIDGET (entry);
5449 PangoLayout *layout = gtk_widget_create_pango_layout (widget, NULL);
5450 PangoAttrList *tmp_attrs = pango_attr_list_new ();
5452 gchar *preedit_string = NULL;
5453 gint preedit_length = 0;
5454 PangoAttrList *preedit_attrs = NULL;
5459 pango_layout_set_single_paragraph_mode (layout, TRUE);
5461 display = gtk_entry_get_display_text (entry, 0, -1);
5462 n_bytes = strlen (display);
5464 if (include_preedit)
5466 gtk_im_context_get_preedit_string (priv->im_context,
5467 &preedit_string, &preedit_attrs, NULL);
5468 preedit_length = priv->preedit_length;
5473 GString *tmp_string = g_string_new (display);
5474 gint cursor_index = g_utf8_offset_to_pointer (display, priv->current_pos) - display;
5476 g_string_insert (tmp_string, cursor_index, preedit_string);
5478 pango_layout_set_text (layout, tmp_string->str, tmp_string->len);
5480 pango_attr_list_splice (tmp_attrs, preedit_attrs,
5481 cursor_index, preedit_length);
5483 g_string_free (tmp_string, TRUE);
5487 PangoDirection pango_dir;
5489 if (gtk_entry_get_display_mode (entry) == DISPLAY_NORMAL)
5490 pango_dir = pango_find_base_dir (display, n_bytes);
5492 pango_dir = PANGO_DIRECTION_NEUTRAL;
5494 if (pango_dir == PANGO_DIRECTION_NEUTRAL)
5496 if (gtk_widget_has_focus (widget))
5498 GdkDisplay *display = gtk_widget_get_display (widget);
5499 GdkKeymap *keymap = gdk_keymap_get_for_display (display);
5500 if (gdk_keymap_get_direction (keymap) == PANGO_DIRECTION_RTL)
5501 pango_dir = PANGO_DIRECTION_RTL;
5503 pango_dir = PANGO_DIRECTION_LTR;
5507 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
5508 pango_dir = PANGO_DIRECTION_RTL;
5510 pango_dir = PANGO_DIRECTION_LTR;
5514 pango_context_set_base_dir (gtk_widget_get_pango_context (widget),
5517 priv->resolved_dir = pango_dir;
5519 pango_layout_set_text (layout, display, n_bytes);
5522 pango_layout_set_attributes (layout, tmp_attrs);
5524 g_free (preedit_string);
5528 pango_attr_list_unref (preedit_attrs);
5530 pango_attr_list_unref (tmp_attrs);
5535 static PangoLayout *
5536 gtk_entry_ensure_layout (GtkEntry *entry,
5537 gboolean include_preedit)
5539 GtkEntryPrivate *priv = entry->priv;
5541 if (priv->preedit_length > 0 &&
5542 !include_preedit != !priv->cache_includes_preedit)
5543 gtk_entry_reset_layout (entry);
5545 if (!priv->cached_layout)
5547 priv->cached_layout = gtk_entry_create_layout (entry, include_preedit);
5548 priv->cache_includes_preedit = include_preedit;
5551 return priv->cached_layout;
5555 get_layout_position (GtkEntry *entry,
5559 GtkEntryPrivate *priv = entry->priv;
5560 PangoLayout *layout;
5561 PangoRectangle logical_rect;
5562 gint area_width, area_height;
5563 GtkBorder inner_border;
5565 PangoLayoutLine *line;
5567 layout = gtk_entry_ensure_layout (entry, TRUE);
5569 gtk_entry_get_text_area_size (entry, NULL, NULL, &area_width, &area_height);
5570 _gtk_entry_effective_inner_border (entry, &inner_border);
5572 area_height = PANGO_SCALE * (area_height - inner_border.top - inner_border.bottom);
5574 line = pango_layout_get_lines_readonly (layout)->data;
5575 pango_layout_line_get_extents (line, NULL, &logical_rect);
5577 /* Align primarily for locale's ascent/descent */
5578 y_pos = ((area_height - priv->ascent - priv->descent) / 2 +
5579 priv->ascent + logical_rect.y);
5581 /* Now see if we need to adjust to fit in actual drawn string */
5582 if (logical_rect.height > area_height)
5583 y_pos = (area_height - logical_rect.height) / 2;
5586 else if (y_pos + logical_rect.height > area_height)
5587 y_pos = area_height - logical_rect.height;
5589 y_pos = inner_border.top + y_pos / PANGO_SCALE;
5592 *x = inner_border.left - priv->scroll_offset;
5599 draw_text_with_color (GtkEntry *entry, cairo_t *cr, GdkColor *default_color)
5601 GtkEntryPrivate *priv = entry->priv;
5602 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
5605 gint start_pos, end_pos;
5607 widget = GTK_WIDGET (entry);
5611 get_layout_position (entry, &x, &y);
5613 cairo_move_to (cr, x, y);
5614 gdk_cairo_set_source_color (cr, default_color);
5615 pango_cairo_show_layout (cr, layout);
5617 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start_pos, &end_pos))
5621 PangoRectangle logical_rect;
5622 GdkColor *selection_color, *text_color;
5623 GtkBorder inner_border;
5626 pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
5627 gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
5629 style = gtk_widget_get_style (widget);
5631 if (gtk_widget_has_focus (widget))
5633 selection_color = &style->base [GTK_STATE_SELECTED];
5634 text_color = &style->text [GTK_STATE_SELECTED];
5638 selection_color = &style->base [GTK_STATE_ACTIVE];
5639 text_color = &style->text [GTK_STATE_ACTIVE];
5642 _gtk_entry_effective_inner_border (entry, &inner_border);
5644 for (i = 0; i < n_ranges; ++i)
5645 cairo_rectangle (cr,
5646 inner_border.left - priv->scroll_offset + ranges[2 * i],
5649 logical_rect.height);
5653 gdk_cairo_set_source_color (cr, selection_color);
5656 cairo_move_to (cr, x, y);
5657 gdk_cairo_set_source_color (cr, text_color);
5658 pango_cairo_show_layout (cr, layout);
5666 gtk_entry_draw_text (GtkEntry *entry,
5669 GtkEntryPrivate *priv = entry->priv;
5670 GtkWidget *widget = GTK_WIDGET (entry);
5673 GdkColor text_color, bar_text_color;
5676 gint progress_x, progress_y, progress_width, progress_height;
5677 gint clip_width, clip_height;
5679 /* Nothing to display at all */
5680 if (gtk_entry_get_display_mode (entry) == DISPLAY_BLANK)
5683 state = GTK_STATE_SELECTED;
5684 if (!gtk_widget_get_sensitive (widget))
5685 state = GTK_STATE_INSENSITIVE;
5686 style = gtk_widget_get_style (widget);
5687 text_color = style->text[gtk_widget_get_state (widget)];
5688 bar_text_color = style->fg[state];
5690 get_progress_area (widget,
5691 &progress_x, &progress_y,
5692 &progress_width, &progress_height);
5694 clip_width = gdk_window_get_width (priv->text_area);
5695 clip_height = gdk_window_get_height (priv->text_area);
5696 cairo_rectangle (cr, 0, 0, clip_width, clip_height);
5699 /* If the color is the same, or the progress area has a zero
5700 * size, then we only need to draw once. */
5701 if ((text_color.pixel == bar_text_color.pixel) ||
5702 ((progress_width == 0) || (progress_height == 0)))
5704 draw_text_with_color (entry, cr, &text_color);
5708 width = gdk_window_get_width (priv->text_area);
5709 height = gdk_window_get_height (priv->text_area);
5713 cairo_rectangle (cr, 0, 0, width, height);
5717 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
5718 cairo_rectangle (cr, 0, 0, width, height);
5720 gdk_window_get_position (priv->text_area, &pos_x, &pos_y);
5721 progress_x -= pos_x;
5722 progress_y -= pos_y;
5724 cairo_rectangle (cr, progress_x, progress_y,
5725 progress_width, progress_height);
5727 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_WINDING);
5729 draw_text_with_color (entry, cr, &text_color);
5732 cairo_rectangle (cr, progress_x, progress_y,
5733 progress_width, progress_height);
5736 draw_text_with_color (entry, cr, &bar_text_color);
5743 draw_insertion_cursor (GtkEntry *entry,
5745 GdkRectangle *cursor_location,
5746 gboolean is_primary,
5747 PangoDirection direction,
5748 gboolean draw_arrow)
5750 GtkWidget *widget = GTK_WIDGET (entry);
5751 GtkTextDirection text_dir;
5753 if (direction == PANGO_DIRECTION_LTR)
5754 text_dir = GTK_TEXT_DIR_LTR;
5756 text_dir = GTK_TEXT_DIR_RTL;
5758 gtk_draw_insertion_cursor (widget, cr,
5760 is_primary, text_dir, draw_arrow);
5764 gtk_entry_draw_cursor (GtkEntry *entry,
5768 GtkEntryPrivate *priv = entry->priv;
5769 GtkWidget *widget = GTK_WIDGET (entry);
5770 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
5771 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
5772 GdkRectangle cursor_location;
5773 gboolean split_cursor;
5774 PangoRectangle cursor_rect;
5775 GtkBorder inner_border;
5777 gint text_area_height;
5780 gboolean block_at_line_end;
5781 PangoLayout *layout;
5784 _gtk_entry_effective_inner_border (entry, &inner_border);
5786 xoffset = inner_border.left - priv->scroll_offset;
5788 text_area_height = gdk_window_get_height (priv->text_area);
5790 layout = gtk_entry_ensure_layout (entry, TRUE);
5791 text = pango_layout_get_text (layout);
5792 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos + priv->preedit_cursor) - text;
5793 if (!priv->overwrite_mode)
5796 block = _gtk_text_util_get_block_cursor_location (layout,
5797 cursor_index, &cursor_rect, &block_at_line_end);
5801 gint strong_x, weak_x;
5802 PangoDirection dir1 = PANGO_DIRECTION_NEUTRAL;
5803 PangoDirection dir2 = PANGO_DIRECTION_NEUTRAL;
5807 gtk_entry_get_cursor_locations (entry, type, &strong_x, &weak_x);
5809 g_object_get (gtk_widget_get_settings (widget),
5810 "gtk-split-cursor", &split_cursor,
5813 dir1 = priv->resolved_dir;
5819 if (weak_x != strong_x)
5821 dir2 = (priv->resolved_dir == PANGO_DIRECTION_LTR) ? PANGO_DIRECTION_RTL : PANGO_DIRECTION_LTR;
5827 if (keymap_direction == priv->resolved_dir)
5833 cursor_location.x = xoffset + x1;
5834 cursor_location.y = inner_border.top;
5835 cursor_location.width = 0;
5836 cursor_location.height = text_area_height - inner_border.top - inner_border.bottom;
5838 draw_insertion_cursor (entry, cr,
5839 &cursor_location, TRUE, dir1,
5840 dir2 != PANGO_DIRECTION_NEUTRAL);
5842 if (dir2 != PANGO_DIRECTION_NEUTRAL)
5844 cursor_location.x = xoffset + x2;
5845 draw_insertion_cursor (entry, cr,
5846 &cursor_location, FALSE, dir2,
5850 else /* overwrite_mode */
5852 GdkColor cursor_color;
5858 get_layout_position (entry, &x, &y);
5860 rect.x = PANGO_PIXELS (cursor_rect.x) + x;
5861 rect.y = PANGO_PIXELS (cursor_rect.y) + y;
5862 rect.width = PANGO_PIXELS (cursor_rect.width);
5863 rect.height = PANGO_PIXELS (cursor_rect.height);
5865 _gtk_widget_get_cursor_color (widget, &cursor_color);
5866 gdk_cairo_set_source_color (cr, &cursor_color);
5867 gdk_cairo_rectangle (cr, &rect);
5870 if (!block_at_line_end)
5872 gdk_cairo_rectangle (cr, &rect);
5874 cairo_move_to (cr, x, y);
5875 gdk_cairo_set_source_color (cr, >k_widget_get_style (widget)->base[gtk_widget_get_state (widget)]);
5876 pango_cairo_show_layout (cr, layout);
5884 gtk_entry_queue_draw (GtkEntry *entry)
5886 if (gtk_widget_is_drawable (GTK_WIDGET (entry)))
5887 gdk_window_invalidate_rect (gtk_widget_get_window (GTK_WIDGET (entry)),
5892 _gtk_entry_reset_im_context (GtkEntry *entry)
5894 GtkEntryPrivate *priv = entry->priv;
5896 if (priv->need_im_reset)
5898 priv->need_im_reset = FALSE;
5899 gtk_im_context_reset (priv->im_context);
5904 * gtk_entry_reset_im_context:
5905 * @entry: a #GtkEntry
5907 * Reset the input method context of the entry if needed.
5909 * This can be necessary in the case where modifying the buffer
5910 * would confuse on-going input method behavior.
5915 gtk_entry_reset_im_context (GtkEntry *entry)
5917 g_return_if_fail (GTK_IS_ENTRY (entry));
5919 _gtk_entry_reset_im_context (entry);
5923 * gtk_entry_im_context_filter_keypress:
5924 * @entry: a #GtkEntry
5925 * @event: the key event
5927 * Allow the #GtkEntry input method to internally handle key press
5928 * and release events. If this function returns %TRUE, then no further
5929 * processing should be done for this key event. See
5930 * gtk_im_context_filter_keypress().
5932 * Note that you are expected to call this function from your handler
5933 * when overriding key event handling. This is needed in the case when
5934 * you need to insert your own key handling between the input method
5935 * and the default key event handling of the #GtkEntry.
5936 * See gtk_text_view_reset_im_context() for an example of use.
5938 * Return value: %TRUE if the input method handled the key event.
5943 gtk_entry_im_context_filter_keypress (GtkEntry *entry,
5946 GtkEntryPrivate *priv;
5948 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
5952 return gtk_im_context_filter_keypress (priv->im_context, event);
5956 _gtk_entry_get_im_context (GtkEntry *entry)
5958 return entry->priv->im_context;
5962 gtk_entry_find_position (GtkEntry *entry,
5965 GtkEntryPrivate *priv = entry->priv;
5966 PangoLayout *layout;
5967 PangoLayoutLine *line;
5974 layout = gtk_entry_ensure_layout (entry, TRUE);
5975 text = pango_layout_get_text (layout);
5976 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos) - text;
5978 line = pango_layout_get_lines_readonly (layout)->data;
5979 pango_layout_line_x_to_index (line, x * PANGO_SCALE, &index, &trailing);
5981 if (index >= cursor_index && priv->preedit_length)
5983 if (index >= cursor_index + priv->preedit_length)
5984 index -= priv->preedit_length;
5987 index = cursor_index;
5992 pos = g_utf8_pointer_to_offset (text, text + index);
5999 gtk_entry_get_cursor_locations (GtkEntry *entry,
6004 GtkEntryPrivate *priv = entry->priv;
6005 DisplayMode mode = gtk_entry_get_display_mode (entry);
6007 /* Nothing to display at all, so no cursor is relevant */
6008 if (mode == DISPLAY_BLANK)
6018 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
6019 const gchar *text = pango_layout_get_text (layout);
6020 PangoRectangle strong_pos, weak_pos;
6023 if (type == CURSOR_STANDARD)
6025 index = g_utf8_offset_to_pointer (text, priv->current_pos + priv->preedit_cursor) - text;
6027 else /* type == CURSOR_DND */
6029 index = g_utf8_offset_to_pointer (text, priv->dnd_position) - text;
6031 if (priv->dnd_position > priv->current_pos)
6033 if (mode == DISPLAY_NORMAL)
6034 index += priv->preedit_length;
6037 gint preedit_len_chars = g_utf8_strlen (text, -1) - gtk_entry_buffer_get_length (get_buffer (entry));
6038 index += preedit_len_chars * g_unichar_to_utf8 (priv->invisible_char, NULL);
6043 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
6046 *strong_x = strong_pos.x / PANGO_SCALE;
6049 *weak_x = weak_pos.x / PANGO_SCALE;
6054 gtk_entry_adjust_scroll (GtkEntry *entry)
6056 GtkEntryPrivate *priv = entry->priv;
6057 gint min_offset, max_offset;
6058 gint text_area_width, text_width;
6059 GtkBorder inner_border;
6060 gint strong_x, weak_x;
6061 gint strong_xoffset, weak_xoffset;
6063 PangoLayout *layout;
6064 PangoLayoutLine *line;
6065 PangoRectangle logical_rect;
6067 if (!gtk_widget_get_realized (GTK_WIDGET (entry)))
6070 _gtk_entry_effective_inner_border (entry, &inner_border);
6072 text_area_width = gdk_window_get_width (priv->text_area);
6073 text_area_width -= inner_border.left + inner_border.right;
6074 if (text_area_width < 0)
6075 text_area_width = 0;
6077 layout = gtk_entry_ensure_layout (entry, TRUE);
6078 line = pango_layout_get_lines_readonly (layout)->data;
6080 pango_layout_line_get_extents (line, NULL, &logical_rect);
6082 /* Display as much text as we can */
6084 if (priv->resolved_dir == PANGO_DIRECTION_LTR)
6085 xalign = priv->xalign;
6087 xalign = 1.0 - priv->xalign;
6089 text_width = PANGO_PIXELS(logical_rect.width);
6091 if (text_width > text_area_width)
6094 max_offset = text_width - text_area_width;
6098 min_offset = (text_width - text_area_width) * xalign;
6099 max_offset = min_offset;
6102 priv->scroll_offset = CLAMP (priv->scroll_offset, min_offset, max_offset);
6104 /* And make sure cursors are on screen. Note that the cursor is
6105 * actually drawn one pixel into the INNER_BORDER space on
6106 * the right, when the scroll is at the utmost right. This
6107 * looks better to to me than confining the cursor inside the
6108 * border entirely, though it means that the cursor gets one
6109 * pixel closer to the edge of the widget on the right than
6110 * on the left. This might need changing if one changed
6111 * INNER_BORDER from 2 to 1, as one would do on a
6112 * small-screen-real-estate display.
6114 * We always make sure that the strong cursor is on screen, and
6115 * put the weak cursor on screen if possible.
6118 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, &weak_x);
6120 strong_xoffset = strong_x - priv->scroll_offset;
6122 if (strong_xoffset < 0)
6124 priv->scroll_offset += strong_xoffset;
6127 else if (strong_xoffset > text_area_width)
6129 priv->scroll_offset += strong_xoffset - text_area_width;
6130 strong_xoffset = text_area_width;
6133 weak_xoffset = weak_x - priv->scroll_offset;
6135 if (weak_xoffset < 0 && strong_xoffset - weak_xoffset <= text_area_width)
6137 priv->scroll_offset += weak_xoffset;
6139 else if (weak_xoffset > text_area_width &&
6140 strong_xoffset - (weak_xoffset - text_area_width) >= 0)
6142 priv->scroll_offset += weak_xoffset - text_area_width;
6145 g_object_notify (G_OBJECT (entry), "scroll-offset");
6149 gtk_entry_move_adjustments (GtkEntry *entry)
6151 GtkWidget *widget = GTK_WIDGET (entry);
6152 GtkAllocation allocation;
6153 GtkAdjustment *adjustment;
6154 PangoContext *context;
6155 PangoFontMetrics *metrics;
6156 gint x, layout_x, border_x, border_y;
6159 adjustment = g_object_get_qdata (G_OBJECT (entry), quark_cursor_hadjustment);
6163 gtk_widget_get_allocation (widget, &allocation);
6165 /* Cursor position, layout offset, border width, and widget allocation */
6166 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &x, NULL);
6167 get_layout_position (entry, &layout_x, NULL);
6168 _gtk_entry_get_borders (entry, &border_x, &border_y);
6169 x += allocation.x + layout_x + border_x;
6171 /* Approximate width of a char, so user can see what is ahead/behind */
6172 context = gtk_widget_get_pango_context (widget);
6173 metrics = pango_context_get_metrics (context,
6174 gtk_widget_get_style (widget)->font_desc,
6175 pango_context_get_language (context));
6176 char_width = pango_font_metrics_get_approximate_char_width (metrics) / PANGO_SCALE;
6179 gtk_adjustment_clamp_page (adjustment,
6180 x - (char_width + 1), /* one char + one pixel before */
6181 x + (char_width + 2)); /* one char + cursor + one pixel after */
6185 gtk_entry_move_visually (GtkEntry *entry,
6189 GtkEntryPrivate *priv = entry->priv;
6191 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6194 text = pango_layout_get_text (layout);
6196 index = g_utf8_offset_to_pointer (text, start) - text;
6200 int new_index, new_trailing;
6201 gboolean split_cursor;
6204 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
6205 "gtk-split-cursor", &split_cursor,
6212 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
6213 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
6215 strong = keymap_direction == priv->resolved_dir;
6220 pango_layout_move_cursor_visually (layout, strong, index, 0, 1, &new_index, &new_trailing);
6225 pango_layout_move_cursor_visually (layout, strong, index, 0, -1, &new_index, &new_trailing);
6231 else if (new_index != G_MAXINT)
6234 while (new_trailing--)
6235 index = g_utf8_next_char (text + index) - text;
6238 return g_utf8_pointer_to_offset (text, text + index);
6242 gtk_entry_move_logically (GtkEntry *entry,
6246 gint new_pos = start;
6249 length = gtk_entry_buffer_get_length (get_buffer (entry));
6251 /* Prevent any leak of information */
6252 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6254 new_pos = CLAMP (start + count, 0, length);
6258 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6259 PangoLogAttr *log_attrs;
6262 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6264 while (count > 0 && new_pos < length)
6268 while (new_pos < length && !log_attrs[new_pos].is_cursor_position);
6272 while (count < 0 && new_pos > 0)
6276 while (new_pos > 0 && !log_attrs[new_pos].is_cursor_position);
6288 gtk_entry_move_forward_word (GtkEntry *entry,
6290 gboolean allow_whitespace)
6292 gint new_pos = start;
6295 length = gtk_entry_buffer_get_length (get_buffer (entry));
6297 /* Prevent any leak of information */
6298 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6302 else if (new_pos < length)
6304 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6305 PangoLogAttr *log_attrs;
6308 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6310 /* Find the next word boundary */
6312 while (new_pos < n_attrs - 1 && !(log_attrs[new_pos].is_word_end ||
6313 (log_attrs[new_pos].is_word_start && allow_whitespace)))
6324 gtk_entry_move_backward_word (GtkEntry *entry,
6326 gboolean allow_whitespace)
6328 gint new_pos = start;
6330 /* Prevent any leak of information */
6331 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6337 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6338 PangoLogAttr *log_attrs;
6341 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6343 new_pos = start - 1;
6345 /* Find the previous word boundary */
6346 while (new_pos > 0 && !(log_attrs[new_pos].is_word_start ||
6347 (log_attrs[new_pos].is_word_end && allow_whitespace)))
6357 gtk_entry_delete_whitespace (GtkEntry *entry)
6359 GtkEntryPrivate *priv = entry->priv;
6360 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6361 PangoLogAttr *log_attrs;
6365 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6367 start = end = priv->current_pos;
6369 while (start > 0 && log_attrs[start-1].is_white)
6372 while (end < n_attrs && log_attrs[end].is_white)
6378 gtk_editable_delete_text (GTK_EDITABLE (entry), start, end);
6383 gtk_entry_select_word (GtkEntry *entry)
6385 GtkEntryPrivate *priv = entry->priv;
6386 gint start_pos = gtk_entry_move_backward_word (entry, priv->current_pos, TRUE);
6387 gint end_pos = gtk_entry_move_forward_word (entry, priv->current_pos, TRUE);
6389 gtk_editable_select_region (GTK_EDITABLE (entry), start_pos, end_pos);
6393 gtk_entry_select_line (GtkEntry *entry)
6395 gtk_editable_select_region (GTK_EDITABLE (entry), 0, -1);
6399 truncate_multiline (const gchar *text)
6404 text[length] && text[length] != '\n' && text[length] != '\r';
6411 paste_received (GtkClipboard *clipboard,
6415 GtkEntry *entry = GTK_ENTRY (data);
6416 GtkEditable *editable = GTK_EDITABLE (entry);
6417 GtkEntryPrivate *priv = entry->priv;
6419 if (priv->button == 2)
6421 gint pos, start, end;
6422 pos = priv->insert_pos;
6423 gtk_editable_get_selection_bounds (editable, &start, &end);
6424 if (!((start <= pos && pos <= end) || (end <= pos && pos <= start)))
6425 gtk_editable_select_region (editable, pos, pos);
6430 gint pos, start, end;
6432 gboolean popup_completion;
6433 GtkEntryCompletion *completion;
6435 completion = gtk_entry_get_completion (entry);
6437 if (priv->truncate_multiline)
6438 length = truncate_multiline (text);
6440 /* only complete if the selection is at the end */
6441 popup_completion = (gtk_entry_buffer_get_length (get_buffer (entry)) ==
6442 MAX (priv->current_pos, priv->selection_bound));
6446 if (gtk_widget_get_mapped (completion->priv->popup_window))
6447 _gtk_entry_completion_popdown (completion);
6449 if (!popup_completion && completion->priv->changed_id > 0)
6450 g_signal_handler_block (entry, completion->priv->changed_id);
6453 begin_change (entry);
6454 g_object_freeze_notify (G_OBJECT (entry));
6455 if (gtk_editable_get_selection_bounds (editable, &start, &end))
6456 gtk_editable_delete_text (editable, start, end);
6458 pos = priv->current_pos;
6459 gtk_editable_insert_text (editable, text, length, &pos);
6460 gtk_editable_set_position (editable, pos);
6461 g_object_thaw_notify (G_OBJECT (entry));
6465 !popup_completion && completion->priv->changed_id > 0)
6466 g_signal_handler_unblock (entry, completion->priv->changed_id);
6469 g_object_unref (entry);
6473 gtk_entry_paste (GtkEntry *entry,
6476 g_object_ref (entry);
6477 gtk_clipboard_request_text (gtk_widget_get_clipboard (GTK_WIDGET (entry), selection),
6478 paste_received, entry);
6482 primary_get_cb (GtkClipboard *clipboard,
6483 GtkSelectionData *selection_data,
6487 GtkEntry *entry = GTK_ENTRY (data);
6490 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end))
6492 gchar *str = gtk_entry_get_display_text (entry, start, end);
6493 gtk_selection_data_set_text (selection_data, str, -1);
6499 primary_clear_cb (GtkClipboard *clipboard,
6502 GtkEntry *entry = GTK_ENTRY (data);
6503 GtkEntryPrivate *priv = entry->priv;
6505 gtk_editable_select_region (GTK_EDITABLE (entry), priv->current_pos, priv->current_pos);
6509 gtk_entry_update_primary_selection (GtkEntry *entry)
6511 GtkTargetList *list;
6512 GtkTargetEntry *targets;
6513 GtkClipboard *clipboard;
6517 if (!gtk_widget_get_realized (GTK_WIDGET (entry)))
6520 list = gtk_target_list_new (NULL, 0);
6521 gtk_target_list_add_text_targets (list, 0);
6523 targets = gtk_target_table_new_from_list (list, &n_targets);
6525 clipboard = gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_PRIMARY);
6527 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end))
6529 if (!gtk_clipboard_set_with_owner (clipboard, targets, n_targets,
6530 primary_get_cb, primary_clear_cb, G_OBJECT (entry)))
6531 primary_clear_cb (clipboard, entry);
6535 if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (entry))
6536 gtk_clipboard_clear (clipboard);
6539 gtk_target_table_free (targets, n_targets);
6540 gtk_target_list_unref (list);
6544 gtk_entry_clear (GtkEntry *entry,
6545 GtkEntryIconPosition icon_pos)
6547 GtkEntryPrivate *priv = entry->priv;
6548 EntryIconInfo *icon_info = priv->icons[icon_pos];
6550 if (!icon_info || icon_info->storage_type == GTK_IMAGE_EMPTY)
6553 g_object_freeze_notify (G_OBJECT (entry));
6555 /* Explicitly check, as the pointer may become invalidated
6556 * during destruction.
6558 if (GDK_IS_WINDOW (icon_info->window))
6559 gdk_window_hide (icon_info->window);
6561 if (icon_info->pixbuf)
6563 g_object_unref (icon_info->pixbuf);
6564 icon_info->pixbuf = NULL;
6567 switch (icon_info->storage_type)
6569 case GTK_IMAGE_PIXBUF:
6570 g_object_notify (G_OBJECT (entry),
6571 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-pixbuf" : "secondary-icon-pixbuf");
6574 case GTK_IMAGE_STOCK:
6575 g_free (icon_info->stock_id);
6576 icon_info->stock_id = NULL;
6577 g_object_notify (G_OBJECT (entry),
6578 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-stock" : "secondary-icon-stock");
6581 case GTK_IMAGE_ICON_NAME:
6582 g_free (icon_info->icon_name);
6583 icon_info->icon_name = NULL;
6584 g_object_notify (G_OBJECT (entry),
6585 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-name" : "secondary-icon-name");
6588 case GTK_IMAGE_GICON:
6589 if (icon_info->gicon)
6591 g_object_unref (icon_info->gicon);
6592 icon_info->gicon = NULL;
6594 g_object_notify (G_OBJECT (entry),
6595 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-gicon" : "secondary-icon-gicon");
6599 g_assert_not_reached ();
6603 icon_info->storage_type = GTK_IMAGE_EMPTY;
6604 g_object_notify (G_OBJECT (entry),
6605 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-storage-type" : "secondary-icon-storage-type");
6607 g_object_thaw_notify (G_OBJECT (entry));
6611 gtk_entry_ensure_pixbuf (GtkEntry *entry,
6612 GtkEntryIconPosition icon_pos)
6614 GtkEntryPrivate *priv = entry->priv;
6615 EntryIconInfo *icon_info = priv->icons[icon_pos];
6617 GtkIconTheme *icon_theme;
6618 GtkSettings *settings;
6619 GtkStateFlags state;
6624 if (!icon_info || icon_info->pixbuf)
6627 widget = GTK_WIDGET (entry);
6629 switch (icon_info->storage_type)
6631 case GTK_IMAGE_EMPTY:
6632 case GTK_IMAGE_PIXBUF:
6634 case GTK_IMAGE_STOCK:
6635 state = gtk_widget_get_state_flags (widget);
6636 gtk_widget_set_state_flags (widget, 0, TRUE);
6637 icon_info->pixbuf = gtk_widget_render_icon (widget,
6638 icon_info->stock_id,
6641 if (!icon_info->pixbuf)
6642 icon_info->pixbuf = gtk_widget_render_icon (widget,
6643 GTK_STOCK_MISSING_IMAGE,
6646 gtk_widget_set_state_flags (widget, state, TRUE);
6649 case GTK_IMAGE_ICON_NAME:
6650 screen = gtk_widget_get_screen (widget);
6653 icon_theme = gtk_icon_theme_get_for_screen (screen);
6654 settings = gtk_settings_get_for_screen (screen);
6656 gtk_icon_size_lookup_for_settings (settings,
6660 icon_info->pixbuf = gtk_icon_theme_load_icon (icon_theme,
6661 icon_info->icon_name,
6662 MIN (width, height),
6665 if (icon_info->pixbuf == NULL)
6667 state = gtk_widget_get_state_flags (widget);
6668 gtk_widget_set_state_flags (widget, 0, TRUE);
6669 icon_info->pixbuf = gtk_widget_render_icon (widget,
6670 GTK_STOCK_MISSING_IMAGE,
6673 gtk_widget_set_state_flags (widget, state, TRUE);
6678 case GTK_IMAGE_GICON:
6679 screen = gtk_widget_get_screen (widget);
6682 icon_theme = gtk_icon_theme_get_for_screen (screen);
6683 settings = gtk_settings_get_for_screen (screen);
6685 gtk_icon_size_lookup_for_settings (settings,
6689 info = gtk_icon_theme_lookup_by_gicon (icon_theme,
6691 MIN (width, height),
6692 GTK_ICON_LOOKUP_USE_BUILTIN);
6695 icon_info->pixbuf = gtk_icon_info_load_icon (info, NULL);
6696 gtk_icon_info_free (info);
6699 if (icon_info->pixbuf == NULL)
6701 state = gtk_widget_get_state_flags (widget);
6702 gtk_widget_set_state_flags (widget, 0, TRUE);
6703 icon_info->pixbuf = gtk_widget_render_icon (widget,
6704 GTK_STOCK_MISSING_IMAGE,
6707 gtk_widget_set_state_flags (widget, state, TRUE);
6713 g_assert_not_reached ();
6717 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
6718 gdk_window_show_unraised (icon_info->window);
6728 * Creates a new entry.
6730 * Return value: a new #GtkEntry.
6733 gtk_entry_new (void)
6735 return g_object_new (GTK_TYPE_ENTRY, NULL);
6739 * gtk_entry_new_with_buffer:
6740 * @buffer: The buffer to use for the new #GtkEntry.
6742 * Creates a new entry with the specified text buffer.
6744 * Return value: a new #GtkEntry
6749 gtk_entry_new_with_buffer (GtkEntryBuffer *buffer)
6751 g_return_val_if_fail (GTK_IS_ENTRY_BUFFER (buffer), NULL);
6752 return g_object_new (GTK_TYPE_ENTRY, "buffer", buffer, NULL);
6755 static GtkEntryBuffer*
6756 get_buffer (GtkEntry *entry)
6758 GtkEntryPrivate *priv = entry->priv;
6760 if (priv->buffer == NULL)
6762 GtkEntryBuffer *buffer;
6763 buffer = gtk_entry_buffer_new (NULL, 0);
6764 gtk_entry_set_buffer (entry, buffer);
6765 g_object_unref (buffer);
6768 return priv->buffer;
6772 * gtk_entry_get_buffer:
6773 * @entry: a #GtkEntry
6775 * Get the #GtkEntryBuffer object which holds the text for
6780 * Returns: (transfer none): A #GtkEntryBuffer object.
6783 gtk_entry_get_buffer (GtkEntry *entry)
6785 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
6787 return get_buffer (entry);
6791 * gtk_entry_set_buffer:
6792 * @entry: a #GtkEntry
6793 * @buffer: a #GtkEntryBuffer
6795 * Set the #GtkEntryBuffer object which holds the text for
6801 gtk_entry_set_buffer (GtkEntry *entry,
6802 GtkEntryBuffer *buffer)
6804 GtkEntryPrivate *priv;
6807 g_return_if_fail (GTK_IS_ENTRY (entry));
6813 g_return_if_fail (GTK_IS_ENTRY_BUFFER (buffer));
6814 g_object_ref (buffer);
6819 buffer_disconnect_signals (entry);
6820 g_object_unref (priv->buffer);
6823 priv->buffer = buffer;
6826 buffer_connect_signals (entry);
6828 obj = G_OBJECT (entry);
6829 g_object_freeze_notify (obj);
6830 g_object_notify (obj, "buffer");
6831 g_object_notify (obj, "text");
6832 g_object_notify (obj, "text-length");
6833 g_object_notify (obj, "max-length");
6834 g_object_notify (obj, "visibility");
6835 g_object_notify (obj, "invisible-char");
6836 g_object_notify (obj, "invisible-char-set");
6837 g_object_thaw_notify (obj);
6839 gtk_editable_set_position (GTK_EDITABLE (entry), 0);
6840 gtk_entry_recompute (entry);
6844 * gtk_entry_get_text_area:
6845 * @entry: a #GtkEntry
6846 * @text_area: Return location for the text area.
6848 * Gets the area where the entry's text is drawn. This function is
6849 * useful when drawing something to the entry in a draw callback.
6851 * If the entry is not realized, @text_area is filled with zeros.
6853 * See also gtk_entry_get_icon_area().
6858 gtk_entry_get_text_area (GtkEntry *entry,
6859 GdkRectangle *text_area)
6861 GtkEntryPrivate *priv;
6863 g_return_if_fail (GTK_IS_ENTRY (entry));
6864 g_return_if_fail (text_area != NULL);
6868 if (priv->text_area)
6870 GtkAllocation allocation;
6873 gtk_widget_get_allocation (GTK_WIDGET (entry), &allocation);
6874 gdk_window_get_position (priv->text_area, &x, &y);
6876 text_area->x = x - allocation.x;
6877 text_area->y = y - allocation.y;
6878 text_area->width = gdk_window_get_width (priv->text_area);
6879 text_area->height = gdk_window_get_height (priv->text_area);
6885 text_area->width = 0;
6886 text_area->height = 0;
6891 * gtk_entry_set_text:
6892 * @entry: a #GtkEntry
6893 * @text: the new text
6895 * Sets the text in the widget to the given
6896 * value, replacing the current contents.
6898 * See gtk_entry_buffer_set_text().
6901 gtk_entry_set_text (GtkEntry *entry,
6905 GtkEntryCompletion *completion;
6907 g_return_if_fail (GTK_IS_ENTRY (entry));
6908 g_return_if_fail (text != NULL);
6910 /* Actually setting the text will affect the cursor and selection;
6911 * if the contents don't actually change, this will look odd to the user.
6913 if (strcmp (gtk_entry_buffer_get_text (get_buffer (entry)), text) == 0)
6916 completion = gtk_entry_get_completion (entry);
6917 if (completion && completion->priv->changed_id > 0)
6918 g_signal_handler_block (entry, completion->priv->changed_id);
6920 begin_change (entry);
6921 g_object_freeze_notify (G_OBJECT (entry));
6922 gtk_editable_delete_text (GTK_EDITABLE (entry), 0, -1);
6924 gtk_editable_insert_text (GTK_EDITABLE (entry), text, strlen (text), &tmp_pos);
6925 g_object_thaw_notify (G_OBJECT (entry));
6928 if (completion && completion->priv->changed_id > 0)
6929 g_signal_handler_unblock (entry, completion->priv->changed_id);
6933 * gtk_entry_set_visibility:
6934 * @entry: a #GtkEntry
6935 * @visible: %TRUE if the contents of the entry are displayed
6938 * Sets whether the contents of the entry are visible or not.
6939 * When visibility is set to %FALSE, characters are displayed
6940 * as the invisible char, and will also appear that way when
6941 * the text in the entry widget is copied elsewhere.
6943 * By default, GTK+ picks the best invisible character available
6944 * in the current font, but it can be changed with
6945 * gtk_entry_set_invisible_char().
6948 gtk_entry_set_visibility (GtkEntry *entry,
6951 GtkEntryPrivate *priv;
6953 g_return_if_fail (GTK_IS_ENTRY (entry));
6957 visible = visible != FALSE;
6959 if (priv->visible != visible)
6961 priv->visible = visible;
6963 g_object_notify (G_OBJECT (entry), "visibility");
6964 gtk_entry_recompute (entry);
6969 * gtk_entry_get_visibility:
6970 * @entry: a #GtkEntry
6972 * Retrieves whether the text in @entry is visible. See
6973 * gtk_entry_set_visibility().
6975 * Return value: %TRUE if the text is currently visible
6978 gtk_entry_get_visibility (GtkEntry *entry)
6980 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
6982 return entry->priv->visible;
6986 * gtk_entry_set_invisible_char:
6987 * @entry: a #GtkEntry
6988 * @ch: a Unicode character
6990 * Sets the character to use in place of the actual text when
6991 * gtk_entry_set_visibility() has been called to set text visibility
6992 * to %FALSE. i.e. this is the character used in "password mode" to
6993 * show the user how many characters have been typed. By default, GTK+
6994 * picks the best invisible char available in the current font. If you
6995 * set the invisible char to 0, then the user will get no feedback
6996 * at all; there will be no text on the screen as they type.
6999 gtk_entry_set_invisible_char (GtkEntry *entry,
7002 GtkEntryPrivate *priv;
7004 g_return_if_fail (GTK_IS_ENTRY (entry));
7008 if (!priv->invisible_char_set)
7010 priv->invisible_char_set = TRUE;
7011 g_object_notify (G_OBJECT (entry), "invisible-char-set");
7014 if (ch == priv->invisible_char)
7017 priv->invisible_char = ch;
7018 g_object_notify (G_OBJECT (entry), "invisible-char");
7019 gtk_entry_recompute (entry);
7023 * gtk_entry_get_invisible_char:
7024 * @entry: a #GtkEntry
7026 * Retrieves the character displayed in place of the real characters
7027 * for entries with visibility set to false. See gtk_entry_set_invisible_char().
7029 * Return value: the current invisible char, or 0, if the entry does not
7030 * show invisible text at all.
7033 gtk_entry_get_invisible_char (GtkEntry *entry)
7035 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7037 return entry->priv->invisible_char;
7041 * gtk_entry_unset_invisible_char:
7042 * @entry: a #GtkEntry
7044 * Unsets the invisible char previously set with
7045 * gtk_entry_set_invisible_char(). So that the
7046 * default invisible char is used again.
7051 gtk_entry_unset_invisible_char (GtkEntry *entry)
7053 GtkEntryPrivate *priv;
7056 g_return_if_fail (GTK_IS_ENTRY (entry));
7060 if (!priv->invisible_char_set)
7063 priv->invisible_char_set = FALSE;
7064 ch = find_invisible_char (GTK_WIDGET (entry));
7066 if (priv->invisible_char != ch)
7068 priv->invisible_char = ch;
7069 g_object_notify (G_OBJECT (entry), "invisible-char");
7072 g_object_notify (G_OBJECT (entry), "invisible-char-set");
7073 gtk_entry_recompute (entry);
7077 * gtk_entry_set_overwrite_mode:
7078 * @entry: a #GtkEntry
7079 * @overwrite: new value
7081 * Sets whether the text is overwritten when typing in the #GtkEntry.
7086 gtk_entry_set_overwrite_mode (GtkEntry *entry,
7089 GtkEntryPrivate *priv = entry->priv;
7091 g_return_if_fail (GTK_IS_ENTRY (entry));
7093 if (priv->overwrite_mode == overwrite)
7096 gtk_entry_toggle_overwrite (entry);
7098 g_object_notify (G_OBJECT (entry), "overwrite-mode");
7102 * gtk_entry_get_overwrite_mode:
7103 * @entry: a #GtkEntry
7105 * Gets the value set by gtk_entry_set_overwrite_mode().
7107 * Return value: whether the text is overwritten when typing.
7112 gtk_entry_get_overwrite_mode (GtkEntry *entry)
7114 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7116 return entry->priv->overwrite_mode;
7120 * gtk_entry_get_text:
7121 * @entry: a #GtkEntry
7123 * Retrieves the contents of the entry widget.
7124 * See also gtk_editable_get_chars().
7126 * This is equivalent to:
7128 * <informalexample><programlisting>
7129 * gtk_entry_buffer_get_text (gtk_entry_get_buffer (entry));
7130 * </programlisting></informalexample>
7132 * Return value: a pointer to the contents of the widget as a
7133 * string. This string points to internally allocated
7134 * storage in the widget and must not be freed, modified or
7137 G_CONST_RETURN gchar*
7138 gtk_entry_get_text (GtkEntry *entry)
7140 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7142 return gtk_entry_buffer_get_text (get_buffer (entry));
7146 * gtk_entry_set_max_length:
7147 * @entry: a #GtkEntry
7148 * @max: the maximum length of the entry, or 0 for no maximum.
7149 * (other than the maximum length of entries.) The value passed in will
7150 * be clamped to the range 0-65536.
7152 * Sets the maximum allowed length of the contents of the widget. If
7153 * the current contents are longer than the given length, then they
7154 * will be truncated to fit.
7156 * This is equivalent to:
7158 * <informalexample><programlisting>
7159 * gtk_entry_buffer_set_max_length (gtk_entry_get_buffer (entry), max);
7160 * </programlisting></informalexample>
7163 gtk_entry_set_max_length (GtkEntry *entry,
7166 g_return_if_fail (GTK_IS_ENTRY (entry));
7167 gtk_entry_buffer_set_max_length (get_buffer (entry), max);
7171 * gtk_entry_get_max_length:
7172 * @entry: a #GtkEntry
7174 * Retrieves the maximum allowed length of the text in
7175 * @entry. See gtk_entry_set_max_length().
7177 * This is equivalent to:
7179 * <informalexample><programlisting>
7180 * gtk_entry_buffer_get_max_length (gtk_entry_get_buffer (entry));
7181 * </programlisting></informalexample>
7183 * Return value: the maximum allowed number of characters
7184 * in #GtkEntry, or 0 if there is no maximum.
7187 gtk_entry_get_max_length (GtkEntry *entry)
7189 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7191 return gtk_entry_buffer_get_max_length (get_buffer (entry));
7195 * gtk_entry_get_text_length:
7196 * @entry: a #GtkEntry
7198 * Retrieves the current length of the text in
7201 * This is equivalent to:
7203 * <informalexample><programlisting>
7204 * gtk_entry_buffer_get_length (gtk_entry_get_buffer (entry));
7205 * </programlisting></informalexample>
7207 * Return value: the current number of characters
7208 * in #GtkEntry, or 0 if there are none.
7213 gtk_entry_get_text_length (GtkEntry *entry)
7215 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7217 return gtk_entry_buffer_get_length (get_buffer (entry));
7221 * gtk_entry_set_activates_default:
7222 * @entry: a #GtkEntry
7223 * @setting: %TRUE to activate window's default widget on Enter keypress
7225 * If @setting is %TRUE, pressing Enter in the @entry will activate the default
7226 * widget for the window containing the entry. This usually means that
7227 * the dialog box containing the entry will be closed, since the default
7228 * widget is usually one of the dialog buttons.
7230 * (For experts: if @setting is %TRUE, the entry calls
7231 * gtk_window_activate_default() on the window containing the entry, in
7232 * the default handler for the #GtkWidget::activate signal.)
7235 gtk_entry_set_activates_default (GtkEntry *entry,
7238 GtkEntryPrivate *priv;
7240 g_return_if_fail (GTK_IS_ENTRY (entry));
7244 setting = setting != FALSE;
7246 if (setting != priv->activates_default)
7248 priv->activates_default = setting;
7249 g_object_notify (G_OBJECT (entry), "activates-default");
7254 * gtk_entry_get_activates_default:
7255 * @entry: a #GtkEntry
7257 * Retrieves the value set by gtk_entry_set_activates_default().
7259 * Return value: %TRUE if the entry will activate the default widget
7262 gtk_entry_get_activates_default (GtkEntry *entry)
7264 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7266 return entry->priv->activates_default;
7270 * gtk_entry_set_width_chars:
7271 * @entry: a #GtkEntry
7272 * @n_chars: width in chars
7274 * Changes the size request of the entry to be about the right size
7275 * for @n_chars characters. Note that it changes the size
7276 * <emphasis>request</emphasis>, the size can still be affected by
7277 * how you pack the widget into containers. If @n_chars is -1, the
7278 * size reverts to the default entry size.
7281 gtk_entry_set_width_chars (GtkEntry *entry,
7284 GtkEntryPrivate *priv;
7286 g_return_if_fail (GTK_IS_ENTRY (entry));
7290 if (priv->width_chars != n_chars)
7292 priv->width_chars = n_chars;
7293 g_object_notify (G_OBJECT (entry), "width-chars");
7294 gtk_widget_queue_resize (GTK_WIDGET (entry));
7299 * gtk_entry_get_width_chars:
7300 * @entry: a #GtkEntry
7302 * Gets the value set by gtk_entry_set_width_chars().
7304 * Return value: number of chars to request space for, or negative if unset
7307 gtk_entry_get_width_chars (GtkEntry *entry)
7309 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7311 return entry->priv->width_chars;
7315 * gtk_entry_set_has_frame:
7316 * @entry: a #GtkEntry
7317 * @setting: new value
7319 * Sets whether the entry has a beveled frame around it.
7322 gtk_entry_set_has_frame (GtkEntry *entry,
7325 GtkEntryPrivate *priv;
7327 g_return_if_fail (GTK_IS_ENTRY (entry));
7331 setting = (setting != FALSE);
7333 if (priv->has_frame == setting)
7336 gtk_widget_queue_resize (GTK_WIDGET (entry));
7337 priv->has_frame = setting;
7338 g_object_notify (G_OBJECT (entry), "has-frame");
7342 * gtk_entry_get_has_frame:
7343 * @entry: a #GtkEntry
7345 * Gets the value set by gtk_entry_set_has_frame().
7347 * Return value: whether the entry has a beveled frame
7350 gtk_entry_get_has_frame (GtkEntry *entry)
7352 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7354 return entry->priv->has_frame;
7358 * gtk_entry_set_inner_border:
7359 * @entry: a #GtkEntry
7360 * @border: (allow-none): a #GtkBorder, or %NULL
7362 * Sets %entry's inner-border property to %border, or clears it if %NULL
7363 * is passed. The inner-border is the area around the entry's text, but
7366 * If set, this property overrides the inner-border style property.
7367 * Overriding the style-provided border is useful when you want to do
7368 * in-place editing of some text in a canvas or list widget, where
7369 * pixel-exact positioning of the entry is important.
7374 gtk_entry_set_inner_border (GtkEntry *entry,
7375 const GtkBorder *border)
7377 g_return_if_fail (GTK_IS_ENTRY (entry));
7379 gtk_widget_queue_resize (GTK_WIDGET (entry));
7382 g_object_set_qdata_full (G_OBJECT (entry), quark_inner_border,
7383 gtk_border_copy (border),
7384 (GDestroyNotify) gtk_border_free);
7386 g_object_set_qdata (G_OBJECT (entry), quark_inner_border, NULL);
7388 g_object_notify (G_OBJECT (entry), "inner-border");
7392 * gtk_entry_get_inner_border:
7393 * @entry: a #GtkEntry
7395 * This function returns the entry's #GtkEntry:inner-border property. See
7396 * gtk_entry_set_inner_border() for more information.
7398 * Return value: (transfer none): the entry's #GtkBorder, or %NULL if none was set.
7402 G_CONST_RETURN GtkBorder *
7403 gtk_entry_get_inner_border (GtkEntry *entry)
7405 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7407 return g_object_get_qdata (G_OBJECT (entry), quark_inner_border);
7411 * gtk_entry_get_layout:
7412 * @entry: a #GtkEntry
7414 * Gets the #PangoLayout used to display the entry.
7415 * The layout is useful to e.g. convert text positions to
7416 * pixel positions, in combination with gtk_entry_get_layout_offsets().
7417 * The returned layout is owned by the entry and must not be
7418 * modified or freed by the caller.
7420 * Keep in mind that the layout text may contain a preedit string, so
7421 * gtk_entry_layout_index_to_text_index() and
7422 * gtk_entry_text_index_to_layout_index() are needed to convert byte
7423 * indices in the layout to byte indices in the entry contents.
7425 * Return value: (transfer none): the #PangoLayout for this entry
7428 gtk_entry_get_layout (GtkEntry *entry)
7430 PangoLayout *layout;
7432 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7434 layout = gtk_entry_ensure_layout (entry, TRUE);
7441 * gtk_entry_layout_index_to_text_index:
7442 * @entry: a #GtkEntry
7443 * @layout_index: byte index into the entry layout text
7445 * Converts from a position in the entry contents (returned
7446 * by gtk_entry_get_text()) to a position in the
7447 * entry's #PangoLayout (returned by gtk_entry_get_layout(),
7448 * with text retrieved via pango_layout_get_text()).
7450 * Return value: byte index into the entry contents
7453 gtk_entry_layout_index_to_text_index (GtkEntry *entry,
7456 GtkEntryPrivate *priv;
7457 PangoLayout *layout;
7461 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7465 layout = gtk_entry_ensure_layout (entry, TRUE);
7466 text = pango_layout_get_text (layout);
7467 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos) - text;
7469 if (layout_index >= cursor_index && priv->preedit_length)
7471 if (layout_index >= cursor_index + priv->preedit_length)
7472 layout_index -= priv->preedit_length;
7474 layout_index = cursor_index;
7477 return layout_index;
7481 * gtk_entry_text_index_to_layout_index:
7482 * @entry: a #GtkEntry
7483 * @text_index: byte index into the entry contents
7485 * Converts from a position in the entry's #PangoLayout (returned by
7486 * gtk_entry_get_layout()) to a position in the entry contents
7487 * (returned by gtk_entry_get_text()).
7489 * Return value: byte index into the entry layout text
7492 gtk_entry_text_index_to_layout_index (GtkEntry *entry,
7495 GtkEntryPrivate *priv;
7496 PangoLayout *layout;
7500 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7504 layout = gtk_entry_ensure_layout (entry, TRUE);
7505 text = pango_layout_get_text (layout);
7506 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos) - text;
7508 if (text_index > cursor_index)
7509 text_index += priv->preedit_length;
7515 * gtk_entry_get_layout_offsets:
7516 * @entry: a #GtkEntry
7517 * @x: (allow-none): location to store X offset of layout, or %NULL
7518 * @y: (allow-none): location to store Y offset of layout, or %NULL
7521 * Obtains the position of the #PangoLayout used to render text
7522 * in the entry, in widget coordinates. Useful if you want to line
7523 * up the text in an entry with some other text, e.g. when using the
7524 * entry to implement editable cells in a sheet widget.
7526 * Also useful to convert mouse events into coordinates inside the
7527 * #PangoLayout, e.g. to take some action if some part of the entry text
7530 * Note that as the user scrolls around in the entry the offsets will
7531 * change; you'll need to connect to the "notify::scroll-offset"
7532 * signal to track this. Remember when using the #PangoLayout
7533 * functions you need to convert to and from pixels using
7534 * PANGO_PIXELS() or #PANGO_SCALE.
7536 * Keep in mind that the layout text may contain a preedit string, so
7537 * gtk_entry_layout_index_to_text_index() and
7538 * gtk_entry_text_index_to_layout_index() are needed to convert byte
7539 * indices in the layout to byte indices in the entry contents.
7542 gtk_entry_get_layout_offsets (GtkEntry *entry,
7546 gint text_area_x, text_area_y;
7548 g_return_if_fail (GTK_IS_ENTRY (entry));
7550 /* this gets coords relative to text area */
7551 get_layout_position (entry, x, y);
7553 /* convert to widget coords */
7554 gtk_entry_get_text_area_size (entry, &text_area_x, &text_area_y, NULL, NULL);
7565 * gtk_entry_set_alignment:
7566 * @entry: a #GtkEntry
7567 * @xalign: The horizontal alignment, from 0 (left) to 1 (right).
7568 * Reversed for RTL layouts
7570 * Sets the alignment for the contents of the entry. This controls
7571 * the horizontal positioning of the contents when the displayed
7572 * text is shorter than the width of the entry.
7577 gtk_entry_set_alignment (GtkEntry *entry, gfloat xalign)
7579 GtkEntryPrivate *priv;
7581 g_return_if_fail (GTK_IS_ENTRY (entry));
7587 else if (xalign > 1.0)
7590 if (xalign != priv->xalign)
7592 priv->xalign = xalign;
7594 gtk_entry_recompute (entry);
7596 g_object_notify (G_OBJECT (entry), "xalign");
7601 * gtk_entry_get_alignment:
7602 * @entry: a #GtkEntry
7604 * Gets the value set by gtk_entry_set_alignment().
7606 * Return value: the alignment
7611 gtk_entry_get_alignment (GtkEntry *entry)
7613 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
7615 return entry->priv->xalign;
7619 * gtk_entry_set_icon_from_pixbuf:
7620 * @entry: a #GtkEntry
7621 * @icon_pos: Icon position
7622 * @pixbuf: (allow-none): A #GdkPixbuf, or %NULL
7624 * Sets the icon shown in the specified position using a pixbuf.
7626 * If @pixbuf is %NULL, no icon will be shown in the specified position.
7631 gtk_entry_set_icon_from_pixbuf (GtkEntry *entry,
7632 GtkEntryIconPosition icon_pos,
7635 GtkEntryPrivate *priv;
7636 EntryIconInfo *icon_info;
7638 g_return_if_fail (GTK_IS_ENTRY (entry));
7639 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7643 if ((icon_info = priv->icons[icon_pos]) == NULL)
7644 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7646 g_object_freeze_notify (G_OBJECT (entry));
7649 g_object_ref (pixbuf);
7651 gtk_entry_clear (entry, icon_pos);
7655 icon_info->storage_type = GTK_IMAGE_PIXBUF;
7656 icon_info->pixbuf = pixbuf;
7658 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7660 g_object_notify (G_OBJECT (entry), "primary-icon-pixbuf");
7661 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7665 g_object_notify (G_OBJECT (entry), "secondary-icon-pixbuf");
7666 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7669 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7670 gdk_window_show_unraised (icon_info->window);
7673 gtk_entry_ensure_pixbuf (entry, icon_pos);
7675 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7676 gtk_widget_queue_resize (GTK_WIDGET (entry));
7678 g_object_thaw_notify (G_OBJECT (entry));
7682 * gtk_entry_set_icon_from_stock:
7683 * @entry: A #GtkEntry
7684 * @icon_pos: Icon position
7685 * @stock_id: (allow-none): The name of the stock item, or %NULL
7687 * Sets the icon shown in the entry at the specified position from
7690 * If @stock_id is %NULL, no icon will be shown in the specified position.
7695 gtk_entry_set_icon_from_stock (GtkEntry *entry,
7696 GtkEntryIconPosition icon_pos,
7697 const gchar *stock_id)
7699 GtkEntryPrivate *priv;
7700 EntryIconInfo *icon_info;
7703 g_return_if_fail (GTK_IS_ENTRY (entry));
7704 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7708 if ((icon_info = priv->icons[icon_pos]) == NULL)
7709 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7711 g_object_freeze_notify (G_OBJECT (entry));
7713 gtk_widget_ensure_style (GTK_WIDGET (entry));
7715 /* need to dup before clearing */
7716 new_id = g_strdup (stock_id);
7718 gtk_entry_clear (entry, icon_pos);
7722 icon_info->storage_type = GTK_IMAGE_STOCK;
7723 icon_info->stock_id = new_id;
7725 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7727 g_object_notify (G_OBJECT (entry), "primary-icon-stock");
7728 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7732 g_object_notify (G_OBJECT (entry), "secondary-icon-stock");
7733 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7736 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7737 gdk_window_show_unraised (icon_info->window);
7740 gtk_entry_ensure_pixbuf (entry, icon_pos);
7742 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7743 gtk_widget_queue_resize (GTK_WIDGET (entry));
7745 g_object_thaw_notify (G_OBJECT (entry));
7749 * gtk_entry_set_icon_from_icon_name:
7750 * @entry: A #GtkEntry
7751 * @icon_pos: The position at which to set the icon
7752 * @icon_name: (allow-none): An icon name, or %NULL
7754 * Sets the icon shown in the entry at the specified position
7755 * from the current icon theme.
7757 * If the icon name isn't known, a "broken image" icon will be displayed
7760 * If @icon_name is %NULL, no icon will be shown in the specified position.
7765 gtk_entry_set_icon_from_icon_name (GtkEntry *entry,
7766 GtkEntryIconPosition icon_pos,
7767 const gchar *icon_name)
7769 GtkEntryPrivate *priv;
7770 EntryIconInfo *icon_info;
7773 g_return_if_fail (GTK_IS_ENTRY (entry));
7774 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7778 if ((icon_info = priv->icons[icon_pos]) == NULL)
7779 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7781 g_object_freeze_notify (G_OBJECT (entry));
7783 gtk_widget_ensure_style (GTK_WIDGET (entry));
7785 /* need to dup before clearing */
7786 new_name = g_strdup (icon_name);
7788 gtk_entry_clear (entry, icon_pos);
7790 if (new_name != NULL)
7792 icon_info->storage_type = GTK_IMAGE_ICON_NAME;
7793 icon_info->icon_name = new_name;
7795 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7797 g_object_notify (G_OBJECT (entry), "primary-icon-name");
7798 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7802 g_object_notify (G_OBJECT (entry), "secondary-icon-name");
7803 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7806 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7807 gdk_window_show_unraised (icon_info->window);
7810 gtk_entry_ensure_pixbuf (entry, icon_pos);
7812 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7813 gtk_widget_queue_resize (GTK_WIDGET (entry));
7815 g_object_thaw_notify (G_OBJECT (entry));
7819 * gtk_entry_set_icon_from_gicon:
7820 * @entry: A #GtkEntry
7821 * @icon_pos: The position at which to set the icon
7822 * @icon: (allow-none): The icon to set, or %NULL
7824 * Sets the icon shown in the entry at the specified position
7825 * from the current icon theme.
7826 * If the icon isn't known, a "broken image" icon will be displayed
7829 * If @icon is %NULL, no icon will be shown in the specified position.
7834 gtk_entry_set_icon_from_gicon (GtkEntry *entry,
7835 GtkEntryIconPosition icon_pos,
7838 GtkEntryPrivate *priv;
7839 EntryIconInfo *icon_info;
7841 g_return_if_fail (GTK_IS_ENTRY (entry));
7842 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7846 if ((icon_info = priv->icons[icon_pos]) == NULL)
7847 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7849 g_object_freeze_notify (G_OBJECT (entry));
7851 /* need to ref before clearing */
7853 g_object_ref (icon);
7855 gtk_entry_clear (entry, icon_pos);
7859 icon_info->storage_type = GTK_IMAGE_GICON;
7860 icon_info->gicon = icon;
7862 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7864 g_object_notify (G_OBJECT (entry), "primary-icon-gicon");
7865 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7869 g_object_notify (G_OBJECT (entry), "secondary-icon-gicon");
7870 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7873 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7874 gdk_window_show_unraised (icon_info->window);
7877 gtk_entry_ensure_pixbuf (entry, icon_pos);
7879 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7880 gtk_widget_queue_resize (GTK_WIDGET (entry));
7882 g_object_thaw_notify (G_OBJECT (entry));
7886 * gtk_entry_set_icon_activatable:
7887 * @entry: A #GtkEntry
7888 * @icon_pos: Icon position
7889 * @activatable: %TRUE if the icon should be activatable
7891 * Sets whether the icon is activatable.
7896 gtk_entry_set_icon_activatable (GtkEntry *entry,
7897 GtkEntryIconPosition icon_pos,
7898 gboolean activatable)
7900 GtkEntryPrivate *priv;
7901 EntryIconInfo *icon_info;
7903 g_return_if_fail (GTK_IS_ENTRY (entry));
7904 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7908 if ((icon_info = priv->icons[icon_pos]) == NULL)
7909 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7911 activatable = activatable != FALSE;
7913 if (icon_info->nonactivatable != !activatable)
7915 icon_info->nonactivatable = !activatable;
7917 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
7918 update_cursors (GTK_WIDGET (entry));
7920 g_object_notify (G_OBJECT (entry),
7921 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-activatable" : "secondary-icon-activatable");
7926 * gtk_entry_get_icon_activatable:
7927 * @entry: a #GtkEntry
7928 * @icon_pos: Icon position
7930 * Returns whether the icon is activatable.
7932 * Returns: %TRUE if the icon is activatable.
7937 gtk_entry_get_icon_activatable (GtkEntry *entry,
7938 GtkEntryIconPosition icon_pos)
7940 GtkEntryPrivate *priv;
7941 EntryIconInfo *icon_info;
7943 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7944 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), FALSE);
7947 icon_info = priv->icons[icon_pos];
7949 return (icon_info != NULL && !icon_info->nonactivatable);
7953 * gtk_entry_get_icon_pixbuf:
7954 * @entry: A #GtkEntry
7955 * @icon_pos: Icon position
7957 * Retrieves the image used for the icon.
7959 * Unlike the other methods of setting and getting icon data, this
7960 * method will work regardless of whether the icon was set using a
7961 * #GdkPixbuf, a #GIcon, a stock item, or an icon name.
7963 * Returns: (transfer none): A #GdkPixbuf, or %NULL if no icon is
7964 * set for this position.
7969 gtk_entry_get_icon_pixbuf (GtkEntry *entry,
7970 GtkEntryIconPosition icon_pos)
7972 GtkEntryPrivate *priv;
7973 EntryIconInfo *icon_info;
7975 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7976 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7980 icon_info = priv->icons[icon_pos];
7985 gtk_entry_ensure_pixbuf (entry, icon_pos);
7987 return icon_info->pixbuf;
7991 * gtk_entry_get_icon_gicon:
7992 * @entry: A #GtkEntry
7993 * @icon_pos: Icon position
7995 * Retrieves the #GIcon used for the icon, or %NULL if there is
7996 * no icon or if the icon was set by some other method (e.g., by
7997 * stock, pixbuf, or icon name).
7999 * Returns: (transfer none): A #GIcon, or %NULL if no icon is set
8000 * or if the icon is not a #GIcon
8005 gtk_entry_get_icon_gicon (GtkEntry *entry,
8006 GtkEntryIconPosition icon_pos)
8008 GtkEntryPrivate *priv;
8009 EntryIconInfo *icon_info;
8011 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8012 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8015 icon_info = priv->icons[icon_pos];
8020 return icon_info->storage_type == GTK_IMAGE_GICON ? icon_info->gicon : NULL;
8024 * gtk_entry_get_icon_stock:
8025 * @entry: A #GtkEntry
8026 * @icon_pos: Icon position
8028 * Retrieves the stock id used for the icon, or %NULL if there is
8029 * no icon or if the icon was set by some other method (e.g., by
8030 * pixbuf, icon name or gicon).
8032 * Returns: A stock id, or %NULL if no icon is set or if the icon
8033 * wasn't set from a stock id
8038 gtk_entry_get_icon_stock (GtkEntry *entry,
8039 GtkEntryIconPosition icon_pos)
8041 GtkEntryPrivate *priv;
8042 EntryIconInfo *icon_info;
8044 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8045 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8048 icon_info = priv->icons[icon_pos];
8053 return icon_info->storage_type == GTK_IMAGE_STOCK ? icon_info->stock_id : NULL;
8057 * gtk_entry_get_icon_name:
8058 * @entry: A #GtkEntry
8059 * @icon_pos: Icon position
8061 * Retrieves the icon name used for the icon, or %NULL if there is
8062 * no icon or if the icon was set by some other method (e.g., by
8063 * pixbuf, stock or gicon).
8065 * Returns: An icon name, or %NULL if no icon is set or if the icon
8066 * wasn't set from an icon name
8071 gtk_entry_get_icon_name (GtkEntry *entry,
8072 GtkEntryIconPosition icon_pos)
8074 GtkEntryPrivate *priv;
8075 EntryIconInfo *icon_info;
8077 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8078 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8081 icon_info = priv->icons[icon_pos];
8086 return icon_info->storage_type == GTK_IMAGE_ICON_NAME ? icon_info->icon_name : NULL;
8090 * gtk_entry_set_icon_sensitive:
8091 * @entry: A #GtkEntry
8092 * @icon_pos: Icon position
8093 * @sensitive: Specifies whether the icon should appear
8094 * sensitive or insensitive
8096 * Sets the sensitivity for the specified icon.
8101 gtk_entry_set_icon_sensitive (GtkEntry *entry,
8102 GtkEntryIconPosition icon_pos,
8105 GtkEntryPrivate *priv;
8106 EntryIconInfo *icon_info;
8108 g_return_if_fail (GTK_IS_ENTRY (entry));
8109 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8113 if ((icon_info = priv->icons[icon_pos]) == NULL)
8114 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8116 if (icon_info->insensitive != !sensitive)
8118 icon_info->insensitive = !sensitive;
8120 icon_info->pressed = FALSE;
8121 icon_info->prelight = FALSE;
8123 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
8124 update_cursors (GTK_WIDGET (entry));
8126 gtk_widget_queue_draw (GTK_WIDGET (entry));
8128 g_object_notify (G_OBJECT (entry),
8129 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-sensitive" : "secondary-icon-sensitive");
8134 * gtk_entry_get_icon_sensitive:
8135 * @entry: a #GtkEntry
8136 * @icon_pos: Icon position
8138 * Returns whether the icon appears sensitive or insensitive.
8140 * Returns: %TRUE if the icon is sensitive.
8145 gtk_entry_get_icon_sensitive (GtkEntry *entry,
8146 GtkEntryIconPosition icon_pos)
8148 GtkEntryPrivate *priv;
8149 EntryIconInfo *icon_info;
8151 g_return_val_if_fail (GTK_IS_ENTRY (entry), TRUE);
8152 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), TRUE);
8156 icon_info = priv->icons[icon_pos];
8158 return (!icon_info || !icon_info->insensitive);
8163 * gtk_entry_get_icon_storage_type:
8164 * @entry: a #GtkEntry
8165 * @icon_pos: Icon position
8167 * Gets the type of representation being used by the icon
8168 * to store image data. If the icon has no image data,
8169 * the return value will be %GTK_IMAGE_EMPTY.
8171 * Return value: image representation being used
8176 gtk_entry_get_icon_storage_type (GtkEntry *entry,
8177 GtkEntryIconPosition icon_pos)
8179 GtkEntryPrivate *priv;
8180 EntryIconInfo *icon_info;
8182 g_return_val_if_fail (GTK_IS_ENTRY (entry), GTK_IMAGE_EMPTY);
8183 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), GTK_IMAGE_EMPTY);
8187 icon_info = priv->icons[icon_pos];
8190 return GTK_IMAGE_EMPTY;
8192 return icon_info->storage_type;
8196 * gtk_entry_get_icon_at_pos:
8197 * @entry: a #GtkEntry
8198 * @x: the x coordinate of the position to find
8199 * @y: the y coordinate of the position to find
8201 * Finds the icon at the given position and return its index.
8202 * If @x, @y doesn't lie inside an icon, -1 is returned.
8203 * This function is intended for use in a #GtkWidget::query-tooltip
8206 * Returns: the index of the icon at the given position, or -1
8211 gtk_entry_get_icon_at_pos (GtkEntry *entry,
8215 GtkAllocation primary;
8216 GtkAllocation secondary;
8217 gint frame_x, frame_y;
8219 g_return_val_if_fail (GTK_IS_ENTRY (entry), -1);
8221 get_frame_size (entry, &frame_x, &frame_y, NULL, NULL);
8225 get_icon_allocations (entry, &primary, &secondary);
8227 if (primary.x <= x && x < primary.x + primary.width &&
8228 primary.y <= y && y < primary.y + primary.height)
8229 return GTK_ENTRY_ICON_PRIMARY;
8231 if (secondary.x <= x && x < secondary.x + secondary.width &&
8232 secondary.y <= y && y < secondary.y + secondary.height)
8233 return GTK_ENTRY_ICON_SECONDARY;
8239 * gtk_entry_set_icon_drag_source:
8240 * @entry: a #GtkIconEntry
8241 * @icon_pos: icon position
8242 * @target_list: the targets (data formats) in which the data can be provided
8243 * @actions: a bitmask of the allowed drag actions
8245 * Sets up the icon at the given position so that GTK+ will start a drag
8246 * operation when the user clicks and drags the icon.
8248 * To handle the drag operation, you need to connect to the usual
8249 * #GtkWidget::drag-data-get (or possibly #GtkWidget::drag-data-delete)
8250 * signal, and use gtk_entry_get_current_icon_drag_source() in
8251 * your signal handler to find out if the drag was started from
8254 * By default, GTK+ uses the icon as the drag icon. You can use the
8255 * #GtkWidget::drag-begin signal to set a different icon. Note that you
8256 * have to use g_signal_connect_after() to ensure that your signal handler
8257 * gets executed after the default handler.
8262 gtk_entry_set_icon_drag_source (GtkEntry *entry,
8263 GtkEntryIconPosition icon_pos,
8264 GtkTargetList *target_list,
8265 GdkDragAction actions)
8267 GtkEntryPrivate *priv;
8268 EntryIconInfo *icon_info;
8270 g_return_if_fail (GTK_IS_ENTRY (entry));
8271 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8275 if ((icon_info = priv->icons[icon_pos]) == NULL)
8276 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8278 if (icon_info->target_list)
8279 gtk_target_list_unref (icon_info->target_list);
8280 icon_info->target_list = target_list;
8281 if (icon_info->target_list)
8282 gtk_target_list_ref (icon_info->target_list);
8284 icon_info->actions = actions;
8288 * gtk_entry_get_current_icon_drag_source:
8289 * @entry: a #GtkIconEntry
8291 * Returns the index of the icon which is the source of the current
8292 * DND operation, or -1.
8294 * This function is meant to be used in a #GtkWidget::drag-data-get
8297 * Returns: index of the icon which is the source of the current
8298 * DND operation, or -1.
8303 gtk_entry_get_current_icon_drag_source (GtkEntry *entry)
8305 GtkEntryPrivate *priv;
8306 EntryIconInfo *icon_info = NULL;
8309 g_return_val_if_fail (GTK_IS_ENTRY (entry), -1);
8313 for (i = 0; i < MAX_ICONS; i++)
8315 if ((icon_info = priv->icons[i]))
8317 if (icon_info->in_drag)
8326 * gtk_entry_get_icon_area:
8327 * @entry: A #GtkEntry
8328 * @icon_pos: Icon position
8329 * @icon_area: Return location for the icon's area
8331 * Gets the area where entry's icon at @icon_pos is drawn.
8332 * This function is useful when drawing something to the
8333 * entry in a draw callback.
8335 * If the entry is not realized or has no icon at the given position,
8336 * @icon_area is filled with zeros.
8338 * See also gtk_entry_get_text_area()
8343 gtk_entry_get_icon_area (GtkEntry *entry,
8344 GtkEntryIconPosition icon_pos,
8345 GdkRectangle *icon_area)
8347 GtkEntryPrivate *priv;
8348 EntryIconInfo *icon_info;
8350 g_return_if_fail (GTK_IS_ENTRY (entry));
8351 g_return_if_fail (icon_area != NULL);
8355 icon_info = priv->icons[icon_pos];
8359 GtkAllocation primary;
8360 GtkAllocation secondary;
8362 get_icon_allocations (entry, &primary, &secondary);
8364 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
8365 *icon_area = primary;
8367 *icon_area = secondary;
8373 icon_area->width = 0;
8374 icon_area->height = 0;
8379 ensure_has_tooltip (GtkEntry *entry)
8381 GtkEntryPrivate *priv;
8382 EntryIconInfo *icon_info;
8384 gboolean has_tooltip = FALSE;
8388 for (i = 0; i < MAX_ICONS; i++)
8390 if ((icon_info = priv->icons[i]) != NULL)
8392 if (icon_info->tooltip != NULL)
8400 gtk_widget_set_has_tooltip (GTK_WIDGET (entry), has_tooltip);
8404 * gtk_entry_get_icon_tooltip_text:
8405 * @entry: a #GtkEntry
8406 * @icon_pos: the icon position
8408 * Gets the contents of the tooltip on the icon at the specified
8409 * position in @entry.
8411 * Returns: the tooltip text, or %NULL. Free the returned string
8412 * with g_free() when done.
8417 gtk_entry_get_icon_tooltip_text (GtkEntry *entry,
8418 GtkEntryIconPosition icon_pos)
8420 GtkEntryPrivate *priv;
8421 EntryIconInfo *icon_info;
8424 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8425 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8429 icon_info = priv->icons[icon_pos];
8434 if (icon_info->tooltip &&
8435 !pango_parse_markup (icon_info->tooltip, -1, 0, NULL, &text, NULL, NULL))
8436 g_assert (NULL == text); /* text should still be NULL in case of markup errors */
8442 * gtk_entry_set_icon_tooltip_text:
8443 * @entry: a #GtkEntry
8444 * @icon_pos: the icon position
8445 * @tooltip: (allow-none): the contents of the tooltip for the icon, or %NULL
8447 * Sets @tooltip as the contents of the tooltip for the icon
8448 * at the specified position.
8450 * Use %NULL for @tooltip to remove an existing tooltip.
8452 * See also gtk_widget_set_tooltip_text() and
8453 * gtk_entry_set_icon_tooltip_markup().
8458 gtk_entry_set_icon_tooltip_text (GtkEntry *entry,
8459 GtkEntryIconPosition icon_pos,
8460 const gchar *tooltip)
8462 GtkEntryPrivate *priv;
8463 EntryIconInfo *icon_info;
8465 g_return_if_fail (GTK_IS_ENTRY (entry));
8466 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8470 if (!(icon_info = priv->icons[icon_pos]))
8471 icon_info = priv->icons[icon_pos];
8473 if (icon_info->tooltip)
8474 g_free (icon_info->tooltip);
8476 /* Treat an empty string as a NULL string,
8477 * because an empty string would be useless for a tooltip:
8479 if (tooltip && tooltip[0] == '\0')
8482 icon_info->tooltip = tooltip ? g_markup_escape_text (tooltip, -1) : NULL;
8484 ensure_has_tooltip (entry);
8488 * gtk_entry_get_icon_tooltip_markup:
8489 * @entry: a #GtkEntry
8490 * @icon_pos: the icon position
8492 * Gets the contents of the tooltip on the icon at the specified
8493 * position in @entry.
8495 * Returns: the tooltip text, or %NULL. Free the returned string
8496 * with g_free() when done.
8501 gtk_entry_get_icon_tooltip_markup (GtkEntry *entry,
8502 GtkEntryIconPosition icon_pos)
8504 GtkEntryPrivate *priv;
8505 EntryIconInfo *icon_info;
8507 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8508 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8512 icon_info = priv->icons[icon_pos];
8517 return g_strdup (icon_info->tooltip);
8521 * gtk_entry_set_icon_tooltip_markup:
8522 * @entry: a #GtkEntry
8523 * @icon_pos: the icon position
8524 * @tooltip: (allow-none): the contents of the tooltip for the icon, or %NULL
8526 * Sets @tooltip as the contents of the tooltip for the icon at
8527 * the specified position. @tooltip is assumed to be marked up with
8528 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
8530 * Use %NULL for @tooltip to remove an existing tooltip.
8532 * See also gtk_widget_set_tooltip_markup() and
8533 * gtk_enty_set_icon_tooltip_text().
8538 gtk_entry_set_icon_tooltip_markup (GtkEntry *entry,
8539 GtkEntryIconPosition icon_pos,
8540 const gchar *tooltip)
8542 GtkEntryPrivate *priv;
8543 EntryIconInfo *icon_info;
8545 g_return_if_fail (GTK_IS_ENTRY (entry));
8546 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8550 if (!(icon_info = priv->icons[icon_pos]))
8551 icon_info = priv->icons[icon_pos];
8553 if (icon_info->tooltip)
8554 g_free (icon_info->tooltip);
8556 /* Treat an empty string as a NULL string,
8557 * because an empty string would be useless for a tooltip:
8559 if (tooltip && tooltip[0] == '\0')
8562 icon_info->tooltip = g_strdup (tooltip);
8564 ensure_has_tooltip (entry);
8568 gtk_entry_query_tooltip (GtkWidget *widget,
8571 gboolean keyboard_tip,
8572 GtkTooltip *tooltip)
8575 GtkEntryPrivate *priv;
8576 EntryIconInfo *icon_info;
8579 entry = GTK_ENTRY (widget);
8584 icon_pos = gtk_entry_get_icon_at_pos (entry, x, y);
8587 if ((icon_info = priv->icons[icon_pos]) != NULL)
8589 if (icon_info->tooltip)
8591 gtk_tooltip_set_markup (tooltip, icon_info->tooltip);
8600 return GTK_WIDGET_CLASS (gtk_entry_parent_class)->query_tooltip (widget,
8607 /* Quick hack of a popup menu
8610 activate_cb (GtkWidget *menuitem,
8613 const gchar *signal = g_object_get_data (G_OBJECT (menuitem), "gtk-signal");
8614 g_signal_emit_by_name (entry, signal);
8619 gtk_entry_mnemonic_activate (GtkWidget *widget,
8620 gboolean group_cycling)
8622 gtk_widget_grab_focus (widget);
8627 append_action_signal (GtkEntry *entry,
8629 const gchar *stock_id,
8630 const gchar *signal,
8633 GtkWidget *menuitem = gtk_image_menu_item_new_from_stock (stock_id, NULL);
8635 g_object_set_data (G_OBJECT (menuitem), I_("gtk-signal"), (char *)signal);
8636 g_signal_connect (menuitem, "activate",
8637 G_CALLBACK (activate_cb), entry);
8639 gtk_widget_set_sensitive (menuitem, sensitive);
8641 gtk_widget_show (menuitem);
8642 gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
8646 popup_menu_detach (GtkWidget *attach_widget,
8649 GtkEntry *entry_attach = GTK_ENTRY (attach_widget);
8650 GtkEntryPrivate *priv_attach = entry_attach->priv;
8652 priv_attach->popup_menu = NULL;
8656 popup_position_func (GtkMenu *menu,
8662 GtkEntry *entry = GTK_ENTRY (user_data);
8663 GtkEntryPrivate *priv = entry->priv;
8664 GtkWidget *widget = GTK_WIDGET (entry);
8666 GtkRequisition menu_req;
8667 GdkRectangle monitor;
8668 GtkBorder inner_border;
8669 gint monitor_num, strong_x, height;
8671 g_return_if_fail (gtk_widget_get_realized (widget));
8673 gdk_window_get_origin (priv->text_area, x, y);
8675 screen = gtk_widget_get_screen (widget);
8676 monitor_num = gdk_screen_get_monitor_at_window (screen, priv->text_area);
8677 if (monitor_num < 0)
8679 gtk_menu_set_monitor (menu, monitor_num);
8681 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
8682 gtk_widget_get_preferred_size (priv->popup_menu,
8684 height = gdk_window_get_height (priv->text_area);
8685 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
8686 _gtk_entry_effective_inner_border (entry, &inner_border);
8688 *x += inner_border.left + strong_x - priv->scroll_offset;
8689 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
8690 *x -= menu_req.width;
8692 if ((*y + height + menu_req.height) <= monitor.y + monitor.height)
8694 else if ((*y - menu_req.height) >= monitor.y)
8695 *y -= menu_req.height;
8696 else if (monitor.y + monitor.height - (*y + height) > *y)
8699 *y -= menu_req.height;
8705 unichar_chosen_func (const char *text,
8708 GtkEntry *entry = GTK_ENTRY (data);
8709 GtkEntryPrivate *priv = entry->priv;
8712 gtk_entry_enter_text (entry, text);
8723 popup_targets_received (GtkClipboard *clipboard,
8724 GtkSelectionData *data,
8727 PopupInfo *info = user_data;
8728 GtkEntry *entry = info->entry;
8729 GtkEntryPrivate *info_entry_priv = entry->priv;
8731 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
8734 gboolean clipboard_contains_text;
8735 GtkWidget *menuitem;
8737 gboolean show_input_method_menu;
8738 gboolean show_unicode_menu;
8740 clipboard_contains_text = gtk_selection_data_targets_include_text (data);
8741 if (info_entry_priv->popup_menu)
8742 gtk_widget_destroy (info_entry_priv->popup_menu);
8744 info_entry_priv->popup_menu = gtk_menu_new ();
8746 gtk_menu_attach_to_widget (GTK_MENU (info_entry_priv->popup_menu),
8750 mode = gtk_entry_get_display_mode (entry);
8751 append_action_signal (entry, info_entry_priv->popup_menu, GTK_STOCK_CUT, "cut-clipboard",
8752 info_entry_priv->editable && mode == DISPLAY_NORMAL &&
8753 info_entry_priv->current_pos != info_entry_priv->selection_bound);
8755 append_action_signal (entry, info_entry_priv->popup_menu, GTK_STOCK_COPY, "copy-clipboard",
8756 mode == DISPLAY_NORMAL &&
8757 info_entry_priv->current_pos != info_entry_priv->selection_bound);
8759 append_action_signal (entry, info_entry_priv->popup_menu, GTK_STOCK_PASTE, "paste-clipboard",
8760 info_entry_priv->editable && clipboard_contains_text);
8762 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_DELETE, NULL);
8763 gtk_widget_set_sensitive (menuitem, info_entry_priv->editable && info_entry_priv->current_pos != info_entry_priv->selection_bound);
8764 g_signal_connect_swapped (menuitem, "activate",
8765 G_CALLBACK (gtk_entry_delete_cb), entry);
8766 gtk_widget_show (menuitem);
8767 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8769 menuitem = gtk_separator_menu_item_new ();
8770 gtk_widget_show (menuitem);
8771 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8773 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_SELECT_ALL, NULL);
8774 g_signal_connect_swapped (menuitem, "activate",
8775 G_CALLBACK (gtk_entry_select_all), entry);
8776 gtk_widget_show (menuitem);
8777 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8779 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
8780 "gtk-show-input-method-menu", &show_input_method_menu,
8781 "gtk-show-unicode-menu", &show_unicode_menu,
8784 if (show_input_method_menu || show_unicode_menu)
8786 menuitem = gtk_separator_menu_item_new ();
8787 gtk_widget_show (menuitem);
8788 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8791 if (show_input_method_menu)
8793 menuitem = gtk_menu_item_new_with_mnemonic (_("Input _Methods"));
8794 gtk_widget_set_sensitive (menuitem, info_entry_priv->editable);
8795 gtk_widget_show (menuitem);
8796 submenu = gtk_menu_new ();
8797 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
8799 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8801 gtk_im_multicontext_append_menuitems (GTK_IM_MULTICONTEXT (info_entry_priv->im_context),
8802 GTK_MENU_SHELL (submenu));
8805 if (show_unicode_menu)
8807 menuitem = gtk_menu_item_new_with_mnemonic (_("_Insert Unicode Control Character"));
8808 gtk_widget_set_sensitive (menuitem, info_entry_priv->editable);
8809 gtk_widget_show (menuitem);
8811 submenu = gtk_menu_new ();
8812 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
8813 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8815 _gtk_text_util_append_special_char_menuitems (GTK_MENU_SHELL (submenu),
8816 unichar_chosen_func,
8820 g_signal_emit (entry,
8821 signals[POPULATE_POPUP],
8823 info_entry_priv->popup_menu);
8827 gtk_menu_popup (GTK_MENU (info_entry_priv->popup_menu), NULL, NULL,
8829 info->button, info->time);
8832 gtk_menu_popup (GTK_MENU (info_entry_priv->popup_menu), NULL, NULL,
8833 popup_position_func, entry,
8834 info->button, info->time);
8835 gtk_menu_shell_select_first (GTK_MENU_SHELL (info_entry_priv->popup_menu), FALSE);
8839 g_object_unref (entry);
8840 g_slice_free (PopupInfo, info);
8844 gtk_entry_do_popup (GtkEntry *entry,
8845 GdkEventButton *event)
8847 PopupInfo *info = g_slice_new (PopupInfo);
8849 /* In order to know what entries we should make sensitive, we
8850 * ask for the current targets of the clipboard, and when
8851 * we get them, then we actually pop up the menu.
8853 info->entry = g_object_ref (entry);
8857 info->button = event->button;
8858 info->time = event->time;
8863 info->time = gtk_get_current_event_time ();
8866 gtk_clipboard_request_contents (gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_CLIPBOARD),
8867 gdk_atom_intern_static_string ("TARGETS"),
8868 popup_targets_received,
8873 gtk_entry_popup_menu (GtkWidget *widget)
8875 gtk_entry_do_popup (GTK_ENTRY (widget), NULL);
8880 gtk_entry_drag_begin (GtkWidget *widget,
8881 GdkDragContext *context)
8883 GtkEntry *entry = GTK_ENTRY (widget);
8884 GtkEntryPrivate *priv = entry->priv;
8887 for (i = 0; i < MAX_ICONS; i++)
8889 EntryIconInfo *icon_info = priv->icons[i];
8891 if (icon_info != NULL)
8893 if (icon_info->in_drag)
8895 switch (icon_info->storage_type)
8897 case GTK_IMAGE_STOCK:
8898 gtk_drag_set_icon_stock (context, icon_info->stock_id, -2, -2);
8901 case GTK_IMAGE_ICON_NAME:
8902 gtk_drag_set_icon_name (context, icon_info->icon_name, -2, -2);
8905 /* FIXME: No GIcon support for dnd icons */
8906 case GTK_IMAGE_GICON:
8907 case GTK_IMAGE_PIXBUF:
8908 gtk_drag_set_icon_pixbuf (context, icon_info->pixbuf, -2, -2);
8911 g_assert_not_reached ();
8919 gtk_entry_drag_end (GtkWidget *widget,
8920 GdkDragContext *context)
8922 GtkEntry *entry = GTK_ENTRY (widget);
8923 GtkEntryPrivate *priv = entry->priv;
8926 for (i = 0; i < MAX_ICONS; i++)
8928 EntryIconInfo *icon_info = priv->icons[i];
8930 if (icon_info != NULL)
8931 icon_info->in_drag = 0;
8936 gtk_entry_drag_leave (GtkWidget *widget,
8937 GdkDragContext *context,
8940 GtkEntry *entry = GTK_ENTRY (widget);
8941 GtkEntryPrivate *priv = entry->priv;
8943 priv->dnd_position = -1;
8944 gtk_widget_queue_draw (widget);
8948 gtk_entry_drag_drop (GtkWidget *widget,
8949 GdkDragContext *context,
8954 GtkEntry *entry = GTK_ENTRY (widget);
8955 GtkEntryPrivate *priv = entry->priv;
8956 GdkAtom target = GDK_NONE;
8959 target = gtk_drag_dest_find_target (widget, context, NULL);
8961 if (target != GDK_NONE)
8962 gtk_drag_get_data (widget, context, target, time);
8964 gtk_drag_finish (context, FALSE, FALSE, time);
8970 gtk_entry_drag_motion (GtkWidget *widget,
8971 GdkDragContext *context,
8976 GtkEntry *entry = GTK_ENTRY (widget);
8977 GtkEntryPrivate *priv = entry->priv;
8979 GtkWidget *source_widget;
8980 GdkDragAction suggested_action;
8981 gint new_position, old_position;
8984 style = gtk_widget_get_style (widget);
8985 x -= style->xthickness;
8986 y -= style->ythickness;
8988 old_position = priv->dnd_position;
8989 new_position = gtk_entry_find_position (entry, x + priv->scroll_offset);
8991 if (priv->editable &&
8992 gtk_drag_dest_find_target (widget, context, NULL) != GDK_NONE)
8994 source_widget = gtk_drag_get_source_widget (context);
8995 suggested_action = context->suggested_action;
8997 if (!gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &sel1, &sel2) ||
8998 new_position < sel1 || new_position > sel2)
9000 if (source_widget == widget)
9002 /* Default to MOVE, unless the user has
9003 * pressed ctrl or alt to affect available actions
9005 if ((context->actions & GDK_ACTION_MOVE) != 0)
9006 suggested_action = GDK_ACTION_MOVE;
9009 priv->dnd_position = new_position;
9013 if (source_widget == widget)
9014 suggested_action = 0; /* Can't drop in selection where drag started */
9016 priv->dnd_position = -1;
9021 /* Entry not editable, or no text */
9022 suggested_action = 0;
9023 priv->dnd_position = -1;
9026 gdk_drag_status (context, suggested_action, time);
9028 if (priv->dnd_position != old_position)
9029 gtk_widget_queue_draw (widget);
9035 gtk_entry_drag_data_received (GtkWidget *widget,
9036 GdkDragContext *context,
9039 GtkSelectionData *selection_data,
9043 GtkEntry *entry = GTK_ENTRY (widget);
9044 GtkEntryPrivate *priv = entry->priv;
9045 GtkEditable *editable = GTK_EDITABLE (widget);
9049 str = (gchar *) gtk_selection_data_get_text (selection_data);
9051 style = gtk_widget_get_style (widget);
9052 x -= style->xthickness;
9053 y -= style->ythickness;
9055 if (str && priv->editable)
9061 if (priv->truncate_multiline)
9062 length = truncate_multiline (str);
9064 new_position = gtk_entry_find_position (entry, x + priv->scroll_offset);
9066 if (!gtk_editable_get_selection_bounds (editable, &sel1, &sel2) ||
9067 new_position < sel1 || new_position > sel2)
9069 gtk_editable_insert_text (editable, str, length, &new_position);
9073 /* Replacing selection */
9074 begin_change (entry);
9075 g_object_freeze_notify (G_OBJECT (entry));
9076 gtk_editable_delete_text (editable, sel1, sel2);
9077 gtk_editable_insert_text (editable, str, length, &sel1);
9078 g_object_thaw_notify (G_OBJECT (entry));
9082 gtk_drag_finish (context, TRUE, context->action == GDK_ACTION_MOVE, time);
9086 /* Drag and drop didn't happen! */
9087 gtk_drag_finish (context, FALSE, FALSE, time);
9094 gtk_entry_drag_data_get (GtkWidget *widget,
9095 GdkDragContext *context,
9096 GtkSelectionData *selection_data,
9100 GtkEntry *entry = GTK_ENTRY (widget);
9101 GtkEntryPrivate *priv = entry->priv;
9102 GtkEditable *editable = GTK_EDITABLE (widget);
9103 gint sel_start, sel_end;
9106 /* If there is an icon drag going on, exit early. */
9107 for (i = 0; i < MAX_ICONS; i++)
9109 EntryIconInfo *icon_info = priv->icons[i];
9111 if (icon_info != NULL)
9113 if (icon_info->in_drag)
9118 if (gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end))
9120 gchar *str = gtk_entry_get_display_text (GTK_ENTRY (widget), sel_start, sel_end);
9122 gtk_selection_data_set_text (selection_data, str, -1);
9130 gtk_entry_drag_data_delete (GtkWidget *widget,
9131 GdkDragContext *context)
9133 GtkEntry *entry = GTK_ENTRY (widget);
9134 GtkEntryPrivate *priv = entry->priv;
9135 GtkEditable *editable = GTK_EDITABLE (widget);
9136 gint sel_start, sel_end;
9139 /* If there is an icon drag going on, exit early. */
9140 for (i = 0; i < MAX_ICONS; i++)
9142 EntryIconInfo *icon_info = priv->icons[i];
9144 if (icon_info != NULL)
9146 if (icon_info->in_drag)
9151 if (priv->editable &&
9152 gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end))
9153 gtk_editable_delete_text (editable, sel_start, sel_end);
9156 /* We display the cursor when
9158 * - the selection is empty, AND
9159 * - the widget has focus
9162 #define CURSOR_ON_MULTIPLIER 2
9163 #define CURSOR_OFF_MULTIPLIER 1
9164 #define CURSOR_PEND_MULTIPLIER 3
9165 #define CURSOR_DIVIDER 3
9168 cursor_blinks (GtkEntry *entry)
9170 GtkEntryPrivate *priv = entry->priv;
9172 if (gtk_widget_has_focus (GTK_WIDGET (entry)) &&
9174 priv->selection_bound == priv->current_pos)
9176 GtkSettings *settings;
9179 settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9180 g_object_get (settings, "gtk-cursor-blink", &blink, NULL);
9189 get_cursor_time (GtkEntry *entry)
9191 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9194 g_object_get (settings, "gtk-cursor-blink-time", &time, NULL);
9200 get_cursor_blink_timeout (GtkEntry *entry)
9202 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9205 g_object_get (settings, "gtk-cursor-blink-timeout", &timeout, NULL);
9211 show_cursor (GtkEntry *entry)
9213 GtkEntryPrivate *priv = entry->priv;
9216 if (!priv->cursor_visible)
9218 priv->cursor_visible = TRUE;
9220 widget = GTK_WIDGET (entry);
9221 if (gtk_widget_has_focus (widget) && priv->selection_bound == priv->current_pos)
9222 gtk_widget_queue_draw (widget);
9227 hide_cursor (GtkEntry *entry)
9229 GtkEntryPrivate *priv = entry->priv;
9232 if (priv->cursor_visible)
9234 priv->cursor_visible = FALSE;
9236 widget = GTK_WIDGET (entry);
9237 if (gtk_widget_has_focus (widget) && priv->selection_bound == priv->current_pos)
9238 gtk_widget_queue_draw (widget);
9246 blink_cb (gpointer data)
9249 GtkEntryPrivate *priv;
9252 entry = GTK_ENTRY (data);
9255 if (!gtk_widget_has_focus (GTK_WIDGET (entry)))
9257 g_warning ("GtkEntry - did not receive focus-out-event. If you\n"
9258 "connect a handler to this signal, it must return\n"
9259 "FALSE so the entry gets the event as well");
9261 gtk_entry_check_cursor_blink (entry);
9266 g_assert (priv->selection_bound == priv->current_pos);
9268 blink_timeout = get_cursor_blink_timeout (entry);
9269 if (priv->blink_time > 1000 * blink_timeout &&
9270 blink_timeout < G_MAXINT/1000)
9272 /* we've blinked enough without the user doing anything, stop blinking */
9273 show_cursor (entry);
9274 priv->blink_timeout = 0;
9276 else if (priv->cursor_visible)
9278 hide_cursor (entry);
9279 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_OFF_MULTIPLIER / CURSOR_DIVIDER,
9285 show_cursor (entry);
9286 priv->blink_time += get_cursor_time (entry);
9287 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
9292 /* Remove ourselves */
9297 gtk_entry_check_cursor_blink (GtkEntry *entry)
9299 GtkEntryPrivate *priv = entry->priv;
9301 if (cursor_blinks (entry))
9303 if (!priv->blink_timeout)
9305 show_cursor (entry);
9306 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
9313 if (priv->blink_timeout)
9315 g_source_remove (priv->blink_timeout);
9316 priv->blink_timeout = 0;
9319 priv->cursor_visible = TRUE;
9324 gtk_entry_pend_cursor_blink (GtkEntry *entry)
9326 GtkEntryPrivate *priv = entry->priv;
9328 if (cursor_blinks (entry))
9330 if (priv->blink_timeout != 0)
9331 g_source_remove (priv->blink_timeout);
9333 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_PEND_MULTIPLIER / CURSOR_DIVIDER,
9336 show_cursor (entry);
9341 gtk_entry_reset_blink_time (GtkEntry *entry)
9343 GtkEntryPrivate *priv = entry->priv;
9345 priv->blink_time = 0;
9351 gtk_entry_completion_timeout (gpointer data)
9353 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (data);
9354 GtkEntryPrivate *completion_entry_priv = GTK_ENTRY (completion->priv->entry)->priv;
9356 completion->priv->completion_timeout = 0;
9358 if (completion->priv->filter_model &&
9359 g_utf8_strlen (gtk_entry_get_text (GTK_ENTRY (completion->priv->entry)), -1)
9360 >= completion->priv->minimum_key_length)
9364 GtkTreeSelection *s;
9365 gboolean popup_single;
9367 gtk_entry_completion_complete (completion);
9368 matches = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->filter_model), NULL);
9370 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9372 s = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view));
9374 gtk_tree_selection_unselect_all (s);
9376 actions = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->actions), NULL);
9378 g_object_get (completion, "popup-single-match", &popup_single, NULL);
9379 if ((matches > (popup_single ? 0: 1)) || actions > 0)
9381 if (gtk_widget_get_visible (completion->priv->popup_window))
9382 _gtk_entry_completion_resize_popup (completion);
9384 _gtk_entry_completion_popup (completion, completion_entry_priv->completion_device);
9387 _gtk_entry_completion_popdown (completion);
9389 else if (gtk_widget_get_visible (completion->priv->popup_window))
9390 _gtk_entry_completion_popdown (completion);
9395 static inline gboolean
9396 keyval_is_cursor_move (guint keyval)
9398 if (keyval == GDK_KEY_Up || keyval == GDK_KEY_KP_Up)
9401 if (keyval == GDK_KEY_Down || keyval == GDK_KEY_KP_Down)
9404 if (keyval == GDK_KEY_Page_Up)
9407 if (keyval == GDK_KEY_Page_Down)
9414 gtk_entry_completion_key_press (GtkWidget *widget,
9418 gint matches, actions = 0;
9419 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
9421 if (!gtk_widget_get_mapped (completion->priv->popup_window))
9424 matches = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->filter_model), NULL);
9426 if (completion->priv->actions)
9427 actions = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->actions), NULL);
9429 if (keyval_is_cursor_move (event->keyval))
9431 GtkTreePath *path = NULL;
9433 if (event->keyval == GDK_KEY_Up || event->keyval == GDK_KEY_KP_Up)
9435 if (completion->priv->current_selected < 0)
9436 completion->priv->current_selected = matches + actions - 1;
9438 completion->priv->current_selected--;
9440 else if (event->keyval == GDK_KEY_Down || event->keyval == GDK_KEY_KP_Down)
9442 if (completion->priv->current_selected < matches + actions - 1)
9443 completion->priv->current_selected++;
9445 completion->priv->current_selected = -1;
9447 else if (event->keyval == GDK_KEY_Page_Up)
9449 if (completion->priv->current_selected < 0)
9450 completion->priv->current_selected = matches + actions - 1;
9451 else if (completion->priv->current_selected == 0)
9452 completion->priv->current_selected = -1;
9453 else if (completion->priv->current_selected < matches)
9455 completion->priv->current_selected -= 14;
9456 if (completion->priv->current_selected < 0)
9457 completion->priv->current_selected = 0;
9461 completion->priv->current_selected -= 14;
9462 if (completion->priv->current_selected < matches - 1)
9463 completion->priv->current_selected = matches - 1;
9466 else if (event->keyval == GDK_KEY_Page_Down)
9468 if (completion->priv->current_selected < 0)
9469 completion->priv->current_selected = 0;
9470 else if (completion->priv->current_selected < matches - 1)
9472 completion->priv->current_selected += 14;
9473 if (completion->priv->current_selected > matches - 1)
9474 completion->priv->current_selected = matches - 1;
9476 else if (completion->priv->current_selected == matches + actions - 1)
9478 completion->priv->current_selected = -1;
9482 completion->priv->current_selected += 14;
9483 if (completion->priv->current_selected > matches + actions - 1)
9484 completion->priv->current_selected = matches + actions - 1;
9488 if (completion->priv->current_selected < 0)
9490 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9491 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view)));
9493 if (completion->priv->inline_selection &&
9494 completion->priv->completion_prefix)
9496 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9497 completion->priv->completion_prefix);
9498 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9501 else if (completion->priv->current_selected < matches)
9503 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view)));
9505 path = gtk_tree_path_new_from_indices (completion->priv->current_selected, -1);
9506 gtk_tree_view_set_cursor (GTK_TREE_VIEW (completion->priv->tree_view),
9509 if (completion->priv->inline_selection)
9513 GtkTreeIter child_iter;
9514 GtkTreeModel *model = NULL;
9515 GtkTreeSelection *sel;
9518 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view));
9519 if (!gtk_tree_selection_get_selected (sel, &model, &iter))
9522 gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (model), &child_iter, &iter);
9523 model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model));
9525 if (completion->priv->completion_prefix == NULL)
9526 completion->priv->completion_prefix = g_strdup (gtk_entry_get_text (GTK_ENTRY (completion->priv->entry)));
9528 g_signal_emit_by_name (completion, "cursor-on-match", model,
9529 &child_iter, &entry_set);
9532 else if (completion->priv->current_selected - matches >= 0)
9534 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9536 path = gtk_tree_path_new_from_indices (completion->priv->current_selected - matches, -1);
9537 gtk_tree_view_set_cursor (GTK_TREE_VIEW (completion->priv->action_view),
9540 if (completion->priv->inline_selection &&
9541 completion->priv->completion_prefix)
9543 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9544 completion->priv->completion_prefix);
9545 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9549 gtk_tree_path_free (path);
9553 else if (event->keyval == GDK_KEY_Escape ||
9554 event->keyval == GDK_KEY_Left ||
9555 event->keyval == GDK_KEY_KP_Left ||
9556 event->keyval == GDK_KEY_Right ||
9557 event->keyval == GDK_KEY_KP_Right)
9559 gboolean retval = TRUE;
9561 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9562 _gtk_entry_completion_popdown (completion);
9564 if (completion->priv->current_selected < 0)
9567 goto keypress_completion_out;
9569 else if (completion->priv->inline_selection)
9571 /* Escape rejects the tentative completion */
9572 if (event->keyval == GDK_KEY_Escape)
9574 if (completion->priv->completion_prefix)
9575 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9576 completion->priv->completion_prefix);
9578 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry), "");
9581 /* Move the cursor to the end for Right/Esc, to the
9582 beginning for Left */
9583 if (event->keyval == GDK_KEY_Right ||
9584 event->keyval == GDK_KEY_KP_Right ||
9585 event->keyval == GDK_KEY_Escape)
9586 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9588 gtk_editable_set_position (GTK_EDITABLE (widget), 0);
9591 keypress_completion_out:
9592 if (completion->priv->inline_selection)
9594 g_free (completion->priv->completion_prefix);
9595 completion->priv->completion_prefix = NULL;
9600 else if (event->keyval == GDK_KEY_Tab ||
9601 event->keyval == GDK_KEY_KP_Tab ||
9602 event->keyval == GDK_KEY_ISO_Left_Tab)
9604 GtkDirectionType dir = event->keyval == GDK_KEY_ISO_Left_Tab ?
9605 GTK_DIR_TAB_BACKWARD : GTK_DIR_TAB_FORWARD;
9607 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9608 _gtk_entry_completion_popdown (completion);
9610 g_free (completion->priv->completion_prefix);
9611 completion->priv->completion_prefix = NULL;
9613 gtk_widget_child_focus (gtk_widget_get_toplevel (widget), dir);
9617 else if (event->keyval == GDK_KEY_ISO_Enter ||
9618 event->keyval == GDK_KEY_KP_Enter ||
9619 event->keyval == GDK_KEY_Return)
9622 GtkTreeModel *model = NULL;
9623 GtkTreeSelection *sel;
9624 gboolean retval = TRUE;
9626 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9627 _gtk_entry_completion_popdown (completion);
9629 if (completion->priv->current_selected < matches)
9633 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view));
9634 if (gtk_tree_selection_get_selected (sel, &model, &iter))
9636 g_signal_handler_block (widget, completion->priv->changed_id);
9637 g_signal_emit_by_name (completion, "match-selected",
9638 model, &iter, &entry_set);
9639 g_signal_handler_unblock (widget, completion->priv->changed_id);
9645 gtk_tree_model_get (model, &iter,
9646 completion->priv->text_column, &str,
9649 gtk_entry_set_text (GTK_ENTRY (widget), str);
9651 /* move the cursor to the end */
9652 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9660 else if (completion->priv->current_selected - matches >= 0)
9662 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view));
9663 if (gtk_tree_selection_get_selected (sel, &model, &iter))
9667 path = gtk_tree_path_new_from_indices (completion->priv->current_selected - matches, -1);
9668 g_signal_emit_by_name (completion, "action-activated",
9669 gtk_tree_path_get_indices (path)[0]);
9670 gtk_tree_path_free (path);
9676 g_free (completion->priv->completion_prefix);
9677 completion->priv->completion_prefix = NULL;
9686 gtk_entry_completion_changed (GtkWidget *widget,
9689 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
9690 GtkEntry *entry = GTK_ENTRY (widget);
9691 GtkEntryPrivate *priv = entry->priv;
9694 /* (re)install completion timeout */
9695 if (completion->priv->completion_timeout)
9696 g_source_remove (completion->priv->completion_timeout);
9698 if (!gtk_entry_get_text (entry))
9701 /* no need to normalize for this test */
9702 if (completion->priv->minimum_key_length > 0 &&
9703 strcmp ("", gtk_entry_get_text (entry)) == 0)
9705 if (gtk_widget_get_visible (completion->priv->popup_window))
9706 _gtk_entry_completion_popdown (completion);
9710 device = gtk_get_current_event_device ();
9712 if (device && gdk_device_get_source (device) == GDK_SOURCE_KEYBOARD)
9713 device = gdk_device_get_associated_device (device);
9716 priv->completion_device = device;
9718 completion->priv->completion_timeout =
9719 gdk_threads_add_timeout (COMPLETION_TIMEOUT,
9720 gtk_entry_completion_timeout,
9725 check_completion_callback (GtkEntryCompletion *completion)
9727 completion->priv->check_completion_idle = NULL;
9729 gtk_entry_completion_complete (completion);
9730 gtk_entry_completion_insert_prefix (completion);
9736 clear_completion_callback (GtkEntry *entry,
9739 if (pspec->name == I_("cursor-position") ||
9740 pspec->name == I_("selection-bound"))
9742 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
9744 completion->priv->has_completion = FALSE;
9749 accept_completion_callback (GtkEntry *entry)
9751 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
9753 if (completion->priv->has_completion)
9754 gtk_editable_set_position (GTK_EDITABLE (entry),
9755 gtk_entry_buffer_get_length (get_buffer (entry)));
9761 completion_insert_text_callback (GtkEntry *entry,
9765 GtkEntryCompletion *completion)
9767 /* idle to update the selection based on the file list */
9768 if (completion->priv->check_completion_idle == NULL)
9770 completion->priv->check_completion_idle = g_idle_source_new ();
9771 g_source_set_priority (completion->priv->check_completion_idle, G_PRIORITY_HIGH);
9772 g_source_set_closure (completion->priv->check_completion_idle,
9773 g_cclosure_new_object (G_CALLBACK (check_completion_callback),
9774 G_OBJECT (completion)));
9775 g_source_attach (completion->priv->check_completion_idle, NULL);
9780 completion_changed (GtkEntryCompletion *completion,
9784 GtkEntry *entry = GTK_ENTRY (data);
9786 if (pspec->name == I_("popup-completion") ||
9787 pspec->name == I_("inline-completion"))
9789 disconnect_completion_signals (entry, completion);
9790 connect_completion_signals (entry, completion);
9795 disconnect_completion_signals (GtkEntry *entry,
9796 GtkEntryCompletion *completion)
9798 g_signal_handlers_disconnect_by_func (completion,
9799 G_CALLBACK (completion_changed), entry);
9800 if (completion->priv->changed_id > 0 &&
9801 g_signal_handler_is_connected (entry, completion->priv->changed_id))
9803 g_signal_handler_disconnect (entry, completion->priv->changed_id);
9804 completion->priv->changed_id = 0;
9806 g_signal_handlers_disconnect_by_func (entry,
9807 G_CALLBACK (gtk_entry_completion_key_press), completion);
9808 if (completion->priv->insert_text_id > 0 &&
9809 g_signal_handler_is_connected (entry, completion->priv->insert_text_id))
9811 g_signal_handler_disconnect (entry, completion->priv->insert_text_id);
9812 completion->priv->insert_text_id = 0;
9814 g_signal_handlers_disconnect_by_func (entry,
9815 G_CALLBACK (completion_insert_text_callback), completion);
9816 g_signal_handlers_disconnect_by_func (entry,
9817 G_CALLBACK (clear_completion_callback), completion);
9818 g_signal_handlers_disconnect_by_func (entry,
9819 G_CALLBACK (accept_completion_callback), completion);
9823 connect_completion_signals (GtkEntry *entry,
9824 GtkEntryCompletion *completion)
9826 if (completion->priv->popup_completion)
9828 completion->priv->changed_id =
9829 g_signal_connect (entry, "changed",
9830 G_CALLBACK (gtk_entry_completion_changed), completion);
9831 g_signal_connect (entry, "key-press-event",
9832 G_CALLBACK (gtk_entry_completion_key_press), completion);
9835 if (completion->priv->inline_completion)
9837 completion->priv->insert_text_id =
9838 g_signal_connect (entry, "insert-text",
9839 G_CALLBACK (completion_insert_text_callback), completion);
9840 g_signal_connect (entry, "notify",
9841 G_CALLBACK (clear_completion_callback), completion);
9842 g_signal_connect (entry, "activate",
9843 G_CALLBACK (accept_completion_callback), completion);
9844 g_signal_connect (entry, "focus-out-event",
9845 G_CALLBACK (accept_completion_callback), completion);
9848 g_signal_connect (completion, "notify",
9849 G_CALLBACK (completion_changed), entry);
9853 * gtk_entry_set_completion:
9854 * @entry: A #GtkEntry
9855 * @completion: (allow-none): The #GtkEntryCompletion or %NULL
9857 * Sets @completion to be the auxiliary completion object to use with @entry.
9858 * All further configuration of the completion mechanism is done on
9859 * @completion using the #GtkEntryCompletion API. Completion is disabled if
9860 * @completion is set to %NULL.
9865 gtk_entry_set_completion (GtkEntry *entry,
9866 GtkEntryCompletion *completion)
9868 GtkEntryCompletion *old;
9870 g_return_if_fail (GTK_IS_ENTRY (entry));
9871 g_return_if_fail (!completion || GTK_IS_ENTRY_COMPLETION (completion));
9873 old = gtk_entry_get_completion (entry);
9875 if (old == completion)
9880 if (old->priv->completion_timeout)
9882 g_source_remove (old->priv->completion_timeout);
9883 old->priv->completion_timeout = 0;
9886 if (gtk_widget_get_mapped (old->priv->popup_window))
9887 _gtk_entry_completion_popdown (old);
9889 disconnect_completion_signals (entry, old);
9890 old->priv->entry = NULL;
9892 g_object_unref (old);
9897 g_object_set_data (G_OBJECT (entry), I_(GTK_ENTRY_COMPLETION_KEY), NULL);
9901 /* hook into the entry */
9902 g_object_ref (completion);
9904 connect_completion_signals (entry, completion);
9905 completion->priv->entry = GTK_WIDGET (entry);
9906 g_object_set_data (G_OBJECT (entry), I_(GTK_ENTRY_COMPLETION_KEY), completion);
9910 * gtk_entry_get_completion:
9911 * @entry: A #GtkEntry
9913 * Returns the auxiliary completion object currently in use by @entry.
9915 * Return value: (transfer none): The auxiliary completion object currently
9920 GtkEntryCompletion *
9921 gtk_entry_get_completion (GtkEntry *entry)
9923 GtkEntryCompletion *completion;
9925 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
9927 completion = GTK_ENTRY_COMPLETION (g_object_get_data (G_OBJECT (entry),
9928 GTK_ENTRY_COMPLETION_KEY));
9934 * gtk_entry_set_cursor_hadjustment:
9935 * @entry: a #GtkEntry
9936 * @adjustment: an adjustment which should be adjusted when the cursor
9937 * is moved, or %NULL
9939 * Hooks up an adjustment to the cursor position in an entry, so that when
9940 * the cursor is moved, the adjustment is scrolled to show that position.
9941 * See gtk_scrolled_window_get_hadjustment() for a typical way of obtaining
9944 * The adjustment has to be in pixel units and in the same coordinate system
9950 gtk_entry_set_cursor_hadjustment (GtkEntry *entry,
9951 GtkAdjustment *adjustment)
9953 g_return_if_fail (GTK_IS_ENTRY (entry));
9955 g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
9958 g_object_ref (adjustment);
9960 g_object_set_qdata_full (G_OBJECT (entry),
9961 quark_cursor_hadjustment,
9967 * gtk_entry_get_cursor_hadjustment:
9968 * @entry: a #GtkEntry
9970 * Retrieves the horizontal cursor adjustment for the entry.
9971 * See gtk_entry_set_cursor_hadjustment().
9973 * Return value: (transfer none): the horizontal cursor adjustment, or %NULL
9974 * if none has been set.
9979 gtk_entry_get_cursor_hadjustment (GtkEntry *entry)
9981 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
9983 return g_object_get_qdata (G_OBJECT (entry), quark_cursor_hadjustment);
9987 * gtk_entry_set_progress_fraction:
9988 * @entry: a #GtkEntry
9989 * @fraction: fraction of the task that's been completed
9991 * Causes the entry's progress indicator to "fill in" the given
9992 * fraction of the bar. The fraction should be between 0.0 and 1.0,
9998 gtk_entry_set_progress_fraction (GtkEntry *entry,
10002 GtkEntryPrivate *private;
10003 gdouble old_fraction;
10004 gint x, y, width, height;
10005 gint old_x, old_y, old_width, old_height;
10007 g_return_if_fail (GTK_IS_ENTRY (entry));
10009 widget = GTK_WIDGET (entry);
10010 private = entry->priv;
10012 if (private->progress_pulse_mode)
10015 old_fraction = private->progress_fraction;
10017 if (gtk_widget_is_drawable (widget))
10018 get_progress_area (widget, &old_x, &old_y, &old_width, &old_height);
10020 fraction = CLAMP (fraction, 0.0, 1.0);
10022 private->progress_fraction = fraction;
10023 private->progress_pulse_mode = FALSE;
10024 private->progress_pulse_current = 0.0;
10026 if (gtk_widget_is_drawable (widget))
10028 get_progress_area (widget, &x, &y, &width, &height);
10030 if ((x != old_x) || (y != old_y) || (width != old_width) || (height != old_height))
10031 gtk_widget_queue_draw (widget);
10034 if (fraction != old_fraction)
10035 g_object_notify (G_OBJECT (entry), "progress-fraction");
10039 * gtk_entry_get_progress_fraction:
10040 * @entry: a #GtkEntry
10042 * Returns the current fraction of the task that's been completed.
10043 * See gtk_entry_set_progress_fraction().
10045 * Return value: a fraction from 0.0 to 1.0
10050 gtk_entry_get_progress_fraction (GtkEntry *entry)
10052 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
10054 return entry->priv->progress_fraction;
10058 * gtk_entry_set_progress_pulse_step:
10059 * @entry: a #GtkEntry
10060 * @fraction: fraction between 0.0 and 1.0
10062 * Sets the fraction of total entry width to move the progress
10063 * bouncing block for each call to gtk_entry_progress_pulse().
10068 gtk_entry_set_progress_pulse_step (GtkEntry *entry,
10071 GtkEntryPrivate *private;
10073 g_return_if_fail (GTK_IS_ENTRY (entry));
10075 private = entry->priv;
10077 fraction = CLAMP (fraction, 0.0, 1.0);
10079 if (fraction != private->progress_pulse_fraction)
10081 private->progress_pulse_fraction = fraction;
10083 gtk_widget_queue_draw (GTK_WIDGET (entry));
10085 g_object_notify (G_OBJECT (entry), "progress-pulse-step");
10090 * gtk_entry_get_progress_pulse_step:
10091 * @entry: a #GtkEntry
10093 * Retrieves the pulse step set with gtk_entry_set_progress_pulse_step().
10095 * Return value: a fraction from 0.0 to 1.0
10100 gtk_entry_get_progress_pulse_step (GtkEntry *entry)
10102 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
10104 return entry->priv->progress_pulse_fraction;
10108 * gtk_entry_progress_pulse:
10109 * @entry: a #GtkEntry
10111 * Indicates that some progress is made, but you don't know how much.
10112 * Causes the entry's progress indicator to enter "activity mode,"
10113 * where a block bounces back and forth. Each call to
10114 * gtk_entry_progress_pulse() causes the block to move by a little bit
10115 * (the amount of movement per pulse is determined by
10116 * gtk_entry_set_progress_pulse_step()).
10121 gtk_entry_progress_pulse (GtkEntry *entry)
10123 GtkEntryPrivate *private;
10125 g_return_if_fail (GTK_IS_ENTRY (entry));
10127 private = entry->priv;
10129 if (private->progress_pulse_mode)
10131 if (private->progress_pulse_way_back)
10133 private->progress_pulse_current -= private->progress_pulse_fraction;
10135 if (private->progress_pulse_current < 0.0)
10137 private->progress_pulse_current = 0.0;
10138 private->progress_pulse_way_back = FALSE;
10143 private->progress_pulse_current += private->progress_pulse_fraction;
10145 if (private->progress_pulse_current > 1.0 - private->progress_pulse_fraction)
10147 private->progress_pulse_current = 1.0 - private->progress_pulse_fraction;
10148 private->progress_pulse_way_back = TRUE;
10154 private->progress_fraction = 0.0;
10155 private->progress_pulse_mode = TRUE;
10156 private->progress_pulse_way_back = FALSE;
10157 private->progress_pulse_current = 0.0;
10160 gtk_widget_queue_draw (GTK_WIDGET (entry));
10163 /* Caps Lock warning for password entries */
10166 show_capslock_feedback (GtkEntry *entry,
10169 GtkEntryPrivate *priv = entry->priv;
10171 if (gtk_entry_get_icon_storage_type (entry, GTK_ENTRY_ICON_SECONDARY) == GTK_IMAGE_EMPTY)
10173 gtk_entry_set_icon_from_stock (entry, GTK_ENTRY_ICON_SECONDARY, GTK_STOCK_CAPS_LOCK_WARNING);
10174 gtk_entry_set_icon_activatable (entry, GTK_ENTRY_ICON_SECONDARY, FALSE);
10175 priv->caps_lock_warning_shown = TRUE;
10178 if (priv->caps_lock_warning_shown)
10179 gtk_entry_set_icon_tooltip_text (entry, GTK_ENTRY_ICON_SECONDARY, text);
10181 g_warning ("Can't show Caps Lock warning, since secondary icon is set");
10185 remove_capslock_feedback (GtkEntry *entry)
10187 GtkEntryPrivate *priv = entry->priv;
10189 if (priv->caps_lock_warning_shown)
10191 gtk_entry_set_icon_from_stock (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
10192 priv->caps_lock_warning_shown = FALSE;
10197 keymap_state_changed (GdkKeymap *keymap,
10200 GtkEntryPrivate *priv = entry->priv;
10203 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL && priv->caps_lock_warning)
10205 if (gdk_keymap_get_num_lock_state (keymap)
10206 && gdk_keymap_get_caps_lock_state (keymap))
10207 text = _("Caps Lock and Num Lock are on");
10208 else if (gdk_keymap_get_num_lock_state (keymap))
10209 text = _("Num Lock is on");
10210 else if (gdk_keymap_get_caps_lock_state (keymap))
10211 text = _("Caps Lock is on");
10215 show_capslock_feedback (entry, text);
10217 remove_capslock_feedback (entry);