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,
268 static void gtk_entry_draw_progress (GtkWidget *widget,
271 static gint gtk_entry_draw (GtkWidget *widget,
273 static gint gtk_entry_button_press (GtkWidget *widget,
274 GdkEventButton *event);
275 static gint gtk_entry_button_release (GtkWidget *widget,
276 GdkEventButton *event);
277 static gint gtk_entry_enter_notify (GtkWidget *widget,
278 GdkEventCrossing *event);
279 static gint gtk_entry_leave_notify (GtkWidget *widget,
280 GdkEventCrossing *event);
281 static gint gtk_entry_motion_notify (GtkWidget *widget,
282 GdkEventMotion *event);
283 static gint gtk_entry_key_press (GtkWidget *widget,
285 static gint gtk_entry_key_release (GtkWidget *widget,
287 static gint gtk_entry_focus_in (GtkWidget *widget,
288 GdkEventFocus *event);
289 static gint gtk_entry_focus_out (GtkWidget *widget,
290 GdkEventFocus *event);
291 static void gtk_entry_grab_focus (GtkWidget *widget);
292 static void gtk_entry_style_set (GtkWidget *widget,
293 GtkStyle *previous_style);
294 static gboolean gtk_entry_query_tooltip (GtkWidget *widget,
297 gboolean keyboard_tip,
298 GtkTooltip *tooltip);
299 static void gtk_entry_direction_changed (GtkWidget *widget,
300 GtkTextDirection previous_dir);
301 static void gtk_entry_state_changed (GtkWidget *widget,
302 GtkStateType previous_state);
303 static void gtk_entry_screen_changed (GtkWidget *widget,
304 GdkScreen *old_screen);
306 static gboolean gtk_entry_drag_drop (GtkWidget *widget,
307 GdkDragContext *context,
311 static gboolean gtk_entry_drag_motion (GtkWidget *widget,
312 GdkDragContext *context,
316 static void gtk_entry_drag_leave (GtkWidget *widget,
317 GdkDragContext *context,
319 static void gtk_entry_drag_data_received (GtkWidget *widget,
320 GdkDragContext *context,
323 GtkSelectionData *selection_data,
326 static void gtk_entry_drag_data_get (GtkWidget *widget,
327 GdkDragContext *context,
328 GtkSelectionData *selection_data,
331 static void gtk_entry_drag_data_delete (GtkWidget *widget,
332 GdkDragContext *context);
333 static void gtk_entry_drag_begin (GtkWidget *widget,
334 GdkDragContext *context);
335 static void gtk_entry_drag_end (GtkWidget *widget,
336 GdkDragContext *context);
339 /* GtkEditable method implementations
341 static void gtk_entry_insert_text (GtkEditable *editable,
342 const gchar *new_text,
343 gint new_text_length,
345 static void gtk_entry_delete_text (GtkEditable *editable,
348 static gchar * gtk_entry_get_chars (GtkEditable *editable,
351 static void gtk_entry_real_set_position (GtkEditable *editable,
353 static gint gtk_entry_get_position (GtkEditable *editable);
354 static void gtk_entry_set_selection_bounds (GtkEditable *editable,
357 static gboolean gtk_entry_get_selection_bounds (GtkEditable *editable,
361 /* GtkCellEditable method implementations
363 static void gtk_entry_start_editing (GtkCellEditable *cell_editable,
366 /* Default signal handlers
368 static void gtk_entry_real_insert_text (GtkEditable *editable,
369 const gchar *new_text,
370 gint new_text_length,
372 static void gtk_entry_real_delete_text (GtkEditable *editable,
375 static void gtk_entry_move_cursor (GtkEntry *entry,
376 GtkMovementStep step,
378 gboolean extend_selection);
379 static void gtk_entry_insert_at_cursor (GtkEntry *entry,
381 static void gtk_entry_delete_from_cursor (GtkEntry *entry,
384 static void gtk_entry_backspace (GtkEntry *entry);
385 static void gtk_entry_cut_clipboard (GtkEntry *entry);
386 static void gtk_entry_copy_clipboard (GtkEntry *entry);
387 static void gtk_entry_paste_clipboard (GtkEntry *entry);
388 static void gtk_entry_toggle_overwrite (GtkEntry *entry);
389 static void gtk_entry_select_all (GtkEntry *entry);
390 static void gtk_entry_real_activate (GtkEntry *entry);
391 static gboolean gtk_entry_popup_menu (GtkWidget *widget);
393 static void keymap_direction_changed (GdkKeymap *keymap,
395 static void keymap_state_changed (GdkKeymap *keymap,
397 static void remove_capslock_feedback (GtkEntry *entry);
399 /* IM Context Callbacks
401 static void gtk_entry_commit_cb (GtkIMContext *context,
404 static void gtk_entry_preedit_changed_cb (GtkIMContext *context,
406 static gboolean gtk_entry_retrieve_surrounding_cb (GtkIMContext *context,
408 static gboolean gtk_entry_delete_surrounding_cb (GtkIMContext *context,
415 static void gtk_entry_enter_text (GtkEntry *entry,
417 static void gtk_entry_set_positions (GtkEntry *entry,
419 gint selection_bound);
420 static void gtk_entry_draw_text (GtkEntry *entry,
422 static void gtk_entry_draw_cursor (GtkEntry *entry,
425 static PangoLayout *gtk_entry_ensure_layout (GtkEntry *entry,
426 gboolean include_preedit);
427 static void gtk_entry_reset_layout (GtkEntry *entry);
428 static void gtk_entry_queue_draw (GtkEntry *entry);
429 static void gtk_entry_recompute (GtkEntry *entry);
430 static gint gtk_entry_find_position (GtkEntry *entry,
432 static void gtk_entry_get_cursor_locations (GtkEntry *entry,
436 static void gtk_entry_adjust_scroll (GtkEntry *entry);
437 static gint gtk_entry_move_visually (GtkEntry *editable,
440 static gint gtk_entry_move_logically (GtkEntry *entry,
443 static gint gtk_entry_move_forward_word (GtkEntry *entry,
445 gboolean allow_whitespace);
446 static gint gtk_entry_move_backward_word (GtkEntry *entry,
448 gboolean allow_whitespace);
449 static void gtk_entry_delete_whitespace (GtkEntry *entry);
450 static void gtk_entry_select_word (GtkEntry *entry);
451 static void gtk_entry_select_line (GtkEntry *entry);
452 static void gtk_entry_paste (GtkEntry *entry,
454 static void gtk_entry_update_primary_selection (GtkEntry *entry);
455 static void gtk_entry_do_popup (GtkEntry *entry,
456 GdkEventButton *event);
457 static gboolean gtk_entry_mnemonic_activate (GtkWidget *widget,
458 gboolean group_cycling);
459 static void gtk_entry_check_cursor_blink (GtkEntry *entry);
460 static void gtk_entry_pend_cursor_blink (GtkEntry *entry);
461 static void gtk_entry_reset_blink_time (GtkEntry *entry);
462 static void gtk_entry_get_text_area_size (GtkEntry *entry,
467 static void get_text_area_size (GtkEntry *entry,
472 static void get_widget_window_size (GtkEntry *entry,
477 static void gtk_entry_move_adjustments (GtkEntry *entry);
478 static void gtk_entry_ensure_pixbuf (GtkEntry *entry,
479 GtkEntryIconPosition icon_pos);
483 static gint gtk_entry_completion_timeout (gpointer data);
484 static gboolean gtk_entry_completion_key_press (GtkWidget *widget,
487 static void gtk_entry_completion_changed (GtkWidget *entry,
489 static gboolean check_completion_callback (GtkEntryCompletion *completion);
490 static void clear_completion_callback (GtkEntry *entry,
492 static gboolean accept_completion_callback (GtkEntry *entry);
493 static void completion_insert_text_callback (GtkEntry *entry,
497 GtkEntryCompletion *completion);
498 static void completion_changed (GtkEntryCompletion *completion,
501 static void disconnect_completion_signals (GtkEntry *entry,
502 GtkEntryCompletion *completion);
503 static void connect_completion_signals (GtkEntry *entry,
504 GtkEntryCompletion *completion);
506 static void begin_change (GtkEntry *entry);
507 static void end_change (GtkEntry *entry);
508 static void emit_changed (GtkEntry *entry);
511 static void buffer_inserted_text (GtkEntryBuffer *buffer,
516 static void buffer_deleted_text (GtkEntryBuffer *buffer,
520 static void buffer_notify_text (GtkEntryBuffer *buffer,
523 static void buffer_notify_length (GtkEntryBuffer *buffer,
526 static void buffer_notify_max_length (GtkEntryBuffer *buffer,
529 static void buffer_connect_signals (GtkEntry *entry);
530 static void buffer_disconnect_signals (GtkEntry *entry);
531 static GtkEntryBuffer *get_buffer (GtkEntry *entry);
534 G_DEFINE_TYPE_WITH_CODE (GtkEntry, gtk_entry, GTK_TYPE_WIDGET,
535 G_IMPLEMENT_INTERFACE (GTK_TYPE_EDITABLE,
536 gtk_entry_editable_init)
537 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_EDITABLE,
538 gtk_entry_cell_editable_init))
541 add_move_binding (GtkBindingSet *binding_set,
544 GtkMovementStep step,
547 g_return_if_fail ((modmask & GDK_SHIFT_MASK) == 0);
549 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
553 G_TYPE_BOOLEAN, FALSE);
555 /* Selection-extending version */
556 gtk_binding_entry_add_signal (binding_set, keyval, modmask | GDK_SHIFT_MASK,
560 G_TYPE_BOOLEAN, TRUE);
564 gtk_entry_class_init (GtkEntryClass *class)
566 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
567 GtkWidgetClass *widget_class;
568 GtkObjectClass *gtk_object_class;
569 GtkBindingSet *binding_set;
571 widget_class = (GtkWidgetClass*) class;
572 gtk_object_class = (GtkObjectClass *)class;
574 gobject_class->dispose = gtk_entry_dispose;
575 gobject_class->finalize = gtk_entry_finalize;
576 gobject_class->set_property = gtk_entry_set_property;
577 gobject_class->get_property = gtk_entry_get_property;
579 widget_class->map = gtk_entry_map;
580 widget_class->unmap = gtk_entry_unmap;
581 widget_class->realize = gtk_entry_realize;
582 widget_class->unrealize = gtk_entry_unrealize;
583 widget_class->size_request = gtk_entry_size_request;
584 widget_class->size_allocate = gtk_entry_size_allocate;
585 widget_class->draw = gtk_entry_draw;
586 widget_class->enter_notify_event = gtk_entry_enter_notify;
587 widget_class->leave_notify_event = gtk_entry_leave_notify;
588 widget_class->button_press_event = gtk_entry_button_press;
589 widget_class->button_release_event = gtk_entry_button_release;
590 widget_class->motion_notify_event = gtk_entry_motion_notify;
591 widget_class->key_press_event = gtk_entry_key_press;
592 widget_class->key_release_event = gtk_entry_key_release;
593 widget_class->focus_in_event = gtk_entry_focus_in;
594 widget_class->focus_out_event = gtk_entry_focus_out;
595 widget_class->grab_focus = gtk_entry_grab_focus;
596 widget_class->style_set = gtk_entry_style_set;
597 widget_class->query_tooltip = gtk_entry_query_tooltip;
598 widget_class->drag_begin = gtk_entry_drag_begin;
599 widget_class->drag_end = gtk_entry_drag_end;
600 widget_class->direction_changed = gtk_entry_direction_changed;
601 widget_class->state_changed = gtk_entry_state_changed;
602 widget_class->screen_changed = gtk_entry_screen_changed;
603 widget_class->mnemonic_activate = gtk_entry_mnemonic_activate;
605 widget_class->drag_drop = gtk_entry_drag_drop;
606 widget_class->drag_motion = gtk_entry_drag_motion;
607 widget_class->drag_leave = gtk_entry_drag_leave;
608 widget_class->drag_data_received = gtk_entry_drag_data_received;
609 widget_class->drag_data_get = gtk_entry_drag_data_get;
610 widget_class->drag_data_delete = gtk_entry_drag_data_delete;
612 widget_class->popup_menu = gtk_entry_popup_menu;
614 gtk_object_class->destroy = gtk_entry_destroy;
616 class->move_cursor = gtk_entry_move_cursor;
617 class->insert_at_cursor = gtk_entry_insert_at_cursor;
618 class->delete_from_cursor = gtk_entry_delete_from_cursor;
619 class->backspace = gtk_entry_backspace;
620 class->cut_clipboard = gtk_entry_cut_clipboard;
621 class->copy_clipboard = gtk_entry_copy_clipboard;
622 class->paste_clipboard = gtk_entry_paste_clipboard;
623 class->toggle_overwrite = gtk_entry_toggle_overwrite;
624 class->activate = gtk_entry_real_activate;
625 class->get_text_area_size = gtk_entry_get_text_area_size;
627 quark_inner_border = g_quark_from_static_string ("gtk-entry-inner-border");
628 quark_password_hint = g_quark_from_static_string ("gtk-entry-password-hint");
629 quark_cursor_hadjustment = g_quark_from_static_string ("gtk-hadjustment");
630 quark_capslock_feedback = g_quark_from_static_string ("gtk-entry-capslock-feedback");
632 g_object_class_override_property (gobject_class,
633 PROP_EDITING_CANCELED,
636 g_object_class_install_property (gobject_class,
638 g_param_spec_object ("buffer",
640 P_("Text buffer object which actually stores entry text"),
641 GTK_TYPE_ENTRY_BUFFER,
642 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT));
644 g_object_class_install_property (gobject_class,
645 PROP_CURSOR_POSITION,
646 g_param_spec_int ("cursor-position",
647 P_("Cursor Position"),
648 P_("The current position of the insertion cursor in chars"),
650 GTK_ENTRY_BUFFER_MAX_SIZE,
652 GTK_PARAM_READABLE));
654 g_object_class_install_property (gobject_class,
655 PROP_SELECTION_BOUND,
656 g_param_spec_int ("selection-bound",
657 P_("Selection Bound"),
658 P_("The position of the opposite end of the selection from the cursor in chars"),
660 GTK_ENTRY_BUFFER_MAX_SIZE,
662 GTK_PARAM_READABLE));
664 g_object_class_install_property (gobject_class,
666 g_param_spec_boolean ("editable",
668 P_("Whether the entry contents can be edited"),
670 GTK_PARAM_READWRITE));
672 g_object_class_install_property (gobject_class,
674 g_param_spec_int ("max-length",
675 P_("Maximum length"),
676 P_("Maximum number of characters for this entry. Zero if no maximum"),
678 GTK_ENTRY_BUFFER_MAX_SIZE,
680 GTK_PARAM_READWRITE));
681 g_object_class_install_property (gobject_class,
683 g_param_spec_boolean ("visibility",
685 P_("FALSE displays the \"invisible char\" instead of the actual text (password mode)"),
687 GTK_PARAM_READWRITE));
689 g_object_class_install_property (gobject_class,
691 g_param_spec_boolean ("has-frame",
693 P_("FALSE removes outside bevel from entry"),
695 GTK_PARAM_READWRITE));
697 g_object_class_install_property (gobject_class,
699 g_param_spec_boxed ("inner-border",
701 P_("Border between text and frame. Overrides the inner-border style property"),
703 GTK_PARAM_READWRITE));
705 g_object_class_install_property (gobject_class,
707 g_param_spec_unichar ("invisible-char",
708 P_("Invisible character"),
709 P_("The character to use when masking entry contents (in \"password mode\")"),
711 GTK_PARAM_READWRITE));
713 g_object_class_install_property (gobject_class,
714 PROP_ACTIVATES_DEFAULT,
715 g_param_spec_boolean ("activates-default",
716 P_("Activates default"),
717 P_("Whether to activate the default widget (such as the default button in a dialog) when Enter is pressed"),
719 GTK_PARAM_READWRITE));
720 g_object_class_install_property (gobject_class,
722 g_param_spec_int ("width-chars",
723 P_("Width in chars"),
724 P_("Number of characters to leave space for in the entry"),
728 GTK_PARAM_READWRITE));
730 g_object_class_install_property (gobject_class,
732 g_param_spec_int ("scroll-offset",
734 P_("Number of pixels of the entry scrolled off the screen to the left"),
738 GTK_PARAM_READABLE));
740 g_object_class_install_property (gobject_class,
742 g_param_spec_string ("text",
744 P_("The contents of the entry"),
746 GTK_PARAM_READWRITE));
751 * The horizontal alignment, from 0 (left) to 1 (right).
752 * Reversed for RTL layouts.
756 g_object_class_install_property (gobject_class,
758 g_param_spec_float ("xalign",
760 P_("The horizontal alignment, from 0 (left) to 1 (right). Reversed for RTL layouts."),
764 GTK_PARAM_READWRITE));
767 * GtkEntry:truncate-multiline:
769 * When %TRUE, pasted multi-line text is truncated to the first line.
773 g_object_class_install_property (gobject_class,
774 PROP_TRUNCATE_MULTILINE,
775 g_param_spec_boolean ("truncate-multiline",
776 P_("Truncate multiline"),
777 P_("Whether to truncate multiline pastes to one line."),
779 GTK_PARAM_READWRITE));
782 * GtkEntry:shadow-type:
784 * Which kind of shadow to draw around the entry when
785 * #GtkEntry:has-frame is set to %TRUE.
789 g_object_class_install_property (gobject_class,
791 g_param_spec_enum ("shadow-type",
793 P_("Which kind of shadow to draw around the entry when has-frame is set"),
794 GTK_TYPE_SHADOW_TYPE,
796 GTK_PARAM_READWRITE));
799 * GtkEntry:overwrite-mode:
801 * If text is overwritten when typing in the #GtkEntry.
805 g_object_class_install_property (gobject_class,
807 g_param_spec_boolean ("overwrite-mode",
808 P_("Overwrite mode"),
809 P_("Whether new text overwrites existing text"),
811 GTK_PARAM_READWRITE));
814 * GtkEntry:text-length:
816 * The length of the text in the #GtkEntry.
820 g_object_class_install_property (gobject_class,
822 g_param_spec_uint ("text-length",
824 P_("Length of the text currently in the entry"),
828 GTK_PARAM_READABLE));
830 * GtkEntry:invisible-char-set:
832 * Whether the invisible char has been set for the #GtkEntry.
836 g_object_class_install_property (gobject_class,
837 PROP_INVISIBLE_CHAR_SET,
838 g_param_spec_boolean ("invisible-char-set",
839 P_("Invisible character set"),
840 P_("Whether the invisible character has been set"),
842 GTK_PARAM_READWRITE));
845 * GtkEntry:caps-lock-warning
847 * Whether password entries will show a warning when Caps Lock is on.
849 * Note that the warning is shown using a secondary icon, and thus
850 * does not work if you are using the secondary icon position for some
855 g_object_class_install_property (gobject_class,
856 PROP_CAPS_LOCK_WARNING,
857 g_param_spec_boolean ("caps-lock-warning",
858 P_("Caps Lock warning"),
859 P_("Whether password entries will show a warning when Caps Lock is on"),
861 GTK_PARAM_READWRITE));
864 * GtkEntry:progress-fraction:
866 * The current fraction of the task that's been completed.
870 g_object_class_install_property (gobject_class,
871 PROP_PROGRESS_FRACTION,
872 g_param_spec_double ("progress-fraction",
873 P_("Progress Fraction"),
874 P_("The current fraction of the task that's been completed"),
878 GTK_PARAM_READWRITE));
881 * GtkEntry:progress-pulse-step:
883 * The fraction of total entry width to move the progress
884 * bouncing block for each call to gtk_entry_progress_pulse().
888 g_object_class_install_property (gobject_class,
889 PROP_PROGRESS_PULSE_STEP,
890 g_param_spec_double ("progress-pulse-step",
891 P_("Progress Pulse Step"),
892 P_("The fraction of total entry width to move the progress bouncing block for each call to gtk_entry_progress_pulse()"),
896 GTK_PARAM_READWRITE));
899 * GtkEntry:primary-icon-pixbuf:
901 * A pixbuf to use as the primary icon for the entry.
905 g_object_class_install_property (gobject_class,
907 g_param_spec_object ("primary-icon-pixbuf",
908 P_("Primary pixbuf"),
909 P_("Primary pixbuf for the entry"),
911 GTK_PARAM_READWRITE));
914 * GtkEntry:secondary-icon-pixbuf:
916 * An pixbuf to use as the secondary icon for the entry.
920 g_object_class_install_property (gobject_class,
921 PROP_PIXBUF_SECONDARY,
922 g_param_spec_object ("secondary-icon-pixbuf",
923 P_("Secondary pixbuf"),
924 P_("Secondary pixbuf for the entry"),
926 GTK_PARAM_READWRITE));
929 * GtkEntry:primary-icon-stock:
931 * The stock id to use for the primary icon for the entry.
935 g_object_class_install_property (gobject_class,
937 g_param_spec_string ("primary-icon-stock",
938 P_("Primary stock ID"),
939 P_("Stock ID for primary icon"),
941 GTK_PARAM_READWRITE));
944 * GtkEntry:secondary-icon-stock:
946 * The stock id to use for the secondary icon for the entry.
950 g_object_class_install_property (gobject_class,
951 PROP_STOCK_SECONDARY,
952 g_param_spec_string ("secondary-icon-stock",
953 P_("Secondary stock ID"),
954 P_("Stock ID for secondary icon"),
956 GTK_PARAM_READWRITE));
959 * GtkEntry:primary-icon-name:
961 * The icon name to use for the primary icon for the entry.
965 g_object_class_install_property (gobject_class,
966 PROP_ICON_NAME_PRIMARY,
967 g_param_spec_string ("primary-icon-name",
968 P_("Primary icon name"),
969 P_("Icon name for primary icon"),
971 GTK_PARAM_READWRITE));
974 * GtkEntry:secondary-icon-name:
976 * The icon name to use for the secondary icon for the entry.
980 g_object_class_install_property (gobject_class,
981 PROP_ICON_NAME_SECONDARY,
982 g_param_spec_string ("secondary-icon-name",
983 P_("Secondary icon name"),
984 P_("Icon name for secondary icon"),
986 GTK_PARAM_READWRITE));
989 * GtkEntry:primary-icon-gicon:
991 * The #GIcon to use for the primary icon for the entry.
995 g_object_class_install_property (gobject_class,
997 g_param_spec_object ("primary-icon-gicon",
999 P_("GIcon for primary icon"),
1001 GTK_PARAM_READWRITE));
1004 * GtkEntry:secondary-icon-gicon:
1006 * The #GIcon to use for the secondary icon for the entry.
1010 g_object_class_install_property (gobject_class,
1011 PROP_GICON_SECONDARY,
1012 g_param_spec_object ("secondary-icon-gicon",
1013 P_("Secondary GIcon"),
1014 P_("GIcon for secondary icon"),
1016 GTK_PARAM_READWRITE));
1019 * GtkEntry:primary-icon-storage-type:
1021 * The representation which is used for the primary icon of the entry.
1025 g_object_class_install_property (gobject_class,
1026 PROP_STORAGE_TYPE_PRIMARY,
1027 g_param_spec_enum ("primary-icon-storage-type",
1028 P_("Primary storage type"),
1029 P_("The representation being used for primary icon"),
1030 GTK_TYPE_IMAGE_TYPE,
1032 GTK_PARAM_READABLE));
1035 * GtkEntry:secondary-icon-storage-type:
1037 * The representation which is used for the secondary icon of the entry.
1041 g_object_class_install_property (gobject_class,
1042 PROP_STORAGE_TYPE_SECONDARY,
1043 g_param_spec_enum ("secondary-icon-storage-type",
1044 P_("Secondary storage type"),
1045 P_("The representation being used for secondary icon"),
1046 GTK_TYPE_IMAGE_TYPE,
1048 GTK_PARAM_READABLE));
1051 * GtkEntry:primary-icon-activatable:
1053 * Whether the primary icon is activatable.
1055 * GTK+ emits the #GtkEntry::icon-press and #GtkEntry::icon-release
1056 * signals only on sensitive, activatable icons.
1058 * Sensitive, but non-activatable icons can be used for purely
1059 * informational purposes.
1063 g_object_class_install_property (gobject_class,
1064 PROP_ACTIVATABLE_PRIMARY,
1065 g_param_spec_boolean ("primary-icon-activatable",
1066 P_("Primary icon activatable"),
1067 P_("Whether the primary icon is activatable"),
1069 GTK_PARAM_READWRITE));
1072 * GtkEntry:secondary-icon-activatable:
1074 * Whether the secondary icon is activatable.
1076 * GTK+ emits the #GtkEntry::icon-press and #GtkEntry::icon-release
1077 * signals only on sensitive, activatable icons.
1079 * Sensitive, but non-activatable icons can be used for purely
1080 * informational purposes.
1084 g_object_class_install_property (gobject_class,
1085 PROP_ACTIVATABLE_SECONDARY,
1086 g_param_spec_boolean ("secondary-icon-activatable",
1087 P_("Secondary icon activatable"),
1088 P_("Whether the secondary icon is activatable"),
1090 GTK_PARAM_READWRITE));
1094 * GtkEntry:primary-icon-sensitive:
1096 * Whether the primary icon is sensitive.
1098 * An insensitive icon appears grayed out. GTK+ does not emit the
1099 * #GtkEntry::icon-press and #GtkEntry::icon-release signals and
1100 * does not allow DND from insensitive icons.
1102 * An icon should be set insensitive if the action that would trigger
1103 * when clicked is currently not available.
1107 g_object_class_install_property (gobject_class,
1108 PROP_SENSITIVE_PRIMARY,
1109 g_param_spec_boolean ("primary-icon-sensitive",
1110 P_("Primary icon sensitive"),
1111 P_("Whether the primary icon is sensitive"),
1113 GTK_PARAM_READWRITE));
1116 * GtkEntry:secondary-icon-sensitive:
1118 * Whether the secondary icon is sensitive.
1120 * An insensitive icon appears grayed out. GTK+ does not emit the
1121 * #GtkEntry::icon-press and #GtkEntry::icon-release signals and
1122 * does not allow DND from insensitive icons.
1124 * An icon should be set insensitive if the action that would trigger
1125 * when clicked is currently not available.
1129 g_object_class_install_property (gobject_class,
1130 PROP_SENSITIVE_SECONDARY,
1131 g_param_spec_boolean ("secondary-icon-sensitive",
1132 P_("Secondary icon sensitive"),
1133 P_("Whether the secondary icon is sensitive"),
1135 GTK_PARAM_READWRITE));
1138 * GtkEntry:primary-icon-tooltip-text:
1140 * The contents of the tooltip on the primary icon.
1142 * Also see gtk_entry_set_icon_tooltip_text().
1146 g_object_class_install_property (gobject_class,
1147 PROP_TOOLTIP_TEXT_PRIMARY,
1148 g_param_spec_string ("primary-icon-tooltip-text",
1149 P_("Primary icon tooltip text"),
1150 P_("The contents of the tooltip on the primary icon"),
1152 GTK_PARAM_READWRITE));
1155 * GtkEntry:secondary-icon-tooltip-text:
1157 * The contents of the tooltip on the secondary icon.
1159 * Also see gtk_entry_set_icon_tooltip_text().
1163 g_object_class_install_property (gobject_class,
1164 PROP_TOOLTIP_TEXT_SECONDARY,
1165 g_param_spec_string ("secondary-icon-tooltip-text",
1166 P_("Secondary icon tooltip text"),
1167 P_("The contents of the tooltip on the secondary icon"),
1169 GTK_PARAM_READWRITE));
1172 * GtkEntry:primary-icon-tooltip-markup:
1174 * The contents of the tooltip on the primary icon, which is marked up
1175 * with the <link linkend="PangoMarkupFormat">Pango text markup
1178 * Also see gtk_entry_set_icon_tooltip_markup().
1182 g_object_class_install_property (gobject_class,
1183 PROP_TOOLTIP_MARKUP_PRIMARY,
1184 g_param_spec_string ("primary-icon-tooltip-markup",
1185 P_("Primary icon tooltip markup"),
1186 P_("The contents of the tooltip on the primary icon"),
1188 GTK_PARAM_READWRITE));
1191 * GtkEntry:secondary-icon-tooltip-markup:
1193 * The contents of the tooltip on the secondary icon, which is marked up
1194 * with the <link linkend="PangoMarkupFormat">Pango text markup
1197 * Also see gtk_entry_set_icon_tooltip_markup().
1201 g_object_class_install_property (gobject_class,
1202 PROP_TOOLTIP_MARKUP_SECONDARY,
1203 g_param_spec_string ("secondary-icon-tooltip-markup",
1204 P_("Secondary icon tooltip markup"),
1205 P_("The contents of the tooltip on the secondary icon"),
1207 GTK_PARAM_READWRITE));
1210 * GtkEntry:im-module:
1212 * Which IM (input method) module should be used for this entry.
1213 * See #GtkIMContext.
1215 * Setting this to a non-%NULL value overrides the
1216 * system-wide IM module setting. See the GtkSettings
1217 * #GtkSettings:gtk-im-module property.
1221 g_object_class_install_property (gobject_class,
1223 g_param_spec_string ("im-module",
1225 P_("Which IM module should be used"),
1227 GTK_PARAM_READWRITE));
1230 * GtkEntry:icon-prelight:
1232 * The prelight style property determines whether activatable
1233 * icons prelight on mouseover.
1237 gtk_widget_class_install_style_property (widget_class,
1238 g_param_spec_boolean ("icon-prelight",
1239 P_("Icon Prelight"),
1240 P_("Whether activatable icons should prelight when hovered"),
1242 GTK_PARAM_READABLE));
1245 * GtkEntry:progress-border:
1247 * The border around the progress bar in the entry.
1251 gtk_widget_class_install_style_property (widget_class,
1252 g_param_spec_boxed ("progress-border",
1253 P_("Progress Border"),
1254 P_("Border around the progress bar"),
1256 GTK_PARAM_READABLE));
1259 * GtkEntry:invisible-char:
1261 * The invisible character is used when masking entry contents (in
1262 * \"password mode\")"). When it is not explicitly set with the
1263 * #GtkEntry::invisible-char property, GTK+ determines the character
1264 * to use from a list of possible candidates, depending on availability
1265 * in the current font.
1267 * This style property allows the theme to prepend a character
1268 * to the list of candidates.
1272 gtk_widget_class_install_style_property (widget_class,
1273 g_param_spec_unichar ("invisible-char",
1274 P_("Invisible character"),
1275 P_("The character to use when masking entry contents (in \"password mode\")"),
1277 GTK_PARAM_READABLE));
1280 * GtkEntry::populate-popup:
1281 * @entry: The entry on which the signal is emitted
1282 * @menu: the menu that is being populated
1284 * The ::populate-popup signal gets emitted before showing the
1285 * context menu of the entry.
1287 * If you need to add items to the context menu, connect
1288 * to this signal and append your menuitems to the @menu.
1290 signals[POPULATE_POPUP] =
1291 g_signal_new (I_("populate-popup"),
1292 G_OBJECT_CLASS_TYPE (gobject_class),
1294 G_STRUCT_OFFSET (GtkEntryClass, populate_popup),
1296 _gtk_marshal_VOID__OBJECT,
1300 /* Action signals */
1303 * GtkEntry::activate:
1304 * @entry: The entry on which the signal is emitted
1306 * A <link linkend="keybinding-signals">keybinding signal</link>
1307 * which gets emitted when the user activates the entry.
1309 * Applications should not connect to it, but may emit it with
1310 * g_signal_emit_by_name() if they need to control activation
1313 * The default bindings for this signal are all forms of the Enter key.
1316 g_signal_new (I_("activate"),
1317 G_OBJECT_CLASS_TYPE (gobject_class),
1318 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1319 G_STRUCT_OFFSET (GtkEntryClass, activate),
1321 _gtk_marshal_VOID__VOID,
1323 widget_class->activate_signal = signals[ACTIVATE];
1326 * GtkEntry::move-cursor:
1327 * @entry: the object which received the signal
1328 * @step: the granularity of the move, as a #GtkMovementStep
1329 * @count: the number of @step units to move
1330 * @extend_selection: %TRUE if the move should extend the selection
1332 * The ::move-cursor signal is a
1333 * <link linkend="keybinding-signals">keybinding signal</link>
1334 * which gets emitted when the user initiates a cursor movement.
1335 * If the cursor is not visible in @entry, this signal causes
1336 * the viewport to be moved instead.
1338 * Applications should not connect to it, but may emit it with
1339 * g_signal_emit_by_name() if they need to control the cursor
1342 * The default bindings for this signal come in two variants,
1343 * the variant with the Shift modifier extends the selection,
1344 * the variant without the Shift modifer does not.
1345 * There are too many key combinations to list them all here.
1347 * <listitem>Arrow keys move by individual characters/lines</listitem>
1348 * <listitem>Ctrl-arrow key combinations move by words/paragraphs</listitem>
1349 * <listitem>Home/End keys move to the ends of the buffer</listitem>
1352 signals[MOVE_CURSOR] =
1353 g_signal_new (I_("move-cursor"),
1354 G_OBJECT_CLASS_TYPE (gobject_class),
1355 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1356 G_STRUCT_OFFSET (GtkEntryClass, move_cursor),
1358 _gtk_marshal_VOID__ENUM_INT_BOOLEAN,
1360 GTK_TYPE_MOVEMENT_STEP,
1365 * GtkEntry::insert-at-cursor:
1366 * @entry: the object which received the signal
1367 * @string: the string to insert
1369 * The ::insert-at-cursor signal is a
1370 * <link linkend="keybinding-signals">keybinding signal</link>
1371 * which gets emitted when the user initiates the insertion of a
1372 * fixed string at the cursor.
1374 * This signal has no default bindings.
1376 signals[INSERT_AT_CURSOR] =
1377 g_signal_new (I_("insert-at-cursor"),
1378 G_OBJECT_CLASS_TYPE (gobject_class),
1379 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1380 G_STRUCT_OFFSET (GtkEntryClass, insert_at_cursor),
1382 _gtk_marshal_VOID__STRING,
1387 * GtkEntry::delete-from-cursor:
1388 * @entry: the object which received the signal
1389 * @type: the granularity of the deletion, as a #GtkDeleteType
1390 * @count: the number of @type units to delete
1392 * The ::delete-from-cursor signal is a
1393 * <link linkend="keybinding-signals">keybinding signal</link>
1394 * which gets emitted when the user initiates a text deletion.
1396 * If the @type is %GTK_DELETE_CHARS, GTK+ deletes the selection
1397 * if there is one, otherwise it deletes the requested number
1400 * The default bindings for this signal are
1401 * Delete for deleting a character and Ctrl-Delete for
1404 signals[DELETE_FROM_CURSOR] =
1405 g_signal_new (I_("delete-from-cursor"),
1406 G_OBJECT_CLASS_TYPE (gobject_class),
1407 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1408 G_STRUCT_OFFSET (GtkEntryClass, delete_from_cursor),
1410 _gtk_marshal_VOID__ENUM_INT,
1412 GTK_TYPE_DELETE_TYPE,
1416 * GtkEntry::backspace:
1417 * @entry: the object which received the signal
1419 * The ::backspace signal is a
1420 * <link linkend="keybinding-signals">keybinding signal</link>
1421 * which gets emitted when the user asks for it.
1423 * The default bindings for this signal are
1424 * Backspace and Shift-Backspace.
1426 signals[BACKSPACE] =
1427 g_signal_new (I_("backspace"),
1428 G_OBJECT_CLASS_TYPE (gobject_class),
1429 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1430 G_STRUCT_OFFSET (GtkEntryClass, backspace),
1432 _gtk_marshal_VOID__VOID,
1436 * GtkEntry::cut-clipboard:
1437 * @entry: the object which received the signal
1439 * The ::cut-clipboard signal is a
1440 * <link linkend="keybinding-signals">keybinding signal</link>
1441 * which gets emitted to cut the selection to the clipboard.
1443 * The default bindings for this signal are
1444 * Ctrl-x and Shift-Delete.
1446 signals[CUT_CLIPBOARD] =
1447 g_signal_new (I_("cut-clipboard"),
1448 G_OBJECT_CLASS_TYPE (gobject_class),
1449 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1450 G_STRUCT_OFFSET (GtkEntryClass, cut_clipboard),
1452 _gtk_marshal_VOID__VOID,
1456 * GtkEntry::copy-clipboard:
1457 * @entry: the object which received the signal
1459 * The ::copy-clipboard signal is a
1460 * <link linkend="keybinding-signals">keybinding signal</link>
1461 * which gets emitted to copy the selection to the clipboard.
1463 * The default bindings for this signal are
1464 * Ctrl-c and Ctrl-Insert.
1466 signals[COPY_CLIPBOARD] =
1467 g_signal_new (I_("copy-clipboard"),
1468 G_OBJECT_CLASS_TYPE (gobject_class),
1469 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1470 G_STRUCT_OFFSET (GtkEntryClass, copy_clipboard),
1472 _gtk_marshal_VOID__VOID,
1476 * GtkEntry::paste-clipboard:
1477 * @entry: the object which received the signal
1479 * The ::paste-clipboard signal is a
1480 * <link linkend="keybinding-signals">keybinding signal</link>
1481 * which gets emitted to paste the contents of the clipboard
1482 * into the text view.
1484 * The default bindings for this signal are
1485 * Ctrl-v and Shift-Insert.
1487 signals[PASTE_CLIPBOARD] =
1488 g_signal_new (I_("paste-clipboard"),
1489 G_OBJECT_CLASS_TYPE (gobject_class),
1490 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1491 G_STRUCT_OFFSET (GtkEntryClass, paste_clipboard),
1493 _gtk_marshal_VOID__VOID,
1497 * GtkEntry::toggle-overwrite:
1498 * @entry: the object which received the signal
1500 * The ::toggle-overwrite signal is a
1501 * <link linkend="keybinding-signals">keybinding signal</link>
1502 * which gets emitted to toggle the overwrite mode of the entry.
1504 * The default bindings for this signal is Insert.
1506 signals[TOGGLE_OVERWRITE] =
1507 g_signal_new (I_("toggle-overwrite"),
1508 G_OBJECT_CLASS_TYPE (gobject_class),
1509 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1510 G_STRUCT_OFFSET (GtkEntryClass, toggle_overwrite),
1512 _gtk_marshal_VOID__VOID,
1516 * GtkEntry::icon-press:
1517 * @entry: The entry on which the signal is emitted
1518 * @icon_pos: The position of the clicked icon
1519 * @event: the button press event
1521 * The ::icon-press signal is emitted when an activatable icon
1526 signals[ICON_PRESS] =
1527 g_signal_new (I_("icon-press"),
1528 G_TYPE_FROM_CLASS (gobject_class),
1532 _gtk_marshal_VOID__ENUM_BOXED,
1534 GTK_TYPE_ENTRY_ICON_POSITION,
1535 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1538 * GtkEntry::icon-release:
1539 * @entry: The entry on which the signal is emitted
1540 * @icon_pos: The position of the clicked icon
1541 * @event: the button release event
1543 * The ::icon-release signal is emitted on the button release from a
1544 * mouse click over an activatable icon.
1548 signals[ICON_RELEASE] =
1549 g_signal_new (I_("icon-release"),
1550 G_TYPE_FROM_CLASS (gobject_class),
1554 _gtk_marshal_VOID__ENUM_BOXED,
1556 GTK_TYPE_ENTRY_ICON_POSITION,
1557 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1560 * GtkEntry::preedit-changed:
1561 * @entry: the object which received the signal
1562 * @preedit: the current preedit string
1564 * If an input method is used, the typed text will not immediately
1565 * be committed to the buffer. So if you are interested in the text,
1566 * connect to this signal.
1570 signals[PREEDIT_CHANGED] =
1571 g_signal_new_class_handler (I_("preedit-changed"),
1572 G_OBJECT_CLASS_TYPE (gobject_class),
1573 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1576 _gtk_marshal_VOID__STRING,
1585 binding_set = gtk_binding_set_by_class (class);
1587 /* Moving the insertion point */
1588 add_move_binding (binding_set, GDK_KEY_Right, 0,
1589 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1591 add_move_binding (binding_set, GDK_KEY_Left, 0,
1592 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1594 add_move_binding (binding_set, GDK_KEY_KP_Right, 0,
1595 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1597 add_move_binding (binding_set, GDK_KEY_KP_Left, 0,
1598 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1600 add_move_binding (binding_set, GDK_KEY_Right, GDK_CONTROL_MASK,
1601 GTK_MOVEMENT_WORDS, 1);
1603 add_move_binding (binding_set, GDK_KEY_Left, GDK_CONTROL_MASK,
1604 GTK_MOVEMENT_WORDS, -1);
1606 add_move_binding (binding_set, GDK_KEY_KP_Right, GDK_CONTROL_MASK,
1607 GTK_MOVEMENT_WORDS, 1);
1609 add_move_binding (binding_set, GDK_KEY_KP_Left, GDK_CONTROL_MASK,
1610 GTK_MOVEMENT_WORDS, -1);
1612 add_move_binding (binding_set, GDK_KEY_Home, 0,
1613 GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
1615 add_move_binding (binding_set, GDK_KEY_End, 0,
1616 GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
1618 add_move_binding (binding_set, GDK_KEY_KP_Home, 0,
1619 GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
1621 add_move_binding (binding_set, GDK_KEY_KP_End, 0,
1622 GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
1624 add_move_binding (binding_set, GDK_KEY_Home, GDK_CONTROL_MASK,
1625 GTK_MOVEMENT_BUFFER_ENDS, -1);
1627 add_move_binding (binding_set, GDK_KEY_End, GDK_CONTROL_MASK,
1628 GTK_MOVEMENT_BUFFER_ENDS, 1);
1630 add_move_binding (binding_set, GDK_KEY_KP_Home, GDK_CONTROL_MASK,
1631 GTK_MOVEMENT_BUFFER_ENDS, -1);
1633 add_move_binding (binding_set, GDK_KEY_KP_End, GDK_CONTROL_MASK,
1634 GTK_MOVEMENT_BUFFER_ENDS, 1);
1638 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK,
1640 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1642 G_TYPE_BOOLEAN, FALSE);
1643 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK,
1645 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1647 G_TYPE_BOOLEAN, TRUE);
1649 gtk_binding_entry_add_signal (binding_set, GDK_KEY_slash, GDK_CONTROL_MASK,
1651 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1653 G_TYPE_BOOLEAN, FALSE);
1654 gtk_binding_entry_add_signal (binding_set, GDK_KEY_slash, GDK_CONTROL_MASK,
1656 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1658 G_TYPE_BOOLEAN, TRUE);
1661 gtk_binding_entry_add_signal (binding_set, GDK_KEY_backslash, GDK_CONTROL_MASK,
1663 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_VISUAL_POSITIONS,
1665 G_TYPE_BOOLEAN, FALSE);
1666 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_SHIFT_MASK | GDK_CONTROL_MASK,
1668 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_VISUAL_POSITIONS,
1670 G_TYPE_BOOLEAN, FALSE);
1674 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Return, 0,
1676 gtk_binding_entry_add_signal (binding_set, GDK_KEY_ISO_Enter, 0,
1678 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Enter, 0,
1682 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, 0,
1683 "delete-from-cursor", 2,
1684 G_TYPE_ENUM, GTK_DELETE_CHARS,
1687 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Delete, 0,
1688 "delete-from-cursor", 2,
1689 G_TYPE_ENUM, GTK_DELETE_CHARS,
1692 gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, 0,
1695 /* Make this do the same as Backspace, to help with mis-typing */
1696 gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, GDK_SHIFT_MASK,
1699 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, GDK_CONTROL_MASK,
1700 "delete-from-cursor", 2,
1701 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1704 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Delete, GDK_CONTROL_MASK,
1705 "delete-from-cursor", 2,
1706 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1709 gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, GDK_CONTROL_MASK,
1710 "delete-from-cursor", 2,
1711 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1714 /* Cut/copy/paste */
1716 gtk_binding_entry_add_signal (binding_set, GDK_KEY_x, GDK_CONTROL_MASK,
1717 "cut-clipboard", 0);
1718 gtk_binding_entry_add_signal (binding_set, GDK_KEY_c, GDK_CONTROL_MASK,
1719 "copy-clipboard", 0);
1720 gtk_binding_entry_add_signal (binding_set, GDK_KEY_v, GDK_CONTROL_MASK,
1721 "paste-clipboard", 0);
1723 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, GDK_SHIFT_MASK,
1724 "cut-clipboard", 0);
1725 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, GDK_CONTROL_MASK,
1726 "copy-clipboard", 0);
1727 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, GDK_SHIFT_MASK,
1728 "paste-clipboard", 0);
1731 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, 0,
1732 "toggle-overwrite", 0);
1733 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Insert, 0,
1734 "toggle-overwrite", 0);
1737 * GtkEntry:inner-border:
1739 * Sets the text area's border between the text and the frame.
1743 gtk_widget_class_install_style_property (widget_class,
1744 g_param_spec_boxed ("inner-border",
1746 P_("Border between text and frame."),
1748 GTK_PARAM_READABLE));
1750 gtk_settings_install_property (g_param_spec_boolean ("gtk-entry-select-on-focus",
1751 P_("Select on focus"),
1752 P_("Whether to select the contents of an entry when it is focused"),
1754 GTK_PARAM_READWRITE));
1757 * GtkSettings:gtk-entry-password-hint-timeout:
1759 * How long to show the last input character in hidden
1760 * entries. This value is in milliseconds. 0 disables showing the
1761 * last char. 600 is a good value for enabling it.
1765 gtk_settings_install_property (g_param_spec_uint ("gtk-entry-password-hint-timeout",
1766 P_("Password Hint Timeout"),
1767 P_("How long to show the last input character in hidden entries"),
1769 GTK_PARAM_READWRITE));
1771 g_type_class_add_private (gobject_class, sizeof (GtkEntryPrivate));
1775 gtk_entry_editable_init (GtkEditableInterface *iface)
1777 iface->do_insert_text = gtk_entry_insert_text;
1778 iface->do_delete_text = gtk_entry_delete_text;
1779 iface->insert_text = gtk_entry_real_insert_text;
1780 iface->delete_text = gtk_entry_real_delete_text;
1781 iface->get_chars = gtk_entry_get_chars;
1782 iface->set_selection_bounds = gtk_entry_set_selection_bounds;
1783 iface->get_selection_bounds = gtk_entry_get_selection_bounds;
1784 iface->set_position = gtk_entry_real_set_position;
1785 iface->get_position = gtk_entry_get_position;
1789 gtk_entry_cell_editable_init (GtkCellEditableIface *iface)
1791 iface->start_editing = gtk_entry_start_editing;
1795 gtk_entry_set_property (GObject *object,
1797 const GValue *value,
1800 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (object);
1801 GtkEntry *entry = GTK_ENTRY (object);
1807 gtk_entry_set_buffer (entry, g_value_get_object (value));
1812 gboolean new_value = g_value_get_boolean (value);
1814 if (new_value != entry->editable)
1816 widget = GTK_WIDGET (entry);
1819 _gtk_entry_reset_im_context (entry);
1820 if (gtk_widget_has_focus (widget))
1821 gtk_im_context_focus_out (entry->im_context);
1823 entry->preedit_length = 0;
1824 entry->preedit_cursor = 0;
1827 entry->editable = new_value;
1829 if (new_value && gtk_widget_has_focus (widget))
1830 gtk_im_context_focus_in (entry->im_context);
1832 gtk_entry_queue_draw (entry);
1837 case PROP_MAX_LENGTH:
1838 gtk_entry_set_max_length (entry, g_value_get_int (value));
1841 case PROP_VISIBILITY:
1842 gtk_entry_set_visibility (entry, g_value_get_boolean (value));
1845 case PROP_HAS_FRAME:
1846 gtk_entry_set_has_frame (entry, g_value_get_boolean (value));
1849 case PROP_INNER_BORDER:
1850 gtk_entry_set_inner_border (entry, g_value_get_boxed (value));
1853 case PROP_INVISIBLE_CHAR:
1854 gtk_entry_set_invisible_char (entry, g_value_get_uint (value));
1857 case PROP_ACTIVATES_DEFAULT:
1858 gtk_entry_set_activates_default (entry, g_value_get_boolean (value));
1861 case PROP_WIDTH_CHARS:
1862 gtk_entry_set_width_chars (entry, g_value_get_int (value));
1866 gtk_entry_set_text (entry, g_value_get_string (value));
1870 gtk_entry_set_alignment (entry, g_value_get_float (value));
1873 case PROP_TRUNCATE_MULTILINE:
1874 entry->truncate_multiline = g_value_get_boolean (value);
1877 case PROP_SHADOW_TYPE:
1878 priv->shadow_type = g_value_get_enum (value);
1881 case PROP_OVERWRITE_MODE:
1882 gtk_entry_set_overwrite_mode (entry, g_value_get_boolean (value));
1885 case PROP_INVISIBLE_CHAR_SET:
1886 if (g_value_get_boolean (value))
1887 priv->invisible_char_set = TRUE;
1889 gtk_entry_unset_invisible_char (entry);
1892 case PROP_CAPS_LOCK_WARNING:
1893 priv->caps_lock_warning = g_value_get_boolean (value);
1896 case PROP_PROGRESS_FRACTION:
1897 gtk_entry_set_progress_fraction (entry, g_value_get_double (value));
1900 case PROP_PROGRESS_PULSE_STEP:
1901 gtk_entry_set_progress_pulse_step (entry, g_value_get_double (value));
1904 case PROP_PIXBUF_PRIMARY:
1905 gtk_entry_set_icon_from_pixbuf (entry,
1906 GTK_ENTRY_ICON_PRIMARY,
1907 g_value_get_object (value));
1910 case PROP_PIXBUF_SECONDARY:
1911 gtk_entry_set_icon_from_pixbuf (entry,
1912 GTK_ENTRY_ICON_SECONDARY,
1913 g_value_get_object (value));
1916 case PROP_STOCK_PRIMARY:
1917 gtk_entry_set_icon_from_stock (entry,
1918 GTK_ENTRY_ICON_PRIMARY,
1919 g_value_get_string (value));
1922 case PROP_STOCK_SECONDARY:
1923 gtk_entry_set_icon_from_stock (entry,
1924 GTK_ENTRY_ICON_SECONDARY,
1925 g_value_get_string (value));
1928 case PROP_ICON_NAME_PRIMARY:
1929 gtk_entry_set_icon_from_icon_name (entry,
1930 GTK_ENTRY_ICON_PRIMARY,
1931 g_value_get_string (value));
1934 case PROP_ICON_NAME_SECONDARY:
1935 gtk_entry_set_icon_from_icon_name (entry,
1936 GTK_ENTRY_ICON_SECONDARY,
1937 g_value_get_string (value));
1940 case PROP_GICON_PRIMARY:
1941 gtk_entry_set_icon_from_gicon (entry,
1942 GTK_ENTRY_ICON_PRIMARY,
1943 g_value_get_object (value));
1946 case PROP_GICON_SECONDARY:
1947 gtk_entry_set_icon_from_gicon (entry,
1948 GTK_ENTRY_ICON_SECONDARY,
1949 g_value_get_object (value));
1952 case PROP_ACTIVATABLE_PRIMARY:
1953 gtk_entry_set_icon_activatable (entry,
1954 GTK_ENTRY_ICON_PRIMARY,
1955 g_value_get_boolean (value));
1958 case PROP_ACTIVATABLE_SECONDARY:
1959 gtk_entry_set_icon_activatable (entry,
1960 GTK_ENTRY_ICON_SECONDARY,
1961 g_value_get_boolean (value));
1964 case PROP_SENSITIVE_PRIMARY:
1965 gtk_entry_set_icon_sensitive (entry,
1966 GTK_ENTRY_ICON_PRIMARY,
1967 g_value_get_boolean (value));
1970 case PROP_SENSITIVE_SECONDARY:
1971 gtk_entry_set_icon_sensitive (entry,
1972 GTK_ENTRY_ICON_SECONDARY,
1973 g_value_get_boolean (value));
1976 case PROP_TOOLTIP_TEXT_PRIMARY:
1977 gtk_entry_set_icon_tooltip_text (entry,
1978 GTK_ENTRY_ICON_PRIMARY,
1979 g_value_get_string (value));
1982 case PROP_TOOLTIP_TEXT_SECONDARY:
1983 gtk_entry_set_icon_tooltip_text (entry,
1984 GTK_ENTRY_ICON_SECONDARY,
1985 g_value_get_string (value));
1988 case PROP_TOOLTIP_MARKUP_PRIMARY:
1989 gtk_entry_set_icon_tooltip_markup (entry,
1990 GTK_ENTRY_ICON_PRIMARY,
1991 g_value_get_string (value));
1994 case PROP_TOOLTIP_MARKUP_SECONDARY:
1995 gtk_entry_set_icon_tooltip_markup (entry,
1996 GTK_ENTRY_ICON_SECONDARY,
1997 g_value_get_string (value));
2000 case PROP_IM_MODULE:
2001 g_free (priv->im_module);
2002 priv->im_module = g_value_dup_string (value);
2003 if (GTK_IS_IM_MULTICONTEXT (entry->im_context))
2004 gtk_im_multicontext_set_context_id (GTK_IM_MULTICONTEXT (entry->im_context), priv->im_module);
2007 case PROP_EDITING_CANCELED:
2008 entry->editing_canceled = g_value_get_boolean (value);
2011 case PROP_SCROLL_OFFSET:
2012 case PROP_CURSOR_POSITION:
2014 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2020 gtk_entry_get_property (GObject *object,
2025 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (object);
2026 GtkEntry *entry = GTK_ENTRY (object);
2031 g_value_set_object (value, gtk_entry_get_buffer (entry));
2034 case PROP_CURSOR_POSITION:
2035 g_value_set_int (value, entry->current_pos);
2038 case PROP_SELECTION_BOUND:
2039 g_value_set_int (value, entry->selection_bound);
2043 g_value_set_boolean (value, entry->editable);
2046 case PROP_MAX_LENGTH:
2047 g_value_set_int (value, gtk_entry_buffer_get_max_length (get_buffer (entry)));
2050 case PROP_VISIBILITY:
2051 g_value_set_boolean (value, entry->visible);
2054 case PROP_HAS_FRAME:
2055 g_value_set_boolean (value, entry->has_frame);
2058 case PROP_INNER_BORDER:
2059 g_value_set_boxed (value, gtk_entry_get_inner_border (entry));
2062 case PROP_INVISIBLE_CHAR:
2063 g_value_set_uint (value, entry->invisible_char);
2066 case PROP_ACTIVATES_DEFAULT:
2067 g_value_set_boolean (value, entry->activates_default);
2070 case PROP_WIDTH_CHARS:
2071 g_value_set_int (value, entry->width_chars);
2074 case PROP_SCROLL_OFFSET:
2075 g_value_set_int (value, entry->scroll_offset);
2079 g_value_set_string (value, gtk_entry_get_text (entry));
2083 g_value_set_float (value, gtk_entry_get_alignment (entry));
2086 case PROP_TRUNCATE_MULTILINE:
2087 g_value_set_boolean (value, entry->truncate_multiline);
2090 case PROP_SHADOW_TYPE:
2091 g_value_set_enum (value, priv->shadow_type);
2094 case PROP_OVERWRITE_MODE:
2095 g_value_set_boolean (value, entry->overwrite_mode);
2098 case PROP_TEXT_LENGTH:
2099 g_value_set_uint (value, gtk_entry_buffer_get_length (get_buffer (entry)));
2102 case PROP_INVISIBLE_CHAR_SET:
2103 g_value_set_boolean (value, priv->invisible_char_set);
2106 case PROP_IM_MODULE:
2107 g_value_set_string (value, priv->im_module);
2110 case PROP_CAPS_LOCK_WARNING:
2111 g_value_set_boolean (value, priv->caps_lock_warning);
2114 case PROP_PROGRESS_FRACTION:
2115 g_value_set_double (value, priv->progress_fraction);
2118 case PROP_PROGRESS_PULSE_STEP:
2119 g_value_set_double (value, priv->progress_pulse_fraction);
2122 case PROP_PIXBUF_PRIMARY:
2123 g_value_set_object (value,
2124 gtk_entry_get_icon_pixbuf (entry,
2125 GTK_ENTRY_ICON_PRIMARY));
2128 case PROP_PIXBUF_SECONDARY:
2129 g_value_set_object (value,
2130 gtk_entry_get_icon_pixbuf (entry,
2131 GTK_ENTRY_ICON_SECONDARY));
2134 case PROP_STOCK_PRIMARY:
2135 g_value_set_string (value,
2136 gtk_entry_get_icon_stock (entry,
2137 GTK_ENTRY_ICON_PRIMARY));
2140 case PROP_STOCK_SECONDARY:
2141 g_value_set_string (value,
2142 gtk_entry_get_icon_stock (entry,
2143 GTK_ENTRY_ICON_SECONDARY));
2146 case PROP_ICON_NAME_PRIMARY:
2147 g_value_set_string (value,
2148 gtk_entry_get_icon_name (entry,
2149 GTK_ENTRY_ICON_PRIMARY));
2152 case PROP_ICON_NAME_SECONDARY:
2153 g_value_set_string (value,
2154 gtk_entry_get_icon_name (entry,
2155 GTK_ENTRY_ICON_SECONDARY));
2158 case PROP_GICON_PRIMARY:
2159 g_value_set_object (value,
2160 gtk_entry_get_icon_gicon (entry,
2161 GTK_ENTRY_ICON_PRIMARY));
2164 case PROP_GICON_SECONDARY:
2165 g_value_set_object (value,
2166 gtk_entry_get_icon_gicon (entry,
2167 GTK_ENTRY_ICON_SECONDARY));
2170 case PROP_STORAGE_TYPE_PRIMARY:
2171 g_value_set_enum (value,
2172 gtk_entry_get_icon_storage_type (entry,
2173 GTK_ENTRY_ICON_PRIMARY));
2176 case PROP_STORAGE_TYPE_SECONDARY:
2177 g_value_set_enum (value,
2178 gtk_entry_get_icon_storage_type (entry,
2179 GTK_ENTRY_ICON_SECONDARY));
2182 case PROP_ACTIVATABLE_PRIMARY:
2183 g_value_set_boolean (value,
2184 gtk_entry_get_icon_activatable (entry, GTK_ENTRY_ICON_PRIMARY));
2187 case PROP_ACTIVATABLE_SECONDARY:
2188 g_value_set_boolean (value,
2189 gtk_entry_get_icon_activatable (entry, GTK_ENTRY_ICON_SECONDARY));
2192 case PROP_SENSITIVE_PRIMARY:
2193 g_value_set_boolean (value,
2194 gtk_entry_get_icon_sensitive (entry, GTK_ENTRY_ICON_PRIMARY));
2197 case PROP_SENSITIVE_SECONDARY:
2198 g_value_set_boolean (value,
2199 gtk_entry_get_icon_sensitive (entry, GTK_ENTRY_ICON_SECONDARY));
2202 case PROP_TOOLTIP_TEXT_PRIMARY:
2203 g_value_take_string (value,
2204 gtk_entry_get_icon_tooltip_text (entry, GTK_ENTRY_ICON_PRIMARY));
2207 case PROP_TOOLTIP_TEXT_SECONDARY:
2208 g_value_take_string (value,
2209 gtk_entry_get_icon_tooltip_text (entry, GTK_ENTRY_ICON_SECONDARY));
2212 case PROP_TOOLTIP_MARKUP_PRIMARY:
2213 g_value_take_string (value,
2214 gtk_entry_get_icon_tooltip_markup (entry, GTK_ENTRY_ICON_PRIMARY));
2217 case PROP_TOOLTIP_MARKUP_SECONDARY:
2218 g_value_take_string (value,
2219 gtk_entry_get_icon_tooltip_markup (entry, GTK_ENTRY_ICON_SECONDARY));
2222 case PROP_EDITING_CANCELED:
2223 g_value_set_boolean (value,
2224 entry->editing_canceled);
2228 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2234 find_invisible_char (GtkWidget *widget)
2236 PangoLayout *layout;
2237 PangoAttrList *attr_list;
2239 gunichar invisible_chars [] = {
2241 0x25cf, /* BLACK CIRCLE */
2242 0x2022, /* BULLET */
2243 0x2731, /* HEAVY ASTERISK */
2244 0x273a /* SIXTEEN POINTED ASTERISK */
2247 if (gtk_widget_get_style (widget))
2248 gtk_widget_style_get (widget,
2249 "invisible-char", &invisible_chars[0],
2252 layout = gtk_widget_create_pango_layout (widget, NULL);
2254 attr_list = pango_attr_list_new ();
2255 pango_attr_list_insert (attr_list, pango_attr_fallback_new (FALSE));
2257 pango_layout_set_attributes (layout, attr_list);
2258 pango_attr_list_unref (attr_list);
2260 for (i = (invisible_chars[0] != 0 ? 0 : 1); i < G_N_ELEMENTS (invisible_chars); i++)
2262 gchar text[7] = { 0, };
2265 len = g_unichar_to_utf8 (invisible_chars[i], text);
2266 pango_layout_set_text (layout, text, len);
2268 count = pango_layout_get_unknown_glyphs_count (layout);
2272 g_object_unref (layout);
2273 return invisible_chars[i];
2277 g_object_unref (layout);
2283 gtk_entry_init (GtkEntry *entry)
2285 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2287 gtk_widget_set_can_focus (GTK_WIDGET (entry), TRUE);
2289 entry->editable = TRUE;
2290 entry->visible = TRUE;
2291 entry->invisible_char = find_invisible_char (GTK_WIDGET (entry));
2292 entry->dnd_position = -1;
2293 entry->width_chars = -1;
2294 entry->is_cell_renderer = FALSE;
2295 entry->editing_canceled = FALSE;
2296 entry->has_frame = TRUE;
2297 entry->truncate_multiline = FALSE;
2298 priv->shadow_type = GTK_SHADOW_IN;
2300 priv->caps_lock_warning = TRUE;
2301 priv->caps_lock_warning_shown = FALSE;
2302 priv->progress_fraction = 0.0;
2303 priv->progress_pulse_fraction = 0.1;
2305 gtk_drag_dest_set (GTK_WIDGET (entry),
2306 GTK_DEST_DEFAULT_HIGHLIGHT,
2308 GDK_ACTION_COPY | GDK_ACTION_MOVE);
2309 gtk_drag_dest_add_text_targets (GTK_WIDGET (entry));
2311 /* This object is completely private. No external entity can gain a reference
2312 * to it; so we create it here and destroy it in finalize().
2314 entry->im_context = gtk_im_multicontext_new ();
2316 g_signal_connect (entry->im_context, "commit",
2317 G_CALLBACK (gtk_entry_commit_cb), entry);
2318 g_signal_connect (entry->im_context, "preedit-changed",
2319 G_CALLBACK (gtk_entry_preedit_changed_cb), entry);
2320 g_signal_connect (entry->im_context, "retrieve-surrounding",
2321 G_CALLBACK (gtk_entry_retrieve_surrounding_cb), entry);
2322 g_signal_connect (entry->im_context, "delete-surrounding",
2323 G_CALLBACK (gtk_entry_delete_surrounding_cb), entry);
2328 get_icon_width (GtkEntry *entry,
2329 GtkEntryIconPosition icon_pos)
2331 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2332 EntryIconInfo *icon_info = priv->icons[icon_pos];
2334 GtkSettings *settings;
2335 gint menu_icon_width;
2337 if (!icon_info || icon_info->pixbuf == NULL)
2340 screen = gtk_widget_get_screen (GTK_WIDGET (entry));
2341 settings = gtk_settings_get_for_screen (screen);
2343 gtk_icon_size_lookup_for_settings (settings, GTK_ICON_SIZE_MENU,
2344 &menu_icon_width, NULL);
2346 return MAX (gdk_pixbuf_get_width (icon_info->pixbuf), menu_icon_width);
2350 get_icon_allocations (GtkEntry *entry,
2351 GtkAllocation *primary,
2352 GtkAllocation *secondary)
2355 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2356 gint x, y, width, height;
2358 get_text_area_size (entry, &x, &y, &width, &height);
2360 if (gtk_widget_has_focus (GTK_WIDGET (entry)) && !priv->interior_focus)
2361 y += priv->focus_width;
2364 primary->height = height;
2365 primary->width = get_icon_width (entry, GTK_ENTRY_ICON_PRIMARY);
2366 if (primary->width > 0)
2367 primary->width += 2 * priv->icon_margin;
2370 secondary->height = height;
2371 secondary->width = get_icon_width (entry, GTK_ENTRY_ICON_SECONDARY);
2372 if (secondary->width > 0)
2373 secondary->width += 2 * priv->icon_margin;
2375 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
2377 primary->x = x + width - primary->width;
2383 secondary->x = x + width - secondary->width;
2389 begin_change (GtkEntry *entry)
2391 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2393 priv->change_count++;
2397 end_change (GtkEntry *entry)
2399 GtkEditable *editable = GTK_EDITABLE (entry);
2400 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2402 g_return_if_fail (priv->change_count > 0);
2404 priv->change_count--;
2406 if (priv->change_count == 0)
2408 if (priv->real_changed)
2410 g_signal_emit_by_name (editable, "changed");
2411 priv->real_changed = FALSE;
2417 emit_changed (GtkEntry *entry)
2419 GtkEditable *editable = GTK_EDITABLE (entry);
2420 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2422 if (priv->change_count == 0)
2423 g_signal_emit_by_name (editable, "changed");
2425 priv->real_changed = TRUE;
2429 gtk_entry_destroy (GtkObject *object)
2431 GtkEntry *entry = GTK_ENTRY (object);
2433 entry->current_pos = entry->selection_bound = 0;
2434 _gtk_entry_reset_im_context (entry);
2435 gtk_entry_reset_layout (entry);
2437 if (entry->blink_timeout)
2439 g_source_remove (entry->blink_timeout);
2440 entry->blink_timeout = 0;
2443 if (entry->recompute_idle)
2445 g_source_remove (entry->recompute_idle);
2446 entry->recompute_idle = 0;
2449 GTK_OBJECT_CLASS (gtk_entry_parent_class)->destroy (object);
2453 gtk_entry_dispose (GObject *object)
2455 GtkEntry *entry = GTK_ENTRY (object);
2456 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2458 gtk_entry_set_icon_from_pixbuf (entry, GTK_ENTRY_ICON_PRIMARY, NULL);
2459 gtk_entry_set_icon_tooltip_markup (entry, GTK_ENTRY_ICON_PRIMARY, NULL);
2460 gtk_entry_set_icon_from_pixbuf (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
2461 gtk_entry_set_icon_tooltip_markup (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
2465 buffer_disconnect_signals (entry);
2466 g_object_unref (priv->buffer);
2467 priv->buffer = NULL;
2470 G_OBJECT_CLASS (gtk_entry_parent_class)->dispose (object);
2474 gtk_entry_finalize (GObject *object)
2476 GtkEntry *entry = GTK_ENTRY (object);
2477 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2478 EntryIconInfo *icon_info = NULL;
2481 for (i = 0; i < MAX_ICONS; i++)
2483 if ((icon_info = priv->icons[i]) != NULL)
2485 if (icon_info->target_list != NULL)
2487 gtk_target_list_unref (icon_info->target_list);
2488 icon_info->target_list = NULL;
2491 g_slice_free (EntryIconInfo, icon_info);
2492 priv->icons[i] = NULL;
2496 gtk_entry_set_completion (entry, NULL);
2498 if (entry->cached_layout)
2499 g_object_unref (entry->cached_layout);
2501 g_object_unref (entry->im_context);
2503 if (entry->blink_timeout)
2504 g_source_remove (entry->blink_timeout);
2506 if (entry->recompute_idle)
2507 g_source_remove (entry->recompute_idle);
2509 g_free (priv->im_module);
2511 G_OBJECT_CLASS (gtk_entry_parent_class)->finalize (object);
2515 gtk_entry_get_display_mode (GtkEntry *entry)
2517 GtkEntryPrivate *priv;
2519 return DISPLAY_NORMAL;
2520 priv = GTK_ENTRY_GET_PRIVATE (entry);
2521 if (entry->invisible_char == 0 && priv->invisible_char_set)
2522 return DISPLAY_BLANK;
2523 return DISPLAY_INVISIBLE;
2527 gtk_entry_get_display_text (GtkEntry *entry,
2531 GtkEntryPasswordHint *password_hint;
2532 GtkEntryPrivate *priv;
2533 gunichar invisible_char;
2543 priv = GTK_ENTRY_GET_PRIVATE (entry);
2544 text = gtk_entry_buffer_get_text (get_buffer (entry));
2545 length = gtk_entry_buffer_get_length (get_buffer (entry));
2549 if (start_pos > length)
2552 if (end_pos <= start_pos)
2553 return g_strdup ("");
2554 else if (entry->visible)
2556 start = g_utf8_offset_to_pointer (text, start_pos);
2557 end = g_utf8_offset_to_pointer (start, end_pos - start_pos);
2558 return g_strndup (start, end - start);
2562 str = g_string_sized_new (length * 2);
2564 /* Figure out what our invisible char is and encode it */
2565 if (!entry->invisible_char)
2566 invisible_char = priv->invisible_char_set ? ' ' : '*';
2568 invisible_char = entry->invisible_char;
2569 char_len = g_unichar_to_utf8 (invisible_char, char_str);
2572 * Add hidden characters for each character in the text
2573 * buffer. If there is a password hint, then keep that
2574 * character visible.
2577 password_hint = g_object_get_qdata (G_OBJECT (entry), quark_password_hint);
2578 for (i = start_pos; i < end_pos; ++i)
2580 if (password_hint && i == password_hint->position)
2582 start = g_utf8_offset_to_pointer (text, i);
2583 g_string_append_len (str, start, g_utf8_next_char (start) - start);
2587 g_string_append_len (str, char_str, char_len);
2591 return g_string_free (str, FALSE);
2597 update_cursors (GtkWidget *widget)
2599 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2600 EntryIconInfo *icon_info = NULL;
2601 GdkDisplay *display;
2605 for (i = 0; i < MAX_ICONS; i++)
2607 if ((icon_info = priv->icons[i]) != NULL)
2609 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
2610 gdk_window_show_unraised (icon_info->window);
2612 /* The icon windows are not children of the visible entry window,
2613 * thus we can't just inherit the xterm cursor. Slight complication
2614 * here is that for the entry, insensitive => arrow cursor, but for
2615 * an icon in a sensitive entry, insensitive => xterm cursor.
2617 if (gtk_widget_is_sensitive (widget) &&
2618 (icon_info->insensitive ||
2619 (icon_info->nonactivatable && icon_info->target_list == NULL)))
2621 display = gtk_widget_get_display (widget);
2622 cursor = gdk_cursor_new_for_display (display, GDK_XTERM);
2623 gdk_window_set_cursor (icon_info->window, cursor);
2624 gdk_cursor_unref (cursor);
2628 gdk_window_set_cursor (icon_info->window, NULL);
2635 realize_icon_info (GtkWidget *widget,
2636 GtkEntryIconPosition icon_pos)
2638 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2639 EntryIconInfo *icon_info = priv->icons[icon_pos];
2640 GdkWindowAttr attributes;
2641 gint attributes_mask;
2643 g_return_if_fail (icon_info != NULL);
2647 attributes.width = 1;
2648 attributes.height = 1;
2649 attributes.window_type = GDK_WINDOW_CHILD;
2650 attributes.wclass = GDK_INPUT_OUTPUT;
2651 attributes.visual = gtk_widget_get_visual (widget);
2652 attributes.event_mask = gtk_widget_get_events (widget);
2653 attributes.event_mask |= (GDK_EXPOSURE_MASK |
2654 GDK_BUTTON_PRESS_MASK |
2655 GDK_BUTTON_RELEASE_MASK |
2656 GDK_BUTTON1_MOTION_MASK |
2657 GDK_BUTTON3_MOTION_MASK |
2658 GDK_POINTER_MOTION_HINT_MASK |
2659 GDK_POINTER_MOTION_MASK |
2660 GDK_ENTER_NOTIFY_MASK |
2661 GDK_LEAVE_NOTIFY_MASK);
2662 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL;
2664 icon_info->window = gdk_window_new (gtk_widget_get_window (widget),
2667 gdk_window_set_user_data (icon_info->window, widget);
2668 gdk_window_set_background (icon_info->window,
2669 >k_widget_get_style (widget)->base[gtk_widget_get_state (widget)]);
2671 gtk_widget_queue_resize (widget);
2674 static EntryIconInfo*
2675 construct_icon_info (GtkWidget *widget,
2676 GtkEntryIconPosition icon_pos)
2678 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2679 EntryIconInfo *icon_info;
2681 g_return_val_if_fail (priv->icons[icon_pos] == NULL, NULL);
2683 icon_info = g_slice_new0 (EntryIconInfo);
2684 priv->icons[icon_pos] = icon_info;
2686 if (gtk_widget_get_realized (widget))
2687 realize_icon_info (widget, icon_pos);
2693 gtk_entry_map (GtkWidget *widget)
2695 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2696 EntryIconInfo *icon_info = NULL;
2699 GTK_WIDGET_CLASS (gtk_entry_parent_class)->map (widget);
2701 for (i = 0; i < MAX_ICONS; i++)
2703 if ((icon_info = priv->icons[i]) != NULL)
2705 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
2706 gdk_window_show (icon_info->window);
2710 update_cursors (widget);
2714 gtk_entry_unmap (GtkWidget *widget)
2716 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2717 EntryIconInfo *icon_info = NULL;
2720 for (i = 0; i < MAX_ICONS; i++)
2722 if ((icon_info = priv->icons[i]) != NULL)
2724 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
2725 gdk_window_hide (icon_info->window);
2729 GTK_WIDGET_CLASS (gtk_entry_parent_class)->unmap (widget);
2733 gtk_entry_realize (GtkWidget *widget)
2736 GtkEntryPrivate *priv;
2739 EntryIconInfo *icon_info;
2741 GdkWindowAttr attributes;
2742 gint attributes_mask;
2745 gtk_widget_set_realized (widget, TRUE);
2746 entry = GTK_ENTRY (widget);
2747 priv = GTK_ENTRY_GET_PRIVATE (entry);
2749 attributes.window_type = GDK_WINDOW_CHILD;
2751 get_widget_window_size (entry, &attributes.x, &attributes.y, &attributes.width, &attributes.height);
2753 attributes.wclass = GDK_INPUT_OUTPUT;
2754 attributes.visual = gtk_widget_get_visual (widget);
2755 attributes.event_mask = gtk_widget_get_events (widget);
2756 attributes.event_mask |= (GDK_EXPOSURE_MASK |
2757 GDK_BUTTON_PRESS_MASK |
2758 GDK_BUTTON_RELEASE_MASK |
2759 GDK_BUTTON1_MOTION_MASK |
2760 GDK_BUTTON3_MOTION_MASK |
2761 GDK_POINTER_MOTION_HINT_MASK |
2762 GDK_POINTER_MOTION_MASK |
2763 GDK_ENTER_NOTIFY_MASK |
2764 GDK_LEAVE_NOTIFY_MASK);
2765 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL;
2767 window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, attributes_mask);
2768 gtk_widget_set_window (widget, window);
2769 gdk_window_set_user_data (window, entry);
2771 get_text_area_size (entry, &attributes.x, &attributes.y, &attributes.width, &attributes.height);
2773 if (gtk_widget_is_sensitive (widget))
2775 attributes.cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
2776 attributes_mask |= GDK_WA_CURSOR;
2779 entry->text_area = gdk_window_new (window, &attributes, attributes_mask);
2781 gdk_window_set_user_data (entry->text_area, entry);
2783 if (attributes_mask & GDK_WA_CURSOR)
2784 gdk_cursor_unref (attributes.cursor);
2786 gtk_widget_style_attach (widget);
2788 style = gtk_widget_get_style (widget);
2789 state = gtk_widget_get_state (widget);
2790 gdk_window_set_background (window, &style->base[state]);
2791 gdk_window_set_background (entry->text_area, &style->base[state]);
2793 gdk_window_show (entry->text_area);
2795 gtk_im_context_set_client_window (entry->im_context, entry->text_area);
2797 gtk_entry_adjust_scroll (entry);
2798 gtk_entry_update_primary_selection (entry);
2801 /* If the icon positions are already setup, create their windows.
2802 * Otherwise if they don't exist yet, then construct_icon_info()
2803 * will create the windows once the widget is already realized.
2805 for (i = 0; i < MAX_ICONS; i++)
2807 if ((icon_info = priv->icons[i]) != NULL)
2809 if (icon_info->window == NULL)
2810 realize_icon_info (widget, i);
2816 gtk_entry_unrealize (GtkWidget *widget)
2818 GtkEntry *entry = GTK_ENTRY (widget);
2819 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2820 GtkClipboard *clipboard;
2821 EntryIconInfo *icon_info;
2824 gtk_entry_reset_layout (entry);
2826 gtk_im_context_set_client_window (entry->im_context, NULL);
2828 clipboard = gtk_widget_get_clipboard (widget, GDK_SELECTION_PRIMARY);
2829 if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (entry))
2830 gtk_clipboard_clear (clipboard);
2832 if (entry->text_area)
2834 gdk_window_set_user_data (entry->text_area, NULL);
2835 gdk_window_destroy (entry->text_area);
2836 entry->text_area = NULL;
2839 if (entry->popup_menu)
2841 gtk_widget_destroy (entry->popup_menu);
2842 entry->popup_menu = NULL;
2845 GTK_WIDGET_CLASS (gtk_entry_parent_class)->unrealize (widget);
2847 for (i = 0; i < MAX_ICONS; i++)
2849 if ((icon_info = priv->icons[i]) != NULL)
2851 if (icon_info->window != NULL)
2853 gdk_window_destroy (icon_info->window);
2854 icon_info->window = NULL;
2861 _gtk_entry_get_borders (GtkEntry *entry,
2865 GtkWidget *widget = GTK_WIDGET (entry);
2866 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2869 if (entry->has_frame)
2871 style = gtk_widget_get_style (widget);
2873 *xborder = style->xthickness;
2874 *yborder = style->ythickness;
2882 if (!priv->interior_focus)
2884 *xborder += priv->focus_width;
2885 *yborder += priv->focus_width;
2890 gtk_entry_size_request (GtkWidget *widget,
2891 GtkRequisition *requisition)
2893 GtkEntry *entry = GTK_ENTRY (widget);
2894 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2895 PangoFontMetrics *metrics;
2896 gint xborder, yborder;
2897 GtkBorder inner_border;
2898 PangoContext *context;
2899 int icon_widths = 0;
2902 gtk_widget_ensure_style (widget);
2903 context = gtk_widget_get_pango_context (widget);
2904 metrics = pango_context_get_metrics (context,
2905 gtk_widget_get_style (widget)->font_desc,
2906 pango_context_get_language (context));
2908 entry->ascent = pango_font_metrics_get_ascent (metrics);
2909 entry->descent = pango_font_metrics_get_descent (metrics);
2911 _gtk_entry_get_borders (entry, &xborder, &yborder);
2912 _gtk_entry_effective_inner_border (entry, &inner_border);
2914 if (entry->width_chars < 0)
2915 requisition->width = MIN_ENTRY_WIDTH + xborder * 2 + inner_border.left + inner_border.right;
2918 gint char_width = pango_font_metrics_get_approximate_char_width (metrics);
2919 gint digit_width = pango_font_metrics_get_approximate_digit_width (metrics);
2920 gint char_pixels = (MAX (char_width, digit_width) + PANGO_SCALE - 1) / PANGO_SCALE;
2922 requisition->width = char_pixels * entry->width_chars + xborder * 2 + inner_border.left + inner_border.right;
2925 requisition->height = PANGO_PIXELS (entry->ascent + entry->descent) + yborder * 2 + inner_border.top + inner_border.bottom;
2927 for (i = 0; i < MAX_ICONS; i++)
2929 icon_width = get_icon_width (entry, i);
2931 icon_widths += icon_width + 2 * priv->icon_margin;
2934 if (icon_widths > requisition->width)
2935 requisition->width += icon_widths;
2937 pango_font_metrics_unref (metrics);
2941 place_windows (GtkEntry *entry)
2943 GtkWidget *widget = GTK_WIDGET (entry);
2944 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2945 gint x, y, width, height;
2946 GtkAllocation primary;
2947 GtkAllocation secondary;
2948 EntryIconInfo *icon_info = NULL;
2950 get_text_area_size (entry, &x, &y, &width, &height);
2951 get_icon_allocations (entry, &primary, &secondary);
2953 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
2954 y += priv->focus_width;
2956 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
2957 x += secondary.width;
2960 width -= primary.width + secondary.width;
2962 if ((icon_info = priv->icons[GTK_ENTRY_ICON_PRIMARY]) != NULL)
2963 gdk_window_move_resize (icon_info->window,
2964 primary.x, primary.y,
2965 primary.width, primary.height);
2967 if ((icon_info = priv->icons[GTK_ENTRY_ICON_SECONDARY]) != NULL)
2968 gdk_window_move_resize (icon_info->window,
2969 secondary.x, secondary.y,
2970 secondary.width, secondary.height);
2972 gdk_window_move_resize (entry->text_area, x, y, width, height);
2976 gtk_entry_get_text_area_size (GtkEntry *entry,
2982 GtkWidget *widget = GTK_WIDGET (entry);
2983 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2984 GtkAllocation allocation;
2985 GtkRequisition requisition;
2987 gint xborder, yborder;
2989 gtk_size_request_get_size (GTK_SIZE_REQUEST (widget),
2990 &requisition, NULL);
2991 gtk_widget_get_allocation (widget, &allocation);
2992 _gtk_entry_get_borders (entry, &xborder, &yborder);
2994 if (gtk_widget_get_realized (widget))
2995 gdk_drawable_get_size (gtk_widget_get_window (widget), NULL, &frame_height);
2997 frame_height = requisition.height;
2999 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3000 frame_height -= 2 * priv->focus_width;
3006 *y = frame_height / 2 - (requisition.height - yborder * 2) / 2;
3009 *width = allocation.width - xborder * 2;
3012 *height = requisition.height - yborder * 2;
3016 get_text_area_size (GtkEntry *entry,
3022 GtkEntryClass *class;
3024 g_return_if_fail (GTK_IS_ENTRY (entry));
3026 class = GTK_ENTRY_GET_CLASS (entry);
3028 if (class->get_text_area_size)
3029 class->get_text_area_size (entry, x, y, width, height);
3034 get_widget_window_size (GtkEntry *entry,
3040 GtkAllocation allocation;
3041 GtkRequisition requisition;
3042 GtkWidget *widget = GTK_WIDGET (entry);
3044 gtk_size_request_get_size (GTK_SIZE_REQUEST (widget),
3045 &requisition, NULL);
3046 gtk_widget_get_allocation (widget, &allocation);
3053 if (entry->is_cell_renderer)
3056 *y = allocation.y + (allocation.height - requisition.height) / 2;
3060 *width = allocation.width;
3064 if (entry->is_cell_renderer)
3065 *height = allocation.height;
3067 *height = requisition.height;
3072 _gtk_entry_effective_inner_border (GtkEntry *entry,
3075 GtkBorder *tmp_border;
3077 tmp_border = g_object_get_qdata (G_OBJECT (entry), quark_inner_border);
3081 *border = *tmp_border;
3085 gtk_widget_style_get (GTK_WIDGET (entry), "inner-border", &tmp_border, NULL);
3089 *border = *tmp_border;
3090 gtk_border_free (tmp_border);
3094 *border = default_inner_border;
3098 gtk_entry_size_allocate (GtkWidget *widget,
3099 GtkAllocation *allocation)
3101 GtkEntry *entry = GTK_ENTRY (widget);
3103 gtk_widget_set_allocation (widget, allocation);
3105 if (gtk_widget_get_realized (widget))
3107 gint x, y, width, height;
3108 GtkEntryCompletion* completion;
3110 get_widget_window_size (entry, &x, &y, &width, &height);
3111 gdk_window_move_resize (gtk_widget_get_window (widget),
3112 x, y, width, height);
3114 place_windows (entry);
3115 gtk_entry_recompute (entry);
3117 completion = gtk_entry_get_completion (entry);
3118 if (completion && gtk_widget_get_mapped (completion->priv->popup_window))
3119 _gtk_entry_completion_resize_popup (completion);
3123 /* Kudos to the gnome-panel guys. */
3125 colorshift_pixbuf (GdkPixbuf *dest,
3130 gint width, height, has_alpha, src_rowstride, dest_rowstride;
3131 guchar *target_pixels;
3132 guchar *original_pixels;
3138 has_alpha = gdk_pixbuf_get_has_alpha (src);
3139 width = gdk_pixbuf_get_width (src);
3140 height = gdk_pixbuf_get_height (src);
3141 src_rowstride = gdk_pixbuf_get_rowstride (src);
3142 dest_rowstride = gdk_pixbuf_get_rowstride (dest);
3143 original_pixels = gdk_pixbuf_get_pixels (src);
3144 target_pixels = gdk_pixbuf_get_pixels (dest);
3146 for (i = 0; i < height; i++)
3148 pix_dest = target_pixels + i * dest_rowstride;
3149 pix_src = original_pixels + i * src_rowstride;
3151 for (j = 0; j < width; j++)
3158 *(pix_dest++) = CLAMP (val, 0, 255);
3161 *(pix_dest++) = CLAMP (val, 0, 255);
3164 *(pix_dest++) = CLAMP (val, 0, 255);
3167 *(pix_dest++) = *(pix_src++);
3173 should_prelight (GtkEntry *entry,
3174 GtkEntryIconPosition icon_pos)
3176 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3177 EntryIconInfo *icon_info = priv->icons[icon_pos];
3183 if (icon_info->nonactivatable && icon_info->target_list == NULL)
3186 if (icon_info->pressed)
3189 gtk_widget_style_get (GTK_WIDGET (entry),
3190 "icon-prelight", &prelight,
3197 draw_icon (GtkWidget *widget,
3199 GtkEntryIconPosition icon_pos)
3201 GtkEntry *entry = GTK_ENTRY (widget);
3202 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3203 EntryIconInfo *icon_info = priv->icons[icon_pos];
3205 gint x, y, width, height;
3210 gtk_entry_ensure_pixbuf (entry, icon_pos);
3212 if (icon_info->pixbuf == NULL)
3215 gdk_drawable_get_size (icon_info->window, &width, &height);
3217 /* size_allocate hasn't been called yet. These are the default values.
3219 if (width == 1 || height == 1)
3222 pixbuf = icon_info->pixbuf;
3223 g_object_ref (pixbuf);
3225 if (gdk_pixbuf_get_height (pixbuf) > height)
3227 GdkPixbuf *temp_pixbuf;
3230 scale = height - 2 * priv->icon_margin;
3231 temp_pixbuf = gdk_pixbuf_scale_simple (pixbuf, scale, scale,
3232 GDK_INTERP_BILINEAR);
3233 g_object_unref (pixbuf);
3234 pixbuf = temp_pixbuf;
3237 x = (width - gdk_pixbuf_get_width (pixbuf)) / 2;
3238 y = (height - gdk_pixbuf_get_height (pixbuf)) / 2;
3240 if (!gtk_widget_is_sensitive (widget) ||
3241 icon_info->insensitive)
3243 GdkPixbuf *temp_pixbuf;
3245 temp_pixbuf = gdk_pixbuf_copy (pixbuf);
3246 gdk_pixbuf_saturate_and_pixelate (pixbuf,
3250 g_object_unref (pixbuf);
3251 pixbuf = temp_pixbuf;
3253 else if (icon_info->prelight)
3255 GdkPixbuf *temp_pixbuf;
3257 temp_pixbuf = gdk_pixbuf_copy (pixbuf);
3258 colorshift_pixbuf (temp_pixbuf, pixbuf, 30);
3259 g_object_unref (pixbuf);
3260 pixbuf = temp_pixbuf;
3263 gdk_cairo_set_source_pixbuf (cr, pixbuf, x, y);
3266 g_object_unref (pixbuf);
3271 gtk_entry_draw_frame (GtkWidget *widget,
3274 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
3277 gint x = 0, y = 0, width, height;
3280 window = gtk_widget_get_window (widget);
3282 gdk_drawable_get_size (window, &width, &height);
3284 /* Fix a problem with some themes which assume that entry->text_area's
3285 * width equals widget->window's width
3286 * http://bugzilla.gnome.org/show_bug.cgi?id=466000 */
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, cr,
3311 state, priv->shadow_type,
3312 widget, "entry", x, y, width, height);
3315 gtk_entry_draw_progress (widget, cr, window);
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, cr,
3325 gtk_widget_get_state (widget),
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,
3420 gint x, y, width, height;
3423 get_progress_area (widget, &x, &y, &width, &height);
3425 if ((width <= 0) || (height <= 0))
3428 if (window != gtk_widget_get_window (widget))
3432 gdk_window_get_position (window, &pos_x, &pos_y);
3438 state = GTK_STATE_SELECTED;
3439 if (!gtk_widget_get_sensitive (widget))
3440 state = GTK_STATE_INSENSITIVE;
3442 gtk_paint_box (gtk_widget_get_style (widget), cr,
3443 state, GTK_SHADOW_OUT,
3444 widget, "entry-progress",
3450 gtk_entry_draw (GtkWidget *widget,
3453 GtkEntry *entry = GTK_ENTRY (widget);
3456 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3459 style = gtk_widget_get_style (widget);
3461 state = gtk_widget_has_focus (widget) ?
3462 GTK_STATE_ACTIVE : gtk_widget_get_state (widget);
3464 if (gtk_cairo_should_draw_window (cr, gtk_widget_get_window (widget)))
3465 gtk_entry_draw_frame (widget, cr);
3467 if (gtk_cairo_should_draw_window (cr, entry->text_area))
3469 gint x, y, width, height;
3473 gdk_drawable_get_size (entry->text_area, &width, &height);
3474 gdk_window_get_position (entry->text_area, &x, &y);
3475 cairo_translate (cr, x, y);
3477 gtk_paint_flat_box (style, cr,
3478 state, GTK_SHADOW_NONE,
3480 0, 0, width, height);
3482 gtk_entry_draw_progress (widget, cr, entry->text_area);
3484 if (entry->dnd_position != -1)
3485 gtk_entry_draw_cursor (GTK_ENTRY (widget), cr, CURSOR_DND);
3487 gtk_entry_draw_text (GTK_ENTRY (widget), cr);
3489 /* When no text is being displayed at all, don't show the cursor */
3490 if (gtk_entry_get_display_mode (entry) != DISPLAY_BLANK &&
3491 gtk_widget_has_focus (widget) &&
3492 entry->selection_bound == entry->current_pos && entry->cursor_visible)
3493 gtk_entry_draw_cursor (GTK_ENTRY (widget), cr, CURSOR_STANDARD);
3498 for (i = 0; i < MAX_ICONS; i++)
3500 EntryIconInfo *icon_info = priv->icons[i];
3502 if (icon_info != NULL && gtk_cairo_should_draw_window (cr, icon_info->window))
3504 gint x, y, width, height;
3508 gdk_drawable_get_size (icon_info->window, &width, &height);
3509 gdk_window_get_position (icon_info->window, &x, &y);
3510 cairo_translate (cr, x, y);
3512 gtk_paint_flat_box (style, cr,
3513 state, GTK_SHADOW_NONE,
3515 0, 0, width, height);
3517 gtk_entry_draw_progress (widget, cr, icon_info->window);
3518 draw_icon (widget, cr, i);
3530 gtk_entry_enter_notify (GtkWidget *widget,
3531 GdkEventCrossing *event)
3533 GtkEntry *entry = GTK_ENTRY (widget);
3534 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3537 for (i = 0; i < MAX_ICONS; i++)
3539 EntryIconInfo *icon_info = priv->icons[i];
3541 if (icon_info != NULL && event->window == icon_info->window)
3543 if (should_prelight (entry, i))
3545 icon_info->prelight = TRUE;
3546 gtk_widget_queue_draw (widget);
3557 gtk_entry_leave_notify (GtkWidget *widget,
3558 GdkEventCrossing *event)
3560 GtkEntry *entry = GTK_ENTRY (widget);
3561 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3564 for (i = 0; i < MAX_ICONS; i++)
3566 EntryIconInfo *icon_info = priv->icons[i];
3568 if (icon_info != NULL && event->window == icon_info->window)
3570 /* a grab means that we may never see the button release */
3571 if (event->mode == GDK_CROSSING_GRAB || event->mode == GDK_CROSSING_GTK_GRAB)
3572 icon_info->pressed = FALSE;
3574 if (should_prelight (entry, i))
3576 icon_info->prelight = FALSE;
3577 gtk_widget_queue_draw (widget);
3588 gtk_entry_get_pixel_ranges (GtkEntry *entry,
3592 gint start_char, end_char;
3594 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start_char, &end_char))
3596 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
3597 PangoLayoutLine *line = pango_layout_get_lines_readonly (layout)->data;
3598 const char *text = pango_layout_get_text (layout);
3599 gint start_index = g_utf8_offset_to_pointer (text, start_char) - text;
3600 gint end_index = g_utf8_offset_to_pointer (text, end_char) - text;
3601 gint real_n_ranges, i;
3603 pango_layout_line_get_x_ranges (line, start_index, end_index, ranges, &real_n_ranges);
3609 for (i = 0; i < real_n_ranges; ++i)
3611 r[2 * i + 1] = (r[2 * i + 1] - r[2 * i]) / PANGO_SCALE;
3612 r[2 * i] = r[2 * i] / PANGO_SCALE;
3617 *n_ranges = real_n_ranges;
3629 in_selection (GtkEntry *entry,
3634 gint retval = FALSE;
3636 gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
3638 for (i = 0; i < n_ranges; ++i)
3640 if (x >= ranges[2 * i] && x < ranges[2 * i] + ranges[2 * i + 1])
3652 gtk_entry_button_press (GtkWidget *widget,
3653 GdkEventButton *event)
3655 GtkEntry *entry = GTK_ENTRY (widget);
3656 GtkEditable *editable = GTK_EDITABLE (widget);
3657 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3658 EntryIconInfo *icon_info = NULL;
3660 gint sel_start, sel_end;
3663 for (i = 0; i < MAX_ICONS; i++)
3665 icon_info = priv->icons[i];
3667 if (!icon_info || icon_info->insensitive)
3670 if (event->window == icon_info->window)
3672 if (should_prelight (entry, i))
3674 icon_info->prelight = FALSE;
3675 gtk_widget_queue_draw (widget);
3678 priv->start_x = event->x;
3679 priv->start_y = event->y;
3680 icon_info->pressed = TRUE;
3682 if (!icon_info->nonactivatable)
3683 g_signal_emit (entry, signals[ICON_PRESS], 0, i, event);
3689 if (event->window != entry->text_area ||
3690 (entry->button && event->button != entry->button))
3693 gtk_entry_reset_blink_time (entry);
3695 entry->button = event->button;
3697 if (!gtk_widget_has_focus (widget))
3699 entry->in_click = TRUE;
3700 gtk_widget_grab_focus (widget);
3701 entry->in_click = FALSE;
3704 tmp_pos = gtk_entry_find_position (entry, event->x + entry->scroll_offset);
3706 if (event->button == 1)
3708 gboolean have_selection = gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end);
3710 entry->select_words = FALSE;
3711 entry->select_lines = FALSE;
3713 if (event->state & GDK_SHIFT_MASK)
3715 _gtk_entry_reset_im_context (entry);
3717 if (!have_selection) /* select from the current position to the clicked position */
3718 sel_start = sel_end = entry->current_pos;
3720 if (tmp_pos > sel_start && tmp_pos < sel_end)
3722 /* Truncate current selection, but keep it as big as possible */
3723 if (tmp_pos - sel_start > sel_end - tmp_pos)
3724 gtk_entry_set_positions (entry, sel_start, tmp_pos);
3726 gtk_entry_set_positions (entry, tmp_pos, sel_end);
3730 gboolean extend_to_left;
3733 /* Figure out what click selects and extend current selection */
3734 switch (event->type)
3736 case GDK_BUTTON_PRESS:
3737 gtk_entry_set_positions (entry, tmp_pos, tmp_pos);
3740 case GDK_2BUTTON_PRESS:
3741 entry->select_words = TRUE;
3742 gtk_entry_select_word (entry);
3745 case GDK_3BUTTON_PRESS:
3746 entry->select_lines = TRUE;
3747 gtk_entry_select_line (entry);
3754 start = MIN (entry->current_pos, entry->selection_bound);
3755 start = MIN (sel_start, start);
3757 end = MAX (entry->current_pos, entry->selection_bound);
3758 end = MAX (sel_end, end);
3760 if (tmp_pos == sel_start || tmp_pos == sel_end)
3761 extend_to_left = (tmp_pos == start);
3763 extend_to_left = (end == sel_end);
3766 gtk_entry_set_positions (entry, start, end);
3768 gtk_entry_set_positions (entry, end, start);
3771 else /* no shift key */
3772 switch (event->type)
3774 case GDK_BUTTON_PRESS:
3775 if (in_selection (entry, event->x + entry->scroll_offset))
3777 /* Click inside the selection - we'll either start a drag, or
3778 * clear the selection
3780 entry->in_drag = TRUE;
3781 entry->drag_start_x = event->x + entry->scroll_offset;
3782 entry->drag_start_y = event->y;
3785 gtk_editable_set_position (editable, tmp_pos);
3788 case GDK_2BUTTON_PRESS:
3789 /* We ALWAYS receive a GDK_BUTTON_PRESS immediately before
3790 * receiving a GDK_2BUTTON_PRESS so we need to reset
3791 * entry->in_drag which may have been set above
3793 entry->in_drag = FALSE;
3794 entry->select_words = TRUE;
3795 gtk_entry_select_word (entry);
3798 case GDK_3BUTTON_PRESS:
3799 /* We ALWAYS receive a GDK_BUTTON_PRESS immediately before
3800 * receiving a GDK_3BUTTON_PRESS so we need to reset
3801 * entry->in_drag which may have been set above
3803 entry->in_drag = FALSE;
3804 entry->select_lines = TRUE;
3805 gtk_entry_select_line (entry);
3814 else if (event->button == 2 && event->type == GDK_BUTTON_PRESS)
3816 if (entry->editable)
3818 priv->insert_pos = tmp_pos;
3819 gtk_entry_paste (entry, GDK_SELECTION_PRIMARY);
3824 gtk_widget_error_bell (widget);
3827 else if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
3829 gtk_entry_do_popup (entry, event);
3830 entry->button = 0; /* Don't wait for release, since the menu will gtk_grab_add */
3839 gtk_entry_button_release (GtkWidget *widget,
3840 GdkEventButton *event)
3842 GtkEntry *entry = GTK_ENTRY (widget);
3843 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
3844 EntryIconInfo *icon_info = NULL;
3847 for (i = 0; i < MAX_ICONS; i++)
3849 icon_info = priv->icons[i];
3851 if (!icon_info || icon_info->insensitive)
3854 if (event->window == icon_info->window)
3858 gdk_drawable_get_size (icon_info->window, &width, &height);
3860 icon_info->pressed = FALSE;
3862 if (should_prelight (entry, i) &&
3863 event->x >= 0 && event->y >= 0 &&
3864 event->x < width && event->y < height)
3866 icon_info->prelight = TRUE;
3867 gtk_widget_queue_draw (widget);
3870 if (!icon_info->nonactivatable)
3871 g_signal_emit (entry, signals[ICON_RELEASE], 0, i, event);
3877 if (event->window != entry->text_area || entry->button != event->button)
3882 gint tmp_pos = gtk_entry_find_position (entry, entry->drag_start_x);
3884 gtk_editable_set_position (GTK_EDITABLE (entry), tmp_pos);
3891 gtk_entry_update_primary_selection (entry);
3897 _gtk_entry_get_selected_text (GtkEntry *entry)
3899 GtkEditable *editable = GTK_EDITABLE (entry);
3900 gint start_text, end_text;
3903 if (gtk_editable_get_selection_bounds (editable, &start_text, &end_text))
3904 text = gtk_editable_get_chars (editable, start_text, end_text);
3910 gtk_entry_motion_notify (GtkWidget *widget,
3911 GdkEventMotion *event)
3913 GtkEntry *entry = GTK_ENTRY (widget);
3914 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3915 EntryIconInfo *icon_info = NULL;
3916 GdkDragContext *context;
3920 for (i = 0; i < MAX_ICONS; i++)
3922 icon_info = priv->icons[i];
3924 if (!icon_info || icon_info->insensitive)
3927 if (event->window == icon_info->window)
3929 if (icon_info->pressed &&
3930 icon_info->target_list != NULL &&
3931 gtk_drag_check_threshold (widget,
3937 icon_info->in_drag = TRUE;
3938 icon_info->pressed = FALSE;
3939 context = gtk_drag_begin (widget,
3940 icon_info->target_list,
3950 if (entry->mouse_cursor_obscured)
3954 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
3955 gdk_window_set_cursor (entry->text_area, cursor);
3956 gdk_cursor_unref (cursor);
3957 entry->mouse_cursor_obscured = FALSE;
3960 if (event->window != entry->text_area || entry->button != 1)
3963 if (entry->select_lines)
3966 gdk_event_request_motions (event);
3970 if (gtk_entry_get_display_mode (entry) == DISPLAY_NORMAL &&
3971 gtk_drag_check_threshold (widget,
3972 entry->drag_start_x, entry->drag_start_y,
3973 event->x + entry->scroll_offset, event->y))
3975 GdkDragContext *context;
3976 GtkTargetList *target_list = gtk_target_list_new (NULL, 0);
3977 guint actions = entry->editable ? GDK_ACTION_COPY | GDK_ACTION_MOVE : GDK_ACTION_COPY;
3979 cairo_surface_t *surface;
3981 gtk_target_list_add_text_targets (target_list, 0);
3983 text = _gtk_entry_get_selected_text (entry);
3984 surface = _gtk_text_util_create_drag_icon (widget, text, -1);
3986 context = gtk_drag_begin (widget, target_list, actions,
3987 entry->button, (GdkEvent *)event);
3990 gtk_drag_set_icon_surface (context, surface);
3992 gtk_drag_set_icon_default (context);
3995 cairo_surface_destroy (surface);
3998 entry->in_drag = FALSE;
4001 gtk_target_list_unref (target_list);
4007 gdk_drawable_get_size (entry->text_area, NULL, &height);
4011 else if (event->y >= height)
4012 tmp_pos = gtk_entry_buffer_get_length (get_buffer (entry));
4014 tmp_pos = gtk_entry_find_position (entry, event->x + entry->scroll_offset);
4016 if (entry->select_words)
4019 gint old_min, old_max;
4022 min = gtk_entry_move_backward_word (entry, tmp_pos, TRUE);
4023 max = gtk_entry_move_forward_word (entry, tmp_pos, TRUE);
4025 pos = entry->current_pos;
4026 bound = entry->selection_bound;
4028 old_min = MIN(entry->current_pos, entry->selection_bound);
4029 old_max = MAX(entry->current_pos, entry->selection_bound);
4036 else if (old_max < max)
4041 else if (pos == old_min)
4043 if (entry->current_pos != min)
4048 if (entry->current_pos != max)
4052 gtk_entry_set_positions (entry, pos, bound);
4055 gtk_entry_set_positions (entry, tmp_pos, -1);
4062 set_invisible_cursor (GdkWindow *window)
4064 GdkDisplay *display;
4067 display = gdk_window_get_display (window);
4068 cursor = gdk_cursor_new_for_display (display, GDK_BLANK_CURSOR);
4070 gdk_window_set_cursor (window, cursor);
4072 gdk_cursor_unref (cursor);
4076 gtk_entry_obscure_mouse_cursor (GtkEntry *entry)
4078 if (entry->mouse_cursor_obscured)
4081 set_invisible_cursor (entry->text_area);
4083 entry->mouse_cursor_obscured = TRUE;
4087 gtk_entry_key_press (GtkWidget *widget,
4090 GtkEntry *entry = GTK_ENTRY (widget);
4092 gtk_entry_reset_blink_time (entry);
4093 gtk_entry_pend_cursor_blink (entry);
4095 if (entry->editable)
4097 if (gtk_im_context_filter_keypress (entry->im_context, event))
4099 gtk_entry_obscure_mouse_cursor (entry);
4100 entry->need_im_reset = TRUE;
4105 if (event->keyval == GDK_KEY_Return ||
4106 event->keyval == GDK_KEY_KP_Enter ||
4107 event->keyval == GDK_KEY_ISO_Enter ||
4108 event->keyval == GDK_KEY_Escape)
4110 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
4112 if (completion && completion->priv->completion_timeout)
4114 g_source_remove (completion->priv->completion_timeout);
4115 completion->priv->completion_timeout = 0;
4118 _gtk_entry_reset_im_context (entry);
4121 if (GTK_WIDGET_CLASS (gtk_entry_parent_class)->key_press_event (widget, event))
4122 /* Activate key bindings
4126 if (!entry->editable && event->length)
4127 gtk_widget_error_bell (widget);
4133 gtk_entry_key_release (GtkWidget *widget,
4136 GtkEntry *entry = GTK_ENTRY (widget);
4138 if (entry->editable)
4140 if (gtk_im_context_filter_keypress (entry->im_context, event))
4142 entry->need_im_reset = TRUE;
4147 return GTK_WIDGET_CLASS (gtk_entry_parent_class)->key_release_event (widget, event);
4151 gtk_entry_focus_in (GtkWidget *widget,
4152 GdkEventFocus *event)
4154 GtkEntry *entry = GTK_ENTRY (widget);
4157 gtk_widget_queue_draw (widget);
4159 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (widget));
4161 if (entry->editable)
4163 entry->need_im_reset = TRUE;
4164 gtk_im_context_focus_in (entry->im_context);
4165 keymap_state_changed (keymap, entry);
4166 g_signal_connect (keymap, "state-changed",
4167 G_CALLBACK (keymap_state_changed), entry);
4170 g_signal_connect (keymap, "direction-changed",
4171 G_CALLBACK (keymap_direction_changed), entry);
4173 gtk_entry_reset_blink_time (entry);
4174 gtk_entry_check_cursor_blink (entry);
4180 gtk_entry_focus_out (GtkWidget *widget,
4181 GdkEventFocus *event)
4183 GtkEntry *entry = GTK_ENTRY (widget);
4184 GtkEntryCompletion *completion;
4187 gtk_widget_queue_draw (widget);
4189 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (widget));
4191 if (entry->editable)
4193 entry->need_im_reset = TRUE;
4194 gtk_im_context_focus_out (entry->im_context);
4195 remove_capslock_feedback (entry);
4198 gtk_entry_check_cursor_blink (entry);
4200 g_signal_handlers_disconnect_by_func (keymap, keymap_state_changed, entry);
4201 g_signal_handlers_disconnect_by_func (keymap, keymap_direction_changed, entry);
4203 completion = gtk_entry_get_completion (entry);
4205 _gtk_entry_completion_popdown (completion);
4211 gtk_entry_grab_focus (GtkWidget *widget)
4213 GtkEntry *entry = GTK_ENTRY (widget);
4214 gboolean select_on_focus;
4216 GTK_WIDGET_CLASS (gtk_entry_parent_class)->grab_focus (widget);
4218 if (entry->editable && !entry->in_click)
4220 g_object_get (gtk_widget_get_settings (widget),
4221 "gtk-entry-select-on-focus",
4225 if (select_on_focus)
4226 gtk_editable_select_region (GTK_EDITABLE (widget), 0, -1);
4231 gtk_entry_direction_changed (GtkWidget *widget,
4232 GtkTextDirection previous_dir)
4234 GtkEntry *entry = GTK_ENTRY (widget);
4236 gtk_entry_recompute (entry);
4238 GTK_WIDGET_CLASS (gtk_entry_parent_class)->direction_changed (widget, previous_dir);
4242 gtk_entry_state_changed (GtkWidget *widget,
4243 GtkStateType previous_state)
4245 GtkEntry *entry = GTK_ENTRY (widget);
4246 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
4250 if (gtk_widget_get_realized (widget))
4255 style = gtk_widget_get_style (widget);
4256 state = gtk_widget_get_state (widget);
4258 gdk_window_set_background (gtk_widget_get_window (widget),
4259 &style->base[state]);
4260 gdk_window_set_background (entry->text_area,
4261 &style->base[state]);
4262 for (i = 0; i < MAX_ICONS; i++)
4264 EntryIconInfo *icon_info = priv->icons[i];
4265 if (icon_info && icon_info->window)
4266 gdk_window_set_background (icon_info->window,
4267 &style->base[state]);
4270 if (gtk_widget_is_sensitive (widget))
4271 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
4275 gdk_window_set_cursor (entry->text_area, cursor);
4278 gdk_cursor_unref (cursor);
4280 entry->mouse_cursor_obscured = FALSE;
4282 update_cursors (widget);
4285 if (!gtk_widget_is_sensitive (widget))
4287 /* Clear any selection */
4288 gtk_editable_select_region (GTK_EDITABLE (entry), entry->current_pos, entry->current_pos);
4291 gtk_widget_queue_draw (widget);
4295 gtk_entry_screen_changed (GtkWidget *widget,
4296 GdkScreen *old_screen)
4298 gtk_entry_recompute (GTK_ENTRY (widget));
4301 /* GtkEditable method implementations
4304 gtk_entry_insert_text (GtkEditable *editable,
4305 const gchar *new_text,
4306 gint new_text_length,
4309 g_object_ref (editable);
4312 * The incoming text may a password or other secret. We make sure
4313 * not to copy it into temporary buffers.
4316 g_signal_emit_by_name (editable, "insert-text", new_text, new_text_length, position);
4318 g_object_unref (editable);
4322 gtk_entry_delete_text (GtkEditable *editable,
4326 g_object_ref (editable);
4328 g_signal_emit_by_name (editable, "delete-text", start_pos, end_pos);
4330 g_object_unref (editable);
4334 gtk_entry_get_chars (GtkEditable *editable,
4338 GtkEntry *entry = GTK_ENTRY (editable);
4341 gint start_index, end_index;
4343 text = gtk_entry_buffer_get_text (get_buffer (entry));
4344 text_length = gtk_entry_buffer_get_length (get_buffer (entry));
4347 end_pos = text_length;
4349 start_pos = MIN (text_length, start_pos);
4350 end_pos = MIN (text_length, end_pos);
4352 start_index = g_utf8_offset_to_pointer (text, start_pos) - text;
4353 end_index = g_utf8_offset_to_pointer (text, end_pos) - text;
4355 return g_strndup (text + start_index, end_index - start_index);
4359 gtk_entry_real_set_position (GtkEditable *editable,
4362 GtkEntry *entry = GTK_ENTRY (editable);
4366 length = gtk_entry_buffer_get_length (get_buffer (entry));
4367 if (position < 0 || position > length)
4370 if (position != entry->current_pos ||
4371 position != entry->selection_bound)
4373 _gtk_entry_reset_im_context (entry);
4374 gtk_entry_set_positions (entry, position, position);
4379 gtk_entry_get_position (GtkEditable *editable)
4381 return GTK_ENTRY (editable)->current_pos;
4385 gtk_entry_set_selection_bounds (GtkEditable *editable,
4389 GtkEntry *entry = GTK_ENTRY (editable);
4392 length = gtk_entry_buffer_get_length (get_buffer (entry));
4398 _gtk_entry_reset_im_context (entry);
4400 gtk_entry_set_positions (entry,
4402 MIN (start, length));
4404 gtk_entry_update_primary_selection (entry);
4408 gtk_entry_get_selection_bounds (GtkEditable *editable,
4412 GtkEntry *entry = GTK_ENTRY (editable);
4414 *start = entry->selection_bound;
4415 *end = entry->current_pos;
4417 return (entry->selection_bound != entry->current_pos);
4421 icon_theme_changed (GtkEntry *entry)
4423 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
4426 for (i = 0; i < MAX_ICONS; i++)
4428 EntryIconInfo *icon_info = priv->icons[i];
4429 if (icon_info != NULL)
4431 if (icon_info->storage_type == GTK_IMAGE_ICON_NAME)
4432 gtk_entry_set_icon_from_icon_name (entry, i, icon_info->icon_name);
4433 else if (icon_info->storage_type == GTK_IMAGE_STOCK)
4434 gtk_entry_set_icon_from_stock (entry, i, icon_info->stock_id);
4435 else if (icon_info->storage_type == GTK_IMAGE_GICON)
4436 gtk_entry_set_icon_from_gicon (entry, i, icon_info->gicon);
4440 gtk_widget_queue_draw (GTK_WIDGET (entry));
4444 icon_margin_changed (GtkEntry *entry)
4446 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
4449 _gtk_entry_effective_inner_border (GTK_ENTRY (entry), &border);
4451 priv->icon_margin = border.left;
4455 gtk_entry_style_set (GtkWidget *widget,
4456 GtkStyle *previous_style)
4458 GtkEntry *entry = GTK_ENTRY (widget);
4459 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
4461 gboolean interior_focus;
4464 gtk_widget_style_get (widget,
4465 "focus-line-width", &focus_width,
4466 "interior-focus", &interior_focus,
4469 priv->focus_width = focus_width;
4470 priv->interior_focus = interior_focus;
4472 if (!priv->invisible_char_set)
4473 entry->invisible_char = find_invisible_char (GTK_WIDGET (entry));
4475 gtk_entry_recompute (entry);
4477 if (previous_style && gtk_widget_get_realized (widget))
4481 style = gtk_widget_get_style (widget);
4483 gdk_window_set_background (gtk_widget_get_window (widget),
4484 &style->base[gtk_widget_get_state (widget)]);
4485 gdk_window_set_background (entry->text_area,
4486 &style->base[gtk_widget_get_state (widget)]);
4487 for (i = 0; i < MAX_ICONS; i++)
4489 EntryIconInfo *icon_info = priv->icons[i];
4490 if (icon_info && icon_info->window)
4491 gdk_window_set_background (icon_info->window,
4492 &style->base[gtk_widget_get_state (widget)]);
4496 icon_theme_changed (entry);
4497 icon_margin_changed (entry);
4500 /* GtkCellEditable method implementations
4503 gtk_cell_editable_entry_activated (GtkEntry *entry, gpointer data)
4505 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4506 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4510 gtk_cell_editable_key_press_event (GtkEntry *entry,
4511 GdkEventKey *key_event,
4514 if (key_event->keyval == GDK_KEY_Escape)
4516 entry->editing_canceled = TRUE;
4517 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4518 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4523 /* override focus */
4524 if (key_event->keyval == GDK_KEY_Up || key_event->keyval == GDK_KEY_Down)
4526 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4527 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4536 gtk_entry_start_editing (GtkCellEditable *cell_editable,
4539 GTK_ENTRY (cell_editable)->is_cell_renderer = TRUE;
4541 g_signal_connect (cell_editable, "activate",
4542 G_CALLBACK (gtk_cell_editable_entry_activated), NULL);
4543 g_signal_connect (cell_editable, "key-press-event",
4544 G_CALLBACK (gtk_cell_editable_key_press_event), NULL);
4548 gtk_entry_password_hint_free (GtkEntryPasswordHint *password_hint)
4550 if (password_hint->source_id)
4551 g_source_remove (password_hint->source_id);
4553 g_slice_free (GtkEntryPasswordHint, password_hint);
4558 gtk_entry_remove_password_hint (gpointer data)
4560 GtkEntryPasswordHint *password_hint = g_object_get_qdata (data, quark_password_hint);
4561 password_hint->position = -1;
4563 /* Force the string to be redrawn, but now without a visible character */
4564 gtk_entry_recompute (GTK_ENTRY (data));
4568 /* Default signal handlers
4571 gtk_entry_real_insert_text (GtkEditable *editable,
4572 const gchar *new_text,
4573 gint new_text_length,
4579 n_chars = g_utf8_strlen (new_text, new_text_length);
4582 * The actual insertion into the buffer. This will end up firing the
4583 * following signal handlers: buffer_inserted_text(), buffer_notify_display_text(),
4584 * buffer_notify_text(), buffer_notify_length()
4586 n_inserted = gtk_entry_buffer_insert_text (get_buffer (GTK_ENTRY (editable)), *position, new_text, n_chars);
4588 if (n_inserted != n_chars)
4589 gtk_widget_error_bell (GTK_WIDGET (editable));
4591 *position += n_inserted;
4595 gtk_entry_real_delete_text (GtkEditable *editable,
4600 * The actual deletion from the buffer. This will end up firing the
4601 * following signal handlers: buffer_deleted_text(), buffer_notify_display_text(),
4602 * buffer_notify_text(), buffer_notify_length()
4605 gtk_entry_buffer_delete_text (get_buffer (GTK_ENTRY (editable)), start_pos, end_pos - start_pos);
4608 /* GtkEntryBuffer signal handlers
4611 buffer_inserted_text (GtkEntryBuffer *buffer,
4617 guint password_hint_timeout;
4619 if (entry->current_pos > position)
4620 entry->current_pos += n_chars;
4622 if (entry->selection_bound > position)
4623 entry->selection_bound += n_chars;
4625 /* Calculate the password hint if it needs to be displayed. */
4626 if (n_chars == 1 && !entry->visible)
4628 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
4629 "gtk-entry-password-hint-timeout", &password_hint_timeout,
4632 if (password_hint_timeout > 0)
4634 GtkEntryPasswordHint *password_hint = g_object_get_qdata (G_OBJECT (entry),
4635 quark_password_hint);
4638 password_hint = g_slice_new0 (GtkEntryPasswordHint);
4639 g_object_set_qdata_full (G_OBJECT (entry), quark_password_hint, password_hint,
4640 (GDestroyNotify)gtk_entry_password_hint_free);
4643 password_hint->position = position;
4644 if (password_hint->source_id)
4645 g_source_remove (password_hint->source_id);
4646 password_hint->source_id = gdk_threads_add_timeout (password_hint_timeout,
4647 (GSourceFunc)gtk_entry_remove_password_hint, entry);
4653 buffer_deleted_text (GtkEntryBuffer *buffer,
4658 guint end_pos = position + n_chars;
4659 gint selection_bound;
4662 current_pos = entry->current_pos;
4663 if (current_pos > position)
4664 current_pos -= MIN (current_pos, end_pos) - position;
4666 selection_bound = entry->selection_bound;
4667 if (selection_bound > position)
4668 selection_bound -= MIN (selection_bound, end_pos) - position;
4670 gtk_entry_set_positions (entry, current_pos, selection_bound);
4672 /* We might have deleted the selection */
4673 gtk_entry_update_primary_selection (entry);
4675 /* Disable the password hint if one exists. */
4676 if (!entry->visible)
4678 GtkEntryPasswordHint *password_hint = g_object_get_qdata (G_OBJECT (entry),
4679 quark_password_hint);
4682 if (password_hint->source_id)
4683 g_source_remove (password_hint->source_id);
4684 password_hint->source_id = 0;
4685 password_hint->position = -1;
4691 buffer_notify_text (GtkEntryBuffer *buffer,
4695 gtk_entry_recompute (entry);
4696 emit_changed (entry);
4697 g_object_notify (G_OBJECT (entry), "text");
4701 buffer_notify_length (GtkEntryBuffer *buffer,
4705 g_object_notify (G_OBJECT (entry), "text-length");
4709 buffer_notify_max_length (GtkEntryBuffer *buffer,
4713 g_object_notify (G_OBJECT (entry), "max-length");
4717 buffer_connect_signals (GtkEntry *entry)
4719 g_signal_connect (get_buffer (entry), "inserted-text", G_CALLBACK (buffer_inserted_text), entry);
4720 g_signal_connect (get_buffer (entry), "deleted-text", G_CALLBACK (buffer_deleted_text), entry);
4721 g_signal_connect (get_buffer (entry), "notify::text", G_CALLBACK (buffer_notify_text), entry);
4722 g_signal_connect (get_buffer (entry), "notify::length", G_CALLBACK (buffer_notify_length), entry);
4723 g_signal_connect (get_buffer (entry), "notify::max-length", G_CALLBACK (buffer_notify_max_length), entry);
4727 buffer_disconnect_signals (GtkEntry *entry)
4729 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_inserted_text, entry);
4730 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_deleted_text, entry);
4731 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_text, entry);
4732 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_length, entry);
4733 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_max_length, entry);
4736 /* Compute the X position for an offset that corresponds to the "more important
4737 * cursor position for that offset. We use this when trying to guess to which
4738 * end of the selection we should go to when the user hits the left or
4742 get_better_cursor_x (GtkEntry *entry,
4745 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
4746 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
4747 gboolean split_cursor;
4749 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
4750 const gchar *text = pango_layout_get_text (layout);
4751 gint index = g_utf8_offset_to_pointer (text, offset) - text;
4753 PangoRectangle strong_pos, weak_pos;
4755 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
4756 "gtk-split-cursor", &split_cursor,
4759 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
4762 return strong_pos.x / PANGO_SCALE;
4764 return (keymap_direction == entry->resolved_dir) ? strong_pos.x / PANGO_SCALE : weak_pos.x / PANGO_SCALE;
4768 gtk_entry_move_cursor (GtkEntry *entry,
4769 GtkMovementStep step,
4771 gboolean extend_selection)
4773 gint new_pos = entry->current_pos;
4774 GtkEntryPrivate *priv;
4776 _gtk_entry_reset_im_context (entry);
4778 if (entry->current_pos != entry->selection_bound && !extend_selection)
4780 /* If we have a current selection and aren't extending it, move to the
4781 * start/or end of the selection as appropriate
4785 case GTK_MOVEMENT_VISUAL_POSITIONS:
4787 gint current_x = get_better_cursor_x (entry, entry->current_pos);
4788 gint bound_x = get_better_cursor_x (entry, entry->selection_bound);
4791 new_pos = current_x < bound_x ? entry->current_pos : entry->selection_bound;
4793 new_pos = current_x > bound_x ? entry->current_pos : entry->selection_bound;
4796 case GTK_MOVEMENT_LOGICAL_POSITIONS:
4797 case GTK_MOVEMENT_WORDS:
4799 new_pos = MIN (entry->current_pos, entry->selection_bound);
4801 new_pos = MAX (entry->current_pos, entry->selection_bound);
4803 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
4804 case GTK_MOVEMENT_PARAGRAPH_ENDS:
4805 case GTK_MOVEMENT_BUFFER_ENDS:
4806 priv = GTK_ENTRY_GET_PRIVATE (entry);
4807 new_pos = count < 0 ? 0 : gtk_entry_buffer_get_length (get_buffer (entry));
4809 case GTK_MOVEMENT_DISPLAY_LINES:
4810 case GTK_MOVEMENT_PARAGRAPHS:
4811 case GTK_MOVEMENT_PAGES:
4812 case GTK_MOVEMENT_HORIZONTAL_PAGES:
4820 case GTK_MOVEMENT_LOGICAL_POSITIONS:
4821 new_pos = gtk_entry_move_logically (entry, new_pos, count);
4823 case GTK_MOVEMENT_VISUAL_POSITIONS:
4824 new_pos = gtk_entry_move_visually (entry, new_pos, count);
4825 if (entry->current_pos == new_pos)
4827 if (!extend_selection)
4829 if (!gtk_widget_keynav_failed (GTK_WIDGET (entry),
4831 GTK_DIR_RIGHT : GTK_DIR_LEFT))
4833 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (entry));
4836 gtk_widget_child_focus (toplevel,
4838 GTK_DIR_RIGHT : GTK_DIR_LEFT);
4843 gtk_widget_error_bell (GTK_WIDGET (entry));
4847 case GTK_MOVEMENT_WORDS:
4850 new_pos = gtk_entry_move_forward_word (entry, new_pos, FALSE);
4855 new_pos = gtk_entry_move_backward_word (entry, new_pos, FALSE);
4858 if (entry->current_pos == new_pos)
4859 gtk_widget_error_bell (GTK_WIDGET (entry));
4861 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
4862 case GTK_MOVEMENT_PARAGRAPH_ENDS:
4863 case GTK_MOVEMENT_BUFFER_ENDS:
4864 priv = GTK_ENTRY_GET_PRIVATE (entry);
4865 new_pos = count < 0 ? 0 : gtk_entry_buffer_get_length (get_buffer (entry));
4866 if (entry->current_pos == new_pos)
4867 gtk_widget_error_bell (GTK_WIDGET (entry));
4869 case GTK_MOVEMENT_DISPLAY_LINES:
4870 case GTK_MOVEMENT_PARAGRAPHS:
4871 case GTK_MOVEMENT_PAGES:
4872 case GTK_MOVEMENT_HORIZONTAL_PAGES:
4877 if (extend_selection)
4878 gtk_editable_select_region (GTK_EDITABLE (entry), entry->selection_bound, new_pos);
4880 gtk_editable_set_position (GTK_EDITABLE (entry), new_pos);
4882 gtk_entry_pend_cursor_blink (entry);
4886 gtk_entry_insert_at_cursor (GtkEntry *entry,
4889 GtkEditable *editable = GTK_EDITABLE (entry);
4890 gint pos = entry->current_pos;
4892 if (entry->editable)
4894 _gtk_entry_reset_im_context (entry);
4896 gtk_editable_insert_text (editable, str, -1, &pos);
4897 gtk_editable_set_position (editable, pos);
4902 gtk_entry_delete_from_cursor (GtkEntry *entry,
4906 GtkEditable *editable = GTK_EDITABLE (entry);
4907 gint start_pos = entry->current_pos;
4908 gint end_pos = entry->current_pos;
4909 gint old_n_bytes = gtk_entry_buffer_get_bytes (get_buffer (entry));
4911 _gtk_entry_reset_im_context (entry);
4913 if (!entry->editable)
4915 gtk_widget_error_bell (GTK_WIDGET (entry));
4919 if (entry->selection_bound != entry->current_pos)
4921 gtk_editable_delete_selection (editable);
4927 case GTK_DELETE_CHARS:
4928 end_pos = gtk_entry_move_logically (entry, entry->current_pos, count);
4929 gtk_editable_delete_text (editable, MIN (start_pos, end_pos), MAX (start_pos, end_pos));
4931 case GTK_DELETE_WORDS:
4934 /* Move to end of current word, or if not on a word, end of previous word */
4935 end_pos = gtk_entry_move_backward_word (entry, end_pos, FALSE);
4936 end_pos = gtk_entry_move_forward_word (entry, end_pos, FALSE);
4940 /* Move to beginning of current word, or if not on a word, begining of next word */
4941 start_pos = gtk_entry_move_forward_word (entry, start_pos, FALSE);
4942 start_pos = gtk_entry_move_backward_word (entry, start_pos, FALSE);
4946 case GTK_DELETE_WORD_ENDS:
4949 start_pos = gtk_entry_move_backward_word (entry, start_pos, FALSE);
4954 end_pos = gtk_entry_move_forward_word (entry, end_pos, FALSE);
4957 gtk_editable_delete_text (editable, start_pos, end_pos);
4959 case GTK_DELETE_DISPLAY_LINE_ENDS:
4960 case GTK_DELETE_PARAGRAPH_ENDS:
4962 gtk_editable_delete_text (editable, 0, entry->current_pos);
4964 gtk_editable_delete_text (editable, entry->current_pos, -1);
4966 case GTK_DELETE_DISPLAY_LINES:
4967 case GTK_DELETE_PARAGRAPHS:
4968 gtk_editable_delete_text (editable, 0, -1);
4970 case GTK_DELETE_WHITESPACE:
4971 gtk_entry_delete_whitespace (entry);
4975 if (gtk_entry_buffer_get_bytes (get_buffer (entry)) == old_n_bytes)
4976 gtk_widget_error_bell (GTK_WIDGET (entry));
4978 gtk_entry_pend_cursor_blink (entry);
4982 gtk_entry_backspace (GtkEntry *entry)
4984 GtkEditable *editable = GTK_EDITABLE (entry);
4987 _gtk_entry_reset_im_context (entry);
4989 if (!entry->editable)
4991 gtk_widget_error_bell (GTK_WIDGET (entry));
4995 if (entry->selection_bound != entry->current_pos)
4997 gtk_editable_delete_selection (editable);
5001 prev_pos = gtk_entry_move_logically (entry, entry->current_pos, -1);
5003 if (prev_pos < entry->current_pos)
5005 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
5006 PangoLogAttr *log_attrs;
5009 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
5011 /* Deleting parts of characters */
5012 if (log_attrs[entry->current_pos].backspace_deletes_character)
5014 gchar *cluster_text;
5015 gchar *normalized_text;
5018 cluster_text = gtk_entry_get_display_text (entry, prev_pos,
5019 entry->current_pos);
5020 normalized_text = g_utf8_normalize (cluster_text,
5021 strlen (cluster_text),
5023 len = g_utf8_strlen (normalized_text, -1);
5025 gtk_editable_delete_text (editable, prev_pos, entry->current_pos);
5028 gint pos = entry->current_pos;
5030 gtk_editable_insert_text (editable, normalized_text,
5031 g_utf8_offset_to_pointer (normalized_text, len - 1) - normalized_text,
5033 gtk_editable_set_position (editable, pos);
5036 g_free (normalized_text);
5037 g_free (cluster_text);
5041 gtk_editable_delete_text (editable, prev_pos, entry->current_pos);
5048 gtk_widget_error_bell (GTK_WIDGET (entry));
5051 gtk_entry_pend_cursor_blink (entry);
5055 gtk_entry_copy_clipboard (GtkEntry *entry)
5057 GtkEditable *editable = GTK_EDITABLE (entry);
5061 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5063 if (!entry->visible)
5065 gtk_widget_error_bell (GTK_WIDGET (entry));
5069 str = gtk_entry_get_display_text (entry, start, end);
5070 gtk_clipboard_set_text (gtk_widget_get_clipboard (GTK_WIDGET (entry),
5071 GDK_SELECTION_CLIPBOARD),
5078 gtk_entry_cut_clipboard (GtkEntry *entry)
5080 GtkEditable *editable = GTK_EDITABLE (entry);
5083 if (!entry->visible)
5085 gtk_widget_error_bell (GTK_WIDGET (entry));
5089 gtk_entry_copy_clipboard (entry);
5091 if (entry->editable)
5093 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5094 gtk_editable_delete_text (editable, start, end);
5098 gtk_widget_error_bell (GTK_WIDGET (entry));
5103 gtk_entry_paste_clipboard (GtkEntry *entry)
5105 if (entry->editable)
5106 gtk_entry_paste (entry, GDK_NONE);
5108 gtk_widget_error_bell (GTK_WIDGET (entry));
5112 gtk_entry_delete_cb (GtkEntry *entry)
5114 GtkEditable *editable = GTK_EDITABLE (entry);
5117 if (entry->editable)
5119 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5120 gtk_editable_delete_text (editable, start, end);
5125 gtk_entry_toggle_overwrite (GtkEntry *entry)
5127 entry->overwrite_mode = !entry->overwrite_mode;
5128 gtk_entry_pend_cursor_blink (entry);
5129 gtk_widget_queue_draw (GTK_WIDGET (entry));
5133 gtk_entry_select_all (GtkEntry *entry)
5135 gtk_entry_select_line (entry);
5139 gtk_entry_real_activate (GtkEntry *entry)
5142 GtkWidget *default_widget, *focus_widget;
5143 GtkWidget *toplevel;
5146 widget = GTK_WIDGET (entry);
5148 if (entry->activates_default)
5150 toplevel = gtk_widget_get_toplevel (widget);
5151 if (GTK_IS_WINDOW (toplevel))
5153 window = GTK_WINDOW (toplevel);
5157 default_widget = gtk_window_get_default_widget (window);
5158 focus_widget = gtk_window_get_focus (window);
5159 if (widget != default_widget &&
5160 !(widget == focus_widget && (!default_widget || !gtk_widget_get_sensitive (default_widget))))
5161 gtk_window_activate_default (window);
5168 keymap_direction_changed (GdkKeymap *keymap,
5171 gtk_entry_recompute (entry);
5174 /* IM Context Callbacks
5178 gtk_entry_commit_cb (GtkIMContext *context,
5182 if (entry->editable)
5183 gtk_entry_enter_text (entry, str);
5187 gtk_entry_preedit_changed_cb (GtkIMContext *context,
5190 if (entry->editable)
5192 gchar *preedit_string;
5195 gtk_im_context_get_preedit_string (entry->im_context,
5196 &preedit_string, NULL,
5198 g_signal_emit (entry, signals[PREEDIT_CHANGED], 0, preedit_string);
5199 entry->preedit_length = strlen (preedit_string);
5200 cursor_pos = CLAMP (cursor_pos, 0, g_utf8_strlen (preedit_string, -1));
5201 entry->preedit_cursor = cursor_pos;
5202 g_free (preedit_string);
5204 gtk_entry_recompute (entry);
5209 gtk_entry_retrieve_surrounding_cb (GtkIMContext *context,
5214 /* XXXX ??? does this even make sense when text is not visible? Should we return FALSE? */
5215 text = gtk_entry_get_display_text (entry, 0, -1);
5216 gtk_im_context_set_surrounding (context, text, strlen (text), /* Length in bytes */
5217 g_utf8_offset_to_pointer (text, entry->current_pos) - text);
5224 gtk_entry_delete_surrounding_cb (GtkIMContext *slave,
5229 if (entry->editable)
5230 gtk_editable_delete_text (GTK_EDITABLE (entry),
5231 entry->current_pos + offset,
5232 entry->current_pos + offset + n_chars);
5237 /* Internal functions
5240 /* Used for im_commit_cb and inserting Unicode chars */
5242 gtk_entry_enter_text (GtkEntry *entry,
5245 GtkEditable *editable = GTK_EDITABLE (entry);
5247 gboolean old_need_im_reset;
5249 old_need_im_reset = entry->need_im_reset;
5250 entry->need_im_reset = FALSE;
5252 if (gtk_editable_get_selection_bounds (editable, NULL, NULL))
5253 gtk_editable_delete_selection (editable);
5256 if (entry->overwrite_mode)
5257 gtk_entry_delete_from_cursor (entry, GTK_DELETE_CHARS, 1);
5260 tmp_pos = entry->current_pos;
5261 gtk_editable_insert_text (editable, str, strlen (str), &tmp_pos);
5262 gtk_editable_set_position (editable, tmp_pos);
5264 entry->need_im_reset = old_need_im_reset;
5267 /* All changes to entry->current_pos and entry->selection_bound
5268 * should go through this function.
5271 gtk_entry_set_positions (GtkEntry *entry,
5273 gint selection_bound)
5275 gboolean changed = FALSE;
5277 g_object_freeze_notify (G_OBJECT (entry));
5279 if (current_pos != -1 &&
5280 entry->current_pos != current_pos)
5282 entry->current_pos = current_pos;
5285 g_object_notify (G_OBJECT (entry), "cursor-position");
5288 if (selection_bound != -1 &&
5289 entry->selection_bound != selection_bound)
5291 entry->selection_bound = selection_bound;
5294 g_object_notify (G_OBJECT (entry), "selection-bound");
5297 g_object_thaw_notify (G_OBJECT (entry));
5301 gtk_entry_move_adjustments (entry);
5302 gtk_entry_recompute (entry);
5307 gtk_entry_reset_layout (GtkEntry *entry)
5309 if (entry->cached_layout)
5311 g_object_unref (entry->cached_layout);
5312 entry->cached_layout = NULL;
5317 update_im_cursor_location (GtkEntry *entry)
5321 gint strong_xoffset;
5322 gint area_width, area_height;
5324 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
5325 gtk_entry_get_text_area_size (entry, NULL, NULL, &area_width, &area_height);
5327 strong_xoffset = strong_x - entry->scroll_offset;
5328 if (strong_xoffset < 0)
5332 else if (strong_xoffset > area_width)
5334 strong_xoffset = area_width;
5336 area.x = strong_xoffset;
5339 area.height = area_height;
5341 gtk_im_context_set_cursor_location (entry->im_context, &area);
5345 recompute_idle_func (gpointer data)
5349 entry = GTK_ENTRY (data);
5351 entry->recompute_idle = 0;
5353 if (gtk_widget_has_screen (GTK_WIDGET (entry)))
5355 gtk_entry_adjust_scroll (entry);
5356 gtk_entry_queue_draw (entry);
5358 update_im_cursor_location (entry);
5365 gtk_entry_recompute (GtkEntry *entry)
5367 gtk_entry_reset_layout (entry);
5368 gtk_entry_check_cursor_blink (entry);
5370 if (!entry->recompute_idle)
5372 entry->recompute_idle = gdk_threads_add_idle_full (G_PRIORITY_HIGH_IDLE + 15, /* between resize and redraw */
5373 recompute_idle_func, entry, NULL);
5377 static PangoLayout *
5378 gtk_entry_create_layout (GtkEntry *entry,
5379 gboolean include_preedit)
5381 GtkWidget *widget = GTK_WIDGET (entry);
5382 PangoLayout *layout = gtk_widget_create_pango_layout (widget, NULL);
5383 PangoAttrList *tmp_attrs = pango_attr_list_new ();
5385 gchar *preedit_string = NULL;
5386 gint preedit_length = 0;
5387 PangoAttrList *preedit_attrs = NULL;
5392 pango_layout_set_single_paragraph_mode (layout, TRUE);
5394 display = gtk_entry_get_display_text (entry, 0, -1);
5395 n_bytes = strlen (display);
5397 if (include_preedit)
5399 gtk_im_context_get_preedit_string (entry->im_context,
5400 &preedit_string, &preedit_attrs, NULL);
5401 preedit_length = entry->preedit_length;
5406 GString *tmp_string = g_string_new (display);
5407 gint cursor_index = g_utf8_offset_to_pointer (display, entry->current_pos) - display;
5409 g_string_insert (tmp_string, cursor_index, preedit_string);
5411 pango_layout_set_text (layout, tmp_string->str, tmp_string->len);
5413 pango_attr_list_splice (tmp_attrs, preedit_attrs,
5414 cursor_index, preedit_length);
5416 g_string_free (tmp_string, TRUE);
5420 PangoDirection pango_dir;
5422 if (gtk_entry_get_display_mode (entry) == DISPLAY_NORMAL)
5423 pango_dir = pango_find_base_dir (display, n_bytes);
5425 pango_dir = PANGO_DIRECTION_NEUTRAL;
5427 if (pango_dir == PANGO_DIRECTION_NEUTRAL)
5429 if (gtk_widget_has_focus (widget))
5431 GdkDisplay *display = gtk_widget_get_display (widget);
5432 GdkKeymap *keymap = gdk_keymap_get_for_display (display);
5433 if (gdk_keymap_get_direction (keymap) == PANGO_DIRECTION_RTL)
5434 pango_dir = PANGO_DIRECTION_RTL;
5436 pango_dir = PANGO_DIRECTION_LTR;
5440 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
5441 pango_dir = PANGO_DIRECTION_RTL;
5443 pango_dir = PANGO_DIRECTION_LTR;
5447 pango_context_set_base_dir (gtk_widget_get_pango_context (widget),
5450 entry->resolved_dir = pango_dir;
5452 pango_layout_set_text (layout, display, n_bytes);
5455 pango_layout_set_attributes (layout, tmp_attrs);
5457 g_free (preedit_string);
5461 pango_attr_list_unref (preedit_attrs);
5463 pango_attr_list_unref (tmp_attrs);
5468 static PangoLayout *
5469 gtk_entry_ensure_layout (GtkEntry *entry,
5470 gboolean include_preedit)
5472 if (entry->preedit_length > 0 &&
5473 !include_preedit != !entry->cache_includes_preedit)
5474 gtk_entry_reset_layout (entry);
5476 if (!entry->cached_layout)
5478 entry->cached_layout = gtk_entry_create_layout (entry, include_preedit);
5479 entry->cache_includes_preedit = include_preedit;
5482 return entry->cached_layout;
5486 get_layout_position (GtkEntry *entry,
5490 PangoLayout *layout;
5491 PangoRectangle logical_rect;
5492 gint area_width, area_height;
5493 GtkBorder inner_border;
5495 PangoLayoutLine *line;
5497 layout = gtk_entry_ensure_layout (entry, TRUE);
5499 gtk_entry_get_text_area_size (entry, NULL, NULL, &area_width, &area_height);
5500 _gtk_entry_effective_inner_border (entry, &inner_border);
5502 area_height = PANGO_SCALE * (area_height - inner_border.top - inner_border.bottom);
5504 line = pango_layout_get_lines_readonly (layout)->data;
5505 pango_layout_line_get_extents (line, NULL, &logical_rect);
5507 /* Align primarily for locale's ascent/descent */
5508 y_pos = ((area_height - entry->ascent - entry->descent) / 2 +
5509 entry->ascent + logical_rect.y);
5511 /* Now see if we need to adjust to fit in actual drawn string */
5512 if (logical_rect.height > area_height)
5513 y_pos = (area_height - logical_rect.height) / 2;
5516 else if (y_pos + logical_rect.height > area_height)
5517 y_pos = area_height - logical_rect.height;
5519 y_pos = inner_border.top + y_pos / PANGO_SCALE;
5522 *x = inner_border.left - entry->scroll_offset;
5529 draw_text_with_color (GtkEntry *entry, cairo_t *cr, GdkColor *default_color)
5531 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
5534 gint start_pos, end_pos;
5536 widget = GTK_WIDGET (entry);
5540 get_layout_position (entry, &x, &y);
5542 cairo_move_to (cr, x, y);
5543 gdk_cairo_set_source_color (cr, default_color);
5544 pango_cairo_show_layout (cr, layout);
5546 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start_pos, &end_pos))
5550 PangoRectangle logical_rect;
5551 GdkColor *selection_color, *text_color;
5552 GtkBorder inner_border;
5555 pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
5556 gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
5558 style = gtk_widget_get_style (widget);
5560 if (gtk_widget_has_focus (widget))
5562 selection_color = &style->base [GTK_STATE_SELECTED];
5563 text_color = &style->text [GTK_STATE_SELECTED];
5567 selection_color = &style->base [GTK_STATE_ACTIVE];
5568 text_color = &style->text [GTK_STATE_ACTIVE];
5571 _gtk_entry_effective_inner_border (entry, &inner_border);
5573 for (i = 0; i < n_ranges; ++i)
5574 cairo_rectangle (cr,
5575 inner_border.left - entry->scroll_offset + ranges[2 * i],
5578 logical_rect.height);
5582 gdk_cairo_set_source_color (cr, selection_color);
5585 cairo_move_to (cr, x, y);
5586 gdk_cairo_set_source_color (cr, text_color);
5587 pango_cairo_show_layout (cr, layout);
5595 gtk_entry_draw_text (GtkEntry *entry,
5598 GtkWidget *widget = GTK_WIDGET (entry);
5601 GdkColor text_color, bar_text_color;
5604 gint progress_x, progress_y, progress_width, progress_height;
5607 /* Nothing to display at all */
5608 if (gtk_entry_get_display_mode (entry) == DISPLAY_BLANK)
5611 state = GTK_STATE_SELECTED;
5612 if (!gtk_widget_get_sensitive (widget))
5613 state = GTK_STATE_INSENSITIVE;
5614 style = gtk_widget_get_style (widget);
5615 text_color = style->text[gtk_widget_get_state (widget)];
5616 bar_text_color = style->fg[state];
5618 get_progress_area (widget,
5619 &progress_x, &progress_y,
5620 &progress_width, &progress_height);
5622 /* If the color is the same, or the progress area has a zero
5623 * size, then we only need to draw once. */
5624 if ((text_color.pixel == bar_text_color.pixel) ||
5625 ((progress_width == 0) || (progress_height == 0)))
5627 draw_text_with_color (entry, cr, &text_color);
5631 gdk_drawable_get_size (entry->text_area, &width, &height);
5635 cairo_rectangle (cr, 0, 0, width, height);
5639 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
5640 cairo_rectangle (cr, 0, 0, width, height);
5642 gdk_window_get_position (entry->text_area, &pos_x, &pos_y);
5643 progress_x -= pos_x;
5644 progress_y -= pos_y;
5646 cairo_rectangle (cr, progress_x, progress_y,
5647 progress_width, progress_height);
5649 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_WINDING);
5651 draw_text_with_color (entry, cr, &text_color);
5654 cairo_rectangle (cr, progress_x, progress_y,
5655 progress_width, progress_height);
5658 draw_text_with_color (entry, cr, &bar_text_color);
5665 draw_insertion_cursor (GtkEntry *entry,
5667 GdkRectangle *cursor_location,
5668 gboolean is_primary,
5669 PangoDirection direction,
5670 gboolean draw_arrow)
5672 GtkWidget *widget = GTK_WIDGET (entry);
5673 GtkTextDirection text_dir;
5675 if (direction == PANGO_DIRECTION_LTR)
5676 text_dir = GTK_TEXT_DIR_LTR;
5678 text_dir = GTK_TEXT_DIR_RTL;
5680 gtk_cairo_draw_insertion_cursor (widget, cr,
5682 is_primary, text_dir, draw_arrow);
5686 gtk_entry_draw_cursor (GtkEntry *entry,
5690 GtkWidget *widget = GTK_WIDGET (entry);
5691 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
5692 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
5693 GdkRectangle cursor_location;
5694 gboolean split_cursor;
5695 PangoRectangle cursor_rect;
5696 GtkBorder inner_border;
5698 gint text_area_height;
5701 gboolean block_at_line_end;
5702 PangoLayout *layout;
5705 _gtk_entry_effective_inner_border (entry, &inner_border);
5707 xoffset = inner_border.left - entry->scroll_offset;
5709 gdk_drawable_get_size (entry->text_area, NULL, &text_area_height);
5711 layout = gtk_entry_ensure_layout (entry, TRUE);
5712 text = pango_layout_get_text (layout);
5713 cursor_index = g_utf8_offset_to_pointer (text, entry->current_pos + entry->preedit_cursor) - text;
5714 if (!entry->overwrite_mode)
5717 block = _gtk_text_util_get_block_cursor_location (layout,
5718 cursor_index, &cursor_rect, &block_at_line_end);
5722 gint strong_x, weak_x;
5723 PangoDirection dir1 = PANGO_DIRECTION_NEUTRAL;
5724 PangoDirection dir2 = PANGO_DIRECTION_NEUTRAL;
5728 gtk_entry_get_cursor_locations (entry, type, &strong_x, &weak_x);
5730 g_object_get (gtk_widget_get_settings (widget),
5731 "gtk-split-cursor", &split_cursor,
5734 dir1 = entry->resolved_dir;
5740 if (weak_x != strong_x)
5742 dir2 = (entry->resolved_dir == PANGO_DIRECTION_LTR) ? PANGO_DIRECTION_RTL : PANGO_DIRECTION_LTR;
5748 if (keymap_direction == entry->resolved_dir)
5754 cursor_location.x = xoffset + x1;
5755 cursor_location.y = inner_border.top;
5756 cursor_location.width = 0;
5757 cursor_location.height = text_area_height - inner_border.top - inner_border.bottom;
5759 draw_insertion_cursor (entry, cr,
5760 &cursor_location, TRUE, dir1,
5761 dir2 != PANGO_DIRECTION_NEUTRAL);
5763 if (dir2 != PANGO_DIRECTION_NEUTRAL)
5765 cursor_location.x = xoffset + x2;
5766 draw_insertion_cursor (entry, cr,
5767 &cursor_location, FALSE, dir2,
5771 else /* overwrite_mode */
5773 GdkColor cursor_color;
5779 get_layout_position (entry, &x, &y);
5781 rect.x = PANGO_PIXELS (cursor_rect.x) + x;
5782 rect.y = PANGO_PIXELS (cursor_rect.y) + y;
5783 rect.width = PANGO_PIXELS (cursor_rect.width);
5784 rect.height = PANGO_PIXELS (cursor_rect.height);
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);
5805 gtk_entry_queue_draw (GtkEntry *entry)
5807 if (gtk_widget_is_drawable (GTK_WIDGET (entry)))
5808 gdk_window_invalidate_rect (entry->text_area, NULL, FALSE);
5812 _gtk_entry_reset_im_context (GtkEntry *entry)
5814 if (entry->need_im_reset)
5816 entry->need_im_reset = FALSE;
5817 gtk_im_context_reset (entry->im_context);
5822 * gtk_entry_reset_im_context:
5823 * @entry: a #GtkEntry
5825 * Reset the input method context of the entry if needed.
5827 * This can be necessary in the case where modifying the buffer
5828 * would confuse on-going input method behavior.
5833 gtk_entry_reset_im_context (GtkEntry *entry)
5835 g_return_if_fail (GTK_IS_ENTRY (entry));
5837 _gtk_entry_reset_im_context (entry);
5841 * gtk_entry_im_context_filter_keypress:
5842 * @entry: a #GtkEntry
5843 * @event: the key event
5845 * Allow the #GtkEntry input method to internally handle key press
5846 * and release events. If this function returns %TRUE, then no further
5847 * processing should be done for this key event. See
5848 * gtk_im_context_filter_keypress().
5850 * Note that you are expected to call this function from your handler
5851 * when overriding key event handling. This is needed in the case when
5852 * you need to insert your own key handling between the input method
5853 * and the default key event handling of the #GtkEntry.
5854 * See gtk_text_view_reset_im_context() for an example of use.
5856 * Return value: %TRUE if the input method handled the key event.
5861 gtk_entry_im_context_filter_keypress (GtkEntry *entry,
5864 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
5866 return gtk_im_context_filter_keypress (entry->im_context, event);
5871 gtk_entry_find_position (GtkEntry *entry,
5874 PangoLayout *layout;
5875 PangoLayoutLine *line;
5882 layout = gtk_entry_ensure_layout (entry, TRUE);
5883 text = pango_layout_get_text (layout);
5884 cursor_index = g_utf8_offset_to_pointer (text, entry->current_pos) - text;
5886 line = pango_layout_get_lines_readonly (layout)->data;
5887 pango_layout_line_x_to_index (line, x * PANGO_SCALE, &index, &trailing);
5889 if (index >= cursor_index && entry->preedit_length)
5891 if (index >= cursor_index + entry->preedit_length)
5892 index -= entry->preedit_length;
5895 index = cursor_index;
5900 pos = g_utf8_pointer_to_offset (text, text + index);
5907 gtk_entry_get_cursor_locations (GtkEntry *entry,
5912 DisplayMode mode = gtk_entry_get_display_mode (entry);
5914 /* Nothing to display at all, so no cursor is relevant */
5915 if (mode == DISPLAY_BLANK)
5925 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
5926 const gchar *text = pango_layout_get_text (layout);
5927 PangoRectangle strong_pos, weak_pos;
5930 if (type == CURSOR_STANDARD)
5932 index = g_utf8_offset_to_pointer (text, entry->current_pos + entry->preedit_cursor) - text;
5934 else /* type == CURSOR_DND */
5936 index = g_utf8_offset_to_pointer (text, entry->dnd_position) - text;
5938 if (entry->dnd_position > entry->current_pos)
5940 if (mode == DISPLAY_NORMAL)
5941 index += entry->preedit_length;
5944 gint preedit_len_chars = g_utf8_strlen (text, -1) - gtk_entry_buffer_get_length (get_buffer (entry));
5945 index += preedit_len_chars * g_unichar_to_utf8 (entry->invisible_char, NULL);
5950 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
5953 *strong_x = strong_pos.x / PANGO_SCALE;
5956 *weak_x = weak_pos.x / PANGO_SCALE;
5961 gtk_entry_adjust_scroll (GtkEntry *entry)
5963 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
5964 gint min_offset, max_offset;
5965 gint text_area_width, text_width;
5966 GtkBorder inner_border;
5967 gint strong_x, weak_x;
5968 gint strong_xoffset, weak_xoffset;
5970 PangoLayout *layout;
5971 PangoLayoutLine *line;
5972 PangoRectangle logical_rect;
5974 if (!gtk_widget_get_realized (GTK_WIDGET (entry)))
5977 _gtk_entry_effective_inner_border (entry, &inner_border);
5979 gdk_drawable_get_size (entry->text_area, &text_area_width, NULL);
5980 text_area_width -= inner_border.left + inner_border.right;
5981 if (text_area_width < 0)
5982 text_area_width = 0;
5984 layout = gtk_entry_ensure_layout (entry, TRUE);
5985 line = pango_layout_get_lines_readonly (layout)->data;
5987 pango_layout_line_get_extents (line, NULL, &logical_rect);
5989 /* Display as much text as we can */
5991 if (entry->resolved_dir == PANGO_DIRECTION_LTR)
5992 xalign = priv->xalign;
5994 xalign = 1.0 - priv->xalign;
5996 text_width = PANGO_PIXELS(logical_rect.width);
5998 if (text_width > text_area_width)
6001 max_offset = text_width - text_area_width;
6005 min_offset = (text_width - text_area_width) * xalign;
6006 max_offset = min_offset;
6009 entry->scroll_offset = CLAMP (entry->scroll_offset, min_offset, max_offset);
6011 /* And make sure cursors are on screen. Note that the cursor is
6012 * actually drawn one pixel into the INNER_BORDER space on
6013 * the right, when the scroll is at the utmost right. This
6014 * looks better to to me than confining the cursor inside the
6015 * border entirely, though it means that the cursor gets one
6016 * pixel closer to the edge of the widget on the right than
6017 * on the left. This might need changing if one changed
6018 * INNER_BORDER from 2 to 1, as one would do on a
6019 * small-screen-real-estate display.
6021 * We always make sure that the strong cursor is on screen, and
6022 * put the weak cursor on screen if possible.
6025 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, &weak_x);
6027 strong_xoffset = strong_x - entry->scroll_offset;
6029 if (strong_xoffset < 0)
6031 entry->scroll_offset += strong_xoffset;
6034 else if (strong_xoffset > text_area_width)
6036 entry->scroll_offset += strong_xoffset - text_area_width;
6037 strong_xoffset = text_area_width;
6040 weak_xoffset = weak_x - entry->scroll_offset;
6042 if (weak_xoffset < 0 && strong_xoffset - weak_xoffset <= text_area_width)
6044 entry->scroll_offset += weak_xoffset;
6046 else if (weak_xoffset > text_area_width &&
6047 strong_xoffset - (weak_xoffset - text_area_width) >= 0)
6049 entry->scroll_offset += weak_xoffset - text_area_width;
6052 g_object_notify (G_OBJECT (entry), "scroll-offset");
6056 gtk_entry_move_adjustments (GtkEntry *entry)
6058 GtkAllocation allocation;
6059 GtkAdjustment *adjustment;
6060 PangoContext *context;
6061 PangoFontMetrics *metrics;
6062 gint x, layout_x, border_x, border_y;
6065 adjustment = g_object_get_qdata (G_OBJECT (entry), quark_cursor_hadjustment);
6069 gtk_widget_get_allocation (&(entry->widget), &allocation);
6071 /* Cursor position, layout offset, border width, and widget allocation */
6072 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &x, NULL);
6073 get_layout_position (entry, &layout_x, NULL);
6074 _gtk_entry_get_borders (entry, &border_x, &border_y);
6075 x += allocation.x + layout_x + border_x;
6077 /* Approximate width of a char, so user can see what is ahead/behind */
6078 context = gtk_widget_get_pango_context (GTK_WIDGET (entry));
6079 metrics = pango_context_get_metrics (context,
6080 gtk_widget_get_style (&(entry->widget))->font_desc,
6081 pango_context_get_language (context));
6082 char_width = pango_font_metrics_get_approximate_char_width (metrics) / PANGO_SCALE;
6085 gtk_adjustment_clamp_page (adjustment,
6086 x - (char_width + 1), /* one char + one pixel before */
6087 x + (char_width + 2)); /* one char + cursor + one pixel after */
6091 gtk_entry_move_visually (GtkEntry *entry,
6096 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6099 text = pango_layout_get_text (layout);
6101 index = g_utf8_offset_to_pointer (text, start) - text;
6105 int new_index, new_trailing;
6106 gboolean split_cursor;
6109 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
6110 "gtk-split-cursor", &split_cursor,
6117 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
6118 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
6120 strong = keymap_direction == entry->resolved_dir;
6125 pango_layout_move_cursor_visually (layout, strong, index, 0, 1, &new_index, &new_trailing);
6130 pango_layout_move_cursor_visually (layout, strong, index, 0, -1, &new_index, &new_trailing);
6136 else if (new_index != G_MAXINT)
6139 while (new_trailing--)
6140 index = g_utf8_next_char (text + index) - text;
6143 return g_utf8_pointer_to_offset (text, text + index);
6147 gtk_entry_move_logically (GtkEntry *entry,
6151 gint new_pos = start;
6154 length = gtk_entry_buffer_get_length (get_buffer (entry));
6156 /* Prevent any leak of information */
6157 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6159 new_pos = CLAMP (start + count, 0, length);
6163 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6164 PangoLogAttr *log_attrs;
6167 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6169 while (count > 0 && new_pos < length)
6173 while (new_pos < length && !log_attrs[new_pos].is_cursor_position);
6177 while (count < 0 && new_pos > 0)
6181 while (new_pos > 0 && !log_attrs[new_pos].is_cursor_position);
6193 gtk_entry_move_forward_word (GtkEntry *entry,
6195 gboolean allow_whitespace)
6197 gint new_pos = start;
6200 length = gtk_entry_buffer_get_length (get_buffer (entry));
6202 /* Prevent any leak of information */
6203 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6207 else if (new_pos < length)
6209 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6210 PangoLogAttr *log_attrs;
6213 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6215 /* Find the next word boundary */
6217 while (new_pos < n_attrs - 1 && !(log_attrs[new_pos].is_word_end ||
6218 (log_attrs[new_pos].is_word_start && allow_whitespace)))
6229 gtk_entry_move_backward_word (GtkEntry *entry,
6231 gboolean allow_whitespace)
6233 gint new_pos = start;
6235 /* Prevent any leak of information */
6236 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6242 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6243 PangoLogAttr *log_attrs;
6246 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6248 new_pos = start - 1;
6250 /* Find the previous word boundary */
6251 while (new_pos > 0 && !(log_attrs[new_pos].is_word_start ||
6252 (log_attrs[new_pos].is_word_end && allow_whitespace)))
6262 gtk_entry_delete_whitespace (GtkEntry *entry)
6264 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6265 PangoLogAttr *log_attrs;
6269 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6271 start = end = entry->current_pos;
6273 while (start > 0 && log_attrs[start-1].is_white)
6276 while (end < n_attrs && log_attrs[end].is_white)
6282 gtk_editable_delete_text (GTK_EDITABLE (entry), start, end);
6287 gtk_entry_select_word (GtkEntry *entry)
6289 gint start_pos = gtk_entry_move_backward_word (entry, entry->current_pos, TRUE);
6290 gint end_pos = gtk_entry_move_forward_word (entry, entry->current_pos, TRUE);
6292 gtk_editable_select_region (GTK_EDITABLE (entry), start_pos, end_pos);
6296 gtk_entry_select_line (GtkEntry *entry)
6298 gtk_editable_select_region (GTK_EDITABLE (entry), 0, -1);
6302 truncate_multiline (const gchar *text)
6307 text[length] && text[length] != '\n' && text[length] != '\r';
6314 paste_received (GtkClipboard *clipboard,
6318 GtkEntry *entry = GTK_ENTRY (data);
6319 GtkEditable *editable = GTK_EDITABLE (entry);
6320 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
6322 if (entry->button == 2)
6324 gint pos, start, end;
6325 pos = priv->insert_pos;
6326 gtk_editable_get_selection_bounds (editable, &start, &end);
6327 if (!((start <= pos && pos <= end) || (end <= pos && pos <= start)))
6328 gtk_editable_select_region (editable, pos, pos);
6333 gint pos, start, end;
6335 gboolean popup_completion;
6336 GtkEntryCompletion *completion;
6338 completion = gtk_entry_get_completion (entry);
6340 if (entry->truncate_multiline)
6341 length = truncate_multiline (text);
6343 /* only complete if the selection is at the end */
6344 popup_completion = (gtk_entry_buffer_get_length (get_buffer (entry)) ==
6345 MAX (entry->current_pos, entry->selection_bound));
6349 if (gtk_widget_get_mapped (completion->priv->popup_window))
6350 _gtk_entry_completion_popdown (completion);
6352 if (!popup_completion && completion->priv->changed_id > 0)
6353 g_signal_handler_block (entry, completion->priv->changed_id);
6356 begin_change (entry);
6357 g_object_freeze_notify (G_OBJECT (entry));
6358 if (gtk_editable_get_selection_bounds (editable, &start, &end))
6359 gtk_editable_delete_text (editable, start, end);
6361 pos = entry->current_pos;
6362 gtk_editable_insert_text (editable, text, length, &pos);
6363 gtk_editable_set_position (editable, pos);
6364 g_object_thaw_notify (G_OBJECT (entry));
6368 !popup_completion && completion->priv->changed_id > 0)
6369 g_signal_handler_unblock (entry, completion->priv->changed_id);
6372 g_object_unref (entry);
6376 gtk_entry_paste (GtkEntry *entry,
6379 g_object_ref (entry);
6380 gtk_clipboard_request_text (gtk_widget_get_clipboard (GTK_WIDGET (entry), selection),
6381 paste_received, entry);
6385 primary_get_cb (GtkClipboard *clipboard,
6386 GtkSelectionData *selection_data,
6390 GtkEntry *entry = GTK_ENTRY (data);
6393 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end))
6395 gchar *str = gtk_entry_get_display_text (entry, start, end);
6396 gtk_selection_data_set_text (selection_data, str, -1);
6402 primary_clear_cb (GtkClipboard *clipboard,
6405 GtkEntry *entry = GTK_ENTRY (data);
6407 gtk_editable_select_region (GTK_EDITABLE (entry), entry->current_pos, entry->current_pos);
6411 gtk_entry_update_primary_selection (GtkEntry *entry)
6413 GtkTargetList *list;
6414 GtkTargetEntry *targets;
6415 GtkClipboard *clipboard;
6419 if (!gtk_widget_get_realized (GTK_WIDGET (entry)))
6422 list = gtk_target_list_new (NULL, 0);
6423 gtk_target_list_add_text_targets (list, 0);
6425 targets = gtk_target_table_new_from_list (list, &n_targets);
6427 clipboard = gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_PRIMARY);
6429 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end))
6431 if (!gtk_clipboard_set_with_owner (clipboard, targets, n_targets,
6432 primary_get_cb, primary_clear_cb, G_OBJECT (entry)))
6433 primary_clear_cb (clipboard, entry);
6437 if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (entry))
6438 gtk_clipboard_clear (clipboard);
6441 gtk_target_table_free (targets, n_targets);
6442 gtk_target_list_unref (list);
6446 gtk_entry_clear (GtkEntry *entry,
6447 GtkEntryIconPosition icon_pos)
6449 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
6450 EntryIconInfo *icon_info = priv->icons[icon_pos];
6452 if (!icon_info || icon_info->storage_type == GTK_IMAGE_EMPTY)
6455 g_object_freeze_notify (G_OBJECT (entry));
6457 /* Explicitly check, as the pointer may become invalidated
6458 * during destruction.
6460 if (GDK_IS_WINDOW (icon_info->window))
6461 gdk_window_hide (icon_info->window);
6463 if (icon_info->pixbuf)
6465 g_object_unref (icon_info->pixbuf);
6466 icon_info->pixbuf = NULL;
6469 switch (icon_info->storage_type)
6471 case GTK_IMAGE_PIXBUF:
6472 g_object_notify (G_OBJECT (entry),
6473 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-pixbuf" : "secondary-icon-pixbuf");
6476 case GTK_IMAGE_STOCK:
6477 g_free (icon_info->stock_id);
6478 icon_info->stock_id = NULL;
6479 g_object_notify (G_OBJECT (entry),
6480 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-stock" : "secondary-icon-stock");
6483 case GTK_IMAGE_ICON_NAME:
6484 g_free (icon_info->icon_name);
6485 icon_info->icon_name = NULL;
6486 g_object_notify (G_OBJECT (entry),
6487 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-name" : "secondary-icon-name");
6490 case GTK_IMAGE_GICON:
6491 if (icon_info->gicon)
6493 g_object_unref (icon_info->gicon);
6494 icon_info->gicon = NULL;
6496 g_object_notify (G_OBJECT (entry),
6497 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-gicon" : "secondary-icon-gicon");
6501 g_assert_not_reached ();
6505 icon_info->storage_type = GTK_IMAGE_EMPTY;
6506 g_object_notify (G_OBJECT (entry),
6507 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-storage-type" : "secondary-icon-storage-type");
6509 g_object_thaw_notify (G_OBJECT (entry));
6513 gtk_entry_ensure_pixbuf (GtkEntry *entry,
6514 GtkEntryIconPosition icon_pos)
6516 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
6517 EntryIconInfo *icon_info = priv->icons[icon_pos];
6519 GtkIconTheme *icon_theme;
6520 GtkSettings *settings;
6526 if (!icon_info || icon_info->pixbuf)
6529 widget = GTK_WIDGET (entry);
6531 switch (icon_info->storage_type)
6533 case GTK_IMAGE_EMPTY:
6534 case GTK_IMAGE_PIXBUF:
6536 case GTK_IMAGE_STOCK:
6537 state = gtk_widget_get_state (widget);
6538 gtk_widget_set_state (widget, GTK_STATE_NORMAL);
6539 icon_info->pixbuf = gtk_widget_render_icon (widget,
6540 icon_info->stock_id,
6543 if (!icon_info->pixbuf)
6544 icon_info->pixbuf = gtk_widget_render_icon (widget,
6545 GTK_STOCK_MISSING_IMAGE,
6548 gtk_widget_set_state (widget, state);
6551 case GTK_IMAGE_ICON_NAME:
6552 screen = gtk_widget_get_screen (widget);
6555 icon_theme = gtk_icon_theme_get_for_screen (screen);
6556 settings = gtk_settings_get_for_screen (screen);
6558 gtk_icon_size_lookup_for_settings (settings,
6562 icon_info->pixbuf = gtk_icon_theme_load_icon (icon_theme,
6563 icon_info->icon_name,
6564 MIN (width, height),
6567 if (icon_info->pixbuf == NULL)
6569 state = gtk_widget_get_state (widget);
6570 gtk_widget_set_state (widget, GTK_STATE_NORMAL);
6571 icon_info->pixbuf = gtk_widget_render_icon (widget,
6572 GTK_STOCK_MISSING_IMAGE,
6575 gtk_widget_set_state (widget, state);
6580 case GTK_IMAGE_GICON:
6581 screen = gtk_widget_get_screen (widget);
6584 icon_theme = gtk_icon_theme_get_for_screen (screen);
6585 settings = gtk_settings_get_for_screen (screen);
6587 gtk_icon_size_lookup_for_settings (settings,
6591 info = gtk_icon_theme_lookup_by_gicon (icon_theme,
6593 MIN (width, height),
6594 GTK_ICON_LOOKUP_USE_BUILTIN);
6597 icon_info->pixbuf = gtk_icon_info_load_icon (info, NULL);
6598 gtk_icon_info_free (info);
6601 if (icon_info->pixbuf == NULL)
6603 state = gtk_widget_get_state (widget);
6604 gtk_widget_set_state (widget, GTK_STATE_NORMAL);
6605 icon_info->pixbuf = gtk_widget_render_icon (widget,
6606 GTK_STOCK_MISSING_IMAGE,
6609 gtk_widget_set_state (widget, state);
6615 g_assert_not_reached ();
6619 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
6620 gdk_window_show_unraised (icon_info->window);
6630 * Creates a new entry.
6632 * Return value: a new #GtkEntry.
6635 gtk_entry_new (void)
6637 return g_object_new (GTK_TYPE_ENTRY, NULL);
6641 * gtk_entry_new_with_buffer:
6642 * @buffer: The buffer to use for the new #GtkEntry.
6644 * Creates a new entry with the specified text buffer.
6646 * Return value: a new #GtkEntry
6651 gtk_entry_new_with_buffer (GtkEntryBuffer *buffer)
6653 g_return_val_if_fail (GTK_IS_ENTRY_BUFFER (buffer), NULL);
6654 return g_object_new (GTK_TYPE_ENTRY, "buffer", buffer, NULL);
6657 static GtkEntryBuffer*
6658 get_buffer (GtkEntry *entry)
6660 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
6662 if (priv->buffer == NULL)
6664 GtkEntryBuffer *buffer;
6665 buffer = gtk_entry_buffer_new (NULL, 0);
6666 gtk_entry_set_buffer (entry, buffer);
6667 g_object_unref (buffer);
6670 return priv->buffer;
6674 * gtk_entry_get_buffer:
6675 * @entry: a #GtkEntry
6677 * Get the #GtkEntryBuffer object which holds the text for
6682 * Returns: (transfer none): A #GtkEntryBuffer object.
6685 gtk_entry_get_buffer (GtkEntry *entry)
6687 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
6689 return get_buffer (entry);
6693 * gtk_entry_set_buffer:
6694 * @entry: a #GtkEntry
6695 * @buffer: a #GtkEntryBuffer
6697 * Set the #GtkEntryBuffer object which holds the text for
6703 gtk_entry_set_buffer (GtkEntry *entry,
6704 GtkEntryBuffer *buffer)
6706 GtkEntryPrivate *priv;
6709 g_return_if_fail (GTK_IS_ENTRY (entry));
6710 priv = GTK_ENTRY_GET_PRIVATE (entry);
6714 g_return_if_fail (GTK_IS_ENTRY_BUFFER (buffer));
6715 g_object_ref (buffer);
6720 buffer_disconnect_signals (entry);
6721 g_object_unref (priv->buffer);
6724 priv->buffer = buffer;
6727 buffer_connect_signals (entry);
6729 obj = G_OBJECT (entry);
6730 g_object_freeze_notify (obj);
6731 g_object_notify (obj, "buffer");
6732 g_object_notify (obj, "text");
6733 g_object_notify (obj, "text-length");
6734 g_object_notify (obj, "max-length");
6735 g_object_notify (obj, "visibility");
6736 g_object_notify (obj, "invisible-char");
6737 g_object_notify (obj, "invisible-char-set");
6738 g_object_thaw_notify (obj);
6740 gtk_editable_set_position (GTK_EDITABLE (entry), 0);
6741 gtk_entry_recompute (entry);
6745 * gtk_entry_get_text_window:
6746 * @entry: a #GtkEntry
6748 * Returns the #GdkWindow which contains the text. This function is
6749 * useful when drawing something to the entry in a draw
6750 * callback because it enables the callback to distinguish between
6751 * the text window and entry's icon windows.
6753 * See also gtk_entry_get_icon_window().
6755 * Return value: (transfer none): the entry's text window.
6760 gtk_entry_get_text_window (GtkEntry *entry)
6762 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
6764 return entry->text_area;
6769 * gtk_entry_set_text:
6770 * @entry: a #GtkEntry
6771 * @text: the new text
6773 * Sets the text in the widget to the given
6774 * value, replacing the current contents.
6776 * See gtk_entry_buffer_set_text().
6779 gtk_entry_set_text (GtkEntry *entry,
6783 GtkEntryCompletion *completion;
6784 GtkEntryPrivate *priv;
6786 g_return_if_fail (GTK_IS_ENTRY (entry));
6787 g_return_if_fail (text != NULL);
6788 priv = GTK_ENTRY_GET_PRIVATE (entry);
6790 /* Actually setting the text will affect the cursor and selection;
6791 * if the contents don't actually change, this will look odd to the user.
6793 if (strcmp (gtk_entry_buffer_get_text (get_buffer (entry)), text) == 0)
6796 completion = gtk_entry_get_completion (entry);
6797 if (completion && completion->priv->changed_id > 0)
6798 g_signal_handler_block (entry, completion->priv->changed_id);
6800 begin_change (entry);
6801 g_object_freeze_notify (G_OBJECT (entry));
6802 gtk_editable_delete_text (GTK_EDITABLE (entry), 0, -1);
6804 gtk_editable_insert_text (GTK_EDITABLE (entry), text, strlen (text), &tmp_pos);
6805 g_object_thaw_notify (G_OBJECT (entry));
6808 if (completion && completion->priv->changed_id > 0)
6809 g_signal_handler_unblock (entry, completion->priv->changed_id);
6813 * gtk_entry_set_visibility:
6814 * @entry: a #GtkEntry
6815 * @visible: %TRUE if the contents of the entry are displayed
6818 * Sets whether the contents of the entry are visible or not.
6819 * When visibility is set to %FALSE, characters are displayed
6820 * as the invisible char, and will also appear that way when
6821 * the text in the entry widget is copied elsewhere.
6823 * By default, GTK+ picks the best invisible character available
6824 * in the current font, but it can be changed with
6825 * gtk_entry_set_invisible_char().
6828 gtk_entry_set_visibility (GtkEntry *entry,
6831 g_return_if_fail (GTK_IS_ENTRY (entry));
6833 visible = visible != FALSE;
6835 if (entry->visible != visible)
6837 entry->visible = visible;
6839 g_object_notify (G_OBJECT (entry), "visibility");
6840 gtk_entry_recompute (entry);
6845 * gtk_entry_get_visibility:
6846 * @entry: a #GtkEntry
6848 * Retrieves whether the text in @entry is visible. See
6849 * gtk_entry_set_visibility().
6851 * Return value: %TRUE if the text is currently visible
6854 gtk_entry_get_visibility (GtkEntry *entry)
6856 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
6858 return entry->visible;
6862 * gtk_entry_set_invisible_char:
6863 * @entry: a #GtkEntry
6864 * @ch: a Unicode character
6866 * Sets the character to use in place of the actual text when
6867 * gtk_entry_set_visibility() has been called to set text visibility
6868 * to %FALSE. i.e. this is the character used in "password mode" to
6869 * show the user how many characters have been typed. By default, GTK+
6870 * picks the best invisible char available in the current font. If you
6871 * set the invisible char to 0, then the user will get no feedback
6872 * at all; there will be no text on the screen as they type.
6875 gtk_entry_set_invisible_char (GtkEntry *entry,
6878 GtkEntryPrivate *priv;
6880 g_return_if_fail (GTK_IS_ENTRY (entry));
6882 priv = GTK_ENTRY_GET_PRIVATE (entry);
6884 if (!priv->invisible_char_set)
6886 priv->invisible_char_set = TRUE;
6887 g_object_notify (G_OBJECT (entry), "invisible-char-set");
6890 if (ch == entry->invisible_char)
6893 entry->invisible_char = ch;
6894 g_object_notify (G_OBJECT (entry), "invisible-char");
6895 gtk_entry_recompute (entry);
6899 * gtk_entry_get_invisible_char:
6900 * @entry: a #GtkEntry
6902 * Retrieves the character displayed in place of the real characters
6903 * for entries with visibility set to false. See gtk_entry_set_invisible_char().
6905 * Return value: the current invisible char, or 0, if the entry does not
6906 * show invisible text at all.
6909 gtk_entry_get_invisible_char (GtkEntry *entry)
6911 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
6913 return entry->invisible_char;
6917 * gtk_entry_unset_invisible_char:
6918 * @entry: a #GtkEntry
6920 * Unsets the invisible char previously set with
6921 * gtk_entry_set_invisible_char(). So that the
6922 * default invisible char is used again.
6927 gtk_entry_unset_invisible_char (GtkEntry *entry)
6929 GtkEntryPrivate *priv;
6932 g_return_if_fail (GTK_IS_ENTRY (entry));
6934 priv = GTK_ENTRY_GET_PRIVATE (entry);
6936 if (!priv->invisible_char_set)
6939 priv->invisible_char_set = FALSE;
6940 ch = find_invisible_char (GTK_WIDGET (entry));
6942 if (entry->invisible_char != ch)
6944 entry->invisible_char = ch;
6945 g_object_notify (G_OBJECT (entry), "invisible-char");
6948 g_object_notify (G_OBJECT (entry), "invisible-char-set");
6949 gtk_entry_recompute (entry);
6953 * gtk_entry_set_overwrite_mode:
6954 * @entry: a #GtkEntry
6955 * @overwrite: new value
6957 * Sets whether the text is overwritten when typing in the #GtkEntry.
6962 gtk_entry_set_overwrite_mode (GtkEntry *entry,
6965 g_return_if_fail (GTK_IS_ENTRY (entry));
6967 if (entry->overwrite_mode == overwrite)
6970 gtk_entry_toggle_overwrite (entry);
6972 g_object_notify (G_OBJECT (entry), "overwrite-mode");
6976 * gtk_entry_get_overwrite_mode:
6977 * @entry: a #GtkEntry
6979 * Gets the value set by gtk_entry_set_overwrite_mode().
6981 * Return value: whether the text is overwritten when typing.
6986 gtk_entry_get_overwrite_mode (GtkEntry *entry)
6988 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
6990 return entry->overwrite_mode;
6994 * gtk_entry_get_text:
6995 * @entry: a #GtkEntry
6997 * Retrieves the contents of the entry widget.
6998 * See also gtk_editable_get_chars().
7000 * This is equivalent to:
7002 * <informalexample><programlisting>
7003 * gtk_entry_buffer_get_text (gtk_entry_get_buffer (entry));
7004 * </programlisting></informalexample>
7006 * Return value: a pointer to the contents of the widget as a
7007 * string. This string points to internally allocated
7008 * storage in the widget and must not be freed, modified or
7011 G_CONST_RETURN gchar*
7012 gtk_entry_get_text (GtkEntry *entry)
7014 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7015 return gtk_entry_buffer_get_text (get_buffer (entry));
7019 * gtk_entry_set_max_length:
7020 * @entry: a #GtkEntry
7021 * @max: the maximum length of the entry, or 0 for no maximum.
7022 * (other than the maximum length of entries.) The value passed in will
7023 * be clamped to the range 0-65536.
7025 * Sets the maximum allowed length of the contents of the widget. If
7026 * the current contents are longer than the given length, then they
7027 * will be truncated to fit.
7029 * This is equivalent to:
7031 * <informalexample><programlisting>
7032 * gtk_entry_buffer_set_max_length (gtk_entry_get_buffer (entry), max);
7033 * </programlisting></informalexample>
7036 gtk_entry_set_max_length (GtkEntry *entry,
7039 g_return_if_fail (GTK_IS_ENTRY (entry));
7040 gtk_entry_buffer_set_max_length (get_buffer (entry), max);
7044 * gtk_entry_get_max_length:
7045 * @entry: a #GtkEntry
7047 * Retrieves the maximum allowed length of the text in
7048 * @entry. See gtk_entry_set_max_length().
7050 * This is equivalent to:
7052 * <informalexample><programlisting>
7053 * gtk_entry_buffer_get_max_length (gtk_entry_get_buffer (entry));
7054 * </programlisting></informalexample>
7056 * Return value: the maximum allowed number of characters
7057 * in #GtkEntry, or 0 if there is no maximum.
7060 gtk_entry_get_max_length (GtkEntry *entry)
7062 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7063 return gtk_entry_buffer_get_max_length (get_buffer (entry));
7067 * gtk_entry_get_text_length:
7068 * @entry: a #GtkEntry
7070 * Retrieves the current length of the text in
7073 * This is equivalent to:
7075 * <informalexample><programlisting>
7076 * gtk_entry_buffer_get_length (gtk_entry_get_buffer (entry));
7077 * </programlisting></informalexample>
7079 * Return value: the current number of characters
7080 * in #GtkEntry, or 0 if there are none.
7085 gtk_entry_get_text_length (GtkEntry *entry)
7087 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7088 return gtk_entry_buffer_get_length (get_buffer (entry));
7092 * gtk_entry_set_activates_default:
7093 * @entry: a #GtkEntry
7094 * @setting: %TRUE to activate window's default widget on Enter keypress
7096 * If @setting is %TRUE, pressing Enter in the @entry will activate the default
7097 * widget for the window containing the entry. This usually means that
7098 * the dialog box containing the entry will be closed, since the default
7099 * widget is usually one of the dialog buttons.
7101 * (For experts: if @setting is %TRUE, the entry calls
7102 * gtk_window_activate_default() on the window containing the entry, in
7103 * the default handler for the #GtkWidget::activate signal.)
7106 gtk_entry_set_activates_default (GtkEntry *entry,
7109 g_return_if_fail (GTK_IS_ENTRY (entry));
7110 setting = setting != FALSE;
7112 if (setting != entry->activates_default)
7114 entry->activates_default = setting;
7115 g_object_notify (G_OBJECT (entry), "activates-default");
7120 * gtk_entry_get_activates_default:
7121 * @entry: a #GtkEntry
7123 * Retrieves the value set by gtk_entry_set_activates_default().
7125 * Return value: %TRUE if the entry will activate the default widget
7128 gtk_entry_get_activates_default (GtkEntry *entry)
7130 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7132 return entry->activates_default;
7136 * gtk_entry_set_width_chars:
7137 * @entry: a #GtkEntry
7138 * @n_chars: width in chars
7140 * Changes the size request of the entry to be about the right size
7141 * for @n_chars characters. Note that it changes the size
7142 * <emphasis>request</emphasis>, the size can still be affected by
7143 * how you pack the widget into containers. If @n_chars is -1, the
7144 * size reverts to the default entry size.
7147 gtk_entry_set_width_chars (GtkEntry *entry,
7150 g_return_if_fail (GTK_IS_ENTRY (entry));
7152 if (entry->width_chars != n_chars)
7154 entry->width_chars = n_chars;
7155 g_object_notify (G_OBJECT (entry), "width-chars");
7156 gtk_widget_queue_resize (GTK_WIDGET (entry));
7161 * gtk_entry_get_width_chars:
7162 * @entry: a #GtkEntry
7164 * Gets the value set by gtk_entry_set_width_chars().
7166 * Return value: number of chars to request space for, or negative if unset
7169 gtk_entry_get_width_chars (GtkEntry *entry)
7171 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7173 return entry->width_chars;
7177 * gtk_entry_set_has_frame:
7178 * @entry: a #GtkEntry
7179 * @setting: new value
7181 * Sets whether the entry has a beveled frame around it.
7184 gtk_entry_set_has_frame (GtkEntry *entry,
7187 g_return_if_fail (GTK_IS_ENTRY (entry));
7189 setting = (setting != FALSE);
7191 if (entry->has_frame == setting)
7194 gtk_widget_queue_resize (GTK_WIDGET (entry));
7195 entry->has_frame = setting;
7196 g_object_notify (G_OBJECT (entry), "has-frame");
7200 * gtk_entry_get_has_frame:
7201 * @entry: a #GtkEntry
7203 * Gets the value set by gtk_entry_set_has_frame().
7205 * Return value: whether the entry has a beveled frame
7208 gtk_entry_get_has_frame (GtkEntry *entry)
7210 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7212 return entry->has_frame;
7216 * gtk_entry_set_inner_border:
7217 * @entry: a #GtkEntry
7218 * @border: (allow-none): a #GtkBorder, or %NULL
7220 * Sets %entry's inner-border property to %border, or clears it if %NULL
7221 * is passed. The inner-border is the area around the entry's text, but
7224 * If set, this property overrides the inner-border style property.
7225 * Overriding the style-provided border is useful when you want to do
7226 * in-place editing of some text in a canvas or list widget, where
7227 * pixel-exact positioning of the entry is important.
7232 gtk_entry_set_inner_border (GtkEntry *entry,
7233 const GtkBorder *border)
7235 g_return_if_fail (GTK_IS_ENTRY (entry));
7237 gtk_widget_queue_resize (GTK_WIDGET (entry));
7240 g_object_set_qdata_full (G_OBJECT (entry), quark_inner_border,
7241 gtk_border_copy (border),
7242 (GDestroyNotify) gtk_border_free);
7244 g_object_set_qdata (G_OBJECT (entry), quark_inner_border, NULL);
7246 g_object_notify (G_OBJECT (entry), "inner-border");
7250 * gtk_entry_get_inner_border:
7251 * @entry: a #GtkEntry
7253 * This function returns the entry's #GtkEntry:inner-border property. See
7254 * gtk_entry_set_inner_border() for more information.
7256 * Return value: (transfer none): the entry's #GtkBorder, or %NULL if none was set.
7260 G_CONST_RETURN GtkBorder *
7261 gtk_entry_get_inner_border (GtkEntry *entry)
7263 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7265 return g_object_get_qdata (G_OBJECT (entry), quark_inner_border);
7269 * gtk_entry_get_layout:
7270 * @entry: a #GtkEntry
7272 * Gets the #PangoLayout used to display the entry.
7273 * The layout is useful to e.g. convert text positions to
7274 * pixel positions, in combination with gtk_entry_get_layout_offsets().
7275 * The returned layout is owned by the entry and must not be
7276 * modified or freed by the caller.
7278 * Keep in mind that the layout text may contain a preedit string, so
7279 * gtk_entry_layout_index_to_text_index() and
7280 * gtk_entry_text_index_to_layout_index() are needed to convert byte
7281 * indices in the layout to byte indices in the entry contents.
7283 * Return value: (transfer none): the #PangoLayout for this entry
7286 gtk_entry_get_layout (GtkEntry *entry)
7288 PangoLayout *layout;
7290 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7292 layout = gtk_entry_ensure_layout (entry, TRUE);
7299 * gtk_entry_layout_index_to_text_index:
7300 * @entry: a #GtkEntry
7301 * @layout_index: byte index into the entry layout text
7303 * Converts from a position in the entry contents (returned
7304 * by gtk_entry_get_text()) to a position in the
7305 * entry's #PangoLayout (returned by gtk_entry_get_layout(),
7306 * with text retrieved via pango_layout_get_text()).
7308 * Return value: byte index into the entry contents
7311 gtk_entry_layout_index_to_text_index (GtkEntry *entry,
7314 PangoLayout *layout;
7318 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7320 layout = gtk_entry_ensure_layout (entry, TRUE);
7321 text = pango_layout_get_text (layout);
7322 cursor_index = g_utf8_offset_to_pointer (text, entry->current_pos) - text;
7324 if (layout_index >= cursor_index && entry->preedit_length)
7326 if (layout_index >= cursor_index + entry->preedit_length)
7327 layout_index -= entry->preedit_length;
7329 layout_index = cursor_index;
7332 return layout_index;
7336 * gtk_entry_text_index_to_layout_index:
7337 * @entry: a #GtkEntry
7338 * @text_index: byte index into the entry contents
7340 * Converts from a position in the entry's #PangoLayout (returned by
7341 * gtk_entry_get_layout()) to a position in the entry contents
7342 * (returned by gtk_entry_get_text()).
7344 * Return value: byte index into the entry layout text
7347 gtk_entry_text_index_to_layout_index (GtkEntry *entry,
7350 PangoLayout *layout;
7353 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7355 layout = gtk_entry_ensure_layout (entry, TRUE);
7356 text = pango_layout_get_text (layout);
7357 cursor_index = g_utf8_offset_to_pointer (text, entry->current_pos) - text;
7359 if (text_index > cursor_index)
7360 text_index += entry->preedit_length;
7366 * gtk_entry_get_layout_offsets:
7367 * @entry: a #GtkEntry
7368 * @x: (allow-none): location to store X offset of layout, or %NULL
7369 * @y: (allow-none): location to store Y offset of layout, or %NULL
7372 * Obtains the position of the #PangoLayout used to render text
7373 * in the entry, in widget coordinates. Useful if you want to line
7374 * up the text in an entry with some other text, e.g. when using the
7375 * entry to implement editable cells in a sheet widget.
7377 * Also useful to convert mouse events into coordinates inside the
7378 * #PangoLayout, e.g. to take some action if some part of the entry text
7381 * Note that as the user scrolls around in the entry the offsets will
7382 * change; you'll need to connect to the "notify::scroll-offset"
7383 * signal to track this. Remember when using the #PangoLayout
7384 * functions you need to convert to and from pixels using
7385 * PANGO_PIXELS() or #PANGO_SCALE.
7387 * Keep in mind that the layout text may contain a preedit string, so
7388 * gtk_entry_layout_index_to_text_index() and
7389 * gtk_entry_text_index_to_layout_index() are needed to convert byte
7390 * indices in the layout to byte indices in the entry contents.
7393 gtk_entry_get_layout_offsets (GtkEntry *entry,
7397 gint text_area_x, text_area_y;
7399 g_return_if_fail (GTK_IS_ENTRY (entry));
7401 /* this gets coords relative to text area */
7402 get_layout_position (entry, x, y);
7404 /* convert to widget coords */
7405 gtk_entry_get_text_area_size (entry, &text_area_x, &text_area_y, NULL, NULL);
7416 * gtk_entry_set_alignment:
7417 * @entry: a #GtkEntry
7418 * @xalign: The horizontal alignment, from 0 (left) to 1 (right).
7419 * Reversed for RTL layouts
7421 * Sets the alignment for the contents of the entry. This controls
7422 * the horizontal positioning of the contents when the displayed
7423 * text is shorter than the width of the entry.
7428 gtk_entry_set_alignment (GtkEntry *entry, gfloat xalign)
7430 GtkEntryPrivate *priv;
7432 g_return_if_fail (GTK_IS_ENTRY (entry));
7434 priv = GTK_ENTRY_GET_PRIVATE (entry);
7438 else if (xalign > 1.0)
7441 if (xalign != priv->xalign)
7443 priv->xalign = xalign;
7445 gtk_entry_recompute (entry);
7447 g_object_notify (G_OBJECT (entry), "xalign");
7452 * gtk_entry_get_alignment:
7453 * @entry: a #GtkEntry
7455 * Gets the value set by gtk_entry_set_alignment().
7457 * Return value: the alignment
7462 gtk_entry_get_alignment (GtkEntry *entry)
7464 GtkEntryPrivate *priv;
7466 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
7468 priv = GTK_ENTRY_GET_PRIVATE (entry);
7470 return priv->xalign;
7474 * gtk_entry_set_icon_from_pixbuf:
7475 * @entry: a #GtkEntry
7476 * @icon_pos: Icon position
7477 * @pixbuf: (allow-none): A #GdkPixbuf, or %NULL
7479 * Sets the icon shown in the specified position using a pixbuf.
7481 * If @pixbuf is %NULL, no icon will be shown in the specified position.
7486 gtk_entry_set_icon_from_pixbuf (GtkEntry *entry,
7487 GtkEntryIconPosition icon_pos,
7490 GtkEntryPrivate *priv;
7491 EntryIconInfo *icon_info;
7493 g_return_if_fail (GTK_IS_ENTRY (entry));
7494 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7496 priv = GTK_ENTRY_GET_PRIVATE (entry);
7498 if ((icon_info = priv->icons[icon_pos]) == NULL)
7499 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7501 g_object_freeze_notify (G_OBJECT (entry));
7504 g_object_ref (pixbuf);
7506 gtk_entry_clear (entry, icon_pos);
7510 icon_info->storage_type = GTK_IMAGE_PIXBUF;
7511 icon_info->pixbuf = pixbuf;
7513 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7515 g_object_notify (G_OBJECT (entry), "primary-icon-pixbuf");
7516 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7520 g_object_notify (G_OBJECT (entry), "secondary-icon-pixbuf");
7521 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7524 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7525 gdk_window_show_unraised (icon_info->window);
7528 gtk_entry_ensure_pixbuf (entry, icon_pos);
7530 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7531 gtk_widget_queue_resize (GTK_WIDGET (entry));
7533 g_object_thaw_notify (G_OBJECT (entry));
7537 * gtk_entry_set_icon_from_stock:
7538 * @entry: A #GtkEntry
7539 * @icon_pos: Icon position
7540 * @stock_id: (allow-none): The name of the stock item, or %NULL
7542 * Sets the icon shown in the entry at the specified position from
7545 * If @stock_id is %NULL, no icon will be shown in the specified position.
7550 gtk_entry_set_icon_from_stock (GtkEntry *entry,
7551 GtkEntryIconPosition icon_pos,
7552 const gchar *stock_id)
7554 GtkEntryPrivate *priv;
7555 EntryIconInfo *icon_info;
7558 g_return_if_fail (GTK_IS_ENTRY (entry));
7559 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7561 priv = GTK_ENTRY_GET_PRIVATE (entry);
7563 if ((icon_info = priv->icons[icon_pos]) == NULL)
7564 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7566 g_object_freeze_notify (G_OBJECT (entry));
7568 gtk_widget_ensure_style (GTK_WIDGET (entry));
7570 /* need to dup before clearing */
7571 new_id = g_strdup (stock_id);
7573 gtk_entry_clear (entry, icon_pos);
7577 icon_info->storage_type = GTK_IMAGE_STOCK;
7578 icon_info->stock_id = new_id;
7580 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7582 g_object_notify (G_OBJECT (entry), "primary-icon-stock");
7583 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7587 g_object_notify (G_OBJECT (entry), "secondary-icon-stock");
7588 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7591 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7592 gdk_window_show_unraised (icon_info->window);
7595 gtk_entry_ensure_pixbuf (entry, icon_pos);
7597 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7598 gtk_widget_queue_resize (GTK_WIDGET (entry));
7600 g_object_thaw_notify (G_OBJECT (entry));
7604 * gtk_entry_set_icon_from_icon_name:
7605 * @entry: A #GtkEntry
7606 * @icon_pos: The position at which to set the icon
7607 * @icon_name: (allow-none): An icon name, or %NULL
7609 * Sets the icon shown in the entry at the specified position
7610 * from the current icon theme.
7612 * If the icon name isn't known, a "broken image" icon will be displayed
7615 * If @icon_name is %NULL, no icon will be shown in the specified position.
7620 gtk_entry_set_icon_from_icon_name (GtkEntry *entry,
7621 GtkEntryIconPosition icon_pos,
7622 const gchar *icon_name)
7624 GtkEntryPrivate *priv;
7625 EntryIconInfo *icon_info;
7628 g_return_if_fail (GTK_IS_ENTRY (entry));
7629 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7631 priv = GTK_ENTRY_GET_PRIVATE (entry);
7633 if ((icon_info = priv->icons[icon_pos]) == NULL)
7634 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7636 g_object_freeze_notify (G_OBJECT (entry));
7638 gtk_widget_ensure_style (GTK_WIDGET (entry));
7640 /* need to dup before clearing */
7641 new_name = g_strdup (icon_name);
7643 gtk_entry_clear (entry, icon_pos);
7645 if (new_name != NULL)
7647 icon_info->storage_type = GTK_IMAGE_ICON_NAME;
7648 icon_info->icon_name = new_name;
7650 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7652 g_object_notify (G_OBJECT (entry), "primary-icon-name");
7653 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7657 g_object_notify (G_OBJECT (entry), "secondary-icon-name");
7658 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7661 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7662 gdk_window_show_unraised (icon_info->window);
7665 gtk_entry_ensure_pixbuf (entry, icon_pos);
7667 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7668 gtk_widget_queue_resize (GTK_WIDGET (entry));
7670 g_object_thaw_notify (G_OBJECT (entry));
7674 * gtk_entry_set_icon_from_gicon:
7675 * @entry: A #GtkEntry
7676 * @icon_pos: The position at which to set the icon
7677 * @icon: (allow-none): The icon to set, or %NULL
7679 * Sets the icon shown in the entry at the specified position
7680 * from the current icon theme.
7681 * If the icon isn't known, a "broken image" icon will be displayed
7684 * If @icon is %NULL, no icon will be shown in the specified position.
7689 gtk_entry_set_icon_from_gicon (GtkEntry *entry,
7690 GtkEntryIconPosition icon_pos,
7693 GtkEntryPrivate *priv;
7694 EntryIconInfo *icon_info;
7696 g_return_if_fail (GTK_IS_ENTRY (entry));
7697 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7699 priv = GTK_ENTRY_GET_PRIVATE (entry);
7701 if ((icon_info = priv->icons[icon_pos]) == NULL)
7702 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7704 g_object_freeze_notify (G_OBJECT (entry));
7706 /* need to ref before clearing */
7708 g_object_ref (icon);
7710 gtk_entry_clear (entry, icon_pos);
7714 icon_info->storage_type = GTK_IMAGE_GICON;
7715 icon_info->gicon = icon;
7717 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7719 g_object_notify (G_OBJECT (entry), "primary-icon-gicon");
7720 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7724 g_object_notify (G_OBJECT (entry), "secondary-icon-gicon");
7725 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7728 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7729 gdk_window_show_unraised (icon_info->window);
7732 gtk_entry_ensure_pixbuf (entry, icon_pos);
7734 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7735 gtk_widget_queue_resize (GTK_WIDGET (entry));
7737 g_object_thaw_notify (G_OBJECT (entry));
7741 * gtk_entry_set_icon_activatable:
7742 * @entry: A #GtkEntry
7743 * @icon_pos: Icon position
7744 * @activatable: %TRUE if the icon should be activatable
7746 * Sets whether the icon is activatable.
7751 gtk_entry_set_icon_activatable (GtkEntry *entry,
7752 GtkEntryIconPosition icon_pos,
7753 gboolean activatable)
7755 GtkEntryPrivate *priv;
7756 EntryIconInfo *icon_info;
7758 g_return_if_fail (GTK_IS_ENTRY (entry));
7759 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7761 priv = GTK_ENTRY_GET_PRIVATE (entry);
7763 if ((icon_info = priv->icons[icon_pos]) == NULL)
7764 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7766 activatable = activatable != FALSE;
7768 if (icon_info->nonactivatable != !activatable)
7770 icon_info->nonactivatable = !activatable;
7772 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
7773 update_cursors (GTK_WIDGET (entry));
7775 g_object_notify (G_OBJECT (entry),
7776 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-activatable" : "secondary-icon-activatable");
7781 * gtk_entry_get_icon_activatable:
7782 * @entry: a #GtkEntry
7783 * @icon_pos: Icon position
7785 * Returns whether the icon is activatable.
7787 * Returns: %TRUE if the icon is activatable.
7792 gtk_entry_get_icon_activatable (GtkEntry *entry,
7793 GtkEntryIconPosition icon_pos)
7795 GtkEntryPrivate *priv;
7796 EntryIconInfo *icon_info;
7798 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7799 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), FALSE);
7801 priv = GTK_ENTRY_GET_PRIVATE (entry);
7802 icon_info = priv->icons[icon_pos];
7804 return (icon_info != NULL && !icon_info->nonactivatable);
7808 * gtk_entry_get_icon_pixbuf:
7809 * @entry: A #GtkEntry
7810 * @icon_pos: Icon position
7812 * Retrieves the image used for the icon.
7814 * Unlike the other methods of setting and getting icon data, this
7815 * method will work regardless of whether the icon was set using a
7816 * #GdkPixbuf, a #GIcon, a stock item, or an icon name.
7818 * Returns: (transfer none): A #GdkPixbuf, or %NULL if no icon is
7819 * set for this position.
7824 gtk_entry_get_icon_pixbuf (GtkEntry *entry,
7825 GtkEntryIconPosition icon_pos)
7827 GtkEntryPrivate *priv;
7828 EntryIconInfo *icon_info;
7830 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7831 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7833 priv = GTK_ENTRY_GET_PRIVATE (entry);
7834 icon_info = priv->icons[icon_pos];
7839 gtk_entry_ensure_pixbuf (entry, icon_pos);
7841 return icon_info->pixbuf;
7845 * gtk_entry_get_icon_gicon:
7846 * @entry: A #GtkEntry
7847 * @icon_pos: Icon position
7849 * Retrieves the #GIcon used for the icon, or %NULL if there is
7850 * no icon or if the icon was set by some other method (e.g., by
7851 * stock, pixbuf, or icon name).
7853 * Returns: (transfer none): A #GIcon, or %NULL if no icon is set
7854 * or if the icon is not a #GIcon
7859 gtk_entry_get_icon_gicon (GtkEntry *entry,
7860 GtkEntryIconPosition icon_pos)
7862 GtkEntryPrivate *priv;
7863 EntryIconInfo *icon_info;
7865 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7866 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7868 priv = GTK_ENTRY_GET_PRIVATE (entry);
7869 icon_info = priv->icons[icon_pos];
7874 return icon_info->storage_type == GTK_IMAGE_GICON ? icon_info->gicon : NULL;
7878 * gtk_entry_get_icon_stock:
7879 * @entry: A #GtkEntry
7880 * @icon_pos: Icon position
7882 * Retrieves the stock id used for the icon, or %NULL if there is
7883 * no icon or if the icon was set by some other method (e.g., by
7884 * pixbuf, icon name or gicon).
7886 * Returns: A stock id, or %NULL if no icon is set or if the icon
7887 * wasn't set from a stock id
7892 gtk_entry_get_icon_stock (GtkEntry *entry,
7893 GtkEntryIconPosition icon_pos)
7895 GtkEntryPrivate *priv;
7896 EntryIconInfo *icon_info;
7898 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7899 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7901 priv = GTK_ENTRY_GET_PRIVATE (entry);
7902 icon_info = priv->icons[icon_pos];
7907 return icon_info->storage_type == GTK_IMAGE_STOCK ? icon_info->stock_id : NULL;
7911 * gtk_entry_get_icon_name:
7912 * @entry: A #GtkEntry
7913 * @icon_pos: Icon position
7915 * Retrieves the icon name used for the icon, or %NULL if there is
7916 * no icon or if the icon was set by some other method (e.g., by
7917 * pixbuf, stock or gicon).
7919 * Returns: An icon name, or %NULL if no icon is set or if the icon
7920 * wasn't set from an icon name
7925 gtk_entry_get_icon_name (GtkEntry *entry,
7926 GtkEntryIconPosition icon_pos)
7928 GtkEntryPrivate *priv;
7929 EntryIconInfo *icon_info;
7931 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7932 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7934 priv = GTK_ENTRY_GET_PRIVATE (entry);
7935 icon_info = priv->icons[icon_pos];
7940 return icon_info->storage_type == GTK_IMAGE_ICON_NAME ? icon_info->icon_name : NULL;
7944 * gtk_entry_set_icon_sensitive:
7945 * @entry: A #GtkEntry
7946 * @icon_pos: Icon position
7947 * @sensitive: Specifies whether the icon should appear
7948 * sensitive or insensitive
7950 * Sets the sensitivity for the specified icon.
7955 gtk_entry_set_icon_sensitive (GtkEntry *entry,
7956 GtkEntryIconPosition icon_pos,
7959 GtkEntryPrivate *priv;
7960 EntryIconInfo *icon_info;
7962 g_return_if_fail (GTK_IS_ENTRY (entry));
7963 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7965 priv = GTK_ENTRY_GET_PRIVATE (entry);
7967 if ((icon_info = priv->icons[icon_pos]) == NULL)
7968 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7970 if (icon_info->insensitive != !sensitive)
7972 icon_info->insensitive = !sensitive;
7974 icon_info->pressed = FALSE;
7975 icon_info->prelight = FALSE;
7977 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
7978 update_cursors (GTK_WIDGET (entry));
7980 gtk_widget_queue_draw (GTK_WIDGET (entry));
7982 g_object_notify (G_OBJECT (entry),
7983 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-sensitive" : "secondary-icon-sensitive");
7988 * gtk_entry_get_icon_sensitive:
7989 * @entry: a #GtkEntry
7990 * @icon_pos: Icon position
7992 * Returns whether the icon appears sensitive or insensitive.
7994 * Returns: %TRUE if the icon is sensitive.
7999 gtk_entry_get_icon_sensitive (GtkEntry *entry,
8000 GtkEntryIconPosition icon_pos)
8002 GtkEntryPrivate *priv;
8003 EntryIconInfo *icon_info;
8005 g_return_val_if_fail (GTK_IS_ENTRY (entry), TRUE);
8006 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), TRUE);
8008 priv = GTK_ENTRY_GET_PRIVATE (entry);
8009 icon_info = priv->icons[icon_pos];
8011 return (!icon_info || !icon_info->insensitive);
8016 * gtk_entry_get_icon_storage_type:
8017 * @entry: a #GtkEntry
8018 * @icon_pos: Icon position
8020 * Gets the type of representation being used by the icon
8021 * to store image data. If the icon has no image data,
8022 * the return value will be %GTK_IMAGE_EMPTY.
8024 * Return value: image representation being used
8029 gtk_entry_get_icon_storage_type (GtkEntry *entry,
8030 GtkEntryIconPosition icon_pos)
8032 GtkEntryPrivate *priv;
8033 EntryIconInfo *icon_info;
8035 g_return_val_if_fail (GTK_IS_ENTRY (entry), GTK_IMAGE_EMPTY);
8036 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), GTK_IMAGE_EMPTY);
8038 priv = GTK_ENTRY_GET_PRIVATE (entry);
8039 icon_info = priv->icons[icon_pos];
8042 return GTK_IMAGE_EMPTY;
8044 return icon_info->storage_type;
8048 * gtk_entry_get_icon_at_pos:
8049 * @entry: a #GtkEntry
8050 * @x: the x coordinate of the position to find
8051 * @y: the y coordinate of the position to find
8053 * Finds the icon at the given position and return its index.
8054 * If @x, @y doesn't lie inside an icon, -1 is returned.
8055 * This function is intended for use in a #GtkWidget::query-tooltip
8058 * Returns: the index of the icon at the given position, or -1
8063 gtk_entry_get_icon_at_pos (GtkEntry *entry,
8067 GtkAllocation primary;
8068 GtkAllocation secondary;
8070 g_return_val_if_fail (GTK_IS_ENTRY (entry), -1);
8072 get_icon_allocations (entry, &primary, &secondary);
8074 if (primary.x <= x && x < primary.x + primary.width &&
8075 primary.y <= y && y < primary.y + primary.height)
8076 return GTK_ENTRY_ICON_PRIMARY;
8078 if (secondary.x <= x && x < secondary.x + secondary.width &&
8079 secondary.y <= y && y < secondary.y + secondary.height)
8080 return GTK_ENTRY_ICON_SECONDARY;
8086 * gtk_entry_set_icon_drag_source:
8087 * @entry: a #GtkIconEntry
8088 * @icon_pos: icon position
8089 * @target_list: the targets (data formats) in which the data can be provided
8090 * @actions: a bitmask of the allowed drag actions
8092 * Sets up the icon at the given position so that GTK+ will start a drag
8093 * operation when the user clicks and drags the icon.
8095 * To handle the drag operation, you need to connect to the usual
8096 * #GtkWidget::drag-data-get (or possibly #GtkWidget::drag-data-delete)
8097 * signal, and use gtk_entry_get_current_icon_drag_source() in
8098 * your signal handler to find out if the drag was started from
8101 * By default, GTK+ uses the icon as the drag icon. You can use the
8102 * #GtkWidget::drag-begin signal to set a different icon. Note that you
8103 * have to use g_signal_connect_after() to ensure that your signal handler
8104 * gets executed after the default handler.
8109 gtk_entry_set_icon_drag_source (GtkEntry *entry,
8110 GtkEntryIconPosition icon_pos,
8111 GtkTargetList *target_list,
8112 GdkDragAction actions)
8114 GtkEntryPrivate *priv;
8115 EntryIconInfo *icon_info;
8117 g_return_if_fail (GTK_IS_ENTRY (entry));
8118 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8120 priv = GTK_ENTRY_GET_PRIVATE (entry);
8122 if ((icon_info = priv->icons[icon_pos]) == NULL)
8123 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8125 if (icon_info->target_list)
8126 gtk_target_list_unref (icon_info->target_list);
8127 icon_info->target_list = target_list;
8128 if (icon_info->target_list)
8129 gtk_target_list_ref (icon_info->target_list);
8131 icon_info->actions = actions;
8135 * gtk_entry_get_current_icon_drag_source:
8136 * @entry: a #GtkIconEntry
8138 * Returns the index of the icon which is the source of the current
8139 * DND operation, or -1.
8141 * This function is meant to be used in a #GtkWidget::drag-data-get
8144 * Returns: index of the icon which is the source of the current
8145 * DND operation, or -1.
8150 gtk_entry_get_current_icon_drag_source (GtkEntry *entry)
8152 GtkEntryPrivate *priv;
8153 EntryIconInfo *icon_info = NULL;
8156 g_return_val_if_fail (GTK_IS_ENTRY (entry), -1);
8158 priv = GTK_ENTRY_GET_PRIVATE (entry);
8160 for (i = 0; i < MAX_ICONS; i++)
8162 if ((icon_info = priv->icons[i]))
8164 if (icon_info->in_drag)
8173 * gtk_entry_get_icon_window:
8174 * @entry: A #GtkEntry
8175 * @icon_pos: Icon position
8177 * Returns the #GdkWindow which contains the entry's icon at
8178 * @icon_pos. This function is useful when drawing something to the
8179 * entry in a draw callback because it enables the callback
8180 * to distinguish between the text window and entry's icon windows.
8182 * See also gtk_entry_get_text_window().
8184 * Return value: (transfer none): the entry's icon window at @icon_pos.
8189 gtk_entry_get_icon_window (GtkEntry *entry,
8190 GtkEntryIconPosition icon_pos)
8192 GtkEntryPrivate *priv;
8193 EntryIconInfo *icon_info;
8195 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8197 priv = GTK_ENTRY_GET_PRIVATE (entry);
8199 icon_info = priv->icons[icon_pos];
8202 return icon_info->window;
8208 ensure_has_tooltip (GtkEntry *entry)
8210 GtkEntryPrivate *priv;
8211 EntryIconInfo *icon_info;
8213 gboolean has_tooltip = FALSE;
8215 priv = GTK_ENTRY_GET_PRIVATE (entry);
8217 for (i = 0; i < MAX_ICONS; i++)
8219 if ((icon_info = priv->icons[i]) != NULL)
8221 if (icon_info->tooltip != NULL)
8229 gtk_widget_set_has_tooltip (GTK_WIDGET (entry), has_tooltip);
8233 * gtk_entry_get_icon_tooltip_text:
8234 * @entry: a #GtkEntry
8235 * @icon_pos: the icon position
8237 * Gets the contents of the tooltip on the icon at the specified
8238 * position in @entry.
8240 * Returns: the tooltip text, or %NULL. Free the returned string
8241 * with g_free() when done.
8246 gtk_entry_get_icon_tooltip_text (GtkEntry *entry,
8247 GtkEntryIconPosition icon_pos)
8249 GtkEntryPrivate *priv;
8250 EntryIconInfo *icon_info;
8253 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8254 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8256 priv = GTK_ENTRY_GET_PRIVATE (entry);
8257 icon_info = priv->icons[icon_pos];
8262 if (icon_info->tooltip &&
8263 !pango_parse_markup (icon_info->tooltip, -1, 0, NULL, &text, NULL, NULL))
8264 g_assert (NULL == text); /* text should still be NULL in case of markup errors */
8270 * gtk_entry_set_icon_tooltip_text:
8271 * @entry: a #GtkEntry
8272 * @icon_pos: the icon position
8273 * @tooltip: (allow-none): the contents of the tooltip for the icon, or %NULL
8275 * Sets @tooltip as the contents of the tooltip for the icon
8276 * at the specified position.
8278 * Use %NULL for @tooltip to remove an existing tooltip.
8280 * See also gtk_widget_set_tooltip_text() and
8281 * gtk_entry_set_icon_tooltip_markup().
8286 gtk_entry_set_icon_tooltip_text (GtkEntry *entry,
8287 GtkEntryIconPosition icon_pos,
8288 const gchar *tooltip)
8290 GtkEntryPrivate *priv;
8291 EntryIconInfo *icon_info;
8293 g_return_if_fail (GTK_IS_ENTRY (entry));
8294 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8296 priv = GTK_ENTRY_GET_PRIVATE (entry);
8298 if (!(icon_info = priv->icons[icon_pos]))
8299 icon_info = priv->icons[icon_pos];
8301 if (icon_info->tooltip)
8302 g_free (icon_info->tooltip);
8304 /* Treat an empty string as a NULL string,
8305 * because an empty string would be useless for a tooltip:
8307 if (tooltip && tooltip[0] == '\0')
8310 icon_info->tooltip = tooltip ? g_markup_escape_text (tooltip, -1) : NULL;
8312 ensure_has_tooltip (entry);
8316 * gtk_entry_get_icon_tooltip_markup:
8317 * @entry: a #GtkEntry
8318 * @icon_pos: the icon position
8320 * Gets the contents of the tooltip on the icon at the specified
8321 * position in @entry.
8323 * Returns: the tooltip text, or %NULL. Free the returned string
8324 * with g_free() when done.
8329 gtk_entry_get_icon_tooltip_markup (GtkEntry *entry,
8330 GtkEntryIconPosition icon_pos)
8332 GtkEntryPrivate *priv;
8333 EntryIconInfo *icon_info;
8335 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8336 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8338 priv = GTK_ENTRY_GET_PRIVATE (entry);
8339 icon_info = priv->icons[icon_pos];
8344 return g_strdup (icon_info->tooltip);
8348 * gtk_entry_set_icon_tooltip_markup:
8349 * @entry: a #GtkEntry
8350 * @icon_pos: the icon position
8351 * @tooltip: (allow-none): the contents of the tooltip for the icon, or %NULL
8353 * Sets @tooltip as the contents of the tooltip for the icon at
8354 * the specified position. @tooltip is assumed to be marked up with
8355 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
8357 * Use %NULL for @tooltip to remove an existing tooltip.
8359 * See also gtk_widget_set_tooltip_markup() and
8360 * gtk_enty_set_icon_tooltip_text().
8365 gtk_entry_set_icon_tooltip_markup (GtkEntry *entry,
8366 GtkEntryIconPosition icon_pos,
8367 const gchar *tooltip)
8369 GtkEntryPrivate *priv;
8370 EntryIconInfo *icon_info;
8372 g_return_if_fail (GTK_IS_ENTRY (entry));
8373 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8375 priv = GTK_ENTRY_GET_PRIVATE (entry);
8377 if (!(icon_info = priv->icons[icon_pos]))
8378 icon_info = priv->icons[icon_pos];
8380 if (icon_info->tooltip)
8381 g_free (icon_info->tooltip);
8383 /* Treat an empty string as a NULL string,
8384 * because an empty string would be useless for a tooltip:
8386 if (tooltip && tooltip[0] == '\0')
8389 icon_info->tooltip = g_strdup (tooltip);
8391 ensure_has_tooltip (entry);
8395 gtk_entry_query_tooltip (GtkWidget *widget,
8398 gboolean keyboard_tip,
8399 GtkTooltip *tooltip)
8402 GtkEntryPrivate *priv;
8403 EntryIconInfo *icon_info;
8406 entry = GTK_ENTRY (widget);
8407 priv = GTK_ENTRY_GET_PRIVATE (entry);
8411 icon_pos = gtk_entry_get_icon_at_pos (entry, x, y);
8414 if ((icon_info = priv->icons[icon_pos]) != NULL)
8416 if (icon_info->tooltip)
8418 gtk_tooltip_set_markup (tooltip, icon_info->tooltip);
8427 return GTK_WIDGET_CLASS (gtk_entry_parent_class)->query_tooltip (widget,
8434 /* Quick hack of a popup menu
8437 activate_cb (GtkWidget *menuitem,
8440 const gchar *signal = g_object_get_data (G_OBJECT (menuitem), "gtk-signal");
8441 g_signal_emit_by_name (entry, signal);
8446 gtk_entry_mnemonic_activate (GtkWidget *widget,
8447 gboolean group_cycling)
8449 gtk_widget_grab_focus (widget);
8454 append_action_signal (GtkEntry *entry,
8456 const gchar *stock_id,
8457 const gchar *signal,
8460 GtkWidget *menuitem = gtk_image_menu_item_new_from_stock (stock_id, NULL);
8462 g_object_set_data (G_OBJECT (menuitem), I_("gtk-signal"), (char *)signal);
8463 g_signal_connect (menuitem, "activate",
8464 G_CALLBACK (activate_cb), entry);
8466 gtk_widget_set_sensitive (menuitem, sensitive);
8468 gtk_widget_show (menuitem);
8469 gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
8473 popup_menu_detach (GtkWidget *attach_widget,
8476 GTK_ENTRY (attach_widget)->popup_menu = NULL;
8480 popup_position_func (GtkMenu *menu,
8486 GtkEntry *entry = GTK_ENTRY (user_data);
8487 GtkWidget *widget = GTK_WIDGET (entry);
8489 GtkRequisition menu_req;
8490 GdkRectangle monitor;
8491 GtkBorder inner_border;
8492 gint monitor_num, strong_x, height;
8494 g_return_if_fail (gtk_widget_get_realized (widget));
8496 gdk_window_get_origin (entry->text_area, x, y);
8498 screen = gtk_widget_get_screen (widget);
8499 monitor_num = gdk_screen_get_monitor_at_window (screen, entry->text_area);
8500 if (monitor_num < 0)
8502 gtk_menu_set_monitor (menu, monitor_num);
8504 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
8505 gtk_size_request_get_size (GTK_SIZE_REQUEST (entry->popup_menu),
8507 gdk_drawable_get_size (entry->text_area, NULL, &height);
8508 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
8509 _gtk_entry_effective_inner_border (entry, &inner_border);
8511 *x += inner_border.left + strong_x - entry->scroll_offset;
8512 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
8513 *x -= menu_req.width;
8515 if ((*y + height + menu_req.height) <= monitor.y + monitor.height)
8517 else if ((*y - menu_req.height) >= monitor.y)
8518 *y -= menu_req.height;
8519 else if (monitor.y + monitor.height - (*y + height) > *y)
8522 *y -= menu_req.height;
8528 unichar_chosen_func (const char *text,
8531 GtkEntry *entry = GTK_ENTRY (data);
8533 if (entry->editable)
8534 gtk_entry_enter_text (entry, text);
8545 popup_targets_received (GtkClipboard *clipboard,
8546 GtkSelectionData *data,
8549 PopupInfo *info = user_data;
8550 GtkEntry *entry = info->entry;
8552 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
8555 gboolean clipboard_contains_text;
8556 GtkWidget *menuitem;
8558 gboolean show_input_method_menu;
8559 gboolean show_unicode_menu;
8561 clipboard_contains_text = gtk_selection_data_targets_include_text (data);
8562 if (entry->popup_menu)
8563 gtk_widget_destroy (entry->popup_menu);
8565 entry->popup_menu = gtk_menu_new ();
8567 gtk_menu_attach_to_widget (GTK_MENU (entry->popup_menu),
8571 mode = gtk_entry_get_display_mode (entry);
8572 append_action_signal (entry, entry->popup_menu, GTK_STOCK_CUT, "cut-clipboard",
8573 entry->editable && mode == DISPLAY_NORMAL &&
8574 entry->current_pos != entry->selection_bound);
8576 append_action_signal (entry, entry->popup_menu, GTK_STOCK_COPY, "copy-clipboard",
8577 mode == DISPLAY_NORMAL &&
8578 entry->current_pos != entry->selection_bound);
8580 append_action_signal (entry, entry->popup_menu, GTK_STOCK_PASTE, "paste-clipboard",
8581 entry->editable && clipboard_contains_text);
8583 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_DELETE, NULL);
8584 gtk_widget_set_sensitive (menuitem, entry->editable && entry->current_pos != entry->selection_bound);
8585 g_signal_connect_swapped (menuitem, "activate",
8586 G_CALLBACK (gtk_entry_delete_cb), entry);
8587 gtk_widget_show (menuitem);
8588 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8590 menuitem = gtk_separator_menu_item_new ();
8591 gtk_widget_show (menuitem);
8592 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8594 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_SELECT_ALL, NULL);
8595 g_signal_connect_swapped (menuitem, "activate",
8596 G_CALLBACK (gtk_entry_select_all), entry);
8597 gtk_widget_show (menuitem);
8598 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8600 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
8601 "gtk-show-input-method-menu", &show_input_method_menu,
8602 "gtk-show-unicode-menu", &show_unicode_menu,
8605 if (show_input_method_menu || show_unicode_menu)
8607 menuitem = gtk_separator_menu_item_new ();
8608 gtk_widget_show (menuitem);
8609 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8612 if (show_input_method_menu)
8614 menuitem = gtk_menu_item_new_with_mnemonic (_("Input _Methods"));
8615 gtk_widget_set_sensitive (menuitem, entry->editable);
8616 gtk_widget_show (menuitem);
8617 submenu = gtk_menu_new ();
8618 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
8620 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8622 gtk_im_multicontext_append_menuitems (GTK_IM_MULTICONTEXT (entry->im_context),
8623 GTK_MENU_SHELL (submenu));
8626 if (show_unicode_menu)
8628 menuitem = gtk_menu_item_new_with_mnemonic (_("_Insert Unicode Control Character"));
8629 gtk_widget_set_sensitive (menuitem, entry->editable);
8630 gtk_widget_show (menuitem);
8632 submenu = gtk_menu_new ();
8633 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
8634 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8636 _gtk_text_util_append_special_char_menuitems (GTK_MENU_SHELL (submenu),
8637 unichar_chosen_func,
8641 g_signal_emit (entry,
8642 signals[POPULATE_POPUP],
8648 gtk_menu_popup (GTK_MENU (entry->popup_menu), NULL, NULL,
8650 info->button, info->time);
8653 gtk_menu_popup (GTK_MENU (entry->popup_menu), NULL, NULL,
8654 popup_position_func, entry,
8655 info->button, info->time);
8656 gtk_menu_shell_select_first (GTK_MENU_SHELL (entry->popup_menu), FALSE);
8660 g_object_unref (entry);
8661 g_slice_free (PopupInfo, info);
8665 gtk_entry_do_popup (GtkEntry *entry,
8666 GdkEventButton *event)
8668 PopupInfo *info = g_slice_new (PopupInfo);
8670 /* In order to know what entries we should make sensitive, we
8671 * ask for the current targets of the clipboard, and when
8672 * we get them, then we actually pop up the menu.
8674 info->entry = g_object_ref (entry);
8678 info->button = event->button;
8679 info->time = event->time;
8684 info->time = gtk_get_current_event_time ();
8687 gtk_clipboard_request_contents (gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_CLIPBOARD),
8688 gdk_atom_intern_static_string ("TARGETS"),
8689 popup_targets_received,
8694 gtk_entry_popup_menu (GtkWidget *widget)
8696 gtk_entry_do_popup (GTK_ENTRY (widget), NULL);
8701 gtk_entry_drag_begin (GtkWidget *widget,
8702 GdkDragContext *context)
8704 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
8707 for (i = 0; i < MAX_ICONS; i++)
8709 EntryIconInfo *icon_info = priv->icons[i];
8711 if (icon_info != NULL)
8713 if (icon_info->in_drag)
8715 switch (icon_info->storage_type)
8717 case GTK_IMAGE_STOCK:
8718 gtk_drag_set_icon_stock (context, icon_info->stock_id, -2, -2);
8721 case GTK_IMAGE_ICON_NAME:
8722 gtk_drag_set_icon_name (context, icon_info->icon_name, -2, -2);
8725 /* FIXME: No GIcon support for dnd icons */
8726 case GTK_IMAGE_GICON:
8727 case GTK_IMAGE_PIXBUF:
8728 gtk_drag_set_icon_pixbuf (context, icon_info->pixbuf, -2, -2);
8731 g_assert_not_reached ();
8739 gtk_entry_drag_end (GtkWidget *widget,
8740 GdkDragContext *context)
8742 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
8745 for (i = 0; i < MAX_ICONS; i++)
8747 EntryIconInfo *icon_info = priv->icons[i];
8749 if (icon_info != NULL)
8750 icon_info->in_drag = 0;
8755 gtk_entry_drag_leave (GtkWidget *widget,
8756 GdkDragContext *context,
8759 GtkEntry *entry = GTK_ENTRY (widget);
8761 entry->dnd_position = -1;
8762 gtk_widget_queue_draw (widget);
8766 gtk_entry_drag_drop (GtkWidget *widget,
8767 GdkDragContext *context,
8772 GtkEntry *entry = GTK_ENTRY (widget);
8773 GdkAtom target = GDK_NONE;
8775 if (entry->editable)
8776 target = gtk_drag_dest_find_target (widget, context, NULL);
8778 if (target != GDK_NONE)
8779 gtk_drag_get_data (widget, context, target, time);
8781 gtk_drag_finish (context, FALSE, FALSE, time);
8787 gtk_entry_drag_motion (GtkWidget *widget,
8788 GdkDragContext *context,
8793 GtkEntry *entry = GTK_ENTRY (widget);
8795 GtkWidget *source_widget;
8796 GdkDragAction suggested_action;
8797 gint new_position, old_position;
8800 style = gtk_widget_get_style (widget);
8801 x -= style->xthickness;
8802 y -= style->ythickness;
8804 old_position = entry->dnd_position;
8805 new_position = gtk_entry_find_position (entry, x + entry->scroll_offset);
8807 if (entry->editable &&
8808 gtk_drag_dest_find_target (widget, context, NULL) != GDK_NONE)
8810 source_widget = gtk_drag_get_source_widget (context);
8811 suggested_action = context->suggested_action;
8813 if (!gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &sel1, &sel2) ||
8814 new_position < sel1 || new_position > sel2)
8816 if (source_widget == widget)
8818 /* Default to MOVE, unless the user has
8819 * pressed ctrl or alt to affect available actions
8821 if ((context->actions & GDK_ACTION_MOVE) != 0)
8822 suggested_action = GDK_ACTION_MOVE;
8825 entry->dnd_position = new_position;
8829 if (source_widget == widget)
8830 suggested_action = 0; /* Can't drop in selection where drag started */
8832 entry->dnd_position = -1;
8837 /* Entry not editable, or no text */
8838 suggested_action = 0;
8839 entry->dnd_position = -1;
8842 gdk_drag_status (context, suggested_action, time);
8844 if (entry->dnd_position != old_position)
8845 gtk_widget_queue_draw (widget);
8851 gtk_entry_drag_data_received (GtkWidget *widget,
8852 GdkDragContext *context,
8855 GtkSelectionData *selection_data,
8859 GtkEntry *entry = GTK_ENTRY (widget);
8860 GtkEditable *editable = GTK_EDITABLE (widget);
8864 str = (gchar *) gtk_selection_data_get_text (selection_data);
8866 style = gtk_widget_get_style (widget);
8867 x -= style->xthickness;
8868 y -= style->ythickness;
8870 if (str && entry->editable)
8876 if (entry->truncate_multiline)
8877 length = truncate_multiline (str);
8879 new_position = gtk_entry_find_position (entry, x + entry->scroll_offset);
8881 if (!gtk_editable_get_selection_bounds (editable, &sel1, &sel2) ||
8882 new_position < sel1 || new_position > sel2)
8884 gtk_editable_insert_text (editable, str, length, &new_position);
8888 /* Replacing selection */
8889 begin_change (entry);
8890 g_object_freeze_notify (G_OBJECT (entry));
8891 gtk_editable_delete_text (editable, sel1, sel2);
8892 gtk_editable_insert_text (editable, str, length, &sel1);
8893 g_object_thaw_notify (G_OBJECT (entry));
8897 gtk_drag_finish (context, TRUE, context->action == GDK_ACTION_MOVE, time);
8901 /* Drag and drop didn't happen! */
8902 gtk_drag_finish (context, FALSE, FALSE, time);
8909 gtk_entry_drag_data_get (GtkWidget *widget,
8910 GdkDragContext *context,
8911 GtkSelectionData *selection_data,
8915 gint sel_start, sel_end;
8918 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
8919 GtkEditable *editable = GTK_EDITABLE (widget);
8921 /* If there is an icon drag going on, exit early. */
8922 for (i = 0; i < MAX_ICONS; i++)
8924 EntryIconInfo *icon_info = priv->icons[i];
8926 if (icon_info != NULL)
8928 if (icon_info->in_drag)
8933 if (gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end))
8935 gchar *str = gtk_entry_get_display_text (GTK_ENTRY (widget), sel_start, sel_end);
8937 gtk_selection_data_set_text (selection_data, str, -1);
8945 gtk_entry_drag_data_delete (GtkWidget *widget,
8946 GdkDragContext *context)
8948 gint sel_start, sel_end;
8951 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
8952 GtkEditable *editable = GTK_EDITABLE (widget);
8954 /* If there is an icon drag going on, exit early. */
8955 for (i = 0; i < MAX_ICONS; i++)
8957 EntryIconInfo *icon_info = priv->icons[i];
8959 if (icon_info != NULL)
8961 if (icon_info->in_drag)
8966 if (GTK_ENTRY (widget)->editable &&
8967 gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end))
8968 gtk_editable_delete_text (editable, sel_start, sel_end);
8971 /* We display the cursor when
8973 * - the selection is empty, AND
8974 * - the widget has focus
8977 #define CURSOR_ON_MULTIPLIER 2
8978 #define CURSOR_OFF_MULTIPLIER 1
8979 #define CURSOR_PEND_MULTIPLIER 3
8980 #define CURSOR_DIVIDER 3
8983 cursor_blinks (GtkEntry *entry)
8985 if (gtk_widget_has_focus (GTK_WIDGET (entry)) &&
8987 entry->selection_bound == entry->current_pos)
8989 GtkSettings *settings;
8992 settings = gtk_widget_get_settings (GTK_WIDGET (entry));
8993 g_object_get (settings, "gtk-cursor-blink", &blink, NULL);
9002 get_cursor_time (GtkEntry *entry)
9004 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9007 g_object_get (settings, "gtk-cursor-blink-time", &time, NULL);
9013 get_cursor_blink_timeout (GtkEntry *entry)
9015 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9018 g_object_get (settings, "gtk-cursor-blink-timeout", &timeout, NULL);
9024 show_cursor (GtkEntry *entry)
9028 if (!entry->cursor_visible)
9030 entry->cursor_visible = TRUE;
9032 widget = GTK_WIDGET (entry);
9033 if (gtk_widget_has_focus (widget) && entry->selection_bound == entry->current_pos)
9034 gtk_widget_queue_draw (widget);
9039 hide_cursor (GtkEntry *entry)
9043 if (entry->cursor_visible)
9045 entry->cursor_visible = FALSE;
9047 widget = GTK_WIDGET (entry);
9048 if (gtk_widget_has_focus (widget) && entry->selection_bound == entry->current_pos)
9049 gtk_widget_queue_draw (widget);
9057 blink_cb (gpointer data)
9060 GtkEntryPrivate *priv;
9063 entry = GTK_ENTRY (data);
9064 priv = GTK_ENTRY_GET_PRIVATE (entry);
9066 if (!gtk_widget_has_focus (GTK_WIDGET (entry)))
9068 g_warning ("GtkEntry - did not receive focus-out-event. If you\n"
9069 "connect a handler to this signal, it must return\n"
9070 "FALSE so the entry gets the event as well");
9072 gtk_entry_check_cursor_blink (entry);
9077 g_assert (entry->selection_bound == entry->current_pos);
9079 blink_timeout = get_cursor_blink_timeout (entry);
9080 if (priv->blink_time > 1000 * blink_timeout &&
9081 blink_timeout < G_MAXINT/1000)
9083 /* we've blinked enough without the user doing anything, stop blinking */
9084 show_cursor (entry);
9085 entry->blink_timeout = 0;
9087 else if (entry->cursor_visible)
9089 hide_cursor (entry);
9090 entry->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_OFF_MULTIPLIER / CURSOR_DIVIDER,
9096 show_cursor (entry);
9097 priv->blink_time += get_cursor_time (entry);
9098 entry->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
9103 /* Remove ourselves */
9108 gtk_entry_check_cursor_blink (GtkEntry *entry)
9110 GtkEntryPrivate *priv;
9112 priv = GTK_ENTRY_GET_PRIVATE (entry);
9114 if (cursor_blinks (entry))
9116 if (!entry->blink_timeout)
9118 show_cursor (entry);
9119 entry->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
9126 if (entry->blink_timeout)
9128 g_source_remove (entry->blink_timeout);
9129 entry->blink_timeout = 0;
9132 entry->cursor_visible = TRUE;
9138 gtk_entry_pend_cursor_blink (GtkEntry *entry)
9140 if (cursor_blinks (entry))
9142 if (entry->blink_timeout != 0)
9143 g_source_remove (entry->blink_timeout);
9145 entry->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_PEND_MULTIPLIER / CURSOR_DIVIDER,
9148 show_cursor (entry);
9153 gtk_entry_reset_blink_time (GtkEntry *entry)
9155 GtkEntryPrivate *priv;
9157 priv = GTK_ENTRY_GET_PRIVATE (entry);
9159 priv->blink_time = 0;
9165 gtk_entry_completion_timeout (gpointer data)
9167 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (data);
9168 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (completion->priv->entry);
9170 completion->priv->completion_timeout = 0;
9172 if (completion->priv->filter_model &&
9173 g_utf8_strlen (gtk_entry_get_text (GTK_ENTRY (completion->priv->entry)), -1)
9174 >= completion->priv->minimum_key_length)
9178 GtkTreeSelection *s;
9179 gboolean popup_single;
9181 gtk_entry_completion_complete (completion);
9182 matches = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->filter_model), NULL);
9184 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9186 s = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view));
9188 gtk_tree_selection_unselect_all (s);
9190 actions = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->actions), NULL);
9192 g_object_get (completion, "popup-single-match", &popup_single, NULL);
9193 if ((matches > (popup_single ? 0: 1)) || actions > 0)
9195 if (gtk_widget_get_visible (completion->priv->popup_window))
9196 _gtk_entry_completion_resize_popup (completion);
9198 _gtk_entry_completion_popup (completion, priv->completion_device);
9201 _gtk_entry_completion_popdown (completion);
9203 else if (gtk_widget_get_visible (completion->priv->popup_window))
9204 _gtk_entry_completion_popdown (completion);
9209 static inline gboolean
9210 keyval_is_cursor_move (guint keyval)
9212 if (keyval == GDK_KEY_Up || keyval == GDK_KEY_KP_Up)
9215 if (keyval == GDK_KEY_Down || keyval == GDK_KEY_KP_Down)
9218 if (keyval == GDK_KEY_Page_Up)
9221 if (keyval == GDK_KEY_Page_Down)
9228 gtk_entry_completion_key_press (GtkWidget *widget,
9232 gint matches, actions = 0;
9233 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
9235 if (!gtk_widget_get_mapped (completion->priv->popup_window))
9238 matches = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->filter_model), NULL);
9240 if (completion->priv->actions)
9241 actions = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->actions), NULL);
9243 if (keyval_is_cursor_move (event->keyval))
9245 GtkTreePath *path = NULL;
9247 if (event->keyval == GDK_KEY_Up || event->keyval == GDK_KEY_KP_Up)
9249 if (completion->priv->current_selected < 0)
9250 completion->priv->current_selected = matches + actions - 1;
9252 completion->priv->current_selected--;
9254 else if (event->keyval == GDK_KEY_Down || event->keyval == GDK_KEY_KP_Down)
9256 if (completion->priv->current_selected < matches + actions - 1)
9257 completion->priv->current_selected++;
9259 completion->priv->current_selected = -1;
9261 else if (event->keyval == GDK_KEY_Page_Up)
9263 if (completion->priv->current_selected < 0)
9264 completion->priv->current_selected = matches + actions - 1;
9265 else if (completion->priv->current_selected == 0)
9266 completion->priv->current_selected = -1;
9267 else if (completion->priv->current_selected < matches)
9269 completion->priv->current_selected -= 14;
9270 if (completion->priv->current_selected < 0)
9271 completion->priv->current_selected = 0;
9275 completion->priv->current_selected -= 14;
9276 if (completion->priv->current_selected < matches - 1)
9277 completion->priv->current_selected = matches - 1;
9280 else if (event->keyval == GDK_KEY_Page_Down)
9282 if (completion->priv->current_selected < 0)
9283 completion->priv->current_selected = 0;
9284 else if (completion->priv->current_selected < matches - 1)
9286 completion->priv->current_selected += 14;
9287 if (completion->priv->current_selected > matches - 1)
9288 completion->priv->current_selected = matches - 1;
9290 else if (completion->priv->current_selected == matches + actions - 1)
9292 completion->priv->current_selected = -1;
9296 completion->priv->current_selected += 14;
9297 if (completion->priv->current_selected > matches + actions - 1)
9298 completion->priv->current_selected = matches + actions - 1;
9302 if (completion->priv->current_selected < 0)
9304 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9305 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view)));
9307 if (completion->priv->inline_selection &&
9308 completion->priv->completion_prefix)
9310 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9311 completion->priv->completion_prefix);
9312 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9315 else if (completion->priv->current_selected < matches)
9317 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view)));
9319 path = gtk_tree_path_new_from_indices (completion->priv->current_selected, -1);
9320 gtk_tree_view_set_cursor (GTK_TREE_VIEW (completion->priv->tree_view),
9323 if (completion->priv->inline_selection)
9327 GtkTreeIter child_iter;
9328 GtkTreeModel *model = NULL;
9329 GtkTreeSelection *sel;
9332 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view));
9333 if (!gtk_tree_selection_get_selected (sel, &model, &iter))
9336 gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (model), &child_iter, &iter);
9337 model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model));
9339 if (completion->priv->completion_prefix == NULL)
9340 completion->priv->completion_prefix = g_strdup (gtk_entry_get_text (GTK_ENTRY (completion->priv->entry)));
9342 g_signal_emit_by_name (completion, "cursor-on-match", model,
9343 &child_iter, &entry_set);
9346 else if (completion->priv->current_selected - matches >= 0)
9348 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9350 path = gtk_tree_path_new_from_indices (completion->priv->current_selected - matches, -1);
9351 gtk_tree_view_set_cursor (GTK_TREE_VIEW (completion->priv->action_view),
9354 if (completion->priv->inline_selection &&
9355 completion->priv->completion_prefix)
9357 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9358 completion->priv->completion_prefix);
9359 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9363 gtk_tree_path_free (path);
9367 else if (event->keyval == GDK_KEY_Escape ||
9368 event->keyval == GDK_KEY_Left ||
9369 event->keyval == GDK_KEY_KP_Left ||
9370 event->keyval == GDK_KEY_Right ||
9371 event->keyval == GDK_KEY_KP_Right)
9373 gboolean retval = TRUE;
9375 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9376 _gtk_entry_completion_popdown (completion);
9378 if (completion->priv->current_selected < 0)
9381 goto keypress_completion_out;
9383 else if (completion->priv->inline_selection)
9385 /* Escape rejects the tentative completion */
9386 if (event->keyval == GDK_KEY_Escape)
9388 if (completion->priv->completion_prefix)
9389 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9390 completion->priv->completion_prefix);
9392 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry), "");
9395 /* Move the cursor to the end for Right/Esc, to the
9396 beginning for Left */
9397 if (event->keyval == GDK_KEY_Right ||
9398 event->keyval == GDK_KEY_KP_Right ||
9399 event->keyval == GDK_KEY_Escape)
9400 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9402 gtk_editable_set_position (GTK_EDITABLE (widget), 0);
9405 keypress_completion_out:
9406 if (completion->priv->inline_selection)
9408 g_free (completion->priv->completion_prefix);
9409 completion->priv->completion_prefix = NULL;
9414 else if (event->keyval == GDK_KEY_Tab ||
9415 event->keyval == GDK_KEY_KP_Tab ||
9416 event->keyval == GDK_KEY_ISO_Left_Tab)
9418 GtkDirectionType dir = event->keyval == GDK_KEY_ISO_Left_Tab ?
9419 GTK_DIR_TAB_BACKWARD : GTK_DIR_TAB_FORWARD;
9421 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9422 _gtk_entry_completion_popdown (completion);
9424 g_free (completion->priv->completion_prefix);
9425 completion->priv->completion_prefix = NULL;
9427 gtk_widget_child_focus (gtk_widget_get_toplevel (widget), dir);
9431 else if (event->keyval == GDK_KEY_ISO_Enter ||
9432 event->keyval == GDK_KEY_KP_Enter ||
9433 event->keyval == GDK_KEY_Return)
9436 GtkTreeModel *model = NULL;
9437 GtkTreeSelection *sel;
9438 gboolean retval = TRUE;
9440 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9441 _gtk_entry_completion_popdown (completion);
9443 if (completion->priv->current_selected < matches)
9447 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view));
9448 if (gtk_tree_selection_get_selected (sel, &model, &iter))
9450 g_signal_handler_block (widget, completion->priv->changed_id);
9451 g_signal_emit_by_name (completion, "match-selected",
9452 model, &iter, &entry_set);
9453 g_signal_handler_unblock (widget, completion->priv->changed_id);
9459 gtk_tree_model_get (model, &iter,
9460 completion->priv->text_column, &str,
9463 gtk_entry_set_text (GTK_ENTRY (widget), str);
9465 /* move the cursor to the end */
9466 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9474 else if (completion->priv->current_selected - matches >= 0)
9476 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view));
9477 if (gtk_tree_selection_get_selected (sel, &model, &iter))
9481 path = gtk_tree_path_new_from_indices (completion->priv->current_selected - matches, -1);
9482 g_signal_emit_by_name (completion, "action-activated",
9483 gtk_tree_path_get_indices (path)[0]);
9484 gtk_tree_path_free (path);
9490 g_free (completion->priv->completion_prefix);
9491 completion->priv->completion_prefix = NULL;
9500 gtk_entry_completion_changed (GtkWidget *entry,
9503 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
9504 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
9507 /* (re)install completion timeout */
9508 if (completion->priv->completion_timeout)
9509 g_source_remove (completion->priv->completion_timeout);
9511 if (!gtk_entry_get_text (GTK_ENTRY (entry)))
9514 /* no need to normalize for this test */
9515 if (completion->priv->minimum_key_length > 0 &&
9516 strcmp ("", gtk_entry_get_text (GTK_ENTRY (entry))) == 0)
9518 if (gtk_widget_get_visible (completion->priv->popup_window))
9519 _gtk_entry_completion_popdown (completion);
9523 device = gtk_get_current_event_device ();
9525 if (device && device->source == GDK_SOURCE_KEYBOARD)
9526 device = gdk_device_get_associated_device (device);
9529 priv->completion_device = device;
9531 completion->priv->completion_timeout =
9532 gdk_threads_add_timeout (COMPLETION_TIMEOUT,
9533 gtk_entry_completion_timeout,
9538 check_completion_callback (GtkEntryCompletion *completion)
9540 completion->priv->check_completion_idle = NULL;
9542 gtk_entry_completion_complete (completion);
9543 gtk_entry_completion_insert_prefix (completion);
9549 clear_completion_callback (GtkEntry *entry,
9552 if (pspec->name == I_("cursor-position") ||
9553 pspec->name == I_("selection-bound"))
9555 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
9557 completion->priv->has_completion = FALSE;
9562 accept_completion_callback (GtkEntry *entry)
9564 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
9566 if (completion->priv->has_completion)
9567 gtk_editable_set_position (GTK_EDITABLE (entry),
9568 gtk_entry_buffer_get_length (get_buffer (entry)));
9574 completion_insert_text_callback (GtkEntry *entry,
9578 GtkEntryCompletion *completion)
9580 /* idle to update the selection based on the file list */
9581 if (completion->priv->check_completion_idle == NULL)
9583 completion->priv->check_completion_idle = g_idle_source_new ();
9584 g_source_set_priority (completion->priv->check_completion_idle, G_PRIORITY_HIGH);
9585 g_source_set_closure (completion->priv->check_completion_idle,
9586 g_cclosure_new_object (G_CALLBACK (check_completion_callback),
9587 G_OBJECT (completion)));
9588 g_source_attach (completion->priv->check_completion_idle, NULL);
9593 completion_changed (GtkEntryCompletion *completion,
9597 GtkEntry *entry = GTK_ENTRY (data);
9599 if (pspec->name == I_("popup-completion") ||
9600 pspec->name == I_("inline-completion"))
9602 disconnect_completion_signals (entry, completion);
9603 connect_completion_signals (entry, completion);
9608 disconnect_completion_signals (GtkEntry *entry,
9609 GtkEntryCompletion *completion)
9611 g_signal_handlers_disconnect_by_func (completion,
9612 G_CALLBACK (completion_changed), entry);
9613 if (completion->priv->changed_id > 0 &&
9614 g_signal_handler_is_connected (entry, completion->priv->changed_id))
9616 g_signal_handler_disconnect (entry, completion->priv->changed_id);
9617 completion->priv->changed_id = 0;
9619 g_signal_handlers_disconnect_by_func (entry,
9620 G_CALLBACK (gtk_entry_completion_key_press), completion);
9621 if (completion->priv->insert_text_id > 0 &&
9622 g_signal_handler_is_connected (entry, completion->priv->insert_text_id))
9624 g_signal_handler_disconnect (entry, completion->priv->insert_text_id);
9625 completion->priv->insert_text_id = 0;
9627 g_signal_handlers_disconnect_by_func (entry,
9628 G_CALLBACK (completion_insert_text_callback), completion);
9629 g_signal_handlers_disconnect_by_func (entry,
9630 G_CALLBACK (clear_completion_callback), completion);
9631 g_signal_handlers_disconnect_by_func (entry,
9632 G_CALLBACK (accept_completion_callback), completion);
9636 connect_completion_signals (GtkEntry *entry,
9637 GtkEntryCompletion *completion)
9639 if (completion->priv->popup_completion)
9641 completion->priv->changed_id =
9642 g_signal_connect (entry, "changed",
9643 G_CALLBACK (gtk_entry_completion_changed), completion);
9644 g_signal_connect (entry, "key-press-event",
9645 G_CALLBACK (gtk_entry_completion_key_press), completion);
9648 if (completion->priv->inline_completion)
9650 completion->priv->insert_text_id =
9651 g_signal_connect (entry, "insert-text",
9652 G_CALLBACK (completion_insert_text_callback), completion);
9653 g_signal_connect (entry, "notify",
9654 G_CALLBACK (clear_completion_callback), completion);
9655 g_signal_connect (entry, "activate",
9656 G_CALLBACK (accept_completion_callback), completion);
9657 g_signal_connect (entry, "focus-out-event",
9658 G_CALLBACK (accept_completion_callback), completion);
9661 g_signal_connect (completion, "notify",
9662 G_CALLBACK (completion_changed), entry);
9666 * gtk_entry_set_completion:
9667 * @entry: A #GtkEntry
9668 * @completion: (allow-none): The #GtkEntryCompletion or %NULL
9670 * Sets @completion to be the auxiliary completion object to use with @entry.
9671 * All further configuration of the completion mechanism is done on
9672 * @completion using the #GtkEntryCompletion API. Completion is disabled if
9673 * @completion is set to %NULL.
9678 gtk_entry_set_completion (GtkEntry *entry,
9679 GtkEntryCompletion *completion)
9681 GtkEntryCompletion *old;
9683 g_return_if_fail (GTK_IS_ENTRY (entry));
9684 g_return_if_fail (!completion || GTK_IS_ENTRY_COMPLETION (completion));
9686 old = gtk_entry_get_completion (entry);
9688 if (old == completion)
9693 if (old->priv->completion_timeout)
9695 g_source_remove (old->priv->completion_timeout);
9696 old->priv->completion_timeout = 0;
9699 if (gtk_widget_get_mapped (old->priv->popup_window))
9700 _gtk_entry_completion_popdown (old);
9702 disconnect_completion_signals (entry, old);
9703 old->priv->entry = NULL;
9705 g_object_unref (old);
9710 g_object_set_data (G_OBJECT (entry), I_(GTK_ENTRY_COMPLETION_KEY), NULL);
9714 /* hook into the entry */
9715 g_object_ref (completion);
9717 connect_completion_signals (entry, completion);
9718 completion->priv->entry = GTK_WIDGET (entry);
9719 g_object_set_data (G_OBJECT (entry), I_(GTK_ENTRY_COMPLETION_KEY), completion);
9723 * gtk_entry_get_completion:
9724 * @entry: A #GtkEntry
9726 * Returns the auxiliary completion object currently in use by @entry.
9728 * Return value: (transfer none): The auxiliary completion object currently
9733 GtkEntryCompletion *
9734 gtk_entry_get_completion (GtkEntry *entry)
9736 GtkEntryCompletion *completion;
9738 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
9740 completion = GTK_ENTRY_COMPLETION (g_object_get_data (G_OBJECT (entry),
9741 GTK_ENTRY_COMPLETION_KEY));
9747 * gtk_entry_set_cursor_hadjustment:
9748 * @entry: a #GtkEntry
9749 * @adjustment: an adjustment which should be adjusted when the cursor
9750 * is moved, or %NULL
9752 * Hooks up an adjustment to the cursor position in an entry, so that when
9753 * the cursor is moved, the adjustment is scrolled to show that position.
9754 * See gtk_scrolled_window_get_hadjustment() for a typical way of obtaining
9757 * The adjustment has to be in pixel units and in the same coordinate system
9763 gtk_entry_set_cursor_hadjustment (GtkEntry *entry,
9764 GtkAdjustment *adjustment)
9766 g_return_if_fail (GTK_IS_ENTRY (entry));
9768 g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
9771 g_object_ref (adjustment);
9773 g_object_set_qdata_full (G_OBJECT (entry),
9774 quark_cursor_hadjustment,
9780 * gtk_entry_get_cursor_hadjustment:
9781 * @entry: a #GtkEntry
9783 * Retrieves the horizontal cursor adjustment for the entry.
9784 * See gtk_entry_set_cursor_hadjustment().
9786 * Return value: (transfer none): the horizontal cursor adjustment, or %NULL
9787 * if none has been set.
9792 gtk_entry_get_cursor_hadjustment (GtkEntry *entry)
9794 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
9796 return g_object_get_qdata (G_OBJECT (entry), quark_cursor_hadjustment);
9800 * gtk_entry_set_progress_fraction:
9801 * @entry: a #GtkEntry
9802 * @fraction: fraction of the task that's been completed
9804 * Causes the entry's progress indicator to "fill in" the given
9805 * fraction of the bar. The fraction should be between 0.0 and 1.0,
9811 gtk_entry_set_progress_fraction (GtkEntry *entry,
9815 GtkEntryPrivate *private;
9816 gdouble old_fraction;
9817 gint x, y, width, height;
9818 gint old_x, old_y, old_width, old_height;
9820 g_return_if_fail (GTK_IS_ENTRY (entry));
9822 widget = GTK_WIDGET (entry);
9823 private = GTK_ENTRY_GET_PRIVATE (entry);
9825 if (private->progress_pulse_mode)
9828 old_fraction = private->progress_fraction;
9830 if (gtk_widget_is_drawable (widget))
9831 get_progress_area (widget, &old_x, &old_y, &old_width, &old_height);
9833 fraction = CLAMP (fraction, 0.0, 1.0);
9835 private->progress_fraction = fraction;
9836 private->progress_pulse_mode = FALSE;
9837 private->progress_pulse_current = 0.0;
9839 if (gtk_widget_is_drawable (widget))
9841 get_progress_area (widget, &x, &y, &width, &height);
9843 if ((x != old_x) || (y != old_y) || (width != old_width) || (height != old_height))
9844 gtk_widget_queue_draw (widget);
9847 if (fraction != old_fraction)
9848 g_object_notify (G_OBJECT (entry), "progress-fraction");
9852 * gtk_entry_get_progress_fraction:
9853 * @entry: a #GtkEntry
9855 * Returns the current fraction of the task that's been completed.
9856 * See gtk_entry_set_progress_fraction().
9858 * Return value: a fraction from 0.0 to 1.0
9863 gtk_entry_get_progress_fraction (GtkEntry *entry)
9865 GtkEntryPrivate *private;
9867 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
9869 private = GTK_ENTRY_GET_PRIVATE (entry);
9871 return private->progress_fraction;
9875 * gtk_entry_set_progress_pulse_step:
9876 * @entry: a #GtkEntry
9877 * @fraction: fraction between 0.0 and 1.0
9879 * Sets the fraction of total entry width to move the progress
9880 * bouncing block for each call to gtk_entry_progress_pulse().
9885 gtk_entry_set_progress_pulse_step (GtkEntry *entry,
9888 GtkEntryPrivate *private;
9890 g_return_if_fail (GTK_IS_ENTRY (entry));
9892 private = GTK_ENTRY_GET_PRIVATE (entry);
9894 fraction = CLAMP (fraction, 0.0, 1.0);
9896 if (fraction != private->progress_pulse_fraction)
9898 private->progress_pulse_fraction = fraction;
9900 gtk_widget_queue_draw (GTK_WIDGET (entry));
9902 g_object_notify (G_OBJECT (entry), "progress-pulse-step");
9907 * gtk_entry_get_progress_pulse_step:
9908 * @entry: a #GtkEntry
9910 * Retrieves the pulse step set with gtk_entry_set_progress_pulse_step().
9912 * Return value: a fraction from 0.0 to 1.0
9917 gtk_entry_get_progress_pulse_step (GtkEntry *entry)
9919 GtkEntryPrivate *private;
9921 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
9923 private = GTK_ENTRY_GET_PRIVATE (entry);
9925 return private->progress_pulse_fraction;
9929 * gtk_entry_progress_pulse:
9930 * @entry: a #GtkEntry
9932 * Indicates that some progress is made, but you don't know how much.
9933 * Causes the entry's progress indicator to enter "activity mode,"
9934 * where a block bounces back and forth. Each call to
9935 * gtk_entry_progress_pulse() causes the block to move by a little bit
9936 * (the amount of movement per pulse is determined by
9937 * gtk_entry_set_progress_pulse_step()).
9942 gtk_entry_progress_pulse (GtkEntry *entry)
9944 GtkEntryPrivate *private;
9946 g_return_if_fail (GTK_IS_ENTRY (entry));
9948 private = GTK_ENTRY_GET_PRIVATE (entry);
9950 if (private->progress_pulse_mode)
9952 if (private->progress_pulse_way_back)
9954 private->progress_pulse_current -= private->progress_pulse_fraction;
9956 if (private->progress_pulse_current < 0.0)
9958 private->progress_pulse_current = 0.0;
9959 private->progress_pulse_way_back = FALSE;
9964 private->progress_pulse_current += private->progress_pulse_fraction;
9966 if (private->progress_pulse_current > 1.0 - private->progress_pulse_fraction)
9968 private->progress_pulse_current = 1.0 - private->progress_pulse_fraction;
9969 private->progress_pulse_way_back = TRUE;
9975 private->progress_fraction = 0.0;
9976 private->progress_pulse_mode = TRUE;
9977 private->progress_pulse_way_back = FALSE;
9978 private->progress_pulse_current = 0.0;
9981 gtk_widget_queue_draw (GTK_WIDGET (entry));
9984 /* Caps Lock warning for password entries */
9987 show_capslock_feedback (GtkEntry *entry,
9990 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
9992 if (gtk_entry_get_icon_storage_type (entry, GTK_ENTRY_ICON_SECONDARY) == GTK_IMAGE_EMPTY)
9994 gtk_entry_set_icon_from_stock (entry, GTK_ENTRY_ICON_SECONDARY, GTK_STOCK_CAPS_LOCK_WARNING);
9995 gtk_entry_set_icon_activatable (entry, GTK_ENTRY_ICON_SECONDARY, FALSE);
9996 priv->caps_lock_warning_shown = TRUE;
9999 if (priv->caps_lock_warning_shown)
10000 gtk_entry_set_icon_tooltip_text (entry, GTK_ENTRY_ICON_SECONDARY, text);
10002 g_warning ("Can't show Caps Lock warning, since secondary icon is set");
10006 remove_capslock_feedback (GtkEntry *entry)
10008 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
10010 if (priv->caps_lock_warning_shown)
10012 gtk_entry_set_icon_from_stock (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
10013 priv->caps_lock_warning_shown = FALSE;
10018 keymap_state_changed (GdkKeymap *keymap,
10021 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
10024 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL && priv->caps_lock_warning)
10026 if (gdk_keymap_get_num_lock_state (keymap)
10027 && gdk_keymap_get_caps_lock_state (keymap))
10028 text = _("Caps Lock and Num Lock are on");
10029 else if (gdk_keymap_get_num_lock_state (keymap))
10030 text = _("Num Lock is on");
10031 else if (gdk_keymap_get_caps_lock_state (keymap))
10032 text = _("Caps Lock is on");
10036 show_capslock_feedback (entry, text);
10038 remove_capslock_feedback (entry);