1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* GTK - The GIMP Toolkit
3 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * Copyright (C) 2004-2006 Christian Hammond
5 * Copyright (C) 2008 Cody Russell
6 * Copyright (C) 2008 Red Hat, Inc.
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
25 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
26 * file for a list of people on the GTK+ Team. See the ChangeLog
27 * files for a list of changes. These files are distributed with
28 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
36 #include "gdk/gdkkeysyms.h"
37 #include "gtkalignment.h"
38 #include "gtkbindings.h"
39 #include "gtkcelleditable.h"
40 #include "gtkclipboard.h"
43 #include "gtkentrybuffer.h"
44 #include "gtkimagemenuitem.h"
45 #include "gtkimcontextsimple.h"
46 #include "gtkimmulticontext.h"
50 #include "gtkmarshalers.h"
52 #include "gtkmenuitem.h"
53 #include "gtkseparatormenuitem.h"
54 #include "gtkselection.h"
55 #include "gtksettings.h"
56 #include "gtkspinbutton.h"
58 #include "gtktextutil.h"
59 #include "gtkwindow.h"
60 #include "gtktreeview.h"
61 #include "gtktreeselection.h"
62 #include "gtkprivate.h"
63 #include "gtkentryprivate.h"
64 #include "gtkcelllayout.h"
65 #include "gtktooltip.h"
66 #include "gtkiconfactory.h"
67 #include "gtkicontheme.h"
69 #define GTK_ENTRY_COMPLETION_KEY "gtk-entry-completion-key"
71 #define MIN_ENTRY_WIDTH 150
72 #define DRAW_TIMEOUT 20
73 #define COMPLETION_TIMEOUT 300
74 #define PASSWORD_HINT_MAX 8
78 #define IS_VALID_ICON_POSITION(pos) \
79 ((pos) == GTK_ENTRY_ICON_PRIMARY || \
80 (pos) == GTK_ENTRY_ICON_SECONDARY)
82 static const GtkBorder default_inner_border = { 2, 2, 2, 2 };
83 static GQuark quark_inner_border = 0;
84 static GQuark quark_password_hint = 0;
85 static GQuark quark_cursor_hadjustment = 0;
86 static GQuark quark_capslock_feedback = 0;
88 typedef struct _GtkEntryPrivate GtkEntryPrivate;
90 #define GTK_ENTRY_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_ENTRY, GtkEntryPrivate))
96 guint insensitive : 1;
97 guint nonactivatable : 1;
102 GtkImageType storage_type;
108 GtkTargetList *target_list;
109 GdkDragAction actions;
112 struct _GtkEntryPrivate
114 GtkEntryBuffer* buffer;
118 guint blink_time; /* time in msec the cursor has blinked since last user event */
119 guint interior_focus : 1;
120 guint real_changed : 1;
121 guint invisible_char_set : 1;
122 guint caps_lock_warning : 1;
123 guint caps_lock_warning_shown : 1;
124 guint change_count : 8;
125 guint progress_pulse_mode : 1;
126 guint progress_pulse_way_back : 1;
129 GtkShadowType shadow_type;
131 gdouble progress_fraction;
132 gdouble progress_pulse_fraction;
133 gdouble progress_pulse_current;
135 EntryIconInfo *icons[MAX_ICONS];
142 GdkDevice *completion_device;
145 typedef struct _GtkEntryPasswordHint GtkEntryPasswordHint;
147 struct _GtkEntryPasswordHint
149 gint position; /* Position (in text) of the last password hint */
150 guint source_id; /* Timeout source id */
153 typedef struct _GtkEntryCapslockFeedback GtkEntryCapslockFeedback;
155 struct _GtkEntryCapslockFeedback
182 PROP_CURSOR_POSITION,
183 PROP_SELECTION_BOUND,
190 PROP_ACTIVATES_DEFAULT,
195 PROP_TRUNCATE_MULTILINE,
199 PROP_INVISIBLE_CHAR_SET,
200 PROP_CAPS_LOCK_WARNING,
201 PROP_PROGRESS_FRACTION,
202 PROP_PROGRESS_PULSE_STEP,
204 PROP_PIXBUF_SECONDARY,
206 PROP_STOCK_SECONDARY,
207 PROP_ICON_NAME_PRIMARY,
208 PROP_ICON_NAME_SECONDARY,
210 PROP_GICON_SECONDARY,
211 PROP_STORAGE_TYPE_PRIMARY,
212 PROP_STORAGE_TYPE_SECONDARY,
213 PROP_ACTIVATABLE_PRIMARY,
214 PROP_ACTIVATABLE_SECONDARY,
215 PROP_SENSITIVE_PRIMARY,
216 PROP_SENSITIVE_SECONDARY,
217 PROP_TOOLTIP_TEXT_PRIMARY,
218 PROP_TOOLTIP_TEXT_SECONDARY,
219 PROP_TOOLTIP_MARKUP_PRIMARY,
220 PROP_TOOLTIP_MARKUP_SECONDARY,
222 PROP_EDITING_CANCELED
225 static guint signals[LAST_SIGNAL] = { 0 };
234 DISPLAY_NORMAL, /* The entry text is being shown */
235 DISPLAY_INVISIBLE, /* In invisible mode, text replaced by (eg) bullets */
236 DISPLAY_BLANK /* In invisible mode, nothing shown at all */
241 static void gtk_entry_editable_init (GtkEditableInterface *iface);
242 static void gtk_entry_cell_editable_init (GtkCellEditableIface *iface);
243 static void gtk_entry_set_property (GObject *object,
247 static void gtk_entry_get_property (GObject *object,
251 static void gtk_entry_finalize (GObject *object);
252 static void gtk_entry_dispose (GObject *object);
256 static void gtk_entry_destroy (GtkWidget *widget);
257 static void gtk_entry_realize (GtkWidget *widget);
258 static void gtk_entry_unrealize (GtkWidget *widget);
259 static void gtk_entry_map (GtkWidget *widget);
260 static void gtk_entry_unmap (GtkWidget *widget);
261 static void gtk_entry_get_preferred_width (GtkWidget *widget,
264 static void gtk_entry_get_preferred_height (GtkWidget *widget,
267 static void gtk_entry_size_allocate (GtkWidget *widget,
268 GtkAllocation *allocation);
269 static void gtk_entry_draw_frame (GtkWidget *widget,
271 static void gtk_entry_draw_progress (GtkWidget *widget,
273 static gint gtk_entry_draw (GtkWidget *widget,
275 static gint gtk_entry_button_press (GtkWidget *widget,
276 GdkEventButton *event);
277 static gint gtk_entry_button_release (GtkWidget *widget,
278 GdkEventButton *event);
279 static gint gtk_entry_enter_notify (GtkWidget *widget,
280 GdkEventCrossing *event);
281 static gint gtk_entry_leave_notify (GtkWidget *widget,
282 GdkEventCrossing *event);
283 static gint gtk_entry_motion_notify (GtkWidget *widget,
284 GdkEventMotion *event);
285 static gint gtk_entry_key_press (GtkWidget *widget,
287 static gint gtk_entry_key_release (GtkWidget *widget,
289 static gint gtk_entry_focus_in (GtkWidget *widget,
290 GdkEventFocus *event);
291 static gint gtk_entry_focus_out (GtkWidget *widget,
292 GdkEventFocus *event);
293 static void gtk_entry_grab_focus (GtkWidget *widget);
294 static void gtk_entry_style_set (GtkWidget *widget,
295 GtkStyle *previous_style);
296 static gboolean gtk_entry_query_tooltip (GtkWidget *widget,
299 gboolean keyboard_tip,
300 GtkTooltip *tooltip);
301 static void gtk_entry_direction_changed (GtkWidget *widget,
302 GtkTextDirection previous_dir);
303 static void gtk_entry_state_changed (GtkWidget *widget,
304 GtkStateType previous_state);
305 static void gtk_entry_screen_changed (GtkWidget *widget,
306 GdkScreen *old_screen);
308 static gboolean gtk_entry_drag_drop (GtkWidget *widget,
309 GdkDragContext *context,
313 static gboolean gtk_entry_drag_motion (GtkWidget *widget,
314 GdkDragContext *context,
318 static void gtk_entry_drag_leave (GtkWidget *widget,
319 GdkDragContext *context,
321 static void gtk_entry_drag_data_received (GtkWidget *widget,
322 GdkDragContext *context,
325 GtkSelectionData *selection_data,
328 static void gtk_entry_drag_data_get (GtkWidget *widget,
329 GdkDragContext *context,
330 GtkSelectionData *selection_data,
333 static void gtk_entry_drag_data_delete (GtkWidget *widget,
334 GdkDragContext *context);
335 static void gtk_entry_drag_begin (GtkWidget *widget,
336 GdkDragContext *context);
337 static void gtk_entry_drag_end (GtkWidget *widget,
338 GdkDragContext *context);
341 /* GtkEditable method implementations
343 static void gtk_entry_insert_text (GtkEditable *editable,
344 const gchar *new_text,
345 gint new_text_length,
347 static void gtk_entry_delete_text (GtkEditable *editable,
350 static gchar * gtk_entry_get_chars (GtkEditable *editable,
353 static void gtk_entry_real_set_position (GtkEditable *editable,
355 static gint gtk_entry_get_position (GtkEditable *editable);
356 static void gtk_entry_set_selection_bounds (GtkEditable *editable,
359 static gboolean gtk_entry_get_selection_bounds (GtkEditable *editable,
363 /* GtkCellEditable method implementations
365 static void gtk_entry_start_editing (GtkCellEditable *cell_editable,
368 /* Default signal handlers
370 static void gtk_entry_real_insert_text (GtkEditable *editable,
371 const gchar *new_text,
372 gint new_text_length,
374 static void gtk_entry_real_delete_text (GtkEditable *editable,
377 static void gtk_entry_move_cursor (GtkEntry *entry,
378 GtkMovementStep step,
380 gboolean extend_selection);
381 static void gtk_entry_insert_at_cursor (GtkEntry *entry,
383 static void gtk_entry_delete_from_cursor (GtkEntry *entry,
386 static void gtk_entry_backspace (GtkEntry *entry);
387 static void gtk_entry_cut_clipboard (GtkEntry *entry);
388 static void gtk_entry_copy_clipboard (GtkEntry *entry);
389 static void gtk_entry_paste_clipboard (GtkEntry *entry);
390 static void gtk_entry_toggle_overwrite (GtkEntry *entry);
391 static void gtk_entry_select_all (GtkEntry *entry);
392 static void gtk_entry_real_activate (GtkEntry *entry);
393 static gboolean gtk_entry_popup_menu (GtkWidget *widget);
395 static void keymap_direction_changed (GdkKeymap *keymap,
397 static void keymap_state_changed (GdkKeymap *keymap,
399 static void remove_capslock_feedback (GtkEntry *entry);
401 /* IM Context Callbacks
403 static void gtk_entry_commit_cb (GtkIMContext *context,
406 static void gtk_entry_preedit_changed_cb (GtkIMContext *context,
408 static gboolean gtk_entry_retrieve_surrounding_cb (GtkIMContext *context,
410 static gboolean gtk_entry_delete_surrounding_cb (GtkIMContext *context,
417 static void gtk_entry_enter_text (GtkEntry *entry,
419 static void gtk_entry_set_positions (GtkEntry *entry,
421 gint selection_bound);
422 static void gtk_entry_draw_text (GtkEntry *entry,
424 static void gtk_entry_draw_cursor (GtkEntry *entry,
427 static PangoLayout *gtk_entry_ensure_layout (GtkEntry *entry,
428 gboolean include_preedit);
429 static void gtk_entry_reset_layout (GtkEntry *entry);
430 static void gtk_entry_queue_draw (GtkEntry *entry);
431 static void gtk_entry_recompute (GtkEntry *entry);
432 static gint gtk_entry_find_position (GtkEntry *entry,
434 static void gtk_entry_get_cursor_locations (GtkEntry *entry,
438 static void gtk_entry_adjust_scroll (GtkEntry *entry);
439 static gint gtk_entry_move_visually (GtkEntry *editable,
442 static gint gtk_entry_move_logically (GtkEntry *entry,
445 static gint gtk_entry_move_forward_word (GtkEntry *entry,
447 gboolean allow_whitespace);
448 static gint gtk_entry_move_backward_word (GtkEntry *entry,
450 gboolean allow_whitespace);
451 static void gtk_entry_delete_whitespace (GtkEntry *entry);
452 static void gtk_entry_select_word (GtkEntry *entry);
453 static void gtk_entry_select_line (GtkEntry *entry);
454 static void gtk_entry_paste (GtkEntry *entry,
456 static void gtk_entry_update_primary_selection (GtkEntry *entry);
457 static void gtk_entry_do_popup (GtkEntry *entry,
458 GdkEventButton *event);
459 static gboolean gtk_entry_mnemonic_activate (GtkWidget *widget,
460 gboolean group_cycling);
461 static void gtk_entry_check_cursor_blink (GtkEntry *entry);
462 static void gtk_entry_pend_cursor_blink (GtkEntry *entry);
463 static void gtk_entry_reset_blink_time (GtkEntry *entry);
464 static void gtk_entry_get_text_area_size (GtkEntry *entry,
469 static void get_text_area_size (GtkEntry *entry,
474 static void get_frame_size (GtkEntry *entry,
479 static void gtk_entry_move_adjustments (GtkEntry *entry);
480 static void gtk_entry_ensure_pixbuf (GtkEntry *entry,
481 GtkEntryIconPosition icon_pos);
485 static gint gtk_entry_completion_timeout (gpointer data);
486 static gboolean gtk_entry_completion_key_press (GtkWidget *widget,
489 static void gtk_entry_completion_changed (GtkWidget *entry,
491 static gboolean check_completion_callback (GtkEntryCompletion *completion);
492 static void clear_completion_callback (GtkEntry *entry,
494 static gboolean accept_completion_callback (GtkEntry *entry);
495 static void completion_insert_text_callback (GtkEntry *entry,
499 GtkEntryCompletion *completion);
500 static void completion_changed (GtkEntryCompletion *completion,
503 static void disconnect_completion_signals (GtkEntry *entry,
504 GtkEntryCompletion *completion);
505 static void connect_completion_signals (GtkEntry *entry,
506 GtkEntryCompletion *completion);
508 static void begin_change (GtkEntry *entry);
509 static void end_change (GtkEntry *entry);
510 static void emit_changed (GtkEntry *entry);
513 static void buffer_inserted_text (GtkEntryBuffer *buffer,
518 static void buffer_deleted_text (GtkEntryBuffer *buffer,
522 static void buffer_notify_text (GtkEntryBuffer *buffer,
525 static void buffer_notify_length (GtkEntryBuffer *buffer,
528 static void buffer_notify_max_length (GtkEntryBuffer *buffer,
531 static void buffer_connect_signals (GtkEntry *entry);
532 static void buffer_disconnect_signals (GtkEntry *entry);
533 static GtkEntryBuffer *get_buffer (GtkEntry *entry);
536 G_DEFINE_TYPE_WITH_CODE (GtkEntry, gtk_entry, GTK_TYPE_WIDGET,
537 G_IMPLEMENT_INTERFACE (GTK_TYPE_EDITABLE,
538 gtk_entry_editable_init)
539 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_EDITABLE,
540 gtk_entry_cell_editable_init))
543 add_move_binding (GtkBindingSet *binding_set,
546 GtkMovementStep step,
549 g_return_if_fail ((modmask & GDK_SHIFT_MASK) == 0);
551 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
555 G_TYPE_BOOLEAN, FALSE);
557 /* Selection-extending version */
558 gtk_binding_entry_add_signal (binding_set, keyval, modmask | GDK_SHIFT_MASK,
562 G_TYPE_BOOLEAN, TRUE);
566 gtk_entry_class_init (GtkEntryClass *class)
568 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
569 GtkWidgetClass *widget_class;
570 GtkBindingSet *binding_set;
572 widget_class = (GtkWidgetClass*) 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->destroy = gtk_entry_destroy;
580 widget_class->map = gtk_entry_map;
581 widget_class->unmap = gtk_entry_unmap;
582 widget_class->realize = gtk_entry_realize;
583 widget_class->unrealize = gtk_entry_unrealize;
584 widget_class->get_preferred_width = gtk_entry_get_preferred_width;
585 widget_class->get_preferred_height = gtk_entry_get_preferred_height;
586 widget_class->size_allocate = gtk_entry_size_allocate;
587 widget_class->draw = gtk_entry_draw;
588 widget_class->enter_notify_event = gtk_entry_enter_notify;
589 widget_class->leave_notify_event = gtk_entry_leave_notify;
590 widget_class->button_press_event = gtk_entry_button_press;
591 widget_class->button_release_event = gtk_entry_button_release;
592 widget_class->motion_notify_event = gtk_entry_motion_notify;
593 widget_class->key_press_event = gtk_entry_key_press;
594 widget_class->key_release_event = gtk_entry_key_release;
595 widget_class->focus_in_event = gtk_entry_focus_in;
596 widget_class->focus_out_event = gtk_entry_focus_out;
597 widget_class->grab_focus = gtk_entry_grab_focus;
598 widget_class->style_set = gtk_entry_style_set;
599 widget_class->query_tooltip = gtk_entry_query_tooltip;
600 widget_class->drag_begin = gtk_entry_drag_begin;
601 widget_class->drag_end = gtk_entry_drag_end;
602 widget_class->direction_changed = gtk_entry_direction_changed;
603 widget_class->state_changed = gtk_entry_state_changed;
604 widget_class->screen_changed = gtk_entry_screen_changed;
605 widget_class->mnemonic_activate = gtk_entry_mnemonic_activate;
607 widget_class->drag_drop = gtk_entry_drag_drop;
608 widget_class->drag_motion = gtk_entry_drag_motion;
609 widget_class->drag_leave = gtk_entry_drag_leave;
610 widget_class->drag_data_received = gtk_entry_drag_data_received;
611 widget_class->drag_data_get = gtk_entry_drag_data_get;
612 widget_class->drag_data_delete = gtk_entry_drag_data_delete;
614 widget_class->popup_menu = gtk_entry_popup_menu;
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 g_type_class_add_private (gobject_class, sizeof (GtkEntryPrivate));
1754 gtk_entry_editable_init (GtkEditableInterface *iface)
1756 iface->do_insert_text = gtk_entry_insert_text;
1757 iface->do_delete_text = gtk_entry_delete_text;
1758 iface->insert_text = gtk_entry_real_insert_text;
1759 iface->delete_text = gtk_entry_real_delete_text;
1760 iface->get_chars = gtk_entry_get_chars;
1761 iface->set_selection_bounds = gtk_entry_set_selection_bounds;
1762 iface->get_selection_bounds = gtk_entry_get_selection_bounds;
1763 iface->set_position = gtk_entry_real_set_position;
1764 iface->get_position = gtk_entry_get_position;
1768 gtk_entry_cell_editable_init (GtkCellEditableIface *iface)
1770 iface->start_editing = gtk_entry_start_editing;
1774 gtk_entry_set_property (GObject *object,
1776 const GValue *value,
1779 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (object);
1780 GtkEntry *entry = GTK_ENTRY (object);
1786 gtk_entry_set_buffer (entry, g_value_get_object (value));
1791 gboolean new_value = g_value_get_boolean (value);
1793 if (new_value != entry->editable)
1795 widget = GTK_WIDGET (entry);
1798 _gtk_entry_reset_im_context (entry);
1799 if (gtk_widget_has_focus (widget))
1800 gtk_im_context_focus_out (entry->im_context);
1802 entry->preedit_length = 0;
1803 entry->preedit_cursor = 0;
1806 entry->editable = new_value;
1808 if (new_value && gtk_widget_has_focus (widget))
1809 gtk_im_context_focus_in (entry->im_context);
1811 gtk_entry_queue_draw (entry);
1816 case PROP_MAX_LENGTH:
1817 gtk_entry_set_max_length (entry, g_value_get_int (value));
1820 case PROP_VISIBILITY:
1821 gtk_entry_set_visibility (entry, g_value_get_boolean (value));
1824 case PROP_HAS_FRAME:
1825 gtk_entry_set_has_frame (entry, g_value_get_boolean (value));
1828 case PROP_INNER_BORDER:
1829 gtk_entry_set_inner_border (entry, g_value_get_boxed (value));
1832 case PROP_INVISIBLE_CHAR:
1833 gtk_entry_set_invisible_char (entry, g_value_get_uint (value));
1836 case PROP_ACTIVATES_DEFAULT:
1837 gtk_entry_set_activates_default (entry, g_value_get_boolean (value));
1840 case PROP_WIDTH_CHARS:
1841 gtk_entry_set_width_chars (entry, g_value_get_int (value));
1845 gtk_entry_set_text (entry, g_value_get_string (value));
1849 gtk_entry_set_alignment (entry, g_value_get_float (value));
1852 case PROP_TRUNCATE_MULTILINE:
1853 entry->truncate_multiline = g_value_get_boolean (value);
1856 case PROP_SHADOW_TYPE:
1857 priv->shadow_type = g_value_get_enum (value);
1860 case PROP_OVERWRITE_MODE:
1861 gtk_entry_set_overwrite_mode (entry, g_value_get_boolean (value));
1864 case PROP_INVISIBLE_CHAR_SET:
1865 if (g_value_get_boolean (value))
1866 priv->invisible_char_set = TRUE;
1868 gtk_entry_unset_invisible_char (entry);
1871 case PROP_CAPS_LOCK_WARNING:
1872 priv->caps_lock_warning = g_value_get_boolean (value);
1875 case PROP_PROGRESS_FRACTION:
1876 gtk_entry_set_progress_fraction (entry, g_value_get_double (value));
1879 case PROP_PROGRESS_PULSE_STEP:
1880 gtk_entry_set_progress_pulse_step (entry, g_value_get_double (value));
1883 case PROP_PIXBUF_PRIMARY:
1884 gtk_entry_set_icon_from_pixbuf (entry,
1885 GTK_ENTRY_ICON_PRIMARY,
1886 g_value_get_object (value));
1889 case PROP_PIXBUF_SECONDARY:
1890 gtk_entry_set_icon_from_pixbuf (entry,
1891 GTK_ENTRY_ICON_SECONDARY,
1892 g_value_get_object (value));
1895 case PROP_STOCK_PRIMARY:
1896 gtk_entry_set_icon_from_stock (entry,
1897 GTK_ENTRY_ICON_PRIMARY,
1898 g_value_get_string (value));
1901 case PROP_STOCK_SECONDARY:
1902 gtk_entry_set_icon_from_stock (entry,
1903 GTK_ENTRY_ICON_SECONDARY,
1904 g_value_get_string (value));
1907 case PROP_ICON_NAME_PRIMARY:
1908 gtk_entry_set_icon_from_icon_name (entry,
1909 GTK_ENTRY_ICON_PRIMARY,
1910 g_value_get_string (value));
1913 case PROP_ICON_NAME_SECONDARY:
1914 gtk_entry_set_icon_from_icon_name (entry,
1915 GTK_ENTRY_ICON_SECONDARY,
1916 g_value_get_string (value));
1919 case PROP_GICON_PRIMARY:
1920 gtk_entry_set_icon_from_gicon (entry,
1921 GTK_ENTRY_ICON_PRIMARY,
1922 g_value_get_object (value));
1925 case PROP_GICON_SECONDARY:
1926 gtk_entry_set_icon_from_gicon (entry,
1927 GTK_ENTRY_ICON_SECONDARY,
1928 g_value_get_object (value));
1931 case PROP_ACTIVATABLE_PRIMARY:
1932 gtk_entry_set_icon_activatable (entry,
1933 GTK_ENTRY_ICON_PRIMARY,
1934 g_value_get_boolean (value));
1937 case PROP_ACTIVATABLE_SECONDARY:
1938 gtk_entry_set_icon_activatable (entry,
1939 GTK_ENTRY_ICON_SECONDARY,
1940 g_value_get_boolean (value));
1943 case PROP_SENSITIVE_PRIMARY:
1944 gtk_entry_set_icon_sensitive (entry,
1945 GTK_ENTRY_ICON_PRIMARY,
1946 g_value_get_boolean (value));
1949 case PROP_SENSITIVE_SECONDARY:
1950 gtk_entry_set_icon_sensitive (entry,
1951 GTK_ENTRY_ICON_SECONDARY,
1952 g_value_get_boolean (value));
1955 case PROP_TOOLTIP_TEXT_PRIMARY:
1956 gtk_entry_set_icon_tooltip_text (entry,
1957 GTK_ENTRY_ICON_PRIMARY,
1958 g_value_get_string (value));
1961 case PROP_TOOLTIP_TEXT_SECONDARY:
1962 gtk_entry_set_icon_tooltip_text (entry,
1963 GTK_ENTRY_ICON_SECONDARY,
1964 g_value_get_string (value));
1967 case PROP_TOOLTIP_MARKUP_PRIMARY:
1968 gtk_entry_set_icon_tooltip_markup (entry,
1969 GTK_ENTRY_ICON_PRIMARY,
1970 g_value_get_string (value));
1973 case PROP_TOOLTIP_MARKUP_SECONDARY:
1974 gtk_entry_set_icon_tooltip_markup (entry,
1975 GTK_ENTRY_ICON_SECONDARY,
1976 g_value_get_string (value));
1979 case PROP_IM_MODULE:
1980 g_free (priv->im_module);
1981 priv->im_module = g_value_dup_string (value);
1982 if (GTK_IS_IM_MULTICONTEXT (entry->im_context))
1983 gtk_im_multicontext_set_context_id (GTK_IM_MULTICONTEXT (entry->im_context), priv->im_module);
1986 case PROP_EDITING_CANCELED:
1987 entry->editing_canceled = g_value_get_boolean (value);
1990 case PROP_SCROLL_OFFSET:
1991 case PROP_CURSOR_POSITION:
1993 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1999 gtk_entry_get_property (GObject *object,
2004 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (object);
2005 GtkEntry *entry = GTK_ENTRY (object);
2010 g_value_set_object (value, gtk_entry_get_buffer (entry));
2013 case PROP_CURSOR_POSITION:
2014 g_value_set_int (value, entry->current_pos);
2017 case PROP_SELECTION_BOUND:
2018 g_value_set_int (value, entry->selection_bound);
2022 g_value_set_boolean (value, entry->editable);
2025 case PROP_MAX_LENGTH:
2026 g_value_set_int (value, gtk_entry_buffer_get_max_length (get_buffer (entry)));
2029 case PROP_VISIBILITY:
2030 g_value_set_boolean (value, entry->visible);
2033 case PROP_HAS_FRAME:
2034 g_value_set_boolean (value, entry->has_frame);
2037 case PROP_INNER_BORDER:
2038 g_value_set_boxed (value, gtk_entry_get_inner_border (entry));
2041 case PROP_INVISIBLE_CHAR:
2042 g_value_set_uint (value, entry->invisible_char);
2045 case PROP_ACTIVATES_DEFAULT:
2046 g_value_set_boolean (value, entry->activates_default);
2049 case PROP_WIDTH_CHARS:
2050 g_value_set_int (value, entry->width_chars);
2053 case PROP_SCROLL_OFFSET:
2054 g_value_set_int (value, entry->scroll_offset);
2058 g_value_set_string (value, gtk_entry_get_text (entry));
2062 g_value_set_float (value, gtk_entry_get_alignment (entry));
2065 case PROP_TRUNCATE_MULTILINE:
2066 g_value_set_boolean (value, entry->truncate_multiline);
2069 case PROP_SHADOW_TYPE:
2070 g_value_set_enum (value, priv->shadow_type);
2073 case PROP_OVERWRITE_MODE:
2074 g_value_set_boolean (value, entry->overwrite_mode);
2077 case PROP_TEXT_LENGTH:
2078 g_value_set_uint (value, gtk_entry_buffer_get_length (get_buffer (entry)));
2081 case PROP_INVISIBLE_CHAR_SET:
2082 g_value_set_boolean (value, priv->invisible_char_set);
2085 case PROP_IM_MODULE:
2086 g_value_set_string (value, priv->im_module);
2089 case PROP_CAPS_LOCK_WARNING:
2090 g_value_set_boolean (value, priv->caps_lock_warning);
2093 case PROP_PROGRESS_FRACTION:
2094 g_value_set_double (value, priv->progress_fraction);
2097 case PROP_PROGRESS_PULSE_STEP:
2098 g_value_set_double (value, priv->progress_pulse_fraction);
2101 case PROP_PIXBUF_PRIMARY:
2102 g_value_set_object (value,
2103 gtk_entry_get_icon_pixbuf (entry,
2104 GTK_ENTRY_ICON_PRIMARY));
2107 case PROP_PIXBUF_SECONDARY:
2108 g_value_set_object (value,
2109 gtk_entry_get_icon_pixbuf (entry,
2110 GTK_ENTRY_ICON_SECONDARY));
2113 case PROP_STOCK_PRIMARY:
2114 g_value_set_string (value,
2115 gtk_entry_get_icon_stock (entry,
2116 GTK_ENTRY_ICON_PRIMARY));
2119 case PROP_STOCK_SECONDARY:
2120 g_value_set_string (value,
2121 gtk_entry_get_icon_stock (entry,
2122 GTK_ENTRY_ICON_SECONDARY));
2125 case PROP_ICON_NAME_PRIMARY:
2126 g_value_set_string (value,
2127 gtk_entry_get_icon_name (entry,
2128 GTK_ENTRY_ICON_PRIMARY));
2131 case PROP_ICON_NAME_SECONDARY:
2132 g_value_set_string (value,
2133 gtk_entry_get_icon_name (entry,
2134 GTK_ENTRY_ICON_SECONDARY));
2137 case PROP_GICON_PRIMARY:
2138 g_value_set_object (value,
2139 gtk_entry_get_icon_gicon (entry,
2140 GTK_ENTRY_ICON_PRIMARY));
2143 case PROP_GICON_SECONDARY:
2144 g_value_set_object (value,
2145 gtk_entry_get_icon_gicon (entry,
2146 GTK_ENTRY_ICON_SECONDARY));
2149 case PROP_STORAGE_TYPE_PRIMARY:
2150 g_value_set_enum (value,
2151 gtk_entry_get_icon_storage_type (entry,
2152 GTK_ENTRY_ICON_PRIMARY));
2155 case PROP_STORAGE_TYPE_SECONDARY:
2156 g_value_set_enum (value,
2157 gtk_entry_get_icon_storage_type (entry,
2158 GTK_ENTRY_ICON_SECONDARY));
2161 case PROP_ACTIVATABLE_PRIMARY:
2162 g_value_set_boolean (value,
2163 gtk_entry_get_icon_activatable (entry, GTK_ENTRY_ICON_PRIMARY));
2166 case PROP_ACTIVATABLE_SECONDARY:
2167 g_value_set_boolean (value,
2168 gtk_entry_get_icon_activatable (entry, GTK_ENTRY_ICON_SECONDARY));
2171 case PROP_SENSITIVE_PRIMARY:
2172 g_value_set_boolean (value,
2173 gtk_entry_get_icon_sensitive (entry, GTK_ENTRY_ICON_PRIMARY));
2176 case PROP_SENSITIVE_SECONDARY:
2177 g_value_set_boolean (value,
2178 gtk_entry_get_icon_sensitive (entry, GTK_ENTRY_ICON_SECONDARY));
2181 case PROP_TOOLTIP_TEXT_PRIMARY:
2182 g_value_take_string (value,
2183 gtk_entry_get_icon_tooltip_text (entry, GTK_ENTRY_ICON_PRIMARY));
2186 case PROP_TOOLTIP_TEXT_SECONDARY:
2187 g_value_take_string (value,
2188 gtk_entry_get_icon_tooltip_text (entry, GTK_ENTRY_ICON_SECONDARY));
2191 case PROP_TOOLTIP_MARKUP_PRIMARY:
2192 g_value_take_string (value,
2193 gtk_entry_get_icon_tooltip_markup (entry, GTK_ENTRY_ICON_PRIMARY));
2196 case PROP_TOOLTIP_MARKUP_SECONDARY:
2197 g_value_take_string (value,
2198 gtk_entry_get_icon_tooltip_markup (entry, GTK_ENTRY_ICON_SECONDARY));
2201 case PROP_EDITING_CANCELED:
2202 g_value_set_boolean (value,
2203 entry->editing_canceled);
2207 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2213 find_invisible_char (GtkWidget *widget)
2215 PangoLayout *layout;
2216 PangoAttrList *attr_list;
2218 gunichar invisible_chars [] = {
2220 0x25cf, /* BLACK CIRCLE */
2221 0x2022, /* BULLET */
2222 0x2731, /* HEAVY ASTERISK */
2223 0x273a /* SIXTEEN POINTED ASTERISK */
2226 if (gtk_widget_get_style (widget))
2227 gtk_widget_style_get (widget,
2228 "invisible-char", &invisible_chars[0],
2231 layout = gtk_widget_create_pango_layout (widget, NULL);
2233 attr_list = pango_attr_list_new ();
2234 pango_attr_list_insert (attr_list, pango_attr_fallback_new (FALSE));
2236 pango_layout_set_attributes (layout, attr_list);
2237 pango_attr_list_unref (attr_list);
2239 for (i = (invisible_chars[0] != 0 ? 0 : 1); i < G_N_ELEMENTS (invisible_chars); i++)
2241 gchar text[7] = { 0, };
2244 len = g_unichar_to_utf8 (invisible_chars[i], text);
2245 pango_layout_set_text (layout, text, len);
2247 count = pango_layout_get_unknown_glyphs_count (layout);
2251 g_object_unref (layout);
2252 return invisible_chars[i];
2256 g_object_unref (layout);
2262 gtk_entry_init (GtkEntry *entry)
2264 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2266 gtk_widget_set_can_focus (GTK_WIDGET (entry), TRUE);
2267 gtk_widget_set_has_window (GTK_WIDGET (entry), FALSE);
2269 entry->editable = TRUE;
2270 entry->visible = TRUE;
2271 entry->invisible_char = find_invisible_char (GTK_WIDGET (entry));
2272 entry->dnd_position = -1;
2273 entry->width_chars = -1;
2274 entry->is_cell_renderer = FALSE;
2275 entry->editing_canceled = FALSE;
2276 entry->has_frame = TRUE;
2277 entry->truncate_multiline = FALSE;
2278 priv->shadow_type = GTK_SHADOW_IN;
2280 priv->caps_lock_warning = TRUE;
2281 priv->caps_lock_warning_shown = FALSE;
2282 priv->progress_fraction = 0.0;
2283 priv->progress_pulse_fraction = 0.1;
2285 gtk_drag_dest_set (GTK_WIDGET (entry),
2286 GTK_DEST_DEFAULT_HIGHLIGHT,
2288 GDK_ACTION_COPY | GDK_ACTION_MOVE);
2289 gtk_drag_dest_add_text_targets (GTK_WIDGET (entry));
2291 /* This object is completely private. No external entity can gain a reference
2292 * to it; so we create it here and destroy it in finalize().
2294 entry->im_context = gtk_im_multicontext_new ();
2296 g_signal_connect (entry->im_context, "commit",
2297 G_CALLBACK (gtk_entry_commit_cb), entry);
2298 g_signal_connect (entry->im_context, "preedit-changed",
2299 G_CALLBACK (gtk_entry_preedit_changed_cb), entry);
2300 g_signal_connect (entry->im_context, "retrieve-surrounding",
2301 G_CALLBACK (gtk_entry_retrieve_surrounding_cb), entry);
2302 g_signal_connect (entry->im_context, "delete-surrounding",
2303 G_CALLBACK (gtk_entry_delete_surrounding_cb), entry);
2308 get_icon_width (GtkEntry *entry,
2309 GtkEntryIconPosition icon_pos)
2311 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2312 EntryIconInfo *icon_info = priv->icons[icon_pos];
2314 GtkSettings *settings;
2315 gint menu_icon_width;
2317 if (!icon_info || icon_info->pixbuf == NULL)
2320 screen = gtk_widget_get_screen (GTK_WIDGET (entry));
2321 settings = gtk_settings_get_for_screen (screen);
2323 gtk_icon_size_lookup_for_settings (settings, GTK_ICON_SIZE_MENU,
2324 &menu_icon_width, NULL);
2326 return MAX (gdk_pixbuf_get_width (icon_info->pixbuf), menu_icon_width);
2330 get_icon_allocations (GtkEntry *entry,
2331 GtkAllocation *primary,
2332 GtkAllocation *secondary)
2335 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2336 gint x, y, width, height;
2338 get_text_area_size (entry, &x, &y, &width, &height);
2340 if (gtk_widget_has_focus (GTK_WIDGET (entry)) && !priv->interior_focus)
2341 y += priv->focus_width;
2344 primary->height = height;
2345 primary->width = get_icon_width (entry, GTK_ENTRY_ICON_PRIMARY);
2346 if (primary->width > 0)
2347 primary->width += 2 * priv->icon_margin;
2350 secondary->height = height;
2351 secondary->width = get_icon_width (entry, GTK_ENTRY_ICON_SECONDARY);
2352 if (secondary->width > 0)
2353 secondary->width += 2 * priv->icon_margin;
2355 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
2357 primary->x = x + width - primary->width;
2363 secondary->x = x + width - secondary->width;
2369 begin_change (GtkEntry *entry)
2371 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2373 priv->change_count++;
2377 end_change (GtkEntry *entry)
2379 GtkEditable *editable = GTK_EDITABLE (entry);
2380 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2382 g_return_if_fail (priv->change_count > 0);
2384 priv->change_count--;
2386 if (priv->change_count == 0)
2388 if (priv->real_changed)
2390 g_signal_emit_by_name (editable, "changed");
2391 priv->real_changed = FALSE;
2397 emit_changed (GtkEntry *entry)
2399 GtkEditable *editable = GTK_EDITABLE (entry);
2400 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2402 if (priv->change_count == 0)
2403 g_signal_emit_by_name (editable, "changed");
2405 priv->real_changed = TRUE;
2409 gtk_entry_destroy (GtkWidget *widget)
2411 GtkEntry *entry = GTK_ENTRY (widget);
2413 entry->current_pos = entry->selection_bound = 0;
2414 _gtk_entry_reset_im_context (entry);
2415 gtk_entry_reset_layout (entry);
2417 if (entry->blink_timeout)
2419 g_source_remove (entry->blink_timeout);
2420 entry->blink_timeout = 0;
2423 if (entry->recompute_idle)
2425 g_source_remove (entry->recompute_idle);
2426 entry->recompute_idle = 0;
2429 GTK_WIDGET_CLASS (gtk_entry_parent_class)->destroy (widget);
2433 gtk_entry_dispose (GObject *object)
2435 GtkEntry *entry = GTK_ENTRY (object);
2436 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2438 gtk_entry_set_icon_from_pixbuf (entry, GTK_ENTRY_ICON_PRIMARY, NULL);
2439 gtk_entry_set_icon_tooltip_markup (entry, GTK_ENTRY_ICON_PRIMARY, NULL);
2440 gtk_entry_set_icon_from_pixbuf (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
2441 gtk_entry_set_icon_tooltip_markup (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
2445 buffer_disconnect_signals (entry);
2446 g_object_unref (priv->buffer);
2447 priv->buffer = NULL;
2450 G_OBJECT_CLASS (gtk_entry_parent_class)->dispose (object);
2454 gtk_entry_finalize (GObject *object)
2456 GtkEntry *entry = GTK_ENTRY (object);
2457 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2458 EntryIconInfo *icon_info = NULL;
2461 for (i = 0; i < MAX_ICONS; i++)
2463 if ((icon_info = priv->icons[i]) != NULL)
2465 if (icon_info->target_list != NULL)
2467 gtk_target_list_unref (icon_info->target_list);
2468 icon_info->target_list = NULL;
2471 g_slice_free (EntryIconInfo, icon_info);
2472 priv->icons[i] = NULL;
2476 gtk_entry_set_completion (entry, NULL);
2478 if (entry->cached_layout)
2479 g_object_unref (entry->cached_layout);
2481 g_object_unref (entry->im_context);
2483 if (entry->blink_timeout)
2484 g_source_remove (entry->blink_timeout);
2486 if (entry->recompute_idle)
2487 g_source_remove (entry->recompute_idle);
2489 g_free (priv->im_module);
2491 G_OBJECT_CLASS (gtk_entry_parent_class)->finalize (object);
2495 gtk_entry_get_display_mode (GtkEntry *entry)
2497 GtkEntryPrivate *priv;
2499 return DISPLAY_NORMAL;
2500 priv = GTK_ENTRY_GET_PRIVATE (entry);
2501 if (entry->invisible_char == 0 && priv->invisible_char_set)
2502 return DISPLAY_BLANK;
2503 return DISPLAY_INVISIBLE;
2507 gtk_entry_get_display_text (GtkEntry *entry,
2511 GtkEntryPasswordHint *password_hint;
2512 GtkEntryPrivate *priv;
2513 gunichar invisible_char;
2523 priv = GTK_ENTRY_GET_PRIVATE (entry);
2524 text = gtk_entry_buffer_get_text (get_buffer (entry));
2525 length = gtk_entry_buffer_get_length (get_buffer (entry));
2529 if (start_pos > length)
2532 if (end_pos <= start_pos)
2533 return g_strdup ("");
2534 else if (entry->visible)
2536 start = g_utf8_offset_to_pointer (text, start_pos);
2537 end = g_utf8_offset_to_pointer (start, end_pos - start_pos);
2538 return g_strndup (start, end - start);
2542 str = g_string_sized_new (length * 2);
2544 /* Figure out what our invisible char is and encode it */
2545 if (!entry->invisible_char)
2546 invisible_char = priv->invisible_char_set ? ' ' : '*';
2548 invisible_char = entry->invisible_char;
2549 char_len = g_unichar_to_utf8 (invisible_char, char_str);
2552 * Add hidden characters for each character in the text
2553 * buffer. If there is a password hint, then keep that
2554 * character visible.
2557 password_hint = g_object_get_qdata (G_OBJECT (entry), quark_password_hint);
2558 for (i = start_pos; i < end_pos; ++i)
2560 if (password_hint && i == password_hint->position)
2562 start = g_utf8_offset_to_pointer (text, i);
2563 g_string_append_len (str, start, g_utf8_next_char (start) - start);
2567 g_string_append_len (str, char_str, char_len);
2571 return g_string_free (str, FALSE);
2577 update_cursors (GtkWidget *widget)
2579 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2580 EntryIconInfo *icon_info = NULL;
2581 GdkDisplay *display;
2585 for (i = 0; i < MAX_ICONS; i++)
2587 if ((icon_info = priv->icons[i]) != NULL)
2589 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
2590 gdk_window_show_unraised (icon_info->window);
2592 /* The icon windows are not children of the visible entry window,
2593 * thus we can't just inherit the xterm cursor. Slight complication
2594 * here is that for the entry, insensitive => arrow cursor, but for
2595 * an icon in a sensitive entry, insensitive => xterm cursor.
2597 if (gtk_widget_is_sensitive (widget) &&
2598 (icon_info->insensitive ||
2599 (icon_info->nonactivatable && icon_info->target_list == NULL)))
2601 display = gtk_widget_get_display (widget);
2602 cursor = gdk_cursor_new_for_display (display, GDK_XTERM);
2603 gdk_window_set_cursor (icon_info->window, cursor);
2604 gdk_cursor_unref (cursor);
2608 gdk_window_set_cursor (icon_info->window, NULL);
2615 realize_icon_info (GtkWidget *widget,
2616 GtkEntryIconPosition icon_pos)
2618 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2619 EntryIconInfo *icon_info = priv->icons[icon_pos];
2620 GdkWindowAttr attributes;
2621 gint attributes_mask;
2623 g_return_if_fail (icon_info != NULL);
2627 attributes.width = 1;
2628 attributes.height = 1;
2629 attributes.window_type = GDK_WINDOW_CHILD;
2630 attributes.wclass = GDK_INPUT_ONLY;
2631 attributes.event_mask = gtk_widget_get_events (widget);
2632 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
2633 GDK_BUTTON_RELEASE_MASK |
2634 GDK_BUTTON1_MOTION_MASK |
2635 GDK_BUTTON3_MOTION_MASK |
2636 GDK_POINTER_MOTION_HINT_MASK |
2637 GDK_POINTER_MOTION_MASK |
2638 GDK_ENTER_NOTIFY_MASK |
2639 GDK_LEAVE_NOTIFY_MASK);
2640 attributes_mask = GDK_WA_X | GDK_WA_Y;
2642 icon_info->window = gdk_window_new (gtk_widget_get_window (widget),
2645 gdk_window_set_user_data (icon_info->window, widget);
2647 gtk_widget_queue_resize (widget);
2650 static EntryIconInfo*
2651 construct_icon_info (GtkWidget *widget,
2652 GtkEntryIconPosition icon_pos)
2654 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2655 EntryIconInfo *icon_info;
2657 g_return_val_if_fail (priv->icons[icon_pos] == NULL, NULL);
2659 icon_info = g_slice_new0 (EntryIconInfo);
2660 priv->icons[icon_pos] = icon_info;
2662 if (gtk_widget_get_realized (widget))
2663 realize_icon_info (widget, icon_pos);
2669 gtk_entry_map (GtkWidget *widget)
2671 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2672 EntryIconInfo *icon_info = NULL;
2675 GTK_WIDGET_CLASS (gtk_entry_parent_class)->map (widget);
2677 for (i = 0; i < MAX_ICONS; i++)
2679 if ((icon_info = priv->icons[i]) != NULL)
2681 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
2682 gdk_window_show (icon_info->window);
2686 update_cursors (widget);
2690 gtk_entry_unmap (GtkWidget *widget)
2692 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2693 EntryIconInfo *icon_info = NULL;
2696 for (i = 0; i < MAX_ICONS; i++)
2698 if ((icon_info = priv->icons[i]) != NULL)
2700 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
2701 gdk_window_hide (icon_info->window);
2705 GTK_WIDGET_CLASS (gtk_entry_parent_class)->unmap (widget);
2709 gtk_entry_realize (GtkWidget *widget)
2712 GtkEntryPrivate *priv;
2713 EntryIconInfo *icon_info;
2715 GdkWindowAttr attributes;
2716 gint attributes_mask;
2717 gint frame_x, frame_y;
2720 gtk_widget_set_realized (widget, TRUE);
2721 window = gtk_widget_get_parent_window (widget);
2722 gtk_widget_set_window (widget, window);
2723 g_object_ref (window);
2725 entry = GTK_ENTRY (widget);
2726 priv = GTK_ENTRY_GET_PRIVATE (entry);
2728 attributes.window_type = GDK_WINDOW_CHILD;
2729 attributes.wclass = GDK_INPUT_ONLY;
2730 attributes.event_mask = gtk_widget_get_events (widget);
2731 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
2732 GDK_BUTTON_RELEASE_MASK |
2733 GDK_BUTTON1_MOTION_MASK |
2734 GDK_BUTTON3_MOTION_MASK |
2735 GDK_POINTER_MOTION_HINT_MASK |
2736 GDK_POINTER_MOTION_MASK |
2737 GDK_ENTER_NOTIFY_MASK |
2738 GDK_LEAVE_NOTIFY_MASK);
2739 attributes_mask = GDK_WA_X | GDK_WA_Y;
2741 get_text_area_size (entry, &attributes.x, &attributes.y, &attributes.width, &attributes.height);
2743 get_frame_size (entry, &frame_x, &frame_y, NULL, NULL);
2744 attributes.x += frame_x;
2745 attributes.y += frame_y;
2747 if (gtk_widget_is_sensitive (widget))
2749 attributes.cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
2750 attributes_mask |= GDK_WA_CURSOR;
2753 entry->text_area = gdk_window_new (gtk_widget_get_window (widget),
2757 gdk_window_set_user_data (entry->text_area, entry);
2759 if (attributes_mask & GDK_WA_CURSOR)
2760 gdk_cursor_unref (attributes.cursor);
2762 gtk_widget_style_attach (widget);
2764 gdk_window_show (entry->text_area);
2766 gtk_im_context_set_client_window (entry->im_context, entry->text_area);
2768 gtk_entry_adjust_scroll (entry);
2769 gtk_entry_update_primary_selection (entry);
2772 /* If the icon positions are already setup, create their windows.
2773 * Otherwise if they don't exist yet, then construct_icon_info()
2774 * will create the windows once the widget is already realized.
2776 for (i = 0; i < MAX_ICONS; i++)
2778 if ((icon_info = priv->icons[i]) != NULL)
2780 if (icon_info->window == NULL)
2781 realize_icon_info (widget, i);
2787 gtk_entry_unrealize (GtkWidget *widget)
2789 GtkEntry *entry = GTK_ENTRY (widget);
2790 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2791 GtkClipboard *clipboard;
2792 EntryIconInfo *icon_info;
2795 gtk_entry_reset_layout (entry);
2797 gtk_im_context_set_client_window (entry->im_context, NULL);
2799 clipboard = gtk_widget_get_clipboard (widget, GDK_SELECTION_PRIMARY);
2800 if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (entry))
2801 gtk_clipboard_clear (clipboard);
2803 if (entry->text_area)
2805 gdk_window_set_user_data (entry->text_area, NULL);
2806 gdk_window_destroy (entry->text_area);
2807 entry->text_area = NULL;
2810 if (entry->popup_menu)
2812 gtk_widget_destroy (entry->popup_menu);
2813 entry->popup_menu = NULL;
2816 GTK_WIDGET_CLASS (gtk_entry_parent_class)->unrealize (widget);
2818 for (i = 0; i < MAX_ICONS; i++)
2820 if ((icon_info = priv->icons[i]) != NULL)
2822 if (icon_info->window != NULL)
2824 gdk_window_destroy (icon_info->window);
2825 icon_info->window = NULL;
2832 _gtk_entry_get_borders (GtkEntry *entry,
2836 GtkWidget *widget = GTK_WIDGET (entry);
2837 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2840 if (entry->has_frame)
2842 style = gtk_widget_get_style (widget);
2844 *xborder = style->xthickness;
2845 *yborder = style->ythickness;
2853 if (!priv->interior_focus)
2855 *xborder += priv->focus_width;
2856 *yborder += priv->focus_width;
2861 gtk_entry_get_preferred_width (GtkWidget *widget,
2865 GtkEntry *entry = GTK_ENTRY (widget);
2866 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2867 PangoFontMetrics *metrics;
2868 gint xborder, yborder;
2869 GtkBorder inner_border;
2870 PangoContext *context;
2871 gint icon_widths = 0;
2875 gtk_widget_ensure_style (widget);
2876 context = gtk_widget_get_pango_context (widget);
2877 metrics = pango_context_get_metrics (context,
2878 gtk_widget_get_style (widget)->font_desc,
2879 pango_context_get_language (context));
2881 _gtk_entry_get_borders (entry, &xborder, &yborder);
2882 _gtk_entry_effective_inner_border (entry, &inner_border);
2884 if (entry->width_chars < 0)
2885 width = MIN_ENTRY_WIDTH + xborder * 2 + inner_border.left + inner_border.right;
2888 gint char_width = pango_font_metrics_get_approximate_char_width (metrics);
2889 gint digit_width = pango_font_metrics_get_approximate_digit_width (metrics);
2890 gint char_pixels = (MAX (char_width, digit_width) + PANGO_SCALE - 1) / PANGO_SCALE;
2892 width = char_pixels * entry->width_chars + xborder * 2 + inner_border.left + inner_border.right;
2895 for (i = 0; i < MAX_ICONS; i++)
2897 icon_width = get_icon_width (entry, i);
2899 icon_widths += icon_width + 2 * priv->icon_margin;
2902 if (icon_widths > width)
2903 width += icon_widths;
2905 pango_font_metrics_unref (metrics);
2912 gtk_entry_get_preferred_height (GtkWidget *widget,
2916 GtkEntry *entry = GTK_ENTRY (widget);
2917 PangoFontMetrics *metrics;
2918 gint xborder, yborder;
2919 GtkBorder inner_border;
2920 PangoContext *context;
2923 gtk_widget_ensure_style (widget);
2924 context = gtk_widget_get_pango_context (widget);
2925 metrics = pango_context_get_metrics (context,
2926 gtk_widget_get_style (widget)->font_desc,
2927 pango_context_get_language (context));
2929 entry->ascent = pango_font_metrics_get_ascent (metrics);
2930 entry->descent = pango_font_metrics_get_descent (metrics);
2932 _gtk_entry_get_borders (entry, &xborder, &yborder);
2933 _gtk_entry_effective_inner_border (entry, &inner_border);
2935 height = PANGO_PIXELS (entry->ascent + entry->descent) + yborder * 2 + inner_border.top + inner_border.bottom;
2937 pango_font_metrics_unref (metrics);
2944 place_windows (GtkEntry *entry)
2946 GtkWidget *widget = GTK_WIDGET (entry);
2947 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2948 gint x, y, width, height;
2949 gint frame_x, frame_y;
2950 GtkAllocation primary;
2951 GtkAllocation secondary;
2952 EntryIconInfo *icon_info = NULL;
2954 get_frame_size (entry, &frame_x, &frame_y, NULL, NULL);
2955 get_text_area_size (entry, &x, &y, &width, &height);
2956 get_icon_allocations (entry, &primary, &secondary);
2958 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
2959 y += priv->focus_width;
2961 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
2962 x += secondary.width;
2965 width -= primary.width + secondary.width;
2969 primary.x += frame_x;
2970 primary.y += frame_y;
2971 secondary.x += frame_x;
2972 secondary.y += frame_y;
2974 if ((icon_info = priv->icons[GTK_ENTRY_ICON_PRIMARY]) != NULL)
2975 gdk_window_move_resize (icon_info->window,
2976 primary.x, primary.y,
2977 primary.width, primary.height);
2979 if ((icon_info = priv->icons[GTK_ENTRY_ICON_SECONDARY]) != NULL)
2980 gdk_window_move_resize (icon_info->window,
2981 secondary.x, secondary.y,
2982 secondary.width, secondary.height);
2984 gdk_window_move_resize (entry->text_area, x, y, width, height);
2988 gtk_entry_get_text_area_size (GtkEntry *entry,
2994 GtkWidget *widget = GTK_WIDGET (entry);
2995 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2996 GtkAllocation allocation;
2997 GtkRequisition requisition;
2999 gint xborder, yborder;
3001 gtk_widget_get_preferred_size (widget, &requisition, NULL);
3002 gtk_widget_get_allocation (widget, &allocation);
3003 _gtk_entry_get_borders (entry, &xborder, &yborder);
3005 if (gtk_widget_get_realized (widget))
3006 get_frame_size (entry, NULL, NULL, NULL, &frame_height);
3008 frame_height = requisition.height;
3010 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3011 frame_height -= 2 * priv->focus_width;
3017 *y = frame_height / 2 - (requisition.height - yborder * 2) / 2;
3020 *width = allocation.width - xborder * 2;
3023 *height = requisition.height - yborder * 2;
3027 get_text_area_size (GtkEntry *entry,
3033 GtkEntryClass *class;
3035 g_return_if_fail (GTK_IS_ENTRY (entry));
3037 class = GTK_ENTRY_GET_CLASS (entry);
3039 if (class->get_text_area_size)
3040 class->get_text_area_size (entry, x, y, width, height);
3045 get_frame_size (GtkEntry *entry,
3051 GtkAllocation allocation;
3052 GtkRequisition requisition;
3053 GtkWidget *widget = GTK_WIDGET (entry);
3055 gtk_widget_get_preferred_size (widget, &requisition, NULL);
3056 gtk_widget_get_allocation (widget, &allocation);
3063 if (entry->is_cell_renderer)
3066 *y = allocation.y + (allocation.height - requisition.height) / 2;
3070 *width = allocation.width;
3074 if (entry->is_cell_renderer)
3075 *height = allocation.height;
3077 *height = requisition.height;
3082 _gtk_entry_effective_inner_border (GtkEntry *entry,
3085 GtkBorder *tmp_border;
3087 tmp_border = g_object_get_qdata (G_OBJECT (entry), quark_inner_border);
3091 *border = *tmp_border;
3095 gtk_widget_style_get (GTK_WIDGET (entry), "inner-border", &tmp_border, NULL);
3099 *border = *tmp_border;
3100 gtk_border_free (tmp_border);
3104 *border = default_inner_border;
3108 gtk_entry_size_allocate (GtkWidget *widget,
3109 GtkAllocation *allocation)
3111 GtkEntry *entry = GTK_ENTRY (widget);
3113 gtk_widget_set_allocation (widget, allocation);
3115 if (gtk_widget_get_realized (widget))
3117 GtkEntryCompletion* completion;
3119 place_windows (entry);
3120 gtk_entry_recompute (entry);
3122 completion = gtk_entry_get_completion (entry);
3123 if (completion && gtk_widget_get_mapped (completion->priv->popup_window))
3124 _gtk_entry_completion_resize_popup (completion);
3128 /* Kudos to the gnome-panel guys. */
3130 colorshift_pixbuf (GdkPixbuf *dest,
3135 gint width, height, has_alpha, src_rowstride, dest_rowstride;
3136 guchar *target_pixels;
3137 guchar *original_pixels;
3143 has_alpha = gdk_pixbuf_get_has_alpha (src);
3144 width = gdk_pixbuf_get_width (src);
3145 height = gdk_pixbuf_get_height (src);
3146 src_rowstride = gdk_pixbuf_get_rowstride (src);
3147 dest_rowstride = gdk_pixbuf_get_rowstride (dest);
3148 original_pixels = gdk_pixbuf_get_pixels (src);
3149 target_pixels = gdk_pixbuf_get_pixels (dest);
3151 for (i = 0; i < height; i++)
3153 pix_dest = target_pixels + i * dest_rowstride;
3154 pix_src = original_pixels + i * src_rowstride;
3156 for (j = 0; j < width; j++)
3163 *(pix_dest++) = CLAMP (val, 0, 255);
3166 *(pix_dest++) = CLAMP (val, 0, 255);
3169 *(pix_dest++) = CLAMP (val, 0, 255);
3172 *(pix_dest++) = *(pix_src++);
3178 should_prelight (GtkEntry *entry,
3179 GtkEntryIconPosition icon_pos)
3181 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3182 EntryIconInfo *icon_info = priv->icons[icon_pos];
3188 if (icon_info->nonactivatable && icon_info->target_list == NULL)
3191 if (icon_info->pressed)
3194 gtk_widget_style_get (GTK_WIDGET (entry),
3195 "icon-prelight", &prelight,
3202 draw_icon (GtkWidget *widget,
3204 GtkEntryIconPosition icon_pos)
3206 GtkEntry *entry = GTK_ENTRY (widget);
3207 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3208 EntryIconInfo *icon_info = priv->icons[icon_pos];
3210 gint x, y, width, height;
3215 gtk_entry_ensure_pixbuf (entry, icon_pos);
3217 if (icon_info->pixbuf == NULL)
3220 width = gdk_window_get_width (icon_info->window);
3221 height = gdk_window_get_height (icon_info->window);
3223 /* size_allocate hasn't been called yet. These are the default values.
3225 if (width == 1 || height == 1)
3228 pixbuf = icon_info->pixbuf;
3229 g_object_ref (pixbuf);
3231 if (gdk_pixbuf_get_height (pixbuf) > height)
3233 GdkPixbuf *temp_pixbuf;
3236 scale = height - 2 * priv->icon_margin;
3237 temp_pixbuf = gdk_pixbuf_scale_simple (pixbuf, scale, scale,
3238 GDK_INTERP_BILINEAR);
3239 g_object_unref (pixbuf);
3240 pixbuf = temp_pixbuf;
3243 x = (width - gdk_pixbuf_get_width (pixbuf)) / 2;
3244 y = (height - gdk_pixbuf_get_height (pixbuf)) / 2;
3246 if (!gtk_widget_is_sensitive (widget) ||
3247 icon_info->insensitive)
3249 GdkPixbuf *temp_pixbuf;
3251 temp_pixbuf = gdk_pixbuf_copy (pixbuf);
3252 gdk_pixbuf_saturate_and_pixelate (pixbuf,
3256 g_object_unref (pixbuf);
3257 pixbuf = temp_pixbuf;
3259 else if (icon_info->prelight)
3261 GdkPixbuf *temp_pixbuf;
3263 temp_pixbuf = gdk_pixbuf_copy (pixbuf);
3264 colorshift_pixbuf (temp_pixbuf, pixbuf, 30);
3265 g_object_unref (pixbuf);
3266 pixbuf = temp_pixbuf;
3269 gdk_cairo_set_source_pixbuf (cr, pixbuf, x, y);
3272 g_object_unref (pixbuf);
3277 gtk_entry_draw_frame (GtkWidget *widget,
3280 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
3283 gint x = 0, y = 0, width, height;
3285 GtkAllocation allocation;
3286 gint frame_x, frame_y;
3290 window = gtk_widget_get_window (widget);
3292 get_frame_size (GTK_ENTRY (widget), &frame_x, &frame_y, &width, &height);
3293 gtk_widget_get_allocation (widget, &allocation);
3295 cairo_translate (cr, frame_x - allocation.x, frame_y - allocation.y);
3297 /* Fix a problem with some themes which assume that entry->text_area's
3298 * width equals widget->window's width
3299 * http://bugzilla.gnome.org/show_bug.cgi?id=466000 */
3300 if (GTK_IS_SPIN_BUTTON (widget))
3302 gint xborder, yborder;
3304 gtk_entry_get_text_area_size (GTK_ENTRY (widget), &x, NULL, &width, NULL);
3305 _gtk_entry_get_borders (GTK_ENTRY (widget), &xborder, &yborder);
3308 width += xborder * 2;
3311 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3313 x += priv->focus_width;
3314 y += priv->focus_width;
3315 width -= 2 * priv->focus_width;
3316 height -= 2 * priv->focus_width;
3319 style = gtk_widget_get_style (widget);
3320 state = gtk_widget_has_focus (widget) ?
3321 GTK_STATE_ACTIVE : gtk_widget_get_state (widget);
3323 gtk_paint_flat_box (style, cr,
3324 state, GTK_SHADOW_NONE,
3326 x, y, width, height);
3328 gtk_paint_shadow (style, cr,
3329 state, priv->shadow_type,
3330 widget, "entry", x, y, width, height);
3333 gtk_entry_draw_progress (widget, cr);
3335 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3337 x -= priv->focus_width;
3338 y -= priv->focus_width;
3339 width += 2 * priv->focus_width;
3340 height += 2 * priv->focus_width;
3342 gtk_paint_focus (style, cr,
3343 gtk_widget_get_state (widget),
3345 0, 0, width, height);
3352 gtk_entry_get_progress_border (GtkWidget *widget,
3353 GtkBorder *progress_border)
3355 GtkBorder *tmp_border;
3358 gtk_widget_style_get (widget, "progress-border", &tmp_border, NULL);
3361 *progress_border = *tmp_border;
3362 gtk_border_free (tmp_border);
3366 style = gtk_widget_get_style (widget);
3368 progress_border->left = style->xthickness;
3369 progress_border->right = style->xthickness;
3370 progress_border->top = style->ythickness;
3371 progress_border->bottom = style->ythickness;
3376 get_progress_area (GtkWidget *widget,
3382 GtkEntryPrivate *private = GTK_ENTRY_GET_PRIVATE (widget);
3383 GtkEntry *entry = GTK_ENTRY (widget);
3384 GtkBorder progress_border;
3385 gint frame_width, frame_height;
3387 get_frame_size (entry, NULL, NULL, &frame_width, &frame_height);
3388 gtk_entry_get_progress_border (widget, &progress_border);
3390 *x = progress_border.left;
3391 *y = progress_border.top;
3393 *width = frame_width
3394 - progress_border.left - progress_border.right;
3395 *height = frame_height
3396 - progress_border.top - progress_border.bottom;
3398 if (gtk_widget_has_focus (widget) && !private->interior_focus)
3400 *x += private->focus_width;
3401 *y += private->focus_width;
3402 *width -= 2 * private->focus_width;
3403 *height -= 2 * private->focus_width;
3406 if (private->progress_pulse_mode)
3408 gdouble value = private->progress_pulse_current;
3410 *x += (gint) floor(value * (*width));
3411 *width = (gint) ceil(private->progress_pulse_fraction * (*width));
3413 else if (private->progress_fraction > 0)
3415 gdouble value = private->progress_fraction;
3417 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
3421 bar_width = floor(value * (*width) + 0.5);
3422 *x += *width - bar_width;
3427 *width = (gint) floor(value * (*width) + 0.5);
3438 gtk_entry_draw_progress (GtkWidget *widget,
3441 gint x, y, width, height;
3444 get_progress_area (widget, &x, &y, &width, &height);
3446 if ((width <= 0) || (height <= 0))
3449 state = GTK_STATE_SELECTED;
3450 if (!gtk_widget_get_sensitive (widget))
3451 state = GTK_STATE_INSENSITIVE;
3453 gtk_paint_box (gtk_widget_get_style (widget), cr,
3454 state, GTK_SHADOW_OUT,
3455 widget, "entry-progress",
3461 gtk_entry_draw (GtkWidget *widget,
3464 GtkEntry *entry = GTK_ENTRY (widget);
3467 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3470 style = gtk_widget_get_style (widget);
3472 state = gtk_widget_has_focus (widget) ?
3473 GTK_STATE_ACTIVE : gtk_widget_get_state (widget);
3475 if (gtk_cairo_should_draw_window (cr, gtk_widget_get_window (widget)))
3477 /* Draw entry_bg, shadow, progress and focus */
3478 gtk_entry_draw_frame (widget, cr);
3480 /* Draw text and cursor */
3483 gtk_cairo_transform_to_window (cr, widget, entry->text_area);
3485 if (entry->dnd_position != -1)
3486 gtk_entry_draw_cursor (GTK_ENTRY (widget), cr, CURSOR_DND);
3488 gtk_entry_draw_text (GTK_ENTRY (widget), cr);
3490 /* When no text is being displayed at all, don't show the cursor */
3491 if (gtk_entry_get_display_mode (entry) != DISPLAY_BLANK &&
3492 gtk_widget_has_focus (widget) &&
3493 entry->selection_bound == entry->current_pos && entry->cursor_visible)
3494 gtk_entry_draw_cursor (GTK_ENTRY (widget), cr, CURSOR_STANDARD);
3499 for (i = 0; i < MAX_ICONS; i++)
3501 EntryIconInfo *icon_info = priv->icons[i];
3503 if (icon_info != NULL)
3507 gtk_cairo_transform_to_window (cr, widget, icon_info->window);
3509 draw_icon (widget, cr, i);
3520 gtk_entry_enter_notify (GtkWidget *widget,
3521 GdkEventCrossing *event)
3523 GtkEntry *entry = GTK_ENTRY (widget);
3524 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3527 for (i = 0; i < MAX_ICONS; i++)
3529 EntryIconInfo *icon_info = priv->icons[i];
3531 if (icon_info != NULL && event->window == icon_info->window)
3533 if (should_prelight (entry, i))
3535 icon_info->prelight = TRUE;
3536 gtk_widget_queue_draw (widget);
3547 gtk_entry_leave_notify (GtkWidget *widget,
3548 GdkEventCrossing *event)
3550 GtkEntry *entry = GTK_ENTRY (widget);
3551 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3554 for (i = 0; i < MAX_ICONS; i++)
3556 EntryIconInfo *icon_info = priv->icons[i];
3558 if (icon_info != NULL && event->window == icon_info->window)
3560 /* a grab means that we may never see the button release */
3561 if (event->mode == GDK_CROSSING_GRAB || event->mode == GDK_CROSSING_GTK_GRAB)
3562 icon_info->pressed = FALSE;
3564 if (should_prelight (entry, i))
3566 icon_info->prelight = FALSE;
3567 gtk_widget_queue_draw (widget);
3578 gtk_entry_get_pixel_ranges (GtkEntry *entry,
3582 gint start_char, end_char;
3584 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start_char, &end_char))
3586 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
3587 PangoLayoutLine *line = pango_layout_get_lines_readonly (layout)->data;
3588 const char *text = pango_layout_get_text (layout);
3589 gint start_index = g_utf8_offset_to_pointer (text, start_char) - text;
3590 gint end_index = g_utf8_offset_to_pointer (text, end_char) - text;
3591 gint real_n_ranges, i;
3593 pango_layout_line_get_x_ranges (line, start_index, end_index, ranges, &real_n_ranges);
3599 for (i = 0; i < real_n_ranges; ++i)
3601 r[2 * i + 1] = (r[2 * i + 1] - r[2 * i]) / PANGO_SCALE;
3602 r[2 * i] = r[2 * i] / PANGO_SCALE;
3607 *n_ranges = real_n_ranges;
3619 in_selection (GtkEntry *entry,
3624 gint retval = FALSE;
3626 gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
3628 for (i = 0; i < n_ranges; ++i)
3630 if (x >= ranges[2 * i] && x < ranges[2 * i] + ranges[2 * i + 1])
3642 gtk_entry_button_press (GtkWidget *widget,
3643 GdkEventButton *event)
3645 GtkEntry *entry = GTK_ENTRY (widget);
3646 GtkEditable *editable = GTK_EDITABLE (widget);
3647 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3648 EntryIconInfo *icon_info = NULL;
3650 gint sel_start, sel_end;
3653 for (i = 0; i < MAX_ICONS; i++)
3655 icon_info = priv->icons[i];
3657 if (!icon_info || icon_info->insensitive)
3660 if (event->window == icon_info->window)
3662 if (should_prelight (entry, i))
3664 icon_info->prelight = FALSE;
3665 gtk_widget_queue_draw (widget);
3668 priv->start_x = event->x;
3669 priv->start_y = event->y;
3670 icon_info->pressed = TRUE;
3672 if (!icon_info->nonactivatable)
3673 g_signal_emit (entry, signals[ICON_PRESS], 0, i, event);
3679 if (event->window != entry->text_area ||
3680 (entry->button && event->button != entry->button))
3683 gtk_entry_reset_blink_time (entry);
3685 entry->button = event->button;
3687 if (!gtk_widget_has_focus (widget))
3689 entry->in_click = TRUE;
3690 gtk_widget_grab_focus (widget);
3691 entry->in_click = FALSE;
3694 tmp_pos = gtk_entry_find_position (entry, event->x + entry->scroll_offset);
3696 if (event->button == 1)
3698 gboolean have_selection = gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end);
3700 entry->select_words = FALSE;
3701 entry->select_lines = FALSE;
3703 if (event->state & GDK_SHIFT_MASK)
3705 _gtk_entry_reset_im_context (entry);
3707 if (!have_selection) /* select from the current position to the clicked position */
3708 sel_start = sel_end = entry->current_pos;
3710 if (tmp_pos > sel_start && tmp_pos < sel_end)
3712 /* Truncate current selection, but keep it as big as possible */
3713 if (tmp_pos - sel_start > sel_end - tmp_pos)
3714 gtk_entry_set_positions (entry, sel_start, tmp_pos);
3716 gtk_entry_set_positions (entry, tmp_pos, sel_end);
3720 gboolean extend_to_left;
3723 /* Figure out what click selects and extend current selection */
3724 switch (event->type)
3726 case GDK_BUTTON_PRESS:
3727 gtk_entry_set_positions (entry, tmp_pos, tmp_pos);
3730 case GDK_2BUTTON_PRESS:
3731 entry->select_words = TRUE;
3732 gtk_entry_select_word (entry);
3735 case GDK_3BUTTON_PRESS:
3736 entry->select_lines = TRUE;
3737 gtk_entry_select_line (entry);
3744 start = MIN (entry->current_pos, entry->selection_bound);
3745 start = MIN (sel_start, start);
3747 end = MAX (entry->current_pos, entry->selection_bound);
3748 end = MAX (sel_end, end);
3750 if (tmp_pos == sel_start || tmp_pos == sel_end)
3751 extend_to_left = (tmp_pos == start);
3753 extend_to_left = (end == sel_end);
3756 gtk_entry_set_positions (entry, start, end);
3758 gtk_entry_set_positions (entry, end, start);
3761 else /* no shift key */
3762 switch (event->type)
3764 case GDK_BUTTON_PRESS:
3765 if (in_selection (entry, event->x + entry->scroll_offset))
3767 /* Click inside the selection - we'll either start a drag, or
3768 * clear the selection
3770 entry->in_drag = TRUE;
3771 entry->drag_start_x = event->x + entry->scroll_offset;
3772 entry->drag_start_y = event->y;
3775 gtk_editable_set_position (editable, tmp_pos);
3778 case GDK_2BUTTON_PRESS:
3779 /* We ALWAYS receive a GDK_BUTTON_PRESS immediately before
3780 * receiving a GDK_2BUTTON_PRESS so we need to reset
3781 * entry->in_drag which may have been set above
3783 entry->in_drag = FALSE;
3784 entry->select_words = TRUE;
3785 gtk_entry_select_word (entry);
3788 case GDK_3BUTTON_PRESS:
3789 /* We ALWAYS receive a GDK_BUTTON_PRESS immediately before
3790 * receiving a GDK_3BUTTON_PRESS so we need to reset
3791 * entry->in_drag which may have been set above
3793 entry->in_drag = FALSE;
3794 entry->select_lines = TRUE;
3795 gtk_entry_select_line (entry);
3804 else if (event->button == 2 && event->type == GDK_BUTTON_PRESS)
3806 if (entry->editable)
3808 priv->insert_pos = tmp_pos;
3809 gtk_entry_paste (entry, GDK_SELECTION_PRIMARY);
3814 gtk_widget_error_bell (widget);
3817 else if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
3819 gtk_entry_do_popup (entry, event);
3820 entry->button = 0; /* Don't wait for release, since the menu will gtk_grab_add */
3829 gtk_entry_button_release (GtkWidget *widget,
3830 GdkEventButton *event)
3832 GtkEntry *entry = GTK_ENTRY (widget);
3833 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
3834 EntryIconInfo *icon_info = NULL;
3837 for (i = 0; i < MAX_ICONS; i++)
3839 icon_info = priv->icons[i];
3841 if (!icon_info || icon_info->insensitive)
3844 if (event->window == icon_info->window)
3846 icon_info->pressed = FALSE;
3848 if (should_prelight (entry, i) &&
3849 event->x >= 0 && event->y >= 0 &&
3850 event->x < gdk_window_get_width (icon_info->window) &&
3851 event->y < gdk_window_get_height (icon_info->window))
3853 icon_info->prelight = TRUE;
3854 gtk_widget_queue_draw (widget);
3857 if (!icon_info->nonactivatable)
3858 g_signal_emit (entry, signals[ICON_RELEASE], 0, i, event);
3864 if (event->window != entry->text_area || entry->button != event->button)
3869 gint tmp_pos = gtk_entry_find_position (entry, entry->drag_start_x);
3871 gtk_editable_set_position (GTK_EDITABLE (entry), tmp_pos);
3878 gtk_entry_update_primary_selection (entry);
3884 _gtk_entry_get_selected_text (GtkEntry *entry)
3886 GtkEditable *editable = GTK_EDITABLE (entry);
3887 gint start_text, end_text;
3890 if (gtk_editable_get_selection_bounds (editable, &start_text, &end_text))
3891 text = gtk_editable_get_chars (editable, start_text, end_text);
3897 gtk_entry_motion_notify (GtkWidget *widget,
3898 GdkEventMotion *event)
3900 GtkEntry *entry = GTK_ENTRY (widget);
3901 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3902 EntryIconInfo *icon_info = NULL;
3903 GdkDragContext *context;
3907 for (i = 0; i < MAX_ICONS; i++)
3909 icon_info = priv->icons[i];
3911 if (!icon_info || icon_info->insensitive)
3914 if (event->window == icon_info->window)
3916 if (icon_info->pressed &&
3917 icon_info->target_list != NULL &&
3918 gtk_drag_check_threshold (widget,
3924 icon_info->in_drag = TRUE;
3925 icon_info->pressed = FALSE;
3926 context = gtk_drag_begin (widget,
3927 icon_info->target_list,
3937 if (entry->mouse_cursor_obscured)
3941 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
3942 gdk_window_set_cursor (entry->text_area, cursor);
3943 gdk_cursor_unref (cursor);
3944 entry->mouse_cursor_obscured = FALSE;
3947 if (event->window != entry->text_area || entry->button != 1)
3950 if (entry->select_lines)
3953 gdk_event_request_motions (event);
3957 if (gtk_entry_get_display_mode (entry) == DISPLAY_NORMAL &&
3958 gtk_drag_check_threshold (widget,
3959 entry->drag_start_x, entry->drag_start_y,
3960 event->x + entry->scroll_offset, event->y))
3962 GdkDragContext *context;
3963 GtkTargetList *target_list = gtk_target_list_new (NULL, 0);
3964 guint actions = entry->editable ? GDK_ACTION_COPY | GDK_ACTION_MOVE : GDK_ACTION_COPY;
3966 cairo_surface_t *surface;
3968 gtk_target_list_add_text_targets (target_list, 0);
3970 text = _gtk_entry_get_selected_text (entry);
3971 surface = _gtk_text_util_create_drag_icon (widget, text, -1);
3973 context = gtk_drag_begin (widget, target_list, actions,
3974 entry->button, (GdkEvent *)event);
3977 gtk_drag_set_icon_surface (context, surface);
3979 gtk_drag_set_icon_default (context);
3982 cairo_surface_destroy (surface);
3985 entry->in_drag = FALSE;
3988 gtk_target_list_unref (target_list);
3995 else if (event->y >= gdk_window_get_height (entry->text_area))
3996 tmp_pos = gtk_entry_buffer_get_length (get_buffer (entry));
3998 tmp_pos = gtk_entry_find_position (entry, event->x + entry->scroll_offset);
4000 if (entry->select_words)
4003 gint old_min, old_max;
4006 min = gtk_entry_move_backward_word (entry, tmp_pos, TRUE);
4007 max = gtk_entry_move_forward_word (entry, tmp_pos, TRUE);
4009 pos = entry->current_pos;
4010 bound = entry->selection_bound;
4012 old_min = MIN(entry->current_pos, entry->selection_bound);
4013 old_max = MAX(entry->current_pos, entry->selection_bound);
4020 else if (old_max < max)
4025 else if (pos == old_min)
4027 if (entry->current_pos != min)
4032 if (entry->current_pos != max)
4036 gtk_entry_set_positions (entry, pos, bound);
4039 gtk_entry_set_positions (entry, tmp_pos, -1);
4046 set_invisible_cursor (GdkWindow *window)
4048 GdkDisplay *display;
4051 display = gdk_window_get_display (window);
4052 cursor = gdk_cursor_new_for_display (display, GDK_BLANK_CURSOR);
4054 gdk_window_set_cursor (window, cursor);
4056 gdk_cursor_unref (cursor);
4060 gtk_entry_obscure_mouse_cursor (GtkEntry *entry)
4062 if (entry->mouse_cursor_obscured)
4065 set_invisible_cursor (entry->text_area);
4067 entry->mouse_cursor_obscured = TRUE;
4071 gtk_entry_key_press (GtkWidget *widget,
4074 GtkEntry *entry = GTK_ENTRY (widget);
4076 gtk_entry_reset_blink_time (entry);
4077 gtk_entry_pend_cursor_blink (entry);
4079 if (entry->editable)
4081 if (gtk_im_context_filter_keypress (entry->im_context, event))
4083 gtk_entry_obscure_mouse_cursor (entry);
4084 entry->need_im_reset = TRUE;
4089 if (event->keyval == GDK_KEY_Return ||
4090 event->keyval == GDK_KEY_KP_Enter ||
4091 event->keyval == GDK_KEY_ISO_Enter ||
4092 event->keyval == GDK_KEY_Escape)
4094 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
4096 if (completion && completion->priv->completion_timeout)
4098 g_source_remove (completion->priv->completion_timeout);
4099 completion->priv->completion_timeout = 0;
4102 _gtk_entry_reset_im_context (entry);
4105 if (GTK_WIDGET_CLASS (gtk_entry_parent_class)->key_press_event (widget, event))
4106 /* Activate key bindings
4110 if (!entry->editable && event->length)
4111 gtk_widget_error_bell (widget);
4117 gtk_entry_key_release (GtkWidget *widget,
4120 GtkEntry *entry = GTK_ENTRY (widget);
4122 if (entry->editable)
4124 if (gtk_im_context_filter_keypress (entry->im_context, event))
4126 entry->need_im_reset = TRUE;
4131 return GTK_WIDGET_CLASS (gtk_entry_parent_class)->key_release_event (widget, event);
4135 gtk_entry_focus_in (GtkWidget *widget,
4136 GdkEventFocus *event)
4138 GtkEntry *entry = GTK_ENTRY (widget);
4141 gtk_widget_queue_draw (widget);
4143 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (widget));
4145 if (entry->editable)
4147 entry->need_im_reset = TRUE;
4148 gtk_im_context_focus_in (entry->im_context);
4149 keymap_state_changed (keymap, entry);
4150 g_signal_connect (keymap, "state-changed",
4151 G_CALLBACK (keymap_state_changed), entry);
4154 g_signal_connect (keymap, "direction-changed",
4155 G_CALLBACK (keymap_direction_changed), entry);
4157 gtk_entry_reset_blink_time (entry);
4158 gtk_entry_check_cursor_blink (entry);
4164 gtk_entry_focus_out (GtkWidget *widget,
4165 GdkEventFocus *event)
4167 GtkEntry *entry = GTK_ENTRY (widget);
4168 GtkEntryCompletion *completion;
4171 gtk_widget_queue_draw (widget);
4173 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (widget));
4175 if (entry->editable)
4177 entry->need_im_reset = TRUE;
4178 gtk_im_context_focus_out (entry->im_context);
4179 remove_capslock_feedback (entry);
4182 gtk_entry_check_cursor_blink (entry);
4184 g_signal_handlers_disconnect_by_func (keymap, keymap_state_changed, entry);
4185 g_signal_handlers_disconnect_by_func (keymap, keymap_direction_changed, entry);
4187 completion = gtk_entry_get_completion (entry);
4189 _gtk_entry_completion_popdown (completion);
4195 gtk_entry_grab_focus (GtkWidget *widget)
4197 GtkEntry *entry = GTK_ENTRY (widget);
4198 gboolean select_on_focus;
4200 GTK_WIDGET_CLASS (gtk_entry_parent_class)->grab_focus (widget);
4202 if (entry->editable && !entry->in_click)
4204 g_object_get (gtk_widget_get_settings (widget),
4205 "gtk-entry-select-on-focus",
4209 if (select_on_focus)
4210 gtk_editable_select_region (GTK_EDITABLE (widget), 0, -1);
4215 gtk_entry_direction_changed (GtkWidget *widget,
4216 GtkTextDirection previous_dir)
4218 GtkEntry *entry = GTK_ENTRY (widget);
4220 gtk_entry_recompute (entry);
4222 GTK_WIDGET_CLASS (gtk_entry_parent_class)->direction_changed (widget, previous_dir);
4226 gtk_entry_state_changed (GtkWidget *widget,
4227 GtkStateType previous_state)
4229 GtkEntry *entry = GTK_ENTRY (widget);
4232 if (gtk_widget_get_realized (widget))
4234 if (gtk_widget_is_sensitive (widget))
4235 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
4239 gdk_window_set_cursor (entry->text_area, cursor);
4242 gdk_cursor_unref (cursor);
4244 entry->mouse_cursor_obscured = FALSE;
4246 update_cursors (widget);
4249 if (!gtk_widget_is_sensitive (widget))
4251 /* Clear any selection */
4252 gtk_editable_select_region (GTK_EDITABLE (entry), entry->current_pos, entry->current_pos);
4255 gtk_widget_queue_draw (widget);
4259 gtk_entry_screen_changed (GtkWidget *widget,
4260 GdkScreen *old_screen)
4262 gtk_entry_recompute (GTK_ENTRY (widget));
4265 /* GtkEditable method implementations
4268 gtk_entry_insert_text (GtkEditable *editable,
4269 const gchar *new_text,
4270 gint new_text_length,
4273 g_object_ref (editable);
4276 * The incoming text may a password or other secret. We make sure
4277 * not to copy it into temporary buffers.
4280 g_signal_emit_by_name (editable, "insert-text", new_text, new_text_length, position);
4282 g_object_unref (editable);
4286 gtk_entry_delete_text (GtkEditable *editable,
4290 g_object_ref (editable);
4292 g_signal_emit_by_name (editable, "delete-text", start_pos, end_pos);
4294 g_object_unref (editable);
4298 gtk_entry_get_chars (GtkEditable *editable,
4302 GtkEntry *entry = GTK_ENTRY (editable);
4305 gint start_index, end_index;
4307 text = gtk_entry_buffer_get_text (get_buffer (entry));
4308 text_length = gtk_entry_buffer_get_length (get_buffer (entry));
4311 end_pos = text_length;
4313 start_pos = MIN (text_length, start_pos);
4314 end_pos = MIN (text_length, end_pos);
4316 start_index = g_utf8_offset_to_pointer (text, start_pos) - text;
4317 end_index = g_utf8_offset_to_pointer (text, end_pos) - text;
4319 return g_strndup (text + start_index, end_index - start_index);
4323 gtk_entry_real_set_position (GtkEditable *editable,
4326 GtkEntry *entry = GTK_ENTRY (editable);
4330 length = gtk_entry_buffer_get_length (get_buffer (entry));
4331 if (position < 0 || position > length)
4334 if (position != entry->current_pos ||
4335 position != entry->selection_bound)
4337 _gtk_entry_reset_im_context (entry);
4338 gtk_entry_set_positions (entry, position, position);
4343 gtk_entry_get_position (GtkEditable *editable)
4345 return GTK_ENTRY (editable)->current_pos;
4349 gtk_entry_set_selection_bounds (GtkEditable *editable,
4353 GtkEntry *entry = GTK_ENTRY (editable);
4356 length = gtk_entry_buffer_get_length (get_buffer (entry));
4362 _gtk_entry_reset_im_context (entry);
4364 gtk_entry_set_positions (entry,
4366 MIN (start, length));
4368 gtk_entry_update_primary_selection (entry);
4372 gtk_entry_get_selection_bounds (GtkEditable *editable,
4376 GtkEntry *entry = GTK_ENTRY (editable);
4378 *start = entry->selection_bound;
4379 *end = entry->current_pos;
4381 return (entry->selection_bound != entry->current_pos);
4385 icon_theme_changed (GtkEntry *entry)
4387 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
4390 for (i = 0; i < MAX_ICONS; i++)
4392 EntryIconInfo *icon_info = priv->icons[i];
4393 if (icon_info != NULL)
4395 if (icon_info->storage_type == GTK_IMAGE_ICON_NAME)
4396 gtk_entry_set_icon_from_icon_name (entry, i, icon_info->icon_name);
4397 else if (icon_info->storage_type == GTK_IMAGE_STOCK)
4398 gtk_entry_set_icon_from_stock (entry, i, icon_info->stock_id);
4399 else if (icon_info->storage_type == GTK_IMAGE_GICON)
4400 gtk_entry_set_icon_from_gicon (entry, i, icon_info->gicon);
4404 gtk_widget_queue_draw (GTK_WIDGET (entry));
4408 icon_margin_changed (GtkEntry *entry)
4410 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
4413 _gtk_entry_effective_inner_border (GTK_ENTRY (entry), &border);
4415 priv->icon_margin = border.left;
4419 gtk_entry_style_set (GtkWidget *widget,
4420 GtkStyle *previous_style)
4422 GtkEntry *entry = GTK_ENTRY (widget);
4423 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
4425 gboolean interior_focus;
4427 gtk_widget_style_get (widget,
4428 "focus-line-width", &focus_width,
4429 "interior-focus", &interior_focus,
4432 priv->focus_width = focus_width;
4433 priv->interior_focus = interior_focus;
4435 if (!priv->invisible_char_set)
4436 entry->invisible_char = find_invisible_char (GTK_WIDGET (entry));
4438 gtk_entry_recompute (entry);
4440 icon_theme_changed (entry);
4441 icon_margin_changed (entry);
4444 /* GtkCellEditable method implementations
4447 gtk_cell_editable_entry_activated (GtkEntry *entry, gpointer data)
4449 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4450 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4454 gtk_cell_editable_key_press_event (GtkEntry *entry,
4455 GdkEventKey *key_event,
4458 if (key_event->keyval == GDK_KEY_Escape)
4460 entry->editing_canceled = TRUE;
4461 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4462 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4467 /* override focus */
4468 if (key_event->keyval == GDK_KEY_Up || key_event->keyval == GDK_KEY_Down)
4470 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4471 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4480 gtk_entry_start_editing (GtkCellEditable *cell_editable,
4483 GTK_ENTRY (cell_editable)->is_cell_renderer = TRUE;
4485 g_signal_connect (cell_editable, "activate",
4486 G_CALLBACK (gtk_cell_editable_entry_activated), NULL);
4487 g_signal_connect (cell_editable, "key-press-event",
4488 G_CALLBACK (gtk_cell_editable_key_press_event), NULL);
4492 gtk_entry_password_hint_free (GtkEntryPasswordHint *password_hint)
4494 if (password_hint->source_id)
4495 g_source_remove (password_hint->source_id);
4497 g_slice_free (GtkEntryPasswordHint, password_hint);
4502 gtk_entry_remove_password_hint (gpointer data)
4504 GtkEntryPasswordHint *password_hint = g_object_get_qdata (data, quark_password_hint);
4505 password_hint->position = -1;
4507 /* Force the string to be redrawn, but now without a visible character */
4508 gtk_entry_recompute (GTK_ENTRY (data));
4512 /* Default signal handlers
4515 gtk_entry_real_insert_text (GtkEditable *editable,
4516 const gchar *new_text,
4517 gint new_text_length,
4523 n_chars = g_utf8_strlen (new_text, new_text_length);
4526 * The actual insertion into the buffer. This will end up firing the
4527 * following signal handlers: buffer_inserted_text(), buffer_notify_display_text(),
4528 * buffer_notify_text(), buffer_notify_length()
4530 n_inserted = gtk_entry_buffer_insert_text (get_buffer (GTK_ENTRY (editable)), *position, new_text, n_chars);
4532 if (n_inserted != n_chars)
4533 gtk_widget_error_bell (GTK_WIDGET (editable));
4535 *position += n_inserted;
4539 gtk_entry_real_delete_text (GtkEditable *editable,
4544 * The actual deletion from the buffer. This will end up firing the
4545 * following signal handlers: buffer_deleted_text(), buffer_notify_display_text(),
4546 * buffer_notify_text(), buffer_notify_length()
4549 gtk_entry_buffer_delete_text (get_buffer (GTK_ENTRY (editable)), start_pos, end_pos - start_pos);
4552 /* GtkEntryBuffer signal handlers
4555 buffer_inserted_text (GtkEntryBuffer *buffer,
4561 guint password_hint_timeout;
4563 if (entry->current_pos > position)
4564 entry->current_pos += n_chars;
4566 if (entry->selection_bound > position)
4567 entry->selection_bound += n_chars;
4569 /* Calculate the password hint if it needs to be displayed. */
4570 if (n_chars == 1 && !entry->visible)
4572 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
4573 "gtk-entry-password-hint-timeout", &password_hint_timeout,
4576 if (password_hint_timeout > 0)
4578 GtkEntryPasswordHint *password_hint = g_object_get_qdata (G_OBJECT (entry),
4579 quark_password_hint);
4582 password_hint = g_slice_new0 (GtkEntryPasswordHint);
4583 g_object_set_qdata_full (G_OBJECT (entry), quark_password_hint, password_hint,
4584 (GDestroyNotify)gtk_entry_password_hint_free);
4587 password_hint->position = position;
4588 if (password_hint->source_id)
4589 g_source_remove (password_hint->source_id);
4590 password_hint->source_id = gdk_threads_add_timeout (password_hint_timeout,
4591 (GSourceFunc)gtk_entry_remove_password_hint, entry);
4597 buffer_deleted_text (GtkEntryBuffer *buffer,
4602 guint end_pos = position + n_chars;
4603 gint selection_bound;
4606 current_pos = entry->current_pos;
4607 if (current_pos > position)
4608 current_pos -= MIN (current_pos, end_pos) - position;
4610 selection_bound = entry->selection_bound;
4611 if (selection_bound > position)
4612 selection_bound -= MIN (selection_bound, end_pos) - position;
4614 gtk_entry_set_positions (entry, current_pos, selection_bound);
4616 /* We might have deleted the selection */
4617 gtk_entry_update_primary_selection (entry);
4619 /* Disable the password hint if one exists. */
4620 if (!entry->visible)
4622 GtkEntryPasswordHint *password_hint = g_object_get_qdata (G_OBJECT (entry),
4623 quark_password_hint);
4626 if (password_hint->source_id)
4627 g_source_remove (password_hint->source_id);
4628 password_hint->source_id = 0;
4629 password_hint->position = -1;
4635 buffer_notify_text (GtkEntryBuffer *buffer,
4639 gtk_entry_recompute (entry);
4640 emit_changed (entry);
4641 g_object_notify (G_OBJECT (entry), "text");
4645 buffer_notify_length (GtkEntryBuffer *buffer,
4649 g_object_notify (G_OBJECT (entry), "text-length");
4653 buffer_notify_max_length (GtkEntryBuffer *buffer,
4657 g_object_notify (G_OBJECT (entry), "max-length");
4661 buffer_connect_signals (GtkEntry *entry)
4663 g_signal_connect (get_buffer (entry), "inserted-text", G_CALLBACK (buffer_inserted_text), entry);
4664 g_signal_connect (get_buffer (entry), "deleted-text", G_CALLBACK (buffer_deleted_text), entry);
4665 g_signal_connect (get_buffer (entry), "notify::text", G_CALLBACK (buffer_notify_text), entry);
4666 g_signal_connect (get_buffer (entry), "notify::length", G_CALLBACK (buffer_notify_length), entry);
4667 g_signal_connect (get_buffer (entry), "notify::max-length", G_CALLBACK (buffer_notify_max_length), entry);
4671 buffer_disconnect_signals (GtkEntry *entry)
4673 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_inserted_text, entry);
4674 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_deleted_text, entry);
4675 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_text, entry);
4676 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_length, entry);
4677 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_max_length, entry);
4680 /* Compute the X position for an offset that corresponds to the "more important
4681 * cursor position for that offset. We use this when trying to guess to which
4682 * end of the selection we should go to when the user hits the left or
4686 get_better_cursor_x (GtkEntry *entry,
4689 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
4690 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
4691 gboolean split_cursor;
4693 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
4694 const gchar *text = pango_layout_get_text (layout);
4695 gint index = g_utf8_offset_to_pointer (text, offset) - text;
4697 PangoRectangle strong_pos, weak_pos;
4699 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
4700 "gtk-split-cursor", &split_cursor,
4703 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
4706 return strong_pos.x / PANGO_SCALE;
4708 return (keymap_direction == entry->resolved_dir) ? strong_pos.x / PANGO_SCALE : weak_pos.x / PANGO_SCALE;
4712 gtk_entry_move_cursor (GtkEntry *entry,
4713 GtkMovementStep step,
4715 gboolean extend_selection)
4717 gint new_pos = entry->current_pos;
4718 GtkEntryPrivate *priv;
4720 _gtk_entry_reset_im_context (entry);
4722 if (entry->current_pos != entry->selection_bound && !extend_selection)
4724 /* If we have a current selection and aren't extending it, move to the
4725 * start/or end of the selection as appropriate
4729 case GTK_MOVEMENT_VISUAL_POSITIONS:
4731 gint current_x = get_better_cursor_x (entry, entry->current_pos);
4732 gint bound_x = get_better_cursor_x (entry, entry->selection_bound);
4735 new_pos = current_x < bound_x ? entry->current_pos : entry->selection_bound;
4737 new_pos = current_x > bound_x ? entry->current_pos : entry->selection_bound;
4740 case GTK_MOVEMENT_LOGICAL_POSITIONS:
4741 case GTK_MOVEMENT_WORDS:
4743 new_pos = MIN (entry->current_pos, entry->selection_bound);
4745 new_pos = MAX (entry->current_pos, entry->selection_bound);
4747 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
4748 case GTK_MOVEMENT_PARAGRAPH_ENDS:
4749 case GTK_MOVEMENT_BUFFER_ENDS:
4750 priv = GTK_ENTRY_GET_PRIVATE (entry);
4751 new_pos = count < 0 ? 0 : gtk_entry_buffer_get_length (get_buffer (entry));
4753 case GTK_MOVEMENT_DISPLAY_LINES:
4754 case GTK_MOVEMENT_PARAGRAPHS:
4755 case GTK_MOVEMENT_PAGES:
4756 case GTK_MOVEMENT_HORIZONTAL_PAGES:
4764 case GTK_MOVEMENT_LOGICAL_POSITIONS:
4765 new_pos = gtk_entry_move_logically (entry, new_pos, count);
4767 case GTK_MOVEMENT_VISUAL_POSITIONS:
4768 new_pos = gtk_entry_move_visually (entry, new_pos, count);
4769 if (entry->current_pos == new_pos)
4771 if (!extend_selection)
4773 if (!gtk_widget_keynav_failed (GTK_WIDGET (entry),
4775 GTK_DIR_RIGHT : GTK_DIR_LEFT))
4777 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (entry));
4780 gtk_widget_child_focus (toplevel,
4782 GTK_DIR_RIGHT : GTK_DIR_LEFT);
4787 gtk_widget_error_bell (GTK_WIDGET (entry));
4791 case GTK_MOVEMENT_WORDS:
4794 new_pos = gtk_entry_move_forward_word (entry, new_pos, FALSE);
4799 new_pos = gtk_entry_move_backward_word (entry, new_pos, FALSE);
4802 if (entry->current_pos == new_pos)
4803 gtk_widget_error_bell (GTK_WIDGET (entry));
4805 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
4806 case GTK_MOVEMENT_PARAGRAPH_ENDS:
4807 case GTK_MOVEMENT_BUFFER_ENDS:
4808 priv = GTK_ENTRY_GET_PRIVATE (entry);
4809 new_pos = count < 0 ? 0 : gtk_entry_buffer_get_length (get_buffer (entry));
4810 if (entry->current_pos == new_pos)
4811 gtk_widget_error_bell (GTK_WIDGET (entry));
4813 case GTK_MOVEMENT_DISPLAY_LINES:
4814 case GTK_MOVEMENT_PARAGRAPHS:
4815 case GTK_MOVEMENT_PAGES:
4816 case GTK_MOVEMENT_HORIZONTAL_PAGES:
4821 if (extend_selection)
4822 gtk_editable_select_region (GTK_EDITABLE (entry), entry->selection_bound, new_pos);
4824 gtk_editable_set_position (GTK_EDITABLE (entry), new_pos);
4826 gtk_entry_pend_cursor_blink (entry);
4830 gtk_entry_insert_at_cursor (GtkEntry *entry,
4833 GtkEditable *editable = GTK_EDITABLE (entry);
4834 gint pos = entry->current_pos;
4836 if (entry->editable)
4838 _gtk_entry_reset_im_context (entry);
4840 gtk_editable_insert_text (editable, str, -1, &pos);
4841 gtk_editable_set_position (editable, pos);
4846 gtk_entry_delete_from_cursor (GtkEntry *entry,
4850 GtkEditable *editable = GTK_EDITABLE (entry);
4851 gint start_pos = entry->current_pos;
4852 gint end_pos = entry->current_pos;
4853 gint old_n_bytes = gtk_entry_buffer_get_bytes (get_buffer (entry));
4855 _gtk_entry_reset_im_context (entry);
4857 if (!entry->editable)
4859 gtk_widget_error_bell (GTK_WIDGET (entry));
4863 if (entry->selection_bound != entry->current_pos)
4865 gtk_editable_delete_selection (editable);
4871 case GTK_DELETE_CHARS:
4872 end_pos = gtk_entry_move_logically (entry, entry->current_pos, count);
4873 gtk_editable_delete_text (editable, MIN (start_pos, end_pos), MAX (start_pos, end_pos));
4875 case GTK_DELETE_WORDS:
4878 /* Move to end of current word, or if not on a word, end of previous word */
4879 end_pos = gtk_entry_move_backward_word (entry, end_pos, FALSE);
4880 end_pos = gtk_entry_move_forward_word (entry, end_pos, FALSE);
4884 /* Move to beginning of current word, or if not on a word, begining of next word */
4885 start_pos = gtk_entry_move_forward_word (entry, start_pos, FALSE);
4886 start_pos = gtk_entry_move_backward_word (entry, start_pos, FALSE);
4890 case GTK_DELETE_WORD_ENDS:
4893 start_pos = gtk_entry_move_backward_word (entry, start_pos, FALSE);
4898 end_pos = gtk_entry_move_forward_word (entry, end_pos, FALSE);
4901 gtk_editable_delete_text (editable, start_pos, end_pos);
4903 case GTK_DELETE_DISPLAY_LINE_ENDS:
4904 case GTK_DELETE_PARAGRAPH_ENDS:
4906 gtk_editable_delete_text (editable, 0, entry->current_pos);
4908 gtk_editable_delete_text (editable, entry->current_pos, -1);
4910 case GTK_DELETE_DISPLAY_LINES:
4911 case GTK_DELETE_PARAGRAPHS:
4912 gtk_editable_delete_text (editable, 0, -1);
4914 case GTK_DELETE_WHITESPACE:
4915 gtk_entry_delete_whitespace (entry);
4919 if (gtk_entry_buffer_get_bytes (get_buffer (entry)) == old_n_bytes)
4920 gtk_widget_error_bell (GTK_WIDGET (entry));
4922 gtk_entry_pend_cursor_blink (entry);
4926 gtk_entry_backspace (GtkEntry *entry)
4928 GtkEditable *editable = GTK_EDITABLE (entry);
4931 _gtk_entry_reset_im_context (entry);
4933 if (!entry->editable)
4935 gtk_widget_error_bell (GTK_WIDGET (entry));
4939 if (entry->selection_bound != entry->current_pos)
4941 gtk_editable_delete_selection (editable);
4945 prev_pos = gtk_entry_move_logically (entry, entry->current_pos, -1);
4947 if (prev_pos < entry->current_pos)
4949 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
4950 PangoLogAttr *log_attrs;
4953 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
4955 /* Deleting parts of characters */
4956 if (log_attrs[entry->current_pos].backspace_deletes_character)
4958 gchar *cluster_text;
4959 gchar *normalized_text;
4962 cluster_text = gtk_entry_get_display_text (entry, prev_pos,
4963 entry->current_pos);
4964 normalized_text = g_utf8_normalize (cluster_text,
4965 strlen (cluster_text),
4967 len = g_utf8_strlen (normalized_text, -1);
4969 gtk_editable_delete_text (editable, prev_pos, entry->current_pos);
4972 gint pos = entry->current_pos;
4974 gtk_editable_insert_text (editable, normalized_text,
4975 g_utf8_offset_to_pointer (normalized_text, len - 1) - normalized_text,
4977 gtk_editable_set_position (editable, pos);
4980 g_free (normalized_text);
4981 g_free (cluster_text);
4985 gtk_editable_delete_text (editable, prev_pos, entry->current_pos);
4992 gtk_widget_error_bell (GTK_WIDGET (entry));
4995 gtk_entry_pend_cursor_blink (entry);
4999 gtk_entry_copy_clipboard (GtkEntry *entry)
5001 GtkEditable *editable = GTK_EDITABLE (entry);
5005 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5007 if (!entry->visible)
5009 gtk_widget_error_bell (GTK_WIDGET (entry));
5013 str = gtk_entry_get_display_text (entry, start, end);
5014 gtk_clipboard_set_text (gtk_widget_get_clipboard (GTK_WIDGET (entry),
5015 GDK_SELECTION_CLIPBOARD),
5022 gtk_entry_cut_clipboard (GtkEntry *entry)
5024 GtkEditable *editable = GTK_EDITABLE (entry);
5027 if (!entry->visible)
5029 gtk_widget_error_bell (GTK_WIDGET (entry));
5033 gtk_entry_copy_clipboard (entry);
5035 if (entry->editable)
5037 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5038 gtk_editable_delete_text (editable, start, end);
5042 gtk_widget_error_bell (GTK_WIDGET (entry));
5047 gtk_entry_paste_clipboard (GtkEntry *entry)
5049 if (entry->editable)
5050 gtk_entry_paste (entry, GDK_NONE);
5052 gtk_widget_error_bell (GTK_WIDGET (entry));
5056 gtk_entry_delete_cb (GtkEntry *entry)
5058 GtkEditable *editable = GTK_EDITABLE (entry);
5061 if (entry->editable)
5063 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5064 gtk_editable_delete_text (editable, start, end);
5069 gtk_entry_toggle_overwrite (GtkEntry *entry)
5071 entry->overwrite_mode = !entry->overwrite_mode;
5072 gtk_entry_pend_cursor_blink (entry);
5073 gtk_widget_queue_draw (GTK_WIDGET (entry));
5077 gtk_entry_select_all (GtkEntry *entry)
5079 gtk_entry_select_line (entry);
5083 gtk_entry_real_activate (GtkEntry *entry)
5086 GtkWidget *default_widget, *focus_widget;
5087 GtkWidget *toplevel;
5090 widget = GTK_WIDGET (entry);
5092 if (entry->activates_default)
5094 toplevel = gtk_widget_get_toplevel (widget);
5095 if (GTK_IS_WINDOW (toplevel))
5097 window = GTK_WINDOW (toplevel);
5101 default_widget = gtk_window_get_default_widget (window);
5102 focus_widget = gtk_window_get_focus (window);
5103 if (widget != default_widget &&
5104 !(widget == focus_widget && (!default_widget || !gtk_widget_get_sensitive (default_widget))))
5105 gtk_window_activate_default (window);
5112 keymap_direction_changed (GdkKeymap *keymap,
5115 gtk_entry_recompute (entry);
5118 /* IM Context Callbacks
5122 gtk_entry_commit_cb (GtkIMContext *context,
5126 if (entry->editable)
5127 gtk_entry_enter_text (entry, str);
5131 gtk_entry_preedit_changed_cb (GtkIMContext *context,
5134 if (entry->editable)
5136 gchar *preedit_string;
5139 gtk_im_context_get_preedit_string (entry->im_context,
5140 &preedit_string, NULL,
5142 g_signal_emit (entry, signals[PREEDIT_CHANGED], 0, preedit_string);
5143 entry->preedit_length = strlen (preedit_string);
5144 cursor_pos = CLAMP (cursor_pos, 0, g_utf8_strlen (preedit_string, -1));
5145 entry->preedit_cursor = cursor_pos;
5146 g_free (preedit_string);
5148 gtk_entry_recompute (entry);
5153 gtk_entry_retrieve_surrounding_cb (GtkIMContext *context,
5158 /* XXXX ??? does this even make sense when text is not visible? Should we return FALSE? */
5159 text = gtk_entry_get_display_text (entry, 0, -1);
5160 gtk_im_context_set_surrounding (context, text, strlen (text), /* Length in bytes */
5161 g_utf8_offset_to_pointer (text, entry->current_pos) - text);
5168 gtk_entry_delete_surrounding_cb (GtkIMContext *slave,
5173 if (entry->editable)
5174 gtk_editable_delete_text (GTK_EDITABLE (entry),
5175 entry->current_pos + offset,
5176 entry->current_pos + offset + n_chars);
5181 /* Internal functions
5184 /* Used for im_commit_cb and inserting Unicode chars */
5186 gtk_entry_enter_text (GtkEntry *entry,
5189 GtkEditable *editable = GTK_EDITABLE (entry);
5191 gboolean old_need_im_reset;
5193 old_need_im_reset = entry->need_im_reset;
5194 entry->need_im_reset = FALSE;
5196 if (gtk_editable_get_selection_bounds (editable, NULL, NULL))
5197 gtk_editable_delete_selection (editable);
5200 if (entry->overwrite_mode)
5201 gtk_entry_delete_from_cursor (entry, GTK_DELETE_CHARS, 1);
5204 tmp_pos = entry->current_pos;
5205 gtk_editable_insert_text (editable, str, strlen (str), &tmp_pos);
5206 gtk_editable_set_position (editable, tmp_pos);
5208 entry->need_im_reset = old_need_im_reset;
5211 /* All changes to entry->current_pos and entry->selection_bound
5212 * should go through this function.
5215 gtk_entry_set_positions (GtkEntry *entry,
5217 gint selection_bound)
5219 gboolean changed = FALSE;
5221 g_object_freeze_notify (G_OBJECT (entry));
5223 if (current_pos != -1 &&
5224 entry->current_pos != current_pos)
5226 entry->current_pos = current_pos;
5229 g_object_notify (G_OBJECT (entry), "cursor-position");
5232 if (selection_bound != -1 &&
5233 entry->selection_bound != selection_bound)
5235 entry->selection_bound = selection_bound;
5238 g_object_notify (G_OBJECT (entry), "selection-bound");
5241 g_object_thaw_notify (G_OBJECT (entry));
5245 gtk_entry_move_adjustments (entry);
5246 gtk_entry_recompute (entry);
5251 gtk_entry_reset_layout (GtkEntry *entry)
5253 if (entry->cached_layout)
5255 g_object_unref (entry->cached_layout);
5256 entry->cached_layout = NULL;
5261 update_im_cursor_location (GtkEntry *entry)
5265 gint strong_xoffset;
5266 gint area_width, area_height;
5268 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
5269 gtk_entry_get_text_area_size (entry, NULL, NULL, &area_width, &area_height);
5271 strong_xoffset = strong_x - entry->scroll_offset;
5272 if (strong_xoffset < 0)
5276 else if (strong_xoffset > area_width)
5278 strong_xoffset = area_width;
5280 area.x = strong_xoffset;
5283 area.height = area_height;
5285 gtk_im_context_set_cursor_location (entry->im_context, &area);
5289 recompute_idle_func (gpointer data)
5293 entry = GTK_ENTRY (data);
5295 entry->recompute_idle = 0;
5297 if (gtk_widget_has_screen (GTK_WIDGET (entry)))
5299 gtk_entry_adjust_scroll (entry);
5300 gtk_entry_queue_draw (entry);
5302 update_im_cursor_location (entry);
5309 gtk_entry_recompute (GtkEntry *entry)
5311 gtk_entry_reset_layout (entry);
5312 gtk_entry_check_cursor_blink (entry);
5314 if (!entry->recompute_idle)
5316 entry->recompute_idle = gdk_threads_add_idle_full (G_PRIORITY_HIGH_IDLE + 15, /* between resize and redraw */
5317 recompute_idle_func, entry, NULL);
5321 static PangoLayout *
5322 gtk_entry_create_layout (GtkEntry *entry,
5323 gboolean include_preedit)
5325 GtkWidget *widget = GTK_WIDGET (entry);
5326 PangoLayout *layout = gtk_widget_create_pango_layout (widget, NULL);
5327 PangoAttrList *tmp_attrs = pango_attr_list_new ();
5329 gchar *preedit_string = NULL;
5330 gint preedit_length = 0;
5331 PangoAttrList *preedit_attrs = NULL;
5336 pango_layout_set_single_paragraph_mode (layout, TRUE);
5338 display = gtk_entry_get_display_text (entry, 0, -1);
5339 n_bytes = strlen (display);
5341 if (include_preedit)
5343 gtk_im_context_get_preedit_string (entry->im_context,
5344 &preedit_string, &preedit_attrs, NULL);
5345 preedit_length = entry->preedit_length;
5350 GString *tmp_string = g_string_new (display);
5351 gint cursor_index = g_utf8_offset_to_pointer (display, entry->current_pos) - display;
5353 g_string_insert (tmp_string, cursor_index, preedit_string);
5355 pango_layout_set_text (layout, tmp_string->str, tmp_string->len);
5357 pango_attr_list_splice (tmp_attrs, preedit_attrs,
5358 cursor_index, preedit_length);
5360 g_string_free (tmp_string, TRUE);
5364 PangoDirection pango_dir;
5366 if (gtk_entry_get_display_mode (entry) == DISPLAY_NORMAL)
5367 pango_dir = pango_find_base_dir (display, n_bytes);
5369 pango_dir = PANGO_DIRECTION_NEUTRAL;
5371 if (pango_dir == PANGO_DIRECTION_NEUTRAL)
5373 if (gtk_widget_has_focus (widget))
5375 GdkDisplay *display = gtk_widget_get_display (widget);
5376 GdkKeymap *keymap = gdk_keymap_get_for_display (display);
5377 if (gdk_keymap_get_direction (keymap) == PANGO_DIRECTION_RTL)
5378 pango_dir = PANGO_DIRECTION_RTL;
5380 pango_dir = PANGO_DIRECTION_LTR;
5384 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
5385 pango_dir = PANGO_DIRECTION_RTL;
5387 pango_dir = PANGO_DIRECTION_LTR;
5391 pango_context_set_base_dir (gtk_widget_get_pango_context (widget),
5394 entry->resolved_dir = pango_dir;
5396 pango_layout_set_text (layout, display, n_bytes);
5399 pango_layout_set_attributes (layout, tmp_attrs);
5401 g_free (preedit_string);
5405 pango_attr_list_unref (preedit_attrs);
5407 pango_attr_list_unref (tmp_attrs);
5412 static PangoLayout *
5413 gtk_entry_ensure_layout (GtkEntry *entry,
5414 gboolean include_preedit)
5416 if (entry->preedit_length > 0 &&
5417 !include_preedit != !entry->cache_includes_preedit)
5418 gtk_entry_reset_layout (entry);
5420 if (!entry->cached_layout)
5422 entry->cached_layout = gtk_entry_create_layout (entry, include_preedit);
5423 entry->cache_includes_preedit = include_preedit;
5426 return entry->cached_layout;
5430 get_layout_position (GtkEntry *entry,
5434 PangoLayout *layout;
5435 PangoRectangle logical_rect;
5436 gint area_width, area_height;
5437 GtkBorder inner_border;
5439 PangoLayoutLine *line;
5441 layout = gtk_entry_ensure_layout (entry, TRUE);
5443 gtk_entry_get_text_area_size (entry, NULL, NULL, &area_width, &area_height);
5444 _gtk_entry_effective_inner_border (entry, &inner_border);
5446 area_height = PANGO_SCALE * (area_height - inner_border.top - inner_border.bottom);
5448 line = pango_layout_get_lines_readonly (layout)->data;
5449 pango_layout_line_get_extents (line, NULL, &logical_rect);
5451 /* Align primarily for locale's ascent/descent */
5452 y_pos = ((area_height - entry->ascent - entry->descent) / 2 +
5453 entry->ascent + logical_rect.y);
5455 /* Now see if we need to adjust to fit in actual drawn string */
5456 if (logical_rect.height > area_height)
5457 y_pos = (area_height - logical_rect.height) / 2;
5460 else if (y_pos + logical_rect.height > area_height)
5461 y_pos = area_height - logical_rect.height;
5463 y_pos = inner_border.top + y_pos / PANGO_SCALE;
5466 *x = inner_border.left - entry->scroll_offset;
5473 draw_text_with_color (GtkEntry *entry, cairo_t *cr, GdkColor *default_color)
5475 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
5478 gint start_pos, end_pos;
5480 widget = GTK_WIDGET (entry);
5484 get_layout_position (entry, &x, &y);
5486 cairo_move_to (cr, x, y);
5487 gdk_cairo_set_source_color (cr, default_color);
5488 pango_cairo_show_layout (cr, layout);
5490 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start_pos, &end_pos))
5494 PangoRectangle logical_rect;
5495 GdkColor *selection_color, *text_color;
5496 GtkBorder inner_border;
5499 pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
5500 gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
5502 style = gtk_widget_get_style (widget);
5504 if (gtk_widget_has_focus (widget))
5506 selection_color = &style->base [GTK_STATE_SELECTED];
5507 text_color = &style->text [GTK_STATE_SELECTED];
5511 selection_color = &style->base [GTK_STATE_ACTIVE];
5512 text_color = &style->text [GTK_STATE_ACTIVE];
5515 _gtk_entry_effective_inner_border (entry, &inner_border);
5517 for (i = 0; i < n_ranges; ++i)
5518 cairo_rectangle (cr,
5519 inner_border.left - entry->scroll_offset + ranges[2 * i],
5522 logical_rect.height);
5526 gdk_cairo_set_source_color (cr, selection_color);
5529 cairo_move_to (cr, x, y);
5530 gdk_cairo_set_source_color (cr, text_color);
5531 pango_cairo_show_layout (cr, layout);
5539 gtk_entry_draw_text (GtkEntry *entry,
5542 GtkWidget *widget = GTK_WIDGET (entry);
5545 GdkColor text_color, bar_text_color;
5548 gint progress_x, progress_y, progress_width, progress_height;
5549 gint clip_width, clip_height;
5551 /* Nothing to display at all */
5552 if (gtk_entry_get_display_mode (entry) == DISPLAY_BLANK)
5555 state = GTK_STATE_SELECTED;
5556 if (!gtk_widget_get_sensitive (widget))
5557 state = GTK_STATE_INSENSITIVE;
5558 style = gtk_widget_get_style (widget);
5559 text_color = style->text[gtk_widget_get_state (widget)];
5560 bar_text_color = style->fg[state];
5562 get_progress_area (widget,
5563 &progress_x, &progress_y,
5564 &progress_width, &progress_height);
5566 clip_width = gdk_window_get_width (entry->text_area);
5567 clip_height = gdk_window_get_height (entry->text_area);
5568 cairo_rectangle (cr, 0, 0, clip_width, clip_height);
5571 /* If the color is the same, or the progress area has a zero
5572 * size, then we only need to draw once. */
5573 if ((text_color.pixel == bar_text_color.pixel) ||
5574 ((progress_width == 0) || (progress_height == 0)))
5576 draw_text_with_color (entry, cr, &text_color);
5580 width = gdk_window_get_width (entry->text_area);
5581 height = gdk_window_get_height (entry->text_area);
5585 cairo_rectangle (cr, 0, 0, width, height);
5589 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
5590 cairo_rectangle (cr, 0, 0, width, height);
5592 gdk_window_get_position (entry->text_area, &pos_x, &pos_y);
5593 progress_x -= pos_x;
5594 progress_y -= pos_y;
5596 cairo_rectangle (cr, progress_x, progress_y,
5597 progress_width, progress_height);
5599 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_WINDING);
5601 draw_text_with_color (entry, cr, &text_color);
5604 cairo_rectangle (cr, progress_x, progress_y,
5605 progress_width, progress_height);
5608 draw_text_with_color (entry, cr, &bar_text_color);
5615 draw_insertion_cursor (GtkEntry *entry,
5617 GdkRectangle *cursor_location,
5618 gboolean is_primary,
5619 PangoDirection direction,
5620 gboolean draw_arrow)
5622 GtkWidget *widget = GTK_WIDGET (entry);
5623 GtkTextDirection text_dir;
5625 if (direction == PANGO_DIRECTION_LTR)
5626 text_dir = GTK_TEXT_DIR_LTR;
5628 text_dir = GTK_TEXT_DIR_RTL;
5630 gtk_draw_insertion_cursor (widget, cr,
5632 is_primary, text_dir, draw_arrow);
5636 gtk_entry_draw_cursor (GtkEntry *entry,
5640 GtkWidget *widget = GTK_WIDGET (entry);
5641 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
5642 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
5643 GdkRectangle cursor_location;
5644 gboolean split_cursor;
5645 PangoRectangle cursor_rect;
5646 GtkBorder inner_border;
5648 gint text_area_height;
5651 gboolean block_at_line_end;
5652 PangoLayout *layout;
5655 _gtk_entry_effective_inner_border (entry, &inner_border);
5657 xoffset = inner_border.left - entry->scroll_offset;
5659 text_area_height = gdk_window_get_height (entry->text_area);
5661 layout = gtk_entry_ensure_layout (entry, TRUE);
5662 text = pango_layout_get_text (layout);
5663 cursor_index = g_utf8_offset_to_pointer (text, entry->current_pos + entry->preedit_cursor) - text;
5664 if (!entry->overwrite_mode)
5667 block = _gtk_text_util_get_block_cursor_location (layout,
5668 cursor_index, &cursor_rect, &block_at_line_end);
5672 gint strong_x, weak_x;
5673 PangoDirection dir1 = PANGO_DIRECTION_NEUTRAL;
5674 PangoDirection dir2 = PANGO_DIRECTION_NEUTRAL;
5678 gtk_entry_get_cursor_locations (entry, type, &strong_x, &weak_x);
5680 g_object_get (gtk_widget_get_settings (widget),
5681 "gtk-split-cursor", &split_cursor,
5684 dir1 = entry->resolved_dir;
5690 if (weak_x != strong_x)
5692 dir2 = (entry->resolved_dir == PANGO_DIRECTION_LTR) ? PANGO_DIRECTION_RTL : PANGO_DIRECTION_LTR;
5698 if (keymap_direction == entry->resolved_dir)
5704 cursor_location.x = xoffset + x1;
5705 cursor_location.y = inner_border.top;
5706 cursor_location.width = 0;
5707 cursor_location.height = text_area_height - inner_border.top - inner_border.bottom;
5709 draw_insertion_cursor (entry, cr,
5710 &cursor_location, TRUE, dir1,
5711 dir2 != PANGO_DIRECTION_NEUTRAL);
5713 if (dir2 != PANGO_DIRECTION_NEUTRAL)
5715 cursor_location.x = xoffset + x2;
5716 draw_insertion_cursor (entry, cr,
5717 &cursor_location, FALSE, dir2,
5721 else /* overwrite_mode */
5723 GdkColor cursor_color;
5729 get_layout_position (entry, &x, &y);
5731 rect.x = PANGO_PIXELS (cursor_rect.x) + x;
5732 rect.y = PANGO_PIXELS (cursor_rect.y) + y;
5733 rect.width = PANGO_PIXELS (cursor_rect.width);
5734 rect.height = PANGO_PIXELS (cursor_rect.height);
5736 _gtk_widget_get_cursor_color (widget, &cursor_color);
5737 gdk_cairo_set_source_color (cr, &cursor_color);
5738 gdk_cairo_rectangle (cr, &rect);
5741 if (!block_at_line_end)
5743 gdk_cairo_rectangle (cr, &rect);
5745 cairo_move_to (cr, x, y);
5746 gdk_cairo_set_source_color (cr, >k_widget_get_style (widget)->base[gtk_widget_get_state (widget)]);
5747 pango_cairo_show_layout (cr, layout);
5755 gtk_entry_queue_draw (GtkEntry *entry)
5757 if (gtk_widget_is_drawable (GTK_WIDGET (entry)))
5758 gdk_window_invalidate_rect (gtk_widget_get_window (GTK_WIDGET (entry)),
5763 _gtk_entry_reset_im_context (GtkEntry *entry)
5765 if (entry->need_im_reset)
5767 entry->need_im_reset = FALSE;
5768 gtk_im_context_reset (entry->im_context);
5773 * gtk_entry_reset_im_context:
5774 * @entry: a #GtkEntry
5776 * Reset the input method context of the entry if needed.
5778 * This can be necessary in the case where modifying the buffer
5779 * would confuse on-going input method behavior.
5784 gtk_entry_reset_im_context (GtkEntry *entry)
5786 g_return_if_fail (GTK_IS_ENTRY (entry));
5788 _gtk_entry_reset_im_context (entry);
5792 * gtk_entry_im_context_filter_keypress:
5793 * @entry: a #GtkEntry
5794 * @event: the key event
5796 * Allow the #GtkEntry input method to internally handle key press
5797 * and release events. If this function returns %TRUE, then no further
5798 * processing should be done for this key event. See
5799 * gtk_im_context_filter_keypress().
5801 * Note that you are expected to call this function from your handler
5802 * when overriding key event handling. This is needed in the case when
5803 * you need to insert your own key handling between the input method
5804 * and the default key event handling of the #GtkEntry.
5805 * See gtk_text_view_reset_im_context() for an example of use.
5807 * Return value: %TRUE if the input method handled the key event.
5812 gtk_entry_im_context_filter_keypress (GtkEntry *entry,
5815 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
5817 return gtk_im_context_filter_keypress (entry->im_context, event);
5822 gtk_entry_find_position (GtkEntry *entry,
5825 PangoLayout *layout;
5826 PangoLayoutLine *line;
5833 layout = gtk_entry_ensure_layout (entry, TRUE);
5834 text = pango_layout_get_text (layout);
5835 cursor_index = g_utf8_offset_to_pointer (text, entry->current_pos) - text;
5837 line = pango_layout_get_lines_readonly (layout)->data;
5838 pango_layout_line_x_to_index (line, x * PANGO_SCALE, &index, &trailing);
5840 if (index >= cursor_index && entry->preedit_length)
5842 if (index >= cursor_index + entry->preedit_length)
5843 index -= entry->preedit_length;
5846 index = cursor_index;
5851 pos = g_utf8_pointer_to_offset (text, text + index);
5858 gtk_entry_get_cursor_locations (GtkEntry *entry,
5863 DisplayMode mode = gtk_entry_get_display_mode (entry);
5865 /* Nothing to display at all, so no cursor is relevant */
5866 if (mode == DISPLAY_BLANK)
5876 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
5877 const gchar *text = pango_layout_get_text (layout);
5878 PangoRectangle strong_pos, weak_pos;
5881 if (type == CURSOR_STANDARD)
5883 index = g_utf8_offset_to_pointer (text, entry->current_pos + entry->preedit_cursor) - text;
5885 else /* type == CURSOR_DND */
5887 index = g_utf8_offset_to_pointer (text, entry->dnd_position) - text;
5889 if (entry->dnd_position > entry->current_pos)
5891 if (mode == DISPLAY_NORMAL)
5892 index += entry->preedit_length;
5895 gint preedit_len_chars = g_utf8_strlen (text, -1) - gtk_entry_buffer_get_length (get_buffer (entry));
5896 index += preedit_len_chars * g_unichar_to_utf8 (entry->invisible_char, NULL);
5901 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
5904 *strong_x = strong_pos.x / PANGO_SCALE;
5907 *weak_x = weak_pos.x / PANGO_SCALE;
5912 gtk_entry_adjust_scroll (GtkEntry *entry)
5914 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
5915 gint min_offset, max_offset;
5916 gint text_area_width, text_width;
5917 GtkBorder inner_border;
5918 gint strong_x, weak_x;
5919 gint strong_xoffset, weak_xoffset;
5921 PangoLayout *layout;
5922 PangoLayoutLine *line;
5923 PangoRectangle logical_rect;
5925 if (!gtk_widget_get_realized (GTK_WIDGET (entry)))
5928 _gtk_entry_effective_inner_border (entry, &inner_border);
5930 text_area_width = gdk_window_get_width (entry->text_area);
5931 text_area_width -= inner_border.left + inner_border.right;
5932 if (text_area_width < 0)
5933 text_area_width = 0;
5935 layout = gtk_entry_ensure_layout (entry, TRUE);
5936 line = pango_layout_get_lines_readonly (layout)->data;
5938 pango_layout_line_get_extents (line, NULL, &logical_rect);
5940 /* Display as much text as we can */
5942 if (entry->resolved_dir == PANGO_DIRECTION_LTR)
5943 xalign = priv->xalign;
5945 xalign = 1.0 - priv->xalign;
5947 text_width = PANGO_PIXELS(logical_rect.width);
5949 if (text_width > text_area_width)
5952 max_offset = text_width - text_area_width;
5956 min_offset = (text_width - text_area_width) * xalign;
5957 max_offset = min_offset;
5960 entry->scroll_offset = CLAMP (entry->scroll_offset, min_offset, max_offset);
5962 /* And make sure cursors are on screen. Note that the cursor is
5963 * actually drawn one pixel into the INNER_BORDER space on
5964 * the right, when the scroll is at the utmost right. This
5965 * looks better to to me than confining the cursor inside the
5966 * border entirely, though it means that the cursor gets one
5967 * pixel closer to the edge of the widget on the right than
5968 * on the left. This might need changing if one changed
5969 * INNER_BORDER from 2 to 1, as one would do on a
5970 * small-screen-real-estate display.
5972 * We always make sure that the strong cursor is on screen, and
5973 * put the weak cursor on screen if possible.
5976 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, &weak_x);
5978 strong_xoffset = strong_x - entry->scroll_offset;
5980 if (strong_xoffset < 0)
5982 entry->scroll_offset += strong_xoffset;
5985 else if (strong_xoffset > text_area_width)
5987 entry->scroll_offset += strong_xoffset - text_area_width;
5988 strong_xoffset = text_area_width;
5991 weak_xoffset = weak_x - entry->scroll_offset;
5993 if (weak_xoffset < 0 && strong_xoffset - weak_xoffset <= text_area_width)
5995 entry->scroll_offset += weak_xoffset;
5997 else if (weak_xoffset > text_area_width &&
5998 strong_xoffset - (weak_xoffset - text_area_width) >= 0)
6000 entry->scroll_offset += weak_xoffset - text_area_width;
6003 g_object_notify (G_OBJECT (entry), "scroll-offset");
6007 gtk_entry_move_adjustments (GtkEntry *entry)
6009 GtkAllocation allocation;
6010 GtkAdjustment *adjustment;
6011 PangoContext *context;
6012 PangoFontMetrics *metrics;
6013 gint x, layout_x, border_x, border_y;
6016 adjustment = g_object_get_qdata (G_OBJECT (entry), quark_cursor_hadjustment);
6020 gtk_widget_get_allocation (&(entry->widget), &allocation);
6022 /* Cursor position, layout offset, border width, and widget allocation */
6023 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &x, NULL);
6024 get_layout_position (entry, &layout_x, NULL);
6025 _gtk_entry_get_borders (entry, &border_x, &border_y);
6026 x += allocation.x + layout_x + border_x;
6028 /* Approximate width of a char, so user can see what is ahead/behind */
6029 context = gtk_widget_get_pango_context (GTK_WIDGET (entry));
6030 metrics = pango_context_get_metrics (context,
6031 gtk_widget_get_style (&(entry->widget))->font_desc,
6032 pango_context_get_language (context));
6033 char_width = pango_font_metrics_get_approximate_char_width (metrics) / PANGO_SCALE;
6036 gtk_adjustment_clamp_page (adjustment,
6037 x - (char_width + 1), /* one char + one pixel before */
6038 x + (char_width + 2)); /* one char + cursor + one pixel after */
6042 gtk_entry_move_visually (GtkEntry *entry,
6047 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6050 text = pango_layout_get_text (layout);
6052 index = g_utf8_offset_to_pointer (text, start) - text;
6056 int new_index, new_trailing;
6057 gboolean split_cursor;
6060 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
6061 "gtk-split-cursor", &split_cursor,
6068 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
6069 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
6071 strong = keymap_direction == entry->resolved_dir;
6076 pango_layout_move_cursor_visually (layout, strong, index, 0, 1, &new_index, &new_trailing);
6081 pango_layout_move_cursor_visually (layout, strong, index, 0, -1, &new_index, &new_trailing);
6087 else if (new_index != G_MAXINT)
6090 while (new_trailing--)
6091 index = g_utf8_next_char (text + index) - text;
6094 return g_utf8_pointer_to_offset (text, text + index);
6098 gtk_entry_move_logically (GtkEntry *entry,
6102 gint new_pos = start;
6105 length = gtk_entry_buffer_get_length (get_buffer (entry));
6107 /* Prevent any leak of information */
6108 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6110 new_pos = CLAMP (start + count, 0, length);
6114 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6115 PangoLogAttr *log_attrs;
6118 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6120 while (count > 0 && new_pos < length)
6124 while (new_pos < length && !log_attrs[new_pos].is_cursor_position);
6128 while (count < 0 && new_pos > 0)
6132 while (new_pos > 0 && !log_attrs[new_pos].is_cursor_position);
6144 gtk_entry_move_forward_word (GtkEntry *entry,
6146 gboolean allow_whitespace)
6148 gint new_pos = start;
6151 length = gtk_entry_buffer_get_length (get_buffer (entry));
6153 /* Prevent any leak of information */
6154 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6158 else if (new_pos < length)
6160 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6161 PangoLogAttr *log_attrs;
6164 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6166 /* Find the next word boundary */
6168 while (new_pos < n_attrs - 1 && !(log_attrs[new_pos].is_word_end ||
6169 (log_attrs[new_pos].is_word_start && allow_whitespace)))
6180 gtk_entry_move_backward_word (GtkEntry *entry,
6182 gboolean allow_whitespace)
6184 gint new_pos = start;
6186 /* Prevent any leak of information */
6187 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6193 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6194 PangoLogAttr *log_attrs;
6197 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6199 new_pos = start - 1;
6201 /* Find the previous word boundary */
6202 while (new_pos > 0 && !(log_attrs[new_pos].is_word_start ||
6203 (log_attrs[new_pos].is_word_end && allow_whitespace)))
6213 gtk_entry_delete_whitespace (GtkEntry *entry)
6215 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6216 PangoLogAttr *log_attrs;
6220 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6222 start = end = entry->current_pos;
6224 while (start > 0 && log_attrs[start-1].is_white)
6227 while (end < n_attrs && log_attrs[end].is_white)
6233 gtk_editable_delete_text (GTK_EDITABLE (entry), start, end);
6238 gtk_entry_select_word (GtkEntry *entry)
6240 gint start_pos = gtk_entry_move_backward_word (entry, entry->current_pos, TRUE);
6241 gint end_pos = gtk_entry_move_forward_word (entry, entry->current_pos, TRUE);
6243 gtk_editable_select_region (GTK_EDITABLE (entry), start_pos, end_pos);
6247 gtk_entry_select_line (GtkEntry *entry)
6249 gtk_editable_select_region (GTK_EDITABLE (entry), 0, -1);
6253 truncate_multiline (const gchar *text)
6258 text[length] && text[length] != '\n' && text[length] != '\r';
6265 paste_received (GtkClipboard *clipboard,
6269 GtkEntry *entry = GTK_ENTRY (data);
6270 GtkEditable *editable = GTK_EDITABLE (entry);
6271 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
6273 if (entry->button == 2)
6275 gint pos, start, end;
6276 pos = priv->insert_pos;
6277 gtk_editable_get_selection_bounds (editable, &start, &end);
6278 if (!((start <= pos && pos <= end) || (end <= pos && pos <= start)))
6279 gtk_editable_select_region (editable, pos, pos);
6284 gint pos, start, end;
6286 gboolean popup_completion;
6287 GtkEntryCompletion *completion;
6289 completion = gtk_entry_get_completion (entry);
6291 if (entry->truncate_multiline)
6292 length = truncate_multiline (text);
6294 /* only complete if the selection is at the end */
6295 popup_completion = (gtk_entry_buffer_get_length (get_buffer (entry)) ==
6296 MAX (entry->current_pos, entry->selection_bound));
6300 if (gtk_widget_get_mapped (completion->priv->popup_window))
6301 _gtk_entry_completion_popdown (completion);
6303 if (!popup_completion && completion->priv->changed_id > 0)
6304 g_signal_handler_block (entry, completion->priv->changed_id);
6307 begin_change (entry);
6308 g_object_freeze_notify (G_OBJECT (entry));
6309 if (gtk_editable_get_selection_bounds (editable, &start, &end))
6310 gtk_editable_delete_text (editable, start, end);
6312 pos = entry->current_pos;
6313 gtk_editable_insert_text (editable, text, length, &pos);
6314 gtk_editable_set_position (editable, pos);
6315 g_object_thaw_notify (G_OBJECT (entry));
6319 !popup_completion && completion->priv->changed_id > 0)
6320 g_signal_handler_unblock (entry, completion->priv->changed_id);
6323 g_object_unref (entry);
6327 gtk_entry_paste (GtkEntry *entry,
6330 g_object_ref (entry);
6331 gtk_clipboard_request_text (gtk_widget_get_clipboard (GTK_WIDGET (entry), selection),
6332 paste_received, entry);
6336 primary_get_cb (GtkClipboard *clipboard,
6337 GtkSelectionData *selection_data,
6341 GtkEntry *entry = GTK_ENTRY (data);
6344 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end))
6346 gchar *str = gtk_entry_get_display_text (entry, start, end);
6347 gtk_selection_data_set_text (selection_data, str, -1);
6353 primary_clear_cb (GtkClipboard *clipboard,
6356 GtkEntry *entry = GTK_ENTRY (data);
6358 gtk_editable_select_region (GTK_EDITABLE (entry), entry->current_pos, entry->current_pos);
6362 gtk_entry_update_primary_selection (GtkEntry *entry)
6364 GtkTargetList *list;
6365 GtkTargetEntry *targets;
6366 GtkClipboard *clipboard;
6370 if (!gtk_widget_get_realized (GTK_WIDGET (entry)))
6373 list = gtk_target_list_new (NULL, 0);
6374 gtk_target_list_add_text_targets (list, 0);
6376 targets = gtk_target_table_new_from_list (list, &n_targets);
6378 clipboard = gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_PRIMARY);
6380 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end))
6382 if (!gtk_clipboard_set_with_owner (clipboard, targets, n_targets,
6383 primary_get_cb, primary_clear_cb, G_OBJECT (entry)))
6384 primary_clear_cb (clipboard, entry);
6388 if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (entry))
6389 gtk_clipboard_clear (clipboard);
6392 gtk_target_table_free (targets, n_targets);
6393 gtk_target_list_unref (list);
6397 gtk_entry_clear (GtkEntry *entry,
6398 GtkEntryIconPosition icon_pos)
6400 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
6401 EntryIconInfo *icon_info = priv->icons[icon_pos];
6403 if (!icon_info || icon_info->storage_type == GTK_IMAGE_EMPTY)
6406 g_object_freeze_notify (G_OBJECT (entry));
6408 /* Explicitly check, as the pointer may become invalidated
6409 * during destruction.
6411 if (GDK_IS_WINDOW (icon_info->window))
6412 gdk_window_hide (icon_info->window);
6414 if (icon_info->pixbuf)
6416 g_object_unref (icon_info->pixbuf);
6417 icon_info->pixbuf = NULL;
6420 switch (icon_info->storage_type)
6422 case GTK_IMAGE_PIXBUF:
6423 g_object_notify (G_OBJECT (entry),
6424 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-pixbuf" : "secondary-icon-pixbuf");
6427 case GTK_IMAGE_STOCK:
6428 g_free (icon_info->stock_id);
6429 icon_info->stock_id = NULL;
6430 g_object_notify (G_OBJECT (entry),
6431 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-stock" : "secondary-icon-stock");
6434 case GTK_IMAGE_ICON_NAME:
6435 g_free (icon_info->icon_name);
6436 icon_info->icon_name = NULL;
6437 g_object_notify (G_OBJECT (entry),
6438 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-name" : "secondary-icon-name");
6441 case GTK_IMAGE_GICON:
6442 if (icon_info->gicon)
6444 g_object_unref (icon_info->gicon);
6445 icon_info->gicon = NULL;
6447 g_object_notify (G_OBJECT (entry),
6448 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-gicon" : "secondary-icon-gicon");
6452 g_assert_not_reached ();
6456 icon_info->storage_type = GTK_IMAGE_EMPTY;
6457 g_object_notify (G_OBJECT (entry),
6458 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-storage-type" : "secondary-icon-storage-type");
6460 g_object_thaw_notify (G_OBJECT (entry));
6464 gtk_entry_ensure_pixbuf (GtkEntry *entry,
6465 GtkEntryIconPosition icon_pos)
6467 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
6468 EntryIconInfo *icon_info = priv->icons[icon_pos];
6470 GtkIconTheme *icon_theme;
6471 GtkSettings *settings;
6477 if (!icon_info || icon_info->pixbuf)
6480 widget = GTK_WIDGET (entry);
6482 switch (icon_info->storage_type)
6484 case GTK_IMAGE_EMPTY:
6485 case GTK_IMAGE_PIXBUF:
6487 case GTK_IMAGE_STOCK:
6488 state = gtk_widget_get_state (widget);
6489 gtk_widget_set_state (widget, GTK_STATE_NORMAL);
6490 icon_info->pixbuf = gtk_widget_render_icon (widget,
6491 icon_info->stock_id,
6494 if (!icon_info->pixbuf)
6495 icon_info->pixbuf = gtk_widget_render_icon (widget,
6496 GTK_STOCK_MISSING_IMAGE,
6499 gtk_widget_set_state (widget, state);
6502 case GTK_IMAGE_ICON_NAME:
6503 screen = gtk_widget_get_screen (widget);
6506 icon_theme = gtk_icon_theme_get_for_screen (screen);
6507 settings = gtk_settings_get_for_screen (screen);
6509 gtk_icon_size_lookup_for_settings (settings,
6513 icon_info->pixbuf = gtk_icon_theme_load_icon (icon_theme,
6514 icon_info->icon_name,
6515 MIN (width, height),
6518 if (icon_info->pixbuf == NULL)
6520 state = gtk_widget_get_state (widget);
6521 gtk_widget_set_state (widget, GTK_STATE_NORMAL);
6522 icon_info->pixbuf = gtk_widget_render_icon (widget,
6523 GTK_STOCK_MISSING_IMAGE,
6526 gtk_widget_set_state (widget, state);
6531 case GTK_IMAGE_GICON:
6532 screen = gtk_widget_get_screen (widget);
6535 icon_theme = gtk_icon_theme_get_for_screen (screen);
6536 settings = gtk_settings_get_for_screen (screen);
6538 gtk_icon_size_lookup_for_settings (settings,
6542 info = gtk_icon_theme_lookup_by_gicon (icon_theme,
6544 MIN (width, height),
6545 GTK_ICON_LOOKUP_USE_BUILTIN);
6548 icon_info->pixbuf = gtk_icon_info_load_icon (info, NULL);
6549 gtk_icon_info_free (info);
6552 if (icon_info->pixbuf == NULL)
6554 state = gtk_widget_get_state (widget);
6555 gtk_widget_set_state (widget, GTK_STATE_NORMAL);
6556 icon_info->pixbuf = gtk_widget_render_icon (widget,
6557 GTK_STOCK_MISSING_IMAGE,
6560 gtk_widget_set_state (widget, state);
6566 g_assert_not_reached ();
6570 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
6571 gdk_window_show_unraised (icon_info->window);
6581 * Creates a new entry.
6583 * Return value: a new #GtkEntry.
6586 gtk_entry_new (void)
6588 return g_object_new (GTK_TYPE_ENTRY, NULL);
6592 * gtk_entry_new_with_buffer:
6593 * @buffer: The buffer to use for the new #GtkEntry.
6595 * Creates a new entry with the specified text buffer.
6597 * Return value: a new #GtkEntry
6602 gtk_entry_new_with_buffer (GtkEntryBuffer *buffer)
6604 g_return_val_if_fail (GTK_IS_ENTRY_BUFFER (buffer), NULL);
6605 return g_object_new (GTK_TYPE_ENTRY, "buffer", buffer, NULL);
6608 static GtkEntryBuffer*
6609 get_buffer (GtkEntry *entry)
6611 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
6613 if (priv->buffer == NULL)
6615 GtkEntryBuffer *buffer;
6616 buffer = gtk_entry_buffer_new (NULL, 0);
6617 gtk_entry_set_buffer (entry, buffer);
6618 g_object_unref (buffer);
6621 return priv->buffer;
6625 * gtk_entry_get_buffer:
6626 * @entry: a #GtkEntry
6628 * Get the #GtkEntryBuffer object which holds the text for
6633 * Returns: (transfer none): A #GtkEntryBuffer object.
6636 gtk_entry_get_buffer (GtkEntry *entry)
6638 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
6640 return get_buffer (entry);
6644 * gtk_entry_set_buffer:
6645 * @entry: a #GtkEntry
6646 * @buffer: a #GtkEntryBuffer
6648 * Set the #GtkEntryBuffer object which holds the text for
6654 gtk_entry_set_buffer (GtkEntry *entry,
6655 GtkEntryBuffer *buffer)
6657 GtkEntryPrivate *priv;
6660 g_return_if_fail (GTK_IS_ENTRY (entry));
6661 priv = GTK_ENTRY_GET_PRIVATE (entry);
6665 g_return_if_fail (GTK_IS_ENTRY_BUFFER (buffer));
6666 g_object_ref (buffer);
6671 buffer_disconnect_signals (entry);
6672 g_object_unref (priv->buffer);
6675 priv->buffer = buffer;
6678 buffer_connect_signals (entry);
6680 obj = G_OBJECT (entry);
6681 g_object_freeze_notify (obj);
6682 g_object_notify (obj, "buffer");
6683 g_object_notify (obj, "text");
6684 g_object_notify (obj, "text-length");
6685 g_object_notify (obj, "max-length");
6686 g_object_notify (obj, "visibility");
6687 g_object_notify (obj, "invisible-char");
6688 g_object_notify (obj, "invisible-char-set");
6689 g_object_thaw_notify (obj);
6691 gtk_editable_set_position (GTK_EDITABLE (entry), 0);
6692 gtk_entry_recompute (entry);
6696 * gtk_entry_get_text_area:
6697 * @entry: a #GtkEntry
6698 * @text_area: Return location for the text area.
6700 * Gets the area where the entry's text is drawn. This function is
6701 * useful when drawing something to the entry in a draw callback.
6703 * If the entry is not realized, @text_area is filled with zeros.
6705 * See also gtk_entry_get_icon_area().
6710 gtk_entry_get_text_area (GtkEntry *entry,
6711 GdkRectangle *text_area)
6713 g_return_if_fail (GTK_IS_ENTRY (entry));
6714 g_return_if_fail (text_area != NULL);
6716 if (entry->text_area)
6718 GtkAllocation allocation;
6721 gtk_widget_get_allocation (GTK_WIDGET (entry), &allocation);
6722 gdk_window_get_position (entry->text_area, &x, &y);
6724 text_area->x = x - allocation.x;
6725 text_area->y = y - allocation.y;
6726 text_area->width = gdk_window_get_width (entry->text_area);
6727 text_area->height = gdk_window_get_height (entry->text_area);
6733 text_area->width = 0;
6734 text_area->height = 0;
6739 * gtk_entry_set_text:
6740 * @entry: a #GtkEntry
6741 * @text: the new text
6743 * Sets the text in the widget to the given
6744 * value, replacing the current contents.
6746 * See gtk_entry_buffer_set_text().
6749 gtk_entry_set_text (GtkEntry *entry,
6753 GtkEntryCompletion *completion;
6754 GtkEntryPrivate *priv;
6756 g_return_if_fail (GTK_IS_ENTRY (entry));
6757 g_return_if_fail (text != NULL);
6758 priv = GTK_ENTRY_GET_PRIVATE (entry);
6760 /* Actually setting the text will affect the cursor and selection;
6761 * if the contents don't actually change, this will look odd to the user.
6763 if (strcmp (gtk_entry_buffer_get_text (get_buffer (entry)), text) == 0)
6766 completion = gtk_entry_get_completion (entry);
6767 if (completion && completion->priv->changed_id > 0)
6768 g_signal_handler_block (entry, completion->priv->changed_id);
6770 begin_change (entry);
6771 g_object_freeze_notify (G_OBJECT (entry));
6772 gtk_editable_delete_text (GTK_EDITABLE (entry), 0, -1);
6774 gtk_editable_insert_text (GTK_EDITABLE (entry), text, strlen (text), &tmp_pos);
6775 g_object_thaw_notify (G_OBJECT (entry));
6778 if (completion && completion->priv->changed_id > 0)
6779 g_signal_handler_unblock (entry, completion->priv->changed_id);
6783 * gtk_entry_set_visibility:
6784 * @entry: a #GtkEntry
6785 * @visible: %TRUE if the contents of the entry are displayed
6788 * Sets whether the contents of the entry are visible or not.
6789 * When visibility is set to %FALSE, characters are displayed
6790 * as the invisible char, and will also appear that way when
6791 * the text in the entry widget is copied elsewhere.
6793 * By default, GTK+ picks the best invisible character available
6794 * in the current font, but it can be changed with
6795 * gtk_entry_set_invisible_char().
6798 gtk_entry_set_visibility (GtkEntry *entry,
6801 g_return_if_fail (GTK_IS_ENTRY (entry));
6803 visible = visible != FALSE;
6805 if (entry->visible != visible)
6807 entry->visible = visible;
6809 g_object_notify (G_OBJECT (entry), "visibility");
6810 gtk_entry_recompute (entry);
6815 * gtk_entry_get_visibility:
6816 * @entry: a #GtkEntry
6818 * Retrieves whether the text in @entry is visible. See
6819 * gtk_entry_set_visibility().
6821 * Return value: %TRUE if the text is currently visible
6824 gtk_entry_get_visibility (GtkEntry *entry)
6826 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
6828 return entry->visible;
6832 * gtk_entry_set_invisible_char:
6833 * @entry: a #GtkEntry
6834 * @ch: a Unicode character
6836 * Sets the character to use in place of the actual text when
6837 * gtk_entry_set_visibility() has been called to set text visibility
6838 * to %FALSE. i.e. this is the character used in "password mode" to
6839 * show the user how many characters have been typed. By default, GTK+
6840 * picks the best invisible char available in the current font. If you
6841 * set the invisible char to 0, then the user will get no feedback
6842 * at all; there will be no text on the screen as they type.
6845 gtk_entry_set_invisible_char (GtkEntry *entry,
6848 GtkEntryPrivate *priv;
6850 g_return_if_fail (GTK_IS_ENTRY (entry));
6852 priv = GTK_ENTRY_GET_PRIVATE (entry);
6854 if (!priv->invisible_char_set)
6856 priv->invisible_char_set = TRUE;
6857 g_object_notify (G_OBJECT (entry), "invisible-char-set");
6860 if (ch == entry->invisible_char)
6863 entry->invisible_char = ch;
6864 g_object_notify (G_OBJECT (entry), "invisible-char");
6865 gtk_entry_recompute (entry);
6869 * gtk_entry_get_invisible_char:
6870 * @entry: a #GtkEntry
6872 * Retrieves the character displayed in place of the real characters
6873 * for entries with visibility set to false. See gtk_entry_set_invisible_char().
6875 * Return value: the current invisible char, or 0, if the entry does not
6876 * show invisible text at all.
6879 gtk_entry_get_invisible_char (GtkEntry *entry)
6881 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
6883 return entry->invisible_char;
6887 * gtk_entry_unset_invisible_char:
6888 * @entry: a #GtkEntry
6890 * Unsets the invisible char previously set with
6891 * gtk_entry_set_invisible_char(). So that the
6892 * default invisible char is used again.
6897 gtk_entry_unset_invisible_char (GtkEntry *entry)
6899 GtkEntryPrivate *priv;
6902 g_return_if_fail (GTK_IS_ENTRY (entry));
6904 priv = GTK_ENTRY_GET_PRIVATE (entry);
6906 if (!priv->invisible_char_set)
6909 priv->invisible_char_set = FALSE;
6910 ch = find_invisible_char (GTK_WIDGET (entry));
6912 if (entry->invisible_char != ch)
6914 entry->invisible_char = ch;
6915 g_object_notify (G_OBJECT (entry), "invisible-char");
6918 g_object_notify (G_OBJECT (entry), "invisible-char-set");
6919 gtk_entry_recompute (entry);
6923 * gtk_entry_set_overwrite_mode:
6924 * @entry: a #GtkEntry
6925 * @overwrite: new value
6927 * Sets whether the text is overwritten when typing in the #GtkEntry.
6932 gtk_entry_set_overwrite_mode (GtkEntry *entry,
6935 g_return_if_fail (GTK_IS_ENTRY (entry));
6937 if (entry->overwrite_mode == overwrite)
6940 gtk_entry_toggle_overwrite (entry);
6942 g_object_notify (G_OBJECT (entry), "overwrite-mode");
6946 * gtk_entry_get_overwrite_mode:
6947 * @entry: a #GtkEntry
6949 * Gets the value set by gtk_entry_set_overwrite_mode().
6951 * Return value: whether the text is overwritten when typing.
6956 gtk_entry_get_overwrite_mode (GtkEntry *entry)
6958 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
6960 return entry->overwrite_mode;
6964 * gtk_entry_get_text:
6965 * @entry: a #GtkEntry
6967 * Retrieves the contents of the entry widget.
6968 * See also gtk_editable_get_chars().
6970 * This is equivalent to:
6972 * <informalexample><programlisting>
6973 * gtk_entry_buffer_get_text (gtk_entry_get_buffer (entry));
6974 * </programlisting></informalexample>
6976 * Return value: a pointer to the contents of the widget as a
6977 * string. This string points to internally allocated
6978 * storage in the widget and must not be freed, modified or
6981 G_CONST_RETURN gchar*
6982 gtk_entry_get_text (GtkEntry *entry)
6984 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
6985 return gtk_entry_buffer_get_text (get_buffer (entry));
6989 * gtk_entry_set_max_length:
6990 * @entry: a #GtkEntry
6991 * @max: the maximum length of the entry, or 0 for no maximum.
6992 * (other than the maximum length of entries.) The value passed in will
6993 * be clamped to the range 0-65536.
6995 * Sets the maximum allowed length of the contents of the widget. If
6996 * the current contents are longer than the given length, then they
6997 * will be truncated to fit.
6999 * This is equivalent to:
7001 * <informalexample><programlisting>
7002 * gtk_entry_buffer_set_max_length (gtk_entry_get_buffer (entry), max);
7003 * </programlisting></informalexample>
7006 gtk_entry_set_max_length (GtkEntry *entry,
7009 g_return_if_fail (GTK_IS_ENTRY (entry));
7010 gtk_entry_buffer_set_max_length (get_buffer (entry), max);
7014 * gtk_entry_get_max_length:
7015 * @entry: a #GtkEntry
7017 * Retrieves the maximum allowed length of the text in
7018 * @entry. See gtk_entry_set_max_length().
7020 * This is equivalent to:
7022 * <informalexample><programlisting>
7023 * gtk_entry_buffer_get_max_length (gtk_entry_get_buffer (entry));
7024 * </programlisting></informalexample>
7026 * Return value: the maximum allowed number of characters
7027 * in #GtkEntry, or 0 if there is no maximum.
7030 gtk_entry_get_max_length (GtkEntry *entry)
7032 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7033 return gtk_entry_buffer_get_max_length (get_buffer (entry));
7037 * gtk_entry_get_text_length:
7038 * @entry: a #GtkEntry
7040 * Retrieves the current length of the text in
7043 * This is equivalent to:
7045 * <informalexample><programlisting>
7046 * gtk_entry_buffer_get_length (gtk_entry_get_buffer (entry));
7047 * </programlisting></informalexample>
7049 * Return value: the current number of characters
7050 * in #GtkEntry, or 0 if there are none.
7055 gtk_entry_get_text_length (GtkEntry *entry)
7057 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7058 return gtk_entry_buffer_get_length (get_buffer (entry));
7062 * gtk_entry_set_activates_default:
7063 * @entry: a #GtkEntry
7064 * @setting: %TRUE to activate window's default widget on Enter keypress
7066 * If @setting is %TRUE, pressing Enter in the @entry will activate the default
7067 * widget for the window containing the entry. This usually means that
7068 * the dialog box containing the entry will be closed, since the default
7069 * widget is usually one of the dialog buttons.
7071 * (For experts: if @setting is %TRUE, the entry calls
7072 * gtk_window_activate_default() on the window containing the entry, in
7073 * the default handler for the #GtkWidget::activate signal.)
7076 gtk_entry_set_activates_default (GtkEntry *entry,
7079 g_return_if_fail (GTK_IS_ENTRY (entry));
7080 setting = setting != FALSE;
7082 if (setting != entry->activates_default)
7084 entry->activates_default = setting;
7085 g_object_notify (G_OBJECT (entry), "activates-default");
7090 * gtk_entry_get_activates_default:
7091 * @entry: a #GtkEntry
7093 * Retrieves the value set by gtk_entry_set_activates_default().
7095 * Return value: %TRUE if the entry will activate the default widget
7098 gtk_entry_get_activates_default (GtkEntry *entry)
7100 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7102 return entry->activates_default;
7106 * gtk_entry_set_width_chars:
7107 * @entry: a #GtkEntry
7108 * @n_chars: width in chars
7110 * Changes the size request of the entry to be about the right size
7111 * for @n_chars characters. Note that it changes the size
7112 * <emphasis>request</emphasis>, the size can still be affected by
7113 * how you pack the widget into containers. If @n_chars is -1, the
7114 * size reverts to the default entry size.
7117 gtk_entry_set_width_chars (GtkEntry *entry,
7120 g_return_if_fail (GTK_IS_ENTRY (entry));
7122 if (entry->width_chars != n_chars)
7124 entry->width_chars = n_chars;
7125 g_object_notify (G_OBJECT (entry), "width-chars");
7126 gtk_widget_queue_resize (GTK_WIDGET (entry));
7131 * gtk_entry_get_width_chars:
7132 * @entry: a #GtkEntry
7134 * Gets the value set by gtk_entry_set_width_chars().
7136 * Return value: number of chars to request space for, or negative if unset
7139 gtk_entry_get_width_chars (GtkEntry *entry)
7141 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7143 return entry->width_chars;
7147 * gtk_entry_set_has_frame:
7148 * @entry: a #GtkEntry
7149 * @setting: new value
7151 * Sets whether the entry has a beveled frame around it.
7154 gtk_entry_set_has_frame (GtkEntry *entry,
7157 g_return_if_fail (GTK_IS_ENTRY (entry));
7159 setting = (setting != FALSE);
7161 if (entry->has_frame == setting)
7164 gtk_widget_queue_resize (GTK_WIDGET (entry));
7165 entry->has_frame = setting;
7166 g_object_notify (G_OBJECT (entry), "has-frame");
7170 * gtk_entry_get_has_frame:
7171 * @entry: a #GtkEntry
7173 * Gets the value set by gtk_entry_set_has_frame().
7175 * Return value: whether the entry has a beveled frame
7178 gtk_entry_get_has_frame (GtkEntry *entry)
7180 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7182 return entry->has_frame;
7186 * gtk_entry_set_inner_border:
7187 * @entry: a #GtkEntry
7188 * @border: (allow-none): a #GtkBorder, or %NULL
7190 * Sets %entry's inner-border property to %border, or clears it if %NULL
7191 * is passed. The inner-border is the area around the entry's text, but
7194 * If set, this property overrides the inner-border style property.
7195 * Overriding the style-provided border is useful when you want to do
7196 * in-place editing of some text in a canvas or list widget, where
7197 * pixel-exact positioning of the entry is important.
7202 gtk_entry_set_inner_border (GtkEntry *entry,
7203 const GtkBorder *border)
7205 g_return_if_fail (GTK_IS_ENTRY (entry));
7207 gtk_widget_queue_resize (GTK_WIDGET (entry));
7210 g_object_set_qdata_full (G_OBJECT (entry), quark_inner_border,
7211 gtk_border_copy (border),
7212 (GDestroyNotify) gtk_border_free);
7214 g_object_set_qdata (G_OBJECT (entry), quark_inner_border, NULL);
7216 g_object_notify (G_OBJECT (entry), "inner-border");
7220 * gtk_entry_get_inner_border:
7221 * @entry: a #GtkEntry
7223 * This function returns the entry's #GtkEntry:inner-border property. See
7224 * gtk_entry_set_inner_border() for more information.
7226 * Return value: (transfer none): the entry's #GtkBorder, or %NULL if none was set.
7230 G_CONST_RETURN GtkBorder *
7231 gtk_entry_get_inner_border (GtkEntry *entry)
7233 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7235 return g_object_get_qdata (G_OBJECT (entry), quark_inner_border);
7239 * gtk_entry_get_layout:
7240 * @entry: a #GtkEntry
7242 * Gets the #PangoLayout used to display the entry.
7243 * The layout is useful to e.g. convert text positions to
7244 * pixel positions, in combination with gtk_entry_get_layout_offsets().
7245 * The returned layout is owned by the entry and must not be
7246 * modified or freed by the caller.
7248 * Keep in mind that the layout text may contain a preedit string, so
7249 * gtk_entry_layout_index_to_text_index() and
7250 * gtk_entry_text_index_to_layout_index() are needed to convert byte
7251 * indices in the layout to byte indices in the entry contents.
7253 * Return value: (transfer none): the #PangoLayout for this entry
7256 gtk_entry_get_layout (GtkEntry *entry)
7258 PangoLayout *layout;
7260 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7262 layout = gtk_entry_ensure_layout (entry, TRUE);
7269 * gtk_entry_layout_index_to_text_index:
7270 * @entry: a #GtkEntry
7271 * @layout_index: byte index into the entry layout text
7273 * Converts from a position in the entry contents (returned
7274 * by gtk_entry_get_text()) to a position in the
7275 * entry's #PangoLayout (returned by gtk_entry_get_layout(),
7276 * with text retrieved via pango_layout_get_text()).
7278 * Return value: byte index into the entry contents
7281 gtk_entry_layout_index_to_text_index (GtkEntry *entry,
7284 PangoLayout *layout;
7288 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7290 layout = gtk_entry_ensure_layout (entry, TRUE);
7291 text = pango_layout_get_text (layout);
7292 cursor_index = g_utf8_offset_to_pointer (text, entry->current_pos) - text;
7294 if (layout_index >= cursor_index && entry->preedit_length)
7296 if (layout_index >= cursor_index + entry->preedit_length)
7297 layout_index -= entry->preedit_length;
7299 layout_index = cursor_index;
7302 return layout_index;
7306 * gtk_entry_text_index_to_layout_index:
7307 * @entry: a #GtkEntry
7308 * @text_index: byte index into the entry contents
7310 * Converts from a position in the entry's #PangoLayout (returned by
7311 * gtk_entry_get_layout()) to a position in the entry contents
7312 * (returned by gtk_entry_get_text()).
7314 * Return value: byte index into the entry layout text
7317 gtk_entry_text_index_to_layout_index (GtkEntry *entry,
7320 PangoLayout *layout;
7323 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7325 layout = gtk_entry_ensure_layout (entry, TRUE);
7326 text = pango_layout_get_text (layout);
7327 cursor_index = g_utf8_offset_to_pointer (text, entry->current_pos) - text;
7329 if (text_index > cursor_index)
7330 text_index += entry->preedit_length;
7336 * gtk_entry_get_layout_offsets:
7337 * @entry: a #GtkEntry
7338 * @x: (allow-none): location to store X offset of layout, or %NULL
7339 * @y: (allow-none): location to store Y offset of layout, or %NULL
7342 * Obtains the position of the #PangoLayout used to render text
7343 * in the entry, in widget coordinates. Useful if you want to line
7344 * up the text in an entry with some other text, e.g. when using the
7345 * entry to implement editable cells in a sheet widget.
7347 * Also useful to convert mouse events into coordinates inside the
7348 * #PangoLayout, e.g. to take some action if some part of the entry text
7351 * Note that as the user scrolls around in the entry the offsets will
7352 * change; you'll need to connect to the "notify::scroll-offset"
7353 * signal to track this. Remember when using the #PangoLayout
7354 * functions you need to convert to and from pixels using
7355 * PANGO_PIXELS() or #PANGO_SCALE.
7357 * Keep in mind that the layout text may contain a preedit string, so
7358 * gtk_entry_layout_index_to_text_index() and
7359 * gtk_entry_text_index_to_layout_index() are needed to convert byte
7360 * indices in the layout to byte indices in the entry contents.
7363 gtk_entry_get_layout_offsets (GtkEntry *entry,
7367 gint text_area_x, text_area_y;
7369 g_return_if_fail (GTK_IS_ENTRY (entry));
7371 /* this gets coords relative to text area */
7372 get_layout_position (entry, x, y);
7374 /* convert to widget coords */
7375 gtk_entry_get_text_area_size (entry, &text_area_x, &text_area_y, NULL, NULL);
7386 * gtk_entry_set_alignment:
7387 * @entry: a #GtkEntry
7388 * @xalign: The horizontal alignment, from 0 (left) to 1 (right).
7389 * Reversed for RTL layouts
7391 * Sets the alignment for the contents of the entry. This controls
7392 * the horizontal positioning of the contents when the displayed
7393 * text is shorter than the width of the entry.
7398 gtk_entry_set_alignment (GtkEntry *entry, gfloat xalign)
7400 GtkEntryPrivate *priv;
7402 g_return_if_fail (GTK_IS_ENTRY (entry));
7404 priv = GTK_ENTRY_GET_PRIVATE (entry);
7408 else if (xalign > 1.0)
7411 if (xalign != priv->xalign)
7413 priv->xalign = xalign;
7415 gtk_entry_recompute (entry);
7417 g_object_notify (G_OBJECT (entry), "xalign");
7422 * gtk_entry_get_alignment:
7423 * @entry: a #GtkEntry
7425 * Gets the value set by gtk_entry_set_alignment().
7427 * Return value: the alignment
7432 gtk_entry_get_alignment (GtkEntry *entry)
7434 GtkEntryPrivate *priv;
7436 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
7438 priv = GTK_ENTRY_GET_PRIVATE (entry);
7440 return priv->xalign;
7444 * gtk_entry_set_icon_from_pixbuf:
7445 * @entry: a #GtkEntry
7446 * @icon_pos: Icon position
7447 * @pixbuf: (allow-none): A #GdkPixbuf, or %NULL
7449 * Sets the icon shown in the specified position using a pixbuf.
7451 * If @pixbuf is %NULL, no icon will be shown in the specified position.
7456 gtk_entry_set_icon_from_pixbuf (GtkEntry *entry,
7457 GtkEntryIconPosition icon_pos,
7460 GtkEntryPrivate *priv;
7461 EntryIconInfo *icon_info;
7463 g_return_if_fail (GTK_IS_ENTRY (entry));
7464 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7466 priv = GTK_ENTRY_GET_PRIVATE (entry);
7468 if ((icon_info = priv->icons[icon_pos]) == NULL)
7469 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7471 g_object_freeze_notify (G_OBJECT (entry));
7474 g_object_ref (pixbuf);
7476 gtk_entry_clear (entry, icon_pos);
7480 icon_info->storage_type = GTK_IMAGE_PIXBUF;
7481 icon_info->pixbuf = pixbuf;
7483 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7485 g_object_notify (G_OBJECT (entry), "primary-icon-pixbuf");
7486 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7490 g_object_notify (G_OBJECT (entry), "secondary-icon-pixbuf");
7491 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7494 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7495 gdk_window_show_unraised (icon_info->window);
7498 gtk_entry_ensure_pixbuf (entry, icon_pos);
7500 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7501 gtk_widget_queue_resize (GTK_WIDGET (entry));
7503 g_object_thaw_notify (G_OBJECT (entry));
7507 * gtk_entry_set_icon_from_stock:
7508 * @entry: A #GtkEntry
7509 * @icon_pos: Icon position
7510 * @stock_id: (allow-none): The name of the stock item, or %NULL
7512 * Sets the icon shown in the entry at the specified position from
7515 * If @stock_id is %NULL, no icon will be shown in the specified position.
7520 gtk_entry_set_icon_from_stock (GtkEntry *entry,
7521 GtkEntryIconPosition icon_pos,
7522 const gchar *stock_id)
7524 GtkEntryPrivate *priv;
7525 EntryIconInfo *icon_info;
7528 g_return_if_fail (GTK_IS_ENTRY (entry));
7529 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7531 priv = GTK_ENTRY_GET_PRIVATE (entry);
7533 if ((icon_info = priv->icons[icon_pos]) == NULL)
7534 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7536 g_object_freeze_notify (G_OBJECT (entry));
7538 gtk_widget_ensure_style (GTK_WIDGET (entry));
7540 /* need to dup before clearing */
7541 new_id = g_strdup (stock_id);
7543 gtk_entry_clear (entry, icon_pos);
7547 icon_info->storage_type = GTK_IMAGE_STOCK;
7548 icon_info->stock_id = new_id;
7550 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7552 g_object_notify (G_OBJECT (entry), "primary-icon-stock");
7553 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7557 g_object_notify (G_OBJECT (entry), "secondary-icon-stock");
7558 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7561 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7562 gdk_window_show_unraised (icon_info->window);
7565 gtk_entry_ensure_pixbuf (entry, icon_pos);
7567 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7568 gtk_widget_queue_resize (GTK_WIDGET (entry));
7570 g_object_thaw_notify (G_OBJECT (entry));
7574 * gtk_entry_set_icon_from_icon_name:
7575 * @entry: A #GtkEntry
7576 * @icon_pos: The position at which to set the icon
7577 * @icon_name: (allow-none): An icon name, or %NULL
7579 * Sets the icon shown in the entry at the specified position
7580 * from the current icon theme.
7582 * If the icon name isn't known, a "broken image" icon will be displayed
7585 * If @icon_name is %NULL, no icon will be shown in the specified position.
7590 gtk_entry_set_icon_from_icon_name (GtkEntry *entry,
7591 GtkEntryIconPosition icon_pos,
7592 const gchar *icon_name)
7594 GtkEntryPrivate *priv;
7595 EntryIconInfo *icon_info;
7598 g_return_if_fail (GTK_IS_ENTRY (entry));
7599 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7601 priv = GTK_ENTRY_GET_PRIVATE (entry);
7603 if ((icon_info = priv->icons[icon_pos]) == NULL)
7604 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7606 g_object_freeze_notify (G_OBJECT (entry));
7608 gtk_widget_ensure_style (GTK_WIDGET (entry));
7610 /* need to dup before clearing */
7611 new_name = g_strdup (icon_name);
7613 gtk_entry_clear (entry, icon_pos);
7615 if (new_name != NULL)
7617 icon_info->storage_type = GTK_IMAGE_ICON_NAME;
7618 icon_info->icon_name = new_name;
7620 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7622 g_object_notify (G_OBJECT (entry), "primary-icon-name");
7623 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7627 g_object_notify (G_OBJECT (entry), "secondary-icon-name");
7628 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7631 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7632 gdk_window_show_unraised (icon_info->window);
7635 gtk_entry_ensure_pixbuf (entry, icon_pos);
7637 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7638 gtk_widget_queue_resize (GTK_WIDGET (entry));
7640 g_object_thaw_notify (G_OBJECT (entry));
7644 * gtk_entry_set_icon_from_gicon:
7645 * @entry: A #GtkEntry
7646 * @icon_pos: The position at which to set the icon
7647 * @icon: (allow-none): The icon to set, or %NULL
7649 * Sets the icon shown in the entry at the specified position
7650 * from the current icon theme.
7651 * If the icon isn't known, a "broken image" icon will be displayed
7654 * If @icon is %NULL, no icon will be shown in the specified position.
7659 gtk_entry_set_icon_from_gicon (GtkEntry *entry,
7660 GtkEntryIconPosition icon_pos,
7663 GtkEntryPrivate *priv;
7664 EntryIconInfo *icon_info;
7666 g_return_if_fail (GTK_IS_ENTRY (entry));
7667 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7669 priv = GTK_ENTRY_GET_PRIVATE (entry);
7671 if ((icon_info = priv->icons[icon_pos]) == NULL)
7672 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7674 g_object_freeze_notify (G_OBJECT (entry));
7676 /* need to ref before clearing */
7678 g_object_ref (icon);
7680 gtk_entry_clear (entry, icon_pos);
7684 icon_info->storage_type = GTK_IMAGE_GICON;
7685 icon_info->gicon = icon;
7687 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7689 g_object_notify (G_OBJECT (entry), "primary-icon-gicon");
7690 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7694 g_object_notify (G_OBJECT (entry), "secondary-icon-gicon");
7695 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7698 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7699 gdk_window_show_unraised (icon_info->window);
7702 gtk_entry_ensure_pixbuf (entry, icon_pos);
7704 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7705 gtk_widget_queue_resize (GTK_WIDGET (entry));
7707 g_object_thaw_notify (G_OBJECT (entry));
7711 * gtk_entry_set_icon_activatable:
7712 * @entry: A #GtkEntry
7713 * @icon_pos: Icon position
7714 * @activatable: %TRUE if the icon should be activatable
7716 * Sets whether the icon is activatable.
7721 gtk_entry_set_icon_activatable (GtkEntry *entry,
7722 GtkEntryIconPosition icon_pos,
7723 gboolean activatable)
7725 GtkEntryPrivate *priv;
7726 EntryIconInfo *icon_info;
7728 g_return_if_fail (GTK_IS_ENTRY (entry));
7729 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7731 priv = GTK_ENTRY_GET_PRIVATE (entry);
7733 if ((icon_info = priv->icons[icon_pos]) == NULL)
7734 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7736 activatable = activatable != FALSE;
7738 if (icon_info->nonactivatable != !activatable)
7740 icon_info->nonactivatable = !activatable;
7742 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
7743 update_cursors (GTK_WIDGET (entry));
7745 g_object_notify (G_OBJECT (entry),
7746 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-activatable" : "secondary-icon-activatable");
7751 * gtk_entry_get_icon_activatable:
7752 * @entry: a #GtkEntry
7753 * @icon_pos: Icon position
7755 * Returns whether the icon is activatable.
7757 * Returns: %TRUE if the icon is activatable.
7762 gtk_entry_get_icon_activatable (GtkEntry *entry,
7763 GtkEntryIconPosition icon_pos)
7765 GtkEntryPrivate *priv;
7766 EntryIconInfo *icon_info;
7768 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7769 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), FALSE);
7771 priv = GTK_ENTRY_GET_PRIVATE (entry);
7772 icon_info = priv->icons[icon_pos];
7774 return (icon_info != NULL && !icon_info->nonactivatable);
7778 * gtk_entry_get_icon_pixbuf:
7779 * @entry: A #GtkEntry
7780 * @icon_pos: Icon position
7782 * Retrieves the image used for the icon.
7784 * Unlike the other methods of setting and getting icon data, this
7785 * method will work regardless of whether the icon was set using a
7786 * #GdkPixbuf, a #GIcon, a stock item, or an icon name.
7788 * Returns: (transfer none): A #GdkPixbuf, or %NULL if no icon is
7789 * set for this position.
7794 gtk_entry_get_icon_pixbuf (GtkEntry *entry,
7795 GtkEntryIconPosition icon_pos)
7797 GtkEntryPrivate *priv;
7798 EntryIconInfo *icon_info;
7800 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7801 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7803 priv = GTK_ENTRY_GET_PRIVATE (entry);
7804 icon_info = priv->icons[icon_pos];
7809 gtk_entry_ensure_pixbuf (entry, icon_pos);
7811 return icon_info->pixbuf;
7815 * gtk_entry_get_icon_gicon:
7816 * @entry: A #GtkEntry
7817 * @icon_pos: Icon position
7819 * Retrieves the #GIcon used for the icon, or %NULL if there is
7820 * no icon or if the icon was set by some other method (e.g., by
7821 * stock, pixbuf, or icon name).
7823 * Returns: (transfer none): A #GIcon, or %NULL if no icon is set
7824 * or if the icon is not a #GIcon
7829 gtk_entry_get_icon_gicon (GtkEntry *entry,
7830 GtkEntryIconPosition icon_pos)
7832 GtkEntryPrivate *priv;
7833 EntryIconInfo *icon_info;
7835 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7836 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7838 priv = GTK_ENTRY_GET_PRIVATE (entry);
7839 icon_info = priv->icons[icon_pos];
7844 return icon_info->storage_type == GTK_IMAGE_GICON ? icon_info->gicon : NULL;
7848 * gtk_entry_get_icon_stock:
7849 * @entry: A #GtkEntry
7850 * @icon_pos: Icon position
7852 * Retrieves the stock id used for the icon, or %NULL if there is
7853 * no icon or if the icon was set by some other method (e.g., by
7854 * pixbuf, icon name or gicon).
7856 * Returns: A stock id, or %NULL if no icon is set or if the icon
7857 * wasn't set from a stock id
7862 gtk_entry_get_icon_stock (GtkEntry *entry,
7863 GtkEntryIconPosition icon_pos)
7865 GtkEntryPrivate *priv;
7866 EntryIconInfo *icon_info;
7868 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7869 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7871 priv = GTK_ENTRY_GET_PRIVATE (entry);
7872 icon_info = priv->icons[icon_pos];
7877 return icon_info->storage_type == GTK_IMAGE_STOCK ? icon_info->stock_id : NULL;
7881 * gtk_entry_get_icon_name:
7882 * @entry: A #GtkEntry
7883 * @icon_pos: Icon position
7885 * Retrieves the icon name used for the icon, or %NULL if there is
7886 * no icon or if the icon was set by some other method (e.g., by
7887 * pixbuf, stock or gicon).
7889 * Returns: An icon name, or %NULL if no icon is set or if the icon
7890 * wasn't set from an icon name
7895 gtk_entry_get_icon_name (GtkEntry *entry,
7896 GtkEntryIconPosition icon_pos)
7898 GtkEntryPrivate *priv;
7899 EntryIconInfo *icon_info;
7901 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7902 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7904 priv = GTK_ENTRY_GET_PRIVATE (entry);
7905 icon_info = priv->icons[icon_pos];
7910 return icon_info->storage_type == GTK_IMAGE_ICON_NAME ? icon_info->icon_name : NULL;
7914 * gtk_entry_set_icon_sensitive:
7915 * @entry: A #GtkEntry
7916 * @icon_pos: Icon position
7917 * @sensitive: Specifies whether the icon should appear
7918 * sensitive or insensitive
7920 * Sets the sensitivity for the specified icon.
7925 gtk_entry_set_icon_sensitive (GtkEntry *entry,
7926 GtkEntryIconPosition icon_pos,
7929 GtkEntryPrivate *priv;
7930 EntryIconInfo *icon_info;
7932 g_return_if_fail (GTK_IS_ENTRY (entry));
7933 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7935 priv = GTK_ENTRY_GET_PRIVATE (entry);
7937 if ((icon_info = priv->icons[icon_pos]) == NULL)
7938 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7940 if (icon_info->insensitive != !sensitive)
7942 icon_info->insensitive = !sensitive;
7944 icon_info->pressed = FALSE;
7945 icon_info->prelight = FALSE;
7947 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
7948 update_cursors (GTK_WIDGET (entry));
7950 gtk_widget_queue_draw (GTK_WIDGET (entry));
7952 g_object_notify (G_OBJECT (entry),
7953 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-sensitive" : "secondary-icon-sensitive");
7958 * gtk_entry_get_icon_sensitive:
7959 * @entry: a #GtkEntry
7960 * @icon_pos: Icon position
7962 * Returns whether the icon appears sensitive or insensitive.
7964 * Returns: %TRUE if the icon is sensitive.
7969 gtk_entry_get_icon_sensitive (GtkEntry *entry,
7970 GtkEntryIconPosition icon_pos)
7972 GtkEntryPrivate *priv;
7973 EntryIconInfo *icon_info;
7975 g_return_val_if_fail (GTK_IS_ENTRY (entry), TRUE);
7976 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), TRUE);
7978 priv = GTK_ENTRY_GET_PRIVATE (entry);
7979 icon_info = priv->icons[icon_pos];
7981 return (!icon_info || !icon_info->insensitive);
7986 * gtk_entry_get_icon_storage_type:
7987 * @entry: a #GtkEntry
7988 * @icon_pos: Icon position
7990 * Gets the type of representation being used by the icon
7991 * to store image data. If the icon has no image data,
7992 * the return value will be %GTK_IMAGE_EMPTY.
7994 * Return value: image representation being used
7999 gtk_entry_get_icon_storage_type (GtkEntry *entry,
8000 GtkEntryIconPosition icon_pos)
8002 GtkEntryPrivate *priv;
8003 EntryIconInfo *icon_info;
8005 g_return_val_if_fail (GTK_IS_ENTRY (entry), GTK_IMAGE_EMPTY);
8006 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), GTK_IMAGE_EMPTY);
8008 priv = GTK_ENTRY_GET_PRIVATE (entry);
8009 icon_info = priv->icons[icon_pos];
8012 return GTK_IMAGE_EMPTY;
8014 return icon_info->storage_type;
8018 * gtk_entry_get_icon_at_pos:
8019 * @entry: a #GtkEntry
8020 * @x: the x coordinate of the position to find
8021 * @y: the y coordinate of the position to find
8023 * Finds the icon at the given position and return its index.
8024 * If @x, @y doesn't lie inside an icon, -1 is returned.
8025 * This function is intended for use in a #GtkWidget::query-tooltip
8028 * Returns: the index of the icon at the given position, or -1
8033 gtk_entry_get_icon_at_pos (GtkEntry *entry,
8037 GtkAllocation primary;
8038 GtkAllocation secondary;
8039 gint frame_x, frame_y;
8041 g_return_val_if_fail (GTK_IS_ENTRY (entry), -1);
8043 get_frame_size (entry, &frame_x, &frame_y, NULL, NULL);
8047 get_icon_allocations (entry, &primary, &secondary);
8049 if (primary.x <= x && x < primary.x + primary.width &&
8050 primary.y <= y && y < primary.y + primary.height)
8051 return GTK_ENTRY_ICON_PRIMARY;
8053 if (secondary.x <= x && x < secondary.x + secondary.width &&
8054 secondary.y <= y && y < secondary.y + secondary.height)
8055 return GTK_ENTRY_ICON_SECONDARY;
8061 * gtk_entry_set_icon_drag_source:
8062 * @entry: a #GtkIconEntry
8063 * @icon_pos: icon position
8064 * @target_list: the targets (data formats) in which the data can be provided
8065 * @actions: a bitmask of the allowed drag actions
8067 * Sets up the icon at the given position so that GTK+ will start a drag
8068 * operation when the user clicks and drags the icon.
8070 * To handle the drag operation, you need to connect to the usual
8071 * #GtkWidget::drag-data-get (or possibly #GtkWidget::drag-data-delete)
8072 * signal, and use gtk_entry_get_current_icon_drag_source() in
8073 * your signal handler to find out if the drag was started from
8076 * By default, GTK+ uses the icon as the drag icon. You can use the
8077 * #GtkWidget::drag-begin signal to set a different icon. Note that you
8078 * have to use g_signal_connect_after() to ensure that your signal handler
8079 * gets executed after the default handler.
8084 gtk_entry_set_icon_drag_source (GtkEntry *entry,
8085 GtkEntryIconPosition icon_pos,
8086 GtkTargetList *target_list,
8087 GdkDragAction actions)
8089 GtkEntryPrivate *priv;
8090 EntryIconInfo *icon_info;
8092 g_return_if_fail (GTK_IS_ENTRY (entry));
8093 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8095 priv = GTK_ENTRY_GET_PRIVATE (entry);
8097 if ((icon_info = priv->icons[icon_pos]) == NULL)
8098 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8100 if (icon_info->target_list)
8101 gtk_target_list_unref (icon_info->target_list);
8102 icon_info->target_list = target_list;
8103 if (icon_info->target_list)
8104 gtk_target_list_ref (icon_info->target_list);
8106 icon_info->actions = actions;
8110 * gtk_entry_get_current_icon_drag_source:
8111 * @entry: a #GtkIconEntry
8113 * Returns the index of the icon which is the source of the current
8114 * DND operation, or -1.
8116 * This function is meant to be used in a #GtkWidget::drag-data-get
8119 * Returns: index of the icon which is the source of the current
8120 * DND operation, or -1.
8125 gtk_entry_get_current_icon_drag_source (GtkEntry *entry)
8127 GtkEntryPrivate *priv;
8128 EntryIconInfo *icon_info = NULL;
8131 g_return_val_if_fail (GTK_IS_ENTRY (entry), -1);
8133 priv = GTK_ENTRY_GET_PRIVATE (entry);
8135 for (i = 0; i < MAX_ICONS; i++)
8137 if ((icon_info = priv->icons[i]))
8139 if (icon_info->in_drag)
8148 * gtk_entry_get_icon_area:
8149 * @entry: A #GtkEntry
8150 * @icon_pos: Icon position
8151 * @icon_area: Return location for the icon's area
8153 * Gets the area where entry's icon at @icon_pos is drawn.
8154 * This function is useful when drawing something to the
8155 * entry in a draw callback.
8157 * If the entry is not realized or has no icon at the given position,
8158 * @icon_area is filled with zeros.
8160 * See also gtk_entry_get_text_area()
8165 gtk_entry_get_icon_area (GtkEntry *entry,
8166 GtkEntryIconPosition icon_pos,
8167 GdkRectangle *icon_area)
8169 GtkEntryPrivate *priv;
8170 EntryIconInfo *icon_info;
8172 g_return_if_fail (GTK_IS_ENTRY (entry));
8173 g_return_if_fail (icon_area != NULL);
8175 priv = GTK_ENTRY_GET_PRIVATE (entry);
8177 icon_info = priv->icons[icon_pos];
8181 GtkAllocation primary;
8182 GtkAllocation secondary;
8184 get_icon_allocations (entry, &primary, &secondary);
8186 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
8187 *icon_area = primary;
8189 *icon_area = secondary;
8195 icon_area->width = 0;
8196 icon_area->height = 0;
8201 ensure_has_tooltip (GtkEntry *entry)
8203 GtkEntryPrivate *priv;
8204 EntryIconInfo *icon_info;
8206 gboolean has_tooltip = FALSE;
8208 priv = GTK_ENTRY_GET_PRIVATE (entry);
8210 for (i = 0; i < MAX_ICONS; i++)
8212 if ((icon_info = priv->icons[i]) != NULL)
8214 if (icon_info->tooltip != NULL)
8222 gtk_widget_set_has_tooltip (GTK_WIDGET (entry), has_tooltip);
8226 * gtk_entry_get_icon_tooltip_text:
8227 * @entry: a #GtkEntry
8228 * @icon_pos: the icon position
8230 * Gets the contents of the tooltip on the icon at the specified
8231 * position in @entry.
8233 * Returns: the tooltip text, or %NULL. Free the returned string
8234 * with g_free() when done.
8239 gtk_entry_get_icon_tooltip_text (GtkEntry *entry,
8240 GtkEntryIconPosition icon_pos)
8242 GtkEntryPrivate *priv;
8243 EntryIconInfo *icon_info;
8246 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8247 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8249 priv = GTK_ENTRY_GET_PRIVATE (entry);
8250 icon_info = priv->icons[icon_pos];
8255 if (icon_info->tooltip &&
8256 !pango_parse_markup (icon_info->tooltip, -1, 0, NULL, &text, NULL, NULL))
8257 g_assert (NULL == text); /* text should still be NULL in case of markup errors */
8263 * gtk_entry_set_icon_tooltip_text:
8264 * @entry: a #GtkEntry
8265 * @icon_pos: the icon position
8266 * @tooltip: (allow-none): the contents of the tooltip for the icon, or %NULL
8268 * Sets @tooltip as the contents of the tooltip for the icon
8269 * at the specified position.
8271 * Use %NULL for @tooltip to remove an existing tooltip.
8273 * See also gtk_widget_set_tooltip_text() and
8274 * gtk_entry_set_icon_tooltip_markup().
8279 gtk_entry_set_icon_tooltip_text (GtkEntry *entry,
8280 GtkEntryIconPosition icon_pos,
8281 const gchar *tooltip)
8283 GtkEntryPrivate *priv;
8284 EntryIconInfo *icon_info;
8286 g_return_if_fail (GTK_IS_ENTRY (entry));
8287 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8289 priv = GTK_ENTRY_GET_PRIVATE (entry);
8291 if (!(icon_info = priv->icons[icon_pos]))
8292 icon_info = priv->icons[icon_pos];
8294 if (icon_info->tooltip)
8295 g_free (icon_info->tooltip);
8297 /* Treat an empty string as a NULL string,
8298 * because an empty string would be useless for a tooltip:
8300 if (tooltip && tooltip[0] == '\0')
8303 icon_info->tooltip = tooltip ? g_markup_escape_text (tooltip, -1) : NULL;
8305 ensure_has_tooltip (entry);
8309 * gtk_entry_get_icon_tooltip_markup:
8310 * @entry: a #GtkEntry
8311 * @icon_pos: the icon position
8313 * Gets the contents of the tooltip on the icon at the specified
8314 * position in @entry.
8316 * Returns: the tooltip text, or %NULL. Free the returned string
8317 * with g_free() when done.
8322 gtk_entry_get_icon_tooltip_markup (GtkEntry *entry,
8323 GtkEntryIconPosition icon_pos)
8325 GtkEntryPrivate *priv;
8326 EntryIconInfo *icon_info;
8328 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8329 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8331 priv = GTK_ENTRY_GET_PRIVATE (entry);
8332 icon_info = priv->icons[icon_pos];
8337 return g_strdup (icon_info->tooltip);
8341 * gtk_entry_set_icon_tooltip_markup:
8342 * @entry: a #GtkEntry
8343 * @icon_pos: the icon position
8344 * @tooltip: (allow-none): the contents of the tooltip for the icon, or %NULL
8346 * Sets @tooltip as the contents of the tooltip for the icon at
8347 * the specified position. @tooltip is assumed to be marked up with
8348 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
8350 * Use %NULL for @tooltip to remove an existing tooltip.
8352 * See also gtk_widget_set_tooltip_markup() and
8353 * gtk_enty_set_icon_tooltip_text().
8358 gtk_entry_set_icon_tooltip_markup (GtkEntry *entry,
8359 GtkEntryIconPosition icon_pos,
8360 const gchar *tooltip)
8362 GtkEntryPrivate *priv;
8363 EntryIconInfo *icon_info;
8365 g_return_if_fail (GTK_IS_ENTRY (entry));
8366 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8368 priv = GTK_ENTRY_GET_PRIVATE (entry);
8370 if (!(icon_info = priv->icons[icon_pos]))
8371 icon_info = priv->icons[icon_pos];
8373 if (icon_info->tooltip)
8374 g_free (icon_info->tooltip);
8376 /* Treat an empty string as a NULL string,
8377 * because an empty string would be useless for a tooltip:
8379 if (tooltip && tooltip[0] == '\0')
8382 icon_info->tooltip = g_strdup (tooltip);
8384 ensure_has_tooltip (entry);
8388 gtk_entry_query_tooltip (GtkWidget *widget,
8391 gboolean keyboard_tip,
8392 GtkTooltip *tooltip)
8395 GtkEntryPrivate *priv;
8396 EntryIconInfo *icon_info;
8399 entry = GTK_ENTRY (widget);
8400 priv = GTK_ENTRY_GET_PRIVATE (entry);
8404 icon_pos = gtk_entry_get_icon_at_pos (entry, x, y);
8407 if ((icon_info = priv->icons[icon_pos]) != NULL)
8409 if (icon_info->tooltip)
8411 gtk_tooltip_set_markup (tooltip, icon_info->tooltip);
8420 return GTK_WIDGET_CLASS (gtk_entry_parent_class)->query_tooltip (widget,
8427 /* Quick hack of a popup menu
8430 activate_cb (GtkWidget *menuitem,
8433 const gchar *signal = g_object_get_data (G_OBJECT (menuitem), "gtk-signal");
8434 g_signal_emit_by_name (entry, signal);
8439 gtk_entry_mnemonic_activate (GtkWidget *widget,
8440 gboolean group_cycling)
8442 gtk_widget_grab_focus (widget);
8447 append_action_signal (GtkEntry *entry,
8449 const gchar *stock_id,
8450 const gchar *signal,
8453 GtkWidget *menuitem = gtk_image_menu_item_new_from_stock (stock_id, NULL);
8455 g_object_set_data (G_OBJECT (menuitem), I_("gtk-signal"), (char *)signal);
8456 g_signal_connect (menuitem, "activate",
8457 G_CALLBACK (activate_cb), entry);
8459 gtk_widget_set_sensitive (menuitem, sensitive);
8461 gtk_widget_show (menuitem);
8462 gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
8466 popup_menu_detach (GtkWidget *attach_widget,
8469 GTK_ENTRY (attach_widget)->popup_menu = NULL;
8473 popup_position_func (GtkMenu *menu,
8479 GtkEntry *entry = GTK_ENTRY (user_data);
8480 GtkWidget *widget = GTK_WIDGET (entry);
8482 GtkRequisition menu_req;
8483 GdkRectangle monitor;
8484 GtkBorder inner_border;
8485 gint monitor_num, strong_x, height;
8487 g_return_if_fail (gtk_widget_get_realized (widget));
8489 gdk_window_get_origin (entry->text_area, x, y);
8491 screen = gtk_widget_get_screen (widget);
8492 monitor_num = gdk_screen_get_monitor_at_window (screen, entry->text_area);
8493 if (monitor_num < 0)
8495 gtk_menu_set_monitor (menu, monitor_num);
8497 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
8498 gtk_widget_get_preferred_size (entry->popup_menu,
8500 height = gdk_window_get_height (entry->text_area);
8501 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
8502 _gtk_entry_effective_inner_border (entry, &inner_border);
8504 *x += inner_border.left + strong_x - entry->scroll_offset;
8505 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
8506 *x -= menu_req.width;
8508 if ((*y + height + menu_req.height) <= monitor.y + monitor.height)
8510 else if ((*y - menu_req.height) >= monitor.y)
8511 *y -= menu_req.height;
8512 else if (monitor.y + monitor.height - (*y + height) > *y)
8515 *y -= menu_req.height;
8521 unichar_chosen_func (const char *text,
8524 GtkEntry *entry = GTK_ENTRY (data);
8526 if (entry->editable)
8527 gtk_entry_enter_text (entry, text);
8538 popup_targets_received (GtkClipboard *clipboard,
8539 GtkSelectionData *data,
8542 PopupInfo *info = user_data;
8543 GtkEntry *entry = info->entry;
8545 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
8548 gboolean clipboard_contains_text;
8549 GtkWidget *menuitem;
8551 gboolean show_input_method_menu;
8552 gboolean show_unicode_menu;
8554 clipboard_contains_text = gtk_selection_data_targets_include_text (data);
8555 if (entry->popup_menu)
8556 gtk_widget_destroy (entry->popup_menu);
8558 entry->popup_menu = gtk_menu_new ();
8560 gtk_menu_attach_to_widget (GTK_MENU (entry->popup_menu),
8564 mode = gtk_entry_get_display_mode (entry);
8565 append_action_signal (entry, entry->popup_menu, GTK_STOCK_CUT, "cut-clipboard",
8566 entry->editable && mode == DISPLAY_NORMAL &&
8567 entry->current_pos != entry->selection_bound);
8569 append_action_signal (entry, entry->popup_menu, GTK_STOCK_COPY, "copy-clipboard",
8570 mode == DISPLAY_NORMAL &&
8571 entry->current_pos != entry->selection_bound);
8573 append_action_signal (entry, entry->popup_menu, GTK_STOCK_PASTE, "paste-clipboard",
8574 entry->editable && clipboard_contains_text);
8576 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_DELETE, NULL);
8577 gtk_widget_set_sensitive (menuitem, entry->editable && entry->current_pos != entry->selection_bound);
8578 g_signal_connect_swapped (menuitem, "activate",
8579 G_CALLBACK (gtk_entry_delete_cb), entry);
8580 gtk_widget_show (menuitem);
8581 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8583 menuitem = gtk_separator_menu_item_new ();
8584 gtk_widget_show (menuitem);
8585 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8587 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_SELECT_ALL, NULL);
8588 g_signal_connect_swapped (menuitem, "activate",
8589 G_CALLBACK (gtk_entry_select_all), entry);
8590 gtk_widget_show (menuitem);
8591 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8593 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
8594 "gtk-show-input-method-menu", &show_input_method_menu,
8595 "gtk-show-unicode-menu", &show_unicode_menu,
8598 if (show_input_method_menu || show_unicode_menu)
8600 menuitem = gtk_separator_menu_item_new ();
8601 gtk_widget_show (menuitem);
8602 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8605 if (show_input_method_menu)
8607 menuitem = gtk_menu_item_new_with_mnemonic (_("Input _Methods"));
8608 gtk_widget_set_sensitive (menuitem, entry->editable);
8609 gtk_widget_show (menuitem);
8610 submenu = gtk_menu_new ();
8611 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
8613 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8615 gtk_im_multicontext_append_menuitems (GTK_IM_MULTICONTEXT (entry->im_context),
8616 GTK_MENU_SHELL (submenu));
8619 if (show_unicode_menu)
8621 menuitem = gtk_menu_item_new_with_mnemonic (_("_Insert Unicode Control Character"));
8622 gtk_widget_set_sensitive (menuitem, entry->editable);
8623 gtk_widget_show (menuitem);
8625 submenu = gtk_menu_new ();
8626 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
8627 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8629 _gtk_text_util_append_special_char_menuitems (GTK_MENU_SHELL (submenu),
8630 unichar_chosen_func,
8634 g_signal_emit (entry,
8635 signals[POPULATE_POPUP],
8641 gtk_menu_popup (GTK_MENU (entry->popup_menu), NULL, NULL,
8643 info->button, info->time);
8646 gtk_menu_popup (GTK_MENU (entry->popup_menu), NULL, NULL,
8647 popup_position_func, entry,
8648 info->button, info->time);
8649 gtk_menu_shell_select_first (GTK_MENU_SHELL (entry->popup_menu), FALSE);
8653 g_object_unref (entry);
8654 g_slice_free (PopupInfo, info);
8658 gtk_entry_do_popup (GtkEntry *entry,
8659 GdkEventButton *event)
8661 PopupInfo *info = g_slice_new (PopupInfo);
8663 /* In order to know what entries we should make sensitive, we
8664 * ask for the current targets of the clipboard, and when
8665 * we get them, then we actually pop up the menu.
8667 info->entry = g_object_ref (entry);
8671 info->button = event->button;
8672 info->time = event->time;
8677 info->time = gtk_get_current_event_time ();
8680 gtk_clipboard_request_contents (gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_CLIPBOARD),
8681 gdk_atom_intern_static_string ("TARGETS"),
8682 popup_targets_received,
8687 gtk_entry_popup_menu (GtkWidget *widget)
8689 gtk_entry_do_popup (GTK_ENTRY (widget), NULL);
8694 gtk_entry_drag_begin (GtkWidget *widget,
8695 GdkDragContext *context)
8697 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
8700 for (i = 0; i < MAX_ICONS; i++)
8702 EntryIconInfo *icon_info = priv->icons[i];
8704 if (icon_info != NULL)
8706 if (icon_info->in_drag)
8708 switch (icon_info->storage_type)
8710 case GTK_IMAGE_STOCK:
8711 gtk_drag_set_icon_stock (context, icon_info->stock_id, -2, -2);
8714 case GTK_IMAGE_ICON_NAME:
8715 gtk_drag_set_icon_name (context, icon_info->icon_name, -2, -2);
8718 /* FIXME: No GIcon support for dnd icons */
8719 case GTK_IMAGE_GICON:
8720 case GTK_IMAGE_PIXBUF:
8721 gtk_drag_set_icon_pixbuf (context, icon_info->pixbuf, -2, -2);
8724 g_assert_not_reached ();
8732 gtk_entry_drag_end (GtkWidget *widget,
8733 GdkDragContext *context)
8735 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
8738 for (i = 0; i < MAX_ICONS; i++)
8740 EntryIconInfo *icon_info = priv->icons[i];
8742 if (icon_info != NULL)
8743 icon_info->in_drag = 0;
8748 gtk_entry_drag_leave (GtkWidget *widget,
8749 GdkDragContext *context,
8752 GtkEntry *entry = GTK_ENTRY (widget);
8754 entry->dnd_position = -1;
8755 gtk_widget_queue_draw (widget);
8759 gtk_entry_drag_drop (GtkWidget *widget,
8760 GdkDragContext *context,
8765 GtkEntry *entry = GTK_ENTRY (widget);
8766 GdkAtom target = GDK_NONE;
8768 if (entry->editable)
8769 target = gtk_drag_dest_find_target (widget, context, NULL);
8771 if (target != GDK_NONE)
8772 gtk_drag_get_data (widget, context, target, time);
8774 gtk_drag_finish (context, FALSE, FALSE, time);
8780 gtk_entry_drag_motion (GtkWidget *widget,
8781 GdkDragContext *context,
8786 GtkEntry *entry = GTK_ENTRY (widget);
8788 GtkWidget *source_widget;
8789 GdkDragAction suggested_action;
8790 gint new_position, old_position;
8793 style = gtk_widget_get_style (widget);
8794 x -= style->xthickness;
8795 y -= style->ythickness;
8797 old_position = entry->dnd_position;
8798 new_position = gtk_entry_find_position (entry, x + entry->scroll_offset);
8800 if (entry->editable &&
8801 gtk_drag_dest_find_target (widget, context, NULL) != GDK_NONE)
8803 source_widget = gtk_drag_get_source_widget (context);
8804 suggested_action = context->suggested_action;
8806 if (!gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &sel1, &sel2) ||
8807 new_position < sel1 || new_position > sel2)
8809 if (source_widget == widget)
8811 /* Default to MOVE, unless the user has
8812 * pressed ctrl or alt to affect available actions
8814 if ((context->actions & GDK_ACTION_MOVE) != 0)
8815 suggested_action = GDK_ACTION_MOVE;
8818 entry->dnd_position = new_position;
8822 if (source_widget == widget)
8823 suggested_action = 0; /* Can't drop in selection where drag started */
8825 entry->dnd_position = -1;
8830 /* Entry not editable, or no text */
8831 suggested_action = 0;
8832 entry->dnd_position = -1;
8835 gdk_drag_status (context, suggested_action, time);
8837 if (entry->dnd_position != old_position)
8838 gtk_widget_queue_draw (widget);
8844 gtk_entry_drag_data_received (GtkWidget *widget,
8845 GdkDragContext *context,
8848 GtkSelectionData *selection_data,
8852 GtkEntry *entry = GTK_ENTRY (widget);
8853 GtkEditable *editable = GTK_EDITABLE (widget);
8857 str = (gchar *) gtk_selection_data_get_text (selection_data);
8859 style = gtk_widget_get_style (widget);
8860 x -= style->xthickness;
8861 y -= style->ythickness;
8863 if (str && entry->editable)
8869 if (entry->truncate_multiline)
8870 length = truncate_multiline (str);
8872 new_position = gtk_entry_find_position (entry, x + entry->scroll_offset);
8874 if (!gtk_editable_get_selection_bounds (editable, &sel1, &sel2) ||
8875 new_position < sel1 || new_position > sel2)
8877 gtk_editable_insert_text (editable, str, length, &new_position);
8881 /* Replacing selection */
8882 begin_change (entry);
8883 g_object_freeze_notify (G_OBJECT (entry));
8884 gtk_editable_delete_text (editable, sel1, sel2);
8885 gtk_editable_insert_text (editable, str, length, &sel1);
8886 g_object_thaw_notify (G_OBJECT (entry));
8890 gtk_drag_finish (context, TRUE, context->action == GDK_ACTION_MOVE, time);
8894 /* Drag and drop didn't happen! */
8895 gtk_drag_finish (context, FALSE, FALSE, time);
8902 gtk_entry_drag_data_get (GtkWidget *widget,
8903 GdkDragContext *context,
8904 GtkSelectionData *selection_data,
8908 gint sel_start, sel_end;
8911 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
8912 GtkEditable *editable = GTK_EDITABLE (widget);
8914 /* If there is an icon drag going on, exit early. */
8915 for (i = 0; i < MAX_ICONS; i++)
8917 EntryIconInfo *icon_info = priv->icons[i];
8919 if (icon_info != NULL)
8921 if (icon_info->in_drag)
8926 if (gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end))
8928 gchar *str = gtk_entry_get_display_text (GTK_ENTRY (widget), sel_start, sel_end);
8930 gtk_selection_data_set_text (selection_data, str, -1);
8938 gtk_entry_drag_data_delete (GtkWidget *widget,
8939 GdkDragContext *context)
8941 gint sel_start, sel_end;
8944 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
8945 GtkEditable *editable = GTK_EDITABLE (widget);
8947 /* If there is an icon drag going on, exit early. */
8948 for (i = 0; i < MAX_ICONS; i++)
8950 EntryIconInfo *icon_info = priv->icons[i];
8952 if (icon_info != NULL)
8954 if (icon_info->in_drag)
8959 if (GTK_ENTRY (widget)->editable &&
8960 gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end))
8961 gtk_editable_delete_text (editable, sel_start, sel_end);
8964 /* We display the cursor when
8966 * - the selection is empty, AND
8967 * - the widget has focus
8970 #define CURSOR_ON_MULTIPLIER 2
8971 #define CURSOR_OFF_MULTIPLIER 1
8972 #define CURSOR_PEND_MULTIPLIER 3
8973 #define CURSOR_DIVIDER 3
8976 cursor_blinks (GtkEntry *entry)
8978 if (gtk_widget_has_focus (GTK_WIDGET (entry)) &&
8980 entry->selection_bound == entry->current_pos)
8982 GtkSettings *settings;
8985 settings = gtk_widget_get_settings (GTK_WIDGET (entry));
8986 g_object_get (settings, "gtk-cursor-blink", &blink, NULL);
8995 get_cursor_time (GtkEntry *entry)
8997 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9000 g_object_get (settings, "gtk-cursor-blink-time", &time, NULL);
9006 get_cursor_blink_timeout (GtkEntry *entry)
9008 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9011 g_object_get (settings, "gtk-cursor-blink-timeout", &timeout, NULL);
9017 show_cursor (GtkEntry *entry)
9021 if (!entry->cursor_visible)
9023 entry->cursor_visible = TRUE;
9025 widget = GTK_WIDGET (entry);
9026 if (gtk_widget_has_focus (widget) && entry->selection_bound == entry->current_pos)
9027 gtk_widget_queue_draw (widget);
9032 hide_cursor (GtkEntry *entry)
9036 if (entry->cursor_visible)
9038 entry->cursor_visible = FALSE;
9040 widget = GTK_WIDGET (entry);
9041 if (gtk_widget_has_focus (widget) && entry->selection_bound == entry->current_pos)
9042 gtk_widget_queue_draw (widget);
9050 blink_cb (gpointer data)
9053 GtkEntryPrivate *priv;
9056 entry = GTK_ENTRY (data);
9057 priv = GTK_ENTRY_GET_PRIVATE (entry);
9059 if (!gtk_widget_has_focus (GTK_WIDGET (entry)))
9061 g_warning ("GtkEntry - did not receive focus-out-event. If you\n"
9062 "connect a handler to this signal, it must return\n"
9063 "FALSE so the entry gets the event as well");
9065 gtk_entry_check_cursor_blink (entry);
9070 g_assert (entry->selection_bound == entry->current_pos);
9072 blink_timeout = get_cursor_blink_timeout (entry);
9073 if (priv->blink_time > 1000 * blink_timeout &&
9074 blink_timeout < G_MAXINT/1000)
9076 /* we've blinked enough without the user doing anything, stop blinking */
9077 show_cursor (entry);
9078 entry->blink_timeout = 0;
9080 else if (entry->cursor_visible)
9082 hide_cursor (entry);
9083 entry->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_OFF_MULTIPLIER / CURSOR_DIVIDER,
9089 show_cursor (entry);
9090 priv->blink_time += get_cursor_time (entry);
9091 entry->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
9096 /* Remove ourselves */
9101 gtk_entry_check_cursor_blink (GtkEntry *entry)
9103 GtkEntryPrivate *priv;
9105 priv = GTK_ENTRY_GET_PRIVATE (entry);
9107 if (cursor_blinks (entry))
9109 if (!entry->blink_timeout)
9111 show_cursor (entry);
9112 entry->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
9119 if (entry->blink_timeout)
9121 g_source_remove (entry->blink_timeout);
9122 entry->blink_timeout = 0;
9125 entry->cursor_visible = TRUE;
9131 gtk_entry_pend_cursor_blink (GtkEntry *entry)
9133 if (cursor_blinks (entry))
9135 if (entry->blink_timeout != 0)
9136 g_source_remove (entry->blink_timeout);
9138 entry->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_PEND_MULTIPLIER / CURSOR_DIVIDER,
9141 show_cursor (entry);
9146 gtk_entry_reset_blink_time (GtkEntry *entry)
9148 GtkEntryPrivate *priv;
9150 priv = GTK_ENTRY_GET_PRIVATE (entry);
9152 priv->blink_time = 0;
9158 gtk_entry_completion_timeout (gpointer data)
9160 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (data);
9161 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (completion->priv->entry);
9163 completion->priv->completion_timeout = 0;
9165 if (completion->priv->filter_model &&
9166 g_utf8_strlen (gtk_entry_get_text (GTK_ENTRY (completion->priv->entry)), -1)
9167 >= completion->priv->minimum_key_length)
9171 GtkTreeSelection *s;
9172 gboolean popup_single;
9174 gtk_entry_completion_complete (completion);
9175 matches = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->filter_model), NULL);
9177 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9179 s = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view));
9181 gtk_tree_selection_unselect_all (s);
9183 actions = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->actions), NULL);
9185 g_object_get (completion, "popup-single-match", &popup_single, NULL);
9186 if ((matches > (popup_single ? 0: 1)) || actions > 0)
9188 if (gtk_widget_get_visible (completion->priv->popup_window))
9189 _gtk_entry_completion_resize_popup (completion);
9191 _gtk_entry_completion_popup (completion, priv->completion_device);
9194 _gtk_entry_completion_popdown (completion);
9196 else if (gtk_widget_get_visible (completion->priv->popup_window))
9197 _gtk_entry_completion_popdown (completion);
9202 static inline gboolean
9203 keyval_is_cursor_move (guint keyval)
9205 if (keyval == GDK_KEY_Up || keyval == GDK_KEY_KP_Up)
9208 if (keyval == GDK_KEY_Down || keyval == GDK_KEY_KP_Down)
9211 if (keyval == GDK_KEY_Page_Up)
9214 if (keyval == GDK_KEY_Page_Down)
9221 gtk_entry_completion_key_press (GtkWidget *widget,
9225 gint matches, actions = 0;
9226 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
9228 if (!gtk_widget_get_mapped (completion->priv->popup_window))
9231 matches = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->filter_model), NULL);
9233 if (completion->priv->actions)
9234 actions = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->actions), NULL);
9236 if (keyval_is_cursor_move (event->keyval))
9238 GtkTreePath *path = NULL;
9240 if (event->keyval == GDK_KEY_Up || event->keyval == GDK_KEY_KP_Up)
9242 if (completion->priv->current_selected < 0)
9243 completion->priv->current_selected = matches + actions - 1;
9245 completion->priv->current_selected--;
9247 else if (event->keyval == GDK_KEY_Down || event->keyval == GDK_KEY_KP_Down)
9249 if (completion->priv->current_selected < matches + actions - 1)
9250 completion->priv->current_selected++;
9252 completion->priv->current_selected = -1;
9254 else if (event->keyval == GDK_KEY_Page_Up)
9256 if (completion->priv->current_selected < 0)
9257 completion->priv->current_selected = matches + actions - 1;
9258 else if (completion->priv->current_selected == 0)
9259 completion->priv->current_selected = -1;
9260 else if (completion->priv->current_selected < matches)
9262 completion->priv->current_selected -= 14;
9263 if (completion->priv->current_selected < 0)
9264 completion->priv->current_selected = 0;
9268 completion->priv->current_selected -= 14;
9269 if (completion->priv->current_selected < matches - 1)
9270 completion->priv->current_selected = matches - 1;
9273 else if (event->keyval == GDK_KEY_Page_Down)
9275 if (completion->priv->current_selected < 0)
9276 completion->priv->current_selected = 0;
9277 else if (completion->priv->current_selected < matches - 1)
9279 completion->priv->current_selected += 14;
9280 if (completion->priv->current_selected > matches - 1)
9281 completion->priv->current_selected = matches - 1;
9283 else if (completion->priv->current_selected == matches + actions - 1)
9285 completion->priv->current_selected = -1;
9289 completion->priv->current_selected += 14;
9290 if (completion->priv->current_selected > matches + actions - 1)
9291 completion->priv->current_selected = matches + actions - 1;
9295 if (completion->priv->current_selected < 0)
9297 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9298 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view)));
9300 if (completion->priv->inline_selection &&
9301 completion->priv->completion_prefix)
9303 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9304 completion->priv->completion_prefix);
9305 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9308 else if (completion->priv->current_selected < matches)
9310 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view)));
9312 path = gtk_tree_path_new_from_indices (completion->priv->current_selected, -1);
9313 gtk_tree_view_set_cursor (GTK_TREE_VIEW (completion->priv->tree_view),
9316 if (completion->priv->inline_selection)
9320 GtkTreeIter child_iter;
9321 GtkTreeModel *model = NULL;
9322 GtkTreeSelection *sel;
9325 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view));
9326 if (!gtk_tree_selection_get_selected (sel, &model, &iter))
9329 gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (model), &child_iter, &iter);
9330 model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model));
9332 if (completion->priv->completion_prefix == NULL)
9333 completion->priv->completion_prefix = g_strdup (gtk_entry_get_text (GTK_ENTRY (completion->priv->entry)));
9335 g_signal_emit_by_name (completion, "cursor-on-match", model,
9336 &child_iter, &entry_set);
9339 else if (completion->priv->current_selected - matches >= 0)
9341 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9343 path = gtk_tree_path_new_from_indices (completion->priv->current_selected - matches, -1);
9344 gtk_tree_view_set_cursor (GTK_TREE_VIEW (completion->priv->action_view),
9347 if (completion->priv->inline_selection &&
9348 completion->priv->completion_prefix)
9350 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9351 completion->priv->completion_prefix);
9352 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9356 gtk_tree_path_free (path);
9360 else if (event->keyval == GDK_KEY_Escape ||
9361 event->keyval == GDK_KEY_Left ||
9362 event->keyval == GDK_KEY_KP_Left ||
9363 event->keyval == GDK_KEY_Right ||
9364 event->keyval == GDK_KEY_KP_Right)
9366 gboolean retval = TRUE;
9368 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9369 _gtk_entry_completion_popdown (completion);
9371 if (completion->priv->current_selected < 0)
9374 goto keypress_completion_out;
9376 else if (completion->priv->inline_selection)
9378 /* Escape rejects the tentative completion */
9379 if (event->keyval == GDK_KEY_Escape)
9381 if (completion->priv->completion_prefix)
9382 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9383 completion->priv->completion_prefix);
9385 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry), "");
9388 /* Move the cursor to the end for Right/Esc, to the
9389 beginning for Left */
9390 if (event->keyval == GDK_KEY_Right ||
9391 event->keyval == GDK_KEY_KP_Right ||
9392 event->keyval == GDK_KEY_Escape)
9393 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9395 gtk_editable_set_position (GTK_EDITABLE (widget), 0);
9398 keypress_completion_out:
9399 if (completion->priv->inline_selection)
9401 g_free (completion->priv->completion_prefix);
9402 completion->priv->completion_prefix = NULL;
9407 else if (event->keyval == GDK_KEY_Tab ||
9408 event->keyval == GDK_KEY_KP_Tab ||
9409 event->keyval == GDK_KEY_ISO_Left_Tab)
9411 GtkDirectionType dir = event->keyval == GDK_KEY_ISO_Left_Tab ?
9412 GTK_DIR_TAB_BACKWARD : GTK_DIR_TAB_FORWARD;
9414 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9415 _gtk_entry_completion_popdown (completion);
9417 g_free (completion->priv->completion_prefix);
9418 completion->priv->completion_prefix = NULL;
9420 gtk_widget_child_focus (gtk_widget_get_toplevel (widget), dir);
9424 else if (event->keyval == GDK_KEY_ISO_Enter ||
9425 event->keyval == GDK_KEY_KP_Enter ||
9426 event->keyval == GDK_KEY_Return)
9429 GtkTreeModel *model = NULL;
9430 GtkTreeSelection *sel;
9431 gboolean retval = TRUE;
9433 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9434 _gtk_entry_completion_popdown (completion);
9436 if (completion->priv->current_selected < matches)
9440 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view));
9441 if (gtk_tree_selection_get_selected (sel, &model, &iter))
9443 g_signal_handler_block (widget, completion->priv->changed_id);
9444 g_signal_emit_by_name (completion, "match-selected",
9445 model, &iter, &entry_set);
9446 g_signal_handler_unblock (widget, completion->priv->changed_id);
9452 gtk_tree_model_get (model, &iter,
9453 completion->priv->text_column, &str,
9456 gtk_entry_set_text (GTK_ENTRY (widget), str);
9458 /* move the cursor to the end */
9459 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9467 else if (completion->priv->current_selected - matches >= 0)
9469 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view));
9470 if (gtk_tree_selection_get_selected (sel, &model, &iter))
9474 path = gtk_tree_path_new_from_indices (completion->priv->current_selected - matches, -1);
9475 g_signal_emit_by_name (completion, "action-activated",
9476 gtk_tree_path_get_indices (path)[0]);
9477 gtk_tree_path_free (path);
9483 g_free (completion->priv->completion_prefix);
9484 completion->priv->completion_prefix = NULL;
9493 gtk_entry_completion_changed (GtkWidget *entry,
9496 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
9497 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
9500 /* (re)install completion timeout */
9501 if (completion->priv->completion_timeout)
9502 g_source_remove (completion->priv->completion_timeout);
9504 if (!gtk_entry_get_text (GTK_ENTRY (entry)))
9507 /* no need to normalize for this test */
9508 if (completion->priv->minimum_key_length > 0 &&
9509 strcmp ("", gtk_entry_get_text (GTK_ENTRY (entry))) == 0)
9511 if (gtk_widget_get_visible (completion->priv->popup_window))
9512 _gtk_entry_completion_popdown (completion);
9516 device = gtk_get_current_event_device ();
9518 if (device && device->source == GDK_SOURCE_KEYBOARD)
9519 device = gdk_device_get_associated_device (device);
9522 priv->completion_device = device;
9524 completion->priv->completion_timeout =
9525 gdk_threads_add_timeout (COMPLETION_TIMEOUT,
9526 gtk_entry_completion_timeout,
9531 check_completion_callback (GtkEntryCompletion *completion)
9533 completion->priv->check_completion_idle = NULL;
9535 gtk_entry_completion_complete (completion);
9536 gtk_entry_completion_insert_prefix (completion);
9542 clear_completion_callback (GtkEntry *entry,
9545 if (pspec->name == I_("cursor-position") ||
9546 pspec->name == I_("selection-bound"))
9548 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
9550 completion->priv->has_completion = FALSE;
9555 accept_completion_callback (GtkEntry *entry)
9557 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
9559 if (completion->priv->has_completion)
9560 gtk_editable_set_position (GTK_EDITABLE (entry),
9561 gtk_entry_buffer_get_length (get_buffer (entry)));
9567 completion_insert_text_callback (GtkEntry *entry,
9571 GtkEntryCompletion *completion)
9573 /* idle to update the selection based on the file list */
9574 if (completion->priv->check_completion_idle == NULL)
9576 completion->priv->check_completion_idle = g_idle_source_new ();
9577 g_source_set_priority (completion->priv->check_completion_idle, G_PRIORITY_HIGH);
9578 g_source_set_closure (completion->priv->check_completion_idle,
9579 g_cclosure_new_object (G_CALLBACK (check_completion_callback),
9580 G_OBJECT (completion)));
9581 g_source_attach (completion->priv->check_completion_idle, NULL);
9586 completion_changed (GtkEntryCompletion *completion,
9590 GtkEntry *entry = GTK_ENTRY (data);
9592 if (pspec->name == I_("popup-completion") ||
9593 pspec->name == I_("inline-completion"))
9595 disconnect_completion_signals (entry, completion);
9596 connect_completion_signals (entry, completion);
9601 disconnect_completion_signals (GtkEntry *entry,
9602 GtkEntryCompletion *completion)
9604 g_signal_handlers_disconnect_by_func (completion,
9605 G_CALLBACK (completion_changed), entry);
9606 if (completion->priv->changed_id > 0 &&
9607 g_signal_handler_is_connected (entry, completion->priv->changed_id))
9609 g_signal_handler_disconnect (entry, completion->priv->changed_id);
9610 completion->priv->changed_id = 0;
9612 g_signal_handlers_disconnect_by_func (entry,
9613 G_CALLBACK (gtk_entry_completion_key_press), completion);
9614 if (completion->priv->insert_text_id > 0 &&
9615 g_signal_handler_is_connected (entry, completion->priv->insert_text_id))
9617 g_signal_handler_disconnect (entry, completion->priv->insert_text_id);
9618 completion->priv->insert_text_id = 0;
9620 g_signal_handlers_disconnect_by_func (entry,
9621 G_CALLBACK (completion_insert_text_callback), completion);
9622 g_signal_handlers_disconnect_by_func (entry,
9623 G_CALLBACK (clear_completion_callback), completion);
9624 g_signal_handlers_disconnect_by_func (entry,
9625 G_CALLBACK (accept_completion_callback), completion);
9629 connect_completion_signals (GtkEntry *entry,
9630 GtkEntryCompletion *completion)
9632 if (completion->priv->popup_completion)
9634 completion->priv->changed_id =
9635 g_signal_connect (entry, "changed",
9636 G_CALLBACK (gtk_entry_completion_changed), completion);
9637 g_signal_connect (entry, "key-press-event",
9638 G_CALLBACK (gtk_entry_completion_key_press), completion);
9641 if (completion->priv->inline_completion)
9643 completion->priv->insert_text_id =
9644 g_signal_connect (entry, "insert-text",
9645 G_CALLBACK (completion_insert_text_callback), completion);
9646 g_signal_connect (entry, "notify",
9647 G_CALLBACK (clear_completion_callback), completion);
9648 g_signal_connect (entry, "activate",
9649 G_CALLBACK (accept_completion_callback), completion);
9650 g_signal_connect (entry, "focus-out-event",
9651 G_CALLBACK (accept_completion_callback), completion);
9654 g_signal_connect (completion, "notify",
9655 G_CALLBACK (completion_changed), entry);
9659 * gtk_entry_set_completion:
9660 * @entry: A #GtkEntry
9661 * @completion: (allow-none): The #GtkEntryCompletion or %NULL
9663 * Sets @completion to be the auxiliary completion object to use with @entry.
9664 * All further configuration of the completion mechanism is done on
9665 * @completion using the #GtkEntryCompletion API. Completion is disabled if
9666 * @completion is set to %NULL.
9671 gtk_entry_set_completion (GtkEntry *entry,
9672 GtkEntryCompletion *completion)
9674 GtkEntryCompletion *old;
9676 g_return_if_fail (GTK_IS_ENTRY (entry));
9677 g_return_if_fail (!completion || GTK_IS_ENTRY_COMPLETION (completion));
9679 old = gtk_entry_get_completion (entry);
9681 if (old == completion)
9686 if (old->priv->completion_timeout)
9688 g_source_remove (old->priv->completion_timeout);
9689 old->priv->completion_timeout = 0;
9692 if (gtk_widget_get_mapped (old->priv->popup_window))
9693 _gtk_entry_completion_popdown (old);
9695 disconnect_completion_signals (entry, old);
9696 old->priv->entry = NULL;
9698 g_object_unref (old);
9703 g_object_set_data (G_OBJECT (entry), I_(GTK_ENTRY_COMPLETION_KEY), NULL);
9707 /* hook into the entry */
9708 g_object_ref (completion);
9710 connect_completion_signals (entry, completion);
9711 completion->priv->entry = GTK_WIDGET (entry);
9712 g_object_set_data (G_OBJECT (entry), I_(GTK_ENTRY_COMPLETION_KEY), completion);
9716 * gtk_entry_get_completion:
9717 * @entry: A #GtkEntry
9719 * Returns the auxiliary completion object currently in use by @entry.
9721 * Return value: (transfer none): The auxiliary completion object currently
9726 GtkEntryCompletion *
9727 gtk_entry_get_completion (GtkEntry *entry)
9729 GtkEntryCompletion *completion;
9731 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
9733 completion = GTK_ENTRY_COMPLETION (g_object_get_data (G_OBJECT (entry),
9734 GTK_ENTRY_COMPLETION_KEY));
9740 * gtk_entry_set_cursor_hadjustment:
9741 * @entry: a #GtkEntry
9742 * @adjustment: an adjustment which should be adjusted when the cursor
9743 * is moved, or %NULL
9745 * Hooks up an adjustment to the cursor position in an entry, so that when
9746 * the cursor is moved, the adjustment is scrolled to show that position.
9747 * See gtk_scrolled_window_get_hadjustment() for a typical way of obtaining
9750 * The adjustment has to be in pixel units and in the same coordinate system
9756 gtk_entry_set_cursor_hadjustment (GtkEntry *entry,
9757 GtkAdjustment *adjustment)
9759 g_return_if_fail (GTK_IS_ENTRY (entry));
9761 g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
9764 g_object_ref (adjustment);
9766 g_object_set_qdata_full (G_OBJECT (entry),
9767 quark_cursor_hadjustment,
9773 * gtk_entry_get_cursor_hadjustment:
9774 * @entry: a #GtkEntry
9776 * Retrieves the horizontal cursor adjustment for the entry.
9777 * See gtk_entry_set_cursor_hadjustment().
9779 * Return value: (transfer none): the horizontal cursor adjustment, or %NULL
9780 * if none has been set.
9785 gtk_entry_get_cursor_hadjustment (GtkEntry *entry)
9787 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
9789 return g_object_get_qdata (G_OBJECT (entry), quark_cursor_hadjustment);
9793 * gtk_entry_set_progress_fraction:
9794 * @entry: a #GtkEntry
9795 * @fraction: fraction of the task that's been completed
9797 * Causes the entry's progress indicator to "fill in" the given
9798 * fraction of the bar. The fraction should be between 0.0 and 1.0,
9804 gtk_entry_set_progress_fraction (GtkEntry *entry,
9808 GtkEntryPrivate *private;
9809 gdouble old_fraction;
9810 gint x, y, width, height;
9811 gint old_x, old_y, old_width, old_height;
9813 g_return_if_fail (GTK_IS_ENTRY (entry));
9815 widget = GTK_WIDGET (entry);
9816 private = GTK_ENTRY_GET_PRIVATE (entry);
9818 if (private->progress_pulse_mode)
9821 old_fraction = private->progress_fraction;
9823 if (gtk_widget_is_drawable (widget))
9824 get_progress_area (widget, &old_x, &old_y, &old_width, &old_height);
9826 fraction = CLAMP (fraction, 0.0, 1.0);
9828 private->progress_fraction = fraction;
9829 private->progress_pulse_mode = FALSE;
9830 private->progress_pulse_current = 0.0;
9832 if (gtk_widget_is_drawable (widget))
9834 get_progress_area (widget, &x, &y, &width, &height);
9836 if ((x != old_x) || (y != old_y) || (width != old_width) || (height != old_height))
9837 gtk_widget_queue_draw (widget);
9840 if (fraction != old_fraction)
9841 g_object_notify (G_OBJECT (entry), "progress-fraction");
9845 * gtk_entry_get_progress_fraction:
9846 * @entry: a #GtkEntry
9848 * Returns the current fraction of the task that's been completed.
9849 * See gtk_entry_set_progress_fraction().
9851 * Return value: a fraction from 0.0 to 1.0
9856 gtk_entry_get_progress_fraction (GtkEntry *entry)
9858 GtkEntryPrivate *private;
9860 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
9862 private = GTK_ENTRY_GET_PRIVATE (entry);
9864 return private->progress_fraction;
9868 * gtk_entry_set_progress_pulse_step:
9869 * @entry: a #GtkEntry
9870 * @fraction: fraction between 0.0 and 1.0
9872 * Sets the fraction of total entry width to move the progress
9873 * bouncing block for each call to gtk_entry_progress_pulse().
9878 gtk_entry_set_progress_pulse_step (GtkEntry *entry,
9881 GtkEntryPrivate *private;
9883 g_return_if_fail (GTK_IS_ENTRY (entry));
9885 private = GTK_ENTRY_GET_PRIVATE (entry);
9887 fraction = CLAMP (fraction, 0.0, 1.0);
9889 if (fraction != private->progress_pulse_fraction)
9891 private->progress_pulse_fraction = fraction;
9893 gtk_widget_queue_draw (GTK_WIDGET (entry));
9895 g_object_notify (G_OBJECT (entry), "progress-pulse-step");
9900 * gtk_entry_get_progress_pulse_step:
9901 * @entry: a #GtkEntry
9903 * Retrieves the pulse step set with gtk_entry_set_progress_pulse_step().
9905 * Return value: a fraction from 0.0 to 1.0
9910 gtk_entry_get_progress_pulse_step (GtkEntry *entry)
9912 GtkEntryPrivate *private;
9914 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
9916 private = GTK_ENTRY_GET_PRIVATE (entry);
9918 return private->progress_pulse_fraction;
9922 * gtk_entry_progress_pulse:
9923 * @entry: a #GtkEntry
9925 * Indicates that some progress is made, but you don't know how much.
9926 * Causes the entry's progress indicator to enter "activity mode,"
9927 * where a block bounces back and forth. Each call to
9928 * gtk_entry_progress_pulse() causes the block to move by a little bit
9929 * (the amount of movement per pulse is determined by
9930 * gtk_entry_set_progress_pulse_step()).
9935 gtk_entry_progress_pulse (GtkEntry *entry)
9937 GtkEntryPrivate *private;
9939 g_return_if_fail (GTK_IS_ENTRY (entry));
9941 private = GTK_ENTRY_GET_PRIVATE (entry);
9943 if (private->progress_pulse_mode)
9945 if (private->progress_pulse_way_back)
9947 private->progress_pulse_current -= private->progress_pulse_fraction;
9949 if (private->progress_pulse_current < 0.0)
9951 private->progress_pulse_current = 0.0;
9952 private->progress_pulse_way_back = FALSE;
9957 private->progress_pulse_current += private->progress_pulse_fraction;
9959 if (private->progress_pulse_current > 1.0 - private->progress_pulse_fraction)
9961 private->progress_pulse_current = 1.0 - private->progress_pulse_fraction;
9962 private->progress_pulse_way_back = TRUE;
9968 private->progress_fraction = 0.0;
9969 private->progress_pulse_mode = TRUE;
9970 private->progress_pulse_way_back = FALSE;
9971 private->progress_pulse_current = 0.0;
9974 gtk_widget_queue_draw (GTK_WIDGET (entry));
9977 /* Caps Lock warning for password entries */
9980 show_capslock_feedback (GtkEntry *entry,
9983 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
9985 if (gtk_entry_get_icon_storage_type (entry, GTK_ENTRY_ICON_SECONDARY) == GTK_IMAGE_EMPTY)
9987 gtk_entry_set_icon_from_stock (entry, GTK_ENTRY_ICON_SECONDARY, GTK_STOCK_CAPS_LOCK_WARNING);
9988 gtk_entry_set_icon_activatable (entry, GTK_ENTRY_ICON_SECONDARY, FALSE);
9989 priv->caps_lock_warning_shown = TRUE;
9992 if (priv->caps_lock_warning_shown)
9993 gtk_entry_set_icon_tooltip_text (entry, GTK_ENTRY_ICON_SECONDARY, text);
9995 g_warning ("Can't show Caps Lock warning, since secondary icon is set");
9999 remove_capslock_feedback (GtkEntry *entry)
10001 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
10003 if (priv->caps_lock_warning_shown)
10005 gtk_entry_set_icon_from_stock (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
10006 priv->caps_lock_warning_shown = FALSE;
10011 keymap_state_changed (GdkKeymap *keymap,
10014 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
10017 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL && priv->caps_lock_warning)
10019 if (gdk_keymap_get_num_lock_state (keymap)
10020 && gdk_keymap_get_caps_lock_state (keymap))
10021 text = _("Caps Lock and Num Lock are on");
10022 else if (gdk_keymap_get_num_lock_state (keymap))
10023 text = _("Num Lock is on");
10024 else if (gdk_keymap_get_caps_lock_state (keymap))
10025 text = _("Caps Lock is on");
10029 show_capslock_feedback (entry, text);
10031 remove_capslock_feedback (entry);