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 "gtkalignment.h"
37 #include "gtkbindings.h"
38 #include "gtkcelleditable.h"
39 #include "gtkclipboard.h"
42 #include "gtkentrybuffer.h"
43 #include "gtkimagemenuitem.h"
44 #include "gtkimcontextsimple.h"
45 #include "gtkimmulticontext.h"
49 #include "gtkmarshalers.h"
51 #include "gtkmenuitem.h"
52 #include "gtkseparatormenuitem.h"
53 #include "gtkselection.h"
54 #include "gtksettings.h"
55 #include "gtkspinbutton.h"
57 #include "gtktextutil.h"
58 #include "gtkwindow.h"
59 #include "gtktreeview.h"
60 #include "gtktreeselection.h"
61 #include "gtktypebuiltins.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"
68 #include "gtkwidgetprivate.h"
69 #include "gtkstylecontextprivate.h"
73 * @Short_description: A single line text entry field
75 * @See_also: #GtkTextView, #GtkEntryCompletion
77 * The #GtkEntry widget is a single line text entry
78 * widget. A fairly large set of key bindings are supported
79 * by default. If the entered text is longer than the allocation
80 * of the widget, the widget will scroll so that the cursor
81 * position is visible.
83 * When using an entry for passwords and other sensitive information,
84 * it can be put into "password mode" using gtk_entry_set_visibility().
85 * In this mode, entered text is displayed using a 'invisible' character.
86 * By default, GTK+ picks the best invisible character that is available
87 * in the current font, but it can be changed with
88 * gtk_entry_set_invisible_char(). Since 2.16, GTK+ displays a warning
89 * when Caps Lock or input methods might interfere with entering text in
90 * a password entry. The warning can be turned off with the
91 * #GtkEntry:caps-lock-warning property.
93 * Since 2.16, GtkEntry has the ability to display progress or activity
94 * information behind the text. To make an entry display such information,
95 * use gtk_entry_set_progress_fraction() or gtk_entry_set_progress_pulse_step().
97 * Additionally, GtkEntry can show icons at either side of the entry. These
98 * icons can be activatable by clicking, can be set up as drag source and
99 * can have tooltips. To add an icon, use gtk_entry_set_icon_from_gicon() or
100 * one of the various other functions that set an icon from a stock id, an
101 * icon name or a pixbuf. To trigger an action when the user clicks an icon,
102 * connect to the #GtkEntry::icon-press signal. To allow DND operations
103 * from an icon, use gtk_entry_set_icon_drag_source(). To set a tooltip on
104 * an icon, use gtk_entry_set_icon_tooltip_text() or the corresponding function
107 * Note that functionality or information that is only available by clicking
108 * on an icon in an entry may not be accessible at all to users which are not
109 * able to use a mouse or other pointing device. It is therefore recommended
110 * that any such functionality should also be available by other means, e.g.
111 * via the context menu of the entry.
115 #define GTK_ENTRY_COMPLETION_KEY "gtk-entry-completion-key"
117 #define MIN_ENTRY_WIDTH 150
118 #define DRAW_TIMEOUT 20
119 #define COMPLETION_TIMEOUT 300
120 #define PASSWORD_HINT_MAX 8
124 #define IS_VALID_ICON_POSITION(pos) \
125 ((pos) == GTK_ENTRY_ICON_PRIMARY || \
126 (pos) == GTK_ENTRY_ICON_SECONDARY)
128 static const GtkBorder default_inner_border = { 2, 2, 2, 2 };
129 static GQuark quark_inner_border = 0;
130 static GQuark quark_password_hint = 0;
131 static GQuark quark_cursor_hadjustment = 0;
132 static GQuark quark_capslock_feedback = 0;
134 typedef struct _EntryIconInfo EntryIconInfo;
135 typedef struct _GtkEntryPasswordHint GtkEntryPasswordHint;
136 typedef struct _GtkEntryCapslockFeedback GtkEntryCapslockFeedback;
138 struct _GtkEntryPrivate
140 EntryIconInfo *icons[MAX_ICONS];
142 GtkEntryBuffer *buffer;
143 GtkIMContext *im_context;
144 GtkShadowType shadow_type;
145 GtkWidget *popup_menu;
147 GdkDevice *completion_device;
148 GdkWindow *text_area;
150 PangoLayout *cached_layout;
154 gdouble progress_fraction;
155 gdouble progress_pulse_fraction;
156 gdouble progress_pulse_current;
158 gchar *placeholder_text;
162 gint ascent; /* font ascent in pango units */
164 gint descent; /* font descent in pango units */
165 gint dnd_position; /* In chars, -1 == no DND cursor */
171 gint selection_bound;
177 gunichar invisible_char;
180 guint blink_time; /* time in msec the cursor has blinked since last user event */
182 guint recompute_idle;
184 guint16 x_text_size; /* allocated size, in bytes */
185 guint16 x_n_bytes; /* length in use, in bytes */
187 guint16 preedit_length; /* length of preedit string, in bytes */
188 guint16 preedit_cursor; /* offset of cursor within preedit string, in chars */
192 guint overwrite_mode : 1;
195 guint activates_default : 1;
196 guint cache_includes_preedit : 1;
197 guint caps_lock_warning : 1;
198 guint caps_lock_warning_shown : 1;
199 guint change_count : 8;
200 guint cursor_visible : 1;
201 guint editing_canceled : 1; /* Only used by GtkCellRendererText */
203 guint in_click : 1; /* Flag so we don't select all when clicking in entry to focus in */
204 guint is_cell_renderer : 1;
205 guint invisible_char_set : 1;
206 guint interior_focus : 1;
207 guint mouse_cursor_obscured : 1;
208 guint need_im_reset : 1;
209 guint progress_pulse_mode : 1;
210 guint progress_pulse_way_back : 1;
211 guint real_changed : 1;
212 guint resolved_dir : 4; /* PangoDirection */
213 guint select_words : 1;
214 guint select_lines : 1;
215 guint truncate_multiline : 1;
218 struct _EntryIconInfo
222 guint insensitive : 1;
223 guint nonactivatable : 1;
228 GtkImageType storage_type;
234 GtkTargetList *target_list;
235 GdkDragAction actions;
238 struct _GtkEntryPasswordHint
240 gint position; /* Position (in text) of the last password hint */
241 guint source_id; /* Timeout source id */
244 struct _GtkEntryCapslockFeedback
271 PROP_CURSOR_POSITION,
272 PROP_SELECTION_BOUND,
279 PROP_ACTIVATES_DEFAULT,
284 PROP_TRUNCATE_MULTILINE,
288 PROP_INVISIBLE_CHAR_SET,
289 PROP_CAPS_LOCK_WARNING,
290 PROP_PROGRESS_FRACTION,
291 PROP_PROGRESS_PULSE_STEP,
293 PROP_PIXBUF_SECONDARY,
295 PROP_STOCK_SECONDARY,
296 PROP_ICON_NAME_PRIMARY,
297 PROP_ICON_NAME_SECONDARY,
299 PROP_GICON_SECONDARY,
300 PROP_STORAGE_TYPE_PRIMARY,
301 PROP_STORAGE_TYPE_SECONDARY,
302 PROP_ACTIVATABLE_PRIMARY,
303 PROP_ACTIVATABLE_SECONDARY,
304 PROP_SENSITIVE_PRIMARY,
305 PROP_SENSITIVE_SECONDARY,
306 PROP_TOOLTIP_TEXT_PRIMARY,
307 PROP_TOOLTIP_TEXT_SECONDARY,
308 PROP_TOOLTIP_MARKUP_PRIMARY,
309 PROP_TOOLTIP_MARKUP_SECONDARY,
311 PROP_EDITING_CANCELED,
312 PROP_PLACEHOLDER_TEXT,
316 static guint signals[LAST_SIGNAL] = { 0 };
325 DISPLAY_NORMAL, /* The entry text is being shown */
326 DISPLAY_INVISIBLE, /* In invisible mode, text replaced by (eg) bullets */
327 DISPLAY_BLANK /* In invisible mode, nothing shown at all */
332 static void gtk_entry_editable_init (GtkEditableInterface *iface);
333 static void gtk_entry_cell_editable_init (GtkCellEditableIface *iface);
334 static void gtk_entry_set_property (GObject *object,
338 static void gtk_entry_get_property (GObject *object,
342 static void gtk_entry_finalize (GObject *object);
343 static void gtk_entry_dispose (GObject *object);
347 static void gtk_entry_destroy (GtkWidget *widget);
348 static void gtk_entry_realize (GtkWidget *widget);
349 static void gtk_entry_unrealize (GtkWidget *widget);
350 static void gtk_entry_map (GtkWidget *widget);
351 static void gtk_entry_unmap (GtkWidget *widget);
352 static void gtk_entry_get_preferred_width (GtkWidget *widget,
355 static void gtk_entry_get_preferred_height (GtkWidget *widget,
358 static void gtk_entry_size_allocate (GtkWidget *widget,
359 GtkAllocation *allocation);
360 static void gtk_entry_draw_frame (GtkWidget *widget,
361 GtkStyleContext *context,
363 static void gtk_entry_draw_progress (GtkWidget *widget,
364 GtkStyleContext *context,
366 static gint gtk_entry_draw (GtkWidget *widget,
368 static gint gtk_entry_button_press (GtkWidget *widget,
369 GdkEventButton *event);
370 static gint gtk_entry_button_release (GtkWidget *widget,
371 GdkEventButton *event);
372 static gint gtk_entry_enter_notify (GtkWidget *widget,
373 GdkEventCrossing *event);
374 static gint gtk_entry_leave_notify (GtkWidget *widget,
375 GdkEventCrossing *event);
376 static gint gtk_entry_motion_notify (GtkWidget *widget,
377 GdkEventMotion *event);
378 static gint gtk_entry_key_press (GtkWidget *widget,
380 static gint gtk_entry_key_release (GtkWidget *widget,
382 static gint gtk_entry_focus_in (GtkWidget *widget,
383 GdkEventFocus *event);
384 static gint gtk_entry_focus_out (GtkWidget *widget,
385 GdkEventFocus *event);
386 static void gtk_entry_grab_focus (GtkWidget *widget);
387 static void gtk_entry_style_updated (GtkWidget *widget);
388 static gboolean gtk_entry_query_tooltip (GtkWidget *widget,
391 gboolean keyboard_tip,
392 GtkTooltip *tooltip);
393 static void gtk_entry_direction_changed (GtkWidget *widget,
394 GtkTextDirection previous_dir);
395 static void gtk_entry_state_flags_changed (GtkWidget *widget,
396 GtkStateFlags previous_state);
397 static void gtk_entry_screen_changed (GtkWidget *widget,
398 GdkScreen *old_screen);
400 static gboolean gtk_entry_drag_drop (GtkWidget *widget,
401 GdkDragContext *context,
405 static gboolean gtk_entry_drag_motion (GtkWidget *widget,
406 GdkDragContext *context,
410 static void gtk_entry_drag_leave (GtkWidget *widget,
411 GdkDragContext *context,
413 static void gtk_entry_drag_data_received (GtkWidget *widget,
414 GdkDragContext *context,
417 GtkSelectionData *selection_data,
420 static void gtk_entry_drag_data_get (GtkWidget *widget,
421 GdkDragContext *context,
422 GtkSelectionData *selection_data,
425 static void gtk_entry_drag_data_delete (GtkWidget *widget,
426 GdkDragContext *context);
427 static void gtk_entry_drag_begin (GtkWidget *widget,
428 GdkDragContext *context);
429 static void gtk_entry_drag_end (GtkWidget *widget,
430 GdkDragContext *context);
433 /* GtkEditable method implementations
435 static void gtk_entry_insert_text (GtkEditable *editable,
436 const gchar *new_text,
437 gint new_text_length,
439 static void gtk_entry_delete_text (GtkEditable *editable,
442 static gchar * gtk_entry_get_chars (GtkEditable *editable,
445 static void gtk_entry_real_set_position (GtkEditable *editable,
447 static gint gtk_entry_get_position (GtkEditable *editable);
448 static void gtk_entry_set_selection_bounds (GtkEditable *editable,
451 static gboolean gtk_entry_get_selection_bounds (GtkEditable *editable,
455 /* GtkCellEditable method implementations
457 static void gtk_entry_start_editing (GtkCellEditable *cell_editable,
460 /* Default signal handlers
462 static void gtk_entry_real_insert_text (GtkEditable *editable,
463 const gchar *new_text,
464 gint new_text_length,
466 static void gtk_entry_real_delete_text (GtkEditable *editable,
469 static void gtk_entry_move_cursor (GtkEntry *entry,
470 GtkMovementStep step,
472 gboolean extend_selection);
473 static void gtk_entry_insert_at_cursor (GtkEntry *entry,
475 static void gtk_entry_delete_from_cursor (GtkEntry *entry,
478 static void gtk_entry_backspace (GtkEntry *entry);
479 static void gtk_entry_cut_clipboard (GtkEntry *entry);
480 static void gtk_entry_copy_clipboard (GtkEntry *entry);
481 static void gtk_entry_paste_clipboard (GtkEntry *entry);
482 static void gtk_entry_toggle_overwrite (GtkEntry *entry);
483 static void gtk_entry_select_all (GtkEntry *entry);
484 static void gtk_entry_real_activate (GtkEntry *entry);
485 static gboolean gtk_entry_popup_menu (GtkWidget *widget);
487 static void keymap_direction_changed (GdkKeymap *keymap,
489 static void keymap_state_changed (GdkKeymap *keymap,
491 static void remove_capslock_feedback (GtkEntry *entry);
493 /* IM Context Callbacks
495 static void gtk_entry_commit_cb (GtkIMContext *context,
498 static void gtk_entry_preedit_changed_cb (GtkIMContext *context,
500 static gboolean gtk_entry_retrieve_surrounding_cb (GtkIMContext *context,
502 static gboolean gtk_entry_delete_surrounding_cb (GtkIMContext *context,
509 static void gtk_entry_enter_text (GtkEntry *entry,
511 static void gtk_entry_set_positions (GtkEntry *entry,
513 gint selection_bound);
514 static void gtk_entry_draw_text (GtkEntry *entry,
516 static void gtk_entry_draw_cursor (GtkEntry *entry,
519 static PangoLayout *gtk_entry_ensure_layout (GtkEntry *entry,
520 gboolean include_preedit);
521 static void gtk_entry_reset_layout (GtkEntry *entry);
522 static void gtk_entry_recompute (GtkEntry *entry);
523 static gint gtk_entry_find_position (GtkEntry *entry,
525 static void gtk_entry_get_cursor_locations (GtkEntry *entry,
529 static void gtk_entry_adjust_scroll (GtkEntry *entry);
530 static gint gtk_entry_move_visually (GtkEntry *editable,
533 static gint gtk_entry_move_logically (GtkEntry *entry,
536 static gint gtk_entry_move_forward_word (GtkEntry *entry,
538 gboolean allow_whitespace);
539 static gint gtk_entry_move_backward_word (GtkEntry *entry,
541 gboolean allow_whitespace);
542 static void gtk_entry_delete_whitespace (GtkEntry *entry);
543 static void gtk_entry_select_word (GtkEntry *entry);
544 static void gtk_entry_select_line (GtkEntry *entry);
545 static void gtk_entry_paste (GtkEntry *entry,
547 static void gtk_entry_update_primary_selection (GtkEntry *entry);
548 static void gtk_entry_do_popup (GtkEntry *entry,
549 GdkEventButton *event);
550 static gboolean gtk_entry_mnemonic_activate (GtkWidget *widget,
551 gboolean group_cycling);
552 static void gtk_entry_check_cursor_blink (GtkEntry *entry);
553 static void gtk_entry_pend_cursor_blink (GtkEntry *entry);
554 static void gtk_entry_reset_blink_time (GtkEntry *entry);
555 static void gtk_entry_get_text_area_size (GtkEntry *entry,
560 static void get_text_area_size (GtkEntry *entry,
565 static void get_frame_size (GtkEntry *entry,
566 gboolean relative_to_window,
571 static void gtk_entry_move_adjustments (GtkEntry *entry);
572 static void gtk_entry_ensure_pixbuf (GtkEntry *entry,
573 GtkEntryIconPosition icon_pos);
577 static gint gtk_entry_completion_timeout (gpointer data);
578 static gboolean gtk_entry_completion_key_press (GtkWidget *widget,
581 static void gtk_entry_completion_changed (GtkWidget *entry,
583 static gboolean check_completion_callback (GtkEntryCompletion *completion);
584 static void clear_completion_callback (GtkEntry *entry,
586 static gboolean accept_completion_callback (GtkEntry *entry);
587 static void completion_insert_text_callback (GtkEntry *entry,
591 GtkEntryCompletion *completion);
592 static void completion_changed (GtkEntryCompletion *completion,
595 static void disconnect_completion_signals (GtkEntry *entry,
596 GtkEntryCompletion *completion);
597 static void connect_completion_signals (GtkEntry *entry,
598 GtkEntryCompletion *completion);
600 static void begin_change (GtkEntry *entry);
601 static void end_change (GtkEntry *entry);
602 static void emit_changed (GtkEntry *entry);
604 static void buffer_inserted_text (GtkEntryBuffer *buffer,
609 static void buffer_deleted_text (GtkEntryBuffer *buffer,
613 static void buffer_notify_text (GtkEntryBuffer *buffer,
616 static void buffer_notify_length (GtkEntryBuffer *buffer,
619 static void buffer_notify_max_length (GtkEntryBuffer *buffer,
622 static void buffer_connect_signals (GtkEntry *entry);
623 static void buffer_disconnect_signals (GtkEntry *entry);
624 static GtkEntryBuffer *get_buffer (GtkEntry *entry);
626 G_DEFINE_TYPE_WITH_CODE (GtkEntry, gtk_entry, GTK_TYPE_WIDGET,
627 G_IMPLEMENT_INTERFACE (GTK_TYPE_EDITABLE,
628 gtk_entry_editable_init)
629 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_EDITABLE,
630 gtk_entry_cell_editable_init))
633 add_move_binding (GtkBindingSet *binding_set,
636 GtkMovementStep step,
639 g_return_if_fail ((modmask & GDK_SHIFT_MASK) == 0);
641 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
645 G_TYPE_BOOLEAN, FALSE);
647 /* Selection-extending version */
648 gtk_binding_entry_add_signal (binding_set, keyval, modmask | GDK_SHIFT_MASK,
652 G_TYPE_BOOLEAN, TRUE);
656 gtk_entry_class_init (GtkEntryClass *class)
658 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
659 GtkWidgetClass *widget_class;
660 GtkBindingSet *binding_set;
662 widget_class = (GtkWidgetClass*) class;
664 gobject_class->dispose = gtk_entry_dispose;
665 gobject_class->finalize = gtk_entry_finalize;
666 gobject_class->set_property = gtk_entry_set_property;
667 gobject_class->get_property = gtk_entry_get_property;
669 widget_class->destroy = gtk_entry_destroy;
670 widget_class->map = gtk_entry_map;
671 widget_class->unmap = gtk_entry_unmap;
672 widget_class->realize = gtk_entry_realize;
673 widget_class->unrealize = gtk_entry_unrealize;
674 widget_class->get_preferred_width = gtk_entry_get_preferred_width;
675 widget_class->get_preferred_height = gtk_entry_get_preferred_height;
676 widget_class->size_allocate = gtk_entry_size_allocate;
677 widget_class->draw = gtk_entry_draw;
678 widget_class->enter_notify_event = gtk_entry_enter_notify;
679 widget_class->leave_notify_event = gtk_entry_leave_notify;
680 widget_class->button_press_event = gtk_entry_button_press;
681 widget_class->button_release_event = gtk_entry_button_release;
682 widget_class->motion_notify_event = gtk_entry_motion_notify;
683 widget_class->key_press_event = gtk_entry_key_press;
684 widget_class->key_release_event = gtk_entry_key_release;
685 widget_class->focus_in_event = gtk_entry_focus_in;
686 widget_class->focus_out_event = gtk_entry_focus_out;
687 widget_class->grab_focus = gtk_entry_grab_focus;
688 widget_class->style_updated = gtk_entry_style_updated;
689 widget_class->query_tooltip = gtk_entry_query_tooltip;
690 widget_class->drag_begin = gtk_entry_drag_begin;
691 widget_class->drag_end = gtk_entry_drag_end;
692 widget_class->direction_changed = gtk_entry_direction_changed;
693 widget_class->state_flags_changed = gtk_entry_state_flags_changed;
694 widget_class->screen_changed = gtk_entry_screen_changed;
695 widget_class->mnemonic_activate = gtk_entry_mnemonic_activate;
697 widget_class->drag_drop = gtk_entry_drag_drop;
698 widget_class->drag_motion = gtk_entry_drag_motion;
699 widget_class->drag_leave = gtk_entry_drag_leave;
700 widget_class->drag_data_received = gtk_entry_drag_data_received;
701 widget_class->drag_data_get = gtk_entry_drag_data_get;
702 widget_class->drag_data_delete = gtk_entry_drag_data_delete;
704 widget_class->popup_menu = gtk_entry_popup_menu;
706 class->move_cursor = gtk_entry_move_cursor;
707 class->insert_at_cursor = gtk_entry_insert_at_cursor;
708 class->delete_from_cursor = gtk_entry_delete_from_cursor;
709 class->backspace = gtk_entry_backspace;
710 class->cut_clipboard = gtk_entry_cut_clipboard;
711 class->copy_clipboard = gtk_entry_copy_clipboard;
712 class->paste_clipboard = gtk_entry_paste_clipboard;
713 class->toggle_overwrite = gtk_entry_toggle_overwrite;
714 class->activate = gtk_entry_real_activate;
715 class->get_text_area_size = gtk_entry_get_text_area_size;
717 quark_inner_border = g_quark_from_static_string ("gtk-entry-inner-border");
718 quark_password_hint = g_quark_from_static_string ("gtk-entry-password-hint");
719 quark_cursor_hadjustment = g_quark_from_static_string ("gtk-hadjustment");
720 quark_capslock_feedback = g_quark_from_static_string ("gtk-entry-capslock-feedback");
722 g_object_class_override_property (gobject_class,
723 PROP_EDITING_CANCELED,
726 g_object_class_install_property (gobject_class,
728 g_param_spec_object ("buffer",
730 P_("Text buffer object which actually stores entry text"),
731 GTK_TYPE_ENTRY_BUFFER,
732 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT));
734 g_object_class_install_property (gobject_class,
735 PROP_CURSOR_POSITION,
736 g_param_spec_int ("cursor-position",
737 P_("Cursor Position"),
738 P_("The current position of the insertion cursor in chars"),
740 GTK_ENTRY_BUFFER_MAX_SIZE,
742 GTK_PARAM_READABLE));
744 g_object_class_install_property (gobject_class,
745 PROP_SELECTION_BOUND,
746 g_param_spec_int ("selection-bound",
747 P_("Selection Bound"),
748 P_("The position of the opposite end of the selection from the cursor in chars"),
750 GTK_ENTRY_BUFFER_MAX_SIZE,
752 GTK_PARAM_READABLE));
754 g_object_class_install_property (gobject_class,
756 g_param_spec_boolean ("editable",
758 P_("Whether the entry contents can be edited"),
760 GTK_PARAM_READWRITE));
762 g_object_class_install_property (gobject_class,
764 g_param_spec_int ("max-length",
765 P_("Maximum length"),
766 P_("Maximum number of characters for this entry. Zero if no maximum"),
768 GTK_ENTRY_BUFFER_MAX_SIZE,
770 GTK_PARAM_READWRITE));
771 g_object_class_install_property (gobject_class,
773 g_param_spec_boolean ("visibility",
775 P_("FALSE displays the \"invisible char\" instead of the actual text (password mode)"),
777 GTK_PARAM_READWRITE));
779 g_object_class_install_property (gobject_class,
781 g_param_spec_boolean ("has-frame",
783 P_("FALSE removes outside bevel from entry"),
785 GTK_PARAM_READWRITE));
787 g_object_class_install_property (gobject_class,
789 g_param_spec_boxed ("inner-border",
791 P_("Border between text and frame. Overrides the inner-border style property"),
793 GTK_PARAM_READWRITE));
795 g_object_class_install_property (gobject_class,
797 g_param_spec_unichar ("invisible-char",
798 P_("Invisible character"),
799 P_("The character to use when masking entry contents (in \"password mode\")"),
801 GTK_PARAM_READWRITE));
803 g_object_class_install_property (gobject_class,
804 PROP_ACTIVATES_DEFAULT,
805 g_param_spec_boolean ("activates-default",
806 P_("Activates default"),
807 P_("Whether to activate the default widget (such as the default button in a dialog) when Enter is pressed"),
809 GTK_PARAM_READWRITE));
810 g_object_class_install_property (gobject_class,
812 g_param_spec_int ("width-chars",
813 P_("Width in chars"),
814 P_("Number of characters to leave space for in the entry"),
818 GTK_PARAM_READWRITE));
820 g_object_class_install_property (gobject_class,
822 g_param_spec_int ("scroll-offset",
824 P_("Number of pixels of the entry scrolled off the screen to the left"),
828 GTK_PARAM_READABLE));
830 g_object_class_install_property (gobject_class,
832 g_param_spec_string ("text",
834 P_("The contents of the entry"),
836 GTK_PARAM_READWRITE));
841 * The horizontal alignment, from 0 (left) to 1 (right).
842 * Reversed for RTL layouts.
846 g_object_class_install_property (gobject_class,
848 g_param_spec_float ("xalign",
850 P_("The horizontal alignment, from 0 (left) to 1 (right). Reversed for RTL layouts."),
854 GTK_PARAM_READWRITE));
857 * GtkEntry:truncate-multiline:
859 * When %TRUE, pasted multi-line text is truncated to the first line.
863 g_object_class_install_property (gobject_class,
864 PROP_TRUNCATE_MULTILINE,
865 g_param_spec_boolean ("truncate-multiline",
866 P_("Truncate multiline"),
867 P_("Whether to truncate multiline pastes to one line."),
869 GTK_PARAM_READWRITE));
872 * GtkEntry:shadow-type:
874 * Which kind of shadow to draw around the entry when
875 * #GtkEntry:has-frame is set to %TRUE.
879 g_object_class_install_property (gobject_class,
881 g_param_spec_enum ("shadow-type",
883 P_("Which kind of shadow to draw around the entry when has-frame is set"),
884 GTK_TYPE_SHADOW_TYPE,
886 GTK_PARAM_READWRITE));
889 * GtkEntry:overwrite-mode:
891 * If text is overwritten when typing in the #GtkEntry.
895 g_object_class_install_property (gobject_class,
897 g_param_spec_boolean ("overwrite-mode",
898 P_("Overwrite mode"),
899 P_("Whether new text overwrites existing text"),
901 GTK_PARAM_READWRITE));
904 * GtkEntry:text-length:
906 * The length of the text in the #GtkEntry.
910 g_object_class_install_property (gobject_class,
912 g_param_spec_uint ("text-length",
914 P_("Length of the text currently in the entry"),
918 GTK_PARAM_READABLE));
920 * GtkEntry:invisible-char-set:
922 * Whether the invisible char has been set for the #GtkEntry.
926 g_object_class_install_property (gobject_class,
927 PROP_INVISIBLE_CHAR_SET,
928 g_param_spec_boolean ("invisible-char-set",
929 P_("Invisible character set"),
930 P_("Whether the invisible character has been set"),
932 GTK_PARAM_READWRITE));
935 * GtkEntry:caps-lock-warning
937 * Whether password entries will show a warning when Caps Lock is on.
939 * Note that the warning is shown using a secondary icon, and thus
940 * does not work if you are using the secondary icon position for some
945 g_object_class_install_property (gobject_class,
946 PROP_CAPS_LOCK_WARNING,
947 g_param_spec_boolean ("caps-lock-warning",
948 P_("Caps Lock warning"),
949 P_("Whether password entries will show a warning when Caps Lock is on"),
951 GTK_PARAM_READWRITE));
954 * GtkEntry:progress-fraction:
956 * The current fraction of the task that's been completed.
960 g_object_class_install_property (gobject_class,
961 PROP_PROGRESS_FRACTION,
962 g_param_spec_double ("progress-fraction",
963 P_("Progress Fraction"),
964 P_("The current fraction of the task that's been completed"),
968 GTK_PARAM_READWRITE));
971 * GtkEntry:progress-pulse-step:
973 * The fraction of total entry width to move the progress
974 * bouncing block for each call to gtk_entry_progress_pulse().
978 g_object_class_install_property (gobject_class,
979 PROP_PROGRESS_PULSE_STEP,
980 g_param_spec_double ("progress-pulse-step",
981 P_("Progress Pulse Step"),
982 P_("The fraction of total entry width to move the progress bouncing block for each call to gtk_entry_progress_pulse()"),
986 GTK_PARAM_READWRITE));
989 * GtkEntry:placeholder-text:
991 * The text that will be displayed in the #GtkEntry when it is empty and unfocused.
995 g_object_class_install_property (gobject_class,
996 PROP_PLACEHOLDER_TEXT,
997 g_param_spec_string ("placeholder-text",
998 P_("Placeholder text"),
999 P_("Show text in the entry when it's empty and unfocused"),
1001 GTK_PARAM_READWRITE));
1004 * GtkEntry:primary-icon-pixbuf:
1006 * A pixbuf to use as the primary icon for the entry.
1010 g_object_class_install_property (gobject_class,
1011 PROP_PIXBUF_PRIMARY,
1012 g_param_spec_object ("primary-icon-pixbuf",
1013 P_("Primary pixbuf"),
1014 P_("Primary pixbuf for the entry"),
1016 GTK_PARAM_READWRITE));
1019 * GtkEntry:secondary-icon-pixbuf:
1021 * An pixbuf to use as the secondary icon for the entry.
1025 g_object_class_install_property (gobject_class,
1026 PROP_PIXBUF_SECONDARY,
1027 g_param_spec_object ("secondary-icon-pixbuf",
1028 P_("Secondary pixbuf"),
1029 P_("Secondary pixbuf for the entry"),
1031 GTK_PARAM_READWRITE));
1034 * GtkEntry:primary-icon-stock:
1036 * The stock id to use for the primary icon for the entry.
1040 g_object_class_install_property (gobject_class,
1042 g_param_spec_string ("primary-icon-stock",
1043 P_("Primary stock ID"),
1044 P_("Stock ID for primary icon"),
1046 GTK_PARAM_READWRITE));
1049 * GtkEntry:secondary-icon-stock:
1051 * The stock id to use for the secondary icon for the entry.
1055 g_object_class_install_property (gobject_class,
1056 PROP_STOCK_SECONDARY,
1057 g_param_spec_string ("secondary-icon-stock",
1058 P_("Secondary stock ID"),
1059 P_("Stock ID for secondary icon"),
1061 GTK_PARAM_READWRITE));
1064 * GtkEntry:primary-icon-name:
1066 * The icon name to use for the primary icon for the entry.
1070 g_object_class_install_property (gobject_class,
1071 PROP_ICON_NAME_PRIMARY,
1072 g_param_spec_string ("primary-icon-name",
1073 P_("Primary icon name"),
1074 P_("Icon name for primary icon"),
1076 GTK_PARAM_READWRITE));
1079 * GtkEntry:secondary-icon-name:
1081 * The icon name to use for the secondary icon for the entry.
1085 g_object_class_install_property (gobject_class,
1086 PROP_ICON_NAME_SECONDARY,
1087 g_param_spec_string ("secondary-icon-name",
1088 P_("Secondary icon name"),
1089 P_("Icon name for secondary icon"),
1091 GTK_PARAM_READWRITE));
1094 * GtkEntry:primary-icon-gicon:
1096 * The #GIcon to use for the primary icon for the entry.
1100 g_object_class_install_property (gobject_class,
1102 g_param_spec_object ("primary-icon-gicon",
1103 P_("Primary GIcon"),
1104 P_("GIcon for primary icon"),
1106 GTK_PARAM_READWRITE));
1109 * GtkEntry:secondary-icon-gicon:
1111 * The #GIcon to use for the secondary icon for the entry.
1115 g_object_class_install_property (gobject_class,
1116 PROP_GICON_SECONDARY,
1117 g_param_spec_object ("secondary-icon-gicon",
1118 P_("Secondary GIcon"),
1119 P_("GIcon for secondary icon"),
1121 GTK_PARAM_READWRITE));
1124 * GtkEntry:primary-icon-storage-type:
1126 * The representation which is used for the primary icon of the entry.
1130 g_object_class_install_property (gobject_class,
1131 PROP_STORAGE_TYPE_PRIMARY,
1132 g_param_spec_enum ("primary-icon-storage-type",
1133 P_("Primary storage type"),
1134 P_("The representation being used for primary icon"),
1135 GTK_TYPE_IMAGE_TYPE,
1137 GTK_PARAM_READABLE));
1140 * GtkEntry:secondary-icon-storage-type:
1142 * The representation which is used for the secondary icon of the entry.
1146 g_object_class_install_property (gobject_class,
1147 PROP_STORAGE_TYPE_SECONDARY,
1148 g_param_spec_enum ("secondary-icon-storage-type",
1149 P_("Secondary storage type"),
1150 P_("The representation being used for secondary icon"),
1151 GTK_TYPE_IMAGE_TYPE,
1153 GTK_PARAM_READABLE));
1156 * GtkEntry:primary-icon-activatable:
1158 * Whether the primary icon is activatable.
1160 * GTK+ emits the #GtkEntry::icon-press and #GtkEntry::icon-release
1161 * signals only on sensitive, activatable icons.
1163 * Sensitive, but non-activatable icons can be used for purely
1164 * informational purposes.
1168 g_object_class_install_property (gobject_class,
1169 PROP_ACTIVATABLE_PRIMARY,
1170 g_param_spec_boolean ("primary-icon-activatable",
1171 P_("Primary icon activatable"),
1172 P_("Whether the primary icon is activatable"),
1174 GTK_PARAM_READWRITE));
1177 * GtkEntry:secondary-icon-activatable:
1179 * Whether the secondary icon is activatable.
1181 * GTK+ emits the #GtkEntry::icon-press and #GtkEntry::icon-release
1182 * signals only on sensitive, activatable icons.
1184 * Sensitive, but non-activatable icons can be used for purely
1185 * informational purposes.
1189 g_object_class_install_property (gobject_class,
1190 PROP_ACTIVATABLE_SECONDARY,
1191 g_param_spec_boolean ("secondary-icon-activatable",
1192 P_("Secondary icon activatable"),
1193 P_("Whether the secondary icon is activatable"),
1195 GTK_PARAM_READWRITE));
1199 * GtkEntry:primary-icon-sensitive:
1201 * Whether the primary icon is sensitive.
1203 * An insensitive icon appears grayed out. GTK+ does not emit the
1204 * #GtkEntry::icon-press and #GtkEntry::icon-release signals and
1205 * does not allow DND from insensitive icons.
1207 * An icon should be set insensitive if the action that would trigger
1208 * when clicked is currently not available.
1212 g_object_class_install_property (gobject_class,
1213 PROP_SENSITIVE_PRIMARY,
1214 g_param_spec_boolean ("primary-icon-sensitive",
1215 P_("Primary icon sensitive"),
1216 P_("Whether the primary icon is sensitive"),
1218 GTK_PARAM_READWRITE));
1221 * GtkEntry:secondary-icon-sensitive:
1223 * Whether the secondary icon is sensitive.
1225 * An insensitive icon appears grayed out. GTK+ does not emit the
1226 * #GtkEntry::icon-press and #GtkEntry::icon-release signals and
1227 * does not allow DND from insensitive icons.
1229 * An icon should be set insensitive if the action that would trigger
1230 * when clicked is currently not available.
1234 g_object_class_install_property (gobject_class,
1235 PROP_SENSITIVE_SECONDARY,
1236 g_param_spec_boolean ("secondary-icon-sensitive",
1237 P_("Secondary icon sensitive"),
1238 P_("Whether the secondary icon is sensitive"),
1240 GTK_PARAM_READWRITE));
1243 * GtkEntry:primary-icon-tooltip-text:
1245 * The contents of the tooltip on the primary icon.
1247 * Also see gtk_entry_set_icon_tooltip_text().
1251 g_object_class_install_property (gobject_class,
1252 PROP_TOOLTIP_TEXT_PRIMARY,
1253 g_param_spec_string ("primary-icon-tooltip-text",
1254 P_("Primary icon tooltip text"),
1255 P_("The contents of the tooltip on the primary icon"),
1257 GTK_PARAM_READWRITE));
1260 * GtkEntry:secondary-icon-tooltip-text:
1262 * The contents of the tooltip on the secondary icon.
1264 * Also see gtk_entry_set_icon_tooltip_text().
1268 g_object_class_install_property (gobject_class,
1269 PROP_TOOLTIP_TEXT_SECONDARY,
1270 g_param_spec_string ("secondary-icon-tooltip-text",
1271 P_("Secondary icon tooltip text"),
1272 P_("The contents of the tooltip on the secondary icon"),
1274 GTK_PARAM_READWRITE));
1277 * GtkEntry:primary-icon-tooltip-markup:
1279 * The contents of the tooltip on the primary 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_PRIMARY,
1289 g_param_spec_string ("primary-icon-tooltip-markup",
1290 P_("Primary icon tooltip markup"),
1291 P_("The contents of the tooltip on the primary icon"),
1293 GTK_PARAM_READWRITE));
1296 * GtkEntry:secondary-icon-tooltip-markup:
1298 * The contents of the tooltip on the secondary icon, which is marked up
1299 * with the <link linkend="PangoMarkupFormat">Pango text markup
1302 * Also see gtk_entry_set_icon_tooltip_markup().
1306 g_object_class_install_property (gobject_class,
1307 PROP_TOOLTIP_MARKUP_SECONDARY,
1308 g_param_spec_string ("secondary-icon-tooltip-markup",
1309 P_("Secondary icon tooltip markup"),
1310 P_("The contents of the tooltip on the secondary icon"),
1312 GTK_PARAM_READWRITE));
1315 * GtkEntry:im-module:
1317 * Which IM (input method) module should be used for this entry.
1318 * See #GtkIMContext.
1320 * Setting this to a non-%NULL value overrides the
1321 * system-wide IM module setting. See the GtkSettings
1322 * #GtkSettings:gtk-im-module property.
1326 g_object_class_install_property (gobject_class,
1328 g_param_spec_string ("im-module",
1330 P_("Which IM module should be used"),
1332 GTK_PARAM_READWRITE));
1335 * GtkEntry:completion:
1337 * The auxiliary completion object to use with the entry.
1341 g_object_class_install_property (gobject_class,
1343 g_param_spec_object ("completion",
1345 P_("The auxiliary completion object"),
1346 GTK_TYPE_ENTRY_COMPLETION,
1347 GTK_PARAM_READWRITE));
1350 * GtkEntry:icon-prelight:
1352 * The prelight style property determines whether activatable
1353 * icons prelight on mouseover.
1357 gtk_widget_class_install_style_property (widget_class,
1358 g_param_spec_boolean ("icon-prelight",
1359 P_("Icon Prelight"),
1360 P_("Whether activatable icons should prelight when hovered"),
1362 GTK_PARAM_READABLE));
1365 * GtkEntry:progress-border:
1367 * The border around the progress bar in the entry.
1371 gtk_widget_class_install_style_property (widget_class,
1372 g_param_spec_boxed ("progress-border",
1373 P_("Progress Border"),
1374 P_("Border around the progress bar"),
1376 GTK_PARAM_READABLE));
1379 * GtkEntry:invisible-char:
1381 * The invisible character is used when masking entry contents (in
1382 * \"password mode\")"). When it is not explicitly set with the
1383 * #GtkEntry::invisible-char property, GTK+ determines the character
1384 * to use from a list of possible candidates, depending on availability
1385 * in the current font.
1387 * This style property allows the theme to prepend a character
1388 * to the list of candidates.
1392 gtk_widget_class_install_style_property (widget_class,
1393 g_param_spec_unichar ("invisible-char",
1394 P_("Invisible character"),
1395 P_("The character to use when masking entry contents (in \"password mode\")"),
1397 GTK_PARAM_READABLE));
1400 * GtkEntry::populate-popup:
1401 * @entry: The entry on which the signal is emitted
1402 * @menu: the menu that is being populated
1404 * The ::populate-popup signal gets emitted before showing the
1405 * context menu of the entry.
1407 * If you need to add items to the context menu, connect
1408 * to this signal and append your menuitems to the @menu.
1410 signals[POPULATE_POPUP] =
1411 g_signal_new (I_("populate-popup"),
1412 G_OBJECT_CLASS_TYPE (gobject_class),
1414 G_STRUCT_OFFSET (GtkEntryClass, populate_popup),
1416 _gtk_marshal_VOID__OBJECT,
1420 /* Action signals */
1423 * GtkEntry::activate:
1424 * @entry: The entry on which the signal is emitted
1426 * A <link linkend="keybinding-signals">keybinding signal</link>
1427 * which gets emitted when the user activates the entry.
1429 * Applications should not connect to it, but may emit it with
1430 * g_signal_emit_by_name() if they need to control activation
1433 * The default bindings for this signal are all forms of the Enter key.
1436 g_signal_new (I_("activate"),
1437 G_OBJECT_CLASS_TYPE (gobject_class),
1438 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1439 G_STRUCT_OFFSET (GtkEntryClass, activate),
1441 _gtk_marshal_VOID__VOID,
1443 widget_class->activate_signal = signals[ACTIVATE];
1446 * GtkEntry::move-cursor:
1447 * @entry: the object which received the signal
1448 * @step: the granularity of the move, as a #GtkMovementStep
1449 * @count: the number of @step units to move
1450 * @extend_selection: %TRUE if the move should extend the selection
1452 * The ::move-cursor signal is a
1453 * <link linkend="keybinding-signals">keybinding signal</link>
1454 * which gets emitted when the user initiates a cursor movement.
1455 * If the cursor is not visible in @entry, this signal causes
1456 * the viewport to be moved instead.
1458 * Applications should not connect to it, but may emit it with
1459 * g_signal_emit_by_name() if they need to control the cursor
1462 * The default bindings for this signal come in two variants,
1463 * the variant with the Shift modifier extends the selection,
1464 * the variant without the Shift modifer does not.
1465 * There are too many key combinations to list them all here.
1467 * <listitem>Arrow keys move by individual characters/lines</listitem>
1468 * <listitem>Ctrl-arrow key combinations move by words/paragraphs</listitem>
1469 * <listitem>Home/End keys move to the ends of the buffer</listitem>
1472 signals[MOVE_CURSOR] =
1473 g_signal_new (I_("move-cursor"),
1474 G_OBJECT_CLASS_TYPE (gobject_class),
1475 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1476 G_STRUCT_OFFSET (GtkEntryClass, move_cursor),
1478 _gtk_marshal_VOID__ENUM_INT_BOOLEAN,
1480 GTK_TYPE_MOVEMENT_STEP,
1485 * GtkEntry::insert-at-cursor:
1486 * @entry: the object which received the signal
1487 * @string: the string to insert
1489 * The ::insert-at-cursor signal is a
1490 * <link linkend="keybinding-signals">keybinding signal</link>
1491 * which gets emitted when the user initiates the insertion of a
1492 * fixed string at the cursor.
1494 * This signal has no default bindings.
1496 signals[INSERT_AT_CURSOR] =
1497 g_signal_new (I_("insert-at-cursor"),
1498 G_OBJECT_CLASS_TYPE (gobject_class),
1499 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1500 G_STRUCT_OFFSET (GtkEntryClass, insert_at_cursor),
1502 _gtk_marshal_VOID__STRING,
1507 * GtkEntry::delete-from-cursor:
1508 * @entry: the object which received the signal
1509 * @type: the granularity of the deletion, as a #GtkDeleteType
1510 * @count: the number of @type units to delete
1512 * The ::delete-from-cursor signal is a
1513 * <link linkend="keybinding-signals">keybinding signal</link>
1514 * which gets emitted when the user initiates a text deletion.
1516 * If the @type is %GTK_DELETE_CHARS, GTK+ deletes the selection
1517 * if there is one, otherwise it deletes the requested number
1520 * The default bindings for this signal are
1521 * Delete for deleting a character and Ctrl-Delete for
1524 signals[DELETE_FROM_CURSOR] =
1525 g_signal_new (I_("delete-from-cursor"),
1526 G_OBJECT_CLASS_TYPE (gobject_class),
1527 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1528 G_STRUCT_OFFSET (GtkEntryClass, delete_from_cursor),
1530 _gtk_marshal_VOID__ENUM_INT,
1532 GTK_TYPE_DELETE_TYPE,
1536 * GtkEntry::backspace:
1537 * @entry: the object which received the signal
1539 * The ::backspace signal is a
1540 * <link linkend="keybinding-signals">keybinding signal</link>
1541 * which gets emitted when the user asks for it.
1543 * The default bindings for this signal are
1544 * Backspace and Shift-Backspace.
1546 signals[BACKSPACE] =
1547 g_signal_new (I_("backspace"),
1548 G_OBJECT_CLASS_TYPE (gobject_class),
1549 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1550 G_STRUCT_OFFSET (GtkEntryClass, backspace),
1552 _gtk_marshal_VOID__VOID,
1556 * GtkEntry::cut-clipboard:
1557 * @entry: the object which received the signal
1559 * The ::cut-clipboard signal is a
1560 * <link linkend="keybinding-signals">keybinding signal</link>
1561 * which gets emitted to cut the selection to the clipboard.
1563 * The default bindings for this signal are
1564 * Ctrl-x and Shift-Delete.
1566 signals[CUT_CLIPBOARD] =
1567 g_signal_new (I_("cut-clipboard"),
1568 G_OBJECT_CLASS_TYPE (gobject_class),
1569 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1570 G_STRUCT_OFFSET (GtkEntryClass, cut_clipboard),
1572 _gtk_marshal_VOID__VOID,
1576 * GtkEntry::copy-clipboard:
1577 * @entry: the object which received the signal
1579 * The ::copy-clipboard signal is a
1580 * <link linkend="keybinding-signals">keybinding signal</link>
1581 * which gets emitted to copy the selection to the clipboard.
1583 * The default bindings for this signal are
1584 * Ctrl-c and Ctrl-Insert.
1586 signals[COPY_CLIPBOARD] =
1587 g_signal_new (I_("copy-clipboard"),
1588 G_OBJECT_CLASS_TYPE (gobject_class),
1589 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1590 G_STRUCT_OFFSET (GtkEntryClass, copy_clipboard),
1592 _gtk_marshal_VOID__VOID,
1596 * GtkEntry::paste-clipboard:
1597 * @entry: the object which received the signal
1599 * The ::paste-clipboard signal is a
1600 * <link linkend="keybinding-signals">keybinding signal</link>
1601 * which gets emitted to paste the contents of the clipboard
1602 * into the text view.
1604 * The default bindings for this signal are
1605 * Ctrl-v and Shift-Insert.
1607 signals[PASTE_CLIPBOARD] =
1608 g_signal_new (I_("paste-clipboard"),
1609 G_OBJECT_CLASS_TYPE (gobject_class),
1610 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1611 G_STRUCT_OFFSET (GtkEntryClass, paste_clipboard),
1613 _gtk_marshal_VOID__VOID,
1617 * GtkEntry::toggle-overwrite:
1618 * @entry: the object which received the signal
1620 * The ::toggle-overwrite signal is a
1621 * <link linkend="keybinding-signals">keybinding signal</link>
1622 * which gets emitted to toggle the overwrite mode of the entry.
1624 * The default bindings for this signal is Insert.
1626 signals[TOGGLE_OVERWRITE] =
1627 g_signal_new (I_("toggle-overwrite"),
1628 G_OBJECT_CLASS_TYPE (gobject_class),
1629 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1630 G_STRUCT_OFFSET (GtkEntryClass, toggle_overwrite),
1632 _gtk_marshal_VOID__VOID,
1636 * GtkEntry::icon-press:
1637 * @entry: The entry on which the signal is emitted
1638 * @icon_pos: The position of the clicked icon
1639 * @event: (type Gdk.EventButton): the button press event
1641 * The ::icon-press signal is emitted when an activatable icon
1646 signals[ICON_PRESS] =
1647 g_signal_new (I_("icon-press"),
1648 G_TYPE_FROM_CLASS (gobject_class),
1652 _gtk_marshal_VOID__ENUM_BOXED,
1654 GTK_TYPE_ENTRY_ICON_POSITION,
1655 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1658 * GtkEntry::icon-release:
1659 * @entry: The entry on which the signal is emitted
1660 * @icon_pos: The position of the clicked icon
1661 * @event: (type Gdk.EventButton): the button release event
1663 * The ::icon-release signal is emitted on the button release from a
1664 * mouse click over an activatable icon.
1668 signals[ICON_RELEASE] =
1669 g_signal_new (I_("icon-release"),
1670 G_TYPE_FROM_CLASS (gobject_class),
1674 _gtk_marshal_VOID__ENUM_BOXED,
1676 GTK_TYPE_ENTRY_ICON_POSITION,
1677 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1680 * GtkEntry::preedit-changed:
1681 * @entry: the object which received the signal
1682 * @preedit: the current preedit string
1684 * If an input method is used, the typed text will not immediately
1685 * be committed to the buffer. So if you are interested in the text,
1686 * connect to this signal.
1690 signals[PREEDIT_CHANGED] =
1691 g_signal_new_class_handler (I_("preedit-changed"),
1692 G_OBJECT_CLASS_TYPE (gobject_class),
1693 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1696 _gtk_marshal_VOID__STRING,
1705 binding_set = gtk_binding_set_by_class (class);
1707 /* Moving the insertion point */
1708 add_move_binding (binding_set, GDK_KEY_Right, 0,
1709 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1711 add_move_binding (binding_set, GDK_KEY_Left, 0,
1712 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1714 add_move_binding (binding_set, GDK_KEY_KP_Right, 0,
1715 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1717 add_move_binding (binding_set, GDK_KEY_KP_Left, 0,
1718 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1720 add_move_binding (binding_set, GDK_KEY_Right, GDK_CONTROL_MASK,
1721 GTK_MOVEMENT_WORDS, 1);
1723 add_move_binding (binding_set, GDK_KEY_Left, GDK_CONTROL_MASK,
1724 GTK_MOVEMENT_WORDS, -1);
1726 add_move_binding (binding_set, GDK_KEY_KP_Right, GDK_CONTROL_MASK,
1727 GTK_MOVEMENT_WORDS, 1);
1729 add_move_binding (binding_set, GDK_KEY_KP_Left, GDK_CONTROL_MASK,
1730 GTK_MOVEMENT_WORDS, -1);
1732 add_move_binding (binding_set, GDK_KEY_Home, 0,
1733 GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
1735 add_move_binding (binding_set, GDK_KEY_End, 0,
1736 GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
1738 add_move_binding (binding_set, GDK_KEY_KP_Home, 0,
1739 GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
1741 add_move_binding (binding_set, GDK_KEY_KP_End, 0,
1742 GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
1744 add_move_binding (binding_set, GDK_KEY_Home, GDK_CONTROL_MASK,
1745 GTK_MOVEMENT_BUFFER_ENDS, -1);
1747 add_move_binding (binding_set, GDK_KEY_End, GDK_CONTROL_MASK,
1748 GTK_MOVEMENT_BUFFER_ENDS, 1);
1750 add_move_binding (binding_set, GDK_KEY_KP_Home, GDK_CONTROL_MASK,
1751 GTK_MOVEMENT_BUFFER_ENDS, -1);
1753 add_move_binding (binding_set, GDK_KEY_KP_End, GDK_CONTROL_MASK,
1754 GTK_MOVEMENT_BUFFER_ENDS, 1);
1758 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK,
1760 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1762 G_TYPE_BOOLEAN, FALSE);
1763 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK,
1765 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1767 G_TYPE_BOOLEAN, TRUE);
1769 gtk_binding_entry_add_signal (binding_set, GDK_KEY_slash, GDK_CONTROL_MASK,
1771 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1773 G_TYPE_BOOLEAN, FALSE);
1774 gtk_binding_entry_add_signal (binding_set, GDK_KEY_slash, GDK_CONTROL_MASK,
1776 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1778 G_TYPE_BOOLEAN, TRUE);
1781 gtk_binding_entry_add_signal (binding_set, GDK_KEY_backslash, GDK_CONTROL_MASK,
1783 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_VISUAL_POSITIONS,
1785 G_TYPE_BOOLEAN, FALSE);
1786 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_SHIFT_MASK | GDK_CONTROL_MASK,
1788 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_VISUAL_POSITIONS,
1790 G_TYPE_BOOLEAN, FALSE);
1794 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Return, 0,
1796 gtk_binding_entry_add_signal (binding_set, GDK_KEY_ISO_Enter, 0,
1798 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Enter, 0,
1802 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, 0,
1803 "delete-from-cursor", 2,
1804 G_TYPE_ENUM, GTK_DELETE_CHARS,
1807 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Delete, 0,
1808 "delete-from-cursor", 2,
1809 G_TYPE_ENUM, GTK_DELETE_CHARS,
1812 gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, 0,
1815 /* Make this do the same as Backspace, to help with mis-typing */
1816 gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, GDK_SHIFT_MASK,
1819 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, GDK_CONTROL_MASK,
1820 "delete-from-cursor", 2,
1821 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1824 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Delete, GDK_CONTROL_MASK,
1825 "delete-from-cursor", 2,
1826 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1829 gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, GDK_CONTROL_MASK,
1830 "delete-from-cursor", 2,
1831 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1834 /* Cut/copy/paste */
1836 gtk_binding_entry_add_signal (binding_set, GDK_KEY_x, GDK_CONTROL_MASK,
1837 "cut-clipboard", 0);
1838 gtk_binding_entry_add_signal (binding_set, GDK_KEY_c, GDK_CONTROL_MASK,
1839 "copy-clipboard", 0);
1840 gtk_binding_entry_add_signal (binding_set, GDK_KEY_v, GDK_CONTROL_MASK,
1841 "paste-clipboard", 0);
1843 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, GDK_SHIFT_MASK,
1844 "cut-clipboard", 0);
1845 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, GDK_CONTROL_MASK,
1846 "copy-clipboard", 0);
1847 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, GDK_SHIFT_MASK,
1848 "paste-clipboard", 0);
1851 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, 0,
1852 "toggle-overwrite", 0);
1853 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Insert, 0,
1854 "toggle-overwrite", 0);
1857 * GtkEntry:inner-border:
1859 * Sets the text area's border between the text and the frame.
1863 gtk_widget_class_install_style_property (widget_class,
1864 g_param_spec_boxed ("inner-border",
1866 P_("Border between text and frame."),
1868 GTK_PARAM_READABLE));
1870 g_type_class_add_private (gobject_class, sizeof (GtkEntryPrivate));
1874 gtk_entry_editable_init (GtkEditableInterface *iface)
1876 iface->do_insert_text = gtk_entry_insert_text;
1877 iface->do_delete_text = gtk_entry_delete_text;
1878 iface->insert_text = gtk_entry_real_insert_text;
1879 iface->delete_text = gtk_entry_real_delete_text;
1880 iface->get_chars = gtk_entry_get_chars;
1881 iface->set_selection_bounds = gtk_entry_set_selection_bounds;
1882 iface->get_selection_bounds = gtk_entry_get_selection_bounds;
1883 iface->set_position = gtk_entry_real_set_position;
1884 iface->get_position = gtk_entry_get_position;
1888 gtk_entry_cell_editable_init (GtkCellEditableIface *iface)
1890 iface->start_editing = gtk_entry_start_editing;
1894 gtk_entry_set_property (GObject *object,
1896 const GValue *value,
1899 GtkEntry *entry = GTK_ENTRY (object);
1900 GtkEntryPrivate *priv = entry->priv;
1905 gtk_entry_set_buffer (entry, g_value_get_object (value));
1910 gboolean new_value = g_value_get_boolean (value);
1912 if (new_value != priv->editable)
1914 GtkWidget *widget = GTK_WIDGET (entry);
1918 _gtk_entry_reset_im_context (entry);
1919 if (gtk_widget_has_focus (widget))
1920 gtk_im_context_focus_out (priv->im_context);
1922 priv->preedit_length = 0;
1923 priv->preedit_cursor = 0;
1926 priv->editable = new_value;
1928 if (new_value && gtk_widget_has_focus (widget))
1929 gtk_im_context_focus_in (priv->im_context);
1931 gtk_widget_queue_draw (widget);
1936 case PROP_MAX_LENGTH:
1937 gtk_entry_set_max_length (entry, g_value_get_int (value));
1940 case PROP_VISIBILITY:
1941 gtk_entry_set_visibility (entry, g_value_get_boolean (value));
1944 case PROP_HAS_FRAME:
1945 gtk_entry_set_has_frame (entry, g_value_get_boolean (value));
1948 case PROP_INNER_BORDER:
1949 gtk_entry_set_inner_border (entry, g_value_get_boxed (value));
1952 case PROP_INVISIBLE_CHAR:
1953 gtk_entry_set_invisible_char (entry, g_value_get_uint (value));
1956 case PROP_ACTIVATES_DEFAULT:
1957 gtk_entry_set_activates_default (entry, g_value_get_boolean (value));
1960 case PROP_WIDTH_CHARS:
1961 gtk_entry_set_width_chars (entry, g_value_get_int (value));
1965 gtk_entry_set_text (entry, g_value_get_string (value));
1969 gtk_entry_set_alignment (entry, g_value_get_float (value));
1972 case PROP_TRUNCATE_MULTILINE:
1973 priv->truncate_multiline = g_value_get_boolean (value);
1976 case PROP_SHADOW_TYPE:
1977 priv->shadow_type = g_value_get_enum (value);
1980 case PROP_OVERWRITE_MODE:
1981 gtk_entry_set_overwrite_mode (entry, g_value_get_boolean (value));
1984 case PROP_INVISIBLE_CHAR_SET:
1985 if (g_value_get_boolean (value))
1986 priv->invisible_char_set = TRUE;
1988 gtk_entry_unset_invisible_char (entry);
1991 case PROP_CAPS_LOCK_WARNING:
1992 priv->caps_lock_warning = g_value_get_boolean (value);
1995 case PROP_PROGRESS_FRACTION:
1996 gtk_entry_set_progress_fraction (entry, g_value_get_double (value));
1999 case PROP_PROGRESS_PULSE_STEP:
2000 gtk_entry_set_progress_pulse_step (entry, g_value_get_double (value));
2003 case PROP_PLACEHOLDER_TEXT:
2004 gtk_entry_set_placeholder_text (entry, g_value_get_string (value));
2007 case PROP_PIXBUF_PRIMARY:
2008 gtk_entry_set_icon_from_pixbuf (entry,
2009 GTK_ENTRY_ICON_PRIMARY,
2010 g_value_get_object (value));
2013 case PROP_PIXBUF_SECONDARY:
2014 gtk_entry_set_icon_from_pixbuf (entry,
2015 GTK_ENTRY_ICON_SECONDARY,
2016 g_value_get_object (value));
2019 case PROP_STOCK_PRIMARY:
2020 gtk_entry_set_icon_from_stock (entry,
2021 GTK_ENTRY_ICON_PRIMARY,
2022 g_value_get_string (value));
2025 case PROP_STOCK_SECONDARY:
2026 gtk_entry_set_icon_from_stock (entry,
2027 GTK_ENTRY_ICON_SECONDARY,
2028 g_value_get_string (value));
2031 case PROP_ICON_NAME_PRIMARY:
2032 gtk_entry_set_icon_from_icon_name (entry,
2033 GTK_ENTRY_ICON_PRIMARY,
2034 g_value_get_string (value));
2037 case PROP_ICON_NAME_SECONDARY:
2038 gtk_entry_set_icon_from_icon_name (entry,
2039 GTK_ENTRY_ICON_SECONDARY,
2040 g_value_get_string (value));
2043 case PROP_GICON_PRIMARY:
2044 gtk_entry_set_icon_from_gicon (entry,
2045 GTK_ENTRY_ICON_PRIMARY,
2046 g_value_get_object (value));
2049 case PROP_GICON_SECONDARY:
2050 gtk_entry_set_icon_from_gicon (entry,
2051 GTK_ENTRY_ICON_SECONDARY,
2052 g_value_get_object (value));
2055 case PROP_ACTIVATABLE_PRIMARY:
2056 gtk_entry_set_icon_activatable (entry,
2057 GTK_ENTRY_ICON_PRIMARY,
2058 g_value_get_boolean (value));
2061 case PROP_ACTIVATABLE_SECONDARY:
2062 gtk_entry_set_icon_activatable (entry,
2063 GTK_ENTRY_ICON_SECONDARY,
2064 g_value_get_boolean (value));
2067 case PROP_SENSITIVE_PRIMARY:
2068 gtk_entry_set_icon_sensitive (entry,
2069 GTK_ENTRY_ICON_PRIMARY,
2070 g_value_get_boolean (value));
2073 case PROP_SENSITIVE_SECONDARY:
2074 gtk_entry_set_icon_sensitive (entry,
2075 GTK_ENTRY_ICON_SECONDARY,
2076 g_value_get_boolean (value));
2079 case PROP_TOOLTIP_TEXT_PRIMARY:
2080 gtk_entry_set_icon_tooltip_text (entry,
2081 GTK_ENTRY_ICON_PRIMARY,
2082 g_value_get_string (value));
2085 case PROP_TOOLTIP_TEXT_SECONDARY:
2086 gtk_entry_set_icon_tooltip_text (entry,
2087 GTK_ENTRY_ICON_SECONDARY,
2088 g_value_get_string (value));
2091 case PROP_TOOLTIP_MARKUP_PRIMARY:
2092 gtk_entry_set_icon_tooltip_markup (entry,
2093 GTK_ENTRY_ICON_PRIMARY,
2094 g_value_get_string (value));
2097 case PROP_TOOLTIP_MARKUP_SECONDARY:
2098 gtk_entry_set_icon_tooltip_markup (entry,
2099 GTK_ENTRY_ICON_SECONDARY,
2100 g_value_get_string (value));
2103 case PROP_IM_MODULE:
2104 g_free (priv->im_module);
2105 priv->im_module = g_value_dup_string (value);
2106 if (GTK_IS_IM_MULTICONTEXT (priv->im_context))
2107 gtk_im_multicontext_set_context_id (GTK_IM_MULTICONTEXT (priv->im_context), priv->im_module);
2110 case PROP_EDITING_CANCELED:
2111 priv->editing_canceled = g_value_get_boolean (value);
2114 case PROP_COMPLETION:
2115 gtk_entry_set_completion (entry, GTK_ENTRY_COMPLETION (g_value_get_object (value)));
2118 case PROP_SCROLL_OFFSET:
2119 case PROP_CURSOR_POSITION:
2121 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2127 gtk_entry_get_property (GObject *object,
2132 GtkEntry *entry = GTK_ENTRY (object);
2133 GtkEntryPrivate *priv = entry->priv;
2138 g_value_set_object (value, gtk_entry_get_buffer (entry));
2141 case PROP_CURSOR_POSITION:
2142 g_value_set_int (value, priv->current_pos);
2145 case PROP_SELECTION_BOUND:
2146 g_value_set_int (value, priv->selection_bound);
2150 g_value_set_boolean (value, priv->editable);
2153 case PROP_MAX_LENGTH:
2154 g_value_set_int (value, gtk_entry_buffer_get_max_length (get_buffer (entry)));
2157 case PROP_VISIBILITY:
2158 g_value_set_boolean (value, priv->visible);
2161 case PROP_HAS_FRAME:
2162 g_value_set_boolean (value, priv->has_frame);
2165 case PROP_INNER_BORDER:
2166 g_value_set_boxed (value, gtk_entry_get_inner_border (entry));
2169 case PROP_INVISIBLE_CHAR:
2170 g_value_set_uint (value, priv->invisible_char);
2173 case PROP_ACTIVATES_DEFAULT:
2174 g_value_set_boolean (value, priv->activates_default);
2177 case PROP_WIDTH_CHARS:
2178 g_value_set_int (value, priv->width_chars);
2181 case PROP_SCROLL_OFFSET:
2182 g_value_set_int (value, priv->scroll_offset);
2186 g_value_set_string (value, gtk_entry_get_text (entry));
2190 g_value_set_float (value, gtk_entry_get_alignment (entry));
2193 case PROP_TRUNCATE_MULTILINE:
2194 g_value_set_boolean (value, priv->truncate_multiline);
2197 case PROP_SHADOW_TYPE:
2198 g_value_set_enum (value, priv->shadow_type);
2201 case PROP_OVERWRITE_MODE:
2202 g_value_set_boolean (value, priv->overwrite_mode);
2205 case PROP_TEXT_LENGTH:
2206 g_value_set_uint (value, gtk_entry_buffer_get_length (get_buffer (entry)));
2209 case PROP_INVISIBLE_CHAR_SET:
2210 g_value_set_boolean (value, priv->invisible_char_set);
2213 case PROP_IM_MODULE:
2214 g_value_set_string (value, priv->im_module);
2217 case PROP_CAPS_LOCK_WARNING:
2218 g_value_set_boolean (value, priv->caps_lock_warning);
2221 case PROP_PROGRESS_FRACTION:
2222 g_value_set_double (value, priv->progress_fraction);
2225 case PROP_PROGRESS_PULSE_STEP:
2226 g_value_set_double (value, priv->progress_pulse_fraction);
2229 case PROP_PLACEHOLDER_TEXT:
2230 g_value_set_string (value, gtk_entry_get_placeholder_text (entry));
2233 case PROP_PIXBUF_PRIMARY:
2234 g_value_set_object (value,
2235 gtk_entry_get_icon_pixbuf (entry,
2236 GTK_ENTRY_ICON_PRIMARY));
2239 case PROP_PIXBUF_SECONDARY:
2240 g_value_set_object (value,
2241 gtk_entry_get_icon_pixbuf (entry,
2242 GTK_ENTRY_ICON_SECONDARY));
2245 case PROP_STOCK_PRIMARY:
2246 g_value_set_string (value,
2247 gtk_entry_get_icon_stock (entry,
2248 GTK_ENTRY_ICON_PRIMARY));
2251 case PROP_STOCK_SECONDARY:
2252 g_value_set_string (value,
2253 gtk_entry_get_icon_stock (entry,
2254 GTK_ENTRY_ICON_SECONDARY));
2257 case PROP_ICON_NAME_PRIMARY:
2258 g_value_set_string (value,
2259 gtk_entry_get_icon_name (entry,
2260 GTK_ENTRY_ICON_PRIMARY));
2263 case PROP_ICON_NAME_SECONDARY:
2264 g_value_set_string (value,
2265 gtk_entry_get_icon_name (entry,
2266 GTK_ENTRY_ICON_SECONDARY));
2269 case PROP_GICON_PRIMARY:
2270 g_value_set_object (value,
2271 gtk_entry_get_icon_gicon (entry,
2272 GTK_ENTRY_ICON_PRIMARY));
2275 case PROP_GICON_SECONDARY:
2276 g_value_set_object (value,
2277 gtk_entry_get_icon_gicon (entry,
2278 GTK_ENTRY_ICON_SECONDARY));
2281 case PROP_STORAGE_TYPE_PRIMARY:
2282 g_value_set_enum (value,
2283 gtk_entry_get_icon_storage_type (entry,
2284 GTK_ENTRY_ICON_PRIMARY));
2287 case PROP_STORAGE_TYPE_SECONDARY:
2288 g_value_set_enum (value,
2289 gtk_entry_get_icon_storage_type (entry,
2290 GTK_ENTRY_ICON_SECONDARY));
2293 case PROP_ACTIVATABLE_PRIMARY:
2294 g_value_set_boolean (value,
2295 gtk_entry_get_icon_activatable (entry, GTK_ENTRY_ICON_PRIMARY));
2298 case PROP_ACTIVATABLE_SECONDARY:
2299 g_value_set_boolean (value,
2300 gtk_entry_get_icon_activatable (entry, GTK_ENTRY_ICON_SECONDARY));
2303 case PROP_SENSITIVE_PRIMARY:
2304 g_value_set_boolean (value,
2305 gtk_entry_get_icon_sensitive (entry, GTK_ENTRY_ICON_PRIMARY));
2308 case PROP_SENSITIVE_SECONDARY:
2309 g_value_set_boolean (value,
2310 gtk_entry_get_icon_sensitive (entry, GTK_ENTRY_ICON_SECONDARY));
2313 case PROP_TOOLTIP_TEXT_PRIMARY:
2314 g_value_take_string (value,
2315 gtk_entry_get_icon_tooltip_text (entry, GTK_ENTRY_ICON_PRIMARY));
2318 case PROP_TOOLTIP_TEXT_SECONDARY:
2319 g_value_take_string (value,
2320 gtk_entry_get_icon_tooltip_text (entry, GTK_ENTRY_ICON_SECONDARY));
2323 case PROP_TOOLTIP_MARKUP_PRIMARY:
2324 g_value_take_string (value,
2325 gtk_entry_get_icon_tooltip_markup (entry, GTK_ENTRY_ICON_PRIMARY));
2328 case PROP_TOOLTIP_MARKUP_SECONDARY:
2329 g_value_take_string (value,
2330 gtk_entry_get_icon_tooltip_markup (entry, GTK_ENTRY_ICON_SECONDARY));
2333 case PROP_EDITING_CANCELED:
2334 g_value_set_boolean (value,
2335 priv->editing_canceled);
2338 case PROP_COMPLETION:
2339 g_value_set_object (value, G_OBJECT (gtk_entry_get_completion (entry)));
2343 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2349 find_invisible_char (GtkWidget *widget)
2351 PangoLayout *layout;
2352 PangoAttrList *attr_list;
2354 gunichar invisible_chars [] = {
2356 0x25cf, /* BLACK CIRCLE */
2357 0x2022, /* BULLET */
2358 0x2731, /* HEAVY ASTERISK */
2359 0x273a /* SIXTEEN POINTED ASTERISK */
2362 gtk_widget_style_get (widget,
2363 "invisible-char", &invisible_chars[0],
2366 layout = gtk_widget_create_pango_layout (widget, NULL);
2368 attr_list = pango_attr_list_new ();
2369 pango_attr_list_insert (attr_list, pango_attr_fallback_new (FALSE));
2371 pango_layout_set_attributes (layout, attr_list);
2372 pango_attr_list_unref (attr_list);
2374 for (i = (invisible_chars[0] != 0 ? 0 : 1); i < G_N_ELEMENTS (invisible_chars); i++)
2376 gchar text[7] = { 0, };
2379 len = g_unichar_to_utf8 (invisible_chars[i], text);
2380 pango_layout_set_text (layout, text, len);
2382 count = pango_layout_get_unknown_glyphs_count (layout);
2386 g_object_unref (layout);
2387 return invisible_chars[i];
2391 g_object_unref (layout);
2397 gtk_entry_init (GtkEntry *entry)
2399 GtkStyleContext *context;
2400 GtkEntryPrivate *priv;
2402 entry->priv = G_TYPE_INSTANCE_GET_PRIVATE (entry,
2407 gtk_widget_set_can_focus (GTK_WIDGET (entry), TRUE);
2408 gtk_widget_set_has_window (GTK_WIDGET (entry), FALSE);
2410 priv->editable = TRUE;
2411 priv->visible = TRUE;
2412 priv->invisible_char = find_invisible_char (GTK_WIDGET (entry));
2413 priv->dnd_position = -1;
2414 priv->width_chars = -1;
2415 priv->is_cell_renderer = FALSE;
2416 priv->editing_canceled = FALSE;
2417 priv->has_frame = TRUE;
2418 priv->truncate_multiline = FALSE;
2419 priv->shadow_type = GTK_SHADOW_IN;
2421 priv->caps_lock_warning = TRUE;
2422 priv->caps_lock_warning_shown = FALSE;
2423 priv->progress_fraction = 0.0;
2424 priv->progress_pulse_fraction = 0.1;
2426 gtk_drag_dest_set (GTK_WIDGET (entry),
2427 GTK_DEST_DEFAULT_HIGHLIGHT,
2429 GDK_ACTION_COPY | GDK_ACTION_MOVE);
2430 gtk_drag_dest_add_text_targets (GTK_WIDGET (entry));
2432 /* This object is completely private. No external entity can gain a reference
2433 * to it; so we create it here and destroy it in finalize().
2435 priv->im_context = gtk_im_multicontext_new ();
2437 g_signal_connect (priv->im_context, "commit",
2438 G_CALLBACK (gtk_entry_commit_cb), entry);
2439 g_signal_connect (priv->im_context, "preedit-changed",
2440 G_CALLBACK (gtk_entry_preedit_changed_cb), entry);
2441 g_signal_connect (priv->im_context, "retrieve-surrounding",
2442 G_CALLBACK (gtk_entry_retrieve_surrounding_cb), entry);
2443 g_signal_connect (priv->im_context, "delete-surrounding",
2444 G_CALLBACK (gtk_entry_delete_surrounding_cb), entry);
2446 context = gtk_widget_get_style_context (GTK_WIDGET (entry));
2447 gtk_style_context_add_class (context, GTK_STYLE_CLASS_ENTRY);
2451 get_icon_width (GtkEntry *entry,
2452 GtkEntryIconPosition icon_pos)
2454 GtkEntryPrivate *priv = entry->priv;
2455 EntryIconInfo *icon_info = priv->icons[icon_pos];
2457 GtkSettings *settings;
2458 gint menu_icon_width;
2460 if (!icon_info || icon_info->pixbuf == NULL)
2463 screen = gtk_widget_get_screen (GTK_WIDGET (entry));
2464 settings = gtk_settings_get_for_screen (screen);
2466 gtk_icon_size_lookup_for_settings (settings, GTK_ICON_SIZE_MENU,
2467 &menu_icon_width, NULL);
2469 return MAX (gdk_pixbuf_get_width (icon_info->pixbuf), menu_icon_width);
2473 get_icon_allocations (GtkEntry *entry,
2474 GtkAllocation *primary,
2475 GtkAllocation *secondary)
2478 GtkEntryPrivate *priv = entry->priv;
2479 gint x, y, width, height;
2481 get_text_area_size (entry, &x, &y, &width, &height);
2483 if (gtk_widget_has_focus (GTK_WIDGET (entry)) && !priv->interior_focus)
2484 y += priv->focus_width;
2487 primary->height = height;
2488 primary->width = get_icon_width (entry, GTK_ENTRY_ICON_PRIMARY);
2489 if (primary->width > 0)
2490 primary->width += 2 * priv->icon_margin;
2493 secondary->height = height;
2494 secondary->width = get_icon_width (entry, GTK_ENTRY_ICON_SECONDARY);
2495 if (secondary->width > 0)
2496 secondary->width += 2 * priv->icon_margin;
2498 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
2500 primary->x = x + width - primary->width;
2506 secondary->x = x + width - secondary->width;
2512 begin_change (GtkEntry *entry)
2514 GtkEntryPrivate *priv = entry->priv;
2516 priv->change_count++;
2520 end_change (GtkEntry *entry)
2522 GtkEditable *editable = GTK_EDITABLE (entry);
2523 GtkEntryPrivate *priv = entry->priv;
2525 g_return_if_fail (priv->change_count > 0);
2527 priv->change_count--;
2529 if (priv->change_count == 0)
2531 if (priv->real_changed)
2533 g_signal_emit_by_name (editable, "changed");
2534 priv->real_changed = FALSE;
2540 emit_changed (GtkEntry *entry)
2542 GtkEditable *editable = GTK_EDITABLE (entry);
2543 GtkEntryPrivate *priv = entry->priv;
2545 if (priv->change_count == 0)
2546 g_signal_emit_by_name (editable, "changed");
2548 priv->real_changed = TRUE;
2552 gtk_entry_destroy (GtkWidget *widget)
2554 GtkEntry *entry = GTK_ENTRY (widget);
2555 GtkEntryPrivate *priv = entry->priv;
2557 priv->current_pos = priv->selection_bound = 0;
2558 _gtk_entry_reset_im_context (entry);
2559 gtk_entry_reset_layout (entry);
2561 if (priv->blink_timeout)
2563 g_source_remove (priv->blink_timeout);
2564 priv->blink_timeout = 0;
2567 if (priv->recompute_idle)
2569 g_source_remove (priv->recompute_idle);
2570 priv->recompute_idle = 0;
2573 GTK_WIDGET_CLASS (gtk_entry_parent_class)->destroy (widget);
2577 gtk_entry_dispose (GObject *object)
2579 GtkEntry *entry = GTK_ENTRY (object);
2580 GtkEntryPrivate *priv = entry->priv;
2582 gtk_entry_set_icon_from_pixbuf (entry, GTK_ENTRY_ICON_PRIMARY, NULL);
2583 gtk_entry_set_icon_tooltip_markup (entry, GTK_ENTRY_ICON_PRIMARY, NULL);
2584 gtk_entry_set_icon_from_pixbuf (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
2585 gtk_entry_set_icon_tooltip_markup (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
2589 buffer_disconnect_signals (entry);
2590 g_object_unref (priv->buffer);
2591 priv->buffer = NULL;
2594 G_OBJECT_CLASS (gtk_entry_parent_class)->dispose (object);
2598 gtk_entry_finalize (GObject *object)
2600 GtkEntry *entry = GTK_ENTRY (object);
2601 GtkEntryPrivate *priv = entry->priv;
2602 EntryIconInfo *icon_info = NULL;
2605 for (i = 0; i < MAX_ICONS; i++)
2607 if ((icon_info = priv->icons[i]) != NULL)
2609 if (icon_info->target_list != NULL)
2611 gtk_target_list_unref (icon_info->target_list);
2612 icon_info->target_list = NULL;
2615 g_slice_free (EntryIconInfo, icon_info);
2616 priv->icons[i] = NULL;
2620 gtk_entry_set_completion (entry, NULL);
2622 if (priv->cached_layout)
2623 g_object_unref (priv->cached_layout);
2625 g_object_unref (priv->im_context);
2627 if (priv->blink_timeout)
2628 g_source_remove (priv->blink_timeout);
2630 if (priv->recompute_idle)
2631 g_source_remove (priv->recompute_idle);
2633 g_free (priv->placeholder_text);
2634 g_free (priv->im_module);
2636 G_OBJECT_CLASS (gtk_entry_parent_class)->finalize (object);
2640 gtk_entry_get_display_mode (GtkEntry *entry)
2642 GtkEntryPrivate *priv = entry->priv;
2645 return DISPLAY_NORMAL;
2647 if (priv->invisible_char == 0 && priv->invisible_char_set)
2648 return DISPLAY_BLANK;
2650 return DISPLAY_INVISIBLE;
2654 gtk_entry_get_display_text (GtkEntry *entry,
2658 GtkEntryPasswordHint *password_hint;
2659 GtkEntryPrivate *priv;
2660 gunichar invisible_char;
2671 text = gtk_entry_buffer_get_text (get_buffer (entry));
2672 length = gtk_entry_buffer_get_length (get_buffer (entry));
2676 if (start_pos > length)
2679 if (end_pos <= start_pos)
2680 return g_strdup ("");
2681 else if (priv->visible)
2683 start = g_utf8_offset_to_pointer (text, start_pos);
2684 end = g_utf8_offset_to_pointer (start, end_pos - start_pos);
2685 return g_strndup (start, end - start);
2689 str = g_string_sized_new (length * 2);
2691 /* Figure out what our invisible char is and encode it */
2692 if (!priv->invisible_char)
2693 invisible_char = priv->invisible_char_set ? ' ' : '*';
2695 invisible_char = priv->invisible_char;
2696 char_len = g_unichar_to_utf8 (invisible_char, char_str);
2699 * Add hidden characters for each character in the text
2700 * buffer. If there is a password hint, then keep that
2701 * character visible.
2704 password_hint = g_object_get_qdata (G_OBJECT (entry), quark_password_hint);
2705 for (i = start_pos; i < end_pos; ++i)
2707 if (password_hint && i == password_hint->position)
2709 start = g_utf8_offset_to_pointer (text, i);
2710 g_string_append_len (str, start, g_utf8_next_char (start) - start);
2714 g_string_append_len (str, char_str, char_len);
2718 return g_string_free (str, FALSE);
2723 update_cursors (GtkWidget *widget)
2725 GtkEntry *entry = GTK_ENTRY (widget);
2726 GtkEntryPrivate *priv = entry->priv;
2727 EntryIconInfo *icon_info = NULL;
2728 GdkDisplay *display;
2732 for (i = 0; i < MAX_ICONS; i++)
2734 if ((icon_info = priv->icons[i]) != NULL)
2736 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
2737 gdk_window_show_unraised (icon_info->window);
2739 /* The icon windows are not children of the visible entry window,
2740 * thus we can't just inherit the xterm cursor. Slight complication
2741 * here is that for the entry, insensitive => arrow cursor, but for
2742 * an icon in a sensitive entry, insensitive => xterm cursor.
2744 if (gtk_widget_is_sensitive (widget) &&
2745 (icon_info->insensitive ||
2746 (icon_info->nonactivatable && icon_info->target_list == NULL)))
2748 display = gtk_widget_get_display (widget);
2749 cursor = gdk_cursor_new_for_display (display, GDK_XTERM);
2750 gdk_window_set_cursor (icon_info->window, cursor);
2751 g_object_unref (cursor);
2755 gdk_window_set_cursor (icon_info->window, NULL);
2762 realize_icon_info (GtkWidget *widget,
2763 GtkEntryIconPosition icon_pos)
2765 GtkEntry *entry = GTK_ENTRY (widget);
2766 GtkEntryPrivate *priv = entry->priv;
2767 EntryIconInfo *icon_info = priv->icons[icon_pos];
2768 GdkWindowAttr attributes;
2769 gint attributes_mask;
2771 g_return_if_fail (icon_info != NULL);
2775 attributes.width = 1;
2776 attributes.height = 1;
2777 attributes.window_type = GDK_WINDOW_CHILD;
2778 attributes.wclass = GDK_INPUT_ONLY;
2779 attributes.event_mask = gtk_widget_get_events (widget);
2780 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
2781 GDK_BUTTON_RELEASE_MASK |
2782 GDK_BUTTON1_MOTION_MASK |
2783 GDK_BUTTON3_MOTION_MASK |
2784 GDK_POINTER_MOTION_HINT_MASK |
2785 GDK_POINTER_MOTION_MASK |
2786 GDK_ENTER_NOTIFY_MASK |
2787 GDK_LEAVE_NOTIFY_MASK);
2788 attributes_mask = GDK_WA_X | GDK_WA_Y;
2790 icon_info->window = gdk_window_new (gtk_widget_get_window (widget),
2793 gdk_window_set_user_data (icon_info->window, widget);
2795 gtk_widget_queue_resize (widget);
2798 static EntryIconInfo*
2799 construct_icon_info (GtkWidget *widget,
2800 GtkEntryIconPosition icon_pos)
2802 GtkEntry *entry = GTK_ENTRY (widget);
2803 GtkEntryPrivate *priv = entry->priv;
2804 EntryIconInfo *icon_info;
2806 g_return_val_if_fail (priv->icons[icon_pos] == NULL, NULL);
2808 icon_info = g_slice_new0 (EntryIconInfo);
2809 priv->icons[icon_pos] = icon_info;
2811 if (gtk_widget_get_realized (widget))
2812 realize_icon_info (widget, icon_pos);
2818 gtk_entry_map (GtkWidget *widget)
2820 GtkEntry *entry = GTK_ENTRY (widget);
2821 GtkEntryPrivate *priv = entry->priv;
2822 EntryIconInfo *icon_info = NULL;
2825 GTK_WIDGET_CLASS (gtk_entry_parent_class)->map (widget);
2827 gdk_window_show (priv->text_area);
2829 for (i = 0; i < MAX_ICONS; i++)
2831 if ((icon_info = priv->icons[i]) != NULL)
2833 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
2834 gdk_window_show (icon_info->window);
2838 update_cursors (widget);
2842 gtk_entry_unmap (GtkWidget *widget)
2844 GtkEntry *entry = GTK_ENTRY (widget);
2845 GtkEntryPrivate *priv = entry->priv;
2846 EntryIconInfo *icon_info = NULL;
2849 for (i = 0; i < MAX_ICONS; i++)
2851 if ((icon_info = priv->icons[i]) != NULL)
2853 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
2854 gdk_window_hide (icon_info->window);
2858 gdk_window_hide (priv->text_area);
2860 GTK_WIDGET_CLASS (gtk_entry_parent_class)->unmap (widget);
2864 gtk_entry_realize (GtkWidget *widget)
2867 GtkEntryPrivate *priv;
2868 EntryIconInfo *icon_info;
2870 GdkWindowAttr attributes;
2871 gint attributes_mask;
2872 gint frame_x, frame_y;
2875 gtk_widget_set_realized (widget, TRUE);
2876 window = gtk_widget_get_parent_window (widget);
2877 gtk_widget_set_window (widget, window);
2878 g_object_ref (window);
2880 entry = GTK_ENTRY (widget);
2883 attributes.window_type = GDK_WINDOW_CHILD;
2884 attributes.wclass = GDK_INPUT_ONLY;
2885 attributes.event_mask = gtk_widget_get_events (widget);
2886 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
2887 GDK_BUTTON_RELEASE_MASK |
2888 GDK_BUTTON1_MOTION_MASK |
2889 GDK_BUTTON3_MOTION_MASK |
2890 GDK_POINTER_MOTION_HINT_MASK |
2891 GDK_POINTER_MOTION_MASK |
2892 GDK_ENTER_NOTIFY_MASK |
2893 GDK_LEAVE_NOTIFY_MASK);
2894 attributes_mask = GDK_WA_X | GDK_WA_Y;
2896 get_text_area_size (entry, &attributes.x, &attributes.y, &attributes.width, &attributes.height);
2898 get_frame_size (entry, TRUE, &frame_x, &frame_y, NULL, NULL);
2899 attributes.x += frame_x;
2900 attributes.y += frame_y;
2902 if (gtk_widget_is_sensitive (widget))
2904 attributes.cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
2905 attributes_mask |= GDK_WA_CURSOR;
2908 priv->text_area = gdk_window_new (gtk_widget_get_window (widget),
2912 gdk_window_set_user_data (priv->text_area, entry);
2914 if (attributes_mask & GDK_WA_CURSOR)
2915 g_object_unref (attributes.cursor);
2917 gtk_im_context_set_client_window (priv->im_context, priv->text_area);
2919 gtk_entry_adjust_scroll (entry);
2920 gtk_entry_update_primary_selection (entry);
2923 /* If the icon positions are already setup, create their windows.
2924 * Otherwise if they don't exist yet, then construct_icon_info()
2925 * will create the windows once the widget is already realized.
2927 for (i = 0; i < MAX_ICONS; i++)
2929 if ((icon_info = priv->icons[i]) != NULL)
2931 if (icon_info->window == NULL)
2932 realize_icon_info (widget, i);
2938 gtk_entry_unrealize (GtkWidget *widget)
2940 GtkEntry *entry = GTK_ENTRY (widget);
2941 GtkEntryPrivate *priv = entry->priv;
2942 GtkClipboard *clipboard;
2943 EntryIconInfo *icon_info;
2946 gtk_entry_reset_layout (entry);
2948 gtk_im_context_set_client_window (priv->im_context, NULL);
2950 clipboard = gtk_widget_get_clipboard (widget, GDK_SELECTION_PRIMARY);
2951 if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (entry))
2952 gtk_clipboard_clear (clipboard);
2954 if (priv->text_area)
2956 gdk_window_set_user_data (priv->text_area, NULL);
2957 gdk_window_destroy (priv->text_area);
2958 priv->text_area = NULL;
2961 if (priv->popup_menu)
2963 gtk_widget_destroy (priv->popup_menu);
2964 priv->popup_menu = NULL;
2967 GTK_WIDGET_CLASS (gtk_entry_parent_class)->unrealize (widget);
2969 for (i = 0; i < MAX_ICONS; i++)
2971 if ((icon_info = priv->icons[i]) != NULL)
2973 if (icon_info->window != NULL)
2975 gdk_window_destroy (icon_info->window);
2976 icon_info->window = NULL;
2983 _gtk_entry_get_borders (GtkEntry *entry,
2987 GtkEntryPrivate *priv = entry->priv;
2988 GtkWidget *widget = GTK_WIDGET (entry);
2990 if (priv->has_frame)
2992 GtkStyleContext *context;
2995 context = gtk_widget_get_style_context (widget);
2996 gtk_style_context_get_padding (context, 0, &padding);
2998 *xborder = padding.left;
2999 *yborder = padding.top;
3007 if (!priv->interior_focus)
3009 *xborder += priv->focus_width;
3010 *yborder += priv->focus_width;
3015 gtk_entry_get_preferred_width (GtkWidget *widget,
3019 GtkEntry *entry = GTK_ENTRY (widget);
3020 GtkEntryPrivate *priv = entry->priv;
3021 PangoFontMetrics *metrics;
3022 gint xborder, yborder;
3023 GtkBorder inner_border;
3024 PangoContext *context;
3025 GtkStyleContext *style_context;
3026 GtkStateFlags state;
3027 gint icon_widths = 0;
3031 context = gtk_widget_get_pango_context (widget);
3033 style_context = gtk_widget_get_style_context (widget);
3034 state = gtk_widget_get_state_flags (widget);
3036 metrics = pango_context_get_metrics (context,
3037 gtk_style_context_get_font (style_context, state),
3038 pango_context_get_language (context));
3040 _gtk_entry_get_borders (entry, &xborder, &yborder);
3041 _gtk_entry_effective_inner_border (entry, &inner_border);
3043 if (priv->width_chars < 0)
3044 width = MIN_ENTRY_WIDTH + xborder * 2 + inner_border.left + inner_border.right;
3047 gint char_width = pango_font_metrics_get_approximate_char_width (metrics);
3048 gint digit_width = pango_font_metrics_get_approximate_digit_width (metrics);
3049 gint char_pixels = (MAX (char_width, digit_width) + PANGO_SCALE - 1) / PANGO_SCALE;
3051 width = char_pixels * priv->width_chars + xborder * 2 + inner_border.left + inner_border.right;
3054 for (i = 0; i < MAX_ICONS; i++)
3056 icon_width = get_icon_width (entry, i);
3058 icon_widths += icon_width + 2 * priv->icon_margin;
3061 if (icon_widths > width)
3062 width += icon_widths;
3064 pango_font_metrics_unref (metrics);
3071 gtk_entry_get_preferred_height (GtkWidget *widget,
3075 GtkEntry *entry = GTK_ENTRY (widget);
3076 GtkEntryPrivate *priv = entry->priv;
3077 PangoFontMetrics *metrics;
3078 gint xborder, yborder;
3079 GtkBorder inner_border;
3080 GtkStyleContext *style_context;
3081 GtkStateFlags state;
3082 PangoContext *context;
3085 context = gtk_widget_get_pango_context (widget);
3087 style_context = gtk_widget_get_style_context (widget);
3088 state = gtk_widget_get_state_flags (widget);
3090 metrics = pango_context_get_metrics (context,
3091 gtk_style_context_get_font (style_context, state),
3092 pango_context_get_language (context));
3094 priv->ascent = pango_font_metrics_get_ascent (metrics);
3095 priv->descent = pango_font_metrics_get_descent (metrics);
3097 _gtk_entry_get_borders (entry, &xborder, &yborder);
3098 _gtk_entry_effective_inner_border (entry, &inner_border);
3100 height = PANGO_PIXELS (priv->ascent + priv->descent) + yborder * 2 + inner_border.top + inner_border.bottom;
3102 pango_font_metrics_unref (metrics);
3109 place_windows (GtkEntry *entry)
3111 GtkWidget *widget = GTK_WIDGET (entry);
3112 GtkEntryPrivate *priv = entry->priv;
3113 gint x, y, width, height;
3114 gint frame_x, frame_y;
3115 GtkAllocation primary;
3116 GtkAllocation secondary;
3117 EntryIconInfo *icon_info = NULL;
3119 get_frame_size (entry, TRUE, &frame_x, &frame_y, NULL, NULL);
3120 get_text_area_size (entry, &x, &y, &width, &height);
3121 get_icon_allocations (entry, &primary, &secondary);
3123 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3124 y += priv->focus_width;
3126 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
3127 x += secondary.width;
3130 width -= primary.width + secondary.width;
3134 primary.x += frame_x;
3135 primary.y += frame_y;
3136 secondary.x += frame_x;
3137 secondary.y += frame_y;
3139 if ((icon_info = priv->icons[GTK_ENTRY_ICON_PRIMARY]) != NULL)
3140 gdk_window_move_resize (icon_info->window,
3141 primary.x, primary.y,
3142 primary.width, primary.height);
3144 if ((icon_info = priv->icons[GTK_ENTRY_ICON_SECONDARY]) != NULL)
3145 gdk_window_move_resize (icon_info->window,
3146 secondary.x, secondary.y,
3147 secondary.width, secondary.height);
3149 gdk_window_move_resize (priv->text_area, x, y, width, height);
3153 gtk_entry_get_text_area_size (GtkEntry *entry,
3159 GtkEntryPrivate *priv = entry->priv;
3160 GtkWidget *widget = GTK_WIDGET (entry);
3161 GtkAllocation allocation;
3162 GtkRequisition requisition;
3164 gint xborder, yborder;
3166 gtk_widget_get_preferred_size (widget, &requisition, NULL);
3167 gtk_widget_get_allocation (widget, &allocation);
3168 _gtk_entry_get_borders (entry, &xborder, &yborder);
3170 if (gtk_widget_get_realized (widget))
3171 get_frame_size (entry, TRUE, NULL, NULL, NULL, &frame_height);
3173 frame_height = requisition.height;
3175 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3176 frame_height -= 2 * priv->focus_width;
3182 *y = frame_height / 2 - (requisition.height - yborder * 2) / 2;
3185 *width = allocation.width - xborder * 2;
3188 *height = requisition.height - yborder * 2;
3192 get_text_area_size (GtkEntry *entry,
3198 GtkEntryClass *class;
3200 g_return_if_fail (GTK_IS_ENTRY (entry));
3202 class = GTK_ENTRY_GET_CLASS (entry);
3204 if (class->get_text_area_size)
3205 class->get_text_area_size (entry, x, y, width, height);
3210 get_frame_size (GtkEntry *entry,
3211 gboolean relative_to_window,
3217 GtkEntryPrivate *priv = entry->priv;
3218 GtkAllocation allocation;
3219 GtkRequisition requisition;
3220 GtkWidget *widget = GTK_WIDGET (entry);
3222 gtk_widget_get_preferred_size (widget, &requisition, NULL);
3223 gtk_widget_get_allocation (widget, &allocation);
3226 *x = relative_to_window ? allocation.x : 0;
3230 if (priv->is_cell_renderer)
3233 *y = (allocation.height - requisition.height) / 2;
3235 if (relative_to_window)
3240 *width = allocation.width;
3244 if (priv->is_cell_renderer)
3245 *height = allocation.height;
3247 *height = requisition.height;
3252 _gtk_entry_effective_inner_border (GtkEntry *entry,
3255 GtkBorder *tmp_border;
3257 tmp_border = g_object_get_qdata (G_OBJECT (entry), quark_inner_border);
3261 *border = *tmp_border;
3265 gtk_widget_style_get (GTK_WIDGET (entry), "inner-border", &tmp_border, NULL);
3269 *border = *tmp_border;
3270 gtk_border_free (tmp_border);
3274 *border = default_inner_border;
3278 gtk_entry_size_allocate (GtkWidget *widget,
3279 GtkAllocation *allocation)
3281 GtkEntry *entry = GTK_ENTRY (widget);
3283 gtk_widget_set_allocation (widget, allocation);
3285 if (gtk_widget_get_realized (widget))
3287 GtkEntryCompletion* completion;
3289 place_windows (entry);
3290 gtk_entry_recompute (entry);
3292 completion = gtk_entry_get_completion (entry);
3293 if (completion && gtk_widget_get_mapped (completion->priv->popup_window))
3294 _gtk_entry_completion_resize_popup (completion);
3299 should_prelight (GtkEntry *entry,
3300 GtkEntryIconPosition icon_pos)
3302 GtkEntryPrivate *priv = entry->priv;
3303 EntryIconInfo *icon_info = priv->icons[icon_pos];
3309 if (icon_info->nonactivatable && icon_info->target_list == NULL)
3312 if (icon_info->pressed)
3315 gtk_widget_style_get (GTK_WIDGET (entry),
3316 "icon-prelight", &prelight,
3323 draw_icon (GtkWidget *widget,
3325 GtkEntryIconPosition icon_pos)
3327 GtkEntry *entry = GTK_ENTRY (widget);
3328 GtkEntryPrivate *priv = entry->priv;
3329 EntryIconInfo *icon_info = priv->icons[icon_pos];
3331 gint x, y, width, height;
3332 GtkStyleContext *context;
3333 GtkIconSource *icon_source;
3334 GtkStateFlags state;
3339 gtk_entry_ensure_pixbuf (entry, icon_pos);
3341 if (icon_info->pixbuf == NULL)
3344 width = gdk_window_get_width (icon_info->window);
3345 height = gdk_window_get_height (icon_info->window);
3347 /* size_allocate hasn't been called yet. These are the default values.
3349 if (width == 1 || height == 1)
3352 pixbuf = icon_info->pixbuf;
3353 g_object_ref (pixbuf);
3355 if (gdk_pixbuf_get_height (pixbuf) > height)
3357 GdkPixbuf *temp_pixbuf;
3360 scale = height - 2 * priv->icon_margin;
3361 temp_pixbuf = gdk_pixbuf_scale_simple (pixbuf, scale, scale,
3362 GDK_INTERP_BILINEAR);
3363 g_object_unref (pixbuf);
3364 pixbuf = temp_pixbuf;
3367 x = (width - gdk_pixbuf_get_width (pixbuf)) / 2;
3368 y = (height - gdk_pixbuf_get_height (pixbuf)) / 2;
3370 icon_source = gtk_icon_source_new ();
3371 gtk_icon_source_set_pixbuf (icon_source, pixbuf);
3372 gtk_icon_source_set_state_wildcarded (icon_source, TRUE);
3375 if (!gtk_widget_is_sensitive (widget) || icon_info->insensitive)
3376 state |= GTK_STATE_FLAG_INSENSITIVE;
3377 else if (icon_info->prelight)
3378 state |= GTK_STATE_FLAG_PRELIGHT;
3380 context = gtk_widget_get_style_context (widget);
3381 gtk_style_context_save (context);
3382 gtk_style_context_set_state (context, state);
3383 pixbuf = gtk_render_icon_pixbuf (context, icon_source, (GtkIconSize)-1);
3384 gtk_style_context_restore (context);
3386 gtk_icon_source_free (icon_source);
3388 gdk_cairo_set_source_pixbuf (cr, pixbuf, x, y);
3391 g_object_unref (pixbuf);
3396 gtk_entry_draw_frame (GtkWidget *widget,
3397 GtkStyleContext *context,
3400 GtkEntry *entry = GTK_ENTRY (widget);
3401 GtkEntryPrivate *priv = entry->priv;
3402 gint x = 0, y = 0, width, height;
3403 GtkAllocation allocation;
3404 gint frame_x, frame_y;
3408 get_frame_size (GTK_ENTRY (widget), TRUE, &frame_x, &frame_y, &width, &height);
3409 gtk_widget_get_allocation (widget, &allocation);
3411 cairo_translate (cr, frame_x - allocation.x, frame_y - allocation.y);
3413 /* Fix a problem with some themes which assume that entry->text_area's
3414 * width equals widget->window's width
3415 * http://bugzilla.gnome.org/show_bug.cgi?id=466000 */
3416 if (GTK_IS_SPIN_BUTTON (widget))
3418 gint xborder, yborder;
3420 gtk_entry_get_text_area_size (GTK_ENTRY (widget), &x, NULL, &width, NULL);
3421 _gtk_entry_get_borders (GTK_ENTRY (widget), &xborder, &yborder);
3424 width += xborder * 2;
3427 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3429 x += priv->focus_width;
3430 y += priv->focus_width;
3431 width -= 2 * priv->focus_width;
3432 height -= 2 * priv->focus_width;
3435 gtk_render_background (context, cr,
3436 x, y, width, height);
3438 if (priv->has_frame)
3439 gtk_render_frame (context, cr,
3440 x, y, width, height);
3442 gtk_entry_draw_progress (widget, context, cr);
3444 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3446 x -= priv->focus_width;
3447 y -= priv->focus_width;
3448 width += 2 * priv->focus_width;
3449 height += 2 * priv->focus_width;
3451 gtk_render_focus (context, cr,
3452 0, 0, width, height);
3459 get_progress_area (GtkWidget *widget,
3465 GtkEntry *entry = GTK_ENTRY (widget);
3466 GtkEntryPrivate *private = entry->priv;
3467 GtkBorder *progress_border;
3469 get_text_area_size (entry, x, y, width, height);
3471 if (!private->interior_focus)
3473 *x -= private->focus_width;
3474 *y -= private->focus_width;
3475 *width += 2 * private->focus_width;
3476 *height += 2 * private->focus_width;
3479 gtk_widget_style_get (widget, "progress-border", &progress_border, NULL);
3481 if (progress_border)
3483 *x += progress_border->left;
3484 *y += progress_border->top;
3485 *width -= progress_border->left + progress_border->right;
3486 *height -= progress_border->top + progress_border->bottom;
3488 gtk_border_free (progress_border);
3491 if (private->progress_pulse_mode)
3493 gdouble value = private->progress_pulse_current;
3495 *x += (gint) floor(value * (*width));
3496 *width = (gint) ceil(private->progress_pulse_fraction * (*width));
3498 else if (private->progress_fraction > 0)
3500 gdouble value = private->progress_fraction;
3502 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
3506 bar_width = floor(value * (*width) + 0.5);
3507 *x += *width - bar_width;
3512 *width = (gint) floor(value * (*width) + 0.5);
3523 gtk_entry_draw_progress (GtkWidget *widget,
3524 GtkStyleContext *context,
3527 gint x, y, width, height;
3529 get_progress_area (widget, &x, &y, &width, &height);
3531 if ((width <= 0) || (height <= 0))
3534 gtk_style_context_save (context);
3535 gtk_style_context_add_class (context, GTK_STYLE_CLASS_PROGRESSBAR);
3537 gtk_render_activity (context, cr,
3538 x, y, width, height);
3540 gtk_style_context_restore (context);
3544 gtk_entry_draw (GtkWidget *widget,
3547 GtkEntry *entry = GTK_ENTRY (widget);
3548 GtkStyleContext *context;
3549 GtkStateFlags state;
3550 GtkEntryPrivate *priv = entry->priv;
3553 context = gtk_widget_get_style_context (widget);
3554 state = gtk_widget_get_state_flags (widget);
3556 gtk_style_context_save (context);
3557 gtk_style_context_set_state (context, state);
3559 if (gtk_cairo_should_draw_window (cr, gtk_widget_get_window (widget)))
3561 /* Draw entry_bg, shadow, progress and focus */
3562 gtk_entry_draw_frame (widget, context, cr);
3564 /* Draw text and cursor */
3567 gtk_cairo_transform_to_window (cr, widget, priv->text_area);
3569 if (priv->dnd_position != -1)
3570 gtk_entry_draw_cursor (GTK_ENTRY (widget), cr, CURSOR_DND);
3572 gtk_entry_draw_text (GTK_ENTRY (widget), cr);
3574 /* When no text is being displayed at all, don't show the cursor */
3575 if (gtk_entry_get_display_mode (entry) != DISPLAY_BLANK &&
3576 gtk_widget_has_focus (widget) &&
3577 priv->selection_bound == priv->current_pos && priv->cursor_visible)
3578 gtk_entry_draw_cursor (GTK_ENTRY (widget), cr, CURSOR_STANDARD);
3583 for (i = 0; i < MAX_ICONS; i++)
3585 EntryIconInfo *icon_info = priv->icons[i];
3587 if (icon_info != NULL)
3591 gtk_cairo_transform_to_window (cr, widget, icon_info->window);
3593 draw_icon (widget, cr, i);
3600 gtk_style_context_restore (context);
3606 gtk_entry_enter_notify (GtkWidget *widget,
3607 GdkEventCrossing *event)
3609 GtkEntry *entry = GTK_ENTRY (widget);
3610 GtkEntryPrivate *priv = entry->priv;
3613 for (i = 0; i < MAX_ICONS; i++)
3615 EntryIconInfo *icon_info = priv->icons[i];
3617 if (icon_info != NULL && event->window == icon_info->window)
3619 if (should_prelight (entry, i))
3621 icon_info->prelight = TRUE;
3622 gtk_widget_queue_draw (widget);
3633 gtk_entry_leave_notify (GtkWidget *widget,
3634 GdkEventCrossing *event)
3636 GtkEntry *entry = GTK_ENTRY (widget);
3637 GtkEntryPrivate *priv = entry->priv;
3640 for (i = 0; i < MAX_ICONS; i++)
3642 EntryIconInfo *icon_info = priv->icons[i];
3644 if (icon_info != NULL && event->window == icon_info->window)
3646 /* a grab means that we may never see the button release */
3647 if (event->mode == GDK_CROSSING_GRAB || event->mode == GDK_CROSSING_GTK_GRAB)
3648 icon_info->pressed = FALSE;
3650 if (should_prelight (entry, i))
3652 icon_info->prelight = FALSE;
3653 gtk_widget_queue_draw (widget);
3664 gtk_entry_get_pixel_ranges (GtkEntry *entry,
3668 gint start_char, end_char;
3670 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start_char, &end_char))
3672 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
3673 PangoLayoutLine *line = pango_layout_get_lines_readonly (layout)->data;
3674 const char *text = pango_layout_get_text (layout);
3675 gint start_index = g_utf8_offset_to_pointer (text, start_char) - text;
3676 gint end_index = g_utf8_offset_to_pointer (text, end_char) - text;
3677 gint real_n_ranges, i;
3679 pango_layout_line_get_x_ranges (line, start_index, end_index, ranges, &real_n_ranges);
3685 for (i = 0; i < real_n_ranges; ++i)
3687 r[2 * i + 1] = (r[2 * i + 1] - r[2 * i]) / PANGO_SCALE;
3688 r[2 * i] = r[2 * i] / PANGO_SCALE;
3693 *n_ranges = real_n_ranges;
3705 in_selection (GtkEntry *entry,
3710 gint retval = FALSE;
3712 gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
3714 for (i = 0; i < n_ranges; ++i)
3716 if (x >= ranges[2 * i] && x < ranges[2 * i] + ranges[2 * i + 1])
3728 gtk_entry_button_press (GtkWidget *widget,
3729 GdkEventButton *event)
3731 GtkEntry *entry = GTK_ENTRY (widget);
3732 GtkEditable *editable = GTK_EDITABLE (widget);
3733 GtkEntryPrivate *priv = entry->priv;
3734 EntryIconInfo *icon_info = NULL;
3736 gint sel_start, sel_end;
3739 for (i = 0; i < MAX_ICONS; i++)
3741 icon_info = priv->icons[i];
3743 if (!icon_info || icon_info->insensitive)
3746 if (event->window == icon_info->window)
3748 if (should_prelight (entry, i))
3750 icon_info->prelight = FALSE;
3751 gtk_widget_queue_draw (widget);
3754 priv->start_x = event->x;
3755 priv->start_y = event->y;
3756 icon_info->pressed = TRUE;
3758 if (!icon_info->nonactivatable)
3759 g_signal_emit (entry, signals[ICON_PRESS], 0, i, event);
3765 if (event->window != priv->text_area ||
3766 (priv->button && event->button != priv->button))
3769 gtk_entry_reset_blink_time (entry);
3771 priv->button = event->button;
3773 if (!gtk_widget_has_focus (widget))
3775 priv->in_click = TRUE;
3776 gtk_widget_grab_focus (widget);
3777 priv->in_click = FALSE;
3780 tmp_pos = gtk_entry_find_position (entry, event->x + priv->scroll_offset);
3782 if (event->button == 1)
3784 gboolean have_selection = gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end);
3786 priv->select_words = FALSE;
3787 priv->select_lines = FALSE;
3789 if (event->state & GDK_SHIFT_MASK)
3791 _gtk_entry_reset_im_context (entry);
3793 if (!have_selection) /* select from the current position to the clicked position */
3794 sel_start = sel_end = priv->current_pos;
3796 if (tmp_pos > sel_start && tmp_pos < sel_end)
3798 /* Truncate current selection, but keep it as big as possible */
3799 if (tmp_pos - sel_start > sel_end - tmp_pos)
3800 gtk_entry_set_positions (entry, sel_start, tmp_pos);
3802 gtk_entry_set_positions (entry, tmp_pos, sel_end);
3806 gboolean extend_to_left;
3809 /* Figure out what click selects and extend current selection */
3810 switch (event->type)
3812 case GDK_BUTTON_PRESS:
3813 gtk_entry_set_positions (entry, tmp_pos, tmp_pos);
3816 case GDK_2BUTTON_PRESS:
3817 priv->select_words = TRUE;
3818 gtk_entry_select_word (entry);
3821 case GDK_3BUTTON_PRESS:
3822 priv->select_lines = TRUE;
3823 gtk_entry_select_line (entry);
3830 start = MIN (priv->current_pos, priv->selection_bound);
3831 start = MIN (sel_start, start);
3833 end = MAX (priv->current_pos, priv->selection_bound);
3834 end = MAX (sel_end, end);
3836 if (tmp_pos == sel_start || tmp_pos == sel_end)
3837 extend_to_left = (tmp_pos == start);
3839 extend_to_left = (end == sel_end);
3842 gtk_entry_set_positions (entry, start, end);
3844 gtk_entry_set_positions (entry, end, start);
3847 else /* no shift key */
3848 switch (event->type)
3850 case GDK_BUTTON_PRESS:
3851 if (in_selection (entry, event->x + priv->scroll_offset))
3853 /* Click inside the selection - we'll either start a drag, or
3854 * clear the selection
3856 priv->in_drag = TRUE;
3857 priv->drag_start_x = event->x + priv->scroll_offset;
3858 priv->drag_start_y = event->y;
3861 gtk_editable_set_position (editable, tmp_pos);
3864 case GDK_2BUTTON_PRESS:
3865 /* We ALWAYS receive a GDK_BUTTON_PRESS immediately before
3866 * receiving a GDK_2BUTTON_PRESS so we need to reset
3867 * priv->in_drag which may have been set above
3869 priv->in_drag = FALSE;
3870 priv->select_words = TRUE;
3871 gtk_entry_select_word (entry);
3874 case GDK_3BUTTON_PRESS:
3875 /* We ALWAYS receive a GDK_BUTTON_PRESS immediately before
3876 * receiving a GDK_3BUTTON_PRESS so we need to reset
3877 * priv->in_drag which may have been set above
3879 priv->in_drag = FALSE;
3880 priv->select_lines = TRUE;
3881 gtk_entry_select_line (entry);
3890 else if (event->button == 2 && event->type == GDK_BUTTON_PRESS)
3894 priv->insert_pos = tmp_pos;
3895 gtk_entry_paste (entry, GDK_SELECTION_PRIMARY);
3900 gtk_widget_error_bell (widget);
3903 else if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
3905 gtk_entry_do_popup (entry, event);
3906 priv->button = 0; /* Don't wait for release, since the menu will gtk_grab_add */
3915 gtk_entry_button_release (GtkWidget *widget,
3916 GdkEventButton *event)
3918 GtkEntry *entry = GTK_ENTRY (widget);
3919 GtkEntryPrivate *priv = entry->priv;
3920 EntryIconInfo *icon_info = NULL;
3923 for (i = 0; i < MAX_ICONS; i++)
3925 icon_info = priv->icons[i];
3927 if (!icon_info || icon_info->insensitive)
3930 if (event->window == icon_info->window)
3932 icon_info->pressed = FALSE;
3934 if (should_prelight (entry, i) &&
3935 event->x >= 0 && event->y >= 0 &&
3936 event->x < gdk_window_get_width (icon_info->window) &&
3937 event->y < gdk_window_get_height (icon_info->window))
3939 icon_info->prelight = TRUE;
3940 gtk_widget_queue_draw (widget);
3943 if (!icon_info->nonactivatable)
3944 g_signal_emit (entry, signals[ICON_RELEASE], 0, i, event);
3950 if (event->window != priv->text_area || priv->button != event->button)
3955 gint tmp_pos = gtk_entry_find_position (entry, priv->drag_start_x);
3957 gtk_editable_set_position (GTK_EDITABLE (entry), tmp_pos);
3964 gtk_entry_update_primary_selection (entry);
3970 _gtk_entry_get_selected_text (GtkEntry *entry)
3972 GtkEditable *editable = GTK_EDITABLE (entry);
3973 gint start_text, end_text;
3976 if (gtk_editable_get_selection_bounds (editable, &start_text, &end_text))
3977 text = gtk_editable_get_chars (editable, start_text, end_text);
3983 gtk_entry_motion_notify (GtkWidget *widget,
3984 GdkEventMotion *event)
3986 GtkEntry *entry = GTK_ENTRY (widget);
3987 GtkEntryPrivate *priv = entry->priv;
3988 EntryIconInfo *icon_info = NULL;
3992 for (i = 0; i < MAX_ICONS; i++)
3994 icon_info = priv->icons[i];
3996 if (!icon_info || icon_info->insensitive)
3999 if (event->window == icon_info->window)
4001 if (icon_info->pressed &&
4002 icon_info->target_list != NULL &&
4003 gtk_drag_check_threshold (widget,
4009 icon_info->in_drag = TRUE;
4010 icon_info->pressed = FALSE;
4011 gtk_drag_begin (widget,
4012 icon_info->target_list,
4022 if (priv->mouse_cursor_obscured)
4026 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
4027 gdk_window_set_cursor (priv->text_area, cursor);
4028 g_object_unref (cursor);
4029 priv->mouse_cursor_obscured = FALSE;
4032 if (event->window != priv->text_area || priv->button != 1)
4035 if (priv->select_lines)
4038 gdk_event_request_motions (event);
4042 if (gtk_entry_get_display_mode (entry) == DISPLAY_NORMAL &&
4043 gtk_drag_check_threshold (widget,
4044 priv->drag_start_x, priv->drag_start_y,
4045 event->x + priv->scroll_offset, event->y))
4047 GdkDragContext *context;
4048 GtkTargetList *target_list = gtk_target_list_new (NULL, 0);
4049 guint actions = priv->editable ? GDK_ACTION_COPY | GDK_ACTION_MOVE : GDK_ACTION_COPY;
4051 cairo_surface_t *surface;
4053 gtk_target_list_add_text_targets (target_list, 0);
4055 text = _gtk_entry_get_selected_text (entry);
4056 surface = _gtk_text_util_create_drag_icon (widget, text, -1);
4058 context = gtk_drag_begin (widget, target_list, actions,
4059 priv->button, (GdkEvent *)event);
4062 gtk_drag_set_icon_surface (context, surface);
4064 gtk_drag_set_icon_default (context);
4067 cairo_surface_destroy (surface);
4070 priv->in_drag = FALSE;
4073 gtk_target_list_unref (target_list);
4080 else if (event->y >= gdk_window_get_height (priv->text_area))
4081 tmp_pos = gtk_entry_buffer_get_length (get_buffer (entry));
4083 tmp_pos = gtk_entry_find_position (entry, event->x + priv->scroll_offset);
4085 if (priv->select_words)
4088 gint old_min, old_max;
4091 min = gtk_entry_move_backward_word (entry, tmp_pos, TRUE);
4092 max = gtk_entry_move_forward_word (entry, tmp_pos, TRUE);
4094 pos = priv->current_pos;
4095 bound = priv->selection_bound;
4097 old_min = MIN(priv->current_pos, priv->selection_bound);
4098 old_max = MAX(priv->current_pos, priv->selection_bound);
4105 else if (old_max < max)
4110 else if (pos == old_min)
4112 if (priv->current_pos != min)
4117 if (priv->current_pos != max)
4121 gtk_entry_set_positions (entry, pos, bound);
4124 gtk_entry_set_positions (entry, tmp_pos, -1);
4131 set_invisible_cursor (GdkWindow *window)
4133 GdkDisplay *display;
4136 display = gdk_window_get_display (window);
4137 cursor = gdk_cursor_new_for_display (display, GDK_BLANK_CURSOR);
4139 gdk_window_set_cursor (window, cursor);
4141 g_object_unref (cursor);
4145 gtk_entry_obscure_mouse_cursor (GtkEntry *entry)
4147 GtkEntryPrivate *priv = entry->priv;
4149 if (priv->mouse_cursor_obscured)
4152 set_invisible_cursor (priv->text_area);
4154 priv->mouse_cursor_obscured = TRUE;
4158 gtk_entry_key_press (GtkWidget *widget,
4161 GtkEntry *entry = GTK_ENTRY (widget);
4162 GtkEntryPrivate *priv = entry->priv;
4164 gtk_entry_reset_blink_time (entry);
4165 gtk_entry_pend_cursor_blink (entry);
4169 if (gtk_im_context_filter_keypress (priv->im_context, event))
4171 gtk_entry_obscure_mouse_cursor (entry);
4172 priv->need_im_reset = TRUE;
4177 if (event->keyval == GDK_KEY_Return ||
4178 event->keyval == GDK_KEY_KP_Enter ||
4179 event->keyval == GDK_KEY_ISO_Enter ||
4180 event->keyval == GDK_KEY_Escape)
4182 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
4184 if (completion && completion->priv->completion_timeout)
4186 g_source_remove (completion->priv->completion_timeout);
4187 completion->priv->completion_timeout = 0;
4190 _gtk_entry_reset_im_context (entry);
4193 if (GTK_WIDGET_CLASS (gtk_entry_parent_class)->key_press_event (widget, event))
4194 /* Activate key bindings
4198 if (!priv->editable && event->length)
4199 gtk_widget_error_bell (widget);
4205 gtk_entry_key_release (GtkWidget *widget,
4208 GtkEntry *entry = GTK_ENTRY (widget);
4209 GtkEntryPrivate *priv = entry->priv;
4213 if (gtk_im_context_filter_keypress (priv->im_context, event))
4215 priv->need_im_reset = TRUE;
4220 return GTK_WIDGET_CLASS (gtk_entry_parent_class)->key_release_event (widget, event);
4224 gtk_entry_focus_in (GtkWidget *widget,
4225 GdkEventFocus *event)
4227 GtkEntry *entry = GTK_ENTRY (widget);
4228 GtkEntryPrivate *priv = entry->priv;
4231 gtk_widget_queue_draw (widget);
4233 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (widget));
4237 priv->need_im_reset = TRUE;
4238 gtk_im_context_focus_in (priv->im_context);
4239 keymap_state_changed (keymap, entry);
4240 g_signal_connect (keymap, "state-changed",
4241 G_CALLBACK (keymap_state_changed), entry);
4244 g_signal_connect (keymap, "direction-changed",
4245 G_CALLBACK (keymap_direction_changed), entry);
4247 if (gtk_entry_buffer_get_bytes (get_buffer (entry)) == 0 &&
4248 priv->placeholder_text != NULL)
4250 gtk_entry_recompute (entry);
4254 gtk_entry_reset_blink_time (entry);
4255 gtk_entry_check_cursor_blink (entry);
4262 gtk_entry_focus_out (GtkWidget *widget,
4263 GdkEventFocus *event)
4265 GtkEntry *entry = GTK_ENTRY (widget);
4266 GtkEntryPrivate *priv = entry->priv;
4267 GtkEntryCompletion *completion;
4270 gtk_widget_queue_draw (widget);
4272 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (widget));
4276 priv->need_im_reset = TRUE;
4277 gtk_im_context_focus_out (priv->im_context);
4278 remove_capslock_feedback (entry);
4281 if (gtk_entry_buffer_get_bytes (get_buffer (entry)) == 0 &&
4282 priv->placeholder_text != NULL)
4284 gtk_entry_recompute (entry);
4288 gtk_entry_check_cursor_blink (entry);
4291 g_signal_handlers_disconnect_by_func (keymap, keymap_state_changed, entry);
4292 g_signal_handlers_disconnect_by_func (keymap, keymap_direction_changed, entry);
4294 completion = gtk_entry_get_completion (entry);
4296 _gtk_entry_completion_popdown (completion);
4302 gtk_entry_grab_focus (GtkWidget *widget)
4304 GtkEntry *entry = GTK_ENTRY (widget);
4305 GtkEntryPrivate *priv = entry->priv;
4306 gboolean select_on_focus;
4308 GTK_WIDGET_CLASS (gtk_entry_parent_class)->grab_focus (widget);
4310 if (priv->editable && !priv->in_click)
4312 g_object_get (gtk_widget_get_settings (widget),
4313 "gtk-entry-select-on-focus",
4317 if (select_on_focus)
4318 gtk_editable_select_region (GTK_EDITABLE (widget), 0, -1);
4323 gtk_entry_direction_changed (GtkWidget *widget,
4324 GtkTextDirection previous_dir)
4326 GtkEntry *entry = GTK_ENTRY (widget);
4328 gtk_entry_recompute (entry);
4330 GTK_WIDGET_CLASS (gtk_entry_parent_class)->direction_changed (widget, previous_dir);
4334 gtk_entry_state_flags_changed (GtkWidget *widget,
4335 GtkStateFlags previous_state)
4337 GtkEntry *entry = GTK_ENTRY (widget);
4338 GtkEntryPrivate *priv = entry->priv;
4341 if (gtk_widget_get_realized (widget))
4343 if (gtk_widget_is_sensitive (widget))
4344 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
4348 gdk_window_set_cursor (priv->text_area, cursor);
4351 g_object_unref (cursor);
4353 priv->mouse_cursor_obscured = FALSE;
4355 update_cursors (widget);
4358 if (!gtk_widget_is_sensitive (widget))
4360 /* Clear any selection */
4361 gtk_editable_select_region (GTK_EDITABLE (entry), priv->current_pos, priv->current_pos);
4364 gtk_widget_queue_draw (widget);
4368 gtk_entry_screen_changed (GtkWidget *widget,
4369 GdkScreen *old_screen)
4371 gtk_entry_recompute (GTK_ENTRY (widget));
4374 /* GtkEditable method implementations
4377 gtk_entry_insert_text (GtkEditable *editable,
4378 const gchar *new_text,
4379 gint new_text_length,
4382 g_object_ref (editable);
4385 * The incoming text may a password or other secret. We make sure
4386 * not to copy it into temporary buffers.
4389 g_signal_emit_by_name (editable, "insert-text", new_text, new_text_length, position);
4391 g_object_unref (editable);
4395 gtk_entry_delete_text (GtkEditable *editable,
4399 g_object_ref (editable);
4401 g_signal_emit_by_name (editable, "delete-text", start_pos, end_pos);
4403 g_object_unref (editable);
4407 gtk_entry_get_chars (GtkEditable *editable,
4411 GtkEntry *entry = GTK_ENTRY (editable);
4414 gint start_index, end_index;
4416 text = gtk_entry_buffer_get_text (get_buffer (entry));
4417 text_length = gtk_entry_buffer_get_length (get_buffer (entry));
4420 end_pos = text_length;
4422 start_pos = MIN (text_length, start_pos);
4423 end_pos = MIN (text_length, end_pos);
4425 start_index = g_utf8_offset_to_pointer (text, start_pos) - text;
4426 end_index = g_utf8_offset_to_pointer (text, end_pos) - text;
4428 return g_strndup (text + start_index, end_index - start_index);
4432 gtk_entry_real_set_position (GtkEditable *editable,
4435 GtkEntry *entry = GTK_ENTRY (editable);
4436 GtkEntryPrivate *priv = entry->priv;
4440 length = gtk_entry_buffer_get_length (get_buffer (entry));
4441 if (position < 0 || position > length)
4444 if (position != priv->current_pos ||
4445 position != priv->selection_bound)
4447 _gtk_entry_reset_im_context (entry);
4448 gtk_entry_set_positions (entry, position, position);
4453 gtk_entry_get_position (GtkEditable *editable)
4455 GtkEntry *entry = GTK_ENTRY (editable);
4456 GtkEntryPrivate *priv = entry->priv;
4458 return priv->current_pos;
4462 gtk_entry_set_selection_bounds (GtkEditable *editable,
4466 GtkEntry *entry = GTK_ENTRY (editable);
4469 length = gtk_entry_buffer_get_length (get_buffer (entry));
4475 _gtk_entry_reset_im_context (entry);
4477 gtk_entry_set_positions (entry,
4479 MIN (start, length));
4481 gtk_entry_update_primary_selection (entry);
4485 gtk_entry_get_selection_bounds (GtkEditable *editable,
4489 GtkEntry *entry = GTK_ENTRY (editable);
4490 GtkEntryPrivate *priv = entry->priv;
4492 *start = priv->selection_bound;
4493 *end = priv->current_pos;
4495 return (priv->selection_bound != priv->current_pos);
4499 icon_theme_changed (GtkEntry *entry)
4501 GtkEntryPrivate *priv = entry->priv;
4504 for (i = 0; i < MAX_ICONS; i++)
4506 EntryIconInfo *icon_info = priv->icons[i];
4507 if (icon_info != NULL)
4509 if (icon_info->storage_type == GTK_IMAGE_ICON_NAME)
4510 gtk_entry_set_icon_from_icon_name (entry, i, icon_info->icon_name);
4511 else if (icon_info->storage_type == GTK_IMAGE_STOCK)
4512 gtk_entry_set_icon_from_stock (entry, i, icon_info->stock_id);
4513 else if (icon_info->storage_type == GTK_IMAGE_GICON)
4514 gtk_entry_set_icon_from_gicon (entry, i, icon_info->gicon);
4518 gtk_widget_queue_draw (GTK_WIDGET (entry));
4522 icon_margin_changed (GtkEntry *entry)
4524 GtkEntryPrivate *priv = entry->priv;
4527 _gtk_entry_effective_inner_border (GTK_ENTRY (entry), &border);
4529 priv->icon_margin = border.left;
4533 gtk_entry_style_updated (GtkWidget *widget)
4535 GtkEntry *entry = GTK_ENTRY (widget);
4536 GtkEntryPrivate *priv = entry->priv;
4538 gboolean interior_focus;
4540 GTK_WIDGET_CLASS (gtk_entry_parent_class)->style_updated (widget);
4542 gtk_widget_style_get (widget,
4543 "focus-line-width", &focus_width,
4544 "interior-focus", &interior_focus,
4547 priv->focus_width = focus_width;
4548 priv->interior_focus = interior_focus;
4550 if (!priv->invisible_char_set)
4551 priv->invisible_char = find_invisible_char (GTK_WIDGET (entry));
4553 gtk_entry_recompute (entry);
4555 icon_theme_changed (entry);
4556 icon_margin_changed (entry);
4559 /* GtkCellEditable method implementations
4562 gtk_cell_editable_entry_activated (GtkEntry *entry, gpointer data)
4564 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4565 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4569 gtk_cell_editable_key_press_event (GtkEntry *entry,
4570 GdkEventKey *key_event,
4573 GtkEntryPrivate *priv = entry->priv;
4575 if (key_event->keyval == GDK_KEY_Escape)
4577 priv->editing_canceled = TRUE;
4578 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4579 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4584 /* override focus */
4585 if (key_event->keyval == GDK_KEY_Up || key_event->keyval == GDK_KEY_Down)
4587 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4588 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4597 gtk_entry_start_editing (GtkCellEditable *cell_editable,
4600 GtkEntry *entry = GTK_ENTRY (cell_editable);
4601 GtkEntryPrivate *priv = entry->priv;
4603 priv->is_cell_renderer = TRUE;
4605 g_signal_connect (cell_editable, "activate",
4606 G_CALLBACK (gtk_cell_editable_entry_activated), NULL);
4607 g_signal_connect (cell_editable, "key-press-event",
4608 G_CALLBACK (gtk_cell_editable_key_press_event), NULL);
4612 gtk_entry_password_hint_free (GtkEntryPasswordHint *password_hint)
4614 if (password_hint->source_id)
4615 g_source_remove (password_hint->source_id);
4617 g_slice_free (GtkEntryPasswordHint, password_hint);
4622 gtk_entry_remove_password_hint (gpointer data)
4624 GtkEntryPasswordHint *password_hint = g_object_get_qdata (data, quark_password_hint);
4625 password_hint->position = -1;
4627 /* Force the string to be redrawn, but now without a visible character */
4628 gtk_entry_recompute (GTK_ENTRY (data));
4632 /* Default signal handlers
4635 gtk_entry_real_insert_text (GtkEditable *editable,
4636 const gchar *new_text,
4637 gint new_text_length,
4643 n_chars = g_utf8_strlen (new_text, new_text_length);
4646 * The actual insertion into the buffer. This will end up firing the
4647 * following signal handlers: buffer_inserted_text(), buffer_notify_display_text(),
4648 * buffer_notify_text(), buffer_notify_length()
4650 n_inserted = gtk_entry_buffer_insert_text (get_buffer (GTK_ENTRY (editable)), *position, new_text, n_chars);
4652 if (n_inserted != n_chars)
4653 gtk_widget_error_bell (GTK_WIDGET (editable));
4655 *position += n_inserted;
4659 gtk_entry_real_delete_text (GtkEditable *editable,
4664 * The actual deletion from the buffer. This will end up firing the
4665 * following signal handlers: buffer_deleted_text(), buffer_notify_display_text(),
4666 * buffer_notify_text(), buffer_notify_length()
4669 gtk_entry_buffer_delete_text (get_buffer (GTK_ENTRY (editable)), start_pos, end_pos - start_pos);
4672 /* GtkEntryBuffer signal handlers
4675 buffer_inserted_text (GtkEntryBuffer *buffer,
4681 GtkEntryPrivate *priv = entry->priv;
4682 guint password_hint_timeout;
4684 if (priv->current_pos > position)
4685 priv->current_pos += n_chars;
4687 if (priv->selection_bound > position)
4688 priv->selection_bound += n_chars;
4690 /* Calculate the password hint if it needs to be displayed. */
4691 if (n_chars == 1 && !priv->visible)
4693 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
4694 "gtk-entry-password-hint-timeout", &password_hint_timeout,
4697 if (password_hint_timeout > 0)
4699 GtkEntryPasswordHint *password_hint = g_object_get_qdata (G_OBJECT (entry),
4700 quark_password_hint);
4703 password_hint = g_slice_new0 (GtkEntryPasswordHint);
4704 g_object_set_qdata_full (G_OBJECT (entry), quark_password_hint, password_hint,
4705 (GDestroyNotify)gtk_entry_password_hint_free);
4708 password_hint->position = position;
4709 if (password_hint->source_id)
4710 g_source_remove (password_hint->source_id);
4711 password_hint->source_id = gdk_threads_add_timeout (password_hint_timeout,
4712 (GSourceFunc)gtk_entry_remove_password_hint, entry);
4718 buffer_deleted_text (GtkEntryBuffer *buffer,
4723 GtkEntryPrivate *priv = entry->priv;
4724 guint end_pos = position + n_chars;
4725 gint selection_bound;
4728 current_pos = priv->current_pos;
4729 if (current_pos > position)
4730 current_pos -= MIN (current_pos, end_pos) - position;
4732 selection_bound = priv->selection_bound;
4733 if (selection_bound > position)
4734 selection_bound -= MIN (selection_bound, end_pos) - position;
4736 gtk_entry_set_positions (entry, current_pos, selection_bound);
4738 /* We might have deleted the selection */
4739 gtk_entry_update_primary_selection (entry);
4741 /* Disable the password hint if one exists. */
4744 GtkEntryPasswordHint *password_hint = g_object_get_qdata (G_OBJECT (entry),
4745 quark_password_hint);
4748 if (password_hint->source_id)
4749 g_source_remove (password_hint->source_id);
4750 password_hint->source_id = 0;
4751 password_hint->position = -1;
4757 buffer_notify_text (GtkEntryBuffer *buffer,
4761 gtk_entry_recompute (entry);
4762 emit_changed (entry);
4763 g_object_notify (G_OBJECT (entry), "text");
4767 buffer_notify_length (GtkEntryBuffer *buffer,
4771 g_object_notify (G_OBJECT (entry), "text-length");
4775 buffer_notify_max_length (GtkEntryBuffer *buffer,
4779 g_object_notify (G_OBJECT (entry), "max-length");
4783 buffer_connect_signals (GtkEntry *entry)
4785 g_signal_connect (get_buffer (entry), "inserted-text", G_CALLBACK (buffer_inserted_text), entry);
4786 g_signal_connect (get_buffer (entry), "deleted-text", G_CALLBACK (buffer_deleted_text), entry);
4787 g_signal_connect (get_buffer (entry), "notify::text", G_CALLBACK (buffer_notify_text), entry);
4788 g_signal_connect (get_buffer (entry), "notify::length", G_CALLBACK (buffer_notify_length), entry);
4789 g_signal_connect (get_buffer (entry), "notify::max-length", G_CALLBACK (buffer_notify_max_length), entry);
4793 buffer_disconnect_signals (GtkEntry *entry)
4795 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_inserted_text, entry);
4796 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_deleted_text, entry);
4797 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_text, entry);
4798 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_length, entry);
4799 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_max_length, entry);
4802 /* Compute the X position for an offset that corresponds to the "more important
4803 * cursor position for that offset. We use this when trying to guess to which
4804 * end of the selection we should go to when the user hits the left or
4808 get_better_cursor_x (GtkEntry *entry,
4811 GtkEntryPrivate *priv = entry->priv;
4812 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
4813 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
4814 gboolean split_cursor;
4816 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
4817 const gchar *text = pango_layout_get_text (layout);
4818 gint index = g_utf8_offset_to_pointer (text, offset) - text;
4820 PangoRectangle strong_pos, weak_pos;
4822 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
4823 "gtk-split-cursor", &split_cursor,
4826 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
4829 return strong_pos.x / PANGO_SCALE;
4831 return (keymap_direction == priv->resolved_dir) ? strong_pos.x / PANGO_SCALE : weak_pos.x / PANGO_SCALE;
4835 gtk_entry_move_cursor (GtkEntry *entry,
4836 GtkMovementStep step,
4838 gboolean extend_selection)
4840 GtkEntryPrivate *priv = entry->priv;
4841 gint new_pos = priv->current_pos;
4843 _gtk_entry_reset_im_context (entry);
4845 if (priv->current_pos != priv->selection_bound && !extend_selection)
4847 /* If we have a current selection and aren't extending it, move to the
4848 * start/or end of the selection as appropriate
4852 case GTK_MOVEMENT_VISUAL_POSITIONS:
4854 gint current_x = get_better_cursor_x (entry, priv->current_pos);
4855 gint bound_x = get_better_cursor_x (entry, priv->selection_bound);
4858 new_pos = current_x < bound_x ? priv->current_pos : priv->selection_bound;
4860 new_pos = current_x > bound_x ? priv->current_pos : priv->selection_bound;
4863 case GTK_MOVEMENT_LOGICAL_POSITIONS:
4864 case GTK_MOVEMENT_WORDS:
4866 new_pos = MIN (priv->current_pos, priv->selection_bound);
4868 new_pos = MAX (priv->current_pos, priv->selection_bound);
4870 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
4871 case GTK_MOVEMENT_PARAGRAPH_ENDS:
4872 case GTK_MOVEMENT_BUFFER_ENDS:
4873 new_pos = count < 0 ? 0 : gtk_entry_buffer_get_length (get_buffer (entry));
4875 case GTK_MOVEMENT_DISPLAY_LINES:
4876 case GTK_MOVEMENT_PARAGRAPHS:
4877 case GTK_MOVEMENT_PAGES:
4878 case GTK_MOVEMENT_HORIZONTAL_PAGES:
4886 case GTK_MOVEMENT_LOGICAL_POSITIONS:
4887 new_pos = gtk_entry_move_logically (entry, new_pos, count);
4889 case GTK_MOVEMENT_VISUAL_POSITIONS:
4890 new_pos = gtk_entry_move_visually (entry, new_pos, count);
4891 if (priv->current_pos == new_pos)
4893 if (!extend_selection)
4895 if (!gtk_widget_keynav_failed (GTK_WIDGET (entry),
4897 GTK_DIR_RIGHT : GTK_DIR_LEFT))
4899 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (entry));
4902 gtk_widget_child_focus (toplevel,
4904 GTK_DIR_RIGHT : GTK_DIR_LEFT);
4909 gtk_widget_error_bell (GTK_WIDGET (entry));
4913 case GTK_MOVEMENT_WORDS:
4916 new_pos = gtk_entry_move_forward_word (entry, new_pos, FALSE);
4921 new_pos = gtk_entry_move_backward_word (entry, new_pos, FALSE);
4924 if (priv->current_pos == new_pos)
4925 gtk_widget_error_bell (GTK_WIDGET (entry));
4927 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
4928 case GTK_MOVEMENT_PARAGRAPH_ENDS:
4929 case GTK_MOVEMENT_BUFFER_ENDS:
4930 new_pos = count < 0 ? 0 : gtk_entry_buffer_get_length (get_buffer (entry));
4931 if (priv->current_pos == new_pos)
4932 gtk_widget_error_bell (GTK_WIDGET (entry));
4934 case GTK_MOVEMENT_DISPLAY_LINES:
4935 case GTK_MOVEMENT_PARAGRAPHS:
4936 case GTK_MOVEMENT_PAGES:
4937 case GTK_MOVEMENT_HORIZONTAL_PAGES:
4942 if (extend_selection)
4943 gtk_editable_select_region (GTK_EDITABLE (entry), priv->selection_bound, new_pos);
4945 gtk_editable_set_position (GTK_EDITABLE (entry), new_pos);
4947 gtk_entry_pend_cursor_blink (entry);
4951 gtk_entry_insert_at_cursor (GtkEntry *entry,
4954 GtkEntryPrivate *priv = entry->priv;
4955 GtkEditable *editable = GTK_EDITABLE (entry);
4956 gint pos = priv->current_pos;
4960 _gtk_entry_reset_im_context (entry);
4962 gtk_editable_insert_text (editable, str, -1, &pos);
4963 gtk_editable_set_position (editable, pos);
4968 gtk_entry_delete_from_cursor (GtkEntry *entry,
4972 GtkEntryPrivate *priv = entry->priv;
4973 GtkEditable *editable = GTK_EDITABLE (entry);
4974 gint start_pos = priv->current_pos;
4975 gint end_pos = priv->current_pos;
4976 gint old_n_bytes = gtk_entry_buffer_get_bytes (get_buffer (entry));
4978 _gtk_entry_reset_im_context (entry);
4980 if (!priv->editable)
4982 gtk_widget_error_bell (GTK_WIDGET (entry));
4986 if (priv->selection_bound != priv->current_pos)
4988 gtk_editable_delete_selection (editable);
4994 case GTK_DELETE_CHARS:
4995 end_pos = gtk_entry_move_logically (entry, priv->current_pos, count);
4996 gtk_editable_delete_text (editable, MIN (start_pos, end_pos), MAX (start_pos, end_pos));
4998 case GTK_DELETE_WORDS:
5001 /* Move to end of current word, or if not on a word, end of previous word */
5002 end_pos = gtk_entry_move_backward_word (entry, end_pos, FALSE);
5003 end_pos = gtk_entry_move_forward_word (entry, end_pos, FALSE);
5007 /* Move to beginning of current word, or if not on a word, begining of next word */
5008 start_pos = gtk_entry_move_forward_word (entry, start_pos, FALSE);
5009 start_pos = gtk_entry_move_backward_word (entry, start_pos, FALSE);
5013 case GTK_DELETE_WORD_ENDS:
5016 start_pos = gtk_entry_move_backward_word (entry, start_pos, FALSE);
5021 end_pos = gtk_entry_move_forward_word (entry, end_pos, FALSE);
5024 gtk_editable_delete_text (editable, start_pos, end_pos);
5026 case GTK_DELETE_DISPLAY_LINE_ENDS:
5027 case GTK_DELETE_PARAGRAPH_ENDS:
5029 gtk_editable_delete_text (editable, 0, priv->current_pos);
5031 gtk_editable_delete_text (editable, priv->current_pos, -1);
5033 case GTK_DELETE_DISPLAY_LINES:
5034 case GTK_DELETE_PARAGRAPHS:
5035 gtk_editable_delete_text (editable, 0, -1);
5037 case GTK_DELETE_WHITESPACE:
5038 gtk_entry_delete_whitespace (entry);
5042 if (gtk_entry_buffer_get_bytes (get_buffer (entry)) == old_n_bytes)
5043 gtk_widget_error_bell (GTK_WIDGET (entry));
5045 gtk_entry_pend_cursor_blink (entry);
5049 gtk_entry_backspace (GtkEntry *entry)
5051 GtkEntryPrivate *priv = entry->priv;
5052 GtkEditable *editable = GTK_EDITABLE (entry);
5055 _gtk_entry_reset_im_context (entry);
5057 if (!priv->editable)
5059 gtk_widget_error_bell (GTK_WIDGET (entry));
5063 if (priv->selection_bound != priv->current_pos)
5065 gtk_editable_delete_selection (editable);
5069 prev_pos = gtk_entry_move_logically (entry, priv->current_pos, -1);
5071 if (prev_pos < priv->current_pos)
5073 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
5074 PangoLogAttr *log_attrs;
5077 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
5079 /* Deleting parts of characters */
5080 if (log_attrs[priv->current_pos].backspace_deletes_character)
5082 gchar *cluster_text;
5083 gchar *normalized_text;
5086 cluster_text = gtk_entry_get_display_text (entry, prev_pos,
5088 normalized_text = g_utf8_normalize (cluster_text,
5089 strlen (cluster_text),
5091 len = g_utf8_strlen (normalized_text, -1);
5093 gtk_editable_delete_text (editable, prev_pos, priv->current_pos);
5096 gint pos = priv->current_pos;
5098 gtk_editable_insert_text (editable, normalized_text,
5099 g_utf8_offset_to_pointer (normalized_text, len - 1) - normalized_text,
5101 gtk_editable_set_position (editable, pos);
5104 g_free (normalized_text);
5105 g_free (cluster_text);
5109 gtk_editable_delete_text (editable, prev_pos, priv->current_pos);
5116 gtk_widget_error_bell (GTK_WIDGET (entry));
5119 gtk_entry_pend_cursor_blink (entry);
5123 gtk_entry_copy_clipboard (GtkEntry *entry)
5125 GtkEntryPrivate *priv = entry->priv;
5126 GtkEditable *editable = GTK_EDITABLE (entry);
5130 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5134 gtk_widget_error_bell (GTK_WIDGET (entry));
5138 str = gtk_entry_get_display_text (entry, start, end);
5139 gtk_clipboard_set_text (gtk_widget_get_clipboard (GTK_WIDGET (entry),
5140 GDK_SELECTION_CLIPBOARD),
5147 gtk_entry_cut_clipboard (GtkEntry *entry)
5149 GtkEntryPrivate *priv = entry->priv;
5150 GtkEditable *editable = GTK_EDITABLE (entry);
5155 gtk_widget_error_bell (GTK_WIDGET (entry));
5159 gtk_entry_copy_clipboard (entry);
5163 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5164 gtk_editable_delete_text (editable, start, end);
5168 gtk_widget_error_bell (GTK_WIDGET (entry));
5173 gtk_entry_paste_clipboard (GtkEntry *entry)
5175 GtkEntryPrivate *priv = entry->priv;
5178 gtk_entry_paste (entry, GDK_SELECTION_CLIPBOARD);
5180 gtk_widget_error_bell (GTK_WIDGET (entry));
5184 gtk_entry_delete_cb (GtkEntry *entry)
5186 GtkEntryPrivate *priv = entry->priv;
5187 GtkEditable *editable = GTK_EDITABLE (entry);
5192 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5193 gtk_editable_delete_text (editable, start, end);
5198 gtk_entry_toggle_overwrite (GtkEntry *entry)
5200 GtkEntryPrivate *priv = entry->priv;
5202 priv->overwrite_mode = !priv->overwrite_mode;
5203 gtk_entry_pend_cursor_blink (entry);
5204 gtk_widget_queue_draw (GTK_WIDGET (entry));
5208 gtk_entry_select_all (GtkEntry *entry)
5210 gtk_entry_select_line (entry);
5214 gtk_entry_real_activate (GtkEntry *entry)
5216 GtkEntryPrivate *priv = entry->priv;
5218 GtkWidget *default_widget, *focus_widget;
5219 GtkWidget *toplevel;
5222 widget = GTK_WIDGET (entry);
5224 if (priv->activates_default)
5226 toplevel = gtk_widget_get_toplevel (widget);
5227 if (GTK_IS_WINDOW (toplevel))
5229 window = GTK_WINDOW (toplevel);
5233 default_widget = gtk_window_get_default_widget (window);
5234 focus_widget = gtk_window_get_focus (window);
5235 if (widget != default_widget &&
5236 !(widget == focus_widget && (!default_widget || !gtk_widget_get_sensitive (default_widget))))
5237 gtk_window_activate_default (window);
5244 keymap_direction_changed (GdkKeymap *keymap,
5247 gtk_entry_recompute (entry);
5250 /* IM Context Callbacks
5254 gtk_entry_commit_cb (GtkIMContext *context,
5258 GtkEntryPrivate *priv = entry->priv;
5261 gtk_entry_enter_text (entry, str);
5265 gtk_entry_preedit_changed_cb (GtkIMContext *context,
5268 GtkEntryPrivate *priv = entry->priv;
5272 gchar *preedit_string;
5275 gtk_im_context_get_preedit_string (priv->im_context,
5276 &preedit_string, NULL,
5278 g_signal_emit (entry, signals[PREEDIT_CHANGED], 0, preedit_string);
5279 priv->preedit_length = strlen (preedit_string);
5280 cursor_pos = CLAMP (cursor_pos, 0, g_utf8_strlen (preedit_string, -1));
5281 priv->preedit_cursor = cursor_pos;
5282 g_free (preedit_string);
5284 gtk_entry_recompute (entry);
5289 gtk_entry_retrieve_surrounding_cb (GtkIMContext *context,
5292 GtkEntryPrivate *priv = entry->priv;
5295 /* XXXX ??? does this even make sense when text is not visible? Should we return FALSE? */
5296 text = gtk_entry_get_display_text (entry, 0, -1);
5297 gtk_im_context_set_surrounding (context, text, strlen (text), /* Length in bytes */
5298 g_utf8_offset_to_pointer (text, priv->current_pos) - text);
5305 gtk_entry_delete_surrounding_cb (GtkIMContext *slave,
5310 GtkEntryPrivate *priv = entry->priv;
5313 gtk_editable_delete_text (GTK_EDITABLE (entry),
5314 priv->current_pos + offset,
5315 priv->current_pos + offset + n_chars);
5320 /* Internal functions
5323 /* Used for im_commit_cb and inserting Unicode chars */
5325 gtk_entry_enter_text (GtkEntry *entry,
5328 GtkEntryPrivate *priv = entry->priv;
5329 GtkEditable *editable = GTK_EDITABLE (entry);
5331 gboolean old_need_im_reset;
5333 old_need_im_reset = priv->need_im_reset;
5334 priv->need_im_reset = FALSE;
5336 if (gtk_editable_get_selection_bounds (editable, NULL, NULL))
5337 gtk_editable_delete_selection (editable);
5340 if (priv->overwrite_mode)
5341 gtk_entry_delete_from_cursor (entry, GTK_DELETE_CHARS, 1);
5344 tmp_pos = priv->current_pos;
5345 gtk_editable_insert_text (editable, str, strlen (str), &tmp_pos);
5346 gtk_editable_set_position (editable, tmp_pos);
5348 priv->need_im_reset = old_need_im_reset;
5351 /* All changes to priv->current_pos and priv->selection_bound
5352 * should go through this function.
5355 gtk_entry_set_positions (GtkEntry *entry,
5357 gint selection_bound)
5359 GtkEntryPrivate *priv = entry->priv;
5360 gboolean changed = FALSE;
5362 g_object_freeze_notify (G_OBJECT (entry));
5364 if (current_pos != -1 &&
5365 priv->current_pos != current_pos)
5367 priv->current_pos = current_pos;
5370 g_object_notify (G_OBJECT (entry), "cursor-position");
5373 if (selection_bound != -1 &&
5374 priv->selection_bound != selection_bound)
5376 priv->selection_bound = selection_bound;
5379 g_object_notify (G_OBJECT (entry), "selection-bound");
5382 g_object_thaw_notify (G_OBJECT (entry));
5386 gtk_entry_move_adjustments (entry);
5387 gtk_entry_recompute (entry);
5392 gtk_entry_reset_layout (GtkEntry *entry)
5394 GtkEntryPrivate *priv = entry->priv;
5396 if (priv->cached_layout)
5398 g_object_unref (priv->cached_layout);
5399 priv->cached_layout = NULL;
5404 update_im_cursor_location (GtkEntry *entry)
5406 GtkEntryPrivate *priv = entry->priv;
5409 gint strong_xoffset;
5410 gint area_width, area_height;
5412 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
5413 gtk_entry_get_text_area_size (entry, NULL, NULL, &area_width, &area_height);
5415 strong_xoffset = strong_x - priv->scroll_offset;
5416 if (strong_xoffset < 0)
5420 else if (strong_xoffset > area_width)
5422 strong_xoffset = area_width;
5424 area.x = strong_xoffset;
5427 area.height = area_height;
5429 gtk_im_context_set_cursor_location (priv->im_context, &area);
5433 recompute_idle_func (gpointer data)
5435 GtkEntry *entry = GTK_ENTRY (data);
5436 GtkEntryPrivate *priv = entry->priv;
5438 priv->recompute_idle = 0;
5440 if (gtk_widget_has_screen (GTK_WIDGET (entry)))
5442 gtk_entry_adjust_scroll (entry);
5443 gtk_widget_queue_draw (GTK_WIDGET (entry));
5445 update_im_cursor_location (entry);
5452 gtk_entry_recompute (GtkEntry *entry)
5454 GtkEntryPrivate *priv = entry->priv;
5456 gtk_entry_reset_layout (entry);
5457 gtk_entry_check_cursor_blink (entry);
5459 if (!priv->recompute_idle)
5461 priv->recompute_idle = gdk_threads_add_idle_full (G_PRIORITY_HIGH_IDLE + 15, /* between resize and redraw */
5462 recompute_idle_func, entry, NULL);
5467 gtk_entry_get_placeholder_text_color (GtkEntry *entry,
5470 GtkWidget *widget = GTK_WIDGET (entry);
5471 GtkStyleContext *context;
5472 GdkRGBA fg = { 0.5, 0.5, 0.5 };
5474 context = gtk_widget_get_style_context (widget);
5475 gtk_style_context_lookup_color (context, "placeholder_text_color", &fg);
5477 color->red = CLAMP (fg.red * 65535. + 0.5, 0, 65535);
5478 color->green = CLAMP (fg.green * 65535. + 0.5, 0, 65535);
5479 color->blue = CLAMP (fg.blue * 65535. + 0.5, 0, 65535);
5482 static inline gboolean
5483 show_placeholder_text (GtkEntry *entry)
5485 GtkEntryPrivate *priv = entry->priv;
5487 if (!gtk_widget_has_focus (GTK_WIDGET (entry)) &&
5488 gtk_entry_buffer_get_bytes (get_buffer (entry)) == 0 &&
5489 priv->placeholder_text != NULL)
5495 static PangoLayout *
5496 gtk_entry_create_layout (GtkEntry *entry,
5497 gboolean include_preedit)
5499 GtkEntryPrivate *priv = entry->priv;
5500 GtkWidget *widget = GTK_WIDGET (entry);
5501 PangoLayout *layout = gtk_widget_create_pango_layout (widget, NULL);
5502 PangoAttrList *tmp_attrs = pango_attr_list_new ();
5503 gboolean placeholder_layout = show_placeholder_text (entry);
5505 gchar *preedit_string = NULL;
5506 gint preedit_length = 0;
5507 PangoAttrList *preedit_attrs = NULL;
5512 pango_layout_set_single_paragraph_mode (layout, TRUE);
5514 display = placeholder_layout ? g_strdup (priv->placeholder_text) : gtk_entry_get_display_text (entry, 0, -1);
5515 n_bytes = strlen (display);
5517 if (!placeholder_layout && include_preedit)
5519 gtk_im_context_get_preedit_string (priv->im_context,
5520 &preedit_string, &preedit_attrs, NULL);
5521 preedit_length = priv->preedit_length;
5523 else if (placeholder_layout)
5526 PangoAttribute *attr;
5528 gtk_entry_get_placeholder_text_color (entry, &color);
5529 attr = pango_attr_foreground_new (color.red, color.green, color.blue);
5530 attr->start_index = 0;
5531 attr->end_index = G_MAXINT;
5532 pango_attr_list_insert (tmp_attrs, attr);
5537 GString *tmp_string = g_string_new (display);
5538 gint cursor_index = g_utf8_offset_to_pointer (display, priv->current_pos) - display;
5540 g_string_insert (tmp_string, cursor_index, preedit_string);
5542 pango_layout_set_text (layout, tmp_string->str, tmp_string->len);
5544 pango_attr_list_splice (tmp_attrs, preedit_attrs,
5545 cursor_index, preedit_length);
5547 g_string_free (tmp_string, TRUE);
5551 PangoDirection pango_dir;
5553 if (gtk_entry_get_display_mode (entry) == DISPLAY_NORMAL)
5554 pango_dir = pango_find_base_dir (display, n_bytes);
5556 pango_dir = PANGO_DIRECTION_NEUTRAL;
5558 if (pango_dir == PANGO_DIRECTION_NEUTRAL)
5560 if (gtk_widget_has_focus (widget))
5562 GdkDisplay *display = gtk_widget_get_display (widget);
5563 GdkKeymap *keymap = gdk_keymap_get_for_display (display);
5564 if (gdk_keymap_get_direction (keymap) == PANGO_DIRECTION_RTL)
5565 pango_dir = PANGO_DIRECTION_RTL;
5567 pango_dir = PANGO_DIRECTION_LTR;
5571 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
5572 pango_dir = PANGO_DIRECTION_RTL;
5574 pango_dir = PANGO_DIRECTION_LTR;
5578 pango_context_set_base_dir (gtk_widget_get_pango_context (widget),
5581 priv->resolved_dir = pango_dir;
5583 pango_layout_set_text (layout, display, n_bytes);
5586 pango_layout_set_attributes (layout, tmp_attrs);
5588 g_free (preedit_string);
5592 pango_attr_list_unref (preedit_attrs);
5594 pango_attr_list_unref (tmp_attrs);
5599 static PangoLayout *
5600 gtk_entry_ensure_layout (GtkEntry *entry,
5601 gboolean include_preedit)
5603 GtkEntryPrivate *priv = entry->priv;
5605 if (priv->preedit_length > 0 &&
5606 !include_preedit != !priv->cache_includes_preedit)
5607 gtk_entry_reset_layout (entry);
5609 if (!priv->cached_layout)
5611 priv->cached_layout = gtk_entry_create_layout (entry, include_preedit);
5612 priv->cache_includes_preedit = include_preedit;
5615 return priv->cached_layout;
5619 get_layout_position (GtkEntry *entry,
5623 GtkEntryPrivate *priv = entry->priv;
5624 PangoLayout *layout;
5625 PangoRectangle logical_rect;
5626 gint area_width, area_height;
5627 GtkBorder inner_border;
5629 PangoLayoutLine *line;
5631 layout = gtk_entry_ensure_layout (entry, TRUE);
5633 gtk_entry_get_text_area_size (entry, NULL, NULL, &area_width, &area_height);
5634 _gtk_entry_effective_inner_border (entry, &inner_border);
5636 area_height = PANGO_SCALE * (area_height - inner_border.top - inner_border.bottom);
5638 line = pango_layout_get_lines_readonly (layout)->data;
5639 pango_layout_line_get_extents (line, NULL, &logical_rect);
5641 /* Align primarily for locale's ascent/descent */
5642 y_pos = ((area_height - priv->ascent - priv->descent) / 2 +
5643 priv->ascent + logical_rect.y);
5645 /* Now see if we need to adjust to fit in actual drawn string */
5646 if (logical_rect.height > area_height)
5647 y_pos = (area_height - logical_rect.height) / 2;
5650 else if (y_pos + logical_rect.height > area_height)
5651 y_pos = area_height - logical_rect.height;
5653 y_pos = inner_border.top + y_pos / PANGO_SCALE;
5656 *x = inner_border.left - priv->scroll_offset;
5663 draw_text_with_color (GtkEntry *entry,
5665 GdkRGBA *default_color)
5667 GtkEntryPrivate *priv = entry->priv;
5668 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
5671 gint start_pos, end_pos;
5673 widget = GTK_WIDGET (entry);
5677 get_layout_position (entry, &x, &y);
5679 cairo_move_to (cr, x, y);
5680 gdk_cairo_set_source_rgba (cr, default_color);
5681 pango_cairo_show_layout (cr, layout);
5683 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start_pos, &end_pos))
5687 PangoRectangle logical_rect;
5688 GdkRGBA selection_color, text_color;
5689 GtkBorder inner_border;
5690 GtkStyleContext *context;
5691 GtkStateFlags state;
5693 context = gtk_widget_get_style_context (widget);
5694 pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
5695 gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
5697 state = GTK_STATE_FLAG_SELECTED;
5699 if (gtk_widget_has_focus (widget))
5700 state |= GTK_STATE_FLAG_FOCUSED;
5702 gtk_style_context_get_background_color (context, state, &selection_color);
5703 gtk_style_context_get_color (context, state, &text_color);
5705 _gtk_entry_effective_inner_border (entry, &inner_border);
5707 for (i = 0; i < n_ranges; ++i)
5708 cairo_rectangle (cr,
5709 inner_border.left - priv->scroll_offset + ranges[2 * i],
5712 logical_rect.height);
5716 gdk_cairo_set_source_rgba (cr, &selection_color);
5719 cairo_move_to (cr, x, y);
5720 gdk_cairo_set_source_rgba (cr, &text_color);
5721 pango_cairo_show_layout (cr, layout);
5729 gtk_entry_draw_text (GtkEntry *entry,
5732 GtkEntryPrivate *priv = entry->priv;
5733 GtkWidget *widget = GTK_WIDGET (entry);
5734 GtkStateFlags state = 0;
5735 GdkRGBA text_color, bar_text_color;
5736 GtkStyleContext *context;
5739 gint progress_x, progress_y, progress_width, progress_height;
5740 gint clip_width, clip_height;
5742 /* Nothing to display at all */
5743 if (gtk_entry_get_display_mode (entry) == DISPLAY_BLANK)
5746 state = gtk_widget_get_state_flags (widget);
5747 context = gtk_widget_get_style_context (widget);
5749 gtk_style_context_get_color (context, state, &text_color);
5751 /* Get foreground color for progressbars */
5752 gtk_style_context_save (context);
5753 gtk_style_context_add_class (context, GTK_STYLE_CLASS_PROGRESSBAR);
5754 gtk_style_context_get_color (context, state, &bar_text_color);
5755 gtk_style_context_restore (context);
5757 get_progress_area (widget,
5758 &progress_x, &progress_y,
5759 &progress_width, &progress_height);
5761 clip_width = gdk_window_get_width (priv->text_area);
5762 clip_height = gdk_window_get_height (priv->text_area);
5763 cairo_rectangle (cr, 0, 0, clip_width, clip_height);
5766 /* If the color is the same, or the progress area has a zero
5767 * size, then we only need to draw once. */
5768 if (gdk_rgba_equal (&text_color, &bar_text_color) ||
5769 ((progress_width == 0) || (progress_height == 0)))
5771 draw_text_with_color (entry, cr, &text_color);
5775 width = gdk_window_get_width (priv->text_area);
5776 height = gdk_window_get_height (priv->text_area);
5780 cairo_rectangle (cr, 0, 0, width, height);
5784 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
5785 cairo_rectangle (cr, 0, 0, width, height);
5787 gdk_window_get_position (priv->text_area, &pos_x, &pos_y);
5788 progress_x -= pos_x;
5789 progress_y -= pos_y;
5791 cairo_rectangle (cr, progress_x, progress_y,
5792 progress_width, progress_height);
5794 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_WINDING);
5796 draw_text_with_color (entry, cr, &text_color);
5799 cairo_rectangle (cr, progress_x, progress_y,
5800 progress_width, progress_height);
5803 draw_text_with_color (entry, cr, &bar_text_color);
5810 draw_insertion_cursor (GtkEntry *entry,
5812 GdkRectangle *cursor_location,
5813 gboolean is_primary,
5814 PangoDirection direction,
5815 gboolean draw_arrow)
5817 GtkWidget *widget = GTK_WIDGET (entry);
5818 GtkTextDirection text_dir;
5820 if (direction == PANGO_DIRECTION_LTR)
5821 text_dir = GTK_TEXT_DIR_LTR;
5823 text_dir = GTK_TEXT_DIR_RTL;
5825 gtk_draw_insertion_cursor (widget, cr,
5827 is_primary, text_dir, draw_arrow);
5831 gtk_entry_draw_cursor (GtkEntry *entry,
5835 GtkEntryPrivate *priv = entry->priv;
5836 GtkWidget *widget = GTK_WIDGET (entry);
5837 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
5838 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
5839 GdkRectangle cursor_location;
5840 gboolean split_cursor;
5841 PangoRectangle cursor_rect;
5842 GtkBorder inner_border;
5844 gint text_area_height;
5847 gboolean block_at_line_end;
5848 PangoLayout *layout;
5851 _gtk_entry_effective_inner_border (entry, &inner_border);
5853 xoffset = inner_border.left - priv->scroll_offset;
5855 text_area_height = gdk_window_get_height (priv->text_area);
5857 layout = gtk_entry_ensure_layout (entry, TRUE);
5858 text = pango_layout_get_text (layout);
5859 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos + priv->preedit_cursor) - text;
5860 if (!priv->overwrite_mode)
5863 block = _gtk_text_util_get_block_cursor_location (layout,
5864 cursor_index, &cursor_rect, &block_at_line_end);
5868 gint strong_x, weak_x;
5869 PangoDirection dir1 = PANGO_DIRECTION_NEUTRAL;
5870 PangoDirection dir2 = PANGO_DIRECTION_NEUTRAL;
5874 gtk_entry_get_cursor_locations (entry, type, &strong_x, &weak_x);
5876 g_object_get (gtk_widget_get_settings (widget),
5877 "gtk-split-cursor", &split_cursor,
5880 dir1 = priv->resolved_dir;
5886 if (weak_x != strong_x)
5888 dir2 = (priv->resolved_dir == PANGO_DIRECTION_LTR) ? PANGO_DIRECTION_RTL : PANGO_DIRECTION_LTR;
5894 if (keymap_direction == priv->resolved_dir)
5900 cursor_location.x = xoffset + x1;
5901 cursor_location.y = inner_border.top;
5902 cursor_location.width = 0;
5903 cursor_location.height = text_area_height - inner_border.top - inner_border.bottom;
5905 draw_insertion_cursor (entry, cr,
5906 &cursor_location, TRUE, dir1,
5907 dir2 != PANGO_DIRECTION_NEUTRAL);
5909 if (dir2 != PANGO_DIRECTION_NEUTRAL)
5911 cursor_location.x = xoffset + x2;
5912 draw_insertion_cursor (entry, cr,
5913 &cursor_location, FALSE, dir2,
5917 else /* overwrite_mode */
5919 GtkStyleContext *context;
5920 GdkRGBA cursor_color;
5926 get_layout_position (entry, &x, &y);
5928 rect.x = PANGO_PIXELS (cursor_rect.x) + x;
5929 rect.y = PANGO_PIXELS (cursor_rect.y) + y;
5930 rect.width = PANGO_PIXELS (cursor_rect.width);
5931 rect.height = PANGO_PIXELS (cursor_rect.height);
5933 context = gtk_widget_get_style_context (widget);
5935 _gtk_style_context_get_cursor_color (context, &cursor_color, NULL);
5936 gdk_cairo_set_source_rgba (cr, &cursor_color);
5937 gdk_cairo_rectangle (cr, &rect);
5940 if (!block_at_line_end)
5942 GtkStateFlags state;
5945 state = gtk_widget_get_state_flags (widget);
5946 gtk_style_context_get_background_color (context, state, &color);
5948 gdk_cairo_rectangle (cr, &rect);
5950 cairo_move_to (cr, x, y);
5951 gdk_cairo_set_source_rgba (cr, &color);
5952 pango_cairo_show_layout (cr, layout);
5960 _gtk_entry_reset_im_context (GtkEntry *entry)
5962 GtkEntryPrivate *priv = entry->priv;
5964 if (priv->need_im_reset)
5966 priv->need_im_reset = FALSE;
5967 gtk_im_context_reset (priv->im_context);
5972 * gtk_entry_reset_im_context:
5973 * @entry: a #GtkEntry
5975 * Reset the input method context of the entry if needed.
5977 * This can be necessary in the case where modifying the buffer
5978 * would confuse on-going input method behavior.
5983 gtk_entry_reset_im_context (GtkEntry *entry)
5985 g_return_if_fail (GTK_IS_ENTRY (entry));
5987 _gtk_entry_reset_im_context (entry);
5991 * gtk_entry_im_context_filter_keypress:
5992 * @entry: a #GtkEntry
5993 * @event: (type Gdk.EventKey): the key event
5995 * Allow the #GtkEntry input method to internally handle key press
5996 * and release events. If this function returns %TRUE, then no further
5997 * processing should be done for this key event. See
5998 * gtk_im_context_filter_keypress().
6000 * Note that you are expected to call this function from your handler
6001 * when overriding key event handling. This is needed in the case when
6002 * you need to insert your own key handling between the input method
6003 * and the default key event handling of the #GtkEntry.
6004 * See gtk_text_view_reset_im_context() for an example of use.
6006 * Return value: %TRUE if the input method handled the key event.
6011 gtk_entry_im_context_filter_keypress (GtkEntry *entry,
6014 GtkEntryPrivate *priv;
6016 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
6020 return gtk_im_context_filter_keypress (priv->im_context, event);
6024 _gtk_entry_get_im_context (GtkEntry *entry)
6026 return entry->priv->im_context;
6030 gtk_entry_find_position (GtkEntry *entry,
6033 GtkEntryPrivate *priv = entry->priv;
6034 PangoLayout *layout;
6035 PangoLayoutLine *line;
6042 layout = gtk_entry_ensure_layout (entry, TRUE);
6043 text = pango_layout_get_text (layout);
6044 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos) - text;
6046 line = pango_layout_get_lines_readonly (layout)->data;
6047 pango_layout_line_x_to_index (line, x * PANGO_SCALE, &index, &trailing);
6049 if (index >= cursor_index && priv->preedit_length)
6051 if (index >= cursor_index + priv->preedit_length)
6052 index -= priv->preedit_length;
6055 index = cursor_index;
6060 pos = g_utf8_pointer_to_offset (text, text + index);
6067 gtk_entry_get_cursor_locations (GtkEntry *entry,
6072 GtkEntryPrivate *priv = entry->priv;
6073 DisplayMode mode = gtk_entry_get_display_mode (entry);
6075 /* Nothing to display at all, so no cursor is relevant */
6076 if (mode == DISPLAY_BLANK)
6086 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
6087 const gchar *text = pango_layout_get_text (layout);
6088 PangoRectangle strong_pos, weak_pos;
6091 if (type == CURSOR_STANDARD)
6093 index = g_utf8_offset_to_pointer (text, priv->current_pos + priv->preedit_cursor) - text;
6095 else /* type == CURSOR_DND */
6097 index = g_utf8_offset_to_pointer (text, priv->dnd_position) - text;
6099 if (priv->dnd_position > priv->current_pos)
6101 if (mode == DISPLAY_NORMAL)
6102 index += priv->preedit_length;
6105 gint preedit_len_chars = g_utf8_strlen (text, -1) - gtk_entry_buffer_get_length (get_buffer (entry));
6106 index += preedit_len_chars * g_unichar_to_utf8 (priv->invisible_char, NULL);
6111 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
6114 *strong_x = strong_pos.x / PANGO_SCALE;
6117 *weak_x = weak_pos.x / PANGO_SCALE;
6122 gtk_entry_adjust_scroll (GtkEntry *entry)
6124 GtkEntryPrivate *priv = entry->priv;
6125 gint min_offset, max_offset;
6126 gint text_area_width, text_width;
6127 GtkBorder inner_border;
6128 gint strong_x, weak_x;
6129 gint strong_xoffset, weak_xoffset;
6131 PangoLayout *layout;
6132 PangoLayoutLine *line;
6133 PangoRectangle logical_rect;
6135 if (!gtk_widget_get_realized (GTK_WIDGET (entry)))
6138 _gtk_entry_effective_inner_border (entry, &inner_border);
6140 text_area_width = gdk_window_get_width (priv->text_area);
6141 text_area_width -= inner_border.left + inner_border.right;
6142 if (text_area_width < 0)
6143 text_area_width = 0;
6145 layout = gtk_entry_ensure_layout (entry, TRUE);
6146 line = pango_layout_get_lines_readonly (layout)->data;
6148 pango_layout_line_get_extents (line, NULL, &logical_rect);
6150 /* Display as much text as we can */
6152 if (priv->resolved_dir == PANGO_DIRECTION_LTR)
6153 xalign = priv->xalign;
6155 xalign = 1.0 - priv->xalign;
6157 text_width = PANGO_PIXELS(logical_rect.width);
6159 if (text_width > text_area_width)
6162 max_offset = text_width - text_area_width;
6166 min_offset = (text_width - text_area_width) * xalign;
6167 max_offset = min_offset;
6170 priv->scroll_offset = CLAMP (priv->scroll_offset, min_offset, max_offset);
6172 /* And make sure cursors are on screen. Note that the cursor is
6173 * actually drawn one pixel into the INNER_BORDER space on
6174 * the right, when the scroll is at the utmost right. This
6175 * looks better to to me than confining the cursor inside the
6176 * border entirely, though it means that the cursor gets one
6177 * pixel closer to the edge of the widget on the right than
6178 * on the left. This might need changing if one changed
6179 * INNER_BORDER from 2 to 1, as one would do on a
6180 * small-screen-real-estate display.
6182 * We always make sure that the strong cursor is on screen, and
6183 * put the weak cursor on screen if possible.
6186 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, &weak_x);
6188 strong_xoffset = strong_x - priv->scroll_offset;
6190 if (strong_xoffset < 0)
6192 priv->scroll_offset += strong_xoffset;
6195 else if (strong_xoffset > text_area_width)
6197 priv->scroll_offset += strong_xoffset - text_area_width;
6198 strong_xoffset = text_area_width;
6201 weak_xoffset = weak_x - priv->scroll_offset;
6203 if (weak_xoffset < 0 && strong_xoffset - weak_xoffset <= text_area_width)
6205 priv->scroll_offset += weak_xoffset;
6207 else if (weak_xoffset > text_area_width &&
6208 strong_xoffset - (weak_xoffset - text_area_width) >= 0)
6210 priv->scroll_offset += weak_xoffset - text_area_width;
6213 g_object_notify (G_OBJECT (entry), "scroll-offset");
6217 gtk_entry_move_adjustments (GtkEntry *entry)
6219 GtkWidget *widget = GTK_WIDGET (entry);
6220 GtkAllocation allocation;
6221 GtkAdjustment *adjustment;
6222 PangoContext *context;
6223 PangoFontMetrics *metrics;
6224 GtkStyleContext *style_context;
6225 GtkStateFlags state;
6226 gint x, layout_x, border_x, border_y;
6229 adjustment = g_object_get_qdata (G_OBJECT (entry), quark_cursor_hadjustment);
6233 gtk_widget_get_allocation (widget, &allocation);
6235 /* Cursor position, layout offset, border width, and widget allocation */
6236 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &x, NULL);
6237 get_layout_position (entry, &layout_x, NULL);
6238 _gtk_entry_get_borders (entry, &border_x, &border_y);
6239 x += allocation.x + layout_x + border_x;
6241 /* Approximate width of a char, so user can see what is ahead/behind */
6242 context = gtk_widget_get_pango_context (widget);
6243 style_context = gtk_widget_get_style_context (widget);
6244 state = gtk_widget_get_state_flags (widget);
6246 metrics = pango_context_get_metrics (context,
6247 gtk_style_context_get_font (style_context, state),
6248 pango_context_get_language (context));
6249 char_width = pango_font_metrics_get_approximate_char_width (metrics) / PANGO_SCALE;
6252 gtk_adjustment_clamp_page (adjustment,
6253 x - (char_width + 1), /* one char + one pixel before */
6254 x + (char_width + 2)); /* one char + cursor + one pixel after */
6258 gtk_entry_move_visually (GtkEntry *entry,
6262 GtkEntryPrivate *priv = entry->priv;
6264 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6267 text = pango_layout_get_text (layout);
6269 index = g_utf8_offset_to_pointer (text, start) - text;
6273 int new_index, new_trailing;
6274 gboolean split_cursor;
6277 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
6278 "gtk-split-cursor", &split_cursor,
6285 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
6286 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
6288 strong = keymap_direction == priv->resolved_dir;
6293 pango_layout_move_cursor_visually (layout, strong, index, 0, 1, &new_index, &new_trailing);
6298 pango_layout_move_cursor_visually (layout, strong, index, 0, -1, &new_index, &new_trailing);
6304 else if (new_index != G_MAXINT)
6307 while (new_trailing--)
6308 index = g_utf8_next_char (text + index) - text;
6311 return g_utf8_pointer_to_offset (text, text + index);
6315 gtk_entry_move_logically (GtkEntry *entry,
6319 gint new_pos = start;
6322 length = gtk_entry_buffer_get_length (get_buffer (entry));
6324 /* Prevent any leak of information */
6325 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6327 new_pos = CLAMP (start + count, 0, length);
6331 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6332 PangoLogAttr *log_attrs;
6335 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6337 while (count > 0 && new_pos < length)
6341 while (new_pos < length && !log_attrs[new_pos].is_cursor_position);
6345 while (count < 0 && new_pos > 0)
6349 while (new_pos > 0 && !log_attrs[new_pos].is_cursor_position);
6361 gtk_entry_move_forward_word (GtkEntry *entry,
6363 gboolean allow_whitespace)
6365 gint new_pos = start;
6368 length = gtk_entry_buffer_get_length (get_buffer (entry));
6370 /* Prevent any leak of information */
6371 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6375 else if (new_pos < length)
6377 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6378 PangoLogAttr *log_attrs;
6381 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6383 /* Find the next word boundary */
6385 while (new_pos < n_attrs - 1 && !(log_attrs[new_pos].is_word_end ||
6386 (log_attrs[new_pos].is_word_start && allow_whitespace)))
6397 gtk_entry_move_backward_word (GtkEntry *entry,
6399 gboolean allow_whitespace)
6401 gint new_pos = start;
6403 /* Prevent any leak of information */
6404 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6410 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6411 PangoLogAttr *log_attrs;
6414 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6416 new_pos = start - 1;
6418 /* Find the previous word boundary */
6419 while (new_pos > 0 && !(log_attrs[new_pos].is_word_start ||
6420 (log_attrs[new_pos].is_word_end && allow_whitespace)))
6430 gtk_entry_delete_whitespace (GtkEntry *entry)
6432 GtkEntryPrivate *priv = entry->priv;
6433 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6434 PangoLogAttr *log_attrs;
6438 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6440 start = end = priv->current_pos;
6442 while (start > 0 && log_attrs[start-1].is_white)
6445 while (end < n_attrs && log_attrs[end].is_white)
6451 gtk_editable_delete_text (GTK_EDITABLE (entry), start, end);
6456 gtk_entry_select_word (GtkEntry *entry)
6458 GtkEntryPrivate *priv = entry->priv;
6459 gint start_pos = gtk_entry_move_backward_word (entry, priv->current_pos, TRUE);
6460 gint end_pos = gtk_entry_move_forward_word (entry, priv->current_pos, TRUE);
6462 gtk_editable_select_region (GTK_EDITABLE (entry), start_pos, end_pos);
6466 gtk_entry_select_line (GtkEntry *entry)
6468 gtk_editable_select_region (GTK_EDITABLE (entry), 0, -1);
6472 truncate_multiline (const gchar *text)
6477 text[length] && text[length] != '\n' && text[length] != '\r';
6484 paste_received (GtkClipboard *clipboard,
6488 GtkEntry *entry = GTK_ENTRY (data);
6489 GtkEditable *editable = GTK_EDITABLE (entry);
6490 GtkEntryPrivate *priv = entry->priv;
6492 if (priv->button == 2)
6494 gint pos, start, end;
6495 pos = priv->insert_pos;
6496 gtk_editable_get_selection_bounds (editable, &start, &end);
6497 if (!((start <= pos && pos <= end) || (end <= pos && pos <= start)))
6498 gtk_editable_select_region (editable, pos, pos);
6503 gint pos, start, end;
6505 gboolean popup_completion;
6506 GtkEntryCompletion *completion;
6508 completion = gtk_entry_get_completion (entry);
6510 if (priv->truncate_multiline)
6511 length = truncate_multiline (text);
6513 /* only complete if the selection is at the end */
6514 popup_completion = (gtk_entry_buffer_get_length (get_buffer (entry)) ==
6515 MAX (priv->current_pos, priv->selection_bound));
6519 if (gtk_widget_get_mapped (completion->priv->popup_window))
6520 _gtk_entry_completion_popdown (completion);
6522 if (!popup_completion && completion->priv->changed_id > 0)
6523 g_signal_handler_block (entry, completion->priv->changed_id);
6526 begin_change (entry);
6527 g_object_freeze_notify (G_OBJECT (entry));
6528 if (gtk_editable_get_selection_bounds (editable, &start, &end))
6529 gtk_editable_delete_text (editable, start, end);
6531 pos = priv->current_pos;
6532 gtk_editable_insert_text (editable, text, length, &pos);
6533 gtk_editable_set_position (editable, pos);
6534 g_object_thaw_notify (G_OBJECT (entry));
6538 !popup_completion && completion->priv->changed_id > 0)
6539 g_signal_handler_unblock (entry, completion->priv->changed_id);
6542 g_object_unref (entry);
6546 gtk_entry_paste (GtkEntry *entry,
6549 g_object_ref (entry);
6550 gtk_clipboard_request_text (gtk_widget_get_clipboard (GTK_WIDGET (entry), selection),
6551 paste_received, entry);
6555 primary_get_cb (GtkClipboard *clipboard,
6556 GtkSelectionData *selection_data,
6560 GtkEntry *entry = GTK_ENTRY (data);
6563 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end))
6565 gchar *str = gtk_entry_get_display_text (entry, start, end);
6566 gtk_selection_data_set_text (selection_data, str, -1);
6572 primary_clear_cb (GtkClipboard *clipboard,
6575 GtkEntry *entry = GTK_ENTRY (data);
6576 GtkEntryPrivate *priv = entry->priv;
6578 gtk_editable_select_region (GTK_EDITABLE (entry), priv->current_pos, priv->current_pos);
6582 gtk_entry_update_primary_selection (GtkEntry *entry)
6584 GtkTargetList *list;
6585 GtkTargetEntry *targets;
6586 GtkClipboard *clipboard;
6590 if (!gtk_widget_get_realized (GTK_WIDGET (entry)))
6593 list = gtk_target_list_new (NULL, 0);
6594 gtk_target_list_add_text_targets (list, 0);
6596 targets = gtk_target_table_new_from_list (list, &n_targets);
6598 clipboard = gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_PRIMARY);
6600 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end))
6602 if (!gtk_clipboard_set_with_owner (clipboard, targets, n_targets,
6603 primary_get_cb, primary_clear_cb, G_OBJECT (entry)))
6604 primary_clear_cb (clipboard, entry);
6608 if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (entry))
6609 gtk_clipboard_clear (clipboard);
6612 gtk_target_table_free (targets, n_targets);
6613 gtk_target_list_unref (list);
6617 gtk_entry_clear (GtkEntry *entry,
6618 GtkEntryIconPosition icon_pos)
6620 GtkEntryPrivate *priv = entry->priv;
6621 EntryIconInfo *icon_info = priv->icons[icon_pos];
6623 if (!icon_info || icon_info->storage_type == GTK_IMAGE_EMPTY)
6626 g_object_freeze_notify (G_OBJECT (entry));
6628 /* Explicitly check, as the pointer may become invalidated
6629 * during destruction.
6631 if (GDK_IS_WINDOW (icon_info->window))
6632 gdk_window_hide (icon_info->window);
6634 if (icon_info->pixbuf)
6636 g_object_unref (icon_info->pixbuf);
6637 icon_info->pixbuf = NULL;
6640 switch (icon_info->storage_type)
6642 case GTK_IMAGE_PIXBUF:
6643 g_object_notify (G_OBJECT (entry),
6644 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-pixbuf" : "secondary-icon-pixbuf");
6647 case GTK_IMAGE_STOCK:
6648 g_free (icon_info->stock_id);
6649 icon_info->stock_id = NULL;
6650 g_object_notify (G_OBJECT (entry),
6651 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-stock" : "secondary-icon-stock");
6654 case GTK_IMAGE_ICON_NAME:
6655 g_free (icon_info->icon_name);
6656 icon_info->icon_name = NULL;
6657 g_object_notify (G_OBJECT (entry),
6658 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-name" : "secondary-icon-name");
6661 case GTK_IMAGE_GICON:
6662 if (icon_info->gicon)
6664 g_object_unref (icon_info->gicon);
6665 icon_info->gicon = NULL;
6667 g_object_notify (G_OBJECT (entry),
6668 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-gicon" : "secondary-icon-gicon");
6672 g_assert_not_reached ();
6676 icon_info->storage_type = GTK_IMAGE_EMPTY;
6677 g_object_notify (G_OBJECT (entry),
6678 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-storage-type" : "secondary-icon-storage-type");
6680 g_object_thaw_notify (G_OBJECT (entry));
6684 create_normal_pixbuf (GtkStyleContext *context,
6685 const gchar *stock_id,
6686 GtkIconSize icon_size)
6688 GtkIconSet *icon_set;
6691 gtk_style_context_save (context);
6693 /* Unset any state */
6694 gtk_style_context_set_state (context, 0);
6696 icon_set = gtk_style_context_lookup_icon_set (context, stock_id);
6697 pixbuf = gtk_icon_set_render_icon_pixbuf (icon_set, context, icon_size);
6699 gtk_style_context_restore (context);
6705 gtk_entry_ensure_pixbuf (GtkEntry *entry,
6706 GtkEntryIconPosition icon_pos)
6708 GtkEntryPrivate *priv = entry->priv;
6709 EntryIconInfo *icon_info = priv->icons[icon_pos];
6710 GtkStyleContext *context;
6712 GtkIconTheme *icon_theme;
6713 GtkSettings *settings;
6718 if (!icon_info || icon_info->pixbuf)
6721 widget = GTK_WIDGET (entry);
6722 context = gtk_widget_get_style_context (widget);
6724 switch (icon_info->storage_type)
6726 case GTK_IMAGE_EMPTY:
6727 case GTK_IMAGE_PIXBUF:
6729 case GTK_IMAGE_STOCK:
6730 icon_info->pixbuf = create_normal_pixbuf (context, icon_info->stock_id,
6731 GTK_ICON_SIZE_MENU);
6733 if (!icon_info->pixbuf)
6734 icon_info->pixbuf = create_normal_pixbuf (context,
6735 GTK_STOCK_MISSING_IMAGE,
6736 GTK_ICON_SIZE_MENU);
6739 case GTK_IMAGE_ICON_NAME:
6740 screen = gtk_widget_get_screen (widget);
6743 icon_theme = gtk_icon_theme_get_for_screen (screen);
6744 settings = gtk_settings_get_for_screen (screen);
6746 gtk_icon_size_lookup_for_settings (settings,
6750 icon_info->pixbuf = gtk_icon_theme_load_icon (icon_theme,
6751 icon_info->icon_name,
6752 MIN (width, height),
6755 if (icon_info->pixbuf == NULL)
6756 icon_info->pixbuf = create_normal_pixbuf (context,
6757 GTK_STOCK_MISSING_IMAGE,
6758 GTK_ICON_SIZE_MENU);
6762 case GTK_IMAGE_GICON:
6763 screen = gtk_widget_get_screen (widget);
6766 icon_theme = gtk_icon_theme_get_for_screen (screen);
6767 settings = gtk_settings_get_for_screen (screen);
6769 gtk_icon_size_lookup_for_settings (settings,
6773 info = gtk_icon_theme_lookup_by_gicon (icon_theme,
6775 MIN (width, height),
6776 GTK_ICON_LOOKUP_USE_BUILTIN);
6779 icon_info->pixbuf = gtk_icon_info_load_icon (info, NULL);
6780 gtk_icon_info_free (info);
6783 if (icon_info->pixbuf == NULL)
6784 icon_info->pixbuf = create_normal_pixbuf (context,
6785 GTK_STOCK_MISSING_IMAGE,
6786 GTK_ICON_SIZE_MENU);
6791 g_assert_not_reached ();
6795 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
6796 gdk_window_show_unraised (icon_info->window);
6806 * Creates a new entry.
6808 * Return value: a new #GtkEntry.
6811 gtk_entry_new (void)
6813 return g_object_new (GTK_TYPE_ENTRY, NULL);
6817 * gtk_entry_new_with_buffer:
6818 * @buffer: The buffer to use for the new #GtkEntry.
6820 * Creates a new entry with the specified text buffer.
6822 * Return value: a new #GtkEntry
6827 gtk_entry_new_with_buffer (GtkEntryBuffer *buffer)
6829 g_return_val_if_fail (GTK_IS_ENTRY_BUFFER (buffer), NULL);
6830 return g_object_new (GTK_TYPE_ENTRY, "buffer", buffer, NULL);
6833 static GtkEntryBuffer*
6834 get_buffer (GtkEntry *entry)
6836 GtkEntryPrivate *priv = entry->priv;
6838 if (priv->buffer == NULL)
6840 GtkEntryBuffer *buffer;
6841 buffer = gtk_entry_buffer_new (NULL, 0);
6842 gtk_entry_set_buffer (entry, buffer);
6843 g_object_unref (buffer);
6846 return priv->buffer;
6850 * gtk_entry_get_buffer:
6851 * @entry: a #GtkEntry
6853 * Get the #GtkEntryBuffer object which holds the text for
6858 * Returns: (transfer none): A #GtkEntryBuffer object.
6861 gtk_entry_get_buffer (GtkEntry *entry)
6863 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
6865 return get_buffer (entry);
6869 * gtk_entry_set_buffer:
6870 * @entry: a #GtkEntry
6871 * @buffer: a #GtkEntryBuffer
6873 * Set the #GtkEntryBuffer object which holds the text for
6879 gtk_entry_set_buffer (GtkEntry *entry,
6880 GtkEntryBuffer *buffer)
6882 GtkEntryPrivate *priv;
6885 g_return_if_fail (GTK_IS_ENTRY (entry));
6891 g_return_if_fail (GTK_IS_ENTRY_BUFFER (buffer));
6892 g_object_ref (buffer);
6897 buffer_disconnect_signals (entry);
6898 g_object_unref (priv->buffer);
6901 priv->buffer = buffer;
6904 buffer_connect_signals (entry);
6906 obj = G_OBJECT (entry);
6907 g_object_freeze_notify (obj);
6908 g_object_notify (obj, "buffer");
6909 g_object_notify (obj, "text");
6910 g_object_notify (obj, "text-length");
6911 g_object_notify (obj, "max-length");
6912 g_object_notify (obj, "visibility");
6913 g_object_notify (obj, "invisible-char");
6914 g_object_notify (obj, "invisible-char-set");
6915 g_object_thaw_notify (obj);
6917 gtk_editable_set_position (GTK_EDITABLE (entry), 0);
6918 gtk_entry_recompute (entry);
6922 * gtk_entry_get_text_area:
6923 * @entry: a #GtkEntry
6924 * @text_area: (out): Return location for the text area.
6926 * Gets the area where the entry's text is drawn. This function is
6927 * useful when drawing something to the entry in a draw callback.
6929 * If the entry is not realized, @text_area is filled with zeros.
6931 * See also gtk_entry_get_icon_area().
6936 gtk_entry_get_text_area (GtkEntry *entry,
6937 GdkRectangle *text_area)
6939 GtkEntryPrivate *priv;
6941 g_return_if_fail (GTK_IS_ENTRY (entry));
6942 g_return_if_fail (text_area != NULL);
6946 if (priv->text_area)
6948 GtkAllocation allocation;
6951 gtk_widget_get_allocation (GTK_WIDGET (entry), &allocation);
6952 gdk_window_get_position (priv->text_area, &x, &y);
6954 text_area->x = x - allocation.x;
6955 text_area->y = y - allocation.y;
6956 text_area->width = gdk_window_get_width (priv->text_area);
6957 text_area->height = gdk_window_get_height (priv->text_area);
6963 text_area->width = 0;
6964 text_area->height = 0;
6969 * gtk_entry_set_text:
6970 * @entry: a #GtkEntry
6971 * @text: the new text
6973 * Sets the text in the widget to the given
6974 * value, replacing the current contents.
6976 * See gtk_entry_buffer_set_text().
6979 gtk_entry_set_text (GtkEntry *entry,
6983 GtkEntryCompletion *completion;
6985 g_return_if_fail (GTK_IS_ENTRY (entry));
6986 g_return_if_fail (text != NULL);
6988 /* Actually setting the text will affect the cursor and selection;
6989 * if the contents don't actually change, this will look odd to the user.
6991 if (strcmp (gtk_entry_buffer_get_text (get_buffer (entry)), text) == 0)
6994 completion = gtk_entry_get_completion (entry);
6995 if (completion && completion->priv->changed_id > 0)
6996 g_signal_handler_block (entry, completion->priv->changed_id);
6998 begin_change (entry);
6999 g_object_freeze_notify (G_OBJECT (entry));
7000 gtk_editable_delete_text (GTK_EDITABLE (entry), 0, -1);
7002 gtk_editable_insert_text (GTK_EDITABLE (entry), text, strlen (text), &tmp_pos);
7003 g_object_thaw_notify (G_OBJECT (entry));
7006 if (completion && completion->priv->changed_id > 0)
7007 g_signal_handler_unblock (entry, completion->priv->changed_id);
7011 * gtk_entry_set_visibility:
7012 * @entry: a #GtkEntry
7013 * @visible: %TRUE if the contents of the entry are displayed
7016 * Sets whether the contents of the entry are visible or not.
7017 * When visibility is set to %FALSE, characters are displayed
7018 * as the invisible char, and will also appear that way when
7019 * the text in the entry widget is copied elsewhere.
7021 * By default, GTK+ picks the best invisible character available
7022 * in the current font, but it can be changed with
7023 * gtk_entry_set_invisible_char().
7026 gtk_entry_set_visibility (GtkEntry *entry,
7029 GtkEntryPrivate *priv;
7031 g_return_if_fail (GTK_IS_ENTRY (entry));
7035 visible = visible != FALSE;
7037 if (priv->visible != visible)
7039 priv->visible = visible;
7041 g_object_notify (G_OBJECT (entry), "visibility");
7042 gtk_entry_recompute (entry);
7047 * gtk_entry_get_visibility:
7048 * @entry: a #GtkEntry
7050 * Retrieves whether the text in @entry is visible. See
7051 * gtk_entry_set_visibility().
7053 * Return value: %TRUE if the text is currently visible
7056 gtk_entry_get_visibility (GtkEntry *entry)
7058 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7060 return entry->priv->visible;
7064 * gtk_entry_set_invisible_char:
7065 * @entry: a #GtkEntry
7066 * @ch: a Unicode character
7068 * Sets the character to use in place of the actual text when
7069 * gtk_entry_set_visibility() has been called to set text visibility
7070 * to %FALSE. i.e. this is the character used in "password mode" to
7071 * show the user how many characters have been typed. By default, GTK+
7072 * picks the best invisible char available in the current font. If you
7073 * set the invisible char to 0, then the user will get no feedback
7074 * at all; there will be no text on the screen as they type.
7077 gtk_entry_set_invisible_char (GtkEntry *entry,
7080 GtkEntryPrivate *priv;
7082 g_return_if_fail (GTK_IS_ENTRY (entry));
7086 if (!priv->invisible_char_set)
7088 priv->invisible_char_set = TRUE;
7089 g_object_notify (G_OBJECT (entry), "invisible-char-set");
7092 if (ch == priv->invisible_char)
7095 priv->invisible_char = ch;
7096 g_object_notify (G_OBJECT (entry), "invisible-char");
7097 gtk_entry_recompute (entry);
7101 * gtk_entry_get_invisible_char:
7102 * @entry: a #GtkEntry
7104 * Retrieves the character displayed in place of the real characters
7105 * for entries with visibility set to false. See gtk_entry_set_invisible_char().
7107 * Return value: the current invisible char, or 0, if the entry does not
7108 * show invisible text at all.
7111 gtk_entry_get_invisible_char (GtkEntry *entry)
7113 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7115 return entry->priv->invisible_char;
7119 * gtk_entry_unset_invisible_char:
7120 * @entry: a #GtkEntry
7122 * Unsets the invisible char previously set with
7123 * gtk_entry_set_invisible_char(). So that the
7124 * default invisible char is used again.
7129 gtk_entry_unset_invisible_char (GtkEntry *entry)
7131 GtkEntryPrivate *priv;
7134 g_return_if_fail (GTK_IS_ENTRY (entry));
7138 if (!priv->invisible_char_set)
7141 priv->invisible_char_set = FALSE;
7142 ch = find_invisible_char (GTK_WIDGET (entry));
7144 if (priv->invisible_char != ch)
7146 priv->invisible_char = ch;
7147 g_object_notify (G_OBJECT (entry), "invisible-char");
7150 g_object_notify (G_OBJECT (entry), "invisible-char-set");
7151 gtk_entry_recompute (entry);
7155 * gtk_entry_set_overwrite_mode:
7156 * @entry: a #GtkEntry
7157 * @overwrite: new value
7159 * Sets whether the text is overwritten when typing in the #GtkEntry.
7164 gtk_entry_set_overwrite_mode (GtkEntry *entry,
7167 GtkEntryPrivate *priv = entry->priv;
7169 g_return_if_fail (GTK_IS_ENTRY (entry));
7171 if (priv->overwrite_mode == overwrite)
7174 gtk_entry_toggle_overwrite (entry);
7176 g_object_notify (G_OBJECT (entry), "overwrite-mode");
7180 * gtk_entry_get_overwrite_mode:
7181 * @entry: a #GtkEntry
7183 * Gets the value set by gtk_entry_set_overwrite_mode().
7185 * Return value: whether the text is overwritten when typing.
7190 gtk_entry_get_overwrite_mode (GtkEntry *entry)
7192 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7194 return entry->priv->overwrite_mode;
7198 * gtk_entry_get_text:
7199 * @entry: a #GtkEntry
7201 * Retrieves the contents of the entry widget.
7202 * See also gtk_editable_get_chars().
7204 * This is equivalent to:
7206 * <informalexample><programlisting>
7207 * gtk_entry_buffer_get_text (gtk_entry_get_buffer (entry));
7208 * </programlisting></informalexample>
7210 * Return value: a pointer to the contents of the widget as a
7211 * string. This string points to internally allocated
7212 * storage in the widget and must not be freed, modified or
7215 G_CONST_RETURN gchar*
7216 gtk_entry_get_text (GtkEntry *entry)
7218 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7220 return gtk_entry_buffer_get_text (get_buffer (entry));
7224 * gtk_entry_set_max_length:
7225 * @entry: a #GtkEntry
7226 * @max: the maximum length of the entry, or 0 for no maximum.
7227 * (other than the maximum length of entries.) The value passed in will
7228 * be clamped to the range 0-65536.
7230 * Sets the maximum allowed length of the contents of the widget. If
7231 * the current contents are longer than the given length, then they
7232 * will be truncated to fit.
7234 * This is equivalent to:
7236 * <informalexample><programlisting>
7237 * gtk_entry_buffer_set_max_length (gtk_entry_get_buffer (entry), max);
7238 * </programlisting></informalexample>
7241 gtk_entry_set_max_length (GtkEntry *entry,
7244 g_return_if_fail (GTK_IS_ENTRY (entry));
7245 gtk_entry_buffer_set_max_length (get_buffer (entry), max);
7249 * gtk_entry_get_max_length:
7250 * @entry: a #GtkEntry
7252 * Retrieves the maximum allowed length of the text in
7253 * @entry. See gtk_entry_set_max_length().
7255 * This is equivalent to:
7257 * <informalexample><programlisting>
7258 * gtk_entry_buffer_get_max_length (gtk_entry_get_buffer (entry));
7259 * </programlisting></informalexample>
7261 * Return value: the maximum allowed number of characters
7262 * in #GtkEntry, or 0 if there is no maximum.
7265 gtk_entry_get_max_length (GtkEntry *entry)
7267 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7269 return gtk_entry_buffer_get_max_length (get_buffer (entry));
7273 * gtk_entry_get_text_length:
7274 * @entry: a #GtkEntry
7276 * Retrieves the current length of the text in
7279 * This is equivalent to:
7281 * <informalexample><programlisting>
7282 * gtk_entry_buffer_get_length (gtk_entry_get_buffer (entry));
7283 * </programlisting></informalexample>
7285 * Return value: the current number of characters
7286 * in #GtkEntry, or 0 if there are none.
7291 gtk_entry_get_text_length (GtkEntry *entry)
7293 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7295 return gtk_entry_buffer_get_length (get_buffer (entry));
7299 * gtk_entry_set_activates_default:
7300 * @entry: a #GtkEntry
7301 * @setting: %TRUE to activate window's default widget on Enter keypress
7303 * If @setting is %TRUE, pressing Enter in the @entry will activate the default
7304 * widget for the window containing the entry. This usually means that
7305 * the dialog box containing the entry will be closed, since the default
7306 * widget is usually one of the dialog buttons.
7308 * (For experts: if @setting is %TRUE, the entry calls
7309 * gtk_window_activate_default() on the window containing the entry, in
7310 * the default handler for the #GtkWidget::activate signal.)
7313 gtk_entry_set_activates_default (GtkEntry *entry,
7316 GtkEntryPrivate *priv;
7318 g_return_if_fail (GTK_IS_ENTRY (entry));
7322 setting = setting != FALSE;
7324 if (setting != priv->activates_default)
7326 priv->activates_default = setting;
7327 g_object_notify (G_OBJECT (entry), "activates-default");
7332 * gtk_entry_get_activates_default:
7333 * @entry: a #GtkEntry
7335 * Retrieves the value set by gtk_entry_set_activates_default().
7337 * Return value: %TRUE if the entry will activate the default widget
7340 gtk_entry_get_activates_default (GtkEntry *entry)
7342 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7344 return entry->priv->activates_default;
7348 * gtk_entry_set_width_chars:
7349 * @entry: a #GtkEntry
7350 * @n_chars: width in chars
7352 * Changes the size request of the entry to be about the right size
7353 * for @n_chars characters. Note that it changes the size
7354 * <emphasis>request</emphasis>, the size can still be affected by
7355 * how you pack the widget into containers. If @n_chars is -1, the
7356 * size reverts to the default entry size.
7359 gtk_entry_set_width_chars (GtkEntry *entry,
7362 GtkEntryPrivate *priv;
7364 g_return_if_fail (GTK_IS_ENTRY (entry));
7368 if (priv->width_chars != n_chars)
7370 priv->width_chars = n_chars;
7371 g_object_notify (G_OBJECT (entry), "width-chars");
7372 gtk_widget_queue_resize (GTK_WIDGET (entry));
7377 * gtk_entry_get_width_chars:
7378 * @entry: a #GtkEntry
7380 * Gets the value set by gtk_entry_set_width_chars().
7382 * Return value: number of chars to request space for, or negative if unset
7385 gtk_entry_get_width_chars (GtkEntry *entry)
7387 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7389 return entry->priv->width_chars;
7393 * gtk_entry_set_has_frame:
7394 * @entry: a #GtkEntry
7395 * @setting: new value
7397 * Sets whether the entry has a beveled frame around it.
7400 gtk_entry_set_has_frame (GtkEntry *entry,
7403 GtkEntryPrivate *priv;
7405 g_return_if_fail (GTK_IS_ENTRY (entry));
7409 setting = (setting != FALSE);
7411 if (priv->has_frame == setting)
7414 gtk_widget_queue_resize (GTK_WIDGET (entry));
7415 priv->has_frame = setting;
7416 g_object_notify (G_OBJECT (entry), "has-frame");
7420 * gtk_entry_get_has_frame:
7421 * @entry: a #GtkEntry
7423 * Gets the value set by gtk_entry_set_has_frame().
7425 * Return value: whether the entry has a beveled frame
7428 gtk_entry_get_has_frame (GtkEntry *entry)
7430 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7432 return entry->priv->has_frame;
7436 * gtk_entry_set_inner_border:
7437 * @entry: a #GtkEntry
7438 * @border: (allow-none): a #GtkBorder, or %NULL
7440 * Sets %entry's inner-border property to %border, or clears it if %NULL
7441 * is passed. The inner-border is the area around the entry's text, but
7444 * If set, this property overrides the inner-border style property.
7445 * Overriding the style-provided border is useful when you want to do
7446 * in-place editing of some text in a canvas or list widget, where
7447 * pixel-exact positioning of the entry is important.
7452 gtk_entry_set_inner_border (GtkEntry *entry,
7453 const GtkBorder *border)
7455 g_return_if_fail (GTK_IS_ENTRY (entry));
7457 gtk_widget_queue_resize (GTK_WIDGET (entry));
7460 g_object_set_qdata_full (G_OBJECT (entry), quark_inner_border,
7461 gtk_border_copy (border),
7462 (GDestroyNotify) gtk_border_free);
7464 g_object_set_qdata (G_OBJECT (entry), quark_inner_border, NULL);
7466 g_object_notify (G_OBJECT (entry), "inner-border");
7470 * gtk_entry_get_inner_border:
7471 * @entry: a #GtkEntry
7473 * This function returns the entry's #GtkEntry:inner-border property. See
7474 * gtk_entry_set_inner_border() for more information.
7476 * Return value: (transfer none): the entry's #GtkBorder, or %NULL if none was set.
7480 G_CONST_RETURN GtkBorder *
7481 gtk_entry_get_inner_border (GtkEntry *entry)
7483 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7485 return g_object_get_qdata (G_OBJECT (entry), quark_inner_border);
7489 * gtk_entry_get_layout:
7490 * @entry: a #GtkEntry
7492 * Gets the #PangoLayout used to display the entry.
7493 * The layout is useful to e.g. convert text positions to
7494 * pixel positions, in combination with gtk_entry_get_layout_offsets().
7495 * The returned layout is owned by the entry and must not be
7496 * modified or freed by the caller.
7498 * Keep in mind that the layout text may contain a preedit string, so
7499 * gtk_entry_layout_index_to_text_index() and
7500 * gtk_entry_text_index_to_layout_index() are needed to convert byte
7501 * indices in the layout to byte indices in the entry contents.
7503 * Return value: (transfer none): the #PangoLayout for this entry
7506 gtk_entry_get_layout (GtkEntry *entry)
7508 PangoLayout *layout;
7510 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7512 layout = gtk_entry_ensure_layout (entry, TRUE);
7519 * gtk_entry_layout_index_to_text_index:
7520 * @entry: a #GtkEntry
7521 * @layout_index: byte index into the entry layout text
7523 * Converts from a position in the entry contents (returned
7524 * by gtk_entry_get_text()) to a position in the
7525 * entry's #PangoLayout (returned by gtk_entry_get_layout(),
7526 * with text retrieved via pango_layout_get_text()).
7528 * Return value: byte index into the entry contents
7531 gtk_entry_layout_index_to_text_index (GtkEntry *entry,
7534 GtkEntryPrivate *priv;
7535 PangoLayout *layout;
7539 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7543 layout = gtk_entry_ensure_layout (entry, TRUE);
7544 text = pango_layout_get_text (layout);
7545 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos) - text;
7547 if (layout_index >= cursor_index && priv->preedit_length)
7549 if (layout_index >= cursor_index + priv->preedit_length)
7550 layout_index -= priv->preedit_length;
7552 layout_index = cursor_index;
7555 return layout_index;
7559 * gtk_entry_text_index_to_layout_index:
7560 * @entry: a #GtkEntry
7561 * @text_index: byte index into the entry contents
7563 * Converts from a position in the entry's #PangoLayout (returned by
7564 * gtk_entry_get_layout()) to a position in the entry contents
7565 * (returned by gtk_entry_get_text()).
7567 * Return value: byte index into the entry layout text
7570 gtk_entry_text_index_to_layout_index (GtkEntry *entry,
7573 GtkEntryPrivate *priv;
7574 PangoLayout *layout;
7578 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7582 layout = gtk_entry_ensure_layout (entry, TRUE);
7583 text = pango_layout_get_text (layout);
7584 cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos) - text;
7586 if (text_index > cursor_index)
7587 text_index += priv->preedit_length;
7593 * gtk_entry_get_layout_offsets:
7594 * @entry: a #GtkEntry
7595 * @x: (out) (allow-none): location to store X offset of layout, or %NULL
7596 * @y: (out) (allow-none): location to store Y offset of layout, or %NULL
7599 * Obtains the position of the #PangoLayout used to render text
7600 * in the entry, in widget coordinates. Useful if you want to line
7601 * up the text in an entry with some other text, e.g. when using the
7602 * entry to implement editable cells in a sheet widget.
7604 * Also useful to convert mouse events into coordinates inside the
7605 * #PangoLayout, e.g. to take some action if some part of the entry text
7608 * Note that as the user scrolls around in the entry the offsets will
7609 * change; you'll need to connect to the "notify::scroll-offset"
7610 * signal to track this. Remember when using the #PangoLayout
7611 * functions you need to convert to and from pixels using
7612 * PANGO_PIXELS() or #PANGO_SCALE.
7614 * Keep in mind that the layout text may contain a preedit string, so
7615 * gtk_entry_layout_index_to_text_index() and
7616 * gtk_entry_text_index_to_layout_index() are needed to convert byte
7617 * indices in the layout to byte indices in the entry contents.
7620 gtk_entry_get_layout_offsets (GtkEntry *entry,
7624 gint text_area_x, text_area_y;
7626 g_return_if_fail (GTK_IS_ENTRY (entry));
7628 /* this gets coords relative to text area */
7629 get_layout_position (entry, x, y);
7631 /* convert to widget coords */
7632 gtk_entry_get_text_area_size (entry, &text_area_x, &text_area_y, NULL, NULL);
7643 * gtk_entry_set_alignment:
7644 * @entry: a #GtkEntry
7645 * @xalign: The horizontal alignment, from 0 (left) to 1 (right).
7646 * Reversed for RTL layouts
7648 * Sets the alignment for the contents of the entry. This controls
7649 * the horizontal positioning of the contents when the displayed
7650 * text is shorter than the width of the entry.
7655 gtk_entry_set_alignment (GtkEntry *entry, gfloat xalign)
7657 GtkEntryPrivate *priv;
7659 g_return_if_fail (GTK_IS_ENTRY (entry));
7665 else if (xalign > 1.0)
7668 if (xalign != priv->xalign)
7670 priv->xalign = xalign;
7672 gtk_entry_recompute (entry);
7674 g_object_notify (G_OBJECT (entry), "xalign");
7679 * gtk_entry_get_alignment:
7680 * @entry: a #GtkEntry
7682 * Gets the value set by gtk_entry_set_alignment().
7684 * Return value: the alignment
7689 gtk_entry_get_alignment (GtkEntry *entry)
7691 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
7693 return entry->priv->xalign;
7697 * gtk_entry_set_icon_from_pixbuf:
7698 * @entry: a #GtkEntry
7699 * @icon_pos: Icon position
7700 * @pixbuf: (allow-none): A #GdkPixbuf, or %NULL
7702 * Sets the icon shown in the specified position using a pixbuf.
7704 * If @pixbuf is %NULL, no icon will be shown in the specified position.
7709 gtk_entry_set_icon_from_pixbuf (GtkEntry *entry,
7710 GtkEntryIconPosition icon_pos,
7713 GtkEntryPrivate *priv;
7714 EntryIconInfo *icon_info;
7716 g_return_if_fail (GTK_IS_ENTRY (entry));
7717 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7721 if ((icon_info = priv->icons[icon_pos]) == NULL)
7722 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7724 g_object_freeze_notify (G_OBJECT (entry));
7727 g_object_ref (pixbuf);
7729 gtk_entry_clear (entry, icon_pos);
7733 icon_info->storage_type = GTK_IMAGE_PIXBUF;
7734 icon_info->pixbuf = pixbuf;
7736 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7738 g_object_notify (G_OBJECT (entry), "primary-icon-pixbuf");
7739 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7743 g_object_notify (G_OBJECT (entry), "secondary-icon-pixbuf");
7744 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7747 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7748 gdk_window_show_unraised (icon_info->window);
7751 gtk_entry_ensure_pixbuf (entry, icon_pos);
7753 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7754 gtk_widget_queue_resize (GTK_WIDGET (entry));
7756 g_object_thaw_notify (G_OBJECT (entry));
7760 * gtk_entry_set_icon_from_stock:
7761 * @entry: A #GtkEntry
7762 * @icon_pos: Icon position
7763 * @stock_id: (allow-none): The name of the stock item, or %NULL
7765 * Sets the icon shown in the entry at the specified position from
7768 * If @stock_id is %NULL, no icon will be shown in the specified position.
7773 gtk_entry_set_icon_from_stock (GtkEntry *entry,
7774 GtkEntryIconPosition icon_pos,
7775 const gchar *stock_id)
7777 GtkEntryPrivate *priv;
7778 EntryIconInfo *icon_info;
7781 g_return_if_fail (GTK_IS_ENTRY (entry));
7782 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7786 if ((icon_info = priv->icons[icon_pos]) == NULL)
7787 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7789 g_object_freeze_notify (G_OBJECT (entry));
7791 /* need to dup before clearing */
7792 new_id = g_strdup (stock_id);
7794 gtk_entry_clear (entry, icon_pos);
7798 icon_info->storage_type = GTK_IMAGE_STOCK;
7799 icon_info->stock_id = new_id;
7801 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7803 g_object_notify (G_OBJECT (entry), "primary-icon-stock");
7804 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7808 g_object_notify (G_OBJECT (entry), "secondary-icon-stock");
7809 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7812 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7813 gdk_window_show_unraised (icon_info->window);
7816 gtk_entry_ensure_pixbuf (entry, icon_pos);
7818 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7819 gtk_widget_queue_resize (GTK_WIDGET (entry));
7821 g_object_thaw_notify (G_OBJECT (entry));
7825 * gtk_entry_set_icon_from_icon_name:
7826 * @entry: A #GtkEntry
7827 * @icon_pos: The position at which to set the icon
7828 * @icon_name: (allow-none): An icon name, or %NULL
7830 * Sets the icon shown in the entry at the specified position
7831 * from the current icon theme.
7833 * If the icon name isn't known, a "broken image" icon will be displayed
7836 * If @icon_name is %NULL, no icon will be shown in the specified position.
7841 gtk_entry_set_icon_from_icon_name (GtkEntry *entry,
7842 GtkEntryIconPosition icon_pos,
7843 const gchar *icon_name)
7845 GtkEntryPrivate *priv;
7846 EntryIconInfo *icon_info;
7849 g_return_if_fail (GTK_IS_ENTRY (entry));
7850 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7854 if ((icon_info = priv->icons[icon_pos]) == NULL)
7855 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7857 g_object_freeze_notify (G_OBJECT (entry));
7859 /* need to dup before clearing */
7860 new_name = g_strdup (icon_name);
7862 gtk_entry_clear (entry, icon_pos);
7864 if (new_name != NULL)
7866 icon_info->storage_type = GTK_IMAGE_ICON_NAME;
7867 icon_info->icon_name = new_name;
7869 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7871 g_object_notify (G_OBJECT (entry), "primary-icon-name");
7872 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7876 g_object_notify (G_OBJECT (entry), "secondary-icon-name");
7877 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7880 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7881 gdk_window_show_unraised (icon_info->window);
7884 gtk_entry_ensure_pixbuf (entry, icon_pos);
7886 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7887 gtk_widget_queue_resize (GTK_WIDGET (entry));
7889 g_object_thaw_notify (G_OBJECT (entry));
7893 * gtk_entry_set_icon_from_gicon:
7894 * @entry: A #GtkEntry
7895 * @icon_pos: The position at which to set the icon
7896 * @icon: (allow-none): The icon to set, or %NULL
7898 * Sets the icon shown in the entry at the specified position
7899 * from the current icon theme.
7900 * If the icon isn't known, a "broken image" icon will be displayed
7903 * If @icon is %NULL, no icon will be shown in the specified position.
7908 gtk_entry_set_icon_from_gicon (GtkEntry *entry,
7909 GtkEntryIconPosition icon_pos,
7912 GtkEntryPrivate *priv;
7913 EntryIconInfo *icon_info;
7915 g_return_if_fail (GTK_IS_ENTRY (entry));
7916 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7920 if ((icon_info = priv->icons[icon_pos]) == NULL)
7921 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7923 g_object_freeze_notify (G_OBJECT (entry));
7925 /* need to ref before clearing */
7927 g_object_ref (icon);
7929 gtk_entry_clear (entry, icon_pos);
7933 icon_info->storage_type = GTK_IMAGE_GICON;
7934 icon_info->gicon = icon;
7936 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7938 g_object_notify (G_OBJECT (entry), "primary-icon-gicon");
7939 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7943 g_object_notify (G_OBJECT (entry), "secondary-icon-gicon");
7944 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7947 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7948 gdk_window_show_unraised (icon_info->window);
7951 gtk_entry_ensure_pixbuf (entry, icon_pos);
7953 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7954 gtk_widget_queue_resize (GTK_WIDGET (entry));
7956 g_object_thaw_notify (G_OBJECT (entry));
7960 * gtk_entry_set_icon_activatable:
7961 * @entry: A #GtkEntry
7962 * @icon_pos: Icon position
7963 * @activatable: %TRUE if the icon should be activatable
7965 * Sets whether the icon is activatable.
7970 gtk_entry_set_icon_activatable (GtkEntry *entry,
7971 GtkEntryIconPosition icon_pos,
7972 gboolean activatable)
7974 GtkEntryPrivate *priv;
7975 EntryIconInfo *icon_info;
7977 g_return_if_fail (GTK_IS_ENTRY (entry));
7978 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7982 if ((icon_info = priv->icons[icon_pos]) == NULL)
7983 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7985 activatable = activatable != FALSE;
7987 if (icon_info->nonactivatable != !activatable)
7989 icon_info->nonactivatable = !activatable;
7991 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
7992 update_cursors (GTK_WIDGET (entry));
7994 g_object_notify (G_OBJECT (entry),
7995 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-activatable" : "secondary-icon-activatable");
8000 * gtk_entry_get_icon_activatable:
8001 * @entry: a #GtkEntry
8002 * @icon_pos: Icon position
8004 * Returns whether the icon is activatable.
8006 * Returns: %TRUE if the icon is activatable.
8011 gtk_entry_get_icon_activatable (GtkEntry *entry,
8012 GtkEntryIconPosition icon_pos)
8014 GtkEntryPrivate *priv;
8015 EntryIconInfo *icon_info;
8017 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
8018 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), FALSE);
8021 icon_info = priv->icons[icon_pos];
8023 return (!icon_info || !icon_info->nonactivatable);
8027 * gtk_entry_get_icon_pixbuf:
8028 * @entry: A #GtkEntry
8029 * @icon_pos: Icon position
8031 * Retrieves the image used for the icon.
8033 * Unlike the other methods of setting and getting icon data, this
8034 * method will work regardless of whether the icon was set using a
8035 * #GdkPixbuf, a #GIcon, a stock item, or an icon name.
8037 * Returns: (transfer none): A #GdkPixbuf, or %NULL if no icon is
8038 * set for this position.
8043 gtk_entry_get_icon_pixbuf (GtkEntry *entry,
8044 GtkEntryIconPosition icon_pos)
8046 GtkEntryPrivate *priv;
8047 EntryIconInfo *icon_info;
8049 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8050 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8054 icon_info = priv->icons[icon_pos];
8059 gtk_entry_ensure_pixbuf (entry, icon_pos);
8061 return icon_info->pixbuf;
8065 * gtk_entry_get_icon_gicon:
8066 * @entry: A #GtkEntry
8067 * @icon_pos: Icon position
8069 * Retrieves the #GIcon used for the icon, or %NULL if there is
8070 * no icon or if the icon was set by some other method (e.g., by
8071 * stock, pixbuf, or icon name).
8073 * Returns: (transfer none): A #GIcon, or %NULL if no icon is set
8074 * or if the icon is not a #GIcon
8079 gtk_entry_get_icon_gicon (GtkEntry *entry,
8080 GtkEntryIconPosition icon_pos)
8082 GtkEntryPrivate *priv;
8083 EntryIconInfo *icon_info;
8085 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8086 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8089 icon_info = priv->icons[icon_pos];
8094 return icon_info->storage_type == GTK_IMAGE_GICON ? icon_info->gicon : NULL;
8098 * gtk_entry_get_icon_stock:
8099 * @entry: A #GtkEntry
8100 * @icon_pos: Icon position
8102 * Retrieves the stock id used for the icon, or %NULL if there is
8103 * no icon or if the icon was set by some other method (e.g., by
8104 * pixbuf, icon name or gicon).
8106 * Returns: A stock id, or %NULL if no icon is set or if the icon
8107 * wasn't set from a stock id
8112 gtk_entry_get_icon_stock (GtkEntry *entry,
8113 GtkEntryIconPosition icon_pos)
8115 GtkEntryPrivate *priv;
8116 EntryIconInfo *icon_info;
8118 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8119 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8122 icon_info = priv->icons[icon_pos];
8127 return icon_info->storage_type == GTK_IMAGE_STOCK ? icon_info->stock_id : NULL;
8131 * gtk_entry_get_icon_name:
8132 * @entry: A #GtkEntry
8133 * @icon_pos: Icon position
8135 * Retrieves the icon name used for the icon, or %NULL if there is
8136 * no icon or if the icon was set by some other method (e.g., by
8137 * pixbuf, stock or gicon).
8139 * Returns: An icon name, or %NULL if no icon is set or if the icon
8140 * wasn't set from an icon name
8145 gtk_entry_get_icon_name (GtkEntry *entry,
8146 GtkEntryIconPosition icon_pos)
8148 GtkEntryPrivate *priv;
8149 EntryIconInfo *icon_info;
8151 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8152 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8155 icon_info = priv->icons[icon_pos];
8160 return icon_info->storage_type == GTK_IMAGE_ICON_NAME ? icon_info->icon_name : NULL;
8164 * gtk_entry_set_icon_sensitive:
8165 * @entry: A #GtkEntry
8166 * @icon_pos: Icon position
8167 * @sensitive: Specifies whether the icon should appear
8168 * sensitive or insensitive
8170 * Sets the sensitivity for the specified icon.
8175 gtk_entry_set_icon_sensitive (GtkEntry *entry,
8176 GtkEntryIconPosition icon_pos,
8179 GtkEntryPrivate *priv;
8180 EntryIconInfo *icon_info;
8182 g_return_if_fail (GTK_IS_ENTRY (entry));
8183 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8187 if ((icon_info = priv->icons[icon_pos]) == NULL)
8188 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8190 if (icon_info->insensitive != !sensitive)
8192 icon_info->insensitive = !sensitive;
8194 icon_info->pressed = FALSE;
8195 icon_info->prelight = FALSE;
8197 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
8198 update_cursors (GTK_WIDGET (entry));
8200 gtk_widget_queue_draw (GTK_WIDGET (entry));
8202 g_object_notify (G_OBJECT (entry),
8203 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-sensitive" : "secondary-icon-sensitive");
8208 * gtk_entry_get_icon_sensitive:
8209 * @entry: a #GtkEntry
8210 * @icon_pos: Icon position
8212 * Returns whether the icon appears sensitive or insensitive.
8214 * Returns: %TRUE if the icon is sensitive.
8219 gtk_entry_get_icon_sensitive (GtkEntry *entry,
8220 GtkEntryIconPosition icon_pos)
8222 GtkEntryPrivate *priv;
8223 EntryIconInfo *icon_info;
8225 g_return_val_if_fail (GTK_IS_ENTRY (entry), TRUE);
8226 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), TRUE);
8230 icon_info = priv->icons[icon_pos];
8232 return (!icon_info || !icon_info->insensitive);
8237 * gtk_entry_get_icon_storage_type:
8238 * @entry: a #GtkEntry
8239 * @icon_pos: Icon position
8241 * Gets the type of representation being used by the icon
8242 * to store image data. If the icon has no image data,
8243 * the return value will be %GTK_IMAGE_EMPTY.
8245 * Return value: image representation being used
8250 gtk_entry_get_icon_storage_type (GtkEntry *entry,
8251 GtkEntryIconPosition icon_pos)
8253 GtkEntryPrivate *priv;
8254 EntryIconInfo *icon_info;
8256 g_return_val_if_fail (GTK_IS_ENTRY (entry), GTK_IMAGE_EMPTY);
8257 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), GTK_IMAGE_EMPTY);
8261 icon_info = priv->icons[icon_pos];
8264 return GTK_IMAGE_EMPTY;
8266 return icon_info->storage_type;
8270 * gtk_entry_get_icon_at_pos:
8271 * @entry: a #GtkEntry
8272 * @x: the x coordinate of the position to find
8273 * @y: the y coordinate of the position to find
8275 * Finds the icon at the given position and return its index.
8276 * If @x, @y doesn't lie inside an icon, -1 is returned.
8277 * This function is intended for use in a #GtkWidget::query-tooltip
8280 * Returns: the index of the icon at the given position, or -1
8285 gtk_entry_get_icon_at_pos (GtkEntry *entry,
8289 GtkAllocation primary;
8290 GtkAllocation secondary;
8291 gint frame_x, frame_y;
8293 g_return_val_if_fail (GTK_IS_ENTRY (entry), -1);
8295 get_frame_size (entry, TRUE, &frame_x, &frame_y, NULL, NULL);
8299 get_icon_allocations (entry, &primary, &secondary);
8301 if (primary.x <= x && x < primary.x + primary.width &&
8302 primary.y <= y && y < primary.y + primary.height)
8303 return GTK_ENTRY_ICON_PRIMARY;
8305 if (secondary.x <= x && x < secondary.x + secondary.width &&
8306 secondary.y <= y && y < secondary.y + secondary.height)
8307 return GTK_ENTRY_ICON_SECONDARY;
8313 * gtk_entry_set_icon_drag_source:
8314 * @entry: a #GtkIconEntry
8315 * @icon_pos: icon position
8316 * @target_list: the targets (data formats) in which the data can be provided
8317 * @actions: a bitmask of the allowed drag actions
8319 * Sets up the icon at the given position so that GTK+ will start a drag
8320 * operation when the user clicks and drags the icon.
8322 * To handle the drag operation, you need to connect to the usual
8323 * #GtkWidget::drag-data-get (or possibly #GtkWidget::drag-data-delete)
8324 * signal, and use gtk_entry_get_current_icon_drag_source() in
8325 * your signal handler to find out if the drag was started from
8328 * By default, GTK+ uses the icon as the drag icon. You can use the
8329 * #GtkWidget::drag-begin signal to set a different icon. Note that you
8330 * have to use g_signal_connect_after() to ensure that your signal handler
8331 * gets executed after the default handler.
8336 gtk_entry_set_icon_drag_source (GtkEntry *entry,
8337 GtkEntryIconPosition icon_pos,
8338 GtkTargetList *target_list,
8339 GdkDragAction actions)
8341 GtkEntryPrivate *priv;
8342 EntryIconInfo *icon_info;
8344 g_return_if_fail (GTK_IS_ENTRY (entry));
8345 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8349 if ((icon_info = priv->icons[icon_pos]) == NULL)
8350 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8352 if (icon_info->target_list)
8353 gtk_target_list_unref (icon_info->target_list);
8354 icon_info->target_list = target_list;
8355 if (icon_info->target_list)
8356 gtk_target_list_ref (icon_info->target_list);
8358 icon_info->actions = actions;
8362 * gtk_entry_get_current_icon_drag_source:
8363 * @entry: a #GtkIconEntry
8365 * Returns the index of the icon which is the source of the current
8366 * DND operation, or -1.
8368 * This function is meant to be used in a #GtkWidget::drag-data-get
8371 * Returns: index of the icon which is the source of the current
8372 * DND operation, or -1.
8377 gtk_entry_get_current_icon_drag_source (GtkEntry *entry)
8379 GtkEntryPrivate *priv;
8380 EntryIconInfo *icon_info = NULL;
8383 g_return_val_if_fail (GTK_IS_ENTRY (entry), -1);
8387 for (i = 0; i < MAX_ICONS; i++)
8389 if ((icon_info = priv->icons[i]))
8391 if (icon_info->in_drag)
8400 * gtk_entry_get_icon_area:
8401 * @entry: A #GtkEntry
8402 * @icon_pos: Icon position
8403 * @icon_area: (out): Return location for the icon's area
8405 * Gets the area where entry's icon at @icon_pos is drawn.
8406 * This function is useful when drawing something to the
8407 * entry in a draw callback.
8409 * If the entry is not realized or has no icon at the given position,
8410 * @icon_area is filled with zeros.
8412 * See also gtk_entry_get_text_area()
8417 gtk_entry_get_icon_area (GtkEntry *entry,
8418 GtkEntryIconPosition icon_pos,
8419 GdkRectangle *icon_area)
8421 GtkEntryPrivate *priv;
8422 EntryIconInfo *icon_info;
8424 g_return_if_fail (GTK_IS_ENTRY (entry));
8425 g_return_if_fail (icon_area != NULL);
8429 icon_info = priv->icons[icon_pos];
8433 GtkAllocation primary;
8434 GtkAllocation secondary;
8436 get_icon_allocations (entry, &primary, &secondary);
8438 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
8439 *icon_area = primary;
8441 *icon_area = secondary;
8447 icon_area->width = 0;
8448 icon_area->height = 0;
8453 ensure_has_tooltip (GtkEntry *entry)
8455 GtkEntryPrivate *priv;
8456 EntryIconInfo *icon_info;
8458 gboolean has_tooltip = FALSE;
8462 for (i = 0; i < MAX_ICONS; i++)
8464 if ((icon_info = priv->icons[i]) != NULL)
8466 if (icon_info->tooltip != NULL)
8474 gtk_widget_set_has_tooltip (GTK_WIDGET (entry), has_tooltip);
8478 * gtk_entry_get_icon_tooltip_text:
8479 * @entry: a #GtkEntry
8480 * @icon_pos: the icon position
8482 * Gets the contents of the tooltip on the icon at the specified
8483 * position in @entry.
8485 * Returns: the tooltip text, or %NULL. Free the returned string
8486 * with g_free() when done.
8491 gtk_entry_get_icon_tooltip_text (GtkEntry *entry,
8492 GtkEntryIconPosition icon_pos)
8494 GtkEntryPrivate *priv;
8495 EntryIconInfo *icon_info;
8498 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8499 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8503 icon_info = priv->icons[icon_pos];
8508 if (icon_info->tooltip &&
8509 !pango_parse_markup (icon_info->tooltip, -1, 0, NULL, &text, NULL, NULL))
8510 g_assert (NULL == text); /* text should still be NULL in case of markup errors */
8516 * gtk_entry_set_icon_tooltip_text:
8517 * @entry: a #GtkEntry
8518 * @icon_pos: the icon position
8519 * @tooltip: (allow-none): the contents of the tooltip for the icon, or %NULL
8521 * Sets @tooltip as the contents of the tooltip for the icon
8522 * at the specified position.
8524 * Use %NULL for @tooltip to remove an existing tooltip.
8526 * See also gtk_widget_set_tooltip_text() and
8527 * gtk_entry_set_icon_tooltip_markup().
8532 gtk_entry_set_icon_tooltip_text (GtkEntry *entry,
8533 GtkEntryIconPosition icon_pos,
8534 const gchar *tooltip)
8536 GtkEntryPrivate *priv;
8537 EntryIconInfo *icon_info;
8539 g_return_if_fail (GTK_IS_ENTRY (entry));
8540 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8544 if ((icon_info = priv->icons[icon_pos]) == NULL)
8545 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8547 if (icon_info->tooltip)
8548 g_free (icon_info->tooltip);
8550 /* Treat an empty string as a NULL string,
8551 * because an empty string would be useless for a tooltip:
8553 if (tooltip && tooltip[0] == '\0')
8556 icon_info->tooltip = tooltip ? g_markup_escape_text (tooltip, -1) : NULL;
8558 ensure_has_tooltip (entry);
8562 * gtk_entry_get_icon_tooltip_markup:
8563 * @entry: a #GtkEntry
8564 * @icon_pos: the icon position
8566 * Gets the contents of the tooltip on the icon at the specified
8567 * position in @entry.
8569 * Returns: the tooltip text, or %NULL. Free the returned string
8570 * with g_free() when done.
8575 gtk_entry_get_icon_tooltip_markup (GtkEntry *entry,
8576 GtkEntryIconPosition icon_pos)
8578 GtkEntryPrivate *priv;
8579 EntryIconInfo *icon_info;
8581 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8582 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8586 icon_info = priv->icons[icon_pos];
8591 return g_strdup (icon_info->tooltip);
8595 * gtk_entry_set_icon_tooltip_markup:
8596 * @entry: a #GtkEntry
8597 * @icon_pos: the icon position
8598 * @tooltip: (allow-none): the contents of the tooltip for the icon, or %NULL
8600 * Sets @tooltip as the contents of the tooltip for the icon at
8601 * the specified position. @tooltip is assumed to be marked up with
8602 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
8604 * Use %NULL for @tooltip to remove an existing tooltip.
8606 * See also gtk_widget_set_tooltip_markup() and
8607 * gtk_enty_set_icon_tooltip_text().
8612 gtk_entry_set_icon_tooltip_markup (GtkEntry *entry,
8613 GtkEntryIconPosition icon_pos,
8614 const gchar *tooltip)
8616 GtkEntryPrivate *priv;
8617 EntryIconInfo *icon_info;
8619 g_return_if_fail (GTK_IS_ENTRY (entry));
8620 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8624 if ((icon_info = priv->icons[icon_pos]) == NULL)
8625 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8627 if (icon_info->tooltip)
8628 g_free (icon_info->tooltip);
8630 /* Treat an empty string as a NULL string,
8631 * because an empty string would be useless for a tooltip:
8633 if (tooltip && tooltip[0] == '\0')
8636 icon_info->tooltip = g_strdup (tooltip);
8638 ensure_has_tooltip (entry);
8642 gtk_entry_query_tooltip (GtkWidget *widget,
8645 gboolean keyboard_tip,
8646 GtkTooltip *tooltip)
8649 GtkEntryPrivate *priv;
8650 EntryIconInfo *icon_info;
8653 entry = GTK_ENTRY (widget);
8658 icon_pos = gtk_entry_get_icon_at_pos (entry, x, y);
8661 if ((icon_info = priv->icons[icon_pos]) != NULL)
8663 if (icon_info->tooltip)
8665 gtk_tooltip_set_markup (tooltip, icon_info->tooltip);
8674 return GTK_WIDGET_CLASS (gtk_entry_parent_class)->query_tooltip (widget,
8681 /* Quick hack of a popup menu
8684 activate_cb (GtkWidget *menuitem,
8687 const gchar *signal = g_object_get_data (G_OBJECT (menuitem), "gtk-signal");
8688 g_signal_emit_by_name (entry, signal);
8693 gtk_entry_mnemonic_activate (GtkWidget *widget,
8694 gboolean group_cycling)
8696 gtk_widget_grab_focus (widget);
8701 append_action_signal (GtkEntry *entry,
8703 const gchar *stock_id,
8704 const gchar *signal,
8707 GtkWidget *menuitem = gtk_image_menu_item_new_from_stock (stock_id, NULL);
8709 g_object_set_data (G_OBJECT (menuitem), I_("gtk-signal"), (char *)signal);
8710 g_signal_connect (menuitem, "activate",
8711 G_CALLBACK (activate_cb), entry);
8713 gtk_widget_set_sensitive (menuitem, sensitive);
8715 gtk_widget_show (menuitem);
8716 gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
8720 popup_menu_detach (GtkWidget *attach_widget,
8723 GtkEntry *entry_attach = GTK_ENTRY (attach_widget);
8724 GtkEntryPrivate *priv_attach = entry_attach->priv;
8726 priv_attach->popup_menu = NULL;
8730 popup_position_func (GtkMenu *menu,
8736 GtkEntry *entry = GTK_ENTRY (user_data);
8737 GtkEntryPrivate *priv = entry->priv;
8738 GtkWidget *widget = GTK_WIDGET (entry);
8740 GtkRequisition menu_req;
8741 GdkRectangle monitor;
8742 GtkBorder inner_border;
8743 gint monitor_num, strong_x, height;
8745 g_return_if_fail (gtk_widget_get_realized (widget));
8747 gdk_window_get_origin (priv->text_area, x, y);
8749 screen = gtk_widget_get_screen (widget);
8750 monitor_num = gdk_screen_get_monitor_at_window (screen, priv->text_area);
8751 if (monitor_num < 0)
8753 gtk_menu_set_monitor (menu, monitor_num);
8755 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
8756 gtk_widget_get_preferred_size (priv->popup_menu,
8758 height = gdk_window_get_height (priv->text_area);
8759 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
8760 _gtk_entry_effective_inner_border (entry, &inner_border);
8762 *x += inner_border.left + strong_x - priv->scroll_offset;
8763 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
8764 *x -= menu_req.width;
8766 if ((*y + height + menu_req.height) <= monitor.y + monitor.height)
8768 else if ((*y - menu_req.height) >= monitor.y)
8769 *y -= menu_req.height;
8770 else if (monitor.y + monitor.height - (*y + height) > *y)
8773 *y -= menu_req.height;
8779 unichar_chosen_func (const char *text,
8782 GtkEntry *entry = GTK_ENTRY (data);
8783 GtkEntryPrivate *priv = entry->priv;
8786 gtk_entry_enter_text (entry, text);
8797 popup_targets_received (GtkClipboard *clipboard,
8798 GtkSelectionData *data,
8801 PopupInfo *info = user_data;
8802 GtkEntry *entry = info->entry;
8803 GtkEntryPrivate *info_entry_priv = entry->priv;
8805 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
8808 gboolean clipboard_contains_text;
8809 GtkWidget *menuitem;
8811 gboolean show_input_method_menu;
8812 gboolean show_unicode_menu;
8814 clipboard_contains_text = gtk_selection_data_targets_include_text (data);
8815 if (info_entry_priv->popup_menu)
8816 gtk_widget_destroy (info_entry_priv->popup_menu);
8818 info_entry_priv->popup_menu = gtk_menu_new ();
8820 gtk_menu_attach_to_widget (GTK_MENU (info_entry_priv->popup_menu),
8824 mode = gtk_entry_get_display_mode (entry);
8825 append_action_signal (entry, info_entry_priv->popup_menu, GTK_STOCK_CUT, "cut-clipboard",
8826 info_entry_priv->editable && mode == DISPLAY_NORMAL &&
8827 info_entry_priv->current_pos != info_entry_priv->selection_bound);
8829 append_action_signal (entry, info_entry_priv->popup_menu, GTK_STOCK_COPY, "copy-clipboard",
8830 mode == DISPLAY_NORMAL &&
8831 info_entry_priv->current_pos != info_entry_priv->selection_bound);
8833 append_action_signal (entry, info_entry_priv->popup_menu, GTK_STOCK_PASTE, "paste-clipboard",
8834 info_entry_priv->editable && clipboard_contains_text);
8836 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_DELETE, NULL);
8837 gtk_widget_set_sensitive (menuitem, info_entry_priv->editable && info_entry_priv->current_pos != info_entry_priv->selection_bound);
8838 g_signal_connect_swapped (menuitem, "activate",
8839 G_CALLBACK (gtk_entry_delete_cb), entry);
8840 gtk_widget_show (menuitem);
8841 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8843 menuitem = gtk_separator_menu_item_new ();
8844 gtk_widget_show (menuitem);
8845 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8847 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_SELECT_ALL, NULL);
8848 g_signal_connect_swapped (menuitem, "activate",
8849 G_CALLBACK (gtk_entry_select_all), entry);
8850 gtk_widget_show (menuitem);
8851 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8853 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
8854 "gtk-show-input-method-menu", &show_input_method_menu,
8855 "gtk-show-unicode-menu", &show_unicode_menu,
8858 if (show_input_method_menu || show_unicode_menu)
8860 menuitem = gtk_separator_menu_item_new ();
8861 gtk_widget_show (menuitem);
8862 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8865 if (show_input_method_menu)
8867 menuitem = gtk_menu_item_new_with_mnemonic (_("Input _Methods"));
8868 gtk_widget_set_sensitive (menuitem, info_entry_priv->editable);
8869 gtk_widget_show (menuitem);
8870 submenu = gtk_menu_new ();
8871 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
8873 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8875 gtk_im_multicontext_append_menuitems (GTK_IM_MULTICONTEXT (info_entry_priv->im_context),
8876 GTK_MENU_SHELL (submenu));
8879 if (show_unicode_menu)
8881 menuitem = gtk_menu_item_new_with_mnemonic (_("_Insert Unicode Control Character"));
8882 gtk_widget_set_sensitive (menuitem, info_entry_priv->editable);
8883 gtk_widget_show (menuitem);
8885 submenu = gtk_menu_new ();
8886 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
8887 gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
8889 _gtk_text_util_append_special_char_menuitems (GTK_MENU_SHELL (submenu),
8890 unichar_chosen_func,
8894 g_signal_emit (entry,
8895 signals[POPULATE_POPUP],
8897 info_entry_priv->popup_menu);
8901 gtk_menu_popup (GTK_MENU (info_entry_priv->popup_menu), NULL, NULL,
8903 info->button, info->time);
8906 gtk_menu_popup (GTK_MENU (info_entry_priv->popup_menu), NULL, NULL,
8907 popup_position_func, entry,
8908 info->button, info->time);
8909 gtk_menu_shell_select_first (GTK_MENU_SHELL (info_entry_priv->popup_menu), FALSE);
8913 g_object_unref (entry);
8914 g_slice_free (PopupInfo, info);
8918 gtk_entry_do_popup (GtkEntry *entry,
8919 GdkEventButton *event)
8921 PopupInfo *info = g_slice_new (PopupInfo);
8923 /* In order to know what entries we should make sensitive, we
8924 * ask for the current targets of the clipboard, and when
8925 * we get them, then we actually pop up the menu.
8927 info->entry = g_object_ref (entry);
8931 info->button = event->button;
8932 info->time = event->time;
8937 info->time = gtk_get_current_event_time ();
8940 gtk_clipboard_request_contents (gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_CLIPBOARD),
8941 gdk_atom_intern_static_string ("TARGETS"),
8942 popup_targets_received,
8947 gtk_entry_popup_menu (GtkWidget *widget)
8949 gtk_entry_do_popup (GTK_ENTRY (widget), NULL);
8954 gtk_entry_drag_begin (GtkWidget *widget,
8955 GdkDragContext *context)
8957 GtkEntry *entry = GTK_ENTRY (widget);
8958 GtkEntryPrivate *priv = entry->priv;
8961 for (i = 0; i < MAX_ICONS; i++)
8963 EntryIconInfo *icon_info = priv->icons[i];
8965 if (icon_info != NULL)
8967 if (icon_info->in_drag)
8969 switch (icon_info->storage_type)
8971 case GTK_IMAGE_STOCK:
8972 gtk_drag_set_icon_stock (context, icon_info->stock_id, -2, -2);
8975 case GTK_IMAGE_ICON_NAME:
8976 gtk_drag_set_icon_name (context, icon_info->icon_name, -2, -2);
8979 /* FIXME: No GIcon support for dnd icons */
8980 case GTK_IMAGE_GICON:
8981 case GTK_IMAGE_PIXBUF:
8982 gtk_drag_set_icon_pixbuf (context, icon_info->pixbuf, -2, -2);
8985 g_assert_not_reached ();
8993 gtk_entry_drag_end (GtkWidget *widget,
8994 GdkDragContext *context)
8996 GtkEntry *entry = GTK_ENTRY (widget);
8997 GtkEntryPrivate *priv = entry->priv;
9000 for (i = 0; i < MAX_ICONS; i++)
9002 EntryIconInfo *icon_info = priv->icons[i];
9004 if (icon_info != NULL)
9005 icon_info->in_drag = 0;
9010 gtk_entry_drag_leave (GtkWidget *widget,
9011 GdkDragContext *context,
9014 GtkEntry *entry = GTK_ENTRY (widget);
9015 GtkEntryPrivate *priv = entry->priv;
9017 priv->dnd_position = -1;
9018 gtk_widget_queue_draw (widget);
9022 gtk_entry_drag_drop (GtkWidget *widget,
9023 GdkDragContext *context,
9028 GtkEntry *entry = GTK_ENTRY (widget);
9029 GtkEntryPrivate *priv = entry->priv;
9030 GdkAtom target = GDK_NONE;
9033 target = gtk_drag_dest_find_target (widget, context, NULL);
9035 if (target != GDK_NONE)
9036 gtk_drag_get_data (widget, context, target, time);
9038 gtk_drag_finish (context, FALSE, FALSE, time);
9044 gtk_entry_drag_motion (GtkWidget *widget,
9045 GdkDragContext *context,
9050 GtkEntry *entry = GTK_ENTRY (widget);
9051 GtkEntryPrivate *priv = entry->priv;
9052 GtkStyleContext *style_context;
9053 GtkWidget *source_widget;
9054 GdkDragAction suggested_action;
9055 gint new_position, old_position;
9059 style_context = gtk_widget_get_style_context (widget);
9060 gtk_style_context_get_padding (style_context, 0, &padding);
9064 old_position = priv->dnd_position;
9065 new_position = gtk_entry_find_position (entry, x + priv->scroll_offset);
9067 if (priv->editable &&
9068 gtk_drag_dest_find_target (widget, context, NULL) != GDK_NONE)
9070 source_widget = gtk_drag_get_source_widget (context);
9071 suggested_action = gdk_drag_context_get_suggested_action (context);
9073 if (!gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &sel1, &sel2) ||
9074 new_position < sel1 || new_position > sel2)
9076 if (source_widget == widget)
9078 /* Default to MOVE, unless the user has
9079 * pressed ctrl or alt to affect available actions
9081 if ((gdk_drag_context_get_actions (context) & GDK_ACTION_MOVE) != 0)
9082 suggested_action = GDK_ACTION_MOVE;
9085 priv->dnd_position = new_position;
9089 if (source_widget == widget)
9090 suggested_action = 0; /* Can't drop in selection where drag started */
9092 priv->dnd_position = -1;
9097 /* Entry not editable, or no text */
9098 suggested_action = 0;
9099 priv->dnd_position = -1;
9102 gdk_drag_status (context, suggested_action, time);
9104 if (priv->dnd_position != old_position)
9105 gtk_widget_queue_draw (widget);
9111 gtk_entry_drag_data_received (GtkWidget *widget,
9112 GdkDragContext *context,
9115 GtkSelectionData *selection_data,
9119 GtkEntry *entry = GTK_ENTRY (widget);
9120 GtkEntryPrivate *priv = entry->priv;
9121 GtkEditable *editable = GTK_EDITABLE (widget);
9122 GtkStyleContext *style_context;
9126 str = (gchar *) gtk_selection_data_get_text (selection_data);
9128 style_context = gtk_widget_get_style_context (widget);
9129 gtk_style_context_get_padding (style_context, 0, &padding);
9133 if (str && priv->editable)
9139 if (priv->truncate_multiline)
9140 length = truncate_multiline (str);
9142 new_position = gtk_entry_find_position (entry, x + priv->scroll_offset);
9144 if (!gtk_editable_get_selection_bounds (editable, &sel1, &sel2) ||
9145 new_position < sel1 || new_position > sel2)
9147 gtk_editable_insert_text (editable, str, length, &new_position);
9151 /* Replacing selection */
9152 begin_change (entry);
9153 g_object_freeze_notify (G_OBJECT (entry));
9154 gtk_editable_delete_text (editable, sel1, sel2);
9155 gtk_editable_insert_text (editable, str, length, &sel1);
9156 g_object_thaw_notify (G_OBJECT (entry));
9160 gtk_drag_finish (context, TRUE, gdk_drag_context_get_selected_action (context) == GDK_ACTION_MOVE, time);
9164 /* Drag and drop didn't happen! */
9165 gtk_drag_finish (context, FALSE, FALSE, time);
9172 gtk_entry_drag_data_get (GtkWidget *widget,
9173 GdkDragContext *context,
9174 GtkSelectionData *selection_data,
9178 GtkEntry *entry = GTK_ENTRY (widget);
9179 GtkEntryPrivate *priv = entry->priv;
9180 GtkEditable *editable = GTK_EDITABLE (widget);
9181 gint sel_start, sel_end;
9184 /* If there is an icon drag going on, exit early. */
9185 for (i = 0; i < MAX_ICONS; i++)
9187 EntryIconInfo *icon_info = priv->icons[i];
9189 if (icon_info != NULL)
9191 if (icon_info->in_drag)
9196 if (gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end))
9198 gchar *str = gtk_entry_get_display_text (GTK_ENTRY (widget), sel_start, sel_end);
9200 gtk_selection_data_set_text (selection_data, str, -1);
9208 gtk_entry_drag_data_delete (GtkWidget *widget,
9209 GdkDragContext *context)
9211 GtkEntry *entry = GTK_ENTRY (widget);
9212 GtkEntryPrivate *priv = entry->priv;
9213 GtkEditable *editable = GTK_EDITABLE (widget);
9214 gint sel_start, sel_end;
9217 /* If there is an icon drag going on, exit early. */
9218 for (i = 0; i < MAX_ICONS; i++)
9220 EntryIconInfo *icon_info = priv->icons[i];
9222 if (icon_info != NULL)
9224 if (icon_info->in_drag)
9229 if (priv->editable &&
9230 gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end))
9231 gtk_editable_delete_text (editable, sel_start, sel_end);
9234 /* We display the cursor when
9236 * - the selection is empty, AND
9237 * - the widget has focus
9240 #define CURSOR_ON_MULTIPLIER 2
9241 #define CURSOR_OFF_MULTIPLIER 1
9242 #define CURSOR_PEND_MULTIPLIER 3
9243 #define CURSOR_DIVIDER 3
9246 cursor_blinks (GtkEntry *entry)
9248 GtkEntryPrivate *priv = entry->priv;
9250 if (gtk_widget_has_focus (GTK_WIDGET (entry)) &&
9252 priv->selection_bound == priv->current_pos)
9254 GtkSettings *settings;
9257 settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9258 g_object_get (settings, "gtk-cursor-blink", &blink, NULL);
9267 get_cursor_time (GtkEntry *entry)
9269 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9272 g_object_get (settings, "gtk-cursor-blink-time", &time, NULL);
9278 get_cursor_blink_timeout (GtkEntry *entry)
9280 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9283 g_object_get (settings, "gtk-cursor-blink-timeout", &timeout, NULL);
9289 show_cursor (GtkEntry *entry)
9291 GtkEntryPrivate *priv = entry->priv;
9294 if (!priv->cursor_visible)
9296 priv->cursor_visible = TRUE;
9298 widget = GTK_WIDGET (entry);
9299 if (gtk_widget_has_focus (widget) && priv->selection_bound == priv->current_pos)
9300 gtk_widget_queue_draw (widget);
9305 hide_cursor (GtkEntry *entry)
9307 GtkEntryPrivate *priv = entry->priv;
9310 if (priv->cursor_visible)
9312 priv->cursor_visible = FALSE;
9314 widget = GTK_WIDGET (entry);
9315 if (gtk_widget_has_focus (widget) && priv->selection_bound == priv->current_pos)
9316 gtk_widget_queue_draw (widget);
9324 blink_cb (gpointer data)
9327 GtkEntryPrivate *priv;
9330 entry = GTK_ENTRY (data);
9333 if (!gtk_widget_has_focus (GTK_WIDGET (entry)))
9335 g_warning ("GtkEntry - did not receive focus-out-event. If you\n"
9336 "connect a handler to this signal, it must return\n"
9337 "FALSE so the entry gets the event as well");
9339 gtk_entry_check_cursor_blink (entry);
9344 g_assert (priv->selection_bound == priv->current_pos);
9346 blink_timeout = get_cursor_blink_timeout (entry);
9347 if (priv->blink_time > 1000 * blink_timeout &&
9348 blink_timeout < G_MAXINT/1000)
9350 /* we've blinked enough without the user doing anything, stop blinking */
9351 show_cursor (entry);
9352 priv->blink_timeout = 0;
9354 else if (priv->cursor_visible)
9356 hide_cursor (entry);
9357 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_OFF_MULTIPLIER / CURSOR_DIVIDER,
9363 show_cursor (entry);
9364 priv->blink_time += get_cursor_time (entry);
9365 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
9370 /* Remove ourselves */
9375 gtk_entry_check_cursor_blink (GtkEntry *entry)
9377 GtkEntryPrivate *priv = entry->priv;
9379 if (cursor_blinks (entry))
9381 if (!priv->blink_timeout)
9383 show_cursor (entry);
9384 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
9391 if (priv->blink_timeout)
9393 g_source_remove (priv->blink_timeout);
9394 priv->blink_timeout = 0;
9397 priv->cursor_visible = TRUE;
9402 gtk_entry_pend_cursor_blink (GtkEntry *entry)
9404 GtkEntryPrivate *priv = entry->priv;
9406 if (cursor_blinks (entry))
9408 if (priv->blink_timeout != 0)
9409 g_source_remove (priv->blink_timeout);
9411 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_PEND_MULTIPLIER / CURSOR_DIVIDER,
9414 show_cursor (entry);
9419 gtk_entry_reset_blink_time (GtkEntry *entry)
9421 GtkEntryPrivate *priv = entry->priv;
9423 priv->blink_time = 0;
9429 gtk_entry_completion_timeout (gpointer data)
9431 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (data);
9432 GtkEntryPrivate *completion_entry_priv = GTK_ENTRY (completion->priv->entry)->priv;
9434 completion->priv->completion_timeout = 0;
9436 if (completion->priv->filter_model &&
9437 g_utf8_strlen (gtk_entry_get_text (GTK_ENTRY (completion->priv->entry)), -1)
9438 >= completion->priv->minimum_key_length)
9442 GtkTreeSelection *s;
9443 gboolean popup_single;
9445 gtk_entry_completion_complete (completion);
9446 matches = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->filter_model), NULL);
9448 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9450 s = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view));
9452 gtk_tree_selection_unselect_all (s);
9454 actions = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->actions), NULL);
9456 g_object_get (completion, "popup-single-match", &popup_single, NULL);
9457 if ((matches > (popup_single ? 0: 1)) || actions > 0)
9459 if (gtk_widget_get_visible (completion->priv->popup_window))
9460 _gtk_entry_completion_resize_popup (completion);
9462 _gtk_entry_completion_popup (completion, completion_entry_priv->completion_device);
9465 _gtk_entry_completion_popdown (completion);
9467 else if (gtk_widget_get_visible (completion->priv->popup_window))
9468 _gtk_entry_completion_popdown (completion);
9473 static inline gboolean
9474 keyval_is_cursor_move (guint keyval)
9476 if (keyval == GDK_KEY_Up || keyval == GDK_KEY_KP_Up)
9479 if (keyval == GDK_KEY_Down || keyval == GDK_KEY_KP_Down)
9482 if (keyval == GDK_KEY_Page_Up)
9485 if (keyval == GDK_KEY_Page_Down)
9492 gtk_entry_completion_key_press (GtkWidget *widget,
9496 gint matches, actions = 0;
9497 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
9499 if (!gtk_widget_get_mapped (completion->priv->popup_window))
9502 matches = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->filter_model), NULL);
9504 if (completion->priv->actions)
9505 actions = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->actions), NULL);
9507 if (keyval_is_cursor_move (event->keyval))
9509 GtkTreePath *path = NULL;
9511 if (event->keyval == GDK_KEY_Up || event->keyval == GDK_KEY_KP_Up)
9513 if (completion->priv->current_selected < 0)
9514 completion->priv->current_selected = matches + actions - 1;
9516 completion->priv->current_selected--;
9518 else if (event->keyval == GDK_KEY_Down || event->keyval == GDK_KEY_KP_Down)
9520 if (completion->priv->current_selected < matches + actions - 1)
9521 completion->priv->current_selected++;
9523 completion->priv->current_selected = -1;
9525 else if (event->keyval == GDK_KEY_Page_Up)
9527 if (completion->priv->current_selected < 0)
9528 completion->priv->current_selected = matches + actions - 1;
9529 else if (completion->priv->current_selected == 0)
9530 completion->priv->current_selected = -1;
9531 else if (completion->priv->current_selected < matches)
9533 completion->priv->current_selected -= 14;
9534 if (completion->priv->current_selected < 0)
9535 completion->priv->current_selected = 0;
9539 completion->priv->current_selected -= 14;
9540 if (completion->priv->current_selected < matches - 1)
9541 completion->priv->current_selected = matches - 1;
9544 else if (event->keyval == GDK_KEY_Page_Down)
9546 if (completion->priv->current_selected < 0)
9547 completion->priv->current_selected = 0;
9548 else if (completion->priv->current_selected < matches - 1)
9550 completion->priv->current_selected += 14;
9551 if (completion->priv->current_selected > matches - 1)
9552 completion->priv->current_selected = matches - 1;
9554 else if (completion->priv->current_selected == matches + actions - 1)
9556 completion->priv->current_selected = -1;
9560 completion->priv->current_selected += 14;
9561 if (completion->priv->current_selected > matches + actions - 1)
9562 completion->priv->current_selected = matches + actions - 1;
9566 if (completion->priv->current_selected < 0)
9568 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9569 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view)));
9571 if (completion->priv->inline_selection &&
9572 completion->priv->completion_prefix)
9574 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9575 completion->priv->completion_prefix);
9576 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9579 else if (completion->priv->current_selected < matches)
9581 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view)));
9583 path = gtk_tree_path_new_from_indices (completion->priv->current_selected, -1);
9584 gtk_tree_view_set_cursor (GTK_TREE_VIEW (completion->priv->tree_view),
9587 if (completion->priv->inline_selection)
9591 GtkTreeIter child_iter;
9592 GtkTreeModel *model = NULL;
9593 GtkTreeSelection *sel;
9596 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view));
9597 if (!gtk_tree_selection_get_selected (sel, &model, &iter))
9600 gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (model), &child_iter, &iter);
9601 model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model));
9603 if (completion->priv->completion_prefix == NULL)
9604 completion->priv->completion_prefix = g_strdup (gtk_entry_get_text (GTK_ENTRY (completion->priv->entry)));
9606 g_signal_emit_by_name (completion, "cursor-on-match", model,
9607 &child_iter, &entry_set);
9610 else if (completion->priv->current_selected - matches >= 0)
9612 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9614 path = gtk_tree_path_new_from_indices (completion->priv->current_selected - matches, -1);
9615 gtk_tree_view_set_cursor (GTK_TREE_VIEW (completion->priv->action_view),
9618 if (completion->priv->inline_selection &&
9619 completion->priv->completion_prefix)
9621 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9622 completion->priv->completion_prefix);
9623 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9627 gtk_tree_path_free (path);
9631 else if (event->keyval == GDK_KEY_Escape ||
9632 event->keyval == GDK_KEY_Left ||
9633 event->keyval == GDK_KEY_KP_Left ||
9634 event->keyval == GDK_KEY_Right ||
9635 event->keyval == GDK_KEY_KP_Right)
9637 gboolean retval = TRUE;
9639 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9640 _gtk_entry_completion_popdown (completion);
9642 if (completion->priv->current_selected < 0)
9645 goto keypress_completion_out;
9647 else if (completion->priv->inline_selection)
9649 /* Escape rejects the tentative completion */
9650 if (event->keyval == GDK_KEY_Escape)
9652 if (completion->priv->completion_prefix)
9653 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9654 completion->priv->completion_prefix);
9656 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry), "");
9659 /* Move the cursor to the end for Right/Esc, to the
9660 beginning for Left */
9661 if (event->keyval == GDK_KEY_Right ||
9662 event->keyval == GDK_KEY_KP_Right ||
9663 event->keyval == GDK_KEY_Escape)
9664 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9666 gtk_editable_set_position (GTK_EDITABLE (widget), 0);
9669 keypress_completion_out:
9670 if (completion->priv->inline_selection)
9672 g_free (completion->priv->completion_prefix);
9673 completion->priv->completion_prefix = NULL;
9678 else if (event->keyval == GDK_KEY_Tab ||
9679 event->keyval == GDK_KEY_KP_Tab ||
9680 event->keyval == GDK_KEY_ISO_Left_Tab)
9682 GtkDirectionType dir = event->keyval == GDK_KEY_ISO_Left_Tab ?
9683 GTK_DIR_TAB_BACKWARD : GTK_DIR_TAB_FORWARD;
9685 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9686 _gtk_entry_completion_popdown (completion);
9688 g_free (completion->priv->completion_prefix);
9689 completion->priv->completion_prefix = NULL;
9691 gtk_widget_child_focus (gtk_widget_get_toplevel (widget), dir);
9695 else if (event->keyval == GDK_KEY_ISO_Enter ||
9696 event->keyval == GDK_KEY_KP_Enter ||
9697 event->keyval == GDK_KEY_Return)
9700 GtkTreeModel *model = NULL;
9701 GtkTreeModel *child_model;
9702 GtkTreeIter child_iter;
9703 GtkTreeSelection *sel;
9704 gboolean retval = TRUE;
9706 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9707 _gtk_entry_completion_popdown (completion);
9709 if (completion->priv->current_selected < matches)
9713 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view));
9714 if (gtk_tree_selection_get_selected (sel, &model, &iter))
9716 gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (model), &child_iter, &iter);
9717 child_model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model));
9718 g_signal_handler_block (widget, completion->priv->changed_id);
9719 g_signal_emit_by_name (completion, "match-selected",
9720 child_model, &child_iter, &entry_set);
9721 g_signal_handler_unblock (widget, completion->priv->changed_id);
9727 gtk_tree_model_get (model, &iter,
9728 completion->priv->text_column, &str,
9731 gtk_entry_set_text (GTK_ENTRY (widget), str);
9733 /* move the cursor to the end */
9734 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9742 else if (completion->priv->current_selected - matches >= 0)
9744 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view));
9745 if (gtk_tree_selection_get_selected (sel, &model, &iter))
9749 path = gtk_tree_path_new_from_indices (completion->priv->current_selected - matches, -1);
9750 g_signal_emit_by_name (completion, "action-activated",
9751 gtk_tree_path_get_indices (path)[0]);
9752 gtk_tree_path_free (path);
9758 g_free (completion->priv->completion_prefix);
9759 completion->priv->completion_prefix = NULL;
9768 gtk_entry_completion_changed (GtkWidget *widget,
9771 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
9772 GtkEntry *entry = GTK_ENTRY (widget);
9773 GtkEntryPrivate *priv = entry->priv;
9776 /* (re)install completion timeout */
9777 if (completion->priv->completion_timeout)
9778 g_source_remove (completion->priv->completion_timeout);
9780 if (!gtk_entry_get_text (entry))
9783 /* no need to normalize for this test */
9784 if (completion->priv->minimum_key_length > 0 &&
9785 strcmp ("", gtk_entry_get_text (entry)) == 0)
9787 if (gtk_widget_get_visible (completion->priv->popup_window))
9788 _gtk_entry_completion_popdown (completion);
9792 device = gtk_get_current_event_device ();
9794 if (device && gdk_device_get_source (device) == GDK_SOURCE_KEYBOARD)
9795 device = gdk_device_get_associated_device (device);
9798 priv->completion_device = device;
9800 completion->priv->completion_timeout =
9801 gdk_threads_add_timeout (COMPLETION_TIMEOUT,
9802 gtk_entry_completion_timeout,
9807 check_completion_callback (GtkEntryCompletion *completion)
9809 completion->priv->check_completion_idle = NULL;
9811 gtk_entry_completion_complete (completion);
9812 gtk_entry_completion_insert_prefix (completion);
9818 clear_completion_callback (GtkEntry *entry,
9821 if (pspec->name == I_("cursor-position") ||
9822 pspec->name == I_("selection-bound"))
9824 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
9826 completion->priv->has_completion = FALSE;
9831 accept_completion_callback (GtkEntry *entry)
9833 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
9835 if (completion->priv->has_completion)
9836 gtk_editable_set_position (GTK_EDITABLE (entry),
9837 gtk_entry_buffer_get_length (get_buffer (entry)));
9843 completion_insert_text_callback (GtkEntry *entry,
9847 GtkEntryCompletion *completion)
9849 /* idle to update the selection based on the file list */
9850 if (completion->priv->check_completion_idle == NULL)
9852 completion->priv->check_completion_idle = g_idle_source_new ();
9853 g_source_set_priority (completion->priv->check_completion_idle, G_PRIORITY_HIGH);
9854 g_source_set_closure (completion->priv->check_completion_idle,
9855 g_cclosure_new_object (G_CALLBACK (check_completion_callback),
9856 G_OBJECT (completion)));
9857 g_source_attach (completion->priv->check_completion_idle, NULL);
9862 completion_changed (GtkEntryCompletion *completion,
9866 GtkEntry *entry = GTK_ENTRY (data);
9868 if (pspec->name == I_("popup-completion") ||
9869 pspec->name == I_("inline-completion"))
9871 disconnect_completion_signals (entry, completion);
9872 connect_completion_signals (entry, completion);
9877 disconnect_completion_signals (GtkEntry *entry,
9878 GtkEntryCompletion *completion)
9880 g_signal_handlers_disconnect_by_func (completion,
9881 G_CALLBACK (completion_changed), entry);
9882 if (completion->priv->changed_id > 0 &&
9883 g_signal_handler_is_connected (entry, completion->priv->changed_id))
9885 g_signal_handler_disconnect (entry, completion->priv->changed_id);
9886 completion->priv->changed_id = 0;
9888 g_signal_handlers_disconnect_by_func (entry,
9889 G_CALLBACK (gtk_entry_completion_key_press), completion);
9890 if (completion->priv->insert_text_id > 0 &&
9891 g_signal_handler_is_connected (entry, completion->priv->insert_text_id))
9893 g_signal_handler_disconnect (entry, completion->priv->insert_text_id);
9894 completion->priv->insert_text_id = 0;
9896 g_signal_handlers_disconnect_by_func (entry,
9897 G_CALLBACK (completion_insert_text_callback), completion);
9898 g_signal_handlers_disconnect_by_func (entry,
9899 G_CALLBACK (clear_completion_callback), completion);
9900 g_signal_handlers_disconnect_by_func (entry,
9901 G_CALLBACK (accept_completion_callback), completion);
9905 connect_completion_signals (GtkEntry *entry,
9906 GtkEntryCompletion *completion)
9908 if (completion->priv->popup_completion)
9910 completion->priv->changed_id =
9911 g_signal_connect (entry, "changed",
9912 G_CALLBACK (gtk_entry_completion_changed), completion);
9913 g_signal_connect (entry, "key-press-event",
9914 G_CALLBACK (gtk_entry_completion_key_press), completion);
9917 if (completion->priv->inline_completion)
9919 completion->priv->insert_text_id =
9920 g_signal_connect (entry, "insert-text",
9921 G_CALLBACK (completion_insert_text_callback), completion);
9922 g_signal_connect (entry, "notify",
9923 G_CALLBACK (clear_completion_callback), completion);
9924 g_signal_connect (entry, "activate",
9925 G_CALLBACK (accept_completion_callback), completion);
9926 g_signal_connect (entry, "focus-out-event",
9927 G_CALLBACK (accept_completion_callback), completion);
9930 g_signal_connect (completion, "notify",
9931 G_CALLBACK (completion_changed), entry);
9935 * gtk_entry_set_completion:
9936 * @entry: A #GtkEntry
9937 * @completion: (allow-none): The #GtkEntryCompletion or %NULL
9939 * Sets @completion to be the auxiliary completion object to use with @entry.
9940 * All further configuration of the completion mechanism is done on
9941 * @completion using the #GtkEntryCompletion API. Completion is disabled if
9942 * @completion is set to %NULL.
9947 gtk_entry_set_completion (GtkEntry *entry,
9948 GtkEntryCompletion *completion)
9950 GtkEntryCompletion *old;
9952 g_return_if_fail (GTK_IS_ENTRY (entry));
9953 g_return_if_fail (!completion || GTK_IS_ENTRY_COMPLETION (completion));
9955 old = gtk_entry_get_completion (entry);
9957 if (old == completion)
9962 if (old->priv->completion_timeout)
9964 g_source_remove (old->priv->completion_timeout);
9965 old->priv->completion_timeout = 0;
9968 if (gtk_widget_get_mapped (old->priv->popup_window))
9969 _gtk_entry_completion_popdown (old);
9971 disconnect_completion_signals (entry, old);
9972 old->priv->entry = NULL;
9974 g_object_unref (old);
9979 g_object_set_data (G_OBJECT (entry), I_(GTK_ENTRY_COMPLETION_KEY), NULL);
9983 /* hook into the entry */
9984 g_object_ref (completion);
9986 connect_completion_signals (entry, completion);
9987 completion->priv->entry = GTK_WIDGET (entry);
9988 g_object_set_data (G_OBJECT (entry), I_(GTK_ENTRY_COMPLETION_KEY), completion);
9990 g_object_notify (G_OBJECT (entry), "completion");
9994 * gtk_entry_get_completion:
9995 * @entry: A #GtkEntry
9997 * Returns the auxiliary completion object currently in use by @entry.
9999 * Return value: (transfer none): The auxiliary completion object currently
10000 * in use by @entry.
10004 GtkEntryCompletion *
10005 gtk_entry_get_completion (GtkEntry *entry)
10007 GtkEntryCompletion *completion;
10009 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
10011 completion = GTK_ENTRY_COMPLETION (g_object_get_data (G_OBJECT (entry),
10012 GTK_ENTRY_COMPLETION_KEY));
10018 * gtk_entry_set_cursor_hadjustment:
10019 * @entry: a #GtkEntry
10020 * @adjustment: an adjustment which should be adjusted when the cursor
10021 * is moved, or %NULL
10023 * Hooks up an adjustment to the cursor position in an entry, so that when
10024 * the cursor is moved, the adjustment is scrolled to show that position.
10025 * See gtk_scrolled_window_get_hadjustment() for a typical way of obtaining
10028 * The adjustment has to be in pixel units and in the same coordinate system
10034 gtk_entry_set_cursor_hadjustment (GtkEntry *entry,
10035 GtkAdjustment *adjustment)
10037 g_return_if_fail (GTK_IS_ENTRY (entry));
10039 g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
10042 g_object_ref (adjustment);
10044 g_object_set_qdata_full (G_OBJECT (entry),
10045 quark_cursor_hadjustment,
10051 * gtk_entry_get_cursor_hadjustment:
10052 * @entry: a #GtkEntry
10054 * Retrieves the horizontal cursor adjustment for the entry.
10055 * See gtk_entry_set_cursor_hadjustment().
10057 * Return value: (transfer none): the horizontal cursor adjustment, or %NULL
10058 * if none has been set.
10063 gtk_entry_get_cursor_hadjustment (GtkEntry *entry)
10065 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
10067 return g_object_get_qdata (G_OBJECT (entry), quark_cursor_hadjustment);
10071 * gtk_entry_set_progress_fraction:
10072 * @entry: a #GtkEntry
10073 * @fraction: fraction of the task that's been completed
10075 * Causes the entry's progress indicator to "fill in" the given
10076 * fraction of the bar. The fraction should be between 0.0 and 1.0,
10082 gtk_entry_set_progress_fraction (GtkEntry *entry,
10086 GtkEntryPrivate *private;
10087 gdouble old_fraction;
10088 gint x, y, width, height;
10089 gint old_x, old_y, old_width, old_height;
10091 g_return_if_fail (GTK_IS_ENTRY (entry));
10093 widget = GTK_WIDGET (entry);
10094 private = entry->priv;
10096 if (private->progress_pulse_mode)
10099 old_fraction = private->progress_fraction;
10101 if (gtk_widget_is_drawable (widget))
10102 get_progress_area (widget, &old_x, &old_y, &old_width, &old_height);
10104 fraction = CLAMP (fraction, 0.0, 1.0);
10106 private->progress_fraction = fraction;
10107 private->progress_pulse_mode = FALSE;
10108 private->progress_pulse_current = 0.0;
10110 if (gtk_widget_is_drawable (widget))
10112 get_progress_area (widget, &x, &y, &width, &height);
10114 if ((x != old_x) || (y != old_y) || (width != old_width) || (height != old_height))
10115 gtk_widget_queue_draw (widget);
10118 if (fraction != old_fraction)
10119 g_object_notify (G_OBJECT (entry), "progress-fraction");
10123 * gtk_entry_get_progress_fraction:
10124 * @entry: a #GtkEntry
10126 * Returns the current fraction of the task that's been completed.
10127 * See gtk_entry_set_progress_fraction().
10129 * Return value: a fraction from 0.0 to 1.0
10134 gtk_entry_get_progress_fraction (GtkEntry *entry)
10136 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
10138 return entry->priv->progress_fraction;
10142 * gtk_entry_set_progress_pulse_step:
10143 * @entry: a #GtkEntry
10144 * @fraction: fraction between 0.0 and 1.0
10146 * Sets the fraction of total entry width to move the progress
10147 * bouncing block for each call to gtk_entry_progress_pulse().
10152 gtk_entry_set_progress_pulse_step (GtkEntry *entry,
10155 GtkEntryPrivate *private;
10157 g_return_if_fail (GTK_IS_ENTRY (entry));
10159 private = entry->priv;
10161 fraction = CLAMP (fraction, 0.0, 1.0);
10163 if (fraction != private->progress_pulse_fraction)
10165 private->progress_pulse_fraction = fraction;
10167 gtk_widget_queue_draw (GTK_WIDGET (entry));
10169 g_object_notify (G_OBJECT (entry), "progress-pulse-step");
10174 * gtk_entry_get_progress_pulse_step:
10175 * @entry: a #GtkEntry
10177 * Retrieves the pulse step set with gtk_entry_set_progress_pulse_step().
10179 * Return value: a fraction from 0.0 to 1.0
10184 gtk_entry_get_progress_pulse_step (GtkEntry *entry)
10186 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
10188 return entry->priv->progress_pulse_fraction;
10192 * gtk_entry_progress_pulse:
10193 * @entry: a #GtkEntry
10195 * Indicates that some progress is made, but you don't know how much.
10196 * Causes the entry's progress indicator to enter "activity mode,"
10197 * where a block bounces back and forth. Each call to
10198 * gtk_entry_progress_pulse() causes the block to move by a little bit
10199 * (the amount of movement per pulse is determined by
10200 * gtk_entry_set_progress_pulse_step()).
10205 gtk_entry_progress_pulse (GtkEntry *entry)
10207 GtkEntryPrivate *private;
10209 g_return_if_fail (GTK_IS_ENTRY (entry));
10211 private = entry->priv;
10213 if (private->progress_pulse_mode)
10215 if (private->progress_pulse_way_back)
10217 private->progress_pulse_current -= private->progress_pulse_fraction;
10219 if (private->progress_pulse_current < 0.0)
10221 private->progress_pulse_current = 0.0;
10222 private->progress_pulse_way_back = FALSE;
10227 private->progress_pulse_current += private->progress_pulse_fraction;
10229 if (private->progress_pulse_current > 1.0 - private->progress_pulse_fraction)
10231 private->progress_pulse_current = 1.0 - private->progress_pulse_fraction;
10232 private->progress_pulse_way_back = TRUE;
10238 private->progress_fraction = 0.0;
10239 private->progress_pulse_mode = TRUE;
10240 private->progress_pulse_way_back = FALSE;
10241 private->progress_pulse_current = 0.0;
10244 gtk_widget_queue_draw (GTK_WIDGET (entry));
10248 * gtk_entry_set_placeholder_text:
10249 * @entry: a #GtkEntry
10250 * @text: a string to be displayed when @entry is empty an unfocused, or %NULL
10252 * Sets text to be displayed in @entry when
10253 * it is empty and unfocused. This can be used to give a visual hint
10254 * of the expected contents of the #GtkEntry.
10259 gtk_entry_set_placeholder_text (GtkEntry *entry,
10262 GtkEntryPrivate *priv;
10264 g_return_if_fail (GTK_IS_ENTRY (entry));
10266 priv = entry->priv;
10268 if (g_strcmp0 (priv->placeholder_text, text) == 0)
10271 g_free (priv->placeholder_text);
10272 priv->placeholder_text = g_strdup (text);
10274 gtk_entry_recompute (entry);
10276 g_object_notify (G_OBJECT (entry), "placeholder-text");
10280 * gtk_entry_get_placeholder_text:
10281 * @entry: a #GtkEntry
10283 * Retrieves the text that will be displayed when @entry is empty and unfocused
10285 * Returns: a pointer to the placeholder text as a string. This string points to internally allocated
10286 * storage in the widget and must not be freed, modified or stored.
10290 G_CONST_RETURN gchar *
10291 gtk_entry_get_placeholder_text (GtkEntry *entry)
10293 GtkEntryPrivate *priv;
10295 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
10297 priv = entry->priv;
10299 return priv->placeholder_text;
10302 /* Caps Lock warning for password entries */
10305 show_capslock_feedback (GtkEntry *entry,
10308 GtkEntryPrivate *priv = entry->priv;
10310 if (gtk_entry_get_icon_storage_type (entry, GTK_ENTRY_ICON_SECONDARY) == GTK_IMAGE_EMPTY)
10312 gtk_entry_set_icon_from_stock (entry, GTK_ENTRY_ICON_SECONDARY, GTK_STOCK_CAPS_LOCK_WARNING);
10313 gtk_entry_set_icon_activatable (entry, GTK_ENTRY_ICON_SECONDARY, FALSE);
10314 priv->caps_lock_warning_shown = TRUE;
10317 if (priv->caps_lock_warning_shown)
10318 gtk_entry_set_icon_tooltip_text (entry, GTK_ENTRY_ICON_SECONDARY, text);
10320 g_warning ("Can't show Caps Lock warning, since secondary icon is set");
10324 remove_capslock_feedback (GtkEntry *entry)
10326 GtkEntryPrivate *priv = entry->priv;
10328 if (priv->caps_lock_warning_shown)
10330 gtk_entry_set_icon_from_stock (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
10331 priv->caps_lock_warning_shown = FALSE;
10336 keymap_state_changed (GdkKeymap *keymap,
10339 GtkEntryPrivate *priv = entry->priv;
10342 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL && priv->caps_lock_warning)
10344 if (gdk_keymap_get_num_lock_state (keymap)
10345 && gdk_keymap_get_caps_lock_state (keymap))
10346 text = _("Caps Lock and Num Lock are on");
10347 else if (gdk_keymap_get_num_lock_state (keymap))
10348 text = _("Num Lock is on");
10349 else if (gdk_keymap_get_caps_lock_state (keymap))
10350 text = _("Caps Lock is on");
10354 show_capslock_feedback (entry, text);
10356 remove_capslock_feedback (entry);
10360 * _gtk_entry_set_is_cell_renderer:
10361 * @entry: a #GtkEntry
10362 * @is_cell_renderer: new value
10364 * This is a helper function for GtkComboBox. A GtkEntry in a GtkComboBox
10365 * is supposed to behave like a GtkCellEditable when placed in a combo box.
10367 * I.e take up its allocation and get GtkEntry->is_cell_renderer = TRUE.
10371 _gtk_entry_set_is_cell_renderer (GtkEntry *entry,
10372 gboolean is_cell_renderer)
10374 entry->priv->is_cell_renderer = is_cell_renderer;