1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* GTK - The GIMP Toolkit
3 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * Copyright (C) 2004-2006 Christian Hammond
5 * Copyright (C) 2008 Cody Russell
6 * Copyright (C) 2008 Red Hat, Inc.
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
25 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
26 * file for a list of people on the GTK+ Team. See the ChangeLog
27 * files for a list of changes. These files are distributed with
28 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
36 #include "gdk/gdkkeysyms.h"
37 #include "gtkalignment.h"
38 #include "gtkbindings.h"
39 #include "gtkcelleditable.h"
40 #include "gtkclipboard.h"
43 #include "gtkentrybuffer.h"
44 #include "gtkimagemenuitem.h"
45 #include "gtkimcontextsimple.h"
46 #include "gtkimmulticontext.h"
50 #include "gtkmarshalers.h"
52 #include "gtkmenuitem.h"
53 #include "gtkseparatormenuitem.h"
54 #include "gtkselection.h"
55 #include "gtksettings.h"
56 #include "gtksizerequest.h"
57 #include "gtkspinbutton.h"
59 #include "gtktextutil.h"
60 #include "gtkwindow.h"
61 #include "gtktreeview.h"
62 #include "gtktreeselection.h"
63 #include "gtkprivate.h"
64 #include "gtkentryprivate.h"
65 #include "gtkcelllayout.h"
66 #include "gtktooltip.h"
67 #include "gtkiconfactory.h"
68 #include "gtkicontheme.h"
70 #define GTK_ENTRY_COMPLETION_KEY "gtk-entry-completion-key"
72 #define MIN_ENTRY_WIDTH 150
73 #define DRAW_TIMEOUT 20
74 #define COMPLETION_TIMEOUT 300
75 #define PASSWORD_HINT_MAX 8
79 #define IS_VALID_ICON_POSITION(pos) \
80 ((pos) == GTK_ENTRY_ICON_PRIMARY || \
81 (pos) == GTK_ENTRY_ICON_SECONDARY)
83 static const GtkBorder default_inner_border = { 2, 2, 2, 2 };
84 static GQuark quark_inner_border = 0;
85 static GQuark quark_password_hint = 0;
86 static GQuark quark_cursor_hadjustment = 0;
87 static GQuark quark_capslock_feedback = 0;
89 typedef struct _GtkEntryPrivate GtkEntryPrivate;
91 #define GTK_ENTRY_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_ENTRY, GtkEntryPrivate))
97 guint insensitive : 1;
98 guint nonactivatable : 1;
103 GtkImageType storage_type;
109 GtkTargetList *target_list;
110 GdkDragAction actions;
113 struct _GtkEntryPrivate
115 GtkEntryBuffer* buffer;
119 guint blink_time; /* time in msec the cursor has blinked since last user event */
120 guint interior_focus : 1;
121 guint real_changed : 1;
122 guint invisible_char_set : 1;
123 guint caps_lock_warning : 1;
124 guint caps_lock_warning_shown : 1;
125 guint change_count : 8;
126 guint progress_pulse_mode : 1;
127 guint progress_pulse_way_back : 1;
130 GtkShadowType shadow_type;
132 gdouble progress_fraction;
133 gdouble progress_pulse_fraction;
134 gdouble progress_pulse_current;
136 EntryIconInfo *icons[MAX_ICONS];
143 GdkDevice *completion_device;
146 typedef struct _GtkEntryPasswordHint GtkEntryPasswordHint;
148 struct _GtkEntryPasswordHint
150 gint position; /* Position (in text) of the last password hint */
151 guint source_id; /* Timeout source id */
154 typedef struct _GtkEntryCapslockFeedback GtkEntryCapslockFeedback;
156 struct _GtkEntryCapslockFeedback
183 PROP_CURSOR_POSITION,
184 PROP_SELECTION_BOUND,
191 PROP_ACTIVATES_DEFAULT,
196 PROP_TRUNCATE_MULTILINE,
200 PROP_INVISIBLE_CHAR_SET,
201 PROP_CAPS_LOCK_WARNING,
202 PROP_PROGRESS_FRACTION,
203 PROP_PROGRESS_PULSE_STEP,
205 PROP_PIXBUF_SECONDARY,
207 PROP_STOCK_SECONDARY,
208 PROP_ICON_NAME_PRIMARY,
209 PROP_ICON_NAME_SECONDARY,
211 PROP_GICON_SECONDARY,
212 PROP_STORAGE_TYPE_PRIMARY,
213 PROP_STORAGE_TYPE_SECONDARY,
214 PROP_ACTIVATABLE_PRIMARY,
215 PROP_ACTIVATABLE_SECONDARY,
216 PROP_SENSITIVE_PRIMARY,
217 PROP_SENSITIVE_SECONDARY,
218 PROP_TOOLTIP_TEXT_PRIMARY,
219 PROP_TOOLTIP_TEXT_SECONDARY,
220 PROP_TOOLTIP_MARKUP_PRIMARY,
221 PROP_TOOLTIP_MARKUP_SECONDARY,
223 PROP_EDITING_CANCELED
226 static guint signals[LAST_SIGNAL] = { 0 };
235 DISPLAY_NORMAL, /* The entry text is being shown */
236 DISPLAY_INVISIBLE, /* In invisible mode, text replaced by (eg) bullets */
237 DISPLAY_BLANK /* In invisible mode, nothing shown at all */
240 /* GObject, GtkObject methods
242 static void gtk_entry_editable_init (GtkEditableInterface *iface);
243 static void gtk_entry_cell_editable_init (GtkCellEditableIface *iface);
244 static void gtk_entry_set_property (GObject *object,
248 static void gtk_entry_get_property (GObject *object,
252 static void gtk_entry_finalize (GObject *object);
253 static void gtk_entry_destroy (GtkObject *object);
254 static void gtk_entry_dispose (GObject *object);
258 static void gtk_entry_realize (GtkWidget *widget);
259 static void gtk_entry_unrealize (GtkWidget *widget);
260 static void gtk_entry_map (GtkWidget *widget);
261 static void gtk_entry_unmap (GtkWidget *widget);
262 static void gtk_entry_size_request (GtkWidget *widget,
263 GtkRequisition *requisition);
264 static void gtk_entry_size_allocate (GtkWidget *widget,
265 GtkAllocation *allocation);
266 static void gtk_entry_draw_frame (GtkWidget *widget,
267 GdkEventExpose *event);
268 static void gtk_entry_draw_progress (GtkWidget *widget,
269 GdkEventExpose *event);
270 static gint gtk_entry_expose (GtkWidget *widget,
271 GdkEventExpose *event);
272 static gint gtk_entry_button_press (GtkWidget *widget,
273 GdkEventButton *event);
274 static gint gtk_entry_button_release (GtkWidget *widget,
275 GdkEventButton *event);
276 static gint gtk_entry_enter_notify (GtkWidget *widget,
277 GdkEventCrossing *event);
278 static gint gtk_entry_leave_notify (GtkWidget *widget,
279 GdkEventCrossing *event);
280 static gint gtk_entry_motion_notify (GtkWidget *widget,
281 GdkEventMotion *event);
282 static gint gtk_entry_key_press (GtkWidget *widget,
284 static gint gtk_entry_key_release (GtkWidget *widget,
286 static gint gtk_entry_focus_in (GtkWidget *widget,
287 GdkEventFocus *event);
288 static gint gtk_entry_focus_out (GtkWidget *widget,
289 GdkEventFocus *event);
290 static void gtk_entry_grab_focus (GtkWidget *widget);
291 static void gtk_entry_style_set (GtkWidget *widget,
292 GtkStyle *previous_style);
293 static gboolean gtk_entry_query_tooltip (GtkWidget *widget,
296 gboolean keyboard_tip,
297 GtkTooltip *tooltip);
298 static void gtk_entry_direction_changed (GtkWidget *widget,
299 GtkTextDirection previous_dir);
300 static void gtk_entry_state_changed (GtkWidget *widget,
301 GtkStateType previous_state);
302 static void gtk_entry_screen_changed (GtkWidget *widget,
303 GdkScreen *old_screen);
305 static gboolean gtk_entry_drag_drop (GtkWidget *widget,
306 GdkDragContext *context,
310 static gboolean gtk_entry_drag_motion (GtkWidget *widget,
311 GdkDragContext *context,
315 static void gtk_entry_drag_leave (GtkWidget *widget,
316 GdkDragContext *context,
318 static void gtk_entry_drag_data_received (GtkWidget *widget,
319 GdkDragContext *context,
322 GtkSelectionData *selection_data,
325 static void gtk_entry_drag_data_get (GtkWidget *widget,
326 GdkDragContext *context,
327 GtkSelectionData *selection_data,
330 static void gtk_entry_drag_data_delete (GtkWidget *widget,
331 GdkDragContext *context);
332 static void gtk_entry_drag_begin (GtkWidget *widget,
333 GdkDragContext *context);
334 static void gtk_entry_drag_end (GtkWidget *widget,
335 GdkDragContext *context);
338 /* GtkEditable method implementations
340 static void gtk_entry_insert_text (GtkEditable *editable,
341 const gchar *new_text,
342 gint new_text_length,
344 static void gtk_entry_delete_text (GtkEditable *editable,
347 static gchar * gtk_entry_get_chars (GtkEditable *editable,
350 static void gtk_entry_real_set_position (GtkEditable *editable,
352 static gint gtk_entry_get_position (GtkEditable *editable);
353 static void gtk_entry_set_selection_bounds (GtkEditable *editable,
356 static gboolean gtk_entry_get_selection_bounds (GtkEditable *editable,
360 /* GtkCellEditable method implementations
362 static void gtk_entry_start_editing (GtkCellEditable *cell_editable,
365 /* Default signal handlers
367 static void gtk_entry_real_insert_text (GtkEditable *editable,
368 const gchar *new_text,
369 gint new_text_length,
371 static void gtk_entry_real_delete_text (GtkEditable *editable,
374 static void gtk_entry_move_cursor (GtkEntry *entry,
375 GtkMovementStep step,
377 gboolean extend_selection);
378 static void gtk_entry_insert_at_cursor (GtkEntry *entry,
380 static void gtk_entry_delete_from_cursor (GtkEntry *entry,
383 static void gtk_entry_backspace (GtkEntry *entry);
384 static void gtk_entry_cut_clipboard (GtkEntry *entry);
385 static void gtk_entry_copy_clipboard (GtkEntry *entry);
386 static void gtk_entry_paste_clipboard (GtkEntry *entry);
387 static void gtk_entry_toggle_overwrite (GtkEntry *entry);
388 static void gtk_entry_select_all (GtkEntry *entry);
389 static void gtk_entry_real_activate (GtkEntry *entry);
390 static gboolean gtk_entry_popup_menu (GtkWidget *widget);
392 static void keymap_direction_changed (GdkKeymap *keymap,
394 static void keymap_state_changed (GdkKeymap *keymap,
396 static void remove_capslock_feedback (GtkEntry *entry);
398 /* IM Context Callbacks
400 static void gtk_entry_commit_cb (GtkIMContext *context,
403 static void gtk_entry_preedit_changed_cb (GtkIMContext *context,
405 static gboolean gtk_entry_retrieve_surrounding_cb (GtkIMContext *context,
407 static gboolean gtk_entry_delete_surrounding_cb (GtkIMContext *context,
414 static void gtk_entry_enter_text (GtkEntry *entry,
416 static void gtk_entry_set_positions (GtkEntry *entry,
418 gint selection_bound);
419 static void gtk_entry_draw_text (GtkEntry *entry);
420 static void gtk_entry_draw_cursor (GtkEntry *entry,
422 static PangoLayout *gtk_entry_ensure_layout (GtkEntry *entry,
423 gboolean include_preedit);
424 static void gtk_entry_reset_layout (GtkEntry *entry);
425 static void gtk_entry_queue_draw (GtkEntry *entry);
426 static void gtk_entry_recompute (GtkEntry *entry);
427 static gint gtk_entry_find_position (GtkEntry *entry,
429 static void gtk_entry_get_cursor_locations (GtkEntry *entry,
433 static void gtk_entry_adjust_scroll (GtkEntry *entry);
434 static gint gtk_entry_move_visually (GtkEntry *editable,
437 static gint gtk_entry_move_logically (GtkEntry *entry,
440 static gint gtk_entry_move_forward_word (GtkEntry *entry,
442 gboolean allow_whitespace);
443 static gint gtk_entry_move_backward_word (GtkEntry *entry,
445 gboolean allow_whitespace);
446 static void gtk_entry_delete_whitespace (GtkEntry *entry);
447 static void gtk_entry_select_word (GtkEntry *entry);
448 static void gtk_entry_select_line (GtkEntry *entry);
449 static void gtk_entry_paste (GtkEntry *entry,
451 static void gtk_entry_update_primary_selection (GtkEntry *entry);
452 static void gtk_entry_do_popup (GtkEntry *entry,
453 GdkEventButton *event);
454 static gboolean gtk_entry_mnemonic_activate (GtkWidget *widget,
455 gboolean group_cycling);
456 static void gtk_entry_check_cursor_blink (GtkEntry *entry);
457 static void gtk_entry_pend_cursor_blink (GtkEntry *entry);
458 static void gtk_entry_reset_blink_time (GtkEntry *entry);
459 static void gtk_entry_get_text_area_size (GtkEntry *entry,
464 static void get_text_area_size (GtkEntry *entry,
469 static void get_widget_window_size (GtkEntry *entry,
474 static void gtk_entry_move_adjustments (GtkEntry *entry);
475 static void gtk_entry_ensure_pixbuf (GtkEntry *entry,
476 GtkEntryIconPosition icon_pos);
480 static gint gtk_entry_completion_timeout (gpointer data);
481 static gboolean gtk_entry_completion_key_press (GtkWidget *widget,
484 static void gtk_entry_completion_changed (GtkWidget *entry,
486 static gboolean check_completion_callback (GtkEntryCompletion *completion);
487 static void clear_completion_callback (GtkEntry *entry,
489 static gboolean accept_completion_callback (GtkEntry *entry);
490 static void completion_insert_text_callback (GtkEntry *entry,
494 GtkEntryCompletion *completion);
495 static void completion_changed (GtkEntryCompletion *completion,
498 static void disconnect_completion_signals (GtkEntry *entry,
499 GtkEntryCompletion *completion);
500 static void connect_completion_signals (GtkEntry *entry,
501 GtkEntryCompletion *completion);
503 static void begin_change (GtkEntry *entry);
504 static void end_change (GtkEntry *entry);
505 static void emit_changed (GtkEntry *entry);
508 static void buffer_inserted_text (GtkEntryBuffer *buffer,
513 static void buffer_deleted_text (GtkEntryBuffer *buffer,
517 static void buffer_notify_text (GtkEntryBuffer *buffer,
520 static void buffer_notify_length (GtkEntryBuffer *buffer,
523 static void buffer_notify_max_length (GtkEntryBuffer *buffer,
526 static void buffer_connect_signals (GtkEntry *entry);
527 static void buffer_disconnect_signals (GtkEntry *entry);
528 static GtkEntryBuffer *get_buffer (GtkEntry *entry);
531 G_DEFINE_TYPE_WITH_CODE (GtkEntry, gtk_entry, GTK_TYPE_WIDGET,
532 G_IMPLEMENT_INTERFACE (GTK_TYPE_EDITABLE,
533 gtk_entry_editable_init)
534 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_EDITABLE,
535 gtk_entry_cell_editable_init))
538 add_move_binding (GtkBindingSet *binding_set,
541 GtkMovementStep step,
544 g_return_if_fail ((modmask & GDK_SHIFT_MASK) == 0);
546 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
550 G_TYPE_BOOLEAN, FALSE);
552 /* Selection-extending version */
553 gtk_binding_entry_add_signal (binding_set, keyval, modmask | GDK_SHIFT_MASK,
557 G_TYPE_BOOLEAN, TRUE);
561 gtk_entry_class_init (GtkEntryClass *class)
563 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
564 GtkWidgetClass *widget_class;
565 GtkObjectClass *gtk_object_class;
566 GtkBindingSet *binding_set;
568 widget_class = (GtkWidgetClass*) class;
569 gtk_object_class = (GtkObjectClass *)class;
571 gobject_class->dispose = gtk_entry_dispose;
572 gobject_class->finalize = gtk_entry_finalize;
573 gobject_class->set_property = gtk_entry_set_property;
574 gobject_class->get_property = gtk_entry_get_property;
576 widget_class->map = gtk_entry_map;
577 widget_class->unmap = gtk_entry_unmap;
578 widget_class->realize = gtk_entry_realize;
579 widget_class->unrealize = gtk_entry_unrealize;
580 widget_class->size_request = gtk_entry_size_request;
581 widget_class->size_allocate = gtk_entry_size_allocate;
582 widget_class->expose_event = gtk_entry_expose;
583 widget_class->enter_notify_event = gtk_entry_enter_notify;
584 widget_class->leave_notify_event = gtk_entry_leave_notify;
585 widget_class->button_press_event = gtk_entry_button_press;
586 widget_class->button_release_event = gtk_entry_button_release;
587 widget_class->motion_notify_event = gtk_entry_motion_notify;
588 widget_class->key_press_event = gtk_entry_key_press;
589 widget_class->key_release_event = gtk_entry_key_release;
590 widget_class->focus_in_event = gtk_entry_focus_in;
591 widget_class->focus_out_event = gtk_entry_focus_out;
592 widget_class->grab_focus = gtk_entry_grab_focus;
593 widget_class->style_set = gtk_entry_style_set;
594 widget_class->query_tooltip = gtk_entry_query_tooltip;
595 widget_class->drag_begin = gtk_entry_drag_begin;
596 widget_class->drag_end = gtk_entry_drag_end;
597 widget_class->direction_changed = gtk_entry_direction_changed;
598 widget_class->state_changed = gtk_entry_state_changed;
599 widget_class->screen_changed = gtk_entry_screen_changed;
600 widget_class->mnemonic_activate = gtk_entry_mnemonic_activate;
602 widget_class->drag_drop = gtk_entry_drag_drop;
603 widget_class->drag_motion = gtk_entry_drag_motion;
604 widget_class->drag_leave = gtk_entry_drag_leave;
605 widget_class->drag_data_received = gtk_entry_drag_data_received;
606 widget_class->drag_data_get = gtk_entry_drag_data_get;
607 widget_class->drag_data_delete = gtk_entry_drag_data_delete;
609 widget_class->popup_menu = gtk_entry_popup_menu;
611 gtk_object_class->destroy = gtk_entry_destroy;
613 class->move_cursor = gtk_entry_move_cursor;
614 class->insert_at_cursor = gtk_entry_insert_at_cursor;
615 class->delete_from_cursor = gtk_entry_delete_from_cursor;
616 class->backspace = gtk_entry_backspace;
617 class->cut_clipboard = gtk_entry_cut_clipboard;
618 class->copy_clipboard = gtk_entry_copy_clipboard;
619 class->paste_clipboard = gtk_entry_paste_clipboard;
620 class->toggle_overwrite = gtk_entry_toggle_overwrite;
621 class->activate = gtk_entry_real_activate;
622 class->get_text_area_size = gtk_entry_get_text_area_size;
624 quark_inner_border = g_quark_from_static_string ("gtk-entry-inner-border");
625 quark_password_hint = g_quark_from_static_string ("gtk-entry-password-hint");
626 quark_cursor_hadjustment = g_quark_from_static_string ("gtk-hadjustment");
627 quark_capslock_feedback = g_quark_from_static_string ("gtk-entry-capslock-feedback");
629 g_object_class_override_property (gobject_class,
630 PROP_EDITING_CANCELED,
633 g_object_class_install_property (gobject_class,
635 g_param_spec_object ("buffer",
637 P_("Text buffer object which actually stores entry text"),
638 GTK_TYPE_ENTRY_BUFFER,
639 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT));
641 g_object_class_install_property (gobject_class,
642 PROP_CURSOR_POSITION,
643 g_param_spec_int ("cursor-position",
644 P_("Cursor Position"),
645 P_("The current position of the insertion cursor in chars"),
647 GTK_ENTRY_BUFFER_MAX_SIZE,
649 GTK_PARAM_READABLE));
651 g_object_class_install_property (gobject_class,
652 PROP_SELECTION_BOUND,
653 g_param_spec_int ("selection-bound",
654 P_("Selection Bound"),
655 P_("The position of the opposite end of the selection from the cursor in chars"),
657 GTK_ENTRY_BUFFER_MAX_SIZE,
659 GTK_PARAM_READABLE));
661 g_object_class_install_property (gobject_class,
663 g_param_spec_boolean ("editable",
665 P_("Whether the entry contents can be edited"),
667 GTK_PARAM_READWRITE));
669 g_object_class_install_property (gobject_class,
671 g_param_spec_int ("max-length",
672 P_("Maximum length"),
673 P_("Maximum number of characters for this entry. Zero if no maximum"),
675 GTK_ENTRY_BUFFER_MAX_SIZE,
677 GTK_PARAM_READWRITE));
678 g_object_class_install_property (gobject_class,
680 g_param_spec_boolean ("visibility",
682 P_("FALSE displays the \"invisible char\" instead of the actual text (password mode)"),
684 GTK_PARAM_READWRITE));
686 g_object_class_install_property (gobject_class,
688 g_param_spec_boolean ("has-frame",
690 P_("FALSE removes outside bevel from entry"),
692 GTK_PARAM_READWRITE));
694 g_object_class_install_property (gobject_class,
696 g_param_spec_boxed ("inner-border",
698 P_("Border between text and frame. Overrides the inner-border style property"),
700 GTK_PARAM_READWRITE));
702 g_object_class_install_property (gobject_class,
704 g_param_spec_unichar ("invisible-char",
705 P_("Invisible character"),
706 P_("The character to use when masking entry contents (in \"password mode\")"),
708 GTK_PARAM_READWRITE));
710 g_object_class_install_property (gobject_class,
711 PROP_ACTIVATES_DEFAULT,
712 g_param_spec_boolean ("activates-default",
713 P_("Activates default"),
714 P_("Whether to activate the default widget (such as the default button in a dialog) when Enter is pressed"),
716 GTK_PARAM_READWRITE));
717 g_object_class_install_property (gobject_class,
719 g_param_spec_int ("width-chars",
720 P_("Width in chars"),
721 P_("Number of characters to leave space for in the entry"),
725 GTK_PARAM_READWRITE));
727 g_object_class_install_property (gobject_class,
729 g_param_spec_int ("scroll-offset",
731 P_("Number of pixels of the entry scrolled off the screen to the left"),
735 GTK_PARAM_READABLE));
737 g_object_class_install_property (gobject_class,
739 g_param_spec_string ("text",
741 P_("The contents of the entry"),
743 GTK_PARAM_READWRITE));
748 * The horizontal alignment, from 0 (left) to 1 (right).
749 * Reversed for RTL layouts.
753 g_object_class_install_property (gobject_class,
755 g_param_spec_float ("xalign",
757 P_("The horizontal alignment, from 0 (left) to 1 (right). Reversed for RTL layouts."),
761 GTK_PARAM_READWRITE));
764 * GtkEntry:truncate-multiline:
766 * When %TRUE, pasted multi-line text is truncated to the first line.
770 g_object_class_install_property (gobject_class,
771 PROP_TRUNCATE_MULTILINE,
772 g_param_spec_boolean ("truncate-multiline",
773 P_("Truncate multiline"),
774 P_("Whether to truncate multiline pastes to one line."),
776 GTK_PARAM_READWRITE));
779 * GtkEntry:shadow-type:
781 * Which kind of shadow to draw around the entry when
782 * #GtkEntry:has-frame is set to %TRUE.
786 g_object_class_install_property (gobject_class,
788 g_param_spec_enum ("shadow-type",
790 P_("Which kind of shadow to draw around the entry when has-frame is set"),
791 GTK_TYPE_SHADOW_TYPE,
793 GTK_PARAM_READWRITE));
796 * GtkEntry:overwrite-mode:
798 * If text is overwritten when typing in the #GtkEntry.
802 g_object_class_install_property (gobject_class,
804 g_param_spec_boolean ("overwrite-mode",
805 P_("Overwrite mode"),
806 P_("Whether new text overwrites existing text"),
808 GTK_PARAM_READWRITE));
811 * GtkEntry:text-length:
813 * The length of the text in the #GtkEntry.
817 g_object_class_install_property (gobject_class,
819 g_param_spec_uint ("text-length",
821 P_("Length of the text currently in the entry"),
825 GTK_PARAM_READABLE));
827 * GtkEntry:invisible-char-set:
829 * Whether the invisible char has been set for the #GtkEntry.
833 g_object_class_install_property (gobject_class,
834 PROP_INVISIBLE_CHAR_SET,
835 g_param_spec_boolean ("invisible-char-set",
836 P_("Invisible character set"),
837 P_("Whether the invisible character has been set"),
839 GTK_PARAM_READWRITE));
842 * GtkEntry:caps-lock-warning
844 * Whether password entries will show a warning when Caps Lock is on.
846 * Note that the warning is shown using a secondary icon, and thus
847 * does not work if you are using the secondary icon position for some
852 g_object_class_install_property (gobject_class,
853 PROP_CAPS_LOCK_WARNING,
854 g_param_spec_boolean ("caps-lock-warning",
855 P_("Caps Lock warning"),
856 P_("Whether password entries will show a warning when Caps Lock is on"),
858 GTK_PARAM_READWRITE));
861 * GtkEntry:progress-fraction:
863 * The current fraction of the task that's been completed.
867 g_object_class_install_property (gobject_class,
868 PROP_PROGRESS_FRACTION,
869 g_param_spec_double ("progress-fraction",
870 P_("Progress Fraction"),
871 P_("The current fraction of the task that's been completed"),
875 GTK_PARAM_READWRITE));
878 * GtkEntry:progress-pulse-step:
880 * The fraction of total entry width to move the progress
881 * bouncing block for each call to gtk_entry_progress_pulse().
885 g_object_class_install_property (gobject_class,
886 PROP_PROGRESS_PULSE_STEP,
887 g_param_spec_double ("progress-pulse-step",
888 P_("Progress Pulse Step"),
889 P_("The fraction of total entry width to move the progress bouncing block for each call to gtk_entry_progress_pulse()"),
893 GTK_PARAM_READWRITE));
896 * GtkEntry:primary-icon-pixbuf:
898 * A pixbuf to use as the primary icon for the entry.
902 g_object_class_install_property (gobject_class,
904 g_param_spec_object ("primary-icon-pixbuf",
905 P_("Primary pixbuf"),
906 P_("Primary pixbuf for the entry"),
908 GTK_PARAM_READWRITE));
911 * GtkEntry:secondary-icon-pixbuf:
913 * An pixbuf to use as the secondary icon for the entry.
917 g_object_class_install_property (gobject_class,
918 PROP_PIXBUF_SECONDARY,
919 g_param_spec_object ("secondary-icon-pixbuf",
920 P_("Secondary pixbuf"),
921 P_("Secondary pixbuf for the entry"),
923 GTK_PARAM_READWRITE));
926 * GtkEntry:primary-icon-stock:
928 * The stock id to use for the primary icon for the entry.
932 g_object_class_install_property (gobject_class,
934 g_param_spec_string ("primary-icon-stock",
935 P_("Primary stock ID"),
936 P_("Stock ID for primary icon"),
938 GTK_PARAM_READWRITE));
941 * GtkEntry:secondary-icon-stock:
943 * The stock id to use for the secondary icon for the entry.
947 g_object_class_install_property (gobject_class,
948 PROP_STOCK_SECONDARY,
949 g_param_spec_string ("secondary-icon-stock",
950 P_("Secondary stock ID"),
951 P_("Stock ID for secondary icon"),
953 GTK_PARAM_READWRITE));
956 * GtkEntry:primary-icon-name:
958 * The icon name to use for the primary icon for the entry.
962 g_object_class_install_property (gobject_class,
963 PROP_ICON_NAME_PRIMARY,
964 g_param_spec_string ("primary-icon-name",
965 P_("Primary icon name"),
966 P_("Icon name for primary icon"),
968 GTK_PARAM_READWRITE));
971 * GtkEntry:secondary-icon-name:
973 * The icon name to use for the secondary icon for the entry.
977 g_object_class_install_property (gobject_class,
978 PROP_ICON_NAME_SECONDARY,
979 g_param_spec_string ("secondary-icon-name",
980 P_("Secondary icon name"),
981 P_("Icon name for secondary icon"),
983 GTK_PARAM_READWRITE));
986 * GtkEntry:primary-icon-gicon:
988 * The #GIcon to use for the primary icon for the entry.
992 g_object_class_install_property (gobject_class,
994 g_param_spec_object ("primary-icon-gicon",
996 P_("GIcon for primary icon"),
998 GTK_PARAM_READWRITE));
1001 * GtkEntry:secondary-icon-gicon:
1003 * The #GIcon to use for the secondary icon for the entry.
1007 g_object_class_install_property (gobject_class,
1008 PROP_GICON_SECONDARY,
1009 g_param_spec_object ("secondary-icon-gicon",
1010 P_("Secondary GIcon"),
1011 P_("GIcon for secondary icon"),
1013 GTK_PARAM_READWRITE));
1016 * GtkEntry:primary-icon-storage-type:
1018 * The representation which is used for the primary icon of the entry.
1022 g_object_class_install_property (gobject_class,
1023 PROP_STORAGE_TYPE_PRIMARY,
1024 g_param_spec_enum ("primary-icon-storage-type",
1025 P_("Primary storage type"),
1026 P_("The representation being used for primary icon"),
1027 GTK_TYPE_IMAGE_TYPE,
1029 GTK_PARAM_READABLE));
1032 * GtkEntry:secondary-icon-storage-type:
1034 * The representation which is used for the secondary icon of the entry.
1038 g_object_class_install_property (gobject_class,
1039 PROP_STORAGE_TYPE_SECONDARY,
1040 g_param_spec_enum ("secondary-icon-storage-type",
1041 P_("Secondary storage type"),
1042 P_("The representation being used for secondary icon"),
1043 GTK_TYPE_IMAGE_TYPE,
1045 GTK_PARAM_READABLE));
1048 * GtkEntry:primary-icon-activatable:
1050 * Whether the primary icon is activatable.
1052 * GTK+ emits the #GtkEntry::icon-press and #GtkEntry::icon-release
1053 * signals only on sensitive, activatable icons.
1055 * Sensitive, but non-activatable icons can be used for purely
1056 * informational purposes.
1060 g_object_class_install_property (gobject_class,
1061 PROP_ACTIVATABLE_PRIMARY,
1062 g_param_spec_boolean ("primary-icon-activatable",
1063 P_("Primary icon activatable"),
1064 P_("Whether the primary icon is activatable"),
1066 GTK_PARAM_READWRITE));
1069 * GtkEntry:secondary-icon-activatable:
1071 * Whether the secondary icon is activatable.
1073 * GTK+ emits the #GtkEntry::icon-press and #GtkEntry::icon-release
1074 * signals only on sensitive, activatable icons.
1076 * Sensitive, but non-activatable icons can be used for purely
1077 * informational purposes.
1081 g_object_class_install_property (gobject_class,
1082 PROP_ACTIVATABLE_SECONDARY,
1083 g_param_spec_boolean ("secondary-icon-activatable",
1084 P_("Secondary icon activatable"),
1085 P_("Whether the secondary icon is activatable"),
1087 GTK_PARAM_READWRITE));
1091 * GtkEntry:primary-icon-sensitive:
1093 * Whether the primary icon is sensitive.
1095 * An insensitive icon appears grayed out. GTK+ does not emit the
1096 * #GtkEntry::icon-press and #GtkEntry::icon-release signals and
1097 * does not allow DND from insensitive icons.
1099 * An icon should be set insensitive if the action that would trigger
1100 * when clicked is currently not available.
1104 g_object_class_install_property (gobject_class,
1105 PROP_SENSITIVE_PRIMARY,
1106 g_param_spec_boolean ("primary-icon-sensitive",
1107 P_("Primary icon sensitive"),
1108 P_("Whether the primary icon is sensitive"),
1110 GTK_PARAM_READWRITE));
1113 * GtkEntry:secondary-icon-sensitive:
1115 * Whether the secondary icon is sensitive.
1117 * An insensitive icon appears grayed out. GTK+ does not emit the
1118 * #GtkEntry::icon-press and #GtkEntry::icon-release signals and
1119 * does not allow DND from insensitive icons.
1121 * An icon should be set insensitive if the action that would trigger
1122 * when clicked is currently not available.
1126 g_object_class_install_property (gobject_class,
1127 PROP_SENSITIVE_SECONDARY,
1128 g_param_spec_boolean ("secondary-icon-sensitive",
1129 P_("Secondary icon sensitive"),
1130 P_("Whether the secondary icon is sensitive"),
1132 GTK_PARAM_READWRITE));
1135 * GtkEntry:primary-icon-tooltip-text:
1137 * The contents of the tooltip on the primary icon.
1139 * Also see gtk_entry_set_icon_tooltip_text().
1143 g_object_class_install_property (gobject_class,
1144 PROP_TOOLTIP_TEXT_PRIMARY,
1145 g_param_spec_string ("primary-icon-tooltip-text",
1146 P_("Primary icon tooltip text"),
1147 P_("The contents of the tooltip on the primary icon"),
1149 GTK_PARAM_READWRITE));
1152 * GtkEntry:secondary-icon-tooltip-text:
1154 * The contents of the tooltip on the secondary icon.
1156 * Also see gtk_entry_set_icon_tooltip_text().
1160 g_object_class_install_property (gobject_class,
1161 PROP_TOOLTIP_TEXT_SECONDARY,
1162 g_param_spec_string ("secondary-icon-tooltip-text",
1163 P_("Secondary icon tooltip text"),
1164 P_("The contents of the tooltip on the secondary icon"),
1166 GTK_PARAM_READWRITE));
1169 * GtkEntry:primary-icon-tooltip-markup:
1171 * The contents of the tooltip on the primary icon, which is marked up
1172 * with the <link linkend="PangoMarkupFormat">Pango text markup
1175 * Also see gtk_entry_set_icon_tooltip_markup().
1179 g_object_class_install_property (gobject_class,
1180 PROP_TOOLTIP_MARKUP_PRIMARY,
1181 g_param_spec_string ("primary-icon-tooltip-markup",
1182 P_("Primary icon tooltip markup"),
1183 P_("The contents of the tooltip on the primary icon"),
1185 GTK_PARAM_READWRITE));
1188 * GtkEntry:secondary-icon-tooltip-markup:
1190 * The contents of the tooltip on the secondary icon, which is marked up
1191 * with the <link linkend="PangoMarkupFormat">Pango text markup
1194 * Also see gtk_entry_set_icon_tooltip_markup().
1198 g_object_class_install_property (gobject_class,
1199 PROP_TOOLTIP_MARKUP_SECONDARY,
1200 g_param_spec_string ("secondary-icon-tooltip-markup",
1201 P_("Secondary icon tooltip markup"),
1202 P_("The contents of the tooltip on the secondary icon"),
1204 GTK_PARAM_READWRITE));
1207 * GtkEntry:im-module:
1209 * Which IM (input method) module should be used for this entry.
1210 * See #GtkIMContext.
1212 * Setting this to a non-%NULL value overrides the
1213 * system-wide IM module setting. See the GtkSettings
1214 * #GtkSettings:gtk-im-module property.
1218 g_object_class_install_property (gobject_class,
1220 g_param_spec_string ("im-module",
1222 P_("Which IM module should be used"),
1224 GTK_PARAM_READWRITE));
1227 * GtkEntry:icon-prelight:
1229 * The prelight style property determines whether activatable
1230 * icons prelight on mouseover.
1234 gtk_widget_class_install_style_property (widget_class,
1235 g_param_spec_boolean ("icon-prelight",
1236 P_("Icon Prelight"),
1237 P_("Whether activatable icons should prelight when hovered"),
1239 GTK_PARAM_READABLE));
1242 * GtkEntry:progress-border:
1244 * The border around the progress bar in the entry.
1248 gtk_widget_class_install_style_property (widget_class,
1249 g_param_spec_boxed ("progress-border",
1250 P_("Progress Border"),
1251 P_("Border around the progress bar"),
1253 GTK_PARAM_READABLE));
1256 * GtkEntry:invisible-char:
1258 * The invisible character is used when masking entry contents (in
1259 * \"password mode\")"). When it is not explicitly set with the
1260 * #GtkEntry::invisible-char property, GTK+ determines the character
1261 * to use from a list of possible candidates, depending on availability
1262 * in the current font.
1264 * This style property allows the theme to prepend a character
1265 * to the list of candidates.
1269 gtk_widget_class_install_style_property (widget_class,
1270 g_param_spec_unichar ("invisible-char",
1271 P_("Invisible character"),
1272 P_("The character to use when masking entry contents (in \"password mode\")"),
1274 GTK_PARAM_READABLE));
1277 * GtkEntry::populate-popup:
1278 * @entry: The entry on which the signal is emitted
1279 * @menu: the menu that is being populated
1281 * The ::populate-popup signal gets emitted before showing the
1282 * context menu of the entry.
1284 * If you need to add items to the context menu, connect
1285 * to this signal and append your menuitems to the @menu.
1287 signals[POPULATE_POPUP] =
1288 g_signal_new (I_("populate-popup"),
1289 G_OBJECT_CLASS_TYPE (gobject_class),
1291 G_STRUCT_OFFSET (GtkEntryClass, populate_popup),
1293 _gtk_marshal_VOID__OBJECT,
1297 /* Action signals */
1300 * GtkEntry::activate:
1301 * @entry: The entry on which the signal is emitted
1303 * A <link linkend="keybinding-signals">keybinding signal</link>
1304 * which gets emitted when the user activates the entry.
1306 * Applications should not connect to it, but may emit it with
1307 * g_signal_emit_by_name() if they need to control activation
1310 * The default bindings for this signal are all forms of the Enter key.
1313 g_signal_new (I_("activate"),
1314 G_OBJECT_CLASS_TYPE (gobject_class),
1315 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1316 G_STRUCT_OFFSET (GtkEntryClass, activate),
1318 _gtk_marshal_VOID__VOID,
1320 widget_class->activate_signal = signals[ACTIVATE];
1323 * GtkEntry::move-cursor:
1324 * @entry: the object which received the signal
1325 * @step: the granularity of the move, as a #GtkMovementStep
1326 * @count: the number of @step units to move
1327 * @extend_selection: %TRUE if the move should extend the selection
1329 * The ::move-cursor signal is a
1330 * <link linkend="keybinding-signals">keybinding signal</link>
1331 * which gets emitted when the user initiates a cursor movement.
1332 * If the cursor is not visible in @entry, this signal causes
1333 * the viewport to be moved instead.
1335 * Applications should not connect to it, but may emit it with
1336 * g_signal_emit_by_name() if they need to control the cursor
1339 * The default bindings for this signal come in two variants,
1340 * the variant with the Shift modifier extends the selection,
1341 * the variant without the Shift modifer does not.
1342 * There are too many key combinations to list them all here.
1344 * <listitem>Arrow keys move by individual characters/lines</listitem>
1345 * <listitem>Ctrl-arrow key combinations move by words/paragraphs</listitem>
1346 * <listitem>Home/End keys move to the ends of the buffer</listitem>
1349 signals[MOVE_CURSOR] =
1350 g_signal_new (I_("move-cursor"),
1351 G_OBJECT_CLASS_TYPE (gobject_class),
1352 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1353 G_STRUCT_OFFSET (GtkEntryClass, move_cursor),
1355 _gtk_marshal_VOID__ENUM_INT_BOOLEAN,
1357 GTK_TYPE_MOVEMENT_STEP,
1362 * GtkEntry::insert-at-cursor:
1363 * @entry: the object which received the signal
1364 * @string: the string to insert
1366 * The ::insert-at-cursor signal is a
1367 * <link linkend="keybinding-signals">keybinding signal</link>
1368 * which gets emitted when the user initiates the insertion of a
1369 * fixed string at the cursor.
1371 * This signal has no default bindings.
1373 signals[INSERT_AT_CURSOR] =
1374 g_signal_new (I_("insert-at-cursor"),
1375 G_OBJECT_CLASS_TYPE (gobject_class),
1376 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1377 G_STRUCT_OFFSET (GtkEntryClass, insert_at_cursor),
1379 _gtk_marshal_VOID__STRING,
1384 * GtkEntry::delete-from-cursor:
1385 * @entry: the object which received the signal
1386 * @type: the granularity of the deletion, as a #GtkDeleteType
1387 * @count: the number of @type units to delete
1389 * The ::delete-from-cursor signal is a
1390 * <link linkend="keybinding-signals">keybinding signal</link>
1391 * which gets emitted when the user initiates a text deletion.
1393 * If the @type is %GTK_DELETE_CHARS, GTK+ deletes the selection
1394 * if there is one, otherwise it deletes the requested number
1397 * The default bindings for this signal are
1398 * Delete for deleting a character and Ctrl-Delete for
1401 signals[DELETE_FROM_CURSOR] =
1402 g_signal_new (I_("delete-from-cursor"),
1403 G_OBJECT_CLASS_TYPE (gobject_class),
1404 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1405 G_STRUCT_OFFSET (GtkEntryClass, delete_from_cursor),
1407 _gtk_marshal_VOID__ENUM_INT,
1409 GTK_TYPE_DELETE_TYPE,
1413 * GtkEntry::backspace:
1414 * @entry: the object which received the signal
1416 * The ::backspace signal is a
1417 * <link linkend="keybinding-signals">keybinding signal</link>
1418 * which gets emitted when the user asks for it.
1420 * The default bindings for this signal are
1421 * Backspace and Shift-Backspace.
1423 signals[BACKSPACE] =
1424 g_signal_new (I_("backspace"),
1425 G_OBJECT_CLASS_TYPE (gobject_class),
1426 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1427 G_STRUCT_OFFSET (GtkEntryClass, backspace),
1429 _gtk_marshal_VOID__VOID,
1433 * GtkEntry::cut-clipboard:
1434 * @entry: the object which received the signal
1436 * The ::cut-clipboard signal is a
1437 * <link linkend="keybinding-signals">keybinding signal</link>
1438 * which gets emitted to cut the selection to the clipboard.
1440 * The default bindings for this signal are
1441 * Ctrl-x and Shift-Delete.
1443 signals[CUT_CLIPBOARD] =
1444 g_signal_new (I_("cut-clipboard"),
1445 G_OBJECT_CLASS_TYPE (gobject_class),
1446 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1447 G_STRUCT_OFFSET (GtkEntryClass, cut_clipboard),
1449 _gtk_marshal_VOID__VOID,
1453 * GtkEntry::copy-clipboard:
1454 * @entry: the object which received the signal
1456 * The ::copy-clipboard signal is a
1457 * <link linkend="keybinding-signals">keybinding signal</link>
1458 * which gets emitted to copy the selection to the clipboard.
1460 * The default bindings for this signal are
1461 * Ctrl-c and Ctrl-Insert.
1463 signals[COPY_CLIPBOARD] =
1464 g_signal_new (I_("copy-clipboard"),
1465 G_OBJECT_CLASS_TYPE (gobject_class),
1466 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1467 G_STRUCT_OFFSET (GtkEntryClass, copy_clipboard),
1469 _gtk_marshal_VOID__VOID,
1473 * GtkEntry::paste-clipboard:
1474 * @entry: the object which received the signal
1476 * The ::paste-clipboard signal is a
1477 * <link linkend="keybinding-signals">keybinding signal</link>
1478 * which gets emitted to paste the contents of the clipboard
1479 * into the text view.
1481 * The default bindings for this signal are
1482 * Ctrl-v and Shift-Insert.
1484 signals[PASTE_CLIPBOARD] =
1485 g_signal_new (I_("paste-clipboard"),
1486 G_OBJECT_CLASS_TYPE (gobject_class),
1487 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1488 G_STRUCT_OFFSET (GtkEntryClass, paste_clipboard),
1490 _gtk_marshal_VOID__VOID,
1494 * GtkEntry::toggle-overwrite:
1495 * @entry: the object which received the signal
1497 * The ::toggle-overwrite signal is a
1498 * <link linkend="keybinding-signals">keybinding signal</link>
1499 * which gets emitted to toggle the overwrite mode of the entry.
1501 * The default bindings for this signal is Insert.
1503 signals[TOGGLE_OVERWRITE] =
1504 g_signal_new (I_("toggle-overwrite"),
1505 G_OBJECT_CLASS_TYPE (gobject_class),
1506 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1507 G_STRUCT_OFFSET (GtkEntryClass, toggle_overwrite),
1509 _gtk_marshal_VOID__VOID,
1513 * GtkEntry::icon-press:
1514 * @entry: The entry on which the signal is emitted
1515 * @icon_pos: The position of the clicked icon
1516 * @event: the button press event
1518 * The ::icon-press signal is emitted when an activatable icon
1523 signals[ICON_PRESS] =
1524 g_signal_new (I_("icon-press"),
1525 G_TYPE_FROM_CLASS (gobject_class),
1529 _gtk_marshal_VOID__ENUM_BOXED,
1531 GTK_TYPE_ENTRY_ICON_POSITION,
1532 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1535 * GtkEntry::icon-release:
1536 * @entry: The entry on which the signal is emitted
1537 * @icon_pos: The position of the clicked icon
1538 * @event: the button release event
1540 * The ::icon-release signal is emitted on the button release from a
1541 * mouse click over an activatable icon.
1545 signals[ICON_RELEASE] =
1546 g_signal_new (I_("icon-release"),
1547 G_TYPE_FROM_CLASS (gobject_class),
1551 _gtk_marshal_VOID__ENUM_BOXED,
1553 GTK_TYPE_ENTRY_ICON_POSITION,
1554 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1557 * GtkEntry::preedit-changed:
1558 * @entry: the object which received the signal
1559 * @preedit: the current preedit string
1561 * If an input method is used, the typed text will not immediately
1562 * be committed to the buffer. So if you are interested in the text,
1563 * connect to this signal.
1567 signals[PREEDIT_CHANGED] =
1568 g_signal_new_class_handler (I_("preedit-changed"),
1569 G_OBJECT_CLASS_TYPE (gobject_class),
1570 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1573 _gtk_marshal_VOID__STRING,
1582 binding_set = gtk_binding_set_by_class (class);
1584 /* Moving the insertion point */
1585 add_move_binding (binding_set, GDK_KEY_Right, 0,
1586 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1588 add_move_binding (binding_set, GDK_KEY_Left, 0,
1589 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1591 add_move_binding (binding_set, GDK_KEY_KP_Right, 0,
1592 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1594 add_move_binding (binding_set, GDK_KEY_KP_Left, 0,
1595 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1597 add_move_binding (binding_set, GDK_KEY_Right, GDK_CONTROL_MASK,
1598 GTK_MOVEMENT_WORDS, 1);
1600 add_move_binding (binding_set, GDK_KEY_Left, GDK_CONTROL_MASK,
1601 GTK_MOVEMENT_WORDS, -1);
1603 add_move_binding (binding_set, GDK_KEY_KP_Right, GDK_CONTROL_MASK,
1604 GTK_MOVEMENT_WORDS, 1);
1606 add_move_binding (binding_set, GDK_KEY_KP_Left, GDK_CONTROL_MASK,
1607 GTK_MOVEMENT_WORDS, -1);
1609 add_move_binding (binding_set, GDK_KEY_Home, 0,
1610 GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
1612 add_move_binding (binding_set, GDK_KEY_End, 0,
1613 GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
1615 add_move_binding (binding_set, GDK_KEY_KP_Home, 0,
1616 GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
1618 add_move_binding (binding_set, GDK_KEY_KP_End, 0,
1619 GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
1621 add_move_binding (binding_set, GDK_KEY_Home, GDK_CONTROL_MASK,
1622 GTK_MOVEMENT_BUFFER_ENDS, -1);
1624 add_move_binding (binding_set, GDK_KEY_End, GDK_CONTROL_MASK,
1625 GTK_MOVEMENT_BUFFER_ENDS, 1);
1627 add_move_binding (binding_set, GDK_KEY_KP_Home, GDK_CONTROL_MASK,
1628 GTK_MOVEMENT_BUFFER_ENDS, -1);
1630 add_move_binding (binding_set, GDK_KEY_KP_End, GDK_CONTROL_MASK,
1631 GTK_MOVEMENT_BUFFER_ENDS, 1);
1635 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK,
1637 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1639 G_TYPE_BOOLEAN, FALSE);
1640 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK,
1642 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1644 G_TYPE_BOOLEAN, TRUE);
1646 gtk_binding_entry_add_signal (binding_set, GDK_KEY_slash, GDK_CONTROL_MASK,
1648 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1650 G_TYPE_BOOLEAN, FALSE);
1651 gtk_binding_entry_add_signal (binding_set, GDK_KEY_slash, GDK_CONTROL_MASK,
1653 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1655 G_TYPE_BOOLEAN, TRUE);
1658 gtk_binding_entry_add_signal (binding_set, GDK_KEY_backslash, GDK_CONTROL_MASK,
1660 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_VISUAL_POSITIONS,
1662 G_TYPE_BOOLEAN, FALSE);
1663 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_SHIFT_MASK | GDK_CONTROL_MASK,
1665 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_VISUAL_POSITIONS,
1667 G_TYPE_BOOLEAN, FALSE);
1671 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Return, 0,
1673 gtk_binding_entry_add_signal (binding_set, GDK_KEY_ISO_Enter, 0,
1675 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Enter, 0,
1679 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, 0,
1680 "delete-from-cursor", 2,
1681 G_TYPE_ENUM, GTK_DELETE_CHARS,
1684 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Delete, 0,
1685 "delete-from-cursor", 2,
1686 G_TYPE_ENUM, GTK_DELETE_CHARS,
1689 gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, 0,
1692 /* Make this do the same as Backspace, to help with mis-typing */
1693 gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, GDK_SHIFT_MASK,
1696 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, GDK_CONTROL_MASK,
1697 "delete-from-cursor", 2,
1698 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1701 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Delete, GDK_CONTROL_MASK,
1702 "delete-from-cursor", 2,
1703 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1706 gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, GDK_CONTROL_MASK,
1707 "delete-from-cursor", 2,
1708 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1711 /* Cut/copy/paste */
1713 gtk_binding_entry_add_signal (binding_set, GDK_KEY_x, GDK_CONTROL_MASK,
1714 "cut-clipboard", 0);
1715 gtk_binding_entry_add_signal (binding_set, GDK_KEY_c, GDK_CONTROL_MASK,
1716 "copy-clipboard", 0);
1717 gtk_binding_entry_add_signal (binding_set, GDK_KEY_v, GDK_CONTROL_MASK,
1718 "paste-clipboard", 0);
1720 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, GDK_SHIFT_MASK,
1721 "cut-clipboard", 0);
1722 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, GDK_CONTROL_MASK,
1723 "copy-clipboard", 0);
1724 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, GDK_SHIFT_MASK,
1725 "paste-clipboard", 0);
1728 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, 0,
1729 "toggle-overwrite", 0);
1730 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Insert, 0,
1731 "toggle-overwrite", 0);
1734 * GtkEntry:inner-border:
1736 * Sets the text area's border between the text and the frame.
1740 gtk_widget_class_install_style_property (widget_class,
1741 g_param_spec_boxed ("inner-border",
1743 P_("Border between text and frame."),
1745 GTK_PARAM_READABLE));
1747 gtk_settings_install_property (g_param_spec_boolean ("gtk-entry-select-on-focus",
1748 P_("Select on focus"),
1749 P_("Whether to select the contents of an entry when it is focused"),
1751 GTK_PARAM_READWRITE));
1754 * GtkSettings:gtk-entry-password-hint-timeout:
1756 * How long to show the last input character in hidden
1757 * entries. This value is in milliseconds. 0 disables showing the
1758 * last char. 600 is a good value for enabling it.
1762 gtk_settings_install_property (g_param_spec_uint ("gtk-entry-password-hint-timeout",
1763 P_("Password Hint Timeout"),
1764 P_("How long to show the last input character in hidden entries"),
1766 GTK_PARAM_READWRITE));
1768 g_type_class_add_private (gobject_class, sizeof (GtkEntryPrivate));
1772 gtk_entry_editable_init (GtkEditableInterface *iface)
1774 iface->do_insert_text = gtk_entry_insert_text;
1775 iface->do_delete_text = gtk_entry_delete_text;
1776 iface->insert_text = gtk_entry_real_insert_text;
1777 iface->delete_text = gtk_entry_real_delete_text;
1778 iface->get_chars = gtk_entry_get_chars;
1779 iface->set_selection_bounds = gtk_entry_set_selection_bounds;
1780 iface->get_selection_bounds = gtk_entry_get_selection_bounds;
1781 iface->set_position = gtk_entry_real_set_position;
1782 iface->get_position = gtk_entry_get_position;
1786 gtk_entry_cell_editable_init (GtkCellEditableIface *iface)
1788 iface->start_editing = gtk_entry_start_editing;
1792 gtk_entry_set_property (GObject *object,
1794 const GValue *value,
1797 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (object);
1798 GtkEntry *entry = GTK_ENTRY (object);
1804 gtk_entry_set_buffer (entry, g_value_get_object (value));
1809 gboolean new_value = g_value_get_boolean (value);
1811 if (new_value != entry->editable)
1813 widget = GTK_WIDGET (entry);
1816 _gtk_entry_reset_im_context (entry);
1817 if (gtk_widget_has_focus (widget))
1818 gtk_im_context_focus_out (entry->im_context);
1820 entry->preedit_length = 0;
1821 entry->preedit_cursor = 0;
1824 entry->editable = new_value;
1826 if (new_value && gtk_widget_has_focus (widget))
1827 gtk_im_context_focus_in (entry->im_context);
1829 gtk_entry_queue_draw (entry);
1834 case PROP_MAX_LENGTH:
1835 gtk_entry_set_max_length (entry, g_value_get_int (value));
1838 case PROP_VISIBILITY:
1839 gtk_entry_set_visibility (entry, g_value_get_boolean (value));
1842 case PROP_HAS_FRAME:
1843 gtk_entry_set_has_frame (entry, g_value_get_boolean (value));
1846 case PROP_INNER_BORDER:
1847 gtk_entry_set_inner_border (entry, g_value_get_boxed (value));
1850 case PROP_INVISIBLE_CHAR:
1851 gtk_entry_set_invisible_char (entry, g_value_get_uint (value));
1854 case PROP_ACTIVATES_DEFAULT:
1855 gtk_entry_set_activates_default (entry, g_value_get_boolean (value));
1858 case PROP_WIDTH_CHARS:
1859 gtk_entry_set_width_chars (entry, g_value_get_int (value));
1863 gtk_entry_set_text (entry, g_value_get_string (value));
1867 gtk_entry_set_alignment (entry, g_value_get_float (value));
1870 case PROP_TRUNCATE_MULTILINE:
1871 entry->truncate_multiline = g_value_get_boolean (value);
1874 case PROP_SHADOW_TYPE:
1875 priv->shadow_type = g_value_get_enum (value);
1878 case PROP_OVERWRITE_MODE:
1879 gtk_entry_set_overwrite_mode (entry, g_value_get_boolean (value));
1882 case PROP_INVISIBLE_CHAR_SET:
1883 if (g_value_get_boolean (value))
1884 priv->invisible_char_set = TRUE;
1886 gtk_entry_unset_invisible_char (entry);
1889 case PROP_CAPS_LOCK_WARNING:
1890 priv->caps_lock_warning = g_value_get_boolean (value);
1893 case PROP_PROGRESS_FRACTION:
1894 gtk_entry_set_progress_fraction (entry, g_value_get_double (value));
1897 case PROP_PROGRESS_PULSE_STEP:
1898 gtk_entry_set_progress_pulse_step (entry, g_value_get_double (value));
1901 case PROP_PIXBUF_PRIMARY:
1902 gtk_entry_set_icon_from_pixbuf (entry,
1903 GTK_ENTRY_ICON_PRIMARY,
1904 g_value_get_object (value));
1907 case PROP_PIXBUF_SECONDARY:
1908 gtk_entry_set_icon_from_pixbuf (entry,
1909 GTK_ENTRY_ICON_SECONDARY,
1910 g_value_get_object (value));
1913 case PROP_STOCK_PRIMARY:
1914 gtk_entry_set_icon_from_stock (entry,
1915 GTK_ENTRY_ICON_PRIMARY,
1916 g_value_get_string (value));
1919 case PROP_STOCK_SECONDARY:
1920 gtk_entry_set_icon_from_stock (entry,
1921 GTK_ENTRY_ICON_SECONDARY,
1922 g_value_get_string (value));
1925 case PROP_ICON_NAME_PRIMARY:
1926 gtk_entry_set_icon_from_icon_name (entry,
1927 GTK_ENTRY_ICON_PRIMARY,
1928 g_value_get_string (value));
1931 case PROP_ICON_NAME_SECONDARY:
1932 gtk_entry_set_icon_from_icon_name (entry,
1933 GTK_ENTRY_ICON_SECONDARY,
1934 g_value_get_string (value));
1937 case PROP_GICON_PRIMARY:
1938 gtk_entry_set_icon_from_gicon (entry,
1939 GTK_ENTRY_ICON_PRIMARY,
1940 g_value_get_object (value));
1943 case PROP_GICON_SECONDARY:
1944 gtk_entry_set_icon_from_gicon (entry,
1945 GTK_ENTRY_ICON_SECONDARY,
1946 g_value_get_object (value));
1949 case PROP_ACTIVATABLE_PRIMARY:
1950 gtk_entry_set_icon_activatable (entry,
1951 GTK_ENTRY_ICON_PRIMARY,
1952 g_value_get_boolean (value));
1955 case PROP_ACTIVATABLE_SECONDARY:
1956 gtk_entry_set_icon_activatable (entry,
1957 GTK_ENTRY_ICON_SECONDARY,
1958 g_value_get_boolean (value));
1961 case PROP_SENSITIVE_PRIMARY:
1962 gtk_entry_set_icon_sensitive (entry,
1963 GTK_ENTRY_ICON_PRIMARY,
1964 g_value_get_boolean (value));
1967 case PROP_SENSITIVE_SECONDARY:
1968 gtk_entry_set_icon_sensitive (entry,
1969 GTK_ENTRY_ICON_SECONDARY,
1970 g_value_get_boolean (value));
1973 case PROP_TOOLTIP_TEXT_PRIMARY:
1974 gtk_entry_set_icon_tooltip_text (entry,
1975 GTK_ENTRY_ICON_PRIMARY,
1976 g_value_get_string (value));
1979 case PROP_TOOLTIP_TEXT_SECONDARY:
1980 gtk_entry_set_icon_tooltip_text (entry,
1981 GTK_ENTRY_ICON_SECONDARY,
1982 g_value_get_string (value));
1985 case PROP_TOOLTIP_MARKUP_PRIMARY:
1986 gtk_entry_set_icon_tooltip_markup (entry,
1987 GTK_ENTRY_ICON_PRIMARY,
1988 g_value_get_string (value));
1991 case PROP_TOOLTIP_MARKUP_SECONDARY:
1992 gtk_entry_set_icon_tooltip_markup (entry,
1993 GTK_ENTRY_ICON_SECONDARY,
1994 g_value_get_string (value));
1997 case PROP_IM_MODULE:
1998 g_free (priv->im_module);
1999 priv->im_module = g_value_dup_string (value);
2000 if (GTK_IS_IM_MULTICONTEXT (entry->im_context))
2001 gtk_im_multicontext_set_context_id (GTK_IM_MULTICONTEXT (entry->im_context), priv->im_module);
2004 case PROP_EDITING_CANCELED:
2005 entry->editing_canceled = g_value_get_boolean (value);
2008 case PROP_SCROLL_OFFSET:
2009 case PROP_CURSOR_POSITION:
2011 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2017 gtk_entry_get_property (GObject *object,
2022 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (object);
2023 GtkEntry *entry = GTK_ENTRY (object);
2028 g_value_set_object (value, gtk_entry_get_buffer (entry));
2031 case PROP_CURSOR_POSITION:
2032 g_value_set_int (value, entry->current_pos);
2035 case PROP_SELECTION_BOUND:
2036 g_value_set_int (value, entry->selection_bound);
2040 g_value_set_boolean (value, entry->editable);
2043 case PROP_MAX_LENGTH:
2044 g_value_set_int (value, gtk_entry_buffer_get_max_length (get_buffer (entry)));
2047 case PROP_VISIBILITY:
2048 g_value_set_boolean (value, entry->visible);
2051 case PROP_HAS_FRAME:
2052 g_value_set_boolean (value, entry->has_frame);
2055 case PROP_INNER_BORDER:
2056 g_value_set_boxed (value, gtk_entry_get_inner_border (entry));
2059 case PROP_INVISIBLE_CHAR:
2060 g_value_set_uint (value, entry->invisible_char);
2063 case PROP_ACTIVATES_DEFAULT:
2064 g_value_set_boolean (value, entry->activates_default);
2067 case PROP_WIDTH_CHARS:
2068 g_value_set_int (value, entry->width_chars);
2071 case PROP_SCROLL_OFFSET:
2072 g_value_set_int (value, entry->scroll_offset);
2076 g_value_set_string (value, gtk_entry_get_text (entry));
2080 g_value_set_float (value, gtk_entry_get_alignment (entry));
2083 case PROP_TRUNCATE_MULTILINE:
2084 g_value_set_boolean (value, entry->truncate_multiline);
2087 case PROP_SHADOW_TYPE:
2088 g_value_set_enum (value, priv->shadow_type);
2091 case PROP_OVERWRITE_MODE:
2092 g_value_set_boolean (value, entry->overwrite_mode);
2095 case PROP_TEXT_LENGTH:
2096 g_value_set_uint (value, gtk_entry_buffer_get_length (get_buffer (entry)));
2099 case PROP_INVISIBLE_CHAR_SET:
2100 g_value_set_boolean (value, priv->invisible_char_set);
2103 case PROP_IM_MODULE:
2104 g_value_set_string (value, priv->im_module);
2107 case PROP_CAPS_LOCK_WARNING:
2108 g_value_set_boolean (value, priv->caps_lock_warning);
2111 case PROP_PROGRESS_FRACTION:
2112 g_value_set_double (value, priv->progress_fraction);
2115 case PROP_PROGRESS_PULSE_STEP:
2116 g_value_set_double (value, priv->progress_pulse_fraction);
2119 case PROP_PIXBUF_PRIMARY:
2120 g_value_set_object (value,
2121 gtk_entry_get_icon_pixbuf (entry,
2122 GTK_ENTRY_ICON_PRIMARY));
2125 case PROP_PIXBUF_SECONDARY:
2126 g_value_set_object (value,
2127 gtk_entry_get_icon_pixbuf (entry,
2128 GTK_ENTRY_ICON_SECONDARY));
2131 case PROP_STOCK_PRIMARY:
2132 g_value_set_string (value,
2133 gtk_entry_get_icon_stock (entry,
2134 GTK_ENTRY_ICON_PRIMARY));
2137 case PROP_STOCK_SECONDARY:
2138 g_value_set_string (value,
2139 gtk_entry_get_icon_stock (entry,
2140 GTK_ENTRY_ICON_SECONDARY));
2143 case PROP_ICON_NAME_PRIMARY:
2144 g_value_set_string (value,
2145 gtk_entry_get_icon_name (entry,
2146 GTK_ENTRY_ICON_PRIMARY));
2149 case PROP_ICON_NAME_SECONDARY:
2150 g_value_set_string (value,
2151 gtk_entry_get_icon_name (entry,
2152 GTK_ENTRY_ICON_SECONDARY));
2155 case PROP_GICON_PRIMARY:
2156 g_value_set_object (value,
2157 gtk_entry_get_icon_gicon (entry,
2158 GTK_ENTRY_ICON_PRIMARY));
2161 case PROP_GICON_SECONDARY:
2162 g_value_set_object (value,
2163 gtk_entry_get_icon_gicon (entry,
2164 GTK_ENTRY_ICON_SECONDARY));
2167 case PROP_STORAGE_TYPE_PRIMARY:
2168 g_value_set_enum (value,
2169 gtk_entry_get_icon_storage_type (entry,
2170 GTK_ENTRY_ICON_PRIMARY));
2173 case PROP_STORAGE_TYPE_SECONDARY:
2174 g_value_set_enum (value,
2175 gtk_entry_get_icon_storage_type (entry,
2176 GTK_ENTRY_ICON_SECONDARY));
2179 case PROP_ACTIVATABLE_PRIMARY:
2180 g_value_set_boolean (value,
2181 gtk_entry_get_icon_activatable (entry, GTK_ENTRY_ICON_PRIMARY));
2184 case PROP_ACTIVATABLE_SECONDARY:
2185 g_value_set_boolean (value,
2186 gtk_entry_get_icon_activatable (entry, GTK_ENTRY_ICON_SECONDARY));
2189 case PROP_SENSITIVE_PRIMARY:
2190 g_value_set_boolean (value,
2191 gtk_entry_get_icon_sensitive (entry, GTK_ENTRY_ICON_PRIMARY));
2194 case PROP_SENSITIVE_SECONDARY:
2195 g_value_set_boolean (value,
2196 gtk_entry_get_icon_sensitive (entry, GTK_ENTRY_ICON_SECONDARY));
2199 case PROP_TOOLTIP_TEXT_PRIMARY:
2200 g_value_take_string (value,
2201 gtk_entry_get_icon_tooltip_text (entry, GTK_ENTRY_ICON_PRIMARY));
2204 case PROP_TOOLTIP_TEXT_SECONDARY:
2205 g_value_take_string (value,
2206 gtk_entry_get_icon_tooltip_text (entry, GTK_ENTRY_ICON_SECONDARY));
2209 case PROP_TOOLTIP_MARKUP_PRIMARY:
2210 g_value_take_string (value,
2211 gtk_entry_get_icon_tooltip_markup (entry, GTK_ENTRY_ICON_PRIMARY));
2214 case PROP_TOOLTIP_MARKUP_SECONDARY:
2215 g_value_take_string (value,
2216 gtk_entry_get_icon_tooltip_markup (entry, GTK_ENTRY_ICON_SECONDARY));
2219 case PROP_EDITING_CANCELED:
2220 g_value_set_boolean (value,
2221 entry->editing_canceled);
2225 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2231 find_invisible_char (GtkWidget *widget)
2233 PangoLayout *layout;
2234 PangoAttrList *attr_list;
2236 gunichar invisible_chars [] = {
2238 0x25cf, /* BLACK CIRCLE */
2239 0x2022, /* BULLET */
2240 0x2731, /* HEAVY ASTERISK */
2241 0x273a /* SIXTEEN POINTED ASTERISK */
2244 if (gtk_widget_get_style (widget))
2245 gtk_widget_style_get (widget,
2246 "invisible-char", &invisible_chars[0],
2249 layout = gtk_widget_create_pango_layout (widget, NULL);
2251 attr_list = pango_attr_list_new ();
2252 pango_attr_list_insert (attr_list, pango_attr_fallback_new (FALSE));
2254 pango_layout_set_attributes (layout, attr_list);
2255 pango_attr_list_unref (attr_list);
2257 for (i = (invisible_chars[0] != 0 ? 0 : 1); i < G_N_ELEMENTS (invisible_chars); i++)
2259 gchar text[7] = { 0, };
2262 len = g_unichar_to_utf8 (invisible_chars[i], text);
2263 pango_layout_set_text (layout, text, len);
2265 count = pango_layout_get_unknown_glyphs_count (layout);
2269 g_object_unref (layout);
2270 return invisible_chars[i];
2274 g_object_unref (layout);
2280 gtk_entry_init (GtkEntry *entry)
2282 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2284 gtk_widget_set_can_focus (GTK_WIDGET (entry), TRUE);
2286 entry->editable = TRUE;
2287 entry->visible = TRUE;
2288 entry->invisible_char = find_invisible_char (GTK_WIDGET (entry));
2289 entry->dnd_position = -1;
2290 entry->width_chars = -1;
2291 entry->is_cell_renderer = FALSE;
2292 entry->editing_canceled = FALSE;
2293 entry->has_frame = TRUE;
2294 entry->truncate_multiline = FALSE;
2295 priv->shadow_type = GTK_SHADOW_IN;
2297 priv->caps_lock_warning = TRUE;
2298 priv->caps_lock_warning_shown = FALSE;
2299 priv->progress_fraction = 0.0;
2300 priv->progress_pulse_fraction = 0.1;
2302 gtk_drag_dest_set (GTK_WIDGET (entry),
2303 GTK_DEST_DEFAULT_HIGHLIGHT,
2305 GDK_ACTION_COPY | GDK_ACTION_MOVE);
2306 gtk_drag_dest_add_text_targets (GTK_WIDGET (entry));
2308 /* This object is completely private. No external entity can gain a reference
2309 * to it; so we create it here and destroy it in finalize().
2311 entry->im_context = gtk_im_multicontext_new ();
2313 g_signal_connect (entry->im_context, "commit",
2314 G_CALLBACK (gtk_entry_commit_cb), entry);
2315 g_signal_connect (entry->im_context, "preedit-changed",
2316 G_CALLBACK (gtk_entry_preedit_changed_cb), entry);
2317 g_signal_connect (entry->im_context, "retrieve-surrounding",
2318 G_CALLBACK (gtk_entry_retrieve_surrounding_cb), entry);
2319 g_signal_connect (entry->im_context, "delete-surrounding",
2320 G_CALLBACK (gtk_entry_delete_surrounding_cb), entry);
2325 get_icon_width (GtkEntry *entry,
2326 GtkEntryIconPosition icon_pos)
2328 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2329 EntryIconInfo *icon_info = priv->icons[icon_pos];
2331 GtkSettings *settings;
2332 gint menu_icon_width;
2334 if (!icon_info || icon_info->pixbuf == NULL)
2337 screen = gtk_widget_get_screen (GTK_WIDGET (entry));
2338 settings = gtk_settings_get_for_screen (screen);
2340 gtk_icon_size_lookup_for_settings (settings, GTK_ICON_SIZE_MENU,
2341 &menu_icon_width, NULL);
2343 return MAX (gdk_pixbuf_get_width (icon_info->pixbuf), menu_icon_width);
2347 get_icon_allocations (GtkEntry *entry,
2348 GtkAllocation *primary,
2349 GtkAllocation *secondary)
2352 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2353 gint x, y, width, height;
2355 get_text_area_size (entry, &x, &y, &width, &height);
2357 if (gtk_widget_has_focus (GTK_WIDGET (entry)) && !priv->interior_focus)
2358 y += priv->focus_width;
2361 primary->height = height;
2362 primary->width = get_icon_width (entry, GTK_ENTRY_ICON_PRIMARY);
2363 if (primary->width > 0)
2364 primary->width += 2 * priv->icon_margin;
2367 secondary->height = height;
2368 secondary->width = get_icon_width (entry, GTK_ENTRY_ICON_SECONDARY);
2369 if (secondary->width > 0)
2370 secondary->width += 2 * priv->icon_margin;
2372 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
2374 primary->x = x + width - primary->width;
2380 secondary->x = x + width - secondary->width;
2386 begin_change (GtkEntry *entry)
2388 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2390 priv->change_count++;
2394 end_change (GtkEntry *entry)
2396 GtkEditable *editable = GTK_EDITABLE (entry);
2397 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2399 g_return_if_fail (priv->change_count > 0);
2401 priv->change_count--;
2403 if (priv->change_count == 0)
2405 if (priv->real_changed)
2407 g_signal_emit_by_name (editable, "changed");
2408 priv->real_changed = FALSE;
2414 emit_changed (GtkEntry *entry)
2416 GtkEditable *editable = GTK_EDITABLE (entry);
2417 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2419 if (priv->change_count == 0)
2420 g_signal_emit_by_name (editable, "changed");
2422 priv->real_changed = TRUE;
2426 gtk_entry_destroy (GtkObject *object)
2428 GtkEntry *entry = GTK_ENTRY (object);
2430 entry->current_pos = entry->selection_bound = 0;
2431 _gtk_entry_reset_im_context (entry);
2432 gtk_entry_reset_layout (entry);
2434 if (entry->blink_timeout)
2436 g_source_remove (entry->blink_timeout);
2437 entry->blink_timeout = 0;
2440 if (entry->recompute_idle)
2442 g_source_remove (entry->recompute_idle);
2443 entry->recompute_idle = 0;
2446 GTK_OBJECT_CLASS (gtk_entry_parent_class)->destroy (object);
2450 gtk_entry_dispose (GObject *object)
2452 GtkEntry *entry = GTK_ENTRY (object);
2453 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2455 gtk_entry_set_icon_from_pixbuf (entry, GTK_ENTRY_ICON_PRIMARY, NULL);
2456 gtk_entry_set_icon_tooltip_markup (entry, GTK_ENTRY_ICON_PRIMARY, NULL);
2457 gtk_entry_set_icon_from_pixbuf (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
2458 gtk_entry_set_icon_tooltip_markup (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
2462 buffer_disconnect_signals (entry);
2463 g_object_unref (priv->buffer);
2464 priv->buffer = NULL;
2467 G_OBJECT_CLASS (gtk_entry_parent_class)->dispose (object);
2471 gtk_entry_finalize (GObject *object)
2473 GtkEntry *entry = GTK_ENTRY (object);
2474 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2475 EntryIconInfo *icon_info = NULL;
2478 for (i = 0; i < MAX_ICONS; i++)
2480 if ((icon_info = priv->icons[i]) != NULL)
2482 if (icon_info->target_list != NULL)
2484 gtk_target_list_unref (icon_info->target_list);
2485 icon_info->target_list = NULL;
2488 g_slice_free (EntryIconInfo, icon_info);
2489 priv->icons[i] = NULL;
2493 gtk_entry_set_completion (entry, NULL);
2495 if (entry->cached_layout)
2496 g_object_unref (entry->cached_layout);
2498 g_object_unref (entry->im_context);
2500 if (entry->blink_timeout)
2501 g_source_remove (entry->blink_timeout);
2503 if (entry->recompute_idle)
2504 g_source_remove (entry->recompute_idle);
2506 g_free (priv->im_module);
2508 G_OBJECT_CLASS (gtk_entry_parent_class)->finalize (object);
2512 gtk_entry_get_display_mode (GtkEntry *entry)
2514 GtkEntryPrivate *priv;
2516 return DISPLAY_NORMAL;
2517 priv = GTK_ENTRY_GET_PRIVATE (entry);
2518 if (entry->invisible_char == 0 && priv->invisible_char_set)
2519 return DISPLAY_BLANK;
2520 return DISPLAY_INVISIBLE;
2524 gtk_entry_get_display_text (GtkEntry *entry,
2528 GtkEntryPasswordHint *password_hint;
2529 GtkEntryPrivate *priv;
2530 gunichar invisible_char;
2540 priv = GTK_ENTRY_GET_PRIVATE (entry);
2541 text = gtk_entry_buffer_get_text (get_buffer (entry));
2542 length = gtk_entry_buffer_get_length (get_buffer (entry));
2546 if (start_pos > length)
2549 if (end_pos <= start_pos)
2550 return g_strdup ("");
2551 else if (entry->visible)
2553 start = g_utf8_offset_to_pointer (text, start_pos);
2554 end = g_utf8_offset_to_pointer (start, end_pos - start_pos);
2555 return g_strndup (start, end - start);
2559 str = g_string_sized_new (length * 2);
2561 /* Figure out what our invisible char is and encode it */
2562 if (!entry->invisible_char)
2563 invisible_char = priv->invisible_char_set ? ' ' : '*';
2565 invisible_char = entry->invisible_char;
2566 char_len = g_unichar_to_utf8 (invisible_char, char_str);
2569 * Add hidden characters for each character in the text
2570 * buffer. If there is a password hint, then keep that
2571 * character visible.
2574 password_hint = g_object_get_qdata (G_OBJECT (entry), quark_password_hint);
2575 for (i = start_pos; i < end_pos; ++i)
2577 if (password_hint && i == password_hint->position)
2579 start = g_utf8_offset_to_pointer (text, i);
2580 g_string_append_len (str, start, g_utf8_next_char (start) - start);
2584 g_string_append_len (str, char_str, char_len);
2588 return g_string_free (str, FALSE);
2594 update_cursors (GtkWidget *widget)
2596 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2597 EntryIconInfo *icon_info = NULL;
2598 GdkDisplay *display;
2602 for (i = 0; i < MAX_ICONS; i++)
2604 if ((icon_info = priv->icons[i]) != NULL)
2606 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
2607 gdk_window_show_unraised (icon_info->window);
2609 /* The icon windows are not children of the visible entry window,
2610 * thus we can't just inherit the xterm cursor. Slight complication
2611 * here is that for the entry, insensitive => arrow cursor, but for
2612 * an icon in a sensitive entry, insensitive => xterm cursor.
2614 if (gtk_widget_is_sensitive (widget) &&
2615 (icon_info->insensitive ||
2616 (icon_info->nonactivatable && icon_info->target_list == NULL)))
2618 display = gtk_widget_get_display (widget);
2619 cursor = gdk_cursor_new_for_display (display, GDK_XTERM);
2620 gdk_window_set_cursor (icon_info->window, cursor);
2621 gdk_cursor_unref (cursor);
2625 gdk_window_set_cursor (icon_info->window, NULL);
2632 realize_icon_info (GtkWidget *widget,
2633 GtkEntryIconPosition icon_pos)
2635 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2636 EntryIconInfo *icon_info = priv->icons[icon_pos];
2637 GdkWindowAttr attributes;
2638 gint attributes_mask;
2640 g_return_if_fail (icon_info != NULL);
2644 attributes.width = 1;
2645 attributes.height = 1;
2646 attributes.window_type = GDK_WINDOW_CHILD;
2647 attributes.wclass = GDK_INPUT_OUTPUT;
2648 attributes.visual = gtk_widget_get_visual (widget);
2649 attributes.colormap = gtk_widget_get_colormap (widget);
2650 attributes.event_mask = gtk_widget_get_events (widget);
2651 attributes.event_mask |= (GDK_EXPOSURE_MASK |
2652 GDK_BUTTON_PRESS_MASK |
2653 GDK_BUTTON_RELEASE_MASK |
2654 GDK_BUTTON1_MOTION_MASK |
2655 GDK_BUTTON3_MOTION_MASK |
2656 GDK_POINTER_MOTION_HINT_MASK |
2657 GDK_POINTER_MOTION_MASK |
2658 GDK_ENTER_NOTIFY_MASK |
2659 GDK_LEAVE_NOTIFY_MASK);
2660 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
2662 icon_info->window = gdk_window_new (gtk_widget_get_window (widget),
2665 gdk_window_set_user_data (icon_info->window, widget);
2666 gdk_window_set_background (icon_info->window,
2667 >k_widget_get_style (widget)->base[gtk_widget_get_state (widget)]);
2669 gtk_widget_queue_resize (widget);
2672 static EntryIconInfo*
2673 construct_icon_info (GtkWidget *widget,
2674 GtkEntryIconPosition icon_pos)
2676 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2677 EntryIconInfo *icon_info;
2679 g_return_val_if_fail (priv->icons[icon_pos] == NULL, NULL);
2681 icon_info = g_slice_new0 (EntryIconInfo);
2682 priv->icons[icon_pos] = icon_info;
2684 if (gtk_widget_get_realized (widget))
2685 realize_icon_info (widget, icon_pos);
2691 gtk_entry_map (GtkWidget *widget)
2693 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2694 EntryIconInfo *icon_info = NULL;
2697 GTK_WIDGET_CLASS (gtk_entry_parent_class)->map (widget);
2699 for (i = 0; i < MAX_ICONS; i++)
2701 if ((icon_info = priv->icons[i]) != NULL)
2703 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
2704 gdk_window_show (icon_info->window);
2708 update_cursors (widget);
2712 gtk_entry_unmap (GtkWidget *widget)
2714 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2715 EntryIconInfo *icon_info = NULL;
2718 for (i = 0; i < MAX_ICONS; i++)
2720 if ((icon_info = priv->icons[i]) != NULL)
2722 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
2723 gdk_window_hide (icon_info->window);
2727 GTK_WIDGET_CLASS (gtk_entry_parent_class)->unmap (widget);
2731 gtk_entry_realize (GtkWidget *widget)
2734 GtkEntryPrivate *priv;
2737 EntryIconInfo *icon_info;
2739 GdkWindowAttr attributes;
2740 gint attributes_mask;
2743 gtk_widget_set_realized (widget, TRUE);
2744 entry = GTK_ENTRY (widget);
2745 priv = GTK_ENTRY_GET_PRIVATE (entry);
2747 attributes.window_type = GDK_WINDOW_CHILD;
2749 get_widget_window_size (entry, &attributes.x, &attributes.y, &attributes.width, &attributes.height);
2751 attributes.wclass = GDK_INPUT_OUTPUT;
2752 attributes.visual = gtk_widget_get_visual (widget);
2753 attributes.colormap = gtk_widget_get_colormap (widget);
2754 attributes.event_mask = gtk_widget_get_events (widget);
2755 attributes.event_mask |= (GDK_EXPOSURE_MASK |
2756 GDK_BUTTON_PRESS_MASK |
2757 GDK_BUTTON_RELEASE_MASK |
2758 GDK_BUTTON1_MOTION_MASK |
2759 GDK_BUTTON3_MOTION_MASK |
2760 GDK_POINTER_MOTION_HINT_MASK |
2761 GDK_POINTER_MOTION_MASK |
2762 GDK_ENTER_NOTIFY_MASK |
2763 GDK_LEAVE_NOTIFY_MASK);
2764 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
2766 window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, attributes_mask);
2767 gtk_widget_set_window (widget, window);
2768 gdk_window_set_user_data (window, entry);
2770 get_text_area_size (entry, &attributes.x, &attributes.y, &attributes.width, &attributes.height);
2772 if (gtk_widget_is_sensitive (widget))
2774 attributes.cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
2775 attributes_mask |= GDK_WA_CURSOR;
2778 entry->text_area = gdk_window_new (window, &attributes, attributes_mask);
2780 gdk_window_set_user_data (entry->text_area, entry);
2782 if (attributes_mask & GDK_WA_CURSOR)
2783 gdk_cursor_unref (attributes.cursor);
2785 gtk_widget_style_attach (widget);
2787 style = gtk_widget_get_style (widget);
2788 state = gtk_widget_get_state (widget);
2789 gdk_window_set_background (window, &style->base[state]);
2790 gdk_window_set_background (entry->text_area, &style->base[state]);
2792 gdk_window_show (entry->text_area);
2794 gtk_im_context_set_client_window (entry->im_context, entry->text_area);
2796 gtk_entry_adjust_scroll (entry);
2797 gtk_entry_update_primary_selection (entry);
2800 /* If the icon positions are already setup, create their windows.
2801 * Otherwise if they don't exist yet, then construct_icon_info()
2802 * will create the windows once the widget is already realized.
2804 for (i = 0; i < MAX_ICONS; i++)
2806 if ((icon_info = priv->icons[i]) != NULL)
2808 if (icon_info->window == NULL)
2809 realize_icon_info (widget, i);
2815 gtk_entry_unrealize (GtkWidget *widget)
2817 GtkEntry *entry = GTK_ENTRY (widget);
2818 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2819 GtkClipboard *clipboard;
2820 EntryIconInfo *icon_info;
2823 gtk_entry_reset_layout (entry);
2825 gtk_im_context_set_client_window (entry->im_context, NULL);
2827 clipboard = gtk_widget_get_clipboard (widget, GDK_SELECTION_PRIMARY);
2828 if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (entry))
2829 gtk_clipboard_clear (clipboard);
2831 if (entry->text_area)
2833 gdk_window_set_user_data (entry->text_area, NULL);
2834 gdk_window_destroy (entry->text_area);
2835 entry->text_area = NULL;
2838 if (entry->popup_menu)
2840 gtk_widget_destroy (entry->popup_menu);
2841 entry->popup_menu = NULL;
2844 GTK_WIDGET_CLASS (gtk_entry_parent_class)->unrealize (widget);
2846 for (i = 0; i < MAX_ICONS; i++)
2848 if ((icon_info = priv->icons[i]) != NULL)
2850 if (icon_info->window != NULL)
2852 gdk_window_destroy (icon_info->window);
2853 icon_info->window = NULL;
2860 _gtk_entry_get_borders (GtkEntry *entry,
2864 GtkWidget *widget = GTK_WIDGET (entry);
2865 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2868 if (entry->has_frame)
2870 style = gtk_widget_get_style (widget);
2872 *xborder = style->xthickness;
2873 *yborder = style->ythickness;
2881 if (!priv->interior_focus)
2883 *xborder += priv->focus_width;
2884 *yborder += priv->focus_width;
2889 gtk_entry_size_request (GtkWidget *widget,
2890 GtkRequisition *requisition)
2892 GtkEntry *entry = GTK_ENTRY (widget);
2893 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2894 PangoFontMetrics *metrics;
2895 gint xborder, yborder;
2896 GtkBorder inner_border;
2897 PangoContext *context;
2898 int icon_widths = 0;
2901 gtk_widget_ensure_style (widget);
2902 context = gtk_widget_get_pango_context (widget);
2903 metrics = pango_context_get_metrics (context,
2904 gtk_widget_get_style (widget)->font_desc,
2905 pango_context_get_language (context));
2907 entry->ascent = pango_font_metrics_get_ascent (metrics);
2908 entry->descent = pango_font_metrics_get_descent (metrics);
2910 _gtk_entry_get_borders (entry, &xborder, &yborder);
2911 _gtk_entry_effective_inner_border (entry, &inner_border);
2913 if (entry->width_chars < 0)
2914 requisition->width = MIN_ENTRY_WIDTH + xborder * 2 + inner_border.left + inner_border.right;
2917 gint char_width = pango_font_metrics_get_approximate_char_width (metrics);
2918 gint digit_width = pango_font_metrics_get_approximate_digit_width (metrics);
2919 gint char_pixels = (MAX (char_width, digit_width) + PANGO_SCALE - 1) / PANGO_SCALE;
2921 requisition->width = char_pixels * entry->width_chars + xborder * 2 + inner_border.left + inner_border.right;
2924 requisition->height = PANGO_PIXELS (entry->ascent + entry->descent) + yborder * 2 + inner_border.top + inner_border.bottom;
2926 for (i = 0; i < MAX_ICONS; i++)
2928 icon_width = get_icon_width (entry, i);
2930 icon_widths += icon_width + 2 * priv->icon_margin;
2933 if (icon_widths > requisition->width)
2934 requisition->width += icon_widths;
2936 pango_font_metrics_unref (metrics);
2940 place_windows (GtkEntry *entry)
2942 GtkWidget *widget = GTK_WIDGET (entry);
2943 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2944 gint x, y, width, height;
2945 GtkAllocation primary;
2946 GtkAllocation secondary;
2947 EntryIconInfo *icon_info = NULL;
2949 get_text_area_size (entry, &x, &y, &width, &height);
2950 get_icon_allocations (entry, &primary, &secondary);
2952 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
2953 y += priv->focus_width;
2955 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
2956 x += secondary.width;
2959 width -= primary.width + secondary.width;
2961 if ((icon_info = priv->icons[GTK_ENTRY_ICON_PRIMARY]) != NULL)
2962 gdk_window_move_resize (icon_info->window,
2963 primary.x, primary.y,
2964 primary.width, primary.height);
2966 if ((icon_info = priv->icons[GTK_ENTRY_ICON_SECONDARY]) != NULL)
2967 gdk_window_move_resize (icon_info->window,
2968 secondary.x, secondary.y,
2969 secondary.width, secondary.height);
2971 gdk_window_move_resize (entry->text_area, x, y, width, height);
2975 gtk_entry_get_text_area_size (GtkEntry *entry,
2981 GtkWidget *widget = GTK_WIDGET (entry);
2982 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2983 GtkAllocation allocation;
2984 GtkRequisition requisition;
2986 gint xborder, yborder;
2988 gtk_size_request_get_size (GTK_SIZE_REQUEST (widget),
2989 &requisition, NULL);
2990 gtk_widget_get_allocation (widget, &allocation);
2991 _gtk_entry_get_borders (entry, &xborder, &yborder);
2993 if (gtk_widget_get_realized (widget))
2994 gdk_drawable_get_size (gtk_widget_get_window (widget), NULL, &frame_height);
2996 frame_height = requisition.height;
2998 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
2999 frame_height -= 2 * priv->focus_width;
3005 *y = frame_height / 2 - (requisition.height - yborder * 2) / 2;
3008 *width = allocation.width - xborder * 2;
3011 *height = requisition.height - yborder * 2;
3015 get_text_area_size (GtkEntry *entry,
3021 GtkEntryClass *class;
3023 g_return_if_fail (GTK_IS_ENTRY (entry));
3025 class = GTK_ENTRY_GET_CLASS (entry);
3027 if (class->get_text_area_size)
3028 class->get_text_area_size (entry, x, y, width, height);
3033 get_widget_window_size (GtkEntry *entry,
3039 GtkAllocation allocation;
3040 GtkRequisition requisition;
3041 GtkWidget *widget = GTK_WIDGET (entry);
3043 gtk_size_request_get_size (GTK_SIZE_REQUEST (widget),
3044 &requisition, NULL);
3045 gtk_widget_get_allocation (widget, &allocation);
3052 if (entry->is_cell_renderer)
3055 *y = allocation.y + (allocation.height - requisition.height) / 2;
3059 *width = allocation.width;
3063 if (entry->is_cell_renderer)
3064 *height = allocation.height;
3066 *height = requisition.height;
3071 _gtk_entry_effective_inner_border (GtkEntry *entry,
3074 GtkBorder *tmp_border;
3076 tmp_border = g_object_get_qdata (G_OBJECT (entry), quark_inner_border);
3080 *border = *tmp_border;
3084 gtk_widget_style_get (GTK_WIDGET (entry), "inner-border", &tmp_border, NULL);
3088 *border = *tmp_border;
3089 gtk_border_free (tmp_border);
3093 *border = default_inner_border;
3097 gtk_entry_size_allocate (GtkWidget *widget,
3098 GtkAllocation *allocation)
3100 GtkEntry *entry = GTK_ENTRY (widget);
3102 gtk_widget_set_allocation (widget, allocation);
3104 if (gtk_widget_get_realized (widget))
3106 gint x, y, width, height;
3107 GtkEntryCompletion* completion;
3109 get_widget_window_size (entry, &x, &y, &width, &height);
3110 gdk_window_move_resize (gtk_widget_get_window (widget),
3111 x, y, width, height);
3113 place_windows (entry);
3114 gtk_entry_recompute (entry);
3116 completion = gtk_entry_get_completion (entry);
3117 if (completion && gtk_widget_get_mapped (completion->priv->popup_window))
3118 _gtk_entry_completion_resize_popup (completion);
3122 /* Kudos to the gnome-panel guys. */
3124 colorshift_pixbuf (GdkPixbuf *dest,
3129 gint width, height, has_alpha, src_rowstride, dest_rowstride;
3130 guchar *target_pixels;
3131 guchar *original_pixels;
3137 has_alpha = gdk_pixbuf_get_has_alpha (src);
3138 width = gdk_pixbuf_get_width (src);
3139 height = gdk_pixbuf_get_height (src);
3140 src_rowstride = gdk_pixbuf_get_rowstride (src);
3141 dest_rowstride = gdk_pixbuf_get_rowstride (dest);
3142 original_pixels = gdk_pixbuf_get_pixels (src);
3143 target_pixels = gdk_pixbuf_get_pixels (dest);
3145 for (i = 0; i < height; i++)
3147 pix_dest = target_pixels + i * dest_rowstride;
3148 pix_src = original_pixels + i * src_rowstride;
3150 for (j = 0; j < width; j++)
3157 *(pix_dest++) = CLAMP (val, 0, 255);
3160 *(pix_dest++) = CLAMP (val, 0, 255);
3163 *(pix_dest++) = CLAMP (val, 0, 255);
3166 *(pix_dest++) = *(pix_src++);
3172 should_prelight (GtkEntry *entry,
3173 GtkEntryIconPosition icon_pos)
3175 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3176 EntryIconInfo *icon_info = priv->icons[icon_pos];
3182 if (icon_info->nonactivatable && icon_info->target_list == NULL)
3185 if (icon_info->pressed)
3188 gtk_widget_style_get (GTK_WIDGET (entry),
3189 "icon-prelight", &prelight,
3196 draw_icon (GtkWidget *widget,
3197 GtkEntryIconPosition icon_pos)
3199 GtkEntry *entry = GTK_ENTRY (widget);
3200 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3201 EntryIconInfo *icon_info = priv->icons[icon_pos];
3203 gint x, y, width, height;
3209 gtk_entry_ensure_pixbuf (entry, icon_pos);
3211 if (icon_info->pixbuf == NULL)
3214 gdk_drawable_get_size (icon_info->window, &width, &height);
3216 /* size_allocate hasn't been called yet. These are the default values.
3218 if (width == 1 || height == 1)
3221 pixbuf = icon_info->pixbuf;
3222 g_object_ref (pixbuf);
3224 if (gdk_pixbuf_get_height (pixbuf) > height)
3226 GdkPixbuf *temp_pixbuf;
3229 scale = height - 2 * priv->icon_margin;
3230 temp_pixbuf = gdk_pixbuf_scale_simple (pixbuf, scale, scale,
3231 GDK_INTERP_BILINEAR);
3232 g_object_unref (pixbuf);
3233 pixbuf = temp_pixbuf;
3236 x = (width - gdk_pixbuf_get_width (pixbuf)) / 2;
3237 y = (height - gdk_pixbuf_get_height (pixbuf)) / 2;
3239 if (!gtk_widget_is_sensitive (widget) ||
3240 icon_info->insensitive)
3242 GdkPixbuf *temp_pixbuf;
3244 temp_pixbuf = gdk_pixbuf_copy (pixbuf);
3245 gdk_pixbuf_saturate_and_pixelate (pixbuf,
3249 g_object_unref (pixbuf);
3250 pixbuf = temp_pixbuf;
3252 else if (icon_info->prelight)
3254 GdkPixbuf *temp_pixbuf;
3256 temp_pixbuf = gdk_pixbuf_copy (pixbuf);
3257 colorshift_pixbuf (temp_pixbuf, pixbuf, 30);
3258 g_object_unref (pixbuf);
3259 pixbuf = temp_pixbuf;
3262 cr = gdk_cairo_create (icon_info->window);
3263 gdk_cairo_set_source_pixbuf (cr, pixbuf, x, y);
3267 g_object_unref (pixbuf);
3272 gtk_entry_draw_frame (GtkWidget *widget,
3273 GdkEventExpose *event)
3275 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
3278 gint x = 0, y = 0, width, height;
3281 window = gtk_widget_get_window (widget);
3283 gdk_drawable_get_size (window, &width, &height);
3285 /* Fix a problem with some themes which assume that entry->text_area's
3286 * width equals widget->window's width */
3287 if (GTK_IS_SPIN_BUTTON (widget))
3289 gint xborder, yborder;
3291 gtk_entry_get_text_area_size (GTK_ENTRY (widget), &x, NULL, &width, NULL);
3292 _gtk_entry_get_borders (GTK_ENTRY (widget), &xborder, &yborder);
3295 width += xborder * 2;
3298 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3300 x += priv->focus_width;
3301 y += priv->focus_width;
3302 width -= 2 * priv->focus_width;
3303 height -= 2 * priv->focus_width;
3306 style = gtk_widget_get_style (widget);
3307 state = gtk_widget_has_focus (widget) ?
3308 GTK_STATE_ACTIVE : gtk_widget_get_state (widget);
3310 gtk_paint_shadow (style, window,
3311 state, priv->shadow_type,
3312 &event->area, widget, "entry", x, y, width, height);
3315 gtk_entry_draw_progress (widget, event);
3317 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3319 x -= priv->focus_width;
3320 y -= priv->focus_width;
3321 width += 2 * priv->focus_width;
3322 height += 2 * priv->focus_width;
3324 gtk_paint_focus (style, window,
3325 gtk_widget_get_state (widget),
3326 &event->area, widget, "entry",
3327 0, 0, width, height);
3332 gtk_entry_get_progress_border (GtkWidget *widget,
3333 GtkBorder *progress_border)
3335 GtkBorder *tmp_border;
3338 gtk_widget_style_get (widget, "progress-border", &tmp_border, NULL);
3341 *progress_border = *tmp_border;
3342 gtk_border_free (tmp_border);
3346 style = gtk_widget_get_style (widget);
3348 progress_border->left = style->xthickness;
3349 progress_border->right = style->xthickness;
3350 progress_border->top = style->ythickness;
3351 progress_border->bottom = style->ythickness;
3356 get_progress_area (GtkWidget *widget,
3362 GtkEntryPrivate *private = GTK_ENTRY_GET_PRIVATE (widget);
3363 GtkEntry *entry = GTK_ENTRY (widget);
3364 GtkBorder progress_border;
3366 gtk_entry_get_progress_border (widget, &progress_border);
3368 *x = progress_border.left;
3369 *y = progress_border.top;
3371 gdk_drawable_get_size (gtk_widget_get_window (widget), width, height);
3373 *width -= progress_border.left + progress_border.right;
3374 *height -= progress_border.top + progress_border.bottom;
3376 if (gtk_widget_has_focus (widget) && !private->interior_focus)
3378 *x += private->focus_width;
3379 *y += private->focus_width;
3380 *width -= 2 * private->focus_width;
3381 *height -= 2 * private->focus_width;
3384 if (private->progress_pulse_mode)
3386 gdouble value = private->progress_pulse_current;
3388 *x += (gint) floor(value * (*width));
3389 *width = (gint) ceil(private->progress_pulse_fraction * (*width));
3391 else if (private->progress_fraction > 0)
3393 gdouble value = private->progress_fraction;
3395 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
3399 bar_width = floor(value * (*width) + 0.5);
3400 *x += *width - bar_width;
3405 *width = (gint) floor(value * (*width) + 0.5);
3416 gtk_entry_draw_progress (GtkWidget *widget,
3417 GdkEventExpose *event)
3419 gint x, y, width, height;
3422 get_progress_area (widget, &x, &y, &width, &height);
3424 if ((width <= 0) || (height <= 0))
3427 if (event->window != gtk_widget_get_window (widget))
3431 gdk_window_get_position (event->window, &pos_x, &pos_y);
3437 state = GTK_STATE_SELECTED;
3438 if (!gtk_widget_get_sensitive (widget))
3439 state = GTK_STATE_INSENSITIVE;
3441 gtk_paint_box (gtk_widget_get_style (widget), event->window,
3442 state, GTK_SHADOW_OUT,
3443 &event->area, widget, "entry-progress",
3449 gtk_entry_expose (GtkWidget *widget,
3450 GdkEventExpose *event)
3452 GtkEntry *entry = GTK_ENTRY (widget);
3455 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3457 style = gtk_widget_get_style (widget);
3459 state = gtk_widget_has_focus (widget) ?
3460 GTK_STATE_ACTIVE : gtk_widget_get_state (widget);
3462 if (gtk_widget_get_window (widget) == event->window)
3464 gtk_entry_draw_frame (widget, event);
3466 else if (entry->text_area == event->window)
3470 gdk_drawable_get_size (entry->text_area, &width, &height);
3472 gtk_paint_flat_box (style, entry->text_area,
3473 state, GTK_SHADOW_NONE,
3474 &event->area, widget, "entry_bg",
3475 0, 0, width, height);
3477 gtk_entry_draw_progress (widget, event);
3479 if (entry->dnd_position != -1)
3480 gtk_entry_draw_cursor (GTK_ENTRY (widget), CURSOR_DND);
3482 gtk_entry_draw_text (GTK_ENTRY (widget));
3484 /* When no text is being displayed at all, don't show the cursor */
3485 if (gtk_entry_get_display_mode (entry) != DISPLAY_BLANK &&
3486 gtk_widget_has_focus (widget) &&
3487 entry->selection_bound == entry->current_pos && entry->cursor_visible)
3488 gtk_entry_draw_cursor (GTK_ENTRY (widget), CURSOR_STANDARD);
3494 for (i = 0; i < MAX_ICONS; i++)
3496 EntryIconInfo *icon_info = priv->icons[i];
3498 if (icon_info != NULL && event->window == icon_info->window)
3502 gdk_drawable_get_size (icon_info->window, &width, &height);
3504 gtk_paint_flat_box (style, icon_info->window,
3505 state, GTK_SHADOW_NONE,
3506 NULL, widget, "entry_bg",
3507 0, 0, width, height);
3509 gtk_entry_draw_progress (widget, event);
3510 draw_icon (widget, i);
3521 gtk_entry_enter_notify (GtkWidget *widget,
3522 GdkEventCrossing *event)
3524 GtkEntry *entry = GTK_ENTRY (widget);
3525 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3528 for (i = 0; i < MAX_ICONS; i++)
3530 EntryIconInfo *icon_info = priv->icons[i];
3532 if (icon_info != NULL && event->window == icon_info->window)
3534 if (should_prelight (entry, i))
3536 icon_info->prelight = TRUE;
3537 gtk_widget_queue_draw (widget);
3548 gtk_entry_leave_notify (GtkWidget *widget,
3549 GdkEventCrossing *event)
3551 GtkEntry *entry = GTK_ENTRY (widget);
3552 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3555 for (i = 0; i < MAX_ICONS; i++)
3557 EntryIconInfo *icon_info = priv->icons[i];
3559 if (icon_info != NULL && event->window == icon_info->window)
3561 /* a grab means that we may never see the button release */
3562 if (event->mode == GDK_CROSSING_GRAB || event->mode == GDK_CROSSING_GTK_GRAB)
3563 icon_info->pressed = FALSE;
3565 if (should_prelight (entry, i))
3567 icon_info->prelight = FALSE;
3568 gtk_widget_queue_draw (widget);
3579 gtk_entry_get_pixel_ranges (GtkEntry *entry,
3583 gint start_char, end_char;
3585 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start_char, &end_char))
3587 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
3588 PangoLayoutLine *line = pango_layout_get_lines_readonly (layout)->data;
3589 const char *text = pango_layout_get_text (layout);
3590 gint start_index = g_utf8_offset_to_pointer (text, start_char) - text;
3591 gint end_index = g_utf8_offset_to_pointer (text, end_char) - text;
3592 gint real_n_ranges, i;
3594 pango_layout_line_get_x_ranges (line, start_index, end_index, ranges, &real_n_ranges);
3600 for (i = 0; i < real_n_ranges; ++i)
3602 r[2 * i + 1] = (r[2 * i + 1] - r[2 * i]) / PANGO_SCALE;
3603 r[2 * i] = r[2 * i] / PANGO_SCALE;
3608 *n_ranges = real_n_ranges;
3620 in_selection (GtkEntry *entry,
3625 gint retval = FALSE;
3627 gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
3629 for (i = 0; i < n_ranges; ++i)
3631 if (x >= ranges[2 * i] && x < ranges[2 * i] + ranges[2 * i + 1])
3643 gtk_entry_button_press (GtkWidget *widget,
3644 GdkEventButton *event)
3646 GtkEntry *entry = GTK_ENTRY (widget);
3647 GtkEditable *editable = GTK_EDITABLE (widget);
3648 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3649 EntryIconInfo *icon_info = NULL;
3651 gint sel_start, sel_end;
3654 for (i = 0; i < MAX_ICONS; i++)
3656 icon_info = priv->icons[i];
3658 if (!icon_info || icon_info->insensitive)
3661 if (event->window == icon_info->window)
3663 if (should_prelight (entry, i))
3665 icon_info->prelight = FALSE;
3666 gtk_widget_queue_draw (widget);
3669 priv->start_x = event->x;
3670 priv->start_y = event->y;
3671 icon_info->pressed = TRUE;
3673 if (!icon_info->nonactivatable)
3674 g_signal_emit (entry, signals[ICON_PRESS], 0, i, event);
3680 if (event->window != entry->text_area ||
3681 (entry->button && event->button != entry->button))
3684 gtk_entry_reset_blink_time (entry);
3686 entry->button = event->button;
3688 if (!gtk_widget_has_focus (widget))
3690 entry->in_click = TRUE;
3691 gtk_widget_grab_focus (widget);
3692 entry->in_click = FALSE;
3695 tmp_pos = gtk_entry_find_position (entry, event->x + entry->scroll_offset);
3697 if (event->button == 1)
3699 gboolean have_selection = gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end);
3701 entry->select_words = FALSE;
3702 entry->select_lines = FALSE;
3704 if (event->state & GDK_SHIFT_MASK)
3706 _gtk_entry_reset_im_context (entry);
3708 if (!have_selection) /* select from the current position to the clicked position */
3709 sel_start = sel_end = entry->current_pos;
3711 if (tmp_pos > sel_start && tmp_pos < sel_end)
3713 /* Truncate current selection, but keep it as big as possible */
3714 if (tmp_pos - sel_start > sel_end - tmp_pos)
3715 gtk_entry_set_positions (entry, sel_start, tmp_pos);
3717 gtk_entry_set_positions (entry, tmp_pos, sel_end);
3721 gboolean extend_to_left;
3724 /* Figure out what click selects and extend current selection */
3725 switch (event->type)
3727 case GDK_BUTTON_PRESS:
3728 gtk_entry_set_positions (entry, tmp_pos, tmp_pos);
3731 case GDK_2BUTTON_PRESS:
3732 entry->select_words = TRUE;
3733 gtk_entry_select_word (entry);
3736 case GDK_3BUTTON_PRESS:
3737 entry->select_lines = TRUE;
3738 gtk_entry_select_line (entry);
3745 start = MIN (entry->current_pos, entry->selection_bound);
3746 start = MIN (sel_start, start);
3748 end = MAX (entry->current_pos, entry->selection_bound);
3749 end = MAX (sel_end, end);
3751 if (tmp_pos == sel_start || tmp_pos == sel_end)
3752 extend_to_left = (tmp_pos == start);
3754 extend_to_left = (end == sel_end);
3757 gtk_entry_set_positions (entry, start, end);
3759 gtk_entry_set_positions (entry, end, start);
3762 else /* no shift key */
3763 switch (event->type)
3765 case GDK_BUTTON_PRESS:
3766 if (in_selection (entry, event->x + entry->scroll_offset))
3768 /* Click inside the selection - we'll either start a drag, or
3769 * clear the selection
3771 entry->in_drag = TRUE;
3772 entry->drag_start_x = event->x + entry->scroll_offset;
3773 entry->drag_start_y = event->y;
3776 gtk_editable_set_position (editable, tmp_pos);
3779 case GDK_2BUTTON_PRESS:
3780 /* We ALWAYS receive a GDK_BUTTON_PRESS immediately before
3781 * receiving a GDK_2BUTTON_PRESS so we need to reset
3782 * entry->in_drag which may have been set above
3784 entry->in_drag = FALSE;
3785 entry->select_words = TRUE;
3786 gtk_entry_select_word (entry);
3789 case GDK_3BUTTON_PRESS:
3790 /* We ALWAYS receive a GDK_BUTTON_PRESS immediately before
3791 * receiving a GDK_3BUTTON_PRESS so we need to reset
3792 * entry->in_drag which may have been set above
3794 entry->in_drag = FALSE;
3795 entry->select_lines = TRUE;
3796 gtk_entry_select_line (entry);
3805 else if (event->button == 2 && event->type == GDK_BUTTON_PRESS)
3807 if (entry->editable)
3809 priv->insert_pos = tmp_pos;
3810 gtk_entry_paste (entry, GDK_SELECTION_PRIMARY);
3815 gtk_widget_error_bell (widget);
3818 else if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
3820 gtk_entry_do_popup (entry, event);
3821 entry->button = 0; /* Don't wait for release, since the menu will gtk_grab_add */
3830 gtk_entry_button_release (GtkWidget *widget,
3831 GdkEventButton *event)
3833 GtkEntry *entry = GTK_ENTRY (widget);
3834 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
3835 EntryIconInfo *icon_info = NULL;
3838 for (i = 0; i < MAX_ICONS; i++)
3840 icon_info = priv->icons[i];
3842 if (!icon_info || icon_info->insensitive)
3845 if (event->window == icon_info->window)
3849 gdk_drawable_get_size (icon_info->window, &width, &height);
3851 icon_info->pressed = FALSE;
3853 if (should_prelight (entry, i) &&
3854 event->x >= 0 && event->y >= 0 &&
3855 event->x < width && event->y < height)
3857 icon_info->prelight = TRUE;
3858 gtk_widget_queue_draw (widget);
3861 if (!icon_info->nonactivatable)
3862 g_signal_emit (entry, signals[ICON_RELEASE], 0, i, event);
3868 if (event->window != entry->text_area || entry->button != event->button)
3873 gint tmp_pos = gtk_entry_find_position (entry, entry->drag_start_x);
3875 gtk_editable_set_position (GTK_EDITABLE (entry), tmp_pos);
3882 gtk_entry_update_primary_selection (entry);
3888 _gtk_entry_get_selected_text (GtkEntry *entry)
3890 GtkEditable *editable = GTK_EDITABLE (entry);
3891 gint start_text, end_text;
3894 if (gtk_editable_get_selection_bounds (editable, &start_text, &end_text))
3895 text = gtk_editable_get_chars (editable, start_text, end_text);
3901 gtk_entry_motion_notify (GtkWidget *widget,
3902 GdkEventMotion *event)
3904 GtkEntry *entry = GTK_ENTRY (widget);
3905 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3906 EntryIconInfo *icon_info = NULL;
3907 GdkDragContext *context;
3911 for (i = 0; i < MAX_ICONS; i++)
3913 icon_info = priv->icons[i];
3915 if (!icon_info || icon_info->insensitive)
3918 if (event->window == icon_info->window)
3920 if (icon_info->pressed &&
3921 icon_info->target_list != NULL &&
3922 gtk_drag_check_threshold (widget,
3928 icon_info->in_drag = TRUE;
3929 icon_info->pressed = FALSE;
3930 context = gtk_drag_begin (widget,
3931 icon_info->target_list,
3941 if (entry->mouse_cursor_obscured)
3945 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
3946 gdk_window_set_cursor (entry->text_area, cursor);
3947 gdk_cursor_unref (cursor);
3948 entry->mouse_cursor_obscured = FALSE;
3951 if (event->window != entry->text_area || entry->button != 1)
3954 if (entry->select_lines)
3957 gdk_event_request_motions (event);
3961 if (gtk_entry_get_display_mode (entry) == DISPLAY_NORMAL &&
3962 gtk_drag_check_threshold (widget,
3963 entry->drag_start_x, entry->drag_start_y,
3964 event->x + entry->scroll_offset, event->y))
3966 GdkDragContext *context;
3967 GtkTargetList *target_list = gtk_target_list_new (NULL, 0);
3968 guint actions = entry->editable ? GDK_ACTION_COPY | GDK_ACTION_MOVE : GDK_ACTION_COPY;
3970 GdkPixmap *pixmap = NULL;
3972 gtk_target_list_add_text_targets (target_list, 0);
3974 text = _gtk_entry_get_selected_text (entry);
3975 pixmap = _gtk_text_util_create_drag_icon (widget, text, -1);
3977 context = gtk_drag_begin (widget, target_list, actions,
3978 entry->button, (GdkEvent *)event);
3981 gtk_drag_set_icon_pixmap (context,
3982 gdk_drawable_get_colormap (pixmap),
3987 gtk_drag_set_icon_default (context);
3990 g_object_unref (pixmap);
3993 entry->in_drag = FALSE;
3996 gtk_target_list_unref (target_list);
4002 gdk_drawable_get_size (entry->text_area, NULL, &height);
4006 else if (event->y >= height)
4007 tmp_pos = gtk_entry_buffer_get_length (get_buffer (entry));
4009 tmp_pos = gtk_entry_find_position (entry, event->x + entry->scroll_offset);
4011 if (entry->select_words)
4014 gint old_min, old_max;
4017 min = gtk_entry_move_backward_word (entry, tmp_pos, TRUE);
4018 max = gtk_entry_move_forward_word (entry, tmp_pos, TRUE);
4020 pos = entry->current_pos;
4021 bound = entry->selection_bound;
4023 old_min = MIN(entry->current_pos, entry->selection_bound);
4024 old_max = MAX(entry->current_pos, entry->selection_bound);
4031 else if (old_max < max)
4036 else if (pos == old_min)
4038 if (entry->current_pos != min)
4043 if (entry->current_pos != max)
4047 gtk_entry_set_positions (entry, pos, bound);
4050 gtk_entry_set_positions (entry, tmp_pos, -1);
4057 set_invisible_cursor (GdkWindow *window)
4059 GdkDisplay *display;
4062 display = gdk_drawable_get_display (window);
4063 cursor = gdk_cursor_new_for_display (display, GDK_BLANK_CURSOR);
4065 gdk_window_set_cursor (window, cursor);
4067 gdk_cursor_unref (cursor);
4071 gtk_entry_obscure_mouse_cursor (GtkEntry *entry)
4073 if (entry->mouse_cursor_obscured)
4076 set_invisible_cursor (entry->text_area);
4078 entry->mouse_cursor_obscured = TRUE;
4082 gtk_entry_key_press (GtkWidget *widget,
4085 GtkEntry *entry = GTK_ENTRY (widget);
4087 gtk_entry_reset_blink_time (entry);
4088 gtk_entry_pend_cursor_blink (entry);
4090 if (entry->editable)
4092 if (gtk_im_context_filter_keypress (entry->im_context, event))
4094 gtk_entry_obscure_mouse_cursor (entry);
4095 entry->need_im_reset = TRUE;
4100 if (event->keyval == GDK_KEY_Return ||
4101 event->keyval == GDK_KEY_KP_Enter ||
4102 event->keyval == GDK_KEY_ISO_Enter ||
4103 event->keyval == GDK_KEY_Escape)
4105 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
4107 if (completion && completion->priv->completion_timeout)
4109 g_source_remove (completion->priv->completion_timeout);
4110 completion->priv->completion_timeout = 0;
4113 _gtk_entry_reset_im_context (entry);
4116 if (GTK_WIDGET_CLASS (gtk_entry_parent_class)->key_press_event (widget, event))
4117 /* Activate key bindings
4121 if (!entry->editable && event->length)
4122 gtk_widget_error_bell (widget);
4128 gtk_entry_key_release (GtkWidget *widget,
4131 GtkEntry *entry = GTK_ENTRY (widget);
4133 if (entry->editable)
4135 if (gtk_im_context_filter_keypress (entry->im_context, event))
4137 entry->need_im_reset = TRUE;
4142 return GTK_WIDGET_CLASS (gtk_entry_parent_class)->key_release_event (widget, event);
4146 gtk_entry_focus_in (GtkWidget *widget,
4147 GdkEventFocus *event)
4149 GtkEntry *entry = GTK_ENTRY (widget);
4152 gtk_widget_queue_draw (widget);
4154 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (widget));
4156 if (entry->editable)
4158 entry->need_im_reset = TRUE;
4159 gtk_im_context_focus_in (entry->im_context);
4160 keymap_state_changed (keymap, entry);
4161 g_signal_connect (keymap, "state-changed",
4162 G_CALLBACK (keymap_state_changed), entry);
4165 g_signal_connect (keymap, "direction-changed",
4166 G_CALLBACK (keymap_direction_changed), entry);
4168 gtk_entry_reset_blink_time (entry);
4169 gtk_entry_check_cursor_blink (entry);
4175 gtk_entry_focus_out (GtkWidget *widget,
4176 GdkEventFocus *event)
4178 GtkEntry *entry = GTK_ENTRY (widget);
4179 GtkEntryCompletion *completion;
4182 gtk_widget_queue_draw (widget);
4184 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (widget));
4186 if (entry->editable)
4188 entry->need_im_reset = TRUE;
4189 gtk_im_context_focus_out (entry->im_context);
4190 remove_capslock_feedback (entry);
4193 gtk_entry_check_cursor_blink (entry);
4195 g_signal_handlers_disconnect_by_func (keymap, keymap_state_changed, entry);
4196 g_signal_handlers_disconnect_by_func (keymap, keymap_direction_changed, entry);
4198 completion = gtk_entry_get_completion (entry);
4200 _gtk_entry_completion_popdown (completion);
4206 gtk_entry_grab_focus (GtkWidget *widget)
4208 GtkEntry *entry = GTK_ENTRY (widget);
4209 gboolean select_on_focus;
4211 GTK_WIDGET_CLASS (gtk_entry_parent_class)->grab_focus (widget);
4213 if (entry->editable && !entry->in_click)
4215 g_object_get (gtk_widget_get_settings (widget),
4216 "gtk-entry-select-on-focus",
4220 if (select_on_focus)
4221 gtk_editable_select_region (GTK_EDITABLE (widget), 0, -1);
4226 gtk_entry_direction_changed (GtkWidget *widget,
4227 GtkTextDirection previous_dir)
4229 GtkEntry *entry = GTK_ENTRY (widget);
4231 gtk_entry_recompute (entry);
4233 GTK_WIDGET_CLASS (gtk_entry_parent_class)->direction_changed (widget, previous_dir);
4237 gtk_entry_state_changed (GtkWidget *widget,
4238 GtkStateType previous_state)
4240 GtkEntry *entry = GTK_ENTRY (widget);
4241 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
4245 if (gtk_widget_get_realized (widget))
4250 style = gtk_widget_get_style (widget);
4251 state = gtk_widget_get_state (widget);
4253 gdk_window_set_background (gtk_widget_get_window (widget),
4254 &style->base[state]);
4255 gdk_window_set_background (entry->text_area,
4256 &style->base[state]);
4257 for (i = 0; i < MAX_ICONS; i++)
4259 EntryIconInfo *icon_info = priv->icons[i];
4260 if (icon_info && icon_info->window)
4261 gdk_window_set_background (icon_info->window,
4262 &style->base[state]);
4265 if (gtk_widget_is_sensitive (widget))
4266 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
4270 gdk_window_set_cursor (entry->text_area, cursor);
4273 gdk_cursor_unref (cursor);
4275 entry->mouse_cursor_obscured = FALSE;
4277 update_cursors (widget);
4280 if (!gtk_widget_is_sensitive (widget))
4282 /* Clear any selection */
4283 gtk_editable_select_region (GTK_EDITABLE (entry), entry->current_pos, entry->current_pos);
4286 gtk_widget_queue_draw (widget);
4290 gtk_entry_screen_changed (GtkWidget *widget,
4291 GdkScreen *old_screen)
4293 gtk_entry_recompute (GTK_ENTRY (widget));
4296 /* GtkEditable method implementations
4299 gtk_entry_insert_text (GtkEditable *editable,
4300 const gchar *new_text,
4301 gint new_text_length,
4304 g_object_ref (editable);
4307 * The incoming text may a password or other secret. We make sure
4308 * not to copy it into temporary buffers.
4311 g_signal_emit_by_name (editable, "insert-text", new_text, new_text_length, position);
4313 g_object_unref (editable);
4317 gtk_entry_delete_text (GtkEditable *editable,
4321 g_object_ref (editable);
4323 g_signal_emit_by_name (editable, "delete-text", start_pos, end_pos);
4325 g_object_unref (editable);
4329 gtk_entry_get_chars (GtkEditable *editable,
4333 GtkEntry *entry = GTK_ENTRY (editable);
4336 gint start_index, end_index;
4338 text = gtk_entry_buffer_get_text (get_buffer (entry));
4339 text_length = gtk_entry_buffer_get_length (get_buffer (entry));
4342 end_pos = text_length;
4344 start_pos = MIN (text_length, start_pos);
4345 end_pos = MIN (text_length, end_pos);
4347 start_index = g_utf8_offset_to_pointer (text, start_pos) - text;
4348 end_index = g_utf8_offset_to_pointer (text, end_pos) - text;
4350 return g_strndup (text + start_index, end_index - start_index);
4354 gtk_entry_real_set_position (GtkEditable *editable,
4357 GtkEntry *entry = GTK_ENTRY (editable);
4361 length = gtk_entry_buffer_get_length (get_buffer (entry));
4362 if (position < 0 || position > length)
4365 if (position != entry->current_pos ||
4366 position != entry->selection_bound)
4368 _gtk_entry_reset_im_context (entry);
4369 gtk_entry_set_positions (entry, position, position);
4374 gtk_entry_get_position (GtkEditable *editable)
4376 return GTK_ENTRY (editable)->current_pos;
4380 gtk_entry_set_selection_bounds (GtkEditable *editable,
4384 GtkEntry *entry = GTK_ENTRY (editable);
4387 length = gtk_entry_buffer_get_length (get_buffer (entry));
4393 _gtk_entry_reset_im_context (entry);
4395 gtk_entry_set_positions (entry,
4397 MIN (start, length));
4399 gtk_entry_update_primary_selection (entry);
4403 gtk_entry_get_selection_bounds (GtkEditable *editable,
4407 GtkEntry *entry = GTK_ENTRY (editable);
4409 *start = entry->selection_bound;
4410 *end = entry->current_pos;
4412 return (entry->selection_bound != entry->current_pos);
4416 icon_theme_changed (GtkEntry *entry)
4418 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
4421 for (i = 0; i < MAX_ICONS; i++)
4423 EntryIconInfo *icon_info = priv->icons[i];
4424 if (icon_info != NULL)
4426 if (icon_info->storage_type == GTK_IMAGE_ICON_NAME)
4427 gtk_entry_set_icon_from_icon_name (entry, i, icon_info->icon_name);
4428 else if (icon_info->storage_type == GTK_IMAGE_STOCK)
4429 gtk_entry_set_icon_from_stock (entry, i, icon_info->stock_id);
4430 else if (icon_info->storage_type == GTK_IMAGE_GICON)
4431 gtk_entry_set_icon_from_gicon (entry, i, icon_info->gicon);
4435 gtk_widget_queue_draw (GTK_WIDGET (entry));
4439 icon_margin_changed (GtkEntry *entry)
4441 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
4444 _gtk_entry_effective_inner_border (GTK_ENTRY (entry), &border);
4446 priv->icon_margin = border.left;
4450 gtk_entry_style_set (GtkWidget *widget,
4451 GtkStyle *previous_style)
4453 GtkEntry *entry = GTK_ENTRY (widget);
4454 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
4456 gboolean interior_focus;
4459 gtk_widget_style_get (widget,
4460 "focus-line-width", &focus_width,
4461 "interior-focus", &interior_focus,
4464 priv->focus_width = focus_width;
4465 priv->interior_focus = interior_focus;
4467 if (!priv->invisible_char_set)
4468 entry->invisible_char = find_invisible_char (GTK_WIDGET (entry));
4470 gtk_entry_recompute (entry);
4472 if (previous_style && gtk_widget_get_realized (widget))
4476 style = gtk_widget_get_style (widget);
4478 gdk_window_set_background (gtk_widget_get_window (widget),
4479 &style->base[gtk_widget_get_state (widget)]);
4480 gdk_window_set_background (entry->text_area,
4481 &style->base[gtk_widget_get_state (widget)]);
4482 for (i = 0; i < MAX_ICONS; i++)
4484 EntryIconInfo *icon_info = priv->icons[i];
4485 if (icon_info && icon_info->window)
4486 gdk_window_set_background (icon_info->window,
4487 &style->base[gtk_widget_get_state (widget)]);
4491 icon_theme_changed (entry);
4492 icon_margin_changed (entry);
4495 /* GtkCellEditable method implementations
4498 gtk_cell_editable_entry_activated (GtkEntry *entry, gpointer data)
4500 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4501 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4505 gtk_cell_editable_key_press_event (GtkEntry *entry,
4506 GdkEventKey *key_event,
4509 if (key_event->keyval == GDK_KEY_Escape)
4511 entry->editing_canceled = TRUE;
4512 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4513 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4518 /* override focus */
4519 if (key_event->keyval == GDK_KEY_Up || key_event->keyval == GDK_KEY_Down)
4521 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4522 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4531 gtk_entry_start_editing (GtkCellEditable *cell_editable,
4534 GTK_ENTRY (cell_editable)->is_cell_renderer = TRUE;
4536 g_signal_connect (cell_editable, "activate",
4537 G_CALLBACK (gtk_cell_editable_entry_activated), NULL);
4538 g_signal_connect (cell_editable, "key-press-event",
4539 G_CALLBACK (gtk_cell_editable_key_press_event), NULL);
4543 gtk_entry_password_hint_free (GtkEntryPasswordHint *password_hint)
4545 if (password_hint->source_id)
4546 g_source_remove (password_hint->source_id);
4548 g_slice_free (GtkEntryPasswordHint, password_hint);
4553 gtk_entry_remove_password_hint (gpointer data)
4555 GtkEntryPasswordHint *password_hint = g_object_get_qdata (data, quark_password_hint);
4556 password_hint->position = -1;
4558 /* Force the string to be redrawn, but now without a visible character */
4559 gtk_entry_recompute (GTK_ENTRY (data));
4563 /* Default signal handlers
4566 gtk_entry_real_insert_text (GtkEditable *editable,
4567 const gchar *new_text,
4568 gint new_text_length,
4574 n_chars = g_utf8_strlen (new_text, new_text_length);
4577 * The actual insertion into the buffer. This will end up firing the
4578 * following signal handlers: buffer_inserted_text(), buffer_notify_display_text(),
4579 * buffer_notify_text(), buffer_notify_length()
4581 n_inserted = gtk_entry_buffer_insert_text (get_buffer (GTK_ENTRY (editable)), *position, new_text, n_chars);
4583 if (n_inserted != n_chars)
4584 gtk_widget_error_bell (GTK_WIDGET (editable));
4586 *position += n_inserted;
4590 gtk_entry_real_delete_text (GtkEditable *editable,
4595 * The actual deletion from the buffer. This will end up firing the
4596 * following signal handlers: buffer_deleted_text(), buffer_notify_display_text(),
4597 * buffer_notify_text(), buffer_notify_length()
4600 gtk_entry_buffer_delete_text (get_buffer (GTK_ENTRY (editable)), start_pos, end_pos - start_pos);
4603 /* GtkEntryBuffer signal handlers
4606 buffer_inserted_text (GtkEntryBuffer *buffer,
4612 guint password_hint_timeout;
4614 if (entry->current_pos > position)
4615 entry->current_pos += n_chars;
4617 if (entry->selection_bound > position)
4618 entry->selection_bound += n_chars;
4620 /* Calculate the password hint if it needs to be displayed. */
4621 if (n_chars == 1 && !entry->visible)
4623 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
4624 "gtk-entry-password-hint-timeout", &password_hint_timeout,
4627 if (password_hint_timeout > 0)
4629 GtkEntryPasswordHint *password_hint = g_object_get_qdata (G_OBJECT (entry),
4630 quark_password_hint);
4633 password_hint = g_slice_new0 (GtkEntryPasswordHint);
4634 g_object_set_qdata_full (G_OBJECT (entry), quark_password_hint, password_hint,
4635 (GDestroyNotify)gtk_entry_password_hint_free);
4638 password_hint->position = position;
4639 if (password_hint->source_id)
4640 g_source_remove (password_hint->source_id);
4641 password_hint->source_id = gdk_threads_add_timeout (password_hint_timeout,
4642 (GSourceFunc)gtk_entry_remove_password_hint, entry);
4648 buffer_deleted_text (GtkEntryBuffer *buffer,
4653 guint end_pos = position + n_chars;
4654 gint selection_bound;
4657 current_pos = entry->current_pos;
4658 if (current_pos > position)
4659 current_pos -= MIN (current_pos, end_pos) - position;
4661 selection_bound = entry->selection_bound;
4662 if (selection_bound > position)
4663 selection_bound -= MIN (selection_bound, end_pos) - position;
4665 gtk_entry_set_positions (entry, current_pos, selection_bound);
4667 /* We might have deleted the selection */
4668 gtk_entry_update_primary_selection (entry);
4670 /* Disable the password hint if one exists. */
4671 if (!entry->visible)
4673 GtkEntryPasswordHint *password_hint = g_object_get_qdata (G_OBJECT (entry),
4674 quark_password_hint);
4677 if (password_hint->source_id)
4678 g_source_remove (password_hint->source_id);
4679 password_hint->source_id = 0;
4680 password_hint->position = -1;
4686 buffer_notify_text (GtkEntryBuffer *buffer,
4690 gtk_entry_recompute (entry);
4691 emit_changed (entry);
4692 g_object_notify (G_OBJECT (entry), "text");
4696 buffer_notify_length (GtkEntryBuffer *buffer,
4700 g_object_notify (G_OBJECT (entry), "text-length");
4704 buffer_notify_max_length (GtkEntryBuffer *buffer,
4708 g_object_notify (G_OBJECT (entry), "max-length");
4712 buffer_connect_signals (GtkEntry *entry)
4714 g_signal_connect (get_buffer (entry), "inserted-text", G_CALLBACK (buffer_inserted_text), entry);
4715 g_signal_connect (get_buffer (entry), "deleted-text", G_CALLBACK (buffer_deleted_text), entry);
4716 g_signal_connect (get_buffer (entry), "notify::text", G_CALLBACK (buffer_notify_text), entry);
4717 g_signal_connect (get_buffer (entry), "notify::length", G_CALLBACK (buffer_notify_length), entry);
4718 g_signal_connect (get_buffer (entry), "notify::max-length", G_CALLBACK (buffer_notify_max_length), entry);
4722 buffer_disconnect_signals (GtkEntry *entry)
4724 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_inserted_text, entry);
4725 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_deleted_text, entry);
4726 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_text, entry);
4727 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_length, entry);
4728 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_max_length, entry);
4731 /* Compute the X position for an offset that corresponds to the "more important
4732 * cursor position for that offset. We use this when trying to guess to which
4733 * end of the selection we should go to when the user hits the left or
4737 get_better_cursor_x (GtkEntry *entry,
4740 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
4741 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
4742 gboolean split_cursor;
4744 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
4745 const gchar *text = pango_layout_get_text (layout);
4746 gint index = g_utf8_offset_to_pointer (text, offset) - text;
4748 PangoRectangle strong_pos, weak_pos;
4750 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
4751 "gtk-split-cursor", &split_cursor,
4754 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
4757 return strong_pos.x / PANGO_SCALE;
4759 return (keymap_direction == entry->resolved_dir) ? strong_pos.x / PANGO_SCALE : weak_pos.x / PANGO_SCALE;
4763 gtk_entry_move_cursor (GtkEntry *entry,
4764 GtkMovementStep step,
4766 gboolean extend_selection)
4768 gint new_pos = entry->current_pos;
4769 GtkEntryPrivate *priv;
4771 _gtk_entry_reset_im_context (entry);
4773 if (entry->current_pos != entry->selection_bound && !extend_selection)
4775 /* If we have a current selection and aren't extending it, move to the
4776 * start/or end of the selection as appropriate
4780 case GTK_MOVEMENT_VISUAL_POSITIONS:
4782 gint current_x = get_better_cursor_x (entry, entry->current_pos);
4783 gint bound_x = get_better_cursor_x (entry, entry->selection_bound);
4786 new_pos = current_x < bound_x ? entry->current_pos : entry->selection_bound;
4788 new_pos = current_x > bound_x ? entry->current_pos : entry->selection_bound;
4791 case GTK_MOVEMENT_LOGICAL_POSITIONS:
4792 case GTK_MOVEMENT_WORDS:
4794 new_pos = MIN (entry->current_pos, entry->selection_bound);
4796 new_pos = MAX (entry->current_pos, entry->selection_bound);
4798 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
4799 case GTK_MOVEMENT_PARAGRAPH_ENDS:
4800 case GTK_MOVEMENT_BUFFER_ENDS:
4801 priv = GTK_ENTRY_GET_PRIVATE (entry);
4802 new_pos = count < 0 ? 0 : gtk_entry_buffer_get_length (get_buffer (entry));
4804 case GTK_MOVEMENT_DISPLAY_LINES:
4805 case GTK_MOVEMENT_PARAGRAPHS:
4806 case GTK_MOVEMENT_PAGES:
4807 case GTK_MOVEMENT_HORIZONTAL_PAGES:
4815 case GTK_MOVEMENT_LOGICAL_POSITIONS:
4816 new_pos = gtk_entry_move_logically (entry, new_pos, count);
4818 case GTK_MOVEMENT_VISUAL_POSITIONS:
4819 new_pos = gtk_entry_move_visually (entry, new_pos, count);
4820 if (entry->current_pos == new_pos)
4822 if (!extend_selection)
4824 if (!gtk_widget_keynav_failed (GTK_WIDGET (entry),
4826 GTK_DIR_RIGHT : GTK_DIR_LEFT))
4828 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (entry));
4831 gtk_widget_child_focus (toplevel,
4833 GTK_DIR_RIGHT : GTK_DIR_LEFT);
4838 gtk_widget_error_bell (GTK_WIDGET (entry));
4842 case GTK_MOVEMENT_WORDS:
4845 new_pos = gtk_entry_move_forward_word (entry, new_pos, FALSE);
4850 new_pos = gtk_entry_move_backward_word (entry, new_pos, FALSE);
4853 if (entry->current_pos == new_pos)
4854 gtk_widget_error_bell (GTK_WIDGET (entry));
4856 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
4857 case GTK_MOVEMENT_PARAGRAPH_ENDS:
4858 case GTK_MOVEMENT_BUFFER_ENDS:
4859 priv = GTK_ENTRY_GET_PRIVATE (entry);
4860 new_pos = count < 0 ? 0 : gtk_entry_buffer_get_length (get_buffer (entry));
4861 if (entry->current_pos == new_pos)
4862 gtk_widget_error_bell (GTK_WIDGET (entry));
4864 case GTK_MOVEMENT_DISPLAY_LINES:
4865 case GTK_MOVEMENT_PARAGRAPHS:
4866 case GTK_MOVEMENT_PAGES:
4867 case GTK_MOVEMENT_HORIZONTAL_PAGES:
4872 if (extend_selection)
4873 gtk_editable_select_region (GTK_EDITABLE (entry), entry->selection_bound, new_pos);
4875 gtk_editable_set_position (GTK_EDITABLE (entry), new_pos);
4877 gtk_entry_pend_cursor_blink (entry);
4881 gtk_entry_insert_at_cursor (GtkEntry *entry,
4884 GtkEditable *editable = GTK_EDITABLE (entry);
4885 gint pos = entry->current_pos;
4887 if (entry->editable)
4889 _gtk_entry_reset_im_context (entry);
4891 gtk_editable_insert_text (editable, str, -1, &pos);
4892 gtk_editable_set_position (editable, pos);
4897 gtk_entry_delete_from_cursor (GtkEntry *entry,
4901 GtkEditable *editable = GTK_EDITABLE (entry);
4902 gint start_pos = entry->current_pos;
4903 gint end_pos = entry->current_pos;
4904 gint old_n_bytes = gtk_entry_buffer_get_bytes (get_buffer (entry));
4906 _gtk_entry_reset_im_context (entry);
4908 if (!entry->editable)
4910 gtk_widget_error_bell (GTK_WIDGET (entry));
4914 if (entry->selection_bound != entry->current_pos)
4916 gtk_editable_delete_selection (editable);
4922 case GTK_DELETE_CHARS:
4923 end_pos = gtk_entry_move_logically (entry, entry->current_pos, count);
4924 gtk_editable_delete_text (editable, MIN (start_pos, end_pos), MAX (start_pos, end_pos));
4926 case GTK_DELETE_WORDS:
4929 /* Move to end of current word, or if not on a word, end of previous word */
4930 end_pos = gtk_entry_move_backward_word (entry, end_pos, FALSE);
4931 end_pos = gtk_entry_move_forward_word (entry, end_pos, FALSE);
4935 /* Move to beginning of current word, or if not on a word, begining of next word */
4936 start_pos = gtk_entry_move_forward_word (entry, start_pos, FALSE);
4937 start_pos = gtk_entry_move_backward_word (entry, start_pos, FALSE);
4941 case GTK_DELETE_WORD_ENDS:
4944 start_pos = gtk_entry_move_backward_word (entry, start_pos, FALSE);
4949 end_pos = gtk_entry_move_forward_word (entry, end_pos, FALSE);
4952 gtk_editable_delete_text (editable, start_pos, end_pos);
4954 case GTK_DELETE_DISPLAY_LINE_ENDS:
4955 case GTK_DELETE_PARAGRAPH_ENDS:
4957 gtk_editable_delete_text (editable, 0, entry->current_pos);
4959 gtk_editable_delete_text (editable, entry->current_pos, -1);
4961 case GTK_DELETE_DISPLAY_LINES:
4962 case GTK_DELETE_PARAGRAPHS:
4963 gtk_editable_delete_text (editable, 0, -1);
4965 case GTK_DELETE_WHITESPACE:
4966 gtk_entry_delete_whitespace (entry);
4970 if (gtk_entry_buffer_get_bytes (get_buffer (entry)) == old_n_bytes)
4971 gtk_widget_error_bell (GTK_WIDGET (entry));
4973 gtk_entry_pend_cursor_blink (entry);
4977 gtk_entry_backspace (GtkEntry *entry)
4979 GtkEditable *editable = GTK_EDITABLE (entry);
4982 _gtk_entry_reset_im_context (entry);
4984 if (!entry->editable)
4986 gtk_widget_error_bell (GTK_WIDGET (entry));
4990 if (entry->selection_bound != entry->current_pos)
4992 gtk_editable_delete_selection (editable);
4996 prev_pos = gtk_entry_move_logically (entry, entry->current_pos, -1);
4998 if (prev_pos < entry->current_pos)
5000 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
5001 PangoLogAttr *log_attrs;
5004 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
5006 /* Deleting parts of characters */
5007 if (log_attrs[entry->current_pos].backspace_deletes_character)
5009 gchar *cluster_text;
5010 gchar *normalized_text;
5013 cluster_text = gtk_entry_get_display_text (entry, prev_pos,
5014 entry->current_pos);
5015 normalized_text = g_utf8_normalize (cluster_text,
5016 strlen (cluster_text),
5018 len = g_utf8_strlen (normalized_text, -1);
5020 gtk_editable_delete_text (editable, prev_pos, entry->current_pos);
5023 gint pos = entry->current_pos;
5025 gtk_editable_insert_text (editable, normalized_text,
5026 g_utf8_offset_to_pointer (normalized_text, len - 1) - normalized_text,
5028 gtk_editable_set_position (editable, pos);
5031 g_free (normalized_text);
5032 g_free (cluster_text);
5036 gtk_editable_delete_text (editable, prev_pos, entry->current_pos);
5043 gtk_widget_error_bell (GTK_WIDGET (entry));
5046 gtk_entry_pend_cursor_blink (entry);
5050 gtk_entry_copy_clipboard (GtkEntry *entry)
5052 GtkEditable *editable = GTK_EDITABLE (entry);
5056 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5058 if (!entry->visible)
5060 gtk_widget_error_bell (GTK_WIDGET (entry));
5064 str = gtk_entry_get_display_text (entry, start, end);
5065 gtk_clipboard_set_text (gtk_widget_get_clipboard (GTK_WIDGET (entry),
5066 GDK_SELECTION_CLIPBOARD),
5073 gtk_entry_cut_clipboard (GtkEntry *entry)
5075 GtkEditable *editable = GTK_EDITABLE (entry);
5078 if (!entry->visible)
5080 gtk_widget_error_bell (GTK_WIDGET (entry));
5084 gtk_entry_copy_clipboard (entry);
5086 if (entry->editable)
5088 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5089 gtk_editable_delete_text (editable, start, end);
5093 gtk_widget_error_bell (GTK_WIDGET (entry));
5098 gtk_entry_paste_clipboard (GtkEntry *entry)
5100 if (entry->editable)
5101 gtk_entry_paste (entry, GDK_NONE);
5103 gtk_widget_error_bell (GTK_WIDGET (entry));
5107 gtk_entry_delete_cb (GtkEntry *entry)
5109 GtkEditable *editable = GTK_EDITABLE (entry);
5112 if (entry->editable)
5114 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5115 gtk_editable_delete_text (editable, start, end);
5120 gtk_entry_toggle_overwrite (GtkEntry *entry)
5122 entry->overwrite_mode = !entry->overwrite_mode;
5123 gtk_entry_pend_cursor_blink (entry);
5124 gtk_widget_queue_draw (GTK_WIDGET (entry));
5128 gtk_entry_select_all (GtkEntry *entry)
5130 gtk_entry_select_line (entry);
5134 gtk_entry_real_activate (GtkEntry *entry)
5137 GtkWidget *default_widget, *focus_widget;
5138 GtkWidget *toplevel;
5141 widget = GTK_WIDGET (entry);
5143 if (entry->activates_default)
5145 toplevel = gtk_widget_get_toplevel (widget);
5146 if (GTK_IS_WINDOW (toplevel))
5148 window = GTK_WINDOW (toplevel);
5152 default_widget = gtk_window_get_default_widget (window);
5153 focus_widget = gtk_window_get_focus (window);
5154 if (widget != default_widget &&
5155 !(widget == focus_widget && (!default_widget || !gtk_widget_get_sensitive (default_widget))))
5156 gtk_window_activate_default (window);
5163 keymap_direction_changed (GdkKeymap *keymap,
5166 gtk_entry_recompute (entry);
5169 /* IM Context Callbacks
5173 gtk_entry_commit_cb (GtkIMContext *context,
5177 if (entry->editable)
5178 gtk_entry_enter_text (entry, str);
5182 gtk_entry_preedit_changed_cb (GtkIMContext *context,
5185 if (entry->editable)
5187 gchar *preedit_string;
5190 gtk_im_context_get_preedit_string (entry->im_context,
5191 &preedit_string, NULL,
5193 g_signal_emit (entry, signals[PREEDIT_CHANGED], 0, preedit_string);
5194 entry->preedit_length = strlen (preedit_string);
5195 cursor_pos = CLAMP (cursor_pos, 0, g_utf8_strlen (preedit_string, -1));
5196 entry->preedit_cursor = cursor_pos;
5197 g_free (preedit_string);
5199 gtk_entry_recompute (entry);
5204 gtk_entry_retrieve_surrounding_cb (GtkIMContext *context,
5209 /* XXXX ??? does this even make sense when text is not visible? Should we return FALSE? */
5210 text = gtk_entry_get_display_text (entry, 0, -1);
5211 gtk_im_context_set_surrounding (context, text, strlen (text), /* Length in bytes */
5212 g_utf8_offset_to_pointer (text, entry->current_pos) - text);
5219 gtk_entry_delete_surrounding_cb (GtkIMContext *slave,
5224 if (entry->editable)
5225 gtk_editable_delete_text (GTK_EDITABLE (entry),
5226 entry->current_pos + offset,
5227 entry->current_pos + offset + n_chars);
5232 /* Internal functions
5235 /* Used for im_commit_cb and inserting Unicode chars */
5237 gtk_entry_enter_text (GtkEntry *entry,
5240 GtkEditable *editable = GTK_EDITABLE (entry);
5242 gboolean old_need_im_reset;
5244 old_need_im_reset = entry->need_im_reset;
5245 entry->need_im_reset = FALSE;
5247 if (gtk_editable_get_selection_bounds (editable, NULL, NULL))
5248 gtk_editable_delete_selection (editable);
5251 if (entry->overwrite_mode)
5252 gtk_entry_delete_from_cursor (entry, GTK_DELETE_CHARS, 1);
5255 tmp_pos = entry->current_pos;
5256 gtk_editable_insert_text (editable, str, strlen (str), &tmp_pos);
5257 gtk_editable_set_position (editable, tmp_pos);
5259 entry->need_im_reset = old_need_im_reset;
5262 /* All changes to entry->current_pos and entry->selection_bound
5263 * should go through this function.
5266 gtk_entry_set_positions (GtkEntry *entry,
5268 gint selection_bound)
5270 gboolean changed = FALSE;
5272 g_object_freeze_notify (G_OBJECT (entry));
5274 if (current_pos != -1 &&
5275 entry->current_pos != current_pos)
5277 entry->current_pos = current_pos;
5280 g_object_notify (G_OBJECT (entry), "cursor-position");
5283 if (selection_bound != -1 &&
5284 entry->selection_bound != selection_bound)
5286 entry->selection_bound = selection_bound;
5289 g_object_notify (G_OBJECT (entry), "selection-bound");
5292 g_object_thaw_notify (G_OBJECT (entry));
5296 gtk_entry_move_adjustments (entry);
5297 gtk_entry_recompute (entry);
5302 gtk_entry_reset_layout (GtkEntry *entry)
5304 if (entry->cached_layout)
5306 g_object_unref (entry->cached_layout);
5307 entry->cached_layout = NULL;
5312 update_im_cursor_location (GtkEntry *entry)
5316 gint strong_xoffset;
5317 gint area_width, area_height;
5319 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
5320 gtk_entry_get_text_area_size (entry, NULL, NULL, &area_width, &area_height);
5322 strong_xoffset = strong_x - entry->scroll_offset;
5323 if (strong_xoffset < 0)
5327 else if (strong_xoffset > area_width)
5329 strong_xoffset = area_width;
5331 area.x = strong_xoffset;
5334 area.height = area_height;
5336 gtk_im_context_set_cursor_location (entry->im_context, &area);
5340 recompute_idle_func (gpointer data)
5344 entry = GTK_ENTRY (data);
5346 entry->recompute_idle = 0;
5348 if (gtk_widget_has_screen (GTK_WIDGET (entry)))
5350 gtk_entry_adjust_scroll (entry);
5351 gtk_entry_queue_draw (entry);
5353 update_im_cursor_location (entry);
5360 gtk_entry_recompute (GtkEntry *entry)
5362 gtk_entry_reset_layout (entry);
5363 gtk_entry_check_cursor_blink (entry);
5365 if (!entry->recompute_idle)
5367 entry->recompute_idle = gdk_threads_add_idle_full (G_PRIORITY_HIGH_IDLE + 15, /* between resize and redraw */
5368 recompute_idle_func, entry, NULL);
5372 static PangoLayout *
5373 gtk_entry_create_layout (GtkEntry *entry,
5374 gboolean include_preedit)
5376 GtkWidget *widget = GTK_WIDGET (entry);
5377 PangoLayout *layout = gtk_widget_create_pango_layout (widget, NULL);
5378 PangoAttrList *tmp_attrs = pango_attr_list_new ();
5380 gchar *preedit_string = NULL;
5381 gint preedit_length = 0;
5382 PangoAttrList *preedit_attrs = NULL;
5387 pango_layout_set_single_paragraph_mode (layout, TRUE);
5389 display = gtk_entry_get_display_text (entry, 0, -1);
5390 n_bytes = strlen (display);
5392 if (include_preedit)
5394 gtk_im_context_get_preedit_string (entry->im_context,
5395 &preedit_string, &preedit_attrs, NULL);
5396 preedit_length = entry->preedit_length;
5401 GString *tmp_string = g_string_new (display);
5402 gint cursor_index = g_utf8_offset_to_pointer (display, entry->current_pos) - display;
5404 g_string_insert (tmp_string, cursor_index, preedit_string);
5406 pango_layout_set_text (layout, tmp_string->str, tmp_string->len);
5408 pango_attr_list_splice (tmp_attrs, preedit_attrs,
5409 cursor_index, preedit_length);
5411 g_string_free (tmp_string, TRUE);
5415 PangoDirection pango_dir;
5417 if (gtk_entry_get_display_mode (entry) == DISPLAY_NORMAL)
5418 pango_dir = pango_find_base_dir (display, n_bytes);
5420 pango_dir = PANGO_DIRECTION_NEUTRAL;
5422 if (pango_dir == PANGO_DIRECTION_NEUTRAL)
5424 if (gtk_widget_has_focus (widget))
5426 GdkDisplay *display = gtk_widget_get_display (widget);
5427 GdkKeymap *keymap = gdk_keymap_get_for_display (display);
5428 if (gdk_keymap_get_direction (keymap) == PANGO_DIRECTION_RTL)
5429 pango_dir = PANGO_DIRECTION_RTL;
5431 pango_dir = PANGO_DIRECTION_LTR;
5435 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
5436 pango_dir = PANGO_DIRECTION_RTL;
5438 pango_dir = PANGO_DIRECTION_LTR;
5442 pango_context_set_base_dir (gtk_widget_get_pango_context (widget),
5445 entry->resolved_dir = pango_dir;
5447 pango_layout_set_text (layout, display, n_bytes);
5450 pango_layout_set_attributes (layout, tmp_attrs);
5452 g_free (preedit_string);
5456 pango_attr_list_unref (preedit_attrs);
5458 pango_attr_list_unref (tmp_attrs);
5463 static PangoLayout *
5464 gtk_entry_ensure_layout (GtkEntry *entry,
5465 gboolean include_preedit)
5467 if (entry->preedit_length > 0 &&
5468 !include_preedit != !entry->cache_includes_preedit)
5469 gtk_entry_reset_layout (entry);
5471 if (!entry->cached_layout)
5473 entry->cached_layout = gtk_entry_create_layout (entry, include_preedit);
5474 entry->cache_includes_preedit = include_preedit;
5477 return entry->cached_layout;
5481 get_layout_position (GtkEntry *entry,
5485 PangoLayout *layout;
5486 PangoRectangle logical_rect;
5487 gint area_width, area_height;
5488 GtkBorder inner_border;
5490 PangoLayoutLine *line;
5492 layout = gtk_entry_ensure_layout (entry, TRUE);
5494 gtk_entry_get_text_area_size (entry, NULL, NULL, &area_width, &area_height);
5495 _gtk_entry_effective_inner_border (entry, &inner_border);
5497 area_height = PANGO_SCALE * (area_height - inner_border.top - inner_border.bottom);
5499 line = pango_layout_get_lines_readonly (layout)->data;
5500 pango_layout_line_get_extents (line, NULL, &logical_rect);
5502 /* Align primarily for locale's ascent/descent */
5503 y_pos = ((area_height - entry->ascent - entry->descent) / 2 +
5504 entry->ascent + logical_rect.y);
5506 /* Now see if we need to adjust to fit in actual drawn string */
5507 if (logical_rect.height > area_height)
5508 y_pos = (area_height - logical_rect.height) / 2;
5511 else if (y_pos + logical_rect.height > area_height)
5512 y_pos = area_height - logical_rect.height;
5514 y_pos = inner_border.top + y_pos / PANGO_SCALE;
5517 *x = inner_border.left - entry->scroll_offset;
5524 draw_text_with_color (GtkEntry *entry, cairo_t *cr, GdkColor *default_color)
5526 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
5529 gint start_pos, end_pos;
5531 widget = GTK_WIDGET (entry);
5535 get_layout_position (entry, &x, &y);
5537 cairo_move_to (cr, x, y);
5538 gdk_cairo_set_source_color (cr, default_color);
5539 pango_cairo_show_layout (cr, layout);
5541 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start_pos, &end_pos))
5545 PangoRectangle logical_rect;
5546 GdkColor *selection_color, *text_color;
5547 GtkBorder inner_border;
5550 pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
5551 gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
5553 style = gtk_widget_get_style (widget);
5555 if (gtk_widget_has_focus (widget))
5557 selection_color = &style->base [GTK_STATE_SELECTED];
5558 text_color = &style->text [GTK_STATE_SELECTED];
5562 selection_color = &style->base [GTK_STATE_ACTIVE];
5563 text_color = &style->text [GTK_STATE_ACTIVE];
5566 _gtk_entry_effective_inner_border (entry, &inner_border);
5568 for (i = 0; i < n_ranges; ++i)
5569 cairo_rectangle (cr,
5570 inner_border.left - entry->scroll_offset + ranges[2 * i],
5573 logical_rect.height);
5577 gdk_cairo_set_source_color (cr, selection_color);
5580 cairo_move_to (cr, x, y);
5581 gdk_cairo_set_source_color (cr, text_color);
5582 pango_cairo_show_layout (cr, layout);
5590 gtk_entry_draw_text (GtkEntry *entry)
5592 GtkWidget *widget = GTK_WIDGET (entry);
5595 /* Nothing to display at all */
5596 if (gtk_entry_get_display_mode (entry) == DISPLAY_BLANK)
5599 if (gtk_widget_is_drawable (widget))
5603 GdkColor text_color, bar_text_color;
5606 gint progress_x, progress_y, progress_width, progress_height;
5608 state = GTK_STATE_SELECTED;
5609 if (!gtk_widget_get_sensitive (widget))
5610 state = GTK_STATE_INSENSITIVE;
5611 style = gtk_widget_get_style (widget);
5612 text_color = style->text[gtk_widget_get_state (widget)];
5613 bar_text_color = style->fg[state];
5615 get_progress_area (widget,
5616 &progress_x, &progress_y,
5617 &progress_width, &progress_height);
5619 cr = gdk_cairo_create (entry->text_area);
5621 /* If the color is the same, or the progress area has a zero
5622 * size, then we only need to draw once. */
5623 if ((text_color.pixel == bar_text_color.pixel) ||
5624 ((progress_width == 0) || (progress_height == 0)))
5626 draw_text_with_color (entry, cr, &text_color);
5630 gdk_drawable_get_size (entry->text_area, &width, &height);
5632 cairo_rectangle (cr, 0, 0, width, height);
5636 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
5637 cairo_rectangle (cr, 0, 0, width, height);
5639 gdk_window_get_position (entry->text_area, &pos_x, &pos_y);
5640 progress_x -= pos_x;
5641 progress_y -= pos_y;
5643 cairo_rectangle (cr, progress_x, progress_y,
5644 progress_width, progress_height);
5646 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_WINDING);
5648 draw_text_with_color (entry, cr, &text_color);
5651 cairo_rectangle (cr, progress_x, progress_y,
5652 progress_width, progress_height);
5655 draw_text_with_color (entry, cr, &bar_text_color);
5663 draw_insertion_cursor (GtkEntry *entry,
5664 GdkRectangle *cursor_location,
5665 gboolean is_primary,
5666 PangoDirection direction,
5667 gboolean draw_arrow)
5669 GtkWidget *widget = GTK_WIDGET (entry);
5670 GtkTextDirection text_dir;
5672 if (direction == PANGO_DIRECTION_LTR)
5673 text_dir = GTK_TEXT_DIR_LTR;
5675 text_dir = GTK_TEXT_DIR_RTL;
5677 gtk_draw_insertion_cursor (widget, entry->text_area, NULL,
5679 is_primary, text_dir, draw_arrow);
5683 gtk_entry_draw_cursor (GtkEntry *entry,
5686 GtkWidget *widget = GTK_WIDGET (entry);
5687 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
5688 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
5690 if (gtk_widget_is_drawable (widget))
5692 GdkRectangle cursor_location;
5693 gboolean split_cursor;
5694 PangoRectangle cursor_rect;
5695 GtkBorder inner_border;
5697 gint text_area_height;
5700 gboolean block_at_line_end;
5701 PangoLayout *layout;
5704 _gtk_entry_effective_inner_border (entry, &inner_border);
5706 xoffset = inner_border.left - entry->scroll_offset;
5708 gdk_drawable_get_size (entry->text_area, NULL, &text_area_height);
5710 layout = gtk_entry_ensure_layout (entry, TRUE);
5711 text = pango_layout_get_text (layout);
5712 cursor_index = g_utf8_offset_to_pointer (text, entry->current_pos + entry->preedit_cursor) - text;
5713 if (!entry->overwrite_mode)
5716 block = _gtk_text_util_get_block_cursor_location (layout,
5717 cursor_index, &cursor_rect, &block_at_line_end);
5721 gint strong_x, weak_x;
5722 PangoDirection dir1 = PANGO_DIRECTION_NEUTRAL;
5723 PangoDirection dir2 = PANGO_DIRECTION_NEUTRAL;
5727 gtk_entry_get_cursor_locations (entry, type, &strong_x, &weak_x);
5729 g_object_get (gtk_widget_get_settings (widget),
5730 "gtk-split-cursor", &split_cursor,
5733 dir1 = entry->resolved_dir;
5739 if (weak_x != strong_x)
5741 dir2 = (entry->resolved_dir == PANGO_DIRECTION_LTR) ? PANGO_DIRECTION_RTL : PANGO_DIRECTION_LTR;
5747 if (keymap_direction == entry->resolved_dir)
5753 cursor_location.x = xoffset + x1;
5754 cursor_location.y = inner_border.top;
5755 cursor_location.width = 0;
5756 cursor_location.height = text_area_height - inner_border.top - inner_border.bottom;
5758 draw_insertion_cursor (entry,
5759 &cursor_location, TRUE, dir1,
5760 dir2 != PANGO_DIRECTION_NEUTRAL);
5762 if (dir2 != PANGO_DIRECTION_NEUTRAL)
5764 cursor_location.x = xoffset + x2;
5765 draw_insertion_cursor (entry,
5766 &cursor_location, FALSE, dir2,
5770 else /* overwrite_mode */
5772 GdkColor cursor_color;
5777 get_layout_position (entry, &x, &y);
5779 rect.x = PANGO_PIXELS (cursor_rect.x) + x;
5780 rect.y = PANGO_PIXELS (cursor_rect.y) + y;
5781 rect.width = PANGO_PIXELS (cursor_rect.width);
5782 rect.height = PANGO_PIXELS (cursor_rect.height);
5784 cr = gdk_cairo_create (entry->text_area);
5786 _gtk_widget_get_cursor_color (widget, &cursor_color);
5787 gdk_cairo_set_source_color (cr, &cursor_color);
5788 gdk_cairo_rectangle (cr, &rect);
5791 if (!block_at_line_end)
5793 gdk_cairo_rectangle (cr, &rect);
5795 cairo_move_to (cr, x, y);
5796 gdk_cairo_set_source_color (cr, >k_widget_get_style (widget)->base[gtk_widget_get_state (widget)]);
5797 pango_cairo_show_layout (cr, layout);
5806 gtk_entry_queue_draw (GtkEntry *entry)
5808 if (gtk_widget_is_drawable (GTK_WIDGET (entry)))
5809 gdk_window_invalidate_rect (entry->text_area, NULL, FALSE);
5813 _gtk_entry_reset_im_context (GtkEntry *entry)
5815 if (entry->need_im_reset)
5817 entry->need_im_reset = FALSE;
5818 gtk_im_context_reset (entry->im_context);
5823 * gtk_entry_reset_im_context:
5824 * @entry: a #GtkEntry
5826 * Reset the input method context of the entry if needed.
5828 * This can be necessary in the case where modifying the buffer
5829 * would confuse on-going input method behavior.
5834 gtk_entry_reset_im_context (GtkEntry *entry)
5836 g_return_if_fail (GTK_IS_ENTRY (entry));
5838 _gtk_entry_reset_im_context (entry);
5842 * gtk_entry_im_context_filter_keypress:
5843 * @entry: a #GtkEntry
5844 * @event: the key event
5846 * Allow the #GtkEntry input method to internally handle key press
5847 * and release events. If this function returns %TRUE, then no further
5848 * processing should be done for this key event. See
5849 * gtk_im_context_filter_keypress().
5851 * Note that you are expected to call this function from your handler
5852 * when overriding key event handling. This is needed in the case when
5853 * you need to insert your own key handling between the input method
5854 * and the default key event handling of the #GtkEntry.
5855 * See gtk_text_view_reset_im_context() for an example of use.
5857 * Return value: %TRUE if the input method handled the key event.
5862 gtk_entry_im_context_filter_keypress (GtkEntry *entry,
5865 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
5867 return gtk_im_context_filter_keypress (entry->im_context, event);
5872 gtk_entry_find_position (GtkEntry *entry,
5875 PangoLayout *layout;
5876 PangoLayoutLine *line;
5883 layout = gtk_entry_ensure_layout (entry, TRUE);
5884 text = pango_layout_get_text (layout);
5885 cursor_index = g_utf8_offset_to_pointer (text, entry->current_pos) - text;
5887 line = pango_layout_get_lines_readonly (layout)->data;
5888 pango_layout_line_x_to_index (line, x * PANGO_SCALE, &index, &trailing);
5890 if (index >= cursor_index && entry->preedit_length)
5892 if (index >= cursor_index + entry->preedit_length)
5893 index -= entry->preedit_length;
5896 index = cursor_index;
5901 pos = g_utf8_pointer_to_offset (text, text + index);
5908 gtk_entry_get_cursor_locations (GtkEntry *entry,
5913 DisplayMode mode = gtk_entry_get_display_mode (entry);
5915 /* Nothing to display at all, so no cursor is relevant */
5916 if (mode == DISPLAY_BLANK)
5926 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
5927 const gchar *text = pango_layout_get_text (layout);
5928 PangoRectangle strong_pos, weak_pos;
5931 if (type == CURSOR_STANDARD)
5933 index = g_utf8_offset_to_pointer (text, entry->current_pos + entry->preedit_cursor) - text;
5935 else /* type == CURSOR_DND */
5937 index = g_utf8_offset_to_pointer (text, entry->dnd_position) - text;
5939 if (entry->dnd_position > entry->current_pos)
5941 if (mode == DISPLAY_NORMAL)
5942 index += entry->preedit_length;
5945 gint preedit_len_chars = g_utf8_strlen (text, -1) - gtk_entry_buffer_get_length (get_buffer (entry));
5946 index += preedit_len_chars * g_unichar_to_utf8 (entry->invisible_char, NULL);
5951 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
5954 *strong_x = strong_pos.x / PANGO_SCALE;
5957 *weak_x = weak_pos.x / PANGO_SCALE;
5962 gtk_entry_adjust_scroll (GtkEntry *entry)
5964 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
5965 gint min_offset, max_offset;
5966 gint text_area_width, text_width;
5967 GtkBorder inner_border;
5968 gint strong_x, weak_x;
5969 gint strong_xoffset, weak_xoffset;
5971 PangoLayout *layout;
5972 PangoLayoutLine *line;
5973 PangoRectangle logical_rect;
5975 if (!gtk_widget_get_realized (GTK_WIDGET (entry)))
5978 _gtk_entry_effective_inner_border (entry, &inner_border);
5980 gdk_drawable_get_size (entry->text_area, &text_area_width, NULL);
5981 text_area_width -= inner_border.left + inner_border.right;
5982 if (text_area_width < 0)
5983 text_area_width = 0;
5985 layout = gtk_entry_ensure_layout (entry, TRUE);
5986 line = pango_layout_get_lines_readonly (layout)->data;
5988 pango_layout_line_get_extents (line, NULL, &logical_rect);
5990 /* Display as much text as we can */
5992 if (entry->resolved_dir == PANGO_DIRECTION_LTR)
5993 xalign = priv->xalign;
5995 xalign = 1.0 - priv->xalign;
5997 text_width = PANGO_PIXELS(logical_rect.width);
5999 if (text_width > text_area_width)
6002 max_offset = text_width - text_area_width;
6006 min_offset = (text_width - text_area_width) * xalign;
6007 max_offset = min_offset;
6010 entry->scroll_offset = CLAMP (entry->scroll_offset, min_offset, max_offset);
6012 /* And make sure cursors are on screen. Note that the cursor is
6013 * actually drawn one pixel into the INNER_BORDER space on
6014 * the right, when the scroll is at the utmost right. This
6015 * looks better to to me than confining the cursor inside the
6016 * border entirely, though it means that the cursor gets one
6017 * pixel closer to the edge of the widget on the right than
6018 * on the left. This might need changing if one changed
6019 * INNER_BORDER from 2 to 1, as one would do on a
6020 * small-screen-real-estate display.
6022 * We always make sure that the strong cursor is on screen, and
6023 * put the weak cursor on screen if possible.
6026 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, &weak_x);
6028 strong_xoffset = strong_x - entry->scroll_offset;
6030 if (strong_xoffset < 0)
6032 entry->scroll_offset += strong_xoffset;
6035 else if (strong_xoffset > text_area_width)
6037 entry->scroll_offset += strong_xoffset - text_area_width;
6038 strong_xoffset = text_area_width;
6041 weak_xoffset = weak_x - entry->scroll_offset;
6043 if (weak_xoffset < 0 && strong_xoffset - weak_xoffset <= text_area_width)
6045 entry->scroll_offset += weak_xoffset;
6047 else if (weak_xoffset > text_area_width &&
6048 strong_xoffset - (weak_xoffset - text_area_width) >= 0)
6050 entry->scroll_offset += weak_xoffset - text_area_width;
6053 g_object_notify (G_OBJECT (entry), "scroll-offset");
6057 gtk_entry_move_adjustments (GtkEntry *entry)
6059 GtkAllocation allocation;
6060 GtkAdjustment *adjustment;
6061 PangoContext *context;
6062 PangoFontMetrics *metrics;
6063 gint x, layout_x, border_x, border_y;
6066 adjustment = g_object_get_qdata (G_OBJECT (entry), quark_cursor_hadjustment);
6070 gtk_widget_get_allocation (&(entry->widget), &allocation);
6072 /* Cursor position, layout offset, border width, and widget allocation */
6073 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &x, NULL);
6074 get_layout_position (entry, &layout_x, NULL);
6075 _gtk_entry_get_borders (entry, &border_x, &border_y);
6076 x += allocation.x + layout_x + border_x;
6078 /* Approximate width of a char, so user can see what is ahead/behind */
6079 context = gtk_widget_get_pango_context (GTK_WIDGET (entry));
6080 metrics = pango_context_get_metrics (context,
6081 gtk_widget_get_style (&(entry->widget))->font_desc,
6082 pango_context_get_language (context));
6083 char_width = pango_font_metrics_get_approximate_char_width (metrics) / PANGO_SCALE;
6086 gtk_adjustment_clamp_page (adjustment,
6087 x - (char_width + 1), /* one char + one pixel before */
6088 x + (char_width + 2)); /* one char + cursor + one pixel after */
6092 gtk_entry_move_visually (GtkEntry *entry,
6097 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6100 text = pango_layout_get_text (layout);
6102 index = g_utf8_offset_to_pointer (text, start) - text;
6106 int new_index, new_trailing;
6107 gboolean split_cursor;
6110 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
6111 "gtk-split-cursor", &split_cursor,
6118 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
6119 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
6121 strong = keymap_direction == entry->resolved_dir;
6126 pango_layout_move_cursor_visually (layout, strong, index, 0, 1, &new_index, &new_trailing);
6131 pango_layout_move_cursor_visually (layout, strong, index, 0, -1, &new_index, &new_trailing);
6137 else if (new_index != G_MAXINT)
6140 while (new_trailing--)
6141 index = g_utf8_next_char (text + index) - text;
6144 return g_utf8_pointer_to_offset (text, text + index);
6148 gtk_entry_move_logically (GtkEntry *entry,
6152 gint new_pos = start;
6155 length = gtk_entry_buffer_get_length (get_buffer (entry));
6157 /* Prevent any leak of information */
6158 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6160 new_pos = CLAMP (start + count, 0, length);
6164 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6165 PangoLogAttr *log_attrs;
6168 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6170 while (count > 0 && new_pos < length)
6174 while (new_pos < length && !log_attrs[new_pos].is_cursor_position);
6178 while (count < 0 && new_pos > 0)
6182 while (new_pos > 0 && !log_attrs[new_pos].is_cursor_position);
6194 gtk_entry_move_forward_word (GtkEntry *entry,
6196 gboolean allow_whitespace)
6198 gint new_pos = start;
6201 length = gtk_entry_buffer_get_length (get_buffer (entry));
6203 /* Prevent any leak of information */
6204 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6208 else if (new_pos < length)
6210 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6211 PangoLogAttr *log_attrs;
6214 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6216 /* Find the next word boundary */
6218 while (new_pos < n_attrs - 1 && !(log_attrs[new_pos].is_word_end ||
6219 (log_attrs[new_pos].is_word_start && allow_whitespace)))
6230 gtk_entry_move_backward_word (GtkEntry *entry,
6232 gboolean allow_whitespace)
6234 gint new_pos = start;
6236 /* Prevent any leak of information */
6237 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6243 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6244 PangoLogAttr *log_attrs;
6247 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6249 new_pos = start - 1;
6251 /* Find the previous word boundary */
6252 while (new_pos > 0 && !(log_attrs[new_pos].is_word_start ||
6253 (log_attrs[new_pos].is_word_end && allow_whitespace)))
6263 gtk_entry_delete_whitespace (GtkEntry *entry)
6265 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6266 PangoLogAttr *log_attrs;
6270 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6272 start = end = entry->current_pos;
6274 while (start > 0 && log_attrs[start-1].is_white)
6277 while (end < n_attrs && log_attrs[end].is_white)
6283 gtk_editable_delete_text (GTK_EDITABLE (entry), start, end);
6288 gtk_entry_select_word (GtkEntry *entry)
6290 gint start_pos = gtk_entry_move_backward_word (entry, entry->current_pos, TRUE);
6291 gint end_pos = gtk_entry_move_forward_word (entry, entry->current_pos, TRUE);
6293 gtk_editable_select_region (GTK_EDITABLE (entry), start_pos, end_pos);
6297 gtk_entry_select_line (GtkEntry *entry)
6299 gtk_editable_select_region (GTK_EDITABLE (entry), 0, -1);
6303 truncate_multiline (const gchar *text)
6308 text[length] && text[length] != '\n' && text[length] != '\r';
6315 paste_received (GtkClipboard *clipboard,
6319 GtkEntry *entry = GTK_ENTRY (data);
6320 GtkEditable *editable = GTK_EDITABLE (entry);
6321 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
6323 if (entry->button == 2)
6325 gint pos, start, end;
6326 pos = priv->insert_pos;
6327 gtk_editable_get_selection_bounds (editable, &start, &end);
6328 if (!((start <= pos && pos <= end) || (end <= pos && pos <= start)))
6329 gtk_editable_select_region (editable, pos, pos);
6334 gint pos, start, end;
6336 gboolean popup_completion;
6337 GtkEntryCompletion *completion;
6339 completion = gtk_entry_get_completion (entry);
6341 if (entry->truncate_multiline)
6342 length = truncate_multiline (text);
6344 /* only complete if the selection is at the end */
6345 popup_completion = (gtk_entry_buffer_get_length (get_buffer (entry)) ==
6346 MAX (entry->current_pos, entry->selection_bound));
6350 if (gtk_widget_get_mapped (completion->priv->popup_window))
6351 _gtk_entry_completion_popdown (completion);
6353 if (!popup_completion && completion->priv->changed_id > 0)
6354 g_signal_handler_block (entry, completion->priv->changed_id);
6357 begin_change (entry);
6358 g_object_freeze_notify (G_OBJECT (entry));
6359 if (gtk_editable_get_selection_bounds (editable, &start, &end))
6360 gtk_editable_delete_text (editable, start, end);
6362 pos = entry->current_pos;
6363 gtk_editable_insert_text (editable, text, length, &pos);
6364 gtk_editable_set_position (editable, pos);
6365 g_object_thaw_notify (G_OBJECT (entry));
6369 !popup_completion && completion->priv->changed_id > 0)
6370 g_signal_handler_unblock (entry, completion->priv->changed_id);
6373 g_object_unref (entry);
6377 gtk_entry_paste (GtkEntry *entry,
6380 g_object_ref (entry);
6381 gtk_clipboard_request_text (gtk_widget_get_clipboard (GTK_WIDGET (entry), selection),
6382 paste_received, entry);
6386 primary_get_cb (GtkClipboard *clipboard,
6387 GtkSelectionData *selection_data,
6391 GtkEntry *entry = GTK_ENTRY (data);
6394 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end))
6396 gchar *str = gtk_entry_get_display_text (entry, start, end);
6397 gtk_selection_data_set_text (selection_data, str, -1);
6403 primary_clear_cb (GtkClipboard *clipboard,
6406 GtkEntry *entry = GTK_ENTRY (data);
6408 gtk_editable_select_region (GTK_EDITABLE (entry), entry->current_pos, entry->current_pos);
6412 gtk_entry_update_primary_selection (GtkEntry *entry)
6414 GtkTargetList *list;
6415 GtkTargetEntry *targets;
6416 GtkClipboard *clipboard;
6420 if (!gtk_widget_get_realized (GTK_WIDGET (entry)))
6423 list = gtk_target_list_new (NULL, 0);
6424 gtk_target_list_add_text_targets (list, 0);
6426 targets = gtk_target_table_new_from_list (list, &n_targets);
6428 clipboard = gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_PRIMARY);
6430 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end))
6432 if (!gtk_clipboard_set_with_owner (clipboard, targets, n_targets,
6433 primary_get_cb, primary_clear_cb, G_OBJECT (entry)))
6434 primary_clear_cb (clipboard, entry);
6438 if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (entry))
6439 gtk_clipboard_clear (clipboard);
6442 gtk_target_table_free (targets, n_targets);
6443 gtk_target_list_unref (list);
6447 gtk_entry_clear (GtkEntry *entry,
6448 GtkEntryIconPosition icon_pos)
6450 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
6451 EntryIconInfo *icon_info = priv->icons[icon_pos];
6453 if (!icon_info || icon_info->storage_type == GTK_IMAGE_EMPTY)
6456 g_object_freeze_notify (G_OBJECT (entry));
6458 /* Explicitly check, as the pointer may become invalidated
6459 * during destruction.
6461 if (GDK_IS_WINDOW (icon_info->window))
6462 gdk_window_hide (icon_info->window);
6464 if (icon_info->pixbuf)
6466 g_object_unref (icon_info->pixbuf);
6467 icon_info->pixbuf = NULL;
6470 switch (icon_info->storage_type)
6472 case GTK_IMAGE_PIXBUF:
6473 g_object_notify (G_OBJECT (entry),
6474 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-pixbuf" : "secondary-icon-pixbuf");
6477 case GTK_IMAGE_STOCK:
6478 g_free (icon_info->stock_id);
6479 icon_info->stock_id = NULL;
6480 g_object_notify (G_OBJECT (entry),
6481 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-stock" : "secondary-icon-stock");
6484 case GTK_IMAGE_ICON_NAME:
6485 g_free (icon_info->icon_name);
6486 icon_info->icon_name = NULL;
6487 g_object_notify (G_OBJECT (entry),
6488 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-name" : "secondary-icon-name");
6491 case GTK_IMAGE_GICON:
6492 if (icon_info->gicon)
6494 g_object_unref (icon_info->gicon);
6495 icon_info->gicon = NULL;
6497 g_object_notify (G_OBJECT (entry),
6498 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-gicon" : "secondary-icon-gicon");
6502 g_assert_not_reached ();
6506 icon_info->storage_type = GTK_IMAGE_EMPTY;
6507 g_object_notify (G_OBJECT (entry),
6508 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-storage-type" : "secondary-icon-storage-type");
6510 g_object_thaw_notify (G_OBJECT (entry));
6514 gtk_entry_ensure_pixbuf (GtkEntry *entry,
6515 GtkEntryIconPosition icon_pos)
6517 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
6518 EntryIconInfo *icon_info = priv->icons[icon_pos];
6520 GtkIconTheme *icon_theme;
6521 GtkSettings *settings;
6527 if (!icon_info || icon_info->pixbuf)
6530 widget = GTK_WIDGET (entry);
6532 switch (icon_info->storage_type)
6534 case GTK_IMAGE_EMPTY:
6535 case GTK_IMAGE_PIXBUF:
6537 case GTK_IMAGE_STOCK:
6538 state = gtk_widget_get_state (widget);
6539 gtk_widget_set_state (widget, GTK_STATE_NORMAL);
6540 icon_info->pixbuf = gtk_widget_render_icon (widget,
6541 icon_info->stock_id,
6544 if (!icon_info->pixbuf)
6545 icon_info->pixbuf = gtk_widget_render_icon (widget,
6546 GTK_STOCK_MISSING_IMAGE,
6549 gtk_widget_set_state (widget, state);
6552 case GTK_IMAGE_ICON_NAME:
6553 screen = gtk_widget_get_screen (widget);
6556 icon_theme = gtk_icon_theme_get_for_screen (screen);
6557 settings = gtk_settings_get_for_screen (screen);
6559 gtk_icon_size_lookup_for_settings (settings,
6563 icon_info->pixbuf = gtk_icon_theme_load_icon (icon_theme,
6564 icon_info->icon_name,
6565 MIN (width, height),
6568 if (icon_info->pixbuf == NULL)
6570 state = gtk_widget_get_state (widget);
6571 gtk_widget_set_state (widget, GTK_STATE_NORMAL);
6572 icon_info->pixbuf = gtk_widget_render_icon (widget,
6573 GTK_STOCK_MISSING_IMAGE,
6576 gtk_widget_set_state (widget, state);
6581 case GTK_IMAGE_GICON:
6582 screen = gtk_widget_get_screen (widget);
6585 icon_theme = gtk_icon_theme_get_for_screen (screen);
6586 settings = gtk_settings_get_for_screen (screen);
6588 gtk_icon_size_lookup_for_settings (settings,
6592 info = gtk_icon_theme_lookup_by_gicon (icon_theme,
6594 MIN (width, height),
6595 GTK_ICON_LOOKUP_USE_BUILTIN);
6598 icon_info->pixbuf = gtk_icon_info_load_icon (info, NULL);
6599 gtk_icon_info_free (info);
6602 if (icon_info->pixbuf == NULL)
6604 state = gtk_widget_get_state (widget);
6605 gtk_widget_set_state (widget, GTK_STATE_NORMAL);
6606 icon_info->pixbuf = gtk_widget_render_icon (widget,
6607 GTK_STOCK_MISSING_IMAGE,
6610 gtk_widget_set_state (widget, state);
6616 g_assert_not_reached ();
6620 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
6621 gdk_window_show_unraised (icon_info->window);
6631 * Creates a new entry.
6633 * Return value: a new #GtkEntry.
6636 gtk_entry_new (void)
6638 return g_object_new (GTK_TYPE_ENTRY, NULL);
6642 * gtk_entry_new_with_buffer:
6643 * @buffer: The buffer to use for the new #GtkEntry.
6645 * Creates a new entry with the specified text buffer.
6647 * Return value: a new #GtkEntry
6652 gtk_entry_new_with_buffer (GtkEntryBuffer *buffer)
6654 g_return_val_if_fail (GTK_IS_ENTRY_BUFFER (buffer), NULL);
6655 return g_object_new (GTK_TYPE_ENTRY, "buffer", buffer, NULL);
6658 static GtkEntryBuffer*
6659 get_buffer (GtkEntry *entry)
6661 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
6663 if (priv->buffer == NULL)
6665 GtkEntryBuffer *buffer;
6666 buffer = gtk_entry_buffer_new (NULL, 0);
6667 gtk_entry_set_buffer (entry, buffer);
6668 g_object_unref (buffer);
6671 return priv->buffer;
6675 * gtk_entry_get_buffer:
6676 * @entry: a #GtkEntry
6678 * Get the #GtkEntryBuffer object which holds the text for
6683 * Returns: (transfer none): A #GtkEntryBuffer object.
6686 gtk_entry_get_buffer (GtkEntry *entry)
6688 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
6690 return get_buffer (entry);
6694 * gtk_entry_set_buffer:
6695 * @entry: a #GtkEntry
6696 * @buffer: a #GtkEntryBuffer
6698 * Set the #GtkEntryBuffer object which holds the text for
6704 gtk_entry_set_buffer (GtkEntry *entry,
6705 GtkEntryBuffer *buffer)
6707 GtkEntryPrivate *priv;
6710 g_return_if_fail (GTK_IS_ENTRY (entry));
6711 priv = GTK_ENTRY_GET_PRIVATE (entry);
6715 g_return_if_fail (GTK_IS_ENTRY_BUFFER (buffer));
6716 g_object_ref (buffer);
6721 buffer_disconnect_signals (entry);
6722 g_object_unref (priv->buffer);
6725 priv->buffer = buffer;
6728 buffer_connect_signals (entry);
6730 obj = G_OBJECT (entry);
6731 g_object_freeze_notify (obj);
6732 g_object_notify (obj, "buffer");
6733 g_object_notify (obj, "text");
6734 g_object_notify (obj, "text-length");
6735 g_object_notify (obj, "max-length");
6736 g_object_notify (obj, "visibility");
6737 g_object_notify (obj, "invisible-char");
6738 g_object_notify (obj, "invisible-char-set");
6739 g_object_thaw_notify (obj);
6741 gtk_editable_set_position (GTK_EDITABLE (entry), 0);
6742 gtk_entry_recompute (entry);
6746 * gtk_entry_get_text_window:
6747 * @entry: a #GtkEntry
6749 * Returns the #GdkWindow which contains the text. This function is
6750 * useful when drawing something to the entry in an expose-event
6751 * callback because it enables the callback to distinguish between
6752 * the text window and entry's icon windows.
6754 * See also gtk_entry_get_icon_window().
6756 * Return value: (transfer none): the entry's text window.
6761 gtk_entry_get_text_window (GtkEntry *entry)
6763 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
6765 return entry->text_area;
6770 * gtk_entry_set_text:
6771 * @entry: a #GtkEntry
6772 * @text: the new text
6774 * Sets the text in the widget to the given
6775 * value, replacing the current contents.
6777 * See gtk_entry_buffer_set_text().
6780 gtk_entry_set_text (GtkEntry *entry,
6784 GtkEntryCompletion *completion;
6785 GtkEntryPrivate *priv;
6787 g_return_if_fail (GTK_IS_ENTRY (entry));
6788 g_return_if_fail (text != NULL);
6789 priv = GTK_ENTRY_GET_PRIVATE (entry);
6791 /* Actually setting the text will affect the cursor and selection;
6792 * if the contents don't actually change, this will look odd to the user.
6794 if (strcmp (gtk_entry_buffer_get_text (get_buffer (entry)), text) == 0)
6797 completion = gtk_entry_get_completion (entry);
6798 if (completion && completion->priv->changed_id > 0)
6799 g_signal_handler_block (entry, completion->priv->changed_id);
6801 begin_change (entry);
6802 g_object_freeze_notify (G_OBJECT (entry));
6803 gtk_editable_delete_text (GTK_EDITABLE (entry), 0, -1);
6805 gtk_editable_insert_text (GTK_EDITABLE (entry), text, strlen (text), &tmp_pos);
6806 g_object_thaw_notify (G_OBJECT (entry));
6809 if (completion && completion->priv->changed_id > 0)
6810 g_signal_handler_unblock (entry, completion->priv->changed_id);
6814 * gtk_entry_set_visibility:
6815 * @entry: a #GtkEntry
6816 * @visible: %TRUE if the contents of the entry are displayed
6819 * Sets whether the contents of the entry are visible or not.
6820 * When visibility is set to %FALSE, characters are displayed
6821 * as the invisible char, and will also appear that way when
6822 * the text in the entry widget is copied elsewhere.
6824 * By default, GTK+ picks the best invisible character available
6825 * in the current font, but it can be changed with
6826 * gtk_entry_set_invisible_char().
6829 gtk_entry_set_visibility (GtkEntry *entry,
6832 g_return_if_fail (GTK_IS_ENTRY (entry));
6834 visible = visible != FALSE;
6836 if (entry->visible != visible)
6838 entry->visible = visible;
6840 g_object_notify (G_OBJECT (entry), "visibility");
6841 gtk_entry_recompute (entry);
6846 * gtk_entry_get_visibility:
6847 * @entry: a #GtkEntry
6849 * Retrieves whether the text in @entry is visible. See
6850 * gtk_entry_set_visibility().
6852 * Return value: %TRUE if the text is currently visible
6855 gtk_entry_get_visibility (GtkEntry *entry)
6857 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
6859 return entry->visible;
6863 * gtk_entry_set_invisible_char:
6864 * @entry: a #GtkEntry
6865 * @ch: a Unicode character
6867 * Sets the character to use in place of the actual text when
6868 * gtk_entry_set_visibility() has been called to set text visibility
6869 * to %FALSE. i.e. this is the character used in "password mode" to
6870 * show the user how many characters have been typed. By default, GTK+
6871 * picks the best invisible char available in the current font. If you
6872 * set the invisible char to 0, then the user will get no feedback
6873 * at all; there will be no text on the screen as they type.
6876 gtk_entry_set_invisible_char (GtkEntry *entry,
6879 GtkEntryPrivate *priv;
6881 g_return_if_fail (GTK_IS_ENTRY (entry));
6883 priv = GTK_ENTRY_GET_PRIVATE (entry);
6885 if (!priv->invisible_char_set)
6887 priv->invisible_char_set = TRUE;
6888 g_object_notify (G_OBJECT (entry), "invisible-char-set");
6891 if (ch == entry->invisible_char)
6894 entry->invisible_char = ch;
6895 g_object_notify (G_OBJECT (entry), "invisible-char");
6896 gtk_entry_recompute (entry);
6900 * gtk_entry_get_invisible_char:
6901 * @entry: a #GtkEntry
6903 * Retrieves the character displayed in place of the real characters
6904 * for entries with visibility set to false. See gtk_entry_set_invisible_char().
6906 * Return value: the current invisible char, or 0, if the entry does not
6907 * show invisible text at all.
6910 gtk_entry_get_invisible_char (GtkEntry *entry)
6912 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
6914 return entry->invisible_char;
6918 * gtk_entry_unset_invisible_char:
6919 * @entry: a #GtkEntry
6921 * Unsets the invisible char previously set with
6922 * gtk_entry_set_invisible_char(). So that the
6923 * default invisible char is used again.
6928 gtk_entry_unset_invisible_char (GtkEntry *entry)
6930 GtkEntryPrivate *priv;
6933 g_return_if_fail (GTK_IS_ENTRY (entry));
6935 priv = GTK_ENTRY_GET_PRIVATE (entry);
6937 if (!priv->invisible_char_set)
6940 priv->invisible_char_set = FALSE;
6941 ch = find_invisible_char (GTK_WIDGET (entry));
6943 if (entry->invisible_char != ch)
6945 entry->invisible_char = ch;
6946 g_object_notify (G_OBJECT (entry), "invisible-char");
6949 g_object_notify (G_OBJECT (entry), "invisible-char-set");
6950 gtk_entry_recompute (entry);
6954 * gtk_entry_set_overwrite_mode:
6955 * @entry: a #GtkEntry
6956 * @overwrite: new value
6958 * Sets whether the text is overwritten when typing in the #GtkEntry.
6963 gtk_entry_set_overwrite_mode (GtkEntry *entry,
6966 g_return_if_fail (GTK_IS_ENTRY (entry));
6968 if (entry->overwrite_mode == overwrite)
6971 gtk_entry_toggle_overwrite (entry);
6973 g_object_notify (G_OBJECT (entry), "overwrite-mode");
6977 * gtk_entry_get_overwrite_mode:
6978 * @entry: a #GtkEntry
6980 * Gets the value set by gtk_entry_set_overwrite_mode().
6982 * Return value: whether the text is overwritten when typing.
6987 gtk_entry_get_overwrite_mode (GtkEntry *entry)
6989 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
6991 return entry->overwrite_mode;
6995 * gtk_entry_get_text:
6996 * @entry: a #GtkEntry
6998 * Retrieves the contents of the entry widget.
6999 * See also gtk_editable_get_chars().
7001 * This is equivalent to:
7003 * <informalexample><programlisting>
7004 * gtk_entry_buffer_get_text (gtk_entry_get_buffer (entry));
7005 * </programlisting></informalexample>
7007 * Return value: a pointer to the contents of the widget as a
7008 * string. This string points to internally allocated
7009 * storage in the widget and must not be freed, modified or
7012 G_CONST_RETURN gchar*
7013 gtk_entry_get_text (GtkEntry *entry)
7015 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7016 return gtk_entry_buffer_get_text (get_buffer (entry));
7020 * gtk_entry_set_max_length:
7021 * @entry: a #GtkEntry
7022 * @max: the maximum length of the entry, or 0 for no maximum.
7023 * (other than the maximum length of entries.) The value passed in will
7024 * be clamped to the range 0-65536.
7026 * Sets the maximum allowed length of the contents of the widget. If
7027 * the current contents are longer than the given length, then they
7028 * will be truncated to fit.
7030 * This is equivalent to:
7032 * <informalexample><programlisting>
7033 * gtk_entry_buffer_set_max_length (gtk_entry_get_buffer (entry), max);
7034 * </programlisting></informalexample>
7037 gtk_entry_set_max_length (GtkEntry *entry,
7040 g_return_if_fail (GTK_IS_ENTRY (entry));
7041 gtk_entry_buffer_set_max_length (get_buffer (entry), max);
7045 * gtk_entry_get_max_length:
7046 * @entry: a #GtkEntry
7048 * Retrieves the maximum allowed length of the text in
7049 * @entry. See gtk_entry_set_max_length().
7051 * This is equivalent to:
7053 * <informalexample><programlisting>
7054 * gtk_entry_buffer_get_max_length (gtk_entry_get_buffer (entry));
7055 * </programlisting></informalexample>
7057 * Return value: the maximum allowed number of characters
7058 * in #GtkEntry, or 0 if there is no maximum.
7061 gtk_entry_get_max_length (GtkEntry *entry)
7063 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7064 return gtk_entry_buffer_get_max_length (get_buffer (entry));
7068 * gtk_entry_get_text_length:
7069 * @entry: a #GtkEntry
7071 * Retrieves the current length of the text in
7074 * This is equivalent to:
7076 * <informalexample><programlisting>
7077 * gtk_entry_buffer_get_length (gtk_entry_get_buffer (entry));
7078 * </programlisting></informalexample>
7080 * Return value: the current number of characters
7081 * in #GtkEntry, or 0 if there are none.
7086 gtk_entry_get_text_length (GtkEntry *entry)
7088 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7089 return gtk_entry_buffer_get_length (get_buffer (entry));
7093 * gtk_entry_set_activates_default:
7094 * @entry: a #GtkEntry
7095 * @setting: %TRUE to activate window's default widget on Enter keypress
7097 * If @setting is %TRUE, pressing Enter in the @entry will activate the default
7098 * widget for the window containing the entry. This usually means that
7099 * the dialog box containing the entry will be closed, since the default
7100 * widget is usually one of the dialog buttons.
7102 * (For experts: if @setting is %TRUE, the entry calls
7103 * gtk_window_activate_default() on the window containing the entry, in
7104 * the default handler for the #GtkWidget::activate signal.)
7107 gtk_entry_set_activates_default (GtkEntry *entry,
7110 g_return_if_fail (GTK_IS_ENTRY (entry));
7111 setting = setting != FALSE;
7113 if (setting != entry->activates_default)
7115 entry->activates_default = setting;
7116 g_object_notify (G_OBJECT (entry), "activates-default");
7121 * gtk_entry_get_activates_default:
7122 * @entry: a #GtkEntry
7124 * Retrieves the value set by gtk_entry_set_activates_default().
7126 * Return value: %TRUE if the entry will activate the default widget
7129 gtk_entry_get_activates_default (GtkEntry *entry)
7131 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7133 return entry->activates_default;
7137 * gtk_entry_set_width_chars:
7138 * @entry: a #GtkEntry
7139 * @n_chars: width in chars
7141 * Changes the size request of the entry to be about the right size
7142 * for @n_chars characters. Note that it changes the size
7143 * <emphasis>request</emphasis>, the size can still be affected by
7144 * how you pack the widget into containers. If @n_chars is -1, the
7145 * size reverts to the default entry size.
7148 gtk_entry_set_width_chars (GtkEntry *entry,
7151 g_return_if_fail (GTK_IS_ENTRY (entry));
7153 if (entry->width_chars != n_chars)
7155 entry->width_chars = n_chars;
7156 g_object_notify (G_OBJECT (entry), "width-chars");
7157 gtk_widget_queue_resize (GTK_WIDGET (entry));
7162 * gtk_entry_get_width_chars:
7163 * @entry: a #GtkEntry
7165 * Gets the value set by gtk_entry_set_width_chars().
7167 * Return value: number of chars to request space for, or negative if unset
7170 gtk_entry_get_width_chars (GtkEntry *entry)
7172 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7174 return entry->width_chars;
7178 * gtk_entry_set_has_frame:
7179 * @entry: a #GtkEntry
7180 * @setting: new value
7182 * Sets whether the entry has a beveled frame around it.
7185 gtk_entry_set_has_frame (GtkEntry *entry,
7188 g_return_if_fail (GTK_IS_ENTRY (entry));
7190 setting = (setting != FALSE);
7192 if (entry->has_frame == setting)
7195 gtk_widget_queue_resize (GTK_WIDGET (entry));
7196 entry->has_frame = setting;
7197 g_object_notify (G_OBJECT (entry), "has-frame");
7201 * gtk_entry_get_has_frame:
7202 * @entry: a #GtkEntry
7204 * Gets the value set by gtk_entry_set_has_frame().
7206 * Return value: whether the entry has a beveled frame
7209 gtk_entry_get_has_frame (GtkEntry *entry)
7211 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7213 return entry->has_frame;
7217 * gtk_entry_set_inner_border:
7218 * @entry: a #GtkEntry
7219 * @border: (allow-none): a #GtkBorder, or %NULL
7221 * Sets %entry's inner-border property to %border, or clears it if %NULL
7222 * is passed. The inner-border is the area around the entry's text, but
7225 * If set, this property overrides the inner-border style property.
7226 * Overriding the style-provided border is useful when you want to do
7227 * in-place editing of some text in a canvas or list widget, where
7228 * pixel-exact positioning of the entry is important.
7233 gtk_entry_set_inner_border (GtkEntry *entry,
7234 const GtkBorder *border)
7236 g_return_if_fail (GTK_IS_ENTRY (entry));
7238 gtk_widget_queue_resize (GTK_WIDGET (entry));
7241 g_object_set_qdata_full (G_OBJECT (entry), quark_inner_border,
7242 gtk_border_copy (border),
7243 (GDestroyNotify) gtk_border_free);
7245 g_object_set_qdata (G_OBJECT (entry), quark_inner_border, NULL);
7247 g_object_notify (G_OBJECT (entry), "inner-border");
7251 * gtk_entry_get_inner_border:
7252 * @entry: a #GtkEntry
7254 * This function returns the entry's #GtkEntry:inner-border property. See
7255 * gtk_entry_set_inner_border() for more information.
7257 * Return value: (transfer none): the entry's #GtkBorder, or %NULL if none was set.
7261 G_CONST_RETURN GtkBorder *
7262 gtk_entry_get_inner_border (GtkEntry *entry)
7264 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7266 return g_object_get_qdata (G_OBJECT (entry), quark_inner_border);
7270 * gtk_entry_get_layout:
7271 * @entry: a #GtkEntry
7273 * Gets the #PangoLayout used to display the entry.
7274 * The layout is useful to e.g. convert text positions to
7275 * pixel positions, in combination with gtk_entry_get_layout_offsets().
7276 * The returned layout is owned by the entry and must not be
7277 * modified or freed by the caller.
7279 * Keep in mind that the layout text may contain a preedit string, so
7280 * gtk_entry_layout_index_to_text_index() and
7281 * gtk_entry_text_index_to_layout_index() are needed to convert byte
7282 * indices in the layout to byte indices in the entry contents.
7284 * Return value: (transfer none): the #PangoLayout for this entry
7287 gtk_entry_get_layout (GtkEntry *entry)
7289 PangoLayout *layout;
7291 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7293 layout = gtk_entry_ensure_layout (entry, TRUE);
7300 * gtk_entry_layout_index_to_text_index:
7301 * @entry: a #GtkEntry
7302 * @layout_index: byte index into the entry layout text
7304 * Converts from a position in the entry contents (returned
7305 * by gtk_entry_get_text()) to a position in the
7306 * entry's #PangoLayout (returned by gtk_entry_get_layout(),
7307 * with text retrieved via pango_layout_get_text()).
7309 * Return value: byte index into the entry contents
7312 gtk_entry_layout_index_to_text_index (GtkEntry *entry,
7315 PangoLayout *layout;
7319 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7321 layout = gtk_entry_ensure_layout (entry, TRUE);
7322 text = pango_layout_get_text (layout);
7323 cursor_index = g_utf8_offset_to_pointer (text, entry->current_pos) - text;
7325 if (layout_index >= cursor_index && entry->preedit_length)
7327 if (layout_index >= cursor_index + entry->preedit_length)
7328 layout_index -= entry->preedit_length;
7330 layout_index = cursor_index;
7333 return layout_index;
7337 * gtk_entry_text_index_to_layout_index:
7338 * @entry: a #GtkEntry
7339 * @text_index: byte index into the entry contents
7341 * Converts from a position in the entry's #PangoLayout (returned by
7342 * gtk_entry_get_layout()) to a position in the entry contents
7343 * (returned by gtk_entry_get_text()).
7345 * Return value: byte index into the entry layout text
7348 gtk_entry_text_index_to_layout_index (GtkEntry *entry,
7351 PangoLayout *layout;
7354 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7356 layout = gtk_entry_ensure_layout (entry, TRUE);
7357 text = pango_layout_get_text (layout);
7358 cursor_index = g_utf8_offset_to_pointer (text, entry->current_pos) - text;
7360 if (text_index > cursor_index)
7361 text_index += entry->preedit_length;
7367 * gtk_entry_get_layout_offsets:
7368 * @entry: a #GtkEntry
7369 * @x: (allow-none): location to store X offset of layout, or %NULL
7370 * @y: (allow-none): location to store Y offset of layout, or %NULL
7373 * Obtains the position of the #PangoLayout used to render text
7374 * in the entry, in widget coordinates. Useful if you want to line
7375 * up the text in an entry with some other text, e.g. when using the
7376 * entry to implement editable cells in a sheet widget.
7378 * Also useful to convert mouse events into coordinates inside the
7379 * #PangoLayout, e.g. to take some action if some part of the entry text
7382 * Note that as the user scrolls around in the entry the offsets will
7383 * change; you'll need to connect to the "notify::scroll-offset"
7384 * signal to track this. Remember when using the #PangoLayout
7385 * functions you need to convert to and from pixels using
7386 * PANGO_PIXELS() or #PANGO_SCALE.
7388 * Keep in mind that the layout text may contain a preedit string, so
7389 * gtk_entry_layout_index_to_text_index() and
7390 * gtk_entry_text_index_to_layout_index() are needed to convert byte
7391 * indices in the layout to byte indices in the entry contents.
7394 gtk_entry_get_layout_offsets (GtkEntry *entry,
7398 gint text_area_x, text_area_y;
7400 g_return_if_fail (GTK_IS_ENTRY (entry));
7402 /* this gets coords relative to text area */
7403 get_layout_position (entry, x, y);
7405 /* convert to widget coords */
7406 gtk_entry_get_text_area_size (entry, &text_area_x, &text_area_y, NULL, NULL);
7417 * gtk_entry_set_alignment:
7418 * @entry: a #GtkEntry
7419 * @xalign: The horizontal alignment, from 0 (left) to 1 (right).
7420 * Reversed for RTL layouts
7422 * Sets the alignment for the contents of the entry. This controls
7423 * the horizontal positioning of the contents when the displayed
7424 * text is shorter than the width of the entry.
7429 gtk_entry_set_alignment (GtkEntry *entry, gfloat xalign)
7431 GtkEntryPrivate *priv;
7433 g_return_if_fail (GTK_IS_ENTRY (entry));
7435 priv = GTK_ENTRY_GET_PRIVATE (entry);
7439 else if (xalign > 1.0)
7442 if (xalign != priv->xalign)
7444 priv->xalign = xalign;
7446 gtk_entry_recompute (entry);
7448 g_object_notify (G_OBJECT (entry), "xalign");
7453 * gtk_entry_get_alignment:
7454 * @entry: a #GtkEntry
7456 * Gets the value set by gtk_entry_set_alignment().
7458 * Return value: the alignment
7463 gtk_entry_get_alignment (GtkEntry *entry)
7465 GtkEntryPrivate *priv;
7467 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
7469 priv = GTK_ENTRY_GET_PRIVATE (entry);
7471 return priv->xalign;
7475 * gtk_entry_set_icon_from_pixbuf:
7476 * @entry: a #GtkEntry
7477 * @icon_pos: Icon position
7478 * @pixbuf: (allow-none): A #GdkPixbuf, or %NULL
7480 * Sets the icon shown in the specified position using a pixbuf.
7482 * If @pixbuf is %NULL, no icon will be shown in the specified position.
7487 gtk_entry_set_icon_from_pixbuf (GtkEntry *entry,
7488 GtkEntryIconPosition icon_pos,
7491 GtkEntryPrivate *priv;
7492 EntryIconInfo *icon_info;
7494 g_return_if_fail (GTK_IS_ENTRY (entry));
7495 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7497 priv = GTK_ENTRY_GET_PRIVATE (entry);
7499 if ((icon_info = priv->icons[icon_pos]) == NULL)
7500 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7502 g_object_freeze_notify (G_OBJECT (entry));
7505 g_object_ref (pixbuf);
7507 gtk_entry_clear (entry, icon_pos);
7511 icon_info->storage_type = GTK_IMAGE_PIXBUF;
7512 icon_info->pixbuf = pixbuf;
7514 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7516 g_object_notify (G_OBJECT (entry), "primary-icon-pixbuf");
7517 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7521 g_object_notify (G_OBJECT (entry), "secondary-icon-pixbuf");
7522 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7525 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7526 gdk_window_show_unraised (icon_info->window);
7529 gtk_entry_ensure_pixbuf (entry, icon_pos);
7531 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7532 gtk_widget_queue_resize (GTK_WIDGET (entry));
7534 g_object_thaw_notify (G_OBJECT (entry));
7538 * gtk_entry_set_icon_from_stock:
7539 * @entry: A #GtkEntry
7540 * @icon_pos: Icon position
7541 * @stock_id: (allow-none): The name of the stock item, or %NULL
7543 * Sets the icon shown in the entry at the specified position from
7546 * If @stock_id is %NULL, no icon will be shown in the specified position.
7551 gtk_entry_set_icon_from_stock (GtkEntry *entry,
7552 GtkEntryIconPosition icon_pos,
7553 const gchar *stock_id)
7555 GtkEntryPrivate *priv;
7556 EntryIconInfo *icon_info;
7559 g_return_if_fail (GTK_IS_ENTRY (entry));
7560 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7562 priv = GTK_ENTRY_GET_PRIVATE (entry);
7564 if ((icon_info = priv->icons[icon_pos]) == NULL)
7565 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7567 g_object_freeze_notify (G_OBJECT (entry));
7569 gtk_widget_ensure_style (GTK_WIDGET (entry));
7571 /* need to dup before clearing */
7572 new_id = g_strdup (stock_id);
7574 gtk_entry_clear (entry, icon_pos);
7578 icon_info->storage_type = GTK_IMAGE_STOCK;
7579 icon_info->stock_id = new_id;
7581 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7583 g_object_notify (G_OBJECT (entry), "primary-icon-stock");
7584 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7588 g_object_notify (G_OBJECT (entry), "secondary-icon-stock");
7589 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7592 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7593 gdk_window_show_unraised (icon_info->window);
7596 gtk_entry_ensure_pixbuf (entry, icon_pos);
7598 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7599 gtk_widget_queue_resize (GTK_WIDGET (entry));
7601 g_object_thaw_notify (G_OBJECT (entry));
7605 * gtk_entry_set_icon_from_icon_name:
7606 * @entry: A #GtkEntry
7607 * @icon_pos: The position at which to set the icon
7608 * @icon_name: (allow-none): An icon name, or %NULL
7610 * Sets the icon shown in the entry at the specified position
7611 * from the current icon theme.
7613 * If the icon name isn't known, a "broken image" icon will be displayed
7616 * If @icon_name is %NULL, no icon will be shown in the specified position.
7621 gtk_entry_set_icon_from_icon_name (GtkEntry *entry,
7622 GtkEntryIconPosition icon_pos,
7623 const gchar *icon_name)
7625 GtkEntryPrivate *priv;
7626 EntryIconInfo *icon_info;
7629 g_return_if_fail (GTK_IS_ENTRY (entry));
7630 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7632 priv = GTK_ENTRY_GET_PRIVATE (entry);
7634 if ((icon_info = priv->icons[icon_pos]) == NULL)
7635 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7637 g_object_freeze_notify (G_OBJECT (entry));
7639 gtk_widget_ensure_style (GTK_WIDGET (entry));
7641 /* need to dup before clearing */
7642 new_name = g_strdup (icon_name);
7644 gtk_entry_clear (entry, icon_pos);
7646 if (new_name != NULL)
7648 icon_info->storage_type = GTK_IMAGE_ICON_NAME;
7649 icon_info->icon_name = new_name;
7651 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7653 g_object_notify (G_OBJECT (entry), "primary-icon-name");
7654 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7658 g_object_notify (G_OBJECT (entry), "secondary-icon-name");
7659 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7662 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7663 gdk_window_show_unraised (icon_info->window);
7666 gtk_entry_ensure_pixbuf (entry, icon_pos);
7668 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7669 gtk_widget_queue_resize (GTK_WIDGET (entry));
7671 g_object_thaw_notify (G_OBJECT (entry));
7675 * gtk_entry_set_icon_from_gicon:
7676 * @entry: A #GtkEntry
7677 * @icon_pos: The position at which to set the icon
7678 * @icon: (allow-none): The icon to set, or %NULL
7680 * Sets the icon shown in the entry at the specified position
7681 * from the current icon theme.
7682 * If the icon isn't known, a "broken image" icon will be displayed
7685 * If @icon is %NULL, no icon will be shown in the specified position.
7690 gtk_entry_set_icon_from_gicon (GtkEntry *entry,
7691 GtkEntryIconPosition icon_pos,
7694 GtkEntryPrivate *priv;
7695 EntryIconInfo *icon_info;
7697 g_return_if_fail (GTK_IS_ENTRY (entry));
7698 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7700 priv = GTK_ENTRY_GET_PRIVATE (entry);
7702 if ((icon_info = priv->icons[icon_pos]) == NULL)
7703 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7705 g_object_freeze_notify (G_OBJECT (entry));
7707 /* need to ref before clearing */
7709 g_object_ref (icon);
7711 gtk_entry_clear (entry, icon_pos);
7715 icon_info->storage_type = GTK_IMAGE_GICON;
7716 icon_info->gicon = icon;
7718 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7720 g_object_notify (G_OBJECT (entry), "primary-icon-gicon");
7721 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7725 g_object_notify (G_OBJECT (entry), "secondary-icon-gicon");
7726 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7729 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7730 gdk_window_show_unraised (icon_info->window);
7733 gtk_entry_ensure_pixbuf (entry, icon_pos);
7735 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7736 gtk_widget_queue_resize (GTK_WIDGET (entry));
7738 g_object_thaw_notify (G_OBJECT (entry));
7742 * gtk_entry_set_icon_activatable:
7743 * @entry: A #GtkEntry
7744 * @icon_pos: Icon position
7745 * @activatable: %TRUE if the icon should be activatable
7747 * Sets whether the icon is activatable.
7752 gtk_entry_set_icon_activatable (GtkEntry *entry,
7753 GtkEntryIconPosition icon_pos,
7754 gboolean activatable)
7756 GtkEntryPrivate *priv;
7757 EntryIconInfo *icon_info;
7759 g_return_if_fail (GTK_IS_ENTRY (entry));
7760 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7762 priv = GTK_ENTRY_GET_PRIVATE (entry);
7764 if ((icon_info = priv->icons[icon_pos]) == NULL)
7765 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7767 activatable = activatable != FALSE;
7769 if (icon_info->nonactivatable != !activatable)
7771 icon_info->nonactivatable = !activatable;
7773 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
7774 update_cursors (GTK_WIDGET (entry));
7776 g_object_notify (G_OBJECT (entry),
7777 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-activatable" : "secondary-icon-activatable");
7782 * gtk_entry_get_icon_activatable:
7783 * @entry: a #GtkEntry
7784 * @icon_pos: Icon position
7786 * Returns whether the icon is activatable.
7788 * Returns: %TRUE if the icon is activatable.
7793 gtk_entry_get_icon_activatable (GtkEntry *entry,
7794 GtkEntryIconPosition icon_pos)
7796 GtkEntryPrivate *priv;
7797 EntryIconInfo *icon_info;
7799 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7800 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), FALSE);
7802 priv = GTK_ENTRY_GET_PRIVATE (entry);
7803 icon_info = priv->icons[icon_pos];
7805 return (icon_info != NULL && !icon_info->nonactivatable);
7809 * gtk_entry_get_icon_pixbuf:
7810 * @entry: A #GtkEntry
7811 * @icon_pos: Icon position
7813 * Retrieves the image used for the icon.
7815 * Unlike the other methods of setting and getting icon data, this
7816 * method will work regardless of whether the icon was set using a
7817 * #GdkPixbuf, a #GIcon, a stock item, or an icon name.
7819 * Returns: (transfer none): A #GdkPixbuf, or %NULL if no icon is
7820 * set for this position.
7825 gtk_entry_get_icon_pixbuf (GtkEntry *entry,
7826 GtkEntryIconPosition icon_pos)
7828 GtkEntryPrivate *priv;
7829 EntryIconInfo *icon_info;
7831 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7832 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7834 priv = GTK_ENTRY_GET_PRIVATE (entry);
7835 icon_info = priv->icons[icon_pos];
7840 gtk_entry_ensure_pixbuf (entry, icon_pos);
7842 return icon_info->pixbuf;
7846 * gtk_entry_get_icon_gicon:
7847 * @entry: A #GtkEntry
7848 * @icon_pos: Icon position
7850 * Retrieves the #GIcon used for the icon, or %NULL if there is
7851 * no icon or if the icon was set by some other method (e.g., by
7852 * stock, pixbuf, or icon name).
7854 * Returns: (transfer none): A #GIcon, or %NULL if no icon is set
7855 * or if the icon is not a #GIcon
7860 gtk_entry_get_icon_gicon (GtkEntry *entry,
7861 GtkEntryIconPosition icon_pos)
7863 GtkEntryPrivate *priv;
7864 EntryIconInfo *icon_info;
7866 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7867 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7869 priv = GTK_ENTRY_GET_PRIVATE (entry);
7870 icon_info = priv->icons[icon_pos];
7875 return icon_info->storage_type == GTK_IMAGE_GICON ? icon_info->gicon : NULL;
7879 * gtk_entry_get_icon_stock:
7880 * @entry: A #GtkEntry
7881 * @icon_pos: Icon position
7883 * Retrieves the stock id used for the icon, or %NULL if there is
7884 * no icon or if the icon was set by some other method (e.g., by
7885 * pixbuf, icon name or gicon).
7887 * Returns: A stock id, or %NULL if no icon is set or if the icon
7888 * wasn't set from a stock id
7893 gtk_entry_get_icon_stock (GtkEntry *entry,
7894 GtkEntryIconPosition icon_pos)
7896 GtkEntryPrivate *priv;
7897 EntryIconInfo *icon_info;
7899 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7900 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7902 priv = GTK_ENTRY_GET_PRIVATE (entry);
7903 icon_info = priv->icons[icon_pos];
7908 return icon_info->storage_type == GTK_IMAGE_STOCK ? icon_info->stock_id : NULL;
7912 * gtk_entry_get_icon_name:
7913 * @entry: A #GtkEntry
7914 * @icon_pos: Icon position
7916 * Retrieves the icon name used for the icon, or %NULL if there is
7917 * no icon or if the icon was set by some other method (e.g., by
7918 * pixbuf, stock or gicon).
7920 * Returns: An icon name, or %NULL if no icon is set or if the icon
7921 * wasn't set from an icon name
7926 gtk_entry_get_icon_name (GtkEntry *entry,
7927 GtkEntryIconPosition icon_pos)
7929 GtkEntryPrivate *priv;
7930 EntryIconInfo *icon_info;
7932 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7933 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7935 priv = GTK_ENTRY_GET_PRIVATE (entry);
7936 icon_info = priv->icons[icon_pos];
7941 return icon_info->storage_type == GTK_IMAGE_ICON_NAME ? icon_info->icon_name : NULL;
7945 * gtk_entry_set_icon_sensitive:
7946 * @entry: A #GtkEntry
7947 * @icon_pos: Icon position
7948 * @sensitive: Specifies whether the icon should appear
7949 * sensitive or insensitive
7951 * Sets the sensitivity for the specified icon.
7956 gtk_entry_set_icon_sensitive (GtkEntry *entry,
7957 GtkEntryIconPosition icon_pos,
7960 GtkEntryPrivate *priv;
7961 EntryIconInfo *icon_info;
7963 g_return_if_fail (GTK_IS_ENTRY (entry));
7964 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7966 priv = GTK_ENTRY_GET_PRIVATE (entry);
7968 if ((icon_info = priv->icons[icon_pos]) == NULL)
7969 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7971 if (icon_info->insensitive != !sensitive)
7973 icon_info->insensitive = !sensitive;
7975 icon_info->pressed = FALSE;
7976 icon_info->prelight = FALSE;
7978 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
7979 update_cursors (GTK_WIDGET (entry));
7981 gtk_widget_queue_draw (GTK_WIDGET (entry));
7983 g_object_notify (G_OBJECT (entry),
7984 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-sensitive" : "secondary-icon-sensitive");
7989 * gtk_entry_get_icon_sensitive:
7990 * @entry: a #GtkEntry
7991 * @icon_pos: Icon position
7993 * Returns whether the icon appears sensitive or insensitive.
7995 * Returns: %TRUE if the icon is sensitive.
8000 gtk_entry_get_icon_sensitive (GtkEntry *entry,
8001 GtkEntryIconPosition icon_pos)
8003 GtkEntryPrivate *priv;
8004 EntryIconInfo *icon_info;
8006 g_return_val_if_fail (GTK_IS_ENTRY (entry), TRUE);
8007 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), TRUE);
8009 priv = GTK_ENTRY_GET_PRIVATE (entry);
8010 icon_info = priv->icons[icon_pos];
8012 return (!icon_info || !icon_info->insensitive);
8017 * gtk_entry_get_icon_storage_type:
8018 * @entry: a #GtkEntry
8019 * @icon_pos: Icon position
8021 * Gets the type of representation being used by the icon
8022 * to store image data. If the icon has no image data,
8023 * the return value will be %GTK_IMAGE_EMPTY.
8025 * Return value: image representation being used
8030 gtk_entry_get_icon_storage_type (GtkEntry *entry,
8031 GtkEntryIconPosition icon_pos)
8033 GtkEntryPrivate *priv;
8034 EntryIconInfo *icon_info;
8036 g_return_val_if_fail (GTK_IS_ENTRY (entry), GTK_IMAGE_EMPTY);
8037 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), GTK_IMAGE_EMPTY);
8039 priv = GTK_ENTRY_GET_PRIVATE (entry);
8040 icon_info = priv->icons[icon_pos];
8043 return GTK_IMAGE_EMPTY;
8045 return icon_info->storage_type;
8049 * gtk_entry_get_icon_at_pos:
8050 * @entry: a #GtkEntry
8051 * @x: the x coordinate of the position to find
8052 * @y: the y coordinate of the position to find
8054 * Finds the icon at the given position and return its index.
8055 * If @x, @y doesn't lie inside an icon, -1 is returned.
8056 * This function is intended for use in a #GtkWidget::query-tooltip
8059 * Returns: the index of the icon at the given position, or -1
8064 gtk_entry_get_icon_at_pos (GtkEntry *entry,
8068 GtkAllocation primary;
8069 GtkAllocation secondary;
8071 g_return_val_if_fail (GTK_IS_ENTRY (entry), -1);
8073 get_icon_allocations (entry, &primary, &secondary);
8075 if (primary.x <= x && x < primary.x + primary.width &&
8076 primary.y <= y && y < primary.y + primary.height)
8077 return GTK_ENTRY_ICON_PRIMARY;
8079 if (secondary.x <= x && x < secondary.x + secondary.width &&
8080 secondary.y <= y && y < secondary.y + secondary.height)
8081 return GTK_ENTRY_ICON_SECONDARY;
8087 * gtk_entry_set_icon_drag_source:
8088 * @entry: a #GtkIconEntry
8089 * @icon_pos: icon position
8090 * @target_list: the targets (data formats) in which the data can be provided
8091 * @actions: a bitmask of the allowed drag actions
8093 * Sets up the icon at the given position so that GTK+ will start a drag
8094 * operation when the user clicks and drags the icon.
8096 * To handle the drag operation, you need to connect to the usual
8097 * #GtkWidget::drag-data-get (or possibly #GtkWidget::drag-data-delete)
8098 * signal, and use gtk_entry_get_current_icon_drag_source() in
8099 * your signal handler to find out if the drag was started from
8102 * By default, GTK+ uses the icon as the drag icon. You can use the
8103 * #GtkWidget::drag-begin signal to set a different icon. Note that you
8104 * have to use g_signal_connect_after() to ensure that your signal handler
8105 * gets executed after the default handler.
8110 gtk_entry_set_icon_drag_source (GtkEntry *entry,
8111 GtkEntryIconPosition icon_pos,
8112 GtkTargetList *target_list,
8113 GdkDragAction actions)
8115 GtkEntryPrivate *priv;
8116 EntryIconInfo *icon_info;
8118 g_return_if_fail (GTK_IS_ENTRY (entry));
8119 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8121 priv = GTK_ENTRY_GET_PRIVATE (entry);
8123 if ((icon_info = priv->icons[icon_pos]) == NULL)
8124 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8126 if (icon_info->target_list)
8127 gtk_target_list_unref (icon_info->target_list);
8128 icon_info->target_list = target_list;
8129 if (icon_info->target_list)
8130 gtk_target_list_ref (icon_info->target_list);
8132 icon_info->actions = actions;
8136 * gtk_entry_get_current_icon_drag_source:
8137 * @entry: a #GtkIconEntry
8139 * Returns the index of the icon which is the source of the current
8140 * DND operation, or -1.
8142 * This function is meant to be used in a #GtkWidget::drag-data-get
8145 * Returns: index of the icon which is the source of the current
8146 * DND operation, or -1.
8151 gtk_entry_get_current_icon_drag_source (GtkEntry *entry)
8153 GtkEntryPrivate *priv;
8154 EntryIconInfo *icon_info = NULL;
8157 g_return_val_if_fail (GTK_IS_ENTRY (entry), -1);
8159 priv = GTK_ENTRY_GET_PRIVATE (entry);
8161 for (i = 0; i < MAX_ICONS; i++)
8163 if ((icon_info = priv->icons[i]))
8165 if (icon_info->in_drag)
8174 * gtk_entry_get_icon_window:
8175 * @entry: A #GtkEntry
8176 * @icon_pos: Icon position
8178 * Returns the #GdkWindow which contains the entry's icon at
8179 * @icon_pos. This function is useful when drawing something to the
8180 * entry in an expose-event callback because it enables the callback
8181 * to distinguish between the text window and entry's icon windows.
8183 * See also gtk_entry_get_text_window().
8185 * Return value: (transfer none): the entry's icon window at @icon_pos.
8190 gtk_entry_get_icon_window (GtkEntry *entry,
8191 GtkEntryIconPosition icon_pos)
8193 GtkEntryPrivate *priv;
8194 EntryIconInfo *icon_info;
8196 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8198 priv = GTK_ENTRY_GET_PRIVATE (entry);
8200 icon_info = priv->icons[icon_pos];
8203 return icon_info->window;
8209 ensure_has_tooltip (GtkEntry *entry)
8211 GtkEntryPrivate *priv;
8212 EntryIconInfo *icon_info;
8214 gboolean has_tooltip = FALSE;
8216 priv = GTK_ENTRY_GET_PRIVATE (entry);
8218 for (i = 0; i < MAX_ICONS; i++)
8220 if ((icon_info = priv->icons[i]) != NULL)
8222 if (icon_info->tooltip != NULL)
8230 gtk_widget_set_has_tooltip (GTK_WIDGET (entry), has_tooltip);
8234 * gtk_entry_get_icon_tooltip_text:
8235 * @entry: a #GtkEntry
8236 * @icon_pos: the icon position
8238 * Gets the contents of the tooltip on the icon at the specified
8239 * position in @entry.
8241 * Returns: the tooltip text, or %NULL. Free the returned string
8242 * with g_free() when done.
8247 gtk_entry_get_icon_tooltip_text (GtkEntry *entry,
8248 GtkEntryIconPosition icon_pos)
8250 GtkEntryPrivate *priv;
8251 EntryIconInfo *icon_info;
8254 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8255 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8257 priv = GTK_ENTRY_GET_PRIVATE (entry);
8258 icon_info = priv->icons[icon_pos];
8263 if (icon_info->tooltip &&
8264 !pango_parse_markup (icon_info->tooltip, -1, 0, NULL, &text, NULL, NULL))
8265 g_assert (NULL == text); /* text should still be NULL in case of markup errors */
8271 * gtk_entry_set_icon_tooltip_text:
8272 * @entry: a #GtkEntry
8273 * @icon_pos: the icon position
8274 * @tooltip: (allow-none): the contents of the tooltip for the icon, or %NULL
8276 * Sets @tooltip as the contents of the tooltip for the icon
8277 * at the specified position.
8279 * Use %NULL for @tooltip to remove an existing tooltip.
8281 * See also gtk_widget_set_tooltip_text() and
8282 * gtk_entry_set_icon_tooltip_markup().
8287 gtk_entry_set_icon_tooltip_text (GtkEntry *entry,
8288 GtkEntryIconPosition icon_pos,
8289 const gchar *tooltip)
8291 GtkEntryPrivate *priv;
8292 EntryIconInfo *icon_info;
8294 g_return_if_fail (GTK_IS_ENTRY (entry));
8295 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8297 priv = GTK_ENTRY_GET_PRIVATE (entry);
8299 if (!(icon_info = priv->icons[icon_pos]))
8300 icon_info = priv->icons[icon_pos];
8302 if (icon_info->tooltip)
8303 g_free (icon_info->tooltip);
8305 /* Treat an empty string as a NULL string,
8306 * because an empty string would be useless for a tooltip:
8308 if (tooltip && tooltip[0] == '\0')
8311 icon_info->tooltip = tooltip ? g_markup_escape_text (tooltip, -1) : NULL;
8313 ensure_has_tooltip (entry);
8317 * gtk_entry_get_icon_tooltip_markup:
8318 * @entry: a #GtkEntry
8319 * @icon_pos: the icon position
8321 * Gets the contents of the tooltip on the icon at the specified
8322 * position in @entry.
8324 * Returns: the tooltip text, or %NULL. Free the returned string
8325 * with g_free() when done.
8330 gtk_entry_get_icon_tooltip_markup (GtkEntry *entry,
8331 GtkEntryIconPosition icon_pos)
8333 GtkEntryPrivate *priv;
8334 EntryIconInfo *icon_info;
8336 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8337 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8339 priv = GTK_ENTRY_GET_PRIVATE (entry);
8340 icon_info = priv->icons[icon_pos];
8345 return g_strdup (icon_info->tooltip);
8349 * gtk_entry_set_icon_tooltip_markup:
8350 * @entry: a #GtkEntry
8351 * @icon_pos: the icon position
8352 * @tooltip: (allow-none): the contents of the tooltip for the icon, or %NULL
8354 * Sets @tooltip as the contents of the tooltip for the icon at
8355 * the specified position. @tooltip is assumed to be marked up with
8356 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
8358 * Use %NULL for @tooltip to remove an existing tooltip.
8360 * See also gtk_widget_set_tooltip_markup() and
8361 * gtk_enty_set_icon_tooltip_text().
8366 gtk_entry_set_icon_tooltip_markup (GtkEntry *entry,
8367 GtkEntryIconPosition icon_pos,
8368 const gchar *tooltip)
8370 GtkEntryPrivate *priv;
8371 EntryIconInfo *icon_info;
8373 g_return_if_fail (GTK_IS_ENTRY (entry));
8374 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8376 priv = GTK_ENTRY_GET_PRIVATE (entry);
8378 if (!(icon_info = priv->icons[icon_pos]))
8379 icon_info = priv->icons[icon_pos];
8381 if (icon_info->tooltip)
8382 g_free (icon_info->tooltip);
8384 /* Treat an empty string as a NULL string,
8385 * because an empty string would be useless for a tooltip:
8387 if (tooltip && tooltip[0] == '\0')
8390 icon_info->tooltip = g_strdup (tooltip);
8392 ensure_has_tooltip (entry);
8396 gtk_entry_query_tooltip (GtkWidget *widget,
8399 gboolean keyboard_tip,
8400 GtkTooltip *tooltip)
8403 GtkEntryPrivate *priv;
8404 EntryIconInfo *icon_info;
8407 entry = GTK_ENTRY (widget);
8408 priv = GTK_ENTRY_GET_PRIVATE (entry);
8412 icon_pos = gtk_entry_get_icon_at_pos (entry, x, y);
8415 if ((icon_info = priv->icons[icon_pos]) != NULL)
8417 if (icon_info->tooltip)
8419 gtk_tooltip_set_markup (tooltip, icon_info->tooltip);
8428 return GTK_WIDGET_CLASS (gtk_entry_parent_class)->query_tooltip (widget,
8435 /* Quick hack of a popup menu
8438 activate_cb (GtkWidget *menuitem,
8441 const gchar *signal = g_object_get_data (G_OBJECT (menuitem), "gtk-signal");
8442 g_signal_emit_by_name (entry, signal);
8447 gtk_entry_mnemonic_activate (GtkWidget *widget,
8448 gboolean group_cycling)
8450 gtk_widget_grab_focus (widget);
8455 append_action_signal (GtkEntry *entry,
8457 const gchar *stock_id,
8458 const gchar *signal,
8461 GtkWidget *menuitem = gtk_image_menu_item_new_from_stock (stock_id, NULL);
8463 g_object_set_data (G_OBJECT (menuitem), I_("gtk-signal"), (char *)signal);
8464 g_signal_connect (menuitem, "activate",
8465 G_CALLBACK (activate_cb), entry);
8467 gtk_widget_set_sensitive (menuitem, sensitive);
8469 gtk_widget_show (menuitem);
8470 gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
8474 popup_menu_detach (GtkWidget *attach_widget,
8477 GTK_ENTRY (attach_widget)->popup_menu = NULL;
8481 popup_position_func (GtkMenu *menu,
8487 GtkEntry *entry = GTK_ENTRY (user_data);
8488 GtkWidget *widget = GTK_WIDGET (entry);
8490 GtkRequisition menu_req;
8491 GdkRectangle monitor;
8492 GtkBorder inner_border;
8493 gint monitor_num, strong_x, height;
8495 g_return_if_fail (gtk_widget_get_realized (widget));
8497 gdk_window_get_origin (entry->text_area, x, y);
8499 screen = gtk_widget_get_screen (widget);
8500 monitor_num = gdk_screen_get_monitor_at_window (screen, entry->text_area);
8501 if (monitor_num < 0)
8503 gtk_menu_set_monitor (menu, monitor_num);
8505 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
8506 gtk_size_request_get_size (GTK_SIZE_REQUEST (entry->popup_menu),
8508 gdk_drawable_get_size (entry->text_area, NULL, &height);
8509 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
8510 _gtk_entry_effective_inner_border (entry, &inner_border);
8512 *x += inner_border.left + strong_x - entry->scroll_offset;
8513 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
8514 *x -= menu_req.width;
8516 if ((*y + height + menu_req.height) <= monitor.y + monitor.height)
8518 else if ((*y - menu_req.height) >= monitor.y)
8519 *y -= menu_req.height;
8520 else if (monitor.y + monitor.height - (*y + height) > *y)
8523 *y -= menu_req.height;
8529 unichar_chosen_func (const char *text,
8532 GtkEntry *entry = GTK_ENTRY (data);
8534 if (entry->editable)
8535 gtk_entry_enter_text (entry, text);
8546 popup_targets_received (GtkClipboard *clipboard,
8547 GtkSelectionData *data,
8550 PopupInfo *info = user_data;
8551 GtkEntry *entry = info->entry;
8553 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
8556 gboolean clipboard_contains_text;
8557 GtkWidget *menuitem;
8559 gboolean show_input_method_menu;
8560 gboolean show_unicode_menu;
8562 clipboard_contains_text = gtk_selection_data_targets_include_text (data);
8563 if (entry->popup_menu)
8564 gtk_widget_destroy (entry->popup_menu);
8566 entry->popup_menu = gtk_menu_new ();
8568 gtk_menu_attach_to_widget (GTK_MENU (entry->popup_menu),
8572 mode = gtk_entry_get_display_mode (entry);
8573 append_action_signal (entry, entry->popup_menu, GTK_STOCK_CUT, "cut-clipboard",
8574 entry->editable && mode == DISPLAY_NORMAL &&
8575 entry->current_pos != entry->selection_bound);
8577 append_action_signal (entry, entry->popup_menu, GTK_STOCK_COPY, "copy-clipboard",
8578 mode == DISPLAY_NORMAL &&
8579 entry->current_pos != entry->selection_bound);
8581 append_action_signal (entry, entry->popup_menu, GTK_STOCK_PASTE, "paste-clipboard",
8582 entry->editable && clipboard_contains_text);
8584 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_DELETE, NULL);
8585 gtk_widget_set_sensitive (menuitem, entry->editable && entry->current_pos != entry->selection_bound);
8586 g_signal_connect_swapped (menuitem, "activate",
8587 G_CALLBACK (gtk_entry_delete_cb), entry);
8588 gtk_widget_show (menuitem);
8589 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8591 menuitem = gtk_separator_menu_item_new ();
8592 gtk_widget_show (menuitem);
8593 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8595 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_SELECT_ALL, NULL);
8596 g_signal_connect_swapped (menuitem, "activate",
8597 G_CALLBACK (gtk_entry_select_all), entry);
8598 gtk_widget_show (menuitem);
8599 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8601 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
8602 "gtk-show-input-method-menu", &show_input_method_menu,
8603 "gtk-show-unicode-menu", &show_unicode_menu,
8606 if (show_input_method_menu || show_unicode_menu)
8608 menuitem = gtk_separator_menu_item_new ();
8609 gtk_widget_show (menuitem);
8610 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8613 if (show_input_method_menu)
8615 menuitem = gtk_menu_item_new_with_mnemonic (_("Input _Methods"));
8616 gtk_widget_set_sensitive (menuitem, entry->editable);
8617 gtk_widget_show (menuitem);
8618 submenu = gtk_menu_new ();
8619 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
8621 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8623 gtk_im_multicontext_append_menuitems (GTK_IM_MULTICONTEXT (entry->im_context),
8624 GTK_MENU_SHELL (submenu));
8627 if (show_unicode_menu)
8629 menuitem = gtk_menu_item_new_with_mnemonic (_("_Insert Unicode Control Character"));
8630 gtk_widget_set_sensitive (menuitem, entry->editable);
8631 gtk_widget_show (menuitem);
8633 submenu = gtk_menu_new ();
8634 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
8635 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8637 _gtk_text_util_append_special_char_menuitems (GTK_MENU_SHELL (submenu),
8638 unichar_chosen_func,
8642 g_signal_emit (entry,
8643 signals[POPULATE_POPUP],
8649 gtk_menu_popup (GTK_MENU (entry->popup_menu), NULL, NULL,
8651 info->button, info->time);
8654 gtk_menu_popup (GTK_MENU (entry->popup_menu), NULL, NULL,
8655 popup_position_func, entry,
8656 info->button, info->time);
8657 gtk_menu_shell_select_first (GTK_MENU_SHELL (entry->popup_menu), FALSE);
8661 g_object_unref (entry);
8662 g_slice_free (PopupInfo, info);
8666 gtk_entry_do_popup (GtkEntry *entry,
8667 GdkEventButton *event)
8669 PopupInfo *info = g_slice_new (PopupInfo);
8671 /* In order to know what entries we should make sensitive, we
8672 * ask for the current targets of the clipboard, and when
8673 * we get them, then we actually pop up the menu.
8675 info->entry = g_object_ref (entry);
8679 info->button = event->button;
8680 info->time = event->time;
8685 info->time = gtk_get_current_event_time ();
8688 gtk_clipboard_request_contents (gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_CLIPBOARD),
8689 gdk_atom_intern_static_string ("TARGETS"),
8690 popup_targets_received,
8695 gtk_entry_popup_menu (GtkWidget *widget)
8697 gtk_entry_do_popup (GTK_ENTRY (widget), NULL);
8702 gtk_entry_drag_begin (GtkWidget *widget,
8703 GdkDragContext *context)
8705 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
8708 for (i = 0; i < MAX_ICONS; i++)
8710 EntryIconInfo *icon_info = priv->icons[i];
8712 if (icon_info != NULL)
8714 if (icon_info->in_drag)
8716 switch (icon_info->storage_type)
8718 case GTK_IMAGE_STOCK:
8719 gtk_drag_set_icon_stock (context, icon_info->stock_id, -2, -2);
8722 case GTK_IMAGE_ICON_NAME:
8723 gtk_drag_set_icon_name (context, icon_info->icon_name, -2, -2);
8726 /* FIXME: No GIcon support for dnd icons */
8727 case GTK_IMAGE_GICON:
8728 case GTK_IMAGE_PIXBUF:
8729 gtk_drag_set_icon_pixbuf (context, icon_info->pixbuf, -2, -2);
8732 g_assert_not_reached ();
8740 gtk_entry_drag_end (GtkWidget *widget,
8741 GdkDragContext *context)
8743 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
8746 for (i = 0; i < MAX_ICONS; i++)
8748 EntryIconInfo *icon_info = priv->icons[i];
8750 if (icon_info != NULL)
8751 icon_info->in_drag = 0;
8756 gtk_entry_drag_leave (GtkWidget *widget,
8757 GdkDragContext *context,
8760 GtkEntry *entry = GTK_ENTRY (widget);
8762 entry->dnd_position = -1;
8763 gtk_widget_queue_draw (widget);
8767 gtk_entry_drag_drop (GtkWidget *widget,
8768 GdkDragContext *context,
8773 GtkEntry *entry = GTK_ENTRY (widget);
8774 GdkAtom target = GDK_NONE;
8776 if (entry->editable)
8777 target = gtk_drag_dest_find_target (widget, context, NULL);
8779 if (target != GDK_NONE)
8780 gtk_drag_get_data (widget, context, target, time);
8782 gtk_drag_finish (context, FALSE, FALSE, time);
8788 gtk_entry_drag_motion (GtkWidget *widget,
8789 GdkDragContext *context,
8794 GtkEntry *entry = GTK_ENTRY (widget);
8796 GtkWidget *source_widget;
8797 GdkDragAction suggested_action;
8798 gint new_position, old_position;
8801 style = gtk_widget_get_style (widget);
8802 x -= style->xthickness;
8803 y -= style->ythickness;
8805 old_position = entry->dnd_position;
8806 new_position = gtk_entry_find_position (entry, x + entry->scroll_offset);
8808 if (entry->editable &&
8809 gtk_drag_dest_find_target (widget, context, NULL) != GDK_NONE)
8811 source_widget = gtk_drag_get_source_widget (context);
8812 suggested_action = context->suggested_action;
8814 if (!gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &sel1, &sel2) ||
8815 new_position < sel1 || new_position > sel2)
8817 if (source_widget == widget)
8819 /* Default to MOVE, unless the user has
8820 * pressed ctrl or alt to affect available actions
8822 if ((context->actions & GDK_ACTION_MOVE) != 0)
8823 suggested_action = GDK_ACTION_MOVE;
8826 entry->dnd_position = new_position;
8830 if (source_widget == widget)
8831 suggested_action = 0; /* Can't drop in selection where drag started */
8833 entry->dnd_position = -1;
8838 /* Entry not editable, or no text */
8839 suggested_action = 0;
8840 entry->dnd_position = -1;
8843 gdk_drag_status (context, suggested_action, time);
8845 if (entry->dnd_position != old_position)
8846 gtk_widget_queue_draw (widget);
8852 gtk_entry_drag_data_received (GtkWidget *widget,
8853 GdkDragContext *context,
8856 GtkSelectionData *selection_data,
8860 GtkEntry *entry = GTK_ENTRY (widget);
8861 GtkEditable *editable = GTK_EDITABLE (widget);
8865 str = (gchar *) gtk_selection_data_get_text (selection_data);
8867 style = gtk_widget_get_style (widget);
8868 x -= style->xthickness;
8869 y -= style->ythickness;
8871 if (str && entry->editable)
8877 if (entry->truncate_multiline)
8878 length = truncate_multiline (str);
8880 new_position = gtk_entry_find_position (entry, x + entry->scroll_offset);
8882 if (!gtk_editable_get_selection_bounds (editable, &sel1, &sel2) ||
8883 new_position < sel1 || new_position > sel2)
8885 gtk_editable_insert_text (editable, str, length, &new_position);
8889 /* Replacing selection */
8890 begin_change (entry);
8891 g_object_freeze_notify (G_OBJECT (entry));
8892 gtk_editable_delete_text (editable, sel1, sel2);
8893 gtk_editable_insert_text (editable, str, length, &sel1);
8894 g_object_thaw_notify (G_OBJECT (entry));
8898 gtk_drag_finish (context, TRUE, context->action == GDK_ACTION_MOVE, time);
8902 /* Drag and drop didn't happen! */
8903 gtk_drag_finish (context, FALSE, FALSE, time);
8910 gtk_entry_drag_data_get (GtkWidget *widget,
8911 GdkDragContext *context,
8912 GtkSelectionData *selection_data,
8916 gint sel_start, sel_end;
8919 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
8920 GtkEditable *editable = GTK_EDITABLE (widget);
8922 /* If there is an icon drag going on, exit early. */
8923 for (i = 0; i < MAX_ICONS; i++)
8925 EntryIconInfo *icon_info = priv->icons[i];
8927 if (icon_info != NULL)
8929 if (icon_info->in_drag)
8934 if (gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end))
8936 gchar *str = gtk_entry_get_display_text (GTK_ENTRY (widget), sel_start, sel_end);
8938 gtk_selection_data_set_text (selection_data, str, -1);
8946 gtk_entry_drag_data_delete (GtkWidget *widget,
8947 GdkDragContext *context)
8949 gint sel_start, sel_end;
8952 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
8953 GtkEditable *editable = GTK_EDITABLE (widget);
8955 /* If there is an icon drag going on, exit early. */
8956 for (i = 0; i < MAX_ICONS; i++)
8958 EntryIconInfo *icon_info = priv->icons[i];
8960 if (icon_info != NULL)
8962 if (icon_info->in_drag)
8967 if (GTK_ENTRY (widget)->editable &&
8968 gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end))
8969 gtk_editable_delete_text (editable, sel_start, sel_end);
8972 /* We display the cursor when
8974 * - the selection is empty, AND
8975 * - the widget has focus
8978 #define CURSOR_ON_MULTIPLIER 2
8979 #define CURSOR_OFF_MULTIPLIER 1
8980 #define CURSOR_PEND_MULTIPLIER 3
8981 #define CURSOR_DIVIDER 3
8984 cursor_blinks (GtkEntry *entry)
8986 if (gtk_widget_has_focus (GTK_WIDGET (entry)) &&
8988 entry->selection_bound == entry->current_pos)
8990 GtkSettings *settings;
8993 settings = gtk_widget_get_settings (GTK_WIDGET (entry));
8994 g_object_get (settings, "gtk-cursor-blink", &blink, NULL);
9003 get_cursor_time (GtkEntry *entry)
9005 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9008 g_object_get (settings, "gtk-cursor-blink-time", &time, NULL);
9014 get_cursor_blink_timeout (GtkEntry *entry)
9016 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9019 g_object_get (settings, "gtk-cursor-blink-timeout", &timeout, NULL);
9025 show_cursor (GtkEntry *entry)
9029 if (!entry->cursor_visible)
9031 entry->cursor_visible = TRUE;
9033 widget = GTK_WIDGET (entry);
9034 if (gtk_widget_has_focus (widget) && entry->selection_bound == entry->current_pos)
9035 gtk_widget_queue_draw (widget);
9040 hide_cursor (GtkEntry *entry)
9044 if (entry->cursor_visible)
9046 entry->cursor_visible = FALSE;
9048 widget = GTK_WIDGET (entry);
9049 if (gtk_widget_has_focus (widget) && entry->selection_bound == entry->current_pos)
9050 gtk_widget_queue_draw (widget);
9058 blink_cb (gpointer data)
9061 GtkEntryPrivate *priv;
9064 entry = GTK_ENTRY (data);
9065 priv = GTK_ENTRY_GET_PRIVATE (entry);
9067 if (!gtk_widget_has_focus (GTK_WIDGET (entry)))
9069 g_warning ("GtkEntry - did not receive focus-out-event. If you\n"
9070 "connect a handler to this signal, it must return\n"
9071 "FALSE so the entry gets the event as well");
9073 gtk_entry_check_cursor_blink (entry);
9078 g_assert (entry->selection_bound == entry->current_pos);
9080 blink_timeout = get_cursor_blink_timeout (entry);
9081 if (priv->blink_time > 1000 * blink_timeout &&
9082 blink_timeout < G_MAXINT/1000)
9084 /* we've blinked enough without the user doing anything, stop blinking */
9085 show_cursor (entry);
9086 entry->blink_timeout = 0;
9088 else if (entry->cursor_visible)
9090 hide_cursor (entry);
9091 entry->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_OFF_MULTIPLIER / CURSOR_DIVIDER,
9097 show_cursor (entry);
9098 priv->blink_time += get_cursor_time (entry);
9099 entry->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
9104 /* Remove ourselves */
9109 gtk_entry_check_cursor_blink (GtkEntry *entry)
9111 GtkEntryPrivate *priv;
9113 priv = GTK_ENTRY_GET_PRIVATE (entry);
9115 if (cursor_blinks (entry))
9117 if (!entry->blink_timeout)
9119 show_cursor (entry);
9120 entry->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
9127 if (entry->blink_timeout)
9129 g_source_remove (entry->blink_timeout);
9130 entry->blink_timeout = 0;
9133 entry->cursor_visible = TRUE;
9139 gtk_entry_pend_cursor_blink (GtkEntry *entry)
9141 if (cursor_blinks (entry))
9143 if (entry->blink_timeout != 0)
9144 g_source_remove (entry->blink_timeout);
9146 entry->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_PEND_MULTIPLIER / CURSOR_DIVIDER,
9149 show_cursor (entry);
9154 gtk_entry_reset_blink_time (GtkEntry *entry)
9156 GtkEntryPrivate *priv;
9158 priv = GTK_ENTRY_GET_PRIVATE (entry);
9160 priv->blink_time = 0;
9166 gtk_entry_completion_timeout (gpointer data)
9168 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (data);
9169 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (completion->priv->entry);
9171 completion->priv->completion_timeout = 0;
9173 if (completion->priv->filter_model &&
9174 g_utf8_strlen (gtk_entry_get_text (GTK_ENTRY (completion->priv->entry)), -1)
9175 >= completion->priv->minimum_key_length)
9179 GtkTreeSelection *s;
9180 gboolean popup_single;
9182 gtk_entry_completion_complete (completion);
9183 matches = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->filter_model), NULL);
9185 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9187 s = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view));
9189 gtk_tree_selection_unselect_all (s);
9191 actions = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->actions), NULL);
9193 g_object_get (completion, "popup-single-match", &popup_single, NULL);
9194 if ((matches > (popup_single ? 0: 1)) || actions > 0)
9196 if (gtk_widget_get_visible (completion->priv->popup_window))
9197 _gtk_entry_completion_resize_popup (completion);
9199 _gtk_entry_completion_popup (completion, priv->completion_device);
9202 _gtk_entry_completion_popdown (completion);
9204 else if (gtk_widget_get_visible (completion->priv->popup_window))
9205 _gtk_entry_completion_popdown (completion);
9210 static inline gboolean
9211 keyval_is_cursor_move (guint keyval)
9213 if (keyval == GDK_KEY_Up || keyval == GDK_KEY_KP_Up)
9216 if (keyval == GDK_KEY_Down || keyval == GDK_KEY_KP_Down)
9219 if (keyval == GDK_KEY_Page_Up)
9222 if (keyval == GDK_KEY_Page_Down)
9229 gtk_entry_completion_key_press (GtkWidget *widget,
9233 gint matches, actions = 0;
9234 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
9236 if (!gtk_widget_get_mapped (completion->priv->popup_window))
9239 matches = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->filter_model), NULL);
9241 if (completion->priv->actions)
9242 actions = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->actions), NULL);
9244 if (keyval_is_cursor_move (event->keyval))
9246 GtkTreePath *path = NULL;
9248 if (event->keyval == GDK_KEY_Up || event->keyval == GDK_KEY_KP_Up)
9250 if (completion->priv->current_selected < 0)
9251 completion->priv->current_selected = matches + actions - 1;
9253 completion->priv->current_selected--;
9255 else if (event->keyval == GDK_KEY_Down || event->keyval == GDK_KEY_KP_Down)
9257 if (completion->priv->current_selected < matches + actions - 1)
9258 completion->priv->current_selected++;
9260 completion->priv->current_selected = -1;
9262 else if (event->keyval == GDK_KEY_Page_Up)
9264 if (completion->priv->current_selected < 0)
9265 completion->priv->current_selected = matches + actions - 1;
9266 else if (completion->priv->current_selected == 0)
9267 completion->priv->current_selected = -1;
9268 else if (completion->priv->current_selected < matches)
9270 completion->priv->current_selected -= 14;
9271 if (completion->priv->current_selected < 0)
9272 completion->priv->current_selected = 0;
9276 completion->priv->current_selected -= 14;
9277 if (completion->priv->current_selected < matches - 1)
9278 completion->priv->current_selected = matches - 1;
9281 else if (event->keyval == GDK_KEY_Page_Down)
9283 if (completion->priv->current_selected < 0)
9284 completion->priv->current_selected = 0;
9285 else if (completion->priv->current_selected < matches - 1)
9287 completion->priv->current_selected += 14;
9288 if (completion->priv->current_selected > matches - 1)
9289 completion->priv->current_selected = matches - 1;
9291 else if (completion->priv->current_selected == matches + actions - 1)
9293 completion->priv->current_selected = -1;
9297 completion->priv->current_selected += 14;
9298 if (completion->priv->current_selected > matches + actions - 1)
9299 completion->priv->current_selected = matches + actions - 1;
9303 if (completion->priv->current_selected < 0)
9305 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9306 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view)));
9308 if (completion->priv->inline_selection &&
9309 completion->priv->completion_prefix)
9311 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9312 completion->priv->completion_prefix);
9313 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9316 else if (completion->priv->current_selected < matches)
9318 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view)));
9320 path = gtk_tree_path_new_from_indices (completion->priv->current_selected, -1);
9321 gtk_tree_view_set_cursor (GTK_TREE_VIEW (completion->priv->tree_view),
9324 if (completion->priv->inline_selection)
9328 GtkTreeIter child_iter;
9329 GtkTreeModel *model = NULL;
9330 GtkTreeSelection *sel;
9333 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view));
9334 if (!gtk_tree_selection_get_selected (sel, &model, &iter))
9337 gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (model), &child_iter, &iter);
9338 model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model));
9340 if (completion->priv->completion_prefix == NULL)
9341 completion->priv->completion_prefix = g_strdup (gtk_entry_get_text (GTK_ENTRY (completion->priv->entry)));
9343 g_signal_emit_by_name (completion, "cursor-on-match", model,
9344 &child_iter, &entry_set);
9347 else if (completion->priv->current_selected - matches >= 0)
9349 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9351 path = gtk_tree_path_new_from_indices (completion->priv->current_selected - matches, -1);
9352 gtk_tree_view_set_cursor (GTK_TREE_VIEW (completion->priv->action_view),
9355 if (completion->priv->inline_selection &&
9356 completion->priv->completion_prefix)
9358 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9359 completion->priv->completion_prefix);
9360 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9364 gtk_tree_path_free (path);
9368 else if (event->keyval == GDK_KEY_Escape ||
9369 event->keyval == GDK_KEY_Left ||
9370 event->keyval == GDK_KEY_KP_Left ||
9371 event->keyval == GDK_KEY_Right ||
9372 event->keyval == GDK_KEY_KP_Right)
9374 gboolean retval = TRUE;
9376 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9377 _gtk_entry_completion_popdown (completion);
9379 if (completion->priv->current_selected < 0)
9382 goto keypress_completion_out;
9384 else if (completion->priv->inline_selection)
9386 /* Escape rejects the tentative completion */
9387 if (event->keyval == GDK_KEY_Escape)
9389 if (completion->priv->completion_prefix)
9390 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9391 completion->priv->completion_prefix);
9393 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry), "");
9396 /* Move the cursor to the end for Right/Esc, to the
9397 beginning for Left */
9398 if (event->keyval == GDK_KEY_Right ||
9399 event->keyval == GDK_KEY_KP_Right ||
9400 event->keyval == GDK_KEY_Escape)
9401 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9403 gtk_editable_set_position (GTK_EDITABLE (widget), 0);
9406 keypress_completion_out:
9407 if (completion->priv->inline_selection)
9409 g_free (completion->priv->completion_prefix);
9410 completion->priv->completion_prefix = NULL;
9415 else if (event->keyval == GDK_KEY_Tab ||
9416 event->keyval == GDK_KEY_KP_Tab ||
9417 event->keyval == GDK_KEY_ISO_Left_Tab)
9419 GtkDirectionType dir = event->keyval == GDK_KEY_ISO_Left_Tab ?
9420 GTK_DIR_TAB_BACKWARD : GTK_DIR_TAB_FORWARD;
9422 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9423 _gtk_entry_completion_popdown (completion);
9425 g_free (completion->priv->completion_prefix);
9426 completion->priv->completion_prefix = NULL;
9428 gtk_widget_child_focus (gtk_widget_get_toplevel (widget), dir);
9432 else if (event->keyval == GDK_KEY_ISO_Enter ||
9433 event->keyval == GDK_KEY_KP_Enter ||
9434 event->keyval == GDK_KEY_Return)
9437 GtkTreeModel *model = NULL;
9438 GtkTreeSelection *sel;
9439 gboolean retval = TRUE;
9441 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9442 _gtk_entry_completion_popdown (completion);
9444 if (completion->priv->current_selected < matches)
9448 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view));
9449 if (gtk_tree_selection_get_selected (sel, &model, &iter))
9451 g_signal_handler_block (widget, completion->priv->changed_id);
9452 g_signal_emit_by_name (completion, "match-selected",
9453 model, &iter, &entry_set);
9454 g_signal_handler_unblock (widget, completion->priv->changed_id);
9460 gtk_tree_model_get (model, &iter,
9461 completion->priv->text_column, &str,
9464 gtk_entry_set_text (GTK_ENTRY (widget), str);
9466 /* move the cursor to the end */
9467 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9475 else if (completion->priv->current_selected - matches >= 0)
9477 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view));
9478 if (gtk_tree_selection_get_selected (sel, &model, &iter))
9482 path = gtk_tree_path_new_from_indices (completion->priv->current_selected - matches, -1);
9483 g_signal_emit_by_name (completion, "action-activated",
9484 gtk_tree_path_get_indices (path)[0]);
9485 gtk_tree_path_free (path);
9491 g_free (completion->priv->completion_prefix);
9492 completion->priv->completion_prefix = NULL;
9501 gtk_entry_completion_changed (GtkWidget *entry,
9504 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
9505 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
9508 /* (re)install completion timeout */
9509 if (completion->priv->completion_timeout)
9510 g_source_remove (completion->priv->completion_timeout);
9512 if (!gtk_entry_get_text (GTK_ENTRY (entry)))
9515 /* no need to normalize for this test */
9516 if (completion->priv->minimum_key_length > 0 &&
9517 strcmp ("", gtk_entry_get_text (GTK_ENTRY (entry))) == 0)
9519 if (gtk_widget_get_visible (completion->priv->popup_window))
9520 _gtk_entry_completion_popdown (completion);
9524 device = gtk_get_current_event_device ();
9526 if (device && device->source == GDK_SOURCE_KEYBOARD)
9527 device = gdk_device_get_associated_device (device);
9530 priv->completion_device = device;
9532 completion->priv->completion_timeout =
9533 gdk_threads_add_timeout (COMPLETION_TIMEOUT,
9534 gtk_entry_completion_timeout,
9539 check_completion_callback (GtkEntryCompletion *completion)
9541 completion->priv->check_completion_idle = NULL;
9543 gtk_entry_completion_complete (completion);
9544 gtk_entry_completion_insert_prefix (completion);
9550 clear_completion_callback (GtkEntry *entry,
9553 if (pspec->name == I_("cursor-position") ||
9554 pspec->name == I_("selection-bound"))
9556 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
9558 completion->priv->has_completion = FALSE;
9563 accept_completion_callback (GtkEntry *entry)
9565 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
9567 if (completion->priv->has_completion)
9568 gtk_editable_set_position (GTK_EDITABLE (entry),
9569 gtk_entry_buffer_get_length (get_buffer (entry)));
9575 completion_insert_text_callback (GtkEntry *entry,
9579 GtkEntryCompletion *completion)
9581 /* idle to update the selection based on the file list */
9582 if (completion->priv->check_completion_idle == NULL)
9584 completion->priv->check_completion_idle = g_idle_source_new ();
9585 g_source_set_priority (completion->priv->check_completion_idle, G_PRIORITY_HIGH);
9586 g_source_set_closure (completion->priv->check_completion_idle,
9587 g_cclosure_new_object (G_CALLBACK (check_completion_callback),
9588 G_OBJECT (completion)));
9589 g_source_attach (completion->priv->check_completion_idle, NULL);
9594 completion_changed (GtkEntryCompletion *completion,
9598 GtkEntry *entry = GTK_ENTRY (data);
9600 if (pspec->name == I_("popup-completion") ||
9601 pspec->name == I_("inline-completion"))
9603 disconnect_completion_signals (entry, completion);
9604 connect_completion_signals (entry, completion);
9609 disconnect_completion_signals (GtkEntry *entry,
9610 GtkEntryCompletion *completion)
9612 g_signal_handlers_disconnect_by_func (completion,
9613 G_CALLBACK (completion_changed), entry);
9614 if (completion->priv->changed_id > 0 &&
9615 g_signal_handler_is_connected (entry, completion->priv->changed_id))
9617 g_signal_handler_disconnect (entry, completion->priv->changed_id);
9618 completion->priv->changed_id = 0;
9620 g_signal_handlers_disconnect_by_func (entry,
9621 G_CALLBACK (gtk_entry_completion_key_press), completion);
9622 if (completion->priv->insert_text_id > 0 &&
9623 g_signal_handler_is_connected (entry, completion->priv->insert_text_id))
9625 g_signal_handler_disconnect (entry, completion->priv->insert_text_id);
9626 completion->priv->insert_text_id = 0;
9628 g_signal_handlers_disconnect_by_func (entry,
9629 G_CALLBACK (completion_insert_text_callback), completion);
9630 g_signal_handlers_disconnect_by_func (entry,
9631 G_CALLBACK (clear_completion_callback), completion);
9632 g_signal_handlers_disconnect_by_func (entry,
9633 G_CALLBACK (accept_completion_callback), completion);
9637 connect_completion_signals (GtkEntry *entry,
9638 GtkEntryCompletion *completion)
9640 if (completion->priv->popup_completion)
9642 completion->priv->changed_id =
9643 g_signal_connect (entry, "changed",
9644 G_CALLBACK (gtk_entry_completion_changed), completion);
9645 g_signal_connect (entry, "key-press-event",
9646 G_CALLBACK (gtk_entry_completion_key_press), completion);
9649 if (completion->priv->inline_completion)
9651 completion->priv->insert_text_id =
9652 g_signal_connect (entry, "insert-text",
9653 G_CALLBACK (completion_insert_text_callback), completion);
9654 g_signal_connect (entry, "notify",
9655 G_CALLBACK (clear_completion_callback), completion);
9656 g_signal_connect (entry, "activate",
9657 G_CALLBACK (accept_completion_callback), completion);
9658 g_signal_connect (entry, "focus-out-event",
9659 G_CALLBACK (accept_completion_callback), completion);
9662 g_signal_connect (completion, "notify",
9663 G_CALLBACK (completion_changed), entry);
9667 * gtk_entry_set_completion:
9668 * @entry: A #GtkEntry
9669 * @completion: (allow-none): The #GtkEntryCompletion or %NULL
9671 * Sets @completion to be the auxiliary completion object to use with @entry.
9672 * All further configuration of the completion mechanism is done on
9673 * @completion using the #GtkEntryCompletion API. Completion is disabled if
9674 * @completion is set to %NULL.
9679 gtk_entry_set_completion (GtkEntry *entry,
9680 GtkEntryCompletion *completion)
9682 GtkEntryCompletion *old;
9684 g_return_if_fail (GTK_IS_ENTRY (entry));
9685 g_return_if_fail (!completion || GTK_IS_ENTRY_COMPLETION (completion));
9687 old = gtk_entry_get_completion (entry);
9689 if (old == completion)
9694 if (old->priv->completion_timeout)
9696 g_source_remove (old->priv->completion_timeout);
9697 old->priv->completion_timeout = 0;
9700 if (gtk_widget_get_mapped (old->priv->popup_window))
9701 _gtk_entry_completion_popdown (old);
9703 disconnect_completion_signals (entry, old);
9704 old->priv->entry = NULL;
9706 g_object_unref (old);
9711 g_object_set_data (G_OBJECT (entry), I_(GTK_ENTRY_COMPLETION_KEY), NULL);
9715 /* hook into the entry */
9716 g_object_ref (completion);
9718 connect_completion_signals (entry, completion);
9719 completion->priv->entry = GTK_WIDGET (entry);
9720 g_object_set_data (G_OBJECT (entry), I_(GTK_ENTRY_COMPLETION_KEY), completion);
9724 * gtk_entry_get_completion:
9725 * @entry: A #GtkEntry
9727 * Returns the auxiliary completion object currently in use by @entry.
9729 * Return value: (transfer none): The auxiliary completion object currently
9734 GtkEntryCompletion *
9735 gtk_entry_get_completion (GtkEntry *entry)
9737 GtkEntryCompletion *completion;
9739 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
9741 completion = GTK_ENTRY_COMPLETION (g_object_get_data (G_OBJECT (entry),
9742 GTK_ENTRY_COMPLETION_KEY));
9748 * gtk_entry_set_cursor_hadjustment:
9749 * @entry: a #GtkEntry
9750 * @adjustment: an adjustment which should be adjusted when the cursor
9751 * is moved, or %NULL
9753 * Hooks up an adjustment to the cursor position in an entry, so that when
9754 * the cursor is moved, the adjustment is scrolled to show that position.
9755 * See gtk_scrolled_window_get_hadjustment() for a typical way of obtaining
9758 * The adjustment has to be in pixel units and in the same coordinate system
9764 gtk_entry_set_cursor_hadjustment (GtkEntry *entry,
9765 GtkAdjustment *adjustment)
9767 g_return_if_fail (GTK_IS_ENTRY (entry));
9769 g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
9772 g_object_ref (adjustment);
9774 g_object_set_qdata_full (G_OBJECT (entry),
9775 quark_cursor_hadjustment,
9781 * gtk_entry_get_cursor_hadjustment:
9782 * @entry: a #GtkEntry
9784 * Retrieves the horizontal cursor adjustment for the entry.
9785 * See gtk_entry_set_cursor_hadjustment().
9787 * Return value: (transfer none): the horizontal cursor adjustment, or %NULL
9788 * if none has been set.
9793 gtk_entry_get_cursor_hadjustment (GtkEntry *entry)
9795 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
9797 return g_object_get_qdata (G_OBJECT (entry), quark_cursor_hadjustment);
9801 * gtk_entry_set_progress_fraction:
9802 * @entry: a #GtkEntry
9803 * @fraction: fraction of the task that's been completed
9805 * Causes the entry's progress indicator to "fill in" the given
9806 * fraction of the bar. The fraction should be between 0.0 and 1.0,
9812 gtk_entry_set_progress_fraction (GtkEntry *entry,
9816 GtkEntryPrivate *private;
9817 gdouble old_fraction;
9818 gint x, y, width, height;
9819 gint old_x, old_y, old_width, old_height;
9821 g_return_if_fail (GTK_IS_ENTRY (entry));
9823 widget = GTK_WIDGET (entry);
9824 private = GTK_ENTRY_GET_PRIVATE (entry);
9826 if (private->progress_pulse_mode)
9829 old_fraction = private->progress_fraction;
9831 if (gtk_widget_is_drawable (widget))
9832 get_progress_area (widget, &old_x, &old_y, &old_width, &old_height);
9834 fraction = CLAMP (fraction, 0.0, 1.0);
9836 private->progress_fraction = fraction;
9837 private->progress_pulse_mode = FALSE;
9838 private->progress_pulse_current = 0.0;
9840 if (gtk_widget_is_drawable (widget))
9842 get_progress_area (widget, &x, &y, &width, &height);
9844 if ((x != old_x) || (y != old_y) || (width != old_width) || (height != old_height))
9845 gtk_widget_queue_draw (widget);
9848 if (fraction != old_fraction)
9849 g_object_notify (G_OBJECT (entry), "progress-fraction");
9853 * gtk_entry_get_progress_fraction:
9854 * @entry: a #GtkEntry
9856 * Returns the current fraction of the task that's been completed.
9857 * See gtk_entry_set_progress_fraction().
9859 * Return value: a fraction from 0.0 to 1.0
9864 gtk_entry_get_progress_fraction (GtkEntry *entry)
9866 GtkEntryPrivate *private;
9868 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
9870 private = GTK_ENTRY_GET_PRIVATE (entry);
9872 return private->progress_fraction;
9876 * gtk_entry_set_progress_pulse_step:
9877 * @entry: a #GtkEntry
9878 * @fraction: fraction between 0.0 and 1.0
9880 * Sets the fraction of total entry width to move the progress
9881 * bouncing block for each call to gtk_entry_progress_pulse().
9886 gtk_entry_set_progress_pulse_step (GtkEntry *entry,
9889 GtkEntryPrivate *private;
9891 g_return_if_fail (GTK_IS_ENTRY (entry));
9893 private = GTK_ENTRY_GET_PRIVATE (entry);
9895 fraction = CLAMP (fraction, 0.0, 1.0);
9897 if (fraction != private->progress_pulse_fraction)
9899 private->progress_pulse_fraction = fraction;
9901 gtk_widget_queue_draw (GTK_WIDGET (entry));
9903 g_object_notify (G_OBJECT (entry), "progress-pulse-step");
9908 * gtk_entry_get_progress_pulse_step:
9909 * @entry: a #GtkEntry
9911 * Retrieves the pulse step set with gtk_entry_set_progress_pulse_step().
9913 * Return value: a fraction from 0.0 to 1.0
9918 gtk_entry_get_progress_pulse_step (GtkEntry *entry)
9920 GtkEntryPrivate *private;
9922 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
9924 private = GTK_ENTRY_GET_PRIVATE (entry);
9926 return private->progress_pulse_fraction;
9930 * gtk_entry_progress_pulse:
9931 * @entry: a #GtkEntry
9933 * Indicates that some progress is made, but you don't know how much.
9934 * Causes the entry's progress indicator to enter "activity mode,"
9935 * where a block bounces back and forth. Each call to
9936 * gtk_entry_progress_pulse() causes the block to move by a little bit
9937 * (the amount of movement per pulse is determined by
9938 * gtk_entry_set_progress_pulse_step()).
9943 gtk_entry_progress_pulse (GtkEntry *entry)
9945 GtkEntryPrivate *private;
9947 g_return_if_fail (GTK_IS_ENTRY (entry));
9949 private = GTK_ENTRY_GET_PRIVATE (entry);
9951 if (private->progress_pulse_mode)
9953 if (private->progress_pulse_way_back)
9955 private->progress_pulse_current -= private->progress_pulse_fraction;
9957 if (private->progress_pulse_current < 0.0)
9959 private->progress_pulse_current = 0.0;
9960 private->progress_pulse_way_back = FALSE;
9965 private->progress_pulse_current += private->progress_pulse_fraction;
9967 if (private->progress_pulse_current > 1.0 - private->progress_pulse_fraction)
9969 private->progress_pulse_current = 1.0 - private->progress_pulse_fraction;
9970 private->progress_pulse_way_back = TRUE;
9976 private->progress_fraction = 0.0;
9977 private->progress_pulse_mode = TRUE;
9978 private->progress_pulse_way_back = FALSE;
9979 private->progress_pulse_current = 0.0;
9982 gtk_widget_queue_draw (GTK_WIDGET (entry));
9985 /* Caps Lock warning for password entries */
9988 show_capslock_feedback (GtkEntry *entry,
9991 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
9993 if (gtk_entry_get_icon_storage_type (entry, GTK_ENTRY_ICON_SECONDARY) == GTK_IMAGE_EMPTY)
9995 gtk_entry_set_icon_from_stock (entry, GTK_ENTRY_ICON_SECONDARY, GTK_STOCK_CAPS_LOCK_WARNING);
9996 gtk_entry_set_icon_activatable (entry, GTK_ENTRY_ICON_SECONDARY, FALSE);
9997 priv->caps_lock_warning_shown = TRUE;
10000 if (priv->caps_lock_warning_shown)
10001 gtk_entry_set_icon_tooltip_text (entry, GTK_ENTRY_ICON_SECONDARY, text);
10003 g_warning ("Can't show Caps Lock warning, since secondary icon is set");
10007 remove_capslock_feedback (GtkEntry *entry)
10009 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
10011 if (priv->caps_lock_warning_shown)
10013 gtk_entry_set_icon_from_stock (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
10014 priv->caps_lock_warning_shown = FALSE;
10019 keymap_state_changed (GdkKeymap *keymap,
10022 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
10025 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL && priv->caps_lock_warning)
10027 if (gdk_keymap_get_num_lock_state (keymap)
10028 && gdk_keymap_get_caps_lock_state (keymap))
10029 text = _("Caps Lock and Num Lock are on");
10030 else if (gdk_keymap_get_num_lock_state (keymap))
10031 text = _("Num Lock is on");
10032 else if (gdk_keymap_get_caps_lock_state (keymap))
10033 text = _("Caps Lock is on");
10037 show_capslock_feedback (entry, text);
10039 remove_capslock_feedback (entry);