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));
1746 gtk_settings_install_property (g_param_spec_boolean ("gtk-entry-select-on-focus",
1747 P_("Select on focus"),
1748 P_("Whether to select the contents of an entry when it is focused"),
1750 GTK_PARAM_READWRITE));
1753 * GtkSettings:gtk-entry-password-hint-timeout:
1755 * How long to show the last input character in hidden
1756 * entries. This value is in milliseconds. 0 disables showing the
1757 * last char. 600 is a good value for enabling it.
1761 gtk_settings_install_property (g_param_spec_uint ("gtk-entry-password-hint-timeout",
1762 P_("Password Hint Timeout"),
1763 P_("How long to show the last input character in hidden entries"),
1765 GTK_PARAM_READWRITE));
1767 g_type_class_add_private (gobject_class, sizeof (GtkEntryPrivate));
1771 gtk_entry_editable_init (GtkEditableClass *iface)
1773 iface->do_insert_text = gtk_entry_insert_text;
1774 iface->do_delete_text = gtk_entry_delete_text;
1775 iface->insert_text = gtk_entry_real_insert_text;
1776 iface->delete_text = gtk_entry_real_delete_text;
1777 iface->get_chars = gtk_entry_get_chars;
1778 iface->set_selection_bounds = gtk_entry_set_selection_bounds;
1779 iface->get_selection_bounds = gtk_entry_get_selection_bounds;
1780 iface->set_position = gtk_entry_real_set_position;
1781 iface->get_position = gtk_entry_get_position;
1785 gtk_entry_cell_editable_init (GtkCellEditableIface *iface)
1787 iface->start_editing = gtk_entry_start_editing;
1791 gtk_entry_set_property (GObject *object,
1793 const GValue *value,
1796 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (object);
1797 GtkEntry *entry = GTK_ENTRY (object);
1803 gtk_entry_set_buffer (entry, g_value_get_object (value));
1808 gboolean new_value = g_value_get_boolean (value);
1810 if (new_value != entry->editable)
1812 widget = GTK_WIDGET (entry);
1815 _gtk_entry_reset_im_context (entry);
1816 if (gtk_widget_has_focus (widget))
1817 gtk_im_context_focus_out (entry->im_context);
1819 entry->preedit_length = 0;
1820 entry->preedit_cursor = 0;
1823 entry->editable = new_value;
1825 if (new_value && gtk_widget_has_focus (widget))
1826 gtk_im_context_focus_in (entry->im_context);
1828 gtk_entry_queue_draw (entry);
1833 case PROP_MAX_LENGTH:
1834 gtk_entry_set_max_length (entry, g_value_get_int (value));
1837 case PROP_VISIBILITY:
1838 gtk_entry_set_visibility (entry, g_value_get_boolean (value));
1841 case PROP_HAS_FRAME:
1842 gtk_entry_set_has_frame (entry, g_value_get_boolean (value));
1845 case PROP_INNER_BORDER:
1846 gtk_entry_set_inner_border (entry, g_value_get_boxed (value));
1849 case PROP_INVISIBLE_CHAR:
1850 gtk_entry_set_invisible_char (entry, g_value_get_uint (value));
1853 case PROP_ACTIVATES_DEFAULT:
1854 gtk_entry_set_activates_default (entry, g_value_get_boolean (value));
1857 case PROP_WIDTH_CHARS:
1858 gtk_entry_set_width_chars (entry, g_value_get_int (value));
1862 gtk_entry_set_text (entry, g_value_get_string (value));
1866 gtk_entry_set_alignment (entry, g_value_get_float (value));
1869 case PROP_TRUNCATE_MULTILINE:
1870 entry->truncate_multiline = g_value_get_boolean (value);
1873 case PROP_SHADOW_TYPE:
1874 priv->shadow_type = g_value_get_enum (value);
1877 case PROP_OVERWRITE_MODE:
1878 gtk_entry_set_overwrite_mode (entry, g_value_get_boolean (value));
1881 case PROP_INVISIBLE_CHAR_SET:
1882 if (g_value_get_boolean (value))
1883 priv->invisible_char_set = TRUE;
1885 gtk_entry_unset_invisible_char (entry);
1888 case PROP_CAPS_LOCK_WARNING:
1889 priv->caps_lock_warning = g_value_get_boolean (value);
1892 case PROP_PROGRESS_FRACTION:
1893 gtk_entry_set_progress_fraction (entry, g_value_get_double (value));
1896 case PROP_PROGRESS_PULSE_STEP:
1897 gtk_entry_set_progress_pulse_step (entry, g_value_get_double (value));
1900 case PROP_PIXBUF_PRIMARY:
1901 gtk_entry_set_icon_from_pixbuf (entry,
1902 GTK_ENTRY_ICON_PRIMARY,
1903 g_value_get_object (value));
1906 case PROP_PIXBUF_SECONDARY:
1907 gtk_entry_set_icon_from_pixbuf (entry,
1908 GTK_ENTRY_ICON_SECONDARY,
1909 g_value_get_object (value));
1912 case PROP_STOCK_PRIMARY:
1913 gtk_entry_set_icon_from_stock (entry,
1914 GTK_ENTRY_ICON_PRIMARY,
1915 g_value_get_string (value));
1918 case PROP_STOCK_SECONDARY:
1919 gtk_entry_set_icon_from_stock (entry,
1920 GTK_ENTRY_ICON_SECONDARY,
1921 g_value_get_string (value));
1924 case PROP_ICON_NAME_PRIMARY:
1925 gtk_entry_set_icon_from_icon_name (entry,
1926 GTK_ENTRY_ICON_PRIMARY,
1927 g_value_get_string (value));
1930 case PROP_ICON_NAME_SECONDARY:
1931 gtk_entry_set_icon_from_icon_name (entry,
1932 GTK_ENTRY_ICON_SECONDARY,
1933 g_value_get_string (value));
1936 case PROP_GICON_PRIMARY:
1937 gtk_entry_set_icon_from_gicon (entry,
1938 GTK_ENTRY_ICON_PRIMARY,
1939 g_value_get_object (value));
1942 case PROP_GICON_SECONDARY:
1943 gtk_entry_set_icon_from_gicon (entry,
1944 GTK_ENTRY_ICON_SECONDARY,
1945 g_value_get_object (value));
1948 case PROP_ACTIVATABLE_PRIMARY:
1949 gtk_entry_set_icon_activatable (entry,
1950 GTK_ENTRY_ICON_PRIMARY,
1951 g_value_get_boolean (value));
1954 case PROP_ACTIVATABLE_SECONDARY:
1955 gtk_entry_set_icon_activatable (entry,
1956 GTK_ENTRY_ICON_SECONDARY,
1957 g_value_get_boolean (value));
1960 case PROP_SENSITIVE_PRIMARY:
1961 gtk_entry_set_icon_sensitive (entry,
1962 GTK_ENTRY_ICON_PRIMARY,
1963 g_value_get_boolean (value));
1966 case PROP_SENSITIVE_SECONDARY:
1967 gtk_entry_set_icon_sensitive (entry,
1968 GTK_ENTRY_ICON_SECONDARY,
1969 g_value_get_boolean (value));
1972 case PROP_TOOLTIP_TEXT_PRIMARY:
1973 gtk_entry_set_icon_tooltip_text (entry,
1974 GTK_ENTRY_ICON_PRIMARY,
1975 g_value_get_string (value));
1978 case PROP_TOOLTIP_TEXT_SECONDARY:
1979 gtk_entry_set_icon_tooltip_text (entry,
1980 GTK_ENTRY_ICON_SECONDARY,
1981 g_value_get_string (value));
1984 case PROP_TOOLTIP_MARKUP_PRIMARY:
1985 gtk_entry_set_icon_tooltip_markup (entry,
1986 GTK_ENTRY_ICON_PRIMARY,
1987 g_value_get_string (value));
1990 case PROP_TOOLTIP_MARKUP_SECONDARY:
1991 gtk_entry_set_icon_tooltip_markup (entry,
1992 GTK_ENTRY_ICON_SECONDARY,
1993 g_value_get_string (value));
1996 case PROP_IM_MODULE:
1997 g_free (priv->im_module);
1998 priv->im_module = g_value_dup_string (value);
1999 if (GTK_IS_IM_MULTICONTEXT (entry->im_context))
2000 gtk_im_multicontext_set_context_id (GTK_IM_MULTICONTEXT (entry->im_context), priv->im_module);
2003 case PROP_EDITING_CANCELED:
2004 entry->editing_canceled = g_value_get_boolean (value);
2007 case PROP_SCROLL_OFFSET:
2008 case PROP_CURSOR_POSITION:
2010 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2016 gtk_entry_get_property (GObject *object,
2021 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (object);
2022 GtkEntry *entry = GTK_ENTRY (object);
2027 g_value_set_object (value, gtk_entry_get_buffer (entry));
2030 case PROP_CURSOR_POSITION:
2031 g_value_set_int (value, entry->current_pos);
2034 case PROP_SELECTION_BOUND:
2035 g_value_set_int (value, entry->selection_bound);
2039 g_value_set_boolean (value, entry->editable);
2042 case PROP_MAX_LENGTH:
2043 g_value_set_int (value, gtk_entry_buffer_get_max_length (get_buffer (entry)));
2046 case PROP_VISIBILITY:
2047 g_value_set_boolean (value, entry->visible);
2050 case PROP_HAS_FRAME:
2051 g_value_set_boolean (value, entry->has_frame);
2054 case PROP_INNER_BORDER:
2055 g_value_set_boxed (value, gtk_entry_get_inner_border (entry));
2058 case PROP_INVISIBLE_CHAR:
2059 g_value_set_uint (value, entry->invisible_char);
2062 case PROP_ACTIVATES_DEFAULT:
2063 g_value_set_boolean (value, entry->activates_default);
2066 case PROP_WIDTH_CHARS:
2067 g_value_set_int (value, entry->width_chars);
2070 case PROP_SCROLL_OFFSET:
2071 g_value_set_int (value, entry->scroll_offset);
2075 g_value_set_string (value, gtk_entry_get_text (entry));
2079 g_value_set_float (value, gtk_entry_get_alignment (entry));
2082 case PROP_TRUNCATE_MULTILINE:
2083 g_value_set_boolean (value, entry->truncate_multiline);
2086 case PROP_SHADOW_TYPE:
2087 g_value_set_enum (value, priv->shadow_type);
2090 case PROP_OVERWRITE_MODE:
2091 g_value_set_boolean (value, entry->overwrite_mode);
2094 case PROP_TEXT_LENGTH:
2095 g_value_set_uint (value, gtk_entry_buffer_get_length (get_buffer (entry)));
2098 case PROP_INVISIBLE_CHAR_SET:
2099 g_value_set_boolean (value, priv->invisible_char_set);
2102 case PROP_IM_MODULE:
2103 g_value_set_string (value, priv->im_module);
2106 case PROP_CAPS_LOCK_WARNING:
2107 g_value_set_boolean (value, priv->caps_lock_warning);
2110 case PROP_PROGRESS_FRACTION:
2111 g_value_set_double (value, priv->progress_fraction);
2114 case PROP_PROGRESS_PULSE_STEP:
2115 g_value_set_double (value, priv->progress_pulse_fraction);
2118 case PROP_PIXBUF_PRIMARY:
2119 g_value_set_object (value,
2120 gtk_entry_get_icon_pixbuf (entry,
2121 GTK_ENTRY_ICON_PRIMARY));
2124 case PROP_PIXBUF_SECONDARY:
2125 g_value_set_object (value,
2126 gtk_entry_get_icon_pixbuf (entry,
2127 GTK_ENTRY_ICON_SECONDARY));
2130 case PROP_STOCK_PRIMARY:
2131 g_value_set_string (value,
2132 gtk_entry_get_icon_stock (entry,
2133 GTK_ENTRY_ICON_PRIMARY));
2136 case PROP_STOCK_SECONDARY:
2137 g_value_set_string (value,
2138 gtk_entry_get_icon_stock (entry,
2139 GTK_ENTRY_ICON_SECONDARY));
2142 case PROP_ICON_NAME_PRIMARY:
2143 g_value_set_string (value,
2144 gtk_entry_get_icon_name (entry,
2145 GTK_ENTRY_ICON_PRIMARY));
2148 case PROP_ICON_NAME_SECONDARY:
2149 g_value_set_string (value,
2150 gtk_entry_get_icon_name (entry,
2151 GTK_ENTRY_ICON_SECONDARY));
2154 case PROP_GICON_PRIMARY:
2155 g_value_set_object (value,
2156 gtk_entry_get_icon_gicon (entry,
2157 GTK_ENTRY_ICON_PRIMARY));
2160 case PROP_GICON_SECONDARY:
2161 g_value_set_object (value,
2162 gtk_entry_get_icon_gicon (entry,
2163 GTK_ENTRY_ICON_SECONDARY));
2166 case PROP_STORAGE_TYPE_PRIMARY:
2167 g_value_set_enum (value,
2168 gtk_entry_get_icon_storage_type (entry,
2169 GTK_ENTRY_ICON_PRIMARY));
2172 case PROP_STORAGE_TYPE_SECONDARY:
2173 g_value_set_enum (value,
2174 gtk_entry_get_icon_storage_type (entry,
2175 GTK_ENTRY_ICON_SECONDARY));
2178 case PROP_ACTIVATABLE_PRIMARY:
2179 g_value_set_boolean (value,
2180 gtk_entry_get_icon_activatable (entry, GTK_ENTRY_ICON_PRIMARY));
2183 case PROP_ACTIVATABLE_SECONDARY:
2184 g_value_set_boolean (value,
2185 gtk_entry_get_icon_activatable (entry, GTK_ENTRY_ICON_SECONDARY));
2188 case PROP_SENSITIVE_PRIMARY:
2189 g_value_set_boolean (value,
2190 gtk_entry_get_icon_sensitive (entry, GTK_ENTRY_ICON_PRIMARY));
2193 case PROP_SENSITIVE_SECONDARY:
2194 g_value_set_boolean (value,
2195 gtk_entry_get_icon_sensitive (entry, GTK_ENTRY_ICON_SECONDARY));
2198 case PROP_TOOLTIP_TEXT_PRIMARY:
2199 g_value_take_string (value,
2200 gtk_entry_get_icon_tooltip_text (entry, GTK_ENTRY_ICON_PRIMARY));
2203 case PROP_TOOLTIP_TEXT_SECONDARY:
2204 g_value_take_string (value,
2205 gtk_entry_get_icon_tooltip_text (entry, GTK_ENTRY_ICON_SECONDARY));
2208 case PROP_TOOLTIP_MARKUP_PRIMARY:
2209 g_value_take_string (value,
2210 gtk_entry_get_icon_tooltip_markup (entry, GTK_ENTRY_ICON_PRIMARY));
2213 case PROP_TOOLTIP_MARKUP_SECONDARY:
2214 g_value_take_string (value,
2215 gtk_entry_get_icon_tooltip_markup (entry, GTK_ENTRY_ICON_SECONDARY));
2218 case PROP_EDITING_CANCELED:
2219 g_value_set_boolean (value,
2220 entry->editing_canceled);
2224 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2230 find_invisible_char (GtkWidget *widget)
2232 PangoLayout *layout;
2233 PangoAttrList *attr_list;
2235 gunichar invisible_chars [] = {
2237 0x25cf, /* BLACK CIRCLE */
2238 0x2022, /* BULLET */
2239 0x2731, /* HEAVY ASTERISK */
2240 0x273a /* SIXTEEN POINTED ASTERISK */
2243 if (gtk_widget_get_style (widget))
2244 gtk_widget_style_get (widget,
2245 "invisible-char", &invisible_chars[0],
2248 layout = gtk_widget_create_pango_layout (widget, NULL);
2250 attr_list = pango_attr_list_new ();
2251 pango_attr_list_insert (attr_list, pango_attr_fallback_new (FALSE));
2253 pango_layout_set_attributes (layout, attr_list);
2254 pango_attr_list_unref (attr_list);
2256 for (i = (invisible_chars[0] != 0 ? 0 : 1); i < G_N_ELEMENTS (invisible_chars); i++)
2258 gchar text[7] = { 0, };
2261 len = g_unichar_to_utf8 (invisible_chars[i], text);
2262 pango_layout_set_text (layout, text, len);
2264 count = pango_layout_get_unknown_glyphs_count (layout);
2268 g_object_unref (layout);
2269 return invisible_chars[i];
2273 g_object_unref (layout);
2279 gtk_entry_init (GtkEntry *entry)
2281 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2283 gtk_widget_set_can_focus (GTK_WIDGET (entry), TRUE);
2285 entry->editable = TRUE;
2286 entry->visible = TRUE;
2287 entry->invisible_char = find_invisible_char (GTK_WIDGET (entry));
2288 entry->dnd_position = -1;
2289 entry->width_chars = -1;
2290 entry->is_cell_renderer = FALSE;
2291 entry->editing_canceled = FALSE;
2292 entry->has_frame = TRUE;
2293 entry->truncate_multiline = FALSE;
2294 priv->shadow_type = GTK_SHADOW_IN;
2296 priv->caps_lock_warning = TRUE;
2297 priv->caps_lock_warning_shown = FALSE;
2298 priv->progress_fraction = 0.0;
2299 priv->progress_pulse_fraction = 0.1;
2301 gtk_drag_dest_set (GTK_WIDGET (entry),
2302 GTK_DEST_DEFAULT_HIGHLIGHT,
2304 GDK_ACTION_COPY | GDK_ACTION_MOVE);
2305 gtk_drag_dest_add_text_targets (GTK_WIDGET (entry));
2307 /* This object is completely private. No external entity can gain a reference
2308 * to it; so we create it here and destroy it in finalize().
2310 entry->im_context = gtk_im_multicontext_new ();
2312 g_signal_connect (entry->im_context, "commit",
2313 G_CALLBACK (gtk_entry_commit_cb), entry);
2314 g_signal_connect (entry->im_context, "preedit-changed",
2315 G_CALLBACK (gtk_entry_preedit_changed_cb), entry);
2316 g_signal_connect (entry->im_context, "retrieve-surrounding",
2317 G_CALLBACK (gtk_entry_retrieve_surrounding_cb), entry);
2318 g_signal_connect (entry->im_context, "delete-surrounding",
2319 G_CALLBACK (gtk_entry_delete_surrounding_cb), entry);
2324 get_icon_width (GtkEntry *entry,
2325 GtkEntryIconPosition icon_pos)
2327 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2328 EntryIconInfo *icon_info = priv->icons[icon_pos];
2330 GtkSettings *settings;
2331 gint menu_icon_width;
2333 if (!icon_info || icon_info->pixbuf == NULL)
2336 screen = gtk_widget_get_screen (GTK_WIDGET (entry));
2337 settings = gtk_settings_get_for_screen (screen);
2339 gtk_icon_size_lookup_for_settings (settings, GTK_ICON_SIZE_MENU,
2340 &menu_icon_width, NULL);
2342 return MAX (gdk_pixbuf_get_width (icon_info->pixbuf), menu_icon_width);
2346 get_icon_allocations (GtkEntry *entry,
2347 GtkAllocation *primary,
2348 GtkAllocation *secondary)
2351 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2352 gint x, y, width, height;
2354 get_text_area_size (entry, &x, &y, &width, &height);
2356 if (gtk_widget_has_focus (GTK_WIDGET (entry)) && !priv->interior_focus)
2357 y += priv->focus_width;
2360 primary->height = height;
2361 primary->width = get_icon_width (entry, GTK_ENTRY_ICON_PRIMARY);
2362 if (primary->width > 0)
2363 primary->width += 2 * priv->icon_margin;
2366 secondary->height = height;
2367 secondary->width = get_icon_width (entry, GTK_ENTRY_ICON_SECONDARY);
2368 if (secondary->width > 0)
2369 secondary->width += 2 * priv->icon_margin;
2371 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
2373 primary->x = x + width - primary->width;
2379 secondary->x = x + width - secondary->width;
2385 begin_change (GtkEntry *entry)
2387 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2389 priv->change_count++;
2393 end_change (GtkEntry *entry)
2395 GtkEditable *editable = GTK_EDITABLE (entry);
2396 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2398 g_return_if_fail (priv->change_count > 0);
2400 priv->change_count--;
2402 if (priv->change_count == 0)
2404 if (priv->real_changed)
2406 g_signal_emit_by_name (editable, "changed");
2407 priv->real_changed = FALSE;
2413 emit_changed (GtkEntry *entry)
2415 GtkEditable *editable = GTK_EDITABLE (entry);
2416 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2418 if (priv->change_count == 0)
2419 g_signal_emit_by_name (editable, "changed");
2421 priv->real_changed = TRUE;
2425 gtk_entry_destroy (GtkObject *object)
2427 GtkEntry *entry = GTK_ENTRY (object);
2429 entry->current_pos = entry->selection_bound = 0;
2430 _gtk_entry_reset_im_context (entry);
2431 gtk_entry_reset_layout (entry);
2433 if (entry->blink_timeout)
2435 g_source_remove (entry->blink_timeout);
2436 entry->blink_timeout = 0;
2439 if (entry->recompute_idle)
2441 g_source_remove (entry->recompute_idle);
2442 entry->recompute_idle = 0;
2445 GTK_OBJECT_CLASS (gtk_entry_parent_class)->destroy (object);
2449 gtk_entry_dispose (GObject *object)
2451 GtkEntry *entry = GTK_ENTRY (object);
2452 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2454 gtk_entry_set_icon_from_pixbuf (entry, GTK_ENTRY_ICON_PRIMARY, NULL);
2455 gtk_entry_set_icon_tooltip_markup (entry, GTK_ENTRY_ICON_PRIMARY, NULL);
2456 gtk_entry_set_icon_from_pixbuf (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
2457 gtk_entry_set_icon_tooltip_markup (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
2461 buffer_disconnect_signals (entry);
2462 g_object_unref (priv->buffer);
2463 priv->buffer = NULL;
2466 G_OBJECT_CLASS (gtk_entry_parent_class)->dispose (object);
2470 gtk_entry_finalize (GObject *object)
2472 GtkEntry *entry = GTK_ENTRY (object);
2473 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2474 EntryIconInfo *icon_info = NULL;
2477 for (i = 0; i < MAX_ICONS; i++)
2479 if ((icon_info = priv->icons[i]) != NULL)
2481 if (icon_info->target_list != NULL)
2483 gtk_target_list_unref (icon_info->target_list);
2484 icon_info->target_list = NULL;
2487 g_slice_free (EntryIconInfo, icon_info);
2488 priv->icons[i] = NULL;
2492 gtk_entry_set_completion (entry, NULL);
2494 if (entry->cached_layout)
2495 g_object_unref (entry->cached_layout);
2497 g_object_unref (entry->im_context);
2499 if (entry->blink_timeout)
2500 g_source_remove (entry->blink_timeout);
2502 if (entry->recompute_idle)
2503 g_source_remove (entry->recompute_idle);
2505 g_free (priv->im_module);
2507 G_OBJECT_CLASS (gtk_entry_parent_class)->finalize (object);
2511 gtk_entry_get_display_mode (GtkEntry *entry)
2513 GtkEntryPrivate *priv;
2515 return DISPLAY_NORMAL;
2516 priv = GTK_ENTRY_GET_PRIVATE (entry);
2517 if (entry->invisible_char == 0 && priv->invisible_char_set)
2518 return DISPLAY_BLANK;
2519 return DISPLAY_INVISIBLE;
2523 gtk_entry_get_display_text (GtkEntry *entry,
2527 GtkEntryPasswordHint *password_hint;
2528 GtkEntryPrivate *priv;
2529 gunichar invisible_char;
2539 priv = GTK_ENTRY_GET_PRIVATE (entry);
2540 text = gtk_entry_buffer_get_text (get_buffer (entry));
2541 length = gtk_entry_buffer_get_length (get_buffer (entry));
2545 if (start_pos > length)
2548 if (end_pos <= start_pos)
2549 return g_strdup ("");
2550 else if (entry->visible)
2552 start = g_utf8_offset_to_pointer (text, start_pos);
2553 end = g_utf8_offset_to_pointer (start, end_pos - start_pos);
2554 return g_strndup (start, end - start);
2558 str = g_string_sized_new (length * 2);
2560 /* Figure out what our invisible char is and encode it */
2561 if (!entry->invisible_char)
2562 invisible_char = priv->invisible_char_set ? ' ' : '*';
2564 invisible_char = entry->invisible_char;
2565 char_len = g_unichar_to_utf8 (invisible_char, char_str);
2568 * Add hidden characters for each character in the text
2569 * buffer. If there is a password hint, then keep that
2570 * character visible.
2573 password_hint = g_object_get_qdata (G_OBJECT (entry), quark_password_hint);
2574 for (i = start_pos; i < end_pos; ++i)
2576 if (password_hint && i == password_hint->position)
2578 start = g_utf8_offset_to_pointer (text, i);
2579 g_string_append_len (str, start, g_utf8_next_char (start) - start);
2583 g_string_append_len (str, char_str, char_len);
2587 return g_string_free (str, FALSE);
2593 update_cursors (GtkWidget *widget)
2595 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2596 EntryIconInfo *icon_info = NULL;
2597 GdkDisplay *display;
2601 for (i = 0; i < MAX_ICONS; i++)
2603 if ((icon_info = priv->icons[i]) != NULL)
2605 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
2606 gdk_window_show_unraised (icon_info->window);
2608 /* The icon windows are not children of the visible entry window,
2609 * thus we can't just inherit the xterm cursor. Slight complication
2610 * here is that for the entry, insensitive => arrow cursor, but for
2611 * an icon in a sensitive entry, insensitive => xterm cursor.
2613 if (gtk_widget_is_sensitive (widget) &&
2614 (icon_info->insensitive ||
2615 (icon_info->nonactivatable && icon_info->target_list == NULL)))
2617 display = gtk_widget_get_display (widget);
2618 cursor = gdk_cursor_new_for_display (display, GDK_XTERM);
2619 gdk_window_set_cursor (icon_info->window, cursor);
2620 gdk_cursor_unref (cursor);
2624 gdk_window_set_cursor (icon_info->window, NULL);
2631 realize_icon_info (GtkWidget *widget,
2632 GtkEntryIconPosition icon_pos)
2634 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2635 EntryIconInfo *icon_info = priv->icons[icon_pos];
2636 GdkWindowAttr attributes;
2637 gint attributes_mask;
2639 g_return_if_fail (icon_info != NULL);
2643 attributes.width = 1;
2644 attributes.height = 1;
2645 attributes.window_type = GDK_WINDOW_CHILD;
2646 attributes.wclass = GDK_INPUT_OUTPUT;
2647 attributes.visual = gtk_widget_get_visual (widget);
2648 attributes.colormap = gtk_widget_get_colormap (widget);
2649 attributes.event_mask = gtk_widget_get_events (widget);
2650 attributes.event_mask |= (GDK_EXPOSURE_MASK |
2651 GDK_BUTTON_PRESS_MASK |
2652 GDK_BUTTON_RELEASE_MASK |
2653 GDK_BUTTON1_MOTION_MASK |
2654 GDK_BUTTON3_MOTION_MASK |
2655 GDK_POINTER_MOTION_HINT_MASK |
2656 GDK_POINTER_MOTION_MASK |
2657 GDK_ENTER_NOTIFY_MASK |
2658 GDK_LEAVE_NOTIFY_MASK);
2659 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
2661 icon_info->window = gdk_window_new (gtk_widget_get_window (widget),
2664 gdk_window_set_user_data (icon_info->window, widget);
2665 gdk_window_set_background (icon_info->window,
2666 >k_widget_get_style (widget)->base[gtk_widget_get_state (widget)]);
2668 gtk_widget_queue_resize (widget);
2671 static EntryIconInfo*
2672 construct_icon_info (GtkWidget *widget,
2673 GtkEntryIconPosition icon_pos)
2675 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2676 EntryIconInfo *icon_info;
2678 g_return_val_if_fail (priv->icons[icon_pos] == NULL, NULL);
2680 icon_info = g_slice_new0 (EntryIconInfo);
2681 priv->icons[icon_pos] = icon_info;
2683 if (gtk_widget_get_realized (widget))
2684 realize_icon_info (widget, icon_pos);
2690 gtk_entry_map (GtkWidget *widget)
2692 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2693 EntryIconInfo *icon_info = NULL;
2696 if (gtk_widget_get_realized (widget) && !gtk_widget_get_mapped (widget))
2698 GTK_WIDGET_CLASS (gtk_entry_parent_class)->map (widget);
2700 for (i = 0; i < MAX_ICONS; i++)
2702 if ((icon_info = priv->icons[i]) != NULL)
2704 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
2705 gdk_window_show (icon_info->window);
2709 update_cursors (widget);
2714 gtk_entry_unmap (GtkWidget *widget)
2716 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2717 EntryIconInfo *icon_info = NULL;
2720 if (gtk_widget_get_mapped (widget))
2722 for (i = 0; i < MAX_ICONS; i++)
2724 if ((icon_info = priv->icons[i]) != NULL)
2726 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
2727 gdk_window_hide (icon_info->window);
2731 GTK_WIDGET_CLASS (gtk_entry_parent_class)->unmap (widget);
2736 gtk_entry_realize (GtkWidget *widget)
2739 GtkEntryPrivate *priv;
2742 EntryIconInfo *icon_info;
2744 GdkWindowAttr attributes;
2745 gint attributes_mask;
2748 gtk_widget_set_realized (widget, TRUE);
2749 entry = GTK_ENTRY (widget);
2750 priv = GTK_ENTRY_GET_PRIVATE (entry);
2752 attributes.window_type = GDK_WINDOW_CHILD;
2754 get_widget_window_size (entry, &attributes.x, &attributes.y, &attributes.width, &attributes.height);
2756 attributes.wclass = GDK_INPUT_OUTPUT;
2757 attributes.visual = gtk_widget_get_visual (widget);
2758 attributes.colormap = gtk_widget_get_colormap (widget);
2759 attributes.event_mask = gtk_widget_get_events (widget);
2760 attributes.event_mask |= (GDK_EXPOSURE_MASK |
2761 GDK_BUTTON_PRESS_MASK |
2762 GDK_BUTTON_RELEASE_MASK |
2763 GDK_BUTTON1_MOTION_MASK |
2764 GDK_BUTTON3_MOTION_MASK |
2765 GDK_POINTER_MOTION_HINT_MASK |
2766 GDK_POINTER_MOTION_MASK |
2767 GDK_ENTER_NOTIFY_MASK |
2768 GDK_LEAVE_NOTIFY_MASK);
2769 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
2771 window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, attributes_mask);
2772 gtk_widget_set_window (widget, window);
2773 gdk_window_set_user_data (window, entry);
2775 get_text_area_size (entry, &attributes.x, &attributes.y, &attributes.width, &attributes.height);
2777 if (gtk_widget_is_sensitive (widget))
2779 attributes.cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
2780 attributes_mask |= GDK_WA_CURSOR;
2783 entry->text_area = gdk_window_new (window, &attributes, attributes_mask);
2785 gdk_window_set_user_data (entry->text_area, entry);
2787 if (attributes_mask & GDK_WA_CURSOR)
2788 gdk_cursor_unref (attributes.cursor);
2790 gtk_widget_style_attach (widget);
2792 style = gtk_widget_get_style (widget);
2793 state = gtk_widget_get_state (widget);
2794 gdk_window_set_background (window, &style->base[state]);
2795 gdk_window_set_background (entry->text_area, &style->base[state]);
2797 gdk_window_show (entry->text_area);
2799 gtk_im_context_set_client_window (entry->im_context, entry->text_area);
2801 gtk_entry_adjust_scroll (entry);
2802 gtk_entry_update_primary_selection (entry);
2805 /* If the icon positions are already setup, create their windows.
2806 * Otherwise if they don't exist yet, then construct_icon_info()
2807 * will create the windows once the widget is already realized.
2809 for (i = 0; i < MAX_ICONS; i++)
2811 if ((icon_info = priv->icons[i]) != NULL)
2813 if (icon_info->window == NULL)
2814 realize_icon_info (widget, i);
2820 gtk_entry_unrealize (GtkWidget *widget)
2822 GtkEntry *entry = GTK_ENTRY (widget);
2823 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2824 GtkClipboard *clipboard;
2825 EntryIconInfo *icon_info;
2828 gtk_entry_reset_layout (entry);
2830 gtk_im_context_set_client_window (entry->im_context, NULL);
2832 clipboard = gtk_widget_get_clipboard (widget, GDK_SELECTION_PRIMARY);
2833 if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (entry))
2834 gtk_clipboard_clear (clipboard);
2836 if (entry->text_area)
2838 gdk_window_set_user_data (entry->text_area, NULL);
2839 gdk_window_destroy (entry->text_area);
2840 entry->text_area = NULL;
2843 if (entry->popup_menu)
2845 gtk_widget_destroy (entry->popup_menu);
2846 entry->popup_menu = NULL;
2849 GTK_WIDGET_CLASS (gtk_entry_parent_class)->unrealize (widget);
2851 for (i = 0; i < MAX_ICONS; i++)
2853 if ((icon_info = priv->icons[i]) != NULL)
2855 if (icon_info->window != NULL)
2857 gdk_window_destroy (icon_info->window);
2858 icon_info->window = NULL;
2865 _gtk_entry_get_borders (GtkEntry *entry,
2869 GtkWidget *widget = GTK_WIDGET (entry);
2870 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2873 if (entry->has_frame)
2875 style = gtk_widget_get_style (widget);
2877 *xborder = style->xthickness;
2878 *yborder = style->ythickness;
2886 if (!priv->interior_focus)
2888 *xborder += priv->focus_width;
2889 *yborder += priv->focus_width;
2894 gtk_entry_size_request (GtkWidget *widget,
2895 GtkRequisition *requisition)
2897 GtkEntry *entry = GTK_ENTRY (widget);
2898 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2899 PangoFontMetrics *metrics;
2900 gint xborder, yborder;
2901 GtkBorder inner_border;
2902 PangoContext *context;
2903 int icon_widths = 0;
2906 gtk_widget_ensure_style (widget);
2907 context = gtk_widget_get_pango_context (widget);
2908 metrics = pango_context_get_metrics (context,
2909 gtk_widget_get_style (widget)->font_desc,
2910 pango_context_get_language (context));
2912 entry->ascent = pango_font_metrics_get_ascent (metrics);
2913 entry->descent = pango_font_metrics_get_descent (metrics);
2915 _gtk_entry_get_borders (entry, &xborder, &yborder);
2916 _gtk_entry_effective_inner_border (entry, &inner_border);
2918 if (entry->width_chars < 0)
2919 requisition->width = MIN_ENTRY_WIDTH + xborder * 2 + inner_border.left + inner_border.right;
2922 gint char_width = pango_font_metrics_get_approximate_char_width (metrics);
2923 gint digit_width = pango_font_metrics_get_approximate_digit_width (metrics);
2924 gint char_pixels = (MAX (char_width, digit_width) + PANGO_SCALE - 1) / PANGO_SCALE;
2926 requisition->width = char_pixels * entry->width_chars + xborder * 2 + inner_border.left + inner_border.right;
2929 requisition->height = PANGO_PIXELS (entry->ascent + entry->descent) + yborder * 2 + inner_border.top + inner_border.bottom;
2931 for (i = 0; i < MAX_ICONS; i++)
2933 icon_width = get_icon_width (entry, i);
2935 icon_widths += icon_width + 2 * priv->icon_margin;
2938 if (icon_widths > requisition->width)
2939 requisition->width += icon_widths;
2941 pango_font_metrics_unref (metrics);
2945 place_windows (GtkEntry *entry)
2947 GtkWidget *widget = GTK_WIDGET (entry);
2948 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2949 gint x, y, width, height;
2950 GtkAllocation primary;
2951 GtkAllocation secondary;
2952 EntryIconInfo *icon_info = NULL;
2954 get_text_area_size (entry, &x, &y, &width, &height);
2955 get_icon_allocations (entry, &primary, &secondary);
2957 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
2958 y += priv->focus_width;
2960 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
2961 x += secondary.width;
2964 width -= primary.width + secondary.width;
2966 if ((icon_info = priv->icons[GTK_ENTRY_ICON_PRIMARY]) != NULL)
2967 gdk_window_move_resize (icon_info->window,
2968 primary.x, primary.y,
2969 primary.width, primary.height);
2971 if ((icon_info = priv->icons[GTK_ENTRY_ICON_SECONDARY]) != NULL)
2972 gdk_window_move_resize (icon_info->window,
2973 secondary.x, secondary.y,
2974 secondary.width, secondary.height);
2976 gdk_window_move_resize (entry->text_area, x, y, width, height);
2980 gtk_entry_get_text_area_size (GtkEntry *entry,
2986 GtkWidget *widget = GTK_WIDGET (entry);
2987 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2988 GtkAllocation allocation;
2989 GtkRequisition requisition;
2991 gint xborder, yborder;
2993 gtk_widget_get_child_requisition (widget, &requisition);
2994 gtk_widget_get_allocation (widget, &allocation);
2995 _gtk_entry_get_borders (entry, &xborder, &yborder);
2997 if (gtk_widget_get_realized (widget))
2998 gdk_drawable_get_size (gtk_widget_get_window (widget), NULL, &frame_height);
3000 frame_height = requisition.height;
3002 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3003 frame_height -= 2 * priv->focus_width;
3009 *y = frame_height / 2 - (requisition.height - yborder * 2) / 2;
3012 *width = allocation.width - xborder * 2;
3015 *height = requisition.height - yborder * 2;
3019 get_text_area_size (GtkEntry *entry,
3025 GtkEntryClass *class;
3027 g_return_if_fail (GTK_IS_ENTRY (entry));
3029 class = GTK_ENTRY_GET_CLASS (entry);
3031 if (class->get_text_area_size)
3032 class->get_text_area_size (entry, x, y, width, height);
3037 get_widget_window_size (GtkEntry *entry,
3043 GtkAllocation allocation;
3044 GtkRequisition requisition;
3045 GtkWidget *widget = GTK_WIDGET (entry);
3047 gtk_widget_get_child_requisition (widget, &requisition);
3048 gtk_widget_get_allocation (widget, &allocation);
3055 if (entry->is_cell_renderer)
3058 *y = allocation.y + (allocation.height - requisition.height) / 2;
3062 *width = allocation.width;
3066 if (entry->is_cell_renderer)
3067 *height = allocation.height;
3069 *height = requisition.height;
3074 _gtk_entry_effective_inner_border (GtkEntry *entry,
3077 GtkBorder *tmp_border;
3079 tmp_border = g_object_get_qdata (G_OBJECT (entry), quark_inner_border);
3083 *border = *tmp_border;
3087 gtk_widget_style_get (GTK_WIDGET (entry), "inner-border", &tmp_border, NULL);
3091 *border = *tmp_border;
3092 gtk_border_free (tmp_border);
3096 *border = default_inner_border;
3100 gtk_entry_size_allocate (GtkWidget *widget,
3101 GtkAllocation *allocation)
3103 GtkEntry *entry = GTK_ENTRY (widget);
3105 gtk_widget_set_allocation (widget, allocation);
3107 if (gtk_widget_get_realized (widget))
3109 /* We call gtk_widget_get_child_requisition, since we want (for
3110 * backwards compatibility reasons) the realization here to
3111 * be affected by the usize of the entry, if set
3113 gint x, y, width, height;
3114 GtkEntryCompletion* completion;
3116 get_widget_window_size (entry, &x, &y, &width, &height);
3117 gdk_window_move_resize (gtk_widget_get_window (widget),
3118 x, y, width, height);
3120 place_windows (entry);
3121 gtk_entry_recompute (entry);
3123 completion = gtk_entry_get_completion (entry);
3124 if (completion && gtk_widget_get_mapped (completion->priv->popup_window))
3125 _gtk_entry_completion_resize_popup (completion);
3129 /* Kudos to the gnome-panel guys. */
3131 colorshift_pixbuf (GdkPixbuf *dest,
3136 gint width, height, has_alpha, src_rowstride, dest_rowstride;
3137 guchar *target_pixels;
3138 guchar *original_pixels;
3144 has_alpha = gdk_pixbuf_get_has_alpha (src);
3145 width = gdk_pixbuf_get_width (src);
3146 height = gdk_pixbuf_get_height (src);
3147 src_rowstride = gdk_pixbuf_get_rowstride (src);
3148 dest_rowstride = gdk_pixbuf_get_rowstride (dest);
3149 original_pixels = gdk_pixbuf_get_pixels (src);
3150 target_pixels = gdk_pixbuf_get_pixels (dest);
3152 for (i = 0; i < height; i++)
3154 pix_dest = target_pixels + i * dest_rowstride;
3155 pix_src = original_pixels + i * src_rowstride;
3157 for (j = 0; j < width; j++)
3164 *(pix_dest++) = CLAMP (val, 0, 255);
3167 *(pix_dest++) = CLAMP (val, 0, 255);
3170 *(pix_dest++) = CLAMP (val, 0, 255);
3173 *(pix_dest++) = *(pix_src++);
3179 should_prelight (GtkEntry *entry,
3180 GtkEntryIconPosition icon_pos)
3182 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3183 EntryIconInfo *icon_info = priv->icons[icon_pos];
3189 if (icon_info->nonactivatable && icon_info->target_list == NULL)
3192 if (icon_info->pressed)
3195 gtk_widget_style_get (GTK_WIDGET (entry),
3196 "icon-prelight", &prelight,
3203 draw_icon (GtkWidget *widget,
3204 GtkEntryIconPosition icon_pos)
3206 GtkEntry *entry = GTK_ENTRY (widget);
3207 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3208 EntryIconInfo *icon_info = priv->icons[icon_pos];
3210 gint x, y, width, height;
3216 gtk_entry_ensure_pixbuf (entry, icon_pos);
3218 if (icon_info->pixbuf == NULL)
3221 gdk_drawable_get_size (icon_info->window, &width, &height);
3223 /* size_allocate hasn't been called yet. These are the default values.
3225 if (width == 1 || height == 1)
3228 pixbuf = icon_info->pixbuf;
3229 g_object_ref (pixbuf);
3231 if (gdk_pixbuf_get_height (pixbuf) > height)
3233 GdkPixbuf *temp_pixbuf;
3236 scale = height - 2 * priv->icon_margin;
3237 temp_pixbuf = gdk_pixbuf_scale_simple (pixbuf, scale, scale,
3238 GDK_INTERP_BILINEAR);
3239 g_object_unref (pixbuf);
3240 pixbuf = temp_pixbuf;
3243 x = (width - gdk_pixbuf_get_width (pixbuf)) / 2;
3244 y = (height - gdk_pixbuf_get_height (pixbuf)) / 2;
3246 if (!gtk_widget_is_sensitive (widget) ||
3247 icon_info->insensitive)
3249 GdkPixbuf *temp_pixbuf;
3251 temp_pixbuf = gdk_pixbuf_copy (pixbuf);
3252 gdk_pixbuf_saturate_and_pixelate (pixbuf,
3256 g_object_unref (pixbuf);
3257 pixbuf = temp_pixbuf;
3259 else if (icon_info->prelight)
3261 GdkPixbuf *temp_pixbuf;
3263 temp_pixbuf = gdk_pixbuf_copy (pixbuf);
3264 colorshift_pixbuf (temp_pixbuf, pixbuf, 30);
3265 g_object_unref (pixbuf);
3266 pixbuf = temp_pixbuf;
3269 cr = gdk_cairo_create (icon_info->window);
3270 gdk_cairo_set_source_pixbuf (cr, pixbuf, x, y);
3274 g_object_unref (pixbuf);
3279 gtk_entry_draw_frame (GtkWidget *widget,
3280 GdkEventExpose *event)
3282 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
3285 gint x = 0, y = 0, width, height;
3288 window = gtk_widget_get_window (widget);
3290 gdk_drawable_get_size (window, &width, &height);
3292 /* Fix a problem with some themes which assume that entry->text_area's
3293 * width equals widget->window's width */
3294 if (GTK_IS_SPIN_BUTTON (widget))
3296 gint xborder, yborder;
3298 gtk_entry_get_text_area_size (GTK_ENTRY (widget), &x, NULL, &width, NULL);
3299 _gtk_entry_get_borders (GTK_ENTRY (widget), &xborder, &yborder);
3302 width += xborder * 2;
3305 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3307 x += priv->focus_width;
3308 y += priv->focus_width;
3309 width -= 2 * priv->focus_width;
3310 height -= 2 * priv->focus_width;
3313 style = gtk_widget_get_style (widget);
3314 state = gtk_widget_has_focus (widget) ?
3315 GTK_STATE_ACTIVE : gtk_widget_get_state (widget);
3317 gtk_paint_shadow (style, window,
3318 state, priv->shadow_type,
3319 &event->area, widget, "entry", x, y, width, height);
3322 gtk_entry_draw_progress (widget, event);
3324 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3326 x -= priv->focus_width;
3327 y -= priv->focus_width;
3328 width += 2 * priv->focus_width;
3329 height += 2 * priv->focus_width;
3331 gtk_paint_focus (style, window,
3332 gtk_widget_get_state (widget),
3333 &event->area, widget, "entry",
3334 0, 0, width, height);
3339 gtk_entry_get_progress_border (GtkWidget *widget,
3340 GtkBorder *progress_border)
3342 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 style = gtk_widget_get_style (widget);
3355 progress_border->left = style->xthickness;
3356 progress_border->right = style->xthickness;
3357 progress_border->top = style->ythickness;
3358 progress_border->bottom = style->ythickness;
3363 get_progress_area (GtkWidget *widget,
3369 GtkEntryPrivate *private = GTK_ENTRY_GET_PRIVATE (widget);
3370 GtkEntry *entry = GTK_ENTRY (widget);
3371 GtkBorder progress_border;
3373 gtk_entry_get_progress_border (widget, &progress_border);
3375 *x = progress_border.left;
3376 *y = progress_border.top;
3378 gdk_drawable_get_size (gtk_widget_get_window (widget), width, height);
3380 *width -= progress_border.left + progress_border.right;
3381 *height -= progress_border.top + progress_border.bottom;
3383 if (gtk_widget_has_focus (widget) && !private->interior_focus)
3385 *x += private->focus_width;
3386 *y += private->focus_width;
3387 *width -= 2 * private->focus_width;
3388 *height -= 2 * private->focus_width;
3391 if (private->progress_pulse_mode)
3393 gdouble value = private->progress_pulse_current;
3395 *x += (gint) floor(value * (*width));
3396 *width = (gint) ceil(private->progress_pulse_fraction * (*width));
3398 else if (private->progress_fraction > 0)
3400 gdouble value = private->progress_fraction;
3402 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
3406 bar_width = floor(value * (*width) + 0.5);
3407 *x += *width - bar_width;
3412 *width = (gint) floor(value * (*width) + 0.5);
3423 gtk_entry_draw_progress (GtkWidget *widget,
3424 GdkEventExpose *event)
3426 gint x, y, width, height;
3429 get_progress_area (widget, &x, &y, &width, &height);
3431 if ((width <= 0) || (height <= 0))
3434 if (event->window != gtk_widget_get_window (widget))
3438 gdk_window_get_position (event->window, &pos_x, &pos_y);
3444 state = GTK_STATE_SELECTED;
3445 if (!gtk_widget_get_sensitive (widget))
3446 state = GTK_STATE_INSENSITIVE;
3448 gtk_paint_box (gtk_widget_get_style (widget), event->window,
3449 state, GTK_SHADOW_OUT,
3450 &event->area, widget, "entry-progress",
3456 gtk_entry_expose (GtkWidget *widget,
3457 GdkEventExpose *event)
3459 GtkEntry *entry = GTK_ENTRY (widget);
3462 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3464 style = gtk_widget_get_style (widget);
3466 state = gtk_widget_has_focus (widget) ?
3467 GTK_STATE_ACTIVE : gtk_widget_get_state (widget);
3469 if (gtk_widget_get_window (widget) == 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 (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 (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))
4257 style = gtk_widget_get_style (widget);
4258 state = gtk_widget_get_state (widget);
4260 gdk_window_set_background (gtk_widget_get_window (widget),
4261 &style->base[state]);
4262 gdk_window_set_background (entry->text_area,
4263 &style->base[state]);
4264 for (i = 0; i < MAX_ICONS; i++)
4266 EntryIconInfo *icon_info = priv->icons[i];
4267 if (icon_info && icon_info->window)
4268 gdk_window_set_background (icon_info->window,
4269 &style->base[state]);
4272 if (gtk_widget_is_sensitive (widget))
4273 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
4277 gdk_window_set_cursor (entry->text_area, cursor);
4280 gdk_cursor_unref (cursor);
4282 entry->mouse_cursor_obscured = FALSE;
4284 update_cursors (widget);
4287 if (!gtk_widget_is_sensitive (widget))
4289 /* Clear any selection */
4290 gtk_editable_select_region (GTK_EDITABLE (entry), entry->current_pos, entry->current_pos);
4293 gtk_widget_queue_draw (widget);
4297 gtk_entry_screen_changed (GtkWidget *widget,
4298 GdkScreen *old_screen)
4300 gtk_entry_recompute (GTK_ENTRY (widget));
4303 /* GtkEditable method implementations
4306 gtk_entry_insert_text (GtkEditable *editable,
4307 const gchar *new_text,
4308 gint new_text_length,
4311 g_object_ref (editable);
4314 * The incoming text may a password or other secret. We make sure
4315 * not to copy it into temporary buffers.
4318 g_signal_emit_by_name (editable, "insert-text", new_text, new_text_length, position);
4320 g_object_unref (editable);
4324 gtk_entry_delete_text (GtkEditable *editable,
4328 g_object_ref (editable);
4330 g_signal_emit_by_name (editable, "delete-text", start_pos, end_pos);
4332 g_object_unref (editable);
4336 gtk_entry_get_chars (GtkEditable *editable,
4340 GtkEntry *entry = GTK_ENTRY (editable);
4343 gint start_index, end_index;
4345 text = gtk_entry_buffer_get_text (get_buffer (entry));
4346 text_length = gtk_entry_buffer_get_length (get_buffer (entry));
4349 end_pos = text_length;
4351 start_pos = MIN (text_length, start_pos);
4352 end_pos = MIN (text_length, end_pos);
4354 start_index = g_utf8_offset_to_pointer (text, start_pos) - text;
4355 end_index = g_utf8_offset_to_pointer (text, end_pos) - text;
4357 return g_strndup (text + start_index, end_index - start_index);
4361 gtk_entry_real_set_position (GtkEditable *editable,
4364 GtkEntry *entry = GTK_ENTRY (editable);
4368 length = gtk_entry_buffer_get_length (get_buffer (entry));
4369 if (position < 0 || position > length)
4372 if (position != entry->current_pos ||
4373 position != entry->selection_bound)
4375 _gtk_entry_reset_im_context (entry);
4376 gtk_entry_set_positions (entry, position, position);
4381 gtk_entry_get_position (GtkEditable *editable)
4383 return GTK_ENTRY (editable)->current_pos;
4387 gtk_entry_set_selection_bounds (GtkEditable *editable,
4391 GtkEntry *entry = GTK_ENTRY (editable);
4394 length = gtk_entry_buffer_get_length (get_buffer (entry));
4400 _gtk_entry_reset_im_context (entry);
4402 gtk_entry_set_positions (entry,
4404 MIN (start, length));
4406 gtk_entry_update_primary_selection (entry);
4410 gtk_entry_get_selection_bounds (GtkEditable *editable,
4414 GtkEntry *entry = GTK_ENTRY (editable);
4416 *start = entry->selection_bound;
4417 *end = entry->current_pos;
4419 return (entry->selection_bound != entry->current_pos);
4423 icon_theme_changed (GtkEntry *entry)
4425 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
4428 for (i = 0; i < MAX_ICONS; i++)
4430 EntryIconInfo *icon_info = priv->icons[i];
4431 if (icon_info != NULL)
4433 if (icon_info->storage_type == GTK_IMAGE_ICON_NAME)
4434 gtk_entry_set_icon_from_icon_name (entry, i, icon_info->icon_name);
4435 else if (icon_info->storage_type == GTK_IMAGE_STOCK)
4436 gtk_entry_set_icon_from_stock (entry, i, icon_info->stock_id);
4437 else if (icon_info->storage_type == GTK_IMAGE_GICON)
4438 gtk_entry_set_icon_from_gicon (entry, i, icon_info->gicon);
4442 gtk_widget_queue_draw (GTK_WIDGET (entry));
4446 icon_margin_changed (GtkEntry *entry)
4448 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
4451 _gtk_entry_effective_inner_border (GTK_ENTRY (entry), &border);
4453 priv->icon_margin = border.left;
4457 gtk_entry_style_set (GtkWidget *widget,
4458 GtkStyle *previous_style)
4460 GtkEntry *entry = GTK_ENTRY (widget);
4461 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
4463 gboolean interior_focus;
4466 gtk_widget_style_get (widget,
4467 "focus-line-width", &focus_width,
4468 "interior-focus", &interior_focus,
4471 priv->focus_width = focus_width;
4472 priv->interior_focus = interior_focus;
4474 if (!priv->invisible_char_set)
4475 entry->invisible_char = find_invisible_char (GTK_WIDGET (entry));
4477 gtk_entry_recompute (entry);
4479 if (previous_style && gtk_widget_get_realized (widget))
4483 style = gtk_widget_get_style (widget);
4485 gdk_window_set_background (gtk_widget_get_window (widget),
4486 &style->base[gtk_widget_get_state (widget)]);
4487 gdk_window_set_background (entry->text_area,
4488 &style->base[gtk_widget_get_state (widget)]);
4489 for (i = 0; i < MAX_ICONS; i++)
4491 EntryIconInfo *icon_info = priv->icons[i];
4492 if (icon_info && icon_info->window)
4493 gdk_window_set_background (icon_info->window,
4494 &style->base[gtk_widget_get_state (widget)]);
4498 icon_theme_changed (entry);
4499 icon_margin_changed (entry);
4502 /* GtkCellEditable method implementations
4505 gtk_cell_editable_entry_activated (GtkEntry *entry, gpointer data)
4507 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4508 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4512 gtk_cell_editable_key_press_event (GtkEntry *entry,
4513 GdkEventKey *key_event,
4516 if (key_event->keyval == GDK_Escape)
4518 entry->editing_canceled = TRUE;
4519 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4520 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4525 /* override focus */
4526 if (key_event->keyval == GDK_Up || key_event->keyval == GDK_Down)
4528 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4529 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4538 gtk_entry_start_editing (GtkCellEditable *cell_editable,
4541 GTK_ENTRY (cell_editable)->is_cell_renderer = TRUE;
4543 g_signal_connect (cell_editable, "activate",
4544 G_CALLBACK (gtk_cell_editable_entry_activated), NULL);
4545 g_signal_connect (cell_editable, "key-press-event",
4546 G_CALLBACK (gtk_cell_editable_key_press_event), NULL);
4550 gtk_entry_password_hint_free (GtkEntryPasswordHint *password_hint)
4552 if (password_hint->source_id)
4553 g_source_remove (password_hint->source_id);
4555 g_slice_free (GtkEntryPasswordHint, password_hint);
4560 gtk_entry_remove_password_hint (gpointer data)
4562 GtkEntryPasswordHint *password_hint = g_object_get_qdata (data, quark_password_hint);
4563 password_hint->position = -1;
4565 /* Force the string to be redrawn, but now without a visible character */
4566 gtk_entry_recompute (GTK_ENTRY (data));
4570 /* Default signal handlers
4573 gtk_entry_real_insert_text (GtkEditable *editable,
4574 const gchar *new_text,
4575 gint new_text_length,
4581 n_chars = g_utf8_strlen (new_text, new_text_length);
4584 * The actual insertion into the buffer. This will end up firing the
4585 * following signal handlers: buffer_inserted_text(), buffer_notify_display_text(),
4586 * buffer_notify_text(), buffer_notify_length()
4588 n_inserted = gtk_entry_buffer_insert_text (get_buffer (GTK_ENTRY (editable)), *position, new_text, n_chars);
4590 if (n_inserted != n_chars)
4591 gtk_widget_error_bell (GTK_WIDGET (editable));
4593 *position += n_inserted;
4597 gtk_entry_real_delete_text (GtkEditable *editable,
4602 * The actual deletion from the buffer. This will end up firing the
4603 * following signal handlers: buffer_deleted_text(), buffer_notify_display_text(),
4604 * buffer_notify_text(), buffer_notify_length()
4607 gtk_entry_buffer_delete_text (get_buffer (GTK_ENTRY (editable)), start_pos, end_pos - start_pos);
4610 /* GtkEntryBuffer signal handlers
4613 buffer_inserted_text (GtkEntryBuffer *buffer,
4619 guint password_hint_timeout;
4621 if (entry->current_pos > position)
4622 entry->current_pos += n_chars;
4624 if (entry->selection_bound > position)
4625 entry->selection_bound += n_chars;
4627 /* Calculate the password hint if it needs to be displayed. */
4628 if (n_chars == 1 && !entry->visible)
4630 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
4631 "gtk-entry-password-hint-timeout", &password_hint_timeout,
4634 if (password_hint_timeout > 0)
4636 GtkEntryPasswordHint *password_hint = g_object_get_qdata (G_OBJECT (entry),
4637 quark_password_hint);
4640 password_hint = g_slice_new0 (GtkEntryPasswordHint);
4641 g_object_set_qdata_full (G_OBJECT (entry), quark_password_hint, password_hint,
4642 (GDestroyNotify)gtk_entry_password_hint_free);
4645 password_hint->position = position;
4646 if (password_hint->source_id)
4647 g_source_remove (password_hint->source_id);
4648 password_hint->source_id = gdk_threads_add_timeout (password_hint_timeout,
4649 (GSourceFunc)gtk_entry_remove_password_hint, entry);
4655 buffer_deleted_text (GtkEntryBuffer *buffer,
4660 guint end_pos = position + n_chars;
4661 gint selection_bound;
4664 current_pos = entry->current_pos;
4665 if (current_pos > position)
4666 current_pos -= MIN (current_pos, end_pos) - position;
4668 selection_bound = entry->selection_bound;
4669 if (selection_bound > position)
4670 selection_bound -= MIN (selection_bound, end_pos) - position;
4672 gtk_entry_set_positions (entry, current_pos, selection_bound);
4674 /* We might have deleted the selection */
4675 gtk_entry_update_primary_selection (entry);
4677 /* Disable the password hint if one exists. */
4678 if (!entry->visible)
4680 GtkEntryPasswordHint *password_hint = g_object_get_qdata (G_OBJECT (entry),
4681 quark_password_hint);
4684 if (password_hint->source_id)
4685 g_source_remove (password_hint->source_id);
4686 password_hint->source_id = 0;
4687 password_hint->position = -1;
4693 buffer_notify_text (GtkEntryBuffer *buffer,
4697 gtk_entry_recompute (entry);
4698 emit_changed (entry);
4699 g_object_notify (G_OBJECT (entry), "text");
4703 buffer_notify_length (GtkEntryBuffer *buffer,
4707 g_object_notify (G_OBJECT (entry), "text-length");
4711 buffer_notify_max_length (GtkEntryBuffer *buffer,
4715 g_object_notify (G_OBJECT (entry), "max-length");
4719 buffer_connect_signals (GtkEntry *entry)
4721 g_signal_connect (get_buffer (entry), "inserted-text", G_CALLBACK (buffer_inserted_text), entry);
4722 g_signal_connect (get_buffer (entry), "deleted-text", G_CALLBACK (buffer_deleted_text), entry);
4723 g_signal_connect (get_buffer (entry), "notify::text", G_CALLBACK (buffer_notify_text), entry);
4724 g_signal_connect (get_buffer (entry), "notify::length", G_CALLBACK (buffer_notify_length), entry);
4725 g_signal_connect (get_buffer (entry), "notify::max-length", G_CALLBACK (buffer_notify_max_length), entry);
4729 buffer_disconnect_signals (GtkEntry *entry)
4731 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_inserted_text, entry);
4732 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_deleted_text, entry);
4733 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_text, entry);
4734 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_length, entry);
4735 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_max_length, entry);
4738 /* Compute the X position for an offset that corresponds to the "more important
4739 * cursor position for that offset. We use this when trying to guess to which
4740 * end of the selection we should go to when the user hits the left or
4744 get_better_cursor_x (GtkEntry *entry,
4747 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
4748 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
4749 gboolean split_cursor;
4751 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
4752 const gchar *text = pango_layout_get_text (layout);
4753 gint index = g_utf8_offset_to_pointer (text, offset) - text;
4755 PangoRectangle strong_pos, weak_pos;
4757 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
4758 "gtk-split-cursor", &split_cursor,
4761 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
4764 return strong_pos.x / PANGO_SCALE;
4766 return (keymap_direction == entry->resolved_dir) ? strong_pos.x / PANGO_SCALE : weak_pos.x / PANGO_SCALE;
4770 gtk_entry_move_cursor (GtkEntry *entry,
4771 GtkMovementStep step,
4773 gboolean extend_selection)
4775 gint new_pos = entry->current_pos;
4776 GtkEntryPrivate *priv;
4778 _gtk_entry_reset_im_context (entry);
4780 if (entry->current_pos != entry->selection_bound && !extend_selection)
4782 /* If we have a current selection and aren't extending it, move to the
4783 * start/or end of the selection as appropriate
4787 case GTK_MOVEMENT_VISUAL_POSITIONS:
4789 gint current_x = get_better_cursor_x (entry, entry->current_pos);
4790 gint bound_x = get_better_cursor_x (entry, entry->selection_bound);
4793 new_pos = current_x < bound_x ? entry->current_pos : entry->selection_bound;
4795 new_pos = current_x > bound_x ? entry->current_pos : entry->selection_bound;
4798 case GTK_MOVEMENT_LOGICAL_POSITIONS:
4799 case GTK_MOVEMENT_WORDS:
4801 new_pos = MIN (entry->current_pos, entry->selection_bound);
4803 new_pos = MAX (entry->current_pos, entry->selection_bound);
4805 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
4806 case GTK_MOVEMENT_PARAGRAPH_ENDS:
4807 case GTK_MOVEMENT_BUFFER_ENDS:
4808 priv = GTK_ENTRY_GET_PRIVATE (entry);
4809 new_pos = count < 0 ? 0 : gtk_entry_buffer_get_length (get_buffer (entry));
4811 case GTK_MOVEMENT_DISPLAY_LINES:
4812 case GTK_MOVEMENT_PARAGRAPHS:
4813 case GTK_MOVEMENT_PAGES:
4814 case GTK_MOVEMENT_HORIZONTAL_PAGES:
4822 case GTK_MOVEMENT_LOGICAL_POSITIONS:
4823 new_pos = gtk_entry_move_logically (entry, new_pos, count);
4825 case GTK_MOVEMENT_VISUAL_POSITIONS:
4826 new_pos = gtk_entry_move_visually (entry, new_pos, count);
4827 if (entry->current_pos == new_pos)
4829 if (!extend_selection)
4831 if (!gtk_widget_keynav_failed (GTK_WIDGET (entry),
4833 GTK_DIR_RIGHT : GTK_DIR_LEFT))
4835 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (entry));
4838 gtk_widget_child_focus (toplevel,
4840 GTK_DIR_RIGHT : GTK_DIR_LEFT);
4845 gtk_widget_error_bell (GTK_WIDGET (entry));
4849 case GTK_MOVEMENT_WORDS:
4852 new_pos = gtk_entry_move_forward_word (entry, new_pos, FALSE);
4857 new_pos = gtk_entry_move_backward_word (entry, new_pos, FALSE);
4860 if (entry->current_pos == new_pos)
4861 gtk_widget_error_bell (GTK_WIDGET (entry));
4863 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
4864 case GTK_MOVEMENT_PARAGRAPH_ENDS:
4865 case GTK_MOVEMENT_BUFFER_ENDS:
4866 priv = GTK_ENTRY_GET_PRIVATE (entry);
4867 new_pos = count < 0 ? 0 : gtk_entry_buffer_get_length (get_buffer (entry));
4868 if (entry->current_pos == new_pos)
4869 gtk_widget_error_bell (GTK_WIDGET (entry));
4871 case GTK_MOVEMENT_DISPLAY_LINES:
4872 case GTK_MOVEMENT_PARAGRAPHS:
4873 case GTK_MOVEMENT_PAGES:
4874 case GTK_MOVEMENT_HORIZONTAL_PAGES:
4879 if (extend_selection)
4880 gtk_editable_select_region (GTK_EDITABLE (entry), entry->selection_bound, new_pos);
4882 gtk_editable_set_position (GTK_EDITABLE (entry), new_pos);
4884 gtk_entry_pend_cursor_blink (entry);
4888 gtk_entry_insert_at_cursor (GtkEntry *entry,
4891 GtkEditable *editable = GTK_EDITABLE (entry);
4892 gint pos = entry->current_pos;
4894 if (entry->editable)
4896 _gtk_entry_reset_im_context (entry);
4898 gtk_editable_insert_text (editable, str, -1, &pos);
4899 gtk_editable_set_position (editable, pos);
4904 gtk_entry_delete_from_cursor (GtkEntry *entry,
4908 GtkEditable *editable = GTK_EDITABLE (entry);
4909 gint start_pos = entry->current_pos;
4910 gint end_pos = entry->current_pos;
4911 gint old_n_bytes = gtk_entry_buffer_get_bytes (get_buffer (entry));
4913 _gtk_entry_reset_im_context (entry);
4915 if (!entry->editable)
4917 gtk_widget_error_bell (GTK_WIDGET (entry));
4921 if (entry->selection_bound != entry->current_pos)
4923 gtk_editable_delete_selection (editable);
4929 case GTK_DELETE_CHARS:
4930 end_pos = gtk_entry_move_logically (entry, entry->current_pos, count);
4931 gtk_editable_delete_text (editable, MIN (start_pos, end_pos), MAX (start_pos, end_pos));
4933 case GTK_DELETE_WORDS:
4936 /* Move to end of current word, or if not on a word, end of previous word */
4937 end_pos = gtk_entry_move_backward_word (entry, end_pos, FALSE);
4938 end_pos = gtk_entry_move_forward_word (entry, end_pos, FALSE);
4942 /* Move to beginning of current word, or if not on a word, begining of next word */
4943 start_pos = gtk_entry_move_forward_word (entry, start_pos, FALSE);
4944 start_pos = gtk_entry_move_backward_word (entry, start_pos, FALSE);
4948 case GTK_DELETE_WORD_ENDS:
4951 start_pos = gtk_entry_move_backward_word (entry, start_pos, FALSE);
4956 end_pos = gtk_entry_move_forward_word (entry, end_pos, FALSE);
4959 gtk_editable_delete_text (editable, start_pos, end_pos);
4961 case GTK_DELETE_DISPLAY_LINE_ENDS:
4962 case GTK_DELETE_PARAGRAPH_ENDS:
4964 gtk_editable_delete_text (editable, 0, entry->current_pos);
4966 gtk_editable_delete_text (editable, entry->current_pos, -1);
4968 case GTK_DELETE_DISPLAY_LINES:
4969 case GTK_DELETE_PARAGRAPHS:
4970 gtk_editable_delete_text (editable, 0, -1);
4972 case GTK_DELETE_WHITESPACE:
4973 gtk_entry_delete_whitespace (entry);
4977 if (gtk_entry_buffer_get_bytes (get_buffer (entry)) == old_n_bytes)
4978 gtk_widget_error_bell (GTK_WIDGET (entry));
4980 gtk_entry_pend_cursor_blink (entry);
4984 gtk_entry_backspace (GtkEntry *entry)
4986 GtkEditable *editable = GTK_EDITABLE (entry);
4989 _gtk_entry_reset_im_context (entry);
4991 if (!entry->editable)
4993 gtk_widget_error_bell (GTK_WIDGET (entry));
4997 if (entry->selection_bound != entry->current_pos)
4999 gtk_editable_delete_selection (editable);
5003 prev_pos = gtk_entry_move_logically (entry, entry->current_pos, -1);
5005 if (prev_pos < entry->current_pos)
5007 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
5008 PangoLogAttr *log_attrs;
5011 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
5013 /* Deleting parts of characters */
5014 if (log_attrs[entry->current_pos].backspace_deletes_character)
5016 gchar *cluster_text;
5017 gchar *normalized_text;
5020 cluster_text = gtk_entry_get_display_text (entry, prev_pos,
5021 entry->current_pos);
5022 normalized_text = g_utf8_normalize (cluster_text,
5023 strlen (cluster_text),
5025 len = g_utf8_strlen (normalized_text, -1);
5027 gtk_editable_delete_text (editable, prev_pos, entry->current_pos);
5030 gint pos = entry->current_pos;
5032 gtk_editable_insert_text (editable, normalized_text,
5033 g_utf8_offset_to_pointer (normalized_text, len - 1) - normalized_text,
5035 gtk_editable_set_position (editable, pos);
5038 g_free (normalized_text);
5039 g_free (cluster_text);
5043 gtk_editable_delete_text (editable, prev_pos, entry->current_pos);
5050 gtk_widget_error_bell (GTK_WIDGET (entry));
5053 gtk_entry_pend_cursor_blink (entry);
5057 gtk_entry_copy_clipboard (GtkEntry *entry)
5059 GtkEditable *editable = GTK_EDITABLE (entry);
5063 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5065 if (!entry->visible)
5067 gtk_widget_error_bell (GTK_WIDGET (entry));
5071 str = gtk_entry_get_display_text (entry, start, end);
5072 gtk_clipboard_set_text (gtk_widget_get_clipboard (GTK_WIDGET (entry),
5073 GDK_SELECTION_CLIPBOARD),
5080 gtk_entry_cut_clipboard (GtkEntry *entry)
5082 GtkEditable *editable = GTK_EDITABLE (entry);
5085 if (!entry->visible)
5087 gtk_widget_error_bell (GTK_WIDGET (entry));
5091 gtk_entry_copy_clipboard (entry);
5093 if (entry->editable)
5095 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5096 gtk_editable_delete_text (editable, start, end);
5100 gtk_widget_error_bell (GTK_WIDGET (entry));
5105 gtk_entry_paste_clipboard (GtkEntry *entry)
5107 if (entry->editable)
5108 gtk_entry_paste (entry, GDK_NONE);
5110 gtk_widget_error_bell (GTK_WIDGET (entry));
5114 gtk_entry_delete_cb (GtkEntry *entry)
5116 GtkEditable *editable = GTK_EDITABLE (entry);
5119 if (entry->editable)
5121 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5122 gtk_editable_delete_text (editable, start, end);
5127 gtk_entry_toggle_overwrite (GtkEntry *entry)
5129 entry->overwrite_mode = !entry->overwrite_mode;
5130 gtk_entry_pend_cursor_blink (entry);
5131 gtk_widget_queue_draw (GTK_WIDGET (entry));
5135 gtk_entry_select_all (GtkEntry *entry)
5137 gtk_entry_select_line (entry);
5141 gtk_entry_real_activate (GtkEntry *entry)
5144 GtkWidget *default_widget, *focus_widget;
5145 GtkWidget *toplevel;
5148 widget = GTK_WIDGET (entry);
5150 if (entry->activates_default)
5152 toplevel = gtk_widget_get_toplevel (widget);
5153 if (GTK_IS_WINDOW (toplevel))
5155 window = GTK_WINDOW (toplevel);
5159 default_widget = gtk_window_get_default_widget (window);
5160 focus_widget = gtk_window_get_focus (window);
5161 if (widget != default_widget &&
5162 !(widget == focus_widget && (!default_widget || !gtk_widget_get_sensitive (default_widget))))
5163 gtk_window_activate_default (window);
5170 keymap_direction_changed (GdkKeymap *keymap,
5173 gtk_entry_recompute (entry);
5176 /* IM Context Callbacks
5180 gtk_entry_commit_cb (GtkIMContext *context,
5184 if (entry->editable)
5185 gtk_entry_enter_text (entry, str);
5189 gtk_entry_preedit_changed_cb (GtkIMContext *context,
5192 if (entry->editable)
5194 gchar *preedit_string;
5197 gtk_im_context_get_preedit_string (entry->im_context,
5198 &preedit_string, NULL,
5200 g_signal_emit (entry, signals[PREEDIT_CHANGED], 0, preedit_string);
5201 entry->preedit_length = strlen (preedit_string);
5202 cursor_pos = CLAMP (cursor_pos, 0, g_utf8_strlen (preedit_string, -1));
5203 entry->preedit_cursor = cursor_pos;
5204 g_free (preedit_string);
5206 gtk_entry_recompute (entry);
5211 gtk_entry_retrieve_surrounding_cb (GtkIMContext *context,
5216 /* XXXX ??? does this even make sense when text is not visible? Should we return FALSE? */
5217 text = gtk_entry_get_display_text (entry, 0, -1);
5218 gtk_im_context_set_surrounding (context, text, strlen (text), /* Length in bytes */
5219 g_utf8_offset_to_pointer (text, entry->current_pos) - text);
5226 gtk_entry_delete_surrounding_cb (GtkIMContext *slave,
5231 if (entry->editable)
5232 gtk_editable_delete_text (GTK_EDITABLE (entry),
5233 entry->current_pos + offset,
5234 entry->current_pos + offset + n_chars);
5239 /* Internal functions
5242 /* Used for im_commit_cb and inserting Unicode chars */
5244 gtk_entry_enter_text (GtkEntry *entry,
5247 GtkEditable *editable = GTK_EDITABLE (entry);
5249 gboolean old_need_im_reset;
5251 old_need_im_reset = entry->need_im_reset;
5252 entry->need_im_reset = FALSE;
5254 if (gtk_editable_get_selection_bounds (editable, NULL, NULL))
5255 gtk_editable_delete_selection (editable);
5258 if (entry->overwrite_mode)
5259 gtk_entry_delete_from_cursor (entry, GTK_DELETE_CHARS, 1);
5262 tmp_pos = entry->current_pos;
5263 gtk_editable_insert_text (editable, str, strlen (str), &tmp_pos);
5264 gtk_editable_set_position (editable, tmp_pos);
5266 entry->need_im_reset = old_need_im_reset;
5269 /* All changes to entry->current_pos and entry->selection_bound
5270 * should go through this function.
5273 gtk_entry_set_positions (GtkEntry *entry,
5275 gint selection_bound)
5277 gboolean changed = FALSE;
5279 g_object_freeze_notify (G_OBJECT (entry));
5281 if (current_pos != -1 &&
5282 entry->current_pos != current_pos)
5284 entry->current_pos = current_pos;
5287 g_object_notify (G_OBJECT (entry), "cursor-position");
5290 if (selection_bound != -1 &&
5291 entry->selection_bound != selection_bound)
5293 entry->selection_bound = selection_bound;
5296 g_object_notify (G_OBJECT (entry), "selection-bound");
5299 g_object_thaw_notify (G_OBJECT (entry));
5303 gtk_entry_move_adjustments (entry);
5304 gtk_entry_recompute (entry);
5309 gtk_entry_reset_layout (GtkEntry *entry)
5311 if (entry->cached_layout)
5313 g_object_unref (entry->cached_layout);
5314 entry->cached_layout = NULL;
5319 update_im_cursor_location (GtkEntry *entry)
5323 gint strong_xoffset;
5324 gint area_width, area_height;
5326 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
5327 gtk_entry_get_text_area_size (entry, NULL, NULL, &area_width, &area_height);
5329 strong_xoffset = strong_x - entry->scroll_offset;
5330 if (strong_xoffset < 0)
5334 else if (strong_xoffset > area_width)
5336 strong_xoffset = area_width;
5338 area.x = strong_xoffset;
5341 area.height = area_height;
5343 gtk_im_context_set_cursor_location (entry->im_context, &area);
5347 recompute_idle_func (gpointer data)
5351 entry = GTK_ENTRY (data);
5353 entry->recompute_idle = 0;
5355 if (gtk_widget_has_screen (GTK_WIDGET (entry)))
5357 gtk_entry_adjust_scroll (entry);
5358 gtk_entry_queue_draw (entry);
5360 update_im_cursor_location (entry);
5367 gtk_entry_recompute (GtkEntry *entry)
5369 gtk_entry_reset_layout (entry);
5370 gtk_entry_check_cursor_blink (entry);
5372 if (!entry->recompute_idle)
5374 entry->recompute_idle = gdk_threads_add_idle_full (G_PRIORITY_HIGH_IDLE + 15, /* between resize and redraw */
5375 recompute_idle_func, entry, NULL);
5379 static PangoLayout *
5380 gtk_entry_create_layout (GtkEntry *entry,
5381 gboolean include_preedit)
5383 GtkWidget *widget = GTK_WIDGET (entry);
5384 PangoLayout *layout = gtk_widget_create_pango_layout (widget, NULL);
5385 PangoAttrList *tmp_attrs = pango_attr_list_new ();
5387 gchar *preedit_string = NULL;
5388 gint preedit_length = 0;
5389 PangoAttrList *preedit_attrs = NULL;
5394 pango_layout_set_single_paragraph_mode (layout, TRUE);
5396 display = gtk_entry_get_display_text (entry, 0, -1);
5397 n_bytes = strlen (display);
5399 if (include_preedit)
5401 gtk_im_context_get_preedit_string (entry->im_context,
5402 &preedit_string, &preedit_attrs, NULL);
5403 preedit_length = entry->preedit_length;
5408 GString *tmp_string = g_string_new (display);
5409 gint cursor_index = g_utf8_offset_to_pointer (display, entry->current_pos) - display;
5411 g_string_insert (tmp_string, cursor_index, preedit_string);
5413 pango_layout_set_text (layout, tmp_string->str, tmp_string->len);
5415 pango_attr_list_splice (tmp_attrs, preedit_attrs,
5416 cursor_index, preedit_length);
5418 g_string_free (tmp_string, TRUE);
5422 PangoDirection pango_dir;
5424 if (gtk_entry_get_display_mode (entry) == DISPLAY_NORMAL)
5425 pango_dir = pango_find_base_dir (display, n_bytes);
5427 pango_dir = PANGO_DIRECTION_NEUTRAL;
5429 if (pango_dir == PANGO_DIRECTION_NEUTRAL)
5431 if (gtk_widget_has_focus (widget))
5433 GdkDisplay *display = gtk_widget_get_display (widget);
5434 GdkKeymap *keymap = gdk_keymap_get_for_display (display);
5435 if (gdk_keymap_get_direction (keymap) == PANGO_DIRECTION_RTL)
5436 pango_dir = PANGO_DIRECTION_RTL;
5438 pango_dir = PANGO_DIRECTION_LTR;
5442 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
5443 pango_dir = PANGO_DIRECTION_RTL;
5445 pango_dir = PANGO_DIRECTION_LTR;
5449 pango_context_set_base_dir (gtk_widget_get_pango_context (widget),
5452 entry->resolved_dir = pango_dir;
5454 pango_layout_set_text (layout, display, n_bytes);
5457 pango_layout_set_attributes (layout, tmp_attrs);
5459 g_free (preedit_string);
5463 pango_attr_list_unref (preedit_attrs);
5465 pango_attr_list_unref (tmp_attrs);
5470 static PangoLayout *
5471 gtk_entry_ensure_layout (GtkEntry *entry,
5472 gboolean include_preedit)
5474 if (entry->preedit_length > 0 &&
5475 !include_preedit != !entry->cache_includes_preedit)
5476 gtk_entry_reset_layout (entry);
5478 if (!entry->cached_layout)
5480 entry->cached_layout = gtk_entry_create_layout (entry, include_preedit);
5481 entry->cache_includes_preedit = include_preedit;
5484 return entry->cached_layout;
5488 get_layout_position (GtkEntry *entry,
5492 PangoLayout *layout;
5493 PangoRectangle logical_rect;
5494 gint area_width, area_height;
5495 GtkBorder inner_border;
5497 PangoLayoutLine *line;
5499 layout = gtk_entry_ensure_layout (entry, TRUE);
5501 gtk_entry_get_text_area_size (entry, NULL, NULL, &area_width, &area_height);
5502 _gtk_entry_effective_inner_border (entry, &inner_border);
5504 area_height = PANGO_SCALE * (area_height - inner_border.top - inner_border.bottom);
5506 line = pango_layout_get_lines_readonly (layout)->data;
5507 pango_layout_line_get_extents (line, NULL, &logical_rect);
5509 /* Align primarily for locale's ascent/descent */
5510 y_pos = ((area_height - entry->ascent - entry->descent) / 2 +
5511 entry->ascent + logical_rect.y);
5513 /* Now see if we need to adjust to fit in actual drawn string */
5514 if (logical_rect.height > area_height)
5515 y_pos = (area_height - logical_rect.height) / 2;
5518 else if (y_pos + logical_rect.height > area_height)
5519 y_pos = area_height - logical_rect.height;
5521 y_pos = inner_border.top + y_pos / PANGO_SCALE;
5524 *x = inner_border.left - entry->scroll_offset;
5531 draw_text_with_color (GtkEntry *entry, cairo_t *cr, GdkColor *default_color)
5533 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
5536 gint start_pos, end_pos;
5538 widget = GTK_WIDGET (entry);
5542 get_layout_position (entry, &x, &y);
5544 cairo_move_to (cr, x, y);
5545 gdk_cairo_set_source_color (cr, default_color);
5546 pango_cairo_show_layout (cr, layout);
5548 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start_pos, &end_pos))
5552 PangoRectangle logical_rect;
5553 GdkColor *selection_color, *text_color;
5554 GtkBorder inner_border;
5557 pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
5558 gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
5560 style = gtk_widget_get_style (widget);
5562 if (gtk_widget_has_focus (widget))
5564 selection_color = &style->base [GTK_STATE_SELECTED];
5565 text_color = &style->text [GTK_STATE_SELECTED];
5569 selection_color = &style->base [GTK_STATE_ACTIVE];
5570 text_color = &style->text [GTK_STATE_ACTIVE];
5573 _gtk_entry_effective_inner_border (entry, &inner_border);
5575 for (i = 0; i < n_ranges; ++i)
5576 cairo_rectangle (cr,
5577 inner_border.left - entry->scroll_offset + ranges[2 * i],
5580 logical_rect.height);
5584 gdk_cairo_set_source_color (cr, selection_color);
5587 cairo_move_to (cr, x, y);
5588 gdk_cairo_set_source_color (cr, text_color);
5589 pango_cairo_show_layout (cr, layout);
5597 gtk_entry_draw_text (GtkEntry *entry)
5599 GtkWidget *widget = GTK_WIDGET (entry);
5602 /* Nothing to display at all */
5603 if (gtk_entry_get_display_mode (entry) == DISPLAY_BLANK)
5606 if (gtk_widget_is_drawable (widget))
5610 GdkColor text_color, bar_text_color;
5613 gint progress_x, progress_y, progress_width, progress_height;
5615 state = GTK_STATE_SELECTED;
5616 if (!gtk_widget_get_sensitive (widget))
5617 state = GTK_STATE_INSENSITIVE;
5618 style = gtk_widget_get_style (widget);
5619 text_color = style->text[gtk_widget_get_state (widget)];
5620 bar_text_color = style->fg[state];
5622 get_progress_area (widget,
5623 &progress_x, &progress_y,
5624 &progress_width, &progress_height);
5626 cr = gdk_cairo_create (entry->text_area);
5628 /* If the color is the same, or the progress area has a zero
5629 * size, then we only need to draw once. */
5630 if ((text_color.pixel == bar_text_color.pixel) ||
5631 ((progress_width == 0) || (progress_height == 0)))
5633 draw_text_with_color (entry, cr, &text_color);
5637 gdk_drawable_get_size (entry->text_area, &width, &height);
5639 cairo_rectangle (cr, 0, 0, width, height);
5643 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
5644 cairo_rectangle (cr, 0, 0, width, height);
5646 gdk_window_get_position (entry->text_area, &pos_x, &pos_y);
5647 progress_x -= pos_x;
5648 progress_y -= pos_y;
5650 cairo_rectangle (cr, progress_x, progress_y,
5651 progress_width, progress_height);
5653 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_WINDING);
5655 draw_text_with_color (entry, cr, &text_color);
5658 cairo_rectangle (cr, progress_x, progress_y,
5659 progress_width, progress_height);
5662 draw_text_with_color (entry, cr, &bar_text_color);
5670 draw_insertion_cursor (GtkEntry *entry,
5671 GdkRectangle *cursor_location,
5672 gboolean is_primary,
5673 PangoDirection direction,
5674 gboolean draw_arrow)
5676 GtkWidget *widget = GTK_WIDGET (entry);
5677 GtkTextDirection text_dir;
5679 if (direction == PANGO_DIRECTION_LTR)
5680 text_dir = GTK_TEXT_DIR_LTR;
5682 text_dir = GTK_TEXT_DIR_RTL;
5684 gtk_draw_insertion_cursor (widget, entry->text_area, NULL,
5686 is_primary, text_dir, draw_arrow);
5690 gtk_entry_draw_cursor (GtkEntry *entry,
5693 GtkWidget *widget = GTK_WIDGET (entry);
5694 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
5695 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
5697 if (gtk_widget_is_drawable (widget))
5699 GdkRectangle cursor_location;
5700 gboolean split_cursor;
5701 PangoRectangle cursor_rect;
5702 GtkBorder inner_border;
5704 gint text_area_height;
5707 gboolean block_at_line_end;
5708 PangoLayout *layout;
5711 _gtk_entry_effective_inner_border (entry, &inner_border);
5713 xoffset = inner_border.left - entry->scroll_offset;
5715 gdk_drawable_get_size (entry->text_area, NULL, &text_area_height);
5717 layout = gtk_entry_ensure_layout (entry, TRUE);
5718 text = pango_layout_get_text (layout);
5719 cursor_index = g_utf8_offset_to_pointer (text, entry->current_pos + entry->preedit_cursor) - text;
5720 if (!entry->overwrite_mode)
5723 block = _gtk_text_util_get_block_cursor_location (layout,
5724 cursor_index, &cursor_rect, &block_at_line_end);
5728 gint strong_x, weak_x;
5729 PangoDirection dir1 = PANGO_DIRECTION_NEUTRAL;
5730 PangoDirection dir2 = PANGO_DIRECTION_NEUTRAL;
5734 gtk_entry_get_cursor_locations (entry, type, &strong_x, &weak_x);
5736 g_object_get (gtk_widget_get_settings (widget),
5737 "gtk-split-cursor", &split_cursor,
5740 dir1 = entry->resolved_dir;
5746 if (weak_x != strong_x)
5748 dir2 = (entry->resolved_dir == PANGO_DIRECTION_LTR) ? PANGO_DIRECTION_RTL : PANGO_DIRECTION_LTR;
5754 if (keymap_direction == entry->resolved_dir)
5760 cursor_location.x = xoffset + x1;
5761 cursor_location.y = inner_border.top;
5762 cursor_location.width = 0;
5763 cursor_location.height = text_area_height - inner_border.top - inner_border.bottom;
5765 draw_insertion_cursor (entry,
5766 &cursor_location, TRUE, dir1,
5767 dir2 != PANGO_DIRECTION_NEUTRAL);
5769 if (dir2 != PANGO_DIRECTION_NEUTRAL)
5771 cursor_location.x = xoffset + x2;
5772 draw_insertion_cursor (entry,
5773 &cursor_location, FALSE, dir2,
5777 else /* overwrite_mode */
5779 GdkColor cursor_color;
5784 get_layout_position (entry, &x, &y);
5786 rect.x = PANGO_PIXELS (cursor_rect.x) + x;
5787 rect.y = PANGO_PIXELS (cursor_rect.y) + y;
5788 rect.width = PANGO_PIXELS (cursor_rect.width);
5789 rect.height = PANGO_PIXELS (cursor_rect.height);
5791 cr = gdk_cairo_create (entry->text_area);
5793 _gtk_widget_get_cursor_color (widget, &cursor_color);
5794 gdk_cairo_set_source_color (cr, &cursor_color);
5795 gdk_cairo_rectangle (cr, &rect);
5798 if (!block_at_line_end)
5800 gdk_cairo_rectangle (cr, &rect);
5802 cairo_move_to (cr, x, y);
5803 gdk_cairo_set_source_color (cr, >k_widget_get_style (widget)->base[gtk_widget_get_state (widget)]);
5804 pango_cairo_show_layout (cr, layout);
5813 gtk_entry_queue_draw (GtkEntry *entry)
5815 if (gtk_widget_is_drawable (GTK_WIDGET (entry)))
5816 gdk_window_invalidate_rect (entry->text_area, NULL, FALSE);
5820 _gtk_entry_reset_im_context (GtkEntry *entry)
5822 if (entry->need_im_reset)
5824 entry->need_im_reset = FALSE;
5825 gtk_im_context_reset (entry->im_context);
5830 * gtk_entry_reset_im_context:
5831 * @entry: a #GtkEntry
5833 * Reset the input method context of the entry if needed.
5835 * This can be necessary in the case where modifying the buffer
5836 * would confuse on-going input method behavior.
5841 gtk_entry_reset_im_context (GtkEntry *entry)
5843 g_return_if_fail (GTK_IS_ENTRY (entry));
5845 _gtk_entry_reset_im_context (entry);
5849 * gtk_entry_im_context_filter_keypress:
5850 * @entry: a #GtkEntry
5851 * @event: the key event
5853 * Allow the #GtkEntry input method to internally handle key press
5854 * and release events. If this function returns %TRUE, then no further
5855 * processing should be done for this key event. See
5856 * gtk_im_context_filter_keypress().
5858 * Note that you are expected to call this function from your handler
5859 * when overriding key event handling. This is needed in the case when
5860 * you need to insert your own key handling between the input method
5861 * and the default key event handling of the #GtkEntry.
5862 * See gtk_text_view_reset_im_context() for an example of use.
5864 * Return value: %TRUE if the input method handled the key event.
5869 gtk_entry_im_context_filter_keypress (GtkEntry *entry,
5872 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
5874 return gtk_im_context_filter_keypress (entry->im_context, event);
5879 gtk_entry_find_position (GtkEntry *entry,
5882 PangoLayout *layout;
5883 PangoLayoutLine *line;
5890 layout = gtk_entry_ensure_layout (entry, TRUE);
5891 text = pango_layout_get_text (layout);
5892 cursor_index = g_utf8_offset_to_pointer (text, entry->current_pos) - text;
5894 line = pango_layout_get_lines_readonly (layout)->data;
5895 pango_layout_line_x_to_index (line, x * PANGO_SCALE, &index, &trailing);
5897 if (index >= cursor_index && entry->preedit_length)
5899 if (index >= cursor_index + entry->preedit_length)
5900 index -= entry->preedit_length;
5903 index = cursor_index;
5908 pos = g_utf8_pointer_to_offset (text, text + index);
5915 gtk_entry_get_cursor_locations (GtkEntry *entry,
5920 DisplayMode mode = gtk_entry_get_display_mode (entry);
5922 /* Nothing to display at all, so no cursor is relevant */
5923 if (mode == DISPLAY_BLANK)
5933 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
5934 const gchar *text = pango_layout_get_text (layout);
5935 PangoRectangle strong_pos, weak_pos;
5938 if (type == CURSOR_STANDARD)
5940 index = g_utf8_offset_to_pointer (text, entry->current_pos + entry->preedit_cursor) - text;
5942 else /* type == CURSOR_DND */
5944 index = g_utf8_offset_to_pointer (text, entry->dnd_position) - text;
5946 if (entry->dnd_position > entry->current_pos)
5948 if (mode == DISPLAY_NORMAL)
5949 index += entry->preedit_length;
5952 gint preedit_len_chars = g_utf8_strlen (text, -1) - gtk_entry_buffer_get_length (get_buffer (entry));
5953 index += preedit_len_chars * g_unichar_to_utf8 (entry->invisible_char, NULL);
5958 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
5961 *strong_x = strong_pos.x / PANGO_SCALE;
5964 *weak_x = weak_pos.x / PANGO_SCALE;
5969 gtk_entry_adjust_scroll (GtkEntry *entry)
5971 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
5972 gint min_offset, max_offset;
5973 gint text_area_width, text_width;
5974 GtkBorder inner_border;
5975 gint strong_x, weak_x;
5976 gint strong_xoffset, weak_xoffset;
5978 PangoLayout *layout;
5979 PangoLayoutLine *line;
5980 PangoRectangle logical_rect;
5982 if (!gtk_widget_get_realized (GTK_WIDGET (entry)))
5985 _gtk_entry_effective_inner_border (entry, &inner_border);
5987 gdk_drawable_get_size (entry->text_area, &text_area_width, NULL);
5988 text_area_width -= inner_border.left + inner_border.right;
5989 if (text_area_width < 0)
5990 text_area_width = 0;
5992 layout = gtk_entry_ensure_layout (entry, TRUE);
5993 line = pango_layout_get_lines_readonly (layout)->data;
5995 pango_layout_line_get_extents (line, NULL, &logical_rect);
5997 /* Display as much text as we can */
5999 if (entry->resolved_dir == PANGO_DIRECTION_LTR)
6000 xalign = priv->xalign;
6002 xalign = 1.0 - priv->xalign;
6004 text_width = PANGO_PIXELS(logical_rect.width);
6006 if (text_width > text_area_width)
6009 max_offset = text_width - text_area_width;
6013 min_offset = (text_width - text_area_width) * xalign;
6014 max_offset = min_offset;
6017 entry->scroll_offset = CLAMP (entry->scroll_offset, min_offset, max_offset);
6019 /* And make sure cursors are on screen. Note that the cursor is
6020 * actually drawn one pixel into the INNER_BORDER space on
6021 * the right, when the scroll is at the utmost right. This
6022 * looks better to to me than confining the cursor inside the
6023 * border entirely, though it means that the cursor gets one
6024 * pixel closer to the edge of the widget on the right than
6025 * on the left. This might need changing if one changed
6026 * INNER_BORDER from 2 to 1, as one would do on a
6027 * small-screen-real-estate display.
6029 * We always make sure that the strong cursor is on screen, and
6030 * put the weak cursor on screen if possible.
6033 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, &weak_x);
6035 strong_xoffset = strong_x - entry->scroll_offset;
6037 if (strong_xoffset < 0)
6039 entry->scroll_offset += strong_xoffset;
6042 else if (strong_xoffset > text_area_width)
6044 entry->scroll_offset += strong_xoffset - text_area_width;
6045 strong_xoffset = text_area_width;
6048 weak_xoffset = weak_x - entry->scroll_offset;
6050 if (weak_xoffset < 0 && strong_xoffset - weak_xoffset <= text_area_width)
6052 entry->scroll_offset += weak_xoffset;
6054 else if (weak_xoffset > text_area_width &&
6055 strong_xoffset - (weak_xoffset - text_area_width) >= 0)
6057 entry->scroll_offset += weak_xoffset - text_area_width;
6060 g_object_notify (G_OBJECT (entry), "scroll-offset");
6064 gtk_entry_move_adjustments (GtkEntry *entry)
6066 GtkAllocation allocation;
6067 GtkAdjustment *adjustment;
6068 PangoContext *context;
6069 PangoFontMetrics *metrics;
6070 gint x, layout_x, border_x, border_y;
6073 adjustment = g_object_get_qdata (G_OBJECT (entry), quark_cursor_hadjustment);
6077 gtk_widget_get_allocation (&(entry->widget), &allocation);
6079 /* Cursor position, layout offset, border width, and widget allocation */
6080 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &x, NULL);
6081 get_layout_position (entry, &layout_x, NULL);
6082 _gtk_entry_get_borders (entry, &border_x, &border_y);
6083 x += allocation.x + layout_x + border_x;
6085 /* Approximate width of a char, so user can see what is ahead/behind */
6086 context = gtk_widget_get_pango_context (GTK_WIDGET (entry));
6087 metrics = pango_context_get_metrics (context,
6088 gtk_widget_get_style (&(entry->widget))->font_desc,
6089 pango_context_get_language (context));
6090 char_width = pango_font_metrics_get_approximate_char_width (metrics) / PANGO_SCALE;
6093 gtk_adjustment_clamp_page (adjustment,
6094 x - (char_width + 1), /* one char + one pixel before */
6095 x + (char_width + 2)); /* one char + cursor + one pixel after */
6099 gtk_entry_move_visually (GtkEntry *entry,
6104 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6107 text = pango_layout_get_text (layout);
6109 index = g_utf8_offset_to_pointer (text, start) - text;
6113 int new_index, new_trailing;
6114 gboolean split_cursor;
6117 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
6118 "gtk-split-cursor", &split_cursor,
6125 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
6126 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
6128 strong = keymap_direction == entry->resolved_dir;
6133 pango_layout_move_cursor_visually (layout, strong, index, 0, 1, &new_index, &new_trailing);
6138 pango_layout_move_cursor_visually (layout, strong, index, 0, -1, &new_index, &new_trailing);
6144 else if (new_index != G_MAXINT)
6147 while (new_trailing--)
6148 index = g_utf8_next_char (text + index) - text;
6151 return g_utf8_pointer_to_offset (text, text + index);
6155 gtk_entry_move_logically (GtkEntry *entry,
6159 gint new_pos = start;
6162 length = gtk_entry_buffer_get_length (get_buffer (entry));
6164 /* Prevent any leak of information */
6165 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6167 new_pos = CLAMP (start + count, 0, length);
6171 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6172 PangoLogAttr *log_attrs;
6175 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6177 while (count > 0 && new_pos < length)
6181 while (new_pos < length && !log_attrs[new_pos].is_cursor_position);
6185 while (count < 0 && new_pos > 0)
6189 while (new_pos > 0 && !log_attrs[new_pos].is_cursor_position);
6201 gtk_entry_move_forward_word (GtkEntry *entry,
6203 gboolean allow_whitespace)
6205 gint new_pos = start;
6208 length = gtk_entry_buffer_get_length (get_buffer (entry));
6210 /* Prevent any leak of information */
6211 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6215 else if (new_pos < length)
6217 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6218 PangoLogAttr *log_attrs;
6221 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6223 /* Find the next word boundary */
6225 while (new_pos < n_attrs - 1 && !(log_attrs[new_pos].is_word_end ||
6226 (log_attrs[new_pos].is_word_start && allow_whitespace)))
6237 gtk_entry_move_backward_word (GtkEntry *entry,
6239 gboolean allow_whitespace)
6241 gint new_pos = start;
6243 /* Prevent any leak of information */
6244 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6250 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6251 PangoLogAttr *log_attrs;
6254 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6256 new_pos = start - 1;
6258 /* Find the previous word boundary */
6259 while (new_pos > 0 && !(log_attrs[new_pos].is_word_start ||
6260 (log_attrs[new_pos].is_word_end && allow_whitespace)))
6270 gtk_entry_delete_whitespace (GtkEntry *entry)
6272 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6273 PangoLogAttr *log_attrs;
6277 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6279 start = end = entry->current_pos;
6281 while (start > 0 && log_attrs[start-1].is_white)
6284 while (end < n_attrs && log_attrs[end].is_white)
6290 gtk_editable_delete_text (GTK_EDITABLE (entry), start, end);
6295 gtk_entry_select_word (GtkEntry *entry)
6297 gint start_pos = gtk_entry_move_backward_word (entry, entry->current_pos, TRUE);
6298 gint end_pos = gtk_entry_move_forward_word (entry, entry->current_pos, TRUE);
6300 gtk_editable_select_region (GTK_EDITABLE (entry), start_pos, end_pos);
6304 gtk_entry_select_line (GtkEntry *entry)
6306 gtk_editable_select_region (GTK_EDITABLE (entry), 0, -1);
6310 truncate_multiline (const gchar *text)
6315 text[length] && text[length] != '\n' && text[length] != '\r';
6322 paste_received (GtkClipboard *clipboard,
6326 GtkEntry *entry = GTK_ENTRY (data);
6327 GtkEditable *editable = GTK_EDITABLE (entry);
6328 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
6330 if (entry->button == 2)
6332 gint pos, start, end;
6333 pos = priv->insert_pos;
6334 gtk_editable_get_selection_bounds (editable, &start, &end);
6335 if (!((start <= pos && pos <= end) || (end <= pos && pos <= start)))
6336 gtk_editable_select_region (editable, pos, pos);
6341 gint pos, start, end;
6343 gboolean popup_completion;
6344 GtkEntryCompletion *completion;
6346 completion = gtk_entry_get_completion (entry);
6348 if (entry->truncate_multiline)
6349 length = truncate_multiline (text);
6351 /* only complete if the selection is at the end */
6352 popup_completion = (gtk_entry_buffer_get_length (get_buffer (entry)) ==
6353 MAX (entry->current_pos, entry->selection_bound));
6357 if (gtk_widget_get_mapped (completion->priv->popup_window))
6358 _gtk_entry_completion_popdown (completion);
6360 if (!popup_completion && completion->priv->changed_id > 0)
6361 g_signal_handler_block (entry, completion->priv->changed_id);
6364 begin_change (entry);
6365 g_object_freeze_notify (G_OBJECT (entry));
6366 if (gtk_editable_get_selection_bounds (editable, &start, &end))
6367 gtk_editable_delete_text (editable, start, end);
6369 pos = entry->current_pos;
6370 gtk_editable_insert_text (editable, text, length, &pos);
6371 gtk_editable_set_position (editable, pos);
6372 g_object_thaw_notify (G_OBJECT (entry));
6376 !popup_completion && completion->priv->changed_id > 0)
6377 g_signal_handler_unblock (entry, completion->priv->changed_id);
6380 g_object_unref (entry);
6384 gtk_entry_paste (GtkEntry *entry,
6387 g_object_ref (entry);
6388 gtk_clipboard_request_text (gtk_widget_get_clipboard (GTK_WIDGET (entry), selection),
6389 paste_received, entry);
6393 primary_get_cb (GtkClipboard *clipboard,
6394 GtkSelectionData *selection_data,
6398 GtkEntry *entry = GTK_ENTRY (data);
6401 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end))
6403 gchar *str = gtk_entry_get_display_text (entry, start, end);
6404 gtk_selection_data_set_text (selection_data, str, -1);
6410 primary_clear_cb (GtkClipboard *clipboard,
6413 GtkEntry *entry = GTK_ENTRY (data);
6415 gtk_editable_select_region (GTK_EDITABLE (entry), entry->current_pos, entry->current_pos);
6419 gtk_entry_update_primary_selection (GtkEntry *entry)
6421 GtkTargetList *list;
6422 GtkTargetEntry *targets;
6423 GtkClipboard *clipboard;
6427 if (!gtk_widget_get_realized (GTK_WIDGET (entry)))
6430 list = gtk_target_list_new (NULL, 0);
6431 gtk_target_list_add_text_targets (list, 0);
6433 targets = gtk_target_table_new_from_list (list, &n_targets);
6435 clipboard = gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_PRIMARY);
6437 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end))
6439 if (!gtk_clipboard_set_with_owner (clipboard, targets, n_targets,
6440 primary_get_cb, primary_clear_cb, G_OBJECT (entry)))
6441 primary_clear_cb (clipboard, entry);
6445 if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (entry))
6446 gtk_clipboard_clear (clipboard);
6449 gtk_target_table_free (targets, n_targets);
6450 gtk_target_list_unref (list);
6454 gtk_entry_clear (GtkEntry *entry,
6455 GtkEntryIconPosition icon_pos)
6457 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
6458 EntryIconInfo *icon_info = priv->icons[icon_pos];
6460 if (!icon_info || icon_info->storage_type == GTK_IMAGE_EMPTY)
6463 g_object_freeze_notify (G_OBJECT (entry));
6465 /* Explicitly check, as the pointer may become invalidated
6466 * during destruction.
6468 if (GDK_IS_WINDOW (icon_info->window))
6469 gdk_window_hide (icon_info->window);
6471 if (icon_info->pixbuf)
6473 g_object_unref (icon_info->pixbuf);
6474 icon_info->pixbuf = NULL;
6477 switch (icon_info->storage_type)
6479 case GTK_IMAGE_PIXBUF:
6480 g_object_notify (G_OBJECT (entry),
6481 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-pixbuf" : "secondary-icon-pixbuf");
6484 case GTK_IMAGE_STOCK:
6485 g_free (icon_info->stock_id);
6486 icon_info->stock_id = NULL;
6487 g_object_notify (G_OBJECT (entry),
6488 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-stock" : "secondary-icon-stock");
6491 case GTK_IMAGE_ICON_NAME:
6492 g_free (icon_info->icon_name);
6493 icon_info->icon_name = NULL;
6494 g_object_notify (G_OBJECT (entry),
6495 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-name" : "secondary-icon-name");
6498 case GTK_IMAGE_GICON:
6499 if (icon_info->gicon)
6501 g_object_unref (icon_info->gicon);
6502 icon_info->gicon = NULL;
6504 g_object_notify (G_OBJECT (entry),
6505 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-gicon" : "secondary-icon-gicon");
6509 g_assert_not_reached ();
6513 icon_info->storage_type = GTK_IMAGE_EMPTY;
6514 g_object_notify (G_OBJECT (entry),
6515 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-storage-type" : "secondary-icon-storage-type");
6517 g_object_thaw_notify (G_OBJECT (entry));
6521 gtk_entry_ensure_pixbuf (GtkEntry *entry,
6522 GtkEntryIconPosition icon_pos)
6524 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
6525 EntryIconInfo *icon_info = priv->icons[icon_pos];
6527 GtkIconTheme *icon_theme;
6528 GtkSettings *settings;
6534 if (!icon_info || icon_info->pixbuf)
6537 widget = GTK_WIDGET (entry);
6539 switch (icon_info->storage_type)
6541 case GTK_IMAGE_EMPTY:
6542 case GTK_IMAGE_PIXBUF:
6544 case GTK_IMAGE_STOCK:
6545 state = gtk_widget_get_state (widget);
6546 gtk_widget_set_state (widget, GTK_STATE_NORMAL);
6547 icon_info->pixbuf = gtk_widget_render_icon (widget,
6548 icon_info->stock_id,
6551 if (!icon_info->pixbuf)
6552 icon_info->pixbuf = gtk_widget_render_icon (widget,
6553 GTK_STOCK_MISSING_IMAGE,
6556 gtk_widget_set_state (widget, state);
6559 case GTK_IMAGE_ICON_NAME:
6560 screen = gtk_widget_get_screen (widget);
6563 icon_theme = gtk_icon_theme_get_for_screen (screen);
6564 settings = gtk_settings_get_for_screen (screen);
6566 gtk_icon_size_lookup_for_settings (settings,
6570 icon_info->pixbuf = gtk_icon_theme_load_icon (icon_theme,
6571 icon_info->icon_name,
6572 MIN (width, height),
6575 if (icon_info->pixbuf == NULL)
6577 state = gtk_widget_get_state (widget);
6578 gtk_widget_set_state (widget, GTK_STATE_NORMAL);
6579 icon_info->pixbuf = gtk_widget_render_icon (widget,
6580 GTK_STOCK_MISSING_IMAGE,
6583 gtk_widget_set_state (widget, state);
6588 case GTK_IMAGE_GICON:
6589 screen = gtk_widget_get_screen (widget);
6592 icon_theme = gtk_icon_theme_get_for_screen (screen);
6593 settings = gtk_settings_get_for_screen (screen);
6595 gtk_icon_size_lookup_for_settings (settings,
6599 info = gtk_icon_theme_lookup_by_gicon (icon_theme,
6601 MIN (width, height),
6602 GTK_ICON_LOOKUP_USE_BUILTIN);
6605 icon_info->pixbuf = gtk_icon_info_load_icon (info, NULL);
6606 gtk_icon_info_free (info);
6609 if (icon_info->pixbuf == NULL)
6611 state = gtk_widget_get_state (widget);
6612 gtk_widget_set_state (widget, GTK_STATE_NORMAL);
6613 icon_info->pixbuf = gtk_widget_render_icon (widget,
6614 GTK_STOCK_MISSING_IMAGE,
6617 gtk_widget_set_state (widget, state);
6623 g_assert_not_reached ();
6627 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
6628 gdk_window_show_unraised (icon_info->window);
6638 * Creates a new entry.
6640 * Return value: a new #GtkEntry.
6643 gtk_entry_new (void)
6645 return g_object_new (GTK_TYPE_ENTRY, NULL);
6649 * gtk_entry_new_with_buffer:
6650 * @buffer: The buffer to use for the new #GtkEntry.
6652 * Creates a new entry with the specified text buffer.
6654 * Return value: a new #GtkEntry
6659 gtk_entry_new_with_buffer (GtkEntryBuffer *buffer)
6661 g_return_val_if_fail (GTK_IS_ENTRY_BUFFER (buffer), NULL);
6662 return g_object_new (GTK_TYPE_ENTRY, "buffer", buffer, NULL);
6665 static GtkEntryBuffer*
6666 get_buffer (GtkEntry *entry)
6668 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
6670 if (priv->buffer == NULL)
6672 GtkEntryBuffer *buffer;
6673 buffer = gtk_entry_buffer_new (NULL, 0);
6674 gtk_entry_set_buffer (entry, buffer);
6675 g_object_unref (buffer);
6678 return priv->buffer;
6682 * gtk_entry_get_buffer:
6683 * @entry: a #GtkEntry
6685 * Get the #GtkEntryBuffer object which holds the text for
6690 * Returns: A #GtkEntryBuffer object.
6693 gtk_entry_get_buffer (GtkEntry *entry)
6695 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
6697 return get_buffer (entry);
6701 * gtk_entry_set_buffer:
6702 * @entry: a #GtkEntry
6703 * @buffer: a #GtkEntryBuffer
6705 * Set the #GtkEntryBuffer object which holds the text for
6711 gtk_entry_set_buffer (GtkEntry *entry,
6712 GtkEntryBuffer *buffer)
6714 GtkEntryPrivate *priv;
6717 g_return_if_fail (GTK_IS_ENTRY (entry));
6718 priv = GTK_ENTRY_GET_PRIVATE (entry);
6722 g_return_if_fail (GTK_IS_ENTRY_BUFFER (buffer));
6723 g_object_ref (buffer);
6728 buffer_disconnect_signals (entry);
6729 g_object_unref (priv->buffer);
6732 priv->buffer = buffer;
6735 buffer_connect_signals (entry);
6737 obj = G_OBJECT (entry);
6738 g_object_freeze_notify (obj);
6739 g_object_notify (obj, "buffer");
6740 g_object_notify (obj, "text");
6741 g_object_notify (obj, "text-length");
6742 g_object_notify (obj, "max-length");
6743 g_object_notify (obj, "visibility");
6744 g_object_notify (obj, "invisible-char");
6745 g_object_notify (obj, "invisible-char-set");
6746 g_object_thaw_notify (obj);
6748 gtk_editable_set_position (GTK_EDITABLE (entry), 0);
6749 gtk_entry_recompute (entry);
6753 * gtk_entry_get_text_window:
6754 * @entry: a #GtkEntry
6756 * Returns the #GdkWindow which contains the text. This function is
6757 * useful when drawing something to the entry in an expose-event
6758 * callback because it enables the callback to distinguish between
6759 * the text window and entry's icon windows.
6761 * See also gtk_entry_get_icon_window().
6763 * Return value: the entry's text window.
6768 gtk_entry_get_text_window (GtkEntry *entry)
6770 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
6772 return entry->text_area;
6777 * gtk_entry_set_text:
6778 * @entry: a #GtkEntry
6779 * @text: the new text
6781 * Sets the text in the widget to the given
6782 * value, replacing the current contents.
6784 * See gtk_entry_buffer_set_text().
6787 gtk_entry_set_text (GtkEntry *entry,
6791 GtkEntryCompletion *completion;
6792 GtkEntryPrivate *priv;
6794 g_return_if_fail (GTK_IS_ENTRY (entry));
6795 g_return_if_fail (text != NULL);
6796 priv = GTK_ENTRY_GET_PRIVATE (entry);
6798 /* Actually setting the text will affect the cursor and selection;
6799 * if the contents don't actually change, this will look odd to the user.
6801 if (strcmp (gtk_entry_buffer_get_text (get_buffer (entry)), text) == 0)
6804 completion = gtk_entry_get_completion (entry);
6805 if (completion && completion->priv->changed_id > 0)
6806 g_signal_handler_block (entry, completion->priv->changed_id);
6808 begin_change (entry);
6809 g_object_freeze_notify (G_OBJECT (entry));
6810 gtk_editable_delete_text (GTK_EDITABLE (entry), 0, -1);
6812 gtk_editable_insert_text (GTK_EDITABLE (entry), text, strlen (text), &tmp_pos);
6813 g_object_thaw_notify (G_OBJECT (entry));
6816 if (completion && completion->priv->changed_id > 0)
6817 g_signal_handler_unblock (entry, completion->priv->changed_id);
6821 * gtk_entry_set_visibility:
6822 * @entry: a #GtkEntry
6823 * @visible: %TRUE if the contents of the entry are displayed
6826 * Sets whether the contents of the entry are visible or not.
6827 * When visibility is set to %FALSE, characters are displayed
6828 * as the invisible char, and will also appear that way when
6829 * the text in the entry widget is copied elsewhere.
6831 * By default, GTK+ picks the best invisible character available
6832 * in the current font, but it can be changed with
6833 * gtk_entry_set_invisible_char().
6836 gtk_entry_set_visibility (GtkEntry *entry,
6839 g_return_if_fail (GTK_IS_ENTRY (entry));
6841 visible = visible != FALSE;
6843 if (entry->visible != visible)
6845 entry->visible = visible;
6847 g_object_notify (G_OBJECT (entry), "visibility");
6848 gtk_entry_recompute (entry);
6853 * gtk_entry_get_visibility:
6854 * @entry: a #GtkEntry
6856 * Retrieves whether the text in @entry is visible. See
6857 * gtk_entry_set_visibility().
6859 * Return value: %TRUE if the text is currently visible
6862 gtk_entry_get_visibility (GtkEntry *entry)
6864 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
6866 return entry->visible;
6870 * gtk_entry_set_invisible_char:
6871 * @entry: a #GtkEntry
6872 * @ch: a Unicode character
6874 * Sets the character to use in place of the actual text when
6875 * gtk_entry_set_visibility() has been called to set text visibility
6876 * to %FALSE. i.e. this is the character used in "password mode" to
6877 * show the user how many characters have been typed. By default, GTK+
6878 * picks the best invisible char available in the current font. If you
6879 * set the invisible char to 0, then the user will get no feedback
6880 * at all; there will be no text on the screen as they type.
6883 gtk_entry_set_invisible_char (GtkEntry *entry,
6886 GtkEntryPrivate *priv;
6888 g_return_if_fail (GTK_IS_ENTRY (entry));
6890 priv = GTK_ENTRY_GET_PRIVATE (entry);
6892 if (!priv->invisible_char_set)
6894 priv->invisible_char_set = TRUE;
6895 g_object_notify (G_OBJECT (entry), "invisible-char-set");
6898 if (ch == entry->invisible_char)
6901 entry->invisible_char = ch;
6902 g_object_notify (G_OBJECT (entry), "invisible-char");
6903 gtk_entry_recompute (entry);
6907 * gtk_entry_get_invisible_char:
6908 * @entry: a #GtkEntry
6910 * Retrieves the character displayed in place of the real characters
6911 * for entries with visibility set to false. See gtk_entry_set_invisible_char().
6913 * Return value: the current invisible char, or 0, if the entry does not
6914 * show invisible text at all.
6917 gtk_entry_get_invisible_char (GtkEntry *entry)
6919 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
6921 return entry->invisible_char;
6925 * gtk_entry_unset_invisible_char:
6926 * @entry: a #GtkEntry
6928 * Unsets the invisible char previously set with
6929 * gtk_entry_set_invisible_char(). So that the
6930 * default invisible char is used again.
6935 gtk_entry_unset_invisible_char (GtkEntry *entry)
6937 GtkEntryPrivate *priv;
6940 g_return_if_fail (GTK_IS_ENTRY (entry));
6942 priv = GTK_ENTRY_GET_PRIVATE (entry);
6944 if (!priv->invisible_char_set)
6947 priv->invisible_char_set = FALSE;
6948 ch = find_invisible_char (GTK_WIDGET (entry));
6950 if (entry->invisible_char != ch)
6952 entry->invisible_char = ch;
6953 g_object_notify (G_OBJECT (entry), "invisible-char");
6956 g_object_notify (G_OBJECT (entry), "invisible-char-set");
6957 gtk_entry_recompute (entry);
6961 * gtk_entry_set_overwrite_mode:
6962 * @entry: a #GtkEntry
6963 * @overwrite: new value
6965 * Sets whether the text is overwritten when typing in the #GtkEntry.
6970 gtk_entry_set_overwrite_mode (GtkEntry *entry,
6973 g_return_if_fail (GTK_IS_ENTRY (entry));
6975 if (entry->overwrite_mode == overwrite)
6978 gtk_entry_toggle_overwrite (entry);
6980 g_object_notify (G_OBJECT (entry), "overwrite-mode");
6984 * gtk_entry_get_overwrite_mode:
6985 * @entry: a #GtkEntry
6987 * Gets the value set by gtk_entry_set_overwrite_mode().
6989 * Return value: whether the text is overwritten when typing.
6994 gtk_entry_get_overwrite_mode (GtkEntry *entry)
6996 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
6998 return entry->overwrite_mode;
7002 * gtk_entry_get_text:
7003 * @entry: a #GtkEntry
7005 * Retrieves the contents of the entry widget.
7006 * See also gtk_editable_get_chars().
7008 * This is equivalent to:
7010 * <informalexample><programlisting>
7011 * gtk_entry_buffer_get_text (gtk_entry_get_buffer (entry));
7012 * </programlisting></informalexample>
7014 * Return value: a pointer to the contents of the widget as a
7015 * string. This string points to internally allocated
7016 * storage in the widget and must not be freed, modified or
7019 G_CONST_RETURN gchar*
7020 gtk_entry_get_text (GtkEntry *entry)
7022 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7023 return gtk_entry_buffer_get_text (get_buffer (entry));
7027 * gtk_entry_set_max_length:
7028 * @entry: a #GtkEntry
7029 * @max: the maximum length of the entry, or 0 for no maximum.
7030 * (other than the maximum length of entries.) The value passed in will
7031 * be clamped to the range 0-65536.
7033 * Sets the maximum allowed length of the contents of the widget. If
7034 * the current contents are longer than the given length, then they
7035 * will be truncated to fit.
7037 * This is equivalent to:
7039 * <informalexample><programlisting>
7040 * gtk_entry_buffer_set_max_length (gtk_entry_get_buffer (entry), max);
7041 * </programlisting></informalexample>
7044 gtk_entry_set_max_length (GtkEntry *entry,
7047 g_return_if_fail (GTK_IS_ENTRY (entry));
7048 gtk_entry_buffer_set_max_length (get_buffer (entry), max);
7052 * gtk_entry_get_max_length:
7053 * @entry: a #GtkEntry
7055 * Retrieves the maximum allowed length of the text in
7056 * @entry. See gtk_entry_set_max_length().
7058 * This is equivalent to:
7060 * <informalexample><programlisting>
7061 * gtk_entry_buffer_get_max_length (gtk_entry_get_buffer (entry));
7062 * </programlisting></informalexample>
7064 * Return value: the maximum allowed number of characters
7065 * in #GtkEntry, or 0 if there is no maximum.
7068 gtk_entry_get_max_length (GtkEntry *entry)
7070 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7071 return gtk_entry_buffer_get_max_length (get_buffer (entry));
7075 * gtk_entry_get_text_length:
7076 * @entry: a #GtkEntry
7078 * Retrieves the current length of the text in
7081 * This is equivalent to:
7083 * <informalexample><programlisting>
7084 * gtk_entry_buffer_get_length (gtk_entry_get_buffer (entry));
7085 * </programlisting></informalexample>
7087 * Return value: the current number of characters
7088 * in #GtkEntry, or 0 if there are none.
7093 gtk_entry_get_text_length (GtkEntry *entry)
7095 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7096 return gtk_entry_buffer_get_length (get_buffer (entry));
7100 * gtk_entry_set_activates_default:
7101 * @entry: a #GtkEntry
7102 * @setting: %TRUE to activate window's default widget on Enter keypress
7104 * If @setting is %TRUE, pressing Enter in the @entry will activate the default
7105 * widget for the window containing the entry. This usually means that
7106 * the dialog box containing the entry will be closed, since the default
7107 * widget is usually one of the dialog buttons.
7109 * (For experts: if @setting is %TRUE, the entry calls
7110 * gtk_window_activate_default() on the window containing the entry, in
7111 * the default handler for the #GtkWidget::activate signal.)
7114 gtk_entry_set_activates_default (GtkEntry *entry,
7117 g_return_if_fail (GTK_IS_ENTRY (entry));
7118 setting = setting != FALSE;
7120 if (setting != entry->activates_default)
7122 entry->activates_default = setting;
7123 g_object_notify (G_OBJECT (entry), "activates-default");
7128 * gtk_entry_get_activates_default:
7129 * @entry: a #GtkEntry
7131 * Retrieves the value set by gtk_entry_set_activates_default().
7133 * Return value: %TRUE if the entry will activate the default widget
7136 gtk_entry_get_activates_default (GtkEntry *entry)
7138 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7140 return entry->activates_default;
7144 * gtk_entry_set_width_chars:
7145 * @entry: a #GtkEntry
7146 * @n_chars: width in chars
7148 * Changes the size request of the entry to be about the right size
7149 * for @n_chars characters. Note that it changes the size
7150 * <emphasis>request</emphasis>, the size can still be affected by
7151 * how you pack the widget into containers. If @n_chars is -1, the
7152 * size reverts to the default entry size.
7155 gtk_entry_set_width_chars (GtkEntry *entry,
7158 g_return_if_fail (GTK_IS_ENTRY (entry));
7160 if (entry->width_chars != n_chars)
7162 entry->width_chars = n_chars;
7163 g_object_notify (G_OBJECT (entry), "width-chars");
7164 gtk_widget_queue_resize (GTK_WIDGET (entry));
7169 * gtk_entry_get_width_chars:
7170 * @entry: a #GtkEntry
7172 * Gets the value set by gtk_entry_set_width_chars().
7174 * Return value: number of chars to request space for, or negative if unset
7177 gtk_entry_get_width_chars (GtkEntry *entry)
7179 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7181 return entry->width_chars;
7185 * gtk_entry_set_has_frame:
7186 * @entry: a #GtkEntry
7187 * @setting: new value
7189 * Sets whether the entry has a beveled frame around it.
7192 gtk_entry_set_has_frame (GtkEntry *entry,
7195 g_return_if_fail (GTK_IS_ENTRY (entry));
7197 setting = (setting != FALSE);
7199 if (entry->has_frame == setting)
7202 gtk_widget_queue_resize (GTK_WIDGET (entry));
7203 entry->has_frame = setting;
7204 g_object_notify (G_OBJECT (entry), "has-frame");
7208 * gtk_entry_get_has_frame:
7209 * @entry: a #GtkEntry
7211 * Gets the value set by gtk_entry_set_has_frame().
7213 * Return value: whether the entry has a beveled frame
7216 gtk_entry_get_has_frame (GtkEntry *entry)
7218 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7220 return entry->has_frame;
7224 * gtk_entry_set_inner_border:
7225 * @entry: a #GtkEntry
7226 * @border: (allow-none): a #GtkBorder, or %NULL
7228 * Sets %entry's inner-border property to %border, or clears it if %NULL
7229 * is passed. The inner-border is the area around the entry's text, but
7232 * If set, this property overrides the inner-border style property.
7233 * Overriding the style-provided border is useful when you want to do
7234 * in-place editing of some text in a canvas or list widget, where
7235 * pixel-exact positioning of the entry is important.
7240 gtk_entry_set_inner_border (GtkEntry *entry,
7241 const GtkBorder *border)
7243 g_return_if_fail (GTK_IS_ENTRY (entry));
7245 gtk_widget_queue_resize (GTK_WIDGET (entry));
7248 g_object_set_qdata_full (G_OBJECT (entry), quark_inner_border,
7249 gtk_border_copy (border),
7250 (GDestroyNotify) gtk_border_free);
7252 g_object_set_qdata (G_OBJECT (entry), quark_inner_border, NULL);
7254 g_object_notify (G_OBJECT (entry), "inner-border");
7258 * gtk_entry_get_inner_border:
7259 * @entry: a #GtkEntry
7261 * This function returns the entry's #GtkEntry:inner-border property. See
7262 * gtk_entry_set_inner_border() for more information.
7264 * Return value: (transfer none): the entry's #GtkBorder, or %NULL if none was set.
7268 G_CONST_RETURN GtkBorder *
7269 gtk_entry_get_inner_border (GtkEntry *entry)
7271 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7273 return g_object_get_qdata (G_OBJECT (entry), quark_inner_border);
7277 * gtk_entry_get_layout:
7278 * @entry: a #GtkEntry
7280 * Gets the #PangoLayout used to display the entry.
7281 * The layout is useful to e.g. convert text positions to
7282 * pixel positions, in combination with gtk_entry_get_layout_offsets().
7283 * The returned layout is owned by the entry and must not be
7284 * modified or freed by the caller.
7286 * Keep in mind that the layout text may contain a preedit string, so
7287 * gtk_entry_layout_index_to_text_index() and
7288 * gtk_entry_text_index_to_layout_index() are needed to convert byte
7289 * indices in the layout to byte indices in the entry contents.
7291 * Return value: (transfer none): the #PangoLayout for this entry
7294 gtk_entry_get_layout (GtkEntry *entry)
7296 PangoLayout *layout;
7298 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7300 layout = gtk_entry_ensure_layout (entry, TRUE);
7307 * gtk_entry_layout_index_to_text_index:
7308 * @entry: a #GtkEntry
7309 * @layout_index: byte index into the entry layout text
7311 * Converts from a position in the entry contents (returned
7312 * by gtk_entry_get_text()) to a position in the
7313 * entry's #PangoLayout (returned by gtk_entry_get_layout(),
7314 * with text retrieved via pango_layout_get_text()).
7316 * Return value: byte index into the entry contents
7319 gtk_entry_layout_index_to_text_index (GtkEntry *entry,
7322 PangoLayout *layout;
7326 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7328 layout = gtk_entry_ensure_layout (entry, TRUE);
7329 text = pango_layout_get_text (layout);
7330 cursor_index = g_utf8_offset_to_pointer (text, entry->current_pos) - text;
7332 if (layout_index >= cursor_index && entry->preedit_length)
7334 if (layout_index >= cursor_index + entry->preedit_length)
7335 layout_index -= entry->preedit_length;
7337 layout_index = cursor_index;
7340 return layout_index;
7344 * gtk_entry_text_index_to_layout_index:
7345 * @entry: a #GtkEntry
7346 * @text_index: byte index into the entry contents
7348 * Converts from a position in the entry's #PangoLayout (returned by
7349 * gtk_entry_get_layout()) to a position in the entry contents
7350 * (returned by gtk_entry_get_text()).
7352 * Return value: byte index into the entry layout text
7355 gtk_entry_text_index_to_layout_index (GtkEntry *entry,
7358 PangoLayout *layout;
7361 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7363 layout = gtk_entry_ensure_layout (entry, TRUE);
7364 text = pango_layout_get_text (layout);
7365 cursor_index = g_utf8_offset_to_pointer (text, entry->current_pos) - text;
7367 if (text_index > cursor_index)
7368 text_index += entry->preedit_length;
7374 * gtk_entry_get_layout_offsets:
7375 * @entry: a #GtkEntry
7376 * @x: (allow-none): location to store X offset of layout, or %NULL
7377 * @y: (allow-none): location to store Y offset of layout, or %NULL
7380 * Obtains the position of the #PangoLayout used to render text
7381 * in the entry, in widget coordinates. Useful if you want to line
7382 * up the text in an entry with some other text, e.g. when using the
7383 * entry to implement editable cells in a sheet widget.
7385 * Also useful to convert mouse events into coordinates inside the
7386 * #PangoLayout, e.g. to take some action if some part of the entry text
7389 * Note that as the user scrolls around in the entry the offsets will
7390 * change; you'll need to connect to the "notify::scroll-offset"
7391 * signal to track this. Remember when using the #PangoLayout
7392 * functions you need to convert to and from pixels using
7393 * PANGO_PIXELS() or #PANGO_SCALE.
7395 * Keep in mind that the layout text may contain a preedit string, so
7396 * gtk_entry_layout_index_to_text_index() and
7397 * gtk_entry_text_index_to_layout_index() are needed to convert byte
7398 * indices in the layout to byte indices in the entry contents.
7401 gtk_entry_get_layout_offsets (GtkEntry *entry,
7405 gint text_area_x, text_area_y;
7407 g_return_if_fail (GTK_IS_ENTRY (entry));
7409 /* this gets coords relative to text area */
7410 get_layout_position (entry, x, y);
7412 /* convert to widget coords */
7413 gtk_entry_get_text_area_size (entry, &text_area_x, &text_area_y, NULL, NULL);
7424 * gtk_entry_set_alignment:
7425 * @entry: a #GtkEntry
7426 * @xalign: The horizontal alignment, from 0 (left) to 1 (right).
7427 * Reversed for RTL layouts
7429 * Sets the alignment for the contents of the entry. This controls
7430 * the horizontal positioning of the contents when the displayed
7431 * text is shorter than the width of the entry.
7436 gtk_entry_set_alignment (GtkEntry *entry, gfloat xalign)
7438 GtkEntryPrivate *priv;
7440 g_return_if_fail (GTK_IS_ENTRY (entry));
7442 priv = GTK_ENTRY_GET_PRIVATE (entry);
7446 else if (xalign > 1.0)
7449 if (xalign != priv->xalign)
7451 priv->xalign = xalign;
7453 gtk_entry_recompute (entry);
7455 g_object_notify (G_OBJECT (entry), "xalign");
7460 * gtk_entry_get_alignment:
7461 * @entry: a #GtkEntry
7463 * Gets the value set by gtk_entry_set_alignment().
7465 * Return value: the alignment
7470 gtk_entry_get_alignment (GtkEntry *entry)
7472 GtkEntryPrivate *priv;
7474 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
7476 priv = GTK_ENTRY_GET_PRIVATE (entry);
7478 return priv->xalign;
7482 * gtk_entry_set_icon_from_pixbuf:
7483 * @entry: a #GtkEntry
7484 * @icon_pos: Icon position
7485 * @pixbuf: (allow-none): A #GdkPixbuf, or %NULL
7487 * Sets the icon shown in the specified position using a pixbuf.
7489 * If @pixbuf is %NULL, no icon will be shown in the specified position.
7494 gtk_entry_set_icon_from_pixbuf (GtkEntry *entry,
7495 GtkEntryIconPosition icon_pos,
7498 GtkEntryPrivate *priv;
7499 EntryIconInfo *icon_info;
7501 g_return_if_fail (GTK_IS_ENTRY (entry));
7502 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7504 priv = GTK_ENTRY_GET_PRIVATE (entry);
7506 if ((icon_info = priv->icons[icon_pos]) == NULL)
7507 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7509 g_object_freeze_notify (G_OBJECT (entry));
7512 g_object_ref (pixbuf);
7514 gtk_entry_clear (entry, icon_pos);
7518 icon_info->storage_type = GTK_IMAGE_PIXBUF;
7519 icon_info->pixbuf = pixbuf;
7521 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7523 g_object_notify (G_OBJECT (entry), "primary-icon-pixbuf");
7524 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7528 g_object_notify (G_OBJECT (entry), "secondary-icon-pixbuf");
7529 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7532 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7533 gdk_window_show_unraised (icon_info->window);
7536 gtk_entry_ensure_pixbuf (entry, icon_pos);
7538 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7539 gtk_widget_queue_resize (GTK_WIDGET (entry));
7541 g_object_thaw_notify (G_OBJECT (entry));
7545 * gtk_entry_set_icon_from_stock:
7546 * @entry: A #GtkEntry
7547 * @icon_pos: Icon position
7548 * @stock_id: (allow-none): The name of the stock item, or %NULL
7550 * Sets the icon shown in the entry at the specified position from
7553 * If @stock_id is %NULL, no icon will be shown in the specified position.
7558 gtk_entry_set_icon_from_stock (GtkEntry *entry,
7559 GtkEntryIconPosition icon_pos,
7560 const gchar *stock_id)
7562 GtkEntryPrivate *priv;
7563 EntryIconInfo *icon_info;
7566 g_return_if_fail (GTK_IS_ENTRY (entry));
7567 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7569 priv = GTK_ENTRY_GET_PRIVATE (entry);
7571 if ((icon_info = priv->icons[icon_pos]) == NULL)
7572 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7574 g_object_freeze_notify (G_OBJECT (entry));
7576 gtk_widget_ensure_style (GTK_WIDGET (entry));
7578 /* need to dup before clearing */
7579 new_id = g_strdup (stock_id);
7581 gtk_entry_clear (entry, icon_pos);
7585 icon_info->storage_type = GTK_IMAGE_STOCK;
7586 icon_info->stock_id = new_id;
7588 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7590 g_object_notify (G_OBJECT (entry), "primary-icon-stock");
7591 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7595 g_object_notify (G_OBJECT (entry), "secondary-icon-stock");
7596 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7599 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7600 gdk_window_show_unraised (icon_info->window);
7603 gtk_entry_ensure_pixbuf (entry, icon_pos);
7605 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7606 gtk_widget_queue_resize (GTK_WIDGET (entry));
7608 g_object_thaw_notify (G_OBJECT (entry));
7612 * gtk_entry_set_icon_from_icon_name:
7613 * @entry: A #GtkEntry
7614 * @icon_pos: The position at which to set the icon
7615 * @icon_name: (allow-none): An icon name, or %NULL
7617 * Sets the icon shown in the entry at the specified position
7618 * from the current icon theme.
7620 * If the icon name isn't known, a "broken image" icon will be displayed
7623 * If @icon_name is %NULL, no icon will be shown in the specified position.
7628 gtk_entry_set_icon_from_icon_name (GtkEntry *entry,
7629 GtkEntryIconPosition icon_pos,
7630 const gchar *icon_name)
7632 GtkEntryPrivate *priv;
7633 EntryIconInfo *icon_info;
7636 g_return_if_fail (GTK_IS_ENTRY (entry));
7637 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7639 priv = GTK_ENTRY_GET_PRIVATE (entry);
7641 if ((icon_info = priv->icons[icon_pos]) == NULL)
7642 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7644 g_object_freeze_notify (G_OBJECT (entry));
7646 gtk_widget_ensure_style (GTK_WIDGET (entry));
7648 /* need to dup before clearing */
7649 new_name = g_strdup (icon_name);
7651 gtk_entry_clear (entry, icon_pos);
7653 if (new_name != NULL)
7655 icon_info->storage_type = GTK_IMAGE_ICON_NAME;
7656 icon_info->icon_name = new_name;
7658 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7660 g_object_notify (G_OBJECT (entry), "primary-icon-name");
7661 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7665 g_object_notify (G_OBJECT (entry), "secondary-icon-name");
7666 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7669 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7670 gdk_window_show_unraised (icon_info->window);
7673 gtk_entry_ensure_pixbuf (entry, icon_pos);
7675 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7676 gtk_widget_queue_resize (GTK_WIDGET (entry));
7678 g_object_thaw_notify (G_OBJECT (entry));
7682 * gtk_entry_set_icon_from_gicon:
7683 * @entry: A #GtkEntry
7684 * @icon_pos: The position at which to set the icon
7685 * @icon: (allow-none): The icon to set, or %NULL
7687 * Sets the icon shown in the entry at the specified position
7688 * from the current icon theme.
7689 * If the icon isn't known, a "broken image" icon will be displayed
7692 * If @icon is %NULL, no icon will be shown in the specified position.
7697 gtk_entry_set_icon_from_gicon (GtkEntry *entry,
7698 GtkEntryIconPosition icon_pos,
7701 GtkEntryPrivate *priv;
7702 EntryIconInfo *icon_info;
7704 g_return_if_fail (GTK_IS_ENTRY (entry));
7705 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7707 priv = GTK_ENTRY_GET_PRIVATE (entry);
7709 if ((icon_info = priv->icons[icon_pos]) == NULL)
7710 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7712 g_object_freeze_notify (G_OBJECT (entry));
7714 /* need to ref before clearing */
7716 g_object_ref (icon);
7718 gtk_entry_clear (entry, icon_pos);
7722 icon_info->storage_type = GTK_IMAGE_GICON;
7723 icon_info->gicon = icon;
7725 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7727 g_object_notify (G_OBJECT (entry), "primary-icon-gicon");
7728 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7732 g_object_notify (G_OBJECT (entry), "secondary-icon-gicon");
7733 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7736 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7737 gdk_window_show_unraised (icon_info->window);
7740 gtk_entry_ensure_pixbuf (entry, icon_pos);
7742 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7743 gtk_widget_queue_resize (GTK_WIDGET (entry));
7745 g_object_thaw_notify (G_OBJECT (entry));
7749 * gtk_entry_set_icon_activatable:
7750 * @entry: A #GtkEntry
7751 * @icon_pos: Icon position
7752 * @activatable: %TRUE if the icon should be activatable
7754 * Sets whether the icon is activatable.
7759 gtk_entry_set_icon_activatable (GtkEntry *entry,
7760 GtkEntryIconPosition icon_pos,
7761 gboolean activatable)
7763 GtkEntryPrivate *priv;
7764 EntryIconInfo *icon_info;
7766 g_return_if_fail (GTK_IS_ENTRY (entry));
7767 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7769 priv = GTK_ENTRY_GET_PRIVATE (entry);
7771 if ((icon_info = priv->icons[icon_pos]) == NULL)
7772 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7774 activatable = activatable != FALSE;
7776 if (icon_info->nonactivatable != !activatable)
7778 icon_info->nonactivatable = !activatable;
7780 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
7781 update_cursors (GTK_WIDGET (entry));
7783 g_object_notify (G_OBJECT (entry),
7784 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-activatable" : "secondary-icon-activatable");
7789 * gtk_entry_get_icon_activatable:
7790 * @entry: a #GtkEntry
7791 * @icon_pos: Icon position
7793 * Returns whether the icon is activatable.
7795 * Returns: %TRUE if the icon is activatable.
7800 gtk_entry_get_icon_activatable (GtkEntry *entry,
7801 GtkEntryIconPosition icon_pos)
7803 GtkEntryPrivate *priv;
7804 EntryIconInfo *icon_info;
7806 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7807 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), FALSE);
7809 priv = GTK_ENTRY_GET_PRIVATE (entry);
7810 icon_info = priv->icons[icon_pos];
7812 return (icon_info != NULL && !icon_info->nonactivatable);
7816 * gtk_entry_get_icon_pixbuf:
7817 * @entry: A #GtkEntry
7818 * @icon_pos: Icon position
7820 * Retrieves the image used for the icon.
7822 * Unlike the other methods of setting and getting icon data, this
7823 * method will work regardless of whether the icon was set using a
7824 * #GdkPixbuf, a #GIcon, a stock item, or an icon name.
7826 * Returns: A #GdkPixbuf, or %NULL if no icon is set for this position.
7831 gtk_entry_get_icon_pixbuf (GtkEntry *entry,
7832 GtkEntryIconPosition icon_pos)
7834 GtkEntryPrivate *priv;
7835 EntryIconInfo *icon_info;
7837 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7838 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7840 priv = GTK_ENTRY_GET_PRIVATE (entry);
7841 icon_info = priv->icons[icon_pos];
7846 gtk_entry_ensure_pixbuf (entry, icon_pos);
7848 return icon_info->pixbuf;
7852 * gtk_entry_get_icon_gicon:
7853 * @entry: A #GtkEntry
7854 * @icon_pos: Icon position
7856 * Retrieves the #GIcon used for the icon, or %NULL if there is
7857 * no icon or if the icon was set by some other method (e.g., by
7858 * stock, pixbuf, or icon name).
7860 * Returns: A #GIcon, or %NULL if no icon is set or if the icon
7866 gtk_entry_get_icon_gicon (GtkEntry *entry,
7867 GtkEntryIconPosition icon_pos)
7869 GtkEntryPrivate *priv;
7870 EntryIconInfo *icon_info;
7872 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7873 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7875 priv = GTK_ENTRY_GET_PRIVATE (entry);
7876 icon_info = priv->icons[icon_pos];
7881 return icon_info->storage_type == GTK_IMAGE_GICON ? icon_info->gicon : NULL;
7885 * gtk_entry_get_icon_stock:
7886 * @entry: A #GtkEntry
7887 * @icon_pos: Icon position
7889 * Retrieves the stock id used for the icon, or %NULL if there is
7890 * no icon or if the icon was set by some other method (e.g., by
7891 * pixbuf, icon name or gicon).
7893 * Returns: A stock id, or %NULL if no icon is set or if the icon
7894 * wasn't set from a stock id
7899 gtk_entry_get_icon_stock (GtkEntry *entry,
7900 GtkEntryIconPosition icon_pos)
7902 GtkEntryPrivate *priv;
7903 EntryIconInfo *icon_info;
7905 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7906 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7908 priv = GTK_ENTRY_GET_PRIVATE (entry);
7909 icon_info = priv->icons[icon_pos];
7914 return icon_info->storage_type == GTK_IMAGE_STOCK ? icon_info->stock_id : NULL;
7918 * gtk_entry_get_icon_name:
7919 * @entry: A #GtkEntry
7920 * @icon_pos: Icon position
7922 * Retrieves the icon name used for the icon, or %NULL if there is
7923 * no icon or if the icon was set by some other method (e.g., by
7924 * pixbuf, stock or gicon).
7926 * Returns: An icon name, or %NULL if no icon is set or if the icon
7927 * wasn't set from an icon name
7932 gtk_entry_get_icon_name (GtkEntry *entry,
7933 GtkEntryIconPosition icon_pos)
7935 GtkEntryPrivate *priv;
7936 EntryIconInfo *icon_info;
7938 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7939 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7941 priv = GTK_ENTRY_GET_PRIVATE (entry);
7942 icon_info = priv->icons[icon_pos];
7947 return icon_info->storage_type == GTK_IMAGE_ICON_NAME ? icon_info->icon_name : NULL;
7951 * gtk_entry_set_icon_sensitive:
7952 * @entry: A #GtkEntry
7953 * @icon_pos: Icon position
7954 * @sensitive: Specifies whether the icon should appear
7955 * sensitive or insensitive
7957 * Sets the sensitivity for the specified icon.
7962 gtk_entry_set_icon_sensitive (GtkEntry *entry,
7963 GtkEntryIconPosition icon_pos,
7966 GtkEntryPrivate *priv;
7967 EntryIconInfo *icon_info;
7969 g_return_if_fail (GTK_IS_ENTRY (entry));
7970 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7972 priv = GTK_ENTRY_GET_PRIVATE (entry);
7974 if ((icon_info = priv->icons[icon_pos]) == NULL)
7975 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7977 if (icon_info->insensitive != !sensitive)
7979 icon_info->insensitive = !sensitive;
7981 icon_info->pressed = FALSE;
7982 icon_info->prelight = FALSE;
7984 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
7985 update_cursors (GTK_WIDGET (entry));
7987 gtk_widget_queue_draw (GTK_WIDGET (entry));
7989 g_object_notify (G_OBJECT (entry),
7990 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-sensitive" : "secondary-icon-sensitive");
7995 * gtk_entry_get_icon_sensitive:
7996 * @entry: a #GtkEntry
7997 * @icon_pos: Icon position
7999 * Returns whether the icon appears sensitive or insensitive.
8001 * Returns: %TRUE if the icon is sensitive.
8006 gtk_entry_get_icon_sensitive (GtkEntry *entry,
8007 GtkEntryIconPosition icon_pos)
8009 GtkEntryPrivate *priv;
8010 EntryIconInfo *icon_info;
8012 g_return_val_if_fail (GTK_IS_ENTRY (entry), TRUE);
8013 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), TRUE);
8015 priv = GTK_ENTRY_GET_PRIVATE (entry);
8016 icon_info = priv->icons[icon_pos];
8018 return (!icon_info || !icon_info->insensitive);
8023 * gtk_entry_get_icon_storage_type:
8024 * @entry: a #GtkEntry
8025 * @icon_pos: Icon position
8027 * Gets the type of representation being used by the icon
8028 * to store image data. If the icon has no image data,
8029 * the return value will be %GTK_IMAGE_EMPTY.
8031 * Return value: image representation being used
8036 gtk_entry_get_icon_storage_type (GtkEntry *entry,
8037 GtkEntryIconPosition icon_pos)
8039 GtkEntryPrivate *priv;
8040 EntryIconInfo *icon_info;
8042 g_return_val_if_fail (GTK_IS_ENTRY (entry), GTK_IMAGE_EMPTY);
8043 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), GTK_IMAGE_EMPTY);
8045 priv = GTK_ENTRY_GET_PRIVATE (entry);
8046 icon_info = priv->icons[icon_pos];
8049 return GTK_IMAGE_EMPTY;
8051 return icon_info->storage_type;
8055 * gtk_entry_get_icon_at_pos:
8056 * @entry: a #GtkEntry
8057 * @x: the x coordinate of the position to find
8058 * @y: the y coordinate of the position to find
8060 * Finds the icon at the given position and return its index.
8061 * If @x, @y doesn't lie inside an icon, -1 is returned.
8062 * This function is intended for use in a #GtkWidget::query-tooltip
8065 * Returns: the index of the icon at the given position, or -1
8070 gtk_entry_get_icon_at_pos (GtkEntry *entry,
8074 GtkAllocation primary;
8075 GtkAllocation secondary;
8077 g_return_val_if_fail (GTK_IS_ENTRY (entry), -1);
8079 get_icon_allocations (entry, &primary, &secondary);
8081 if (primary.x <= x && x < primary.x + primary.width &&
8082 primary.y <= y && y < primary.y + primary.height)
8083 return GTK_ENTRY_ICON_PRIMARY;
8085 if (secondary.x <= x && x < secondary.x + secondary.width &&
8086 secondary.y <= y && y < secondary.y + secondary.height)
8087 return GTK_ENTRY_ICON_SECONDARY;
8093 * gtk_entry_set_icon_drag_source:
8094 * @entry: a #GtkIconEntry
8095 * @icon_pos: icon position
8096 * @target_list: the targets (data formats) in which the data can be provided
8097 * @actions: a bitmask of the allowed drag actions
8099 * Sets up the icon at the given position so that GTK+ will start a drag
8100 * operation when the user clicks and drags the icon.
8102 * To handle the drag operation, you need to connect to the usual
8103 * #GtkWidget::drag-data-get (or possibly #GtkWidget::drag-data-delete)
8104 * signal, and use gtk_entry_get_current_icon_drag_source() in
8105 * your signal handler to find out if the drag was started from
8108 * By default, GTK+ uses the icon as the drag icon. You can use the
8109 * #GtkWidget::drag-begin signal to set a different icon. Note that you
8110 * have to use g_signal_connect_after() to ensure that your signal handler
8111 * gets executed after the default handler.
8116 gtk_entry_set_icon_drag_source (GtkEntry *entry,
8117 GtkEntryIconPosition icon_pos,
8118 GtkTargetList *target_list,
8119 GdkDragAction actions)
8121 GtkEntryPrivate *priv;
8122 EntryIconInfo *icon_info;
8124 g_return_if_fail (GTK_IS_ENTRY (entry));
8125 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8127 priv = GTK_ENTRY_GET_PRIVATE (entry);
8129 if ((icon_info = priv->icons[icon_pos]) == NULL)
8130 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8132 if (icon_info->target_list)
8133 gtk_target_list_unref (icon_info->target_list);
8134 icon_info->target_list = target_list;
8135 if (icon_info->target_list)
8136 gtk_target_list_ref (icon_info->target_list);
8138 icon_info->actions = actions;
8142 * gtk_entry_get_current_icon_drag_source:
8143 * @entry: a #GtkIconEntry
8145 * Returns the index of the icon which is the source of the current
8146 * DND operation, or -1.
8148 * This function is meant to be used in a #GtkWidget::drag-data-get
8151 * Returns: index of the icon which is the source of the current
8152 * DND operation, or -1.
8157 gtk_entry_get_current_icon_drag_source (GtkEntry *entry)
8159 GtkEntryPrivate *priv;
8160 EntryIconInfo *icon_info = NULL;
8163 g_return_val_if_fail (GTK_IS_ENTRY (entry), -1);
8165 priv = GTK_ENTRY_GET_PRIVATE (entry);
8167 for (i = 0; i < MAX_ICONS; i++)
8169 if ((icon_info = priv->icons[i]))
8171 if (icon_info->in_drag)
8180 * gtk_entry_get_icon_window:
8181 * @entry: A #GtkEntry
8182 * @icon_pos: Icon position
8184 * Returns the #GdkWindow which contains the entry's icon at
8185 * @icon_pos. This function is useful when drawing something to the
8186 * entry in an expose-event callback because it enables the callback
8187 * to distinguish between the text window and entry's icon windows.
8189 * See also gtk_entry_get_text_window().
8191 * Return value: the entry's icon window at @icon_pos.
8196 gtk_entry_get_icon_window (GtkEntry *entry,
8197 GtkEntryIconPosition icon_pos)
8199 GtkEntryPrivate *priv;
8200 EntryIconInfo *icon_info;
8202 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8204 priv = GTK_ENTRY_GET_PRIVATE (entry);
8206 icon_info = priv->icons[icon_pos];
8209 return icon_info->window;
8215 ensure_has_tooltip (GtkEntry *entry)
8217 GtkEntryPrivate *priv;
8218 EntryIconInfo *icon_info;
8220 gboolean has_tooltip = FALSE;
8222 priv = GTK_ENTRY_GET_PRIVATE (entry);
8224 for (i = 0; i < MAX_ICONS; i++)
8226 if ((icon_info = priv->icons[i]) != NULL)
8228 if (icon_info->tooltip != NULL)
8236 gtk_widget_set_has_tooltip (GTK_WIDGET (entry), has_tooltip);
8240 * gtk_entry_get_icon_tooltip_text:
8241 * @entry: a #GtkEntry
8242 * @icon_pos: the icon position
8244 * Gets the contents of the tooltip on the icon at the specified
8245 * position in @entry.
8247 * Returns: the tooltip text, or %NULL. Free the returned string
8248 * with g_free() when done.
8253 gtk_entry_get_icon_tooltip_text (GtkEntry *entry,
8254 GtkEntryIconPosition icon_pos)
8256 GtkEntryPrivate *priv;
8257 EntryIconInfo *icon_info;
8260 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8261 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8263 priv = GTK_ENTRY_GET_PRIVATE (entry);
8264 icon_info = priv->icons[icon_pos];
8269 if (icon_info->tooltip &&
8270 !pango_parse_markup (icon_info->tooltip, -1, 0, NULL, &text, NULL, NULL))
8271 g_assert (NULL == text); /* text should still be NULL in case of markup errors */
8277 * gtk_entry_set_icon_tooltip_text:
8278 * @entry: a #GtkEntry
8279 * @icon_pos: the icon position
8280 * @tooltip: (allow-none): the contents of the tooltip for the icon, or %NULL
8282 * Sets @tooltip as the contents of the tooltip for the icon
8283 * at the specified position.
8285 * Use %NULL for @tooltip to remove an existing tooltip.
8287 * See also gtk_widget_set_tooltip_text() and
8288 * gtk_entry_set_icon_tooltip_markup().
8293 gtk_entry_set_icon_tooltip_text (GtkEntry *entry,
8294 GtkEntryIconPosition icon_pos,
8295 const gchar *tooltip)
8297 GtkEntryPrivate *priv;
8298 EntryIconInfo *icon_info;
8300 g_return_if_fail (GTK_IS_ENTRY (entry));
8301 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8303 priv = GTK_ENTRY_GET_PRIVATE (entry);
8305 if (!(icon_info = priv->icons[icon_pos]))
8306 icon_info = priv->icons[icon_pos];
8308 if (icon_info->tooltip)
8309 g_free (icon_info->tooltip);
8311 /* Treat an empty string as a NULL string,
8312 * because an empty string would be useless for a tooltip:
8314 if (tooltip && tooltip[0] == '\0')
8317 icon_info->tooltip = tooltip ? g_markup_escape_text (tooltip, -1) : NULL;
8319 ensure_has_tooltip (entry);
8323 * gtk_entry_get_icon_tooltip_markup:
8324 * @entry: a #GtkEntry
8325 * @icon_pos: the icon position
8327 * Gets the contents of the tooltip on the icon at the specified
8328 * position in @entry.
8330 * Returns: the tooltip text, or %NULL. Free the returned string
8331 * with g_free() when done.
8336 gtk_entry_get_icon_tooltip_markup (GtkEntry *entry,
8337 GtkEntryIconPosition icon_pos)
8339 GtkEntryPrivate *priv;
8340 EntryIconInfo *icon_info;
8342 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8343 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8345 priv = GTK_ENTRY_GET_PRIVATE (entry);
8346 icon_info = priv->icons[icon_pos];
8351 return g_strdup (icon_info->tooltip);
8355 * gtk_entry_set_icon_tooltip_markup:
8356 * @entry: a #GtkEntry
8357 * @icon_pos: the icon position
8358 * @tooltip: (allow-none): the contents of the tooltip for the icon, or %NULL
8360 * Sets @tooltip as the contents of the tooltip for the icon at
8361 * the specified position. @tooltip is assumed to be marked up with
8362 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
8364 * Use %NULL for @tooltip to remove an existing tooltip.
8366 * See also gtk_widget_set_tooltip_markup() and
8367 * gtk_enty_set_icon_tooltip_text().
8372 gtk_entry_set_icon_tooltip_markup (GtkEntry *entry,
8373 GtkEntryIconPosition icon_pos,
8374 const gchar *tooltip)
8376 GtkEntryPrivate *priv;
8377 EntryIconInfo *icon_info;
8379 g_return_if_fail (GTK_IS_ENTRY (entry));
8380 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8382 priv = GTK_ENTRY_GET_PRIVATE (entry);
8384 if (!(icon_info = priv->icons[icon_pos]))
8385 icon_info = priv->icons[icon_pos];
8387 if (icon_info->tooltip)
8388 g_free (icon_info->tooltip);
8390 /* Treat an empty string as a NULL string,
8391 * because an empty string would be useless for a tooltip:
8393 if (tooltip && tooltip[0] == '\0')
8396 icon_info->tooltip = g_strdup (tooltip);
8398 ensure_has_tooltip (entry);
8402 gtk_entry_query_tooltip (GtkWidget *widget,
8405 gboolean keyboard_tip,
8406 GtkTooltip *tooltip)
8409 GtkEntryPrivate *priv;
8410 EntryIconInfo *icon_info;
8413 entry = GTK_ENTRY (widget);
8414 priv = GTK_ENTRY_GET_PRIVATE (entry);
8418 icon_pos = gtk_entry_get_icon_at_pos (entry, x, y);
8421 if ((icon_info = priv->icons[icon_pos]) != NULL)
8423 if (icon_info->tooltip)
8425 gtk_tooltip_set_markup (tooltip, icon_info->tooltip);
8434 return GTK_WIDGET_CLASS (gtk_entry_parent_class)->query_tooltip (widget,
8441 /* Quick hack of a popup menu
8444 activate_cb (GtkWidget *menuitem,
8447 const gchar *signal = g_object_get_data (G_OBJECT (menuitem), "gtk-signal");
8448 g_signal_emit_by_name (entry, signal);
8453 gtk_entry_mnemonic_activate (GtkWidget *widget,
8454 gboolean group_cycling)
8456 gtk_widget_grab_focus (widget);
8461 append_action_signal (GtkEntry *entry,
8463 const gchar *stock_id,
8464 const gchar *signal,
8467 GtkWidget *menuitem = gtk_image_menu_item_new_from_stock (stock_id, NULL);
8469 g_object_set_data (G_OBJECT (menuitem), I_("gtk-signal"), (char *)signal);
8470 g_signal_connect (menuitem, "activate",
8471 G_CALLBACK (activate_cb), entry);
8473 gtk_widget_set_sensitive (menuitem, sensitive);
8475 gtk_widget_show (menuitem);
8476 gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
8480 popup_menu_detach (GtkWidget *attach_widget,
8483 GTK_ENTRY (attach_widget)->popup_menu = NULL;
8487 popup_position_func (GtkMenu *menu,
8493 GtkEntry *entry = GTK_ENTRY (user_data);
8494 GtkWidget *widget = GTK_WIDGET (entry);
8496 GtkRequisition menu_req;
8497 GdkRectangle monitor;
8498 GtkBorder inner_border;
8499 gint monitor_num, strong_x, height;
8501 g_return_if_fail (gtk_widget_get_realized (widget));
8503 gdk_window_get_origin (entry->text_area, x, y);
8505 screen = gtk_widget_get_screen (widget);
8506 monitor_num = gdk_screen_get_monitor_at_window (screen, entry->text_area);
8507 if (monitor_num < 0)
8509 gtk_menu_set_monitor (menu, monitor_num);
8511 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
8512 gtk_widget_size_request (entry->popup_menu, &menu_req);
8513 gdk_drawable_get_size (entry->text_area, NULL, &height);
8514 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
8515 _gtk_entry_effective_inner_border (entry, &inner_border);
8517 *x += inner_border.left + strong_x - entry->scroll_offset;
8518 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
8519 *x -= menu_req.width;
8521 if ((*y + height + menu_req.height) <= monitor.y + monitor.height)
8523 else if ((*y - menu_req.height) >= monitor.y)
8524 *y -= menu_req.height;
8525 else if (monitor.y + monitor.height - (*y + height) > *y)
8528 *y -= menu_req.height;
8534 unichar_chosen_func (const char *text,
8537 GtkEntry *entry = GTK_ENTRY (data);
8539 if (entry->editable)
8540 gtk_entry_enter_text (entry, text);
8551 popup_targets_received (GtkClipboard *clipboard,
8552 GtkSelectionData *data,
8555 PopupInfo *info = user_data;
8556 GtkEntry *entry = info->entry;
8558 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
8561 gboolean clipboard_contains_text;
8562 GtkWidget *menuitem;
8564 gboolean show_input_method_menu;
8565 gboolean show_unicode_menu;
8567 clipboard_contains_text = gtk_selection_data_targets_include_text (data);
8568 if (entry->popup_menu)
8569 gtk_widget_destroy (entry->popup_menu);
8571 entry->popup_menu = gtk_menu_new ();
8573 gtk_menu_attach_to_widget (GTK_MENU (entry->popup_menu),
8577 mode = gtk_entry_get_display_mode (entry);
8578 append_action_signal (entry, entry->popup_menu, GTK_STOCK_CUT, "cut-clipboard",
8579 entry->editable && mode == DISPLAY_NORMAL &&
8580 entry->current_pos != entry->selection_bound);
8582 append_action_signal (entry, entry->popup_menu, GTK_STOCK_COPY, "copy-clipboard",
8583 mode == DISPLAY_NORMAL &&
8584 entry->current_pos != entry->selection_bound);
8586 append_action_signal (entry, entry->popup_menu, GTK_STOCK_PASTE, "paste-clipboard",
8587 entry->editable && clipboard_contains_text);
8589 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_DELETE, NULL);
8590 gtk_widget_set_sensitive (menuitem, entry->editable && entry->current_pos != entry->selection_bound);
8591 g_signal_connect_swapped (menuitem, "activate",
8592 G_CALLBACK (gtk_entry_delete_cb), entry);
8593 gtk_widget_show (menuitem);
8594 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8596 menuitem = gtk_separator_menu_item_new ();
8597 gtk_widget_show (menuitem);
8598 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8600 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_SELECT_ALL, NULL);
8601 g_signal_connect_swapped (menuitem, "activate",
8602 G_CALLBACK (gtk_entry_select_all), entry);
8603 gtk_widget_show (menuitem);
8604 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8606 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
8607 "gtk-show-input-method-menu", &show_input_method_menu,
8608 "gtk-show-unicode-menu", &show_unicode_menu,
8611 if (show_input_method_menu || show_unicode_menu)
8613 menuitem = gtk_separator_menu_item_new ();
8614 gtk_widget_show (menuitem);
8615 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8618 if (show_input_method_menu)
8620 menuitem = gtk_menu_item_new_with_mnemonic (_("Input _Methods"));
8621 gtk_widget_set_sensitive (menuitem, entry->editable);
8622 gtk_widget_show (menuitem);
8623 submenu = gtk_menu_new ();
8624 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
8626 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8628 gtk_im_multicontext_append_menuitems (GTK_IM_MULTICONTEXT (entry->im_context),
8629 GTK_MENU_SHELL (submenu));
8632 if (show_unicode_menu)
8634 menuitem = gtk_menu_item_new_with_mnemonic (_("_Insert Unicode Control Character"));
8635 gtk_widget_set_sensitive (menuitem, entry->editable);
8636 gtk_widget_show (menuitem);
8638 submenu = gtk_menu_new ();
8639 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
8640 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8642 _gtk_text_util_append_special_char_menuitems (GTK_MENU_SHELL (submenu),
8643 unichar_chosen_func,
8647 g_signal_emit (entry,
8648 signals[POPULATE_POPUP],
8654 gtk_menu_popup (GTK_MENU (entry->popup_menu), NULL, NULL,
8656 info->button, info->time);
8659 gtk_menu_popup (GTK_MENU (entry->popup_menu), NULL, NULL,
8660 popup_position_func, entry,
8661 info->button, info->time);
8662 gtk_menu_shell_select_first (GTK_MENU_SHELL (entry->popup_menu), FALSE);
8666 g_object_unref (entry);
8667 g_slice_free (PopupInfo, info);
8671 gtk_entry_do_popup (GtkEntry *entry,
8672 GdkEventButton *event)
8674 PopupInfo *info = g_slice_new (PopupInfo);
8676 /* In order to know what entries we should make sensitive, we
8677 * ask for the current targets of the clipboard, and when
8678 * we get them, then we actually pop up the menu.
8680 info->entry = g_object_ref (entry);
8684 info->button = event->button;
8685 info->time = event->time;
8690 info->time = gtk_get_current_event_time ();
8693 gtk_clipboard_request_contents (gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_CLIPBOARD),
8694 gdk_atom_intern_static_string ("TARGETS"),
8695 popup_targets_received,
8700 gtk_entry_popup_menu (GtkWidget *widget)
8702 gtk_entry_do_popup (GTK_ENTRY (widget), NULL);
8707 gtk_entry_drag_begin (GtkWidget *widget,
8708 GdkDragContext *context)
8710 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
8713 for (i = 0; i < MAX_ICONS; i++)
8715 EntryIconInfo *icon_info = priv->icons[i];
8717 if (icon_info != NULL)
8719 if (icon_info->in_drag)
8721 switch (icon_info->storage_type)
8723 case GTK_IMAGE_STOCK:
8724 gtk_drag_set_icon_stock (context, icon_info->stock_id, -2, -2);
8727 case GTK_IMAGE_ICON_NAME:
8728 gtk_drag_set_icon_name (context, icon_info->icon_name, -2, -2);
8731 /* FIXME: No GIcon support for dnd icons */
8732 case GTK_IMAGE_GICON:
8733 case GTK_IMAGE_PIXBUF:
8734 gtk_drag_set_icon_pixbuf (context, icon_info->pixbuf, -2, -2);
8737 g_assert_not_reached ();
8745 gtk_entry_drag_end (GtkWidget *widget,
8746 GdkDragContext *context)
8748 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
8751 for (i = 0; i < MAX_ICONS; i++)
8753 EntryIconInfo *icon_info = priv->icons[i];
8755 if (icon_info != NULL)
8756 icon_info->in_drag = 0;
8761 gtk_entry_drag_leave (GtkWidget *widget,
8762 GdkDragContext *context,
8765 GtkEntry *entry = GTK_ENTRY (widget);
8767 entry->dnd_position = -1;
8768 gtk_widget_queue_draw (widget);
8772 gtk_entry_drag_drop (GtkWidget *widget,
8773 GdkDragContext *context,
8778 GtkEntry *entry = GTK_ENTRY (widget);
8779 GdkAtom target = GDK_NONE;
8781 if (entry->editable)
8782 target = gtk_drag_dest_find_target (widget, context, NULL);
8784 if (target != GDK_NONE)
8785 gtk_drag_get_data (widget, context, target, time);
8787 gtk_drag_finish (context, FALSE, FALSE, time);
8793 gtk_entry_drag_motion (GtkWidget *widget,
8794 GdkDragContext *context,
8799 GtkEntry *entry = GTK_ENTRY (widget);
8801 GtkWidget *source_widget;
8802 GdkDragAction suggested_action;
8803 gint new_position, old_position;
8806 style = gtk_widget_get_style (widget);
8807 x -= style->xthickness;
8808 y -= style->ythickness;
8810 old_position = entry->dnd_position;
8811 new_position = gtk_entry_find_position (entry, x + entry->scroll_offset);
8813 if (entry->editable &&
8814 gtk_drag_dest_find_target (widget, context, NULL) != GDK_NONE)
8816 source_widget = gtk_drag_get_source_widget (context);
8817 suggested_action = context->suggested_action;
8819 if (!gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &sel1, &sel2) ||
8820 new_position < sel1 || new_position > sel2)
8822 if (source_widget == widget)
8824 /* Default to MOVE, unless the user has
8825 * pressed ctrl or alt to affect available actions
8827 if ((context->actions & GDK_ACTION_MOVE) != 0)
8828 suggested_action = GDK_ACTION_MOVE;
8831 entry->dnd_position = new_position;
8835 if (source_widget == widget)
8836 suggested_action = 0; /* Can't drop in selection where drag started */
8838 entry->dnd_position = -1;
8843 /* Entry not editable, or no text */
8844 suggested_action = 0;
8845 entry->dnd_position = -1;
8848 gdk_drag_status (context, suggested_action, time);
8850 if (entry->dnd_position != old_position)
8851 gtk_widget_queue_draw (widget);
8857 gtk_entry_drag_data_received (GtkWidget *widget,
8858 GdkDragContext *context,
8861 GtkSelectionData *selection_data,
8865 GtkEntry *entry = GTK_ENTRY (widget);
8866 GtkEditable *editable = GTK_EDITABLE (widget);
8870 str = (gchar *) gtk_selection_data_get_text (selection_data);
8872 style = gtk_widget_get_style (widget);
8873 x -= style->xthickness;
8874 y -= style->ythickness;
8876 if (str && entry->editable)
8882 if (entry->truncate_multiline)
8883 length = truncate_multiline (str);
8885 new_position = gtk_entry_find_position (entry, x + entry->scroll_offset);
8887 if (!gtk_editable_get_selection_bounds (editable, &sel1, &sel2) ||
8888 new_position < sel1 || new_position > sel2)
8890 gtk_editable_insert_text (editable, str, length, &new_position);
8894 /* Replacing selection */
8895 begin_change (entry);
8896 g_object_freeze_notify (G_OBJECT (entry));
8897 gtk_editable_delete_text (editable, sel1, sel2);
8898 gtk_editable_insert_text (editable, str, length, &sel1);
8899 g_object_thaw_notify (G_OBJECT (entry));
8903 gtk_drag_finish (context, TRUE, context->action == GDK_ACTION_MOVE, time);
8907 /* Drag and drop didn't happen! */
8908 gtk_drag_finish (context, FALSE, FALSE, time);
8915 gtk_entry_drag_data_get (GtkWidget *widget,
8916 GdkDragContext *context,
8917 GtkSelectionData *selection_data,
8921 gint sel_start, sel_end;
8924 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
8925 GtkEditable *editable = GTK_EDITABLE (widget);
8927 /* If there is an icon drag going on, exit early. */
8928 for (i = 0; i < MAX_ICONS; i++)
8930 EntryIconInfo *icon_info = priv->icons[i];
8932 if (icon_info != NULL)
8934 if (icon_info->in_drag)
8939 if (gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end))
8941 gchar *str = gtk_entry_get_display_text (GTK_ENTRY (widget), sel_start, sel_end);
8943 gtk_selection_data_set_text (selection_data, str, -1);
8951 gtk_entry_drag_data_delete (GtkWidget *widget,
8952 GdkDragContext *context)
8954 gint sel_start, sel_end;
8957 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
8958 GtkEditable *editable = GTK_EDITABLE (widget);
8960 /* If there is an icon drag going on, exit early. */
8961 for (i = 0; i < MAX_ICONS; i++)
8963 EntryIconInfo *icon_info = priv->icons[i];
8965 if (icon_info != NULL)
8967 if (icon_info->in_drag)
8972 if (GTK_ENTRY (widget)->editable &&
8973 gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end))
8974 gtk_editable_delete_text (editable, sel_start, sel_end);
8977 /* We display the cursor when
8979 * - the selection is empty, AND
8980 * - the widget has focus
8983 #define CURSOR_ON_MULTIPLIER 2
8984 #define CURSOR_OFF_MULTIPLIER 1
8985 #define CURSOR_PEND_MULTIPLIER 3
8986 #define CURSOR_DIVIDER 3
8989 cursor_blinks (GtkEntry *entry)
8991 if (gtk_widget_has_focus (GTK_WIDGET (entry)) &&
8993 entry->selection_bound == entry->current_pos)
8995 GtkSettings *settings;
8998 settings = gtk_widget_get_settings (GTK_WIDGET (entry));
8999 g_object_get (settings, "gtk-cursor-blink", &blink, NULL);
9008 get_cursor_time (GtkEntry *entry)
9010 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9013 g_object_get (settings, "gtk-cursor-blink-time", &time, NULL);
9019 get_cursor_blink_timeout (GtkEntry *entry)
9021 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9024 g_object_get (settings, "gtk-cursor-blink-timeout", &timeout, NULL);
9030 show_cursor (GtkEntry *entry)
9034 if (!entry->cursor_visible)
9036 entry->cursor_visible = TRUE;
9038 widget = GTK_WIDGET (entry);
9039 if (gtk_widget_has_focus (widget) && entry->selection_bound == entry->current_pos)
9040 gtk_widget_queue_draw (widget);
9045 hide_cursor (GtkEntry *entry)
9049 if (entry->cursor_visible)
9051 entry->cursor_visible = FALSE;
9053 widget = GTK_WIDGET (entry);
9054 if (gtk_widget_has_focus (widget) && entry->selection_bound == entry->current_pos)
9055 gtk_widget_queue_draw (widget);
9063 blink_cb (gpointer data)
9066 GtkEntryPrivate *priv;
9069 entry = GTK_ENTRY (data);
9070 priv = GTK_ENTRY_GET_PRIVATE (entry);
9072 if (!gtk_widget_has_focus (GTK_WIDGET (entry)))
9074 g_warning ("GtkEntry - did not receive focus-out-event. If you\n"
9075 "connect a handler to this signal, it must return\n"
9076 "FALSE so the entry gets the event as well");
9078 gtk_entry_check_cursor_blink (entry);
9083 g_assert (entry->selection_bound == entry->current_pos);
9085 blink_timeout = get_cursor_blink_timeout (entry);
9086 if (priv->blink_time > 1000 * blink_timeout &&
9087 blink_timeout < G_MAXINT/1000)
9089 /* we've blinked enough without the user doing anything, stop blinking */
9090 show_cursor (entry);
9091 entry->blink_timeout = 0;
9093 else if (entry->cursor_visible)
9095 hide_cursor (entry);
9096 entry->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_OFF_MULTIPLIER / CURSOR_DIVIDER,
9102 show_cursor (entry);
9103 priv->blink_time += get_cursor_time (entry);
9104 entry->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
9109 /* Remove ourselves */
9114 gtk_entry_check_cursor_blink (GtkEntry *entry)
9116 GtkEntryPrivate *priv;
9118 priv = GTK_ENTRY_GET_PRIVATE (entry);
9120 if (cursor_blinks (entry))
9122 if (!entry->blink_timeout)
9124 show_cursor (entry);
9125 entry->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
9132 if (entry->blink_timeout)
9134 g_source_remove (entry->blink_timeout);
9135 entry->blink_timeout = 0;
9138 entry->cursor_visible = TRUE;
9144 gtk_entry_pend_cursor_blink (GtkEntry *entry)
9146 if (cursor_blinks (entry))
9148 if (entry->blink_timeout != 0)
9149 g_source_remove (entry->blink_timeout);
9151 entry->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_PEND_MULTIPLIER / CURSOR_DIVIDER,
9154 show_cursor (entry);
9159 gtk_entry_reset_blink_time (GtkEntry *entry)
9161 GtkEntryPrivate *priv;
9163 priv = GTK_ENTRY_GET_PRIVATE (entry);
9165 priv->blink_time = 0;
9171 gtk_entry_completion_timeout (gpointer data)
9173 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (data);
9174 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (completion->priv->entry);
9176 completion->priv->completion_timeout = 0;
9178 if (completion->priv->filter_model &&
9179 g_utf8_strlen (gtk_entry_get_text (GTK_ENTRY (completion->priv->entry)), -1)
9180 >= completion->priv->minimum_key_length)
9184 GtkTreeSelection *s;
9185 gboolean popup_single;
9187 gtk_entry_completion_complete (completion);
9188 matches = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->filter_model), NULL);
9190 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9192 s = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view));
9194 gtk_tree_selection_unselect_all (s);
9196 actions = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->actions), NULL);
9198 g_object_get (completion, "popup-single-match", &popup_single, NULL);
9199 if ((matches > (popup_single ? 0: 1)) || actions > 0)
9201 if (gtk_widget_get_visible (completion->priv->popup_window))
9202 _gtk_entry_completion_resize_popup (completion);
9204 _gtk_entry_completion_popup (completion, priv->completion_device);
9207 _gtk_entry_completion_popdown (completion);
9209 else if (gtk_widget_get_visible (completion->priv->popup_window))
9210 _gtk_entry_completion_popdown (completion);
9215 static inline gboolean
9216 keyval_is_cursor_move (guint keyval)
9218 if (keyval == GDK_Up || keyval == GDK_KP_Up)
9221 if (keyval == GDK_Down || keyval == GDK_KP_Down)
9224 if (keyval == GDK_Page_Up)
9227 if (keyval == GDK_Page_Down)
9234 gtk_entry_completion_key_press (GtkWidget *widget,
9238 gint matches, actions = 0;
9239 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
9241 if (!gtk_widget_get_mapped (completion->priv->popup_window))
9244 matches = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->filter_model), NULL);
9246 if (completion->priv->actions)
9247 actions = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->actions), NULL);
9249 if (keyval_is_cursor_move (event->keyval))
9251 GtkTreePath *path = NULL;
9253 if (event->keyval == GDK_Up || event->keyval == GDK_KP_Up)
9255 if (completion->priv->current_selected < 0)
9256 completion->priv->current_selected = matches + actions - 1;
9258 completion->priv->current_selected--;
9260 else if (event->keyval == GDK_Down || event->keyval == GDK_KP_Down)
9262 if (completion->priv->current_selected < matches + actions - 1)
9263 completion->priv->current_selected++;
9265 completion->priv->current_selected = -1;
9267 else if (event->keyval == GDK_Page_Up)
9269 if (completion->priv->current_selected < 0)
9270 completion->priv->current_selected = matches + actions - 1;
9271 else if (completion->priv->current_selected == 0)
9272 completion->priv->current_selected = -1;
9273 else if (completion->priv->current_selected < matches)
9275 completion->priv->current_selected -= 14;
9276 if (completion->priv->current_selected < 0)
9277 completion->priv->current_selected = 0;
9281 completion->priv->current_selected -= 14;
9282 if (completion->priv->current_selected < matches - 1)
9283 completion->priv->current_selected = matches - 1;
9286 else if (event->keyval == GDK_Page_Down)
9288 if (completion->priv->current_selected < 0)
9289 completion->priv->current_selected = 0;
9290 else if (completion->priv->current_selected < matches - 1)
9292 completion->priv->current_selected += 14;
9293 if (completion->priv->current_selected > matches - 1)
9294 completion->priv->current_selected = matches - 1;
9296 else if (completion->priv->current_selected == matches + actions - 1)
9298 completion->priv->current_selected = -1;
9302 completion->priv->current_selected += 14;
9303 if (completion->priv->current_selected > matches + actions - 1)
9304 completion->priv->current_selected = matches + actions - 1;
9308 if (completion->priv->current_selected < 0)
9310 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9311 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view)));
9313 if (completion->priv->inline_selection &&
9314 completion->priv->completion_prefix)
9316 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9317 completion->priv->completion_prefix);
9318 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9321 else if (completion->priv->current_selected < matches)
9323 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view)));
9325 path = gtk_tree_path_new_from_indices (completion->priv->current_selected, -1);
9326 gtk_tree_view_set_cursor (GTK_TREE_VIEW (completion->priv->tree_view),
9329 if (completion->priv->inline_selection)
9333 GtkTreeIter child_iter;
9334 GtkTreeModel *model = NULL;
9335 GtkTreeSelection *sel;
9338 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view));
9339 if (!gtk_tree_selection_get_selected (sel, &model, &iter))
9342 gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (model), &child_iter, &iter);
9343 model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model));
9345 if (completion->priv->completion_prefix == NULL)
9346 completion->priv->completion_prefix = g_strdup (gtk_entry_get_text (GTK_ENTRY (completion->priv->entry)));
9348 g_signal_emit_by_name (completion, "cursor-on-match", model,
9349 &child_iter, &entry_set);
9352 else if (completion->priv->current_selected - matches >= 0)
9354 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9356 path = gtk_tree_path_new_from_indices (completion->priv->current_selected - matches, -1);
9357 gtk_tree_view_set_cursor (GTK_TREE_VIEW (completion->priv->action_view),
9360 if (completion->priv->inline_selection &&
9361 completion->priv->completion_prefix)
9363 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9364 completion->priv->completion_prefix);
9365 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9369 gtk_tree_path_free (path);
9373 else if (event->keyval == GDK_Escape ||
9374 event->keyval == GDK_Left ||
9375 event->keyval == GDK_KP_Left ||
9376 event->keyval == GDK_Right ||
9377 event->keyval == GDK_KP_Right)
9379 gboolean retval = TRUE;
9381 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9382 _gtk_entry_completion_popdown (completion);
9384 if (completion->priv->current_selected < 0)
9387 goto keypress_completion_out;
9389 else if (completion->priv->inline_selection)
9391 /* Escape rejects the tentative completion */
9392 if (event->keyval == GDK_Escape)
9394 if (completion->priv->completion_prefix)
9395 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9396 completion->priv->completion_prefix);
9398 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry), "");
9401 /* Move the cursor to the end for Right/Esc, to the
9402 beginning for Left */
9403 if (event->keyval == GDK_Right ||
9404 event->keyval == GDK_KP_Right ||
9405 event->keyval == GDK_Escape)
9406 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9408 gtk_editable_set_position (GTK_EDITABLE (widget), 0);
9411 keypress_completion_out:
9412 if (completion->priv->inline_selection)
9414 g_free (completion->priv->completion_prefix);
9415 completion->priv->completion_prefix = NULL;
9420 else if (event->keyval == GDK_Tab ||
9421 event->keyval == GDK_KP_Tab ||
9422 event->keyval == GDK_ISO_Left_Tab)
9424 GtkDirectionType dir = event->keyval == GDK_ISO_Left_Tab ?
9425 GTK_DIR_TAB_BACKWARD : GTK_DIR_TAB_FORWARD;
9427 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9428 _gtk_entry_completion_popdown (completion);
9430 g_free (completion->priv->completion_prefix);
9431 completion->priv->completion_prefix = NULL;
9433 gtk_widget_child_focus (gtk_widget_get_toplevel (widget), dir);
9437 else if (event->keyval == GDK_ISO_Enter ||
9438 event->keyval == GDK_KP_Enter ||
9439 event->keyval == GDK_Return)
9442 GtkTreeModel *model = NULL;
9443 GtkTreeSelection *sel;
9444 gboolean retval = TRUE;
9446 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9447 _gtk_entry_completion_popdown (completion);
9449 if (completion->priv->current_selected < matches)
9453 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view));
9454 if (gtk_tree_selection_get_selected (sel, &model, &iter))
9456 g_signal_handler_block (widget, completion->priv->changed_id);
9457 g_signal_emit_by_name (completion, "match-selected",
9458 model, &iter, &entry_set);
9459 g_signal_handler_unblock (widget, completion->priv->changed_id);
9465 gtk_tree_model_get (model, &iter,
9466 completion->priv->text_column, &str,
9469 gtk_entry_set_text (GTK_ENTRY (widget), str);
9471 /* move the cursor to the end */
9472 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9480 else if (completion->priv->current_selected - matches >= 0)
9482 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view));
9483 if (gtk_tree_selection_get_selected (sel, &model, &iter))
9487 path = gtk_tree_path_new_from_indices (completion->priv->current_selected - matches, -1);
9488 g_signal_emit_by_name (completion, "action-activated",
9489 gtk_tree_path_get_indices (path)[0]);
9490 gtk_tree_path_free (path);
9496 g_free (completion->priv->completion_prefix);
9497 completion->priv->completion_prefix = NULL;
9506 gtk_entry_completion_changed (GtkWidget *entry,
9509 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
9510 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
9513 /* (re)install completion timeout */
9514 if (completion->priv->completion_timeout)
9515 g_source_remove (completion->priv->completion_timeout);
9517 if (!gtk_entry_get_text (GTK_ENTRY (entry)))
9520 /* no need to normalize for this test */
9521 if (completion->priv->minimum_key_length > 0 &&
9522 strcmp ("", gtk_entry_get_text (GTK_ENTRY (entry))) == 0)
9524 if (gtk_widget_get_visible (completion->priv->popup_window))
9525 _gtk_entry_completion_popdown (completion);
9529 device = gtk_get_current_event_device ();
9531 if (device && device->source == GDK_SOURCE_KEYBOARD)
9532 device = gdk_device_get_associated_device (device);
9535 priv->completion_device = device;
9537 completion->priv->completion_timeout =
9538 gdk_threads_add_timeout (COMPLETION_TIMEOUT,
9539 gtk_entry_completion_timeout,
9544 check_completion_callback (GtkEntryCompletion *completion)
9546 completion->priv->check_completion_idle = NULL;
9548 gtk_entry_completion_complete (completion);
9549 gtk_entry_completion_insert_prefix (completion);
9555 clear_completion_callback (GtkEntry *entry,
9558 if (pspec->name == I_("cursor-position") ||
9559 pspec->name == I_("selection-bound"))
9561 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
9563 completion->priv->has_completion = FALSE;
9568 accept_completion_callback (GtkEntry *entry)
9570 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
9572 if (completion->priv->has_completion)
9573 gtk_editable_set_position (GTK_EDITABLE (entry),
9574 gtk_entry_buffer_get_length (get_buffer (entry)));
9580 completion_insert_text_callback (GtkEntry *entry,
9584 GtkEntryCompletion *completion)
9586 /* idle to update the selection based on the file list */
9587 if (completion->priv->check_completion_idle == NULL)
9589 completion->priv->check_completion_idle = g_idle_source_new ();
9590 g_source_set_priority (completion->priv->check_completion_idle, G_PRIORITY_HIGH);
9591 g_source_set_closure (completion->priv->check_completion_idle,
9592 g_cclosure_new_object (G_CALLBACK (check_completion_callback),
9593 G_OBJECT (completion)));
9594 g_source_attach (completion->priv->check_completion_idle, NULL);
9599 completion_changed (GtkEntryCompletion *completion,
9603 GtkEntry *entry = GTK_ENTRY (data);
9605 if (pspec->name == I_("popup-completion") ||
9606 pspec->name == I_("inline-completion"))
9608 disconnect_completion_signals (entry, completion);
9609 connect_completion_signals (entry, completion);
9614 disconnect_completion_signals (GtkEntry *entry,
9615 GtkEntryCompletion *completion)
9617 g_signal_handlers_disconnect_by_func (completion,
9618 G_CALLBACK (completion_changed), entry);
9619 if (completion->priv->changed_id > 0 &&
9620 g_signal_handler_is_connected (entry, completion->priv->changed_id))
9622 g_signal_handler_disconnect (entry, completion->priv->changed_id);
9623 completion->priv->changed_id = 0;
9625 g_signal_handlers_disconnect_by_func (entry,
9626 G_CALLBACK (gtk_entry_completion_key_press), completion);
9627 if (completion->priv->insert_text_id > 0 &&
9628 g_signal_handler_is_connected (entry, completion->priv->insert_text_id))
9630 g_signal_handler_disconnect (entry, completion->priv->insert_text_id);
9631 completion->priv->insert_text_id = 0;
9633 g_signal_handlers_disconnect_by_func (entry,
9634 G_CALLBACK (completion_insert_text_callback), completion);
9635 g_signal_handlers_disconnect_by_func (entry,
9636 G_CALLBACK (clear_completion_callback), completion);
9637 g_signal_handlers_disconnect_by_func (entry,
9638 G_CALLBACK (accept_completion_callback), completion);
9642 connect_completion_signals (GtkEntry *entry,
9643 GtkEntryCompletion *completion)
9645 if (completion->priv->popup_completion)
9647 completion->priv->changed_id =
9648 g_signal_connect (entry, "changed",
9649 G_CALLBACK (gtk_entry_completion_changed), completion);
9650 g_signal_connect (entry, "key-press-event",
9651 G_CALLBACK (gtk_entry_completion_key_press), completion);
9654 if (completion->priv->inline_completion)
9656 completion->priv->insert_text_id =
9657 g_signal_connect (entry, "insert-text",
9658 G_CALLBACK (completion_insert_text_callback), completion);
9659 g_signal_connect (entry, "notify",
9660 G_CALLBACK (clear_completion_callback), completion);
9661 g_signal_connect (entry, "activate",
9662 G_CALLBACK (accept_completion_callback), completion);
9663 g_signal_connect (entry, "focus-out-event",
9664 G_CALLBACK (accept_completion_callback), completion);
9667 g_signal_connect (completion, "notify",
9668 G_CALLBACK (completion_changed), entry);
9672 * gtk_entry_set_completion:
9673 * @entry: A #GtkEntry
9674 * @completion: (allow-none): The #GtkEntryCompletion or %NULL
9676 * Sets @completion to be the auxiliary completion object to use with @entry.
9677 * All further configuration of the completion mechanism is done on
9678 * @completion using the #GtkEntryCompletion API. Completion is disabled if
9679 * @completion is set to %NULL.
9684 gtk_entry_set_completion (GtkEntry *entry,
9685 GtkEntryCompletion *completion)
9687 GtkEntryCompletion *old;
9689 g_return_if_fail (GTK_IS_ENTRY (entry));
9690 g_return_if_fail (!completion || GTK_IS_ENTRY_COMPLETION (completion));
9692 old = gtk_entry_get_completion (entry);
9694 if (old == completion)
9699 if (old->priv->completion_timeout)
9701 g_source_remove (old->priv->completion_timeout);
9702 old->priv->completion_timeout = 0;
9705 if (gtk_widget_get_mapped (old->priv->popup_window))
9706 _gtk_entry_completion_popdown (old);
9708 disconnect_completion_signals (entry, old);
9709 old->priv->entry = NULL;
9711 g_object_unref (old);
9716 g_object_set_data (G_OBJECT (entry), I_(GTK_ENTRY_COMPLETION_KEY), NULL);
9720 /* hook into the entry */
9721 g_object_ref (completion);
9723 connect_completion_signals (entry, completion);
9724 completion->priv->entry = GTK_WIDGET (entry);
9725 g_object_set_data (G_OBJECT (entry), I_(GTK_ENTRY_COMPLETION_KEY), completion);
9729 * gtk_entry_get_completion:
9730 * @entry: A #GtkEntry
9732 * Returns the auxiliary completion object currently in use by @entry.
9734 * Return value: The auxiliary completion object currently in use by @entry.
9738 GtkEntryCompletion *
9739 gtk_entry_get_completion (GtkEntry *entry)
9741 GtkEntryCompletion *completion;
9743 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
9745 completion = GTK_ENTRY_COMPLETION (g_object_get_data (G_OBJECT (entry),
9746 GTK_ENTRY_COMPLETION_KEY));
9752 * gtk_entry_set_cursor_hadjustment:
9753 * @entry: a #GtkEntry
9754 * @adjustment: an adjustment which should be adjusted when the cursor
9755 * is moved, or %NULL
9757 * Hooks up an adjustment to the cursor position in an entry, so that when
9758 * the cursor is moved, the adjustment is scrolled to show that position.
9759 * See gtk_scrolled_window_get_hadjustment() for a typical way of obtaining
9762 * The adjustment has to be in pixel units and in the same coordinate system
9768 gtk_entry_set_cursor_hadjustment (GtkEntry *entry,
9769 GtkAdjustment *adjustment)
9771 g_return_if_fail (GTK_IS_ENTRY (entry));
9773 g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
9776 g_object_ref (adjustment);
9778 g_object_set_qdata_full (G_OBJECT (entry),
9779 quark_cursor_hadjustment,
9785 * gtk_entry_get_cursor_hadjustment:
9786 * @entry: a #GtkEntry
9788 * Retrieves the horizontal cursor adjustment for the entry.
9789 * See gtk_entry_set_cursor_hadjustment().
9791 * Return value: (transfer none): the horizontal cursor adjustment, or %NULL
9792 * if none has been set.
9797 gtk_entry_get_cursor_hadjustment (GtkEntry *entry)
9799 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
9801 return g_object_get_qdata (G_OBJECT (entry), quark_cursor_hadjustment);
9805 * gtk_entry_set_progress_fraction:
9806 * @entry: a #GtkEntry
9807 * @fraction: fraction of the task that's been completed
9809 * Causes the entry's progress indicator to "fill in" the given
9810 * fraction of the bar. The fraction should be between 0.0 and 1.0,
9816 gtk_entry_set_progress_fraction (GtkEntry *entry,
9820 GtkEntryPrivate *private;
9821 gdouble old_fraction;
9822 gint x, y, width, height;
9823 gint old_x, old_y, old_width, old_height;
9825 g_return_if_fail (GTK_IS_ENTRY (entry));
9827 widget = GTK_WIDGET (entry);
9828 private = GTK_ENTRY_GET_PRIVATE (entry);
9830 if (private->progress_pulse_mode)
9833 old_fraction = private->progress_fraction;
9835 if (gtk_widget_is_drawable (widget))
9836 get_progress_area (widget, &old_x, &old_y, &old_width, &old_height);
9838 fraction = CLAMP (fraction, 0.0, 1.0);
9840 private->progress_fraction = fraction;
9841 private->progress_pulse_mode = FALSE;
9842 private->progress_pulse_current = 0.0;
9844 if (gtk_widget_is_drawable (widget))
9846 get_progress_area (widget, &x, &y, &width, &height);
9848 if ((x != old_x) || (y != old_y) || (width != old_width) || (height != old_height))
9849 gtk_widget_queue_draw (widget);
9852 if (fraction != old_fraction)
9853 g_object_notify (G_OBJECT (entry), "progress-fraction");
9857 * gtk_entry_get_progress_fraction:
9858 * @entry: a #GtkEntry
9860 * Returns the current fraction of the task that's been completed.
9861 * See gtk_entry_set_progress_fraction().
9863 * Return value: a fraction from 0.0 to 1.0
9868 gtk_entry_get_progress_fraction (GtkEntry *entry)
9870 GtkEntryPrivate *private;
9872 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
9874 private = GTK_ENTRY_GET_PRIVATE (entry);
9876 return private->progress_fraction;
9880 * gtk_entry_set_progress_pulse_step:
9881 * @entry: a #GtkEntry
9882 * @fraction: fraction between 0.0 and 1.0
9884 * Sets the fraction of total entry width to move the progress
9885 * bouncing block for each call to gtk_entry_progress_pulse().
9890 gtk_entry_set_progress_pulse_step (GtkEntry *entry,
9893 GtkEntryPrivate *private;
9895 g_return_if_fail (GTK_IS_ENTRY (entry));
9897 private = GTK_ENTRY_GET_PRIVATE (entry);
9899 fraction = CLAMP (fraction, 0.0, 1.0);
9901 if (fraction != private->progress_pulse_fraction)
9903 private->progress_pulse_fraction = fraction;
9905 gtk_widget_queue_draw (GTK_WIDGET (entry));
9907 g_object_notify (G_OBJECT (entry), "progress-pulse-step");
9912 * gtk_entry_get_progress_pulse_step:
9913 * @entry: a #GtkEntry
9915 * Retrieves the pulse step set with gtk_entry_set_progress_pulse_step().
9917 * Return value: a fraction from 0.0 to 1.0
9922 gtk_entry_get_progress_pulse_step (GtkEntry *entry)
9924 GtkEntryPrivate *private;
9926 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
9928 private = GTK_ENTRY_GET_PRIVATE (entry);
9930 return private->progress_pulse_fraction;
9934 * gtk_entry_progress_pulse:
9935 * @entry: a #GtkEntry
9937 * Indicates that some progress is made, but you don't know how much.
9938 * Causes the entry's progress indicator to enter "activity mode,"
9939 * where a block bounces back and forth. Each call to
9940 * gtk_entry_progress_pulse() causes the block to move by a little bit
9941 * (the amount of movement per pulse is determined by
9942 * gtk_entry_set_progress_pulse_step()).
9947 gtk_entry_progress_pulse (GtkEntry *entry)
9949 GtkEntryPrivate *private;
9951 g_return_if_fail (GTK_IS_ENTRY (entry));
9953 private = GTK_ENTRY_GET_PRIVATE (entry);
9955 if (private->progress_pulse_mode)
9957 if (private->progress_pulse_way_back)
9959 private->progress_pulse_current -= private->progress_pulse_fraction;
9961 if (private->progress_pulse_current < 0.0)
9963 private->progress_pulse_current = 0.0;
9964 private->progress_pulse_way_back = FALSE;
9969 private->progress_pulse_current += private->progress_pulse_fraction;
9971 if (private->progress_pulse_current > 1.0 - private->progress_pulse_fraction)
9973 private->progress_pulse_current = 1.0 - private->progress_pulse_fraction;
9974 private->progress_pulse_way_back = TRUE;
9980 private->progress_fraction = 0.0;
9981 private->progress_pulse_mode = TRUE;
9982 private->progress_pulse_way_back = FALSE;
9983 private->progress_pulse_current = 0.0;
9986 gtk_widget_queue_draw (GTK_WIDGET (entry));
9989 /* Caps Lock warning for password entries */
9992 show_capslock_feedback (GtkEntry *entry,
9995 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
9997 if (gtk_entry_get_icon_storage_type (entry, GTK_ENTRY_ICON_SECONDARY) == GTK_IMAGE_EMPTY)
9999 gtk_entry_set_icon_from_stock (entry, GTK_ENTRY_ICON_SECONDARY, GTK_STOCK_CAPS_LOCK_WARNING);
10000 gtk_entry_set_icon_activatable (entry, GTK_ENTRY_ICON_SECONDARY, FALSE);
10001 priv->caps_lock_warning_shown = TRUE;
10004 if (priv->caps_lock_warning_shown)
10005 gtk_entry_set_icon_tooltip_text (entry, GTK_ENTRY_ICON_SECONDARY, text);
10007 g_warning ("Can't show Caps Lock warning, since secondary icon is set");
10011 remove_capslock_feedback (GtkEntry *entry)
10013 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
10015 if (priv->caps_lock_warning_shown)
10017 gtk_entry_set_icon_from_stock (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
10018 priv->caps_lock_warning_shown = FALSE;
10023 keymap_state_changed (GdkKeymap *keymap,
10026 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
10029 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL && priv->caps_lock_warning)
10031 if (gdk_keymap_get_num_lock_state (keymap)
10032 && gdk_keymap_get_caps_lock_state (keymap))
10033 text = _("Caps Lock and Num Lock are on");
10034 else if (gdk_keymap_get_num_lock_state (keymap))
10035 text = _("Num Lock is on");
10036 else if (gdk_keymap_get_caps_lock_state (keymap))
10037 text = _("Caps Lock is on");
10041 show_capslock_feedback (entry, text);
10043 remove_capslock_feedback (entry);