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_has_focus (widget) ?
3423 GTK_STATE_ACTIVE : gtk_widget_get_state (widget);
3425 gtk_paint_flat_box (style, cr,
3426 state, GTK_SHADOW_NONE,
3428 x, y, width, height);
3430 if (priv->has_frame)
3431 gtk_paint_shadow (style, cr,
3432 state, priv->shadow_type,
3433 widget, "entry", x, y, width, height);
3435 gtk_entry_draw_progress (widget, cr);
3437 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3439 x -= priv->focus_width;
3440 y -= priv->focus_width;
3441 width += 2 * priv->focus_width;
3442 height += 2 * priv->focus_width;
3444 gtk_paint_focus (style, cr,
3445 gtk_widget_get_state (widget),
3447 0, 0, width, height);
3454 get_progress_area (GtkWidget *widget,
3460 GtkEntry *entry = GTK_ENTRY (widget);
3461 GtkEntryPrivate *private = entry->priv;
3462 GtkBorder *progress_border;
3464 get_text_area_size (entry, x, y, width, height);
3466 if (!private->interior_focus)
3468 *x -= private->focus_width;
3469 *y -= private->focus_width;
3470 *width += 2 * private->focus_width;
3471 *height += 2 * private->focus_width;
3474 gtk_widget_style_get (widget, "progress-border", &progress_border, NULL);
3476 if (progress_border)
3478 *x += progress_border->left;
3479 *y += progress_border->top;
3480 *width -= progress_border->left + progress_border->right;
3481 *height -= progress_border->top + progress_border->bottom;
3483 gtk_border_free (progress_border);
3486 if (private->progress_pulse_mode)
3488 gdouble value = private->progress_pulse_current;
3490 *x += (gint) floor(value * (*width));
3491 *width = (gint) ceil(private->progress_pulse_fraction * (*width));
3493 else if (private->progress_fraction > 0)
3495 gdouble value = private->progress_fraction;
3497 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
3501 bar_width = floor(value * (*width) + 0.5);
3502 *x += *width - bar_width;
3507 *width = (gint) floor(value * (*width) + 0.5);
3518 gtk_entry_draw_progress (GtkWidget *widget,
3521 gint x, y, width, height;
3524 get_progress_area (widget, &x, &y, &width, &height);
3526 if ((width <= 0) || (height <= 0))
3529 state = GTK_STATE_SELECTED;
3530 if (!gtk_widget_get_sensitive (widget))
3531 state = GTK_STATE_INSENSITIVE;
3533 gtk_paint_box (gtk_widget_get_style (widget), cr,
3534 state, GTK_SHADOW_OUT,
3535 widget, "entry-progress",
3541 gtk_entry_draw (GtkWidget *widget,
3544 GtkEntry *entry = GTK_ENTRY (widget);
3547 GtkEntryPrivate *priv = entry->priv;
3550 style = gtk_widget_get_style (widget);
3552 state = gtk_widget_has_focus (widget) ?
3553 GTK_STATE_ACTIVE : gtk_widget_get_state (widget);
3555 if (gtk_cairo_should_draw_window (cr, gtk_widget_get_window (widget)))
3557 /* Draw entry_bg, shadow, progress and focus */
3558 gtk_entry_draw_frame (widget, cr);
3560 /* Draw text and cursor */
3563 gtk_cairo_transform_to_window (cr, widget, priv->text_area);
3565 if (priv->dnd_position != -1)
3566 gtk_entry_draw_cursor (GTK_ENTRY (widget), cr, CURSOR_DND);
3568 gtk_entry_draw_text (GTK_ENTRY (widget), cr);
3570 /* When no text is being displayed at all, don't show the cursor */
3571 if (gtk_entry_get_display_mode (entry) != DISPLAY_BLANK &&
3572 gtk_widget_has_focus (widget) &&
3573 priv->selection_bound == priv->current_pos && priv->cursor_visible)
3574 gtk_entry_draw_cursor (GTK_ENTRY (widget), cr, CURSOR_STANDARD);
3579 for (i = 0; i < MAX_ICONS; i++)
3581 EntryIconInfo *icon_info = priv->icons[i];
3583 if (icon_info != NULL)
3587 gtk_cairo_transform_to_window (cr, widget, icon_info->window);
3589 draw_icon (widget, cr, i);
3600 gtk_entry_enter_notify (GtkWidget *widget,
3601 GdkEventCrossing *event)
3603 GtkEntry *entry = GTK_ENTRY (widget);
3604 GtkEntryPrivate *priv = entry->priv;
3607 for (i = 0; i < MAX_ICONS; i++)
3609 EntryIconInfo *icon_info = priv->icons[i];
3611 if (icon_info != NULL && event->window == icon_info->window)
3613 if (should_prelight (entry, i))
3615 icon_info->prelight = TRUE;
3616 gtk_widget_queue_draw (widget);
3627 gtk_entry_leave_notify (GtkWidget *widget,
3628 GdkEventCrossing *event)
3630 GtkEntry *entry = GTK_ENTRY (widget);
3631 GtkEntryPrivate *priv = entry->priv;
3634 for (i = 0; i < MAX_ICONS; i++)
3636 EntryIconInfo *icon_info = priv->icons[i];
3638 if (icon_info != NULL && event->window == icon_info->window)
3640 /* a grab means that we may never see the button release */
3641 if (event->mode == GDK_CROSSING_GRAB || event->mode == GDK_CROSSING_GTK_GRAB)
3642 icon_info->pressed = FALSE;
3644 if (should_prelight (entry, i))
3646 icon_info->prelight = FALSE;
3647 gtk_widget_queue_draw (widget);
3658 gtk_entry_get_pixel_ranges (GtkEntry *entry,
3662 gint start_char, end_char;
3664 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start_char, &end_char))
3666 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
3667 PangoLayoutLine *line = pango_layout_get_lines_readonly (layout)->data;
3668 const char *text = pango_layout_get_text (layout);
3669 gint start_index = g_utf8_offset_to_pointer (text, start_char) - text;
3670 gint end_index = g_utf8_offset_to_pointer (text, end_char) - text;
3671 gint real_n_ranges, i;
3673 pango_layout_line_get_x_ranges (line, start_index, end_index, ranges, &real_n_ranges);
3679 for (i = 0; i < real_n_ranges; ++i)
3681 r[2 * i + 1] = (r[2 * i + 1] - r[2 * i]) / PANGO_SCALE;
3682 r[2 * i] = r[2 * i] / PANGO_SCALE;
3687 *n_ranges = real_n_ranges;
3699 in_selection (GtkEntry *entry,
3704 gint retval = FALSE;
3706 gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
3708 for (i = 0; i < n_ranges; ++i)
3710 if (x >= ranges[2 * i] && x < ranges[2 * i] + ranges[2 * i + 1])
3722 gtk_entry_button_press (GtkWidget *widget,
3723 GdkEventButton *event)
3725 GtkEntry *entry = GTK_ENTRY (widget);
3726 GtkEditable *editable = GTK_EDITABLE (widget);
3727 GtkEntryPrivate *priv = entry->priv;
3728 EntryIconInfo *icon_info = NULL;
3730 gint sel_start, sel_end;
3733 for (i = 0; i < MAX_ICONS; i++)
3735 icon_info = priv->icons[i];
3737 if (!icon_info || icon_info->insensitive)
3740 if (event->window == icon_info->window)
3742 if (should_prelight (entry, i))
3744 icon_info->prelight = FALSE;
3745 gtk_widget_queue_draw (widget);
3748 priv->start_x = event->x;
3749 priv->start_y = event->y;
3750 icon_info->pressed = TRUE;
3752 if (!icon_info->nonactivatable)
3753 g_signal_emit (entry, signals[ICON_PRESS], 0, i, event);
3759 if (event->window != priv->text_area ||
3760 (priv->button && event->button != priv->button))
3763 gtk_entry_reset_blink_time (entry);
3765 priv->button = event->button;
3767 if (!gtk_widget_has_focus (widget))
3769 priv->in_click = TRUE;
3770 gtk_widget_grab_focus (widget);
3771 priv->in_click = FALSE;
3774 tmp_pos = gtk_entry_find_position (entry, event->x + priv->scroll_offset);
3776 if (event->button == 1)
3778 gboolean have_selection = gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end);
3780 priv->select_words = FALSE;
3781 priv->select_lines = FALSE;
3783 if (event->state & GDK_SHIFT_MASK)
3785 _gtk_entry_reset_im_context (entry);
3787 if (!have_selection) /* select from the current position to the clicked position */
3788 sel_start = sel_end = priv->current_pos;
3790 if (tmp_pos > sel_start && tmp_pos < sel_end)
3792 /* Truncate current selection, but keep it as big as possible */
3793 if (tmp_pos - sel_start > sel_end - tmp_pos)
3794 gtk_entry_set_positions (entry, sel_start, tmp_pos);
3796 gtk_entry_set_positions (entry, tmp_pos, sel_end);
3800 gboolean extend_to_left;
3803 /* Figure out what click selects and extend current selection */
3804 switch (event->type)
3806 case GDK_BUTTON_PRESS:
3807 gtk_entry_set_positions (entry, tmp_pos, tmp_pos);
3810 case GDK_2BUTTON_PRESS:
3811 priv->select_words = TRUE;
3812 gtk_entry_select_word (entry);
3815 case GDK_3BUTTON_PRESS:
3816 priv->select_lines = TRUE;
3817 gtk_entry_select_line (entry);
3824 start = MIN (priv->current_pos, priv->selection_bound);
3825 start = MIN (sel_start, start);
3827 end = MAX (priv->current_pos, priv->selection_bound);
3828 end = MAX (sel_end, end);
3830 if (tmp_pos == sel_start || tmp_pos == sel_end)
3831 extend_to_left = (tmp_pos == start);
3833 extend_to_left = (end == sel_end);
3836 gtk_entry_set_positions (entry, start, end);
3838 gtk_entry_set_positions (entry, end, start);
3841 else /* no shift key */
3842 switch (event->type)
3844 case GDK_BUTTON_PRESS:
3845 if (in_selection (entry, event->x + priv->scroll_offset))
3847 /* Click inside the selection - we'll either start a drag, or
3848 * clear the selection
3850 priv->in_drag = TRUE;
3851 priv->drag_start_x = event->x + priv->scroll_offset;
3852 priv->drag_start_y = event->y;
3855 gtk_editable_set_position (editable, tmp_pos);
3858 case GDK_2BUTTON_PRESS:
3859 /* We ALWAYS receive a GDK_BUTTON_PRESS immediately before
3860 * receiving a GDK_2BUTTON_PRESS so we need to reset
3861 * priv->in_drag which may have been set above
3863 priv->in_drag = FALSE;
3864 priv->select_words = TRUE;
3865 gtk_entry_select_word (entry);
3868 case GDK_3BUTTON_PRESS:
3869 /* We ALWAYS receive a GDK_BUTTON_PRESS immediately before
3870 * receiving a GDK_3BUTTON_PRESS so we need to reset
3871 * priv->in_drag which may have been set above
3873 priv->in_drag = FALSE;
3874 priv->select_lines = TRUE;
3875 gtk_entry_select_line (entry);
3884 else if (event->button == 2 && event->type == GDK_BUTTON_PRESS)
3888 priv->insert_pos = tmp_pos;
3889 gtk_entry_paste (entry, GDK_SELECTION_PRIMARY);
3894 gtk_widget_error_bell (widget);
3897 else if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
3899 gtk_entry_do_popup (entry, event);
3900 priv->button = 0; /* Don't wait for release, since the menu will gtk_grab_add */
3909 gtk_entry_button_release (GtkWidget *widget,
3910 GdkEventButton *event)
3912 GtkEntry *entry = GTK_ENTRY (widget);
3913 GtkEntryPrivate *priv = entry->priv;
3914 EntryIconInfo *icon_info = NULL;
3917 for (i = 0; i < MAX_ICONS; i++)
3919 icon_info = priv->icons[i];
3921 if (!icon_info || icon_info->insensitive)
3924 if (event->window == icon_info->window)
3926 icon_info->pressed = FALSE;
3928 if (should_prelight (entry, i) &&
3929 event->x >= 0 && event->y >= 0 &&
3930 event->x < gdk_window_get_width (icon_info->window) &&
3931 event->y < gdk_window_get_height (icon_info->window))
3933 icon_info->prelight = TRUE;
3934 gtk_widget_queue_draw (widget);
3937 if (!icon_info->nonactivatable)
3938 g_signal_emit (entry, signals[ICON_RELEASE], 0, i, event);
3944 if (event->window != priv->text_area || priv->button != event->button)
3949 gint tmp_pos = gtk_entry_find_position (entry, priv->drag_start_x);
3951 gtk_editable_set_position (GTK_EDITABLE (entry), tmp_pos);
3958 gtk_entry_update_primary_selection (entry);
3964 _gtk_entry_get_selected_text (GtkEntry *entry)
3966 GtkEditable *editable = GTK_EDITABLE (entry);
3967 gint start_text, end_text;
3970 if (gtk_editable_get_selection_bounds (editable, &start_text, &end_text))
3971 text = gtk_editable_get_chars (editable, start_text, end_text);
3977 gtk_entry_motion_notify (GtkWidget *widget,
3978 GdkEventMotion *event)
3980 GtkEntry *entry = GTK_ENTRY (widget);
3981 GtkEntryPrivate *priv = entry->priv;
3982 EntryIconInfo *icon_info = NULL;
3983 GdkDragContext *context;
3987 for (i = 0; i < MAX_ICONS; i++)
3989 icon_info = priv->icons[i];
3991 if (!icon_info || icon_info->insensitive)
3994 if (event->window == icon_info->window)
3996 if (icon_info->pressed &&
3997 icon_info->target_list != NULL &&
3998 gtk_drag_check_threshold (widget,
4004 icon_info->in_drag = TRUE;
4005 icon_info->pressed = FALSE;
4006 context = gtk_drag_begin (widget,
4007 icon_info->target_list,
4017 if (priv->mouse_cursor_obscured)
4021 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
4022 gdk_window_set_cursor (priv->text_area, cursor);
4023 gdk_cursor_unref (cursor);
4024 priv->mouse_cursor_obscured = FALSE;
4027 if (event->window != priv->text_area || priv->button != 1)
4030 if (priv->select_lines)
4033 gdk_event_request_motions (event);
4037 if (gtk_entry_get_display_mode (entry) == DISPLAY_NORMAL &&
4038 gtk_drag_check_threshold (widget,
4039 priv->drag_start_x, priv->drag_start_y,
4040 event->x + priv->scroll_offset, event->y))
4042 GdkDragContext *context;
4043 GtkTargetList *target_list = gtk_target_list_new (NULL, 0);
4044 guint actions = priv->editable ? GDK_ACTION_COPY | GDK_ACTION_MOVE : GDK_ACTION_COPY;
4046 cairo_surface_t *surface;
4048 gtk_target_list_add_text_targets (target_list, 0);
4050 text = _gtk_entry_get_selected_text (entry);
4051 surface = _gtk_text_util_create_drag_icon (widget, text, -1);
4053 context = gtk_drag_begin (widget, target_list, actions,
4054 priv->button, (GdkEvent *)event);
4057 gtk_drag_set_icon_surface (context, surface);
4059 gtk_drag_set_icon_default (context);
4062 cairo_surface_destroy (surface);
4065 priv->in_drag = FALSE;
4068 gtk_target_list_unref (target_list);
4075 else if (event->y >= gdk_window_get_height (priv->text_area))
4076 tmp_pos = gtk_entry_buffer_get_length (get_buffer (entry));
4078 tmp_pos = gtk_entry_find_position (entry, event->x + priv->scroll_offset);
4080 if (priv->select_words)
4083 gint old_min, old_max;
4086 min = gtk_entry_move_backward_word (entry, tmp_pos, TRUE);
4087 max = gtk_entry_move_forward_word (entry, tmp_pos, TRUE);
4089 pos = priv->current_pos;
4090 bound = priv->selection_bound;
4092 old_min = MIN(priv->current_pos, priv->selection_bound);
4093 old_max = MAX(priv->current_pos, priv->selection_bound);
4100 else if (old_max < max)
4105 else if (pos == old_min)
4107 if (priv->current_pos != min)
4112 if (priv->current_pos != max)
4116 gtk_entry_set_positions (entry, pos, bound);
4119 gtk_entry_set_positions (entry, tmp_pos, -1);
4126 set_invisible_cursor (GdkWindow *window)
4128 GdkDisplay *display;
4131 display = gdk_window_get_display (window);
4132 cursor = gdk_cursor_new_for_display (display, GDK_BLANK_CURSOR);
4134 gdk_window_set_cursor (window, cursor);
4136 gdk_cursor_unref (cursor);
4140 gtk_entry_obscure_mouse_cursor (GtkEntry *entry)
4142 GtkEntryPrivate *priv = entry->priv;
4144 if (priv->mouse_cursor_obscured)
4147 set_invisible_cursor (priv->text_area);
4149 priv->mouse_cursor_obscured = TRUE;
4153 gtk_entry_key_press (GtkWidget *widget,
4156 GtkEntry *entry = GTK_ENTRY (widget);
4157 GtkEntryPrivate *priv = entry->priv;
4159 gtk_entry_reset_blink_time (entry);
4160 gtk_entry_pend_cursor_blink (entry);
4164 if (gtk_im_context_filter_keypress (priv->im_context, event))
4166 gtk_entry_obscure_mouse_cursor (entry);
4167 priv->need_im_reset = TRUE;
4172 if (event->keyval == GDK_KEY_Return ||
4173 event->keyval == GDK_KEY_KP_Enter ||
4174 event->keyval == GDK_KEY_ISO_Enter ||
4175 event->keyval == GDK_KEY_Escape)
4177 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
4179 if (completion && completion->priv->completion_timeout)
4181 g_source_remove (completion->priv->completion_timeout);
4182 completion->priv->completion_timeout = 0;
4185 _gtk_entry_reset_im_context (entry);
4188 if (GTK_WIDGET_CLASS (gtk_entry_parent_class)->key_press_event (widget, event))
4189 /* Activate key bindings
4193 if (!priv->editable && event->length)
4194 gtk_widget_error_bell (widget);
4200 gtk_entry_key_release (GtkWidget *widget,
4203 GtkEntry *entry = GTK_ENTRY (widget);
4204 GtkEntryPrivate *priv = entry->priv;
4208 if (gtk_im_context_filter_keypress (priv->im_context, event))
4210 priv->need_im_reset = TRUE;
4215 return GTK_WIDGET_CLASS (gtk_entry_parent_class)->key_release_event (widget, event);
4219 gtk_entry_focus_in (GtkWidget *widget,
4220 GdkEventFocus *event)
4222 GtkEntry *entry = GTK_ENTRY (widget);
4223 GtkEntryPrivate *priv = entry->priv;
4226 gtk_widget_queue_draw (widget);
4228 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (widget));
4232 priv->need_im_reset = TRUE;
4233 gtk_im_context_focus_in (priv->im_context);
4234 keymap_state_changed (keymap, entry);
4235 g_signal_connect (keymap, "state-changed",
4236 G_CALLBACK (keymap_state_changed), entry);
4239 g_signal_connect (keymap, "direction-changed",
4240 G_CALLBACK (keymap_direction_changed), entry);
4242 gtk_entry_reset_blink_time (entry);
4243 gtk_entry_check_cursor_blink (entry);
4249 gtk_entry_focus_out (GtkWidget *widget,
4250 GdkEventFocus *event)
4252 GtkEntry *entry = GTK_ENTRY (widget);
4253 GtkEntryPrivate *priv = entry->priv;
4254 GtkEntryCompletion *completion;
4257 gtk_widget_queue_draw (widget);
4259 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (widget));
4263 priv->need_im_reset = TRUE;
4264 gtk_im_context_focus_out (priv->im_context);
4265 remove_capslock_feedback (entry);
4268 gtk_entry_check_cursor_blink (entry);
4270 g_signal_handlers_disconnect_by_func (keymap, keymap_state_changed, entry);
4271 g_signal_handlers_disconnect_by_func (keymap, keymap_direction_changed, entry);
4273 completion = gtk_entry_get_completion (entry);
4275 _gtk_entry_completion_popdown (completion);
4281 gtk_entry_grab_focus (GtkWidget *widget)
4283 GtkEntry *entry = GTK_ENTRY (widget);
4284 GtkEntryPrivate *priv = entry->priv;
4285 gboolean select_on_focus;
4287 GTK_WIDGET_CLASS (gtk_entry_parent_class)->grab_focus (widget);
4289 if (priv->editable && !priv->in_click)
4291 g_object_get (gtk_widget_get_settings (widget),
4292 "gtk-entry-select-on-focus",
4296 if (select_on_focus)
4297 gtk_editable_select_region (GTK_EDITABLE (widget), 0, -1);
4302 gtk_entry_direction_changed (GtkWidget *widget,
4303 GtkTextDirection previous_dir)
4305 GtkEntry *entry = GTK_ENTRY (widget);
4307 gtk_entry_recompute (entry);
4309 GTK_WIDGET_CLASS (gtk_entry_parent_class)->direction_changed (widget, previous_dir);
4313 gtk_entry_state_changed (GtkWidget *widget,
4314 GtkStateType previous_state)
4316 GtkEntry *entry = GTK_ENTRY (widget);
4317 GtkEntryPrivate *priv = entry->priv;
4320 if (gtk_widget_get_realized (widget))
4322 if (gtk_widget_is_sensitive (widget))
4323 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
4327 gdk_window_set_cursor (priv->text_area, cursor);
4330 gdk_cursor_unref (cursor);
4332 priv->mouse_cursor_obscured = FALSE;
4334 update_cursors (widget);
4337 if (!gtk_widget_is_sensitive (widget))
4339 /* Clear any selection */
4340 gtk_editable_select_region (GTK_EDITABLE (entry), priv->current_pos, priv->current_pos);
4343 gtk_widget_queue_draw (widget);
4347 gtk_entry_screen_changed (GtkWidget *widget,
4348 GdkScreen *old_screen)
4350 gtk_entry_recompute (GTK_ENTRY (widget));
4353 /* GtkEditable method implementations
4356 gtk_entry_insert_text (GtkEditable *editable,
4357 const gchar *new_text,
4358 gint new_text_length,
4361 g_object_ref (editable);
4364 * The incoming text may a password or other secret. We make sure
4365 * not to copy it into temporary buffers.
4368 g_signal_emit_by_name (editable, "insert-text", new_text, new_text_length, position);
4370 g_object_unref (editable);
4374 gtk_entry_delete_text (GtkEditable *editable,
4378 g_object_ref (editable);
4380 g_signal_emit_by_name (editable, "delete-text", start_pos, end_pos);
4382 g_object_unref (editable);
4386 gtk_entry_get_chars (GtkEditable *editable,
4390 GtkEntry *entry = GTK_ENTRY (editable);
4393 gint start_index, end_index;
4395 text = gtk_entry_buffer_get_text (get_buffer (entry));
4396 text_length = gtk_entry_buffer_get_length (get_buffer (entry));
4399 end_pos = text_length;
4401 start_pos = MIN (text_length, start_pos);
4402 end_pos = MIN (text_length, end_pos);
4404 start_index = g_utf8_offset_to_pointer (text, start_pos) - text;
4405 end_index = g_utf8_offset_to_pointer (text, end_pos) - text;
4407 return g_strndup (text + start_index, end_index - start_index);
4411 gtk_entry_real_set_position (GtkEditable *editable,
4414 GtkEntry *entry = GTK_ENTRY (editable);
4415 GtkEntryPrivate *priv = entry->priv;
4419 length = gtk_entry_buffer_get_length (get_buffer (entry));
4420 if (position < 0 || position > length)
4423 if (position != priv->current_pos ||
4424 position != priv->selection_bound)
4426 _gtk_entry_reset_im_context (entry);
4427 gtk_entry_set_positions (entry, position, position);
4432 gtk_entry_get_position (GtkEditable *editable)
4434 GtkEntry *entry = GTK_ENTRY (editable);
4435 GtkEntryPrivate *priv = entry->priv;
4437 return priv->current_pos;
4441 gtk_entry_set_selection_bounds (GtkEditable *editable,
4445 GtkEntry *entry = GTK_ENTRY (editable);
4448 length = gtk_entry_buffer_get_length (get_buffer (entry));
4454 _gtk_entry_reset_im_context (entry);
4456 gtk_entry_set_positions (entry,
4458 MIN (start, length));
4460 gtk_entry_update_primary_selection (entry);
4464 gtk_entry_get_selection_bounds (GtkEditable *editable,
4468 GtkEntry *entry = GTK_ENTRY (editable);
4469 GtkEntryPrivate *priv = entry->priv;
4471 *start = priv->selection_bound;
4472 *end = priv->current_pos;
4474 return (priv->selection_bound != priv->current_pos);
4478 icon_theme_changed (GtkEntry *entry)
4480 GtkEntryPrivate *priv = entry->priv;
4483 for (i = 0; i < MAX_ICONS; i++)
4485 EntryIconInfo *icon_info = priv->icons[i];
4486 if (icon_info != NULL)
4488 if (icon_info->storage_type == GTK_IMAGE_ICON_NAME)
4489 gtk_entry_set_icon_from_icon_name (entry, i, icon_info->icon_name);
4490 else if (icon_info->storage_type == GTK_IMAGE_STOCK)
4491 gtk_entry_set_icon_from_stock (entry, i, icon_info->stock_id);
4492 else if (icon_info->storage_type == GTK_IMAGE_GICON)
4493 gtk_entry_set_icon_from_gicon (entry, i, icon_info->gicon);
4497 gtk_widget_queue_draw (GTK_WIDGET (entry));
4501 icon_margin_changed (GtkEntry *entry)
4503 GtkEntryPrivate *priv = entry->priv;
4506 _gtk_entry_effective_inner_border (GTK_ENTRY (entry), &border);
4508 priv->icon_margin = border.left;
4512 gtk_entry_style_set (GtkWidget *widget,
4513 GtkStyle *previous_style)
4515 GtkEntry *entry = GTK_ENTRY (widget);
4516 GtkEntryPrivate *priv = entry->priv;
4518 gboolean interior_focus;
4520 gtk_widget_style_get (widget,
4521 "focus-line-width", &focus_width,
4522 "interior-focus", &interior_focus,
4525 priv->focus_width = focus_width;
4526 priv->interior_focus = interior_focus;
4528 if (!priv->invisible_char_set)
4529 priv->invisible_char = find_invisible_char (GTK_WIDGET (entry));
4531 gtk_entry_recompute (entry);
4533 icon_theme_changed (entry);
4534 icon_margin_changed (entry);
4537 /* GtkCellEditable method implementations
4540 gtk_cell_editable_entry_activated (GtkEntry *entry, gpointer data)
4542 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4543 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4547 gtk_cell_editable_key_press_event (GtkEntry *entry,
4548 GdkEventKey *key_event,
4551 GtkEntryPrivate *priv = entry->priv;
4553 if (key_event->keyval == GDK_KEY_Escape)
4555 priv->editing_canceled = TRUE;
4556 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4557 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4562 /* override focus */
4563 if (key_event->keyval == GDK_KEY_Up || key_event->keyval == GDK_KEY_Down)
4565 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4566 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4575 gtk_entry_start_editing (GtkCellEditable *cell_editable,
4578 GtkEntry *entry = GTK_ENTRY (cell_editable);
4579 GtkEntryPrivate *priv = entry->priv;
4581 priv->is_cell_renderer = TRUE;
4583 g_signal_connect (cell_editable, "activate",
4584 G_CALLBACK (gtk_cell_editable_entry_activated), NULL);
4585 g_signal_connect (cell_editable, "key-press-event",
4586 G_CALLBACK (gtk_cell_editable_key_press_event), NULL);
4590 gtk_entry_password_hint_free (GtkEntryPasswordHint *password_hint)
4592 if (password_hint->source_id)
4593 g_source_remove (password_hint->source_id);
4595 g_slice_free (GtkEntryPasswordHint, password_hint);
4600 gtk_entry_remove_password_hint (gpointer data)
4602 GtkEntryPasswordHint *password_hint = g_object_get_qdata (data, quark_password_hint);
4603 password_hint->position = -1;
4605 /* Force the string to be redrawn, but now without a visible character */
4606 gtk_entry_recompute (GTK_ENTRY (data));
4610 /* Default signal handlers
4613 gtk_entry_real_insert_text (GtkEditable *editable,
4614 const gchar *new_text,
4615 gint new_text_length,
4621 n_chars = g_utf8_strlen (new_text, new_text_length);
4624 * The actual insertion into the buffer. This will end up firing the
4625 * following signal handlers: buffer_inserted_text(), buffer_notify_display_text(),
4626 * buffer_notify_text(), buffer_notify_length()
4628 n_inserted = gtk_entry_buffer_insert_text (get_buffer (GTK_ENTRY (editable)), *position, new_text, n_chars);
4630 if (n_inserted != n_chars)
4631 gtk_widget_error_bell (GTK_WIDGET (editable));
4633 *position += n_inserted;
4637 gtk_entry_real_delete_text (GtkEditable *editable,
4642 * The actual deletion from the buffer. This will end up firing the
4643 * following signal handlers: buffer_deleted_text(), buffer_notify_display_text(),
4644 * buffer_notify_text(), buffer_notify_length()
4647 gtk_entry_buffer_delete_text (get_buffer (GTK_ENTRY (editable)), start_pos, end_pos - start_pos);
4650 /* GtkEntryBuffer signal handlers
4653 buffer_inserted_text (GtkEntryBuffer *buffer,
4659 GtkEntryPrivate *priv = entry->priv;
4660 guint password_hint_timeout;
4662 if (priv->current_pos > position)
4663 priv->current_pos += n_chars;
4665 if (priv->selection_bound > position)
4666 priv->selection_bound += n_chars;
4668 /* Calculate the password hint if it needs to be displayed. */
4669 if (n_chars == 1 && !priv->visible)
4671 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
4672 "gtk-entry-password-hint-timeout", &password_hint_timeout,
4675 if (password_hint_timeout > 0)
4677 GtkEntryPasswordHint *password_hint = g_object_get_qdata (G_OBJECT (entry),
4678 quark_password_hint);
4681 password_hint = g_slice_new0 (GtkEntryPasswordHint);
4682 g_object_set_qdata_full (G_OBJECT (entry), quark_password_hint, password_hint,
4683 (GDestroyNotify)gtk_entry_password_hint_free);
4686 password_hint->position = position;
4687 if (password_hint->source_id)
4688 g_source_remove (password_hint->source_id);
4689 password_hint->source_id = gdk_threads_add_timeout (password_hint_timeout,
4690 (GSourceFunc)gtk_entry_remove_password_hint, entry);
4696 buffer_deleted_text (GtkEntryBuffer *buffer,
4701 GtkEntryPrivate *priv = entry->priv;
4702 guint end_pos = position + n_chars;
4703 gint selection_bound;
4706 current_pos = priv->current_pos;
4707 if (current_pos > position)
4708 current_pos -= MIN (current_pos, end_pos) - position;
4710 selection_bound = priv->selection_bound;
4711 if (selection_bound > position)
4712 selection_bound -= MIN (selection_bound, end_pos) - position;
4714 gtk_entry_set_positions (entry, current_pos, selection_bound);
4716 /* We might have deleted the selection */
4717 gtk_entry_update_primary_selection (entry);
4719 /* Disable the password hint if one exists. */
4722 GtkEntryPasswordHint *password_hint = g_object_get_qdata (G_OBJECT (entry),
4723 quark_password_hint);
4726 if (password_hint->source_id)
4727 g_source_remove (password_hint->source_id);
4728 password_hint->source_id = 0;
4729 password_hint->position = -1;
4735 buffer_notify_text (GtkEntryBuffer *buffer,
4739 gtk_entry_recompute (entry);
4740 emit_changed (entry);
4741 g_object_notify (G_OBJECT (entry), "text");
4745 buffer_notify_length (GtkEntryBuffer *buffer,
4749 g_object_notify (G_OBJECT (entry), "text-length");
4753 buffer_notify_max_length (GtkEntryBuffer *buffer,
4757 g_object_notify (G_OBJECT (entry), "max-length");
4761 buffer_connect_signals (GtkEntry *entry)
4763 g_signal_connect (get_buffer (entry), "inserted-text", G_CALLBACK (buffer_inserted_text), entry);
4764 g_signal_connect (get_buffer (entry), "deleted-text", G_CALLBACK (buffer_deleted_text), entry);
4765 g_signal_connect (get_buffer (entry), "notify::text", G_CALLBACK (buffer_notify_text), entry);
4766 g_signal_connect (get_buffer (entry), "notify::length", G_CALLBACK (buffer_notify_length), entry);
4767 g_signal_connect (get_buffer (entry), "notify::max-length", G_CALLBACK (buffer_notify_max_length), entry);
4771 buffer_disconnect_signals (GtkEntry *entry)
4773 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_inserted_text, entry);
4774 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_deleted_text, entry);
4775 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_text, entry);
4776 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_length, entry);
4777 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_max_length, entry);
4780 /* Compute the X position for an offset that corresponds to the "more important
4781 * cursor position for that offset. We use this when trying to guess to which
4782 * end of the selection we should go to when the user hits the left or
4786 get_better_cursor_x (GtkEntry *entry,
4789 GtkEntryPrivate *priv = entry->priv;
4790 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
4791 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
4792 gboolean split_cursor;
4794 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
4795 const gchar *text = pango_layout_get_text (layout);
4796 gint index = g_utf8_offset_to_pointer (text, offset) - text;
4798 PangoRectangle strong_pos, weak_pos;
4800 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
4801 "gtk-split-cursor", &split_cursor,
4804 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
4807 return strong_pos.x / PANGO_SCALE;
4809 return (keymap_direction == priv->resolved_dir) ? strong_pos.x / PANGO_SCALE : weak_pos.x / PANGO_SCALE;
4813 gtk_entry_move_cursor (GtkEntry *entry,
4814 GtkMovementStep step,
4816 gboolean extend_selection)
4818 GtkEntryPrivate *priv = entry->priv;
4819 gint new_pos = priv->current_pos;
4821 _gtk_entry_reset_im_context (entry);
4823 if (priv->current_pos != priv->selection_bound && !extend_selection)
4825 /* If we have a current selection and aren't extending it, move to the
4826 * start/or end of the selection as appropriate
4830 case GTK_MOVEMENT_VISUAL_POSITIONS:
4832 gint current_x = get_better_cursor_x (entry, priv->current_pos);
4833 gint bound_x = get_better_cursor_x (entry, priv->selection_bound);
4836 new_pos = current_x < bound_x ? priv->current_pos : priv->selection_bound;
4838 new_pos = current_x > bound_x ? priv->current_pos : priv->selection_bound;
4841 case GTK_MOVEMENT_LOGICAL_POSITIONS:
4842 case GTK_MOVEMENT_WORDS:
4844 new_pos = MIN (priv->current_pos, priv->selection_bound);
4846 new_pos = MAX (priv->current_pos, priv->selection_bound);
4848 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
4849 case GTK_MOVEMENT_PARAGRAPH_ENDS:
4850 case GTK_MOVEMENT_BUFFER_ENDS:
4851 new_pos = count < 0 ? 0 : gtk_entry_buffer_get_length (get_buffer (entry));
4853 case GTK_MOVEMENT_DISPLAY_LINES:
4854 case GTK_MOVEMENT_PARAGRAPHS:
4855 case GTK_MOVEMENT_PAGES:
4856 case GTK_MOVEMENT_HORIZONTAL_PAGES:
4864 case GTK_MOVEMENT_LOGICAL_POSITIONS:
4865 new_pos = gtk_entry_move_logically (entry, new_pos, count);
4867 case GTK_MOVEMENT_VISUAL_POSITIONS:
4868 new_pos = gtk_entry_move_visually (entry, new_pos, count);
4869 if (priv->current_pos == new_pos)
4871 if (!extend_selection)
4873 if (!gtk_widget_keynav_failed (GTK_WIDGET (entry),
4875 GTK_DIR_RIGHT : GTK_DIR_LEFT))
4877 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (entry));
4880 gtk_widget_child_focus (toplevel,
4882 GTK_DIR_RIGHT : GTK_DIR_LEFT);
4887 gtk_widget_error_bell (GTK_WIDGET (entry));
4891 case GTK_MOVEMENT_WORDS:
4894 new_pos = gtk_entry_move_forward_word (entry, new_pos, FALSE);
4899 new_pos = gtk_entry_move_backward_word (entry, new_pos, FALSE);
4902 if (priv->current_pos == new_pos)
4903 gtk_widget_error_bell (GTK_WIDGET (entry));
4905 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
4906 case GTK_MOVEMENT_PARAGRAPH_ENDS:
4907 case GTK_MOVEMENT_BUFFER_ENDS:
4908 new_pos = count < 0 ? 0 : gtk_entry_buffer_get_length (get_buffer (entry));
4909 if (priv->current_pos == new_pos)
4910 gtk_widget_error_bell (GTK_WIDGET (entry));
4912 case GTK_MOVEMENT_DISPLAY_LINES:
4913 case GTK_MOVEMENT_PARAGRAPHS:
4914 case GTK_MOVEMENT_PAGES:
4915 case GTK_MOVEMENT_HORIZONTAL_PAGES:
4920 if (extend_selection)
4921 gtk_editable_select_region (GTK_EDITABLE (entry), priv->selection_bound, new_pos);
4923 gtk_editable_set_position (GTK_EDITABLE (entry), new_pos);
4925 gtk_entry_pend_cursor_blink (entry);
4929 gtk_entry_insert_at_cursor (GtkEntry *entry,
4932 GtkEntryPrivate *priv = entry->priv;
4933 GtkEditable *editable = GTK_EDITABLE (entry);
4934 gint pos = priv->current_pos;
4938 _gtk_entry_reset_im_context (entry);
4940 gtk_editable_insert_text (editable, str, -1, &pos);
4941 gtk_editable_set_position (editable, pos);
4946 gtk_entry_delete_from_cursor (GtkEntry *entry,
4950 GtkEntryPrivate *priv = entry->priv;
4951 GtkEditable *editable = GTK_EDITABLE (entry);
4952 gint start_pos = priv->current_pos;
4953 gint end_pos = priv->current_pos;
4954 gint old_n_bytes = gtk_entry_buffer_get_bytes (get_buffer (entry));
4956 _gtk_entry_reset_im_context (entry);
4958 if (!priv->editable)
4960 gtk_widget_error_bell (GTK_WIDGET (entry));
4964 if (priv->selection_bound != priv->current_pos)
4966 gtk_editable_delete_selection (editable);
4972 case GTK_DELETE_CHARS:
4973 end_pos = gtk_entry_move_logically (entry, priv->current_pos, count);
4974 gtk_editable_delete_text (editable, MIN (start_pos, end_pos), MAX (start_pos, end_pos));
4976 case GTK_DELETE_WORDS:
4979 /* Move to end of current word, or if not on a word, end of previous word */
4980 end_pos = gtk_entry_move_backward_word (entry, end_pos, FALSE);
4981 end_pos = gtk_entry_move_forward_word (entry, end_pos, FALSE);
4985 /* Move to beginning of current word, or if not on a word, begining of next word */
4986 start_pos = gtk_entry_move_forward_word (entry, start_pos, FALSE);
4987 start_pos = gtk_entry_move_backward_word (entry, start_pos, FALSE);
4991 case GTK_DELETE_WORD_ENDS:
4994 start_pos = gtk_entry_move_backward_word (entry, start_pos, FALSE);
4999 end_pos = gtk_entry_move_forward_word (entry, end_pos, FALSE);
5002 gtk_editable_delete_text (editable, start_pos, end_pos);
5004 case GTK_DELETE_DISPLAY_LINE_ENDS:
5005 case GTK_DELETE_PARAGRAPH_ENDS:
5007 gtk_editable_delete_text (editable, 0, priv->current_pos);
5009 gtk_editable_delete_text (editable, priv->current_pos, -1);
5011 case GTK_DELETE_DISPLAY_LINES:
5012 case GTK_DELETE_PARAGRAPHS:
5013 gtk_editable_delete_text (editable, 0, -1);
5015 case GTK_DELETE_WHITESPACE:
5016 gtk_entry_delete_whitespace (entry);
5020 if (gtk_entry_buffer_get_bytes (get_buffer (entry)) == old_n_bytes)
5021 gtk_widget_error_bell (GTK_WIDGET (entry));
5023 gtk_entry_pend_cursor_blink (entry);
5027 gtk_entry_backspace (GtkEntry *entry)
5029 GtkEntryPrivate *priv = entry->priv;
5030 GtkEditable *editable = GTK_EDITABLE (entry);
5033 _gtk_entry_reset_im_context (entry);
5035 if (!priv->editable)
5037 gtk_widget_error_bell (GTK_WIDGET (entry));
5041 if (priv->selection_bound != priv->current_pos)
5043 gtk_editable_delete_selection (editable);
5047 prev_pos = gtk_entry_move_logically (entry, priv->current_pos, -1);
5049 if (prev_pos < priv->current_pos)
5051 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
5052 PangoLogAttr *log_attrs;
5055 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
5057 /* Deleting parts of characters */
5058 if (log_attrs[priv->current_pos].backspace_deletes_character)
5060 gchar *cluster_text;
5061 gchar *normalized_text;
5064 cluster_text = gtk_entry_get_display_text (entry, prev_pos,
5066 normalized_text = g_utf8_normalize (cluster_text,
5067 strlen (cluster_text),
5069 len = g_utf8_strlen (normalized_text, -1);
5071 gtk_editable_delete_text (editable, prev_pos, priv->current_pos);
5074 gint pos = priv->current_pos;
5076 gtk_editable_insert_text (editable, normalized_text,
5077 g_utf8_offset_to_pointer (normalized_text, len - 1) - normalized_text,
5079 gtk_editable_set_position (editable, pos);
5082 g_free (normalized_text);
5083 g_free (cluster_text);
5087 gtk_editable_delete_text (editable, prev_pos, priv->current_pos);
5094 gtk_widget_error_bell (GTK_WIDGET (entry));
5097 gtk_entry_pend_cursor_blink (entry);
5101 gtk_entry_copy_clipboard (GtkEntry *entry)
5103 GtkEntryPrivate *priv = entry->priv;
5104 GtkEditable *editable = GTK_EDITABLE (entry);
5108 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5112 gtk_widget_error_bell (GTK_WIDGET (entry));
5116 str = gtk_entry_get_display_text (entry, start, end);
5117 gtk_clipboard_set_text (gtk_widget_get_clipboard (GTK_WIDGET (entry),
5118 GDK_SELECTION_CLIPBOARD),
5125 gtk_entry_cut_clipboard (GtkEntry *entry)
5127 GtkEntryPrivate *priv = entry->priv;
5128 GtkEditable *editable = GTK_EDITABLE (entry);
5133 gtk_widget_error_bell (GTK_WIDGET (entry));
5137 gtk_entry_copy_clipboard (entry);
5141 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5142 gtk_editable_delete_text (editable, start, end);
5146 gtk_widget_error_bell (GTK_WIDGET (entry));
5151 gtk_entry_paste_clipboard (GtkEntry *entry)
5153 GtkEntryPrivate *priv = entry->priv;
5156 gtk_entry_paste (entry, GDK_NONE);
5158 gtk_widget_error_bell (GTK_WIDGET (entry));
5162 gtk_entry_delete_cb (GtkEntry *entry)
5164 GtkEntryPrivate *priv = entry->priv;
5165 GtkEditable *editable = GTK_EDITABLE (entry);
5170 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5171 gtk_editable_delete_text (editable, start, end);
5176 gtk_entry_toggle_overwrite (GtkEntry *entry)
5178 GtkEntryPrivate *priv = entry->priv;
5180 priv->overwrite_mode = !priv->overwrite_mode;
5181 gtk_entry_pend_cursor_blink (entry);
5182 gtk_widget_queue_draw (GTK_WIDGET (entry));
5186 gtk_entry_select_all (GtkEntry *entry)
5188 gtk_entry_select_line (entry);
5192 gtk_entry_real_activate (GtkEntry *entry)
5194 GtkEntryPrivate *priv = entry->priv;
5196 GtkWidget *default_widget, *focus_widget;
5197 GtkWidget *toplevel;
5200 widget = GTK_WIDGET (entry);
5202 if (priv->activates_default)
5204 toplevel = gtk_widget_get_toplevel (widget);
5205 if (GTK_IS_WINDOW (toplevel))
5207 window = GTK_WINDOW (toplevel);
5211 default_widget = gtk_window_get_default_widget (window);
5212 focus_widget = gtk_window_get_focus (window);
5213 if (widget != default_widget &&
5214 !(widget == focus_widget && (!default_widget || !gtk_widget_get_sensitive (default_widget))))
5215 gtk_window_activate_default (window);
5222 keymap_direction_changed (GdkKeymap *keymap,
5225 gtk_entry_recompute (entry);
5228 /* IM Context Callbacks
5232 gtk_entry_commit_cb (GtkIMContext *context,
5236 GtkEntryPrivate *priv = entry->priv;
5239 gtk_entry_enter_text (entry, str);
5243 gtk_entry_preedit_changed_cb (GtkIMContext *context,
5246 GtkEntryPrivate *priv = entry->priv;
5250 gchar *preedit_string;
5253 gtk_im_context_get_preedit_string (priv->im_context,
5254 &preedit_string, NULL,
5256 g_signal_emit (entry, signals[PREEDIT_CHANGED], 0, preedit_string);
5257 priv->preedit_length = strlen (preedit_string);
5258 cursor_pos = CLAMP (cursor_pos, 0, g_utf8_strlen (preedit_string, -1));
5259 priv->preedit_cursor = cursor_pos;
5260 g_free (preedit_string);
5262 gtk_entry_recompute (entry);
5267 gtk_entry_retrieve_surrounding_cb (GtkIMContext *context,
5270 GtkEntryPrivate *priv = entry->priv;
5273 /* XXXX ??? does this even make sense when text is not visible? Should we return FALSE? */
5274 text = gtk_entry_get_display_text (entry, 0, -1);
5275 gtk_im_context_set_surrounding (context, text, strlen (text), /* Length in bytes */
5276 g_utf8_offset_to_pointer (text, priv->current_pos) - text);
5283 gtk_entry_delete_surrounding_cb (GtkIMContext *slave,
5288 GtkEntryPrivate *priv = entry->priv;
5291 gtk_editable_delete_text (GTK_EDITABLE (entry),
5292 priv->current_pos + offset,
5293 priv->current_pos + offset + n_chars);
5298 /* Internal functions
5301 /* Used for im_commit_cb and inserting Unicode chars */
5303 gtk_entry_enter_text (GtkEntry *entry,
5306 GtkEntryPrivate *priv = entry->priv;
5307 GtkEditable *editable = GTK_EDITABLE (entry);
5309 gboolean old_need_im_reset;
5311 old_need_im_reset = priv->need_im_reset;
5312 priv->need_im_reset = FALSE;
5314 if (gtk_editable_get_selection_bounds (editable, NULL, NULL))
5315 gtk_editable_delete_selection (editable);
5318 if (priv->overwrite_mode)
5319 gtk_entry_delete_from_cursor (entry, GTK_DELETE_CHARS, 1);
5322 tmp_pos = priv->current_pos;
5323 gtk_editable_insert_text (editable, str, strlen (str), &tmp_pos);
5324 gtk_editable_set_position (editable, tmp_pos);
5326 priv->need_im_reset = old_need_im_reset;
5329 /* All changes to priv->current_pos and priv->selection_bound
5330 * should go through this function.
5333 gtk_entry_set_positions (GtkEntry *entry,
5335 gint selection_bound)
5337 GtkEntryPrivate *priv = entry->priv;
5338 gboolean changed = FALSE;
5340 g_object_freeze_notify (G_OBJECT (entry));
5342 if (current_pos != -1 &&
5343 priv->current_pos != current_pos)
5345 priv->current_pos = current_pos;
5348 g_object_notify (G_OBJECT (entry), "cursor-position");
5351 if (selection_bound != -1 &&
5352 priv->selection_bound != selection_bound)
5354 priv->selection_bound = selection_bound;
5357 g_object_notify (G_OBJECT (entry), "selection-bound");
5360 g_object_thaw_notify (G_OBJECT (entry));
5364 gtk_entry_move_adjustments (entry);
5365 gtk_entry_recompute (entry);
5370 gtk_entry_reset_layout (GtkEntry *entry)
5372 GtkEntryPrivate *priv = entry->priv;
5374 if (priv->cached_layout)
5376 g_object_unref (priv->cached_layout);
5377 priv->cached_layout = NULL;
5382 update_im_cursor_location (GtkEntry *entry)
5384 GtkEntryPrivate *priv = entry->priv;
5387 gint strong_xoffset;
5388 gint area_width, area_height;
5390 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
5391 gtk_entry_get_text_area_size (entry, NULL, NULL, &area_width, &area_height);
5393 strong_xoffset = strong_x - priv->scroll_offset;
5394 if (strong_xoffset < 0)
5398 else if (strong_xoffset > area_width)
5400 strong_xoffset = area_width;
5402 area.x = strong_xoffset;
5405 area.height = area_height;
5407 gtk_im_context_set_cursor_location (priv->im_context, &area);
5411 recompute_idle_func (gpointer data)
5413 GtkEntry *entry = GTK_ENTRY (data);
5414 GtkEntryPrivate *priv = entry->priv;
5416 priv->recompute_idle = 0;
5418 if (gtk_widget_has_screen (GTK_WIDGET (entry)))
5420 gtk_entry_adjust_scroll (entry);
5421 gtk_entry_queue_draw (entry);
5423 update_im_cursor_location (entry);
5430 gtk_entry_recompute (GtkEntry *entry)
5432 GtkEntryPrivate *priv = entry->priv;
5434 gtk_entry_reset_layout (entry);
5435 gtk_entry_check_cursor_blink (entry);
5437 if (!priv->recompute_idle)
5439 priv->recompute_idle = gdk_threads_add_idle_full (G_PRIORITY_HIGH_IDLE + 15, /* between resize and redraw */
5440 recompute_idle_func, entry, NULL);
5444 static PangoLayout *
5445 gtk_entry_create_layout (GtkEntry *entry,
5446 gboolean include_preedit)
5448 GtkEntryPrivate *priv = entry->priv;
5449 GtkWidget *widget = GTK_WIDGET (entry);
5450 PangoLayout *layout = gtk_widget_create_pango_layout (widget, NULL);
5451 PangoAttrList *tmp_attrs = pango_attr_list_new ();
5453 gchar *preedit_string = NULL;
5454 gint preedit_length = 0;
5455 PangoAttrList *preedit_attrs = NULL;
5460 pango_layout_set_single_paragraph_mode (layout, TRUE);
5462 display = gtk_entry_get_display_text (entry, 0, -1);
5463 n_bytes = strlen (display);
5465 if (include_preedit)
5467 gtk_im_context_get_preedit_string (priv->im_context,
5468 &preedit_string, &preedit_attrs, NULL);
5469 preedit_length = priv->preedit_length;
5474 GString *tmp_string = g_string_new (display);
5475 gint cursor_index = g_utf8_offset_to_pointer (display, priv->current_pos) - display;
5477 g_string_insert (tmp_string, cursor_index, preedit_string);
5479 pango_layout_set_text (layout, tmp_string->str, tmp_string->len);
5481 pango_attr_list_splice (tmp_attrs, preedit_attrs,
5482 cursor_index, preedit_length);
5484 g_string_free (tmp_string, TRUE);
5488 PangoDirection pango_dir;
5490 if (gtk_entry_get_display_mode (entry) == DISPLAY_NORMAL)
5491 pango_dir = pango_find_base_dir (display, n_bytes);
5493 pango_dir = PANGO_DIRECTION_NEUTRAL;
5495 if (pango_dir == PANGO_DIRECTION_NEUTRAL)
5497 if (gtk_widget_has_focus (widget))
5499 GdkDisplay *display = gtk_widget_get_display (widget);
5500 GdkKeymap *keymap = gdk_keymap_get_for_display (display);
5501 if (gdk_keymap_get_direction (keymap) == PANGO_DIRECTION_RTL)
5502 pango_dir = PANGO_DIRECTION_RTL;
5504 pango_dir = PANGO_DIRECTION_LTR;
5508 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
5509 pango_dir = PANGO_DIRECTION_RTL;
5511 pango_dir = PANGO_DIRECTION_LTR;
5515 pango_context_set_base_dir (gtk_widget_get_pango_context (widget),
5518 priv->resolved_dir = pango_dir;
5520 pango_layout_set_text (layout, display, n_bytes);
5523 pango_layout_set_attributes (layout, tmp_attrs);
5525 g_free (preedit_string);
5529 pango_attr_list_unref (preedit_attrs);
5531 pango_attr_list_unref (tmp_attrs);
5536 static PangoLayout *
5537 gtk_entry_ensure_layout (GtkEntry *entry,
5538 gboolean include_preedit)
5540 GtkEntryPrivate *priv = entry->priv;
5542 if (priv->preedit_length > 0 &&
5543 !include_preedit != !priv->cache_includes_preedit)
5544 gtk_entry_reset_layout (entry);
5546 if (!priv->cached_layout)
5548 priv->cached_layout = gtk_entry_create_layout (entry, include_preedit);
5549 priv->cache_includes_preedit = include_preedit;
5552 return priv->cached_layout;
5556 get_layout_position (GtkEntry *entry,
5560 GtkEntryPrivate *priv = entry->priv;
5561 PangoLayout *layout;
5562 PangoRectangle logical_rect;
5563 gint area_width, area_height;
5564 GtkBorder inner_border;
5566 PangoLayoutLine *line;
5568 layout = gtk_entry_ensure_layout (entry, TRUE);
5570 gtk_entry_get_text_area_size (entry, NULL, NULL, &area_width, &area_height);
5571 _gtk_entry_effective_inner_border (entry, &inner_border);
5573 area_height = PANGO_SCALE * (area_height - inner_border.top - inner_border.bottom);
5575 line = pango_layout_get_lines_readonly (layout)->data;
5576 pango_layout_line_get_extents (line, NULL, &logical_rect);
5578 /* Align primarily for locale's ascent/descent */
5579 y_pos = ((area_height - priv->ascent - priv->descent) / 2 +
5580 priv->ascent + logical_rect.y);
5582 /* Now see if we need to adjust to fit in actual drawn string */
5583 if (logical_rect.height > area_height)
5584 y_pos = (area_height - logical_rect.height) / 2;
5587 else if (y_pos + logical_rect.height > area_height)
5588 y_pos = area_height - logical_rect.height;
5590 y_pos = inner_border.top + y_pos / PANGO_SCALE;
5593 *x = inner_border.left - priv->scroll_offset;
5600 draw_text_with_color (GtkEntry *entry, cairo_t *cr, GdkColor *default_color)
5602 GtkEntryPrivate *priv = entry->priv;
5603 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
5606 gint start_pos, end_pos;
5608 widget = GTK_WIDGET (entry);
5612 get_layout_position (entry, &x, &y);
5614 cairo_move_to (cr, x, y);
5615 gdk_cairo_set_source_color (cr, default_color);
5616 pango_cairo_show_layout (cr, layout);
5618 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start_pos, &end_pos))
5622 PangoRectangle logical_rect;
5623 GdkColor *selection_color, *text_color;
5624 GtkBorder inner_border;
5627 pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
5628 gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
5630 style = gtk_widget_get_style (widget);
5632 if (gtk_widget_has_focus (widget))
5634 selection_color = &style->base [GTK_STATE_SELECTED];
5635 text_color = &style->text [GTK_STATE_SELECTED];
5639 selection_color = &style->base [GTK_STATE_ACTIVE];
5640 text_color = &style->text [GTK_STATE_ACTIVE];
5643 _gtk_entry_effective_inner_border (entry, &inner_border);
5645 for (i = 0; i < n_ranges; ++i)
5646 cairo_rectangle (cr,
5647 inner_border.left - priv->scroll_offset + ranges[2 * i],
5650 logical_rect.height);
5654 gdk_cairo_set_source_color (cr, selection_color);
5657 cairo_move_to (cr, x, y);
5658 gdk_cairo_set_source_color (cr, text_color);
5659 pango_cairo_show_layout (cr, layout);
5667 gtk_entry_draw_text (GtkEntry *entry,
5670 GtkEntryPrivate *priv = entry->priv;
5671 GtkWidget *widget = GTK_WIDGET (entry);
5674 GdkColor text_color, bar_text_color;
5677 gint progress_x, progress_y, progress_width, progress_height;
5678 gint clip_width, clip_height;
5680 /* Nothing to display at all */
5681 if (gtk_entry_get_display_mode (entry) == DISPLAY_BLANK)
5684 state = GTK_STATE_SELECTED;
5685 if (!gtk_widget_get_sensitive (widget))
5686 state = GTK_STATE_INSENSITIVE;
5687 style = gtk_widget_get_style (widget);
5688 text_color = style->text[gtk_widget_get_state (widget)];
5689 bar_text_color = style->fg[state];
5691 get_progress_area (widget,
5692 &progress_x, &progress_y,
5693 &progress_width, &progress_height);
5695 clip_width = gdk_window_get_width (priv->text_area);
5696 clip_height = gdk_window_get_height (priv->text_area);
5697 cairo_rectangle (cr, 0, 0, clip_width, clip_height);
5700 /* If the color is the same, or the progress area has a zero
5701 * size, then we only need to draw once. */
5702 if ((text_color.pixel == bar_text_color.pixel) ||
5703 ((progress_width == 0) || (progress_height == 0)))
5705 draw_text_with_color (entry, cr, &text_color);
5709 width = gdk_window_get_width (priv->text_area);
5710 height = gdk_window_get_height (priv->text_area);
5714 cairo_rectangle (cr, 0, 0, width, height);
5718 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
5719 cairo_rectangle (cr, 0, 0, width, height);
5721 gdk_window_get_position (priv->text_area, &pos_x, &pos_y);
5722 progress_x -= pos_x;
5723 progress_y -= pos_y;
5725 cairo_rectangle (cr, progress_x, progress_y,
5726 progress_width, progress_height);
5728 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_WINDING);
5730 draw_text_with_color (entry, cr, &text_color);
5733 cairo_rectangle (cr, progress_x, progress_y,
5734 progress_width, progress_height);
5737 draw_text_with_color (entry, cr, &bar_text_color);
5744 draw_insertion_cursor (GtkEntry *entry,
5746 GdkRectangle *cursor_location,
5747 gboolean is_primary,
5748 PangoDirection direction,
5749 gboolean draw_arrow)
5751 GtkWidget *widget = GTK_WIDGET (entry);
5752 GtkTextDirection text_dir;
5754 if (direction == PANGO_DIRECTION_LTR)
5755 text_dir = GTK_TEXT_DIR_LTR;
5757 text_dir = GTK_TEXT_DIR_RTL;
5759 gtk_draw_insertion_cursor (widget, cr,
5761 is_primary, text_dir, draw_arrow);
5765 gtk_entry_draw_cursor (GtkEntry *entry,
5769 GtkEntryPrivate *priv = entry->priv;
5770 GtkWidget *widget = GTK_WIDGET (entry);
5771 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
5772 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
5773 GdkRectangle cursor_location;
5774 gboolean split_cursor;
5775 PangoRectangle cursor_rect;
5776 GtkBorder inner_border;
5778 gint text_area_height;
5781 gboolean block_at_line_end;
5782 PangoLayout *layout;
5785 _gtk_entry_effective_inner_border (entry, &inner_border);
5787 xoffset = inner_border.left - priv->scroll_offset;
5789 text_area_height = gdk_window_get_height (priv->text_area);
5791 layout = gtk_entry_ensure_layout (entry, TRUE);
5792 text = pango_layout_get_text (layout);
5793 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos + priv->preedit_cursor) - text;
5794 if (!priv->overwrite_mode)
5797 block = _gtk_text_util_get_block_cursor_location (layout,
5798 cursor_index, &cursor_rect, &block_at_line_end);
5802 gint strong_x, weak_x;
5803 PangoDirection dir1 = PANGO_DIRECTION_NEUTRAL;
5804 PangoDirection dir2 = PANGO_DIRECTION_NEUTRAL;
5808 gtk_entry_get_cursor_locations (entry, type, &strong_x, &weak_x);
5810 g_object_get (gtk_widget_get_settings (widget),
5811 "gtk-split-cursor", &split_cursor,
5814 dir1 = priv->resolved_dir;
5820 if (weak_x != strong_x)
5822 dir2 = (priv->resolved_dir == PANGO_DIRECTION_LTR) ? PANGO_DIRECTION_RTL : PANGO_DIRECTION_LTR;
5828 if (keymap_direction == priv->resolved_dir)
5834 cursor_location.x = xoffset + x1;
5835 cursor_location.y = inner_border.top;
5836 cursor_location.width = 0;
5837 cursor_location.height = text_area_height - inner_border.top - inner_border.bottom;
5839 draw_insertion_cursor (entry, cr,
5840 &cursor_location, TRUE, dir1,
5841 dir2 != PANGO_DIRECTION_NEUTRAL);
5843 if (dir2 != PANGO_DIRECTION_NEUTRAL)
5845 cursor_location.x = xoffset + x2;
5846 draw_insertion_cursor (entry, cr,
5847 &cursor_location, FALSE, dir2,
5851 else /* overwrite_mode */
5853 GdkColor cursor_color;
5859 get_layout_position (entry, &x, &y);
5861 rect.x = PANGO_PIXELS (cursor_rect.x) + x;
5862 rect.y = PANGO_PIXELS (cursor_rect.y) + y;
5863 rect.width = PANGO_PIXELS (cursor_rect.width);
5864 rect.height = PANGO_PIXELS (cursor_rect.height);
5866 _gtk_widget_get_cursor_color (widget, &cursor_color);
5867 gdk_cairo_set_source_color (cr, &cursor_color);
5868 gdk_cairo_rectangle (cr, &rect);
5871 if (!block_at_line_end)
5873 gdk_cairo_rectangle (cr, &rect);
5875 cairo_move_to (cr, x, y);
5876 gdk_cairo_set_source_color (cr, >k_widget_get_style (widget)->base[gtk_widget_get_state (widget)]);
5877 pango_cairo_show_layout (cr, layout);
5885 gtk_entry_queue_draw (GtkEntry *entry)
5887 if (gtk_widget_is_drawable (GTK_WIDGET (entry)))
5888 gdk_window_invalidate_rect (gtk_widget_get_window (GTK_WIDGET (entry)),
5893 _gtk_entry_reset_im_context (GtkEntry *entry)
5895 GtkEntryPrivate *priv = entry->priv;
5897 if (priv->need_im_reset)
5899 priv->need_im_reset = FALSE;
5900 gtk_im_context_reset (priv->im_context);
5905 * gtk_entry_reset_im_context:
5906 * @entry: a #GtkEntry
5908 * Reset the input method context of the entry if needed.
5910 * This can be necessary in the case where modifying the buffer
5911 * would confuse on-going input method behavior.
5916 gtk_entry_reset_im_context (GtkEntry *entry)
5918 g_return_if_fail (GTK_IS_ENTRY (entry));
5920 _gtk_entry_reset_im_context (entry);
5924 * gtk_entry_im_context_filter_keypress:
5925 * @entry: a #GtkEntry
5926 * @event: the key event
5928 * Allow the #GtkEntry input method to internally handle key press
5929 * and release events. If this function returns %TRUE, then no further
5930 * processing should be done for this key event. See
5931 * gtk_im_context_filter_keypress().
5933 * Note that you are expected to call this function from your handler
5934 * when overriding key event handling. This is needed in the case when
5935 * you need to insert your own key handling between the input method
5936 * and the default key event handling of the #GtkEntry.
5937 * See gtk_text_view_reset_im_context() for an example of use.
5939 * Return value: %TRUE if the input method handled the key event.
5944 gtk_entry_im_context_filter_keypress (GtkEntry *entry,
5947 GtkEntryPrivate *priv;
5949 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
5953 return gtk_im_context_filter_keypress (priv->im_context, event);
5957 _gtk_entry_get_im_context (GtkEntry *entry)
5959 return entry->priv->im_context;
5963 gtk_entry_find_position (GtkEntry *entry,
5966 GtkEntryPrivate *priv = entry->priv;
5967 PangoLayout *layout;
5968 PangoLayoutLine *line;
5975 layout = gtk_entry_ensure_layout (entry, TRUE);
5976 text = pango_layout_get_text (layout);
5977 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos) - text;
5979 line = pango_layout_get_lines_readonly (layout)->data;
5980 pango_layout_line_x_to_index (line, x * PANGO_SCALE, &index, &trailing);
5982 if (index >= cursor_index && priv->preedit_length)
5984 if (index >= cursor_index + priv->preedit_length)
5985 index -= priv->preedit_length;
5988 index = cursor_index;
5993 pos = g_utf8_pointer_to_offset (text, text + index);
6000 gtk_entry_get_cursor_locations (GtkEntry *entry,
6005 GtkEntryPrivate *priv = entry->priv;
6006 DisplayMode mode = gtk_entry_get_display_mode (entry);
6008 /* Nothing to display at all, so no cursor is relevant */
6009 if (mode == DISPLAY_BLANK)
6019 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
6020 const gchar *text = pango_layout_get_text (layout);
6021 PangoRectangle strong_pos, weak_pos;
6024 if (type == CURSOR_STANDARD)
6026 index = g_utf8_offset_to_pointer (text, priv->current_pos + priv->preedit_cursor) - text;
6028 else /* type == CURSOR_DND */
6030 index = g_utf8_offset_to_pointer (text, priv->dnd_position) - text;
6032 if (priv->dnd_position > priv->current_pos)
6034 if (mode == DISPLAY_NORMAL)
6035 index += priv->preedit_length;
6038 gint preedit_len_chars = g_utf8_strlen (text, -1) - gtk_entry_buffer_get_length (get_buffer (entry));
6039 index += preedit_len_chars * g_unichar_to_utf8 (priv->invisible_char, NULL);
6044 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
6047 *strong_x = strong_pos.x / PANGO_SCALE;
6050 *weak_x = weak_pos.x / PANGO_SCALE;
6055 gtk_entry_adjust_scroll (GtkEntry *entry)
6057 GtkEntryPrivate *priv = entry->priv;
6058 gint min_offset, max_offset;
6059 gint text_area_width, text_width;
6060 GtkBorder inner_border;
6061 gint strong_x, weak_x;
6062 gint strong_xoffset, weak_xoffset;
6064 PangoLayout *layout;
6065 PangoLayoutLine *line;
6066 PangoRectangle logical_rect;
6068 if (!gtk_widget_get_realized (GTK_WIDGET (entry)))
6071 _gtk_entry_effective_inner_border (entry, &inner_border);
6073 text_area_width = gdk_window_get_width (priv->text_area);
6074 text_area_width -= inner_border.left + inner_border.right;
6075 if (text_area_width < 0)
6076 text_area_width = 0;
6078 layout = gtk_entry_ensure_layout (entry, TRUE);
6079 line = pango_layout_get_lines_readonly (layout)->data;
6081 pango_layout_line_get_extents (line, NULL, &logical_rect);
6083 /* Display as much text as we can */
6085 if (priv->resolved_dir == PANGO_DIRECTION_LTR)
6086 xalign = priv->xalign;
6088 xalign = 1.0 - priv->xalign;
6090 text_width = PANGO_PIXELS(logical_rect.width);
6092 if (text_width > text_area_width)
6095 max_offset = text_width - text_area_width;
6099 min_offset = (text_width - text_area_width) * xalign;
6100 max_offset = min_offset;
6103 priv->scroll_offset = CLAMP (priv->scroll_offset, min_offset, max_offset);
6105 /* And make sure cursors are on screen. Note that the cursor is
6106 * actually drawn one pixel into the INNER_BORDER space on
6107 * the right, when the scroll is at the utmost right. This
6108 * looks better to to me than confining the cursor inside the
6109 * border entirely, though it means that the cursor gets one
6110 * pixel closer to the edge of the widget on the right than
6111 * on the left. This might need changing if one changed
6112 * INNER_BORDER from 2 to 1, as one would do on a
6113 * small-screen-real-estate display.
6115 * We always make sure that the strong cursor is on screen, and
6116 * put the weak cursor on screen if possible.
6119 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, &weak_x);
6121 strong_xoffset = strong_x - priv->scroll_offset;
6123 if (strong_xoffset < 0)
6125 priv->scroll_offset += strong_xoffset;
6128 else if (strong_xoffset > text_area_width)
6130 priv->scroll_offset += strong_xoffset - text_area_width;
6131 strong_xoffset = text_area_width;
6134 weak_xoffset = weak_x - priv->scroll_offset;
6136 if (weak_xoffset < 0 && strong_xoffset - weak_xoffset <= text_area_width)
6138 priv->scroll_offset += weak_xoffset;
6140 else if (weak_xoffset > text_area_width &&
6141 strong_xoffset - (weak_xoffset - text_area_width) >= 0)
6143 priv->scroll_offset += weak_xoffset - text_area_width;
6146 g_object_notify (G_OBJECT (entry), "scroll-offset");
6150 gtk_entry_move_adjustments (GtkEntry *entry)
6152 GtkWidget *widget = GTK_WIDGET (entry);
6153 GtkAllocation allocation;
6154 GtkAdjustment *adjustment;
6155 PangoContext *context;
6156 PangoFontMetrics *metrics;
6157 gint x, layout_x, border_x, border_y;
6160 adjustment = g_object_get_qdata (G_OBJECT (entry), quark_cursor_hadjustment);
6164 gtk_widget_get_allocation (widget, &allocation);
6166 /* Cursor position, layout offset, border width, and widget allocation */
6167 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &x, NULL);
6168 get_layout_position (entry, &layout_x, NULL);
6169 _gtk_entry_get_borders (entry, &border_x, &border_y);
6170 x += allocation.x + layout_x + border_x;
6172 /* Approximate width of a char, so user can see what is ahead/behind */
6173 context = gtk_widget_get_pango_context (widget);
6174 metrics = pango_context_get_metrics (context,
6175 gtk_widget_get_style (widget)->font_desc,
6176 pango_context_get_language (context));
6177 char_width = pango_font_metrics_get_approximate_char_width (metrics) / PANGO_SCALE;
6180 gtk_adjustment_clamp_page (adjustment,
6181 x - (char_width + 1), /* one char + one pixel before */
6182 x + (char_width + 2)); /* one char + cursor + one pixel after */
6186 gtk_entry_move_visually (GtkEntry *entry,
6190 GtkEntryPrivate *priv = entry->priv;
6192 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6195 text = pango_layout_get_text (layout);
6197 index = g_utf8_offset_to_pointer (text, start) - text;
6201 int new_index, new_trailing;
6202 gboolean split_cursor;
6205 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
6206 "gtk-split-cursor", &split_cursor,
6213 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
6214 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
6216 strong = keymap_direction == priv->resolved_dir;
6221 pango_layout_move_cursor_visually (layout, strong, index, 0, 1, &new_index, &new_trailing);
6226 pango_layout_move_cursor_visually (layout, strong, index, 0, -1, &new_index, &new_trailing);
6232 else if (new_index != G_MAXINT)
6235 while (new_trailing--)
6236 index = g_utf8_next_char (text + index) - text;
6239 return g_utf8_pointer_to_offset (text, text + index);
6243 gtk_entry_move_logically (GtkEntry *entry,
6247 gint new_pos = start;
6250 length = gtk_entry_buffer_get_length (get_buffer (entry));
6252 /* Prevent any leak of information */
6253 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6255 new_pos = CLAMP (start + count, 0, length);
6259 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6260 PangoLogAttr *log_attrs;
6263 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6265 while (count > 0 && new_pos < length)
6269 while (new_pos < length && !log_attrs[new_pos].is_cursor_position);
6273 while (count < 0 && new_pos > 0)
6277 while (new_pos > 0 && !log_attrs[new_pos].is_cursor_position);
6289 gtk_entry_move_forward_word (GtkEntry *entry,
6291 gboolean allow_whitespace)
6293 gint new_pos = start;
6296 length = gtk_entry_buffer_get_length (get_buffer (entry));
6298 /* Prevent any leak of information */
6299 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6303 else if (new_pos < length)
6305 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6306 PangoLogAttr *log_attrs;
6309 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6311 /* Find the next word boundary */
6313 while (new_pos < n_attrs - 1 && !(log_attrs[new_pos].is_word_end ||
6314 (log_attrs[new_pos].is_word_start && allow_whitespace)))
6325 gtk_entry_move_backward_word (GtkEntry *entry,
6327 gboolean allow_whitespace)
6329 gint new_pos = start;
6331 /* Prevent any leak of information */
6332 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6338 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6339 PangoLogAttr *log_attrs;
6342 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6344 new_pos = start - 1;
6346 /* Find the previous word boundary */
6347 while (new_pos > 0 && !(log_attrs[new_pos].is_word_start ||
6348 (log_attrs[new_pos].is_word_end && allow_whitespace)))
6358 gtk_entry_delete_whitespace (GtkEntry *entry)
6360 GtkEntryPrivate *priv = entry->priv;
6361 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6362 PangoLogAttr *log_attrs;
6366 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6368 start = end = priv->current_pos;
6370 while (start > 0 && log_attrs[start-1].is_white)
6373 while (end < n_attrs && log_attrs[end].is_white)
6379 gtk_editable_delete_text (GTK_EDITABLE (entry), start, end);
6384 gtk_entry_select_word (GtkEntry *entry)
6386 GtkEntryPrivate *priv = entry->priv;
6387 gint start_pos = gtk_entry_move_backward_word (entry, priv->current_pos, TRUE);
6388 gint end_pos = gtk_entry_move_forward_word (entry, priv->current_pos, TRUE);
6390 gtk_editable_select_region (GTK_EDITABLE (entry), start_pos, end_pos);
6394 gtk_entry_select_line (GtkEntry *entry)
6396 gtk_editable_select_region (GTK_EDITABLE (entry), 0, -1);
6400 truncate_multiline (const gchar *text)
6405 text[length] && text[length] != '\n' && text[length] != '\r';
6412 paste_received (GtkClipboard *clipboard,
6416 GtkEntry *entry = GTK_ENTRY (data);
6417 GtkEditable *editable = GTK_EDITABLE (entry);
6418 GtkEntryPrivate *priv = entry->priv;
6420 if (priv->button == 2)
6422 gint pos, start, end;
6423 pos = priv->insert_pos;
6424 gtk_editable_get_selection_bounds (editable, &start, &end);
6425 if (!((start <= pos && pos <= end) || (end <= pos && pos <= start)))
6426 gtk_editable_select_region (editable, pos, pos);
6431 gint pos, start, end;
6433 gboolean popup_completion;
6434 GtkEntryCompletion *completion;
6436 completion = gtk_entry_get_completion (entry);
6438 if (priv->truncate_multiline)
6439 length = truncate_multiline (text);
6441 /* only complete if the selection is at the end */
6442 popup_completion = (gtk_entry_buffer_get_length (get_buffer (entry)) ==
6443 MAX (priv->current_pos, priv->selection_bound));
6447 if (gtk_widget_get_mapped (completion->priv->popup_window))
6448 _gtk_entry_completion_popdown (completion);
6450 if (!popup_completion && completion->priv->changed_id > 0)
6451 g_signal_handler_block (entry, completion->priv->changed_id);
6454 begin_change (entry);
6455 g_object_freeze_notify (G_OBJECT (entry));
6456 if (gtk_editable_get_selection_bounds (editable, &start, &end))
6457 gtk_editable_delete_text (editable, start, end);
6459 pos = priv->current_pos;
6460 gtk_editable_insert_text (editable, text, length, &pos);
6461 gtk_editable_set_position (editable, pos);
6462 g_object_thaw_notify (G_OBJECT (entry));
6466 !popup_completion && completion->priv->changed_id > 0)
6467 g_signal_handler_unblock (entry, completion->priv->changed_id);
6470 g_object_unref (entry);
6474 gtk_entry_paste (GtkEntry *entry,
6477 g_object_ref (entry);
6478 gtk_clipboard_request_text (gtk_widget_get_clipboard (GTK_WIDGET (entry), selection),
6479 paste_received, entry);
6483 primary_get_cb (GtkClipboard *clipboard,
6484 GtkSelectionData *selection_data,
6488 GtkEntry *entry = GTK_ENTRY (data);
6491 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end))
6493 gchar *str = gtk_entry_get_display_text (entry, start, end);
6494 gtk_selection_data_set_text (selection_data, str, -1);
6500 primary_clear_cb (GtkClipboard *clipboard,
6503 GtkEntry *entry = GTK_ENTRY (data);
6504 GtkEntryPrivate *priv = entry->priv;
6506 gtk_editable_select_region (GTK_EDITABLE (entry), priv->current_pos, priv->current_pos);
6510 gtk_entry_update_primary_selection (GtkEntry *entry)
6512 GtkTargetList *list;
6513 GtkTargetEntry *targets;
6514 GtkClipboard *clipboard;
6518 if (!gtk_widget_get_realized (GTK_WIDGET (entry)))
6521 list = gtk_target_list_new (NULL, 0);
6522 gtk_target_list_add_text_targets (list, 0);
6524 targets = gtk_target_table_new_from_list (list, &n_targets);
6526 clipboard = gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_PRIMARY);
6528 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end))
6530 if (!gtk_clipboard_set_with_owner (clipboard, targets, n_targets,
6531 primary_get_cb, primary_clear_cb, G_OBJECT (entry)))
6532 primary_clear_cb (clipboard, entry);
6536 if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (entry))
6537 gtk_clipboard_clear (clipboard);
6540 gtk_target_table_free (targets, n_targets);
6541 gtk_target_list_unref (list);
6545 gtk_entry_clear (GtkEntry *entry,
6546 GtkEntryIconPosition icon_pos)
6548 GtkEntryPrivate *priv = entry->priv;
6549 EntryIconInfo *icon_info = priv->icons[icon_pos];
6551 if (!icon_info || icon_info->storage_type == GTK_IMAGE_EMPTY)
6554 g_object_freeze_notify (G_OBJECT (entry));
6556 /* Explicitly check, as the pointer may become invalidated
6557 * during destruction.
6559 if (GDK_IS_WINDOW (icon_info->window))
6560 gdk_window_hide (icon_info->window);
6562 if (icon_info->pixbuf)
6564 g_object_unref (icon_info->pixbuf);
6565 icon_info->pixbuf = NULL;
6568 switch (icon_info->storage_type)
6570 case GTK_IMAGE_PIXBUF:
6571 g_object_notify (G_OBJECT (entry),
6572 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-pixbuf" : "secondary-icon-pixbuf");
6575 case GTK_IMAGE_STOCK:
6576 g_free (icon_info->stock_id);
6577 icon_info->stock_id = NULL;
6578 g_object_notify (G_OBJECT (entry),
6579 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-stock" : "secondary-icon-stock");
6582 case GTK_IMAGE_ICON_NAME:
6583 g_free (icon_info->icon_name);
6584 icon_info->icon_name = NULL;
6585 g_object_notify (G_OBJECT (entry),
6586 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-name" : "secondary-icon-name");
6589 case GTK_IMAGE_GICON:
6590 if (icon_info->gicon)
6592 g_object_unref (icon_info->gicon);
6593 icon_info->gicon = NULL;
6595 g_object_notify (G_OBJECT (entry),
6596 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-gicon" : "secondary-icon-gicon");
6600 g_assert_not_reached ();
6604 icon_info->storage_type = GTK_IMAGE_EMPTY;
6605 g_object_notify (G_OBJECT (entry),
6606 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-storage-type" : "secondary-icon-storage-type");
6608 g_object_thaw_notify (G_OBJECT (entry));
6612 gtk_entry_ensure_pixbuf (GtkEntry *entry,
6613 GtkEntryIconPosition icon_pos)
6615 GtkEntryPrivate *priv = entry->priv;
6616 EntryIconInfo *icon_info = priv->icons[icon_pos];
6618 GtkIconTheme *icon_theme;
6619 GtkSettings *settings;
6625 if (!icon_info || icon_info->pixbuf)
6628 widget = GTK_WIDGET (entry);
6630 switch (icon_info->storage_type)
6632 case GTK_IMAGE_EMPTY:
6633 case GTK_IMAGE_PIXBUF:
6635 case GTK_IMAGE_STOCK:
6636 state = gtk_widget_get_state (widget);
6637 gtk_widget_set_state (widget, GTK_STATE_NORMAL);
6638 icon_info->pixbuf = gtk_widget_render_icon (widget,
6639 icon_info->stock_id,
6642 if (!icon_info->pixbuf)
6643 icon_info->pixbuf = gtk_widget_render_icon (widget,
6644 GTK_STOCK_MISSING_IMAGE,
6647 gtk_widget_set_state (widget, state);
6650 case GTK_IMAGE_ICON_NAME:
6651 screen = gtk_widget_get_screen (widget);
6654 icon_theme = gtk_icon_theme_get_for_screen (screen);
6655 settings = gtk_settings_get_for_screen (screen);
6657 gtk_icon_size_lookup_for_settings (settings,
6661 icon_info->pixbuf = gtk_icon_theme_load_icon (icon_theme,
6662 icon_info->icon_name,
6663 MIN (width, height),
6666 if (icon_info->pixbuf == NULL)
6668 state = gtk_widget_get_state (widget);
6669 gtk_widget_set_state (widget, GTK_STATE_NORMAL);
6670 icon_info->pixbuf = gtk_widget_render_icon (widget,
6671 GTK_STOCK_MISSING_IMAGE,
6674 gtk_widget_set_state (widget, state);
6679 case GTK_IMAGE_GICON:
6680 screen = gtk_widget_get_screen (widget);
6683 icon_theme = gtk_icon_theme_get_for_screen (screen);
6684 settings = gtk_settings_get_for_screen (screen);
6686 gtk_icon_size_lookup_for_settings (settings,
6690 info = gtk_icon_theme_lookup_by_gicon (icon_theme,
6692 MIN (width, height),
6693 GTK_ICON_LOOKUP_USE_BUILTIN);
6696 icon_info->pixbuf = gtk_icon_info_load_icon (info, NULL);
6697 gtk_icon_info_free (info);
6700 if (icon_info->pixbuf == NULL)
6702 state = gtk_widget_get_state (widget);
6703 gtk_widget_set_state (widget, GTK_STATE_NORMAL);
6704 icon_info->pixbuf = gtk_widget_render_icon (widget,
6705 GTK_STOCK_MISSING_IMAGE,
6708 gtk_widget_set_state (widget, state);
6714 g_assert_not_reached ();
6718 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
6719 gdk_window_show_unraised (icon_info->window);
6729 * Creates a new entry.
6731 * Return value: a new #GtkEntry.
6734 gtk_entry_new (void)
6736 return g_object_new (GTK_TYPE_ENTRY, NULL);
6740 * gtk_entry_new_with_buffer:
6741 * @buffer: The buffer to use for the new #GtkEntry.
6743 * Creates a new entry with the specified text buffer.
6745 * Return value: a new #GtkEntry
6750 gtk_entry_new_with_buffer (GtkEntryBuffer *buffer)
6752 g_return_val_if_fail (GTK_IS_ENTRY_BUFFER (buffer), NULL);
6753 return g_object_new (GTK_TYPE_ENTRY, "buffer", buffer, NULL);
6756 static GtkEntryBuffer*
6757 get_buffer (GtkEntry *entry)
6759 GtkEntryPrivate *priv = entry->priv;
6761 if (priv->buffer == NULL)
6763 GtkEntryBuffer *buffer;
6764 buffer = gtk_entry_buffer_new (NULL, 0);
6765 gtk_entry_set_buffer (entry, buffer);
6766 g_object_unref (buffer);
6769 return priv->buffer;
6773 * gtk_entry_get_buffer:
6774 * @entry: a #GtkEntry
6776 * Get the #GtkEntryBuffer object which holds the text for
6781 * Returns: (transfer none): A #GtkEntryBuffer object.
6784 gtk_entry_get_buffer (GtkEntry *entry)
6786 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
6788 return get_buffer (entry);
6792 * gtk_entry_set_buffer:
6793 * @entry: a #GtkEntry
6794 * @buffer: a #GtkEntryBuffer
6796 * Set the #GtkEntryBuffer object which holds the text for
6802 gtk_entry_set_buffer (GtkEntry *entry,
6803 GtkEntryBuffer *buffer)
6805 GtkEntryPrivate *priv;
6808 g_return_if_fail (GTK_IS_ENTRY (entry));
6814 g_return_if_fail (GTK_IS_ENTRY_BUFFER (buffer));
6815 g_object_ref (buffer);
6820 buffer_disconnect_signals (entry);
6821 g_object_unref (priv->buffer);
6824 priv->buffer = buffer;
6827 buffer_connect_signals (entry);
6829 obj = G_OBJECT (entry);
6830 g_object_freeze_notify (obj);
6831 g_object_notify (obj, "buffer");
6832 g_object_notify (obj, "text");
6833 g_object_notify (obj, "text-length");
6834 g_object_notify (obj, "max-length");
6835 g_object_notify (obj, "visibility");
6836 g_object_notify (obj, "invisible-char");
6837 g_object_notify (obj, "invisible-char-set");
6838 g_object_thaw_notify (obj);
6840 gtk_editable_set_position (GTK_EDITABLE (entry), 0);
6841 gtk_entry_recompute (entry);
6845 * gtk_entry_get_text_area:
6846 * @entry: a #GtkEntry
6847 * @text_area: Return location for the text area.
6849 * Gets the area where the entry's text is drawn. This function is
6850 * useful when drawing something to the entry in a draw callback.
6852 * If the entry is not realized, @text_area is filled with zeros.
6854 * See also gtk_entry_get_icon_area().
6859 gtk_entry_get_text_area (GtkEntry *entry,
6860 GdkRectangle *text_area)
6862 GtkEntryPrivate *priv;
6864 g_return_if_fail (GTK_IS_ENTRY (entry));
6865 g_return_if_fail (text_area != NULL);
6869 if (priv->text_area)
6871 GtkAllocation allocation;
6874 gtk_widget_get_allocation (GTK_WIDGET (entry), &allocation);
6875 gdk_window_get_position (priv->text_area, &x, &y);
6877 text_area->x = x - allocation.x;
6878 text_area->y = y - allocation.y;
6879 text_area->width = gdk_window_get_width (priv->text_area);
6880 text_area->height = gdk_window_get_height (priv->text_area);
6886 text_area->width = 0;
6887 text_area->height = 0;
6892 * gtk_entry_set_text:
6893 * @entry: a #GtkEntry
6894 * @text: the new text
6896 * Sets the text in the widget to the given
6897 * value, replacing the current contents.
6899 * See gtk_entry_buffer_set_text().
6902 gtk_entry_set_text (GtkEntry *entry,
6906 GtkEntryCompletion *completion;
6908 g_return_if_fail (GTK_IS_ENTRY (entry));
6909 g_return_if_fail (text != NULL);
6911 /* Actually setting the text will affect the cursor and selection;
6912 * if the contents don't actually change, this will look odd to the user.
6914 if (strcmp (gtk_entry_buffer_get_text (get_buffer (entry)), text) == 0)
6917 completion = gtk_entry_get_completion (entry);
6918 if (completion && completion->priv->changed_id > 0)
6919 g_signal_handler_block (entry, completion->priv->changed_id);
6921 begin_change (entry);
6922 g_object_freeze_notify (G_OBJECT (entry));
6923 gtk_editable_delete_text (GTK_EDITABLE (entry), 0, -1);
6925 gtk_editable_insert_text (GTK_EDITABLE (entry), text, strlen (text), &tmp_pos);
6926 g_object_thaw_notify (G_OBJECT (entry));
6929 if (completion && completion->priv->changed_id > 0)
6930 g_signal_handler_unblock (entry, completion->priv->changed_id);
6934 * gtk_entry_set_visibility:
6935 * @entry: a #GtkEntry
6936 * @visible: %TRUE if the contents of the entry are displayed
6939 * Sets whether the contents of the entry are visible or not.
6940 * When visibility is set to %FALSE, characters are displayed
6941 * as the invisible char, and will also appear that way when
6942 * the text in the entry widget is copied elsewhere.
6944 * By default, GTK+ picks the best invisible character available
6945 * in the current font, but it can be changed with
6946 * gtk_entry_set_invisible_char().
6949 gtk_entry_set_visibility (GtkEntry *entry,
6952 GtkEntryPrivate *priv;
6954 g_return_if_fail (GTK_IS_ENTRY (entry));
6958 visible = visible != FALSE;
6960 if (priv->visible != visible)
6962 priv->visible = visible;
6964 g_object_notify (G_OBJECT (entry), "visibility");
6965 gtk_entry_recompute (entry);
6970 * gtk_entry_get_visibility:
6971 * @entry: a #GtkEntry
6973 * Retrieves whether the text in @entry is visible. See
6974 * gtk_entry_set_visibility().
6976 * Return value: %TRUE if the text is currently visible
6979 gtk_entry_get_visibility (GtkEntry *entry)
6981 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
6983 return entry->priv->visible;
6987 * gtk_entry_set_invisible_char:
6988 * @entry: a #GtkEntry
6989 * @ch: a Unicode character
6991 * Sets the character to use in place of the actual text when
6992 * gtk_entry_set_visibility() has been called to set text visibility
6993 * to %FALSE. i.e. this is the character used in "password mode" to
6994 * show the user how many characters have been typed. By default, GTK+
6995 * picks the best invisible char available in the current font. If you
6996 * set the invisible char to 0, then the user will get no feedback
6997 * at all; there will be no text on the screen as they type.
7000 gtk_entry_set_invisible_char (GtkEntry *entry,
7003 GtkEntryPrivate *priv;
7005 g_return_if_fail (GTK_IS_ENTRY (entry));
7009 if (!priv->invisible_char_set)
7011 priv->invisible_char_set = TRUE;
7012 g_object_notify (G_OBJECT (entry), "invisible-char-set");
7015 if (ch == priv->invisible_char)
7018 priv->invisible_char = ch;
7019 g_object_notify (G_OBJECT (entry), "invisible-char");
7020 gtk_entry_recompute (entry);
7024 * gtk_entry_get_invisible_char:
7025 * @entry: a #GtkEntry
7027 * Retrieves the character displayed in place of the real characters
7028 * for entries with visibility set to false. See gtk_entry_set_invisible_char().
7030 * Return value: the current invisible char, or 0, if the entry does not
7031 * show invisible text at all.
7034 gtk_entry_get_invisible_char (GtkEntry *entry)
7036 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7038 return entry->priv->invisible_char;
7042 * gtk_entry_unset_invisible_char:
7043 * @entry: a #GtkEntry
7045 * Unsets the invisible char previously set with
7046 * gtk_entry_set_invisible_char(). So that the
7047 * default invisible char is used again.
7052 gtk_entry_unset_invisible_char (GtkEntry *entry)
7054 GtkEntryPrivate *priv;
7057 g_return_if_fail (GTK_IS_ENTRY (entry));
7061 if (!priv->invisible_char_set)
7064 priv->invisible_char_set = FALSE;
7065 ch = find_invisible_char (GTK_WIDGET (entry));
7067 if (priv->invisible_char != ch)
7069 priv->invisible_char = ch;
7070 g_object_notify (G_OBJECT (entry), "invisible-char");
7073 g_object_notify (G_OBJECT (entry), "invisible-char-set");
7074 gtk_entry_recompute (entry);
7078 * gtk_entry_set_overwrite_mode:
7079 * @entry: a #GtkEntry
7080 * @overwrite: new value
7082 * Sets whether the text is overwritten when typing in the #GtkEntry.
7087 gtk_entry_set_overwrite_mode (GtkEntry *entry,
7090 GtkEntryPrivate *priv = entry->priv;
7092 g_return_if_fail (GTK_IS_ENTRY (entry));
7094 if (priv->overwrite_mode == overwrite)
7097 gtk_entry_toggle_overwrite (entry);
7099 g_object_notify (G_OBJECT (entry), "overwrite-mode");
7103 * gtk_entry_get_overwrite_mode:
7104 * @entry: a #GtkEntry
7106 * Gets the value set by gtk_entry_set_overwrite_mode().
7108 * Return value: whether the text is overwritten when typing.
7113 gtk_entry_get_overwrite_mode (GtkEntry *entry)
7115 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7117 return entry->priv->overwrite_mode;
7121 * gtk_entry_get_text:
7122 * @entry: a #GtkEntry
7124 * Retrieves the contents of the entry widget.
7125 * See also gtk_editable_get_chars().
7127 * This is equivalent to:
7129 * <informalexample><programlisting>
7130 * gtk_entry_buffer_get_text (gtk_entry_get_buffer (entry));
7131 * </programlisting></informalexample>
7133 * Return value: a pointer to the contents of the widget as a
7134 * string. This string points to internally allocated
7135 * storage in the widget and must not be freed, modified or
7138 G_CONST_RETURN gchar*
7139 gtk_entry_get_text (GtkEntry *entry)
7141 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7143 return gtk_entry_buffer_get_text (get_buffer (entry));
7147 * gtk_entry_set_max_length:
7148 * @entry: a #GtkEntry
7149 * @max: the maximum length of the entry, or 0 for no maximum.
7150 * (other than the maximum length of entries.) The value passed in will
7151 * be clamped to the range 0-65536.
7153 * Sets the maximum allowed length of the contents of the widget. If
7154 * the current contents are longer than the given length, then they
7155 * will be truncated to fit.
7157 * This is equivalent to:
7159 * <informalexample><programlisting>
7160 * gtk_entry_buffer_set_max_length (gtk_entry_get_buffer (entry), max);
7161 * </programlisting></informalexample>
7164 gtk_entry_set_max_length (GtkEntry *entry,
7167 g_return_if_fail (GTK_IS_ENTRY (entry));
7168 gtk_entry_buffer_set_max_length (get_buffer (entry), max);
7172 * gtk_entry_get_max_length:
7173 * @entry: a #GtkEntry
7175 * Retrieves the maximum allowed length of the text in
7176 * @entry. See gtk_entry_set_max_length().
7178 * This is equivalent to:
7180 * <informalexample><programlisting>
7181 * gtk_entry_buffer_get_max_length (gtk_entry_get_buffer (entry));
7182 * </programlisting></informalexample>
7184 * Return value: the maximum allowed number of characters
7185 * in #GtkEntry, or 0 if there is no maximum.
7188 gtk_entry_get_max_length (GtkEntry *entry)
7190 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7192 return gtk_entry_buffer_get_max_length (get_buffer (entry));
7196 * gtk_entry_get_text_length:
7197 * @entry: a #GtkEntry
7199 * Retrieves the current length of the text in
7202 * This is equivalent to:
7204 * <informalexample><programlisting>
7205 * gtk_entry_buffer_get_length (gtk_entry_get_buffer (entry));
7206 * </programlisting></informalexample>
7208 * Return value: the current number of characters
7209 * in #GtkEntry, or 0 if there are none.
7214 gtk_entry_get_text_length (GtkEntry *entry)
7216 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7218 return gtk_entry_buffer_get_length (get_buffer (entry));
7222 * gtk_entry_set_activates_default:
7223 * @entry: a #GtkEntry
7224 * @setting: %TRUE to activate window's default widget on Enter keypress
7226 * If @setting is %TRUE, pressing Enter in the @entry will activate the default
7227 * widget for the window containing the entry. This usually means that
7228 * the dialog box containing the entry will be closed, since the default
7229 * widget is usually one of the dialog buttons.
7231 * (For experts: if @setting is %TRUE, the entry calls
7232 * gtk_window_activate_default() on the window containing the entry, in
7233 * the default handler for the #GtkWidget::activate signal.)
7236 gtk_entry_set_activates_default (GtkEntry *entry,
7239 GtkEntryPrivate *priv;
7241 g_return_if_fail (GTK_IS_ENTRY (entry));
7245 setting = setting != FALSE;
7247 if (setting != priv->activates_default)
7249 priv->activates_default = setting;
7250 g_object_notify (G_OBJECT (entry), "activates-default");
7255 * gtk_entry_get_activates_default:
7256 * @entry: a #GtkEntry
7258 * Retrieves the value set by gtk_entry_set_activates_default().
7260 * Return value: %TRUE if the entry will activate the default widget
7263 gtk_entry_get_activates_default (GtkEntry *entry)
7265 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7267 return entry->priv->activates_default;
7271 * gtk_entry_set_width_chars:
7272 * @entry: a #GtkEntry
7273 * @n_chars: width in chars
7275 * Changes the size request of the entry to be about the right size
7276 * for @n_chars characters. Note that it changes the size
7277 * <emphasis>request</emphasis>, the size can still be affected by
7278 * how you pack the widget into containers. If @n_chars is -1, the
7279 * size reverts to the default entry size.
7282 gtk_entry_set_width_chars (GtkEntry *entry,
7285 GtkEntryPrivate *priv;
7287 g_return_if_fail (GTK_IS_ENTRY (entry));
7291 if (priv->width_chars != n_chars)
7293 priv->width_chars = n_chars;
7294 g_object_notify (G_OBJECT (entry), "width-chars");
7295 gtk_widget_queue_resize (GTK_WIDGET (entry));
7300 * gtk_entry_get_width_chars:
7301 * @entry: a #GtkEntry
7303 * Gets the value set by gtk_entry_set_width_chars().
7305 * Return value: number of chars to request space for, or negative if unset
7308 gtk_entry_get_width_chars (GtkEntry *entry)
7310 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7312 return entry->priv->width_chars;
7316 * gtk_entry_set_has_frame:
7317 * @entry: a #GtkEntry
7318 * @setting: new value
7320 * Sets whether the entry has a beveled frame around it.
7323 gtk_entry_set_has_frame (GtkEntry *entry,
7326 GtkEntryPrivate *priv;
7328 g_return_if_fail (GTK_IS_ENTRY (entry));
7332 setting = (setting != FALSE);
7334 if (priv->has_frame == setting)
7337 gtk_widget_queue_resize (GTK_WIDGET (entry));
7338 priv->has_frame = setting;
7339 g_object_notify (G_OBJECT (entry), "has-frame");
7343 * gtk_entry_get_has_frame:
7344 * @entry: a #GtkEntry
7346 * Gets the value set by gtk_entry_set_has_frame().
7348 * Return value: whether the entry has a beveled frame
7351 gtk_entry_get_has_frame (GtkEntry *entry)
7353 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7355 return entry->priv->has_frame;
7359 * gtk_entry_set_inner_border:
7360 * @entry: a #GtkEntry
7361 * @border: (allow-none): a #GtkBorder, or %NULL
7363 * Sets %entry's inner-border property to %border, or clears it if %NULL
7364 * is passed. The inner-border is the area around the entry's text, but
7367 * If set, this property overrides the inner-border style property.
7368 * Overriding the style-provided border is useful when you want to do
7369 * in-place editing of some text in a canvas or list widget, where
7370 * pixel-exact positioning of the entry is important.
7375 gtk_entry_set_inner_border (GtkEntry *entry,
7376 const GtkBorder *border)
7378 g_return_if_fail (GTK_IS_ENTRY (entry));
7380 gtk_widget_queue_resize (GTK_WIDGET (entry));
7383 g_object_set_qdata_full (G_OBJECT (entry), quark_inner_border,
7384 gtk_border_copy (border),
7385 (GDestroyNotify) gtk_border_free);
7387 g_object_set_qdata (G_OBJECT (entry), quark_inner_border, NULL);
7389 g_object_notify (G_OBJECT (entry), "inner-border");
7393 * gtk_entry_get_inner_border:
7394 * @entry: a #GtkEntry
7396 * This function returns the entry's #GtkEntry:inner-border property. See
7397 * gtk_entry_set_inner_border() for more information.
7399 * Return value: (transfer none): the entry's #GtkBorder, or %NULL if none was set.
7403 G_CONST_RETURN GtkBorder *
7404 gtk_entry_get_inner_border (GtkEntry *entry)
7406 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7408 return g_object_get_qdata (G_OBJECT (entry), quark_inner_border);
7412 * gtk_entry_get_layout:
7413 * @entry: a #GtkEntry
7415 * Gets the #PangoLayout used to display the entry.
7416 * The layout is useful to e.g. convert text positions to
7417 * pixel positions, in combination with gtk_entry_get_layout_offsets().
7418 * The returned layout is owned by the entry and must not be
7419 * modified or freed by the caller.
7421 * Keep in mind that the layout text may contain a preedit string, so
7422 * gtk_entry_layout_index_to_text_index() and
7423 * gtk_entry_text_index_to_layout_index() are needed to convert byte
7424 * indices in the layout to byte indices in the entry contents.
7426 * Return value: (transfer none): the #PangoLayout for this entry
7429 gtk_entry_get_layout (GtkEntry *entry)
7431 PangoLayout *layout;
7433 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7435 layout = gtk_entry_ensure_layout (entry, TRUE);
7442 * gtk_entry_layout_index_to_text_index:
7443 * @entry: a #GtkEntry
7444 * @layout_index: byte index into the entry layout text
7446 * Converts from a position in the entry contents (returned
7447 * by gtk_entry_get_text()) to a position in the
7448 * entry's #PangoLayout (returned by gtk_entry_get_layout(),
7449 * with text retrieved via pango_layout_get_text()).
7451 * Return value: byte index into the entry contents
7454 gtk_entry_layout_index_to_text_index (GtkEntry *entry,
7457 GtkEntryPrivate *priv;
7458 PangoLayout *layout;
7462 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7466 layout = gtk_entry_ensure_layout (entry, TRUE);
7467 text = pango_layout_get_text (layout);
7468 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos) - text;
7470 if (layout_index >= cursor_index && priv->preedit_length)
7472 if (layout_index >= cursor_index + priv->preedit_length)
7473 layout_index -= priv->preedit_length;
7475 layout_index = cursor_index;
7478 return layout_index;
7482 * gtk_entry_text_index_to_layout_index:
7483 * @entry: a #GtkEntry
7484 * @text_index: byte index into the entry contents
7486 * Converts from a position in the entry's #PangoLayout (returned by
7487 * gtk_entry_get_layout()) to a position in the entry contents
7488 * (returned by gtk_entry_get_text()).
7490 * Return value: byte index into the entry layout text
7493 gtk_entry_text_index_to_layout_index (GtkEntry *entry,
7496 GtkEntryPrivate *priv;
7497 PangoLayout *layout;
7501 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7505 layout = gtk_entry_ensure_layout (entry, TRUE);
7506 text = pango_layout_get_text (layout);
7507 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos) - text;
7509 if (text_index > cursor_index)
7510 text_index += priv->preedit_length;
7516 * gtk_entry_get_layout_offsets:
7517 * @entry: a #GtkEntry
7518 * @x: (allow-none): location to store X offset of layout, or %NULL
7519 * @y: (allow-none): location to store Y offset of layout, or %NULL
7522 * Obtains the position of the #PangoLayout used to render text
7523 * in the entry, in widget coordinates. Useful if you want to line
7524 * up the text in an entry with some other text, e.g. when using the
7525 * entry to implement editable cells in a sheet widget.
7527 * Also useful to convert mouse events into coordinates inside the
7528 * #PangoLayout, e.g. to take some action if some part of the entry text
7531 * Note that as the user scrolls around in the entry the offsets will
7532 * change; you'll need to connect to the "notify::scroll-offset"
7533 * signal to track this. Remember when using the #PangoLayout
7534 * functions you need to convert to and from pixels using
7535 * PANGO_PIXELS() or #PANGO_SCALE.
7537 * Keep in mind that the layout text may contain a preedit string, so
7538 * gtk_entry_layout_index_to_text_index() and
7539 * gtk_entry_text_index_to_layout_index() are needed to convert byte
7540 * indices in the layout to byte indices in the entry contents.
7543 gtk_entry_get_layout_offsets (GtkEntry *entry,
7547 gint text_area_x, text_area_y;
7549 g_return_if_fail (GTK_IS_ENTRY (entry));
7551 /* this gets coords relative to text area */
7552 get_layout_position (entry, x, y);
7554 /* convert to widget coords */
7555 gtk_entry_get_text_area_size (entry, &text_area_x, &text_area_y, NULL, NULL);
7566 * gtk_entry_set_alignment:
7567 * @entry: a #GtkEntry
7568 * @xalign: The horizontal alignment, from 0 (left) to 1 (right).
7569 * Reversed for RTL layouts
7571 * Sets the alignment for the contents of the entry. This controls
7572 * the horizontal positioning of the contents when the displayed
7573 * text is shorter than the width of the entry.
7578 gtk_entry_set_alignment (GtkEntry *entry, gfloat xalign)
7580 GtkEntryPrivate *priv;
7582 g_return_if_fail (GTK_IS_ENTRY (entry));
7588 else if (xalign > 1.0)
7591 if (xalign != priv->xalign)
7593 priv->xalign = xalign;
7595 gtk_entry_recompute (entry);
7597 g_object_notify (G_OBJECT (entry), "xalign");
7602 * gtk_entry_get_alignment:
7603 * @entry: a #GtkEntry
7605 * Gets the value set by gtk_entry_set_alignment().
7607 * Return value: the alignment
7612 gtk_entry_get_alignment (GtkEntry *entry)
7614 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
7616 return entry->priv->xalign;
7620 * gtk_entry_set_icon_from_pixbuf:
7621 * @entry: a #GtkEntry
7622 * @icon_pos: Icon position
7623 * @pixbuf: (allow-none): A #GdkPixbuf, or %NULL
7625 * Sets the icon shown in the specified position using a pixbuf.
7627 * If @pixbuf is %NULL, no icon will be shown in the specified position.
7632 gtk_entry_set_icon_from_pixbuf (GtkEntry *entry,
7633 GtkEntryIconPosition icon_pos,
7636 GtkEntryPrivate *priv;
7637 EntryIconInfo *icon_info;
7639 g_return_if_fail (GTK_IS_ENTRY (entry));
7640 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7644 if ((icon_info = priv->icons[icon_pos]) == NULL)
7645 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7647 g_object_freeze_notify (G_OBJECT (entry));
7650 g_object_ref (pixbuf);
7652 gtk_entry_clear (entry, icon_pos);
7656 icon_info->storage_type = GTK_IMAGE_PIXBUF;
7657 icon_info->pixbuf = pixbuf;
7659 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7661 g_object_notify (G_OBJECT (entry), "primary-icon-pixbuf");
7662 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7666 g_object_notify (G_OBJECT (entry), "secondary-icon-pixbuf");
7667 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7670 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7671 gdk_window_show_unraised (icon_info->window);
7674 gtk_entry_ensure_pixbuf (entry, icon_pos);
7676 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7677 gtk_widget_queue_resize (GTK_WIDGET (entry));
7679 g_object_thaw_notify (G_OBJECT (entry));
7683 * gtk_entry_set_icon_from_stock:
7684 * @entry: A #GtkEntry
7685 * @icon_pos: Icon position
7686 * @stock_id: (allow-none): The name of the stock item, or %NULL
7688 * Sets the icon shown in the entry at the specified position from
7691 * If @stock_id is %NULL, no icon will be shown in the specified position.
7696 gtk_entry_set_icon_from_stock (GtkEntry *entry,
7697 GtkEntryIconPosition icon_pos,
7698 const gchar *stock_id)
7700 GtkEntryPrivate *priv;
7701 EntryIconInfo *icon_info;
7704 g_return_if_fail (GTK_IS_ENTRY (entry));
7705 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7709 if ((icon_info = priv->icons[icon_pos]) == NULL)
7710 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7712 g_object_freeze_notify (G_OBJECT (entry));
7714 gtk_widget_ensure_style (GTK_WIDGET (entry));
7716 /* need to dup before clearing */
7717 new_id = g_strdup (stock_id);
7719 gtk_entry_clear (entry, icon_pos);
7723 icon_info->storage_type = GTK_IMAGE_STOCK;
7724 icon_info->stock_id = new_id;
7726 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7728 g_object_notify (G_OBJECT (entry), "primary-icon-stock");
7729 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7733 g_object_notify (G_OBJECT (entry), "secondary-icon-stock");
7734 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7737 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7738 gdk_window_show_unraised (icon_info->window);
7741 gtk_entry_ensure_pixbuf (entry, icon_pos);
7743 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7744 gtk_widget_queue_resize (GTK_WIDGET (entry));
7746 g_object_thaw_notify (G_OBJECT (entry));
7750 * gtk_entry_set_icon_from_icon_name:
7751 * @entry: A #GtkEntry
7752 * @icon_pos: The position at which to set the icon
7753 * @icon_name: (allow-none): An icon name, or %NULL
7755 * Sets the icon shown in the entry at the specified position
7756 * from the current icon theme.
7758 * If the icon name isn't known, a "broken image" icon will be displayed
7761 * If @icon_name is %NULL, no icon will be shown in the specified position.
7766 gtk_entry_set_icon_from_icon_name (GtkEntry *entry,
7767 GtkEntryIconPosition icon_pos,
7768 const gchar *icon_name)
7770 GtkEntryPrivate *priv;
7771 EntryIconInfo *icon_info;
7774 g_return_if_fail (GTK_IS_ENTRY (entry));
7775 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7779 if ((icon_info = priv->icons[icon_pos]) == NULL)
7780 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7782 g_object_freeze_notify (G_OBJECT (entry));
7784 gtk_widget_ensure_style (GTK_WIDGET (entry));
7786 /* need to dup before clearing */
7787 new_name = g_strdup (icon_name);
7789 gtk_entry_clear (entry, icon_pos);
7791 if (new_name != NULL)
7793 icon_info->storage_type = GTK_IMAGE_ICON_NAME;
7794 icon_info->icon_name = new_name;
7796 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7798 g_object_notify (G_OBJECT (entry), "primary-icon-name");
7799 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7803 g_object_notify (G_OBJECT (entry), "secondary-icon-name");
7804 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7807 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7808 gdk_window_show_unraised (icon_info->window);
7811 gtk_entry_ensure_pixbuf (entry, icon_pos);
7813 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7814 gtk_widget_queue_resize (GTK_WIDGET (entry));
7816 g_object_thaw_notify (G_OBJECT (entry));
7820 * gtk_entry_set_icon_from_gicon:
7821 * @entry: A #GtkEntry
7822 * @icon_pos: The position at which to set the icon
7823 * @icon: (allow-none): The icon to set, or %NULL
7825 * Sets the icon shown in the entry at the specified position
7826 * from the current icon theme.
7827 * If the icon isn't known, a "broken image" icon will be displayed
7830 * If @icon is %NULL, no icon will be shown in the specified position.
7835 gtk_entry_set_icon_from_gicon (GtkEntry *entry,
7836 GtkEntryIconPosition icon_pos,
7839 GtkEntryPrivate *priv;
7840 EntryIconInfo *icon_info;
7842 g_return_if_fail (GTK_IS_ENTRY (entry));
7843 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7847 if ((icon_info = priv->icons[icon_pos]) == NULL)
7848 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7850 g_object_freeze_notify (G_OBJECT (entry));
7852 /* need to ref before clearing */
7854 g_object_ref (icon);
7856 gtk_entry_clear (entry, icon_pos);
7860 icon_info->storage_type = GTK_IMAGE_GICON;
7861 icon_info->gicon = icon;
7863 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7865 g_object_notify (G_OBJECT (entry), "primary-icon-gicon");
7866 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7870 g_object_notify (G_OBJECT (entry), "secondary-icon-gicon");
7871 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7874 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7875 gdk_window_show_unraised (icon_info->window);
7878 gtk_entry_ensure_pixbuf (entry, icon_pos);
7880 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7881 gtk_widget_queue_resize (GTK_WIDGET (entry));
7883 g_object_thaw_notify (G_OBJECT (entry));
7887 * gtk_entry_set_icon_activatable:
7888 * @entry: A #GtkEntry
7889 * @icon_pos: Icon position
7890 * @activatable: %TRUE if the icon should be activatable
7892 * Sets whether the icon is activatable.
7897 gtk_entry_set_icon_activatable (GtkEntry *entry,
7898 GtkEntryIconPosition icon_pos,
7899 gboolean activatable)
7901 GtkEntryPrivate *priv;
7902 EntryIconInfo *icon_info;
7904 g_return_if_fail (GTK_IS_ENTRY (entry));
7905 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7909 if ((icon_info = priv->icons[icon_pos]) == NULL)
7910 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7912 activatable = activatable != FALSE;
7914 if (icon_info->nonactivatable != !activatable)
7916 icon_info->nonactivatable = !activatable;
7918 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
7919 update_cursors (GTK_WIDGET (entry));
7921 g_object_notify (G_OBJECT (entry),
7922 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-activatable" : "secondary-icon-activatable");
7927 * gtk_entry_get_icon_activatable:
7928 * @entry: a #GtkEntry
7929 * @icon_pos: Icon position
7931 * Returns whether the icon is activatable.
7933 * Returns: %TRUE if the icon is activatable.
7938 gtk_entry_get_icon_activatable (GtkEntry *entry,
7939 GtkEntryIconPosition icon_pos)
7941 GtkEntryPrivate *priv;
7942 EntryIconInfo *icon_info;
7944 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7945 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), FALSE);
7948 icon_info = priv->icons[icon_pos];
7950 return (icon_info != NULL && !icon_info->nonactivatable);
7954 * gtk_entry_get_icon_pixbuf:
7955 * @entry: A #GtkEntry
7956 * @icon_pos: Icon position
7958 * Retrieves the image used for the icon.
7960 * Unlike the other methods of setting and getting icon data, this
7961 * method will work regardless of whether the icon was set using a
7962 * #GdkPixbuf, a #GIcon, a stock item, or an icon name.
7964 * Returns: (transfer none): A #GdkPixbuf, or %NULL if no icon is
7965 * set for this position.
7970 gtk_entry_get_icon_pixbuf (GtkEntry *entry,
7971 GtkEntryIconPosition icon_pos)
7973 GtkEntryPrivate *priv;
7974 EntryIconInfo *icon_info;
7976 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7977 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7981 icon_info = priv->icons[icon_pos];
7986 gtk_entry_ensure_pixbuf (entry, icon_pos);
7988 return icon_info->pixbuf;
7992 * gtk_entry_get_icon_gicon:
7993 * @entry: A #GtkEntry
7994 * @icon_pos: Icon position
7996 * Retrieves the #GIcon used for the icon, or %NULL if there is
7997 * no icon or if the icon was set by some other method (e.g., by
7998 * stock, pixbuf, or icon name).
8000 * Returns: (transfer none): A #GIcon, or %NULL if no icon is set
8001 * or if the icon is not a #GIcon
8006 gtk_entry_get_icon_gicon (GtkEntry *entry,
8007 GtkEntryIconPosition icon_pos)
8009 GtkEntryPrivate *priv;
8010 EntryIconInfo *icon_info;
8012 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8013 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8016 icon_info = priv->icons[icon_pos];
8021 return icon_info->storage_type == GTK_IMAGE_GICON ? icon_info->gicon : NULL;
8025 * gtk_entry_get_icon_stock:
8026 * @entry: A #GtkEntry
8027 * @icon_pos: Icon position
8029 * Retrieves the stock id used for the icon, or %NULL if there is
8030 * no icon or if the icon was set by some other method (e.g., by
8031 * pixbuf, icon name or gicon).
8033 * Returns: A stock id, or %NULL if no icon is set or if the icon
8034 * wasn't set from a stock id
8039 gtk_entry_get_icon_stock (GtkEntry *entry,
8040 GtkEntryIconPosition icon_pos)
8042 GtkEntryPrivate *priv;
8043 EntryIconInfo *icon_info;
8045 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8046 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8049 icon_info = priv->icons[icon_pos];
8054 return icon_info->storage_type == GTK_IMAGE_STOCK ? icon_info->stock_id : NULL;
8058 * gtk_entry_get_icon_name:
8059 * @entry: A #GtkEntry
8060 * @icon_pos: Icon position
8062 * Retrieves the icon name used for the icon, or %NULL if there is
8063 * no icon or if the icon was set by some other method (e.g., by
8064 * pixbuf, stock or gicon).
8066 * Returns: An icon name, or %NULL if no icon is set or if the icon
8067 * wasn't set from an icon name
8072 gtk_entry_get_icon_name (GtkEntry *entry,
8073 GtkEntryIconPosition icon_pos)
8075 GtkEntryPrivate *priv;
8076 EntryIconInfo *icon_info;
8078 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8079 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8082 icon_info = priv->icons[icon_pos];
8087 return icon_info->storage_type == GTK_IMAGE_ICON_NAME ? icon_info->icon_name : NULL;
8091 * gtk_entry_set_icon_sensitive:
8092 * @entry: A #GtkEntry
8093 * @icon_pos: Icon position
8094 * @sensitive: Specifies whether the icon should appear
8095 * sensitive or insensitive
8097 * Sets the sensitivity for the specified icon.
8102 gtk_entry_set_icon_sensitive (GtkEntry *entry,
8103 GtkEntryIconPosition icon_pos,
8106 GtkEntryPrivate *priv;
8107 EntryIconInfo *icon_info;
8109 g_return_if_fail (GTK_IS_ENTRY (entry));
8110 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8114 if ((icon_info = priv->icons[icon_pos]) == NULL)
8115 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8117 if (icon_info->insensitive != !sensitive)
8119 icon_info->insensitive = !sensitive;
8121 icon_info->pressed = FALSE;
8122 icon_info->prelight = FALSE;
8124 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
8125 update_cursors (GTK_WIDGET (entry));
8127 gtk_widget_queue_draw (GTK_WIDGET (entry));
8129 g_object_notify (G_OBJECT (entry),
8130 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-sensitive" : "secondary-icon-sensitive");
8135 * gtk_entry_get_icon_sensitive:
8136 * @entry: a #GtkEntry
8137 * @icon_pos: Icon position
8139 * Returns whether the icon appears sensitive or insensitive.
8141 * Returns: %TRUE if the icon is sensitive.
8146 gtk_entry_get_icon_sensitive (GtkEntry *entry,
8147 GtkEntryIconPosition icon_pos)
8149 GtkEntryPrivate *priv;
8150 EntryIconInfo *icon_info;
8152 g_return_val_if_fail (GTK_IS_ENTRY (entry), TRUE);
8153 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), TRUE);
8157 icon_info = priv->icons[icon_pos];
8159 return (!icon_info || !icon_info->insensitive);
8164 * gtk_entry_get_icon_storage_type:
8165 * @entry: a #GtkEntry
8166 * @icon_pos: Icon position
8168 * Gets the type of representation being used by the icon
8169 * to store image data. If the icon has no image data,
8170 * the return value will be %GTK_IMAGE_EMPTY.
8172 * Return value: image representation being used
8177 gtk_entry_get_icon_storage_type (GtkEntry *entry,
8178 GtkEntryIconPosition icon_pos)
8180 GtkEntryPrivate *priv;
8181 EntryIconInfo *icon_info;
8183 g_return_val_if_fail (GTK_IS_ENTRY (entry), GTK_IMAGE_EMPTY);
8184 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), GTK_IMAGE_EMPTY);
8188 icon_info = priv->icons[icon_pos];
8191 return GTK_IMAGE_EMPTY;
8193 return icon_info->storage_type;
8197 * gtk_entry_get_icon_at_pos:
8198 * @entry: a #GtkEntry
8199 * @x: the x coordinate of the position to find
8200 * @y: the y coordinate of the position to find
8202 * Finds the icon at the given position and return its index.
8203 * If @x, @y doesn't lie inside an icon, -1 is returned.
8204 * This function is intended for use in a #GtkWidget::query-tooltip
8207 * Returns: the index of the icon at the given position, or -1
8212 gtk_entry_get_icon_at_pos (GtkEntry *entry,
8216 GtkAllocation primary;
8217 GtkAllocation secondary;
8218 gint frame_x, frame_y;
8220 g_return_val_if_fail (GTK_IS_ENTRY (entry), -1);
8222 get_frame_size (entry, &frame_x, &frame_y, NULL, NULL);
8226 get_icon_allocations (entry, &primary, &secondary);
8228 if (primary.x <= x && x < primary.x + primary.width &&
8229 primary.y <= y && y < primary.y + primary.height)
8230 return GTK_ENTRY_ICON_PRIMARY;
8232 if (secondary.x <= x && x < secondary.x + secondary.width &&
8233 secondary.y <= y && y < secondary.y + secondary.height)
8234 return GTK_ENTRY_ICON_SECONDARY;
8240 * gtk_entry_set_icon_drag_source:
8241 * @entry: a #GtkIconEntry
8242 * @icon_pos: icon position
8243 * @target_list: the targets (data formats) in which the data can be provided
8244 * @actions: a bitmask of the allowed drag actions
8246 * Sets up the icon at the given position so that GTK+ will start a drag
8247 * operation when the user clicks and drags the icon.
8249 * To handle the drag operation, you need to connect to the usual
8250 * #GtkWidget::drag-data-get (or possibly #GtkWidget::drag-data-delete)
8251 * signal, and use gtk_entry_get_current_icon_drag_source() in
8252 * your signal handler to find out if the drag was started from
8255 * By default, GTK+ uses the icon as the drag icon. You can use the
8256 * #GtkWidget::drag-begin signal to set a different icon. Note that you
8257 * have to use g_signal_connect_after() to ensure that your signal handler
8258 * gets executed after the default handler.
8263 gtk_entry_set_icon_drag_source (GtkEntry *entry,
8264 GtkEntryIconPosition icon_pos,
8265 GtkTargetList *target_list,
8266 GdkDragAction actions)
8268 GtkEntryPrivate *priv;
8269 EntryIconInfo *icon_info;
8271 g_return_if_fail (GTK_IS_ENTRY (entry));
8272 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8276 if ((icon_info = priv->icons[icon_pos]) == NULL)
8277 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8279 if (icon_info->target_list)
8280 gtk_target_list_unref (icon_info->target_list);
8281 icon_info->target_list = target_list;
8282 if (icon_info->target_list)
8283 gtk_target_list_ref (icon_info->target_list);
8285 icon_info->actions = actions;
8289 * gtk_entry_get_current_icon_drag_source:
8290 * @entry: a #GtkIconEntry
8292 * Returns the index of the icon which is the source of the current
8293 * DND operation, or -1.
8295 * This function is meant to be used in a #GtkWidget::drag-data-get
8298 * Returns: index of the icon which is the source of the current
8299 * DND operation, or -1.
8304 gtk_entry_get_current_icon_drag_source (GtkEntry *entry)
8306 GtkEntryPrivate *priv;
8307 EntryIconInfo *icon_info = NULL;
8310 g_return_val_if_fail (GTK_IS_ENTRY (entry), -1);
8314 for (i = 0; i < MAX_ICONS; i++)
8316 if ((icon_info = priv->icons[i]))
8318 if (icon_info->in_drag)
8327 * gtk_entry_get_icon_area:
8328 * @entry: A #GtkEntry
8329 * @icon_pos: Icon position
8330 * @icon_area: Return location for the icon's area
8332 * Gets the area where entry's icon at @icon_pos is drawn.
8333 * This function is useful when drawing something to the
8334 * entry in a draw callback.
8336 * If the entry is not realized or has no icon at the given position,
8337 * @icon_area is filled with zeros.
8339 * See also gtk_entry_get_text_area()
8344 gtk_entry_get_icon_area (GtkEntry *entry,
8345 GtkEntryIconPosition icon_pos,
8346 GdkRectangle *icon_area)
8348 GtkEntryPrivate *priv;
8349 EntryIconInfo *icon_info;
8351 g_return_if_fail (GTK_IS_ENTRY (entry));
8352 g_return_if_fail (icon_area != NULL);
8356 icon_info = priv->icons[icon_pos];
8360 GtkAllocation primary;
8361 GtkAllocation secondary;
8363 get_icon_allocations (entry, &primary, &secondary);
8365 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
8366 *icon_area = primary;
8368 *icon_area = secondary;
8374 icon_area->width = 0;
8375 icon_area->height = 0;
8380 ensure_has_tooltip (GtkEntry *entry)
8382 GtkEntryPrivate *priv;
8383 EntryIconInfo *icon_info;
8385 gboolean has_tooltip = FALSE;
8389 for (i = 0; i < MAX_ICONS; i++)
8391 if ((icon_info = priv->icons[i]) != NULL)
8393 if (icon_info->tooltip != NULL)
8401 gtk_widget_set_has_tooltip (GTK_WIDGET (entry), has_tooltip);
8405 * gtk_entry_get_icon_tooltip_text:
8406 * @entry: a #GtkEntry
8407 * @icon_pos: the icon position
8409 * Gets the contents of the tooltip on the icon at the specified
8410 * position in @entry.
8412 * Returns: the tooltip text, or %NULL. Free the returned string
8413 * with g_free() when done.
8418 gtk_entry_get_icon_tooltip_text (GtkEntry *entry,
8419 GtkEntryIconPosition icon_pos)
8421 GtkEntryPrivate *priv;
8422 EntryIconInfo *icon_info;
8425 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8426 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8430 icon_info = priv->icons[icon_pos];
8435 if (icon_info->tooltip &&
8436 !pango_parse_markup (icon_info->tooltip, -1, 0, NULL, &text, NULL, NULL))
8437 g_assert (NULL == text); /* text should still be NULL in case of markup errors */
8443 * gtk_entry_set_icon_tooltip_text:
8444 * @entry: a #GtkEntry
8445 * @icon_pos: the icon position
8446 * @tooltip: (allow-none): the contents of the tooltip for the icon, or %NULL
8448 * Sets @tooltip as the contents of the tooltip for the icon
8449 * at the specified position.
8451 * Use %NULL for @tooltip to remove an existing tooltip.
8453 * See also gtk_widget_set_tooltip_text() and
8454 * gtk_entry_set_icon_tooltip_markup().
8459 gtk_entry_set_icon_tooltip_text (GtkEntry *entry,
8460 GtkEntryIconPosition icon_pos,
8461 const gchar *tooltip)
8463 GtkEntryPrivate *priv;
8464 EntryIconInfo *icon_info;
8466 g_return_if_fail (GTK_IS_ENTRY (entry));
8467 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8471 if (!(icon_info = priv->icons[icon_pos]))
8472 icon_info = priv->icons[icon_pos];
8474 if (icon_info->tooltip)
8475 g_free (icon_info->tooltip);
8477 /* Treat an empty string as a NULL string,
8478 * because an empty string would be useless for a tooltip:
8480 if (tooltip && tooltip[0] == '\0')
8483 icon_info->tooltip = tooltip ? g_markup_escape_text (tooltip, -1) : NULL;
8485 ensure_has_tooltip (entry);
8489 * gtk_entry_get_icon_tooltip_markup:
8490 * @entry: a #GtkEntry
8491 * @icon_pos: the icon position
8493 * Gets the contents of the tooltip on the icon at the specified
8494 * position in @entry.
8496 * Returns: the tooltip text, or %NULL. Free the returned string
8497 * with g_free() when done.
8502 gtk_entry_get_icon_tooltip_markup (GtkEntry *entry,
8503 GtkEntryIconPosition icon_pos)
8505 GtkEntryPrivate *priv;
8506 EntryIconInfo *icon_info;
8508 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8509 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8513 icon_info = priv->icons[icon_pos];
8518 return g_strdup (icon_info->tooltip);
8522 * gtk_entry_set_icon_tooltip_markup:
8523 * @entry: a #GtkEntry
8524 * @icon_pos: the icon position
8525 * @tooltip: (allow-none): the contents of the tooltip for the icon, or %NULL
8527 * Sets @tooltip as the contents of the tooltip for the icon at
8528 * the specified position. @tooltip is assumed to be marked up with
8529 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
8531 * Use %NULL for @tooltip to remove an existing tooltip.
8533 * See also gtk_widget_set_tooltip_markup() and
8534 * gtk_enty_set_icon_tooltip_text().
8539 gtk_entry_set_icon_tooltip_markup (GtkEntry *entry,
8540 GtkEntryIconPosition icon_pos,
8541 const gchar *tooltip)
8543 GtkEntryPrivate *priv;
8544 EntryIconInfo *icon_info;
8546 g_return_if_fail (GTK_IS_ENTRY (entry));
8547 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8551 if (!(icon_info = priv->icons[icon_pos]))
8552 icon_info = priv->icons[icon_pos];
8554 if (icon_info->tooltip)
8555 g_free (icon_info->tooltip);
8557 /* Treat an empty string as a NULL string,
8558 * because an empty string would be useless for a tooltip:
8560 if (tooltip && tooltip[0] == '\0')
8563 icon_info->tooltip = g_strdup (tooltip);
8565 ensure_has_tooltip (entry);
8569 gtk_entry_query_tooltip (GtkWidget *widget,
8572 gboolean keyboard_tip,
8573 GtkTooltip *tooltip)
8576 GtkEntryPrivate *priv;
8577 EntryIconInfo *icon_info;
8580 entry = GTK_ENTRY (widget);
8585 icon_pos = gtk_entry_get_icon_at_pos (entry, x, y);
8588 if ((icon_info = priv->icons[icon_pos]) != NULL)
8590 if (icon_info->tooltip)
8592 gtk_tooltip_set_markup (tooltip, icon_info->tooltip);
8601 return GTK_WIDGET_CLASS (gtk_entry_parent_class)->query_tooltip (widget,
8608 /* Quick hack of a popup menu
8611 activate_cb (GtkWidget *menuitem,
8614 const gchar *signal = g_object_get_data (G_OBJECT (menuitem), "gtk-signal");
8615 g_signal_emit_by_name (entry, signal);
8620 gtk_entry_mnemonic_activate (GtkWidget *widget,
8621 gboolean group_cycling)
8623 gtk_widget_grab_focus (widget);
8628 append_action_signal (GtkEntry *entry,
8630 const gchar *stock_id,
8631 const gchar *signal,
8634 GtkWidget *menuitem = gtk_image_menu_item_new_from_stock (stock_id, NULL);
8636 g_object_set_data (G_OBJECT (menuitem), I_("gtk-signal"), (char *)signal);
8637 g_signal_connect (menuitem, "activate",
8638 G_CALLBACK (activate_cb), entry);
8640 gtk_widget_set_sensitive (menuitem, sensitive);
8642 gtk_widget_show (menuitem);
8643 gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
8647 popup_menu_detach (GtkWidget *attach_widget,
8650 GtkEntry *entry_attach = GTK_ENTRY (attach_widget);
8651 GtkEntryPrivate *priv_attach = entry_attach->priv;
8653 priv_attach->popup_menu = NULL;
8657 popup_position_func (GtkMenu *menu,
8663 GtkEntry *entry = GTK_ENTRY (user_data);
8664 GtkEntryPrivate *priv = entry->priv;
8665 GtkWidget *widget = GTK_WIDGET (entry);
8667 GtkRequisition menu_req;
8668 GdkRectangle monitor;
8669 GtkBorder inner_border;
8670 gint monitor_num, strong_x, height;
8672 g_return_if_fail (gtk_widget_get_realized (widget));
8674 gdk_window_get_origin (priv->text_area, x, y);
8676 screen = gtk_widget_get_screen (widget);
8677 monitor_num = gdk_screen_get_monitor_at_window (screen, priv->text_area);
8678 if (monitor_num < 0)
8680 gtk_menu_set_monitor (menu, monitor_num);
8682 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
8683 gtk_widget_get_preferred_size (priv->popup_menu,
8685 height = gdk_window_get_height (priv->text_area);
8686 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
8687 _gtk_entry_effective_inner_border (entry, &inner_border);
8689 *x += inner_border.left + strong_x - priv->scroll_offset;
8690 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
8691 *x -= menu_req.width;
8693 if ((*y + height + menu_req.height) <= monitor.y + monitor.height)
8695 else if ((*y - menu_req.height) >= monitor.y)
8696 *y -= menu_req.height;
8697 else if (monitor.y + monitor.height - (*y + height) > *y)
8700 *y -= menu_req.height;
8706 unichar_chosen_func (const char *text,
8709 GtkEntry *entry = GTK_ENTRY (data);
8710 GtkEntryPrivate *priv = entry->priv;
8713 gtk_entry_enter_text (entry, text);
8724 popup_targets_received (GtkClipboard *clipboard,
8725 GtkSelectionData *data,
8728 PopupInfo *info = user_data;
8729 GtkEntry *entry = info->entry;
8730 GtkEntryPrivate *info_entry_priv = entry->priv;
8732 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
8735 gboolean clipboard_contains_text;
8736 GtkWidget *menuitem;
8738 gboolean show_input_method_menu;
8739 gboolean show_unicode_menu;
8741 clipboard_contains_text = gtk_selection_data_targets_include_text (data);
8742 if (info_entry_priv->popup_menu)
8743 gtk_widget_destroy (info_entry_priv->popup_menu);
8745 info_entry_priv->popup_menu = gtk_menu_new ();
8747 gtk_menu_attach_to_widget (GTK_MENU (info_entry_priv->popup_menu),
8751 mode = gtk_entry_get_display_mode (entry);
8752 append_action_signal (entry, info_entry_priv->popup_menu, GTK_STOCK_CUT, "cut-clipboard",
8753 info_entry_priv->editable && mode == DISPLAY_NORMAL &&
8754 info_entry_priv->current_pos != info_entry_priv->selection_bound);
8756 append_action_signal (entry, info_entry_priv->popup_menu, GTK_STOCK_COPY, "copy-clipboard",
8757 mode == DISPLAY_NORMAL &&
8758 info_entry_priv->current_pos != info_entry_priv->selection_bound);
8760 append_action_signal (entry, info_entry_priv->popup_menu, GTK_STOCK_PASTE, "paste-clipboard",
8761 info_entry_priv->editable && clipboard_contains_text);
8763 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_DELETE, NULL);
8764 gtk_widget_set_sensitive (menuitem, info_entry_priv->editable && info_entry_priv->current_pos != info_entry_priv->selection_bound);
8765 g_signal_connect_swapped (menuitem, "activate",
8766 G_CALLBACK (gtk_entry_delete_cb), entry);
8767 gtk_widget_show (menuitem);
8768 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8770 menuitem = gtk_separator_menu_item_new ();
8771 gtk_widget_show (menuitem);
8772 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8774 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_SELECT_ALL, NULL);
8775 g_signal_connect_swapped (menuitem, "activate",
8776 G_CALLBACK (gtk_entry_select_all), entry);
8777 gtk_widget_show (menuitem);
8778 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8780 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
8781 "gtk-show-input-method-menu", &show_input_method_menu,
8782 "gtk-show-unicode-menu", &show_unicode_menu,
8785 if (show_input_method_menu || show_unicode_menu)
8787 menuitem = gtk_separator_menu_item_new ();
8788 gtk_widget_show (menuitem);
8789 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8792 if (show_input_method_menu)
8794 menuitem = gtk_menu_item_new_with_mnemonic (_("Input _Methods"));
8795 gtk_widget_set_sensitive (menuitem, info_entry_priv->editable);
8796 gtk_widget_show (menuitem);
8797 submenu = gtk_menu_new ();
8798 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
8800 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8802 gtk_im_multicontext_append_menuitems (GTK_IM_MULTICONTEXT (info_entry_priv->im_context),
8803 GTK_MENU_SHELL (submenu));
8806 if (show_unicode_menu)
8808 menuitem = gtk_menu_item_new_with_mnemonic (_("_Insert Unicode Control Character"));
8809 gtk_widget_set_sensitive (menuitem, info_entry_priv->editable);
8810 gtk_widget_show (menuitem);
8812 submenu = gtk_menu_new ();
8813 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
8814 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8816 _gtk_text_util_append_special_char_menuitems (GTK_MENU_SHELL (submenu),
8817 unichar_chosen_func,
8821 g_signal_emit (entry,
8822 signals[POPULATE_POPUP],
8824 info_entry_priv->popup_menu);
8828 gtk_menu_popup (GTK_MENU (info_entry_priv->popup_menu), NULL, NULL,
8830 info->button, info->time);
8833 gtk_menu_popup (GTK_MENU (info_entry_priv->popup_menu), NULL, NULL,
8834 popup_position_func, entry,
8835 info->button, info->time);
8836 gtk_menu_shell_select_first (GTK_MENU_SHELL (info_entry_priv->popup_menu), FALSE);
8840 g_object_unref (entry);
8841 g_slice_free (PopupInfo, info);
8845 gtk_entry_do_popup (GtkEntry *entry,
8846 GdkEventButton *event)
8848 PopupInfo *info = g_slice_new (PopupInfo);
8850 /* In order to know what entries we should make sensitive, we
8851 * ask for the current targets of the clipboard, and when
8852 * we get them, then we actually pop up the menu.
8854 info->entry = g_object_ref (entry);
8858 info->button = event->button;
8859 info->time = event->time;
8864 info->time = gtk_get_current_event_time ();
8867 gtk_clipboard_request_contents (gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_CLIPBOARD),
8868 gdk_atom_intern_static_string ("TARGETS"),
8869 popup_targets_received,
8874 gtk_entry_popup_menu (GtkWidget *widget)
8876 gtk_entry_do_popup (GTK_ENTRY (widget), NULL);
8881 gtk_entry_drag_begin (GtkWidget *widget,
8882 GdkDragContext *context)
8884 GtkEntry *entry = GTK_ENTRY (widget);
8885 GtkEntryPrivate *priv = entry->priv;
8888 for (i = 0; i < MAX_ICONS; i++)
8890 EntryIconInfo *icon_info = priv->icons[i];
8892 if (icon_info != NULL)
8894 if (icon_info->in_drag)
8896 switch (icon_info->storage_type)
8898 case GTK_IMAGE_STOCK:
8899 gtk_drag_set_icon_stock (context, icon_info->stock_id, -2, -2);
8902 case GTK_IMAGE_ICON_NAME:
8903 gtk_drag_set_icon_name (context, icon_info->icon_name, -2, -2);
8906 /* FIXME: No GIcon support for dnd icons */
8907 case GTK_IMAGE_GICON:
8908 case GTK_IMAGE_PIXBUF:
8909 gtk_drag_set_icon_pixbuf (context, icon_info->pixbuf, -2, -2);
8912 g_assert_not_reached ();
8920 gtk_entry_drag_end (GtkWidget *widget,
8921 GdkDragContext *context)
8923 GtkEntry *entry = GTK_ENTRY (widget);
8924 GtkEntryPrivate *priv = entry->priv;
8927 for (i = 0; i < MAX_ICONS; i++)
8929 EntryIconInfo *icon_info = priv->icons[i];
8931 if (icon_info != NULL)
8932 icon_info->in_drag = 0;
8937 gtk_entry_drag_leave (GtkWidget *widget,
8938 GdkDragContext *context,
8941 GtkEntry *entry = GTK_ENTRY (widget);
8942 GtkEntryPrivate *priv = entry->priv;
8944 priv->dnd_position = -1;
8945 gtk_widget_queue_draw (widget);
8949 gtk_entry_drag_drop (GtkWidget *widget,
8950 GdkDragContext *context,
8955 GtkEntry *entry = GTK_ENTRY (widget);
8956 GtkEntryPrivate *priv = entry->priv;
8957 GdkAtom target = GDK_NONE;
8960 target = gtk_drag_dest_find_target (widget, context, NULL);
8962 if (target != GDK_NONE)
8963 gtk_drag_get_data (widget, context, target, time);
8965 gtk_drag_finish (context, FALSE, FALSE, time);
8971 gtk_entry_drag_motion (GtkWidget *widget,
8972 GdkDragContext *context,
8977 GtkEntry *entry = GTK_ENTRY (widget);
8978 GtkEntryPrivate *priv = entry->priv;
8980 GtkWidget *source_widget;
8981 GdkDragAction suggested_action;
8982 gint new_position, old_position;
8985 style = gtk_widget_get_style (widget);
8986 x -= style->xthickness;
8987 y -= style->ythickness;
8989 old_position = priv->dnd_position;
8990 new_position = gtk_entry_find_position (entry, x + priv->scroll_offset);
8992 if (priv->editable &&
8993 gtk_drag_dest_find_target (widget, context, NULL) != GDK_NONE)
8995 source_widget = gtk_drag_get_source_widget (context);
8996 suggested_action = context->suggested_action;
8998 if (!gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &sel1, &sel2) ||
8999 new_position < sel1 || new_position > sel2)
9001 if (source_widget == widget)
9003 /* Default to MOVE, unless the user has
9004 * pressed ctrl or alt to affect available actions
9006 if ((context->actions & GDK_ACTION_MOVE) != 0)
9007 suggested_action = GDK_ACTION_MOVE;
9010 priv->dnd_position = new_position;
9014 if (source_widget == widget)
9015 suggested_action = 0; /* Can't drop in selection where drag started */
9017 priv->dnd_position = -1;
9022 /* Entry not editable, or no text */
9023 suggested_action = 0;
9024 priv->dnd_position = -1;
9027 gdk_drag_status (context, suggested_action, time);
9029 if (priv->dnd_position != old_position)
9030 gtk_widget_queue_draw (widget);
9036 gtk_entry_drag_data_received (GtkWidget *widget,
9037 GdkDragContext *context,
9040 GtkSelectionData *selection_data,
9044 GtkEntry *entry = GTK_ENTRY (widget);
9045 GtkEntryPrivate *priv = entry->priv;
9046 GtkEditable *editable = GTK_EDITABLE (widget);
9050 str = (gchar *) gtk_selection_data_get_text (selection_data);
9052 style = gtk_widget_get_style (widget);
9053 x -= style->xthickness;
9054 y -= style->ythickness;
9056 if (str && priv->editable)
9062 if (priv->truncate_multiline)
9063 length = truncate_multiline (str);
9065 new_position = gtk_entry_find_position (entry, x + priv->scroll_offset);
9067 if (!gtk_editable_get_selection_bounds (editable, &sel1, &sel2) ||
9068 new_position < sel1 || new_position > sel2)
9070 gtk_editable_insert_text (editable, str, length, &new_position);
9074 /* Replacing selection */
9075 begin_change (entry);
9076 g_object_freeze_notify (G_OBJECT (entry));
9077 gtk_editable_delete_text (editable, sel1, sel2);
9078 gtk_editable_insert_text (editable, str, length, &sel1);
9079 g_object_thaw_notify (G_OBJECT (entry));
9083 gtk_drag_finish (context, TRUE, context->action == GDK_ACTION_MOVE, time);
9087 /* Drag and drop didn't happen! */
9088 gtk_drag_finish (context, FALSE, FALSE, time);
9095 gtk_entry_drag_data_get (GtkWidget *widget,
9096 GdkDragContext *context,
9097 GtkSelectionData *selection_data,
9101 GtkEntry *entry = GTK_ENTRY (widget);
9102 GtkEntryPrivate *priv = entry->priv;
9103 GtkEditable *editable = GTK_EDITABLE (widget);
9104 gint sel_start, sel_end;
9107 /* If there is an icon drag going on, exit early. */
9108 for (i = 0; i < MAX_ICONS; i++)
9110 EntryIconInfo *icon_info = priv->icons[i];
9112 if (icon_info != NULL)
9114 if (icon_info->in_drag)
9119 if (gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end))
9121 gchar *str = gtk_entry_get_display_text (GTK_ENTRY (widget), sel_start, sel_end);
9123 gtk_selection_data_set_text (selection_data, str, -1);
9131 gtk_entry_drag_data_delete (GtkWidget *widget,
9132 GdkDragContext *context)
9134 GtkEntry *entry = GTK_ENTRY (widget);
9135 GtkEntryPrivate *priv = entry->priv;
9136 GtkEditable *editable = GTK_EDITABLE (widget);
9137 gint sel_start, sel_end;
9140 /* If there is an icon drag going on, exit early. */
9141 for (i = 0; i < MAX_ICONS; i++)
9143 EntryIconInfo *icon_info = priv->icons[i];
9145 if (icon_info != NULL)
9147 if (icon_info->in_drag)
9152 if (priv->editable &&
9153 gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end))
9154 gtk_editable_delete_text (editable, sel_start, sel_end);
9157 /* We display the cursor when
9159 * - the selection is empty, AND
9160 * - the widget has focus
9163 #define CURSOR_ON_MULTIPLIER 2
9164 #define CURSOR_OFF_MULTIPLIER 1
9165 #define CURSOR_PEND_MULTIPLIER 3
9166 #define CURSOR_DIVIDER 3
9169 cursor_blinks (GtkEntry *entry)
9171 GtkEntryPrivate *priv = entry->priv;
9173 if (gtk_widget_has_focus (GTK_WIDGET (entry)) &&
9175 priv->selection_bound == priv->current_pos)
9177 GtkSettings *settings;
9180 settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9181 g_object_get (settings, "gtk-cursor-blink", &blink, NULL);
9190 get_cursor_time (GtkEntry *entry)
9192 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9195 g_object_get (settings, "gtk-cursor-blink-time", &time, NULL);
9201 get_cursor_blink_timeout (GtkEntry *entry)
9203 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9206 g_object_get (settings, "gtk-cursor-blink-timeout", &timeout, NULL);
9212 show_cursor (GtkEntry *entry)
9214 GtkEntryPrivate *priv = entry->priv;
9217 if (!priv->cursor_visible)
9219 priv->cursor_visible = TRUE;
9221 widget = GTK_WIDGET (entry);
9222 if (gtk_widget_has_focus (widget) && priv->selection_bound == priv->current_pos)
9223 gtk_widget_queue_draw (widget);
9228 hide_cursor (GtkEntry *entry)
9230 GtkEntryPrivate *priv = entry->priv;
9233 if (priv->cursor_visible)
9235 priv->cursor_visible = FALSE;
9237 widget = GTK_WIDGET (entry);
9238 if (gtk_widget_has_focus (widget) && priv->selection_bound == priv->current_pos)
9239 gtk_widget_queue_draw (widget);
9247 blink_cb (gpointer data)
9250 GtkEntryPrivate *priv;
9253 entry = GTK_ENTRY (data);
9256 if (!gtk_widget_has_focus (GTK_WIDGET (entry)))
9258 g_warning ("GtkEntry - did not receive focus-out-event. If you\n"
9259 "connect a handler to this signal, it must return\n"
9260 "FALSE so the entry gets the event as well");
9262 gtk_entry_check_cursor_blink (entry);
9267 g_assert (priv->selection_bound == priv->current_pos);
9269 blink_timeout = get_cursor_blink_timeout (entry);
9270 if (priv->blink_time > 1000 * blink_timeout &&
9271 blink_timeout < G_MAXINT/1000)
9273 /* we've blinked enough without the user doing anything, stop blinking */
9274 show_cursor (entry);
9275 priv->blink_timeout = 0;
9277 else if (priv->cursor_visible)
9279 hide_cursor (entry);
9280 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_OFF_MULTIPLIER / CURSOR_DIVIDER,
9286 show_cursor (entry);
9287 priv->blink_time += get_cursor_time (entry);
9288 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
9293 /* Remove ourselves */
9298 gtk_entry_check_cursor_blink (GtkEntry *entry)
9300 GtkEntryPrivate *priv = entry->priv;
9302 if (cursor_blinks (entry))
9304 if (!priv->blink_timeout)
9306 show_cursor (entry);
9307 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
9314 if (priv->blink_timeout)
9316 g_source_remove (priv->blink_timeout);
9317 priv->blink_timeout = 0;
9320 priv->cursor_visible = TRUE;
9325 gtk_entry_pend_cursor_blink (GtkEntry *entry)
9327 GtkEntryPrivate *priv = entry->priv;
9329 if (cursor_blinks (entry))
9331 if (priv->blink_timeout != 0)
9332 g_source_remove (priv->blink_timeout);
9334 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_PEND_MULTIPLIER / CURSOR_DIVIDER,
9337 show_cursor (entry);
9342 gtk_entry_reset_blink_time (GtkEntry *entry)
9344 GtkEntryPrivate *priv = entry->priv;
9346 priv->blink_time = 0;
9352 gtk_entry_completion_timeout (gpointer data)
9354 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (data);
9355 GtkEntryPrivate *completion_entry_priv = GTK_ENTRY (completion->priv->entry)->priv;
9357 completion->priv->completion_timeout = 0;
9359 if (completion->priv->filter_model &&
9360 g_utf8_strlen (gtk_entry_get_text (GTK_ENTRY (completion->priv->entry)), -1)
9361 >= completion->priv->minimum_key_length)
9365 GtkTreeSelection *s;
9366 gboolean popup_single;
9368 gtk_entry_completion_complete (completion);
9369 matches = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->filter_model), NULL);
9371 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9373 s = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view));
9375 gtk_tree_selection_unselect_all (s);
9377 actions = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->actions), NULL);
9379 g_object_get (completion, "popup-single-match", &popup_single, NULL);
9380 if ((matches > (popup_single ? 0: 1)) || actions > 0)
9382 if (gtk_widget_get_visible (completion->priv->popup_window))
9383 _gtk_entry_completion_resize_popup (completion);
9385 _gtk_entry_completion_popup (completion, completion_entry_priv->completion_device);
9388 _gtk_entry_completion_popdown (completion);
9390 else if (gtk_widget_get_visible (completion->priv->popup_window))
9391 _gtk_entry_completion_popdown (completion);
9396 static inline gboolean
9397 keyval_is_cursor_move (guint keyval)
9399 if (keyval == GDK_KEY_Up || keyval == GDK_KEY_KP_Up)
9402 if (keyval == GDK_KEY_Down || keyval == GDK_KEY_KP_Down)
9405 if (keyval == GDK_KEY_Page_Up)
9408 if (keyval == GDK_KEY_Page_Down)
9415 gtk_entry_completion_key_press (GtkWidget *widget,
9419 gint matches, actions = 0;
9420 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
9422 if (!gtk_widget_get_mapped (completion->priv->popup_window))
9425 matches = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->filter_model), NULL);
9427 if (completion->priv->actions)
9428 actions = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->actions), NULL);
9430 if (keyval_is_cursor_move (event->keyval))
9432 GtkTreePath *path = NULL;
9434 if (event->keyval == GDK_KEY_Up || event->keyval == GDK_KEY_KP_Up)
9436 if (completion->priv->current_selected < 0)
9437 completion->priv->current_selected = matches + actions - 1;
9439 completion->priv->current_selected--;
9441 else if (event->keyval == GDK_KEY_Down || event->keyval == GDK_KEY_KP_Down)
9443 if (completion->priv->current_selected < matches + actions - 1)
9444 completion->priv->current_selected++;
9446 completion->priv->current_selected = -1;
9448 else if (event->keyval == GDK_KEY_Page_Up)
9450 if (completion->priv->current_selected < 0)
9451 completion->priv->current_selected = matches + actions - 1;
9452 else if (completion->priv->current_selected == 0)
9453 completion->priv->current_selected = -1;
9454 else if (completion->priv->current_selected < matches)
9456 completion->priv->current_selected -= 14;
9457 if (completion->priv->current_selected < 0)
9458 completion->priv->current_selected = 0;
9462 completion->priv->current_selected -= 14;
9463 if (completion->priv->current_selected < matches - 1)
9464 completion->priv->current_selected = matches - 1;
9467 else if (event->keyval == GDK_KEY_Page_Down)
9469 if (completion->priv->current_selected < 0)
9470 completion->priv->current_selected = 0;
9471 else if (completion->priv->current_selected < matches - 1)
9473 completion->priv->current_selected += 14;
9474 if (completion->priv->current_selected > matches - 1)
9475 completion->priv->current_selected = matches - 1;
9477 else if (completion->priv->current_selected == matches + actions - 1)
9479 completion->priv->current_selected = -1;
9483 completion->priv->current_selected += 14;
9484 if (completion->priv->current_selected > matches + actions - 1)
9485 completion->priv->current_selected = matches + actions - 1;
9489 if (completion->priv->current_selected < 0)
9491 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9492 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view)));
9494 if (completion->priv->inline_selection &&
9495 completion->priv->completion_prefix)
9497 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9498 completion->priv->completion_prefix);
9499 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9502 else if (completion->priv->current_selected < matches)
9504 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view)));
9506 path = gtk_tree_path_new_from_indices (completion->priv->current_selected, -1);
9507 gtk_tree_view_set_cursor (GTK_TREE_VIEW (completion->priv->tree_view),
9510 if (completion->priv->inline_selection)
9514 GtkTreeIter child_iter;
9515 GtkTreeModel *model = NULL;
9516 GtkTreeSelection *sel;
9519 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view));
9520 if (!gtk_tree_selection_get_selected (sel, &model, &iter))
9523 gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (model), &child_iter, &iter);
9524 model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model));
9526 if (completion->priv->completion_prefix == NULL)
9527 completion->priv->completion_prefix = g_strdup (gtk_entry_get_text (GTK_ENTRY (completion->priv->entry)));
9529 g_signal_emit_by_name (completion, "cursor-on-match", model,
9530 &child_iter, &entry_set);
9533 else if (completion->priv->current_selected - matches >= 0)
9535 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9537 path = gtk_tree_path_new_from_indices (completion->priv->current_selected - matches, -1);
9538 gtk_tree_view_set_cursor (GTK_TREE_VIEW (completion->priv->action_view),
9541 if (completion->priv->inline_selection &&
9542 completion->priv->completion_prefix)
9544 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9545 completion->priv->completion_prefix);
9546 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9550 gtk_tree_path_free (path);
9554 else if (event->keyval == GDK_KEY_Escape ||
9555 event->keyval == GDK_KEY_Left ||
9556 event->keyval == GDK_KEY_KP_Left ||
9557 event->keyval == GDK_KEY_Right ||
9558 event->keyval == GDK_KEY_KP_Right)
9560 gboolean retval = TRUE;
9562 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9563 _gtk_entry_completion_popdown (completion);
9565 if (completion->priv->current_selected < 0)
9568 goto keypress_completion_out;
9570 else if (completion->priv->inline_selection)
9572 /* Escape rejects the tentative completion */
9573 if (event->keyval == GDK_KEY_Escape)
9575 if (completion->priv->completion_prefix)
9576 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9577 completion->priv->completion_prefix);
9579 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry), "");
9582 /* Move the cursor to the end for Right/Esc, to the
9583 beginning for Left */
9584 if (event->keyval == GDK_KEY_Right ||
9585 event->keyval == GDK_KEY_KP_Right ||
9586 event->keyval == GDK_KEY_Escape)
9587 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9589 gtk_editable_set_position (GTK_EDITABLE (widget), 0);
9592 keypress_completion_out:
9593 if (completion->priv->inline_selection)
9595 g_free (completion->priv->completion_prefix);
9596 completion->priv->completion_prefix = NULL;
9601 else if (event->keyval == GDK_KEY_Tab ||
9602 event->keyval == GDK_KEY_KP_Tab ||
9603 event->keyval == GDK_KEY_ISO_Left_Tab)
9605 GtkDirectionType dir = event->keyval == GDK_KEY_ISO_Left_Tab ?
9606 GTK_DIR_TAB_BACKWARD : GTK_DIR_TAB_FORWARD;
9608 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9609 _gtk_entry_completion_popdown (completion);
9611 g_free (completion->priv->completion_prefix);
9612 completion->priv->completion_prefix = NULL;
9614 gtk_widget_child_focus (gtk_widget_get_toplevel (widget), dir);
9618 else if (event->keyval == GDK_KEY_ISO_Enter ||
9619 event->keyval == GDK_KEY_KP_Enter ||
9620 event->keyval == GDK_KEY_Return)
9623 GtkTreeModel *model = NULL;
9624 GtkTreeSelection *sel;
9625 gboolean retval = TRUE;
9627 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9628 _gtk_entry_completion_popdown (completion);
9630 if (completion->priv->current_selected < matches)
9634 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view));
9635 if (gtk_tree_selection_get_selected (sel, &model, &iter))
9637 g_signal_handler_block (widget, completion->priv->changed_id);
9638 g_signal_emit_by_name (completion, "match-selected",
9639 model, &iter, &entry_set);
9640 g_signal_handler_unblock (widget, completion->priv->changed_id);
9646 gtk_tree_model_get (model, &iter,
9647 completion->priv->text_column, &str,
9650 gtk_entry_set_text (GTK_ENTRY (widget), str);
9652 /* move the cursor to the end */
9653 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9661 else if (completion->priv->current_selected - matches >= 0)
9663 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view));
9664 if (gtk_tree_selection_get_selected (sel, &model, &iter))
9668 path = gtk_tree_path_new_from_indices (completion->priv->current_selected - matches, -1);
9669 g_signal_emit_by_name (completion, "action-activated",
9670 gtk_tree_path_get_indices (path)[0]);
9671 gtk_tree_path_free (path);
9677 g_free (completion->priv->completion_prefix);
9678 completion->priv->completion_prefix = NULL;
9687 gtk_entry_completion_changed (GtkWidget *widget,
9690 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
9691 GtkEntry *entry = GTK_ENTRY (widget);
9692 GtkEntryPrivate *priv = entry->priv;
9695 /* (re)install completion timeout */
9696 if (completion->priv->completion_timeout)
9697 g_source_remove (completion->priv->completion_timeout);
9699 if (!gtk_entry_get_text (entry))
9702 /* no need to normalize for this test */
9703 if (completion->priv->minimum_key_length > 0 &&
9704 strcmp ("", gtk_entry_get_text (entry)) == 0)
9706 if (gtk_widget_get_visible (completion->priv->popup_window))
9707 _gtk_entry_completion_popdown (completion);
9711 device = gtk_get_current_event_device ();
9713 if (device && gdk_device_get_source (device) == GDK_SOURCE_KEYBOARD)
9714 device = gdk_device_get_associated_device (device);
9717 priv->completion_device = device;
9719 completion->priv->completion_timeout =
9720 gdk_threads_add_timeout (COMPLETION_TIMEOUT,
9721 gtk_entry_completion_timeout,
9726 check_completion_callback (GtkEntryCompletion *completion)
9728 completion->priv->check_completion_idle = NULL;
9730 gtk_entry_completion_complete (completion);
9731 gtk_entry_completion_insert_prefix (completion);
9737 clear_completion_callback (GtkEntry *entry,
9740 if (pspec->name == I_("cursor-position") ||
9741 pspec->name == I_("selection-bound"))
9743 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
9745 completion->priv->has_completion = FALSE;
9750 accept_completion_callback (GtkEntry *entry)
9752 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
9754 if (completion->priv->has_completion)
9755 gtk_editable_set_position (GTK_EDITABLE (entry),
9756 gtk_entry_buffer_get_length (get_buffer (entry)));
9762 completion_insert_text_callback (GtkEntry *entry,
9766 GtkEntryCompletion *completion)
9768 /* idle to update the selection based on the file list */
9769 if (completion->priv->check_completion_idle == NULL)
9771 completion->priv->check_completion_idle = g_idle_source_new ();
9772 g_source_set_priority (completion->priv->check_completion_idle, G_PRIORITY_HIGH);
9773 g_source_set_closure (completion->priv->check_completion_idle,
9774 g_cclosure_new_object (G_CALLBACK (check_completion_callback),
9775 G_OBJECT (completion)));
9776 g_source_attach (completion->priv->check_completion_idle, NULL);
9781 completion_changed (GtkEntryCompletion *completion,
9785 GtkEntry *entry = GTK_ENTRY (data);
9787 if (pspec->name == I_("popup-completion") ||
9788 pspec->name == I_("inline-completion"))
9790 disconnect_completion_signals (entry, completion);
9791 connect_completion_signals (entry, completion);
9796 disconnect_completion_signals (GtkEntry *entry,
9797 GtkEntryCompletion *completion)
9799 g_signal_handlers_disconnect_by_func (completion,
9800 G_CALLBACK (completion_changed), entry);
9801 if (completion->priv->changed_id > 0 &&
9802 g_signal_handler_is_connected (entry, completion->priv->changed_id))
9804 g_signal_handler_disconnect (entry, completion->priv->changed_id);
9805 completion->priv->changed_id = 0;
9807 g_signal_handlers_disconnect_by_func (entry,
9808 G_CALLBACK (gtk_entry_completion_key_press), completion);
9809 if (completion->priv->insert_text_id > 0 &&
9810 g_signal_handler_is_connected (entry, completion->priv->insert_text_id))
9812 g_signal_handler_disconnect (entry, completion->priv->insert_text_id);
9813 completion->priv->insert_text_id = 0;
9815 g_signal_handlers_disconnect_by_func (entry,
9816 G_CALLBACK (completion_insert_text_callback), completion);
9817 g_signal_handlers_disconnect_by_func (entry,
9818 G_CALLBACK (clear_completion_callback), completion);
9819 g_signal_handlers_disconnect_by_func (entry,
9820 G_CALLBACK (accept_completion_callback), completion);
9824 connect_completion_signals (GtkEntry *entry,
9825 GtkEntryCompletion *completion)
9827 if (completion->priv->popup_completion)
9829 completion->priv->changed_id =
9830 g_signal_connect (entry, "changed",
9831 G_CALLBACK (gtk_entry_completion_changed), completion);
9832 g_signal_connect (entry, "key-press-event",
9833 G_CALLBACK (gtk_entry_completion_key_press), completion);
9836 if (completion->priv->inline_completion)
9838 completion->priv->insert_text_id =
9839 g_signal_connect (entry, "insert-text",
9840 G_CALLBACK (completion_insert_text_callback), completion);
9841 g_signal_connect (entry, "notify",
9842 G_CALLBACK (clear_completion_callback), completion);
9843 g_signal_connect (entry, "activate",
9844 G_CALLBACK (accept_completion_callback), completion);
9845 g_signal_connect (entry, "focus-out-event",
9846 G_CALLBACK (accept_completion_callback), completion);
9849 g_signal_connect (completion, "notify",
9850 G_CALLBACK (completion_changed), entry);
9854 * gtk_entry_set_completion:
9855 * @entry: A #GtkEntry
9856 * @completion: (allow-none): The #GtkEntryCompletion or %NULL
9858 * Sets @completion to be the auxiliary completion object to use with @entry.
9859 * All further configuration of the completion mechanism is done on
9860 * @completion using the #GtkEntryCompletion API. Completion is disabled if
9861 * @completion is set to %NULL.
9866 gtk_entry_set_completion (GtkEntry *entry,
9867 GtkEntryCompletion *completion)
9869 GtkEntryCompletion *old;
9871 g_return_if_fail (GTK_IS_ENTRY (entry));
9872 g_return_if_fail (!completion || GTK_IS_ENTRY_COMPLETION (completion));
9874 old = gtk_entry_get_completion (entry);
9876 if (old == completion)
9881 if (old->priv->completion_timeout)
9883 g_source_remove (old->priv->completion_timeout);
9884 old->priv->completion_timeout = 0;
9887 if (gtk_widget_get_mapped (old->priv->popup_window))
9888 _gtk_entry_completion_popdown (old);
9890 disconnect_completion_signals (entry, old);
9891 old->priv->entry = NULL;
9893 g_object_unref (old);
9898 g_object_set_data (G_OBJECT (entry), I_(GTK_ENTRY_COMPLETION_KEY), NULL);
9902 /* hook into the entry */
9903 g_object_ref (completion);
9905 connect_completion_signals (entry, completion);
9906 completion->priv->entry = GTK_WIDGET (entry);
9907 g_object_set_data (G_OBJECT (entry), I_(GTK_ENTRY_COMPLETION_KEY), completion);
9911 * gtk_entry_get_completion:
9912 * @entry: A #GtkEntry
9914 * Returns the auxiliary completion object currently in use by @entry.
9916 * Return value: (transfer none): The auxiliary completion object currently
9921 GtkEntryCompletion *
9922 gtk_entry_get_completion (GtkEntry *entry)
9924 GtkEntryCompletion *completion;
9926 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
9928 completion = GTK_ENTRY_COMPLETION (g_object_get_data (G_OBJECT (entry),
9929 GTK_ENTRY_COMPLETION_KEY));
9935 * gtk_entry_set_cursor_hadjustment:
9936 * @entry: a #GtkEntry
9937 * @adjustment: an adjustment which should be adjusted when the cursor
9938 * is moved, or %NULL
9940 * Hooks up an adjustment to the cursor position in an entry, so that when
9941 * the cursor is moved, the adjustment is scrolled to show that position.
9942 * See gtk_scrolled_window_get_hadjustment() for a typical way of obtaining
9945 * The adjustment has to be in pixel units and in the same coordinate system
9951 gtk_entry_set_cursor_hadjustment (GtkEntry *entry,
9952 GtkAdjustment *adjustment)
9954 g_return_if_fail (GTK_IS_ENTRY (entry));
9956 g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
9959 g_object_ref (adjustment);
9961 g_object_set_qdata_full (G_OBJECT (entry),
9962 quark_cursor_hadjustment,
9968 * gtk_entry_get_cursor_hadjustment:
9969 * @entry: a #GtkEntry
9971 * Retrieves the horizontal cursor adjustment for the entry.
9972 * See gtk_entry_set_cursor_hadjustment().
9974 * Return value: (transfer none): the horizontal cursor adjustment, or %NULL
9975 * if none has been set.
9980 gtk_entry_get_cursor_hadjustment (GtkEntry *entry)
9982 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
9984 return g_object_get_qdata (G_OBJECT (entry), quark_cursor_hadjustment);
9988 * gtk_entry_set_progress_fraction:
9989 * @entry: a #GtkEntry
9990 * @fraction: fraction of the task that's been completed
9992 * Causes the entry's progress indicator to "fill in" the given
9993 * fraction of the bar. The fraction should be between 0.0 and 1.0,
9999 gtk_entry_set_progress_fraction (GtkEntry *entry,
10003 GtkEntryPrivate *private;
10004 gdouble old_fraction;
10005 gint x, y, width, height;
10006 gint old_x, old_y, old_width, old_height;
10008 g_return_if_fail (GTK_IS_ENTRY (entry));
10010 widget = GTK_WIDGET (entry);
10011 private = entry->priv;
10013 if (private->progress_pulse_mode)
10016 old_fraction = private->progress_fraction;
10018 if (gtk_widget_is_drawable (widget))
10019 get_progress_area (widget, &old_x, &old_y, &old_width, &old_height);
10021 fraction = CLAMP (fraction, 0.0, 1.0);
10023 private->progress_fraction = fraction;
10024 private->progress_pulse_mode = FALSE;
10025 private->progress_pulse_current = 0.0;
10027 if (gtk_widget_is_drawable (widget))
10029 get_progress_area (widget, &x, &y, &width, &height);
10031 if ((x != old_x) || (y != old_y) || (width != old_width) || (height != old_height))
10032 gtk_widget_queue_draw (widget);
10035 if (fraction != old_fraction)
10036 g_object_notify (G_OBJECT (entry), "progress-fraction");
10040 * gtk_entry_get_progress_fraction:
10041 * @entry: a #GtkEntry
10043 * Returns the current fraction of the task that's been completed.
10044 * See gtk_entry_set_progress_fraction().
10046 * Return value: a fraction from 0.0 to 1.0
10051 gtk_entry_get_progress_fraction (GtkEntry *entry)
10053 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
10055 return entry->priv->progress_fraction;
10059 * gtk_entry_set_progress_pulse_step:
10060 * @entry: a #GtkEntry
10061 * @fraction: fraction between 0.0 and 1.0
10063 * Sets the fraction of total entry width to move the progress
10064 * bouncing block for each call to gtk_entry_progress_pulse().
10069 gtk_entry_set_progress_pulse_step (GtkEntry *entry,
10072 GtkEntryPrivate *private;
10074 g_return_if_fail (GTK_IS_ENTRY (entry));
10076 private = entry->priv;
10078 fraction = CLAMP (fraction, 0.0, 1.0);
10080 if (fraction != private->progress_pulse_fraction)
10082 private->progress_pulse_fraction = fraction;
10084 gtk_widget_queue_draw (GTK_WIDGET (entry));
10086 g_object_notify (G_OBJECT (entry), "progress-pulse-step");
10091 * gtk_entry_get_progress_pulse_step:
10092 * @entry: a #GtkEntry
10094 * Retrieves the pulse step set with gtk_entry_set_progress_pulse_step().
10096 * Return value: a fraction from 0.0 to 1.0
10101 gtk_entry_get_progress_pulse_step (GtkEntry *entry)
10103 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
10105 return entry->priv->progress_pulse_fraction;
10109 * gtk_entry_progress_pulse:
10110 * @entry: a #GtkEntry
10112 * Indicates that some progress is made, but you don't know how much.
10113 * Causes the entry's progress indicator to enter "activity mode,"
10114 * where a block bounces back and forth. Each call to
10115 * gtk_entry_progress_pulse() causes the block to move by a little bit
10116 * (the amount of movement per pulse is determined by
10117 * gtk_entry_set_progress_pulse_step()).
10122 gtk_entry_progress_pulse (GtkEntry *entry)
10124 GtkEntryPrivate *private;
10126 g_return_if_fail (GTK_IS_ENTRY (entry));
10128 private = entry->priv;
10130 if (private->progress_pulse_mode)
10132 if (private->progress_pulse_way_back)
10134 private->progress_pulse_current -= private->progress_pulse_fraction;
10136 if (private->progress_pulse_current < 0.0)
10138 private->progress_pulse_current = 0.0;
10139 private->progress_pulse_way_back = FALSE;
10144 private->progress_pulse_current += private->progress_pulse_fraction;
10146 if (private->progress_pulse_current > 1.0 - private->progress_pulse_fraction)
10148 private->progress_pulse_current = 1.0 - private->progress_pulse_fraction;
10149 private->progress_pulse_way_back = TRUE;
10155 private->progress_fraction = 0.0;
10156 private->progress_pulse_mode = TRUE;
10157 private->progress_pulse_way_back = FALSE;
10158 private->progress_pulse_current = 0.0;
10161 gtk_widget_queue_draw (GTK_WIDGET (entry));
10164 /* Caps Lock warning for password entries */
10167 show_capslock_feedback (GtkEntry *entry,
10170 GtkEntryPrivate *priv = entry->priv;
10172 if (gtk_entry_get_icon_storage_type (entry, GTK_ENTRY_ICON_SECONDARY) == GTK_IMAGE_EMPTY)
10174 gtk_entry_set_icon_from_stock (entry, GTK_ENTRY_ICON_SECONDARY, GTK_STOCK_CAPS_LOCK_WARNING);
10175 gtk_entry_set_icon_activatable (entry, GTK_ENTRY_ICON_SECONDARY, FALSE);
10176 priv->caps_lock_warning_shown = TRUE;
10179 if (priv->caps_lock_warning_shown)
10180 gtk_entry_set_icon_tooltip_text (entry, GTK_ENTRY_ICON_SECONDARY, text);
10182 g_warning ("Can't show Caps Lock warning, since secondary icon is set");
10186 remove_capslock_feedback (GtkEntry *entry)
10188 GtkEntryPrivate *priv = entry->priv;
10190 if (priv->caps_lock_warning_shown)
10192 gtk_entry_set_icon_from_stock (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
10193 priv->caps_lock_warning_shown = FALSE;
10198 keymap_state_changed (GdkKeymap *keymap,
10201 GtkEntryPrivate *priv = entry->priv;
10204 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL && priv->caps_lock_warning)
10206 if (gdk_keymap_get_num_lock_state (keymap)
10207 && gdk_keymap_get_caps_lock_state (keymap))
10208 text = _("Caps Lock and Num Lock are on");
10209 else if (gdk_keymap_get_num_lock_state (keymap))
10210 text = _("Num Lock is on");
10211 else if (gdk_keymap_get_caps_lock_state (keymap))
10212 text = _("Caps Lock is on");
10216 show_capslock_feedback (entry, text);
10218 remove_capslock_feedback (entry);