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 (GtkEditableInterface *iface);
242 static void gtk_entry_cell_editable_init (GtkCellEditableIface *iface);
243 static void gtk_entry_set_property (GObject *object,
247 static void gtk_entry_get_property (GObject *object,
251 static void gtk_entry_finalize (GObject *object);
252 static void gtk_entry_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,
267 static void gtk_entry_draw_progress (GtkWidget *widget,
270 static gint gtk_entry_draw (GtkWidget *widget,
272 static gint gtk_entry_button_press (GtkWidget *widget,
273 GdkEventButton *event);
274 static gint gtk_entry_button_release (GtkWidget *widget,
275 GdkEventButton *event);
276 static gint gtk_entry_enter_notify (GtkWidget *widget,
277 GdkEventCrossing *event);
278 static gint gtk_entry_leave_notify (GtkWidget *widget,
279 GdkEventCrossing *event);
280 static gint gtk_entry_motion_notify (GtkWidget *widget,
281 GdkEventMotion *event);
282 static gint gtk_entry_key_press (GtkWidget *widget,
284 static gint gtk_entry_key_release (GtkWidget *widget,
286 static gint gtk_entry_focus_in (GtkWidget *widget,
287 GdkEventFocus *event);
288 static gint gtk_entry_focus_out (GtkWidget *widget,
289 GdkEventFocus *event);
290 static void gtk_entry_grab_focus (GtkWidget *widget);
291 static void gtk_entry_style_set (GtkWidget *widget,
292 GtkStyle *previous_style);
293 static gboolean gtk_entry_query_tooltip (GtkWidget *widget,
296 gboolean keyboard_tip,
297 GtkTooltip *tooltip);
298 static void gtk_entry_direction_changed (GtkWidget *widget,
299 GtkTextDirection previous_dir);
300 static void gtk_entry_state_changed (GtkWidget *widget,
301 GtkStateType previous_state);
302 static void gtk_entry_screen_changed (GtkWidget *widget,
303 GdkScreen *old_screen);
305 static gboolean gtk_entry_drag_drop (GtkWidget *widget,
306 GdkDragContext *context,
310 static gboolean gtk_entry_drag_motion (GtkWidget *widget,
311 GdkDragContext *context,
315 static void gtk_entry_drag_leave (GtkWidget *widget,
316 GdkDragContext *context,
318 static void gtk_entry_drag_data_received (GtkWidget *widget,
319 GdkDragContext *context,
322 GtkSelectionData *selection_data,
325 static void gtk_entry_drag_data_get (GtkWidget *widget,
326 GdkDragContext *context,
327 GtkSelectionData *selection_data,
330 static void gtk_entry_drag_data_delete (GtkWidget *widget,
331 GdkDragContext *context);
332 static void gtk_entry_drag_begin (GtkWidget *widget,
333 GdkDragContext *context);
334 static void gtk_entry_drag_end (GtkWidget *widget,
335 GdkDragContext *context);
338 /* GtkEditable method implementations
340 static void gtk_entry_insert_text (GtkEditable *editable,
341 const gchar *new_text,
342 gint new_text_length,
344 static void gtk_entry_delete_text (GtkEditable *editable,
347 static gchar * gtk_entry_get_chars (GtkEditable *editable,
350 static void gtk_entry_real_set_position (GtkEditable *editable,
352 static gint gtk_entry_get_position (GtkEditable *editable);
353 static void gtk_entry_set_selection_bounds (GtkEditable *editable,
356 static gboolean gtk_entry_get_selection_bounds (GtkEditable *editable,
360 /* GtkCellEditable method implementations
362 static void gtk_entry_start_editing (GtkCellEditable *cell_editable,
365 /* Default signal handlers
367 static void gtk_entry_real_insert_text (GtkEditable *editable,
368 const gchar *new_text,
369 gint new_text_length,
371 static void gtk_entry_real_delete_text (GtkEditable *editable,
374 static void gtk_entry_move_cursor (GtkEntry *entry,
375 GtkMovementStep step,
377 gboolean extend_selection);
378 static void gtk_entry_insert_at_cursor (GtkEntry *entry,
380 static void gtk_entry_delete_from_cursor (GtkEntry *entry,
383 static void gtk_entry_backspace (GtkEntry *entry);
384 static void gtk_entry_cut_clipboard (GtkEntry *entry);
385 static void gtk_entry_copy_clipboard (GtkEntry *entry);
386 static void gtk_entry_paste_clipboard (GtkEntry *entry);
387 static void gtk_entry_toggle_overwrite (GtkEntry *entry);
388 static void gtk_entry_select_all (GtkEntry *entry);
389 static void gtk_entry_real_activate (GtkEntry *entry);
390 static gboolean gtk_entry_popup_menu (GtkWidget *widget);
392 static void keymap_direction_changed (GdkKeymap *keymap,
394 static void keymap_state_changed (GdkKeymap *keymap,
396 static void remove_capslock_feedback (GtkEntry *entry);
398 /* IM Context Callbacks
400 static void gtk_entry_commit_cb (GtkIMContext *context,
403 static void gtk_entry_preedit_changed_cb (GtkIMContext *context,
405 static gboolean gtk_entry_retrieve_surrounding_cb (GtkIMContext *context,
407 static gboolean gtk_entry_delete_surrounding_cb (GtkIMContext *context,
414 static void gtk_entry_enter_text (GtkEntry *entry,
416 static void gtk_entry_set_positions (GtkEntry *entry,
418 gint selection_bound);
419 static void gtk_entry_draw_text (GtkEntry *entry,
421 static void gtk_entry_draw_cursor (GtkEntry *entry,
424 static PangoLayout *gtk_entry_ensure_layout (GtkEntry *entry,
425 gboolean include_preedit);
426 static void gtk_entry_reset_layout (GtkEntry *entry);
427 static void gtk_entry_queue_draw (GtkEntry *entry);
428 static void gtk_entry_recompute (GtkEntry *entry);
429 static gint gtk_entry_find_position (GtkEntry *entry,
431 static void gtk_entry_get_cursor_locations (GtkEntry *entry,
435 static void gtk_entry_adjust_scroll (GtkEntry *entry);
436 static gint gtk_entry_move_visually (GtkEntry *editable,
439 static gint gtk_entry_move_logically (GtkEntry *entry,
442 static gint gtk_entry_move_forward_word (GtkEntry *entry,
444 gboolean allow_whitespace);
445 static gint gtk_entry_move_backward_word (GtkEntry *entry,
447 gboolean allow_whitespace);
448 static void gtk_entry_delete_whitespace (GtkEntry *entry);
449 static void gtk_entry_select_word (GtkEntry *entry);
450 static void gtk_entry_select_line (GtkEntry *entry);
451 static void gtk_entry_paste (GtkEntry *entry,
453 static void gtk_entry_update_primary_selection (GtkEntry *entry);
454 static void gtk_entry_do_popup (GtkEntry *entry,
455 GdkEventButton *event);
456 static gboolean gtk_entry_mnemonic_activate (GtkWidget *widget,
457 gboolean group_cycling);
458 static void gtk_entry_check_cursor_blink (GtkEntry *entry);
459 static void gtk_entry_pend_cursor_blink (GtkEntry *entry);
460 static void gtk_entry_reset_blink_time (GtkEntry *entry);
461 static void gtk_entry_get_text_area_size (GtkEntry *entry,
466 static void get_text_area_size (GtkEntry *entry,
471 static void get_widget_window_size (GtkEntry *entry,
476 static void gtk_entry_move_adjustments (GtkEntry *entry);
477 static void gtk_entry_ensure_pixbuf (GtkEntry *entry,
478 GtkEntryIconPosition icon_pos);
482 static gint gtk_entry_completion_timeout (gpointer data);
483 static gboolean gtk_entry_completion_key_press (GtkWidget *widget,
486 static void gtk_entry_completion_changed (GtkWidget *entry,
488 static gboolean check_completion_callback (GtkEntryCompletion *completion);
489 static void clear_completion_callback (GtkEntry *entry,
491 static gboolean accept_completion_callback (GtkEntry *entry);
492 static void completion_insert_text_callback (GtkEntry *entry,
496 GtkEntryCompletion *completion);
497 static void completion_changed (GtkEntryCompletion *completion,
500 static void disconnect_completion_signals (GtkEntry *entry,
501 GtkEntryCompletion *completion);
502 static void connect_completion_signals (GtkEntry *entry,
503 GtkEntryCompletion *completion);
505 static void begin_change (GtkEntry *entry);
506 static void end_change (GtkEntry *entry);
507 static void emit_changed (GtkEntry *entry);
510 static void buffer_inserted_text (GtkEntryBuffer *buffer,
515 static void buffer_deleted_text (GtkEntryBuffer *buffer,
519 static void buffer_notify_text (GtkEntryBuffer *buffer,
522 static void buffer_notify_length (GtkEntryBuffer *buffer,
525 static void buffer_notify_max_length (GtkEntryBuffer *buffer,
528 static void buffer_connect_signals (GtkEntry *entry);
529 static void buffer_disconnect_signals (GtkEntry *entry);
530 static GtkEntryBuffer *get_buffer (GtkEntry *entry);
533 G_DEFINE_TYPE_WITH_CODE (GtkEntry, gtk_entry, GTK_TYPE_WIDGET,
534 G_IMPLEMENT_INTERFACE (GTK_TYPE_EDITABLE,
535 gtk_entry_editable_init)
536 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_EDITABLE,
537 gtk_entry_cell_editable_init))
540 add_move_binding (GtkBindingSet *binding_set,
543 GtkMovementStep step,
546 g_return_if_fail ((modmask & GDK_SHIFT_MASK) == 0);
548 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
552 G_TYPE_BOOLEAN, FALSE);
554 /* Selection-extending version */
555 gtk_binding_entry_add_signal (binding_set, keyval, modmask | GDK_SHIFT_MASK,
559 G_TYPE_BOOLEAN, TRUE);
563 gtk_entry_class_init (GtkEntryClass *class)
565 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
566 GtkWidgetClass *widget_class;
567 GtkObjectClass *gtk_object_class;
568 GtkBindingSet *binding_set;
570 widget_class = (GtkWidgetClass*) class;
571 gtk_object_class = (GtkObjectClass *)class;
573 gobject_class->dispose = gtk_entry_dispose;
574 gobject_class->finalize = gtk_entry_finalize;
575 gobject_class->set_property = gtk_entry_set_property;
576 gobject_class->get_property = gtk_entry_get_property;
578 widget_class->map = gtk_entry_map;
579 widget_class->unmap = gtk_entry_unmap;
580 widget_class->realize = gtk_entry_realize;
581 widget_class->unrealize = gtk_entry_unrealize;
582 widget_class->size_request = gtk_entry_size_request;
583 widget_class->size_allocate = gtk_entry_size_allocate;
584 widget_class->draw = gtk_entry_draw;
585 widget_class->enter_notify_event = gtk_entry_enter_notify;
586 widget_class->leave_notify_event = gtk_entry_leave_notify;
587 widget_class->button_press_event = gtk_entry_button_press;
588 widget_class->button_release_event = gtk_entry_button_release;
589 widget_class->motion_notify_event = gtk_entry_motion_notify;
590 widget_class->key_press_event = gtk_entry_key_press;
591 widget_class->key_release_event = gtk_entry_key_release;
592 widget_class->focus_in_event = gtk_entry_focus_in;
593 widget_class->focus_out_event = gtk_entry_focus_out;
594 widget_class->grab_focus = gtk_entry_grab_focus;
595 widget_class->style_set = gtk_entry_style_set;
596 widget_class->query_tooltip = gtk_entry_query_tooltip;
597 widget_class->drag_begin = gtk_entry_drag_begin;
598 widget_class->drag_end = gtk_entry_drag_end;
599 widget_class->direction_changed = gtk_entry_direction_changed;
600 widget_class->state_changed = gtk_entry_state_changed;
601 widget_class->screen_changed = gtk_entry_screen_changed;
602 widget_class->mnemonic_activate = gtk_entry_mnemonic_activate;
604 widget_class->drag_drop = gtk_entry_drag_drop;
605 widget_class->drag_motion = gtk_entry_drag_motion;
606 widget_class->drag_leave = gtk_entry_drag_leave;
607 widget_class->drag_data_received = gtk_entry_drag_data_received;
608 widget_class->drag_data_get = gtk_entry_drag_data_get;
609 widget_class->drag_data_delete = gtk_entry_drag_data_delete;
611 widget_class->popup_menu = gtk_entry_popup_menu;
613 gtk_object_class->destroy = gtk_entry_destroy;
615 class->move_cursor = gtk_entry_move_cursor;
616 class->insert_at_cursor = gtk_entry_insert_at_cursor;
617 class->delete_from_cursor = gtk_entry_delete_from_cursor;
618 class->backspace = gtk_entry_backspace;
619 class->cut_clipboard = gtk_entry_cut_clipboard;
620 class->copy_clipboard = gtk_entry_copy_clipboard;
621 class->paste_clipboard = gtk_entry_paste_clipboard;
622 class->toggle_overwrite = gtk_entry_toggle_overwrite;
623 class->activate = gtk_entry_real_activate;
624 class->get_text_area_size = gtk_entry_get_text_area_size;
626 quark_inner_border = g_quark_from_static_string ("gtk-entry-inner-border");
627 quark_password_hint = g_quark_from_static_string ("gtk-entry-password-hint");
628 quark_cursor_hadjustment = g_quark_from_static_string ("gtk-hadjustment");
629 quark_capslock_feedback = g_quark_from_static_string ("gtk-entry-capslock-feedback");
631 g_object_class_override_property (gobject_class,
632 PROP_EDITING_CANCELED,
635 g_object_class_install_property (gobject_class,
637 g_param_spec_object ("buffer",
639 P_("Text buffer object which actually stores entry text"),
640 GTK_TYPE_ENTRY_BUFFER,
641 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT));
643 g_object_class_install_property (gobject_class,
644 PROP_CURSOR_POSITION,
645 g_param_spec_int ("cursor-position",
646 P_("Cursor Position"),
647 P_("The current position of the insertion cursor in chars"),
649 GTK_ENTRY_BUFFER_MAX_SIZE,
651 GTK_PARAM_READABLE));
653 g_object_class_install_property (gobject_class,
654 PROP_SELECTION_BOUND,
655 g_param_spec_int ("selection-bound",
656 P_("Selection Bound"),
657 P_("The position of the opposite end of the selection from the cursor in chars"),
659 GTK_ENTRY_BUFFER_MAX_SIZE,
661 GTK_PARAM_READABLE));
663 g_object_class_install_property (gobject_class,
665 g_param_spec_boolean ("editable",
667 P_("Whether the entry contents can be edited"),
669 GTK_PARAM_READWRITE));
671 g_object_class_install_property (gobject_class,
673 g_param_spec_int ("max-length",
674 P_("Maximum length"),
675 P_("Maximum number of characters for this entry. Zero if no maximum"),
677 GTK_ENTRY_BUFFER_MAX_SIZE,
679 GTK_PARAM_READWRITE));
680 g_object_class_install_property (gobject_class,
682 g_param_spec_boolean ("visibility",
684 P_("FALSE displays the \"invisible char\" instead of the actual text (password mode)"),
686 GTK_PARAM_READWRITE));
688 g_object_class_install_property (gobject_class,
690 g_param_spec_boolean ("has-frame",
692 P_("FALSE removes outside bevel from entry"),
694 GTK_PARAM_READWRITE));
696 g_object_class_install_property (gobject_class,
698 g_param_spec_boxed ("inner-border",
700 P_("Border between text and frame. Overrides the inner-border style property"),
702 GTK_PARAM_READWRITE));
704 g_object_class_install_property (gobject_class,
706 g_param_spec_unichar ("invisible-char",
707 P_("Invisible character"),
708 P_("The character to use when masking entry contents (in \"password mode\")"),
710 GTK_PARAM_READWRITE));
712 g_object_class_install_property (gobject_class,
713 PROP_ACTIVATES_DEFAULT,
714 g_param_spec_boolean ("activates-default",
715 P_("Activates default"),
716 P_("Whether to activate the default widget (such as the default button in a dialog) when Enter is pressed"),
718 GTK_PARAM_READWRITE));
719 g_object_class_install_property (gobject_class,
721 g_param_spec_int ("width-chars",
722 P_("Width in chars"),
723 P_("Number of characters to leave space for in the entry"),
727 GTK_PARAM_READWRITE));
729 g_object_class_install_property (gobject_class,
731 g_param_spec_int ("scroll-offset",
733 P_("Number of pixels of the entry scrolled off the screen to the left"),
737 GTK_PARAM_READABLE));
739 g_object_class_install_property (gobject_class,
741 g_param_spec_string ("text",
743 P_("The contents of the entry"),
745 GTK_PARAM_READWRITE));
750 * The horizontal alignment, from 0 (left) to 1 (right).
751 * Reversed for RTL layouts.
755 g_object_class_install_property (gobject_class,
757 g_param_spec_float ("xalign",
759 P_("The horizontal alignment, from 0 (left) to 1 (right). Reversed for RTL layouts."),
763 GTK_PARAM_READWRITE));
766 * GtkEntry:truncate-multiline:
768 * When %TRUE, pasted multi-line text is truncated to the first line.
772 g_object_class_install_property (gobject_class,
773 PROP_TRUNCATE_MULTILINE,
774 g_param_spec_boolean ("truncate-multiline",
775 P_("Truncate multiline"),
776 P_("Whether to truncate multiline pastes to one line."),
778 GTK_PARAM_READWRITE));
781 * GtkEntry:shadow-type:
783 * Which kind of shadow to draw around the entry when
784 * #GtkEntry:has-frame is set to %TRUE.
788 g_object_class_install_property (gobject_class,
790 g_param_spec_enum ("shadow-type",
792 P_("Which kind of shadow to draw around the entry when has-frame is set"),
793 GTK_TYPE_SHADOW_TYPE,
795 GTK_PARAM_READWRITE));
798 * GtkEntry:overwrite-mode:
800 * If text is overwritten when typing in the #GtkEntry.
804 g_object_class_install_property (gobject_class,
806 g_param_spec_boolean ("overwrite-mode",
807 P_("Overwrite mode"),
808 P_("Whether new text overwrites existing text"),
810 GTK_PARAM_READWRITE));
813 * GtkEntry:text-length:
815 * The length of the text in the #GtkEntry.
819 g_object_class_install_property (gobject_class,
821 g_param_spec_uint ("text-length",
823 P_("Length of the text currently in the entry"),
827 GTK_PARAM_READABLE));
829 * GtkEntry:invisible-char-set:
831 * Whether the invisible char has been set for the #GtkEntry.
835 g_object_class_install_property (gobject_class,
836 PROP_INVISIBLE_CHAR_SET,
837 g_param_spec_boolean ("invisible-char-set",
838 P_("Invisible character set"),
839 P_("Whether the invisible character has been set"),
841 GTK_PARAM_READWRITE));
844 * GtkEntry:caps-lock-warning
846 * Whether password entries will show a warning when Caps Lock is on.
848 * Note that the warning is shown using a secondary icon, and thus
849 * does not work if you are using the secondary icon position for some
854 g_object_class_install_property (gobject_class,
855 PROP_CAPS_LOCK_WARNING,
856 g_param_spec_boolean ("caps-lock-warning",
857 P_("Caps Lock warning"),
858 P_("Whether password entries will show a warning when Caps Lock is on"),
860 GTK_PARAM_READWRITE));
863 * GtkEntry:progress-fraction:
865 * The current fraction of the task that's been completed.
869 g_object_class_install_property (gobject_class,
870 PROP_PROGRESS_FRACTION,
871 g_param_spec_double ("progress-fraction",
872 P_("Progress Fraction"),
873 P_("The current fraction of the task that's been completed"),
877 GTK_PARAM_READWRITE));
880 * GtkEntry:progress-pulse-step:
882 * The fraction of total entry width to move the progress
883 * bouncing block for each call to gtk_entry_progress_pulse().
887 g_object_class_install_property (gobject_class,
888 PROP_PROGRESS_PULSE_STEP,
889 g_param_spec_double ("progress-pulse-step",
890 P_("Progress Pulse Step"),
891 P_("The fraction of total entry width to move the progress bouncing block for each call to gtk_entry_progress_pulse()"),
895 GTK_PARAM_READWRITE));
898 * GtkEntry:primary-icon-pixbuf:
900 * A pixbuf to use as the primary icon for the entry.
904 g_object_class_install_property (gobject_class,
906 g_param_spec_object ("primary-icon-pixbuf",
907 P_("Primary pixbuf"),
908 P_("Primary pixbuf for the entry"),
910 GTK_PARAM_READWRITE));
913 * GtkEntry:secondary-icon-pixbuf:
915 * An pixbuf to use as the secondary icon for the entry.
919 g_object_class_install_property (gobject_class,
920 PROP_PIXBUF_SECONDARY,
921 g_param_spec_object ("secondary-icon-pixbuf",
922 P_("Secondary pixbuf"),
923 P_("Secondary pixbuf for the entry"),
925 GTK_PARAM_READWRITE));
928 * GtkEntry:primary-icon-stock:
930 * The stock id to use for the primary icon for the entry.
934 g_object_class_install_property (gobject_class,
936 g_param_spec_string ("primary-icon-stock",
937 P_("Primary stock ID"),
938 P_("Stock ID for primary icon"),
940 GTK_PARAM_READWRITE));
943 * GtkEntry:secondary-icon-stock:
945 * The stock id to use for the secondary icon for the entry.
949 g_object_class_install_property (gobject_class,
950 PROP_STOCK_SECONDARY,
951 g_param_spec_string ("secondary-icon-stock",
952 P_("Secondary stock ID"),
953 P_("Stock ID for secondary icon"),
955 GTK_PARAM_READWRITE));
958 * GtkEntry:primary-icon-name:
960 * The icon name to use for the primary icon for the entry.
964 g_object_class_install_property (gobject_class,
965 PROP_ICON_NAME_PRIMARY,
966 g_param_spec_string ("primary-icon-name",
967 P_("Primary icon name"),
968 P_("Icon name for primary icon"),
970 GTK_PARAM_READWRITE));
973 * GtkEntry:secondary-icon-name:
975 * The icon name to use for the secondary icon for the entry.
979 g_object_class_install_property (gobject_class,
980 PROP_ICON_NAME_SECONDARY,
981 g_param_spec_string ("secondary-icon-name",
982 P_("Secondary icon name"),
983 P_("Icon name for secondary icon"),
985 GTK_PARAM_READWRITE));
988 * GtkEntry:primary-icon-gicon:
990 * The #GIcon to use for the primary icon for the entry.
994 g_object_class_install_property (gobject_class,
996 g_param_spec_object ("primary-icon-gicon",
998 P_("GIcon for primary icon"),
1000 GTK_PARAM_READWRITE));
1003 * GtkEntry:secondary-icon-gicon:
1005 * The #GIcon to use for the secondary icon for the entry.
1009 g_object_class_install_property (gobject_class,
1010 PROP_GICON_SECONDARY,
1011 g_param_spec_object ("secondary-icon-gicon",
1012 P_("Secondary GIcon"),
1013 P_("GIcon for secondary icon"),
1015 GTK_PARAM_READWRITE));
1018 * GtkEntry:primary-icon-storage-type:
1020 * The representation which is used for the primary icon of the entry.
1024 g_object_class_install_property (gobject_class,
1025 PROP_STORAGE_TYPE_PRIMARY,
1026 g_param_spec_enum ("primary-icon-storage-type",
1027 P_("Primary storage type"),
1028 P_("The representation being used for primary icon"),
1029 GTK_TYPE_IMAGE_TYPE,
1031 GTK_PARAM_READABLE));
1034 * GtkEntry:secondary-icon-storage-type:
1036 * The representation which is used for the secondary icon of the entry.
1040 g_object_class_install_property (gobject_class,
1041 PROP_STORAGE_TYPE_SECONDARY,
1042 g_param_spec_enum ("secondary-icon-storage-type",
1043 P_("Secondary storage type"),
1044 P_("The representation being used for secondary icon"),
1045 GTK_TYPE_IMAGE_TYPE,
1047 GTK_PARAM_READABLE));
1050 * GtkEntry:primary-icon-activatable:
1052 * Whether the primary icon is activatable.
1054 * GTK+ emits the #GtkEntry::icon-press and #GtkEntry::icon-release
1055 * signals only on sensitive, activatable icons.
1057 * Sensitive, but non-activatable icons can be used for purely
1058 * informational purposes.
1062 g_object_class_install_property (gobject_class,
1063 PROP_ACTIVATABLE_PRIMARY,
1064 g_param_spec_boolean ("primary-icon-activatable",
1065 P_("Primary icon activatable"),
1066 P_("Whether the primary icon is activatable"),
1068 GTK_PARAM_READWRITE));
1071 * GtkEntry:secondary-icon-activatable:
1073 * Whether the secondary icon is activatable.
1075 * GTK+ emits the #GtkEntry::icon-press and #GtkEntry::icon-release
1076 * signals only on sensitive, activatable icons.
1078 * Sensitive, but non-activatable icons can be used for purely
1079 * informational purposes.
1083 g_object_class_install_property (gobject_class,
1084 PROP_ACTIVATABLE_SECONDARY,
1085 g_param_spec_boolean ("secondary-icon-activatable",
1086 P_("Secondary icon activatable"),
1087 P_("Whether the secondary icon is activatable"),
1089 GTK_PARAM_READWRITE));
1093 * GtkEntry:primary-icon-sensitive:
1095 * Whether the primary icon is sensitive.
1097 * An insensitive icon appears grayed out. GTK+ does not emit the
1098 * #GtkEntry::icon-press and #GtkEntry::icon-release signals and
1099 * does not allow DND from insensitive icons.
1101 * An icon should be set insensitive if the action that would trigger
1102 * when clicked is currently not available.
1106 g_object_class_install_property (gobject_class,
1107 PROP_SENSITIVE_PRIMARY,
1108 g_param_spec_boolean ("primary-icon-sensitive",
1109 P_("Primary icon sensitive"),
1110 P_("Whether the primary icon is sensitive"),
1112 GTK_PARAM_READWRITE));
1115 * GtkEntry:secondary-icon-sensitive:
1117 * Whether the secondary icon is sensitive.
1119 * An insensitive icon appears grayed out. GTK+ does not emit the
1120 * #GtkEntry::icon-press and #GtkEntry::icon-release signals and
1121 * does not allow DND from insensitive icons.
1123 * An icon should be set insensitive if the action that would trigger
1124 * when clicked is currently not available.
1128 g_object_class_install_property (gobject_class,
1129 PROP_SENSITIVE_SECONDARY,
1130 g_param_spec_boolean ("secondary-icon-sensitive",
1131 P_("Secondary icon sensitive"),
1132 P_("Whether the secondary icon is sensitive"),
1134 GTK_PARAM_READWRITE));
1137 * GtkEntry:primary-icon-tooltip-text:
1139 * The contents of the tooltip on the primary icon.
1141 * Also see gtk_entry_set_icon_tooltip_text().
1145 g_object_class_install_property (gobject_class,
1146 PROP_TOOLTIP_TEXT_PRIMARY,
1147 g_param_spec_string ("primary-icon-tooltip-text",
1148 P_("Primary icon tooltip text"),
1149 P_("The contents of the tooltip on the primary icon"),
1151 GTK_PARAM_READWRITE));
1154 * GtkEntry:secondary-icon-tooltip-text:
1156 * The contents of the tooltip on the secondary icon.
1158 * Also see gtk_entry_set_icon_tooltip_text().
1162 g_object_class_install_property (gobject_class,
1163 PROP_TOOLTIP_TEXT_SECONDARY,
1164 g_param_spec_string ("secondary-icon-tooltip-text",
1165 P_("Secondary icon tooltip text"),
1166 P_("The contents of the tooltip on the secondary icon"),
1168 GTK_PARAM_READWRITE));
1171 * GtkEntry:primary-icon-tooltip-markup:
1173 * The contents of the tooltip on the primary icon, which is marked up
1174 * with the <link linkend="PangoMarkupFormat">Pango text markup
1177 * Also see gtk_entry_set_icon_tooltip_markup().
1181 g_object_class_install_property (gobject_class,
1182 PROP_TOOLTIP_MARKUP_PRIMARY,
1183 g_param_spec_string ("primary-icon-tooltip-markup",
1184 P_("Primary icon tooltip markup"),
1185 P_("The contents of the tooltip on the primary icon"),
1187 GTK_PARAM_READWRITE));
1190 * GtkEntry:secondary-icon-tooltip-markup:
1192 * The contents of the tooltip on the secondary icon, which is marked up
1193 * with the <link linkend="PangoMarkupFormat">Pango text markup
1196 * Also see gtk_entry_set_icon_tooltip_markup().
1200 g_object_class_install_property (gobject_class,
1201 PROP_TOOLTIP_MARKUP_SECONDARY,
1202 g_param_spec_string ("secondary-icon-tooltip-markup",
1203 P_("Secondary icon tooltip markup"),
1204 P_("The contents of the tooltip on the secondary icon"),
1206 GTK_PARAM_READWRITE));
1209 * GtkEntry:im-module:
1211 * Which IM (input method) module should be used for this entry.
1212 * See #GtkIMContext.
1214 * Setting this to a non-%NULL value overrides the
1215 * system-wide IM module setting. See the GtkSettings
1216 * #GtkSettings:gtk-im-module property.
1220 g_object_class_install_property (gobject_class,
1222 g_param_spec_string ("im-module",
1224 P_("Which IM module should be used"),
1226 GTK_PARAM_READWRITE));
1229 * GtkEntry:icon-prelight:
1231 * The prelight style property determines whether activatable
1232 * icons prelight on mouseover.
1236 gtk_widget_class_install_style_property (widget_class,
1237 g_param_spec_boolean ("icon-prelight",
1238 P_("Icon Prelight"),
1239 P_("Whether activatable icons should prelight when hovered"),
1241 GTK_PARAM_READABLE));
1244 * GtkEntry:progress-border:
1246 * The border around the progress bar in the entry.
1250 gtk_widget_class_install_style_property (widget_class,
1251 g_param_spec_boxed ("progress-border",
1252 P_("Progress Border"),
1253 P_("Border around the progress bar"),
1255 GTK_PARAM_READABLE));
1258 * GtkEntry:invisible-char:
1260 * The invisible character is used when masking entry contents (in
1261 * \"password mode\")"). When it is not explicitly set with the
1262 * #GtkEntry::invisible-char property, GTK+ determines the character
1263 * to use from a list of possible candidates, depending on availability
1264 * in the current font.
1266 * This style property allows the theme to prepend a character
1267 * to the list of candidates.
1271 gtk_widget_class_install_style_property (widget_class,
1272 g_param_spec_unichar ("invisible-char",
1273 P_("Invisible character"),
1274 P_("The character to use when masking entry contents (in \"password mode\")"),
1276 GTK_PARAM_READABLE));
1279 * GtkEntry::populate-popup:
1280 * @entry: The entry on which the signal is emitted
1281 * @menu: the menu that is being populated
1283 * The ::populate-popup signal gets emitted before showing the
1284 * context menu of the entry.
1286 * If you need to add items to the context menu, connect
1287 * to this signal and append your menuitems to the @menu.
1289 signals[POPULATE_POPUP] =
1290 g_signal_new (I_("populate-popup"),
1291 G_OBJECT_CLASS_TYPE (gobject_class),
1293 G_STRUCT_OFFSET (GtkEntryClass, populate_popup),
1295 _gtk_marshal_VOID__OBJECT,
1299 /* Action signals */
1302 * GtkEntry::activate:
1303 * @entry: The entry on which the signal is emitted
1305 * A <link linkend="keybinding-signals">keybinding signal</link>
1306 * which gets emitted when the user activates the entry.
1308 * Applications should not connect to it, but may emit it with
1309 * g_signal_emit_by_name() if they need to control activation
1312 * The default bindings for this signal are all forms of the Enter key.
1315 g_signal_new (I_("activate"),
1316 G_OBJECT_CLASS_TYPE (gobject_class),
1317 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1318 G_STRUCT_OFFSET (GtkEntryClass, activate),
1320 _gtk_marshal_VOID__VOID,
1322 widget_class->activate_signal = signals[ACTIVATE];
1325 * GtkEntry::move-cursor:
1326 * @entry: the object which received the signal
1327 * @step: the granularity of the move, as a #GtkMovementStep
1328 * @count: the number of @step units to move
1329 * @extend_selection: %TRUE if the move should extend the selection
1331 * The ::move-cursor signal is a
1332 * <link linkend="keybinding-signals">keybinding signal</link>
1333 * which gets emitted when the user initiates a cursor movement.
1334 * If the cursor is not visible in @entry, this signal causes
1335 * the viewport to be moved instead.
1337 * Applications should not connect to it, but may emit it with
1338 * g_signal_emit_by_name() if they need to control the cursor
1341 * The default bindings for this signal come in two variants,
1342 * the variant with the Shift modifier extends the selection,
1343 * the variant without the Shift modifer does not.
1344 * There are too many key combinations to list them all here.
1346 * <listitem>Arrow keys move by individual characters/lines</listitem>
1347 * <listitem>Ctrl-arrow key combinations move by words/paragraphs</listitem>
1348 * <listitem>Home/End keys move to the ends of the buffer</listitem>
1351 signals[MOVE_CURSOR] =
1352 g_signal_new (I_("move-cursor"),
1353 G_OBJECT_CLASS_TYPE (gobject_class),
1354 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1355 G_STRUCT_OFFSET (GtkEntryClass, move_cursor),
1357 _gtk_marshal_VOID__ENUM_INT_BOOLEAN,
1359 GTK_TYPE_MOVEMENT_STEP,
1364 * GtkEntry::insert-at-cursor:
1365 * @entry: the object which received the signal
1366 * @string: the string to insert
1368 * The ::insert-at-cursor signal is a
1369 * <link linkend="keybinding-signals">keybinding signal</link>
1370 * which gets emitted when the user initiates the insertion of a
1371 * fixed string at the cursor.
1373 * This signal has no default bindings.
1375 signals[INSERT_AT_CURSOR] =
1376 g_signal_new (I_("insert-at-cursor"),
1377 G_OBJECT_CLASS_TYPE (gobject_class),
1378 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1379 G_STRUCT_OFFSET (GtkEntryClass, insert_at_cursor),
1381 _gtk_marshal_VOID__STRING,
1386 * GtkEntry::delete-from-cursor:
1387 * @entry: the object which received the signal
1388 * @type: the granularity of the deletion, as a #GtkDeleteType
1389 * @count: the number of @type units to delete
1391 * The ::delete-from-cursor signal is a
1392 * <link linkend="keybinding-signals">keybinding signal</link>
1393 * which gets emitted when the user initiates a text deletion.
1395 * If the @type is %GTK_DELETE_CHARS, GTK+ deletes the selection
1396 * if there is one, otherwise it deletes the requested number
1399 * The default bindings for this signal are
1400 * Delete for deleting a character and Ctrl-Delete for
1403 signals[DELETE_FROM_CURSOR] =
1404 g_signal_new (I_("delete-from-cursor"),
1405 G_OBJECT_CLASS_TYPE (gobject_class),
1406 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1407 G_STRUCT_OFFSET (GtkEntryClass, delete_from_cursor),
1409 _gtk_marshal_VOID__ENUM_INT,
1411 GTK_TYPE_DELETE_TYPE,
1415 * GtkEntry::backspace:
1416 * @entry: the object which received the signal
1418 * The ::backspace signal is a
1419 * <link linkend="keybinding-signals">keybinding signal</link>
1420 * which gets emitted when the user asks for it.
1422 * The default bindings for this signal are
1423 * Backspace and Shift-Backspace.
1425 signals[BACKSPACE] =
1426 g_signal_new (I_("backspace"),
1427 G_OBJECT_CLASS_TYPE (gobject_class),
1428 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1429 G_STRUCT_OFFSET (GtkEntryClass, backspace),
1431 _gtk_marshal_VOID__VOID,
1435 * GtkEntry::cut-clipboard:
1436 * @entry: the object which received the signal
1438 * The ::cut-clipboard signal is a
1439 * <link linkend="keybinding-signals">keybinding signal</link>
1440 * which gets emitted to cut the selection to the clipboard.
1442 * The default bindings for this signal are
1443 * Ctrl-x and Shift-Delete.
1445 signals[CUT_CLIPBOARD] =
1446 g_signal_new (I_("cut-clipboard"),
1447 G_OBJECT_CLASS_TYPE (gobject_class),
1448 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1449 G_STRUCT_OFFSET (GtkEntryClass, cut_clipboard),
1451 _gtk_marshal_VOID__VOID,
1455 * GtkEntry::copy-clipboard:
1456 * @entry: the object which received the signal
1458 * The ::copy-clipboard signal is a
1459 * <link linkend="keybinding-signals">keybinding signal</link>
1460 * which gets emitted to copy the selection to the clipboard.
1462 * The default bindings for this signal are
1463 * Ctrl-c and Ctrl-Insert.
1465 signals[COPY_CLIPBOARD] =
1466 g_signal_new (I_("copy-clipboard"),
1467 G_OBJECT_CLASS_TYPE (gobject_class),
1468 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1469 G_STRUCT_OFFSET (GtkEntryClass, copy_clipboard),
1471 _gtk_marshal_VOID__VOID,
1475 * GtkEntry::paste-clipboard:
1476 * @entry: the object which received the signal
1478 * The ::paste-clipboard signal is a
1479 * <link linkend="keybinding-signals">keybinding signal</link>
1480 * which gets emitted to paste the contents of the clipboard
1481 * into the text view.
1483 * The default bindings for this signal are
1484 * Ctrl-v and Shift-Insert.
1486 signals[PASTE_CLIPBOARD] =
1487 g_signal_new (I_("paste-clipboard"),
1488 G_OBJECT_CLASS_TYPE (gobject_class),
1489 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1490 G_STRUCT_OFFSET (GtkEntryClass, paste_clipboard),
1492 _gtk_marshal_VOID__VOID,
1496 * GtkEntry::toggle-overwrite:
1497 * @entry: the object which received the signal
1499 * The ::toggle-overwrite signal is a
1500 * <link linkend="keybinding-signals">keybinding signal</link>
1501 * which gets emitted to toggle the overwrite mode of the entry.
1503 * The default bindings for this signal is Insert.
1505 signals[TOGGLE_OVERWRITE] =
1506 g_signal_new (I_("toggle-overwrite"),
1507 G_OBJECT_CLASS_TYPE (gobject_class),
1508 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1509 G_STRUCT_OFFSET (GtkEntryClass, toggle_overwrite),
1511 _gtk_marshal_VOID__VOID,
1515 * GtkEntry::icon-press:
1516 * @entry: The entry on which the signal is emitted
1517 * @icon_pos: The position of the clicked icon
1518 * @event: the button press event
1520 * The ::icon-press signal is emitted when an activatable icon
1525 signals[ICON_PRESS] =
1526 g_signal_new (I_("icon-press"),
1527 G_TYPE_FROM_CLASS (gobject_class),
1531 _gtk_marshal_VOID__ENUM_BOXED,
1533 GTK_TYPE_ENTRY_ICON_POSITION,
1534 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1537 * GtkEntry::icon-release:
1538 * @entry: The entry on which the signal is emitted
1539 * @icon_pos: The position of the clicked icon
1540 * @event: the button release event
1542 * The ::icon-release signal is emitted on the button release from a
1543 * mouse click over an activatable icon.
1547 signals[ICON_RELEASE] =
1548 g_signal_new (I_("icon-release"),
1549 G_TYPE_FROM_CLASS (gobject_class),
1553 _gtk_marshal_VOID__ENUM_BOXED,
1555 GTK_TYPE_ENTRY_ICON_POSITION,
1556 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1559 * GtkEntry::preedit-changed:
1560 * @entry: the object which received the signal
1561 * @preedit: the current preedit string
1563 * If an input method is used, the typed text will not immediately
1564 * be committed to the buffer. So if you are interested in the text,
1565 * connect to this signal.
1569 signals[PREEDIT_CHANGED] =
1570 g_signal_new_class_handler (I_("preedit-changed"),
1571 G_OBJECT_CLASS_TYPE (gobject_class),
1572 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1575 _gtk_marshal_VOID__STRING,
1584 binding_set = gtk_binding_set_by_class (class);
1586 /* Moving the insertion point */
1587 add_move_binding (binding_set, GDK_KEY_Right, 0,
1588 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1590 add_move_binding (binding_set, GDK_KEY_Left, 0,
1591 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1593 add_move_binding (binding_set, GDK_KEY_KP_Right, 0,
1594 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1596 add_move_binding (binding_set, GDK_KEY_KP_Left, 0,
1597 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1599 add_move_binding (binding_set, GDK_KEY_Right, GDK_CONTROL_MASK,
1600 GTK_MOVEMENT_WORDS, 1);
1602 add_move_binding (binding_set, GDK_KEY_Left, GDK_CONTROL_MASK,
1603 GTK_MOVEMENT_WORDS, -1);
1605 add_move_binding (binding_set, GDK_KEY_KP_Right, GDK_CONTROL_MASK,
1606 GTK_MOVEMENT_WORDS, 1);
1608 add_move_binding (binding_set, GDK_KEY_KP_Left, GDK_CONTROL_MASK,
1609 GTK_MOVEMENT_WORDS, -1);
1611 add_move_binding (binding_set, GDK_KEY_Home, 0,
1612 GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
1614 add_move_binding (binding_set, GDK_KEY_End, 0,
1615 GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
1617 add_move_binding (binding_set, GDK_KEY_KP_Home, 0,
1618 GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
1620 add_move_binding (binding_set, GDK_KEY_KP_End, 0,
1621 GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
1623 add_move_binding (binding_set, GDK_KEY_Home, GDK_CONTROL_MASK,
1624 GTK_MOVEMENT_BUFFER_ENDS, -1);
1626 add_move_binding (binding_set, GDK_KEY_End, GDK_CONTROL_MASK,
1627 GTK_MOVEMENT_BUFFER_ENDS, 1);
1629 add_move_binding (binding_set, GDK_KEY_KP_Home, GDK_CONTROL_MASK,
1630 GTK_MOVEMENT_BUFFER_ENDS, -1);
1632 add_move_binding (binding_set, GDK_KEY_KP_End, GDK_CONTROL_MASK,
1633 GTK_MOVEMENT_BUFFER_ENDS, 1);
1637 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK,
1639 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1641 G_TYPE_BOOLEAN, FALSE);
1642 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK,
1644 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1646 G_TYPE_BOOLEAN, TRUE);
1648 gtk_binding_entry_add_signal (binding_set, GDK_KEY_slash, GDK_CONTROL_MASK,
1650 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1652 G_TYPE_BOOLEAN, FALSE);
1653 gtk_binding_entry_add_signal (binding_set, GDK_KEY_slash, GDK_CONTROL_MASK,
1655 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1657 G_TYPE_BOOLEAN, TRUE);
1660 gtk_binding_entry_add_signal (binding_set, GDK_KEY_backslash, GDK_CONTROL_MASK,
1662 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_VISUAL_POSITIONS,
1664 G_TYPE_BOOLEAN, FALSE);
1665 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_SHIFT_MASK | GDK_CONTROL_MASK,
1667 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_VISUAL_POSITIONS,
1669 G_TYPE_BOOLEAN, FALSE);
1673 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Return, 0,
1675 gtk_binding_entry_add_signal (binding_set, GDK_KEY_ISO_Enter, 0,
1677 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Enter, 0,
1681 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, 0,
1682 "delete-from-cursor", 2,
1683 G_TYPE_ENUM, GTK_DELETE_CHARS,
1686 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Delete, 0,
1687 "delete-from-cursor", 2,
1688 G_TYPE_ENUM, GTK_DELETE_CHARS,
1691 gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, 0,
1694 /* Make this do the same as Backspace, to help with mis-typing */
1695 gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, GDK_SHIFT_MASK,
1698 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, GDK_CONTROL_MASK,
1699 "delete-from-cursor", 2,
1700 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1703 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Delete, GDK_CONTROL_MASK,
1704 "delete-from-cursor", 2,
1705 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1708 gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, GDK_CONTROL_MASK,
1709 "delete-from-cursor", 2,
1710 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1713 /* Cut/copy/paste */
1715 gtk_binding_entry_add_signal (binding_set, GDK_KEY_x, GDK_CONTROL_MASK,
1716 "cut-clipboard", 0);
1717 gtk_binding_entry_add_signal (binding_set, GDK_KEY_c, GDK_CONTROL_MASK,
1718 "copy-clipboard", 0);
1719 gtk_binding_entry_add_signal (binding_set, GDK_KEY_v, GDK_CONTROL_MASK,
1720 "paste-clipboard", 0);
1722 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, GDK_SHIFT_MASK,
1723 "cut-clipboard", 0);
1724 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, GDK_CONTROL_MASK,
1725 "copy-clipboard", 0);
1726 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, GDK_SHIFT_MASK,
1727 "paste-clipboard", 0);
1730 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, 0,
1731 "toggle-overwrite", 0);
1732 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Insert, 0,
1733 "toggle-overwrite", 0);
1736 * GtkEntry:inner-border:
1738 * Sets the text area's border between the text and the frame.
1742 gtk_widget_class_install_style_property (widget_class,
1743 g_param_spec_boxed ("inner-border",
1745 P_("Border between text and frame."),
1747 GTK_PARAM_READABLE));
1749 gtk_settings_install_property (g_param_spec_boolean ("gtk-entry-select-on-focus",
1750 P_("Select on focus"),
1751 P_("Whether to select the contents of an entry when it is focused"),
1753 GTK_PARAM_READWRITE));
1756 * GtkSettings:gtk-entry-password-hint-timeout:
1758 * How long to show the last input character in hidden
1759 * entries. This value is in milliseconds. 0 disables showing the
1760 * last char. 600 is a good value for enabling it.
1764 gtk_settings_install_property (g_param_spec_uint ("gtk-entry-password-hint-timeout",
1765 P_("Password Hint Timeout"),
1766 P_("How long to show the last input character in hidden entries"),
1768 GTK_PARAM_READWRITE));
1770 g_type_class_add_private (gobject_class, sizeof (GtkEntryPrivate));
1774 gtk_entry_editable_init (GtkEditableInterface *iface)
1776 iface->do_insert_text = gtk_entry_insert_text;
1777 iface->do_delete_text = gtk_entry_delete_text;
1778 iface->insert_text = gtk_entry_real_insert_text;
1779 iface->delete_text = gtk_entry_real_delete_text;
1780 iface->get_chars = gtk_entry_get_chars;
1781 iface->set_selection_bounds = gtk_entry_set_selection_bounds;
1782 iface->get_selection_bounds = gtk_entry_get_selection_bounds;
1783 iface->set_position = gtk_entry_real_set_position;
1784 iface->get_position = gtk_entry_get_position;
1788 gtk_entry_cell_editable_init (GtkCellEditableIface *iface)
1790 iface->start_editing = gtk_entry_start_editing;
1794 gtk_entry_set_property (GObject *object,
1796 const GValue *value,
1799 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (object);
1800 GtkEntry *entry = GTK_ENTRY (object);
1806 gtk_entry_set_buffer (entry, g_value_get_object (value));
1811 gboolean new_value = g_value_get_boolean (value);
1813 if (new_value != entry->editable)
1815 widget = GTK_WIDGET (entry);
1818 _gtk_entry_reset_im_context (entry);
1819 if (gtk_widget_has_focus (widget))
1820 gtk_im_context_focus_out (entry->im_context);
1822 entry->preedit_length = 0;
1823 entry->preedit_cursor = 0;
1826 entry->editable = new_value;
1828 if (new_value && gtk_widget_has_focus (widget))
1829 gtk_im_context_focus_in (entry->im_context);
1831 gtk_entry_queue_draw (entry);
1836 case PROP_MAX_LENGTH:
1837 gtk_entry_set_max_length (entry, g_value_get_int (value));
1840 case PROP_VISIBILITY:
1841 gtk_entry_set_visibility (entry, g_value_get_boolean (value));
1844 case PROP_HAS_FRAME:
1845 gtk_entry_set_has_frame (entry, g_value_get_boolean (value));
1848 case PROP_INNER_BORDER:
1849 gtk_entry_set_inner_border (entry, g_value_get_boxed (value));
1852 case PROP_INVISIBLE_CHAR:
1853 gtk_entry_set_invisible_char (entry, g_value_get_uint (value));
1856 case PROP_ACTIVATES_DEFAULT:
1857 gtk_entry_set_activates_default (entry, g_value_get_boolean (value));
1860 case PROP_WIDTH_CHARS:
1861 gtk_entry_set_width_chars (entry, g_value_get_int (value));
1865 gtk_entry_set_text (entry, g_value_get_string (value));
1869 gtk_entry_set_alignment (entry, g_value_get_float (value));
1872 case PROP_TRUNCATE_MULTILINE:
1873 entry->truncate_multiline = g_value_get_boolean (value);
1876 case PROP_SHADOW_TYPE:
1877 priv->shadow_type = g_value_get_enum (value);
1880 case PROP_OVERWRITE_MODE:
1881 gtk_entry_set_overwrite_mode (entry, g_value_get_boolean (value));
1884 case PROP_INVISIBLE_CHAR_SET:
1885 if (g_value_get_boolean (value))
1886 priv->invisible_char_set = TRUE;
1888 gtk_entry_unset_invisible_char (entry);
1891 case PROP_CAPS_LOCK_WARNING:
1892 priv->caps_lock_warning = g_value_get_boolean (value);
1895 case PROP_PROGRESS_FRACTION:
1896 gtk_entry_set_progress_fraction (entry, g_value_get_double (value));
1899 case PROP_PROGRESS_PULSE_STEP:
1900 gtk_entry_set_progress_pulse_step (entry, g_value_get_double (value));
1903 case PROP_PIXBUF_PRIMARY:
1904 gtk_entry_set_icon_from_pixbuf (entry,
1905 GTK_ENTRY_ICON_PRIMARY,
1906 g_value_get_object (value));
1909 case PROP_PIXBUF_SECONDARY:
1910 gtk_entry_set_icon_from_pixbuf (entry,
1911 GTK_ENTRY_ICON_SECONDARY,
1912 g_value_get_object (value));
1915 case PROP_STOCK_PRIMARY:
1916 gtk_entry_set_icon_from_stock (entry,
1917 GTK_ENTRY_ICON_PRIMARY,
1918 g_value_get_string (value));
1921 case PROP_STOCK_SECONDARY:
1922 gtk_entry_set_icon_from_stock (entry,
1923 GTK_ENTRY_ICON_SECONDARY,
1924 g_value_get_string (value));
1927 case PROP_ICON_NAME_PRIMARY:
1928 gtk_entry_set_icon_from_icon_name (entry,
1929 GTK_ENTRY_ICON_PRIMARY,
1930 g_value_get_string (value));
1933 case PROP_ICON_NAME_SECONDARY:
1934 gtk_entry_set_icon_from_icon_name (entry,
1935 GTK_ENTRY_ICON_SECONDARY,
1936 g_value_get_string (value));
1939 case PROP_GICON_PRIMARY:
1940 gtk_entry_set_icon_from_gicon (entry,
1941 GTK_ENTRY_ICON_PRIMARY,
1942 g_value_get_object (value));
1945 case PROP_GICON_SECONDARY:
1946 gtk_entry_set_icon_from_gicon (entry,
1947 GTK_ENTRY_ICON_SECONDARY,
1948 g_value_get_object (value));
1951 case PROP_ACTIVATABLE_PRIMARY:
1952 gtk_entry_set_icon_activatable (entry,
1953 GTK_ENTRY_ICON_PRIMARY,
1954 g_value_get_boolean (value));
1957 case PROP_ACTIVATABLE_SECONDARY:
1958 gtk_entry_set_icon_activatable (entry,
1959 GTK_ENTRY_ICON_SECONDARY,
1960 g_value_get_boolean (value));
1963 case PROP_SENSITIVE_PRIMARY:
1964 gtk_entry_set_icon_sensitive (entry,
1965 GTK_ENTRY_ICON_PRIMARY,
1966 g_value_get_boolean (value));
1969 case PROP_SENSITIVE_SECONDARY:
1970 gtk_entry_set_icon_sensitive (entry,
1971 GTK_ENTRY_ICON_SECONDARY,
1972 g_value_get_boolean (value));
1975 case PROP_TOOLTIP_TEXT_PRIMARY:
1976 gtk_entry_set_icon_tooltip_text (entry,
1977 GTK_ENTRY_ICON_PRIMARY,
1978 g_value_get_string (value));
1981 case PROP_TOOLTIP_TEXT_SECONDARY:
1982 gtk_entry_set_icon_tooltip_text (entry,
1983 GTK_ENTRY_ICON_SECONDARY,
1984 g_value_get_string (value));
1987 case PROP_TOOLTIP_MARKUP_PRIMARY:
1988 gtk_entry_set_icon_tooltip_markup (entry,
1989 GTK_ENTRY_ICON_PRIMARY,
1990 g_value_get_string (value));
1993 case PROP_TOOLTIP_MARKUP_SECONDARY:
1994 gtk_entry_set_icon_tooltip_markup (entry,
1995 GTK_ENTRY_ICON_SECONDARY,
1996 g_value_get_string (value));
1999 case PROP_IM_MODULE:
2000 g_free (priv->im_module);
2001 priv->im_module = g_value_dup_string (value);
2002 if (GTK_IS_IM_MULTICONTEXT (entry->im_context))
2003 gtk_im_multicontext_set_context_id (GTK_IM_MULTICONTEXT (entry->im_context), priv->im_module);
2006 case PROP_EDITING_CANCELED:
2007 entry->editing_canceled = g_value_get_boolean (value);
2010 case PROP_SCROLL_OFFSET:
2011 case PROP_CURSOR_POSITION:
2013 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2019 gtk_entry_get_property (GObject *object,
2024 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (object);
2025 GtkEntry *entry = GTK_ENTRY (object);
2030 g_value_set_object (value, gtk_entry_get_buffer (entry));
2033 case PROP_CURSOR_POSITION:
2034 g_value_set_int (value, entry->current_pos);
2037 case PROP_SELECTION_BOUND:
2038 g_value_set_int (value, entry->selection_bound);
2042 g_value_set_boolean (value, entry->editable);
2045 case PROP_MAX_LENGTH:
2046 g_value_set_int (value, gtk_entry_buffer_get_max_length (get_buffer (entry)));
2049 case PROP_VISIBILITY:
2050 g_value_set_boolean (value, entry->visible);
2053 case PROP_HAS_FRAME:
2054 g_value_set_boolean (value, entry->has_frame);
2057 case PROP_INNER_BORDER:
2058 g_value_set_boxed (value, gtk_entry_get_inner_border (entry));
2061 case PROP_INVISIBLE_CHAR:
2062 g_value_set_uint (value, entry->invisible_char);
2065 case PROP_ACTIVATES_DEFAULT:
2066 g_value_set_boolean (value, entry->activates_default);
2069 case PROP_WIDTH_CHARS:
2070 g_value_set_int (value, entry->width_chars);
2073 case PROP_SCROLL_OFFSET:
2074 g_value_set_int (value, entry->scroll_offset);
2078 g_value_set_string (value, gtk_entry_get_text (entry));
2082 g_value_set_float (value, gtk_entry_get_alignment (entry));
2085 case PROP_TRUNCATE_MULTILINE:
2086 g_value_set_boolean (value, entry->truncate_multiline);
2089 case PROP_SHADOW_TYPE:
2090 g_value_set_enum (value, priv->shadow_type);
2093 case PROP_OVERWRITE_MODE:
2094 g_value_set_boolean (value, entry->overwrite_mode);
2097 case PROP_TEXT_LENGTH:
2098 g_value_set_uint (value, gtk_entry_buffer_get_length (get_buffer (entry)));
2101 case PROP_INVISIBLE_CHAR_SET:
2102 g_value_set_boolean (value, priv->invisible_char_set);
2105 case PROP_IM_MODULE:
2106 g_value_set_string (value, priv->im_module);
2109 case PROP_CAPS_LOCK_WARNING:
2110 g_value_set_boolean (value, priv->caps_lock_warning);
2113 case PROP_PROGRESS_FRACTION:
2114 g_value_set_double (value, priv->progress_fraction);
2117 case PROP_PROGRESS_PULSE_STEP:
2118 g_value_set_double (value, priv->progress_pulse_fraction);
2121 case PROP_PIXBUF_PRIMARY:
2122 g_value_set_object (value,
2123 gtk_entry_get_icon_pixbuf (entry,
2124 GTK_ENTRY_ICON_PRIMARY));
2127 case PROP_PIXBUF_SECONDARY:
2128 g_value_set_object (value,
2129 gtk_entry_get_icon_pixbuf (entry,
2130 GTK_ENTRY_ICON_SECONDARY));
2133 case PROP_STOCK_PRIMARY:
2134 g_value_set_string (value,
2135 gtk_entry_get_icon_stock (entry,
2136 GTK_ENTRY_ICON_PRIMARY));
2139 case PROP_STOCK_SECONDARY:
2140 g_value_set_string (value,
2141 gtk_entry_get_icon_stock (entry,
2142 GTK_ENTRY_ICON_SECONDARY));
2145 case PROP_ICON_NAME_PRIMARY:
2146 g_value_set_string (value,
2147 gtk_entry_get_icon_name (entry,
2148 GTK_ENTRY_ICON_PRIMARY));
2151 case PROP_ICON_NAME_SECONDARY:
2152 g_value_set_string (value,
2153 gtk_entry_get_icon_name (entry,
2154 GTK_ENTRY_ICON_SECONDARY));
2157 case PROP_GICON_PRIMARY:
2158 g_value_set_object (value,
2159 gtk_entry_get_icon_gicon (entry,
2160 GTK_ENTRY_ICON_PRIMARY));
2163 case PROP_GICON_SECONDARY:
2164 g_value_set_object (value,
2165 gtk_entry_get_icon_gicon (entry,
2166 GTK_ENTRY_ICON_SECONDARY));
2169 case PROP_STORAGE_TYPE_PRIMARY:
2170 g_value_set_enum (value,
2171 gtk_entry_get_icon_storage_type (entry,
2172 GTK_ENTRY_ICON_PRIMARY));
2175 case PROP_STORAGE_TYPE_SECONDARY:
2176 g_value_set_enum (value,
2177 gtk_entry_get_icon_storage_type (entry,
2178 GTK_ENTRY_ICON_SECONDARY));
2181 case PROP_ACTIVATABLE_PRIMARY:
2182 g_value_set_boolean (value,
2183 gtk_entry_get_icon_activatable (entry, GTK_ENTRY_ICON_PRIMARY));
2186 case PROP_ACTIVATABLE_SECONDARY:
2187 g_value_set_boolean (value,
2188 gtk_entry_get_icon_activatable (entry, GTK_ENTRY_ICON_SECONDARY));
2191 case PROP_SENSITIVE_PRIMARY:
2192 g_value_set_boolean (value,
2193 gtk_entry_get_icon_sensitive (entry, GTK_ENTRY_ICON_PRIMARY));
2196 case PROP_SENSITIVE_SECONDARY:
2197 g_value_set_boolean (value,
2198 gtk_entry_get_icon_sensitive (entry, GTK_ENTRY_ICON_SECONDARY));
2201 case PROP_TOOLTIP_TEXT_PRIMARY:
2202 g_value_take_string (value,
2203 gtk_entry_get_icon_tooltip_text (entry, GTK_ENTRY_ICON_PRIMARY));
2206 case PROP_TOOLTIP_TEXT_SECONDARY:
2207 g_value_take_string (value,
2208 gtk_entry_get_icon_tooltip_text (entry, GTK_ENTRY_ICON_SECONDARY));
2211 case PROP_TOOLTIP_MARKUP_PRIMARY:
2212 g_value_take_string (value,
2213 gtk_entry_get_icon_tooltip_markup (entry, GTK_ENTRY_ICON_PRIMARY));
2216 case PROP_TOOLTIP_MARKUP_SECONDARY:
2217 g_value_take_string (value,
2218 gtk_entry_get_icon_tooltip_markup (entry, GTK_ENTRY_ICON_SECONDARY));
2221 case PROP_EDITING_CANCELED:
2222 g_value_set_boolean (value,
2223 entry->editing_canceled);
2227 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2233 find_invisible_char (GtkWidget *widget)
2235 PangoLayout *layout;
2236 PangoAttrList *attr_list;
2238 gunichar invisible_chars [] = {
2240 0x25cf, /* BLACK CIRCLE */
2241 0x2022, /* BULLET */
2242 0x2731, /* HEAVY ASTERISK */
2243 0x273a /* SIXTEEN POINTED ASTERISK */
2246 if (gtk_widget_get_style (widget))
2247 gtk_widget_style_get (widget,
2248 "invisible-char", &invisible_chars[0],
2251 layout = gtk_widget_create_pango_layout (widget, NULL);
2253 attr_list = pango_attr_list_new ();
2254 pango_attr_list_insert (attr_list, pango_attr_fallback_new (FALSE));
2256 pango_layout_set_attributes (layout, attr_list);
2257 pango_attr_list_unref (attr_list);
2259 for (i = (invisible_chars[0] != 0 ? 0 : 1); i < G_N_ELEMENTS (invisible_chars); i++)
2261 gchar text[7] = { 0, };
2264 len = g_unichar_to_utf8 (invisible_chars[i], text);
2265 pango_layout_set_text (layout, text, len);
2267 count = pango_layout_get_unknown_glyphs_count (layout);
2271 g_object_unref (layout);
2272 return invisible_chars[i];
2276 g_object_unref (layout);
2282 gtk_entry_init (GtkEntry *entry)
2284 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2286 gtk_widget_set_can_focus (GTK_WIDGET (entry), TRUE);
2288 entry->editable = TRUE;
2289 entry->visible = TRUE;
2290 entry->invisible_char = find_invisible_char (GTK_WIDGET (entry));
2291 entry->dnd_position = -1;
2292 entry->width_chars = -1;
2293 entry->is_cell_renderer = FALSE;
2294 entry->editing_canceled = FALSE;
2295 entry->has_frame = TRUE;
2296 entry->truncate_multiline = FALSE;
2297 priv->shadow_type = GTK_SHADOW_IN;
2299 priv->caps_lock_warning = TRUE;
2300 priv->caps_lock_warning_shown = FALSE;
2301 priv->progress_fraction = 0.0;
2302 priv->progress_pulse_fraction = 0.1;
2304 gtk_drag_dest_set (GTK_WIDGET (entry),
2305 GTK_DEST_DEFAULT_HIGHLIGHT,
2307 GDK_ACTION_COPY | GDK_ACTION_MOVE);
2308 gtk_drag_dest_add_text_targets (GTK_WIDGET (entry));
2310 /* This object is completely private. No external entity can gain a reference
2311 * to it; so we create it here and destroy it in finalize().
2313 entry->im_context = gtk_im_multicontext_new ();
2315 g_signal_connect (entry->im_context, "commit",
2316 G_CALLBACK (gtk_entry_commit_cb), entry);
2317 g_signal_connect (entry->im_context, "preedit-changed",
2318 G_CALLBACK (gtk_entry_preedit_changed_cb), entry);
2319 g_signal_connect (entry->im_context, "retrieve-surrounding",
2320 G_CALLBACK (gtk_entry_retrieve_surrounding_cb), entry);
2321 g_signal_connect (entry->im_context, "delete-surrounding",
2322 G_CALLBACK (gtk_entry_delete_surrounding_cb), entry);
2327 get_icon_width (GtkEntry *entry,
2328 GtkEntryIconPosition icon_pos)
2330 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2331 EntryIconInfo *icon_info = priv->icons[icon_pos];
2333 GtkSettings *settings;
2334 gint menu_icon_width;
2336 if (!icon_info || icon_info->pixbuf == NULL)
2339 screen = gtk_widget_get_screen (GTK_WIDGET (entry));
2340 settings = gtk_settings_get_for_screen (screen);
2342 gtk_icon_size_lookup_for_settings (settings, GTK_ICON_SIZE_MENU,
2343 &menu_icon_width, NULL);
2345 return MAX (gdk_pixbuf_get_width (icon_info->pixbuf), menu_icon_width);
2349 get_icon_allocations (GtkEntry *entry,
2350 GtkAllocation *primary,
2351 GtkAllocation *secondary)
2354 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2355 gint x, y, width, height;
2357 get_text_area_size (entry, &x, &y, &width, &height);
2359 if (gtk_widget_has_focus (GTK_WIDGET (entry)) && !priv->interior_focus)
2360 y += priv->focus_width;
2363 primary->height = height;
2364 primary->width = get_icon_width (entry, GTK_ENTRY_ICON_PRIMARY);
2365 if (primary->width > 0)
2366 primary->width += 2 * priv->icon_margin;
2369 secondary->height = height;
2370 secondary->width = get_icon_width (entry, GTK_ENTRY_ICON_SECONDARY);
2371 if (secondary->width > 0)
2372 secondary->width += 2 * priv->icon_margin;
2374 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
2376 primary->x = x + width - primary->width;
2382 secondary->x = x + width - secondary->width;
2388 begin_change (GtkEntry *entry)
2390 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2392 priv->change_count++;
2396 end_change (GtkEntry *entry)
2398 GtkEditable *editable = GTK_EDITABLE (entry);
2399 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2401 g_return_if_fail (priv->change_count > 0);
2403 priv->change_count--;
2405 if (priv->change_count == 0)
2407 if (priv->real_changed)
2409 g_signal_emit_by_name (editable, "changed");
2410 priv->real_changed = FALSE;
2416 emit_changed (GtkEntry *entry)
2418 GtkEditable *editable = GTK_EDITABLE (entry);
2419 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2421 if (priv->change_count == 0)
2422 g_signal_emit_by_name (editable, "changed");
2424 priv->real_changed = TRUE;
2428 gtk_entry_destroy (GtkObject *object)
2430 GtkEntry *entry = GTK_ENTRY (object);
2432 entry->current_pos = entry->selection_bound = 0;
2433 _gtk_entry_reset_im_context (entry);
2434 gtk_entry_reset_layout (entry);
2436 if (entry->blink_timeout)
2438 g_source_remove (entry->blink_timeout);
2439 entry->blink_timeout = 0;
2442 if (entry->recompute_idle)
2444 g_source_remove (entry->recompute_idle);
2445 entry->recompute_idle = 0;
2448 GTK_OBJECT_CLASS (gtk_entry_parent_class)->destroy (object);
2452 gtk_entry_dispose (GObject *object)
2454 GtkEntry *entry = GTK_ENTRY (object);
2455 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2457 gtk_entry_set_icon_from_pixbuf (entry, GTK_ENTRY_ICON_PRIMARY, NULL);
2458 gtk_entry_set_icon_tooltip_markup (entry, GTK_ENTRY_ICON_PRIMARY, NULL);
2459 gtk_entry_set_icon_from_pixbuf (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
2460 gtk_entry_set_icon_tooltip_markup (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
2464 buffer_disconnect_signals (entry);
2465 g_object_unref (priv->buffer);
2466 priv->buffer = NULL;
2469 G_OBJECT_CLASS (gtk_entry_parent_class)->dispose (object);
2473 gtk_entry_finalize (GObject *object)
2475 GtkEntry *entry = GTK_ENTRY (object);
2476 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2477 EntryIconInfo *icon_info = NULL;
2480 for (i = 0; i < MAX_ICONS; i++)
2482 if ((icon_info = priv->icons[i]) != NULL)
2484 if (icon_info->target_list != NULL)
2486 gtk_target_list_unref (icon_info->target_list);
2487 icon_info->target_list = NULL;
2490 g_slice_free (EntryIconInfo, icon_info);
2491 priv->icons[i] = NULL;
2495 gtk_entry_set_completion (entry, NULL);
2497 if (entry->cached_layout)
2498 g_object_unref (entry->cached_layout);
2500 g_object_unref (entry->im_context);
2502 if (entry->blink_timeout)
2503 g_source_remove (entry->blink_timeout);
2505 if (entry->recompute_idle)
2506 g_source_remove (entry->recompute_idle);
2508 g_free (priv->im_module);
2510 G_OBJECT_CLASS (gtk_entry_parent_class)->finalize (object);
2514 gtk_entry_get_display_mode (GtkEntry *entry)
2516 GtkEntryPrivate *priv;
2518 return DISPLAY_NORMAL;
2519 priv = GTK_ENTRY_GET_PRIVATE (entry);
2520 if (entry->invisible_char == 0 && priv->invisible_char_set)
2521 return DISPLAY_BLANK;
2522 return DISPLAY_INVISIBLE;
2526 gtk_entry_get_display_text (GtkEntry *entry,
2530 GtkEntryPasswordHint *password_hint;
2531 GtkEntryPrivate *priv;
2532 gunichar invisible_char;
2542 priv = GTK_ENTRY_GET_PRIVATE (entry);
2543 text = gtk_entry_buffer_get_text (get_buffer (entry));
2544 length = gtk_entry_buffer_get_length (get_buffer (entry));
2548 if (start_pos > length)
2551 if (end_pos <= start_pos)
2552 return g_strdup ("");
2553 else if (entry->visible)
2555 start = g_utf8_offset_to_pointer (text, start_pos);
2556 end = g_utf8_offset_to_pointer (start, end_pos - start_pos);
2557 return g_strndup (start, end - start);
2561 str = g_string_sized_new (length * 2);
2563 /* Figure out what our invisible char is and encode it */
2564 if (!entry->invisible_char)
2565 invisible_char = priv->invisible_char_set ? ' ' : '*';
2567 invisible_char = entry->invisible_char;
2568 char_len = g_unichar_to_utf8 (invisible_char, char_str);
2571 * Add hidden characters for each character in the text
2572 * buffer. If there is a password hint, then keep that
2573 * character visible.
2576 password_hint = g_object_get_qdata (G_OBJECT (entry), quark_password_hint);
2577 for (i = start_pos; i < end_pos; ++i)
2579 if (password_hint && i == password_hint->position)
2581 start = g_utf8_offset_to_pointer (text, i);
2582 g_string_append_len (str, start, g_utf8_next_char (start) - start);
2586 g_string_append_len (str, char_str, char_len);
2590 return g_string_free (str, FALSE);
2596 update_cursors (GtkWidget *widget)
2598 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2599 EntryIconInfo *icon_info = NULL;
2600 GdkDisplay *display;
2604 for (i = 0; i < MAX_ICONS; i++)
2606 if ((icon_info = priv->icons[i]) != NULL)
2608 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
2609 gdk_window_show_unraised (icon_info->window);
2611 /* The icon windows are not children of the visible entry window,
2612 * thus we can't just inherit the xterm cursor. Slight complication
2613 * here is that for the entry, insensitive => arrow cursor, but for
2614 * an icon in a sensitive entry, insensitive => xterm cursor.
2616 if (gtk_widget_is_sensitive (widget) &&
2617 (icon_info->insensitive ||
2618 (icon_info->nonactivatable && icon_info->target_list == NULL)))
2620 display = gtk_widget_get_display (widget);
2621 cursor = gdk_cursor_new_for_display (display, GDK_XTERM);
2622 gdk_window_set_cursor (icon_info->window, cursor);
2623 gdk_cursor_unref (cursor);
2627 gdk_window_set_cursor (icon_info->window, NULL);
2634 realize_icon_info (GtkWidget *widget,
2635 GtkEntryIconPosition icon_pos)
2637 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2638 EntryIconInfo *icon_info = priv->icons[icon_pos];
2639 GdkWindowAttr attributes;
2640 gint attributes_mask;
2642 g_return_if_fail (icon_info != NULL);
2646 attributes.width = 1;
2647 attributes.height = 1;
2648 attributes.window_type = GDK_WINDOW_CHILD;
2649 attributes.wclass = GDK_INPUT_OUTPUT;
2650 attributes.visual = gtk_widget_get_visual (widget);
2651 attributes.event_mask = gtk_widget_get_events (widget);
2652 attributes.event_mask |= (GDK_EXPOSURE_MASK |
2653 GDK_BUTTON_PRESS_MASK |
2654 GDK_BUTTON_RELEASE_MASK |
2655 GDK_BUTTON1_MOTION_MASK |
2656 GDK_BUTTON3_MOTION_MASK |
2657 GDK_POINTER_MOTION_HINT_MASK |
2658 GDK_POINTER_MOTION_MASK |
2659 GDK_ENTER_NOTIFY_MASK |
2660 GDK_LEAVE_NOTIFY_MASK);
2661 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL;
2663 icon_info->window = gdk_window_new (gtk_widget_get_window (widget),
2666 gdk_window_set_user_data (icon_info->window, widget);
2667 gdk_window_set_background (icon_info->window,
2668 >k_widget_get_style (widget)->base[gtk_widget_get_state (widget)]);
2670 gtk_widget_queue_resize (widget);
2673 static EntryIconInfo*
2674 construct_icon_info (GtkWidget *widget,
2675 GtkEntryIconPosition icon_pos)
2677 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2678 EntryIconInfo *icon_info;
2680 g_return_val_if_fail (priv->icons[icon_pos] == NULL, NULL);
2682 icon_info = g_slice_new0 (EntryIconInfo);
2683 priv->icons[icon_pos] = icon_info;
2685 if (gtk_widget_get_realized (widget))
2686 realize_icon_info (widget, icon_pos);
2692 gtk_entry_map (GtkWidget *widget)
2694 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2695 EntryIconInfo *icon_info = NULL;
2698 GTK_WIDGET_CLASS (gtk_entry_parent_class)->map (widget);
2700 for (i = 0; i < MAX_ICONS; i++)
2702 if ((icon_info = priv->icons[i]) != NULL)
2704 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
2705 gdk_window_show (icon_info->window);
2709 update_cursors (widget);
2713 gtk_entry_unmap (GtkWidget *widget)
2715 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2716 EntryIconInfo *icon_info = NULL;
2719 for (i = 0; i < MAX_ICONS; i++)
2721 if ((icon_info = priv->icons[i]) != NULL)
2723 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
2724 gdk_window_hide (icon_info->window);
2728 GTK_WIDGET_CLASS (gtk_entry_parent_class)->unmap (widget);
2732 gtk_entry_realize (GtkWidget *widget)
2735 GtkEntryPrivate *priv;
2738 EntryIconInfo *icon_info;
2740 GdkWindowAttr attributes;
2741 gint attributes_mask;
2744 gtk_widget_set_realized (widget, TRUE);
2745 entry = GTK_ENTRY (widget);
2746 priv = GTK_ENTRY_GET_PRIVATE (entry);
2748 attributes.window_type = GDK_WINDOW_CHILD;
2750 get_widget_window_size (entry, &attributes.x, &attributes.y, &attributes.width, &attributes.height);
2752 attributes.wclass = GDK_INPUT_OUTPUT;
2753 attributes.visual = gtk_widget_get_visual (widget);
2754 attributes.event_mask = gtk_widget_get_events (widget);
2755 attributes.event_mask |= (GDK_EXPOSURE_MASK |
2756 GDK_BUTTON_PRESS_MASK |
2757 GDK_BUTTON_RELEASE_MASK |
2758 GDK_BUTTON1_MOTION_MASK |
2759 GDK_BUTTON3_MOTION_MASK |
2760 GDK_POINTER_MOTION_HINT_MASK |
2761 GDK_POINTER_MOTION_MASK |
2762 GDK_ENTER_NOTIFY_MASK |
2763 GDK_LEAVE_NOTIFY_MASK);
2764 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL;
2766 window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, attributes_mask);
2767 gtk_widget_set_window (widget, window);
2768 gdk_window_set_user_data (window, entry);
2770 get_text_area_size (entry, &attributes.x, &attributes.y, &attributes.width, &attributes.height);
2772 if (gtk_widget_is_sensitive (widget))
2774 attributes.cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
2775 attributes_mask |= GDK_WA_CURSOR;
2778 entry->text_area = gdk_window_new (window, &attributes, attributes_mask);
2780 gdk_window_set_user_data (entry->text_area, entry);
2782 if (attributes_mask & GDK_WA_CURSOR)
2783 gdk_cursor_unref (attributes.cursor);
2785 gtk_widget_style_attach (widget);
2787 style = gtk_widget_get_style (widget);
2788 state = gtk_widget_get_state (widget);
2789 gdk_window_set_background (window, &style->base[state]);
2790 gdk_window_set_background (entry->text_area, &style->base[state]);
2792 gdk_window_show (entry->text_area);
2794 gtk_im_context_set_client_window (entry->im_context, entry->text_area);
2796 gtk_entry_adjust_scroll (entry);
2797 gtk_entry_update_primary_selection (entry);
2800 /* If the icon positions are already setup, create their windows.
2801 * Otherwise if they don't exist yet, then construct_icon_info()
2802 * will create the windows once the widget is already realized.
2804 for (i = 0; i < MAX_ICONS; i++)
2806 if ((icon_info = priv->icons[i]) != NULL)
2808 if (icon_info->window == NULL)
2809 realize_icon_info (widget, i);
2815 gtk_entry_unrealize (GtkWidget *widget)
2817 GtkEntry *entry = GTK_ENTRY (widget);
2818 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2819 GtkClipboard *clipboard;
2820 EntryIconInfo *icon_info;
2823 gtk_entry_reset_layout (entry);
2825 gtk_im_context_set_client_window (entry->im_context, NULL);
2827 clipboard = gtk_widget_get_clipboard (widget, GDK_SELECTION_PRIMARY);
2828 if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (entry))
2829 gtk_clipboard_clear (clipboard);
2831 if (entry->text_area)
2833 gdk_window_set_user_data (entry->text_area, NULL);
2834 gdk_window_destroy (entry->text_area);
2835 entry->text_area = NULL;
2838 if (entry->popup_menu)
2840 gtk_widget_destroy (entry->popup_menu);
2841 entry->popup_menu = NULL;
2844 GTK_WIDGET_CLASS (gtk_entry_parent_class)->unrealize (widget);
2846 for (i = 0; i < MAX_ICONS; i++)
2848 if ((icon_info = priv->icons[i]) != NULL)
2850 if (icon_info->window != NULL)
2852 gdk_window_destroy (icon_info->window);
2853 icon_info->window = NULL;
2860 _gtk_entry_get_borders (GtkEntry *entry,
2864 GtkWidget *widget = GTK_WIDGET (entry);
2865 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2868 if (entry->has_frame)
2870 style = gtk_widget_get_style (widget);
2872 *xborder = style->xthickness;
2873 *yborder = style->ythickness;
2881 if (!priv->interior_focus)
2883 *xborder += priv->focus_width;
2884 *yborder += priv->focus_width;
2889 gtk_entry_size_request (GtkWidget *widget,
2890 GtkRequisition *requisition)
2892 GtkEntry *entry = GTK_ENTRY (widget);
2893 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2894 PangoFontMetrics *metrics;
2895 gint xborder, yborder;
2896 GtkBorder inner_border;
2897 PangoContext *context;
2898 int icon_widths = 0;
2901 gtk_widget_ensure_style (widget);
2902 context = gtk_widget_get_pango_context (widget);
2903 metrics = pango_context_get_metrics (context,
2904 gtk_widget_get_style (widget)->font_desc,
2905 pango_context_get_language (context));
2907 entry->ascent = pango_font_metrics_get_ascent (metrics);
2908 entry->descent = pango_font_metrics_get_descent (metrics);
2910 _gtk_entry_get_borders (entry, &xborder, &yborder);
2911 _gtk_entry_effective_inner_border (entry, &inner_border);
2913 if (entry->width_chars < 0)
2914 requisition->width = MIN_ENTRY_WIDTH + xborder * 2 + inner_border.left + inner_border.right;
2917 gint char_width = pango_font_metrics_get_approximate_char_width (metrics);
2918 gint digit_width = pango_font_metrics_get_approximate_digit_width (metrics);
2919 gint char_pixels = (MAX (char_width, digit_width) + PANGO_SCALE - 1) / PANGO_SCALE;
2921 requisition->width = char_pixels * entry->width_chars + xborder * 2 + inner_border.left + inner_border.right;
2924 requisition->height = PANGO_PIXELS (entry->ascent + entry->descent) + yborder * 2 + inner_border.top + inner_border.bottom;
2926 for (i = 0; i < MAX_ICONS; i++)
2928 icon_width = get_icon_width (entry, i);
2930 icon_widths += icon_width + 2 * priv->icon_margin;
2933 if (icon_widths > requisition->width)
2934 requisition->width += icon_widths;
2936 pango_font_metrics_unref (metrics);
2940 place_windows (GtkEntry *entry)
2942 GtkWidget *widget = GTK_WIDGET (entry);
2943 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2944 gint x, y, width, height;
2945 GtkAllocation primary;
2946 GtkAllocation secondary;
2947 EntryIconInfo *icon_info = NULL;
2949 get_text_area_size (entry, &x, &y, &width, &height);
2950 get_icon_allocations (entry, &primary, &secondary);
2952 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
2953 y += priv->focus_width;
2955 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
2956 x += secondary.width;
2959 width -= primary.width + secondary.width;
2961 if ((icon_info = priv->icons[GTK_ENTRY_ICON_PRIMARY]) != NULL)
2962 gdk_window_move_resize (icon_info->window,
2963 primary.x, primary.y,
2964 primary.width, primary.height);
2966 if ((icon_info = priv->icons[GTK_ENTRY_ICON_SECONDARY]) != NULL)
2967 gdk_window_move_resize (icon_info->window,
2968 secondary.x, secondary.y,
2969 secondary.width, secondary.height);
2971 gdk_window_move_resize (entry->text_area, x, y, width, height);
2975 gtk_entry_get_text_area_size (GtkEntry *entry,
2981 GtkWidget *widget = GTK_WIDGET (entry);
2982 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2983 GtkAllocation allocation;
2984 GtkRequisition requisition;
2986 gint xborder, yborder;
2988 gtk_widget_get_preferred_size (widget, &requisition, NULL);
2989 gtk_widget_get_allocation (widget, &allocation);
2990 _gtk_entry_get_borders (entry, &xborder, &yborder);
2992 if (gtk_widget_get_realized (widget))
2993 frame_height = gdk_window_get_height (gtk_widget_get_window (widget));
2995 frame_height = requisition.height;
2997 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
2998 frame_height -= 2 * priv->focus_width;
3004 *y = frame_height / 2 - (requisition.height - yborder * 2) / 2;
3007 *width = allocation.width - xborder * 2;
3010 *height = requisition.height - yborder * 2;
3014 get_text_area_size (GtkEntry *entry,
3020 GtkEntryClass *class;
3022 g_return_if_fail (GTK_IS_ENTRY (entry));
3024 class = GTK_ENTRY_GET_CLASS (entry);
3026 if (class->get_text_area_size)
3027 class->get_text_area_size (entry, x, y, width, height);
3032 get_widget_window_size (GtkEntry *entry,
3038 GtkAllocation allocation;
3039 GtkRequisition requisition;
3040 GtkWidget *widget = GTK_WIDGET (entry);
3042 gtk_widget_get_preferred_size (widget, &requisition, NULL);
3043 gtk_widget_get_allocation (widget, &allocation);
3050 if (entry->is_cell_renderer)
3053 *y = allocation.y + (allocation.height - requisition.height) / 2;
3057 *width = allocation.width;
3061 if (entry->is_cell_renderer)
3062 *height = allocation.height;
3064 *height = requisition.height;
3069 _gtk_entry_effective_inner_border (GtkEntry *entry,
3072 GtkBorder *tmp_border;
3074 tmp_border = g_object_get_qdata (G_OBJECT (entry), quark_inner_border);
3078 *border = *tmp_border;
3082 gtk_widget_style_get (GTK_WIDGET (entry), "inner-border", &tmp_border, NULL);
3086 *border = *tmp_border;
3087 gtk_border_free (tmp_border);
3091 *border = default_inner_border;
3095 gtk_entry_size_allocate (GtkWidget *widget,
3096 GtkAllocation *allocation)
3098 GtkEntry *entry = GTK_ENTRY (widget);
3100 gtk_widget_set_allocation (widget, allocation);
3102 if (gtk_widget_get_realized (widget))
3104 gint x, y, width, height;
3105 GtkEntryCompletion* completion;
3107 get_widget_window_size (entry, &x, &y, &width, &height);
3108 gdk_window_move_resize (gtk_widget_get_window (widget),
3109 x, y, width, height);
3111 place_windows (entry);
3112 gtk_entry_recompute (entry);
3114 completion = gtk_entry_get_completion (entry);
3115 if (completion && gtk_widget_get_mapped (completion->priv->popup_window))
3116 _gtk_entry_completion_resize_popup (completion);
3120 /* Kudos to the gnome-panel guys. */
3122 colorshift_pixbuf (GdkPixbuf *dest,
3127 gint width, height, has_alpha, src_rowstride, dest_rowstride;
3128 guchar *target_pixels;
3129 guchar *original_pixels;
3135 has_alpha = gdk_pixbuf_get_has_alpha (src);
3136 width = gdk_pixbuf_get_width (src);
3137 height = gdk_pixbuf_get_height (src);
3138 src_rowstride = gdk_pixbuf_get_rowstride (src);
3139 dest_rowstride = gdk_pixbuf_get_rowstride (dest);
3140 original_pixels = gdk_pixbuf_get_pixels (src);
3141 target_pixels = gdk_pixbuf_get_pixels (dest);
3143 for (i = 0; i < height; i++)
3145 pix_dest = target_pixels + i * dest_rowstride;
3146 pix_src = original_pixels + i * src_rowstride;
3148 for (j = 0; j < width; j++)
3155 *(pix_dest++) = CLAMP (val, 0, 255);
3158 *(pix_dest++) = CLAMP (val, 0, 255);
3161 *(pix_dest++) = CLAMP (val, 0, 255);
3164 *(pix_dest++) = *(pix_src++);
3170 should_prelight (GtkEntry *entry,
3171 GtkEntryIconPosition icon_pos)
3173 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3174 EntryIconInfo *icon_info = priv->icons[icon_pos];
3180 if (icon_info->nonactivatable && icon_info->target_list == NULL)
3183 if (icon_info->pressed)
3186 gtk_widget_style_get (GTK_WIDGET (entry),
3187 "icon-prelight", &prelight,
3194 draw_icon (GtkWidget *widget,
3196 GtkEntryIconPosition icon_pos)
3198 GtkEntry *entry = GTK_ENTRY (widget);
3199 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3200 EntryIconInfo *icon_info = priv->icons[icon_pos];
3202 gint x, y, width, height;
3207 gtk_entry_ensure_pixbuf (entry, icon_pos);
3209 if (icon_info->pixbuf == NULL)
3212 width = gdk_window_get_width (icon_info->window);
3213 height = gdk_window_get_height (icon_info->window);
3215 /* size_allocate hasn't been called yet. These are the default values.
3217 if (width == 1 || height == 1)
3220 pixbuf = icon_info->pixbuf;
3221 g_object_ref (pixbuf);
3223 if (gdk_pixbuf_get_height (pixbuf) > height)
3225 GdkPixbuf *temp_pixbuf;
3228 scale = height - 2 * priv->icon_margin;
3229 temp_pixbuf = gdk_pixbuf_scale_simple (pixbuf, scale, scale,
3230 GDK_INTERP_BILINEAR);
3231 g_object_unref (pixbuf);
3232 pixbuf = temp_pixbuf;
3235 x = (width - gdk_pixbuf_get_width (pixbuf)) / 2;
3236 y = (height - gdk_pixbuf_get_height (pixbuf)) / 2;
3238 if (!gtk_widget_is_sensitive (widget) ||
3239 icon_info->insensitive)
3241 GdkPixbuf *temp_pixbuf;
3243 temp_pixbuf = gdk_pixbuf_copy (pixbuf);
3244 gdk_pixbuf_saturate_and_pixelate (pixbuf,
3248 g_object_unref (pixbuf);
3249 pixbuf = temp_pixbuf;
3251 else if (icon_info->prelight)
3253 GdkPixbuf *temp_pixbuf;
3255 temp_pixbuf = gdk_pixbuf_copy (pixbuf);
3256 colorshift_pixbuf (temp_pixbuf, pixbuf, 30);
3257 g_object_unref (pixbuf);
3258 pixbuf = temp_pixbuf;
3261 gdk_cairo_set_source_pixbuf (cr, pixbuf, x, y);
3264 g_object_unref (pixbuf);
3269 gtk_entry_draw_frame (GtkWidget *widget,
3272 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
3275 gint x = 0, y = 0, width, height;
3278 window = gtk_widget_get_window (widget);
3280 width = gdk_window_get_width (window);
3281 height = gdk_window_get_height (window);
3283 /* Fix a problem with some themes which assume that entry->text_area's
3284 * width equals widget->window's width
3285 * http://bugzilla.gnome.org/show_bug.cgi?id=466000 */
3286 if (GTK_IS_SPIN_BUTTON (widget))
3288 gint xborder, yborder;
3290 gtk_entry_get_text_area_size (GTK_ENTRY (widget), &x, NULL, &width, NULL);
3291 _gtk_entry_get_borders (GTK_ENTRY (widget), &xborder, &yborder);
3294 width += xborder * 2;
3297 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3299 x += priv->focus_width;
3300 y += priv->focus_width;
3301 width -= 2 * priv->focus_width;
3302 height -= 2 * priv->focus_width;
3305 style = gtk_widget_get_style (widget);
3306 state = gtk_widget_has_focus (widget) ?
3307 GTK_STATE_ACTIVE : gtk_widget_get_state (widget);
3309 gtk_paint_shadow (style, cr,
3310 state, priv->shadow_type,
3311 widget, "entry", x, y, width, height);
3314 gtk_entry_draw_progress (widget, cr, window);
3316 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3318 x -= priv->focus_width;
3319 y -= priv->focus_width;
3320 width += 2 * priv->focus_width;
3321 height += 2 * priv->focus_width;
3323 gtk_paint_focus (style, cr,
3324 gtk_widget_get_state (widget),
3326 0, 0, width, height);
3331 gtk_entry_get_progress_border (GtkWidget *widget,
3332 GtkBorder *progress_border)
3334 GtkBorder *tmp_border;
3337 gtk_widget_style_get (widget, "progress-border", &tmp_border, NULL);
3340 *progress_border = *tmp_border;
3341 gtk_border_free (tmp_border);
3345 style = gtk_widget_get_style (widget);
3347 progress_border->left = style->xthickness;
3348 progress_border->right = style->xthickness;
3349 progress_border->top = style->ythickness;
3350 progress_border->bottom = style->ythickness;
3355 get_progress_area (GtkWidget *widget,
3361 GtkEntryPrivate *private = GTK_ENTRY_GET_PRIVATE (widget);
3362 GtkEntry *entry = GTK_ENTRY (widget);
3363 GtkBorder progress_border;
3365 gtk_entry_get_progress_border (widget, &progress_border);
3367 *x = progress_border.left;
3368 *y = progress_border.top;
3370 *width = gdk_window_get_width (gtk_widget_get_window (widget))
3371 - progress_border.left - progress_border.right;
3372 *height = gdk_window_get_height (gtk_widget_get_window (widget))
3373 - progress_border.top - progress_border.bottom;
3375 if (gtk_widget_has_focus (widget) && !private->interior_focus)
3377 *x += private->focus_width;
3378 *y += private->focus_width;
3379 *width -= 2 * private->focus_width;
3380 *height -= 2 * private->focus_width;
3383 if (private->progress_pulse_mode)
3385 gdouble value = private->progress_pulse_current;
3387 *x += (gint) floor(value * (*width));
3388 *width = (gint) ceil(private->progress_pulse_fraction * (*width));
3390 else if (private->progress_fraction > 0)
3392 gdouble value = private->progress_fraction;
3394 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
3398 bar_width = floor(value * (*width) + 0.5);
3399 *x += *width - bar_width;
3404 *width = (gint) floor(value * (*width) + 0.5);
3415 gtk_entry_draw_progress (GtkWidget *widget,
3419 gint x, y, width, height;
3422 get_progress_area (widget, &x, &y, &width, &height);
3424 if ((width <= 0) || (height <= 0))
3427 if (window != gtk_widget_get_window (widget))
3431 gdk_window_get_position (window, &pos_x, &pos_y);
3437 state = GTK_STATE_SELECTED;
3438 if (!gtk_widget_get_sensitive (widget))
3439 state = GTK_STATE_INSENSITIVE;
3441 gtk_paint_box (gtk_widget_get_style (widget), cr,
3442 state, GTK_SHADOW_OUT,
3443 widget, "entry-progress",
3449 gtk_entry_draw (GtkWidget *widget,
3452 GtkEntry *entry = GTK_ENTRY (widget);
3455 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3458 style = gtk_widget_get_style (widget);
3460 state = gtk_widget_has_focus (widget) ?
3461 GTK_STATE_ACTIVE : gtk_widget_get_state (widget);
3463 if (gtk_cairo_should_draw_window (cr, gtk_widget_get_window (widget)))
3464 gtk_entry_draw_frame (widget, cr);
3466 if (gtk_cairo_should_draw_window (cr, entry->text_area))
3472 gdk_window_get_position (entry->text_area, &x, &y);
3473 cairo_translate (cr, x, y);
3475 gtk_paint_flat_box (style, cr,
3476 state, GTK_SHADOW_NONE,
3479 gdk_window_get_width (entry->text_area),
3480 gdk_window_get_height (entry->text_area));
3482 gtk_entry_draw_progress (widget, cr, entry->text_area);
3484 if (entry->dnd_position != -1)
3485 gtk_entry_draw_cursor (GTK_ENTRY (widget), cr, CURSOR_DND);
3487 gtk_entry_draw_text (GTK_ENTRY (widget), cr);
3489 /* When no text is being displayed at all, don't show the cursor */
3490 if (gtk_entry_get_display_mode (entry) != DISPLAY_BLANK &&
3491 gtk_widget_has_focus (widget) &&
3492 entry->selection_bound == entry->current_pos && entry->cursor_visible)
3493 gtk_entry_draw_cursor (GTK_ENTRY (widget), cr, CURSOR_STANDARD);
3498 for (i = 0; i < MAX_ICONS; i++)
3500 EntryIconInfo *icon_info = priv->icons[i];
3502 if (icon_info != NULL && gtk_cairo_should_draw_window (cr, icon_info->window))
3508 gdk_window_get_position (icon_info->window, &x, &y);
3509 cairo_translate (cr, x, y);
3511 gtk_paint_flat_box (style, cr,
3512 state, GTK_SHADOW_NONE,
3515 gdk_window_get_width (icon_info->window),
3516 gdk_window_get_height (icon_info->window));
3518 gtk_entry_draw_progress (widget, cr, icon_info->window);
3519 draw_icon (widget, cr, i);
3531 gtk_entry_enter_notify (GtkWidget *widget,
3532 GdkEventCrossing *event)
3534 GtkEntry *entry = GTK_ENTRY (widget);
3535 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3538 for (i = 0; i < MAX_ICONS; i++)
3540 EntryIconInfo *icon_info = priv->icons[i];
3542 if (icon_info != NULL && event->window == icon_info->window)
3544 if (should_prelight (entry, i))
3546 icon_info->prelight = TRUE;
3547 gtk_widget_queue_draw (widget);
3558 gtk_entry_leave_notify (GtkWidget *widget,
3559 GdkEventCrossing *event)
3561 GtkEntry *entry = GTK_ENTRY (widget);
3562 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3565 for (i = 0; i < MAX_ICONS; i++)
3567 EntryIconInfo *icon_info = priv->icons[i];
3569 if (icon_info != NULL && event->window == icon_info->window)
3571 /* a grab means that we may never see the button release */
3572 if (event->mode == GDK_CROSSING_GRAB || event->mode == GDK_CROSSING_GTK_GRAB)
3573 icon_info->pressed = FALSE;
3575 if (should_prelight (entry, i))
3577 icon_info->prelight = FALSE;
3578 gtk_widget_queue_draw (widget);
3589 gtk_entry_get_pixel_ranges (GtkEntry *entry,
3593 gint start_char, end_char;
3595 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start_char, &end_char))
3597 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
3598 PangoLayoutLine *line = pango_layout_get_lines_readonly (layout)->data;
3599 const char *text = pango_layout_get_text (layout);
3600 gint start_index = g_utf8_offset_to_pointer (text, start_char) - text;
3601 gint end_index = g_utf8_offset_to_pointer (text, end_char) - text;
3602 gint real_n_ranges, i;
3604 pango_layout_line_get_x_ranges (line, start_index, end_index, ranges, &real_n_ranges);
3610 for (i = 0; i < real_n_ranges; ++i)
3612 r[2 * i + 1] = (r[2 * i + 1] - r[2 * i]) / PANGO_SCALE;
3613 r[2 * i] = r[2 * i] / PANGO_SCALE;
3618 *n_ranges = real_n_ranges;
3630 in_selection (GtkEntry *entry,
3635 gint retval = FALSE;
3637 gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
3639 for (i = 0; i < n_ranges; ++i)
3641 if (x >= ranges[2 * i] && x < ranges[2 * i] + ranges[2 * i + 1])
3653 gtk_entry_button_press (GtkWidget *widget,
3654 GdkEventButton *event)
3656 GtkEntry *entry = GTK_ENTRY (widget);
3657 GtkEditable *editable = GTK_EDITABLE (widget);
3658 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3659 EntryIconInfo *icon_info = NULL;
3661 gint sel_start, sel_end;
3664 for (i = 0; i < MAX_ICONS; i++)
3666 icon_info = priv->icons[i];
3668 if (!icon_info || icon_info->insensitive)
3671 if (event->window == icon_info->window)
3673 if (should_prelight (entry, i))
3675 icon_info->prelight = FALSE;
3676 gtk_widget_queue_draw (widget);
3679 priv->start_x = event->x;
3680 priv->start_y = event->y;
3681 icon_info->pressed = TRUE;
3683 if (!icon_info->nonactivatable)
3684 g_signal_emit (entry, signals[ICON_PRESS], 0, i, event);
3690 if (event->window != entry->text_area ||
3691 (entry->button && event->button != entry->button))
3694 gtk_entry_reset_blink_time (entry);
3696 entry->button = event->button;
3698 if (!gtk_widget_has_focus (widget))
3700 entry->in_click = TRUE;
3701 gtk_widget_grab_focus (widget);
3702 entry->in_click = FALSE;
3705 tmp_pos = gtk_entry_find_position (entry, event->x + entry->scroll_offset);
3707 if (event->button == 1)
3709 gboolean have_selection = gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end);
3711 entry->select_words = FALSE;
3712 entry->select_lines = FALSE;
3714 if (event->state & GDK_SHIFT_MASK)
3716 _gtk_entry_reset_im_context (entry);
3718 if (!have_selection) /* select from the current position to the clicked position */
3719 sel_start = sel_end = entry->current_pos;
3721 if (tmp_pos > sel_start && tmp_pos < sel_end)
3723 /* Truncate current selection, but keep it as big as possible */
3724 if (tmp_pos - sel_start > sel_end - tmp_pos)
3725 gtk_entry_set_positions (entry, sel_start, tmp_pos);
3727 gtk_entry_set_positions (entry, tmp_pos, sel_end);
3731 gboolean extend_to_left;
3734 /* Figure out what click selects and extend current selection */
3735 switch (event->type)
3737 case GDK_BUTTON_PRESS:
3738 gtk_entry_set_positions (entry, tmp_pos, tmp_pos);
3741 case GDK_2BUTTON_PRESS:
3742 entry->select_words = TRUE;
3743 gtk_entry_select_word (entry);
3746 case GDK_3BUTTON_PRESS:
3747 entry->select_lines = TRUE;
3748 gtk_entry_select_line (entry);
3755 start = MIN (entry->current_pos, entry->selection_bound);
3756 start = MIN (sel_start, start);
3758 end = MAX (entry->current_pos, entry->selection_bound);
3759 end = MAX (sel_end, end);
3761 if (tmp_pos == sel_start || tmp_pos == sel_end)
3762 extend_to_left = (tmp_pos == start);
3764 extend_to_left = (end == sel_end);
3767 gtk_entry_set_positions (entry, start, end);
3769 gtk_entry_set_positions (entry, end, start);
3772 else /* no shift key */
3773 switch (event->type)
3775 case GDK_BUTTON_PRESS:
3776 if (in_selection (entry, event->x + entry->scroll_offset))
3778 /* Click inside the selection - we'll either start a drag, or
3779 * clear the selection
3781 entry->in_drag = TRUE;
3782 entry->drag_start_x = event->x + entry->scroll_offset;
3783 entry->drag_start_y = event->y;
3786 gtk_editable_set_position (editable, tmp_pos);
3789 case GDK_2BUTTON_PRESS:
3790 /* We ALWAYS receive a GDK_BUTTON_PRESS immediately before
3791 * receiving a GDK_2BUTTON_PRESS so we need to reset
3792 * entry->in_drag which may have been set above
3794 entry->in_drag = FALSE;
3795 entry->select_words = TRUE;
3796 gtk_entry_select_word (entry);
3799 case GDK_3BUTTON_PRESS:
3800 /* We ALWAYS receive a GDK_BUTTON_PRESS immediately before
3801 * receiving a GDK_3BUTTON_PRESS so we need to reset
3802 * entry->in_drag which may have been set above
3804 entry->in_drag = FALSE;
3805 entry->select_lines = TRUE;
3806 gtk_entry_select_line (entry);
3815 else if (event->button == 2 && event->type == GDK_BUTTON_PRESS)
3817 if (entry->editable)
3819 priv->insert_pos = tmp_pos;
3820 gtk_entry_paste (entry, GDK_SELECTION_PRIMARY);
3825 gtk_widget_error_bell (widget);
3828 else if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
3830 gtk_entry_do_popup (entry, event);
3831 entry->button = 0; /* Don't wait for release, since the menu will gtk_grab_add */
3840 gtk_entry_button_release (GtkWidget *widget,
3841 GdkEventButton *event)
3843 GtkEntry *entry = GTK_ENTRY (widget);
3844 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
3845 EntryIconInfo *icon_info = NULL;
3848 for (i = 0; i < MAX_ICONS; i++)
3850 icon_info = priv->icons[i];
3852 if (!icon_info || icon_info->insensitive)
3855 if (event->window == icon_info->window)
3857 icon_info->pressed = FALSE;
3859 if (should_prelight (entry, i) &&
3860 event->x >= 0 && event->y >= 0 &&
3861 event->x < gdk_window_get_width (icon_info->window) &&
3862 event->y < gdk_window_get_height (icon_info->window))
3864 icon_info->prelight = TRUE;
3865 gtk_widget_queue_draw (widget);
3868 if (!icon_info->nonactivatable)
3869 g_signal_emit (entry, signals[ICON_RELEASE], 0, i, event);
3875 if (event->window != entry->text_area || entry->button != event->button)
3880 gint tmp_pos = gtk_entry_find_position (entry, entry->drag_start_x);
3882 gtk_editable_set_position (GTK_EDITABLE (entry), tmp_pos);
3889 gtk_entry_update_primary_selection (entry);
3895 _gtk_entry_get_selected_text (GtkEntry *entry)
3897 GtkEditable *editable = GTK_EDITABLE (entry);
3898 gint start_text, end_text;
3901 if (gtk_editable_get_selection_bounds (editable, &start_text, &end_text))
3902 text = gtk_editable_get_chars (editable, start_text, end_text);
3908 gtk_entry_motion_notify (GtkWidget *widget,
3909 GdkEventMotion *event)
3911 GtkEntry *entry = GTK_ENTRY (widget);
3912 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3913 EntryIconInfo *icon_info = NULL;
3914 GdkDragContext *context;
3918 for (i = 0; i < MAX_ICONS; i++)
3920 icon_info = priv->icons[i];
3922 if (!icon_info || icon_info->insensitive)
3925 if (event->window == icon_info->window)
3927 if (icon_info->pressed &&
3928 icon_info->target_list != NULL &&
3929 gtk_drag_check_threshold (widget,
3935 icon_info->in_drag = TRUE;
3936 icon_info->pressed = FALSE;
3937 context = gtk_drag_begin (widget,
3938 icon_info->target_list,
3948 if (entry->mouse_cursor_obscured)
3952 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
3953 gdk_window_set_cursor (entry->text_area, cursor);
3954 gdk_cursor_unref (cursor);
3955 entry->mouse_cursor_obscured = FALSE;
3958 if (event->window != entry->text_area || entry->button != 1)
3961 if (entry->select_lines)
3964 gdk_event_request_motions (event);
3968 if (gtk_entry_get_display_mode (entry) == DISPLAY_NORMAL &&
3969 gtk_drag_check_threshold (widget,
3970 entry->drag_start_x, entry->drag_start_y,
3971 event->x + entry->scroll_offset, event->y))
3973 GdkDragContext *context;
3974 GtkTargetList *target_list = gtk_target_list_new (NULL, 0);
3975 guint actions = entry->editable ? GDK_ACTION_COPY | GDK_ACTION_MOVE : GDK_ACTION_COPY;
3977 cairo_surface_t *surface;
3979 gtk_target_list_add_text_targets (target_list, 0);
3981 text = _gtk_entry_get_selected_text (entry);
3982 surface = _gtk_text_util_create_drag_icon (widget, text, -1);
3984 context = gtk_drag_begin (widget, target_list, actions,
3985 entry->button, (GdkEvent *)event);
3988 gtk_drag_set_icon_surface (context, surface);
3990 gtk_drag_set_icon_default (context);
3993 cairo_surface_destroy (surface);
3996 entry->in_drag = FALSE;
3999 gtk_target_list_unref (target_list);
4006 else if (event->y >= gdk_window_get_height (entry->text_area))
4007 tmp_pos = gtk_entry_buffer_get_length (get_buffer (entry));
4009 tmp_pos = gtk_entry_find_position (entry, event->x + entry->scroll_offset);
4011 if (entry->select_words)
4014 gint old_min, old_max;
4017 min = gtk_entry_move_backward_word (entry, tmp_pos, TRUE);
4018 max = gtk_entry_move_forward_word (entry, tmp_pos, TRUE);
4020 pos = entry->current_pos;
4021 bound = entry->selection_bound;
4023 old_min = MIN(entry->current_pos, entry->selection_bound);
4024 old_max = MAX(entry->current_pos, entry->selection_bound);
4031 else if (old_max < max)
4036 else if (pos == old_min)
4038 if (entry->current_pos != min)
4043 if (entry->current_pos != max)
4047 gtk_entry_set_positions (entry, pos, bound);
4050 gtk_entry_set_positions (entry, tmp_pos, -1);
4057 set_invisible_cursor (GdkWindow *window)
4059 GdkDisplay *display;
4062 display = gdk_window_get_display (window);
4063 cursor = gdk_cursor_new_for_display (display, GDK_BLANK_CURSOR);
4065 gdk_window_set_cursor (window, cursor);
4067 gdk_cursor_unref (cursor);
4071 gtk_entry_obscure_mouse_cursor (GtkEntry *entry)
4073 if (entry->mouse_cursor_obscured)
4076 set_invisible_cursor (entry->text_area);
4078 entry->mouse_cursor_obscured = TRUE;
4082 gtk_entry_key_press (GtkWidget *widget,
4085 GtkEntry *entry = GTK_ENTRY (widget);
4087 gtk_entry_reset_blink_time (entry);
4088 gtk_entry_pend_cursor_blink (entry);
4090 if (entry->editable)
4092 if (gtk_im_context_filter_keypress (entry->im_context, event))
4094 gtk_entry_obscure_mouse_cursor (entry);
4095 entry->need_im_reset = TRUE;
4100 if (event->keyval == GDK_KEY_Return ||
4101 event->keyval == GDK_KEY_KP_Enter ||
4102 event->keyval == GDK_KEY_ISO_Enter ||
4103 event->keyval == GDK_KEY_Escape)
4105 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
4107 if (completion && completion->priv->completion_timeout)
4109 g_source_remove (completion->priv->completion_timeout);
4110 completion->priv->completion_timeout = 0;
4113 _gtk_entry_reset_im_context (entry);
4116 if (GTK_WIDGET_CLASS (gtk_entry_parent_class)->key_press_event (widget, event))
4117 /* Activate key bindings
4121 if (!entry->editable && event->length)
4122 gtk_widget_error_bell (widget);
4128 gtk_entry_key_release (GtkWidget *widget,
4131 GtkEntry *entry = GTK_ENTRY (widget);
4133 if (entry->editable)
4135 if (gtk_im_context_filter_keypress (entry->im_context, event))
4137 entry->need_im_reset = TRUE;
4142 return GTK_WIDGET_CLASS (gtk_entry_parent_class)->key_release_event (widget, event);
4146 gtk_entry_focus_in (GtkWidget *widget,
4147 GdkEventFocus *event)
4149 GtkEntry *entry = GTK_ENTRY (widget);
4152 gtk_widget_queue_draw (widget);
4154 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (widget));
4156 if (entry->editable)
4158 entry->need_im_reset = TRUE;
4159 gtk_im_context_focus_in (entry->im_context);
4160 keymap_state_changed (keymap, entry);
4161 g_signal_connect (keymap, "state-changed",
4162 G_CALLBACK (keymap_state_changed), entry);
4165 g_signal_connect (keymap, "direction-changed",
4166 G_CALLBACK (keymap_direction_changed), entry);
4168 gtk_entry_reset_blink_time (entry);
4169 gtk_entry_check_cursor_blink (entry);
4175 gtk_entry_focus_out (GtkWidget *widget,
4176 GdkEventFocus *event)
4178 GtkEntry *entry = GTK_ENTRY (widget);
4179 GtkEntryCompletion *completion;
4182 gtk_widget_queue_draw (widget);
4184 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (widget));
4186 if (entry->editable)
4188 entry->need_im_reset = TRUE;
4189 gtk_im_context_focus_out (entry->im_context);
4190 remove_capslock_feedback (entry);
4193 gtk_entry_check_cursor_blink (entry);
4195 g_signal_handlers_disconnect_by_func (keymap, keymap_state_changed, entry);
4196 g_signal_handlers_disconnect_by_func (keymap, keymap_direction_changed, entry);
4198 completion = gtk_entry_get_completion (entry);
4200 _gtk_entry_completion_popdown (completion);
4206 gtk_entry_grab_focus (GtkWidget *widget)
4208 GtkEntry *entry = GTK_ENTRY (widget);
4209 gboolean select_on_focus;
4211 GTK_WIDGET_CLASS (gtk_entry_parent_class)->grab_focus (widget);
4213 if (entry->editable && !entry->in_click)
4215 g_object_get (gtk_widget_get_settings (widget),
4216 "gtk-entry-select-on-focus",
4220 if (select_on_focus)
4221 gtk_editable_select_region (GTK_EDITABLE (widget), 0, -1);
4226 gtk_entry_direction_changed (GtkWidget *widget,
4227 GtkTextDirection previous_dir)
4229 GtkEntry *entry = GTK_ENTRY (widget);
4231 gtk_entry_recompute (entry);
4233 GTK_WIDGET_CLASS (gtk_entry_parent_class)->direction_changed (widget, previous_dir);
4237 gtk_entry_state_changed (GtkWidget *widget,
4238 GtkStateType previous_state)
4240 GtkEntry *entry = GTK_ENTRY (widget);
4241 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
4245 if (gtk_widget_get_realized (widget))
4250 style = gtk_widget_get_style (widget);
4251 state = gtk_widget_get_state (widget);
4253 gdk_window_set_background (gtk_widget_get_window (widget),
4254 &style->base[state]);
4255 gdk_window_set_background (entry->text_area,
4256 &style->base[state]);
4257 for (i = 0; i < MAX_ICONS; i++)
4259 EntryIconInfo *icon_info = priv->icons[i];
4260 if (icon_info && icon_info->window)
4261 gdk_window_set_background (icon_info->window,
4262 &style->base[state]);
4265 if (gtk_widget_is_sensitive (widget))
4266 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
4270 gdk_window_set_cursor (entry->text_area, cursor);
4273 gdk_cursor_unref (cursor);
4275 entry->mouse_cursor_obscured = FALSE;
4277 update_cursors (widget);
4280 if (!gtk_widget_is_sensitive (widget))
4282 /* Clear any selection */
4283 gtk_editable_select_region (GTK_EDITABLE (entry), entry->current_pos, entry->current_pos);
4286 gtk_widget_queue_draw (widget);
4290 gtk_entry_screen_changed (GtkWidget *widget,
4291 GdkScreen *old_screen)
4293 gtk_entry_recompute (GTK_ENTRY (widget));
4296 /* GtkEditable method implementations
4299 gtk_entry_insert_text (GtkEditable *editable,
4300 const gchar *new_text,
4301 gint new_text_length,
4304 g_object_ref (editable);
4307 * The incoming text may a password or other secret. We make sure
4308 * not to copy it into temporary buffers.
4311 g_signal_emit_by_name (editable, "insert-text", new_text, new_text_length, position);
4313 g_object_unref (editable);
4317 gtk_entry_delete_text (GtkEditable *editable,
4321 g_object_ref (editable);
4323 g_signal_emit_by_name (editable, "delete-text", start_pos, end_pos);
4325 g_object_unref (editable);
4329 gtk_entry_get_chars (GtkEditable *editable,
4333 GtkEntry *entry = GTK_ENTRY (editable);
4336 gint start_index, end_index;
4338 text = gtk_entry_buffer_get_text (get_buffer (entry));
4339 text_length = gtk_entry_buffer_get_length (get_buffer (entry));
4342 end_pos = text_length;
4344 start_pos = MIN (text_length, start_pos);
4345 end_pos = MIN (text_length, end_pos);
4347 start_index = g_utf8_offset_to_pointer (text, start_pos) - text;
4348 end_index = g_utf8_offset_to_pointer (text, end_pos) - text;
4350 return g_strndup (text + start_index, end_index - start_index);
4354 gtk_entry_real_set_position (GtkEditable *editable,
4357 GtkEntry *entry = GTK_ENTRY (editable);
4361 length = gtk_entry_buffer_get_length (get_buffer (entry));
4362 if (position < 0 || position > length)
4365 if (position != entry->current_pos ||
4366 position != entry->selection_bound)
4368 _gtk_entry_reset_im_context (entry);
4369 gtk_entry_set_positions (entry, position, position);
4374 gtk_entry_get_position (GtkEditable *editable)
4376 return GTK_ENTRY (editable)->current_pos;
4380 gtk_entry_set_selection_bounds (GtkEditable *editable,
4384 GtkEntry *entry = GTK_ENTRY (editable);
4387 length = gtk_entry_buffer_get_length (get_buffer (entry));
4393 _gtk_entry_reset_im_context (entry);
4395 gtk_entry_set_positions (entry,
4397 MIN (start, length));
4399 gtk_entry_update_primary_selection (entry);
4403 gtk_entry_get_selection_bounds (GtkEditable *editable,
4407 GtkEntry *entry = GTK_ENTRY (editable);
4409 *start = entry->selection_bound;
4410 *end = entry->current_pos;
4412 return (entry->selection_bound != entry->current_pos);
4416 icon_theme_changed (GtkEntry *entry)
4418 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
4421 for (i = 0; i < MAX_ICONS; i++)
4423 EntryIconInfo *icon_info = priv->icons[i];
4424 if (icon_info != NULL)
4426 if (icon_info->storage_type == GTK_IMAGE_ICON_NAME)
4427 gtk_entry_set_icon_from_icon_name (entry, i, icon_info->icon_name);
4428 else if (icon_info->storage_type == GTK_IMAGE_STOCK)
4429 gtk_entry_set_icon_from_stock (entry, i, icon_info->stock_id);
4430 else if (icon_info->storage_type == GTK_IMAGE_GICON)
4431 gtk_entry_set_icon_from_gicon (entry, i, icon_info->gicon);
4435 gtk_widget_queue_draw (GTK_WIDGET (entry));
4439 icon_margin_changed (GtkEntry *entry)
4441 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
4444 _gtk_entry_effective_inner_border (GTK_ENTRY (entry), &border);
4446 priv->icon_margin = border.left;
4450 gtk_entry_style_set (GtkWidget *widget,
4451 GtkStyle *previous_style)
4453 GtkEntry *entry = GTK_ENTRY (widget);
4454 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
4456 gboolean interior_focus;
4459 gtk_widget_style_get (widget,
4460 "focus-line-width", &focus_width,
4461 "interior-focus", &interior_focus,
4464 priv->focus_width = focus_width;
4465 priv->interior_focus = interior_focus;
4467 if (!priv->invisible_char_set)
4468 entry->invisible_char = find_invisible_char (GTK_WIDGET (entry));
4470 gtk_entry_recompute (entry);
4472 if (previous_style && gtk_widget_get_realized (widget))
4476 style = gtk_widget_get_style (widget);
4478 gdk_window_set_background (gtk_widget_get_window (widget),
4479 &style->base[gtk_widget_get_state (widget)]);
4480 gdk_window_set_background (entry->text_area,
4481 &style->base[gtk_widget_get_state (widget)]);
4482 for (i = 0; i < MAX_ICONS; i++)
4484 EntryIconInfo *icon_info = priv->icons[i];
4485 if (icon_info && icon_info->window)
4486 gdk_window_set_background (icon_info->window,
4487 &style->base[gtk_widget_get_state (widget)]);
4491 icon_theme_changed (entry);
4492 icon_margin_changed (entry);
4495 /* GtkCellEditable method implementations
4498 gtk_cell_editable_entry_activated (GtkEntry *entry, gpointer data)
4500 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4501 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4505 gtk_cell_editable_key_press_event (GtkEntry *entry,
4506 GdkEventKey *key_event,
4509 if (key_event->keyval == GDK_KEY_Escape)
4511 entry->editing_canceled = TRUE;
4512 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4513 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4518 /* override focus */
4519 if (key_event->keyval == GDK_KEY_Up || key_event->keyval == GDK_KEY_Down)
4521 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4522 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4531 gtk_entry_start_editing (GtkCellEditable *cell_editable,
4534 GTK_ENTRY (cell_editable)->is_cell_renderer = TRUE;
4536 g_signal_connect (cell_editable, "activate",
4537 G_CALLBACK (gtk_cell_editable_entry_activated), NULL);
4538 g_signal_connect (cell_editable, "key-press-event",
4539 G_CALLBACK (gtk_cell_editable_key_press_event), NULL);
4543 gtk_entry_password_hint_free (GtkEntryPasswordHint *password_hint)
4545 if (password_hint->source_id)
4546 g_source_remove (password_hint->source_id);
4548 g_slice_free (GtkEntryPasswordHint, password_hint);
4553 gtk_entry_remove_password_hint (gpointer data)
4555 GtkEntryPasswordHint *password_hint = g_object_get_qdata (data, quark_password_hint);
4556 password_hint->position = -1;
4558 /* Force the string to be redrawn, but now without a visible character */
4559 gtk_entry_recompute (GTK_ENTRY (data));
4563 /* Default signal handlers
4566 gtk_entry_real_insert_text (GtkEditable *editable,
4567 const gchar *new_text,
4568 gint new_text_length,
4574 n_chars = g_utf8_strlen (new_text, new_text_length);
4577 * The actual insertion into the buffer. This will end up firing the
4578 * following signal handlers: buffer_inserted_text(), buffer_notify_display_text(),
4579 * buffer_notify_text(), buffer_notify_length()
4581 n_inserted = gtk_entry_buffer_insert_text (get_buffer (GTK_ENTRY (editable)), *position, new_text, n_chars);
4583 if (n_inserted != n_chars)
4584 gtk_widget_error_bell (GTK_WIDGET (editable));
4586 *position += n_inserted;
4590 gtk_entry_real_delete_text (GtkEditable *editable,
4595 * The actual deletion from the buffer. This will end up firing the
4596 * following signal handlers: buffer_deleted_text(), buffer_notify_display_text(),
4597 * buffer_notify_text(), buffer_notify_length()
4600 gtk_entry_buffer_delete_text (get_buffer (GTK_ENTRY (editable)), start_pos, end_pos - start_pos);
4603 /* GtkEntryBuffer signal handlers
4606 buffer_inserted_text (GtkEntryBuffer *buffer,
4612 guint password_hint_timeout;
4614 if (entry->current_pos > position)
4615 entry->current_pos += n_chars;
4617 if (entry->selection_bound > position)
4618 entry->selection_bound += n_chars;
4620 /* Calculate the password hint if it needs to be displayed. */
4621 if (n_chars == 1 && !entry->visible)
4623 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
4624 "gtk-entry-password-hint-timeout", &password_hint_timeout,
4627 if (password_hint_timeout > 0)
4629 GtkEntryPasswordHint *password_hint = g_object_get_qdata (G_OBJECT (entry),
4630 quark_password_hint);
4633 password_hint = g_slice_new0 (GtkEntryPasswordHint);
4634 g_object_set_qdata_full (G_OBJECT (entry), quark_password_hint, password_hint,
4635 (GDestroyNotify)gtk_entry_password_hint_free);
4638 password_hint->position = position;
4639 if (password_hint->source_id)
4640 g_source_remove (password_hint->source_id);
4641 password_hint->source_id = gdk_threads_add_timeout (password_hint_timeout,
4642 (GSourceFunc)gtk_entry_remove_password_hint, entry);
4648 buffer_deleted_text (GtkEntryBuffer *buffer,
4653 guint end_pos = position + n_chars;
4654 gint selection_bound;
4657 current_pos = entry->current_pos;
4658 if (current_pos > position)
4659 current_pos -= MIN (current_pos, end_pos) - position;
4661 selection_bound = entry->selection_bound;
4662 if (selection_bound > position)
4663 selection_bound -= MIN (selection_bound, end_pos) - position;
4665 gtk_entry_set_positions (entry, current_pos, selection_bound);
4667 /* We might have deleted the selection */
4668 gtk_entry_update_primary_selection (entry);
4670 /* Disable the password hint if one exists. */
4671 if (!entry->visible)
4673 GtkEntryPasswordHint *password_hint = g_object_get_qdata (G_OBJECT (entry),
4674 quark_password_hint);
4677 if (password_hint->source_id)
4678 g_source_remove (password_hint->source_id);
4679 password_hint->source_id = 0;
4680 password_hint->position = -1;
4686 buffer_notify_text (GtkEntryBuffer *buffer,
4690 gtk_entry_recompute (entry);
4691 emit_changed (entry);
4692 g_object_notify (G_OBJECT (entry), "text");
4696 buffer_notify_length (GtkEntryBuffer *buffer,
4700 g_object_notify (G_OBJECT (entry), "text-length");
4704 buffer_notify_max_length (GtkEntryBuffer *buffer,
4708 g_object_notify (G_OBJECT (entry), "max-length");
4712 buffer_connect_signals (GtkEntry *entry)
4714 g_signal_connect (get_buffer (entry), "inserted-text", G_CALLBACK (buffer_inserted_text), entry);
4715 g_signal_connect (get_buffer (entry), "deleted-text", G_CALLBACK (buffer_deleted_text), entry);
4716 g_signal_connect (get_buffer (entry), "notify::text", G_CALLBACK (buffer_notify_text), entry);
4717 g_signal_connect (get_buffer (entry), "notify::length", G_CALLBACK (buffer_notify_length), entry);
4718 g_signal_connect (get_buffer (entry), "notify::max-length", G_CALLBACK (buffer_notify_max_length), entry);
4722 buffer_disconnect_signals (GtkEntry *entry)
4724 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_inserted_text, entry);
4725 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_deleted_text, entry);
4726 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_text, entry);
4727 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_length, entry);
4728 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_max_length, entry);
4731 /* Compute the X position for an offset that corresponds to the "more important
4732 * cursor position for that offset. We use this when trying to guess to which
4733 * end of the selection we should go to when the user hits the left or
4737 get_better_cursor_x (GtkEntry *entry,
4740 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
4741 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
4742 gboolean split_cursor;
4744 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
4745 const gchar *text = pango_layout_get_text (layout);
4746 gint index = g_utf8_offset_to_pointer (text, offset) - text;
4748 PangoRectangle strong_pos, weak_pos;
4750 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
4751 "gtk-split-cursor", &split_cursor,
4754 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
4757 return strong_pos.x / PANGO_SCALE;
4759 return (keymap_direction == entry->resolved_dir) ? strong_pos.x / PANGO_SCALE : weak_pos.x / PANGO_SCALE;
4763 gtk_entry_move_cursor (GtkEntry *entry,
4764 GtkMovementStep step,
4766 gboolean extend_selection)
4768 gint new_pos = entry->current_pos;
4769 GtkEntryPrivate *priv;
4771 _gtk_entry_reset_im_context (entry);
4773 if (entry->current_pos != entry->selection_bound && !extend_selection)
4775 /* If we have a current selection and aren't extending it, move to the
4776 * start/or end of the selection as appropriate
4780 case GTK_MOVEMENT_VISUAL_POSITIONS:
4782 gint current_x = get_better_cursor_x (entry, entry->current_pos);
4783 gint bound_x = get_better_cursor_x (entry, entry->selection_bound);
4786 new_pos = current_x < bound_x ? entry->current_pos : entry->selection_bound;
4788 new_pos = current_x > bound_x ? entry->current_pos : entry->selection_bound;
4791 case GTK_MOVEMENT_LOGICAL_POSITIONS:
4792 case GTK_MOVEMENT_WORDS:
4794 new_pos = MIN (entry->current_pos, entry->selection_bound);
4796 new_pos = MAX (entry->current_pos, entry->selection_bound);
4798 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
4799 case GTK_MOVEMENT_PARAGRAPH_ENDS:
4800 case GTK_MOVEMENT_BUFFER_ENDS:
4801 priv = GTK_ENTRY_GET_PRIVATE (entry);
4802 new_pos = count < 0 ? 0 : gtk_entry_buffer_get_length (get_buffer (entry));
4804 case GTK_MOVEMENT_DISPLAY_LINES:
4805 case GTK_MOVEMENT_PARAGRAPHS:
4806 case GTK_MOVEMENT_PAGES:
4807 case GTK_MOVEMENT_HORIZONTAL_PAGES:
4815 case GTK_MOVEMENT_LOGICAL_POSITIONS:
4816 new_pos = gtk_entry_move_logically (entry, new_pos, count);
4818 case GTK_MOVEMENT_VISUAL_POSITIONS:
4819 new_pos = gtk_entry_move_visually (entry, new_pos, count);
4820 if (entry->current_pos == new_pos)
4822 if (!extend_selection)
4824 if (!gtk_widget_keynav_failed (GTK_WIDGET (entry),
4826 GTK_DIR_RIGHT : GTK_DIR_LEFT))
4828 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (entry));
4831 gtk_widget_child_focus (toplevel,
4833 GTK_DIR_RIGHT : GTK_DIR_LEFT);
4838 gtk_widget_error_bell (GTK_WIDGET (entry));
4842 case GTK_MOVEMENT_WORDS:
4845 new_pos = gtk_entry_move_forward_word (entry, new_pos, FALSE);
4850 new_pos = gtk_entry_move_backward_word (entry, new_pos, FALSE);
4853 if (entry->current_pos == new_pos)
4854 gtk_widget_error_bell (GTK_WIDGET (entry));
4856 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
4857 case GTK_MOVEMENT_PARAGRAPH_ENDS:
4858 case GTK_MOVEMENT_BUFFER_ENDS:
4859 priv = GTK_ENTRY_GET_PRIVATE (entry);
4860 new_pos = count < 0 ? 0 : gtk_entry_buffer_get_length (get_buffer (entry));
4861 if (entry->current_pos == new_pos)
4862 gtk_widget_error_bell (GTK_WIDGET (entry));
4864 case GTK_MOVEMENT_DISPLAY_LINES:
4865 case GTK_MOVEMENT_PARAGRAPHS:
4866 case GTK_MOVEMENT_PAGES:
4867 case GTK_MOVEMENT_HORIZONTAL_PAGES:
4872 if (extend_selection)
4873 gtk_editable_select_region (GTK_EDITABLE (entry), entry->selection_bound, new_pos);
4875 gtk_editable_set_position (GTK_EDITABLE (entry), new_pos);
4877 gtk_entry_pend_cursor_blink (entry);
4881 gtk_entry_insert_at_cursor (GtkEntry *entry,
4884 GtkEditable *editable = GTK_EDITABLE (entry);
4885 gint pos = entry->current_pos;
4887 if (entry->editable)
4889 _gtk_entry_reset_im_context (entry);
4891 gtk_editable_insert_text (editable, str, -1, &pos);
4892 gtk_editable_set_position (editable, pos);
4897 gtk_entry_delete_from_cursor (GtkEntry *entry,
4901 GtkEditable *editable = GTK_EDITABLE (entry);
4902 gint start_pos = entry->current_pos;
4903 gint end_pos = entry->current_pos;
4904 gint old_n_bytes = gtk_entry_buffer_get_bytes (get_buffer (entry));
4906 _gtk_entry_reset_im_context (entry);
4908 if (!entry->editable)
4910 gtk_widget_error_bell (GTK_WIDGET (entry));
4914 if (entry->selection_bound != entry->current_pos)
4916 gtk_editable_delete_selection (editable);
4922 case GTK_DELETE_CHARS:
4923 end_pos = gtk_entry_move_logically (entry, entry->current_pos, count);
4924 gtk_editable_delete_text (editable, MIN (start_pos, end_pos), MAX (start_pos, end_pos));
4926 case GTK_DELETE_WORDS:
4929 /* Move to end of current word, or if not on a word, end of previous word */
4930 end_pos = gtk_entry_move_backward_word (entry, end_pos, FALSE);
4931 end_pos = gtk_entry_move_forward_word (entry, end_pos, FALSE);
4935 /* Move to beginning of current word, or if not on a word, begining of next word */
4936 start_pos = gtk_entry_move_forward_word (entry, start_pos, FALSE);
4937 start_pos = gtk_entry_move_backward_word (entry, start_pos, FALSE);
4941 case GTK_DELETE_WORD_ENDS:
4944 start_pos = gtk_entry_move_backward_word (entry, start_pos, FALSE);
4949 end_pos = gtk_entry_move_forward_word (entry, end_pos, FALSE);
4952 gtk_editable_delete_text (editable, start_pos, end_pos);
4954 case GTK_DELETE_DISPLAY_LINE_ENDS:
4955 case GTK_DELETE_PARAGRAPH_ENDS:
4957 gtk_editable_delete_text (editable, 0, entry->current_pos);
4959 gtk_editable_delete_text (editable, entry->current_pos, -1);
4961 case GTK_DELETE_DISPLAY_LINES:
4962 case GTK_DELETE_PARAGRAPHS:
4963 gtk_editable_delete_text (editable, 0, -1);
4965 case GTK_DELETE_WHITESPACE:
4966 gtk_entry_delete_whitespace (entry);
4970 if (gtk_entry_buffer_get_bytes (get_buffer (entry)) == old_n_bytes)
4971 gtk_widget_error_bell (GTK_WIDGET (entry));
4973 gtk_entry_pend_cursor_blink (entry);
4977 gtk_entry_backspace (GtkEntry *entry)
4979 GtkEditable *editable = GTK_EDITABLE (entry);
4982 _gtk_entry_reset_im_context (entry);
4984 if (!entry->editable)
4986 gtk_widget_error_bell (GTK_WIDGET (entry));
4990 if (entry->selection_bound != entry->current_pos)
4992 gtk_editable_delete_selection (editable);
4996 prev_pos = gtk_entry_move_logically (entry, entry->current_pos, -1);
4998 if (prev_pos < entry->current_pos)
5000 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
5001 PangoLogAttr *log_attrs;
5004 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
5006 /* Deleting parts of characters */
5007 if (log_attrs[entry->current_pos].backspace_deletes_character)
5009 gchar *cluster_text;
5010 gchar *normalized_text;
5013 cluster_text = gtk_entry_get_display_text (entry, prev_pos,
5014 entry->current_pos);
5015 normalized_text = g_utf8_normalize (cluster_text,
5016 strlen (cluster_text),
5018 len = g_utf8_strlen (normalized_text, -1);
5020 gtk_editable_delete_text (editable, prev_pos, entry->current_pos);
5023 gint pos = entry->current_pos;
5025 gtk_editable_insert_text (editable, normalized_text,
5026 g_utf8_offset_to_pointer (normalized_text, len - 1) - normalized_text,
5028 gtk_editable_set_position (editable, pos);
5031 g_free (normalized_text);
5032 g_free (cluster_text);
5036 gtk_editable_delete_text (editable, prev_pos, entry->current_pos);
5043 gtk_widget_error_bell (GTK_WIDGET (entry));
5046 gtk_entry_pend_cursor_blink (entry);
5050 gtk_entry_copy_clipboard (GtkEntry *entry)
5052 GtkEditable *editable = GTK_EDITABLE (entry);
5056 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5058 if (!entry->visible)
5060 gtk_widget_error_bell (GTK_WIDGET (entry));
5064 str = gtk_entry_get_display_text (entry, start, end);
5065 gtk_clipboard_set_text (gtk_widget_get_clipboard (GTK_WIDGET (entry),
5066 GDK_SELECTION_CLIPBOARD),
5073 gtk_entry_cut_clipboard (GtkEntry *entry)
5075 GtkEditable *editable = GTK_EDITABLE (entry);
5078 if (!entry->visible)
5080 gtk_widget_error_bell (GTK_WIDGET (entry));
5084 gtk_entry_copy_clipboard (entry);
5086 if (entry->editable)
5088 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5089 gtk_editable_delete_text (editable, start, end);
5093 gtk_widget_error_bell (GTK_WIDGET (entry));
5098 gtk_entry_paste_clipboard (GtkEntry *entry)
5100 if (entry->editable)
5101 gtk_entry_paste (entry, GDK_NONE);
5103 gtk_widget_error_bell (GTK_WIDGET (entry));
5107 gtk_entry_delete_cb (GtkEntry *entry)
5109 GtkEditable *editable = GTK_EDITABLE (entry);
5112 if (entry->editable)
5114 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5115 gtk_editable_delete_text (editable, start, end);
5120 gtk_entry_toggle_overwrite (GtkEntry *entry)
5122 entry->overwrite_mode = !entry->overwrite_mode;
5123 gtk_entry_pend_cursor_blink (entry);
5124 gtk_widget_queue_draw (GTK_WIDGET (entry));
5128 gtk_entry_select_all (GtkEntry *entry)
5130 gtk_entry_select_line (entry);
5134 gtk_entry_real_activate (GtkEntry *entry)
5137 GtkWidget *default_widget, *focus_widget;
5138 GtkWidget *toplevel;
5141 widget = GTK_WIDGET (entry);
5143 if (entry->activates_default)
5145 toplevel = gtk_widget_get_toplevel (widget);
5146 if (GTK_IS_WINDOW (toplevel))
5148 window = GTK_WINDOW (toplevel);
5152 default_widget = gtk_window_get_default_widget (window);
5153 focus_widget = gtk_window_get_focus (window);
5154 if (widget != default_widget &&
5155 !(widget == focus_widget && (!default_widget || !gtk_widget_get_sensitive (default_widget))))
5156 gtk_window_activate_default (window);
5163 keymap_direction_changed (GdkKeymap *keymap,
5166 gtk_entry_recompute (entry);
5169 /* IM Context Callbacks
5173 gtk_entry_commit_cb (GtkIMContext *context,
5177 if (entry->editable)
5178 gtk_entry_enter_text (entry, str);
5182 gtk_entry_preedit_changed_cb (GtkIMContext *context,
5185 if (entry->editable)
5187 gchar *preedit_string;
5190 gtk_im_context_get_preedit_string (entry->im_context,
5191 &preedit_string, NULL,
5193 g_signal_emit (entry, signals[PREEDIT_CHANGED], 0, preedit_string);
5194 entry->preedit_length = strlen (preedit_string);
5195 cursor_pos = CLAMP (cursor_pos, 0, g_utf8_strlen (preedit_string, -1));
5196 entry->preedit_cursor = cursor_pos;
5197 g_free (preedit_string);
5199 gtk_entry_recompute (entry);
5204 gtk_entry_retrieve_surrounding_cb (GtkIMContext *context,
5209 /* XXXX ??? does this even make sense when text is not visible? Should we return FALSE? */
5210 text = gtk_entry_get_display_text (entry, 0, -1);
5211 gtk_im_context_set_surrounding (context, text, strlen (text), /* Length in bytes */
5212 g_utf8_offset_to_pointer (text, entry->current_pos) - text);
5219 gtk_entry_delete_surrounding_cb (GtkIMContext *slave,
5224 if (entry->editable)
5225 gtk_editable_delete_text (GTK_EDITABLE (entry),
5226 entry->current_pos + offset,
5227 entry->current_pos + offset + n_chars);
5232 /* Internal functions
5235 /* Used for im_commit_cb and inserting Unicode chars */
5237 gtk_entry_enter_text (GtkEntry *entry,
5240 GtkEditable *editable = GTK_EDITABLE (entry);
5242 gboolean old_need_im_reset;
5244 old_need_im_reset = entry->need_im_reset;
5245 entry->need_im_reset = FALSE;
5247 if (gtk_editable_get_selection_bounds (editable, NULL, NULL))
5248 gtk_editable_delete_selection (editable);
5251 if (entry->overwrite_mode)
5252 gtk_entry_delete_from_cursor (entry, GTK_DELETE_CHARS, 1);
5255 tmp_pos = entry->current_pos;
5256 gtk_editable_insert_text (editable, str, strlen (str), &tmp_pos);
5257 gtk_editable_set_position (editable, tmp_pos);
5259 entry->need_im_reset = old_need_im_reset;
5262 /* All changes to entry->current_pos and entry->selection_bound
5263 * should go through this function.
5266 gtk_entry_set_positions (GtkEntry *entry,
5268 gint selection_bound)
5270 gboolean changed = FALSE;
5272 g_object_freeze_notify (G_OBJECT (entry));
5274 if (current_pos != -1 &&
5275 entry->current_pos != current_pos)
5277 entry->current_pos = current_pos;
5280 g_object_notify (G_OBJECT (entry), "cursor-position");
5283 if (selection_bound != -1 &&
5284 entry->selection_bound != selection_bound)
5286 entry->selection_bound = selection_bound;
5289 g_object_notify (G_OBJECT (entry), "selection-bound");
5292 g_object_thaw_notify (G_OBJECT (entry));
5296 gtk_entry_move_adjustments (entry);
5297 gtk_entry_recompute (entry);
5302 gtk_entry_reset_layout (GtkEntry *entry)
5304 if (entry->cached_layout)
5306 g_object_unref (entry->cached_layout);
5307 entry->cached_layout = NULL;
5312 update_im_cursor_location (GtkEntry *entry)
5316 gint strong_xoffset;
5317 gint area_width, area_height;
5319 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
5320 gtk_entry_get_text_area_size (entry, NULL, NULL, &area_width, &area_height);
5322 strong_xoffset = strong_x - entry->scroll_offset;
5323 if (strong_xoffset < 0)
5327 else if (strong_xoffset > area_width)
5329 strong_xoffset = area_width;
5331 area.x = strong_xoffset;
5334 area.height = area_height;
5336 gtk_im_context_set_cursor_location (entry->im_context, &area);
5340 recompute_idle_func (gpointer data)
5344 entry = GTK_ENTRY (data);
5346 entry->recompute_idle = 0;
5348 if (gtk_widget_has_screen (GTK_WIDGET (entry)))
5350 gtk_entry_adjust_scroll (entry);
5351 gtk_entry_queue_draw (entry);
5353 update_im_cursor_location (entry);
5360 gtk_entry_recompute (GtkEntry *entry)
5362 gtk_entry_reset_layout (entry);
5363 gtk_entry_check_cursor_blink (entry);
5365 if (!entry->recompute_idle)
5367 entry->recompute_idle = gdk_threads_add_idle_full (G_PRIORITY_HIGH_IDLE + 15, /* between resize and redraw */
5368 recompute_idle_func, entry, NULL);
5372 static PangoLayout *
5373 gtk_entry_create_layout (GtkEntry *entry,
5374 gboolean include_preedit)
5376 GtkWidget *widget = GTK_WIDGET (entry);
5377 PangoLayout *layout = gtk_widget_create_pango_layout (widget, NULL);
5378 PangoAttrList *tmp_attrs = pango_attr_list_new ();
5380 gchar *preedit_string = NULL;
5381 gint preedit_length = 0;
5382 PangoAttrList *preedit_attrs = NULL;
5387 pango_layout_set_single_paragraph_mode (layout, TRUE);
5389 display = gtk_entry_get_display_text (entry, 0, -1);
5390 n_bytes = strlen (display);
5392 if (include_preedit)
5394 gtk_im_context_get_preedit_string (entry->im_context,
5395 &preedit_string, &preedit_attrs, NULL);
5396 preedit_length = entry->preedit_length;
5401 GString *tmp_string = g_string_new (display);
5402 gint cursor_index = g_utf8_offset_to_pointer (display, entry->current_pos) - display;
5404 g_string_insert (tmp_string, cursor_index, preedit_string);
5406 pango_layout_set_text (layout, tmp_string->str, tmp_string->len);
5408 pango_attr_list_splice (tmp_attrs, preedit_attrs,
5409 cursor_index, preedit_length);
5411 g_string_free (tmp_string, TRUE);
5415 PangoDirection pango_dir;
5417 if (gtk_entry_get_display_mode (entry) == DISPLAY_NORMAL)
5418 pango_dir = pango_find_base_dir (display, n_bytes);
5420 pango_dir = PANGO_DIRECTION_NEUTRAL;
5422 if (pango_dir == PANGO_DIRECTION_NEUTRAL)
5424 if (gtk_widget_has_focus (widget))
5426 GdkDisplay *display = gtk_widget_get_display (widget);
5427 GdkKeymap *keymap = gdk_keymap_get_for_display (display);
5428 if (gdk_keymap_get_direction (keymap) == PANGO_DIRECTION_RTL)
5429 pango_dir = PANGO_DIRECTION_RTL;
5431 pango_dir = PANGO_DIRECTION_LTR;
5435 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
5436 pango_dir = PANGO_DIRECTION_RTL;
5438 pango_dir = PANGO_DIRECTION_LTR;
5442 pango_context_set_base_dir (gtk_widget_get_pango_context (widget),
5445 entry->resolved_dir = pango_dir;
5447 pango_layout_set_text (layout, display, n_bytes);
5450 pango_layout_set_attributes (layout, tmp_attrs);
5452 g_free (preedit_string);
5456 pango_attr_list_unref (preedit_attrs);
5458 pango_attr_list_unref (tmp_attrs);
5463 static PangoLayout *
5464 gtk_entry_ensure_layout (GtkEntry *entry,
5465 gboolean include_preedit)
5467 if (entry->preedit_length > 0 &&
5468 !include_preedit != !entry->cache_includes_preedit)
5469 gtk_entry_reset_layout (entry);
5471 if (!entry->cached_layout)
5473 entry->cached_layout = gtk_entry_create_layout (entry, include_preedit);
5474 entry->cache_includes_preedit = include_preedit;
5477 return entry->cached_layout;
5481 get_layout_position (GtkEntry *entry,
5485 PangoLayout *layout;
5486 PangoRectangle logical_rect;
5487 gint area_width, area_height;
5488 GtkBorder inner_border;
5490 PangoLayoutLine *line;
5492 layout = gtk_entry_ensure_layout (entry, TRUE);
5494 gtk_entry_get_text_area_size (entry, NULL, NULL, &area_width, &area_height);
5495 _gtk_entry_effective_inner_border (entry, &inner_border);
5497 area_height = PANGO_SCALE * (area_height - inner_border.top - inner_border.bottom);
5499 line = pango_layout_get_lines_readonly (layout)->data;
5500 pango_layout_line_get_extents (line, NULL, &logical_rect);
5502 /* Align primarily for locale's ascent/descent */
5503 y_pos = ((area_height - entry->ascent - entry->descent) / 2 +
5504 entry->ascent + logical_rect.y);
5506 /* Now see if we need to adjust to fit in actual drawn string */
5507 if (logical_rect.height > area_height)
5508 y_pos = (area_height - logical_rect.height) / 2;
5511 else if (y_pos + logical_rect.height > area_height)
5512 y_pos = area_height - logical_rect.height;
5514 y_pos = inner_border.top + y_pos / PANGO_SCALE;
5517 *x = inner_border.left - entry->scroll_offset;
5524 draw_text_with_color (GtkEntry *entry, cairo_t *cr, GdkColor *default_color)
5526 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
5529 gint start_pos, end_pos;
5531 widget = GTK_WIDGET (entry);
5535 get_layout_position (entry, &x, &y);
5537 cairo_move_to (cr, x, y);
5538 gdk_cairo_set_source_color (cr, default_color);
5539 pango_cairo_show_layout (cr, layout);
5541 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start_pos, &end_pos))
5545 PangoRectangle logical_rect;
5546 GdkColor *selection_color, *text_color;
5547 GtkBorder inner_border;
5550 pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
5551 gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
5553 style = gtk_widget_get_style (widget);
5555 if (gtk_widget_has_focus (widget))
5557 selection_color = &style->base [GTK_STATE_SELECTED];
5558 text_color = &style->text [GTK_STATE_SELECTED];
5562 selection_color = &style->base [GTK_STATE_ACTIVE];
5563 text_color = &style->text [GTK_STATE_ACTIVE];
5566 _gtk_entry_effective_inner_border (entry, &inner_border);
5568 for (i = 0; i < n_ranges; ++i)
5569 cairo_rectangle (cr,
5570 inner_border.left - entry->scroll_offset + ranges[2 * i],
5573 logical_rect.height);
5577 gdk_cairo_set_source_color (cr, selection_color);
5580 cairo_move_to (cr, x, y);
5581 gdk_cairo_set_source_color (cr, text_color);
5582 pango_cairo_show_layout (cr, layout);
5590 gtk_entry_draw_text (GtkEntry *entry,
5593 GtkWidget *widget = GTK_WIDGET (entry);
5596 GdkColor text_color, bar_text_color;
5599 gint progress_x, progress_y, progress_width, progress_height;
5602 /* Nothing to display at all */
5603 if (gtk_entry_get_display_mode (entry) == DISPLAY_BLANK)
5606 state = GTK_STATE_SELECTED;
5607 if (!gtk_widget_get_sensitive (widget))
5608 state = GTK_STATE_INSENSITIVE;
5609 style = gtk_widget_get_style (widget);
5610 text_color = style->text[gtk_widget_get_state (widget)];
5611 bar_text_color = style->fg[state];
5613 get_progress_area (widget,
5614 &progress_x, &progress_y,
5615 &progress_width, &progress_height);
5617 /* If the color is the same, or the progress area has a zero
5618 * size, then we only need to draw once. */
5619 if ((text_color.pixel == bar_text_color.pixel) ||
5620 ((progress_width == 0) || (progress_height == 0)))
5622 draw_text_with_color (entry, cr, &text_color);
5626 width = gdk_window_get_width (entry->text_area);
5627 height = gdk_window_get_height (entry->text_area);
5631 cairo_rectangle (cr, 0, 0, width, height);
5635 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
5636 cairo_rectangle (cr, 0, 0, width, height);
5638 gdk_window_get_position (entry->text_area, &pos_x, &pos_y);
5639 progress_x -= pos_x;
5640 progress_y -= pos_y;
5642 cairo_rectangle (cr, progress_x, progress_y,
5643 progress_width, progress_height);
5645 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_WINDING);
5647 draw_text_with_color (entry, cr, &text_color);
5650 cairo_rectangle (cr, progress_x, progress_y,
5651 progress_width, progress_height);
5654 draw_text_with_color (entry, cr, &bar_text_color);
5661 draw_insertion_cursor (GtkEntry *entry,
5663 GdkRectangle *cursor_location,
5664 gboolean is_primary,
5665 PangoDirection direction,
5666 gboolean draw_arrow)
5668 GtkWidget *widget = GTK_WIDGET (entry);
5669 GtkTextDirection text_dir;
5671 if (direction == PANGO_DIRECTION_LTR)
5672 text_dir = GTK_TEXT_DIR_LTR;
5674 text_dir = GTK_TEXT_DIR_RTL;
5676 gtk_draw_insertion_cursor (widget, cr,
5678 is_primary, text_dir, draw_arrow);
5682 gtk_entry_draw_cursor (GtkEntry *entry,
5686 GtkWidget *widget = GTK_WIDGET (entry);
5687 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
5688 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
5689 GdkRectangle cursor_location;
5690 gboolean split_cursor;
5691 PangoRectangle cursor_rect;
5692 GtkBorder inner_border;
5694 gint text_area_height;
5697 gboolean block_at_line_end;
5698 PangoLayout *layout;
5701 _gtk_entry_effective_inner_border (entry, &inner_border);
5703 xoffset = inner_border.left - entry->scroll_offset;
5705 text_area_height = gdk_window_get_height (entry->text_area);
5707 layout = gtk_entry_ensure_layout (entry, TRUE);
5708 text = pango_layout_get_text (layout);
5709 cursor_index = g_utf8_offset_to_pointer (text, entry->current_pos + entry->preedit_cursor) - text;
5710 if (!entry->overwrite_mode)
5713 block = _gtk_text_util_get_block_cursor_location (layout,
5714 cursor_index, &cursor_rect, &block_at_line_end);
5718 gint strong_x, weak_x;
5719 PangoDirection dir1 = PANGO_DIRECTION_NEUTRAL;
5720 PangoDirection dir2 = PANGO_DIRECTION_NEUTRAL;
5724 gtk_entry_get_cursor_locations (entry, type, &strong_x, &weak_x);
5726 g_object_get (gtk_widget_get_settings (widget),
5727 "gtk-split-cursor", &split_cursor,
5730 dir1 = entry->resolved_dir;
5736 if (weak_x != strong_x)
5738 dir2 = (entry->resolved_dir == PANGO_DIRECTION_LTR) ? PANGO_DIRECTION_RTL : PANGO_DIRECTION_LTR;
5744 if (keymap_direction == entry->resolved_dir)
5750 cursor_location.x = xoffset + x1;
5751 cursor_location.y = inner_border.top;
5752 cursor_location.width = 0;
5753 cursor_location.height = text_area_height - inner_border.top - inner_border.bottom;
5755 draw_insertion_cursor (entry, cr,
5756 &cursor_location, TRUE, dir1,
5757 dir2 != PANGO_DIRECTION_NEUTRAL);
5759 if (dir2 != PANGO_DIRECTION_NEUTRAL)
5761 cursor_location.x = xoffset + x2;
5762 draw_insertion_cursor (entry, cr,
5763 &cursor_location, FALSE, dir2,
5767 else /* overwrite_mode */
5769 GdkColor cursor_color;
5775 get_layout_position (entry, &x, &y);
5777 rect.x = PANGO_PIXELS (cursor_rect.x) + x;
5778 rect.y = PANGO_PIXELS (cursor_rect.y) + y;
5779 rect.width = PANGO_PIXELS (cursor_rect.width);
5780 rect.height = PANGO_PIXELS (cursor_rect.height);
5782 _gtk_widget_get_cursor_color (widget, &cursor_color);
5783 gdk_cairo_set_source_color (cr, &cursor_color);
5784 gdk_cairo_rectangle (cr, &rect);
5787 if (!block_at_line_end)
5789 gdk_cairo_rectangle (cr, &rect);
5791 cairo_move_to (cr, x, y);
5792 gdk_cairo_set_source_color (cr, >k_widget_get_style (widget)->base[gtk_widget_get_state (widget)]);
5793 pango_cairo_show_layout (cr, layout);
5801 gtk_entry_queue_draw (GtkEntry *entry)
5803 if (gtk_widget_is_drawable (GTK_WIDGET (entry)))
5804 gdk_window_invalidate_rect (entry->text_area, NULL, FALSE);
5808 _gtk_entry_reset_im_context (GtkEntry *entry)
5810 if (entry->need_im_reset)
5812 entry->need_im_reset = FALSE;
5813 gtk_im_context_reset (entry->im_context);
5818 * gtk_entry_reset_im_context:
5819 * @entry: a #GtkEntry
5821 * Reset the input method context of the entry if needed.
5823 * This can be necessary in the case where modifying the buffer
5824 * would confuse on-going input method behavior.
5829 gtk_entry_reset_im_context (GtkEntry *entry)
5831 g_return_if_fail (GTK_IS_ENTRY (entry));
5833 _gtk_entry_reset_im_context (entry);
5837 * gtk_entry_im_context_filter_keypress:
5838 * @entry: a #GtkEntry
5839 * @event: the key event
5841 * Allow the #GtkEntry input method to internally handle key press
5842 * and release events. If this function returns %TRUE, then no further
5843 * processing should be done for this key event. See
5844 * gtk_im_context_filter_keypress().
5846 * Note that you are expected to call this function from your handler
5847 * when overriding key event handling. This is needed in the case when
5848 * you need to insert your own key handling between the input method
5849 * and the default key event handling of the #GtkEntry.
5850 * See gtk_text_view_reset_im_context() for an example of use.
5852 * Return value: %TRUE if the input method handled the key event.
5857 gtk_entry_im_context_filter_keypress (GtkEntry *entry,
5860 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
5862 return gtk_im_context_filter_keypress (entry->im_context, event);
5867 gtk_entry_find_position (GtkEntry *entry,
5870 PangoLayout *layout;
5871 PangoLayoutLine *line;
5878 layout = gtk_entry_ensure_layout (entry, TRUE);
5879 text = pango_layout_get_text (layout);
5880 cursor_index = g_utf8_offset_to_pointer (text, entry->current_pos) - text;
5882 line = pango_layout_get_lines_readonly (layout)->data;
5883 pango_layout_line_x_to_index (line, x * PANGO_SCALE, &index, &trailing);
5885 if (index >= cursor_index && entry->preedit_length)
5887 if (index >= cursor_index + entry->preedit_length)
5888 index -= entry->preedit_length;
5891 index = cursor_index;
5896 pos = g_utf8_pointer_to_offset (text, text + index);
5903 gtk_entry_get_cursor_locations (GtkEntry *entry,
5908 DisplayMode mode = gtk_entry_get_display_mode (entry);
5910 /* Nothing to display at all, so no cursor is relevant */
5911 if (mode == DISPLAY_BLANK)
5921 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
5922 const gchar *text = pango_layout_get_text (layout);
5923 PangoRectangle strong_pos, weak_pos;
5926 if (type == CURSOR_STANDARD)
5928 index = g_utf8_offset_to_pointer (text, entry->current_pos + entry->preedit_cursor) - text;
5930 else /* type == CURSOR_DND */
5932 index = g_utf8_offset_to_pointer (text, entry->dnd_position) - text;
5934 if (entry->dnd_position > entry->current_pos)
5936 if (mode == DISPLAY_NORMAL)
5937 index += entry->preedit_length;
5940 gint preedit_len_chars = g_utf8_strlen (text, -1) - gtk_entry_buffer_get_length (get_buffer (entry));
5941 index += preedit_len_chars * g_unichar_to_utf8 (entry->invisible_char, NULL);
5946 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
5949 *strong_x = strong_pos.x / PANGO_SCALE;
5952 *weak_x = weak_pos.x / PANGO_SCALE;
5957 gtk_entry_adjust_scroll (GtkEntry *entry)
5959 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
5960 gint min_offset, max_offset;
5961 gint text_area_width, text_width;
5962 GtkBorder inner_border;
5963 gint strong_x, weak_x;
5964 gint strong_xoffset, weak_xoffset;
5966 PangoLayout *layout;
5967 PangoLayoutLine *line;
5968 PangoRectangle logical_rect;
5970 if (!gtk_widget_get_realized (GTK_WIDGET (entry)))
5973 _gtk_entry_effective_inner_border (entry, &inner_border);
5975 text_area_width = gdk_window_get_width (entry->text_area);
5976 text_area_width -= inner_border.left + inner_border.right;
5977 if (text_area_width < 0)
5978 text_area_width = 0;
5980 layout = gtk_entry_ensure_layout (entry, TRUE);
5981 line = pango_layout_get_lines_readonly (layout)->data;
5983 pango_layout_line_get_extents (line, NULL, &logical_rect);
5985 /* Display as much text as we can */
5987 if (entry->resolved_dir == PANGO_DIRECTION_LTR)
5988 xalign = priv->xalign;
5990 xalign = 1.0 - priv->xalign;
5992 text_width = PANGO_PIXELS(logical_rect.width);
5994 if (text_width > text_area_width)
5997 max_offset = text_width - text_area_width;
6001 min_offset = (text_width - text_area_width) * xalign;
6002 max_offset = min_offset;
6005 entry->scroll_offset = CLAMP (entry->scroll_offset, min_offset, max_offset);
6007 /* And make sure cursors are on screen. Note that the cursor is
6008 * actually drawn one pixel into the INNER_BORDER space on
6009 * the right, when the scroll is at the utmost right. This
6010 * looks better to to me than confining the cursor inside the
6011 * border entirely, though it means that the cursor gets one
6012 * pixel closer to the edge of the widget on the right than
6013 * on the left. This might need changing if one changed
6014 * INNER_BORDER from 2 to 1, as one would do on a
6015 * small-screen-real-estate display.
6017 * We always make sure that the strong cursor is on screen, and
6018 * put the weak cursor on screen if possible.
6021 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, &weak_x);
6023 strong_xoffset = strong_x - entry->scroll_offset;
6025 if (strong_xoffset < 0)
6027 entry->scroll_offset += strong_xoffset;
6030 else if (strong_xoffset > text_area_width)
6032 entry->scroll_offset += strong_xoffset - text_area_width;
6033 strong_xoffset = text_area_width;
6036 weak_xoffset = weak_x - entry->scroll_offset;
6038 if (weak_xoffset < 0 && strong_xoffset - weak_xoffset <= text_area_width)
6040 entry->scroll_offset += weak_xoffset;
6042 else if (weak_xoffset > text_area_width &&
6043 strong_xoffset - (weak_xoffset - text_area_width) >= 0)
6045 entry->scroll_offset += weak_xoffset - text_area_width;
6048 g_object_notify (G_OBJECT (entry), "scroll-offset");
6052 gtk_entry_move_adjustments (GtkEntry *entry)
6054 GtkAllocation allocation;
6055 GtkAdjustment *adjustment;
6056 PangoContext *context;
6057 PangoFontMetrics *metrics;
6058 gint x, layout_x, border_x, border_y;
6061 adjustment = g_object_get_qdata (G_OBJECT (entry), quark_cursor_hadjustment);
6065 gtk_widget_get_allocation (&(entry->widget), &allocation);
6067 /* Cursor position, layout offset, border width, and widget allocation */
6068 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &x, NULL);
6069 get_layout_position (entry, &layout_x, NULL);
6070 _gtk_entry_get_borders (entry, &border_x, &border_y);
6071 x += allocation.x + layout_x + border_x;
6073 /* Approximate width of a char, so user can see what is ahead/behind */
6074 context = gtk_widget_get_pango_context (GTK_WIDGET (entry));
6075 metrics = pango_context_get_metrics (context,
6076 gtk_widget_get_style (&(entry->widget))->font_desc,
6077 pango_context_get_language (context));
6078 char_width = pango_font_metrics_get_approximate_char_width (metrics) / PANGO_SCALE;
6081 gtk_adjustment_clamp_page (adjustment,
6082 x - (char_width + 1), /* one char + one pixel before */
6083 x + (char_width + 2)); /* one char + cursor + one pixel after */
6087 gtk_entry_move_visually (GtkEntry *entry,
6092 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6095 text = pango_layout_get_text (layout);
6097 index = g_utf8_offset_to_pointer (text, start) - text;
6101 int new_index, new_trailing;
6102 gboolean split_cursor;
6105 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
6106 "gtk-split-cursor", &split_cursor,
6113 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
6114 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
6116 strong = keymap_direction == entry->resolved_dir;
6121 pango_layout_move_cursor_visually (layout, strong, index, 0, 1, &new_index, &new_trailing);
6126 pango_layout_move_cursor_visually (layout, strong, index, 0, -1, &new_index, &new_trailing);
6132 else if (new_index != G_MAXINT)
6135 while (new_trailing--)
6136 index = g_utf8_next_char (text + index) - text;
6139 return g_utf8_pointer_to_offset (text, text + index);
6143 gtk_entry_move_logically (GtkEntry *entry,
6147 gint new_pos = start;
6150 length = gtk_entry_buffer_get_length (get_buffer (entry));
6152 /* Prevent any leak of information */
6153 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6155 new_pos = CLAMP (start + count, 0, length);
6159 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6160 PangoLogAttr *log_attrs;
6163 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6165 while (count > 0 && new_pos < length)
6169 while (new_pos < length && !log_attrs[new_pos].is_cursor_position);
6173 while (count < 0 && new_pos > 0)
6177 while (new_pos > 0 && !log_attrs[new_pos].is_cursor_position);
6189 gtk_entry_move_forward_word (GtkEntry *entry,
6191 gboolean allow_whitespace)
6193 gint new_pos = start;
6196 length = gtk_entry_buffer_get_length (get_buffer (entry));
6198 /* Prevent any leak of information */
6199 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6203 else if (new_pos < length)
6205 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6206 PangoLogAttr *log_attrs;
6209 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6211 /* Find the next word boundary */
6213 while (new_pos < n_attrs - 1 && !(log_attrs[new_pos].is_word_end ||
6214 (log_attrs[new_pos].is_word_start && allow_whitespace)))
6225 gtk_entry_move_backward_word (GtkEntry *entry,
6227 gboolean allow_whitespace)
6229 gint new_pos = start;
6231 /* Prevent any leak of information */
6232 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6238 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6239 PangoLogAttr *log_attrs;
6242 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6244 new_pos = start - 1;
6246 /* Find the previous word boundary */
6247 while (new_pos > 0 && !(log_attrs[new_pos].is_word_start ||
6248 (log_attrs[new_pos].is_word_end && allow_whitespace)))
6258 gtk_entry_delete_whitespace (GtkEntry *entry)
6260 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6261 PangoLogAttr *log_attrs;
6265 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6267 start = end = entry->current_pos;
6269 while (start > 0 && log_attrs[start-1].is_white)
6272 while (end < n_attrs && log_attrs[end].is_white)
6278 gtk_editable_delete_text (GTK_EDITABLE (entry), start, end);
6283 gtk_entry_select_word (GtkEntry *entry)
6285 gint start_pos = gtk_entry_move_backward_word (entry, entry->current_pos, TRUE);
6286 gint end_pos = gtk_entry_move_forward_word (entry, entry->current_pos, TRUE);
6288 gtk_editable_select_region (GTK_EDITABLE (entry), start_pos, end_pos);
6292 gtk_entry_select_line (GtkEntry *entry)
6294 gtk_editable_select_region (GTK_EDITABLE (entry), 0, -1);
6298 truncate_multiline (const gchar *text)
6303 text[length] && text[length] != '\n' && text[length] != '\r';
6310 paste_received (GtkClipboard *clipboard,
6314 GtkEntry *entry = GTK_ENTRY (data);
6315 GtkEditable *editable = GTK_EDITABLE (entry);
6316 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
6318 if (entry->button == 2)
6320 gint pos, start, end;
6321 pos = priv->insert_pos;
6322 gtk_editable_get_selection_bounds (editable, &start, &end);
6323 if (!((start <= pos && pos <= end) || (end <= pos && pos <= start)))
6324 gtk_editable_select_region (editable, pos, pos);
6329 gint pos, start, end;
6331 gboolean popup_completion;
6332 GtkEntryCompletion *completion;
6334 completion = gtk_entry_get_completion (entry);
6336 if (entry->truncate_multiline)
6337 length = truncate_multiline (text);
6339 /* only complete if the selection is at the end */
6340 popup_completion = (gtk_entry_buffer_get_length (get_buffer (entry)) ==
6341 MAX (entry->current_pos, entry->selection_bound));
6345 if (gtk_widget_get_mapped (completion->priv->popup_window))
6346 _gtk_entry_completion_popdown (completion);
6348 if (!popup_completion && completion->priv->changed_id > 0)
6349 g_signal_handler_block (entry, completion->priv->changed_id);
6352 begin_change (entry);
6353 g_object_freeze_notify (G_OBJECT (entry));
6354 if (gtk_editable_get_selection_bounds (editable, &start, &end))
6355 gtk_editable_delete_text (editable, start, end);
6357 pos = entry->current_pos;
6358 gtk_editable_insert_text (editable, text, length, &pos);
6359 gtk_editable_set_position (editable, pos);
6360 g_object_thaw_notify (G_OBJECT (entry));
6364 !popup_completion && completion->priv->changed_id > 0)
6365 g_signal_handler_unblock (entry, completion->priv->changed_id);
6368 g_object_unref (entry);
6372 gtk_entry_paste (GtkEntry *entry,
6375 g_object_ref (entry);
6376 gtk_clipboard_request_text (gtk_widget_get_clipboard (GTK_WIDGET (entry), selection),
6377 paste_received, entry);
6381 primary_get_cb (GtkClipboard *clipboard,
6382 GtkSelectionData *selection_data,
6386 GtkEntry *entry = GTK_ENTRY (data);
6389 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end))
6391 gchar *str = gtk_entry_get_display_text (entry, start, end);
6392 gtk_selection_data_set_text (selection_data, str, -1);
6398 primary_clear_cb (GtkClipboard *clipboard,
6401 GtkEntry *entry = GTK_ENTRY (data);
6403 gtk_editable_select_region (GTK_EDITABLE (entry), entry->current_pos, entry->current_pos);
6407 gtk_entry_update_primary_selection (GtkEntry *entry)
6409 GtkTargetList *list;
6410 GtkTargetEntry *targets;
6411 GtkClipboard *clipboard;
6415 if (!gtk_widget_get_realized (GTK_WIDGET (entry)))
6418 list = gtk_target_list_new (NULL, 0);
6419 gtk_target_list_add_text_targets (list, 0);
6421 targets = gtk_target_table_new_from_list (list, &n_targets);
6423 clipboard = gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_PRIMARY);
6425 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end))
6427 if (!gtk_clipboard_set_with_owner (clipboard, targets, n_targets,
6428 primary_get_cb, primary_clear_cb, G_OBJECT (entry)))
6429 primary_clear_cb (clipboard, entry);
6433 if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (entry))
6434 gtk_clipboard_clear (clipboard);
6437 gtk_target_table_free (targets, n_targets);
6438 gtk_target_list_unref (list);
6442 gtk_entry_clear (GtkEntry *entry,
6443 GtkEntryIconPosition icon_pos)
6445 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
6446 EntryIconInfo *icon_info = priv->icons[icon_pos];
6448 if (!icon_info || icon_info->storage_type == GTK_IMAGE_EMPTY)
6451 g_object_freeze_notify (G_OBJECT (entry));
6453 /* Explicitly check, as the pointer may become invalidated
6454 * during destruction.
6456 if (GDK_IS_WINDOW (icon_info->window))
6457 gdk_window_hide (icon_info->window);
6459 if (icon_info->pixbuf)
6461 g_object_unref (icon_info->pixbuf);
6462 icon_info->pixbuf = NULL;
6465 switch (icon_info->storage_type)
6467 case GTK_IMAGE_PIXBUF:
6468 g_object_notify (G_OBJECT (entry),
6469 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-pixbuf" : "secondary-icon-pixbuf");
6472 case GTK_IMAGE_STOCK:
6473 g_free (icon_info->stock_id);
6474 icon_info->stock_id = NULL;
6475 g_object_notify (G_OBJECT (entry),
6476 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-stock" : "secondary-icon-stock");
6479 case GTK_IMAGE_ICON_NAME:
6480 g_free (icon_info->icon_name);
6481 icon_info->icon_name = NULL;
6482 g_object_notify (G_OBJECT (entry),
6483 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-name" : "secondary-icon-name");
6486 case GTK_IMAGE_GICON:
6487 if (icon_info->gicon)
6489 g_object_unref (icon_info->gicon);
6490 icon_info->gicon = NULL;
6492 g_object_notify (G_OBJECT (entry),
6493 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-gicon" : "secondary-icon-gicon");
6497 g_assert_not_reached ();
6501 icon_info->storage_type = GTK_IMAGE_EMPTY;
6502 g_object_notify (G_OBJECT (entry),
6503 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-storage-type" : "secondary-icon-storage-type");
6505 g_object_thaw_notify (G_OBJECT (entry));
6509 gtk_entry_ensure_pixbuf (GtkEntry *entry,
6510 GtkEntryIconPosition icon_pos)
6512 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
6513 EntryIconInfo *icon_info = priv->icons[icon_pos];
6515 GtkIconTheme *icon_theme;
6516 GtkSettings *settings;
6522 if (!icon_info || icon_info->pixbuf)
6525 widget = GTK_WIDGET (entry);
6527 switch (icon_info->storage_type)
6529 case GTK_IMAGE_EMPTY:
6530 case GTK_IMAGE_PIXBUF:
6532 case GTK_IMAGE_STOCK:
6533 state = gtk_widget_get_state (widget);
6534 gtk_widget_set_state (widget, GTK_STATE_NORMAL);
6535 icon_info->pixbuf = gtk_widget_render_icon (widget,
6536 icon_info->stock_id,
6539 if (!icon_info->pixbuf)
6540 icon_info->pixbuf = gtk_widget_render_icon (widget,
6541 GTK_STOCK_MISSING_IMAGE,
6544 gtk_widget_set_state (widget, state);
6547 case GTK_IMAGE_ICON_NAME:
6548 screen = gtk_widget_get_screen (widget);
6551 icon_theme = gtk_icon_theme_get_for_screen (screen);
6552 settings = gtk_settings_get_for_screen (screen);
6554 gtk_icon_size_lookup_for_settings (settings,
6558 icon_info->pixbuf = gtk_icon_theme_load_icon (icon_theme,
6559 icon_info->icon_name,
6560 MIN (width, height),
6563 if (icon_info->pixbuf == NULL)
6565 state = gtk_widget_get_state (widget);
6566 gtk_widget_set_state (widget, GTK_STATE_NORMAL);
6567 icon_info->pixbuf = gtk_widget_render_icon (widget,
6568 GTK_STOCK_MISSING_IMAGE,
6571 gtk_widget_set_state (widget, state);
6576 case GTK_IMAGE_GICON:
6577 screen = gtk_widget_get_screen (widget);
6580 icon_theme = gtk_icon_theme_get_for_screen (screen);
6581 settings = gtk_settings_get_for_screen (screen);
6583 gtk_icon_size_lookup_for_settings (settings,
6587 info = gtk_icon_theme_lookup_by_gicon (icon_theme,
6589 MIN (width, height),
6590 GTK_ICON_LOOKUP_USE_BUILTIN);
6593 icon_info->pixbuf = gtk_icon_info_load_icon (info, NULL);
6594 gtk_icon_info_free (info);
6597 if (icon_info->pixbuf == NULL)
6599 state = gtk_widget_get_state (widget);
6600 gtk_widget_set_state (widget, GTK_STATE_NORMAL);
6601 icon_info->pixbuf = gtk_widget_render_icon (widget,
6602 GTK_STOCK_MISSING_IMAGE,
6605 gtk_widget_set_state (widget, state);
6611 g_assert_not_reached ();
6615 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
6616 gdk_window_show_unraised (icon_info->window);
6626 * Creates a new entry.
6628 * Return value: a new #GtkEntry.
6631 gtk_entry_new (void)
6633 return g_object_new (GTK_TYPE_ENTRY, NULL);
6637 * gtk_entry_new_with_buffer:
6638 * @buffer: The buffer to use for the new #GtkEntry.
6640 * Creates a new entry with the specified text buffer.
6642 * Return value: a new #GtkEntry
6647 gtk_entry_new_with_buffer (GtkEntryBuffer *buffer)
6649 g_return_val_if_fail (GTK_IS_ENTRY_BUFFER (buffer), NULL);
6650 return g_object_new (GTK_TYPE_ENTRY, "buffer", buffer, NULL);
6653 static GtkEntryBuffer*
6654 get_buffer (GtkEntry *entry)
6656 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
6658 if (priv->buffer == NULL)
6660 GtkEntryBuffer *buffer;
6661 buffer = gtk_entry_buffer_new (NULL, 0);
6662 gtk_entry_set_buffer (entry, buffer);
6663 g_object_unref (buffer);
6666 return priv->buffer;
6670 * gtk_entry_get_buffer:
6671 * @entry: a #GtkEntry
6673 * Get the #GtkEntryBuffer object which holds the text for
6678 * Returns: (transfer none): A #GtkEntryBuffer object.
6681 gtk_entry_get_buffer (GtkEntry *entry)
6683 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
6685 return get_buffer (entry);
6689 * gtk_entry_set_buffer:
6690 * @entry: a #GtkEntry
6691 * @buffer: a #GtkEntryBuffer
6693 * Set the #GtkEntryBuffer object which holds the text for
6699 gtk_entry_set_buffer (GtkEntry *entry,
6700 GtkEntryBuffer *buffer)
6702 GtkEntryPrivate *priv;
6705 g_return_if_fail (GTK_IS_ENTRY (entry));
6706 priv = GTK_ENTRY_GET_PRIVATE (entry);
6710 g_return_if_fail (GTK_IS_ENTRY_BUFFER (buffer));
6711 g_object_ref (buffer);
6716 buffer_disconnect_signals (entry);
6717 g_object_unref (priv->buffer);
6720 priv->buffer = buffer;
6723 buffer_connect_signals (entry);
6725 obj = G_OBJECT (entry);
6726 g_object_freeze_notify (obj);
6727 g_object_notify (obj, "buffer");
6728 g_object_notify (obj, "text");
6729 g_object_notify (obj, "text-length");
6730 g_object_notify (obj, "max-length");
6731 g_object_notify (obj, "visibility");
6732 g_object_notify (obj, "invisible-char");
6733 g_object_notify (obj, "invisible-char-set");
6734 g_object_thaw_notify (obj);
6736 gtk_editable_set_position (GTK_EDITABLE (entry), 0);
6737 gtk_entry_recompute (entry);
6741 * gtk_entry_get_text_window:
6742 * @entry: a #GtkEntry
6744 * Returns the #GdkWindow which contains the text. This function is
6745 * useful when drawing something to the entry in a draw
6746 * callback because it enables the callback to distinguish between
6747 * the text window and entry's icon windows.
6749 * See also gtk_entry_get_icon_window().
6751 * Return value: (transfer none): the entry's text window.
6756 gtk_entry_get_text_window (GtkEntry *entry)
6758 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
6760 return entry->text_area;
6765 * gtk_entry_set_text:
6766 * @entry: a #GtkEntry
6767 * @text: the new text
6769 * Sets the text in the widget to the given
6770 * value, replacing the current contents.
6772 * See gtk_entry_buffer_set_text().
6775 gtk_entry_set_text (GtkEntry *entry,
6779 GtkEntryCompletion *completion;
6780 GtkEntryPrivate *priv;
6782 g_return_if_fail (GTK_IS_ENTRY (entry));
6783 g_return_if_fail (text != NULL);
6784 priv = GTK_ENTRY_GET_PRIVATE (entry);
6786 /* Actually setting the text will affect the cursor and selection;
6787 * if the contents don't actually change, this will look odd to the user.
6789 if (strcmp (gtk_entry_buffer_get_text (get_buffer (entry)), text) == 0)
6792 completion = gtk_entry_get_completion (entry);
6793 if (completion && completion->priv->changed_id > 0)
6794 g_signal_handler_block (entry, completion->priv->changed_id);
6796 begin_change (entry);
6797 g_object_freeze_notify (G_OBJECT (entry));
6798 gtk_editable_delete_text (GTK_EDITABLE (entry), 0, -1);
6800 gtk_editable_insert_text (GTK_EDITABLE (entry), text, strlen (text), &tmp_pos);
6801 g_object_thaw_notify (G_OBJECT (entry));
6804 if (completion && completion->priv->changed_id > 0)
6805 g_signal_handler_unblock (entry, completion->priv->changed_id);
6809 * gtk_entry_set_visibility:
6810 * @entry: a #GtkEntry
6811 * @visible: %TRUE if the contents of the entry are displayed
6814 * Sets whether the contents of the entry are visible or not.
6815 * When visibility is set to %FALSE, characters are displayed
6816 * as the invisible char, and will also appear that way when
6817 * the text in the entry widget is copied elsewhere.
6819 * By default, GTK+ picks the best invisible character available
6820 * in the current font, but it can be changed with
6821 * gtk_entry_set_invisible_char().
6824 gtk_entry_set_visibility (GtkEntry *entry,
6827 g_return_if_fail (GTK_IS_ENTRY (entry));
6829 visible = visible != FALSE;
6831 if (entry->visible != visible)
6833 entry->visible = visible;
6835 g_object_notify (G_OBJECT (entry), "visibility");
6836 gtk_entry_recompute (entry);
6841 * gtk_entry_get_visibility:
6842 * @entry: a #GtkEntry
6844 * Retrieves whether the text in @entry is visible. See
6845 * gtk_entry_set_visibility().
6847 * Return value: %TRUE if the text is currently visible
6850 gtk_entry_get_visibility (GtkEntry *entry)
6852 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
6854 return entry->visible;
6858 * gtk_entry_set_invisible_char:
6859 * @entry: a #GtkEntry
6860 * @ch: a Unicode character
6862 * Sets the character to use in place of the actual text when
6863 * gtk_entry_set_visibility() has been called to set text visibility
6864 * to %FALSE. i.e. this is the character used in "password mode" to
6865 * show the user how many characters have been typed. By default, GTK+
6866 * picks the best invisible char available in the current font. If you
6867 * set the invisible char to 0, then the user will get no feedback
6868 * at all; there will be no text on the screen as they type.
6871 gtk_entry_set_invisible_char (GtkEntry *entry,
6874 GtkEntryPrivate *priv;
6876 g_return_if_fail (GTK_IS_ENTRY (entry));
6878 priv = GTK_ENTRY_GET_PRIVATE (entry);
6880 if (!priv->invisible_char_set)
6882 priv->invisible_char_set = TRUE;
6883 g_object_notify (G_OBJECT (entry), "invisible-char-set");
6886 if (ch == entry->invisible_char)
6889 entry->invisible_char = ch;
6890 g_object_notify (G_OBJECT (entry), "invisible-char");
6891 gtk_entry_recompute (entry);
6895 * gtk_entry_get_invisible_char:
6896 * @entry: a #GtkEntry
6898 * Retrieves the character displayed in place of the real characters
6899 * for entries with visibility set to false. See gtk_entry_set_invisible_char().
6901 * Return value: the current invisible char, or 0, if the entry does not
6902 * show invisible text at all.
6905 gtk_entry_get_invisible_char (GtkEntry *entry)
6907 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
6909 return entry->invisible_char;
6913 * gtk_entry_unset_invisible_char:
6914 * @entry: a #GtkEntry
6916 * Unsets the invisible char previously set with
6917 * gtk_entry_set_invisible_char(). So that the
6918 * default invisible char is used again.
6923 gtk_entry_unset_invisible_char (GtkEntry *entry)
6925 GtkEntryPrivate *priv;
6928 g_return_if_fail (GTK_IS_ENTRY (entry));
6930 priv = GTK_ENTRY_GET_PRIVATE (entry);
6932 if (!priv->invisible_char_set)
6935 priv->invisible_char_set = FALSE;
6936 ch = find_invisible_char (GTK_WIDGET (entry));
6938 if (entry->invisible_char != ch)
6940 entry->invisible_char = ch;
6941 g_object_notify (G_OBJECT (entry), "invisible-char");
6944 g_object_notify (G_OBJECT (entry), "invisible-char-set");
6945 gtk_entry_recompute (entry);
6949 * gtk_entry_set_overwrite_mode:
6950 * @entry: a #GtkEntry
6951 * @overwrite: new value
6953 * Sets whether the text is overwritten when typing in the #GtkEntry.
6958 gtk_entry_set_overwrite_mode (GtkEntry *entry,
6961 g_return_if_fail (GTK_IS_ENTRY (entry));
6963 if (entry->overwrite_mode == overwrite)
6966 gtk_entry_toggle_overwrite (entry);
6968 g_object_notify (G_OBJECT (entry), "overwrite-mode");
6972 * gtk_entry_get_overwrite_mode:
6973 * @entry: a #GtkEntry
6975 * Gets the value set by gtk_entry_set_overwrite_mode().
6977 * Return value: whether the text is overwritten when typing.
6982 gtk_entry_get_overwrite_mode (GtkEntry *entry)
6984 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
6986 return entry->overwrite_mode;
6990 * gtk_entry_get_text:
6991 * @entry: a #GtkEntry
6993 * Retrieves the contents of the entry widget.
6994 * See also gtk_editable_get_chars().
6996 * This is equivalent to:
6998 * <informalexample><programlisting>
6999 * gtk_entry_buffer_get_text (gtk_entry_get_buffer (entry));
7000 * </programlisting></informalexample>
7002 * Return value: a pointer to the contents of the widget as a
7003 * string. This string points to internally allocated
7004 * storage in the widget and must not be freed, modified or
7007 G_CONST_RETURN gchar*
7008 gtk_entry_get_text (GtkEntry *entry)
7010 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7011 return gtk_entry_buffer_get_text (get_buffer (entry));
7015 * gtk_entry_set_max_length:
7016 * @entry: a #GtkEntry
7017 * @max: the maximum length of the entry, or 0 for no maximum.
7018 * (other than the maximum length of entries.) The value passed in will
7019 * be clamped to the range 0-65536.
7021 * Sets the maximum allowed length of the contents of the widget. If
7022 * the current contents are longer than the given length, then they
7023 * will be truncated to fit.
7025 * This is equivalent to:
7027 * <informalexample><programlisting>
7028 * gtk_entry_buffer_set_max_length (gtk_entry_get_buffer (entry), max);
7029 * </programlisting></informalexample>
7032 gtk_entry_set_max_length (GtkEntry *entry,
7035 g_return_if_fail (GTK_IS_ENTRY (entry));
7036 gtk_entry_buffer_set_max_length (get_buffer (entry), max);
7040 * gtk_entry_get_max_length:
7041 * @entry: a #GtkEntry
7043 * Retrieves the maximum allowed length of the text in
7044 * @entry. See gtk_entry_set_max_length().
7046 * This is equivalent to:
7048 * <informalexample><programlisting>
7049 * gtk_entry_buffer_get_max_length (gtk_entry_get_buffer (entry));
7050 * </programlisting></informalexample>
7052 * Return value: the maximum allowed number of characters
7053 * in #GtkEntry, or 0 if there is no maximum.
7056 gtk_entry_get_max_length (GtkEntry *entry)
7058 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7059 return gtk_entry_buffer_get_max_length (get_buffer (entry));
7063 * gtk_entry_get_text_length:
7064 * @entry: a #GtkEntry
7066 * Retrieves the current length of the text in
7069 * This is equivalent to:
7071 * <informalexample><programlisting>
7072 * gtk_entry_buffer_get_length (gtk_entry_get_buffer (entry));
7073 * </programlisting></informalexample>
7075 * Return value: the current number of characters
7076 * in #GtkEntry, or 0 if there are none.
7081 gtk_entry_get_text_length (GtkEntry *entry)
7083 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7084 return gtk_entry_buffer_get_length (get_buffer (entry));
7088 * gtk_entry_set_activates_default:
7089 * @entry: a #GtkEntry
7090 * @setting: %TRUE to activate window's default widget on Enter keypress
7092 * If @setting is %TRUE, pressing Enter in the @entry will activate the default
7093 * widget for the window containing the entry. This usually means that
7094 * the dialog box containing the entry will be closed, since the default
7095 * widget is usually one of the dialog buttons.
7097 * (For experts: if @setting is %TRUE, the entry calls
7098 * gtk_window_activate_default() on the window containing the entry, in
7099 * the default handler for the #GtkWidget::activate signal.)
7102 gtk_entry_set_activates_default (GtkEntry *entry,
7105 g_return_if_fail (GTK_IS_ENTRY (entry));
7106 setting = setting != FALSE;
7108 if (setting != entry->activates_default)
7110 entry->activates_default = setting;
7111 g_object_notify (G_OBJECT (entry), "activates-default");
7116 * gtk_entry_get_activates_default:
7117 * @entry: a #GtkEntry
7119 * Retrieves the value set by gtk_entry_set_activates_default().
7121 * Return value: %TRUE if the entry will activate the default widget
7124 gtk_entry_get_activates_default (GtkEntry *entry)
7126 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7128 return entry->activates_default;
7132 * gtk_entry_set_width_chars:
7133 * @entry: a #GtkEntry
7134 * @n_chars: width in chars
7136 * Changes the size request of the entry to be about the right size
7137 * for @n_chars characters. Note that it changes the size
7138 * <emphasis>request</emphasis>, the size can still be affected by
7139 * how you pack the widget into containers. If @n_chars is -1, the
7140 * size reverts to the default entry size.
7143 gtk_entry_set_width_chars (GtkEntry *entry,
7146 g_return_if_fail (GTK_IS_ENTRY (entry));
7148 if (entry->width_chars != n_chars)
7150 entry->width_chars = n_chars;
7151 g_object_notify (G_OBJECT (entry), "width-chars");
7152 gtk_widget_queue_resize (GTK_WIDGET (entry));
7157 * gtk_entry_get_width_chars:
7158 * @entry: a #GtkEntry
7160 * Gets the value set by gtk_entry_set_width_chars().
7162 * Return value: number of chars to request space for, or negative if unset
7165 gtk_entry_get_width_chars (GtkEntry *entry)
7167 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7169 return entry->width_chars;
7173 * gtk_entry_set_has_frame:
7174 * @entry: a #GtkEntry
7175 * @setting: new value
7177 * Sets whether the entry has a beveled frame around it.
7180 gtk_entry_set_has_frame (GtkEntry *entry,
7183 g_return_if_fail (GTK_IS_ENTRY (entry));
7185 setting = (setting != FALSE);
7187 if (entry->has_frame == setting)
7190 gtk_widget_queue_resize (GTK_WIDGET (entry));
7191 entry->has_frame = setting;
7192 g_object_notify (G_OBJECT (entry), "has-frame");
7196 * gtk_entry_get_has_frame:
7197 * @entry: a #GtkEntry
7199 * Gets the value set by gtk_entry_set_has_frame().
7201 * Return value: whether the entry has a beveled frame
7204 gtk_entry_get_has_frame (GtkEntry *entry)
7206 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7208 return entry->has_frame;
7212 * gtk_entry_set_inner_border:
7213 * @entry: a #GtkEntry
7214 * @border: (allow-none): a #GtkBorder, or %NULL
7216 * Sets %entry's inner-border property to %border, or clears it if %NULL
7217 * is passed. The inner-border is the area around the entry's text, but
7220 * If set, this property overrides the inner-border style property.
7221 * Overriding the style-provided border is useful when you want to do
7222 * in-place editing of some text in a canvas or list widget, where
7223 * pixel-exact positioning of the entry is important.
7228 gtk_entry_set_inner_border (GtkEntry *entry,
7229 const GtkBorder *border)
7231 g_return_if_fail (GTK_IS_ENTRY (entry));
7233 gtk_widget_queue_resize (GTK_WIDGET (entry));
7236 g_object_set_qdata_full (G_OBJECT (entry), quark_inner_border,
7237 gtk_border_copy (border),
7238 (GDestroyNotify) gtk_border_free);
7240 g_object_set_qdata (G_OBJECT (entry), quark_inner_border, NULL);
7242 g_object_notify (G_OBJECT (entry), "inner-border");
7246 * gtk_entry_get_inner_border:
7247 * @entry: a #GtkEntry
7249 * This function returns the entry's #GtkEntry:inner-border property. See
7250 * gtk_entry_set_inner_border() for more information.
7252 * Return value: (transfer none): the entry's #GtkBorder, or %NULL if none was set.
7256 G_CONST_RETURN GtkBorder *
7257 gtk_entry_get_inner_border (GtkEntry *entry)
7259 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7261 return g_object_get_qdata (G_OBJECT (entry), quark_inner_border);
7265 * gtk_entry_get_layout:
7266 * @entry: a #GtkEntry
7268 * Gets the #PangoLayout used to display the entry.
7269 * The layout is useful to e.g. convert text positions to
7270 * pixel positions, in combination with gtk_entry_get_layout_offsets().
7271 * The returned layout is owned by the entry and must not be
7272 * modified or freed by the caller.
7274 * Keep in mind that the layout text may contain a preedit string, so
7275 * gtk_entry_layout_index_to_text_index() and
7276 * gtk_entry_text_index_to_layout_index() are needed to convert byte
7277 * indices in the layout to byte indices in the entry contents.
7279 * Return value: (transfer none): the #PangoLayout for this entry
7282 gtk_entry_get_layout (GtkEntry *entry)
7284 PangoLayout *layout;
7286 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7288 layout = gtk_entry_ensure_layout (entry, TRUE);
7295 * gtk_entry_layout_index_to_text_index:
7296 * @entry: a #GtkEntry
7297 * @layout_index: byte index into the entry layout text
7299 * Converts from a position in the entry contents (returned
7300 * by gtk_entry_get_text()) to a position in the
7301 * entry's #PangoLayout (returned by gtk_entry_get_layout(),
7302 * with text retrieved via pango_layout_get_text()).
7304 * Return value: byte index into the entry contents
7307 gtk_entry_layout_index_to_text_index (GtkEntry *entry,
7310 PangoLayout *layout;
7314 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7316 layout = gtk_entry_ensure_layout (entry, TRUE);
7317 text = pango_layout_get_text (layout);
7318 cursor_index = g_utf8_offset_to_pointer (text, entry->current_pos) - text;
7320 if (layout_index >= cursor_index && entry->preedit_length)
7322 if (layout_index >= cursor_index + entry->preedit_length)
7323 layout_index -= entry->preedit_length;
7325 layout_index = cursor_index;
7328 return layout_index;
7332 * gtk_entry_text_index_to_layout_index:
7333 * @entry: a #GtkEntry
7334 * @text_index: byte index into the entry contents
7336 * Converts from a position in the entry's #PangoLayout (returned by
7337 * gtk_entry_get_layout()) to a position in the entry contents
7338 * (returned by gtk_entry_get_text()).
7340 * Return value: byte index into the entry layout text
7343 gtk_entry_text_index_to_layout_index (GtkEntry *entry,
7346 PangoLayout *layout;
7349 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7351 layout = gtk_entry_ensure_layout (entry, TRUE);
7352 text = pango_layout_get_text (layout);
7353 cursor_index = g_utf8_offset_to_pointer (text, entry->current_pos) - text;
7355 if (text_index > cursor_index)
7356 text_index += entry->preedit_length;
7362 * gtk_entry_get_layout_offsets:
7363 * @entry: a #GtkEntry
7364 * @x: (allow-none): location to store X offset of layout, or %NULL
7365 * @y: (allow-none): location to store Y offset of layout, or %NULL
7368 * Obtains the position of the #PangoLayout used to render text
7369 * in the entry, in widget coordinates. Useful if you want to line
7370 * up the text in an entry with some other text, e.g. when using the
7371 * entry to implement editable cells in a sheet widget.
7373 * Also useful to convert mouse events into coordinates inside the
7374 * #PangoLayout, e.g. to take some action if some part of the entry text
7377 * Note that as the user scrolls around in the entry the offsets will
7378 * change; you'll need to connect to the "notify::scroll-offset"
7379 * signal to track this. Remember when using the #PangoLayout
7380 * functions you need to convert to and from pixels using
7381 * PANGO_PIXELS() or #PANGO_SCALE.
7383 * Keep in mind that the layout text may contain a preedit string, so
7384 * gtk_entry_layout_index_to_text_index() and
7385 * gtk_entry_text_index_to_layout_index() are needed to convert byte
7386 * indices in the layout to byte indices in the entry contents.
7389 gtk_entry_get_layout_offsets (GtkEntry *entry,
7393 gint text_area_x, text_area_y;
7395 g_return_if_fail (GTK_IS_ENTRY (entry));
7397 /* this gets coords relative to text area */
7398 get_layout_position (entry, x, y);
7400 /* convert to widget coords */
7401 gtk_entry_get_text_area_size (entry, &text_area_x, &text_area_y, NULL, NULL);
7412 * gtk_entry_set_alignment:
7413 * @entry: a #GtkEntry
7414 * @xalign: The horizontal alignment, from 0 (left) to 1 (right).
7415 * Reversed for RTL layouts
7417 * Sets the alignment for the contents of the entry. This controls
7418 * the horizontal positioning of the contents when the displayed
7419 * text is shorter than the width of the entry.
7424 gtk_entry_set_alignment (GtkEntry *entry, gfloat xalign)
7426 GtkEntryPrivate *priv;
7428 g_return_if_fail (GTK_IS_ENTRY (entry));
7430 priv = GTK_ENTRY_GET_PRIVATE (entry);
7434 else if (xalign > 1.0)
7437 if (xalign != priv->xalign)
7439 priv->xalign = xalign;
7441 gtk_entry_recompute (entry);
7443 g_object_notify (G_OBJECT (entry), "xalign");
7448 * gtk_entry_get_alignment:
7449 * @entry: a #GtkEntry
7451 * Gets the value set by gtk_entry_set_alignment().
7453 * Return value: the alignment
7458 gtk_entry_get_alignment (GtkEntry *entry)
7460 GtkEntryPrivate *priv;
7462 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
7464 priv = GTK_ENTRY_GET_PRIVATE (entry);
7466 return priv->xalign;
7470 * gtk_entry_set_icon_from_pixbuf:
7471 * @entry: a #GtkEntry
7472 * @icon_pos: Icon position
7473 * @pixbuf: (allow-none): A #GdkPixbuf, or %NULL
7475 * Sets the icon shown in the specified position using a pixbuf.
7477 * If @pixbuf is %NULL, no icon will be shown in the specified position.
7482 gtk_entry_set_icon_from_pixbuf (GtkEntry *entry,
7483 GtkEntryIconPosition icon_pos,
7486 GtkEntryPrivate *priv;
7487 EntryIconInfo *icon_info;
7489 g_return_if_fail (GTK_IS_ENTRY (entry));
7490 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7492 priv = GTK_ENTRY_GET_PRIVATE (entry);
7494 if ((icon_info = priv->icons[icon_pos]) == NULL)
7495 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7497 g_object_freeze_notify (G_OBJECT (entry));
7500 g_object_ref (pixbuf);
7502 gtk_entry_clear (entry, icon_pos);
7506 icon_info->storage_type = GTK_IMAGE_PIXBUF;
7507 icon_info->pixbuf = pixbuf;
7509 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7511 g_object_notify (G_OBJECT (entry), "primary-icon-pixbuf");
7512 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7516 g_object_notify (G_OBJECT (entry), "secondary-icon-pixbuf");
7517 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7520 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7521 gdk_window_show_unraised (icon_info->window);
7524 gtk_entry_ensure_pixbuf (entry, icon_pos);
7526 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7527 gtk_widget_queue_resize (GTK_WIDGET (entry));
7529 g_object_thaw_notify (G_OBJECT (entry));
7533 * gtk_entry_set_icon_from_stock:
7534 * @entry: A #GtkEntry
7535 * @icon_pos: Icon position
7536 * @stock_id: (allow-none): The name of the stock item, or %NULL
7538 * Sets the icon shown in the entry at the specified position from
7541 * If @stock_id is %NULL, no icon will be shown in the specified position.
7546 gtk_entry_set_icon_from_stock (GtkEntry *entry,
7547 GtkEntryIconPosition icon_pos,
7548 const gchar *stock_id)
7550 GtkEntryPrivate *priv;
7551 EntryIconInfo *icon_info;
7554 g_return_if_fail (GTK_IS_ENTRY (entry));
7555 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7557 priv = GTK_ENTRY_GET_PRIVATE (entry);
7559 if ((icon_info = priv->icons[icon_pos]) == NULL)
7560 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7562 g_object_freeze_notify (G_OBJECT (entry));
7564 gtk_widget_ensure_style (GTK_WIDGET (entry));
7566 /* need to dup before clearing */
7567 new_id = g_strdup (stock_id);
7569 gtk_entry_clear (entry, icon_pos);
7573 icon_info->storage_type = GTK_IMAGE_STOCK;
7574 icon_info->stock_id = new_id;
7576 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7578 g_object_notify (G_OBJECT (entry), "primary-icon-stock");
7579 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7583 g_object_notify (G_OBJECT (entry), "secondary-icon-stock");
7584 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7587 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7588 gdk_window_show_unraised (icon_info->window);
7591 gtk_entry_ensure_pixbuf (entry, icon_pos);
7593 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7594 gtk_widget_queue_resize (GTK_WIDGET (entry));
7596 g_object_thaw_notify (G_OBJECT (entry));
7600 * gtk_entry_set_icon_from_icon_name:
7601 * @entry: A #GtkEntry
7602 * @icon_pos: The position at which to set the icon
7603 * @icon_name: (allow-none): An icon name, or %NULL
7605 * Sets the icon shown in the entry at the specified position
7606 * from the current icon theme.
7608 * If the icon name isn't known, a "broken image" icon will be displayed
7611 * If @icon_name is %NULL, no icon will be shown in the specified position.
7616 gtk_entry_set_icon_from_icon_name (GtkEntry *entry,
7617 GtkEntryIconPosition icon_pos,
7618 const gchar *icon_name)
7620 GtkEntryPrivate *priv;
7621 EntryIconInfo *icon_info;
7624 g_return_if_fail (GTK_IS_ENTRY (entry));
7625 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7627 priv = GTK_ENTRY_GET_PRIVATE (entry);
7629 if ((icon_info = priv->icons[icon_pos]) == NULL)
7630 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7632 g_object_freeze_notify (G_OBJECT (entry));
7634 gtk_widget_ensure_style (GTK_WIDGET (entry));
7636 /* need to dup before clearing */
7637 new_name = g_strdup (icon_name);
7639 gtk_entry_clear (entry, icon_pos);
7641 if (new_name != NULL)
7643 icon_info->storage_type = GTK_IMAGE_ICON_NAME;
7644 icon_info->icon_name = new_name;
7646 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7648 g_object_notify (G_OBJECT (entry), "primary-icon-name");
7649 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7653 g_object_notify (G_OBJECT (entry), "secondary-icon-name");
7654 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7657 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7658 gdk_window_show_unraised (icon_info->window);
7661 gtk_entry_ensure_pixbuf (entry, icon_pos);
7663 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7664 gtk_widget_queue_resize (GTK_WIDGET (entry));
7666 g_object_thaw_notify (G_OBJECT (entry));
7670 * gtk_entry_set_icon_from_gicon:
7671 * @entry: A #GtkEntry
7672 * @icon_pos: The position at which to set the icon
7673 * @icon: (allow-none): The icon to set, or %NULL
7675 * Sets the icon shown in the entry at the specified position
7676 * from the current icon theme.
7677 * If the icon isn't known, a "broken image" icon will be displayed
7680 * If @icon is %NULL, no icon will be shown in the specified position.
7685 gtk_entry_set_icon_from_gicon (GtkEntry *entry,
7686 GtkEntryIconPosition icon_pos,
7689 GtkEntryPrivate *priv;
7690 EntryIconInfo *icon_info;
7692 g_return_if_fail (GTK_IS_ENTRY (entry));
7693 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7695 priv = GTK_ENTRY_GET_PRIVATE (entry);
7697 if ((icon_info = priv->icons[icon_pos]) == NULL)
7698 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7700 g_object_freeze_notify (G_OBJECT (entry));
7702 /* need to ref before clearing */
7704 g_object_ref (icon);
7706 gtk_entry_clear (entry, icon_pos);
7710 icon_info->storage_type = GTK_IMAGE_GICON;
7711 icon_info->gicon = icon;
7713 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7715 g_object_notify (G_OBJECT (entry), "primary-icon-gicon");
7716 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7720 g_object_notify (G_OBJECT (entry), "secondary-icon-gicon");
7721 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7724 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7725 gdk_window_show_unraised (icon_info->window);
7728 gtk_entry_ensure_pixbuf (entry, icon_pos);
7730 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7731 gtk_widget_queue_resize (GTK_WIDGET (entry));
7733 g_object_thaw_notify (G_OBJECT (entry));
7737 * gtk_entry_set_icon_activatable:
7738 * @entry: A #GtkEntry
7739 * @icon_pos: Icon position
7740 * @activatable: %TRUE if the icon should be activatable
7742 * Sets whether the icon is activatable.
7747 gtk_entry_set_icon_activatable (GtkEntry *entry,
7748 GtkEntryIconPosition icon_pos,
7749 gboolean activatable)
7751 GtkEntryPrivate *priv;
7752 EntryIconInfo *icon_info;
7754 g_return_if_fail (GTK_IS_ENTRY (entry));
7755 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7757 priv = GTK_ENTRY_GET_PRIVATE (entry);
7759 if ((icon_info = priv->icons[icon_pos]) == NULL)
7760 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7762 activatable = activatable != FALSE;
7764 if (icon_info->nonactivatable != !activatable)
7766 icon_info->nonactivatable = !activatable;
7768 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
7769 update_cursors (GTK_WIDGET (entry));
7771 g_object_notify (G_OBJECT (entry),
7772 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-activatable" : "secondary-icon-activatable");
7777 * gtk_entry_get_icon_activatable:
7778 * @entry: a #GtkEntry
7779 * @icon_pos: Icon position
7781 * Returns whether the icon is activatable.
7783 * Returns: %TRUE if the icon is activatable.
7788 gtk_entry_get_icon_activatable (GtkEntry *entry,
7789 GtkEntryIconPosition icon_pos)
7791 GtkEntryPrivate *priv;
7792 EntryIconInfo *icon_info;
7794 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7795 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), FALSE);
7797 priv = GTK_ENTRY_GET_PRIVATE (entry);
7798 icon_info = priv->icons[icon_pos];
7800 return (icon_info != NULL && !icon_info->nonactivatable);
7804 * gtk_entry_get_icon_pixbuf:
7805 * @entry: A #GtkEntry
7806 * @icon_pos: Icon position
7808 * Retrieves the image used for the icon.
7810 * Unlike the other methods of setting and getting icon data, this
7811 * method will work regardless of whether the icon was set using a
7812 * #GdkPixbuf, a #GIcon, a stock item, or an icon name.
7814 * Returns: (transfer none): A #GdkPixbuf, or %NULL if no icon is
7815 * set for this position.
7820 gtk_entry_get_icon_pixbuf (GtkEntry *entry,
7821 GtkEntryIconPosition icon_pos)
7823 GtkEntryPrivate *priv;
7824 EntryIconInfo *icon_info;
7826 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7827 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7829 priv = GTK_ENTRY_GET_PRIVATE (entry);
7830 icon_info = priv->icons[icon_pos];
7835 gtk_entry_ensure_pixbuf (entry, icon_pos);
7837 return icon_info->pixbuf;
7841 * gtk_entry_get_icon_gicon:
7842 * @entry: A #GtkEntry
7843 * @icon_pos: Icon position
7845 * Retrieves the #GIcon used for the icon, or %NULL if there is
7846 * no icon or if the icon was set by some other method (e.g., by
7847 * stock, pixbuf, or icon name).
7849 * Returns: (transfer none): A #GIcon, or %NULL if no icon is set
7850 * or if the icon is not a #GIcon
7855 gtk_entry_get_icon_gicon (GtkEntry *entry,
7856 GtkEntryIconPosition icon_pos)
7858 GtkEntryPrivate *priv;
7859 EntryIconInfo *icon_info;
7861 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7862 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7864 priv = GTK_ENTRY_GET_PRIVATE (entry);
7865 icon_info = priv->icons[icon_pos];
7870 return icon_info->storage_type == GTK_IMAGE_GICON ? icon_info->gicon : NULL;
7874 * gtk_entry_get_icon_stock:
7875 * @entry: A #GtkEntry
7876 * @icon_pos: Icon position
7878 * Retrieves the stock id used for the icon, or %NULL if there is
7879 * no icon or if the icon was set by some other method (e.g., by
7880 * pixbuf, icon name or gicon).
7882 * Returns: A stock id, or %NULL if no icon is set or if the icon
7883 * wasn't set from a stock id
7888 gtk_entry_get_icon_stock (GtkEntry *entry,
7889 GtkEntryIconPosition icon_pos)
7891 GtkEntryPrivate *priv;
7892 EntryIconInfo *icon_info;
7894 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7895 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7897 priv = GTK_ENTRY_GET_PRIVATE (entry);
7898 icon_info = priv->icons[icon_pos];
7903 return icon_info->storage_type == GTK_IMAGE_STOCK ? icon_info->stock_id : NULL;
7907 * gtk_entry_get_icon_name:
7908 * @entry: A #GtkEntry
7909 * @icon_pos: Icon position
7911 * Retrieves the icon name used for the icon, or %NULL if there is
7912 * no icon or if the icon was set by some other method (e.g., by
7913 * pixbuf, stock or gicon).
7915 * Returns: An icon name, or %NULL if no icon is set or if the icon
7916 * wasn't set from an icon name
7921 gtk_entry_get_icon_name (GtkEntry *entry,
7922 GtkEntryIconPosition icon_pos)
7924 GtkEntryPrivate *priv;
7925 EntryIconInfo *icon_info;
7927 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7928 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7930 priv = GTK_ENTRY_GET_PRIVATE (entry);
7931 icon_info = priv->icons[icon_pos];
7936 return icon_info->storage_type == GTK_IMAGE_ICON_NAME ? icon_info->icon_name : NULL;
7940 * gtk_entry_set_icon_sensitive:
7941 * @entry: A #GtkEntry
7942 * @icon_pos: Icon position
7943 * @sensitive: Specifies whether the icon should appear
7944 * sensitive or insensitive
7946 * Sets the sensitivity for the specified icon.
7951 gtk_entry_set_icon_sensitive (GtkEntry *entry,
7952 GtkEntryIconPosition icon_pos,
7955 GtkEntryPrivate *priv;
7956 EntryIconInfo *icon_info;
7958 g_return_if_fail (GTK_IS_ENTRY (entry));
7959 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7961 priv = GTK_ENTRY_GET_PRIVATE (entry);
7963 if ((icon_info = priv->icons[icon_pos]) == NULL)
7964 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7966 if (icon_info->insensitive != !sensitive)
7968 icon_info->insensitive = !sensitive;
7970 icon_info->pressed = FALSE;
7971 icon_info->prelight = FALSE;
7973 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
7974 update_cursors (GTK_WIDGET (entry));
7976 gtk_widget_queue_draw (GTK_WIDGET (entry));
7978 g_object_notify (G_OBJECT (entry),
7979 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-sensitive" : "secondary-icon-sensitive");
7984 * gtk_entry_get_icon_sensitive:
7985 * @entry: a #GtkEntry
7986 * @icon_pos: Icon position
7988 * Returns whether the icon appears sensitive or insensitive.
7990 * Returns: %TRUE if the icon is sensitive.
7995 gtk_entry_get_icon_sensitive (GtkEntry *entry,
7996 GtkEntryIconPosition icon_pos)
7998 GtkEntryPrivate *priv;
7999 EntryIconInfo *icon_info;
8001 g_return_val_if_fail (GTK_IS_ENTRY (entry), TRUE);
8002 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), TRUE);
8004 priv = GTK_ENTRY_GET_PRIVATE (entry);
8005 icon_info = priv->icons[icon_pos];
8007 return (!icon_info || !icon_info->insensitive);
8012 * gtk_entry_get_icon_storage_type:
8013 * @entry: a #GtkEntry
8014 * @icon_pos: Icon position
8016 * Gets the type of representation being used by the icon
8017 * to store image data. If the icon has no image data,
8018 * the return value will be %GTK_IMAGE_EMPTY.
8020 * Return value: image representation being used
8025 gtk_entry_get_icon_storage_type (GtkEntry *entry,
8026 GtkEntryIconPosition icon_pos)
8028 GtkEntryPrivate *priv;
8029 EntryIconInfo *icon_info;
8031 g_return_val_if_fail (GTK_IS_ENTRY (entry), GTK_IMAGE_EMPTY);
8032 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), GTK_IMAGE_EMPTY);
8034 priv = GTK_ENTRY_GET_PRIVATE (entry);
8035 icon_info = priv->icons[icon_pos];
8038 return GTK_IMAGE_EMPTY;
8040 return icon_info->storage_type;
8044 * gtk_entry_get_icon_at_pos:
8045 * @entry: a #GtkEntry
8046 * @x: the x coordinate of the position to find
8047 * @y: the y coordinate of the position to find
8049 * Finds the icon at the given position and return its index.
8050 * If @x, @y doesn't lie inside an icon, -1 is returned.
8051 * This function is intended for use in a #GtkWidget::query-tooltip
8054 * Returns: the index of the icon at the given position, or -1
8059 gtk_entry_get_icon_at_pos (GtkEntry *entry,
8063 GtkAllocation primary;
8064 GtkAllocation secondary;
8066 g_return_val_if_fail (GTK_IS_ENTRY (entry), -1);
8068 get_icon_allocations (entry, &primary, &secondary);
8070 if (primary.x <= x && x < primary.x + primary.width &&
8071 primary.y <= y && y < primary.y + primary.height)
8072 return GTK_ENTRY_ICON_PRIMARY;
8074 if (secondary.x <= x && x < secondary.x + secondary.width &&
8075 secondary.y <= y && y < secondary.y + secondary.height)
8076 return GTK_ENTRY_ICON_SECONDARY;
8082 * gtk_entry_set_icon_drag_source:
8083 * @entry: a #GtkIconEntry
8084 * @icon_pos: icon position
8085 * @target_list: the targets (data formats) in which the data can be provided
8086 * @actions: a bitmask of the allowed drag actions
8088 * Sets up the icon at the given position so that GTK+ will start a drag
8089 * operation when the user clicks and drags the icon.
8091 * To handle the drag operation, you need to connect to the usual
8092 * #GtkWidget::drag-data-get (or possibly #GtkWidget::drag-data-delete)
8093 * signal, and use gtk_entry_get_current_icon_drag_source() in
8094 * your signal handler to find out if the drag was started from
8097 * By default, GTK+ uses the icon as the drag icon. You can use the
8098 * #GtkWidget::drag-begin signal to set a different icon. Note that you
8099 * have to use g_signal_connect_after() to ensure that your signal handler
8100 * gets executed after the default handler.
8105 gtk_entry_set_icon_drag_source (GtkEntry *entry,
8106 GtkEntryIconPosition icon_pos,
8107 GtkTargetList *target_list,
8108 GdkDragAction actions)
8110 GtkEntryPrivate *priv;
8111 EntryIconInfo *icon_info;
8113 g_return_if_fail (GTK_IS_ENTRY (entry));
8114 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8116 priv = GTK_ENTRY_GET_PRIVATE (entry);
8118 if ((icon_info = priv->icons[icon_pos]) == NULL)
8119 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8121 if (icon_info->target_list)
8122 gtk_target_list_unref (icon_info->target_list);
8123 icon_info->target_list = target_list;
8124 if (icon_info->target_list)
8125 gtk_target_list_ref (icon_info->target_list);
8127 icon_info->actions = actions;
8131 * gtk_entry_get_current_icon_drag_source:
8132 * @entry: a #GtkIconEntry
8134 * Returns the index of the icon which is the source of the current
8135 * DND operation, or -1.
8137 * This function is meant to be used in a #GtkWidget::drag-data-get
8140 * Returns: index of the icon which is the source of the current
8141 * DND operation, or -1.
8146 gtk_entry_get_current_icon_drag_source (GtkEntry *entry)
8148 GtkEntryPrivate *priv;
8149 EntryIconInfo *icon_info = NULL;
8152 g_return_val_if_fail (GTK_IS_ENTRY (entry), -1);
8154 priv = GTK_ENTRY_GET_PRIVATE (entry);
8156 for (i = 0; i < MAX_ICONS; i++)
8158 if ((icon_info = priv->icons[i]))
8160 if (icon_info->in_drag)
8169 * gtk_entry_get_icon_window:
8170 * @entry: A #GtkEntry
8171 * @icon_pos: Icon position
8173 * Returns the #GdkWindow which contains the entry's icon at
8174 * @icon_pos. This function is useful when drawing something to the
8175 * entry in a draw callback because it enables the callback
8176 * to distinguish between the text window and entry's icon windows.
8178 * See also gtk_entry_get_text_window().
8180 * Return value: (transfer none): the entry's icon window at @icon_pos.
8185 gtk_entry_get_icon_window (GtkEntry *entry,
8186 GtkEntryIconPosition icon_pos)
8188 GtkEntryPrivate *priv;
8189 EntryIconInfo *icon_info;
8191 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8193 priv = GTK_ENTRY_GET_PRIVATE (entry);
8195 icon_info = priv->icons[icon_pos];
8198 return icon_info->window;
8204 ensure_has_tooltip (GtkEntry *entry)
8206 GtkEntryPrivate *priv;
8207 EntryIconInfo *icon_info;
8209 gboolean has_tooltip = FALSE;
8211 priv = GTK_ENTRY_GET_PRIVATE (entry);
8213 for (i = 0; i < MAX_ICONS; i++)
8215 if ((icon_info = priv->icons[i]) != NULL)
8217 if (icon_info->tooltip != NULL)
8225 gtk_widget_set_has_tooltip (GTK_WIDGET (entry), has_tooltip);
8229 * gtk_entry_get_icon_tooltip_text:
8230 * @entry: a #GtkEntry
8231 * @icon_pos: the icon position
8233 * Gets the contents of the tooltip on the icon at the specified
8234 * position in @entry.
8236 * Returns: the tooltip text, or %NULL. Free the returned string
8237 * with g_free() when done.
8242 gtk_entry_get_icon_tooltip_text (GtkEntry *entry,
8243 GtkEntryIconPosition icon_pos)
8245 GtkEntryPrivate *priv;
8246 EntryIconInfo *icon_info;
8249 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8250 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8252 priv = GTK_ENTRY_GET_PRIVATE (entry);
8253 icon_info = priv->icons[icon_pos];
8258 if (icon_info->tooltip &&
8259 !pango_parse_markup (icon_info->tooltip, -1, 0, NULL, &text, NULL, NULL))
8260 g_assert (NULL == text); /* text should still be NULL in case of markup errors */
8266 * gtk_entry_set_icon_tooltip_text:
8267 * @entry: a #GtkEntry
8268 * @icon_pos: the icon position
8269 * @tooltip: (allow-none): the contents of the tooltip for the icon, or %NULL
8271 * Sets @tooltip as the contents of the tooltip for the icon
8272 * at the specified position.
8274 * Use %NULL for @tooltip to remove an existing tooltip.
8276 * See also gtk_widget_set_tooltip_text() and
8277 * gtk_entry_set_icon_tooltip_markup().
8282 gtk_entry_set_icon_tooltip_text (GtkEntry *entry,
8283 GtkEntryIconPosition icon_pos,
8284 const gchar *tooltip)
8286 GtkEntryPrivate *priv;
8287 EntryIconInfo *icon_info;
8289 g_return_if_fail (GTK_IS_ENTRY (entry));
8290 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8292 priv = GTK_ENTRY_GET_PRIVATE (entry);
8294 if (!(icon_info = priv->icons[icon_pos]))
8295 icon_info = priv->icons[icon_pos];
8297 if (icon_info->tooltip)
8298 g_free (icon_info->tooltip);
8300 /* Treat an empty string as a NULL string,
8301 * because an empty string would be useless for a tooltip:
8303 if (tooltip && tooltip[0] == '\0')
8306 icon_info->tooltip = tooltip ? g_markup_escape_text (tooltip, -1) : NULL;
8308 ensure_has_tooltip (entry);
8312 * gtk_entry_get_icon_tooltip_markup:
8313 * @entry: a #GtkEntry
8314 * @icon_pos: the icon position
8316 * Gets the contents of the tooltip on the icon at the specified
8317 * position in @entry.
8319 * Returns: the tooltip text, or %NULL. Free the returned string
8320 * with g_free() when done.
8325 gtk_entry_get_icon_tooltip_markup (GtkEntry *entry,
8326 GtkEntryIconPosition icon_pos)
8328 GtkEntryPrivate *priv;
8329 EntryIconInfo *icon_info;
8331 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8332 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8334 priv = GTK_ENTRY_GET_PRIVATE (entry);
8335 icon_info = priv->icons[icon_pos];
8340 return g_strdup (icon_info->tooltip);
8344 * gtk_entry_set_icon_tooltip_markup:
8345 * @entry: a #GtkEntry
8346 * @icon_pos: the icon position
8347 * @tooltip: (allow-none): the contents of the tooltip for the icon, or %NULL
8349 * Sets @tooltip as the contents of the tooltip for the icon at
8350 * the specified position. @tooltip is assumed to be marked up with
8351 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
8353 * Use %NULL for @tooltip to remove an existing tooltip.
8355 * See also gtk_widget_set_tooltip_markup() and
8356 * gtk_enty_set_icon_tooltip_text().
8361 gtk_entry_set_icon_tooltip_markup (GtkEntry *entry,
8362 GtkEntryIconPosition icon_pos,
8363 const gchar *tooltip)
8365 GtkEntryPrivate *priv;
8366 EntryIconInfo *icon_info;
8368 g_return_if_fail (GTK_IS_ENTRY (entry));
8369 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8371 priv = GTK_ENTRY_GET_PRIVATE (entry);
8373 if (!(icon_info = priv->icons[icon_pos]))
8374 icon_info = priv->icons[icon_pos];
8376 if (icon_info->tooltip)
8377 g_free (icon_info->tooltip);
8379 /* Treat an empty string as a NULL string,
8380 * because an empty string would be useless for a tooltip:
8382 if (tooltip && tooltip[0] == '\0')
8385 icon_info->tooltip = g_strdup (tooltip);
8387 ensure_has_tooltip (entry);
8391 gtk_entry_query_tooltip (GtkWidget *widget,
8394 gboolean keyboard_tip,
8395 GtkTooltip *tooltip)
8398 GtkEntryPrivate *priv;
8399 EntryIconInfo *icon_info;
8402 entry = GTK_ENTRY (widget);
8403 priv = GTK_ENTRY_GET_PRIVATE (entry);
8407 icon_pos = gtk_entry_get_icon_at_pos (entry, x, y);
8410 if ((icon_info = priv->icons[icon_pos]) != NULL)
8412 if (icon_info->tooltip)
8414 gtk_tooltip_set_markup (tooltip, icon_info->tooltip);
8423 return GTK_WIDGET_CLASS (gtk_entry_parent_class)->query_tooltip (widget,
8430 /* Quick hack of a popup menu
8433 activate_cb (GtkWidget *menuitem,
8436 const gchar *signal = g_object_get_data (G_OBJECT (menuitem), "gtk-signal");
8437 g_signal_emit_by_name (entry, signal);
8442 gtk_entry_mnemonic_activate (GtkWidget *widget,
8443 gboolean group_cycling)
8445 gtk_widget_grab_focus (widget);
8450 append_action_signal (GtkEntry *entry,
8452 const gchar *stock_id,
8453 const gchar *signal,
8456 GtkWidget *menuitem = gtk_image_menu_item_new_from_stock (stock_id, NULL);
8458 g_object_set_data (G_OBJECT (menuitem), I_("gtk-signal"), (char *)signal);
8459 g_signal_connect (menuitem, "activate",
8460 G_CALLBACK (activate_cb), entry);
8462 gtk_widget_set_sensitive (menuitem, sensitive);
8464 gtk_widget_show (menuitem);
8465 gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
8469 popup_menu_detach (GtkWidget *attach_widget,
8472 GTK_ENTRY (attach_widget)->popup_menu = NULL;
8476 popup_position_func (GtkMenu *menu,
8482 GtkEntry *entry = GTK_ENTRY (user_data);
8483 GtkWidget *widget = GTK_WIDGET (entry);
8485 GtkRequisition menu_req;
8486 GdkRectangle monitor;
8487 GtkBorder inner_border;
8488 gint monitor_num, strong_x, height;
8490 g_return_if_fail (gtk_widget_get_realized (widget));
8492 gdk_window_get_origin (entry->text_area, x, y);
8494 screen = gtk_widget_get_screen (widget);
8495 monitor_num = gdk_screen_get_monitor_at_window (screen, entry->text_area);
8496 if (monitor_num < 0)
8498 gtk_menu_set_monitor (menu, monitor_num);
8500 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
8501 gtk_widget_get_preferred_size (entry->popup_menu,
8503 height = gdk_window_get_height (entry->text_area);
8504 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
8505 _gtk_entry_effective_inner_border (entry, &inner_border);
8507 *x += inner_border.left + strong_x - entry->scroll_offset;
8508 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
8509 *x -= menu_req.width;
8511 if ((*y + height + menu_req.height) <= monitor.y + monitor.height)
8513 else if ((*y - menu_req.height) >= monitor.y)
8514 *y -= menu_req.height;
8515 else if (monitor.y + monitor.height - (*y + height) > *y)
8518 *y -= menu_req.height;
8524 unichar_chosen_func (const char *text,
8527 GtkEntry *entry = GTK_ENTRY (data);
8529 if (entry->editable)
8530 gtk_entry_enter_text (entry, text);
8541 popup_targets_received (GtkClipboard *clipboard,
8542 GtkSelectionData *data,
8545 PopupInfo *info = user_data;
8546 GtkEntry *entry = info->entry;
8548 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
8551 gboolean clipboard_contains_text;
8552 GtkWidget *menuitem;
8554 gboolean show_input_method_menu;
8555 gboolean show_unicode_menu;
8557 clipboard_contains_text = gtk_selection_data_targets_include_text (data);
8558 if (entry->popup_menu)
8559 gtk_widget_destroy (entry->popup_menu);
8561 entry->popup_menu = gtk_menu_new ();
8563 gtk_menu_attach_to_widget (GTK_MENU (entry->popup_menu),
8567 mode = gtk_entry_get_display_mode (entry);
8568 append_action_signal (entry, entry->popup_menu, GTK_STOCK_CUT, "cut-clipboard",
8569 entry->editable && mode == DISPLAY_NORMAL &&
8570 entry->current_pos != entry->selection_bound);
8572 append_action_signal (entry, entry->popup_menu, GTK_STOCK_COPY, "copy-clipboard",
8573 mode == DISPLAY_NORMAL &&
8574 entry->current_pos != entry->selection_bound);
8576 append_action_signal (entry, entry->popup_menu, GTK_STOCK_PASTE, "paste-clipboard",
8577 entry->editable && clipboard_contains_text);
8579 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_DELETE, NULL);
8580 gtk_widget_set_sensitive (menuitem, entry->editable && entry->current_pos != entry->selection_bound);
8581 g_signal_connect_swapped (menuitem, "activate",
8582 G_CALLBACK (gtk_entry_delete_cb), entry);
8583 gtk_widget_show (menuitem);
8584 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8586 menuitem = gtk_separator_menu_item_new ();
8587 gtk_widget_show (menuitem);
8588 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8590 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_SELECT_ALL, NULL);
8591 g_signal_connect_swapped (menuitem, "activate",
8592 G_CALLBACK (gtk_entry_select_all), entry);
8593 gtk_widget_show (menuitem);
8594 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8596 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
8597 "gtk-show-input-method-menu", &show_input_method_menu,
8598 "gtk-show-unicode-menu", &show_unicode_menu,
8601 if (show_input_method_menu || show_unicode_menu)
8603 menuitem = gtk_separator_menu_item_new ();
8604 gtk_widget_show (menuitem);
8605 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8608 if (show_input_method_menu)
8610 menuitem = gtk_menu_item_new_with_mnemonic (_("Input _Methods"));
8611 gtk_widget_set_sensitive (menuitem, entry->editable);
8612 gtk_widget_show (menuitem);
8613 submenu = gtk_menu_new ();
8614 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
8616 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8618 gtk_im_multicontext_append_menuitems (GTK_IM_MULTICONTEXT (entry->im_context),
8619 GTK_MENU_SHELL (submenu));
8622 if (show_unicode_menu)
8624 menuitem = gtk_menu_item_new_with_mnemonic (_("_Insert Unicode Control Character"));
8625 gtk_widget_set_sensitive (menuitem, entry->editable);
8626 gtk_widget_show (menuitem);
8628 submenu = gtk_menu_new ();
8629 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
8630 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8632 _gtk_text_util_append_special_char_menuitems (GTK_MENU_SHELL (submenu),
8633 unichar_chosen_func,
8637 g_signal_emit (entry,
8638 signals[POPULATE_POPUP],
8644 gtk_menu_popup (GTK_MENU (entry->popup_menu), NULL, NULL,
8646 info->button, info->time);
8649 gtk_menu_popup (GTK_MENU (entry->popup_menu), NULL, NULL,
8650 popup_position_func, entry,
8651 info->button, info->time);
8652 gtk_menu_shell_select_first (GTK_MENU_SHELL (entry->popup_menu), FALSE);
8656 g_object_unref (entry);
8657 g_slice_free (PopupInfo, info);
8661 gtk_entry_do_popup (GtkEntry *entry,
8662 GdkEventButton *event)
8664 PopupInfo *info = g_slice_new (PopupInfo);
8666 /* In order to know what entries we should make sensitive, we
8667 * ask for the current targets of the clipboard, and when
8668 * we get them, then we actually pop up the menu.
8670 info->entry = g_object_ref (entry);
8674 info->button = event->button;
8675 info->time = event->time;
8680 info->time = gtk_get_current_event_time ();
8683 gtk_clipboard_request_contents (gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_CLIPBOARD),
8684 gdk_atom_intern_static_string ("TARGETS"),
8685 popup_targets_received,
8690 gtk_entry_popup_menu (GtkWidget *widget)
8692 gtk_entry_do_popup (GTK_ENTRY (widget), NULL);
8697 gtk_entry_drag_begin (GtkWidget *widget,
8698 GdkDragContext *context)
8700 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
8703 for (i = 0; i < MAX_ICONS; i++)
8705 EntryIconInfo *icon_info = priv->icons[i];
8707 if (icon_info != NULL)
8709 if (icon_info->in_drag)
8711 switch (icon_info->storage_type)
8713 case GTK_IMAGE_STOCK:
8714 gtk_drag_set_icon_stock (context, icon_info->stock_id, -2, -2);
8717 case GTK_IMAGE_ICON_NAME:
8718 gtk_drag_set_icon_name (context, icon_info->icon_name, -2, -2);
8721 /* FIXME: No GIcon support for dnd icons */
8722 case GTK_IMAGE_GICON:
8723 case GTK_IMAGE_PIXBUF:
8724 gtk_drag_set_icon_pixbuf (context, icon_info->pixbuf, -2, -2);
8727 g_assert_not_reached ();
8735 gtk_entry_drag_end (GtkWidget *widget,
8736 GdkDragContext *context)
8738 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
8741 for (i = 0; i < MAX_ICONS; i++)
8743 EntryIconInfo *icon_info = priv->icons[i];
8745 if (icon_info != NULL)
8746 icon_info->in_drag = 0;
8751 gtk_entry_drag_leave (GtkWidget *widget,
8752 GdkDragContext *context,
8755 GtkEntry *entry = GTK_ENTRY (widget);
8757 entry->dnd_position = -1;
8758 gtk_widget_queue_draw (widget);
8762 gtk_entry_drag_drop (GtkWidget *widget,
8763 GdkDragContext *context,
8768 GtkEntry *entry = GTK_ENTRY (widget);
8769 GdkAtom target = GDK_NONE;
8771 if (entry->editable)
8772 target = gtk_drag_dest_find_target (widget, context, NULL);
8774 if (target != GDK_NONE)
8775 gtk_drag_get_data (widget, context, target, time);
8777 gtk_drag_finish (context, FALSE, FALSE, time);
8783 gtk_entry_drag_motion (GtkWidget *widget,
8784 GdkDragContext *context,
8789 GtkEntry *entry = GTK_ENTRY (widget);
8791 GtkWidget *source_widget;
8792 GdkDragAction suggested_action;
8793 gint new_position, old_position;
8796 style = gtk_widget_get_style (widget);
8797 x -= style->xthickness;
8798 y -= style->ythickness;
8800 old_position = entry->dnd_position;
8801 new_position = gtk_entry_find_position (entry, x + entry->scroll_offset);
8803 if (entry->editable &&
8804 gtk_drag_dest_find_target (widget, context, NULL) != GDK_NONE)
8806 source_widget = gtk_drag_get_source_widget (context);
8807 suggested_action = context->suggested_action;
8809 if (!gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &sel1, &sel2) ||
8810 new_position < sel1 || new_position > sel2)
8812 if (source_widget == widget)
8814 /* Default to MOVE, unless the user has
8815 * pressed ctrl or alt to affect available actions
8817 if ((context->actions & GDK_ACTION_MOVE) != 0)
8818 suggested_action = GDK_ACTION_MOVE;
8821 entry->dnd_position = new_position;
8825 if (source_widget == widget)
8826 suggested_action = 0; /* Can't drop in selection where drag started */
8828 entry->dnd_position = -1;
8833 /* Entry not editable, or no text */
8834 suggested_action = 0;
8835 entry->dnd_position = -1;
8838 gdk_drag_status (context, suggested_action, time);
8840 if (entry->dnd_position != old_position)
8841 gtk_widget_queue_draw (widget);
8847 gtk_entry_drag_data_received (GtkWidget *widget,
8848 GdkDragContext *context,
8851 GtkSelectionData *selection_data,
8855 GtkEntry *entry = GTK_ENTRY (widget);
8856 GtkEditable *editable = GTK_EDITABLE (widget);
8860 str = (gchar *) gtk_selection_data_get_text (selection_data);
8862 style = gtk_widget_get_style (widget);
8863 x -= style->xthickness;
8864 y -= style->ythickness;
8866 if (str && entry->editable)
8872 if (entry->truncate_multiline)
8873 length = truncate_multiline (str);
8875 new_position = gtk_entry_find_position (entry, x + entry->scroll_offset);
8877 if (!gtk_editable_get_selection_bounds (editable, &sel1, &sel2) ||
8878 new_position < sel1 || new_position > sel2)
8880 gtk_editable_insert_text (editable, str, length, &new_position);
8884 /* Replacing selection */
8885 begin_change (entry);
8886 g_object_freeze_notify (G_OBJECT (entry));
8887 gtk_editable_delete_text (editable, sel1, sel2);
8888 gtk_editable_insert_text (editable, str, length, &sel1);
8889 g_object_thaw_notify (G_OBJECT (entry));
8893 gtk_drag_finish (context, TRUE, context->action == GDK_ACTION_MOVE, time);
8897 /* Drag and drop didn't happen! */
8898 gtk_drag_finish (context, FALSE, FALSE, time);
8905 gtk_entry_drag_data_get (GtkWidget *widget,
8906 GdkDragContext *context,
8907 GtkSelectionData *selection_data,
8911 gint sel_start, sel_end;
8914 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
8915 GtkEditable *editable = GTK_EDITABLE (widget);
8917 /* If there is an icon drag going on, exit early. */
8918 for (i = 0; i < MAX_ICONS; i++)
8920 EntryIconInfo *icon_info = priv->icons[i];
8922 if (icon_info != NULL)
8924 if (icon_info->in_drag)
8929 if (gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end))
8931 gchar *str = gtk_entry_get_display_text (GTK_ENTRY (widget), sel_start, sel_end);
8933 gtk_selection_data_set_text (selection_data, str, -1);
8941 gtk_entry_drag_data_delete (GtkWidget *widget,
8942 GdkDragContext *context)
8944 gint sel_start, sel_end;
8947 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
8948 GtkEditable *editable = GTK_EDITABLE (widget);
8950 /* If there is an icon drag going on, exit early. */
8951 for (i = 0; i < MAX_ICONS; i++)
8953 EntryIconInfo *icon_info = priv->icons[i];
8955 if (icon_info != NULL)
8957 if (icon_info->in_drag)
8962 if (GTK_ENTRY (widget)->editable &&
8963 gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end))
8964 gtk_editable_delete_text (editable, sel_start, sel_end);
8967 /* We display the cursor when
8969 * - the selection is empty, AND
8970 * - the widget has focus
8973 #define CURSOR_ON_MULTIPLIER 2
8974 #define CURSOR_OFF_MULTIPLIER 1
8975 #define CURSOR_PEND_MULTIPLIER 3
8976 #define CURSOR_DIVIDER 3
8979 cursor_blinks (GtkEntry *entry)
8981 if (gtk_widget_has_focus (GTK_WIDGET (entry)) &&
8983 entry->selection_bound == entry->current_pos)
8985 GtkSettings *settings;
8988 settings = gtk_widget_get_settings (GTK_WIDGET (entry));
8989 g_object_get (settings, "gtk-cursor-blink", &blink, NULL);
8998 get_cursor_time (GtkEntry *entry)
9000 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9003 g_object_get (settings, "gtk-cursor-blink-time", &time, NULL);
9009 get_cursor_blink_timeout (GtkEntry *entry)
9011 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9014 g_object_get (settings, "gtk-cursor-blink-timeout", &timeout, NULL);
9020 show_cursor (GtkEntry *entry)
9024 if (!entry->cursor_visible)
9026 entry->cursor_visible = TRUE;
9028 widget = GTK_WIDGET (entry);
9029 if (gtk_widget_has_focus (widget) && entry->selection_bound == entry->current_pos)
9030 gtk_widget_queue_draw (widget);
9035 hide_cursor (GtkEntry *entry)
9039 if (entry->cursor_visible)
9041 entry->cursor_visible = FALSE;
9043 widget = GTK_WIDGET (entry);
9044 if (gtk_widget_has_focus (widget) && entry->selection_bound == entry->current_pos)
9045 gtk_widget_queue_draw (widget);
9053 blink_cb (gpointer data)
9056 GtkEntryPrivate *priv;
9059 entry = GTK_ENTRY (data);
9060 priv = GTK_ENTRY_GET_PRIVATE (entry);
9062 if (!gtk_widget_has_focus (GTK_WIDGET (entry)))
9064 g_warning ("GtkEntry - did not receive focus-out-event. If you\n"
9065 "connect a handler to this signal, it must return\n"
9066 "FALSE so the entry gets the event as well");
9068 gtk_entry_check_cursor_blink (entry);
9073 g_assert (entry->selection_bound == entry->current_pos);
9075 blink_timeout = get_cursor_blink_timeout (entry);
9076 if (priv->blink_time > 1000 * blink_timeout &&
9077 blink_timeout < G_MAXINT/1000)
9079 /* we've blinked enough without the user doing anything, stop blinking */
9080 show_cursor (entry);
9081 entry->blink_timeout = 0;
9083 else if (entry->cursor_visible)
9085 hide_cursor (entry);
9086 entry->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_OFF_MULTIPLIER / CURSOR_DIVIDER,
9092 show_cursor (entry);
9093 priv->blink_time += get_cursor_time (entry);
9094 entry->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
9099 /* Remove ourselves */
9104 gtk_entry_check_cursor_blink (GtkEntry *entry)
9106 GtkEntryPrivate *priv;
9108 priv = GTK_ENTRY_GET_PRIVATE (entry);
9110 if (cursor_blinks (entry))
9112 if (!entry->blink_timeout)
9114 show_cursor (entry);
9115 entry->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
9122 if (entry->blink_timeout)
9124 g_source_remove (entry->blink_timeout);
9125 entry->blink_timeout = 0;
9128 entry->cursor_visible = TRUE;
9134 gtk_entry_pend_cursor_blink (GtkEntry *entry)
9136 if (cursor_blinks (entry))
9138 if (entry->blink_timeout != 0)
9139 g_source_remove (entry->blink_timeout);
9141 entry->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_PEND_MULTIPLIER / CURSOR_DIVIDER,
9144 show_cursor (entry);
9149 gtk_entry_reset_blink_time (GtkEntry *entry)
9151 GtkEntryPrivate *priv;
9153 priv = GTK_ENTRY_GET_PRIVATE (entry);
9155 priv->blink_time = 0;
9161 gtk_entry_completion_timeout (gpointer data)
9163 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (data);
9164 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (completion->priv->entry);
9166 completion->priv->completion_timeout = 0;
9168 if (completion->priv->filter_model &&
9169 g_utf8_strlen (gtk_entry_get_text (GTK_ENTRY (completion->priv->entry)), -1)
9170 >= completion->priv->minimum_key_length)
9174 GtkTreeSelection *s;
9175 gboolean popup_single;
9177 gtk_entry_completion_complete (completion);
9178 matches = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->filter_model), NULL);
9180 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9182 s = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view));
9184 gtk_tree_selection_unselect_all (s);
9186 actions = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->actions), NULL);
9188 g_object_get (completion, "popup-single-match", &popup_single, NULL);
9189 if ((matches > (popup_single ? 0: 1)) || actions > 0)
9191 if (gtk_widget_get_visible (completion->priv->popup_window))
9192 _gtk_entry_completion_resize_popup (completion);
9194 _gtk_entry_completion_popup (completion, priv->completion_device);
9197 _gtk_entry_completion_popdown (completion);
9199 else if (gtk_widget_get_visible (completion->priv->popup_window))
9200 _gtk_entry_completion_popdown (completion);
9205 static inline gboolean
9206 keyval_is_cursor_move (guint keyval)
9208 if (keyval == GDK_KEY_Up || keyval == GDK_KEY_KP_Up)
9211 if (keyval == GDK_KEY_Down || keyval == GDK_KEY_KP_Down)
9214 if (keyval == GDK_KEY_Page_Up)
9217 if (keyval == GDK_KEY_Page_Down)
9224 gtk_entry_completion_key_press (GtkWidget *widget,
9228 gint matches, actions = 0;
9229 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
9231 if (!gtk_widget_get_mapped (completion->priv->popup_window))
9234 matches = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->filter_model), NULL);
9236 if (completion->priv->actions)
9237 actions = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->actions), NULL);
9239 if (keyval_is_cursor_move (event->keyval))
9241 GtkTreePath *path = NULL;
9243 if (event->keyval == GDK_KEY_Up || event->keyval == GDK_KEY_KP_Up)
9245 if (completion->priv->current_selected < 0)
9246 completion->priv->current_selected = matches + actions - 1;
9248 completion->priv->current_selected--;
9250 else if (event->keyval == GDK_KEY_Down || event->keyval == GDK_KEY_KP_Down)
9252 if (completion->priv->current_selected < matches + actions - 1)
9253 completion->priv->current_selected++;
9255 completion->priv->current_selected = -1;
9257 else if (event->keyval == GDK_KEY_Page_Up)
9259 if (completion->priv->current_selected < 0)
9260 completion->priv->current_selected = matches + actions - 1;
9261 else if (completion->priv->current_selected == 0)
9262 completion->priv->current_selected = -1;
9263 else if (completion->priv->current_selected < matches)
9265 completion->priv->current_selected -= 14;
9266 if (completion->priv->current_selected < 0)
9267 completion->priv->current_selected = 0;
9271 completion->priv->current_selected -= 14;
9272 if (completion->priv->current_selected < matches - 1)
9273 completion->priv->current_selected = matches - 1;
9276 else if (event->keyval == GDK_KEY_Page_Down)
9278 if (completion->priv->current_selected < 0)
9279 completion->priv->current_selected = 0;
9280 else if (completion->priv->current_selected < matches - 1)
9282 completion->priv->current_selected += 14;
9283 if (completion->priv->current_selected > matches - 1)
9284 completion->priv->current_selected = matches - 1;
9286 else if (completion->priv->current_selected == matches + actions - 1)
9288 completion->priv->current_selected = -1;
9292 completion->priv->current_selected += 14;
9293 if (completion->priv->current_selected > matches + actions - 1)
9294 completion->priv->current_selected = matches + actions - 1;
9298 if (completion->priv->current_selected < 0)
9300 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9301 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view)));
9303 if (completion->priv->inline_selection &&
9304 completion->priv->completion_prefix)
9306 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9307 completion->priv->completion_prefix);
9308 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9311 else if (completion->priv->current_selected < matches)
9313 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view)));
9315 path = gtk_tree_path_new_from_indices (completion->priv->current_selected, -1);
9316 gtk_tree_view_set_cursor (GTK_TREE_VIEW (completion->priv->tree_view),
9319 if (completion->priv->inline_selection)
9323 GtkTreeIter child_iter;
9324 GtkTreeModel *model = NULL;
9325 GtkTreeSelection *sel;
9328 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view));
9329 if (!gtk_tree_selection_get_selected (sel, &model, &iter))
9332 gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (model), &child_iter, &iter);
9333 model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model));
9335 if (completion->priv->completion_prefix == NULL)
9336 completion->priv->completion_prefix = g_strdup (gtk_entry_get_text (GTK_ENTRY (completion->priv->entry)));
9338 g_signal_emit_by_name (completion, "cursor-on-match", model,
9339 &child_iter, &entry_set);
9342 else if (completion->priv->current_selected - matches >= 0)
9344 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9346 path = gtk_tree_path_new_from_indices (completion->priv->current_selected - matches, -1);
9347 gtk_tree_view_set_cursor (GTK_TREE_VIEW (completion->priv->action_view),
9350 if (completion->priv->inline_selection &&
9351 completion->priv->completion_prefix)
9353 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9354 completion->priv->completion_prefix);
9355 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9359 gtk_tree_path_free (path);
9363 else if (event->keyval == GDK_KEY_Escape ||
9364 event->keyval == GDK_KEY_Left ||
9365 event->keyval == GDK_KEY_KP_Left ||
9366 event->keyval == GDK_KEY_Right ||
9367 event->keyval == GDK_KEY_KP_Right)
9369 gboolean retval = TRUE;
9371 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9372 _gtk_entry_completion_popdown (completion);
9374 if (completion->priv->current_selected < 0)
9377 goto keypress_completion_out;
9379 else if (completion->priv->inline_selection)
9381 /* Escape rejects the tentative completion */
9382 if (event->keyval == GDK_KEY_Escape)
9384 if (completion->priv->completion_prefix)
9385 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9386 completion->priv->completion_prefix);
9388 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry), "");
9391 /* Move the cursor to the end for Right/Esc, to the
9392 beginning for Left */
9393 if (event->keyval == GDK_KEY_Right ||
9394 event->keyval == GDK_KEY_KP_Right ||
9395 event->keyval == GDK_KEY_Escape)
9396 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9398 gtk_editable_set_position (GTK_EDITABLE (widget), 0);
9401 keypress_completion_out:
9402 if (completion->priv->inline_selection)
9404 g_free (completion->priv->completion_prefix);
9405 completion->priv->completion_prefix = NULL;
9410 else if (event->keyval == GDK_KEY_Tab ||
9411 event->keyval == GDK_KEY_KP_Tab ||
9412 event->keyval == GDK_KEY_ISO_Left_Tab)
9414 GtkDirectionType dir = event->keyval == GDK_KEY_ISO_Left_Tab ?
9415 GTK_DIR_TAB_BACKWARD : GTK_DIR_TAB_FORWARD;
9417 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9418 _gtk_entry_completion_popdown (completion);
9420 g_free (completion->priv->completion_prefix);
9421 completion->priv->completion_prefix = NULL;
9423 gtk_widget_child_focus (gtk_widget_get_toplevel (widget), dir);
9427 else if (event->keyval == GDK_KEY_ISO_Enter ||
9428 event->keyval == GDK_KEY_KP_Enter ||
9429 event->keyval == GDK_KEY_Return)
9432 GtkTreeModel *model = NULL;
9433 GtkTreeSelection *sel;
9434 gboolean retval = TRUE;
9436 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9437 _gtk_entry_completion_popdown (completion);
9439 if (completion->priv->current_selected < matches)
9443 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view));
9444 if (gtk_tree_selection_get_selected (sel, &model, &iter))
9446 g_signal_handler_block (widget, completion->priv->changed_id);
9447 g_signal_emit_by_name (completion, "match-selected",
9448 model, &iter, &entry_set);
9449 g_signal_handler_unblock (widget, completion->priv->changed_id);
9455 gtk_tree_model_get (model, &iter,
9456 completion->priv->text_column, &str,
9459 gtk_entry_set_text (GTK_ENTRY (widget), str);
9461 /* move the cursor to the end */
9462 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9470 else if (completion->priv->current_selected - matches >= 0)
9472 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view));
9473 if (gtk_tree_selection_get_selected (sel, &model, &iter))
9477 path = gtk_tree_path_new_from_indices (completion->priv->current_selected - matches, -1);
9478 g_signal_emit_by_name (completion, "action-activated",
9479 gtk_tree_path_get_indices (path)[0]);
9480 gtk_tree_path_free (path);
9486 g_free (completion->priv->completion_prefix);
9487 completion->priv->completion_prefix = NULL;
9496 gtk_entry_completion_changed (GtkWidget *entry,
9499 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
9500 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
9503 /* (re)install completion timeout */
9504 if (completion->priv->completion_timeout)
9505 g_source_remove (completion->priv->completion_timeout);
9507 if (!gtk_entry_get_text (GTK_ENTRY (entry)))
9510 /* no need to normalize for this test */
9511 if (completion->priv->minimum_key_length > 0 &&
9512 strcmp ("", gtk_entry_get_text (GTK_ENTRY (entry))) == 0)
9514 if (gtk_widget_get_visible (completion->priv->popup_window))
9515 _gtk_entry_completion_popdown (completion);
9519 device = gtk_get_current_event_device ();
9521 if (device && device->source == GDK_SOURCE_KEYBOARD)
9522 device = gdk_device_get_associated_device (device);
9525 priv->completion_device = device;
9527 completion->priv->completion_timeout =
9528 gdk_threads_add_timeout (COMPLETION_TIMEOUT,
9529 gtk_entry_completion_timeout,
9534 check_completion_callback (GtkEntryCompletion *completion)
9536 completion->priv->check_completion_idle = NULL;
9538 gtk_entry_completion_complete (completion);
9539 gtk_entry_completion_insert_prefix (completion);
9545 clear_completion_callback (GtkEntry *entry,
9548 if (pspec->name == I_("cursor-position") ||
9549 pspec->name == I_("selection-bound"))
9551 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
9553 completion->priv->has_completion = FALSE;
9558 accept_completion_callback (GtkEntry *entry)
9560 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
9562 if (completion->priv->has_completion)
9563 gtk_editable_set_position (GTK_EDITABLE (entry),
9564 gtk_entry_buffer_get_length (get_buffer (entry)));
9570 completion_insert_text_callback (GtkEntry *entry,
9574 GtkEntryCompletion *completion)
9576 /* idle to update the selection based on the file list */
9577 if (completion->priv->check_completion_idle == NULL)
9579 completion->priv->check_completion_idle = g_idle_source_new ();
9580 g_source_set_priority (completion->priv->check_completion_idle, G_PRIORITY_HIGH);
9581 g_source_set_closure (completion->priv->check_completion_idle,
9582 g_cclosure_new_object (G_CALLBACK (check_completion_callback),
9583 G_OBJECT (completion)));
9584 g_source_attach (completion->priv->check_completion_idle, NULL);
9589 completion_changed (GtkEntryCompletion *completion,
9593 GtkEntry *entry = GTK_ENTRY (data);
9595 if (pspec->name == I_("popup-completion") ||
9596 pspec->name == I_("inline-completion"))
9598 disconnect_completion_signals (entry, completion);
9599 connect_completion_signals (entry, completion);
9604 disconnect_completion_signals (GtkEntry *entry,
9605 GtkEntryCompletion *completion)
9607 g_signal_handlers_disconnect_by_func (completion,
9608 G_CALLBACK (completion_changed), entry);
9609 if (completion->priv->changed_id > 0 &&
9610 g_signal_handler_is_connected (entry, completion->priv->changed_id))
9612 g_signal_handler_disconnect (entry, completion->priv->changed_id);
9613 completion->priv->changed_id = 0;
9615 g_signal_handlers_disconnect_by_func (entry,
9616 G_CALLBACK (gtk_entry_completion_key_press), completion);
9617 if (completion->priv->insert_text_id > 0 &&
9618 g_signal_handler_is_connected (entry, completion->priv->insert_text_id))
9620 g_signal_handler_disconnect (entry, completion->priv->insert_text_id);
9621 completion->priv->insert_text_id = 0;
9623 g_signal_handlers_disconnect_by_func (entry,
9624 G_CALLBACK (completion_insert_text_callback), completion);
9625 g_signal_handlers_disconnect_by_func (entry,
9626 G_CALLBACK (clear_completion_callback), completion);
9627 g_signal_handlers_disconnect_by_func (entry,
9628 G_CALLBACK (accept_completion_callback), completion);
9632 connect_completion_signals (GtkEntry *entry,
9633 GtkEntryCompletion *completion)
9635 if (completion->priv->popup_completion)
9637 completion->priv->changed_id =
9638 g_signal_connect (entry, "changed",
9639 G_CALLBACK (gtk_entry_completion_changed), completion);
9640 g_signal_connect (entry, "key-press-event",
9641 G_CALLBACK (gtk_entry_completion_key_press), completion);
9644 if (completion->priv->inline_completion)
9646 completion->priv->insert_text_id =
9647 g_signal_connect (entry, "insert-text",
9648 G_CALLBACK (completion_insert_text_callback), completion);
9649 g_signal_connect (entry, "notify",
9650 G_CALLBACK (clear_completion_callback), completion);
9651 g_signal_connect (entry, "activate",
9652 G_CALLBACK (accept_completion_callback), completion);
9653 g_signal_connect (entry, "focus-out-event",
9654 G_CALLBACK (accept_completion_callback), completion);
9657 g_signal_connect (completion, "notify",
9658 G_CALLBACK (completion_changed), entry);
9662 * gtk_entry_set_completion:
9663 * @entry: A #GtkEntry
9664 * @completion: (allow-none): The #GtkEntryCompletion or %NULL
9666 * Sets @completion to be the auxiliary completion object to use with @entry.
9667 * All further configuration of the completion mechanism is done on
9668 * @completion using the #GtkEntryCompletion API. Completion is disabled if
9669 * @completion is set to %NULL.
9674 gtk_entry_set_completion (GtkEntry *entry,
9675 GtkEntryCompletion *completion)
9677 GtkEntryCompletion *old;
9679 g_return_if_fail (GTK_IS_ENTRY (entry));
9680 g_return_if_fail (!completion || GTK_IS_ENTRY_COMPLETION (completion));
9682 old = gtk_entry_get_completion (entry);
9684 if (old == completion)
9689 if (old->priv->completion_timeout)
9691 g_source_remove (old->priv->completion_timeout);
9692 old->priv->completion_timeout = 0;
9695 if (gtk_widget_get_mapped (old->priv->popup_window))
9696 _gtk_entry_completion_popdown (old);
9698 disconnect_completion_signals (entry, old);
9699 old->priv->entry = NULL;
9701 g_object_unref (old);
9706 g_object_set_data (G_OBJECT (entry), I_(GTK_ENTRY_COMPLETION_KEY), NULL);
9710 /* hook into the entry */
9711 g_object_ref (completion);
9713 connect_completion_signals (entry, completion);
9714 completion->priv->entry = GTK_WIDGET (entry);
9715 g_object_set_data (G_OBJECT (entry), I_(GTK_ENTRY_COMPLETION_KEY), completion);
9719 * gtk_entry_get_completion:
9720 * @entry: A #GtkEntry
9722 * Returns the auxiliary completion object currently in use by @entry.
9724 * Return value: (transfer none): The auxiliary completion object currently
9729 GtkEntryCompletion *
9730 gtk_entry_get_completion (GtkEntry *entry)
9732 GtkEntryCompletion *completion;
9734 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
9736 completion = GTK_ENTRY_COMPLETION (g_object_get_data (G_OBJECT (entry),
9737 GTK_ENTRY_COMPLETION_KEY));
9743 * gtk_entry_set_cursor_hadjustment:
9744 * @entry: a #GtkEntry
9745 * @adjustment: an adjustment which should be adjusted when the cursor
9746 * is moved, or %NULL
9748 * Hooks up an adjustment to the cursor position in an entry, so that when
9749 * the cursor is moved, the adjustment is scrolled to show that position.
9750 * See gtk_scrolled_window_get_hadjustment() for a typical way of obtaining
9753 * The adjustment has to be in pixel units and in the same coordinate system
9759 gtk_entry_set_cursor_hadjustment (GtkEntry *entry,
9760 GtkAdjustment *adjustment)
9762 g_return_if_fail (GTK_IS_ENTRY (entry));
9764 g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
9767 g_object_ref (adjustment);
9769 g_object_set_qdata_full (G_OBJECT (entry),
9770 quark_cursor_hadjustment,
9776 * gtk_entry_get_cursor_hadjustment:
9777 * @entry: a #GtkEntry
9779 * Retrieves the horizontal cursor adjustment for the entry.
9780 * See gtk_entry_set_cursor_hadjustment().
9782 * Return value: (transfer none): the horizontal cursor adjustment, or %NULL
9783 * if none has been set.
9788 gtk_entry_get_cursor_hadjustment (GtkEntry *entry)
9790 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
9792 return g_object_get_qdata (G_OBJECT (entry), quark_cursor_hadjustment);
9796 * gtk_entry_set_progress_fraction:
9797 * @entry: a #GtkEntry
9798 * @fraction: fraction of the task that's been completed
9800 * Causes the entry's progress indicator to "fill in" the given
9801 * fraction of the bar. The fraction should be between 0.0 and 1.0,
9807 gtk_entry_set_progress_fraction (GtkEntry *entry,
9811 GtkEntryPrivate *private;
9812 gdouble old_fraction;
9813 gint x, y, width, height;
9814 gint old_x, old_y, old_width, old_height;
9816 g_return_if_fail (GTK_IS_ENTRY (entry));
9818 widget = GTK_WIDGET (entry);
9819 private = GTK_ENTRY_GET_PRIVATE (entry);
9821 if (private->progress_pulse_mode)
9824 old_fraction = private->progress_fraction;
9826 if (gtk_widget_is_drawable (widget))
9827 get_progress_area (widget, &old_x, &old_y, &old_width, &old_height);
9829 fraction = CLAMP (fraction, 0.0, 1.0);
9831 private->progress_fraction = fraction;
9832 private->progress_pulse_mode = FALSE;
9833 private->progress_pulse_current = 0.0;
9835 if (gtk_widget_is_drawable (widget))
9837 get_progress_area (widget, &x, &y, &width, &height);
9839 if ((x != old_x) || (y != old_y) || (width != old_width) || (height != old_height))
9840 gtk_widget_queue_draw (widget);
9843 if (fraction != old_fraction)
9844 g_object_notify (G_OBJECT (entry), "progress-fraction");
9848 * gtk_entry_get_progress_fraction:
9849 * @entry: a #GtkEntry
9851 * Returns the current fraction of the task that's been completed.
9852 * See gtk_entry_set_progress_fraction().
9854 * Return value: a fraction from 0.0 to 1.0
9859 gtk_entry_get_progress_fraction (GtkEntry *entry)
9861 GtkEntryPrivate *private;
9863 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
9865 private = GTK_ENTRY_GET_PRIVATE (entry);
9867 return private->progress_fraction;
9871 * gtk_entry_set_progress_pulse_step:
9872 * @entry: a #GtkEntry
9873 * @fraction: fraction between 0.0 and 1.0
9875 * Sets the fraction of total entry width to move the progress
9876 * bouncing block for each call to gtk_entry_progress_pulse().
9881 gtk_entry_set_progress_pulse_step (GtkEntry *entry,
9884 GtkEntryPrivate *private;
9886 g_return_if_fail (GTK_IS_ENTRY (entry));
9888 private = GTK_ENTRY_GET_PRIVATE (entry);
9890 fraction = CLAMP (fraction, 0.0, 1.0);
9892 if (fraction != private->progress_pulse_fraction)
9894 private->progress_pulse_fraction = fraction;
9896 gtk_widget_queue_draw (GTK_WIDGET (entry));
9898 g_object_notify (G_OBJECT (entry), "progress-pulse-step");
9903 * gtk_entry_get_progress_pulse_step:
9904 * @entry: a #GtkEntry
9906 * Retrieves the pulse step set with gtk_entry_set_progress_pulse_step().
9908 * Return value: a fraction from 0.0 to 1.0
9913 gtk_entry_get_progress_pulse_step (GtkEntry *entry)
9915 GtkEntryPrivate *private;
9917 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
9919 private = GTK_ENTRY_GET_PRIVATE (entry);
9921 return private->progress_pulse_fraction;
9925 * gtk_entry_progress_pulse:
9926 * @entry: a #GtkEntry
9928 * Indicates that some progress is made, but you don't know how much.
9929 * Causes the entry's progress indicator to enter "activity mode,"
9930 * where a block bounces back and forth. Each call to
9931 * gtk_entry_progress_pulse() causes the block to move by a little bit
9932 * (the amount of movement per pulse is determined by
9933 * gtk_entry_set_progress_pulse_step()).
9938 gtk_entry_progress_pulse (GtkEntry *entry)
9940 GtkEntryPrivate *private;
9942 g_return_if_fail (GTK_IS_ENTRY (entry));
9944 private = GTK_ENTRY_GET_PRIVATE (entry);
9946 if (private->progress_pulse_mode)
9948 if (private->progress_pulse_way_back)
9950 private->progress_pulse_current -= private->progress_pulse_fraction;
9952 if (private->progress_pulse_current < 0.0)
9954 private->progress_pulse_current = 0.0;
9955 private->progress_pulse_way_back = FALSE;
9960 private->progress_pulse_current += private->progress_pulse_fraction;
9962 if (private->progress_pulse_current > 1.0 - private->progress_pulse_fraction)
9964 private->progress_pulse_current = 1.0 - private->progress_pulse_fraction;
9965 private->progress_pulse_way_back = TRUE;
9971 private->progress_fraction = 0.0;
9972 private->progress_pulse_mode = TRUE;
9973 private->progress_pulse_way_back = FALSE;
9974 private->progress_pulse_current = 0.0;
9977 gtk_widget_queue_draw (GTK_WIDGET (entry));
9980 /* Caps Lock warning for password entries */
9983 show_capslock_feedback (GtkEntry *entry,
9986 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
9988 if (gtk_entry_get_icon_storage_type (entry, GTK_ENTRY_ICON_SECONDARY) == GTK_IMAGE_EMPTY)
9990 gtk_entry_set_icon_from_stock (entry, GTK_ENTRY_ICON_SECONDARY, GTK_STOCK_CAPS_LOCK_WARNING);
9991 gtk_entry_set_icon_activatable (entry, GTK_ENTRY_ICON_SECONDARY, FALSE);
9992 priv->caps_lock_warning_shown = TRUE;
9995 if (priv->caps_lock_warning_shown)
9996 gtk_entry_set_icon_tooltip_text (entry, GTK_ENTRY_ICON_SECONDARY, text);
9998 g_warning ("Can't show Caps Lock warning, since secondary icon is set");
10002 remove_capslock_feedback (GtkEntry *entry)
10004 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
10006 if (priv->caps_lock_warning_shown)
10008 gtk_entry_set_icon_from_stock (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
10009 priv->caps_lock_warning_shown = FALSE;
10014 keymap_state_changed (GdkKeymap *keymap,
10017 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
10020 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL && priv->caps_lock_warning)
10022 if (gdk_keymap_get_num_lock_state (keymap)
10023 && gdk_keymap_get_caps_lock_state (keymap))
10024 text = _("Caps Lock and Num Lock are on");
10025 else if (gdk_keymap_get_num_lock_state (keymap))
10026 text = _("Num Lock is on");
10027 else if (gdk_keymap_get_caps_lock_state (keymap))
10028 text = _("Caps Lock is on");
10032 show_capslock_feedback (entry, text);
10034 remove_capslock_feedback (entry);