1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* GTK - The GIMP Toolkit
3 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * Copyright (C) 2004-2006 Christian Hammond
5 * Copyright (C) 2008 Cody Russell
6 * Copyright (C) 2008 Red Hat, Inc.
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
25 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
26 * file for a list of people on the GTK+ Team. See the ChangeLog
27 * files for a list of changes. These files are distributed with
28 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
36 #include "gdk/gdkkeysyms.h"
37 #include "gtkalignment.h"
38 #include "gtkbindings.h"
39 #include "gtkcelleditable.h"
40 #include "gtkclipboard.h"
43 #include "gtkentrybuffer.h"
44 #include "gtkimagemenuitem.h"
45 #include "gtkimcontextsimple.h"
46 #include "gtkimmulticontext.h"
50 #include "gtkmarshalers.h"
52 #include "gtkmenuitem.h"
53 #include "gtkseparatormenuitem.h"
54 #include "gtkselection.h"
55 #include "gtksettings.h"
56 #include "gtkspinbutton.h"
58 #include "gtktextutil.h"
59 #include "gtkwindow.h"
60 #include "gtktreeview.h"
61 #include "gtktreeselection.h"
62 #include "gtkprivate.h"
63 #include "gtkentryprivate.h"
64 #include "gtkcelllayout.h"
65 #include "gtktooltip.h"
66 #include "gtkiconfactory.h"
67 #include "gtkicontheme.h"
70 #define GTK_ENTRY_COMPLETION_KEY "gtk-entry-completion-key"
72 #define MIN_ENTRY_WIDTH 150
73 #define DRAW_TIMEOUT 20
74 #define COMPLETION_TIMEOUT 300
75 #define PASSWORD_HINT_MAX 8
79 #define IS_VALID_ICON_POSITION(pos) \
80 ((pos) == GTK_ENTRY_ICON_PRIMARY || \
81 (pos) == GTK_ENTRY_ICON_SECONDARY)
83 static const GtkBorder default_inner_border = { 2, 2, 2, 2 };
84 static GQuark quark_inner_border = 0;
85 static GQuark quark_password_hint = 0;
86 static GQuark quark_cursor_hadjustment = 0;
87 static GQuark quark_capslock_feedback = 0;
89 typedef struct _GtkEntryPrivate GtkEntryPrivate;
91 #define GTK_ENTRY_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_ENTRY, GtkEntryPrivate))
97 guint insensitive : 1;
98 guint nonactivatable : 1;
103 GtkImageType storage_type;
109 GtkTargetList *target_list;
110 GdkDragAction actions;
113 struct _GtkEntryPrivate
115 GtkEntryBuffer* buffer;
119 guint blink_time; /* time in msec the cursor has blinked since last user event */
120 guint interior_focus : 1;
121 guint real_changed : 1;
122 guint invisible_char_set : 1;
123 guint caps_lock_warning : 1;
124 guint caps_lock_warning_shown : 1;
125 guint change_count : 8;
126 guint progress_pulse_mode : 1;
127 guint progress_pulse_way_back : 1;
130 GtkShadowType shadow_type;
132 gdouble progress_fraction;
133 gdouble progress_pulse_fraction;
134 gdouble progress_pulse_current;
136 EntryIconInfo *icons[MAX_ICONS];
144 typedef struct _GtkEntryPasswordHint GtkEntryPasswordHint;
146 struct _GtkEntryPasswordHint
148 gint position; /* Position (in text) of the last password hint */
149 guint source_id; /* Timeout source id */
152 typedef struct _GtkEntryCapslockFeedback GtkEntryCapslockFeedback;
154 struct _GtkEntryCapslockFeedback
181 PROP_CURSOR_POSITION,
182 PROP_SELECTION_BOUND,
189 PROP_ACTIVATES_DEFAULT,
194 PROP_TRUNCATE_MULTILINE,
198 PROP_INVISIBLE_CHAR_SET,
199 PROP_CAPS_LOCK_WARNING,
200 PROP_PROGRESS_FRACTION,
201 PROP_PROGRESS_PULSE_STEP,
203 PROP_PIXBUF_SECONDARY,
205 PROP_STOCK_SECONDARY,
206 PROP_ICON_NAME_PRIMARY,
207 PROP_ICON_NAME_SECONDARY,
209 PROP_GICON_SECONDARY,
210 PROP_STORAGE_TYPE_PRIMARY,
211 PROP_STORAGE_TYPE_SECONDARY,
212 PROP_ACTIVATABLE_PRIMARY,
213 PROP_ACTIVATABLE_SECONDARY,
214 PROP_SENSITIVE_PRIMARY,
215 PROP_SENSITIVE_SECONDARY,
216 PROP_TOOLTIP_TEXT_PRIMARY,
217 PROP_TOOLTIP_TEXT_SECONDARY,
218 PROP_TOOLTIP_MARKUP_PRIMARY,
219 PROP_TOOLTIP_MARKUP_SECONDARY,
221 PROP_EDITING_CANCELED
224 static guint signals[LAST_SIGNAL] = { 0 };
233 DISPLAY_NORMAL, /* The entry text is being shown */
234 DISPLAY_INVISIBLE, /* In invisible mode, text replaced by (eg) bullets */
235 DISPLAY_BLANK /* In invisible mode, nothing shown at all */
238 /* GObject, GtkObject methods
240 static void gtk_entry_editable_init (GtkEditableClass *iface);
241 static void gtk_entry_cell_editable_init (GtkCellEditableIface *iface);
242 static void gtk_entry_set_property (GObject *object,
246 static void gtk_entry_get_property (GObject *object,
250 static void gtk_entry_finalize (GObject *object);
251 static void gtk_entry_destroy (GtkObject *object);
252 static void gtk_entry_dispose (GObject *object);
256 static void gtk_entry_realize (GtkWidget *widget);
257 static void gtk_entry_unrealize (GtkWidget *widget);
258 static void gtk_entry_map (GtkWidget *widget);
259 static void gtk_entry_unmap (GtkWidget *widget);
260 static void gtk_entry_size_request (GtkWidget *widget,
261 GtkRequisition *requisition);
262 static void gtk_entry_size_allocate (GtkWidget *widget,
263 GtkAllocation *allocation);
264 static void gtk_entry_draw_frame (GtkWidget *widget,
265 GdkEventExpose *event);
266 static void gtk_entry_draw_progress (GtkWidget *widget,
267 GdkEventExpose *event);
268 static gint gtk_entry_expose (GtkWidget *widget,
269 GdkEventExpose *event);
270 static gint gtk_entry_button_press (GtkWidget *widget,
271 GdkEventButton *event);
272 static gint gtk_entry_button_release (GtkWidget *widget,
273 GdkEventButton *event);
274 static gint gtk_entry_enter_notify (GtkWidget *widget,
275 GdkEventCrossing *event);
276 static gint gtk_entry_leave_notify (GtkWidget *widget,
277 GdkEventCrossing *event);
278 static gint gtk_entry_motion_notify (GtkWidget *widget,
279 GdkEventMotion *event);
280 static gint gtk_entry_key_press (GtkWidget *widget,
282 static gint gtk_entry_key_release (GtkWidget *widget,
284 static gint gtk_entry_focus_in (GtkWidget *widget,
285 GdkEventFocus *event);
286 static gint gtk_entry_focus_out (GtkWidget *widget,
287 GdkEventFocus *event);
288 static void gtk_entry_grab_focus (GtkWidget *widget);
289 static void gtk_entry_style_set (GtkWidget *widget,
290 GtkStyle *previous_style);
291 static gboolean gtk_entry_query_tooltip (GtkWidget *widget,
294 gboolean keyboard_tip,
295 GtkTooltip *tooltip);
296 static void gtk_entry_direction_changed (GtkWidget *widget,
297 GtkTextDirection previous_dir);
298 static void gtk_entry_state_changed (GtkWidget *widget,
299 GtkStateType previous_state);
300 static void gtk_entry_screen_changed (GtkWidget *widget,
301 GdkScreen *old_screen);
303 static gboolean gtk_entry_drag_drop (GtkWidget *widget,
304 GdkDragContext *context,
308 static gboolean gtk_entry_drag_motion (GtkWidget *widget,
309 GdkDragContext *context,
313 static void gtk_entry_drag_leave (GtkWidget *widget,
314 GdkDragContext *context,
316 static void gtk_entry_drag_data_received (GtkWidget *widget,
317 GdkDragContext *context,
320 GtkSelectionData *selection_data,
323 static void gtk_entry_drag_data_get (GtkWidget *widget,
324 GdkDragContext *context,
325 GtkSelectionData *selection_data,
328 static void gtk_entry_drag_data_delete (GtkWidget *widget,
329 GdkDragContext *context);
330 static void gtk_entry_drag_begin (GtkWidget *widget,
331 GdkDragContext *context);
332 static void gtk_entry_drag_end (GtkWidget *widget,
333 GdkDragContext *context);
336 /* GtkEditable method implementations
338 static void gtk_entry_insert_text (GtkEditable *editable,
339 const gchar *new_text,
340 gint new_text_length,
342 static void gtk_entry_delete_text (GtkEditable *editable,
345 static gchar * gtk_entry_get_chars (GtkEditable *editable,
348 static void gtk_entry_real_set_position (GtkEditable *editable,
350 static gint gtk_entry_get_position (GtkEditable *editable);
351 static void gtk_entry_set_selection_bounds (GtkEditable *editable,
354 static gboolean gtk_entry_get_selection_bounds (GtkEditable *editable,
358 /* GtkCellEditable method implementations
360 static void gtk_entry_start_editing (GtkCellEditable *cell_editable,
363 /* Default signal handlers
365 static void gtk_entry_real_insert_text (GtkEditable *editable,
366 const gchar *new_text,
367 gint new_text_length,
369 static void gtk_entry_real_delete_text (GtkEditable *editable,
372 static void gtk_entry_move_cursor (GtkEntry *entry,
373 GtkMovementStep step,
375 gboolean extend_selection);
376 static void gtk_entry_insert_at_cursor (GtkEntry *entry,
378 static void gtk_entry_delete_from_cursor (GtkEntry *entry,
381 static void gtk_entry_backspace (GtkEntry *entry);
382 static void gtk_entry_cut_clipboard (GtkEntry *entry);
383 static void gtk_entry_copy_clipboard (GtkEntry *entry);
384 static void gtk_entry_paste_clipboard (GtkEntry *entry);
385 static void gtk_entry_toggle_overwrite (GtkEntry *entry);
386 static void gtk_entry_select_all (GtkEntry *entry);
387 static void gtk_entry_real_activate (GtkEntry *entry);
388 static gboolean gtk_entry_popup_menu (GtkWidget *widget);
390 static void keymap_direction_changed (GdkKeymap *keymap,
392 static void keymap_state_changed (GdkKeymap *keymap,
394 static void remove_capslock_feedback (GtkEntry *entry);
396 /* IM Context Callbacks
398 static void gtk_entry_commit_cb (GtkIMContext *context,
401 static void gtk_entry_preedit_changed_cb (GtkIMContext *context,
403 static gboolean gtk_entry_retrieve_surrounding_cb (GtkIMContext *context,
405 static gboolean gtk_entry_delete_surrounding_cb (GtkIMContext *context,
412 static void gtk_entry_enter_text (GtkEntry *entry,
414 static void gtk_entry_set_positions (GtkEntry *entry,
416 gint selection_bound);
417 static void gtk_entry_draw_text (GtkEntry *entry);
418 static void gtk_entry_draw_cursor (GtkEntry *entry,
420 static PangoLayout *gtk_entry_ensure_layout (GtkEntry *entry,
421 gboolean include_preedit);
422 static void gtk_entry_reset_layout (GtkEntry *entry);
423 static void gtk_entry_queue_draw (GtkEntry *entry);
424 static void gtk_entry_recompute (GtkEntry *entry);
425 static gint gtk_entry_find_position (GtkEntry *entry,
427 static void gtk_entry_get_cursor_locations (GtkEntry *entry,
431 static void gtk_entry_adjust_scroll (GtkEntry *entry);
432 static gint gtk_entry_move_visually (GtkEntry *editable,
435 static gint gtk_entry_move_logically (GtkEntry *entry,
438 static gint gtk_entry_move_forward_word (GtkEntry *entry,
440 gboolean allow_whitespace);
441 static gint gtk_entry_move_backward_word (GtkEntry *entry,
443 gboolean allow_whitespace);
444 static void gtk_entry_delete_whitespace (GtkEntry *entry);
445 static void gtk_entry_select_word (GtkEntry *entry);
446 static void gtk_entry_select_line (GtkEntry *entry);
447 static void gtk_entry_paste (GtkEntry *entry,
449 static void gtk_entry_update_primary_selection (GtkEntry *entry);
450 static void gtk_entry_do_popup (GtkEntry *entry,
451 GdkEventButton *event);
452 static gboolean gtk_entry_mnemonic_activate (GtkWidget *widget,
453 gboolean group_cycling);
454 static void gtk_entry_check_cursor_blink (GtkEntry *entry);
455 static void gtk_entry_pend_cursor_blink (GtkEntry *entry);
456 static void gtk_entry_reset_blink_time (GtkEntry *entry);
457 static void gtk_entry_get_text_area_size (GtkEntry *entry,
462 static void get_text_area_size (GtkEntry *entry,
467 static void get_widget_window_size (GtkEntry *entry,
472 static void gtk_entry_move_adjustments (GtkEntry *entry);
473 static void gtk_entry_ensure_pixbuf (GtkEntry *entry,
474 GtkEntryIconPosition icon_pos);
478 static gint gtk_entry_completion_timeout (gpointer data);
479 static gboolean gtk_entry_completion_key_press (GtkWidget *widget,
482 static void gtk_entry_completion_changed (GtkWidget *entry,
484 static gboolean check_completion_callback (GtkEntryCompletion *completion);
485 static void clear_completion_callback (GtkEntry *entry,
487 static gboolean accept_completion_callback (GtkEntry *entry);
488 static void completion_insert_text_callback (GtkEntry *entry,
492 GtkEntryCompletion *completion);
493 static void completion_changed (GtkEntryCompletion *completion,
496 static void disconnect_completion_signals (GtkEntry *entry,
497 GtkEntryCompletion *completion);
498 static void connect_completion_signals (GtkEntry *entry,
499 GtkEntryCompletion *completion);
501 static void begin_change (GtkEntry *entry);
502 static void end_change (GtkEntry *entry);
503 static void emit_changed (GtkEntry *entry);
506 static void buffer_inserted_text (GtkEntryBuffer *buffer,
511 static void buffer_deleted_text (GtkEntryBuffer *buffer,
515 static void buffer_notify_text (GtkEntryBuffer *buffer,
518 static void buffer_notify_length (GtkEntryBuffer *buffer,
521 static void buffer_notify_max_length (GtkEntryBuffer *buffer,
524 static void buffer_connect_signals (GtkEntry *entry);
525 static void buffer_disconnect_signals (GtkEntry *entry);
526 static GtkEntryBuffer *get_buffer (GtkEntry *entry);
529 G_DEFINE_TYPE_WITH_CODE (GtkEntry, gtk_entry, GTK_TYPE_WIDGET,
530 G_IMPLEMENT_INTERFACE (GTK_TYPE_EDITABLE,
531 gtk_entry_editable_init)
532 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_EDITABLE,
533 gtk_entry_cell_editable_init))
536 add_move_binding (GtkBindingSet *binding_set,
539 GtkMovementStep step,
542 g_return_if_fail ((modmask & GDK_SHIFT_MASK) == 0);
544 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
548 G_TYPE_BOOLEAN, FALSE);
550 /* Selection-extending version */
551 gtk_binding_entry_add_signal (binding_set, keyval, modmask | GDK_SHIFT_MASK,
555 G_TYPE_BOOLEAN, TRUE);
559 gtk_entry_class_init (GtkEntryClass *class)
561 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
562 GtkWidgetClass *widget_class;
563 GtkObjectClass *gtk_object_class;
564 GtkBindingSet *binding_set;
566 widget_class = (GtkWidgetClass*) class;
567 gtk_object_class = (GtkObjectClass *)class;
569 gobject_class->dispose = gtk_entry_dispose;
570 gobject_class->finalize = gtk_entry_finalize;
571 gobject_class->set_property = gtk_entry_set_property;
572 gobject_class->get_property = gtk_entry_get_property;
574 widget_class->map = gtk_entry_map;
575 widget_class->unmap = gtk_entry_unmap;
576 widget_class->realize = gtk_entry_realize;
577 widget_class->unrealize = gtk_entry_unrealize;
578 widget_class->size_request = gtk_entry_size_request;
579 widget_class->size_allocate = gtk_entry_size_allocate;
580 widget_class->expose_event = gtk_entry_expose;
581 widget_class->enter_notify_event = gtk_entry_enter_notify;
582 widget_class->leave_notify_event = gtk_entry_leave_notify;
583 widget_class->button_press_event = gtk_entry_button_press;
584 widget_class->button_release_event = gtk_entry_button_release;
585 widget_class->motion_notify_event = gtk_entry_motion_notify;
586 widget_class->key_press_event = gtk_entry_key_press;
587 widget_class->key_release_event = gtk_entry_key_release;
588 widget_class->focus_in_event = gtk_entry_focus_in;
589 widget_class->focus_out_event = gtk_entry_focus_out;
590 widget_class->grab_focus = gtk_entry_grab_focus;
591 widget_class->style_set = gtk_entry_style_set;
592 widget_class->query_tooltip = gtk_entry_query_tooltip;
593 widget_class->drag_begin = gtk_entry_drag_begin;
594 widget_class->drag_end = gtk_entry_drag_end;
595 widget_class->direction_changed = gtk_entry_direction_changed;
596 widget_class->state_changed = gtk_entry_state_changed;
597 widget_class->screen_changed = gtk_entry_screen_changed;
598 widget_class->mnemonic_activate = gtk_entry_mnemonic_activate;
600 widget_class->drag_drop = gtk_entry_drag_drop;
601 widget_class->drag_motion = gtk_entry_drag_motion;
602 widget_class->drag_leave = gtk_entry_drag_leave;
603 widget_class->drag_data_received = gtk_entry_drag_data_received;
604 widget_class->drag_data_get = gtk_entry_drag_data_get;
605 widget_class->drag_data_delete = gtk_entry_drag_data_delete;
607 widget_class->popup_menu = gtk_entry_popup_menu;
609 gtk_object_class->destroy = gtk_entry_destroy;
611 class->move_cursor = gtk_entry_move_cursor;
612 class->insert_at_cursor = gtk_entry_insert_at_cursor;
613 class->delete_from_cursor = gtk_entry_delete_from_cursor;
614 class->backspace = gtk_entry_backspace;
615 class->cut_clipboard = gtk_entry_cut_clipboard;
616 class->copy_clipboard = gtk_entry_copy_clipboard;
617 class->paste_clipboard = gtk_entry_paste_clipboard;
618 class->toggle_overwrite = gtk_entry_toggle_overwrite;
619 class->activate = gtk_entry_real_activate;
620 class->get_text_area_size = gtk_entry_get_text_area_size;
622 quark_inner_border = g_quark_from_static_string ("gtk-entry-inner-border");
623 quark_password_hint = g_quark_from_static_string ("gtk-entry-password-hint");
624 quark_cursor_hadjustment = g_quark_from_static_string ("gtk-hadjustment");
625 quark_capslock_feedback = g_quark_from_static_string ("gtk-entry-capslock-feedback");
627 g_object_class_override_property (gobject_class,
628 PROP_EDITING_CANCELED,
631 g_object_class_install_property (gobject_class,
633 g_param_spec_object ("buffer",
635 P_("Text buffer object which actually stores entry text"),
636 GTK_TYPE_ENTRY_BUFFER,
637 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT));
639 g_object_class_install_property (gobject_class,
640 PROP_CURSOR_POSITION,
641 g_param_spec_int ("cursor-position",
642 P_("Cursor Position"),
643 P_("The current position of the insertion cursor in chars"),
645 GTK_ENTRY_BUFFER_MAX_SIZE,
647 GTK_PARAM_READABLE));
649 g_object_class_install_property (gobject_class,
650 PROP_SELECTION_BOUND,
651 g_param_spec_int ("selection-bound",
652 P_("Selection Bound"),
653 P_("The position of the opposite end of the selection from the cursor in chars"),
655 GTK_ENTRY_BUFFER_MAX_SIZE,
657 GTK_PARAM_READABLE));
659 g_object_class_install_property (gobject_class,
661 g_param_spec_boolean ("editable",
663 P_("Whether the entry contents can be edited"),
665 GTK_PARAM_READWRITE));
667 g_object_class_install_property (gobject_class,
669 g_param_spec_int ("max-length",
670 P_("Maximum length"),
671 P_("Maximum number of characters for this entry. Zero if no maximum"),
673 GTK_ENTRY_BUFFER_MAX_SIZE,
675 GTK_PARAM_READWRITE));
676 g_object_class_install_property (gobject_class,
678 g_param_spec_boolean ("visibility",
680 P_("FALSE displays the \"invisible char\" instead of the actual text (password mode)"),
682 GTK_PARAM_READWRITE));
684 g_object_class_install_property (gobject_class,
686 g_param_spec_boolean ("has-frame",
688 P_("FALSE removes outside bevel from entry"),
690 GTK_PARAM_READWRITE));
692 g_object_class_install_property (gobject_class,
694 g_param_spec_boxed ("inner-border",
696 P_("Border between text and frame. Overrides the inner-border style property"),
698 GTK_PARAM_READWRITE));
700 g_object_class_install_property (gobject_class,
702 g_param_spec_unichar ("invisible-char",
703 P_("Invisible character"),
704 P_("The character to use when masking entry contents (in \"password mode\")"),
706 GTK_PARAM_READWRITE));
708 g_object_class_install_property (gobject_class,
709 PROP_ACTIVATES_DEFAULT,
710 g_param_spec_boolean ("activates-default",
711 P_("Activates default"),
712 P_("Whether to activate the default widget (such as the default button in a dialog) when Enter is pressed"),
714 GTK_PARAM_READWRITE));
715 g_object_class_install_property (gobject_class,
717 g_param_spec_int ("width-chars",
718 P_("Width in chars"),
719 P_("Number of characters to leave space for in the entry"),
723 GTK_PARAM_READWRITE));
725 g_object_class_install_property (gobject_class,
727 g_param_spec_int ("scroll-offset",
729 P_("Number of pixels of the entry scrolled off the screen to the left"),
733 GTK_PARAM_READABLE));
735 g_object_class_install_property (gobject_class,
737 g_param_spec_string ("text",
739 P_("The contents of the entry"),
741 GTK_PARAM_READWRITE));
746 * The horizontal alignment, from 0 (left) to 1 (right).
747 * Reversed for RTL layouts.
751 g_object_class_install_property (gobject_class,
753 g_param_spec_float ("xalign",
755 P_("The horizontal alignment, from 0 (left) to 1 (right). Reversed for RTL layouts."),
759 GTK_PARAM_READWRITE));
762 * GtkEntry:truncate-multiline:
764 * When %TRUE, pasted multi-line text is truncated to the first line.
768 g_object_class_install_property (gobject_class,
769 PROP_TRUNCATE_MULTILINE,
770 g_param_spec_boolean ("truncate-multiline",
771 P_("Truncate multiline"),
772 P_("Whether to truncate multiline pastes to one line."),
774 GTK_PARAM_READWRITE));
777 * GtkEntry:shadow-type:
779 * Which kind of shadow to draw around the entry when
780 * #GtkEntry:has-frame is set to %TRUE.
784 g_object_class_install_property (gobject_class,
786 g_param_spec_enum ("shadow-type",
788 P_("Which kind of shadow to draw around the entry when has-frame is set"),
789 GTK_TYPE_SHADOW_TYPE,
791 GTK_PARAM_READWRITE));
794 * GtkEntry:overwrite-mode:
796 * If text is overwritten when typing in the #GtkEntry.
800 g_object_class_install_property (gobject_class,
802 g_param_spec_boolean ("overwrite-mode",
803 P_("Overwrite mode"),
804 P_("Whether new text overwrites existing text"),
806 GTK_PARAM_READWRITE));
809 * GtkEntry:text-length:
811 * The length of the text in the #GtkEntry.
815 g_object_class_install_property (gobject_class,
817 g_param_spec_uint ("text-length",
819 P_("Length of the text currently in the entry"),
823 GTK_PARAM_READABLE));
825 * GtkEntry:invisible-char-set:
827 * Whether the invisible char has been set for the #GtkEntry.
831 g_object_class_install_property (gobject_class,
832 PROP_INVISIBLE_CHAR_SET,
833 g_param_spec_boolean ("invisible-char-set",
834 P_("Invisible char set"),
835 P_("Whether the invisible char has been set"),
837 GTK_PARAM_READWRITE));
840 * GtkEntry:caps-lock-warning
842 * Whether password entries will show a warning when Caps Lock is on.
844 * Note that the warning is shown using a secondary icon, and thus
845 * does not work if you are using the secondary icon position for some
850 g_object_class_install_property (gobject_class,
851 PROP_CAPS_LOCK_WARNING,
852 g_param_spec_boolean ("caps-lock-warning",
853 P_("Caps Lock warning"),
854 P_("Whether password entries will show a warning when Caps Lock is on"),
856 GTK_PARAM_READWRITE));
859 * GtkEntry:progress-fraction:
861 * The current fraction of the task that's been completed.
865 g_object_class_install_property (gobject_class,
866 PROP_PROGRESS_FRACTION,
867 g_param_spec_double ("progress-fraction",
868 P_("Progress Fraction"),
869 P_("The current fraction of the task that's been completed"),
873 GTK_PARAM_READWRITE));
876 * GtkEntry:progress-pulse-step:
878 * The fraction of total entry width to move the progress
879 * bouncing block for each call to gtk_entry_progress_pulse().
883 g_object_class_install_property (gobject_class,
884 PROP_PROGRESS_PULSE_STEP,
885 g_param_spec_double ("progress-pulse-step",
886 P_("Progress Pulse Step"),
887 P_("The fraction of total entry width to move the progress bouncing block for each call to gtk_entry_progress_pulse()"),
891 GTK_PARAM_READWRITE));
894 * GtkEntry:primary-icon-pixbuf:
896 * A pixbuf to use as the primary icon for the entry.
900 g_object_class_install_property (gobject_class,
902 g_param_spec_object ("primary-icon-pixbuf",
903 P_("Primary pixbuf"),
904 P_("Primary pixbuf for the entry"),
906 GTK_PARAM_READWRITE));
909 * GtkEntry:secondary-icon-pixbuf:
911 * An pixbuf to use as the secondary icon for the entry.
915 g_object_class_install_property (gobject_class,
916 PROP_PIXBUF_SECONDARY,
917 g_param_spec_object ("secondary-icon-pixbuf",
918 P_("Secondary pixbuf"),
919 P_("Secondary pixbuf for the entry"),
921 GTK_PARAM_READWRITE));
924 * GtkEntry:primary-icon-stock:
926 * The stock id to use for the primary icon for the entry.
930 g_object_class_install_property (gobject_class,
932 g_param_spec_string ("primary-icon-stock",
933 P_("Primary stock ID"),
934 P_("Stock ID for primary icon"),
936 GTK_PARAM_READWRITE));
939 * GtkEntry:secondary-icon-stock:
941 * The stock id to use for the secondary icon for the entry.
945 g_object_class_install_property (gobject_class,
946 PROP_STOCK_SECONDARY,
947 g_param_spec_string ("secondary-icon-stock",
948 P_("Secondary stock ID"),
949 P_("Stock ID for secondary icon"),
951 GTK_PARAM_READWRITE));
954 * GtkEntry:primary-icon-name:
956 * The icon name to use for the primary icon for the entry.
960 g_object_class_install_property (gobject_class,
961 PROP_ICON_NAME_PRIMARY,
962 g_param_spec_string ("primary-icon-name",
963 P_("Primary icon name"),
964 P_("Icon name for primary icon"),
966 GTK_PARAM_READWRITE));
969 * GtkEntry:secondary-icon-name:
971 * The icon name to use for the secondary icon for the entry.
975 g_object_class_install_property (gobject_class,
976 PROP_ICON_NAME_SECONDARY,
977 g_param_spec_string ("secondary-icon-name",
978 P_("Secondary icon name"),
979 P_("Icon name for secondary icon"),
981 GTK_PARAM_READWRITE));
984 * GtkEntry:primary-icon-gicon:
986 * The #GIcon to use for the primary icon for the entry.
990 g_object_class_install_property (gobject_class,
992 g_param_spec_object ("primary-icon-gicon",
994 P_("GIcon for primary icon"),
996 GTK_PARAM_READWRITE));
999 * GtkEntry:secondary-icon-gicon:
1001 * The #GIcon to use for the secondary icon for the entry.
1005 g_object_class_install_property (gobject_class,
1006 PROP_GICON_SECONDARY,
1007 g_param_spec_object ("secondary-icon-gicon",
1008 P_("Secondary GIcon"),
1009 P_("GIcon for secondary icon"),
1011 GTK_PARAM_READWRITE));
1014 * GtkEntry:primary-icon-storage-type:
1016 * The representation which is used for the primary icon of the entry.
1020 g_object_class_install_property (gobject_class,
1021 PROP_STORAGE_TYPE_PRIMARY,
1022 g_param_spec_enum ("primary-icon-storage-type",
1023 P_("Primary storage type"),
1024 P_("The representation being used for primary icon"),
1025 GTK_TYPE_IMAGE_TYPE,
1027 GTK_PARAM_READABLE));
1030 * GtkEntry:secondary-icon-storage-type:
1032 * The representation which is used for the secondary icon of the entry.
1036 g_object_class_install_property (gobject_class,
1037 PROP_STORAGE_TYPE_SECONDARY,
1038 g_param_spec_enum ("secondary-icon-storage-type",
1039 P_("Secondary storage type"),
1040 P_("The representation being used for secondary icon"),
1041 GTK_TYPE_IMAGE_TYPE,
1043 GTK_PARAM_READABLE));
1046 * GtkEntry:primary-icon-activatable:
1048 * Whether the primary icon is activatable.
1050 * GTK+ emits the #GtkEntry::icon-press and #GtkEntry::icon-release
1051 * signals only on sensitive, activatable icons.
1053 * Sensitive, but non-activatable icons can be used for purely
1054 * informational purposes.
1058 g_object_class_install_property (gobject_class,
1059 PROP_ACTIVATABLE_PRIMARY,
1060 g_param_spec_boolean ("primary-icon-activatable",
1061 P_("Primary icon activatable"),
1062 P_("Whether the primary icon is activatable"),
1064 GTK_PARAM_READWRITE));
1067 * GtkEntry:secondary-icon-activatable:
1069 * Whether the secondary icon is activatable.
1071 * GTK+ emits the #GtkEntry::icon-press and #GtkEntry::icon-release
1072 * signals only on sensitive, activatable icons.
1074 * Sensitive, but non-activatable icons can be used for purely
1075 * informational purposes.
1079 g_object_class_install_property (gobject_class,
1080 PROP_ACTIVATABLE_SECONDARY,
1081 g_param_spec_boolean ("secondary-icon-activatable",
1082 P_("Secondary icon activatable"),
1083 P_("Whether the secondary icon is activatable"),
1085 GTK_PARAM_READWRITE));
1089 * GtkEntry:primary-icon-sensitive:
1091 * Whether the primary icon is sensitive.
1093 * An insensitive icon appears grayed out. GTK+ does not emit the
1094 * #GtkEntry::icon-press and #GtkEntry::icon-release signals and
1095 * does not allow DND from insensitive icons.
1097 * An icon should be set insensitive if the action that would trigger
1098 * when clicked is currently not available.
1102 g_object_class_install_property (gobject_class,
1103 PROP_SENSITIVE_PRIMARY,
1104 g_param_spec_boolean ("primary-icon-sensitive",
1105 P_("Primary icon sensitive"),
1106 P_("Whether the primary icon is sensitive"),
1108 GTK_PARAM_READWRITE));
1111 * GtkEntry:secondary-icon-sensitive:
1113 * Whether the secondary icon is sensitive.
1115 * An insensitive icon appears grayed out. GTK+ does not emit the
1116 * #GtkEntry::icon-press and #GtkEntry::icon-release signals and
1117 * does not allow DND from insensitive icons.
1119 * An icon should be set insensitive if the action that would trigger
1120 * when clicked is currently not available.
1124 g_object_class_install_property (gobject_class,
1125 PROP_SENSITIVE_SECONDARY,
1126 g_param_spec_boolean ("secondary-icon-sensitive",
1127 P_("Secondary icon sensitive"),
1128 P_("Whether the secondary icon is sensitive"),
1130 GTK_PARAM_READWRITE));
1133 * GtkEntry:primary-icon-tooltip-text:
1135 * The contents of the tooltip on the primary icon.
1137 * Also see gtk_entry_set_icon_tooltip_text().
1141 g_object_class_install_property (gobject_class,
1142 PROP_TOOLTIP_TEXT_PRIMARY,
1143 g_param_spec_string ("primary-icon-tooltip-text",
1144 P_("Primary icon tooltip text"),
1145 P_("The contents of the tooltip on the primary icon"),
1147 GTK_PARAM_READWRITE));
1150 * GtkEntry:secondary-icon-tooltip-text:
1152 * The contents of the tooltip on the secondary icon.
1154 * Also see gtk_entry_set_icon_tooltip_text().
1158 g_object_class_install_property (gobject_class,
1159 PROP_TOOLTIP_TEXT_SECONDARY,
1160 g_param_spec_string ("secondary-icon-tooltip-text",
1161 P_("Secondary icon tooltip text"),
1162 P_("The contents of the tooltip on the secondary icon"),
1164 GTK_PARAM_READWRITE));
1167 * GtkEntry:primary-icon-tooltip-markup:
1169 * The contents of the tooltip on the primary icon, which is marked up
1170 * with the <link linkend="PangoMarkupFormat">Pango text markup
1173 * Also see gtk_entry_set_icon_tooltip_markup().
1177 g_object_class_install_property (gobject_class,
1178 PROP_TOOLTIP_MARKUP_PRIMARY,
1179 g_param_spec_string ("primary-icon-tooltip-markup",
1180 P_("Primary icon tooltip markup"),
1181 P_("The contents of the tooltip on the primary icon"),
1183 GTK_PARAM_READWRITE));
1186 * GtkEntry:secondary-icon-tooltip-markup:
1188 * The contents of the tooltip on the secondary icon, which is marked up
1189 * with the <link linkend="PangoMarkupFormat">Pango text markup
1192 * Also see gtk_entry_set_icon_tooltip_markup().
1196 g_object_class_install_property (gobject_class,
1197 PROP_TOOLTIP_MARKUP_SECONDARY,
1198 g_param_spec_string ("secondary-icon-tooltip-markup",
1199 P_("Secondary icon tooltip markup"),
1200 P_("The contents of the tooltip on the secondary icon"),
1202 GTK_PARAM_READWRITE));
1205 * GtkEntry:im-module:
1207 * Which IM (input method) module should be used for this entry.
1208 * See #GtkIMContext.
1210 * Setting this to a non-%NULL value overrides the
1211 * system-wide IM module setting. See the GtkSettings
1212 * #GtkSettings:gtk-im-module property.
1216 g_object_class_install_property (gobject_class,
1218 g_param_spec_string ("im-module",
1220 P_("Which IM module should be used"),
1222 GTK_PARAM_READWRITE));
1225 * GtkEntry:icon-prelight:
1227 * The prelight style property determines whether activatable
1228 * icons prelight on mouseover.
1232 gtk_widget_class_install_style_property (widget_class,
1233 g_param_spec_boolean ("icon-prelight",
1234 P_("Icon Prelight"),
1235 P_("Whether activatable icons should prelight when hovered"),
1237 GTK_PARAM_READABLE));
1240 * GtkEntry:progress-border:
1242 * The border around the progress bar in the entry.
1246 gtk_widget_class_install_style_property (widget_class,
1247 g_param_spec_boxed ("progress-border",
1248 P_("Progress Border"),
1249 P_("Border around the progress bar"),
1251 GTK_PARAM_READABLE));
1254 * GtkEntry:invisible-char:
1256 * The invisible character is used when masking entry contents (in
1257 * \"password mode\")"). When it is not explicitly set with the
1258 * #GtkEntry::invisible-char property, GTK+ determines the character
1259 * to use from a list of possible candidates, depending on availability
1260 * in the current font.
1262 * This style property allows the theme to prepend a character
1263 * to the list of candidates.
1267 gtk_widget_class_install_style_property (widget_class,
1268 g_param_spec_unichar ("invisible-char",
1269 P_("Invisible character"),
1270 P_("The character to use when masking entry contents (in \"password mode\")"),
1272 GTK_PARAM_READABLE));
1275 * GtkEntry::populate-popup:
1276 * @entry: The entry on which the signal is emitted
1277 * @menu: the menu that is being populated
1279 * The ::populate-popup signal gets emitted before showing the
1280 * context menu of the entry.
1282 * If you need to add items to the context menu, connect
1283 * to this signal and append your menuitems to the @menu.
1285 signals[POPULATE_POPUP] =
1286 g_signal_new (I_("populate-popup"),
1287 G_OBJECT_CLASS_TYPE (gobject_class),
1289 G_STRUCT_OFFSET (GtkEntryClass, populate_popup),
1291 _gtk_marshal_VOID__OBJECT,
1295 /* Action signals */
1298 * GtkEntry::activate:
1299 * @entry: The entry on which the signal is emitted
1301 * A <link linkend="keybinding-signals">keybinding signal</link>
1302 * which gets emitted when the user activates the entry.
1304 * Applications should not connect to it, but may emit it with
1305 * g_signal_emit_by_name() if they need to control activation
1308 * The default bindings for this signal are all forms of the Enter key.
1311 g_signal_new (I_("activate"),
1312 G_OBJECT_CLASS_TYPE (gobject_class),
1313 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1314 G_STRUCT_OFFSET (GtkEntryClass, activate),
1316 _gtk_marshal_VOID__VOID,
1318 widget_class->activate_signal = signals[ACTIVATE];
1321 * GtkEntry::move-cursor:
1322 * @entry: the object which received the signal
1323 * @step: the granularity of the move, as a #GtkMovementStep
1324 * @count: the number of @step units to move
1325 * @extend_selection: %TRUE if the move should extend the selection
1327 * The ::move-cursor signal is a
1328 * <link linkend="keybinding-signals">keybinding signal</link>
1329 * which gets emitted when the user initiates a cursor movement.
1330 * If the cursor is not visible in @entry, this signal causes
1331 * the viewport to be moved instead.
1333 * Applications should not connect to it, but may emit it with
1334 * g_signal_emit_by_name() if they need to control the cursor
1337 * The default bindings for this signal come in two variants,
1338 * the variant with the Shift modifier extends the selection,
1339 * the variant without the Shift modifer does not.
1340 * There are too many key combinations to list them all here.
1342 * <listitem>Arrow keys move by individual characters/lines</listitem>
1343 * <listitem>Ctrl-arrow key combinations move by words/paragraphs</listitem>
1344 * <listitem>Home/End keys move to the ends of the buffer</listitem>
1347 signals[MOVE_CURSOR] =
1348 g_signal_new (I_("move-cursor"),
1349 G_OBJECT_CLASS_TYPE (gobject_class),
1350 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1351 G_STRUCT_OFFSET (GtkEntryClass, move_cursor),
1353 _gtk_marshal_VOID__ENUM_INT_BOOLEAN,
1355 GTK_TYPE_MOVEMENT_STEP,
1360 * GtkEntry::insert-at-cursor:
1361 * @entry: the object which received the signal
1362 * @string: the string to insert
1364 * The ::insert-at-cursor signal is a
1365 * <link linkend="keybinding-signals">keybinding signal</link>
1366 * which gets emitted when the user initiates the insertion of a
1367 * fixed string at the cursor.
1369 * This signal has no default bindings.
1371 signals[INSERT_AT_CURSOR] =
1372 g_signal_new (I_("insert-at-cursor"),
1373 G_OBJECT_CLASS_TYPE (gobject_class),
1374 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1375 G_STRUCT_OFFSET (GtkEntryClass, insert_at_cursor),
1377 _gtk_marshal_VOID__STRING,
1382 * GtkEntry::delete-from-cursor:
1383 * @entry: the object which received the signal
1384 * @type: the granularity of the deletion, as a #GtkDeleteType
1385 * @count: the number of @type units to delete
1387 * The ::delete-from-cursor signal is a
1388 * <link linkend="keybinding-signals">keybinding signal</link>
1389 * which gets emitted when the user initiates a text deletion.
1391 * If the @type is %GTK_DELETE_CHARS, GTK+ deletes the selection
1392 * if there is one, otherwise it deletes the requested number
1395 * The default bindings for this signal are
1396 * Delete for deleting a character and Ctrl-Delete for
1399 signals[DELETE_FROM_CURSOR] =
1400 g_signal_new (I_("delete-from-cursor"),
1401 G_OBJECT_CLASS_TYPE (gobject_class),
1402 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1403 G_STRUCT_OFFSET (GtkEntryClass, delete_from_cursor),
1405 _gtk_marshal_VOID__ENUM_INT,
1407 GTK_TYPE_DELETE_TYPE,
1411 * GtkEntry::backspace:
1412 * @entry: the object which received the signal
1414 * The ::backspace signal is a
1415 * <link linkend="keybinding-signals">keybinding signal</link>
1416 * which gets emitted when the user asks for it.
1418 * The default bindings for this signal are
1419 * Backspace and Shift-Backspace.
1421 signals[BACKSPACE] =
1422 g_signal_new (I_("backspace"),
1423 G_OBJECT_CLASS_TYPE (gobject_class),
1424 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1425 G_STRUCT_OFFSET (GtkEntryClass, backspace),
1427 _gtk_marshal_VOID__VOID,
1431 * GtkEntry::cut-clipboard:
1432 * @entry: the object which received the signal
1434 * The ::cut-clipboard signal is a
1435 * <link linkend="keybinding-signals">keybinding signal</link>
1436 * which gets emitted to cut the selection to the clipboard.
1438 * The default bindings for this signal are
1439 * Ctrl-x and Shift-Delete.
1441 signals[CUT_CLIPBOARD] =
1442 g_signal_new (I_("cut-clipboard"),
1443 G_OBJECT_CLASS_TYPE (gobject_class),
1444 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1445 G_STRUCT_OFFSET (GtkEntryClass, cut_clipboard),
1447 _gtk_marshal_VOID__VOID,
1451 * GtkEntry::copy-clipboard:
1452 * @entry: the object which received the signal
1454 * The ::copy-clipboard signal is a
1455 * <link linkend="keybinding-signals">keybinding signal</link>
1456 * which gets emitted to copy the selection to the clipboard.
1458 * The default bindings for this signal are
1459 * Ctrl-c and Ctrl-Insert.
1461 signals[COPY_CLIPBOARD] =
1462 g_signal_new (I_("copy-clipboard"),
1463 G_OBJECT_CLASS_TYPE (gobject_class),
1464 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1465 G_STRUCT_OFFSET (GtkEntryClass, copy_clipboard),
1467 _gtk_marshal_VOID__VOID,
1471 * GtkEntry::paste-clipboard:
1472 * @entry: the object which received the signal
1474 * The ::paste-clipboard signal is a
1475 * <link linkend="keybinding-signals">keybinding signal</link>
1476 * which gets emitted to paste the contents of the clipboard
1477 * into the text view.
1479 * The default bindings for this signal are
1480 * Ctrl-v and Shift-Insert.
1482 signals[PASTE_CLIPBOARD] =
1483 g_signal_new (I_("paste-clipboard"),
1484 G_OBJECT_CLASS_TYPE (gobject_class),
1485 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1486 G_STRUCT_OFFSET (GtkEntryClass, paste_clipboard),
1488 _gtk_marshal_VOID__VOID,
1492 * GtkEntry::toggle-overwrite:
1493 * @entry: the object which received the signal
1495 * The ::toggle-overwrite signal is a
1496 * <link linkend="keybinding-signals">keybinding signal</link>
1497 * which gets emitted to toggle the overwrite mode of the entry.
1499 * The default bindings for this signal is Insert.
1501 signals[TOGGLE_OVERWRITE] =
1502 g_signal_new (I_("toggle-overwrite"),
1503 G_OBJECT_CLASS_TYPE (gobject_class),
1504 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1505 G_STRUCT_OFFSET (GtkEntryClass, toggle_overwrite),
1507 _gtk_marshal_VOID__VOID,
1511 * GtkEntry::icon-press:
1512 * @entry: The entry on which the signal is emitted
1513 * @icon_pos: The position of the clicked icon
1514 * @event: the button press event
1516 * The ::icon-press signal is emitted when an activatable icon
1521 signals[ICON_PRESS] =
1522 g_signal_new (I_("icon-press"),
1523 G_TYPE_FROM_CLASS (gobject_class),
1527 _gtk_marshal_VOID__ENUM_BOXED,
1529 GTK_TYPE_ENTRY_ICON_POSITION,
1530 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1533 * GtkEntry::icon-release:
1534 * @entry: The entry on which the signal is emitted
1535 * @icon_pos: The position of the clicked icon
1536 * @event: the button release event
1538 * The ::icon-release signal is emitted on the button release from a
1539 * mouse click over an activatable icon.
1543 signals[ICON_RELEASE] =
1544 g_signal_new (I_("icon-release"),
1545 G_TYPE_FROM_CLASS (gobject_class),
1549 _gtk_marshal_VOID__ENUM_BOXED,
1551 GTK_TYPE_ENTRY_ICON_POSITION,
1552 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1555 * GtkEntry::preedit-changed:
1556 * @entry: the object which received the signal
1557 * @preedit: the current preedit string
1559 * If an input method is used, the typed text will not immediately
1560 * be committed to the buffer. So if you are interested in the text,
1561 * connect to this signal.
1565 signals[PREEDIT_CHANGED] =
1566 g_signal_new_class_handler (I_("preedit-changed"),
1567 G_OBJECT_CLASS_TYPE (gobject_class),
1568 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1571 _gtk_marshal_VOID__STRING,
1580 binding_set = gtk_binding_set_by_class (class);
1582 /* Moving the insertion point */
1583 add_move_binding (binding_set, GDK_Right, 0,
1584 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1586 add_move_binding (binding_set, GDK_Left, 0,
1587 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1589 add_move_binding (binding_set, GDK_KP_Right, 0,
1590 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1592 add_move_binding (binding_set, GDK_KP_Left, 0,
1593 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1595 add_move_binding (binding_set, GDK_Right, GDK_CONTROL_MASK,
1596 GTK_MOVEMENT_WORDS, 1);
1598 add_move_binding (binding_set, GDK_Left, GDK_CONTROL_MASK,
1599 GTK_MOVEMENT_WORDS, -1);
1601 add_move_binding (binding_set, GDK_KP_Right, GDK_CONTROL_MASK,
1602 GTK_MOVEMENT_WORDS, 1);
1604 add_move_binding (binding_set, GDK_KP_Left, GDK_CONTROL_MASK,
1605 GTK_MOVEMENT_WORDS, -1);
1607 add_move_binding (binding_set, GDK_Home, 0,
1608 GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
1610 add_move_binding (binding_set, GDK_End, 0,
1611 GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
1613 add_move_binding (binding_set, GDK_KP_Home, 0,
1614 GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
1616 add_move_binding (binding_set, GDK_KP_End, 0,
1617 GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
1619 add_move_binding (binding_set, GDK_Home, GDK_CONTROL_MASK,
1620 GTK_MOVEMENT_BUFFER_ENDS, -1);
1622 add_move_binding (binding_set, GDK_End, GDK_CONTROL_MASK,
1623 GTK_MOVEMENT_BUFFER_ENDS, 1);
1625 add_move_binding (binding_set, GDK_KP_Home, GDK_CONTROL_MASK,
1626 GTK_MOVEMENT_BUFFER_ENDS, -1);
1628 add_move_binding (binding_set, GDK_KP_End, GDK_CONTROL_MASK,
1629 GTK_MOVEMENT_BUFFER_ENDS, 1);
1633 gtk_binding_entry_add_signal (binding_set, GDK_a, GDK_CONTROL_MASK,
1635 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1637 G_TYPE_BOOLEAN, FALSE);
1638 gtk_binding_entry_add_signal (binding_set, GDK_a, GDK_CONTROL_MASK,
1640 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1642 G_TYPE_BOOLEAN, TRUE);
1644 gtk_binding_entry_add_signal (binding_set, GDK_slash, GDK_CONTROL_MASK,
1646 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1648 G_TYPE_BOOLEAN, FALSE);
1649 gtk_binding_entry_add_signal (binding_set, GDK_slash, GDK_CONTROL_MASK,
1651 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
1653 G_TYPE_BOOLEAN, TRUE);
1656 gtk_binding_entry_add_signal (binding_set, GDK_backslash, GDK_CONTROL_MASK,
1658 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_VISUAL_POSITIONS,
1660 G_TYPE_BOOLEAN, FALSE);
1661 gtk_binding_entry_add_signal (binding_set, GDK_a, GDK_SHIFT_MASK | GDK_CONTROL_MASK,
1663 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_VISUAL_POSITIONS,
1665 G_TYPE_BOOLEAN, FALSE);
1669 gtk_binding_entry_add_signal (binding_set, GDK_Return, 0,
1671 gtk_binding_entry_add_signal (binding_set, GDK_ISO_Enter, 0,
1673 gtk_binding_entry_add_signal (binding_set, GDK_KP_Enter, 0,
1677 gtk_binding_entry_add_signal (binding_set, GDK_Delete, 0,
1678 "delete-from-cursor", 2,
1679 G_TYPE_ENUM, GTK_DELETE_CHARS,
1682 gtk_binding_entry_add_signal (binding_set, GDK_KP_Delete, 0,
1683 "delete-from-cursor", 2,
1684 G_TYPE_ENUM, GTK_DELETE_CHARS,
1687 gtk_binding_entry_add_signal (binding_set, GDK_BackSpace, 0,
1690 /* Make this do the same as Backspace, to help with mis-typing */
1691 gtk_binding_entry_add_signal (binding_set, GDK_BackSpace, GDK_SHIFT_MASK,
1694 gtk_binding_entry_add_signal (binding_set, GDK_Delete, GDK_CONTROL_MASK,
1695 "delete-from-cursor", 2,
1696 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1699 gtk_binding_entry_add_signal (binding_set, GDK_KP_Delete, GDK_CONTROL_MASK,
1700 "delete-from-cursor", 2,
1701 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1704 gtk_binding_entry_add_signal (binding_set, GDK_BackSpace, GDK_CONTROL_MASK,
1705 "delete-from-cursor", 2,
1706 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1709 /* Cut/copy/paste */
1711 gtk_binding_entry_add_signal (binding_set, GDK_x, GDK_CONTROL_MASK,
1712 "cut-clipboard", 0);
1713 gtk_binding_entry_add_signal (binding_set, GDK_c, GDK_CONTROL_MASK,
1714 "copy-clipboard", 0);
1715 gtk_binding_entry_add_signal (binding_set, GDK_v, GDK_CONTROL_MASK,
1716 "paste-clipboard", 0);
1718 gtk_binding_entry_add_signal (binding_set, GDK_Delete, GDK_SHIFT_MASK,
1719 "cut-clipboard", 0);
1720 gtk_binding_entry_add_signal (binding_set, GDK_Insert, GDK_CONTROL_MASK,
1721 "copy-clipboard", 0);
1722 gtk_binding_entry_add_signal (binding_set, GDK_Insert, GDK_SHIFT_MASK,
1723 "paste-clipboard", 0);
1726 gtk_binding_entry_add_signal (binding_set, GDK_Insert, 0,
1727 "toggle-overwrite", 0);
1728 gtk_binding_entry_add_signal (binding_set, GDK_KP_Insert, 0,
1729 "toggle-overwrite", 0);
1732 * GtkEntry:inner-border:
1734 * Sets the text area's border between the text and the frame.
1738 gtk_widget_class_install_style_property (widget_class,
1739 g_param_spec_boxed ("inner-border",
1741 P_("Border between text and frame."),
1743 GTK_PARAM_READABLE));
1746 * GtkEntry:state-hint:
1748 * Indicates whether to pass a proper widget state when
1749 * drawing the shadow and the widget background.
1753 gtk_widget_class_install_style_property (widget_class,
1754 g_param_spec_boolean ("state-hint",
1756 P_("Whether to pass a proper state when drawing shadow or background"),
1758 GTK_PARAM_READABLE));
1760 gtk_settings_install_property (g_param_spec_boolean ("gtk-entry-select-on-focus",
1761 P_("Select on focus"),
1762 P_("Whether to select the contents of an entry when it is focused"),
1764 GTK_PARAM_READWRITE));
1767 * GtkSettings:gtk-entry-password-hint-timeout:
1769 * How long to show the last input character in hidden
1770 * entries. This value is in milliseconds. 0 disables showing the
1771 * last char. 600 is a good value for enabling it.
1775 gtk_settings_install_property (g_param_spec_uint ("gtk-entry-password-hint-timeout",
1776 P_("Password Hint Timeout"),
1777 P_("How long to show the last input character in hidden entries"),
1779 GTK_PARAM_READWRITE));
1781 g_type_class_add_private (gobject_class, sizeof (GtkEntryPrivate));
1785 gtk_entry_editable_init (GtkEditableClass *iface)
1787 iface->do_insert_text = gtk_entry_insert_text;
1788 iface->do_delete_text = gtk_entry_delete_text;
1789 iface->insert_text = gtk_entry_real_insert_text;
1790 iface->delete_text = gtk_entry_real_delete_text;
1791 iface->get_chars = gtk_entry_get_chars;
1792 iface->set_selection_bounds = gtk_entry_set_selection_bounds;
1793 iface->get_selection_bounds = gtk_entry_get_selection_bounds;
1794 iface->set_position = gtk_entry_real_set_position;
1795 iface->get_position = gtk_entry_get_position;
1799 gtk_entry_cell_editable_init (GtkCellEditableIface *iface)
1801 iface->start_editing = gtk_entry_start_editing;
1805 gtk_entry_set_property (GObject *object,
1807 const GValue *value,
1810 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (object);
1811 GtkEntry *entry = GTK_ENTRY (object);
1817 gtk_entry_set_buffer (entry, g_value_get_object (value));
1822 gboolean new_value = g_value_get_boolean (value);
1824 if (new_value != entry->editable)
1826 widget = GTK_WIDGET (entry);
1829 _gtk_entry_reset_im_context (entry);
1830 if (gtk_widget_has_focus (widget))
1831 gtk_im_context_focus_out (entry->im_context);
1833 entry->preedit_length = 0;
1834 entry->preedit_cursor = 0;
1837 entry->editable = new_value;
1839 if (new_value && gtk_widget_has_focus (widget))
1840 gtk_im_context_focus_in (entry->im_context);
1842 gtk_entry_queue_draw (entry);
1847 case PROP_MAX_LENGTH:
1848 gtk_entry_set_max_length (entry, g_value_get_int (value));
1851 case PROP_VISIBILITY:
1852 gtk_entry_set_visibility (entry, g_value_get_boolean (value));
1855 case PROP_HAS_FRAME:
1856 gtk_entry_set_has_frame (entry, g_value_get_boolean (value));
1859 case PROP_INNER_BORDER:
1860 gtk_entry_set_inner_border (entry, g_value_get_boxed (value));
1863 case PROP_INVISIBLE_CHAR:
1864 gtk_entry_set_invisible_char (entry, g_value_get_uint (value));
1867 case PROP_ACTIVATES_DEFAULT:
1868 gtk_entry_set_activates_default (entry, g_value_get_boolean (value));
1871 case PROP_WIDTH_CHARS:
1872 gtk_entry_set_width_chars (entry, g_value_get_int (value));
1876 gtk_entry_set_text (entry, g_value_get_string (value));
1880 gtk_entry_set_alignment (entry, g_value_get_float (value));
1883 case PROP_TRUNCATE_MULTILINE:
1884 entry->truncate_multiline = g_value_get_boolean (value);
1887 case PROP_SHADOW_TYPE:
1888 priv->shadow_type = g_value_get_enum (value);
1891 case PROP_OVERWRITE_MODE:
1892 gtk_entry_set_overwrite_mode (entry, g_value_get_boolean (value));
1895 case PROP_INVISIBLE_CHAR_SET:
1896 if (g_value_get_boolean (value))
1897 priv->invisible_char_set = TRUE;
1899 gtk_entry_unset_invisible_char (entry);
1902 case PROP_CAPS_LOCK_WARNING:
1903 priv->caps_lock_warning = g_value_get_boolean (value);
1906 case PROP_PROGRESS_FRACTION:
1907 gtk_entry_set_progress_fraction (entry, g_value_get_double (value));
1910 case PROP_PROGRESS_PULSE_STEP:
1911 gtk_entry_set_progress_pulse_step (entry, g_value_get_double (value));
1914 case PROP_PIXBUF_PRIMARY:
1915 gtk_entry_set_icon_from_pixbuf (entry,
1916 GTK_ENTRY_ICON_PRIMARY,
1917 g_value_get_object (value));
1920 case PROP_PIXBUF_SECONDARY:
1921 gtk_entry_set_icon_from_pixbuf (entry,
1922 GTK_ENTRY_ICON_SECONDARY,
1923 g_value_get_object (value));
1926 case PROP_STOCK_PRIMARY:
1927 gtk_entry_set_icon_from_stock (entry,
1928 GTK_ENTRY_ICON_PRIMARY,
1929 g_value_get_string (value));
1932 case PROP_STOCK_SECONDARY:
1933 gtk_entry_set_icon_from_stock (entry,
1934 GTK_ENTRY_ICON_SECONDARY,
1935 g_value_get_string (value));
1938 case PROP_ICON_NAME_PRIMARY:
1939 gtk_entry_set_icon_from_icon_name (entry,
1940 GTK_ENTRY_ICON_PRIMARY,
1941 g_value_get_string (value));
1944 case PROP_ICON_NAME_SECONDARY:
1945 gtk_entry_set_icon_from_icon_name (entry,
1946 GTK_ENTRY_ICON_SECONDARY,
1947 g_value_get_string (value));
1950 case PROP_GICON_PRIMARY:
1951 gtk_entry_set_icon_from_gicon (entry,
1952 GTK_ENTRY_ICON_PRIMARY,
1953 g_value_get_object (value));
1956 case PROP_GICON_SECONDARY:
1957 gtk_entry_set_icon_from_gicon (entry,
1958 GTK_ENTRY_ICON_SECONDARY,
1959 g_value_get_object (value));
1962 case PROP_ACTIVATABLE_PRIMARY:
1963 gtk_entry_set_icon_activatable (entry,
1964 GTK_ENTRY_ICON_PRIMARY,
1965 g_value_get_boolean (value));
1968 case PROP_ACTIVATABLE_SECONDARY:
1969 gtk_entry_set_icon_activatable (entry,
1970 GTK_ENTRY_ICON_SECONDARY,
1971 g_value_get_boolean (value));
1974 case PROP_SENSITIVE_PRIMARY:
1975 gtk_entry_set_icon_sensitive (entry,
1976 GTK_ENTRY_ICON_PRIMARY,
1977 g_value_get_boolean (value));
1980 case PROP_SENSITIVE_SECONDARY:
1981 gtk_entry_set_icon_sensitive (entry,
1982 GTK_ENTRY_ICON_SECONDARY,
1983 g_value_get_boolean (value));
1986 case PROP_TOOLTIP_TEXT_PRIMARY:
1987 gtk_entry_set_icon_tooltip_text (entry,
1988 GTK_ENTRY_ICON_PRIMARY,
1989 g_value_get_string (value));
1992 case PROP_TOOLTIP_TEXT_SECONDARY:
1993 gtk_entry_set_icon_tooltip_text (entry,
1994 GTK_ENTRY_ICON_SECONDARY,
1995 g_value_get_string (value));
1998 case PROP_TOOLTIP_MARKUP_PRIMARY:
1999 gtk_entry_set_icon_tooltip_markup (entry,
2000 GTK_ENTRY_ICON_PRIMARY,
2001 g_value_get_string (value));
2004 case PROP_TOOLTIP_MARKUP_SECONDARY:
2005 gtk_entry_set_icon_tooltip_markup (entry,
2006 GTK_ENTRY_ICON_SECONDARY,
2007 g_value_get_string (value));
2010 case PROP_IM_MODULE:
2011 g_free (priv->im_module);
2012 priv->im_module = g_value_dup_string (value);
2013 if (GTK_IS_IM_MULTICONTEXT (entry->im_context))
2014 gtk_im_multicontext_set_context_id (GTK_IM_MULTICONTEXT (entry->im_context), priv->im_module);
2017 case PROP_EDITING_CANCELED:
2018 entry->editing_canceled = g_value_get_boolean (value);
2021 case PROP_SCROLL_OFFSET:
2022 case PROP_CURSOR_POSITION:
2024 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2030 gtk_entry_get_property (GObject *object,
2035 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (object);
2036 GtkEntry *entry = GTK_ENTRY (object);
2041 g_value_set_object (value, gtk_entry_get_buffer (entry));
2044 case PROP_CURSOR_POSITION:
2045 g_value_set_int (value, entry->current_pos);
2048 case PROP_SELECTION_BOUND:
2049 g_value_set_int (value, entry->selection_bound);
2053 g_value_set_boolean (value, entry->editable);
2056 case PROP_MAX_LENGTH:
2057 g_value_set_int (value, gtk_entry_buffer_get_max_length (get_buffer (entry)));
2060 case PROP_VISIBILITY:
2061 g_value_set_boolean (value, entry->visible);
2064 case PROP_HAS_FRAME:
2065 g_value_set_boolean (value, entry->has_frame);
2068 case PROP_INNER_BORDER:
2069 g_value_set_boxed (value, gtk_entry_get_inner_border (entry));
2072 case PROP_INVISIBLE_CHAR:
2073 g_value_set_uint (value, entry->invisible_char);
2076 case PROP_ACTIVATES_DEFAULT:
2077 g_value_set_boolean (value, entry->activates_default);
2080 case PROP_WIDTH_CHARS:
2081 g_value_set_int (value, entry->width_chars);
2084 case PROP_SCROLL_OFFSET:
2085 g_value_set_int (value, entry->scroll_offset);
2089 g_value_set_string (value, gtk_entry_get_text (entry));
2093 g_value_set_float (value, gtk_entry_get_alignment (entry));
2096 case PROP_TRUNCATE_MULTILINE:
2097 g_value_set_boolean (value, entry->truncate_multiline);
2100 case PROP_SHADOW_TYPE:
2101 g_value_set_enum (value, priv->shadow_type);
2104 case PROP_OVERWRITE_MODE:
2105 g_value_set_boolean (value, entry->overwrite_mode);
2108 case PROP_TEXT_LENGTH:
2109 g_value_set_uint (value, gtk_entry_buffer_get_length (get_buffer (entry)));
2112 case PROP_INVISIBLE_CHAR_SET:
2113 g_value_set_boolean (value, priv->invisible_char_set);
2116 case PROP_IM_MODULE:
2117 g_value_set_string (value, priv->im_module);
2120 case PROP_CAPS_LOCK_WARNING:
2121 g_value_set_boolean (value, priv->caps_lock_warning);
2124 case PROP_PROGRESS_FRACTION:
2125 g_value_set_double (value, priv->progress_fraction);
2128 case PROP_PROGRESS_PULSE_STEP:
2129 g_value_set_double (value, priv->progress_pulse_fraction);
2132 case PROP_PIXBUF_PRIMARY:
2133 g_value_set_object (value,
2134 gtk_entry_get_icon_pixbuf (entry,
2135 GTK_ENTRY_ICON_PRIMARY));
2138 case PROP_PIXBUF_SECONDARY:
2139 g_value_set_object (value,
2140 gtk_entry_get_icon_pixbuf (entry,
2141 GTK_ENTRY_ICON_SECONDARY));
2144 case PROP_STOCK_PRIMARY:
2145 g_value_set_string (value,
2146 gtk_entry_get_icon_stock (entry,
2147 GTK_ENTRY_ICON_PRIMARY));
2150 case PROP_STOCK_SECONDARY:
2151 g_value_set_string (value,
2152 gtk_entry_get_icon_stock (entry,
2153 GTK_ENTRY_ICON_SECONDARY));
2156 case PROP_ICON_NAME_PRIMARY:
2157 g_value_set_string (value,
2158 gtk_entry_get_icon_name (entry,
2159 GTK_ENTRY_ICON_PRIMARY));
2162 case PROP_ICON_NAME_SECONDARY:
2163 g_value_set_string (value,
2164 gtk_entry_get_icon_name (entry,
2165 GTK_ENTRY_ICON_SECONDARY));
2168 case PROP_GICON_PRIMARY:
2169 g_value_set_object (value,
2170 gtk_entry_get_icon_gicon (entry,
2171 GTK_ENTRY_ICON_PRIMARY));
2174 case PROP_GICON_SECONDARY:
2175 g_value_set_object (value,
2176 gtk_entry_get_icon_gicon (entry,
2177 GTK_ENTRY_ICON_SECONDARY));
2180 case PROP_STORAGE_TYPE_PRIMARY:
2181 g_value_set_enum (value,
2182 gtk_entry_get_icon_storage_type (entry,
2183 GTK_ENTRY_ICON_PRIMARY));
2186 case PROP_STORAGE_TYPE_SECONDARY:
2187 g_value_set_enum (value,
2188 gtk_entry_get_icon_storage_type (entry,
2189 GTK_ENTRY_ICON_SECONDARY));
2192 case PROP_ACTIVATABLE_PRIMARY:
2193 g_value_set_boolean (value,
2194 gtk_entry_get_icon_activatable (entry, GTK_ENTRY_ICON_PRIMARY));
2197 case PROP_ACTIVATABLE_SECONDARY:
2198 g_value_set_boolean (value,
2199 gtk_entry_get_icon_activatable (entry, GTK_ENTRY_ICON_SECONDARY));
2202 case PROP_SENSITIVE_PRIMARY:
2203 g_value_set_boolean (value,
2204 gtk_entry_get_icon_sensitive (entry, GTK_ENTRY_ICON_PRIMARY));
2207 case PROP_SENSITIVE_SECONDARY:
2208 g_value_set_boolean (value,
2209 gtk_entry_get_icon_sensitive (entry, GTK_ENTRY_ICON_SECONDARY));
2212 case PROP_TOOLTIP_TEXT_PRIMARY:
2213 g_value_take_string (value,
2214 gtk_entry_get_icon_tooltip_text (entry, GTK_ENTRY_ICON_PRIMARY));
2217 case PROP_TOOLTIP_TEXT_SECONDARY:
2218 g_value_take_string (value,
2219 gtk_entry_get_icon_tooltip_text (entry, GTK_ENTRY_ICON_SECONDARY));
2222 case PROP_TOOLTIP_MARKUP_PRIMARY:
2223 g_value_take_string (value,
2224 gtk_entry_get_icon_tooltip_markup (entry, GTK_ENTRY_ICON_PRIMARY));
2227 case PROP_TOOLTIP_MARKUP_SECONDARY:
2228 g_value_take_string (value,
2229 gtk_entry_get_icon_tooltip_markup (entry, GTK_ENTRY_ICON_SECONDARY));
2232 case PROP_EDITING_CANCELED:
2233 g_value_set_boolean (value,
2234 entry->editing_canceled);
2238 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2244 find_invisible_char (GtkWidget *widget)
2246 PangoLayout *layout;
2247 PangoAttrList *attr_list;
2249 gunichar invisible_chars [] = {
2251 0x25cf, /* BLACK CIRCLE */
2252 0x2022, /* BULLET */
2253 0x2731, /* HEAVY ASTERISK */
2254 0x273a /* SIXTEEN POINTED ASTERISK */
2258 gtk_widget_style_get (widget,
2259 "invisible-char", &invisible_chars[0],
2262 layout = gtk_widget_create_pango_layout (widget, NULL);
2264 attr_list = pango_attr_list_new ();
2265 pango_attr_list_insert (attr_list, pango_attr_fallback_new (FALSE));
2267 pango_layout_set_attributes (layout, attr_list);
2268 pango_attr_list_unref (attr_list);
2270 for (i = (invisible_chars[0] != 0 ? 0 : 1); i < G_N_ELEMENTS (invisible_chars); i++)
2272 gchar text[7] = { 0, };
2275 len = g_unichar_to_utf8 (invisible_chars[i], text);
2276 pango_layout_set_text (layout, text, len);
2278 count = pango_layout_get_unknown_glyphs_count (layout);
2282 g_object_unref (layout);
2283 return invisible_chars[i];
2287 g_object_unref (layout);
2293 gtk_entry_init (GtkEntry *entry)
2295 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2297 gtk_widget_set_can_focus (GTK_WIDGET (entry), TRUE);
2299 entry->editable = TRUE;
2300 entry->visible = TRUE;
2301 entry->invisible_char = find_invisible_char (GTK_WIDGET (entry));
2302 entry->dnd_position = -1;
2303 entry->width_chars = -1;
2304 entry->is_cell_renderer = FALSE;
2305 entry->editing_canceled = FALSE;
2306 entry->has_frame = TRUE;
2307 entry->truncate_multiline = FALSE;
2308 priv->shadow_type = GTK_SHADOW_IN;
2310 priv->caps_lock_warning = TRUE;
2311 priv->caps_lock_warning_shown = FALSE;
2312 priv->progress_fraction = 0.0;
2313 priv->progress_pulse_fraction = 0.1;
2315 gtk_drag_dest_set (GTK_WIDGET (entry),
2316 GTK_DEST_DEFAULT_HIGHLIGHT,
2318 GDK_ACTION_COPY | GDK_ACTION_MOVE);
2319 gtk_drag_dest_add_text_targets (GTK_WIDGET (entry));
2321 /* This object is completely private. No external entity can gain a reference
2322 * to it; so we create it here and destroy it in finalize().
2324 entry->im_context = gtk_im_multicontext_new ();
2326 g_signal_connect (entry->im_context, "commit",
2327 G_CALLBACK (gtk_entry_commit_cb), entry);
2328 g_signal_connect (entry->im_context, "preedit-changed",
2329 G_CALLBACK (gtk_entry_preedit_changed_cb), entry);
2330 g_signal_connect (entry->im_context, "retrieve-surrounding",
2331 G_CALLBACK (gtk_entry_retrieve_surrounding_cb), entry);
2332 g_signal_connect (entry->im_context, "delete-surrounding",
2333 G_CALLBACK (gtk_entry_delete_surrounding_cb), entry);
2338 get_icon_width (GtkEntry *entry,
2339 GtkEntryIconPosition icon_pos)
2341 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2342 EntryIconInfo *icon_info = priv->icons[icon_pos];
2344 GtkSettings *settings;
2345 gint menu_icon_width;
2347 if (!icon_info || icon_info->pixbuf == NULL)
2350 screen = gtk_widget_get_screen (GTK_WIDGET (entry));
2351 settings = gtk_settings_get_for_screen (screen);
2353 gtk_icon_size_lookup_for_settings (settings, GTK_ICON_SIZE_MENU,
2354 &menu_icon_width, NULL);
2356 return MAX (gdk_pixbuf_get_width (icon_info->pixbuf), menu_icon_width);
2360 get_icon_allocations (GtkEntry *entry,
2361 GtkAllocation *primary,
2362 GtkAllocation *secondary)
2365 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2366 gint x, y, width, height;
2368 get_text_area_size (entry, &x, &y, &width, &height);
2370 if (gtk_widget_has_focus (GTK_WIDGET (entry)) && !priv->interior_focus)
2371 y += priv->focus_width;
2374 primary->height = height;
2375 primary->width = get_icon_width (entry, GTK_ENTRY_ICON_PRIMARY);
2376 if (primary->width > 0)
2377 primary->width += 2 * priv->icon_margin;
2380 secondary->height = height;
2381 secondary->width = get_icon_width (entry, GTK_ENTRY_ICON_SECONDARY);
2382 if (secondary->width > 0)
2383 secondary->width += 2 * priv->icon_margin;
2385 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
2387 primary->x = x + width - primary->width;
2393 secondary->x = x + width - secondary->width;
2399 begin_change (GtkEntry *entry)
2401 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2403 priv->change_count++;
2407 end_change (GtkEntry *entry)
2409 GtkEditable *editable = GTK_EDITABLE (entry);
2410 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2412 g_return_if_fail (priv->change_count > 0);
2414 priv->change_count--;
2416 if (priv->change_count == 0)
2418 if (priv->real_changed)
2420 g_signal_emit_by_name (editable, "changed");
2421 priv->real_changed = FALSE;
2427 emit_changed (GtkEntry *entry)
2429 GtkEditable *editable = GTK_EDITABLE (entry);
2430 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2432 if (priv->change_count == 0)
2433 g_signal_emit_by_name (editable, "changed");
2435 priv->real_changed = TRUE;
2439 gtk_entry_destroy (GtkObject *object)
2441 GtkEntry *entry = GTK_ENTRY (object);
2443 entry->current_pos = entry->selection_bound = 0;
2444 _gtk_entry_reset_im_context (entry);
2445 gtk_entry_reset_layout (entry);
2447 if (entry->blink_timeout)
2449 g_source_remove (entry->blink_timeout);
2450 entry->blink_timeout = 0;
2453 if (entry->recompute_idle)
2455 g_source_remove (entry->recompute_idle);
2456 entry->recompute_idle = 0;
2459 GTK_OBJECT_CLASS (gtk_entry_parent_class)->destroy (object);
2463 gtk_entry_dispose (GObject *object)
2465 GtkEntry *entry = GTK_ENTRY (object);
2466 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2468 gtk_entry_set_icon_from_pixbuf (entry, GTK_ENTRY_ICON_PRIMARY, NULL);
2469 gtk_entry_set_icon_tooltip_markup (entry, GTK_ENTRY_ICON_PRIMARY, NULL);
2470 gtk_entry_set_icon_from_pixbuf (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
2471 gtk_entry_set_icon_tooltip_markup (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
2475 buffer_disconnect_signals (entry);
2476 g_object_unref (priv->buffer);
2477 priv->buffer = NULL;
2480 G_OBJECT_CLASS (gtk_entry_parent_class)->dispose (object);
2484 gtk_entry_finalize (GObject *object)
2486 GtkEntry *entry = GTK_ENTRY (object);
2487 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2488 EntryIconInfo *icon_info = NULL;
2491 for (i = 0; i < MAX_ICONS; i++)
2493 if ((icon_info = priv->icons[i]) != NULL)
2495 if (icon_info->target_list != NULL)
2497 gtk_target_list_unref (icon_info->target_list);
2498 icon_info->target_list = NULL;
2501 g_slice_free (EntryIconInfo, icon_info);
2502 priv->icons[i] = NULL;
2506 gtk_entry_set_completion (entry, NULL);
2508 if (entry->cached_layout)
2509 g_object_unref (entry->cached_layout);
2511 g_object_unref (entry->im_context);
2513 if (entry->blink_timeout)
2514 g_source_remove (entry->blink_timeout);
2516 if (entry->recompute_idle)
2517 g_source_remove (entry->recompute_idle);
2519 g_free (priv->im_module);
2521 G_OBJECT_CLASS (gtk_entry_parent_class)->finalize (object);
2525 gtk_entry_get_display_mode (GtkEntry *entry)
2527 GtkEntryPrivate *priv;
2529 return DISPLAY_NORMAL;
2530 priv = GTK_ENTRY_GET_PRIVATE (entry);
2531 if (entry->invisible_char == 0 && priv->invisible_char_set)
2532 return DISPLAY_BLANK;
2533 return DISPLAY_INVISIBLE;
2537 gtk_entry_get_display_text (GtkEntry *entry,
2541 GtkEntryPasswordHint *password_hint;
2542 GtkEntryPrivate *priv;
2543 gunichar invisible_char;
2553 priv = GTK_ENTRY_GET_PRIVATE (entry);
2554 text = gtk_entry_buffer_get_text (get_buffer (entry));
2555 length = gtk_entry_buffer_get_length (get_buffer (entry));
2559 if (start_pos > length)
2562 if (end_pos <= start_pos)
2563 return g_strdup ("");
2564 else if (entry->visible)
2566 start = g_utf8_offset_to_pointer (text, start_pos);
2567 end = g_utf8_offset_to_pointer (start, end_pos - start_pos);
2568 return g_strndup (start, end - start);
2572 str = g_string_sized_new (length * 2);
2574 /* Figure out what our invisible char is and encode it */
2575 if (!entry->invisible_char)
2576 invisible_char = priv->invisible_char_set ? ' ' : '*';
2578 invisible_char = entry->invisible_char;
2579 char_len = g_unichar_to_utf8 (invisible_char, char_str);
2582 * Add hidden characters for each character in the text
2583 * buffer. If there is a password hint, then keep that
2584 * character visible.
2587 password_hint = g_object_get_qdata (G_OBJECT (entry), quark_password_hint);
2588 for (i = start_pos; i < end_pos; ++i)
2590 if (password_hint && i == password_hint->position)
2592 start = g_utf8_offset_to_pointer (text, i);
2593 g_string_append_len (str, start, g_utf8_next_char (start) - start);
2597 g_string_append_len (str, char_str, char_len);
2601 return g_string_free (str, FALSE);
2607 update_cursors (GtkWidget *widget)
2609 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2610 EntryIconInfo *icon_info = NULL;
2611 GdkDisplay *display;
2615 for (i = 0; i < MAX_ICONS; i++)
2617 if ((icon_info = priv->icons[i]) != NULL)
2619 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
2620 gdk_window_show_unraised (icon_info->window);
2622 /* The icon windows are not children of the visible entry window,
2623 * thus we can't just inherit the xterm cursor. Slight complication
2624 * here is that for the entry, insensitive => arrow cursor, but for
2625 * an icon in a sensitive entry, insensitive => xterm cursor.
2627 if (gtk_widget_is_sensitive (widget) &&
2628 (icon_info->insensitive ||
2629 (icon_info->nonactivatable && icon_info->target_list == NULL)))
2631 display = gtk_widget_get_display (widget);
2632 cursor = gdk_cursor_new_for_display (display, GDK_XTERM);
2633 gdk_window_set_cursor (icon_info->window, cursor);
2634 gdk_cursor_unref (cursor);
2638 gdk_window_set_cursor (icon_info->window, NULL);
2645 realize_icon_info (GtkWidget *widget,
2646 GtkEntryIconPosition icon_pos)
2648 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2649 EntryIconInfo *icon_info = priv->icons[icon_pos];
2650 GdkWindowAttr attributes;
2651 gint attributes_mask;
2653 g_return_if_fail (icon_info != NULL);
2657 attributes.width = 1;
2658 attributes.height = 1;
2659 attributes.window_type = GDK_WINDOW_CHILD;
2660 attributes.wclass = GDK_INPUT_OUTPUT;
2661 attributes.visual = gtk_widget_get_visual (widget);
2662 attributes.colormap = gtk_widget_get_colormap (widget);
2663 attributes.event_mask = gtk_widget_get_events (widget);
2664 attributes.event_mask |= (GDK_EXPOSURE_MASK |
2665 GDK_BUTTON_PRESS_MASK |
2666 GDK_BUTTON_RELEASE_MASK |
2667 GDK_BUTTON1_MOTION_MASK |
2668 GDK_BUTTON3_MOTION_MASK |
2669 GDK_POINTER_MOTION_HINT_MASK |
2670 GDK_POINTER_MOTION_MASK |
2671 GDK_ENTER_NOTIFY_MASK |
2672 GDK_LEAVE_NOTIFY_MASK);
2673 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
2675 icon_info->window = gdk_window_new (widget->window,
2678 gdk_window_set_user_data (icon_info->window, widget);
2679 gdk_window_set_background (icon_info->window,
2680 &widget->style->base[gtk_widget_get_state (widget)]);
2682 gtk_widget_queue_resize (widget);
2685 static EntryIconInfo*
2686 construct_icon_info (GtkWidget *widget,
2687 GtkEntryIconPosition icon_pos)
2689 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2690 EntryIconInfo *icon_info;
2692 g_return_val_if_fail (priv->icons[icon_pos] == NULL, NULL);
2694 icon_info = g_slice_new0 (EntryIconInfo);
2695 priv->icons[icon_pos] = icon_info;
2697 if (gtk_widget_get_realized (widget))
2698 realize_icon_info (widget, icon_pos);
2704 gtk_entry_map (GtkWidget *widget)
2706 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2707 EntryIconInfo *icon_info = NULL;
2710 if (gtk_widget_get_realized (widget) && !gtk_widget_get_mapped (widget))
2712 GTK_WIDGET_CLASS (gtk_entry_parent_class)->map (widget);
2714 for (i = 0; i < MAX_ICONS; i++)
2716 if ((icon_info = priv->icons[i]) != NULL)
2718 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
2719 gdk_window_show (icon_info->window);
2723 update_cursors (widget);
2728 gtk_entry_unmap (GtkWidget *widget)
2730 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2731 EntryIconInfo *icon_info = NULL;
2734 if (gtk_widget_get_mapped (widget))
2736 for (i = 0; i < MAX_ICONS; i++)
2738 if ((icon_info = priv->icons[i]) != NULL)
2740 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
2741 gdk_window_hide (icon_info->window);
2745 GTK_WIDGET_CLASS (gtk_entry_parent_class)->unmap (widget);
2750 gtk_entry_realize (GtkWidget *widget)
2753 GtkEntryPrivate *priv;
2754 EntryIconInfo *icon_info;
2755 GdkWindowAttr attributes;
2756 gint attributes_mask;
2759 gtk_widget_set_realized (widget, TRUE);
2760 entry = GTK_ENTRY (widget);
2761 priv = GTK_ENTRY_GET_PRIVATE (entry);
2763 attributes.window_type = GDK_WINDOW_CHILD;
2765 get_widget_window_size (entry, &attributes.x, &attributes.y, &attributes.width, &attributes.height);
2767 attributes.wclass = GDK_INPUT_OUTPUT;
2768 attributes.visual = gtk_widget_get_visual (widget);
2769 attributes.colormap = gtk_widget_get_colormap (widget);
2770 attributes.event_mask = gtk_widget_get_events (widget);
2771 attributes.event_mask |= (GDK_EXPOSURE_MASK |
2772 GDK_BUTTON_PRESS_MASK |
2773 GDK_BUTTON_RELEASE_MASK |
2774 GDK_BUTTON1_MOTION_MASK |
2775 GDK_BUTTON3_MOTION_MASK |
2776 GDK_POINTER_MOTION_HINT_MASK |
2777 GDK_POINTER_MOTION_MASK |
2778 GDK_ENTER_NOTIFY_MASK |
2779 GDK_LEAVE_NOTIFY_MASK);
2780 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
2782 widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, attributes_mask);
2783 gdk_window_set_user_data (widget->window, entry);
2785 get_text_area_size (entry, &attributes.x, &attributes.y, &attributes.width, &attributes.height);
2787 if (gtk_widget_is_sensitive (widget))
2789 attributes.cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
2790 attributes_mask |= GDK_WA_CURSOR;
2793 entry->text_area = gdk_window_new (widget->window, &attributes, attributes_mask);
2795 gdk_window_set_user_data (entry->text_area, entry);
2797 if (attributes_mask & GDK_WA_CURSOR)
2798 gdk_cursor_unref (attributes.cursor);
2800 widget->style = gtk_style_attach (widget->style, widget->window);
2802 gdk_window_set_background (widget->window, &widget->style->base[gtk_widget_get_state (widget)]);
2803 gdk_window_set_background (entry->text_area, &widget->style->base[gtk_widget_get_state (widget)]);
2805 gdk_window_show (entry->text_area);
2807 gtk_im_context_set_client_window (entry->im_context, entry->text_area);
2809 gtk_entry_adjust_scroll (entry);
2810 gtk_entry_update_primary_selection (entry);
2813 /* If the icon positions are already setup, create their windows.
2814 * Otherwise if they don't exist yet, then construct_icon_info()
2815 * will create the windows once the widget is already realized.
2817 for (i = 0; i < MAX_ICONS; i++)
2819 if ((icon_info = priv->icons[i]) != NULL)
2821 if (icon_info->window == NULL)
2822 realize_icon_info (widget, i);
2828 gtk_entry_unrealize (GtkWidget *widget)
2830 GtkEntry *entry = GTK_ENTRY (widget);
2831 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2832 GtkClipboard *clipboard;
2833 EntryIconInfo *icon_info;
2836 gtk_entry_reset_layout (entry);
2838 gtk_im_context_set_client_window (entry->im_context, NULL);
2840 clipboard = gtk_widget_get_clipboard (widget, GDK_SELECTION_PRIMARY);
2841 if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (entry))
2842 gtk_clipboard_clear (clipboard);
2844 if (entry->text_area)
2846 gdk_window_set_user_data (entry->text_area, NULL);
2847 gdk_window_destroy (entry->text_area);
2848 entry->text_area = NULL;
2851 if (entry->popup_menu)
2853 gtk_widget_destroy (entry->popup_menu);
2854 entry->popup_menu = NULL;
2857 GTK_WIDGET_CLASS (gtk_entry_parent_class)->unrealize (widget);
2859 for (i = 0; i < MAX_ICONS; i++)
2861 if ((icon_info = priv->icons[i]) != NULL)
2863 if (icon_info->window != NULL)
2865 gdk_window_destroy (icon_info->window);
2866 icon_info->window = NULL;
2873 _gtk_entry_get_borders (GtkEntry *entry,
2877 GtkWidget *widget = GTK_WIDGET (entry);
2878 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2880 if (entry->has_frame)
2882 *xborder = widget->style->xthickness;
2883 *yborder = widget->style->ythickness;
2891 if (!priv->interior_focus)
2893 *xborder += priv->focus_width;
2894 *yborder += priv->focus_width;
2899 gtk_entry_size_request (GtkWidget *widget,
2900 GtkRequisition *requisition)
2902 GtkEntry *entry = GTK_ENTRY (widget);
2903 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2904 PangoFontMetrics *metrics;
2905 gint xborder, yborder;
2906 GtkBorder inner_border;
2907 PangoContext *context;
2908 int icon_widths = 0;
2911 gtk_widget_ensure_style (widget);
2912 context = gtk_widget_get_pango_context (widget);
2913 metrics = pango_context_get_metrics (context,
2914 widget->style->font_desc,
2915 pango_context_get_language (context));
2917 entry->ascent = pango_font_metrics_get_ascent (metrics);
2918 entry->descent = pango_font_metrics_get_descent (metrics);
2920 _gtk_entry_get_borders (entry, &xborder, &yborder);
2921 _gtk_entry_effective_inner_border (entry, &inner_border);
2923 if (entry->width_chars < 0)
2924 requisition->width = MIN_ENTRY_WIDTH + xborder * 2 + inner_border.left + inner_border.right;
2927 gint char_width = pango_font_metrics_get_approximate_char_width (metrics);
2928 gint digit_width = pango_font_metrics_get_approximate_digit_width (metrics);
2929 gint char_pixels = (MAX (char_width, digit_width) + PANGO_SCALE - 1) / PANGO_SCALE;
2931 requisition->width = char_pixels * entry->width_chars + xborder * 2 + inner_border.left + inner_border.right;
2934 requisition->height = PANGO_PIXELS (entry->ascent + entry->descent) + yborder * 2 + inner_border.top + inner_border.bottom;
2936 for (i = 0; i < MAX_ICONS; i++)
2938 icon_width = get_icon_width (entry, i);
2940 icon_widths += icon_width + 2 * priv->icon_margin;
2943 if (icon_widths > requisition->width)
2944 requisition->width += icon_widths;
2946 pango_font_metrics_unref (metrics);
2950 place_windows (GtkEntry *entry)
2952 GtkWidget *widget = GTK_WIDGET (entry);
2953 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2954 gint x, y, width, height;
2955 GtkAllocation primary;
2956 GtkAllocation secondary;
2957 EntryIconInfo *icon_info = NULL;
2959 get_text_area_size (entry, &x, &y, &width, &height);
2960 get_icon_allocations (entry, &primary, &secondary);
2962 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
2963 y += priv->focus_width;
2965 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
2966 x += secondary.width;
2969 width -= primary.width + secondary.width;
2971 if ((icon_info = priv->icons[GTK_ENTRY_ICON_PRIMARY]) != NULL)
2972 gdk_window_move_resize (icon_info->window,
2973 primary.x, primary.y,
2974 primary.width, primary.height);
2976 if ((icon_info = priv->icons[GTK_ENTRY_ICON_SECONDARY]) != NULL)
2977 gdk_window_move_resize (icon_info->window,
2978 secondary.x, secondary.y,
2979 secondary.width, secondary.height);
2981 gdk_window_move_resize (entry->text_area, x, y, width, height);
2985 gtk_entry_get_text_area_size (GtkEntry *entry,
2991 GtkWidget *widget = GTK_WIDGET (entry);
2992 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2994 gint xborder, yborder;
2995 GtkRequisition requisition;
2997 gtk_widget_get_child_requisition (widget, &requisition);
2998 _gtk_entry_get_borders (entry, &xborder, &yborder);
3000 if (gtk_widget_get_realized (widget))
3001 gdk_drawable_get_size (widget->window, NULL, &frame_height);
3003 frame_height = requisition.height;
3005 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3006 frame_height -= 2 * priv->focus_width;
3012 *y = frame_height / 2 - (requisition.height - yborder * 2) / 2;
3015 *width = GTK_WIDGET (entry)->allocation.width - xborder * 2;
3018 *height = requisition.height - yborder * 2;
3022 get_text_area_size (GtkEntry *entry,
3028 GtkEntryClass *class;
3030 g_return_if_fail (GTK_IS_ENTRY (entry));
3032 class = GTK_ENTRY_GET_CLASS (entry);
3034 if (class->get_text_area_size)
3035 class->get_text_area_size (entry, x, y, width, height);
3040 get_widget_window_size (GtkEntry *entry,
3046 GtkRequisition requisition;
3047 GtkWidget *widget = GTK_WIDGET (entry);
3049 gtk_widget_get_child_requisition (widget, &requisition);
3052 *x = widget->allocation.x;
3056 if (entry->is_cell_renderer)
3057 *y = widget->allocation.y;
3059 *y = widget->allocation.y + (widget->allocation.height - requisition.height) / 2;
3063 *width = widget->allocation.width;
3067 if (entry->is_cell_renderer)
3068 *height = widget->allocation.height;
3070 *height = requisition.height;
3075 _gtk_entry_effective_inner_border (GtkEntry *entry,
3078 GtkBorder *tmp_border;
3080 tmp_border = g_object_get_qdata (G_OBJECT (entry), quark_inner_border);
3084 *border = *tmp_border;
3088 gtk_widget_style_get (GTK_WIDGET (entry), "inner-border", &tmp_border, NULL);
3092 *border = *tmp_border;
3093 gtk_border_free (tmp_border);
3097 *border = default_inner_border;
3101 gtk_entry_size_allocate (GtkWidget *widget,
3102 GtkAllocation *allocation)
3104 GtkEntry *entry = GTK_ENTRY (widget);
3106 widget->allocation = *allocation;
3108 if (gtk_widget_get_realized (widget))
3110 /* We call gtk_widget_get_child_requisition, since we want (for
3111 * backwards compatibility reasons) the realization here to
3112 * be affected by the usize of the entry, if set
3114 gint x, y, width, height;
3115 GtkEntryCompletion* completion;
3117 get_widget_window_size (entry, &x, &y, &width, &height);
3118 gdk_window_move_resize (widget->window, 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;
3215 gtk_entry_ensure_pixbuf (entry, icon_pos);
3217 if (icon_info->pixbuf == NULL)
3220 gdk_drawable_get_size (icon_info->window, &width, &height);
3222 /* size_allocate hasn't been called yet. These are the default values.
3224 if (width == 1 || height == 1)
3227 pixbuf = icon_info->pixbuf;
3228 g_object_ref (pixbuf);
3230 if (gdk_pixbuf_get_height (pixbuf) > height)
3232 GdkPixbuf *temp_pixbuf;
3235 scale = height - 2 * priv->icon_margin;
3236 temp_pixbuf = gdk_pixbuf_scale_simple (pixbuf, scale, scale,
3237 GDK_INTERP_BILINEAR);
3238 g_object_unref (pixbuf);
3239 pixbuf = temp_pixbuf;
3242 x = (width - gdk_pixbuf_get_width (pixbuf)) / 2;
3243 y = (height - gdk_pixbuf_get_height (pixbuf)) / 2;
3245 if (!gtk_widget_is_sensitive (widget) ||
3246 icon_info->insensitive)
3248 GdkPixbuf *temp_pixbuf;
3250 temp_pixbuf = gdk_pixbuf_copy (pixbuf);
3251 gdk_pixbuf_saturate_and_pixelate (pixbuf,
3255 g_object_unref (pixbuf);
3256 pixbuf = temp_pixbuf;
3258 else if (icon_info->prelight)
3260 GdkPixbuf *temp_pixbuf;
3262 temp_pixbuf = gdk_pixbuf_copy (pixbuf);
3263 colorshift_pixbuf (temp_pixbuf, pixbuf, 30);
3264 g_object_unref (pixbuf);
3265 pixbuf = temp_pixbuf;
3268 gdk_draw_pixbuf (icon_info->window, widget->style->black_gc, pixbuf,
3270 GDK_RGB_DITHER_NORMAL, 0, 0);
3272 g_object_unref (pixbuf);
3277 gtk_entry_draw_frame (GtkWidget *widget,
3278 GdkEventExpose *event)
3280 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
3281 gint x = 0, y = 0, width, height;
3282 gboolean state_hint;
3285 gdk_drawable_get_size (widget->window, &width, &height);
3287 /* Fix a problem with some themes which assume that entry->text_area's
3288 * width equals widget->window's width */
3289 if (GTK_IS_SPIN_BUTTON (widget))
3291 gint xborder, yborder;
3293 gtk_entry_get_text_area_size (GTK_ENTRY (widget), &x, NULL, &width, NULL);
3294 _gtk_entry_get_borders (GTK_ENTRY (widget), &xborder, &yborder);
3297 width += xborder * 2;
3300 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3302 x += priv->focus_width;
3303 y += priv->focus_width;
3304 width -= 2 * priv->focus_width;
3305 height -= 2 * priv->focus_width;
3308 gtk_widget_style_get (widget, "state-hint", &state_hint, NULL);
3310 state = gtk_widget_has_focus (widget) ?
3311 GTK_STATE_ACTIVE : gtk_widget_get_state (widget);
3313 state = GTK_STATE_NORMAL;
3315 gtk_paint_shadow (widget->style, widget->window,
3316 state, priv->shadow_type,
3317 &event->area, widget, "entry", x, y, width, height);
3320 gtk_entry_draw_progress (widget, event);
3322 if (gtk_widget_has_focus (widget) && !priv->interior_focus)
3324 x -= priv->focus_width;
3325 y -= priv->focus_width;
3326 width += 2 * priv->focus_width;
3327 height += 2 * priv->focus_width;
3329 gtk_paint_focus (widget->style, widget->window,
3330 gtk_widget_get_state (widget),
3331 &event->area, widget, "entry",
3332 0, 0, width, height);
3337 gtk_entry_get_progress_border (GtkWidget *widget,
3338 GtkBorder *progress_border)
3340 GtkBorder *tmp_border;
3342 gtk_widget_style_get (widget, "progress-border", &tmp_border, NULL);
3345 *progress_border = *tmp_border;
3346 gtk_border_free (tmp_border);
3350 progress_border->left = widget->style->xthickness;
3351 progress_border->right = widget->style->xthickness;
3352 progress_border->top = widget->style->ythickness;
3353 progress_border->bottom = widget->style->ythickness;
3358 get_progress_area (GtkWidget *widget,
3364 GtkEntryPrivate *private = GTK_ENTRY_GET_PRIVATE (widget);
3365 GtkEntry *entry = GTK_ENTRY (widget);
3366 GtkBorder progress_border;
3368 gtk_entry_get_progress_border (widget, &progress_border);
3370 *x = progress_border.left;
3371 *y = progress_border.top;
3373 gdk_drawable_get_size (widget->window, width, height);
3375 *width -= progress_border.left + progress_border.right;
3376 *height -= progress_border.top + progress_border.bottom;
3378 if (gtk_widget_has_focus (widget) && !private->interior_focus)
3380 *x += private->focus_width;
3381 *y += private->focus_width;
3382 *width -= 2 * private->focus_width;
3383 *height -= 2 * private->focus_width;
3386 if (private->progress_pulse_mode)
3388 gdouble value = private->progress_pulse_current;
3390 *x += (gint) floor(value * (*width));
3391 *width = (gint) ceil(private->progress_pulse_fraction * (*width));
3393 else if (private->progress_fraction > 0)
3395 gdouble value = private->progress_fraction;
3397 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
3401 bar_width = floor(value * (*width) + 0.5);
3402 *x += *width - bar_width;
3407 *width = (gint) floor(value * (*width) + 0.5);
3418 gtk_entry_draw_progress (GtkWidget *widget,
3419 GdkEventExpose *event)
3421 gint x, y, width, height;
3424 get_progress_area (widget, &x, &y, &width, &height);
3426 if ((width <= 0) || (height <= 0))
3429 if (event->window != widget->window)
3433 gdk_window_get_position (event->window, &pos_x, &pos_y);
3439 state = GTK_STATE_SELECTED;
3440 if (!gtk_widget_get_sensitive (widget))
3441 state = GTK_STATE_INSENSITIVE;
3443 gtk_paint_box (widget->style, event->window,
3444 state, GTK_SHADOW_OUT,
3445 &event->area, widget, "entry-progress",
3451 gtk_entry_expose (GtkWidget *widget,
3452 GdkEventExpose *event)
3454 GtkEntry *entry = GTK_ENTRY (widget);
3455 gboolean state_hint;
3457 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3459 gtk_widget_style_get (widget, "state-hint", &state_hint, NULL);
3461 state = gtk_widget_has_focus (widget) ?
3462 GTK_STATE_ACTIVE : gtk_widget_get_state (widget);
3464 state = gtk_widget_get_state(widget);
3466 if (widget->window == event->window)
3468 gtk_entry_draw_frame (widget, event);
3470 else if (entry->text_area == event->window)
3474 gdk_drawable_get_size (entry->text_area, &width, &height);
3476 gtk_paint_flat_box (widget->style, entry->text_area,
3477 state, GTK_SHADOW_NONE,
3478 &event->area, widget, "entry_bg",
3479 0, 0, width, height);
3481 gtk_entry_draw_progress (widget, event);
3483 if (entry->dnd_position != -1)
3484 gtk_entry_draw_cursor (GTK_ENTRY (widget), CURSOR_DND);
3486 gtk_entry_draw_text (GTK_ENTRY (widget));
3488 /* When no text is being displayed at all, don't show the cursor */
3489 if (gtk_entry_get_display_mode (entry) != DISPLAY_BLANK &&
3490 gtk_widget_has_focus (widget) &&
3491 entry->selection_bound == entry->current_pos && entry->cursor_visible)
3492 gtk_entry_draw_cursor (GTK_ENTRY (widget), CURSOR_STANDARD);
3498 for (i = 0; i < MAX_ICONS; i++)
3500 EntryIconInfo *icon_info = priv->icons[i];
3502 if (icon_info != NULL && event->window == icon_info->window)
3506 gdk_drawable_get_size (icon_info->window, &width, &height);
3508 gtk_paint_flat_box (widget->style, icon_info->window,
3509 gtk_widget_get_state (widget), GTK_SHADOW_NONE,
3510 NULL, widget, "entry_bg",
3511 0, 0, width, height);
3513 gtk_entry_draw_progress (widget, event);
3514 draw_icon (widget, i);
3525 gtk_entry_enter_notify (GtkWidget *widget,
3526 GdkEventCrossing *event)
3528 GtkEntry *entry = GTK_ENTRY (widget);
3529 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3532 for (i = 0; i < MAX_ICONS; i++)
3534 EntryIconInfo *icon_info = priv->icons[i];
3536 if (icon_info != NULL && event->window == icon_info->window)
3538 if (should_prelight (entry, i))
3540 icon_info->prelight = TRUE;
3541 gtk_widget_queue_draw (widget);
3552 gtk_entry_leave_notify (GtkWidget *widget,
3553 GdkEventCrossing *event)
3555 GtkEntry *entry = GTK_ENTRY (widget);
3556 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3559 for (i = 0; i < MAX_ICONS; i++)
3561 EntryIconInfo *icon_info = priv->icons[i];
3563 if (icon_info != NULL && event->window == icon_info->window)
3565 /* a grab means that we may never see the button release */
3566 if (event->mode == GDK_CROSSING_GRAB || event->mode == GDK_CROSSING_GTK_GRAB)
3567 icon_info->pressed = FALSE;
3569 if (should_prelight (entry, i))
3571 icon_info->prelight = FALSE;
3572 gtk_widget_queue_draw (widget);
3583 gtk_entry_get_pixel_ranges (GtkEntry *entry,
3587 gint start_char, end_char;
3589 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start_char, &end_char))
3591 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
3592 PangoLayoutLine *line = pango_layout_get_lines_readonly (layout)->data;
3593 const char *text = pango_layout_get_text (layout);
3594 gint start_index = g_utf8_offset_to_pointer (text, start_char) - text;
3595 gint end_index = g_utf8_offset_to_pointer (text, end_char) - text;
3596 gint real_n_ranges, i;
3598 pango_layout_line_get_x_ranges (line, start_index, end_index, ranges, &real_n_ranges);
3604 for (i = 0; i < real_n_ranges; ++i)
3606 r[2 * i + 1] = (r[2 * i + 1] - r[2 * i]) / PANGO_SCALE;
3607 r[2 * i] = r[2 * i] / PANGO_SCALE;
3612 *n_ranges = real_n_ranges;
3624 in_selection (GtkEntry *entry,
3629 gint retval = FALSE;
3631 gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
3633 for (i = 0; i < n_ranges; ++i)
3635 if (x >= ranges[2 * i] && x < ranges[2 * i] + ranges[2 * i + 1])
3647 gtk_entry_button_press (GtkWidget *widget,
3648 GdkEventButton *event)
3650 GtkEntry *entry = GTK_ENTRY (widget);
3651 GtkEditable *editable = GTK_EDITABLE (widget);
3652 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3653 EntryIconInfo *icon_info = NULL;
3655 gint sel_start, sel_end;
3658 for (i = 0; i < MAX_ICONS; i++)
3660 icon_info = priv->icons[i];
3662 if (!icon_info || icon_info->insensitive)
3665 if (event->window == icon_info->window)
3667 if (should_prelight (entry, i))
3669 icon_info->prelight = FALSE;
3670 gtk_widget_queue_draw (widget);
3673 priv->start_x = event->x;
3674 priv->start_y = event->y;
3675 icon_info->pressed = TRUE;
3677 if (!icon_info->nonactivatable)
3678 g_signal_emit (entry, signals[ICON_PRESS], 0, i, event);
3684 if (event->window != entry->text_area ||
3685 (entry->button && event->button != entry->button))
3688 gtk_entry_reset_blink_time (entry);
3690 entry->button = event->button;
3692 if (!gtk_widget_has_focus (widget))
3694 entry->in_click = TRUE;
3695 gtk_widget_grab_focus (widget);
3696 entry->in_click = FALSE;
3699 tmp_pos = gtk_entry_find_position (entry, event->x + entry->scroll_offset);
3701 if (event->button == 1)
3703 gboolean have_selection = gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end);
3705 entry->select_words = FALSE;
3706 entry->select_lines = FALSE;
3708 if (event->state & GDK_SHIFT_MASK)
3710 _gtk_entry_reset_im_context (entry);
3712 if (!have_selection) /* select from the current position to the clicked position */
3713 sel_start = sel_end = entry->current_pos;
3715 if (tmp_pos > sel_start && tmp_pos < sel_end)
3717 /* Truncate current selection, but keep it as big as possible */
3718 if (tmp_pos - sel_start > sel_end - tmp_pos)
3719 gtk_entry_set_positions (entry, sel_start, tmp_pos);
3721 gtk_entry_set_positions (entry, tmp_pos, sel_end);
3725 gboolean extend_to_left;
3728 /* Figure out what click selects and extend current selection */
3729 switch (event->type)
3731 case GDK_BUTTON_PRESS:
3732 gtk_entry_set_positions (entry, tmp_pos, tmp_pos);
3735 case GDK_2BUTTON_PRESS:
3736 entry->select_words = TRUE;
3737 gtk_entry_select_word (entry);
3740 case GDK_3BUTTON_PRESS:
3741 entry->select_lines = TRUE;
3742 gtk_entry_select_line (entry);
3749 start = MIN (entry->current_pos, entry->selection_bound);
3750 start = MIN (sel_start, start);
3752 end = MAX (entry->current_pos, entry->selection_bound);
3753 end = MAX (sel_end, end);
3755 if (tmp_pos == sel_start || tmp_pos == sel_end)
3756 extend_to_left = (tmp_pos == start);
3758 extend_to_left = (end == sel_end);
3761 gtk_entry_set_positions (entry, start, end);
3763 gtk_entry_set_positions (entry, end, start);
3766 else /* no shift key */
3767 switch (event->type)
3769 case GDK_BUTTON_PRESS:
3770 if (in_selection (entry, event->x + entry->scroll_offset))
3772 /* Click inside the selection - we'll either start a drag, or
3773 * clear the selection
3775 entry->in_drag = TRUE;
3776 entry->drag_start_x = event->x + entry->scroll_offset;
3777 entry->drag_start_y = event->y;
3780 gtk_editable_set_position (editable, tmp_pos);
3783 case GDK_2BUTTON_PRESS:
3784 /* We ALWAYS receive a GDK_BUTTON_PRESS immediately before
3785 * receiving a GDK_2BUTTON_PRESS so we need to reset
3786 * entry->in_drag which may have been set above
3788 entry->in_drag = FALSE;
3789 entry->select_words = TRUE;
3790 gtk_entry_select_word (entry);
3793 case GDK_3BUTTON_PRESS:
3794 /* We ALWAYS receive a GDK_BUTTON_PRESS immediately before
3795 * receiving a GDK_3BUTTON_PRESS so we need to reset
3796 * entry->in_drag which may have been set above
3798 entry->in_drag = FALSE;
3799 entry->select_lines = TRUE;
3800 gtk_entry_select_line (entry);
3809 else if (event->button == 2 && event->type == GDK_BUTTON_PRESS)
3811 if (entry->editable)
3813 priv->insert_pos = tmp_pos;
3814 gtk_entry_paste (entry, GDK_SELECTION_PRIMARY);
3819 gtk_widget_error_bell (widget);
3822 else if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
3824 gtk_entry_do_popup (entry, event);
3825 entry->button = 0; /* Don't wait for release, since the menu will gtk_grab_add */
3834 gtk_entry_button_release (GtkWidget *widget,
3835 GdkEventButton *event)
3837 GtkEntry *entry = GTK_ENTRY (widget);
3838 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
3839 EntryIconInfo *icon_info = NULL;
3842 for (i = 0; i < MAX_ICONS; i++)
3844 icon_info = priv->icons[i];
3846 if (!icon_info || icon_info->insensitive)
3849 if (event->window == icon_info->window)
3853 gdk_drawable_get_size (icon_info->window, &width, &height);
3855 icon_info->pressed = FALSE;
3857 if (should_prelight (entry, i) &&
3858 event->x >= 0 && event->y >= 0 &&
3859 event->x < width && event->y < height)
3861 icon_info->prelight = TRUE;
3862 gtk_widget_queue_draw (widget);
3865 if (!icon_info->nonactivatable)
3866 g_signal_emit (entry, signals[ICON_RELEASE], 0, i, event);
3872 if (event->window != entry->text_area || entry->button != event->button)
3877 gint tmp_pos = gtk_entry_find_position (entry, entry->drag_start_x);
3879 gtk_editable_set_position (GTK_EDITABLE (entry), tmp_pos);
3886 gtk_entry_update_primary_selection (entry);
3892 _gtk_entry_get_selected_text (GtkEntry *entry)
3894 GtkEditable *editable = GTK_EDITABLE (entry);
3895 gint start_text, end_text;
3898 if (gtk_editable_get_selection_bounds (editable, &start_text, &end_text))
3899 text = gtk_editable_get_chars (editable, start_text, end_text);
3905 gtk_entry_motion_notify (GtkWidget *widget,
3906 GdkEventMotion *event)
3908 GtkEntry *entry = GTK_ENTRY (widget);
3909 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3910 EntryIconInfo *icon_info = NULL;
3911 GdkDragContext *context;
3915 for (i = 0; i < MAX_ICONS; i++)
3917 icon_info = priv->icons[i];
3919 if (!icon_info || icon_info->insensitive)
3922 if (event->window == icon_info->window)
3924 if (icon_info->pressed &&
3925 icon_info->target_list != NULL &&
3926 gtk_drag_check_threshold (widget,
3932 icon_info->in_drag = TRUE;
3933 icon_info->pressed = FALSE;
3934 context = gtk_drag_begin (widget,
3935 icon_info->target_list,
3945 if (entry->mouse_cursor_obscured)
3949 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
3950 gdk_window_set_cursor (entry->text_area, cursor);
3951 gdk_cursor_unref (cursor);
3952 entry->mouse_cursor_obscured = FALSE;
3955 if (event->window != entry->text_area || entry->button != 1)
3958 if (entry->select_lines)
3961 gdk_event_request_motions (event);
3965 if (gtk_entry_get_display_mode (entry) == DISPLAY_NORMAL &&
3966 gtk_drag_check_threshold (widget,
3967 entry->drag_start_x, entry->drag_start_y,
3968 event->x + entry->scroll_offset, event->y))
3970 GdkDragContext *context;
3971 GtkTargetList *target_list = gtk_target_list_new (NULL, 0);
3972 guint actions = entry->editable ? GDK_ACTION_COPY | GDK_ACTION_MOVE : GDK_ACTION_COPY;
3974 GdkPixmap *pixmap = NULL;
3976 gtk_target_list_add_text_targets (target_list, 0);
3978 text = _gtk_entry_get_selected_text (entry);
3979 pixmap = _gtk_text_util_create_drag_icon (widget, text, -1);
3981 context = gtk_drag_begin (widget, target_list, actions,
3982 entry->button, (GdkEvent *)event);
3985 gtk_drag_set_icon_pixmap (context,
3986 gdk_drawable_get_colormap (pixmap),
3991 gtk_drag_set_icon_default (context);
3994 g_object_unref (pixmap);
3997 entry->in_drag = FALSE;
4000 gtk_target_list_unref (target_list);
4006 gdk_drawable_get_size (entry->text_area, NULL, &height);
4010 else if (event->y >= height)
4011 tmp_pos = gtk_entry_buffer_get_length (get_buffer (entry));
4013 tmp_pos = gtk_entry_find_position (entry, event->x + entry->scroll_offset);
4015 if (entry->select_words)
4018 gint old_min, old_max;
4021 min = gtk_entry_move_backward_word (entry, tmp_pos, TRUE);
4022 max = gtk_entry_move_forward_word (entry, tmp_pos, TRUE);
4024 pos = entry->current_pos;
4025 bound = entry->selection_bound;
4027 old_min = MIN(entry->current_pos, entry->selection_bound);
4028 old_max = MAX(entry->current_pos, entry->selection_bound);
4035 else if (old_max < max)
4040 else if (pos == old_min)
4042 if (entry->current_pos != min)
4047 if (entry->current_pos != max)
4051 gtk_entry_set_positions (entry, pos, bound);
4054 gtk_entry_set_positions (entry, tmp_pos, -1);
4061 set_invisible_cursor (GdkWindow *window)
4063 GdkDisplay *display;
4066 display = gdk_drawable_get_display (window);
4067 cursor = gdk_cursor_new_for_display (display, GDK_BLANK_CURSOR);
4069 gdk_window_set_cursor (window, cursor);
4071 gdk_cursor_unref (cursor);
4075 gtk_entry_obscure_mouse_cursor (GtkEntry *entry)
4077 if (entry->mouse_cursor_obscured)
4080 set_invisible_cursor (entry->text_area);
4082 entry->mouse_cursor_obscured = TRUE;
4086 gtk_entry_key_press (GtkWidget *widget,
4089 GtkEntry *entry = GTK_ENTRY (widget);
4091 gtk_entry_reset_blink_time (entry);
4092 gtk_entry_pend_cursor_blink (entry);
4094 if (entry->editable)
4096 if (gtk_im_context_filter_keypress (entry->im_context, event))
4098 gtk_entry_obscure_mouse_cursor (entry);
4099 entry->need_im_reset = TRUE;
4104 if (event->keyval == GDK_Return ||
4105 event->keyval == GDK_KP_Enter ||
4106 event->keyval == GDK_ISO_Enter ||
4107 event->keyval == GDK_Escape)
4109 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
4111 if (completion && completion->priv->completion_timeout)
4113 g_source_remove (completion->priv->completion_timeout);
4114 completion->priv->completion_timeout = 0;
4117 _gtk_entry_reset_im_context (entry);
4120 if (GTK_WIDGET_CLASS (gtk_entry_parent_class)->key_press_event (widget, event))
4121 /* Activate key bindings
4125 if (!entry->editable && event->length)
4126 gtk_widget_error_bell (widget);
4132 gtk_entry_key_release (GtkWidget *widget,
4135 GtkEntry *entry = GTK_ENTRY (widget);
4137 if (entry->editable)
4139 if (gtk_im_context_filter_keypress (entry->im_context, event))
4141 entry->need_im_reset = TRUE;
4146 return GTK_WIDGET_CLASS (gtk_entry_parent_class)->key_release_event (widget, event);
4150 gtk_entry_focus_in (GtkWidget *widget,
4151 GdkEventFocus *event)
4153 GtkEntry *entry = GTK_ENTRY (widget);
4156 gtk_widget_queue_draw (widget);
4158 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (widget));
4160 if (entry->editable)
4162 entry->need_im_reset = TRUE;
4163 gtk_im_context_focus_in (entry->im_context);
4164 keymap_state_changed (keymap, entry);
4165 g_signal_connect (keymap, "state-changed",
4166 G_CALLBACK (keymap_state_changed), entry);
4169 g_signal_connect (keymap, "direction-changed",
4170 G_CALLBACK (keymap_direction_changed), entry);
4172 gtk_entry_reset_blink_time (entry);
4173 gtk_entry_check_cursor_blink (entry);
4179 gtk_entry_focus_out (GtkWidget *widget,
4180 GdkEventFocus *event)
4182 GtkEntry *entry = GTK_ENTRY (widget);
4183 GtkEntryCompletion *completion;
4186 gtk_widget_queue_draw (widget);
4188 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (widget));
4190 if (entry->editable)
4192 entry->need_im_reset = TRUE;
4193 gtk_im_context_focus_out (entry->im_context);
4194 remove_capslock_feedback (entry);
4197 gtk_entry_check_cursor_blink (entry);
4199 g_signal_handlers_disconnect_by_func (keymap, keymap_state_changed, entry);
4200 g_signal_handlers_disconnect_by_func (keymap, keymap_direction_changed, entry);
4202 completion = gtk_entry_get_completion (entry);
4204 _gtk_entry_completion_popdown (completion);
4210 gtk_entry_grab_focus (GtkWidget *widget)
4212 GtkEntry *entry = GTK_ENTRY (widget);
4213 gboolean select_on_focus;
4215 GTK_WIDGET_CLASS (gtk_entry_parent_class)->grab_focus (widget);
4217 if (entry->editable && !entry->in_click)
4219 g_object_get (gtk_widget_get_settings (widget),
4220 "gtk-entry-select-on-focus",
4224 if (select_on_focus)
4225 gtk_editable_select_region (GTK_EDITABLE (widget), 0, -1);
4230 gtk_entry_direction_changed (GtkWidget *widget,
4231 GtkTextDirection previous_dir)
4233 GtkEntry *entry = GTK_ENTRY (widget);
4235 gtk_entry_recompute (entry);
4237 GTK_WIDGET_CLASS (gtk_entry_parent_class)->direction_changed (widget, previous_dir);
4241 gtk_entry_state_changed (GtkWidget *widget,
4242 GtkStateType previous_state)
4244 GtkEntry *entry = GTK_ENTRY (widget);
4245 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
4249 if (gtk_widget_get_realized (widget))
4251 gdk_window_set_background (widget->window, &widget->style->base[gtk_widget_get_state (widget)]);
4252 gdk_window_set_background (entry->text_area, &widget->style->base[gtk_widget_get_state (widget)]);
4253 for (i = 0; i < MAX_ICONS; i++)
4255 EntryIconInfo *icon_info = priv->icons[i];
4256 if (icon_info && icon_info->window)
4257 gdk_window_set_background (icon_info->window, &widget->style->base[gtk_widget_get_state (widget)]);
4260 if (gtk_widget_is_sensitive (widget))
4261 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
4265 gdk_window_set_cursor (entry->text_area, cursor);
4268 gdk_cursor_unref (cursor);
4270 entry->mouse_cursor_obscured = FALSE;
4272 update_cursors (widget);
4275 if (!gtk_widget_is_sensitive (widget))
4277 /* Clear any selection */
4278 gtk_editable_select_region (GTK_EDITABLE (entry), entry->current_pos, entry->current_pos);
4281 gtk_widget_queue_draw (widget);
4285 gtk_entry_screen_changed (GtkWidget *widget,
4286 GdkScreen *old_screen)
4288 gtk_entry_recompute (GTK_ENTRY (widget));
4291 /* GtkEditable method implementations
4294 gtk_entry_insert_text (GtkEditable *editable,
4295 const gchar *new_text,
4296 gint new_text_length,
4299 g_object_ref (editable);
4302 * The incoming text may a password or other secret. We make sure
4303 * not to copy it into temporary buffers.
4306 g_signal_emit_by_name (editable, "insert-text", new_text, new_text_length, position);
4308 g_object_unref (editable);
4312 gtk_entry_delete_text (GtkEditable *editable,
4316 g_object_ref (editable);
4318 g_signal_emit_by_name (editable, "delete-text", start_pos, end_pos);
4320 g_object_unref (editable);
4324 gtk_entry_get_chars (GtkEditable *editable,
4328 GtkEntry *entry = GTK_ENTRY (editable);
4331 gint start_index, end_index;
4333 text = gtk_entry_buffer_get_text (get_buffer (entry));
4334 text_length = gtk_entry_buffer_get_length (get_buffer (entry));
4337 end_pos = text_length;
4339 start_pos = MIN (text_length, start_pos);
4340 end_pos = MIN (text_length, end_pos);
4342 start_index = g_utf8_offset_to_pointer (text, start_pos) - entry->text;
4343 end_index = g_utf8_offset_to_pointer (text, end_pos) - entry->text;
4345 return g_strndup (text + start_index, end_index - start_index);
4349 gtk_entry_real_set_position (GtkEditable *editable,
4352 GtkEntry *entry = GTK_ENTRY (editable);
4356 length = gtk_entry_buffer_get_length (get_buffer (entry));
4357 if (position < 0 || position > length)
4360 if (position != entry->current_pos ||
4361 position != entry->selection_bound)
4363 _gtk_entry_reset_im_context (entry);
4364 gtk_entry_set_positions (entry, position, position);
4369 gtk_entry_get_position (GtkEditable *editable)
4371 return GTK_ENTRY (editable)->current_pos;
4375 gtk_entry_set_selection_bounds (GtkEditable *editable,
4379 GtkEntry *entry = GTK_ENTRY (editable);
4382 length = gtk_entry_buffer_get_length (get_buffer (entry));
4388 _gtk_entry_reset_im_context (entry);
4390 gtk_entry_set_positions (entry,
4392 MIN (start, length));
4394 gtk_entry_update_primary_selection (entry);
4398 gtk_entry_get_selection_bounds (GtkEditable *editable,
4402 GtkEntry *entry = GTK_ENTRY (editable);
4404 *start = entry->selection_bound;
4405 *end = entry->current_pos;
4407 return (entry->selection_bound != entry->current_pos);
4411 icon_theme_changed (GtkEntry *entry)
4413 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
4416 for (i = 0; i < MAX_ICONS; i++)
4418 EntryIconInfo *icon_info = priv->icons[i];
4419 if (icon_info != NULL)
4421 if (icon_info->storage_type == GTK_IMAGE_ICON_NAME)
4422 gtk_entry_set_icon_from_icon_name (entry, i, icon_info->icon_name);
4423 else if (icon_info->storage_type == GTK_IMAGE_STOCK)
4424 gtk_entry_set_icon_from_stock (entry, i, icon_info->stock_id);
4425 else if (icon_info->storage_type == GTK_IMAGE_GICON)
4426 gtk_entry_set_icon_from_gicon (entry, i, icon_info->gicon);
4430 gtk_widget_queue_draw (GTK_WIDGET (entry));
4434 icon_margin_changed (GtkEntry *entry)
4436 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
4439 _gtk_entry_effective_inner_border (GTK_ENTRY (entry), &border);
4441 priv->icon_margin = border.left;
4445 gtk_entry_style_set (GtkWidget *widget,
4446 GtkStyle *previous_style)
4448 GtkEntry *entry = GTK_ENTRY (widget);
4449 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
4451 gboolean interior_focus;
4454 gtk_widget_style_get (widget,
4455 "focus-line-width", &focus_width,
4456 "interior-focus", &interior_focus,
4459 priv->focus_width = focus_width;
4460 priv->interior_focus = interior_focus;
4462 if (!priv->invisible_char_set)
4463 entry->invisible_char = find_invisible_char (GTK_WIDGET (entry));
4465 gtk_entry_recompute (entry);
4467 if (previous_style && gtk_widget_get_realized (widget))
4469 gdk_window_set_background (widget->window, &widget->style->base[gtk_widget_get_state (widget)]);
4470 gdk_window_set_background (entry->text_area, &widget->style->base[gtk_widget_get_state (widget)]);
4471 for (i = 0; i < MAX_ICONS; i++)
4473 EntryIconInfo *icon_info = priv->icons[i];
4474 if (icon_info && icon_info->window)
4475 gdk_window_set_background (icon_info->window, &widget->style->base[gtk_widget_get_state (widget)]);
4479 icon_theme_changed (entry);
4480 icon_margin_changed (entry);
4483 /* GtkCellEditable method implementations
4486 gtk_cell_editable_entry_activated (GtkEntry *entry, gpointer data)
4488 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4489 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4493 gtk_cell_editable_key_press_event (GtkEntry *entry,
4494 GdkEventKey *key_event,
4497 if (key_event->keyval == GDK_Escape)
4499 entry->editing_canceled = TRUE;
4500 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4501 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4506 /* override focus */
4507 if (key_event->keyval == GDK_Up || key_event->keyval == GDK_Down)
4509 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4510 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4519 gtk_entry_start_editing (GtkCellEditable *cell_editable,
4522 GTK_ENTRY (cell_editable)->is_cell_renderer = TRUE;
4524 g_signal_connect (cell_editable, "activate",
4525 G_CALLBACK (gtk_cell_editable_entry_activated), NULL);
4526 g_signal_connect (cell_editable, "key-press-event",
4527 G_CALLBACK (gtk_cell_editable_key_press_event), NULL);
4531 gtk_entry_password_hint_free (GtkEntryPasswordHint *password_hint)
4533 if (password_hint->source_id)
4534 g_source_remove (password_hint->source_id);
4536 g_slice_free (GtkEntryPasswordHint, password_hint);
4541 gtk_entry_remove_password_hint (gpointer data)
4543 GtkEntryPasswordHint *password_hint = g_object_get_qdata (data, quark_password_hint);
4544 password_hint->position = -1;
4546 /* Force the string to be redrawn, but now without a visible character */
4547 gtk_entry_recompute (GTK_ENTRY (data));
4551 /* Default signal handlers
4554 gtk_entry_real_insert_text (GtkEditable *editable,
4555 const gchar *new_text,
4556 gint new_text_length,
4562 n_chars = g_utf8_strlen (new_text, new_text_length);
4565 * The actual insertion into the buffer. This will end up firing the
4566 * following signal handlers: buffer_inserted_text(), buffer_notify_display_text(),
4567 * buffer_notify_text(), buffer_notify_length()
4569 n_inserted = gtk_entry_buffer_insert_text (get_buffer (GTK_ENTRY (editable)), *position, new_text, n_chars);
4571 if (n_inserted != n_chars)
4572 gtk_widget_error_bell (GTK_WIDGET (editable));
4574 *position += n_inserted;
4578 gtk_entry_real_delete_text (GtkEditable *editable,
4583 * The actual deletion from the buffer. This will end up firing the
4584 * following signal handlers: buffer_deleted_text(), buffer_notify_display_text(),
4585 * buffer_notify_text(), buffer_notify_length()
4588 gtk_entry_buffer_delete_text (get_buffer (GTK_ENTRY (editable)), start_pos, end_pos - start_pos);
4591 /* GtkEntryBuffer signal handlers
4594 buffer_inserted_text (GtkEntryBuffer *buffer,
4600 guint password_hint_timeout;
4602 if (entry->current_pos > position)
4603 entry->current_pos += n_chars;
4605 if (entry->selection_bound > position)
4606 entry->selection_bound += n_chars;
4608 /* Calculate the password hint if it needs to be displayed. */
4609 if (n_chars == 1 && !entry->visible)
4611 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
4612 "gtk-entry-password-hint-timeout", &password_hint_timeout,
4615 if (password_hint_timeout > 0)
4617 GtkEntryPasswordHint *password_hint = g_object_get_qdata (G_OBJECT (entry),
4618 quark_password_hint);
4621 password_hint = g_slice_new0 (GtkEntryPasswordHint);
4622 g_object_set_qdata_full (G_OBJECT (entry), quark_password_hint, password_hint,
4623 (GDestroyNotify)gtk_entry_password_hint_free);
4626 password_hint->position = position;
4627 if (password_hint->source_id)
4628 g_source_remove (password_hint->source_id);
4629 password_hint->source_id = gdk_threads_add_timeout (password_hint_timeout,
4630 (GSourceFunc)gtk_entry_remove_password_hint, entry);
4636 buffer_deleted_text (GtkEntryBuffer *buffer,
4641 guint end_pos = position + n_chars;
4642 gint selection_bound;
4645 current_pos = entry->current_pos;
4646 if (current_pos > position)
4647 current_pos -= MIN (current_pos, end_pos) - position;
4649 selection_bound = entry->selection_bound;
4650 if (selection_bound > position)
4651 selection_bound -= MIN (selection_bound, end_pos) - position;
4653 gtk_entry_set_positions (entry, current_pos, selection_bound);
4655 /* We might have deleted the selection */
4656 gtk_entry_update_primary_selection (entry);
4658 /* Disable the password hint if one exists. */
4659 if (!entry->visible)
4661 GtkEntryPasswordHint *password_hint = g_object_get_qdata (G_OBJECT (entry),
4662 quark_password_hint);
4665 if (password_hint->source_id)
4666 g_source_remove (password_hint->source_id);
4667 password_hint->source_id = 0;
4668 password_hint->position = -1;
4674 buffer_notify_text (GtkEntryBuffer *buffer,
4678 /* COMPAT: Deprecated, not used. This struct field will be removed in GTK+ 3.x */
4679 entry->text = (gchar*)gtk_entry_buffer_get_text (buffer);
4681 gtk_entry_recompute (entry);
4682 emit_changed (entry);
4683 g_object_notify (G_OBJECT (entry), "text");
4687 buffer_notify_length (GtkEntryBuffer *buffer,
4691 /* COMPAT: Deprecated, not used. This struct field will be removed in GTK+ 3.x */
4692 entry->text_length = gtk_entry_buffer_get_length (buffer);
4694 g_object_notify (G_OBJECT (entry), "text-length");
4698 buffer_notify_max_length (GtkEntryBuffer *buffer,
4702 /* COMPAT: Deprecated, not used. This struct field will be removed in GTK+ 3.x */
4703 entry->text_max_length = gtk_entry_buffer_get_max_length (buffer);
4705 g_object_notify (G_OBJECT (entry), "max-length");
4709 buffer_connect_signals (GtkEntry *entry)
4711 g_signal_connect (get_buffer (entry), "inserted-text", G_CALLBACK (buffer_inserted_text), entry);
4712 g_signal_connect (get_buffer (entry), "deleted-text", G_CALLBACK (buffer_deleted_text), entry);
4713 g_signal_connect (get_buffer (entry), "notify::text", G_CALLBACK (buffer_notify_text), entry);
4714 g_signal_connect (get_buffer (entry), "notify::length", G_CALLBACK (buffer_notify_length), entry);
4715 g_signal_connect (get_buffer (entry), "notify::max-length", G_CALLBACK (buffer_notify_max_length), entry);
4719 buffer_disconnect_signals (GtkEntry *entry)
4721 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_inserted_text, entry);
4722 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_deleted_text, entry);
4723 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_text, entry);
4724 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_length, entry);
4725 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_max_length, entry);
4728 /* Compute the X position for an offset that corresponds to the "more important
4729 * cursor position for that offset. We use this when trying to guess to which
4730 * end of the selection we should go to when the user hits the left or
4734 get_better_cursor_x (GtkEntry *entry,
4737 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
4738 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
4739 gboolean split_cursor;
4741 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
4742 const gchar *text = pango_layout_get_text (layout);
4743 gint index = g_utf8_offset_to_pointer (text, offset) - text;
4745 PangoRectangle strong_pos, weak_pos;
4747 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
4748 "gtk-split-cursor", &split_cursor,
4751 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
4754 return strong_pos.x / PANGO_SCALE;
4756 return (keymap_direction == entry->resolved_dir) ? strong_pos.x / PANGO_SCALE : weak_pos.x / PANGO_SCALE;
4760 gtk_entry_move_cursor (GtkEntry *entry,
4761 GtkMovementStep step,
4763 gboolean extend_selection)
4765 gint new_pos = entry->current_pos;
4766 GtkEntryPrivate *priv;
4768 _gtk_entry_reset_im_context (entry);
4770 if (entry->current_pos != entry->selection_bound && !extend_selection)
4772 /* If we have a current selection and aren't extending it, move to the
4773 * start/or end of the selection as appropriate
4777 case GTK_MOVEMENT_VISUAL_POSITIONS:
4779 gint current_x = get_better_cursor_x (entry, entry->current_pos);
4780 gint bound_x = get_better_cursor_x (entry, entry->selection_bound);
4783 new_pos = current_x < bound_x ? entry->current_pos : entry->selection_bound;
4785 new_pos = current_x > bound_x ? entry->current_pos : entry->selection_bound;
4788 case GTK_MOVEMENT_LOGICAL_POSITIONS:
4789 case GTK_MOVEMENT_WORDS:
4791 new_pos = MIN (entry->current_pos, entry->selection_bound);
4793 new_pos = MAX (entry->current_pos, entry->selection_bound);
4795 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
4796 case GTK_MOVEMENT_PARAGRAPH_ENDS:
4797 case GTK_MOVEMENT_BUFFER_ENDS:
4798 priv = GTK_ENTRY_GET_PRIVATE (entry);
4799 new_pos = count < 0 ? 0 : gtk_entry_buffer_get_length (get_buffer (entry));
4801 case GTK_MOVEMENT_DISPLAY_LINES:
4802 case GTK_MOVEMENT_PARAGRAPHS:
4803 case GTK_MOVEMENT_PAGES:
4804 case GTK_MOVEMENT_HORIZONTAL_PAGES:
4812 case GTK_MOVEMENT_LOGICAL_POSITIONS:
4813 new_pos = gtk_entry_move_logically (entry, new_pos, count);
4815 case GTK_MOVEMENT_VISUAL_POSITIONS:
4816 new_pos = gtk_entry_move_visually (entry, new_pos, count);
4817 if (entry->current_pos == new_pos)
4819 if (!extend_selection)
4821 if (!gtk_widget_keynav_failed (GTK_WIDGET (entry),
4823 GTK_DIR_RIGHT : GTK_DIR_LEFT))
4825 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (entry));
4828 gtk_widget_child_focus (toplevel,
4830 GTK_DIR_RIGHT : GTK_DIR_LEFT);
4835 gtk_widget_error_bell (GTK_WIDGET (entry));
4839 case GTK_MOVEMENT_WORDS:
4842 new_pos = gtk_entry_move_forward_word (entry, new_pos, FALSE);
4847 new_pos = gtk_entry_move_backward_word (entry, new_pos, FALSE);
4850 if (entry->current_pos == new_pos)
4851 gtk_widget_error_bell (GTK_WIDGET (entry));
4853 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
4854 case GTK_MOVEMENT_PARAGRAPH_ENDS:
4855 case GTK_MOVEMENT_BUFFER_ENDS:
4856 priv = GTK_ENTRY_GET_PRIVATE (entry);
4857 new_pos = count < 0 ? 0 : gtk_entry_buffer_get_length (get_buffer (entry));
4858 if (entry->current_pos == new_pos)
4859 gtk_widget_error_bell (GTK_WIDGET (entry));
4861 case GTK_MOVEMENT_DISPLAY_LINES:
4862 case GTK_MOVEMENT_PARAGRAPHS:
4863 case GTK_MOVEMENT_PAGES:
4864 case GTK_MOVEMENT_HORIZONTAL_PAGES:
4869 if (extend_selection)
4870 gtk_editable_select_region (GTK_EDITABLE (entry), entry->selection_bound, new_pos);
4872 gtk_editable_set_position (GTK_EDITABLE (entry), new_pos);
4874 gtk_entry_pend_cursor_blink (entry);
4878 gtk_entry_insert_at_cursor (GtkEntry *entry,
4881 GtkEditable *editable = GTK_EDITABLE (entry);
4882 gint pos = entry->current_pos;
4884 if (entry->editable)
4886 _gtk_entry_reset_im_context (entry);
4888 gtk_editable_insert_text (editable, str, -1, &pos);
4889 gtk_editable_set_position (editable, pos);
4894 gtk_entry_delete_from_cursor (GtkEntry *entry,
4898 GtkEditable *editable = GTK_EDITABLE (entry);
4899 gint start_pos = entry->current_pos;
4900 gint end_pos = entry->current_pos;
4901 gint old_n_bytes = gtk_entry_buffer_get_bytes (get_buffer (entry));
4903 _gtk_entry_reset_im_context (entry);
4905 if (!entry->editable)
4907 gtk_widget_error_bell (GTK_WIDGET (entry));
4911 if (entry->selection_bound != entry->current_pos)
4913 gtk_editable_delete_selection (editable);
4919 case GTK_DELETE_CHARS:
4920 end_pos = gtk_entry_move_logically (entry, entry->current_pos, count);
4921 gtk_editable_delete_text (editable, MIN (start_pos, end_pos), MAX (start_pos, end_pos));
4923 case GTK_DELETE_WORDS:
4926 /* Move to end of current word, or if not on a word, end of previous word */
4927 end_pos = gtk_entry_move_backward_word (entry, end_pos, FALSE);
4928 end_pos = gtk_entry_move_forward_word (entry, end_pos, FALSE);
4932 /* Move to beginning of current word, or if not on a word, begining of next word */
4933 start_pos = gtk_entry_move_forward_word (entry, start_pos, FALSE);
4934 start_pos = gtk_entry_move_backward_word (entry, start_pos, FALSE);
4938 case GTK_DELETE_WORD_ENDS:
4941 start_pos = gtk_entry_move_backward_word (entry, start_pos, FALSE);
4946 end_pos = gtk_entry_move_forward_word (entry, end_pos, FALSE);
4949 gtk_editable_delete_text (editable, start_pos, end_pos);
4951 case GTK_DELETE_DISPLAY_LINE_ENDS:
4952 case GTK_DELETE_PARAGRAPH_ENDS:
4954 gtk_editable_delete_text (editable, 0, entry->current_pos);
4956 gtk_editable_delete_text (editable, entry->current_pos, -1);
4958 case GTK_DELETE_DISPLAY_LINES:
4959 case GTK_DELETE_PARAGRAPHS:
4960 gtk_editable_delete_text (editable, 0, -1);
4962 case GTK_DELETE_WHITESPACE:
4963 gtk_entry_delete_whitespace (entry);
4967 if (gtk_entry_buffer_get_bytes (get_buffer (entry)) == old_n_bytes)
4968 gtk_widget_error_bell (GTK_WIDGET (entry));
4970 gtk_entry_pend_cursor_blink (entry);
4974 gtk_entry_backspace (GtkEntry *entry)
4976 GtkEditable *editable = GTK_EDITABLE (entry);
4979 _gtk_entry_reset_im_context (entry);
4981 if (!entry->editable)
4983 gtk_widget_error_bell (GTK_WIDGET (entry));
4987 if (entry->selection_bound != entry->current_pos)
4989 gtk_editable_delete_selection (editable);
4993 prev_pos = gtk_entry_move_logically (entry, entry->current_pos, -1);
4995 if (prev_pos < entry->current_pos)
4997 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
4998 PangoLogAttr *log_attrs;
5001 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
5003 /* Deleting parts of characters */
5004 if (log_attrs[entry->current_pos].backspace_deletes_character)
5006 gchar *cluster_text;
5007 gchar *normalized_text;
5010 cluster_text = gtk_entry_get_display_text (entry, prev_pos,
5011 entry->current_pos);
5012 normalized_text = g_utf8_normalize (cluster_text,
5013 strlen (cluster_text),
5015 len = g_utf8_strlen (normalized_text, -1);
5017 gtk_editable_delete_text (editable, prev_pos, entry->current_pos);
5020 gint pos = entry->current_pos;
5022 gtk_editable_insert_text (editable, normalized_text,
5023 g_utf8_offset_to_pointer (normalized_text, len - 1) - normalized_text,
5025 gtk_editable_set_position (editable, pos);
5028 g_free (normalized_text);
5029 g_free (cluster_text);
5033 gtk_editable_delete_text (editable, prev_pos, entry->current_pos);
5040 gtk_widget_error_bell (GTK_WIDGET (entry));
5043 gtk_entry_pend_cursor_blink (entry);
5047 gtk_entry_copy_clipboard (GtkEntry *entry)
5049 GtkEditable *editable = GTK_EDITABLE (entry);
5053 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5055 if (!entry->visible)
5057 gtk_widget_error_bell (GTK_WIDGET (entry));
5061 str = gtk_entry_get_display_text (entry, start, end);
5062 gtk_clipboard_set_text (gtk_widget_get_clipboard (GTK_WIDGET (entry),
5063 GDK_SELECTION_CLIPBOARD),
5070 gtk_entry_cut_clipboard (GtkEntry *entry)
5072 GtkEditable *editable = GTK_EDITABLE (entry);
5075 if (!entry->visible)
5077 gtk_widget_error_bell (GTK_WIDGET (entry));
5081 gtk_entry_copy_clipboard (entry);
5083 if (entry->editable)
5085 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5086 gtk_editable_delete_text (editable, start, end);
5090 gtk_widget_error_bell (GTK_WIDGET (entry));
5095 gtk_entry_paste_clipboard (GtkEntry *entry)
5097 if (entry->editable)
5098 gtk_entry_paste (entry, GDK_NONE);
5100 gtk_widget_error_bell (GTK_WIDGET (entry));
5104 gtk_entry_delete_cb (GtkEntry *entry)
5106 GtkEditable *editable = GTK_EDITABLE (entry);
5109 if (entry->editable)
5111 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5112 gtk_editable_delete_text (editable, start, end);
5117 gtk_entry_toggle_overwrite (GtkEntry *entry)
5119 entry->overwrite_mode = !entry->overwrite_mode;
5120 gtk_entry_pend_cursor_blink (entry);
5121 gtk_widget_queue_draw (GTK_WIDGET (entry));
5125 gtk_entry_select_all (GtkEntry *entry)
5127 gtk_entry_select_line (entry);
5131 gtk_entry_real_activate (GtkEntry *entry)
5134 GtkWidget *toplevel;
5137 widget = GTK_WIDGET (entry);
5139 if (entry->activates_default)
5141 toplevel = gtk_widget_get_toplevel (widget);
5142 if (GTK_IS_WINDOW (toplevel))
5144 window = GTK_WINDOW (toplevel);
5147 widget != window->default_widget &&
5148 !(widget == window->focus_widget &&
5149 (!window->default_widget || !gtk_widget_get_sensitive (window->default_widget))))
5150 gtk_window_activate_default (window);
5156 keymap_direction_changed (GdkKeymap *keymap,
5159 gtk_entry_recompute (entry);
5162 /* IM Context Callbacks
5166 gtk_entry_commit_cb (GtkIMContext *context,
5170 if (entry->editable)
5171 gtk_entry_enter_text (entry, str);
5175 gtk_entry_preedit_changed_cb (GtkIMContext *context,
5178 if (entry->editable)
5180 gchar *preedit_string;
5183 gtk_im_context_get_preedit_string (entry->im_context,
5184 &preedit_string, NULL,
5186 g_signal_emit (entry, signals[PREEDIT_CHANGED], 0, preedit_string);
5187 entry->preedit_length = strlen (preedit_string);
5188 cursor_pos = CLAMP (cursor_pos, 0, g_utf8_strlen (preedit_string, -1));
5189 entry->preedit_cursor = cursor_pos;
5190 g_free (preedit_string);
5192 gtk_entry_recompute (entry);
5197 gtk_entry_retrieve_surrounding_cb (GtkIMContext *context,
5202 /* XXXX ??? does this even make sense when text is not visible? Should we return FALSE? */
5203 text = gtk_entry_get_display_text (entry, 0, -1);
5204 gtk_im_context_set_surrounding (context, text, strlen (text), /* Length in bytes */
5205 g_utf8_offset_to_pointer (text, entry->current_pos) - text);
5212 gtk_entry_delete_surrounding_cb (GtkIMContext *slave,
5217 if (entry->editable)
5218 gtk_editable_delete_text (GTK_EDITABLE (entry),
5219 entry->current_pos + offset,
5220 entry->current_pos + offset + n_chars);
5225 /* Internal functions
5228 /* Used for im_commit_cb and inserting Unicode chars */
5230 gtk_entry_enter_text (GtkEntry *entry,
5233 GtkEditable *editable = GTK_EDITABLE (entry);
5235 gboolean old_need_im_reset;
5237 old_need_im_reset = entry->need_im_reset;
5238 entry->need_im_reset = FALSE;
5240 if (gtk_editable_get_selection_bounds (editable, NULL, NULL))
5241 gtk_editable_delete_selection (editable);
5244 if (entry->overwrite_mode)
5245 gtk_entry_delete_from_cursor (entry, GTK_DELETE_CHARS, 1);
5248 tmp_pos = entry->current_pos;
5249 gtk_editable_insert_text (editable, str, strlen (str), &tmp_pos);
5250 gtk_editable_set_position (editable, tmp_pos);
5252 entry->need_im_reset = old_need_im_reset;
5255 /* All changes to entry->current_pos and entry->selection_bound
5256 * should go through this function.
5259 gtk_entry_set_positions (GtkEntry *entry,
5261 gint selection_bound)
5263 gboolean changed = FALSE;
5265 g_object_freeze_notify (G_OBJECT (entry));
5267 if (current_pos != -1 &&
5268 entry->current_pos != current_pos)
5270 entry->current_pos = current_pos;
5273 g_object_notify (G_OBJECT (entry), "cursor-position");
5276 if (selection_bound != -1 &&
5277 entry->selection_bound != selection_bound)
5279 entry->selection_bound = selection_bound;
5282 g_object_notify (G_OBJECT (entry), "selection-bound");
5285 g_object_thaw_notify (G_OBJECT (entry));
5289 gtk_entry_move_adjustments (entry);
5290 gtk_entry_recompute (entry);
5295 gtk_entry_reset_layout (GtkEntry *entry)
5297 if (entry->cached_layout)
5299 g_object_unref (entry->cached_layout);
5300 entry->cached_layout = NULL;
5305 update_im_cursor_location (GtkEntry *entry)
5309 gint strong_xoffset;
5310 gint area_width, area_height;
5312 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
5313 gtk_entry_get_text_area_size (entry, NULL, NULL, &area_width, &area_height);
5315 strong_xoffset = strong_x - entry->scroll_offset;
5316 if (strong_xoffset < 0)
5320 else if (strong_xoffset > area_width)
5322 strong_xoffset = area_width;
5324 area.x = strong_xoffset;
5327 area.height = area_height;
5329 gtk_im_context_set_cursor_location (entry->im_context, &area);
5333 recompute_idle_func (gpointer data)
5337 entry = GTK_ENTRY (data);
5339 entry->recompute_idle = 0;
5341 if (gtk_widget_has_screen (GTK_WIDGET (entry)))
5343 gtk_entry_adjust_scroll (entry);
5344 gtk_entry_queue_draw (entry);
5346 update_im_cursor_location (entry);
5353 gtk_entry_recompute (GtkEntry *entry)
5355 gtk_entry_reset_layout (entry);
5356 gtk_entry_check_cursor_blink (entry);
5358 if (!entry->recompute_idle)
5360 entry->recompute_idle = gdk_threads_add_idle_full (G_PRIORITY_HIGH_IDLE + 15, /* between resize and redraw */
5361 recompute_idle_func, entry, NULL);
5365 static PangoLayout *
5366 gtk_entry_create_layout (GtkEntry *entry,
5367 gboolean include_preedit)
5369 GtkWidget *widget = GTK_WIDGET (entry);
5370 PangoLayout *layout = gtk_widget_create_pango_layout (widget, NULL);
5371 PangoAttrList *tmp_attrs = pango_attr_list_new ();
5373 gchar *preedit_string = NULL;
5374 gint preedit_length = 0;
5375 PangoAttrList *preedit_attrs = NULL;
5380 pango_layout_set_single_paragraph_mode (layout, TRUE);
5382 display = gtk_entry_get_display_text (entry, 0, -1);
5383 n_bytes = strlen (display);
5385 if (include_preedit)
5387 gtk_im_context_get_preedit_string (entry->im_context,
5388 &preedit_string, &preedit_attrs, NULL);
5389 preedit_length = entry->preedit_length;
5394 GString *tmp_string = g_string_new (display);
5395 gint cursor_index = g_utf8_offset_to_pointer (display, entry->current_pos) - display;
5397 g_string_insert (tmp_string, cursor_index, preedit_string);
5399 pango_layout_set_text (layout, tmp_string->str, tmp_string->len);
5401 pango_attr_list_splice (tmp_attrs, preedit_attrs,
5402 cursor_index, preedit_length);
5404 g_string_free (tmp_string, TRUE);
5408 PangoDirection pango_dir;
5410 if (gtk_entry_get_display_mode (entry) == DISPLAY_NORMAL)
5411 pango_dir = pango_find_base_dir (display, n_bytes);
5413 pango_dir = PANGO_DIRECTION_NEUTRAL;
5415 if (pango_dir == PANGO_DIRECTION_NEUTRAL)
5417 if (gtk_widget_has_focus (widget))
5419 GdkDisplay *display = gtk_widget_get_display (widget);
5420 GdkKeymap *keymap = gdk_keymap_get_for_display (display);
5421 if (gdk_keymap_get_direction (keymap) == PANGO_DIRECTION_RTL)
5422 pango_dir = PANGO_DIRECTION_RTL;
5424 pango_dir = PANGO_DIRECTION_LTR;
5428 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
5429 pango_dir = PANGO_DIRECTION_RTL;
5431 pango_dir = PANGO_DIRECTION_LTR;
5435 pango_context_set_base_dir (gtk_widget_get_pango_context (widget),
5438 entry->resolved_dir = pango_dir;
5440 pango_layout_set_text (layout, display, n_bytes);
5443 pango_layout_set_attributes (layout, tmp_attrs);
5445 g_free (preedit_string);
5449 pango_attr_list_unref (preedit_attrs);
5451 pango_attr_list_unref (tmp_attrs);
5456 static PangoLayout *
5457 gtk_entry_ensure_layout (GtkEntry *entry,
5458 gboolean include_preedit)
5460 if (entry->preedit_length > 0 &&
5461 !include_preedit != !entry->cache_includes_preedit)
5462 gtk_entry_reset_layout (entry);
5464 if (!entry->cached_layout)
5466 entry->cached_layout = gtk_entry_create_layout (entry, include_preedit);
5467 entry->cache_includes_preedit = include_preedit;
5470 return entry->cached_layout;
5474 get_layout_position (GtkEntry *entry,
5478 PangoLayout *layout;
5479 PangoRectangle logical_rect;
5480 gint area_width, area_height;
5481 GtkBorder inner_border;
5483 PangoLayoutLine *line;
5485 layout = gtk_entry_ensure_layout (entry, TRUE);
5487 gtk_entry_get_text_area_size (entry, NULL, NULL, &area_width, &area_height);
5488 _gtk_entry_effective_inner_border (entry, &inner_border);
5490 area_height = PANGO_SCALE * (area_height - inner_border.top - inner_border.bottom);
5492 line = pango_layout_get_lines_readonly (layout)->data;
5493 pango_layout_line_get_extents (line, NULL, &logical_rect);
5495 /* Align primarily for locale's ascent/descent */
5496 y_pos = ((area_height - entry->ascent - entry->descent) / 2 +
5497 entry->ascent + logical_rect.y);
5499 /* Now see if we need to adjust to fit in actual drawn string */
5500 if (logical_rect.height > area_height)
5501 y_pos = (area_height - logical_rect.height) / 2;
5504 else if (y_pos + logical_rect.height > area_height)
5505 y_pos = area_height - logical_rect.height;
5507 y_pos = inner_border.top + y_pos / PANGO_SCALE;
5510 *x = inner_border.left - entry->scroll_offset;
5517 draw_text_with_color (GtkEntry *entry, cairo_t *cr, GdkColor *default_color)
5519 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
5522 gint start_pos, end_pos;
5524 widget = GTK_WIDGET (entry);
5528 get_layout_position (entry, &x, &y);
5530 cairo_move_to (cr, x, y);
5531 gdk_cairo_set_source_color (cr, default_color);
5532 pango_cairo_show_layout (cr, layout);
5534 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start_pos, &end_pos))
5538 PangoRectangle logical_rect;
5539 GdkColor *selection_color, *text_color;
5540 GtkBorder inner_border;
5542 pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
5543 gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
5545 if (gtk_widget_has_focus (widget))
5547 selection_color = &widget->style->base [GTK_STATE_SELECTED];
5548 text_color = &widget->style->text [GTK_STATE_SELECTED];
5552 selection_color = &widget->style->base [GTK_STATE_ACTIVE];
5553 text_color = &widget->style->text [GTK_STATE_ACTIVE];
5556 _gtk_entry_effective_inner_border (entry, &inner_border);
5558 for (i = 0; i < n_ranges; ++i)
5559 cairo_rectangle (cr,
5560 inner_border.left - entry->scroll_offset + ranges[2 * i],
5563 logical_rect.height);
5567 gdk_cairo_set_source_color (cr, selection_color);
5570 cairo_move_to (cr, x, y);
5571 gdk_cairo_set_source_color (cr, text_color);
5572 pango_cairo_show_layout (cr, layout);
5580 gtk_entry_draw_text (GtkEntry *entry)
5582 GtkWidget *widget = GTK_WIDGET (entry);
5585 /* Nothing to display at all */
5586 if (gtk_entry_get_display_mode (entry) == DISPLAY_BLANK)
5589 if (gtk_widget_is_drawable (widget))
5591 GdkColor text_color, bar_text_color;
5594 gint progress_x, progress_y, progress_width, progress_height;
5597 state = GTK_STATE_SELECTED;
5598 if (!gtk_widget_get_sensitive (widget))
5599 state = GTK_STATE_INSENSITIVE;
5600 text_color = widget->style->text[widget->state];
5601 bar_text_color = widget->style->fg[state];
5603 get_progress_area (widget,
5604 &progress_x, &progress_y,
5605 &progress_width, &progress_height);
5607 cr = gdk_cairo_create (entry->text_area);
5609 /* If the color is the same, or the progress area has a zero
5610 * size, then we only need to draw once. */
5611 if ((text_color.pixel == bar_text_color.pixel) ||
5612 ((progress_width == 0) || (progress_height == 0)))
5614 draw_text_with_color (entry, cr, &text_color);
5618 gdk_drawable_get_size (entry->text_area, &width, &height);
5620 cairo_rectangle (cr, 0, 0, width, height);
5624 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
5625 cairo_rectangle (cr, 0, 0, width, height);
5627 gdk_window_get_position (entry->text_area, &pos_x, &pos_y);
5628 progress_x -= pos_x;
5629 progress_y -= pos_y;
5631 cairo_rectangle (cr, progress_x, progress_y,
5632 progress_width, progress_height);
5634 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_WINDING);
5636 draw_text_with_color (entry, cr, &text_color);
5639 cairo_rectangle (cr, progress_x, progress_y,
5640 progress_width, progress_height);
5643 draw_text_with_color (entry, cr, &bar_text_color);
5651 draw_insertion_cursor (GtkEntry *entry,
5652 GdkRectangle *cursor_location,
5653 gboolean is_primary,
5654 PangoDirection direction,
5655 gboolean draw_arrow)
5657 GtkWidget *widget = GTK_WIDGET (entry);
5658 GtkTextDirection text_dir;
5660 if (direction == PANGO_DIRECTION_LTR)
5661 text_dir = GTK_TEXT_DIR_LTR;
5663 text_dir = GTK_TEXT_DIR_RTL;
5665 gtk_draw_insertion_cursor (widget, entry->text_area, NULL,
5667 is_primary, text_dir, draw_arrow);
5671 gtk_entry_draw_cursor (GtkEntry *entry,
5674 GtkWidget *widget = GTK_WIDGET (entry);
5675 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
5676 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
5678 if (gtk_widget_is_drawable (widget))
5680 GdkRectangle cursor_location;
5681 gboolean split_cursor;
5682 PangoRectangle cursor_rect;
5683 GtkBorder inner_border;
5685 gint text_area_height;
5688 gboolean block_at_line_end;
5689 PangoLayout *layout;
5692 _gtk_entry_effective_inner_border (entry, &inner_border);
5694 xoffset = inner_border.left - entry->scroll_offset;
5696 gdk_drawable_get_size (entry->text_area, NULL, &text_area_height);
5698 layout = gtk_entry_ensure_layout (entry, TRUE);
5699 text = pango_layout_get_text (layout);
5700 cursor_index = g_utf8_offset_to_pointer (text, entry->current_pos + entry->preedit_cursor) - text;
5701 if (!entry->overwrite_mode)
5704 block = _gtk_text_util_get_block_cursor_location (layout,
5705 cursor_index, &cursor_rect, &block_at_line_end);
5709 gint strong_x, weak_x;
5710 PangoDirection dir1 = PANGO_DIRECTION_NEUTRAL;
5711 PangoDirection dir2 = PANGO_DIRECTION_NEUTRAL;
5715 gtk_entry_get_cursor_locations (entry, type, &strong_x, &weak_x);
5717 g_object_get (gtk_widget_get_settings (widget),
5718 "gtk-split-cursor", &split_cursor,
5721 dir1 = entry->resolved_dir;
5727 if (weak_x != strong_x)
5729 dir2 = (entry->resolved_dir == PANGO_DIRECTION_LTR) ? PANGO_DIRECTION_RTL : PANGO_DIRECTION_LTR;
5735 if (keymap_direction == entry->resolved_dir)
5741 cursor_location.x = xoffset + x1;
5742 cursor_location.y = inner_border.top;
5743 cursor_location.width = 0;
5744 cursor_location.height = text_area_height - inner_border.top - inner_border.bottom;
5746 draw_insertion_cursor (entry,
5747 &cursor_location, TRUE, dir1,
5748 dir2 != PANGO_DIRECTION_NEUTRAL);
5750 if (dir2 != PANGO_DIRECTION_NEUTRAL)
5752 cursor_location.x = xoffset + x2;
5753 draw_insertion_cursor (entry,
5754 &cursor_location, FALSE, dir2,
5758 else /* overwrite_mode */
5760 GdkColor cursor_color;
5765 get_layout_position (entry, &x, &y);
5767 rect.x = PANGO_PIXELS (cursor_rect.x) + x;
5768 rect.y = PANGO_PIXELS (cursor_rect.y) + y;
5769 rect.width = PANGO_PIXELS (cursor_rect.width);
5770 rect.height = PANGO_PIXELS (cursor_rect.height);
5772 cr = gdk_cairo_create (entry->text_area);
5774 _gtk_widget_get_cursor_color (widget, &cursor_color);
5775 gdk_cairo_set_source_color (cr, &cursor_color);
5776 gdk_cairo_rectangle (cr, &rect);
5779 if (!block_at_line_end)
5781 gdk_cairo_rectangle (cr, &rect);
5783 cairo_move_to (cr, x, y);
5784 gdk_cairo_set_source_color (cr, &widget->style->base[widget->state]);
5785 pango_cairo_show_layout (cr, layout);
5794 gtk_entry_queue_draw (GtkEntry *entry)
5796 if (gtk_widget_is_drawable (GTK_WIDGET (entry)))
5797 gdk_window_invalidate_rect (entry->text_area, NULL, FALSE);
5801 _gtk_entry_reset_im_context (GtkEntry *entry)
5803 if (entry->need_im_reset)
5805 entry->need_im_reset = FALSE;
5806 gtk_im_context_reset (entry->im_context);
5811 gtk_entry_find_position (GtkEntry *entry,
5814 PangoLayout *layout;
5815 PangoLayoutLine *line;
5822 layout = gtk_entry_ensure_layout (entry, TRUE);
5823 text = pango_layout_get_text (layout);
5824 cursor_index = g_utf8_offset_to_pointer (text, entry->current_pos) - text;
5826 line = pango_layout_get_lines_readonly (layout)->data;
5827 pango_layout_line_x_to_index (line, x * PANGO_SCALE, &index, &trailing);
5829 if (index >= cursor_index && entry->preedit_length)
5831 if (index >= cursor_index + entry->preedit_length)
5832 index -= entry->preedit_length;
5835 index = cursor_index;
5840 pos = g_utf8_pointer_to_offset (text, text + index);
5847 gtk_entry_get_cursor_locations (GtkEntry *entry,
5852 DisplayMode mode = gtk_entry_get_display_mode (entry);
5854 /* Nothing to display at all, so no cursor is relevant */
5855 if (mode == DISPLAY_BLANK)
5865 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
5866 const gchar *text = pango_layout_get_text (layout);
5867 PangoRectangle strong_pos, weak_pos;
5870 if (type == CURSOR_STANDARD)
5872 index = g_utf8_offset_to_pointer (text, entry->current_pos + entry->preedit_cursor) - text;
5874 else /* type == CURSOR_DND */
5876 index = g_utf8_offset_to_pointer (text, entry->dnd_position) - text;
5878 if (entry->dnd_position > entry->current_pos)
5880 if (mode == DISPLAY_NORMAL)
5881 index += entry->preedit_length;
5884 gint preedit_len_chars = g_utf8_strlen (text, -1) - gtk_entry_buffer_get_length (get_buffer (entry));
5885 index += preedit_len_chars * g_unichar_to_utf8 (entry->invisible_char, NULL);
5890 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
5893 *strong_x = strong_pos.x / PANGO_SCALE;
5896 *weak_x = weak_pos.x / PANGO_SCALE;
5901 gtk_entry_adjust_scroll (GtkEntry *entry)
5903 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
5904 gint min_offset, max_offset;
5905 gint text_area_width, text_width;
5906 GtkBorder inner_border;
5907 gint strong_x, weak_x;
5908 gint strong_xoffset, weak_xoffset;
5910 PangoLayout *layout;
5911 PangoLayoutLine *line;
5912 PangoRectangle logical_rect;
5914 if (!gtk_widget_get_realized (GTK_WIDGET (entry)))
5917 _gtk_entry_effective_inner_border (entry, &inner_border);
5919 gdk_drawable_get_size (entry->text_area, &text_area_width, NULL);
5920 text_area_width -= inner_border.left + inner_border.right;
5921 if (text_area_width < 0)
5922 text_area_width = 0;
5924 layout = gtk_entry_ensure_layout (entry, TRUE);
5925 line = pango_layout_get_lines_readonly (layout)->data;
5927 pango_layout_line_get_extents (line, NULL, &logical_rect);
5929 /* Display as much text as we can */
5931 if (entry->resolved_dir == PANGO_DIRECTION_LTR)
5932 xalign = priv->xalign;
5934 xalign = 1.0 - priv->xalign;
5936 text_width = PANGO_PIXELS(logical_rect.width);
5938 if (text_width > text_area_width)
5941 max_offset = text_width - text_area_width;
5945 min_offset = (text_width - text_area_width) * xalign;
5946 max_offset = min_offset;
5949 entry->scroll_offset = CLAMP (entry->scroll_offset, min_offset, max_offset);
5951 /* And make sure cursors are on screen. Note that the cursor is
5952 * actually drawn one pixel into the INNER_BORDER space on
5953 * the right, when the scroll is at the utmost right. This
5954 * looks better to to me than confining the cursor inside the
5955 * border entirely, though it means that the cursor gets one
5956 * pixel closer to the edge of the widget on the right than
5957 * on the left. This might need changing if one changed
5958 * INNER_BORDER from 2 to 1, as one would do on a
5959 * small-screen-real-estate display.
5961 * We always make sure that the strong cursor is on screen, and
5962 * put the weak cursor on screen if possible.
5965 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, &weak_x);
5967 strong_xoffset = strong_x - entry->scroll_offset;
5969 if (strong_xoffset < 0)
5971 entry->scroll_offset += strong_xoffset;
5974 else if (strong_xoffset > text_area_width)
5976 entry->scroll_offset += strong_xoffset - text_area_width;
5977 strong_xoffset = text_area_width;
5980 weak_xoffset = weak_x - entry->scroll_offset;
5982 if (weak_xoffset < 0 && strong_xoffset - weak_xoffset <= text_area_width)
5984 entry->scroll_offset += weak_xoffset;
5986 else if (weak_xoffset > text_area_width &&
5987 strong_xoffset - (weak_xoffset - text_area_width) >= 0)
5989 entry->scroll_offset += weak_xoffset - text_area_width;
5992 g_object_notify (G_OBJECT (entry), "scroll-offset");
5996 gtk_entry_move_adjustments (GtkEntry *entry)
5998 PangoContext *context;
5999 PangoFontMetrics *metrics;
6000 gint x, layout_x, border_x, border_y;
6002 GtkAdjustment *adjustment;
6004 adjustment = g_object_get_qdata (G_OBJECT (entry), quark_cursor_hadjustment);
6008 /* Cursor position, layout offset, border width, and widget allocation */
6009 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &x, NULL);
6010 get_layout_position (entry, &layout_x, NULL);
6011 _gtk_entry_get_borders (entry, &border_x, &border_y);
6012 x += entry->widget.allocation.x + layout_x + border_x;
6014 /* Approximate width of a char, so user can see what is ahead/behind */
6015 context = gtk_widget_get_pango_context (GTK_WIDGET (entry));
6016 metrics = pango_context_get_metrics (context,
6017 entry->widget.style->font_desc,
6018 pango_context_get_language (context));
6019 char_width = pango_font_metrics_get_approximate_char_width (metrics) / PANGO_SCALE;
6022 gtk_adjustment_clamp_page (adjustment,
6023 x - (char_width + 1), /* one char + one pixel before */
6024 x + (char_width + 2)); /* one char + cursor + one pixel after */
6028 gtk_entry_move_visually (GtkEntry *entry,
6033 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6036 text = pango_layout_get_text (layout);
6038 index = g_utf8_offset_to_pointer (text, start) - text;
6042 int new_index, new_trailing;
6043 gboolean split_cursor;
6046 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
6047 "gtk-split-cursor", &split_cursor,
6054 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
6055 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
6057 strong = keymap_direction == entry->resolved_dir;
6062 pango_layout_move_cursor_visually (layout, strong, index, 0, 1, &new_index, &new_trailing);
6067 pango_layout_move_cursor_visually (layout, strong, index, 0, -1, &new_index, &new_trailing);
6073 else if (new_index != G_MAXINT)
6076 while (new_trailing--)
6077 index = g_utf8_next_char (text + index) - text;
6080 return g_utf8_pointer_to_offset (text, text + index);
6084 gtk_entry_move_logically (GtkEntry *entry,
6088 gint new_pos = start;
6091 length = gtk_entry_buffer_get_length (get_buffer (entry));
6093 /* Prevent any leak of information */
6094 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6096 new_pos = CLAMP (start + count, 0, length);
6100 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6101 PangoLogAttr *log_attrs;
6104 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6106 while (count > 0 && new_pos < length)
6110 while (new_pos < length && !log_attrs[new_pos].is_cursor_position);
6114 while (count < 0 && new_pos > 0)
6118 while (new_pos > 0 && !log_attrs[new_pos].is_cursor_position);
6130 gtk_entry_move_forward_word (GtkEntry *entry,
6132 gboolean allow_whitespace)
6134 gint new_pos = start;
6137 length = gtk_entry_buffer_get_length (get_buffer (entry));
6139 /* Prevent any leak of information */
6140 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6144 else if (new_pos < length)
6146 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6147 PangoLogAttr *log_attrs;
6150 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6152 /* Find the next word boundary */
6154 while (new_pos < n_attrs - 1 && !(log_attrs[new_pos].is_word_end ||
6155 (log_attrs[new_pos].is_word_start && allow_whitespace)))
6166 gtk_entry_move_backward_word (GtkEntry *entry,
6168 gboolean allow_whitespace)
6170 gint new_pos = start;
6172 /* Prevent any leak of information */
6173 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6179 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6180 PangoLogAttr *log_attrs;
6183 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6185 new_pos = start - 1;
6187 /* Find the previous word boundary */
6188 while (new_pos > 0 && !(log_attrs[new_pos].is_word_start ||
6189 (log_attrs[new_pos].is_word_end && allow_whitespace)))
6199 gtk_entry_delete_whitespace (GtkEntry *entry)
6201 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6202 PangoLogAttr *log_attrs;
6206 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6208 start = end = entry->current_pos;
6210 while (start > 0 && log_attrs[start-1].is_white)
6213 while (end < n_attrs && log_attrs[end].is_white)
6219 gtk_editable_delete_text (GTK_EDITABLE (entry), start, end);
6224 gtk_entry_select_word (GtkEntry *entry)
6226 gint start_pos = gtk_entry_move_backward_word (entry, entry->current_pos, TRUE);
6227 gint end_pos = gtk_entry_move_forward_word (entry, entry->current_pos, TRUE);
6229 gtk_editable_select_region (GTK_EDITABLE (entry), start_pos, end_pos);
6233 gtk_entry_select_line (GtkEntry *entry)
6235 gtk_editable_select_region (GTK_EDITABLE (entry), 0, -1);
6239 truncate_multiline (const gchar *text)
6244 text[length] && text[length] != '\n' && text[length] != '\r';
6251 paste_received (GtkClipboard *clipboard,
6255 GtkEntry *entry = GTK_ENTRY (data);
6256 GtkEditable *editable = GTK_EDITABLE (entry);
6257 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
6259 if (entry->button == 2)
6261 gint pos, start, end;
6262 pos = priv->insert_pos;
6263 gtk_editable_get_selection_bounds (editable, &start, &end);
6264 if (!((start <= pos && pos <= end) || (end <= pos && pos <= start)))
6265 gtk_editable_select_region (editable, pos, pos);
6270 gint pos, start, end;
6272 gboolean popup_completion;
6273 GtkEntryCompletion *completion;
6275 completion = gtk_entry_get_completion (entry);
6277 if (entry->truncate_multiline)
6278 length = truncate_multiline (text);
6280 /* only complete if the selection is at the end */
6281 popup_completion = (gtk_entry_buffer_get_length (get_buffer (entry)) ==
6282 MAX (entry->current_pos, entry->selection_bound));
6286 if (gtk_widget_get_mapped (completion->priv->popup_window))
6287 _gtk_entry_completion_popdown (completion);
6289 if (!popup_completion && completion->priv->changed_id > 0)
6290 g_signal_handler_block (entry, completion->priv->changed_id);
6293 begin_change (entry);
6294 g_object_freeze_notify (G_OBJECT (entry));
6295 if (gtk_editable_get_selection_bounds (editable, &start, &end))
6296 gtk_editable_delete_text (editable, start, end);
6298 pos = entry->current_pos;
6299 gtk_editable_insert_text (editable, text, length, &pos);
6300 gtk_editable_set_position (editable, pos);
6301 g_object_thaw_notify (G_OBJECT (entry));
6305 !popup_completion && completion->priv->changed_id > 0)
6306 g_signal_handler_unblock (entry, completion->priv->changed_id);
6309 g_object_unref (entry);
6313 gtk_entry_paste (GtkEntry *entry,
6316 g_object_ref (entry);
6317 gtk_clipboard_request_text (gtk_widget_get_clipboard (GTK_WIDGET (entry), selection),
6318 paste_received, entry);
6322 primary_get_cb (GtkClipboard *clipboard,
6323 GtkSelectionData *selection_data,
6327 GtkEntry *entry = GTK_ENTRY (data);
6330 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end))
6332 gchar *str = gtk_entry_get_display_text (entry, start, end);
6333 gtk_selection_data_set_text (selection_data, str, -1);
6339 primary_clear_cb (GtkClipboard *clipboard,
6342 GtkEntry *entry = GTK_ENTRY (data);
6344 gtk_editable_select_region (GTK_EDITABLE (entry), entry->current_pos, entry->current_pos);
6348 gtk_entry_update_primary_selection (GtkEntry *entry)
6350 GtkTargetList *list;
6351 GtkTargetEntry *targets;
6352 GtkClipboard *clipboard;
6356 if (!gtk_widget_get_realized (GTK_WIDGET (entry)))
6359 list = gtk_target_list_new (NULL, 0);
6360 gtk_target_list_add_text_targets (list, 0);
6362 targets = gtk_target_table_new_from_list (list, &n_targets);
6364 clipboard = gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_PRIMARY);
6366 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end))
6368 if (!gtk_clipboard_set_with_owner (clipboard, targets, n_targets,
6369 primary_get_cb, primary_clear_cb, G_OBJECT (entry)))
6370 primary_clear_cb (clipboard, entry);
6374 if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (entry))
6375 gtk_clipboard_clear (clipboard);
6378 gtk_target_table_free (targets, n_targets);
6379 gtk_target_list_unref (list);
6383 gtk_entry_clear (GtkEntry *entry,
6384 GtkEntryIconPosition icon_pos)
6386 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
6387 EntryIconInfo *icon_info = priv->icons[icon_pos];
6389 if (!icon_info || icon_info->storage_type == GTK_IMAGE_EMPTY)
6392 g_object_freeze_notify (G_OBJECT (entry));
6394 /* Explicitly check, as the pointer may become invalidated
6395 * during destruction.
6397 if (GDK_IS_WINDOW (icon_info->window))
6398 gdk_window_hide (icon_info->window);
6400 if (icon_info->pixbuf)
6402 g_object_unref (icon_info->pixbuf);
6403 icon_info->pixbuf = NULL;
6406 switch (icon_info->storage_type)
6408 case GTK_IMAGE_PIXBUF:
6409 g_object_notify (G_OBJECT (entry),
6410 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-pixbuf" : "secondary-icon-pixbuf");
6413 case GTK_IMAGE_STOCK:
6414 g_free (icon_info->stock_id);
6415 icon_info->stock_id = NULL;
6416 g_object_notify (G_OBJECT (entry),
6417 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-stock" : "secondary-icon-stock");
6420 case GTK_IMAGE_ICON_NAME:
6421 g_free (icon_info->icon_name);
6422 icon_info->icon_name = NULL;
6423 g_object_notify (G_OBJECT (entry),
6424 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-name" : "secondary-icon-name");
6427 case GTK_IMAGE_GICON:
6428 if (icon_info->gicon)
6430 g_object_unref (icon_info->gicon);
6431 icon_info->gicon = NULL;
6433 g_object_notify (G_OBJECT (entry),
6434 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-gicon" : "secondary-icon-gicon");
6438 g_assert_not_reached ();
6442 icon_info->storage_type = GTK_IMAGE_EMPTY;
6443 g_object_notify (G_OBJECT (entry),
6444 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-storage-type" : "secondary-icon-storage-type");
6446 g_object_thaw_notify (G_OBJECT (entry));
6450 gtk_entry_ensure_pixbuf (GtkEntry *entry,
6451 GtkEntryIconPosition icon_pos)
6453 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
6454 EntryIconInfo *icon_info = priv->icons[icon_pos];
6456 GtkIconTheme *icon_theme;
6457 GtkSettings *settings;
6463 if (!icon_info || icon_info->pixbuf)
6466 widget = GTK_WIDGET (entry);
6468 switch (icon_info->storage_type)
6470 case GTK_IMAGE_EMPTY:
6471 case GTK_IMAGE_PIXBUF:
6473 case GTK_IMAGE_STOCK:
6474 state = gtk_widget_get_state (widget);
6475 gtk_widget_set_state (widget, GTK_STATE_NORMAL);
6476 icon_info->pixbuf = gtk_widget_render_icon (widget,
6477 icon_info->stock_id,
6480 if (!icon_info->pixbuf)
6481 icon_info->pixbuf = gtk_widget_render_icon (widget,
6482 GTK_STOCK_MISSING_IMAGE,
6485 gtk_widget_set_state (widget, state);
6488 case GTK_IMAGE_ICON_NAME:
6489 screen = gtk_widget_get_screen (widget);
6492 icon_theme = gtk_icon_theme_get_for_screen (screen);
6493 settings = gtk_settings_get_for_screen (screen);
6495 gtk_icon_size_lookup_for_settings (settings,
6499 icon_info->pixbuf = gtk_icon_theme_load_icon (icon_theme,
6500 icon_info->icon_name,
6501 MIN (width, height),
6504 if (icon_info->pixbuf == NULL)
6506 state = gtk_widget_get_state (widget);
6507 gtk_widget_set_state (widget, GTK_STATE_NORMAL);
6508 icon_info->pixbuf = gtk_widget_render_icon (widget,
6509 GTK_STOCK_MISSING_IMAGE,
6512 gtk_widget_set_state (widget, state);
6517 case GTK_IMAGE_GICON:
6518 screen = gtk_widget_get_screen (widget);
6521 icon_theme = gtk_icon_theme_get_for_screen (screen);
6522 settings = gtk_settings_get_for_screen (screen);
6524 gtk_icon_size_lookup_for_settings (settings,
6528 info = gtk_icon_theme_lookup_by_gicon (icon_theme,
6530 MIN (width, height),
6531 GTK_ICON_LOOKUP_USE_BUILTIN);
6534 icon_info->pixbuf = gtk_icon_info_load_icon (info, NULL);
6535 gtk_icon_info_free (info);
6538 if (icon_info->pixbuf == NULL)
6540 state = gtk_widget_get_state (widget);
6541 gtk_widget_set_state (widget, GTK_STATE_NORMAL);
6542 icon_info->pixbuf = gtk_widget_render_icon (widget,
6543 GTK_STOCK_MISSING_IMAGE,
6546 gtk_widget_set_state (widget, state);
6552 g_assert_not_reached ();
6556 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
6557 gdk_window_show_unraised (icon_info->window);
6567 * Creates a new entry.
6569 * Return value: a new #GtkEntry.
6572 gtk_entry_new (void)
6574 return g_object_new (GTK_TYPE_ENTRY, NULL);
6578 * gtk_entry_new_with_buffer:
6579 * @buffer: The buffer to use for the new #GtkEntry.
6581 * Creates a new entry with the specified text buffer.
6583 * Return value: a new #GtkEntry
6588 gtk_entry_new_with_buffer (GtkEntryBuffer *buffer)
6590 g_return_val_if_fail (GTK_IS_ENTRY_BUFFER (buffer), NULL);
6591 return g_object_new (GTK_TYPE_ENTRY, "buffer", buffer, NULL);
6595 * gtk_entry_new_with_max_length:
6596 * @max: the maximum length of the entry, or 0 for no maximum.
6597 * (other than the maximum length of entries.) The value passed in will
6598 * be clamped to the range 0-65536.
6600 * Creates a new #GtkEntry widget with the given maximum length.
6602 * Return value: a new #GtkEntry
6604 * Deprecated: 2.0: Use gtk_entry_set_max_length() instead.
6607 gtk_entry_new_with_max_length (gint max)
6611 max = CLAMP (max, 0, GTK_ENTRY_BUFFER_MAX_SIZE);
6613 entry = g_object_new (GTK_TYPE_ENTRY, NULL);
6614 gtk_entry_buffer_set_max_length (get_buffer (entry), max);
6616 return GTK_WIDGET (entry);
6620 static GtkEntryBuffer*
6621 get_buffer (GtkEntry *entry)
6623 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
6625 if (priv->buffer == NULL)
6627 GtkEntryBuffer *buffer;
6628 buffer = gtk_entry_buffer_new (NULL, 0);
6629 gtk_entry_set_buffer (entry, buffer);
6630 g_object_unref (buffer);
6633 return priv->buffer;
6637 * gtk_entry_get_buffer:
6638 * @entry: a #GtkEntry
6640 * Get the #GtkEntryBuffer object which holds the text for
6645 * Returns: A #GtkEntryBuffer object.
6648 gtk_entry_get_buffer (GtkEntry *entry)
6650 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
6652 return get_buffer (entry);
6656 * gtk_entry_set_buffer:
6657 * @entry: a #GtkEntry
6658 * @buffer: a #GtkEntryBuffer
6660 * Set the #GtkEntryBuffer object which holds the text for
6666 gtk_entry_set_buffer (GtkEntry *entry,
6667 GtkEntryBuffer *buffer)
6669 GtkEntryPrivate *priv;
6672 g_return_if_fail (GTK_IS_ENTRY (entry));
6673 priv = GTK_ENTRY_GET_PRIVATE (entry);
6677 g_return_if_fail (GTK_IS_ENTRY_BUFFER (buffer));
6678 g_object_ref (buffer);
6683 buffer_disconnect_signals (entry);
6684 g_object_unref (priv->buffer);
6686 /* COMPAT: Deprecated. Not used. Setting these fields no longer necessary in GTK 3.x */
6688 entry->text_length = 0;
6689 entry->text_max_length = 0;
6692 priv->buffer = buffer;
6696 buffer_connect_signals (entry);
6698 /* COMPAT: Deprecated. Not used. Setting these fields no longer necessary in GTK 3.x */
6699 entry->text = (char*)gtk_entry_buffer_get_text (priv->buffer);
6700 entry->text_length = gtk_entry_buffer_get_length (priv->buffer);
6701 entry->text_max_length = gtk_entry_buffer_get_max_length (priv->buffer);
6704 obj = G_OBJECT (entry);
6705 g_object_freeze_notify (obj);
6706 g_object_notify (obj, "buffer");
6707 g_object_notify (obj, "text");
6708 g_object_notify (obj, "text-length");
6709 g_object_notify (obj, "max-length");
6710 g_object_notify (obj, "visibility");
6711 g_object_notify (obj, "invisible-char");
6712 g_object_notify (obj, "invisible-char-set");
6713 g_object_thaw_notify (obj);
6715 gtk_editable_set_position (GTK_EDITABLE (entry), 0);
6716 gtk_entry_recompute (entry);
6720 * gtk_entry_get_text_window:
6721 * @entry: a #GtkEntry
6723 * Returns the #GdkWindow which contains the text. This function is
6724 * useful when drawing something to the entry in an expose-event
6725 * callback because it enables the callback to distinguish between
6726 * the text window and entry's icon windows.
6728 * See also gtk_entry_get_icon_window().
6730 * Return value: the entry's text window.
6735 gtk_entry_get_text_window (GtkEntry *entry)
6737 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
6739 return entry->text_area;
6744 * gtk_entry_set_text:
6745 * @entry: a #GtkEntry
6746 * @text: the new text
6748 * Sets the text in the widget to the given
6749 * value, replacing the current contents.
6751 * See gtk_entry_buffer_set_text().
6754 gtk_entry_set_text (GtkEntry *entry,
6758 GtkEntryCompletion *completion;
6759 GtkEntryPrivate *priv;
6761 g_return_if_fail (GTK_IS_ENTRY (entry));
6762 g_return_if_fail (text != NULL);
6763 priv = GTK_ENTRY_GET_PRIVATE (entry);
6765 /* Actually setting the text will affect the cursor and selection;
6766 * if the contents don't actually change, this will look odd to the user.
6768 if (strcmp (gtk_entry_buffer_get_text (get_buffer (entry)), text) == 0)
6771 completion = gtk_entry_get_completion (entry);
6772 if (completion && completion->priv->changed_id > 0)
6773 g_signal_handler_block (entry, completion->priv->changed_id);
6775 begin_change (entry);
6776 g_object_freeze_notify (G_OBJECT (entry));
6777 gtk_editable_delete_text (GTK_EDITABLE (entry), 0, -1);
6779 gtk_editable_insert_text (GTK_EDITABLE (entry), text, strlen (text), &tmp_pos);
6780 g_object_thaw_notify (G_OBJECT (entry));
6783 if (completion && completion->priv->changed_id > 0)
6784 g_signal_handler_unblock (entry, completion->priv->changed_id);
6788 * gtk_entry_append_text:
6789 * @entry: a #GtkEntry
6790 * @text: the text to append
6792 * Appends the given text to the contents of the widget.
6794 * Deprecated: 2.0: Use gtk_editable_insert_text() instead.
6797 gtk_entry_append_text (GtkEntry *entry,
6800 GtkEntryPrivate *priv;
6803 g_return_if_fail (GTK_IS_ENTRY (entry));
6804 g_return_if_fail (text != NULL);
6805 priv = GTK_ENTRY_GET_PRIVATE (entry);
6807 tmp_pos = gtk_entry_buffer_get_length (get_buffer (entry));
6808 gtk_editable_insert_text (GTK_EDITABLE (entry), text, -1, &tmp_pos);
6812 * gtk_entry_prepend_text:
6813 * @entry: a #GtkEntry
6814 * @text: the text to prepend
6816 * Prepends the given text to the contents of the widget.
6818 * Deprecated: 2.0: Use gtk_editable_insert_text() instead.
6821 gtk_entry_prepend_text (GtkEntry *entry,
6826 g_return_if_fail (GTK_IS_ENTRY (entry));
6827 g_return_if_fail (text != NULL);
6830 gtk_editable_insert_text (GTK_EDITABLE (entry), text, -1, &tmp_pos);
6834 * gtk_entry_set_position:
6835 * @entry: a #GtkEntry
6836 * @position: the position of the cursor. The cursor is displayed
6837 * before the character with the given (base 0) index in the widget.
6838 * The value must be less than or equal to the number of characters
6839 * in the widget. A value of -1 indicates that the position should
6840 * be set after the last character in the entry. Note that this
6841 * position is in characters, not in bytes.
6843 * Sets the cursor position in an entry to the given value.
6845 * Deprecated: 2.0: Use gtk_editable_set_position() instead.
6848 gtk_entry_set_position (GtkEntry *entry,
6851 g_return_if_fail (GTK_IS_ENTRY (entry));
6853 gtk_editable_set_position (GTK_EDITABLE (entry), position);
6857 * gtk_entry_set_visibility:
6858 * @entry: a #GtkEntry
6859 * @visible: %TRUE if the contents of the entry are displayed
6862 * Sets whether the contents of the entry are visible or not.
6863 * When visibility is set to %FALSE, characters are displayed
6864 * as the invisible char, and will also appear that way when
6865 * the text in the entry widget is copied elsewhere.
6867 * By default, GTK+ picks the best invisible character available
6868 * in the current font, but it can be changed with
6869 * gtk_entry_set_invisible_char().
6872 gtk_entry_set_visibility (GtkEntry *entry,
6875 g_return_if_fail (GTK_IS_ENTRY (entry));
6877 visible = visible != FALSE;
6879 if (entry->visible != visible)
6881 entry->visible = visible;
6883 g_object_notify (G_OBJECT (entry), "visibility");
6884 gtk_entry_recompute (entry);
6889 * gtk_entry_get_visibility:
6890 * @entry: a #GtkEntry
6892 * Retrieves whether the text in @entry is visible. See
6893 * gtk_entry_set_visibility().
6895 * Return value: %TRUE if the text is currently visible
6898 gtk_entry_get_visibility (GtkEntry *entry)
6900 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
6902 return entry->visible;
6906 * gtk_entry_set_invisible_char:
6907 * @entry: a #GtkEntry
6908 * @ch: a Unicode character
6910 * Sets the character to use in place of the actual text when
6911 * gtk_entry_set_visibility() has been called to set text visibility
6912 * to %FALSE. i.e. this is the character used in "password mode" to
6913 * show the user how many characters have been typed. By default, GTK+
6914 * picks the best invisible char available in the current font. If you
6915 * set the invisible char to 0, then the user will get no feedback
6916 * at all; there will be no text on the screen as they type.
6919 gtk_entry_set_invisible_char (GtkEntry *entry,
6922 GtkEntryPrivate *priv;
6924 g_return_if_fail (GTK_IS_ENTRY (entry));
6926 priv = GTK_ENTRY_GET_PRIVATE (entry);
6928 if (!priv->invisible_char_set)
6930 priv->invisible_char_set = TRUE;
6931 g_object_notify (G_OBJECT (entry), "invisible-char-set");
6934 if (ch == entry->invisible_char)
6937 entry->invisible_char = ch;
6938 g_object_notify (G_OBJECT (entry), "invisible-char");
6939 gtk_entry_recompute (entry);
6943 * gtk_entry_get_invisible_char:
6944 * @entry: a #GtkEntry
6946 * Retrieves the character displayed in place of the real characters
6947 * for entries with visibility set to false. See gtk_entry_set_invisible_char().
6949 * Return value: the current invisible char, or 0, if the entry does not
6950 * show invisible text at all.
6953 gtk_entry_get_invisible_char (GtkEntry *entry)
6955 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
6957 return entry->invisible_char;
6961 * gtk_entry_unset_invisible_char:
6962 * @entry: a #GtkEntry
6964 * Unsets the invisible char previously set with
6965 * gtk_entry_set_invisible_char(). So that the
6966 * default invisible char is used again.
6971 gtk_entry_unset_invisible_char (GtkEntry *entry)
6973 GtkEntryPrivate *priv;
6976 g_return_if_fail (GTK_IS_ENTRY (entry));
6978 priv = GTK_ENTRY_GET_PRIVATE (entry);
6980 if (!priv->invisible_char_set)
6983 priv->invisible_char_set = FALSE;
6984 ch = find_invisible_char (GTK_WIDGET (entry));
6986 if (entry->invisible_char != ch)
6988 entry->invisible_char = ch;
6989 g_object_notify (G_OBJECT (entry), "invisible-char");
6992 g_object_notify (G_OBJECT (entry), "invisible-char-set");
6993 gtk_entry_recompute (entry);
6997 * gtk_entry_set_editable:
6998 * @entry: a #GtkEntry
6999 * @editable: %TRUE if the user is allowed to edit the text
7002 * Determines if the user can edit the text in the editable
7005 * Deprecated: 2.0: Use gtk_editable_set_editable() instead.
7008 gtk_entry_set_editable (GtkEntry *entry,
7011 g_return_if_fail (GTK_IS_ENTRY (entry));
7013 gtk_editable_set_editable (GTK_EDITABLE (entry), editable);
7017 * gtk_entry_set_overwrite_mode:
7018 * @entry: a #GtkEntry
7019 * @overwrite: new value
7021 * Sets whether the text is overwritten when typing in the #GtkEntry.
7026 gtk_entry_set_overwrite_mode (GtkEntry *entry,
7029 g_return_if_fail (GTK_IS_ENTRY (entry));
7031 if (entry->overwrite_mode == overwrite)
7034 gtk_entry_toggle_overwrite (entry);
7036 g_object_notify (G_OBJECT (entry), "overwrite-mode");
7040 * gtk_entry_get_overwrite_mode:
7041 * @entry: a #GtkEntry
7043 * Gets the value set by gtk_entry_set_overwrite_mode().
7045 * Return value: whether the text is overwritten when typing.
7050 gtk_entry_get_overwrite_mode (GtkEntry *entry)
7052 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7054 return entry->overwrite_mode;
7058 * gtk_entry_get_text:
7059 * @entry: a #GtkEntry
7061 * Retrieves the contents of the entry widget.
7062 * See also gtk_editable_get_chars().
7064 * This is equivalent to:
7066 * <informalexample><programlisting>
7067 * gtk_entry_buffer_get_text (gtk_entry_get_buffer (entry));
7068 * </programlisting></informalexample>
7070 * Return value: a pointer to the contents of the widget as a
7071 * string. This string points to internally allocated
7072 * storage in the widget and must not be freed, modified or
7075 G_CONST_RETURN gchar*
7076 gtk_entry_get_text (GtkEntry *entry)
7078 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7079 return gtk_entry_buffer_get_text (get_buffer (entry));
7083 * gtk_entry_select_region:
7084 * @entry: a #GtkEntry
7085 * @start: the starting position
7086 * @end: the end position
7088 * Selects a region of text. The characters that are selected are
7089 * those characters at positions from @start_pos up to, but not
7090 * including @end_pos. If @end_pos is negative, then the the characters
7091 * selected will be those characters from @start_pos to the end of
7094 * Deprecated: 2.0: Use gtk_editable_select_region() instead.
7097 gtk_entry_select_region (GtkEntry *entry,
7101 gtk_editable_select_region (GTK_EDITABLE (entry), start, end);
7105 * gtk_entry_set_max_length:
7106 * @entry: a #GtkEntry
7107 * @max: the maximum length of the entry, or 0 for no maximum.
7108 * (other than the maximum length of entries.) The value passed in will
7109 * be clamped to the range 0-65536.
7111 * Sets the maximum allowed length of the contents of the widget. If
7112 * the current contents are longer than the given length, then they
7113 * will be truncated to fit.
7115 * This is equivalent to:
7117 * <informalexample><programlisting>
7118 * gtk_entry_buffer_set_max_length (gtk_entry_get_buffer (entry), max);
7119 * </programlisting></informalexample>
7122 gtk_entry_set_max_length (GtkEntry *entry,
7125 g_return_if_fail (GTK_IS_ENTRY (entry));
7126 gtk_entry_buffer_set_max_length (get_buffer (entry), max);
7130 * gtk_entry_get_max_length:
7131 * @entry: a #GtkEntry
7133 * Retrieves the maximum allowed length of the text in
7134 * @entry. See gtk_entry_set_max_length().
7136 * This is equivalent to:
7138 * <informalexample><programlisting>
7139 * gtk_entry_buffer_get_max_length (gtk_entry_get_buffer (entry));
7140 * </programlisting></informalexample>
7142 * Return value: the maximum allowed number of characters
7143 * in #GtkEntry, or 0 if there is no maximum.
7146 gtk_entry_get_max_length (GtkEntry *entry)
7148 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7149 return gtk_entry_buffer_get_max_length (get_buffer (entry));
7153 * gtk_entry_get_text_length:
7154 * @entry: a #GtkEntry
7156 * Retrieves the current length of the text in
7159 * This is equivalent to:
7161 * <informalexample><programlisting>
7162 * gtk_entry_buffer_get_length (gtk_entry_get_buffer (entry));
7163 * </programlisting></informalexample>
7165 * Return value: the current number of characters
7166 * in #GtkEntry, or 0 if there are none.
7171 gtk_entry_get_text_length (GtkEntry *entry)
7173 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7174 return gtk_entry_buffer_get_length (get_buffer (entry));
7178 * gtk_entry_set_activates_default:
7179 * @entry: a #GtkEntry
7180 * @setting: %TRUE to activate window's default widget on Enter keypress
7182 * If @setting is %TRUE, pressing Enter in the @entry will activate the default
7183 * widget for the window containing the entry. This usually means that
7184 * the dialog box containing the entry will be closed, since the default
7185 * widget is usually one of the dialog buttons.
7187 * (For experts: if @setting is %TRUE, the entry calls
7188 * gtk_window_activate_default() on the window containing the entry, in
7189 * the default handler for the #GtkWidget::activate signal.)
7192 gtk_entry_set_activates_default (GtkEntry *entry,
7195 g_return_if_fail (GTK_IS_ENTRY (entry));
7196 setting = setting != FALSE;
7198 if (setting != entry->activates_default)
7200 entry->activates_default = setting;
7201 g_object_notify (G_OBJECT (entry), "activates-default");
7206 * gtk_entry_get_activates_default:
7207 * @entry: a #GtkEntry
7209 * Retrieves the value set by gtk_entry_set_activates_default().
7211 * Return value: %TRUE if the entry will activate the default widget
7214 gtk_entry_get_activates_default (GtkEntry *entry)
7216 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7218 return entry->activates_default;
7222 * gtk_entry_set_width_chars:
7223 * @entry: a #GtkEntry
7224 * @n_chars: width in chars
7226 * Changes the size request of the entry to be about the right size
7227 * for @n_chars characters. Note that it changes the size
7228 * <emphasis>request</emphasis>, the size can still be affected by
7229 * how you pack the widget into containers. If @n_chars is -1, the
7230 * size reverts to the default entry size.
7233 gtk_entry_set_width_chars (GtkEntry *entry,
7236 g_return_if_fail (GTK_IS_ENTRY (entry));
7238 if (entry->width_chars != n_chars)
7240 entry->width_chars = n_chars;
7241 g_object_notify (G_OBJECT (entry), "width-chars");
7242 gtk_widget_queue_resize (GTK_WIDGET (entry));
7247 * gtk_entry_get_width_chars:
7248 * @entry: a #GtkEntry
7250 * Gets the value set by gtk_entry_set_width_chars().
7252 * Return value: number of chars to request space for, or negative if unset
7255 gtk_entry_get_width_chars (GtkEntry *entry)
7257 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7259 return entry->width_chars;
7263 * gtk_entry_set_has_frame:
7264 * @entry: a #GtkEntry
7265 * @setting: new value
7267 * Sets whether the entry has a beveled frame around it.
7270 gtk_entry_set_has_frame (GtkEntry *entry,
7273 g_return_if_fail (GTK_IS_ENTRY (entry));
7275 setting = (setting != FALSE);
7277 if (entry->has_frame == setting)
7280 gtk_widget_queue_resize (GTK_WIDGET (entry));
7281 entry->has_frame = setting;
7282 g_object_notify (G_OBJECT (entry), "has-frame");
7286 * gtk_entry_get_has_frame:
7287 * @entry: a #GtkEntry
7289 * Gets the value set by gtk_entry_set_has_frame().
7291 * Return value: whether the entry has a beveled frame
7294 gtk_entry_get_has_frame (GtkEntry *entry)
7296 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7298 return entry->has_frame;
7302 * gtk_entry_set_inner_border:
7303 * @entry: a #GtkEntry
7304 * @border: (allow-none): a #GtkBorder, or %NULL
7306 * Sets %entry's inner-border property to %border, or clears it if %NULL
7307 * is passed. The inner-border is the area around the entry's text, but
7310 * If set, this property overrides the inner-border style property.
7311 * Overriding the style-provided border is useful when you want to do
7312 * in-place editing of some text in a canvas or list widget, where
7313 * pixel-exact positioning of the entry is important.
7318 gtk_entry_set_inner_border (GtkEntry *entry,
7319 const GtkBorder *border)
7321 g_return_if_fail (GTK_IS_ENTRY (entry));
7323 gtk_widget_queue_resize (GTK_WIDGET (entry));
7326 g_object_set_qdata_full (G_OBJECT (entry), quark_inner_border,
7327 gtk_border_copy (border),
7328 (GDestroyNotify) gtk_border_free);
7330 g_object_set_qdata (G_OBJECT (entry), quark_inner_border, NULL);
7332 g_object_notify (G_OBJECT (entry), "inner-border");
7336 * gtk_entry_get_inner_border:
7337 * @entry: a #GtkEntry
7339 * This function returns the entry's #GtkEntry:inner-border property. See
7340 * gtk_entry_set_inner_border() for more information.
7342 * Return value: (transfer none): the entry's #GtkBorder, or %NULL if none was set.
7346 G_CONST_RETURN GtkBorder *
7347 gtk_entry_get_inner_border (GtkEntry *entry)
7349 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7351 return g_object_get_qdata (G_OBJECT (entry), quark_inner_border);
7355 * gtk_entry_get_layout:
7356 * @entry: a #GtkEntry
7358 * Gets the #PangoLayout used to display the entry.
7359 * The layout is useful to e.g. convert text positions to
7360 * pixel positions, in combination with gtk_entry_get_layout_offsets().
7361 * The returned layout is owned by the entry and must not be
7362 * modified or freed by the caller.
7364 * Keep in mind that the layout text may contain a preedit string, so
7365 * gtk_entry_layout_index_to_text_index() and
7366 * gtk_entry_text_index_to_layout_index() are needed to convert byte
7367 * indices in the layout to byte indices in the entry contents.
7369 * Return value: (transfer none): the #PangoLayout for this entry
7372 gtk_entry_get_layout (GtkEntry *entry)
7374 PangoLayout *layout;
7376 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7378 layout = gtk_entry_ensure_layout (entry, TRUE);
7385 * gtk_entry_layout_index_to_text_index:
7386 * @entry: a #GtkEntry
7387 * @layout_index: byte index into the entry layout text
7389 * Converts from a position in the entry contents (returned
7390 * by gtk_entry_get_text()) to a position in the
7391 * entry's #PangoLayout (returned by gtk_entry_get_layout(),
7392 * with text retrieved via pango_layout_get_text()).
7394 * Return value: byte index into the entry contents
7397 gtk_entry_layout_index_to_text_index (GtkEntry *entry,
7400 PangoLayout *layout;
7404 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7406 layout = gtk_entry_ensure_layout (entry, TRUE);
7407 text = pango_layout_get_text (layout);
7408 cursor_index = g_utf8_offset_to_pointer (text, entry->current_pos) - text;
7410 if (layout_index >= cursor_index && entry->preedit_length)
7412 if (layout_index >= cursor_index + entry->preedit_length)
7413 layout_index -= entry->preedit_length;
7415 layout_index = cursor_index;
7418 return layout_index;
7422 * gtk_entry_text_index_to_layout_index:
7423 * @entry: a #GtkEntry
7424 * @text_index: byte index into the entry contents
7426 * Converts from a position in the entry's #PangoLayout (returned by
7427 * gtk_entry_get_layout()) to a position in the entry contents
7428 * (returned by gtk_entry_get_text()).
7430 * Return value: byte index into the entry layout text
7433 gtk_entry_text_index_to_layout_index (GtkEntry *entry,
7436 PangoLayout *layout;
7439 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7441 layout = gtk_entry_ensure_layout (entry, TRUE);
7442 text = pango_layout_get_text (layout);
7443 cursor_index = g_utf8_offset_to_pointer (text, entry->current_pos) - text;
7445 if (text_index > cursor_index)
7446 text_index += entry->preedit_length;
7452 * gtk_entry_get_layout_offsets:
7453 * @entry: a #GtkEntry
7454 * @x: (allow-none): location to store X offset of layout, or %NULL
7455 * @y: (allow-none): location to store Y offset of layout, or %NULL
7458 * Obtains the position of the #PangoLayout used to render text
7459 * in the entry, in widget coordinates. Useful if you want to line
7460 * up the text in an entry with some other text, e.g. when using the
7461 * entry to implement editable cells in a sheet widget.
7463 * Also useful to convert mouse events into coordinates inside the
7464 * #PangoLayout, e.g. to take some action if some part of the entry text
7467 * Note that as the user scrolls around in the entry the offsets will
7468 * change; you'll need to connect to the "notify::scroll-offset"
7469 * signal to track this. Remember when using the #PangoLayout
7470 * functions you need to convert to and from pixels using
7471 * PANGO_PIXELS() or #PANGO_SCALE.
7473 * Keep in mind that the layout text may contain a preedit string, so
7474 * gtk_entry_layout_index_to_text_index() and
7475 * gtk_entry_text_index_to_layout_index() are needed to convert byte
7476 * indices in the layout to byte indices in the entry contents.
7479 gtk_entry_get_layout_offsets (GtkEntry *entry,
7483 gint text_area_x, text_area_y;
7485 g_return_if_fail (GTK_IS_ENTRY (entry));
7487 /* this gets coords relative to text area */
7488 get_layout_position (entry, x, y);
7490 /* convert to widget coords */
7491 gtk_entry_get_text_area_size (entry, &text_area_x, &text_area_y, NULL, NULL);
7502 * gtk_entry_set_alignment:
7503 * @entry: a #GtkEntry
7504 * @xalign: The horizontal alignment, from 0 (left) to 1 (right).
7505 * Reversed for RTL layouts
7507 * Sets the alignment for the contents of the entry. This controls
7508 * the horizontal positioning of the contents when the displayed
7509 * text is shorter than the width of the entry.
7514 gtk_entry_set_alignment (GtkEntry *entry, gfloat xalign)
7516 GtkEntryPrivate *priv;
7518 g_return_if_fail (GTK_IS_ENTRY (entry));
7520 priv = GTK_ENTRY_GET_PRIVATE (entry);
7524 else if (xalign > 1.0)
7527 if (xalign != priv->xalign)
7529 priv->xalign = xalign;
7531 gtk_entry_recompute (entry);
7533 g_object_notify (G_OBJECT (entry), "xalign");
7538 * gtk_entry_get_alignment:
7539 * @entry: a #GtkEntry
7541 * Gets the value set by gtk_entry_set_alignment().
7543 * Return value: the alignment
7548 gtk_entry_get_alignment (GtkEntry *entry)
7550 GtkEntryPrivate *priv;
7552 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
7554 priv = GTK_ENTRY_GET_PRIVATE (entry);
7556 return priv->xalign;
7560 * gtk_entry_set_icon_from_pixbuf:
7561 * @entry: a #GtkEntry
7562 * @icon_pos: Icon position
7563 * @pixbuf: (allow-none): A #GdkPixbuf, or %NULL
7565 * Sets the icon shown in the specified position using a pixbuf.
7567 * If @pixbuf is %NULL, no icon will be shown in the specified position.
7572 gtk_entry_set_icon_from_pixbuf (GtkEntry *entry,
7573 GtkEntryIconPosition icon_pos,
7576 GtkEntryPrivate *priv;
7577 EntryIconInfo *icon_info;
7579 g_return_if_fail (GTK_IS_ENTRY (entry));
7580 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7582 priv = GTK_ENTRY_GET_PRIVATE (entry);
7584 if ((icon_info = priv->icons[icon_pos]) == NULL)
7585 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7587 g_object_freeze_notify (G_OBJECT (entry));
7590 g_object_ref (pixbuf);
7592 gtk_entry_clear (entry, icon_pos);
7596 icon_info->storage_type = GTK_IMAGE_PIXBUF;
7597 icon_info->pixbuf = pixbuf;
7599 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7601 g_object_notify (G_OBJECT (entry), "primary-icon-pixbuf");
7602 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7606 g_object_notify (G_OBJECT (entry), "secondary-icon-pixbuf");
7607 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7610 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7611 gdk_window_show_unraised (icon_info->window);
7614 gtk_entry_ensure_pixbuf (entry, icon_pos);
7616 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7617 gtk_widget_queue_resize (GTK_WIDGET (entry));
7619 g_object_thaw_notify (G_OBJECT (entry));
7623 * gtk_entry_set_icon_from_stock:
7624 * @entry: A #GtkEntry
7625 * @icon_pos: Icon position
7626 * @stock_id: (allow-none): The name of the stock item, or %NULL
7628 * Sets the icon shown in the entry at the specified position from
7631 * If @stock_id is %NULL, no icon will be shown in the specified position.
7636 gtk_entry_set_icon_from_stock (GtkEntry *entry,
7637 GtkEntryIconPosition icon_pos,
7638 const gchar *stock_id)
7640 GtkEntryPrivate *priv;
7641 EntryIconInfo *icon_info;
7644 g_return_if_fail (GTK_IS_ENTRY (entry));
7645 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7647 priv = GTK_ENTRY_GET_PRIVATE (entry);
7649 if ((icon_info = priv->icons[icon_pos]) == NULL)
7650 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7652 g_object_freeze_notify (G_OBJECT (entry));
7654 gtk_widget_ensure_style (GTK_WIDGET (entry));
7656 /* need to dup before clearing */
7657 new_id = g_strdup (stock_id);
7659 gtk_entry_clear (entry, icon_pos);
7663 icon_info->storage_type = GTK_IMAGE_STOCK;
7664 icon_info->stock_id = new_id;
7666 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7668 g_object_notify (G_OBJECT (entry), "primary-icon-stock");
7669 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7673 g_object_notify (G_OBJECT (entry), "secondary-icon-stock");
7674 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7677 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7678 gdk_window_show_unraised (icon_info->window);
7681 gtk_entry_ensure_pixbuf (entry, icon_pos);
7683 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7684 gtk_widget_queue_resize (GTK_WIDGET (entry));
7686 g_object_thaw_notify (G_OBJECT (entry));
7690 * gtk_entry_set_icon_from_icon_name:
7691 * @entry: A #GtkEntry
7692 * @icon_pos: The position at which to set the icon
7693 * @icon_name: (allow-none): An icon name, or %NULL
7695 * Sets the icon shown in the entry at the specified position
7696 * from the current icon theme.
7698 * If the icon name isn't known, a "broken image" icon will be displayed
7701 * If @icon_name is %NULL, no icon will be shown in the specified position.
7706 gtk_entry_set_icon_from_icon_name (GtkEntry *entry,
7707 GtkEntryIconPosition icon_pos,
7708 const gchar *icon_name)
7710 GtkEntryPrivate *priv;
7711 EntryIconInfo *icon_info;
7714 g_return_if_fail (GTK_IS_ENTRY (entry));
7715 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7717 priv = GTK_ENTRY_GET_PRIVATE (entry);
7719 if ((icon_info = priv->icons[icon_pos]) == NULL)
7720 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7722 g_object_freeze_notify (G_OBJECT (entry));
7724 gtk_widget_ensure_style (GTK_WIDGET (entry));
7726 /* need to dup before clearing */
7727 new_name = g_strdup (icon_name);
7729 gtk_entry_clear (entry, icon_pos);
7731 if (new_name != NULL)
7733 icon_info->storage_type = GTK_IMAGE_ICON_NAME;
7734 icon_info->icon_name = new_name;
7736 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7738 g_object_notify (G_OBJECT (entry), "primary-icon-name");
7739 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7743 g_object_notify (G_OBJECT (entry), "secondary-icon-name");
7744 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7747 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7748 gdk_window_show_unraised (icon_info->window);
7751 gtk_entry_ensure_pixbuf (entry, icon_pos);
7753 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7754 gtk_widget_queue_resize (GTK_WIDGET (entry));
7756 g_object_thaw_notify (G_OBJECT (entry));
7760 * gtk_entry_set_icon_from_gicon:
7761 * @entry: A #GtkEntry
7762 * @icon_pos: The position at which to set the icon
7763 * @icon: (allow-none): The icon to set, or %NULL
7765 * Sets the icon shown in the entry at the specified position
7766 * from the current icon theme.
7767 * If the icon isn't known, a "broken image" icon will be displayed
7770 * If @icon is %NULL, no icon will be shown in the specified position.
7775 gtk_entry_set_icon_from_gicon (GtkEntry *entry,
7776 GtkEntryIconPosition icon_pos,
7779 GtkEntryPrivate *priv;
7780 EntryIconInfo *icon_info;
7782 g_return_if_fail (GTK_IS_ENTRY (entry));
7783 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7785 priv = GTK_ENTRY_GET_PRIVATE (entry);
7787 if ((icon_info = priv->icons[icon_pos]) == NULL)
7788 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7790 g_object_freeze_notify (G_OBJECT (entry));
7792 /* need to ref before clearing */
7794 g_object_ref (icon);
7796 gtk_entry_clear (entry, icon_pos);
7800 icon_info->storage_type = GTK_IMAGE_GICON;
7801 icon_info->gicon = icon;
7803 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7805 g_object_notify (G_OBJECT (entry), "primary-icon-gicon");
7806 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7810 g_object_notify (G_OBJECT (entry), "secondary-icon-gicon");
7811 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7814 if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
7815 gdk_window_show_unraised (icon_info->window);
7818 gtk_entry_ensure_pixbuf (entry, icon_pos);
7820 if (gtk_widget_get_visible (GTK_WIDGET (entry)))
7821 gtk_widget_queue_resize (GTK_WIDGET (entry));
7823 g_object_thaw_notify (G_OBJECT (entry));
7827 * gtk_entry_set_icon_activatable:
7828 * @entry: A #GtkEntry
7829 * @icon_pos: Icon position
7830 * @activatable: %TRUE if the icon should be activatable
7832 * Sets whether the icon is activatable.
7837 gtk_entry_set_icon_activatable (GtkEntry *entry,
7838 GtkEntryIconPosition icon_pos,
7839 gboolean activatable)
7841 GtkEntryPrivate *priv;
7842 EntryIconInfo *icon_info;
7844 g_return_if_fail (GTK_IS_ENTRY (entry));
7845 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7847 priv = GTK_ENTRY_GET_PRIVATE (entry);
7849 if ((icon_info = priv->icons[icon_pos]) == NULL)
7850 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7852 activatable = activatable != FALSE;
7854 if (icon_info->nonactivatable != !activatable)
7856 icon_info->nonactivatable = !activatable;
7858 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
7859 update_cursors (GTK_WIDGET (entry));
7861 g_object_notify (G_OBJECT (entry),
7862 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-activatable" : "secondary-icon-activatable");
7867 * gtk_entry_get_icon_activatable:
7868 * @entry: a #GtkEntry
7869 * @icon_pos: Icon position
7871 * Returns whether the icon is activatable.
7873 * Returns: %TRUE if the icon is activatable.
7878 gtk_entry_get_icon_activatable (GtkEntry *entry,
7879 GtkEntryIconPosition icon_pos)
7881 GtkEntryPrivate *priv;
7882 EntryIconInfo *icon_info;
7884 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7885 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), FALSE);
7887 priv = GTK_ENTRY_GET_PRIVATE (entry);
7888 icon_info = priv->icons[icon_pos];
7890 return (icon_info != NULL && !icon_info->nonactivatable);
7894 * gtk_entry_get_icon_pixbuf:
7895 * @entry: A #GtkEntry
7896 * @icon_pos: Icon position
7898 * Retrieves the image used for the icon.
7900 * Unlike the other methods of setting and getting icon data, this
7901 * method will work regardless of whether the icon was set using a
7902 * #GdkPixbuf, a #GIcon, a stock item, or an icon name.
7904 * Returns: A #GdkPixbuf, or %NULL if no icon is set for this position.
7909 gtk_entry_get_icon_pixbuf (GtkEntry *entry,
7910 GtkEntryIconPosition icon_pos)
7912 GtkEntryPrivate *priv;
7913 EntryIconInfo *icon_info;
7915 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7916 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7918 priv = GTK_ENTRY_GET_PRIVATE (entry);
7919 icon_info = priv->icons[icon_pos];
7924 gtk_entry_ensure_pixbuf (entry, icon_pos);
7926 return icon_info->pixbuf;
7930 * gtk_entry_get_icon_gicon:
7931 * @entry: A #GtkEntry
7932 * @icon_pos: Icon position
7934 * Retrieves the #GIcon used for the icon, or %NULL if there is
7935 * no icon or if the icon was set by some other method (e.g., by
7936 * stock, pixbuf, or icon name).
7938 * Returns: A #GIcon, or %NULL if no icon is set or if the icon
7944 gtk_entry_get_icon_gicon (GtkEntry *entry,
7945 GtkEntryIconPosition icon_pos)
7947 GtkEntryPrivate *priv;
7948 EntryIconInfo *icon_info;
7950 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7951 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7953 priv = GTK_ENTRY_GET_PRIVATE (entry);
7954 icon_info = priv->icons[icon_pos];
7959 return icon_info->storage_type == GTK_IMAGE_GICON ? icon_info->gicon : NULL;
7963 * gtk_entry_get_icon_stock:
7964 * @entry: A #GtkEntry
7965 * @icon_pos: Icon position
7967 * Retrieves the stock id used for the icon, or %NULL if there is
7968 * no icon or if the icon was set by some other method (e.g., by
7969 * pixbuf, icon name or gicon).
7971 * Returns: A stock id, or %NULL if no icon is set or if the icon
7972 * wasn't set from a stock id
7977 gtk_entry_get_icon_stock (GtkEntry *entry,
7978 GtkEntryIconPosition icon_pos)
7980 GtkEntryPrivate *priv;
7981 EntryIconInfo *icon_info;
7983 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7984 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7986 priv = GTK_ENTRY_GET_PRIVATE (entry);
7987 icon_info = priv->icons[icon_pos];
7992 return icon_info->storage_type == GTK_IMAGE_STOCK ? icon_info->stock_id : NULL;
7996 * gtk_entry_get_icon_name:
7997 * @entry: A #GtkEntry
7998 * @icon_pos: Icon position
8000 * Retrieves the icon name used for the icon, or %NULL if there is
8001 * no icon or if the icon was set by some other method (e.g., by
8002 * pixbuf, stock or gicon).
8004 * Returns: An icon name, or %NULL if no icon is set or if the icon
8005 * wasn't set from an icon name
8010 gtk_entry_get_icon_name (GtkEntry *entry,
8011 GtkEntryIconPosition icon_pos)
8013 GtkEntryPrivate *priv;
8014 EntryIconInfo *icon_info;
8016 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8017 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8019 priv = GTK_ENTRY_GET_PRIVATE (entry);
8020 icon_info = priv->icons[icon_pos];
8025 return icon_info->storage_type == GTK_IMAGE_ICON_NAME ? icon_info->icon_name : NULL;
8029 * gtk_entry_set_icon_sensitive:
8030 * @entry: A #GtkEntry
8031 * @icon_pos: Icon position
8032 * @sensitive: Specifies whether the icon should appear
8033 * sensitive or insensitive
8035 * Sets the sensitivity for the specified icon.
8040 gtk_entry_set_icon_sensitive (GtkEntry *entry,
8041 GtkEntryIconPosition icon_pos,
8044 GtkEntryPrivate *priv;
8045 EntryIconInfo *icon_info;
8047 g_return_if_fail (GTK_IS_ENTRY (entry));
8048 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8050 priv = GTK_ENTRY_GET_PRIVATE (entry);
8052 if ((icon_info = priv->icons[icon_pos]) == NULL)
8053 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8055 if (icon_info->insensitive != !sensitive)
8057 icon_info->insensitive = !sensitive;
8059 icon_info->pressed = FALSE;
8060 icon_info->prelight = FALSE;
8062 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
8063 update_cursors (GTK_WIDGET (entry));
8065 gtk_widget_queue_draw (GTK_WIDGET (entry));
8067 g_object_notify (G_OBJECT (entry),
8068 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-sensitive" : "secondary-icon-sensitive");
8073 * gtk_entry_get_icon_sensitive:
8074 * @entry: a #GtkEntry
8075 * @icon_pos: Icon position
8077 * Returns whether the icon appears sensitive or insensitive.
8079 * Returns: %TRUE if the icon is sensitive.
8084 gtk_entry_get_icon_sensitive (GtkEntry *entry,
8085 GtkEntryIconPosition icon_pos)
8087 GtkEntryPrivate *priv;
8088 EntryIconInfo *icon_info;
8090 g_return_val_if_fail (GTK_IS_ENTRY (entry), TRUE);
8091 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), TRUE);
8093 priv = GTK_ENTRY_GET_PRIVATE (entry);
8094 icon_info = priv->icons[icon_pos];
8096 return (!icon_info || !icon_info->insensitive);
8101 * gtk_entry_get_icon_storage_type:
8102 * @entry: a #GtkEntry
8103 * @icon_pos: Icon position
8105 * Gets the type of representation being used by the icon
8106 * to store image data. If the icon has no image data,
8107 * the return value will be %GTK_IMAGE_EMPTY.
8109 * Return value: image representation being used
8114 gtk_entry_get_icon_storage_type (GtkEntry *entry,
8115 GtkEntryIconPosition icon_pos)
8117 GtkEntryPrivate *priv;
8118 EntryIconInfo *icon_info;
8120 g_return_val_if_fail (GTK_IS_ENTRY (entry), GTK_IMAGE_EMPTY);
8121 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), GTK_IMAGE_EMPTY);
8123 priv = GTK_ENTRY_GET_PRIVATE (entry);
8124 icon_info = priv->icons[icon_pos];
8127 return GTK_IMAGE_EMPTY;
8129 return icon_info->storage_type;
8133 * gtk_entry_get_icon_at_pos:
8134 * @entry: a #GtkEntry
8135 * @x: the x coordinate of the position to find
8136 * @y: the y coordinate of the position to find
8138 * Finds the icon at the given position and return its index.
8139 * If @x, @y doesn't lie inside an icon, -1 is returned.
8140 * This function is intended for use in a #GtkWidget::query-tooltip
8143 * Returns: the index of the icon at the given position, or -1
8148 gtk_entry_get_icon_at_pos (GtkEntry *entry,
8152 GtkAllocation primary;
8153 GtkAllocation secondary;
8155 g_return_val_if_fail (GTK_IS_ENTRY (entry), -1);
8157 get_icon_allocations (entry, &primary, &secondary);
8159 if (primary.x <= x && x < primary.x + primary.width &&
8160 primary.y <= y && y < primary.y + primary.height)
8161 return GTK_ENTRY_ICON_PRIMARY;
8163 if (secondary.x <= x && x < secondary.x + secondary.width &&
8164 secondary.y <= y && y < secondary.y + secondary.height)
8165 return GTK_ENTRY_ICON_SECONDARY;
8171 * gtk_entry_set_icon_drag_source:
8172 * @entry: a #GtkIconEntry
8173 * @icon_pos: icon position
8174 * @target_list: the targets (data formats) in which the data can be provided
8175 * @actions: a bitmask of the allowed drag actions
8177 * Sets up the icon at the given position so that GTK+ will start a drag
8178 * operation when the user clicks and drags the icon.
8180 * To handle the drag operation, you need to connect to the usual
8181 * #GtkWidget::drag-data-get (or possibly #GtkWidget::drag-data-delete)
8182 * signal, and use gtk_entry_get_current_icon_drag_source() in
8183 * your signal handler to find out if the drag was started from
8186 * By default, GTK+ uses the icon as the drag icon. You can use the
8187 * #GtkWidget::drag-begin signal to set a different icon. Note that you
8188 * have to use g_signal_connect_after() to ensure that your signal handler
8189 * gets executed after the default handler.
8194 gtk_entry_set_icon_drag_source (GtkEntry *entry,
8195 GtkEntryIconPosition icon_pos,
8196 GtkTargetList *target_list,
8197 GdkDragAction actions)
8199 GtkEntryPrivate *priv;
8200 EntryIconInfo *icon_info;
8202 g_return_if_fail (GTK_IS_ENTRY (entry));
8203 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8205 priv = GTK_ENTRY_GET_PRIVATE (entry);
8207 if ((icon_info = priv->icons[icon_pos]) == NULL)
8208 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8210 if (icon_info->target_list)
8211 gtk_target_list_unref (icon_info->target_list);
8212 icon_info->target_list = target_list;
8213 if (icon_info->target_list)
8214 gtk_target_list_ref (icon_info->target_list);
8216 icon_info->actions = actions;
8220 * gtk_entry_get_current_icon_drag_source:
8221 * @entry: a #GtkIconEntry
8223 * Returns the index of the icon which is the source of the current
8224 * DND operation, or -1.
8226 * This function is meant to be used in a #GtkWidget::drag-data-get
8229 * Returns: index of the icon which is the source of the current
8230 * DND operation, or -1.
8235 gtk_entry_get_current_icon_drag_source (GtkEntry *entry)
8237 GtkEntryPrivate *priv;
8238 EntryIconInfo *icon_info = NULL;
8241 g_return_val_if_fail (GTK_IS_ENTRY (entry), -1);
8243 priv = GTK_ENTRY_GET_PRIVATE (entry);
8245 for (i = 0; i < MAX_ICONS; i++)
8247 if ((icon_info = priv->icons[i]))
8249 if (icon_info->in_drag)
8258 * gtk_entry_get_icon_window:
8259 * @entry: A #GtkEntry
8260 * @icon_pos: Icon position
8262 * Returns the #GdkWindow which contains the entry's icon at
8263 * @icon_pos. This function is useful when drawing something to the
8264 * entry in an expose-event callback because it enables the callback
8265 * to distinguish between the text window and entry's icon windows.
8267 * See also gtk_entry_get_text_window().
8269 * Return value: the entry's icon window at @icon_pos.
8274 gtk_entry_get_icon_window (GtkEntry *entry,
8275 GtkEntryIconPosition icon_pos)
8277 GtkEntryPrivate *priv;
8278 EntryIconInfo *icon_info;
8280 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8282 priv = GTK_ENTRY_GET_PRIVATE (entry);
8284 icon_info = priv->icons[icon_pos];
8287 return icon_info->window;
8293 ensure_has_tooltip (GtkEntry *entry)
8295 GtkEntryPrivate *priv;
8296 EntryIconInfo *icon_info;
8298 gboolean has_tooltip = FALSE;
8300 priv = GTK_ENTRY_GET_PRIVATE (entry);
8302 for (i = 0; i < MAX_ICONS; i++)
8304 if ((icon_info = priv->icons[i]) != NULL)
8306 if (icon_info->tooltip != NULL)
8314 gtk_widget_set_has_tooltip (GTK_WIDGET (entry), has_tooltip);
8318 * gtk_entry_get_icon_tooltip_text:
8319 * @entry: a #GtkEntry
8320 * @icon_pos: the icon position
8322 * Gets the contents of the tooltip on the icon at the specified
8323 * position in @entry.
8325 * Returns: the tooltip text, or %NULL. Free the returned string
8326 * with g_free() when done.
8331 gtk_entry_get_icon_tooltip_text (GtkEntry *entry,
8332 GtkEntryIconPosition icon_pos)
8334 GtkEntryPrivate *priv;
8335 EntryIconInfo *icon_info;
8338 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8339 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8341 priv = GTK_ENTRY_GET_PRIVATE (entry);
8342 icon_info = priv->icons[icon_pos];
8347 if (icon_info->tooltip &&
8348 !pango_parse_markup (icon_info->tooltip, -1, 0, NULL, &text, NULL, NULL))
8349 g_assert (NULL == text); /* text should still be NULL in case of markup errors */
8355 * gtk_entry_set_icon_tooltip_text:
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
8361 * at the specified position.
8363 * Use %NULL for @tooltip to remove an existing tooltip.
8365 * See also gtk_widget_set_tooltip_text() and
8366 * gtk_entry_set_icon_tooltip_markup().
8371 gtk_entry_set_icon_tooltip_text (GtkEntry *entry,
8372 GtkEntryIconPosition icon_pos,
8373 const gchar *tooltip)
8375 GtkEntryPrivate *priv;
8376 EntryIconInfo *icon_info;
8378 g_return_if_fail (GTK_IS_ENTRY (entry));
8379 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8381 priv = GTK_ENTRY_GET_PRIVATE (entry);
8383 if (!(icon_info = priv->icons[icon_pos]))
8384 icon_info = priv->icons[icon_pos];
8386 if (icon_info->tooltip)
8387 g_free (icon_info->tooltip);
8389 /* Treat an empty string as a NULL string,
8390 * because an empty string would be useless for a tooltip:
8392 if (tooltip && tooltip[0] == '\0')
8395 icon_info->tooltip = tooltip ? g_markup_escape_text (tooltip, -1) : NULL;
8397 ensure_has_tooltip (entry);
8401 * gtk_entry_get_icon_tooltip_markup:
8402 * @entry: a #GtkEntry
8403 * @icon_pos: the icon position
8405 * Gets the contents of the tooltip on the icon at the specified
8406 * position in @entry.
8408 * Returns: the tooltip text, or %NULL. Free the returned string
8409 * with g_free() when done.
8414 gtk_entry_get_icon_tooltip_markup (GtkEntry *entry,
8415 GtkEntryIconPosition icon_pos)
8417 GtkEntryPrivate *priv;
8418 EntryIconInfo *icon_info;
8420 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8421 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8423 priv = GTK_ENTRY_GET_PRIVATE (entry);
8424 icon_info = priv->icons[icon_pos];
8429 return g_strdup (icon_info->tooltip);
8433 * gtk_entry_set_icon_tooltip_markup:
8434 * @entry: a #GtkEntry
8435 * @icon_pos: the icon position
8436 * @tooltip: (allow-none): the contents of the tooltip for the icon, or %NULL
8438 * Sets @tooltip as the contents of the tooltip for the icon at
8439 * the specified position. @tooltip is assumed to be marked up with
8440 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
8442 * Use %NULL for @tooltip to remove an existing tooltip.
8444 * See also gtk_widget_set_tooltip_markup() and
8445 * gtk_enty_set_icon_tooltip_text().
8450 gtk_entry_set_icon_tooltip_markup (GtkEntry *entry,
8451 GtkEntryIconPosition icon_pos,
8452 const gchar *tooltip)
8454 GtkEntryPrivate *priv;
8455 EntryIconInfo *icon_info;
8457 g_return_if_fail (GTK_IS_ENTRY (entry));
8458 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8460 priv = GTK_ENTRY_GET_PRIVATE (entry);
8462 if (!(icon_info = priv->icons[icon_pos]))
8463 icon_info = priv->icons[icon_pos];
8465 if (icon_info->tooltip)
8466 g_free (icon_info->tooltip);
8468 /* Treat an empty string as a NULL string,
8469 * because an empty string would be useless for a tooltip:
8471 if (tooltip && tooltip[0] == '\0')
8474 icon_info->tooltip = g_strdup (tooltip);
8476 ensure_has_tooltip (entry);
8480 gtk_entry_query_tooltip (GtkWidget *widget,
8483 gboolean keyboard_tip,
8484 GtkTooltip *tooltip)
8487 GtkEntryPrivate *priv;
8488 EntryIconInfo *icon_info;
8491 entry = GTK_ENTRY (widget);
8492 priv = GTK_ENTRY_GET_PRIVATE (entry);
8496 icon_pos = gtk_entry_get_icon_at_pos (entry, x, y);
8499 if ((icon_info = priv->icons[icon_pos]) != NULL)
8501 if (icon_info->tooltip)
8503 gtk_tooltip_set_markup (tooltip, icon_info->tooltip);
8512 return GTK_WIDGET_CLASS (gtk_entry_parent_class)->query_tooltip (widget,
8519 /* Quick hack of a popup menu
8522 activate_cb (GtkWidget *menuitem,
8525 const gchar *signal = g_object_get_data (G_OBJECT (menuitem), "gtk-signal");
8526 g_signal_emit_by_name (entry, signal);
8531 gtk_entry_mnemonic_activate (GtkWidget *widget,
8532 gboolean group_cycling)
8534 gtk_widget_grab_focus (widget);
8539 append_action_signal (GtkEntry *entry,
8541 const gchar *stock_id,
8542 const gchar *signal,
8545 GtkWidget *menuitem = gtk_image_menu_item_new_from_stock (stock_id, NULL);
8547 g_object_set_data (G_OBJECT (menuitem), I_("gtk-signal"), (char *)signal);
8548 g_signal_connect (menuitem, "activate",
8549 G_CALLBACK (activate_cb), entry);
8551 gtk_widget_set_sensitive (menuitem, sensitive);
8553 gtk_widget_show (menuitem);
8554 gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
8558 popup_menu_detach (GtkWidget *attach_widget,
8561 GTK_ENTRY (attach_widget)->popup_menu = NULL;
8565 popup_position_func (GtkMenu *menu,
8571 GtkEntry *entry = GTK_ENTRY (user_data);
8572 GtkWidget *widget = GTK_WIDGET (entry);
8574 GtkRequisition menu_req;
8575 GdkRectangle monitor;
8576 GtkBorder inner_border;
8577 gint monitor_num, strong_x, height;
8579 g_return_if_fail (gtk_widget_get_realized (widget));
8581 gdk_window_get_origin (entry->text_area, x, y);
8583 screen = gtk_widget_get_screen (widget);
8584 monitor_num = gdk_screen_get_monitor_at_window (screen, entry->text_area);
8585 if (monitor_num < 0)
8587 gtk_menu_set_monitor (menu, monitor_num);
8589 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
8590 gtk_widget_size_request (entry->popup_menu, &menu_req);
8591 gdk_drawable_get_size (entry->text_area, NULL, &height);
8592 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
8593 _gtk_entry_effective_inner_border (entry, &inner_border);
8595 *x += inner_border.left + strong_x - entry->scroll_offset;
8596 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
8597 *x -= menu_req.width;
8599 if ((*y + height + menu_req.height) <= monitor.y + monitor.height)
8601 else if ((*y - menu_req.height) >= monitor.y)
8602 *y -= menu_req.height;
8603 else if (monitor.y + monitor.height - (*y + height) > *y)
8606 *y -= menu_req.height;
8612 unichar_chosen_func (const char *text,
8615 GtkEntry *entry = GTK_ENTRY (data);
8617 if (entry->editable)
8618 gtk_entry_enter_text (entry, text);
8629 popup_targets_received (GtkClipboard *clipboard,
8630 GtkSelectionData *data,
8633 PopupInfo *info = user_data;
8634 GtkEntry *entry = info->entry;
8636 if (gtk_widget_get_realized (GTK_WIDGET (entry)))
8639 gboolean clipboard_contains_text;
8640 GtkWidget *menuitem;
8642 gboolean show_input_method_menu;
8643 gboolean show_unicode_menu;
8645 clipboard_contains_text = gtk_selection_data_targets_include_text (data);
8646 if (entry->popup_menu)
8647 gtk_widget_destroy (entry->popup_menu);
8649 entry->popup_menu = gtk_menu_new ();
8651 gtk_menu_attach_to_widget (GTK_MENU (entry->popup_menu),
8655 mode = gtk_entry_get_display_mode (entry);
8656 append_action_signal (entry, entry->popup_menu, GTK_STOCK_CUT, "cut-clipboard",
8657 entry->editable && mode == DISPLAY_NORMAL &&
8658 entry->current_pos != entry->selection_bound);
8660 append_action_signal (entry, entry->popup_menu, GTK_STOCK_COPY, "copy-clipboard",
8661 mode == DISPLAY_NORMAL &&
8662 entry->current_pos != entry->selection_bound);
8664 append_action_signal (entry, entry->popup_menu, GTK_STOCK_PASTE, "paste-clipboard",
8665 entry->editable && clipboard_contains_text);
8667 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_DELETE, NULL);
8668 gtk_widget_set_sensitive (menuitem, entry->editable && entry->current_pos != entry->selection_bound);
8669 g_signal_connect_swapped (menuitem, "activate",
8670 G_CALLBACK (gtk_entry_delete_cb), entry);
8671 gtk_widget_show (menuitem);
8672 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8674 menuitem = gtk_separator_menu_item_new ();
8675 gtk_widget_show (menuitem);
8676 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8678 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_SELECT_ALL, NULL);
8679 g_signal_connect_swapped (menuitem, "activate",
8680 G_CALLBACK (gtk_entry_select_all), entry);
8681 gtk_widget_show (menuitem);
8682 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8684 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
8685 "gtk-show-input-method-menu", &show_input_method_menu,
8686 "gtk-show-unicode-menu", &show_unicode_menu,
8689 if (show_input_method_menu || show_unicode_menu)
8691 menuitem = gtk_separator_menu_item_new ();
8692 gtk_widget_show (menuitem);
8693 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8696 if (show_input_method_menu)
8698 menuitem = gtk_menu_item_new_with_mnemonic (_("Input _Methods"));
8699 gtk_widget_set_sensitive (menuitem, entry->editable);
8700 gtk_widget_show (menuitem);
8701 submenu = gtk_menu_new ();
8702 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
8704 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8706 gtk_im_multicontext_append_menuitems (GTK_IM_MULTICONTEXT (entry->im_context),
8707 GTK_MENU_SHELL (submenu));
8710 if (show_unicode_menu)
8712 menuitem = gtk_menu_item_new_with_mnemonic (_("_Insert Unicode Control Character"));
8713 gtk_widget_set_sensitive (menuitem, entry->editable);
8714 gtk_widget_show (menuitem);
8716 submenu = gtk_menu_new ();
8717 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
8718 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8720 _gtk_text_util_append_special_char_menuitems (GTK_MENU_SHELL (submenu),
8721 unichar_chosen_func,
8725 g_signal_emit (entry,
8726 signals[POPULATE_POPUP],
8732 gtk_menu_popup (GTK_MENU (entry->popup_menu), NULL, NULL,
8734 info->button, info->time);
8737 gtk_menu_popup (GTK_MENU (entry->popup_menu), NULL, NULL,
8738 popup_position_func, entry,
8739 info->button, info->time);
8740 gtk_menu_shell_select_first (GTK_MENU_SHELL (entry->popup_menu), FALSE);
8744 g_object_unref (entry);
8745 g_slice_free (PopupInfo, info);
8749 gtk_entry_do_popup (GtkEntry *entry,
8750 GdkEventButton *event)
8752 PopupInfo *info = g_slice_new (PopupInfo);
8754 /* In order to know what entries we should make sensitive, we
8755 * ask for the current targets of the clipboard, and when
8756 * we get them, then we actually pop up the menu.
8758 info->entry = g_object_ref (entry);
8762 info->button = event->button;
8763 info->time = event->time;
8768 info->time = gtk_get_current_event_time ();
8771 gtk_clipboard_request_contents (gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_CLIPBOARD),
8772 gdk_atom_intern_static_string ("TARGETS"),
8773 popup_targets_received,
8778 gtk_entry_popup_menu (GtkWidget *widget)
8780 gtk_entry_do_popup (GTK_ENTRY (widget), NULL);
8785 gtk_entry_drag_begin (GtkWidget *widget,
8786 GdkDragContext *context)
8788 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
8791 for (i = 0; i < MAX_ICONS; i++)
8793 EntryIconInfo *icon_info = priv->icons[i];
8795 if (icon_info != NULL)
8797 if (icon_info->in_drag)
8799 switch (icon_info->storage_type)
8801 case GTK_IMAGE_STOCK:
8802 gtk_drag_set_icon_stock (context, icon_info->stock_id, -2, -2);
8805 case GTK_IMAGE_ICON_NAME:
8806 gtk_drag_set_icon_name (context, icon_info->icon_name, -2, -2);
8809 /* FIXME: No GIcon support for dnd icons */
8810 case GTK_IMAGE_GICON:
8811 case GTK_IMAGE_PIXBUF:
8812 gtk_drag_set_icon_pixbuf (context, icon_info->pixbuf, -2, -2);
8815 g_assert_not_reached ();
8823 gtk_entry_drag_end (GtkWidget *widget,
8824 GdkDragContext *context)
8826 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
8829 for (i = 0; i < MAX_ICONS; i++)
8831 EntryIconInfo *icon_info = priv->icons[i];
8833 if (icon_info != NULL)
8834 icon_info->in_drag = 0;
8839 gtk_entry_drag_leave (GtkWidget *widget,
8840 GdkDragContext *context,
8843 GtkEntry *entry = GTK_ENTRY (widget);
8845 entry->dnd_position = -1;
8846 gtk_widget_queue_draw (widget);
8850 gtk_entry_drag_drop (GtkWidget *widget,
8851 GdkDragContext *context,
8856 GtkEntry *entry = GTK_ENTRY (widget);
8857 GdkAtom target = GDK_NONE;
8859 if (entry->editable)
8860 target = gtk_drag_dest_find_target (widget, context, NULL);
8862 if (target != GDK_NONE)
8863 gtk_drag_get_data (widget, context, target, time);
8865 gtk_drag_finish (context, FALSE, FALSE, time);
8871 gtk_entry_drag_motion (GtkWidget *widget,
8872 GdkDragContext *context,
8877 GtkEntry *entry = GTK_ENTRY (widget);
8878 GtkWidget *source_widget;
8879 GdkDragAction suggested_action;
8880 gint new_position, old_position;
8883 x -= widget->style->xthickness;
8884 y -= widget->style->ythickness;
8886 old_position = entry->dnd_position;
8887 new_position = gtk_entry_find_position (entry, x + entry->scroll_offset);
8889 if (entry->editable &&
8890 gtk_drag_dest_find_target (widget, context, NULL) != GDK_NONE)
8892 source_widget = gtk_drag_get_source_widget (context);
8893 suggested_action = context->suggested_action;
8895 if (!gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &sel1, &sel2) ||
8896 new_position < sel1 || new_position > sel2)
8898 if (source_widget == widget)
8900 /* Default to MOVE, unless the user has
8901 * pressed ctrl or alt to affect available actions
8903 if ((context->actions & GDK_ACTION_MOVE) != 0)
8904 suggested_action = GDK_ACTION_MOVE;
8907 entry->dnd_position = new_position;
8911 if (source_widget == widget)
8912 suggested_action = 0; /* Can't drop in selection where drag started */
8914 entry->dnd_position = -1;
8919 /* Entry not editable, or no text */
8920 suggested_action = 0;
8921 entry->dnd_position = -1;
8924 gdk_drag_status (context, suggested_action, time);
8926 if (entry->dnd_position != old_position)
8927 gtk_widget_queue_draw (widget);
8933 gtk_entry_drag_data_received (GtkWidget *widget,
8934 GdkDragContext *context,
8937 GtkSelectionData *selection_data,
8941 GtkEntry *entry = GTK_ENTRY (widget);
8942 GtkEditable *editable = GTK_EDITABLE (widget);
8945 str = (gchar *) gtk_selection_data_get_text (selection_data);
8947 x -= widget->style->xthickness;
8948 y -= widget->style->ythickness;
8950 if (str && entry->editable)
8956 if (entry->truncate_multiline)
8957 length = truncate_multiline (str);
8959 new_position = gtk_entry_find_position (entry, x + entry->scroll_offset);
8961 if (!gtk_editable_get_selection_bounds (editable, &sel1, &sel2) ||
8962 new_position < sel1 || new_position > sel2)
8964 gtk_editable_insert_text (editable, str, length, &new_position);
8968 /* Replacing selection */
8969 begin_change (entry);
8970 g_object_freeze_notify (G_OBJECT (entry));
8971 gtk_editable_delete_text (editable, sel1, sel2);
8972 gtk_editable_insert_text (editable, str, length, &sel1);
8973 g_object_thaw_notify (G_OBJECT (entry));
8977 gtk_drag_finish (context, TRUE, context->action == GDK_ACTION_MOVE, time);
8981 /* Drag and drop didn't happen! */
8982 gtk_drag_finish (context, FALSE, FALSE, time);
8989 gtk_entry_drag_data_get (GtkWidget *widget,
8990 GdkDragContext *context,
8991 GtkSelectionData *selection_data,
8995 gint sel_start, sel_end;
8998 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
8999 GtkEditable *editable = GTK_EDITABLE (widget);
9001 /* If there is an icon drag going on, exit early. */
9002 for (i = 0; i < MAX_ICONS; i++)
9004 EntryIconInfo *icon_info = priv->icons[i];
9006 if (icon_info != NULL)
9008 if (icon_info->in_drag)
9013 if (gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end))
9015 gchar *str = gtk_entry_get_display_text (GTK_ENTRY (widget), sel_start, sel_end);
9017 gtk_selection_data_set_text (selection_data, str, -1);
9025 gtk_entry_drag_data_delete (GtkWidget *widget,
9026 GdkDragContext *context)
9028 gint sel_start, sel_end;
9031 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
9032 GtkEditable *editable = GTK_EDITABLE (widget);
9034 /* If there is an icon drag going on, exit early. */
9035 for (i = 0; i < MAX_ICONS; i++)
9037 EntryIconInfo *icon_info = priv->icons[i];
9039 if (icon_info != NULL)
9041 if (icon_info->in_drag)
9046 if (GTK_ENTRY (widget)->editable &&
9047 gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end))
9048 gtk_editable_delete_text (editable, sel_start, sel_end);
9051 /* We display the cursor when
9053 * - the selection is empty, AND
9054 * - the widget has focus
9057 #define CURSOR_ON_MULTIPLIER 2
9058 #define CURSOR_OFF_MULTIPLIER 1
9059 #define CURSOR_PEND_MULTIPLIER 3
9060 #define CURSOR_DIVIDER 3
9063 cursor_blinks (GtkEntry *entry)
9065 if (gtk_widget_has_focus (GTK_WIDGET (entry)) &&
9067 entry->selection_bound == entry->current_pos)
9069 GtkSettings *settings;
9072 settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9073 g_object_get (settings, "gtk-cursor-blink", &blink, NULL);
9082 get_cursor_time (GtkEntry *entry)
9084 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9087 g_object_get (settings, "gtk-cursor-blink-time", &time, NULL);
9093 get_cursor_blink_timeout (GtkEntry *entry)
9095 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9098 g_object_get (settings, "gtk-cursor-blink-timeout", &timeout, NULL);
9104 show_cursor (GtkEntry *entry)
9108 if (!entry->cursor_visible)
9110 entry->cursor_visible = TRUE;
9112 widget = GTK_WIDGET (entry);
9113 if (gtk_widget_has_focus (widget) && entry->selection_bound == entry->current_pos)
9114 gtk_widget_queue_draw (widget);
9119 hide_cursor (GtkEntry *entry)
9123 if (entry->cursor_visible)
9125 entry->cursor_visible = FALSE;
9127 widget = GTK_WIDGET (entry);
9128 if (gtk_widget_has_focus (widget) && entry->selection_bound == entry->current_pos)
9129 gtk_widget_queue_draw (widget);
9137 blink_cb (gpointer data)
9140 GtkEntryPrivate *priv;
9143 entry = GTK_ENTRY (data);
9144 priv = GTK_ENTRY_GET_PRIVATE (entry);
9146 if (!gtk_widget_has_focus (GTK_WIDGET (entry)))
9148 g_warning ("GtkEntry - did not receive focus-out-event. If you\n"
9149 "connect a handler to this signal, it must return\n"
9150 "FALSE so the entry gets the event as well");
9152 gtk_entry_check_cursor_blink (entry);
9157 g_assert (entry->selection_bound == entry->current_pos);
9159 blink_timeout = get_cursor_blink_timeout (entry);
9160 if (priv->blink_time > 1000 * blink_timeout &&
9161 blink_timeout < G_MAXINT/1000)
9163 /* we've blinked enough without the user doing anything, stop blinking */
9164 show_cursor (entry);
9165 entry->blink_timeout = 0;
9167 else if (entry->cursor_visible)
9169 hide_cursor (entry);
9170 entry->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_OFF_MULTIPLIER / CURSOR_DIVIDER,
9176 show_cursor (entry);
9177 priv->blink_time += get_cursor_time (entry);
9178 entry->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
9183 /* Remove ourselves */
9188 gtk_entry_check_cursor_blink (GtkEntry *entry)
9190 GtkEntryPrivate *priv;
9192 priv = GTK_ENTRY_GET_PRIVATE (entry);
9194 if (cursor_blinks (entry))
9196 if (!entry->blink_timeout)
9198 show_cursor (entry);
9199 entry->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
9206 if (entry->blink_timeout)
9208 g_source_remove (entry->blink_timeout);
9209 entry->blink_timeout = 0;
9212 entry->cursor_visible = TRUE;
9218 gtk_entry_pend_cursor_blink (GtkEntry *entry)
9220 if (cursor_blinks (entry))
9222 if (entry->blink_timeout != 0)
9223 g_source_remove (entry->blink_timeout);
9225 entry->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_PEND_MULTIPLIER / CURSOR_DIVIDER,
9228 show_cursor (entry);
9233 gtk_entry_reset_blink_time (GtkEntry *entry)
9235 GtkEntryPrivate *priv;
9237 priv = GTK_ENTRY_GET_PRIVATE (entry);
9239 priv->blink_time = 0;
9245 gtk_entry_completion_timeout (gpointer data)
9247 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (data);
9249 completion->priv->completion_timeout = 0;
9251 if (completion->priv->filter_model &&
9252 g_utf8_strlen (gtk_entry_get_text (GTK_ENTRY (completion->priv->entry)), -1)
9253 >= completion->priv->minimum_key_length)
9257 GtkTreeSelection *s;
9258 gboolean popup_single;
9260 gtk_entry_completion_complete (completion);
9261 matches = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->filter_model), NULL);
9263 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9265 s = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view));
9267 gtk_tree_selection_unselect_all (s);
9269 actions = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->actions), NULL);
9271 g_object_get (completion, "popup-single-match", &popup_single, NULL);
9272 if ((matches > (popup_single ? 0: 1)) || actions > 0)
9274 if (gtk_widget_get_visible (completion->priv->popup_window))
9275 _gtk_entry_completion_resize_popup (completion);
9277 _gtk_entry_completion_popup (completion);
9280 _gtk_entry_completion_popdown (completion);
9282 else if (gtk_widget_get_visible (completion->priv->popup_window))
9283 _gtk_entry_completion_popdown (completion);
9288 static inline gboolean
9289 keyval_is_cursor_move (guint keyval)
9291 if (keyval == GDK_Up || keyval == GDK_KP_Up)
9294 if (keyval == GDK_Down || keyval == GDK_KP_Down)
9297 if (keyval == GDK_Page_Up)
9300 if (keyval == GDK_Page_Down)
9307 gtk_entry_completion_key_press (GtkWidget *widget,
9311 gint matches, actions = 0;
9312 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
9314 if (!gtk_widget_get_mapped (completion->priv->popup_window))
9317 matches = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->filter_model), NULL);
9319 if (completion->priv->actions)
9320 actions = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->actions), NULL);
9322 if (keyval_is_cursor_move (event->keyval))
9324 GtkTreePath *path = NULL;
9326 if (event->keyval == GDK_Up || event->keyval == GDK_KP_Up)
9328 if (completion->priv->current_selected < 0)
9329 completion->priv->current_selected = matches + actions - 1;
9331 completion->priv->current_selected--;
9333 else if (event->keyval == GDK_Down || event->keyval == GDK_KP_Down)
9335 if (completion->priv->current_selected < matches + actions - 1)
9336 completion->priv->current_selected++;
9338 completion->priv->current_selected = -1;
9340 else if (event->keyval == GDK_Page_Up)
9342 if (completion->priv->current_selected < 0)
9343 completion->priv->current_selected = matches + actions - 1;
9344 else if (completion->priv->current_selected == 0)
9345 completion->priv->current_selected = -1;
9346 else if (completion->priv->current_selected < matches)
9348 completion->priv->current_selected -= 14;
9349 if (completion->priv->current_selected < 0)
9350 completion->priv->current_selected = 0;
9354 completion->priv->current_selected -= 14;
9355 if (completion->priv->current_selected < matches - 1)
9356 completion->priv->current_selected = matches - 1;
9359 else if (event->keyval == GDK_Page_Down)
9361 if (completion->priv->current_selected < 0)
9362 completion->priv->current_selected = 0;
9363 else if (completion->priv->current_selected < matches - 1)
9365 completion->priv->current_selected += 14;
9366 if (completion->priv->current_selected > matches - 1)
9367 completion->priv->current_selected = matches - 1;
9369 else if (completion->priv->current_selected == matches + actions - 1)
9371 completion->priv->current_selected = -1;
9375 completion->priv->current_selected += 14;
9376 if (completion->priv->current_selected > matches + actions - 1)
9377 completion->priv->current_selected = matches + actions - 1;
9381 if (completion->priv->current_selected < 0)
9383 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9384 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view)));
9386 if (completion->priv->inline_selection &&
9387 completion->priv->completion_prefix)
9389 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9390 completion->priv->completion_prefix);
9391 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9394 else if (completion->priv->current_selected < matches)
9396 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view)));
9398 path = gtk_tree_path_new_from_indices (completion->priv->current_selected, -1);
9399 gtk_tree_view_set_cursor (GTK_TREE_VIEW (completion->priv->tree_view),
9402 if (completion->priv->inline_selection)
9406 GtkTreeModel *model = NULL;
9407 GtkTreeSelection *sel;
9410 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view));
9411 if (!gtk_tree_selection_get_selected (sel, &model, &iter))
9414 if (completion->priv->completion_prefix == NULL)
9415 completion->priv->completion_prefix = g_strdup (gtk_entry_get_text (GTK_ENTRY (completion->priv->entry)));
9417 g_signal_emit_by_name (completion, "cursor-on-match", model,
9421 else if (completion->priv->current_selected - matches >= 0)
9423 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9425 path = gtk_tree_path_new_from_indices (completion->priv->current_selected - matches, -1);
9426 gtk_tree_view_set_cursor (GTK_TREE_VIEW (completion->priv->action_view),
9429 if (completion->priv->inline_selection &&
9430 completion->priv->completion_prefix)
9432 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9433 completion->priv->completion_prefix);
9434 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9438 gtk_tree_path_free (path);
9442 else if (event->keyval == GDK_Escape ||
9443 event->keyval == GDK_Left ||
9444 event->keyval == GDK_KP_Left ||
9445 event->keyval == GDK_Right ||
9446 event->keyval == GDK_KP_Right)
9448 gboolean retval = TRUE;
9450 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9451 _gtk_entry_completion_popdown (completion);
9453 if (completion->priv->current_selected < 0)
9456 goto keypress_completion_out;
9458 else if (completion->priv->inline_selection)
9460 /* Escape rejects the tentative completion */
9461 if (event->keyval == GDK_Escape)
9463 if (completion->priv->completion_prefix)
9464 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9465 completion->priv->completion_prefix);
9467 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry), "");
9470 /* Move the cursor to the end for Right/Esc, to the
9471 beginning for Left */
9472 if (event->keyval == GDK_Right ||
9473 event->keyval == GDK_KP_Right ||
9474 event->keyval == GDK_Escape)
9475 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9477 gtk_editable_set_position (GTK_EDITABLE (widget), 0);
9480 keypress_completion_out:
9481 if (completion->priv->inline_selection)
9483 g_free (completion->priv->completion_prefix);
9484 completion->priv->completion_prefix = NULL;
9489 else if (event->keyval == GDK_Tab ||
9490 event->keyval == GDK_KP_Tab ||
9491 event->keyval == GDK_ISO_Left_Tab)
9493 GtkDirectionType dir = event->keyval == GDK_ISO_Left_Tab ?
9494 GTK_DIR_TAB_BACKWARD : GTK_DIR_TAB_FORWARD;
9496 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9497 _gtk_entry_completion_popdown (completion);
9499 g_free (completion->priv->completion_prefix);
9500 completion->priv->completion_prefix = NULL;
9502 gtk_widget_child_focus (gtk_widget_get_toplevel (widget), dir);
9506 else if (event->keyval == GDK_ISO_Enter ||
9507 event->keyval == GDK_KP_Enter ||
9508 event->keyval == GDK_Return)
9511 GtkTreeModel *model = NULL;
9512 GtkTreeSelection *sel;
9513 gboolean retval = TRUE;
9515 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9516 _gtk_entry_completion_popdown (completion);
9518 if (completion->priv->current_selected < matches)
9522 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view));
9523 if (gtk_tree_selection_get_selected (sel, &model, &iter))
9525 g_signal_handler_block (widget, completion->priv->changed_id);
9526 g_signal_emit_by_name (completion, "match-selected",
9527 model, &iter, &entry_set);
9528 g_signal_handler_unblock (widget, completion->priv->changed_id);
9534 gtk_tree_model_get (model, &iter,
9535 completion->priv->text_column, &str,
9538 gtk_entry_set_text (GTK_ENTRY (widget), str);
9540 /* move the cursor to the end */
9541 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9549 else if (completion->priv->current_selected - matches >= 0)
9551 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view));
9552 if (gtk_tree_selection_get_selected (sel, &model, &iter))
9556 path = gtk_tree_path_new_from_indices (completion->priv->current_selected - matches, -1);
9557 g_signal_emit_by_name (completion, "action-activated",
9558 gtk_tree_path_get_indices (path)[0]);
9559 gtk_tree_path_free (path);
9565 g_free (completion->priv->completion_prefix);
9566 completion->priv->completion_prefix = NULL;
9575 gtk_entry_completion_changed (GtkWidget *entry,
9578 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
9580 /* (re)install completion timeout */
9581 if (completion->priv->completion_timeout)
9582 g_source_remove (completion->priv->completion_timeout);
9584 if (!gtk_entry_get_text (GTK_ENTRY (entry)))
9587 /* no need to normalize for this test */
9588 if (completion->priv->minimum_key_length > 0 &&
9589 strcmp ("", gtk_entry_get_text (GTK_ENTRY (entry))) == 0)
9591 if (gtk_widget_get_visible (completion->priv->popup_window))
9592 _gtk_entry_completion_popdown (completion);
9596 completion->priv->completion_timeout =
9597 gdk_threads_add_timeout (COMPLETION_TIMEOUT,
9598 gtk_entry_completion_timeout,
9603 check_completion_callback (GtkEntryCompletion *completion)
9605 completion->priv->check_completion_idle = NULL;
9607 gtk_entry_completion_complete (completion);
9608 gtk_entry_completion_insert_prefix (completion);
9614 clear_completion_callback (GtkEntry *entry,
9617 if (pspec->name == I_("cursor-position") ||
9618 pspec->name == I_("selection-bound"))
9620 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
9622 completion->priv->has_completion = FALSE;
9627 accept_completion_callback (GtkEntry *entry)
9629 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
9631 if (completion->priv->has_completion)
9632 gtk_editable_set_position (GTK_EDITABLE (entry),
9633 gtk_entry_buffer_get_length (get_buffer (entry)));
9639 completion_insert_text_callback (GtkEntry *entry,
9643 GtkEntryCompletion *completion)
9645 /* idle to update the selection based on the file list */
9646 if (completion->priv->check_completion_idle == NULL)
9648 completion->priv->check_completion_idle = g_idle_source_new ();
9649 g_source_set_priority (completion->priv->check_completion_idle, G_PRIORITY_HIGH);
9650 g_source_set_closure (completion->priv->check_completion_idle,
9651 g_cclosure_new_object (G_CALLBACK (check_completion_callback),
9652 G_OBJECT (completion)));
9653 g_source_attach (completion->priv->check_completion_idle, NULL);
9658 completion_changed (GtkEntryCompletion *completion,
9662 GtkEntry *entry = GTK_ENTRY (data);
9664 if (pspec->name == I_("popup-completion") ||
9665 pspec->name == I_("inline-completion"))
9667 disconnect_completion_signals (entry, completion);
9668 connect_completion_signals (entry, completion);
9673 disconnect_completion_signals (GtkEntry *entry,
9674 GtkEntryCompletion *completion)
9676 g_signal_handlers_disconnect_by_func (completion,
9677 G_CALLBACK (completion_changed), entry);
9678 if (completion->priv->changed_id > 0 &&
9679 g_signal_handler_is_connected (entry, completion->priv->changed_id))
9681 g_signal_handler_disconnect (entry, completion->priv->changed_id);
9682 completion->priv->changed_id = 0;
9684 g_signal_handlers_disconnect_by_func (entry,
9685 G_CALLBACK (gtk_entry_completion_key_press), completion);
9686 if (completion->priv->insert_text_id > 0 &&
9687 g_signal_handler_is_connected (entry, completion->priv->insert_text_id))
9689 g_signal_handler_disconnect (entry, completion->priv->insert_text_id);
9690 completion->priv->insert_text_id = 0;
9692 g_signal_handlers_disconnect_by_func (entry,
9693 G_CALLBACK (completion_insert_text_callback), completion);
9694 g_signal_handlers_disconnect_by_func (entry,
9695 G_CALLBACK (clear_completion_callback), completion);
9696 g_signal_handlers_disconnect_by_func (entry,
9697 G_CALLBACK (accept_completion_callback), completion);
9701 connect_completion_signals (GtkEntry *entry,
9702 GtkEntryCompletion *completion)
9704 if (completion->priv->popup_completion)
9706 completion->priv->changed_id =
9707 g_signal_connect (entry, "changed",
9708 G_CALLBACK (gtk_entry_completion_changed), completion);
9709 g_signal_connect (entry, "key-press-event",
9710 G_CALLBACK (gtk_entry_completion_key_press), completion);
9713 if (completion->priv->inline_completion)
9715 completion->priv->insert_text_id =
9716 g_signal_connect (entry, "insert-text",
9717 G_CALLBACK (completion_insert_text_callback), completion);
9718 g_signal_connect (entry, "notify",
9719 G_CALLBACK (clear_completion_callback), completion);
9720 g_signal_connect (entry, "activate",
9721 G_CALLBACK (accept_completion_callback), completion);
9722 g_signal_connect (entry, "focus-out-event",
9723 G_CALLBACK (accept_completion_callback), completion);
9726 g_signal_connect (completion, "notify",
9727 G_CALLBACK (completion_changed), entry);
9731 * gtk_entry_set_completion:
9732 * @entry: A #GtkEntry
9733 * @completion: (allow-none): The #GtkEntryCompletion or %NULL
9735 * Sets @completion to be the auxiliary completion object to use with @entry.
9736 * All further configuration of the completion mechanism is done on
9737 * @completion using the #GtkEntryCompletion API. Completion is disabled if
9738 * @completion is set to %NULL.
9743 gtk_entry_set_completion (GtkEntry *entry,
9744 GtkEntryCompletion *completion)
9746 GtkEntryCompletion *old;
9748 g_return_if_fail (GTK_IS_ENTRY (entry));
9749 g_return_if_fail (!completion || GTK_IS_ENTRY_COMPLETION (completion));
9751 old = gtk_entry_get_completion (entry);
9753 if (old == completion)
9758 if (old->priv->completion_timeout)
9760 g_source_remove (old->priv->completion_timeout);
9761 old->priv->completion_timeout = 0;
9764 if (gtk_widget_get_mapped (old->priv->popup_window))
9765 _gtk_entry_completion_popdown (old);
9767 disconnect_completion_signals (entry, old);
9768 old->priv->entry = NULL;
9770 g_object_unref (old);
9775 g_object_set_data (G_OBJECT (entry), I_(GTK_ENTRY_COMPLETION_KEY), NULL);
9779 /* hook into the entry */
9780 g_object_ref (completion);
9782 connect_completion_signals (entry, completion);
9783 completion->priv->entry = GTK_WIDGET (entry);
9784 g_object_set_data (G_OBJECT (entry), I_(GTK_ENTRY_COMPLETION_KEY), completion);
9788 * gtk_entry_get_completion:
9789 * @entry: A #GtkEntry
9791 * Returns the auxiliary completion object currently in use by @entry.
9793 * Return value: The auxiliary completion object currently in use by @entry.
9797 GtkEntryCompletion *
9798 gtk_entry_get_completion (GtkEntry *entry)
9800 GtkEntryCompletion *completion;
9802 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
9804 completion = GTK_ENTRY_COMPLETION (g_object_get_data (G_OBJECT (entry),
9805 GTK_ENTRY_COMPLETION_KEY));
9811 * gtk_entry_set_cursor_hadjustment:
9812 * @entry: a #GtkEntry
9813 * @adjustment: an adjustment which should be adjusted when the cursor
9814 * is moved, or %NULL
9816 * Hooks up an adjustment to the cursor position in an entry, so that when
9817 * the cursor is moved, the adjustment is scrolled to show that position.
9818 * See gtk_scrolled_window_get_hadjustment() for a typical way of obtaining
9821 * The adjustment has to be in pixel units and in the same coordinate system
9827 gtk_entry_set_cursor_hadjustment (GtkEntry *entry,
9828 GtkAdjustment *adjustment)
9830 g_return_if_fail (GTK_IS_ENTRY (entry));
9832 g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
9835 g_object_ref (adjustment);
9837 g_object_set_qdata_full (G_OBJECT (entry),
9838 quark_cursor_hadjustment,
9844 * gtk_entry_get_cursor_hadjustment:
9845 * @entry: a #GtkEntry
9847 * Retrieves the horizontal cursor adjustment for the entry.
9848 * See gtk_entry_set_cursor_hadjustment().
9850 * Return value: (transfer none): the horizontal cursor adjustment, or %NULL
9851 * if none has been set.
9856 gtk_entry_get_cursor_hadjustment (GtkEntry *entry)
9858 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
9860 return g_object_get_qdata (G_OBJECT (entry), quark_cursor_hadjustment);
9864 * gtk_entry_set_progress_fraction:
9865 * @entry: a #GtkEntry
9866 * @fraction: fraction of the task that's been completed
9868 * Causes the entry's progress indicator to "fill in" the given
9869 * fraction of the bar. The fraction should be between 0.0 and 1.0,
9875 gtk_entry_set_progress_fraction (GtkEntry *entry,
9879 GtkEntryPrivate *private;
9880 gdouble old_fraction;
9881 gint x, y, width, height;
9882 gint old_x, old_y, old_width, old_height;
9884 g_return_if_fail (GTK_IS_ENTRY (entry));
9886 widget = GTK_WIDGET (entry);
9887 private = GTK_ENTRY_GET_PRIVATE (entry);
9889 if (private->progress_pulse_mode)
9892 old_fraction = private->progress_fraction;
9894 if (gtk_widget_is_drawable (widget))
9895 get_progress_area (widget, &old_x, &old_y, &old_width, &old_height);
9897 fraction = CLAMP (fraction, 0.0, 1.0);
9899 private->progress_fraction = fraction;
9900 private->progress_pulse_mode = FALSE;
9901 private->progress_pulse_current = 0.0;
9903 if (gtk_widget_is_drawable (widget))
9905 get_progress_area (widget, &x, &y, &width, &height);
9907 if ((x != old_x) || (y != old_y) || (width != old_width) || (height != old_height))
9908 gtk_widget_queue_draw (widget);
9911 if (fraction != old_fraction)
9912 g_object_notify (G_OBJECT (entry), "progress-fraction");
9916 * gtk_entry_get_progress_fraction:
9917 * @entry: a #GtkEntry
9919 * Returns the current fraction of the task that's been completed.
9920 * See gtk_entry_set_progress_fraction().
9922 * Return value: a fraction from 0.0 to 1.0
9927 gtk_entry_get_progress_fraction (GtkEntry *entry)
9929 GtkEntryPrivate *private;
9931 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
9933 private = GTK_ENTRY_GET_PRIVATE (entry);
9935 return private->progress_fraction;
9939 * gtk_entry_set_progress_pulse_step:
9940 * @entry: a #GtkEntry
9941 * @fraction: fraction between 0.0 and 1.0
9943 * Sets the fraction of total entry width to move the progress
9944 * bouncing block for each call to gtk_entry_progress_pulse().
9949 gtk_entry_set_progress_pulse_step (GtkEntry *entry,
9952 GtkEntryPrivate *private;
9954 g_return_if_fail (GTK_IS_ENTRY (entry));
9956 private = GTK_ENTRY_GET_PRIVATE (entry);
9958 fraction = CLAMP (fraction, 0.0, 1.0);
9960 if (fraction != private->progress_pulse_fraction)
9962 private->progress_pulse_fraction = fraction;
9964 gtk_widget_queue_draw (GTK_WIDGET (entry));
9966 g_object_notify (G_OBJECT (entry), "progress-pulse-step");
9971 * gtk_entry_get_progress_pulse_step:
9972 * @entry: a #GtkEntry
9974 * Retrieves the pulse step set with gtk_entry_set_progress_pulse_step().
9976 * Return value: a fraction from 0.0 to 1.0
9981 gtk_entry_get_progress_pulse_step (GtkEntry *entry)
9983 GtkEntryPrivate *private;
9985 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
9987 private = GTK_ENTRY_GET_PRIVATE (entry);
9989 return private->progress_pulse_fraction;
9993 * gtk_entry_progress_pulse:
9994 * @entry: a #GtkEntry
9996 * Indicates that some progress is made, but you don't know how much.
9997 * Causes the entry's progress indicator to enter "activity mode,"
9998 * where a block bounces back and forth. Each call to
9999 * gtk_entry_progress_pulse() causes the block to move by a little bit
10000 * (the amount of movement per pulse is determined by
10001 * gtk_entry_set_progress_pulse_step()).
10006 gtk_entry_progress_pulse (GtkEntry *entry)
10008 GtkEntryPrivate *private;
10010 g_return_if_fail (GTK_IS_ENTRY (entry));
10012 private = GTK_ENTRY_GET_PRIVATE (entry);
10014 if (private->progress_pulse_mode)
10016 if (private->progress_pulse_way_back)
10018 private->progress_pulse_current -= private->progress_pulse_fraction;
10020 if (private->progress_pulse_current < 0.0)
10022 private->progress_pulse_current = 0.0;
10023 private->progress_pulse_way_back = FALSE;
10028 private->progress_pulse_current += private->progress_pulse_fraction;
10030 if (private->progress_pulse_current > 1.0 - private->progress_pulse_fraction)
10032 private->progress_pulse_current = 1.0 - private->progress_pulse_fraction;
10033 private->progress_pulse_way_back = TRUE;
10039 private->progress_fraction = 0.0;
10040 private->progress_pulse_mode = TRUE;
10041 private->progress_pulse_way_back = FALSE;
10042 private->progress_pulse_current = 0.0;
10045 gtk_widget_queue_draw (GTK_WIDGET (entry));
10048 /* Caps Lock warning for password entries */
10051 show_capslock_feedback (GtkEntry *entry,
10054 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
10056 if (gtk_entry_get_icon_storage_type (entry, GTK_ENTRY_ICON_SECONDARY) == GTK_IMAGE_EMPTY)
10058 gtk_entry_set_icon_from_stock (entry, GTK_ENTRY_ICON_SECONDARY, GTK_STOCK_CAPS_LOCK_WARNING);
10059 gtk_entry_set_icon_activatable (entry, GTK_ENTRY_ICON_SECONDARY, FALSE);
10060 priv->caps_lock_warning_shown = TRUE;
10063 if (priv->caps_lock_warning_shown)
10064 gtk_entry_set_icon_tooltip_text (entry, GTK_ENTRY_ICON_SECONDARY, text);
10066 g_warning ("Can't show Caps Lock warning, since secondary icon is set");
10070 remove_capslock_feedback (GtkEntry *entry)
10072 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
10074 if (priv->caps_lock_warning_shown)
10076 gtk_entry_set_icon_from_stock (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
10077 priv->caps_lock_warning_shown = FALSE;
10082 keymap_state_changed (GdkKeymap *keymap,
10085 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
10088 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL && priv->caps_lock_warning)
10090 if (gdk_keymap_get_caps_lock_state (keymap))
10091 text = _("Caps Lock is on");
10095 show_capslock_feedback (entry, text);
10097 remove_capslock_feedback (entry);
10100 #define __GTK_ENTRY_C__
10101 #include "gtkaliasdef.c"