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 */
239 /* GObject, GtkObject methods
241 static void gtk_entry_editable_init (GtkEditableClass *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_destroy (GtkObject *object);
253 static void gtk_entry_dispose (GObject *object);
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_size_request (GtkWidget *widget,
262 GtkRequisition *requisition);
263 static void gtk_entry_size_allocate (GtkWidget *widget,
264 GtkAllocation *allocation);
265 static void gtk_entry_draw_frame (GtkWidget *widget,
266 GdkEventExpose *event);
267 static void gtk_entry_draw_progress (GtkWidget *widget,
268 GdkEventExpose *event);
269 static gint gtk_entry_expose (GtkWidget *widget,
270 GdkEventExpose *event);
271 static gint gtk_entry_button_press (GtkWidget *widget,
272 GdkEventButton *event);
273 static gint gtk_entry_button_release (GtkWidget *widget,
274 GdkEventButton *event);
275 static gint gtk_entry_enter_notify (GtkWidget *widget,
276 GdkEventCrossing *event);
277 static gint gtk_entry_leave_notify (GtkWidget *widget,
278 GdkEventCrossing *event);
279 static gint gtk_entry_motion_notify (GtkWidget *widget,
280 GdkEventMotion *event);
281 static gint gtk_entry_key_press (GtkWidget *widget,
283 static gint gtk_entry_key_release (GtkWidget *widget,
285 static gint gtk_entry_focus_in (GtkWidget *widget,
286 GdkEventFocus *event);
287 static gint gtk_entry_focus_out (GtkWidget *widget,
288 GdkEventFocus *event);
289 static void gtk_entry_grab_focus (GtkWidget *widget);
290 static void gtk_entry_style_set (GtkWidget *widget,
291 GtkStyle *previous_style);
292 static gboolean gtk_entry_query_tooltip (GtkWidget *widget,
295 gboolean keyboard_tip,
296 GtkTooltip *tooltip);
297 static void gtk_entry_direction_changed (GtkWidget *widget,
298 GtkTextDirection previous_dir);
299 static void gtk_entry_state_changed (GtkWidget *widget,
300 GtkStateType previous_state);
301 static void gtk_entry_screen_changed (GtkWidget *widget,
302 GdkScreen *old_screen);
304 static gboolean gtk_entry_drag_drop (GtkWidget *widget,
305 GdkDragContext *context,
309 static gboolean gtk_entry_drag_motion (GtkWidget *widget,
310 GdkDragContext *context,
314 static void gtk_entry_drag_leave (GtkWidget *widget,
315 GdkDragContext *context,
317 static void gtk_entry_drag_data_received (GtkWidget *widget,
318 GdkDragContext *context,
321 GtkSelectionData *selection_data,
324 static void gtk_entry_drag_data_get (GtkWidget *widget,
325 GdkDragContext *context,
326 GtkSelectionData *selection_data,
329 static void gtk_entry_drag_data_delete (GtkWidget *widget,
330 GdkDragContext *context);
331 static void gtk_entry_drag_begin (GtkWidget *widget,
332 GdkDragContext *context);
333 static void gtk_entry_drag_end (GtkWidget *widget,
334 GdkDragContext *context);
337 /* GtkEditable method implementations
339 static void gtk_entry_insert_text (GtkEditable *editable,
340 const gchar *new_text,
341 gint new_text_length,
343 static void gtk_entry_delete_text (GtkEditable *editable,
346 static gchar * gtk_entry_get_chars (GtkEditable *editable,
349 static void gtk_entry_real_set_position (GtkEditable *editable,
351 static gint gtk_entry_get_position (GtkEditable *editable);
352 static void gtk_entry_set_selection_bounds (GtkEditable *editable,
355 static gboolean gtk_entry_get_selection_bounds (GtkEditable *editable,
359 /* GtkCellEditable method implementations
361 static void gtk_entry_start_editing (GtkCellEditable *cell_editable,
364 /* Default signal handlers
366 static void gtk_entry_real_insert_text (GtkEditable *editable,
367 const gchar *new_text,
368 gint new_text_length,
370 static void gtk_entry_real_delete_text (GtkEditable *editable,
373 static void gtk_entry_move_cursor (GtkEntry *entry,
374 GtkMovementStep step,
376 gboolean extend_selection);
377 static void gtk_entry_insert_at_cursor (GtkEntry *entry,
379 static void gtk_entry_delete_from_cursor (GtkEntry *entry,
382 static void gtk_entry_backspace (GtkEntry *entry);
383 static void gtk_entry_cut_clipboard (GtkEntry *entry);
384 static void gtk_entry_copy_clipboard (GtkEntry *entry);
385 static void gtk_entry_paste_clipboard (GtkEntry *entry);
386 static void gtk_entry_toggle_overwrite (GtkEntry *entry);
387 static void gtk_entry_select_all (GtkEntry *entry);
388 static void gtk_entry_real_activate (GtkEntry *entry);
389 static gboolean gtk_entry_popup_menu (GtkWidget *widget);
391 static void keymap_direction_changed (GdkKeymap *keymap,
393 static void keymap_state_changed (GdkKeymap *keymap,
395 static void remove_capslock_feedback (GtkEntry *entry);
397 /* IM Context Callbacks
399 static void gtk_entry_commit_cb (GtkIMContext *context,
402 static void gtk_entry_preedit_changed_cb (GtkIMContext *context,
404 static gboolean gtk_entry_retrieve_surrounding_cb (GtkIMContext *context,
406 static gboolean gtk_entry_delete_surrounding_cb (GtkIMContext *context,
413 static void gtk_entry_enter_text (GtkEntry *entry,
415 static void gtk_entry_set_positions (GtkEntry *entry,
417 gint selection_bound);
418 static void gtk_entry_draw_text (GtkEntry *entry);
419 static void gtk_entry_draw_cursor (GtkEntry *entry,
421 static PangoLayout *gtk_entry_ensure_layout (GtkEntry *entry,
422 gboolean include_preedit);
423 static void gtk_entry_reset_layout (GtkEntry *entry);
424 static void gtk_entry_queue_draw (GtkEntry *entry);
425 static void gtk_entry_recompute (GtkEntry *entry);
426 static gint gtk_entry_find_position (GtkEntry *entry,
428 static void gtk_entry_get_cursor_locations (GtkEntry *entry,
432 static void gtk_entry_adjust_scroll (GtkEntry *entry);
433 static gint gtk_entry_move_visually (GtkEntry *editable,
436 static gint gtk_entry_move_logically (GtkEntry *entry,
439 static gint gtk_entry_move_forward_word (GtkEntry *entry,
441 gboolean allow_whitespace);
442 static gint gtk_entry_move_backward_word (GtkEntry *entry,
444 gboolean allow_whitespace);
445 static void gtk_entry_delete_whitespace (GtkEntry *entry);
446 static void gtk_entry_select_word (GtkEntry *entry);
447 static void gtk_entry_select_line (GtkEntry *entry);
448 static void gtk_entry_paste (GtkEntry *entry,
450 static void gtk_entry_update_primary_selection (GtkEntry *entry);
451 static void gtk_entry_do_popup (GtkEntry *entry,
452 GdkEventButton *event);
453 static gboolean gtk_entry_mnemonic_activate (GtkWidget *widget,
454 gboolean group_cycling);
455 static void gtk_entry_check_cursor_blink (GtkEntry *entry);
456 static void gtk_entry_pend_cursor_blink (GtkEntry *entry);
457 static void gtk_entry_reset_blink_time (GtkEntry *entry);
458 static void gtk_entry_get_text_area_size (GtkEntry *entry,
463 static void get_text_area_size (GtkEntry *entry,
468 static void get_widget_window_size (GtkEntry *entry,
473 static void gtk_entry_move_adjustments (GtkEntry *entry);
474 static void gtk_entry_ensure_pixbuf (GtkEntry *entry,
475 GtkEntryIconPosition icon_pos);
479 static gint gtk_entry_completion_timeout (gpointer data);
480 static gboolean gtk_entry_completion_key_press (GtkWidget *widget,
483 static void gtk_entry_completion_changed (GtkWidget *entry,
485 static gboolean check_completion_callback (GtkEntryCompletion *completion);
486 static void clear_completion_callback (GtkEntry *entry,
488 static gboolean accept_completion_callback (GtkEntry *entry);
489 static void completion_insert_text_callback (GtkEntry *entry,
493 GtkEntryCompletion *completion);
494 static void completion_changed (GtkEntryCompletion *completion,
497 static void disconnect_completion_signals (GtkEntry *entry,
498 GtkEntryCompletion *completion);
499 static void connect_completion_signals (GtkEntry *entry,
500 GtkEntryCompletion *completion);
502 static void begin_change (GtkEntry *entry);
503 static void end_change (GtkEntry *entry);
504 static void emit_changed (GtkEntry *entry);
507 static void buffer_inserted_text (GtkEntryBuffer *buffer,
512 static void buffer_deleted_text (GtkEntryBuffer *buffer,
516 static void buffer_notify_text (GtkEntryBuffer *buffer,
519 static void buffer_notify_length (GtkEntryBuffer *buffer,
522 static void buffer_notify_max_length (GtkEntryBuffer *buffer,
525 static void buffer_connect_signals (GtkEntry *entry);
526 static void buffer_disconnect_signals (GtkEntry *entry);
527 static GtkEntryBuffer *get_buffer (GtkEntry *entry);
530 G_DEFINE_TYPE_WITH_CODE (GtkEntry, gtk_entry, GTK_TYPE_WIDGET,
531 G_IMPLEMENT_INTERFACE (GTK_TYPE_EDITABLE,
532 gtk_entry_editable_init)
533 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_EDITABLE,
534 gtk_entry_cell_editable_init))
537 add_move_binding (GtkBindingSet *binding_set,
540 GtkMovementStep step,
543 g_return_if_fail ((modmask & GDK_SHIFT_MASK) == 0);
545 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
549 G_TYPE_BOOLEAN, FALSE);
551 /* Selection-extending version */
552 gtk_binding_entry_add_signal (binding_set, keyval, modmask | GDK_SHIFT_MASK,
556 G_TYPE_BOOLEAN, TRUE);
560 gtk_entry_class_init (GtkEntryClass *class)
562 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
563 GtkWidgetClass *widget_class;
564 GtkObjectClass *gtk_object_class;
565 GtkBindingSet *binding_set;
567 widget_class = (GtkWidgetClass*) class;
568 gtk_object_class = (GtkObjectClass *)class;
570 gobject_class->dispose = gtk_entry_dispose;
571 gobject_class->finalize = gtk_entry_finalize;
572 gobject_class->set_property = gtk_entry_set_property;
573 gobject_class->get_property = gtk_entry_get_property;
575 widget_class->map = gtk_entry_map;
576 widget_class->unmap = gtk_entry_unmap;
577 widget_class->realize = gtk_entry_realize;
578 widget_class->unrealize = gtk_entry_unrealize;
579 widget_class->size_request = gtk_entry_size_request;
580 widget_class->size_allocate = gtk_entry_size_allocate;
581 widget_class->expose_event = gtk_entry_expose;
582 widget_class->enter_notify_event = gtk_entry_enter_notify;
583 widget_class->leave_notify_event = gtk_entry_leave_notify;
584 widget_class->button_press_event = gtk_entry_button_press;
585 widget_class->button_release_event = gtk_entry_button_release;
586 widget_class->motion_notify_event = gtk_entry_motion_notify;
587 widget_class->key_press_event = gtk_entry_key_press;
588 widget_class->key_release_event = gtk_entry_key_release;
589 widget_class->focus_in_event = gtk_entry_focus_in;
590 widget_class->focus_out_event = gtk_entry_focus_out;
591 widget_class->grab_focus = gtk_entry_grab_focus;
592 widget_class->style_set = gtk_entry_style_set;
593 widget_class->query_tooltip = gtk_entry_query_tooltip;
594 widget_class->drag_begin = gtk_entry_drag_begin;
595 widget_class->drag_end = gtk_entry_drag_end;
596 widget_class->direction_changed = gtk_entry_direction_changed;
597 widget_class->state_changed = gtk_entry_state_changed;
598 widget_class->screen_changed = gtk_entry_screen_changed;
599 widget_class->mnemonic_activate = gtk_entry_mnemonic_activate;
601 widget_class->drag_drop = gtk_entry_drag_drop;
602 widget_class->drag_motion = gtk_entry_drag_motion;
603 widget_class->drag_leave = gtk_entry_drag_leave;
604 widget_class->drag_data_received = gtk_entry_drag_data_received;
605 widget_class->drag_data_get = gtk_entry_drag_data_get;
606 widget_class->drag_data_delete = gtk_entry_drag_data_delete;
608 widget_class->popup_menu = gtk_entry_popup_menu;
610 gtk_object_class->destroy = gtk_entry_destroy;
612 class->move_cursor = gtk_entry_move_cursor;
613 class->insert_at_cursor = gtk_entry_insert_at_cursor;
614 class->delete_from_cursor = gtk_entry_delete_from_cursor;
615 class->backspace = gtk_entry_backspace;
616 class->cut_clipboard = gtk_entry_cut_clipboard;
617 class->copy_clipboard = gtk_entry_copy_clipboard;
618 class->paste_clipboard = gtk_entry_paste_clipboard;
619 class->toggle_overwrite = gtk_entry_toggle_overwrite;
620 class->activate = gtk_entry_real_activate;
621 class->get_text_area_size = gtk_entry_get_text_area_size;
623 quark_inner_border = g_quark_from_static_string ("gtk-entry-inner-border");
624 quark_password_hint = g_quark_from_static_string ("gtk-entry-password-hint");
625 quark_cursor_hadjustment = g_quark_from_static_string ("gtk-hadjustment");
626 quark_capslock_feedback = g_quark_from_static_string ("gtk-entry-capslock-feedback");
628 g_object_class_override_property (gobject_class,
629 PROP_EDITING_CANCELED,
632 g_object_class_install_property (gobject_class,
634 g_param_spec_object ("buffer",
636 P_("Text buffer object which actually stores entry text"),
637 GTK_TYPE_ENTRY_BUFFER,
638 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT));
640 g_object_class_install_property (gobject_class,
641 PROP_CURSOR_POSITION,
642 g_param_spec_int ("cursor-position",
643 P_("Cursor Position"),
644 P_("The current position of the insertion cursor in chars"),
646 GTK_ENTRY_BUFFER_MAX_SIZE,
648 GTK_PARAM_READABLE));
650 g_object_class_install_property (gobject_class,
651 PROP_SELECTION_BOUND,
652 g_param_spec_int ("selection-bound",
653 P_("Selection Bound"),
654 P_("The position of the opposite end of the selection from the cursor in chars"),
656 GTK_ENTRY_BUFFER_MAX_SIZE,
658 GTK_PARAM_READABLE));
660 g_object_class_install_property (gobject_class,
662 g_param_spec_boolean ("editable",
664 P_("Whether the entry contents can be edited"),
666 GTK_PARAM_READWRITE));
668 g_object_class_install_property (gobject_class,
670 g_param_spec_int ("max-length",
671 P_("Maximum length"),
672 P_("Maximum number of characters for this entry. Zero if no maximum"),
674 GTK_ENTRY_BUFFER_MAX_SIZE,
676 GTK_PARAM_READWRITE));
677 g_object_class_install_property (gobject_class,
679 g_param_spec_boolean ("visibility",
681 P_("FALSE displays the \"invisible char\" instead of the actual text (password mode)"),
683 GTK_PARAM_READWRITE));
685 g_object_class_install_property (gobject_class,
687 g_param_spec_boolean ("has-frame",
689 P_("FALSE removes outside bevel from entry"),
691 GTK_PARAM_READWRITE));
693 g_object_class_install_property (gobject_class,
695 g_param_spec_boxed ("inner-border",
697 P_("Border between text and frame. Overrides the inner-border style property"),
699 GTK_PARAM_READWRITE));
701 g_object_class_install_property (gobject_class,
703 g_param_spec_unichar ("invisible-char",
704 P_("Invisible character"),
705 P_("The character to use when masking entry contents (in \"password mode\")"),
707 GTK_PARAM_READWRITE));
709 g_object_class_install_property (gobject_class,
710 PROP_ACTIVATES_DEFAULT,
711 g_param_spec_boolean ("activates-default",
712 P_("Activates default"),
713 P_("Whether to activate the default widget (such as the default button in a dialog) when Enter is pressed"),
715 GTK_PARAM_READWRITE));
716 g_object_class_install_property (gobject_class,
718 g_param_spec_int ("width-chars",
719 P_("Width in chars"),
720 P_("Number of characters to leave space for in the entry"),
724 GTK_PARAM_READWRITE));
726 g_object_class_install_property (gobject_class,
728 g_param_spec_int ("scroll-offset",
730 P_("Number of pixels of the entry scrolled off the screen to the left"),
734 GTK_PARAM_READABLE));
736 g_object_class_install_property (gobject_class,
738 g_param_spec_string ("text",
740 P_("The contents of the entry"),
742 GTK_PARAM_READWRITE));
747 * The horizontal alignment, from 0 (left) to 1 (right).
748 * Reversed for RTL layouts.
752 g_object_class_install_property (gobject_class,
754 g_param_spec_float ("xalign",
756 P_("The horizontal alignment, from 0 (left) to 1 (right). Reversed for RTL layouts."),
760 GTK_PARAM_READWRITE));
763 * GtkEntry:truncate-multiline:
765 * When %TRUE, pasted multi-line text is truncated to the first line.
769 g_object_class_install_property (gobject_class,
770 PROP_TRUNCATE_MULTILINE,
771 g_param_spec_boolean ("truncate-multiline",
772 P_("Truncate multiline"),
773 P_("Whether to truncate multiline pastes to one line."),
775 GTK_PARAM_READWRITE));
778 * GtkEntry:shadow-type:
780 * Which kind of shadow to draw around the entry when
781 * #GtkEntry:has-frame is set to %TRUE.
785 g_object_class_install_property (gobject_class,
787 g_param_spec_enum ("shadow-type",
789 P_("Which kind of shadow to draw around the entry when has-frame is set"),
790 GTK_TYPE_SHADOW_TYPE,
792 GTK_PARAM_READWRITE));
795 * GtkEntry:overwrite-mode:
797 * If text is overwritten when typing in the #GtkEntry.
801 g_object_class_install_property (gobject_class,
803 g_param_spec_boolean ("overwrite-mode",
804 P_("Overwrite mode"),
805 P_("Whether new text overwrites existing text"),
807 GTK_PARAM_READWRITE));
810 * GtkEntry:text-length:
812 * The length of the text in the #GtkEntry.
816 g_object_class_install_property (gobject_class,
818 g_param_spec_uint ("text-length",
820 P_("Length of the text currently in the entry"),
824 GTK_PARAM_READABLE));
826 * GtkEntry:invisible-char-set:
828 * Whether the invisible char has been set for the #GtkEntry.
832 g_object_class_install_property (gobject_class,
833 PROP_INVISIBLE_CHAR_SET,
834 g_param_spec_boolean ("invisible-char-set",
835 P_("Invisible character set"),
836 P_("Whether the invisible character has been set"),
838 GTK_PARAM_READWRITE));
841 * GtkEntry:caps-lock-warning
843 * Whether password entries will show a warning when Caps Lock is on.
845 * Note that the warning is shown using a secondary icon, and thus
846 * does not work if you are using the secondary icon position for some
851 g_object_class_install_property (gobject_class,
852 PROP_CAPS_LOCK_WARNING,
853 g_param_spec_boolean ("caps-lock-warning",
854 P_("Caps Lock warning"),
855 P_("Whether password entries will show a warning when Caps Lock is on"),
857 GTK_PARAM_READWRITE));
860 * GtkEntry:progress-fraction:
862 * The current fraction of the task that's been completed.
866 g_object_class_install_property (gobject_class,
867 PROP_PROGRESS_FRACTION,
868 g_param_spec_double ("progress-fraction",
869 P_("Progress Fraction"),
870 P_("The current fraction of the task that's been completed"),
874 GTK_PARAM_READWRITE));
877 * GtkEntry:progress-pulse-step:
879 * The fraction of total entry width to move the progress
880 * bouncing block for each call to gtk_entry_progress_pulse().
884 g_object_class_install_property (gobject_class,
885 PROP_PROGRESS_PULSE_STEP,
886 g_param_spec_double ("progress-pulse-step",
887 P_("Progress Pulse Step"),
888 P_("The fraction of total entry width to move the progress bouncing block for each call to gtk_entry_progress_pulse()"),
892 GTK_PARAM_READWRITE));
895 * GtkEntry:primary-icon-pixbuf:
897 * A pixbuf to use as the primary icon for the entry.
901 g_object_class_install_property (gobject_class,
903 g_param_spec_object ("primary-icon-pixbuf",
904 P_("Primary pixbuf"),
905 P_("Primary pixbuf for the entry"),
907 GTK_PARAM_READWRITE));
910 * GtkEntry:secondary-icon-pixbuf:
912 * An pixbuf to use as the secondary icon for the entry.
916 g_object_class_install_property (gobject_class,
917 PROP_PIXBUF_SECONDARY,
918 g_param_spec_object ("secondary-icon-pixbuf",
919 P_("Secondary pixbuf"),
920 P_("Secondary pixbuf for the entry"),
922 GTK_PARAM_READWRITE));
925 * GtkEntry:primary-icon-stock:
927 * The stock id to use for the primary icon for the entry.
931 g_object_class_install_property (gobject_class,
933 g_param_spec_string ("primary-icon-stock",
934 P_("Primary stock ID"),
935 P_("Stock ID for primary icon"),
937 GTK_PARAM_READWRITE));
940 * GtkEntry:secondary-icon-stock:
942 * The stock id to use for the secondary icon for the entry.
946 g_object_class_install_property (gobject_class,
947 PROP_STOCK_SECONDARY,
948 g_param_spec_string ("secondary-icon-stock",
949 P_("Secondary stock ID"),
950 P_("Stock ID for secondary icon"),
952 GTK_PARAM_READWRITE));
955 * GtkEntry:primary-icon-name:
957 * The icon name to use for the primary icon for the entry.
961 g_object_class_install_property (gobject_class,
962 PROP_ICON_NAME_PRIMARY,
963 g_param_spec_string ("primary-icon-name",
964 P_("Primary icon name"),
965 P_("Icon name for primary icon"),
967 GTK_PARAM_READWRITE));
970 * GtkEntry:secondary-icon-name:
972 * The icon name to use for the secondary icon for the entry.
976 g_object_class_install_property (gobject_class,
977 PROP_ICON_NAME_SECONDARY,
978 g_param_spec_string ("secondary-icon-name",
979 P_("Secondary icon name"),
980 P_("Icon name for secondary icon"),
982 GTK_PARAM_READWRITE));
985 * GtkEntry:primary-icon-gicon:
987 * The #GIcon to use for the primary icon for the entry.
991 g_object_class_install_property (gobject_class,
993 g_param_spec_object ("primary-icon-gicon",
995 P_("GIcon for primary icon"),
997 GTK_PARAM_READWRITE));
1000 * GtkEntry:secondary-icon-gicon:
1002 * The #GIcon to use for the secondary icon for the entry.
1006 g_object_class_install_property (gobject_class,
1007 PROP_GICON_SECONDARY,
1008 g_param_spec_object ("secondary-icon-gicon",
1009 P_("Secondary GIcon"),
1010 P_("GIcon for secondary icon"),
1012 GTK_PARAM_READWRITE));
1015 * GtkEntry:primary-icon-storage-type:
1017 * The representation which is used for the primary icon of the entry.
1021 g_object_class_install_property (gobject_class,
1022 PROP_STORAGE_TYPE_PRIMARY,
1023 g_param_spec_enum ("primary-icon-storage-type",
1024 P_("Primary storage type"),
1025 P_("The representation being used for primary icon"),
1026 GTK_TYPE_IMAGE_TYPE,
1028 GTK_PARAM_READABLE));
1031 * GtkEntry:secondary-icon-storage-type:
1033 * The representation which is used for the secondary icon of the entry.
1037 g_object_class_install_property (gobject_class,
1038 PROP_STORAGE_TYPE_SECONDARY,
1039 g_param_spec_enum ("secondary-icon-storage-type",
1040 P_("Secondary storage type"),
1041 P_("The representation being used for secondary icon"),
1042 GTK_TYPE_IMAGE_TYPE,
1044 GTK_PARAM_READABLE));
1047 * GtkEntry:primary-icon-activatable:
1049 * Whether the primary icon is activatable.
1051 * GTK+ emits the #GtkEntry::icon-press and #GtkEntry::icon-release
1052 * signals only on sensitive, activatable icons.
1054 * Sensitive, but non-activatable icons can be used for purely
1055 * informational purposes.
1059 g_object_class_install_property (gobject_class,
1060 PROP_ACTIVATABLE_PRIMARY,
1061 g_param_spec_boolean ("primary-icon-activatable",
1062 P_("Primary icon activatable"),
1063 P_("Whether the primary icon is activatable"),
1065 GTK_PARAM_READWRITE));
1068 * GtkEntry:secondary-icon-activatable:
1070 * Whether the secondary icon is activatable.
1072 * GTK+ emits the #GtkEntry::icon-press and #GtkEntry::icon-release
1073 * signals only on sensitive, activatable icons.
1075 * Sensitive, but non-activatable icons can be used for purely
1076 * informational purposes.
1080 g_object_class_install_property (gobject_class,
1081 PROP_ACTIVATABLE_SECONDARY,
1082 g_param_spec_boolean ("secondary-icon-activatable",
1083 P_("Secondary icon activatable"),
1084 P_("Whether the secondary icon is activatable"),
1086 GTK_PARAM_READWRITE));
1090 * GtkEntry:primary-icon-sensitive:
1092 * Whether the primary icon is sensitive.
1094 * An insensitive icon appears grayed out. GTK+ does not emit the
1095 * #GtkEntry::icon-press and #GtkEntry::icon-release signals and
1096 * does not allow DND from insensitive icons.
1098 * An icon should be set insensitive if the action that would trigger
1099 * when clicked is currently not available.
1103 g_object_class_install_property (gobject_class,
1104 PROP_SENSITIVE_PRIMARY,
1105 g_param_spec_boolean ("primary-icon-sensitive",
1106 P_("Primary icon sensitive"),
1107 P_("Whether the primary icon is sensitive"),
1109 GTK_PARAM_READWRITE));
1112 * GtkEntry:secondary-icon-sensitive:
1114 * Whether the secondary icon is sensitive.
1116 * An insensitive icon appears grayed out. GTK+ does not emit the
1117 * #GtkEntry::icon-press and #GtkEntry::icon-release signals and
1118 * does not allow DND from insensitive icons.
1120 * An icon should be set insensitive if the action that would trigger
1121 * when clicked is currently not available.
1125 g_object_class_install_property (gobject_class,
1126 PROP_SENSITIVE_SECONDARY,
1127 g_param_spec_boolean ("secondary-icon-sensitive",
1128 P_("Secondary icon sensitive"),
1129 P_("Whether the secondary icon is sensitive"),
1131 GTK_PARAM_READWRITE));
1134 * GtkEntry:primary-icon-tooltip-text:
1136 * The contents of the tooltip on the primary icon.
1138 * Also see gtk_entry_set_icon_tooltip_text().
1142 g_object_class_install_property (gobject_class,
1143 PROP_TOOLTIP_TEXT_PRIMARY,
1144 g_param_spec_string ("primary-icon-tooltip-text",
1145 P_("Primary icon tooltip text"),
1146 P_("The contents of the tooltip on the primary icon"),
1148 GTK_PARAM_READWRITE));
1151 * GtkEntry:secondary-icon-tooltip-text:
1153 * The contents of the tooltip on the secondary icon.
1155 * Also see gtk_entry_set_icon_tooltip_text().
1159 g_object_class_install_property (gobject_class,
1160 PROP_TOOLTIP_TEXT_SECONDARY,
1161 g_param_spec_string ("secondary-icon-tooltip-text",
1162 P_("Secondary icon tooltip text"),
1163 P_("The contents of the tooltip on the secondary icon"),
1165 GTK_PARAM_READWRITE));
1168 * GtkEntry:primary-icon-tooltip-markup:
1170 * The contents of the tooltip on the primary icon, which is marked up
1171 * with the <link linkend="PangoMarkupFormat">Pango text markup
1174 * Also see gtk_entry_set_icon_tooltip_markup().
1178 g_object_class_install_property (gobject_class,
1179 PROP_TOOLTIP_MARKUP_PRIMARY,
1180 g_param_spec_string ("primary-icon-tooltip-markup",
1181 P_("Primary icon tooltip markup"),
1182 P_("The contents of the tooltip on the primary icon"),
1184 GTK_PARAM_READWRITE));
1187 * GtkEntry:secondary-icon-tooltip-markup:
1189 * The contents of the tooltip on the secondary icon, which is marked up
1190 * with the <link linkend="PangoMarkupFormat">Pango text markup
1193 * Also see gtk_entry_set_icon_tooltip_markup().
1197 g_object_class_install_property (gobject_class,
1198 PROP_TOOLTIP_MARKUP_SECONDARY,
1199 g_param_spec_string ("secondary-icon-tooltip-markup",
1200 P_("Secondary icon tooltip markup"),
1201 P_("The contents of the tooltip on the secondary icon"),
1203 GTK_PARAM_READWRITE));
1206 * GtkEntry:im-module:
1208 * Which IM (input method) module should be used for this entry.
1209 * See #GtkIMContext.
1211 * Setting this to a non-%NULL value overrides the
1212 * system-wide IM module setting. See the GtkSettings
1213 * #GtkSettings:gtk-im-module property.
1217 g_object_class_install_property (gobject_class,
1219 g_param_spec_string ("im-module",
1221 P_("Which IM module should be used"),
1223 GTK_PARAM_READWRITE));
1226 * GtkEntry:icon-prelight:
1228 * The prelight style property determines whether activatable
1229 * icons prelight on mouseover.
1233 gtk_widget_class_install_style_property (widget_class,
1234 g_param_spec_boolean ("icon-prelight",
1235 P_("Icon Prelight"),
1236 P_("Whether activatable icons should prelight when hovered"),
1238 GTK_PARAM_READABLE));
1241 * GtkEntry:progress-border:
1243 * The border around the progress bar in the entry.
1247 gtk_widget_class_install_style_property (widget_class,
1248 g_param_spec_boxed ("progress-border",
1249 P_("Progress Border"),
1250 P_("Border around the progress bar"),
1252 GTK_PARAM_READABLE));
1255 * GtkEntry:invisible-char:
1257 * The invisible character is used when masking entry contents (in
1258 * \"password mode\")"). When it is not explicitly set with the
1259 * #GtkEntry::invisible-char property, GTK+ determines the character
1260 * to use from a list of possible candidates, depending on availability
1261 * in the current font.
1263 * This style property allows the theme to prepend a character
1264 * to the list of candidates.
1268 gtk_widget_class_install_style_property (widget_class,
1269 g_param_spec_unichar ("invisible-char",
1270 P_("Invisible character"),
1271 P_("The character to use when masking entry contents (in \"password mode\")"),
1273 GTK_PARAM_READABLE));
1276 * GtkEntry::populate-popup:
1277 * @entry: The entry on which the signal is emitted
1278 * @menu: the menu that is being populated
1280 * The ::populate-popup signal gets emitted before showing the
1281 * context menu of the entry.
1283 * If you need to add items to the context menu, connect
1284 * to this signal and append your menuitems to the @menu.
1286 signals[POPULATE_POPUP] =
1287 g_signal_new (I_("populate-popup"),
1288 G_OBJECT_CLASS_TYPE (gobject_class),
1290 G_STRUCT_OFFSET (GtkEntryClass, populate_popup),
1292 _gtk_marshal_VOID__OBJECT,
1296 /* Action signals */
1299 * GtkEntry::activate:
1300 * @entry: The entry on which the signal is emitted
1302 * A <link linkend="keybinding-signals">keybinding signal</link>
1303 * which gets emitted when the user activates the entry.
1305 * Applications should not connect to it, but may emit it with
1306 * g_signal_emit_by_name() if they need to control activation
1309 * The default bindings for this signal are all forms of the Enter key.
1312 g_signal_new (I_("activate"),
1313 G_OBJECT_CLASS_TYPE (gobject_class),
1314 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1315 G_STRUCT_OFFSET (GtkEntryClass, activate),
1317 _gtk_marshal_VOID__VOID,
1319 widget_class->activate_signal = signals[ACTIVATE];
1322 * GtkEntry::move-cursor:
1323 * @entry: the object which received the signal
1324 * @step: the granularity of the move, as a #GtkMovementStep
1325 * @count: the number of @step units to move
1326 * @extend_selection: %TRUE if the move should extend the selection
1328 * The ::move-cursor signal is a
1329 * <link linkend="keybinding-signals">keybinding signal</link>
1330 * which gets emitted when the user initiates a cursor movement.
1331 * If the cursor is not visible in @entry, this signal causes
1332 * the viewport to be moved instead.
1334 * Applications should not connect to it, but may emit it with
1335 * g_signal_emit_by_name() if they need to control the cursor
1338 * The default bindings for this signal come in two variants,
1339 * the variant with the Shift modifier extends the selection,
1340 * the variant without the Shift modifer does not.
1341 * There are too many key combinations to list them all here.
1343 * <listitem>Arrow keys move by individual characters/lines</listitem>
1344 * <listitem>Ctrl-arrow key combinations move by words/paragraphs</listitem>
1345 * <listitem>Home/End keys move to the ends of the buffer</listitem>
1348 signals[MOVE_CURSOR] =
1349 g_signal_new (I_("move-cursor"),
1350 G_OBJECT_CLASS_TYPE (gobject_class),
1351 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1352 G_STRUCT_OFFSET (GtkEntryClass, move_cursor),
1354 _gtk_marshal_VOID__ENUM_INT_BOOLEAN,
1356 GTK_TYPE_MOVEMENT_STEP,
1361 * GtkEntry::insert-at-cursor:
1362 * @entry: the object which received the signal
1363 * @string: the string to insert
1365 * The ::insert-at-cursor signal is a
1366 * <link linkend="keybinding-signals">keybinding signal</link>
1367 * which gets emitted when the user initiates the insertion of a
1368 * fixed string at the cursor.
1370 * This signal has no default bindings.
1372 signals[INSERT_AT_CURSOR] =
1373 g_signal_new (I_("insert-at-cursor"),
1374 G_OBJECT_CLASS_TYPE (gobject_class),
1375 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1376 G_STRUCT_OFFSET (GtkEntryClass, insert_at_cursor),
1378 _gtk_marshal_VOID__STRING,
1383 * GtkEntry::delete-from-cursor:
1384 * @entry: the object which received the signal
1385 * @type: the granularity of the deletion, as a #GtkDeleteType
1386 * @count: the number of @type units to delete
1388 * The ::delete-from-cursor signal is a
1389 * <link linkend="keybinding-signals">keybinding signal</link>
1390 * which gets emitted when the user initiates a text deletion.
1392 * If the @type is %GTK_DELETE_CHARS, GTK+ deletes the selection
1393 * if there is one, otherwise it deletes the requested number
1396 * The default bindings for this signal are
1397 * Delete for deleting a character and Ctrl-Delete for
1400 signals[DELETE_FROM_CURSOR] =
1401 g_signal_new (I_("delete-from-cursor"),
1402 G_OBJECT_CLASS_TYPE (gobject_class),
1403 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1404 G_STRUCT_OFFSET (GtkEntryClass, delete_from_cursor),
1406 _gtk_marshal_VOID__ENUM_INT,
1408 GTK_TYPE_DELETE_TYPE,
1412 * GtkEntry::backspace:
1413 * @entry: the object which received the signal
1415 * The ::backspace signal is a
1416 * <link linkend="keybinding-signals">keybinding signal</link>
1417 * which gets emitted when the user asks for it.
1419 * The default bindings for this signal are
1420 * Backspace and Shift-Backspace.
1422 signals[BACKSPACE] =
1423 g_signal_new (I_("backspace"),
1424 G_OBJECT_CLASS_TYPE (gobject_class),
1425 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1426 G_STRUCT_OFFSET (GtkEntryClass, backspace),
1428 _gtk_marshal_VOID__VOID,
1432 * GtkEntry::cut-clipboard:
1433 * @entry: the object which received the signal
1435 * The ::cut-clipboard signal is a
1436 * <link linkend="keybinding-signals">keybinding signal</link>
1437 * which gets emitted to cut the selection to the clipboard.
1439 * The default bindings for this signal are
1440 * Ctrl-x and Shift-Delete.
1442 signals[CUT_CLIPBOARD] =
1443 g_signal_new (I_("cut-clipboard"),
1444 G_OBJECT_CLASS_TYPE (gobject_class),
1445 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1446 G_STRUCT_OFFSET (GtkEntryClass, cut_clipboard),
1448 _gtk_marshal_VOID__VOID,
1452 * GtkEntry::copy-clipboard:
1453 * @entry: the object which received the signal
1455 * The ::copy-clipboard signal is a
1456 * <link linkend="keybinding-signals">keybinding signal</link>
1457 * which gets emitted to copy the selection to the clipboard.
1459 * The default bindings for this signal are
1460 * Ctrl-c and Ctrl-Insert.
1462 signals[COPY_CLIPBOARD] =
1463 g_signal_new (I_("copy-clipboard"),
1464 G_OBJECT_CLASS_TYPE (gobject_class),
1465 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1466 G_STRUCT_OFFSET (GtkEntryClass, copy_clipboard),
1468 _gtk_marshal_VOID__VOID,
1472 * GtkEntry::paste-clipboard:
1473 * @entry: the object which received the signal
1475 * The ::paste-clipboard signal is a
1476 * <link linkend="keybinding-signals">keybinding signal</link>
1477 * which gets emitted to paste the contents of the clipboard
1478 * into the text view.
1480 * The default bindings for this signal are
1481 * Ctrl-v and Shift-Insert.
1483 signals[PASTE_CLIPBOARD] =
1484 g_signal_new (I_("paste-clipboard"),
1485 G_OBJECT_CLASS_TYPE (gobject_class),
1486 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1487 G_STRUCT_OFFSET (GtkEntryClass, paste_clipboard),
1489 _gtk_marshal_VOID__VOID,
1493 * GtkEntry::toggle-overwrite:
1494 * @entry: the object which received the signal
1496 * The ::toggle-overwrite signal is a
1497 * <link linkend="keybinding-signals">keybinding signal</link>
1498 * which gets emitted to toggle the overwrite mode of the entry.
1500 * The default bindings for this signal is Insert.
1502 signals[TOGGLE_OVERWRITE] =
1503 g_signal_new (I_("toggle-overwrite"),
1504 G_OBJECT_CLASS_TYPE (gobject_class),
1505 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1506 G_STRUCT_OFFSET (GtkEntryClass, toggle_overwrite),
1508 _gtk_marshal_VOID__VOID,
1512 * GtkEntry::icon-press:
1513 * @entry: The entry on which the signal is emitted
1514 * @icon_pos: The position of the clicked icon
1515 * @event: the button press event
1517 * The ::icon-press signal is emitted when an activatable icon
1522 signals[ICON_PRESS] =
1523 g_signal_new (I_("icon-press"),
1524 G_TYPE_FROM_CLASS (gobject_class),
1528 _gtk_marshal_VOID__ENUM_BOXED,
1530 GTK_TYPE_ENTRY_ICON_POSITION,
1531 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1534 * GtkEntry::icon-release:
1535 * @entry: The entry on which the signal is emitted
1536 * @icon_pos: The position of the clicked icon
1537 * @event: the button release event
1539 * The ::icon-release signal is emitted on the button release from a
1540 * mouse click over an activatable icon.
1544 signals[ICON_RELEASE] =
1545 g_signal_new (I_("icon-release"),
1546 G_TYPE_FROM_CLASS (gobject_class),
1550 _gtk_marshal_VOID__ENUM_BOXED,
1552 GTK_TYPE_ENTRY_ICON_POSITION,
1553 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1556 * GtkEntry::preedit-changed:
1557 * @entry: the object which received the signal
1558 * @preedit: the current preedit string
1560 * If an input method is used, the typed text will not immediately
1561 * be committed to the buffer. So if you are interested in the text,
1562 * connect to this signal.
1566 signals[PREEDIT_CHANGED] =
1567 g_signal_new_class_handler (I_("preedit-changed"),
1568 G_OBJECT_CLASS_TYPE (gobject_class),
1569 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1572 _gtk_marshal_VOID__STRING,
1581 binding_set = gtk_binding_set_by_class (class);
1583 /* Moving the insertion point */
1584 add_move_binding (binding_set, GDK_Right, 0,
1585 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1587 add_move_binding (binding_set, GDK_Left, 0,
1588 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1590 add_move_binding (binding_set, GDK_KP_Right, 0,
1591 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1593 add_move_binding (binding_set, GDK_KP_Left, 0,
1594 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1596 add_move_binding (binding_set, GDK_Right, GDK_CONTROL_MASK,
1597 GTK_MOVEMENT_WORDS, 1);
1599 add_move_binding (binding_set, GDK_Left, GDK_CONTROL_MASK,
1600 GTK_MOVEMENT_WORDS, -1);
1602 add_move_binding (binding_set, GDK_KP_Right, GDK_CONTROL_MASK,
1603 GTK_MOVEMENT_WORDS, 1);
1605 add_move_binding (binding_set, GDK_KP_Left, GDK_CONTROL_MASK,
1606 GTK_MOVEMENT_WORDS, -1);
1608 add_move_binding (binding_set, GDK_Home, 0,
1609 GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
1611 add_move_binding (binding_set, GDK_End, 0,
1612 GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
1614 add_move_binding (binding_set, GDK_KP_Home, 0,
1615 GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
1617 add_move_binding (binding_set, GDK_KP_End, 0,
1618 GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
1620 add_move_binding (binding_set, GDK_Home, GDK_CONTROL_MASK,
1621 GTK_MOVEMENT_BUFFER_ENDS, -1);
1623 add_move_binding (binding_set, GDK_End, GDK_CONTROL_MASK,
1624 GTK_MOVEMENT_BUFFER_ENDS, 1);
1626 add_move_binding (binding_set, GDK_KP_Home, GDK_CONTROL_MASK,
1627 GTK_MOVEMENT_BUFFER_ENDS, -1);
1629 add_move_binding (binding_set, GDK_KP_End, GDK_CONTROL_MASK,
1630 GTK_MOVEMENT_BUFFER_ENDS, 1);
1634 gtk_binding_entry_add_signal (binding_set, GDK_a, GDK_CONTROL_MASK,
1636 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1638 G_TYPE_BOOLEAN, FALSE);
1639 gtk_binding_entry_add_signal (binding_set, GDK_a, GDK_CONTROL_MASK,
1641 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1643 G_TYPE_BOOLEAN, TRUE);
1645 gtk_binding_entry_add_signal (binding_set, GDK_slash, GDK_CONTROL_MASK,
1647 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1649 G_TYPE_BOOLEAN, FALSE);
1650 gtk_binding_entry_add_signal (binding_set, GDK_slash, GDK_CONTROL_MASK,
1652 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1654 G_TYPE_BOOLEAN, TRUE);
1657 gtk_binding_entry_add_signal (binding_set, GDK_backslash, GDK_CONTROL_MASK,
1659 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_VISUAL_POSITIONS,
1661 G_TYPE_BOOLEAN, FALSE);
1662 gtk_binding_entry_add_signal (binding_set, GDK_a, GDK_SHIFT_MASK | GDK_CONTROL_MASK,
1664 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_VISUAL_POSITIONS,
1666 G_TYPE_BOOLEAN, FALSE);
1670 gtk_binding_entry_add_signal (binding_set, GDK_Return, 0,
1672 gtk_binding_entry_add_signal (binding_set, GDK_ISO_Enter, 0,
1674 gtk_binding_entry_add_signal (binding_set, GDK_KP_Enter, 0,
1678 gtk_binding_entry_add_signal (binding_set, GDK_Delete, 0,
1679 "delete-from-cursor", 2,
1680 G_TYPE_ENUM, GTK_DELETE_CHARS,
1683 gtk_binding_entry_add_signal (binding_set, GDK_KP_Delete, 0,
1684 "delete-from-cursor", 2,
1685 G_TYPE_ENUM, GTK_DELETE_CHARS,
1688 gtk_binding_entry_add_signal (binding_set, GDK_BackSpace, 0,
1691 /* Make this do the same as Backspace, to help with mis-typing */
1692 gtk_binding_entry_add_signal (binding_set, GDK_BackSpace, GDK_SHIFT_MASK,
1695 gtk_binding_entry_add_signal (binding_set, GDK_Delete, GDK_CONTROL_MASK,
1696 "delete-from-cursor", 2,
1697 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1700 gtk_binding_entry_add_signal (binding_set, GDK_KP_Delete, GDK_CONTROL_MASK,
1701 "delete-from-cursor", 2,
1702 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1705 gtk_binding_entry_add_signal (binding_set, GDK_BackSpace, GDK_CONTROL_MASK,
1706 "delete-from-cursor", 2,
1707 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1710 /* Cut/copy/paste */
1712 gtk_binding_entry_add_signal (binding_set, GDK_x, GDK_CONTROL_MASK,
1713 "cut-clipboard", 0);
1714 gtk_binding_entry_add_signal (binding_set, GDK_c, GDK_CONTROL_MASK,
1715 "copy-clipboard", 0);
1716 gtk_binding_entry_add_signal (binding_set, GDK_v, GDK_CONTROL_MASK,
1717 "paste-clipboard", 0);
1719 gtk_binding_entry_add_signal (binding_set, GDK_Delete, GDK_SHIFT_MASK,
1720 "cut-clipboard", 0);
1721 gtk_binding_entry_add_signal (binding_set, GDK_Insert, GDK_CONTROL_MASK,
1722 "copy-clipboard", 0);
1723 gtk_binding_entry_add_signal (binding_set, GDK_Insert, GDK_SHIFT_MASK,
1724 "paste-clipboard", 0);
1727 gtk_binding_entry_add_signal (binding_set, GDK_Insert, 0,
1728 "toggle-overwrite", 0);
1729 gtk_binding_entry_add_signal (binding_set, GDK_KP_Insert, 0,
1730 "toggle-overwrite", 0);
1733 * GtkEntry:inner-border:
1735 * Sets the text area's border between the text and the frame.
1739 gtk_widget_class_install_style_property (widget_class,
1740 g_param_spec_boxed ("inner-border",
1742 P_("Border between text and frame."),
1744 GTK_PARAM_READABLE));
1747 * GtkEntry:state-hint:
1749 * Indicates whether to pass a proper widget state when
1750 * drawing the shadow and the widget background.
1754 gtk_widget_class_install_style_property (widget_class,
1755 g_param_spec_boolean ("state-hint",
1757 P_("Whether to pass a proper state when drawing shadow or background"),
1759 GTK_PARAM_READABLE));
1761 gtk_settings_install_property (g_param_spec_boolean ("gtk-entry-select-on-focus",
1762 P_("Select on focus"),
1763 P_("Whether to select the contents of an entry when it is focused"),
1765 GTK_PARAM_READWRITE));
1768 * GtkSettings:gtk-entry-password-hint-timeout:
1770 * How long to show the last input character in hidden
1771 * entries. This value is in milliseconds. 0 disables showing the
1772 * last char. 600 is a good value for enabling it.
1776 gtk_settings_install_property (g_param_spec_uint ("gtk-entry-password-hint-timeout",
1777 P_("Password Hint Timeout"),
1778 P_("How long to show the last input character in hidden entries"),
1780 GTK_PARAM_READWRITE));
1782 g_type_class_add_private (gobject_class, sizeof (GtkEntryPrivate));
1786 gtk_entry_editable_init (GtkEditableClass *iface)
1788 iface->do_insert_text = gtk_entry_insert_text;
1789 iface->do_delete_text = gtk_entry_delete_text;
1790 iface->insert_text = gtk_entry_real_insert_text;
1791 iface->delete_text = gtk_entry_real_delete_text;
1792 iface->get_chars = gtk_entry_get_chars;
1793 iface->set_selection_bounds = gtk_entry_set_selection_bounds;
1794 iface->get_selection_bounds = gtk_entry_get_selection_bounds;
1795 iface->set_position = gtk_entry_real_set_position;
1796 iface->get_position = gtk_entry_get_position;
1800 gtk_entry_cell_editable_init (GtkCellEditableIface *iface)
1802 iface->start_editing = gtk_entry_start_editing;
1806 gtk_entry_set_property (GObject *object,
1808 const GValue *value,
1811 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (object);
1812 GtkEntry *entry = GTK_ENTRY (object);
1818 gtk_entry_set_buffer (entry, g_value_get_object (value));
1823 gboolean new_value = g_value_get_boolean (value);
1825 if (new_value != entry->editable)
1827 widget = GTK_WIDGET (entry);
1830 _gtk_entry_reset_im_context (entry);
1831 if (gtk_widget_has_focus (widget))
1832 gtk_im_context_focus_out (entry->im_context);
1834 entry->preedit_length = 0;
1835 entry->preedit_cursor = 0;
1838 entry->editable = new_value;
1840 if (new_value && gtk_widget_has_focus (widget))
1841 gtk_im_context_focus_in (entry->im_context);
1843 gtk_entry_queue_draw (entry);
1848 case PROP_MAX_LENGTH:
1849 gtk_entry_set_max_length (entry, g_value_get_int (value));
1852 case PROP_VISIBILITY:
1853 gtk_entry_set_visibility (entry, g_value_get_boolean (value));
1856 case PROP_HAS_FRAME:
1857 gtk_entry_set_has_frame (entry, g_value_get_boolean (value));
1860 case PROP_INNER_BORDER:
1861 gtk_entry_set_inner_border (entry, g_value_get_boxed (value));
1864 case PROP_INVISIBLE_CHAR:
1865 gtk_entry_set_invisible_char (entry, g_value_get_uint (value));
1868 case PROP_ACTIVATES_DEFAULT:
1869 gtk_entry_set_activates_default (entry, g_value_get_boolean (value));
1872 case PROP_WIDTH_CHARS:
1873 gtk_entry_set_width_chars (entry, g_value_get_int (value));
1877 gtk_entry_set_text (entry, g_value_get_string (value));
1881 gtk_entry_set_alignment (entry, g_value_get_float (value));
1884 case PROP_TRUNCATE_MULTILINE:
1885 entry->truncate_multiline = g_value_get_boolean (value);
1888 case PROP_SHADOW_TYPE:
1889 priv->shadow_type = g_value_get_enum (value);
1892 case PROP_OVERWRITE_MODE:
1893 gtk_entry_set_overwrite_mode (entry, g_value_get_boolean (value));
1896 case PROP_INVISIBLE_CHAR_SET:
1897 if (g_value_get_boolean (value))
1898 priv->invisible_char_set = TRUE;
1900 gtk_entry_unset_invisible_char (entry);
1903 case PROP_CAPS_LOCK_WARNING:
1904 priv->caps_lock_warning = g_value_get_boolean (value);
1907 case PROP_PROGRESS_FRACTION:
1908 gtk_entry_set_progress_fraction (entry, g_value_get_double (value));
1911 case PROP_PROGRESS_PULSE_STEP:
1912 gtk_entry_set_progress_pulse_step (entry, g_value_get_double (value));
1915 case PROP_PIXBUF_PRIMARY:
1916 gtk_entry_set_icon_from_pixbuf (entry,
1917 GTK_ENTRY_ICON_PRIMARY,
1918 g_value_get_object (value));
1921 case PROP_PIXBUF_SECONDARY:
1922 gtk_entry_set_icon_from_pixbuf (entry,
1923 GTK_ENTRY_ICON_SECONDARY,
1924 g_value_get_object (value));
1927 case PROP_STOCK_PRIMARY:
1928 gtk_entry_set_icon_from_stock (entry,
1929 GTK_ENTRY_ICON_PRIMARY,
1930 g_value_get_string (value));
1933 case PROP_STOCK_SECONDARY:
1934 gtk_entry_set_icon_from_stock (entry,
1935 GTK_ENTRY_ICON_SECONDARY,
1936 g_value_get_string (value));
1939 case PROP_ICON_NAME_PRIMARY:
1940 gtk_entry_set_icon_from_icon_name (entry,
1941 GTK_ENTRY_ICON_PRIMARY,
1942 g_value_get_string (value));
1945 case PROP_ICON_NAME_SECONDARY:
1946 gtk_entry_set_icon_from_icon_name (entry,
1947 GTK_ENTRY_ICON_SECONDARY,
1948 g_value_get_string (value));
1951 case PROP_GICON_PRIMARY:
1952 gtk_entry_set_icon_from_gicon (entry,
1953 GTK_ENTRY_ICON_PRIMARY,
1954 g_value_get_object (value));
1957 case PROP_GICON_SECONDARY:
1958 gtk_entry_set_icon_from_gicon (entry,
1959 GTK_ENTRY_ICON_SECONDARY,
1960 g_value_get_object (value));
1963 case PROP_ACTIVATABLE_PRIMARY:
1964 gtk_entry_set_icon_activatable (entry,
1965 GTK_ENTRY_ICON_PRIMARY,
1966 g_value_get_boolean (value));
1969 case PROP_ACTIVATABLE_SECONDARY:
1970 gtk_entry_set_icon_activatable (entry,
1971 GTK_ENTRY_ICON_SECONDARY,
1972 g_value_get_boolean (value));
1975 case PROP_SENSITIVE_PRIMARY:
1976 gtk_entry_set_icon_sensitive (entry,
1977 GTK_ENTRY_ICON_PRIMARY,
1978 g_value_get_boolean (value));
1981 case PROP_SENSITIVE_SECONDARY:
1982 gtk_entry_set_icon_sensitive (entry,
1983 GTK_ENTRY_ICON_SECONDARY,
1984 g_value_get_boolean (value));
1987 case PROP_TOOLTIP_TEXT_PRIMARY:
1988 gtk_entry_set_icon_tooltip_text (entry,
1989 GTK_ENTRY_ICON_PRIMARY,
1990 g_value_get_string (value));
1993 case PROP_TOOLTIP_TEXT_SECONDARY:
1994 gtk_entry_set_icon_tooltip_text (entry,
1995 GTK_ENTRY_ICON_SECONDARY,
1996 g_value_get_string (value));
1999 case PROP_TOOLTIP_MARKUP_PRIMARY:
2000 gtk_entry_set_icon_tooltip_markup (entry,
2001 GTK_ENTRY_ICON_PRIMARY,
2002 g_value_get_string (value));
2005 case PROP_TOOLTIP_MARKUP_SECONDARY:
2006 gtk_entry_set_icon_tooltip_markup (entry,
2007 GTK_ENTRY_ICON_SECONDARY,
2008 g_value_get_string (value));
2011 case PROP_IM_MODULE:
2012 g_free (priv->im_module);
2013 priv->im_module = g_value_dup_string (value);
2014 if (GTK_IS_IM_MULTICONTEXT (entry->im_context))
2015 gtk_im_multicontext_set_context_id (GTK_IM_MULTICONTEXT (entry->im_context), priv->im_module);
2018 case PROP_EDITING_CANCELED:
2019 entry->editing_canceled = g_value_get_boolean (value);
2022 case PROP_SCROLL_OFFSET:
2023 case PROP_CURSOR_POSITION:
2025 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2031 gtk_entry_get_property (GObject *object,
2036 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (object);
2037 GtkEntry *entry = GTK_ENTRY (object);
2042 g_value_set_object (value, gtk_entry_get_buffer (entry));
2045 case PROP_CURSOR_POSITION:
2046 g_value_set_int (value, entry->current_pos);
2049 case PROP_SELECTION_BOUND:
2050 g_value_set_int (value, entry->selection_bound);
2054 g_value_set_boolean (value, entry->editable);
2057 case PROP_MAX_LENGTH:
2058 g_value_set_int (value, gtk_entry_buffer_get_max_length (get_buffer (entry)));
2061 case PROP_VISIBILITY:
2062 g_value_set_boolean (value, entry->visible);
2065 case PROP_HAS_FRAME:
2066 g_value_set_boolean (value, entry->has_frame);
2069 case PROP_INNER_BORDER:
2070 g_value_set_boxed (value, gtk_entry_get_inner_border (entry));
2073 case PROP_INVISIBLE_CHAR:
2074 g_value_set_uint (value, entry->invisible_char);
2077 case PROP_ACTIVATES_DEFAULT:
2078 g_value_set_boolean (value, entry->activates_default);
2081 case PROP_WIDTH_CHARS:
2082 g_value_set_int (value, entry->width_chars);
2085 case PROP_SCROLL_OFFSET:
2086 g_value_set_int (value, entry->scroll_offset);
2090 g_value_set_string (value, gtk_entry_get_text (entry));
2094 g_value_set_float (value, gtk_entry_get_alignment (entry));
2097 case PROP_TRUNCATE_MULTILINE:
2098 g_value_set_boolean (value, entry->truncate_multiline);
2101 case PROP_SHADOW_TYPE:
2102 g_value_set_enum (value, priv->shadow_type);
2105 case PROP_OVERWRITE_MODE:
2106 g_value_set_boolean (value, entry->overwrite_mode);
2109 case PROP_TEXT_LENGTH:
2110 g_value_set_uint (value, gtk_entry_buffer_get_length (get_buffer (entry)));
2113 case PROP_INVISIBLE_CHAR_SET:
2114 g_value_set_boolean (value, priv->invisible_char_set);
2117 case PROP_IM_MODULE:
2118 g_value_set_string (value, priv->im_module);
2121 case PROP_CAPS_LOCK_WARNING:
2122 g_value_set_boolean (value, priv->caps_lock_warning);
2125 case PROP_PROGRESS_FRACTION:
2126 g_value_set_double (value, priv->progress_fraction);
2129 case PROP_PROGRESS_PULSE_STEP:
2130 g_value_set_double (value, priv->progress_pulse_fraction);
2133 case PROP_PIXBUF_PRIMARY:
2134 g_value_set_object (value,
2135 gtk_entry_get_icon_pixbuf (entry,
2136 GTK_ENTRY_ICON_PRIMARY));
2139 case PROP_PIXBUF_SECONDARY:
2140 g_value_set_object (value,
2141 gtk_entry_get_icon_pixbuf (entry,
2142 GTK_ENTRY_ICON_SECONDARY));
2145 case PROP_STOCK_PRIMARY:
2146 g_value_set_string (value,
2147 gtk_entry_get_icon_stock (entry,
2148 GTK_ENTRY_ICON_PRIMARY));
2151 case PROP_STOCK_SECONDARY:
2152 g_value_set_string (value,
2153 gtk_entry_get_icon_stock (entry,
2154 GTK_ENTRY_ICON_SECONDARY));
2157 case PROP_ICON_NAME_PRIMARY:
2158 g_value_set_string (value,
2159 gtk_entry_get_icon_name (entry,
2160 GTK_ENTRY_ICON_PRIMARY));
2163 case PROP_ICON_NAME_SECONDARY:
2164 g_value_set_string (value,
2165 gtk_entry_get_icon_name (entry,
2166 GTK_ENTRY_ICON_SECONDARY));
2169 case PROP_GICON_PRIMARY:
2170 g_value_set_object (value,
2171 gtk_entry_get_icon_gicon (entry,
2172 GTK_ENTRY_ICON_PRIMARY));
2175 case PROP_GICON_SECONDARY:
2176 g_value_set_object (value,
2177 gtk_entry_get_icon_gicon (entry,
2178 GTK_ENTRY_ICON_SECONDARY));
2181 case PROP_STORAGE_TYPE_PRIMARY:
2182 g_value_set_enum (value,
2183 gtk_entry_get_icon_storage_type (entry,
2184 GTK_ENTRY_ICON_PRIMARY));
2187 case PROP_STORAGE_TYPE_SECONDARY:
2188 g_value_set_enum (value,
2189 gtk_entry_get_icon_storage_type (entry,
2190 GTK_ENTRY_ICON_SECONDARY));
2193 case PROP_ACTIVATABLE_PRIMARY:
2194 g_value_set_boolean (value,
2195 gtk_entry_get_icon_activatable (entry, GTK_ENTRY_ICON_PRIMARY));
2198 case PROP_ACTIVATABLE_SECONDARY:
2199 g_value_set_boolean (value,
2200 gtk_entry_get_icon_activatable (entry, GTK_ENTRY_ICON_SECONDARY));
2203 case PROP_SENSITIVE_PRIMARY:
2204 g_value_set_boolean (value,
2205 gtk_entry_get_icon_sensitive (entry, GTK_ENTRY_ICON_PRIMARY));
2208 case PROP_SENSITIVE_SECONDARY:
2209 g_value_set_boolean (value,
2210 gtk_entry_get_icon_sensitive (entry, GTK_ENTRY_ICON_SECONDARY));
2213 case PROP_TOOLTIP_TEXT_PRIMARY:
2214 g_value_take_string (value,
2215 gtk_entry_get_icon_tooltip_text (entry, GTK_ENTRY_ICON_PRIMARY));
2218 case PROP_TOOLTIP_TEXT_SECONDARY:
2219 g_value_take_string (value,
2220 gtk_entry_get_icon_tooltip_text (entry, GTK_ENTRY_ICON_SECONDARY));
2223 case PROP_TOOLTIP_MARKUP_PRIMARY:
2224 g_value_take_string (value,
2225 gtk_entry_get_icon_tooltip_markup (entry, GTK_ENTRY_ICON_PRIMARY));
2228 case PROP_TOOLTIP_MARKUP_SECONDARY:
2229 g_value_take_string (value,
2230 gtk_entry_get_icon_tooltip_markup (entry, GTK_ENTRY_ICON_SECONDARY));
2233 case PROP_EDITING_CANCELED:
2234 g_value_set_boolean (value,
2235 entry->editing_canceled);
2239 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2245 find_invisible_char (GtkWidget *widget)
2247 PangoLayout *layout;
2248 PangoAttrList *attr_list;
2250 gunichar invisible_chars [] = {
2252 0x25cf, /* BLACK CIRCLE */
2253 0x2022, /* BULLET */
2254 0x2731, /* HEAVY ASTERISK */
2255 0x273a /* SIXTEEN POINTED ASTERISK */
2258 if (gtk_widget_get_style (widget))
2259 gtk_widget_style_get (widget,
2260 "invisible-char", &invisible_chars[0],
2263 layout = gtk_widget_create_pango_layout (widget, NULL);
2265 attr_list = pango_attr_list_new ();
2266 pango_attr_list_insert (attr_list, pango_attr_fallback_new (FALSE));
2268 pango_layout_set_attributes (layout, attr_list);
2269 pango_attr_list_unref (attr_list);
2271 for (i = (invisible_chars[0] != 0 ? 0 : 1); i < G_N_ELEMENTS (invisible_chars); i++)
2273 gchar text[7] = { 0, };
2276 len = g_unichar_to_utf8 (invisible_chars[i], text);
2277 pango_layout_set_text (layout, text, len);
2279 count = pango_layout_get_unknown_glyphs_count (layout);
2283 g_object_unref (layout);
2284 return invisible_chars[i];
2288 g_object_unref (layout);
2294 gtk_entry_init (GtkEntry *entry)
2296 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2298 gtk_widget_set_can_focus (GTK_WIDGET (entry), TRUE);
2300 entry->editable = TRUE;
2301 entry->visible = TRUE;
2302 entry->invisible_char = find_invisible_char (GTK_WIDGET (entry));
2303 entry->dnd_position = -1;
2304 entry->width_chars = -1;
2305 entry->is_cell_renderer = FALSE;
2306 entry->editing_canceled = FALSE;
2307 entry->has_frame = TRUE;
2308 entry->truncate_multiline = FALSE;
2309 priv->shadow_type = GTK_SHADOW_IN;
2311 priv->caps_lock_warning = TRUE;
2312 priv->caps_lock_warning_shown = FALSE;
2313 priv->progress_fraction = 0.0;
2314 priv->progress_pulse_fraction = 0.1;
2316 gtk_drag_dest_set (GTK_WIDGET (entry),
2317 GTK_DEST_DEFAULT_HIGHLIGHT,
2319 GDK_ACTION_COPY | GDK_ACTION_MOVE);
2320 gtk_drag_dest_add_text_targets (GTK_WIDGET (entry));
2322 /* This object is completely private. No external entity can gain a reference
2323 * to it; so we create it here and destroy it in finalize().
2325 entry->im_context = gtk_im_multicontext_new ();
2327 g_signal_connect (entry->im_context, "commit",
2328 G_CALLBACK (gtk_entry_commit_cb), entry);
2329 g_signal_connect (entry->im_context, "preedit-changed",
2330 G_CALLBACK (gtk_entry_preedit_changed_cb), entry);
2331 g_signal_connect (entry->im_context, "retrieve-surrounding",
2332 G_CALLBACK (gtk_entry_retrieve_surrounding_cb), entry);
2333 g_signal_connect (entry->im_context, "delete-surrounding",
2334 G_CALLBACK (gtk_entry_delete_surrounding_cb), entry);
2339 get_icon_width (GtkEntry *entry,
2340 GtkEntryIconPosition icon_pos)
2342 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2343 EntryIconInfo *icon_info = priv->icons[icon_pos];
2345 GtkSettings *settings;
2346 gint menu_icon_width;
2348 if (!icon_info || icon_info->pixbuf == NULL)
2351 screen = gtk_widget_get_screen (GTK_WIDGET (entry));
2352 settings = gtk_settings_get_for_screen (screen);
2354 gtk_icon_size_lookup_for_settings (settings, GTK_ICON_SIZE_MENU,
2355 &menu_icon_width, NULL);
2357 return MAX (gdk_pixbuf_get_width (icon_info->pixbuf), menu_icon_width);
2361 get_icon_allocations (GtkEntry *entry,
2362 GtkAllocation *primary,
2363 GtkAllocation *secondary)
2366 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2367 gint x, y, width, height;
2369 get_text_area_size (entry, &x, &y, &width, &height);
2371 if (gtk_widget_has_focus (GTK_WIDGET (entry)) && !priv->interior_focus)
2372 y += priv->focus_width;
2375 primary->height = height;
2376 primary->width = get_icon_width (entry, GTK_ENTRY_ICON_PRIMARY);
2377 if (primary->width > 0)
2378 primary->width += 2 * priv->icon_margin;
2381 secondary->height = height;
2382 secondary->width = get_icon_width (entry, GTK_ENTRY_ICON_SECONDARY);
2383 if (secondary->width > 0)
2384 secondary->width += 2 * priv->icon_margin;
2386 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
2388 primary->x = x + width - primary->width;
2394 secondary->x = x + width - secondary->width;
2400 begin_change (GtkEntry *entry)
2402 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2404 priv->change_count++;
2408 end_change (GtkEntry *entry)
2410 GtkEditable *editable = GTK_EDITABLE (entry);
2411 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2413 g_return_if_fail (priv->change_count > 0);
2415 priv->change_count--;
2417 if (priv->change_count == 0)
2419 if (priv->real_changed)
2421 g_signal_emit_by_name (editable, "changed");
2422 priv->real_changed = FALSE;
2428 emit_changed (GtkEntry *entry)
2430 GtkEditable *editable = GTK_EDITABLE (entry);
2431 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2433 if (priv->change_count == 0)
2434 g_signal_emit_by_name (editable, "changed");
2436 priv->real_changed = TRUE;
2440 gtk_entry_destroy (GtkObject *object)
2442 GtkEntry *entry = GTK_ENTRY (object);
2444 entry->current_pos = entry->selection_bound = 0;
2445 _gtk_entry_reset_im_context (entry);
2446 gtk_entry_reset_layout (entry);
2448 if (entry->blink_timeout)
2450 g_source_remove (entry->blink_timeout);
2451 entry->blink_timeout = 0;
2454 if (entry->recompute_idle)
2456 g_source_remove (entry->recompute_idle);
2457 entry->recompute_idle = 0;
2460 GTK_OBJECT_CLASS (gtk_entry_parent_class)->destroy (object);
2464 gtk_entry_dispose (GObject *object)
2466 GtkEntry *entry = GTK_ENTRY (object);
2467 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2469 gtk_entry_set_icon_from_pixbuf (entry, GTK_ENTRY_ICON_PRIMARY, NULL);
2470 gtk_entry_set_icon_tooltip_markup (entry, GTK_ENTRY_ICON_PRIMARY, NULL);
2471 gtk_entry_set_icon_from_pixbuf (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
2472 gtk_entry_set_icon_tooltip_markup (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
2476 buffer_disconnect_signals (entry);
2477 g_object_unref (priv->buffer);
2478 priv->buffer = NULL;
2481 G_OBJECT_CLASS (gtk_entry_parent_class)->dispose (object);
2485 gtk_entry_finalize (GObject *object)
2487 GtkEntry *entry = GTK_ENTRY (object);
2488 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2489 EntryIconInfo *icon_info = NULL;
2492 for (i = 0; i < MAX_ICONS; i++)
2494 if ((icon_info = priv->icons[i]) != NULL)
2496 if (icon_info->target_list != NULL)
2498 gtk_target_list_unref (icon_info->target_list);
2499 icon_info->target_list = NULL;
2502 g_slice_free (EntryIconInfo, icon_info);
2503 priv->icons[i] = NULL;
2507 gtk_entry_set_completion (entry, NULL);
2509 if (entry->cached_layout)
2510 g_object_unref (entry->cached_layout);
2512 g_object_unref (entry->im_context);
2514 if (entry->blink_timeout)
2515 g_source_remove (entry->blink_timeout);
2517 if (entry->recompute_idle)
2518 g_source_remove (entry->recompute_idle);
2520 g_free (priv->im_module);
2522 G_OBJECT_CLASS (gtk_entry_parent_class)->finalize (object);
2526 gtk_entry_get_display_mode (GtkEntry *entry)
2528 GtkEntryPrivate *priv;
2530 return DISPLAY_NORMAL;
2531 priv = GTK_ENTRY_GET_PRIVATE (entry);
2532 if (entry->invisible_char == 0 && priv->invisible_char_set)
2533 return DISPLAY_BLANK;
2534 return DISPLAY_INVISIBLE;
2538 gtk_entry_get_display_text (GtkEntry *entry,
2542 GtkEntryPasswordHint *password_hint;
2543 GtkEntryPrivate *priv;
2544 gunichar invisible_char;
2554 priv = GTK_ENTRY_GET_PRIVATE (entry);
2555 text = gtk_entry_buffer_get_text (get_buffer (entry));
2556 length = gtk_entry_buffer_get_length (get_buffer (entry));
2560 if (start_pos > length)
2563 if (end_pos <= start_pos)
2564 return g_strdup ("");
2565 else if (entry->visible)
2567 start = g_utf8_offset_to_pointer (text, start_pos);
2568 end = g_utf8_offset_to_pointer (start, end_pos - start_pos);
2569 return g_strndup (start, end - start);
2573 str = g_string_sized_new (length * 2);
2575 /* Figure out what our invisible char is and encode it */
2576 if (!entry->invisible_char)
2577 invisible_char = priv->invisible_char_set ? ' ' : '*';
2579 invisible_char = entry->invisible_char;
2580 char_len = g_unichar_to_utf8 (invisible_char, char_str);
2583 * Add hidden characters for each character in the text
2584 * buffer. If there is a password hint, then keep that
2585 * character visible.
2588 password_hint = g_object_get_qdata (G_OBJECT (entry), quark_password_hint);
2589 for (i = start_pos; i < end_pos; ++i)
2591 if (password_hint && i == password_hint->position)
2593 start = g_utf8_offset_to_pointer (text, i);
2594 g_string_append_len (str, start, g_utf8_next_char (start) - start);
2598 g_string_append_len (str, char_str, char_len);
2602 return g_string_free (str, FALSE);
2608 update_cursors (GtkWidget *widget)
2610 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2611 EntryIconInfo *icon_info = NULL;
2612 GdkDisplay *display;
2616 for (i = 0; i < MAX_ICONS; i++)
2618 if ((icon_info = priv->icons[i]) != NULL)
2620 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
2621 gdk_window_show_unraised (icon_info->window);
2623 /* The icon windows are not children of the visible entry window,
2624 * thus we can't just inherit the xterm cursor. Slight complication
2625 * here is that for the entry, insensitive => arrow cursor, but for
2626 * an icon in a sensitive entry, insensitive => xterm cursor.
2628 if (gtk_widget_is_sensitive (widget) &&
2629 (icon_info->insensitive ||
2630 (icon_info->nonactivatable && icon_info->target_list == NULL)))
2632 display = gtk_widget_get_display (widget);
2633 cursor = gdk_cursor_new_for_display (display, GDK_XTERM);
2634 gdk_window_set_cursor (icon_info->window, cursor);
2635 gdk_cursor_unref (cursor);
2639 gdk_window_set_cursor (icon_info->window, NULL);
2646 realize_icon_info (GtkWidget *widget,
2647 GtkEntryIconPosition icon_pos)
2649 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2650 EntryIconInfo *icon_info = priv->icons[icon_pos];
2651 GdkWindowAttr attributes;
2652 gint attributes_mask;
2654 g_return_if_fail (icon_info != NULL);
2658 attributes.width = 1;
2659 attributes.height = 1;
2660 attributes.window_type = GDK_WINDOW_CHILD;
2661 attributes.wclass = GDK_INPUT_OUTPUT;
2662 attributes.visual = gtk_widget_get_visual (widget);
2663 attributes.colormap = gtk_widget_get_colormap (widget);
2664 attributes.event_mask = gtk_widget_get_events (widget);
2665 attributes.event_mask |= (GDK_EXPOSURE_MASK |
2666 GDK_BUTTON_PRESS_MASK |
2667 GDK_BUTTON_RELEASE_MASK |
2668 GDK_BUTTON1_MOTION_MASK |
2669 GDK_BUTTON3_MOTION_MASK |
2670 GDK_POINTER_MOTION_HINT_MASK |
2671 GDK_POINTER_MOTION_MASK |
2672 GDK_ENTER_NOTIFY_MASK |
2673 GDK_LEAVE_NOTIFY_MASK);
2674 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
2676 icon_info->window = gdk_window_new (gtk_widget_get_window (widget),
2679 gdk_window_set_user_data (icon_info->window, widget);
2680 gdk_window_set_background (icon_info->window,
2681 >k_widget_get_style (widget)->base[gtk_widget_get_state (widget)]);
2683 gtk_widget_queue_resize (widget);
2686 static EntryIconInfo*
2687 construct_icon_info (GtkWidget *widget,
2688 GtkEntryIconPosition icon_pos)
2690 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2691 EntryIconInfo *icon_info;
2693 g_return_val_if_fail (priv->icons[icon_pos] == NULL, NULL);
2695 icon_info = g_slice_new0 (EntryIconInfo);
2696 priv->icons[icon_pos] = icon_info;
2698 if (gtk_widget_get_realized (widget))
2699 realize_icon_info (widget, icon_pos);
2705 gtk_entry_map (GtkWidget *widget)
2707 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2708 EntryIconInfo *icon_info = NULL;
2711 if (gtk_widget_get_realized (widget) && !gtk_widget_get_mapped (widget))
2713 GTK_WIDGET_CLASS (gtk_entry_parent_class)->map (widget);
2715 for (i = 0; i < MAX_ICONS; i++)
2717 if ((icon_info = priv->icons[i]) != NULL)
2719 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
2720 gdk_window_show (icon_info->window);
2724 update_cursors (widget);
2729 gtk_entry_unmap (GtkWidget *widget)
2731 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2732 EntryIconInfo *icon_info = NULL;
2735 if (gtk_widget_get_mapped (widget))
2737 for (i = 0; i < MAX_ICONS; i++)
2739 if ((icon_info = priv->icons[i]) != NULL)
2741 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
2742 gdk_window_hide (icon_info->window);
2746 GTK_WIDGET_CLASS (gtk_entry_parent_class)->unmap (widget);
2751 gtk_entry_realize (GtkWidget *widget)
2754 GtkEntryPrivate *priv;
2757 EntryIconInfo *icon_info;
2759 GdkWindowAttr attributes;
2760 gint attributes_mask;
2763 gtk_widget_set_realized (widget, TRUE);
2764 entry = GTK_ENTRY (widget);
2765 priv = GTK_ENTRY_GET_PRIVATE (entry);
2767 attributes.window_type = GDK_WINDOW_CHILD;
2769 get_widget_window_size (entry, &attributes.x, &attributes.y, &attributes.width, &attributes.height);
2771 attributes.wclass = GDK_INPUT_OUTPUT;
2772 attributes.visual = gtk_widget_get_visual (widget);
2773 attributes.colormap = gtk_widget_get_colormap (widget);
2774 attributes.event_mask = gtk_widget_get_events (widget);
2775 attributes.event_mask |= (GDK_EXPOSURE_MASK |
2776 GDK_BUTTON_PRESS_MASK |
2777 GDK_BUTTON_RELEASE_MASK |
2778 GDK_BUTTON1_MOTION_MASK |
2779 GDK_BUTTON3_MOTION_MASK |
2780 GDK_POINTER_MOTION_HINT_MASK |
2781 GDK_POINTER_MOTION_MASK |
2782 GDK_ENTER_NOTIFY_MASK |
2783 GDK_LEAVE_NOTIFY_MASK);
2784 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
2786 window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, attributes_mask);
2787 gtk_widget_set_window (widget, window);
2788 gdk_window_set_user_data (window, entry);
2790 get_text_area_size (entry, &attributes.x, &attributes.y, &attributes.width, &attributes.height);
2792 if (gtk_widget_is_sensitive (widget))
2794 attributes.cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
2795 attributes_mask |= GDK_WA_CURSOR;
2798 entry->text_area = gdk_window_new (window, &attributes, attributes_mask);
2800 gdk_window_set_user_data (entry->text_area, entry);
2802 if (attributes_mask & GDK_WA_CURSOR)
2803 gdk_cursor_unref (attributes.cursor);
2805 gtk_widget_style_attach (widget);
2807 style = gtk_widget_get_style (widget);
2808 state = gtk_widget_get_state (widget);
2809 gdk_window_set_background (window, &style->base[state]);
2810 gdk_window_set_background (entry->text_area, &style->base[state]);
2812 gdk_window_show (entry->text_area);
2814 gtk_im_context_set_client_window (entry->im_context, entry->text_area);
2816 gtk_entry_adjust_scroll (entry);
2817 gtk_entry_update_primary_selection (entry);
2820 /* If the icon positions are already setup, create their windows.
2821 * Otherwise if they don't exist yet, then construct_icon_info()
2822 * will create the windows once the widget is already realized.
2824 for (i = 0; i < MAX_ICONS; i++)
2826 if ((icon_info = priv->icons[i]) != NULL)
2828 if (icon_info->window == NULL)
2829 realize_icon_info (widget, i);
2835 gtk_entry_unrealize (GtkWidget *widget)
2837 GtkEntry *entry = GTK_ENTRY (widget);
2838 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2839 GtkClipboard *clipboard;
2840 EntryIconInfo *icon_info;
2843 gtk_entry_reset_layout (entry);
2845 gtk_im_context_set_client_window (entry->im_context, NULL);
2847 clipboard = gtk_widget_get_clipboard (widget, GDK_SELECTION_PRIMARY);
2848 if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (entry))
2849 gtk_clipboard_clear (clipboard);
2851 if (entry->text_area)
2853 gdk_window_set_user_data (entry->text_area, NULL);
2854 gdk_window_destroy (entry->text_area);
2855 entry->text_area = NULL;
2858 if (entry->popup_menu)
2860 gtk_widget_destroy (entry->popup_menu);
2861 entry->popup_menu = NULL;
2864 GTK_WIDGET_CLASS (gtk_entry_parent_class)->unrealize (widget);
2866 for (i = 0; i < MAX_ICONS; i++)
2868 if ((icon_info = priv->icons[i]) != NULL)
2870 if (icon_info->window != NULL)
2872 gdk_window_destroy (icon_info->window);
2873 icon_info->window = NULL;
2880 _gtk_entry_get_borders (GtkEntry *entry,
2884 GtkWidget *widget = GTK_WIDGET (entry);
2885 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2888 if (entry->has_frame)
2890 style = gtk_widget_get_style (widget);
2892 *xborder = style->xthickness;
2893 *yborder = style->ythickness;
2901 if (!priv->interior_focus)
2903 *xborder += priv->focus_width;
2904 *yborder += priv->focus_width;
2909 gtk_entry_size_request (GtkWidget *widget,
2910 GtkRequisition *requisition)
2912 GtkEntry *entry = GTK_ENTRY (widget);
2913 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2914 PangoFontMetrics *metrics;
2915 gint xborder, yborder;
2916 GtkBorder inner_border;
2917 PangoContext *context;
2918 int icon_widths = 0;
2921 gtk_widget_ensure_style (widget);
2922 context = gtk_widget_get_pango_context (widget);
2923 metrics = pango_context_get_metrics (context,
2924 gtk_widget_get_style (widget)->font_desc,
2925 pango_context_get_language (context));
2927 entry->ascent = pango_font_metrics_get_ascent (metrics);
2928 entry->descent = pango_font_metrics_get_descent (metrics);
2930 _gtk_entry_get_borders (entry, &xborder, &yborder);
2931 _gtk_entry_effective_inner_border (entry, &inner_border);
2933 if (entry->width_chars < 0)
2934 requisition->width = MIN_ENTRY_WIDTH + xborder * 2 + inner_border.left + inner_border.right;
2937 gint char_width = pango_font_metrics_get_approximate_char_width (metrics);
2938 gint digit_width = pango_font_metrics_get_approximate_digit_width (metrics);
2939 gint char_pixels = (MAX (char_width, digit_width) + PANGO_SCALE - 1) / PANGO_SCALE;
2941 requisition->width = char_pixels * entry->width_chars + xborder * 2 + inner_border.left + inner_border.right;
2944 requisition->height = PANGO_PIXELS (entry->ascent + entry->descent) + yborder * 2 + inner_border.top + inner_border.bottom;
2946 for (i = 0; i < MAX_ICONS; i++)
2948 icon_width = get_icon_width (entry, i);
2950 icon_widths += icon_width + 2 * priv->icon_margin;
2953 if (icon_widths > requisition->width)
2954 requisition->width += icon_widths;
2956 pango_font_metrics_unref (metrics);
2960 place_windows (GtkEntry *entry)
2962 GtkWidget *widget = GTK_WIDGET (entry);
2963 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2964 gint x, y, width, height;
2965 GtkAllocation primary;
2966 GtkAllocation secondary;
2967 EntryIconInfo *icon_info = NULL;
2969 get_text_area_size (entry, &x, &y, &width, &height);
2970 get_icon_allocations (entry, &primary, &secondary);
2972 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
2973 y += priv->focus_width;
2975 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
2976 x += secondary.width;
2979 width -= primary.width + secondary.width;
2981 if ((icon_info = priv->icons[GTK_ENTRY_ICON_PRIMARY]) != NULL)
2982 gdk_window_move_resize (icon_info->window,
2983 primary.x, primary.y,
2984 primary.width, primary.height);
2986 if ((icon_info = priv->icons[GTK_ENTRY_ICON_SECONDARY]) != NULL)
2987 gdk_window_move_resize (icon_info->window,
2988 secondary.x, secondary.y,
2989 secondary.width, secondary.height);
2991 gdk_window_move_resize (entry->text_area, x, y, width, height);
2995 gtk_entry_get_text_area_size (GtkEntry *entry,
3001 GtkWidget *widget = GTK_WIDGET (entry);
3002 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
3003 GtkAllocation allocation;
3004 GtkRequisition requisition;
3006 gint xborder, yborder;
3008 gtk_widget_get_child_requisition (widget, &requisition);
3009 gtk_widget_get_allocation (widget, &allocation);
3010 _gtk_entry_get_borders (entry, &xborder, &yborder);
3012 if (gtk_widget_get_realized (widget))
3013 gdk_drawable_get_size (gtk_widget_get_window (widget), NULL, &frame_height);
3015 frame_height = requisition.height;
3017 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3018 frame_height -= 2 * priv->focus_width;
3024 *y = frame_height / 2 - (requisition.height - yborder * 2) / 2;
3027 *width = allocation.width - xborder * 2;
3030 *height = requisition.height - yborder * 2;
3034 get_text_area_size (GtkEntry *entry,
3040 GtkEntryClass *class;
3042 g_return_if_fail (GTK_IS_ENTRY (entry));
3044 class = GTK_ENTRY_GET_CLASS (entry);
3046 if (class->get_text_area_size)
3047 class->get_text_area_size (entry, x, y, width, height);
3052 get_widget_window_size (GtkEntry *entry,
3058 GtkAllocation allocation;
3059 GtkRequisition requisition;
3060 GtkWidget *widget = GTK_WIDGET (entry);
3062 gtk_widget_get_child_requisition (widget, &requisition);
3063 gtk_widget_get_allocation (widget, &allocation);
3070 if (entry->is_cell_renderer)
3073 *y = allocation.y + (allocation.height - requisition.height) / 2;
3077 *width = allocation.width;
3081 if (entry->is_cell_renderer)
3082 *height = allocation.height;
3084 *height = requisition.height;
3089 _gtk_entry_effective_inner_border (GtkEntry *entry,
3092 GtkBorder *tmp_border;
3094 tmp_border = g_object_get_qdata (G_OBJECT (entry), quark_inner_border);
3098 *border = *tmp_border;
3102 gtk_widget_style_get (GTK_WIDGET (entry), "inner-border", &tmp_border, NULL);
3106 *border = *tmp_border;
3107 gtk_border_free (tmp_border);
3111 *border = default_inner_border;
3115 gtk_entry_size_allocate (GtkWidget *widget,
3116 GtkAllocation *allocation)
3118 GtkEntry *entry = GTK_ENTRY (widget);
3120 gtk_widget_set_allocation (widget, allocation);
3122 if (gtk_widget_get_realized (widget))
3124 /* We call gtk_widget_get_child_requisition, since we want (for
3125 * backwards compatibility reasons) the realization here to
3126 * be affected by the usize of the entry, if set
3128 gint x, y, width, height;
3129 GtkEntryCompletion* completion;
3131 get_widget_window_size (entry, &x, &y, &width, &height);
3132 gdk_window_move_resize (gtk_widget_get_window (widget),
3133 x, y, width, height);
3135 place_windows (entry);
3136 gtk_entry_recompute (entry);
3138 completion = gtk_entry_get_completion (entry);
3139 if (completion && gtk_widget_get_mapped (completion->priv->popup_window))
3140 _gtk_entry_completion_resize_popup (completion);
3144 /* Kudos to the gnome-panel guys. */
3146 colorshift_pixbuf (GdkPixbuf *dest,
3151 gint width, height, has_alpha, src_rowstride, dest_rowstride;
3152 guchar *target_pixels;
3153 guchar *original_pixels;
3159 has_alpha = gdk_pixbuf_get_has_alpha (src);
3160 width = gdk_pixbuf_get_width (src);
3161 height = gdk_pixbuf_get_height (src);
3162 src_rowstride = gdk_pixbuf_get_rowstride (src);
3163 dest_rowstride = gdk_pixbuf_get_rowstride (dest);
3164 original_pixels = gdk_pixbuf_get_pixels (src);
3165 target_pixels = gdk_pixbuf_get_pixels (dest);
3167 for (i = 0; i < height; i++)
3169 pix_dest = target_pixels + i * dest_rowstride;
3170 pix_src = original_pixels + i * src_rowstride;
3172 for (j = 0; j < width; j++)
3179 *(pix_dest++) = CLAMP (val, 0, 255);
3182 *(pix_dest++) = CLAMP (val, 0, 255);
3185 *(pix_dest++) = CLAMP (val, 0, 255);
3188 *(pix_dest++) = *(pix_src++);
3194 should_prelight (GtkEntry *entry,
3195 GtkEntryIconPosition icon_pos)
3197 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3198 EntryIconInfo *icon_info = priv->icons[icon_pos];
3204 if (icon_info->nonactivatable && icon_info->target_list == NULL)
3207 if (icon_info->pressed)
3210 gtk_widget_style_get (GTK_WIDGET (entry),
3211 "icon-prelight", &prelight,
3218 draw_icon (GtkWidget *widget,
3219 GtkEntryIconPosition icon_pos)
3221 GtkEntry *entry = GTK_ENTRY (widget);
3222 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3223 EntryIconInfo *icon_info = priv->icons[icon_pos];
3225 gint x, y, width, height;
3231 gtk_entry_ensure_pixbuf (entry, icon_pos);
3233 if (icon_info->pixbuf == NULL)
3236 gdk_drawable_get_size (icon_info->window, &width, &height);
3238 /* size_allocate hasn't been called yet. These are the default values.
3240 if (width == 1 || height == 1)
3243 pixbuf = icon_info->pixbuf;
3244 g_object_ref (pixbuf);
3246 if (gdk_pixbuf_get_height (pixbuf) > height)
3248 GdkPixbuf *temp_pixbuf;
3251 scale = height - 2 * priv->icon_margin;
3252 temp_pixbuf = gdk_pixbuf_scale_simple (pixbuf, scale, scale,
3253 GDK_INTERP_BILINEAR);
3254 g_object_unref (pixbuf);
3255 pixbuf = temp_pixbuf;
3258 x = (width - gdk_pixbuf_get_width (pixbuf)) / 2;
3259 y = (height - gdk_pixbuf_get_height (pixbuf)) / 2;
3261 if (!gtk_widget_is_sensitive (widget) ||
3262 icon_info->insensitive)
3264 GdkPixbuf *temp_pixbuf;
3266 temp_pixbuf = gdk_pixbuf_copy (pixbuf);
3267 gdk_pixbuf_saturate_and_pixelate (pixbuf,
3271 g_object_unref (pixbuf);
3272 pixbuf = temp_pixbuf;
3274 else if (icon_info->prelight)
3276 GdkPixbuf *temp_pixbuf;
3278 temp_pixbuf = gdk_pixbuf_copy (pixbuf);
3279 colorshift_pixbuf (temp_pixbuf, pixbuf, 30);
3280 g_object_unref (pixbuf);
3281 pixbuf = temp_pixbuf;
3284 cr = gdk_cairo_create (icon_info->window);
3285 gdk_cairo_set_source_pixbuf (cr, pixbuf, x, y);
3289 g_object_unref (pixbuf);
3294 gtk_entry_draw_frame (GtkWidget *widget,
3295 GdkEventExpose *event)
3297 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
3300 gint x = 0, y = 0, width, height;
3301 gboolean state_hint;
3304 window = gtk_widget_get_window (widget);
3306 gdk_drawable_get_size (window, &width, &height);
3308 /* Fix a problem with some themes which assume that entry->text_area's
3309 * width equals widget->window's width */
3310 if (GTK_IS_SPIN_BUTTON (widget))
3312 gint xborder, yborder;
3314 gtk_entry_get_text_area_size (GTK_ENTRY (widget), &x, NULL, &width, NULL);
3315 _gtk_entry_get_borders (GTK_ENTRY (widget), &xborder, &yborder);
3318 width += xborder * 2;
3321 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3323 x += priv->focus_width;
3324 y += priv->focus_width;
3325 width -= 2 * priv->focus_width;
3326 height -= 2 * priv->focus_width;
3329 style = gtk_widget_get_style (widget);
3330 gtk_widget_style_get (widget, "state-hint", &state_hint, NULL);
3332 state = gtk_widget_has_focus (widget) ?
3333 GTK_STATE_ACTIVE : gtk_widget_get_state (widget);
3335 state = GTK_STATE_NORMAL;
3337 gtk_paint_shadow (style, window,
3338 state, priv->shadow_type,
3339 &event->area, widget, "entry", x, y, width, height);
3342 gtk_entry_draw_progress (widget, event);
3344 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3346 x -= priv->focus_width;
3347 y -= priv->focus_width;
3348 width += 2 * priv->focus_width;
3349 height += 2 * priv->focus_width;
3351 gtk_paint_focus (style, window,
3352 gtk_widget_get_state (widget),
3353 &event->area, widget, "entry",
3354 0, 0, width, height);
3359 gtk_entry_get_progress_border (GtkWidget *widget,
3360 GtkBorder *progress_border)
3362 GtkBorder *tmp_border;
3365 gtk_widget_style_get (widget, "progress-border", &tmp_border, NULL);
3368 *progress_border = *tmp_border;
3369 gtk_border_free (tmp_border);
3373 style = gtk_widget_get_style (widget);
3375 progress_border->left = style->xthickness;
3376 progress_border->right = style->xthickness;
3377 progress_border->top = style->ythickness;
3378 progress_border->bottom = style->ythickness;
3383 get_progress_area (GtkWidget *widget,
3389 GtkEntryPrivate *private = GTK_ENTRY_GET_PRIVATE (widget);
3390 GtkEntry *entry = GTK_ENTRY (widget);
3391 GtkBorder progress_border;
3393 gtk_entry_get_progress_border (widget, &progress_border);
3395 *x = progress_border.left;
3396 *y = progress_border.top;
3398 gdk_drawable_get_size (gtk_widget_get_window (widget), width, height);
3400 *width -= progress_border.left + progress_border.right;
3401 *height -= progress_border.top + progress_border.bottom;
3403 if (gtk_widget_has_focus (widget) && !private->interior_focus)
3405 *x += private->focus_width;
3406 *y += private->focus_width;
3407 *width -= 2 * private->focus_width;
3408 *height -= 2 * private->focus_width;
3411 if (private->progress_pulse_mode)
3413 gdouble value = private->progress_pulse_current;
3415 *x += (gint) floor(value * (*width));
3416 *width = (gint) ceil(private->progress_pulse_fraction * (*width));
3418 else if (private->progress_fraction > 0)
3420 gdouble value = private->progress_fraction;
3422 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
3426 bar_width = floor(value * (*width) + 0.5);
3427 *x += *width - bar_width;
3432 *width = (gint) floor(value * (*width) + 0.5);
3443 gtk_entry_draw_progress (GtkWidget *widget,
3444 GdkEventExpose *event)
3446 gint x, y, width, height;
3449 get_progress_area (widget, &x, &y, &width, &height);
3451 if ((width <= 0) || (height <= 0))
3454 if (event->window != gtk_widget_get_window (widget))
3458 gdk_window_get_position (event->window, &pos_x, &pos_y);
3464 state = GTK_STATE_SELECTED;
3465 if (!gtk_widget_get_sensitive (widget))
3466 state = GTK_STATE_INSENSITIVE;
3468 gtk_paint_box (gtk_widget_get_style (widget), event->window,
3469 state, GTK_SHADOW_OUT,
3470 &event->area, widget, "entry-progress",
3476 gtk_entry_expose (GtkWidget *widget,
3477 GdkEventExpose *event)
3479 GtkEntry *entry = GTK_ENTRY (widget);
3481 gboolean state_hint;
3483 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3485 style = gtk_widget_get_style (widget);
3487 gtk_widget_style_get (widget, "state-hint", &state_hint, NULL);
3490 state = gtk_widget_has_focus (widget) ?
3491 GTK_STATE_ACTIVE : gtk_widget_get_state (widget);
3493 state = gtk_widget_get_state(widget);
3495 if (gtk_widget_get_window (widget) == event->window)
3497 gtk_entry_draw_frame (widget, event);
3499 else if (entry->text_area == event->window)
3503 gdk_drawable_get_size (entry->text_area, &width, &height);
3505 gtk_paint_flat_box (style, entry->text_area,
3506 state, GTK_SHADOW_NONE,
3507 &event->area, widget, "entry_bg",
3508 0, 0, width, height);
3510 gtk_entry_draw_progress (widget, event);
3512 if (entry->dnd_position != -1)
3513 gtk_entry_draw_cursor (GTK_ENTRY (widget), CURSOR_DND);
3515 gtk_entry_draw_text (GTK_ENTRY (widget));
3517 /* When no text is being displayed at all, don't show the cursor */
3518 if (gtk_entry_get_display_mode (entry) != DISPLAY_BLANK &&
3519 gtk_widget_has_focus (widget) &&
3520 entry->selection_bound == entry->current_pos && entry->cursor_visible)
3521 gtk_entry_draw_cursor (GTK_ENTRY (widget), CURSOR_STANDARD);
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)
3535 gdk_drawable_get_size (icon_info->window, &width, &height);
3537 gtk_paint_flat_box (style, icon_info->window,
3538 gtk_widget_get_state (widget), GTK_SHADOW_NONE,
3539 NULL, widget, "entry_bg",
3540 0, 0, width, height);
3542 gtk_entry_draw_progress (widget, event);
3543 draw_icon (widget, i);
3554 gtk_entry_enter_notify (GtkWidget *widget,
3555 GdkEventCrossing *event)
3557 GtkEntry *entry = GTK_ENTRY (widget);
3558 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3561 for (i = 0; i < MAX_ICONS; i++)
3563 EntryIconInfo *icon_info = priv->icons[i];
3565 if (icon_info != NULL && event->window == icon_info->window)
3567 if (should_prelight (entry, i))
3569 icon_info->prelight = TRUE;
3570 gtk_widget_queue_draw (widget);
3581 gtk_entry_leave_notify (GtkWidget *widget,
3582 GdkEventCrossing *event)
3584 GtkEntry *entry = GTK_ENTRY (widget);
3585 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3588 for (i = 0; i < MAX_ICONS; i++)
3590 EntryIconInfo *icon_info = priv->icons[i];
3592 if (icon_info != NULL && event->window == icon_info->window)
3594 /* a grab means that we may never see the button release */
3595 if (event->mode == GDK_CROSSING_GRAB || event->mode == GDK_CROSSING_GTK_GRAB)
3596 icon_info->pressed = FALSE;
3598 if (should_prelight (entry, i))
3600 icon_info->prelight = FALSE;
3601 gtk_widget_queue_draw (widget);
3612 gtk_entry_get_pixel_ranges (GtkEntry *entry,
3616 gint start_char, end_char;
3618 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start_char, &end_char))
3620 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
3621 PangoLayoutLine *line = pango_layout_get_lines_readonly (layout)->data;
3622 const char *text = pango_layout_get_text (layout);
3623 gint start_index = g_utf8_offset_to_pointer (text, start_char) - text;
3624 gint end_index = g_utf8_offset_to_pointer (text, end_char) - text;
3625 gint real_n_ranges, i;
3627 pango_layout_line_get_x_ranges (line, start_index, end_index, ranges, &real_n_ranges);
3633 for (i = 0; i < real_n_ranges; ++i)
3635 r[2 * i + 1] = (r[2 * i + 1] - r[2 * i]) / PANGO_SCALE;
3636 r[2 * i] = r[2 * i] / PANGO_SCALE;
3641 *n_ranges = real_n_ranges;
3653 in_selection (GtkEntry *entry,
3658 gint retval = FALSE;
3660 gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
3662 for (i = 0; i < n_ranges; ++i)
3664 if (x >= ranges[2 * i] && x < ranges[2 * i] + ranges[2 * i + 1])
3676 gtk_entry_button_press (GtkWidget *widget,
3677 GdkEventButton *event)
3679 GtkEntry *entry = GTK_ENTRY (widget);
3680 GtkEditable *editable = GTK_EDITABLE (widget);
3681 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3682 EntryIconInfo *icon_info = NULL;
3684 gint sel_start, sel_end;
3687 for (i = 0; i < MAX_ICONS; i++)
3689 icon_info = priv->icons[i];
3691 if (!icon_info || icon_info->insensitive)
3694 if (event->window == icon_info->window)
3696 if (should_prelight (entry, i))
3698 icon_info->prelight = FALSE;
3699 gtk_widget_queue_draw (widget);
3702 priv->start_x = event->x;
3703 priv->start_y = event->y;
3704 icon_info->pressed = TRUE;
3706 if (!icon_info->nonactivatable)
3707 g_signal_emit (entry, signals[ICON_PRESS], 0, i, event);
3713 if (event->window != entry->text_area ||
3714 (entry->button && event->button != entry->button))
3717 gtk_entry_reset_blink_time (entry);
3719 entry->button = event->button;
3721 if (!gtk_widget_has_focus (widget))
3723 entry->in_click = TRUE;
3724 gtk_widget_grab_focus (widget);
3725 entry->in_click = FALSE;
3728 tmp_pos = gtk_entry_find_position (entry, event->x + entry->scroll_offset);
3730 if (event->button == 1)
3732 gboolean have_selection = gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end);
3734 entry->select_words = FALSE;
3735 entry->select_lines = FALSE;
3737 if (event->state & GDK_SHIFT_MASK)
3739 _gtk_entry_reset_im_context (entry);
3741 if (!have_selection) /* select from the current position to the clicked position */
3742 sel_start = sel_end = entry->current_pos;
3744 if (tmp_pos > sel_start && tmp_pos < sel_end)
3746 /* Truncate current selection, but keep it as big as possible */
3747 if (tmp_pos - sel_start > sel_end - tmp_pos)
3748 gtk_entry_set_positions (entry, sel_start, tmp_pos);
3750 gtk_entry_set_positions (entry, tmp_pos, sel_end);
3754 gboolean extend_to_left;
3757 /* Figure out what click selects and extend current selection */
3758 switch (event->type)
3760 case GDK_BUTTON_PRESS:
3761 gtk_entry_set_positions (entry, tmp_pos, tmp_pos);
3764 case GDK_2BUTTON_PRESS:
3765 entry->select_words = TRUE;
3766 gtk_entry_select_word (entry);
3769 case GDK_3BUTTON_PRESS:
3770 entry->select_lines = TRUE;
3771 gtk_entry_select_line (entry);
3778 start = MIN (entry->current_pos, entry->selection_bound);
3779 start = MIN (sel_start, start);
3781 end = MAX (entry->current_pos, entry->selection_bound);
3782 end = MAX (sel_end, end);
3784 if (tmp_pos == sel_start || tmp_pos == sel_end)
3785 extend_to_left = (tmp_pos == start);
3787 extend_to_left = (end == sel_end);
3790 gtk_entry_set_positions (entry, start, end);
3792 gtk_entry_set_positions (entry, end, start);
3795 else /* no shift key */
3796 switch (event->type)
3798 case GDK_BUTTON_PRESS:
3799 if (in_selection (entry, event->x + entry->scroll_offset))
3801 /* Click inside the selection - we'll either start a drag, or
3802 * clear the selection
3804 entry->in_drag = TRUE;
3805 entry->drag_start_x = event->x + entry->scroll_offset;
3806 entry->drag_start_y = event->y;
3809 gtk_editable_set_position (editable, tmp_pos);
3812 case GDK_2BUTTON_PRESS:
3813 /* We ALWAYS receive a GDK_BUTTON_PRESS immediately before
3814 * receiving a GDK_2BUTTON_PRESS so we need to reset
3815 * entry->in_drag which may have been set above
3817 entry->in_drag = FALSE;
3818 entry->select_words = TRUE;
3819 gtk_entry_select_word (entry);
3822 case GDK_3BUTTON_PRESS:
3823 /* We ALWAYS receive a GDK_BUTTON_PRESS immediately before
3824 * receiving a GDK_3BUTTON_PRESS so we need to reset
3825 * entry->in_drag which may have been set above
3827 entry->in_drag = FALSE;
3828 entry->select_lines = TRUE;
3829 gtk_entry_select_line (entry);
3838 else if (event->button == 2 && event->type == GDK_BUTTON_PRESS)
3840 if (entry->editable)
3842 priv->insert_pos = tmp_pos;
3843 gtk_entry_paste (entry, GDK_SELECTION_PRIMARY);
3848 gtk_widget_error_bell (widget);
3851 else if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
3853 gtk_entry_do_popup (entry, event);
3854 entry->button = 0; /* Don't wait for release, since the menu will gtk_grab_add */
3863 gtk_entry_button_release (GtkWidget *widget,
3864 GdkEventButton *event)
3866 GtkEntry *entry = GTK_ENTRY (widget);
3867 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
3868 EntryIconInfo *icon_info = NULL;
3871 for (i = 0; i < MAX_ICONS; i++)
3873 icon_info = priv->icons[i];
3875 if (!icon_info || icon_info->insensitive)
3878 if (event->window == icon_info->window)
3882 gdk_drawable_get_size (icon_info->window, &width, &height);
3884 icon_info->pressed = FALSE;
3886 if (should_prelight (entry, i) &&
3887 event->x >= 0 && event->y >= 0 &&
3888 event->x < width && event->y < height)
3890 icon_info->prelight = TRUE;
3891 gtk_widget_queue_draw (widget);
3894 if (!icon_info->nonactivatable)
3895 g_signal_emit (entry, signals[ICON_RELEASE], 0, i, event);
3901 if (event->window != entry->text_area || entry->button != event->button)
3906 gint tmp_pos = gtk_entry_find_position (entry, entry->drag_start_x);
3908 gtk_editable_set_position (GTK_EDITABLE (entry), tmp_pos);
3915 gtk_entry_update_primary_selection (entry);
3921 _gtk_entry_get_selected_text (GtkEntry *entry)
3923 GtkEditable *editable = GTK_EDITABLE (entry);
3924 gint start_text, end_text;
3927 if (gtk_editable_get_selection_bounds (editable, &start_text, &end_text))
3928 text = gtk_editable_get_chars (editable, start_text, end_text);
3934 gtk_entry_motion_notify (GtkWidget *widget,
3935 GdkEventMotion *event)
3937 GtkEntry *entry = GTK_ENTRY (widget);
3938 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3939 EntryIconInfo *icon_info = NULL;
3940 GdkDragContext *context;
3944 for (i = 0; i < MAX_ICONS; i++)
3946 icon_info = priv->icons[i];
3948 if (!icon_info || icon_info->insensitive)
3951 if (event->window == icon_info->window)
3953 if (icon_info->pressed &&
3954 icon_info->target_list != NULL &&
3955 gtk_drag_check_threshold (widget,
3961 icon_info->in_drag = TRUE;
3962 icon_info->pressed = FALSE;
3963 context = gtk_drag_begin (widget,
3964 icon_info->target_list,
3974 if (entry->mouse_cursor_obscured)
3978 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
3979 gdk_window_set_cursor (entry->text_area, cursor);
3980 gdk_cursor_unref (cursor);
3981 entry->mouse_cursor_obscured = FALSE;
3984 if (event->window != entry->text_area || entry->button != 1)
3987 if (entry->select_lines)
3990 gdk_event_request_motions (event);
3994 if (gtk_entry_get_display_mode (entry) == DISPLAY_NORMAL &&
3995 gtk_drag_check_threshold (widget,
3996 entry->drag_start_x, entry->drag_start_y,
3997 event->x + entry->scroll_offset, event->y))
3999 GdkDragContext *context;
4000 GtkTargetList *target_list = gtk_target_list_new (NULL, 0);
4001 guint actions = entry->editable ? GDK_ACTION_COPY | GDK_ACTION_MOVE : GDK_ACTION_COPY;
4003 GdkPixmap *pixmap = NULL;
4005 gtk_target_list_add_text_targets (target_list, 0);
4007 text = _gtk_entry_get_selected_text (entry);
4008 pixmap = _gtk_text_util_create_drag_icon (widget, text, -1);
4010 context = gtk_drag_begin (widget, target_list, actions,
4011 entry->button, (GdkEvent *)event);
4014 gtk_drag_set_icon_pixmap (context,
4015 gdk_drawable_get_colormap (pixmap),
4020 gtk_drag_set_icon_default (context);
4023 g_object_unref (pixmap);
4026 entry->in_drag = FALSE;
4029 gtk_target_list_unref (target_list);
4035 gdk_drawable_get_size (entry->text_area, NULL, &height);
4039 else if (event->y >= height)
4040 tmp_pos = gtk_entry_buffer_get_length (get_buffer (entry));
4042 tmp_pos = gtk_entry_find_position (entry, event->x + entry->scroll_offset);
4044 if (entry->select_words)
4047 gint old_min, old_max;
4050 min = gtk_entry_move_backward_word (entry, tmp_pos, TRUE);
4051 max = gtk_entry_move_forward_word (entry, tmp_pos, TRUE);
4053 pos = entry->current_pos;
4054 bound = entry->selection_bound;
4056 old_min = MIN(entry->current_pos, entry->selection_bound);
4057 old_max = MAX(entry->current_pos, entry->selection_bound);
4064 else if (old_max < max)
4069 else if (pos == old_min)
4071 if (entry->current_pos != min)
4076 if (entry->current_pos != max)
4080 gtk_entry_set_positions (entry, pos, bound);
4083 gtk_entry_set_positions (entry, tmp_pos, -1);
4090 set_invisible_cursor (GdkWindow *window)
4092 GdkDisplay *display;
4095 display = gdk_drawable_get_display (window);
4096 cursor = gdk_cursor_new_for_display (display, GDK_BLANK_CURSOR);
4098 gdk_window_set_cursor (window, cursor);
4100 gdk_cursor_unref (cursor);
4104 gtk_entry_obscure_mouse_cursor (GtkEntry *entry)
4106 if (entry->mouse_cursor_obscured)
4109 set_invisible_cursor (entry->text_area);
4111 entry->mouse_cursor_obscured = TRUE;
4115 gtk_entry_key_press (GtkWidget *widget,
4118 GtkEntry *entry = GTK_ENTRY (widget);
4120 gtk_entry_reset_blink_time (entry);
4121 gtk_entry_pend_cursor_blink (entry);
4123 if (entry->editable)
4125 if (gtk_im_context_filter_keypress (entry->im_context, event))
4127 gtk_entry_obscure_mouse_cursor (entry);
4128 entry->need_im_reset = TRUE;
4133 if (event->keyval == GDK_Return ||
4134 event->keyval == GDK_KP_Enter ||
4135 event->keyval == GDK_ISO_Enter ||
4136 event->keyval == GDK_Escape)
4138 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
4140 if (completion && completion->priv->completion_timeout)
4142 g_source_remove (completion->priv->completion_timeout);
4143 completion->priv->completion_timeout = 0;
4146 _gtk_entry_reset_im_context (entry);
4149 if (GTK_WIDGET_CLASS (gtk_entry_parent_class)->key_press_event (widget, event))
4150 /* Activate key bindings
4154 if (!entry->editable && event->length)
4155 gtk_widget_error_bell (widget);
4161 gtk_entry_key_release (GtkWidget *widget,
4164 GtkEntry *entry = GTK_ENTRY (widget);
4166 if (entry->editable)
4168 if (gtk_im_context_filter_keypress (entry->im_context, event))
4170 entry->need_im_reset = TRUE;
4175 return GTK_WIDGET_CLASS (gtk_entry_parent_class)->key_release_event (widget, event);
4179 gtk_entry_focus_in (GtkWidget *widget,
4180 GdkEventFocus *event)
4182 GtkEntry *entry = GTK_ENTRY (widget);
4185 gtk_widget_queue_draw (widget);
4187 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (widget));
4189 if (entry->editable)
4191 entry->need_im_reset = TRUE;
4192 gtk_im_context_focus_in (entry->im_context);
4193 keymap_state_changed (keymap, entry);
4194 g_signal_connect (keymap, "state-changed",
4195 G_CALLBACK (keymap_state_changed), entry);
4198 g_signal_connect (keymap, "direction-changed",
4199 G_CALLBACK (keymap_direction_changed), entry);
4201 gtk_entry_reset_blink_time (entry);
4202 gtk_entry_check_cursor_blink (entry);
4208 gtk_entry_focus_out (GtkWidget *widget,
4209 GdkEventFocus *event)
4211 GtkEntry *entry = GTK_ENTRY (widget);
4212 GtkEntryCompletion *completion;
4215 gtk_widget_queue_draw (widget);
4217 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (widget));
4219 if (entry->editable)
4221 entry->need_im_reset = TRUE;
4222 gtk_im_context_focus_out (entry->im_context);
4223 remove_capslock_feedback (entry);
4226 gtk_entry_check_cursor_blink (entry);
4228 g_signal_handlers_disconnect_by_func (keymap, keymap_state_changed, entry);
4229 g_signal_handlers_disconnect_by_func (keymap, keymap_direction_changed, entry);
4231 completion = gtk_entry_get_completion (entry);
4233 _gtk_entry_completion_popdown (completion);
4239 gtk_entry_grab_focus (GtkWidget *widget)
4241 GtkEntry *entry = GTK_ENTRY (widget);
4242 gboolean select_on_focus;
4244 GTK_WIDGET_CLASS (gtk_entry_parent_class)->grab_focus (widget);
4246 if (entry->editable && !entry->in_click)
4248 g_object_get (gtk_widget_get_settings (widget),
4249 "gtk-entry-select-on-focus",
4253 if (select_on_focus)
4254 gtk_editable_select_region (GTK_EDITABLE (widget), 0, -1);
4259 gtk_entry_direction_changed (GtkWidget *widget,
4260 GtkTextDirection previous_dir)
4262 GtkEntry *entry = GTK_ENTRY (widget);
4264 gtk_entry_recompute (entry);
4266 GTK_WIDGET_CLASS (gtk_entry_parent_class)->direction_changed (widget, previous_dir);
4270 gtk_entry_state_changed (GtkWidget *widget,
4271 GtkStateType previous_state)
4273 GtkEntry *entry = GTK_ENTRY (widget);
4274 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
4278 if (gtk_widget_get_realized (widget))
4283 style = gtk_widget_get_style (widget);
4284 state = gtk_widget_get_state (widget);
4286 gdk_window_set_background (gtk_widget_get_window (widget),
4287 &style->base[state]);
4288 gdk_window_set_background (entry->text_area,
4289 &style->base[state]);
4290 for (i = 0; i < MAX_ICONS; i++)
4292 EntryIconInfo *icon_info = priv->icons[i];
4293 if (icon_info && icon_info->window)
4294 gdk_window_set_background (icon_info->window,
4295 &style->base[state]);
4298 if (gtk_widget_is_sensitive (widget))
4299 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
4303 gdk_window_set_cursor (entry->text_area, cursor);
4306 gdk_cursor_unref (cursor);
4308 entry->mouse_cursor_obscured = FALSE;
4310 update_cursors (widget);
4313 if (!gtk_widget_is_sensitive (widget))
4315 /* Clear any selection */
4316 gtk_editable_select_region (GTK_EDITABLE (entry), entry->current_pos, entry->current_pos);
4319 gtk_widget_queue_draw (widget);
4323 gtk_entry_screen_changed (GtkWidget *widget,
4324 GdkScreen *old_screen)
4326 gtk_entry_recompute (GTK_ENTRY (widget));
4329 /* GtkEditable method implementations
4332 gtk_entry_insert_text (GtkEditable *editable,
4333 const gchar *new_text,
4334 gint new_text_length,
4337 g_object_ref (editable);
4340 * The incoming text may a password or other secret. We make sure
4341 * not to copy it into temporary buffers.
4344 g_signal_emit_by_name (editable, "insert-text", new_text, new_text_length, position);
4346 g_object_unref (editable);
4350 gtk_entry_delete_text (GtkEditable *editable,
4354 g_object_ref (editable);
4356 g_signal_emit_by_name (editable, "delete-text", start_pos, end_pos);
4358 g_object_unref (editable);
4362 gtk_entry_get_chars (GtkEditable *editable,
4366 GtkEntry *entry = GTK_ENTRY (editable);
4369 gint start_index, end_index;
4371 text = gtk_entry_buffer_get_text (get_buffer (entry));
4372 text_length = gtk_entry_buffer_get_length (get_buffer (entry));
4375 end_pos = text_length;
4377 start_pos = MIN (text_length, start_pos);
4378 end_pos = MIN (text_length, end_pos);
4380 start_index = g_utf8_offset_to_pointer (text, start_pos) - entry->text;
4381 end_index = g_utf8_offset_to_pointer (text, end_pos) - entry->text;
4383 return g_strndup (text + start_index, end_index - start_index);
4387 gtk_entry_real_set_position (GtkEditable *editable,
4390 GtkEntry *entry = GTK_ENTRY (editable);
4394 length = gtk_entry_buffer_get_length (get_buffer (entry));
4395 if (position < 0 || position > length)
4398 if (position != entry->current_pos ||
4399 position != entry->selection_bound)
4401 _gtk_entry_reset_im_context (entry);
4402 gtk_entry_set_positions (entry, position, position);
4407 gtk_entry_get_position (GtkEditable *editable)
4409 return GTK_ENTRY (editable)->current_pos;
4413 gtk_entry_set_selection_bounds (GtkEditable *editable,
4417 GtkEntry *entry = GTK_ENTRY (editable);
4420 length = gtk_entry_buffer_get_length (get_buffer (entry));
4426 _gtk_entry_reset_im_context (entry);
4428 gtk_entry_set_positions (entry,
4430 MIN (start, length));
4432 gtk_entry_update_primary_selection (entry);
4436 gtk_entry_get_selection_bounds (GtkEditable *editable,
4440 GtkEntry *entry = GTK_ENTRY (editable);
4442 *start = entry->selection_bound;
4443 *end = entry->current_pos;
4445 return (entry->selection_bound != entry->current_pos);
4449 icon_theme_changed (GtkEntry *entry)
4451 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
4454 for (i = 0; i < MAX_ICONS; i++)
4456 EntryIconInfo *icon_info = priv->icons[i];
4457 if (icon_info != NULL)
4459 if (icon_info->storage_type == GTK_IMAGE_ICON_NAME)
4460 gtk_entry_set_icon_from_icon_name (entry, i, icon_info->icon_name);
4461 else if (icon_info->storage_type == GTK_IMAGE_STOCK)
4462 gtk_entry_set_icon_from_stock (entry, i, icon_info->stock_id);
4463 else if (icon_info->storage_type == GTK_IMAGE_GICON)
4464 gtk_entry_set_icon_from_gicon (entry, i, icon_info->gicon);
4468 gtk_widget_queue_draw (GTK_WIDGET (entry));
4472 icon_margin_changed (GtkEntry *entry)
4474 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
4477 _gtk_entry_effective_inner_border (GTK_ENTRY (entry), &border);
4479 priv->icon_margin = border.left;
4483 gtk_entry_style_set (GtkWidget *widget,
4484 GtkStyle *previous_style)
4486 GtkEntry *entry = GTK_ENTRY (widget);
4487 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
4489 gboolean interior_focus;
4492 gtk_widget_style_get (widget,
4493 "focus-line-width", &focus_width,
4494 "interior-focus", &interior_focus,
4497 priv->focus_width = focus_width;
4498 priv->interior_focus = interior_focus;
4500 if (!priv->invisible_char_set)
4501 entry->invisible_char = find_invisible_char (GTK_WIDGET (entry));
4503 gtk_entry_recompute (entry);
4505 if (previous_style && gtk_widget_get_realized (widget))
4509 style = gtk_widget_get_style (widget);
4511 gdk_window_set_background (gtk_widget_get_window (widget),
4512 &style->base[gtk_widget_get_state (widget)]);
4513 gdk_window_set_background (entry->text_area,
4514 &style->base[gtk_widget_get_state (widget)]);
4515 for (i = 0; i < MAX_ICONS; i++)
4517 EntryIconInfo *icon_info = priv->icons[i];
4518 if (icon_info && icon_info->window)
4519 gdk_window_set_background (icon_info->window,
4520 &style->base[gtk_widget_get_state (widget)]);
4524 icon_theme_changed (entry);
4525 icon_margin_changed (entry);
4528 /* GtkCellEditable method implementations
4531 gtk_cell_editable_entry_activated (GtkEntry *entry, gpointer data)
4533 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4534 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4538 gtk_cell_editable_key_press_event (GtkEntry *entry,
4539 GdkEventKey *key_event,
4542 if (key_event->keyval == GDK_Escape)
4544 entry->editing_canceled = TRUE;
4545 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4546 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4551 /* override focus */
4552 if (key_event->keyval == GDK_Up || key_event->keyval == GDK_Down)
4554 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4555 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4564 gtk_entry_start_editing (GtkCellEditable *cell_editable,
4567 GTK_ENTRY (cell_editable)->is_cell_renderer = TRUE;
4569 g_signal_connect (cell_editable, "activate",
4570 G_CALLBACK (gtk_cell_editable_entry_activated), NULL);
4571 g_signal_connect (cell_editable, "key-press-event",
4572 G_CALLBACK (gtk_cell_editable_key_press_event), NULL);
4576 gtk_entry_password_hint_free (GtkEntryPasswordHint *password_hint)
4578 if (password_hint->source_id)
4579 g_source_remove (password_hint->source_id);
4581 g_slice_free (GtkEntryPasswordHint, password_hint);
4586 gtk_entry_remove_password_hint (gpointer data)
4588 GtkEntryPasswordHint *password_hint = g_object_get_qdata (data, quark_password_hint);
4589 password_hint->position = -1;
4591 /* Force the string to be redrawn, but now without a visible character */
4592 gtk_entry_recompute (GTK_ENTRY (data));
4596 /* Default signal handlers
4599 gtk_entry_real_insert_text (GtkEditable *editable,
4600 const gchar *new_text,
4601 gint new_text_length,
4607 n_chars = g_utf8_strlen (new_text, new_text_length);
4610 * The actual insertion into the buffer. This will end up firing the
4611 * following signal handlers: buffer_inserted_text(), buffer_notify_display_text(),
4612 * buffer_notify_text(), buffer_notify_length()
4614 n_inserted = gtk_entry_buffer_insert_text (get_buffer (GTK_ENTRY (editable)), *position, new_text, n_chars);
4616 if (n_inserted != n_chars)
4617 gtk_widget_error_bell (GTK_WIDGET (editable));
4619 *position += n_inserted;
4623 gtk_entry_real_delete_text (GtkEditable *editable,
4628 * The actual deletion from the buffer. This will end up firing the
4629 * following signal handlers: buffer_deleted_text(), buffer_notify_display_text(),
4630 * buffer_notify_text(), buffer_notify_length()
4633 gtk_entry_buffer_delete_text (get_buffer (GTK_ENTRY (editable)), start_pos, end_pos - start_pos);
4636 /* GtkEntryBuffer signal handlers
4639 buffer_inserted_text (GtkEntryBuffer *buffer,
4645 guint password_hint_timeout;
4647 if (entry->current_pos > position)
4648 entry->current_pos += n_chars;
4650 if (entry->selection_bound > position)
4651 entry->selection_bound += n_chars;
4653 /* Calculate the password hint if it needs to be displayed. */
4654 if (n_chars == 1 && !entry->visible)
4656 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
4657 "gtk-entry-password-hint-timeout", &password_hint_timeout,
4660 if (password_hint_timeout > 0)
4662 GtkEntryPasswordHint *password_hint = g_object_get_qdata (G_OBJECT (entry),
4663 quark_password_hint);
4666 password_hint = g_slice_new0 (GtkEntryPasswordHint);
4667 g_object_set_qdata_full (G_OBJECT (entry), quark_password_hint, password_hint,
4668 (GDestroyNotify)gtk_entry_password_hint_free);
4671 password_hint->position = position;
4672 if (password_hint->source_id)
4673 g_source_remove (password_hint->source_id);
4674 password_hint->source_id = gdk_threads_add_timeout (password_hint_timeout,
4675 (GSourceFunc)gtk_entry_remove_password_hint, entry);
4681 buffer_deleted_text (GtkEntryBuffer *buffer,
4686 guint end_pos = position + n_chars;
4687 gint selection_bound;
4690 current_pos = entry->current_pos;
4691 if (current_pos > position)
4692 current_pos -= MIN (current_pos, end_pos) - position;
4694 selection_bound = entry->selection_bound;
4695 if (selection_bound > position)
4696 selection_bound -= MIN (selection_bound, end_pos) - position;
4698 gtk_entry_set_positions (entry, current_pos, selection_bound);
4700 /* We might have deleted the selection */
4701 gtk_entry_update_primary_selection (entry);
4703 /* Disable the password hint if one exists. */
4704 if (!entry->visible)
4706 GtkEntryPasswordHint *password_hint = g_object_get_qdata (G_OBJECT (entry),
4707 quark_password_hint);
4710 if (password_hint->source_id)
4711 g_source_remove (password_hint->source_id);
4712 password_hint->source_id = 0;
4713 password_hint->position = -1;
4719 buffer_notify_text (GtkEntryBuffer *buffer,
4723 /* COMPAT: Deprecated, not used. This struct field will be removed in GTK+ 3.x */
4724 entry->text = (gchar*)gtk_entry_buffer_get_text (buffer);
4726 gtk_entry_recompute (entry);
4727 emit_changed (entry);
4728 g_object_notify (G_OBJECT (entry), "text");
4732 buffer_notify_length (GtkEntryBuffer *buffer,
4736 /* COMPAT: Deprecated, not used. This struct field will be removed in GTK+ 3.x */
4737 entry->text_length = gtk_entry_buffer_get_length (buffer);
4739 g_object_notify (G_OBJECT (entry), "text-length");
4743 buffer_notify_max_length (GtkEntryBuffer *buffer,
4747 /* COMPAT: Deprecated, not used. This struct field will be removed in GTK+ 3.x */
4748 entry->text_max_length = gtk_entry_buffer_get_max_length (buffer);
4750 g_object_notify (G_OBJECT (entry), "max-length");
4754 buffer_connect_signals (GtkEntry *entry)
4756 g_signal_connect (get_buffer (entry), "inserted-text", G_CALLBACK (buffer_inserted_text), entry);
4757 g_signal_connect (get_buffer (entry), "deleted-text", G_CALLBACK (buffer_deleted_text), entry);
4758 g_signal_connect (get_buffer (entry), "notify::text", G_CALLBACK (buffer_notify_text), entry);
4759 g_signal_connect (get_buffer (entry), "notify::length", G_CALLBACK (buffer_notify_length), entry);
4760 g_signal_connect (get_buffer (entry), "notify::max-length", G_CALLBACK (buffer_notify_max_length), entry);
4764 buffer_disconnect_signals (GtkEntry *entry)
4766 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_inserted_text, entry);
4767 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_deleted_text, entry);
4768 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_text, entry);
4769 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_length, entry);
4770 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_max_length, entry);
4773 /* Compute the X position for an offset that corresponds to the "more important
4774 * cursor position for that offset. We use this when trying to guess to which
4775 * end of the selection we should go to when the user hits the left or
4779 get_better_cursor_x (GtkEntry *entry,
4782 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
4783 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
4784 gboolean split_cursor;
4786 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
4787 const gchar *text = pango_layout_get_text (layout);
4788 gint index = g_utf8_offset_to_pointer (text, offset) - text;
4790 PangoRectangle strong_pos, weak_pos;
4792 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
4793 "gtk-split-cursor", &split_cursor,
4796 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
4799 return strong_pos.x / PANGO_SCALE;
4801 return (keymap_direction == entry->resolved_dir) ? strong_pos.x / PANGO_SCALE : weak_pos.x / PANGO_SCALE;
4805 gtk_entry_move_cursor (GtkEntry *entry,
4806 GtkMovementStep step,
4808 gboolean extend_selection)
4810 gint new_pos = entry->current_pos;
4811 GtkEntryPrivate *priv;
4813 _gtk_entry_reset_im_context (entry);
4815 if (entry->current_pos != entry->selection_bound && !extend_selection)
4817 /* If we have a current selection and aren't extending it, move to the
4818 * start/or end of the selection as appropriate
4822 case GTK_MOVEMENT_VISUAL_POSITIONS:
4824 gint current_x = get_better_cursor_x (entry, entry->current_pos);
4825 gint bound_x = get_better_cursor_x (entry, entry->selection_bound);
4828 new_pos = current_x < bound_x ? entry->current_pos : entry->selection_bound;
4830 new_pos = current_x > bound_x ? entry->current_pos : entry->selection_bound;
4833 case GTK_MOVEMENT_LOGICAL_POSITIONS:
4834 case GTK_MOVEMENT_WORDS:
4836 new_pos = MIN (entry->current_pos, entry->selection_bound);
4838 new_pos = MAX (entry->current_pos, entry->selection_bound);
4840 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
4841 case GTK_MOVEMENT_PARAGRAPH_ENDS:
4842 case GTK_MOVEMENT_BUFFER_ENDS:
4843 priv = GTK_ENTRY_GET_PRIVATE (entry);
4844 new_pos = count < 0 ? 0 : gtk_entry_buffer_get_length (get_buffer (entry));
4846 case GTK_MOVEMENT_DISPLAY_LINES:
4847 case GTK_MOVEMENT_PARAGRAPHS:
4848 case GTK_MOVEMENT_PAGES:
4849 case GTK_MOVEMENT_HORIZONTAL_PAGES:
4857 case GTK_MOVEMENT_LOGICAL_POSITIONS:
4858 new_pos = gtk_entry_move_logically (entry, new_pos, count);
4860 case GTK_MOVEMENT_VISUAL_POSITIONS:
4861 new_pos = gtk_entry_move_visually (entry, new_pos, count);
4862 if (entry->current_pos == new_pos)
4864 if (!extend_selection)
4866 if (!gtk_widget_keynav_failed (GTK_WIDGET (entry),
4868 GTK_DIR_RIGHT : GTK_DIR_LEFT))
4870 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (entry));
4873 gtk_widget_child_focus (toplevel,
4875 GTK_DIR_RIGHT : GTK_DIR_LEFT);
4880 gtk_widget_error_bell (GTK_WIDGET (entry));
4884 case GTK_MOVEMENT_WORDS:
4887 new_pos = gtk_entry_move_forward_word (entry, new_pos, FALSE);
4892 new_pos = gtk_entry_move_backward_word (entry, new_pos, FALSE);
4895 if (entry->current_pos == new_pos)
4896 gtk_widget_error_bell (GTK_WIDGET (entry));
4898 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
4899 case GTK_MOVEMENT_PARAGRAPH_ENDS:
4900 case GTK_MOVEMENT_BUFFER_ENDS:
4901 priv = GTK_ENTRY_GET_PRIVATE (entry);
4902 new_pos = count < 0 ? 0 : gtk_entry_buffer_get_length (get_buffer (entry));
4903 if (entry->current_pos == new_pos)
4904 gtk_widget_error_bell (GTK_WIDGET (entry));
4906 case GTK_MOVEMENT_DISPLAY_LINES:
4907 case GTK_MOVEMENT_PARAGRAPHS:
4908 case GTK_MOVEMENT_PAGES:
4909 case GTK_MOVEMENT_HORIZONTAL_PAGES:
4914 if (extend_selection)
4915 gtk_editable_select_region (GTK_EDITABLE (entry), entry->selection_bound, new_pos);
4917 gtk_editable_set_position (GTK_EDITABLE (entry), new_pos);
4919 gtk_entry_pend_cursor_blink (entry);
4923 gtk_entry_insert_at_cursor (GtkEntry *entry,
4926 GtkEditable *editable = GTK_EDITABLE (entry);
4927 gint pos = entry->current_pos;
4929 if (entry->editable)
4931 _gtk_entry_reset_im_context (entry);
4933 gtk_editable_insert_text (editable, str, -1, &pos);
4934 gtk_editable_set_position (editable, pos);
4939 gtk_entry_delete_from_cursor (GtkEntry *entry,
4943 GtkEditable *editable = GTK_EDITABLE (entry);
4944 gint start_pos = entry->current_pos;
4945 gint end_pos = entry->current_pos;
4946 gint old_n_bytes = gtk_entry_buffer_get_bytes (get_buffer (entry));
4948 _gtk_entry_reset_im_context (entry);
4950 if (!entry->editable)
4952 gtk_widget_error_bell (GTK_WIDGET (entry));
4956 if (entry->selection_bound != entry->current_pos)
4958 gtk_editable_delete_selection (editable);
4964 case GTK_DELETE_CHARS:
4965 end_pos = gtk_entry_move_logically (entry, entry->current_pos, count);
4966 gtk_editable_delete_text (editable, MIN (start_pos, end_pos), MAX (start_pos, end_pos));
4968 case GTK_DELETE_WORDS:
4971 /* Move to end of current word, or if not on a word, end of previous word */
4972 end_pos = gtk_entry_move_backward_word (entry, end_pos, FALSE);
4973 end_pos = gtk_entry_move_forward_word (entry, end_pos, FALSE);
4977 /* Move to beginning of current word, or if not on a word, begining of next word */
4978 start_pos = gtk_entry_move_forward_word (entry, start_pos, FALSE);
4979 start_pos = gtk_entry_move_backward_word (entry, start_pos, FALSE);
4983 case GTK_DELETE_WORD_ENDS:
4986 start_pos = gtk_entry_move_backward_word (entry, start_pos, FALSE);
4991 end_pos = gtk_entry_move_forward_word (entry, end_pos, FALSE);
4994 gtk_editable_delete_text (editable, start_pos, end_pos);
4996 case GTK_DELETE_DISPLAY_LINE_ENDS:
4997 case GTK_DELETE_PARAGRAPH_ENDS:
4999 gtk_editable_delete_text (editable, 0, entry->current_pos);
5001 gtk_editable_delete_text (editable, entry->current_pos, -1);
5003 case GTK_DELETE_DISPLAY_LINES:
5004 case GTK_DELETE_PARAGRAPHS:
5005 gtk_editable_delete_text (editable, 0, -1);
5007 case GTK_DELETE_WHITESPACE:
5008 gtk_entry_delete_whitespace (entry);
5012 if (gtk_entry_buffer_get_bytes (get_buffer (entry)) == old_n_bytes)
5013 gtk_widget_error_bell (GTK_WIDGET (entry));
5015 gtk_entry_pend_cursor_blink (entry);
5019 gtk_entry_backspace (GtkEntry *entry)
5021 GtkEditable *editable = GTK_EDITABLE (entry);
5024 _gtk_entry_reset_im_context (entry);
5026 if (!entry->editable)
5028 gtk_widget_error_bell (GTK_WIDGET (entry));
5032 if (entry->selection_bound != entry->current_pos)
5034 gtk_editable_delete_selection (editable);
5038 prev_pos = gtk_entry_move_logically (entry, entry->current_pos, -1);
5040 if (prev_pos < entry->current_pos)
5042 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
5043 PangoLogAttr *log_attrs;
5046 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
5048 /* Deleting parts of characters */
5049 if (log_attrs[entry->current_pos].backspace_deletes_character)
5051 gchar *cluster_text;
5052 gchar *normalized_text;
5055 cluster_text = gtk_entry_get_display_text (entry, prev_pos,
5056 entry->current_pos);
5057 normalized_text = g_utf8_normalize (cluster_text,
5058 strlen (cluster_text),
5060 len = g_utf8_strlen (normalized_text, -1);
5062 gtk_editable_delete_text (editable, prev_pos, entry->current_pos);
5065 gint pos = entry->current_pos;
5067 gtk_editable_insert_text (editable, normalized_text,
5068 g_utf8_offset_to_pointer (normalized_text, len - 1) - normalized_text,
5070 gtk_editable_set_position (editable, pos);
5073 g_free (normalized_text);
5074 g_free (cluster_text);
5078 gtk_editable_delete_text (editable, prev_pos, entry->current_pos);
5085 gtk_widget_error_bell (GTK_WIDGET (entry));
5088 gtk_entry_pend_cursor_blink (entry);
5092 gtk_entry_copy_clipboard (GtkEntry *entry)
5094 GtkEditable *editable = GTK_EDITABLE (entry);
5098 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5100 if (!entry->visible)
5102 gtk_widget_error_bell (GTK_WIDGET (entry));
5106 str = gtk_entry_get_display_text (entry, start, end);
5107 gtk_clipboard_set_text (gtk_widget_get_clipboard (GTK_WIDGET (entry),
5108 GDK_SELECTION_CLIPBOARD),
5115 gtk_entry_cut_clipboard (GtkEntry *entry)
5117 GtkEditable *editable = GTK_EDITABLE (entry);
5120 if (!entry->visible)
5122 gtk_widget_error_bell (GTK_WIDGET (entry));
5126 gtk_entry_copy_clipboard (entry);
5128 if (entry->editable)
5130 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5131 gtk_editable_delete_text (editable, start, end);
5135 gtk_widget_error_bell (GTK_WIDGET (entry));
5140 gtk_entry_paste_clipboard (GtkEntry *entry)
5142 if (entry->editable)
5143 gtk_entry_paste (entry, GDK_NONE);
5145 gtk_widget_error_bell (GTK_WIDGET (entry));
5149 gtk_entry_delete_cb (GtkEntry *entry)
5151 GtkEditable *editable = GTK_EDITABLE (entry);
5154 if (entry->editable)
5156 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5157 gtk_editable_delete_text (editable, start, end);
5162 gtk_entry_toggle_overwrite (GtkEntry *entry)
5164 entry->overwrite_mode = !entry->overwrite_mode;
5165 gtk_entry_pend_cursor_blink (entry);
5166 gtk_widget_queue_draw (GTK_WIDGET (entry));
5170 gtk_entry_select_all (GtkEntry *entry)
5172 gtk_entry_select_line (entry);
5176 gtk_entry_real_activate (GtkEntry *entry)
5179 GtkWidget *toplevel;
5182 widget = GTK_WIDGET (entry);
5184 if (entry->activates_default)
5186 toplevel = gtk_widget_get_toplevel (widget);
5187 if (GTK_IS_WINDOW (toplevel))
5189 window = GTK_WINDOW (toplevel);
5192 widget != window->default_widget &&
5193 !(widget == window->focus_widget &&
5194 (!window->default_widget || !gtk_widget_get_sensitive (window->default_widget))))
5195 gtk_window_activate_default (window);
5201 keymap_direction_changed (GdkKeymap *keymap,
5204 gtk_entry_recompute (entry);
5207 /* IM Context Callbacks
5211 gtk_entry_commit_cb (GtkIMContext *context,
5215 if (entry->editable)
5216 gtk_entry_enter_text (entry, str);
5220 gtk_entry_preedit_changed_cb (GtkIMContext *context,
5223 if (entry->editable)
5225 gchar *preedit_string;
5228 gtk_im_context_get_preedit_string (entry->im_context,
5229 &preedit_string, NULL,
5231 g_signal_emit (entry, signals[PREEDIT_CHANGED], 0, preedit_string);
5232 entry->preedit_length = strlen (preedit_string);
5233 cursor_pos = CLAMP (cursor_pos, 0, g_utf8_strlen (preedit_string, -1));
5234 entry->preedit_cursor = cursor_pos;
5235 g_free (preedit_string);
5237 gtk_entry_recompute (entry);
5242 gtk_entry_retrieve_surrounding_cb (GtkIMContext *context,
5247 /* XXXX ??? does this even make sense when text is not visible? Should we return FALSE? */
5248 text = gtk_entry_get_display_text (entry, 0, -1);
5249 gtk_im_context_set_surrounding (context, text, strlen (text), /* Length in bytes */
5250 g_utf8_offset_to_pointer (text, entry->current_pos) - text);
5257 gtk_entry_delete_surrounding_cb (GtkIMContext *slave,
5262 if (entry->editable)
5263 gtk_editable_delete_text (GTK_EDITABLE (entry),
5264 entry->current_pos + offset,
5265 entry->current_pos + offset + n_chars);
5270 /* Internal functions
5273 /* Used for im_commit_cb and inserting Unicode chars */
5275 gtk_entry_enter_text (GtkEntry *entry,
5278 GtkEditable *editable = GTK_EDITABLE (entry);
5280 gboolean old_need_im_reset;
5282 old_need_im_reset = entry->need_im_reset;
5283 entry->need_im_reset = FALSE;
5285 if (gtk_editable_get_selection_bounds (editable, NULL, NULL))
5286 gtk_editable_delete_selection (editable);
5289 if (entry->overwrite_mode)
5290 gtk_entry_delete_from_cursor (entry, GTK_DELETE_CHARS, 1);
5293 tmp_pos = entry->current_pos;
5294 gtk_editable_insert_text (editable, str, strlen (str), &tmp_pos);
5295 gtk_editable_set_position (editable, tmp_pos);
5297 entry->need_im_reset = old_need_im_reset;
5300 /* All changes to entry->current_pos and entry->selection_bound
5301 * should go through this function.
5304 gtk_entry_set_positions (GtkEntry *entry,
5306 gint selection_bound)
5308 gboolean changed = FALSE;
5310 g_object_freeze_notify (G_OBJECT (entry));
5312 if (current_pos != -1 &&
5313 entry->current_pos != current_pos)
5315 entry->current_pos = current_pos;
5318 g_object_notify (G_OBJECT (entry), "cursor-position");
5321 if (selection_bound != -1 &&
5322 entry->selection_bound != selection_bound)
5324 entry->selection_bound = selection_bound;
5327 g_object_notify (G_OBJECT (entry), "selection-bound");
5330 g_object_thaw_notify (G_OBJECT (entry));
5334 gtk_entry_move_adjustments (entry);
5335 gtk_entry_recompute (entry);
5340 gtk_entry_reset_layout (GtkEntry *entry)
5342 if (entry->cached_layout)
5344 g_object_unref (entry->cached_layout);
5345 entry->cached_layout = NULL;
5350 update_im_cursor_location (GtkEntry *entry)
5354 gint strong_xoffset;
5355 gint area_width, area_height;
5357 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
5358 gtk_entry_get_text_area_size (entry, NULL, NULL, &area_width, &area_height);
5360 strong_xoffset = strong_x - entry->scroll_offset;
5361 if (strong_xoffset < 0)
5365 else if (strong_xoffset > area_width)
5367 strong_xoffset = area_width;
5369 area.x = strong_xoffset;
5372 area.height = area_height;
5374 gtk_im_context_set_cursor_location (entry->im_context, &area);
5378 recompute_idle_func (gpointer data)
5382 entry = GTK_ENTRY (data);
5384 entry->recompute_idle = 0;
5386 if (gtk_widget_has_screen (GTK_WIDGET (entry)))
5388 gtk_entry_adjust_scroll (entry);
5389 gtk_entry_queue_draw (entry);
5391 update_im_cursor_location (entry);
5398 gtk_entry_recompute (GtkEntry *entry)
5400 gtk_entry_reset_layout (entry);
5401 gtk_entry_check_cursor_blink (entry);
5403 if (!entry->recompute_idle)
5405 entry->recompute_idle = gdk_threads_add_idle_full (G_PRIORITY_HIGH_IDLE + 15, /* between resize and redraw */
5406 recompute_idle_func, entry, NULL);
5410 static PangoLayout *
5411 gtk_entry_create_layout (GtkEntry *entry,
5412 gboolean include_preedit)
5414 GtkWidget *widget = GTK_WIDGET (entry);
5415 PangoLayout *layout = gtk_widget_create_pango_layout (widget, NULL);
5416 PangoAttrList *tmp_attrs = pango_attr_list_new ();
5418 gchar *preedit_string = NULL;
5419 gint preedit_length = 0;
5420 PangoAttrList *preedit_attrs = NULL;
5425 pango_layout_set_single_paragraph_mode (layout, TRUE);
5427 display = gtk_entry_get_display_text (entry, 0, -1);
5428 n_bytes = strlen (display);
5430 if (include_preedit)
5432 gtk_im_context_get_preedit_string (entry->im_context,
5433 &preedit_string, &preedit_attrs, NULL);
5434 preedit_length = entry->preedit_length;
5439 GString *tmp_string = g_string_new (display);
5440 gint cursor_index = g_utf8_offset_to_pointer (display, entry->current_pos) - display;
5442 g_string_insert (tmp_string, cursor_index, preedit_string);
5444 pango_layout_set_text (layout, tmp_string->str, tmp_string->len);
5446 pango_attr_list_splice (tmp_attrs, preedit_attrs,
5447 cursor_index, preedit_length);
5449 g_string_free (tmp_string, TRUE);
5453 PangoDirection pango_dir;
5455 if (gtk_entry_get_display_mode (entry) == DISPLAY_NORMAL)
5456 pango_dir = pango_find_base_dir (display, n_bytes);
5458 pango_dir = PANGO_DIRECTION_NEUTRAL;
5460 if (pango_dir == PANGO_DIRECTION_NEUTRAL)
5462 if (gtk_widget_has_focus (widget))
5464 GdkDisplay *display = gtk_widget_get_display (widget);
5465 GdkKeymap *keymap = gdk_keymap_get_for_display (display);
5466 if (gdk_keymap_get_direction (keymap) == PANGO_DIRECTION_RTL)
5467 pango_dir = PANGO_DIRECTION_RTL;
5469 pango_dir = PANGO_DIRECTION_LTR;
5473 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
5474 pango_dir = PANGO_DIRECTION_RTL;
5476 pango_dir = PANGO_DIRECTION_LTR;
5480 pango_context_set_base_dir (gtk_widget_get_pango_context (widget),
5483 entry->resolved_dir = pango_dir;
5485 pango_layout_set_text (layout, display, n_bytes);
5488 pango_layout_set_attributes (layout, tmp_attrs);
5490 g_free (preedit_string);
5494 pango_attr_list_unref (preedit_attrs);
5496 pango_attr_list_unref (tmp_attrs);
5501 static PangoLayout *
5502 gtk_entry_ensure_layout (GtkEntry *entry,
5503 gboolean include_preedit)
5505 if (entry->preedit_length > 0 &&
5506 !include_preedit != !entry->cache_includes_preedit)
5507 gtk_entry_reset_layout (entry);
5509 if (!entry->cached_layout)
5511 entry->cached_layout = gtk_entry_create_layout (entry, include_preedit);
5512 entry->cache_includes_preedit = include_preedit;
5515 return entry->cached_layout;
5519 get_layout_position (GtkEntry *entry,
5523 PangoLayout *layout;
5524 PangoRectangle logical_rect;
5525 gint area_width, area_height;
5526 GtkBorder inner_border;
5528 PangoLayoutLine *line;
5530 layout = gtk_entry_ensure_layout (entry, TRUE);
5532 gtk_entry_get_text_area_size (entry, NULL, NULL, &area_width, &area_height);
5533 _gtk_entry_effective_inner_border (entry, &inner_border);
5535 area_height = PANGO_SCALE * (area_height - inner_border.top - inner_border.bottom);
5537 line = pango_layout_get_lines_readonly (layout)->data;
5538 pango_layout_line_get_extents (line, NULL, &logical_rect);
5540 /* Align primarily for locale's ascent/descent */
5541 y_pos = ((area_height - entry->ascent - entry->descent) / 2 +
5542 entry->ascent + logical_rect.y);
5544 /* Now see if we need to adjust to fit in actual drawn string */
5545 if (logical_rect.height > area_height)
5546 y_pos = (area_height - logical_rect.height) / 2;
5549 else if (y_pos + logical_rect.height > area_height)
5550 y_pos = area_height - logical_rect.height;
5552 y_pos = inner_border.top + y_pos / PANGO_SCALE;
5555 *x = inner_border.left - entry->scroll_offset;
5562 draw_text_with_color (GtkEntry *entry, cairo_t *cr, GdkColor *default_color)
5564 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
5567 gint start_pos, end_pos;
5569 widget = GTK_WIDGET (entry);
5573 get_layout_position (entry, &x, &y);
5575 cairo_move_to (cr, x, y);
5576 gdk_cairo_set_source_color (cr, default_color);
5577 pango_cairo_show_layout (cr, layout);
5579 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start_pos, &end_pos))
5583 PangoRectangle logical_rect;
5584 GdkColor *selection_color, *text_color;
5585 GtkBorder inner_border;
5588 pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
5589 gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
5591 style = gtk_widget_get_style (widget);
5593 if (gtk_widget_has_focus (widget))
5595 selection_color = &style->base [GTK_STATE_SELECTED];
5596 text_color = &style->text [GTK_STATE_SELECTED];
5600 selection_color = &style->base [GTK_STATE_ACTIVE];
5601 text_color = &style->text [GTK_STATE_ACTIVE];
5604 _gtk_entry_effective_inner_border (entry, &inner_border);
5606 for (i = 0; i < n_ranges; ++i)
5607 cairo_rectangle (cr,
5608 inner_border.left - entry->scroll_offset + ranges[2 * i],
5611 logical_rect.height);
5615 gdk_cairo_set_source_color (cr, selection_color);
5618 cairo_move_to (cr, x, y);
5619 gdk_cairo_set_source_color (cr, text_color);
5620 pango_cairo_show_layout (cr, layout);
5628 gtk_entry_draw_text (GtkEntry *entry)
5630 GtkWidget *widget = GTK_WIDGET (entry);
5633 /* Nothing to display at all */
5634 if (gtk_entry_get_display_mode (entry) == DISPLAY_BLANK)
5637 if (gtk_widget_is_drawable (widget))
5641 GdkColor text_color, bar_text_color;
5644 gint progress_x, progress_y, progress_width, progress_height;
5646 state = GTK_STATE_SELECTED;
5647 if (!gtk_widget_get_sensitive (widget))
5648 state = GTK_STATE_INSENSITIVE;
5649 style = gtk_widget_get_style (widget);
5650 text_color = style->text[gtk_widget_get_state (widget)];
5651 bar_text_color = style->fg[state];
5653 get_progress_area (widget,
5654 &progress_x, &progress_y,
5655 &progress_width, &progress_height);
5657 cr = gdk_cairo_create (entry->text_area);
5659 /* If the color is the same, or the progress area has a zero
5660 * size, then we only need to draw once. */
5661 if ((text_color.pixel == bar_text_color.pixel) ||
5662 ((progress_width == 0) || (progress_height == 0)))
5664 draw_text_with_color (entry, cr, &text_color);
5668 gdk_drawable_get_size (entry->text_area, &width, &height);
5670 cairo_rectangle (cr, 0, 0, width, height);
5674 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
5675 cairo_rectangle (cr, 0, 0, width, height);
5677 gdk_window_get_position (entry->text_area, &pos_x, &pos_y);
5678 progress_x -= pos_x;
5679 progress_y -= pos_y;
5681 cairo_rectangle (cr, progress_x, progress_y,
5682 progress_width, progress_height);
5684 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_WINDING);
5686 draw_text_with_color (entry, cr, &text_color);
5689 cairo_rectangle (cr, progress_x, progress_y,
5690 progress_width, progress_height);
5693 draw_text_with_color (entry, cr, &bar_text_color);
5701 draw_insertion_cursor (GtkEntry *entry,
5702 GdkRectangle *cursor_location,
5703 gboolean is_primary,
5704 PangoDirection direction,
5705 gboolean draw_arrow)
5707 GtkWidget *widget = GTK_WIDGET (entry);
5708 GtkTextDirection text_dir;
5710 if (direction == PANGO_DIRECTION_LTR)
5711 text_dir = GTK_TEXT_DIR_LTR;
5713 text_dir = GTK_TEXT_DIR_RTL;
5715 gtk_draw_insertion_cursor (widget, entry->text_area, NULL,
5717 is_primary, text_dir, draw_arrow);
5721 gtk_entry_draw_cursor (GtkEntry *entry,
5724 GtkWidget *widget = GTK_WIDGET (entry);
5725 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
5726 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
5728 if (gtk_widget_is_drawable (widget))
5730 GdkRectangle cursor_location;
5731 gboolean split_cursor;
5732 PangoRectangle cursor_rect;
5733 GtkBorder inner_border;
5735 gint text_area_height;
5738 gboolean block_at_line_end;
5739 PangoLayout *layout;
5742 _gtk_entry_effective_inner_border (entry, &inner_border);
5744 xoffset = inner_border.left - entry->scroll_offset;
5746 gdk_drawable_get_size (entry->text_area, NULL, &text_area_height);
5748 layout = gtk_entry_ensure_layout (entry, TRUE);
5749 text = pango_layout_get_text (layout);
5750 cursor_index = g_utf8_offset_to_pointer (text, entry->current_pos + entry->preedit_cursor) - text;
5751 if (!entry->overwrite_mode)
5754 block = _gtk_text_util_get_block_cursor_location (layout,
5755 cursor_index, &cursor_rect, &block_at_line_end);
5759 gint strong_x, weak_x;
5760 PangoDirection dir1 = PANGO_DIRECTION_NEUTRAL;
5761 PangoDirection dir2 = PANGO_DIRECTION_NEUTRAL;
5765 gtk_entry_get_cursor_locations (entry, type, &strong_x, &weak_x);
5767 g_object_get (gtk_widget_get_settings (widget),
5768 "gtk-split-cursor", &split_cursor,
5771 dir1 = entry->resolved_dir;
5777 if (weak_x != strong_x)
5779 dir2 = (entry->resolved_dir == PANGO_DIRECTION_LTR) ? PANGO_DIRECTION_RTL : PANGO_DIRECTION_LTR;
5785 if (keymap_direction == entry->resolved_dir)
5791 cursor_location.x = xoffset + x1;
5792 cursor_location.y = inner_border.top;
5793 cursor_location.width = 0;
5794 cursor_location.height = text_area_height - inner_border.top - inner_border.bottom;
5796 draw_insertion_cursor (entry,
5797 &cursor_location, TRUE, dir1,
5798 dir2 != PANGO_DIRECTION_NEUTRAL);
5800 if (dir2 != PANGO_DIRECTION_NEUTRAL)
5802 cursor_location.x = xoffset + x2;
5803 draw_insertion_cursor (entry,
5804 &cursor_location, FALSE, dir2,
5808 else /* overwrite_mode */
5810 GdkColor cursor_color;
5815 get_layout_position (entry, &x, &y);
5817 rect.x = PANGO_PIXELS (cursor_rect.x) + x;
5818 rect.y = PANGO_PIXELS (cursor_rect.y) + y;
5819 rect.width = PANGO_PIXELS (cursor_rect.width);
5820 rect.height = PANGO_PIXELS (cursor_rect.height);
5822 cr = gdk_cairo_create (entry->text_area);
5824 _gtk_widget_get_cursor_color (widget, &cursor_color);
5825 gdk_cairo_set_source_color (cr, &cursor_color);
5826 gdk_cairo_rectangle (cr, &rect);
5829 if (!block_at_line_end)
5831 gdk_cairo_rectangle (cr, &rect);
5833 cairo_move_to (cr, x, y);
5834 gdk_cairo_set_source_color (cr, >k_widget_get_style (widget)->base[gtk_widget_get_state (widget)]);
5835 pango_cairo_show_layout (cr, layout);
5844 gtk_entry_queue_draw (GtkEntry *entry)
5846 if (gtk_widget_is_drawable (GTK_WIDGET (entry)))
5847 gdk_window_invalidate_rect (entry->text_area, NULL, FALSE);
5851 _gtk_entry_reset_im_context (GtkEntry *entry)
5853 if (entry->need_im_reset)
5855 entry->need_im_reset = FALSE;
5856 gtk_im_context_reset (entry->im_context);
5861 * gtk_entry_reset_im_context:
5862 * @entry: a #GtkEntry
5864 * Reset the input method context of the entry if needed.
5866 * This can be necessary in the case where modifying the buffer
5867 * would confuse on-going input method behavior.
5872 gtk_entry_reset_im_context (GtkEntry *entry)
5874 g_return_if_fail (GTK_IS_ENTRY (entry));
5876 _gtk_entry_reset_im_context (entry);
5880 * gtk_entry_im_context_filter_keypress:
5881 * @entry: a #GtkEntry
5882 * @event: the key event
5884 * Allow the #GtkEntry input method to internally handle key press
5885 * and release events. If this function returns %TRUE, then no further
5886 * processing should be done for this key event. See
5887 * gtk_im_context_filter_keypress().
5889 * Note that you are expected to call this function from your handler
5890 * when overriding key event handling. This is needed in the case when
5891 * you need to insert your own key handling between the input method
5892 * and the default key event handling of the #GtkEntry.
5893 * See gtk_text_view_reset_im_context() for an example of use.
5895 * Return value: %TRUE if the input method handled the key event.
5900 gtk_entry_im_context_filter_keypress (GtkEntry *entry,
5903 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
5905 return gtk_im_context_filter_keypress (entry->im_context, event);
5910 gtk_entry_find_position (GtkEntry *entry,
5913 PangoLayout *layout;
5914 PangoLayoutLine *line;
5921 layout = gtk_entry_ensure_layout (entry, TRUE);
5922 text = pango_layout_get_text (layout);
5923 cursor_index = g_utf8_offset_to_pointer (text, entry->current_pos) - text;
5925 line = pango_layout_get_lines_readonly (layout)->data;
5926 pango_layout_line_x_to_index (line, x * PANGO_SCALE, &index, &trailing);
5928 if (index >= cursor_index && entry->preedit_length)
5930 if (index >= cursor_index + entry->preedit_length)
5931 index -= entry->preedit_length;
5934 index = cursor_index;
5939 pos = g_utf8_pointer_to_offset (text, text + index);
5946 gtk_entry_get_cursor_locations (GtkEntry *entry,
5951 DisplayMode mode = gtk_entry_get_display_mode (entry);
5953 /* Nothing to display at all, so no cursor is relevant */
5954 if (mode == DISPLAY_BLANK)
5964 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
5965 const gchar *text = pango_layout_get_text (layout);
5966 PangoRectangle strong_pos, weak_pos;
5969 if (type == CURSOR_STANDARD)
5971 index = g_utf8_offset_to_pointer (text, entry->current_pos + entry->preedit_cursor) - text;
5973 else /* type == CURSOR_DND */
5975 index = g_utf8_offset_to_pointer (text, entry->dnd_position) - text;
5977 if (entry->dnd_position > entry->current_pos)
5979 if (mode == DISPLAY_NORMAL)
5980 index += entry->preedit_length;
5983 gint preedit_len_chars = g_utf8_strlen (text, -1) - gtk_entry_buffer_get_length (get_buffer (entry));
5984 index += preedit_len_chars * g_unichar_to_utf8 (entry->invisible_char, NULL);
5989 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
5992 *strong_x = strong_pos.x / PANGO_SCALE;
5995 *weak_x = weak_pos.x / PANGO_SCALE;
6000 gtk_entry_adjust_scroll (GtkEntry *entry)
6002 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
6003 gint min_offset, max_offset;
6004 gint text_area_width, text_width;
6005 GtkBorder inner_border;
6006 gint strong_x, weak_x;
6007 gint strong_xoffset, weak_xoffset;
6009 PangoLayout *layout;
6010 PangoLayoutLine *line;
6011 PangoRectangle logical_rect;
6013 if (!gtk_widget_get_realized (GTK_WIDGET (entry)))
6016 _gtk_entry_effective_inner_border (entry, &inner_border);
6018 gdk_drawable_get_size (entry->text_area, &text_area_width, NULL);
6019 text_area_width -= inner_border.left + inner_border.right;
6020 if (text_area_width < 0)
6021 text_area_width = 0;
6023 layout = gtk_entry_ensure_layout (entry, TRUE);
6024 line = pango_layout_get_lines_readonly (layout)->data;
6026 pango_layout_line_get_extents (line, NULL, &logical_rect);
6028 /* Display as much text as we can */
6030 if (entry->resolved_dir == PANGO_DIRECTION_LTR)
6031 xalign = priv->xalign;
6033 xalign = 1.0 - priv->xalign;
6035 text_width = PANGO_PIXELS(logical_rect.width);
6037 if (text_width > text_area_width)
6040 max_offset = text_width - text_area_width;
6044 min_offset = (text_width - text_area_width) * xalign;
6045 max_offset = min_offset;
6048 entry->scroll_offset = CLAMP (entry->scroll_offset, min_offset, max_offset);
6050 /* And make sure cursors are on screen. Note that the cursor is
6051 * actually drawn one pixel into the INNER_BORDER space on
6052 * the right, when the scroll is at the utmost right. This
6053 * looks better to to me than confining the cursor inside the
6054 * border entirely, though it means that the cursor gets one
6055 * pixel closer to the edge of the widget on the right than
6056 * on the left. This might need changing if one changed
6057 * INNER_BORDER from 2 to 1, as one would do on a
6058 * small-screen-real-estate display.
6060 * We always make sure that the strong cursor is on screen, and
6061 * put the weak cursor on screen if possible.
6064 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, &weak_x);
6066 strong_xoffset = strong_x - entry->scroll_offset;
6068 if (strong_xoffset < 0)
6070 entry->scroll_offset += strong_xoffset;
6073 else if (strong_xoffset > text_area_width)
6075 entry->scroll_offset += strong_xoffset - text_area_width;
6076 strong_xoffset = text_area_width;
6079 weak_xoffset = weak_x - entry->scroll_offset;
6081 if (weak_xoffset < 0 && strong_xoffset - weak_xoffset <= text_area_width)
6083 entry->scroll_offset += weak_xoffset;
6085 else if (weak_xoffset > text_area_width &&
6086 strong_xoffset - (weak_xoffset - text_area_width) >= 0)
6088 entry->scroll_offset += weak_xoffset - text_area_width;
6091 g_object_notify (G_OBJECT (entry), "scroll-offset");
6095 gtk_entry_move_adjustments (GtkEntry *entry)
6097 GtkAllocation allocation;
6098 GtkAdjustment *adjustment;
6099 PangoContext *context;
6100 PangoFontMetrics *metrics;
6101 gint x, layout_x, border_x, border_y;
6104 adjustment = g_object_get_qdata (G_OBJECT (entry), quark_cursor_hadjustment);
6108 gtk_widget_get_allocation (&(entry->widget), &allocation);
6110 /* Cursor position, layout offset, border width, and widget allocation */
6111 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &x, NULL);
6112 get_layout_position (entry, &layout_x, NULL);
6113 _gtk_entry_get_borders (entry, &border_x, &border_y);
6114 x += allocation.x + layout_x + border_x;
6116 /* Approximate width of a char, so user can see what is ahead/behind */
6117 context = gtk_widget_get_pango_context (GTK_WIDGET (entry));
6118 metrics = pango_context_get_metrics (context,
6119 gtk_widget_get_style (&(entry->widget))->font_desc,
6120 pango_context_get_language (context));
6121 char_width = pango_font_metrics_get_approximate_char_width (metrics) / PANGO_SCALE;
6124 gtk_adjustment_clamp_page (adjustment,
6125 x - (char_width + 1), /* one char + one pixel before */
6126 x + (char_width + 2)); /* one char + cursor + one pixel after */
6130 gtk_entry_move_visually (GtkEntry *entry,
6135 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6138 text = pango_layout_get_text (layout);
6140 index = g_utf8_offset_to_pointer (text, start) - text;
6144 int new_index, new_trailing;
6145 gboolean split_cursor;
6148 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
6149 "gtk-split-cursor", &split_cursor,
6156 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
6157 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
6159 strong = keymap_direction == entry->resolved_dir;
6164 pango_layout_move_cursor_visually (layout, strong, index, 0, 1, &new_index, &new_trailing);
6169 pango_layout_move_cursor_visually (layout, strong, index, 0, -1, &new_index, &new_trailing);
6175 else if (new_index != G_MAXINT)
6178 while (new_trailing--)
6179 index = g_utf8_next_char (text + index) - text;
6182 return g_utf8_pointer_to_offset (text, text + index);
6186 gtk_entry_move_logically (GtkEntry *entry,
6190 gint new_pos = start;
6193 length = gtk_entry_buffer_get_length (get_buffer (entry));
6195 /* Prevent any leak of information */
6196 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6198 new_pos = CLAMP (start + count, 0, length);
6202 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6203 PangoLogAttr *log_attrs;
6206 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6208 while (count > 0 && new_pos < length)
6212 while (new_pos < length && !log_attrs[new_pos].is_cursor_position);
6216 while (count < 0 && new_pos > 0)
6220 while (new_pos > 0 && !log_attrs[new_pos].is_cursor_position);
6232 gtk_entry_move_forward_word (GtkEntry *entry,
6234 gboolean allow_whitespace)
6236 gint new_pos = start;
6239 length = gtk_entry_buffer_get_length (get_buffer (entry));
6241 /* Prevent any leak of information */
6242 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6246 else if (new_pos < length)
6248 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6249 PangoLogAttr *log_attrs;
6252 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6254 /* Find the next word boundary */
6256 while (new_pos < n_attrs - 1 && !(log_attrs[new_pos].is_word_end ||
6257 (log_attrs[new_pos].is_word_start && allow_whitespace)))
6268 gtk_entry_move_backward_word (GtkEntry *entry,
6270 gboolean allow_whitespace)
6272 gint new_pos = start;
6274 /* Prevent any leak of information */
6275 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6281 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6282 PangoLogAttr *log_attrs;
6285 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6287 new_pos = start - 1;
6289 /* Find the previous word boundary */
6290 while (new_pos > 0 && !(log_attrs[new_pos].is_word_start ||
6291 (log_attrs[new_pos].is_word_end && allow_whitespace)))
6301 gtk_entry_delete_whitespace (GtkEntry *entry)
6303 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6304 PangoLogAttr *log_attrs;
6308 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6310 start = end = entry->current_pos;
6312 while (start > 0 && log_attrs[start-1].is_white)
6315 while (end < n_attrs && log_attrs[end].is_white)
6321 gtk_editable_delete_text (GTK_EDITABLE (entry), start, end);
6326 gtk_entry_select_word (GtkEntry *entry)
6328 gint start_pos = gtk_entry_move_backward_word (entry, entry->current_pos, TRUE);
6329 gint end_pos = gtk_entry_move_forward_word (entry, entry->current_pos, TRUE);
6331 gtk_editable_select_region (GTK_EDITABLE (entry), start_pos, end_pos);
6335 gtk_entry_select_line (GtkEntry *entry)
6337 gtk_editable_select_region (GTK_EDITABLE (entry), 0, -1);
6341 truncate_multiline (const gchar *text)
6346 text[length] && text[length] != '\n' && text[length] != '\r';
6353 paste_received (GtkClipboard *clipboard,
6357 GtkEntry *entry = GTK_ENTRY (data);
6358 GtkEditable *editable = GTK_EDITABLE (entry);
6359 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
6361 if (entry->button == 2)
6363 gint pos, start, end;
6364 pos = priv->insert_pos;
6365 gtk_editable_get_selection_bounds (editable, &start, &end);
6366 if (!((start <= pos && pos <= end) || (end <= pos && pos <= start)))
6367 gtk_editable_select_region (editable, pos, pos);
6372 gint pos, start, end;
6374 gboolean popup_completion;
6375 GtkEntryCompletion *completion;
6377 completion = gtk_entry_get_completion (entry);
6379 if (entry->truncate_multiline)
6380 length = truncate_multiline (text);
6382 /* only complete if the selection is at the end */
6383 popup_completion = (gtk_entry_buffer_get_length (get_buffer (entry)) ==
6384 MAX (entry->current_pos, entry->selection_bound));
6388 if (gtk_widget_get_mapped (completion->priv->popup_window))
6389 _gtk_entry_completion_popdown (completion);
6391 if (!popup_completion && completion->priv->changed_id > 0)
6392 g_signal_handler_block (entry, completion->priv->changed_id);
6395 begin_change (entry);
6396 g_object_freeze_notify (G_OBJECT (entry));
6397 if (gtk_editable_get_selection_bounds (editable, &start, &end))
6398 gtk_editable_delete_text (editable, start, end);
6400 pos = entry->current_pos;
6401 gtk_editable_insert_text (editable, text, length, &pos);
6402 gtk_editable_set_position (editable, pos);
6403 g_object_thaw_notify (G_OBJECT (entry));
6407 !popup_completion && completion->priv->changed_id > 0)
6408 g_signal_handler_unblock (entry, completion->priv->changed_id);
6411 g_object_unref (entry);
6415 gtk_entry_paste (GtkEntry *entry,
6418 g_object_ref (entry);
6419 gtk_clipboard_request_text (gtk_widget_get_clipboard (GTK_WIDGET (entry), selection),
6420 paste_received, entry);
6424 primary_get_cb (GtkClipboard *clipboard,
6425 GtkSelectionData *selection_data,
6429 GtkEntry *entry = GTK_ENTRY (data);
6432 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end))
6434 gchar *str = gtk_entry_get_display_text (entry, start, end);
6435 gtk_selection_data_set_text (selection_data, str, -1);
6441 primary_clear_cb (GtkClipboard *clipboard,
6444 GtkEntry *entry = GTK_ENTRY (data);
6446 gtk_editable_select_region (GTK_EDITABLE (entry), entry->current_pos, entry->current_pos);
6450 gtk_entry_update_primary_selection (GtkEntry *entry)
6452 GtkTargetList *list;
6453 GtkTargetEntry *targets;
6454 GtkClipboard *clipboard;
6458 if (!gtk_widget_get_realized (GTK_WIDGET (entry)))
6461 list = gtk_target_list_new (NULL, 0);
6462 gtk_target_list_add_text_targets (list, 0);
6464 targets = gtk_target_table_new_from_list (list, &n_targets);
6466 clipboard = gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_PRIMARY);
6468 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end))
6470 if (!gtk_clipboard_set_with_owner (clipboard, targets, n_targets,
6471 primary_get_cb, primary_clear_cb, G_OBJECT (entry)))
6472 primary_clear_cb (clipboard, entry);
6476 if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (entry))
6477 gtk_clipboard_clear (clipboard);
6480 gtk_target_table_free (targets, n_targets);
6481 gtk_target_list_unref (list);
6485 gtk_entry_clear (GtkEntry *entry,
6486 GtkEntryIconPosition icon_pos)
6488 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
6489 EntryIconInfo *icon_info = priv->icons[icon_pos];
6491 if (!icon_info || icon_info->storage_type == GTK_IMAGE_EMPTY)
6494 g_object_freeze_notify (G_OBJECT (entry));
6496 /* Explicitly check, as the pointer may become invalidated
6497 * during destruction.
6499 if (GDK_IS_WINDOW (icon_info->window))
6500 gdk_window_hide (icon_info->window);
6502 if (icon_info->pixbuf)
6504 g_object_unref (icon_info->pixbuf);
6505 icon_info->pixbuf = NULL;
6508 switch (icon_info->storage_type)
6510 case GTK_IMAGE_PIXBUF:
6511 g_object_notify (G_OBJECT (entry),
6512 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-pixbuf" : "secondary-icon-pixbuf");
6515 case GTK_IMAGE_STOCK:
6516 g_free (icon_info->stock_id);
6517 icon_info->stock_id = NULL;
6518 g_object_notify (G_OBJECT (entry),
6519 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-stock" : "secondary-icon-stock");
6522 case GTK_IMAGE_ICON_NAME:
6523 g_free (icon_info->icon_name);
6524 icon_info->icon_name = NULL;
6525 g_object_notify (G_OBJECT (entry),
6526 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-name" : "secondary-icon-name");
6529 case GTK_IMAGE_GICON:
6530 if (icon_info->gicon)
6532 g_object_unref (icon_info->gicon);
6533 icon_info->gicon = NULL;
6535 g_object_notify (G_OBJECT (entry),
6536 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-gicon" : "secondary-icon-gicon");
6540 g_assert_not_reached ();
6544 icon_info->storage_type = GTK_IMAGE_EMPTY;
6545 g_object_notify (G_OBJECT (entry),
6546 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-storage-type" : "secondary-icon-storage-type");
6548 g_object_thaw_notify (G_OBJECT (entry));
6552 gtk_entry_ensure_pixbuf (GtkEntry *entry,
6553 GtkEntryIconPosition icon_pos)
6555 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
6556 EntryIconInfo *icon_info = priv->icons[icon_pos];
6558 GtkIconTheme *icon_theme;
6559 GtkSettings *settings;
6565 if (!icon_info || icon_info->pixbuf)
6568 widget = GTK_WIDGET (entry);
6570 switch (icon_info->storage_type)
6572 case GTK_IMAGE_EMPTY:
6573 case GTK_IMAGE_PIXBUF:
6575 case GTK_IMAGE_STOCK:
6576 state = gtk_widget_get_state (widget);
6577 gtk_widget_set_state (widget, GTK_STATE_NORMAL);
6578 icon_info->pixbuf = gtk_widget_render_icon (widget,
6579 icon_info->stock_id,
6582 if (!icon_info->pixbuf)
6583 icon_info->pixbuf = gtk_widget_render_icon (widget,
6584 GTK_STOCK_MISSING_IMAGE,
6587 gtk_widget_set_state (widget, state);
6590 case GTK_IMAGE_ICON_NAME:
6591 screen = gtk_widget_get_screen (widget);
6594 icon_theme = gtk_icon_theme_get_for_screen (screen);
6595 settings = gtk_settings_get_for_screen (screen);
6597 gtk_icon_size_lookup_for_settings (settings,
6601 icon_info->pixbuf = gtk_icon_theme_load_icon (icon_theme,
6602 icon_info->icon_name,
6603 MIN (width, height),
6606 if (icon_info->pixbuf == NULL)
6608 state = gtk_widget_get_state (widget);
6609 gtk_widget_set_state (widget, GTK_STATE_NORMAL);
6610 icon_info->pixbuf = gtk_widget_render_icon (widget,
6611 GTK_STOCK_MISSING_IMAGE,
6614 gtk_widget_set_state (widget, state);
6619 case GTK_IMAGE_GICON:
6620 screen = gtk_widget_get_screen (widget);
6623 icon_theme = gtk_icon_theme_get_for_screen (screen);
6624 settings = gtk_settings_get_for_screen (screen);
6626 gtk_icon_size_lookup_for_settings (settings,
6630 info = gtk_icon_theme_lookup_by_gicon (icon_theme,
6632 MIN (width, height),
6633 GTK_ICON_LOOKUP_USE_BUILTIN);
6636 icon_info->pixbuf = gtk_icon_info_load_icon (info, NULL);
6637 gtk_icon_info_free (info);
6640 if (icon_info->pixbuf == NULL)
6642 state = gtk_widget_get_state (widget);
6643 gtk_widget_set_state (widget, GTK_STATE_NORMAL);
6644 icon_info->pixbuf = gtk_widget_render_icon (widget,
6645 GTK_STOCK_MISSING_IMAGE,
6648 gtk_widget_set_state (widget, state);
6654 g_assert_not_reached ();
6658 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
6659 gdk_window_show_unraised (icon_info->window);
6669 * Creates a new entry.
6671 * Return value: a new #GtkEntry.
6674 gtk_entry_new (void)
6676 return g_object_new (GTK_TYPE_ENTRY, NULL);
6680 * gtk_entry_new_with_buffer:
6681 * @buffer: The buffer to use for the new #GtkEntry.
6683 * Creates a new entry with the specified text buffer.
6685 * Return value: a new #GtkEntry
6690 gtk_entry_new_with_buffer (GtkEntryBuffer *buffer)
6692 g_return_val_if_fail (GTK_IS_ENTRY_BUFFER (buffer), NULL);
6693 return g_object_new (GTK_TYPE_ENTRY, "buffer", buffer, NULL);
6696 static GtkEntryBuffer*
6697 get_buffer (GtkEntry *entry)
6699 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
6701 if (priv->buffer == NULL)
6703 GtkEntryBuffer *buffer;
6704 buffer = gtk_entry_buffer_new (NULL, 0);
6705 gtk_entry_set_buffer (entry, buffer);
6706 g_object_unref (buffer);
6709 return priv->buffer;
6713 * gtk_entry_get_buffer:
6714 * @entry: a #GtkEntry
6716 * Get the #GtkEntryBuffer object which holds the text for
6721 * Returns: A #GtkEntryBuffer object.
6724 gtk_entry_get_buffer (GtkEntry *entry)
6726 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
6728 return get_buffer (entry);
6732 * gtk_entry_set_buffer:
6733 * @entry: a #GtkEntry
6734 * @buffer: a #GtkEntryBuffer
6736 * Set the #GtkEntryBuffer object which holds the text for
6742 gtk_entry_set_buffer (GtkEntry *entry,
6743 GtkEntryBuffer *buffer)
6745 GtkEntryPrivate *priv;
6748 g_return_if_fail (GTK_IS_ENTRY (entry));
6749 priv = GTK_ENTRY_GET_PRIVATE (entry);
6753 g_return_if_fail (GTK_IS_ENTRY_BUFFER (buffer));
6754 g_object_ref (buffer);
6759 buffer_disconnect_signals (entry);
6760 g_object_unref (priv->buffer);
6762 /* COMPAT: Deprecated. Not used. Setting these fields no longer necessary in GTK 3.x */
6764 entry->text_length = 0;
6765 entry->text_max_length = 0;
6768 priv->buffer = buffer;
6772 buffer_connect_signals (entry);
6774 /* COMPAT: Deprecated. Not used. Setting these fields no longer necessary in GTK 3.x */
6775 entry->text = (char*)gtk_entry_buffer_get_text (priv->buffer);
6776 entry->text_length = gtk_entry_buffer_get_length (priv->buffer);
6777 entry->text_max_length = gtk_entry_buffer_get_max_length (priv->buffer);
6780 obj = G_OBJECT (entry);
6781 g_object_freeze_notify (obj);
6782 g_object_notify (obj, "buffer");
6783 g_object_notify (obj, "text");
6784 g_object_notify (obj, "text-length");
6785 g_object_notify (obj, "max-length");
6786 g_object_notify (obj, "visibility");
6787 g_object_notify (obj, "invisible-char");
6788 g_object_notify (obj, "invisible-char-set");
6789 g_object_thaw_notify (obj);
6791 gtk_editable_set_position (GTK_EDITABLE (entry), 0);
6792 gtk_entry_recompute (entry);
6796 * gtk_entry_get_text_window:
6797 * @entry: a #GtkEntry
6799 * Returns the #GdkWindow which contains the text. This function is
6800 * useful when drawing something to the entry in an expose-event
6801 * callback because it enables the callback to distinguish between
6802 * the text window and entry's icon windows.
6804 * See also gtk_entry_get_icon_window().
6806 * Return value: the entry's text window.
6811 gtk_entry_get_text_window (GtkEntry *entry)
6813 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
6815 return entry->text_area;
6820 * gtk_entry_set_text:
6821 * @entry: a #GtkEntry
6822 * @text: the new text
6824 * Sets the text in the widget to the given
6825 * value, replacing the current contents.
6827 * See gtk_entry_buffer_set_text().
6830 gtk_entry_set_text (GtkEntry *entry,
6834 GtkEntryCompletion *completion;
6835 GtkEntryPrivate *priv;
6837 g_return_if_fail (GTK_IS_ENTRY (entry));
6838 g_return_if_fail (text != NULL);
6839 priv = GTK_ENTRY_GET_PRIVATE (entry);
6841 /* Actually setting the text will affect the cursor and selection;
6842 * if the contents don't actually change, this will look odd to the user.
6844 if (strcmp (gtk_entry_buffer_get_text (get_buffer (entry)), text) == 0)
6847 completion = gtk_entry_get_completion (entry);
6848 if (completion && completion->priv->changed_id > 0)
6849 g_signal_handler_block (entry, completion->priv->changed_id);
6851 begin_change (entry);
6852 g_object_freeze_notify (G_OBJECT (entry));
6853 gtk_editable_delete_text (GTK_EDITABLE (entry), 0, -1);
6855 gtk_editable_insert_text (GTK_EDITABLE (entry), text, strlen (text), &tmp_pos);
6856 g_object_thaw_notify (G_OBJECT (entry));
6859 if (completion && completion->priv->changed_id > 0)
6860 g_signal_handler_unblock (entry, completion->priv->changed_id);
6864 * gtk_entry_set_visibility:
6865 * @entry: a #GtkEntry
6866 * @visible: %TRUE if the contents of the entry are displayed
6869 * Sets whether the contents of the entry are visible or not.
6870 * When visibility is set to %FALSE, characters are displayed
6871 * as the invisible char, and will also appear that way when
6872 * the text in the entry widget is copied elsewhere.
6874 * By default, GTK+ picks the best invisible character available
6875 * in the current font, but it can be changed with
6876 * gtk_entry_set_invisible_char().
6879 gtk_entry_set_visibility (GtkEntry *entry,
6882 g_return_if_fail (GTK_IS_ENTRY (entry));
6884 visible = visible != FALSE;
6886 if (entry->visible != visible)
6888 entry->visible = visible;
6890 g_object_notify (G_OBJECT (entry), "visibility");
6891 gtk_entry_recompute (entry);
6896 * gtk_entry_get_visibility:
6897 * @entry: a #GtkEntry
6899 * Retrieves whether the text in @entry is visible. See
6900 * gtk_entry_set_visibility().
6902 * Return value: %TRUE if the text is currently visible
6905 gtk_entry_get_visibility (GtkEntry *entry)
6907 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
6909 return entry->visible;
6913 * gtk_entry_set_invisible_char:
6914 * @entry: a #GtkEntry
6915 * @ch: a Unicode character
6917 * Sets the character to use in place of the actual text when
6918 * gtk_entry_set_visibility() has been called to set text visibility
6919 * to %FALSE. i.e. this is the character used in "password mode" to
6920 * show the user how many characters have been typed. By default, GTK+
6921 * picks the best invisible char available in the current font. If you
6922 * set the invisible char to 0, then the user will get no feedback
6923 * at all; there will be no text on the screen as they type.
6926 gtk_entry_set_invisible_char (GtkEntry *entry,
6929 GtkEntryPrivate *priv;
6931 g_return_if_fail (GTK_IS_ENTRY (entry));
6933 priv = GTK_ENTRY_GET_PRIVATE (entry);
6935 if (!priv->invisible_char_set)
6937 priv->invisible_char_set = TRUE;
6938 g_object_notify (G_OBJECT (entry), "invisible-char-set");
6941 if (ch == entry->invisible_char)
6944 entry->invisible_char = ch;
6945 g_object_notify (G_OBJECT (entry), "invisible-char");
6946 gtk_entry_recompute (entry);
6950 * gtk_entry_get_invisible_char:
6951 * @entry: a #GtkEntry
6953 * Retrieves the character displayed in place of the real characters
6954 * for entries with visibility set to false. See gtk_entry_set_invisible_char().
6956 * Return value: the current invisible char, or 0, if the entry does not
6957 * show invisible text at all.
6960 gtk_entry_get_invisible_char (GtkEntry *entry)
6962 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
6964 return entry->invisible_char;
6968 * gtk_entry_unset_invisible_char:
6969 * @entry: a #GtkEntry
6971 * Unsets the invisible char previously set with
6972 * gtk_entry_set_invisible_char(). So that the
6973 * default invisible char is used again.
6978 gtk_entry_unset_invisible_char (GtkEntry *entry)
6980 GtkEntryPrivate *priv;
6983 g_return_if_fail (GTK_IS_ENTRY (entry));
6985 priv = GTK_ENTRY_GET_PRIVATE (entry);
6987 if (!priv->invisible_char_set)
6990 priv->invisible_char_set = FALSE;
6991 ch = find_invisible_char (GTK_WIDGET (entry));
6993 if (entry->invisible_char != ch)
6995 entry->invisible_char = ch;
6996 g_object_notify (G_OBJECT (entry), "invisible-char");
6999 g_object_notify (G_OBJECT (entry), "invisible-char-set");
7000 gtk_entry_recompute (entry);
7004 * gtk_entry_set_overwrite_mode:
7005 * @entry: a #GtkEntry
7006 * @overwrite: new value
7008 * Sets whether the text is overwritten when typing in the #GtkEntry.
7013 gtk_entry_set_overwrite_mode (GtkEntry *entry,
7016 g_return_if_fail (GTK_IS_ENTRY (entry));
7018 if (entry->overwrite_mode == overwrite)
7021 gtk_entry_toggle_overwrite (entry);
7023 g_object_notify (G_OBJECT (entry), "overwrite-mode");
7027 * gtk_entry_get_overwrite_mode:
7028 * @entry: a #GtkEntry
7030 * Gets the value set by gtk_entry_set_overwrite_mode().
7032 * Return value: whether the text is overwritten when typing.
7037 gtk_entry_get_overwrite_mode (GtkEntry *entry)
7039 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7041 return entry->overwrite_mode;
7045 * gtk_entry_get_text:
7046 * @entry: a #GtkEntry
7048 * Retrieves the contents of the entry widget.
7049 * See also gtk_editable_get_chars().
7051 * This is equivalent to:
7053 * <informalexample><programlisting>
7054 * gtk_entry_buffer_get_text (gtk_entry_get_buffer (entry));
7055 * </programlisting></informalexample>
7057 * Return value: a pointer to the contents of the widget as a
7058 * string. This string points to internally allocated
7059 * storage in the widget and must not be freed, modified or
7062 G_CONST_RETURN gchar*
7063 gtk_entry_get_text (GtkEntry *entry)
7065 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7066 return gtk_entry_buffer_get_text (get_buffer (entry));
7070 * gtk_entry_set_max_length:
7071 * @entry: a #GtkEntry
7072 * @max: the maximum length of the entry, or 0 for no maximum.
7073 * (other than the maximum length of entries.) The value passed in will
7074 * be clamped to the range 0-65536.
7076 * Sets the maximum allowed length of the contents of the widget. If
7077 * the current contents are longer than the given length, then they
7078 * will be truncated to fit.
7080 * This is equivalent to:
7082 * <informalexample><programlisting>
7083 * gtk_entry_buffer_set_max_length (gtk_entry_get_buffer (entry), max);
7084 * </programlisting></informalexample>
7087 gtk_entry_set_max_length (GtkEntry *entry,
7090 g_return_if_fail (GTK_IS_ENTRY (entry));
7091 gtk_entry_buffer_set_max_length (get_buffer (entry), max);
7095 * gtk_entry_get_max_length:
7096 * @entry: a #GtkEntry
7098 * Retrieves the maximum allowed length of the text in
7099 * @entry. See gtk_entry_set_max_length().
7101 * This is equivalent to:
7103 * <informalexample><programlisting>
7104 * gtk_entry_buffer_get_max_length (gtk_entry_get_buffer (entry));
7105 * </programlisting></informalexample>
7107 * Return value: the maximum allowed number of characters
7108 * in #GtkEntry, or 0 if there is no maximum.
7111 gtk_entry_get_max_length (GtkEntry *entry)
7113 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7114 return gtk_entry_buffer_get_max_length (get_buffer (entry));
7118 * gtk_entry_get_text_length:
7119 * @entry: a #GtkEntry
7121 * Retrieves the current length of the text in
7124 * This is equivalent to:
7126 * <informalexample><programlisting>
7127 * gtk_entry_buffer_get_length (gtk_entry_get_buffer (entry));
7128 * </programlisting></informalexample>
7130 * Return value: the current number of characters
7131 * in #GtkEntry, or 0 if there are none.
7136 gtk_entry_get_text_length (GtkEntry *entry)
7138 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7139 return gtk_entry_buffer_get_length (get_buffer (entry));
7143 * gtk_entry_set_activates_default:
7144 * @entry: a #GtkEntry
7145 * @setting: %TRUE to activate window's default widget on Enter keypress
7147 * If @setting is %TRUE, pressing Enter in the @entry will activate the default
7148 * widget for the window containing the entry. This usually means that
7149 * the dialog box containing the entry will be closed, since the default
7150 * widget is usually one of the dialog buttons.
7152 * (For experts: if @setting is %TRUE, the entry calls
7153 * gtk_window_activate_default() on the window containing the entry, in
7154 * the default handler for the #GtkWidget::activate signal.)
7157 gtk_entry_set_activates_default (GtkEntry *entry,
7160 g_return_if_fail (GTK_IS_ENTRY (entry));
7161 setting = setting != FALSE;
7163 if (setting != entry->activates_default)
7165 entry->activates_default = setting;
7166 g_object_notify (G_OBJECT (entry), "activates-default");
7171 * gtk_entry_get_activates_default:
7172 * @entry: a #GtkEntry
7174 * Retrieves the value set by gtk_entry_set_activates_default().
7176 * Return value: %TRUE if the entry will activate the default widget
7179 gtk_entry_get_activates_default (GtkEntry *entry)
7181 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7183 return entry->activates_default;
7187 * gtk_entry_set_width_chars:
7188 * @entry: a #GtkEntry
7189 * @n_chars: width in chars
7191 * Changes the size request of the entry to be about the right size
7192 * for @n_chars characters. Note that it changes the size
7193 * <emphasis>request</emphasis>, the size can still be affected by
7194 * how you pack the widget into containers. If @n_chars is -1, the
7195 * size reverts to the default entry size.
7198 gtk_entry_set_width_chars (GtkEntry *entry,
7201 g_return_if_fail (GTK_IS_ENTRY (entry));
7203 if (entry->width_chars != n_chars)
7205 entry->width_chars = n_chars;
7206 g_object_notify (G_OBJECT (entry), "width-chars");
7207 gtk_widget_queue_resize (GTK_WIDGET (entry));
7212 * gtk_entry_get_width_chars:
7213 * @entry: a #GtkEntry
7215 * Gets the value set by gtk_entry_set_width_chars().
7217 * Return value: number of chars to request space for, or negative if unset
7220 gtk_entry_get_width_chars (GtkEntry *entry)
7222 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7224 return entry->width_chars;
7228 * gtk_entry_set_has_frame:
7229 * @entry: a #GtkEntry
7230 * @setting: new value
7232 * Sets whether the entry has a beveled frame around it.
7235 gtk_entry_set_has_frame (GtkEntry *entry,
7238 g_return_if_fail (GTK_IS_ENTRY (entry));
7240 setting = (setting != FALSE);
7242 if (entry->has_frame == setting)
7245 gtk_widget_queue_resize (GTK_WIDGET (entry));
7246 entry->has_frame = setting;
7247 g_object_notify (G_OBJECT (entry), "has-frame");
7251 * gtk_entry_get_has_frame:
7252 * @entry: a #GtkEntry
7254 * Gets the value set by gtk_entry_set_has_frame().
7256 * Return value: whether the entry has a beveled frame
7259 gtk_entry_get_has_frame (GtkEntry *entry)
7261 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7263 return entry->has_frame;
7267 * gtk_entry_set_inner_border:
7268 * @entry: a #GtkEntry
7269 * @border: (allow-none): a #GtkBorder, or %NULL
7271 * Sets %entry's inner-border property to %border, or clears it if %NULL
7272 * is passed. The inner-border is the area around the entry's text, but
7275 * If set, this property overrides the inner-border style property.
7276 * Overriding the style-provided border is useful when you want to do
7277 * in-place editing of some text in a canvas or list widget, where
7278 * pixel-exact positioning of the entry is important.
7283 gtk_entry_set_inner_border (GtkEntry *entry,
7284 const GtkBorder *border)
7286 g_return_if_fail (GTK_IS_ENTRY (entry));
7288 gtk_widget_queue_resize (GTK_WIDGET (entry));
7291 g_object_set_qdata_full (G_OBJECT (entry), quark_inner_border,
7292 gtk_border_copy (border),
7293 (GDestroyNotify) gtk_border_free);
7295 g_object_set_qdata (G_OBJECT (entry), quark_inner_border, NULL);
7297 g_object_notify (G_OBJECT (entry), "inner-border");
7301 * gtk_entry_get_inner_border:
7302 * @entry: a #GtkEntry
7304 * This function returns the entry's #GtkEntry:inner-border property. See
7305 * gtk_entry_set_inner_border() for more information.
7307 * Return value: (transfer none): the entry's #GtkBorder, or %NULL if none was set.
7311 G_CONST_RETURN GtkBorder *
7312 gtk_entry_get_inner_border (GtkEntry *entry)
7314 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7316 return g_object_get_qdata (G_OBJECT (entry), quark_inner_border);
7320 * gtk_entry_get_layout:
7321 * @entry: a #GtkEntry
7323 * Gets the #PangoLayout used to display the entry.
7324 * The layout is useful to e.g. convert text positions to
7325 * pixel positions, in combination with gtk_entry_get_layout_offsets().
7326 * The returned layout is owned by the entry and must not be
7327 * modified or freed by the caller.
7329 * Keep in mind that the layout text may contain a preedit string, so
7330 * gtk_entry_layout_index_to_text_index() and
7331 * gtk_entry_text_index_to_layout_index() are needed to convert byte
7332 * indices in the layout to byte indices in the entry contents.
7334 * Return value: (transfer none): the #PangoLayout for this entry
7337 gtk_entry_get_layout (GtkEntry *entry)
7339 PangoLayout *layout;
7341 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7343 layout = gtk_entry_ensure_layout (entry, TRUE);
7350 * gtk_entry_layout_index_to_text_index:
7351 * @entry: a #GtkEntry
7352 * @layout_index: byte index into the entry layout text
7354 * Converts from a position in the entry contents (returned
7355 * by gtk_entry_get_text()) to a position in the
7356 * entry's #PangoLayout (returned by gtk_entry_get_layout(),
7357 * with text retrieved via pango_layout_get_text()).
7359 * Return value: byte index into the entry contents
7362 gtk_entry_layout_index_to_text_index (GtkEntry *entry,
7365 PangoLayout *layout;
7369 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7371 layout = gtk_entry_ensure_layout (entry, TRUE);
7372 text = pango_layout_get_text (layout);
7373 cursor_index = g_utf8_offset_to_pointer (text, entry->current_pos) - text;
7375 if (layout_index >= cursor_index && entry->preedit_length)
7377 if (layout_index >= cursor_index + entry->preedit_length)
7378 layout_index -= entry->preedit_length;
7380 layout_index = cursor_index;
7383 return layout_index;
7387 * gtk_entry_text_index_to_layout_index:
7388 * @entry: a #GtkEntry
7389 * @text_index: byte index into the entry contents
7391 * Converts from a position in the entry's #PangoLayout (returned by
7392 * gtk_entry_get_layout()) to a position in the entry contents
7393 * (returned by gtk_entry_get_text()).
7395 * Return value: byte index into the entry layout text
7398 gtk_entry_text_index_to_layout_index (GtkEntry *entry,
7401 PangoLayout *layout;
7404 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7406 layout = gtk_entry_ensure_layout (entry, TRUE);
7407 text = pango_layout_get_text (layout);
7408 cursor_index = g_utf8_offset_to_pointer (text, entry->current_pos) - text;
7410 if (text_index > cursor_index)
7411 text_index += entry->preedit_length;
7417 * gtk_entry_get_layout_offsets:
7418 * @entry: a #GtkEntry
7419 * @x: (allow-none): location to store X offset of layout, or %NULL
7420 * @y: (allow-none): location to store Y offset of layout, or %NULL
7423 * Obtains the position of the #PangoLayout used to render text
7424 * in the entry, in widget coordinates. Useful if you want to line
7425 * up the text in an entry with some other text, e.g. when using the
7426 * entry to implement editable cells in a sheet widget.
7428 * Also useful to convert mouse events into coordinates inside the
7429 * #PangoLayout, e.g. to take some action if some part of the entry text
7432 * Note that as the user scrolls around in the entry the offsets will
7433 * change; you'll need to connect to the "notify::scroll-offset"
7434 * signal to track this. Remember when using the #PangoLayout
7435 * functions you need to convert to and from pixels using
7436 * PANGO_PIXELS() or #PANGO_SCALE.
7438 * Keep in mind that the layout text may contain a preedit string, so
7439 * gtk_entry_layout_index_to_text_index() and
7440 * gtk_entry_text_index_to_layout_index() are needed to convert byte
7441 * indices in the layout to byte indices in the entry contents.
7444 gtk_entry_get_layout_offsets (GtkEntry *entry,
7448 gint text_area_x, text_area_y;
7450 g_return_if_fail (GTK_IS_ENTRY (entry));
7452 /* this gets coords relative to text area */
7453 get_layout_position (entry, x, y);
7455 /* convert to widget coords */
7456 gtk_entry_get_text_area_size (entry, &text_area_x, &text_area_y, NULL, NULL);
7467 * gtk_entry_set_alignment:
7468 * @entry: a #GtkEntry
7469 * @xalign: The horizontal alignment, from 0 (left) to 1 (right).
7470 * Reversed for RTL layouts
7472 * Sets the alignment for the contents of the entry. This controls
7473 * the horizontal positioning of the contents when the displayed
7474 * text is shorter than the width of the entry.
7479 gtk_entry_set_alignment (GtkEntry *entry, gfloat xalign)
7481 GtkEntryPrivate *priv;
7483 g_return_if_fail (GTK_IS_ENTRY (entry));
7485 priv = GTK_ENTRY_GET_PRIVATE (entry);
7489 else if (xalign > 1.0)
7492 if (xalign != priv->xalign)
7494 priv->xalign = xalign;
7496 gtk_entry_recompute (entry);
7498 g_object_notify (G_OBJECT (entry), "xalign");
7503 * gtk_entry_get_alignment:
7504 * @entry: a #GtkEntry
7506 * Gets the value set by gtk_entry_set_alignment().
7508 * Return value: the alignment
7513 gtk_entry_get_alignment (GtkEntry *entry)
7515 GtkEntryPrivate *priv;
7517 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
7519 priv = GTK_ENTRY_GET_PRIVATE (entry);
7521 return priv->xalign;
7525 * gtk_entry_set_icon_from_pixbuf:
7526 * @entry: a #GtkEntry
7527 * @icon_pos: Icon position
7528 * @pixbuf: (allow-none): A #GdkPixbuf, or %NULL
7530 * Sets the icon shown in the specified position using a pixbuf.
7532 * If @pixbuf is %NULL, no icon will be shown in the specified position.
7537 gtk_entry_set_icon_from_pixbuf (GtkEntry *entry,
7538 GtkEntryIconPosition icon_pos,
7541 GtkEntryPrivate *priv;
7542 EntryIconInfo *icon_info;
7544 g_return_if_fail (GTK_IS_ENTRY (entry));
7545 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7547 priv = GTK_ENTRY_GET_PRIVATE (entry);
7549 if ((icon_info = priv->icons[icon_pos]) == NULL)
7550 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7552 g_object_freeze_notify (G_OBJECT (entry));
7555 g_object_ref (pixbuf);
7557 gtk_entry_clear (entry, icon_pos);
7561 icon_info->storage_type = GTK_IMAGE_PIXBUF;
7562 icon_info->pixbuf = pixbuf;
7564 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7566 g_object_notify (G_OBJECT (entry), "primary-icon-pixbuf");
7567 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7571 g_object_notify (G_OBJECT (entry), "secondary-icon-pixbuf");
7572 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7575 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7576 gdk_window_show_unraised (icon_info->window);
7579 gtk_entry_ensure_pixbuf (entry, icon_pos);
7581 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7582 gtk_widget_queue_resize (GTK_WIDGET (entry));
7584 g_object_thaw_notify (G_OBJECT (entry));
7588 * gtk_entry_set_icon_from_stock:
7589 * @entry: A #GtkEntry
7590 * @icon_pos: Icon position
7591 * @stock_id: (allow-none): The name of the stock item, or %NULL
7593 * Sets the icon shown in the entry at the specified position from
7596 * If @stock_id is %NULL, no icon will be shown in the specified position.
7601 gtk_entry_set_icon_from_stock (GtkEntry *entry,
7602 GtkEntryIconPosition icon_pos,
7603 const gchar *stock_id)
7605 GtkEntryPrivate *priv;
7606 EntryIconInfo *icon_info;
7609 g_return_if_fail (GTK_IS_ENTRY (entry));
7610 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7612 priv = GTK_ENTRY_GET_PRIVATE (entry);
7614 if ((icon_info = priv->icons[icon_pos]) == NULL)
7615 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7617 g_object_freeze_notify (G_OBJECT (entry));
7619 gtk_widget_ensure_style (GTK_WIDGET (entry));
7621 /* need to dup before clearing */
7622 new_id = g_strdup (stock_id);
7624 gtk_entry_clear (entry, icon_pos);
7628 icon_info->storage_type = GTK_IMAGE_STOCK;
7629 icon_info->stock_id = new_id;
7631 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7633 g_object_notify (G_OBJECT (entry), "primary-icon-stock");
7634 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7638 g_object_notify (G_OBJECT (entry), "secondary-icon-stock");
7639 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7642 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7643 gdk_window_show_unraised (icon_info->window);
7646 gtk_entry_ensure_pixbuf (entry, icon_pos);
7648 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7649 gtk_widget_queue_resize (GTK_WIDGET (entry));
7651 g_object_thaw_notify (G_OBJECT (entry));
7655 * gtk_entry_set_icon_from_icon_name:
7656 * @entry: A #GtkEntry
7657 * @icon_pos: The position at which to set the icon
7658 * @icon_name: (allow-none): An icon name, or %NULL
7660 * Sets the icon shown in the entry at the specified position
7661 * from the current icon theme.
7663 * If the icon name isn't known, a "broken image" icon will be displayed
7666 * If @icon_name is %NULL, no icon will be shown in the specified position.
7671 gtk_entry_set_icon_from_icon_name (GtkEntry *entry,
7672 GtkEntryIconPosition icon_pos,
7673 const gchar *icon_name)
7675 GtkEntryPrivate *priv;
7676 EntryIconInfo *icon_info;
7679 g_return_if_fail (GTK_IS_ENTRY (entry));
7680 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7682 priv = GTK_ENTRY_GET_PRIVATE (entry);
7684 if ((icon_info = priv->icons[icon_pos]) == NULL)
7685 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7687 g_object_freeze_notify (G_OBJECT (entry));
7689 gtk_widget_ensure_style (GTK_WIDGET (entry));
7691 /* need to dup before clearing */
7692 new_name = g_strdup (icon_name);
7694 gtk_entry_clear (entry, icon_pos);
7696 if (new_name != NULL)
7698 icon_info->storage_type = GTK_IMAGE_ICON_NAME;
7699 icon_info->icon_name = new_name;
7701 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7703 g_object_notify (G_OBJECT (entry), "primary-icon-name");
7704 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7708 g_object_notify (G_OBJECT (entry), "secondary-icon-name");
7709 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7712 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7713 gdk_window_show_unraised (icon_info->window);
7716 gtk_entry_ensure_pixbuf (entry, icon_pos);
7718 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7719 gtk_widget_queue_resize (GTK_WIDGET (entry));
7721 g_object_thaw_notify (G_OBJECT (entry));
7725 * gtk_entry_set_icon_from_gicon:
7726 * @entry: A #GtkEntry
7727 * @icon_pos: The position at which to set the icon
7728 * @icon: (allow-none): The icon to set, or %NULL
7730 * Sets the icon shown in the entry at the specified position
7731 * from the current icon theme.
7732 * If the icon isn't known, a "broken image" icon will be displayed
7735 * If @icon is %NULL, no icon will be shown in the specified position.
7740 gtk_entry_set_icon_from_gicon (GtkEntry *entry,
7741 GtkEntryIconPosition icon_pos,
7744 GtkEntryPrivate *priv;
7745 EntryIconInfo *icon_info;
7747 g_return_if_fail (GTK_IS_ENTRY (entry));
7748 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7750 priv = GTK_ENTRY_GET_PRIVATE (entry);
7752 if ((icon_info = priv->icons[icon_pos]) == NULL)
7753 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7755 g_object_freeze_notify (G_OBJECT (entry));
7757 /* need to ref before clearing */
7759 g_object_ref (icon);
7761 gtk_entry_clear (entry, icon_pos);
7765 icon_info->storage_type = GTK_IMAGE_GICON;
7766 icon_info->gicon = icon;
7768 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7770 g_object_notify (G_OBJECT (entry), "primary-icon-gicon");
7771 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7775 g_object_notify (G_OBJECT (entry), "secondary-icon-gicon");
7776 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7779 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7780 gdk_window_show_unraised (icon_info->window);
7783 gtk_entry_ensure_pixbuf (entry, icon_pos);
7785 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7786 gtk_widget_queue_resize (GTK_WIDGET (entry));
7788 g_object_thaw_notify (G_OBJECT (entry));
7792 * gtk_entry_set_icon_activatable:
7793 * @entry: A #GtkEntry
7794 * @icon_pos: Icon position
7795 * @activatable: %TRUE if the icon should be activatable
7797 * Sets whether the icon is activatable.
7802 gtk_entry_set_icon_activatable (GtkEntry *entry,
7803 GtkEntryIconPosition icon_pos,
7804 gboolean activatable)
7806 GtkEntryPrivate *priv;
7807 EntryIconInfo *icon_info;
7809 g_return_if_fail (GTK_IS_ENTRY (entry));
7810 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7812 priv = GTK_ENTRY_GET_PRIVATE (entry);
7814 if ((icon_info = priv->icons[icon_pos]) == NULL)
7815 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7817 activatable = activatable != FALSE;
7819 if (icon_info->nonactivatable != !activatable)
7821 icon_info->nonactivatable = !activatable;
7823 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
7824 update_cursors (GTK_WIDGET (entry));
7826 g_object_notify (G_OBJECT (entry),
7827 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-activatable" : "secondary-icon-activatable");
7832 * gtk_entry_get_icon_activatable:
7833 * @entry: a #GtkEntry
7834 * @icon_pos: Icon position
7836 * Returns whether the icon is activatable.
7838 * Returns: %TRUE if the icon is activatable.
7843 gtk_entry_get_icon_activatable (GtkEntry *entry,
7844 GtkEntryIconPosition icon_pos)
7846 GtkEntryPrivate *priv;
7847 EntryIconInfo *icon_info;
7849 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7850 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), FALSE);
7852 priv = GTK_ENTRY_GET_PRIVATE (entry);
7853 icon_info = priv->icons[icon_pos];
7855 return (icon_info != NULL && !icon_info->nonactivatable);
7859 * gtk_entry_get_icon_pixbuf:
7860 * @entry: A #GtkEntry
7861 * @icon_pos: Icon position
7863 * Retrieves the image used for the icon.
7865 * Unlike the other methods of setting and getting icon data, this
7866 * method will work regardless of whether the icon was set using a
7867 * #GdkPixbuf, a #GIcon, a stock item, or an icon name.
7869 * Returns: A #GdkPixbuf, or %NULL if no icon is set for this position.
7874 gtk_entry_get_icon_pixbuf (GtkEntry *entry,
7875 GtkEntryIconPosition icon_pos)
7877 GtkEntryPrivate *priv;
7878 EntryIconInfo *icon_info;
7880 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7881 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7883 priv = GTK_ENTRY_GET_PRIVATE (entry);
7884 icon_info = priv->icons[icon_pos];
7889 gtk_entry_ensure_pixbuf (entry, icon_pos);
7891 return icon_info->pixbuf;
7895 * gtk_entry_get_icon_gicon:
7896 * @entry: A #GtkEntry
7897 * @icon_pos: Icon position
7899 * Retrieves the #GIcon used for the icon, or %NULL if there is
7900 * no icon or if the icon was set by some other method (e.g., by
7901 * stock, pixbuf, or icon name).
7903 * Returns: A #GIcon, or %NULL if no icon is set or if the icon
7909 gtk_entry_get_icon_gicon (GtkEntry *entry,
7910 GtkEntryIconPosition icon_pos)
7912 GtkEntryPrivate *priv;
7913 EntryIconInfo *icon_info;
7915 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7916 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7918 priv = GTK_ENTRY_GET_PRIVATE (entry);
7919 icon_info = priv->icons[icon_pos];
7924 return icon_info->storage_type == GTK_IMAGE_GICON ? icon_info->gicon : NULL;
7928 * gtk_entry_get_icon_stock:
7929 * @entry: A #GtkEntry
7930 * @icon_pos: Icon position
7932 * Retrieves the stock id used for the icon, or %NULL if there is
7933 * no icon or if the icon was set by some other method (e.g., by
7934 * pixbuf, icon name or gicon).
7936 * Returns: A stock id, or %NULL if no icon is set or if the icon
7937 * wasn't set from a stock id
7942 gtk_entry_get_icon_stock (GtkEntry *entry,
7943 GtkEntryIconPosition icon_pos)
7945 GtkEntryPrivate *priv;
7946 EntryIconInfo *icon_info;
7948 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7949 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7951 priv = GTK_ENTRY_GET_PRIVATE (entry);
7952 icon_info = priv->icons[icon_pos];
7957 return icon_info->storage_type == GTK_IMAGE_STOCK ? icon_info->stock_id : NULL;
7961 * gtk_entry_get_icon_name:
7962 * @entry: A #GtkEntry
7963 * @icon_pos: Icon position
7965 * Retrieves the icon name used for the icon, or %NULL if there is
7966 * no icon or if the icon was set by some other method (e.g., by
7967 * pixbuf, stock or gicon).
7969 * Returns: An icon name, or %NULL if no icon is set or if the icon
7970 * wasn't set from an icon name
7975 gtk_entry_get_icon_name (GtkEntry *entry,
7976 GtkEntryIconPosition icon_pos)
7978 GtkEntryPrivate *priv;
7979 EntryIconInfo *icon_info;
7981 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7982 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7984 priv = GTK_ENTRY_GET_PRIVATE (entry);
7985 icon_info = priv->icons[icon_pos];
7990 return icon_info->storage_type == GTK_IMAGE_ICON_NAME ? icon_info->icon_name : NULL;
7994 * gtk_entry_set_icon_sensitive:
7995 * @entry: A #GtkEntry
7996 * @icon_pos: Icon position
7997 * @sensitive: Specifies whether the icon should appear
7998 * sensitive or insensitive
8000 * Sets the sensitivity for the specified icon.
8005 gtk_entry_set_icon_sensitive (GtkEntry *entry,
8006 GtkEntryIconPosition icon_pos,
8009 GtkEntryPrivate *priv;
8010 EntryIconInfo *icon_info;
8012 g_return_if_fail (GTK_IS_ENTRY (entry));
8013 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8015 priv = GTK_ENTRY_GET_PRIVATE (entry);
8017 if ((icon_info = priv->icons[icon_pos]) == NULL)
8018 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8020 if (icon_info->insensitive != !sensitive)
8022 icon_info->insensitive = !sensitive;
8024 icon_info->pressed = FALSE;
8025 icon_info->prelight = FALSE;
8027 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
8028 update_cursors (GTK_WIDGET (entry));
8030 gtk_widget_queue_draw (GTK_WIDGET (entry));
8032 g_object_notify (G_OBJECT (entry),
8033 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-sensitive" : "secondary-icon-sensitive");
8038 * gtk_entry_get_icon_sensitive:
8039 * @entry: a #GtkEntry
8040 * @icon_pos: Icon position
8042 * Returns whether the icon appears sensitive or insensitive.
8044 * Returns: %TRUE if the icon is sensitive.
8049 gtk_entry_get_icon_sensitive (GtkEntry *entry,
8050 GtkEntryIconPosition icon_pos)
8052 GtkEntryPrivate *priv;
8053 EntryIconInfo *icon_info;
8055 g_return_val_if_fail (GTK_IS_ENTRY (entry), TRUE);
8056 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), TRUE);
8058 priv = GTK_ENTRY_GET_PRIVATE (entry);
8059 icon_info = priv->icons[icon_pos];
8061 return (!icon_info || !icon_info->insensitive);
8066 * gtk_entry_get_icon_storage_type:
8067 * @entry: a #GtkEntry
8068 * @icon_pos: Icon position
8070 * Gets the type of representation being used by the icon
8071 * to store image data. If the icon has no image data,
8072 * the return value will be %GTK_IMAGE_EMPTY.
8074 * Return value: image representation being used
8079 gtk_entry_get_icon_storage_type (GtkEntry *entry,
8080 GtkEntryIconPosition icon_pos)
8082 GtkEntryPrivate *priv;
8083 EntryIconInfo *icon_info;
8085 g_return_val_if_fail (GTK_IS_ENTRY (entry), GTK_IMAGE_EMPTY);
8086 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), GTK_IMAGE_EMPTY);
8088 priv = GTK_ENTRY_GET_PRIVATE (entry);
8089 icon_info = priv->icons[icon_pos];
8092 return GTK_IMAGE_EMPTY;
8094 return icon_info->storage_type;
8098 * gtk_entry_get_icon_at_pos:
8099 * @entry: a #GtkEntry
8100 * @x: the x coordinate of the position to find
8101 * @y: the y coordinate of the position to find
8103 * Finds the icon at the given position and return its index.
8104 * If @x, @y doesn't lie inside an icon, -1 is returned.
8105 * This function is intended for use in a #GtkWidget::query-tooltip
8108 * Returns: the index of the icon at the given position, or -1
8113 gtk_entry_get_icon_at_pos (GtkEntry *entry,
8117 GtkAllocation primary;
8118 GtkAllocation secondary;
8120 g_return_val_if_fail (GTK_IS_ENTRY (entry), -1);
8122 get_icon_allocations (entry, &primary, &secondary);
8124 if (primary.x <= x && x < primary.x + primary.width &&
8125 primary.y <= y && y < primary.y + primary.height)
8126 return GTK_ENTRY_ICON_PRIMARY;
8128 if (secondary.x <= x && x < secondary.x + secondary.width &&
8129 secondary.y <= y && y < secondary.y + secondary.height)
8130 return GTK_ENTRY_ICON_SECONDARY;
8136 * gtk_entry_set_icon_drag_source:
8137 * @entry: a #GtkIconEntry
8138 * @icon_pos: icon position
8139 * @target_list: the targets (data formats) in which the data can be provided
8140 * @actions: a bitmask of the allowed drag actions
8142 * Sets up the icon at the given position so that GTK+ will start a drag
8143 * operation when the user clicks and drags the icon.
8145 * To handle the drag operation, you need to connect to the usual
8146 * #GtkWidget::drag-data-get (or possibly #GtkWidget::drag-data-delete)
8147 * signal, and use gtk_entry_get_current_icon_drag_source() in
8148 * your signal handler to find out if the drag was started from
8151 * By default, GTK+ uses the icon as the drag icon. You can use the
8152 * #GtkWidget::drag-begin signal to set a different icon. Note that you
8153 * have to use g_signal_connect_after() to ensure that your signal handler
8154 * gets executed after the default handler.
8159 gtk_entry_set_icon_drag_source (GtkEntry *entry,
8160 GtkEntryIconPosition icon_pos,
8161 GtkTargetList *target_list,
8162 GdkDragAction actions)
8164 GtkEntryPrivate *priv;
8165 EntryIconInfo *icon_info;
8167 g_return_if_fail (GTK_IS_ENTRY (entry));
8168 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8170 priv = GTK_ENTRY_GET_PRIVATE (entry);
8172 if ((icon_info = priv->icons[icon_pos]) == NULL)
8173 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8175 if (icon_info->target_list)
8176 gtk_target_list_unref (icon_info->target_list);
8177 icon_info->target_list = target_list;
8178 if (icon_info->target_list)
8179 gtk_target_list_ref (icon_info->target_list);
8181 icon_info->actions = actions;
8185 * gtk_entry_get_current_icon_drag_source:
8186 * @entry: a #GtkIconEntry
8188 * Returns the index of the icon which is the source of the current
8189 * DND operation, or -1.
8191 * This function is meant to be used in a #GtkWidget::drag-data-get
8194 * Returns: index of the icon which is the source of the current
8195 * DND operation, or -1.
8200 gtk_entry_get_current_icon_drag_source (GtkEntry *entry)
8202 GtkEntryPrivate *priv;
8203 EntryIconInfo *icon_info = NULL;
8206 g_return_val_if_fail (GTK_IS_ENTRY (entry), -1);
8208 priv = GTK_ENTRY_GET_PRIVATE (entry);
8210 for (i = 0; i < MAX_ICONS; i++)
8212 if ((icon_info = priv->icons[i]))
8214 if (icon_info->in_drag)
8223 * gtk_entry_get_icon_window:
8224 * @entry: A #GtkEntry
8225 * @icon_pos: Icon position
8227 * Returns the #GdkWindow which contains the entry's icon at
8228 * @icon_pos. This function is useful when drawing something to the
8229 * entry in an expose-event callback because it enables the callback
8230 * to distinguish between the text window and entry's icon windows.
8232 * See also gtk_entry_get_text_window().
8234 * Return value: the entry's icon window at @icon_pos.
8239 gtk_entry_get_icon_window (GtkEntry *entry,
8240 GtkEntryIconPosition icon_pos)
8242 GtkEntryPrivate *priv;
8243 EntryIconInfo *icon_info;
8245 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8247 priv = GTK_ENTRY_GET_PRIVATE (entry);
8249 icon_info = priv->icons[icon_pos];
8252 return icon_info->window;
8258 ensure_has_tooltip (GtkEntry *entry)
8260 GtkEntryPrivate *priv;
8261 EntryIconInfo *icon_info;
8263 gboolean has_tooltip = FALSE;
8265 priv = GTK_ENTRY_GET_PRIVATE (entry);
8267 for (i = 0; i < MAX_ICONS; i++)
8269 if ((icon_info = priv->icons[i]) != NULL)
8271 if (icon_info->tooltip != NULL)
8279 gtk_widget_set_has_tooltip (GTK_WIDGET (entry), has_tooltip);
8283 * gtk_entry_get_icon_tooltip_text:
8284 * @entry: a #GtkEntry
8285 * @icon_pos: the icon position
8287 * Gets the contents of the tooltip on the icon at the specified
8288 * position in @entry.
8290 * Returns: the tooltip text, or %NULL. Free the returned string
8291 * with g_free() when done.
8296 gtk_entry_get_icon_tooltip_text (GtkEntry *entry,
8297 GtkEntryIconPosition icon_pos)
8299 GtkEntryPrivate *priv;
8300 EntryIconInfo *icon_info;
8303 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8304 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8306 priv = GTK_ENTRY_GET_PRIVATE (entry);
8307 icon_info = priv->icons[icon_pos];
8312 if (icon_info->tooltip &&
8313 !pango_parse_markup (icon_info->tooltip, -1, 0, NULL, &text, NULL, NULL))
8314 g_assert (NULL == text); /* text should still be NULL in case of markup errors */
8320 * gtk_entry_set_icon_tooltip_text:
8321 * @entry: a #GtkEntry
8322 * @icon_pos: the icon position
8323 * @tooltip: (allow-none): the contents of the tooltip for the icon, or %NULL
8325 * Sets @tooltip as the contents of the tooltip for the icon
8326 * at the specified position.
8328 * Use %NULL for @tooltip to remove an existing tooltip.
8330 * See also gtk_widget_set_tooltip_text() and
8331 * gtk_entry_set_icon_tooltip_markup().
8336 gtk_entry_set_icon_tooltip_text (GtkEntry *entry,
8337 GtkEntryIconPosition icon_pos,
8338 const gchar *tooltip)
8340 GtkEntryPrivate *priv;
8341 EntryIconInfo *icon_info;
8343 g_return_if_fail (GTK_IS_ENTRY (entry));
8344 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8346 priv = GTK_ENTRY_GET_PRIVATE (entry);
8348 if (!(icon_info = priv->icons[icon_pos]))
8349 icon_info = priv->icons[icon_pos];
8351 if (icon_info->tooltip)
8352 g_free (icon_info->tooltip);
8354 /* Treat an empty string as a NULL string,
8355 * because an empty string would be useless for a tooltip:
8357 if (tooltip && tooltip[0] == '\0')
8360 icon_info->tooltip = tooltip ? g_markup_escape_text (tooltip, -1) : NULL;
8362 ensure_has_tooltip (entry);
8366 * gtk_entry_get_icon_tooltip_markup:
8367 * @entry: a #GtkEntry
8368 * @icon_pos: the icon position
8370 * Gets the contents of the tooltip on the icon at the specified
8371 * position in @entry.
8373 * Returns: the tooltip text, or %NULL. Free the returned string
8374 * with g_free() when done.
8379 gtk_entry_get_icon_tooltip_markup (GtkEntry *entry,
8380 GtkEntryIconPosition icon_pos)
8382 GtkEntryPrivate *priv;
8383 EntryIconInfo *icon_info;
8385 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8386 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8388 priv = GTK_ENTRY_GET_PRIVATE (entry);
8389 icon_info = priv->icons[icon_pos];
8394 return g_strdup (icon_info->tooltip);
8398 * gtk_entry_set_icon_tooltip_markup:
8399 * @entry: a #GtkEntry
8400 * @icon_pos: the icon position
8401 * @tooltip: (allow-none): the contents of the tooltip for the icon, or %NULL
8403 * Sets @tooltip as the contents of the tooltip for the icon at
8404 * the specified position. @tooltip is assumed to be marked up with
8405 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
8407 * Use %NULL for @tooltip to remove an existing tooltip.
8409 * See also gtk_widget_set_tooltip_markup() and
8410 * gtk_enty_set_icon_tooltip_text().
8415 gtk_entry_set_icon_tooltip_markup (GtkEntry *entry,
8416 GtkEntryIconPosition icon_pos,
8417 const gchar *tooltip)
8419 GtkEntryPrivate *priv;
8420 EntryIconInfo *icon_info;
8422 g_return_if_fail (GTK_IS_ENTRY (entry));
8423 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8425 priv = GTK_ENTRY_GET_PRIVATE (entry);
8427 if (!(icon_info = priv->icons[icon_pos]))
8428 icon_info = priv->icons[icon_pos];
8430 if (icon_info->tooltip)
8431 g_free (icon_info->tooltip);
8433 /* Treat an empty string as a NULL string,
8434 * because an empty string would be useless for a tooltip:
8436 if (tooltip && tooltip[0] == '\0')
8439 icon_info->tooltip = g_strdup (tooltip);
8441 ensure_has_tooltip (entry);
8445 gtk_entry_query_tooltip (GtkWidget *widget,
8448 gboolean keyboard_tip,
8449 GtkTooltip *tooltip)
8452 GtkEntryPrivate *priv;
8453 EntryIconInfo *icon_info;
8456 entry = GTK_ENTRY (widget);
8457 priv = GTK_ENTRY_GET_PRIVATE (entry);
8461 icon_pos = gtk_entry_get_icon_at_pos (entry, x, y);
8464 if ((icon_info = priv->icons[icon_pos]) != NULL)
8466 if (icon_info->tooltip)
8468 gtk_tooltip_set_markup (tooltip, icon_info->tooltip);
8477 return GTK_WIDGET_CLASS (gtk_entry_parent_class)->query_tooltip (widget,
8484 /* Quick hack of a popup menu
8487 activate_cb (GtkWidget *menuitem,
8490 const gchar *signal = g_object_get_data (G_OBJECT (menuitem), "gtk-signal");
8491 g_signal_emit_by_name (entry, signal);
8496 gtk_entry_mnemonic_activate (GtkWidget *widget,
8497 gboolean group_cycling)
8499 gtk_widget_grab_focus (widget);
8504 append_action_signal (GtkEntry *entry,
8506 const gchar *stock_id,
8507 const gchar *signal,
8510 GtkWidget *menuitem = gtk_image_menu_item_new_from_stock (stock_id, NULL);
8512 g_object_set_data (G_OBJECT (menuitem), I_("gtk-signal"), (char *)signal);
8513 g_signal_connect (menuitem, "activate",
8514 G_CALLBACK (activate_cb), entry);
8516 gtk_widget_set_sensitive (menuitem, sensitive);
8518 gtk_widget_show (menuitem);
8519 gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
8523 popup_menu_detach (GtkWidget *attach_widget,
8526 GTK_ENTRY (attach_widget)->popup_menu = NULL;
8530 popup_position_func (GtkMenu *menu,
8536 GtkEntry *entry = GTK_ENTRY (user_data);
8537 GtkWidget *widget = GTK_WIDGET (entry);
8539 GtkRequisition menu_req;
8540 GdkRectangle monitor;
8541 GtkBorder inner_border;
8542 gint monitor_num, strong_x, height;
8544 g_return_if_fail (gtk_widget_get_realized (widget));
8546 gdk_window_get_origin (entry->text_area, x, y);
8548 screen = gtk_widget_get_screen (widget);
8549 monitor_num = gdk_screen_get_monitor_at_window (screen, entry->text_area);
8550 if (monitor_num < 0)
8552 gtk_menu_set_monitor (menu, monitor_num);
8554 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
8555 gtk_widget_size_request (entry->popup_menu, &menu_req);
8556 gdk_drawable_get_size (entry->text_area, NULL, &height);
8557 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
8558 _gtk_entry_effective_inner_border (entry, &inner_border);
8560 *x += inner_border.left + strong_x - entry->scroll_offset;
8561 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
8562 *x -= menu_req.width;
8564 if ((*y + height + menu_req.height) <= monitor.y + monitor.height)
8566 else if ((*y - menu_req.height) >= monitor.y)
8567 *y -= menu_req.height;
8568 else if (monitor.y + monitor.height - (*y + height) > *y)
8571 *y -= menu_req.height;
8577 unichar_chosen_func (const char *text,
8580 GtkEntry *entry = GTK_ENTRY (data);
8582 if (entry->editable)
8583 gtk_entry_enter_text (entry, text);
8594 popup_targets_received (GtkClipboard *clipboard,
8595 GtkSelectionData *data,
8598 PopupInfo *info = user_data;
8599 GtkEntry *entry = info->entry;
8601 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
8604 gboolean clipboard_contains_text;
8605 GtkWidget *menuitem;
8607 gboolean show_input_method_menu;
8608 gboolean show_unicode_menu;
8610 clipboard_contains_text = gtk_selection_data_targets_include_text (data);
8611 if (entry->popup_menu)
8612 gtk_widget_destroy (entry->popup_menu);
8614 entry->popup_menu = gtk_menu_new ();
8616 gtk_menu_attach_to_widget (GTK_MENU (entry->popup_menu),
8620 mode = gtk_entry_get_display_mode (entry);
8621 append_action_signal (entry, entry->popup_menu, GTK_STOCK_CUT, "cut-clipboard",
8622 entry->editable && mode == DISPLAY_NORMAL &&
8623 entry->current_pos != entry->selection_bound);
8625 append_action_signal (entry, entry->popup_menu, GTK_STOCK_COPY, "copy-clipboard",
8626 mode == DISPLAY_NORMAL &&
8627 entry->current_pos != entry->selection_bound);
8629 append_action_signal (entry, entry->popup_menu, GTK_STOCK_PASTE, "paste-clipboard",
8630 entry->editable && clipboard_contains_text);
8632 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_DELETE, NULL);
8633 gtk_widget_set_sensitive (menuitem, entry->editable && entry->current_pos != entry->selection_bound);
8634 g_signal_connect_swapped (menuitem, "activate",
8635 G_CALLBACK (gtk_entry_delete_cb), entry);
8636 gtk_widget_show (menuitem);
8637 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8639 menuitem = gtk_separator_menu_item_new ();
8640 gtk_widget_show (menuitem);
8641 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8643 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_SELECT_ALL, NULL);
8644 g_signal_connect_swapped (menuitem, "activate",
8645 G_CALLBACK (gtk_entry_select_all), entry);
8646 gtk_widget_show (menuitem);
8647 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8649 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
8650 "gtk-show-input-method-menu", &show_input_method_menu,
8651 "gtk-show-unicode-menu", &show_unicode_menu,
8654 if (show_input_method_menu || show_unicode_menu)
8656 menuitem = gtk_separator_menu_item_new ();
8657 gtk_widget_show (menuitem);
8658 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8661 if (show_input_method_menu)
8663 menuitem = gtk_menu_item_new_with_mnemonic (_("Input _Methods"));
8664 gtk_widget_set_sensitive (menuitem, entry->editable);
8665 gtk_widget_show (menuitem);
8666 submenu = gtk_menu_new ();
8667 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
8669 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8671 gtk_im_multicontext_append_menuitems (GTK_IM_MULTICONTEXT (entry->im_context),
8672 GTK_MENU_SHELL (submenu));
8675 if (show_unicode_menu)
8677 menuitem = gtk_menu_item_new_with_mnemonic (_("_Insert Unicode Control Character"));
8678 gtk_widget_set_sensitive (menuitem, entry->editable);
8679 gtk_widget_show (menuitem);
8681 submenu = gtk_menu_new ();
8682 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
8683 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8685 _gtk_text_util_append_special_char_menuitems (GTK_MENU_SHELL (submenu),
8686 unichar_chosen_func,
8690 g_signal_emit (entry,
8691 signals[POPULATE_POPUP],
8697 gtk_menu_popup (GTK_MENU (entry->popup_menu), NULL, NULL,
8699 info->button, info->time);
8702 gtk_menu_popup (GTK_MENU (entry->popup_menu), NULL, NULL,
8703 popup_position_func, entry,
8704 info->button, info->time);
8705 gtk_menu_shell_select_first (GTK_MENU_SHELL (entry->popup_menu), FALSE);
8709 g_object_unref (entry);
8710 g_slice_free (PopupInfo, info);
8714 gtk_entry_do_popup (GtkEntry *entry,
8715 GdkEventButton *event)
8717 PopupInfo *info = g_slice_new (PopupInfo);
8719 /* In order to know what entries we should make sensitive, we
8720 * ask for the current targets of the clipboard, and when
8721 * we get them, then we actually pop up the menu.
8723 info->entry = g_object_ref (entry);
8727 info->button = event->button;
8728 info->time = event->time;
8733 info->time = gtk_get_current_event_time ();
8736 gtk_clipboard_request_contents (gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_CLIPBOARD),
8737 gdk_atom_intern_static_string ("TARGETS"),
8738 popup_targets_received,
8743 gtk_entry_popup_menu (GtkWidget *widget)
8745 gtk_entry_do_popup (GTK_ENTRY (widget), NULL);
8750 gtk_entry_drag_begin (GtkWidget *widget,
8751 GdkDragContext *context)
8753 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
8756 for (i = 0; i < MAX_ICONS; i++)
8758 EntryIconInfo *icon_info = priv->icons[i];
8760 if (icon_info != NULL)
8762 if (icon_info->in_drag)
8764 switch (icon_info->storage_type)
8766 case GTK_IMAGE_STOCK:
8767 gtk_drag_set_icon_stock (context, icon_info->stock_id, -2, -2);
8770 case GTK_IMAGE_ICON_NAME:
8771 gtk_drag_set_icon_name (context, icon_info->icon_name, -2, -2);
8774 /* FIXME: No GIcon support for dnd icons */
8775 case GTK_IMAGE_GICON:
8776 case GTK_IMAGE_PIXBUF:
8777 gtk_drag_set_icon_pixbuf (context, icon_info->pixbuf, -2, -2);
8780 g_assert_not_reached ();
8788 gtk_entry_drag_end (GtkWidget *widget,
8789 GdkDragContext *context)
8791 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
8794 for (i = 0; i < MAX_ICONS; i++)
8796 EntryIconInfo *icon_info = priv->icons[i];
8798 if (icon_info != NULL)
8799 icon_info->in_drag = 0;
8804 gtk_entry_drag_leave (GtkWidget *widget,
8805 GdkDragContext *context,
8808 GtkEntry *entry = GTK_ENTRY (widget);
8810 entry->dnd_position = -1;
8811 gtk_widget_queue_draw (widget);
8815 gtk_entry_drag_drop (GtkWidget *widget,
8816 GdkDragContext *context,
8821 GtkEntry *entry = GTK_ENTRY (widget);
8822 GdkAtom target = GDK_NONE;
8824 if (entry->editable)
8825 target = gtk_drag_dest_find_target (widget, context, NULL);
8827 if (target != GDK_NONE)
8828 gtk_drag_get_data (widget, context, target, time);
8830 gtk_drag_finish (context, FALSE, FALSE, time);
8836 gtk_entry_drag_motion (GtkWidget *widget,
8837 GdkDragContext *context,
8842 GtkEntry *entry = GTK_ENTRY (widget);
8844 GtkWidget *source_widget;
8845 GdkDragAction suggested_action;
8846 gint new_position, old_position;
8849 style = gtk_widget_get_style (widget);
8850 x -= style->xthickness;
8851 y -= style->ythickness;
8853 old_position = entry->dnd_position;
8854 new_position = gtk_entry_find_position (entry, x + entry->scroll_offset);
8856 if (entry->editable &&
8857 gtk_drag_dest_find_target (widget, context, NULL) != GDK_NONE)
8859 source_widget = gtk_drag_get_source_widget (context);
8860 suggested_action = context->suggested_action;
8862 if (!gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &sel1, &sel2) ||
8863 new_position < sel1 || new_position > sel2)
8865 if (source_widget == widget)
8867 /* Default to MOVE, unless the user has
8868 * pressed ctrl or alt to affect available actions
8870 if ((context->actions & GDK_ACTION_MOVE) != 0)
8871 suggested_action = GDK_ACTION_MOVE;
8874 entry->dnd_position = new_position;
8878 if (source_widget == widget)
8879 suggested_action = 0; /* Can't drop in selection where drag started */
8881 entry->dnd_position = -1;
8886 /* Entry not editable, or no text */
8887 suggested_action = 0;
8888 entry->dnd_position = -1;
8891 gdk_drag_status (context, suggested_action, time);
8893 if (entry->dnd_position != old_position)
8894 gtk_widget_queue_draw (widget);
8900 gtk_entry_drag_data_received (GtkWidget *widget,
8901 GdkDragContext *context,
8904 GtkSelectionData *selection_data,
8908 GtkEntry *entry = GTK_ENTRY (widget);
8909 GtkEditable *editable = GTK_EDITABLE (widget);
8913 str = (gchar *) gtk_selection_data_get_text (selection_data);
8915 style = gtk_widget_get_style (widget);
8916 x -= style->xthickness;
8917 y -= style->ythickness;
8919 if (str && entry->editable)
8925 if (entry->truncate_multiline)
8926 length = truncate_multiline (str);
8928 new_position = gtk_entry_find_position (entry, x + entry->scroll_offset);
8930 if (!gtk_editable_get_selection_bounds (editable, &sel1, &sel2) ||
8931 new_position < sel1 || new_position > sel2)
8933 gtk_editable_insert_text (editable, str, length, &new_position);
8937 /* Replacing selection */
8938 begin_change (entry);
8939 g_object_freeze_notify (G_OBJECT (entry));
8940 gtk_editable_delete_text (editable, sel1, sel2);
8941 gtk_editable_insert_text (editable, str, length, &sel1);
8942 g_object_thaw_notify (G_OBJECT (entry));
8946 gtk_drag_finish (context, TRUE, context->action == GDK_ACTION_MOVE, time);
8950 /* Drag and drop didn't happen! */
8951 gtk_drag_finish (context, FALSE, FALSE, time);
8958 gtk_entry_drag_data_get (GtkWidget *widget,
8959 GdkDragContext *context,
8960 GtkSelectionData *selection_data,
8964 gint sel_start, sel_end;
8967 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
8968 GtkEditable *editable = GTK_EDITABLE (widget);
8970 /* If there is an icon drag going on, exit early. */
8971 for (i = 0; i < MAX_ICONS; i++)
8973 EntryIconInfo *icon_info = priv->icons[i];
8975 if (icon_info != NULL)
8977 if (icon_info->in_drag)
8982 if (gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end))
8984 gchar *str = gtk_entry_get_display_text (GTK_ENTRY (widget), sel_start, sel_end);
8986 gtk_selection_data_set_text (selection_data, str, -1);
8994 gtk_entry_drag_data_delete (GtkWidget *widget,
8995 GdkDragContext *context)
8997 gint sel_start, sel_end;
9000 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
9001 GtkEditable *editable = GTK_EDITABLE (widget);
9003 /* If there is an icon drag going on, exit early. */
9004 for (i = 0; i < MAX_ICONS; i++)
9006 EntryIconInfo *icon_info = priv->icons[i];
9008 if (icon_info != NULL)
9010 if (icon_info->in_drag)
9015 if (GTK_ENTRY (widget)->editable &&
9016 gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end))
9017 gtk_editable_delete_text (editable, sel_start, sel_end);
9020 /* We display the cursor when
9022 * - the selection is empty, AND
9023 * - the widget has focus
9026 #define CURSOR_ON_MULTIPLIER 2
9027 #define CURSOR_OFF_MULTIPLIER 1
9028 #define CURSOR_PEND_MULTIPLIER 3
9029 #define CURSOR_DIVIDER 3
9032 cursor_blinks (GtkEntry *entry)
9034 if (gtk_widget_has_focus (GTK_WIDGET (entry)) &&
9036 entry->selection_bound == entry->current_pos)
9038 GtkSettings *settings;
9041 settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9042 g_object_get (settings, "gtk-cursor-blink", &blink, NULL);
9051 get_cursor_time (GtkEntry *entry)
9053 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9056 g_object_get (settings, "gtk-cursor-blink-time", &time, NULL);
9062 get_cursor_blink_timeout (GtkEntry *entry)
9064 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9067 g_object_get (settings, "gtk-cursor-blink-timeout", &timeout, NULL);
9073 show_cursor (GtkEntry *entry)
9077 if (!entry->cursor_visible)
9079 entry->cursor_visible = TRUE;
9081 widget = GTK_WIDGET (entry);
9082 if (gtk_widget_has_focus (widget) && entry->selection_bound == entry->current_pos)
9083 gtk_widget_queue_draw (widget);
9088 hide_cursor (GtkEntry *entry)
9092 if (entry->cursor_visible)
9094 entry->cursor_visible = FALSE;
9096 widget = GTK_WIDGET (entry);
9097 if (gtk_widget_has_focus (widget) && entry->selection_bound == entry->current_pos)
9098 gtk_widget_queue_draw (widget);
9106 blink_cb (gpointer data)
9109 GtkEntryPrivate *priv;
9112 entry = GTK_ENTRY (data);
9113 priv = GTK_ENTRY_GET_PRIVATE (entry);
9115 if (!gtk_widget_has_focus (GTK_WIDGET (entry)))
9117 g_warning ("GtkEntry - did not receive focus-out-event. If you\n"
9118 "connect a handler to this signal, it must return\n"
9119 "FALSE so the entry gets the event as well");
9121 gtk_entry_check_cursor_blink (entry);
9126 g_assert (entry->selection_bound == entry->current_pos);
9128 blink_timeout = get_cursor_blink_timeout (entry);
9129 if (priv->blink_time > 1000 * blink_timeout &&
9130 blink_timeout < G_MAXINT/1000)
9132 /* we've blinked enough without the user doing anything, stop blinking */
9133 show_cursor (entry);
9134 entry->blink_timeout = 0;
9136 else if (entry->cursor_visible)
9138 hide_cursor (entry);
9139 entry->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_OFF_MULTIPLIER / CURSOR_DIVIDER,
9145 show_cursor (entry);
9146 priv->blink_time += get_cursor_time (entry);
9147 entry->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
9152 /* Remove ourselves */
9157 gtk_entry_check_cursor_blink (GtkEntry *entry)
9159 GtkEntryPrivate *priv;
9161 priv = GTK_ENTRY_GET_PRIVATE (entry);
9163 if (cursor_blinks (entry))
9165 if (!entry->blink_timeout)
9167 show_cursor (entry);
9168 entry->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
9175 if (entry->blink_timeout)
9177 g_source_remove (entry->blink_timeout);
9178 entry->blink_timeout = 0;
9181 entry->cursor_visible = TRUE;
9187 gtk_entry_pend_cursor_blink (GtkEntry *entry)
9189 if (cursor_blinks (entry))
9191 if (entry->blink_timeout != 0)
9192 g_source_remove (entry->blink_timeout);
9194 entry->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_PEND_MULTIPLIER / CURSOR_DIVIDER,
9197 show_cursor (entry);
9202 gtk_entry_reset_blink_time (GtkEntry *entry)
9204 GtkEntryPrivate *priv;
9206 priv = GTK_ENTRY_GET_PRIVATE (entry);
9208 priv->blink_time = 0;
9214 gtk_entry_completion_timeout (gpointer data)
9216 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (data);
9217 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (completion->priv->entry);
9219 completion->priv->completion_timeout = 0;
9221 if (completion->priv->filter_model &&
9222 g_utf8_strlen (gtk_entry_get_text (GTK_ENTRY (completion->priv->entry)), -1)
9223 >= completion->priv->minimum_key_length)
9227 GtkTreeSelection *s;
9228 gboolean popup_single;
9230 gtk_entry_completion_complete (completion);
9231 matches = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->filter_model), NULL);
9233 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9235 s = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view));
9237 gtk_tree_selection_unselect_all (s);
9239 actions = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->actions), NULL);
9241 g_object_get (completion, "popup-single-match", &popup_single, NULL);
9242 if ((matches > (popup_single ? 0: 1)) || actions > 0)
9244 if (gtk_widget_get_visible (completion->priv->popup_window))
9245 _gtk_entry_completion_resize_popup (completion);
9247 _gtk_entry_completion_popup (completion, priv->completion_device);
9250 _gtk_entry_completion_popdown (completion);
9252 else if (gtk_widget_get_visible (completion->priv->popup_window))
9253 _gtk_entry_completion_popdown (completion);
9258 static inline gboolean
9259 keyval_is_cursor_move (guint keyval)
9261 if (keyval == GDK_Up || keyval == GDK_KP_Up)
9264 if (keyval == GDK_Down || keyval == GDK_KP_Down)
9267 if (keyval == GDK_Page_Up)
9270 if (keyval == GDK_Page_Down)
9277 gtk_entry_completion_key_press (GtkWidget *widget,
9281 gint matches, actions = 0;
9282 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
9284 if (!gtk_widget_get_mapped (completion->priv->popup_window))
9287 matches = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->filter_model), NULL);
9289 if (completion->priv->actions)
9290 actions = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->actions), NULL);
9292 if (keyval_is_cursor_move (event->keyval))
9294 GtkTreePath *path = NULL;
9296 if (event->keyval == GDK_Up || event->keyval == GDK_KP_Up)
9298 if (completion->priv->current_selected < 0)
9299 completion->priv->current_selected = matches + actions - 1;
9301 completion->priv->current_selected--;
9303 else if (event->keyval == GDK_Down || event->keyval == GDK_KP_Down)
9305 if (completion->priv->current_selected < matches + actions - 1)
9306 completion->priv->current_selected++;
9308 completion->priv->current_selected = -1;
9310 else if (event->keyval == GDK_Page_Up)
9312 if (completion->priv->current_selected < 0)
9313 completion->priv->current_selected = matches + actions - 1;
9314 else if (completion->priv->current_selected == 0)
9315 completion->priv->current_selected = -1;
9316 else if (completion->priv->current_selected < matches)
9318 completion->priv->current_selected -= 14;
9319 if (completion->priv->current_selected < 0)
9320 completion->priv->current_selected = 0;
9324 completion->priv->current_selected -= 14;
9325 if (completion->priv->current_selected < matches - 1)
9326 completion->priv->current_selected = matches - 1;
9329 else if (event->keyval == GDK_Page_Down)
9331 if (completion->priv->current_selected < 0)
9332 completion->priv->current_selected = 0;
9333 else if (completion->priv->current_selected < matches - 1)
9335 completion->priv->current_selected += 14;
9336 if (completion->priv->current_selected > matches - 1)
9337 completion->priv->current_selected = matches - 1;
9339 else if (completion->priv->current_selected == matches + actions - 1)
9341 completion->priv->current_selected = -1;
9345 completion->priv->current_selected += 14;
9346 if (completion->priv->current_selected > matches + actions - 1)
9347 completion->priv->current_selected = matches + actions - 1;
9351 if (completion->priv->current_selected < 0)
9353 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9354 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view)));
9356 if (completion->priv->inline_selection &&
9357 completion->priv->completion_prefix)
9359 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9360 completion->priv->completion_prefix);
9361 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9364 else if (completion->priv->current_selected < matches)
9366 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view)));
9368 path = gtk_tree_path_new_from_indices (completion->priv->current_selected, -1);
9369 gtk_tree_view_set_cursor (GTK_TREE_VIEW (completion->priv->tree_view),
9372 if (completion->priv->inline_selection)
9376 GtkTreeIter child_iter;
9377 GtkTreeModel *model = NULL;
9378 GtkTreeSelection *sel;
9381 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view));
9382 if (!gtk_tree_selection_get_selected (sel, &model, &iter))
9385 gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (model), &child_iter, &iter);
9386 model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model));
9388 if (completion->priv->completion_prefix == NULL)
9389 completion->priv->completion_prefix = g_strdup (gtk_entry_get_text (GTK_ENTRY (completion->priv->entry)));
9391 g_signal_emit_by_name (completion, "cursor-on-match", model,
9392 &child_iter, &entry_set);
9395 else if (completion->priv->current_selected - matches >= 0)
9397 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9399 path = gtk_tree_path_new_from_indices (completion->priv->current_selected - matches, -1);
9400 gtk_tree_view_set_cursor (GTK_TREE_VIEW (completion->priv->action_view),
9403 if (completion->priv->inline_selection &&
9404 completion->priv->completion_prefix)
9406 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9407 completion->priv->completion_prefix);
9408 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9412 gtk_tree_path_free (path);
9416 else if (event->keyval == GDK_Escape ||
9417 event->keyval == GDK_Left ||
9418 event->keyval == GDK_KP_Left ||
9419 event->keyval == GDK_Right ||
9420 event->keyval == GDK_KP_Right)
9422 gboolean retval = TRUE;
9424 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9425 _gtk_entry_completion_popdown (completion);
9427 if (completion->priv->current_selected < 0)
9430 goto keypress_completion_out;
9432 else if (completion->priv->inline_selection)
9434 /* Escape rejects the tentative completion */
9435 if (event->keyval == GDK_Escape)
9437 if (completion->priv->completion_prefix)
9438 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9439 completion->priv->completion_prefix);
9441 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry), "");
9444 /* Move the cursor to the end for Right/Esc, to the
9445 beginning for Left */
9446 if (event->keyval == GDK_Right ||
9447 event->keyval == GDK_KP_Right ||
9448 event->keyval == GDK_Escape)
9449 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9451 gtk_editable_set_position (GTK_EDITABLE (widget), 0);
9454 keypress_completion_out:
9455 if (completion->priv->inline_selection)
9457 g_free (completion->priv->completion_prefix);
9458 completion->priv->completion_prefix = NULL;
9463 else if (event->keyval == GDK_Tab ||
9464 event->keyval == GDK_KP_Tab ||
9465 event->keyval == GDK_ISO_Left_Tab)
9467 GtkDirectionType dir = event->keyval == GDK_ISO_Left_Tab ?
9468 GTK_DIR_TAB_BACKWARD : GTK_DIR_TAB_FORWARD;
9470 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9471 _gtk_entry_completion_popdown (completion);
9473 g_free (completion->priv->completion_prefix);
9474 completion->priv->completion_prefix = NULL;
9476 gtk_widget_child_focus (gtk_widget_get_toplevel (widget), dir);
9480 else if (event->keyval == GDK_ISO_Enter ||
9481 event->keyval == GDK_KP_Enter ||
9482 event->keyval == GDK_Return)
9485 GtkTreeModel *model = NULL;
9486 GtkTreeSelection *sel;
9487 gboolean retval = TRUE;
9489 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9490 _gtk_entry_completion_popdown (completion);
9492 if (completion->priv->current_selected < matches)
9496 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view));
9497 if (gtk_tree_selection_get_selected (sel, &model, &iter))
9499 g_signal_handler_block (widget, completion->priv->changed_id);
9500 g_signal_emit_by_name (completion, "match-selected",
9501 model, &iter, &entry_set);
9502 g_signal_handler_unblock (widget, completion->priv->changed_id);
9508 gtk_tree_model_get (model, &iter,
9509 completion->priv->text_column, &str,
9512 gtk_entry_set_text (GTK_ENTRY (widget), str);
9514 /* move the cursor to the end */
9515 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9523 else if (completion->priv->current_selected - matches >= 0)
9525 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view));
9526 if (gtk_tree_selection_get_selected (sel, &model, &iter))
9530 path = gtk_tree_path_new_from_indices (completion->priv->current_selected - matches, -1);
9531 g_signal_emit_by_name (completion, "action-activated",
9532 gtk_tree_path_get_indices (path)[0]);
9533 gtk_tree_path_free (path);
9539 g_free (completion->priv->completion_prefix);
9540 completion->priv->completion_prefix = NULL;
9549 gtk_entry_completion_changed (GtkWidget *entry,
9552 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
9553 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
9556 /* (re)install completion timeout */
9557 if (completion->priv->completion_timeout)
9558 g_source_remove (completion->priv->completion_timeout);
9560 if (!gtk_entry_get_text (GTK_ENTRY (entry)))
9563 /* no need to normalize for this test */
9564 if (completion->priv->minimum_key_length > 0 &&
9565 strcmp ("", gtk_entry_get_text (GTK_ENTRY (entry))) == 0)
9567 if (gtk_widget_get_visible (completion->priv->popup_window))
9568 _gtk_entry_completion_popdown (completion);
9572 device = gtk_get_current_event_device ();
9574 if (device && device->source == GDK_SOURCE_KEYBOARD)
9575 device = gdk_device_get_associated_device (device);
9578 priv->completion_device = device;
9580 completion->priv->completion_timeout =
9581 gdk_threads_add_timeout (COMPLETION_TIMEOUT,
9582 gtk_entry_completion_timeout,
9587 check_completion_callback (GtkEntryCompletion *completion)
9589 completion->priv->check_completion_idle = NULL;
9591 gtk_entry_completion_complete (completion);
9592 gtk_entry_completion_insert_prefix (completion);
9598 clear_completion_callback (GtkEntry *entry,
9601 if (pspec->name == I_("cursor-position") ||
9602 pspec->name == I_("selection-bound"))
9604 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
9606 completion->priv->has_completion = FALSE;
9611 accept_completion_callback (GtkEntry *entry)
9613 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
9615 if (completion->priv->has_completion)
9616 gtk_editable_set_position (GTK_EDITABLE (entry),
9617 gtk_entry_buffer_get_length (get_buffer (entry)));
9623 completion_insert_text_callback (GtkEntry *entry,
9627 GtkEntryCompletion *completion)
9629 /* idle to update the selection based on the file list */
9630 if (completion->priv->check_completion_idle == NULL)
9632 completion->priv->check_completion_idle = g_idle_source_new ();
9633 g_source_set_priority (completion->priv->check_completion_idle, G_PRIORITY_HIGH);
9634 g_source_set_closure (completion->priv->check_completion_idle,
9635 g_cclosure_new_object (G_CALLBACK (check_completion_callback),
9636 G_OBJECT (completion)));
9637 g_source_attach (completion->priv->check_completion_idle, NULL);
9642 completion_changed (GtkEntryCompletion *completion,
9646 GtkEntry *entry = GTK_ENTRY (data);
9648 if (pspec->name == I_("popup-completion") ||
9649 pspec->name == I_("inline-completion"))
9651 disconnect_completion_signals (entry, completion);
9652 connect_completion_signals (entry, completion);
9657 disconnect_completion_signals (GtkEntry *entry,
9658 GtkEntryCompletion *completion)
9660 g_signal_handlers_disconnect_by_func (completion,
9661 G_CALLBACK (completion_changed), entry);
9662 if (completion->priv->changed_id > 0 &&
9663 g_signal_handler_is_connected (entry, completion->priv->changed_id))
9665 g_signal_handler_disconnect (entry, completion->priv->changed_id);
9666 completion->priv->changed_id = 0;
9668 g_signal_handlers_disconnect_by_func (entry,
9669 G_CALLBACK (gtk_entry_completion_key_press), completion);
9670 if (completion->priv->insert_text_id > 0 &&
9671 g_signal_handler_is_connected (entry, completion->priv->insert_text_id))
9673 g_signal_handler_disconnect (entry, completion->priv->insert_text_id);
9674 completion->priv->insert_text_id = 0;
9676 g_signal_handlers_disconnect_by_func (entry,
9677 G_CALLBACK (completion_insert_text_callback), completion);
9678 g_signal_handlers_disconnect_by_func (entry,
9679 G_CALLBACK (clear_completion_callback), completion);
9680 g_signal_handlers_disconnect_by_func (entry,
9681 G_CALLBACK (accept_completion_callback), completion);
9685 connect_completion_signals (GtkEntry *entry,
9686 GtkEntryCompletion *completion)
9688 if (completion->priv->popup_completion)
9690 completion->priv->changed_id =
9691 g_signal_connect (entry, "changed",
9692 G_CALLBACK (gtk_entry_completion_changed), completion);
9693 g_signal_connect (entry, "key-press-event",
9694 G_CALLBACK (gtk_entry_completion_key_press), completion);
9697 if (completion->priv->inline_completion)
9699 completion->priv->insert_text_id =
9700 g_signal_connect (entry, "insert-text",
9701 G_CALLBACK (completion_insert_text_callback), completion);
9702 g_signal_connect (entry, "notify",
9703 G_CALLBACK (clear_completion_callback), completion);
9704 g_signal_connect (entry, "activate",
9705 G_CALLBACK (accept_completion_callback), completion);
9706 g_signal_connect (entry, "focus-out-event",
9707 G_CALLBACK (accept_completion_callback), completion);
9710 g_signal_connect (completion, "notify",
9711 G_CALLBACK (completion_changed), entry);
9715 * gtk_entry_set_completion:
9716 * @entry: A #GtkEntry
9717 * @completion: (allow-none): The #GtkEntryCompletion or %NULL
9719 * Sets @completion to be the auxiliary completion object to use with @entry.
9720 * All further configuration of the completion mechanism is done on
9721 * @completion using the #GtkEntryCompletion API. Completion is disabled if
9722 * @completion is set to %NULL.
9727 gtk_entry_set_completion (GtkEntry *entry,
9728 GtkEntryCompletion *completion)
9730 GtkEntryCompletion *old;
9732 g_return_if_fail (GTK_IS_ENTRY (entry));
9733 g_return_if_fail (!completion || GTK_IS_ENTRY_COMPLETION (completion));
9735 old = gtk_entry_get_completion (entry);
9737 if (old == completion)
9742 if (old->priv->completion_timeout)
9744 g_source_remove (old->priv->completion_timeout);
9745 old->priv->completion_timeout = 0;
9748 if (gtk_widget_get_mapped (old->priv->popup_window))
9749 _gtk_entry_completion_popdown (old);
9751 disconnect_completion_signals (entry, old);
9752 old->priv->entry = NULL;
9754 g_object_unref (old);
9759 g_object_set_data (G_OBJECT (entry), I_(GTK_ENTRY_COMPLETION_KEY), NULL);
9763 /* hook into the entry */
9764 g_object_ref (completion);
9766 connect_completion_signals (entry, completion);
9767 completion->priv->entry = GTK_WIDGET (entry);
9768 g_object_set_data (G_OBJECT (entry), I_(GTK_ENTRY_COMPLETION_KEY), completion);
9772 * gtk_entry_get_completion:
9773 * @entry: A #GtkEntry
9775 * Returns the auxiliary completion object currently in use by @entry.
9777 * Return value: The auxiliary completion object currently in use by @entry.
9781 GtkEntryCompletion *
9782 gtk_entry_get_completion (GtkEntry *entry)
9784 GtkEntryCompletion *completion;
9786 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
9788 completion = GTK_ENTRY_COMPLETION (g_object_get_data (G_OBJECT (entry),
9789 GTK_ENTRY_COMPLETION_KEY));
9795 * gtk_entry_set_cursor_hadjustment:
9796 * @entry: a #GtkEntry
9797 * @adjustment: an adjustment which should be adjusted when the cursor
9798 * is moved, or %NULL
9800 * Hooks up an adjustment to the cursor position in an entry, so that when
9801 * the cursor is moved, the adjustment is scrolled to show that position.
9802 * See gtk_scrolled_window_get_hadjustment() for a typical way of obtaining
9805 * The adjustment has to be in pixel units and in the same coordinate system
9811 gtk_entry_set_cursor_hadjustment (GtkEntry *entry,
9812 GtkAdjustment *adjustment)
9814 g_return_if_fail (GTK_IS_ENTRY (entry));
9816 g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
9819 g_object_ref (adjustment);
9821 g_object_set_qdata_full (G_OBJECT (entry),
9822 quark_cursor_hadjustment,
9828 * gtk_entry_get_cursor_hadjustment:
9829 * @entry: a #GtkEntry
9831 * Retrieves the horizontal cursor adjustment for the entry.
9832 * See gtk_entry_set_cursor_hadjustment().
9834 * Return value: (transfer none): the horizontal cursor adjustment, or %NULL
9835 * if none has been set.
9840 gtk_entry_get_cursor_hadjustment (GtkEntry *entry)
9842 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
9844 return g_object_get_qdata (G_OBJECT (entry), quark_cursor_hadjustment);
9848 * gtk_entry_set_progress_fraction:
9849 * @entry: a #GtkEntry
9850 * @fraction: fraction of the task that's been completed
9852 * Causes the entry's progress indicator to "fill in" the given
9853 * fraction of the bar. The fraction should be between 0.0 and 1.0,
9859 gtk_entry_set_progress_fraction (GtkEntry *entry,
9863 GtkEntryPrivate *private;
9864 gdouble old_fraction;
9865 gint x, y, width, height;
9866 gint old_x, old_y, old_width, old_height;
9868 g_return_if_fail (GTK_IS_ENTRY (entry));
9870 widget = GTK_WIDGET (entry);
9871 private = GTK_ENTRY_GET_PRIVATE (entry);
9873 if (private->progress_pulse_mode)
9876 old_fraction = private->progress_fraction;
9878 if (gtk_widget_is_drawable (widget))
9879 get_progress_area (widget, &old_x, &old_y, &old_width, &old_height);
9881 fraction = CLAMP (fraction, 0.0, 1.0);
9883 private->progress_fraction = fraction;
9884 private->progress_pulse_mode = FALSE;
9885 private->progress_pulse_current = 0.0;
9887 if (gtk_widget_is_drawable (widget))
9889 get_progress_area (widget, &x, &y, &width, &height);
9891 if ((x != old_x) || (y != old_y) || (width != old_width) || (height != old_height))
9892 gtk_widget_queue_draw (widget);
9895 if (fraction != old_fraction)
9896 g_object_notify (G_OBJECT (entry), "progress-fraction");
9900 * gtk_entry_get_progress_fraction:
9901 * @entry: a #GtkEntry
9903 * Returns the current fraction of the task that's been completed.
9904 * See gtk_entry_set_progress_fraction().
9906 * Return value: a fraction from 0.0 to 1.0
9911 gtk_entry_get_progress_fraction (GtkEntry *entry)
9913 GtkEntryPrivate *private;
9915 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
9917 private = GTK_ENTRY_GET_PRIVATE (entry);
9919 return private->progress_fraction;
9923 * gtk_entry_set_progress_pulse_step:
9924 * @entry: a #GtkEntry
9925 * @fraction: fraction between 0.0 and 1.0
9927 * Sets the fraction of total entry width to move the progress
9928 * bouncing block for each call to gtk_entry_progress_pulse().
9933 gtk_entry_set_progress_pulse_step (GtkEntry *entry,
9936 GtkEntryPrivate *private;
9938 g_return_if_fail (GTK_IS_ENTRY (entry));
9940 private = GTK_ENTRY_GET_PRIVATE (entry);
9942 fraction = CLAMP (fraction, 0.0, 1.0);
9944 if (fraction != private->progress_pulse_fraction)
9946 private->progress_pulse_fraction = fraction;
9948 gtk_widget_queue_draw (GTK_WIDGET (entry));
9950 g_object_notify (G_OBJECT (entry), "progress-pulse-step");
9955 * gtk_entry_get_progress_pulse_step:
9956 * @entry: a #GtkEntry
9958 * Retrieves the pulse step set with gtk_entry_set_progress_pulse_step().
9960 * Return value: a fraction from 0.0 to 1.0
9965 gtk_entry_get_progress_pulse_step (GtkEntry *entry)
9967 GtkEntryPrivate *private;
9969 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
9971 private = GTK_ENTRY_GET_PRIVATE (entry);
9973 return private->progress_pulse_fraction;
9977 * gtk_entry_progress_pulse:
9978 * @entry: a #GtkEntry
9980 * Indicates that some progress is made, but you don't know how much.
9981 * Causes the entry's progress indicator to enter "activity mode,"
9982 * where a block bounces back and forth. Each call to
9983 * gtk_entry_progress_pulse() causes the block to move by a little bit
9984 * (the amount of movement per pulse is determined by
9985 * gtk_entry_set_progress_pulse_step()).
9990 gtk_entry_progress_pulse (GtkEntry *entry)
9992 GtkEntryPrivate *private;
9994 g_return_if_fail (GTK_IS_ENTRY (entry));
9996 private = GTK_ENTRY_GET_PRIVATE (entry);
9998 if (private->progress_pulse_mode)
10000 if (private->progress_pulse_way_back)
10002 private->progress_pulse_current -= private->progress_pulse_fraction;
10004 if (private->progress_pulse_current < 0.0)
10006 private->progress_pulse_current = 0.0;
10007 private->progress_pulse_way_back = FALSE;
10012 private->progress_pulse_current += private->progress_pulse_fraction;
10014 if (private->progress_pulse_current > 1.0 - private->progress_pulse_fraction)
10016 private->progress_pulse_current = 1.0 - private->progress_pulse_fraction;
10017 private->progress_pulse_way_back = TRUE;
10023 private->progress_fraction = 0.0;
10024 private->progress_pulse_mode = TRUE;
10025 private->progress_pulse_way_back = FALSE;
10026 private->progress_pulse_current = 0.0;
10029 gtk_widget_queue_draw (GTK_WIDGET (entry));
10032 /* Caps Lock warning for password entries */
10035 show_capslock_feedback (GtkEntry *entry,
10038 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
10040 if (gtk_entry_get_icon_storage_type (entry, GTK_ENTRY_ICON_SECONDARY) == GTK_IMAGE_EMPTY)
10042 gtk_entry_set_icon_from_stock (entry, GTK_ENTRY_ICON_SECONDARY, GTK_STOCK_CAPS_LOCK_WARNING);
10043 gtk_entry_set_icon_activatable (entry, GTK_ENTRY_ICON_SECONDARY, FALSE);
10044 priv->caps_lock_warning_shown = TRUE;
10047 if (priv->caps_lock_warning_shown)
10048 gtk_entry_set_icon_tooltip_text (entry, GTK_ENTRY_ICON_SECONDARY, text);
10050 g_warning ("Can't show Caps Lock warning, since secondary icon is set");
10054 remove_capslock_feedback (GtkEntry *entry)
10056 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
10058 if (priv->caps_lock_warning_shown)
10060 gtk_entry_set_icon_from_stock (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
10061 priv->caps_lock_warning_shown = FALSE;
10066 keymap_state_changed (GdkKeymap *keymap,
10069 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
10072 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL && priv->caps_lock_warning)
10074 if (gdk_keymap_get_num_lock_state (keymap)
10075 && gdk_keymap_get_caps_lock_state (keymap))
10076 text = _("Caps Lock and Num Lock are on");
10077 else if (gdk_keymap_get_num_lock_state (keymap))
10078 text = _("Num Lock is on");
10079 else if (gdk_keymap_get_caps_lock_state (keymap))
10080 text = _("Caps Lock is on");
10084 show_capslock_feedback (entry, text);
10086 remove_capslock_feedback (entry);