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"
70 #define GTK_ENTRY_COMPLETION_KEY "gtk-entry-completion-key"
72 #define MIN_ENTRY_WIDTH 150
73 #define DRAW_TIMEOUT 20
74 #define COMPLETION_TIMEOUT 300
75 #define PASSWORD_HINT_MAX 8
79 #define IS_VALID_ICON_POSITION(pos) \
80 ((pos) == GTK_ENTRY_ICON_PRIMARY || \
81 (pos) == GTK_ENTRY_ICON_SECONDARY)
83 static const GtkBorder default_inner_border = { 2, 2, 2, 2 };
84 static GQuark quark_inner_border = 0;
85 static GQuark quark_password_hint = 0;
86 static GQuark quark_cursor_hadjustment = 0;
87 static GQuark quark_capslock_feedback = 0;
89 typedef struct _GtkEntryPrivate GtkEntryPrivate;
91 #define GTK_ENTRY_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_ENTRY, GtkEntryPrivate))
97 guint insensitive : 1;
98 guint nonactivatable : 1;
103 GtkImageType storage_type;
109 GtkTargetList *target_list;
110 GdkDragAction actions;
113 struct _GtkEntryPrivate
115 GtkEntryBuffer* buffer;
119 guint blink_time; /* time in msec the cursor has blinked since last user event */
120 guint interior_focus : 1;
121 guint real_changed : 1;
122 guint invisible_char_set : 1;
123 guint caps_lock_warning : 1;
124 guint caps_lock_warning_shown : 1;
125 guint change_count : 8;
126 guint progress_pulse_mode : 1;
127 guint progress_pulse_way_back : 1;
130 GtkShadowType shadow_type;
132 gdouble progress_fraction;
133 gdouble progress_pulse_fraction;
134 gdouble progress_pulse_current;
136 EntryIconInfo *icons[MAX_ICONS];
144 typedef struct _GtkEntryPasswordHint GtkEntryPasswordHint;
146 struct _GtkEntryPasswordHint
148 gint position; /* Position (in text) of the last password hint */
149 guint source_id; /* Timeout source id */
152 typedef struct _GtkEntryCapslockFeedback GtkEntryCapslockFeedback;
154 struct _GtkEntryCapslockFeedback
180 PROP_CURSOR_POSITION,
181 PROP_SELECTION_BOUND,
188 PROP_ACTIVATES_DEFAULT,
193 PROP_TRUNCATE_MULTILINE,
197 PROP_INVISIBLE_CHAR_SET,
198 PROP_CAPS_LOCK_WARNING,
199 PROP_PROGRESS_FRACTION,
200 PROP_PROGRESS_PULSE_STEP,
202 PROP_PIXBUF_SECONDARY,
204 PROP_STOCK_SECONDARY,
205 PROP_ICON_NAME_PRIMARY,
206 PROP_ICON_NAME_SECONDARY,
208 PROP_GICON_SECONDARY,
209 PROP_STORAGE_TYPE_PRIMARY,
210 PROP_STORAGE_TYPE_SECONDARY,
211 PROP_ACTIVATABLE_PRIMARY,
212 PROP_ACTIVATABLE_SECONDARY,
213 PROP_SENSITIVE_PRIMARY,
214 PROP_SENSITIVE_SECONDARY,
215 PROP_TOOLTIP_TEXT_PRIMARY,
216 PROP_TOOLTIP_TEXT_SECONDARY,
217 PROP_TOOLTIP_MARKUP_PRIMARY,
218 PROP_TOOLTIP_MARKUP_SECONDARY,
222 static guint signals[LAST_SIGNAL] = { 0 };
231 DISPLAY_NORMAL, /* The entry text is being shown */
232 DISPLAY_INVISIBLE, /* In invisible mode, text replaced by (eg) bullets */
233 DISPLAY_BLANK /* In invisible mode, nothing shown at all */
236 /* GObject, GtkObject methods
238 static void gtk_entry_editable_init (GtkEditableClass *iface);
239 static void gtk_entry_cell_editable_init (GtkCellEditableIface *iface);
240 static void gtk_entry_set_property (GObject *object,
244 static void gtk_entry_get_property (GObject *object,
248 static void gtk_entry_finalize (GObject *object);
249 static void gtk_entry_destroy (GtkObject *object);
250 static void gtk_entry_dispose (GObject *object);
254 static void gtk_entry_realize (GtkWidget *widget);
255 static void gtk_entry_unrealize (GtkWidget *widget);
256 static void gtk_entry_map (GtkWidget *widget);
257 static void gtk_entry_unmap (GtkWidget *widget);
258 static void gtk_entry_size_request (GtkWidget *widget,
259 GtkRequisition *requisition);
260 static void gtk_entry_size_allocate (GtkWidget *widget,
261 GtkAllocation *allocation);
262 static void gtk_entry_draw_frame (GtkWidget *widget,
263 GdkEventExpose *event);
264 static void gtk_entry_draw_progress (GtkWidget *widget,
265 GdkEventExpose *event);
266 static gint gtk_entry_expose (GtkWidget *widget,
267 GdkEventExpose *event);
268 static gint gtk_entry_button_press (GtkWidget *widget,
269 GdkEventButton *event);
270 static gint gtk_entry_button_release (GtkWidget *widget,
271 GdkEventButton *event);
272 static gint gtk_entry_enter_notify (GtkWidget *widget,
273 GdkEventCrossing *event);
274 static gint gtk_entry_leave_notify (GtkWidget *widget,
275 GdkEventCrossing *event);
276 static gint gtk_entry_motion_notify (GtkWidget *widget,
277 GdkEventMotion *event);
278 static gint gtk_entry_key_press (GtkWidget *widget,
280 static gint gtk_entry_key_release (GtkWidget *widget,
282 static gint gtk_entry_focus_in (GtkWidget *widget,
283 GdkEventFocus *event);
284 static gint gtk_entry_focus_out (GtkWidget *widget,
285 GdkEventFocus *event);
286 static void gtk_entry_grab_focus (GtkWidget *widget);
287 static void gtk_entry_style_set (GtkWidget *widget,
288 GtkStyle *previous_style);
289 static gboolean gtk_entry_query_tooltip (GtkWidget *widget,
292 gboolean keyboard_tip,
293 GtkTooltip *tooltip);
294 static void gtk_entry_direction_changed (GtkWidget *widget,
295 GtkTextDirection previous_dir);
296 static void gtk_entry_state_changed (GtkWidget *widget,
297 GtkStateType previous_state);
298 static void gtk_entry_screen_changed (GtkWidget *widget,
299 GdkScreen *old_screen);
301 static gboolean gtk_entry_drag_drop (GtkWidget *widget,
302 GdkDragContext *context,
306 static gboolean gtk_entry_drag_motion (GtkWidget *widget,
307 GdkDragContext *context,
311 static void gtk_entry_drag_leave (GtkWidget *widget,
312 GdkDragContext *context,
314 static void gtk_entry_drag_data_received (GtkWidget *widget,
315 GdkDragContext *context,
318 GtkSelectionData *selection_data,
321 static void gtk_entry_drag_data_get (GtkWidget *widget,
322 GdkDragContext *context,
323 GtkSelectionData *selection_data,
326 static void gtk_entry_drag_data_delete (GtkWidget *widget,
327 GdkDragContext *context);
328 static void gtk_entry_drag_begin (GtkWidget *widget,
329 GdkDragContext *context);
330 static void gtk_entry_drag_end (GtkWidget *widget,
331 GdkDragContext *context);
334 /* GtkEditable method implementations
336 static void gtk_entry_insert_text (GtkEditable *editable,
337 const gchar *new_text,
338 gint new_text_length,
340 static void gtk_entry_delete_text (GtkEditable *editable,
343 static gchar * gtk_entry_get_chars (GtkEditable *editable,
346 static void gtk_entry_real_set_position (GtkEditable *editable,
348 static gint gtk_entry_get_position (GtkEditable *editable);
349 static void gtk_entry_set_selection_bounds (GtkEditable *editable,
352 static gboolean gtk_entry_get_selection_bounds (GtkEditable *editable,
356 /* GtkCellEditable method implementations
358 static void gtk_entry_start_editing (GtkCellEditable *cell_editable,
361 /* Default signal handlers
363 static void gtk_entry_real_insert_text (GtkEditable *editable,
364 const gchar *new_text,
365 gint new_text_length,
367 static void gtk_entry_real_delete_text (GtkEditable *editable,
370 static void gtk_entry_move_cursor (GtkEntry *entry,
371 GtkMovementStep step,
373 gboolean extend_selection);
374 static void gtk_entry_insert_at_cursor (GtkEntry *entry,
376 static void gtk_entry_delete_from_cursor (GtkEntry *entry,
379 static void gtk_entry_backspace (GtkEntry *entry);
380 static void gtk_entry_cut_clipboard (GtkEntry *entry);
381 static void gtk_entry_copy_clipboard (GtkEntry *entry);
382 static void gtk_entry_paste_clipboard (GtkEntry *entry);
383 static void gtk_entry_toggle_overwrite (GtkEntry *entry);
384 static void gtk_entry_select_all (GtkEntry *entry);
385 static void gtk_entry_real_activate (GtkEntry *entry);
386 static gboolean gtk_entry_popup_menu (GtkWidget *widget);
388 static void keymap_direction_changed (GdkKeymap *keymap,
390 static void keymap_state_changed (GdkKeymap *keymap,
392 static void remove_capslock_feedback (GtkEntry *entry);
394 /* IM Context Callbacks
396 static void gtk_entry_commit_cb (GtkIMContext *context,
399 static void gtk_entry_preedit_changed_cb (GtkIMContext *context,
401 static gboolean gtk_entry_retrieve_surrounding_cb (GtkIMContext *context,
403 static gboolean gtk_entry_delete_surrounding_cb (GtkIMContext *context,
410 static void gtk_entry_enter_text (GtkEntry *entry,
412 static void gtk_entry_set_positions (GtkEntry *entry,
414 gint selection_bound);
415 static void gtk_entry_draw_text (GtkEntry *entry);
416 static void gtk_entry_draw_cursor (GtkEntry *entry,
418 static PangoLayout *gtk_entry_ensure_layout (GtkEntry *entry,
419 gboolean include_preedit);
420 static void gtk_entry_reset_layout (GtkEntry *entry);
421 static void gtk_entry_queue_draw (GtkEntry *entry);
422 static void gtk_entry_recompute (GtkEntry *entry);
423 static gint gtk_entry_find_position (GtkEntry *entry,
425 static void gtk_entry_get_cursor_locations (GtkEntry *entry,
429 static void gtk_entry_adjust_scroll (GtkEntry *entry);
430 static gint gtk_entry_move_visually (GtkEntry *editable,
433 static gint gtk_entry_move_logically (GtkEntry *entry,
436 static gint gtk_entry_move_forward_word (GtkEntry *entry,
438 gboolean allow_whitespace);
439 static gint gtk_entry_move_backward_word (GtkEntry *entry,
441 gboolean allow_whitespace);
442 static void gtk_entry_delete_whitespace (GtkEntry *entry);
443 static void gtk_entry_select_word (GtkEntry *entry);
444 static void gtk_entry_select_line (GtkEntry *entry);
445 static void gtk_entry_paste (GtkEntry *entry,
447 static void gtk_entry_update_primary_selection (GtkEntry *entry);
448 static void gtk_entry_do_popup (GtkEntry *entry,
449 GdkEventButton *event);
450 static gboolean gtk_entry_mnemonic_activate (GtkWidget *widget,
451 gboolean group_cycling);
452 static void gtk_entry_check_cursor_blink (GtkEntry *entry);
453 static void gtk_entry_pend_cursor_blink (GtkEntry *entry);
454 static void gtk_entry_reset_blink_time (GtkEntry *entry);
455 static void gtk_entry_get_text_area_size (GtkEntry *entry,
460 static void get_text_area_size (GtkEntry *entry,
465 static void get_widget_window_size (GtkEntry *entry,
470 static void gtk_entry_move_adjustments (GtkEntry *entry);
471 static void gtk_entry_ensure_pixbuf (GtkEntry *entry,
472 GtkEntryIconPosition icon_pos);
476 static gint gtk_entry_completion_timeout (gpointer data);
477 static gboolean gtk_entry_completion_key_press (GtkWidget *widget,
480 static void gtk_entry_completion_changed (GtkWidget *entry,
482 static gboolean check_completion_callback (GtkEntryCompletion *completion);
483 static void clear_completion_callback (GtkEntry *entry,
485 static gboolean accept_completion_callback (GtkEntry *entry);
486 static void completion_insert_text_callback (GtkEntry *entry,
490 GtkEntryCompletion *completion);
491 static void completion_changed (GtkEntryCompletion *completion,
494 static void disconnect_completion_signals (GtkEntry *entry,
495 GtkEntryCompletion *completion);
496 static void connect_completion_signals (GtkEntry *entry,
497 GtkEntryCompletion *completion);
499 static void begin_change (GtkEntry *entry);
500 static void end_change (GtkEntry *entry);
501 static void emit_changed (GtkEntry *entry);
504 static void buffer_inserted_text (GtkEntryBuffer *buffer,
509 static void buffer_deleted_text (GtkEntryBuffer *buffer,
513 static void buffer_notify_text (GtkEntryBuffer *buffer,
516 static void buffer_notify_length (GtkEntryBuffer *buffer,
519 static void buffer_notify_max_length (GtkEntryBuffer *buffer,
522 static void buffer_connect_signals (GtkEntry *entry);
523 static void buffer_disconnect_signals (GtkEntry *entry);
524 static GtkEntryBuffer *get_buffer (GtkEntry *entry);
527 G_DEFINE_TYPE_WITH_CODE (GtkEntry, gtk_entry, GTK_TYPE_WIDGET,
528 G_IMPLEMENT_INTERFACE (GTK_TYPE_EDITABLE,
529 gtk_entry_editable_init)
530 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_EDITABLE,
531 gtk_entry_cell_editable_init))
534 add_move_binding (GtkBindingSet *binding_set,
537 GtkMovementStep step,
540 g_return_if_fail ((modmask & GDK_SHIFT_MASK) == 0);
542 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
546 G_TYPE_BOOLEAN, FALSE);
548 /* Selection-extending version */
549 gtk_binding_entry_add_signal (binding_set, keyval, modmask | GDK_SHIFT_MASK,
553 G_TYPE_BOOLEAN, TRUE);
557 gtk_entry_class_init (GtkEntryClass *class)
559 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
560 GtkWidgetClass *widget_class;
561 GtkObjectClass *gtk_object_class;
562 GtkBindingSet *binding_set;
564 widget_class = (GtkWidgetClass*) class;
565 gtk_object_class = (GtkObjectClass *)class;
567 gobject_class->dispose = gtk_entry_dispose;
568 gobject_class->finalize = gtk_entry_finalize;
569 gobject_class->set_property = gtk_entry_set_property;
570 gobject_class->get_property = gtk_entry_get_property;
572 widget_class->map = gtk_entry_map;
573 widget_class->unmap = gtk_entry_unmap;
574 widget_class->realize = gtk_entry_realize;
575 widget_class->unrealize = gtk_entry_unrealize;
576 widget_class->size_request = gtk_entry_size_request;
577 widget_class->size_allocate = gtk_entry_size_allocate;
578 widget_class->expose_event = gtk_entry_expose;
579 widget_class->enter_notify_event = gtk_entry_enter_notify;
580 widget_class->leave_notify_event = gtk_entry_leave_notify;
581 widget_class->button_press_event = gtk_entry_button_press;
582 widget_class->button_release_event = gtk_entry_button_release;
583 widget_class->motion_notify_event = gtk_entry_motion_notify;
584 widget_class->key_press_event = gtk_entry_key_press;
585 widget_class->key_release_event = gtk_entry_key_release;
586 widget_class->focus_in_event = gtk_entry_focus_in;
587 widget_class->focus_out_event = gtk_entry_focus_out;
588 widget_class->grab_focus = gtk_entry_grab_focus;
589 widget_class->style_set = gtk_entry_style_set;
590 widget_class->query_tooltip = gtk_entry_query_tooltip;
591 widget_class->drag_begin = gtk_entry_drag_begin;
592 widget_class->drag_end = gtk_entry_drag_end;
593 widget_class->direction_changed = gtk_entry_direction_changed;
594 widget_class->state_changed = gtk_entry_state_changed;
595 widget_class->screen_changed = gtk_entry_screen_changed;
596 widget_class->mnemonic_activate = gtk_entry_mnemonic_activate;
598 widget_class->drag_drop = gtk_entry_drag_drop;
599 widget_class->drag_motion = gtk_entry_drag_motion;
600 widget_class->drag_leave = gtk_entry_drag_leave;
601 widget_class->drag_data_received = gtk_entry_drag_data_received;
602 widget_class->drag_data_get = gtk_entry_drag_data_get;
603 widget_class->drag_data_delete = gtk_entry_drag_data_delete;
605 widget_class->popup_menu = gtk_entry_popup_menu;
607 gtk_object_class->destroy = gtk_entry_destroy;
609 class->move_cursor = gtk_entry_move_cursor;
610 class->insert_at_cursor = gtk_entry_insert_at_cursor;
611 class->delete_from_cursor = gtk_entry_delete_from_cursor;
612 class->backspace = gtk_entry_backspace;
613 class->cut_clipboard = gtk_entry_cut_clipboard;
614 class->copy_clipboard = gtk_entry_copy_clipboard;
615 class->paste_clipboard = gtk_entry_paste_clipboard;
616 class->toggle_overwrite = gtk_entry_toggle_overwrite;
617 class->activate = gtk_entry_real_activate;
618 class->get_text_area_size = gtk_entry_get_text_area_size;
620 quark_inner_border = g_quark_from_static_string ("gtk-entry-inner-border");
621 quark_password_hint = g_quark_from_static_string ("gtk-entry-password-hint");
622 quark_cursor_hadjustment = g_quark_from_static_string ("gtk-hadjustment");
623 quark_capslock_feedback = g_quark_from_static_string ("gtk-entry-capslock-feedback");
625 g_object_class_install_property (gobject_class,
627 g_param_spec_object ("buffer",
629 P_("Text buffer object which actually stores entry text"),
630 GTK_TYPE_ENTRY_BUFFER,
631 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT));
633 g_object_class_install_property (gobject_class,
634 PROP_CURSOR_POSITION,
635 g_param_spec_int ("cursor-position",
636 P_("Cursor Position"),
637 P_("The current position of the insertion cursor in chars"),
639 GTK_ENTRY_BUFFER_MAX_SIZE,
641 GTK_PARAM_READABLE));
643 g_object_class_install_property (gobject_class,
644 PROP_SELECTION_BOUND,
645 g_param_spec_int ("selection-bound",
646 P_("Selection Bound"),
647 P_("The position of the opposite end of the selection from the cursor in chars"),
649 GTK_ENTRY_BUFFER_MAX_SIZE,
651 GTK_PARAM_READABLE));
653 g_object_class_install_property (gobject_class,
655 g_param_spec_boolean ("editable",
657 P_("Whether the entry contents can be edited"),
659 GTK_PARAM_READWRITE));
661 g_object_class_install_property (gobject_class,
663 g_param_spec_int ("max-length",
664 P_("Maximum length"),
665 P_("Maximum number of characters for this entry. Zero if no maximum"),
667 GTK_ENTRY_BUFFER_MAX_SIZE,
669 GTK_PARAM_READWRITE));
670 g_object_class_install_property (gobject_class,
672 g_param_spec_boolean ("visibility",
674 P_("FALSE displays the \"invisible char\" instead of the actual text (password mode)"),
676 GTK_PARAM_READWRITE));
678 g_object_class_install_property (gobject_class,
680 g_param_spec_boolean ("has-frame",
682 P_("FALSE removes outside bevel from entry"),
684 GTK_PARAM_READWRITE));
686 g_object_class_install_property (gobject_class,
688 g_param_spec_boxed ("inner-border",
690 P_("Border between text and frame. Overrides the inner-border style property"),
692 GTK_PARAM_READWRITE));
694 g_object_class_install_property (gobject_class,
696 g_param_spec_unichar ("invisible-char",
697 P_("Invisible character"),
698 P_("The character to use when masking entry contents (in \"password mode\")"),
700 GTK_PARAM_READWRITE));
702 g_object_class_install_property (gobject_class,
703 PROP_ACTIVATES_DEFAULT,
704 g_param_spec_boolean ("activates-default",
705 P_("Activates default"),
706 P_("Whether to activate the default widget (such as the default button in a dialog) when Enter is pressed"),
708 GTK_PARAM_READWRITE));
709 g_object_class_install_property (gobject_class,
711 g_param_spec_int ("width-chars",
712 P_("Width in chars"),
713 P_("Number of characters to leave space for in the entry"),
717 GTK_PARAM_READWRITE));
719 g_object_class_install_property (gobject_class,
721 g_param_spec_int ("scroll-offset",
723 P_("Number of pixels of the entry scrolled off the screen to the left"),
727 GTK_PARAM_READABLE));
729 g_object_class_install_property (gobject_class,
731 g_param_spec_string ("text",
733 P_("The contents of the entry"),
735 GTK_PARAM_READWRITE));
740 * The horizontal alignment, from 0 (left) to 1 (right).
741 * Reversed for RTL layouts.
745 g_object_class_install_property (gobject_class,
747 g_param_spec_float ("xalign",
749 P_("The horizontal alignment, from 0 (left) to 1 (right). Reversed for RTL layouts."),
753 GTK_PARAM_READWRITE));
756 * GtkEntry:truncate-multiline:
758 * When %TRUE, pasted multi-line text is truncated to the first line.
762 g_object_class_install_property (gobject_class,
763 PROP_TRUNCATE_MULTILINE,
764 g_param_spec_boolean ("truncate-multiline",
765 P_("Truncate multiline"),
766 P_("Whether to truncate multiline pastes to one line."),
768 GTK_PARAM_READWRITE));
771 * GtkEntry:shadow-type:
773 * Which kind of shadow to draw around the entry when
774 * #GtkEntry:has-frame is set to %TRUE.
778 g_object_class_install_property (gobject_class,
780 g_param_spec_enum ("shadow-type",
782 P_("Which kind of shadow to draw around the entry when has-frame is set"),
783 GTK_TYPE_SHADOW_TYPE,
785 GTK_PARAM_READWRITE));
788 * GtkEntry:overwrite-mode:
790 * If text is overwritten when typing in the #GtkEntry.
794 g_object_class_install_property (gobject_class,
796 g_param_spec_boolean ("overwrite-mode",
797 P_("Overwrite mode"),
798 P_("Whether new text overwrites existing text"),
800 GTK_PARAM_READWRITE));
803 * GtkEntry:text-length:
805 * The length of the text in the #GtkEntry.
809 g_object_class_install_property (gobject_class,
811 g_param_spec_uint ("text-length",
813 P_("Length of the text currently in the entry"),
817 GTK_PARAM_READABLE));
819 * GtkEntry:invisible-char-set:
821 * Whether the invisible char has been set for the #GtkEntry.
825 g_object_class_install_property (gobject_class,
826 PROP_INVISIBLE_CHAR_SET,
827 g_param_spec_boolean ("invisible-char-set",
828 P_("Invisible char set"),
829 P_("Whether the invisible char has been set"),
831 GTK_PARAM_READWRITE));
834 * GtkEntry:caps-lock-warning
836 * Whether password entries will show a warning when Caps Lock is on.
838 * Note that the warning is shown using a secondary icon, and thus
839 * does not work if you are using the secondary icon position for some
844 g_object_class_install_property (gobject_class,
845 PROP_CAPS_LOCK_WARNING,
846 g_param_spec_boolean ("caps-lock-warning",
847 P_("Caps Lock warning"),
848 P_("Whether password entries will show a warning when Caps Lock is on"),
850 GTK_PARAM_READWRITE));
853 * GtkEntry:progress-fraction:
855 * The current fraction of the task that's been completed.
859 g_object_class_install_property (gobject_class,
860 PROP_PROGRESS_FRACTION,
861 g_param_spec_double ("progress-fraction",
862 P_("Progress Fraction"),
863 P_("The current fraction of the task that's been completed"),
867 GTK_PARAM_READWRITE));
870 * GtkEntry:progress-pulse-step:
872 * The fraction of total entry width to move the progress
873 * bouncing block for each call to gtk_entry_progress_pulse().
877 g_object_class_install_property (gobject_class,
878 PROP_PROGRESS_PULSE_STEP,
879 g_param_spec_double ("progress-pulse-step",
880 P_("Progress Pulse Step"),
881 P_("The fraction of total entry width to move the progress bouncing block for each call to gtk_entry_progress_pulse()"),
885 GTK_PARAM_READWRITE));
888 * GtkEntry:primary-icon-pixbuf:
890 * A pixbuf to use as the primary icon for the entry.
894 g_object_class_install_property (gobject_class,
896 g_param_spec_object ("primary-icon-pixbuf",
897 P_("Primary pixbuf"),
898 P_("Primary pixbuf for the entry"),
900 GTK_PARAM_READWRITE));
903 * GtkEntry:secondary-icon-pixbuf:
905 * An pixbuf to use as the secondary icon for the entry.
909 g_object_class_install_property (gobject_class,
910 PROP_PIXBUF_SECONDARY,
911 g_param_spec_object ("secondary-icon-pixbuf",
912 P_("Secondary pixbuf"),
913 P_("Secondary pixbuf for the entry"),
915 GTK_PARAM_READWRITE));
918 * GtkEntry:primary-icon-stock:
920 * The stock id to use for the primary icon for the entry.
924 g_object_class_install_property (gobject_class,
926 g_param_spec_string ("primary-icon-stock",
927 P_("Primary stock ID"),
928 P_("Stock ID for primary icon"),
930 GTK_PARAM_READWRITE));
933 * GtkEntry:secondary-icon-stock:
935 * The stock id to use for the secondary icon for the entry.
939 g_object_class_install_property (gobject_class,
940 PROP_STOCK_SECONDARY,
941 g_param_spec_string ("secondary-icon-stock",
942 P_("Secondary stock ID"),
943 P_("Stock ID for secondary icon"),
945 GTK_PARAM_READWRITE));
948 * GtkEntry:primary-icon-name:
950 * The icon name to use for the primary icon for the entry.
954 g_object_class_install_property (gobject_class,
955 PROP_ICON_NAME_PRIMARY,
956 g_param_spec_string ("primary-icon-name",
957 P_("Primary icon name"),
958 P_("Icon name for primary icon"),
960 GTK_PARAM_READWRITE));
963 * GtkEntry:secondary-icon-name:
965 * The icon name to use for the secondary icon for the entry.
969 g_object_class_install_property (gobject_class,
970 PROP_ICON_NAME_SECONDARY,
971 g_param_spec_string ("secondary-icon-name",
972 P_("Secondary icon name"),
973 P_("Icon name for secondary icon"),
975 GTK_PARAM_READWRITE));
978 * GtkEntry:primary-icon-gicon:
980 * The #GIcon to use for the primary icon for the entry.
984 g_object_class_install_property (gobject_class,
986 g_param_spec_object ("primary-icon-gicon",
988 P_("GIcon for primary icon"),
990 GTK_PARAM_READWRITE));
993 * GtkEntry:secondary-icon-gicon:
995 * The #GIcon to use for the secondary icon for the entry.
999 g_object_class_install_property (gobject_class,
1000 PROP_GICON_SECONDARY,
1001 g_param_spec_object ("secondary-icon-gicon",
1002 P_("Secondary GIcon"),
1003 P_("GIcon for secondary icon"),
1005 GTK_PARAM_READWRITE));
1008 * GtkEntry:primary-icon-storage-type:
1010 * The representation which is used for the primary icon of the entry.
1014 g_object_class_install_property (gobject_class,
1015 PROP_STORAGE_TYPE_PRIMARY,
1016 g_param_spec_enum ("primary-icon-storage-type",
1017 P_("Primary storage type"),
1018 P_("The representation being used for primary icon"),
1019 GTK_TYPE_IMAGE_TYPE,
1021 GTK_PARAM_READABLE));
1024 * GtkEntry:secondary-icon-storage-type:
1026 * The representation which is used for the secondary icon of the entry.
1030 g_object_class_install_property (gobject_class,
1031 PROP_STORAGE_TYPE_SECONDARY,
1032 g_param_spec_enum ("secondary-icon-storage-type",
1033 P_("Secondary storage type"),
1034 P_("The representation being used for secondary icon"),
1035 GTK_TYPE_IMAGE_TYPE,
1037 GTK_PARAM_READABLE));
1040 * GtkEntry:primary-icon-activatable:
1042 * Whether the primary icon is activatable.
1044 * GTK+ emits the #GtkEntry::icon-press and #GtkEntry::icon-release
1045 * signals only on sensitive, activatable icons.
1047 * Sensitive, but non-activatable icons can be used for purely
1048 * informational purposes.
1052 g_object_class_install_property (gobject_class,
1053 PROP_ACTIVATABLE_PRIMARY,
1054 g_param_spec_boolean ("primary-icon-activatable",
1055 P_("Primary icon activatable"),
1056 P_("Whether the primary icon is activatable"),
1058 GTK_PARAM_READWRITE));
1061 * GtkEntry:secondary-icon-activatable:
1063 * Whether the secondary icon is activatable.
1065 * GTK+ emits the #GtkEntry::icon-press and #GtkEntry::icon-release
1066 * signals only on sensitive, activatable icons.
1068 * Sensitive, but non-activatable icons can be used for purely
1069 * informational purposes.
1073 g_object_class_install_property (gobject_class,
1074 PROP_ACTIVATABLE_SECONDARY,
1075 g_param_spec_boolean ("secondary-icon-activatable",
1076 P_("Secondary icon activatable"),
1077 P_("Whether the secondary icon is activatable"),
1079 GTK_PARAM_READWRITE));
1083 * GtkEntry:primary-icon-sensitive:
1085 * Whether the primary icon is sensitive.
1087 * An insensitive icon appears grayed out. GTK+ does not emit the
1088 * #GtkEntry::icon-press and #GtkEntry::icon-release signals and
1089 * does not allow DND from insensitive icons.
1091 * An icon should be set insensitive if the action that would trigger
1092 * when clicked is currently not available.
1096 g_object_class_install_property (gobject_class,
1097 PROP_SENSITIVE_PRIMARY,
1098 g_param_spec_boolean ("primary-icon-sensitive",
1099 P_("Primary icon sensitive"),
1100 P_("Whether the primary icon is sensitive"),
1102 GTK_PARAM_READWRITE));
1105 * GtkEntry:secondary-icon-sensitive:
1107 * Whether the secondary icon is sensitive.
1109 * An insensitive icon appears grayed out. GTK+ does not emit the
1110 * #GtkEntry::icon-press and #GtkEntry::icon-release signals and
1111 * does not allow DND from insensitive icons.
1113 * An icon should be set insensitive if the action that would trigger
1114 * when clicked is currently not available.
1118 g_object_class_install_property (gobject_class,
1119 PROP_SENSITIVE_SECONDARY,
1120 g_param_spec_boolean ("secondary-icon-sensitive",
1121 P_("Secondary icon sensitive"),
1122 P_("Whether the secondary icon is sensitive"),
1124 GTK_PARAM_READWRITE));
1127 * GtkEntry:primary-icon-tooltip-text:
1129 * The contents of the tooltip on the primary icon.
1131 * Also see gtk_entry_set_icon_tooltip_text().
1135 g_object_class_install_property (gobject_class,
1136 PROP_TOOLTIP_TEXT_PRIMARY,
1137 g_param_spec_string ("primary-icon-tooltip-text",
1138 P_("Primary icon tooltip text"),
1139 P_("The contents of the tooltip on the primary icon"),
1141 GTK_PARAM_READWRITE));
1144 * GtkEntry:secondary-icon-tooltip-text:
1146 * The contents of the tooltip on the secondary icon.
1148 * Also see gtk_entry_set_icon_tooltip_text().
1152 g_object_class_install_property (gobject_class,
1153 PROP_TOOLTIP_TEXT_SECONDARY,
1154 g_param_spec_string ("secondary-icon-tooltip-text",
1155 P_("Secondary icon tooltip text"),
1156 P_("The contents of the tooltip on the secondary icon"),
1158 GTK_PARAM_READWRITE));
1161 * GtkEntry:primary-icon-tooltip-markup:
1163 * The contents of the tooltip on the primary icon, which is marked up
1164 * with the <link linkend="PangoMarkupFormat">Pango text markup
1167 * Also see gtk_entry_set_icon_tooltip_markup().
1171 g_object_class_install_property (gobject_class,
1172 PROP_TOOLTIP_MARKUP_PRIMARY,
1173 g_param_spec_string ("primary-icon-tooltip-markup",
1174 P_("Primary icon tooltip markup"),
1175 P_("The contents of the tooltip on the primary icon"),
1177 GTK_PARAM_READWRITE));
1180 * GtkEntry:secondary-icon-tooltip-markup:
1182 * The contents of the tooltip on the secondary icon, which is marked up
1183 * with the <link linkend="PangoMarkupFormat">Pango text markup
1186 * Also see gtk_entry_set_icon_tooltip_markup().
1190 g_object_class_install_property (gobject_class,
1191 PROP_TOOLTIP_MARKUP_SECONDARY,
1192 g_param_spec_string ("secondary-icon-tooltip-markup",
1193 P_("Secondary icon tooltip markup"),
1194 P_("The contents of the tooltip on the secondary icon"),
1196 GTK_PARAM_READWRITE));
1199 * GtkEntry:im-module:
1201 * Which IM (input method) module should be used for this entry.
1202 * See #GtkIMContext.
1204 * Setting this to a non-%NULL value overrides the
1205 * system-wide IM module setting. See the GtkSettings
1206 * #GtkSettings:gtk-im-module property.
1210 g_object_class_install_property (gobject_class,
1212 g_param_spec_string ("im-module",
1214 P_("Which IM module should be used"),
1216 GTK_PARAM_READWRITE));
1219 * GtkEntry:icon-prelight:
1221 * The prelight style property determines whether activatable
1222 * icons prelight on mouseover.
1226 gtk_widget_class_install_style_property (widget_class,
1227 g_param_spec_boolean ("icon-prelight",
1228 P_("Icon Prelight"),
1229 P_("Whether activatable icons should prelight when hovered"),
1231 GTK_PARAM_READABLE));
1234 * GtkEntry::progress-border:
1236 * The border around the progress bar in the entry.
1240 gtk_widget_class_install_style_property (widget_class,
1241 g_param_spec_boxed ("progress-border",
1242 P_("Progress Border"),
1243 P_("Border around the progress bar"),
1245 GTK_PARAM_READABLE));
1248 * GtkEntry::invisible-char:
1250 * The invisible character is used when masking entry contents (in
1251 * \"password mode\")"). When it is not explicitly set with the
1252 * #GtkEntry::invisible-char property, GTK+ determines the character
1253 * to use from a list of possible candidates, depending on availability
1254 * in the current font.
1256 * This style property allows the theme to prepend a character
1257 * to the list of candidates.
1261 gtk_widget_class_install_style_property (widget_class,
1262 g_param_spec_unichar ("invisible-char",
1263 P_("Invisible character"),
1264 P_("The character to use when masking entry contents (in \"password mode\")"),
1266 GTK_PARAM_READABLE));
1269 * GtkEntry::populate-popup:
1270 * @entry: The entry on which the signal is emitted
1271 * @menu: the menu that is being populated
1273 * The ::populate-popup signal gets emitted before showing the
1274 * context menu of the entry.
1276 * If you need to add items to the context menu, connect
1277 * to this signal and append your menuitems to the @menu.
1279 signals[POPULATE_POPUP] =
1280 g_signal_new (I_("populate-popup"),
1281 G_OBJECT_CLASS_TYPE (gobject_class),
1283 G_STRUCT_OFFSET (GtkEntryClass, populate_popup),
1285 _gtk_marshal_VOID__OBJECT,
1289 /* Action signals */
1292 * GtkEntry::activate:
1293 * @entry: The entry on which the signal is emitted
1295 * A <link linkend="keybinding-signals">keybinding signal</link>
1296 * which gets emitted when the user activates the entry.
1298 * Applications should not connect to it, but may emit it with
1299 * g_signal_emit_by_name() if they need to control activation
1302 * The default bindings for this signal are all forms of the Enter key.
1305 g_signal_new (I_("activate"),
1306 G_OBJECT_CLASS_TYPE (gobject_class),
1307 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1308 G_STRUCT_OFFSET (GtkEntryClass, activate),
1310 _gtk_marshal_VOID__VOID,
1312 widget_class->activate_signal = signals[ACTIVATE];
1315 * GtkEntry::move-cursor:
1316 * @entry: the object which received the signal
1317 * @step: the granularity of the move, as a #GtkMovementStep
1318 * @count: the number of @step units to move
1319 * @extend_selection: %TRUE if the move should extend the selection
1321 * The ::move-cursor signal is a
1322 * <link linkend="keybinding-signals">keybinding signal</link>
1323 * which gets emitted when the user initiates a cursor movement.
1324 * If the cursor is not visible in @entry, this signal causes
1325 * the viewport to be moved instead.
1327 * Applications should not connect to it, but may emit it with
1328 * g_signal_emit_by_name() if they need to control the cursor
1331 * The default bindings for this signal come in two variants,
1332 * the variant with the Shift modifier extends the selection,
1333 * the variant without the Shift modifer does not.
1334 * There are too many key combinations to list them all here.
1336 * <listitem>Arrow keys move by individual characters/lines</listitem>
1337 * <listitem>Ctrl-arrow key combinations move by words/paragraphs</listitem>
1338 * <listitem>Home/End keys move to the ends of the buffer</listitem>
1341 signals[MOVE_CURSOR] =
1342 g_signal_new (I_("move-cursor"),
1343 G_OBJECT_CLASS_TYPE (gobject_class),
1344 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1345 G_STRUCT_OFFSET (GtkEntryClass, move_cursor),
1347 _gtk_marshal_VOID__ENUM_INT_BOOLEAN,
1349 GTK_TYPE_MOVEMENT_STEP,
1354 * GtkEntry::insert-at-cursor:
1355 * @entry: the object which received the signal
1356 * @string: the string to insert
1358 * The ::insert-at-cursor signal is a
1359 * <link linkend="keybinding-signals">keybinding signal</link>
1360 * which gets emitted when the user initiates the insertion of a
1361 * fixed string at the cursor.
1363 * This signal has no default bindings.
1365 signals[INSERT_AT_CURSOR] =
1366 g_signal_new (I_("insert-at-cursor"),
1367 G_OBJECT_CLASS_TYPE (gobject_class),
1368 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1369 G_STRUCT_OFFSET (GtkEntryClass, insert_at_cursor),
1371 _gtk_marshal_VOID__STRING,
1376 * GtkEntry::delete-from-cursor:
1377 * @entry: the object which received the signal
1378 * @type: the granularity of the deletion, as a #GtkDeleteType
1379 * @count: the number of @type units to delete
1381 * The ::delete-from-cursor signal is a
1382 * <link linkend="keybinding-signals">keybinding signal</link>
1383 * which gets emitted when the user initiates a text deletion.
1385 * If the @type is %GTK_DELETE_CHARS, GTK+ deletes the selection
1386 * if there is one, otherwise it deletes the requested number
1389 * The default bindings for this signal are
1390 * Delete for deleting a character and Ctrl-Delete for
1393 signals[DELETE_FROM_CURSOR] =
1394 g_signal_new (I_("delete-from-cursor"),
1395 G_OBJECT_CLASS_TYPE (gobject_class),
1396 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1397 G_STRUCT_OFFSET (GtkEntryClass, delete_from_cursor),
1399 _gtk_marshal_VOID__ENUM_INT,
1401 GTK_TYPE_DELETE_TYPE,
1405 * GtkEntry::backspace:
1406 * @entry: the object which received the signal
1408 * The ::backspace signal is a
1409 * <link linkend="keybinding-signals">keybinding signal</link>
1410 * which gets emitted when the user asks for it.
1412 * The default bindings for this signal are
1413 * Backspace and Shift-Backspace.
1415 signals[BACKSPACE] =
1416 g_signal_new (I_("backspace"),
1417 G_OBJECT_CLASS_TYPE (gobject_class),
1418 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1419 G_STRUCT_OFFSET (GtkEntryClass, backspace),
1421 _gtk_marshal_VOID__VOID,
1425 * GtkEntry::cut-clipboard:
1426 * @entry: the object which received the signal
1428 * The ::cut-clipboard signal is a
1429 * <link linkend="keybinding-signals">keybinding signal</link>
1430 * which gets emitted to cut the selection to the clipboard.
1432 * The default bindings for this signal are
1433 * Ctrl-x and Shift-Delete.
1435 signals[CUT_CLIPBOARD] =
1436 g_signal_new (I_("cut-clipboard"),
1437 G_OBJECT_CLASS_TYPE (gobject_class),
1438 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1439 G_STRUCT_OFFSET (GtkEntryClass, cut_clipboard),
1441 _gtk_marshal_VOID__VOID,
1445 * GtkEntry::copy-clipboard:
1446 * @entry: the object which received the signal
1448 * The ::copy-clipboard signal is a
1449 * <link linkend="keybinding-signals">keybinding signal</link>
1450 * which gets emitted to copy the selection to the clipboard.
1452 * The default bindings for this signal are
1453 * Ctrl-c and Ctrl-Insert.
1455 signals[COPY_CLIPBOARD] =
1456 g_signal_new (I_("copy-clipboard"),
1457 G_OBJECT_CLASS_TYPE (gobject_class),
1458 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1459 G_STRUCT_OFFSET (GtkEntryClass, copy_clipboard),
1461 _gtk_marshal_VOID__VOID,
1465 * GtkEntry::paste-clipboard:
1466 * @entry: the object which received the signal
1468 * The ::paste-clipboard signal is a
1469 * <link linkend="keybinding-signals">keybinding signal</link>
1470 * which gets emitted to paste the contents of the clipboard
1471 * into the text view.
1473 * The default bindings for this signal are
1474 * Ctrl-v and Shift-Insert.
1476 signals[PASTE_CLIPBOARD] =
1477 g_signal_new (I_("paste-clipboard"),
1478 G_OBJECT_CLASS_TYPE (gobject_class),
1479 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1480 G_STRUCT_OFFSET (GtkEntryClass, paste_clipboard),
1482 _gtk_marshal_VOID__VOID,
1486 * GtkEntry::toggle-overwrite:
1487 * @entry: the object which received the signal
1489 * The ::toggle-overwrite signal is a
1490 * <link linkend="keybinding-signals">keybinding signal</link>
1491 * which gets emitted to toggle the overwrite mode of the entry.
1493 * The default bindings for this signal is Insert.
1495 signals[TOGGLE_OVERWRITE] =
1496 g_signal_new (I_("toggle-overwrite"),
1497 G_OBJECT_CLASS_TYPE (gobject_class),
1498 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1499 G_STRUCT_OFFSET (GtkEntryClass, toggle_overwrite),
1501 _gtk_marshal_VOID__VOID,
1505 * GtkEntry::icon-press:
1506 * @entry: The entry on which the signal is emitted
1507 * @icon_pos: The position of the clicked icon
1508 * @event: the button press event
1510 * The ::icon-press signal is emitted when an activatable icon
1515 signals[ICON_PRESS] =
1516 g_signal_new (I_("icon-press"),
1517 G_TYPE_FROM_CLASS (gobject_class),
1521 _gtk_marshal_VOID__ENUM_BOXED,
1523 GTK_TYPE_ENTRY_ICON_POSITION,
1524 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1527 * GtkEntry::icon-release:
1528 * @entry: The entry on which the signal is emitted
1529 * @icon_pos: The position of the clicked icon
1530 * @event: the button release event
1532 * The ::icon-release signal is emitted on the button release from a
1533 * mouse click over an activatable icon.
1537 signals[ICON_RELEASE] =
1538 g_signal_new (I_("icon-release"),
1539 G_TYPE_FROM_CLASS (gobject_class),
1543 _gtk_marshal_VOID__ENUM_BOXED,
1545 GTK_TYPE_ENTRY_ICON_POSITION,
1546 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1553 binding_set = gtk_binding_set_by_class (class);
1555 /* Moving the insertion point */
1556 add_move_binding (binding_set, GDK_Right, 0,
1557 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1559 add_move_binding (binding_set, GDK_Left, 0,
1560 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1562 add_move_binding (binding_set, GDK_KP_Right, 0,
1563 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1565 add_move_binding (binding_set, GDK_KP_Left, 0,
1566 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1568 add_move_binding (binding_set, GDK_Right, GDK_CONTROL_MASK,
1569 GTK_MOVEMENT_WORDS, 1);
1571 add_move_binding (binding_set, GDK_Left, GDK_CONTROL_MASK,
1572 GTK_MOVEMENT_WORDS, -1);
1574 add_move_binding (binding_set, GDK_KP_Right, GDK_CONTROL_MASK,
1575 GTK_MOVEMENT_WORDS, 1);
1577 add_move_binding (binding_set, GDK_KP_Left, GDK_CONTROL_MASK,
1578 GTK_MOVEMENT_WORDS, -1);
1580 add_move_binding (binding_set, GDK_Home, 0,
1581 GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
1583 add_move_binding (binding_set, GDK_End, 0,
1584 GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
1586 add_move_binding (binding_set, GDK_KP_Home, 0,
1587 GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
1589 add_move_binding (binding_set, GDK_KP_End, 0,
1590 GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
1592 add_move_binding (binding_set, GDK_Home, GDK_CONTROL_MASK,
1593 GTK_MOVEMENT_BUFFER_ENDS, -1);
1595 add_move_binding (binding_set, GDK_End, GDK_CONTROL_MASK,
1596 GTK_MOVEMENT_BUFFER_ENDS, 1);
1598 add_move_binding (binding_set, GDK_KP_Home, GDK_CONTROL_MASK,
1599 GTK_MOVEMENT_BUFFER_ENDS, -1);
1601 add_move_binding (binding_set, GDK_KP_End, GDK_CONTROL_MASK,
1602 GTK_MOVEMENT_BUFFER_ENDS, 1);
1606 gtk_binding_entry_add_signal (binding_set, GDK_a, GDK_CONTROL_MASK,
1608 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1610 G_TYPE_BOOLEAN, FALSE);
1611 gtk_binding_entry_add_signal (binding_set, GDK_a, GDK_CONTROL_MASK,
1613 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1615 G_TYPE_BOOLEAN, TRUE);
1617 gtk_binding_entry_add_signal (binding_set, GDK_slash, GDK_CONTROL_MASK,
1619 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1621 G_TYPE_BOOLEAN, FALSE);
1622 gtk_binding_entry_add_signal (binding_set, GDK_slash, GDK_CONTROL_MASK,
1624 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1626 G_TYPE_BOOLEAN, TRUE);
1629 gtk_binding_entry_add_signal (binding_set, GDK_backslash, GDK_CONTROL_MASK,
1631 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_VISUAL_POSITIONS,
1633 G_TYPE_BOOLEAN, FALSE);
1634 gtk_binding_entry_add_signal (binding_set, GDK_a, GDK_SHIFT_MASK | GDK_CONTROL_MASK,
1636 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_VISUAL_POSITIONS,
1638 G_TYPE_BOOLEAN, FALSE);
1642 gtk_binding_entry_add_signal (binding_set, GDK_Return, 0,
1644 gtk_binding_entry_add_signal (binding_set, GDK_ISO_Enter, 0,
1646 gtk_binding_entry_add_signal (binding_set, GDK_KP_Enter, 0,
1650 gtk_binding_entry_add_signal (binding_set, GDK_Delete, 0,
1651 "delete-from-cursor", 2,
1652 G_TYPE_ENUM, GTK_DELETE_CHARS,
1655 gtk_binding_entry_add_signal (binding_set, GDK_KP_Delete, 0,
1656 "delete-from-cursor", 2,
1657 G_TYPE_ENUM, GTK_DELETE_CHARS,
1660 gtk_binding_entry_add_signal (binding_set, GDK_BackSpace, 0,
1663 /* Make this do the same as Backspace, to help with mis-typing */
1664 gtk_binding_entry_add_signal (binding_set, GDK_BackSpace, GDK_SHIFT_MASK,
1667 gtk_binding_entry_add_signal (binding_set, GDK_Delete, GDK_CONTROL_MASK,
1668 "delete-from-cursor", 2,
1669 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1672 gtk_binding_entry_add_signal (binding_set, GDK_KP_Delete, GDK_CONTROL_MASK,
1673 "delete-from-cursor", 2,
1674 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1677 gtk_binding_entry_add_signal (binding_set, GDK_BackSpace, GDK_CONTROL_MASK,
1678 "delete-from-cursor", 2,
1679 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1682 /* Cut/copy/paste */
1684 gtk_binding_entry_add_signal (binding_set, GDK_x, GDK_CONTROL_MASK,
1685 "cut-clipboard", 0);
1686 gtk_binding_entry_add_signal (binding_set, GDK_c, GDK_CONTROL_MASK,
1687 "copy-clipboard", 0);
1688 gtk_binding_entry_add_signal (binding_set, GDK_v, GDK_CONTROL_MASK,
1689 "paste-clipboard", 0);
1691 gtk_binding_entry_add_signal (binding_set, GDK_Delete, GDK_SHIFT_MASK,
1692 "cut-clipboard", 0);
1693 gtk_binding_entry_add_signal (binding_set, GDK_Insert, GDK_CONTROL_MASK,
1694 "copy-clipboard", 0);
1695 gtk_binding_entry_add_signal (binding_set, GDK_Insert, GDK_SHIFT_MASK,
1696 "paste-clipboard", 0);
1699 gtk_binding_entry_add_signal (binding_set, GDK_Insert, 0,
1700 "toggle-overwrite", 0);
1701 gtk_binding_entry_add_signal (binding_set, GDK_KP_Insert, 0,
1702 "toggle-overwrite", 0);
1705 * GtkEntry:inner-border:
1707 * Sets the text area's border between the text and the frame.
1711 gtk_widget_class_install_style_property (widget_class,
1712 g_param_spec_boxed ("inner-border",
1714 P_("Border between text and frame."),
1716 GTK_PARAM_READABLE));
1719 * GtkEntry:state-hint:
1721 * Indicates whether to pass a proper widget state when
1722 * drawing the shadow and the widget background.
1726 gtk_widget_class_install_style_property (widget_class,
1727 g_param_spec_boolean ("state-hint",
1729 P_("Whether to pass a proper state when drawing shadow or background"),
1731 GTK_PARAM_READABLE));
1733 gtk_settings_install_property (g_param_spec_boolean ("gtk-entry-select-on-focus",
1734 P_("Select on focus"),
1735 P_("Whether to select the contents of an entry when it is focused"),
1737 GTK_PARAM_READWRITE));
1740 * GtkSettings:gtk-entry-password-hint-timeout:
1742 * How long to show the last input character in hidden
1743 * entries. This value is in milliseconds. 0 disables showing the
1744 * last char. 600 is a good value for enabling it.
1748 gtk_settings_install_property (g_param_spec_uint ("gtk-entry-password-hint-timeout",
1749 P_("Password Hint Timeout"),
1750 P_("How long to show the last input character in hidden entries"),
1752 GTK_PARAM_READWRITE));
1754 g_type_class_add_private (gobject_class, sizeof (GtkEntryPrivate));
1758 gtk_entry_editable_init (GtkEditableClass *iface)
1760 iface->do_insert_text = gtk_entry_insert_text;
1761 iface->do_delete_text = gtk_entry_delete_text;
1762 iface->insert_text = gtk_entry_real_insert_text;
1763 iface->delete_text = gtk_entry_real_delete_text;
1764 iface->get_chars = gtk_entry_get_chars;
1765 iface->set_selection_bounds = gtk_entry_set_selection_bounds;
1766 iface->get_selection_bounds = gtk_entry_get_selection_bounds;
1767 iface->set_position = gtk_entry_real_set_position;
1768 iface->get_position = gtk_entry_get_position;
1772 gtk_entry_cell_editable_init (GtkCellEditableIface *iface)
1774 iface->start_editing = gtk_entry_start_editing;
1778 gtk_entry_set_property (GObject *object,
1780 const GValue *value,
1783 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (object);
1784 GtkEntry *entry = GTK_ENTRY (object);
1789 gtk_entry_set_buffer (entry, g_value_get_object (value));
1794 gboolean new_value = g_value_get_boolean (value);
1796 if (new_value != entry->editable)
1800 _gtk_entry_reset_im_context (entry);
1801 if (GTK_WIDGET_HAS_FOCUS (entry))
1802 gtk_im_context_focus_out (entry->im_context);
1804 entry->preedit_length = 0;
1805 entry->preedit_cursor = 0;
1808 entry->editable = new_value;
1810 if (new_value && GTK_WIDGET_HAS_FOCUS (entry))
1811 gtk_im_context_focus_in (entry->im_context);
1813 gtk_entry_queue_draw (entry);
1818 case PROP_MAX_LENGTH:
1819 gtk_entry_set_max_length (entry, g_value_get_int (value));
1822 case PROP_VISIBILITY:
1823 gtk_entry_set_visibility (entry, g_value_get_boolean (value));
1826 case PROP_HAS_FRAME:
1827 gtk_entry_set_has_frame (entry, g_value_get_boolean (value));
1830 case PROP_INNER_BORDER:
1831 gtk_entry_set_inner_border (entry, g_value_get_boxed (value));
1834 case PROP_INVISIBLE_CHAR:
1835 gtk_entry_set_invisible_char (entry, g_value_get_uint (value));
1838 case PROP_ACTIVATES_DEFAULT:
1839 gtk_entry_set_activates_default (entry, g_value_get_boolean (value));
1842 case PROP_WIDTH_CHARS:
1843 gtk_entry_set_width_chars (entry, g_value_get_int (value));
1847 gtk_entry_set_text (entry, g_value_get_string (value));
1851 gtk_entry_set_alignment (entry, g_value_get_float (value));
1854 case PROP_TRUNCATE_MULTILINE:
1855 entry->truncate_multiline = g_value_get_boolean (value);
1858 case PROP_SHADOW_TYPE:
1859 priv->shadow_type = g_value_get_enum (value);
1862 case PROP_OVERWRITE_MODE:
1863 gtk_entry_set_overwrite_mode (entry, g_value_get_boolean (value));
1866 case PROP_INVISIBLE_CHAR_SET:
1867 if (g_value_get_boolean (value))
1868 priv->invisible_char_set = TRUE;
1870 gtk_entry_unset_invisible_char (entry);
1873 case PROP_CAPS_LOCK_WARNING:
1874 priv->caps_lock_warning = g_value_get_boolean (value);
1877 case PROP_PROGRESS_FRACTION:
1878 gtk_entry_set_progress_fraction (entry, g_value_get_double (value));
1881 case PROP_PROGRESS_PULSE_STEP:
1882 gtk_entry_set_progress_pulse_step (entry, g_value_get_double (value));
1885 case PROP_PIXBUF_PRIMARY:
1886 gtk_entry_set_icon_from_pixbuf (entry,
1887 GTK_ENTRY_ICON_PRIMARY,
1888 g_value_get_object (value));
1891 case PROP_PIXBUF_SECONDARY:
1892 gtk_entry_set_icon_from_pixbuf (entry,
1893 GTK_ENTRY_ICON_SECONDARY,
1894 g_value_get_object (value));
1897 case PROP_STOCK_PRIMARY:
1898 gtk_entry_set_icon_from_stock (entry,
1899 GTK_ENTRY_ICON_PRIMARY,
1900 g_value_get_string (value));
1903 case PROP_STOCK_SECONDARY:
1904 gtk_entry_set_icon_from_stock (entry,
1905 GTK_ENTRY_ICON_SECONDARY,
1906 g_value_get_string (value));
1909 case PROP_ICON_NAME_PRIMARY:
1910 gtk_entry_set_icon_from_icon_name (entry,
1911 GTK_ENTRY_ICON_PRIMARY,
1912 g_value_get_string (value));
1915 case PROP_ICON_NAME_SECONDARY:
1916 gtk_entry_set_icon_from_icon_name (entry,
1917 GTK_ENTRY_ICON_SECONDARY,
1918 g_value_get_string (value));
1921 case PROP_GICON_PRIMARY:
1922 gtk_entry_set_icon_from_gicon (entry,
1923 GTK_ENTRY_ICON_PRIMARY,
1924 g_value_get_object (value));
1927 case PROP_GICON_SECONDARY:
1928 gtk_entry_set_icon_from_gicon (entry,
1929 GTK_ENTRY_ICON_SECONDARY,
1930 g_value_get_object (value));
1933 case PROP_ACTIVATABLE_PRIMARY:
1934 gtk_entry_set_icon_activatable (entry,
1935 GTK_ENTRY_ICON_PRIMARY,
1936 g_value_get_boolean (value));
1939 case PROP_ACTIVATABLE_SECONDARY:
1940 gtk_entry_set_icon_activatable (entry,
1941 GTK_ENTRY_ICON_SECONDARY,
1942 g_value_get_boolean (value));
1945 case PROP_SENSITIVE_PRIMARY:
1946 gtk_entry_set_icon_sensitive (entry,
1947 GTK_ENTRY_ICON_PRIMARY,
1948 g_value_get_boolean (value));
1951 case PROP_SENSITIVE_SECONDARY:
1952 gtk_entry_set_icon_sensitive (entry,
1953 GTK_ENTRY_ICON_SECONDARY,
1954 g_value_get_boolean (value));
1957 case PROP_TOOLTIP_TEXT_PRIMARY:
1958 gtk_entry_set_icon_tooltip_text (entry,
1959 GTK_ENTRY_ICON_PRIMARY,
1960 g_value_get_string (value));
1963 case PROP_TOOLTIP_TEXT_SECONDARY:
1964 gtk_entry_set_icon_tooltip_text (entry,
1965 GTK_ENTRY_ICON_SECONDARY,
1966 g_value_get_string (value));
1969 case PROP_TOOLTIP_MARKUP_PRIMARY:
1970 gtk_entry_set_icon_tooltip_markup (entry,
1971 GTK_ENTRY_ICON_PRIMARY,
1972 g_value_get_string (value));
1975 case PROP_TOOLTIP_MARKUP_SECONDARY:
1976 gtk_entry_set_icon_tooltip_markup (entry,
1977 GTK_ENTRY_ICON_SECONDARY,
1978 g_value_get_string (value));
1981 case PROP_IM_MODULE:
1982 g_free (priv->im_module);
1983 priv->im_module = g_strdup (g_value_get_string (value));
1984 if (GTK_IS_IM_MULTICONTEXT (entry->im_context))
1985 gtk_im_multicontext_set_context_id (GTK_IM_MULTICONTEXT (entry->im_context), priv->im_module);
1988 case PROP_SCROLL_OFFSET:
1989 case PROP_CURSOR_POSITION:
1991 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1997 gtk_entry_get_property (GObject *object,
2002 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (object);
2003 GtkEntry *entry = GTK_ENTRY (object);
2008 g_value_set_object (value, gtk_entry_get_buffer (entry));
2011 case PROP_CURSOR_POSITION:
2012 g_value_set_int (value, entry->current_pos);
2015 case PROP_SELECTION_BOUND:
2016 g_value_set_int (value, entry->selection_bound);
2020 g_value_set_boolean (value, entry->editable);
2023 case PROP_MAX_LENGTH:
2024 g_value_set_int (value, gtk_entry_buffer_get_max_length (get_buffer (entry)));
2027 case PROP_VISIBILITY:
2028 g_value_set_boolean (value, entry->visible);
2031 case PROP_HAS_FRAME:
2032 g_value_set_boolean (value, entry->has_frame);
2035 case PROP_INNER_BORDER:
2036 g_value_set_boxed (value, gtk_entry_get_inner_border (entry));
2039 case PROP_INVISIBLE_CHAR:
2040 g_value_set_uint (value, entry->invisible_char);
2043 case PROP_ACTIVATES_DEFAULT:
2044 g_value_set_boolean (value, entry->activates_default);
2047 case PROP_WIDTH_CHARS:
2048 g_value_set_int (value, entry->width_chars);
2051 case PROP_SCROLL_OFFSET:
2052 g_value_set_int (value, entry->scroll_offset);
2056 g_value_set_string (value, gtk_entry_get_text (entry));
2060 g_value_set_float (value, gtk_entry_get_alignment (entry));
2063 case PROP_TRUNCATE_MULTILINE:
2064 g_value_set_boolean (value, entry->truncate_multiline);
2067 case PROP_SHADOW_TYPE:
2068 g_value_set_enum (value, priv->shadow_type);
2071 case PROP_OVERWRITE_MODE:
2072 g_value_set_boolean (value, entry->overwrite_mode);
2075 case PROP_TEXT_LENGTH:
2076 g_value_set_uint (value, gtk_entry_buffer_get_length (get_buffer (entry)));
2079 case PROP_INVISIBLE_CHAR_SET:
2080 g_value_set_boolean (value, priv->invisible_char_set);
2083 case PROP_IM_MODULE:
2084 g_value_set_string (value, priv->im_module);
2087 case PROP_CAPS_LOCK_WARNING:
2088 g_value_set_boolean (value, priv->caps_lock_warning);
2091 case PROP_PROGRESS_FRACTION:
2092 g_value_set_double (value, priv->progress_fraction);
2095 case PROP_PROGRESS_PULSE_STEP:
2096 g_value_set_double (value, priv->progress_pulse_fraction);
2099 case PROP_PIXBUF_PRIMARY:
2100 g_value_set_object (value,
2101 gtk_entry_get_icon_pixbuf (entry,
2102 GTK_ENTRY_ICON_PRIMARY));
2105 case PROP_PIXBUF_SECONDARY:
2106 g_value_set_object (value,
2107 gtk_entry_get_icon_pixbuf (entry,
2108 GTK_ENTRY_ICON_SECONDARY));
2111 case PROP_STOCK_PRIMARY:
2112 g_value_set_string (value,
2113 gtk_entry_get_icon_stock (entry,
2114 GTK_ENTRY_ICON_PRIMARY));
2117 case PROP_STOCK_SECONDARY:
2118 g_value_set_string (value,
2119 gtk_entry_get_icon_stock (entry,
2120 GTK_ENTRY_ICON_SECONDARY));
2123 case PROP_ICON_NAME_PRIMARY:
2124 g_value_set_string (value,
2125 gtk_entry_get_icon_name (entry,
2126 GTK_ENTRY_ICON_PRIMARY));
2129 case PROP_ICON_NAME_SECONDARY:
2130 g_value_set_string (value,
2131 gtk_entry_get_icon_name (entry,
2132 GTK_ENTRY_ICON_SECONDARY));
2135 case PROP_GICON_PRIMARY:
2136 g_value_set_object (value,
2137 gtk_entry_get_icon_gicon (entry,
2138 GTK_ENTRY_ICON_PRIMARY));
2141 case PROP_GICON_SECONDARY:
2142 g_value_set_object (value,
2143 gtk_entry_get_icon_gicon (entry,
2144 GTK_ENTRY_ICON_SECONDARY));
2147 case PROP_STORAGE_TYPE_PRIMARY:
2148 g_value_set_enum (value,
2149 gtk_entry_get_icon_storage_type (entry,
2150 GTK_ENTRY_ICON_PRIMARY));
2153 case PROP_STORAGE_TYPE_SECONDARY:
2154 g_value_set_enum (value,
2155 gtk_entry_get_icon_storage_type (entry,
2156 GTK_ENTRY_ICON_SECONDARY));
2159 case PROP_ACTIVATABLE_PRIMARY:
2160 g_value_set_boolean (value,
2161 gtk_entry_get_icon_activatable (entry, GTK_ENTRY_ICON_PRIMARY));
2164 case PROP_ACTIVATABLE_SECONDARY:
2165 g_value_set_boolean (value,
2166 gtk_entry_get_icon_activatable (entry, GTK_ENTRY_ICON_SECONDARY));
2169 case PROP_SENSITIVE_PRIMARY:
2170 g_value_set_boolean (value,
2171 gtk_entry_get_icon_sensitive (entry, GTK_ENTRY_ICON_PRIMARY));
2174 case PROP_SENSITIVE_SECONDARY:
2175 g_value_set_boolean (value,
2176 gtk_entry_get_icon_sensitive (entry, GTK_ENTRY_ICON_SECONDARY));
2179 case PROP_TOOLTIP_TEXT_PRIMARY:
2180 g_value_take_string (value,
2181 gtk_entry_get_icon_tooltip_text (entry, GTK_ENTRY_ICON_PRIMARY));
2184 case PROP_TOOLTIP_TEXT_SECONDARY:
2185 g_value_take_string (value,
2186 gtk_entry_get_icon_tooltip_text (entry, GTK_ENTRY_ICON_SECONDARY));
2189 case PROP_TOOLTIP_MARKUP_PRIMARY:
2190 g_value_take_string (value,
2191 gtk_entry_get_icon_tooltip_markup (entry, GTK_ENTRY_ICON_PRIMARY));
2194 case PROP_TOOLTIP_MARKUP_SECONDARY:
2195 g_value_take_string (value,
2196 gtk_entry_get_icon_tooltip_markup (entry, GTK_ENTRY_ICON_SECONDARY));
2200 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2206 find_invisible_char (GtkWidget *widget)
2208 PangoLayout *layout;
2209 PangoAttrList *attr_list;
2211 gunichar invisible_chars [] = {
2213 0x25cf, /* BLACK CIRCLE */
2214 0x2022, /* BULLET */
2215 0x2731, /* HEAVY ASTERISK */
2216 0x273a /* SIXTEEN POINTED ASTERISK */
2220 gtk_widget_style_get (widget,
2221 "invisible-char", &invisible_chars[0],
2224 layout = gtk_widget_create_pango_layout (widget, NULL);
2226 attr_list = pango_attr_list_new ();
2227 pango_attr_list_insert (attr_list, pango_attr_fallback_new (FALSE));
2229 pango_layout_set_attributes (layout, attr_list);
2230 pango_attr_list_unref (attr_list);
2232 for (i = (invisible_chars[0] != 0 ? 0 : 1); i < G_N_ELEMENTS (invisible_chars); i++)
2234 gchar text[7] = { 0, };
2237 len = g_unichar_to_utf8 (invisible_chars[i], text);
2238 pango_layout_set_text (layout, text, len);
2240 count = pango_layout_get_unknown_glyphs_count (layout);
2244 g_object_unref (layout);
2245 return invisible_chars[i];
2249 g_object_unref (layout);
2255 gtk_entry_init (GtkEntry *entry)
2257 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2259 GTK_WIDGET_SET_FLAGS (entry, GTK_CAN_FOCUS);
2261 entry->editable = TRUE;
2262 entry->visible = TRUE;
2263 entry->invisible_char = find_invisible_char (GTK_WIDGET (entry));
2264 entry->dnd_position = -1;
2265 entry->width_chars = -1;
2266 entry->is_cell_renderer = FALSE;
2267 entry->editing_canceled = FALSE;
2268 entry->has_frame = TRUE;
2269 entry->truncate_multiline = FALSE;
2270 priv->shadow_type = GTK_SHADOW_IN;
2272 priv->caps_lock_warning = TRUE;
2273 priv->caps_lock_warning_shown = FALSE;
2274 priv->progress_fraction = 0.0;
2275 priv->progress_pulse_fraction = 0.1;
2277 gtk_drag_dest_set (GTK_WIDGET (entry),
2278 GTK_DEST_DEFAULT_HIGHLIGHT,
2280 GDK_ACTION_COPY | GDK_ACTION_MOVE);
2281 gtk_drag_dest_add_text_targets (GTK_WIDGET (entry));
2283 /* This object is completely private. No external entity can gain a reference
2284 * to it; so we create it here and destroy it in finalize().
2286 entry->im_context = gtk_im_multicontext_new ();
2288 g_signal_connect (entry->im_context, "commit",
2289 G_CALLBACK (gtk_entry_commit_cb), entry);
2290 g_signal_connect (entry->im_context, "preedit-changed",
2291 G_CALLBACK (gtk_entry_preedit_changed_cb), entry);
2292 g_signal_connect (entry->im_context, "retrieve-surrounding",
2293 G_CALLBACK (gtk_entry_retrieve_surrounding_cb), entry);
2294 g_signal_connect (entry->im_context, "delete-surrounding",
2295 G_CALLBACK (gtk_entry_delete_surrounding_cb), entry);
2300 get_icon_width (GtkEntry *entry,
2301 GtkEntryIconPosition icon_pos)
2303 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2304 EntryIconInfo *icon_info = priv->icons[icon_pos];
2306 GtkSettings *settings;
2307 gint menu_icon_width;
2309 if (!icon_info || icon_info->pixbuf == NULL)
2312 screen = gtk_widget_get_screen (GTK_WIDGET (entry));
2313 settings = gtk_settings_get_for_screen (screen);
2315 gtk_icon_size_lookup_for_settings (settings, GTK_ICON_SIZE_MENU,
2316 &menu_icon_width, NULL);
2318 return MAX (gdk_pixbuf_get_width (icon_info->pixbuf), menu_icon_width);
2322 get_icon_allocations (GtkEntry *entry,
2323 GtkAllocation *primary,
2324 GtkAllocation *secondary)
2327 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2328 gint x, y, width, height;
2330 get_text_area_size (entry, &x, &y, &width, &height);
2332 if (GTK_WIDGET_HAS_FOCUS (entry) && !priv->interior_focus)
2333 y += priv->focus_width;
2336 primary->height = height;
2337 primary->width = get_icon_width (entry, GTK_ENTRY_ICON_PRIMARY);
2338 if (primary->width > 0)
2339 primary->width += 2 * priv->icon_margin;
2342 secondary->height = height;
2343 secondary->width = get_icon_width (entry, GTK_ENTRY_ICON_SECONDARY);
2344 if (secondary->width > 0)
2345 secondary->width += 2 * priv->icon_margin;
2347 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
2349 primary->x = x + width - primary->width;
2355 secondary->x = x + width - secondary->width;
2361 begin_change (GtkEntry *entry)
2363 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2365 priv->change_count++;
2369 end_change (GtkEntry *entry)
2371 GtkEditable *editable = GTK_EDITABLE (entry);
2372 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2374 g_return_if_fail (priv->change_count > 0);
2376 priv->change_count--;
2378 if (priv->change_count == 0)
2380 if (priv->real_changed)
2382 g_signal_emit_by_name (editable, "changed");
2383 priv->real_changed = FALSE;
2389 emit_changed (GtkEntry *entry)
2391 GtkEditable *editable = GTK_EDITABLE (entry);
2392 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2394 if (priv->change_count == 0)
2395 g_signal_emit_by_name (editable, "changed");
2397 priv->real_changed = TRUE;
2401 gtk_entry_destroy (GtkObject *object)
2403 GtkEntry *entry = GTK_ENTRY (object);
2405 entry->current_pos = entry->selection_bound = 0;
2406 _gtk_entry_reset_im_context (entry);
2407 gtk_entry_reset_layout (entry);
2409 if (entry->blink_timeout)
2411 g_source_remove (entry->blink_timeout);
2412 entry->blink_timeout = 0;
2415 if (entry->recompute_idle)
2417 g_source_remove (entry->recompute_idle);
2418 entry->recompute_idle = 0;
2421 GTK_OBJECT_CLASS (gtk_entry_parent_class)->destroy (object);
2425 gtk_entry_dispose (GObject *object)
2427 GtkEntry *entry = GTK_ENTRY (object);
2429 gtk_entry_set_icon_from_pixbuf (entry, GTK_ENTRY_ICON_PRIMARY, NULL);
2430 gtk_entry_set_icon_tooltip_markup (entry, GTK_ENTRY_ICON_PRIMARY, NULL);
2431 gtk_entry_set_icon_from_pixbuf (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
2432 gtk_entry_set_icon_tooltip_markup (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
2434 G_OBJECT_CLASS (gtk_entry_parent_class)->dispose (object);
2438 gtk_entry_finalize (GObject *object)
2440 GtkEntry *entry = GTK_ENTRY (object);
2441 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2442 EntryIconInfo *icon_info = NULL;
2445 for (i = 0; i < MAX_ICONS; i++)
2447 if ((icon_info = priv->icons[i]) != NULL)
2449 if (icon_info->target_list != NULL)
2451 gtk_target_list_unref (icon_info->target_list);
2452 icon_info->target_list = NULL;
2455 g_slice_free (EntryIconInfo, icon_info);
2456 priv->icons[i] = NULL;
2460 gtk_entry_set_completion (entry, NULL);
2462 if (entry->cached_layout)
2463 g_object_unref (entry->cached_layout);
2465 g_object_unref (entry->im_context);
2467 if (entry->blink_timeout)
2468 g_source_remove (entry->blink_timeout);
2470 if (entry->recompute_idle)
2471 g_source_remove (entry->recompute_idle);
2473 g_free (priv->im_module);
2475 /* COMPAT: entry->text is a deprecated field, and the allocation
2476 is owned by the buffer. */
2478 gtk_entry_set_buffer (entry, NULL);
2480 G_OBJECT_CLASS (gtk_entry_parent_class)->finalize (object);
2484 gtk_entry_get_display_mode (GtkEntry *entry)
2486 GtkEntryPrivate *priv;
2488 return DISPLAY_NORMAL;
2489 priv = GTK_ENTRY_GET_PRIVATE (entry);
2490 if (entry->invisible_char == 0 && priv->invisible_char_set)
2491 return DISPLAY_BLANK;
2492 return DISPLAY_INVISIBLE;
2496 gtk_entry_get_display_text (GtkEntry *entry,
2500 GtkEntryPasswordHint *password_hint;
2501 GtkEntryPrivate *priv;
2502 gunichar invisible_char;
2512 priv = GTK_ENTRY_GET_PRIVATE (entry);
2513 text = gtk_entry_buffer_get_text (get_buffer (entry));
2514 length = gtk_entry_buffer_get_length (get_buffer (entry));
2518 if (start_pos > length)
2521 if (end_pos <= start_pos)
2522 return g_strdup ("");
2523 else if (entry->visible)
2525 start = g_utf8_offset_to_pointer (text, start_pos);
2526 end = g_utf8_offset_to_pointer (start, end_pos - start_pos);
2527 return g_strndup (start, end - start);
2531 str = g_string_sized_new (length * 2);
2533 /* Figure out what our invisible char is and encode it */
2534 if (!entry->invisible_char)
2535 invisible_char = priv->invisible_char_set ? ' ' : '*';
2537 invisible_char = entry->invisible_char;
2538 char_len = g_unichar_to_utf8 (invisible_char, char_str);
2541 * Add hidden characters for each character in the text
2542 * buffer. If there is a password hint, then keep that
2543 * character visible.
2546 password_hint = g_object_get_qdata (G_OBJECT (entry), quark_password_hint);
2547 for (i = start_pos; i < end_pos; ++i)
2549 if (password_hint && i == password_hint->position)
2551 start = g_utf8_offset_to_pointer (text, i);
2552 g_string_append_len (str, start, g_utf8_next_char (start) - start);
2556 g_string_append_len (str, char_str, char_len);
2560 return g_string_free (str, FALSE);
2566 update_cursors (GtkWidget *widget)
2568 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2569 EntryIconInfo *icon_info = NULL;
2570 GdkDisplay *display;
2574 for (i = 0; i < MAX_ICONS; i++)
2576 if ((icon_info = priv->icons[i]) != NULL)
2578 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
2579 gdk_window_show_unraised (icon_info->window);
2581 /* The icon windows are not children of the visible entry window,
2582 * thus we can't just inherit the xterm cursor. Slight complication
2583 * here is that for the entry, insensitive => arrow cursor, but for
2584 * an icon in a sensitive entry, insensitive => xterm cursor.
2586 if (GTK_WIDGET_IS_SENSITIVE (widget) &&
2587 (icon_info->insensitive ||
2588 (icon_info->nonactivatable && icon_info->target_list == NULL)))
2590 display = gtk_widget_get_display (widget);
2591 cursor = gdk_cursor_new_for_display (display, GDK_XTERM);
2592 gdk_window_set_cursor (icon_info->window, cursor);
2593 gdk_cursor_unref (cursor);
2597 gdk_window_set_cursor (icon_info->window, NULL);
2604 realize_icon_info (GtkWidget *widget,
2605 GtkEntryIconPosition icon_pos)
2607 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2608 EntryIconInfo *icon_info = priv->icons[icon_pos];
2609 GdkWindowAttr attributes;
2610 gint attributes_mask;
2612 g_return_if_fail (icon_info != NULL);
2616 attributes.width = 1;
2617 attributes.height = 1;
2618 attributes.window_type = GDK_WINDOW_CHILD;
2619 attributes.wclass = GDK_INPUT_OUTPUT;
2620 attributes.visual = gtk_widget_get_visual (widget);
2621 attributes.colormap = gtk_widget_get_colormap (widget);
2622 attributes.event_mask = gtk_widget_get_events (widget);
2623 attributes.event_mask |= (GDK_EXPOSURE_MASK |
2624 GDK_BUTTON_PRESS_MASK |
2625 GDK_BUTTON_RELEASE_MASK |
2626 GDK_BUTTON1_MOTION_MASK |
2627 GDK_BUTTON3_MOTION_MASK |
2628 GDK_POINTER_MOTION_HINT_MASK |
2629 GDK_POINTER_MOTION_MASK |
2630 GDK_ENTER_NOTIFY_MASK |
2631 GDK_LEAVE_NOTIFY_MASK);
2632 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
2634 icon_info->window = gdk_window_new (widget->window,
2637 gdk_window_set_user_data (icon_info->window, widget);
2638 gdk_window_set_background (icon_info->window,
2639 &widget->style->base[GTK_WIDGET_STATE (widget)]);
2641 gtk_widget_queue_resize (widget);
2644 static EntryIconInfo*
2645 construct_icon_info (GtkWidget *widget,
2646 GtkEntryIconPosition icon_pos)
2648 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2649 EntryIconInfo *icon_info;
2651 g_return_val_if_fail (priv->icons[icon_pos] == NULL, NULL);
2653 icon_info = g_slice_new0 (EntryIconInfo);
2654 priv->icons[icon_pos] = icon_info;
2656 if (GTK_WIDGET_REALIZED (widget))
2657 realize_icon_info (widget, icon_pos);
2663 gtk_entry_map (GtkWidget *widget)
2665 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2666 EntryIconInfo *icon_info = NULL;
2669 if (GTK_WIDGET_REALIZED (widget) && !GTK_WIDGET_MAPPED (widget))
2671 GTK_WIDGET_CLASS (gtk_entry_parent_class)->map (widget);
2673 for (i = 0; i < MAX_ICONS; i++)
2675 if ((icon_info = priv->icons[i]) != NULL)
2677 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
2678 gdk_window_show (icon_info->window);
2682 update_cursors (widget);
2687 gtk_entry_unmap (GtkWidget *widget)
2689 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2690 EntryIconInfo *icon_info = NULL;
2693 if (GTK_WIDGET_MAPPED (widget))
2695 for (i = 0; i < MAX_ICONS; i++)
2697 if ((icon_info = priv->icons[i]) != NULL)
2699 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
2700 gdk_window_hide (icon_info->window);
2704 GTK_WIDGET_CLASS (gtk_entry_parent_class)->unmap (widget);
2709 gtk_entry_realize (GtkWidget *widget)
2712 GtkEntryPrivate *priv;
2713 EntryIconInfo *icon_info;
2714 GdkWindowAttr attributes;
2715 gint attributes_mask;
2718 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
2719 entry = GTK_ENTRY (widget);
2720 priv = GTK_ENTRY_GET_PRIVATE (entry);
2722 attributes.window_type = GDK_WINDOW_CHILD;
2724 get_widget_window_size (entry, &attributes.x, &attributes.y, &attributes.width, &attributes.height);
2726 attributes.wclass = GDK_INPUT_OUTPUT;
2727 attributes.visual = gtk_widget_get_visual (widget);
2728 attributes.colormap = gtk_widget_get_colormap (widget);
2729 attributes.event_mask = gtk_widget_get_events (widget);
2730 attributes.event_mask |= (GDK_EXPOSURE_MASK |
2731 GDK_BUTTON_PRESS_MASK |
2732 GDK_BUTTON_RELEASE_MASK |
2733 GDK_BUTTON1_MOTION_MASK |
2734 GDK_BUTTON3_MOTION_MASK |
2735 GDK_POINTER_MOTION_HINT_MASK |
2736 GDK_POINTER_MOTION_MASK |
2737 GDK_ENTER_NOTIFY_MASK |
2738 GDK_LEAVE_NOTIFY_MASK);
2739 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
2741 widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, attributes_mask);
2742 gdk_window_set_user_data (widget->window, entry);
2744 get_text_area_size (entry, &attributes.x, &attributes.y, &attributes.width, &attributes.height);
2746 if (GTK_WIDGET_IS_SENSITIVE (widget))
2748 attributes.cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
2749 attributes_mask |= GDK_WA_CURSOR;
2752 entry->text_area = gdk_window_new (widget->window, &attributes, attributes_mask);
2754 gdk_window_set_user_data (entry->text_area, entry);
2756 if (attributes_mask & GDK_WA_CURSOR)
2757 gdk_cursor_unref (attributes.cursor);
2759 widget->style = gtk_style_attach (widget->style, widget->window);
2761 gdk_window_set_background (widget->window, &widget->style->base[GTK_WIDGET_STATE (widget)]);
2762 gdk_window_set_background (entry->text_area, &widget->style->base[GTK_WIDGET_STATE (widget)]);
2764 gdk_window_show (entry->text_area);
2766 gtk_im_context_set_client_window (entry->im_context, entry->text_area);
2768 gtk_entry_adjust_scroll (entry);
2769 gtk_entry_update_primary_selection (entry);
2772 /* If the icon positions are already setup, create their windows.
2773 * Otherwise if they don't exist yet, then construct_icon_info()
2774 * will create the windows once the widget is already realized.
2776 for (i = 0; i < MAX_ICONS; i++)
2778 if ((icon_info = priv->icons[i]) != NULL)
2780 if (icon_info->window == NULL)
2781 realize_icon_info (widget, i);
2787 gtk_entry_unrealize (GtkWidget *widget)
2789 GtkEntry *entry = GTK_ENTRY (widget);
2790 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2791 GtkClipboard *clipboard;
2792 EntryIconInfo *icon_info;
2795 gtk_entry_reset_layout (entry);
2797 gtk_im_context_set_client_window (entry->im_context, NULL);
2799 clipboard = gtk_widget_get_clipboard (widget, GDK_SELECTION_PRIMARY);
2800 if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (entry))
2801 gtk_clipboard_clear (clipboard);
2803 if (entry->text_area)
2805 gdk_window_set_user_data (entry->text_area, NULL);
2806 gdk_window_destroy (entry->text_area);
2807 entry->text_area = NULL;
2810 if (entry->popup_menu)
2812 gtk_widget_destroy (entry->popup_menu);
2813 entry->popup_menu = NULL;
2816 GTK_WIDGET_CLASS (gtk_entry_parent_class)->unrealize (widget);
2818 for (i = 0; i < MAX_ICONS; i++)
2820 if ((icon_info = priv->icons[i]) != NULL)
2822 if (icon_info->window != NULL)
2824 gdk_window_destroy (icon_info->window);
2825 icon_info->window = NULL;
2832 _gtk_entry_get_borders (GtkEntry *entry,
2836 GtkWidget *widget = GTK_WIDGET (entry);
2837 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2839 if (entry->has_frame)
2841 *xborder = widget->style->xthickness;
2842 *yborder = widget->style->ythickness;
2850 if (!priv->interior_focus)
2852 *xborder += priv->focus_width;
2853 *yborder += priv->focus_width;
2858 gtk_entry_size_request (GtkWidget *widget,
2859 GtkRequisition *requisition)
2861 GtkEntry *entry = GTK_ENTRY (widget);
2862 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2863 PangoFontMetrics *metrics;
2864 gint xborder, yborder;
2865 GtkBorder inner_border;
2866 PangoContext *context;
2867 int icon_widths = 0;
2870 gtk_widget_ensure_style (widget);
2871 context = gtk_widget_get_pango_context (widget);
2872 metrics = pango_context_get_metrics (context,
2873 widget->style->font_desc,
2874 pango_context_get_language (context));
2876 entry->ascent = pango_font_metrics_get_ascent (metrics);
2877 entry->descent = pango_font_metrics_get_descent (metrics);
2879 _gtk_entry_get_borders (entry, &xborder, &yborder);
2880 _gtk_entry_effective_inner_border (entry, &inner_border);
2882 if (entry->width_chars < 0)
2883 requisition->width = MIN_ENTRY_WIDTH + xborder * 2 + inner_border.left + inner_border.right;
2886 gint char_width = pango_font_metrics_get_approximate_char_width (metrics);
2887 gint digit_width = pango_font_metrics_get_approximate_digit_width (metrics);
2888 gint char_pixels = (MAX (char_width, digit_width) + PANGO_SCALE - 1) / PANGO_SCALE;
2890 requisition->width = char_pixels * entry->width_chars + xborder * 2 + inner_border.left + inner_border.right;
2893 requisition->height = PANGO_PIXELS (entry->ascent + entry->descent) + yborder * 2 + inner_border.top + inner_border.bottom;
2895 for (i = 0; i < MAX_ICONS; i++)
2897 icon_width = get_icon_width (entry, i);
2899 icon_widths += icon_width + 2 * priv->icon_margin;
2902 if (icon_widths > requisition->width)
2903 requisition->width += icon_widths;
2905 pango_font_metrics_unref (metrics);
2909 place_windows (GtkEntry *entry)
2911 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2912 gint x, y, width, height;
2913 GtkAllocation primary;
2914 GtkAllocation secondary;
2915 EntryIconInfo *icon_info = NULL;
2917 get_text_area_size (entry, &x, &y, &width, &height);
2918 get_icon_allocations (entry, &primary, &secondary);
2920 if (GTK_WIDGET_HAS_FOCUS (entry) && !priv->interior_focus)
2921 y += priv->focus_width;
2923 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
2924 x += secondary.width;
2927 width -= primary.width + secondary.width;
2929 if ((icon_info = priv->icons[GTK_ENTRY_ICON_PRIMARY]) != NULL)
2930 gdk_window_move_resize (icon_info->window,
2931 primary.x, primary.y,
2932 primary.width, primary.height);
2934 if ((icon_info = priv->icons[GTK_ENTRY_ICON_SECONDARY]) != NULL)
2935 gdk_window_move_resize (icon_info->window,
2936 secondary.x, secondary.y,
2937 secondary.width, secondary.height);
2939 gdk_window_move_resize (GTK_ENTRY (entry)->text_area, x, y, width, height);
2943 gtk_entry_get_text_area_size (GtkEntry *entry,
2949 GtkWidget *widget = GTK_WIDGET (entry);
2950 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2952 gint xborder, yborder;
2953 GtkRequisition requisition;
2955 gtk_widget_get_child_requisition (widget, &requisition);
2956 _gtk_entry_get_borders (entry, &xborder, &yborder);
2958 if (GTK_WIDGET_REALIZED (widget))
2959 gdk_drawable_get_size (widget->window, NULL, &frame_height);
2961 frame_height = requisition.height;
2963 if (GTK_WIDGET_HAS_FOCUS (widget) && !priv->interior_focus)
2964 frame_height -= 2 * priv->focus_width;
2970 *y = frame_height / 2 - (requisition.height - yborder * 2) / 2;
2973 *width = GTK_WIDGET (entry)->allocation.width - xborder * 2;
2976 *height = requisition.height - yborder * 2;
2980 get_text_area_size (GtkEntry *entry,
2986 GtkEntryClass *class;
2988 g_return_if_fail (GTK_IS_ENTRY (entry));
2990 class = GTK_ENTRY_GET_CLASS (entry);
2992 if (class->get_text_area_size)
2993 class->get_text_area_size (entry, x, y, width, height);
2998 get_widget_window_size (GtkEntry *entry,
3004 GtkRequisition requisition;
3005 GtkWidget *widget = GTK_WIDGET (entry);
3007 gtk_widget_get_child_requisition (widget, &requisition);
3010 *x = widget->allocation.x;
3014 if (entry->is_cell_renderer)
3015 *y = widget->allocation.y;
3017 *y = widget->allocation.y + (widget->allocation.height - requisition.height) / 2;
3021 *width = widget->allocation.width;
3025 if (entry->is_cell_renderer)
3026 *height = widget->allocation.height;
3028 *height = requisition.height;
3033 _gtk_entry_effective_inner_border (GtkEntry *entry,
3036 GtkBorder *tmp_border;
3038 tmp_border = g_object_get_qdata (G_OBJECT (entry), quark_inner_border);
3042 *border = *tmp_border;
3046 gtk_widget_style_get (GTK_WIDGET (entry), "inner-border", &tmp_border, NULL);
3050 *border = *tmp_border;
3051 gtk_border_free (tmp_border);
3055 *border = default_inner_border;
3059 gtk_entry_size_allocate (GtkWidget *widget,
3060 GtkAllocation *allocation)
3062 GtkEntry *entry = GTK_ENTRY (widget);
3064 widget->allocation = *allocation;
3066 if (GTK_WIDGET_REALIZED (widget))
3068 /* We call gtk_widget_get_child_requisition, since we want (for
3069 * backwards compatibility reasons) the realization here to
3070 * be affected by the usize of the entry, if set
3072 gint x, y, width, height;
3073 GtkEntryCompletion* completion;
3075 get_widget_window_size (entry, &x, &y, &width, &height);
3076 gdk_window_move_resize (widget->window, x, y, width, height);
3078 place_windows (entry);
3079 gtk_entry_recompute (entry);
3081 completion = gtk_entry_get_completion (entry);
3082 if (completion && GTK_WIDGET_MAPPED (completion->priv->popup_window))
3083 _gtk_entry_completion_resize_popup (completion);
3087 /* Kudos to the gnome-panel guys. */
3089 colorshift_pixbuf (GdkPixbuf *dest,
3094 gint width, height, has_alpha, src_rowstride, dest_rowstride;
3095 guchar *target_pixels;
3096 guchar *original_pixels;
3102 has_alpha = gdk_pixbuf_get_has_alpha (src);
3103 width = gdk_pixbuf_get_width (src);
3104 height = gdk_pixbuf_get_height (src);
3105 src_rowstride = gdk_pixbuf_get_rowstride (src);
3106 dest_rowstride = gdk_pixbuf_get_rowstride (dest);
3107 original_pixels = gdk_pixbuf_get_pixels (src);
3108 target_pixels = gdk_pixbuf_get_pixels (dest);
3110 for (i = 0; i < height; i++)
3112 pix_dest = target_pixels + i * dest_rowstride;
3113 pix_src = original_pixels + i * src_rowstride;
3115 for (j = 0; j < width; j++)
3122 *(pix_dest++) = CLAMP (val, 0, 255);
3125 *(pix_dest++) = CLAMP (val, 0, 255);
3128 *(pix_dest++) = CLAMP (val, 0, 255);
3131 *(pix_dest++) = *(pix_src++);
3137 should_prelight (GtkEntry *entry,
3138 GtkEntryIconPosition icon_pos)
3140 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3141 EntryIconInfo *icon_info = priv->icons[icon_pos];
3147 if (icon_info->nonactivatable && icon_info->target_list == NULL)
3150 if (icon_info->pressed)
3153 gtk_widget_style_get (GTK_WIDGET (entry),
3154 "icon-prelight", &prelight,
3161 draw_icon (GtkWidget *widget,
3162 GtkEntryIconPosition icon_pos)
3164 GtkEntry *entry = GTK_ENTRY (widget);
3165 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3166 EntryIconInfo *icon_info = priv->icons[icon_pos];
3168 gint x, y, width, height;
3173 gtk_entry_ensure_pixbuf (entry, icon_pos);
3175 if (icon_info->pixbuf == NULL)
3178 gdk_drawable_get_size (icon_info->window, &width, &height);
3180 /* size_allocate hasn't been called yet. These are the default values.
3182 if (width == 1 || height == 1)
3185 pixbuf = icon_info->pixbuf;
3186 g_object_ref (pixbuf);
3188 if (gdk_pixbuf_get_height (pixbuf) > height)
3190 GdkPixbuf *temp_pixbuf;
3193 scale = height - 2 * priv->icon_margin;
3194 temp_pixbuf = gdk_pixbuf_scale_simple (pixbuf, scale, scale,
3195 GDK_INTERP_BILINEAR);
3196 g_object_unref (pixbuf);
3197 pixbuf = temp_pixbuf;
3200 x = (width - gdk_pixbuf_get_width (pixbuf)) / 2;
3201 y = (height - gdk_pixbuf_get_height (pixbuf)) / 2;
3203 if (!GTK_WIDGET_IS_SENSITIVE (widget) ||
3204 icon_info->insensitive)
3206 GdkPixbuf *temp_pixbuf;
3208 temp_pixbuf = gdk_pixbuf_copy (pixbuf);
3209 gdk_pixbuf_saturate_and_pixelate (pixbuf,
3213 g_object_unref (pixbuf);
3214 pixbuf = temp_pixbuf;
3216 else if (icon_info->prelight)
3218 GdkPixbuf *temp_pixbuf;
3220 temp_pixbuf = gdk_pixbuf_copy (pixbuf);
3221 colorshift_pixbuf (temp_pixbuf, pixbuf, 30);
3222 g_object_unref (pixbuf);
3223 pixbuf = temp_pixbuf;
3226 gdk_draw_pixbuf (icon_info->window, widget->style->black_gc, pixbuf,
3228 GDK_RGB_DITHER_NORMAL, 0, 0);
3230 g_object_unref (pixbuf);
3235 gtk_entry_draw_frame (GtkWidget *widget,
3236 GdkEventExpose *event)
3238 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
3239 gint x = 0, y = 0, width, height;
3240 gboolean state_hint;
3243 gdk_drawable_get_size (widget->window, &width, &height);
3245 /* Fix a problem with some themes which assume that entry->text_area's
3246 * width equals widget->window's width */
3247 if (GTK_IS_SPIN_BUTTON (widget))
3249 gint xborder, yborder;
3251 gtk_entry_get_text_area_size (GTK_ENTRY (widget), &x, NULL, &width, NULL);
3252 _gtk_entry_get_borders (GTK_ENTRY (widget), &xborder, &yborder);
3255 width += xborder * 2;
3258 if (GTK_WIDGET_HAS_FOCUS (widget) && !priv->interior_focus)
3260 x += priv->focus_width;
3261 y += priv->focus_width;
3262 width -= 2 * priv->focus_width;
3263 height -= 2 * priv->focus_width;
3266 gtk_widget_style_get (widget, "state-hint", &state_hint, NULL);
3268 state = GTK_WIDGET_HAS_FOCUS (widget) ?
3269 GTK_STATE_ACTIVE : GTK_WIDGET_STATE (widget);
3271 state = GTK_STATE_NORMAL;
3273 gtk_paint_shadow (widget->style, widget->window,
3274 state, priv->shadow_type,
3275 &event->area, widget, "entry", x, y, width, height);
3278 gtk_entry_draw_progress (widget, event);
3280 if (GTK_WIDGET_HAS_FOCUS (widget) && !priv->interior_focus)
3282 x -= priv->focus_width;
3283 y -= priv->focus_width;
3284 width += 2 * priv->focus_width;
3285 height += 2 * priv->focus_width;
3287 gtk_paint_focus (widget->style, widget->window, GTK_WIDGET_STATE (widget),
3288 &event->area, widget, "entry",
3289 0, 0, width, height);
3294 gtk_entry_get_progress_border (GtkWidget *widget,
3295 GtkBorder *progress_border)
3297 GtkBorder *tmp_border;
3299 gtk_widget_style_get (widget, "progress-border", &tmp_border, NULL);
3302 *progress_border = *tmp_border;
3303 gtk_border_free (tmp_border);
3307 progress_border->left = widget->style->xthickness;
3308 progress_border->right = widget->style->xthickness;
3309 progress_border->top = widget->style->ythickness;
3310 progress_border->bottom = widget->style->ythickness;
3315 get_progress_area (GtkWidget *widget,
3321 GtkEntryPrivate *private = GTK_ENTRY_GET_PRIVATE (widget);
3322 GtkEntry *entry = GTK_ENTRY (widget);
3323 GtkBorder progress_border;
3325 gtk_entry_get_progress_border (widget, &progress_border);
3327 *x = progress_border.left;
3328 *y = progress_border.top;
3330 gdk_drawable_get_size (widget->window, width, height);
3332 *width -= progress_border.left + progress_border.right;
3333 *height -= progress_border.top + progress_border.bottom;
3335 if (GTK_WIDGET_HAS_FOCUS (widget) && !private->interior_focus)
3337 *x += private->focus_width;
3338 *y += private->focus_width;
3339 *width -= 2 * private->focus_width;
3340 *height -= 2 * private->focus_width;
3343 if (private->progress_pulse_mode)
3345 gdouble value = private->progress_pulse_current;
3347 *x += (gint) floor(value * (*width));
3348 *width = (gint) ceil(private->progress_pulse_fraction * (*width));
3350 else if (private->progress_fraction > 0)
3352 gdouble value = private->progress_fraction;
3354 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
3358 bar_width = floor(value * (*width) + 0.5);
3359 *x += *width - bar_width;
3364 *width = (gint) floor(value * (*width) + 0.5);
3375 gtk_entry_draw_progress (GtkWidget *widget,
3376 GdkEventExpose *event)
3378 gint x, y, width, height;
3381 get_progress_area (widget, &x, &y, &width, &height);
3383 if ((width <= 0) || (height <= 0))
3386 if (event->window != widget->window)
3390 gdk_window_get_position (event->window, &pos_x, &pos_y);
3396 state = GTK_STATE_SELECTED;
3397 if (!GTK_WIDGET_SENSITIVE (widget))
3398 state = GTK_STATE_INSENSITIVE;
3400 gtk_paint_box (widget->style, event->window,
3401 state, GTK_SHADOW_OUT,
3402 &event->area, widget, "entry-progress",
3408 gtk_entry_expose (GtkWidget *widget,
3409 GdkEventExpose *event)
3411 GtkEntry *entry = GTK_ENTRY (widget);
3412 gboolean state_hint;
3414 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3416 gtk_widget_style_get (widget, "state-hint", &state_hint, NULL);
3418 state = GTK_WIDGET_HAS_FOCUS (widget) ?
3419 GTK_STATE_ACTIVE : GTK_WIDGET_STATE (widget);
3421 state = GTK_WIDGET_STATE(widget);
3423 if (widget->window == event->window)
3425 gtk_entry_draw_frame (widget, event);
3427 else if (entry->text_area == event->window)
3431 gdk_drawable_get_size (entry->text_area, &width, &height);
3433 gtk_paint_flat_box (widget->style, entry->text_area,
3434 state, GTK_SHADOW_NONE,
3435 &event->area, widget, "entry_bg",
3436 0, 0, width, height);
3438 gtk_entry_draw_progress (widget, event);
3440 if (entry->dnd_position != -1)
3441 gtk_entry_draw_cursor (GTK_ENTRY (widget), CURSOR_DND);
3443 gtk_entry_draw_text (GTK_ENTRY (widget));
3445 /* When no text is being displayed at all, don't show the cursor */
3446 if (gtk_entry_get_display_mode (entry) != DISPLAY_BLANK &&
3447 GTK_WIDGET_HAS_FOCUS (widget) &&
3448 entry->selection_bound == entry->current_pos && entry->cursor_visible)
3449 gtk_entry_draw_cursor (GTK_ENTRY (widget), CURSOR_STANDARD);
3455 for (i = 0; i < MAX_ICONS; i++)
3457 EntryIconInfo *icon_info = priv->icons[i];
3459 if (icon_info != NULL && event->window == icon_info->window)
3463 gdk_drawable_get_size (icon_info->window, &width, &height);
3465 gtk_paint_flat_box (widget->style, icon_info->window,
3466 GTK_WIDGET_STATE (widget), GTK_SHADOW_NONE,
3467 NULL, widget, "entry_bg",
3468 0, 0, width, height);
3470 gtk_entry_draw_progress (widget, event);
3471 draw_icon (widget, i);
3482 gtk_entry_enter_notify (GtkWidget *widget,
3483 GdkEventCrossing *event)
3485 GtkEntry *entry = GTK_ENTRY (widget);
3486 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3489 for (i = 0; i < MAX_ICONS; i++)
3491 EntryIconInfo *icon_info = priv->icons[i];
3493 if (icon_info != NULL && event->window == icon_info->window)
3495 if (should_prelight (entry, i))
3497 icon_info->prelight = TRUE;
3498 gtk_widget_queue_draw (widget);
3509 gtk_entry_leave_notify (GtkWidget *widget,
3510 GdkEventCrossing *event)
3512 GtkEntry *entry = GTK_ENTRY (widget);
3513 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3516 for (i = 0; i < MAX_ICONS; i++)
3518 EntryIconInfo *icon_info = priv->icons[i];
3520 if (icon_info != NULL && event->window == icon_info->window)
3522 /* a grab means that we may never see the button release */
3523 if (event->mode == GDK_CROSSING_GRAB || event->mode == GDK_CROSSING_GTK_GRAB)
3524 icon_info->pressed = FALSE;
3526 if (should_prelight (entry, i))
3528 icon_info->prelight = FALSE;
3529 gtk_widget_queue_draw (widget);
3540 gtk_entry_get_pixel_ranges (GtkEntry *entry,
3544 gint start_char, end_char;
3546 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start_char, &end_char))
3548 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
3549 PangoLayoutLine *line = pango_layout_get_lines_readonly (layout)->data;
3550 const char *text = pango_layout_get_text (layout);
3551 gint start_index = g_utf8_offset_to_pointer (text, start_char) - text;
3552 gint end_index = g_utf8_offset_to_pointer (text, end_char) - text;
3553 gint real_n_ranges, i;
3555 pango_layout_line_get_x_ranges (line, start_index, end_index, ranges, &real_n_ranges);
3561 for (i = 0; i < real_n_ranges; ++i)
3563 r[2 * i + 1] = (r[2 * i + 1] - r[2 * i]) / PANGO_SCALE;
3564 r[2 * i] = r[2 * i] / PANGO_SCALE;
3569 *n_ranges = real_n_ranges;
3581 in_selection (GtkEntry *entry,
3586 gint retval = FALSE;
3588 gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
3590 for (i = 0; i < n_ranges; ++i)
3592 if (x >= ranges[2 * i] && x < ranges[2 * i] + ranges[2 * i + 1])
3604 gtk_entry_button_press (GtkWidget *widget,
3605 GdkEventButton *event)
3607 GtkEntry *entry = GTK_ENTRY (widget);
3608 GtkEditable *editable = GTK_EDITABLE (widget);
3609 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3610 EntryIconInfo *icon_info = NULL;
3612 gint sel_start, sel_end;
3615 for (i = 0; i < MAX_ICONS; i++)
3617 icon_info = priv->icons[i];
3619 if (!icon_info || icon_info->insensitive)
3622 if (event->window == icon_info->window)
3624 if (should_prelight (entry, i))
3626 icon_info->prelight = FALSE;
3627 gtk_widget_queue_draw (widget);
3630 priv->start_x = event->x;
3631 priv->start_y = event->y;
3632 icon_info->pressed = TRUE;
3634 if (!icon_info->nonactivatable)
3635 g_signal_emit (entry, signals[ICON_PRESS], 0, i, event);
3641 if (event->window != entry->text_area ||
3642 (entry->button && event->button != entry->button))
3645 gtk_entry_reset_blink_time (entry);
3647 entry->button = event->button;
3649 if (!GTK_WIDGET_HAS_FOCUS (widget))
3651 entry->in_click = TRUE;
3652 gtk_widget_grab_focus (widget);
3653 entry->in_click = FALSE;
3656 tmp_pos = gtk_entry_find_position (entry, event->x + entry->scroll_offset);
3658 if (event->button == 1)
3660 gboolean have_selection = gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end);
3662 entry->select_words = FALSE;
3663 entry->select_lines = FALSE;
3665 if (event->state & GDK_SHIFT_MASK)
3667 _gtk_entry_reset_im_context (entry);
3669 if (!have_selection) /* select from the current position to the clicked position */
3670 sel_start = sel_end = entry->current_pos;
3672 if (tmp_pos > sel_start && tmp_pos < sel_end)
3674 /* Truncate current selection, but keep it as big as possible */
3675 if (tmp_pos - sel_start > sel_end - tmp_pos)
3676 gtk_entry_set_positions (entry, sel_start, tmp_pos);
3678 gtk_entry_set_positions (entry, tmp_pos, sel_end);
3682 gboolean extend_to_left;
3685 /* Figure out what click selects and extend current selection */
3686 switch (event->type)
3688 case GDK_BUTTON_PRESS:
3689 gtk_entry_set_positions (entry, tmp_pos, tmp_pos);
3692 case GDK_2BUTTON_PRESS:
3693 entry->select_words = TRUE;
3694 gtk_entry_select_word (entry);
3697 case GDK_3BUTTON_PRESS:
3698 entry->select_lines = TRUE;
3699 gtk_entry_select_line (entry);
3706 start = MIN (entry->current_pos, entry->selection_bound);
3707 start = MIN (sel_start, start);
3709 end = MAX (entry->current_pos, entry->selection_bound);
3710 end = MAX (sel_end, end);
3712 if (tmp_pos == sel_start || tmp_pos == sel_end)
3713 extend_to_left = (tmp_pos == start);
3715 extend_to_left = (end == sel_end);
3718 gtk_entry_set_positions (entry, start, end);
3720 gtk_entry_set_positions (entry, end, start);
3723 else /* no shift key */
3724 switch (event->type)
3726 case GDK_BUTTON_PRESS:
3727 if (in_selection (entry, event->x + entry->scroll_offset))
3729 /* Click inside the selection - we'll either start a drag, or
3730 * clear the selection
3732 entry->in_drag = TRUE;
3733 entry->drag_start_x = event->x + entry->scroll_offset;
3734 entry->drag_start_y = event->y;
3737 gtk_editable_set_position (editable, tmp_pos);
3740 case GDK_2BUTTON_PRESS:
3741 /* We ALWAYS receive a GDK_BUTTON_PRESS immediately before
3742 * receiving a GDK_2BUTTON_PRESS so we need to reset
3743 * entry->in_drag which may have been set above
3745 entry->in_drag = FALSE;
3746 entry->select_words = TRUE;
3747 gtk_entry_select_word (entry);
3750 case GDK_3BUTTON_PRESS:
3751 /* We ALWAYS receive a GDK_BUTTON_PRESS immediately before
3752 * receiving a GDK_3BUTTON_PRESS so we need to reset
3753 * entry->in_drag which may have been set above
3755 entry->in_drag = FALSE;
3756 entry->select_lines = TRUE;
3757 gtk_entry_select_line (entry);
3766 else if (event->button == 2 && event->type == GDK_BUTTON_PRESS)
3768 if (entry->editable)
3770 priv->insert_pos = tmp_pos;
3771 gtk_entry_paste (entry, GDK_SELECTION_PRIMARY);
3776 gtk_widget_error_bell (widget);
3779 else if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
3781 gtk_entry_do_popup (entry, event);
3782 entry->button = 0; /* Don't wait for release, since the menu will gtk_grab_add */
3791 gtk_entry_button_release (GtkWidget *widget,
3792 GdkEventButton *event)
3794 GtkEntry *entry = GTK_ENTRY (widget);
3795 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
3796 EntryIconInfo *icon_info = NULL;
3799 for (i = 0; i < MAX_ICONS; i++)
3801 icon_info = priv->icons[i];
3803 if (!icon_info || icon_info->insensitive)
3806 if (event->window == icon_info->window)
3810 gdk_drawable_get_size (icon_info->window, &width, &height);
3812 icon_info->pressed = FALSE;
3814 if (should_prelight (entry, i) &&
3815 event->x >= 0 && event->y >= 0 &&
3816 event->x < width && event->y < height)
3818 icon_info->prelight = TRUE;
3819 gtk_widget_queue_draw (widget);
3822 if (!icon_info->nonactivatable)
3823 g_signal_emit (entry, signals[ICON_RELEASE], 0, i, event);
3829 if (event->window != entry->text_area || entry->button != event->button)
3834 gint tmp_pos = gtk_entry_find_position (entry, entry->drag_start_x);
3836 gtk_editable_set_position (GTK_EDITABLE (entry), tmp_pos);
3843 gtk_entry_update_primary_selection (entry);
3849 _gtk_entry_get_selected_text (GtkEntry *entry)
3851 GtkEditable *editable = GTK_EDITABLE (entry);
3852 gint start_text, end_text;
3855 if (gtk_editable_get_selection_bounds (editable, &start_text, &end_text))
3856 text = gtk_editable_get_chars (editable, start_text, end_text);
3862 gtk_entry_motion_notify (GtkWidget *widget,
3863 GdkEventMotion *event)
3865 GtkEntry *entry = GTK_ENTRY (widget);
3866 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3867 EntryIconInfo *icon_info = NULL;
3868 GdkDragContext *context;
3872 for (i = 0; i < MAX_ICONS; i++)
3874 icon_info = priv->icons[i];
3876 if (!icon_info || icon_info->insensitive)
3879 if (event->window == icon_info->window)
3881 if (icon_info->pressed &&
3882 icon_info->target_list != NULL &&
3883 gtk_drag_check_threshold (widget,
3889 icon_info->in_drag = TRUE;
3890 icon_info->pressed = FALSE;
3891 context = gtk_drag_begin (widget,
3892 icon_info->target_list,
3902 if (entry->mouse_cursor_obscured)
3906 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
3907 gdk_window_set_cursor (entry->text_area, cursor);
3908 gdk_cursor_unref (cursor);
3909 entry->mouse_cursor_obscured = FALSE;
3912 if (event->window != entry->text_area || entry->button != 1)
3915 if (entry->select_lines)
3918 gdk_event_request_motions (event);
3922 if (gtk_entry_get_display_mode (entry) == DISPLAY_NORMAL &&
3923 gtk_drag_check_threshold (widget,
3924 entry->drag_start_x, entry->drag_start_y,
3925 event->x + entry->scroll_offset, event->y))
3927 GdkDragContext *context;
3928 GtkTargetList *target_list = gtk_target_list_new (NULL, 0);
3929 guint actions = entry->editable ? GDK_ACTION_COPY | GDK_ACTION_MOVE : GDK_ACTION_COPY;
3931 GdkPixmap *pixmap = NULL;
3933 gtk_target_list_add_text_targets (target_list, 0);
3935 text = _gtk_entry_get_selected_text (entry);
3936 pixmap = _gtk_text_util_create_drag_icon (widget, text, -1);
3938 context = gtk_drag_begin (widget, target_list, actions,
3939 entry->button, (GdkEvent *)event);
3942 gtk_drag_set_icon_pixmap (context,
3943 gdk_drawable_get_colormap (pixmap),
3948 gtk_drag_set_icon_default (context);
3951 g_object_unref (pixmap);
3954 entry->in_drag = FALSE;
3957 gtk_target_list_unref (target_list);
3963 gdk_drawable_get_size (entry->text_area, NULL, &height);
3967 else if (event->y >= height)
3968 tmp_pos = gtk_entry_buffer_get_length (get_buffer (entry));
3970 tmp_pos = gtk_entry_find_position (entry, event->x + entry->scroll_offset);
3972 if (entry->select_words)
3975 gint old_min, old_max;
3978 min = gtk_entry_move_backward_word (entry, tmp_pos, TRUE);
3979 max = gtk_entry_move_forward_word (entry, tmp_pos, TRUE);
3981 pos = entry->current_pos;
3982 bound = entry->selection_bound;
3984 old_min = MIN(entry->current_pos, entry->selection_bound);
3985 old_max = MAX(entry->current_pos, entry->selection_bound);
3992 else if (old_max < max)
3997 else if (pos == old_min)
3999 if (entry->current_pos != min)
4004 if (entry->current_pos != max)
4008 gtk_entry_set_positions (entry, pos, bound);
4011 gtk_entry_set_positions (entry, tmp_pos, -1);
4018 set_invisible_cursor (GdkWindow *window)
4020 GdkDisplay *display;
4023 display = gdk_drawable_get_display (window);
4024 cursor = gdk_cursor_new_for_display (display, GDK_BLANK_CURSOR);
4026 gdk_window_set_cursor (window, cursor);
4028 gdk_cursor_unref (cursor);
4032 gtk_entry_obscure_mouse_cursor (GtkEntry *entry)
4034 if (entry->mouse_cursor_obscured)
4037 set_invisible_cursor (entry->text_area);
4039 entry->mouse_cursor_obscured = TRUE;
4043 gtk_entry_key_press (GtkWidget *widget,
4046 GtkEntry *entry = GTK_ENTRY (widget);
4048 gtk_entry_reset_blink_time (entry);
4049 gtk_entry_pend_cursor_blink (entry);
4051 if (entry->editable)
4053 if (gtk_im_context_filter_keypress (entry->im_context, event))
4055 gtk_entry_obscure_mouse_cursor (entry);
4056 entry->need_im_reset = TRUE;
4061 if (event->keyval == GDK_Return ||
4062 event->keyval == GDK_KP_Enter ||
4063 event->keyval == GDK_ISO_Enter ||
4064 event->keyval == GDK_Escape)
4066 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
4068 if (completion && completion->priv->completion_timeout)
4070 g_source_remove (completion->priv->completion_timeout);
4071 completion->priv->completion_timeout = 0;
4074 _gtk_entry_reset_im_context (entry);
4077 if (GTK_WIDGET_CLASS (gtk_entry_parent_class)->key_press_event (widget, event))
4078 /* Activate key bindings
4082 if (!entry->editable && event->length)
4083 gtk_widget_error_bell (widget);
4089 gtk_entry_key_release (GtkWidget *widget,
4092 GtkEntry *entry = GTK_ENTRY (widget);
4094 if (entry->editable)
4096 if (gtk_im_context_filter_keypress (entry->im_context, event))
4098 entry->need_im_reset = TRUE;
4103 return GTK_WIDGET_CLASS (gtk_entry_parent_class)->key_release_event (widget, event);
4107 gtk_entry_focus_in (GtkWidget *widget,
4108 GdkEventFocus *event)
4110 GtkEntry *entry = GTK_ENTRY (widget);
4113 gtk_widget_queue_draw (widget);
4115 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (widget));
4117 if (entry->editable)
4119 entry->need_im_reset = TRUE;
4120 gtk_im_context_focus_in (entry->im_context);
4121 keymap_state_changed (keymap, entry);
4122 g_signal_connect (keymap, "state-changed",
4123 G_CALLBACK (keymap_state_changed), entry);
4126 g_signal_connect (keymap, "direction-changed",
4127 G_CALLBACK (keymap_direction_changed), entry);
4129 gtk_entry_reset_blink_time (entry);
4130 gtk_entry_check_cursor_blink (entry);
4136 gtk_entry_focus_out (GtkWidget *widget,
4137 GdkEventFocus *event)
4139 GtkEntry *entry = GTK_ENTRY (widget);
4140 GtkEntryCompletion *completion;
4143 gtk_widget_queue_draw (widget);
4145 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (widget));
4147 if (entry->editable)
4149 entry->need_im_reset = TRUE;
4150 gtk_im_context_focus_out (entry->im_context);
4151 remove_capslock_feedback (entry);
4154 gtk_entry_check_cursor_blink (entry);
4156 g_signal_handlers_disconnect_by_func (keymap, keymap_state_changed, entry);
4157 g_signal_handlers_disconnect_by_func (keymap, keymap_direction_changed, entry);
4159 completion = gtk_entry_get_completion (entry);
4161 _gtk_entry_completion_popdown (completion);
4167 gtk_entry_grab_focus (GtkWidget *widget)
4169 GtkEntry *entry = GTK_ENTRY (widget);
4170 gboolean select_on_focus;
4172 GTK_WIDGET_CLASS (gtk_entry_parent_class)->grab_focus (widget);
4174 if (entry->editable && !entry->in_click)
4176 g_object_get (gtk_widget_get_settings (widget),
4177 "gtk-entry-select-on-focus",
4181 if (select_on_focus)
4182 gtk_editable_select_region (GTK_EDITABLE (widget), 0, -1);
4187 gtk_entry_direction_changed (GtkWidget *widget,
4188 GtkTextDirection previous_dir)
4190 GtkEntry *entry = GTK_ENTRY (widget);
4192 gtk_entry_recompute (entry);
4194 GTK_WIDGET_CLASS (gtk_entry_parent_class)->direction_changed (widget, previous_dir);
4198 gtk_entry_state_changed (GtkWidget *widget,
4199 GtkStateType previous_state)
4201 GtkEntry *entry = GTK_ENTRY (widget);
4202 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
4206 if (GTK_WIDGET_REALIZED (widget))
4208 gdk_window_set_background (widget->window, &widget->style->base[GTK_WIDGET_STATE (widget)]);
4209 gdk_window_set_background (entry->text_area, &widget->style->base[GTK_WIDGET_STATE (widget)]);
4210 for (i = 0; i < MAX_ICONS; i++)
4212 EntryIconInfo *icon_info = priv->icons[i];
4213 if (icon_info && icon_info->window)
4214 gdk_window_set_background (icon_info->window, &widget->style->base[GTK_WIDGET_STATE (widget)]);
4217 if (GTK_WIDGET_IS_SENSITIVE (widget))
4218 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
4222 gdk_window_set_cursor (entry->text_area, cursor);
4225 gdk_cursor_unref (cursor);
4227 entry->mouse_cursor_obscured = FALSE;
4229 update_cursors (widget);
4232 if (!GTK_WIDGET_IS_SENSITIVE (widget))
4234 /* Clear any selection */
4235 gtk_editable_select_region (GTK_EDITABLE (entry), entry->current_pos, entry->current_pos);
4238 gtk_widget_queue_draw (widget);
4242 gtk_entry_screen_changed (GtkWidget *widget,
4243 GdkScreen *old_screen)
4245 gtk_entry_recompute (GTK_ENTRY (widget));
4248 /* GtkEditable method implementations
4251 gtk_entry_insert_text (GtkEditable *editable,
4252 const gchar *new_text,
4253 gint new_text_length,
4256 g_object_ref (editable);
4259 * The incoming text may a password or other secret. We make sure
4260 * not to copy it into temporary buffers.
4263 g_signal_emit_by_name (editable, "insert-text", new_text, new_text_length, position);
4265 g_object_unref (editable);
4269 gtk_entry_delete_text (GtkEditable *editable,
4273 g_object_ref (editable);
4275 g_signal_emit_by_name (editable, "delete-text", start_pos, end_pos);
4277 g_object_unref (editable);
4281 gtk_entry_get_chars (GtkEditable *editable,
4285 GtkEntry *entry = GTK_ENTRY (editable);
4288 gint start_index, end_index;
4290 text = gtk_entry_buffer_get_text (get_buffer (entry));
4291 text_length = gtk_entry_buffer_get_length (get_buffer (entry));
4294 end_pos = text_length;
4296 start_pos = MIN (text_length, start_pos);
4297 end_pos = MIN (text_length, end_pos);
4299 start_index = g_utf8_offset_to_pointer (text, start_pos) - entry->text;
4300 end_index = g_utf8_offset_to_pointer (text, end_pos) - entry->text;
4302 return g_strndup (text + start_index, end_index - start_index);
4306 gtk_entry_real_set_position (GtkEditable *editable,
4309 GtkEntry *entry = GTK_ENTRY (editable);
4313 length = gtk_entry_buffer_get_length (get_buffer (entry));
4314 if (position < 0 || position > length)
4317 if (position != entry->current_pos ||
4318 position != entry->selection_bound)
4320 _gtk_entry_reset_im_context (entry);
4321 gtk_entry_set_positions (entry, position, position);
4326 gtk_entry_get_position (GtkEditable *editable)
4328 return GTK_ENTRY (editable)->current_pos;
4332 gtk_entry_set_selection_bounds (GtkEditable *editable,
4336 GtkEntry *entry = GTK_ENTRY (editable);
4339 length = gtk_entry_buffer_get_length (get_buffer (entry));
4345 _gtk_entry_reset_im_context (entry);
4347 gtk_entry_set_positions (entry,
4349 MIN (start, length));
4351 gtk_entry_update_primary_selection (entry);
4355 gtk_entry_get_selection_bounds (GtkEditable *editable,
4359 GtkEntry *entry = GTK_ENTRY (editable);
4361 *start = entry->selection_bound;
4362 *end = entry->current_pos;
4364 return (entry->selection_bound != entry->current_pos);
4368 icon_theme_changed (GtkEntry *entry)
4370 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
4373 for (i = 0; i < MAX_ICONS; i++)
4375 EntryIconInfo *icon_info = priv->icons[i];
4376 if (icon_info != NULL)
4378 if (icon_info->storage_type == GTK_IMAGE_ICON_NAME)
4379 gtk_entry_set_icon_from_icon_name (entry, i, icon_info->icon_name);
4380 else if (icon_info->storage_type == GTK_IMAGE_STOCK)
4381 gtk_entry_set_icon_from_stock (entry, i, icon_info->stock_id);
4382 else if (icon_info->storage_type == GTK_IMAGE_GICON)
4383 gtk_entry_set_icon_from_gicon (entry, i, icon_info->gicon);
4387 gtk_widget_queue_draw (GTK_WIDGET (entry));
4391 icon_margin_changed (GtkEntry *entry)
4393 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
4396 _gtk_entry_effective_inner_border (GTK_ENTRY (entry), &border);
4398 priv->icon_margin = border.left;
4402 gtk_entry_style_set (GtkWidget *widget,
4403 GtkStyle *previous_style)
4405 GtkEntry *entry = GTK_ENTRY (widget);
4406 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
4408 gboolean interior_focus;
4411 gtk_widget_style_get (widget,
4412 "focus-line-width", &focus_width,
4413 "interior-focus", &interior_focus,
4416 priv->focus_width = focus_width;
4417 priv->interior_focus = interior_focus;
4419 if (!priv->invisible_char_set)
4420 entry->invisible_char = find_invisible_char (GTK_WIDGET (entry));
4422 gtk_entry_recompute (entry);
4424 if (previous_style && GTK_WIDGET_REALIZED (widget))
4426 gdk_window_set_background (widget->window, &widget->style->base[GTK_WIDGET_STATE (widget)]);
4427 gdk_window_set_background (entry->text_area, &widget->style->base[GTK_WIDGET_STATE (widget)]);
4428 for (i = 0; i < MAX_ICONS; i++)
4430 EntryIconInfo *icon_info = priv->icons[i];
4431 if (icon_info && icon_info->window)
4432 gdk_window_set_background (icon_info->window, &widget->style->base[GTK_WIDGET_STATE (widget)]);
4436 icon_theme_changed (entry);
4437 icon_margin_changed (entry);
4440 /* GtkCellEditable method implementations
4443 gtk_cell_editable_entry_activated (GtkEntry *entry, gpointer data)
4445 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4446 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4450 gtk_cell_editable_key_press_event (GtkEntry *entry,
4451 GdkEventKey *key_event,
4454 if (key_event->keyval == GDK_Escape)
4456 entry->editing_canceled = TRUE;
4457 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4458 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4463 /* override focus */
4464 if (key_event->keyval == GDK_Up || key_event->keyval == GDK_Down)
4466 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4467 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4476 gtk_entry_start_editing (GtkCellEditable *cell_editable,
4479 GTK_ENTRY (cell_editable)->is_cell_renderer = TRUE;
4481 g_signal_connect (cell_editable, "activate",
4482 G_CALLBACK (gtk_cell_editable_entry_activated), NULL);
4483 g_signal_connect (cell_editable, "key-press-event",
4484 G_CALLBACK (gtk_cell_editable_key_press_event), NULL);
4488 gtk_entry_password_hint_free (GtkEntryPasswordHint *password_hint)
4490 if (password_hint->source_id)
4491 g_source_remove (password_hint->source_id);
4493 g_slice_free (GtkEntryPasswordHint, password_hint);
4498 gtk_entry_remove_password_hint (gpointer data)
4500 GtkEntryPasswordHint *password_hint = g_object_get_qdata (data, quark_password_hint);
4501 password_hint->position = -1;
4503 /* Force the string to be redrawn, but now without a visible character */
4504 gtk_entry_recompute (GTK_ENTRY (data));
4508 /* Default signal handlers
4511 gtk_entry_real_insert_text (GtkEditable *editable,
4512 const gchar *new_text,
4513 gint new_text_length,
4519 n_chars = g_utf8_strlen (new_text, new_text_length);
4522 * The actual insertion into the buffer. This will end up firing the
4523 * following signal handlers: buffer_inserted_text(), buffer_notify_display_text(),
4524 * buffer_notify_text(), buffer_notify_length()
4526 n_inserted = gtk_entry_buffer_insert_text (GTK_ENTRY_GET_PRIVATE (editable)->buffer, *position, new_text, n_chars);
4528 if (n_inserted != n_chars)
4529 gtk_widget_error_bell (GTK_WIDGET (editable));
4531 *position += n_inserted;
4535 gtk_entry_real_delete_text (GtkEditable *editable,
4540 * The actual deletion from the buffer. This will end up firing the
4541 * following signal handlers: buffer_deleted_text(), buffer_notify_display_text(),
4542 * buffer_notify_text(), buffer_notify_length()
4545 gtk_entry_buffer_delete_text (get_buffer (GTK_ENTRY (editable)), start_pos, end_pos - start_pos);
4548 /* GtkEntryBuffer signal handlers
4551 buffer_inserted_text (GtkEntryBuffer *buffer,
4557 guint password_hint_timeout;
4559 if (entry->current_pos > position)
4560 entry->current_pos += n_chars;
4562 if (entry->selection_bound > position)
4563 entry->selection_bound += n_chars;
4565 /* Calculate the password hint if it needs to be displayed. */
4566 if (n_chars == 1 && !entry->visible)
4568 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
4569 "gtk-entry-password-hint-timeout", &password_hint_timeout,
4572 if (password_hint_timeout > 0)
4574 GtkEntryPasswordHint *password_hint = g_object_get_qdata (G_OBJECT (entry),
4575 quark_password_hint);
4578 password_hint = g_slice_new0 (GtkEntryPasswordHint);
4579 g_object_set_qdata_full (G_OBJECT (entry), quark_password_hint, password_hint,
4580 (GDestroyNotify)gtk_entry_password_hint_free);
4583 password_hint->position = position;
4584 if (password_hint->source_id)
4585 g_source_remove (password_hint->source_id);
4586 password_hint->source_id = gdk_threads_add_timeout (password_hint_timeout,
4587 (GSourceFunc)gtk_entry_remove_password_hint, entry);
4593 buffer_deleted_text (GtkEntryBuffer *buffer,
4598 guint end_pos = position + n_chars;
4599 gint selection_bound;
4602 current_pos = entry->current_pos;
4603 if (current_pos > position)
4604 current_pos -= MIN (current_pos, end_pos) - position;
4606 selection_bound = entry->selection_bound;
4607 if (selection_bound > position)
4608 selection_bound -= MIN (selection_bound, end_pos) - position;
4610 gtk_entry_set_positions (entry, current_pos, selection_bound);
4612 /* We might have deleted the selection */
4613 gtk_entry_update_primary_selection (entry);
4615 /* Disable the password hint if one exists. */
4616 if (!entry->visible)
4618 GtkEntryPasswordHint *password_hint = g_object_get_qdata (G_OBJECT (entry),
4619 quark_password_hint);
4622 if (password_hint->source_id)
4623 g_source_remove (password_hint->source_id);
4624 password_hint->source_id = 0;
4625 password_hint->position = -1;
4631 buffer_notify_text (GtkEntryBuffer *buffer,
4635 /* COMPAT: Deprecated, not used. This struct field will be removed in GTK+ 3.x */
4636 entry->text = (gchar*)gtk_entry_buffer_get_text (buffer);
4638 gtk_entry_recompute (entry);
4639 emit_changed (entry);
4640 g_object_notify (G_OBJECT (entry), "text");
4644 buffer_notify_length (GtkEntryBuffer *buffer,
4648 /* COMPAT: Deprecated, not used. This struct field will be removed in GTK+ 3.x */
4649 entry->text_length = gtk_entry_buffer_get_length (buffer);
4651 g_object_notify (G_OBJECT (entry), "text-length");
4655 buffer_notify_max_length (GtkEntryBuffer *buffer,
4659 /* COMPAT: Deprecated, not used. This struct field will be removed in GTK+ 3.x */
4660 entry->text_max_length = gtk_entry_buffer_get_max_length (buffer);
4662 g_object_notify (G_OBJECT (entry), "max-length");
4666 buffer_connect_signals (GtkEntry *entry)
4668 g_signal_connect (get_buffer (entry), "inserted-text", G_CALLBACK (buffer_inserted_text), entry);
4669 g_signal_connect (get_buffer (entry), "deleted-text", G_CALLBACK (buffer_deleted_text), entry);
4670 g_signal_connect (get_buffer (entry), "notify::text", G_CALLBACK (buffer_notify_text), entry);
4671 g_signal_connect (get_buffer (entry), "notify::length", G_CALLBACK (buffer_notify_length), entry);
4672 g_signal_connect (get_buffer (entry), "notify::max-length", G_CALLBACK (buffer_notify_max_length), entry);
4676 buffer_disconnect_signals (GtkEntry *entry)
4678 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_inserted_text, entry);
4679 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_deleted_text, entry);
4680 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_text, entry);
4681 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_length, entry);
4682 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_max_length, entry);
4685 /* Compute the X position for an offset that corresponds to the "more important
4686 * cursor position for that offset. We use this when trying to guess to which
4687 * end of the selection we should go to when the user hits the left or
4691 get_better_cursor_x (GtkEntry *entry,
4694 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
4695 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
4696 gboolean split_cursor;
4698 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
4699 const gchar *text = pango_layout_get_text (layout);
4700 gint index = g_utf8_offset_to_pointer (text, offset) - text;
4702 PangoRectangle strong_pos, weak_pos;
4704 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
4705 "gtk-split-cursor", &split_cursor,
4708 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
4711 return strong_pos.x / PANGO_SCALE;
4713 return (keymap_direction == entry->resolved_dir) ? strong_pos.x / PANGO_SCALE : weak_pos.x / PANGO_SCALE;
4717 gtk_entry_move_cursor (GtkEntry *entry,
4718 GtkMovementStep step,
4720 gboolean extend_selection)
4722 gint new_pos = entry->current_pos;
4723 GtkEntryPrivate *priv;
4725 _gtk_entry_reset_im_context (entry);
4727 if (entry->current_pos != entry->selection_bound && !extend_selection)
4729 /* If we have a current selection and aren't extending it, move to the
4730 * start/or end of the selection as appropriate
4734 case GTK_MOVEMENT_VISUAL_POSITIONS:
4736 gint current_x = get_better_cursor_x (entry, entry->current_pos);
4737 gint bound_x = get_better_cursor_x (entry, entry->selection_bound);
4740 new_pos = current_x < bound_x ? entry->current_pos : entry->selection_bound;
4742 new_pos = current_x > bound_x ? entry->current_pos : entry->selection_bound;
4745 case GTK_MOVEMENT_LOGICAL_POSITIONS:
4746 case GTK_MOVEMENT_WORDS:
4748 new_pos = MIN (entry->current_pos, entry->selection_bound);
4750 new_pos = MAX (entry->current_pos, entry->selection_bound);
4752 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
4753 case GTK_MOVEMENT_PARAGRAPH_ENDS:
4754 case GTK_MOVEMENT_BUFFER_ENDS:
4755 priv = GTK_ENTRY_GET_PRIVATE (entry);
4756 new_pos = count < 0 ? 0 : gtk_entry_buffer_get_length (get_buffer (entry));
4758 case GTK_MOVEMENT_DISPLAY_LINES:
4759 case GTK_MOVEMENT_PARAGRAPHS:
4760 case GTK_MOVEMENT_PAGES:
4761 case GTK_MOVEMENT_HORIZONTAL_PAGES:
4769 case GTK_MOVEMENT_LOGICAL_POSITIONS:
4770 new_pos = gtk_entry_move_logically (entry, new_pos, count);
4772 case GTK_MOVEMENT_VISUAL_POSITIONS:
4773 new_pos = gtk_entry_move_visually (entry, new_pos, count);
4774 if (entry->current_pos == new_pos)
4776 if (!extend_selection)
4778 if (!gtk_widget_keynav_failed (GTK_WIDGET (entry),
4780 GTK_DIR_RIGHT : GTK_DIR_LEFT))
4782 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (entry));
4785 gtk_widget_child_focus (toplevel,
4787 GTK_DIR_RIGHT : GTK_DIR_LEFT);
4792 gtk_widget_error_bell (GTK_WIDGET (entry));
4796 case GTK_MOVEMENT_WORDS:
4799 new_pos = gtk_entry_move_forward_word (entry, new_pos, FALSE);
4804 new_pos = gtk_entry_move_backward_word (entry, new_pos, FALSE);
4807 if (entry->current_pos == new_pos)
4808 gtk_widget_error_bell (GTK_WIDGET (entry));
4810 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
4811 case GTK_MOVEMENT_PARAGRAPH_ENDS:
4812 case GTK_MOVEMENT_BUFFER_ENDS:
4813 priv = GTK_ENTRY_GET_PRIVATE (entry);
4814 new_pos = count < 0 ? 0 : gtk_entry_buffer_get_length (get_buffer (entry));
4815 if (entry->current_pos == new_pos)
4816 gtk_widget_error_bell (GTK_WIDGET (entry));
4818 case GTK_MOVEMENT_DISPLAY_LINES:
4819 case GTK_MOVEMENT_PARAGRAPHS:
4820 case GTK_MOVEMENT_PAGES:
4821 case GTK_MOVEMENT_HORIZONTAL_PAGES:
4826 if (extend_selection)
4827 gtk_editable_select_region (GTK_EDITABLE (entry), entry->selection_bound, new_pos);
4829 gtk_editable_set_position (GTK_EDITABLE (entry), new_pos);
4831 gtk_entry_pend_cursor_blink (entry);
4835 gtk_entry_insert_at_cursor (GtkEntry *entry,
4838 GtkEditable *editable = GTK_EDITABLE (entry);
4839 gint pos = entry->current_pos;
4841 if (entry->editable)
4843 _gtk_entry_reset_im_context (entry);
4845 gtk_editable_insert_text (editable, str, -1, &pos);
4846 gtk_editable_set_position (editable, pos);
4851 gtk_entry_delete_from_cursor (GtkEntry *entry,
4855 GtkEditable *editable = GTK_EDITABLE (entry);
4856 gint start_pos = entry->current_pos;
4857 gint end_pos = entry->current_pos;
4858 gint old_n_bytes = gtk_entry_buffer_get_bytes (get_buffer (entry));
4860 _gtk_entry_reset_im_context (entry);
4862 if (!entry->editable)
4864 gtk_widget_error_bell (GTK_WIDGET (entry));
4868 if (entry->selection_bound != entry->current_pos)
4870 gtk_editable_delete_selection (editable);
4876 case GTK_DELETE_CHARS:
4877 end_pos = gtk_entry_move_logically (entry, entry->current_pos, count);
4878 gtk_editable_delete_text (editable, MIN (start_pos, end_pos), MAX (start_pos, end_pos));
4880 case GTK_DELETE_WORDS:
4883 /* Move to end of current word, or if not on a word, end of previous word */
4884 end_pos = gtk_entry_move_backward_word (entry, end_pos, FALSE);
4885 end_pos = gtk_entry_move_forward_word (entry, end_pos, FALSE);
4889 /* Move to beginning of current word, or if not on a word, begining of next word */
4890 start_pos = gtk_entry_move_forward_word (entry, start_pos, FALSE);
4891 start_pos = gtk_entry_move_backward_word (entry, start_pos, FALSE);
4895 case GTK_DELETE_WORD_ENDS:
4898 start_pos = gtk_entry_move_backward_word (entry, start_pos, FALSE);
4903 end_pos = gtk_entry_move_forward_word (entry, end_pos, FALSE);
4906 gtk_editable_delete_text (editable, start_pos, end_pos);
4908 case GTK_DELETE_DISPLAY_LINE_ENDS:
4909 case GTK_DELETE_PARAGRAPH_ENDS:
4911 gtk_editable_delete_text (editable, 0, entry->current_pos);
4913 gtk_editable_delete_text (editable, entry->current_pos, -1);
4915 case GTK_DELETE_DISPLAY_LINES:
4916 case GTK_DELETE_PARAGRAPHS:
4917 gtk_editable_delete_text (editable, 0, -1);
4919 case GTK_DELETE_WHITESPACE:
4920 gtk_entry_delete_whitespace (entry);
4924 if (gtk_entry_buffer_get_bytes (get_buffer (entry)) == old_n_bytes)
4925 gtk_widget_error_bell (GTK_WIDGET (entry));
4927 gtk_entry_pend_cursor_blink (entry);
4931 gtk_entry_backspace (GtkEntry *entry)
4933 GtkEditable *editable = GTK_EDITABLE (entry);
4936 _gtk_entry_reset_im_context (entry);
4938 if (!entry->editable)
4940 gtk_widget_error_bell (GTK_WIDGET (entry));
4944 if (entry->selection_bound != entry->current_pos)
4946 gtk_editable_delete_selection (editable);
4950 prev_pos = gtk_entry_move_logically (entry, entry->current_pos, -1);
4952 if (prev_pos < entry->current_pos)
4954 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
4955 PangoLogAttr *log_attrs;
4958 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
4960 /* Deleting parts of characters */
4961 if (log_attrs[entry->current_pos].backspace_deletes_character)
4963 gchar *cluster_text;
4964 gchar *normalized_text;
4967 cluster_text = gtk_entry_get_display_text (entry, prev_pos,
4968 entry->current_pos);
4969 normalized_text = g_utf8_normalize (cluster_text,
4970 strlen (cluster_text),
4972 len = g_utf8_strlen (normalized_text, -1);
4974 gtk_editable_delete_text (editable, prev_pos, entry->current_pos);
4977 gint pos = entry->current_pos;
4979 gtk_editable_insert_text (editable, normalized_text,
4980 g_utf8_offset_to_pointer (normalized_text, len - 1) - normalized_text,
4982 gtk_editable_set_position (editable, pos);
4985 g_free (normalized_text);
4986 g_free (cluster_text);
4990 gtk_editable_delete_text (editable, prev_pos, entry->current_pos);
4997 gtk_widget_error_bell (GTK_WIDGET (entry));
5000 gtk_entry_pend_cursor_blink (entry);
5004 gtk_entry_copy_clipboard (GtkEntry *entry)
5006 GtkEditable *editable = GTK_EDITABLE (entry);
5010 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5012 if (!entry->visible)
5014 gtk_widget_error_bell (GTK_WIDGET (entry));
5018 str = gtk_entry_get_display_text (entry, start, end);
5019 gtk_clipboard_set_text (gtk_widget_get_clipboard (GTK_WIDGET (entry),
5020 GDK_SELECTION_CLIPBOARD),
5027 gtk_entry_cut_clipboard (GtkEntry *entry)
5029 GtkEditable *editable = GTK_EDITABLE (entry);
5032 if (!entry->visible)
5034 gtk_widget_error_bell (GTK_WIDGET (entry));
5038 gtk_entry_copy_clipboard (entry);
5040 if (entry->editable)
5042 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5043 gtk_editable_delete_text (editable, start, end);
5047 gtk_widget_error_bell (GTK_WIDGET (entry));
5052 gtk_entry_paste_clipboard (GtkEntry *entry)
5054 if (entry->editable)
5055 gtk_entry_paste (entry, GDK_NONE);
5057 gtk_widget_error_bell (GTK_WIDGET (entry));
5061 gtk_entry_delete_cb (GtkEntry *entry)
5063 GtkEditable *editable = GTK_EDITABLE (entry);
5066 if (entry->editable)
5068 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5069 gtk_editable_delete_text (editable, start, end);
5074 gtk_entry_toggle_overwrite (GtkEntry *entry)
5076 entry->overwrite_mode = !entry->overwrite_mode;
5077 gtk_entry_pend_cursor_blink (entry);
5078 gtk_widget_queue_draw (GTK_WIDGET (entry));
5082 gtk_entry_select_all (GtkEntry *entry)
5084 gtk_entry_select_line (entry);
5088 gtk_entry_real_activate (GtkEntry *entry)
5091 GtkWidget *toplevel;
5094 widget = GTK_WIDGET (entry);
5096 if (entry->activates_default)
5098 toplevel = gtk_widget_get_toplevel (widget);
5099 if (GTK_IS_WINDOW (toplevel))
5101 window = GTK_WINDOW (toplevel);
5104 widget != window->default_widget &&
5105 !(widget == window->focus_widget &&
5106 (!window->default_widget || !GTK_WIDGET_SENSITIVE (window->default_widget))))
5107 gtk_window_activate_default (window);
5113 keymap_direction_changed (GdkKeymap *keymap,
5116 gtk_entry_recompute (entry);
5119 /* IM Context Callbacks
5123 gtk_entry_commit_cb (GtkIMContext *context,
5127 if (entry->editable)
5128 gtk_entry_enter_text (entry, str);
5132 gtk_entry_preedit_changed_cb (GtkIMContext *context,
5135 if (entry->editable)
5137 gchar *preedit_string;
5140 gtk_im_context_get_preedit_string (entry->im_context,
5141 &preedit_string, NULL,
5143 entry->preedit_length = strlen (preedit_string);
5144 cursor_pos = CLAMP (cursor_pos, 0, g_utf8_strlen (preedit_string, -1));
5145 entry->preedit_cursor = cursor_pos;
5146 g_free (preedit_string);
5148 gtk_entry_recompute (entry);
5153 gtk_entry_retrieve_surrounding_cb (GtkIMContext *context,
5158 /* XXXX ??? does this even make sense when text is not visible? Should we return FALSE? */
5159 text = gtk_entry_get_display_text (entry, 0, -1);
5160 gtk_im_context_set_surrounding (context, text, strlen (text), /* Length in bytes */
5161 g_utf8_offset_to_pointer (text, entry->current_pos) - text);
5168 gtk_entry_delete_surrounding_cb (GtkIMContext *slave,
5173 if (entry->editable)
5174 gtk_editable_delete_text (GTK_EDITABLE (entry),
5175 entry->current_pos + offset,
5176 entry->current_pos + offset + n_chars);
5181 /* Internal functions
5184 /* Used for im_commit_cb and inserting Unicode chars */
5186 gtk_entry_enter_text (GtkEntry *entry,
5189 GtkEditable *editable = GTK_EDITABLE (entry);
5191 gboolean old_need_im_reset;
5193 old_need_im_reset = entry->need_im_reset;
5194 entry->need_im_reset = FALSE;
5196 if (gtk_editable_get_selection_bounds (editable, NULL, NULL))
5197 gtk_editable_delete_selection (editable);
5200 if (entry->overwrite_mode)
5201 gtk_entry_delete_from_cursor (entry, GTK_DELETE_CHARS, 1);
5204 tmp_pos = entry->current_pos;
5205 gtk_editable_insert_text (editable, str, strlen (str), &tmp_pos);
5206 gtk_editable_set_position (editable, tmp_pos);
5208 entry->need_im_reset = old_need_im_reset;
5211 /* All changes to entry->current_pos and entry->selection_bound
5212 * should go through this function.
5215 gtk_entry_set_positions (GtkEntry *entry,
5217 gint selection_bound)
5219 gboolean changed = FALSE;
5221 g_object_freeze_notify (G_OBJECT (entry));
5223 if (current_pos != -1 &&
5224 entry->current_pos != current_pos)
5226 entry->current_pos = current_pos;
5229 g_object_notify (G_OBJECT (entry), "cursor-position");
5232 if (selection_bound != -1 &&
5233 entry->selection_bound != selection_bound)
5235 entry->selection_bound = selection_bound;
5238 g_object_notify (G_OBJECT (entry), "selection-bound");
5241 g_object_thaw_notify (G_OBJECT (entry));
5245 gtk_entry_move_adjustments (entry);
5246 gtk_entry_recompute (entry);
5251 gtk_entry_reset_layout (GtkEntry *entry)
5253 if (entry->cached_layout)
5255 g_object_unref (entry->cached_layout);
5256 entry->cached_layout = NULL;
5261 update_im_cursor_location (GtkEntry *entry)
5265 gint strong_xoffset;
5266 gint area_width, area_height;
5268 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
5269 gtk_entry_get_text_area_size (entry, NULL, NULL, &area_width, &area_height);
5271 strong_xoffset = strong_x - entry->scroll_offset;
5272 if (strong_xoffset < 0)
5276 else if (strong_xoffset > area_width)
5278 strong_xoffset = area_width;
5280 area.x = strong_xoffset;
5283 area.height = area_height;
5285 gtk_im_context_set_cursor_location (entry->im_context, &area);
5289 recompute_idle_func (gpointer data)
5293 entry = GTK_ENTRY (data);
5295 entry->recompute_idle = 0;
5297 if (gtk_widget_has_screen (GTK_WIDGET (entry)))
5299 gtk_entry_adjust_scroll (entry);
5300 gtk_entry_queue_draw (entry);
5302 update_im_cursor_location (entry);
5309 gtk_entry_recompute (GtkEntry *entry)
5311 gtk_entry_reset_layout (entry);
5312 gtk_entry_check_cursor_blink (entry);
5314 if (!entry->recompute_idle)
5316 entry->recompute_idle = gdk_threads_add_idle_full (G_PRIORITY_HIGH_IDLE + 15, /* between resize and redraw */
5317 recompute_idle_func, entry, NULL);
5321 static PangoLayout *
5322 gtk_entry_create_layout (GtkEntry *entry,
5323 gboolean include_preedit)
5325 GtkWidget *widget = GTK_WIDGET (entry);
5326 PangoLayout *layout = gtk_widget_create_pango_layout (widget, NULL);
5327 PangoAttrList *tmp_attrs = pango_attr_list_new ();
5329 gchar *preedit_string = NULL;
5330 gint preedit_length = 0;
5331 PangoAttrList *preedit_attrs = NULL;
5336 pango_layout_set_single_paragraph_mode (layout, TRUE);
5338 display = gtk_entry_get_display_text (entry, 0, -1);
5339 n_bytes = strlen (display);
5341 if (include_preedit)
5343 gtk_im_context_get_preedit_string (entry->im_context,
5344 &preedit_string, &preedit_attrs, NULL);
5345 preedit_length = entry->preedit_length;
5350 GString *tmp_string = g_string_new (display);
5351 gint cursor_index = g_utf8_offset_to_pointer (display, entry->current_pos) - display;
5353 g_string_insert (tmp_string, cursor_index, preedit_string);
5355 pango_layout_set_text (layout, tmp_string->str, tmp_string->len);
5357 pango_attr_list_splice (tmp_attrs, preedit_attrs,
5358 cursor_index, preedit_length);
5360 g_string_free (tmp_string, TRUE);
5364 PangoDirection pango_dir;
5366 if (gtk_entry_get_display_mode (entry) == DISPLAY_NORMAL)
5367 pango_dir = pango_find_base_dir (display, n_bytes);
5369 pango_dir = PANGO_DIRECTION_NEUTRAL;
5371 if (pango_dir == PANGO_DIRECTION_NEUTRAL)
5373 if (GTK_WIDGET_HAS_FOCUS (widget))
5375 GdkDisplay *display = gtk_widget_get_display (widget);
5376 GdkKeymap *keymap = gdk_keymap_get_for_display (display);
5377 if (gdk_keymap_get_direction (keymap) == PANGO_DIRECTION_RTL)
5378 pango_dir = PANGO_DIRECTION_RTL;
5380 pango_dir = PANGO_DIRECTION_LTR;
5384 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
5385 pango_dir = PANGO_DIRECTION_RTL;
5387 pango_dir = PANGO_DIRECTION_LTR;
5391 pango_context_set_base_dir (gtk_widget_get_pango_context (widget),
5394 entry->resolved_dir = pango_dir;
5396 pango_layout_set_text (layout, display, n_bytes);
5399 pango_layout_set_attributes (layout, tmp_attrs);
5401 g_free (preedit_string);
5405 pango_attr_list_unref (preedit_attrs);
5407 pango_attr_list_unref (tmp_attrs);
5412 static PangoLayout *
5413 gtk_entry_ensure_layout (GtkEntry *entry,
5414 gboolean include_preedit)
5416 if (entry->preedit_length > 0 &&
5417 !include_preedit != !entry->cache_includes_preedit)
5418 gtk_entry_reset_layout (entry);
5420 if (!entry->cached_layout)
5422 entry->cached_layout = gtk_entry_create_layout (entry, include_preedit);
5423 entry->cache_includes_preedit = include_preedit;
5426 return entry->cached_layout;
5430 get_layout_position (GtkEntry *entry,
5434 PangoLayout *layout;
5435 PangoRectangle logical_rect;
5436 gint area_width, area_height;
5437 GtkBorder inner_border;
5439 PangoLayoutLine *line;
5441 layout = gtk_entry_ensure_layout (entry, TRUE);
5443 gtk_entry_get_text_area_size (entry, NULL, NULL, &area_width, &area_height);
5444 _gtk_entry_effective_inner_border (entry, &inner_border);
5446 area_height = PANGO_SCALE * (area_height - inner_border.top - inner_border.bottom);
5448 line = pango_layout_get_lines_readonly (layout)->data;
5449 pango_layout_line_get_extents (line, NULL, &logical_rect);
5451 /* Align primarily for locale's ascent/descent */
5452 y_pos = ((area_height - entry->ascent - entry->descent) / 2 +
5453 entry->ascent + logical_rect.y);
5455 /* Now see if we need to adjust to fit in actual drawn string */
5456 if (logical_rect.height > area_height)
5457 y_pos = (area_height - logical_rect.height) / 2;
5460 else if (y_pos + logical_rect.height > area_height)
5461 y_pos = area_height - logical_rect.height;
5463 y_pos = inner_border.top + y_pos / PANGO_SCALE;
5466 *x = inner_border.left - entry->scroll_offset;
5473 draw_text_with_color (GtkEntry *entry, cairo_t *cr, GdkColor *default_color)
5475 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
5478 gint start_pos, end_pos;
5480 widget = GTK_WIDGET (entry);
5484 get_layout_position (entry, &x, &y);
5486 cairo_move_to (cr, x, y);
5487 gdk_cairo_set_source_color (cr, default_color);
5488 pango_cairo_show_layout (cr, layout);
5490 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start_pos, &end_pos))
5494 PangoRectangle logical_rect;
5495 GdkColor *selection_color, *text_color;
5496 GtkBorder inner_border;
5498 pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
5499 gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
5501 if (GTK_WIDGET_HAS_FOCUS (entry))
5503 selection_color = &widget->style->base [GTK_STATE_SELECTED];
5504 text_color = &widget->style->text [GTK_STATE_SELECTED];
5508 selection_color = &widget->style->base [GTK_STATE_ACTIVE];
5509 text_color = &widget->style->text [GTK_STATE_ACTIVE];
5512 _gtk_entry_effective_inner_border (entry, &inner_border);
5514 for (i = 0; i < n_ranges; ++i)
5515 cairo_rectangle (cr,
5516 inner_border.left - entry->scroll_offset + ranges[2 * i],
5519 logical_rect.height);
5523 gdk_cairo_set_source_color (cr, selection_color);
5526 cairo_move_to (cr, x, y);
5527 gdk_cairo_set_source_color (cr, text_color);
5528 pango_cairo_show_layout (cr, layout);
5536 gtk_entry_draw_text (GtkEntry *entry)
5538 GtkWidget *widget = GTK_WIDGET (entry);
5541 /* Nothing to display at all */
5542 if (gtk_entry_get_display_mode (entry) == DISPLAY_BLANK)
5545 if (GTK_WIDGET_DRAWABLE (entry))
5547 GdkColor text_color, bar_text_color;
5550 gint progress_x, progress_y, progress_width, progress_height;
5553 state = GTK_STATE_SELECTED;
5554 if (!GTK_WIDGET_SENSITIVE (widget))
5555 state = GTK_STATE_INSENSITIVE;
5556 text_color = widget->style->text[widget->state];
5557 bar_text_color = widget->style->fg[state];
5559 get_progress_area (widget,
5560 &progress_x, &progress_y,
5561 &progress_width, &progress_height);
5563 cr = gdk_cairo_create (entry->text_area);
5565 /* If the color is the same, or the progress area has a zero
5566 * size, then we only need to draw once. */
5567 if ((text_color.pixel == bar_text_color.pixel) ||
5568 ((progress_width == 0) || (progress_height == 0)))
5570 draw_text_with_color (entry, cr, &text_color);
5574 gdk_drawable_get_size (entry->text_area, &width, &height);
5576 cairo_rectangle (cr, 0, 0, width, height);
5580 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
5581 cairo_rectangle (cr, 0, 0, width, height);
5583 gdk_window_get_position (entry->text_area, &pos_x, &pos_y);
5584 progress_x -= pos_x;
5585 progress_y -= pos_y;
5587 cairo_rectangle (cr, progress_x, progress_y,
5588 progress_width, progress_height);
5590 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_WINDING);
5592 draw_text_with_color (entry, cr, &text_color);
5595 cairo_rectangle (cr, progress_x, progress_y,
5596 progress_width, progress_height);
5599 draw_text_with_color (entry, cr, &bar_text_color);
5607 draw_insertion_cursor (GtkEntry *entry,
5608 GdkRectangle *cursor_location,
5609 gboolean is_primary,
5610 PangoDirection direction,
5611 gboolean draw_arrow)
5613 GtkWidget *widget = GTK_WIDGET (entry);
5614 GtkTextDirection text_dir;
5616 if (direction == PANGO_DIRECTION_LTR)
5617 text_dir = GTK_TEXT_DIR_LTR;
5619 text_dir = GTK_TEXT_DIR_RTL;
5621 gtk_draw_insertion_cursor (widget, entry->text_area, NULL,
5623 is_primary, text_dir, draw_arrow);
5627 gtk_entry_draw_cursor (GtkEntry *entry,
5630 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
5631 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
5633 if (GTK_WIDGET_DRAWABLE (entry))
5635 GtkWidget *widget = GTK_WIDGET (entry);
5636 GdkRectangle cursor_location;
5637 gboolean split_cursor;
5638 PangoRectangle cursor_rect;
5639 GtkBorder inner_border;
5641 gint text_area_height;
5644 gboolean block_at_line_end;
5645 PangoLayout *layout;
5648 _gtk_entry_effective_inner_border (entry, &inner_border);
5650 xoffset = inner_border.left - entry->scroll_offset;
5652 gdk_drawable_get_size (entry->text_area, NULL, &text_area_height);
5654 layout = gtk_entry_ensure_layout (entry, TRUE);
5655 text = pango_layout_get_text (layout);
5656 cursor_index = g_utf8_offset_to_pointer (text, entry->current_pos + entry->preedit_cursor) - text;
5657 if (!entry->overwrite_mode)
5660 block = _gtk_text_util_get_block_cursor_location (layout,
5661 cursor_index, &cursor_rect, &block_at_line_end);
5665 gint strong_x, weak_x;
5666 PangoDirection dir1 = PANGO_DIRECTION_NEUTRAL;
5667 PangoDirection dir2 = PANGO_DIRECTION_NEUTRAL;
5671 gtk_entry_get_cursor_locations (entry, type, &strong_x, &weak_x);
5673 g_object_get (gtk_widget_get_settings (widget),
5674 "gtk-split-cursor", &split_cursor,
5677 dir1 = entry->resolved_dir;
5683 if (weak_x != strong_x)
5685 dir2 = (entry->resolved_dir == PANGO_DIRECTION_LTR) ? PANGO_DIRECTION_RTL : PANGO_DIRECTION_LTR;
5691 if (keymap_direction == entry->resolved_dir)
5697 cursor_location.x = xoffset + x1;
5698 cursor_location.y = inner_border.top;
5699 cursor_location.width = 0;
5700 cursor_location.height = text_area_height - inner_border.top - inner_border.bottom;
5702 draw_insertion_cursor (entry,
5703 &cursor_location, TRUE, dir1,
5704 dir2 != PANGO_DIRECTION_NEUTRAL);
5706 if (dir2 != PANGO_DIRECTION_NEUTRAL)
5708 cursor_location.x = xoffset + x2;
5709 draw_insertion_cursor (entry,
5710 &cursor_location, FALSE, dir2,
5714 else /* overwrite_mode */
5716 GdkColor cursor_color;
5721 get_layout_position (entry, &x, &y);
5723 rect.x = PANGO_PIXELS (cursor_rect.x) + x;
5724 rect.y = PANGO_PIXELS (cursor_rect.y) + y;
5725 rect.width = PANGO_PIXELS (cursor_rect.width);
5726 rect.height = PANGO_PIXELS (cursor_rect.height);
5728 cr = gdk_cairo_create (entry->text_area);
5730 _gtk_widget_get_cursor_color (widget, &cursor_color);
5731 gdk_cairo_set_source_color (cr, &cursor_color);
5732 gdk_cairo_rectangle (cr, &rect);
5735 if (!block_at_line_end)
5737 gdk_cairo_rectangle (cr, &rect);
5739 cairo_move_to (cr, x, y);
5740 gdk_cairo_set_source_color (cr, &widget->style->base[widget->state]);
5741 pango_cairo_show_layout (cr, layout);
5750 gtk_entry_queue_draw (GtkEntry *entry)
5752 if (GTK_WIDGET_DRAWABLE (entry))
5753 gdk_window_invalidate_rect (entry->text_area, NULL, FALSE);
5757 _gtk_entry_reset_im_context (GtkEntry *entry)
5759 if (entry->need_im_reset)
5761 entry->need_im_reset = FALSE;
5762 gtk_im_context_reset (entry->im_context);
5767 gtk_entry_find_position (GtkEntry *entry,
5770 PangoLayout *layout;
5771 PangoLayoutLine *line;
5778 layout = gtk_entry_ensure_layout (entry, TRUE);
5779 text = pango_layout_get_text (layout);
5780 cursor_index = g_utf8_offset_to_pointer (text, entry->current_pos) - text;
5782 line = pango_layout_get_lines_readonly (layout)->data;
5783 pango_layout_line_x_to_index (line, x * PANGO_SCALE, &index, &trailing);
5785 if (index >= cursor_index && entry->preedit_length)
5787 if (index >= cursor_index + entry->preedit_length)
5788 index -= entry->preedit_length;
5791 index = cursor_index;
5796 pos = g_utf8_pointer_to_offset (text, text + index);
5803 gtk_entry_get_cursor_locations (GtkEntry *entry,
5808 DisplayMode mode = gtk_entry_get_display_mode (entry);
5810 /* Nothing to display at all, so no cursor is relevant */
5811 if (mode == DISPLAY_BLANK)
5821 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
5822 const gchar *text = pango_layout_get_text (layout);
5823 PangoRectangle strong_pos, weak_pos;
5826 if (type == CURSOR_STANDARD)
5828 index = g_utf8_offset_to_pointer (text, entry->current_pos + entry->preedit_cursor) - text;
5830 else /* type == CURSOR_DND */
5832 index = g_utf8_offset_to_pointer (text, entry->dnd_position) - text;
5834 if (entry->dnd_position > entry->current_pos)
5836 if (mode == DISPLAY_NORMAL)
5837 index += entry->preedit_length;
5840 gint preedit_len_chars = g_utf8_strlen (text, -1) - gtk_entry_buffer_get_length (get_buffer (entry));
5841 index += preedit_len_chars * g_unichar_to_utf8 (entry->invisible_char, NULL);
5846 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
5849 *strong_x = strong_pos.x / PANGO_SCALE;
5852 *weak_x = weak_pos.x / PANGO_SCALE;
5857 gtk_entry_adjust_scroll (GtkEntry *entry)
5859 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
5860 gint min_offset, max_offset;
5861 gint text_area_width, text_width;
5862 GtkBorder inner_border;
5863 gint strong_x, weak_x;
5864 gint strong_xoffset, weak_xoffset;
5866 PangoLayout *layout;
5867 PangoLayoutLine *line;
5868 PangoRectangle logical_rect;
5870 if (!GTK_WIDGET_REALIZED (entry))
5873 _gtk_entry_effective_inner_border (entry, &inner_border);
5875 gdk_drawable_get_size (entry->text_area, &text_area_width, NULL);
5876 text_area_width -= inner_border.left + inner_border.right;
5877 if (text_area_width < 0)
5878 text_area_width = 0;
5880 layout = gtk_entry_ensure_layout (entry, TRUE);
5881 line = pango_layout_get_lines_readonly (layout)->data;
5883 pango_layout_line_get_extents (line, NULL, &logical_rect);
5885 /* Display as much text as we can */
5887 if (entry->resolved_dir == PANGO_DIRECTION_LTR)
5888 xalign = priv->xalign;
5890 xalign = 1.0 - priv->xalign;
5892 text_width = PANGO_PIXELS(logical_rect.width);
5894 if (text_width > text_area_width)
5897 max_offset = text_width - text_area_width;
5901 min_offset = (text_width - text_area_width) * xalign;
5902 max_offset = min_offset;
5905 entry->scroll_offset = CLAMP (entry->scroll_offset, min_offset, max_offset);
5907 /* And make sure cursors are on screen. Note that the cursor is
5908 * actually drawn one pixel into the INNER_BORDER space on
5909 * the right, when the scroll is at the utmost right. This
5910 * looks better to to me than confining the cursor inside the
5911 * border entirely, though it means that the cursor gets one
5912 * pixel closer to the edge of the widget on the right than
5913 * on the left. This might need changing if one changed
5914 * INNER_BORDER from 2 to 1, as one would do on a
5915 * small-screen-real-estate display.
5917 * We always make sure that the strong cursor is on screen, and
5918 * put the weak cursor on screen if possible.
5921 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, &weak_x);
5923 strong_xoffset = strong_x - entry->scroll_offset;
5925 if (strong_xoffset < 0)
5927 entry->scroll_offset += strong_xoffset;
5930 else if (strong_xoffset > text_area_width)
5932 entry->scroll_offset += strong_xoffset - text_area_width;
5933 strong_xoffset = text_area_width;
5936 weak_xoffset = weak_x - entry->scroll_offset;
5938 if (weak_xoffset < 0 && strong_xoffset - weak_xoffset <= text_area_width)
5940 entry->scroll_offset += weak_xoffset;
5942 else if (weak_xoffset > text_area_width &&
5943 strong_xoffset - (weak_xoffset - text_area_width) >= 0)
5945 entry->scroll_offset += weak_xoffset - text_area_width;
5948 g_object_notify (G_OBJECT (entry), "scroll-offset");
5952 gtk_entry_move_adjustments (GtkEntry *entry)
5954 PangoContext *context;
5955 PangoFontMetrics *metrics;
5956 gint x, layout_x, border_x, border_y;
5958 GtkAdjustment *adjustment;
5960 adjustment = g_object_get_qdata (G_OBJECT (entry), quark_cursor_hadjustment);
5964 /* Cursor position, layout offset, border width, and widget allocation */
5965 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &x, NULL);
5966 get_layout_position (entry, &layout_x, NULL);
5967 _gtk_entry_get_borders (entry, &border_x, &border_y);
5968 x += entry->widget.allocation.x + layout_x + border_x;
5970 /* Approximate width of a char, so user can see what is ahead/behind */
5971 context = gtk_widget_get_pango_context (GTK_WIDGET (entry));
5972 metrics = pango_context_get_metrics (context,
5973 entry->widget.style->font_desc,
5974 pango_context_get_language (context));
5975 char_width = pango_font_metrics_get_approximate_char_width (metrics) / PANGO_SCALE;
5978 gtk_adjustment_clamp_page (adjustment,
5979 x - (char_width + 1), /* one char + one pixel before */
5980 x + (char_width + 2)); /* one char + cursor + one pixel after */
5984 gtk_entry_move_visually (GtkEntry *entry,
5989 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
5992 text = pango_layout_get_text (layout);
5994 index = g_utf8_offset_to_pointer (text, start) - text;
5998 int new_index, new_trailing;
5999 gboolean split_cursor;
6002 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
6003 "gtk-split-cursor", &split_cursor,
6010 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
6011 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
6013 strong = keymap_direction == entry->resolved_dir;
6018 pango_layout_move_cursor_visually (layout, strong, index, 0, 1, &new_index, &new_trailing);
6023 pango_layout_move_cursor_visually (layout, strong, index, 0, -1, &new_index, &new_trailing);
6029 else if (new_index != G_MAXINT)
6032 while (new_trailing--)
6033 index = g_utf8_next_char (text + index) - text;
6036 return g_utf8_pointer_to_offset (text, text + index);
6040 gtk_entry_move_logically (GtkEntry *entry,
6044 gint new_pos = start;
6047 length = gtk_entry_buffer_get_length (get_buffer (entry));
6049 /* Prevent any leak of information */
6050 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6052 new_pos = CLAMP (start + count, 0, length);
6056 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6057 PangoLogAttr *log_attrs;
6060 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6062 while (count > 0 && new_pos < length)
6066 while (new_pos < length && !log_attrs[new_pos].is_cursor_position);
6070 while (count < 0 && new_pos > 0)
6074 while (new_pos > 0 && !log_attrs[new_pos].is_cursor_position);
6086 gtk_entry_move_forward_word (GtkEntry *entry,
6088 gboolean allow_whitespace)
6090 gint new_pos = start;
6093 length = gtk_entry_buffer_get_length (get_buffer (entry));
6095 /* Prevent any leak of information */
6096 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6100 else if (new_pos < length)
6102 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6103 PangoLogAttr *log_attrs;
6106 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6108 /* Find the next word boundary */
6110 while (new_pos < n_attrs - 1 && !(log_attrs[new_pos].is_word_end ||
6111 (log_attrs[new_pos].is_word_start && allow_whitespace)))
6122 gtk_entry_move_backward_word (GtkEntry *entry,
6124 gboolean allow_whitespace)
6126 gint new_pos = start;
6128 /* Prevent any leak of information */
6129 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6135 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6136 PangoLogAttr *log_attrs;
6139 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6141 new_pos = start - 1;
6143 /* Find the previous word boundary */
6144 while (new_pos > 0 && !(log_attrs[new_pos].is_word_start ||
6145 (log_attrs[new_pos].is_word_end && allow_whitespace)))
6155 gtk_entry_delete_whitespace (GtkEntry *entry)
6157 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6158 PangoLogAttr *log_attrs;
6162 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6164 start = end = entry->current_pos;
6166 while (start > 0 && log_attrs[start-1].is_white)
6169 while (end < n_attrs && log_attrs[end].is_white)
6175 gtk_editable_delete_text (GTK_EDITABLE (entry), start, end);
6180 gtk_entry_select_word (GtkEntry *entry)
6182 gint start_pos = gtk_entry_move_backward_word (entry, entry->current_pos, TRUE);
6183 gint end_pos = gtk_entry_move_forward_word (entry, entry->current_pos, TRUE);
6185 gtk_editable_select_region (GTK_EDITABLE (entry), start_pos, end_pos);
6189 gtk_entry_select_line (GtkEntry *entry)
6191 gtk_editable_select_region (GTK_EDITABLE (entry), 0, -1);
6195 truncate_multiline (const gchar *text)
6200 text[length] && text[length] != '\n' && text[length] != '\r';
6207 paste_received (GtkClipboard *clipboard,
6211 GtkEntry *entry = GTK_ENTRY (data);
6212 GtkEditable *editable = GTK_EDITABLE (entry);
6213 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
6215 if (entry->button == 2)
6217 gint pos, start, end;
6218 pos = priv->insert_pos;
6219 gtk_editable_get_selection_bounds (editable, &start, &end);
6220 if (!((start <= pos && pos <= end) || (end <= pos && pos <= start)))
6221 gtk_editable_select_region (editable, pos, pos);
6226 gint pos, start, end;
6228 gboolean popup_completion;
6229 GtkEntryCompletion *completion;
6231 completion = gtk_entry_get_completion (entry);
6233 if (entry->truncate_multiline)
6234 length = truncate_multiline (text);
6236 /* only complete if the selection is at the end */
6237 popup_completion = (gtk_entry_buffer_get_length (get_buffer (entry)) ==
6238 MAX (entry->current_pos, entry->selection_bound));
6242 if (GTK_WIDGET_MAPPED (completion->priv->popup_window))
6243 _gtk_entry_completion_popdown (completion);
6245 if (!popup_completion && completion->priv->changed_id > 0)
6246 g_signal_handler_block (entry, completion->priv->changed_id);
6249 begin_change (entry);
6250 g_object_freeze_notify (G_OBJECT (entry));
6251 if (gtk_editable_get_selection_bounds (editable, &start, &end))
6252 gtk_editable_delete_text (editable, start, end);
6254 pos = entry->current_pos;
6255 gtk_editable_insert_text (editable, text, length, &pos);
6256 gtk_editable_set_position (editable, pos);
6257 g_object_thaw_notify (G_OBJECT (entry));
6261 !popup_completion && completion->priv->changed_id > 0)
6262 g_signal_handler_unblock (entry, completion->priv->changed_id);
6265 g_object_unref (entry);
6269 gtk_entry_paste (GtkEntry *entry,
6272 g_object_ref (entry);
6273 gtk_clipboard_request_text (gtk_widget_get_clipboard (GTK_WIDGET (entry), selection),
6274 paste_received, entry);
6278 primary_get_cb (GtkClipboard *clipboard,
6279 GtkSelectionData *selection_data,
6283 GtkEntry *entry = GTK_ENTRY (data);
6286 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end))
6288 gchar *str = gtk_entry_get_display_text (entry, start, end);
6289 gtk_selection_data_set_text (selection_data, str, -1);
6295 primary_clear_cb (GtkClipboard *clipboard,
6298 GtkEntry *entry = GTK_ENTRY (data);
6300 gtk_editable_select_region (GTK_EDITABLE (entry), entry->current_pos, entry->current_pos);
6304 gtk_entry_update_primary_selection (GtkEntry *entry)
6306 GtkTargetList *list;
6307 GtkTargetEntry *targets;
6308 GtkClipboard *clipboard;
6312 if (!GTK_WIDGET_REALIZED (entry))
6315 list = gtk_target_list_new (NULL, 0);
6316 gtk_target_list_add_text_targets (list, 0);
6318 targets = gtk_target_table_new_from_list (list, &n_targets);
6320 clipboard = gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_PRIMARY);
6322 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end))
6324 if (!gtk_clipboard_set_with_owner (clipboard, targets, n_targets,
6325 primary_get_cb, primary_clear_cb, G_OBJECT (entry)))
6326 primary_clear_cb (clipboard, entry);
6330 if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (entry))
6331 gtk_clipboard_clear (clipboard);
6334 gtk_target_table_free (targets, n_targets);
6335 gtk_target_list_unref (list);
6339 gtk_entry_clear (GtkEntry *entry,
6340 GtkEntryIconPosition icon_pos)
6342 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
6343 EntryIconInfo *icon_info = priv->icons[icon_pos];
6345 if (!icon_info || icon_info->storage_type == GTK_IMAGE_EMPTY)
6348 g_object_freeze_notify (G_OBJECT (entry));
6350 /* Explicitly check, as the pointer may become invalidated
6351 * during destruction.
6353 if (GDK_IS_WINDOW (icon_info->window))
6354 gdk_window_hide (icon_info->window);
6356 if (icon_info->pixbuf)
6358 g_object_unref (icon_info->pixbuf);
6359 icon_info->pixbuf = NULL;
6362 switch (icon_info->storage_type)
6364 case GTK_IMAGE_PIXBUF:
6365 g_object_notify (G_OBJECT (entry),
6366 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-pixbuf" : "secondary-icon-pixbuf");
6369 case GTK_IMAGE_STOCK:
6370 g_free (icon_info->stock_id);
6371 icon_info->stock_id = NULL;
6372 g_object_notify (G_OBJECT (entry),
6373 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-stock" : "secondary-icon-stock");
6376 case GTK_IMAGE_ICON_NAME:
6377 g_free (icon_info->icon_name);
6378 icon_info->icon_name = NULL;
6379 g_object_notify (G_OBJECT (entry),
6380 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-name" : "secondary-icon-name");
6383 case GTK_IMAGE_GICON:
6384 if (icon_info->gicon)
6386 g_object_unref (icon_info->gicon);
6387 icon_info->gicon = NULL;
6389 g_object_notify (G_OBJECT (entry),
6390 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-gicon" : "secondary-icon-gicon");
6394 g_assert_not_reached ();
6398 icon_info->storage_type = GTK_IMAGE_EMPTY;
6399 g_object_notify (G_OBJECT (entry),
6400 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-storage-type" : "secondary-icon-storage-type");
6402 g_object_thaw_notify (G_OBJECT (entry));
6406 gtk_entry_ensure_pixbuf (GtkEntry *entry,
6407 GtkEntryIconPosition icon_pos)
6409 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
6410 EntryIconInfo *icon_info = priv->icons[icon_pos];
6412 GtkIconTheme *icon_theme;
6413 GtkSettings *settings;
6418 if (!icon_info || icon_info->pixbuf)
6421 switch (icon_info->storage_type)
6423 case GTK_IMAGE_EMPTY:
6424 case GTK_IMAGE_PIXBUF:
6426 case GTK_IMAGE_STOCK:
6427 state = GTK_WIDGET_STATE (entry);
6428 GTK_WIDGET_STATE (entry) = GTK_STATE_NORMAL;
6429 icon_info->pixbuf = gtk_widget_render_icon (GTK_WIDGET (entry),
6430 icon_info->stock_id,
6433 if (!icon_info->pixbuf)
6434 icon_info->pixbuf = gtk_widget_render_icon (GTK_WIDGET (entry),
6435 GTK_STOCK_MISSING_IMAGE,
6438 GTK_WIDGET_STATE (entry) = state;
6441 case GTK_IMAGE_ICON_NAME:
6442 screen = gtk_widget_get_screen (GTK_WIDGET (entry));
6445 icon_theme = gtk_icon_theme_get_for_screen (screen);
6446 settings = gtk_settings_get_for_screen (screen);
6448 gtk_icon_size_lookup_for_settings (settings,
6452 icon_info->pixbuf = gtk_icon_theme_load_icon (icon_theme,
6453 icon_info->icon_name,
6454 MIN (width, height),
6457 if (icon_info->pixbuf == NULL)
6459 state = GTK_WIDGET_STATE (entry);
6460 GTK_WIDGET_STATE (entry) = GTK_STATE_NORMAL;
6461 icon_info->pixbuf = gtk_widget_render_icon (GTK_WIDGET (entry),
6462 GTK_STOCK_MISSING_IMAGE,
6465 GTK_WIDGET_STATE (entry) = state;
6470 case GTK_IMAGE_GICON:
6471 screen = gtk_widget_get_screen (GTK_WIDGET (entry));
6474 icon_theme = gtk_icon_theme_get_for_screen (screen);
6475 settings = gtk_settings_get_for_screen (screen);
6477 gtk_icon_size_lookup_for_settings (settings,
6481 info = gtk_icon_theme_lookup_by_gicon (icon_theme,
6483 MIN (width, height),
6484 GTK_ICON_LOOKUP_USE_BUILTIN);
6487 icon_info->pixbuf = gtk_icon_info_load_icon (info, NULL);
6488 gtk_icon_info_free (info);
6491 if (icon_info->pixbuf == NULL)
6493 state = GTK_WIDGET_STATE (entry);
6494 GTK_WIDGET_STATE (entry) = GTK_STATE_NORMAL;
6495 icon_info->pixbuf = gtk_widget_render_icon (GTK_WIDGET (entry),
6496 GTK_STOCK_MISSING_IMAGE,
6499 GTK_WIDGET_STATE (entry) = state;
6505 g_assert_not_reached ();
6509 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
6510 gdk_window_show_unraised (icon_info->window);
6520 * Creates a new entry.
6522 * Return value: a new #GtkEntry.
6525 gtk_entry_new (void)
6527 return g_object_new (GTK_TYPE_ENTRY, NULL);
6531 * gtk_entry_new_with_buffer:
6532 * @buffer: The buffer to use for the new #GtkEntry.
6534 * Creates a new entry with the specified text buffer.
6536 * Return value: a new #GtkEntry
6541 gtk_entry_new_with_buffer (GtkEntryBuffer *buffer)
6543 g_return_val_if_fail (GTK_IS_ENTRY_BUFFER (buffer), NULL);
6544 return g_object_new (GTK_TYPE_ENTRY, "buffer", buffer, NULL);
6548 * gtk_entry_new_with_max_length:
6549 * @max: the maximum length of the entry, or 0 for no maximum.
6550 * (other than the maximum length of entries.) The value passed in will
6551 * be clamped to the range 0-65536.
6553 * Creates a new #GtkEntry widget with the given maximum length.
6555 * Return value: a new #GtkEntry
6557 * Deprecated: Use gtk_entry_set_max_length() instead.
6560 gtk_entry_new_with_max_length (gint max)
6564 max = CLAMP (max, 0, GTK_ENTRY_BUFFER_MAX_SIZE);
6566 entry = g_object_new (GTK_TYPE_ENTRY, NULL);
6567 gtk_entry_buffer_set_max_length (get_buffer (entry), max);
6569 return GTK_WIDGET (entry);
6573 static GtkEntryBuffer*
6574 get_buffer (GtkEntry *entry)
6576 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
6578 if (priv->buffer == NULL)
6580 GtkEntryBuffer *buffer;
6581 buffer = gtk_entry_buffer_new (NULL, 0);
6582 gtk_entry_set_buffer (entry, buffer);
6583 g_object_unref (buffer);
6586 return priv->buffer;
6590 * gtk_entry_get_buffer:
6591 * @entry: a #GtkEntry
6593 * Get the #GtkEntryBuffer object which holds the text for
6598 * Returns: A #GtkEntryBuffer object.
6601 gtk_entry_get_buffer (GtkEntry *entry)
6603 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
6605 return get_buffer (entry);
6609 * gtk_entry_set_buffer:
6610 * @entry: a #GtkEntry
6611 * @buffer: a #GtkEntryBuffer
6613 * Set the #GtkEntryBuffer object which holds the text for
6619 gtk_entry_set_buffer (GtkEntry *entry,
6620 GtkEntryBuffer *buffer)
6622 GtkEntryPrivate *priv;
6625 g_return_if_fail (GTK_IS_ENTRY (entry));
6626 priv = GTK_ENTRY_GET_PRIVATE (entry);
6630 g_return_if_fail (GTK_IS_ENTRY_BUFFER (buffer));
6631 g_object_ref (buffer);
6636 buffer_disconnect_signals (entry);
6637 g_object_unref (priv->buffer);
6639 /* COMPAT: Deprecated. Not used. Setting these fields no longer necessary in GTK 3.x */
6641 entry->text_length = 0;
6642 entry->text_max_length = 0;
6645 priv->buffer = buffer;
6649 buffer_connect_signals (entry);
6651 /* COMPAT: Deprecated. Not used. Setting these fields no longer necessary in GTK 3.x */
6652 entry->text = (char*)gtk_entry_buffer_get_text (priv->buffer);
6653 entry->text_length = gtk_entry_buffer_get_length (priv->buffer);
6654 entry->text_max_length = gtk_entry_buffer_get_max_length (priv->buffer);
6657 obj = G_OBJECT (entry);
6658 g_object_freeze_notify (obj);
6659 g_object_notify (obj, "buffer");
6660 g_object_notify (obj, "text");
6661 g_object_notify (obj, "text-length");
6662 g_object_notify (obj, "max-length");
6663 g_object_notify (obj, "visibility");
6664 g_object_notify (obj, "invisible-char");
6665 g_object_notify (obj, "invisible-char-set");
6666 g_object_thaw_notify (obj);
6671 * gtk_entry_set_text:
6672 * @entry: a #GtkEntry
6673 * @text: the new text
6675 * Sets the text in the widget to the given
6676 * value, replacing the current contents.
6678 * See gtk_entry_buffer_set_text().
6681 gtk_entry_set_text (GtkEntry *entry,
6685 GtkEntryCompletion *completion;
6686 GtkEntryPrivate *priv;
6688 g_return_if_fail (GTK_IS_ENTRY (entry));
6689 g_return_if_fail (text != NULL);
6690 priv = GTK_ENTRY_GET_PRIVATE (entry);
6692 /* Actually setting the text will affect the cursor and selection;
6693 * if the contents don't actually change, this will look odd to the user.
6695 if (strcmp (gtk_entry_buffer_get_text (get_buffer (entry)), text) == 0)
6698 completion = gtk_entry_get_completion (entry);
6699 if (completion && completion->priv->changed_id > 0)
6700 g_signal_handler_block (entry, completion->priv->changed_id);
6702 begin_change (entry);
6703 g_object_freeze_notify (G_OBJECT (entry));
6704 gtk_editable_delete_text (GTK_EDITABLE (entry), 0, -1);
6706 gtk_editable_insert_text (GTK_EDITABLE (entry), text, strlen (text), &tmp_pos);
6707 g_object_thaw_notify (G_OBJECT (entry));
6710 if (completion && completion->priv->changed_id > 0)
6711 g_signal_handler_unblock (entry, completion->priv->changed_id);
6715 * gtk_entry_append_text:
6716 * @entry: a #GtkEntry
6717 * @text: the text to append
6719 * Appends the given text to the contents of the widget.
6721 * Deprecated: 2.0: Use gtk_editable_insert_text() instead.
6724 gtk_entry_append_text (GtkEntry *entry,
6727 GtkEntryPrivate *priv;
6730 g_return_if_fail (GTK_IS_ENTRY (entry));
6731 g_return_if_fail (text != NULL);
6732 priv = GTK_ENTRY_GET_PRIVATE (entry);
6734 tmp_pos = gtk_entry_buffer_get_length (get_buffer (entry));
6735 gtk_editable_insert_text (GTK_EDITABLE (entry), text, -1, &tmp_pos);
6739 * gtk_entry_prepend_text:
6740 * @entry: a #GtkEntry
6741 * @text: the text to prepend
6743 * Prepends the given text to the contents of the widget.
6745 * Deprecated: 2.0: Use gtk_editable_insert_text() instead.
6748 gtk_entry_prepend_text (GtkEntry *entry,
6753 g_return_if_fail (GTK_IS_ENTRY (entry));
6754 g_return_if_fail (text != NULL);
6757 gtk_editable_insert_text (GTK_EDITABLE (entry), text, -1, &tmp_pos);
6761 * gtk_entry_set_position:
6762 * @entry: a #GtkEntry
6763 * @position: the position of the cursor. The cursor is displayed
6764 * before the character with the given (base 0) index in the widget.
6765 * The value must be less than or equal to the number of characters
6766 * in the widget. A value of -1 indicates that the position should
6767 * be set after the last character in the entry. Note that this
6768 * position is in characters, not in bytes.
6770 * Sets the cursor position in an entry to the given value.
6772 * Deprecated: 2.0: Use gtk_editable_set_position() instead.
6775 gtk_entry_set_position (GtkEntry *entry,
6778 g_return_if_fail (GTK_IS_ENTRY (entry));
6780 gtk_editable_set_position (GTK_EDITABLE (entry), position);
6784 * gtk_entry_set_visibility:
6785 * @entry: a #GtkEntry
6786 * @visible: %TRUE if the contents of the entry are displayed
6789 * Sets whether the contents of the entry are visible or not.
6790 * When visibility is set to %FALSE, characters are displayed
6791 * as the invisible char, and will also appear that way when
6792 * the text in the entry widget is copied elsewhere.
6794 * By default, GTK+ picks the best invisible character available
6795 * in the current font, but it can be changed with
6796 * gtk_entry_set_invisible_char().
6799 gtk_entry_set_visibility (GtkEntry *entry,
6802 g_return_if_fail (GTK_IS_ENTRY (entry));
6804 visible = visible != FALSE;
6806 if (entry->visible != visible)
6808 entry->visible = visible;
6810 g_object_notify (G_OBJECT (entry), "visibility");
6811 gtk_entry_recompute (entry);
6816 * gtk_entry_get_visibility:
6817 * @entry: a #GtkEntry
6819 * Retrieves whether the text in @entry is visible. See
6820 * gtk_entry_set_visibility().
6822 * Return value: %TRUE if the text is currently visible
6825 gtk_entry_get_visibility (GtkEntry *entry)
6827 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
6829 return entry->visible;
6833 * gtk_entry_set_invisible_char:
6834 * @entry: a #GtkEntry
6835 * @ch: a Unicode character
6837 * Sets the character to use in place of the actual text when
6838 * gtk_entry_set_visibility() has been called to set text visibility
6839 * to %FALSE. i.e. this is the character used in "password mode" to
6840 * show the user how many characters have been typed. By default, GTK+
6841 * picks the best invisible char available in the current font. If you
6842 * set the invisible char to 0, then the user will get no feedback
6843 * at all; there will be no text on the screen as they type.
6846 gtk_entry_set_invisible_char (GtkEntry *entry,
6849 GtkEntryPrivate *priv;
6851 g_return_if_fail (GTK_IS_ENTRY (entry));
6853 priv = GTK_ENTRY_GET_PRIVATE (entry);
6855 if (!priv->invisible_char_set)
6857 priv->invisible_char_set = TRUE;
6858 g_object_notify (G_OBJECT (entry), "invisible-char-set");
6861 if (ch == entry->invisible_char)
6864 entry->invisible_char = ch;
6865 g_object_notify (G_OBJECT (entry), "invisible-char");
6866 gtk_entry_recompute (entry);
6870 * gtk_entry_get_invisible_char:
6871 * @entry: a #GtkEntry
6873 * Retrieves the character displayed in place of the real characters
6874 * for entries with visibility set to false. See gtk_entry_set_invisible_char().
6876 * Return value: the current invisible char, or 0, if the entry does not
6877 * show invisible text at all.
6880 gtk_entry_get_invisible_char (GtkEntry *entry)
6882 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
6884 return entry->invisible_char;
6888 * gtk_entry_unset_invisible_char:
6889 * @entry: a #GtkEntry
6891 * Unsets the invisible char previously set with
6892 * gtk_entry_set_invisible_char(). So that the
6893 * default invisible char is used again.
6898 gtk_entry_unset_invisible_char (GtkEntry *entry)
6900 GtkEntryPrivate *priv;
6903 g_return_if_fail (GTK_IS_ENTRY (entry));
6905 priv = GTK_ENTRY_GET_PRIVATE (entry);
6907 if (!priv->invisible_char_set)
6910 priv->invisible_char_set = FALSE;
6911 ch = find_invisible_char (GTK_WIDGET (entry));
6913 if (entry->invisible_char != ch)
6915 entry->invisible_char = ch;
6916 g_object_notify (G_OBJECT (entry), "invisible-char");
6919 g_object_notify (G_OBJECT (entry), "invisible-char-set");
6920 gtk_entry_recompute (entry);
6924 * gtk_entry_set_editable:
6925 * @entry: a #GtkEntry
6926 * @editable: %TRUE if the user is allowed to edit the text
6929 * Determines if the user can edit the text in the editable
6932 * Deprecated: 2.0: Use gtk_editable_set_editable() instead.
6935 gtk_entry_set_editable (GtkEntry *entry,
6938 g_return_if_fail (GTK_IS_ENTRY (entry));
6940 gtk_editable_set_editable (GTK_EDITABLE (entry), editable);
6944 * gtk_entry_set_overwrite_mode:
6945 * @entry: a #GtkEntry
6946 * @overwrite: new value
6948 * Sets whether the text is overwritten when typing in the #GtkEntry.
6953 gtk_entry_set_overwrite_mode (GtkEntry *entry,
6956 g_return_if_fail (GTK_IS_ENTRY (entry));
6958 if (entry->overwrite_mode == overwrite)
6961 gtk_entry_toggle_overwrite (entry);
6963 g_object_notify (G_OBJECT (entry), "overwrite-mode");
6967 * gtk_entry_get_overwrite_mode:
6968 * @entry: a #GtkEntry
6970 * Gets the value set by gtk_entry_set_overwrite_mode().
6972 * Return value: whether the text is overwritten when typing.
6977 gtk_entry_get_overwrite_mode (GtkEntry *entry)
6979 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
6981 return entry->overwrite_mode;
6985 * gtk_entry_get_text:
6986 * @entry: a #GtkEntry
6988 * Retrieves the contents of the entry widget.
6989 * See also gtk_editable_get_chars().
6991 * This is equivalent to:
6993 * <informalexample><programlisting>
6994 * gtk_entry_buffer_get_text (gtk_entry_get_buffer (entry));
6995 * </programlisting></informalexample>
6997 * Return value: a pointer to the contents of the widget as a
6998 * string. This string points to internally allocated
6999 * storage in the widget and must not be freed, modified or
7002 G_CONST_RETURN gchar*
7003 gtk_entry_get_text (GtkEntry *entry)
7005 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7006 return gtk_entry_buffer_get_text (get_buffer (entry));
7010 * gtk_entry_select_region:
7011 * @entry: a #GtkEntry
7012 * @start: the starting position
7013 * @end: the end position
7015 * Selects a region of text. The characters that are selected are
7016 * those characters at positions from @start_pos up to, but not
7017 * including @end_pos. If @end_pos is negative, then the the characters
7018 * selected will be those characters from @start_pos to the end of
7021 * Deprecated: 2.0: Use gtk_editable_select_region() instead.
7024 gtk_entry_select_region (GtkEntry *entry,
7028 gtk_editable_select_region (GTK_EDITABLE (entry), start, end);
7032 * gtk_entry_set_max_length:
7033 * @entry: a #GtkEntry
7034 * @max: the maximum length of the entry, or 0 for no maximum.
7035 * (other than the maximum length of entries.) The value passed in will
7036 * be clamped to the range 0-65536.
7038 * Sets the maximum allowed length of the contents of the widget. If
7039 * the current contents are longer than the given length, then they
7040 * will be truncated to fit.
7042 * This is equivalent to:
7044 * <informalexample><programlisting>
7045 * gtk_entry_buffer_set_max_length (gtk_entry_get_buffer (entry), max);
7046 * </programlisting></informalexample>
7049 gtk_entry_set_max_length (GtkEntry *entry,
7052 g_return_if_fail (GTK_IS_ENTRY (entry));
7053 gtk_entry_buffer_set_max_length (get_buffer (entry), max);
7057 * gtk_entry_get_max_length:
7058 * @entry: a #GtkEntry
7060 * Retrieves the maximum allowed length of the text in
7061 * @entry. See gtk_entry_set_max_length().
7063 * This is equivalent to:
7065 * <informalexample><programlisting>
7066 * gtk_entry_buffer_get_max_length (gtk_entry_get_buffer (entry));
7067 * </programlisting></informalexample>
7069 * Return value: the maximum allowed number of characters
7070 * in #GtkEntry, or 0 if there is no maximum.
7073 gtk_entry_get_max_length (GtkEntry *entry)
7075 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7076 return gtk_entry_buffer_get_max_length (get_buffer (entry));
7080 * gtk_entry_get_text_length:
7081 * @entry: a #GtkEntry
7083 * Retrieves the current length of the text in
7086 * This is equivalent to:
7088 * <informalexample><programlisting>
7089 * gtk_entry_buffer_get_length (gtk_entry_get_buffer (entry));
7090 * </programlisting></informalexample>
7092 * Return value: the current number of characters
7093 * in #GtkEntry, or 0 if there are none.
7098 gtk_entry_get_text_length (GtkEntry *entry)
7100 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7101 return gtk_entry_buffer_get_length (get_buffer (entry));
7105 * gtk_entry_set_activates_default:
7106 * @entry: a #GtkEntry
7107 * @setting: %TRUE to activate window's default widget on Enter keypress
7109 * If @setting is %TRUE, pressing Enter in the @entry will activate the default
7110 * widget for the window containing the entry. This usually means that
7111 * the dialog box containing the entry will be closed, since the default
7112 * widget is usually one of the dialog buttons.
7114 * (For experts: if @setting is %TRUE, the entry calls
7115 * gtk_window_activate_default() on the window containing the entry, in
7116 * the default handler for the #GtkWidget::activate signal.)
7119 gtk_entry_set_activates_default (GtkEntry *entry,
7122 g_return_if_fail (GTK_IS_ENTRY (entry));
7123 setting = setting != FALSE;
7125 if (setting != entry->activates_default)
7127 entry->activates_default = setting;
7128 g_object_notify (G_OBJECT (entry), "activates-default");
7133 * gtk_entry_get_activates_default:
7134 * @entry: a #GtkEntry
7136 * Retrieves the value set by gtk_entry_set_activates_default().
7138 * Return value: %TRUE if the entry will activate the default widget
7141 gtk_entry_get_activates_default (GtkEntry *entry)
7143 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7145 return entry->activates_default;
7149 * gtk_entry_set_width_chars:
7150 * @entry: a #GtkEntry
7151 * @n_chars: width in chars
7153 * Changes the size request of the entry to be about the right size
7154 * for @n_chars characters. Note that it changes the size
7155 * <emphasis>request</emphasis>, the size can still be affected by
7156 * how you pack the widget into containers. If @n_chars is -1, the
7157 * size reverts to the default entry size.
7160 gtk_entry_set_width_chars (GtkEntry *entry,
7163 g_return_if_fail (GTK_IS_ENTRY (entry));
7165 if (entry->width_chars != n_chars)
7167 entry->width_chars = n_chars;
7168 g_object_notify (G_OBJECT (entry), "width-chars");
7169 gtk_widget_queue_resize (GTK_WIDGET (entry));
7174 * gtk_entry_get_width_chars:
7175 * @entry: a #GtkEntry
7177 * Gets the value set by gtk_entry_set_width_chars().
7179 * Return value: number of chars to request space for, or negative if unset
7182 gtk_entry_get_width_chars (GtkEntry *entry)
7184 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7186 return entry->width_chars;
7190 * gtk_entry_set_has_frame:
7191 * @entry: a #GtkEntry
7192 * @setting: new value
7194 * Sets whether the entry has a beveled frame around it.
7197 gtk_entry_set_has_frame (GtkEntry *entry,
7200 g_return_if_fail (GTK_IS_ENTRY (entry));
7202 setting = (setting != FALSE);
7204 if (entry->has_frame == setting)
7207 gtk_widget_queue_resize (GTK_WIDGET (entry));
7208 entry->has_frame = setting;
7209 g_object_notify (G_OBJECT (entry), "has-frame");
7213 * gtk_entry_get_has_frame:
7214 * @entry: a #GtkEntry
7216 * Gets the value set by gtk_entry_set_has_frame().
7218 * Return value: whether the entry has a beveled frame
7221 gtk_entry_get_has_frame (GtkEntry *entry)
7223 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7225 return entry->has_frame;
7229 * gtk_entry_set_inner_border:
7230 * @entry: a #GtkEntry
7231 * @border: a #GtkBorder, or %NULL
7233 * Sets %entry's inner-border property to %border, or clears it if %NULL
7234 * is passed. The inner-border is the area around the entry's text, but
7237 * If set, this property overrides the inner-border style property.
7238 * Overriding the style-provided border is useful when you want to do
7239 * in-place editing of some text in a canvas or list widget, where
7240 * pixel-exact positioning of the entry is important.
7245 gtk_entry_set_inner_border (GtkEntry *entry,
7246 const GtkBorder *border)
7248 g_return_if_fail (GTK_IS_ENTRY (entry));
7250 gtk_widget_queue_resize (GTK_WIDGET (entry));
7253 g_object_set_qdata_full (G_OBJECT (entry), quark_inner_border,
7254 gtk_border_copy (border),
7255 (GDestroyNotify) gtk_border_free);
7257 g_object_set_qdata (G_OBJECT (entry), quark_inner_border, NULL);
7259 g_object_notify (G_OBJECT (entry), "inner-border");
7263 * gtk_entry_get_inner_border:
7264 * @entry: a #GtkEntry
7266 * This function returns the entry's #GtkEntry:inner-border property. See
7267 * gtk_entry_set_inner_border() for more information.
7269 * Return value: the entry's #GtkBorder, or %NULL if none was set.
7273 G_CONST_RETURN GtkBorder *
7274 gtk_entry_get_inner_border (GtkEntry *entry)
7276 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7278 return g_object_get_qdata (G_OBJECT (entry), quark_inner_border);
7282 * gtk_entry_get_layout:
7283 * @entry: a #GtkEntry
7285 * Gets the #PangoLayout used to display the entry.
7286 * The layout is useful to e.g. convert text positions to
7287 * pixel positions, in combination with gtk_entry_get_layout_offsets().
7288 * The returned layout is owned by the entry and must not be
7289 * modified or freed by the caller.
7291 * Keep in mind that the layout text may contain a preedit string, so
7292 * gtk_entry_layout_index_to_text_index() and
7293 * gtk_entry_text_index_to_layout_index() are needed to convert byte
7294 * indices in the layout to byte indices in the entry contents.
7296 * Return value: the #PangoLayout for this entry
7299 gtk_entry_get_layout (GtkEntry *entry)
7301 PangoLayout *layout;
7303 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7305 layout = gtk_entry_ensure_layout (entry, TRUE);
7312 * gtk_entry_layout_index_to_text_index:
7313 * @entry: a #GtkEntry
7314 * @layout_index: byte index into the entry layout text
7316 * Converts from a position in the entry contents (returned
7317 * by gtk_entry_get_text()) to a position in the
7318 * entry's #PangoLayout (returned by gtk_entry_get_layout(),
7319 * with text retrieved via pango_layout_get_text()).
7321 * Return value: byte index into the entry contents
7324 gtk_entry_layout_index_to_text_index (GtkEntry *entry,
7327 PangoLayout *layout;
7331 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7333 layout = gtk_entry_ensure_layout (entry, TRUE);
7334 text = pango_layout_get_text (layout);
7335 cursor_index = g_utf8_offset_to_pointer (text, entry->current_pos) - text;
7337 if (layout_index >= cursor_index && entry->preedit_length)
7339 if (layout_index >= cursor_index + entry->preedit_length)
7340 layout_index -= entry->preedit_length;
7342 layout_index = cursor_index;
7345 return layout_index;
7349 * gtk_entry_text_index_to_layout_index:
7350 * @entry: a #GtkEntry
7351 * @text_index: byte index into the entry contents
7353 * Converts from a position in the entry's #PangoLayout (returned by
7354 * gtk_entry_get_layout()) to a position in the entry contents
7355 * (returned by gtk_entry_get_text()).
7357 * Return value: byte index into the entry layout text
7360 gtk_entry_text_index_to_layout_index (GtkEntry *entry,
7363 PangoLayout *layout;
7366 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7368 layout = gtk_entry_ensure_layout (entry, TRUE);
7369 text = pango_layout_get_text (layout);
7370 cursor_index = g_utf8_offset_to_pointer (text, entry->current_pos) - text;
7372 if (text_index > cursor_index)
7373 text_index += entry->preedit_length;
7379 * gtk_entry_get_layout_offsets:
7380 * @entry: a #GtkEntry
7381 * @x: location to store X offset of layout, or %NULL
7382 * @y: location to store Y offset of layout, or %NULL
7385 * Obtains the position of the #PangoLayout used to render text
7386 * in the entry, in widget coordinates. Useful if you want to line
7387 * up the text in an entry with some other text, e.g. when using the
7388 * entry to implement editable cells in a sheet widget.
7390 * Also useful to convert mouse events into coordinates inside the
7391 * #PangoLayout, e.g. to take some action if some part of the entry text
7394 * Note that as the user scrolls around in the entry the offsets will
7395 * change; you'll need to connect to the "notify::scroll-offset"
7396 * signal to track this. Remember when using the #PangoLayout
7397 * functions you need to convert to and from pixels using
7398 * PANGO_PIXELS() or #PANGO_SCALE.
7400 * Keep in mind that the layout text may contain a preedit string, so
7401 * gtk_entry_layout_index_to_text_index() and
7402 * gtk_entry_text_index_to_layout_index() are needed to convert byte
7403 * indices in the layout to byte indices in the entry contents.
7406 gtk_entry_get_layout_offsets (GtkEntry *entry,
7410 gint text_area_x, text_area_y;
7412 g_return_if_fail (GTK_IS_ENTRY (entry));
7414 /* this gets coords relative to text area */
7415 get_layout_position (entry, x, y);
7417 /* convert to widget coords */
7418 gtk_entry_get_text_area_size (entry, &text_area_x, &text_area_y, NULL, NULL);
7429 * gtk_entry_set_alignment:
7430 * @entry: a #GtkEntry
7431 * @xalign: The horizontal alignment, from 0 (left) to 1 (right).
7432 * Reversed for RTL layouts
7434 * Sets the alignment for the contents of the entry. This controls
7435 * the horizontal positioning of the contents when the displayed
7436 * text is shorter than the width of the entry.
7441 gtk_entry_set_alignment (GtkEntry *entry, gfloat xalign)
7443 GtkEntryPrivate *priv;
7445 g_return_if_fail (GTK_IS_ENTRY (entry));
7447 priv = GTK_ENTRY_GET_PRIVATE (entry);
7451 else if (xalign > 1.0)
7454 if (xalign != priv->xalign)
7456 priv->xalign = xalign;
7458 gtk_entry_recompute (entry);
7460 g_object_notify (G_OBJECT (entry), "xalign");
7465 * gtk_entry_get_alignment:
7466 * @entry: a #GtkEntry
7468 * Gets the value set by gtk_entry_set_alignment().
7470 * Return value: the alignment
7475 gtk_entry_get_alignment (GtkEntry *entry)
7477 GtkEntryPrivate *priv;
7479 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
7481 priv = GTK_ENTRY_GET_PRIVATE (entry);
7483 return priv->xalign;
7487 * gtk_entry_set_icon_from_pixbuf:
7488 * @entry: a #GtkEntry
7489 * @icon_pos: Icon position
7490 * @pixbuf: A #GdkPixbuf, or %NULL
7492 * Sets the icon shown in the specified position using a pixbuf.
7494 * If @pixbuf is %NULL, no icon will be shown in the specified position.
7499 gtk_entry_set_icon_from_pixbuf (GtkEntry *entry,
7500 GtkEntryIconPosition icon_pos,
7503 GtkEntryPrivate *priv;
7504 EntryIconInfo *icon_info;
7506 g_return_if_fail (GTK_IS_ENTRY (entry));
7507 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7509 priv = GTK_ENTRY_GET_PRIVATE (entry);
7511 if ((icon_info = priv->icons[icon_pos]) == NULL)
7512 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7514 g_object_freeze_notify (G_OBJECT (entry));
7517 g_object_ref (pixbuf);
7519 gtk_entry_clear (entry, icon_pos);
7523 icon_info->storage_type = GTK_IMAGE_PIXBUF;
7524 icon_info->pixbuf = pixbuf;
7526 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7528 g_object_notify (G_OBJECT (entry), "primary-icon-pixbuf");
7529 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7533 g_object_notify (G_OBJECT (entry), "secondary-icon-pixbuf");
7534 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7537 if (GTK_WIDGET_MAPPED (entry))
7538 gdk_window_show_unraised (icon_info->window);
7541 gtk_entry_ensure_pixbuf (entry, icon_pos);
7543 if (GTK_WIDGET_VISIBLE (entry))
7544 gtk_widget_queue_resize (GTK_WIDGET (entry));
7546 g_object_thaw_notify (G_OBJECT (entry));
7550 * gtk_entry_set_icon_from_stock:
7551 * @entry: A #GtkEntry
7552 * @icon_pos: Icon position
7553 * @stock_id: The name of the stock item, or %NULL
7555 * Sets the icon shown in the entry at the specified position from
7558 * If @stock_id is %NULL, no icon will be shown in the specified position.
7563 gtk_entry_set_icon_from_stock (GtkEntry *entry,
7564 GtkEntryIconPosition icon_pos,
7565 const gchar *stock_id)
7567 GtkEntryPrivate *priv;
7568 EntryIconInfo *icon_info;
7571 g_return_if_fail (GTK_IS_ENTRY (entry));
7572 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7574 priv = GTK_ENTRY_GET_PRIVATE (entry);
7576 if ((icon_info = priv->icons[icon_pos]) == NULL)
7577 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7579 g_object_freeze_notify (G_OBJECT (entry));
7581 gtk_widget_ensure_style (GTK_WIDGET (entry));
7583 /* need to dup before clearing */
7584 new_id = g_strdup (stock_id);
7586 gtk_entry_clear (entry, icon_pos);
7590 icon_info->storage_type = GTK_IMAGE_STOCK;
7591 icon_info->stock_id = new_id;
7593 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7595 g_object_notify (G_OBJECT (entry), "primary-icon-stock");
7596 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7600 g_object_notify (G_OBJECT (entry), "secondary-icon-stock");
7601 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7604 if (GTK_WIDGET_MAPPED (entry))
7605 gdk_window_show_unraised (icon_info->window);
7608 gtk_entry_ensure_pixbuf (entry, icon_pos);
7610 if (GTK_WIDGET_VISIBLE (entry))
7611 gtk_widget_queue_resize (GTK_WIDGET (entry));
7613 g_object_thaw_notify (G_OBJECT (entry));
7617 * gtk_entry_set_icon_from_icon_name:
7618 * @entry: A #GtkEntry
7619 * @icon_pos: The position at which to set the icon
7620 * @icon_name: An icon name, or %NULL
7622 * Sets the icon shown in the entry at the specified position
7623 * from the current icon theme.
7625 * If the icon name isn't known, a "broken image" icon will be displayed
7628 * If @icon_name is %NULL, no icon will be shown in the specified position.
7633 gtk_entry_set_icon_from_icon_name (GtkEntry *entry,
7634 GtkEntryIconPosition icon_pos,
7635 const gchar *icon_name)
7637 GtkEntryPrivate *priv;
7638 EntryIconInfo *icon_info;
7641 g_return_if_fail (GTK_IS_ENTRY (entry));
7642 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7644 priv = GTK_ENTRY_GET_PRIVATE (entry);
7646 if ((icon_info = priv->icons[icon_pos]) == NULL)
7647 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7649 g_object_freeze_notify (G_OBJECT (entry));
7651 gtk_widget_ensure_style (GTK_WIDGET (entry));
7653 /* need to dup before clearing */
7654 new_name = g_strdup (icon_name);
7656 gtk_entry_clear (entry, icon_pos);
7658 if (new_name != NULL)
7660 icon_info->storage_type = GTK_IMAGE_ICON_NAME;
7661 icon_info->icon_name = new_name;
7663 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7665 g_object_notify (G_OBJECT (entry), "primary-icon-name");
7666 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7670 g_object_notify (G_OBJECT (entry), "secondary-icon-name");
7671 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7674 if (GTK_WIDGET_MAPPED (entry))
7675 gdk_window_show_unraised (icon_info->window);
7678 gtk_entry_ensure_pixbuf (entry, icon_pos);
7680 if (GTK_WIDGET_VISIBLE (entry))
7681 gtk_widget_queue_resize (GTK_WIDGET (entry));
7683 g_object_thaw_notify (G_OBJECT (entry));
7687 * gtk_entry_set_icon_from_gicon:
7688 * @entry: A #GtkEntry
7689 * @icon_pos: The position at which to set the icon
7690 * @icon: The icon to set, or %NULL
7692 * Sets the icon shown in the entry at the specified position
7693 * from the current icon theme.
7694 * If the icon isn't known, a "broken image" icon will be displayed
7697 * If @icon is %NULL, no icon will be shown in the specified position.
7702 gtk_entry_set_icon_from_gicon (GtkEntry *entry,
7703 GtkEntryIconPosition icon_pos,
7706 GtkEntryPrivate *priv;
7707 EntryIconInfo *icon_info;
7709 g_return_if_fail (GTK_IS_ENTRY (entry));
7710 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7712 priv = GTK_ENTRY_GET_PRIVATE (entry);
7714 if ((icon_info = priv->icons[icon_pos]) == NULL)
7715 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7717 g_object_freeze_notify (G_OBJECT (entry));
7719 /* need to ref before clearing */
7721 g_object_ref (icon);
7723 gtk_entry_clear (entry, icon_pos);
7727 icon_info->storage_type = GTK_IMAGE_GICON;
7728 icon_info->gicon = icon;
7730 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7732 g_object_notify (G_OBJECT (entry), "primary-icon-gicon");
7733 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7737 g_object_notify (G_OBJECT (entry), "secondary-icon-gicon");
7738 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7741 if (GTK_WIDGET_MAPPED (entry))
7742 gdk_window_show_unraised (icon_info->window);
7745 gtk_entry_ensure_pixbuf (entry, icon_pos);
7747 if (GTK_WIDGET_VISIBLE (entry))
7748 gtk_widget_queue_resize (GTK_WIDGET (entry));
7750 g_object_thaw_notify (G_OBJECT (entry));
7754 * gtk_entry_set_icon_activatable:
7755 * @entry: A #GtkEntry
7756 * @icon_pos: Icon position
7757 * @activatable: %TRUE if the icon should be activatable
7759 * Sets whether the icon is activatable.
7764 gtk_entry_set_icon_activatable (GtkEntry *entry,
7765 GtkEntryIconPosition icon_pos,
7766 gboolean activatable)
7768 GtkEntryPrivate *priv;
7769 EntryIconInfo *icon_info;
7771 g_return_if_fail (GTK_IS_ENTRY (entry));
7772 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7774 priv = GTK_ENTRY_GET_PRIVATE (entry);
7776 if ((icon_info = priv->icons[icon_pos]) == NULL)
7777 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7779 activatable = activatable != FALSE;
7781 if (icon_info->nonactivatable != !activatable)
7783 icon_info->nonactivatable = !activatable;
7785 if (GTK_WIDGET_REALIZED (GTK_WIDGET (entry)))
7786 update_cursors (GTK_WIDGET (entry));
7788 g_object_notify (G_OBJECT (entry),
7789 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-activatable" : "secondary-icon-activatable");
7794 * gtk_entry_get_icon_activatable:
7795 * @entry: a #GtkEntry
7796 * @icon_pos: Icon position
7798 * Returns whether the icon is activatable.
7800 * Returns: %TRUE if the icon is activatable.
7805 gtk_entry_get_icon_activatable (GtkEntry *entry,
7806 GtkEntryIconPosition icon_pos)
7808 GtkEntryPrivate *priv;
7809 EntryIconInfo *icon_info;
7811 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7812 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), FALSE);
7814 priv = GTK_ENTRY_GET_PRIVATE (entry);
7815 icon_info = priv->icons[icon_pos];
7817 return (icon_info != NULL && !icon_info->nonactivatable);
7821 * gtk_entry_get_icon_pixbuf:
7822 * @entry: A #GtkEntry
7823 * @icon_pos: Icon position
7825 * Retrieves the image used for the icon.
7827 * Unlike the other methods of setting and getting icon data, this
7828 * method will work regardless of whether the icon was set using a
7829 * #GdkPixbuf, a #GIcon, a stock item, or an icon name.
7831 * Returns: A #GdkPixbuf, or %NULL if no icon is set for this position.
7836 gtk_entry_get_icon_pixbuf (GtkEntry *entry,
7837 GtkEntryIconPosition icon_pos)
7839 GtkEntryPrivate *priv;
7840 EntryIconInfo *icon_info;
7842 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7843 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7845 priv = GTK_ENTRY_GET_PRIVATE (entry);
7846 icon_info = priv->icons[icon_pos];
7851 gtk_entry_ensure_pixbuf (entry, icon_pos);
7853 return icon_info->pixbuf;
7857 * gtk_entry_get_icon_gicon:
7858 * @entry: A #GtkEntry
7859 * @icon_pos: Icon position
7861 * Retrieves the #GIcon used for the icon, or %NULL if there is
7862 * no icon or if the icon was set by some other method (e.g., by
7863 * stock, pixbuf, or icon name).
7865 * Returns: A #GIcon, or %NULL if no icon is set or if the icon
7871 gtk_entry_get_icon_gicon (GtkEntry *entry,
7872 GtkEntryIconPosition icon_pos)
7874 GtkEntryPrivate *priv;
7875 EntryIconInfo *icon_info;
7877 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7878 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7880 priv = GTK_ENTRY_GET_PRIVATE (entry);
7881 icon_info = priv->icons[icon_pos];
7886 return icon_info->storage_type == GTK_IMAGE_GICON ? icon_info->gicon : NULL;
7890 * gtk_entry_get_icon_stock:
7891 * @entry: A #GtkEntry
7892 * @icon_pos: Icon position
7894 * Retrieves the stock id used for the icon, or %NULL if there is
7895 * no icon or if the icon was set by some other method (e.g., by
7896 * pixbuf, icon name or gicon).
7898 * Returns: A stock id, or %NULL if no icon is set or if the icon
7899 * wasn't set from a stock id
7904 gtk_entry_get_icon_stock (GtkEntry *entry,
7905 GtkEntryIconPosition icon_pos)
7907 GtkEntryPrivate *priv;
7908 EntryIconInfo *icon_info;
7910 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7911 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7913 priv = GTK_ENTRY_GET_PRIVATE (entry);
7914 icon_info = priv->icons[icon_pos];
7919 return icon_info->storage_type == GTK_IMAGE_STOCK ? icon_info->stock_id : NULL;
7923 * gtk_entry_get_icon_name:
7924 * @entry: A #GtkEntry
7925 * @icon_pos: Icon position
7927 * Retrieves the icon name used for the icon, or %NULL if there is
7928 * no icon or if the icon was set by some other method (e.g., by
7929 * pixbuf, stock or gicon).
7931 * Returns: An icon name, or %NULL if no icon is set or if the icon
7932 * wasn't set from an icon name
7937 gtk_entry_get_icon_name (GtkEntry *entry,
7938 GtkEntryIconPosition icon_pos)
7940 GtkEntryPrivate *priv;
7941 EntryIconInfo *icon_info;
7943 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7944 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7946 priv = GTK_ENTRY_GET_PRIVATE (entry);
7947 icon_info = priv->icons[icon_pos];
7952 return icon_info->storage_type == GTK_IMAGE_ICON_NAME ? icon_info->icon_name : NULL;
7956 * gtk_entry_set_icon_sensitive:
7957 * @entry: A #GtkEntry
7958 * @icon_pos: Icon position
7959 * @sensitive: Specifies whether the icon should appear
7960 * sensitive or insensitive
7962 * Sets the sensitivity for the specified icon.
7967 gtk_entry_set_icon_sensitive (GtkEntry *entry,
7968 GtkEntryIconPosition icon_pos,
7971 GtkEntryPrivate *priv;
7972 EntryIconInfo *icon_info;
7974 g_return_if_fail (GTK_IS_ENTRY (entry));
7975 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7977 priv = GTK_ENTRY_GET_PRIVATE (entry);
7979 if ((icon_info = priv->icons[icon_pos]) == NULL)
7980 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7982 if (icon_info->insensitive != !sensitive)
7984 icon_info->insensitive = !sensitive;
7986 icon_info->pressed = FALSE;
7987 icon_info->prelight = FALSE;
7989 if (GTK_WIDGET_REALIZED (GTK_WIDGET (entry)))
7990 update_cursors (GTK_WIDGET (entry));
7992 gtk_widget_queue_draw (GTK_WIDGET (entry));
7994 g_object_notify (G_OBJECT (entry),
7995 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-sensitive" : "secondary-icon-sensitive");
8000 * gtk_entry_get_icon_sensitive:
8001 * @entry: a #GtkEntry
8002 * @icon_pos: Icon position
8004 * Returns whether the icon appears sensitive or insensitive.
8006 * Returns: %TRUE if the icon is sensitive.
8011 gtk_entry_get_icon_sensitive (GtkEntry *entry,
8012 GtkEntryIconPosition icon_pos)
8014 GtkEntryPrivate *priv;
8015 EntryIconInfo *icon_info;
8017 g_return_val_if_fail (GTK_IS_ENTRY (entry), TRUE);
8018 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), TRUE);
8020 priv = GTK_ENTRY_GET_PRIVATE (entry);
8021 icon_info = priv->icons[icon_pos];
8023 return (!icon_info || !icon_info->insensitive);
8028 * gtk_entry_get_icon_storage_type:
8029 * @entry: a #GtkEntry
8030 * @icon_pos: Icon position
8032 * Gets the type of representation being used by the icon
8033 * to store image data. If the icon has no image data,
8034 * the return value will be %GTK_IMAGE_EMPTY.
8036 * Return value: image representation being used
8041 gtk_entry_get_icon_storage_type (GtkEntry *entry,
8042 GtkEntryIconPosition icon_pos)
8044 GtkEntryPrivate *priv;
8045 EntryIconInfo *icon_info;
8047 g_return_val_if_fail (GTK_IS_ENTRY (entry), GTK_IMAGE_EMPTY);
8048 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), GTK_IMAGE_EMPTY);
8050 priv = GTK_ENTRY_GET_PRIVATE (entry);
8051 icon_info = priv->icons[icon_pos];
8054 return GTK_IMAGE_EMPTY;
8056 return icon_info->storage_type;
8060 * gtk_entry_get_icon_at_pos:
8061 * @entry: a #GtkEntry
8062 * @x: the x coordinate of the position to find
8063 * @y: the y coordinate of the position to find
8065 * Finds the icon at the given position and return its index.
8066 * If @x, @y doesn't lie inside an icon, -1 is returned.
8067 * This function is intended for use in a #GtkWidget::query-tooltip
8070 * Returns: the index of the icon at the given position, or -1
8075 gtk_entry_get_icon_at_pos (GtkEntry *entry,
8079 GtkAllocation primary;
8080 GtkAllocation secondary;
8082 g_return_val_if_fail (GTK_IS_ENTRY (entry), -1);
8084 get_icon_allocations (entry, &primary, &secondary);
8086 if (primary.x <= x && x < primary.x + primary.width &&
8087 primary.y <= y && y < primary.y + primary.height)
8088 return GTK_ENTRY_ICON_PRIMARY;
8090 if (secondary.x <= x && x < secondary.x + secondary.width &&
8091 secondary.y <= y && y < secondary.y + secondary.height)
8092 return GTK_ENTRY_ICON_SECONDARY;
8098 * gtk_entry_set_icon_drag_source:
8099 * @entry: a #GtkIconEntry
8100 * @icon_pos: icon position
8101 * @target_list: the targets (data formats) in which the data can be provided
8102 * @actions: a bitmask of the allowed drag actions
8104 * Sets up the icon at the given position so that GTK+ will start a drag
8105 * operation when the user clicks and drags the icon.
8107 * To handle the drag operation, you need to connect to the usual
8108 * #GtkWidget::drag-data-get (or possibly #GtkWidget::drag-data-delete)
8109 * signal, and use gtk_entry_get_current_icon_drag_source() in
8110 * your signal handler to find out if the drag was started from
8113 * By default, GTK+ uses the icon as the drag icon. You can use the
8114 * #GtkWidget::drag-begin signal to set a different icon. Note that you
8115 * have to use g_signal_connect_after() to ensure that your signal handler
8116 * gets executed after the default handler.
8119 gtk_entry_set_icon_drag_source (GtkEntry *entry,
8120 GtkEntryIconPosition icon_pos,
8121 GtkTargetList *target_list,
8122 GdkDragAction actions)
8124 GtkEntryPrivate *priv;
8125 EntryIconInfo *icon_info;
8127 g_return_if_fail (GTK_IS_ENTRY (entry));
8128 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8130 priv = GTK_ENTRY_GET_PRIVATE (entry);
8132 if ((icon_info = priv->icons[icon_pos]) == NULL)
8133 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8135 if (icon_info->target_list)
8136 gtk_target_list_unref (icon_info->target_list);
8137 icon_info->target_list = target_list;
8138 if (icon_info->target_list)
8139 gtk_target_list_ref (icon_info->target_list);
8141 icon_info->actions = actions;
8145 * gtk_entry_get_current_icon_drag_source:
8146 * @entry: a #GtkIconEntry
8148 * Returns the index of the icon which is the source of the current
8149 * DND operation, or -1.
8151 * This function is meant to be used in a #GtkWidget::drag-data-get
8154 * Returns: index of the icon which is the source of the current
8155 * DND operation, or -1.
8158 gtk_entry_get_current_icon_drag_source (GtkEntry *entry)
8160 GtkEntryPrivate *priv;
8161 EntryIconInfo *icon_info = NULL;
8164 g_return_val_if_fail (GTK_IS_ENTRY (entry), -1);
8166 priv = GTK_ENTRY_GET_PRIVATE (entry);
8168 for (i = 0; i < MAX_ICONS; i++)
8170 if ((icon_info = priv->icons[i]))
8172 if (icon_info->in_drag)
8181 ensure_has_tooltip (GtkEntry *entry)
8183 GtkEntryPrivate *priv;
8184 EntryIconInfo *icon_info;
8186 gboolean has_tooltip = FALSE;
8188 priv = GTK_ENTRY_GET_PRIVATE (entry);
8190 for (i = 0; i < MAX_ICONS; i++)
8192 if ((icon_info = priv->icons[i]) != NULL)
8194 if (icon_info->tooltip != NULL)
8202 gtk_widget_set_has_tooltip (GTK_WIDGET (entry), has_tooltip);
8206 * gtk_entry_get_icon_tooltip_text:
8207 * @entry: a #GtkEntry
8208 * @icon_pos: the icon position
8210 * Gets the contents of the tooltip on the icon at the specified
8211 * position in @entry.
8213 * Returns: the tooltip text, or %NULL. Free the returned string
8214 * with g_free() when done.
8219 gtk_entry_get_icon_tooltip_text (GtkEntry *entry,
8220 GtkEntryIconPosition icon_pos)
8222 GtkEntryPrivate *priv;
8223 EntryIconInfo *icon_info;
8226 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8227 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8229 priv = GTK_ENTRY_GET_PRIVATE (entry);
8230 icon_info = priv->icons[icon_pos];
8235 if (icon_info->tooltip &&
8236 !pango_parse_markup (icon_info->tooltip, -1, 0, NULL, &text, NULL, NULL))
8237 g_assert (NULL == text); /* text should still be NULL in case of markup errors */
8243 * gtk_entry_set_icon_tooltip_text:
8244 * @entry: a #GtkEntry
8245 * @icon_pos: the icon position
8246 * @tooltip: the contents of the tooltip for the icon, or %NULL
8248 * Sets @tooltip as the contents of the tooltip for the icon
8249 * at the specified position.
8251 * Use %NULL for @tooltip to remove an existing tooltip.
8253 * See also gtk_widget_set_tooltip_text() and
8254 * gtk_entry_set_icon_tooltip_markup().
8259 gtk_entry_set_icon_tooltip_text (GtkEntry *entry,
8260 GtkEntryIconPosition icon_pos,
8261 const gchar *tooltip)
8263 GtkEntryPrivate *priv;
8264 EntryIconInfo *icon_info;
8266 g_return_if_fail (GTK_IS_ENTRY (entry));
8267 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8269 priv = GTK_ENTRY_GET_PRIVATE (entry);
8271 if (!(icon_info = priv->icons[icon_pos]))
8272 icon_info = priv->icons[icon_pos];
8274 if (icon_info->tooltip)
8275 g_free (icon_info->tooltip);
8277 /* Treat an empty string as a NULL string,
8278 * because an empty string would be useless for a tooltip:
8280 if (tooltip && tooltip[0] == '\0')
8283 icon_info->tooltip = tooltip ? g_markup_escape_text (tooltip, -1) : NULL;
8285 ensure_has_tooltip (entry);
8289 * gtk_entry_get_icon_tooltip_markup:
8290 * @entry: a #GtkEntry
8291 * @icon_pos: the icon position
8293 * Gets the contents of the tooltip on the icon at the specified
8294 * position in @entry.
8296 * Returns: the tooltip text, or %NULL. Free the returned string
8297 * with g_free() when done.
8302 gtk_entry_get_icon_tooltip_markup (GtkEntry *entry,
8303 GtkEntryIconPosition icon_pos)
8305 GtkEntryPrivate *priv;
8306 EntryIconInfo *icon_info;
8308 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8309 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8311 priv = GTK_ENTRY_GET_PRIVATE (entry);
8312 icon_info = priv->icons[icon_pos];
8317 return g_strdup (icon_info->tooltip);
8321 * gtk_entry_set_icon_tooltip_markup:
8322 * @entry: a #GtkEntry
8323 * @icon_pos: the icon position
8324 * @tooltip: the contents of the tooltip for the icon, or %NULL
8326 * Sets @tooltip as the contents of the tooltip for the icon at
8327 * the specified position. @tooltip is assumed to be marked up with
8328 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
8330 * Use %NULL for @tooltip to remove an existing tooltip.
8332 * See also gtk_widget_set_tooltip_markup() and
8333 * gtk_enty_set_icon_tooltip_text().
8338 gtk_entry_set_icon_tooltip_markup (GtkEntry *entry,
8339 GtkEntryIconPosition icon_pos,
8340 const gchar *tooltip)
8342 GtkEntryPrivate *priv;
8343 EntryIconInfo *icon_info;
8345 g_return_if_fail (GTK_IS_ENTRY (entry));
8346 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8348 priv = GTK_ENTRY_GET_PRIVATE (entry);
8350 if (!(icon_info = priv->icons[icon_pos]))
8351 icon_info = priv->icons[icon_pos];
8353 if (icon_info->tooltip)
8354 g_free (icon_info->tooltip);
8356 /* Treat an empty string as a NULL string,
8357 * because an empty string would be useless for a tooltip:
8359 if (tooltip && tooltip[0] == '\0')
8362 icon_info->tooltip = g_strdup (tooltip);
8364 ensure_has_tooltip (entry);
8368 gtk_entry_query_tooltip (GtkWidget *widget,
8371 gboolean keyboard_tip,
8372 GtkTooltip *tooltip)
8375 GtkEntryPrivate *priv;
8376 EntryIconInfo *icon_info;
8379 entry = GTK_ENTRY (widget);
8380 priv = GTK_ENTRY_GET_PRIVATE (entry);
8384 icon_pos = gtk_entry_get_icon_at_pos (entry, x, y);
8387 if ((icon_info = priv->icons[icon_pos]) != NULL)
8389 if (icon_info->tooltip)
8391 gtk_tooltip_set_markup (tooltip, icon_info->tooltip);
8400 return GTK_WIDGET_CLASS (gtk_entry_parent_class)->query_tooltip (widget,
8407 /* Quick hack of a popup menu
8410 activate_cb (GtkWidget *menuitem,
8413 const gchar *signal = g_object_get_data (G_OBJECT (menuitem), "gtk-signal");
8414 g_signal_emit_by_name (entry, signal);
8419 gtk_entry_mnemonic_activate (GtkWidget *widget,
8420 gboolean group_cycling)
8422 gtk_widget_grab_focus (widget);
8427 append_action_signal (GtkEntry *entry,
8429 const gchar *stock_id,
8430 const gchar *signal,
8433 GtkWidget *menuitem = gtk_image_menu_item_new_from_stock (stock_id, NULL);
8435 g_object_set_data (G_OBJECT (menuitem), I_("gtk-signal"), (char *)signal);
8436 g_signal_connect (menuitem, "activate",
8437 G_CALLBACK (activate_cb), entry);
8439 gtk_widget_set_sensitive (menuitem, sensitive);
8441 gtk_widget_show (menuitem);
8442 gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
8446 popup_menu_detach (GtkWidget *attach_widget,
8449 GTK_ENTRY (attach_widget)->popup_menu = NULL;
8453 popup_position_func (GtkMenu *menu,
8459 GtkEntry *entry = GTK_ENTRY (user_data);
8460 GtkWidget *widget = GTK_WIDGET (entry);
8462 GtkRequisition menu_req;
8463 GdkRectangle monitor;
8464 GtkBorder inner_border;
8465 gint monitor_num, strong_x, height;
8467 g_return_if_fail (GTK_WIDGET_REALIZED (entry));
8469 gdk_window_get_origin (entry->text_area, x, y);
8471 screen = gtk_widget_get_screen (widget);
8472 monitor_num = gdk_screen_get_monitor_at_window (screen, entry->text_area);
8473 if (monitor_num < 0)
8475 gtk_menu_set_monitor (menu, monitor_num);
8477 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
8478 gtk_widget_size_request (entry->popup_menu, &menu_req);
8479 gdk_drawable_get_size (entry->text_area, NULL, &height);
8480 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
8481 _gtk_entry_effective_inner_border (entry, &inner_border);
8483 *x += inner_border.left + strong_x - entry->scroll_offset;
8484 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
8485 *x -= menu_req.width;
8487 if ((*y + height + menu_req.height) <= monitor.y + monitor.height)
8489 else if ((*y - menu_req.height) >= monitor.y)
8490 *y -= menu_req.height;
8491 else if (monitor.y + monitor.height - (*y + height) > *y)
8494 *y -= menu_req.height;
8500 unichar_chosen_func (const char *text,
8503 GtkEntry *entry = GTK_ENTRY (data);
8505 if (entry->editable)
8506 gtk_entry_enter_text (entry, text);
8517 popup_targets_received (GtkClipboard *clipboard,
8518 GtkSelectionData *data,
8521 PopupInfo *info = user_data;
8522 GtkEntry *entry = info->entry;
8524 if (GTK_WIDGET_REALIZED (entry))
8527 gboolean clipboard_contains_text;
8528 GtkWidget *menuitem;
8530 gboolean show_input_method_menu;
8531 gboolean show_unicode_menu;
8533 clipboard_contains_text = gtk_selection_data_targets_include_text (data);
8534 if (entry->popup_menu)
8535 gtk_widget_destroy (entry->popup_menu);
8537 entry->popup_menu = gtk_menu_new ();
8539 gtk_menu_attach_to_widget (GTK_MENU (entry->popup_menu),
8543 mode = gtk_entry_get_display_mode (entry);
8544 append_action_signal (entry, entry->popup_menu, GTK_STOCK_CUT, "cut-clipboard",
8545 entry->editable && mode == DISPLAY_NORMAL &&
8546 entry->current_pos != entry->selection_bound);
8548 append_action_signal (entry, entry->popup_menu, GTK_STOCK_COPY, "copy-clipboard",
8549 mode == DISPLAY_NORMAL &&
8550 entry->current_pos != entry->selection_bound);
8552 append_action_signal (entry, entry->popup_menu, GTK_STOCK_PASTE, "paste-clipboard",
8553 entry->editable && clipboard_contains_text);
8555 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_DELETE, NULL);
8556 gtk_widget_set_sensitive (menuitem, entry->editable && entry->current_pos != entry->selection_bound);
8557 g_signal_connect_swapped (menuitem, "activate",
8558 G_CALLBACK (gtk_entry_delete_cb), entry);
8559 gtk_widget_show (menuitem);
8560 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8562 menuitem = gtk_separator_menu_item_new ();
8563 gtk_widget_show (menuitem);
8564 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8566 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_SELECT_ALL, NULL);
8567 g_signal_connect_swapped (menuitem, "activate",
8568 G_CALLBACK (gtk_entry_select_all), entry);
8569 gtk_widget_show (menuitem);
8570 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8572 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
8573 "gtk-show-input-method-menu", &show_input_method_menu,
8574 "gtk-show-unicode-menu", &show_unicode_menu,
8577 if (show_input_method_menu || show_unicode_menu)
8579 menuitem = gtk_separator_menu_item_new ();
8580 gtk_widget_show (menuitem);
8581 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8584 if (show_input_method_menu)
8586 menuitem = gtk_menu_item_new_with_mnemonic (_("Input _Methods"));
8587 gtk_widget_set_sensitive (menuitem, entry->editable);
8588 gtk_widget_show (menuitem);
8589 submenu = gtk_menu_new ();
8590 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
8592 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8594 gtk_im_multicontext_append_menuitems (GTK_IM_MULTICONTEXT (entry->im_context),
8595 GTK_MENU_SHELL (submenu));
8598 if (show_unicode_menu)
8600 menuitem = gtk_menu_item_new_with_mnemonic (_("_Insert Unicode Control Character"));
8601 gtk_widget_set_sensitive (menuitem, entry->editable);
8602 gtk_widget_show (menuitem);
8604 submenu = gtk_menu_new ();
8605 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
8606 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8608 _gtk_text_util_append_special_char_menuitems (GTK_MENU_SHELL (submenu),
8609 unichar_chosen_func,
8613 g_signal_emit (entry,
8614 signals[POPULATE_POPUP],
8620 gtk_menu_popup (GTK_MENU (entry->popup_menu), NULL, NULL,
8622 info->button, info->time);
8625 gtk_menu_popup (GTK_MENU (entry->popup_menu), NULL, NULL,
8626 popup_position_func, entry,
8627 info->button, info->time);
8628 gtk_menu_shell_select_first (GTK_MENU_SHELL (entry->popup_menu), FALSE);
8632 g_object_unref (entry);
8633 g_slice_free (PopupInfo, info);
8637 gtk_entry_do_popup (GtkEntry *entry,
8638 GdkEventButton *event)
8640 PopupInfo *info = g_slice_new (PopupInfo);
8642 /* In order to know what entries we should make sensitive, we
8643 * ask for the current targets of the clipboard, and when
8644 * we get them, then we actually pop up the menu.
8646 info->entry = g_object_ref (entry);
8650 info->button = event->button;
8651 info->time = event->time;
8656 info->time = gtk_get_current_event_time ();
8659 gtk_clipboard_request_contents (gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_CLIPBOARD),
8660 gdk_atom_intern_static_string ("TARGETS"),
8661 popup_targets_received,
8666 gtk_entry_popup_menu (GtkWidget *widget)
8668 gtk_entry_do_popup (GTK_ENTRY (widget), NULL);
8673 gtk_entry_drag_begin (GtkWidget *widget,
8674 GdkDragContext *context)
8676 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
8679 for (i = 0; i < MAX_ICONS; i++)
8681 EntryIconInfo *icon_info = priv->icons[i];
8683 if (icon_info != NULL)
8685 if (icon_info->in_drag)
8687 switch (icon_info->storage_type)
8689 case GTK_IMAGE_STOCK:
8690 gtk_drag_set_icon_stock (context, icon_info->stock_id, -2, -2);
8693 case GTK_IMAGE_ICON_NAME:
8694 gtk_drag_set_icon_name (context, icon_info->icon_name, -2, -2);
8697 /* FIXME: No GIcon support for dnd icons */
8698 case GTK_IMAGE_GICON:
8699 case GTK_IMAGE_PIXBUF:
8700 gtk_drag_set_icon_pixbuf (context, icon_info->pixbuf, -2, -2);
8703 g_assert_not_reached ();
8711 gtk_entry_drag_end (GtkWidget *widget,
8712 GdkDragContext *context)
8714 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
8717 for (i = 0; i < MAX_ICONS; i++)
8719 EntryIconInfo *icon_info = priv->icons[i];
8721 if (icon_info != NULL)
8722 icon_info->in_drag = 0;
8727 gtk_entry_drag_leave (GtkWidget *widget,
8728 GdkDragContext *context,
8731 GtkEntry *entry = GTK_ENTRY (widget);
8733 entry->dnd_position = -1;
8734 gtk_widget_queue_draw (widget);
8738 gtk_entry_drag_drop (GtkWidget *widget,
8739 GdkDragContext *context,
8744 GtkEntry *entry = GTK_ENTRY (widget);
8745 GdkAtom target = GDK_NONE;
8747 if (entry->editable)
8748 target = gtk_drag_dest_find_target (widget, context, NULL);
8750 if (target != GDK_NONE)
8751 gtk_drag_get_data (widget, context, target, time);
8753 gtk_drag_finish (context, FALSE, FALSE, time);
8759 gtk_entry_drag_motion (GtkWidget *widget,
8760 GdkDragContext *context,
8765 GtkEntry *entry = GTK_ENTRY (widget);
8766 GtkWidget *source_widget;
8767 GdkDragAction suggested_action;
8768 gint new_position, old_position;
8771 x -= widget->style->xthickness;
8772 y -= widget->style->ythickness;
8774 old_position = entry->dnd_position;
8775 new_position = gtk_entry_find_position (entry, x + entry->scroll_offset);
8777 if (entry->editable &&
8778 gtk_drag_dest_find_target (widget, context, NULL) != GDK_NONE)
8780 source_widget = gtk_drag_get_source_widget (context);
8781 suggested_action = context->suggested_action;
8783 if (!gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &sel1, &sel2) ||
8784 new_position < sel1 || new_position > sel2)
8786 if (source_widget == widget)
8788 /* Default to MOVE, unless the user has
8789 * pressed ctrl or alt to affect available actions
8791 if ((context->actions & GDK_ACTION_MOVE) != 0)
8792 suggested_action = GDK_ACTION_MOVE;
8795 entry->dnd_position = new_position;
8799 if (source_widget == widget)
8800 suggested_action = 0; /* Can't drop in selection where drag started */
8802 entry->dnd_position = -1;
8807 /* Entry not editable, or no text */
8808 suggested_action = 0;
8809 entry->dnd_position = -1;
8812 gdk_drag_status (context, suggested_action, time);
8814 if (entry->dnd_position != old_position)
8815 gtk_widget_queue_draw (widget);
8821 gtk_entry_drag_data_received (GtkWidget *widget,
8822 GdkDragContext *context,
8825 GtkSelectionData *selection_data,
8829 GtkEntry *entry = GTK_ENTRY (widget);
8830 GtkEditable *editable = GTK_EDITABLE (widget);
8833 str = (gchar *) gtk_selection_data_get_text (selection_data);
8835 x -= widget->style->xthickness;
8836 y -= widget->style->ythickness;
8838 if (str && entry->editable)
8844 if (entry->truncate_multiline)
8845 length = truncate_multiline (str);
8847 new_position = gtk_entry_find_position (entry, x + entry->scroll_offset);
8849 if (!gtk_editable_get_selection_bounds (editable, &sel1, &sel2) ||
8850 new_position < sel1 || new_position > sel2)
8852 gtk_editable_insert_text (editable, str, length, &new_position);
8856 /* Replacing selection */
8857 begin_change (entry);
8858 g_object_freeze_notify (G_OBJECT (entry));
8859 gtk_editable_delete_text (editable, sel1, sel2);
8860 gtk_editable_insert_text (editable, str, length, &sel1);
8861 g_object_thaw_notify (G_OBJECT (entry));
8865 gtk_drag_finish (context, TRUE, context->action == GDK_ACTION_MOVE, time);
8869 /* Drag and drop didn't happen! */
8870 gtk_drag_finish (context, FALSE, FALSE, time);
8877 gtk_entry_drag_data_get (GtkWidget *widget,
8878 GdkDragContext *context,
8879 GtkSelectionData *selection_data,
8883 gint sel_start, sel_end;
8886 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
8887 GtkEditable *editable = GTK_EDITABLE (widget);
8889 /* If there is an icon drag going on, exit early. */
8890 for (i = 0; i < MAX_ICONS; i++)
8892 EntryIconInfo *icon_info = priv->icons[i];
8894 if (icon_info != NULL)
8896 if (icon_info->in_drag)
8901 if (gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end))
8903 gchar *str = gtk_entry_get_display_text (GTK_ENTRY (widget), sel_start, sel_end);
8905 gtk_selection_data_set_text (selection_data, str, -1);
8913 gtk_entry_drag_data_delete (GtkWidget *widget,
8914 GdkDragContext *context)
8916 gint sel_start, sel_end;
8919 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
8920 GtkEditable *editable = GTK_EDITABLE (widget);
8922 /* If there is an icon drag going on, exit early. */
8923 for (i = 0; i < MAX_ICONS; i++)
8925 EntryIconInfo *icon_info = priv->icons[i];
8927 if (icon_info != NULL)
8929 if (icon_info->in_drag)
8934 if (GTK_ENTRY (widget)->editable &&
8935 gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end))
8936 gtk_editable_delete_text (editable, sel_start, sel_end);
8939 /* We display the cursor when
8941 * - the selection is empty, AND
8942 * - the widget has focus
8945 #define CURSOR_ON_MULTIPLIER 2
8946 #define CURSOR_OFF_MULTIPLIER 1
8947 #define CURSOR_PEND_MULTIPLIER 3
8948 #define CURSOR_DIVIDER 3
8951 cursor_blinks (GtkEntry *entry)
8953 if (GTK_WIDGET_HAS_FOCUS (entry) &&
8955 entry->selection_bound == entry->current_pos)
8957 GtkSettings *settings;
8960 settings = gtk_widget_get_settings (GTK_WIDGET (entry));
8961 g_object_get (settings, "gtk-cursor-blink", &blink, NULL);
8970 get_cursor_time (GtkEntry *entry)
8972 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (entry));
8975 g_object_get (settings, "gtk-cursor-blink-time", &time, NULL);
8981 get_cursor_blink_timeout (GtkEntry *entry)
8983 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (entry));
8986 g_object_get (settings, "gtk-cursor-blink-timeout", &timeout, NULL);
8992 show_cursor (GtkEntry *entry)
8994 if (!entry->cursor_visible)
8996 entry->cursor_visible = TRUE;
8998 if (GTK_WIDGET_HAS_FOCUS (entry) && entry->selection_bound == entry->current_pos)
8999 gtk_widget_queue_draw (GTK_WIDGET (entry));
9004 hide_cursor (GtkEntry *entry)
9006 if (entry->cursor_visible)
9008 entry->cursor_visible = FALSE;
9010 if (GTK_WIDGET_HAS_FOCUS (entry) && entry->selection_bound == entry->current_pos)
9011 gtk_widget_queue_draw (GTK_WIDGET (entry));
9019 blink_cb (gpointer data)
9022 GtkEntryPrivate *priv;
9025 entry = GTK_ENTRY (data);
9026 priv = GTK_ENTRY_GET_PRIVATE (entry);
9028 if (!GTK_WIDGET_HAS_FOCUS (entry))
9030 g_warning ("GtkEntry - did not receive focus-out-event. If you\n"
9031 "connect a handler to this signal, it must return\n"
9032 "FALSE so the entry gets the event as well");
9034 gtk_entry_check_cursor_blink (entry);
9039 g_assert (entry->selection_bound == entry->current_pos);
9041 blink_timeout = get_cursor_blink_timeout (entry);
9042 if (priv->blink_time > 1000 * blink_timeout &&
9043 blink_timeout < G_MAXINT/1000)
9045 /* we've blinked enough without the user doing anything, stop blinking */
9046 show_cursor (entry);
9047 entry->blink_timeout = 0;
9049 else if (entry->cursor_visible)
9051 hide_cursor (entry);
9052 entry->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_OFF_MULTIPLIER / CURSOR_DIVIDER,
9058 show_cursor (entry);
9059 priv->blink_time += get_cursor_time (entry);
9060 entry->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
9065 /* Remove ourselves */
9070 gtk_entry_check_cursor_blink (GtkEntry *entry)
9072 GtkEntryPrivate *priv;
9074 priv = GTK_ENTRY_GET_PRIVATE (entry);
9076 if (cursor_blinks (entry))
9078 if (!entry->blink_timeout)
9080 show_cursor (entry);
9081 entry->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
9088 if (entry->blink_timeout)
9090 g_source_remove (entry->blink_timeout);
9091 entry->blink_timeout = 0;
9094 entry->cursor_visible = TRUE;
9100 gtk_entry_pend_cursor_blink (GtkEntry *entry)
9102 if (cursor_blinks (entry))
9104 if (entry->blink_timeout != 0)
9105 g_source_remove (entry->blink_timeout);
9107 entry->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_PEND_MULTIPLIER / CURSOR_DIVIDER,
9110 show_cursor (entry);
9115 gtk_entry_reset_blink_time (GtkEntry *entry)
9117 GtkEntryPrivate *priv;
9119 priv = GTK_ENTRY_GET_PRIVATE (entry);
9121 priv->blink_time = 0;
9127 gtk_entry_completion_timeout (gpointer data)
9129 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (data);
9131 completion->priv->completion_timeout = 0;
9133 if (completion->priv->filter_model &&
9134 g_utf8_strlen (gtk_entry_get_text (GTK_ENTRY (completion->priv->entry)), -1)
9135 >= completion->priv->minimum_key_length)
9139 GtkTreeSelection *s;
9140 gboolean popup_single;
9142 gtk_entry_completion_complete (completion);
9143 matches = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->filter_model), NULL);
9145 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9147 s = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view));
9149 gtk_tree_selection_unselect_all (s);
9151 actions = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->actions), NULL);
9153 g_object_get (completion, "popup-single-match", &popup_single, NULL);
9154 if ((matches > (popup_single ? 0: 1)) || actions > 0)
9156 if (GTK_WIDGET_VISIBLE (completion->priv->popup_window))
9157 _gtk_entry_completion_resize_popup (completion);
9159 _gtk_entry_completion_popup (completion);
9162 _gtk_entry_completion_popdown (completion);
9164 else if (GTK_WIDGET_VISIBLE (completion->priv->popup_window))
9165 _gtk_entry_completion_popdown (completion);
9170 static inline gboolean
9171 keyval_is_cursor_move (guint keyval)
9173 if (keyval == GDK_Up || keyval == GDK_KP_Up)
9176 if (keyval == GDK_Down || keyval == GDK_KP_Down)
9179 if (keyval == GDK_Page_Up)
9182 if (keyval == GDK_Page_Down)
9189 gtk_entry_completion_key_press (GtkWidget *widget,
9193 gint matches, actions = 0;
9194 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
9196 if (!GTK_WIDGET_MAPPED (completion->priv->popup_window))
9199 matches = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->filter_model), NULL);
9201 if (completion->priv->actions)
9202 actions = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->actions), NULL);
9204 if (keyval_is_cursor_move (event->keyval))
9206 GtkTreePath *path = NULL;
9208 if (event->keyval == GDK_Up || event->keyval == GDK_KP_Up)
9210 if (completion->priv->current_selected < 0)
9211 completion->priv->current_selected = matches + actions - 1;
9213 completion->priv->current_selected--;
9215 else if (event->keyval == GDK_Down || event->keyval == GDK_KP_Down)
9217 if (completion->priv->current_selected < matches + actions - 1)
9218 completion->priv->current_selected++;
9220 completion->priv->current_selected = -1;
9222 else if (event->keyval == GDK_Page_Up)
9224 if (completion->priv->current_selected < 0)
9225 completion->priv->current_selected = matches + actions - 1;
9226 else if (completion->priv->current_selected == 0)
9227 completion->priv->current_selected = -1;
9228 else if (completion->priv->current_selected < matches)
9230 completion->priv->current_selected -= 14;
9231 if (completion->priv->current_selected < 0)
9232 completion->priv->current_selected = 0;
9236 completion->priv->current_selected -= 14;
9237 if (completion->priv->current_selected < matches - 1)
9238 completion->priv->current_selected = matches - 1;
9241 else if (event->keyval == GDK_Page_Down)
9243 if (completion->priv->current_selected < 0)
9244 completion->priv->current_selected = 0;
9245 else if (completion->priv->current_selected < matches - 1)
9247 completion->priv->current_selected += 14;
9248 if (completion->priv->current_selected > matches - 1)
9249 completion->priv->current_selected = matches - 1;
9251 else if (completion->priv->current_selected == matches + actions - 1)
9253 completion->priv->current_selected = -1;
9257 completion->priv->current_selected += 14;
9258 if (completion->priv->current_selected > matches + actions - 1)
9259 completion->priv->current_selected = matches + actions - 1;
9263 if (completion->priv->current_selected < 0)
9265 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9266 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view)));
9268 if (completion->priv->inline_selection &&
9269 completion->priv->completion_prefix)
9271 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9272 completion->priv->completion_prefix);
9273 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9276 else if (completion->priv->current_selected < matches)
9278 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view)));
9280 path = gtk_tree_path_new_from_indices (completion->priv->current_selected, -1);
9281 gtk_tree_view_set_cursor (GTK_TREE_VIEW (completion->priv->tree_view),
9284 if (completion->priv->inline_selection)
9288 GtkTreeModel *model = NULL;
9289 GtkTreeSelection *sel;
9292 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view));
9293 if (!gtk_tree_selection_get_selected (sel, &model, &iter))
9296 if (completion->priv->completion_prefix == NULL)
9297 completion->priv->completion_prefix = g_strdup (gtk_entry_get_text (GTK_ENTRY (completion->priv->entry)));
9299 g_signal_emit_by_name (completion, "cursor-on-match", model,
9303 else if (completion->priv->current_selected - matches >= 0)
9305 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9307 path = gtk_tree_path_new_from_indices (completion->priv->current_selected - matches, -1);
9308 gtk_tree_view_set_cursor (GTK_TREE_VIEW (completion->priv->action_view),
9311 if (completion->priv->inline_selection &&
9312 completion->priv->completion_prefix)
9314 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9315 completion->priv->completion_prefix);
9316 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9320 gtk_tree_path_free (path);
9324 else if (event->keyval == GDK_Escape ||
9325 event->keyval == GDK_Left ||
9326 event->keyval == GDK_KP_Left ||
9327 event->keyval == GDK_Right ||
9328 event->keyval == GDK_KP_Right)
9330 gboolean retval = TRUE;
9332 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9333 _gtk_entry_completion_popdown (completion);
9335 if (completion->priv->current_selected < 0)
9338 goto keypress_completion_out;
9340 else if (completion->priv->inline_selection)
9342 /* Escape rejects the tentative completion */
9343 if (event->keyval == GDK_Escape)
9345 if (completion->priv->completion_prefix)
9346 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9347 completion->priv->completion_prefix);
9349 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry), "");
9352 /* Move the cursor to the end for Right/Esc, to the
9353 beginning for Left */
9354 if (event->keyval == GDK_Right ||
9355 event->keyval == GDK_KP_Right ||
9356 event->keyval == GDK_Escape)
9357 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9359 gtk_editable_set_position (GTK_EDITABLE (widget), 0);
9362 keypress_completion_out:
9363 if (completion->priv->inline_selection)
9365 g_free (completion->priv->completion_prefix);
9366 completion->priv->completion_prefix = NULL;
9371 else if (event->keyval == GDK_Tab ||
9372 event->keyval == GDK_KP_Tab ||
9373 event->keyval == GDK_ISO_Left_Tab)
9375 GtkDirectionType dir = event->keyval == GDK_ISO_Left_Tab ?
9376 GTK_DIR_TAB_BACKWARD : GTK_DIR_TAB_FORWARD;
9378 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9379 _gtk_entry_completion_popdown (completion);
9381 g_free (completion->priv->completion_prefix);
9382 completion->priv->completion_prefix = NULL;
9384 gtk_widget_child_focus (gtk_widget_get_toplevel (widget), dir);
9388 else if (event->keyval == GDK_ISO_Enter ||
9389 event->keyval == GDK_KP_Enter ||
9390 event->keyval == GDK_Return)
9393 GtkTreeModel *model = NULL;
9394 GtkTreeSelection *sel;
9395 gboolean retval = TRUE;
9397 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9398 _gtk_entry_completion_popdown (completion);
9400 if (completion->priv->current_selected < matches)
9404 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view));
9405 if (gtk_tree_selection_get_selected (sel, &model, &iter))
9407 g_signal_handler_block (widget, completion->priv->changed_id);
9408 g_signal_emit_by_name (completion, "match-selected",
9409 model, &iter, &entry_set);
9410 g_signal_handler_unblock (widget, completion->priv->changed_id);
9416 gtk_tree_model_get (model, &iter,
9417 completion->priv->text_column, &str,
9420 gtk_entry_set_text (GTK_ENTRY (widget), str);
9422 /* move the cursor to the end */
9423 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9431 else if (completion->priv->current_selected - matches >= 0)
9433 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view));
9434 if (gtk_tree_selection_get_selected (sel, &model, &iter))
9438 path = gtk_tree_path_new_from_indices (completion->priv->current_selected - matches, -1);
9439 g_signal_emit_by_name (completion, "action-activated",
9440 gtk_tree_path_get_indices (path)[0]);
9441 gtk_tree_path_free (path);
9447 g_free (completion->priv->completion_prefix);
9448 completion->priv->completion_prefix = NULL;
9457 gtk_entry_completion_changed (GtkWidget *entry,
9460 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
9462 /* (re)install completion timeout */
9463 if (completion->priv->completion_timeout)
9464 g_source_remove (completion->priv->completion_timeout);
9466 if (!gtk_entry_get_text (GTK_ENTRY (entry)))
9469 /* no need to normalize for this test */
9470 if (completion->priv->minimum_key_length > 0 &&
9471 strcmp ("", gtk_entry_get_text (GTK_ENTRY (entry))) == 0)
9473 if (GTK_WIDGET_VISIBLE (completion->priv->popup_window))
9474 _gtk_entry_completion_popdown (completion);
9478 completion->priv->completion_timeout =
9479 gdk_threads_add_timeout (COMPLETION_TIMEOUT,
9480 gtk_entry_completion_timeout,
9485 check_completion_callback (GtkEntryCompletion *completion)
9487 completion->priv->check_completion_idle = NULL;
9489 gtk_entry_completion_complete (completion);
9490 gtk_entry_completion_insert_prefix (completion);
9496 clear_completion_callback (GtkEntry *entry,
9499 if (pspec->name == I_("cursor-position") ||
9500 pspec->name == I_("selection-bound"))
9502 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
9504 completion->priv->has_completion = FALSE;
9509 accept_completion_callback (GtkEntry *entry)
9511 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
9513 if (completion->priv->has_completion)
9514 gtk_editable_set_position (GTK_EDITABLE (entry),
9515 gtk_entry_buffer_get_length (get_buffer (entry)));
9521 completion_insert_text_callback (GtkEntry *entry,
9525 GtkEntryCompletion *completion)
9527 /* idle to update the selection based on the file list */
9528 if (completion->priv->check_completion_idle == NULL)
9530 completion->priv->check_completion_idle = g_idle_source_new ();
9531 g_source_set_priority (completion->priv->check_completion_idle, G_PRIORITY_HIGH);
9532 g_source_set_closure (completion->priv->check_completion_idle,
9533 g_cclosure_new_object (G_CALLBACK (check_completion_callback),
9534 G_OBJECT (completion)));
9535 g_source_attach (completion->priv->check_completion_idle, NULL);
9540 completion_changed (GtkEntryCompletion *completion,
9544 GtkEntry *entry = GTK_ENTRY (data);
9546 if (pspec->name == I_("popup-completion") ||
9547 pspec->name == I_("inline-completion"))
9549 disconnect_completion_signals (entry, completion);
9550 connect_completion_signals (entry, completion);
9555 disconnect_completion_signals (GtkEntry *entry,
9556 GtkEntryCompletion *completion)
9558 g_signal_handlers_disconnect_by_func (completion,
9559 G_CALLBACK (completion_changed), entry);
9560 if (completion->priv->changed_id > 0 &&
9561 g_signal_handler_is_connected (entry, completion->priv->changed_id))
9563 g_signal_handler_disconnect (entry, completion->priv->changed_id);
9564 completion->priv->changed_id = 0;
9566 g_signal_handlers_disconnect_by_func (entry,
9567 G_CALLBACK (gtk_entry_completion_key_press), completion);
9568 if (completion->priv->insert_text_id > 0 &&
9569 g_signal_handler_is_connected (entry, completion->priv->insert_text_id))
9571 g_signal_handler_disconnect (entry, completion->priv->insert_text_id);
9572 completion->priv->insert_text_id = 0;
9574 g_signal_handlers_disconnect_by_func (entry,
9575 G_CALLBACK (completion_insert_text_callback), completion);
9576 g_signal_handlers_disconnect_by_func (entry,
9577 G_CALLBACK (clear_completion_callback), completion);
9578 g_signal_handlers_disconnect_by_func (entry,
9579 G_CALLBACK (accept_completion_callback), completion);
9583 connect_completion_signals (GtkEntry *entry,
9584 GtkEntryCompletion *completion)
9586 if (completion->priv->popup_completion)
9588 completion->priv->changed_id =
9589 g_signal_connect (entry, "changed",
9590 G_CALLBACK (gtk_entry_completion_changed), completion);
9591 g_signal_connect (entry, "key-press-event",
9592 G_CALLBACK (gtk_entry_completion_key_press), completion);
9595 if (completion->priv->inline_completion)
9597 completion->priv->insert_text_id =
9598 g_signal_connect (entry, "insert-text",
9599 G_CALLBACK (completion_insert_text_callback), completion);
9600 g_signal_connect (entry, "notify",
9601 G_CALLBACK (clear_completion_callback), completion);
9602 g_signal_connect (entry, "activate",
9603 G_CALLBACK (accept_completion_callback), completion);
9604 g_signal_connect (entry, "focus-out-event",
9605 G_CALLBACK (accept_completion_callback), completion);
9608 g_signal_connect (completion, "notify",
9609 G_CALLBACK (completion_changed), entry);
9613 * gtk_entry_set_completion:
9614 * @entry: A #GtkEntry
9615 * @completion: The #GtkEntryCompletion or %NULL
9617 * Sets @completion to be the auxiliary completion object to use with @entry.
9618 * All further configuration of the completion mechanism is done on
9619 * @completion using the #GtkEntryCompletion API. Completion is disabled if
9620 * @completion is set to %NULL.
9625 gtk_entry_set_completion (GtkEntry *entry,
9626 GtkEntryCompletion *completion)
9628 GtkEntryCompletion *old;
9630 g_return_if_fail (GTK_IS_ENTRY (entry));
9631 g_return_if_fail (!completion || GTK_IS_ENTRY_COMPLETION (completion));
9633 old = gtk_entry_get_completion (entry);
9635 if (old == completion)
9640 if (old->priv->completion_timeout)
9642 g_source_remove (old->priv->completion_timeout);
9643 old->priv->completion_timeout = 0;
9646 if (GTK_WIDGET_MAPPED (old->priv->popup_window))
9647 _gtk_entry_completion_popdown (old);
9649 disconnect_completion_signals (entry, old);
9650 old->priv->entry = NULL;
9652 g_object_unref (old);
9657 g_object_set_data (G_OBJECT (entry), I_(GTK_ENTRY_COMPLETION_KEY), NULL);
9661 /* hook into the entry */
9662 g_object_ref (completion);
9664 connect_completion_signals (entry, completion);
9665 completion->priv->entry = GTK_WIDGET (entry);
9666 g_object_set_data (G_OBJECT (entry), I_(GTK_ENTRY_COMPLETION_KEY), completion);
9670 * gtk_entry_get_completion:
9671 * @entry: A #GtkEntry
9673 * Returns the auxiliary completion object currently in use by @entry.
9675 * Return value: The auxiliary completion object currently in use by @entry.
9679 GtkEntryCompletion *
9680 gtk_entry_get_completion (GtkEntry *entry)
9682 GtkEntryCompletion *completion;
9684 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
9686 completion = GTK_ENTRY_COMPLETION (g_object_get_data (G_OBJECT (entry),
9687 GTK_ENTRY_COMPLETION_KEY));
9693 * gtk_entry_set_cursor_hadjustment:
9694 * @entry: a #GtkEntry
9695 * @adjustment: an adjustment which should be adjusted when the cursor
9696 * is moved, or %NULL
9698 * Hooks up an adjustment to the cursor position in an entry, so that when
9699 * the cursor is moved, the adjustment is scrolled to show that position.
9700 * See gtk_scrolled_window_get_hadjustment() for a typical way of obtaining
9703 * The adjustment has to be in pixel units and in the same coordinate system
9709 gtk_entry_set_cursor_hadjustment (GtkEntry *entry,
9710 GtkAdjustment *adjustment)
9712 g_return_if_fail (GTK_IS_ENTRY (entry));
9714 g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
9717 g_object_ref (adjustment);
9719 g_object_set_qdata_full (G_OBJECT (entry),
9720 quark_cursor_hadjustment,
9726 * gtk_entry_get_cursor_hadjustment:
9727 * @entry: a #GtkEntry
9729 * Retrieves the horizontal cursor adjustment for the entry.
9730 * See gtk_entry_set_cursor_hadjustment().
9732 * Return value: the horizontal cursor adjustment, or %NULL
9733 * if none has been set.
9738 gtk_entry_get_cursor_hadjustment (GtkEntry *entry)
9740 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
9742 return g_object_get_qdata (G_OBJECT (entry), quark_cursor_hadjustment);
9746 * gtk_entry_set_progress_fraction:
9747 * @entry: a #GtkEntry
9748 * @fraction: fraction of the task that's been completed
9750 * Causes the entry's progress indicator to "fill in" the given
9751 * fraction of the bar. The fraction should be between 0.0 and 1.0,
9757 gtk_entry_set_progress_fraction (GtkEntry *entry,
9760 GtkEntryPrivate *private;
9761 gdouble old_fraction;
9762 gint x, y, width, height;
9763 gint old_x, old_y, old_width, old_height;
9765 g_return_if_fail (GTK_IS_ENTRY (entry));
9767 private = GTK_ENTRY_GET_PRIVATE (entry);
9769 if (private->progress_pulse_mode)
9772 old_fraction = private->progress_fraction;
9774 if (GTK_WIDGET_DRAWABLE (GTK_WIDGET (entry)))
9775 get_progress_area (GTK_WIDGET(entry), &old_x, &old_y, &old_width, &old_height);
9777 fraction = CLAMP (fraction, 0.0, 1.0);
9779 private->progress_fraction = fraction;
9780 private->progress_pulse_mode = FALSE;
9781 private->progress_pulse_current = 0.0;
9783 if (GTK_WIDGET_DRAWABLE (GTK_WIDGET (entry)))
9785 get_progress_area (GTK_WIDGET(entry), &x, &y, &width, &height);
9787 if ((x != old_x) || (y != old_y) || (width != old_width) || (height != old_height))
9788 gtk_widget_queue_draw (GTK_WIDGET (entry));
9791 if (fraction != old_fraction)
9792 g_object_notify (G_OBJECT (entry), "progress-fraction");
9796 * gtk_entry_get_progress_fraction:
9797 * @entry: a #GtkEntry
9799 * Returns the current fraction of the task that's been completed.
9800 * See gtk_entry_set_progress_fraction().
9802 * Return value: a fraction from 0.0 to 1.0
9807 gtk_entry_get_progress_fraction (GtkEntry *entry)
9809 GtkEntryPrivate *private;
9811 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
9813 private = GTK_ENTRY_GET_PRIVATE (entry);
9815 return private->progress_fraction;
9819 * gtk_entry_set_progress_pulse_step:
9820 * @entry: a #GtkEntry
9821 * @fraction: fraction between 0.0 and 1.0
9823 * Sets the fraction of total entry width to move the progress
9824 * bouncing block for each call to gtk_entry_progress_pulse().
9829 gtk_entry_set_progress_pulse_step (GtkEntry *entry,
9832 GtkEntryPrivate *private;
9834 g_return_if_fail (GTK_IS_ENTRY (entry));
9836 private = GTK_ENTRY_GET_PRIVATE (entry);
9838 fraction = CLAMP (fraction, 0.0, 1.0);
9840 if (fraction != private->progress_pulse_fraction)
9842 private->progress_pulse_fraction = fraction;
9844 gtk_widget_queue_draw (GTK_WIDGET (entry));
9846 g_object_notify (G_OBJECT (entry), "progress-pulse-step");
9851 * gtk_entry_get_progress_pulse_step:
9852 * @entry: a #GtkEntry
9854 * Retrieves the pulse step set with gtk_entry_set_progress_pulse_step().
9856 * Return value: a fraction from 0.0 to 1.0
9861 gtk_entry_get_progress_pulse_step (GtkEntry *entry)
9863 GtkEntryPrivate *private;
9865 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
9867 private = GTK_ENTRY_GET_PRIVATE (entry);
9869 return private->progress_pulse_fraction;
9873 * gtk_entry_progress_pulse:
9874 * @entry: a #GtkEntry
9876 * Indicates that some progress is made, but you don't know how much.
9877 * Causes the entry's progress indicator to enter "activity mode,"
9878 * where a block bounces back and forth. Each call to
9879 * gtk_entry_progress_pulse() causes the block to move by a little bit
9880 * (the amount of movement per pulse is determined by
9881 * gtk_entry_set_progress_pulse_step()).
9886 gtk_entry_progress_pulse (GtkEntry *entry)
9888 GtkEntryPrivate *private;
9890 g_return_if_fail (GTK_IS_ENTRY (entry));
9892 private = GTK_ENTRY_GET_PRIVATE (entry);
9894 if (private->progress_pulse_mode)
9896 if (private->progress_pulse_way_back)
9898 private->progress_pulse_current -= private->progress_pulse_fraction;
9900 if (private->progress_pulse_current < 0.0)
9902 private->progress_pulse_current = 0.0;
9903 private->progress_pulse_way_back = FALSE;
9908 private->progress_pulse_current += private->progress_pulse_fraction;
9910 if (private->progress_pulse_current > 1.0 - private->progress_pulse_fraction)
9912 private->progress_pulse_current = 1.0 - private->progress_pulse_fraction;
9913 private->progress_pulse_way_back = TRUE;
9919 private->progress_fraction = 0.0;
9920 private->progress_pulse_mode = TRUE;
9921 private->progress_pulse_way_back = FALSE;
9922 private->progress_pulse_current = 0.0;
9925 gtk_widget_queue_draw (GTK_WIDGET (entry));
9928 /* Caps Lock warning for password entries */
9931 show_capslock_feedback (GtkEntry *entry,
9934 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
9936 if (gtk_entry_get_icon_storage_type (entry, GTK_ENTRY_ICON_SECONDARY) == GTK_IMAGE_EMPTY)
9938 gtk_entry_set_icon_from_stock (entry, GTK_ENTRY_ICON_SECONDARY, GTK_STOCK_CAPS_LOCK_WARNING);
9939 gtk_entry_set_icon_activatable (entry, GTK_ENTRY_ICON_SECONDARY, FALSE);
9940 priv->caps_lock_warning_shown = TRUE;
9943 if (priv->caps_lock_warning_shown)
9944 gtk_entry_set_icon_tooltip_text (entry, GTK_ENTRY_ICON_SECONDARY, text);
9946 g_warning ("Can't show Caps Lock warning, since secondary icon is set");
9950 remove_capslock_feedback (GtkEntry *entry)
9952 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
9954 if (priv->caps_lock_warning_shown)
9956 gtk_entry_set_icon_from_stock (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
9957 priv->caps_lock_warning_shown = FALSE;
9962 keymap_state_changed (GdkKeymap *keymap,
9965 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
9968 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL && priv->caps_lock_warning)
9970 if (gdk_keymap_get_caps_lock_state (keymap))
9971 text = _("Caps Lock is on");
9975 show_capslock_feedback (entry, text);
9977 remove_capslock_feedback (entry);
9980 #define __GTK_ENTRY_C__
9981 #include "gtkaliasdef.c"