1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* GTK - The GIMP Toolkit
3 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * Copyright (C) 2004-2006 Christian Hammond
5 * Copyright (C) 2008 Cody Russell
6 * Copyright (C) 2008 Red Hat, Inc.
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
25 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
26 * file for a list of people on the GTK+ Team. See the ChangeLog
27 * files for a list of changes. These files are distributed with
28 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
36 #include "gdk/gdkkeysyms.h"
37 #include "gtkalignment.h"
38 #include "gtkbindings.h"
39 #include "gtkcelleditable.h"
40 #include "gtkclipboard.h"
43 #include "gtkentrybuffer.h"
44 #include "gtkimagemenuitem.h"
45 #include "gtkimcontextsimple.h"
46 #include "gtkimmulticontext.h"
50 #include "gtkmarshalers.h"
52 #include "gtkmenuitem.h"
53 #include "gtkseparatormenuitem.h"
54 #include "gtkselection.h"
55 #include "gtksettings.h"
56 #include "gtkspinbutton.h"
58 #include "gtktextutil.h"
59 #include "gtkwindow.h"
60 #include "gtktreeview.h"
61 #include "gtktreeselection.h"
62 #include "gtkprivate.h"
63 #include "gtkentryprivate.h"
64 #include "gtkcelllayout.h"
65 #include "gtktooltip.h"
66 #include "gtkiconfactory.h"
67 #include "gtkicontheme.h"
69 #define GTK_ENTRY_COMPLETION_KEY "gtk-entry-completion-key"
71 #define MIN_ENTRY_WIDTH 150
72 #define DRAW_TIMEOUT 20
73 #define COMPLETION_TIMEOUT 300
74 #define PASSWORD_HINT_MAX 8
78 #define IS_VALID_ICON_POSITION(pos) \
79 ((pos) == GTK_ENTRY_ICON_PRIMARY || \
80 (pos) == GTK_ENTRY_ICON_SECONDARY)
82 static const GtkBorder default_inner_border = { 2, 2, 2, 2 };
83 static GQuark quark_inner_border = 0;
84 static GQuark quark_password_hint = 0;
85 static GQuark quark_cursor_hadjustment = 0;
86 static GQuark quark_capslock_feedback = 0;
88 typedef struct _GtkEntryPrivate GtkEntryPrivate;
90 #define GTK_ENTRY_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_ENTRY, GtkEntryPrivate))
96 guint insensitive : 1;
97 guint nonactivatable : 1;
102 GtkImageType storage_type;
108 GtkTargetList *target_list;
109 GdkDragAction actions;
112 struct _GtkEntryPrivate
114 GtkEntryBuffer* buffer;
118 guint blink_time; /* time in msec the cursor has blinked since last user event */
119 guint interior_focus : 1;
120 guint real_changed : 1;
121 guint invisible_char_set : 1;
122 guint caps_lock_warning : 1;
123 guint caps_lock_warning_shown : 1;
124 guint change_count : 8;
125 guint progress_pulse_mode : 1;
126 guint progress_pulse_way_back : 1;
129 GtkShadowType shadow_type;
131 gdouble progress_fraction;
132 gdouble progress_pulse_fraction;
133 gdouble progress_pulse_current;
135 EntryIconInfo *icons[MAX_ICONS];
142 GdkDevice *completion_device;
145 typedef struct _GtkEntryPasswordHint GtkEntryPasswordHint;
147 struct _GtkEntryPasswordHint
149 gint position; /* Position (in text) of the last password hint */
150 guint source_id; /* Timeout source id */
153 typedef struct _GtkEntryCapslockFeedback GtkEntryCapslockFeedback;
155 struct _GtkEntryCapslockFeedback
182 PROP_CURSOR_POSITION,
183 PROP_SELECTION_BOUND,
190 PROP_ACTIVATES_DEFAULT,
195 PROP_TRUNCATE_MULTILINE,
199 PROP_INVISIBLE_CHAR_SET,
200 PROP_CAPS_LOCK_WARNING,
201 PROP_PROGRESS_FRACTION,
202 PROP_PROGRESS_PULSE_STEP,
204 PROP_PIXBUF_SECONDARY,
206 PROP_STOCK_SECONDARY,
207 PROP_ICON_NAME_PRIMARY,
208 PROP_ICON_NAME_SECONDARY,
210 PROP_GICON_SECONDARY,
211 PROP_STORAGE_TYPE_PRIMARY,
212 PROP_STORAGE_TYPE_SECONDARY,
213 PROP_ACTIVATABLE_PRIMARY,
214 PROP_ACTIVATABLE_SECONDARY,
215 PROP_SENSITIVE_PRIMARY,
216 PROP_SENSITIVE_SECONDARY,
217 PROP_TOOLTIP_TEXT_PRIMARY,
218 PROP_TOOLTIP_TEXT_SECONDARY,
219 PROP_TOOLTIP_MARKUP_PRIMARY,
220 PROP_TOOLTIP_MARKUP_SECONDARY,
222 PROP_EDITING_CANCELED
225 static guint signals[LAST_SIGNAL] = { 0 };
234 DISPLAY_NORMAL, /* The entry text is being shown */
235 DISPLAY_INVISIBLE, /* In invisible mode, text replaced by (eg) bullets */
236 DISPLAY_BLANK /* In invisible mode, nothing shown at all */
239 /* GObject, GtkObject methods
241 static void gtk_entry_editable_init (GtkEditableClass *iface);
242 static void gtk_entry_cell_editable_init (GtkCellEditableIface *iface);
243 static void gtk_entry_set_property (GObject *object,
247 static void gtk_entry_get_property (GObject *object,
251 static void gtk_entry_finalize (GObject *object);
252 static void gtk_entry_destroy (GtkObject *object);
253 static void gtk_entry_dispose (GObject *object);
257 static void gtk_entry_realize (GtkWidget *widget);
258 static void gtk_entry_unrealize (GtkWidget *widget);
259 static void gtk_entry_map (GtkWidget *widget);
260 static void gtk_entry_unmap (GtkWidget *widget);
261 static void gtk_entry_size_request (GtkWidget *widget,
262 GtkRequisition *requisition);
263 static void gtk_entry_size_allocate (GtkWidget *widget,
264 GtkAllocation *allocation);
265 static void gtk_entry_draw_frame (GtkWidget *widget,
266 GdkEventExpose *event);
267 static void gtk_entry_draw_progress (GtkWidget *widget,
268 GdkEventExpose *event);
269 static gint gtk_entry_expose (GtkWidget *widget,
270 GdkEventExpose *event);
271 static gint gtk_entry_button_press (GtkWidget *widget,
272 GdkEventButton *event);
273 static gint gtk_entry_button_release (GtkWidget *widget,
274 GdkEventButton *event);
275 static gint gtk_entry_enter_notify (GtkWidget *widget,
276 GdkEventCrossing *event);
277 static gint gtk_entry_leave_notify (GtkWidget *widget,
278 GdkEventCrossing *event);
279 static gint gtk_entry_motion_notify (GtkWidget *widget,
280 GdkEventMotion *event);
281 static gint gtk_entry_key_press (GtkWidget *widget,
283 static gint gtk_entry_key_release (GtkWidget *widget,
285 static gint gtk_entry_focus_in (GtkWidget *widget,
286 GdkEventFocus *event);
287 static gint gtk_entry_focus_out (GtkWidget *widget,
288 GdkEventFocus *event);
289 static void gtk_entry_grab_focus (GtkWidget *widget);
290 static void gtk_entry_style_set (GtkWidget *widget,
291 GtkStyle *previous_style);
292 static gboolean gtk_entry_query_tooltip (GtkWidget *widget,
295 gboolean keyboard_tip,
296 GtkTooltip *tooltip);
297 static void gtk_entry_direction_changed (GtkWidget *widget,
298 GtkTextDirection previous_dir);
299 static void gtk_entry_state_changed (GtkWidget *widget,
300 GtkStateType previous_state);
301 static void gtk_entry_screen_changed (GtkWidget *widget,
302 GdkScreen *old_screen);
304 static gboolean gtk_entry_drag_drop (GtkWidget *widget,
305 GdkDragContext *context,
309 static gboolean gtk_entry_drag_motion (GtkWidget *widget,
310 GdkDragContext *context,
314 static void gtk_entry_drag_leave (GtkWidget *widget,
315 GdkDragContext *context,
317 static void gtk_entry_drag_data_received (GtkWidget *widget,
318 GdkDragContext *context,
321 GtkSelectionData *selection_data,
324 static void gtk_entry_drag_data_get (GtkWidget *widget,
325 GdkDragContext *context,
326 GtkSelectionData *selection_data,
329 static void gtk_entry_drag_data_delete (GtkWidget *widget,
330 GdkDragContext *context);
331 static void gtk_entry_drag_begin (GtkWidget *widget,
332 GdkDragContext *context);
333 static void gtk_entry_drag_end (GtkWidget *widget,
334 GdkDragContext *context);
337 /* GtkEditable method implementations
339 static void gtk_entry_insert_text (GtkEditable *editable,
340 const gchar *new_text,
341 gint new_text_length,
343 static void gtk_entry_delete_text (GtkEditable *editable,
346 static gchar * gtk_entry_get_chars (GtkEditable *editable,
349 static void gtk_entry_real_set_position (GtkEditable *editable,
351 static gint gtk_entry_get_position (GtkEditable *editable);
352 static void gtk_entry_set_selection_bounds (GtkEditable *editable,
355 static gboolean gtk_entry_get_selection_bounds (GtkEditable *editable,
359 /* GtkCellEditable method implementations
361 static void gtk_entry_start_editing (GtkCellEditable *cell_editable,
364 /* Default signal handlers
366 static void gtk_entry_real_insert_text (GtkEditable *editable,
367 const gchar *new_text,
368 gint new_text_length,
370 static void gtk_entry_real_delete_text (GtkEditable *editable,
373 static void gtk_entry_move_cursor (GtkEntry *entry,
374 GtkMovementStep step,
376 gboolean extend_selection);
377 static void gtk_entry_insert_at_cursor (GtkEntry *entry,
379 static void gtk_entry_delete_from_cursor (GtkEntry *entry,
382 static void gtk_entry_backspace (GtkEntry *entry);
383 static void gtk_entry_cut_clipboard (GtkEntry *entry);
384 static void gtk_entry_copy_clipboard (GtkEntry *entry);
385 static void gtk_entry_paste_clipboard (GtkEntry *entry);
386 static void gtk_entry_toggle_overwrite (GtkEntry *entry);
387 static void gtk_entry_select_all (GtkEntry *entry);
388 static void gtk_entry_real_activate (GtkEntry *entry);
389 static gboolean gtk_entry_popup_menu (GtkWidget *widget);
391 static void keymap_direction_changed (GdkKeymap *keymap,
393 static void keymap_state_changed (GdkKeymap *keymap,
395 static void remove_capslock_feedback (GtkEntry *entry);
397 /* IM Context Callbacks
399 static void gtk_entry_commit_cb (GtkIMContext *context,
402 static void gtk_entry_preedit_changed_cb (GtkIMContext *context,
404 static gboolean gtk_entry_retrieve_surrounding_cb (GtkIMContext *context,
406 static gboolean gtk_entry_delete_surrounding_cb (GtkIMContext *context,
413 static void gtk_entry_enter_text (GtkEntry *entry,
415 static void gtk_entry_set_positions (GtkEntry *entry,
417 gint selection_bound);
418 static void gtk_entry_draw_text (GtkEntry *entry);
419 static void gtk_entry_draw_cursor (GtkEntry *entry,
421 static PangoLayout *gtk_entry_ensure_layout (GtkEntry *entry,
422 gboolean include_preedit);
423 static void gtk_entry_reset_layout (GtkEntry *entry);
424 static void gtk_entry_queue_draw (GtkEntry *entry);
425 static void gtk_entry_recompute (GtkEntry *entry);
426 static gint gtk_entry_find_position (GtkEntry *entry,
428 static void gtk_entry_get_cursor_locations (GtkEntry *entry,
432 static void gtk_entry_adjust_scroll (GtkEntry *entry);
433 static gint gtk_entry_move_visually (GtkEntry *editable,
436 static gint gtk_entry_move_logically (GtkEntry *entry,
439 static gint gtk_entry_move_forward_word (GtkEntry *entry,
441 gboolean allow_whitespace);
442 static gint gtk_entry_move_backward_word (GtkEntry *entry,
444 gboolean allow_whitespace);
445 static void gtk_entry_delete_whitespace (GtkEntry *entry);
446 static void gtk_entry_select_word (GtkEntry *entry);
447 static void gtk_entry_select_line (GtkEntry *entry);
448 static void gtk_entry_paste (GtkEntry *entry,
450 static void gtk_entry_update_primary_selection (GtkEntry *entry);
451 static void gtk_entry_do_popup (GtkEntry *entry,
452 GdkEventButton *event);
453 static gboolean gtk_entry_mnemonic_activate (GtkWidget *widget,
454 gboolean group_cycling);
455 static void gtk_entry_check_cursor_blink (GtkEntry *entry);
456 static void gtk_entry_pend_cursor_blink (GtkEntry *entry);
457 static void gtk_entry_reset_blink_time (GtkEntry *entry);
458 static void gtk_entry_get_text_area_size (GtkEntry *entry,
463 static void get_text_area_size (GtkEntry *entry,
468 static void get_widget_window_size (GtkEntry *entry,
473 static void gtk_entry_move_adjustments (GtkEntry *entry);
474 static void gtk_entry_ensure_pixbuf (GtkEntry *entry,
475 GtkEntryIconPosition icon_pos);
479 static gint gtk_entry_completion_timeout (gpointer data);
480 static gboolean gtk_entry_completion_key_press (GtkWidget *widget,
483 static void gtk_entry_completion_changed (GtkWidget *entry,
485 static gboolean check_completion_callback (GtkEntryCompletion *completion);
486 static void clear_completion_callback (GtkEntry *entry,
488 static gboolean accept_completion_callback (GtkEntry *entry);
489 static void completion_insert_text_callback (GtkEntry *entry,
493 GtkEntryCompletion *completion);
494 static void completion_changed (GtkEntryCompletion *completion,
497 static void disconnect_completion_signals (GtkEntry *entry,
498 GtkEntryCompletion *completion);
499 static void connect_completion_signals (GtkEntry *entry,
500 GtkEntryCompletion *completion);
502 static void begin_change (GtkEntry *entry);
503 static void end_change (GtkEntry *entry);
504 static void emit_changed (GtkEntry *entry);
507 static void buffer_inserted_text (GtkEntryBuffer *buffer,
512 static void buffer_deleted_text (GtkEntryBuffer *buffer,
516 static void buffer_notify_text (GtkEntryBuffer *buffer,
519 static void buffer_notify_length (GtkEntryBuffer *buffer,
522 static void buffer_notify_max_length (GtkEntryBuffer *buffer,
525 static void buffer_connect_signals (GtkEntry *entry);
526 static void buffer_disconnect_signals (GtkEntry *entry);
527 static GtkEntryBuffer *get_buffer (GtkEntry *entry);
530 G_DEFINE_TYPE_WITH_CODE (GtkEntry, gtk_entry, GTK_TYPE_WIDGET,
531 G_IMPLEMENT_INTERFACE (GTK_TYPE_EDITABLE,
532 gtk_entry_editable_init)
533 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_EDITABLE,
534 gtk_entry_cell_editable_init))
537 add_move_binding (GtkBindingSet *binding_set,
540 GtkMovementStep step,
543 g_return_if_fail ((modmask & GDK_SHIFT_MASK) == 0);
545 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
549 G_TYPE_BOOLEAN, FALSE);
551 /* Selection-extending version */
552 gtk_binding_entry_add_signal (binding_set, keyval, modmask | GDK_SHIFT_MASK,
556 G_TYPE_BOOLEAN, TRUE);
560 gtk_entry_class_init (GtkEntryClass *class)
562 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
563 GtkWidgetClass *widget_class;
564 GtkObjectClass *gtk_object_class;
565 GtkBindingSet *binding_set;
567 widget_class = (GtkWidgetClass*) class;
568 gtk_object_class = (GtkObjectClass *)class;
570 gobject_class->dispose = gtk_entry_dispose;
571 gobject_class->finalize = gtk_entry_finalize;
572 gobject_class->set_property = gtk_entry_set_property;
573 gobject_class->get_property = gtk_entry_get_property;
575 widget_class->map = gtk_entry_map;
576 widget_class->unmap = gtk_entry_unmap;
577 widget_class->realize = gtk_entry_realize;
578 widget_class->unrealize = gtk_entry_unrealize;
579 widget_class->size_request = gtk_entry_size_request;
580 widget_class->size_allocate = gtk_entry_size_allocate;
581 widget_class->expose_event = gtk_entry_expose;
582 widget_class->enter_notify_event = gtk_entry_enter_notify;
583 widget_class->leave_notify_event = gtk_entry_leave_notify;
584 widget_class->button_press_event = gtk_entry_button_press;
585 widget_class->button_release_event = gtk_entry_button_release;
586 widget_class->motion_notify_event = gtk_entry_motion_notify;
587 widget_class->key_press_event = gtk_entry_key_press;
588 widget_class->key_release_event = gtk_entry_key_release;
589 widget_class->focus_in_event = gtk_entry_focus_in;
590 widget_class->focus_out_event = gtk_entry_focus_out;
591 widget_class->grab_focus = gtk_entry_grab_focus;
592 widget_class->style_set = gtk_entry_style_set;
593 widget_class->query_tooltip = gtk_entry_query_tooltip;
594 widget_class->drag_begin = gtk_entry_drag_begin;
595 widget_class->drag_end = gtk_entry_drag_end;
596 widget_class->direction_changed = gtk_entry_direction_changed;
597 widget_class->state_changed = gtk_entry_state_changed;
598 widget_class->screen_changed = gtk_entry_screen_changed;
599 widget_class->mnemonic_activate = gtk_entry_mnemonic_activate;
601 widget_class->drag_drop = gtk_entry_drag_drop;
602 widget_class->drag_motion = gtk_entry_drag_motion;
603 widget_class->drag_leave = gtk_entry_drag_leave;
604 widget_class->drag_data_received = gtk_entry_drag_data_received;
605 widget_class->drag_data_get = gtk_entry_drag_data_get;
606 widget_class->drag_data_delete = gtk_entry_drag_data_delete;
608 widget_class->popup_menu = gtk_entry_popup_menu;
610 gtk_object_class->destroy = gtk_entry_destroy;
612 class->move_cursor = gtk_entry_move_cursor;
613 class->insert_at_cursor = gtk_entry_insert_at_cursor;
614 class->delete_from_cursor = gtk_entry_delete_from_cursor;
615 class->backspace = gtk_entry_backspace;
616 class->cut_clipboard = gtk_entry_cut_clipboard;
617 class->copy_clipboard = gtk_entry_copy_clipboard;
618 class->paste_clipboard = gtk_entry_paste_clipboard;
619 class->toggle_overwrite = gtk_entry_toggle_overwrite;
620 class->activate = gtk_entry_real_activate;
621 class->get_text_area_size = gtk_entry_get_text_area_size;
623 quark_inner_border = g_quark_from_static_string ("gtk-entry-inner-border");
624 quark_password_hint = g_quark_from_static_string ("gtk-entry-password-hint");
625 quark_cursor_hadjustment = g_quark_from_static_string ("gtk-hadjustment");
626 quark_capslock_feedback = g_quark_from_static_string ("gtk-entry-capslock-feedback");
628 g_object_class_override_property (gobject_class,
629 PROP_EDITING_CANCELED,
632 g_object_class_install_property (gobject_class,
634 g_param_spec_object ("buffer",
636 P_("Text buffer object which actually stores entry text"),
637 GTK_TYPE_ENTRY_BUFFER,
638 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT));
640 g_object_class_install_property (gobject_class,
641 PROP_CURSOR_POSITION,
642 g_param_spec_int ("cursor-position",
643 P_("Cursor Position"),
644 P_("The current position of the insertion cursor in chars"),
646 GTK_ENTRY_BUFFER_MAX_SIZE,
648 GTK_PARAM_READABLE));
650 g_object_class_install_property (gobject_class,
651 PROP_SELECTION_BOUND,
652 g_param_spec_int ("selection-bound",
653 P_("Selection Bound"),
654 P_("The position of the opposite end of the selection from the cursor in chars"),
656 GTK_ENTRY_BUFFER_MAX_SIZE,
658 GTK_PARAM_READABLE));
660 g_object_class_install_property (gobject_class,
662 g_param_spec_boolean ("editable",
664 P_("Whether the entry contents can be edited"),
666 GTK_PARAM_READWRITE));
668 g_object_class_install_property (gobject_class,
670 g_param_spec_int ("max-length",
671 P_("Maximum length"),
672 P_("Maximum number of characters for this entry. Zero if no maximum"),
674 GTK_ENTRY_BUFFER_MAX_SIZE,
676 GTK_PARAM_READWRITE));
677 g_object_class_install_property (gobject_class,
679 g_param_spec_boolean ("visibility",
681 P_("FALSE displays the \"invisible char\" instead of the actual text (password mode)"),
683 GTK_PARAM_READWRITE));
685 g_object_class_install_property (gobject_class,
687 g_param_spec_boolean ("has-frame",
689 P_("FALSE removes outside bevel from entry"),
691 GTK_PARAM_READWRITE));
693 g_object_class_install_property (gobject_class,
695 g_param_spec_boxed ("inner-border",
697 P_("Border between text and frame. Overrides the inner-border style property"),
699 GTK_PARAM_READWRITE));
701 g_object_class_install_property (gobject_class,
703 g_param_spec_unichar ("invisible-char",
704 P_("Invisible character"),
705 P_("The character to use when masking entry contents (in \"password mode\")"),
707 GTK_PARAM_READWRITE));
709 g_object_class_install_property (gobject_class,
710 PROP_ACTIVATES_DEFAULT,
711 g_param_spec_boolean ("activates-default",
712 P_("Activates default"),
713 P_("Whether to activate the default widget (such as the default button in a dialog) when Enter is pressed"),
715 GTK_PARAM_READWRITE));
716 g_object_class_install_property (gobject_class,
718 g_param_spec_int ("width-chars",
719 P_("Width in chars"),
720 P_("Number of characters to leave space for in the entry"),
724 GTK_PARAM_READWRITE));
726 g_object_class_install_property (gobject_class,
728 g_param_spec_int ("scroll-offset",
730 P_("Number of pixels of the entry scrolled off the screen to the left"),
734 GTK_PARAM_READABLE));
736 g_object_class_install_property (gobject_class,
738 g_param_spec_string ("text",
740 P_("The contents of the entry"),
742 GTK_PARAM_READWRITE));
747 * The horizontal alignment, from 0 (left) to 1 (right).
748 * Reversed for RTL layouts.
752 g_object_class_install_property (gobject_class,
754 g_param_spec_float ("xalign",
756 P_("The horizontal alignment, from 0 (left) to 1 (right). Reversed for RTL layouts."),
760 GTK_PARAM_READWRITE));
763 * GtkEntry:truncate-multiline:
765 * When %TRUE, pasted multi-line text is truncated to the first line.
769 g_object_class_install_property (gobject_class,
770 PROP_TRUNCATE_MULTILINE,
771 g_param_spec_boolean ("truncate-multiline",
772 P_("Truncate multiline"),
773 P_("Whether to truncate multiline pastes to one line."),
775 GTK_PARAM_READWRITE));
778 * GtkEntry:shadow-type:
780 * Which kind of shadow to draw around the entry when
781 * #GtkEntry:has-frame is set to %TRUE.
785 g_object_class_install_property (gobject_class,
787 g_param_spec_enum ("shadow-type",
789 P_("Which kind of shadow to draw around the entry when has-frame is set"),
790 GTK_TYPE_SHADOW_TYPE,
792 GTK_PARAM_READWRITE));
795 * GtkEntry:overwrite-mode:
797 * If text is overwritten when typing in the #GtkEntry.
801 g_object_class_install_property (gobject_class,
803 g_param_spec_boolean ("overwrite-mode",
804 P_("Overwrite mode"),
805 P_("Whether new text overwrites existing text"),
807 GTK_PARAM_READWRITE));
810 * GtkEntry:text-length:
812 * The length of the text in the #GtkEntry.
816 g_object_class_install_property (gobject_class,
818 g_param_spec_uint ("text-length",
820 P_("Length of the text currently in the entry"),
824 GTK_PARAM_READABLE));
826 * GtkEntry:invisible-char-set:
828 * Whether the invisible char has been set for the #GtkEntry.
832 g_object_class_install_property (gobject_class,
833 PROP_INVISIBLE_CHAR_SET,
834 g_param_spec_boolean ("invisible-char-set",
835 P_("Invisible character set"),
836 P_("Whether the invisible character has been set"),
838 GTK_PARAM_READWRITE));
841 * GtkEntry:caps-lock-warning
843 * Whether password entries will show a warning when Caps Lock is on.
845 * Note that the warning is shown using a secondary icon, and thus
846 * does not work if you are using the secondary icon position for some
851 g_object_class_install_property (gobject_class,
852 PROP_CAPS_LOCK_WARNING,
853 g_param_spec_boolean ("caps-lock-warning",
854 P_("Caps Lock warning"),
855 P_("Whether password entries will show a warning when Caps Lock is on"),
857 GTK_PARAM_READWRITE));
860 * GtkEntry:progress-fraction:
862 * The current fraction of the task that's been completed.
866 g_object_class_install_property (gobject_class,
867 PROP_PROGRESS_FRACTION,
868 g_param_spec_double ("progress-fraction",
869 P_("Progress Fraction"),
870 P_("The current fraction of the task that's been completed"),
874 GTK_PARAM_READWRITE));
877 * GtkEntry:progress-pulse-step:
879 * The fraction of total entry width to move the progress
880 * bouncing block for each call to gtk_entry_progress_pulse().
884 g_object_class_install_property (gobject_class,
885 PROP_PROGRESS_PULSE_STEP,
886 g_param_spec_double ("progress-pulse-step",
887 P_("Progress Pulse Step"),
888 P_("The fraction of total entry width to move the progress bouncing block for each call to gtk_entry_progress_pulse()"),
892 GTK_PARAM_READWRITE));
895 * GtkEntry:primary-icon-pixbuf:
897 * A pixbuf to use as the primary icon for the entry.
901 g_object_class_install_property (gobject_class,
903 g_param_spec_object ("primary-icon-pixbuf",
904 P_("Primary pixbuf"),
905 P_("Primary pixbuf for the entry"),
907 GTK_PARAM_READWRITE));
910 * GtkEntry:secondary-icon-pixbuf:
912 * An pixbuf to use as the secondary icon for the entry.
916 g_object_class_install_property (gobject_class,
917 PROP_PIXBUF_SECONDARY,
918 g_param_spec_object ("secondary-icon-pixbuf",
919 P_("Secondary pixbuf"),
920 P_("Secondary pixbuf for the entry"),
922 GTK_PARAM_READWRITE));
925 * GtkEntry:primary-icon-stock:
927 * The stock id to use for the primary icon for the entry.
931 g_object_class_install_property (gobject_class,
933 g_param_spec_string ("primary-icon-stock",
934 P_("Primary stock ID"),
935 P_("Stock ID for primary icon"),
937 GTK_PARAM_READWRITE));
940 * GtkEntry:secondary-icon-stock:
942 * The stock id to use for the secondary icon for the entry.
946 g_object_class_install_property (gobject_class,
947 PROP_STOCK_SECONDARY,
948 g_param_spec_string ("secondary-icon-stock",
949 P_("Secondary stock ID"),
950 P_("Stock ID for secondary icon"),
952 GTK_PARAM_READWRITE));
955 * GtkEntry:primary-icon-name:
957 * The icon name to use for the primary icon for the entry.
961 g_object_class_install_property (gobject_class,
962 PROP_ICON_NAME_PRIMARY,
963 g_param_spec_string ("primary-icon-name",
964 P_("Primary icon name"),
965 P_("Icon name for primary icon"),
967 GTK_PARAM_READWRITE));
970 * GtkEntry:secondary-icon-name:
972 * The icon name to use for the secondary icon for the entry.
976 g_object_class_install_property (gobject_class,
977 PROP_ICON_NAME_SECONDARY,
978 g_param_spec_string ("secondary-icon-name",
979 P_("Secondary icon name"),
980 P_("Icon name for secondary icon"),
982 GTK_PARAM_READWRITE));
985 * GtkEntry:primary-icon-gicon:
987 * The #GIcon to use for the primary icon for the entry.
991 g_object_class_install_property (gobject_class,
993 g_param_spec_object ("primary-icon-gicon",
995 P_("GIcon for primary icon"),
997 GTK_PARAM_READWRITE));
1000 * GtkEntry:secondary-icon-gicon:
1002 * The #GIcon to use for the secondary icon for the entry.
1006 g_object_class_install_property (gobject_class,
1007 PROP_GICON_SECONDARY,
1008 g_param_spec_object ("secondary-icon-gicon",
1009 P_("Secondary GIcon"),
1010 P_("GIcon for secondary icon"),
1012 GTK_PARAM_READWRITE));
1015 * GtkEntry:primary-icon-storage-type:
1017 * The representation which is used for the primary icon of the entry.
1021 g_object_class_install_property (gobject_class,
1022 PROP_STORAGE_TYPE_PRIMARY,
1023 g_param_spec_enum ("primary-icon-storage-type",
1024 P_("Primary storage type"),
1025 P_("The representation being used for primary icon"),
1026 GTK_TYPE_IMAGE_TYPE,
1028 GTK_PARAM_READABLE));
1031 * GtkEntry:secondary-icon-storage-type:
1033 * The representation which is used for the secondary icon of the entry.
1037 g_object_class_install_property (gobject_class,
1038 PROP_STORAGE_TYPE_SECONDARY,
1039 g_param_spec_enum ("secondary-icon-storage-type",
1040 P_("Secondary storage type"),
1041 P_("The representation being used for secondary icon"),
1042 GTK_TYPE_IMAGE_TYPE,
1044 GTK_PARAM_READABLE));
1047 * GtkEntry:primary-icon-activatable:
1049 * Whether the primary icon is activatable.
1051 * GTK+ emits the #GtkEntry::icon-press and #GtkEntry::icon-release
1052 * signals only on sensitive, activatable icons.
1054 * Sensitive, but non-activatable icons can be used for purely
1055 * informational purposes.
1059 g_object_class_install_property (gobject_class,
1060 PROP_ACTIVATABLE_PRIMARY,
1061 g_param_spec_boolean ("primary-icon-activatable",
1062 P_("Primary icon activatable"),
1063 P_("Whether the primary icon is activatable"),
1065 GTK_PARAM_READWRITE));
1068 * GtkEntry:secondary-icon-activatable:
1070 * Whether the secondary icon is activatable.
1072 * GTK+ emits the #GtkEntry::icon-press and #GtkEntry::icon-release
1073 * signals only on sensitive, activatable icons.
1075 * Sensitive, but non-activatable icons can be used for purely
1076 * informational purposes.
1080 g_object_class_install_property (gobject_class,
1081 PROP_ACTIVATABLE_SECONDARY,
1082 g_param_spec_boolean ("secondary-icon-activatable",
1083 P_("Secondary icon activatable"),
1084 P_("Whether the secondary icon is activatable"),
1086 GTK_PARAM_READWRITE));
1090 * GtkEntry:primary-icon-sensitive:
1092 * Whether the primary icon is sensitive.
1094 * An insensitive icon appears grayed out. GTK+ does not emit the
1095 * #GtkEntry::icon-press and #GtkEntry::icon-release signals and
1096 * does not allow DND from insensitive icons.
1098 * An icon should be set insensitive if the action that would trigger
1099 * when clicked is currently not available.
1103 g_object_class_install_property (gobject_class,
1104 PROP_SENSITIVE_PRIMARY,
1105 g_param_spec_boolean ("primary-icon-sensitive",
1106 P_("Primary icon sensitive"),
1107 P_("Whether the primary icon is sensitive"),
1109 GTK_PARAM_READWRITE));
1112 * GtkEntry:secondary-icon-sensitive:
1114 * Whether the secondary icon is sensitive.
1116 * An insensitive icon appears grayed out. GTK+ does not emit the
1117 * #GtkEntry::icon-press and #GtkEntry::icon-release signals and
1118 * does not allow DND from insensitive icons.
1120 * An icon should be set insensitive if the action that would trigger
1121 * when clicked is currently not available.
1125 g_object_class_install_property (gobject_class,
1126 PROP_SENSITIVE_SECONDARY,
1127 g_param_spec_boolean ("secondary-icon-sensitive",
1128 P_("Secondary icon sensitive"),
1129 P_("Whether the secondary icon is sensitive"),
1131 GTK_PARAM_READWRITE));
1134 * GtkEntry:primary-icon-tooltip-text:
1136 * The contents of the tooltip on the primary icon.
1138 * Also see gtk_entry_set_icon_tooltip_text().
1142 g_object_class_install_property (gobject_class,
1143 PROP_TOOLTIP_TEXT_PRIMARY,
1144 g_param_spec_string ("primary-icon-tooltip-text",
1145 P_("Primary icon tooltip text"),
1146 P_("The contents of the tooltip on the primary icon"),
1148 GTK_PARAM_READWRITE));
1151 * GtkEntry:secondary-icon-tooltip-text:
1153 * The contents of the tooltip on the secondary icon.
1155 * Also see gtk_entry_set_icon_tooltip_text().
1159 g_object_class_install_property (gobject_class,
1160 PROP_TOOLTIP_TEXT_SECONDARY,
1161 g_param_spec_string ("secondary-icon-tooltip-text",
1162 P_("Secondary icon tooltip text"),
1163 P_("The contents of the tooltip on the secondary icon"),
1165 GTK_PARAM_READWRITE));
1168 * GtkEntry:primary-icon-tooltip-markup:
1170 * The contents of the tooltip on the primary icon, which is marked up
1171 * with the <link linkend="PangoMarkupFormat">Pango text markup
1174 * Also see gtk_entry_set_icon_tooltip_markup().
1178 g_object_class_install_property (gobject_class,
1179 PROP_TOOLTIP_MARKUP_PRIMARY,
1180 g_param_spec_string ("primary-icon-tooltip-markup",
1181 P_("Primary icon tooltip markup"),
1182 P_("The contents of the tooltip on the primary icon"),
1184 GTK_PARAM_READWRITE));
1187 * GtkEntry:secondary-icon-tooltip-markup:
1189 * The contents of the tooltip on the secondary icon, which is marked up
1190 * with the <link linkend="PangoMarkupFormat">Pango text markup
1193 * Also see gtk_entry_set_icon_tooltip_markup().
1197 g_object_class_install_property (gobject_class,
1198 PROP_TOOLTIP_MARKUP_SECONDARY,
1199 g_param_spec_string ("secondary-icon-tooltip-markup",
1200 P_("Secondary icon tooltip markup"),
1201 P_("The contents of the tooltip on the secondary icon"),
1203 GTK_PARAM_READWRITE));
1206 * GtkEntry:im-module:
1208 * Which IM (input method) module should be used for this entry.
1209 * See #GtkIMContext.
1211 * Setting this to a non-%NULL value overrides the
1212 * system-wide IM module setting. See the GtkSettings
1213 * #GtkSettings:gtk-im-module property.
1217 g_object_class_install_property (gobject_class,
1219 g_param_spec_string ("im-module",
1221 P_("Which IM module should be used"),
1223 GTK_PARAM_READWRITE));
1226 * GtkEntry:icon-prelight:
1228 * The prelight style property determines whether activatable
1229 * icons prelight on mouseover.
1233 gtk_widget_class_install_style_property (widget_class,
1234 g_param_spec_boolean ("icon-prelight",
1235 P_("Icon Prelight"),
1236 P_("Whether activatable icons should prelight when hovered"),
1238 GTK_PARAM_READABLE));
1241 * GtkEntry:progress-border:
1243 * The border around the progress bar in the entry.
1247 gtk_widget_class_install_style_property (widget_class,
1248 g_param_spec_boxed ("progress-border",
1249 P_("Progress Border"),
1250 P_("Border around the progress bar"),
1252 GTK_PARAM_READABLE));
1255 * GtkEntry:invisible-char:
1257 * The invisible character is used when masking entry contents (in
1258 * \"password mode\")"). When it is not explicitly set with the
1259 * #GtkEntry::invisible-char property, GTK+ determines the character
1260 * to use from a list of possible candidates, depending on availability
1261 * in the current font.
1263 * This style property allows the theme to prepend a character
1264 * to the list of candidates.
1268 gtk_widget_class_install_style_property (widget_class,
1269 g_param_spec_unichar ("invisible-char",
1270 P_("Invisible character"),
1271 P_("The character to use when masking entry contents (in \"password mode\")"),
1273 GTK_PARAM_READABLE));
1276 * GtkEntry::populate-popup:
1277 * @entry: The entry on which the signal is emitted
1278 * @menu: the menu that is being populated
1280 * The ::populate-popup signal gets emitted before showing the
1281 * context menu of the entry.
1283 * If you need to add items to the context menu, connect
1284 * to this signal and append your menuitems to the @menu.
1286 signals[POPULATE_POPUP] =
1287 g_signal_new (I_("populate-popup"),
1288 G_OBJECT_CLASS_TYPE (gobject_class),
1290 G_STRUCT_OFFSET (GtkEntryClass, populate_popup),
1292 _gtk_marshal_VOID__OBJECT,
1296 /* Action signals */
1299 * GtkEntry::activate:
1300 * @entry: The entry on which the signal is emitted
1302 * A <link linkend="keybinding-signals">keybinding signal</link>
1303 * which gets emitted when the user activates the entry.
1305 * Applications should not connect to it, but may emit it with
1306 * g_signal_emit_by_name() if they need to control activation
1309 * The default bindings for this signal are all forms of the Enter key.
1312 g_signal_new (I_("activate"),
1313 G_OBJECT_CLASS_TYPE (gobject_class),
1314 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1315 G_STRUCT_OFFSET (GtkEntryClass, activate),
1317 _gtk_marshal_VOID__VOID,
1319 widget_class->activate_signal = signals[ACTIVATE];
1322 * GtkEntry::move-cursor:
1323 * @entry: the object which received the signal
1324 * @step: the granularity of the move, as a #GtkMovementStep
1325 * @count: the number of @step units to move
1326 * @extend_selection: %TRUE if the move should extend the selection
1328 * The ::move-cursor signal is a
1329 * <link linkend="keybinding-signals">keybinding signal</link>
1330 * which gets emitted when the user initiates a cursor movement.
1331 * If the cursor is not visible in @entry, this signal causes
1332 * the viewport to be moved instead.
1334 * Applications should not connect to it, but may emit it with
1335 * g_signal_emit_by_name() if they need to control the cursor
1338 * The default bindings for this signal come in two variants,
1339 * the variant with the Shift modifier extends the selection,
1340 * the variant without the Shift modifer does not.
1341 * There are too many key combinations to list them all here.
1343 * <listitem>Arrow keys move by individual characters/lines</listitem>
1344 * <listitem>Ctrl-arrow key combinations move by words/paragraphs</listitem>
1345 * <listitem>Home/End keys move to the ends of the buffer</listitem>
1348 signals[MOVE_CURSOR] =
1349 g_signal_new (I_("move-cursor"),
1350 G_OBJECT_CLASS_TYPE (gobject_class),
1351 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1352 G_STRUCT_OFFSET (GtkEntryClass, move_cursor),
1354 _gtk_marshal_VOID__ENUM_INT_BOOLEAN,
1356 GTK_TYPE_MOVEMENT_STEP,
1361 * GtkEntry::insert-at-cursor:
1362 * @entry: the object which received the signal
1363 * @string: the string to insert
1365 * The ::insert-at-cursor signal is a
1366 * <link linkend="keybinding-signals">keybinding signal</link>
1367 * which gets emitted when the user initiates the insertion of a
1368 * fixed string at the cursor.
1370 * This signal has no default bindings.
1372 signals[INSERT_AT_CURSOR] =
1373 g_signal_new (I_("insert-at-cursor"),
1374 G_OBJECT_CLASS_TYPE (gobject_class),
1375 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1376 G_STRUCT_OFFSET (GtkEntryClass, insert_at_cursor),
1378 _gtk_marshal_VOID__STRING,
1383 * GtkEntry::delete-from-cursor:
1384 * @entry: the object which received the signal
1385 * @type: the granularity of the deletion, as a #GtkDeleteType
1386 * @count: the number of @type units to delete
1388 * The ::delete-from-cursor signal is a
1389 * <link linkend="keybinding-signals">keybinding signal</link>
1390 * which gets emitted when the user initiates a text deletion.
1392 * If the @type is %GTK_DELETE_CHARS, GTK+ deletes the selection
1393 * if there is one, otherwise it deletes the requested number
1396 * The default bindings for this signal are
1397 * Delete for deleting a character and Ctrl-Delete for
1400 signals[DELETE_FROM_CURSOR] =
1401 g_signal_new (I_("delete-from-cursor"),
1402 G_OBJECT_CLASS_TYPE (gobject_class),
1403 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1404 G_STRUCT_OFFSET (GtkEntryClass, delete_from_cursor),
1406 _gtk_marshal_VOID__ENUM_INT,
1408 GTK_TYPE_DELETE_TYPE,
1412 * GtkEntry::backspace:
1413 * @entry: the object which received the signal
1415 * The ::backspace signal is a
1416 * <link linkend="keybinding-signals">keybinding signal</link>
1417 * which gets emitted when the user asks for it.
1419 * The default bindings for this signal are
1420 * Backspace and Shift-Backspace.
1422 signals[BACKSPACE] =
1423 g_signal_new (I_("backspace"),
1424 G_OBJECT_CLASS_TYPE (gobject_class),
1425 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1426 G_STRUCT_OFFSET (GtkEntryClass, backspace),
1428 _gtk_marshal_VOID__VOID,
1432 * GtkEntry::cut-clipboard:
1433 * @entry: the object which received the signal
1435 * The ::cut-clipboard signal is a
1436 * <link linkend="keybinding-signals">keybinding signal</link>
1437 * which gets emitted to cut the selection to the clipboard.
1439 * The default bindings for this signal are
1440 * Ctrl-x and Shift-Delete.
1442 signals[CUT_CLIPBOARD] =
1443 g_signal_new (I_("cut-clipboard"),
1444 G_OBJECT_CLASS_TYPE (gobject_class),
1445 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1446 G_STRUCT_OFFSET (GtkEntryClass, cut_clipboard),
1448 _gtk_marshal_VOID__VOID,
1452 * GtkEntry::copy-clipboard:
1453 * @entry: the object which received the signal
1455 * The ::copy-clipboard signal is a
1456 * <link linkend="keybinding-signals">keybinding signal</link>
1457 * which gets emitted to copy the selection to the clipboard.
1459 * The default bindings for this signal are
1460 * Ctrl-c and Ctrl-Insert.
1462 signals[COPY_CLIPBOARD] =
1463 g_signal_new (I_("copy-clipboard"),
1464 G_OBJECT_CLASS_TYPE (gobject_class),
1465 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1466 G_STRUCT_OFFSET (GtkEntryClass, copy_clipboard),
1468 _gtk_marshal_VOID__VOID,
1472 * GtkEntry::paste-clipboard:
1473 * @entry: the object which received the signal
1475 * The ::paste-clipboard signal is a
1476 * <link linkend="keybinding-signals">keybinding signal</link>
1477 * which gets emitted to paste the contents of the clipboard
1478 * into the text view.
1480 * The default bindings for this signal are
1481 * Ctrl-v and Shift-Insert.
1483 signals[PASTE_CLIPBOARD] =
1484 g_signal_new (I_("paste-clipboard"),
1485 G_OBJECT_CLASS_TYPE (gobject_class),
1486 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1487 G_STRUCT_OFFSET (GtkEntryClass, paste_clipboard),
1489 _gtk_marshal_VOID__VOID,
1493 * GtkEntry::toggle-overwrite:
1494 * @entry: the object which received the signal
1496 * The ::toggle-overwrite signal is a
1497 * <link linkend="keybinding-signals">keybinding signal</link>
1498 * which gets emitted to toggle the overwrite mode of the entry.
1500 * The default bindings for this signal is Insert.
1502 signals[TOGGLE_OVERWRITE] =
1503 g_signal_new (I_("toggle-overwrite"),
1504 G_OBJECT_CLASS_TYPE (gobject_class),
1505 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1506 G_STRUCT_OFFSET (GtkEntryClass, toggle_overwrite),
1508 _gtk_marshal_VOID__VOID,
1512 * GtkEntry::icon-press:
1513 * @entry: The entry on which the signal is emitted
1514 * @icon_pos: The position of the clicked icon
1515 * @event: the button press event
1517 * The ::icon-press signal is emitted when an activatable icon
1522 signals[ICON_PRESS] =
1523 g_signal_new (I_("icon-press"),
1524 G_TYPE_FROM_CLASS (gobject_class),
1528 _gtk_marshal_VOID__ENUM_BOXED,
1530 GTK_TYPE_ENTRY_ICON_POSITION,
1531 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1534 * GtkEntry::icon-release:
1535 * @entry: The entry on which the signal is emitted
1536 * @icon_pos: The position of the clicked icon
1537 * @event: the button release event
1539 * The ::icon-release signal is emitted on the button release from a
1540 * mouse click over an activatable icon.
1544 signals[ICON_RELEASE] =
1545 g_signal_new (I_("icon-release"),
1546 G_TYPE_FROM_CLASS (gobject_class),
1550 _gtk_marshal_VOID__ENUM_BOXED,
1552 GTK_TYPE_ENTRY_ICON_POSITION,
1553 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1556 * GtkEntry::preedit-changed:
1557 * @entry: the object which received the signal
1558 * @preedit: the current preedit string
1560 * If an input method is used, the typed text will not immediately
1561 * be committed to the buffer. So if you are interested in the text,
1562 * connect to this signal.
1566 signals[PREEDIT_CHANGED] =
1567 g_signal_new_class_handler (I_("preedit-changed"),
1568 G_OBJECT_CLASS_TYPE (gobject_class),
1569 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1572 _gtk_marshal_VOID__STRING,
1581 binding_set = gtk_binding_set_by_class (class);
1583 /* Moving the insertion point */
1584 add_move_binding (binding_set, GDK_Right, 0,
1585 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1587 add_move_binding (binding_set, GDK_Left, 0,
1588 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1590 add_move_binding (binding_set, GDK_KP_Right, 0,
1591 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1593 add_move_binding (binding_set, GDK_KP_Left, 0,
1594 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1596 add_move_binding (binding_set, GDK_Right, GDK_CONTROL_MASK,
1597 GTK_MOVEMENT_WORDS, 1);
1599 add_move_binding (binding_set, GDK_Left, GDK_CONTROL_MASK,
1600 GTK_MOVEMENT_WORDS, -1);
1602 add_move_binding (binding_set, GDK_KP_Right, GDK_CONTROL_MASK,
1603 GTK_MOVEMENT_WORDS, 1);
1605 add_move_binding (binding_set, GDK_KP_Left, GDK_CONTROL_MASK,
1606 GTK_MOVEMENT_WORDS, -1);
1608 add_move_binding (binding_set, GDK_Home, 0,
1609 GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
1611 add_move_binding (binding_set, GDK_End, 0,
1612 GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
1614 add_move_binding (binding_set, GDK_KP_Home, 0,
1615 GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
1617 add_move_binding (binding_set, GDK_KP_End, 0,
1618 GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
1620 add_move_binding (binding_set, GDK_Home, GDK_CONTROL_MASK,
1621 GTK_MOVEMENT_BUFFER_ENDS, -1);
1623 add_move_binding (binding_set, GDK_End, GDK_CONTROL_MASK,
1624 GTK_MOVEMENT_BUFFER_ENDS, 1);
1626 add_move_binding (binding_set, GDK_KP_Home, GDK_CONTROL_MASK,
1627 GTK_MOVEMENT_BUFFER_ENDS, -1);
1629 add_move_binding (binding_set, GDK_KP_End, GDK_CONTROL_MASK,
1630 GTK_MOVEMENT_BUFFER_ENDS, 1);
1634 gtk_binding_entry_add_signal (binding_set, GDK_a, GDK_CONTROL_MASK,
1636 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1638 G_TYPE_BOOLEAN, FALSE);
1639 gtk_binding_entry_add_signal (binding_set, GDK_a, GDK_CONTROL_MASK,
1641 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1643 G_TYPE_BOOLEAN, TRUE);
1645 gtk_binding_entry_add_signal (binding_set, GDK_slash, GDK_CONTROL_MASK,
1647 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1649 G_TYPE_BOOLEAN, FALSE);
1650 gtk_binding_entry_add_signal (binding_set, GDK_slash, GDK_CONTROL_MASK,
1652 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1654 G_TYPE_BOOLEAN, TRUE);
1657 gtk_binding_entry_add_signal (binding_set, GDK_backslash, GDK_CONTROL_MASK,
1659 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_VISUAL_POSITIONS,
1661 G_TYPE_BOOLEAN, FALSE);
1662 gtk_binding_entry_add_signal (binding_set, GDK_a, GDK_SHIFT_MASK | GDK_CONTROL_MASK,
1664 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_VISUAL_POSITIONS,
1666 G_TYPE_BOOLEAN, FALSE);
1670 gtk_binding_entry_add_signal (binding_set, GDK_Return, 0,
1672 gtk_binding_entry_add_signal (binding_set, GDK_ISO_Enter, 0,
1674 gtk_binding_entry_add_signal (binding_set, GDK_KP_Enter, 0,
1678 gtk_binding_entry_add_signal (binding_set, GDK_Delete, 0,
1679 "delete-from-cursor", 2,
1680 G_TYPE_ENUM, GTK_DELETE_CHARS,
1683 gtk_binding_entry_add_signal (binding_set, GDK_KP_Delete, 0,
1684 "delete-from-cursor", 2,
1685 G_TYPE_ENUM, GTK_DELETE_CHARS,
1688 gtk_binding_entry_add_signal (binding_set, GDK_BackSpace, 0,
1691 /* Make this do the same as Backspace, to help with mis-typing */
1692 gtk_binding_entry_add_signal (binding_set, GDK_BackSpace, GDK_SHIFT_MASK,
1695 gtk_binding_entry_add_signal (binding_set, GDK_Delete, GDK_CONTROL_MASK,
1696 "delete-from-cursor", 2,
1697 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1700 gtk_binding_entry_add_signal (binding_set, GDK_KP_Delete, GDK_CONTROL_MASK,
1701 "delete-from-cursor", 2,
1702 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1705 gtk_binding_entry_add_signal (binding_set, GDK_BackSpace, GDK_CONTROL_MASK,
1706 "delete-from-cursor", 2,
1707 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1710 /* Cut/copy/paste */
1712 gtk_binding_entry_add_signal (binding_set, GDK_x, GDK_CONTROL_MASK,
1713 "cut-clipboard", 0);
1714 gtk_binding_entry_add_signal (binding_set, GDK_c, GDK_CONTROL_MASK,
1715 "copy-clipboard", 0);
1716 gtk_binding_entry_add_signal (binding_set, GDK_v, GDK_CONTROL_MASK,
1717 "paste-clipboard", 0);
1719 gtk_binding_entry_add_signal (binding_set, GDK_Delete, GDK_SHIFT_MASK,
1720 "cut-clipboard", 0);
1721 gtk_binding_entry_add_signal (binding_set, GDK_Insert, GDK_CONTROL_MASK,
1722 "copy-clipboard", 0);
1723 gtk_binding_entry_add_signal (binding_set, GDK_Insert, GDK_SHIFT_MASK,
1724 "paste-clipboard", 0);
1727 gtk_binding_entry_add_signal (binding_set, GDK_Insert, 0,
1728 "toggle-overwrite", 0);
1729 gtk_binding_entry_add_signal (binding_set, GDK_KP_Insert, 0,
1730 "toggle-overwrite", 0);
1733 * GtkEntry:inner-border:
1735 * Sets the text area's border between the text and the frame.
1739 gtk_widget_class_install_style_property (widget_class,
1740 g_param_spec_boxed ("inner-border",
1742 P_("Border between text and frame."),
1744 GTK_PARAM_READABLE));
1747 * GtkEntry:state-hint:
1749 * Indicates whether to pass a proper widget state when
1750 * drawing the shadow and the widget background.
1754 gtk_widget_class_install_style_property (widget_class,
1755 g_param_spec_boolean ("state-hint",
1757 P_("Whether to pass a proper state when drawing shadow or background"),
1759 GTK_PARAM_READABLE));
1761 gtk_settings_install_property (g_param_spec_boolean ("gtk-entry-select-on-focus",
1762 P_("Select on focus"),
1763 P_("Whether to select the contents of an entry when it is focused"),
1765 GTK_PARAM_READWRITE));
1768 * GtkSettings:gtk-entry-password-hint-timeout:
1770 * How long to show the last input character in hidden
1771 * entries. This value is in milliseconds. 0 disables showing the
1772 * last char. 600 is a good value for enabling it.
1776 gtk_settings_install_property (g_param_spec_uint ("gtk-entry-password-hint-timeout",
1777 P_("Password Hint Timeout"),
1778 P_("How long to show the last input character in hidden entries"),
1780 GTK_PARAM_READWRITE));
1782 g_type_class_add_private (gobject_class, sizeof (GtkEntryPrivate));
1786 gtk_entry_editable_init (GtkEditableClass *iface)
1788 iface->do_insert_text = gtk_entry_insert_text;
1789 iface->do_delete_text = gtk_entry_delete_text;
1790 iface->insert_text = gtk_entry_real_insert_text;
1791 iface->delete_text = gtk_entry_real_delete_text;
1792 iface->get_chars = gtk_entry_get_chars;
1793 iface->set_selection_bounds = gtk_entry_set_selection_bounds;
1794 iface->get_selection_bounds = gtk_entry_get_selection_bounds;
1795 iface->set_position = gtk_entry_real_set_position;
1796 iface->get_position = gtk_entry_get_position;
1800 gtk_entry_cell_editable_init (GtkCellEditableIface *iface)
1802 iface->start_editing = gtk_entry_start_editing;
1806 gtk_entry_set_property (GObject *object,
1808 const GValue *value,
1811 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (object);
1812 GtkEntry *entry = GTK_ENTRY (object);
1818 gtk_entry_set_buffer (entry, g_value_get_object (value));
1823 gboolean new_value = g_value_get_boolean (value);
1825 if (new_value != entry->editable)
1827 widget = GTK_WIDGET (entry);
1830 _gtk_entry_reset_im_context (entry);
1831 if (gtk_widget_has_focus (widget))
1832 gtk_im_context_focus_out (entry->im_context);
1834 entry->preedit_length = 0;
1835 entry->preedit_cursor = 0;
1838 entry->editable = new_value;
1840 if (new_value && gtk_widget_has_focus (widget))
1841 gtk_im_context_focus_in (entry->im_context);
1843 gtk_entry_queue_draw (entry);
1848 case PROP_MAX_LENGTH:
1849 gtk_entry_set_max_length (entry, g_value_get_int (value));
1852 case PROP_VISIBILITY:
1853 gtk_entry_set_visibility (entry, g_value_get_boolean (value));
1856 case PROP_HAS_FRAME:
1857 gtk_entry_set_has_frame (entry, g_value_get_boolean (value));
1860 case PROP_INNER_BORDER:
1861 gtk_entry_set_inner_border (entry, g_value_get_boxed (value));
1864 case PROP_INVISIBLE_CHAR:
1865 gtk_entry_set_invisible_char (entry, g_value_get_uint (value));
1868 case PROP_ACTIVATES_DEFAULT:
1869 gtk_entry_set_activates_default (entry, g_value_get_boolean (value));
1872 case PROP_WIDTH_CHARS:
1873 gtk_entry_set_width_chars (entry, g_value_get_int (value));
1877 gtk_entry_set_text (entry, g_value_get_string (value));
1881 gtk_entry_set_alignment (entry, g_value_get_float (value));
1884 case PROP_TRUNCATE_MULTILINE:
1885 entry->truncate_multiline = g_value_get_boolean (value);
1888 case PROP_SHADOW_TYPE:
1889 priv->shadow_type = g_value_get_enum (value);
1892 case PROP_OVERWRITE_MODE:
1893 gtk_entry_set_overwrite_mode (entry, g_value_get_boolean (value));
1896 case PROP_INVISIBLE_CHAR_SET:
1897 if (g_value_get_boolean (value))
1898 priv->invisible_char_set = TRUE;
1900 gtk_entry_unset_invisible_char (entry);
1903 case PROP_CAPS_LOCK_WARNING:
1904 priv->caps_lock_warning = g_value_get_boolean (value);
1907 case PROP_PROGRESS_FRACTION:
1908 gtk_entry_set_progress_fraction (entry, g_value_get_double (value));
1911 case PROP_PROGRESS_PULSE_STEP:
1912 gtk_entry_set_progress_pulse_step (entry, g_value_get_double (value));
1915 case PROP_PIXBUF_PRIMARY:
1916 gtk_entry_set_icon_from_pixbuf (entry,
1917 GTK_ENTRY_ICON_PRIMARY,
1918 g_value_get_object (value));
1921 case PROP_PIXBUF_SECONDARY:
1922 gtk_entry_set_icon_from_pixbuf (entry,
1923 GTK_ENTRY_ICON_SECONDARY,
1924 g_value_get_object (value));
1927 case PROP_STOCK_PRIMARY:
1928 gtk_entry_set_icon_from_stock (entry,
1929 GTK_ENTRY_ICON_PRIMARY,
1930 g_value_get_string (value));
1933 case PROP_STOCK_SECONDARY:
1934 gtk_entry_set_icon_from_stock (entry,
1935 GTK_ENTRY_ICON_SECONDARY,
1936 g_value_get_string (value));
1939 case PROP_ICON_NAME_PRIMARY:
1940 gtk_entry_set_icon_from_icon_name (entry,
1941 GTK_ENTRY_ICON_PRIMARY,
1942 g_value_get_string (value));
1945 case PROP_ICON_NAME_SECONDARY:
1946 gtk_entry_set_icon_from_icon_name (entry,
1947 GTK_ENTRY_ICON_SECONDARY,
1948 g_value_get_string (value));
1951 case PROP_GICON_PRIMARY:
1952 gtk_entry_set_icon_from_gicon (entry,
1953 GTK_ENTRY_ICON_PRIMARY,
1954 g_value_get_object (value));
1957 case PROP_GICON_SECONDARY:
1958 gtk_entry_set_icon_from_gicon (entry,
1959 GTK_ENTRY_ICON_SECONDARY,
1960 g_value_get_object (value));
1963 case PROP_ACTIVATABLE_PRIMARY:
1964 gtk_entry_set_icon_activatable (entry,
1965 GTK_ENTRY_ICON_PRIMARY,
1966 g_value_get_boolean (value));
1969 case PROP_ACTIVATABLE_SECONDARY:
1970 gtk_entry_set_icon_activatable (entry,
1971 GTK_ENTRY_ICON_SECONDARY,
1972 g_value_get_boolean (value));
1975 case PROP_SENSITIVE_PRIMARY:
1976 gtk_entry_set_icon_sensitive (entry,
1977 GTK_ENTRY_ICON_PRIMARY,
1978 g_value_get_boolean (value));
1981 case PROP_SENSITIVE_SECONDARY:
1982 gtk_entry_set_icon_sensitive (entry,
1983 GTK_ENTRY_ICON_SECONDARY,
1984 g_value_get_boolean (value));
1987 case PROP_TOOLTIP_TEXT_PRIMARY:
1988 gtk_entry_set_icon_tooltip_text (entry,
1989 GTK_ENTRY_ICON_PRIMARY,
1990 g_value_get_string (value));
1993 case PROP_TOOLTIP_TEXT_SECONDARY:
1994 gtk_entry_set_icon_tooltip_text (entry,
1995 GTK_ENTRY_ICON_SECONDARY,
1996 g_value_get_string (value));
1999 case PROP_TOOLTIP_MARKUP_PRIMARY:
2000 gtk_entry_set_icon_tooltip_markup (entry,
2001 GTK_ENTRY_ICON_PRIMARY,
2002 g_value_get_string (value));
2005 case PROP_TOOLTIP_MARKUP_SECONDARY:
2006 gtk_entry_set_icon_tooltip_markup (entry,
2007 GTK_ENTRY_ICON_SECONDARY,
2008 g_value_get_string (value));
2011 case PROP_IM_MODULE:
2012 g_free (priv->im_module);
2013 priv->im_module = g_value_dup_string (value);
2014 if (GTK_IS_IM_MULTICONTEXT (entry->im_context))
2015 gtk_im_multicontext_set_context_id (GTK_IM_MULTICONTEXT (entry->im_context), priv->im_module);
2018 case PROP_EDITING_CANCELED:
2019 entry->editing_canceled = g_value_get_boolean (value);
2022 case PROP_SCROLL_OFFSET:
2023 case PROP_CURSOR_POSITION:
2025 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2031 gtk_entry_get_property (GObject *object,
2036 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (object);
2037 GtkEntry *entry = GTK_ENTRY (object);
2042 g_value_set_object (value, gtk_entry_get_buffer (entry));
2045 case PROP_CURSOR_POSITION:
2046 g_value_set_int (value, entry->current_pos);
2049 case PROP_SELECTION_BOUND:
2050 g_value_set_int (value, entry->selection_bound);
2054 g_value_set_boolean (value, entry->editable);
2057 case PROP_MAX_LENGTH:
2058 g_value_set_int (value, gtk_entry_buffer_get_max_length (get_buffer (entry)));
2061 case PROP_VISIBILITY:
2062 g_value_set_boolean (value, entry->visible);
2065 case PROP_HAS_FRAME:
2066 g_value_set_boolean (value, entry->has_frame);
2069 case PROP_INNER_BORDER:
2070 g_value_set_boxed (value, gtk_entry_get_inner_border (entry));
2073 case PROP_INVISIBLE_CHAR:
2074 g_value_set_uint (value, entry->invisible_char);
2077 case PROP_ACTIVATES_DEFAULT:
2078 g_value_set_boolean (value, entry->activates_default);
2081 case PROP_WIDTH_CHARS:
2082 g_value_set_int (value, entry->width_chars);
2085 case PROP_SCROLL_OFFSET:
2086 g_value_set_int (value, entry->scroll_offset);
2090 g_value_set_string (value, gtk_entry_get_text (entry));
2094 g_value_set_float (value, gtk_entry_get_alignment (entry));
2097 case PROP_TRUNCATE_MULTILINE:
2098 g_value_set_boolean (value, entry->truncate_multiline);
2101 case PROP_SHADOW_TYPE:
2102 g_value_set_enum (value, priv->shadow_type);
2105 case PROP_OVERWRITE_MODE:
2106 g_value_set_boolean (value, entry->overwrite_mode);
2109 case PROP_TEXT_LENGTH:
2110 g_value_set_uint (value, gtk_entry_buffer_get_length (get_buffer (entry)));
2113 case PROP_INVISIBLE_CHAR_SET:
2114 g_value_set_boolean (value, priv->invisible_char_set);
2117 case PROP_IM_MODULE:
2118 g_value_set_string (value, priv->im_module);
2121 case PROP_CAPS_LOCK_WARNING:
2122 g_value_set_boolean (value, priv->caps_lock_warning);
2125 case PROP_PROGRESS_FRACTION:
2126 g_value_set_double (value, priv->progress_fraction);
2129 case PROP_PROGRESS_PULSE_STEP:
2130 g_value_set_double (value, priv->progress_pulse_fraction);
2133 case PROP_PIXBUF_PRIMARY:
2134 g_value_set_object (value,
2135 gtk_entry_get_icon_pixbuf (entry,
2136 GTK_ENTRY_ICON_PRIMARY));
2139 case PROP_PIXBUF_SECONDARY:
2140 g_value_set_object (value,
2141 gtk_entry_get_icon_pixbuf (entry,
2142 GTK_ENTRY_ICON_SECONDARY));
2145 case PROP_STOCK_PRIMARY:
2146 g_value_set_string (value,
2147 gtk_entry_get_icon_stock (entry,
2148 GTK_ENTRY_ICON_PRIMARY));
2151 case PROP_STOCK_SECONDARY:
2152 g_value_set_string (value,
2153 gtk_entry_get_icon_stock (entry,
2154 GTK_ENTRY_ICON_SECONDARY));
2157 case PROP_ICON_NAME_PRIMARY:
2158 g_value_set_string (value,
2159 gtk_entry_get_icon_name (entry,
2160 GTK_ENTRY_ICON_PRIMARY));
2163 case PROP_ICON_NAME_SECONDARY:
2164 g_value_set_string (value,
2165 gtk_entry_get_icon_name (entry,
2166 GTK_ENTRY_ICON_SECONDARY));
2169 case PROP_GICON_PRIMARY:
2170 g_value_set_object (value,
2171 gtk_entry_get_icon_gicon (entry,
2172 GTK_ENTRY_ICON_PRIMARY));
2175 case PROP_GICON_SECONDARY:
2176 g_value_set_object (value,
2177 gtk_entry_get_icon_gicon (entry,
2178 GTK_ENTRY_ICON_SECONDARY));
2181 case PROP_STORAGE_TYPE_PRIMARY:
2182 g_value_set_enum (value,
2183 gtk_entry_get_icon_storage_type (entry,
2184 GTK_ENTRY_ICON_PRIMARY));
2187 case PROP_STORAGE_TYPE_SECONDARY:
2188 g_value_set_enum (value,
2189 gtk_entry_get_icon_storage_type (entry,
2190 GTK_ENTRY_ICON_SECONDARY));
2193 case PROP_ACTIVATABLE_PRIMARY:
2194 g_value_set_boolean (value,
2195 gtk_entry_get_icon_activatable (entry, GTK_ENTRY_ICON_PRIMARY));
2198 case PROP_ACTIVATABLE_SECONDARY:
2199 g_value_set_boolean (value,
2200 gtk_entry_get_icon_activatable (entry, GTK_ENTRY_ICON_SECONDARY));
2203 case PROP_SENSITIVE_PRIMARY:
2204 g_value_set_boolean (value,
2205 gtk_entry_get_icon_sensitive (entry, GTK_ENTRY_ICON_PRIMARY));
2208 case PROP_SENSITIVE_SECONDARY:
2209 g_value_set_boolean (value,
2210 gtk_entry_get_icon_sensitive (entry, GTK_ENTRY_ICON_SECONDARY));
2213 case PROP_TOOLTIP_TEXT_PRIMARY:
2214 g_value_take_string (value,
2215 gtk_entry_get_icon_tooltip_text (entry, GTK_ENTRY_ICON_PRIMARY));
2218 case PROP_TOOLTIP_TEXT_SECONDARY:
2219 g_value_take_string (value,
2220 gtk_entry_get_icon_tooltip_text (entry, GTK_ENTRY_ICON_SECONDARY));
2223 case PROP_TOOLTIP_MARKUP_PRIMARY:
2224 g_value_take_string (value,
2225 gtk_entry_get_icon_tooltip_markup (entry, GTK_ENTRY_ICON_PRIMARY));
2228 case PROP_TOOLTIP_MARKUP_SECONDARY:
2229 g_value_take_string (value,
2230 gtk_entry_get_icon_tooltip_markup (entry, GTK_ENTRY_ICON_SECONDARY));
2233 case PROP_EDITING_CANCELED:
2234 g_value_set_boolean (value,
2235 entry->editing_canceled);
2239 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2245 find_invisible_char (GtkWidget *widget)
2247 PangoLayout *layout;
2248 PangoAttrList *attr_list;
2250 gunichar invisible_chars [] = {
2252 0x25cf, /* BLACK CIRCLE */
2253 0x2022, /* BULLET */
2254 0x2731, /* HEAVY ASTERISK */
2255 0x273a /* SIXTEEN POINTED ASTERISK */
2259 gtk_widget_style_get (widget,
2260 "invisible-char", &invisible_chars[0],
2263 layout = gtk_widget_create_pango_layout (widget, NULL);
2265 attr_list = pango_attr_list_new ();
2266 pango_attr_list_insert (attr_list, pango_attr_fallback_new (FALSE));
2268 pango_layout_set_attributes (layout, attr_list);
2269 pango_attr_list_unref (attr_list);
2271 for (i = (invisible_chars[0] != 0 ? 0 : 1); i < G_N_ELEMENTS (invisible_chars); i++)
2273 gchar text[7] = { 0, };
2276 len = g_unichar_to_utf8 (invisible_chars[i], text);
2277 pango_layout_set_text (layout, text, len);
2279 count = pango_layout_get_unknown_glyphs_count (layout);
2283 g_object_unref (layout);
2284 return invisible_chars[i];
2288 g_object_unref (layout);
2294 gtk_entry_init (GtkEntry *entry)
2296 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2298 gtk_widget_set_can_focus (GTK_WIDGET (entry), TRUE);
2300 entry->editable = TRUE;
2301 entry->visible = TRUE;
2302 entry->invisible_char = find_invisible_char (GTK_WIDGET (entry));
2303 entry->dnd_position = -1;
2304 entry->width_chars = -1;
2305 entry->is_cell_renderer = FALSE;
2306 entry->editing_canceled = FALSE;
2307 entry->has_frame = TRUE;
2308 entry->truncate_multiline = FALSE;
2309 priv->shadow_type = GTK_SHADOW_IN;
2311 priv->caps_lock_warning = TRUE;
2312 priv->caps_lock_warning_shown = FALSE;
2313 priv->progress_fraction = 0.0;
2314 priv->progress_pulse_fraction = 0.1;
2316 gtk_drag_dest_set (GTK_WIDGET (entry),
2317 GTK_DEST_DEFAULT_HIGHLIGHT,
2319 GDK_ACTION_COPY | GDK_ACTION_MOVE);
2320 gtk_drag_dest_add_text_targets (GTK_WIDGET (entry));
2322 /* This object is completely private. No external entity can gain a reference
2323 * to it; so we create it here and destroy it in finalize().
2325 entry->im_context = gtk_im_multicontext_new ();
2327 g_signal_connect (entry->im_context, "commit",
2328 G_CALLBACK (gtk_entry_commit_cb), entry);
2329 g_signal_connect (entry->im_context, "preedit-changed",
2330 G_CALLBACK (gtk_entry_preedit_changed_cb), entry);
2331 g_signal_connect (entry->im_context, "retrieve-surrounding",
2332 G_CALLBACK (gtk_entry_retrieve_surrounding_cb), entry);
2333 g_signal_connect (entry->im_context, "delete-surrounding",
2334 G_CALLBACK (gtk_entry_delete_surrounding_cb), entry);
2339 get_icon_width (GtkEntry *entry,
2340 GtkEntryIconPosition icon_pos)
2342 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2343 EntryIconInfo *icon_info = priv->icons[icon_pos];
2345 GtkSettings *settings;
2346 gint menu_icon_width;
2348 if (!icon_info || icon_info->pixbuf == NULL)
2351 screen = gtk_widget_get_screen (GTK_WIDGET (entry));
2352 settings = gtk_settings_get_for_screen (screen);
2354 gtk_icon_size_lookup_for_settings (settings, GTK_ICON_SIZE_MENU,
2355 &menu_icon_width, NULL);
2357 return MAX (gdk_pixbuf_get_width (icon_info->pixbuf), menu_icon_width);
2361 get_icon_allocations (GtkEntry *entry,
2362 GtkAllocation *primary,
2363 GtkAllocation *secondary)
2366 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2367 gint x, y, width, height;
2369 get_text_area_size (entry, &x, &y, &width, &height);
2371 if (gtk_widget_has_focus (GTK_WIDGET (entry)) && !priv->interior_focus)
2372 y += priv->focus_width;
2375 primary->height = height;
2376 primary->width = get_icon_width (entry, GTK_ENTRY_ICON_PRIMARY);
2377 if (primary->width > 0)
2378 primary->width += 2 * priv->icon_margin;
2381 secondary->height = height;
2382 secondary->width = get_icon_width (entry, GTK_ENTRY_ICON_SECONDARY);
2383 if (secondary->width > 0)
2384 secondary->width += 2 * priv->icon_margin;
2386 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
2388 primary->x = x + width - primary->width;
2394 secondary->x = x + width - secondary->width;
2400 begin_change (GtkEntry *entry)
2402 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2404 priv->change_count++;
2408 end_change (GtkEntry *entry)
2410 GtkEditable *editable = GTK_EDITABLE (entry);
2411 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2413 g_return_if_fail (priv->change_count > 0);
2415 priv->change_count--;
2417 if (priv->change_count == 0)
2419 if (priv->real_changed)
2421 g_signal_emit_by_name (editable, "changed");
2422 priv->real_changed = FALSE;
2428 emit_changed (GtkEntry *entry)
2430 GtkEditable *editable = GTK_EDITABLE (entry);
2431 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2433 if (priv->change_count == 0)
2434 g_signal_emit_by_name (editable, "changed");
2436 priv->real_changed = TRUE;
2440 gtk_entry_destroy (GtkObject *object)
2442 GtkEntry *entry = GTK_ENTRY (object);
2444 entry->current_pos = entry->selection_bound = 0;
2445 _gtk_entry_reset_im_context (entry);
2446 gtk_entry_reset_layout (entry);
2448 if (entry->blink_timeout)
2450 g_source_remove (entry->blink_timeout);
2451 entry->blink_timeout = 0;
2454 if (entry->recompute_idle)
2456 g_source_remove (entry->recompute_idle);
2457 entry->recompute_idle = 0;
2460 GTK_OBJECT_CLASS (gtk_entry_parent_class)->destroy (object);
2464 gtk_entry_dispose (GObject *object)
2466 GtkEntry *entry = GTK_ENTRY (object);
2467 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2469 gtk_entry_set_icon_from_pixbuf (entry, GTK_ENTRY_ICON_PRIMARY, NULL);
2470 gtk_entry_set_icon_tooltip_markup (entry, GTK_ENTRY_ICON_PRIMARY, NULL);
2471 gtk_entry_set_icon_from_pixbuf (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
2472 gtk_entry_set_icon_tooltip_markup (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
2476 buffer_disconnect_signals (entry);
2477 g_object_unref (priv->buffer);
2478 priv->buffer = NULL;
2481 G_OBJECT_CLASS (gtk_entry_parent_class)->dispose (object);
2485 gtk_entry_finalize (GObject *object)
2487 GtkEntry *entry = GTK_ENTRY (object);
2488 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2489 EntryIconInfo *icon_info = NULL;
2492 for (i = 0; i < MAX_ICONS; i++)
2494 if ((icon_info = priv->icons[i]) != NULL)
2496 if (icon_info->target_list != NULL)
2498 gtk_target_list_unref (icon_info->target_list);
2499 icon_info->target_list = NULL;
2502 g_slice_free (EntryIconInfo, icon_info);
2503 priv->icons[i] = NULL;
2507 gtk_entry_set_completion (entry, NULL);
2509 if (entry->cached_layout)
2510 g_object_unref (entry->cached_layout);
2512 g_object_unref (entry->im_context);
2514 if (entry->blink_timeout)
2515 g_source_remove (entry->blink_timeout);
2517 if (entry->recompute_idle)
2518 g_source_remove (entry->recompute_idle);
2520 g_free (priv->im_module);
2522 G_OBJECT_CLASS (gtk_entry_parent_class)->finalize (object);
2526 gtk_entry_get_display_mode (GtkEntry *entry)
2528 GtkEntryPrivate *priv;
2530 return DISPLAY_NORMAL;
2531 priv = GTK_ENTRY_GET_PRIVATE (entry);
2532 if (entry->invisible_char == 0 && priv->invisible_char_set)
2533 return DISPLAY_BLANK;
2534 return DISPLAY_INVISIBLE;
2538 gtk_entry_get_display_text (GtkEntry *entry,
2542 GtkEntryPasswordHint *password_hint;
2543 GtkEntryPrivate *priv;
2544 gunichar invisible_char;
2554 priv = GTK_ENTRY_GET_PRIVATE (entry);
2555 text = gtk_entry_buffer_get_text (get_buffer (entry));
2556 length = gtk_entry_buffer_get_length (get_buffer (entry));
2560 if (start_pos > length)
2563 if (end_pos <= start_pos)
2564 return g_strdup ("");
2565 else if (entry->visible)
2567 start = g_utf8_offset_to_pointer (text, start_pos);
2568 end = g_utf8_offset_to_pointer (start, end_pos - start_pos);
2569 return g_strndup (start, end - start);
2573 str = g_string_sized_new (length * 2);
2575 /* Figure out what our invisible char is and encode it */
2576 if (!entry->invisible_char)
2577 invisible_char = priv->invisible_char_set ? ' ' : '*';
2579 invisible_char = entry->invisible_char;
2580 char_len = g_unichar_to_utf8 (invisible_char, char_str);
2583 * Add hidden characters for each character in the text
2584 * buffer. If there is a password hint, then keep that
2585 * character visible.
2588 password_hint = g_object_get_qdata (G_OBJECT (entry), quark_password_hint);
2589 for (i = start_pos; i < end_pos; ++i)
2591 if (password_hint && i == password_hint->position)
2593 start = g_utf8_offset_to_pointer (text, i);
2594 g_string_append_len (str, start, g_utf8_next_char (start) - start);
2598 g_string_append_len (str, char_str, char_len);
2602 return g_string_free (str, FALSE);
2608 update_cursors (GtkWidget *widget)
2610 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2611 EntryIconInfo *icon_info = NULL;
2612 GdkDisplay *display;
2616 for (i = 0; i < MAX_ICONS; i++)
2618 if ((icon_info = priv->icons[i]) != NULL)
2620 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
2621 gdk_window_show_unraised (icon_info->window);
2623 /* The icon windows are not children of the visible entry window,
2624 * thus we can't just inherit the xterm cursor. Slight complication
2625 * here is that for the entry, insensitive => arrow cursor, but for
2626 * an icon in a sensitive entry, insensitive => xterm cursor.
2628 if (gtk_widget_is_sensitive (widget) &&
2629 (icon_info->insensitive ||
2630 (icon_info->nonactivatable && icon_info->target_list == NULL)))
2632 display = gtk_widget_get_display (widget);
2633 cursor = gdk_cursor_new_for_display (display, GDK_XTERM);
2634 gdk_window_set_cursor (icon_info->window, cursor);
2635 gdk_cursor_unref (cursor);
2639 gdk_window_set_cursor (icon_info->window, NULL);
2646 realize_icon_info (GtkWidget *widget,
2647 GtkEntryIconPosition icon_pos)
2649 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2650 EntryIconInfo *icon_info = priv->icons[icon_pos];
2651 GdkWindowAttr attributes;
2652 gint attributes_mask;
2654 g_return_if_fail (icon_info != NULL);
2658 attributes.width = 1;
2659 attributes.height = 1;
2660 attributes.window_type = GDK_WINDOW_CHILD;
2661 attributes.wclass = GDK_INPUT_OUTPUT;
2662 attributes.visual = gtk_widget_get_visual (widget);
2663 attributes.colormap = gtk_widget_get_colormap (widget);
2664 attributes.event_mask = gtk_widget_get_events (widget);
2665 attributes.event_mask |= (GDK_EXPOSURE_MASK |
2666 GDK_BUTTON_PRESS_MASK |
2667 GDK_BUTTON_RELEASE_MASK |
2668 GDK_BUTTON1_MOTION_MASK |
2669 GDK_BUTTON3_MOTION_MASK |
2670 GDK_POINTER_MOTION_HINT_MASK |
2671 GDK_POINTER_MOTION_MASK |
2672 GDK_ENTER_NOTIFY_MASK |
2673 GDK_LEAVE_NOTIFY_MASK);
2674 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
2676 icon_info->window = gdk_window_new (widget->window,
2679 gdk_window_set_user_data (icon_info->window, widget);
2680 gdk_window_set_background (icon_info->window,
2681 &widget->style->base[gtk_widget_get_state (widget)]);
2683 gtk_widget_queue_resize (widget);
2686 static EntryIconInfo*
2687 construct_icon_info (GtkWidget *widget,
2688 GtkEntryIconPosition icon_pos)
2690 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2691 EntryIconInfo *icon_info;
2693 g_return_val_if_fail (priv->icons[icon_pos] == NULL, NULL);
2695 icon_info = g_slice_new0 (EntryIconInfo);
2696 priv->icons[icon_pos] = icon_info;
2698 if (gtk_widget_get_realized (widget))
2699 realize_icon_info (widget, icon_pos);
2705 gtk_entry_map (GtkWidget *widget)
2707 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2708 EntryIconInfo *icon_info = NULL;
2711 if (gtk_widget_get_realized (widget) && !gtk_widget_get_mapped (widget))
2713 GTK_WIDGET_CLASS (gtk_entry_parent_class)->map (widget);
2715 for (i = 0; i < MAX_ICONS; i++)
2717 if ((icon_info = priv->icons[i]) != NULL)
2719 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
2720 gdk_window_show (icon_info->window);
2724 update_cursors (widget);
2729 gtk_entry_unmap (GtkWidget *widget)
2731 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2732 EntryIconInfo *icon_info = NULL;
2735 if (gtk_widget_get_mapped (widget))
2737 for (i = 0; i < MAX_ICONS; i++)
2739 if ((icon_info = priv->icons[i]) != NULL)
2741 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
2742 gdk_window_hide (icon_info->window);
2746 GTK_WIDGET_CLASS (gtk_entry_parent_class)->unmap (widget);
2751 gtk_entry_realize (GtkWidget *widget)
2754 GtkEntryPrivate *priv;
2755 EntryIconInfo *icon_info;
2756 GdkWindowAttr attributes;
2757 gint attributes_mask;
2760 gtk_widget_set_realized (widget, TRUE);
2761 entry = GTK_ENTRY (widget);
2762 priv = GTK_ENTRY_GET_PRIVATE (entry);
2764 attributes.window_type = GDK_WINDOW_CHILD;
2766 get_widget_window_size (entry, &attributes.x, &attributes.y, &attributes.width, &attributes.height);
2768 attributes.wclass = GDK_INPUT_OUTPUT;
2769 attributes.visual = gtk_widget_get_visual (widget);
2770 attributes.colormap = gtk_widget_get_colormap (widget);
2771 attributes.event_mask = gtk_widget_get_events (widget);
2772 attributes.event_mask |= (GDK_EXPOSURE_MASK |
2773 GDK_BUTTON_PRESS_MASK |
2774 GDK_BUTTON_RELEASE_MASK |
2775 GDK_BUTTON1_MOTION_MASK |
2776 GDK_BUTTON3_MOTION_MASK |
2777 GDK_POINTER_MOTION_HINT_MASK |
2778 GDK_POINTER_MOTION_MASK |
2779 GDK_ENTER_NOTIFY_MASK |
2780 GDK_LEAVE_NOTIFY_MASK);
2781 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
2783 widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, attributes_mask);
2784 gdk_window_set_user_data (widget->window, entry);
2786 get_text_area_size (entry, &attributes.x, &attributes.y, &attributes.width, &attributes.height);
2788 if (gtk_widget_is_sensitive (widget))
2790 attributes.cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
2791 attributes_mask |= GDK_WA_CURSOR;
2794 entry->text_area = gdk_window_new (widget->window, &attributes, attributes_mask);
2796 gdk_window_set_user_data (entry->text_area, entry);
2798 if (attributes_mask & GDK_WA_CURSOR)
2799 gdk_cursor_unref (attributes.cursor);
2801 widget->style = gtk_style_attach (widget->style, widget->window);
2803 gdk_window_set_background (widget->window, &widget->style->base[gtk_widget_get_state (widget)]);
2804 gdk_window_set_background (entry->text_area, &widget->style->base[gtk_widget_get_state (widget)]);
2806 gdk_window_show (entry->text_area);
2808 gtk_im_context_set_client_window (entry->im_context, entry->text_area);
2810 gtk_entry_adjust_scroll (entry);
2811 gtk_entry_update_primary_selection (entry);
2814 /* If the icon positions are already setup, create their windows.
2815 * Otherwise if they don't exist yet, then construct_icon_info()
2816 * will create the windows once the widget is already realized.
2818 for (i = 0; i < MAX_ICONS; i++)
2820 if ((icon_info = priv->icons[i]) != NULL)
2822 if (icon_info->window == NULL)
2823 realize_icon_info (widget, i);
2829 gtk_entry_unrealize (GtkWidget *widget)
2831 GtkEntry *entry = GTK_ENTRY (widget);
2832 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2833 GtkClipboard *clipboard;
2834 EntryIconInfo *icon_info;
2837 gtk_entry_reset_layout (entry);
2839 gtk_im_context_set_client_window (entry->im_context, NULL);
2841 clipboard = gtk_widget_get_clipboard (widget, GDK_SELECTION_PRIMARY);
2842 if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (entry))
2843 gtk_clipboard_clear (clipboard);
2845 if (entry->text_area)
2847 gdk_window_set_user_data (entry->text_area, NULL);
2848 gdk_window_destroy (entry->text_area);
2849 entry->text_area = NULL;
2852 if (entry->popup_menu)
2854 gtk_widget_destroy (entry->popup_menu);
2855 entry->popup_menu = NULL;
2858 GTK_WIDGET_CLASS (gtk_entry_parent_class)->unrealize (widget);
2860 for (i = 0; i < MAX_ICONS; i++)
2862 if ((icon_info = priv->icons[i]) != NULL)
2864 if (icon_info->window != NULL)
2866 gdk_window_destroy (icon_info->window);
2867 icon_info->window = NULL;
2874 _gtk_entry_get_borders (GtkEntry *entry,
2878 GtkWidget *widget = GTK_WIDGET (entry);
2879 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2881 if (entry->has_frame)
2883 *xborder = widget->style->xthickness;
2884 *yborder = widget->style->ythickness;
2892 if (!priv->interior_focus)
2894 *xborder += priv->focus_width;
2895 *yborder += priv->focus_width;
2900 gtk_entry_size_request (GtkWidget *widget,
2901 GtkRequisition *requisition)
2903 GtkEntry *entry = GTK_ENTRY (widget);
2904 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2905 PangoFontMetrics *metrics;
2906 gint xborder, yborder;
2907 GtkBorder inner_border;
2908 PangoContext *context;
2909 int icon_widths = 0;
2912 gtk_widget_ensure_style (widget);
2913 context = gtk_widget_get_pango_context (widget);
2914 metrics = pango_context_get_metrics (context,
2915 widget->style->font_desc,
2916 pango_context_get_language (context));
2918 entry->ascent = pango_font_metrics_get_ascent (metrics);
2919 entry->descent = pango_font_metrics_get_descent (metrics);
2921 _gtk_entry_get_borders (entry, &xborder, &yborder);
2922 _gtk_entry_effective_inner_border (entry, &inner_border);
2924 if (entry->width_chars < 0)
2925 requisition->width = MIN_ENTRY_WIDTH + xborder * 2 + inner_border.left + inner_border.right;
2928 gint char_width = pango_font_metrics_get_approximate_char_width (metrics);
2929 gint digit_width = pango_font_metrics_get_approximate_digit_width (metrics);
2930 gint char_pixels = (MAX (char_width, digit_width) + PANGO_SCALE - 1) / PANGO_SCALE;
2932 requisition->width = char_pixels * entry->width_chars + xborder * 2 + inner_border.left + inner_border.right;
2935 requisition->height = PANGO_PIXELS (entry->ascent + entry->descent) + yborder * 2 + inner_border.top + inner_border.bottom;
2937 for (i = 0; i < MAX_ICONS; i++)
2939 icon_width = get_icon_width (entry, i);
2941 icon_widths += icon_width + 2 * priv->icon_margin;
2944 if (icon_widths > requisition->width)
2945 requisition->width += icon_widths;
2947 pango_font_metrics_unref (metrics);
2951 place_windows (GtkEntry *entry)
2953 GtkWidget *widget = GTK_WIDGET (entry);
2954 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2955 gint x, y, width, height;
2956 GtkAllocation primary;
2957 GtkAllocation secondary;
2958 EntryIconInfo *icon_info = NULL;
2960 get_text_area_size (entry, &x, &y, &width, &height);
2961 get_icon_allocations (entry, &primary, &secondary);
2963 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
2964 y += priv->focus_width;
2966 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
2967 x += secondary.width;
2970 width -= primary.width + secondary.width;
2972 if ((icon_info = priv->icons[GTK_ENTRY_ICON_PRIMARY]) != NULL)
2973 gdk_window_move_resize (icon_info->window,
2974 primary.x, primary.y,
2975 primary.width, primary.height);
2977 if ((icon_info = priv->icons[GTK_ENTRY_ICON_SECONDARY]) != NULL)
2978 gdk_window_move_resize (icon_info->window,
2979 secondary.x, secondary.y,
2980 secondary.width, secondary.height);
2982 gdk_window_move_resize (entry->text_area, x, y, width, height);
2986 gtk_entry_get_text_area_size (GtkEntry *entry,
2992 GtkWidget *widget = GTK_WIDGET (entry);
2993 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2995 gint xborder, yborder;
2996 GtkRequisition requisition;
2998 gtk_widget_get_child_requisition (widget, &requisition);
2999 _gtk_entry_get_borders (entry, &xborder, &yborder);
3001 if (gtk_widget_get_realized (widget))
3002 gdk_drawable_get_size (widget->window, NULL, &frame_height);
3004 frame_height = requisition.height;
3006 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3007 frame_height -= 2 * priv->focus_width;
3013 *y = frame_height / 2 - (requisition.height - yborder * 2) / 2;
3016 *width = GTK_WIDGET (entry)->allocation.width - xborder * 2;
3019 *height = requisition.height - yborder * 2;
3023 get_text_area_size (GtkEntry *entry,
3029 GtkEntryClass *class;
3031 g_return_if_fail (GTK_IS_ENTRY (entry));
3033 class = GTK_ENTRY_GET_CLASS (entry);
3035 if (class->get_text_area_size)
3036 class->get_text_area_size (entry, x, y, width, height);
3041 get_widget_window_size (GtkEntry *entry,
3047 GtkRequisition requisition;
3048 GtkWidget *widget = GTK_WIDGET (entry);
3050 gtk_widget_get_child_requisition (widget, &requisition);
3053 *x = widget->allocation.x;
3057 if (entry->is_cell_renderer)
3058 *y = widget->allocation.y;
3060 *y = widget->allocation.y + (widget->allocation.height - requisition.height) / 2;
3064 *width = widget->allocation.width;
3068 if (entry->is_cell_renderer)
3069 *height = widget->allocation.height;
3071 *height = requisition.height;
3076 _gtk_entry_effective_inner_border (GtkEntry *entry,
3079 GtkBorder *tmp_border;
3081 tmp_border = g_object_get_qdata (G_OBJECT (entry), quark_inner_border);
3085 *border = *tmp_border;
3089 gtk_widget_style_get (GTK_WIDGET (entry), "inner-border", &tmp_border, NULL);
3093 *border = *tmp_border;
3094 gtk_border_free (tmp_border);
3098 *border = default_inner_border;
3102 gtk_entry_size_allocate (GtkWidget *widget,
3103 GtkAllocation *allocation)
3105 GtkEntry *entry = GTK_ENTRY (widget);
3107 widget->allocation = *allocation;
3109 if (gtk_widget_get_realized (widget))
3111 /* We call gtk_widget_get_child_requisition, since we want (for
3112 * backwards compatibility reasons) the realization here to
3113 * be affected by the usize of the entry, if set
3115 gint x, y, width, height;
3116 GtkEntryCompletion* completion;
3118 get_widget_window_size (entry, &x, &y, &width, &height);
3119 gdk_window_move_resize (widget->window, x, y, width, height);
3121 place_windows (entry);
3122 gtk_entry_recompute (entry);
3124 completion = gtk_entry_get_completion (entry);
3125 if (completion && gtk_widget_get_mapped (completion->priv->popup_window))
3126 _gtk_entry_completion_resize_popup (completion);
3130 /* Kudos to the gnome-panel guys. */
3132 colorshift_pixbuf (GdkPixbuf *dest,
3137 gint width, height, has_alpha, src_rowstride, dest_rowstride;
3138 guchar *target_pixels;
3139 guchar *original_pixels;
3145 has_alpha = gdk_pixbuf_get_has_alpha (src);
3146 width = gdk_pixbuf_get_width (src);
3147 height = gdk_pixbuf_get_height (src);
3148 src_rowstride = gdk_pixbuf_get_rowstride (src);
3149 dest_rowstride = gdk_pixbuf_get_rowstride (dest);
3150 original_pixels = gdk_pixbuf_get_pixels (src);
3151 target_pixels = gdk_pixbuf_get_pixels (dest);
3153 for (i = 0; i < height; i++)
3155 pix_dest = target_pixels + i * dest_rowstride;
3156 pix_src = original_pixels + i * src_rowstride;
3158 for (j = 0; j < width; j++)
3165 *(pix_dest++) = CLAMP (val, 0, 255);
3168 *(pix_dest++) = CLAMP (val, 0, 255);
3171 *(pix_dest++) = CLAMP (val, 0, 255);
3174 *(pix_dest++) = *(pix_src++);
3180 should_prelight (GtkEntry *entry,
3181 GtkEntryIconPosition icon_pos)
3183 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3184 EntryIconInfo *icon_info = priv->icons[icon_pos];
3190 if (icon_info->nonactivatable && icon_info->target_list == NULL)
3193 if (icon_info->pressed)
3196 gtk_widget_style_get (GTK_WIDGET (entry),
3197 "icon-prelight", &prelight,
3204 draw_icon (GtkWidget *widget,
3205 GtkEntryIconPosition icon_pos)
3207 GtkEntry *entry = GTK_ENTRY (widget);
3208 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3209 EntryIconInfo *icon_info = priv->icons[icon_pos];
3211 gint x, y, width, height;
3217 gtk_entry_ensure_pixbuf (entry, icon_pos);
3219 if (icon_info->pixbuf == NULL)
3222 gdk_drawable_get_size (icon_info->window, &width, &height);
3224 /* size_allocate hasn't been called yet. These are the default values.
3226 if (width == 1 || height == 1)
3229 pixbuf = icon_info->pixbuf;
3230 g_object_ref (pixbuf);
3232 if (gdk_pixbuf_get_height (pixbuf) > height)
3234 GdkPixbuf *temp_pixbuf;
3237 scale = height - 2 * priv->icon_margin;
3238 temp_pixbuf = gdk_pixbuf_scale_simple (pixbuf, scale, scale,
3239 GDK_INTERP_BILINEAR);
3240 g_object_unref (pixbuf);
3241 pixbuf = temp_pixbuf;
3244 x = (width - gdk_pixbuf_get_width (pixbuf)) / 2;
3245 y = (height - gdk_pixbuf_get_height (pixbuf)) / 2;
3247 if (!gtk_widget_is_sensitive (widget) ||
3248 icon_info->insensitive)
3250 GdkPixbuf *temp_pixbuf;
3252 temp_pixbuf = gdk_pixbuf_copy (pixbuf);
3253 gdk_pixbuf_saturate_and_pixelate (pixbuf,
3257 g_object_unref (pixbuf);
3258 pixbuf = temp_pixbuf;
3260 else if (icon_info->prelight)
3262 GdkPixbuf *temp_pixbuf;
3264 temp_pixbuf = gdk_pixbuf_copy (pixbuf);
3265 colorshift_pixbuf (temp_pixbuf, pixbuf, 30);
3266 g_object_unref (pixbuf);
3267 pixbuf = temp_pixbuf;
3270 cr = gdk_cairo_create (icon_info->window);
3271 gdk_cairo_set_source_pixbuf (cr, pixbuf, x, y);
3275 g_object_unref (pixbuf);
3280 gtk_entry_draw_frame (GtkWidget *widget,
3281 GdkEventExpose *event)
3283 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
3284 gint x = 0, y = 0, width, height;
3285 gboolean state_hint;
3288 gdk_drawable_get_size (widget->window, &width, &height);
3290 /* Fix a problem with some themes which assume that entry->text_area's
3291 * width equals widget->window's width */
3292 if (GTK_IS_SPIN_BUTTON (widget))
3294 gint xborder, yborder;
3296 gtk_entry_get_text_area_size (GTK_ENTRY (widget), &x, NULL, &width, NULL);
3297 _gtk_entry_get_borders (GTK_ENTRY (widget), &xborder, &yborder);
3300 width += xborder * 2;
3303 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3305 x += priv->focus_width;
3306 y += priv->focus_width;
3307 width -= 2 * priv->focus_width;
3308 height -= 2 * priv->focus_width;
3311 gtk_widget_style_get (widget, "state-hint", &state_hint, NULL);
3313 state = gtk_widget_has_focus (widget) ?
3314 GTK_STATE_ACTIVE : gtk_widget_get_state (widget);
3316 state = GTK_STATE_NORMAL;
3318 gtk_paint_shadow (widget->style, widget->window,
3319 state, priv->shadow_type,
3320 &event->area, widget, "entry", x, y, width, height);
3323 gtk_entry_draw_progress (widget, event);
3325 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3327 x -= priv->focus_width;
3328 y -= priv->focus_width;
3329 width += 2 * priv->focus_width;
3330 height += 2 * priv->focus_width;
3332 gtk_paint_focus (widget->style, widget->window,
3333 gtk_widget_get_state (widget),
3334 &event->area, widget, "entry",
3335 0, 0, width, height);
3340 gtk_entry_get_progress_border (GtkWidget *widget,
3341 GtkBorder *progress_border)
3343 GtkBorder *tmp_border;
3345 gtk_widget_style_get (widget, "progress-border", &tmp_border, NULL);
3348 *progress_border = *tmp_border;
3349 gtk_border_free (tmp_border);
3353 progress_border->left = widget->style->xthickness;
3354 progress_border->right = widget->style->xthickness;
3355 progress_border->top = widget->style->ythickness;
3356 progress_border->bottom = widget->style->ythickness;
3361 get_progress_area (GtkWidget *widget,
3367 GtkEntryPrivate *private = GTK_ENTRY_GET_PRIVATE (widget);
3368 GtkEntry *entry = GTK_ENTRY (widget);
3369 GtkBorder progress_border;
3371 gtk_entry_get_progress_border (widget, &progress_border);
3373 *x = progress_border.left;
3374 *y = progress_border.top;
3376 gdk_drawable_get_size (widget->window, width, height);
3378 *width -= progress_border.left + progress_border.right;
3379 *height -= progress_border.top + progress_border.bottom;
3381 if (gtk_widget_has_focus (widget) && !private->interior_focus)
3383 *x += private->focus_width;
3384 *y += private->focus_width;
3385 *width -= 2 * private->focus_width;
3386 *height -= 2 * private->focus_width;
3389 if (private->progress_pulse_mode)
3391 gdouble value = private->progress_pulse_current;
3393 *x += (gint) floor(value * (*width));
3394 *width = (gint) ceil(private->progress_pulse_fraction * (*width));
3396 else if (private->progress_fraction > 0)
3398 gdouble value = private->progress_fraction;
3400 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
3404 bar_width = floor(value * (*width) + 0.5);
3405 *x += *width - bar_width;
3410 *width = (gint) floor(value * (*width) + 0.5);
3421 gtk_entry_draw_progress (GtkWidget *widget,
3422 GdkEventExpose *event)
3424 gint x, y, width, height;
3427 get_progress_area (widget, &x, &y, &width, &height);
3429 if ((width <= 0) || (height <= 0))
3432 if (event->window != widget->window)
3436 gdk_window_get_position (event->window, &pos_x, &pos_y);
3442 state = GTK_STATE_SELECTED;
3443 if (!gtk_widget_get_sensitive (widget))
3444 state = GTK_STATE_INSENSITIVE;
3446 gtk_paint_box (widget->style, event->window,
3447 state, GTK_SHADOW_OUT,
3448 &event->area, widget, "entry-progress",
3454 gtk_entry_expose (GtkWidget *widget,
3455 GdkEventExpose *event)
3457 GtkEntry *entry = GTK_ENTRY (widget);
3458 gboolean state_hint;
3460 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3462 gtk_widget_style_get (widget, "state-hint", &state_hint, NULL);
3464 state = gtk_widget_has_focus (widget) ?
3465 GTK_STATE_ACTIVE : gtk_widget_get_state (widget);
3467 state = gtk_widget_get_state(widget);
3469 if (widget->window == event->window)
3471 gtk_entry_draw_frame (widget, event);
3473 else if (entry->text_area == event->window)
3477 gdk_drawable_get_size (entry->text_area, &width, &height);
3479 gtk_paint_flat_box (widget->style, entry->text_area,
3480 state, GTK_SHADOW_NONE,
3481 &event->area, widget, "entry_bg",
3482 0, 0, width, height);
3484 gtk_entry_draw_progress (widget, event);
3486 if (entry->dnd_position != -1)
3487 gtk_entry_draw_cursor (GTK_ENTRY (widget), CURSOR_DND);
3489 gtk_entry_draw_text (GTK_ENTRY (widget));
3491 /* When no text is being displayed at all, don't show the cursor */
3492 if (gtk_entry_get_display_mode (entry) != DISPLAY_BLANK &&
3493 gtk_widget_has_focus (widget) &&
3494 entry->selection_bound == entry->current_pos && entry->cursor_visible)
3495 gtk_entry_draw_cursor (GTK_ENTRY (widget), CURSOR_STANDARD);
3501 for (i = 0; i < MAX_ICONS; i++)
3503 EntryIconInfo *icon_info = priv->icons[i];
3505 if (icon_info != NULL && event->window == icon_info->window)
3509 gdk_drawable_get_size (icon_info->window, &width, &height);
3511 gtk_paint_flat_box (widget->style, icon_info->window,
3512 gtk_widget_get_state (widget), GTK_SHADOW_NONE,
3513 NULL, widget, "entry_bg",
3514 0, 0, width, height);
3516 gtk_entry_draw_progress (widget, event);
3517 draw_icon (widget, i);
3528 gtk_entry_enter_notify (GtkWidget *widget,
3529 GdkEventCrossing *event)
3531 GtkEntry *entry = GTK_ENTRY (widget);
3532 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3535 for (i = 0; i < MAX_ICONS; i++)
3537 EntryIconInfo *icon_info = priv->icons[i];
3539 if (icon_info != NULL && event->window == icon_info->window)
3541 if (should_prelight (entry, i))
3543 icon_info->prelight = TRUE;
3544 gtk_widget_queue_draw (widget);
3555 gtk_entry_leave_notify (GtkWidget *widget,
3556 GdkEventCrossing *event)
3558 GtkEntry *entry = GTK_ENTRY (widget);
3559 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3562 for (i = 0; i < MAX_ICONS; i++)
3564 EntryIconInfo *icon_info = priv->icons[i];
3566 if (icon_info != NULL && event->window == icon_info->window)
3568 /* a grab means that we may never see the button release */
3569 if (event->mode == GDK_CROSSING_GRAB || event->mode == GDK_CROSSING_GTK_GRAB)
3570 icon_info->pressed = FALSE;
3572 if (should_prelight (entry, i))
3574 icon_info->prelight = FALSE;
3575 gtk_widget_queue_draw (widget);
3586 gtk_entry_get_pixel_ranges (GtkEntry *entry,
3590 gint start_char, end_char;
3592 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start_char, &end_char))
3594 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
3595 PangoLayoutLine *line = pango_layout_get_lines_readonly (layout)->data;
3596 const char *text = pango_layout_get_text (layout);
3597 gint start_index = g_utf8_offset_to_pointer (text, start_char) - text;
3598 gint end_index = g_utf8_offset_to_pointer (text, end_char) - text;
3599 gint real_n_ranges, i;
3601 pango_layout_line_get_x_ranges (line, start_index, end_index, ranges, &real_n_ranges);
3607 for (i = 0; i < real_n_ranges; ++i)
3609 r[2 * i + 1] = (r[2 * i + 1] - r[2 * i]) / PANGO_SCALE;
3610 r[2 * i] = r[2 * i] / PANGO_SCALE;
3615 *n_ranges = real_n_ranges;
3627 in_selection (GtkEntry *entry,
3632 gint retval = FALSE;
3634 gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
3636 for (i = 0; i < n_ranges; ++i)
3638 if (x >= ranges[2 * i] && x < ranges[2 * i] + ranges[2 * i + 1])
3650 gtk_entry_button_press (GtkWidget *widget,
3651 GdkEventButton *event)
3653 GtkEntry *entry = GTK_ENTRY (widget);
3654 GtkEditable *editable = GTK_EDITABLE (widget);
3655 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3656 EntryIconInfo *icon_info = NULL;
3658 gint sel_start, sel_end;
3661 for (i = 0; i < MAX_ICONS; i++)
3663 icon_info = priv->icons[i];
3665 if (!icon_info || icon_info->insensitive)
3668 if (event->window == icon_info->window)
3670 if (should_prelight (entry, i))
3672 icon_info->prelight = FALSE;
3673 gtk_widget_queue_draw (widget);
3676 priv->start_x = event->x;
3677 priv->start_y = event->y;
3678 icon_info->pressed = TRUE;
3680 if (!icon_info->nonactivatable)
3681 g_signal_emit (entry, signals[ICON_PRESS], 0, i, event);
3687 if (event->window != entry->text_area ||
3688 (entry->button && event->button != entry->button))
3691 gtk_entry_reset_blink_time (entry);
3693 entry->button = event->button;
3695 if (!gtk_widget_has_focus (widget))
3697 entry->in_click = TRUE;
3698 gtk_widget_grab_focus (widget);
3699 entry->in_click = FALSE;
3702 tmp_pos = gtk_entry_find_position (entry, event->x + entry->scroll_offset);
3704 if (event->button == 1)
3706 gboolean have_selection = gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end);
3708 entry->select_words = FALSE;
3709 entry->select_lines = FALSE;
3711 if (event->state & GDK_SHIFT_MASK)
3713 _gtk_entry_reset_im_context (entry);
3715 if (!have_selection) /* select from the current position to the clicked position */
3716 sel_start = sel_end = entry->current_pos;
3718 if (tmp_pos > sel_start && tmp_pos < sel_end)
3720 /* Truncate current selection, but keep it as big as possible */
3721 if (tmp_pos - sel_start > sel_end - tmp_pos)
3722 gtk_entry_set_positions (entry, sel_start, tmp_pos);
3724 gtk_entry_set_positions (entry, tmp_pos, sel_end);
3728 gboolean extend_to_left;
3731 /* Figure out what click selects and extend current selection */
3732 switch (event->type)
3734 case GDK_BUTTON_PRESS:
3735 gtk_entry_set_positions (entry, tmp_pos, tmp_pos);
3738 case GDK_2BUTTON_PRESS:
3739 entry->select_words = TRUE;
3740 gtk_entry_select_word (entry);
3743 case GDK_3BUTTON_PRESS:
3744 entry->select_lines = TRUE;
3745 gtk_entry_select_line (entry);
3752 start = MIN (entry->current_pos, entry->selection_bound);
3753 start = MIN (sel_start, start);
3755 end = MAX (entry->current_pos, entry->selection_bound);
3756 end = MAX (sel_end, end);
3758 if (tmp_pos == sel_start || tmp_pos == sel_end)
3759 extend_to_left = (tmp_pos == start);
3761 extend_to_left = (end == sel_end);
3764 gtk_entry_set_positions (entry, start, end);
3766 gtk_entry_set_positions (entry, end, start);
3769 else /* no shift key */
3770 switch (event->type)
3772 case GDK_BUTTON_PRESS:
3773 if (in_selection (entry, event->x + entry->scroll_offset))
3775 /* Click inside the selection - we'll either start a drag, or
3776 * clear the selection
3778 entry->in_drag = TRUE;
3779 entry->drag_start_x = event->x + entry->scroll_offset;
3780 entry->drag_start_y = event->y;
3783 gtk_editable_set_position (editable, tmp_pos);
3786 case GDK_2BUTTON_PRESS:
3787 /* We ALWAYS receive a GDK_BUTTON_PRESS immediately before
3788 * receiving a GDK_2BUTTON_PRESS so we need to reset
3789 * entry->in_drag which may have been set above
3791 entry->in_drag = FALSE;
3792 entry->select_words = TRUE;
3793 gtk_entry_select_word (entry);
3796 case GDK_3BUTTON_PRESS:
3797 /* We ALWAYS receive a GDK_BUTTON_PRESS immediately before
3798 * receiving a GDK_3BUTTON_PRESS so we need to reset
3799 * entry->in_drag which may have been set above
3801 entry->in_drag = FALSE;
3802 entry->select_lines = TRUE;
3803 gtk_entry_select_line (entry);
3812 else if (event->button == 2 && event->type == GDK_BUTTON_PRESS)
3814 if (entry->editable)
3816 priv->insert_pos = tmp_pos;
3817 gtk_entry_paste (entry, GDK_SELECTION_PRIMARY);
3822 gtk_widget_error_bell (widget);
3825 else if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
3827 gtk_entry_do_popup (entry, event);
3828 entry->button = 0; /* Don't wait for release, since the menu will gtk_grab_add */
3837 gtk_entry_button_release (GtkWidget *widget,
3838 GdkEventButton *event)
3840 GtkEntry *entry = GTK_ENTRY (widget);
3841 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
3842 EntryIconInfo *icon_info = NULL;
3845 for (i = 0; i < MAX_ICONS; i++)
3847 icon_info = priv->icons[i];
3849 if (!icon_info || icon_info->insensitive)
3852 if (event->window == icon_info->window)
3856 gdk_drawable_get_size (icon_info->window, &width, &height);
3858 icon_info->pressed = FALSE;
3860 if (should_prelight (entry, i) &&
3861 event->x >= 0 && event->y >= 0 &&
3862 event->x < width && event->y < height)
3864 icon_info->prelight = TRUE;
3865 gtk_widget_queue_draw (widget);
3868 if (!icon_info->nonactivatable)
3869 g_signal_emit (entry, signals[ICON_RELEASE], 0, i, event);
3875 if (event->window != entry->text_area || entry->button != event->button)
3880 gint tmp_pos = gtk_entry_find_position (entry, entry->drag_start_x);
3882 gtk_editable_set_position (GTK_EDITABLE (entry), tmp_pos);
3889 gtk_entry_update_primary_selection (entry);
3895 _gtk_entry_get_selected_text (GtkEntry *entry)
3897 GtkEditable *editable = GTK_EDITABLE (entry);
3898 gint start_text, end_text;
3901 if (gtk_editable_get_selection_bounds (editable, &start_text, &end_text))
3902 text = gtk_editable_get_chars (editable, start_text, end_text);
3908 gtk_entry_motion_notify (GtkWidget *widget,
3909 GdkEventMotion *event)
3911 GtkEntry *entry = GTK_ENTRY (widget);
3912 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3913 EntryIconInfo *icon_info = NULL;
3914 GdkDragContext *context;
3918 for (i = 0; i < MAX_ICONS; i++)
3920 icon_info = priv->icons[i];
3922 if (!icon_info || icon_info->insensitive)
3925 if (event->window == icon_info->window)
3927 if (icon_info->pressed &&
3928 icon_info->target_list != NULL &&
3929 gtk_drag_check_threshold (widget,
3935 icon_info->in_drag = TRUE;
3936 icon_info->pressed = FALSE;
3937 context = gtk_drag_begin (widget,
3938 icon_info->target_list,
3948 if (entry->mouse_cursor_obscured)
3952 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
3953 gdk_window_set_cursor (entry->text_area, cursor);
3954 gdk_cursor_unref (cursor);
3955 entry->mouse_cursor_obscured = FALSE;
3958 if (event->window != entry->text_area || entry->button != 1)
3961 if (entry->select_lines)
3964 gdk_event_request_motions (event);
3968 if (gtk_entry_get_display_mode (entry) == DISPLAY_NORMAL &&
3969 gtk_drag_check_threshold (widget,
3970 entry->drag_start_x, entry->drag_start_y,
3971 event->x + entry->scroll_offset, event->y))
3973 GdkDragContext *context;
3974 GtkTargetList *target_list = gtk_target_list_new (NULL, 0);
3975 guint actions = entry->editable ? GDK_ACTION_COPY | GDK_ACTION_MOVE : GDK_ACTION_COPY;
3977 GdkPixmap *pixmap = NULL;
3979 gtk_target_list_add_text_targets (target_list, 0);
3981 text = _gtk_entry_get_selected_text (entry);
3982 pixmap = _gtk_text_util_create_drag_icon (widget, text, -1);
3984 context = gtk_drag_begin (widget, target_list, actions,
3985 entry->button, (GdkEvent *)event);
3988 gtk_drag_set_icon_pixmap (context,
3989 gdk_drawable_get_colormap (pixmap),
3994 gtk_drag_set_icon_default (context);
3997 g_object_unref (pixmap);
4000 entry->in_drag = FALSE;
4003 gtk_target_list_unref (target_list);
4009 gdk_drawable_get_size (entry->text_area, NULL, &height);
4013 else if (event->y >= height)
4014 tmp_pos = gtk_entry_buffer_get_length (get_buffer (entry));
4016 tmp_pos = gtk_entry_find_position (entry, event->x + entry->scroll_offset);
4018 if (entry->select_words)
4021 gint old_min, old_max;
4024 min = gtk_entry_move_backward_word (entry, tmp_pos, TRUE);
4025 max = gtk_entry_move_forward_word (entry, tmp_pos, TRUE);
4027 pos = entry->current_pos;
4028 bound = entry->selection_bound;
4030 old_min = MIN(entry->current_pos, entry->selection_bound);
4031 old_max = MAX(entry->current_pos, entry->selection_bound);
4038 else if (old_max < max)
4043 else if (pos == old_min)
4045 if (entry->current_pos != min)
4050 if (entry->current_pos != max)
4054 gtk_entry_set_positions (entry, pos, bound);
4057 gtk_entry_set_positions (entry, tmp_pos, -1);
4064 set_invisible_cursor (GdkWindow *window)
4066 GdkDisplay *display;
4069 display = gdk_drawable_get_display (window);
4070 cursor = gdk_cursor_new_for_display (display, GDK_BLANK_CURSOR);
4072 gdk_window_set_cursor (window, cursor);
4074 gdk_cursor_unref (cursor);
4078 gtk_entry_obscure_mouse_cursor (GtkEntry *entry)
4080 if (entry->mouse_cursor_obscured)
4083 set_invisible_cursor (entry->text_area);
4085 entry->mouse_cursor_obscured = TRUE;
4089 gtk_entry_key_press (GtkWidget *widget,
4092 GtkEntry *entry = GTK_ENTRY (widget);
4094 gtk_entry_reset_blink_time (entry);
4095 gtk_entry_pend_cursor_blink (entry);
4097 if (entry->editable)
4099 if (gtk_im_context_filter_keypress (entry->im_context, event))
4101 gtk_entry_obscure_mouse_cursor (entry);
4102 entry->need_im_reset = TRUE;
4107 if (event->keyval == GDK_Return ||
4108 event->keyval == GDK_KP_Enter ||
4109 event->keyval == GDK_ISO_Enter ||
4110 event->keyval == GDK_Escape)
4112 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
4114 if (completion && completion->priv->completion_timeout)
4116 g_source_remove (completion->priv->completion_timeout);
4117 completion->priv->completion_timeout = 0;
4120 _gtk_entry_reset_im_context (entry);
4123 if (GTK_WIDGET_CLASS (gtk_entry_parent_class)->key_press_event (widget, event))
4124 /* Activate key bindings
4128 if (!entry->editable && event->length)
4129 gtk_widget_error_bell (widget);
4135 gtk_entry_key_release (GtkWidget *widget,
4138 GtkEntry *entry = GTK_ENTRY (widget);
4140 if (entry->editable)
4142 if (gtk_im_context_filter_keypress (entry->im_context, event))
4144 entry->need_im_reset = TRUE;
4149 return GTK_WIDGET_CLASS (gtk_entry_parent_class)->key_release_event (widget, event);
4153 gtk_entry_focus_in (GtkWidget *widget,
4154 GdkEventFocus *event)
4156 GtkEntry *entry = GTK_ENTRY (widget);
4159 gtk_widget_queue_draw (widget);
4161 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (widget));
4163 if (entry->editable)
4165 entry->need_im_reset = TRUE;
4166 gtk_im_context_focus_in (entry->im_context);
4167 keymap_state_changed (keymap, entry);
4168 g_signal_connect (keymap, "state-changed",
4169 G_CALLBACK (keymap_state_changed), entry);
4172 g_signal_connect (keymap, "direction-changed",
4173 G_CALLBACK (keymap_direction_changed), entry);
4175 gtk_entry_reset_blink_time (entry);
4176 gtk_entry_check_cursor_blink (entry);
4182 gtk_entry_focus_out (GtkWidget *widget,
4183 GdkEventFocus *event)
4185 GtkEntry *entry = GTK_ENTRY (widget);
4186 GtkEntryCompletion *completion;
4189 gtk_widget_queue_draw (widget);
4191 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (widget));
4193 if (entry->editable)
4195 entry->need_im_reset = TRUE;
4196 gtk_im_context_focus_out (entry->im_context);
4197 remove_capslock_feedback (entry);
4200 gtk_entry_check_cursor_blink (entry);
4202 g_signal_handlers_disconnect_by_func (keymap, keymap_state_changed, entry);
4203 g_signal_handlers_disconnect_by_func (keymap, keymap_direction_changed, entry);
4205 completion = gtk_entry_get_completion (entry);
4207 _gtk_entry_completion_popdown (completion);
4213 gtk_entry_grab_focus (GtkWidget *widget)
4215 GtkEntry *entry = GTK_ENTRY (widget);
4216 gboolean select_on_focus;
4218 GTK_WIDGET_CLASS (gtk_entry_parent_class)->grab_focus (widget);
4220 if (entry->editable && !entry->in_click)
4222 g_object_get (gtk_widget_get_settings (widget),
4223 "gtk-entry-select-on-focus",
4227 if (select_on_focus)
4228 gtk_editable_select_region (GTK_EDITABLE (widget), 0, -1);
4233 gtk_entry_direction_changed (GtkWidget *widget,
4234 GtkTextDirection previous_dir)
4236 GtkEntry *entry = GTK_ENTRY (widget);
4238 gtk_entry_recompute (entry);
4240 GTK_WIDGET_CLASS (gtk_entry_parent_class)->direction_changed (widget, previous_dir);
4244 gtk_entry_state_changed (GtkWidget *widget,
4245 GtkStateType previous_state)
4247 GtkEntry *entry = GTK_ENTRY (widget);
4248 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
4252 if (gtk_widget_get_realized (widget))
4254 gdk_window_set_background (widget->window, &widget->style->base[gtk_widget_get_state (widget)]);
4255 gdk_window_set_background (entry->text_area, &widget->style->base[gtk_widget_get_state (widget)]);
4256 for (i = 0; i < MAX_ICONS; i++)
4258 EntryIconInfo *icon_info = priv->icons[i];
4259 if (icon_info && icon_info->window)
4260 gdk_window_set_background (icon_info->window, &widget->style->base[gtk_widget_get_state (widget)]);
4263 if (gtk_widget_is_sensitive (widget))
4264 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
4268 gdk_window_set_cursor (entry->text_area, cursor);
4271 gdk_cursor_unref (cursor);
4273 entry->mouse_cursor_obscured = FALSE;
4275 update_cursors (widget);
4278 if (!gtk_widget_is_sensitive (widget))
4280 /* Clear any selection */
4281 gtk_editable_select_region (GTK_EDITABLE (entry), entry->current_pos, entry->current_pos);
4284 gtk_widget_queue_draw (widget);
4288 gtk_entry_screen_changed (GtkWidget *widget,
4289 GdkScreen *old_screen)
4291 gtk_entry_recompute (GTK_ENTRY (widget));
4294 /* GtkEditable method implementations
4297 gtk_entry_insert_text (GtkEditable *editable,
4298 const gchar *new_text,
4299 gint new_text_length,
4302 g_object_ref (editable);
4305 * The incoming text may a password or other secret. We make sure
4306 * not to copy it into temporary buffers.
4309 g_signal_emit_by_name (editable, "insert-text", new_text, new_text_length, position);
4311 g_object_unref (editable);
4315 gtk_entry_delete_text (GtkEditable *editable,
4319 g_object_ref (editable);
4321 g_signal_emit_by_name (editable, "delete-text", start_pos, end_pos);
4323 g_object_unref (editable);
4327 gtk_entry_get_chars (GtkEditable *editable,
4331 GtkEntry *entry = GTK_ENTRY (editable);
4334 gint start_index, end_index;
4336 text = gtk_entry_buffer_get_text (get_buffer (entry));
4337 text_length = gtk_entry_buffer_get_length (get_buffer (entry));
4340 end_pos = text_length;
4342 start_pos = MIN (text_length, start_pos);
4343 end_pos = MIN (text_length, end_pos);
4345 start_index = g_utf8_offset_to_pointer (text, start_pos) - entry->text;
4346 end_index = g_utf8_offset_to_pointer (text, end_pos) - entry->text;
4348 return g_strndup (text + start_index, end_index - start_index);
4352 gtk_entry_real_set_position (GtkEditable *editable,
4355 GtkEntry *entry = GTK_ENTRY (editable);
4359 length = gtk_entry_buffer_get_length (get_buffer (entry));
4360 if (position < 0 || position > length)
4363 if (position != entry->current_pos ||
4364 position != entry->selection_bound)
4366 _gtk_entry_reset_im_context (entry);
4367 gtk_entry_set_positions (entry, position, position);
4372 gtk_entry_get_position (GtkEditable *editable)
4374 return GTK_ENTRY (editable)->current_pos;
4378 gtk_entry_set_selection_bounds (GtkEditable *editable,
4382 GtkEntry *entry = GTK_ENTRY (editable);
4385 length = gtk_entry_buffer_get_length (get_buffer (entry));
4391 _gtk_entry_reset_im_context (entry);
4393 gtk_entry_set_positions (entry,
4395 MIN (start, length));
4397 gtk_entry_update_primary_selection (entry);
4401 gtk_entry_get_selection_bounds (GtkEditable *editable,
4405 GtkEntry *entry = GTK_ENTRY (editable);
4407 *start = entry->selection_bound;
4408 *end = entry->current_pos;
4410 return (entry->selection_bound != entry->current_pos);
4414 icon_theme_changed (GtkEntry *entry)
4416 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
4419 for (i = 0; i < MAX_ICONS; i++)
4421 EntryIconInfo *icon_info = priv->icons[i];
4422 if (icon_info != NULL)
4424 if (icon_info->storage_type == GTK_IMAGE_ICON_NAME)
4425 gtk_entry_set_icon_from_icon_name (entry, i, icon_info->icon_name);
4426 else if (icon_info->storage_type == GTK_IMAGE_STOCK)
4427 gtk_entry_set_icon_from_stock (entry, i, icon_info->stock_id);
4428 else if (icon_info->storage_type == GTK_IMAGE_GICON)
4429 gtk_entry_set_icon_from_gicon (entry, i, icon_info->gicon);
4433 gtk_widget_queue_draw (GTK_WIDGET (entry));
4437 icon_margin_changed (GtkEntry *entry)
4439 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
4442 _gtk_entry_effective_inner_border (GTK_ENTRY (entry), &border);
4444 priv->icon_margin = border.left;
4448 gtk_entry_style_set (GtkWidget *widget,
4449 GtkStyle *previous_style)
4451 GtkEntry *entry = GTK_ENTRY (widget);
4452 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
4454 gboolean interior_focus;
4457 gtk_widget_style_get (widget,
4458 "focus-line-width", &focus_width,
4459 "interior-focus", &interior_focus,
4462 priv->focus_width = focus_width;
4463 priv->interior_focus = interior_focus;
4465 if (!priv->invisible_char_set)
4466 entry->invisible_char = find_invisible_char (GTK_WIDGET (entry));
4468 gtk_entry_recompute (entry);
4470 if (previous_style && gtk_widget_get_realized (widget))
4472 gdk_window_set_background (widget->window, &widget->style->base[gtk_widget_get_state (widget)]);
4473 gdk_window_set_background (entry->text_area, &widget->style->base[gtk_widget_get_state (widget)]);
4474 for (i = 0; i < MAX_ICONS; i++)
4476 EntryIconInfo *icon_info = priv->icons[i];
4477 if (icon_info && icon_info->window)
4478 gdk_window_set_background (icon_info->window, &widget->style->base[gtk_widget_get_state (widget)]);
4482 icon_theme_changed (entry);
4483 icon_margin_changed (entry);
4486 /* GtkCellEditable method implementations
4489 gtk_cell_editable_entry_activated (GtkEntry *entry, gpointer data)
4491 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4492 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4496 gtk_cell_editable_key_press_event (GtkEntry *entry,
4497 GdkEventKey *key_event,
4500 if (key_event->keyval == GDK_Escape)
4502 entry->editing_canceled = TRUE;
4503 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4504 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4509 /* override focus */
4510 if (key_event->keyval == GDK_Up || key_event->keyval == GDK_Down)
4512 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4513 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4522 gtk_entry_start_editing (GtkCellEditable *cell_editable,
4525 GTK_ENTRY (cell_editable)->is_cell_renderer = TRUE;
4527 g_signal_connect (cell_editable, "activate",
4528 G_CALLBACK (gtk_cell_editable_entry_activated), NULL);
4529 g_signal_connect (cell_editable, "key-press-event",
4530 G_CALLBACK (gtk_cell_editable_key_press_event), NULL);
4534 gtk_entry_password_hint_free (GtkEntryPasswordHint *password_hint)
4536 if (password_hint->source_id)
4537 g_source_remove (password_hint->source_id);
4539 g_slice_free (GtkEntryPasswordHint, password_hint);
4544 gtk_entry_remove_password_hint (gpointer data)
4546 GtkEntryPasswordHint *password_hint = g_object_get_qdata (data, quark_password_hint);
4547 password_hint->position = -1;
4549 /* Force the string to be redrawn, but now without a visible character */
4550 gtk_entry_recompute (GTK_ENTRY (data));
4554 /* Default signal handlers
4557 gtk_entry_real_insert_text (GtkEditable *editable,
4558 const gchar *new_text,
4559 gint new_text_length,
4565 n_chars = g_utf8_strlen (new_text, new_text_length);
4568 * The actual insertion into the buffer. This will end up firing the
4569 * following signal handlers: buffer_inserted_text(), buffer_notify_display_text(),
4570 * buffer_notify_text(), buffer_notify_length()
4572 n_inserted = gtk_entry_buffer_insert_text (get_buffer (GTK_ENTRY (editable)), *position, new_text, n_chars);
4574 if (n_inserted != n_chars)
4575 gtk_widget_error_bell (GTK_WIDGET (editable));
4577 *position += n_inserted;
4581 gtk_entry_real_delete_text (GtkEditable *editable,
4586 * The actual deletion from the buffer. This will end up firing the
4587 * following signal handlers: buffer_deleted_text(), buffer_notify_display_text(),
4588 * buffer_notify_text(), buffer_notify_length()
4591 gtk_entry_buffer_delete_text (get_buffer (GTK_ENTRY (editable)), start_pos, end_pos - start_pos);
4594 /* GtkEntryBuffer signal handlers
4597 buffer_inserted_text (GtkEntryBuffer *buffer,
4603 guint password_hint_timeout;
4605 if (entry->current_pos > position)
4606 entry->current_pos += n_chars;
4608 if (entry->selection_bound > position)
4609 entry->selection_bound += n_chars;
4611 /* Calculate the password hint if it needs to be displayed. */
4612 if (n_chars == 1 && !entry->visible)
4614 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
4615 "gtk-entry-password-hint-timeout", &password_hint_timeout,
4618 if (password_hint_timeout > 0)
4620 GtkEntryPasswordHint *password_hint = g_object_get_qdata (G_OBJECT (entry),
4621 quark_password_hint);
4624 password_hint = g_slice_new0 (GtkEntryPasswordHint);
4625 g_object_set_qdata_full (G_OBJECT (entry), quark_password_hint, password_hint,
4626 (GDestroyNotify)gtk_entry_password_hint_free);
4629 password_hint->position = position;
4630 if (password_hint->source_id)
4631 g_source_remove (password_hint->source_id);
4632 password_hint->source_id = gdk_threads_add_timeout (password_hint_timeout,
4633 (GSourceFunc)gtk_entry_remove_password_hint, entry);
4639 buffer_deleted_text (GtkEntryBuffer *buffer,
4644 guint end_pos = position + n_chars;
4645 gint selection_bound;
4648 current_pos = entry->current_pos;
4649 if (current_pos > position)
4650 current_pos -= MIN (current_pos, end_pos) - position;
4652 selection_bound = entry->selection_bound;
4653 if (selection_bound > position)
4654 selection_bound -= MIN (selection_bound, end_pos) - position;
4656 gtk_entry_set_positions (entry, current_pos, selection_bound);
4658 /* We might have deleted the selection */
4659 gtk_entry_update_primary_selection (entry);
4661 /* Disable the password hint if one exists. */
4662 if (!entry->visible)
4664 GtkEntryPasswordHint *password_hint = g_object_get_qdata (G_OBJECT (entry),
4665 quark_password_hint);
4668 if (password_hint->source_id)
4669 g_source_remove (password_hint->source_id);
4670 password_hint->source_id = 0;
4671 password_hint->position = -1;
4677 buffer_notify_text (GtkEntryBuffer *buffer,
4681 /* COMPAT: Deprecated, not used. This struct field will be removed in GTK+ 3.x */
4682 entry->text = (gchar*)gtk_entry_buffer_get_text (buffer);
4684 gtk_entry_recompute (entry);
4685 emit_changed (entry);
4686 g_object_notify (G_OBJECT (entry), "text");
4690 buffer_notify_length (GtkEntryBuffer *buffer,
4694 /* COMPAT: Deprecated, not used. This struct field will be removed in GTK+ 3.x */
4695 entry->text_length = gtk_entry_buffer_get_length (buffer);
4697 g_object_notify (G_OBJECT (entry), "text-length");
4701 buffer_notify_max_length (GtkEntryBuffer *buffer,
4705 /* COMPAT: Deprecated, not used. This struct field will be removed in GTK+ 3.x */
4706 entry->text_max_length = gtk_entry_buffer_get_max_length (buffer);
4708 g_object_notify (G_OBJECT (entry), "max-length");
4712 buffer_connect_signals (GtkEntry *entry)
4714 g_signal_connect (get_buffer (entry), "inserted-text", G_CALLBACK (buffer_inserted_text), entry);
4715 g_signal_connect (get_buffer (entry), "deleted-text", G_CALLBACK (buffer_deleted_text), entry);
4716 g_signal_connect (get_buffer (entry), "notify::text", G_CALLBACK (buffer_notify_text), entry);
4717 g_signal_connect (get_buffer (entry), "notify::length", G_CALLBACK (buffer_notify_length), entry);
4718 g_signal_connect (get_buffer (entry), "notify::max-length", G_CALLBACK (buffer_notify_max_length), entry);
4722 buffer_disconnect_signals (GtkEntry *entry)
4724 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_inserted_text, entry);
4725 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_deleted_text, entry);
4726 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_text, entry);
4727 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_length, entry);
4728 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_max_length, entry);
4731 /* Compute the X position for an offset that corresponds to the "more important
4732 * cursor position for that offset. We use this when trying to guess to which
4733 * end of the selection we should go to when the user hits the left or
4737 get_better_cursor_x (GtkEntry *entry,
4740 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
4741 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
4742 gboolean split_cursor;
4744 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
4745 const gchar *text = pango_layout_get_text (layout);
4746 gint index = g_utf8_offset_to_pointer (text, offset) - text;
4748 PangoRectangle strong_pos, weak_pos;
4750 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
4751 "gtk-split-cursor", &split_cursor,
4754 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
4757 return strong_pos.x / PANGO_SCALE;
4759 return (keymap_direction == entry->resolved_dir) ? strong_pos.x / PANGO_SCALE : weak_pos.x / PANGO_SCALE;
4763 gtk_entry_move_cursor (GtkEntry *entry,
4764 GtkMovementStep step,
4766 gboolean extend_selection)
4768 gint new_pos = entry->current_pos;
4769 GtkEntryPrivate *priv;
4771 _gtk_entry_reset_im_context (entry);
4773 if (entry->current_pos != entry->selection_bound && !extend_selection)
4775 /* If we have a current selection and aren't extending it, move to the
4776 * start/or end of the selection as appropriate
4780 case GTK_MOVEMENT_VISUAL_POSITIONS:
4782 gint current_x = get_better_cursor_x (entry, entry->current_pos);
4783 gint bound_x = get_better_cursor_x (entry, entry->selection_bound);
4786 new_pos = current_x < bound_x ? entry->current_pos : entry->selection_bound;
4788 new_pos = current_x > bound_x ? entry->current_pos : entry->selection_bound;
4791 case GTK_MOVEMENT_LOGICAL_POSITIONS:
4792 case GTK_MOVEMENT_WORDS:
4794 new_pos = MIN (entry->current_pos, entry->selection_bound);
4796 new_pos = MAX (entry->current_pos, entry->selection_bound);
4798 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
4799 case GTK_MOVEMENT_PARAGRAPH_ENDS:
4800 case GTK_MOVEMENT_BUFFER_ENDS:
4801 priv = GTK_ENTRY_GET_PRIVATE (entry);
4802 new_pos = count < 0 ? 0 : gtk_entry_buffer_get_length (get_buffer (entry));
4804 case GTK_MOVEMENT_DISPLAY_LINES:
4805 case GTK_MOVEMENT_PARAGRAPHS:
4806 case GTK_MOVEMENT_PAGES:
4807 case GTK_MOVEMENT_HORIZONTAL_PAGES:
4815 case GTK_MOVEMENT_LOGICAL_POSITIONS:
4816 new_pos = gtk_entry_move_logically (entry, new_pos, count);
4818 case GTK_MOVEMENT_VISUAL_POSITIONS:
4819 new_pos = gtk_entry_move_visually (entry, new_pos, count);
4820 if (entry->current_pos == new_pos)
4822 if (!extend_selection)
4824 if (!gtk_widget_keynav_failed (GTK_WIDGET (entry),
4826 GTK_DIR_RIGHT : GTK_DIR_LEFT))
4828 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (entry));
4831 gtk_widget_child_focus (toplevel,
4833 GTK_DIR_RIGHT : GTK_DIR_LEFT);
4838 gtk_widget_error_bell (GTK_WIDGET (entry));
4842 case GTK_MOVEMENT_WORDS:
4845 new_pos = gtk_entry_move_forward_word (entry, new_pos, FALSE);
4850 new_pos = gtk_entry_move_backward_word (entry, new_pos, FALSE);
4853 if (entry->current_pos == new_pos)
4854 gtk_widget_error_bell (GTK_WIDGET (entry));
4856 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
4857 case GTK_MOVEMENT_PARAGRAPH_ENDS:
4858 case GTK_MOVEMENT_BUFFER_ENDS:
4859 priv = GTK_ENTRY_GET_PRIVATE (entry);
4860 new_pos = count < 0 ? 0 : gtk_entry_buffer_get_length (get_buffer (entry));
4861 if (entry->current_pos == new_pos)
4862 gtk_widget_error_bell (GTK_WIDGET (entry));
4864 case GTK_MOVEMENT_DISPLAY_LINES:
4865 case GTK_MOVEMENT_PARAGRAPHS:
4866 case GTK_MOVEMENT_PAGES:
4867 case GTK_MOVEMENT_HORIZONTAL_PAGES:
4872 if (extend_selection)
4873 gtk_editable_select_region (GTK_EDITABLE (entry), entry->selection_bound, new_pos);
4875 gtk_editable_set_position (GTK_EDITABLE (entry), new_pos);
4877 gtk_entry_pend_cursor_blink (entry);
4881 gtk_entry_insert_at_cursor (GtkEntry *entry,
4884 GtkEditable *editable = GTK_EDITABLE (entry);
4885 gint pos = entry->current_pos;
4887 if (entry->editable)
4889 _gtk_entry_reset_im_context (entry);
4891 gtk_editable_insert_text (editable, str, -1, &pos);
4892 gtk_editable_set_position (editable, pos);
4897 gtk_entry_delete_from_cursor (GtkEntry *entry,
4901 GtkEditable *editable = GTK_EDITABLE (entry);
4902 gint start_pos = entry->current_pos;
4903 gint end_pos = entry->current_pos;
4904 gint old_n_bytes = gtk_entry_buffer_get_bytes (get_buffer (entry));
4906 _gtk_entry_reset_im_context (entry);
4908 if (!entry->editable)
4910 gtk_widget_error_bell (GTK_WIDGET (entry));
4914 if (entry->selection_bound != entry->current_pos)
4916 gtk_editable_delete_selection (editable);
4922 case GTK_DELETE_CHARS:
4923 end_pos = gtk_entry_move_logically (entry, entry->current_pos, count);
4924 gtk_editable_delete_text (editable, MIN (start_pos, end_pos), MAX (start_pos, end_pos));
4926 case GTK_DELETE_WORDS:
4929 /* Move to end of current word, or if not on a word, end of previous word */
4930 end_pos = gtk_entry_move_backward_word (entry, end_pos, FALSE);
4931 end_pos = gtk_entry_move_forward_word (entry, end_pos, FALSE);
4935 /* Move to beginning of current word, or if not on a word, begining of next word */
4936 start_pos = gtk_entry_move_forward_word (entry, start_pos, FALSE);
4937 start_pos = gtk_entry_move_backward_word (entry, start_pos, FALSE);
4941 case GTK_DELETE_WORD_ENDS:
4944 start_pos = gtk_entry_move_backward_word (entry, start_pos, FALSE);
4949 end_pos = gtk_entry_move_forward_word (entry, end_pos, FALSE);
4952 gtk_editable_delete_text (editable, start_pos, end_pos);
4954 case GTK_DELETE_DISPLAY_LINE_ENDS:
4955 case GTK_DELETE_PARAGRAPH_ENDS:
4957 gtk_editable_delete_text (editable, 0, entry->current_pos);
4959 gtk_editable_delete_text (editable, entry->current_pos, -1);
4961 case GTK_DELETE_DISPLAY_LINES:
4962 case GTK_DELETE_PARAGRAPHS:
4963 gtk_editable_delete_text (editable, 0, -1);
4965 case GTK_DELETE_WHITESPACE:
4966 gtk_entry_delete_whitespace (entry);
4970 if (gtk_entry_buffer_get_bytes (get_buffer (entry)) == old_n_bytes)
4971 gtk_widget_error_bell (GTK_WIDGET (entry));
4973 gtk_entry_pend_cursor_blink (entry);
4977 gtk_entry_backspace (GtkEntry *entry)
4979 GtkEditable *editable = GTK_EDITABLE (entry);
4982 _gtk_entry_reset_im_context (entry);
4984 if (!entry->editable)
4986 gtk_widget_error_bell (GTK_WIDGET (entry));
4990 if (entry->selection_bound != entry->current_pos)
4992 gtk_editable_delete_selection (editable);
4996 prev_pos = gtk_entry_move_logically (entry, entry->current_pos, -1);
4998 if (prev_pos < entry->current_pos)
5000 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
5001 PangoLogAttr *log_attrs;
5004 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
5006 /* Deleting parts of characters */
5007 if (log_attrs[entry->current_pos].backspace_deletes_character)
5009 gchar *cluster_text;
5010 gchar *normalized_text;
5013 cluster_text = gtk_entry_get_display_text (entry, prev_pos,
5014 entry->current_pos);
5015 normalized_text = g_utf8_normalize (cluster_text,
5016 strlen (cluster_text),
5018 len = g_utf8_strlen (normalized_text, -1);
5020 gtk_editable_delete_text (editable, prev_pos, entry->current_pos);
5023 gint pos = entry->current_pos;
5025 gtk_editable_insert_text (editable, normalized_text,
5026 g_utf8_offset_to_pointer (normalized_text, len - 1) - normalized_text,
5028 gtk_editable_set_position (editable, pos);
5031 g_free (normalized_text);
5032 g_free (cluster_text);
5036 gtk_editable_delete_text (editable, prev_pos, entry->current_pos);
5043 gtk_widget_error_bell (GTK_WIDGET (entry));
5046 gtk_entry_pend_cursor_blink (entry);
5050 gtk_entry_copy_clipboard (GtkEntry *entry)
5052 GtkEditable *editable = GTK_EDITABLE (entry);
5056 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5058 if (!entry->visible)
5060 gtk_widget_error_bell (GTK_WIDGET (entry));
5064 str = gtk_entry_get_display_text (entry, start, end);
5065 gtk_clipboard_set_text (gtk_widget_get_clipboard (GTK_WIDGET (entry),
5066 GDK_SELECTION_CLIPBOARD),
5073 gtk_entry_cut_clipboard (GtkEntry *entry)
5075 GtkEditable *editable = GTK_EDITABLE (entry);
5078 if (!entry->visible)
5080 gtk_widget_error_bell (GTK_WIDGET (entry));
5084 gtk_entry_copy_clipboard (entry);
5086 if (entry->editable)
5088 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5089 gtk_editable_delete_text (editable, start, end);
5093 gtk_widget_error_bell (GTK_WIDGET (entry));
5098 gtk_entry_paste_clipboard (GtkEntry *entry)
5100 if (entry->editable)
5101 gtk_entry_paste (entry, GDK_NONE);
5103 gtk_widget_error_bell (GTK_WIDGET (entry));
5107 gtk_entry_delete_cb (GtkEntry *entry)
5109 GtkEditable *editable = GTK_EDITABLE (entry);
5112 if (entry->editable)
5114 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5115 gtk_editable_delete_text (editable, start, end);
5120 gtk_entry_toggle_overwrite (GtkEntry *entry)
5122 entry->overwrite_mode = !entry->overwrite_mode;
5123 gtk_entry_pend_cursor_blink (entry);
5124 gtk_widget_queue_draw (GTK_WIDGET (entry));
5128 gtk_entry_select_all (GtkEntry *entry)
5130 gtk_entry_select_line (entry);
5134 gtk_entry_real_activate (GtkEntry *entry)
5137 GtkWidget *toplevel;
5140 widget = GTK_WIDGET (entry);
5142 if (entry->activates_default)
5144 toplevel = gtk_widget_get_toplevel (widget);
5145 if (GTK_IS_WINDOW (toplevel))
5147 window = GTK_WINDOW (toplevel);
5150 widget != window->default_widget &&
5151 !(widget == window->focus_widget &&
5152 (!window->default_widget || !gtk_widget_get_sensitive (window->default_widget))))
5153 gtk_window_activate_default (window);
5159 keymap_direction_changed (GdkKeymap *keymap,
5162 gtk_entry_recompute (entry);
5165 /* IM Context Callbacks
5169 gtk_entry_commit_cb (GtkIMContext *context,
5173 if (entry->editable)
5174 gtk_entry_enter_text (entry, str);
5178 gtk_entry_preedit_changed_cb (GtkIMContext *context,
5181 if (entry->editable)
5183 gchar *preedit_string;
5186 gtk_im_context_get_preedit_string (entry->im_context,
5187 &preedit_string, NULL,
5189 g_signal_emit (entry, signals[PREEDIT_CHANGED], 0, preedit_string);
5190 entry->preedit_length = strlen (preedit_string);
5191 cursor_pos = CLAMP (cursor_pos, 0, g_utf8_strlen (preedit_string, -1));
5192 entry->preedit_cursor = cursor_pos;
5193 g_free (preedit_string);
5195 gtk_entry_recompute (entry);
5200 gtk_entry_retrieve_surrounding_cb (GtkIMContext *context,
5205 /* XXXX ??? does this even make sense when text is not visible? Should we return FALSE? */
5206 text = gtk_entry_get_display_text (entry, 0, -1);
5207 gtk_im_context_set_surrounding (context, text, strlen (text), /* Length in bytes */
5208 g_utf8_offset_to_pointer (text, entry->current_pos) - text);
5215 gtk_entry_delete_surrounding_cb (GtkIMContext *slave,
5220 if (entry->editable)
5221 gtk_editable_delete_text (GTK_EDITABLE (entry),
5222 entry->current_pos + offset,
5223 entry->current_pos + offset + n_chars);
5228 /* Internal functions
5231 /* Used for im_commit_cb and inserting Unicode chars */
5233 gtk_entry_enter_text (GtkEntry *entry,
5236 GtkEditable *editable = GTK_EDITABLE (entry);
5238 gboolean old_need_im_reset;
5240 old_need_im_reset = entry->need_im_reset;
5241 entry->need_im_reset = FALSE;
5243 if (gtk_editable_get_selection_bounds (editable, NULL, NULL))
5244 gtk_editable_delete_selection (editable);
5247 if (entry->overwrite_mode)
5248 gtk_entry_delete_from_cursor (entry, GTK_DELETE_CHARS, 1);
5251 tmp_pos = entry->current_pos;
5252 gtk_editable_insert_text (editable, str, strlen (str), &tmp_pos);
5253 gtk_editable_set_position (editable, tmp_pos);
5255 entry->need_im_reset = old_need_im_reset;
5258 /* All changes to entry->current_pos and entry->selection_bound
5259 * should go through this function.
5262 gtk_entry_set_positions (GtkEntry *entry,
5264 gint selection_bound)
5266 gboolean changed = FALSE;
5268 g_object_freeze_notify (G_OBJECT (entry));
5270 if (current_pos != -1 &&
5271 entry->current_pos != current_pos)
5273 entry->current_pos = current_pos;
5276 g_object_notify (G_OBJECT (entry), "cursor-position");
5279 if (selection_bound != -1 &&
5280 entry->selection_bound != selection_bound)
5282 entry->selection_bound = selection_bound;
5285 g_object_notify (G_OBJECT (entry), "selection-bound");
5288 g_object_thaw_notify (G_OBJECT (entry));
5292 gtk_entry_move_adjustments (entry);
5293 gtk_entry_recompute (entry);
5298 gtk_entry_reset_layout (GtkEntry *entry)
5300 if (entry->cached_layout)
5302 g_object_unref (entry->cached_layout);
5303 entry->cached_layout = NULL;
5308 update_im_cursor_location (GtkEntry *entry)
5312 gint strong_xoffset;
5313 gint area_width, area_height;
5315 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
5316 gtk_entry_get_text_area_size (entry, NULL, NULL, &area_width, &area_height);
5318 strong_xoffset = strong_x - entry->scroll_offset;
5319 if (strong_xoffset < 0)
5323 else if (strong_xoffset > area_width)
5325 strong_xoffset = area_width;
5327 area.x = strong_xoffset;
5330 area.height = area_height;
5332 gtk_im_context_set_cursor_location (entry->im_context, &area);
5336 recompute_idle_func (gpointer data)
5340 entry = GTK_ENTRY (data);
5342 entry->recompute_idle = 0;
5344 if (gtk_widget_has_screen (GTK_WIDGET (entry)))
5346 gtk_entry_adjust_scroll (entry);
5347 gtk_entry_queue_draw (entry);
5349 update_im_cursor_location (entry);
5356 gtk_entry_recompute (GtkEntry *entry)
5358 gtk_entry_reset_layout (entry);
5359 gtk_entry_check_cursor_blink (entry);
5361 if (!entry->recompute_idle)
5363 entry->recompute_idle = gdk_threads_add_idle_full (G_PRIORITY_HIGH_IDLE + 15, /* between resize and redraw */
5364 recompute_idle_func, entry, NULL);
5368 static PangoLayout *
5369 gtk_entry_create_layout (GtkEntry *entry,
5370 gboolean include_preedit)
5372 GtkWidget *widget = GTK_WIDGET (entry);
5373 PangoLayout *layout = gtk_widget_create_pango_layout (widget, NULL);
5374 PangoAttrList *tmp_attrs = pango_attr_list_new ();
5376 gchar *preedit_string = NULL;
5377 gint preedit_length = 0;
5378 PangoAttrList *preedit_attrs = NULL;
5383 pango_layout_set_single_paragraph_mode (layout, TRUE);
5385 display = gtk_entry_get_display_text (entry, 0, -1);
5386 n_bytes = strlen (display);
5388 if (include_preedit)
5390 gtk_im_context_get_preedit_string (entry->im_context,
5391 &preedit_string, &preedit_attrs, NULL);
5392 preedit_length = entry->preedit_length;
5397 GString *tmp_string = g_string_new (display);
5398 gint cursor_index = g_utf8_offset_to_pointer (display, entry->current_pos) - display;
5400 g_string_insert (tmp_string, cursor_index, preedit_string);
5402 pango_layout_set_text (layout, tmp_string->str, tmp_string->len);
5404 pango_attr_list_splice (tmp_attrs, preedit_attrs,
5405 cursor_index, preedit_length);
5407 g_string_free (tmp_string, TRUE);
5411 PangoDirection pango_dir;
5413 if (gtk_entry_get_display_mode (entry) == DISPLAY_NORMAL)
5414 pango_dir = pango_find_base_dir (display, n_bytes);
5416 pango_dir = PANGO_DIRECTION_NEUTRAL;
5418 if (pango_dir == PANGO_DIRECTION_NEUTRAL)
5420 if (gtk_widget_has_focus (widget))
5422 GdkDisplay *display = gtk_widget_get_display (widget);
5423 GdkKeymap *keymap = gdk_keymap_get_for_display (display);
5424 if (gdk_keymap_get_direction (keymap) == PANGO_DIRECTION_RTL)
5425 pango_dir = PANGO_DIRECTION_RTL;
5427 pango_dir = PANGO_DIRECTION_LTR;
5431 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
5432 pango_dir = PANGO_DIRECTION_RTL;
5434 pango_dir = PANGO_DIRECTION_LTR;
5438 pango_context_set_base_dir (gtk_widget_get_pango_context (widget),
5441 entry->resolved_dir = pango_dir;
5443 pango_layout_set_text (layout, display, n_bytes);
5446 pango_layout_set_attributes (layout, tmp_attrs);
5448 g_free (preedit_string);
5452 pango_attr_list_unref (preedit_attrs);
5454 pango_attr_list_unref (tmp_attrs);
5459 static PangoLayout *
5460 gtk_entry_ensure_layout (GtkEntry *entry,
5461 gboolean include_preedit)
5463 if (entry->preedit_length > 0 &&
5464 !include_preedit != !entry->cache_includes_preedit)
5465 gtk_entry_reset_layout (entry);
5467 if (!entry->cached_layout)
5469 entry->cached_layout = gtk_entry_create_layout (entry, include_preedit);
5470 entry->cache_includes_preedit = include_preedit;
5473 return entry->cached_layout;
5477 get_layout_position (GtkEntry *entry,
5481 PangoLayout *layout;
5482 PangoRectangle logical_rect;
5483 gint area_width, area_height;
5484 GtkBorder inner_border;
5486 PangoLayoutLine *line;
5488 layout = gtk_entry_ensure_layout (entry, TRUE);
5490 gtk_entry_get_text_area_size (entry, NULL, NULL, &area_width, &area_height);
5491 _gtk_entry_effective_inner_border (entry, &inner_border);
5493 area_height = PANGO_SCALE * (area_height - inner_border.top - inner_border.bottom);
5495 line = pango_layout_get_lines_readonly (layout)->data;
5496 pango_layout_line_get_extents (line, NULL, &logical_rect);
5498 /* Align primarily for locale's ascent/descent */
5499 y_pos = ((area_height - entry->ascent - entry->descent) / 2 +
5500 entry->ascent + logical_rect.y);
5502 /* Now see if we need to adjust to fit in actual drawn string */
5503 if (logical_rect.height > area_height)
5504 y_pos = (area_height - logical_rect.height) / 2;
5507 else if (y_pos + logical_rect.height > area_height)
5508 y_pos = area_height - logical_rect.height;
5510 y_pos = inner_border.top + y_pos / PANGO_SCALE;
5513 *x = inner_border.left - entry->scroll_offset;
5520 draw_text_with_color (GtkEntry *entry, cairo_t *cr, GdkColor *default_color)
5522 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
5525 gint start_pos, end_pos;
5527 widget = GTK_WIDGET (entry);
5531 get_layout_position (entry, &x, &y);
5533 cairo_move_to (cr, x, y);
5534 gdk_cairo_set_source_color (cr, default_color);
5535 pango_cairo_show_layout (cr, layout);
5537 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start_pos, &end_pos))
5541 PangoRectangle logical_rect;
5542 GdkColor *selection_color, *text_color;
5543 GtkBorder inner_border;
5545 pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
5546 gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
5548 if (gtk_widget_has_focus (widget))
5550 selection_color = &widget->style->base [GTK_STATE_SELECTED];
5551 text_color = &widget->style->text [GTK_STATE_SELECTED];
5555 selection_color = &widget->style->base [GTK_STATE_ACTIVE];
5556 text_color = &widget->style->text [GTK_STATE_ACTIVE];
5559 _gtk_entry_effective_inner_border (entry, &inner_border);
5561 for (i = 0; i < n_ranges; ++i)
5562 cairo_rectangle (cr,
5563 inner_border.left - entry->scroll_offset + ranges[2 * i],
5566 logical_rect.height);
5570 gdk_cairo_set_source_color (cr, selection_color);
5573 cairo_move_to (cr, x, y);
5574 gdk_cairo_set_source_color (cr, text_color);
5575 pango_cairo_show_layout (cr, layout);
5583 gtk_entry_draw_text (GtkEntry *entry)
5585 GtkWidget *widget = GTK_WIDGET (entry);
5588 /* Nothing to display at all */
5589 if (gtk_entry_get_display_mode (entry) == DISPLAY_BLANK)
5592 if (gtk_widget_is_drawable (widget))
5594 GdkColor text_color, bar_text_color;
5597 gint progress_x, progress_y, progress_width, progress_height;
5600 state = GTK_STATE_SELECTED;
5601 if (!gtk_widget_get_sensitive (widget))
5602 state = GTK_STATE_INSENSITIVE;
5603 text_color = widget->style->text[widget->state];
5604 bar_text_color = widget->style->fg[state];
5606 get_progress_area (widget,
5607 &progress_x, &progress_y,
5608 &progress_width, &progress_height);
5610 cr = gdk_cairo_create (entry->text_area);
5612 /* If the color is the same, or the progress area has a zero
5613 * size, then we only need to draw once. */
5614 if ((text_color.pixel == bar_text_color.pixel) ||
5615 ((progress_width == 0) || (progress_height == 0)))
5617 draw_text_with_color (entry, cr, &text_color);
5621 gdk_drawable_get_size (entry->text_area, &width, &height);
5623 cairo_rectangle (cr, 0, 0, width, height);
5627 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
5628 cairo_rectangle (cr, 0, 0, width, height);
5630 gdk_window_get_position (entry->text_area, &pos_x, &pos_y);
5631 progress_x -= pos_x;
5632 progress_y -= pos_y;
5634 cairo_rectangle (cr, progress_x, progress_y,
5635 progress_width, progress_height);
5637 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_WINDING);
5639 draw_text_with_color (entry, cr, &text_color);
5642 cairo_rectangle (cr, progress_x, progress_y,
5643 progress_width, progress_height);
5646 draw_text_with_color (entry, cr, &bar_text_color);
5654 draw_insertion_cursor (GtkEntry *entry,
5655 GdkRectangle *cursor_location,
5656 gboolean is_primary,
5657 PangoDirection direction,
5658 gboolean draw_arrow)
5660 GtkWidget *widget = GTK_WIDGET (entry);
5661 GtkTextDirection text_dir;
5663 if (direction == PANGO_DIRECTION_LTR)
5664 text_dir = GTK_TEXT_DIR_LTR;
5666 text_dir = GTK_TEXT_DIR_RTL;
5668 gtk_draw_insertion_cursor (widget, entry->text_area, NULL,
5670 is_primary, text_dir, draw_arrow);
5674 gtk_entry_draw_cursor (GtkEntry *entry,
5677 GtkWidget *widget = GTK_WIDGET (entry);
5678 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
5679 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
5681 if (gtk_widget_is_drawable (widget))
5683 GdkRectangle cursor_location;
5684 gboolean split_cursor;
5685 PangoRectangle cursor_rect;
5686 GtkBorder inner_border;
5688 gint text_area_height;
5691 gboolean block_at_line_end;
5692 PangoLayout *layout;
5695 _gtk_entry_effective_inner_border (entry, &inner_border);
5697 xoffset = inner_border.left - entry->scroll_offset;
5699 gdk_drawable_get_size (entry->text_area, NULL, &text_area_height);
5701 layout = gtk_entry_ensure_layout (entry, TRUE);
5702 text = pango_layout_get_text (layout);
5703 cursor_index = g_utf8_offset_to_pointer (text, entry->current_pos + entry->preedit_cursor) - text;
5704 if (!entry->overwrite_mode)
5707 block = _gtk_text_util_get_block_cursor_location (layout,
5708 cursor_index, &cursor_rect, &block_at_line_end);
5712 gint strong_x, weak_x;
5713 PangoDirection dir1 = PANGO_DIRECTION_NEUTRAL;
5714 PangoDirection dir2 = PANGO_DIRECTION_NEUTRAL;
5718 gtk_entry_get_cursor_locations (entry, type, &strong_x, &weak_x);
5720 g_object_get (gtk_widget_get_settings (widget),
5721 "gtk-split-cursor", &split_cursor,
5724 dir1 = entry->resolved_dir;
5730 if (weak_x != strong_x)
5732 dir2 = (entry->resolved_dir == PANGO_DIRECTION_LTR) ? PANGO_DIRECTION_RTL : PANGO_DIRECTION_LTR;
5738 if (keymap_direction == entry->resolved_dir)
5744 cursor_location.x = xoffset + x1;
5745 cursor_location.y = inner_border.top;
5746 cursor_location.width = 0;
5747 cursor_location.height = text_area_height - inner_border.top - inner_border.bottom;
5749 draw_insertion_cursor (entry,
5750 &cursor_location, TRUE, dir1,
5751 dir2 != PANGO_DIRECTION_NEUTRAL);
5753 if (dir2 != PANGO_DIRECTION_NEUTRAL)
5755 cursor_location.x = xoffset + x2;
5756 draw_insertion_cursor (entry,
5757 &cursor_location, FALSE, dir2,
5761 else /* overwrite_mode */
5763 GdkColor cursor_color;
5768 get_layout_position (entry, &x, &y);
5770 rect.x = PANGO_PIXELS (cursor_rect.x) + x;
5771 rect.y = PANGO_PIXELS (cursor_rect.y) + y;
5772 rect.width = PANGO_PIXELS (cursor_rect.width);
5773 rect.height = PANGO_PIXELS (cursor_rect.height);
5775 cr = gdk_cairo_create (entry->text_area);
5777 _gtk_widget_get_cursor_color (widget, &cursor_color);
5778 gdk_cairo_set_source_color (cr, &cursor_color);
5779 gdk_cairo_rectangle (cr, &rect);
5782 if (!block_at_line_end)
5784 gdk_cairo_rectangle (cr, &rect);
5786 cairo_move_to (cr, x, y);
5787 gdk_cairo_set_source_color (cr, &widget->style->base[widget->state]);
5788 pango_cairo_show_layout (cr, layout);
5797 gtk_entry_queue_draw (GtkEntry *entry)
5799 if (gtk_widget_is_drawable (GTK_WIDGET (entry)))
5800 gdk_window_invalidate_rect (entry->text_area, NULL, FALSE);
5804 _gtk_entry_reset_im_context (GtkEntry *entry)
5806 if (entry->need_im_reset)
5808 entry->need_im_reset = FALSE;
5809 gtk_im_context_reset (entry->im_context);
5814 * gtk_entry_reset_im_context:
5815 * @entry: a #GtkEntry
5817 * Reset the input method context of the entry if needed.
5819 * This can be necessary in the case where modifying the buffer
5820 * would confuse on-going input method behavior.
5825 gtk_entry_reset_im_context (GtkEntry *entry)
5827 g_return_if_fail (GTK_IS_ENTRY (entry));
5829 _gtk_entry_reset_im_context (entry);
5833 * gtk_entry_im_context_filter_keypress:
5834 * @entry: a #GtkEntry
5835 * @event: the key event
5837 * Allow the #GtkEntry input method to internally handle key press
5838 * and release events. If this function returns %TRUE, then no further
5839 * processing should be done for this key event. See
5840 * gtk_im_context_filter_keypress().
5842 * Note that you are expected to call this function from your handler
5843 * when overriding key event handling. This is needed in the case when
5844 * you need to insert your own key handling between the input method
5845 * and the default key event handling of the #GtkEntry.
5846 * See gtk_text_view_reset_im_context() for an example of use.
5848 * Return value: %TRUE if the input method handled the key event.
5853 gtk_entry_im_context_filter_keypress (GtkEntry *entry,
5856 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
5858 return gtk_im_context_filter_keypress (entry->im_context, event);
5863 gtk_entry_find_position (GtkEntry *entry,
5866 PangoLayout *layout;
5867 PangoLayoutLine *line;
5874 layout = gtk_entry_ensure_layout (entry, TRUE);
5875 text = pango_layout_get_text (layout);
5876 cursor_index = g_utf8_offset_to_pointer (text, entry->current_pos) - text;
5878 line = pango_layout_get_lines_readonly (layout)->data;
5879 pango_layout_line_x_to_index (line, x * PANGO_SCALE, &index, &trailing);
5881 if (index >= cursor_index && entry->preedit_length)
5883 if (index >= cursor_index + entry->preedit_length)
5884 index -= entry->preedit_length;
5887 index = cursor_index;
5892 pos = g_utf8_pointer_to_offset (text, text + index);
5899 gtk_entry_get_cursor_locations (GtkEntry *entry,
5904 DisplayMode mode = gtk_entry_get_display_mode (entry);
5906 /* Nothing to display at all, so no cursor is relevant */
5907 if (mode == DISPLAY_BLANK)
5917 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
5918 const gchar *text = pango_layout_get_text (layout);
5919 PangoRectangle strong_pos, weak_pos;
5922 if (type == CURSOR_STANDARD)
5924 index = g_utf8_offset_to_pointer (text, entry->current_pos + entry->preedit_cursor) - text;
5926 else /* type == CURSOR_DND */
5928 index = g_utf8_offset_to_pointer (text, entry->dnd_position) - text;
5930 if (entry->dnd_position > entry->current_pos)
5932 if (mode == DISPLAY_NORMAL)
5933 index += entry->preedit_length;
5936 gint preedit_len_chars = g_utf8_strlen (text, -1) - gtk_entry_buffer_get_length (get_buffer (entry));
5937 index += preedit_len_chars * g_unichar_to_utf8 (entry->invisible_char, NULL);
5942 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
5945 *strong_x = strong_pos.x / PANGO_SCALE;
5948 *weak_x = weak_pos.x / PANGO_SCALE;
5953 gtk_entry_adjust_scroll (GtkEntry *entry)
5955 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
5956 gint min_offset, max_offset;
5957 gint text_area_width, text_width;
5958 GtkBorder inner_border;
5959 gint strong_x, weak_x;
5960 gint strong_xoffset, weak_xoffset;
5962 PangoLayout *layout;
5963 PangoLayoutLine *line;
5964 PangoRectangle logical_rect;
5966 if (!gtk_widget_get_realized (GTK_WIDGET (entry)))
5969 _gtk_entry_effective_inner_border (entry, &inner_border);
5971 gdk_drawable_get_size (entry->text_area, &text_area_width, NULL);
5972 text_area_width -= inner_border.left + inner_border.right;
5973 if (text_area_width < 0)
5974 text_area_width = 0;
5976 layout = gtk_entry_ensure_layout (entry, TRUE);
5977 line = pango_layout_get_lines_readonly (layout)->data;
5979 pango_layout_line_get_extents (line, NULL, &logical_rect);
5981 /* Display as much text as we can */
5983 if (entry->resolved_dir == PANGO_DIRECTION_LTR)
5984 xalign = priv->xalign;
5986 xalign = 1.0 - priv->xalign;
5988 text_width = PANGO_PIXELS(logical_rect.width);
5990 if (text_width > text_area_width)
5993 max_offset = text_width - text_area_width;
5997 min_offset = (text_width - text_area_width) * xalign;
5998 max_offset = min_offset;
6001 entry->scroll_offset = CLAMP (entry->scroll_offset, min_offset, max_offset);
6003 /* And make sure cursors are on screen. Note that the cursor is
6004 * actually drawn one pixel into the INNER_BORDER space on
6005 * the right, when the scroll is at the utmost right. This
6006 * looks better to to me than confining the cursor inside the
6007 * border entirely, though it means that the cursor gets one
6008 * pixel closer to the edge of the widget on the right than
6009 * on the left. This might need changing if one changed
6010 * INNER_BORDER from 2 to 1, as one would do on a
6011 * small-screen-real-estate display.
6013 * We always make sure that the strong cursor is on screen, and
6014 * put the weak cursor on screen if possible.
6017 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, &weak_x);
6019 strong_xoffset = strong_x - entry->scroll_offset;
6021 if (strong_xoffset < 0)
6023 entry->scroll_offset += strong_xoffset;
6026 else if (strong_xoffset > text_area_width)
6028 entry->scroll_offset += strong_xoffset - text_area_width;
6029 strong_xoffset = text_area_width;
6032 weak_xoffset = weak_x - entry->scroll_offset;
6034 if (weak_xoffset < 0 && strong_xoffset - weak_xoffset <= text_area_width)
6036 entry->scroll_offset += weak_xoffset;
6038 else if (weak_xoffset > text_area_width &&
6039 strong_xoffset - (weak_xoffset - text_area_width) >= 0)
6041 entry->scroll_offset += weak_xoffset - text_area_width;
6044 g_object_notify (G_OBJECT (entry), "scroll-offset");
6048 gtk_entry_move_adjustments (GtkEntry *entry)
6050 PangoContext *context;
6051 PangoFontMetrics *metrics;
6052 gint x, layout_x, border_x, border_y;
6054 GtkAdjustment *adjustment;
6056 adjustment = g_object_get_qdata (G_OBJECT (entry), quark_cursor_hadjustment);
6060 /* Cursor position, layout offset, border width, and widget allocation */
6061 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &x, NULL);
6062 get_layout_position (entry, &layout_x, NULL);
6063 _gtk_entry_get_borders (entry, &border_x, &border_y);
6064 x += entry->widget.allocation.x + layout_x + border_x;
6066 /* Approximate width of a char, so user can see what is ahead/behind */
6067 context = gtk_widget_get_pango_context (GTK_WIDGET (entry));
6068 metrics = pango_context_get_metrics (context,
6069 entry->widget.style->font_desc,
6070 pango_context_get_language (context));
6071 char_width = pango_font_metrics_get_approximate_char_width (metrics) / PANGO_SCALE;
6074 gtk_adjustment_clamp_page (adjustment,
6075 x - (char_width + 1), /* one char + one pixel before */
6076 x + (char_width + 2)); /* one char + cursor + one pixel after */
6080 gtk_entry_move_visually (GtkEntry *entry,
6085 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6088 text = pango_layout_get_text (layout);
6090 index = g_utf8_offset_to_pointer (text, start) - text;
6094 int new_index, new_trailing;
6095 gboolean split_cursor;
6098 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
6099 "gtk-split-cursor", &split_cursor,
6106 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
6107 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
6109 strong = keymap_direction == entry->resolved_dir;
6114 pango_layout_move_cursor_visually (layout, strong, index, 0, 1, &new_index, &new_trailing);
6119 pango_layout_move_cursor_visually (layout, strong, index, 0, -1, &new_index, &new_trailing);
6125 else if (new_index != G_MAXINT)
6128 while (new_trailing--)
6129 index = g_utf8_next_char (text + index) - text;
6132 return g_utf8_pointer_to_offset (text, text + index);
6136 gtk_entry_move_logically (GtkEntry *entry,
6140 gint new_pos = start;
6143 length = gtk_entry_buffer_get_length (get_buffer (entry));
6145 /* Prevent any leak of information */
6146 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6148 new_pos = CLAMP (start + count, 0, length);
6152 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6153 PangoLogAttr *log_attrs;
6156 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6158 while (count > 0 && new_pos < length)
6162 while (new_pos < length && !log_attrs[new_pos].is_cursor_position);
6166 while (count < 0 && new_pos > 0)
6170 while (new_pos > 0 && !log_attrs[new_pos].is_cursor_position);
6182 gtk_entry_move_forward_word (GtkEntry *entry,
6184 gboolean allow_whitespace)
6186 gint new_pos = start;
6189 length = gtk_entry_buffer_get_length (get_buffer (entry));
6191 /* Prevent any leak of information */
6192 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6196 else if (new_pos < length)
6198 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6199 PangoLogAttr *log_attrs;
6202 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6204 /* Find the next word boundary */
6206 while (new_pos < n_attrs - 1 && !(log_attrs[new_pos].is_word_end ||
6207 (log_attrs[new_pos].is_word_start && allow_whitespace)))
6218 gtk_entry_move_backward_word (GtkEntry *entry,
6220 gboolean allow_whitespace)
6222 gint new_pos = start;
6224 /* Prevent any leak of information */
6225 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6231 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6232 PangoLogAttr *log_attrs;
6235 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6237 new_pos = start - 1;
6239 /* Find the previous word boundary */
6240 while (new_pos > 0 && !(log_attrs[new_pos].is_word_start ||
6241 (log_attrs[new_pos].is_word_end && allow_whitespace)))
6251 gtk_entry_delete_whitespace (GtkEntry *entry)
6253 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6254 PangoLogAttr *log_attrs;
6258 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6260 start = end = entry->current_pos;
6262 while (start > 0 && log_attrs[start-1].is_white)
6265 while (end < n_attrs && log_attrs[end].is_white)
6271 gtk_editable_delete_text (GTK_EDITABLE (entry), start, end);
6276 gtk_entry_select_word (GtkEntry *entry)
6278 gint start_pos = gtk_entry_move_backward_word (entry, entry->current_pos, TRUE);
6279 gint end_pos = gtk_entry_move_forward_word (entry, entry->current_pos, TRUE);
6281 gtk_editable_select_region (GTK_EDITABLE (entry), start_pos, end_pos);
6285 gtk_entry_select_line (GtkEntry *entry)
6287 gtk_editable_select_region (GTK_EDITABLE (entry), 0, -1);
6291 truncate_multiline (const gchar *text)
6296 text[length] && text[length] != '\n' && text[length] != '\r';
6303 paste_received (GtkClipboard *clipboard,
6307 GtkEntry *entry = GTK_ENTRY (data);
6308 GtkEditable *editable = GTK_EDITABLE (entry);
6309 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
6311 if (entry->button == 2)
6313 gint pos, start, end;
6314 pos = priv->insert_pos;
6315 gtk_editable_get_selection_bounds (editable, &start, &end);
6316 if (!((start <= pos && pos <= end) || (end <= pos && pos <= start)))
6317 gtk_editable_select_region (editable, pos, pos);
6322 gint pos, start, end;
6324 gboolean popup_completion;
6325 GtkEntryCompletion *completion;
6327 completion = gtk_entry_get_completion (entry);
6329 if (entry->truncate_multiline)
6330 length = truncate_multiline (text);
6332 /* only complete if the selection is at the end */
6333 popup_completion = (gtk_entry_buffer_get_length (get_buffer (entry)) ==
6334 MAX (entry->current_pos, entry->selection_bound));
6338 if (gtk_widget_get_mapped (completion->priv->popup_window))
6339 _gtk_entry_completion_popdown (completion);
6341 if (!popup_completion && completion->priv->changed_id > 0)
6342 g_signal_handler_block (entry, completion->priv->changed_id);
6345 begin_change (entry);
6346 g_object_freeze_notify (G_OBJECT (entry));
6347 if (gtk_editable_get_selection_bounds (editable, &start, &end))
6348 gtk_editable_delete_text (editable, start, end);
6350 pos = entry->current_pos;
6351 gtk_editable_insert_text (editable, text, length, &pos);
6352 gtk_editable_set_position (editable, pos);
6353 g_object_thaw_notify (G_OBJECT (entry));
6357 !popup_completion && completion->priv->changed_id > 0)
6358 g_signal_handler_unblock (entry, completion->priv->changed_id);
6361 g_object_unref (entry);
6365 gtk_entry_paste (GtkEntry *entry,
6368 g_object_ref (entry);
6369 gtk_clipboard_request_text (gtk_widget_get_clipboard (GTK_WIDGET (entry), selection),
6370 paste_received, entry);
6374 primary_get_cb (GtkClipboard *clipboard,
6375 GtkSelectionData *selection_data,
6379 GtkEntry *entry = GTK_ENTRY (data);
6382 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end))
6384 gchar *str = gtk_entry_get_display_text (entry, start, end);
6385 gtk_selection_data_set_text (selection_data, str, -1);
6391 primary_clear_cb (GtkClipboard *clipboard,
6394 GtkEntry *entry = GTK_ENTRY (data);
6396 gtk_editable_select_region (GTK_EDITABLE (entry), entry->current_pos, entry->current_pos);
6400 gtk_entry_update_primary_selection (GtkEntry *entry)
6402 GtkTargetList *list;
6403 GtkTargetEntry *targets;
6404 GtkClipboard *clipboard;
6408 if (!gtk_widget_get_realized (GTK_WIDGET (entry)))
6411 list = gtk_target_list_new (NULL, 0);
6412 gtk_target_list_add_text_targets (list, 0);
6414 targets = gtk_target_table_new_from_list (list, &n_targets);
6416 clipboard = gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_PRIMARY);
6418 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end))
6420 if (!gtk_clipboard_set_with_owner (clipboard, targets, n_targets,
6421 primary_get_cb, primary_clear_cb, G_OBJECT (entry)))
6422 primary_clear_cb (clipboard, entry);
6426 if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (entry))
6427 gtk_clipboard_clear (clipboard);
6430 gtk_target_table_free (targets, n_targets);
6431 gtk_target_list_unref (list);
6435 gtk_entry_clear (GtkEntry *entry,
6436 GtkEntryIconPosition icon_pos)
6438 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
6439 EntryIconInfo *icon_info = priv->icons[icon_pos];
6441 if (!icon_info || icon_info->storage_type == GTK_IMAGE_EMPTY)
6444 g_object_freeze_notify (G_OBJECT (entry));
6446 /* Explicitly check, as the pointer may become invalidated
6447 * during destruction.
6449 if (GDK_IS_WINDOW (icon_info->window))
6450 gdk_window_hide (icon_info->window);
6452 if (icon_info->pixbuf)
6454 g_object_unref (icon_info->pixbuf);
6455 icon_info->pixbuf = NULL;
6458 switch (icon_info->storage_type)
6460 case GTK_IMAGE_PIXBUF:
6461 g_object_notify (G_OBJECT (entry),
6462 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-pixbuf" : "secondary-icon-pixbuf");
6465 case GTK_IMAGE_STOCK:
6466 g_free (icon_info->stock_id);
6467 icon_info->stock_id = NULL;
6468 g_object_notify (G_OBJECT (entry),
6469 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-stock" : "secondary-icon-stock");
6472 case GTK_IMAGE_ICON_NAME:
6473 g_free (icon_info->icon_name);
6474 icon_info->icon_name = NULL;
6475 g_object_notify (G_OBJECT (entry),
6476 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-name" : "secondary-icon-name");
6479 case GTK_IMAGE_GICON:
6480 if (icon_info->gicon)
6482 g_object_unref (icon_info->gicon);
6483 icon_info->gicon = NULL;
6485 g_object_notify (G_OBJECT (entry),
6486 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-gicon" : "secondary-icon-gicon");
6490 g_assert_not_reached ();
6494 icon_info->storage_type = GTK_IMAGE_EMPTY;
6495 g_object_notify (G_OBJECT (entry),
6496 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-storage-type" : "secondary-icon-storage-type");
6498 g_object_thaw_notify (G_OBJECT (entry));
6502 gtk_entry_ensure_pixbuf (GtkEntry *entry,
6503 GtkEntryIconPosition icon_pos)
6505 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
6506 EntryIconInfo *icon_info = priv->icons[icon_pos];
6508 GtkIconTheme *icon_theme;
6509 GtkSettings *settings;
6515 if (!icon_info || icon_info->pixbuf)
6518 widget = GTK_WIDGET (entry);
6520 switch (icon_info->storage_type)
6522 case GTK_IMAGE_EMPTY:
6523 case GTK_IMAGE_PIXBUF:
6525 case GTK_IMAGE_STOCK:
6526 state = gtk_widget_get_state (widget);
6527 gtk_widget_set_state (widget, GTK_STATE_NORMAL);
6528 icon_info->pixbuf = gtk_widget_render_icon (widget,
6529 icon_info->stock_id,
6532 if (!icon_info->pixbuf)
6533 icon_info->pixbuf = gtk_widget_render_icon (widget,
6534 GTK_STOCK_MISSING_IMAGE,
6537 gtk_widget_set_state (widget, state);
6540 case GTK_IMAGE_ICON_NAME:
6541 screen = gtk_widget_get_screen (widget);
6544 icon_theme = gtk_icon_theme_get_for_screen (screen);
6545 settings = gtk_settings_get_for_screen (screen);
6547 gtk_icon_size_lookup_for_settings (settings,
6551 icon_info->pixbuf = gtk_icon_theme_load_icon (icon_theme,
6552 icon_info->icon_name,
6553 MIN (width, height),
6556 if (icon_info->pixbuf == NULL)
6558 state = gtk_widget_get_state (widget);
6559 gtk_widget_set_state (widget, GTK_STATE_NORMAL);
6560 icon_info->pixbuf = gtk_widget_render_icon (widget,
6561 GTK_STOCK_MISSING_IMAGE,
6564 gtk_widget_set_state (widget, state);
6569 case GTK_IMAGE_GICON:
6570 screen = gtk_widget_get_screen (widget);
6573 icon_theme = gtk_icon_theme_get_for_screen (screen);
6574 settings = gtk_settings_get_for_screen (screen);
6576 gtk_icon_size_lookup_for_settings (settings,
6580 info = gtk_icon_theme_lookup_by_gicon (icon_theme,
6582 MIN (width, height),
6583 GTK_ICON_LOOKUP_USE_BUILTIN);
6586 icon_info->pixbuf = gtk_icon_info_load_icon (info, NULL);
6587 gtk_icon_info_free (info);
6590 if (icon_info->pixbuf == NULL)
6592 state = gtk_widget_get_state (widget);
6593 gtk_widget_set_state (widget, GTK_STATE_NORMAL);
6594 icon_info->pixbuf = gtk_widget_render_icon (widget,
6595 GTK_STOCK_MISSING_IMAGE,
6598 gtk_widget_set_state (widget, state);
6604 g_assert_not_reached ();
6608 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
6609 gdk_window_show_unraised (icon_info->window);
6619 * Creates a new entry.
6621 * Return value: a new #GtkEntry.
6624 gtk_entry_new (void)
6626 return g_object_new (GTK_TYPE_ENTRY, NULL);
6630 * gtk_entry_new_with_buffer:
6631 * @buffer: The buffer to use for the new #GtkEntry.
6633 * Creates a new entry with the specified text buffer.
6635 * Return value: a new #GtkEntry
6640 gtk_entry_new_with_buffer (GtkEntryBuffer *buffer)
6642 g_return_val_if_fail (GTK_IS_ENTRY_BUFFER (buffer), NULL);
6643 return g_object_new (GTK_TYPE_ENTRY, "buffer", buffer, NULL);
6646 static GtkEntryBuffer*
6647 get_buffer (GtkEntry *entry)
6649 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
6651 if (priv->buffer == NULL)
6653 GtkEntryBuffer *buffer;
6654 buffer = gtk_entry_buffer_new (NULL, 0);
6655 gtk_entry_set_buffer (entry, buffer);
6656 g_object_unref (buffer);
6659 return priv->buffer;
6663 * gtk_entry_get_buffer:
6664 * @entry: a #GtkEntry
6666 * Get the #GtkEntryBuffer object which holds the text for
6671 * Returns: A #GtkEntryBuffer object.
6674 gtk_entry_get_buffer (GtkEntry *entry)
6676 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
6678 return get_buffer (entry);
6682 * gtk_entry_set_buffer:
6683 * @entry: a #GtkEntry
6684 * @buffer: a #GtkEntryBuffer
6686 * Set the #GtkEntryBuffer object which holds the text for
6692 gtk_entry_set_buffer (GtkEntry *entry,
6693 GtkEntryBuffer *buffer)
6695 GtkEntryPrivate *priv;
6698 g_return_if_fail (GTK_IS_ENTRY (entry));
6699 priv = GTK_ENTRY_GET_PRIVATE (entry);
6703 g_return_if_fail (GTK_IS_ENTRY_BUFFER (buffer));
6704 g_object_ref (buffer);
6709 buffer_disconnect_signals (entry);
6710 g_object_unref (priv->buffer);
6712 /* COMPAT: Deprecated. Not used. Setting these fields no longer necessary in GTK 3.x */
6714 entry->text_length = 0;
6715 entry->text_max_length = 0;
6718 priv->buffer = buffer;
6722 buffer_connect_signals (entry);
6724 /* COMPAT: Deprecated. Not used. Setting these fields no longer necessary in GTK 3.x */
6725 entry->text = (char*)gtk_entry_buffer_get_text (priv->buffer);
6726 entry->text_length = gtk_entry_buffer_get_length (priv->buffer);
6727 entry->text_max_length = gtk_entry_buffer_get_max_length (priv->buffer);
6730 obj = G_OBJECT (entry);
6731 g_object_freeze_notify (obj);
6732 g_object_notify (obj, "buffer");
6733 g_object_notify (obj, "text");
6734 g_object_notify (obj, "text-length");
6735 g_object_notify (obj, "max-length");
6736 g_object_notify (obj, "visibility");
6737 g_object_notify (obj, "invisible-char");
6738 g_object_notify (obj, "invisible-char-set");
6739 g_object_thaw_notify (obj);
6741 gtk_editable_set_position (GTK_EDITABLE (entry), 0);
6742 gtk_entry_recompute (entry);
6746 * gtk_entry_get_text_window:
6747 * @entry: a #GtkEntry
6749 * Returns the #GdkWindow which contains the text. This function is
6750 * useful when drawing something to the entry in an expose-event
6751 * callback because it enables the callback to distinguish between
6752 * the text window and entry's icon windows.
6754 * See also gtk_entry_get_icon_window().
6756 * Return value: the entry's text window.
6761 gtk_entry_get_text_window (GtkEntry *entry)
6763 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
6765 return entry->text_area;
6770 * gtk_entry_set_text:
6771 * @entry: a #GtkEntry
6772 * @text: the new text
6774 * Sets the text in the widget to the given
6775 * value, replacing the current contents.
6777 * See gtk_entry_buffer_set_text().
6780 gtk_entry_set_text (GtkEntry *entry,
6784 GtkEntryCompletion *completion;
6785 GtkEntryPrivate *priv;
6787 g_return_if_fail (GTK_IS_ENTRY (entry));
6788 g_return_if_fail (text != NULL);
6789 priv = GTK_ENTRY_GET_PRIVATE (entry);
6791 /* Actually setting the text will affect the cursor and selection;
6792 * if the contents don't actually change, this will look odd to the user.
6794 if (strcmp (gtk_entry_buffer_get_text (get_buffer (entry)), text) == 0)
6797 completion = gtk_entry_get_completion (entry);
6798 if (completion && completion->priv->changed_id > 0)
6799 g_signal_handler_block (entry, completion->priv->changed_id);
6801 begin_change (entry);
6802 g_object_freeze_notify (G_OBJECT (entry));
6803 gtk_editable_delete_text (GTK_EDITABLE (entry), 0, -1);
6805 gtk_editable_insert_text (GTK_EDITABLE (entry), text, strlen (text), &tmp_pos);
6806 g_object_thaw_notify (G_OBJECT (entry));
6809 if (completion && completion->priv->changed_id > 0)
6810 g_signal_handler_unblock (entry, completion->priv->changed_id);
6814 * gtk_entry_set_visibility:
6815 * @entry: a #GtkEntry
6816 * @visible: %TRUE if the contents of the entry are displayed
6819 * Sets whether the contents of the entry are visible or not.
6820 * When visibility is set to %FALSE, characters are displayed
6821 * as the invisible char, and will also appear that way when
6822 * the text in the entry widget is copied elsewhere.
6824 * By default, GTK+ picks the best invisible character available
6825 * in the current font, but it can be changed with
6826 * gtk_entry_set_invisible_char().
6829 gtk_entry_set_visibility (GtkEntry *entry,
6832 g_return_if_fail (GTK_IS_ENTRY (entry));
6834 visible = visible != FALSE;
6836 if (entry->visible != visible)
6838 entry->visible = visible;
6840 g_object_notify (G_OBJECT (entry), "visibility");
6841 gtk_entry_recompute (entry);
6846 * gtk_entry_get_visibility:
6847 * @entry: a #GtkEntry
6849 * Retrieves whether the text in @entry is visible. See
6850 * gtk_entry_set_visibility().
6852 * Return value: %TRUE if the text is currently visible
6855 gtk_entry_get_visibility (GtkEntry *entry)
6857 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
6859 return entry->visible;
6863 * gtk_entry_set_invisible_char:
6864 * @entry: a #GtkEntry
6865 * @ch: a Unicode character
6867 * Sets the character to use in place of the actual text when
6868 * gtk_entry_set_visibility() has been called to set text visibility
6869 * to %FALSE. i.e. this is the character used in "password mode" to
6870 * show the user how many characters have been typed. By default, GTK+
6871 * picks the best invisible char available in the current font. If you
6872 * set the invisible char to 0, then the user will get no feedback
6873 * at all; there will be no text on the screen as they type.
6876 gtk_entry_set_invisible_char (GtkEntry *entry,
6879 GtkEntryPrivate *priv;
6881 g_return_if_fail (GTK_IS_ENTRY (entry));
6883 priv = GTK_ENTRY_GET_PRIVATE (entry);
6885 if (!priv->invisible_char_set)
6887 priv->invisible_char_set = TRUE;
6888 g_object_notify (G_OBJECT (entry), "invisible-char-set");
6891 if (ch == entry->invisible_char)
6894 entry->invisible_char = ch;
6895 g_object_notify (G_OBJECT (entry), "invisible-char");
6896 gtk_entry_recompute (entry);
6900 * gtk_entry_get_invisible_char:
6901 * @entry: a #GtkEntry
6903 * Retrieves the character displayed in place of the real characters
6904 * for entries with visibility set to false. See gtk_entry_set_invisible_char().
6906 * Return value: the current invisible char, or 0, if the entry does not
6907 * show invisible text at all.
6910 gtk_entry_get_invisible_char (GtkEntry *entry)
6912 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
6914 return entry->invisible_char;
6918 * gtk_entry_unset_invisible_char:
6919 * @entry: a #GtkEntry
6921 * Unsets the invisible char previously set with
6922 * gtk_entry_set_invisible_char(). So that the
6923 * default invisible char is used again.
6928 gtk_entry_unset_invisible_char (GtkEntry *entry)
6930 GtkEntryPrivate *priv;
6933 g_return_if_fail (GTK_IS_ENTRY (entry));
6935 priv = GTK_ENTRY_GET_PRIVATE (entry);
6937 if (!priv->invisible_char_set)
6940 priv->invisible_char_set = FALSE;
6941 ch = find_invisible_char (GTK_WIDGET (entry));
6943 if (entry->invisible_char != ch)
6945 entry->invisible_char = ch;
6946 g_object_notify (G_OBJECT (entry), "invisible-char");
6949 g_object_notify (G_OBJECT (entry), "invisible-char-set");
6950 gtk_entry_recompute (entry);
6954 * gtk_entry_set_overwrite_mode:
6955 * @entry: a #GtkEntry
6956 * @overwrite: new value
6958 * Sets whether the text is overwritten when typing in the #GtkEntry.
6963 gtk_entry_set_overwrite_mode (GtkEntry *entry,
6966 g_return_if_fail (GTK_IS_ENTRY (entry));
6968 if (entry->overwrite_mode == overwrite)
6971 gtk_entry_toggle_overwrite (entry);
6973 g_object_notify (G_OBJECT (entry), "overwrite-mode");
6977 * gtk_entry_get_overwrite_mode:
6978 * @entry: a #GtkEntry
6980 * Gets the value set by gtk_entry_set_overwrite_mode().
6982 * Return value: whether the text is overwritten when typing.
6987 gtk_entry_get_overwrite_mode (GtkEntry *entry)
6989 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
6991 return entry->overwrite_mode;
6995 * gtk_entry_get_text:
6996 * @entry: a #GtkEntry
6998 * Retrieves the contents of the entry widget.
6999 * See also gtk_editable_get_chars().
7001 * This is equivalent to:
7003 * <informalexample><programlisting>
7004 * gtk_entry_buffer_get_text (gtk_entry_get_buffer (entry));
7005 * </programlisting></informalexample>
7007 * Return value: a pointer to the contents of the widget as a
7008 * string. This string points to internally allocated
7009 * storage in the widget and must not be freed, modified or
7012 G_CONST_RETURN gchar*
7013 gtk_entry_get_text (GtkEntry *entry)
7015 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7016 return gtk_entry_buffer_get_text (get_buffer (entry));
7020 * gtk_entry_set_max_length:
7021 * @entry: a #GtkEntry
7022 * @max: the maximum length of the entry, or 0 for no maximum.
7023 * (other than the maximum length of entries.) The value passed in will
7024 * be clamped to the range 0-65536.
7026 * Sets the maximum allowed length of the contents of the widget. If
7027 * the current contents are longer than the given length, then they
7028 * will be truncated to fit.
7030 * This is equivalent to:
7032 * <informalexample><programlisting>
7033 * gtk_entry_buffer_set_max_length (gtk_entry_get_buffer (entry), max);
7034 * </programlisting></informalexample>
7037 gtk_entry_set_max_length (GtkEntry *entry,
7040 g_return_if_fail (GTK_IS_ENTRY (entry));
7041 gtk_entry_buffer_set_max_length (get_buffer (entry), max);
7045 * gtk_entry_get_max_length:
7046 * @entry: a #GtkEntry
7048 * Retrieves the maximum allowed length of the text in
7049 * @entry. See gtk_entry_set_max_length().
7051 * This is equivalent to:
7053 * <informalexample><programlisting>
7054 * gtk_entry_buffer_get_max_length (gtk_entry_get_buffer (entry));
7055 * </programlisting></informalexample>
7057 * Return value: the maximum allowed number of characters
7058 * in #GtkEntry, or 0 if there is no maximum.
7061 gtk_entry_get_max_length (GtkEntry *entry)
7063 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7064 return gtk_entry_buffer_get_max_length (get_buffer (entry));
7068 * gtk_entry_get_text_length:
7069 * @entry: a #GtkEntry
7071 * Retrieves the current length of the text in
7074 * This is equivalent to:
7076 * <informalexample><programlisting>
7077 * gtk_entry_buffer_get_length (gtk_entry_get_buffer (entry));
7078 * </programlisting></informalexample>
7080 * Return value: the current number of characters
7081 * in #GtkEntry, or 0 if there are none.
7086 gtk_entry_get_text_length (GtkEntry *entry)
7088 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7089 return gtk_entry_buffer_get_length (get_buffer (entry));
7093 * gtk_entry_set_activates_default:
7094 * @entry: a #GtkEntry
7095 * @setting: %TRUE to activate window's default widget on Enter keypress
7097 * If @setting is %TRUE, pressing Enter in the @entry will activate the default
7098 * widget for the window containing the entry. This usually means that
7099 * the dialog box containing the entry will be closed, since the default
7100 * widget is usually one of the dialog buttons.
7102 * (For experts: if @setting is %TRUE, the entry calls
7103 * gtk_window_activate_default() on the window containing the entry, in
7104 * the default handler for the #GtkWidget::activate signal.)
7107 gtk_entry_set_activates_default (GtkEntry *entry,
7110 g_return_if_fail (GTK_IS_ENTRY (entry));
7111 setting = setting != FALSE;
7113 if (setting != entry->activates_default)
7115 entry->activates_default = setting;
7116 g_object_notify (G_OBJECT (entry), "activates-default");
7121 * gtk_entry_get_activates_default:
7122 * @entry: a #GtkEntry
7124 * Retrieves the value set by gtk_entry_set_activates_default().
7126 * Return value: %TRUE if the entry will activate the default widget
7129 gtk_entry_get_activates_default (GtkEntry *entry)
7131 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7133 return entry->activates_default;
7137 * gtk_entry_set_width_chars:
7138 * @entry: a #GtkEntry
7139 * @n_chars: width in chars
7141 * Changes the size request of the entry to be about the right size
7142 * for @n_chars characters. Note that it changes the size
7143 * <emphasis>request</emphasis>, the size can still be affected by
7144 * how you pack the widget into containers. If @n_chars is -1, the
7145 * size reverts to the default entry size.
7148 gtk_entry_set_width_chars (GtkEntry *entry,
7151 g_return_if_fail (GTK_IS_ENTRY (entry));
7153 if (entry->width_chars != n_chars)
7155 entry->width_chars = n_chars;
7156 g_object_notify (G_OBJECT (entry), "width-chars");
7157 gtk_widget_queue_resize (GTK_WIDGET (entry));
7162 * gtk_entry_get_width_chars:
7163 * @entry: a #GtkEntry
7165 * Gets the value set by gtk_entry_set_width_chars().
7167 * Return value: number of chars to request space for, or negative if unset
7170 gtk_entry_get_width_chars (GtkEntry *entry)
7172 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7174 return entry->width_chars;
7178 * gtk_entry_set_has_frame:
7179 * @entry: a #GtkEntry
7180 * @setting: new value
7182 * Sets whether the entry has a beveled frame around it.
7185 gtk_entry_set_has_frame (GtkEntry *entry,
7188 g_return_if_fail (GTK_IS_ENTRY (entry));
7190 setting = (setting != FALSE);
7192 if (entry->has_frame == setting)
7195 gtk_widget_queue_resize (GTK_WIDGET (entry));
7196 entry->has_frame = setting;
7197 g_object_notify (G_OBJECT (entry), "has-frame");
7201 * gtk_entry_get_has_frame:
7202 * @entry: a #GtkEntry
7204 * Gets the value set by gtk_entry_set_has_frame().
7206 * Return value: whether the entry has a beveled frame
7209 gtk_entry_get_has_frame (GtkEntry *entry)
7211 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7213 return entry->has_frame;
7217 * gtk_entry_set_inner_border:
7218 * @entry: a #GtkEntry
7219 * @border: (allow-none): a #GtkBorder, or %NULL
7221 * Sets %entry's inner-border property to %border, or clears it if %NULL
7222 * is passed. The inner-border is the area around the entry's text, but
7225 * If set, this property overrides the inner-border style property.
7226 * Overriding the style-provided border is useful when you want to do
7227 * in-place editing of some text in a canvas or list widget, where
7228 * pixel-exact positioning of the entry is important.
7233 gtk_entry_set_inner_border (GtkEntry *entry,
7234 const GtkBorder *border)
7236 g_return_if_fail (GTK_IS_ENTRY (entry));
7238 gtk_widget_queue_resize (GTK_WIDGET (entry));
7241 g_object_set_qdata_full (G_OBJECT (entry), quark_inner_border,
7242 gtk_border_copy (border),
7243 (GDestroyNotify) gtk_border_free);
7245 g_object_set_qdata (G_OBJECT (entry), quark_inner_border, NULL);
7247 g_object_notify (G_OBJECT (entry), "inner-border");
7251 * gtk_entry_get_inner_border:
7252 * @entry: a #GtkEntry
7254 * This function returns the entry's #GtkEntry:inner-border property. See
7255 * gtk_entry_set_inner_border() for more information.
7257 * Return value: (transfer none): the entry's #GtkBorder, or %NULL if none was set.
7261 G_CONST_RETURN GtkBorder *
7262 gtk_entry_get_inner_border (GtkEntry *entry)
7264 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7266 return g_object_get_qdata (G_OBJECT (entry), quark_inner_border);
7270 * gtk_entry_get_layout:
7271 * @entry: a #GtkEntry
7273 * Gets the #PangoLayout used to display the entry.
7274 * The layout is useful to e.g. convert text positions to
7275 * pixel positions, in combination with gtk_entry_get_layout_offsets().
7276 * The returned layout is owned by the entry and must not be
7277 * modified or freed by the caller.
7279 * Keep in mind that the layout text may contain a preedit string, so
7280 * gtk_entry_layout_index_to_text_index() and
7281 * gtk_entry_text_index_to_layout_index() are needed to convert byte
7282 * indices in the layout to byte indices in the entry contents.
7284 * Return value: (transfer none): the #PangoLayout for this entry
7287 gtk_entry_get_layout (GtkEntry *entry)
7289 PangoLayout *layout;
7291 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7293 layout = gtk_entry_ensure_layout (entry, TRUE);
7300 * gtk_entry_layout_index_to_text_index:
7301 * @entry: a #GtkEntry
7302 * @layout_index: byte index into the entry layout text
7304 * Converts from a position in the entry contents (returned
7305 * by gtk_entry_get_text()) to a position in the
7306 * entry's #PangoLayout (returned by gtk_entry_get_layout(),
7307 * with text retrieved via pango_layout_get_text()).
7309 * Return value: byte index into the entry contents
7312 gtk_entry_layout_index_to_text_index (GtkEntry *entry,
7315 PangoLayout *layout;
7319 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7321 layout = gtk_entry_ensure_layout (entry, TRUE);
7322 text = pango_layout_get_text (layout);
7323 cursor_index = g_utf8_offset_to_pointer (text, entry->current_pos) - text;
7325 if (layout_index >= cursor_index && entry->preedit_length)
7327 if (layout_index >= cursor_index + entry->preedit_length)
7328 layout_index -= entry->preedit_length;
7330 layout_index = cursor_index;
7333 return layout_index;
7337 * gtk_entry_text_index_to_layout_index:
7338 * @entry: a #GtkEntry
7339 * @text_index: byte index into the entry contents
7341 * Converts from a position in the entry's #PangoLayout (returned by
7342 * gtk_entry_get_layout()) to a position in the entry contents
7343 * (returned by gtk_entry_get_text()).
7345 * Return value: byte index into the entry layout text
7348 gtk_entry_text_index_to_layout_index (GtkEntry *entry,
7351 PangoLayout *layout;
7354 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7356 layout = gtk_entry_ensure_layout (entry, TRUE);
7357 text = pango_layout_get_text (layout);
7358 cursor_index = g_utf8_offset_to_pointer (text, entry->current_pos) - text;
7360 if (text_index > cursor_index)
7361 text_index += entry->preedit_length;
7367 * gtk_entry_get_layout_offsets:
7368 * @entry: a #GtkEntry
7369 * @x: (allow-none): location to store X offset of layout, or %NULL
7370 * @y: (allow-none): location to store Y offset of layout, or %NULL
7373 * Obtains the position of the #PangoLayout used to render text
7374 * in the entry, in widget coordinates. Useful if you want to line
7375 * up the text in an entry with some other text, e.g. when using the
7376 * entry to implement editable cells in a sheet widget.
7378 * Also useful to convert mouse events into coordinates inside the
7379 * #PangoLayout, e.g. to take some action if some part of the entry text
7382 * Note that as the user scrolls around in the entry the offsets will
7383 * change; you'll need to connect to the "notify::scroll-offset"
7384 * signal to track this. Remember when using the #PangoLayout
7385 * functions you need to convert to and from pixels using
7386 * PANGO_PIXELS() or #PANGO_SCALE.
7388 * Keep in mind that the layout text may contain a preedit string, so
7389 * gtk_entry_layout_index_to_text_index() and
7390 * gtk_entry_text_index_to_layout_index() are needed to convert byte
7391 * indices in the layout to byte indices in the entry contents.
7394 gtk_entry_get_layout_offsets (GtkEntry *entry,
7398 gint text_area_x, text_area_y;
7400 g_return_if_fail (GTK_IS_ENTRY (entry));
7402 /* this gets coords relative to text area */
7403 get_layout_position (entry, x, y);
7405 /* convert to widget coords */
7406 gtk_entry_get_text_area_size (entry, &text_area_x, &text_area_y, NULL, NULL);
7417 * gtk_entry_set_alignment:
7418 * @entry: a #GtkEntry
7419 * @xalign: The horizontal alignment, from 0 (left) to 1 (right).
7420 * Reversed for RTL layouts
7422 * Sets the alignment for the contents of the entry. This controls
7423 * the horizontal positioning of the contents when the displayed
7424 * text is shorter than the width of the entry.
7429 gtk_entry_set_alignment (GtkEntry *entry, gfloat xalign)
7431 GtkEntryPrivate *priv;
7433 g_return_if_fail (GTK_IS_ENTRY (entry));
7435 priv = GTK_ENTRY_GET_PRIVATE (entry);
7439 else if (xalign > 1.0)
7442 if (xalign != priv->xalign)
7444 priv->xalign = xalign;
7446 gtk_entry_recompute (entry);
7448 g_object_notify (G_OBJECT (entry), "xalign");
7453 * gtk_entry_get_alignment:
7454 * @entry: a #GtkEntry
7456 * Gets the value set by gtk_entry_set_alignment().
7458 * Return value: the alignment
7463 gtk_entry_get_alignment (GtkEntry *entry)
7465 GtkEntryPrivate *priv;
7467 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
7469 priv = GTK_ENTRY_GET_PRIVATE (entry);
7471 return priv->xalign;
7475 * gtk_entry_set_icon_from_pixbuf:
7476 * @entry: a #GtkEntry
7477 * @icon_pos: Icon position
7478 * @pixbuf: (allow-none): A #GdkPixbuf, or %NULL
7480 * Sets the icon shown in the specified position using a pixbuf.
7482 * If @pixbuf is %NULL, no icon will be shown in the specified position.
7487 gtk_entry_set_icon_from_pixbuf (GtkEntry *entry,
7488 GtkEntryIconPosition icon_pos,
7491 GtkEntryPrivate *priv;
7492 EntryIconInfo *icon_info;
7494 g_return_if_fail (GTK_IS_ENTRY (entry));
7495 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7497 priv = GTK_ENTRY_GET_PRIVATE (entry);
7499 if ((icon_info = priv->icons[icon_pos]) == NULL)
7500 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7502 g_object_freeze_notify (G_OBJECT (entry));
7505 g_object_ref (pixbuf);
7507 gtk_entry_clear (entry, icon_pos);
7511 icon_info->storage_type = GTK_IMAGE_PIXBUF;
7512 icon_info->pixbuf = pixbuf;
7514 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7516 g_object_notify (G_OBJECT (entry), "primary-icon-pixbuf");
7517 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7521 g_object_notify (G_OBJECT (entry), "secondary-icon-pixbuf");
7522 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7525 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7526 gdk_window_show_unraised (icon_info->window);
7529 gtk_entry_ensure_pixbuf (entry, icon_pos);
7531 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7532 gtk_widget_queue_resize (GTK_WIDGET (entry));
7534 g_object_thaw_notify (G_OBJECT (entry));
7538 * gtk_entry_set_icon_from_stock:
7539 * @entry: A #GtkEntry
7540 * @icon_pos: Icon position
7541 * @stock_id: (allow-none): The name of the stock item, or %NULL
7543 * Sets the icon shown in the entry at the specified position from
7546 * If @stock_id is %NULL, no icon will be shown in the specified position.
7551 gtk_entry_set_icon_from_stock (GtkEntry *entry,
7552 GtkEntryIconPosition icon_pos,
7553 const gchar *stock_id)
7555 GtkEntryPrivate *priv;
7556 EntryIconInfo *icon_info;
7559 g_return_if_fail (GTK_IS_ENTRY (entry));
7560 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7562 priv = GTK_ENTRY_GET_PRIVATE (entry);
7564 if ((icon_info = priv->icons[icon_pos]) == NULL)
7565 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7567 g_object_freeze_notify (G_OBJECT (entry));
7569 gtk_widget_ensure_style (GTK_WIDGET (entry));
7571 /* need to dup before clearing */
7572 new_id = g_strdup (stock_id);
7574 gtk_entry_clear (entry, icon_pos);
7578 icon_info->storage_type = GTK_IMAGE_STOCK;
7579 icon_info->stock_id = new_id;
7581 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7583 g_object_notify (G_OBJECT (entry), "primary-icon-stock");
7584 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7588 g_object_notify (G_OBJECT (entry), "secondary-icon-stock");
7589 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7592 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7593 gdk_window_show_unraised (icon_info->window);
7596 gtk_entry_ensure_pixbuf (entry, icon_pos);
7598 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7599 gtk_widget_queue_resize (GTK_WIDGET (entry));
7601 g_object_thaw_notify (G_OBJECT (entry));
7605 * gtk_entry_set_icon_from_icon_name:
7606 * @entry: A #GtkEntry
7607 * @icon_pos: The position at which to set the icon
7608 * @icon_name: (allow-none): An icon name, or %NULL
7610 * Sets the icon shown in the entry at the specified position
7611 * from the current icon theme.
7613 * If the icon name isn't known, a "broken image" icon will be displayed
7616 * If @icon_name is %NULL, no icon will be shown in the specified position.
7621 gtk_entry_set_icon_from_icon_name (GtkEntry *entry,
7622 GtkEntryIconPosition icon_pos,
7623 const gchar *icon_name)
7625 GtkEntryPrivate *priv;
7626 EntryIconInfo *icon_info;
7629 g_return_if_fail (GTK_IS_ENTRY (entry));
7630 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7632 priv = GTK_ENTRY_GET_PRIVATE (entry);
7634 if ((icon_info = priv->icons[icon_pos]) == NULL)
7635 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7637 g_object_freeze_notify (G_OBJECT (entry));
7639 gtk_widget_ensure_style (GTK_WIDGET (entry));
7641 /* need to dup before clearing */
7642 new_name = g_strdup (icon_name);
7644 gtk_entry_clear (entry, icon_pos);
7646 if (new_name != NULL)
7648 icon_info->storage_type = GTK_IMAGE_ICON_NAME;
7649 icon_info->icon_name = new_name;
7651 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7653 g_object_notify (G_OBJECT (entry), "primary-icon-name");
7654 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7658 g_object_notify (G_OBJECT (entry), "secondary-icon-name");
7659 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7662 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7663 gdk_window_show_unraised (icon_info->window);
7666 gtk_entry_ensure_pixbuf (entry, icon_pos);
7668 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7669 gtk_widget_queue_resize (GTK_WIDGET (entry));
7671 g_object_thaw_notify (G_OBJECT (entry));
7675 * gtk_entry_set_icon_from_gicon:
7676 * @entry: A #GtkEntry
7677 * @icon_pos: The position at which to set the icon
7678 * @icon: (allow-none): The icon to set, or %NULL
7680 * Sets the icon shown in the entry at the specified position
7681 * from the current icon theme.
7682 * If the icon isn't known, a "broken image" icon will be displayed
7685 * If @icon is %NULL, no icon will be shown in the specified position.
7690 gtk_entry_set_icon_from_gicon (GtkEntry *entry,
7691 GtkEntryIconPosition icon_pos,
7694 GtkEntryPrivate *priv;
7695 EntryIconInfo *icon_info;
7697 g_return_if_fail (GTK_IS_ENTRY (entry));
7698 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7700 priv = GTK_ENTRY_GET_PRIVATE (entry);
7702 if ((icon_info = priv->icons[icon_pos]) == NULL)
7703 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7705 g_object_freeze_notify (G_OBJECT (entry));
7707 /* need to ref before clearing */
7709 g_object_ref (icon);
7711 gtk_entry_clear (entry, icon_pos);
7715 icon_info->storage_type = GTK_IMAGE_GICON;
7716 icon_info->gicon = icon;
7718 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7720 g_object_notify (G_OBJECT (entry), "primary-icon-gicon");
7721 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7725 g_object_notify (G_OBJECT (entry), "secondary-icon-gicon");
7726 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7729 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7730 gdk_window_show_unraised (icon_info->window);
7733 gtk_entry_ensure_pixbuf (entry, icon_pos);
7735 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7736 gtk_widget_queue_resize (GTK_WIDGET (entry));
7738 g_object_thaw_notify (G_OBJECT (entry));
7742 * gtk_entry_set_icon_activatable:
7743 * @entry: A #GtkEntry
7744 * @icon_pos: Icon position
7745 * @activatable: %TRUE if the icon should be activatable
7747 * Sets whether the icon is activatable.
7752 gtk_entry_set_icon_activatable (GtkEntry *entry,
7753 GtkEntryIconPosition icon_pos,
7754 gboolean activatable)
7756 GtkEntryPrivate *priv;
7757 EntryIconInfo *icon_info;
7759 g_return_if_fail (GTK_IS_ENTRY (entry));
7760 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7762 priv = GTK_ENTRY_GET_PRIVATE (entry);
7764 if ((icon_info = priv->icons[icon_pos]) == NULL)
7765 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7767 activatable = activatable != FALSE;
7769 if (icon_info->nonactivatable != !activatable)
7771 icon_info->nonactivatable = !activatable;
7773 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
7774 update_cursors (GTK_WIDGET (entry));
7776 g_object_notify (G_OBJECT (entry),
7777 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-activatable" : "secondary-icon-activatable");
7782 * gtk_entry_get_icon_activatable:
7783 * @entry: a #GtkEntry
7784 * @icon_pos: Icon position
7786 * Returns whether the icon is activatable.
7788 * Returns: %TRUE if the icon is activatable.
7793 gtk_entry_get_icon_activatable (GtkEntry *entry,
7794 GtkEntryIconPosition icon_pos)
7796 GtkEntryPrivate *priv;
7797 EntryIconInfo *icon_info;
7799 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7800 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), FALSE);
7802 priv = GTK_ENTRY_GET_PRIVATE (entry);
7803 icon_info = priv->icons[icon_pos];
7805 return (icon_info != NULL && !icon_info->nonactivatable);
7809 * gtk_entry_get_icon_pixbuf:
7810 * @entry: A #GtkEntry
7811 * @icon_pos: Icon position
7813 * Retrieves the image used for the icon.
7815 * Unlike the other methods of setting and getting icon data, this
7816 * method will work regardless of whether the icon was set using a
7817 * #GdkPixbuf, a #GIcon, a stock item, or an icon name.
7819 * Returns: A #GdkPixbuf, or %NULL if no icon is set for this position.
7824 gtk_entry_get_icon_pixbuf (GtkEntry *entry,
7825 GtkEntryIconPosition icon_pos)
7827 GtkEntryPrivate *priv;
7828 EntryIconInfo *icon_info;
7830 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7831 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7833 priv = GTK_ENTRY_GET_PRIVATE (entry);
7834 icon_info = priv->icons[icon_pos];
7839 gtk_entry_ensure_pixbuf (entry, icon_pos);
7841 return icon_info->pixbuf;
7845 * gtk_entry_get_icon_gicon:
7846 * @entry: A #GtkEntry
7847 * @icon_pos: Icon position
7849 * Retrieves the #GIcon used for the icon, or %NULL if there is
7850 * no icon or if the icon was set by some other method (e.g., by
7851 * stock, pixbuf, or icon name).
7853 * Returns: A #GIcon, or %NULL if no icon is set or if the icon
7859 gtk_entry_get_icon_gicon (GtkEntry *entry,
7860 GtkEntryIconPosition icon_pos)
7862 GtkEntryPrivate *priv;
7863 EntryIconInfo *icon_info;
7865 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7866 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7868 priv = GTK_ENTRY_GET_PRIVATE (entry);
7869 icon_info = priv->icons[icon_pos];
7874 return icon_info->storage_type == GTK_IMAGE_GICON ? icon_info->gicon : NULL;
7878 * gtk_entry_get_icon_stock:
7879 * @entry: A #GtkEntry
7880 * @icon_pos: Icon position
7882 * Retrieves the stock id used for the icon, or %NULL if there is
7883 * no icon or if the icon was set by some other method (e.g., by
7884 * pixbuf, icon name or gicon).
7886 * Returns: A stock id, or %NULL if no icon is set or if the icon
7887 * wasn't set from a stock id
7892 gtk_entry_get_icon_stock (GtkEntry *entry,
7893 GtkEntryIconPosition icon_pos)
7895 GtkEntryPrivate *priv;
7896 EntryIconInfo *icon_info;
7898 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7899 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7901 priv = GTK_ENTRY_GET_PRIVATE (entry);
7902 icon_info = priv->icons[icon_pos];
7907 return icon_info->storage_type == GTK_IMAGE_STOCK ? icon_info->stock_id : NULL;
7911 * gtk_entry_get_icon_name:
7912 * @entry: A #GtkEntry
7913 * @icon_pos: Icon position
7915 * Retrieves the icon name used for the icon, or %NULL if there is
7916 * no icon or if the icon was set by some other method (e.g., by
7917 * pixbuf, stock or gicon).
7919 * Returns: An icon name, or %NULL if no icon is set or if the icon
7920 * wasn't set from an icon name
7925 gtk_entry_get_icon_name (GtkEntry *entry,
7926 GtkEntryIconPosition icon_pos)
7928 GtkEntryPrivate *priv;
7929 EntryIconInfo *icon_info;
7931 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7932 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7934 priv = GTK_ENTRY_GET_PRIVATE (entry);
7935 icon_info = priv->icons[icon_pos];
7940 return icon_info->storage_type == GTK_IMAGE_ICON_NAME ? icon_info->icon_name : NULL;
7944 * gtk_entry_set_icon_sensitive:
7945 * @entry: A #GtkEntry
7946 * @icon_pos: Icon position
7947 * @sensitive: Specifies whether the icon should appear
7948 * sensitive or insensitive
7950 * Sets the sensitivity for the specified icon.
7955 gtk_entry_set_icon_sensitive (GtkEntry *entry,
7956 GtkEntryIconPosition icon_pos,
7959 GtkEntryPrivate *priv;
7960 EntryIconInfo *icon_info;
7962 g_return_if_fail (GTK_IS_ENTRY (entry));
7963 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7965 priv = GTK_ENTRY_GET_PRIVATE (entry);
7967 if ((icon_info = priv->icons[icon_pos]) == NULL)
7968 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7970 if (icon_info->insensitive != !sensitive)
7972 icon_info->insensitive = !sensitive;
7974 icon_info->pressed = FALSE;
7975 icon_info->prelight = FALSE;
7977 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
7978 update_cursors (GTK_WIDGET (entry));
7980 gtk_widget_queue_draw (GTK_WIDGET (entry));
7982 g_object_notify (G_OBJECT (entry),
7983 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-sensitive" : "secondary-icon-sensitive");
7988 * gtk_entry_get_icon_sensitive:
7989 * @entry: a #GtkEntry
7990 * @icon_pos: Icon position
7992 * Returns whether the icon appears sensitive or insensitive.
7994 * Returns: %TRUE if the icon is sensitive.
7999 gtk_entry_get_icon_sensitive (GtkEntry *entry,
8000 GtkEntryIconPosition icon_pos)
8002 GtkEntryPrivate *priv;
8003 EntryIconInfo *icon_info;
8005 g_return_val_if_fail (GTK_IS_ENTRY (entry), TRUE);
8006 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), TRUE);
8008 priv = GTK_ENTRY_GET_PRIVATE (entry);
8009 icon_info = priv->icons[icon_pos];
8011 return (!icon_info || !icon_info->insensitive);
8016 * gtk_entry_get_icon_storage_type:
8017 * @entry: a #GtkEntry
8018 * @icon_pos: Icon position
8020 * Gets the type of representation being used by the icon
8021 * to store image data. If the icon has no image data,
8022 * the return value will be %GTK_IMAGE_EMPTY.
8024 * Return value: image representation being used
8029 gtk_entry_get_icon_storage_type (GtkEntry *entry,
8030 GtkEntryIconPosition icon_pos)
8032 GtkEntryPrivate *priv;
8033 EntryIconInfo *icon_info;
8035 g_return_val_if_fail (GTK_IS_ENTRY (entry), GTK_IMAGE_EMPTY);
8036 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), GTK_IMAGE_EMPTY);
8038 priv = GTK_ENTRY_GET_PRIVATE (entry);
8039 icon_info = priv->icons[icon_pos];
8042 return GTK_IMAGE_EMPTY;
8044 return icon_info->storage_type;
8048 * gtk_entry_get_icon_at_pos:
8049 * @entry: a #GtkEntry
8050 * @x: the x coordinate of the position to find
8051 * @y: the y coordinate of the position to find
8053 * Finds the icon at the given position and return its index.
8054 * If @x, @y doesn't lie inside an icon, -1 is returned.
8055 * This function is intended for use in a #GtkWidget::query-tooltip
8058 * Returns: the index of the icon at the given position, or -1
8063 gtk_entry_get_icon_at_pos (GtkEntry *entry,
8067 GtkAllocation primary;
8068 GtkAllocation secondary;
8070 g_return_val_if_fail (GTK_IS_ENTRY (entry), -1);
8072 get_icon_allocations (entry, &primary, &secondary);
8074 if (primary.x <= x && x < primary.x + primary.width &&
8075 primary.y <= y && y < primary.y + primary.height)
8076 return GTK_ENTRY_ICON_PRIMARY;
8078 if (secondary.x <= x && x < secondary.x + secondary.width &&
8079 secondary.y <= y && y < secondary.y + secondary.height)
8080 return GTK_ENTRY_ICON_SECONDARY;
8086 * gtk_entry_set_icon_drag_source:
8087 * @entry: a #GtkIconEntry
8088 * @icon_pos: icon position
8089 * @target_list: the targets (data formats) in which the data can be provided
8090 * @actions: a bitmask of the allowed drag actions
8092 * Sets up the icon at the given position so that GTK+ will start a drag
8093 * operation when the user clicks and drags the icon.
8095 * To handle the drag operation, you need to connect to the usual
8096 * #GtkWidget::drag-data-get (or possibly #GtkWidget::drag-data-delete)
8097 * signal, and use gtk_entry_get_current_icon_drag_source() in
8098 * your signal handler to find out if the drag was started from
8101 * By default, GTK+ uses the icon as the drag icon. You can use the
8102 * #GtkWidget::drag-begin signal to set a different icon. Note that you
8103 * have to use g_signal_connect_after() to ensure that your signal handler
8104 * gets executed after the default handler.
8109 gtk_entry_set_icon_drag_source (GtkEntry *entry,
8110 GtkEntryIconPosition icon_pos,
8111 GtkTargetList *target_list,
8112 GdkDragAction actions)
8114 GtkEntryPrivate *priv;
8115 EntryIconInfo *icon_info;
8117 g_return_if_fail (GTK_IS_ENTRY (entry));
8118 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8120 priv = GTK_ENTRY_GET_PRIVATE (entry);
8122 if ((icon_info = priv->icons[icon_pos]) == NULL)
8123 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8125 if (icon_info->target_list)
8126 gtk_target_list_unref (icon_info->target_list);
8127 icon_info->target_list = target_list;
8128 if (icon_info->target_list)
8129 gtk_target_list_ref (icon_info->target_list);
8131 icon_info->actions = actions;
8135 * gtk_entry_get_current_icon_drag_source:
8136 * @entry: a #GtkIconEntry
8138 * Returns the index of the icon which is the source of the current
8139 * DND operation, or -1.
8141 * This function is meant to be used in a #GtkWidget::drag-data-get
8144 * Returns: index of the icon which is the source of the current
8145 * DND operation, or -1.
8150 gtk_entry_get_current_icon_drag_source (GtkEntry *entry)
8152 GtkEntryPrivate *priv;
8153 EntryIconInfo *icon_info = NULL;
8156 g_return_val_if_fail (GTK_IS_ENTRY (entry), -1);
8158 priv = GTK_ENTRY_GET_PRIVATE (entry);
8160 for (i = 0; i < MAX_ICONS; i++)
8162 if ((icon_info = priv->icons[i]))
8164 if (icon_info->in_drag)
8173 * gtk_entry_get_icon_window:
8174 * @entry: A #GtkEntry
8175 * @icon_pos: Icon position
8177 * Returns the #GdkWindow which contains the entry's icon at
8178 * @icon_pos. This function is useful when drawing something to the
8179 * entry in an expose-event callback because it enables the callback
8180 * to distinguish between the text window and entry's icon windows.
8182 * See also gtk_entry_get_text_window().
8184 * Return value: the entry's icon window at @icon_pos.
8189 gtk_entry_get_icon_window (GtkEntry *entry,
8190 GtkEntryIconPosition icon_pos)
8192 GtkEntryPrivate *priv;
8193 EntryIconInfo *icon_info;
8195 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8197 priv = GTK_ENTRY_GET_PRIVATE (entry);
8199 icon_info = priv->icons[icon_pos];
8202 return icon_info->window;
8208 ensure_has_tooltip (GtkEntry *entry)
8210 GtkEntryPrivate *priv;
8211 EntryIconInfo *icon_info;
8213 gboolean has_tooltip = FALSE;
8215 priv = GTK_ENTRY_GET_PRIVATE (entry);
8217 for (i = 0; i < MAX_ICONS; i++)
8219 if ((icon_info = priv->icons[i]) != NULL)
8221 if (icon_info->tooltip != NULL)
8229 gtk_widget_set_has_tooltip (GTK_WIDGET (entry), has_tooltip);
8233 * gtk_entry_get_icon_tooltip_text:
8234 * @entry: a #GtkEntry
8235 * @icon_pos: the icon position
8237 * Gets the contents of the tooltip on the icon at the specified
8238 * position in @entry.
8240 * Returns: the tooltip text, or %NULL. Free the returned string
8241 * with g_free() when done.
8246 gtk_entry_get_icon_tooltip_text (GtkEntry *entry,
8247 GtkEntryIconPosition icon_pos)
8249 GtkEntryPrivate *priv;
8250 EntryIconInfo *icon_info;
8253 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8254 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8256 priv = GTK_ENTRY_GET_PRIVATE (entry);
8257 icon_info = priv->icons[icon_pos];
8262 if (icon_info->tooltip &&
8263 !pango_parse_markup (icon_info->tooltip, -1, 0, NULL, &text, NULL, NULL))
8264 g_assert (NULL == text); /* text should still be NULL in case of markup errors */
8270 * gtk_entry_set_icon_tooltip_text:
8271 * @entry: a #GtkEntry
8272 * @icon_pos: the icon position
8273 * @tooltip: (allow-none): the contents of the tooltip for the icon, or %NULL
8275 * Sets @tooltip as the contents of the tooltip for the icon
8276 * at the specified position.
8278 * Use %NULL for @tooltip to remove an existing tooltip.
8280 * See also gtk_widget_set_tooltip_text() and
8281 * gtk_entry_set_icon_tooltip_markup().
8286 gtk_entry_set_icon_tooltip_text (GtkEntry *entry,
8287 GtkEntryIconPosition icon_pos,
8288 const gchar *tooltip)
8290 GtkEntryPrivate *priv;
8291 EntryIconInfo *icon_info;
8293 g_return_if_fail (GTK_IS_ENTRY (entry));
8294 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8296 priv = GTK_ENTRY_GET_PRIVATE (entry);
8298 if (!(icon_info = priv->icons[icon_pos]))
8299 icon_info = priv->icons[icon_pos];
8301 if (icon_info->tooltip)
8302 g_free (icon_info->tooltip);
8304 /* Treat an empty string as a NULL string,
8305 * because an empty string would be useless for a tooltip:
8307 if (tooltip && tooltip[0] == '\0')
8310 icon_info->tooltip = tooltip ? g_markup_escape_text (tooltip, -1) : NULL;
8312 ensure_has_tooltip (entry);
8316 * gtk_entry_get_icon_tooltip_markup:
8317 * @entry: a #GtkEntry
8318 * @icon_pos: the icon position
8320 * Gets the contents of the tooltip on the icon at the specified
8321 * position in @entry.
8323 * Returns: the tooltip text, or %NULL. Free the returned string
8324 * with g_free() when done.
8329 gtk_entry_get_icon_tooltip_markup (GtkEntry *entry,
8330 GtkEntryIconPosition icon_pos)
8332 GtkEntryPrivate *priv;
8333 EntryIconInfo *icon_info;
8335 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8336 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8338 priv = GTK_ENTRY_GET_PRIVATE (entry);
8339 icon_info = priv->icons[icon_pos];
8344 return g_strdup (icon_info->tooltip);
8348 * gtk_entry_set_icon_tooltip_markup:
8349 * @entry: a #GtkEntry
8350 * @icon_pos: the icon position
8351 * @tooltip: (allow-none): the contents of the tooltip for the icon, or %NULL
8353 * Sets @tooltip as the contents of the tooltip for the icon at
8354 * the specified position. @tooltip is assumed to be marked up with
8355 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
8357 * Use %NULL for @tooltip to remove an existing tooltip.
8359 * See also gtk_widget_set_tooltip_markup() and
8360 * gtk_enty_set_icon_tooltip_text().
8365 gtk_entry_set_icon_tooltip_markup (GtkEntry *entry,
8366 GtkEntryIconPosition icon_pos,
8367 const gchar *tooltip)
8369 GtkEntryPrivate *priv;
8370 EntryIconInfo *icon_info;
8372 g_return_if_fail (GTK_IS_ENTRY (entry));
8373 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8375 priv = GTK_ENTRY_GET_PRIVATE (entry);
8377 if (!(icon_info = priv->icons[icon_pos]))
8378 icon_info = priv->icons[icon_pos];
8380 if (icon_info->tooltip)
8381 g_free (icon_info->tooltip);
8383 /* Treat an empty string as a NULL string,
8384 * because an empty string would be useless for a tooltip:
8386 if (tooltip && tooltip[0] == '\0')
8389 icon_info->tooltip = g_strdup (tooltip);
8391 ensure_has_tooltip (entry);
8395 gtk_entry_query_tooltip (GtkWidget *widget,
8398 gboolean keyboard_tip,
8399 GtkTooltip *tooltip)
8402 GtkEntryPrivate *priv;
8403 EntryIconInfo *icon_info;
8406 entry = GTK_ENTRY (widget);
8407 priv = GTK_ENTRY_GET_PRIVATE (entry);
8411 icon_pos = gtk_entry_get_icon_at_pos (entry, x, y);
8414 if ((icon_info = priv->icons[icon_pos]) != NULL)
8416 if (icon_info->tooltip)
8418 gtk_tooltip_set_markup (tooltip, icon_info->tooltip);
8427 return GTK_WIDGET_CLASS (gtk_entry_parent_class)->query_tooltip (widget,
8434 /* Quick hack of a popup menu
8437 activate_cb (GtkWidget *menuitem,
8440 const gchar *signal = g_object_get_data (G_OBJECT (menuitem), "gtk-signal");
8441 g_signal_emit_by_name (entry, signal);
8446 gtk_entry_mnemonic_activate (GtkWidget *widget,
8447 gboolean group_cycling)
8449 gtk_widget_grab_focus (widget);
8454 append_action_signal (GtkEntry *entry,
8456 const gchar *stock_id,
8457 const gchar *signal,
8460 GtkWidget *menuitem = gtk_image_menu_item_new_from_stock (stock_id, NULL);
8462 g_object_set_data (G_OBJECT (menuitem), I_("gtk-signal"), (char *)signal);
8463 g_signal_connect (menuitem, "activate",
8464 G_CALLBACK (activate_cb), entry);
8466 gtk_widget_set_sensitive (menuitem, sensitive);
8468 gtk_widget_show (menuitem);
8469 gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
8473 popup_menu_detach (GtkWidget *attach_widget,
8476 GTK_ENTRY (attach_widget)->popup_menu = NULL;
8480 popup_position_func (GtkMenu *menu,
8486 GtkEntry *entry = GTK_ENTRY (user_data);
8487 GtkWidget *widget = GTK_WIDGET (entry);
8489 GtkRequisition menu_req;
8490 GdkRectangle monitor;
8491 GtkBorder inner_border;
8492 gint monitor_num, strong_x, height;
8494 g_return_if_fail (gtk_widget_get_realized (widget));
8496 gdk_window_get_origin (entry->text_area, x, y);
8498 screen = gtk_widget_get_screen (widget);
8499 monitor_num = gdk_screen_get_monitor_at_window (screen, entry->text_area);
8500 if (monitor_num < 0)
8502 gtk_menu_set_monitor (menu, monitor_num);
8504 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
8505 gtk_widget_size_request (entry->popup_menu, &menu_req);
8506 gdk_drawable_get_size (entry->text_area, NULL, &height);
8507 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
8508 _gtk_entry_effective_inner_border (entry, &inner_border);
8510 *x += inner_border.left + strong_x - entry->scroll_offset;
8511 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
8512 *x -= menu_req.width;
8514 if ((*y + height + menu_req.height) <= monitor.y + monitor.height)
8516 else if ((*y - menu_req.height) >= monitor.y)
8517 *y -= menu_req.height;
8518 else if (monitor.y + monitor.height - (*y + height) > *y)
8521 *y -= menu_req.height;
8527 unichar_chosen_func (const char *text,
8530 GtkEntry *entry = GTK_ENTRY (data);
8532 if (entry->editable)
8533 gtk_entry_enter_text (entry, text);
8544 popup_targets_received (GtkClipboard *clipboard,
8545 GtkSelectionData *data,
8548 PopupInfo *info = user_data;
8549 GtkEntry *entry = info->entry;
8551 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
8554 gboolean clipboard_contains_text;
8555 GtkWidget *menuitem;
8557 gboolean show_input_method_menu;
8558 gboolean show_unicode_menu;
8560 clipboard_contains_text = gtk_selection_data_targets_include_text (data);
8561 if (entry->popup_menu)
8562 gtk_widget_destroy (entry->popup_menu);
8564 entry->popup_menu = gtk_menu_new ();
8566 gtk_menu_attach_to_widget (GTK_MENU (entry->popup_menu),
8570 mode = gtk_entry_get_display_mode (entry);
8571 append_action_signal (entry, entry->popup_menu, GTK_STOCK_CUT, "cut-clipboard",
8572 entry->editable && mode == DISPLAY_NORMAL &&
8573 entry->current_pos != entry->selection_bound);
8575 append_action_signal (entry, entry->popup_menu, GTK_STOCK_COPY, "copy-clipboard",
8576 mode == DISPLAY_NORMAL &&
8577 entry->current_pos != entry->selection_bound);
8579 append_action_signal (entry, entry->popup_menu, GTK_STOCK_PASTE, "paste-clipboard",
8580 entry->editable && clipboard_contains_text);
8582 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_DELETE, NULL);
8583 gtk_widget_set_sensitive (menuitem, entry->editable && entry->current_pos != entry->selection_bound);
8584 g_signal_connect_swapped (menuitem, "activate",
8585 G_CALLBACK (gtk_entry_delete_cb), entry);
8586 gtk_widget_show (menuitem);
8587 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8589 menuitem = gtk_separator_menu_item_new ();
8590 gtk_widget_show (menuitem);
8591 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8593 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_SELECT_ALL, NULL);
8594 g_signal_connect_swapped (menuitem, "activate",
8595 G_CALLBACK (gtk_entry_select_all), entry);
8596 gtk_widget_show (menuitem);
8597 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8599 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
8600 "gtk-show-input-method-menu", &show_input_method_menu,
8601 "gtk-show-unicode-menu", &show_unicode_menu,
8604 if (show_input_method_menu || show_unicode_menu)
8606 menuitem = gtk_separator_menu_item_new ();
8607 gtk_widget_show (menuitem);
8608 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8611 if (show_input_method_menu)
8613 menuitem = gtk_menu_item_new_with_mnemonic (_("Input _Methods"));
8614 gtk_widget_set_sensitive (menuitem, entry->editable);
8615 gtk_widget_show (menuitem);
8616 submenu = gtk_menu_new ();
8617 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
8619 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8621 gtk_im_multicontext_append_menuitems (GTK_IM_MULTICONTEXT (entry->im_context),
8622 GTK_MENU_SHELL (submenu));
8625 if (show_unicode_menu)
8627 menuitem = gtk_menu_item_new_with_mnemonic (_("_Insert Unicode Control Character"));
8628 gtk_widget_set_sensitive (menuitem, entry->editable);
8629 gtk_widget_show (menuitem);
8631 submenu = gtk_menu_new ();
8632 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
8633 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8635 _gtk_text_util_append_special_char_menuitems (GTK_MENU_SHELL (submenu),
8636 unichar_chosen_func,
8640 g_signal_emit (entry,
8641 signals[POPULATE_POPUP],
8647 gtk_menu_popup (GTK_MENU (entry->popup_menu), NULL, NULL,
8649 info->button, info->time);
8652 gtk_menu_popup (GTK_MENU (entry->popup_menu), NULL, NULL,
8653 popup_position_func, entry,
8654 info->button, info->time);
8655 gtk_menu_shell_select_first (GTK_MENU_SHELL (entry->popup_menu), FALSE);
8659 g_object_unref (entry);
8660 g_slice_free (PopupInfo, info);
8664 gtk_entry_do_popup (GtkEntry *entry,
8665 GdkEventButton *event)
8667 PopupInfo *info = g_slice_new (PopupInfo);
8669 /* In order to know what entries we should make sensitive, we
8670 * ask for the current targets of the clipboard, and when
8671 * we get them, then we actually pop up the menu.
8673 info->entry = g_object_ref (entry);
8677 info->button = event->button;
8678 info->time = event->time;
8683 info->time = gtk_get_current_event_time ();
8686 gtk_clipboard_request_contents (gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_CLIPBOARD),
8687 gdk_atom_intern_static_string ("TARGETS"),
8688 popup_targets_received,
8693 gtk_entry_popup_menu (GtkWidget *widget)
8695 gtk_entry_do_popup (GTK_ENTRY (widget), NULL);
8700 gtk_entry_drag_begin (GtkWidget *widget,
8701 GdkDragContext *context)
8703 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
8706 for (i = 0; i < MAX_ICONS; i++)
8708 EntryIconInfo *icon_info = priv->icons[i];
8710 if (icon_info != NULL)
8712 if (icon_info->in_drag)
8714 switch (icon_info->storage_type)
8716 case GTK_IMAGE_STOCK:
8717 gtk_drag_set_icon_stock (context, icon_info->stock_id, -2, -2);
8720 case GTK_IMAGE_ICON_NAME:
8721 gtk_drag_set_icon_name (context, icon_info->icon_name, -2, -2);
8724 /* FIXME: No GIcon support for dnd icons */
8725 case GTK_IMAGE_GICON:
8726 case GTK_IMAGE_PIXBUF:
8727 gtk_drag_set_icon_pixbuf (context, icon_info->pixbuf, -2, -2);
8730 g_assert_not_reached ();
8738 gtk_entry_drag_end (GtkWidget *widget,
8739 GdkDragContext *context)
8741 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
8744 for (i = 0; i < MAX_ICONS; i++)
8746 EntryIconInfo *icon_info = priv->icons[i];
8748 if (icon_info != NULL)
8749 icon_info->in_drag = 0;
8754 gtk_entry_drag_leave (GtkWidget *widget,
8755 GdkDragContext *context,
8758 GtkEntry *entry = GTK_ENTRY (widget);
8760 entry->dnd_position = -1;
8761 gtk_widget_queue_draw (widget);
8765 gtk_entry_drag_drop (GtkWidget *widget,
8766 GdkDragContext *context,
8771 GtkEntry *entry = GTK_ENTRY (widget);
8772 GdkAtom target = GDK_NONE;
8774 if (entry->editable)
8775 target = gtk_drag_dest_find_target (widget, context, NULL);
8777 if (target != GDK_NONE)
8778 gtk_drag_get_data (widget, context, target, time);
8780 gtk_drag_finish (context, FALSE, FALSE, time);
8786 gtk_entry_drag_motion (GtkWidget *widget,
8787 GdkDragContext *context,
8792 GtkEntry *entry = GTK_ENTRY (widget);
8793 GtkWidget *source_widget;
8794 GdkDragAction suggested_action;
8795 gint new_position, old_position;
8798 x -= widget->style->xthickness;
8799 y -= widget->style->ythickness;
8801 old_position = entry->dnd_position;
8802 new_position = gtk_entry_find_position (entry, x + entry->scroll_offset);
8804 if (entry->editable &&
8805 gtk_drag_dest_find_target (widget, context, NULL) != GDK_NONE)
8807 source_widget = gtk_drag_get_source_widget (context);
8808 suggested_action = context->suggested_action;
8810 if (!gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &sel1, &sel2) ||
8811 new_position < sel1 || new_position > sel2)
8813 if (source_widget == widget)
8815 /* Default to MOVE, unless the user has
8816 * pressed ctrl or alt to affect available actions
8818 if ((context->actions & GDK_ACTION_MOVE) != 0)
8819 suggested_action = GDK_ACTION_MOVE;
8822 entry->dnd_position = new_position;
8826 if (source_widget == widget)
8827 suggested_action = 0; /* Can't drop in selection where drag started */
8829 entry->dnd_position = -1;
8834 /* Entry not editable, or no text */
8835 suggested_action = 0;
8836 entry->dnd_position = -1;
8839 gdk_drag_status (context, suggested_action, time);
8841 if (entry->dnd_position != old_position)
8842 gtk_widget_queue_draw (widget);
8848 gtk_entry_drag_data_received (GtkWidget *widget,
8849 GdkDragContext *context,
8852 GtkSelectionData *selection_data,
8856 GtkEntry *entry = GTK_ENTRY (widget);
8857 GtkEditable *editable = GTK_EDITABLE (widget);
8860 str = (gchar *) gtk_selection_data_get_text (selection_data);
8862 x -= widget->style->xthickness;
8863 y -= widget->style->ythickness;
8865 if (str && entry->editable)
8871 if (entry->truncate_multiline)
8872 length = truncate_multiline (str);
8874 new_position = gtk_entry_find_position (entry, x + entry->scroll_offset);
8876 if (!gtk_editable_get_selection_bounds (editable, &sel1, &sel2) ||
8877 new_position < sel1 || new_position > sel2)
8879 gtk_editable_insert_text (editable, str, length, &new_position);
8883 /* Replacing selection */
8884 begin_change (entry);
8885 g_object_freeze_notify (G_OBJECT (entry));
8886 gtk_editable_delete_text (editable, sel1, sel2);
8887 gtk_editable_insert_text (editable, str, length, &sel1);
8888 g_object_thaw_notify (G_OBJECT (entry));
8892 gtk_drag_finish (context, TRUE, context->action == GDK_ACTION_MOVE, time);
8896 /* Drag and drop didn't happen! */
8897 gtk_drag_finish (context, FALSE, FALSE, time);
8904 gtk_entry_drag_data_get (GtkWidget *widget,
8905 GdkDragContext *context,
8906 GtkSelectionData *selection_data,
8910 gint sel_start, sel_end;
8913 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
8914 GtkEditable *editable = GTK_EDITABLE (widget);
8916 /* If there is an icon drag going on, exit early. */
8917 for (i = 0; i < MAX_ICONS; i++)
8919 EntryIconInfo *icon_info = priv->icons[i];
8921 if (icon_info != NULL)
8923 if (icon_info->in_drag)
8928 if (gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end))
8930 gchar *str = gtk_entry_get_display_text (GTK_ENTRY (widget), sel_start, sel_end);
8932 gtk_selection_data_set_text (selection_data, str, -1);
8940 gtk_entry_drag_data_delete (GtkWidget *widget,
8941 GdkDragContext *context)
8943 gint sel_start, sel_end;
8946 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
8947 GtkEditable *editable = GTK_EDITABLE (widget);
8949 /* If there is an icon drag going on, exit early. */
8950 for (i = 0; i < MAX_ICONS; i++)
8952 EntryIconInfo *icon_info = priv->icons[i];
8954 if (icon_info != NULL)
8956 if (icon_info->in_drag)
8961 if (GTK_ENTRY (widget)->editable &&
8962 gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end))
8963 gtk_editable_delete_text (editable, sel_start, sel_end);
8966 /* We display the cursor when
8968 * - the selection is empty, AND
8969 * - the widget has focus
8972 #define CURSOR_ON_MULTIPLIER 2
8973 #define CURSOR_OFF_MULTIPLIER 1
8974 #define CURSOR_PEND_MULTIPLIER 3
8975 #define CURSOR_DIVIDER 3
8978 cursor_blinks (GtkEntry *entry)
8980 if (gtk_widget_has_focus (GTK_WIDGET (entry)) &&
8982 entry->selection_bound == entry->current_pos)
8984 GtkSettings *settings;
8987 settings = gtk_widget_get_settings (GTK_WIDGET (entry));
8988 g_object_get (settings, "gtk-cursor-blink", &blink, NULL);
8997 get_cursor_time (GtkEntry *entry)
8999 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9002 g_object_get (settings, "gtk-cursor-blink-time", &time, NULL);
9008 get_cursor_blink_timeout (GtkEntry *entry)
9010 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9013 g_object_get (settings, "gtk-cursor-blink-timeout", &timeout, NULL);
9019 show_cursor (GtkEntry *entry)
9023 if (!entry->cursor_visible)
9025 entry->cursor_visible = TRUE;
9027 widget = GTK_WIDGET (entry);
9028 if (gtk_widget_has_focus (widget) && entry->selection_bound == entry->current_pos)
9029 gtk_widget_queue_draw (widget);
9034 hide_cursor (GtkEntry *entry)
9038 if (entry->cursor_visible)
9040 entry->cursor_visible = FALSE;
9042 widget = GTK_WIDGET (entry);
9043 if (gtk_widget_has_focus (widget) && entry->selection_bound == entry->current_pos)
9044 gtk_widget_queue_draw (widget);
9052 blink_cb (gpointer data)
9055 GtkEntryPrivate *priv;
9058 entry = GTK_ENTRY (data);
9059 priv = GTK_ENTRY_GET_PRIVATE (entry);
9061 if (!gtk_widget_has_focus (GTK_WIDGET (entry)))
9063 g_warning ("GtkEntry - did not receive focus-out-event. If you\n"
9064 "connect a handler to this signal, it must return\n"
9065 "FALSE so the entry gets the event as well");
9067 gtk_entry_check_cursor_blink (entry);
9072 g_assert (entry->selection_bound == entry->current_pos);
9074 blink_timeout = get_cursor_blink_timeout (entry);
9075 if (priv->blink_time > 1000 * blink_timeout &&
9076 blink_timeout < G_MAXINT/1000)
9078 /* we've blinked enough without the user doing anything, stop blinking */
9079 show_cursor (entry);
9080 entry->blink_timeout = 0;
9082 else if (entry->cursor_visible)
9084 hide_cursor (entry);
9085 entry->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_OFF_MULTIPLIER / CURSOR_DIVIDER,
9091 show_cursor (entry);
9092 priv->blink_time += get_cursor_time (entry);
9093 entry->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
9098 /* Remove ourselves */
9103 gtk_entry_check_cursor_blink (GtkEntry *entry)
9105 GtkEntryPrivate *priv;
9107 priv = GTK_ENTRY_GET_PRIVATE (entry);
9109 if (cursor_blinks (entry))
9111 if (!entry->blink_timeout)
9113 show_cursor (entry);
9114 entry->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
9121 if (entry->blink_timeout)
9123 g_source_remove (entry->blink_timeout);
9124 entry->blink_timeout = 0;
9127 entry->cursor_visible = TRUE;
9133 gtk_entry_pend_cursor_blink (GtkEntry *entry)
9135 if (cursor_blinks (entry))
9137 if (entry->blink_timeout != 0)
9138 g_source_remove (entry->blink_timeout);
9140 entry->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_PEND_MULTIPLIER / CURSOR_DIVIDER,
9143 show_cursor (entry);
9148 gtk_entry_reset_blink_time (GtkEntry *entry)
9150 GtkEntryPrivate *priv;
9152 priv = GTK_ENTRY_GET_PRIVATE (entry);
9154 priv->blink_time = 0;
9160 gtk_entry_completion_timeout (gpointer data)
9162 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (data);
9163 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (completion->priv->entry);
9165 completion->priv->completion_timeout = 0;
9167 if (completion->priv->filter_model &&
9168 g_utf8_strlen (gtk_entry_get_text (GTK_ENTRY (completion->priv->entry)), -1)
9169 >= completion->priv->minimum_key_length)
9173 GtkTreeSelection *s;
9174 gboolean popup_single;
9176 gtk_entry_completion_complete (completion);
9177 matches = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->filter_model), NULL);
9179 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9181 s = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view));
9183 gtk_tree_selection_unselect_all (s);
9185 actions = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->actions), NULL);
9187 g_object_get (completion, "popup-single-match", &popup_single, NULL);
9188 if ((matches > (popup_single ? 0: 1)) || actions > 0)
9190 if (gtk_widget_get_visible (completion->priv->popup_window))
9191 _gtk_entry_completion_resize_popup (completion);
9193 _gtk_entry_completion_popup (completion, priv->completion_device);
9196 _gtk_entry_completion_popdown (completion);
9198 else if (gtk_widget_get_visible (completion->priv->popup_window))
9199 _gtk_entry_completion_popdown (completion);
9204 static inline gboolean
9205 keyval_is_cursor_move (guint keyval)
9207 if (keyval == GDK_Up || keyval == GDK_KP_Up)
9210 if (keyval == GDK_Down || keyval == GDK_KP_Down)
9213 if (keyval == GDK_Page_Up)
9216 if (keyval == GDK_Page_Down)
9223 gtk_entry_completion_key_press (GtkWidget *widget,
9227 gint matches, actions = 0;
9228 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
9230 if (!gtk_widget_get_mapped (completion->priv->popup_window))
9233 matches = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->filter_model), NULL);
9235 if (completion->priv->actions)
9236 actions = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->actions), NULL);
9238 if (keyval_is_cursor_move (event->keyval))
9240 GtkTreePath *path = NULL;
9242 if (event->keyval == GDK_Up || event->keyval == GDK_KP_Up)
9244 if (completion->priv->current_selected < 0)
9245 completion->priv->current_selected = matches + actions - 1;
9247 completion->priv->current_selected--;
9249 else if (event->keyval == GDK_Down || event->keyval == GDK_KP_Down)
9251 if (completion->priv->current_selected < matches + actions - 1)
9252 completion->priv->current_selected++;
9254 completion->priv->current_selected = -1;
9256 else if (event->keyval == GDK_Page_Up)
9258 if (completion->priv->current_selected < 0)
9259 completion->priv->current_selected = matches + actions - 1;
9260 else if (completion->priv->current_selected == 0)
9261 completion->priv->current_selected = -1;
9262 else if (completion->priv->current_selected < matches)
9264 completion->priv->current_selected -= 14;
9265 if (completion->priv->current_selected < 0)
9266 completion->priv->current_selected = 0;
9270 completion->priv->current_selected -= 14;
9271 if (completion->priv->current_selected < matches - 1)
9272 completion->priv->current_selected = matches - 1;
9275 else if (event->keyval == GDK_Page_Down)
9277 if (completion->priv->current_selected < 0)
9278 completion->priv->current_selected = 0;
9279 else if (completion->priv->current_selected < matches - 1)
9281 completion->priv->current_selected += 14;
9282 if (completion->priv->current_selected > matches - 1)
9283 completion->priv->current_selected = matches - 1;
9285 else if (completion->priv->current_selected == matches + actions - 1)
9287 completion->priv->current_selected = -1;
9291 completion->priv->current_selected += 14;
9292 if (completion->priv->current_selected > matches + actions - 1)
9293 completion->priv->current_selected = matches + actions - 1;
9297 if (completion->priv->current_selected < 0)
9299 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9300 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view)));
9302 if (completion->priv->inline_selection &&
9303 completion->priv->completion_prefix)
9305 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9306 completion->priv->completion_prefix);
9307 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9310 else if (completion->priv->current_selected < matches)
9312 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view)));
9314 path = gtk_tree_path_new_from_indices (completion->priv->current_selected, -1);
9315 gtk_tree_view_set_cursor (GTK_TREE_VIEW (completion->priv->tree_view),
9318 if (completion->priv->inline_selection)
9322 GtkTreeIter child_iter;
9323 GtkTreeModel *model = NULL;
9324 GtkTreeSelection *sel;
9327 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view));
9328 if (!gtk_tree_selection_get_selected (sel, &model, &iter))
9331 gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (model), &child_iter, &iter);
9332 model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model));
9334 if (completion->priv->completion_prefix == NULL)
9335 completion->priv->completion_prefix = g_strdup (gtk_entry_get_text (GTK_ENTRY (completion->priv->entry)));
9337 g_signal_emit_by_name (completion, "cursor-on-match", model,
9338 &child_iter, &entry_set);
9341 else if (completion->priv->current_selected - matches >= 0)
9343 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9345 path = gtk_tree_path_new_from_indices (completion->priv->current_selected - matches, -1);
9346 gtk_tree_view_set_cursor (GTK_TREE_VIEW (completion->priv->action_view),
9349 if (completion->priv->inline_selection &&
9350 completion->priv->completion_prefix)
9352 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9353 completion->priv->completion_prefix);
9354 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9358 gtk_tree_path_free (path);
9362 else if (event->keyval == GDK_Escape ||
9363 event->keyval == GDK_Left ||
9364 event->keyval == GDK_KP_Left ||
9365 event->keyval == GDK_Right ||
9366 event->keyval == GDK_KP_Right)
9368 gboolean retval = TRUE;
9370 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9371 _gtk_entry_completion_popdown (completion);
9373 if (completion->priv->current_selected < 0)
9376 goto keypress_completion_out;
9378 else if (completion->priv->inline_selection)
9380 /* Escape rejects the tentative completion */
9381 if (event->keyval == GDK_Escape)
9383 if (completion->priv->completion_prefix)
9384 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9385 completion->priv->completion_prefix);
9387 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry), "");
9390 /* Move the cursor to the end for Right/Esc, to the
9391 beginning for Left */
9392 if (event->keyval == GDK_Right ||
9393 event->keyval == GDK_KP_Right ||
9394 event->keyval == GDK_Escape)
9395 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9397 gtk_editable_set_position (GTK_EDITABLE (widget), 0);
9400 keypress_completion_out:
9401 if (completion->priv->inline_selection)
9403 g_free (completion->priv->completion_prefix);
9404 completion->priv->completion_prefix = NULL;
9409 else if (event->keyval == GDK_Tab ||
9410 event->keyval == GDK_KP_Tab ||
9411 event->keyval == GDK_ISO_Left_Tab)
9413 GtkDirectionType dir = event->keyval == GDK_ISO_Left_Tab ?
9414 GTK_DIR_TAB_BACKWARD : GTK_DIR_TAB_FORWARD;
9416 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9417 _gtk_entry_completion_popdown (completion);
9419 g_free (completion->priv->completion_prefix);
9420 completion->priv->completion_prefix = NULL;
9422 gtk_widget_child_focus (gtk_widget_get_toplevel (widget), dir);
9426 else if (event->keyval == GDK_ISO_Enter ||
9427 event->keyval == GDK_KP_Enter ||
9428 event->keyval == GDK_Return)
9431 GtkTreeModel *model = NULL;
9432 GtkTreeSelection *sel;
9433 gboolean retval = TRUE;
9435 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9436 _gtk_entry_completion_popdown (completion);
9438 if (completion->priv->current_selected < matches)
9442 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view));
9443 if (gtk_tree_selection_get_selected (sel, &model, &iter))
9445 g_signal_handler_block (widget, completion->priv->changed_id);
9446 g_signal_emit_by_name (completion, "match-selected",
9447 model, &iter, &entry_set);
9448 g_signal_handler_unblock (widget, completion->priv->changed_id);
9454 gtk_tree_model_get (model, &iter,
9455 completion->priv->text_column, &str,
9458 gtk_entry_set_text (GTK_ENTRY (widget), str);
9460 /* move the cursor to the end */
9461 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9469 else if (completion->priv->current_selected - matches >= 0)
9471 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view));
9472 if (gtk_tree_selection_get_selected (sel, &model, &iter))
9476 path = gtk_tree_path_new_from_indices (completion->priv->current_selected - matches, -1);
9477 g_signal_emit_by_name (completion, "action-activated",
9478 gtk_tree_path_get_indices (path)[0]);
9479 gtk_tree_path_free (path);
9485 g_free (completion->priv->completion_prefix);
9486 completion->priv->completion_prefix = NULL;
9495 gtk_entry_completion_changed (GtkWidget *entry,
9498 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
9499 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
9502 /* (re)install completion timeout */
9503 if (completion->priv->completion_timeout)
9504 g_source_remove (completion->priv->completion_timeout);
9506 if (!gtk_entry_get_text (GTK_ENTRY (entry)))
9509 /* no need to normalize for this test */
9510 if (completion->priv->minimum_key_length > 0 &&
9511 strcmp ("", gtk_entry_get_text (GTK_ENTRY (entry))) == 0)
9513 if (gtk_widget_get_visible (completion->priv->popup_window))
9514 _gtk_entry_completion_popdown (completion);
9518 device = gtk_get_current_event_device ();
9520 if (device && device->source == GDK_SOURCE_KEYBOARD)
9521 device = gdk_device_get_associated_device (device);
9524 priv->completion_device = device;
9526 completion->priv->completion_timeout =
9527 gdk_threads_add_timeout (COMPLETION_TIMEOUT,
9528 gtk_entry_completion_timeout,
9533 check_completion_callback (GtkEntryCompletion *completion)
9535 completion->priv->check_completion_idle = NULL;
9537 gtk_entry_completion_complete (completion);
9538 gtk_entry_completion_insert_prefix (completion);
9544 clear_completion_callback (GtkEntry *entry,
9547 if (pspec->name == I_("cursor-position") ||
9548 pspec->name == I_("selection-bound"))
9550 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
9552 completion->priv->has_completion = FALSE;
9557 accept_completion_callback (GtkEntry *entry)
9559 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
9561 if (completion->priv->has_completion)
9562 gtk_editable_set_position (GTK_EDITABLE (entry),
9563 gtk_entry_buffer_get_length (get_buffer (entry)));
9569 completion_insert_text_callback (GtkEntry *entry,
9573 GtkEntryCompletion *completion)
9575 /* idle to update the selection based on the file list */
9576 if (completion->priv->check_completion_idle == NULL)
9578 completion->priv->check_completion_idle = g_idle_source_new ();
9579 g_source_set_priority (completion->priv->check_completion_idle, G_PRIORITY_HIGH);
9580 g_source_set_closure (completion->priv->check_completion_idle,
9581 g_cclosure_new_object (G_CALLBACK (check_completion_callback),
9582 G_OBJECT (completion)));
9583 g_source_attach (completion->priv->check_completion_idle, NULL);
9588 completion_changed (GtkEntryCompletion *completion,
9592 GtkEntry *entry = GTK_ENTRY (data);
9594 if (pspec->name == I_("popup-completion") ||
9595 pspec->name == I_("inline-completion"))
9597 disconnect_completion_signals (entry, completion);
9598 connect_completion_signals (entry, completion);
9603 disconnect_completion_signals (GtkEntry *entry,
9604 GtkEntryCompletion *completion)
9606 g_signal_handlers_disconnect_by_func (completion,
9607 G_CALLBACK (completion_changed), entry);
9608 if (completion->priv->changed_id > 0 &&
9609 g_signal_handler_is_connected (entry, completion->priv->changed_id))
9611 g_signal_handler_disconnect (entry, completion->priv->changed_id);
9612 completion->priv->changed_id = 0;
9614 g_signal_handlers_disconnect_by_func (entry,
9615 G_CALLBACK (gtk_entry_completion_key_press), completion);
9616 if (completion->priv->insert_text_id > 0 &&
9617 g_signal_handler_is_connected (entry, completion->priv->insert_text_id))
9619 g_signal_handler_disconnect (entry, completion->priv->insert_text_id);
9620 completion->priv->insert_text_id = 0;
9622 g_signal_handlers_disconnect_by_func (entry,
9623 G_CALLBACK (completion_insert_text_callback), completion);
9624 g_signal_handlers_disconnect_by_func (entry,
9625 G_CALLBACK (clear_completion_callback), completion);
9626 g_signal_handlers_disconnect_by_func (entry,
9627 G_CALLBACK (accept_completion_callback), completion);
9631 connect_completion_signals (GtkEntry *entry,
9632 GtkEntryCompletion *completion)
9634 if (completion->priv->popup_completion)
9636 completion->priv->changed_id =
9637 g_signal_connect (entry, "changed",
9638 G_CALLBACK (gtk_entry_completion_changed), completion);
9639 g_signal_connect (entry, "key-press-event",
9640 G_CALLBACK (gtk_entry_completion_key_press), completion);
9643 if (completion->priv->inline_completion)
9645 completion->priv->insert_text_id =
9646 g_signal_connect (entry, "insert-text",
9647 G_CALLBACK (completion_insert_text_callback), completion);
9648 g_signal_connect (entry, "notify",
9649 G_CALLBACK (clear_completion_callback), completion);
9650 g_signal_connect (entry, "activate",
9651 G_CALLBACK (accept_completion_callback), completion);
9652 g_signal_connect (entry, "focus-out-event",
9653 G_CALLBACK (accept_completion_callback), completion);
9656 g_signal_connect (completion, "notify",
9657 G_CALLBACK (completion_changed), entry);
9661 * gtk_entry_set_completion:
9662 * @entry: A #GtkEntry
9663 * @completion: (allow-none): The #GtkEntryCompletion or %NULL
9665 * Sets @completion to be the auxiliary completion object to use with @entry.
9666 * All further configuration of the completion mechanism is done on
9667 * @completion using the #GtkEntryCompletion API. Completion is disabled if
9668 * @completion is set to %NULL.
9673 gtk_entry_set_completion (GtkEntry *entry,
9674 GtkEntryCompletion *completion)
9676 GtkEntryCompletion *old;
9678 g_return_if_fail (GTK_IS_ENTRY (entry));
9679 g_return_if_fail (!completion || GTK_IS_ENTRY_COMPLETION (completion));
9681 old = gtk_entry_get_completion (entry);
9683 if (old == completion)
9688 if (old->priv->completion_timeout)
9690 g_source_remove (old->priv->completion_timeout);
9691 old->priv->completion_timeout = 0;
9694 if (gtk_widget_get_mapped (old->priv->popup_window))
9695 _gtk_entry_completion_popdown (old);
9697 disconnect_completion_signals (entry, old);
9698 old->priv->entry = NULL;
9700 g_object_unref (old);
9705 g_object_set_data (G_OBJECT (entry), I_(GTK_ENTRY_COMPLETION_KEY), NULL);
9709 /* hook into the entry */
9710 g_object_ref (completion);
9712 connect_completion_signals (entry, completion);
9713 completion->priv->entry = GTK_WIDGET (entry);
9714 g_object_set_data (G_OBJECT (entry), I_(GTK_ENTRY_COMPLETION_KEY), completion);
9718 * gtk_entry_get_completion:
9719 * @entry: A #GtkEntry
9721 * Returns the auxiliary completion object currently in use by @entry.
9723 * Return value: The auxiliary completion object currently in use by @entry.
9727 GtkEntryCompletion *
9728 gtk_entry_get_completion (GtkEntry *entry)
9730 GtkEntryCompletion *completion;
9732 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
9734 completion = GTK_ENTRY_COMPLETION (g_object_get_data (G_OBJECT (entry),
9735 GTK_ENTRY_COMPLETION_KEY));
9741 * gtk_entry_set_cursor_hadjustment:
9742 * @entry: a #GtkEntry
9743 * @adjustment: an adjustment which should be adjusted when the cursor
9744 * is moved, or %NULL
9746 * Hooks up an adjustment to the cursor position in an entry, so that when
9747 * the cursor is moved, the adjustment is scrolled to show that position.
9748 * See gtk_scrolled_window_get_hadjustment() for a typical way of obtaining
9751 * The adjustment has to be in pixel units and in the same coordinate system
9757 gtk_entry_set_cursor_hadjustment (GtkEntry *entry,
9758 GtkAdjustment *adjustment)
9760 g_return_if_fail (GTK_IS_ENTRY (entry));
9762 g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
9765 g_object_ref (adjustment);
9767 g_object_set_qdata_full (G_OBJECT (entry),
9768 quark_cursor_hadjustment,
9774 * gtk_entry_get_cursor_hadjustment:
9775 * @entry: a #GtkEntry
9777 * Retrieves the horizontal cursor adjustment for the entry.
9778 * See gtk_entry_set_cursor_hadjustment().
9780 * Return value: (transfer none): the horizontal cursor adjustment, or %NULL
9781 * if none has been set.
9786 gtk_entry_get_cursor_hadjustment (GtkEntry *entry)
9788 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
9790 return g_object_get_qdata (G_OBJECT (entry), quark_cursor_hadjustment);
9794 * gtk_entry_set_progress_fraction:
9795 * @entry: a #GtkEntry
9796 * @fraction: fraction of the task that's been completed
9798 * Causes the entry's progress indicator to "fill in" the given
9799 * fraction of the bar. The fraction should be between 0.0 and 1.0,
9805 gtk_entry_set_progress_fraction (GtkEntry *entry,
9809 GtkEntryPrivate *private;
9810 gdouble old_fraction;
9811 gint x, y, width, height;
9812 gint old_x, old_y, old_width, old_height;
9814 g_return_if_fail (GTK_IS_ENTRY (entry));
9816 widget = GTK_WIDGET (entry);
9817 private = GTK_ENTRY_GET_PRIVATE (entry);
9819 if (private->progress_pulse_mode)
9822 old_fraction = private->progress_fraction;
9824 if (gtk_widget_is_drawable (widget))
9825 get_progress_area (widget, &old_x, &old_y, &old_width, &old_height);
9827 fraction = CLAMP (fraction, 0.0, 1.0);
9829 private->progress_fraction = fraction;
9830 private->progress_pulse_mode = FALSE;
9831 private->progress_pulse_current = 0.0;
9833 if (gtk_widget_is_drawable (widget))
9835 get_progress_area (widget, &x, &y, &width, &height);
9837 if ((x != old_x) || (y != old_y) || (width != old_width) || (height != old_height))
9838 gtk_widget_queue_draw (widget);
9841 if (fraction != old_fraction)
9842 g_object_notify (G_OBJECT (entry), "progress-fraction");
9846 * gtk_entry_get_progress_fraction:
9847 * @entry: a #GtkEntry
9849 * Returns the current fraction of the task that's been completed.
9850 * See gtk_entry_set_progress_fraction().
9852 * Return value: a fraction from 0.0 to 1.0
9857 gtk_entry_get_progress_fraction (GtkEntry *entry)
9859 GtkEntryPrivate *private;
9861 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
9863 private = GTK_ENTRY_GET_PRIVATE (entry);
9865 return private->progress_fraction;
9869 * gtk_entry_set_progress_pulse_step:
9870 * @entry: a #GtkEntry
9871 * @fraction: fraction between 0.0 and 1.0
9873 * Sets the fraction of total entry width to move the progress
9874 * bouncing block for each call to gtk_entry_progress_pulse().
9879 gtk_entry_set_progress_pulse_step (GtkEntry *entry,
9882 GtkEntryPrivate *private;
9884 g_return_if_fail (GTK_IS_ENTRY (entry));
9886 private = GTK_ENTRY_GET_PRIVATE (entry);
9888 fraction = CLAMP (fraction, 0.0, 1.0);
9890 if (fraction != private->progress_pulse_fraction)
9892 private->progress_pulse_fraction = fraction;
9894 gtk_widget_queue_draw (GTK_WIDGET (entry));
9896 g_object_notify (G_OBJECT (entry), "progress-pulse-step");
9901 * gtk_entry_get_progress_pulse_step:
9902 * @entry: a #GtkEntry
9904 * Retrieves the pulse step set with gtk_entry_set_progress_pulse_step().
9906 * Return value: a fraction from 0.0 to 1.0
9911 gtk_entry_get_progress_pulse_step (GtkEntry *entry)
9913 GtkEntryPrivate *private;
9915 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
9917 private = GTK_ENTRY_GET_PRIVATE (entry);
9919 return private->progress_pulse_fraction;
9923 * gtk_entry_progress_pulse:
9924 * @entry: a #GtkEntry
9926 * Indicates that some progress is made, but you don't know how much.
9927 * Causes the entry's progress indicator to enter "activity mode,"
9928 * where a block bounces back and forth. Each call to
9929 * gtk_entry_progress_pulse() causes the block to move by a little bit
9930 * (the amount of movement per pulse is determined by
9931 * gtk_entry_set_progress_pulse_step()).
9936 gtk_entry_progress_pulse (GtkEntry *entry)
9938 GtkEntryPrivate *private;
9940 g_return_if_fail (GTK_IS_ENTRY (entry));
9942 private = GTK_ENTRY_GET_PRIVATE (entry);
9944 if (private->progress_pulse_mode)
9946 if (private->progress_pulse_way_back)
9948 private->progress_pulse_current -= private->progress_pulse_fraction;
9950 if (private->progress_pulse_current < 0.0)
9952 private->progress_pulse_current = 0.0;
9953 private->progress_pulse_way_back = FALSE;
9958 private->progress_pulse_current += private->progress_pulse_fraction;
9960 if (private->progress_pulse_current > 1.0 - private->progress_pulse_fraction)
9962 private->progress_pulse_current = 1.0 - private->progress_pulse_fraction;
9963 private->progress_pulse_way_back = TRUE;
9969 private->progress_fraction = 0.0;
9970 private->progress_pulse_mode = TRUE;
9971 private->progress_pulse_way_back = FALSE;
9972 private->progress_pulse_current = 0.0;
9975 gtk_widget_queue_draw (GTK_WIDGET (entry));
9978 /* Caps Lock warning for password entries */
9981 show_capslock_feedback (GtkEntry *entry,
9984 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
9986 if (gtk_entry_get_icon_storage_type (entry, GTK_ENTRY_ICON_SECONDARY) == GTK_IMAGE_EMPTY)
9988 gtk_entry_set_icon_from_stock (entry, GTK_ENTRY_ICON_SECONDARY, GTK_STOCK_CAPS_LOCK_WARNING);
9989 gtk_entry_set_icon_activatable (entry, GTK_ENTRY_ICON_SECONDARY, FALSE);
9990 priv->caps_lock_warning_shown = TRUE;
9993 if (priv->caps_lock_warning_shown)
9994 gtk_entry_set_icon_tooltip_text (entry, GTK_ENTRY_ICON_SECONDARY, text);
9996 g_warning ("Can't show Caps Lock warning, since secondary icon is set");
10000 remove_capslock_feedback (GtkEntry *entry)
10002 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
10004 if (priv->caps_lock_warning_shown)
10006 gtk_entry_set_icon_from_stock (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
10007 priv->caps_lock_warning_shown = FALSE;
10012 keymap_state_changed (GdkKeymap *keymap,
10015 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
10018 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL && priv->caps_lock_warning)
10020 if (gdk_keymap_get_num_lock_state (keymap)
10021 && gdk_keymap_get_caps_lock_state (keymap))
10022 text = _("Caps Lock and Num Lock are on");
10023 else if (gdk_keymap_get_num_lock_state (keymap))
10024 text = _("Num Lock is on");
10025 else if (gdk_keymap_get_caps_lock_state (keymap))
10026 text = _("Caps Lock is on");
10030 show_capslock_feedback (entry, text);
10032 remove_capslock_feedback (entry);